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

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: CassandraExecutorTest.java    From cassandra-mesos-deprecated with Apache License 2.0 6 votes vote down vote up
private void terminateExecutor() {
        List<Protos.TaskStatus> taskStatus = driver.taskStatusList();
        assertEquals(0, taskStatus.size());

        driver.killTask(taskIdExecutor);

        taskStatus = driver.taskStatusList();
        assertEquals(1, taskStatus.size());
        // server task finished...
        assertEquals(taskIdExecutor, taskStatus.get(0).getTaskId());
        assertEquals(Protos.TaskState.TASK_FINISHED, taskStatus.get(0).getState());

        //TODO: Make async friendly
//        final List<CassandraFrameworkProtos.SlaveStatusDetails> slaveStatusDetailsList = driver.frameworkMessages();
//        assertEquals(0, slaveStatusDetailsList.size());
    }
 
Example 2
Source File: StateStoreTest.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testMissingTaskStatus() {
    store.storeTasks(Arrays.asList(TestConstants.TASK_INFO));
    assertEquals(0, store.fetchStatuses().size());
    assertEquals(1, store.fetchTasks().size());
    assertEquals(TestConstants.TASK_INFO, store.fetchTasks().stream().findAny().get());

    store = new StateStore(persister);
    assertEquals(1, store.fetchStatuses().size());
    assertEquals(1, store.fetchTasks().size());
    assertEquals(TestConstants.TASK_ID, store.fetchTasks().stream().findAny().get().getTaskId());

    Protos.TaskStatus taskStatus = store.fetchStatuses().stream().findAny().get();
    assertEquals(TestConstants.TASK_ID, taskStatus.getTaskId());
    assertEquals(Protos.TaskState.TASK_FAILED, taskStatus.getState());
}
 
Example 3
Source File: CassandraDaemonStepTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateDataNotPresent() throws Exception {
    final String EXPECTED_NAME = "node-0";
    CassandraDaemonStep step = CassandraDaemonStep.create(
            EXPECTED_NAME, persistentOfferRequirementProvider, cassandraState);

    final OfferRequirement mockOfferReq = mock(OfferRequirement.class);
    when(persistentOfferRequirementProvider.getNewOfferRequirement(Mockito.any())).thenReturn(
            Optional.of(mockOfferReq));

    Assert.assertTrue(step.start().isPresent());

    final CassandraDaemonTask task = taskFactory.create(EXPECTED_NAME,
            "abc",
            CassandraTaskExecutor.create("1234", EXPECTED_NAME, "cassandra-role", "cassandra-principal", config.getExecutorConfig()),
            config.getCassandraConfig());
    Protos.TaskInfo taskInfo = task.getTaskInfo();
    taskInfo = Protos.TaskInfo.newBuilder(taskInfo)
            .setSlaveId(Protos.SlaveID.newBuilder().setValue("1.2.3.4").build()).build();
    stateStore.storeTasks(Arrays.asList(taskInfo));
    step.updateOfferStatus(Collections.emptyList());
    final Protos.TaskStatus status = TestUtils.generateStatus(taskInfo.getTaskId(),
            Protos.TaskState.TASK_RUNNING);

    step.update(status);
}
 
Example 4
Source File: MesosStateTracker.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
void unknownTaskStatusUpdate(Protos.TaskStatus taskStatus) {
    String taskId = taskStatus.getTaskId().getValue();
    knownTasks.invalidate(taskId);
    LostTask previous = unknownTasks.getIfPresent(taskId);
    if (previous == null) {
        unknownTasks.put(taskId, new LostTask(taskId, taskStatus, titusRuntime.getClock().wallTime(), false));
    } else {
        unknownTasks.put(taskId, previous.updateState(taskStatus));
    }
}
 
Example 5
Source File: StateStoreUtils.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an Optional<TaskStatus> from the properties in the provided state store for the
 * specified task name.
 */
public static Optional<Protos.TaskStatus> getTaskStatusFromProperty(StateStore stateStore,
                                                                    String taskName)
{
  try {
    return Optional.of(Protos.TaskStatus.parseFrom(
        stateStore.fetchProperty(taskName + PROPERTY_TASK_INFO_SUFFIX)));
  } catch (Exception e) {
    // Broadly catch exceptions to handle:
    // Invalid TaskStatuses
    // StateStoreExceptions
    LOGGER.error("Unable to decode TaskStatus for taskName=" + taskName, e);
    return Optional.empty();
  }
}
 
Example 6
Source File: StateStore.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Stores the TaskStatus of a particular Task. The {@link Protos.TaskInfo} for this exact task MUST have already
 * been written via {@link #storeTasks(Collection)} beforehand. The TaskId must be well-formatted as produced by
 * {@link com.mesosphere.sdk.offer.CommonIdUtils#toTaskId(String, String)}.
 *
 * @param status The status to be stored, which meets the above requirements
 * @throws StateStoreException if storing the TaskStatus fails, or if its TaskId is malformed, or if its matching
 *                             TaskInfo wasn't stored first
 */
public void storeStatus(String taskName, Protos.TaskStatus status) throws StateStoreException {
  Optional<Protos.TaskStatus> currentStatusOptional = fetchStatus(taskName);
  if (currentStatusOptional.isPresent()
      && (status.getState().equals(Protos.TaskState.TASK_LOST)
      || status.getState().equals(Protos.TaskState.TASK_GONE)
      || status.getState().equals(Protos.TaskState.TASK_DROPPED)
      || status.getState().equals(Protos.TaskState.TASK_UNKNOWN)
      || status.getState().equals(Protos.TaskState.TASK_UNREACHABLE))
      && TaskUtils.isTerminal(currentStatusOptional.get()))
  {
    throw new StateStoreException(Reason.LOGIC_ERROR,
        String.format("Skipping task status processing. Ignoring %s as task already in a" +
            " terminal state %s: %s",
            status.getState(), currentStatusOptional.get().getState(), taskName));
  }

  if (!status.getState().equals(Protos.TaskState.TASK_STAGING) &&
      currentStatusOptional.isPresent() &&
      !currentStatusOptional.get().getTaskId().equals(status.getTaskId()))
  {
    throw new StateStoreException(
        Reason.NOT_FOUND,
        String.format("Dropping TaskStatus with unknown TaskID: %s", status));
  }

  String path = getTaskStatusPath(namespace, taskName);
  logger.debug("Storing status '{}' for '{}' in '{}'", status.getState(), taskName, path);

  try {
    persister.set(path, status.toByteArray());
  } catch (PersisterException e) {
    throw new StateStoreException(e);
  }
}
 
Example 7
Source File: TLSCleanupStep.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void update(Protos.TaskStatus status) {
  logger.debug(
      "Step {} ignoring irrelevant TaskStatus: {}",
      getName(),
      TextFormat.shortDebugString(status)
  );
}
 
Example 8
Source File: StateStoreUtilsTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepairTaskIdsNothingNeeded() {
    Protos.TaskInfo taskInfo = newTaskInfo(TestConstants.TASK_NAME);
    stateStore.storeTasks(ImmutableList.of(taskInfo));
    Protos.TaskStatus taskStatus = newTaskStatus(taskInfo.getTaskId(), Protos.TaskState.TASK_UNKNOWN);
    stateStore.storeStatus(TestConstants.TASK_NAME, taskStatus);

    StateStoreUtils.repairTaskIDs(stateStore);

    assertThat(stateStore.fetchTask(TestConstants.TASK_NAME).get(), is(taskInfo));
    assertThat(stateStore.fetchStatus(TestConstants.TASK_NAME).get(), is(taskStatus));
}
 
Example 9
Source File: CassandraDaemonStepTest.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartNeedConfigUpdateNotTerminated1() throws Exception {
    final String EXPECTED_NAME = "node-0";
    CassandraDaemonStep step = CassandraDaemonStep.create(
            EXPECTED_NAME, persistentOfferRequirementProvider, cassandraState);

    final OfferRequirement mockOfferReq = mock(OfferRequirement.class);
    when(persistentOfferRequirementProvider.getNewOfferRequirement(Mockito.any())).thenReturn(
            Optional.of(mockOfferReq));

    Assert.assertTrue(step.start().isPresent());

    final CassandraDaemonTask task = taskFactory.create(EXPECTED_NAME,
            String.valueOf(configurationManager.getTargetName()),
            CassandraTaskExecutor.create("1234", EXPECTED_NAME, "cassandra-role", "cassandra-principal", config.getExecutorConfig()),
            config.getCassandraConfig());
    Protos.TaskInfo taskInfo = task.getTaskInfo();
    taskInfo = Protos.TaskInfo.newBuilder(taskInfo)
            .setSlaveId(Protos.SlaveID.newBuilder().setValue("1.2.3.4").build()).build();
    stateStore.storeTasks(Arrays.asList(TaskUtils.packTaskInfo(taskInfo)));

    Protos.TaskStatus status = TestUtils.generateStatus(taskInfo.getTaskId(),
            Protos.TaskState.TASK_RUNNING, CassandraMode.NORMAL);
    stateStore.storeStatus(status);

    Assert.assertTrue(!step.start().isPresent());

    when(mockStage.toCompletableFuture()).thenReturn(mockFuture);
    when(mockFuture.get()).thenReturn(true);

    status = TestUtils.generateStatus(taskInfo.getTaskId(),
            Protos.TaskState.TASK_FINISHED);
    stateStore.storeStatus(status);

    when(persistentOfferRequirementProvider.getReplacementOfferRequirement(Mockito.any())).thenReturn(
            Optional.empty());
    Assert.assertTrue(!step.start().isPresent());
}
 
Example 10
Source File: IgniteScheduler.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public synchronized void statusUpdate(SchedulerDriver schedulerDriver, Protos.TaskStatus taskStatus) {
    final String taskId = taskStatus.getTaskId().getValue();

    log.log(Level.INFO, "Received update event task: {0} is in state: {1}",
        new Object[]{taskId, taskStatus.getState()});

    if (taskStatus.getState().equals(Protos.TaskState.TASK_FAILED)
        || taskStatus.getState().equals(Protos.TaskState.TASK_ERROR)
        || taskStatus.getState().equals(Protos.TaskState.TASK_FINISHED)
        || taskStatus.getState().equals(Protos.TaskState.TASK_KILLED)
        || taskStatus.getState().equals(Protos.TaskState.TASK_LOST)) {
        IgniteTask failedTask = tasks.remove(taskId);

        if (failedTask != null) {
            List<Protos.Request> requests = new ArrayList<>();

            Protos.Request request = Protos.Request.newBuilder()
                .addResources(Protos.Resource.newBuilder()
                    .setType(Protos.Value.Type.SCALAR)
                    .setName(MEM)
                    .setScalar(Protos.Value.Scalar.newBuilder().setValue(failedTask.mem())))
                .addResources(Protos.Resource.newBuilder()
                    .setType(Protos.Value.Type.SCALAR)
                    .setName(CPU)
                    .setScalar(Protos.Value.Scalar.newBuilder().setValue(failedTask.cpuCores())))
                .build();

            requests.add(request);

            schedulerDriver.requestResources(requests);
        }
    }
}
 
Example 11
Source File: MesosResourceManager.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Handles a termination notification from a task monitor.
 */
public void taskTerminated(TaskMonitor.TaskTerminated message) {
	Protos.TaskID taskID = message.taskID();
	Protos.TaskStatus status = message.status();

	// note: this callback occurs for failed containers and for released containers alike
	final ResourceID id = extractResourceID(taskID);

	boolean existed;
	try {
		existed = workerStore.removeWorker(taskID);
	} catch (Exception ex) {
		onFatalError(new ResourceManagerException("unable to remove worker", ex));
		return;
	}

	if (!existed) {
		LOG.info("Received a termination notice for an unrecognized worker: {}", id);
		return;
	}

	// check if this is a failed task or a released task
	assert(!workersInNew.containsKey(id));
	if (workersBeingReturned.remove(id) != null) {
		// regular finished worker that we released
		LOG.info("Worker {} finished successfully with message: {}",
			id, status.getMessage());
	} else {
		// failed worker, either at startup, or running
		final MesosWorkerStore.Worker launched = workersInLaunch.remove(id);
		assert(launched != null);
		LOG.info("Worker {} failed with status: {}, reason: {}, message: {}.",
			id, status.getState(), status.getReason(), status.getMessage());
		startNewWorker(launched.profile());
	}

	closeTaskManagerConnection(id, new Exception(status.getMessage()));
}
 
Example 12
Source File: ProtoTestUtil.java    From logstash with Apache License 2.0 5 votes vote down vote up
public static Protos.TaskStatus createTaskStatus(Protos.TaskState taskState, String taskId,
    String slaveID, String message) {
    return Protos.TaskStatus.newBuilder()
        .setState(taskState)
        .setMessage(message)
        .setTaskId(Protos.TaskID.newBuilder().setValue(taskId))
        .setSlaveId(Protos.SlaveID.newBuilder().setValue(slaveID)).build();
}
 
Example 13
Source File: RestoreSnapshotStepTest.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeEach() {
    MockitoAnnotations.initMocks(this);
    final StateStore mockStateStore = Mockito.mock(StateStore.class);
    final Protos.TaskStatus status = TestUtils
            .generateStatus(TaskUtils.toTaskId("node-0"), Protos.TaskState.TASK_RUNNING, CassandraMode.NORMAL);
    Mockito.when(mockStateStore.fetchStatus("node-0")).thenReturn(Optional.of(status));
    Mockito.when(cassandraState.getStateStore()).thenReturn(mockStateStore);
}
 
Example 14
Source File: SchedulerProxy.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void statusUpdate(SchedulerDriver driver, Protos.TaskStatus status) {
	mesosActor.tell(new StatusUpdate(status), ActorRef.noSender());
}
 
Example 15
Source File: ClusterJobHandler.java    From cassandra-mesos-deprecated with Apache License 2.0 4 votes vote down vote up
public void onTaskRemoved(@NotNull final Protos.TaskStatus status, @NotNull final CassandraFrameworkProtos.ClusterJobStatus clusterJob) {
    jobsState.removeTaskForCurrentNode(status, clusterJob);
}
 
Example 16
Source File: MultiServiceManagerTest.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
private static Protos.TaskStatus buildStatus(String clientName) {
    return Protos.TaskStatus.newBuilder()
            .setTaskId(CommonIdUtils.toTaskId(clientName, "foo"))
            .setState(TaskState.TASK_FINISHED)
            .build();
}
 
Example 17
Source File: CassandraStateTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
private Protos.TaskStatus getTestTaskStatus(CassandraDaemonTask task) {
    final CassandraDaemonStatus status = task.createStatus(Protos.TaskState.TASK_RUNNING, CassandraMode.NORMAL, Optional.empty());
    return status.getTaskStatus();
}
 
Example 18
Source File: ProtoTestUtil.java    From elasticsearch with Apache License 2.0 4 votes vote down vote up
public static Protos.TaskStatus getDefaultTaskStatus(Protos.TaskState state) {
    return getDefaultTaskStatus(state, 1.0);
}
 
Example 19
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 20
Source File: CassandraCluster.java    From cassandra-mesos-deprecated with Apache License 2.0 4 votes vote down vote up
public void removeTask(@NotNull final String taskId, @NotNull final Protos.TaskStatus status) {
    final List<CassandraNode> nodes = clusterState.nodes();
    final List<CassandraNode> newNodes = new ArrayList<>(nodes.size());
    boolean changed = false;
    for (final CassandraNode cassandraNode : nodes) {
        final CassandraNodeTask nodeTask = CassandraFrameworkProtosUtils.getTaskForNode(cassandraNode, taskId);
        if (nodeTask == null) {
            newNodes.add(cassandraNode);
            continue;
        }
        final CassandraNode.Builder builder = CassandraFrameworkProtosUtils.removeTask(cassandraNode, nodeTask);
        changed = true;
        switch (nodeTask.getType()) {
            case METADATA:
                // TODO shouldn't we also assume that the server task is no longer running ??
                // TODO do we need to remove the executor metadata ??

                removeExecutorMetadata(cassandraNode.getCassandraNodeExecutor().getExecutorId());
                builder.clearTasks();
                break;
            case SERVER:
                builder.clearCassandraDaemonPid();
                if (status.hasSource()) {
                    switch (status.getSource()) {
                        case SOURCE_MASTER:
                        case SOURCE_SLAVE:
                            recordHealthCheck(cassandraNode.getCassandraNodeExecutor().getExecutorId(),
                                HealthCheckDetails.newBuilder()
                                    .setHealthy(false)
                                    .setMsg("Removing Cassandra server task " + taskId + ". Reason=" + status.getReason() + ", source=" + status.getSource() + ", message=\"" + status.getMessage() + '"')
                                    .build());
                            break;
                    }
                }
                break;
            case CLUSTER_JOB:
                jobsState.clearClusterJobCurrentNode(status.getExecutorId().getValue());
                break;
        }

        newNodes.add(builder.build());
    }
    if (changed) {
        clusterState.nodes(newNodes);
    }

    final ClusterJobStatus clusterJob = getCurrentClusterJob();
    if (clusterJob != null) {
        if (clusterJob.hasCurrentNode() && clusterJob.getCurrentNode().getTaskId().equals(taskId)) {
            clusterJobHandlers.get(clusterJob.getJobType()).onTaskRemoved(status, clusterJob);
        }
    }
}