Search in sources :

Example 1 with UpdatePolicyRequest

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

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

the class AutoScalingSpringResourceTest method testUpdateScalingPolicy.

@Test
public void testUpdateScalingPolicy() throws Exception {
    UpdatePolicyRequest request = UpdatePolicyRequest.newBuilder().build();
    when(serviceMock.updateAutoScalingPolicy(request, JUNIT_REST_CALL_METADATA)).thenReturn(Completable.complete());
    SpringMockMvcUtil.doPut(mockMvc, "/api/v3/autoscaling/scalingPolicy", request);
    verify(serviceMock, times(1)).updateAutoScalingPolicy(request, JUNIT_REST_CALL_METADATA);
}
Also used : UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 3 with UpdatePolicyRequest

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

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

the class AutoScalingTestUtils method generateUpdateStepScalingPolicyRequest.

public static UpdatePolicyRequest generateUpdateStepScalingPolicyRequest(String policyRefId, double threshold) {
    ScalingPolicy scalingPolicy = generateStepPolicy();
    AlarmConfiguration alarmConfig = scalingPolicy.getStepPolicyDescriptor().getAlarmConfig().toBuilder().setThreshold(DoubleValue.newBuilder().setValue(threshold).build()).build();
    StepScalingPolicyDescriptor stepScalingPolicyDescriptor = scalingPolicy.getStepPolicyDescriptor().toBuilder().setAlarmConfig(alarmConfig).build();
    ScalingPolicy scalingPolicyToBeUpdated = scalingPolicy.toBuilder().setStepPolicyDescriptor(stepScalingPolicyDescriptor).build();
    UpdatePolicyRequest updatePolicyRequest = UpdatePolicyRequest.newBuilder().setPolicyId(ScalingPolicyID.newBuilder().setId(policyRefId).build()).setScalingPolicy(scalingPolicyToBeUpdated).build();
    return updatePolicyRequest;
}
Also used : ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) StepScalingPolicyDescriptor(com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) AlarmConfiguration(com.netflix.titus.grpc.protogen.AlarmConfiguration)

Example 5 with UpdatePolicyRequest

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

the class AutoScalingTestUtils method generateUpdateTargetTrackingPolicyRequest.

public static UpdatePolicyRequest generateUpdateTargetTrackingPolicyRequest(String policyRefId, double targetValue) {
    ScalingPolicy scalingPolicy = generateTargetPolicy();
    TargetTrackingPolicyDescriptor targetPolicyDescriptor = scalingPolicy.getTargetPolicyDescriptor();
    TargetTrackingPolicyDescriptor targetPolicyWithUpdatedValue = targetPolicyDescriptor.toBuilder().setTargetValue(DoubleValue.newBuilder().setValue(targetValue).build()).build();
    ScalingPolicy scalingPolicyTobeUpdated = scalingPolicy.toBuilder().setTargetPolicyDescriptor(targetPolicyWithUpdatedValue).build();
    UpdatePolicyRequest updatePolicyRequest = UpdatePolicyRequest.newBuilder().setPolicyId(ScalingPolicyID.newBuilder().setId(policyRefId).build()).setScalingPolicy(scalingPolicyTobeUpdated).build();
    return updatePolicyRequest;
}
Also used : ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) TargetTrackingPolicyDescriptor(com.netflix.titus.grpc.protogen.TargetTrackingPolicyDescriptor)

Aggregations

UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)6 GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)3 ScalingPolicy (com.netflix.titus.grpc.protogen.ScalingPolicy)3 ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)3 Test (org.junit.Test)3 ScalingPolicyResult (com.netflix.titus.grpc.protogen.ScalingPolicyResult)2 StepScalingPolicy (com.netflix.titus.grpc.protogen.StepScalingPolicy)2 DoubleValue (com.google.protobuf.DoubleValue)1 Empty (com.google.protobuf.Empty)1 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 AlarmConfiguration (com.netflix.titus.grpc.protogen.AlarmConfiguration)1 AutoScalingServiceGrpc (com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc)1 AutoScalingServiceStub (com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc.AutoScalingServiceStub)1 DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)1 JobId (com.netflix.titus.grpc.protogen.JobId)1 PutPolicyRequest (com.netflix.titus.grpc.protogen.PutPolicyRequest)1 StepScalingPolicyDescriptor (com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor)1