//Ensure that cluster specified by clusterName does not already exist.
//Given that we've already checked for uniqueness earlier, this should never
//be the case, but we'll be extra safe here.
Domain domain = ConfigAPIHelper.getDomainConfigBean(configContext);
Clusters clusters = domain.getClusters();
Cluster cluster = clusters.getClusterByName(clusterName);
if (cluster != null) {
throw new InstanceException(_strMgr.getString("clusterAlreadyExists",
clusterName));
}
//Create the new cluster instance
cluster = new Cluster();
cluster.setName(clusterName);
if (configName != null) {
//A shared cluster has its configuration pre-created.
//Get the configuration specified by configName and ensure that it exists
//is valid.
Config config = validateSharedConfiguration(configContext, configName);
cluster.setConfigRef(configName);
//add system properties into cluster element itself
if (props != null) {
for (Enumeration e = props.propertyNames(); e.hasMoreElements() ;) {
String propName = (String)e.nextElement();
String propValue = (String)props.getProperty(propName);
if (propValue != null) {
SystemProperty ep = new SystemProperty();
ep.setName(propName);
ep.setValue(propValue);
cluster.addSystemProperty(ep, OVERWRITE);
}
}
}
} else {
//For a standalone cluster, we need to create a standalone configuration.
//Create the standalone configuration to be referenced by the server
//FIXTHIS: Currently properties are passed when creating a standalone configuration
//to override defaults in the default configuration. We need to be consistent
//with properties passed during server instance creation and do one of the following:
//Currently Aspproach #2 is implemented.
//1) add property support at the cluster level (domain, configuration, cluster, instance)
//2) use the properties passed at standalone cluster creation in a manner
//similar to standalone cluster creation.
//FIXTHIS: One issue is that the call below will result in a call to flushAll
//which is also called below. This must be taken into account when we
//figure out the notification story.
String stanaloneConfigName = getConfigsConfigBean().createStandAloneConfiguration(
clusterName, props);
cluster.setConfigRef(stanaloneConfigName);
}
setHeartbeatAddressAndPort(cluster);
//Add system applications and resources
addSystemApplications(cluster);
addSystemResources(cluster);
//Add the new cluster
clusters.addCluster(cluster, OVERWRITE);
//FIXTHIS: We force persistence, clear any notifications, and update the
//Application server's config context explicitely. Until this is modelled
//as an event notification (TBD) we need this to happen before notifying or
//the Node Agent will not synchronize the correct data.