use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.
the class AutoScalingGrpcTest method testUpdatePolicyConfigurationForStepScaling.
/**
* Test policy configuration update for target tracking policy
*
* @throws Exception
*/
@Test(timeout = TEST_TIMEOUT_MS)
public void testUpdatePolicyConfigurationForStepScaling() throws Exception {
String jobId = "Titus-123";
PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, PolicyType.StepScaling);
TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
client.setAutoScalingPolicy(putPolicyRequest, putResponse);
putResponse.awaitDone();
ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(!scalingPolicyID.getId().isEmpty());
TestStreamObserver<Empty> updateResponse = new TestStreamObserver<>();
client.updateAutoScalingPolicy(AutoScalingTestUtils.generateUpdateStepScalingPolicyRequest(scalingPolicyID.getId(), 100.0), updateResponse);
updateResponse.awaitDone();
AutoScalingPolicyTests.waitForCondition(() -> {
TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
client.getScalingPolicy(scalingPolicyID, getResponse);
try {
GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
return getPolicyResult.getItemsCount() == 1 && getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold().getValue() == 100.0;
} catch (Exception ignored) {
}
return false;
});
TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
client.getScalingPolicy(scalingPolicyID, getResponse);
getResponse.awaitDone();
GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
DoubleValue threshold = getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold();
assertThat(threshold.getValue()).isEqualTo(100.0);
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.
the class AutoScalingGrpcTest method testGetNonexistentJob.
/**
* Test that a non-existent job returns an empty list of policies.
*
* @throws Exception
*/
@Test(timeout = TEST_TIMEOUT_MS)
public void testGetNonexistentJob() throws Exception {
String jobId = "Titus-0";
JobId getPolicyRequest = JobId.newBuilder().setId(jobId).build();
TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
client.getJobScalingPolicies(getPolicyRequest, getResponse);
GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
log.info("Got result {}", getPolicyResult);
assertThat(getPolicyResult.getItemsCount()).isEqualTo(0);
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.
the class AutoScalingResource method getScalingPolicyForJob.
@GET
@ApiOperation("Find scaling policies for a job")
@Path("scalingPolicies/{jobId}")
public GetPolicyResult getScalingPolicyForJob(@PathParam("jobId") String jobId) {
JobId request = JobId.newBuilder().setId(jobId).build();
GetPolicyResult getPolicyResult = Responses.fromSingleValueObservable(autoScalingService.getJobScalingPolicies(request, resolveCallMetadata()));
return getPolicyResult;
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult 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.GetPolicyResult 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);
}
Aggregations