use of com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters in project cruise-control by linkedin.
the class RequestParameterTest method checkOpenApiSpec.
/**
* Load the OpenAPI files for endpoints and compares them against the source code
*/
@Test
public void checkOpenApiSpec() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
options.setFlatten(true);
SwaggerParseResult parseResult = openApiParser.readLocation(OPENAPI_SPEC_PATH, null, options);
_openAPI = parseResult.getOpenAPI();
Map<String, Set<String>> schema = parseSchema();
Assert.assertEquals(schema.keySet(), _endpointToClass.keySet());
for (Map.Entry<String, Set<String>> endpoint : schema.entrySet()) {
Assert.assertTrue(_endpointToClass.containsKey(endpoint.getKey()));
CruiseControlParameters endpointParams = _endpointToClass.get(endpoint.getKey());
Assert.assertEquals(endpoint.getValue(), endpointParams.caseInsensitiveParameterNames());
}
}
use of com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters in project cruise-control by linkedin.
the class RequestParameterTest method setupParameterClasses.
/**
* Specify endpoints to be tested
*/
@Before
public void setupParameterClasses() throws Exception {
_endpointToClass = new HashMap<>();
KafkaCruiseControlConfig defaultConfig = new KafkaCruiseControlConfig(KafkaCruiseControlUnitTestUtils.getKafkaCruiseControlProperties());
String webserverApiUrlPrefix = KafkaCruiseControlServletTestUtils.getDefaultWebServerApiUrlPrefix();
for (CruiseControlEndPoint endpoint : CruiseControlEndPoint.cachedValues()) {
_endpointToClass.put((webserverApiUrlPrefix + endpoint.toString()).toLowerCase(), ((CruiseControlParameters) (defaultConfig.getClass(requestParameterFor(endpoint).parametersClass()).newInstance())));
}
}
use of com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters 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);
}
}
use of com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters 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);
}
}
use of com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters 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;
}
}
Aggregations