Search in sources :

Example 16 with GetPolicyResult

use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.

the class AggregatingAutoScalingServiceTest method getPoliciesForJobFromTwoCells.

@Test
public void getPoliciesForJobFromTwoCells() {
    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));
    cellOne.getServiceRegistry().addService(cellOneService);
    cellTwo.getServiceRegistry().addService(cellTwoService);
    AssertableSubscriber<GetPolicyResult> testSubscriber = service.getJobScalingPolicies(JobId.newBuilder().setId(JOB_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);
    assertThat(onNextEvents.get(0).getItems(0).getJobId()).isEqualTo(JOB_2);
    // Bad policy id, currently each Cell returns an empty result
    testSubscriber = service.getJobScalingPolicies(JobId.newBuilder().setId("badID").build(), JUNIT_REST_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    onNextEvents = testSubscriber.getOnNextEvents();
    assertThat(onNextEvents).isNotNull();
    assertThat(onNextEvents.size()).isEqualTo(1);
    assertThat(onNextEvents.get(0).getItemsCount()).isEqualTo(0);
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Example 17 with GetPolicyResult

use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.

the class AutoScalingResourceTest 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);
    final AutoScalingResource autoScalingResource = new AutoScalingResource(service, callMetadataResolver);
    final GetPolicyResult scalingPolicy = autoScalingResource.getScalingPolicy(POLICY_2);
    assertThat(scalingPolicy.getItemsCount()).isEqualTo(1);
    assertThat(scalingPolicy.getItems(0).getId().getId()).isEqualTo(POLICY_2);
    // bad id
    Assertions.assertThatCode(() -> autoScalingResource.getScalingPolicy("badPolicyId")).hasCause(Status.CANCELLED.withDescription("server cancelled stream").asRuntimeException());
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) AutoScalingResource(com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Example 18 with GetPolicyResult

use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.

the class AutoScalingResourceTest 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);
    cellOne.getServiceRegistry().addService(cellOneJobsService);
    cellTwo.getServiceRegistry().addService(cellTwoService);
    cellTwo.getServiceRegistry().addService(cellTwoJobsService);
    final AutoScalingResource autoScalingResource = new AutoScalingResource(service, callMetadataResolver);
    final ScalingPolicyID scalingPolicyId = autoScalingResource.setScalingPolicy(PutPolicyRequest.newBuilder().setJobId(JOB_2).build());
    assertThat(scalingPolicyId).isNotNull();
    assertThat(scalingPolicyId.getId()).isNotEmpty();
    final GetPolicyResult scalingPolicyForJob = autoScalingResource.getScalingPolicyForJob(JOB_2);
    assertThat(scalingPolicyForJob).isNotNull();
    assertThat(scalingPolicyForJob.getItemsCount()).isEqualTo(2);
    assertThat(scalingPolicyForJob.getItems(0).getJobId()).isEqualTo(JOB_2);
    assertThat(scalingPolicyForJob.getItems(1).getJobId()).isEqualTo(JOB_2);
    final Response deleteResponse = autoScalingResource.removePolicy(scalingPolicyId.getId());
    assertThat(deleteResponse.getStatus()).isEqualTo(200);
    final GetPolicyResult scalingPolicyForJobResult = autoScalingResource.getScalingPolicyForJob(JOB_2);
    assertThat(scalingPolicyForJobResult).isNotNull();
    assertThat(scalingPolicyForJobResult.getItemsCount()).isEqualTo(1);
    assertThat(scalingPolicyForJobResult.getItems(0).getJobId()).isEqualTo(JOB_2);
}
Also used : Response(javax.ws.rs.core.Response) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) AutoScalingResource(com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Example 19 with GetPolicyResult

use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.

the class AutoScalingResourceTest 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);
    final AutoScalingResource autoScalingResource = new AutoScalingResource(service, callMetadataResolver);
    final ScalingPolicyID scalingPolicyID = autoScalingResource.setScalingPolicy(PutPolicyRequest.newBuilder().setJobId(JOB_2).build());
    assertThat(scalingPolicyID).isNotNull();
    assertThat(scalingPolicyID.getId()).isNotEmpty();
    final GetPolicyResult scalingPolicyForJob = autoScalingResource.getScalingPolicyForJob(JOB_2);
    assertThat(scalingPolicyForJob).isNotNull();
    assertThat(scalingPolicyForJob.getItemsCount()).isEqualTo(2);
    assertThat(scalingPolicyForJob.getItems(0).getJobId()).isEqualTo(JOB_2);
    assertThat(scalingPolicyForJob.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();
    final Response updateScalingPolicyResponse = autoScalingResource.updateScalingPolicy(updatePolicyRequest);
    assertThat(updateScalingPolicyResponse.getStatus()).isEqualTo(200);
    final GetPolicyResult updatedScalingPolicy = autoScalingResource.getScalingPolicy(POLICY_2);
    assertThat(updatedScalingPolicy.getItemsCount()).isEqualTo(1);
    assertThat(updatedScalingPolicy.getItems(0).getJobId()).isEqualTo(JOB_2);
    assertThat(updatedScalingPolicy.getItems(0).getId().getId()).isEqualTo(POLICY_2);
    final DoubleValue targetValue = updatedScalingPolicy.getItems(0).getScalingPolicy().getTargetPolicyDescriptor().getTargetValue();
    assertThat(targetValue.getValue()).isEqualTo(100.0);
}
Also used : Response(javax.ws.rs.core.Response) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) DoubleValue(com.google.protobuf.DoubleValue) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) AutoScalingResource(com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Example 20 with GetPolicyResult

use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.

the class AutoScalingResourceTest method getPoliciesForJobFromTwoCells.

@Test
public void getPoliciesForJobFromTwoCells() {
    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));
    cellOne.getServiceRegistry().addService(cellOneService);
    cellTwo.getServiceRegistry().addService(cellTwoService);
    final AutoScalingResource autoScalingResource = new AutoScalingResource(service, callMetadataResolver);
    final GetPolicyResult scalingPolicyForJob = autoScalingResource.getScalingPolicyForJob(JOB_2);
    assertThat(scalingPolicyForJob).isNotNull();
    assertThat(scalingPolicyForJob.getItemsCount()).isEqualTo(1);
    assertThat(scalingPolicyForJob.getItems(0).getJobId()).isEqualTo(JOB_2);
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) AutoScalingResource(com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Aggregations

GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)29 Test (org.junit.Test)28 ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)22 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)14 ScalingPolicyResult (com.netflix.titus.grpc.protogen.ScalingPolicyResult)12 Empty (com.google.protobuf.Empty)7 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)7 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)7 JobId (com.netflix.titus.grpc.protogen.JobId)5 PutPolicyRequest (com.netflix.titus.grpc.protogen.PutPolicyRequest)5 AutoScalingResource (com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource)5 DoubleValue (com.google.protobuf.DoubleValue)3 DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)3 HashSet (java.util.HashSet)3 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)3 UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)2 Set (java.util.Set)2 Response (javax.ws.rs.core.Response)2 ScalingPolicy (com.netflix.titus.grpc.protogen.ScalingPolicy)1 ApiOperation (io.swagger.annotations.ApiOperation)1