Search in sources :

Example 21 with JobDescriptor

use of com.netflix.titus.api.jobmanager.model.job.JobDescriptor 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 22 with JobDescriptor

use of com.netflix.titus.api.jobmanager.model.job.JobDescriptor 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)

Example 23 with JobDescriptor

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

the class JobSubmitAndControlBasicTest method testSubmitBatchJobWithEfsMount.

/**
 * Verify batch job submit with the expected state transitions. Verify agent receives proper EFS mount data.
 */
@Test(timeout = 30_000)
public void testSubmitBatchJobWithEfsMount() {
    EfsMount efsMount1 = ContainersGenerator.efsMounts().getValue().toBuilder().withMountPoint("/data/logs").build();
    EfsMount efsMount2 = ContainersGenerator.efsMounts().skip(1).getValue().toBuilder().withMountPoint("/data").build();
    List<EfsMount> efsMounts = asList(efsMount1, efsMount2);
    List<EfsMount> expectedOrder = asList(efsMount2, efsMount1);
    JobDescriptor<BatchJobExt> jobWithEfs = ONE_TASK_BATCH_JOB.but(jd -> jd.getContainer().but(c -> c.getContainerResources().toBuilder().withEfsMounts(efsMounts)));
    jobsScenarioBuilder.schedule(jobWithEfs, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.startTasksInNewJob()).assertEachPod(podWithEfsMounts(expectedOrder), "Container not assigned the expected EFS mount").allTasks(ScenarioTemplates.completeTask()).template(ScenarioTemplates.jobFinished()).expectJobEventStreamCompletes());
}
Also used : TaskScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.TaskScenarioBuilder) AwsInstanceType(com.netflix.titus.common.aws.AwsInstanceType) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) JobManagerConfiguration(com.netflix.titus.runtime.jobmanager.JobManagerConfiguration) V3_ENGINE_APP_PREFIX(com.netflix.titus.testkit.junit.master.TitusStackResource.V3_ENGINE_APP_PREFIX) EfsMount(com.netflix.titus.api.model.EfsMount) JobAsserts.podWithResources(com.netflix.titus.master.integration.v3.scenario.JobAsserts.podWithResources) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ContainersGenerator(com.netflix.titus.testkit.model.job.ContainersGenerator) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) 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) JobAsserts.podWithEfsMounts(com.netflix.titus.master.integration.v3.scenario.JobAsserts.podWithEfsMounts) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) List(java.util.List) Rule(org.junit.Rule) EmbeddedTitusCells.basicKubeCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCells.basicKubeCell) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) JobAttributes(com.netflix.titus.api.jobmanager.JobAttributes) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) EfsMount(com.netflix.titus.api.model.EfsMount) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 24 with JobDescriptor

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

the class JobsScenarioBuilder method schedule.

public JobsScenarioBuilder schedule(JobDescriptor<?> jobDescriptor, int times, Function<JobScenarioBuilder, JobScenarioBuilder> jobScenario) throws Exception {
    String sequence = jobDescriptor.getJobGroupInfo().getSequence();
    for (int i = 0; i < times; i++) {
        int finalI = i;
        JobDescriptor effective = sequence.isEmpty() ? jobDescriptor : jobDescriptor.but(jd -> jd.getJobGroupInfo().toBuilder().withSequence(sequence + '_' + finalI));
        schedule(effective, jobScenario);
    }
    return this;
}
Also used : TitusMasterResource(com.netflix.titus.testkit.junit.master.TitusMasterResource) LoggerFactory(org.slf4j.LoggerFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) EmbeddedTitusOperations(com.netflix.titus.testkit.embedded.EmbeddedTitusOperations) TIMEOUT_MS(com.netflix.titus.master.integration.v3.scenario.ScenarioBuilderUtil.TIMEOUT_MS) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Job(com.netflix.titus.api.jobmanager.model.job.Job) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) GrpcJobManagementModelConverters(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters) Collectors(java.util.stream.Collectors) Page(com.netflix.titus.grpc.protogen.Page) TimeUnit(java.util.concurrent.TimeUnit) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) List(java.util.List) ExternalResource(org.junit.rules.ExternalResource) Preconditions(com.google.common.base.Preconditions) ExceptionExt.rethrow(com.netflix.titus.common.util.ExceptionExt.rethrow) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobId(com.netflix.titus.grpc.protogen.JobId) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor)

Example 25 with JobDescriptor

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

the class MoveTaskTest method testMoveWithStoreUpdateFailure.

@Test
public void testMoveWithStoreUpdateFailure() {
    JobDescriptor<ServiceJobExt> jobDescriptor = oneTaskServiceJobDescriptor();
    String targetJobId = startNewJob(jobDescriptor).getJobId();
    JobScenarioBuilder sourceJobBuilder = startNewJob(jobDescriptor);
    String sourceJobId = sourceJobBuilder.getJobId();
    try {
        sourceJobBuilder.advance().breakStore().allTasks(tasks -> assertThat(tasks).hasSize(1)).moveTask(0, 0, sourceJobId, targetJobId);
    } catch (Exception e) {
        assertThat(ExceptionExt.toMessageChain(e)).contains("Store is broken");
    }
    jobsScenarioBuilder.getJobScenario(0).allTasks(tasks -> assertThat(tasks).hasSize(1));
    jobsScenarioBuilder.getJobScenario(1).allTasks(tasks -> assertThat(tasks).hasSize(1));
}
Also used : ScenarioTemplates(com.netflix.titus.master.jobmanager.service.integration.scenario.ScenarioTemplates) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) TimeoutException(java.util.concurrent.TimeoutException) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) JobScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder) Test(org.junit.Test) JobsScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobsScenarioBuilder) TestScheduler(rx.schedulers.TestScheduler) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) TimeUnit(java.util.concurrent.TimeUnit) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) ExceptionExt(com.netflix.titus.common.util.ExceptionExt) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder) TimeoutException(java.util.concurrent.TimeoutException) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) Test(org.junit.Test)

Aggregations

JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)28 Test (org.junit.Test)20 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)15 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)13 Before (org.junit.Before)13 Mono (reactor.core.publisher.Mono)12 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)11 AdmissionSanitizer (com.netflix.titus.common.model.admission.AdmissionSanitizer)11 Mockito.mock (org.mockito.Mockito.mock)11 Mockito.when (org.mockito.Mockito.when)11 JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION)9 JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION)9 JOB_PARAMETER_SKIP_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_PARAMETER_SKIP_RUNTIME_PREDICTION)9 JobRuntimePrediction (com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction)9 JobRuntimePredictionClient (com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient)9