use of org.apache.mesos.Protos.TaskStatus in project dcos-commons by mesosphere.
the class Reconciler method start.
/**
* 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 = new ArrayList<>();
try {
taskStatuses.addAll(stateStore.fetchStatuses());
} catch (Exception e) {
throw new RuntimeException("Failed to fetch TaskStatuses for reconciliation with exception: ", e);
}
synchronized (unreconciled) {
for (TaskStatus status : taskStatuses) {
if (!TaskUtils.isTerminal(status)) {
unreconciled.put(status.getTaskId().getValue(), status);
}
}
// even if the scheduler thinks no tasks are launched, we should still always perform
// implicit reconciliation:
isImplicitReconciliationTriggered.set(false);
LOGGER.info("Added {} unreconciled tasks to reconciler: {} tasks to reconcile: {}", taskStatuses.size(), unreconciled.size(), unreconciled.keySet());
}
}
use of org.apache.mesos.Protos.TaskStatus in project incubator-myriad by apache.
the class StatusUpdateEventHandler method onEvent.
/**
* 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;
}
}
use of org.apache.mesos.Protos.TaskStatus in project dcos-commons by mesosphere.
the class EndpointsQueries method reconcileIpAddresses.
private static List<String> reconcileIpAddresses(StateStore stateStore, String taskName) {
// get the IP addresses from the latest TaskStatus (currentTaskStatus), if that TaskStatus doesn't have an
// IP address (it's a TASK_KILLED, LOST, etc.) than use the last IP address recorded in the stateStore
// (this is better than nothing).
TaskStatus currentTaskStatus = stateStore.fetchStatus(taskName).orElse(null);
TaskStatus savedTaskStatus = StateStoreUtils.getTaskStatusFromProperty(stateStore, taskName).orElse(null);
List<String> currentIpAddresses = getIpAddresses(currentTaskStatus);
return currentIpAddresses.isEmpty() ? getIpAddresses(savedTaskStatus) : currentIpAddresses;
}
use of org.apache.mesos.Protos.TaskStatus in project dcos-commons by mesosphere.
the class Expect method reconciledExplicitly.
/**
* Verifies that an explicit task reconciliation for the task statuses in the provided persister was invoked.
*/
public static Expect reconciledExplicitly(Persister persisterWithStatuses) {
// Use a custom comparator for sorting: Protos don't implement Comparable
final Comparator<Protos.TaskStatus> statusComparator = new Comparator<Protos.TaskStatus>() {
@Override
public int compare(TaskStatus o1, TaskStatus o2) {
return o1.getTaskId().getValue().compareTo(o2.getTaskId().getValue());
}
};
return new Expect() {
// Use this form instead of using ArgumentCaptor.forClass() to avoid problems with typecasting generics:
@Captor
private ArgumentCaptor<Collection<Protos.TaskStatus>> statusCaptor;
@Override
public void expect(ClusterState state, SchedulerDriver mockDriver) {
MockitoAnnotations.initMocks(this);
verify(mockDriver, atLeastOnce()).reconcileTasks(statusCaptor.capture());
Set<Protos.TaskStatus> expected = new TreeSet<>(statusComparator);
expected.addAll(new StateStore(persisterWithStatuses).fetchStatuses());
// We do this arg ourselves, since the in-mock comparison never matches.
for (Collection<Protos.TaskStatus> reconcileArgs : statusCaptor.getAllValues()) {
Set<Protos.TaskStatus> got = new TreeSet<>(statusComparator);
got.addAll(reconcileArgs);
if (expected.equals(got)) {
// Found matching call
return;
}
}
Assert.fail(String.format("Expected a task reconcile with arguments: %s, but actual calls were: %s", expected, statusCaptor.getAllValues()));
}
@Override
public String getDescription() {
return String.format("Explicit task reconcile call for statuses: %s", new StateStore(persisterWithStatuses).fetchStatuses().stream().map(status -> String.format("%s=%s", status.getTaskId().getValue(), status.getState())).collect(Collectors.toList()));
}
};
}
use of org.apache.mesos.Protos.TaskStatus in project jesos by groupon.
the class LocalSchedulerMessageProcessor method frameworkStatusUpdate.
@Subscribe
public void frameworkStatusUpdate(final StatusUpdateMessageEnvelope envelope) throws IOException {
checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");
final UPID sender = envelope.getSender();
if (!driverIsConnected(sender)) {
return;
}
final StatusUpdateMessage statusUpdateMessage = envelope.getMessage();
final FrameworkID frameworkId = context.getFrameworkId();
final FrameworkID messageFrameworkId = statusUpdateMessage.getUpdate().getFrameworkId();
checkState(frameworkId.equals(messageFrameworkId), "Received Message for framework %s, but local id is %s", messageFrameworkId, frameworkId);
final TaskStatus.Builder taskStatusBuilder = TaskStatus.newBuilder(statusUpdateMessage.getUpdate().getStatus());
final TaskStatus taskStatus;
// If the update is driver-generated or master-generated, it does not require acknowledgement (from Mesos source code, sched.cpp).
final Optional<UPID> pid = statusUpdateMessage.hasPid() ? Optional.of(UPID.create(statusUpdateMessage.getPid())) : Optional.<UPID>absent();
final boolean noAckRequired = envelope.getSender().equals(context.getDriverUPID()) || pid.isPresent() && pid.get().equals(context.getDriverUPID());
if (noAckRequired) {
taskStatus = taskStatusBuilder.clearUuid().build();
} else {
taskStatus = taskStatusBuilder.setUuid(statusUpdateMessage.getUpdate().getUuid()).build();
}
eventBus.post(new SchedulerCallback() {
@Override
public Runnable getCallback(final Scheduler scheduler, final SchedulerDriver schedulerDriver) {
return new Runnable() {
@Override
public void run() {
scheduler.statusUpdate(schedulerDriver, taskStatus);
}
};
}
});
if (implicitAcknowledgements && !noAckRequired) {
final StatusUpdateAcknowledgementMessage statusUpdateAcknowledgementMessage = StatusUpdateAcknowledgementMessage.newBuilder().setFrameworkId(frameworkId).setSlaveId(statusUpdateMessage.getUpdate().getSlaveId()).setTaskId(taskStatus.getTaskId()).setUuid(statusUpdateMessage.getUpdate().getUuid()).build();
eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), statusUpdateAcknowledgementMessage));
}
}
Aggregations