Search in sources :

Example 1 with LaunchTaskException

use of io.mantisrx.server.master.LaunchTaskException in project mantis by Netflix.

the class VirtualMachineMasterServiceMesosImpl method createTaskInfo.

private Collection<TaskInfo> createTaskInfo(Protos.SlaveID slaveID, final LaunchTaskRequest launchTaskRequest) throws LaunchTaskException {
    final ScheduleRequest scheduleRequest = launchTaskRequest.getScheduleRequest();
    String name = scheduleRequest.getWorkerId().getJobCluster() + " (stage: " + scheduleRequest.getStageNum() + " of " + scheduleRequest.getJobMetadata().getTotalStages() + ")";
    TaskID taskId = TaskID.newBuilder().setValue(scheduleRequest.getWorkerId().getId()).build();
    MachineDefinition machineDefinition = scheduleRequest.getMachineDefinition();
    // grab ports within range
    List<Integer> ports = launchTaskRequest.getPorts().getAllPorts();
    TaskInfo taskInfo = null;
    try {
        TaskInfo.Builder taskInfoBuilder = TaskInfo.newBuilder();
        ExecuteStageRequest executeStageRequest = new ExecuteStageRequest(scheduleRequest.getWorkerId().getJobCluster(), scheduleRequest.getWorkerId().getJobId(), scheduleRequest.getWorkerId().getWorkerIndex(), scheduleRequest.getWorkerId().getWorkerNum(), scheduleRequest.getJobMetadata().getJobJarUrl(), scheduleRequest.getStageNum(), scheduleRequest.getJobMetadata().getTotalStages(), ports, getTimeoutSecsToReportStart(), launchTaskRequest.getPorts().getMetricsPort(), scheduleRequest.getJobMetadata().getParameters(), scheduleRequest.getJobMetadata().getSchedulingInfo(), scheduleRequest.getDurationType(), scheduleRequest.getJobMetadata().getSubscriptionTimeoutSecs(), scheduleRequest.getJobMetadata().getMinRuntimeSecs() - (System.currentTimeMillis() - scheduleRequest.getJobMetadata().getMinRuntimeSecs()), launchTaskRequest.getPorts());
        taskInfoBuilder.setName(name).setTaskId(taskId).setSlaveId(slaveID).addResources(Resource.newBuilder().setName("cpus").setType(Value.Type.SCALAR).setScalar(Value.Scalar.newBuilder().setValue(machineDefinition.getCpuCores()))).addResources(Resource.newBuilder().setName("mem").setType(Value.Type.SCALAR).setScalar(Value.Scalar.newBuilder().setValue(machineDefinition.getMemoryMB()))).addResources(Resource.newBuilder().setName("disk").setType(Value.Type.SCALAR).setScalar(Value.Scalar.newBuilder().setValue(machineDefinition.getDiskMB()))).addResources(Resource.newBuilder().setName("network").setType(Value.Type.SCALAR).setScalar(Value.Scalar.newBuilder().setValue(machineDefinition.getNetworkMbps()))).setExecutor(createMantisWorkerExecutor(executeStageRequest, launchTaskRequest, machineDefinition.getMemoryMB(), machineDefinition.getCpuCores())).setData(ByteString.copyFrom(mapper.writeValueAsBytes(executeStageRequest)));
        if (!ports.isEmpty()) {
            for (Integer port : ports) {
                // add ports
                taskInfoBuilder.addResources(Resource.newBuilder().setName("ports").setType(Value.Type.RANGES).setRanges(Value.Ranges.newBuilder().addRange(Value.Range.newBuilder().setBegin(port).setEnd(port))));
            }
        }
        taskInfo = taskInfoBuilder.build();
    } catch (JsonProcessingException e) {
        throw new LaunchTaskException("Failed to build a TaskInfo instance: " + e.getMessage(), e);
    }
    List<TaskInfo> tasks = new ArrayList<>(1);
    tasks.add(taskInfo);
    return tasks;
}
Also used : TaskID(org.apache.mesos.Protos.TaskID) MachineDefinition(io.mantisrx.runtime.MachineDefinition) ScheduleRequest(io.mantisrx.server.master.scheduler.ScheduleRequest) ArrayList(java.util.ArrayList) LaunchTaskException(io.mantisrx.server.master.LaunchTaskException) ByteString(com.google.protobuf.ByteString) ExecuteStageRequest(io.mantisrx.server.core.ExecuteStageRequest) TaskInfo(org.apache.mesos.Protos.TaskInfo) JsonProcessingException(io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with LaunchTaskException

use of io.mantisrx.server.master.LaunchTaskException in project mantis by Netflix.

the class VirtualMachineMasterServiceMesosImpl method launchTasks.

// NOTE: All leases are for the same agent.
@Override
public Map<ScheduleRequest, LaunchTaskException> launchTasks(List<LaunchTaskRequest> requests, List<VirtualMachineLease> leases) {
    if (!super.getIsInited()) {
        logger.error("Not in leader mode, not launching tasks");
        return new HashMap<>();
    }
    Protos.SlaveID slaveID = leases.get(0).getOffer().getSlaveId();
    List<Protos.OfferID> offerIDs = new ArrayList<>();
    for (VirtualMachineLease vml : leases) offerIDs.add(vml.getOffer().getId());
    Map<ScheduleRequest, LaunchTaskException> errorResults = new HashMap<>();
    List<TaskInfo> taskInfos = new ArrayList<>();
    for (LaunchTaskRequest request : requests) {
        try {
            taskInfos.addAll(createTaskInfo(slaveID, request));
        } catch (LaunchTaskException e) {
            errorResults.put(request.getScheduleRequest(), e);
        }
    }
    if (!taskInfos.isEmpty())
        mesosDriver.get().launchTasks(offerIDs, taskInfos);
    else {
        // reject offers to prevent offer leak, but shouldn't happen
        for (VirtualMachineLease l : leases) {
            mesosDriver.get().declineOffer(l.getOffer().getId());
        }
    }
    return errorResults;
}
Also used : ScheduleRequest(io.mantisrx.server.master.scheduler.ScheduleRequest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LaunchTaskRequest(io.mantisrx.server.master.scheduler.LaunchTaskRequest) LaunchTaskException(io.mantisrx.server.master.LaunchTaskException) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) TaskInfo(org.apache.mesos.Protos.TaskInfo) Protos(org.apache.mesos.Protos)

Aggregations

LaunchTaskException (io.mantisrx.server.master.LaunchTaskException)2 ScheduleRequest (io.mantisrx.server.master.scheduler.ScheduleRequest)2 ArrayList (java.util.ArrayList)2 TaskInfo (org.apache.mesos.Protos.TaskInfo)2 ByteString (com.google.protobuf.ByteString)1 VirtualMachineLease (com.netflix.fenzo.VirtualMachineLease)1 MachineDefinition (io.mantisrx.runtime.MachineDefinition)1 ExecuteStageRequest (io.mantisrx.server.core.ExecuteStageRequest)1 LaunchTaskRequest (io.mantisrx.server.master.scheduler.LaunchTaskRequest)1 JsonProcessingException (io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)1 HashMap (java.util.HashMap)1 Protos (org.apache.mesos.Protos)1 TaskID (org.apache.mesos.Protos.TaskID)1