Search in sources :

Example 61 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class TaskScenarioBuilder method transitionTo.

public TaskScenarioBuilder transitionTo(TaskStatus.TaskState... taskStates) {
    logger.info("[{}] Transition task on agent through states {}", discoverActiveTest(), asList(taskStates));
    Task task = getTask();
    for (TaskStatus.TaskState taskState : taskStates) {
        if (taskState == TaskStatus.TaskState.StartInitiated) {
            kubeCluster.moveToStartInitiatedState(task.getId());
        } else if (taskState == TaskStatus.TaskState.Started) {
            kubeCluster.moveToStartedState(task.getId());
        } else if (taskState == TaskStatus.TaskState.KillInitiated) {
            kubeCluster.moveToKillInitiatedState(task.getId(), 0);
        } else if (taskState == TaskStatus.TaskState.Finished) {
            kubeCluster.moveToFinishedSuccess(task.getId());
        }
    }
    return this;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) TaskStatus(com.netflix.titus.grpc.protogen.TaskStatus)

Example 62 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class TaskScenarioBuilder method expectInstanceType.

public TaskScenarioBuilder expectInstanceType(AwsInstanceType expectedInstanceType) {
    logger.info("[{}] Expecting current task to run on instance type {}", discoverActiveTest(), expectedInstanceType);
    Task task = getTask();
    V1Pod pod = kubeCluster.getPods().get(task.getId());
    String nodeId = pod.getSpec().getNodeName();
    EmbeddedKubeNode node = kubeCluster.getFleet().getNodes().get(nodeId);
    String instanceType = node.getServerGroup().getInstanceType();
    Preconditions.checkArgument(expectedInstanceType.name().equalsIgnoreCase(instanceType), "Task is expected to run on AWS instance %s, but is running on %s", expectedInstanceType, instanceType);
    return this;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) V1Pod(io.kubernetes.client.openapi.models.V1Pod) EmbeddedKubeNode(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeNode)

Example 63 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class DefaultLoadBalancerReconcilerTest method deregisterExtraTargetsPreviouslyRegisteredByUs.

@Test(timeout = TEST_TIMEOUT_MS)
public void deregisterExtraTargetsPreviouslyRegisteredByUs() {
    List<Task> tasks = LoadBalancerTests.buildTasksStarted(3, jobId);
    JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
    JobLoadBalancerState association = new JobLoadBalancerState(jobLoadBalancer, State.ASSOCIATED);
    when(v3JobOperations.getTasks(jobId)).thenReturn(tasks);
    reset(connector);
    when(connector.getLoadBalancer(loadBalancerId)).thenReturn(Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, CollectionsExt.asSet("1.1.1.1", "2.2.2.2", "3.3.3.3", "4.4.4.4", "5.5.5.5", "6.6.6.6"))));
    store.addOrUpdateLoadBalancer(association.getJobLoadBalancer(), association.getState()).await();
    store.addOrUpdateTargets(// 3 running tasks were previously registered by us and are in the load balancer
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(1).getId(), "2.2.2.2"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(2).getId(), "3.3.3.3"), LoadBalancerTarget.State.REGISTERED), // Next two ips were previously registered by us, but their tasks do not exist anymore
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "some-dead-task", "4.4.4.4"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "another-dead-task", "5.5.5.5"), LoadBalancerTarget.State.DEREGISTERED)).block();
    testScheduler.triggerActions();
    subscriber.assertNotCompleted().assertNoValues();
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(2);
    subscriber.getOnNextEvents().forEach(update -> {
        assertThat(update.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
        assertThat(update.getPriority()).isEqualTo(Priority.LOW);
        assertThat(update.getLoadBalancerId()).isEqualTo(loadBalancerId);
        assertThat(update.getIdentifier().getTaskId()).isIn("some-dead-task", "another-dead-task");
        assertThat(update.getIdentifier().getIpAddress()).isIn("4.4.4.4", "5.5.5.5");
    });
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Test(org.junit.Test)

Example 64 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class DefaultLoadBalancerReconcilerTest method registerMissingTargets.

@Test(timeout = TEST_TIMEOUT_MS)
public void registerMissingTargets() {
    List<Task> tasks = LoadBalancerTests.buildTasksStarted(5, jobId);
    JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
    JobLoadBalancerState association = new JobLoadBalancerState(jobLoadBalancer, State.ASSOCIATED);
    when(v3JobOperations.getTasks(jobId)).thenReturn(tasks);
    store.addOrUpdateLoadBalancer(association.getJobLoadBalancer(), association.getState()).await();
    testScheduler.triggerActions();
    subscriber.assertNotCompleted().assertNoValues();
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(5);
    subscriber.getOnNextEvents().forEach(update -> {
        assertThat(update.getState()).isEqualTo(LoadBalancerTarget.State.REGISTERED);
        // reconciliation always generates Priority.Low events that can be replaced by higher priority reactive updates
        assertThat(update.getPriority()).isEqualTo(Priority.LOW);
        assertThat(update.getLoadBalancerId()).isEqualTo(loadBalancerId);
    });
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Test(org.junit.Test)

Example 65 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class DefaultLoadBalancerReconcilerTest method deregisteredTargetsAreCleanedUp.

@Test(timeout = TEST_TIMEOUT_MS)
public void deregisteredTargetsAreCleanedUp() {
    List<Task> tasks = LoadBalancerTests.buildTasksStarted(1, jobId);
    JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
    JobLoadBalancerState association = new JobLoadBalancerState(jobLoadBalancer, State.ASSOCIATED);
    when(v3JobOperations.getTasks(jobId)).thenReturn(tasks);
    reset(connector);
    when(connector.getLoadBalancer(loadBalancerId)).thenReturn(Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, CollectionsExt.asSet("1.1.1.1", "10.10.10.10"))));
    store.addOrUpdateLoadBalancer(association.getJobLoadBalancer(), association.getState()).await();
    store.addOrUpdateTargets(// running tasks was previously registered by us and are in the load balancer
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED), // Next three ips were previously registered by us, but their tasks do not exist anymore and are not in the load balancer anymore
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-inconsistent", "2.2.2.2"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-not-in-lb", "3.3.3.3"), LoadBalancerTarget.State.DEREGISTERED)).block();
    // no reconciliation ran yet
    testScheduler.triggerActions();
    subscriber.assertNotCompleted().assertNoValues();
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).hasSize(3);
    // first pass, the one stored as DEREGISTERED is cleaned up, the other in an inconsistent state is fixed
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(1);
    TargetStateBatchable inconsistencyFix = subscriber.getOnNextEvents().get(0);
    assertThat(inconsistencyFix.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
    assertThat(inconsistencyFix.getLoadBalancerId()).isEqualTo(loadBalancerId);
    assertThat(inconsistencyFix.getIpAddress()).isEqualTo("2.2.2.2");
    List<LoadBalancerTargetState> storedTargets = store.getLoadBalancerTargets(loadBalancerId).collectList().block();
    assertThat(storedTargets).hasSize(2);
    assertThat(storedTargets).doesNotContain(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-not-in-lb", "3.3.3.3"), LoadBalancerTarget.State.DEREGISTERED));
    // update with fix not applied yet, keep trying
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(2);
    TargetStateBatchable update2 = subscriber.getOnNextEvents().get(0);
    assertThat(update2.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
    assertThat(update2.getLoadBalancerId()).isEqualTo(loadBalancerId);
    assertThat(update2.getIpAddress()).isEqualTo("2.2.2.2");
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).hasSize(2);
    // simulate the update with the fix above being applied
    store.addOrUpdateTargets(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-inconsistent", "2.2.2.2"), LoadBalancerTarget.State.DEREGISTERED)).block();
    // finally, corrected record is now cleaned up
    awaitReconciliationRuns(1);
    // no changes needed
    subscriber.assertNotCompleted().assertValueCount(2);
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).containsOnly(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED));
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Test(org.junit.Test)

Aggregations

Task (com.netflix.titus.api.jobmanager.model.job.Task)222 Test (org.junit.Test)98 ArrayList (java.util.ArrayList)63 List (java.util.List)62 Job (com.netflix.titus.api.jobmanager.model.job.Job)58 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)45 TaskStatus (com.netflix.titus.api.jobmanager.model.job.TaskStatus)45 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)42 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)38 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)34 Pair (com.netflix.titus.common.util.tuple.Pair)32 V1Pod (io.kubernetes.client.openapi.models.V1Pod)32 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)31 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)29 Optional (java.util.Optional)27 Collections (java.util.Collections)26 Collectors (java.util.stream.Collectors)25 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)24 HashMap (java.util.HashMap)24 TaskUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)23