Search in sources :

Example 11 with ActionContext

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

the class UpgradeOperationRecordConsumer method handleUAVOperationRecord.

@SuppressWarnings("unchecked")
private void handleUAVOperationRecord(UpgradeOperationRecord oprRecord, EndAction endAction) {
    Map<String, Object> action = JSONHelper.toObject(String.valueOf(oprRecord.getAction()), Map.class);
    if (UpgradePhase.PROCESS_STOP.toString().equalsIgnoreCase(oprRecord.getPhase())) {
        // will start all the process which have been stopped
        this.upgradeContext.setRollback(true);
        List<TargetProcess> processList = UpgradeUtil.generateUAVProcessListFromJsonStrList((List<String>) action.get("processes"));
        StartUAVProcessAction startAction = new StartUAVProcessAction(this.feature, this.upgradeContext, this.engine);
        startAction.setProcessList(processList);
        engine.execute(startAction.getName(), new ActionContext());
    } else if (UpgradePhase.OVERRIDE_FILE.toString().equalsIgnoreCase(oprRecord.getPhase())) {
        // will roll back
        this.upgradeContext.setRollback(true);
        JSONObject object = (JSONObject) action.get("override");
        String backupZip = String.valueOf(object.get("backup"));
        OverrideFileAction overrideFileAction = new UAVOverrideFileAction(this.feature, this.upgradeContext, this.engine);
        overrideFileAction.setBackupZipPath(Paths.get(backupZip));
        List<UpgradeOperationRecord> recordList = getOperationRecordByPhase(UpgradePhase.PROCESS_STOP);
        Map<String, Object> actionMap = JSONHelper.toObject(String.valueOf(recordList.get(0).getAction()), Map.class);
        List<TargetProcess> processList = UpgradeUtil.generateUAVProcessListFromJsonStrList((List<String>) actionMap.get("processes"));
        StartUAVProcessAction startAction = new StartUAVProcessAction(this.feature, this.upgradeContext, this.engine);
        startAction.setProcessList(processList);
        engine.execute(overrideFileAction.getName(), new ActionContext());
    } else if (UpgradePhase.PROCESS_START.toString().equalsIgnoreCase(oprRecord.getPhase())) {
        if (Float.valueOf(String.valueOf(action.get("ratio"))) == 1.0f) {
            // all the processes have been started successfully, so just finished the end action.
            engine.execute(endAction.getName(), new ActionContext());
        } else {
            // no all the processes were started successfully, so continue to start processes
            List<TargetProcess> totalProcessList = UpgradeUtil.generateUAVProcessListFromJsonStrList((List<String>) action.get("processes"));
            List<TargetProcess> alreadyStartedProcessList = new ArrayList<TargetProcess>();
            List<UpgradeOperationRecord> recordList = getOperationRecordByPhase(UpgradePhase.PROCESS_START);
            for (UpgradeOperationRecord record : recordList) {
                Map<String, Object> actionMap = JSONHelper.toObject(String.valueOf(record.getAction()), Map.class);
                alreadyStartedProcessList.add(JSONHelper.toObject(String.valueOf(actionMap.get("start_process")), TargetProcess.class));
            }
            // find the processes to be started
            List<TargetProcess> toStartProcessList = new ArrayList<TargetProcess>();
            boolean find = false;
            for (TargetProcess process : totalProcessList) {
                String profile = process.getProfileName();
                for (TargetProcess startedProcess : alreadyStartedProcessList) {
                    if (profile.equals(startedProcess.getProfileName())) {
                        find = true;
                        break;
                    }
                }
                if (!find) {
                    toStartProcessList.add(process);
                }
                find = false;
            }
            StartUAVProcessAction startAction = new StartUAVProcessAction(this.feature, this.upgradeContext, this.engine);
            startAction.setProcessList(toStartProcessList);
            engine.execute(startAction.getName(), new ActionContext());
        }
    }
}
Also used : TargetProcess(com.creditease.uav.feature.upgrade.beans.TargetProcess) UAVOverrideFileAction(com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction) ArrayList(java.util.ArrayList) StartUAVProcessAction(com.creditease.uav.feature.upgrade.action.uav.StartUAVProcessAction) ActionContext(com.creditease.agent.spi.ActionContext) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) UAVOverrideFileAction(com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction) ThirdpartySoftwareOverrideFileAction(com.creditease.uav.feature.upgrade.action.thirdparty.ThirdpartySoftwareOverrideFileAction) OverrideFileAction(com.creditease.uav.feature.upgrade.action.OverrideFileAction) Map(java.util.Map)

Example 12 with ActionContext

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

the class UpgradeOperationRecordConsumer method handleThirdPartySoftwareOperationRecord.

@SuppressWarnings("unchecked")
private void handleThirdPartySoftwareOperationRecord(UpgradeOperationRecord oprRecord) {
    Map<String, Object> action = JSONHelper.toObject(String.valueOf(oprRecord.getAction()), Map.class);
    if (action.containsKey("override")) {
        JSONObject object = (JSONObject) action.get("override");
        String backupZip = String.valueOf(object.get("backup"));
        OverrideFileAction overrideFileAction = new ThirdpartySoftwareOverrideFileAction(this.feature, upgradeContext, this.engine);
        overrideFileAction.setBackupZipPath(Paths.get(backupZip));
        engine.execute(overrideFileAction.getName(), new ActionContext());
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) UAVOverrideFileAction(com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction) ThirdpartySoftwareOverrideFileAction(com.creditease.uav.feature.upgrade.action.thirdparty.ThirdpartySoftwareOverrideFileAction) OverrideFileAction(com.creditease.uav.feature.upgrade.action.OverrideFileAction) ActionContext(com.creditease.agent.spi.ActionContext) ThirdpartySoftwareOverrideFileAction(com.creditease.uav.feature.upgrade.action.thirdparty.ThirdpartySoftwareOverrideFileAction)

Example 13 with ActionContext

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

the class UpgradeAgent method stop.

@Override
public void stop() {
    if (log.isTraceEnable()) {
        log.info(this, "Stoping upgrade process");
    }
    this.getActionEngineMgr().shutdown("UpgradeActionEngine");
    if (upgradeContext.getCurrentPhase() != UpgradePhase.END) {
        // handle the case which receive shutdown cmd from outside.
        this.endAction.doAction(new ActionContext());
    }
    super.stop();
}
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