use of com.netflix.titus.grpc.protogen.ScalingPolicyResult 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.ScalingPolicyResult 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.ScalingPolicyResult 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.ScalingPolicyResult 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.ScalingPolicyResult in project titus-control-plane by Netflix.
the class CellWithPolicies method updateAutoScalingPolicy.
@Override
public void updateAutoScalingPolicy(UpdatePolicyRequest request, StreamObserver<Empty> responseObserver) {
if (policyMap.containsKey(request.getPolicyId().getId())) {
ScalingPolicyResult currentPolicy = policyMap.get(request.getPolicyId().getId());
ScalingPolicyResult updatePolicy = ScalingPolicyResult.newBuilder().setId(currentPolicy.getId()).setJobId(currentPolicy.getJobId()).setScalingPolicy(request.getScalingPolicy()).build();
policyMap.put(currentPolicy.getId().getId(), updatePolicy);
responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onCompleted();
} else {
responseObserver.onError(new IllegalArgumentException(request.getPolicyId().getId() + " is Invalid"));
}
}
Aggregations