Search in sources :

Example 1 with JobGroupInfo

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;
}
Also used : V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 2 with JobGroupInfo

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;
}
Also used : V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 3 with JobGroupInfo

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");
}
Also used : JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) Test(org.junit.Test)

Example 4 with JobGroupInfo

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);
}
Also used : JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) AutoScalingGroupNameBuilder(com.netflix.frigga.autoscaling.AutoScalingGroupNameBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with JobGroupInfo

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;
}
Also used : JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo)

Aggregations

JobGroupInfo (com.netflix.titus.api.jobmanager.model.job.JobGroupInfo)7 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)3 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)3 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)3 Container (com.netflix.titus.api.jobmanager.model.job.Container)2 ContainerResources (com.netflix.titus.api.jobmanager.model.job.ContainerResources)2 Job (com.netflix.titus.api.jobmanager.model.job.Job)2 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AutoScalingGroupNameBuilder (com.netflix.frigga.autoscaling.AutoScalingGroupNameBuilder)1 BasicContainer (com.netflix.titus.api.jobmanager.model.job.BasicContainer)1 Image (com.netflix.titus.api.jobmanager.model.job.Image)1 JobStatus (com.netflix.titus.api.jobmanager.model.job.JobStatus)1 SecurityProfile (com.netflix.titus.api.jobmanager.model.job.SecurityProfile)1 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)1 V1Container (io.kubernetes.client.openapi.models.V1Container)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1