Search in sources :

Example 1 with DeletePolicyRequest

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);
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) Test(org.junit.Test)

Example 2 with DeletePolicyRequest

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()));
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with DeletePolicyRequest

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);
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 4 with DeletePolicyRequest

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);
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with DeletePolicyRequest

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);
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) Empty(com.google.protobuf.Empty) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Aggregations

DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)7 ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)6 GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)4 Test (org.junit.Test)4 Empty (com.google.protobuf.Empty)3 PutPolicyRequest (com.netflix.titus.grpc.protogen.PutPolicyRequest)2 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Cell (com.netflix.titus.api.federation.model.Cell)1 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)1 CellConnectorUtil.callToCell (com.netflix.titus.federation.service.CellConnectorUtil.callToCell)1 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)1 AutoScalingServiceGrpc (com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc)1 AutoScalingServiceStub (com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc.AutoScalingServiceStub)1 JobId (com.netflix.titus.grpc.protogen.JobId)1 ScalingPolicyResult (com.netflix.titus.grpc.protogen.ScalingPolicyResult)1 UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)1 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)1 GrpcUtil.createWrappedStub (com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil.createWrappedStub)1 AutoScalingService (com.netflix.titus.runtime.service.AutoScalingService)1