Search in sources :

Example 1 with GetPolicyResult

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

the class AggregatingAutoScalingServiceTest 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);
    AssertableSubscriber<GetPolicyResult> testSubscriber = service.getScalingPolicy(ScalingPolicyID.newBuilder().setId(POLICY_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);
    // Bad id. The current behavior is "INTERNAL: Completed without a response", but it will change to NOT_FOUND someday
    testSubscriber = service.getScalingPolicy(ScalingPolicyID.newBuilder().setId("badID").build(), JUNIT_REST_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertError(StatusRuntimeException.class);
    testSubscriber.assertNoValues();
    List<Throwable> onErrorEvents = testSubscriber.getOnErrorEvents();
    assertThat(onErrorEvents).isNotNull();
    assertThat(onErrorEvents).hasSize(1);
    assertThat(Status.fromThrowable(onErrorEvents.get(0)).getCode()).isEqualTo(Status.CANCELLED.getCode());
}
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 2 with GetPolicyResult

use of com.netflix.titus.grpc.protogen.GetPolicyResult 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 3 with GetPolicyResult

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

the class AggregatingAutoScalingServiceTest 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);
    AssertableSubscriber<ScalingPolicyID> testSubscriber = service.setAutoScalingPolicy(PutPolicyRequest.newBuilder().setJobId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
    testSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    List<ScalingPolicyID> onNextEvents = testSubscriber.getOnNextEvents();
    assertThat(onNextEvents).isNotNull();
    assertThat(onNextEvents.size()).isEqualTo(1);
    assertThat(onNextEvents.get(0).getId()).isNotEmpty();
    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);
    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();
    AssertableSubscriber<Void> testSubscriber3 = service.updateAutoScalingPolicy(updatePolicyRequest, JUNIT_REST_CALL_METADATA).test();
    testSubscriber3.assertNoErrors();
    AssertableSubscriber<GetPolicyResult> testSubscriber4 = service.getScalingPolicy(ScalingPolicyID.newBuilder().setId(POLICY_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);
    ScalingPolicy scalingPolicy = onNextEvents2.get(0).getItems(0).getScalingPolicy();
    double updatedValue = scalingPolicy.getTargetPolicyDescriptor().getTargetValue().getValue();
    assertThat(updatedValue).isEqualTo(100);
}
Also used : ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) Test(org.junit.Test)

Example 4 with GetPolicyResult

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

the class AutoScalingResourceTest method getPoliciesFromTwoCells.

@Test
public void getPoliciesFromTwoCells() {
    ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
    ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
    List<ScalingPolicyID> policyIds = Arrays.asList(policy1, policy2);
    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 allScalingPolicies = autoScalingResource.getAllScalingPolicies();
    assertThat(allScalingPolicies).isNotNull();
    assertThat(allScalingPolicies.getItemsCount()).isEqualTo(2);
    allScalingPolicies.getItemsList().forEach(scalingPolicyResult -> assertThat(policyIds.contains(scalingPolicyResult.getId())).isTrue());
}
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 5 with GetPolicyResult

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

the class DefaultAutoScalingServiceGrpcTest method testTargetTrackingPolicy.

/**
 * Tests setting and getting a Target Tracking Policy.
 *
 * @throws Exception
 */
@Test
public void testTargetTrackingPolicy() throws Exception {
    String jobId = "Titus-123";
    ScalingPolicyID scalingPolicyID = putPolicyWithJobId(jobId, PolicyType.TargetTrackingScaling);
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    service.getScalingPolicy(scalingPolicyID, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext();
    log.info("Got response {}", getPolicyResult);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    assertThat(getPolicyResult.getItems(0).getId()).isEqualTo(scalingPolicyID);
    assertThat(getPolicyResult.getItems(0).getJobId()).isEqualTo(jobId);
}
Also used : 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

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