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);
}
}
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);
}
}
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;
}
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());
}
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));
}
Aggregations