use of com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource in project titus-control-plane by Netflix.
the class AutoScalingResourceTest method getPoliciesFromTwoCells.
@Test
public void getPoliciesFromTwoCells() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
List<ScalingPolicyID> policyIds = Arrays.asList(policy1, policy2);
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).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 allScalingPolicies = autoScalingResource.getAllScalingPolicies();
assertThat(allScalingPolicies).isNotNull();
assertThat(allScalingPolicies.getItemsCount()).isEqualTo(2);
allScalingPolicies.getItemsList().forEach(scalingPolicyResult -> assertThat(policyIds.contains(scalingPolicyResult.getId())).isTrue());
}
use of com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource in project titus-control-plane by Netflix.
the class AutoScalingResourceTest method getPoliciesFromTwoCellsWithOneFailing.
@Test(expected = RestException.class)
public void getPoliciesFromTwoCellsWithOneFailing() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
CellWithFailingAutoscalingService badCell = new CellWithFailingAutoscalingService();
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(badCell);
final AutoScalingResource autoScalingResource = new AutoScalingResource(service, callMetadataResolver);
autoScalingResource.getAllScalingPolicies();
assertThat(false).isTrue();
}
use of com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource in project titus-control-plane by Netflix.
the class AutoScalingResourceTest method getPolicyByIdFromTwoCells.
@Test
public void getPolicyByIdFromTwoCells() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).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 scalingPolicy = autoScalingResource.getScalingPolicy(POLICY_2);
assertThat(scalingPolicy.getItemsCount()).isEqualTo(1);
assertThat(scalingPolicy.getItems(0).getId().getId()).isEqualTo(POLICY_2);
// bad id
Assertions.assertThatCode(() -> autoScalingResource.getScalingPolicy("badPolicyId")).hasCause(Status.CANCELLED.withDescription("server cancelled stream").asRuntimeException());
}
use of com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource 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.runtime.endpoint.v3.rest.AutoScalingResource 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);
}
Aggregations