Search in sources :

Example 1 with V3JobOperations

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);
}
Also used : V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) ArrayList(java.util.ArrayList) InMemoryPolicyStore(com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Test(org.junit.Test)

Example 2 with V3JobOperations

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;
}
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 3 with 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;
}
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 4 with 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();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) InMemoryLoadBalancerStore(com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) NoopRegistry(com.netflix.spectator.api.NoopRegistry) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) Before(org.junit.Before)

Example 5 with V3JobOperations

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();
}
Also used : LoadBalancerValidationConfiguration(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerValidationConfiguration) LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) InMemoryLoadBalancerStore(com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) DefaultLoadBalancerJobValidator(com.netflix.titus.api.loadbalancer.model.sanitizer.DefaultLoadBalancerJobValidator) Before(org.junit.Before)

Aggregations

V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)20 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)16 LoadBalancerConnector (com.netflix.titus.api.connector.cloud.LoadBalancerConnector)14 InMemoryLoadBalancerStore (com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 LoadBalancer (com.netflix.titus.api.connector.cloud.LoadBalancer)12 Task (com.netflix.titus.api.jobmanager.model.job.Task)12 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)12 JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)12 DefaultLoadBalancerJobValidator (com.netflix.titus.api.loadbalancer.model.sanitizer.DefaultLoadBalancerJobValidator)12 LoadBalancerJobValidator (com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerJobValidator)12 LoadBalancerValidationConfiguration (com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerValidationConfiguration)12 LoadBalancerStore (com.netflix.titus.api.loadbalancer.store.LoadBalancerStore)12 TitusRuntimes (com.netflix.titus.common.runtime.TitusRuntimes)12 List (java.util.List)12 Set (java.util.Set)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 TaskAttributes (com.netflix.titus.api.jobmanager.TaskAttributes)11 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)11