Search in sources :

Example 1 with LoadBalancerCursors

use of com.netflix.titus.runtime.loadbalancer.LoadBalancerCursors in project titus-control-plane by Netflix.

the class DefaultLoadBalancerService method getAllLoadBalancers.

@Override
public Pair<List<JobLoadBalancer>, Pagination> getAllLoadBalancers(Page page) {
    if (StringExt.isNotEmpty(page.getCursor())) {
        final List<JobLoadBalancer> allLoadBalancers = loadBalancerStore.getAssociations().stream().map(JobLoadBalancerState::getJobLoadBalancer).sorted(LoadBalancerCursors.loadBalancerComparator()).collect(Collectors.toList());
        return PaginationUtil.takePageWithCursor(Page.newBuilder().withPageSize(page.getPageSize()).withCursor(page.getCursor()).build(), allLoadBalancers, LoadBalancerCursors.loadBalancerComparator(), LoadBalancerCursors::loadBalancerIndexOf, LoadBalancerCursors::newCursorFrom);
    }
    // no cursor provided
    int offset = page.getPageSize() * page.getPageNumber();
    // Grab an extra item so we can tell if there's more to read after offset+limit.
    int limit = page.getPageSize() + 1;
    List<JobLoadBalancer> jobLoadBalancerPageList = loadBalancerStore.getAssociationsPage(offset, limit);
    boolean hasMore = jobLoadBalancerPageList.size() > page.getPageSize();
    jobLoadBalancerPageList = hasMore ? jobLoadBalancerPageList.subList(0, page.getPageSize()) : jobLoadBalancerPageList;
    final String cursor = jobLoadBalancerPageList.isEmpty() ? "" : LoadBalancerCursors.newCursorFrom(jobLoadBalancerPageList.get(jobLoadBalancerPageList.size() - 1));
    return Pair.of(jobLoadBalancerPageList, new Pagination(page, hasMore, 1, jobLoadBalancerPageList.size(), cursor, 0));
}
Also used : Pagination(com.netflix.titus.api.model.Pagination) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) LoadBalancerCursors(com.netflix.titus.runtime.loadbalancer.LoadBalancerCursors) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)

Aggregations

JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)1 JobLoadBalancerState (com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState)1 Pagination (com.netflix.titus.api.model.Pagination)1 LoadBalancerCursors (com.netflix.titus.runtime.loadbalancer.LoadBalancerCursors)1