use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class SingularityScheduler method getScheduledTaskIds.
private List<SingularityPendingTask> getScheduledTaskIds(int numMissingInstances, List<SingularityTaskId> matchingTaskIds, SingularityRequest request, RequestState state, SingularityDeployStatistics deployStatistics, String deployId, SingularityPendingRequest pendingRequest, Optional<SingularityPendingDeploy> maybePendingDeploy) {
final Optional<Long> nextRunAt = getNextRunAt(request, state, deployStatistics, pendingRequest, maybePendingDeploy);
if (!nextRunAt.isPresent()) {
return Collections.emptyList();
}
final Set<Integer> inuseInstanceNumbers = Sets.newHashSetWithExpectedSize(matchingTaskIds.size());
for (SingularityTaskId matchingTaskId : matchingTaskIds) {
inuseInstanceNumbers.add(matchingTaskId.getInstanceNo());
}
final List<SingularityPendingTask> newTasks = Lists.newArrayListWithCapacity(numMissingInstances);
int nextInstanceNumber = 1;
for (int i = 0; i < numMissingInstances; i++) {
while (inuseInstanceNumbers.contains(nextInstanceNumber)) {
nextInstanceNumber++;
}
newTasks.add(new SingularityPendingTask(new SingularityPendingTaskId(request.getId(), deployId, nextRunAt.get(), nextInstanceNumber, pendingRequest.getPendingType(), pendingRequest.getTimestamp()), pendingRequest.getCmdLineArgsList(), pendingRequest.getUser(), pendingRequest.getRunId(), pendingRequest.getSkipHealthchecks(), pendingRequest.getMessage(), pendingRequest.getResources(), pendingRequest.getS3UploaderAdditionalFiles(), pendingRequest.getRunAsUserOverride(), pendingRequest.getEnvOverrides(), pendingRequest.getExtraArtifacts(), pendingRequest.getActionId()));
nextInstanceNumber++;
}
return newTasks;
}
use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class ValidatorTest method whenRunNowItForbidsMoreInstancesForOnDemandThanInRequest.
@Test(expected = WebApplicationException.class)
public void whenRunNowItForbidsMoreInstancesForOnDemandThanInRequest() {
String deployID = "deploy";
Optional<String> userEmail = Optional.absent();
SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.ON_DEMAND).setInstances(Optional.of(1)).build();
Optional<SingularityRunNowRequest> runNowRequest = Optional.absent();
List<SingularityTaskId> activeTasks = Collections.singletonList(activeTask());
List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
}
use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class ValidatorTest method whenRunNowIfRunIdSetItWillBePropagated.
@Test
public void whenRunNowIfRunIdSetItWillBePropagated() {
String deployID = "deploy";
Optional<String> userEmail = Optional.absent();
SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.ON_DEMAND).build();
Optional<SingularityRunNowRequest> runNowRequest = Optional.of(runNowRequest("runId"));
List<SingularityTaskId> activeTasks = Collections.emptyList();
List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
SingularityPendingRequest pendingRequest = validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
Assert.assertEquals("runId", pendingRequest.getRunId().get());
}
use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class ValidatorTest method whenRunNowItForbidsTooLongRunIds.
@Test(expected = WebApplicationException.class)
public void whenRunNowItForbidsTooLongRunIds() {
String deployID = "deploy";
Optional<String> userEmail = Optional.absent();
SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.SERVICE).build();
Optional<SingularityRunNowRequest> runNowRequest = Optional.of(runNowRequest(tooLongId()));
List<SingularityTaskId> activeTasks = Collections.emptyList();
List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
}
use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class ZkMigrationTest method testCmdLineArgsMigration.
@Test
public void testCmdLineArgsMigration() throws Exception {
metadataManager.setZkDataVersion("2");
// save some old stuff
SingularityPendingRequestPrevious p1 = new SingularityPendingRequestPrevious("r1", "d1", 23L, Optional.<String>absent(), PendingType.BOUNCE, Optional.<String>absent());
SingularityPendingRequestPrevious p2 = new SingularityPendingRequestPrevious("r2", "d3", 123L, Optional.of("user1"), PendingType.BOUNCE, Optional.of("cmd line args"));
byte[] p1b = objectMapper.writeValueAsBytes(p1);
byte[] p2b = objectMapper.writeValueAsBytes(p2);
curator.create().creatingParentsIfNeeded().forPath(getPendingPath("r1", "d1"), p1b);
curator.create().creatingParentsIfNeeded().forPath(getPendingPath("r2", "de"), p2b);
SingularityPendingTaskId pt1 = new SingularityPendingTaskId("r1", "d1", 23L, 3, PendingType.BOUNCE, 1L);
SingularityPendingTaskId pt2 = new SingularityPendingTaskId("r2", "d3", 231L, 1, PendingType.UNPAUSED, 23L);
curator.create().creatingParentsIfNeeded().forPath(getPendingPath(pt1));
curator.create().creatingParentsIfNeeded().forPath(getPendingPath(pt2), StringTranscoder.INSTANCE.toBytes("cmd line args"));
migrationRunner.checkMigrations();
Assert.assertTrue(!taskManager.getPendingTask(pt1).get().getCmdLineArgsList().isPresent());
Assert.assertTrue(taskManager.getPendingTask(pt2).get().getCmdLineArgsList().get().get(0).equals("cmd line args"));
Assert.assertTrue(taskManager.getPendingTask(pt2).get().getCmdLineArgsList().get().size() == 1);
Assert.assertTrue(taskManager.getPendingTaskIds().contains(pt1));
Assert.assertTrue(taskManager.getPendingTaskIds().contains(pt2));
Assert.assertTrue(requestManager.getPendingRequests().size() == 2);
for (SingularityPendingRequest r : requestManager.getPendingRequests()) {
if (r.getRequestId().equals("r1")) {
Assert.assertEquals(r.getDeployId(), p1.getDeployId());
Assert.assertEquals(r.getTimestamp(), p1.getTimestamp());
Assert.assertEquals(r.getPendingType(), p1.getPendingType());
Assert.assertTrue(!r.getCmdLineArgsList().isPresent());
Assert.assertEquals(r.getUser(), p1.getUser());
} else {
Assert.assertEquals(r.getDeployId(), p2.getDeployId());
Assert.assertEquals(r.getTimestamp(), p2.getTimestamp());
Assert.assertEquals(r.getPendingType(), p2.getPendingType());
Assert.assertTrue(r.getCmdLineArgsList().get().size() == 1);
Assert.assertTrue(r.getCmdLineArgsList().get().get(0).equals("cmd line args"));
Assert.assertEquals(r.getUser(), p2.getUser());
}
}
}
Aggregations