Search in sources :

Example 6 with ActionContext

use of com.creditease.agent.spi.ActionContext 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;
    }
}
Also used : List(java.util.List) UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) ActionContext(com.creditease.agent.spi.ActionContext)

Example 7 with ActionContext

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

the class UpgradeAgent method run.

@Override
public void run() {
    if (log.isTraceEnable()) {
        log.info(this, "Sleep 5 seconds for waiting other features, and then start upgrade process");
    }
    ThreadHelper.suspend(5000);
    this.upgradeContext.initProcessRecordFile();
    ActionContext context = new ActionContext();
    this.engine.execute(UpgradeConstants.getActionName(false, UpgradeConstants.BACKUP_ACTION_KEY), context);
}
Also used : ActionContext(com.creditease.agent.spi.ActionContext)

Example 8 with ActionContext

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

the class NodeOperCtrlHandler method handle.

@Override
public void handle(UAVHttpMessage data) {
    long curTS = System.currentTimeMillis();
    String intent = data.getIntent();
    if (isCheckSec == true) {
        Long ts = actionLimits.get(intent);
        if (ts != null && curTS - ts < 1000 && (!"loadnodepro".equalsIgnoreCase(intent) && !"chgsyspro".equalsIgnoreCase(intent))) {
            data.putResponse("rs", "该节点上的操作[" + intent + "]1秒内只能进行一次");
            return;
        }
        actionLimits.put(intent, curTS);
    }
    if (log.isDebugEnable()) {
        log.debug(this, "NodeOperation[" + intent + "] START: request=" + JSONHelper.toString(data.getRequest()));
    }
    IActionEngine engine = this.getActionEngineMgr().getActionEngine("NodeOperActionEngine");
    ActionContext ac = new ActionContext();
    ac.putParam("msg", data);
    engine.execute(data.getIntent(), ac);
    if (log.isDebugEnable()) {
        log.debug(this, "NodeOperation[" + intent + "] END: response=" + JSONHelper.toString(data.getResponseAsJsonString()));
    }
}
Also used : ActionContext(com.creditease.agent.spi.ActionContext) IActionEngine(com.creditease.agent.spi.IActionEngine)

Example 9 with ActionContext

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

the class StrategyJudgement method convertInstance.

/**
 * @param orignal instance
 *
 * @return adaptive instance
 *
 * convert instance to expr's adaptive instance
 */
private String convertInstance(String instance, String instType, Expression expr) {
    ActionContext ac = new ActionContext();
    ac.putParam("instance", instance);
    ac.putParam("instType", instType);
    this.getActionEngineMgr().getActionEngine("RuntimeNotifyActionEngine").execute(expr.getExprAdaptorId(), ac);
    return (String) ac.getParam("instance");
}
Also used : ActionContext(com.creditease.agent.spi.ActionContext)

Example 10 with ActionContext

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

the class NCJudgementHandler method handle.

/**
 * 预警通知决策流程
 */
@SuppressWarnings({ "unchecked" })
@Override
public void handle(NotificationEvent event) {
    /**
     * Step 1 generate eventKey
     */
    String eventKey = getKeyfromNTFE(event);
    if (log.isTraceEnable()) {
        log.info(this, "NCJudgementHandler START: key=" + eventKey + ",event=" + event.toJSONString());
    }
    /**
     * Step 1.1 check if there is SYNC atomic key on enevtKey
     */
    boolean isSYNCAtomicKey = eventStatusManager.checkSyncAtomicKey(eventKey);
    if (isSYNCAtomicKey) {
        if (log.isTraceEnable()) {
            log.info(this, "NCJudgementHandler event is locked:" + event.toJSONString());
        }
        return;
    }
    /**
     * Step 2 Check if there is a cache for current event
     */
    String stateDataStr = eventStatusManager.getEventCache(eventKey);
    if (!StringHelper.isEmpty(event.getArg("convergences"))) {
        ActionContext ac = new ActionContext();
        ac.putParam("eventKey", eventKey);
        ac.putParam("event", event);
        ac.putParam("stateDataStr", stateDataStr);
        engine.execute(NotificationConvergenceAction.class.getSimpleName(), ac);
        if (log.isTraceEnable()) {
            log.info(this, "NCJudgementHandler END: key=" + eventKey);
        }
        return;
    }
    /**
     * Step 2.1 if none, take this event as the first event record
     */
    if (null == stateDataStr) {
        if (log.isDebugEnable()) {
            log.debug(this, "NC Event happens FIRST TIME: NTFKEY=" + eventKey + ",time=" + event.getTime());
        }
        playAsFirstEventRecord(event, eventKey);
        if (log.isTraceEnable()) {
            log.info(this, "NCJudgementHandler END: key=" + eventKey);
        }
        return;
    }
    /**
     * Step 2.2 if there is a cache for current event, we need get the cache state data
     */
    Map<String, Object> stateData = JSONHelper.toObject(stateDataStr, Map.class);
    if (log.isDebugEnable()) {
        log.debug(this, "NC Event happens OVERTIMEs: NTFKEY=" + eventKey + ",time=" + event.getTime());
    }
    /**
     * Step 3 if there is processTime and processTime exceeds processTTL, that means human has seen this event, and
     * processTTL is the timespan we give to them to fix the issue, if reach processTTL, that may mean the issue is
     * not fixed or may be a new issue, anyway, we will take current event as NEWCOME. then a new first event record
     * is generated, it is the split line to the previous first event record
     */
    long curTime = System.currentTimeMillis();
    long processTime = DataConvertHelper.toLong(stateData.get(NCConstant.COLUMN_PROCESSTIME), -1);
    if (processTime > -1) {
        if (log.isDebugEnable()) {
            log.debug(this, "NC Event Check Result, Over process TTL: processTTL=" + processTTL + ",curTime - processTime=" + (curTime - processTime));
        }
        /**
         * if over processTTL, take this as a new event record
         */
        if (curTime - processTime > processTTL) {
            playAsFirstEventRecord(event, eventKey);
        } else /**
         * if less than processTTL, take this as a re-entry event record then we will not send the notification
         */
        {
            playAsReEntryRecord(event, eventKey, stateData, false);
        }
        if (log.isTraceEnable()) {
            log.info(this, "NCJudgementHandler END: key=" + eventKey);
        }
        return;
    }
    /**
     * Step 4 check if reach notification frozenTime, if not, just update the COLUMN_LATESTRECORDTIME
     */
    long timeSpan = curTime - DataConvertHelper.toLong(stateData.get(NCConstant.COLUMN_LATESTIME), 0);
    if (timeSpan < frozenTime) {
        if (log.isDebugEnable()) {
            log.debug(this, "NC Event Check Result, NO Rearch Frozen Time: timespan=" + timeSpan + ",frozentime=" + frozenTime);
        }
        playAsReEntryRecord(event, eventKey, stateData, false);
        if (log.isTraceEnable()) {
            log.info(this, "NCJudgementHandler END: key=" + eventKey);
        }
        return;
    }
    /**
     * Step 5 if reach frozeTime, then check if reach MAX retry times
     */
    int curRetry = (int) stateData.get(NCConstant.COLUMN_RETRY_COUNT);
    /**
     * Step 5.1 if less than retryTime, we need send notification and update the retry & latest_time
     */
    if (curRetry < retryTime) {
        if (log.isDebugEnable()) {
            log.debug(this, "NC Event Check Result, RE-Action Notify: retry done=" + (++curRetry));
        }
        playAsReEntryRecord(event, eventKey, stateData, true);
        // doing notification actions
        addNotficationTask(event, stateData);
    } else /**
     * Step 5.2 if more than retryTime, just update status, not send notification
     */
    {
        /**
         * Step 5.3 check priority from cache
         */
        log.debug(this, "Reach MAX Retry with NO RE-Action Notify: retry:" + curRetry);
        int priority = (int) stateData.get(NCConstant.COLUMN_PRIORITY);
        if (priority < getMaxPrioritySizeByEvent(event) - 1) {
            log.debug(this, "current priority is: " + priority);
            /**
             * Add priorityFlag to make playAsReEntryRecord could distinct this step,
             *
             * if priorityFlag is true, it need ++ priority
             */
            stateData.put(NCConstant.PRIORITYFLAG, true);
            playAsReEntryRecord(event, eventKey, stateData, false);
            // doing notification actions
            addNotficationTask(event, stateData);
        } else {
            log.debug(this, "Reach MAX Priority size , priority: " + priority);
            playAsReEntryRecord(event, eventKey, stateData, false);
        }
    }
    if (log.isTraceEnable()) {
        log.info(this, "NCJudgementHandler END: key=" + eventKey);
    }
}
Also used : 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