use of com.creditease.uav.feature.upgrade.beans.TargetProcess in project uavstack by uavorg.
the class UAVOverrideFileAction method addAppVersionToProfile.
/**
* Append upgrade target version to profile configuration file
*/
private void addAppVersionToProfile() {
String version = UpgradeUtil.getVersionFromPackageName(this.getSoftwarePackage());
if (!StringHelper.isEmpty(version)) {
for (TargetProcess process : this.upgradeContext.getAffectedProcessList()) {
Path profilePath = Paths.get(this.getConfigManager().getContext(IConfigurationManager.CONFIGPATH), process.getProfileName() + ".properties");
if (log.isTraceEnable()) {
log.info(this, "Start adding new app version " + version + " to " + profilePath);
}
try {
List<String> lines = Files.readAllLines(profilePath, Charset.forName("UTF-8"));
StringBuffer sbf = new StringBuffer();
for (String line : lines) {
if (line.contains("meta.nodeappversion")) {
// ignore the old meta.nodeappversion
continue;
}
sbf.append(line).append(System.getProperty("line.separator"));
if (line.contains("meta.nodetype")) {
// append meta.nodeappversion after the line of meta.nodetype
sbf.append("meta.nodeappversion=" + version).append(System.getProperty("line.separator"));
}
}
Files.write(profilePath, sbf.toString().getBytes(Charset.forName("UTF-8")));
} catch (IOException e) {
if (log.isTraceEnable()) {
log.err(this, "Failed to app version info to profile " + e.getMessage());
}
}
}
} else {
if (log.isTraceEnable()) {
log.warn(this, "Did not get valid version from " + this.getSoftwarePackage());
}
}
}
use of com.creditease.uav.feature.upgrade.beans.TargetProcess 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());
}
}
}
use of com.creditease.uav.feature.upgrade.beans.TargetProcess in project uavstack by uavorg.
the class StopUAVProcessAction method doAction.
@Override
public void doAction(ActionContext context) throws Exception {
setUpgradePhase(UpgradePhase.PROCESS_STOP);
List<TargetProcess> processList = getProcessList();
int size = processList.size();
float processIndex = 1;
for (TargetProcess process : processList) {
if (!UpgradeUtil.isUAVProcessAlive(process)) {
if (log.isTraceEnable()) {
log.info(this, process + " is not alive, no need to stop it");
}
continue;
}
stopProcess(process);
if (this.upgradeContext.canWriteOperationRecord()) {
this.writeProcessRecord(this.cName, process, processIndex / size, UpgradeUtil.getUAVProcessJsonStrList(processList));
}
processIndex++;
}
context.setSucessful(true);
}
use of com.creditease.uav.feature.upgrade.beans.TargetProcess in project uavstack by uavorg.
the class StartUAVProcessAction method doAction.
@Override
public void doAction(ActionContext context) throws Exception {
setUpgradePhase(UpgradePhase.PROCESS_START);
List<TargetProcess> processList = getProcessList();
int size = processList.size();
float processIndex = 1;
for (TargetProcess process : processList) {
if (UpgradeUtil.isUAVProcessAlive(process)) {
if (log.isTraceEnable()) {
log.info(this, process + " is already alive, no need to start");
}
continue;
}
startProcess(process);
// Sleep 3 seconds to finish starting
ThreadHelper.suspend(3000);
if (!UpgradeUtil.isUAVProcessAlive(process)) {
throw new UpgradeException("Failed to start profile: " + process.getProfileName());
}
if (this.upgradeContext.canWriteOperationRecord()) {
this.writeProcessRecord(this.cName, process, processIndex / size, UpgradeUtil.getUAVProcessJsonStrList(processList));
}
if (log.isTraceEnable()) {
log.info(this, "Profile: " + process.getProfileName() + " was restarted successfully");
}
processIndex++;
}
context.setSucessful(true);
}
Aggregations