use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class AggregatingLoadBalancerServiceTest method getJobLoadBalancersWithOneFailingCell.
@Test
public void getJobLoadBalancersWithOneFailingCell() {
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<GetJobLoadBalancersResult> resultSubscriber = service.getLoadBalancers(JobId.newBuilder().setId(JOB_1).build(), JUNIT_REST_CALL_METADATA).test();
resultSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
resultSubscriber.assertNoErrors();
final List<GetJobLoadBalancersResult> onNextEvents = resultSubscriber.getOnNextEvents();
assertThat(onNextEvents).hasSize(1);
final List<LoadBalancerId> loadBalancersList = onNextEvents.get(0).getLoadBalancersList();
final List<String> resultLoadBalancers = loadBalancersList.stream().map(loadBalancerId -> loadBalancerId.getId()).collect(Collectors.toList());
assertThat(resultLoadBalancers).contains(LB_1, LB_2);
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class LoadBalancerEngine method moveFromEvents.
private Observable<TargetStateBatchable> moveFromEvents(Observable<TaskUpdateEvent> taskMovedEvents) {
return taskMovedEvents.flatMapIterable(taskMoved -> {
ArrayList<TargetStateBatchable> changes = new ArrayList<>();
Task task = taskMoved.getCurrentTask();
String targetJobId = task.getJobId();
Set<JobLoadBalancer> targetJobLoadBalancers = store.getAssociatedLoadBalancersSetForJob(targetJobId);
String sourceJobId = task.getTaskContext().get(TaskAttributes.TASK_ATTRIBUTES_MOVED_FROM_JOB);
if (StringExt.isEmpty(sourceJobId)) {
invariants.inconsistent("Task moved to %s does not include the source job id: %s", task.getJobId(), task.getId());
return Collections.emptyList();
}
Set<JobLoadBalancer> sourceJobLoadBalancers = store.getAssociatedLoadBalancersSetForJob(sourceJobId);
// register on load balancers associated with the target job
if (TaskHelpers.isStartedWithIp(task)) {
Collection<JobLoadBalancer> toRegister = CollectionsExt.difference(targetJobLoadBalancers, sourceJobLoadBalancers, JobLoadBalancer::byLoadBalancerId);
changes.addAll(updatesForLoadBalancers(toRegister, task, State.REGISTERED));
}
// deregister from load balancers associated with the source job
Collection<JobLoadBalancer> toDeregister = CollectionsExt.difference(sourceJobLoadBalancers, targetJobLoadBalancers, JobLoadBalancer::byLoadBalancerId);
changes.addAll(updatesForLoadBalancers(toDeregister, task, State.DEREGISTERED));
if (!changes.isEmpty()) {
logger.info("Task moved to {} from {}. Jobs are associated with one or more load balancers, generating {} load balancer updates", targetJobId, sourceJobId, changes.size());
}
return changes;
});
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class LoadBalancerCursorsTest method checkMissingCursor.
@Test
public void checkMissingCursor() {
final String cursor = LoadBalancerCursors.newCursorFrom(new JobLoadBalancer("job30", "lb3"));
final Optional<Integer> loadBalancerIndex = LoadBalancerCursors.loadBalancerIndexOf(loadBalancerList, cursor);
assertThat(loadBalancerIndex.isPresent()).isTrue();
assertThat(loadBalancerIndex.get()).isEqualTo(1);
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class CassandraLoadBalancerStoreTest method checkDataSetExists.
/**
* Checks if a provided data set fully exists in the store. The method is
* expected to assert if the check is false.
*
* @throws Exception
*/
private void checkDataSetExists(CassandraLoadBalancerStore store, Map<JobLoadBalancer, JobLoadBalancer.State> testData) throws Exception {
Set<JobLoadBalancer> observableVerificationSet = new HashSet<>(testData.keySet());
Set<JobLoadBalancer> listVerificationSet = new HashSet<>(observableVerificationSet);
Set<String> jobIdSet = getJobIdsFromTestData(testData);
Map<String, List<JobLoadBalancerState>> byJobId = store.getAssociations().stream().collect(Collectors.groupingBy(JobLoadBalancerState::getJobId));
jobIdSet.forEach(jobId -> {
// Verify we get the correct load balancers in the correct state
byJobId.get(jobId).forEach(loadBalancerState -> {
// Verify that all of the returned data was in the test data.
JobLoadBalancer jobLoadBalancer = loadBalancerState.getJobLoadBalancer();
assertThat(jobLoadBalancer.getJobId().equals(jobId)).isTrue();
assertThat(testData.containsKey(jobLoadBalancer)).isTrue();
assertThat(testData.get(jobLoadBalancer)).isEqualTo(loadBalancerState.getState());
// Mark that this job/load balancer was checked
assertThat(observableVerificationSet.contains(jobLoadBalancer)).isTrue();
assertThat(observableVerificationSet.remove(jobLoadBalancer)).isTrue();
logger.debug("Verified job {} has load balancer id {} in state {}", jobId, loadBalancerState.getLoadBalancerId(), loadBalancerState.getState());
});
// Verify the secondary indexes return the correct state
store.getAssociatedLoadBalancersSetForJob(jobId).forEach(jobLoadBalancer -> {
logger.info("Verifying jobLoadBalancer {}", jobLoadBalancer);
assertThat(jobLoadBalancer.getJobId().equals(jobId)).isTrue();
assertThat(testData.containsKey(jobLoadBalancer)).isTrue();
assertThat(testData.get(jobLoadBalancer)).isEqualTo(ASSOCIATED);
// Mark that this job/load balancer was checked
assertThat(listVerificationSet.contains(jobLoadBalancer)).isTrue();
assertThat(listVerificationSet.remove(jobLoadBalancer)).isTrue();
logger.debug("Verified job load balancer {}", jobLoadBalancer);
});
});
// Verify that all of the test data was checked.
assertThat(observableVerificationSet.isEmpty()).isTrue();
assertThat(listVerificationSet.isEmpty()).isTrue();
}
use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.
the class CassandraLoadBalancerStoreTest method generateTestData.
/**
* Returns a map of data to be inserted that can be used for later verification.
*/
private TestData generateTestData(int numJobs, int numLoadBalancersPerJob, int numTasksPerJob) {
Map<JobLoadBalancer, JobLoadBalancer.State> associations = new HashMap<>();
Map<LoadBalancerTarget, LoadBalancerTarget.State> targets = new HashMap<>();
for (int i = 0; i < numJobs; i++) {
String jobId = UUID.randomUUID().toString();
for (int j = 0; j < numLoadBalancersPerJob; j++) {
String loadBalancerId = UUID.randomUUID().toString();
JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, jobId + "-" + loadBalancerId);
associations.put(jobLoadBalancer, ASSOCIATED);
for (int t = 0; t < numTasksPerJob; t++) {
targets.put(new LoadBalancerTarget(loadBalancerId, "task-" + t, String.format("%s.%s.%s.%s", i, t, t, t)), LoadBalancerTarget.State.REGISTERED);
}
}
}
assertThat(associations.size()).isEqualTo(numJobs * numLoadBalancersPerJob);
assertThat(targets.size()).isEqualTo(numJobs * numLoadBalancersPerJob * numTasksPerJob);
return new TestData(associations, targets);
}
Aggregations