Search in sources :

Example 1 with UAVOverrideFileAction

use of com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction in project uavstack by uavorg.

the class UpgradeAgent method registerActionsAccordingUpgradeTarget.

@SuppressWarnings("unused")
private void registerActionsAccordingUpgradeTarget() {
    if (this.upgradeContext.isUAVContext()) {
        StopUAVProcessAction stopAction = new StopUAVProcessAction(this.feature, this.upgradeContext, engine);
        OverrideFileAction overrideFileAction = new UAVOverrideFileAction(this.feature, this.upgradeContext, engine);
        StartUAVProcessAction startAction = new StartUAVProcessAction(this.feature, this.upgradeContext, engine);
    } else {
        OverrideFileAction overrideFileAction = new ThirdpartySoftwareOverrideFileAction(this.feature, this.upgradeContext, engine);
    }
}
Also used : StopUAVProcessAction(com.creditease.uav.feature.upgrade.action.uav.StopUAVProcessAction) UAVOverrideFileAction(com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction) StartUAVProcessAction(com.creditease.uav.feature.upgrade.action.uav.StartUAVProcessAction) UAVOverrideFileAction(com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction) OverrideFileAction(com.creditease.uav.feature.upgrade.action.OverrideFileAction) ThirdpartySoftwareOverrideFileAction(com.creditease.uav.feature.upgrade.action.thirdparty.ThirdpartySoftwareOverrideFileAction) ThirdpartySoftwareOverrideFileAction(com.creditease.uav.feature.upgrade.action.thirdparty.ThirdpartySoftwareOverrideFileAction)

Example 2 with UAVOverrideFileAction

use of com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction 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)

Aggregations

OverrideFileAction (com.creditease.uav.feature.upgrade.action.OverrideFileAction)2 ThirdpartySoftwareOverrideFileAction (com.creditease.uav.feature.upgrade.action.thirdparty.ThirdpartySoftwareOverrideFileAction)2 StartUAVProcessAction (com.creditease.uav.feature.upgrade.action.uav.StartUAVProcessAction)2 UAVOverrideFileAction (com.creditease.uav.feature.upgrade.action.uav.UAVOverrideFileAction)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ActionContext (com.creditease.agent.spi.ActionContext)1 StopUAVProcessAction (com.creditease.uav.feature.upgrade.action.uav.StopUAVProcessAction)1 TargetProcess (com.creditease.uav.feature.upgrade.beans.TargetProcess)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1