use of com.netflix.titus.api.appscale.model.AutoScalingPolicy 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());
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy 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);
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy 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);
}
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class InMemoryPolicyStore method updateStatusMessage.
@Override
public Completable updateStatusMessage(String policyRefId, String statusMessage) {
return Completable.fromCallable(() -> {
AutoScalingPolicy autoScalingPolicy = policyMap.get(policyRefId);
AutoScalingPolicy policySaved = AutoScalingPolicy.newBuilder().withAutoScalingPolicy(autoScalingPolicy).withStatusMessage(statusMessage).build();
return policyMap.put(policyRefId, policySaved);
});
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class InMemoryPolicyStore method updatePolicyId.
@Override
public Completable updatePolicyId(String policyRefId, String policyId) {
return Completable.fromCallable(() -> {
AutoScalingPolicy autoScalingPolicy = policyMap.get(policyRefId);
AutoScalingPolicy policySaved = AutoScalingPolicy.newBuilder().withAutoScalingPolicy(autoScalingPolicy).withPolicyId(policyId).build();
return policyMap.put(policyRefId, policySaved);
});
}
Aggregations