Search in sources :

Example 11 with CallMetadata

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);
}
Also used : LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Task(com.netflix.titus.api.jobmanager.model.job.Task) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Single(rx.Single) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) DefaultLoadBalancerJobValidator(com.netflix.titus.api.loadbalancer.model.sanitizer.DefaultLoadBalancerJobValidator) Schedulers(rx.schedulers.Schedulers) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) LoadBalancerStore(com.netflix.titus.api.loadbalancer.store.LoadBalancerStore) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerValidationConfiguration(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerValidationConfiguration) Collection(java.util.Collection) DEREGISTERED(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget.State.DEREGISTERED) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) Set(java.util.Set) UUID(java.util.UUID) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) Collectors(java.util.stream.Collectors) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) List(java.util.List) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) Assert.assertFalse(org.junit.Assert.assertFalse) PublishSubject(rx.subjects.PublishSubject) Mockito.mock(org.mockito.Mockito.mock) Completable(rx.Completable) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) LoadBalancerJobValidator(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerJobValidator) TestScheduler(rx.schedulers.TestScheduler) ArrayList(java.util.ArrayList) AssertableSubscriber(rx.observers.AssertableSubscriber) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) Batch(com.netflix.titus.common.util.rx.batch.Batch) Mockito.never(org.mockito.Mockito.never) TaskAttributes(com.netflix.titus.api.jobmanager.TaskAttributes) InMemoryLoadBalancerStore(com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore) REGISTERED(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget.State.REGISTERED) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.titus.api.jobmanager.model.job.Task) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) Batch(com.netflix.titus.common.util.rx.batch.Batch) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) Test(org.junit.Test)

Example 12 with CallMetadata

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);
}
Also used : Trigger(com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger) Job(com.netflix.titus.api.jobmanager.model.job.Job) Logger(org.slf4j.Logger) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) Test(org.junit.Test) UUID(java.util.UUID) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) JobStatus(com.netflix.titus.api.jobmanager.model.job.JobStatus) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder) JobModelUpdateReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobModelUpdateReconcilerEvent) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) Optional(java.util.Optional) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobModelUpdateReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobModelUpdateReconcilerEvent) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) Job(com.netflix.titus.api.jobmanager.model.job.Job) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder) Test(org.junit.Test)

Example 13 with CallMetadata

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);
}
Also used : CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) Subscription(rx.Subscription)

Example 14 with CallMetadata

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));
}
Also used : CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) Page(com.netflix.titus.grpc.protogen.Page) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 15 with 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));
}
Also used : CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) Page(com.netflix.titus.grpc.protogen.Page) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)35 List (java.util.List)16 ArrayList (java.util.ArrayList)14 Task (com.netflix.titus.api.jobmanager.model.job.Task)13 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)12 Completable (rx.Completable)12 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)11 Collections (java.util.Collections)11 Collectors (java.util.stream.Collectors)11 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)10 Test (org.junit.Test)10 TaskStatus (com.netflix.titus.api.jobmanager.model.job.TaskStatus)9 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)9 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)9 Pair (com.netflix.titus.common.util.tuple.Pair)9 Set (java.util.Set)9 TimeUnit (java.util.concurrent.TimeUnit)9 TaskAttributes (com.netflix.titus.api.jobmanager.TaskAttributes)7 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)7 JobManagerEvent (com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent)7