Search in sources :

Example 21 with ScalingPolicyID

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

the class AutoScalingResourceTest method createAndDeletePolicyForJobIdFromTwoCells.

@Test
public void createAndDeletePolicyForJobIdFromTwoCells() {
    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);
    final Response deleteResponse = autoScalingResource.removePolicy(scalingPolicyId.getId());
    assertThat(deleteResponse.getStatus()).isEqualTo(200);
    final GetPolicyResult scalingPolicyForJobResult = autoScalingResource.getScalingPolicyForJob(JOB_2);
    assertThat(scalingPolicyForJobResult).isNotNull();
    assertThat(scalingPolicyForJobResult.getItemsCount()).isEqualTo(1);
    assertThat(scalingPolicyForJobResult.getItems(0).getJobId()).isEqualTo(JOB_2);
}
Also used : Response(javax.ws.rs.core.Response) 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)

Example 22 with ScalingPolicyID

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

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

the class AutoScalingResourceTest 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);
    final AutoScalingResource autoScalingResource = new AutoScalingResource(service, callMetadataResolver);
    final GetPolicyResult scalingPolicyForJob = autoScalingResource.getScalingPolicyForJob(JOB_2);
    assertThat(scalingPolicyForJob).isNotNull();
    assertThat(scalingPolicyForJob.getItemsCount()).isEqualTo(1);
    assertThat(scalingPolicyForJob.getItems(0).getJobId()).isEqualTo(JOB_2);
}
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)

Example 24 with ScalingPolicyID

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

the class CellWithPolicies method setAutoScalingPolicy.

@Override
public void setAutoScalingPolicy(PutPolicyRequest request, StreamObserver<ScalingPolicyID> responseObserver) {
    ScalingPolicyID newPolicyId = ScalingPolicyID.newBuilder().setId(UUID.randomUUID().toString()).build();
    ScalingPolicyResult newPolicyResult = ScalingPolicyResult.newBuilder().setId(newPolicyId).setJobId(request.getJobId()).build();
    policyMap.put(newPolicyId.getId(), newPolicyResult);
    responseObserver.onNext(newPolicyId);
    responseObserver.onCompleted();
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult)

Example 25 with ScalingPolicyID

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

the class DefaultAutoScalingServiceGrpcTest method testDeletePolicyId.

/**
 * Tests deleting policies by Ref ID.
 *
 * @throws Exception
 */
@Test
public void testDeletePolicyId() throws Exception {
    String jobId = "Titus-123";
    ScalingPolicyID scalingPolicyID = putPolicyWithJobId(jobId, PolicyType.StepScaling);
    DeletePolicyRequest deletePolicyRequest = DeletePolicyRequest.newBuilder().setId(scalingPolicyID).build();
    TestStreamObserver<Empty> deleteResponse = new TestStreamObserver<>();
    service.deleteAutoScalingPolicy(deletePolicyRequest, deleteResponse);
    deleteResponse.awaitDone();
    AutoScalingPolicyTests.waitForCondition(() -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        service.getScalingPolicy(scalingPolicyID, getResponse);
        GetPolicyResult getPolicyResult = getResponse.takeNext();
        return getPolicyResult.getItemsCount() == 1 && getPolicyResult.getItems(0).getPolicyState().getState() == Deleted;
    });
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    service.getScalingPolicy(scalingPolicyID, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext();
    // Check that the policy still exists but the state is updated
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    assertThat(getPolicyResult.getItems(0).getPolicyState().getState()).isEqualTo(Deleted);
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) 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)

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