use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class HistoryPersisterTest method testTaskAgePurging.
@Test
public void testTaskAgePurging() {
initLoadBalancedRequest();
initFirstDeploy();
SingularityTask taskOne = launchTask(request, firstDeploy, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(3), 1, TaskState.TASK_RUNNING);
SingularityTask taskTwo = launchTask(request, firstDeploy, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(3), 2, TaskState.TASK_RUNNING);
taskHistoryPersister.runActionOnPoll();
Assert.assertTrue(taskManager.getTaskHistory(taskOne.getTaskId()).isPresent());
Assert.assertTrue(taskManager.getTaskHistory(taskTwo.getTaskId()).isPresent());
configuration.setDeleteTasksFromZkWhenNoDatabaseAfterHours(1);
taskHistoryPersister.runActionOnPoll();
Assert.assertTrue(taskManager.getTaskHistory(taskOne.getTaskId()).isPresent());
Assert.assertTrue(taskManager.getTaskHistory(taskTwo.getTaskId()).isPresent());
statusUpdate(taskOne, TaskState.TASK_FINISHED, Optional.of(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(2)));
taskHistoryPersister.runActionOnPoll();
Assert.assertTrue(taskManager.getTaskHistory(taskOne.getTaskId()).isPresent());
Assert.assertTrue(taskManager.getTaskHistory(taskTwo.getTaskId()).isPresent());
cleaner.drainCleanupQueue();
taskHistoryPersister.runActionOnPoll();
Assert.assertTrue(!taskManager.getTaskHistory(taskOne.getTaskId()).isPresent());
Assert.assertTrue(taskManager.getTaskHistory(taskTwo.getTaskId()).isPresent());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class HistoryPersisterTest method testTaskCountPurging.
@Test
public void testTaskCountPurging() {
initLoadBalancedRequest();
initFirstDeploy();
configuration.setMaxStaleTasksPerRequestInZkWhenNoDatabase(Optional.of(2));
final int tasksToLaunch = 10;
final List<SingularityTaskId> taskIds = new ArrayList<>();
for (int i = 0; i < tasksToLaunch; i++) {
final SingularityTask task = launchTask(request, firstDeploy, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(3), 1, TaskState.TASK_RUNNING);
statusUpdate(task, TaskState.TASK_FINISHED, Optional.of(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(2)));
cleaner.drainCleanupQueue();
taskIds.add(task.getTaskId());
}
final List<SingularityTaskId> tasksBeforePurge = taskManager.getInactiveTaskIdsForDeploy(requestId, firstDeployId);
Assert.assertEquals(taskIds.size(), tasksBeforePurge.size());
Assert.assertTrue(tasksBeforePurge.containsAll(taskIds));
taskHistoryPersister.runActionOnPoll();
final List<SingularityTaskId> tasksAfterPurge = taskManager.getInactiveTaskIdsForDeploy(requestId, firstDeployId);
Assert.assertEquals(configuration.getMaxStaleTasksPerRequestInZkWhenNoDatabase().get().intValue(), tasksAfterPurge.size());
// we should just have the last 2 tasks
Assert.assertTrue(tasksAfterPurge.containsAll(taskIds.subList(tasksToLaunch - 2, tasksToLaunch - 1)));
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityUsageTest method testUsagePollerSimple.
@Test
public void testUsagePollerSimple() {
// works with no slaves
usagePoller.runActionOnPoll();
cleaner.runActionOnPoll();
initRequest();
initFirstDeploy();
saveAndSchedule(request.toBuilder().setInstances(Optional.of(1)));
resourceOffers(1);
SingularityTask firstTask = taskManager.getActiveTasks().get(0);
String hostname = firstTask.getHostname();
MesosTaskMonitorObject usage = getTaskMonitor(firstTask.getTaskId().getId(), 2, 5, 100);
mesosClient.setSlaveResourceUsage(hostname, Collections.singletonList(usage));
usagePoller.runActionOnPoll();
String slaveId = firstTask.getAgentId().getValue();
List<String> slaves = usageManager.getSlavesWithUsage();
Assert.assertEquals(1, slaves.size());
Assert.assertEquals(slaves.get(0), slaveId);
Assert.assertEquals(0, usageManager.getSlaveUsage(slaveId).get(0).getCpusUsed(), 0);
Assert.assertEquals(100, usageManager.getSlaveUsage(slaveId).get(0).getMemoryBytesUsed());
SingularityTaskUsage first = usageManager.getTaskUsage(firstTask.getTaskId().getId()).get(0);
Assert.assertEquals(2, first.getCpuSeconds(), 0);
Assert.assertEquals(100, first.getMemoryTotalBytes(), 0);
Assert.assertEquals(5, first.getTimestamp(), 0);
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class HistoryResource method getRecentCommandLineArgs.
@GET
@Path("/request/{requestId}/command-line-args")
@ApiOperation("Get a list of recently used command line args for an on-demand or scheduled request")
public Set<List<String>> getRecentCommandLineArgs(@Auth SingularityUser user, @ApiParam("Request ID to look up") @PathParam("requestId") String requestId, @ApiParam("Max number of recent args to return") @QueryParam("count") Optional<Integer> count) {
authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);
final int argCount = count.or(DEFAULT_ARGS_HISTORY_COUNT);
List<SingularityTaskIdHistory> historiesToCheck = taskHistoryHelper.getBlendedHistory(new SingularityTaskHistoryQuery(Optional.of(requestId), Optional.<String>absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<ExtendedTaskState>absent(), Optional.<Long>absent(), Optional.<Long>absent(), Optional.<Long>absent(), Optional.<Long>absent(), Optional.<OrderDirection>absent()), 0, argCount);
Collections.sort(historiesToCheck);
Set<List<String>> args = new HashSet<>();
for (SingularityTaskIdHistory taskIdHistory : historiesToCheck) {
Optional<SingularityTask> maybeTask = taskHistoryHelper.getTask(taskIdHistory.getTaskId());
if (maybeTask.isPresent() && maybeTask.get().getTaskRequest().getPendingTask().getCmdLineArgsList().isPresent()) {
List<String> taskArgs = maybeTask.get().getTaskRequest().getPendingTask().getCmdLineArgsList().get();
if (!taskArgs.isEmpty()) {
args.add(maybeTask.get().getTaskRequest().getPendingTask().getCmdLineArgsList().get());
}
}
}
return args;
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class LoadBalancerClientImpl method tasksToUpstreams.
private List<UpstreamInfo> tasksToUpstreams(List<SingularityTask> tasks, String requestId, Optional<String> loadBalancerUpstreamGroup) {
final List<UpstreamInfo> upstreams = Lists.newArrayListWithCapacity(tasks.size());
for (SingularityTask task : tasks) {
final Optional<Long> maybeLoadBalancerPort = MesosUtils.getPortByIndex(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), task.getTaskRequest().getDeploy().getLoadBalancerPortIndex().or(0));
if (maybeLoadBalancerPort.isPresent()) {
String upstream = String.format("%s:%d", task.getHostname(), maybeLoadBalancerPort.get());
Optional<String> group = loadBalancerUpstreamGroup;
if (taskLabelForLoadBalancerUpstreamGroup.isPresent()) {
for (MesosParameter label : task.getMesosTask().getLabels().getLabels()) {
if (label.hasKey() && label.getKey().equals(taskLabelForLoadBalancerUpstreamGroup.get()) && label.hasValue()) {
group = Optional.of(label.getValue());
break;
}
}
}
upstreams.add(new UpstreamInfo(upstream, Optional.of(requestId), task.getRackId(), Optional.<String>absent(), group));
} else {
LOG.warn("Task {} is missing port but is being passed to LB ({})", task.getTaskId(), task);
}
}
return upstreams;
}
Aggregations