use of com.hubspot.singularity.SingularityLoadBalancerUpdate in project Singularity by HubSpot.
the class SingularityDeployChecker method processLbState.
private SingularityDeployResult processLbState(SingularityRequest request, Optional<SingularityDeploy> deploy, SingularityPendingDeploy pendingDeploy, Optional<SingularityUpdatePendingDeployRequest> updatePendingDeployRequest, Collection<SingularityTaskId> deployActiveTasks, Collection<SingularityTaskId> otherActiveTasks, Collection<SingularityTaskId> tasksToShutDown, SingularityLoadBalancerUpdate lbUpdate) {
List<SingularityTaskId> toRemoveFromLb = new ArrayList<>();
for (SingularityTaskId taskId : tasksToShutDown) {
Optional<SingularityLoadBalancerUpdate> maybeRemoveUpdate = taskManager.getLoadBalancerState(taskId, LoadBalancerRequestType.REMOVE);
if (maybeRemoveUpdate.isPresent() && maybeRemoveUpdate.get().getLoadBalancerRequestId().getId().equals(lbUpdate.getLoadBalancerRequestId().getId())) {
toRemoveFromLb.add(taskId);
}
}
updateLoadBalancerStateForTasks(deployActiveTasks, LoadBalancerRequestType.ADD, lbUpdate);
updateLoadBalancerStateForTasks(toRemoveFromLb, LoadBalancerRequestType.REMOVE, lbUpdate);
DeployState deployState = interpretLoadBalancerState(lbUpdate, pendingDeploy.getCurrentDeployState());
if (deployState == DeployState.SUCCEEDED) {
// A step has completed, markStepFinished will determine SUCCEEDED/WAITING
updatePendingDeploy(pendingDeploy, Optional.of(lbUpdate), DeployState.WAITING);
return markStepFinished(pendingDeploy, deploy, deployActiveTasks, otherActiveTasks, request, updatePendingDeployRequest);
} else if (deployState == DeployState.WAITING) {
updatePendingDeploy(pendingDeploy, Optional.of(lbUpdate), deployState);
maybeUpdatePendingRequest(pendingDeploy, deploy, request, updatePendingDeployRequest, Optional.of(lbUpdate));
return new SingularityDeployResult(DeployState.WAITING);
} else {
updatePendingDeploy(pendingDeploy, Optional.of(lbUpdate), deployState);
maybeUpdatePendingRequest(pendingDeploy, deploy, request, updatePendingDeployRequest, Optional.of(lbUpdate));
return new SingularityDeployResult(deployState, lbUpdate, SingularityDeployFailure.lbUpdateFailed());
}
}
use of com.hubspot.singularity.SingularityLoadBalancerUpdate 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());
}
use of com.hubspot.singularity.SingularityLoadBalancerUpdate in project Singularity by HubSpot.
the class LoadBalancerClientImpl method sendBaragonRequest.
private SingularityLoadBalancerUpdate sendBaragonRequest(LoadBalancerRequestId loadBalancerRequestId, BaragonRequest loadBalancerRequest, LoadBalancerMethod method) {
try {
LOG.trace("Preparing to send request {}", loadBalancerRequest);
final BoundRequestBuilder requestBuilder = httpClient.preparePost(loadBalancerUri).addHeader(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON).setBody(objectMapper.writeValueAsBytes(loadBalancerRequest));
if (loadBalancerQueryParams.isPresent()) {
addAllQueryParams(requestBuilder, loadBalancerQueryParams.get());
}
return sendRequestWrapper(loadBalancerRequestId, method, requestBuilder.build(), BaragonRequestState.FAILED);
} catch (IOException e) {
return new SingularityLoadBalancerUpdate(BaragonRequestState.UNKNOWN, loadBalancerRequestId, Optional.of(e.getMessage()), System.currentTimeMillis(), method, Optional.of(loadBalancerUri));
}
}
Aggregations