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);
}
}
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());
}
}
}
Aggregations