Search in sources :

Example 1 with ActionContext

use of com.creditease.agent.spi.ActionContext in project uavstack by uavorg.

the class ProfileDataMessageHandler method pushLatestProfileDataToCacheCenter.

/**
 * 推送最新的ProfileData到缓存中心
 *
 * @param profileString
 */
private List<String> pushLatestProfileDataToCacheCenter(String profileString) {
    /**
     * setup ProfileDataMessageHandler as IStandardProfileModelListener for StandardProfileModeler
     */
    ISystemActionEngineMgr engineMgr = (ISystemActionEngineMgr) ConfigurationManager.getInstance().getComponent("Global", "ISystemActionEngineMgr");
    IActionEngine engine = engineMgr.getActionEngine("StandardProfileModelingEngine");
    StandardProfileModeler modeler = (StandardProfileModeler) ConfigurationManager.getInstance().getComponent("healthmanager", "StandardProfileModeler");
    modeler.setListener(this);
    cm.beginBatch();
    List<String> monitorDataFrames = JSONHelper.toObjectArray(profileString, String.class);
    List<String> newMDFs = new ArrayList<String>();
    for (String mdfStr : monitorDataFrames) {
        MonitorDataFrame mdf = new MonitorDataFrame(mdfStr);
        ActionContext ac = new ActionContext();
        ac.putParam(MonitorDataFrame.class, mdf);
        ac.putParam("NewMDFList", newMDFs);
        ac.putParam("MDFString", mdfStr);
        engine.execute("StandardProfileModeler", ac);
    }
    cm.submitBatch();
    return newMDFs;
}
Also used : ISystemActionEngineMgr(com.creditease.agent.spi.ISystemActionEngineMgr) ArrayList(java.util.ArrayList) StandardProfileModeler(com.creditease.agent.profile.api.StandardProfileModeler) MonitorDataFrame(com.creditease.agent.monitor.api.MonitorDataFrame) ActionContext(com.creditease.agent.spi.ActionContext) IActionEngine(com.creditease.agent.spi.IActionEngine)

Example 2 with ActionContext

use of com.creditease.agent.spi.ActionContext in project uavstack by uavorg.

the class SlowOperDataCollectHandler method handle.

@Override
public void handle(CollectDataFrame frame) {
    if (this.log.isDebugEnable()) {
        this.log.debug(this, frame.toJSONString());
    }
    BulkRequestBuilder bulkRequest = client.getClient().prepareBulk();
    String appUUID = frame.getTarget();
    // 从uuid中获取appid
    String appid = appUUID.split("---")[1];
    for (Line line : frame.getLines()) {
        String content = line.getContent();
        try {
            // 提取epinfo
            StringBuilder builder = new StringBuilder();
            int headPoint = 0;
            for (int i = 0; i < content.length(); i++) {
                char item = content.charAt(i);
                if (item == ';') {
                    headPoint++;
                    if (headPoint == 3) {
                        break;
                    }
                } else {
                    if (headPoint > 1) {
                        builder.append(item);
                    }
                }
            }
            String epinfo = builder.toString();
            // 若epinfo为数字则说明为方法级
            if (DataConvertHelper.toInt(epinfo, -1) != -1) {
                epinfo = "method";
            }
            IActionEngine engine = this.getActionEngineMgr().getActionEngine("SlowOperActionEngine");
            ActionContext ac = new ActionContext();
            ac.putParam("content", content);
            ac.putParam("appid", appid);
            engine.execute(epinfo, ac);
            SlowOperSpan span = (SlowOperSpan) ac.getParam("span");
            pushSpanToBulkRequest(appUUID, frame.getAppgroup(), span, bulkRequest, (String) ac.getParam("protocolType"));
        } catch (Exception e) {
            // 防止有不合法的协议报文出现
            this.log.err(this, "unsupported protocol,content is" + frame.toJSONString(), e);
        }
    }
    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        log.err(this, "INSERT InvokeChain Data to ES FAIL: " + bulkResponse.buildFailureMessage());
    }
}
Also used : Line(com.creditease.agent.apm.api.CollectDataFrame.Line) SlowOperSpan(com.creditease.uav.invokechain.data.SlowOperSpan) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) ActionContext(com.creditease.agent.spi.ActionContext) IActionEngine(com.creditease.agent.spi.IActionEngine)

Example 3 with ActionContext

use of com.creditease.agent.spi.ActionContext in project uavstack by uavorg.

the class NotificationCenter method executeNotifyAction.

/**
 * 执行NotifyAction
 *
 * @param actionSet
 * @param event
 */
public void executeNotifyAction(Map<String, String> actionMap, NotificationEvent event) {
    for (String actionkey : actionMap.keySet()) {
        ActionContext ac = new ActionContext();
        ac.putParam("event", event);
        ac.putParam(NCConstant.ACTIONVALUE, actionMap.get(actionkey));
        ac = engine.execute(actionkey, ac);
        String stateStr = (ac.isSucessful() == true) ? "SUCCESS" : "FAIL";
        if (log.isTraceEnable()) {
            log.info(this, "NotificationTask Action[" + actionkey + "] " + stateStr);
        }
    }
}
Also used : ActionContext(com.creditease.agent.spi.ActionContext)

Example 4 with ActionContext

use of com.creditease.agent.spi.ActionContext in project uavstack by uavorg.

the class ThreadAnalysisAction method sendMail.

private boolean sendMail(NotificationEvent notifyEvent) {
    String address = getMailAddress(notifyEvent);
    // 如果没有获取到地址,则返回不发送通知邮件
    if (StringHelper.isEmpty(address)) {
        if (log.isTraceEnable()) {
            log.warn(this, "Threadanalysis notify mail Send FAIL as email addresses is EMPTY or INVALID!");
        }
        return false;
    }
    ActionContext ac = new ActionContext();
    ac.putParam("event", notifyEvent);
    ac.putParam(NCConstant.ACTIONVALUE, address);
    ac.putParam("mailTemplatePath", "config/JTAmail.template");
    ac.putParam("mailTitle", "【UAV预警】线程分析执行通知");
    ac = engine.execute(NCConstant.ACTION4MAIL, ac);
    return ac.isSucessful();
}
Also used : ActionContext(com.creditease.agent.spi.ActionContext)

Example 5 with ActionContext

use of com.creditease.agent.spi.ActionContext in project uavstack by uavorg.

the class UpgradeOperationRecordConsumer method handleOperationRecord.

public void handleOperationRecord(String upgradeInfo) {
    EndAction endAction = new EndAction(this.feature, null, null);
    try {
        parseOldUpgradeRecord(feature, upgradeInfo);
    } catch (Exception e) {
        if (log.isTraceEnable()) {
            log.err(this, "Failed to parse upgrade record", e);
        }
        endAction.stopUpgradeProcess();
    }
    int length = this.recordList.size();
    if (length <= 1) {
        endAction.stopUpgradeProcess();
    }
    endAction = new EndAction(this.feature, this.upgradeContext, this.engine);
    if (!upgradeContext.getFileLock()) {
        if (log.isTraceEnable()) {
            log.warn(this, "Failed to get upgrade file lock");
        }
        endAction.stopUpgradeProcess();
    }
    UpgradeOperationRecord record = this.recordList.get(length - 1);
    if (upgradeContext.needRollback(record.getPhase())) {
        if (upgradeContext.isUAVContext()) {
            handleUAVOperationRecord(record, endAction);
        } else {
            handleThirdPartySoftwareOperationRecord(record);
        }
        return;
    }
    endAction.doAction(new ActionContext());
}
Also used : EndAction(com.creditease.uav.feature.upgrade.action.EndAction) ActionContext(com.creditease.agent.spi.ActionContext)

Aggregations

ActionContext (com.creditease.agent.spi.ActionContext)13 IActionEngine (com.creditease.agent.spi.IActionEngine)3 JSONObject (com.alibaba.fastjson.JSONObject)2 OverrideFileAction (com.creditease.uav.feature.upgrade.action.OverrideFileAction)2 ThirdpartySoftwareOverrideFileAction (com.creditease.uav.feature.upgrade.action.thirdparty.ThirdpartySoftwareOverrideFileAction)2 UAVOverrideFileAction (com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Line (com.creditease.agent.apm.api.CollectDataFrame.Line)1 UAVHttpMessage (com.creditease.agent.http.api.UAVHttpMessage)1 MonitorDataFrame (com.creditease.agent.monitor.api.MonitorDataFrame)1 StandardProfileModeler (com.creditease.agent.profile.api.StandardProfileModeler)1 ISystemActionEngineMgr (com.creditease.agent.spi.ISystemActionEngineMgr)1 EndAction (com.creditease.uav.feature.upgrade.action.EndAction)1 StartUAVProcessAction (com.creditease.uav.feature.upgrade.action.uav.StartUAVProcessAction)1 TargetProcess (com.creditease.uav.feature.upgrade.beans.TargetProcess)1 SlowOperSpan (com.creditease.uav.invokechain.data.SlowOperSpan)1 Map (java.util.Map)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1