Search in sources :

Example 6 with SingularityPendingTaskId

use of com.hubspot.singularity.SingularityPendingTaskId 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 SingularityPendingTaskId

use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method createAndSchedulePendingTask.

protected SingularityPendingTask createAndSchedulePendingTask(String deployId) {
    Random random = new Random();
    SingularityPendingTaskId pendingTaskId = new SingularityPendingTaskId(requestId, deployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(random.nextInt(3)), random.nextInt(10), PendingType.NEW_DEPLOY, System.currentTimeMillis());
    SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(pendingTaskId).build();
    taskManager.savePendingTask(pendingTask);
    return pendingTask;
}
Also used : Random(java.util.Random) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder)

Example 8 with SingularityPendingTaskId

use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.

the class SingularityMesosTaskBuilderTest method createMocks.

@Before
public void createMocks() {
    pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(new SingularityPendingTaskId("test", "1", 0, 1, PendingType.IMMEDIATE, 0)).setUser(user).build();
    final SingularitySlaveAndRackHelper slaveAndRackHelper = mock(SingularitySlaveAndRackHelper.class);
    final ExecutorIdGenerator idGenerator = mock(ExecutorIdGenerator.class);
    when(idGenerator.getNextExecutorId()).then(new CreateFakeId());
    objectMapper = new ObjectMapper();
    objectMapper.registerModule(new ProtobufModule());
    objectMapper.registerModule(new GuavaModule());
    builder = new SingularityMesosTaskBuilder(objectMapper, idGenerator, configuration, new MesosProtosUtils(objectMapper));
    taskResources = new Resources(1, 1, 0, 0);
    executorResources = new Resources(0.1, 1, 0, 0);
    when(slaveAndRackHelper.getRackId(offer)).thenReturn(Optional.absent());
    when(slaveAndRackHelper.getMaybeTruncatedHost(offer)).thenReturn("host");
    when(slaveAndRackHelper.getRackIdOrDefault(offer)).thenReturn("DEFAULT");
    offer = Offer.newBuilder().setAgentId(AgentID.newBuilder().setValue("1")).setId(OfferID.newBuilder().setValue("1")).setFrameworkId(FrameworkID.newBuilder().setValue("1")).setHostname("test").build();
    offerHolder = new SingularityOfferHolder(Collections.singletonList(offer), 1, "DEFAULT", offer.getAgentId().getValue(), offer.getHostname(), Collections.emptyMap(), Collections.emptyMap());
}
Also used : MesosProtosUtils(com.hubspot.singularity.helpers.MesosProtosUtils) ExecutorIdGenerator(com.hubspot.singularity.data.ExecutorIdGenerator) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) Resources(com.hubspot.mesos.Resources) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder) Before(org.junit.Before)

Example 9 with SingularityPendingTaskId

use of com.hubspot.singularity.SingularityPendingTaskId 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 SingularityPendingTaskId

use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.

the class SingularityDeploysTest method testDeployClearsObsoleteScheduledTasks.

@Test
public void testDeployClearsObsoleteScheduledTasks() {
    initRequest();
    initFirstDeploy();
    initSecondDeploy();
    SingularityPendingTaskId taskIdOne = new SingularityPendingTaskId(requestId, firstDeployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(3), 1, PendingType.IMMEDIATE, System.currentTimeMillis());
    SingularityPendingTask taskOne = new SingularityPendingTaskBuilder().setPendingTaskId(taskIdOne).build();
    SingularityPendingTaskId taskIdTwo = new SingularityPendingTaskId(requestId, firstDeployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1), 2, PendingType.IMMEDIATE, System.currentTimeMillis());
    SingularityPendingTask taskTwo = new SingularityPendingTaskBuilder().setPendingTaskId(taskIdTwo).build();
    SingularityPendingTaskId taskIdThree = new SingularityPendingTaskId(requestId, secondDeployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(3), 1, PendingType.IMMEDIATE, System.currentTimeMillis());
    SingularityPendingTask taskThree = new SingularityPendingTaskBuilder().setPendingTaskId(taskIdThree).build();
    SingularityPendingTaskId taskIdFour = new SingularityPendingTaskId(requestId + "hi", firstDeployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(3), 5, PendingType.IMMEDIATE, System.currentTimeMillis());
    SingularityPendingTask taskFour = new SingularityPendingTaskBuilder().setPendingTaskId(taskIdFour).build();
    taskManager.savePendingTask(taskOne);
    taskManager.savePendingTask(taskTwo);
    taskManager.savePendingTask(taskThree);
    taskManager.savePendingTask(taskFour);
    launchTask(request, secondDeploy, 1, TaskState.TASK_RUNNING);
    deployChecker.checkDeploys();
    List<SingularityPendingTaskId> pendingTaskIds = taskManager.getPendingTaskIds();
    Assert.assertTrue(!pendingTaskIds.contains(taskIdOne));
    Assert.assertTrue(!pendingTaskIds.contains(taskIdTwo));
    Assert.assertTrue(pendingTaskIds.contains(taskIdThree));
    Assert.assertTrue(pendingTaskIds.contains(taskIdFour));
}
Also used : SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder) Test(org.junit.Test)

Aggregations

SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)36 SingularityRequest (com.hubspot.singularity.SingularityRequest)16 Test (org.junit.Test)16 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)15 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)9 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)8 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)8 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)7 SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)7 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)6 SingularityTask (com.hubspot.singularity.SingularityTask)6 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)5 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)4 PendingType (com.hubspot.singularity.SingularityPendingRequest.PendingType)4 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)4 Optional (com.google.common.base.Optional)3 Inject (com.google.inject.Inject)3 RequestType (com.hubspot.singularity.RequestType)3 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)3 ArrayList (java.util.ArrayList)3