use of org.batfish.datamodel.EnvironmentMetadata.ProcessingStatus in project batfish by batfish.
the class WorkQueueMgr method processTaskCheckResult.
public synchronized void processTaskCheckResult(QueuedWork work, Task task) throws Exception {
switch(task.getStatus()) {
case Unscheduled:
case InProgress:
work.setStatus(WorkStatusCode.ASSIGNED);
work.recordTaskCheckResult(task);
break;
case TerminatedAbnormally:
case TerminatedByUser:
case TerminatedNormally:
case RequeueFailure:
{
// move the work to completed queue
_queueIncompleteWork.delete(work);
_queueCompletedWork.enque(work);
work.setStatus(WorkStatusCode.fromTerminatedTaskStatus(task.getStatus()));
work.recordTaskCheckResult(task);
// update testrig metadata
WorkItem wItem = work.getWorkItem();
WorkDetails wDetails = work.getDetails();
if (wDetails.workType == WorkType.PARSING) {
ProcessingStatus status = (task.getStatus() == TaskStatus.TerminatedNormally) ? ProcessingStatus.PARSED : ProcessingStatus.PARSING_FAIL;
TestrigMetadataMgr.updateEnvironmentStatus(wItem.getContainerName(), wDetails.baseTestrig, wDetails.baseEnv, status, task.getErrMessage());
} else if (wDetails.workType == WorkType.DATAPLANING) {
// no change in status needed if task.getStatus() is RequeueFailure
if (task.getStatus() == TaskStatus.TerminatedAbnormally || task.getStatus() == TaskStatus.TerminatedByUser) {
TestrigMetadataMgr.updateEnvironmentStatus(wItem.getContainerName(), wDetails.baseTestrig, wDetails.baseEnv, ProcessingStatus.DATAPLANING_FAIL, task.getErrMessage());
} else if (task.getStatus() == TaskStatus.TerminatedNormally) {
TestrigMetadataMgr.updateEnvironmentStatus(wItem.getContainerName(), wDetails.baseTestrig, wDetails.baseEnv, ProcessingStatus.DATAPLANED, null);
}
}
// check if we unblocked anything
if (_blockingWork.contains(wItem.getId())) {
_blockingWork.remove(wItem.getId());
List<QueuedWork> requeueWorks = new LinkedList<>();
for (QueuedWork incompleteWork : _queueIncompleteWork) {
if (incompleteWork.getStatus() == WorkStatusCode.BLOCKED && wDetails.isOverlappingInput(incompleteWork.getDetails())) {
requeueWorks.add(incompleteWork);
}
}
for (QueuedWork requeueWork : requeueWorks) {
_queueIncompleteWork.delete(requeueWork);
requeueWork.setStatus(WorkStatusCode.UNASSIGNED);
}
for (QueuedWork requeueWork : requeueWorks) {
try {
boolean queued = queueUnassignedWork(requeueWork);
if (!queued) {
throw new BatfishException("Failed to requeue previously blocked work " + requeueWork.getId());
}
} catch (Exception e) {
String stackTrace = ExceptionUtils.getStackTrace(e);
_logger.errorf("exception: %s\n", stackTrace);
// put this work back on incomplete queue and process as if it terminatedabnormally
// people may be checking its status and this work may be blocking others
_queueIncompleteWork.enque(requeueWork);
Task fakeTask = new Task(TaskStatus.RequeueFailure, "Couldn't requeue after unblocking");
processTaskCheckResult(requeueWork, fakeTask);
}
}
}
}
break;
case Unknown:
// we mark this unassigned, so we try to schedule it again
work.setStatus(WorkStatusCode.UNASSIGNED);
work.clearAssignment();
break;
case UnreachableOrBadResponse:
{
if (work.getLastTaskCheckResult().getStatus() == TaskStatus.UnreachableOrBadResponse) {
// if we saw the same thing last time around, free the task to be scheduled elsewhere
work.setStatus(WorkStatusCode.UNASSIGNED);
work.clearAssignment();
work.recordTaskCheckResult(task);
// update testrig metadata
WorkItem wItem = work.getWorkItem();
WorkDetails wDetails = work.getDetails();
if (wDetails.workType == WorkType.PARSING || wDetails.workType == WorkType.DATAPLANING) {
EnvironmentMetadata envMetadata = TestrigMetadataMgr.getEnvironmentMetadata(wItem.getContainerName(), wDetails.baseTestrig, wDetails.baseEnv);
if (wDetails.workType == WorkType.PARSING) {
if (envMetadata.getProcessingStatus() != ProcessingStatus.PARSING) {
_logger.errorf("Unexpected status %s when parsing failed for %s / %s", envMetadata.getProcessingStatus(), wDetails.baseTestrig, wDetails.baseEnv);
} else {
TestrigMetadataMgr.updateEnvironmentStatus(wItem.getContainerName(), wDetails.baseTestrig, wDetails.baseEnv, ProcessingStatus.UNINITIALIZED, task.getErrMessage());
}
} else {
// wDetails.workType == WorkType.DATAPLANING
if (envMetadata.getProcessingStatus() != ProcessingStatus.DATAPLANING) {
_logger.errorf("Unexpected status %s when dataplaning failed for %s / %s", envMetadata.getProcessingStatus(), wDetails.baseTestrig, wDetails.baseEnv);
} else {
TestrigMetadataMgr.updateEnvironmentStatus(wItem.getContainerName(), wDetails.baseTestrig, wDetails.baseEnv, ProcessingStatus.PARSED, task.getErrMessage());
}
}
}
} else {
work.setStatus(WorkStatusCode.ASSIGNED);
work.recordTaskCheckResult(task);
}
}
break;
default:
throw new BatfishException("Unhandled " + TaskStatus.class.getCanonicalName() + ": " + task.getStatus());
}
}
Aggregations