final ConfigContext configContext = getConfigContext();
//Add properties
addServerProperties(server, props);
//Get the configuration specified by configName and ensure that it exists
Cluster cluster = ClusterHelper.getClusterByName(configContext,
clusterName);
//The clustered server inherits its configuration from the cluster
server.setConfigRef(cluster.getConfigRef());
//Now add the new server instance
// to avoid Validator's complains
Domain domain = ConfigAPIHelper.getDomainConfigBean(configContext);
domain.getServers().addServer(server, OVERWRITE);
//Add the server to the cluster
ServerRef serverRef = new ServerRef();
serverRef.setRef(server.getName());
cluster.addServerRef(serverRef, OVERWRITE);
//The clustered server inherits its applications from the cluster
ApplicationRef[] appRefs = cluster.getApplicationRef();
for (int i = 0; i < appRefs.length; i++) {
addApplicationReference(server, appRefs[i].isEnabled(),
appRefs[i].getRef(), appRefs[i].getVirtualServers());
}
//The clustered server inherits its resources from the cluster
ResourceRef[] resRefs = cluster.getResourceRef();
ResourceRef resRef = null;
for (int i = 0; i < resRefs.length; i++) {
addResourceReference(server, resRefs[i].isEnabled(),
resRefs[i].getRef());
}