Search in sources :

Example 1 with TaskRelocationStatus

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;
    });
}
Also used : List(java.util.List) TaskRelocationStatus(com.netflix.titus.api.relocation.model.TaskRelocationStatus)

Example 2 with TaskRelocationStatus

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);
}
Also used : Optional(java.util.Optional) TaskRelocationStatus(com.netflix.titus.api.relocation.model.TaskRelocationStatus) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with TaskRelocationStatus

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());
}
Also used : TaskRelocationStatus(com.netflix.titus.api.relocation.model.TaskRelocationStatus) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Example 4 with TaskRelocationStatus

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());
}
Also used : TaskRelocationStatus(com.netflix.titus.api.relocation.model.TaskRelocationStatus) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Example 5 with TaskRelocationStatus

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);
}
Also used : TaskRelocationStatus(com.netflix.titus.api.relocation.model.TaskRelocationStatus) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Aggregations

TaskRelocationStatus (com.netflix.titus.api.relocation.model.TaskRelocationStatus)12 Test (org.junit.Test)5 AbstractTaskRelocationTest (com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest)4 TaskRelocationPlan (com.netflix.titus.api.relocation.model.TaskRelocationPlan)3 Stopwatch (com.google.common.base.Stopwatch)2 Optional (java.util.Optional)2 Task (com.netflix.titus.api.jobmanager.model.job.Task)1 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)1 TaskRelocationState (com.netflix.titus.api.relocation.model.TaskRelocationStatus.TaskRelocationState)1 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)1 DateTimeExt (com.netflix.titus.common.util.DateTimeExt)1 ExceptionExt (com.netflix.titus.common.util.ExceptionExt)1 CodeInvariants (com.netflix.titus.common.util.code.CodeInvariants)1 ReactorExt (com.netflix.titus.common.util.rx.ReactorExt)1 Clock (com.netflix.titus.common.util.time.Clock)1 TaskRelocationExecutions (com.netflix.titus.grpc.protogen.TaskRelocationExecutions)1 EvictionServiceClient (com.netflix.titus.runtime.connector.eviction.EvictionServiceClient)1 RelocationGrpcModelConverters.toGrpcTaskRelocationExecutions (com.netflix.titus.runtime.relocation.endpoint.RelocationGrpcModelConverters.toGrpcTaskRelocationExecutions)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 Duration (java.time.Duration)1