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;
}
}
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;
}
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;
}
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);
}
});
}
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());
}
Aggregations