Search in sources :

Example 16 with Context

use of doitincloud.rdbcache.supports.Context in project rdbcache by rdbcache.

the class RTQueryApis method queryCache.

/**
 * query cache
 *
 * query local cache
 *
 * @param request HttpServletRequest
 * @param action config, table, key and data
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rtquery/v1/cache/{action}" }, method = RequestMethod.GET)
public ResponseEntity<?> queryCache(HttpServletRequest request, @PathVariable String action) {
    Context context = new Context();
    Request.process(context, request);
    Map<String, Object> data = null;
    try {
        if (action.equals("config")) {
            data = new LinkedHashMap<>();
            data.put("keyMinCacheTTL", PropCfg.getKeyMinCacheTTL());
            data.put("dataMaxCacheTLL", PropCfg.getDataMaxCacheTLL());
            data.put("tableInfoCacheTTL", PropCfg.getTableInfoCacheTTL());
        } else if (action.equals("table")) {
            data = AppCtx.getCacheOps().listAllTables();
        } else if (action.equals("key")) {
            data = AppCtx.getCacheOps().listAllKeyInfo(null);
        } else if (action.equals("data")) {
            data = AppCtx.getCacheOps().listAllData(null);
        }
    } catch (Exception e) {
        String msg = e.getCause().getMessage();
        throw new ServerErrorException(msg);
    }
    return Response.send(context, data);
}
Also used : Context(doitincloud.rdbcache.supports.Context) ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Context

use of doitincloud.rdbcache.supports.Context in project rdbcache by rdbcache.

the class RTQueryApis method queryVerionInfo.

/**
 * query version info
 *
 * @param request HttpServletRequest
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rtquery/v1/version-info" }, method = RequestMethod.GET)
public ResponseEntity<?> queryVerionInfo(HttpServletRequest request) {
    Context context = new Context();
    Request.process(context, request);
    VersionInfo versionInfo = AppCtx.getVersionInfo();
    Map<String, Object> data = Utils.toMap(versionInfo);
    return Response.send(context, data);
}
Also used : Context(doitincloud.rdbcache.supports.Context) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with Context

use of doitincloud.rdbcache.supports.Context in project rdbcache by rdbcache.

the class RTQueryApis method queryAppCtx.

/**
 * query AppCtx
 *
 * @param request HttpServletRequest
 * @param nameOpt, optional bean name
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rtquery/v1/app-ctx", "/rtquery/v1/app-ctx/{nameOpt}" }, method = RequestMethod.GET)
public ResponseEntity<?> queryAppCtx(HttpServletRequest request, @PathVariable Optional<String> nameOpt) {
    Context context = new Context();
    Request.process(context, request);
    Map<String, Object> data = new LinkedHashMap<String, Object>();
    for (Method method : AppCtx.class.getMethods()) {
        String appCtxFName = method.getName();
        if (Modifier.isStatic(method.getModifiers()) && appCtxFName.startsWith("get")) {
            String beanName = appCtxFName.substring(3, appCtxFName.length());
            if (nameOpt.isPresent()) {
                if (!beanName.equalsIgnoreCase(nameOpt.get())) {
                    continue;
                }
            }
            try {
                Map<String, Object> map = new LinkedHashMap<String, Object>();
                Object object = method.invoke(null);
                if (object == null)
                    continue;
                for (Method objMethod : object.getClass().getMethods()) {
                    if (objMethod.getParameterCount() > 0)
                        continue;
                    if (objMethod.getReturnType().equals("void"))
                        continue;
                    String objFName = objMethod.getName();
                    if (ignoreMethodList.contains(objFName))
                        continue;
                    String type = objMethod.getReturnType().getName();
                    String name = null;
                    if (objFName.startsWith("get")) {
                        name = objFName.substring(3, objFName.length());
                    } else if (objFName.startsWith("is")) {
                        name = objFName.substring(2, objFName.length());
                    }
                    if (name == null)
                        continue;
                    if (type.indexOf('.') == -1 || type.startsWith("java.lang.") || type.startsWith("java.util.")) {
                        try {
                            Object value = objMethod.invoke(object);
                            map.put(name, value);
                        } catch (Exception e) {
                            // System.out.println("Call " + beanName + "." + objFName);
                            e.printStackTrace();
                        }
                    }
                }
                data.put(beanName, map);
            } catch (Exception e) {
                // System.out.println("Call AppCtxx." + appCtxFName);
                e.printStackTrace();
            }
        }
    }
    return Response.send(context, data);
}
Also used : Context(doitincloud.rdbcache.supports.Context) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Method(java.lang.reflect.Method) ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Context

use of doitincloud.rdbcache.supports.Context in project rdbcache by rdbcache.

the class RTQueryApis method queryProperties.

/**
 * query properties
 *
 * @param request HttpServletRequest
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rtquery/v1/properties", "/rtquery/v1/properties/{nameOpt}" }, method = RequestMethod.GET)
public ResponseEntity<?> queryProperties(HttpServletRequest request, @PathVariable Optional<String> nameOpt) {
    Context context = new Context();
    Request.process(context, request);
    Map<String, Object> data = new LinkedHashMap<String, Object>();
    for (Iterator it = ((AbstractEnvironment) env).getPropertySources().iterator(); it.hasNext(); ) {
        PropertySource propertySource = (PropertySource) it.next();
        if (propertySource instanceof MapPropertySource) {
            data.putAll(((MapPropertySource) propertySource).getSource());
        }
    }
    if (nameOpt.isPresent()) {
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        String key = nameOpt.get();
        map.put(key, data.get(key));
        data = map;
    }
    return Response.send(context, data);
}
Also used : Context(doitincloud.rdbcache.supports.Context) MapPropertySource(org.springframework.core.env.MapPropertySource) PropertySource(org.springframework.core.env.PropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with Context

use of doitincloud.rdbcache.supports.Context in project rdbcache by rdbcache.

the class RequestTest method process2.

@Test
public void process2() {
    try {
        String key = "01a089f3ab704c1aaecdbe13777538e0";
        HttpServletRequest request = getRequest("get", key, null, null, null, null);
        Context context = new Context();
        AnyKey anyKey = Request.process(context, request, new KvPairs(key), null, null);
        assertEquals(1, anyKey.size());
        KeyInfo keyInfo = anyKey.getKeyInfo();
        assertFalse(keyInfo.getIsNew());
        // System.out.println(keyInfo.toString());
        assertEquals("KeyInfo(false, user_table, 30, id = ?, [12466])", keyInfo.toString());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getCause().getMessage());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Context(doitincloud.rdbcache.supports.Context) MockServletContext(org.springframework.mock.web.MockServletContext) AnyKey(doitincloud.rdbcache.supports.AnyKey) KeyInfo(doitincloud.rdbcache.models.KeyInfo) KvPairs(doitincloud.rdbcache.supports.KvPairs) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Context (doitincloud.rdbcache.supports.Context)33 KvPairs (doitincloud.rdbcache.supports.KvPairs)25 AnyKey (doitincloud.rdbcache.supports.AnyKey)23 KeyInfo (doitincloud.rdbcache.models.KeyInfo)17 BadRequestException (doitincloud.commons.exceptions.BadRequestException)15 KvPair (doitincloud.rdbcache.models.KvPair)15 Test (org.junit.Test)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 NotFoundException (doitincloud.commons.exceptions.NotFoundException)4 ServerErrorException (doitincloud.commons.exceptions.ServerErrorException)2 KvIdType (doitincloud.rdbcache.models.KvIdType)2 QueryInfo (doitincloud.rdbcache.queries.QueryInfo)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 StopWatch (doitincloud.rdbcache.models.StopWatch)1 DbaseOps (doitincloud.rdbcache.services.DbaseOps)1 ExpireDbOps (doitincloud.rdbcache.supports.ExpireDbOps)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1