use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class ThreadAnalysisAction method doAction.
@Override
public void doAction(ActionContext context) throws Exception {
try {
UAVHttpMessage data = (UAVHttpMessage) context.getParam("msg");
if (!controlConcurrency(data)) {
data.putResponse("rs", "ERR");
data.putResponse("msg", "ERR:THREAD DUMP IS RUNNING");
return;
}
String user = data.getRequest("user");
if (StringHelper.isEmpty(user)) {
user = "UNKNOWN";
}
String url = data.getRequest("server") + SERVICE_POSTFIX;
if (!url.startsWith("http")) {
url = "http://" + url;
}
String param = data.getRequest("actparam");
@SuppressWarnings("unchecked") Map<String, Object> paramMap = JSONHelper.toObject(param, Map.class);
@SuppressWarnings("unchecked") List<Object> paramsList = (List<Object>) paramMap.get("param");
paramsList.add(this.dumpFileDirectory);
paramMap.put("param", paramsList);
ActionContext ac = new ActionContext();
ac.putParam("user", user);
ac.putParam("url", url);
ac.putParam("paramMap", paramMap);
if ("true".equals(data.getRequest("multiple"))) {
ac.putParam("multiple", true);
int duration = DataConvertHelper.toInt(data.getRequest("duration"), 0);
int interval = DataConvertHelper.toInt(data.getRequest("interval"), 5);
int times = duration / interval + 1;
ac.putParam("times", times);
ac.putParam("suspendTime", interval * 1000);
} else {
ac.putParam("multiple", false);
ac.putParam("times", 1);
ac.putParam("suspendTime", 0);
}
ac = getActionEngineMgr().getActionEngine("JTAActionEngine").execute("DumpThreadAction", ac);
String ret = (String) ac.getParam("msg");
if (ret.contains("ERR:")) {
data.putResponse("rs", "ERR");
data.putResponse("msg", ret);
} else {
data.putResponse("rs", "OK");
data.putResponse("msg", ret);
}
} catch (Exception e) {
log.err(this, "do thread analysis FAILED.", e);
throw e;
}
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class PushNotifyEventAction method run.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public boolean run(NotificationEvent event) {
AbstractSystemInvoker invoker = this.getSystemInvokerMgr().getSystemInvoker(InvokerType.HTTP);
UAVHttpMessage tmsg = new UAVHttpMessage();
tmsg.setIntent("ntfpush");
tmsg.putRequest("ntfevent", event.toJSONString());
String serviceStr = this.getConfigManager().getFeatureConfiguration(this.feature, "push.services");
if (StringHelper.isEmpty(serviceStr)) {
return true;
}
String[] services = serviceStr.split(",");
boolean check = true;
for (String service : services) {
try {
Map<String, Object> res = (Map<String, Object>) invoker.invoke(service, tmsg, Map.class);
if (res == null) {
check = false;
continue;
}
if (log.isTraceEnable()) {
log.info(this, "Push Notification to Service[" + service + "] SUCCESS.");
}
return true;
} catch (Exception e) {
check = false;
// ignore
}
}
return check;
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class NCHttpServerWorker method adaptRequest.
@Override
protected UAVHttpMessage adaptRequest(HttpMessage message) {
String messageBody = message.getRequestBodyAsString("UTF-8");
if (log.isDebugEnable()) {
log.debug(this, "NCHttpServerWorker Request: " + messageBody);
}
UAVHttpMessage msg = new UAVHttpMessage(messageBody);
return msg;
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class HttpSystemInvoker method invoke.
/**
* invoke
*
* @param serviceName
* 服务名
* @param serviceSubPath
* 服务相对路径(可选)
* @param msg
* 提交msg对象
* @param callback
* 异步回调(可选)
* @param syncTimeout
* 同步等待超时(可选)
* @param returnClass
* 同步返回对象类型(可选)
* @return
*/
private Object invoke(final String serviceName, final String serviceSubPath, final Object msg, final HttpClientCallback callback, final long syncTimeout, final Class<?> returnClass) {
if (StringHelper.isEmpty(serviceName)) {
return null;
}
// step 1: get service URI
final ConnectionFailoverMgr cfm = this.getServiceRoute(serviceName);
if (cfm == null) {
throw new RuntimeException("NoSuchServiceExist:" + serviceName);
}
final String serviceURL = cfm.getConnection();
if (serviceURL == null) {
throw new RuntimeException("NoAvailableServiceInstance:" + serviceName);
}
String finalServiceURL = serviceURL;
if (serviceSubPath != null) {
finalServiceURL = serviceURL + serviceSubPath;
}
// step 2: convert request Object to byte
byte[] data = null;
// byte[]
if (msg.getClass().isArray() && msg instanceof byte[]) {
data = (byte[]) msg;
} else // UAVHttpMessage
if (UAVHttpMessage.class.isAssignableFrom(msg.getClass())) {
try {
data = JSONHelper.toString(msg).getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else // String
if (String.class.isAssignableFrom(msg.getClass())) {
try {
data = msg.toString().getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
final SyncResult syncResult = new SyncResult();
// step 3: do post invoke
httpAsyncClient.doAsyncHttpPost(finalServiceURL, data, "application/json", "utf-8", new HttpClientCallback() {
@Override
public void completed(HttpClientCallbackResult result) {
if (callback != null) {
callback.completed(result);
}
if (syncTimeout <= 0) {
return;
}
if (returnClass != null) {
syncResult.setSdata(result.getReplyDataAsString());
} else {
syncResult.setBdata(result.getResulDataAsByteArray());
}
}
@Override
public void failed(HttpClientCallbackResult result) {
Exception exception = result.getException();
/**
* Auto Failover
*/
if (getDefFailoverCondition(exception)) {
cfm.putFailConnection(serviceURL);
invoke(serviceName, serviceSubPath, msg, callback);
return;
}
if (callback != null) {
callback.failed(result);
}
if (syncTimeout <= 0) {
return;
}
HttpAsyncException excep = result.getException();
if (excep != null) {
syncResult.setE(excep);
}
}
});
// step 4(optional): if sync mode, we should wait
if (syncTimeout <= 0) {
return null;
}
syncResult.waitSync(syncTimeout);
if (syncResult.getE() != null) {
throw new RuntimeException(syncResult.getE());
}
if (returnClass == null) {
return syncResult.getBdata();
}
if (String.class.isAssignableFrom(returnClass)) {
return syncResult.getSdata();
} else if (UAVHttpMessage.class.isAssignableFrom(returnClass)) {
return new UAVHttpMessage(syncResult.getSdata());
} else {
return JSONHelper.toObject(syncResult.getSdata(), returnClass);
}
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class DoTestNodeOperCtrl method main.
public static void main(String[] args) {
HttpAsyncClient.build(5, 5);
UAVHttpMessage msg = new UAVHttpMessage();
doTestSysPro(msg);
installMOF(msg);
// try {
// System.in.read();
// }
// catch (IOException e) {
//
// }
//
// uninstallMOF(msg);
}
Aggregations