use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class TaskEvictionStep method execute.
private Map<String, TaskRelocationStatus> execute(Map<String, TaskRelocationPlan> taskToEvict) {
Map<String, Mono<Void>> actions = taskToEvict.values().stream().collect(Collectors.toMap(TaskRelocationPlan::getTaskId, p -> {
String message;
switch(p.getReason()) {
case AgentEvacuation:
message = String.format("Agent evacuation: %s", p.getReasonMessage());
break;
case SelfManagedMigration:
message = String.format("Self managed migration requested on %s: %s", DateTimeExt.toUtcDateTimeString(p.getDecisionTime()), p.getReasonMessage());
break;
case TaskMigration:
message = p.getReasonMessage();
break;
default:
message = String.format("[unrecognized relocation reason %s]: %s" + p.getReason(), p.getReasonMessage());
}
return evictionServiceClient.terminateTask(p.getTaskId(), message).timeout(EVICTION_TIMEOUT);
}));
Map<String, Optional<Throwable>> evictionResults;
try {
evictionResults = ReactorExt.merge(actions, CONCURRENCY_LIMIT, scheduler).block();
} catch (Exception e) {
logger.warn("Unexpected error when calling the eviction service", e);
return taskToEvict.values().stream().map(p -> TaskRelocationStatus.newBuilder().withState(TaskRelocationState.Failure).withStatusCode(TaskRelocationStatus.STATUS_SYSTEM_ERROR).withStatusMessage("Unexpected error: " + ExceptionExt.toMessageChain(e)).withTimestamp(clock.wallTime()).build()).collect(Collectors.toMap(TaskRelocationStatus::getTaskId, s -> s));
}
Map<String, TaskRelocationStatus> results = new HashMap<>();
taskToEvict.forEach((taskId, plan) -> {
Optional<Throwable> evictionResult = evictionResults.get(plan.getTaskId());
TaskRelocationStatus status;
if (evictionResult != null) {
if (!evictionResult.isPresent()) {
status = TaskRelocationStatus.newBuilder().withTaskId(taskId).withState(TaskRelocationState.Success).withStatusCode(TaskRelocationStatus.STATUS_CODE_TERMINATED).withStatusMessage("Task terminated successfully").withTaskRelocationPlan(plan).withTimestamp(clock.wallTime()).build();
} else {
status = TaskRelocationStatus.newBuilder().withTaskId(taskId).withState(TaskRelocationState.Failure).withStatusCode(TaskRelocationStatus.STATUS_EVICTION_ERROR).withStatusMessage(evictionResult.get().getMessage()).withTaskRelocationPlan(plan).withTimestamp(clock.wallTime()).build();
}
} else {
// This should never happen
invariants.inconsistent("Eviction result missing: taskId=%s", plan.getTaskId());
status = TaskRelocationStatus.newBuilder().withTaskId(taskId).withState(TaskRelocationState.Failure).withStatusCode(TaskRelocationStatus.STATUS_SYSTEM_ERROR).withStatusMessage("Eviction result missing").withTaskRelocationPlan(plan).withTimestamp(clock.wallTime()).build();
}
results.put(taskId, status);
transactionLog.logTaskRelocationStatus(STEP_NAME, "eviction", status);
});
return results;
}
use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class TaskEvictionStep method evict.
public Map<String, TaskRelocationStatus> evict(Map<String, TaskRelocationPlan> taskToEvict) {
Stopwatch stopwatch = Stopwatch.createStarted();
try {
Map<String, TaskRelocationStatus> result = execute(taskToEvict);
metrics.onSuccess(result.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
logger.debug("Eviction result: {}", result);
return result;
} catch (Exception e) {
logger.error("Step processing error", e);
metrics.onError(stopwatch.elapsed(TimeUnit.MILLISECONDS));
throw e;
}
}
use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class ReactorTaskRelocationGrpcService method getLatestTaskRelocationResults.
/**
* TODO Implement filtering.
*/
public Mono<TaskRelocationExecutions> getLatestTaskRelocationResults(TaskRelocationQuery request) {
List<TaskRelocationStatus> coreResults = new ArrayList<>(relocationWorkflowExecutor.getLastEvictionResults().values());
TaskRelocationExecutions grpcResults = toGrpcTaskRelocationExecutions(coreResults);
return Mono.just(grpcResults);
}
use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class ReactorTaskRelocationGrpcService method getTaskRelocationResult.
public Mono<TaskRelocationExecution> getTaskRelocationResult(RelocationTaskId request) {
String taskId = request.getId();
TaskRelocationStatus latest = relocationWorkflowExecutor.getLastEvictionResults().get(taskId);
return archiveStore.getTaskRelocationStatusList(taskId).flatMap(archived -> {
if (latest == null && archived.isEmpty()) {
return Mono.error(new StatusRuntimeException(Status.NOT_FOUND));
}
List<TaskRelocationStatus> combined;
if (latest == null) {
combined = archived;
} else if (archived.isEmpty()) {
combined = Collections.singletonList(latest);
} else {
if (CollectionsExt.last(archived).equals(latest)) {
combined = archived;
} else {
combined = CollectionsExt.copyAndAdd(archived, latest);
}
}
return Mono.just(RelocationGrpcModelConverters.toGrpcTaskRelocationExecution(combined));
});
}
use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class TaskRelocationSpringResource method getTaskRelocationResult.
@RequestMapping(method = RequestMethod.GET, path = "/executions/{taskId}", produces = "application/json")
public TaskRelocationExecution getTaskRelocationResult(@PathVariable("taskId") String taskId) {
TaskRelocationStatus latest = relocationWorkflowExecutor.getLastEvictionResults().get(taskId);
List<TaskRelocationStatus> archived = archiveStore.getTaskRelocationStatusList(taskId).block();
if (latest == null && archived.isEmpty()) {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
}
List<TaskRelocationStatus> combined;
if (latest == null) {
combined = archived;
} else if (archived.isEmpty()) {
combined = Collections.singletonList(latest);
} else {
if (CollectionsExt.last(archived).equals(latest)) {
combined = archived;
} else {
combined = CollectionsExt.copyAndAdd(archived, latest);
}
}
return RelocationGrpcModelConverters.toGrpcTaskRelocationExecution(combined);
}
Aggregations