org.apache.mesos.Protos.TaskStatus Java Examples

The following examples show how to use org.apache.mesos.Protos.TaskStatus. 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: TaskLabelReader.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether or not a readiness check succeeded.  If the indicated TaskInfo does not have
 * a readiness check, then this method indicates that the readiness check has passed.  Otherwise
 * failures to parse readiness checks are interpreted as readiness check failures.  If some value other
 * than "true" is present in the readiness check label of the TaskStatus, the readiness check has
 * failed.
 *
 * @param taskStatus A TaskStatus which may or may not contain a readiness check outcome label
 * @return the result of a readiness check for the indicated TaskStatus
 */
public boolean isReadinessCheckSucceeded(TaskStatus taskStatus) {
  Optional<String> readinessCheckOptional =
      reader.getOptional(LabelConstants.READINESS_CHECK_LABEL);
  if (!readinessCheckOptional.isPresent() && !taskStatus.hasCheckStatus()) {
    // check not applicable: PASS
    return true;
  } else if (taskStatus.hasCheckStatus()) {
    return taskStatus.getCheckStatus().getCommand().hasExitCode() &&
        taskStatus.getCheckStatus().getCommand().getExitCode() == 0;
  }

  // Special case: the 'readiness check passed' bit is set in TaskStatus (by the executor),
  // not in TaskInfo like other labels
  for (Label statusLabel : taskStatus.getLabels().getLabelsList()) {
    if (statusLabel.getKey().equals(LabelConstants.READINESS_CHECK_PASSED_LABEL)) {
      return statusLabel.getValue().equals(LabelConstants.BOOLEAN_LABEL_TRUE_VALUE);
    }
  }
  return false;
}
 
Example #2
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status acknowledgeStatusUpdate(final TaskStatus taskStatus)
{
    checkNotNull(taskStatus, "taskStatus is null");
    checkState(!implicitAcknowledges, "Can not call acknowledgeStatusUpdate with implicitAcknowledges turned off");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final StatusUpdateAcknowledgementMessage message = StatusUpdateAcknowledgementMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .setSlaveId(taskStatus.getSlaveId())
        .setTaskId(taskStatus.getTaskId())
        .setUuid(taskStatus.getUuid())
        .build();

    eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), message));

    return context.getStateMachine();
}
 
Example #3
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 #4
Source File: MesosSupervisor.java    From storm with Apache License 2.0 6 votes vote down vote up
@Override
public void killedWorker(int port) {
  LOG.info("killedWorker: executor {} removing port {} assignment and sending " +
      "TASK_FINISHED update to Mesos", _executorId, port);
  TaskID taskId = _taskAssignments.deregister(port);
  if (taskId == null) {
    LOG.error("killedWorker: Executor {} failed to find TaskID for port {}, so not " +
        "issuing TaskStatus update to Mesos for this dead task.", _executorId, port);
    return;
  }
  TaskStatus status = TaskStatus.newBuilder()
      .setState(TaskState.TASK_FINISHED)
      .setTaskId(taskId)
      .build();
  _driver.sendStatusUpdate(status);
}
 
Example #5
Source File: REEFExecutor.java    From reef with Apache License 2.0 6 votes vote down vote up
private void onRuntimeError() {
  // Shutdown REEF Evaluator
  if (this.evaluatorProcess != null) {
    this.evaluatorProcess.destroy();
  }
  mesosExecutorDriver.sendStatusUpdate(TaskStatus.newBuilder()
      .setTaskId(TaskID.newBuilder()
          .setValue(mesosExecutorId)
          .build())
      .setState(TaskState.TASK_FAILED)
      .setMessage("Evaluator Process exited with status " + String.valueOf(evaluatorProcessExitValue))
      .build());

  // Shutdown Mesos Executor
  this.executorService.shutdown();
  this.mesosExecutorDriver.stop();
}
 
Example #6
Source File: ESTaskStatus.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
public void setStatus(TaskStatus status) throws IllegalStateException {
    try {
        LOGGER.debug("Writing task status to zk: [" + status.getState() + "] " + status.getTaskId().getValue());
        statePath.mkdir(getKey());
        state.set(getKey(), status);
    } catch (IOException e) {
        throw new IllegalStateException("Unable to write task status to zookeeper", e);
    }
}
 
Example #7
Source File: DaemonTaskSchedulerTest.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 5 votes vote down vote up
@Test
public void assertJobRunWithEventSampling() throws Exception {
    when(shardingContexts.getJobEventSamplingCount()).thenReturn(2);
    when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
    when(jobFacade.loadJobRootConfiguration(true)).thenReturn(new TestScriptJobConfiguration("test.sh"));
    daemonJob.execute(jobExecutionContext);
    verify(shardingContexts).setCurrentJobEventSamplingCount(1);
    verify(shardingContexts).setAllowSendJobEvent(false);
    when(shardingContexts.getCurrentJobEventSamplingCount()).thenReturn(1);
    daemonJob.execute(jobExecutionContext);
    verify(shardingContexts).setAllowSendJobEvent(true);
    verify(executorDriver).sendStatusUpdate(TaskStatus.newBuilder().setTaskId(taskId).setState(TaskState.TASK_RUNNING).setMessage("BEGIN").build());
    verify(executorDriver).sendStatusUpdate(TaskStatus.newBuilder().setTaskId(taskId).setState(TaskState.TASK_RUNNING).setMessage("COMPLETE").build());
    verify(shardingContexts).setCurrentJobEventSamplingCount(0);
}
 
Example #8
Source File: ESTaskStatus.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
public TaskStatus getStatus() throws IllegalStateException {
    try {
        return state.get(getKey());
    } catch (IOException e) {
        throw new IllegalStateException("Unable to get task status from zookeeper", e);
    }
}
 
Example #9
Source File: ESTaskStatus.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
public TaskStatus getDefaultStatus() {
    return TaskStatus.newBuilder()
            .setState(TaskState.TASK_STAGING)
                .setTaskId(taskInfo.getTaskId())
                .setMessage(DEFAULT_STATUS_NO_MESSAGE_SET)
                .build();
}
 
Example #10
Source File: MyriadExecutor.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
@Override
public void killTask(ExecutorDriver driver, TaskID taskId) {
  String taskIdString = taskId.toString();
  LOGGER.debug("killTask received for taskId: " + taskIdString);
  TaskStatus status;

  if (!taskIdString.contains(MyriadExecutorAuxService.YARN_CONTAINER_TASK_ID_PREFIX)) {
    // Inform mesos of killing all tasks corresponding to yarn containers that are
    // currently running 
    synchronized (containerIds) {
      for (String containerId : containerIds) {
        Protos.TaskID containerTaskId = Protos.TaskID.newBuilder().setValue(
            MyriadExecutorAuxService.YARN_CONTAINER_TASK_ID_PREFIX + containerId).build();
        status = TaskStatus.newBuilder().setTaskId(containerTaskId).setState(TaskState.TASK_KILLED).build();
        driver.sendStatusUpdate(status);
      }
    }

    // Now kill the node manager task
    status = TaskStatus.newBuilder().setTaskId(taskId).setState(TaskState.TASK_KILLED).build();
    driver.sendStatusUpdate(status);
    LOGGER.info("NodeManager shutdown after receiving KILL_TASK for taskId {}", taskIdString);
    Runtime.getRuntime().exit(0);

  } else {
    status = TaskStatus.newBuilder().setTaskId(taskId).setState(TaskState.TASK_KILLED).build();
    driver.sendStatusUpdate(status);
    synchronized (containerIds) {
      //Likely the container isn't in here, but just in case remove it.
      if (containerIds.remove(taskIdString.substring(MyriadExecutorAuxService.YARN_CONTAINER_FULL_PREFIX.length(),
          taskIdString.length()))) {
        LOGGER.debug("Removed taskId {} from containerIds", taskIdString);
      }
    }
    LOGGER.debug("Killing " + taskId);
  }
}
 
Example #11
Source File: MyriadExecutorAuxService.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
private void sendStatus(ContainerId containerId, TaskState taskState) {
  Protos.TaskID taskId = Protos.TaskID.newBuilder().setValue(YARN_CONTAINER_TASK_ID_PREFIX + containerId.toString()).build();

  TaskStatus status = TaskStatus.newBuilder().setTaskId(taskId).setState(taskState).build();
  driver.sendStatusUpdate(status);
  LOGGER.debug("Sent status " + taskState + " for taskId " + taskId);
}
 
Example #12
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Override
public Status reconcileTasks(final Collection<TaskStatus> statuses)
{
    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final ReconcileTasksMessage message = ReconcileTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addAllStatuses(statuses)
        .build();
    eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), message));

    return context.getStateMachine();
}
 
Example #13
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 5 votes vote down vote up
private void loseTask(final TaskInfo taskInfo, final String reason)
{
    final StatusUpdateMessage statusUpdate = StatusUpdateMessage.newBuilder()
        .setUpdate(StatusUpdate.newBuilder()
            .setFrameworkId(context.getFrameworkId())
            .setSlaveId(taskInfo.getSlaveId())
            .setExecutorId(taskInfo.getExecutor().getExecutorId())
            .setStatus(TaskStatus.newBuilder().setTaskId(taskInfo.getTaskId()).setState(TaskState.TASK_LOST).setMessage(reason))
            .setTimestamp(TimeUtil.currentTime())
            .setUuid(UUIDUtil.uuidBytes(UUID.randomUUID())))
        .build();

    eventBus.post(new StatusUpdateMessageEnvelope(context.getDriverUPID(), context.getDriverUPID(), statusUpdate));
}
 
Example #14
Source File: REEFExecutor.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * We assume a long-running Mesos Task that manages a REEF Evaluator process, leveraging Mesos Executor's interface.
 */
@Override
public void launchTask(final ExecutorDriver driver, final TaskInfo task) {
  driver.sendStatusUpdate(TaskStatus.newBuilder()
      .setTaskId(TaskID.newBuilder().setValue(this.mesosExecutorId).build())
      .setState(TaskState.TASK_STARTING)
      .setSlaveId(task.getSlaveId())
      .setMessage(this.mesosRemoteManager.getMyIdentifier())
      .build());
}
 
Example #15
Source File: REEFExecutor.java    From reef with Apache License 2.0 5 votes vote down vote up
private void onStop() {
  // Shutdown REEF Evaluator
  if (this.evaluatorProcess != null) {
    this.evaluatorProcess.destroy();
    mesosExecutorDriver.sendStatusUpdate(TaskStatus.newBuilder()
        .setTaskId(TaskID.newBuilder()
            .setValue(mesosExecutorId)
            .build())
        .setState(TaskState.TASK_FINISHED)
        .setMessage("Evaluator Process exited with status " + String.valueOf(evaluatorProcessExitValue))
        .build());
  } else {
    mesosExecutorDriver.sendStatusUpdate(TaskStatus.newBuilder()
        .setTaskId(TaskID.newBuilder()
            .setValue(mesosExecutorId)
            .build())
        .setState(TaskState.TASK_FINISHED)
        .setData(ByteString.copyFromUtf8("eval_not_run"))
        // TODO[JIRA REEF-102]: a hack to pass closeEvaluator test, replace this with a better interface
        .setMessage("Evaluator Process exited with status " + String.valueOf(evaluatorProcessExitValue))
        .build());
  }

  // Shutdown Mesos Executor
  this.executorService.shutdown();
  this.mesosExecutorDriver.stop();
}
 
Example #16
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 #17
Source File: PrettyProtobuf.java    From storm with Apache License 2.0 5 votes vote down vote up
/**
 * Pretty-print mesos protobuf TaskStatus.
 */
public static String taskStatusToString(TaskStatus taskStatus) {
  Map<String, String> map = new LinkedHashMap<>();
  map.put("task_id", taskStatus.getTaskId().getValue());
  map.put("slave_id", taskStatus.getSlaveId().getValue());
  map.put("state", taskStatus.getState().toString());
  if (taskStatus.hasMessage()) {
    map.put("message", taskStatus.getMessage());
  }
  return JSONValue.toJSONString(map);
}
 
Example #18
Source File: MesosNimbus.java    From storm with Apache License 2.0 5 votes vote down vote up
public void doRegistration(final SchedulerDriver driver, Protos.FrameworkID id) {
  _driver = driver;
  // Now that we've set the driver, we can create our scheduler
  _stormScheduler = new StormSchedulerImpl(_driver);

  _state.put(FRAMEWORK_ID, id.getValue());
  _offers = new HashMap<Protos.OfferID, Protos.Offer>();

  if (_enabledLogviewerSidecar) {

    _timer.scheduleAtFixedRate(new TimerTask() {
      @Override
      public void run() {
        // performing "explicit" reconciliation; master will respond with the latest state for all logviewer tasks
        // in the framework scheduler's statusUpdate() method
        List<TaskStatus> taskStatuses = new ArrayList<TaskStatus>();
        List<String> logviewerPaths = _zkClient.getChildren(_logviewerZkDir);
        if (logviewerPaths == null) {
          _driver.reconcileTasks(taskStatuses);
          return;
        }
        for (String path : logviewerPaths) {
          TaskID logviewerTaskId = TaskID.newBuilder()
                                         .setValue(new String(_zkClient.getNodeData(String.format("%s/%s", _logviewerZkDir, path))))
                                         .build();
          TaskStatus logviewerTaskStatus = TaskStatus.newBuilder()
                                                     .setTaskId(logviewerTaskId)
                                                     .setState(TaskState.TASK_RUNNING)
                                                     .build();
          taskStatuses.add(logviewerTaskStatus);
        }
        _driver.reconcileTasks(taskStatuses);
        LOG.info("Performing task reconciliation between scheduler and master on following tasks: {}", taskStatusListToTaskIDsString(taskStatuses));
      }
    }, 0, TASK_RECONCILIATION_INTERVAL); // reconciliation performed every 5 minutes
  }
}
 
Example #19
Source File: SchedulerDriverService.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void acknowledgeStatusUpdate(Protos.TaskStatus status) {
  ensureRunning();

  TaskStatus convertedStatus = ProtosConversion.convert(status);
  Futures.getUnchecked(driverFuture).acknowledgeStatusUpdate(convertedStatus);
}
 
Example #20
Source File: SchedulerDriverService.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void reconcileTasks(Collection<Protos.TaskStatus> statuses) {
  ensureRunning();

  Collection<TaskStatus> convertedStatuses =
      Collections2.transform(statuses, ProtosConversion::convert);
  Futures.getUnchecked(driverFuture).reconcileTasks(convertedStatuses);
}
 
Example #21
Source File: FakeMaster.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
public void changeState(TaskID task, TaskState state) {
  assertNotStopped();

  checkState(activeTasks.containsKey(task), "Task " + task + " does not exist.");
  Futures.getUnchecked(schedulerFuture).statusUpdate(this, TaskStatus.newBuilder()
      .setTaskId(task)
      .setState(state)
      .build());
}
 
Example #22
Source File: FakeMaster.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Status launchTasks(Collection<OfferID> offerIds, Collection<TaskInfo> tasks) {
  assertNotStopped();

  OfferID id = Iterables.getOnlyElement(offerIds);
  Offer offer = sentOffers.remove(id);
  checkState(offer != null, "Offer " + id + " is invalid.");

  final TaskInfo task = Iterables.getOnlyElement(tasks);
  synchronized (activeTasks) {
    checkState(
        !activeTasks.containsKey(task.getTaskId()),
        "Task " + task.getTaskId() + " already exists.");
    activeTasks.put(task.getTaskId(), new Task(offer, task));
  }

  executor.schedule(
      () -> Futures.getUnchecked(schedulerFuture).statusUpdate(
          this,
          TaskStatus.newBuilder()
              .setTaskId(task.getTaskId())
              .setState(TaskState.TASK_RUNNING)
              .build()),
      1,
      TimeUnit.SECONDS);

  return Status.DRIVER_RUNNING;
}
 
Example #23
Source File: FakeMaster.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Status killTask(TaskID taskId) {
  assertNotStopped();

  Task task = activeTasks.remove(taskId);
  checkState(task != null, "Task " + taskId + " not found.");
  idleOffers.put(task.getOffer().getId(), task.getOffer());

  Futures.getUnchecked(schedulerFuture).statusUpdate(this, TaskStatus.newBuilder()
      .setTaskId(taskId)
      .setState(TaskState.TASK_FINISHED)
      .build());

  return Status.DRIVER_RUNNING;
}
 
Example #24
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 #25
Source File: ExplicitReconciler.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Used to update the Reconciler with current task status. This is effectively an asynchronous
 * callback which is triggered by a call to reconcile().
 * <p>
 * NOTE: THIS CALL MUST BE THREAD-SAFE AGAINST OTHER RECONCILER CALLS
 *
 * @param status The TaskStatus used to update the Reconciler.
 */
public void update(final Protos.TaskStatus status) {
  rwlock.lock();
  try {
    if (unreconciled.isEmpty()) {
      return;
    }
    // we've gotten a task status update callback. mark this task as reconciled, if needed
    unreconciled.remove(status.getTaskId().getValue());
    logger.info("Reconciled task: {} ({} remaining tasks)",
        status.getTaskId().getValue(), unreconciled.size());
  } finally {
    rwlock.unlock();
  }
}
 
Example #26
Source File: DaemonTaskSchedulerTest.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 5 votes vote down vote up
@Test
public void assertJobRun() throws Exception {
    when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
    when(jobFacade.loadJobRootConfiguration(true)).thenReturn(new TestScriptJobConfiguration("test.sh"));
    daemonJob.execute(jobExecutionContext);
    verify(shardingContexts).setAllowSendJobEvent(true);
    verify(executorDriver).sendStatusUpdate(TaskStatus.newBuilder().setTaskId(taskId).setState(TaskState.TASK_RUNNING).setMessage("BEGIN").build());
    verify(executorDriver).sendStatusUpdate(TaskStatus.newBuilder().setTaskId(taskId).setState(TaskState.TASK_RUNNING).setMessage("COMPLETE").build());
    verify(shardingContexts).setCurrentJobEventSamplingCount(0);
}
 
Example #27
Source File: BackupManagerTest.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartCompleteStop() {
    when(mockState.fetchProperty(BackupManager.BACKUP_KEY)).thenThrow(
            new StateStoreException("no state found"));
    BackupManager manager = new BackupManager(mockCassandraState, mockProvider, mockState);

    final CassandraDaemonTask daemonTask = Mockito.mock(CassandraDaemonTask.class);
    Mockito.when(daemonTask.getState()).thenReturn(Protos.TaskState.TASK_RUNNING);
    final HashMap<String, CassandraDaemonTask> map = new HashMap<>();
    map.put(NODE_0, daemonTask);
    when(mockCassandraState.getDaemons()).thenReturn(map);
    when(mockCassandraState.get(SNAPSHOT_NODE_0)).thenReturn(Optional.of(daemonTask));
    when(mockCassandraState.get(UPLOAD_NODE_0)).thenReturn(Optional.of(daemonTask));
    when(mockCassandraState.get(BACKUPSCHEMA_NODE_0)).thenReturn(Optional.of(daemonTask));

    manager.start(emptyRequest());

    assertFalse(manager.isComplete());
    assertTrue(manager.isInProgress());
    assertEquals(3, manager.getPhases().size());

    Mockito.when(daemonTask.getState()).thenReturn(Protos.TaskState.TASK_FINISHED);
    // notify steps to check for TASK_FINISHED:
    for (Phase phase : manager.getPhases()) {
        for (Step step : phase.getChildren()) {
            step.update(TaskStatus.getDefaultInstance());
        }
    }

    assertTrue(manager.isComplete());
    assertFalse(manager.isInProgress());
    assertEquals(3, manager.getPhases().size());

    manager.stop();

    assertFalse(manager.isComplete());
    assertFalse(manager.isInProgress());
    assertTrue(manager.getPhases().isEmpty());
}
 
Example #28
Source File: ExplicitReconciler.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Starts reconciliation against the provided tasks, which should represent what the Scheduler
 * currently knows about task status.
 * <p>
 * NOTE: THIS CALL MUST BE THREAD-SAFE AGAINST OTHER RECONCILER CALLS
 */
public void start() {
  Collection<Protos.TaskStatus> taskStatuses;
  try {
    taskStatuses = new ArrayList<>(stateStore.fetchStatuses());
  } catch (Exception e) { // SUPPRESS CHECKSTYLE IllegalCatch
    throw new RuntimeException(
        "Failed to fetch TaskStatuses for reconciliation with exception: ",
        e
    );
  }

  rwlock.lock();
  try {
    for (TaskStatus status : taskStatuses) {
      if (!TaskUtils.isTerminal(status)) {
        unreconciled.put(status.getTaskId().getValue(), status);
      }
    }
    if (!unreconciled.isEmpty()) {
      // Only resume explicit reconciliation if there's something to reconcile...
      isComplete.set(false);
    }
    resetTimerValues();
    logger.info("Added {} unreconciled task{} to reconciler: {} task{} to reconcile: {}",
        taskStatuses.size(), taskStatuses.size() == 1 ? "" : "s",
        unreconciled.size(), unreconciled.size() == 1 ? "" : "s",
        unreconciled.keySet());
  } finally {
    rwlock.unlock();
  }
}
 
Example #29
Source File: EndpointsQueries.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
private static List<String> getIpAddresses(Protos.TaskStatus taskStatus) {
  if (taskStatus != null && taskStatus.hasContainerStatus() &&
      taskStatus.getContainerStatus().getNetworkInfosCount() > 0)
  {
    return taskStatus
        .getContainerStatus()
        .getNetworkInfosList()
        .stream()
        .flatMap(networkInfo -> networkInfo.getIpAddressesList().stream())
        .map(Protos.NetworkInfo.IPAddress::getIpAddress)
        .collect(Collectors.toList());
  }
  return Collections.emptyList();
}
 
Example #30
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;
    }
}