use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class HeartBeatClientReqWorker method doServiceDiscovery.
/**
* 实现服务发现功能:MSCP的服务发现需要利用心跳客户端的支持
*
* @param serviceName
* @return
*/
public String[] doServiceDiscovery(String serviceName) {
/**
* step 1: select a heartbeat server url
*/
final String connectStr = cfmgr.getConnection();
if (null == connectStr) {
log.err(this, "Select HeartBeatServer URL Fail as no available HeartBeatServer.");
return null;
}
String[] connectInfo = connectStr.split(":");
/**
* NOTE: hbQueryServer's port=hbServer's port +10
*/
int hbServerPort = DataConvertHelper.toInt(connectInfo[1], 8010) + 10;
String hbserverURL = "http://" + connectInfo[0] + ":" + hbServerPort + "/hb/query";
if (log.isDebugEnable()) {
log.debug(this, "Selected HeartBeatServer URL is " + hbserverURL);
}
/**
* step 2: build msg
*/
UAVHttpMessage msg = new UAVHttpMessage();
msg.setIntent("services");
msg.putRequest("service", serviceName);
byte[] datab = null;
try {
datab = JSONHelper.toString(msg).getBytes("utf-8");
} catch (UnsupportedEncodingException e1) {
return null;
}
/**
* step 3: request hbquery
*/
final CountDownLatch cdl = new CountDownLatch(1);
final StringBuffer resultStr = new StringBuffer();
client.doAsyncHttpPost(hbserverURL, datab, "application/json", "utf-8", new HttpClientCallback() {
@Override
public void completed(HttpClientCallbackResult result) {
/**
* step 4: run handlers for downstream response
*/
resultStr.append(result.getReplyDataAsString());
// CountDownLatch unlock
cdl.countDown();
}
@Override
public void failed(HttpClientCallbackResult result) {
/**
* mark this hbserver is NOT OK
*/
cfmgr.putFailConnection(connectStr);
// CountDownLatch unlock
cdl.countDown();
}
});
/**
* step 4: wait the async http invoking result
*/
try {
cdl.await(5000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// ignore
}
if (resultStr.length() == 0) {
return null;
}
@SuppressWarnings("unchecked") Map<String, String> resMap = JSONHelper.toObject(resultStr.toString(), Map.class);
if (resMap.containsKey("err")) {
return null;
}
String servicesStr = resMap.get("rs");
List<String> services = JSONHelper.toObjectArray(servicesStr, String.class);
String[] urls = new String[services.size()];
return services.toArray(urls);
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class NewLogQueryServerWorker method adaptRequest.
@Override
protected UAVHttpMessage adaptRequest(HttpMessage message) {
String messageBody = message.getRequestBodyAsString("UTF-8");
if (log.isDebugEnable()) {
log.debug(this, "NewLogQueryServerWorker Request: " + messageBody);
}
UAVHttpMessage msg = new UAVHttpMessage(messageBody);
return msg;
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method loadUavNetworkInfo.
/**
* 应用容器监控+UAV节点信息
*
* @return
*/
@GET
@Path("node/q/cache")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void loadUavNetworkInfo(@QueryParam("fkey") String fkey, @QueryParam("fvalue") String fvalue, @Suspended AsyncResponse response) {
UAVHttpMessage message = new UAVHttpMessage();
message.setIntent("node");
if (StringHelper.isEmpty(fkey) || StringHelper.isEmpty(fvalue)) {
String groups = getUserGroupsByFilter(request);
if ("NOMAPPING".equals(groups)) {
response.resume("{\"rs\":\"{}\"}");
} else if ("ALL".equals(groups)) {
loadUavNetworkInfoFromHttp(message, response);
} else {
message.putRequest("fkey", "group");
message.putRequest("fvalue", groups);
loadUavNetworkInfoFromHttp(message, response);
}
} else {
message.putRequest("fkey", fkey);
message.putRequest("fvalue", fvalue);
loadUavNetworkInfoFromHttp(message, response);
}
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method groupFilterLoadAppProfileList.
// -----------------------------------------filter begin -------------------------------------
/**
* 应用服务监控:全网应用Profile SnapShot
*
* @return
*/
@GET
@Path("filter/profile/q/cache")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void groupFilterLoadAppProfileList(@Suspended AsyncResponse response) {
UAVHttpMessage message = new UAVHttpMessage();
message.setIntent("profile");
loadAppProfileListFromHttp(message, response);
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method loadAppProfileList.
/**
* 应用服务监控:全网应用Profile SnapShot
*
* @return
*/
@GET
@Path("profile/q/cache")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void loadAppProfileList(@QueryParam("fkey") String fkey, @QueryParam("fvalue") String fvalue, @Suspended AsyncResponse response) {
UAVHttpMessage message = new UAVHttpMessage();
message.setIntent("profile");
if (StringHelper.isEmpty(fkey) || StringHelper.isEmpty(fvalue)) {
String groups = getUserGroupsByFilter(request);
if ("NOMAPPING".equals(groups)) {
response.resume("{\"rs\":\"{}\"}");
} else if ("ALL".equals(groups)) {
loadAppProfileListFromHttp(message, response);
} else {
message.putRequest("fkey", "appgroup");
message.putRequest("fvalue", groups);
loadAppProfileListFromHttp(message, response);
}
} else {
message.putRequest("fkey", fkey);
message.putRequest("fvalue", fvalue);
loadAppProfileListFromHttp(message, response);
}
}
Aggregations