use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class LoadBalancerCursorsTest method checkValidCursor.
@Test
public void checkValidCursor() {
final String cursor = LoadBalancerCursors.newCursorFrom(new JobLoadBalancer("job3", "lb3"));
final Optional<Integer> loadBalancerIndex = LoadBalancerCursors.loadBalancerIndexOf(loadBalancerList, cursor);
assertThat(loadBalancerIndex.isPresent()).isTrue();
assertThat(loadBalancerIndex.get()).isEqualTo(2);
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class DefaultLoadBalancerJobValidatorTest method testValidateMaxLoadBalancers.
@Test
public void testValidateMaxLoadBalancers() throws Exception {
when(jobOperations.getJob(JOB_ID)).thenReturn(Optional.of(Job.<ServiceJobExt>newBuilder().withId(JOB_ID).withStatus(JobStatus.newBuilder().withState(JobState.Accepted).build()).withJobDescriptor(JobDescriptor.<ServiceJobExt>newBuilder().withExtensions(ServiceJobExt.newBuilder().build()).withContainer(Container.newBuilder().withImage(Image.newBuilder().build()).withContainerResources(ContainerResources.newBuilder().withAllocateIP(true).build()).build()).build()).build()));
when(loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob()).thenReturn(30);
for (int i = 0; i < loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob() + 1; i++) {
loadBalancerStore.addOrUpdateLoadBalancer(new JobLoadBalancer(JOB_ID, "LoadBalancer-" + i), JobLoadBalancer.State.ASSOCIATED).await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
Throwable thrown = catchThrowable(() -> loadBalancerValidator.validateJobId(JOB_ID));
assertThat(thrown).isInstanceOf(LoadBalancerException.class);
assertThat(((LoadBalancerException) thrown).getErrorCode()).isEqualTo(LoadBalancerException.ErrorCode.JobMaxLoadBalancers);
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class AggregatingLoadBalancerServiceTest method getLoadBalancersForJob.
@Test
public void getLoadBalancersForJob() {
JobLoadBalancer jobLoadBalancer1 = new JobLoadBalancer(JOB_1, LB_1);
JobLoadBalancer jobLoadBalancer2 = new JobLoadBalancer(JOB_2, LB_2);
final CellWithLoadBalancers cellWithLoadBalancersOne = new CellWithLoadBalancers(singletonList(jobLoadBalancer1));
final CellWithLoadBalancers cellWithLoadBalancersTwo = new CellWithLoadBalancers(singletonList(jobLoadBalancer2));
cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne);
cellTwo.getServiceRegistry().addService(cellWithLoadBalancersTwo);
final AssertableSubscriber<GetJobLoadBalancersResult> resultSubscriber = service.getLoadBalancers(JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
resultSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
resultSubscriber.assertNoErrors();
final List<GetJobLoadBalancersResult> onNextEvents = resultSubscriber.getOnNextEvents();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getJobId()).isEqualTo(JOB_2);
assertThat(onNextEvents.get(0).getLoadBalancersCount()).isEqualTo(1);
assertThat(onNextEvents.get(0).getLoadBalancers(0).getId()).isEqualTo(LB_2);
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class AggregatingLoadBalancerServiceTest method removeLoadBalancer.
@Test
public void removeLoadBalancer() {
JobLoadBalancer jobLoadBalancer1 = new JobLoadBalancer(JOB_1, LB_1);
JobLoadBalancer jobLoadBalancer2 = new JobLoadBalancer(JOB_2, LB_2);
JobLoadBalancer jobLoadBalancer3 = new JobLoadBalancer(JOB_2, LB_3);
final CellWithLoadBalancers cellWithLoadBalancersOne = new CellWithLoadBalancers(singletonList(jobLoadBalancer1));
final CellWithLoadBalancers cellWithLoadBalancersTwo = new CellWithLoadBalancers(new ArrayList<>(Arrays.asList(jobLoadBalancer2, jobLoadBalancer3)));
final CellWithJobIds cellWithJobIdsOne = new CellWithJobIds(singletonList(JOB_1));
final CellWithJobIds cellWithJobIdsTwo = new CellWithJobIds(singletonList(JOB_2));
cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne);
cellOne.getServiceRegistry().addService(cellWithJobIdsOne);
cellTwo.getServiceRegistry().addService(cellWithLoadBalancersTwo);
cellTwo.getServiceRegistry().addService(cellWithJobIdsTwo);
final AssertableSubscriber<Void> resultSubscriber = service.removeLoadBalancer(RemoveLoadBalancerRequest.newBuilder().setJobId(JOB_2).setLoadBalancerId(LoadBalancerId.newBuilder().setId(LB_2).build()).build(), JUNIT_REST_CALL_METADATA).test();
resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
resultSubscriber.assertNoErrors();
resultSubscriber.assertNoValues();
resultSubscriber.assertCompleted();
final AssertableSubscriber<GetJobLoadBalancersResult> jobResults = service.getLoadBalancers(JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
jobResults.awaitValueCount(1, 1, TimeUnit.SECONDS);
jobResults.assertNoErrors();
final List<GetJobLoadBalancersResult> onNextEvents = jobResults.getOnNextEvents();
assertThat(onNextEvents.size()).isEqualTo(1);
final List<LoadBalancerId> loadBalancersList = onNextEvents.get(0).getLoadBalancersList();
assertThat(loadBalancersList.size()).isEqualTo(1);
assertThat(loadBalancersList.get(0).getId()).isEqualTo(LB_3);
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class AggregatingLoadBalancerServiceTest method getLoadBalancersWithOneFailingCell.
@Test
public void getLoadBalancersWithOneFailingCell() {
JobLoadBalancer jobLoadBalancer1 = new JobLoadBalancer(JOB_1, LB_1);
JobLoadBalancer jobLoadBalancer2 = new JobLoadBalancer(JOB_1, LB_2);
final CellWithLoadBalancers cellWithLoadBalancersOne = new CellWithLoadBalancers(Arrays.asList(jobLoadBalancer1, jobLoadBalancer2));
cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne);
cellTwo.getServiceRegistry().addService(new CellWithFailingLoadBalancers(Status.INTERNAL));
final AssertableSubscriber<GetAllLoadBalancersResult> resultSubscriber = service.getAllLoadBalancers(GetAllLoadBalancersRequest.newBuilder().setPage(Page.newBuilder().setPageSize(10)).build(), JUNIT_REST_CALL_METADATA).test();
resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
resultSubscriber.assertNoValues();
final List<Throwable> onErrorEvents = resultSubscriber.getOnErrorEvents();
assertThat(onErrorEvents).hasSize(1);
assertThat(Status.fromThrowable(onErrorEvents.get(0))).isEqualTo(Status.INTERNAL);
}
Aggregations