use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method runLaunchedTasks.
protected void runLaunchedTasks() {
for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
Collection<SingularityTaskHistoryUpdate> updates = taskManager.getTaskHistoryUpdates(taskId);
SimplifiedTaskState currentState = SingularityTaskHistoryUpdate.getCurrentState(updates);
switch(currentState) {
case UNKNOWN:
case WAITING:
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
break;
case DONE:
case RUNNING:
break;
}
}
}
use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.
the class SingularityDeployHealthHelper method getNoHealthcheckDeployHealth.
private DeployHealth getNoHealthcheckDeployHealth(final Optional<SingularityDeploy> deploy, final Collection<SingularityTaskId> matchingActiveTasks) {
final Map<SingularityTaskId, List<SingularityTaskHistoryUpdate>> taskUpdates = taskManager.getTaskHistoryUpdates(matchingActiveTasks);
for (SingularityTaskId taskId : matchingActiveTasks) {
Collection<SingularityTaskHistoryUpdate> updates = taskUpdates.get(taskId);
SimplifiedTaskState currentState = SingularityTaskHistoryUpdate.getCurrentState(updates);
switch(currentState) {
case UNKNOWN:
case WAITING:
return DeployHealth.WAITING;
case DONE:
LOG.warn("Unexpectedly found an active task ({}) in done state: {}}", taskId, updates);
return DeployHealth.UNHEALTHY;
case RUNNING:
if (!isRunningTaskHealthy(deploy, updates, taskId)) {
return DeployHealth.WAITING;
}
}
}
return DeployHealth.HEALTHY;
}
use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.
the class S3LogResource method getS3PrefixesForTask.
// Generation of prefixes
private Collection<String> getS3PrefixesForTask(S3Configuration s3Configuration, SingularityTaskId taskId, Optional<Long> startArg, Optional<Long> endArg, String group, SingularityUser user) {
Optional<SingularityTaskHistory> history = getTaskHistory(taskId, user);
long start = taskId.getStartedAt();
if (startArg.isPresent()) {
start = Math.max(startArg.get(), start);
}
long end = start + s3Configuration.getMissingTaskDefaultS3SearchPeriodMillis();
if (history.isPresent()) {
SimplifiedTaskState taskState = SingularityTaskHistoryUpdate.getCurrentState(history.get().getTaskUpdates());
if (taskState == SimplifiedTaskState.DONE) {
end = Iterables.getLast(history.get().getTaskUpdates()).getTimestamp();
} else {
end = System.currentTimeMillis();
}
}
if (endArg.isPresent()) {
end = Math.min(endArg.get(), end);
}
Optional<String> tag = Optional.absent();
if (history.isPresent() && history.get().getTask().getTaskRequest().getDeploy().getExecutorData().isPresent()) {
tag = history.get().getTask().getTaskRequest().getDeploy().getExecutorData().get().getLoggingTag();
}
Collection<String> prefixes = SingularityS3FormatHelper.getS3KeyPrefixes(s3Configuration.getS3KeyFormat(), taskId, tag, start, end, group);
for (SingularityS3UploaderFile additionalFile : s3Configuration.getS3UploaderAdditionalFiles()) {
if (additionalFile.getS3UploaderKeyPattern().isPresent() && !additionalFile.getS3UploaderKeyPattern().get().equals(s3Configuration.getS3KeyFormat())) {
prefixes.addAll(SingularityS3FormatHelper.getS3KeyPrefixes(additionalFile.getS3UploaderKeyPattern().get(), taskId, tag, start, end, group));
}
}
LOG.trace("Task {} got S3 prefixes {} for start {}, end {}, tag {}", taskId, prefixes, start, end, tag);
return prefixes;
}
use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.
the class SingularityNewTaskChecker method getTaskState.
@VisibleForTesting
CheckTaskState getTaskState(SingularityTask task, Optional<SingularityRequestWithState> requestWithState, SingularityHealthchecker healthchecker) {
if (!taskManager.isActiveTask(task.getTaskId().getId())) {
return CheckTaskState.OBSOLETE;
}
SimplifiedTaskState taskState = SingularityTaskHistoryUpdate.getCurrentState(taskManager.getTaskHistoryUpdates(task.getTaskId()));
switch(taskState) {
case DONE:
return CheckTaskState.OBSOLETE;
case WAITING:
case UNKNOWN:
return CheckTaskState.CHECK_IF_TASK_OVERDUE;
case RUNNING:
break;
}
if (hasHealthcheck(task, requestWithState)) {
Optional<SingularityTaskHealthcheckResult> maybeHealthCheck = taskManager.getLastHealthcheck(task.getTaskId());
DeployHealth health = deployHealthHelper.getTaskHealth(task.getTaskRequest().getDeploy(), false, maybeHealthCheck, task.getTaskId());
switch(health) {
case WAITING:
healthchecker.checkHealthcheck(task);
return CheckTaskState.CHECK_IF_HEALTHCHECK_OVERDUE;
case UNHEALTHY:
taskManager.clearStartupHealthchecks(task.getTaskId());
return CheckTaskState.UNHEALTHY_KILL_TASK;
case HEALTHY:
taskManager.clearStartupHealthchecks(task.getTaskId());
break;
}
}
// task is running + has succeeded healthcheck if available.
if (!task.getTaskRequest().getRequest().isLoadBalanced()) {
return CheckTaskState.HEALTHY;
}
Optional<SingularityLoadBalancerUpdate> lbUpdate = taskManager.getLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.ADD);
SingularityLoadBalancerUpdate newLbUpdate;
final LoadBalancerRequestId loadBalancerRequestId = new LoadBalancerRequestId(task.getTaskId().getId(), LoadBalancerRequestType.ADD, Optional.absent());
boolean taskCleaning = taskManager.getCleanupTaskIds().contains(task.getTaskId());
if ((!lbUpdate.isPresent() || unknownNotRemoving(lbUpdate.get())) && !taskCleaning) {
taskManager.saveLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.ADD, new SingularityLoadBalancerUpdate(BaragonRequestState.UNKNOWN, loadBalancerRequestId, Optional.absent(), System.currentTimeMillis(), LoadBalancerMethod.PRE_ENQUEUE, Optional.absent()));
newLbUpdate = lbClient.enqueue(loadBalancerRequestId, task.getTaskRequest().getRequest(), task.getTaskRequest().getDeploy(), Collections.singletonList(task), Collections.emptyList());
} else {
Optional<CheckTaskState> maybeCheckTaskState = checkLbState(lbUpdate.get().getLoadBalancerState());
if (maybeCheckTaskState.isPresent()) {
return maybeCheckTaskState.get();
}
newLbUpdate = lbClient.getState(loadBalancerRequestId);
}
taskManager.saveLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.ADD, newLbUpdate);
Optional<CheckTaskState> maybeCheckTaskState = checkLbState(newLbUpdate.getLoadBalancerState());
if (maybeCheckTaskState.isPresent()) {
return maybeCheckTaskState.get();
}
return CheckTaskState.LB_IN_PROGRESS_CHECK_AGAIN;
}
use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.
the class SingularityDeployHealthHelper method getNoHealthcheckHealthyTasks.
private List<SingularityTaskId> getNoHealthcheckHealthyTasks(final Optional<SingularityDeploy> deploy, final Collection<SingularityTaskId> matchingActiveTasks) {
final Map<SingularityTaskId, List<SingularityTaskHistoryUpdate>> taskUpdates = taskManager.getTaskHistoryUpdates(matchingActiveTasks);
final List<SingularityTaskId> healthyTaskIds = Lists.newArrayListWithCapacity(matchingActiveTasks.size());
for (SingularityTaskId taskId : matchingActiveTasks) {
Collection<SingularityTaskHistoryUpdate> updates = taskUpdates.get(taskId);
SimplifiedTaskState currentState = SingularityTaskHistoryUpdate.getCurrentState(updates);
if (currentState == SimplifiedTaskState.RUNNING && isRunningTaskHealthy(deploy, updates, taskId)) {
healthyTaskIds.add(taskId);
}
}
return healthyTaskIds;
}
Aggregations