Search in sources :

Example 6 with RemoteMessageEnvelope

use of com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope in project jesos by groupon.

the class InternalSchedulerDriver method sendFrameworkMessage.

@Override
public Status sendFrameworkMessage(final ExecutorID executorId, final SlaveID slaveId, final byte[] data) {
    checkNotNull(executorId, "executorId is null");
    checkNotNull(slaveId, "slaveId is null");
    checkNotNull(data, "data is null");
    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }
    final FrameworkToExecutorMessage message = FrameworkToExecutorMessage.newBuilder().setFrameworkId(context.getFrameworkId()).setExecutorId(executorId).setSlaveId(slaveId).setData(ByteString.copyFrom(data)).build();
    // directly to the slave, otherwise to the master and let the master sort it out.
    if (context.containsSlave(message.getSlaveId())) {
        final UPID slave = context.getSlaveUPID(message.getSlaveId());
        eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), slave, message));
    } else {
        eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), message));
    }
    return context.getStateMachine();
}
Also used : UPID(com.groupon.mesos.util.UPID) RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope) FrameworkToExecutorMessage(mesos.internal.Messages.FrameworkToExecutorMessage)

Example 7 with RemoteMessageEnvelope

use of com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope in project jesos by groupon.

the class InternalSchedulerDriver method reconcileTasks.

@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();
}
Also used : RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope) ReconcileTasksMessage(mesos.internal.Messages.ReconcileTasksMessage)

Example 8 with RemoteMessageEnvelope

use of com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope 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));
    }
}
Also used : Scheduler(org.apache.mesos.Scheduler) TaskStatus(org.apache.mesos.Protos.TaskStatus) UPID(com.groupon.mesos.util.UPID) RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope) StatusUpdateAcknowledgementMessage(mesos.internal.Messages.StatusUpdateAcknowledgementMessage) StatusUpdateMessage(mesos.internal.Messages.StatusUpdateMessage) FrameworkID(org.apache.mesos.Protos.FrameworkID) SchedulerDriver(org.apache.mesos.SchedulerDriver) Subscribe(com.google.common.eventbus.Subscribe)

Example 9 with RemoteMessageEnvelope

use of com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope in project jesos by groupon.

the class InternalSchedulerDriver method abort.

@Override
public Status abort() {
    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }
    if (context.isConnected()) {
        final DeactivateFrameworkMessage message = DeactivateFrameworkMessage.newBuilder().setFrameworkId(context.getFrameworkId()).build();
        eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), message));
    }
    context.setStateMachine(DRIVER_ABORTED);
    return context.getStateMachine();
}
Also used : DeactivateFrameworkMessage(mesos.internal.Messages.DeactivateFrameworkMessage) RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope)

Example 10 with RemoteMessageEnvelope

use of com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope in project jesos by groupon.

the class InternalSchedulerDriver method killTask.

@Override
public Status killTask(final TaskID taskId) {
    checkNotNull(taskId, "taskId is null");
    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }
    final KillTaskMessage message = KillTaskMessage.newBuilder().setFrameworkId(context.getFrameworkId()).setTaskId(taskId).build();
    eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), message));
    return context.getStateMachine();
}
Also used : KillTaskMessage(mesos.internal.Messages.KillTaskMessage) RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope)

Aggregations

RemoteMessageEnvelope (com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope)10 UPID (com.groupon.mesos.util.UPID)2 StatusUpdateAcknowledgementMessage (mesos.internal.Messages.StatusUpdateAcknowledgementMessage)2 FrameworkID (org.apache.mesos.Protos.FrameworkID)2 TaskStatus (org.apache.mesos.Protos.TaskStatus)2 ImmutableList (com.google.common.collect.ImmutableList)1 Subscribe (com.google.common.eventbus.Subscribe)1 IOException (java.io.IOException)1 DeactivateFrameworkMessage (mesos.internal.Messages.DeactivateFrameworkMessage)1 FrameworkToExecutorMessage (mesos.internal.Messages.FrameworkToExecutorMessage)1 KillTaskMessage (mesos.internal.Messages.KillTaskMessage)1 LaunchTasksMessage (mesos.internal.Messages.LaunchTasksMessage)1 ReconcileTasksMessage (mesos.internal.Messages.ReconcileTasksMessage)1 ResourceRequestMessage (mesos.internal.Messages.ResourceRequestMessage)1 ReviveOffersMessage (mesos.internal.Messages.ReviveOffersMessage)1 StatusUpdateMessage (mesos.internal.Messages.StatusUpdateMessage)1 UnregisterFrameworkMessage (mesos.internal.Messages.UnregisterFrameworkMessage)1 MasterInfo (org.apache.mesos.Protos.MasterInfo)1 OfferID (org.apache.mesos.Protos.OfferID)1 Status (org.apache.mesos.Protos.Status)1