Search in sources :

Example 1 with SingularityTaskId

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

the class SingularityWebCache method cacheActiveTasks.

public void cacheActiveTasks(List<SingularityTask> activeTasks) {
    activeMissMeter.mark();
    Map<SingularityTaskId, SingularityTask> newActiveTasks = new HashMap<>(activeTasks.size());
    for (SingularityTask activeTask : activeTasks) {
        newActiveTasks.put(activeTask.getTaskId(), activeTask);
    }
    cachedActiveTasks = newActiveTasks;
    lastActiveTaskCache = System.currentTimeMillis();
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) HashMap(java.util.HashMap) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 2 with SingularityTaskId

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

the class StateManager method getNumTasks.

private Map<String, Long> getNumTasks(List<SingularityRequestWithState> requests) {
    final CounterMap<String> numTasks = new CounterMap<>(requests.size());
    for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
        numTasks.incr(taskId.getRequestId());
    }
    for (SingularityPendingTaskId pendingTaskId : taskManager.getPendingTaskIds()) {
        numTasks.incr(pendingTaskId.getRequestId());
    }
    for (SingularityTaskId cleaningTaskId : taskManager.getCleanupTaskIds()) {
        Optional<SingularityRequestWithState> request = requestManager.getRequest(cleaningTaskId.getRequestId());
        if (request.isPresent() && request.get().getRequest().isScheduled()) {
            continue;
        }
        numTasks.decr(cleaningTaskId.getRequestId());
    }
    return numTasks.toCountMap();
}
Also used : CounterMap(com.hubspot.mesos.CounterMap) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 3 with SingularityTaskId

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

the class TaskManager method getLastHealthcheck.

public Map<SingularityTaskId, SingularityTaskHealthcheckResult> getLastHealthcheck(Collection<SingularityTaskId> taskIds) {
    List<String> paths = Lists.newArrayListWithCapacity(taskIds.size());
    for (SingularityTaskId taskId : taskIds) {
        paths.add(getLastHealthcheckPath(taskId));
    }
    List<SingularityTaskHealthcheckResult> healthcheckResults = getAsync("getLastHealthcheck", paths, healthcheckResultTranscoder);
    return Maps.uniqueIndex(healthcheckResults, SingularityTaskIdHolder.getTaskIdFunction());
}
Also used : SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 4 with SingularityTaskId

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

the class TaskManager method getTasksOnSlave.

public List<SingularityTask> getTasksOnSlave(Collection<SingularityTaskId> activeTaskIds, SingularitySlave slave) {
    final List<SingularityTask> tasks = Lists.newArrayList();
    final String sanitizedHost = JavaUtils.getReplaceHyphensWithUnderscores(slave.getHost());
    for (SingularityTaskId activeTaskId : activeTaskIds) {
        if (activeTaskId.getSanitizedHost().equals(sanitizedHost)) {
            Optional<SingularityTask> maybeTask = getTask(activeTaskId);
            if (maybeTask.isPresent() && slave.getId().equals(maybeTask.get().getAgentId().getValue())) {
                tasks.add(maybeTask.get());
            }
        }
    }
    return tasks;
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 5 with SingularityTaskId

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

the class SingularityMesosOfferScheduler method getMaxProbableUsageForSlave.

private MaxProbableUsage getMaxProbableUsageForSlave(List<SingularityTaskId> activeTaskIds, Map<String, RequestUtilization> requestUtilizations, String sanitizedHostname) {
    double cpu = 0;
    double memBytes = 0;
    double diskBytes = 0;
    for (SingularityTaskId taskId : activeTaskIds) {
        if (taskId.getSanitizedHost().equals(sanitizedHostname)) {
            if (requestUtilizations.containsKey(taskId.getRequestId())) {
                RequestUtilization utilization = requestUtilizations.get(taskId.getRequestId());
                // To account for cpu bursts, tend towards max usage if the app is consistently over-utilizing cpu, tend towards avg if it is over-utilized in short bursts
                cpu += (utilization.getMaxCpuUsed() - utilization.getAvgCpuUsed()) * utilization.getCpuBurstRating() + utilization.getAvgCpuUsed();
                memBytes += utilization.getMaxMemBytesUsed();
                diskBytes += utilization.getMaxDiskBytesUsed();
            } else {
                Optional<SingularityTask> maybeTask = taskManager.getTask(taskId);
                if (maybeTask.isPresent()) {
                    Resources resources = maybeTask.get().getTaskRequest().getPendingTask().getResources().or(maybeTask.get().getTaskRequest().getDeploy().getResources()).or(defaultResources);
                    cpu += resources.getCpus();
                    memBytes += resources.getDiskMb() * SingularitySlaveUsage.BYTES_PER_MEGABYTE;
                    diskBytes += resources.getDiskMb() * SingularitySlaveUsage.BYTES_PER_MEGABYTE;
                }
            }
        }
    }
    return new MaxProbableUsage(cpu, memBytes, diskBytes);
}
Also used : MaxProbableUsage(com.hubspot.singularity.mesos.SingularitySlaveUsageWithCalculatedScores.MaxProbableUsage) SingularityTask(com.hubspot.singularity.SingularityTask) RequestUtilization(com.hubspot.singularity.RequestUtilization) Resources(com.hubspot.mesos.Resources) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Aggregations

SingularityTaskId (com.hubspot.singularity.SingularityTaskId)106 Test (org.junit.Test)44 SingularityTask (com.hubspot.singularity.SingularityTask)34 SingularityRequest (com.hubspot.singularity.SingularityRequest)26 ArrayList (java.util.ArrayList)26 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)14 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)13 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)12 List (java.util.List)11 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)10 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)9 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)9 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)9 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)8 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)7 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)7 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)7 HashMap (java.util.HashMap)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)6 SingularitySlaveUsage (com.hubspot.singularity.SingularitySlaveUsage)6