Search in sources :

Example 16 with AutoScalingPolicy

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;
    });
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy)

Example 17 with AutoScalingPolicy

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);
    });
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy)

Example 18 with AutoScalingPolicy

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;
    });
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy)

Example 19 with AutoScalingPolicy

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();
    }
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) AutoScalePolicyException(com.netflix.titus.api.appscale.service.AutoScalePolicyException)

Example 20 with AutoScalingPolicy

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));
}
Also used : Arrays(java.util.Arrays) StepAdjustmentType(com.netflix.titus.api.appscale.model.StepAdjustmentType) Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) ComparisonOperator(com.netflix.titus.api.appscale.model.ComparisonOperator) CassandraCQLUnit(org.cassandraunit.CassandraCQLUnit) Observable(rx.Observable) PreparedStatement(com.datastax.driver.core.PreparedStatement) ResultSet(com.datastax.driver.core.ResultSet) BoundStatement(com.datastax.driver.core.BoundStatement) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) Session(com.datastax.driver.core.Session) ClassPathCQLDataSet(org.cassandraunit.dataset.cql.ClassPathCQLDataSet) Assertions(org.assertj.core.api.Assertions) PolicyStatus(com.netflix.titus.api.appscale.model.PolicyStatus) Before(org.junit.Before) AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) MetricAggregationType(com.netflix.titus.api.appscale.model.MetricAggregationType) Logger(org.slf4j.Logger) Test(org.junit.Test) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) PolicyType(com.netflix.titus.api.appscale.model.PolicyType) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration) Statistic(com.netflix.titus.api.appscale.model.Statistic) List(java.util.List) StepAdjustment(com.netflix.titus.api.appscale.model.StepAdjustment) ObjectMappers(com.netflix.titus.api.json.ObjectMappers) Rule(org.junit.Rule) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Optional(java.util.Optional) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest) Mockito.mock(org.mockito.Mockito.mock) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) StepAdjustment(com.netflix.titus.api.appscale.model.StepAdjustment) Session(com.datastax.driver.core.Session) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Aggregations

AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)21 PolicyConfiguration (com.netflix.titus.api.appscale.model.PolicyConfiguration)8 StepScalingPolicyConfiguration (com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration)8 Test (org.junit.Test)7 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)6 AlarmConfiguration (com.netflix.titus.api.appscale.model.AlarmConfiguration)6 StepAdjustment (com.netflix.titus.api.appscale.model.StepAdjustment)4 BoundStatement (com.datastax.driver.core.BoundStatement)3 ResultSet (com.datastax.driver.core.ResultSet)3 Row (com.datastax.driver.core.Row)3 Session (com.datastax.driver.core.Session)3 PolicyStatus (com.netflix.titus.api.appscale.model.PolicyStatus)3 PolicyType (com.netflix.titus.api.appscale.model.PolicyType)3 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)3 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)3 InMemoryPolicyStore (com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore)3 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)3 List (java.util.List)3 Optional (java.util.Optional)3 UUID (java.util.UUID)3