Search in sources :

Example 31 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class HttpTestQuery method loopTest.

public static void loopTest() {
    try {
        // HttpAsyncClient.build(1000, 1000, 100000, 100000, 100000);
        String url = "http://localhost:8765/hm/query";
        UAVHttpMessage request = new UAVHttpMessage();
        String content = null;
        String[] fileName = { "DSAggregatequery.json", "DSAggregatequeryGtLt.json", "DSAggregatequeryMKV.json", "DSAggregatequeryRegex_GtInOR.json", "DSAggregatequeryRegex.json", "DSAggregatequeryRegexInOR.json", "DSAggregatequeryRegexMKVInOR.json", "DSfind.json" };
        for (int i = 0; i < fileName.length; i++) {
            // System.out.println("test query : " + fileName[i]);
            String query = DataStoreUnitTest.getData(queryJsonDir + fileName[i]);
            content = prepareMongoProfileDBdata(request, query);
            executeHttpCommand(fileName[i], url, content);
            Thread.sleep(100);
        }
    } catch (Exception e) {
        return;
    }
}
Also used : UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 32 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class StrategyJudgement method queryOpentsdb.

@SuppressWarnings({ "unchecked", "rawtypes" })
private Double queryOpentsdb(String instance, String metric, String func, Long startTime, Long endTime) {
    Double result = null;
    for (int i = 0; i < 3 && result == null; i++) {
        try {
            UAVHttpMessage message = new UAVHttpMessage();
            String data = String.format("{\"start\":%d,\"end\":%d,\"queries\":[{\"aggregator\":\"avg\",\"downsample\":\"%s\",\"metric\":\"%s\",\"filters\":[{\"filter\":\"%s\",\"tagk\":\"instid\",\"type\":\"regexp\",\"groupBy\":false}]}]}", startTime, endTime, func, metric, instance.replace(":", "/u003a").replace("%", "/u0025").replace("#", "/u0023"));
            message.putRequest("opentsdb.query.json", data);
            message.putRequest("datastore.name", MonitorDataFrame.MessageType.Monitor.toString());
            String queryResponse = String.valueOf(invoker.invoke(queryServiceName, message, String.class));
            if (queryResponse.equals("null") || queryResponse.equals("{}") || queryResponse.equals("{\"rs\":\"[]\"}")) {
                continue;
            }
            Map<Object, Object> responseMap = JSONHelper.toObject(queryResponse, Map.class);
            List<Map> rsList = JSONHelper.toObjectArray((String) responseMap.get(UAVHttpMessage.RESULT), Map.class);
            for (Object value : ((Map) rsList.get(0).get("dps")).values()) {
                result = ((BigDecimal) value).doubleValue();
            }
        } catch (Exception e) {
            log.err(this, "TimerExpression judgement query opentsdb failed ", e);
        }
    }
    return result;
}
Also used : UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 33 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class RuntimeNotifyServerWorker method adaptRequest.

@Override
protected UAVHttpMessage adaptRequest(HttpMessage message) {
    String messageBody = message.getRequestBodyAsString("UTF-8");
    if (log.isDebugEnable()) {
        log.debug(this, "RuntimeNotifyServerWorker Request: " + messageBody);
    }
    UAVHttpMessage msg = new UAVHttpMessage(messageBody);
    return msg;
}
Also used : UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage)

Example 34 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class NodeOperCtrlClient method doCMD.

private static void doCMD(final String cmd, Map<String, String> jsonArgs, String port) {
    UAVHttpMessage msg = new UAVHttpMessage();
    msg.setIntent(cmd);
    for (String key : jsonArgs.keySet()) {
        msg.putRequest(key, jsonArgs.get(key));
    }
    HttpAsyncClient.build(5, 5);
    String url = "http://localhost:" + port + "/node/ctrl";
    print("Node Operation Command[" + cmd + "] START on " + url);
    HttpAsyncClient.instance().doAsyncHttpPost(url, JSONHelper.toString(msg), new HttpClientCallback() {

        @Override
        public void completed(HttpClientCallbackResult result) {
            print("Node Operation Command[" + cmd + "] DONE.");
            System.exit(0);
        }

        @Override
        public void failed(HttpClientCallbackResult result) {
            print("Node Operation Command[" + cmd + "] DONE.");
            System.exit(0);
        }
    });
}
Also used : HttpClientCallback(com.creditease.uav.httpasync.HttpClientCallback) UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) HttpClientCallbackResult(com.creditease.uav.httpasync.HttpClientCallbackResult)

Example 35 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class MOFCtrlAction method doAction.

@Override
public void doAction(ActionContext context) throws Exception {
    UAVHttpMessage data = (UAVHttpMessage) context.getParam("msg");
    /**
     * Step 1: start the Supporter (AutoCheck if it is started)
     */
    String action = data.getRequest("action");
    String server = data.getRequest("server") + "/com.creditease.uav/server?action=" + action;
    String rootPath = data.getRequest("root");
    if (!StringHelper.isEmpty(rootPath)) {
        server += "&tag=" + rootPath;
    }
    final String url = server;
    String param = data.getRequest("actparam");
    final AtomicBoolean isSuccess = new AtomicBoolean(false);
    final CountDownLatch cdl = new CountDownLatch(1);
    final StringBuilder response = new StringBuilder();
    client.doAsyncHttpPost(url, param, new HttpClientCallback() {

        @Override
        public void completed(HttpClientCallbackResult result) {
            String res = result.getReplyDataAsString();
            if (result.getRetCode() >= 400) {
                log.err(this, "MOFCtrlAction FAIL: retcode=" + result.getRetCode() + ", url=" + url + ", err=" + res);
                if (result.getRetCode() >= 500) {
                    response.append("请求" + url + "完成时的状态码为【" + result.getRetCode() + "】, 服务器遇到错误而不能完成该请求.");
                } else {
                    response.append("请求" + url + "完成时的状态码为【" + result.getRetCode() + "】, 请求客户端错误.");
                }
                isSuccess.set(false);
            } else {
                response.append(res);
                log.info(this, "MOFCtrlAction Success: retcode=" + result.getRetCode() + ", url=" + url + ", res=" + res);
                if (!StringHelper.isEmpty(res)) {
                    isSuccess.set(true);
                }
            }
            cdl.countDown();
        }

        @Override
        public void failed(HttpClientCallbackResult result) {
            String exp = result.getException().getMessage();
            response.append(exp);
            log.err(this, "MOFCtrlAction FAIL: url=" + url + ", err=" + exp);
            isSuccess.set(false);
            cdl.countDown();
        }
    });
    cdl.await(5000, TimeUnit.MILLISECONDS);
    if (isSuccess.get() == false) {
        data.putResponse("rs", "ERR");
        data.putResponse("msg", response.toString());
        return;
    }
    /**
     * Step 2: notify Collect Client for capture files
     */
    if (data.getRequest().containsKey("collectact")) {
        doCollectFiles(data, response, rootPath);
        return;
    }
    data.putResponse("rs", "OK");
    data.putResponse("msg", response.toString());
}
Also used : HttpClientCallback(com.creditease.uav.httpasync.HttpClientCallback) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientCallbackResult(com.creditease.uav.httpasync.HttpClientCallbackResult)

Aggregations

UAVHttpMessage (com.creditease.agent.http.api.UAVHttpMessage)58 Path (javax.ws.rs.Path)25 Produces (javax.ws.rs.Produces)25 POST (javax.ws.rs.POST)22 HashMap (java.util.HashMap)14 HttpClientCallback (com.creditease.uav.httpasync.HttpClientCallback)5 HttpClientCallbackResult (com.creditease.uav.httpasync.HttpClientCallbackResult)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ApphubException (com.creditease.uav.exception.ApphubException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 IOException (java.io.IOException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 GET (javax.ws.rs.GET)3 AbstractSystemInvoker (com.creditease.agent.spi.AbstractSystemInvoker)2 AgentFeatureComponent (com.creditease.agent.spi.AgentFeatureComponent)2 BASE64DecoderUrl (com.creditease.uav.helpers.url.BASE64DecoderUrl)2 Date (java.util.Date)2