use of org.apache.mesos.v1.scheduler.Protos.Call.Request in project Singularity by HubSpot.
the class SingularityTaskShellCommandDispatchPoller method runActionOnPoll.
@Override
public void runActionOnPoll() {
final long start = System.currentTimeMillis();
final List<SingularityTaskShellCommandRequest> shellRequests = taskManager.getAllQueuedTaskShellCommandRequests();
if (!schedulerClient.isRunning()) {
LOG.warn("Unable to process shell requests because scheduler driver isn't present ({} tasks waiting)", shellRequests.size());
return;
}
if (shellRequests.isEmpty()) {
LOG.trace("No shell requests to send.");
return;
}
for (SingularityTaskShellCommandRequest shellRequest : shellRequests) {
Optional<SingularityTask> task = taskManager.getTask(shellRequest.getTaskId());
if (!task.isPresent() || !taskManager.isActiveTask(shellRequest.getTaskId().getId())) {
LOG.info("Skipping shell request {} because {} didn't exist or isn't active", shellRequest, shellRequest.getTaskId());
continue;
}
final ExecutorID executorId = MesosProtosUtils.toExecutorId(task.get().getMesosTask().getExecutor().getExecutorId());
final AgentID slaveId = MesosProtosUtils.toAgentId(task.get().getMesosTask().getAgentId());
final byte[] bytes = transcoder.toBytes(shellRequest);
schedulerClient.frameworkMessage(executorId, slaveId, bytes);
LOG.info("Sent {} ({} bytes) to {} on {}", shellRequest, bytes.length, executorId, slaveId);
taskManager.saveTaskShellCommandRequestToTask(shellRequest);
taskManager.deleteTaskShellCommandRequestFromQueue(shellRequest);
}
LOG.info("Sent {} shell requests to executors in {}", shellRequests.size(), JavaUtils.duration(start));
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Request in project Singularity by HubSpot.
the class SingularitySchedulerTest method testTaskOddities.
@Test
public void testTaskOddities() {
// test unparseable status update
TaskStatus.Builder bldr = TaskStatus.newBuilder().setTaskId(TaskID.newBuilder().setValue("task")).setAgentId(AgentID.newBuilder().setValue("slave1")).setState(TaskState.TASK_RUNNING);
// should not throw exception:
sms.statusUpdate(bldr.build()).join();
initRequest();
initFirstDeploy();
SingularityTask taskOne = launchTask(request, firstDeploy, 1, TaskState.TASK_STARTING);
taskManager.deleteTaskHistory(taskOne.getTaskId());
Assert.assertTrue(taskManager.isActiveTask(taskOne.getTaskId().getId()));
statusUpdate(taskOne, TaskState.TASK_RUNNING);
statusUpdate(taskOne, TaskState.TASK_FAILED);
Assert.assertTrue(!taskManager.isActiveTask(taskOne.getTaskId().getId()));
Assert.assertEquals(2, taskManager.getTaskHistoryUpdates(taskOne.getTaskId()).size());
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Request in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method prepTask.
protected SingularityTask prepTask(SingularityRequest request, SingularityDeploy deploy, long launchTime, int instanceNo, boolean separateHosts, Optional<String> runId) {
SingularityPendingTask pendingTask = buildPendingTask(request, deploy, launchTime, instanceNo, runId);
SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
Offer offer;
if (separateHosts) {
offer = createOffer(125, 1024, 2048, String.format("slave%s", instanceNo), String.format("host%s", instanceNo));
} else {
offer = createOffer(125, 1024, 2048);
}
SingularityTaskId taskId = new SingularityTaskId(request.getId(), deploy.getId(), launchTime, instanceNo, offer.getHostname(), "rack1");
TaskID taskIdProto = TaskID.newBuilder().setValue(taskId.toString()).build();
TaskInfo taskInfo = TaskInfo.newBuilder().setAgentId(offer.getAgentId()).setExecutor(ExecutorInfo.newBuilder().setExecutorId(ExecutorID.newBuilder().setValue("executorID"))).setTaskId(taskIdProto).setName("name").build();
SingularityTask task = new SingularityTask(taskRequest, taskId, Collections.singletonList(mesosProtosUtils.offerFromProtos(offer)), mesosProtosUtils.taskFromProtos(taskInfo), Optional.of("rack1"));
taskManager.savePendingTask(pendingTask);
return task;
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Request in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testEnvironmentVariableOverrides.
@Test
public void testEnvironmentVariableOverrides() {
Map<String, String> overrideVariables = new HashMap<>();
overrideVariables.put("MY_NEW_ENV_VAR", "test");
overrideVariables.put("STARTED_BY_USER", "notTestUser");
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setCommand(Optional.of("/bin/echo hi")).build();
final SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(new SingularityPendingTaskId("test", "1", 0, 1, PendingType.IMMEDIATE, 0)).setUser(user).setEnvOverrides(overrideVariables).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final TaskInfo task = builder.buildTask(offerHolder, null, taskRequest, taskResources, executorResources).getMesosTask();
Map<String, String> environmentVariables = task.getCommand().getEnvironment().getVariablesList().stream().collect(Collectors.toMap(Variable::getName, Variable::getValue));
for (String key : overrideVariables.keySet()) {
assertEquals("Environment variable " + key + " not overridden.", environmentVariables.get(key), overrideVariables.get(key));
}
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Request in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testGetPortByIndex.
@Test
public void testGetPortByIndex() throws Exception {
taskResources = new Resources(1, 1, 4, 0);
final Protos.Resource portsResource = Protos.Resource.newBuilder().setName("ports").setType(Protos.Value.Type.RANGES).setRanges(Protos.Value.Ranges.newBuilder().addRange(Protos.Value.Range.newBuilder().setBegin(31003).setEnd(31004).build()).addRange(Protos.Value.Range.newBuilder().setBegin(31000).setEnd(31001).build()).build()).build();
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setCommand(Optional.of("/bin/echo")).setArguments(Optional.of(Collections.singletonList("wat"))).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final SingularityMesosTaskHolder task = builder.buildTask(offerHolder, Collections.singletonList(portsResource), taskRequest, taskResources, executorResources);
assertEquals(31003L, task.getTask().getPortByIndex(2).get().longValue());
}
Aggregations