Search in sources :

Example 31 with Job

use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.

the class JobDirectQueryTest method testFindBatchJob.

private void testFindBatchJob(String jobId) {
    Job job = client.findJob(JobId.newBuilder().setId(jobId).build());
    assertThat(job.getId()).isEqualTo(jobId);
    CellAssertions.assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME);
}
Also used : Job(com.netflix.titus.grpc.protogen.Job)

Example 32 with Job

use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.

the class JobObserveTest method observeJobs.

@Test(timeout = LONG_TEST_TIMEOUT_MS)
public void observeJobs() throws InterruptedException {
    TestStreamObserver<JobChangeNotification> subscriber = subscribe(ObserveJobsQuery.getDefaultInstance());
    for (int i = 0; i < 2; i++) {
        String jobId = jobsScenarioBuilder.scheduleAndReturnJob(oneTaskBatchJobDescriptor(), jobScenarioBuilder -> jobScenarioBuilder.template(startTasksInNewJob()).template(ScenarioTemplates.killJob())).getId();
        JobChangeNotification event;
        while (true) {
            event = subscriber.takeNext(SHORT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
            if (event.hasJobUpdate()) {
                Job job = event.getJobUpdate().getJob();
                assertThat(job.getId()).isEqualTo(jobId);
                CellAssertions.assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME);
                if (job.getStatus().getState() == JobState.Finished) {
                    break;
                }
            }
        }
    }
    subscriber.cancel();
}
Also used : Arrays(java.util.Arrays) JobDescriptorGenerator.serviceJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.serviceJobDescriptors) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Job(com.netflix.titus.grpc.protogen.Job) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) ScenarioTemplates.startTasksInNewJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.startTasksInNewJob) Image(com.netflix.titus.grpc.protogen.Image) ScenarioTemplates.killJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.killJob) JobState(com.netflix.titus.grpc.protogen.JobStatus.JobState) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) Owner(com.netflix.titus.api.jobmanager.model.job.Owner) SERVICE(com.netflix.titus.grpc.protogen.JobDescriptor.JobSpecCase.SERVICE) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TaskState(com.netflix.titus.grpc.protogen.TaskStatus.TaskState) EmbeddedTitusCells(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCells) ImmutableMap(com.google.common.collect.ImmutableMap) Task(com.netflix.titus.grpc.protogen.Task) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) CellAssertions(com.netflix.titus.master.integration.v3.job.CellAssertions) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) Rule(org.junit.Rule) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) EmbeddedTitusMaster(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMaster) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) Job(com.netflix.titus.grpc.protogen.Job) ScenarioTemplates.startTasksInNewJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.startTasksInNewJob) ScenarioTemplates.killJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.killJob) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 33 with Job

use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.

the class JobObserveTest method observeByJobDescriptor.

@Test(timeout = LONG_TEST_TIMEOUT_MS)
public void observeByJobDescriptor() throws InterruptedException {
    startAll(batchJobDescriptors().getValue().toBuilder().withApplicationName("myApp").build(), batchJobDescriptors().getValue().toBuilder().withApplicationName("otherApp").withOwner(Owner.newBuilder().withTeamEmail("me@netflix.com").build()).build(), batchJobDescriptors().getValue().but(j -> j.getContainer().toBuilder().withImage(JobModel.newImage().withName("some/image").withTag("stable").build())), batchJobDescriptors().getValue().toBuilder().withAttributes(ImmutableMap.<String, String>builder().put("attr1", "value1").put("attr2", "value2").build()).build());
    startAll(serviceJobDescriptors().getValue());
    observeByJobDescriptor(jobsScenarioBuilder.takeJobId(0), ObserveJobsQuery.newBuilder().putFilteringCriteria("applicationName", "myApp").build(), job -> assertThat(job.getJobDescriptor().getApplicationName()).isEqualTo("myApp"));
    observeByJobDescriptor(jobsScenarioBuilder.takeJobId(1), ObserveJobsQuery.newBuilder().putFilteringCriteria("owner", "me@netflix.com").build(), job -> assertThat(job.getJobDescriptor().getOwner().getTeamEmail()).isEqualTo("me@netflix.com"));
    observeByJobDescriptor(jobsScenarioBuilder.takeJobId(2), ObserveJobsQuery.newBuilder().putFilteringCriteria("imageName", "some/image").putFilteringCriteria("imageTag", "stable").build(), job -> {
        Image image = job.getJobDescriptor().getContainer().getImage();
        assertThat(image.getName()).isEqualTo("some/image");
        assertThat(image.getTag()).isEqualTo("stable");
    });
    observeByJobDescriptor(jobsScenarioBuilder.takeJobId(3), ObserveJobsQuery.newBuilder().putFilteringCriteria("attributes", "attr1,attr2:value2").putFilteringCriteria("attributes.op", "and").build(), job -> assertThat(job.getJobDescriptor().getAttributesMap()).containsKey("attr1").containsEntry("attr2", "value2"));
    observeByJobDescriptor(jobsScenarioBuilder.takeJobId(4), ObserveJobsQuery.newBuilder().putFilteringCriteria("jobType", "service").build(), job -> assertThat(job.getJobDescriptor().getJobSpecCase()).isEqualTo(SERVICE));
}
Also used : Arrays(java.util.Arrays) JobDescriptorGenerator.serviceJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.serviceJobDescriptors) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Job(com.netflix.titus.grpc.protogen.Job) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) ScenarioTemplates.startTasksInNewJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.startTasksInNewJob) Image(com.netflix.titus.grpc.protogen.Image) ScenarioTemplates.killJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.killJob) JobState(com.netflix.titus.grpc.protogen.JobStatus.JobState) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) Owner(com.netflix.titus.api.jobmanager.model.job.Owner) SERVICE(com.netflix.titus.grpc.protogen.JobDescriptor.JobSpecCase.SERVICE) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TaskState(com.netflix.titus.grpc.protogen.TaskStatus.TaskState) EmbeddedTitusCells(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCells) ImmutableMap(com.google.common.collect.ImmutableMap) Task(com.netflix.titus.grpc.protogen.Task) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) CellAssertions(com.netflix.titus.master.integration.v3.job.CellAssertions) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) Rule(org.junit.Rule) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) EmbeddedTitusMaster(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMaster) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) Image(com.netflix.titus.grpc.protogen.Image) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 34 with Job

use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.

the class JobSanitizeTest method testSuppressedInternalError.

/**
 * Verifies that non-NOT_FOUND errors are suppressed and the original job descriptor is not modified.
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testSuppressedInternalError() {
    when(registryClient.getImageDigest(anyString(), anyString())).thenReturn(Mono.error(TitusRegistryException.internalError(repo, tag, HttpStatus.INTERNAL_SERVER_ERROR)));
    final com.netflix.titus.grpc.protogen.JobDescriptor jobDescriptor = toGrpcJobDescriptor(batchJobDescriptors().map(jd -> jd.but(d -> d.getContainer().toBuilder().withImage(Image.newBuilder().withName(repo).withTag(tag).build()))).getValue());
    String jobId = client.createJob(jobDescriptor).getId();
    Job resultJobDescriptor = client.findJob(JobId.newBuilder().setId(jobId).build());
    logger.info("Got back result {}", resultJobDescriptor);
    assertTrue(resultJobDescriptor.getJobDescriptor().getContainer().getImage().getDigest().isEmpty());
}
Also used : JobImageSanitizerConfiguration(com.netflix.titus.runtime.endpoint.admission.JobImageSanitizerConfiguration) RegistryClient(com.netflix.titus.runtime.connector.registry.RegistryClient) EmbeddedKubeCluster(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeCluster) LoggerFactory(org.slf4j.LoggerFactory) Job(com.netflix.titus.grpc.protogen.Job) Image(com.netflix.titus.api.jobmanager.model.job.Image) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) EmbeddedTitusMasters(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMasters) AdmissionSanitizer(com.netflix.titus.common.model.admission.AdmissionSanitizer) EmbeddedKubeClusters(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeClusters) Assert.fail(org.junit.Assert.fail) Status(io.grpc.Status) GrpcJobManagementModelConverters.toGrpcJobDescriptor(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcJobDescriptor) Before(org.junit.Before) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) TitusRegistryException(com.netflix.titus.runtime.connector.registry.TitusRegistryException) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Logger(org.slf4j.Logger) Assert.assertTrue(org.junit.Assert.assertTrue) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) Category(org.junit.experimental.categories.Category) JobImageSanitizer(com.netflix.titus.runtime.endpoint.admission.JobImageSanitizer) StatusRuntimeException(io.grpc.StatusRuntimeException) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) HttpStatus(org.springframework.http.HttpStatus) Rule(org.junit.Rule) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) EmbeddedTitusCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCell) JobId(com.netflix.titus.grpc.protogen.JobId) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Job(com.netflix.titus.grpc.protogen.Job) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 35 with Job

use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.

the class JobSanitizeTest method testJobDigestResolution.

/**
 * Verifies that a digest value is properly added to a job descriptor that is using tag.
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testJobDigestResolution() {
    when(registryClient.getImageDigest(anyString(), anyString())).thenReturn(Mono.just(digest));
    com.netflix.titus.grpc.protogen.JobDescriptor jobDescriptor = toGrpcJobDescriptor(batchJobDescriptors().map(jd -> jd.but(d -> d.getContainer().toBuilder().withImage(Image.newBuilder().withName(repo).withTag(tag).build()))).getValue());
    String jobId = client.createJob(jobDescriptor).getId();
    Job resultJobDescriptor = client.findJob(JobId.newBuilder().setId(jobId).build());
    assertEquals(digest, resultJobDescriptor.getJobDescriptor().getContainer().getImage().getDigest());
}
Also used : JobImageSanitizerConfiguration(com.netflix.titus.runtime.endpoint.admission.JobImageSanitizerConfiguration) RegistryClient(com.netflix.titus.runtime.connector.registry.RegistryClient) EmbeddedKubeCluster(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeCluster) LoggerFactory(org.slf4j.LoggerFactory) Job(com.netflix.titus.grpc.protogen.Job) Image(com.netflix.titus.api.jobmanager.model.job.Image) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) EmbeddedTitusMasters(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMasters) AdmissionSanitizer(com.netflix.titus.common.model.admission.AdmissionSanitizer) EmbeddedKubeClusters(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeClusters) Assert.fail(org.junit.Assert.fail) Status(io.grpc.Status) GrpcJobManagementModelConverters.toGrpcJobDescriptor(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcJobDescriptor) Before(org.junit.Before) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) TitusRegistryException(com.netflix.titus.runtime.connector.registry.TitusRegistryException) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Logger(org.slf4j.Logger) Assert.assertTrue(org.junit.Assert.assertTrue) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) Category(org.junit.experimental.categories.Category) JobImageSanitizer(com.netflix.titus.runtime.endpoint.admission.JobImageSanitizer) StatusRuntimeException(io.grpc.StatusRuntimeException) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) HttpStatus(org.springframework.http.HttpStatus) Rule(org.junit.Rule) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) EmbeddedTitusCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCell) JobId(com.netflix.titus.grpc.protogen.JobId) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Job(com.netflix.titus.grpc.protogen.Job) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Aggregations

Job (com.netflix.titus.grpc.protogen.Job)36 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)15 JobQueryResult (com.netflix.titus.grpc.protogen.JobQueryResult)14 Task (com.netflix.titus.grpc.protogen.Task)10 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)9 JobQuery (com.netflix.titus.grpc.protogen.JobQuery)9 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)9 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)9 List (java.util.List)9 TaskQueryResult (com.netflix.titus.grpc.protogen.TaskQueryResult)7 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)6 Pair (com.netflix.titus.common.util.tuple.Pair)6 JobManagementServiceGrpc (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc)6 TaskQuery (com.netflix.titus.grpc.protogen.TaskQuery)6 JobManagementServiceStub (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub)5 Page (com.netflix.titus.grpc.protogen.Page)5 Random (java.util.Random)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5