using the deployment service you can easily swith from
different configuration, but actually you need to change
the CarbonDeploymentConfig.properties or to set an
environment variable to specify a different environment.
If you need to deploy a totally self-contained application
(no external lib, no change to the classpath) as an ear
or war this is not a good solution: if you want to deploy
the same application, without rebuilding the war/ear you
need to expand the application and manually modify the
file (usually contained in a jar into the ear) OR specify
an environment variable (not very good if you want to
keep the application indipendent from the environment
set-up).
To solve this problem we come up with a modified
version of the DeploymentService implementation which
let you specify a special variable ${servername} in the
deployment configuration.
using
carbon.deployment.Environment=dev/${servername}
the deployment service automatically replace the server
name and select the correct xml file according to the
environment, for example dev/server_test.xml or
dev/integration1.xml. This is also very useful for
developers who can have their specific xml configuration
working without modifying anything in the code base.
this is a snippet from my quick simple implementation:
public class ServerBasedDeploymentServiceImpl
implements DeploymentService, Configurable,
Startable, Suspendable, Destroyable
{
private static final String SERVER\_NAME
= "${servername}";
public void configure(ComponentConfiguration
configuration)
{
// original code here
// at the end of the Configure method, following the
default implementation code:
int servernameindex; if \(\(servernameindex =
targetNodeName.indexOf(SERVER_NAME)) != -1)
{
String lServerName = null; try \{ lServerName =
InetAddress.getLocalHost().getHostName().toLowerCase
();
}
catch
(UnknownHostException e)
{
throw new
InvalidConfigurationException(
this.getClass\(\), configuration.getConfigurationName\(\), "ServerName", "ServerName cannot be read. Unable to
replace " + SERVER_NAME + " in deployment properties");
}
log.debug\("Replacing " +
SERVER_NAME + " with " + lServerName);
this.targetNodeName = targetNodeName.substring\(0, servernameindex\) \+
lServerName
+
targetNodeName.substring(servernameindex +
SERVER_NAME.length());
\} \}
// end of configure()
I'd really like to see this feature added to the standard
deployment service
Logged In: YES
user_id=584426
made some changes to the deployment service so that you
can now specify NameLookup components that are
responsible for looking up either environment or instance
names. Also added a LocalHostNameLookup component that
will return the local host name. Other NameLookups could be
written to do such things as query an application for
environment and instance names.