use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class InMemoryPolicyStore method storePolicy.
@Override
public Observable<String> storePolicy(AutoScalingPolicy autoScalingPolicy) {
return Observable.fromCallable(() -> {
String policyRefId = UUID.randomUUID().toString();
AutoScalingPolicy policySaved = AutoScalingPolicy.newBuilder().withAutoScalingPolicy(autoScalingPolicy).withRefId(policyRefId).withStatus(PolicyStatus.Pending).build();
policyMap.putIfAbsent(policyRefId, policySaved);
return policyRefId;
});
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class InMemoryPolicyStore method updatePolicyStatus.
@Override
public Completable updatePolicyStatus(String policyRefId, PolicyStatus policyStatus) {
return Completable.fromCallable(() -> {
log.info("Updating policy status for refID {} -> {}", policyRefId, policyStatus);
AutoScalingPolicy autoScalingPolicy = policyMap.get(policyRefId);
AutoScalingPolicy policySaved = AutoScalingPolicy.newBuilder().withAutoScalingPolicy(autoScalingPolicy).withStatus(policyStatus).build();
return policyMap.put(policyRefId, policySaved);
});
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class DefaultAppScaleManager method createAutoScalingPolicy.
@Override
public Observable<String> createAutoScalingPolicy(AutoScalingPolicy autoScalingPolicy) {
logger.info("Adding new AutoScalingPolicy {}", autoScalingPolicy);
if (autoScalingPolicy.getJobId() == null || autoScalingPolicy.getPolicyConfiguration() == null) {
return Observable.error(AutoScalePolicyException.invalidScalingPolicy(autoScalingPolicy.getRefId(), String.format("JobID Or PolicyConfiguration missing for %s", autoScalingPolicy.getRefId())));
}
return appScalePolicyStore.storePolicy(autoScalingPolicy).map(policyRefId -> {
addScalableTargetIfNew(autoScalingPolicy.getJobId());
AutoScalingPolicy newPolicy = AutoScalingPolicy.newBuilder().withAutoScalingPolicy(autoScalingPolicy).withRefId(policyRefId).build();
sendCreatePolicyAction(newPolicy);
metrics.reportPolicyStatusTransition(newPolicy, PolicyStatus.Pending);
return policyRefId;
});
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class DefaultAppScaleManager method saveStatusOnError.
private Completable saveStatusOnError(Throwable e) {
Optional<AutoScalePolicyException> autoScalePolicyExceptionOpt = extractAutoScalePolicyException(e);
if (!autoScalePolicyExceptionOpt.isPresent()) {
return Completable.complete();
}
logger.info("Saving AutoScalePolicyException", autoScalePolicyExceptionOpt.get());
AutoScalePolicyException autoScalePolicyException = autoScalePolicyExceptionOpt.get();
if (autoScalePolicyException.getPolicyRefId() != null && !autoScalePolicyException.getPolicyRefId().isEmpty()) {
metrics.reportErrorForException(autoScalePolicyException);
String statusMessage = String.format("%s - %s", autoScalePolicyException.getErrorCode(), autoScalePolicyException.getMessage());
AutoScalingPolicy autoScalingPolicy = AutoScalingPolicy.newBuilder().withRefId(autoScalePolicyException.getPolicyRefId()).build();
if (autoScalePolicyException.getErrorCode() == AutoScalePolicyException.ErrorCode.UnknownScalingPolicy) {
metrics.reportPolicyStatusTransition(autoScalingPolicy, PolicyStatus.Deleted);
return appScalePolicyStore.updateStatusMessage(autoScalePolicyException.getPolicyRefId(), statusMessage).andThen(appScalePolicyStore.updatePolicyStatus(autoScalePolicyException.getPolicyRefId(), PolicyStatus.Deleted));
} else if (isPolicyCreationError(autoScalePolicyException)) {
metrics.reportPolicyStatusTransition(autoScalingPolicy, PolicyStatus.Error);
return appScalePolicyStore.updateStatusMessage(autoScalePolicyException.getPolicyRefId(), statusMessage).andThen(appScalePolicyStore.updatePolicyStatus(autoScalePolicyException.getPolicyRefId(), PolicyStatus.Error));
} else {
return appScalePolicyStore.updateStatusMessage(autoScalePolicyException.getPolicyRefId(), statusMessage);
}
} else {
return Completable.complete();
}
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class CassAppScalePolicyStoreTest method verifyStoreInit.
@Test
public void verifyStoreInit() throws Exception {
Session session = cassandraCQLUnit.getSession();
loadTestData();
CassAppScalePolicyStore store = new CassAppScalePolicyStore(session, configuration, new DefaultRegistry());
store.init().await();
List<AutoScalingPolicy> allPolicies = store.retrievePolicies(false).toList().toBlocking().first();
Assertions.assertThat(allPolicies.size()).isEqualTo(3);
List<AutoScalingPolicy> jobOnePolicies = store.retrievePoliciesForJob("job-1").toList().toBlocking().first();
Assertions.assertThat(jobOnePolicies.size()).isEqualTo(2);
List<String> refIdList = jobOnePolicies.stream().map(as -> as.getRefId()).collect(Collectors.toList());
Assertions.assertThat(refIdList).containsOnly(POLICY_1_ID, POLICY_3_ID);
List<AutoScalingPolicy> jobTwoPolicies = store.retrievePoliciesForJob("job-2").toList().toBlocking().first();
Assertions.assertThat(jobTwoPolicies.size()).isEqualTo(1);
List<String> jobTwoRefIdList = jobTwoPolicies.stream().map(as -> as.getRefId()).collect(Collectors.toList());
Assertions.assertThat(jobTwoRefIdList).isEqualTo(Arrays.asList(POLICY_2_ID));
// verify metric lower/upper bounds
List<StepAdjustment> stepAdjustments = jobTwoPolicies.stream().flatMap(as -> as.getPolicyConfiguration().getStepScalingPolicyConfiguration().getSteps().stream()).collect(Collectors.toList());
Assertions.assertThat(stepAdjustments.size()).isEqualTo(1);
Assertions.assertThat(stepAdjustments.get(0).getMetricIntervalUpperBound()).isEqualTo(Optional.empty());
Assertions.assertThat(stepAdjustments.get(0).getMetricIntervalLowerBound().get()).isEqualTo(Double.valueOf(0));
}
Aggregations