use of org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest in project ignite by apache.
the class GridRedisDbSizeCommandHandler method asRestRequest.
/** {@inheritDoc} */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
assert msg != null;
GridRestCacheRequest restReq = new GridRestCacheRequest();
restReq.clientId(msg.clientId());
restReq.key(msg.key());
restReq.command(CACHE_SIZE);
restReq.cacheName(CACHE_NAME);
return restReq;
}
use of org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest in project ignite by apache.
the class GridRedisGetSetCommandHandler method asRestRequest.
/** {@inheritDoc} */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
assert msg != null;
if (msg.messageSize() < 3)
throw new GridRedisGenericException("Wrong syntax");
GridRestCacheRequest restReq = new GridRestCacheRequest();
restReq.clientId(msg.clientId());
restReq.key(msg.key());
restReq.value(msg.aux(VAL_POS));
restReq.command(CACHE_GET_AND_PUT);
restReq.cacheName(CACHE_NAME);
return restReq;
}
use of org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest in project ignite by apache.
the class GridRedisIncrDecrCommandHandler method asRestRequest.
/** {@inheritDoc} */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
assert msg != null;
DataStructuresRequest restReq = new DataStructuresRequest();
GridRestCacheRequest getReq = new GridRestCacheRequest();
getReq.clientId(msg.clientId());
getReq.key(msg.key());
getReq.command(CACHE_GET);
getReq.cacheName(CACHE_NAME);
GridRestResponse getResp = hnd.handle(getReq);
if (getResp.getResponse() == null)
restReq.initial(0L);
else {
if (getResp.getResponse() instanceof String) {
Long init;
try {
init = Long.parseLong((String) getResp.getResponse());
restReq.initial(init);
} catch (Exception e) {
U.error(log, "An initial value must be numeric and in range", e);
throw new GridRedisGenericException("An initial value must be numeric and in range");
}
if ((init == Long.MAX_VALUE && (msg.command() == INCR || msg.command() == INCRBY)) || (init == Long.MIN_VALUE && (msg.command() == DECR || msg.command() == DECRBY)))
throw new GridRedisGenericException("Increment or decrement would overflow");
} else
throw new GridRedisTypeException("Operation against a key holding the wrong kind of value");
// remove from cache.
GridRestCacheRequest rmReq = new GridRestCacheRequest();
rmReq.clientId(msg.clientId());
rmReq.key(msg.key());
rmReq.command(CACHE_REMOVE);
rmReq.cacheName(CACHE_NAME);
Object rmResp = hnd.handle(rmReq).getResponse();
if (rmResp == null || !(boolean) rmResp)
throw new GridRedisGenericException("Cannot incr/decr on the non-atomiclong key");
}
restReq.clientId(msg.clientId());
restReq.key(msg.key());
restReq.delta(1L);
if (msg.messageSize() > 2) {
try {
Long delta = Long.valueOf(msg.aux(DELTA_POS));
// check if it can be safely added.
safeAdd(restReq.initial(), delta);
restReq.delta(delta);
} catch (NumberFormatException | ArithmeticException e) {
U.error(log, "An increment value must be numeric and in range", e);
throw new GridRedisGenericException("An increment value must be numeric and in range");
}
}
switch(msg.command()) {
case INCR:
case INCRBY:
restReq.command(ATOMIC_INCREMENT);
break;
case DECR:
case DECRBY:
restReq.command(ATOMIC_DECREMENT);
break;
default:
assert false : "Unexpected command received";
}
return restReq;
}
use of org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest in project ignite by apache.
the class GridRedisDelCommandHandler method asRestRequest.
/** {@inheritDoc} */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
assert msg != null;
if (msg.messageSize() < 2)
throw new GridRedisGenericException("Wrong number of arguments");
GridRestCacheRequest restReq = new GridRestCacheRequest();
restReq.clientId(msg.clientId());
restReq.key(msg.key());
restReq.command(CACHE_REMOVE_ALL);
restReq.cacheName(CACHE_NAME);
List<String> keys = msg.auxMKeys();
Map<Object, Object> mget = U.newHashMap(keys.size());
for (String key : keys) mget.put(key, null);
restReq.values(mget);
return restReq;
}
use of org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest 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);
}
}
Aggregations