use of com.linkedin.kafka.cruisecontrol.servlet.UserRequestException in project cruise-control by linkedin.
the class ParameterUtils method entries.
/**
* Get the specified value for the {@link #ENTRIES_PARAM} parameter.
*
* @param request HTTP request received by Cruise Control.
* @return The specified value for the {@link #ENTRIES_PARAM} parameter, or {@link Integer#MAX_VALUE} if the
* parameter is missing.
*/
public static int entries(HttpServletRequest request) {
String parameterString = caseSensitiveParameterName(request.getParameterMap(), ENTRIES_PARAM);
int entries = parameterString == null ? Integer.MAX_VALUE : Integer.parseInt(request.getParameter(parameterString));
if (entries <= 0) {
throw new UserRequestException("The requested entries must be positive (Requested: " + entries + ").");
}
return entries;
}
use of com.linkedin.kafka.cruisecontrol.servlet.UserRequestException in project cruise-control by linkedin.
the class ParameterUtils method concurrencyTypes.
private static Set<ConcurrencyType> concurrencyTypes(HttpServletRequest request, boolean isEnable) throws UnsupportedEncodingException {
Set<String> concurrencyForStringSet = parseParamToStringSet(request, isEnable ? ENABLE_CONCURRENCY_ADJUSTER_FOR_PARAM : DISABLE_CONCURRENCY_ADJUSTER_FOR_PARAM);
Set<ConcurrencyType> concurrencyTypes = new HashSet<>();
try {
for (String concurrencyForString : concurrencyForStringSet) {
concurrencyTypes.add(ConcurrencyType.valueOf(concurrencyForString.toUpperCase()));
}
} catch (IllegalArgumentException iae) {
throw new UserRequestException(String.format("Unsupported concurrency types in %s. Supported: %s", concurrencyForStringSet, ConcurrencyType.cachedValues()));
}
return Collections.unmodifiableSet(concurrencyTypes);
}
use of com.linkedin.kafka.cruisecontrol.servlet.UserRequestException in project cruise-control by linkedin.
the class Purgatory method submit.
/**
* Ensure that:
* <ul>
* <li>A request with the given review id exists in the purgatory.</li>
* <li>The request with the given review id matches the given request.</li>
* <li>The request with the given review id is approved in the purgatory.</li>
* </ul>
*
* Then mark the review status as submitted.
*
* @param reviewId The review id for which the corresponding request is requested to be submitted.
* @param request The request to submit.
* @return Submitted request info.
*/
public synchronized RequestInfo submit(int reviewId, HttpServletRequest request) {
RequestInfo requestInfo = _requestInfoById.get(reviewId);
// 1. Ensure that a request with the given review id exists in the purgatory.
if (requestInfo == null) {
throw new UserRequestException(String.format("No request with review id %d exists in purgatory. Please use %s endpoint to check for the " + "current requests awaiting review in purgatory.", reviewId, REVIEW));
}
// 2. Ensure that the request with the given review id matches the given request.
CruiseControlEndPoint endpoint = ParameterUtils.endPoint(request);
if (requestInfo.endPoint() != endpoint) {
throw new UserRequestException(String.format("Request with review id %d is associated with %s endpoint, but the given request has %s endpoint." + "Please use %s endpoint to check for the current requests awaiting review in purgatory.", reviewId, requestInfo.endPoint(), endpoint, REVIEW));
}
if (requestInfo.status() == ReviewStatus.SUBMITTED) {
LOG.info("Request {} has already been submitted (review: {}).", requestInfo.endpointWithParams(), reviewId);
requestInfo.setAccessToAlreadySubmittedRequest();
} else {
// 3. Ensure that the request with the given review id is approved in the purgatory, and mark the status as submitted.
requestInfo.submitReview(reviewId);
LOG.info("Submitted request {} for execution (review: {}).", requestInfo.endpointWithParams(), reviewId);
}
return requestInfo;
}
use of com.linkedin.kafka.cruisecontrol.servlet.UserRequestException in project cruise-control by linkedin.
the class ParameterUtils method concurrentMovements.
/**
* Get the execution concurrency requirement dynamically set from the Http request.
* Based on value of isInterBrokerPartitionMovement and isIntraBrokerPartitionMovement, different type of concurrency
* requirement is set. The mapping is as follows.
* <ul>
* <li>{false, false} -> leader movement concurrency requirement</li>
* <li>{true , false} -> per-broker inter-broker partition movement concurrency requirement</li>
* <li>{false, true} -> intra-broker partition movement concurrency requirement</li>
* <li>{true , true} -> not defined</li>
* </ul>
*
* @param request The Http request.
* @param isInterBrokerPartitionMovement {@code true} if inter-broker partition movement per broker.
* @param isIntraBrokerPartitionMovement {@code true} if intra-broker partition movement.
* @return The execution concurrency requirement dynamically set from the Http request.
*/
static Integer concurrentMovements(HttpServletRequest request, boolean isInterBrokerPartitionMovement, boolean isIntraBrokerPartitionMovement) {
String parameter = isInterBrokerPartitionMovement ? CONCURRENT_PARTITION_MOVEMENTS_PER_BROKER_PARAM : isIntraBrokerPartitionMovement ? CONCURRENT_INTRA_BROKER_PARTITION_MOVEMENTS_PARAM : CONCURRENT_LEADER_MOVEMENTS_PARAM;
String parameterString = caseSensitiveParameterName(request.getParameterMap(), parameter);
if (parameterString == null) {
return null;
}
int concurrentMovementsPerBroker = Integer.parseInt(request.getParameter(parameterString));
if (concurrentMovementsPerBroker <= 0) {
throw new UserRequestException("The requested movement concurrency must be positive (Requested: " + concurrentMovementsPerBroker + ").");
}
return concurrentMovementsPerBroker;
}
use of com.linkedin.kafka.cruisecontrol.servlet.UserRequestException in project cruise-control by linkedin.
the class ParameterUtils method partitionCount.
/**
* Get the {@link #PARTITION_COUNT} from the request.
*
* Default: {@link ProvisionRecommendation#DEFAULT_OPTIONAL_INT}
* @param request Http servlet request.
* @return The value of {@link #PARTITION_COUNT} parameter.
* @throws UserRequestException if the targeted partition count is not a positive integer.
*/
static int partitionCount(HttpServletRequest request) {
String parameterString = caseSensitiveParameterName(request.getParameterMap(), PARTITION_COUNT);
if (parameterString == null) {
return ProvisionRecommendation.DEFAULT_OPTIONAL_INT;
}
int targetPartitionCount = Integer.parseInt(request.getParameter(parameterString));
if (targetPartitionCount <= 0) {
throw new UserRequestException("The requested targeted partition count must be positive (Requested: " + targetPartitionCount + ").");
}
return targetPartitionCount;
}
Aggregations