@GET @Path(BfConsts.SVC_GET_TASKSTATUS_RSC) @Produces(MediaType.APPLICATION_JSON) public JSONArray getTaskStatus(@QueryParam(BfConsts.SVC_TASKID_KEY) String taskId) { _logger.infof("BFS:getTaskStatus %s\n", taskId); try { if (taskId == null || taskId.equals("")) { return new JSONArray(Arrays.asList(BfConsts.SVC_FAILURE_KEY, "taskid not supplied")); } Task task = Driver.getTaskFromLog(taskId); if (task == null) { task = new Task(TaskStatus.Unknown); } String taskStr = BatfishObjectMapper.writePrettyString(task); return new JSONArray(Arrays.asList(BfConsts.SVC_SUCCESS_KEY, taskStr)); } catch (Exception e) { return new JSONArray(Arrays.asList(BfConsts.SVC_FAILURE_KEY, e.getMessage())); } }
public static synchronized Task killTask(String taskId) { Task task = _taskLog.get(taskId); if (_mainSettings.getParentPid() <= 0) { throw new BatfishException("Cannot kill tasks when started in non-watchdog mode"); } else if (task == null) { throw new BatfishException("Task with provided id not found: " + taskId); } else if (task.getStatus().isTerminated()) { throw new BatfishException("Task with provided id already terminated " + taskId); } else { // update task details in case a new query for status check comes in task.newBatch("Got kill request"); task.setStatus(TaskStatus.TerminatedByUser); task.setTerminated(new Date()); task.setErrMessage("Terminated by user"); // we die after a little bit, to allow for the response making it back to the coordinator new java.util.Timer() .schedule( new java.util.TimerTask() { @Override public void run() { System.exit(0); } }, 3000); return task; } }
settings.setLogger(jobLogger); final Task task = new Task(args); .startActive()) { assert runBatfishSpan != null; // avoid unused warning task.setStatus(TaskStatus.InProgress); String errMsg = runBatfish(settings); if (errMsg == null) { task.setStatus(TaskStatus.TerminatedNormally); } else { task.setStatus(TaskStatus.TerminatedAbnormally); task.setErrMessage(errMsg); task.setTerminated(new Date()); jobLogger.close(); makeIdle();
switch (task.getStatus()) { case Unscheduled: case InProgress: work.setStatus(WorkStatusCode.fromTerminatedTaskStatus(task.getStatus())); work.recordTaskCheckResult(task); if (wDetails.workType == WorkType.PARSING) { ProcessingStatus status = (task.getStatus() == TaskStatus.TerminatedNormally) ? ProcessingStatus.PARSED : ProcessingStatus.PARSING_FAIL; WorkQueueMgr.updateInitializationStatus( wItem.getContainerName(), wDetails.baseTestrig, status, task.getErrMessage()); } else if (wDetails.workType == WorkType.DATAPLANING) { if (task.getStatus() == TaskStatus.TerminatedAbnormally || task.getStatus() == TaskStatus.TerminatedByUser) { WorkQueueMgr.updateInitializationStatus( wItem.getContainerName(), wDetails.baseTestrig, ProcessingStatus.DATAPLANING_FAIL, task.getErrMessage()); } else if (task.getStatus() == TaskStatus.TerminatedNormally) { WorkQueueMgr.updateInitializationStatus( wItem.getContainerName(), new Task( TaskStatus.RequeueFailure,
private void checkTask(QueuedWork work, String worker) { _logger.infof("WM:CheckWork: Trying to check %s on %s\n", work, worker); Task task = new Task(TaskStatus.UnreachableOrBadResponse); String taskStr = array.get(1).toString(); task = BatfishObjectMapper.mapper().readValue(taskStr, Task.class); if (task.getStatus() == null) { _logger.error("did not see status key in json response\n"); if (task.getStatus().isTerminated()) { Main.getPoolMgr().refreshWorkerStatus(worker);
public Task(TaskStatus status, String description) { this(status); newBatch(description); }
@Override public String toString() { return String.format( "%s [%s] [%s %s %s] [%s] [%s, %s]", _workItem.toString(), _status, _dateCreated, _dateAssigned, _dateTerminated, _assignedWorker, (_lastTaskCheckResult == null) ? "null" : _lastTaskCheckResult.getStatus(), _dateLastTaskCheckedStatus); }
List<Batch> batches = task.getBatches(); _logger.outputf(".... %s: %s\n", task.getTerminated(), status);
public static synchronized AtomicInteger newBatch( Settings settings, String description, int jobs) { Batch batch = null; Task task = getTask(settings); if (task != null) { batch = task.newBatch(description); batch.setSize(jobs); return batch.getCompleted(); } else { return new AtomicInteger(); } }
public boolean killWork(QueuedWork work) { String worker = work.getAssignedWorker(); if (worker != null) { return killWork(work, worker); } // (worker = null) => this work was not assigned in the first place boolean killed = false; Task fakeTask = new Task(TaskStatus.TerminatedByUser, "Killed unassigned work"); try { _workQueueMgr.processTaskCheckResult(work, fakeTask); killed = true; } catch (Exception e) { _logger.errorf("exception: %s\n", Throwables.getStackTraceAsString(e)); } return killed; }
new Task(TaskStatus.TerminatedByUser, "worker appears dead before responding"); _workQueueMgr.processTaskCheckResult(work, fakeTask); killed = true;
case STATUS_INPROGRESS: Task task = new Task(TaskStatus.InProgress); _workQueueMgr.processTaskCheckResult(action.work, task); case STATUS_TERMINATED_ABNORMALLY: Task task = new Task(TaskStatus.TerminatedAbnormally); _workQueueMgr.processTaskCheckResult(action.work, task); case STATUS_TERMINATED_NORMALLY: Task task = new Task(TaskStatus.TerminatedNormally); _workQueueMgr.processTaskCheckResult(action.work, task); case STATUS_UNREACHABLE: Task task = new Task(TaskStatus.UnreachableOrBadResponse); _workQueueMgr.processTaskCheckResult(action.work, task);
@Test public void processTaskCheckTerminatedByUser() throws Exception { initSnapshotMetadata("testrig", ProcessingStatus.UNINITIALIZED); QueuedWork work1 = resolvedQueuedWork( new WorkItem(NETWORK, "testrig"), new WorkDetails("testrig", WorkType.PARSING)); doAction(new Action(ActionType.QUEUE, work1)); _workQueueMgr.processTaskCheckResult(work1, new Task(TaskStatus.TerminatedByUser, "Fake")); /* * after processing the termination task, * 1) the status of work should be terminatedbyuser * 2) incomplete queue should be empty */ assertThat(work1.getStatus(), equalTo(WorkStatusCode.TERMINATEDBYUSER)); assertThat(_workQueueMgr.getLength(QueueType.INCOMPLETE), equalTo(0L)); }