getConfigContext());
Server[] servers=domain.getServers().getServer();
// get EEInstancesManager and get instances that currently
// physically exist in repository
InstanceConfig instanceConfig = new InstanceConfig(
InstanceDirs.getInstanceRoot());
EEInstancesManager eeInstancesManager = new EEInstancesManager(
instanceConfig);
HashMap hmInstances = getInstancesAndStatus(
instanceConfig, eeInstancesManager);
// loop through for creatation of instances boolean match = false;
Iterator serverIt = null;
String instanceName = null;
int status = 0;
// get node controller config bean from domain
com.sun.enterprise.config.serverbeans.NodeAgent nodeController
= getNodeAgentConfigBean(getConfigContext());
if (nodeController != null) {
Properties props = null;
ElementProperty elementProperty = null;
Cluster cluster = null;
// need a default, can't have %%%DOMAIN_NAME%%% go into
// running server
String domainName="DomainPropertyNotFound";
// set default to "" because this string will actual be placed
// in the startserv's java command for starting the instance
// via the ProcessLauncher. This is the easiest way to have the
// com.sun.aas.clusterName set to null for a standalone Instance
String clusterArg = "";
for (int ii = 0; ii < servers.length; ii++) {
// check to see if the server belongs to this
// node agent (repository)
if (instanceConfig.getRepositoryName().equals(
servers[ii].getNodeAgentRef())) {
// check if instance already exists or
// needs to be created.
if (instanceExists(servers[ii].getName())) {
getLogger().log(Level.INFO,
"nodeagent.instance.exists", servers[ii].getName());
} else {
// instance does not exist so create it
getLogger().log(Level.INFO,
"nodeagent.create.instance", servers[ii].getName());
instanceConfig.setInstanceName(servers[ii].getName());
// set properties for token replacing startserv scripts
props = new Properties();
// add proper domain
elementProperty = domain.getElementPropertyByName(
DOMAIN_XML_DOMAIN_NAME_PROPERTY_NAME);
if (elementProperty != null)
domainName=elementProperty.getValue();
getLogger().log(Level.INFO,
"domain for instance - " + domainName);
props.setProperty(EEScriptsTokens.DOMAIN_NAME,
domainName);
if (ServerHelper.isServerClustered(
getConfigContext(), servers[ii].getName())) {
try {
// see if part of cluster
cluster = ClusterHelper.getClusterForInstance(
getConfigContext(), servers[ii].getName());
if (cluster != null)
clusterArg = "-D" + CLUSTER_NAME + "=\""
+ cluster.getName() + "\"";
} catch (ConfigException ce) {
// show at finest, because the server may
// not be part of cluster
getLogger().log(Level.FINEST,
"Server isn't part of cluster", ce);
}
}
props.setProperty(EEScriptsTokens.CLUSTER_NAME, clusterArg);
// set the overriding properties used in token replacement
eeInstancesManager.setOverridingProperties(props);
// create instance
eeInstancesManager.createInstance();
// make list of created server instances to know which ones to
// sync on nodeagent startup.
createdInstances.add(servers[ii].getName());
}
// remove it from delete instances array
hmInstances.remove(servers[ii].getName());
}
}
}
// loop through and delete instances if nessesary
serverIt = hmInstances.keySet().iterator();
while (serverIt.hasNext()) {
instanceName = (String)serverIt.next();
status = ((Status)hmInstances.get(instanceName)).getStatusCode();
// delete instances
if (bDebug) System.out.println("Delete Server =" + instanceName
+ " with status:" + status);
getLogger().log(Level.INFO, "nodeagent.delete.instance",
instanceName);
instanceConfig.setInstanceName(instanceName);
// check to see if instances is
if(status != Status.kInstanceNotRunningCode) {
try {
stopInstance(instanceName);