Search in sources :

Example 16 with ServiceJobExt

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

the class MoveTaskTest method testMoveWithIncompatibleTargetJob.

@Test
public void testMoveWithIncompatibleTargetJob() {
    JobDescriptor<ServiceJobExt> jobDescriptor = oneTaskServiceJobDescriptor();
    JobScenarioBuilder sourceJobBuilder = startNewJob(jobDescriptor);
    String sourceJobId = sourceJobBuilder.getJobId();
    JobDescriptor<ServiceJobExt> incompatible = jobDescriptor.but(descriptor -> descriptor.getContainer().but(container -> container.getImage().toBuilder().withName("other/image").build()));
    String targetJobId = startNewJob(incompatible).getJobId();
    try {
        sourceJobBuilder.moveTask(0, 0, sourceJobId, targetJobId);
    } catch (JobManagerException e) {
        assertThat(e.getErrorCode()).isEqualTo(JobManagerException.ErrorCode.JobsNotCompatible);
        assertThat(e.getMessage()).contains("container.image.name");
    }
}
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) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) JobScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder) Test(org.junit.Test)

Example 17 with ServiceJobExt

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

the class V1SpecPodFactoryTest method relocationLabel.

@Test
public void relocationLabel() {
    Job<ServiceJobExt> job = JobGenerator.oneServiceJob();
    Job<ServiceJobExt> selfManagedJob = job.toBuilder().withJobDescriptor(job.getJobDescriptor().but(jd -> jd.getDisruptionBudget().toBuilder().withDisruptionBudgetPolicy(SelfManagedDisruptionBudgetPolicy.newBuilder().build()))).build();
    ServiceJobTask task = JobGenerator.oneServiceTask();
    when(podAffinityFactory.buildV1Affinity(any(), eq(task))).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    assertThat(pod.getMetadata().getLabels()).doesNotContainKey(KubeConstants.POD_LABEL_RELOCATION_BINPACK);
    V1Pod selfManagedPod = podFactory.buildV1Pod(selfManagedJob, task);
    assertThat(selfManagedPod.getMetadata().getLabels()).containsEntry(KubeConstants.POD_LABEL_RELOCATION_BINPACK, "SelfManaged");
}
Also used : V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) HashMap(java.util.HashMap) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) Test(org.junit.Test)

Example 18 with ServiceJobExt

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

the class DefaultDeschedulerServiceTest method verifyRelocationPlan.

private void verifyRelocationPlan(long relocationDelay, String reasonMessage) {
    ReadOnlyJobOperations jobOperations = mock(ReadOnlyJobOperations.class);
    DefaultDeschedulerService dds = new DefaultDeschedulerService(jobOperations, mock(ReadOnlyEvictionOperations.class), new KubernetesNodeDataResolver(configuration, TestDataFactory.mockFabric8IOConnector(), node -> true), () -> "foo|bar", titusRuntime);
    Job<ServiceJobExt> job = JobGenerator.serviceJobs(oneTaskServiceJobDescriptor().but(ofServiceSize(2), withDisruptionBudget(budget(selfManagedPolicy(relocationDelay), unlimitedRate(), Collections.emptyList())))).getValue();
    ServiceJobTask task = JobGenerator.serviceTasks(job).getValue();
    when(jobOperations.getJob(job.getId())).thenReturn(Optional.of(job));
    TitusNode node = TitusNode.newBuilder().withId("node1").withServerGroupId("asg1").withRelocationRequired(true).withBadCondition(false).build();
    // Advance test clock
    long clockAdvancedMs = 5_000;
    TestClock testClock = (TestClock) titusRuntime.getClock();
    testClock.advanceTime(Duration.ofMillis(clockAdvancedMs));
    Optional<TaskRelocationPlan> relocationPlanForTask = dds.getRelocationPlanForTask(node, task, Collections.emptyMap());
    assertThat(relocationPlanForTask).isPresent();
    assertThat(relocationPlanForTask.get().getTaskId()).isEqualTo(task.getId());
    // relocation time is expected to be decision clock time + retentionTimeMs
    assertThat(relocationPlanForTask.get().getRelocationTime()).isEqualTo(relocationDelay + clockAdvancedMs);
    assertThat(relocationPlanForTask.get().getDecisionTime()).isEqualTo(clockAdvancedMs);
    assertThat(relocationPlanForTask.get().getReasonMessage()).isEqualTo(reasonMessage);
}
Also used : TestDataFactory(com.netflix.titus.supplementary.relocation.TestDataFactory) Archaius2Ext(com.netflix.titus.common.util.archaius2.Archaius2Ext) DisruptionBudgetGenerator.unlimitedRate(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.unlimitedRate) RelocationAttributes(com.netflix.titus.runtime.RelocationAttributes) Task(com.netflix.titus.api.jobmanager.model.job.Task) DisruptionBudgetGenerator.budget(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.budget) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) KubernetesNodeDataResolver(com.netflix.titus.supplementary.relocation.connector.KubernetesNodeDataResolver) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) RelocationConfiguration(com.netflix.titus.supplementary.relocation.RelocationConfiguration) Duration(java.time.Duration) RelocationConnectorStubs(com.netflix.titus.supplementary.relocation.RelocationConnectorStubs) JobFunctions.ofServiceSize(com.netflix.titus.api.jobmanager.model.job.JobFunctions.ofServiceSize) ReadOnlyJobOperations(com.netflix.titus.api.jobmanager.service.ReadOnlyJobOperations) TaskRelocationReason(com.netflix.titus.api.relocation.model.TaskRelocationPlan.TaskRelocationReason) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) MutableDataGenerator(com.netflix.titus.common.data.generator.MutableDataGenerator) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) DeschedulingResult(com.netflix.titus.supplementary.relocation.model.DeschedulingResult) DisruptionBudgetGenerator.selfManagedPolicy(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.selfManagedPolicy) Job(com.netflix.titus.api.jobmanager.model.job.Job) JobFunctions.withJobId(com.netflix.titus.api.jobmanager.model.job.JobFunctions.withJobId) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobFunctions.withDisruptionBudget(com.netflix.titus.api.jobmanager.model.job.JobFunctions.withDisruptionBudget) JobGenerator(com.netflix.titus.testkit.model.job.JobGenerator) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) List(java.util.List) ReadOnlyEvictionOperations(com.netflix.titus.api.eviction.service.ReadOnlyEvictionOperations) Optional(java.util.Optional) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) TestClock(com.netflix.titus.common.util.time.TestClock) Collections(java.util.Collections) TitusNode(com.netflix.titus.supplementary.relocation.connector.TitusNode) Mockito.mock(org.mockito.Mockito.mock) ReadOnlyJobOperations(com.netflix.titus.api.jobmanager.service.ReadOnlyJobOperations) KubernetesNodeDataResolver(com.netflix.titus.supplementary.relocation.connector.KubernetesNodeDataResolver) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) TestClock(com.netflix.titus.common.util.time.TestClock) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) ReadOnlyEvictionOperations(com.netflix.titus.api.eviction.service.ReadOnlyEvictionOperations) TitusNode(com.netflix.titus.supplementary.relocation.connector.TitusNode) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)

Example 19 with ServiceJobExt

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

the class ExtendedJobSanitizerTest method testLegacyServiceJobDisruptionBudgetRewrite.

@Test
public void testLegacyServiceJobDisruptionBudgetRewrite() {
    JobDescriptor<ServiceJobExt> jobDescriptor = newServiceJob().getValue().toBuilder().withDisruptionBudget(DisruptionBudget.none()).build();
    ExtendedJobSanitizer sanitizer = new ExtendedJobSanitizer(configuration, jobAssertions, entitySanitizer, disruptionBudgetSanitizer, jd -> false, jd -> false, titusRuntime);
    Optional<JobDescriptor<ServiceJobExt>> sanitizedOpt = sanitizer.sanitize(jobDescriptor);
    assertThat(sanitizedOpt).isNotEmpty();
    JobDescriptor<ServiceJobExt> sanitized = sanitizedOpt.get();
    String nonCompliant = sanitized.getAttributes().get(TITUS_NON_COMPLIANT_FEATURES);
    assertThat(nonCompliant).contains(JobFeatureComplianceChecks.DISRUPTION_BUDGET_FEATURE);
    SelfManagedDisruptionBudgetPolicy policy = (SelfManagedDisruptionBudgetPolicy) sanitized.getDisruptionBudget().getDisruptionBudgetPolicy();
    assertThat(policy.getRelocationTimeMs()).isEqualTo(DisruptionBudgetSanitizer.DEFAULT_SERVICE_RELOCATION_TIME_MS);
}
Also used : SelfManagedDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.SelfManagedDisruptionBudgetPolicy) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Test(org.junit.Test)

Example 20 with ServiceJobExt

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

the class CassandraJobStore method retrieveJobs.

@Override
public Observable<Pair<List<Job<?>>, Integer>> retrieveJobs() {
    Observable result = Observable.fromCallable(() -> {
        List<String> jobIds = activeJobIdsBucketManager.getItems();
        return jobIds.stream().map(retrieveActiveJobStatement::bind).map(this::execute).collect(Collectors.toList());
    }).flatMap(observables -> Observable.merge(observables, getConcurrencyLimit()).flatMapIterable(resultSet -> {
        List<Row> allRows = resultSet.all();
        if (allRows.isEmpty()) {
            logger.debug("Job id with no record");
            return Collections.emptyList();
        }
        return allRows.stream().map(row -> row.getString(0)).map(value -> {
            String effectiveValue;
            if (fitBadDataInjection.isPresent()) {
                effectiveValue = fitBadDataInjection.get().afterImmediate(JobStoreFitAction.ErrorKind.CorruptedRawJobRecords.name(), value);
            } else {
                effectiveValue = value;
            }
            Job<?> job;
            try {
                job = deserializeJob(effectiveValue);
            } catch (Exception e) {
                logger.error("Cannot map serialized job data to Job class: {}", effectiveValue, e);
                return Either.ofError(e);
            }
            if (job.getJobDescriptor().getDisruptionBudget() == null) {
                titusRuntime.getCodeInvariants().inconsistent("jobWithNoDisruptionBudget: jobId=%s", job.getId());
                job = JobFunctions.changeDisruptionBudget(job, DisruptionBudget.none());
            }
            // TODO Remove this code when there are no more jobs with missing migration data (caused by a bug in ServiceJobExt builder).
            if (job.getJobDescriptor().getExtensions() instanceof ServiceJobExt) {
                Job<ServiceJobExt> serviceJob = (Job<ServiceJobExt>) job;
                ServiceJobExt ext = serviceJob.getJobDescriptor().getExtensions();
                if (ext.getMigrationPolicy() == null) {
                    titusRuntime.getCodePointTracker().markReachable("Corrupted task migration record in Cassandra: " + job.getId());
                    ServiceJobExt fixedExt = ext.toBuilder().withMigrationPolicy(SystemDefaultMigrationPolicy.newBuilder().build()).build();
                    logger.warn("Service job with no migration policy defined. Setting system default: {}", job.getId());
                    job = serviceJob.toBuilder().withJobDescriptor(serviceJob.getJobDescriptor().toBuilder().withExtensions(fixedExt).build()).build();
                }
            }
            if (!fitBadDataInjection.isPresent()) {
                return Either.ofValue(job);
            }
            Job<?> effectiveJob = fitBadDataInjection.get().afterImmediate(JobStoreFitAction.ErrorKind.CorruptedJobRecords.name(), job);
            return Either.ofValue(effectiveJob);
        }).collect(Collectors.toList());
    })).toList().map(everything -> {
        List<Job> goodJobs = (List<Job>) everything.stream().filter(Either::hasValue).map(Either::getValue).collect(Collectors.toList());
        int errors = everything.size() - goodJobs.size();
        return Pair.of(goodJobs, errors);
    });
    return result;
}
Also used : JobStoreException(com.netflix.titus.api.jobmanager.store.JobStoreException) Task(com.netflix.titus.api.jobmanager.model.job.Task) LoggerFactory(org.slf4j.LoggerFactory) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) Session(com.datastax.driver.core.Session) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) Either(com.netflix.titus.common.util.tuple.Either) JobStore(com.netflix.titus.api.jobmanager.store.JobStore) BatchStatement(com.datastax.driver.core.BatchStatement) JobStoreFitAction(com.netflix.titus.api.jobmanager.store.JobStoreFitAction) Job(com.netflix.titus.api.jobmanager.model.job.Job) StoreTransactionLoggers.transactionLogger(com.netflix.titus.ext.cassandra.store.StoreTransactionLoggers.transactionLogger) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) Collectors(java.util.stream.Collectors) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) List(java.util.List) Stream(java.util.stream.Stream) DisruptionBudget(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget) ProxyConfiguration(com.netflix.titus.common.util.guice.annotation.ProxyConfiguration) Optional(java.util.Optional) Logging(com.netflix.titus.common.util.guice.ProxyType.Logging) Statement(com.datastax.driver.core.Statement) Completable(rx.Completable) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) QueryTrace(com.datastax.driver.core.QueryTrace) Row(com.datastax.driver.core.Row) Exceptions(rx.exceptions.Exceptions) Callable(java.util.concurrent.Callable) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Observable(rx.Observable) Inject(javax.inject.Inject) PreparedStatement(com.datastax.driver.core.PreparedStatement) ResultSet(com.datastax.driver.core.ResultSet) Pair(com.netflix.titus.common.util.tuple.Pair) Spectator(com.netflix.titus.common.util.guice.ProxyType.Spectator) DriverException(com.datastax.driver.core.exceptions.DriverException) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) FitFramework(com.netflix.titus.common.framework.fit.FitFramework) Logger(org.slf4j.Logger) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) FitInjection(com.netflix.titus.common.framework.fit.FitInjection) SystemDefaultMigrationPolicy(com.netflix.titus.api.jobmanager.model.job.migration.SystemDefaultMigrationPolicy) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Emitter(rx.Emitter) FutureCallback(com.google.common.util.concurrent.FutureCallback) Futures(com.google.common.util.concurrent.Futures) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) ObjectMappers(com.netflix.titus.api.json.ObjectMappers) Version(com.netflix.titus.api.jobmanager.model.job.Version) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Collections(java.util.Collections) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Either(com.netflix.titus.common.util.tuple.Either) List(java.util.List) ArrayList(java.util.ArrayList) Job(com.netflix.titus.api.jobmanager.model.job.Job) Observable(rx.Observable) JobStoreException(com.netflix.titus.api.jobmanager.store.JobStoreException) DriverException(com.datastax.driver.core.exceptions.DriverException)

Aggregations

ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)42 Test (org.junit.Test)17 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)13 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)13 Job (com.netflix.titus.api.jobmanager.model.job.Job)11 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)8 Task (com.netflix.titus.api.jobmanager.model.job.Task)8 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)8 List (java.util.List)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Stopwatch (com.google.common.base.Stopwatch)6 Empty (com.google.protobuf.Empty)6 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)6 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)6 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)6 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)5 JobScenarioBuilder (com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder)5 JobDescriptorGenerator.oneTaskServiceJobDescriptor (com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor)5 ArrayList (java.util.ArrayList)5 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)4