Search in sources :

Example 1 with JobManagerException

use of com.netflix.titus.api.jobmanager.service.JobManagerException in project titus-control-plane by Netflix.

the class DefaultLoadBalancerJobValidatorTest method testValidateJobAccepted.

@Test
public void testValidateJobAccepted() throws Exception {
    when(jobOperations.getJob(JOB_ID)).thenReturn(Optional.of(Job.newBuilder().withId(JOB_ID).withStatus(JobStatus.newBuilder().withState(JobState.Finished).build()).build()));
    Throwable thrown = catchThrowable(() -> loadBalancerValidator.validateJobId(JOB_ID));
    assertThat(thrown).isInstanceOf(JobManagerException.class);
    assertThat(((JobManagerException) thrown).getErrorCode()).isEqualTo(JobManagerException.ErrorCode.UnexpectedJobState);
}
Also used : JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) AssertionsForClassTypes.catchThrowable(org.assertj.core.api.AssertionsForClassTypes.catchThrowable) Test(org.junit.Test)

Example 2 with JobManagerException

use of com.netflix.titus.api.jobmanager.service.JobManagerException in project titus-control-plane by Netflix.

the class TaskRelocationLimitController method getJobQuota.

private EvictionQuota getJobQuota(Reference jobReference) {
    EvictionQuota.Builder quotaBuilder = EvictionQuota.newBuilder().withReference(jobReference);
    List<Task> tasks;
    try {
        tasks = jobOperations.getTasks(job.getId());
    } catch (JobManagerException e) {
        return quotaBuilder.withQuota(0).withMessage("Internal error: %s", e.getMessage()).build();
    }
    int quota = 0;
    for (Task task : tasks) {
        if (task.getEvictionResubmitNumber() < perTaskLimit) {
            quota++;
        }
    }
    return quota > 0 ? quotaBuilder.withQuota(quota).withMessage("Per task limit is %s", perTaskLimit).build() : quotaBuilder.withQuota(0).withMessage("Each task of the job reached its maximum eviction limit %s", perTaskLimit).build();
}
Also used : EvictionQuota(com.netflix.titus.api.eviction.model.EvictionQuota) Task(com.netflix.titus.api.jobmanager.model.job.Task) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException)

Example 3 with JobManagerException

use of com.netflix.titus.api.jobmanager.service.JobManagerException in project titus-control-plane by Netflix.

the class UnhealthyTasksLimitTracker method countHealthy.

private Pair<Integer, String> countHealthy() {
    List<Task> tasks;
    try {
        tasks = jobOperations.getTasks(job.getId());
    } catch (JobManagerException e) {
        return Pair.of(0, "job not found");
    }
    int healthy = 0;
    Map<String, String> notStartedOrUnhealthyTasks = new HashMap<>();
    for (Task task : tasks) {
        if (task.getStatus().getState() == TaskState.Started) {
            Optional<ContainerHealthStatus> statusOpt = containerHealthService.findHealthStatus(task.getId());
            if (statusOpt.isPresent() && statusOpt.get().getState() == ContainerHealthState.Healthy) {
                healthy++;
            } else {
                String report = statusOpt.map(status -> startWithLowercase(status.getState().name()) + '(' + status.getReason() + ')').orElse("health not found");
                notStartedOrUnhealthyTasks.put(task.getId(), report);
            }
        } else {
            notStartedOrUnhealthyTasks.put(task.getId(), String.format("Not started (current task state=%s)", task.getStatus().getState()));
        }
    }
    if (!notStartedOrUnhealthyTasks.isEmpty()) {
        StringBuilder builder = new StringBuilder("not started and healthy: ");
        builder.append("total=").append(notStartedOrUnhealthyTasks.size());
        builder.append(", tasks=[");
        int counter = 0;
        for (Map.Entry<String, String> entry : notStartedOrUnhealthyTasks.entrySet()) {
            builder.append(entry.getKey()).append('=').append(entry.getValue());
            counter++;
            if (counter < notStartedOrUnhealthyTasks.size()) {
                builder.append(", ");
            } else {
                builder.append("]");
            }
            if (counter >= TASK_ID_REPORT_LIMIT && counter < notStartedOrUnhealthyTasks.size()) {
                builder.append(",... dropped ").append(notStartedOrUnhealthyTasks.size() - counter).append(" tasks]");
            }
        }
        return Pair.of(healthy, builder.toString());
    }
    return Pair.of(healthy, healthy > minimumHealthyCount ? "" : String.format("not enough healthy containers: healthy=%s, minimum=%s", healthy, minimumHealthyCount));
}
Also used : Job(com.netflix.titus.api.jobmanager.model.job.Job) Task(com.netflix.titus.api.jobmanager.model.job.Task) EvictionQuota(com.netflix.titus.api.eviction.model.EvictionQuota) HashMap(java.util.HashMap) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) Reference(com.netflix.titus.api.model.reference.Reference) UnhealthyTasksLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) ContainerHealthState(com.netflix.titus.api.containerhealth.model.ContainerHealthState) List(java.util.List) ContainerHealthStatus(com.netflix.titus.api.containerhealth.model.ContainerHealthStatus) AvailabilityPercentageLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) Pair(com.netflix.titus.common.util.tuple.Pair) QuotaTracker(com.netflix.titus.master.eviction.service.quota.QuotaTracker) Map(java.util.Map) Optional(java.util.Optional) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) StringExt.startWithLowercase(com.netflix.titus.common.util.StringExt.startWithLowercase) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ContainerHealthService(com.netflix.titus.api.containerhealth.service.ContainerHealthService) Task(com.netflix.titus.api.jobmanager.model.job.Task) HashMap(java.util.HashMap) ContainerHealthStatus(com.netflix.titus.api.containerhealth.model.ContainerHealthStatus) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with JobManagerException

use of com.netflix.titus.api.jobmanager.service.JobManagerException 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 5 with JobManagerException

use of com.netflix.titus.api.jobmanager.service.JobManagerException in project titus-control-plane by Netflix.

the class DefaultLoadBalancerJobValidatorTest method testValidateJobExists.

@Test
public void testValidateJobExists() throws Exception {
    when(jobOperations.getJob(JOB_ID)).thenReturn(Optional.empty());
    Throwable thrown = catchThrowable(() -> loadBalancerValidator.validateJobId(JOB_ID));
    assertThat(thrown).isInstanceOf(JobManagerException.class);
    assertThat(((JobManagerException) thrown).getErrorCode()).isEqualTo(JobManagerException.ErrorCode.JobNotFound);
}
Also used : JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) AssertionsForClassTypes.catchThrowable(org.assertj.core.api.AssertionsForClassTypes.catchThrowable) Test(org.junit.Test)

Aggregations

JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)7 Test (org.junit.Test)5 AssertionsForClassTypes.catchThrowable (org.assertj.core.api.AssertionsForClassTypes.catchThrowable)3 EvictionQuota (com.netflix.titus.api.eviction.model.EvictionQuota)2 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)2 Task (com.netflix.titus.api.jobmanager.model.job.Task)2 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)2 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)2 JobScenarioBuilder (com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ContainerHealthState (com.netflix.titus.api.containerhealth.model.ContainerHealthState)1 ContainerHealthStatus (com.netflix.titus.api.containerhealth.model.ContainerHealthStatus)1 ContainerHealthService (com.netflix.titus.api.containerhealth.service.ContainerHealthService)1 Job (com.netflix.titus.api.jobmanager.model.job.Job)1 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)1 AvailabilityPercentageLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy)1 UnhealthyTasksLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy)1 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)1 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)1 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)1