use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method noitifyStrategyGet.
@POST
@Path("notify/get/stgy/hm")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void noitifyStrategyGet(String data, @Suspended AsyncResponse response) throws Exception {
Map<String, String> strategyMap = new HashMap<String, String>();
strategyMap.put("keys", data);
// 封装http请求数据
UAVHttpMessage message = new UAVHttpMessage();
message.putRequest("body", JSONHelper.toString(strategyMap));
message.setIntent("strategy.query");
NoitifyStrategyGetCB callback = new NoitifyStrategyGetCB();
callback.setResponse(response);
doHttpPost("uav.app.godeye.notify.strategy.http.addr", "/rtntf/oper", message, callback);
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method noitifyDescQuery.
/**
* 先获取第一条预警信息,条件:time,ntfkey 获取当前查看时间:如果有则取其时间范围内数据,没有则取time以后所有数据
*
* @param data
* @param response
* @throws Exception
*/
@SuppressWarnings("unchecked")
@POST
@Path("notify/q/desc/hm")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void noitifyDescQuery(String data, @Suspended AsyncResponse response) throws Exception {
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Map<String, String> jsonParam = JSONHelper.toObject(data, Map.class);
String url = jsonParam.get("url");
Long time;
if ("link".equals(jsonParam.get("type"))) {
byte[] d = new BASE64DecoderUrl().decodeBuffer(url);
url = new String(d, "utf-8");
time = Long.valueOf(url.substring(url.lastIndexOf("&") + 1));
} else {
String timeStr = url.substring(url.lastIndexOf("&") + 1);
time = simpleDateFormat.parse(timeStr).getTime();
}
final String ntfkey = url.substring(0, url.lastIndexOf("&"));
HashMap<String, Object> requestWhere = new HashMap<String, Object>();
requestWhere.put("ntfkey", ntfkey);
requestWhere.put("firstrecord", "true");
requestWhere.put("time", time);
HashMap<String, Object> requestParam = new HashMap<String, Object>();
requestParam.put("where", requestWhere);
HashMap<String, Object> sort = new HashMap<String, Object>();
sort.put("values", "time");
sort.put("sortorder", "-1");
requestParam.put("sort", sort);
// 封装http请求数据
UAVHttpMessage message = new UAVHttpMessage();
message.putRequest("mgo.sql", JSONHelper.toString(requestParam));
message.putRequest("datastore.name", "MT_Notify");
message.putRequest("mgo.coll.name", "uav_notify");
NoitifyDescQueryCB callback = new NoitifyDescQueryCB();
callback.setResponse(response);
callback.setNtfkey(ntfkey);
callback.setTime(time);
doHttpPost("uav.app.godeye.healthmanager.http.addr", "/hm/query", message, callback);
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method saveFeedback.
// ---------------------------------------新日志服务接口 END-------------------------------------
// ---------------------------------------反馈建议 START-----------------------------------
/**
* searchNewLog
*
* @param data
* @param resp
*/
@SuppressWarnings("unchecked")
@POST
@Path("/feedback/save")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void saveFeedback(String reqData, @Suspended AsyncResponse resp) {
String userId = "";
if (null != request.getSession(false)) {
Object obj = request.getSession(false).getAttribute("apphub.gui.session.login.user.id");
userId = null == obj ? "" : String.valueOf(obj);
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String time = simpleDateFormat.format(new Date());
Map<String, String> httpData = JSONHelper.toObject(reqData, Map.class);
httpData.put("time", time);
httpData.put("uid", userId);
IdWorker idWorker = CommonHelper.getUUIDWorker(new Random().nextInt(30) + 1, 1);
String uuid = String.valueOf(idWorker.nextId());
httpData.put("key", uuid);
/**
* 打包请求数据
*/
Map<String, Object> mapParam = new HashMap<String, Object>();
mapParam.put("type", "create");
mapParam.put("data", httpData);
UAVHttpMessage request = new UAVHttpMessage();
request.putRequest("mrd.data", JSONHelper.toString(mapParam));
request.putRequest("datastore.name", "AppHub.feedback");
request.putRequest("mgo.coll.name", "uav_feedback");
doHttpPost("uav.app.manage.apphubmanager.http.addr", "/ah/feedback", request, new GodEyeCB(resp));
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method queryFeedbackCount.
@SuppressWarnings("unchecked")
@POST
@Path("/feedback/query/count")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void queryFeedbackCount(String reqData, @Suspended AsyncResponse resp) {
Map<String, String> reqInfo = JSONHelper.toObject(reqData, Map.class);
Map<String, Object> where = new HashMap<String, Object>();
String userGroup = String.valueOf(request.getSession(false).getAttribute("apphub.gui.session.login.user.group"));
if (reqInfo.containsKey("checkuser") || (!"vipgroup".equals(userGroup) && !"uav_admin".equals(userGroup))) {
/**
* 不是admin用户则添加过滤
*/
Object obj = request.getSession(false).getAttribute("apphub.gui.session.login.user.id");
String userId = null == obj ? "" : String.valueOf(obj);
where.put("uid", userId);
}
Map<String, Object> data = new HashMap<String, Object>();
data.put("where", where);
data.put("count", "true");
Map<String, Object> mapParam = new HashMap<String, Object>();
mapParam.put("type", "query");
mapParam.put("data", data);
/**
* 打包请求数据
*/
UAVHttpMessage request = new UAVHttpMessage();
request.putRequest("mrd.data", JSONHelper.toString(mapParam));
request.putRequest("datastore.name", "AppHub.feedback");
request.putRequest("mgo.coll.name", "uav_feedback");
doHttpPost("uav.app.manage.apphubmanager.http.addr", "/ah/feedback", request, new GodEyeCB(resp));
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method noitifyQueryBest.
@SuppressWarnings({ "unchecked", "rawtypes" })
@POST
@Path("notify/q/best/hm")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void noitifyQueryBest(String data, @Suspended AsyncResponse response) {
// 数据权限begin
String groups = getUserGroupsByFilter(request);
List groupList = Collections.emptyList();
boolean checkAuthor = true;
if ("NOMAPPING".equals(groups)) {
checkAuthor = false;
} else if ("ALL".equals(groups)) {
/**
* nothing
*/
} else {
String[] gs = groups.split(",");
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("[");
for (String group : gs) {
sBuilder.append("{");
sBuilder.append("\"regex\":{\"appgroup\":\"" + group + "\"}");
sBuilder.append("}");
}
sBuilder.append("]");
HashMap<String, Object> or = new HashMap<String, Object>();
or.put("or", JSONHelper.toObjectArray(sBuilder.toString(), Map.class));
HashMap<String, Object> match = new HashMap<String, Object>();
match.put("match", or);
groupList = new ArrayList<HashMap<String, Object>>();
groupList.add(match);
}
if (checkAuthor) {
// mongodb .为关键字,封装时替换为#交由后台处理
data = data.replaceAll("\\.", "#");
HashMap<String, String> jsonParam = JSONHelper.toObject(data, HashMap.class);
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
// 过滤数据,只查询最近的指定数据 begin
HashMap<String, Object> sortMap = new HashMap<String, Object>();
HashMap<String, Object> sort = new HashMap<String, Object>();
sort.put("values", "time");
sort.put("sortorder", "-1");
sortMap.put("sort", sort);
list.add(sortMap);
HashMap<String, Object> firstRecord = new HashMap<String, Object>();
HashMap<String, Object> firstRecordMatch = new HashMap<String, Object>();
firstRecord.put("firstrecord", "true");
firstRecordMatch.put("match", firstRecord);
list.add(firstRecordMatch);
// 封装组合查询条件 list.add = and
if (jsonParam.containsKey("event")) {
HashMap<String, Object> eventMap = new HashMap<String, Object>();
HashMap<String, Object> eventMatch = new HashMap<String, Object>();
eventMap.put("eventid", jsonParam.get("event"));
eventMatch.put("match", eventMap);
list.add(eventMatch);
}
if (jsonParam.containsKey("ip")) {
HashMap<String, Object> ipMap = new HashMap<String, Object>();
HashMap<String, Object> ipRegex = new HashMap<String, Object>();
HashMap<String, Object> ipMatch = new HashMap<String, Object>();
ipMap.put("ip", jsonParam.get("ip"));
ipRegex.put("regex", ipMap);
ipMatch.put("match", ipRegex);
list.add(ipMatch);
}
if (jsonParam.containsKey("host")) {
HashMap<String, Object> hostMap = new HashMap<String, Object>();
HashMap<String, Object> hostRegex = new HashMap<String, Object>();
HashMap<String, Object> hostMatch = new HashMap<String, Object>();
hostMap.put("host", jsonParam.get("host"));
hostRegex.put("regex", hostMap);
hostMatch.put("match", hostRegex);
list.add(hostMatch);
}
if (jsonParam.containsKey("description")) {
HashMap<String, Object> descriptionMap = new HashMap<String, Object>();
HashMap<String, Object> descriptionRegex = new HashMap<String, Object>();
HashMap<String, Object> descriptionMatch = new HashMap<String, Object>();
descriptionMap.put("description", jsonParam.get("description"));
descriptionRegex.put("regex", descriptionMap);
descriptionMatch.put("match", descriptionRegex);
list.add(descriptionMatch);
}
if (jsonParam.containsKey("abstract")) {
HashMap<String, Object> abstractMap = new HashMap<String, Object>();
HashMap<String, Object> abstractRegex = new HashMap<String, Object>();
HashMap<String, Object> abstractMatch = new HashMap<String, Object>();
abstractMap.put("title", jsonParam.get("abstract"));
abstractRegex.put("regex", abstractMap);
abstractMatch.put("match", abstractRegex);
list.add(abstractMatch);
}
if (jsonParam.containsKey("startTime")) {
HashMap<String, Object> startTime = new HashMap<String, Object>();
HashMap<String, Object> startTimeRegex = new HashMap<String, Object>();
HashMap<String, Object> startTimeMatch = new HashMap<String, Object>();
startTime.put("latestrecord_ts", jsonParam.get("startTime"));
startTimeRegex.put(">", startTime);
startTimeMatch.put("match", startTimeRegex);
list.add(startTimeMatch);
}
if (jsonParam.containsKey("endTime")) {
HashMap<String, Object> endTime = new HashMap<String, Object>();
HashMap<String, Object> endTimeRegex = new HashMap<String, Object>();
HashMap<String, Object> endTimeMatch = new HashMap<String, Object>();
endTime.put("latestrecord_ts", jsonParam.get("endTime"));
endTimeRegex.put("<", endTime);
endTimeMatch.put("match", endTimeRegex);
list.add(endTimeMatch);
}
if (!groupList.isEmpty()) {
list.addAll(groupList);
}
HashMap<String, Object> skipMap = new HashMap<String, Object>();
skipMap.put("skip", mongodbQueryRangeMap.get("skip"));
list.add(skipMap);
HashMap<String, Object> limitMap = new HashMap<String, Object>();
limitMap.put("limit", mongodbQueryRangeMap.get("limit"));
list.add(limitMap);
HashMap<String, Object> pageIndex = new HashMap<String, Object>();
HashMap<String, Object> pageSize = new HashMap<String, Object>();
HashMap<String, Object> pageSortOrder = new HashMap<String, Object>();
pageIndex.put("pageindex", String.valueOf(jsonParam.get("pageindex")));
pageSize.put("pagesize", String.valueOf(jsonParam.get("pagesize")));
list.add(pageIndex);
list.add(pageSize);
list.add(pageSortOrder);
// 封装http请求数据
UAVHttpMessage message = new UAVHttpMessage();
message.putRequest("mgo.sql", JSONHelper.toString(list));
message.putRequest("datastore.name", "MT_Notify");
message.putRequest("mgo.coll.name", "uav_notify");
NoitifyQueryBestCB callback = new NoitifyQueryBestCB();
callback.setResponse(response);
doHttpPost("uav.app.godeye.healthmanager.http.addr", "/hm/query", message, callback);
}
}
Aggregations