Search in sources :

Example 11 with ScalingPolicyID

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

the class AutoScalingGrpcTest method getAllPolicies.

/**
 * Test that we can get multiple exceptions.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void getAllPolicies() throws Exception {
    Set<ScalingPolicyID> policyIDSet = new HashSet<>();
    int numJobs = 2;
    for (int i = 1; i <= numJobs; i++) {
        PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest("Titus-" + i, PolicyType.StepScaling);
        TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
        client.setAutoScalingPolicy(putPolicyRequest, putResponse);
        ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
        assertThat(!scalingPolicyID.getId().isEmpty());
        policyIDSet.add(scalingPolicyID);
    }
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getAllScalingPolicies(Empty.newBuilder().build(), getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(numJobs);
    getPolicyResult.getItemsList().forEach(scalingPolicyResult -> {
        assertThat(policyIDSet.contains(scalingPolicyResult.getId())).isTrue();
    });
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) HashSet(java.util.HashSet) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 12 with ScalingPolicyID

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

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

the class AutoScalingResource method removePolicy.

@DELETE
@ApiOperation("Delete scaling policy")
@Path("scalingPolicy/{policyId}")
public javax.ws.rs.core.Response removePolicy(@PathParam("policyId") String policyId) {
    ScalingPolicyID scalingPolicyId = ScalingPolicyID.newBuilder().setId(policyId).build();
    DeletePolicyRequest deletePolicyRequest = DeletePolicyRequest.newBuilder().setId(scalingPolicyId).build();
    return Responses.fromCompletable(autoScalingService.deleteAutoScalingPolicy(deletePolicyRequest, resolveCallMetadata()));
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation)

Example 14 with ScalingPolicyID

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

the class AutoScalingSpringResource method setScalingPolicy.

@ApiOperation("Create or Update scaling policy")
@PostMapping(path = "/scalingPolicy")
public ScalingPolicyID setScalingPolicy(@RequestBody PutPolicyRequest putPolicyRequest, CallMetadataAuthentication authentication) {
    Observable<ScalingPolicyID> putPolicyResult = autoScalingService.setAutoScalingPolicy(putPolicyRequest, authentication.getCallMetadata());
    ScalingPolicyID policyId = Responses.fromSingleValueObservable(putPolicyResult);
    log.info("New policy created {}", policyId);
    return policyId;
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 15 with ScalingPolicyID

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

the class AutoScalingResource method setScalingPolicy.

@POST
@ApiOperation("Create or Update scaling policy")
@Path("scalingPolicy")
public ScalingPolicyID setScalingPolicy(PutPolicyRequest putPolicyRequest) {
    Observable<ScalingPolicyID> putPolicyResult = autoScalingService.setAutoScalingPolicy(putPolicyRequest, resolveCallMetadata());
    ScalingPolicyID policyId = Responses.fromSingleValueObservable(putPolicyResult);
    log.info("New policy created {}", policyId);
    return policyId;
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation)

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