Search in sources :

Example 1 with ConfigException

use of com.linkedin.cruisecontrol.common.config.ConfigException 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 ConfigException

use of com.linkedin.cruisecontrol.common.config.ConfigException 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)

Example 3 with ConfigException

use of com.linkedin.cruisecontrol.common.config.ConfigException in project cruise-control by linkedin.

the class PrometheusMetricSampler method configurePrometheusAdapter.

private void configurePrometheusAdapter(Map<String, ?> configs) {
    final String endpoint = (String) configs.get(PROMETHEUS_SERVER_ENDPOINT_CONFIG);
    if (endpoint == null) {
        throw new ConfigException(String.format("%s config is required by Prometheus metric sampler", PROMETHEUS_SERVER_ENDPOINT_CONFIG));
    }
    try {
        HttpHost host = HttpHost.create(endpoint);
        if (host.getPort() < 0) {
            throw new IllegalArgumentException();
        }
        _httpClient = HttpClients.createDefault();
        _prometheusAdapter = new PrometheusAdapter(_httpClient, host, _samplingIntervalMs);
    } catch (IllegalArgumentException ex) {
        throw new ConfigException(String.format("Prometheus endpoint URI is malformed, " + "expected schema://host:port, provided %s", endpoint));
    }
}
Also used : HttpHost(org.apache.http.HttpHost) ConfigException(com.linkedin.cruisecontrol.common.config.ConfigException)

Aggregations

ConfigException (com.linkedin.cruisecontrol.common.config.ConfigException)3 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 HttpHost (org.apache.http.HttpHost)1