Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly Update Job Status to Running After Agent Restarts #386

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,19 @@ private void addStatusToJobContainer(CloudVmStatus status, CloudVmStatusContaine
boolean rampPaused = true;
boolean stopped = true;
boolean running = true;
int activeAgentCount = 0;

LOG.debug(new ObjectMessage(ImmutableMap.of("jobId", cloudVmStatusContainer.getJobId(), "message", "DEBUG: Starting aggregation loop", "totalStatuses", cloudVmStatusContainer.getStatuses().size())));

// look up the job
JobInstance job = jobInstanceDao.get().findById(Integer.parseInt(status.getJobId()));
for (CloudVmStatus s : cloudVmStatusContainer.getStatuses()) {
JobStatus jobStatus = s.getJobStatus();
boolean isActive = (s.getEndTime() == null && s.getVmStatus() != VMStatus.terminated);
if (isActive) {
activeAgentCount++; // track active agents (tracking agent restarts)
}

if (jobStatus != JobStatus.Completed) { // If no VMs are Completed
isFinished = false;
}
Expand All @@ -329,10 +337,23 @@ private void addStatusToJobContainer(CloudVmStatus status, CloudVmStatusContaine
if (jobStatus != JobStatus.Stopped) { // If no VMs are Stopped
stopped = false;
}
if (jobStatus != JobStatus.Running) { // If no VMs are Running
running = false;
if (jobStatus != JobStatus.Running) {
if (isActive) {
running = false;
LOG.debug(new ObjectMessage(ImmutableMap.of("jobId", cloudVmStatusContainer.getJobId(), "message", "DEBUG: Active agent not Running, setting overall running=false", "instanceId", s.getInstanceId(), "agentJobStatus", jobStatus)));
} else {
// ignore terminated agent for running flag
LOG.debug(new ObjectMessage(ImmutableMap.of("jobId", cloudVmStatusContainer.getJobId(), "message", "DEBUG: Ignoring terminated agent status for 'running' flag check", "instanceId", s.getInstanceId(), "agentJobStatus", jobStatus)));
}
}
}

if (activeAgentCount == 0) {
// correcting running flag for zero active agents
LOG.debug(new ObjectMessage(ImmutableMap.of("jobId", cloudVmStatusContainer.getJobId(), "message", "DEBUG: No active agents found after loop, forcing running=false")));
running = false;
}

if (isFinished) {
LOG.info(new ObjectMessage(ImmutableMap.of("Message","Setting end time on container " + cloudVmStatusContainer.getJobId())));
if (cloudVmStatusContainer.getEndTime() == null) {
Expand Down