Search in sources :

Example 6 with ScalingPolicyResult

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

the class DefaultAutoScalingServiceGrpcTest method testSetAndGetJobScalingPolicy.

/**
 * Tests setting and getting policies by Job ID.
 *
 * @throws Exception
 */
@Test
public void testSetAndGetJobScalingPolicy() throws Exception {
    int numJobs = 2;
    int numPoliciesPerJob = 3;
    Map<String, Set<ScalingPolicyID>> jobIdToPoliciesMap = putPoliciesPerJob(numJobs, numPoliciesPerJob, PolicyType.StepScaling);
    // For each job, check that all of the policies exist
    jobIdToPoliciesMap.forEach((jobId, policyIDSet) -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        JobId jobIdRequest = JobId.newBuilder().setId(jobId).build();
        service.getJobScalingPolicies(jobIdRequest, getResponse);
        GetPolicyResult getPolicyResult = getResponse.takeNext();
        assertThat(getPolicyResult.getItemsCount()).isEqualTo(numPoliciesPerJob);
        for (int i = 0; i < getPolicyResult.getItemsCount(); i++) {
            ScalingPolicyResult scalingPolicyResult = getPolicyResult.getItems(i);
            assertThat(policyIDSet.contains(scalingPolicyResult.getId())).isTrue();
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) JobId(com.netflix.titus.grpc.protogen.JobId) Test(org.junit.Test)

Example 7 with ScalingPolicyResult

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

the class AggregatingAutoScalingServiceTest method getPoliciesFromTwoCells.

@Test
public void getPoliciesFromTwoCells() {
    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 AssertableSubscriber<GetPolicyResult> testSubscriber = service.getAllScalingPolicies(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(2);
}
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 8 with ScalingPolicyResult

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

the class AggregatingAutoScalingServiceTest method getPoliciesFromTwoCellsWithOneFailing.

@Test
public void getPoliciesFromTwoCellsWithOneFailing() {
    ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
    ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
    CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
    CellWithFailingAutoscalingService badCell = new CellWithFailingAutoscalingService();
    cellOne.getServiceRegistry().addService(cellOneService);
    cellTwo.getServiceRegistry().addService(badCell);
    final AssertableSubscriber<GetPolicyResult> testSubscriber = service.getAllScalingPolicies(JUNIT_REST_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoValues();
    testSubscriber.assertError(StatusRuntimeException.class);
    List<Throwable> onErrorEvents = testSubscriber.getOnErrorEvents();
    assertThat(onErrorEvents.size()).isEqualTo(1);
}
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 9 with ScalingPolicyResult

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

use of com.netflix.titus.grpc.protogen.ScalingPolicyResult 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)

Aggregations

ScalingPolicyResult (com.netflix.titus.grpc.protogen.ScalingPolicyResult)17 ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)13 Test (org.junit.Test)13 GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)12 AutoScalingResource (com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource)6 UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)2 Response (javax.ws.rs.core.Response)2 DoubleValue (com.google.protobuf.DoubleValue)1 DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)1 JobId (com.netflix.titus.grpc.protogen.JobId)1 ScalingPolicy (com.netflix.titus.grpc.protogen.ScalingPolicy)1 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1