Search in sources :

Example 26 with ScalingPolicyID

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

the class DefaultAutoScalingServiceGrpcTest method testUpdatePolicyConfigurationForStepScaling.

@Test
public void testUpdatePolicyConfigurationForStepScaling() throws Exception {
    ScalingPolicyID policyId = putPolicyWithJobId("Job-1", PolicyType.StepScaling);
    TestStreamObserver<Empty> updateResponse = new TestStreamObserver<>();
    service.updateAutoScalingPolicy(AutoScalingTestUtils.generateUpdateStepScalingPolicyRequest(policyId.getId(), 100.0), updateResponse);
    updateResponse.awaitDone();
    AutoScalingPolicyTests.waitForCondition(() -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        service.getScalingPolicy(policyId, getResponse);
        GetPolicyResult getPolicyResult = getResponse.takeNext();
        return getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold().getValue() == 100.0 && getPolicyResult.getItems(0).getPolicyState().getState() == Applied;
    });
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    service.getScalingPolicy(policyId, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext();
    assertThat(getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold().getValue()).isEqualTo(100.0);
    assertThat(getPolicyResult.getItems(0).getPolicyState().getState()).isEqualTo(Applied);
}
Also used : Empty(com.google.protobuf.Empty) 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)

Example 27 with ScalingPolicyID

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

the class DefaultAutoScalingServiceGrpcTest method testGetByPolicyId.

/**
 * Tests getting policies by Ref ID.
 *
 * @throws Exception
 */
@Test
public void testGetByPolicyId() throws Exception {
    String jobId = "Titus-123";
    ScalingPolicyID scalingPolicyID = putPolicyWithJobId(jobId, PolicyType.StepScaling);
    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)

Example 28 with ScalingPolicyID

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

the class AutoScalingSpringResourceTest method testSetScalingPolicy.

@Test
public void testSetScalingPolicy() throws Exception {
    PutPolicyRequest request = PutPolicyRequest.newBuilder().build();
    when(serviceMock.setAutoScalingPolicy(request, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(SCALING_POLICY_ID));
    ScalingPolicyID entity = SpringMockMvcUtil.doPost(mockMvc, "/api/v3/autoscaling/scalingPolicy", request, ScalingPolicyID.class);
    assertThat(entity).isEqualTo(SCALING_POLICY_ID);
    verify(serviceMock, times(1)).setAutoScalingPolicy(request, JUNIT_REST_CALL_METADATA);
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 29 with ScalingPolicyID

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

the class AggregatingAutoScalingService method updateAutoScalingPolicy.

@Override
public Completable updateAutoScalingPolicy(UpdatePolicyRequest request, CallMetadata callMetadata) {
    ScalingPolicyID policyId = request.getPolicyId();
    Observable<Empty> observable = getScalingPolicyInAllCells(policyId, callMetadata).flatMap(response -> singleCellCall(response.getCell(), (client, responseObserver) -> client.updateAutoScalingPolicy(request, responseObserver), callMetadata));
    return observable.toCompletable();
}
Also used : Completable(rx.Completable) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) Cell(com.netflix.titus.api.federation.model.Cell) DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) GrpcUtil.createWrappedStub(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil.createWrappedStub) Singleton(javax.inject.Singleton) AutoScalingServiceStub(com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc.AutoScalingServiceStub) PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) Observable(rx.Observable) Inject(javax.inject.Inject) Empty(com.google.protobuf.Empty) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) StreamObserver(io.grpc.stub.StreamObserver) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) AbstractStub(io.grpc.stub.AbstractStub) AutoScalingServiceGrpc(com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc) AutoScalingService(com.netflix.titus.runtime.service.AutoScalingService) BiConsumer(java.util.function.BiConsumer) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobId(com.netflix.titus.grpc.protogen.JobId) Empty(com.google.protobuf.Empty) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID)

Example 30 with ScalingPolicyID

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

the class AggregatingAutoScalingService method deleteAutoScalingPolicy.

@Override
public Completable deleteAutoScalingPolicy(DeletePolicyRequest request, CallMetadata callMetadata) {
    ScalingPolicyID policyId = request.getId();
    Observable<Empty> observable = getScalingPolicyInAllCells(policyId, callMetadata).flatMap(response -> singleCellCall(response.getCell(), (client, responseObserver) -> client.deleteAutoScalingPolicy(request, responseObserver), callMetadata));
    return observable.toCompletable();
}
Also used : Completable(rx.Completable) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) Cell(com.netflix.titus.api.federation.model.Cell) DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) GrpcUtil.createWrappedStub(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil.createWrappedStub) Singleton(javax.inject.Singleton) AutoScalingServiceStub(com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc.AutoScalingServiceStub) PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) Observable(rx.Observable) Inject(javax.inject.Inject) Empty(com.google.protobuf.Empty) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) StreamObserver(io.grpc.stub.StreamObserver) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) AbstractStub(io.grpc.stub.AbstractStub) AutoScalingServiceGrpc(com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc) AutoScalingService(com.netflix.titus.runtime.service.AutoScalingService) BiConsumer(java.util.function.BiConsumer) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobId(com.netflix.titus.grpc.protogen.JobId) Empty(com.google.protobuf.Empty) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID)

Aggregations

ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)32 GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)24 Test (org.junit.Test)24 ScalingPolicyResult (com.netflix.titus.grpc.protogen.ScalingPolicyResult)13 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)12 PutPolicyRequest (com.netflix.titus.grpc.protogen.PutPolicyRequest)9 Empty (com.google.protobuf.Empty)8 DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)7 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)6 AutoScalingResource (com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource)6 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)6 UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)4 ApiOperation (io.swagger.annotations.ApiOperation)4 DoubleValue (com.google.protobuf.DoubleValue)3 JobId (com.netflix.titus.grpc.protogen.JobId)3 Cell (com.netflix.titus.api.federation.model.Cell)2 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)2 CellConnectorUtil.callToCell (com.netflix.titus.federation.service.CellConnectorUtil.callToCell)2 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)2 AutoScalingServiceGrpc (com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc)2