Search in sources :

Example 1 with SingularityPendingTaskBuilder

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

the class SingularityCmdLineArgsMigration method checkPendingTasks.

private void checkPendingTasks() {
    try {
        if (curator.checkExists().forPath(TASK_PENDING_PATH) == null) {
            return;
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    try {
        for (SingularityPendingTaskId pendingTaskId : taskManager.getPendingTaskIds()) {
            Optional<String> cmdLineArgs = getCmdLineArgs(pendingTaskId);
            SingularityCreateResult result = taskManager.savePendingTask(new SingularityPendingTaskBuilder().setPendingTaskId(pendingTaskId).setCmdLineArgsList(getCmdLineArgs(cmdLineArgs)).build());
            LOG.info("Saving {} ({}) {}", pendingTaskId, cmdLineArgs, result);
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder)

Example 2 with SingularityPendingTaskBuilder

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

the class SingularityPendingTaskIdMigration method applyMigration.

@Override
public void applyMigration() {
    final long start = System.currentTimeMillis();
    try {
        if (curator.checkExists().forPath(PENDING_TASKS_ROOT) == null) {
            return;
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    try {
        for (String pendingTaskId : curator.getChildren().forPath(PENDING_TASKS_ROOT)) {
            SingularityPendingTaskId newPendingTaskId = createFrom(pendingTaskId, start);
            if (!newPendingTaskId.toString().equals(pendingTaskId)) {
                LOG.info("Migrating {} to {}", pendingTaskId, newPendingTaskId);
                Optional<String> cmdLineArgs = getCmdLineArgs(pendingTaskId);
                taskManager.savePendingTask(new SingularityPendingTaskBuilder().setPendingTaskId(newPendingTaskId).setCmdLineArgsList(cmdLineArgs.isPresent() ? Optional.of(Collections.singletonList(cmdLineArgs.get())) : Optional.<List<String>>absent()).build());
                curator.delete().forPath(ZKPaths.makePath(PENDING_TASKS_ROOT, pendingTaskId));
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) List(java.util.List) InvalidSingularityTaskIdException(com.hubspot.singularity.InvalidSingularityTaskIdException) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder)

Example 3 with SingularityPendingTaskBuilder

use of com.hubspot.singularity.SingularityPendingTaskBuilder 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 4 with SingularityPendingTaskBuilder

use of com.hubspot.singularity.SingularityPendingTaskBuilder 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 5 with SingularityPendingTaskBuilder

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

SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)7 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)7 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 ProtobufModule (com.hubspot.jackson.datatype.protobuf.ProtobufModule)1 Resources (com.hubspot.mesos.Resources)1 InvalidSingularityTaskIdException (com.hubspot.singularity.InvalidSingularityTaskIdException)1 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)1 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)1 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)1 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)1 ExecutorIdGenerator (com.hubspot.singularity.data.ExecutorIdGenerator)1 MesosProtosUtils (com.hubspot.singularity.helpers.MesosProtosUtils)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1