Search in sources :

Example 11 with GetPolicyResult

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

the class AutoScalingGrpcTest method testUpdatePolicyConfigurationForStepScaling.

/**
 * Test policy configuration update for target tracking policy
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testUpdatePolicyConfigurationForStepScaling() throws Exception {
    String jobId = "Titus-123";
    PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, PolicyType.StepScaling);
    TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
    client.setAutoScalingPolicy(putPolicyRequest, putResponse);
    putResponse.awaitDone();
    ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(!scalingPolicyID.getId().isEmpty());
    TestStreamObserver<Empty> updateResponse = new TestStreamObserver<>();
    client.updateAutoScalingPolicy(AutoScalingTestUtils.generateUpdateStepScalingPolicyRequest(scalingPolicyID.getId(), 100.0), updateResponse);
    updateResponse.awaitDone();
    AutoScalingPolicyTests.waitForCondition(() -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        client.getScalingPolicy(scalingPolicyID, getResponse);
        try {
            GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
            return getPolicyResult.getItemsCount() == 1 && getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold().getValue() == 100.0;
        } catch (Exception ignored) {
        }
        return false;
    });
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getScalingPolicy(scalingPolicyID, getResponse);
    getResponse.awaitDone();
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    DoubleValue threshold = getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold();
    assertThat(threshold.getValue()).isEqualTo(100.0);
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) Empty(com.google.protobuf.Empty) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) DoubleValue(com.google.protobuf.DoubleValue) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 12 with GetPolicyResult

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

the class AutoScalingGrpcTest method testGetNonexistentJob.

/**
 * Test that a non-existent job returns an empty list of policies.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testGetNonexistentJob() throws Exception {
    String jobId = "Titus-0";
    JobId getPolicyRequest = JobId.newBuilder().setId(jobId).build();
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getJobScalingPolicies(getPolicyRequest, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    log.info("Got result {}", getPolicyResult);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(0);
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) JobId(com.netflix.titus.grpc.protogen.JobId) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 13 with GetPolicyResult

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

the class AutoScalingResource method getScalingPolicyForJob.

@GET
@ApiOperation("Find scaling policies for a job")
@Path("scalingPolicies/{jobId}")
public GetPolicyResult getScalingPolicyForJob(@PathParam("jobId") String jobId) {
    JobId request = JobId.newBuilder().setId(jobId).build();
    GetPolicyResult getPolicyResult = Responses.fromSingleValueObservable(autoScalingService.getJobScalingPolicies(request, resolveCallMetadata()));
    return getPolicyResult;
}
Also used : GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) JobId(com.netflix.titus.grpc.protogen.JobId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 14 with GetPolicyResult

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

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

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