use of com.netflix.titus.api.jobmanager.service.V3JobOperations in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method checkV3LiveStreamTargetUpdates.
@Test
public void checkV3LiveStreamTargetUpdates() throws Exception {
String jobIdOne = UUID.randomUUID().toString();
String jobIdTwo = UUID.randomUUID().toString();
InMemoryPolicyStore policyStore = new InMemoryPolicyStore();
V3JobOperations v3JobOperations = mockV3Operations(jobIdOne, jobIdTwo);
AppScaleClientWithScalingPolicyConstraints appScalingClient = new AppScaleClientWithScalingPolicyConstraints();
DefaultAppScaleManager appScaleManager = new DefaultAppScaleManager(policyStore, new AutoScalingPolicyTests.MockAlarmClient(), appScalingClient, v3JobOperations, new DefaultRegistry(), AutoScalingPolicyTests.mockAppScaleManagerConfiguration(), Schedulers.immediate(), mock(TitusRuntime.class));
List<String> refIds = submitTwoJobs(appScaleManager, jobIdOne, jobIdTwo, policyStore);
Assertions.assertThat(refIds.size()).isEqualTo(2);
CountDownLatch latch = new CountDownLatch(1);
Observable<String> jobIdTargetUpdates = appScaleManager.v3LiveStreamTargetUpdates();
List<String> targetsUpdated = new ArrayList<>();
jobIdTargetUpdates.subscribe(targetUpdated -> {
log.info("Got ScalableTarget to be updated {}", targetUpdated);
Assertions.assertThat(targetUpdated).isEqualTo(jobIdTwo);
targetsUpdated.add(targetUpdated);
latch.countDown();
}, e -> log.error("Error in v2 live stream for scalable target update", e), () -> log.info("Completed"));
latch.await(60, TimeUnit.SECONDS);
AutoScalingPolicyTests.waitForCondition(() -> {
JobScalingConstraints jpc = appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo);
return jpc != null && jpc.getMinCapacity() == 5 && jpc.getMaxCapacity() == 15;
});
Assertions.assertThat(targetsUpdated.size()).isEqualTo(1);
Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdOne).getMinCapacity()).isEqualTo(1);
Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdOne).getMaxCapacity()).isEqualTo(10);
Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo).getMinCapacity()).isEqualTo(5);
Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo).getMaxCapacity()).isEqualTo(15);
}
use of com.netflix.titus.api.jobmanager.service.V3JobOperations 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.service.V3JobOperations 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.service.V3JobOperations in project titus-control-plane by Netflix.
the class DefaultLoadBalancerReconcilerTest method setUp.
@Before
public void setUp() throws Exception {
loadBalancerId = UUID.randomUUID().toString();
jobId = UUID.randomUUID().toString();
delayMs = 60_000L;
/* 1 min */
store = new InMemoryLoadBalancerStore();
connector = mock(LoadBalancerConnector.class);
when(connector.getLoadBalancer(loadBalancerId)).thenReturn(Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, Collections.emptySet())));
v3JobOperations = mock(V3JobOperations.class);
testScheduler = Schedulers.test();
reconciliationCount = new AtomicLong(0);
reconciler = new DefaultLoadBalancerReconciler(mockConfigWithDelay(delayMs), store, connector, new LoadBalancerJobOperations(v3JobOperations), () -> reconciliationCount.incrementAndGet(), new NoopRegistry(), testScheduler);
subscriber = reconciler.events().test();
}
use of com.netflix.titus.api.jobmanager.service.V3JobOperations in project titus-control-plane by Netflix.
the class DefaultLoadBalancerServiceTest method setUp.
@Before
public void setUp() throws Exception {
runtime = TitusRuntimes.internal();
client = mock(LoadBalancerConnector.class);
loadBalancerStore = new InMemoryLoadBalancerStore();
reconciler = mock(LoadBalancerReconciler.class);
reconcilerEvents = PublishSubject.create();
when(reconciler.events()).thenReturn(reconcilerEvents.toSerialized());
v3JobOperations = mock(V3JobOperations.class);
loadBalancerJobOperations = new LoadBalancerJobOperations(v3JobOperations);
LoadBalancerValidationConfiguration validationConfiguration = LoadBalancerTests.mockValidationConfig(30);
validator = new DefaultLoadBalancerJobValidator(v3JobOperations, loadBalancerStore, validationConfiguration);
testScheduler = Schedulers.test();
}
Aggregations