Search in sources :

Example 6 with Task

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);
}
Also used : MesosClientBuilder(com.hubspot.mesos.rx.java.MesosClientBuilder) Builder(org.apache.mesos.v1.scheduler.Protos.Call.Builder) ProtobufMesosClientBuilder(com.hubspot.mesos.rx.java.protobuf.ProtobufMesosClientBuilder)

Example 7 with Task

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());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) TaskStatus(org.apache.mesos.v1.Protos.TaskStatus) Test(org.junit.jupiter.api.Test)

Example 8 with Task

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());
    }
}
Also used : SingularityAgentUsage(com.hubspot.singularity.SingularityAgentUsage) Offer(org.apache.mesos.v1.Protos.Offer) SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) SingularityAgentUsageWithId(com.hubspot.singularity.SingularityAgentUsageWithId) Test(org.junit.jupiter.api.Test)

Example 9 with Task

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());
}
Also used : SingularityContainerInfo(com.hubspot.mesos.SingularityContainerInfo) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityMesosTaskHolder(com.hubspot.singularity.helpers.SingularityMesosTaskHolder) NetworkConfiguration(com.hubspot.singularity.config.NetworkConfiguration) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) PortMapping(org.apache.mesos.v1.Protos.ContainerInfo.DockerInfo.PortMapping) SingularityPortMapping(com.hubspot.mesos.SingularityPortMapping) SingularityDockerPortMapping(com.hubspot.mesos.SingularityDockerPortMapping) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityDockerInfo(com.hubspot.mesos.SingularityDockerInfo) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.jupiter.api.Test)

Example 10 with Task

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());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityNetworkInfo(com.hubspot.mesos.SingularityNetworkInfo) SingularityDockerVolume(com.hubspot.mesos.SingularityDockerVolume) NetworkInfo(org.apache.mesos.v1.Protos.NetworkInfo) SingularityNetworkInfo(com.hubspot.mesos.SingularityNetworkInfo) SingularityVolume(com.hubspot.mesos.SingularityVolume) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityMesosTaskHolder(com.hubspot.singularity.helpers.SingularityMesosTaskHolder) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDockerImage(com.hubspot.mesos.SingularityDockerImage) SingularityMesosImage(com.hubspot.mesos.SingularityMesosImage) SingularityDockerImage(com.hubspot.mesos.SingularityDockerImage) Image(org.apache.mesos.v1.Protos.Image) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityContainerInfo(com.hubspot.mesos.SingularityContainerInfo) SingularityPortMapping(com.hubspot.mesos.SingularityPortMapping) SingularityDockerVolume(com.hubspot.mesos.SingularityDockerVolume) Volume(org.apache.mesos.v1.Protos.Volume) SingularityVolume(com.hubspot.mesos.SingularityVolume) DockerVolume(org.apache.mesos.v1.Protos.Volume.Source.DockerVolume) Protos(org.apache.mesos.v1.Protos) Resources(com.hubspot.mesos.Resources) SingularityMesosInfo(com.hubspot.mesos.SingularityMesosInfo) PortMapping(org.apache.mesos.v1.Protos.ContainerInfo.DockerInfo.PortMapping) SingularityPortMapping(com.hubspot.mesos.SingularityPortMapping) SingularityDockerPortMapping(com.hubspot.mesos.SingularityDockerPortMapping) SingularityMesosImage(com.hubspot.mesos.SingularityMesosImage) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityVolumeSource(com.hubspot.mesos.SingularityVolumeSource) SingularityDockerVolume(com.hubspot.mesos.SingularityDockerVolume) DockerVolume(org.apache.mesos.v1.Protos.Volume.Source.DockerVolume) Test(org.junit.jupiter.api.Test)

Aggregations

SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)11 Test (org.junit.jupiter.api.Test)11 SingularityTask (com.hubspot.singularity.SingularityTask)9 Resources (com.hubspot.mesos.Resources)8 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)8 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)8 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)7 SingularityRequest (com.hubspot.singularity.SingularityRequest)7 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)6 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)6 Protos (org.apache.mesos.v1.Protos)5 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)4 SingularityDockerPortMapping (com.hubspot.mesos.SingularityDockerPortMapping)4 TaskInfo (org.apache.mesos.v1.Protos.TaskInfo)4 ImmutableList (com.google.common.collect.ImmutableList)3 Inject (com.google.inject.Inject)3 ByteString (com.google.protobuf.ByteString)3 JavaUtils (com.hubspot.mesos.JavaUtils)3 SingularityDockerInfo (com.hubspot.mesos.SingularityDockerInfo)3 SingularityPortMapping (com.hubspot.mesos.SingularityPortMapping)3