use of com.netflix.titus.grpc.protogen.ScalingPolicyID in project titus-control-plane by Netflix.
the class AutoScalingSpringResource method removePolicy.
@ApiOperation("Delete scaling policy")
@DeleteMapping(path = "scalingPolicy/{policyId}")
public ResponseEntity<Void> removePolicy(@PathVariable("policyId") String policyId, CallMetadataAuthentication authentication) {
ScalingPolicyID scalingPolicyId = ScalingPolicyID.newBuilder().setId(policyId).build();
DeletePolicyRequest deletePolicyRequest = DeletePolicyRequest.newBuilder().setId(scalingPolicyId).build();
return Responses.fromCompletable(autoScalingService.deleteAutoScalingPolicy(deletePolicyRequest, authentication.getCallMetadata()), HttpStatus.OK);
}
use of com.netflix.titus.grpc.protogen.ScalingPolicyID in project titus-control-plane by Netflix.
the class AggregatingAutoScalingServiceTest method getPoliciesFromTwoCells.
@Test
public void getPoliciesFromTwoCells() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).build();
CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
CellWithPolicies cellTwoService = new CellWithPolicies(Collections.singletonList(policyTwoResult));
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(cellTwoService);
final AssertableSubscriber<GetPolicyResult> testSubscriber = service.getAllScalingPolicies(JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
List<GetPolicyResult> onNextEvents = testSubscriber.getOnNextEvents();
assertThat(onNextEvents).isNotNull();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getItemsCount()).isEqualTo(2);
}
use of com.netflix.titus.grpc.protogen.ScalingPolicyID in project titus-control-plane by Netflix.
the class AggregatingAutoScalingServiceTest method getPoliciesFromTwoCellsWithOneFailing.
@Test
public void getPoliciesFromTwoCellsWithOneFailing() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
CellWithFailingAutoscalingService badCell = new CellWithFailingAutoscalingService();
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(badCell);
final AssertableSubscriber<GetPolicyResult> testSubscriber = service.getAllScalingPolicies(JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoValues();
testSubscriber.assertError(StatusRuntimeException.class);
List<Throwable> onErrorEvents = testSubscriber.getOnErrorEvents();
assertThat(onErrorEvents.size()).isEqualTo(1);
}
use of com.netflix.titus.grpc.protogen.ScalingPolicyID in project titus-control-plane by Netflix.
the class AggregatingAutoScalingServiceTest method getPoliciesForJobFromTwoCells.
@Test
public void getPoliciesForJobFromTwoCells() {
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));
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(cellTwoService);
AssertableSubscriber<GetPolicyResult> testSubscriber = service.getJobScalingPolicies(JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
List<GetPolicyResult> onNextEvents = testSubscriber.getOnNextEvents();
assertThat(onNextEvents).isNotNull();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getItemsCount()).isEqualTo(1);
assertThat(onNextEvents.get(0).getItems(0).getJobId()).isEqualTo(JOB_2);
// Bad policy id, currently each Cell returns an empty result
testSubscriber = service.getJobScalingPolicies(JobId.newBuilder().setId("badID").build(), JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors();
onNextEvents = testSubscriber.getOnNextEvents();
assertThat(onNextEvents).isNotNull();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getItemsCount()).isEqualTo(0);
}
use of com.netflix.titus.grpc.protogen.ScalingPolicyID in project titus-control-plane by Netflix.
the class AutoScalingResourceTest method getPolicyByIdFromTwoCells.
@Test
public void getPolicyByIdFromTwoCells() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).build();
CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
CellWithPolicies cellTwoService = new CellWithPolicies(Collections.singletonList(policyTwoResult));
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(cellTwoService);
final AutoScalingResource autoScalingResource = new AutoScalingResource(service, callMetadataResolver);
final GetPolicyResult scalingPolicy = autoScalingResource.getScalingPolicy(POLICY_2);
assertThat(scalingPolicy.getItemsCount()).isEqualTo(1);
assertThat(scalingPolicy.getItems(0).getId().getId()).isEqualTo(POLICY_2);
// bad id
Assertions.assertThatCode(() -> autoScalingResource.getScalingPolicy("badPolicyId")).hasCause(Status.CANCELLED.withDescription("server cancelled stream").asRuntimeException());
}
Aggregations