use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class JooqTaskRelocationResultStore method getTaskRelocationStatusList.
@Override
public Mono<List<TaskRelocationStatus>> getTaskRelocationStatusList(String taskId) {
return Mono.defer(() -> {
TaskRelocationStatus status = statusesByTaskId.getIfPresent(taskId);
if (status != null) {
return Mono.just(Collections.singletonList(status));
}
CompletionStage<Void> asyncAction = JooqUtils.executeAsync(() -> {
loadToCache(Collections.singleton(taskId), dslContext.configuration());
return null;
}, dslContext);
MonoProcessor<List<TaskRelocationStatus>> callerProcessor = MonoProcessor.create();
asyncAction.handle((result, error) -> {
if (error == null) {
TaskRelocationStatus loadedStatus = statusesByTaskId.getIfPresent(taskId);
callerProcessor.onNext(loadedStatus == null ? Collections.emptyList() : Collections.singletonList(loadedStatus));
} else {
callerProcessor.onError(error);
}
return null;
});
return callerProcessor;
});
}
use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class JooqTaskRelocationResultStoreTest method testRelocationStatusStoreCrud.
@Test
public void testRelocationStatusStoreCrud() {
List<TaskRelocationStatus> statusList = newRelocationStatuses("task", 1, System.currentTimeMillis());
TaskRelocationStatus status = statusList.get(0);
// Create
Map<String, Optional<Throwable>> result = store.createTaskRelocationStatuses(statusList).block();
assertThat(result).hasSize(1);
assertThat(result.get(status.getTaskId())).isEmpty();
// Reboot (to force reload from the database).
this.store = newStore();
// Read
List<TaskRelocationStatus> statusListRead = store.getTaskRelocationStatusList(status.getTaskId()).block();
assertThat(statusListRead).hasSize(1);
assertThat(statusListRead.get(0)).isEqualTo(status);
// Update
TaskRelocationStatus updatedStatus = status.toBuilder().withStatusMessage("Updated...").build();
Map<String, Optional<Throwable>> updatedResult = store.createTaskRelocationStatuses(Collections.singletonList(updatedStatus)).block();
assertThat(updatedResult).hasSize(1);
assertThat(store.getTaskRelocationStatusList(status.getTaskId()).block().get(0)).isEqualTo(updatedStatus);
// Reboot (to force reload from the database).
this.store = newStore();
// Read
assertThat(store.getTaskRelocationStatusList(status.getTaskId()).block().get(0)).isEqualTo(updatedStatus);
}
use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class TaskEvictionResultStoreStepTest method testStoreFailure.
@Test
public void testStoreFailure() {
when(store.createTaskRelocationStatuses(anyList())).thenReturn(Mono.error(new RuntimeException("Simulated store error")));
TaskRelocationStatus relocationStatus = TaskRelocationPlanGenerator.oneSuccessfulRelocation();
step.storeTaskEvictionResults(Collections.singletonMap(relocationStatus.getTaskId(), relocationStatus));
verify(store, times(1)).createTaskRelocationStatuses(anyList());
}
use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class TaskEvictionResultStoreStepTest method testSuccessfulStore.
@Test
public void testSuccessfulStore() {
TaskRelocationStatus relocationStatus = TaskRelocationPlanGenerator.oneSuccessfulRelocation();
when(store.createTaskRelocationStatuses(anyList())).thenReturn(Mono.just(Collections.singletonMap(relocationStatus.getTaskId(), Optional.empty())));
step.storeTaskEvictionResults(Collections.singletonMap(relocationStatus.getTaskId(), relocationStatus));
verify(store, times(1)).createTaskRelocationStatuses(anyList());
}
use of com.netflix.titus.api.relocation.model.TaskRelocationStatus in project titus-control-plane by Netflix.
the class TaskEvictionStepTest method testFailedEviction.
@Test
public void testFailedEviction() {
TaskRelocationPlan taskRelocationPlan = oneMigrationPlan().toBuilder().withTaskId("nonExistingTaskId").build();
Map<String, TaskRelocationStatus> result = step.evict(Collections.singletonMap("nonExistingTaskId", taskRelocationPlan));
assertThat(result).hasSize(1);
TaskRelocationStatus relocationStatus = result.get("nonExistingTaskId");
assertThat(relocationStatus.getTaskId()).isEqualTo("nonExistingTaskId");
assertThat(relocationStatus.getStatusCode()).isEqualTo(TaskRelocationStatus.STATUS_EVICTION_ERROR);
assertThat(relocationStatus.getTaskRelocationPlan()).isEqualTo(taskRelocationPlan);
}
Aggregations