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);
}
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();
}
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));
}
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");
}
}
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);
}
Aggregations