use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.
the class PersistentTask method updateDatabase.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void updateDatabase(NotificationEvent event) {
DataStoreMsg msg = new DataStoreMsg();
Map<String, Map> condition = new LinkedHashMap<String, Map>();
Map<String, Object> where = new LinkedHashMap<String, Object>();
Map<String, Object> update = new LinkedHashMap<String, Object>();
Map<String, Object> set = new LinkedHashMap<String, Object>();
Map<String, Object> ntfargs = JSONHelper.toObject(event.getArg(NCConstant.NTFVALUE), Map.class);
// 如果当前预警是第一条数据,如果不是第一条数据,只更新第一条
if (event.getArg(NCConstant.NCFirstEvent).equals("true")) {
if (log.isDebugEnable()) {
log.debug(this, "the Event is new for key:" + event.getArg(NCConstant.NTFKEY));
log.debug(this, "the Event is new for start Time :" + event.getTime());
}
where.put(NCConstant.COLUMN_NTFKEY, event.getArg(NCConstant.NTFKEY));
// fix bug
where.put("time", event.getTime());
set.put(NCConstant.COLUMN_FIRSTRECORD, "true");
} else {
if (log.isDebugEnable()) {
log.debug(this, "the Event exists for key:" + event.getArgs(true).get(NCConstant.NTFKEY));
log.debug(this, "the Event exists for start Time :" + event.getArg(NCConstant.COLUMN_STARTTIME));
}
where.put(NCConstant.COLUMN_NTFKEY, event.getArg(NCConstant.NTFKEY));
where.put("time", ntfargs.get(NCConstant.COLUMN_STARTTIME));
where.put(NCConstant.COLUMN_FIRSTRECORD, "true");
}
set.put(NCConstant.COLUMN_STATE, ntfargs.get(NCConstant.COLUMN_STATE));
if (ntfargs.get(NCConstant.COLUMN_RETRY_COUNT) != null) {
set.put(NCConstant.COLUMN_RETRY_COUNT, ntfargs.get(NCConstant.COLUMN_RETRY_COUNT));
}
if (ntfargs.get(NCConstant.COLUMN_VIEWTIME) != null) {
set.put(NCConstant.COLUMN_VIEWTIME, ntfargs.get(NCConstant.COLUMN_VIEWTIME));
}
if (ntfargs.get(NCConstant.COLUMN_LATESTIME) != null) {
set.put(NCConstant.COLUMN_LATESTIME, ntfargs.get(NCConstant.COLUMN_LATESTIME));
}
if (ntfargs.get(NCConstant.COLUMN_LATESTRECORDTIME) != null) {
set.put(NCConstant.COLUMN_LATESTRECORDTIME, ntfargs.get(NCConstant.COLUMN_LATESTRECORDTIME));
}
if (ntfargs.get(NCConstant.EVENT_COUNT) != null) {
set.put(NCConstant.EVENT_COUNT, ntfargs.get(NCConstant.EVENT_COUNT));
}
update.put("set", set);
condition.put("where", where);
condition.put("update", update);
msg.put(DataStoreProtocol.DATASTORE_NAME, MonitorDataFrame.MessageType.Notification.toString());
msg.put(DataStoreProtocol.MONGO_QUERY_SQL, JSONHelper.toString(condition));
msg.put(DataStoreProtocol.MONGO_COLLECTION_NAME, NCConstant.MONGO_COLLECTION_NOTIFY);
if (log.isDebugEnable()) {
log.debug(this, "NC Update Mongodb condition: " + JSONHelper.toString(condition));
}
// Exchange消息给HM做数据库更新
AgentFeatureComponent afc = (AgentFeatureComponent) ConfigurationManager.getInstance().getComponent("healthmanager", "HealthManager");
if (null != afc) {
boolean flag = (boolean) afc.exchange("opt.update", msg);
if (log.isDebugEnable()) {
log.debug(this, "NC Update Mongodb result: " + flag);
}
}
}
use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.
the class DoTestLoadNCCache method pushEventoNC.
public static void pushEventoNC() {
AgentFeatureComponent afc = (AgentFeatureComponent) ConfigurationManager.getInstance().getComponent("notifycenter", "NotificationCenter");
String rawData = getData(notifyJson);
afc.exchange("notify.center.put", rawData);
}
use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.
the class AppServerLogPublishWorker method handle.
@Override
protected void handle(List<MonitorDataFrame> mdflist) {
MessageProducer producer = (MessageProducer) this.getComponentResource("messageproducer", "MessageProducerResourceComponent");
// submit profile data
Message msg = MessagingFactory.createMessage(MonitorDataFrame.MessageType.Log.toString());
StringBuilder sb = new StringBuilder("[");
for (MonitorDataFrame mdf : mdflist) {
sb.append(mdf.toJSONString() + ",");
}
if (mdflist.size() > 0) {
sb = sb.deleteCharAt(sb.length() - 1);
}
String stream = sb.append("]").toString();
msg.setParam(MonitorDataFrame.MessageType.Log.toString(), stream);
if (log.isDebugEnable()) {
log.debug(this, "## LogPublishWorker stream length ## : " + stream.getBytes().length);
log.debug(this, "## LogPublishWorker stream value ## : " + stream);
}
producer.setLogger(log);
boolean check = producer.submit(msg);
String sendState = "Log Data Sent " + (check ? "SUCCESS" : "FAIL");
if (log.isDebugEnable()) {
log.debug(this, sendState + " " + sendState);
}
if (null != getConfigManager().getComponent("monitortestagent", "MonitorAgentUT")) {
AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent("monitortestagent", "monitortestagent");
afc.exchange("logTest", mdflist);
}
}
use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.
the class JVMContainerOSDetector method scanWithProcDetection.
/**
* scanWithProcDetection
*/
@SuppressWarnings("unchecked")
private void scanWithProcDetection() {
AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent("procscan", "ProcDetectAgent");
if (afc == null) {
return;
}
Collection<OSProcess> procs = (Collection<OSProcess>) afc.exchange("procscan.query.allprocs");
if (procs == null) {
return;
}
if (log.isDebugEnable()) {
log.debug(this, "ContainerOSDetector scan START...");
}
for (OSProcess proc : procs) {
String name = proc.getName();
/**
* NOTE: support docker-proxy,docker,docker-current; support java http scanning for dev work more
*/
if (name.indexOf("docker") == -1 && name.indexOf("java") == -1) {
continue;
}
Map<String, String> tags = proc.getTags();
String jargs = StringHelper.isEmpty(tags.get("jargs")) ? "" : tags.get("jargs");
/**
* NOTE: must install uavmof
*/
if (!(jargs.contains("-javaagent:") && jargs.contains("monitorframework"))) {
continue;
}
List<String> needDectectUrls = getDetectUrls(proc);
for (String url : needDectectUrls) {
client.doAsyncHttpGet(url + UAV_MOF_ROOT + "jvm?action=ping", new ScanPingCallback(proc, url));
}
}
}
use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.
the class MSCPGeneralAction method restartProc.
/**
* restartProc
*
* @param data
*/
private void restartProc(UAVHttpMessage data) {
String pid = data.getRequest("pid");
AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent("procwatch", "ProcWatchAgent");
if (afc != null) {
Object res = afc.exchange("agent.procwatch.restart", pid);
if (res != null) {
data.putResponse("rs", String.valueOf(res));
return;
}
}
data.putResponse("rs", "ERR");
}
Aggregations