use of com.netflix.titus.api.jobmanager.model.job.JobGroupInfo in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method mockV3Operations.
private V3JobOperations mockV3Operations(String jobIdOne, String jobIdTwo) {
V3JobOperations v3JobOperations = mock(V3JobOperations.class);
// FIXME Use JobGenerator instead of mocking.
Job jobOne = mock(Job.class);
when(jobOne.getId()).thenReturn(jobIdOne);
JobDescriptor jobDescriptorOne = mock(JobDescriptor.class);
ServiceJobExt serviceJobExtOne = mock(ServiceJobExt.class);
JobGroupInfo jobGroupInfoOne = buildMockJobGroupInfo(jobIdOne);
Capacity capacityOne = mock(Capacity.class);
when(capacityOne.getMax()).thenReturn(10);
when(capacityOne.getMin()).thenReturn(1);
when(serviceJobExtOne.getCapacity()).thenReturn(capacityOne);
when(jobDescriptorOne.getExtensions()).thenReturn(serviceJobExtOne);
when(jobOne.getJobDescriptor()).thenReturn(jobDescriptorOne);
when(jobDescriptorOne.getJobGroupInfo()).thenReturn(jobGroupInfoOne);
when(jobDescriptorOne.getApplicationName()).thenReturn("testApp1");
Job jobTwo = mock(Job.class);
when(jobTwo.getId()).thenReturn(jobIdTwo);
JobDescriptor jobDescriptorTwo = mock(JobDescriptor.class);
ServiceJobExt serviceJobExtTwo = mock(ServiceJobExt.class);
Capacity capacityJobTwo = mock(Capacity.class);
when(capacityJobTwo.getMin()).thenAnswer(new Answer<Integer>() {
private int count = 0;
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
if (count++ < 2) {
return 1;
} else {
return 5;
}
}
});
when(capacityJobTwo.getMax()).thenAnswer(new Answer<Integer>() {
private int count = 0;
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
if (count++ < 2) {
return 10;
} else {
return 15;
}
}
});
when(serviceJobExtTwo.getCapacity()).thenReturn(capacityJobTwo);
when(jobDescriptorTwo.getExtensions()).thenReturn(serviceJobExtTwo);
when(jobDescriptorTwo.getJobGroupInfo()).thenReturn(jobGroupInfoOne);
when(jobDescriptorTwo.getApplicationName()).thenReturn("testApp2");
when(jobTwo.getJobDescriptor()).thenReturn(jobDescriptorTwo);
when(jobTwo.getStatus()).thenReturn(JobModel.newJobStatus().withState(JobState.Accepted).build());
when(v3JobOperations.getJob(jobIdOne)).thenReturn(Optional.of(jobOne));
when(v3JobOperations.getJob(jobIdTwo)).thenReturn(Optional.of(jobTwo));
JobManagerEvent<?> jobUpdateEvent = JobUpdateEvent.newJob(jobTwo, callMetadata);
when(v3JobOperations.observeJobs()).thenAnswer(invocation -> Observable.from(asList(jobUpdateEvent)));
return v3JobOperations;
}
use of com.netflix.titus.api.jobmanager.model.job.JobGroupInfo in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method mockV3OperationsForJobs.
private V3JobOperations mockV3OperationsForJobs(List<String> jobIds) {
V3JobOperations v3JobOperations = mock(V3JobOperations.class);
for (String jobId : jobIds) {
// FIXME Use JobGenerator instead of mocking.
Job job = mock(Job.class);
when(job.getId()).thenReturn(jobId);
JobDescriptor jobDescriptorOne = mock(JobDescriptor.class);
ServiceJobExt serviceJobExtOne = mock(ServiceJobExt.class);
JobGroupInfo jobGroupInfoOne = buildMockJobGroupInfo(jobId);
Capacity capacityOne = mock(Capacity.class);
when(capacityOne.getMax()).thenReturn(10);
when(capacityOne.getMin()).thenReturn(1);
when(serviceJobExtOne.getCapacity()).thenReturn(capacityOne);
when(jobDescriptorOne.getExtensions()).thenReturn(serviceJobExtOne);
when(job.getJobDescriptor()).thenReturn(jobDescriptorOne);
when(jobDescriptorOne.getJobGroupInfo()).thenReturn(jobGroupInfoOne);
when(jobDescriptorOne.getApplicationName()).thenReturn("testApp");
when(v3JobOperations.getJob(jobId)).thenReturn(Optional.of(job));
JobManagerEvent<?> jobUpdateEvent = JobUpdateEvent.newJob(job, callMetadata);
when(v3JobOperations.observeJobs()).thenAnswer(invocation -> Observable.from(asList(jobUpdateEvent)));
}
return v3JobOperations;
}
use of com.netflix.titus.api.jobmanager.model.job.JobGroupInfo in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method checkASGNameBuildingV3.
@Test
public void checkASGNameBuildingV3() {
JobGroupInfo jobGroupInfoOne = JobGroupInfo.newBuilder().withDetail("^1.0.0").withSequence("v001").withStack("main").build();
JobDescriptor<JobDescriptor.JobDescriptorExt> jobDescriptorOne = JobDescriptor.newBuilder().withApplicationName("testapp").withJobGroupInfo(jobGroupInfoOne).build();
String autoScalingGroup = DefaultAppScaleManager.buildAutoScalingGroupV3(jobDescriptorOne);
Assertions.assertThat(autoScalingGroup).isEqualTo("testapp-main-^1.0.0-v001");
JobGroupInfo jobGroupInfoTwo = JobGroupInfo.newBuilder().withDetail("^1.0.0").withStack("main").build();
JobDescriptor<JobDescriptor.JobDescriptorExt> jobDescriptorTwo = JobDescriptor.newBuilder().withApplicationName("testapp").withJobGroupInfo(jobGroupInfoTwo).build();
autoScalingGroup = DefaultAppScaleManager.buildAutoScalingGroupV3(jobDescriptorTwo);
Assertions.assertThat(autoScalingGroup).isEqualTo("testapp-main-^1.0.0-v000");
JobGroupInfo jobGroupInfoThree = JobGroupInfo.newBuilder().withDetail("^1.0.0").build();
JobDescriptor<JobDescriptor.JobDescriptorExt> jobDescriptorThree = JobDescriptor.newBuilder().withApplicationName("testapp").withJobGroupInfo(jobGroupInfoThree).build();
autoScalingGroup = DefaultAppScaleManager.buildAutoScalingGroupV3(jobDescriptorThree);
Assertions.assertThat(autoScalingGroup).isEqualTo("testapp--^1.0.0-v000");
JobGroupInfo jobGroupInfoFour = JobGroupInfo.newBuilder().build();
JobDescriptor<JobDescriptor.JobDescriptorExt> jobDescriptorFour = JobDescriptor.newBuilder().withApplicationName("testapp").withJobGroupInfo(jobGroupInfoFour).build();
autoScalingGroup = DefaultAppScaleManager.buildAutoScalingGroupV3(jobDescriptorFour);
Assertions.assertThat(autoScalingGroup).isEqualTo("testapp-v000");
JobGroupInfo jobGroupInfoFive = JobGroupInfo.newBuilder().withDetail("titus").withSequence("v038").build();
JobDescriptor<JobDescriptor.JobDescriptorExt> jobDescriptorFive = JobDescriptor.newBuilder().withApplicationName("tbd").withJobGroupInfo(jobGroupInfoFive).build();
autoScalingGroup = DefaultAppScaleManager.buildAutoScalingGroupV3(jobDescriptorFive);
Assertions.assertThat(autoScalingGroup).isEqualTo("tbd--titus-v038");
}
use of com.netflix.titus.api.jobmanager.model.job.JobGroupInfo in project titus-control-plane by Netflix.
the class DefaultAppScaleManager method buildAutoScalingGroupV3.
@VisibleForTesting
static String buildAutoScalingGroupV3(JobDescriptor<?> jobDescriptor) {
JobGroupInfo jobGroupInfo = jobDescriptor.getJobGroupInfo();
String jobGroupSequence = jobGroupInfo.getSequence() != null ? jobGroupInfo.getSequence() : DEFAULT_JOB_GROUP_SEQ;
// Using frigga builder for auto scaling group name so that cloud watch alarm configuration
// is compatible with spinnaker generated auto scaling group name that is tagged with cloud watch metrics
AutoScalingGroupNameBuilder autoScalingGroupNameBuilder = new AutoScalingGroupNameBuilder();
String asgWithNoSequence = autoScalingGroupNameBuilder.withAppName(jobDescriptor.getApplicationName()).withStack(jobGroupInfo.getStack()).withDetail(jobGroupInfo.getDetail()).buildGroupName();
return String.format("%s-%s", asgWithNoSequence, jobGroupSequence);
}
use of com.netflix.titus.api.jobmanager.model.job.JobGroupInfo in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method buildMockJobGroupInfo.
private JobGroupInfo buildMockJobGroupInfo(String jobId) {
JobGroupInfo jobGroupInfo = mock(JobGroupInfo.class);
when(jobGroupInfo.getDetail()).thenReturn("ii" + jobId);
when(jobGroupInfo.getStack()).thenReturn("test");
when(jobGroupInfo.getSequence()).thenReturn("001");
return jobGroupInfo;
}
Aggregations