LogFactory.getLog("HighAvailabilityLogic").fatal(stackTrace);
}
}
public void establishCurrentServerMode() {
Server server = getServer();
Server.OperationMode serverMode = determineServerOperationMode(
server.hasStatus(Server.Status.MANUAL_MAINTENANCE_MODE), storageClientManager.isClusterAvailable(),
server.getOperationMode());
// no state change means no work
if (serverMode == lastEstablishedServerMode)
return;
// whenever starting up clear the agent references to this server. Agent references will exist
// for previously connected agents that did not fail-over while this server was unavailable. This
// is done to avoid unnecessary cache re/load and moreover provides a logically initialized environment.
if (null == lastEstablishedServerMode) {
printWithTrace("establishCurrentServerMode: NULL->" + serverMode + ", clearing agent references");
clearAgentReferences(server);
}
try {
if (Server.OperationMode.NORMAL == serverMode) {
// If moving into normal operating mode from Maintenance Mode then:
// 1) Ensure lingering agent references are cleared
// - this may have been done at startup already, this covers the case when we go in and
// - out of MM without ever taking down the server
// 2) Re-establish server communication by taking away the MM listener
if (Server.OperationMode.MAINTENANCE == lastEstablishedServerMode) {
printWithTrace("establishCurrentServerMode: MAINTENANCE->NORMAL, clearing agent references");
clearAgentReferences(server);
ServerCommunicationsServiceUtil.getService().safeGetServiceContainer()
.removeCommandListener(getMaintenanceModeListener());
log.info("Notified communication layer of server operation mode " + serverMode);
}
} else if (Server.OperationMode.MAINTENANCE == serverMode) {
// If moving into Maintenance Mode from any other mode then stop processing agent commands
ServerCommunicationsServiceUtil.getService().safeGetServiceContainer()
.addCommandListener(getMaintenanceModeListener());
log.info("Notified communication layer of server operation mode " + serverMode);
} else if (Server.OperationMode.INSTALLED == serverMode
// The server must have just been installed and must be coming for the first time
// up as of this call. So, attempt to update the mode to NORMAL.
// This will prevent a running CloudManagerJob from resetting to DOWN before the real
// ServerManagerJob starts updating the heart beat regularly.
|| Server.OperationMode.DOWN == serverMode) {
// The server can't be DOWN if this code is executing, it means the server must be coming
// up as of this call. So, attempt to update the mode to NORMAL.
// This will prevent a running CloudManagerJob from resetting to DOWN before the real
// ServerManagerJob starts updating the heart beat regularly.
log.info("Notified communication layer of server operation mode " + serverMode);
lastEstablishedServerMode = serverMode;
serverMode = determineServerOperationMode(server.hasStatus(Server.Status.MANUAL_MAINTENANCE_MODE),
storageClientManager.isClusterAvailable(), OperationMode.NORMAL);
if (serverMode == OperationMode.MAINTENANCE) {
ServerCommunicationsServiceUtil.getService().safeGetServiceContainer()
.addCommandListener(getMaintenanceModeListener());
}
}
// If this server just transitioned from INSTALLED to NORMAL operation mode then it
// has just been added to the cloud. Changing the number of servers in the cloud requires agent
// distribution work, even if this is a 1-Server cloud. Generate a request for a repartitioning
// of agent load, it will be executed on the next invocation of the cluster manager job.
// Otherwise, audit the operation mode change as a partition event of interest.
String audit = server.getName() + ": "
+ ((null != lastEstablishedServerMode) ? lastEstablishedServerMode : Server.OperationMode.DOWN)
+ " --> " + serverMode;
if ((Server.OperationMode.NORMAL == serverMode)
&& (Server.OperationMode.INSTALLED == lastEstablishedServerMode)) {
partitionEventManager.cloudPartitionEventRequest(subjectManager.getOverlord(),
PartitionEventType.OPERATION_MODE_CHANGE, audit);
} else {
partitionEventManager.auditPartitionEvent(subjectManager.getOverlord(),
PartitionEventType.OPERATION_MODE_CHANGE, audit);
}
lastEstablishedServerMode = serverMode;
server.setOperationMode(lastEstablishedServerMode);
server.setMtime(System.currentTimeMillis());
} catch (Throwable e) {
log.error("Unable to change HA Server Mode from " + lastEstablishedServerMode + " to " + serverMode + ": "
+ e);
}
}