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;
}
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;
}
Aggregations