use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class DefaultLoadBalancerServiceTest method movedTaskOnlySourceAssociatedWithLoadBalancer.
@Test
public void movedTaskOnlySourceAssociatedWithLoadBalancer() {
String taskId = UUID.randomUUID().toString();
String sourceJobId = UUID.randomUUID().toString();
String targetJobId = UUID.randomUUID().toString();
String sourceLoadBalancerId = "lb-" + UUID.randomUUID().toString();
PublishSubject<JobManagerEvent<?>> taskEvents = PublishSubject.create();
when(client.registerAll(any(), any())).thenReturn(Completable.complete());
when(client.deregisterAll(any(), any())).thenReturn(Completable.complete());
when(v3JobOperations.observeJobs()).thenReturn(taskEvents);
LoadBalancerTests.applyValidGetJobMock(v3JobOperations, sourceJobId);
LoadBalancerTests.applyValidGetJobMock(v3JobOperations, targetJobId);
LoadBalancerConfiguration configuration = LoadBalancerTests.mockConfiguration(MIN_TIME_IN_QUEUE_MS);
DefaultLoadBalancerService service = new DefaultLoadBalancerService(runtime, configuration, client, loadBalancerStore, loadBalancerJobOperations, reconciler, validator, testScheduler);
AssertableSubscriber<Batch<TargetStateBatchable, String>> testSubscriber = service.events().test();
assertTrue(service.addLoadBalancer(sourceJobId, sourceLoadBalancerId).await(100, TimeUnit.MILLISECONDS));
assertThat(service.getJobLoadBalancers(sourceJobId).toBlocking().toIterable()).containsExactlyInAnyOrder(sourceLoadBalancerId);
assertThat(service.getJobLoadBalancers(targetJobId).toBlocking().toIterable()).isEmpty();
testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors().assertValueCount(0);
verify(client, never()).registerAll(any(), any());
verify(client, never()).deregisterAll(any(), any());
verifyNoReconcilerIgnore();
Task moved = ServiceJobTask.newBuilder().withJobId(targetJobId).withId(taskId).withStatus(TaskStatus.newBuilder().withState(TaskState.Started).build()).withTaskContext(CollectionsExt.asMap(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP, "1.2.3.4", TaskAttributes.TASK_ATTRIBUTES_MOVED_FROM_JOB, sourceJobId)).build();
// detect the task is moved and gets deregistered from the source
taskEvents.onNext(TaskUpdateEvent.newTaskFromAnotherJob(null, moved, callMetadata));
testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors().assertValueCount(1);
verify(client).deregisterAll(eq(sourceLoadBalancerId), argThat(set -> set.contains("1.2.3.4")));
verify(client, never()).registerAll(any(), any());
verifyReconcilerIgnore(sourceLoadBalancerId, "1.2.3.4");
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class DefaultLoadBalancerServiceTest method movedTasks.
@Test
public void movedTasks() {
String taskId = UUID.randomUUID().toString();
String sourceJobId = UUID.randomUUID().toString();
String targetJobId = UUID.randomUUID().toString();
String sourceLoadBalancerId = "lb-" + UUID.randomUUID().toString();
String targetLoadBalancerId = "lb-" + UUID.randomUUID().toString();
String commonLoadBalancerId = "lb-" + UUID.randomUUID().toString();
PublishSubject<JobManagerEvent<?>> taskEvents = PublishSubject.create();
when(client.registerAll(any(), any())).thenReturn(Completable.complete());
when(client.deregisterAll(any(), any())).thenReturn(Completable.complete());
when(v3JobOperations.observeJobs()).thenReturn(taskEvents);
LoadBalancerTests.applyValidGetJobMock(v3JobOperations, sourceJobId);
LoadBalancerTests.applyValidGetJobMock(v3JobOperations, targetJobId);
LoadBalancerConfiguration configuration = LoadBalancerTests.mockConfiguration(MIN_TIME_IN_QUEUE_MS);
DefaultLoadBalancerService service = new DefaultLoadBalancerService(runtime, configuration, client, loadBalancerStore, loadBalancerJobOperations, reconciler, validator, testScheduler);
AssertableSubscriber<Batch<TargetStateBatchable, String>> testSubscriber = service.events().test();
assertTrue(service.addLoadBalancer(sourceJobId, sourceLoadBalancerId).await(100, TimeUnit.MILLISECONDS));
assertTrue(service.addLoadBalancer(sourceJobId, commonLoadBalancerId).await(100, TimeUnit.MILLISECONDS));
assertThat(service.getJobLoadBalancers(sourceJobId).toBlocking().toIterable()).containsExactlyInAnyOrder(sourceLoadBalancerId, commonLoadBalancerId);
assertTrue(service.addLoadBalancer(targetJobId, targetLoadBalancerId).await(100, TimeUnit.MILLISECONDS));
assertTrue(service.addLoadBalancer(targetJobId, commonLoadBalancerId).await(100, TimeUnit.MILLISECONDS));
assertThat(service.getJobLoadBalancers(targetJobId).toBlocking().toIterable()).containsExactlyInAnyOrder(targetLoadBalancerId, commonLoadBalancerId);
testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors().assertValueCount(0);
verify(client, never()).registerAll(any(), any());
verify(client, never()).deregisterAll(any(), any());
verifyNoReconcilerIgnore();
Task moved = ServiceJobTask.newBuilder().withJobId(targetJobId).withId(taskId).withStatus(TaskStatus.newBuilder().withState(TaskState.Started).build()).withTaskContext(CollectionsExt.asMap(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP, "1.2.3.4", TaskAttributes.TASK_ATTRIBUTES_MOVED_FROM_JOB, sourceJobId)).build();
// detect the task is moved, gets deregistered from the source and registered on the target
taskEvents.onNext(TaskUpdateEvent.newTaskFromAnotherJob(null, moved, callMetadata));
testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors().assertValueCount(2);
verify(client).registerAll(eq(targetLoadBalancerId), argThat(set -> set.contains("1.2.3.4")));
verify(client).deregisterAll(eq(sourceLoadBalancerId), argThat(set -> set.contains("1.2.3.4")));
verifyReconcilerIgnore(targetLoadBalancerId, "1.2.3.4");
verifyReconcilerIgnore(sourceLoadBalancerId, "1.2.3.4");
// load balancers associated with both source and target jobs are not changed
verify(client, never()).registerAll(eq(commonLoadBalancerId), any());
verify(client, never()).deregisterAll(eq(commonLoadBalancerId), any());
verifyNoReconcilerIgnore(commonLoadBalancerId);
verifyNoReconcilerIgnore(commonLoadBalancerId);
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class ObserveJobsSubscriptionTest method testObserveJobsWithKeepAliveSnapshot.
@Test
public void testObserveJobsWithKeepAliveSnapshot() {
Job<?> job1 = jobComponentStub.createJob(SERVICE_JOB_WITH_ONE_TASK);
Task task1 = jobComponentStub.createDesiredTasks(job1).get(0);
StreamObserver<ObserveJobsWithKeepAliveRequest> request = jobsSubscription.observeJobsWithKeepAlive(responseStreamObserver);
// Check that nothing is emitted until we send the query request
request.onNext(newKeepAliveRequest(1));
triggerActions(5);
assertThat(responseEvents.poll()).isNull();
// Now send the request and read the snapshot
request.onNext(QUERY_REQUEST);
request.onNext(newKeepAliveRequest(2));
assertThat(expectJobUpdateEvent().getJob().getId()).isEqualTo(job1.getId());
assertThat(expectTaskUpdateEvent().getTask().getId()).isEqualTo(task1.getId());
expectSnapshotEvent();
triggerActions(1);
jobComponentStub.emitCheckpoint();
triggerActions(1);
expectKeepAlive(2);
triggerActions(1);
// Now changes
Job<?> job2 = jobComponentStub.createJob(SERVICE_JOB_WITH_ONE_TASK);
triggerActions(1);
assertThat(expectJobUpdateEvent().getJob().getId()).isEqualTo(job2.getId());
// Now keep alive
request.onNext(newKeepAliveRequest(3));
jobComponentStub.emitCheckpoint();
triggerActions(1);
expectKeepAlive(3);
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class KubeNotificationProcessorTest method testUpdateTaskStatusVK.
@Test
public void testUpdateTaskStatusVK() {
V1Pod pod = newPod(TASK.getId(), andRunning());
V1Node node = newNode(andIpAddress("2.2.2.2"), andNodeAnnotations(TITUS_NODE_DOMAIN + "ami", "ami123", TITUS_NODE_DOMAIN + "stack", "myStack"));
Map<String, String> UpdatedAnnotations = new HashMap<>();
UpdatedAnnotations.put(LEGACY_ANNOTATION_IP_ADDRESS, "1.2.3.4");
pod.getMetadata().setAnnotations(UpdatedAnnotations);
Task updatedTask = processor.updateTaskStatus(new PodWrapper(pod), TaskStatus.newBuilder().withState(TaskState.Started).build(), Optional.of(node), TASK, false).orElse(null);
Set<TaskState> pastStates = updatedTask.getStatusHistory().stream().map(ExecutableStatus::getState).collect(Collectors.toSet());
assertThat(pastStates).contains(TaskState.Accepted, TaskState.Launched, TaskState.StartInitiated);
assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_AGENT_HOST, "2.2.2.2");
assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP, "1.2.3.4");
assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_AGENT_AMI, "ami123");
assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_AGENT_STACK, "myStack");
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class JobScenarioBuilder method expectTaskAddedToStore.
public JobScenarioBuilder expectTaskAddedToStore(int taskIdx, int resubmit, Consumer<Task> check) {
Task task = expectTaskEvent(taskIdx, resubmit, StoreEvent.TaskAdded);
check.accept(task);
return this;
}
Aggregations