Search in sources :

Example 11 with SingularityLoadBalancerUpdate

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());
    }
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) DeployState(com.hubspot.singularity.DeployState) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult) ArrayList(java.util.ArrayList) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 12 with SingularityLoadBalancerUpdate

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());
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) SingularityRequestLbCleanup(com.hubspot.singularity.SingularityRequestLbCleanup) Test(org.junit.Test)

Example 13 with SingularityLoadBalancerUpdate

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));
    }
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Aggregations

SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)13 LoadBalancerRequestId (com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId)5 SingularityTask (com.hubspot.singularity.SingularityTask)4 SingularityDeployResult (com.hubspot.singularity.SingularityDeployResult)3 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)3 DeployState (com.hubspot.singularity.DeployState)2 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)2 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)2 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)2 DeployHealth (com.hubspot.singularity.scheduler.SingularityDeployHealthHelper.DeployHealth)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 SingularityRequestLbCleanup (com.hubspot.singularity.SingularityRequestLbCleanup)1 SingularityTaskHistory (com.hubspot.singularity.SingularityTaskHistory)1 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)1 SimplifiedTaskState (com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState)1 SingularityTaskMetadata (com.hubspot.singularity.SingularityTaskMetadata)1