Java Code Examples for org.apache.mesos.Protos#TaskState

The following examples show how to use org.apache.mesos.Protos#TaskState . 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: SimulatedTitusAgent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public void killTask(TaskID taskId) {
    synchronized (lock) {
        TaskExecutorHolder taskExecutorHolder = pendingTasks.remove(taskId);
        if (taskExecutorHolder == null) {
            logger.warn(slaveId + " is not running task " + taskId); // don't throw, treat it as no-op
            return;
        }
        Protos.TaskState taskState = taskExecutorHolder.getState();
        if (taskState == Protos.TaskState.TASK_FINISHED || taskState == Protos.TaskState.TASK_FAILED || taskState == Protos.TaskState.TASK_KILLED) {
            taskUpdates.onNext(Protos.TaskStatus.newBuilder()
                    .setTaskId(taskId)
                    .setState(Protos.TaskState.TASK_LOST)
                    .setMessage("Task already terminated: " + taskState)
                    .build()
            );
            return;
        }

        taskExecutorHolder.transitionTo(Protos.TaskState.TASK_KILLED);

        releaseResourcesAndReOffer(taskExecutorHolder);
    }
}
 
Example 2
Source File: SingularityExecutorMonitor.java    From Singularity with Apache License 2.0 6 votes vote down vote up
private void onFinish(SingularityExecutorTask task, Protos.TaskState taskState) {
  processKiller.cancelDestroyFuture(task.getTaskId());

  tasks.remove(task.getTaskId());
  processRunningTasks.remove(task.getTaskId());
  processBuildingTasks.remove(task.getTaskId());

  task.cleanup(taskState);

  ListeningExecutorService executorService = taskToShellCommandPool.remove(
    task.getTaskId()
  );

  if (executorService != null) {
    executorService.shutdownNow();
    try {
      executorService.awaitTermination(5, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
      LOG.warn("Awaiting shutdown of shell executor service", e);
    }
  }

  logging.stopTaskLogger(task.getTaskId(), task.getLogbackLog());

  checkIdleExecutorShutdown(task.getDriver());
}
 
Example 3
Source File: OfferEvaluator.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
private boolean taskHasReusableExecutor(Protos.TaskInfo taskInfo) {
  Optional<Protos.TaskStatus> taskStatus = stateStore.fetchStatus(taskInfo.getName());
  if (!taskStatus.isPresent() || FailureUtils.isPermanentlyFailed(taskInfo)) {
    return false;
  }

  Protos.TaskState state = taskStatus.get().getState();
  switch (state) {
    case TASK_STAGING:
    case TASK_STARTING:
    case TASK_RUNNING:
      return true;
    default:
      return false;
  }
}
 
Example 4
Source File: ScenarioBuilderUtil.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
static TaskStatus.TaskState fromMesosTaskState(Protos.TaskState mesosTaskState) {
    switch (mesosTaskState) {
        case TASK_STAGING:
            return TaskStatus.TaskState.Launched;
        case TASK_STARTING:
            return TaskStatus.TaskState.StartInitiated;
        case TASK_RUNNING:
            return TaskStatus.TaskState.Started;
        case TASK_KILLING:
            return TaskStatus.TaskState.KillInitiated;
        case TASK_FINISHED:
        case TASK_FAILED:
        case TASK_ERROR:
        case TASK_LOST:
        case TASK_KILLED:
            return TaskStatus.TaskState.Finished;
    }
    throw new IllegalArgumentException("Unknown Mesos task state found: " + mesosTaskState);
}
 
Example 5
Source File: ExecutorUtils.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
@NotNull
static Protos.TaskStatus taskStatus(
    @NotNull final Protos.ExecutorID executorId,
    @NotNull final Protos.TaskID taskId,
    @NotNull final Protos.TaskState state,
    @NotNull final CassandraFrameworkProtos.SlaveStatusDetails details
) {
    return Protos.TaskStatus.newBuilder()
        .setExecutorId(executorId)
        .setTaskId(taskId)
        .setState(state)
        .setSource(Protos.TaskStatus.Source.SOURCE_EXECUTOR)
        .setData(ByteString.copyFrom(details.toByteArray()))
        .build();
}
 
Example 6
Source File: SingularityExecutorMonitor.java    From Singularity with Apache License 2.0 5 votes vote down vote up
private void sendStatusUpdate(
  SingularityExecutorTask task,
  Protos.TaskState taskState,
  String message
) {
  executorUtils.sendStatusUpdate(
    task.getDriver(),
    TaskID.newBuilder().setValue(task.getTaskId()).build(),
    taskState,
    message,
    task.getLog()
  );
}
 
Example 7
Source File: ContainerStateRule.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
ContainerStateRule(long delayInStateMs,
                   Action action,
                   Optional<Protos.TaskState> mesosTerminalState,
                   Optional<Protos.TaskStatus.Reason> mesosReasonCode,
                   Optional<String> reasonMessage) {
    this.delayInStateMs = delayInStateMs;
    this.action = action;
    this.mesosTerminalState = mesosTerminalState;
    this.mesosReasonCode = mesosReasonCode;
    this.reasonMessage = reasonMessage;
}
 
Example 8
Source File: RepairTask.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Override
public RepairStatus createStatus(
        Protos.TaskState state,
        Optional<String> message) {

    Protos.TaskStatus.Builder builder = getStatusBuilder();
    if (message.isPresent()) {
        builder.setMessage(message.get());
    }

    return RepairStatus.create(builder
            .setData(CassandraData.createRepairStatusData().getBytes())
            .setState(state)
            .build());
}
 
Example 9
Source File: RestoreSnapshotTask.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Override
public RestoreSnapshotStatus createStatus(
        Protos.TaskState state,
        Optional<String> message) {

    Protos.TaskStatus.Builder builder = getStatusBuilder();
    if (message.isPresent()) {
        builder.setMessage(message.get());
    }

    return RestoreSnapshotStatus.create(builder
            .setData(CassandraData.createRestoreSnapshotStatusData().getBytes())
            .setState(state)
            .build());
}
 
Example 10
Source File: ExecutorUtils.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("DM_EXIT")
public void sendStatusUpdate(
  ExecutorDriver driver,
  Protos.TaskID taskID,
  Protos.TaskState taskState,
  String message,
  Logger logger
) {
  logger.info("Sending status update \"{}\" ({})", message, taskState.name());

  message =
    message.substring(
      0,
      Math.min(configuration.getMaxTaskMessageLength(), message.length())
    );

  try {
    final Protos.TaskStatus.Builder builder = Protos
      .TaskStatus.newBuilder()
      .setTaskId(taskID)
      .setState(taskState)
      .setMessage(message);

    driver.sendStatusUpdate(builder.build());
  } catch (Throwable t) {
    try {
      logger.error("Exception while sending status updates, exiting", t);
    } finally {
      System.exit(4);
    }
  }
}
 
Example 11
Source File: TaskTestUtils.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
public static Protos.TaskStatus generateStatus(
        Protos.TaskID taskID,
        Protos.TaskState taskState) {
    return Protos.TaskStatus.newBuilder()
            .setTaskId(taskID)
            .setState(taskState)
            .build();
}
 
Example 12
Source File: SingularityExecutorMonitor.java    From Singularity with Apache License 2.0 5 votes vote down vote up
public void finishTask(
  final SingularityExecutorTask task,
  Protos.TaskState taskState,
  String message,
  Optional<String> errorMsg,
  Object... errorObjects
) {
  try {
    if (errorMsg.isPresent()) {
      task.getLog().error(errorMsg.get(), errorObjects);
    }
  } finally {
    try {
      sendStatusUpdate(task, taskState, message);

      onFinish(task, taskState);
    } catch (Throwable t) {
      logAndExit(
        3,
        "Failed while finishing task {} (state {})",
        task.getTaskId(),
        taskState,
        t
      );
    }
  }
}
 
Example 13
Source File: DownloadSnapshotTask.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Override
public DownloadSnapshotTask update(Protos.TaskState state) {
    return new DownloadSnapshotTask(getBuilder().setData(
        getData().withState(state).getBytes()).build());
}
 
Example 14
Source File: TaskStatusesTrackerTest.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
private static Protos.TaskStatus newTaskStatus(final Protos.TaskID taskID, final Protos.TaskState taskState) {
  return Protos.TaskStatus.newBuilder()
      .setTaskId(taskID)
      .setState(taskState)
      .build();
}
 
Example 15
Source File: CassandraData.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
public CassandraData withState(final Protos.TaskState state) {
    return new CassandraData(
        getBuilder()
            .setState(state.ordinal())
            .build());
}
 
Example 16
Source File: StateStoreUtilsTest.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
public static Protos.TaskStatus newTaskStatus(final Protos.TaskInfo taskInfo, final Protos.TaskState taskState) {
    return newTaskStatus(taskInfo.getTaskId(), taskState);
}
 
Example 17
Source File: Task.java    From elasticsearch with Apache License 2.0 4 votes vote down vote up
public Protos.TaskState getState() {
    return state;
}
 
Example 18
Source File: UpgradeSSTable.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
private void sendStatus(ExecutorDriver driver,
                        Protos.TaskState state, String message) {
    Protos.TaskStatus status =
        task.createStatus(state, Optional.of(message)).getTaskStatus();
    driver.sendStatusUpdate(status);
}
 
Example 19
Source File: Send.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
public static SendTaskStatus.Builder taskStatus(String taskName, Protos.TaskState taskState) {
  return new SendTaskStatus.Builder(taskName, taskState);
}
 
Example 20
Source File: CassandraTaskStatus.java    From dcos-cassandra-service with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the state.
 *
 * @return The state of the task associated with the status.
 */
public Protos.TaskState getState() {
    return status.getState();
}