Search in sources :

Example 11 with OperationFuture

use of com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture in project cruise-control by linkedin.

the class AbstractSyncRequest method getResponse.

@Override
public CruiseControlResponse getResponse(HttpServletRequest request, HttpServletResponse response) throws ExecutionException, InterruptedException {
    LOG.info("Processing sync request {}.", name());
    long requestExecutionStartTime = System.nanoTime();
    int step = 0;
    OperationFuture resultFuture = _userTaskManager.getOrCreateUserTask(request, response, uuid -> {
        OperationFuture future = new OperationFuture(String.format("%s request", parameters().endPoint().toString()));
        future.complete(handle());
        return future;
    }, step, false, parameters()).get(step);
    CruiseControlResponse ccResponse = resultFuture.get();
    _successfulRequestExecutionTimer.get(parameters().endPoint()).update(System.nanoTime() - requestExecutionStartTime, TimeUnit.NANOSECONDS);
    return ccResponse;
}
Also used : CruiseControlParameters(com.linkedin.cruisecontrol.servlet.parameters.CruiseControlParameters) Logger(org.slf4j.Logger) EndPoint(com.linkedin.cruisecontrol.servlet.EndPoint) HttpServletResponse(javax.servlet.http.HttpServletResponse) LoggerFactory(org.slf4j.LoggerFactory) AbstractRequest(com.linkedin.kafka.cruisecontrol.servlet.handler.AbstractRequest) CruiseControlResponse(com.linkedin.cruisecontrol.servlet.response.CruiseControlResponse) AbstractAsyncRequest(com.linkedin.kafka.cruisecontrol.servlet.handler.async.AbstractAsyncRequest) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) UserTaskManager(com.linkedin.kafka.cruisecontrol.servlet.UserTaskManager) HttpServletRequest(javax.servlet.http.HttpServletRequest) OperationFuture(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture) Map(java.util.Map) Timer(com.codahale.metrics.Timer) CruiseControlResponse(com.linkedin.cruisecontrol.servlet.response.CruiseControlResponse) OperationFuture(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture) EndPoint(com.linkedin.cruisecontrol.servlet.EndPoint)

Example 12 with OperationFuture

use of com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture in project cruise-control by linkedin.

the class UserTaskManager method getFuture.

/**
 * Get the future from the given request.
 *
 * @param request HTTP request received by Cruise Control.
 * @param <T> The returned future type.
 * @return The future from the given request.
 */
@SuppressWarnings("unchecked")
public <T> T getFuture(HttpServletRequest request) {
    UUID userTaskId = getUserTaskId(request);
    UserTaskInfo userTaskInfo = getUserTaskByUserTaskId(userTaskId, request);
    List<OperationFuture> operationFutures = null;
    if (userTaskInfo != null) {
        operationFutures = userTaskInfo.futures();
    }
    if (operationFutures == null || operationFutures.isEmpty()) {
        return null;
    }
    return (T) operationFutures.get(operationFutures.size() - 1);
}
Also used : UUID(java.util.UUID) OperationFuture(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture)

Example 13 with OperationFuture

use of com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture in project cruise-control by linkedin.

the class ClusterLoadRequest method handle.

@Override
protected OperationFuture handle(String uuid) {
    OperationFuture future = new OperationFuture("Get broker stats");
    pending(future.operationProgress());
    _asyncKafkaCruiseControl.sessionExecutor().submit(new LoadRunnable(_asyncKafkaCruiseControl, future, _parameters));
    return future;
}
Also used : LoadRunnable(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.LoadRunnable) OperationFuture(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture)

Example 14 with OperationFuture

use of com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture in project cruise-control by linkedin.

the class CruiseControlStateRequest method handle.

@Override
protected OperationFuture handle(String uuid) {
    OperationFuture future = new OperationFuture("Get state");
    pending(future.operationProgress());
    _asyncKafkaCruiseControl.sessionExecutor().submit(new GetStateRunnable(_asyncKafkaCruiseControl, future, _parameters));
    return future;
}
Also used : OperationFuture(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture) GetStateRunnable(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.GetStateRunnable)

Example 15 with OperationFuture

use of com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture in project cruise-control by linkedin.

the class FixOfflineReplicasRequest method handle.

@Override
protected OperationFuture handle(String uuid) {
    OperationFuture future = new OperationFuture("Fix offline replicas");
    pending(future.operationProgress());
    _asyncKafkaCruiseControl.sessionExecutor().submit(new FixOfflineReplicasRunnable(_asyncKafkaCruiseControl, future, _parameters, uuid));
    return future;
}
Also used : FixOfflineReplicasRunnable(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.FixOfflineReplicasRunnable) OperationFuture(com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture)

Aggregations

OperationFuture (com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 HashMap (java.util.HashMap)7 UUID (java.util.UUID)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6 HttpSession (javax.servlet.http.HttpSession)6 MockTime (kafka.utils.MockTime)6 Test (org.junit.Test)6 GET_METHOD (com.linkedin.kafka.cruisecontrol.servlet.KafkaCruiseControlServletUtils.GET_METHOD)5 Collections (java.util.Collections)5 Time (org.apache.kafka.common.utils.Time)5 Capture (org.easymock.Capture)5 EasyMock (org.easymock.EasyMock)5 Assert (org.junit.Assert)5 CruiseControlResponse (com.linkedin.cruisecontrol.servlet.response.CruiseControlResponse)2 ArrayList (java.util.ArrayList)2 Timer (com.codahale.metrics.Timer)1 Gson (com.google.gson.Gson)1