Java Code Examples for org.apache.mesos.Protos.TaskStatus#getState()

The following examples show how to use org.apache.mesos.Protos.TaskStatus#getState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NimbusMesosScheduler.java    From storm with Apache License 2.0 6 votes vote down vote up
@Override
public void statusUpdate(SchedulerDriver driver, TaskStatus status) {
  String msg = String.format("Received status update: %s", taskStatusToString(status));
  if (status.getTaskId().getValue().contains("logviewer")) {
    updateLogviewerState(status);
  }
  switch (status.getState()) {
    case TASK_STAGING:
    case TASK_STARTING:
      LOG.debug(msg);
      break;
    case TASK_RUNNING:
      LOG.info(msg);
      break;
    case TASK_FINISHED:
    case TASK_FAILED:
    case TASK_KILLED:
    case TASK_LOST:
    case TASK_ERROR:
      LOG.info(msg);
      break;
    default:
      LOG.warn("Received unrecognized status update: {}", taskStatusToString(status));
      break;
  }
}
 
Example 2
Source File: MesosSchedulerCallbackHandler.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public void statusUpdate(final SchedulerDriver arg0, TaskStatus taskStatus) {
    try {
        String taskId = taskStatus.getTaskId().getValue();
        TaskState taskState = taskStatus.getState();

        TaskStatus effectiveTaskStatus = taskStatusUpdateFitInjection.map(i -> i.afterImmediate("update", taskStatus)).orElse(taskStatus);

        if (isReconcilerUpdateForUnknownTask(effectiveTaskStatus)) {
            if (taskStatus.getState() == TaskState.TASK_LOST) {
                logger.info("Ignoring reconciler TASK_LOST status update for task: {}", taskId);
                return;
            }
            mesosStateTracker.unknownTaskStatusUpdate(taskStatus);
            if (!mesosConfiguration.isAllowReconcilerUpdatesForUnknownTasks()) {
                logger.info("Ignoring reconciler triggered task status update: {}", taskId);
                return;
            }
        } else {
            mesosStateTracker.knownTaskStatusUpdate(taskStatus);
        }

        logMesosCallbackInfo("Task status update: taskId=%s, taskState=%s, message=%s", taskId, taskState, effectiveTaskStatus.getMessage());

        v3StatusUpdate(effectiveTaskStatus);
    } catch (Exception e) {
        logger.error("Unexpected error when handling the status update: {}", taskStatus, e);
        throw e;
    }
}
 
Example 3
Source File: NimbusMesosScheduler.java    From storm with Apache License 2.0 5 votes vote down vote up
private void updateLogviewerState(TaskStatus status) {
  String taskId = status.getTaskId().getValue();
  if (!taskId.contains(MesosCommon.MESOS_COMPONENT_ID_DELIMITER)) {
    LOG.error("updateLogviewerState: taskId for logviewer, {}, isn't formatted correctly so ignoring task update", taskId);
    return;
  }
  String nodeId = taskId.split("\\" + MesosCommon.MESOS_COMPONENT_ID_DELIMITER)[1];
  String logviewerZKPath = String.format("%s/%s", logviewerZkDir, nodeId);
  switch (status.getState()) {
    case TASK_STAGING:
      checkRunningLogviewerState(logviewerZKPath);
      return;
    case TASK_STARTING:
      checkRunningLogviewerState(logviewerZKPath);
      return;
    case TASK_RUNNING:
      checkRunningLogviewerState(logviewerZKPath);
      return;
    case TASK_LOST:
      // this status update can be triggered by the explicit kill and isn't terminal, do not kill again
      break;
    default:
      // explicitly kill the logviewer task to ensure logviewer is terminated
      mesosNimbus._driver.killTask(status.getTaskId());
  }
  // if it gets to this point it means logviewer terminated; update ZK with new logviewer state
  if (zkClient.nodeExists(logviewerZKPath)) {
    LOG.info("updateLogviewerState: Remove logviewer state in zk at {} for logviewer task {}", logviewerZKPath, taskId);
    zkClient.deleteNode(logviewerZKPath);
    LOG.info("updateLogviewerState: Add offer request for logviewer");
    StormSchedulerImpl stormScheduler = (StormSchedulerImpl) mesosNimbus.getForcedScheduler();
    stormScheduler.addOfferRequest(MesosCommon.LOGVIEWER_OFFERS_REQUEST_KEY);
  }
}
 
Example 4
Source File: BdsMesosScheduler.java    From BigDataScript with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked when the status of a task has changed (e.g., a slave is
 * lost and so the task is lost, a task finishes and an executor
 * sends a status update saying so, etc). Note that returning from
 * this callback _acknowledges_ receipt of this status update! If
 * for whatever reason the scheduler aborts during this callback (or
 * the process exits) another status update will be delivered (note,
 * however, that this is currently not true if the slave sending the
 * status update is lost/fails during that time).
 */
@Override
public void statusUpdate(SchedulerDriver driver, TaskStatus status) {
	String taskId = status.getTaskId().getValue();
	if (verbose) Gpr.debug("Scheduler: Status update, task " + taskId + ", state " + status.getState());

	// Find task
	Task task = taskById.get(taskId);
	if (task == null) throw new RuntimeException("task ID '" + taskId + "' not found. This should never happen!");

	// Update state
	switch (status.getState()) {
	case TASK_RUNNING:
		executionerMesos.taskRunning(task);
		break;

	case TASK_FINISHED:
		executionerMesos.taskFinished(task, TaskState.FINISHED);
		break;

	case TASK_ERROR:
	case TASK_FAILED:
		executionerMesos.taskFinished(task, TaskState.ERROR);
		break;

	case TASK_KILLED:
	case TASK_LOST:
		executionerMesos.taskFinished(task, TaskState.KILLED);
		break;

	default:
		throw new RuntimeException("Unhandled Mesos task state: " + status.getState());
	}
}
 
Example 5
Source File: StatusUpdateEventHandler.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
/**
 * Encapsulates the logic to log and respond to the incoming StatusUpdateEvent per the
 * Event TaskStatus state:
 * 
 * 1. TASK_STAGING: mark task as staging wtihin SchedulerState
 * 2. TASK_STARTING: mark task as staging within SchedulerState
 * 3. TASK_RUNNING: mark task as active within SchedulerState
 * 4. TASK_FINISHED: decline outstanding offers and remove task from SchedulerState
 * 5. TASK_FAILED: decline outstanding offers, remove failed, killable tasks from SchedulerState,
 *    mark as pending non-killable, failed tasks
 * 6. TASK_KILLED: decline outstanding offers, removed killed tasks from SchedulerState
 * 7. TASK_LOST: decline outstanding offers, remove killable, lost tasks from SchedulerState,
 *    mark as pending non-killable, lost tasks
 */
@Override
public void onEvent(StatusUpdateEvent event, long sequence, boolean endOfBatch) throws Exception {
  TaskStatus status = event.getStatus();
  this.schedulerState.updateTask(status);
  TaskID taskId = status.getTaskId();
  NodeTask task = schedulerState.getTask(taskId);
  if (task == null) {
    LOGGER.warn("Task: {} not found, status: {}", taskId.getValue(), status.getState());
    schedulerState.removeTask(taskId);
    return;
  }
  LOGGER.info("Status Update for task: {} | state: {}", taskId.getValue(), status.getState());
  TaskState state = status.getState();

  switch (state) {
    case TASK_STAGING:
      schedulerState.makeTaskStaging(taskId);
      break;
    case TASK_STARTING:
      schedulerState.makeTaskStaging(taskId);
      break;
    case TASK_RUNNING:
      schedulerState.makeTaskActive(taskId);
      break;
    case TASK_FINISHED:
      cleanupTask(taskId, task, "finished");
      break;
    case TASK_FAILED:
      cleanupFailedTask(taskId, task, "failed");
      break;
    case TASK_KILLED:
      cleanupTask(taskId, task, "killed");
      break;
    case TASK_LOST:
      cleanupFailedTask(taskId, task, "lost");
      break;
    default:
      LOGGER.error("Invalid state: {}", state);
      break;
  }
}