Search in sources :

Example 21 with Task

use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task in project Singularity by HubSpot.

the class SingularityMesosSchedulerClient method reconcile.

/**
 * Sent by the scheduler to query the status of non-terminal tasks. This causes the master to send back UPDATE
 * events for each task in the list. Tasks that are no longer known to Mesos will result in TASK_LOST updates.
 * If the list of tasks is empty, master will send UPDATE events for all currently known tasks of the framework.
 *
 * @param tasks
 */
public void reconcile(List<Reconcile.Task> tasks) {
    Builder reconsile = build().setReconcile(Reconcile.newBuilder().addAllTasks(tasks));
    sendCall(reconsile, Type.RECONCILE);
}
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 22 with Task

use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task in project Singularity by HubSpot.

the class SingularityMesosOfferSchedulerTest method itAccountsForExpectedTaskUsage.

@Test
public void itAccountsForExpectedTaskUsage() {
    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, (double) (taskId.getStartedAt() + 5000) / 1000, 1000);
    mesosClient.setAgentResourceUsage("host1", Collections.singletonList(t1u1));
    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(2.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 23 with Task

use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task 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");
    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(environmentVariables.get(key), overrideVariables.get(key), "Environment variable " + key + " not overridden.");
    }
}
Also used : TaskInfo(org.apache.mesos.v1.Protos.TaskInfo) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) HashMap(java.util.HashMap) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder) Test(org.junit.jupiter.api.Test)

Example 24 with Task

use of org.apache.mesos.v1.scheduler.Protos.Call.Reconcile.Task 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(31006).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(31005L, task.getTask().getPortByIndex(2).get().longValue());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) Protos(org.apache.mesos.v1.Protos) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityMesosTaskHolder(com.hubspot.singularity.helpers.SingularityMesosTaskHolder) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) 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