Search in sources :

Example 1 with InMemoryPolicyStore

use of com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore 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 InMemoryPolicyStore

use of com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore in project titus-control-plane by Netflix.

the class DefaultAppScaleManagerTest method submitTwoJobs.

private List<String> submitTwoJobs(DefaultAppScaleManager appScaleManager, String jobIdOne, String jobIdTwo, InMemoryPolicyStore policyStore) throws Exception {
    // call - createAutoScalingPolicy
    AutoScalingPolicy autoScalingPolicyOne = AutoScalingPolicyTests.buildStepScalingPolicy(jobIdOne);
    appScaleManager.createAutoScalingPolicy(autoScalingPolicyOne).toBlocking().single();
    // call - createAutoScalingPolicy
    AutoScalingPolicy autoScalingPolicyTwo = AutoScalingPolicyTests.buildStepScalingPolicy(jobIdTwo);
    appScaleManager.createAutoScalingPolicy(autoScalingPolicyTwo).toBlocking().single();
    // call - processPendingPolicies
    List<AutoScalingPolicy> savedPolicies = policyStore.retrievePolicies(false).toList().toBlocking().first();
    AutoScalingPolicyTests.waitForCondition(() -> savedPolicies.size() == 2);
    Assertions.assertThat(savedPolicies.size()).isEqualTo(2);
    return savedPolicies.stream().map(policy -> policy.getRefId()).collect(Collectors.toList());
}
Also used : AutoScalePolicyException(com.netflix.titus.api.appscale.service.AutoScalePolicyException) Completable(rx.Completable) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) LoggerFactory(org.slf4j.LoggerFactory) AutoScalableTarget(com.netflix.titus.api.appscale.model.AutoScalableTarget) ArrayList(java.util.ArrayList) Observable(rx.Observable) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) Schedulers(rx.schedulers.Schedulers) Assertions(org.assertj.core.api.Assertions) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Job(com.netflix.titus.api.jobmanager.model.job.Job) Logger(org.slf4j.Logger) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Awaitility.await(com.jayway.awaitility.Awaitility.await) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) Collectors(java.util.stream.Collectors) PolicyType(com.netflix.titus.api.appscale.model.PolicyType) InMemoryPolicyStore(com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Optional(java.util.Optional) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Mockito.mock(org.mockito.Mockito.mock) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy)

Example 3 with InMemoryPolicyStore

use of com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore in project titus-control-plane by Netflix.

the class DefaultAppScaleManagerTest method checkBulkPolicyCreations.

@Test
public void checkBulkPolicyCreations() {
    AutoScalingPolicyTests.MockAlarmClient mockAlarmClient = new AutoScalingPolicyTests.MockAlarmClient();
    AutoScalingPolicyTests.MockAppAutoScalingClient mockAppAutoScalingClient = new AutoScalingPolicyTests.MockAppAutoScalingClient();
    InMemoryPolicyStore policyStore = new InMemoryPolicyStore();
    final int totalJobs = 300;
    List<String> jobIds = new ArrayList<>(totalJobs);
    for (int i = 0; i < totalJobs; i++) {
        String jobId = UUID.randomUUID().toString();
        jobIds.add(jobId);
    }
    V3JobOperations v3JobOperations = mockV3OperationsForJobs(jobIds);
    DefaultAppScaleManager appScaleManager = new DefaultAppScaleManager(policyStore, mockAlarmClient, mockAppAutoScalingClient, v3JobOperations, new DefaultRegistry(), AutoScalingPolicyTests.mockAppScaleManagerConfiguration(), Schedulers.computation(), mock(TitusRuntime.class));
    final CountDownLatch latch = new CountDownLatch(totalJobs);
    for (int i = 0; i < totalJobs; i++) {
        final AutoScalingPolicy autoScalingPolicy = AutoScalingPolicyTests.buildStepScalingPolicy(jobIds.get(i));
        appScaleManager.createAutoScalingPolicy(autoScalingPolicy).subscribe(pid -> {
            log.info("Policy created {}", pid);
            latch.countDown();
        });
    }
    await().timeout(30, TimeUnit.SECONDS).until(() -> mockAppAutoScalingClient.getNumPolicies() == totalJobs);
}
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) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Test(org.junit.Test)

Example 4 with InMemoryPolicyStore

use of com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore in project titus-control-plane by Netflix.

the class DefaultAppScaleManagerTest method checkCreatePolicyFlow.

private void checkCreatePolicyFlow(PolicyType policyType) throws Exception {
    // create instance of DefaultAppScaleManager
    AutoScalingPolicyTests.MockAlarmClient mockAlarmClient = new AutoScalingPolicyTests.MockAlarmClient();
    AutoScalingPolicyTests.MockAppAutoScalingClient mockAppAutoScalingClient = new AutoScalingPolicyTests.MockAppAutoScalingClient();
    InMemoryPolicyStore policyStore = new InMemoryPolicyStore();
    String jobIdOne = UUID.randomUUID().toString();
    String jobIdTwo = UUID.randomUUID().toString();
    V3JobOperations v3JobOperations = mockV3Operations(jobIdOne, jobIdTwo);
    DefaultAppScaleManager appScaleManager = new DefaultAppScaleManager(policyStore, mockAlarmClient, mockAppAutoScalingClient, v3JobOperations, new DefaultRegistry(), AutoScalingPolicyTests.mockAppScaleManagerConfiguration(), Schedulers.immediate(), mock(TitusRuntime.class));
    AutoScalingPolicy autoScalingPolicyOne;
    AutoScalingPolicy autoScalingPolicyTwo;
    if (policyType == PolicyType.StepScaling) {
        autoScalingPolicyOne = AutoScalingPolicyTests.buildStepScalingPolicy(jobIdOne);
        autoScalingPolicyTwo = AutoScalingPolicyTests.buildStepScalingPolicy(jobIdTwo);
    } else {
        autoScalingPolicyOne = AutoScalingPolicyTests.buildTargetTrackingPolicy(jobIdOne);
        autoScalingPolicyTwo = AutoScalingPolicyTests.buildTargetTrackingPolicy(jobIdTwo);
    }
    // call - createAutoScalingPolicy
    appScaleManager.createAutoScalingPolicy(autoScalingPolicyOne).toBlocking().single();
    String policyRefIdTwo = appScaleManager.createAutoScalingPolicy(autoScalingPolicyTwo).toBlocking().single();
    AutoScalingPolicyTests.waitForCondition(() -> {
        List<AutoScalingPolicy> policies = policyStore.retrievePolicies(false).toList().toBlocking().first();
        return policies.size() == 2 && mockAppAutoScalingClient.getNumPolicies() == 2 && mockAppAutoScalingClient.getNumScalableTargets() == 2;
    });
    // verify counts in CloudAlarmClient, AppAutoScaleClient and AppScalePolicyStore
    List<AutoScalingPolicy> policiesStored = policyStore.retrievePolicies(false).toList().toBlocking().first();
    Assertions.assertThat(policiesStored.size()).isEqualTo(2);
    Assertions.assertThat(mockAppAutoScalingClient.getNumPolicies()).isEqualTo(2);
    Assertions.assertThat(mockAppAutoScalingClient.getNumScalableTargets()).isEqualTo(2);
    if (policyType == PolicyType.StepScaling) {
        Assertions.assertThat(mockAlarmClient.getNumOfAlarmsCreated()).isEqualTo(2);
    }
    appScaleManager.removeAutoScalingPolicy(policyRefIdTwo).await();
    AutoScalingPolicyTests.waitForCondition(() -> {
        List<AutoScalingPolicy> policies = policyStore.retrievePolicies(false).toList().toBlocking().first();
        return policies.size() == 1 && mockAppAutoScalingClient.getNumPolicies() == 1 && mockAppAutoScalingClient.getNumScalableTargets() == 1;
    });
    // verify counts in CloudAlarmClient, AppAutoScaleClient and AppScalePolicyStore
    policiesStored = policyStore.retrievePolicies(false).toList().toBlocking().first();
    Assertions.assertThat(policiesStored.size()).isEqualTo(1);
    Assertions.assertThat(mockAppAutoScalingClient.getNumPolicies()).isEqualTo(1);
    Assertions.assertThat(mockAppAutoScalingClient.getNumScalableTargets()).isEqualTo(1);
    if (policyType == PolicyType.StepScaling) {
        Assertions.assertThat(mockAlarmClient.getNumOfAlarmsCreated()).isEqualTo(1);
    }
}
Also used : V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) InMemoryPolicyStore(com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry)

Aggregations

DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)4 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)4 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)4 InMemoryPolicyStore (com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore)4 AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 Awaitility.await (com.jayway.awaitility.Awaitility.await)1 AutoScalableTarget (com.netflix.titus.api.appscale.model.AutoScalableTarget)1 PolicyType (com.netflix.titus.api.appscale.model.PolicyType)1 AutoScalePolicyException (com.netflix.titus.api.appscale.service.AutoScalePolicyException)1 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)1 Job (com.netflix.titus.api.jobmanager.model.job.Job)1 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)1 JobGroupInfo (com.netflix.titus.api.jobmanager.model.job.JobGroupInfo)1 JobModel (com.netflix.titus.api.jobmanager.model.job.JobModel)1 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)1 JobManagerEvent (com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent)1 JobUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent)1