Search in sources :

Example 1 with SingularityDeployKey

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

the class PendingRequestDataMigration method applyMigration.

@Override
public void applyMigration() {
    String basePath = "/requests/pending";
    LOG.warn("Starting migration to re-write pending request paths");
    long start = System.currentTimeMillis();
    int rewrittenPaths = 0;
    try {
        if (curator.checkExists().forPath(basePath) == null) {
            return;
        }
    } catch (Exception exn) {
        LOG.error("Could not check existence of pending request path", exn);
        throw new RuntimeException(exn);
    }
    try {
        List<String> childPaths = curator.getChildren().forPath(basePath);
        for (String childPath : childPaths) {
            SingularityPendingRequest pendingRequest = requestTranscoder.fromBytes(curator.getData().forPath(String.format("%s/%s", basePath, childPath)));
            if (pendingRequest.getPendingType() == PendingType.IMMEDIATE) {
                String rewrittenPath = new SingularityDeployKey(pendingRequest.getRequestId(), pendingRequest.getDeployId()).getId();
                LOG.warn("Rewriting path {} to {}", childPath, String.format("%s%s", rewrittenPath, pendingRequest.getTimestamp()));
                requestManager.addToPendingQueue(pendingRequest);
                curator.delete().forPath(String.format("%s/%s", basePath, childPath));
                rewrittenPaths += 1;
            } else {
                LOG.warn("Not rewriting path {}, already correct", childPath);
            }
        }
    } catch (Exception exn) {
        LOG.error("Connection to Zookeeper failed while running migration", exn);
        throw new RuntimeException(exn);
    }
    LOG.warn("Applied PendingRequestDataMigration to {} requests in {}", rewrittenPaths, JavaUtils.duration(start));
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest)

Example 2 with SingularityDeployKey

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

the class DeployManager method getDeploysForKeys.

public Map<SingularityDeployKey, SingularityDeploy> getDeploysForKeys(Collection<SingularityDeployKey> deployKeys) {
    final List<String> paths = Lists.newArrayListWithCapacity(deployKeys.size());
    for (SingularityDeployKey deployKey : deployKeys) {
        paths.add(getDeployDataPath(deployKey.getRequestId(), deployKey.getDeployId()));
    }
    final List<SingularityDeploy> deploys = getAsync("getDeploysForKeys", paths, deployTranscoder, deploysCache);
    final Map<SingularityDeployKey, SingularityDeploy> deployKeyToDeploy = Maps.uniqueIndex(deploys, new Function<SingularityDeploy, SingularityDeployKey>() {

        @Override
        public SingularityDeployKey apply(SingularityDeploy input) {
            return SingularityDeployKey.fromDeploy(input);
        }
    });
    return deployKeyToDeploy;
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityDeploy(com.hubspot.singularity.SingularityDeploy)

Example 3 with SingularityDeployKey

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

the class DeployHistoryHelper method getFromZk.

@Override
protected List<SingularityDeployHistory> getFromZk(String requestId) {
    final List<SingularityDeployKey> deployKeys = deployManager.getDeployIdsFor(requestId);
    final List<SingularityDeployHistory> histories = Lists.newArrayListWithCapacity(deployKeys.size());
    for (SingularityDeployKey key : deployKeys) {
        Optional<SingularityDeployHistory> deployHistory = deployManager.getDeployHistory(key.getRequestId(), key.getDeployId(), false);
        if (deployHistory.isPresent()) {
            histories.add(deployHistory.get());
        }
    }
    Collections.sort(histories);
    return histories;
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityDeployHistory(com.hubspot.singularity.SingularityDeployHistory)

Example 4 with SingularityDeployKey

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

the class SingularityDeployHistoryPersister method runActionOnPoll.

@Override
public void runActionOnPoll() {
    LOG.info("Checking inactive deploys for deploy history persistance");
    final long start = System.currentTimeMillis();
    final List<SingularityDeployKey> allDeployIds = deployManager.getAllDeployIds();
    final Map<String, SingularityRequestDeployState> byRequestId = deployManager.getAllRequestDeployStatesByRequestId();
    final TreeMultimap<String, SingularityDeployHistory> deployHistoryByRequestId = TreeMultimap.create();
    int numTotal = 0;
    int numTransferred = 0;
    for (SingularityDeployKey deployKey : allDeployIds) {
        SingularityRequestDeployState deployState = byRequestId.get(deployKey.getRequestId());
        if (!shouldTransferDeploy(deployState, deployKey)) {
            continue;
        }
        Optional<SingularityDeployHistory> deployHistory = deployManager.getDeployHistory(deployKey.getRequestId(), deployKey.getDeployId(), true);
        if (deployHistory.isPresent()) {
            deployHistoryByRequestId.put(deployKey.getRequestId(), deployHistory.get());
        } else {
            LOG.info("Deploy history for key {} not found", deployKey);
        }
    }
    for (Collection<SingularityDeployHistory> deployHistoryForRequest : deployHistoryByRequestId.asMap().values()) {
        int i = 0;
        for (SingularityDeployHistory deployHistory : deployHistoryForRequest) {
            if (moveToHistoryOrCheckForPurge(deployHistory, i++)) {
                numTransferred++;
            }
            numTotal++;
        }
    }
    LOG.info("Transferred {} out of {} deploys in {}", numTransferred, numTotal, JavaUtils.duration(start));
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityDeployHistory(com.hubspot.singularity.SingularityDeployHistory) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState)

Example 5 with SingularityDeployKey

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

the class SingularityClient method createDeployForSingularityRequest.

public SingularityRequestParent createDeployForSingularityRequest(String requestId, SingularityDeploy pendingDeploy, Optional<Boolean> deployUnpause, Optional<String> message, Optional<SingularityRequest> updatedRequest) {
    final Function<String, String> requestUri = (String host) -> String.format(DEPLOYS_FORMAT, getApiBase(host));
    HttpResponse response = post(requestUri, String.format("new deploy %s", new SingularityDeployKey(requestId, pendingDeploy.getId())), Optional.of(new SingularityDeployRequest(pendingDeploy, deployUnpause, message, updatedRequest)));
    return getAndLogRequestAndDeployStatus(response.getAs(SingularityRequestParent.class));
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) HttpResponse(com.hubspot.horizon.HttpResponse) SingularityRequestParent(com.hubspot.singularity.SingularityRequestParent)

Aggregations

SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)19 SingularityRequest (com.hubspot.singularity.SingularityRequest)7 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)7 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)6 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)6 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)6 ArrayList (java.util.ArrayList)6 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)5 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)5 Optional (com.google.common.base.Optional)3 ImmutableList (com.google.common.collect.ImmutableList)3 Inject (com.google.inject.Inject)3 HttpResponse (com.hubspot.horizon.HttpResponse)3 ExtendedTaskState (com.hubspot.singularity.ExtendedTaskState)3 MachineState (com.hubspot.singularity.MachineState)3 SingularityTask (com.hubspot.singularity.SingularityTask)3 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)3 SingularityTaskShellCommandUpdate (com.hubspot.singularity.SingularityTaskShellCommandUpdate)3 List (java.util.List)3 Map (java.util.Map)3