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));
}
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()));
}
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());
}
Aggregations