use of com.netflix.titus.api.model.callmetadata.CallMetadata 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.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.
the class JobTransactionLoggerTest method testLogFormatting.
/**
* Sole purpose of this test is visual inspection of the generated log line.
*/
@Test
public void testLogFormatting() throws Exception {
Job previousJob = createJob();
Job currentJob = previousJob.toBuilder().withStatus(JobStatus.newBuilder().withState(JobState.Finished).build()).build();
ModelActionHolder modelActionHolder = ModelActionHolder.reference(TitusModelAction.newModelUpdate("testModelAction").job(previousJob).trigger(Trigger.API).summary("Job model update").jobUpdate(jobHolder -> jobHolder.setEntity(currentJob)));
TitusChangeAction changeAction = TitusChangeAction.newAction("testChangeAction").job(previousJob).trigger(Trigger.API).summary("Job update").callMetadata(CallMetadata.newBuilder().withCallerId("LoggerTest").withCallReason("Testing logger transaction").build()).applyModelUpdate(self -> modelActionHolder);
JobManagerReconcilerEvent jobReconcilerEvent = new JobModelUpdateReconcilerEvent(previousJob, changeAction, modelActionHolder, EntityHolder.newRoot(currentJob.getId(), currentJob), Optional.of(EntityHolder.newRoot(previousJob.getId(), previousJob)), "1");
String logLine = JobTransactionLogger.doFormat(jobReconcilerEvent);
assertThat(logLine).isNotEmpty();
logger.info("Job event: {}", logLine);
}
use of com.netflix.titus.api.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.
the class DefaultJobManagementServiceGrpc method findJobs.
@Override
public void findJobs(JobQuery jobQuery, StreamObserver<JobQueryResult> responseObserver) {
if (!checkPageIsValid(jobQuery.getPage(), responseObserver)) {
return;
}
CallMetadata callMetadata = resolveCallMetadata();
logPageNumberUsage(systemLog, callMetadata, getClass().getSimpleName(), "findJobs", jobQuery.getPage());
Subscription subscription = jobServiceGateway.findJobs(jobQuery, callMetadata).subscribe(responseObserver::onNext, e -> safeOnError(logger, e, responseObserver), responseObserver::onCompleted);
attachCancellingCallback(responseObserver, subscription);
}
use of com.netflix.titus.api.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.
the class JobManagementResource method findTasks.
@GET
@ApiOperation("Find tasks")
@Path("/tasks")
public TaskQueryResult findTasks(@Context UriInfo info) {
MultivaluedMap<String, String> queryParameters = info.getQueryParameters(true);
TaskQuery.Builder queryBuilder = TaskQuery.newBuilder();
Page page = RestUtil.createPage(queryParameters);
CallMetadata callMetadata = resolveCallMetadata();
logPageNumberUsage(systemLog, callMetadata, getClass().getSimpleName(), "findTasks", page);
queryBuilder.setPage(page);
queryBuilder.putAllFilteringCriteria(RestUtil.getFilteringCriteria(queryParameters));
queryBuilder.addAllFields(RestUtil.getFieldsParameter(queryParameters));
return Responses.fromSingleValueObservable(jobServiceGateway.findTasks(queryBuilder.build(), callMetadata));
}
use of com.netflix.titus.api.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.
the class LoadBalancerResource method getAllLoadBalancers.
@GET
@ApiOperation("Get all load balancers")
public GetAllLoadBalancersResult getAllLoadBalancers(@Context UriInfo info) {
Page page = RestUtil.createPage(info.getQueryParameters());
CallMetadata callMetadata = resolveCallMetadata();
logPageNumberUsage(systemLog, callMetadata, getClass().getSimpleName(), "getAllLoadBalancers", page);
return Responses.fromSingleValueObservable(loadBalancerService.getAllLoadBalancers(GetAllLoadBalancersRequest.newBuilder().setPage(page).build(), callMetadata));
}
Aggregations