use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testMaxOnDemandTasks.
@Test
public void testMaxOnDemandTasks() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
bldr.setInstances(Optional.of(1));
requestResource.postRequest(bldr.build(), singularityUser);
deploy("on_demand_deploy");
deployChecker.checkDeploys();
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", System.currentTimeMillis(), Optional.<String>empty(), PendingType.ONEOFF, Optional.<List<String>>empty(), Optional.<String>empty(), Optional.<Boolean>empty(), Optional.<String>empty(), Optional.<String>empty()));
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", System.currentTimeMillis(), Optional.<String>empty(), PendingType.ONEOFF, Optional.<List<String>>empty(), Optional.<String>empty(), Optional.<Boolean>empty(), Optional.<String>empty(), Optional.<String>empty()));
scheduler.drainPendingQueue();
resourceOffers();
Assertions.assertEquals(1, taskManager.getActiveTaskIds().size());
}
use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testSchedulerDropsMultipleScheduledTaskInstances.
@Test
public void testSchedulerDropsMultipleScheduledTaskInstances() {
initScheduledRequest();
SingularityDeploy deploy = SingularityDeploy.newBuilder(requestId, firstDeployId).setCommand(Optional.of("sleep 100")).build();
SingularityDeployRequest singularityDeployRequest = new SingularityDeployRequest(deploy, Optional.empty(), Optional.empty(), Optional.empty());
deployResource.deploy(singularityDeployRequest, singularityUser);
scheduler.drainPendingQueue();
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, firstDeployId, Instant.now().plus(3, ChronoUnit.DAYS).toEpochMilli(), Optional.empty(), PendingType.NEW_DEPLOY, Optional.empty(), Optional.empty()));
SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().build();
requestResource.scheduleImmediately(singularityUser, requestId, runNowRequest);
Assertions.assertEquals(2, requestManager.getPendingRequests().size());
Assertions.assertEquals(PendingType.IMMEDIATE, requestManager.getPendingRequests().get(0).getPendingType());
Assertions.assertEquals(PendingType.NEW_DEPLOY, requestManager.getPendingRequests().get(1).getPendingType());
scheduler.drainPendingQueue();
Assertions.assertEquals(1, taskManager.getPendingTaskIds().size());
Assertions.assertEquals(PendingType.IMMEDIATE, taskManager.getPendingTaskIds().get(0).getPendingType());
Assertions.assertEquals(0, requestManager.getPendingRequests().size());
}
use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testQueueMultipleOneOffs.
@Test
public void testQueueMultipleOneOffs() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
requestResource.postRequest(bldr.build(), singularityUser);
deploy("on_demand_deploy");
deployChecker.checkDeploys();
long now = System.currentTimeMillis();
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", now, Optional.<String>empty(), PendingType.ONEOFF, Optional.<List<String>>empty(), Optional.<String>empty(), Optional.<Boolean>empty(), Optional.<String>empty(), Optional.<String>empty()));
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", now + 1, Optional.<String>empty(), PendingType.ONEOFF, Optional.<List<String>>empty(), Optional.<String>empty(), Optional.<Boolean>empty(), Optional.<String>empty(), Optional.<String>empty()));
scheduler.drainPendingQueue();
Assertions.assertEquals(2, taskManager.getPendingTaskIds().size());
}
use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class PendingRequestDataMigration method applyMigration.
@Override
public void applyMigration() {
String basePath = "/requests/pending";
LOG.info("Starting migration to re-write pending request paths");
long start = System.currentTimeMillis();
int rewrittenPaths = 0;
try {
if (curator.checkExists().forPath(basePath) == null) {
return;
}
} catch (Exception exn) {
LOG.error("Could not check existence of pending request path", exn);
throw new RuntimeException(exn);
}
try {
List<String> childPaths = curator.getChildren().forPath(basePath);
for (String childPath : childPaths) {
SingularityPendingRequest pendingRequest = requestTranscoder.fromBytes(curator.getData().forPath(String.format("%s/%s", basePath, childPath)));
if (pendingRequest.getPendingType() == PendingType.IMMEDIATE) {
String rewrittenPath = new SingularityDeployKey(pendingRequest.getRequestId(), pendingRequest.getDeployId()).getId();
LOG.warn("Rewriting path {} to {}", childPath, String.format("%s%s", rewrittenPath, pendingRequest.getTimestamp()));
requestManager.addToPendingQueue(pendingRequest);
curator.delete().forPath(String.format("%s/%s", basePath, childPath));
rewrittenPaths += 1;
} else {
LOG.warn("Not rewriting path {}, already correct", childPath);
}
}
} catch (Exception exn) {
LOG.error("Connection to Zookeeper failed while running migration", exn);
throw new RuntimeException(exn);
}
LOG.warn("Applied PendingRequestDataMigration to {} requests in {}", rewrittenPaths, JavaUtils.duration(start));
}
use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class RequestHelper method unpause.
public long unpause(SingularityRequest request, String user, Optional<String> message, Optional<Boolean> skipHealthchecks) {
mailer.sendRequestUnpausedMail(request, user, message);
Optional<String> maybeDeployId = deployManager.getInUseDeployId(request.getId());
final long now = System.currentTimeMillis();
requestManager.unpause(request, now, Optional.of(user), message);
if (maybeDeployId.isPresent() && !request.isOneOff()) {
requestManager.addToPendingQueue(new SingularityPendingRequest(request.getId(), maybeDeployId.get(), now, Optional.of(user), PendingType.UNPAUSED, skipHealthchecks, message));
}
return now;
}
Aggregations