Search in sources :

Example 1 with OfferID

use of org.apache.mesos.Protos.OfferID 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 2 with OfferID

use of org.apache.mesos.Protos.OfferID in project storm-mesos by nathanmarz.

the class MesosNimbus method assignSlots.

@Override
public void assignSlots(Topologies topologies, Map<String, Collection<WorkerSlot>> slots) {
    synchronized (OFFERS_LOCK) {
        Map<OfferID, List<TaskInfo>> toLaunch = new HashMap();
        for (String topologyId : slots.keySet()) {
            for (WorkerSlot slot : slots.get(topologyId)) {
                OfferID id = findOffer(slot);
                Offer offer = _offers.get(id);
                if (id != null) {
                    if (!toLaunch.containsKey(id)) {
                        toLaunch.put(id, new ArrayList());
                    }
                    TopologyDetails details = topologies.getById(topologyId);
                    int cpu = MesosCommon.topologyCpu(_conf, details);
                    int mem = MesosCommon.topologyMem(_conf, details);
                    Map executorData = new HashMap();
                    executorData.put(MesosCommon.SUPERVISOR_ID, slot.getNodeId() + "-" + details.getId());
                    executorData.put(MesosCommon.ASSIGNMENT_ID, slot.getNodeId());
                    String executorDataStr = JSONValue.toJSONString(executorData);
                    LOG.info("Launching task with executor data: <" + executorDataStr + ">");
                    TaskInfo task = TaskInfo.newBuilder().setName("worker " + slot.getNodeId() + ":" + slot.getPort()).setTaskId(TaskID.newBuilder().setValue(MesosCommon.taskId(slot.getNodeId(), slot.getPort()))).setSlaveId(offer.getSlaveId()).setExecutor(ExecutorInfo.newBuilder().setExecutorId(ExecutorID.newBuilder().setValue(details.getId())).setData(ByteString.copyFromUtf8(executorDataStr)).setCommand(CommandInfo.newBuilder().addUris(URI.newBuilder().setValue((String) _conf.get(CONF_EXECUTOR_URI))).setValue("cd storm-mesos* && python bin/storm-mesos supervisor"))).addResources(Resource.newBuilder().setName("cpus").setType(Type.SCALAR).setScalar(Scalar.newBuilder().setValue(cpu))).addResources(Resource.newBuilder().setName("mem").setType(Type.SCALAR).setScalar(Scalar.newBuilder().setValue(mem))).addResources(Resource.newBuilder().setName("ports").setType(Type.RANGES).setRanges(Ranges.newBuilder().addRange(Range.newBuilder().setBegin(slot.getPort()).setEnd(slot.getPort())))).build();
                    toLaunch.get(id).add(task);
                }
            }
        }
        for (OfferID id : toLaunch.keySet()) {
            List<TaskInfo> tasks = toLaunch.get(id);
            LOG.info("Launching tasks for offer " + id.getValue() + "\n" + tasks.toString());
            _driver.launchTasks(id, tasks);
            _offers.remove(id);
        }
    }
}
Also used : ByteString(com.google.protobuf.ByteString) TopologyDetails(backtype.storm.scheduler.TopologyDetails) OfferID(org.apache.mesos.Protos.OfferID) TaskInfo(org.apache.mesos.Protos.TaskInfo) WorkerSlot(backtype.storm.scheduler.WorkerSlot) Offer(org.apache.mesos.Protos.Offer)

Aggregations

OfferID (org.apache.mesos.Protos.OfferID)2 TaskInfo (org.apache.mesos.Protos.TaskInfo)2 TopologyDetails (backtype.storm.scheduler.TopologyDetails)1 WorkerSlot (backtype.storm.scheduler.WorkerSlot)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 RemoteMessageEnvelope (com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope)1 LaunchTasksMessage (mesos.internal.Messages.LaunchTasksMessage)1 FrameworkID (org.apache.mesos.Protos.FrameworkID)1 MasterInfo (org.apache.mesos.Protos.MasterInfo)1 Offer (org.apache.mesos.Protos.Offer)1