use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.
the class AggregatingAutoScalingServiceTest 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);
AssertableSubscriber<GetPolicyResult> testSubscriber = service.getScalingPolicy(ScalingPolicyID.newBuilder().setId(POLICY_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);
// Bad id. The current behavior is "INTERNAL: Completed without a response", but it will change to NOT_FOUND someday
testSubscriber = service.getScalingPolicy(ScalingPolicyID.newBuilder().setId("badID").build(), JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertError(StatusRuntimeException.class);
testSubscriber.assertNoValues();
List<Throwable> onErrorEvents = testSubscriber.getOnErrorEvents();
assertThat(onErrorEvents).isNotNull();
assertThat(onErrorEvents).hasSize(1);
assertThat(Status.fromThrowable(onErrorEvents.get(0)).getCode()).isEqualTo(Status.CANCELLED.getCode());
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.
the class AggregatingAutoScalingServiceTest method createAndDeletePolicyForJobIdFromTwoCells.
@Test
public void createAndDeletePolicyForJobIdFromTwoCells() {
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);
cellTwo.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);
assertThat(testSubscriber.getOnErrorEvents().isEmpty()).isTrue();
List<ScalingPolicyID> onNextEvents = testSubscriber.getOnNextEvents();
assertThat(onNextEvents).isNotNull();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getId()).isNotEmpty();
String newPolicyId = onNextEvents.get(0).getId();
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);
DeletePolicyRequest deletePolicyRequest = DeletePolicyRequest.newBuilder().setId(ScalingPolicyID.newBuilder().setId(newPolicyId).build()).build();
AssertableSubscriber<Void> testSubscriber3 = service.deleteAutoScalingPolicy(deletePolicyRequest, JUNIT_REST_CALL_METADATA).test();
testSubscriber3.assertNoErrors();
AssertableSubscriber<GetPolicyResult> testSubscriber4 = service.getJobScalingPolicies(JobId.newBuilder().setId(JOB_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);
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult 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.GetPolicyResult in project titus-control-plane by Netflix.
the class AutoScalingResourceTest method getPoliciesFromTwoCells.
@Test
public void getPoliciesFromTwoCells() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
List<ScalingPolicyID> policyIds = Arrays.asList(policy1, policy2);
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 allScalingPolicies = autoScalingResource.getAllScalingPolicies();
assertThat(allScalingPolicies).isNotNull();
assertThat(allScalingPolicies.getItemsCount()).isEqualTo(2);
allScalingPolicies.getItemsList().forEach(scalingPolicyResult -> assertThat(policyIds.contains(scalingPolicyResult.getId())).isTrue());
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.
the class DefaultAutoScalingServiceGrpcTest method testTargetTrackingPolicy.
/**
* Tests setting and getting a Target Tracking Policy.
*
* @throws Exception
*/
@Test
public void testTargetTrackingPolicy() throws Exception {
String jobId = "Titus-123";
ScalingPolicyID scalingPolicyID = putPolicyWithJobId(jobId, PolicyType.TargetTrackingScaling);
TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
service.getScalingPolicy(scalingPolicyID, getResponse);
GetPolicyResult getPolicyResult = getResponse.takeNext();
log.info("Got response {}", getPolicyResult);
assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
assertThat(getPolicyResult.getItems(0).getId()).isEqualTo(scalingPolicyID);
assertThat(getPolicyResult.getItems(0).getJobId()).isEqualTo(jobId);
}
Aggregations