use of com.netflix.titus.grpc.protogen.DeletePolicyRequest 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.DeletePolicyRequest in project titus-control-plane by Netflix.
the class AutoScalingResource method removePolicy.
@DELETE
@ApiOperation("Delete scaling policy")
@Path("scalingPolicy/{policyId}")
public javax.ws.rs.core.Response removePolicy(@PathParam("policyId") String policyId) {
ScalingPolicyID scalingPolicyId = ScalingPolicyID.newBuilder().setId(policyId).build();
DeletePolicyRequest deletePolicyRequest = DeletePolicyRequest.newBuilder().setId(scalingPolicyId).build();
return Responses.fromCompletable(autoScalingService.deleteAutoScalingPolicy(deletePolicyRequest, resolveCallMetadata()));
}
use of com.netflix.titus.grpc.protogen.DeletePolicyRequest in project titus-control-plane by Netflix.
the class AutoScalingSpringResourceTest method testRemovePolicy.
@Test
public void testRemovePolicy() throws Exception {
DeletePolicyRequest request = DeletePolicyRequest.newBuilder().setId(SCALING_POLICY_ID).build();
when(serviceMock.deleteAutoScalingPolicy(request, JUNIT_REST_CALL_METADATA)).thenReturn(Completable.complete());
SpringMockMvcUtil.doDelete(mockMvc, String.format("/api/v3/autoscaling/scalingPolicy/%s", SCALING_POLICY_ID.getId()));
verify(serviceMock, times(1)).deleteAutoScalingPolicy(request, JUNIT_REST_CALL_METADATA);
}
use of com.netflix.titus.grpc.protogen.DeletePolicyRequest 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.DeletePolicyRequest in project titus-control-plane by Netflix.
the class DefaultAutoScalingServiceGrpcTest method testDeletePolicyId.
/**
* Tests deleting policies by Ref ID.
*
* @throws Exception
*/
@Test
public void testDeletePolicyId() throws Exception {
String jobId = "Titus-123";
ScalingPolicyID scalingPolicyID = putPolicyWithJobId(jobId, PolicyType.StepScaling);
DeletePolicyRequest deletePolicyRequest = DeletePolicyRequest.newBuilder().setId(scalingPolicyID).build();
TestStreamObserver<Empty> deleteResponse = new TestStreamObserver<>();
service.deleteAutoScalingPolicy(deletePolicyRequest, deleteResponse);
deleteResponse.awaitDone();
AutoScalingPolicyTests.waitForCondition(() -> {
TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
service.getScalingPolicy(scalingPolicyID, getResponse);
GetPolicyResult getPolicyResult = getResponse.takeNext();
return getPolicyResult.getItemsCount() == 1 && getPolicyResult.getItems(0).getPolicyState().getState() == Deleted;
});
TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
service.getScalingPolicy(scalingPolicyID, getResponse);
GetPolicyResult getPolicyResult = getResponse.takeNext();
// Check that the policy still exists but the state is updated
assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
assertThat(getPolicyResult.getItems(0).getPolicyState().getState()).isEqualTo(Deleted);
}
Aggregations