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