Search in sources :

Example 1 with ReviewResult

use of com.linkedin.kafka.cruisecontrol.servlet.response.ReviewResult in project cruise-control by linkedin.

the class Purgatory method addRequest.

/**
 * Add request to the purgatory and return the {@link ReviewResult} for the request that has been added to
 * the purgatory.
 *
 * @param request Http Servlet Request to add to the purgatory.
 * @param parameters Request parameters.
 * @param <P> Type corresponding to the request parameters.
 * @return The result showing the {@link ReviewResult} for the request that has been added to the purgatory.
 */
private synchronized <P extends CruiseControlParameters> ReviewResult addRequest(HttpServletRequest request, P parameters) {
    if (!request.getMethod().equals(POST_METHOD)) {
        throw new IllegalArgumentException(String.format("Purgatory can only contain POST request (Attempted to add: %s).", httpServletRequestToString(request)));
    }
    RequestInfo requestInfo = new RequestInfo(request, parameters);
    _requestInfoById.put(_requestId, requestInfo);
    Map<Integer, RequestInfo> requestInfoById = new HashMap<>();
    requestInfoById.put(_requestId, requestInfo);
    Set<Integer> filteredRequestIds = new HashSet<>();
    filteredRequestIds.add(_requestId);
    ReviewResult result = new ReviewResult(requestInfoById, filteredRequestIds, _config);
    _requestId++;
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ReviewResult(com.linkedin.kafka.cruisecontrol.servlet.response.ReviewResult) HashSet(java.util.HashSet)

Example 2 with ReviewResult

use of com.linkedin.kafka.cruisecontrol.servlet.response.ReviewResult in project cruise-control by linkedin.

the class Purgatory method maybeAddToPurgatory.

/**
 * Add the given request to the purgatory unless:
 * <ul>
 *   <li>Request is already in the purgatory and contains the corresponding reviewId to retrieve its parameters.</li>
 *   <li>Request contains invalid parameter names.</li>
 *   <li>Parameters specified in the request cannot be parsed.</li>
 * </ul>
 *
 * @param request HTTP request received by Cruise Control.
 * @param response HTTP response of Cruise Control. Populated in case the request is not already in the purgatory.
 * @param classConfig Config indicating the class of the pluggable parameter.
 * @param parameterConfigOverrides Configs to override upon creating the pluggable parameter.
 * @param userTaskManager a reference to {@link UserTaskManager}
 * @return Parameters of the request if it is in the purgatory, and requested with the corresponding reviewId,
 * {@code null} otherwise.
 */
public CruiseControlParameters maybeAddToPurgatory(HttpServletRequest request, HttpServletResponse response, String classConfig, Map<String, Object> parameterConfigOverrides, UserTaskManager userTaskManager) throws IOException {
    Integer reviewId = ParameterUtils.reviewId(request, true);
    if (reviewId != null) {
        // Submit the request with reviewId that should already be in the purgatory associated with the request endpoint.
        RequestInfo requestInfo = submit(reviewId, request);
        // Ensure that if the request has already been submitted, the user is not attempting to create another user task
        // with the same parameters and endpoint.
        sanityCheckSubmittedRequest(request, requestInfo, userTaskManager);
        return requestInfo.parameters();
    } else {
        CruiseControlParameters parameters = _config.getConfiguredInstance(classConfig, CruiseControlParameters.class, parameterConfigOverrides);
        if (hasValidParameterNames(request, response, _config, parameters) && !parameters.parseParameters(response)) {
            // Add request to purgatory and return ReviewResult.
            ReviewResult reviewResult = addRequest(request, parameters);
            reviewResult.writeSuccessResponse(parameters, response);
            LOG.info("Added request {} (parameters: {}) to purgatory.", request.getPathInfo(), request.getParameterMap());
        }
        return null;
    }
}
Also used : ReviewResult(com.linkedin.kafka.cruisecontrol.servlet.response.ReviewResult) CruiseControlParameters(com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters)

Aggregations

ReviewResult (com.linkedin.kafka.cruisecontrol.servlet.response.ReviewResult)2 CruiseControlParameters (com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1