use of org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler in project ignite by apache.
the class TaskCommandHandlerSelfTest method testManyTasksRun.
/**
* @throws Exception If failed.
*/
public void testManyTasksRun() throws Exception {
GridClientCompute compute = client.compute();
for (int i = 0; i < 1000; i++) assertEquals(new Integer("executing".length()), compute.execute(TestTask.class.getName(), "executing"));
GridClientFactory.stop(client.id(), true);
IgniteKernal g = (IgniteKernal) grid(0);
Map<GridRestCommand, GridRestCommandHandler> handlers = U.field(g.context().rest(), "handlers");
GridTaskCommandHandler taskHnd = (GridTaskCommandHandler) F.find(handlers.values(), null, new P1<GridRestCommandHandler>() {
@Override
public boolean apply(GridRestCommandHandler e) {
return e instanceof GridTaskCommandHandler;
}
});
assertNotNull("GridTaskCommandHandler was not found", taskHnd);
ConcurrentLinkedHashMap taskDesc = U.field(taskHnd, "taskDescs");
assertTrue("Task result map size exceeded max value [mapSize=" + taskDesc.sizex() + ", " + "maxSize=" + MAX_TASK_RESULTS + ']', taskDesc.sizex() <= MAX_TASK_RESULTS);
}
use of org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler in project ignite by apache.
the class GridCacheCommandHandlerSelfTest method testCacheGetFailsSyncNotify.
/**
* Tests the cache failure during the execution of the CACHE_GET command.
*
* @throws Exception If failed.
*/
public void testCacheGetFailsSyncNotify() throws Exception {
GridRestCommandHandler hnd = new TestableCacheCommandHandler(grid().context(), "getAsync");
GridRestCacheRequest req = new GridRestCacheRequest();
req.cacheName(DEFAULT_CACHE_NAME);
req.command(GridRestCommand.CACHE_GET);
req.key("k1");
try {
hnd.handleAsync(req).get();
fail("Expected exception not thrown.");
} catch (IgniteCheckedException e) {
info("Got expected exception: " + e);
}
}
use of org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler in project ignite by apache.
the class GridCacheCommandHandlerSelfTest method testAppend.
/**
* Test cache handler append/prepend commands with specified environment.
*
* @param curVal Current value in cache.
* @param newVal New value to append/prepend.
* @param append Append or prepend flag.
* @param <T> Cache value type.
* @return Resulting value in cache.
* @throws IgniteCheckedException In case of any grid exception.
*/
private <T> T testAppend(T curVal, T newVal, boolean append) throws IgniteCheckedException, EntryProcessorException {
GridRestCommandHandler hnd = new GridCacheCommandHandler(((IgniteKernal) grid()).context());
String key = UUID.randomUUID().toString();
GridRestCacheRequest req = new GridRestCacheRequest();
req.cacheName(DEFAULT_CACHE_NAME);
req.command(append ? GridRestCommand.CACHE_APPEND : GridRestCommand.CACHE_PREPEND);
req.key(key);
req.value(newVal);
assertFalse("Expects failure due to no value in cache.", (Boolean) hnd.handleAsync(req).get().getResponse());
T res;
try {
// Change cache state.
jcache().put(key, curVal);
// Validate behavior for initialized cache (has current value).
assertTrue((Boolean) hnd.handleAsync(req).get().getResponse());
} finally {
res = (T) jcache().getAndRemove(key);
}
return res;
}
use of org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler in project ignite by apache.
the class JettyRestProcessorAbstractSelfTest method queryCursorFound.
/**
* @return True if any query cursor is available.
*/
private boolean queryCursorFound() {
boolean found = false;
for (int i = 0; i < GRID_CNT; ++i) {
Map<GridRestCommand, GridRestCommandHandler> handlers = GridTestUtils.getFieldValue(grid(i).context().rest(), "handlers");
GridRestCommandHandler qryHnd = handlers.get(GridRestCommand.CLOSE_SQL_QUERY);
ConcurrentHashMap<Long, Iterator> its = GridTestUtils.getFieldValue(qryHnd, "qryCurs");
found |= its.size() != 0;
}
return found;
}
use of org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler in project ignite by apache.
the class GridRestProcessor method handleRequest.
/**
* @param req Request.
* @return Future.
*/
private IgniteInternalFuture<GridRestResponse> handleRequest(final GridRestRequest req) {
if (startLatch.getCount() > 0) {
try {
startLatch.await();
} catch (InterruptedException e) {
return new GridFinishedFuture<>(new IgniteCheckedException("Failed to handle request " + "(protocol handler was interrupted when awaiting grid start).", e));
}
}
if (log.isDebugEnabled())
log.debug("Received request from client: " + req);
if (ctx.security().enabled()) {
Session ses;
try {
ses = session(req);
} catch (IgniteCheckedException e) {
GridRestResponse res = new GridRestResponse(STATUS_FAILED, e.getMessage());
return new GridFinishedFuture<>(res);
}
assert ses != null;
req.clientId(ses.clientId);
req.sessionToken(U.uuidToBytes(ses.sesId));
if (log.isDebugEnabled())
log.debug("Next clientId and sessionToken were extracted according to request: " + "[clientId=" + req.clientId() + ", sesTok=" + Arrays.toString(req.sessionToken()) + "]");
SecurityContext secCtx0 = ses.secCtx;
try {
if (secCtx0 == null)
ses.secCtx = secCtx0 = authenticate(req);
authorize(req, secCtx0);
} catch (SecurityException e) {
assert secCtx0 != null;
GridRestResponse res = new GridRestResponse(STATUS_SECURITY_CHECK_FAILED, e.getMessage());
return new GridFinishedFuture<>(res);
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(new GridRestResponse(STATUS_AUTH_FAILED, e.getMessage()));
}
}
interceptRequest(req);
GridRestCommandHandler hnd = handlers.get(req.command());
IgniteInternalFuture<GridRestResponse> res = hnd == null ? null : hnd.handleAsync(req);
if (res == null)
return new GridFinishedFuture<>(new IgniteCheckedException("Failed to find registered handler for command: " + req.command()));
return res.chain(new C1<IgniteInternalFuture<GridRestResponse>, GridRestResponse>() {
@Override
public GridRestResponse apply(IgniteInternalFuture<GridRestResponse> f) {
GridRestResponse res;
boolean failed = false;
try {
res = f.get();
} catch (Exception e) {
failed = true;
if (!X.hasCause(e, VisorClusterGroupEmptyException.class))
LT.error(log, e, "Failed to handle request: " + req.command());
if (log.isDebugEnabled())
log.debug("Failed to handle request [req=" + req + ", e=" + e + "]");
// Prepare error message:
SB sb = new SB(256);
sb.a("Failed to handle request: [req=").a(req.command());
if (req instanceof GridRestTaskRequest) {
GridRestTaskRequest tskReq = (GridRestTaskRequest) req;
sb.a(", taskName=").a(tskReq.taskName()).a(", params=").a(tskReq.params());
}
sb.a(", err=").a(e.getMessage() != null ? e.getMessage() : e.getClass().getName()).a(']');
res = new GridRestResponse(STATUS_FAILED, sb.toString());
}
assert res != null;
if (ctx.security().enabled() && !failed)
res.sessionTokenBytes(req.sessionToken());
interceptResponse(res, req);
return res;
}
});
}
Aggregations