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);
}
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());
}
}
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.");
}
}
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());
}
Aggregations