Search in sources :

Example 1 with MasterInfo

use of org.apache.mesos.Protos.MasterInfo in project jesos by groupon.

the class LocalSchedulerMessageProcessor method driverIsConnected.

private boolean driverIsConnected(final UPID messageSender) {
    final MasterInfo master = context.connectedMaster();
    if (master == null) {
        LOG.warn("Received message from  %s, but no master is leading, ignoring!", messageSender);
        return false;
    }
    // Master PID may have changed in the context in the meantime. Don't rely on the context
    // to be up to date but resolve the MasterInfo that was retrieved earlier.
    final UPID masterUpid = UPID.create(master.getPid());
    if (!masterUpid.equals(messageSender)) {
        LOG.warn("Received message from %s, leading master is %s, ignoring!", messageSender, masterUpid);
        return false;
    }
    return true;
}
Also used : MasterInfo(org.apache.mesos.Protos.MasterInfo) UPID(com.groupon.mesos.util.UPID)

Example 2 with MasterInfo

use of org.apache.mesos.Protos.MasterInfo in project jesos by groupon.

the class InternalSchedulerDriver method doLaunchTasks.

// 
// Launch Tasks processing
// 
private void doLaunchTasks(final LaunchTasksMessage message) {
    final MasterInfo masterInfo = context.connectedMaster();
    if (masterInfo == null) {
        loseAllTasks(message.getTasksList(), "Master disconnected");
        return;
    }
    final ImmutableList.Builder<TaskInfo> builder = ImmutableList.builder();
    for (TaskInfo taskInfo : message.getTasksList()) {
        if (taskInfo.hasExecutor() == taskInfo.hasCommand()) {
            loseTask(taskInfo, "TaskInfo must have either an 'executor' or a 'command'");
            // for(...
            continue;
        }
        if (taskInfo.hasExecutor()) {
            if (taskInfo.getExecutor().hasFrameworkId()) {
                final FrameworkID executorFrameworkId = taskInfo.getExecutor().getFrameworkId();
                if (!executorFrameworkId.equals(context.getFrameworkId())) {
                    loseTask(taskInfo, format("ExecutorInfo has an invalid FrameworkID (Actual: %s vs Expected: %s)", executorFrameworkId.getValue(), context.getFrameworkId().getValue()));
                    // for(...
                    continue;
                }
            } else {
                // Executor present but not framework id. Set the framework id.
                taskInfo = TaskInfo.newBuilder(taskInfo).setExecutor(ExecutorInfo.newBuilder(taskInfo.getExecutor()).setFrameworkId(context.getFrameworkId())).build();
            }
        }
        builder.add(taskInfo);
    }
    final List<TaskInfo> launchTasks = builder.build();
    for (final OfferID offer : message.getOfferIdsList()) {
        if (!context.hasOffers(offer)) {
            LOG.warn("Unknown offer %s ignored!", offer.getValue());
        }
        for (final TaskInfo launchTask : launchTasks) {
            if (context.hasOffer(offer, launchTask.getSlaveId())) {
                context.addSlave(launchTask.getSlaveId(), context.getOffer(offer, launchTask.getSlaveId()));
            }
        }
        context.removeAllOffers(offer);
    }
    final LaunchTasksMessage launchMessage = LaunchTasksMessage.newBuilder(message).setFrameworkId(context.getFrameworkId()).clearTasks().addAllTasks(launchTasks).build();
    eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), launchMessage));
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) OfferID(org.apache.mesos.Protos.OfferID) MasterInfo(org.apache.mesos.Protos.MasterInfo) RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope) ImmutableList(com.google.common.collect.ImmutableList) FrameworkID(org.apache.mesos.Protos.FrameworkID) LaunchTasksMessage(mesos.internal.Messages.LaunchTasksMessage)

Example 3 with MasterInfo

use of org.apache.mesos.Protos.MasterInfo in project jesos by groupon.

the class LocalSchedulerMessageProcessor method masterIsValid.

private boolean masterIsValid(final MasterInfo masterInfo) {
    checkNotNull(masterInfo, "masterInfo is null");
    if (context.isStateMachine(DRIVER_ABORTED)) {
        LOG.warn("driver is aborted!");
        return false;
    }
    final MasterInfo currentMaster = context.getMaster();
    if (currentMaster == null) {
        LOG.warn("Received registration from  %s, but no master is leading, ignoring!", masterInfo.getId());
        return false;
    }
    if (!masterInfo.equals(currentMaster)) {
        LOG.warn("Received registration from %s, leading master is %s, ignoring!", masterInfo, currentMaster);
        return false;
    }
    return true;
}
Also used : MasterInfo(org.apache.mesos.Protos.MasterInfo)

Example 4 with MasterInfo

use of org.apache.mesos.Protos.MasterInfo in project jesos by groupon.

the class ZookeeperMasterDetector method processMasterUpdate.

@Subscribe
public void processMasterUpdate(final MasterUpdateMessage message) {
    final Set<String> currentNodes = message.getNodes();
    final Set<String> nodesToRemove = ImmutableSet.copyOf(Sets.difference(nodeCache.keySet(), currentNodes));
    final Set<String> nodesToAdd = ImmutableSet.copyOf(Sets.difference(currentNodes, nodeCache.keySet()));
    for (final String node : nodesToAdd) {
        final String path = zookeeperPath + "/" + node;
        final MasterInfo masterInfo = client.readData(path);
        nodeCache.put(node, masterInfo);
    }
    for (final String node : nodesToRemove) {
        nodeCache.remove(node);
    }
    LOG.debug("Processed event, active nodes are %s", nodeCache.entrySet());
    final MasterInfo masterInfo = getMaster();
    if (masterInfo == null) {
        LOG.debug("No current master exists!");
    } else {
        LOG.debug("Current master is %s", UPID.create(masterInfo.getPid()).asString());
    }
    final List<DetectMessage> detectMessages = new ArrayList<>(futures.size());
    futures.drainTo(detectMessages);
    for (final DetectMessage detectMessage : detectMessages) {
        processDetect(detectMessage);
    }
}
Also used : MasterInfo(org.apache.mesos.Protos.MasterInfo) ArrayList(java.util.ArrayList) Subscribe(com.google.common.eventbus.Subscribe)

Example 5 with MasterInfo

use of org.apache.mesos.Protos.MasterInfo in project jesos by groupon.

the class ZookeeperMasterDetector method processDetect.

@Subscribe
public void processDetect(final DetectMessage message) {
    final SettableFuture<MasterInfo> future = message.getFuture();
    final MasterInfo previous = message.getPrevious();
    final MasterInfo currentLeader = getMaster();
    if (!Objects.equal(currentLeader, previous)) {
        LOG.debug("Master has changed: %s -> %s", previous, currentLeader);
        future.set(currentLeader);
    } else {
        LOG.debug("Master unchanged, queueing");
        futures.add(message);
    }
}
Also used : MasterInfo(org.apache.mesos.Protos.MasterInfo) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

MasterInfo (org.apache.mesos.Protos.MasterInfo)5 Subscribe (com.google.common.eventbus.Subscribe)2 ImmutableList (com.google.common.collect.ImmutableList)1 RemoteMessageEnvelope (com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope)1 UPID (com.groupon.mesos.util.UPID)1 ArrayList (java.util.ArrayList)1 LaunchTasksMessage (mesos.internal.Messages.LaunchTasksMessage)1 FrameworkID (org.apache.mesos.Protos.FrameworkID)1 OfferID (org.apache.mesos.Protos.OfferID)1 TaskInfo (org.apache.mesos.Protos.TaskInfo)1