use of com.linkedin.kafka.cruisecontrol.servlet.CruiseControlEndPoint in project cruise-control by linkedin.
the class ParameterUtils method hasValidParameterNames.
/**
* Check whether the request has valid parameter names. If not, populate the HTTP response with the corresponding
* error message and return {@code false}, return {@code true} otherwise.
*
* @param request HTTP request received by Cruise Control.
* @param response HTTP response of Cruise Control. Populated in case of an error.
* @param config The configurations for Cruise Control.
* @param parameters Request parameters
* @return {@code true} if the request has valid parameter names, {@code false} otherwise (and response is populated).
*/
public static boolean hasValidParameterNames(HttpServletRequest request, HttpServletResponse response, KafkaCruiseControlConfig config, CruiseControlParameters parameters) throws IOException {
CruiseControlEndPoint endPoint = endPoint(request);
Set<String> validParamNames = parameters.caseInsensitiveParameterNames();
Set<String> userParams = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
userParams.addAll(request.getParameterMap().keySet());
if (validParamNames != null) {
userParams.removeAll(validParamNames);
}
if (!userParams.isEmpty()) {
// User request specifies parameters that are not a subset of the valid parameters.
String errorMessage = String.format("Unrecognized endpoint parameters in %s %s request: %s.", endPoint, request.getMethod(), userParams);
writeErrorResponse(response, null, errorMessage, SC_BAD_REQUEST, wantJSON(request), wantResponseSchema(request), config);
return false;
}
return true;
}
use of com.linkedin.kafka.cruisecontrol.servlet.CruiseControlEndPoint in project cruise-control by linkedin.
the class ParameterUtils method endPoints.
/**
* Default: An empty set.
* @param request Http servlet request.
* @return Endpoints.
*/
public static Set<CruiseControlEndPoint> endPoints(HttpServletRequest request) throws UnsupportedEncodingException {
Set<String> parsedEndPoints = parseParamToStringSet(request, ENDPOINTS_PARAM).stream().map(String::toUpperCase).collect(Collectors.toSet());
Set<CruiseControlEndPoint> endPoints = new HashSet<>();
for (CruiseControlEndPoint endPoint : CruiseControlEndPoint.cachedValues()) {
if (parsedEndPoints.contains(endPoint.toString())) {
endPoints.add(endPoint);
}
}
return Collections.unmodifiableSet(endPoints);
}
Aggregations