Search in sources :

Example 86 with SingularityTask

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());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Example 87 with SingularityTask

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)));
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) ArrayList(java.util.ArrayList) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 88 with SingularityTask

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);
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskUsage(com.hubspot.singularity.SingularityTaskUsage) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) Test(org.junit.Test)

Example 89 with SingularityTask

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;
}
Also used : ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryQuery(com.hubspot.singularity.SingularityTaskHistoryQuery) List(java.util.List) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory) OrderDirection(com.hubspot.singularity.OrderDirection) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 90 with SingularityTask

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;
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) MesosParameter(com.hubspot.mesos.protos.MesosParameter) UpstreamInfo(com.hubspot.baragon.models.UpstreamInfo)

Aggregations

SingularityTask (com.hubspot.singularity.SingularityTask)94 Test (org.junit.Test)66 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)33 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)15 SingularityRequest (com.hubspot.singularity.SingularityRequest)15 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)12 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)11 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)9 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)9 Resources (com.hubspot.mesos.Resources)7 ArrayList (java.util.ArrayList)7 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)6 List (java.util.List)6 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)5 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)5 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)4 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)4 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)3