use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task in project Singularity by HubSpot.
the class SingularityMesosSchedulerClient method kill.
/**
* Sent by the scheduler to kill a specific task. If the scheduler has a custom executor, the kill is
* forwarded to the executor; it is up to the executor to kill the task and send a TASK_KILLED
* (or TASK_FAILED) update. If the task hasn’t yet been delivered to the executor when Mesos master or
* agent receives the kill request, a TASK_KILLED is generated and the task launch is not forwarded to
* the executor. Note that if the task belongs to a task group, killing of one task results in all tasks
* in the task group being killed. Mesos releases the resources for a task once it receives a terminal
* update for the task. If the task is unknown to the master, a TASK_LOST will be generated.
*
* @param taskId
*/
public void kill(TaskID taskId) {
Builder kill = build().setKill(Kill.newBuilder().setTaskId(taskId));
sendCall(kill, Type.KILL);
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRecoveredTask.
@Test
public void testRecoveredTask() {
// set up the agent first
sms.resourceOffers(Arrays.asList(createOffer(1, 129, 1025, "agent1", "host1", Optional.of("rack1")))).join();
initRequest();
initFirstDeploy();
SingularityTask task = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
Assertions.assertEquals(1, taskManager.getNumActiveTasks());
TaskStatus lost = TaskStatus.newBuilder().setTaskId(MesosProtosUtils.toTaskId(task.getMesosTask().getTaskId())).setAgentId(MesosProtosUtils.toAgentId(task.getAgentId())).setReason(Reason.REASON_AGENT_REMOVED).setMessage("health check timed out").setState(TaskState.TASK_LOST).build();
sms.statusUpdate(lost).join();
Assertions.assertEquals(0, taskManager.getNumActiveTasks());
Assertions.assertTrue(taskManager.getTaskHistory(task.getTaskId()).isPresent());
TaskStatus recovered = TaskStatus.newBuilder().setTaskId(MesosProtosUtils.toTaskId(task.getMesosTask().getTaskId())).setAgentId(MesosProtosUtils.toAgentId(task.getAgentId())).setReason(Reason.REASON_AGENT_REREGISTERED).setMessage("agent reregistered").setState(TaskState.TASK_RUNNING).build();
sms.statusUpdate(recovered).join();
Assertions.assertEquals(1, taskManager.getNumActiveTasks());
Assertions.assertEquals(1, requestManager.getSizeOfPendingQueue());
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task in project Singularity by HubSpot.
the class SingularityMesosOfferSchedulerTest method itAccountsForMaxHistoricalTaskUsage.
@Test
public void itAccountsForMaxHistoricalTaskUsage() {
initRequest();
double cpuReserved = 2;
double memMbReserved = 1000;
initFirstDeployWithResources(cpuReserved, memMbReserved);
saveAndSchedule(requestManager.getRequest(requestId).get().getRequest().toBuilder().setInstances(Optional.of(1)));
resourceOffers(3);
SingularityTaskId taskId = taskManager.getActiveTaskIds().get(0);
String t1 = taskId.getId();
// 2 cpus used
MesosTaskMonitorObject t1u1 = getTaskMonitor(t1, 10, getTimestampSeconds(taskId, 5), 1000);
mesosClient.setAgentResourceUsage("host1", Collections.singletonList(t1u1));
usagePoller.runActionOnPoll();
// 1 cpus used
MesosTaskMonitorObject t1u2 = getTaskMonitor(t1, 11, getTimestampSeconds(taskId, 6), 1000);
mesosClient.setAgentResourceUsage("host1", Collections.singletonList(t1u2));
usagePoller.runActionOnPoll();
SingularityAgentUsage smallUsage = new SingularityAgentUsage(0.1, 0.1, Optional.of(10.0), 1, 1, Optional.of(30L), 1, 1, Optional.of(1024L), 1, System.currentTimeMillis(), 1, 30000, 10, 0, 0, 0, 0, 107374182);
usageManager.saveCurrentAgentUsage(new SingularityAgentUsageWithId(smallUsage, "host1"));
usageManager.saveCurrentAgentUsage(new SingularityAgentUsageWithId(smallUsage, "host2"));
usageManager.saveCurrentAgentUsage(new SingularityAgentUsageWithId(smallUsage, "host3"));
requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(3), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), SingularityUser.DEFAULT_USER);
Assertions.assertEquals(3.0, usageManager.getRequestUtilizations().get(requestId).getCpuUsed(), 0.001);
Offer host2Offer = createOffer(6, 30000, 107374182, "host2", "host2");
agentAndRackManager.checkOffer(host2Offer);
Offer host3Offer = createOffer(6, 30000, 107374182, "host3", "host3");
agentAndRackManager.checkOffer(host3Offer);
singularityScheduler.drainPendingQueue();
Collection<SingularityOfferHolder> offerHolders = offerScheduler.checkOffers(ImmutableMap.of(host2Offer.getId().getValue(), host2Offer, host3Offer.getId().getValue(), host3Offer), System.currentTimeMillis());
Assertions.assertEquals(2, offerHolders.size());
// A single offer should only ever get a single task even though both have room for both tasks here. Adding a task should reduce the score for the next check
for (SingularityOfferHolder offerHolder : offerHolders) {
Assertions.assertEquals(1, offerHolder.getAcceptedTasks().size());
}
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testAutomaticPortMapping.
@Test
public void testAutomaticPortMapping() {
NetworkConfiguration netConf = new NetworkConfiguration();
netConf.setDefaultPortMapping(true);
configuration.setNetworkConfiguration(netConf);
taskResources = new Resources(1, 1, 2);
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.DOCKER, Optional.empty(), Optional.of(new SingularityDockerInfo("docker-image", false, SingularityDockerNetworkType.BRIDGE, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty())));
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setContainerInfo(Optional.of(containerInfo)).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final SingularityMesosTaskHolder task = builder.buildTask(offerHolder, Collections.singletonList(MesosUtils.getPortRangeResource(31010, 31011)), taskRequest, taskResources, executorResources);
assertEquals(Type.DOCKER, task.getMesosTask().getContainer().getType());
assertEquals(Protos.ContainerInfo.DockerInfo.Network.BRIDGE, task.getMesosTask().getContainer().getDocker().getNetwork());
List<PortMapping> portMappings = task.getMesosTask().getContainer().getDocker().getPortMappingsList();
assertEquals(2, portMappings.size());
assertEquals(31010, portMappings.get(0).getHostPort());
assertEquals(31010, portMappings.get(0).getContainerPort());
assertEquals(31011, portMappings.get(1).getHostPort());
assertEquals(31011, portMappings.get(1).getContainerPort());
}
use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testMesosContainer.
@Test
public void testMesosContainer() {
taskResources = new Resources(1, 1, 2);
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.MESOS, Optional.of(Collections.singletonList(new SingularityVolume("/testing", Optional.of("/host"), SingularityDockerVolumeMode.RW, Optional.of(new SingularityVolumeSource(SingularityVolumeSourceType.DOCKER_VOLUME, Optional.of(new SingularityDockerVolume(Optional.of("rexray"), Optional.of("testvolume-%i"), Collections.singletonMap("iops", "1")))))))), Optional.empty(), Optional.of(new SingularityMesosInfo(Optional.of(new SingularityMesosImage(SingularityMesosImageType.DOCKER, Optional.empty(), Optional.of(new SingularityDockerImage("test:image")), true)))), Optional.of(Arrays.asList(new SingularityNetworkInfo(Optional.of("network-name"), Optional.of(Arrays.asList("blue", "purple")), Optional.of(Arrays.asList(new SingularityPortMapping(0, 8080, Optional.of("tcp")), new SingularityPortMapping(8888, 8081, Optional.of("udp"))))))));
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setContainerInfo(Optional.of(containerInfo)).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final SingularityMesosTaskHolder task = builder.buildTask(offerHolder, Collections.singletonList(MesosUtils.getPortRangeResource(31010, 31011)), taskRequest, taskResources, executorResources);
assertEquals(Type.MESOS, task.getMesosTask().getContainer().getType());
final Image image = task.getMesosTask().getContainer().getMesos().getImage();
assertEquals(Protos.Image.Type.DOCKER, image.getType());
assertEquals("test:image", image.getDocker().getName());
final Volume volume = task.getMesosTask().getContainer().getVolumesList().get(0);
assertEquals("/testing", volume.getContainerPath());
assertEquals("/host", volume.getHostPath());
assertEquals(Volume.Mode.RW, volume.getMode());
assertEquals(Volume.Source.Type.DOCKER_VOLUME, volume.getSource().getType());
final DockerVolume dockerVolume = volume.getSource().getDockerVolume();
assertEquals("rexray", dockerVolume.getDriver());
assertEquals("testvolume-1", dockerVolume.getName());
assertEquals("iops", dockerVolume.getDriverOptions().getParameterList().get(0).getKey());
final NetworkInfo networkInfo = task.getMesosTask().getContainer().getNetworkInfosList().get(0);
assertEquals("network-name", networkInfo.getName());
assertEquals(Arrays.asList("blue", "purple"), networkInfo.getGroupsList());
final List<Protos.NetworkInfo.PortMapping> portMappings = networkInfo.getPortMappingsList();
assertEquals(2, portMappings.size());
assertEquals(31010, portMappings.get(0).getHostPort());
assertEquals(8080, portMappings.get(0).getContainerPort());
assertEquals("tcp", portMappings.get(0).getProtocol());
assertEquals(8888, portMappings.get(1).getHostPort());
assertEquals(8081, portMappings.get(1).getContainerPort());
assertEquals("udp", portMappings.get(1).getProtocol());
}
Aggregations