Search in sources :

Example 1 with SingularityRequestLbCleanup

use of com.hubspot.singularity.SingularityRequestLbCleanup in project Singularity by HubSpot.

the class SingularityCleaner method drainLBRequestCleanupQueue.

private void drainLBRequestCleanupQueue(List<SingularityTaskId> lbCleanupTasks) {
    final long start = System.currentTimeMillis();
    final List<SingularityRequestLbCleanup> lbCleanupRequests = requestManager.getLbCleanupRequests();
    if (lbCleanupRequests.isEmpty()) {
        LOG.trace("LB request cleanup queue is empty");
        return;
    }
    LOG.info("LB request cleanup queue had {} requests", lbCleanupRequests.size());
    AtomicInteger cleanedRequests = new AtomicInteger(0);
    AtomicInteger ignoredRequests = new AtomicInteger(0);
    lbCleanupRequests.parallelStream().forEach((cleanup) -> {
        lock.runWithRequestLock(() -> {
            final long checkStart = System.currentTimeMillis();
            final CheckLBState checkLbState = checkRequestLbState(cleanup, lbCleanupTasks);
            LOG.debug("LB cleanup for request {} had state {} after {}", cleanup.getRequestId(), checkLbState, JavaUtils.duration(checkStart));
            switch(checkLbState) {
                case WAITING:
                case RETRY:
                    return;
                case DONE:
                case MISSING_TASK:
                    cleanedRequests.getAndIncrement();
                    break;
                case NOT_LOAD_BALANCED:
                case LOAD_BALANCE_FAILED:
                    ignoredRequests.getAndIncrement();
            }
            requestManager.deleteLbCleanupRequest(cleanup.getRequestId());
        }, cleanup.getRequestId(), String.format("%s#%s", getClass().getSimpleName(), "drainLBRequestCleanupQueue"));
    });
    LOG.info("LB cleaned {} requests ({} left, {} obsolete) in {}", cleanedRequests, lbCleanupRequests.size() - (ignoredRequests.get() + cleanedRequests.get()), ignoredRequests, JavaUtils.duration(start));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingularityRequestLbCleanup(com.hubspot.singularity.SingularityRequestLbCleanup)

Example 2 with SingularityRequestLbCleanup

use of com.hubspot.singularity.SingularityRequestLbCleanup in project Singularity by HubSpot.

the class SingularityCleaner method createLbCleanupRequest.

private void createLbCleanupRequest(String requestId, Iterable<SingularityTaskId> matchingActiveTaskIds) {
    Optional<String> maybeCurrentDeployId = deployManager.getInUseDeployId(requestId);
    Optional<SingularityDeploy> maybeDeploy = Optional.absent();
    if (maybeCurrentDeployId.isPresent()) {
        maybeDeploy = deployManager.getDeploy(requestId, maybeCurrentDeployId.get());
        if (maybeDeploy.isPresent()) {
            List<String> taskIds = new ArrayList<>();
            for (SingularityTaskId taskId : matchingActiveTaskIds) {
                taskIds.add(taskId.getId());
            }
            requestManager.saveLbCleanupRequest(new SingularityRequestLbCleanup(requestId, maybeDeploy.get().getLoadBalancerGroups().get(), maybeDeploy.get().getServiceBasePath().get(), taskIds, Optional.absent()));
            return;
        }
    }
    exceptionNotifier.notify("Insufficient data to create LB request cleanup", ImmutableMap.of("requestId", requestId, "deployId", maybeCurrentDeployId.toString(), "deploy", maybeDeploy.toString()));
}
Also used : ArrayList(java.util.ArrayList) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) SingularityRequestLbCleanup(com.hubspot.singularity.SingularityRequestLbCleanup)

Example 3 with SingularityRequestLbCleanup

use of com.hubspot.singularity.SingularityRequestLbCleanup in project Singularity by HubSpot.

the class SingularitySchedulerTest method testPauseLbCleanup.

@Test
public void testPauseLbCleanup() {
    initLoadBalancedRequest();
    initFirstDeploy();
    requestManager.saveLbCleanupRequest(new SingularityRequestLbCleanup(requestId, Sets.newHashSet("test"), "/basepath", Collections.<String>emptyList(), Optional.<SingularityLoadBalancerUpdate>absent()));
    requestManager.pause(request, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent());
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING);
    cleaner.drainCleanupQueue();
    Assert.assertTrue(!requestManager.getLbCleanupRequestIds().isEmpty());
    Optional<SingularityLoadBalancerUpdate> lbUpdate = requestManager.getLbCleanupRequest(requestId).get().getLoadBalancerUpdate();
    Assert.assertTrue(lbUpdate.isPresent());
    Assert.assertTrue(lbUpdate.get().getLoadBalancerState() == BaragonRequestState.WAITING);
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.FAILED);
    cleaner.drainCleanupQueue();
    Assert.assertTrue(!requestManager.getLbCleanupRequestIds().isEmpty());
    lbUpdate = requestManager.getLbCleanupRequest(requestId).get().getLoadBalancerUpdate();
    Assert.assertTrue(lbUpdate.isPresent());
    Assert.assertTrue(lbUpdate.get().getLoadBalancerState() == BaragonRequestState.FAILED);
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS);
    cleaner.drainCleanupQueue();
    Assert.assertTrue(requestManager.getLbCleanupRequestIds().isEmpty());
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) SingularityRequestLbCleanup(com.hubspot.singularity.SingularityRequestLbCleanup) Test(org.junit.Test)

Aggregations

SingularityRequestLbCleanup (com.hubspot.singularity.SingularityRequestLbCleanup)3 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)1 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)1 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1