Search in sources :

Example 6 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularitySchedulerTest method testDifferentQuartzTimeZones.

@Test
public void testDifferentQuartzTimeZones() {
    final Optional<String> schedule = Optional.of("* 30 14 22 3 ? 2083");
    SingularityRequest requestEST = new SingularityRequestBuilder("est_id", RequestType.SCHEDULED).setSchedule(schedule).setScheduleType(Optional.of(ScheduleType.QUARTZ)).setScheduleTimeZone(// fixed in relation to GMT
    Optional.of("EST")).build();
    SingularityRequest requestGMT = new SingularityRequestBuilder("gmt_id", RequestType.SCHEDULED).setSchedule(schedule).setScheduleType(Optional.of(ScheduleType.QUARTZ)).setScheduleTimeZone(Optional.of("GMT")).build();
    requestResource.postRequest(requestEST, singularityUser);
    requestResource.postRequest(requestGMT, singularityUser);
    SingularityDeploy deployEST = new SingularityDeployBuilder(requestEST.getId(), "est_deploy_id").setCommand(Optional.of("sleep 1")).build();
    SingularityDeploy deployGMT = new SingularityDeployBuilder(requestGMT.getId(), "gmt_deploy_id").setCommand(Optional.of("sleep 1")).build();
    deployResource.deploy(new SingularityDeployRequest(deployEST, Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    deployResource.deploy(new SingularityDeployRequest(deployGMT, Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    final long nextRunEST;
    final long nextRunGMT;
    final long fiveHoursInMilliseconds = TimeUnit.HOURS.toMillis(5);
    final List<SingularityPendingTaskId> pendingTaskIds = taskManager.getPendingTaskIds();
    if (pendingTaskIds.get(0).getRequestId().equals(requestEST.getId())) {
        nextRunEST = pendingTaskIds.get(0).getNextRunAt();
        nextRunGMT = pendingTaskIds.get(1).getNextRunAt();
    } else {
        nextRunEST = pendingTaskIds.get(1).getNextRunAt();
        nextRunGMT = pendingTaskIds.get(0).getNextRunAt();
    }
    // GMT happens first, so EST is a larger timestamp
    Assert.assertEquals(nextRunEST - nextRunGMT, fiveHoursInMilliseconds);
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 7 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method deploy.

protected void deploy(String deployId, Optional<Boolean> unpauseOnDeploy, Optional<Integer> deployRate, Optional<Boolean> autoAdvance, boolean loadBalanced) {
    SingularityDeployBuilder builder = new SingularityDeployBuilder(requestId, deployId);
    builder.setCommand(Optional.of("sleep 1")).setDeployInstanceCountPerStep(deployRate).setAutoAdvanceDeploySteps(autoAdvance).setDeployStepWaitTimeMs(Optional.of(0));
    if (loadBalanced) {
        Set<String> groups = new HashSet<>(Arrays.asList("group"));
        builder.setServiceBasePath(Optional.of("/basepath")).setLoadBalancerGroups(Optional.of(groups));
    }
    deployResource.deploy(new SingularityDeployRequest(builder.build(), unpauseOnDeploy, Optional.absent()), singularityUser);
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) HashSet(java.util.HashSet)

Example 8 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method deployRequest.

protected SingularityDeploy deployRequest(SingularityRequest request, double cpus, double memoryMb) {
    Resources r = new Resources(cpus, memoryMb, 0);
    SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), "deploy1").setCommand(Optional.of("sleep 1")).setResources(Optional.of(r)).build();
    deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent()), singularityUser);
    return deploy;
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) SingularityDeploy(com.hubspot.singularity.SingularityDeploy)

Example 9 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularityDeploysTest method testUsesNewRequestDataFromPendingDeploy.

@Test
public void testUsesNewRequestDataFromPendingDeploy() {
    initRequest();
    initFirstDeploy();
    saveAndSchedule(request.toBuilder().setInstances(Optional.of(2)));
    scheduler.drainPendingQueue();
    Assert.assertEquals(2, taskManager.getPendingTaskIds().size());
    Assert.assertEquals(2, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    SingularityRequest newRequest = request.toBuilder().setInstances(Optional.of(1)).build();
    String deployId = "test_new_request_data";
    SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), deployId).setCommand(Optional.of("sleep 100")).build();
    deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    List<SingularityPendingTaskId> pendingTaskIdsForNewDeploy = new ArrayList<>();
    for (SingularityPendingTaskId pendingTaskId : taskManager.getPendingTaskIds()) {
        if (pendingTaskId.getDeployId().equals(deployId)) {
            pendingTaskIdsForNewDeploy.add(pendingTaskId);
        }
    }
    Assert.assertEquals(1, pendingTaskIdsForNewDeploy.size());
    Assert.assertEquals(2, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
    resourceOffers();
    for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, deployId)) {
        statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
    }
    deployChecker.checkDeploys();
    Assert.assertEquals(1, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) ArrayList(java.util.ArrayList) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 10 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularityDeploysTest method testCannotUpdateRequestDuringPendingDeployWithNewData.

@Test(expected = WebApplicationException.class)
public void testCannotUpdateRequestDuringPendingDeployWithNewData() {
    initRequest();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    SingularityRequest newRequest = request.toBuilder().setInstances(Optional.of(1)).build();
    String deployId = "test_new_request_data";
    SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), deployId).setCommand(Optional.of("sleep 100")).build();
    deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
    requestResource.postRequest(newRequest, singularityUser);
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Aggregations

SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)18 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)15 Test (org.junit.Test)14 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)10 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)8 SingularityRequest (com.hubspot.singularity.SingularityRequest)6 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)3 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)3 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)3 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)2 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 HttpResponse (com.hubspot.horizon.HttpResponse)1 Resources (com.hubspot.mesos.Resources)1 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)1 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)1 SingularityPriorityFreezeParent (com.hubspot.singularity.SingularityPriorityFreezeParent)1 SingularityRequestParent (com.hubspot.singularity.SingularityRequestParent)1 SingularityPriorityFreeze (com.hubspot.singularity.api.SingularityPriorityFreeze)1 ArrayList (java.util.ArrayList)1