Search in sources :

Example 6 with GridRedisGenericException

use of org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException in project ignite by apache.

the class GridRedisGetRangeCommandHandler method asRestRequest.

/**
 * {@inheritDoc}
 */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
    assert msg != null;
    if (msg.messageSize() < 4)
        throw new GridRedisGenericException("Wrong number of arguments");
    GridRestCacheRequest getReq = new GridRestCacheRequest();
    getReq.clientId(msg.clientId());
    getReq.key(msg.key());
    getReq.command(CACHE_GET);
    getReq.cacheName(msg.cacheName());
    return getReq;
}
Also used : GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRedisGenericException(org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException)

Example 7 with GridRedisGenericException

use of org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException in project ignite by apache.

the class GridRedisSetRangeCommandHandler method asRestRequest.

/**
 * {@inheritDoc}
 */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
    assert msg != null;
    if (msg.messageSize() < 4)
        throw new GridRedisGenericException("Wrong number of arguments");
    int off;
    try {
        off = Integer.parseInt(msg.aux(OFFSET_POS));
    } catch (NumberFormatException e) {
        U.error(log, "Erroneous offset", e);
        throw new GridRedisGenericException("Offset is not an integer");
    }
    String val = String.valueOf(msg.aux(VAL_POS));
    GridRestCacheRequest getReq = new GridRestCacheRequest();
    getReq.clientId(msg.clientId());
    getReq.key(msg.key());
    getReq.command(CACHE_GET);
    getReq.cacheName(msg.cacheName());
    if (val.isEmpty())
        return getReq;
    Object resp = hnd.handle(getReq).getResponse();
    int totalLen = off + val.length();
    if (off < 0 || totalLen > MAX_OFFSET)
        throw new GridRedisGenericException("Offset is out of range");
    GridRestCacheRequest putReq = new GridRestCacheRequest();
    putReq.clientId(msg.clientId());
    putReq.key(msg.key());
    putReq.command(CACHE_PUT);
    putReq.cacheName(msg.cacheName());
    if (resp == null) {
        byte[] dst = new byte[totalLen];
        System.arraycopy(val.getBytes(), 0, dst, off, val.length());
        putReq.value(new String(dst));
    } else {
        if (!(resp instanceof String))
            return getReq;
        String cacheVal = String.valueOf(resp);
        cacheVal = cacheVal.substring(0, off) + val;
        putReq.value(cacheVal);
    }
    hnd.handle(putReq);
    return getReq;
}
Also used : GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRedisGenericException(org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException)

Example 8 with GridRedisGenericException

use of org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException in project ignite by apache.

the class GridRedisExistsCommandHandler 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_GET_ALL);
    restReq.cacheName(msg.cacheName());
    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;
}
Also used : GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRedisGenericException(org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException)

Example 9 with GridRedisGenericException

use of org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException in project ignite by apache.

the class GridRedisExpireCommandHandler 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 (key is missing)");
    else if (msg.messageSize() < 3)
        throw new GridRedisGenericException("Wrong number of arguments (timeout value is missing)");
    GridRestCacheRequest restReq = new GridRestCacheRequest();
    restReq.clientId(msg.clientId());
    restReq.key(msg.key());
    restReq.command(CACHE_UPDATE_TLL);
    restReq.cacheName(msg.cacheName());
    switch(msg.command()) {
        case EXPIRE:
            restReq.ttl(Long.valueOf(msg.aux(TTL_POS)) * 1000);
            break;
        default:
            // PEXPIRE
            restReq.ttl(Long.valueOf(msg.aux(TTL_POS)));
    }
    return restReq;
}
Also used : GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRedisGenericException(org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException)

Example 10 with GridRedisGenericException

use of org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException in project ignite by apache.

the class GridRedisFlushCommandHandler method asRestRequest.

/**
 * {@inheritDoc}
 */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
    assert msg != null;
    GridRestCacheRequest restReq = new GridRestCacheRequest();
    restReq.clientId(msg.clientId());
    switch(msg.command()) {
        case FLUSHDB:
            restReq.command(CACHE_REMOVE_ALL);
            restReq.cacheName(msg.cacheName());
            break;
        default:
            // CACHE_CLEAR
            Map<Object, Object> redisCaches = new HashMap<>();
            for (IgniteCacheProxy<?, ?> cache : ctx.cache().publicCaches()) {
                if (cache.getName().startsWith(CACHE_NAME_PREFIX)) {
                    redisCaches.put(cache.getName(), null);
                }
            }
            if (redisCaches.isEmpty())
                throw new GridRedisGenericException("No Redis caches found");
            restReq.command(CACHE_CLEAR);
            restReq.values(redisCaches);
    }
    return restReq;
}
Also used : GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) HashMap(java.util.HashMap) GridRedisGenericException(org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException)

Aggregations

GridRedisGenericException (org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException)11 GridRestCacheRequest (org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest)11 HashMap (java.util.HashMap)1 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 GridRestResponse (org.apache.ignite.internal.processors.rest.GridRestResponse)1 GridRedisTypeException (org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisTypeException)1 DataStructuresRequest (org.apache.ignite.internal.processors.rest.request.DataStructuresRequest)1