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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations