Search in sources :

Example 1 with ScalingPolicy

use of com.netflix.titus.grpc.protogen.ScalingPolicy in project titus-control-plane by Netflix.

the class AggregatingAutoScalingServiceTest method createAndUpdatePolicyForJobIdFromTwoCells.

@Test
public void createAndUpdatePolicyForJobIdFromTwoCells() {
    ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
    ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
    ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).setJobId(JOB_1).build();
    ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).setJobId(JOB_2).build();
    CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
    CellWithPolicies cellTwoService = new CellWithPolicies(Collections.singletonList(policyTwoResult));
    CellWithJobIds cellOneJobsService = new CellWithJobIds(Collections.singletonList(JOB_1));
    CellWithJobIds cellTwoJobsService = new CellWithJobIds(Collections.singletonList(JOB_2));
    cellOne.getServiceRegistry().addService(cellOneService);
    cellOne.getServiceRegistry().addService(cellOneJobsService);
    cellTwo.getServiceRegistry().addService(cellTwoService);
    cellTwo.getServiceRegistry().addService(cellTwoJobsService);
    AssertableSubscriber<ScalingPolicyID> testSubscriber = service.setAutoScalingPolicy(PutPolicyRequest.newBuilder().setJobId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
    testSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    List<ScalingPolicyID> onNextEvents = testSubscriber.getOnNextEvents();
    assertThat(onNextEvents).isNotNull();
    assertThat(onNextEvents.size()).isEqualTo(1);
    assertThat(onNextEvents.get(0).getId()).isNotEmpty();
    AssertableSubscriber<GetPolicyResult> testSubscriber2 = service.getJobScalingPolicies(JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
    testSubscriber2.awaitValueCount(1, 1, TimeUnit.SECONDS);
    List<GetPolicyResult> onNextEvents1 = testSubscriber2.getOnNextEvents();
    assertThat(onNextEvents1).isNotNull();
    assertThat(onNextEvents1.size()).isEqualTo(1);
    assertThat(onNextEvents1.get(0).getItemsCount()).isEqualTo(2);
    assertThat(onNextEvents1.get(0).getItems(0).getJobId()).isEqualTo(JOB_2);
    assertThat(onNextEvents1.get(0).getItems(1).getJobId()).isEqualTo(JOB_2);
    UpdatePolicyRequest updatePolicyRequest = UpdatePolicyRequest.newBuilder().setPolicyId(ScalingPolicyID.newBuilder().setId(POLICY_2)).setScalingPolicy(ScalingPolicy.newBuilder().setTargetPolicyDescriptor(TargetTrackingPolicyDescriptor.newBuilder().setTargetValue(DoubleValue.newBuilder().setValue(100.0).build()).build()).build()).build();
    AssertableSubscriber<Void> testSubscriber3 = service.updateAutoScalingPolicy(updatePolicyRequest, JUNIT_REST_CALL_METADATA).test();
    testSubscriber3.assertNoErrors();
    AssertableSubscriber<GetPolicyResult> testSubscriber4 = service.getScalingPolicy(ScalingPolicyID.newBuilder().setId(POLICY_2).build(), JUNIT_REST_CALL_METADATA).test();
    testSubscriber2.awaitValueCount(1, 1, TimeUnit.SECONDS);
    List<GetPolicyResult> onNextEvents2 = testSubscriber4.getOnNextEvents();
    assertThat(onNextEvents2).isNotNull();
    assertThat(onNextEvents2.size()).isEqualTo(1);
    assertThat(onNextEvents2.get(0).getItemsCount()).isEqualTo(1);
    assertThat(onNextEvents2.get(0).getItems(0).getJobId()).isEqualTo(JOB_2);
    assertThat(onNextEvents2.get(0).getItems(0).getId().getId()).isEqualTo(POLICY_2);
    ScalingPolicy scalingPolicy = onNextEvents2.get(0).getItems(0).getScalingPolicy();
    double updatedValue = scalingPolicy.getTargetPolicyDescriptor().getTargetValue().getValue();
    assertThat(updatedValue).isEqualTo(100);
}
Also used : ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) Test(org.junit.Test)

Example 2 with ScalingPolicy

use of com.netflix.titus.grpc.protogen.ScalingPolicy in project titus-control-plane by Netflix.

the class GrpcModelConverters method toScalingPolicy.

private static ScalingPolicy toScalingPolicy(AutoScalingPolicy autoScalingPolicy) {
    ScalingPolicy.Builder scalingPolicyBuilder = ScalingPolicy.newBuilder();
    if (autoScalingPolicy.getPolicyConfiguration().getPolicyType() == StepScaling) {
        AlarmConfiguration alarmConfiguration = toAlarmConfiguration(autoScalingPolicy.getPolicyConfiguration().getAlarmConfiguration());
        StepScalingPolicy stepScalingPolicy = toStepScalingPolicy(autoScalingPolicy.getPolicyConfiguration().getStepScalingPolicyConfiguration());
        StepScalingPolicyDescriptor stepScalingPolicyDescriptor = StepScalingPolicyDescriptor.newBuilder().setAlarmConfig(alarmConfiguration).setScalingPolicy(stepScalingPolicy).build();
        scalingPolicyBuilder.setStepPolicyDescriptor(stepScalingPolicyDescriptor);
    } else if (autoScalingPolicy.getPolicyConfiguration().getPolicyType() == TargetTrackingScaling) {
        TargetTrackingPolicyDescriptor targetTrackingPolicyDesc = toTargetTrackingPolicyDescriptor(autoScalingPolicy.getPolicyConfiguration().getTargetTrackingPolicy());
        scalingPolicyBuilder.setTargetPolicyDescriptor(targetTrackingPolicyDesc);
    } else {
        throw new IllegalArgumentException("Invalid AutoScalingPolicyType value " + autoScalingPolicy.getPolicyConfiguration().getPolicyType());
    }
    return scalingPolicyBuilder.build();
}
Also used : StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) StepScalingPolicyDescriptor(com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor) AlarmConfiguration(com.netflix.titus.grpc.protogen.AlarmConfiguration) TargetTrackingPolicyDescriptor(com.netflix.titus.grpc.protogen.TargetTrackingPolicyDescriptor)

Example 3 with ScalingPolicy

use of com.netflix.titus.grpc.protogen.ScalingPolicy in project titus-control-plane by Netflix.

the class GrpcModelConverters method toScalingPolicyResult.

public static ScalingPolicyResult toScalingPolicyResult(AutoScalingPolicy autoScalingPolicy) {
    ScalingPolicy scalingPolicy = toScalingPolicy(autoScalingPolicy);
    ScalingPolicyStatus scalingPolicyStatus = toScalingPolicyStatus(autoScalingPolicy.getStatus(), autoScalingPolicy.getStatusMessage());
    return ScalingPolicyResult.newBuilder().setJobId(autoScalingPolicy.getJobId()).setId(ScalingPolicyID.newBuilder().setId(autoScalingPolicy.getRefId()).build()).setPolicyState(scalingPolicyStatus).setScalingPolicy(scalingPolicy).build();
}
Also used : ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) ScalingPolicyStatus(com.netflix.titus.grpc.protogen.ScalingPolicyStatus)

Example 4 with ScalingPolicy

use of com.netflix.titus.grpc.protogen.ScalingPolicy in project titus-control-plane by Netflix.

the class AutoScalingTestUtils method generateUpdateStepScalingPolicyRequest.

public static UpdatePolicyRequest generateUpdateStepScalingPolicyRequest(String policyRefId, double threshold) {
    ScalingPolicy scalingPolicy = generateStepPolicy();
    AlarmConfiguration alarmConfig = scalingPolicy.getStepPolicyDescriptor().getAlarmConfig().toBuilder().setThreshold(DoubleValue.newBuilder().setValue(threshold).build()).build();
    StepScalingPolicyDescriptor stepScalingPolicyDescriptor = scalingPolicy.getStepPolicyDescriptor().toBuilder().setAlarmConfig(alarmConfig).build();
    ScalingPolicy scalingPolicyToBeUpdated = scalingPolicy.toBuilder().setStepPolicyDescriptor(stepScalingPolicyDescriptor).build();
    UpdatePolicyRequest updatePolicyRequest = UpdatePolicyRequest.newBuilder().setPolicyId(ScalingPolicyID.newBuilder().setId(policyRefId).build()).setScalingPolicy(scalingPolicyToBeUpdated).build();
    return updatePolicyRequest;
}
Also used : ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) StepScalingPolicyDescriptor(com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) AlarmConfiguration(com.netflix.titus.grpc.protogen.AlarmConfiguration)

Example 5 with ScalingPolicy

use of com.netflix.titus.grpc.protogen.ScalingPolicy in project titus-control-plane by Netflix.

the class AutoScalingTestUtils method generateUpdateTargetTrackingPolicyRequest.

public static UpdatePolicyRequest generateUpdateTargetTrackingPolicyRequest(String policyRefId, double targetValue) {
    ScalingPolicy scalingPolicy = generateTargetPolicy();
    TargetTrackingPolicyDescriptor targetPolicyDescriptor = scalingPolicy.getTargetPolicyDescriptor();
    TargetTrackingPolicyDescriptor targetPolicyWithUpdatedValue = targetPolicyDescriptor.toBuilder().setTargetValue(DoubleValue.newBuilder().setValue(targetValue).build()).build();
    ScalingPolicy scalingPolicyTobeUpdated = scalingPolicy.toBuilder().setTargetPolicyDescriptor(targetPolicyWithUpdatedValue).build();
    UpdatePolicyRequest updatePolicyRequest = UpdatePolicyRequest.newBuilder().setPolicyId(ScalingPolicyID.newBuilder().setId(policyRefId).build()).setScalingPolicy(scalingPolicyTobeUpdated).build();
    return updatePolicyRequest;
}
Also used : ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) TargetTrackingPolicyDescriptor(com.netflix.titus.grpc.protogen.TargetTrackingPolicyDescriptor)

Aggregations

ScalingPolicy (com.netflix.titus.grpc.protogen.ScalingPolicy)5 StepScalingPolicy (com.netflix.titus.grpc.protogen.StepScalingPolicy)4 UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)3 AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)2 AlarmConfiguration (com.netflix.titus.grpc.protogen.AlarmConfiguration)2 StepScalingPolicyDescriptor (com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor)2 TargetTrackingPolicyDescriptor (com.netflix.titus.grpc.protogen.TargetTrackingPolicyDescriptor)2 GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)1 ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)1 ScalingPolicyResult (com.netflix.titus.grpc.protogen.ScalingPolicyResult)1 ScalingPolicyStatus (com.netflix.titus.grpc.protogen.ScalingPolicyStatus)1 Test (org.junit.Test)1