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);
}
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();
}
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();
}
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;
}
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;
}
Aggregations