Search in sources :

Example 46 with BatchJobExt

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

the class JobRuntimePredictionSanitizerTest method emptyPredictionsCauseSanitizationToBeSkipped.

@Test
public void emptyPredictionsCauseSanitizationToBeSkipped() {
    JobDescriptor<BatchJobExt> noRuntimeLimit = jobDescriptor.but(jd -> jd.getExtensions().toBuilder().withRuntimeLimitMs(0));
    JobRuntimePredictionClient client = mock(JobRuntimePredictionClient.class);
    JobRuntimePredictions predictions = new JobRuntimePredictions("v1", modelId, new TreeSet<>());
    when(client.getRuntimePredictions(any())).thenReturn(Mono.just(predictions));
    AdmissionSanitizer<JobDescriptor> sanitizer = new JobRuntimePredictionSanitizer(client, JobRuntimePredictionSelectors.best(), config, TitusRuntimes.test());
    StepVerifier.create(sanitizer.sanitizeAndApply(noRuntimeLimit)).assertNext(result -> assertThat(((JobDescriptor<?>) result).getAttributes()).containsEntry(JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION, "true").containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID, modelId).containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION, "v1").doesNotContainKeys(JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC, JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE, JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE)).verifyComplete();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JobDescriptorGenerator(com.netflix.titus.testkit.model.job.JobDescriptorGenerator) Arrays(java.util.Arrays) JobRuntimePredictions(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictions) JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION) StepVerifier(reactor.test.StepVerifier) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRuntimePrediction(com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction) TreeSet(java.util.TreeSet) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) AdmissionSanitizer(com.netflix.titus.common.model.admission.AdmissionSanitizer) Before(org.junit.Before) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC) JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) JOB_PARAMETER_SKIP_RUNTIME_PREDICTION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_PARAMETER_SKIP_RUNTIME_PREDICTION) JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID) Mockito.mock(org.mockito.Mockito.mock) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobRuntimePredictions(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictions) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) Test(org.junit.Test)

Example 47 with BatchJobExt

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

the class CachedBatchJobWithOneTaskTest method testInitial.

@Test
public void testInitial() {
    Pair<Job<BatchJobExt>, PMap<String, Task>> jobAndTasks = newBatchJobWithTasks(0, 1);
    Job<BatchJobExt> job = jobAndTasks.getLeft();
    PMap<String, Task> tasks = jobAndTasks.getRight();
    // Create finished task for slot 0 to test filtering.
    Task task = CollectionsExt.first(tasks.values());
    Task finishedTask = task.toBuilder().withId("finishedTaskId").withStatus(TaskStatus.newBuilder().withState(TaskState.Finished).build()).withVersion(Version.newBuilder().withTimestamp(task.getVersion().getTimestamp() - 1_000).build()).build();
    tasks = tasks.plus(finishedTask.getId(), finishedTask);
    CachedJob cached1 = CachedBatchJobWithOneTask.newBatchInstance(job, tasks, titusRuntime);
    assertThat(cached1.getJob()).isEqualTo(job);
    assertThat(cached1.getTasks()).hasSize(1);
    assertThat(cached1.getTasks()).containsValue(task);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) PMap(org.pcollections.PMap) Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Example 48 with BatchJobExt

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

the class CachedBatchJobWithOneTaskTest method initialSnapshot.

private Pair<PCollectionJobSnapshot, Task> initialSnapshot(boolean create) {
    Pair<Job<BatchJobExt>, PMap<String, Task>> jobAndTasks = newBatchJobWithTasks(0, 1);
    Job<BatchJobExt> job = jobAndTasks.getLeft();
    Task task = CollectionsExt.first(jobAndTasks.getRight().values());
    PCollectionJobSnapshot snapshot = PCollectionJobSnapshot.newInstance("test", Collections.singletonMap(job.getId(), job), Collections.singletonMap(job.getId(), create ? Collections.singletonMap(task.getId(), task) : Collections.emptyMap()), false, false, error -> {
        throw new IllegalStateException(error);
    }, titusRuntime);
    return Pair.of(snapshot, task);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) PMap(org.pcollections.PMap) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 49 with BatchJobExt

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

the class JobSnapshotPerf method newJobWithTasks.

private Pair<Job<?>, Map<String, Task>> newJobWithTasks() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob().toBuilder().withId("job#" + jobIdx.getAndIncrement()).build();
    Map<String, Task> tasks = new HashMap<>();
    for (int t = 0; t < taskPerJobCount; t++) {
        BatchJobTask task = newTask(job);
        tasks.put(task.getId(), task);
    }
    return Pair.of(job, tasks);
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask)

Example 50 with BatchJobExt

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

the class JobScenarioBuilder method updateJobCapacityDesiredInvalid.

public JobScenarioBuilder updateJobCapacityDesiredInvalid(int targetDesired, int currentDesired) {
    logger.info("[{}] Changing job {} capacity desired to {}...", discoverActiveTest(), jobId, targetDesired);
    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
    client.updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setDesired(UInt32Value.newBuilder().setValue(targetDesired).build()).build()).build(), responseObserver);
    await().timeout(TIMEOUT_MS, TimeUnit.MILLISECONDS).until(responseObserver::hasError);
    Throwable error = responseObserver.getError();
    assertThat(error).isNotNull();
    assertThat(error).isInstanceOf(StatusRuntimeException.class);
    StatusRuntimeException statusRuntimeException = (StatusRuntimeException) error;
    assertThat(statusRuntimeException.getStatus().getCode() == Status.Code.INVALID_ARGUMENT).isTrue();
    // Make sure desired count is unchanged
    Job job = getJob();
    JobDescriptor.JobDescriptorExt ext = job.getJobDescriptor().getExtensions();
    int currentCapacity = ext instanceof BatchJobExt ? ((BatchJobExt) ext).getSize() : ((ServiceJobExt) ext).getCapacity().getDesired();
    assertThat(currentCapacity).isEqualTo(currentDesired);
    return this;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) StatusRuntimeException(io.grpc.StatusRuntimeException) GrpcJobManagementModelConverters.toCoreJob(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toCoreJob) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Aggregations

BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)73 Test (org.junit.Test)55 Task (com.netflix.titus.api.jobmanager.model.job.Task)30 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)25 List (java.util.List)20 ArrayList (java.util.ArrayList)19 JobStore (com.netflix.titus.api.jobmanager.store.JobStore)17 HashMap (java.util.HashMap)16 V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)14 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)13 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)11 V1Pod (io.kubernetes.client.openapi.models.V1Pod)11 Job (com.netflix.titus.api.jobmanager.model.job.Job)10 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)10 Container (com.netflix.titus.api.jobmanager.model.job.Container)6 Map (java.util.Map)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 V1Container (io.kubernetes.client.openapi.models.V1Container)5 BasicContainer (com.netflix.titus.api.jobmanager.model.job.BasicContainer)4 Image (com.netflix.titus.api.jobmanager.model.job.Image)4