processEntry.getValue().setTimeWindowRun(twr);
twr.setStart(millis);
}
}
}
ManagedProcess deployedProcess = null;
synchronized (monitor) {
for (ManagedProcess dProcess : deployedProcesses) {
// Find ManagedProcess instance the DuccProcess
// instance is associated with
if (dProcess.getDuccProcess().getDuccId().getUnique()
.equals(duccEvent.getDuccProcessId())) {
deployedProcess = dProcess;
break;
}
}
}
if (processEntry.getValue().getProcessState() != ProcessState.Running
&& duccEvent.getState().equals(ProcessState.Running) && deployedProcess != null) {
// cancel process initialization timer.
deployedProcess.stopInitializationTimer();
}
// if a JP process has been deallocated, ignore any updates
// from it. It's stopping.
if (processEntry.getValue().isDeallocated()) {
// stop collecting process stats from /proc/<pid>/statm
if (duccEvent.getPid() != null) {
super.getContext().stopRoute(duccEvent.getPid());
}
return;
}
logger.info(methodName, null, ">>>> Agent Handling Process Update - Ducc Id: "
+ processEntry.getValue().getDuccId() + " PID:" + duccEvent.getPid() + " Status:"
+ duccEvent.getState() + " Deallocated:"
+ processEntry.getValue().isDeallocated());
if (deployedProcess != null && deployedProcess.getSocketEndpoint() == null
&& duccEvent.getServiceEdnpoint() != null) {
deployedProcess.setSocketEndpoint(duccEvent.getServiceEdnpoint());
}
// This is a delayed stop. Previously a request to stop the
// process was received
// but the PID was not available yet. Instead a flag was set
// to initiate a
// stop after the process reports the PID.
if (deployedProcess != null && deployedProcess.killAfterLaunch()) {
logger.info(methodName, null, ">>>> Process Ducc Id:"
+ processEntry.getValue().getDuccId()
+ " Was Previously Tagged for Kill While It Was Starting");
undeployProcess(processEntry.getValue());
} else if ( deployedProcess != null && deployedProcess.doKill() &&
deployedProcess.getDuccProcess().getProcessState().equals(ProcessState.Stopped) ) {
deployedProcess.getDuccProcess().setReasonForStoppingProcess(ReasonForStoppingProcess.KilledByDucc.toString());
} else if ( deployedProcess != null && ( deployedProcess.doKill()
|| deployedProcess.getDuccProcess().getProcessState().equals(ProcessState.Failed)
|| deployedProcess.getDuccProcess().getProcessState().equals(ProcessState.Killed)) ) {
// The process has already stopped, but managed to send
// the last update before dying. Ignore the update
return;
} else if (changeState(duccEvent.getState())) {
processEntry.getValue().setProcessState(duccEvent.getState());
// if the process is Stopping, it must have hit an error threshold
}
// Check if MemoryCollector should be created for this
// process. It collects
// resident memory of the process at regular intervals.
// Should only be added
// once for each process. This route will have its id set to
// process PID.
if (addProcessMemoryCollector(duccEvent.getPid())
&& (duccEvent.getState().equals(ProcessState.Initializing) || duccEvent
.getState().equals(ProcessState.Running))) {
RouteBuilder rb = new ProcessMemoryUsageRoute(this, processEntry.getValue(),
deployedProcess);
super.getContext().addRoutes(rb);
logger.info(
methodName,
null,
">>>> Agent Added new Process Memory Collector Thread for Process:"
+ duccEvent.getPid());
} else if (duccEvent.getState().equals(ProcessState.Stopped)
|| duccEvent.getState().equals(ProcessState.Failed)
|| duccEvent.getState().equals(ProcessState.Killed)) {
super.getContext().stopRoute(duccEvent.getPid());
if ( deployedProcess.getMetricsProcessor() != null ) {
deployedProcess.getMetricsProcessor().close(); // close open fds (stat and statm files)
}
logger.info(methodName, null,
"----------- Agent Stopped ProcessMemoryUsagePollingRouter for Process:"
+ duccEvent.getPid());
} else if (duccEvent.getState().equals(ProcessState.FailedInitialization)) {
deployedProcess.getDuccProcess().setReasonForStoppingProcess(
ReasonForStoppingProcess.FailedInitialization.toString());
// Mark the process for death. Doesnt actually kill the
// process
deployedProcess.kill();
logger.info(methodName, null, ">>>> Agent Handling Process FailedInitialization. PID:"
+ duccEvent.getPid() + " Killing Process");
super.getContext().stopRoute(duccEvent.getPid());
logger.info(methodName, null,
"----------- Agent Stopped ProcessMemoryUsagePollingRouter for Process:"
+ duccEvent.getPid() + ". Process Failed Initialization");
// kill the process
undeployProcess(processEntry.getValue());
} else if (duccEvent.getState().equals(ProcessState.InitializationTimeout)) {
deployedProcess.getDuccProcess().setReasonForStoppingProcess(
ReasonForStoppingProcess.InitializationTimeout.toString());
// Mark the process for death. Doesnt actually kill the
// process
deployedProcess.kill();
logger.info(methodName, null, ">>>> Agent Handling Process InitializationTimeout. PID:"
+ duccEvent.getPid() + " Killing Process");
super.getContext().stopRoute(duccEvent.getPid());
logger.info(methodName, null,
"----------- Agent Stopped ProcessMemoryUsagePollingRouter for Process:"
+ duccEvent.getPid()
+ ". Agent Timedout Waiting For Process to Initialize");
// kill the process
undeployProcess(processEntry.getValue());
}
else if (duccEvent.getState().equals(ProcessState.Stopping)) {
deployedProcess.getDuccProcess().setProcessState(ProcessState.Stopping);
processEntry.getValue().
setReasonForStoppingProcess(ReasonForStoppingProcess.ExceededErrorThreshold.toString());
deployedProcess.setStopping();
}
if (duccEvent.getUimaPipeline() != null) {
StringBuffer buffer = new StringBuffer("\t\tUima Pipeline -");
for (IUimaPipelineAEComponent uimaAeState : duccEvent.getUimaPipeline()) {
buffer.append("\n\t\tAE:").append(uimaAeState.getAeName()).append(" state:")