All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.hubspot.singularity.resources.AbstractRequestResource Maven / Gradle / Ivy
package com.hubspot.singularity.resources;
import static com.hubspot.singularity.WebExceptions.checkNotFound;
import org.apache.curator.framework.recipes.leader.LeaderLatch;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Optional;
import com.hubspot.singularity.SingularityAuthorizationScope;
import com.hubspot.singularity.SingularityDeploy;
import com.hubspot.singularity.SingularityDeployMarker;
import com.hubspot.singularity.SingularityPendingDeploy;
import com.hubspot.singularity.SingularityRequest;
import com.hubspot.singularity.SingularityRequestDeployState;
import com.hubspot.singularity.SingularityRequestParent;
import com.hubspot.singularity.SingularityRequestWithState;
import com.hubspot.singularity.SingularityUser;
import com.hubspot.singularity.auth.SingularityAuthorizationHelper;
import com.hubspot.singularity.data.DeployManager;
import com.hubspot.singularity.data.RequestManager;
import com.hubspot.singularity.data.SingularityValidator;
import com.hubspot.singularity.data.history.RequestHistoryHelper;
import com.hubspot.singularity.helpers.RequestHelper;
import com.ning.http.client.AsyncHttpClient;
public class AbstractRequestResource extends AbstractLeaderAwareResource {
protected final RequestManager requestManager;
protected final DeployManager deployManager;
protected final RequestHelper requestHelper;
private final RequestHistoryHelper requestHistoryHelper;
protected final SingularityValidator validator;
protected final SingularityAuthorizationHelper authorizationHelper;
public AbstractRequestResource(RequestManager requestManager, DeployManager deployManager, SingularityValidator validator, SingularityAuthorizationHelper authorizationHelper,
AsyncHttpClient httpClient, LeaderLatch leaderLatch, ObjectMapper objectMapper, RequestHelper requestHelper, RequestHistoryHelper requestHistoryHelper) {
super(httpClient, leaderLatch, objectMapper);
this.requestManager = requestManager;
this.deployManager = deployManager;
this.requestHelper = requestHelper;
this.requestHistoryHelper = requestHistoryHelper;
this.validator = validator;
this.authorizationHelper = authorizationHelper;
}
protected SingularityRequestWithState fetchRequestWithState(String requestId, SingularityUser user) {
return fetchRequestWithState(requestId, false, user);
}
protected SingularityRequestWithState fetchRequestWithState(String requestId, boolean useWebCache, SingularityUser user) {
Optional request = requestManager.getRequest(requestId, useWebCache);
checkNotFound(request.isPresent(), "Couldn't find request with id %s", requestId);
authorizationHelper.checkForAuthorization(request.get().getRequest(), user, SingularityAuthorizationScope.READ);
return request.get();
}
protected SingularityRequestParent fillEntireRequest(SingularityRequestWithState requestWithState) {
return fillEntireRequest(requestWithState, Optional.absent());
}
protected SingularityRequestParent fillEntireRequest(SingularityRequestWithState requestWithState, Optional newRequestData) {
final String requestId = requestWithState.getRequest().getId();
final Optional requestDeployState = deployManager.getRequestDeployState(requestId);
Optional activeDeploy = Optional.absent();
Optional pendingDeploy = Optional.absent();
if (requestDeployState.isPresent()) {
activeDeploy = fillDeploy(requestDeployState.get().getActiveDeploy());
pendingDeploy = fillDeploy(requestDeployState.get().getPendingDeploy());
}
Optional pendingDeployState = deployManager.getPendingDeploy(requestId);
return new SingularityRequestParent(newRequestData.or(requestWithState.getRequest()), requestWithState.getState(), requestDeployState, activeDeploy, pendingDeploy, pendingDeployState,
requestManager.getExpiringBounce(requestId), requestManager.getExpiringPause(requestId), requestManager.getExpiringScale(requestId),
requestManager.getExpiringSkipHealthchecks(requestId), requestHelper.getTaskIdsByStatusForRequest(requestId), requestHistoryHelper.getLastHistory(requestId),
requestHelper.getMostRecentTask(requestWithState.getRequest()));
}
protected Optional fillDeploy(Optional deployMarker) {
if (!deployMarker.isPresent()) {
return Optional.absent();
}
return deployManager.getDeploy(deployMarker.get().getRequestId(), deployMarker.get().getDeployId());
}
}