use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class DefaultLoadBalancerReconcilerTest method updatesAreIgnoredWhileCooldownIsActive.
@Test(timeout = TEST_TIMEOUT_MS)
public void updatesAreIgnoredWhileCooldownIsActive() {
long cooldownPeriodMs = 5 * delayMs;
List<Task> tasks = LoadBalancerTests.buildTasksStarted(5, jobId);
JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
JobLoadBalancerState association = new JobLoadBalancerState(jobLoadBalancer, State.ASSOCIATED);
when(v3JobOperations.getTasks(jobId)).thenReturn(tasks);
store.addOrUpdateLoadBalancer(association.getJobLoadBalancer(), association.getState()).await();
for (Task task : tasks) {
String ipAddress = task.getTaskContext().get(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP);
LoadBalancerTarget target = new LoadBalancerTarget(loadBalancerId, task.getId(), ipAddress);
reconciler.activateCooldownFor(target, cooldownPeriodMs, TimeUnit.MILLISECONDS);
}
testScheduler.triggerActions();
subscriber.assertNotCompleted().assertNoValues();
// no updates while cooldown is active in the first iteration
awaitReconciliationRuns(1);
subscriber.assertNotCompleted().assertNoValues();
awaitReconciliationRuns(4);
subscriber.assertNotCompleted().assertValueCount(5);
subscriber.getOnNextEvents().forEach(update -> {
assertThat(update.getState()).isEqualTo(LoadBalancerTarget.State.REGISTERED);
assertThat(update.getPriority()).isEqualTo(Priority.LOW);
assertThat(update.getLoadBalancerId()).isEqualTo(loadBalancerId);
});
// try again since it still can't see updates applied on the connector
awaitReconciliationRuns(1);
subscriber.assertNotCompleted().assertValueCount(10);
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class DefaultLoadBalancerServiceTest method removeLoadBalancerDeregisterKnownTargets.
@Test
public void removeLoadBalancerDeregisterKnownTargets() {
String jobId = UUID.randomUUID().toString();
String loadBalancerId = "lb-" + UUID.randomUUID().toString();
JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
defaultStubs();
LoadBalancerTests.applyValidGetJobMock(v3JobOperations, jobId);
List<Task> tasks = LoadBalancerTests.buildTasksStarted(5, jobId);
Collection<LoadBalancerTargetState> expectedTargets = tasks.stream().map(task -> new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, task.getId(), task.getTaskContext().get(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP)), // final state expected after updates are applied
DEREGISTERED)).collect(Collectors.toList());
when(v3JobOperations.getTasks(jobId)).thenReturn(CollectionsExt.merge(tasks, LoadBalancerTests.buildTasks(2, jobId, TaskState.StartInitiated), LoadBalancerTests.buildTasks(2, jobId, TaskState.KillInitiated), LoadBalancerTests.buildTasks(3, jobId, TaskState.Finished), LoadBalancerTests.buildTasks(1, jobId, TaskState.Disconnected)));
LoadBalancerConfiguration configuration = LoadBalancerTests.mockConfiguration(MIN_TIME_IN_QUEUE_MS);
DefaultLoadBalancerService service = new DefaultLoadBalancerService(runtime, configuration, client, loadBalancerStore, loadBalancerJobOperations, reconciler, validator, testScheduler);
AssertableSubscriber<Batch<TargetStateBatchable, String>> testSubscriber = service.events().test();
assertTrue(loadBalancerStore.addOrUpdateLoadBalancer(jobLoadBalancer, JobLoadBalancer.State.ASSOCIATED).await(100, TimeUnit.MILLISECONDS));
assertTrue(service.removeLoadBalancer(jobId, loadBalancerId).await(100, TimeUnit.MILLISECONDS));
List<JobLoadBalancerState> jobLoadBalancers = loadBalancerStore.getAssociations().stream().filter(association -> jobId.equals(association.getJobId())).collect(Collectors.toList());
assertThat(jobLoadBalancers).isNotEmpty();
assertThat(jobLoadBalancers).hasSize(1);
JobLoadBalancerState jobLoadBalancerState = jobLoadBalancers.iterator().next();
assertEquals(loadBalancerId, jobLoadBalancerState.getLoadBalancerId());
assertEquals(JobLoadBalancer.State.DISSOCIATED, jobLoadBalancerState.getState());
assertFalse(service.getJobLoadBalancers(jobId).toBlocking().getIterator().hasNext());
testScheduler.advanceTimeBy(FLUSH_WAIT_TIME_MS, TimeUnit.MILLISECONDS);
testSubscriber.assertNoErrors().assertValueCount(1);
assertThat(loadBalancerStore.getLoadBalancerTargets(loadBalancerId).collectList().block()).containsExactlyInAnyOrderElementsOf(expectedTargets);
verify(client, never()).registerAll(eq(loadBalancerId), any());
verify(client).deregisterAll(eq(loadBalancerId), argThat(targets -> targets != null && targets.size() == tasks.size()));
verifyReconcilerIgnore(loadBalancerId, LoadBalancerTests.ipAddresses(tasks));
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class GrpcModelConverters method toGetAllLoadBalancersResult.
public static GetAllLoadBalancersResult toGetAllLoadBalancersResult(List<JobLoadBalancer> jobLoadBalancerList, Pagination runtimePagination) {
GetAllLoadBalancersResult.Builder allLoadBalancersResult = GetAllLoadBalancersResult.newBuilder();
allLoadBalancersResult.setPagination(toGrpcPagination(runtimePagination));
// We expect the list to be in a sorted-by-jobId order and iterate as such
GetJobLoadBalancersResult.Builder getJobLoadBalancersResultBuilder = GetJobLoadBalancersResult.newBuilder();
Set<String> addedJobIds = new HashSet<>();
for (JobLoadBalancer jobLoadBalancer : jobLoadBalancerList) {
String jobId = jobLoadBalancer.getJobId();
// Check if we're processing a new Job ID
if (!addedJobIds.contains(jobId)) {
// Add any previous JobID's result if it existed
if (getJobLoadBalancersResultBuilder.getLoadBalancersBuilderList().size() > 0) {
allLoadBalancersResult.addJobLoadBalancers(getJobLoadBalancersResultBuilder.build());
}
getJobLoadBalancersResultBuilder = GetJobLoadBalancersResult.newBuilder().setJobId(jobId);
addedJobIds.add(jobId);
}
getJobLoadBalancersResultBuilder.addLoadBalancers(LoadBalancerId.newBuilder().setId(jobLoadBalancer.getLoadBalancerId()).build());
}
if (getJobLoadBalancersResultBuilder.getLoadBalancersBuilderList().size() > 0) {
allLoadBalancersResult.addJobLoadBalancers(getJobLoadBalancersResultBuilder.build());
}
return allLoadBalancersResult.build();
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class LoadBalancerCursors method loadBalancerIndexOf.
public static Optional<Integer> loadBalancerIndexOf(List<JobLoadBalancer> sortedLoadBalancers, String cursor) {
return decode(cursor).map(p -> {
final JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(p.getLeft(), p.getRight());
final int idx = Collections.binarySearch(sortedLoadBalancers, jobLoadBalancer, loadBalancerComparator());
return idx >= 0 ? idx : Math.max(-1, -idx - 2);
});
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class LoadBalancerCursorsTest method checkFirstMissingCursorElement.
@Test
public void checkFirstMissingCursorElement() {
final String cursor = LoadBalancerCursors.newCursorFrom(new JobLoadBalancer("job1", "lb0"));
final Optional<Integer> loadBalancerIndex = LoadBalancerCursors.loadBalancerIndexOf(loadBalancerList, cursor);
assertThat(loadBalancerIndex.isPresent()).isTrue();
assertThat(loadBalancerIndex.get()).isEqualTo(-1);
}
Aggregations