use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class SingularityDeployChecker method deleteObsoletePendingTasks.
private void deleteObsoletePendingTasks(SingularityPendingDeploy pendingDeploy) {
List<SingularityPendingTaskId> obsoletePendingTasks = taskManager.getPendingTaskIds().stream().filter(taskId -> taskId.getRequestId().equals(pendingDeploy.getDeployMarker().getRequestId())).filter(taskId -> !taskId.getDeployId().equals(pendingDeploy.getDeployMarker().getDeployId())).collect(Collectors.toList());
for (SingularityPendingTaskId pendingTaskId : obsoletePendingTasks) {
LOG.debug("Deleting obsolete pending task {}", pendingTaskId.getId());
taskManager.deletePendingTask(pendingTaskId);
}
}
use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class SingularityDisasterDetectionPoller method collectDisasterStats.
private SingularityDisasterDataPoint collectDisasterStats() {
long now = System.currentTimeMillis();
int numActiveTasks = taskManager.getNumActiveTasks();
List<SingularityPendingTaskId> pendingTasks = taskManager.getPendingTaskIds();
int numPendingTasks = pendingTasks.size();
int numLateTasks = 0;
long totalTaskLagMillis = 0;
int numPastDueTasks = 0;
for (SingularityPendingTaskId pendingTask : pendingTasks) {
long taskLagMillis = now - pendingTask.getNextRunAt();
if (taskLagMillis > 0) {
numPastDueTasks++;
totalTaskLagMillis += taskLagMillis;
if (taskLagMillis > configuration.getDeltaAfterWhichTasksAreLateMillis()) {
numLateTasks++;
}
}
}
long avgTaskLagMillis = totalTaskLagMillis / Math.max(numPastDueTasks, 1);
List<SingularitySlave> slaves = slaveManager.getObjects();
int numRunningSlaves = 0;
for (SingularitySlave slave : slaves) {
if (slave.getCurrentState().getState() != MachineState.DEAD && slave.getCurrentState().getState() != MachineState.MISSING_ON_STARTUP) {
numRunningSlaves++;
}
}
int numLostSlaves = activeSlavesLost.getAndSet(0);
int numLostTasks = 0;
for (Reason lostTaskReason : disasterConfiguration.getLostTaskReasons()) {
numLostTasks += taskLostReasons.count(lostTaskReason);
}
taskLostReasons.clear();
return new SingularityDisasterDataPoint(now, numActiveTasks, numPendingTasks, numLateTasks, avgTaskLagMillis, numLostTasks, numRunningSlaves, numLostSlaves);
}
use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class TaskResource method deleteScheduledTask.
public Optional<SingularityPendingTask> deleteScheduledTask(String taskId, SingularityUser user) {
Optional<SingularityPendingTask> maybePendingTask = taskManager.getPendingTask(getPendingTaskIdFromStr(taskId));
if (maybePendingTask.isPresent()) {
SingularityPendingTaskId pendingTaskId = maybePendingTask.get().getPendingTaskId();
Optional<SingularityRequestWithState> maybeRequest = requestManager.getRequest(pendingTaskId.getRequestId());
checkNotFound(maybeRequest.isPresent(), "Couldn't find: " + taskId);
SingularityRequest request = maybeRequest.get().getRequest();
authorizationHelper.checkForAuthorizationByRequestId(request.getId(), user, SingularityAuthorizationScope.WRITE);
checkBadRequest(request.getRequestType() == RequestType.ON_DEMAND, "Only ON_DEMAND tasks may be deleted.");
taskManager.markPendingTaskForDeletion(pendingTaskId);
}
return maybePendingTask;
}
use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class SingularityStartup method getDeployKeyToPendingTaskId.
private Map<SingularityDeployKey, SingularityPendingTaskId> getDeployKeyToPendingTaskId() {
final List<SingularityPendingTaskId> pendingTaskIds = taskManager.getPendingTaskIds();
final Map<SingularityDeployKey, SingularityPendingTaskId> deployKeyToPendingTaskId = Maps.newHashMapWithExpectedSize(pendingTaskIds.size());
for (SingularityPendingTaskId taskId : pendingTaskIds) {
SingularityDeployKey deployKey = new SingularityDeployKey(taskId.getRequestId(), taskId.getDeployId());
deployKeyToPendingTaskId.put(deployKey, taskId);
}
return deployKeyToPendingTaskId;
}
use of com.hubspot.singularity.SingularityPendingTaskId in project Singularity by HubSpot.
the class SingularityStartup method checkSchedulerForInconsistentState.
/**
* We need to run this check for the various situations where the scheduler could get in an inconsistent state due
* to a crash/network failure during series of state transactions.
*
* 1) Unpausing
* 2) Launching Task
*/
@VisibleForTesting
void checkSchedulerForInconsistentState() {
final long now = System.currentTimeMillis();
final Map<SingularityDeployKey, SingularityPendingTaskId> deployKeyToPendingTaskId = getDeployKeyToPendingTaskId();
for (SingularityRequestWithState requestWithState : requestManager.getRequests()) {
switch(requestWithState.getState()) {
case ACTIVE:
case SYSTEM_COOLDOWN:
case DEPLOYING_TO_UNPAUSE:
checkActiveRequest(requestWithState, deployKeyToPendingTaskId, now);
break;
case DELETED:
case PAUSED:
case FINISHED:
break;
}
}
}
Aggregations