Search in sources :

Example 1 with RequestParameterWrapper

use of com.linkedin.kafka.cruisecontrol.config.RequestParameterWrapper in project cruise-control by linkedin.

the class KafkaCruiseControlServlet method handleGet.

/**
 * The GET method allows users to perform actions supported by {@link CruiseControlEndPoint#getEndpoints()}.
 * @param request HTTP request received by Cruise Control.
 * @param response HTTP response of Cruise Control.
 * @param endPoint A GET endpoint of Cruise Control.
 * @param requestConfigOverrides Config overrides to be used while creating the {@link Request}.
 * @param parameterConfigOverrides Config overrides to be used while creating the {@link CruiseControlParameters}.
 */
private void handleGet(HttpServletRequest request, HttpServletResponse response, CruiseControlEndPoint endPoint, Map<String, Object> requestConfigOverrides, Map<String, Object> parameterConfigOverrides) throws InterruptedException, ExecutionException, IOException {
    // Sanity check: if the request is for REVIEW_BOARD, two step verification must be enabled.
    if (endPoint == REVIEW_BOARD && !_twoStepVerification) {
        throw new ConfigException(String.format("Attempt to access %s endpoint without enabling '%s' config.", endPoint, WebServerConfig.TWO_STEP_VERIFICATION_ENABLED_CONFIG));
    }
    RequestParameterWrapper requestParameter = requestParameterFor(endPoint);
    CruiseControlParameters parameters = _config.getConfiguredInstance(requestParameter.parametersClass(), CruiseControlParameters.class, parameterConfigOverrides);
    if (hasValidParameterNames(request, response, _config, parameters)) {
        requestConfigOverrides.put(requestParameter.parameterObject(), parameters);
        Request ccRequest = _config.getConfiguredInstance(requestParameter.requestClass(), Request.class, requestConfigOverrides);
        ccRequest.handle(request, response);
    }
}
Also used : RequestParameterWrapper(com.linkedin.kafka.cruisecontrol.config.RequestParameterWrapper) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.linkedin.cruisecontrol.servlet.handler.Request) ConfigException(com.linkedin.cruisecontrol.common.config.ConfigException) CruiseControlParameters(com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters)

Example 2 with RequestParameterWrapper

use of com.linkedin.kafka.cruisecontrol.config.RequestParameterWrapper in project cruise-control by linkedin.

the class KafkaCruiseControlServlet method handlePost.

/**
 * The POST method allows users to perform actions supported by {@link CruiseControlEndPoint#postEndpoints()}.
 * @param request HTTP request received by Cruise Control.
 * @param response HTTP response of Cruise Control.
 * @param endPoint A POST endpoint of Cruise Control.
 * @param requestConfigOverrides Config overrides to be used while creating the {@link Request}.
 * @param parameterConfigOverrides Config overrides to be used while creating the {@link CruiseControlParameters}.
 */
private void handlePost(HttpServletRequest request, HttpServletResponse response, CruiseControlEndPoint endPoint, Map<String, Object> requestConfigOverrides, Map<String, Object> parameterConfigOverrides) throws InterruptedException, ExecutionException, IOException {
    CruiseControlParameters parameters;
    RequestParameterWrapper requestParameter = requestParameterFor(endPoint);
    if (endPoint == REVIEW) {
        // Sanity check: if the request is for REVIEW, two step verification must be enabled.
        if (!_twoStepVerification) {
            throw new ConfigException(String.format("Attempt to access %s endpoint without enabling '%s' config.", endPoint, WebServerConfig.TWO_STEP_VERIFICATION_ENABLED_CONFIG));
        }
        parameters = _config.getConfiguredInstance(requestParameter.parametersClass(), CruiseControlParameters.class, parameterConfigOverrides);
        if (!hasValidParameterNames(request, response, _config, parameters)) {
            return;
        }
    } else if (!_twoStepVerification) {
        // Do not add to the purgatory if the two-step verification is disabled.
        parameters = _config.getConfiguredInstance(requestParameter.parametersClass(), CruiseControlParameters.class, parameterConfigOverrides);
        if (!hasValidParameterNames(request, response, _config, parameters)) {
            return;
        }
    } else {
        // Add to the purgatory if the two-step verification is enabled.
        parameters = _purgatory.maybeAddToPurgatory(request, response, requestParameter.parametersClass(), parameterConfigOverrides, _userTaskManager);
    }
    Request ccRequest = null;
    if (parameters != null) {
        requestConfigOverrides.put(requestParameter.parameterObject(), parameters);
        ccRequest = _config.getConfiguredInstance(requestParameter.requestClass(), Request.class, requestConfigOverrides);
    }
    if (ccRequest != null) {
        // ccRequest would be null if request is added to Purgatory.
        ccRequest.handle(request, response);
    }
}
Also used : RequestParameterWrapper(com.linkedin.kafka.cruisecontrol.config.RequestParameterWrapper) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.linkedin.cruisecontrol.servlet.handler.Request) ConfigException(com.linkedin.cruisecontrol.common.config.ConfigException) CruiseControlParameters(com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters)

Aggregations

ConfigException (com.linkedin.cruisecontrol.common.config.ConfigException)2 Request (com.linkedin.cruisecontrol.servlet.handler.Request)2 CruiseControlParameters (com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters)2 RequestParameterWrapper (com.linkedin.kafka.cruisecontrol.config.RequestParameterWrapper)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2