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