use of com.netflix.titus.grpc.protogen.PutPolicyRequest in project titus-control-plane by Netflix.
the class DefaultAutoScalingServiceGrpcTest method putPolicyWithJobId.
private ScalingPolicyID putPolicyWithJobId(String jobId, PolicyType policyType) {
PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, policyType);
TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
service.setAutoScalingPolicy(putPolicyRequest, putResponse);
log.info("Put policy {}", putPolicyRequest);
ScalingPolicyID scalingPolicyID = putResponse.takeNext();
assertThat(scalingPolicyID.getId()).isNotEmpty();
return scalingPolicyID;
}
use of com.netflix.titus.grpc.protogen.PutPolicyRequest in project titus-control-plane by Netflix.
the class AutoScalingGrpcTest method testGetPolicyById.
/**
* Test that we can retrieve a policy by a specific ID.
*
* @throws Exception
*/
@Test(timeout = TEST_TIMEOUT_MS)
public void testGetPolicyById() throws Exception {
String jobId = "Titus-123";
PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, PolicyType.StepScaling);
TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
client.setAutoScalingPolicy(putPolicyRequest, putResponse);
ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(!scalingPolicyID.getId().isEmpty());
log.info("Put policy {} with ID {}", putPolicyRequest, scalingPolicyID);
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(1);
assertThat(getPolicyResult.getItems(0).getId()).isEqualTo(scalingPolicyID);
assertThat(getPolicyResult.getItems(0).getJobId()).isEqualTo(jobId);
}
use of com.netflix.titus.grpc.protogen.PutPolicyRequest in project titus-control-plane by Netflix.
the class AutoScalingGrpcTest method getAllPolicies.
/**
* Test that we can get multiple exceptions.
*
* @throws Exception
*/
@Test(timeout = TEST_TIMEOUT_MS)
public void getAllPolicies() throws Exception {
Set<ScalingPolicyID> policyIDSet = new HashSet<>();
int numJobs = 2;
for (int i = 1; i <= numJobs; i++) {
PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest("Titus-" + i, PolicyType.StepScaling);
TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
client.setAutoScalingPolicy(putPolicyRequest, putResponse);
ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(!scalingPolicyID.getId().isEmpty());
policyIDSet.add(scalingPolicyID);
}
TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
client.getAllScalingPolicies(Empty.newBuilder().build(), getResponse);
GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(getPolicyResult.getItemsCount()).isEqualTo(numJobs);
getPolicyResult.getItemsList().forEach(scalingPolicyResult -> {
assertThat(policyIDSet.contains(scalingPolicyResult.getId())).isTrue();
});
}
use of com.netflix.titus.grpc.protogen.PutPolicyRequest 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.PutPolicyRequest in project titus-control-plane by Netflix.
the class AutoScalingSpringResourceTest method testSetScalingPolicy.
@Test
public void testSetScalingPolicy() throws Exception {
PutPolicyRequest request = PutPolicyRequest.newBuilder().build();
when(serviceMock.setAutoScalingPolicy(request, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(SCALING_POLICY_ID));
ScalingPolicyID entity = SpringMockMvcUtil.doPost(mockMvc, "/api/v3/autoscaling/scalingPolicy", request, ScalingPolicyID.class);
assertThat(entity).isEqualTo(SCALING_POLICY_ID);
verify(serviceMock, times(1)).setAutoScalingPolicy(request, JUNIT_REST_CALL_METADATA);
}
Aggregations