Search in sources :

Example 6 with BadRequestException

use of doitincloud.commons.exceptions.BadRequestException in project rdbcache by rdbcache.

the class RdbcacheApis method delkey_get.

/**
 * delkey_get get/delete single item
 *
 * To delete a key from redis based on the input key. No query string.
 * It returns immediately. It will not delete database entry.
 *
 * @param request HttpServletRequest
 * @param key String, hash key
 * @param opt1 String, can be "sync" or "async" and table
 * @param opt2 String, can be "sync" or "async"  and table, but not the same as opt1
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rdbcache/v1/delkey/{key}", "/rdbcache/v1/delkey/{key}/{opt1}", "/rdbcache/v1/delkey/{key}/{opt1}/{opt2}" }, method = { RequestMethod.GET, RequestMethod.DELETE })
public ResponseEntity<?> delkey_get(HttpServletRequest request, @PathVariable("key") String key, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2) {
    if (request.getParameterMap().size() != 0) {
        throw new BadRequestException("query string is not supported");
    }
    if (key.equals("*")) {
        throw new BadRequestException("no * allowed as key");
    }
    Context context = new Context();
    KvPairs pairs = new KvPairs(key);
    AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2);
    if (anyKey.getKeyInfo().getIsNew()) {
        throw new NotFoundException("key not found for " + key);
    }
    LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
    AppCtx.getAsyncOps().doDeleteFromRedis(context, pairs, anyKey);
    return Response.send(context, pairs);
}
Also used : Context(doitincloud.rdbcache.supports.Context) AnyKey(doitincloud.rdbcache.supports.AnyKey) BadRequestException(doitincloud.commons.exceptions.BadRequestException) NotFoundException(doitincloud.commons.exceptions.NotFoundException) KvPairs(doitincloud.rdbcache.supports.KvPairs)

Example 7 with BadRequestException

use of doitincloud.commons.exceptions.BadRequestException in project rdbcache by rdbcache.

the class RdbcacheApis method trace_get.

/**
 * trace_get get single item
 *
 * get error messages by trace id
 *
 * @param request HttpServletRequest
 * @param traceId the trace id return by API call
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rdbcache/v1/trace/{traceId}" }, method = RequestMethod.GET)
public ResponseEntity<?> trace_get(HttpServletRequest request, @PathVariable("traceId") String traceId) {
    if (request.getParameterMap().size() != 0) {
        throw new BadRequestException("query string is not supported");
    }
    if (traceId.equals("*")) {
        throw new BadRequestException("no * allowed as trace id");
    }
    if (request.getParameterMap().size() != 0) {
        throw new BadRequestException("no query string is allowed");
    }
    Context context = new Context(true);
    KvPairs pairs = new KvPairs();
    Request.process(context, request, pairs);
    LOGGER.trace("pairs(" + pairs.size() + "): " + pairs.printKey());
    KvPair pair = AppCtx.getKvPairRepo().findById(new KvIdType(traceId, "trace"));
    if (pair != null) {
        pairs.add(pair);
    }
    return Response.send(context, pairs);
}
Also used : Context(doitincloud.rdbcache.supports.Context) KvIdType(doitincloud.rdbcache.models.KvIdType) KvPair(doitincloud.rdbcache.models.KvPair) BadRequestException(doitincloud.commons.exceptions.BadRequestException) KvPairs(doitincloud.rdbcache.supports.KvPairs)

Example 8 with BadRequestException

use of doitincloud.commons.exceptions.BadRequestException in project rdbcache by rdbcache.

the class RdbcacheApis method flushcache_get.

/**
 * flushcache_get get operational to multiple items
 *
 * flush local cache
 *
 * @param request HttpServletRequest
 * @param opt optional, all, table, key and data
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rdbcache/v1/flush-cache", "/rdbcache/v1/flush-cache/{opt}" }, method = RequestMethod.GET)
public ResponseEntity<?> flushcache_get(HttpServletRequest request, @PathVariable Optional<String> opt) {
    if (request.getParameterMap().size() != 0) {
        throw new BadRequestException("query string is not supported");
    }
    Context context = new Context();
    Request.process(context, request);
    if (!opt.isPresent()) {
        AppCtx.getCacheOps().removeAllKeyAndData();
    } else {
        String option = opt.get();
        if (option.equals("all")) {
            AppCtx.getCacheOps().removeAll();
        } else if (option.equals("table")) {
            AppCtx.getCacheOps().removeAllTables();
        } else if (option.equals("key")) {
            AppCtx.getCacheOps().removeAllKeyInfo(null);
        } else if (option.equals("data")) {
            AppCtx.getCacheOps().removeAllData(null);
        } else if (option.equals("key-and-data")) {
            AppCtx.getCacheOps().removeAllKeyAndData();
        } else {
            throw new BadRequestException("unknown option: " + option);
        }
    }
    Map<String, Object> data = new LinkedHashMap<>();
    data.put("result", "DONE");
    return Response.send(context, data);
}
Also used : Context(doitincloud.rdbcache.supports.Context) BadRequestException(doitincloud.commons.exceptions.BadRequestException)

Example 9 with BadRequestException

use of doitincloud.commons.exceptions.BadRequestException in project rdbcache by rdbcache.

the class RdbcacheApis method delkey_post.

/**
 * delkey_post post multiple items
 *
 * To delete one or more keys from redis based on the input keys. No query string.
 * It returns immediately. It will not delete database entry.
 *
 * @param request HttpServletRequest
 * @param keys List, list of keys for returned entries
 * @param opt1 String, can be "sync" or "async" and table
 * @param opt2 String, can be "sync" or "async"  and table, but not the same as opt1
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rdbcache/v1/delkey", "/rdbcache/v1/delkey/{opt1}", "/rdbcache/v1/delkey/{opt1}/{opt2}" }, method = RequestMethod.POST)
public ResponseEntity<?> delkey_post(HttpServletRequest request, @RequestBody List<String> keys, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2) {
    if (request.getParameterMap().size() != 0) {
        throw new BadRequestException("query string is not supported");
    }
    if (keys.contains("*")) {
        throw new BadRequestException("no * allowed as key");
    }
    Context context = new Context();
    KvPairs pairs = new KvPairs(keys);
    AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2);
    if (anyKey.size() != keys.size()) {
        context.logTraceMessage("one or more keys not found");
    }
    for (int i = 0; i < anyKey.size(); i++) {
        KvPair pair = pairs.get(i);
        KeyInfo keyInfo = anyKey.get(i);
        if (keyInfo.getIsNew()) {
            context.logTraceMessage("key not found for " + pair.getId());
        }
    }
    LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
    AppCtx.getAsyncOps().doDeleteFromRedis(context, pairs, anyKey);
    return Response.send(context, pairs);
}
Also used : Context(doitincloud.rdbcache.supports.Context) AnyKey(doitincloud.rdbcache.supports.AnyKey) KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo) BadRequestException(doitincloud.commons.exceptions.BadRequestException) KvPairs(doitincloud.rdbcache.supports.KvPairs)

Example 10 with BadRequestException

use of doitincloud.commons.exceptions.BadRequestException in project rdbcache by rdbcache.

the class RdbcacheApis method delall_post.

/**
 * delall_post post multple items
 *
 * To delete one or more keys from redis and database based on the input keys. No query string.
 * It returns immediately.
 *
 * @param request HttpServletRequest
 * @param keys List, list of keys for returned entries
 * @param opt1 String, can be "sync" and table
 * @param opt2 String, can be "sync" and table, but not the same as opt1
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rdbcache/v1/delall", "/rdbcache/v1/delall/{opt1}", "/rdbcache/v1/delall/{opt1}/{opt2}" }, method = RequestMethod.POST)
public ResponseEntity<?> delall_post(HttpServletRequest request, @RequestBody List<String> keys, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2) {
    if (request.getParameterMap().size() != 0) {
        throw new BadRequestException("query string is not supported");
    }
    if (keys.contains("*")) {
        throw new BadRequestException("no * allowed as key");
    }
    Context context = new Context();
    KvPairs pairs = new KvPairs(keys);
    AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2);
    if (anyKey.size() != keys.size()) {
        context.logTraceMessage("one or more keys not found");
    }
    for (int i = 0; i < anyKey.size(); i++) {
        KvPair pair = pairs.get(i);
        KeyInfo keyInfo = anyKey.get(i);
        if (keyInfo.getIsNew()) {
            context.logTraceMessage("key not found for " + pair.getId());
        }
    }
    AppCtx.getAsyncOps().doDeleteFromRedisAndDbase(context, pairs, anyKey);
    return Response.send(context, pairs);
}
Also used : Context(doitincloud.rdbcache.supports.Context) AnyKey(doitincloud.rdbcache.supports.AnyKey) KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo) BadRequestException(doitincloud.commons.exceptions.BadRequestException) KvPairs(doitincloud.rdbcache.supports.KvPairs)

Aggregations

BadRequestException (doitincloud.commons.exceptions.BadRequestException)16 Context (doitincloud.rdbcache.supports.Context)15 KvPairs (doitincloud.rdbcache.supports.KvPairs)14 AnyKey (doitincloud.rdbcache.supports.AnyKey)12 KeyInfo (doitincloud.rdbcache.models.KeyInfo)7 KvPair (doitincloud.rdbcache.models.KvPair)7 NotFoundException (doitincloud.commons.exceptions.NotFoundException)3 QueryInfo (doitincloud.rdbcache.queries.QueryInfo)3 KvIdType (doitincloud.rdbcache.models.KvIdType)2