// make sure instance exists to start it
if (!instanceExists(instanceName)) {
// instance doesn't exist, this could be caused by a sync error
// with the nodeagent so it doesn't know to create the instance
// and then someone tries to start or stop it
throw new AgentException(_strMgr.getString(
"nodeAgent.instanceDoesNotExist", instanceName));
}
//Ensure that the instance is in a stopped state before starting it.
ensureInstanceIsStopped(instanceName, synchronizeInstance);
if (synchronizeInstance) {
try {
//beginning instance synchronization
InstanceStatus.getInstance().updateStatus(
instanceName, Status.kInstanceSynchronizingCode);
// synchronise of behalf of the instance, should only be done
// on direct start invocation
getLogger().log(Level.INFO,
"NodeAgent synchronizing for instance", instanceName);
synchronizeInstanceWithDAS(instanceName);
} catch (AgentException ae) {
//synchronization failed
InstanceStatus.getInstance().updateStatusFromAdminChannel(
instanceName, Status.kInstanceNotRunningCode);
// need to throw exception so start-instance command show
// proper error and fails
debug("ERROR IN SYNCHRONIZATION!!!! " + ae);
throw ae;
}
}
debug("Release Lock: " + instanceName);
}
// there was no sync or it succeeded
try {
//beginning instance startup
debug("Getting ready to have ProcessManger start the instance: " + instanceName);
InstanceStatus.getInstance().updateStatus(
instanceName, Status.kInstanceStartingCode);
// always start when asked (not checking for now)
// add instance to ProcessManager & start it
ProcessManager.getInstance().addProcessInstance(instanceName,
new ProcessInstanceInternal(instanceName));
ProcessManager.getInstance().startProcess(instanceName);
//startup succeeded
InstanceStatus.getInstance().updateStatusFromAdminChannel(
instanceName, Status.kInstanceRunningCode);
} catch (Exception e) {
//startup failed. We put the instance in a not running state so that
// the user can attempt to start it again.
InstanceStatus.getInstance().updateStatusFromAdminChannel(
instanceName, Status.kInstanceNotRunningCode);
StringManagerBase sm = StringManagerBase.getStringManager(
getLogger().getResourceBundleName());
getLogger().log(Level.WARNING,
sm.getString("nodeagent.start.instance.exception", instanceName), e);
throw new AgentException(e);
}
}