final ConfigContext configContext = getConfigContext();
ConfigContextImpl.lock();
//validate that the server exists and return its node agent
final Target target = TargetBuilder.INSTANCE.createTarget(
VALID_TYPES, serverName, configContext);
final NodeAgent controller = target.getNodeAgents()[0];
//Remove the server instance
final Domain domain = ConfigAPIHelper.getDomainConfigBean(configContext);
final Servers servers = domain.getServers();
final Server server = target.getServers()[0];
boolean isReachable = true;
try {
ServerRuntimeMBean serverMBean = InstanceProxy.getInstanceProxy(serverName);
Status status = serverMBean.getRuntimeStatus().getStatus();
} catch (Exception ex) {
if (InstanceProxy.isUnreachable(ex)) {
isReachable = false;
}
}
if(isReachable)
throw new InstanceException(_strMgr.getString("serverIsNotStopped",
serverName));
if (ServerHelper.isServerStandAlone(configContext, serverName)) {
//If the server instance is stand-alone, we must remove its stand alone
//configuration after removing the server instance (since a configuration
//can only be deleted if it is unreferenced). Unfortunately, if
//this fails, we leave an unreferenced standalone configurtion.
String configName = server.getConfigRef();
// remove the server
servers.removeServer(server, OVERWRITE);
//remove the standalone configuration
//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.
getConfigsConfigBean().deleteConfiguration(configName);
} else {
if (ServerHelper.isServerClustered(configContext, server)) {
//If the instance is clustered, the we must remove the server refs from
//the cluster.
deleteClusterReferences(serverName);
}
//Remove the server
servers.removeServer(server, OVERWRITE);
}
//Remove our connction to the server instance
InstanceRegistry.removeInstanceConnection(serverName);
//Notify the node agent that a new server has been deleted to it so it can
//resynchronize.
//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.
//QUESTION: What happens if an exception is thrown above (e.g. in addNodeAgent). How do
//we restore the admin config context to its previous (and unpersisted value)???
flushAll();
NodeAgentMBean agentMBean = NodeAgentProxy.getNodeAgentProxy(controller.getName());
agentMBean.synchronizeWithDAS();
} catch (Exception ex) {
throw getExceptionHandler().handleInstanceException(
ex, "eeadmin.deleteServerInstance.Exception", serverName);
} finally {