use of com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt in project titus-control-plane by Netflix.
the class DefaultLoadBalancerJobValidator method validateJobId.
@Override
public void validateJobId(String jobId) throws LoadBalancerException, JobManagerException {
// Job must exist
Job job = v3JobOperations.getJob(jobId).orElseThrow(() -> JobManagerException.v3JobNotFound(jobId));
// Job must be active
JobState state = job.getStatus().getState();
if (state != JobState.Accepted) {
throw JobManagerException.unexpectedJobState(job, JobState.Accepted);
}
// Must be a service job
JobDescriptor.JobDescriptorExt extensions = job.getJobDescriptor().getExtensions();
if (!(extensions instanceof ServiceJobExt)) {
throw JobManagerException.notServiceJob(jobId);
}
// Job should have less than max current load balancer associations
int maxLoadBalancers = loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob();
int numLoadBalancers = loadBalancerStore.getNumLoadBalancersForJob(jobId);
if (numLoadBalancers > maxLoadBalancers) {
throw LoadBalancerException.jobMaxLoadBalancers(jobId, numLoadBalancers, maxLoadBalancers);
}
}
use of com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt in project titus-control-plane by Netflix.
the class CachedServiceJobTest method testAddTask.
@Test
public void testAddTask() {
PCollectionJobSnapshot initialSnapshot = initialSnapshot(2, false);
// Empty
CachedJob cached1 = CollectionsExt.first(initialSnapshot.cachedJobsById.values());
assertThat(cached1.getTasks()).hasSize(2);
// One task
Task extraTask = newServiceTask((Job<ServiceJobExt>) cached1.getJob(), 3);
PCollectionJobSnapshot withThreeTasks = (PCollectionJobSnapshot) cached1.updateTask(initialSnapshot, extraTask).orElse(null);
CachedJob cached2 = CollectionsExt.first(withThreeTasks.cachedJobsById.values());
assertThat(cached2.getTasks()).hasSize(3);
assertThat(cached2.getTasks()).containsValue(extraTask);
}
use of com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt in project titus-control-plane by Netflix.
the class CassandraJobStoreTest method testMoveTask.
@Test
public void testMoveTask() {
JobStore store = getJobStore();
store.init().await();
Job<ServiceJobExt> jobFrom = createServiceJobObject();
store.storeJob(jobFrom).await();
Job<ServiceJobExt> jobTo = createServiceJobObject();
store.storeJob(jobTo).await();
Task task = createServiceTaskObject(jobFrom);
store.storeTask(task).await();
Job<ServiceJobExt> updatedFromJob = JobFunctions.incrementJobSize(jobFrom, -1);
Job<ServiceJobExt> updatedToJob = JobFunctions.incrementJobSize(jobTo, 1);
Task updatedTask = task.toBuilder().withJobId(updatedToJob.getId()).build();
store.moveTask(updatedFromJob, updatedToJob, updatedTask).await();
// Load jobFrom from store
Job<?> jobFromLoaded = store.retrieveJob(jobFrom.getId()).toBlocking().first();
assertThat(JobFunctions.getJobDesiredSize(jobFromLoaded)).isEqualTo(0);
Pair<List<Task>, Integer> jobFromTasksLoaded = store.retrieveTasksForJob(jobFrom.getId()).toBlocking().first();
assertThat(jobFromTasksLoaded.getLeft()).hasSize(0);
// Load jobTo from store
Job<?> jobToLoaded = store.retrieveJob(jobTo.getId()).toBlocking().first();
assertThat(JobFunctions.getJobDesiredSize(jobToLoaded)).isEqualTo(2);
Pair<List<Task>, Integer> jobToTasksLoaded = store.retrieveTasksForJob(jobTo.getId()).toBlocking().first();
assertThat(jobToTasksLoaded.getLeft()).hasSize(1);
jobToTasksLoaded.getLeft().forEach(t -> assertThat(t.getJobId()).isEqualTo(jobTo.getId()));
}
use of com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt in project titus-control-plane by Netflix.
the class CassandraJobStoreTest method createServiceJobObject.
private Job<ServiceJobExt> createServiceJobObject() {
ExponentialBackoffRetryPolicy exponential = JobModel.newExponentialBackoffRetryPolicy().withInitialDelayMs(10).withMaxDelayMs(100).withRetries(5).build();
JobDescriptor<ServiceJobExt> jobDescriptor = JobDescriptorGenerator.oneTaskServiceJobDescriptor().but(jd -> jd.getExtensions().toBuilder().withRetryPolicy(exponential).build());
return JobGenerator.serviceJobs(jobDescriptor).getValue();
}
use of com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt in project titus-control-plane by Netflix.
the class CassandraJobStoreTest method createServiceJobWithPlatformSidecarsObject.
/**
* createServiceJobWithPlatformSidecarsObject is an extra strenuous test for the CassandraJobStore
* suite, as it exercises all the things needed to ensure that the complex arguments field
* is properly serialized correctly.
*/
private Job<ServiceJobExt> createServiceJobWithPlatformSidecarsObject() {
Struct.Builder args = Struct.newBuilder();
args.putFields("foo", Value.newBuilder().setStringValue("bar").build());
args.putFields("baz", Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());
args.putFields("num", Value.newBuilder().setNumberValue(42.0).build());
PlatformSidecar ps1 = PlatformSidecar.newBuilder().withName("testSidecar").withChannel("testChannel").withArguments("{\"foo\":true,\"bar\":3.0}").build();
List<PlatformSidecar> platformSidecars = Collections.singletonList(ps1);
JobDescriptor<ServiceJobExt> jobDescriptor = JobDescriptorGenerator.oneTaskServiceJobDescriptor().but(jd -> jd.toBuilder().withPlatformSidecars(platformSidecars).build());
return JobGenerator.serviceJobs(jobDescriptor).getValue();
}
Aggregations