use of com.creditease.uav.feature.upgrade.exception.UpgradeException in project uavstack by uavorg.
the class UAVOverrideFileAction method overrideFiles.
@Override
protected void overrideFiles(Path source) throws Exception {
if (log.isTraceEnable()) {
log.info(this, "start overriding files from " + source + " to " + this.getParentDirOfRoot());
}
if (Files.notExists(source)) {
throw new UpgradeException("The source of override file action does not exit");
}
// 解压前清除原目录文件
String regex = "(" + UpgradeConstants.BACKUP_FOLDER + "|" + UpgradeConstants.UPGRADE_FILE_LOCK_NAME + "|" + UpgradeConstants.UPGRADE_RECORD_FILE_NAME + ")";
File rootDir = new File(this.getRootDir());
String[] files = rootDir.list();
if (files != null && files.length > 0) {
if (log.isTraceEnable()) {
log.info(this, "Delete all the old files in the root folder: " + this.getRootDir());
}
for (int i = 0; i < files.length; i++) {
File file = new File(this.getRootDir() + "/" + files[i]);
if (!file.getName().matches(regex)) {
if (file.isDirectory()) {
IOHelper.deleteFolder(file.getAbsolutePath());
} else {
IOHelper.deleteFile(file.getAbsolutePath());
}
}
}
}
ZIPHelper.decompressZipToDir(source.toString(), this.getParentDirOfRoot());
if (this.upgradeContext.canWriteOperationRecord()) {
addAppVersionToProfile();
modifyFilePermission();
this.writeProcessRecord(this.cName, source.toString());
}
}
use of com.creditease.uav.feature.upgrade.exception.UpgradeException in project uavstack by uavorg.
the class PackageDownloadAction method checkPackageIntegrity.
/**
* Check if md5 of current upgrade zip package is same as the value in the md5 file
*
* @throws IOException
* @throws UpgradeException
*/
private void checkPackageIntegrity() throws IOException, UpgradeException {
Path packagePath = this.getUpgradePackagePath();
if (Files.notExists(packagePath)) {
if (this.log.isTraceEnable()) {
this.log.warn(this, "Package " + this.getSoftwarePackage() + " does not exist");
}
throw new UpgradeException("Upgrade package does not exist");
}
Path md5Path = this.getUpgardePackageMD5FilePath();
if (Files.notExists(md5Path)) {
if (this.log.isTraceEnable()) {
this.log.warn(this, "MD5 file for " + this.getSoftwarePackage() + " does not exist");
}
throw new UpgradeException("MD5 file does not exist");
}
String originalMD5 = new String(Files.readAllBytes(md5Path));
String newMD5 = generateMD5ForFile(packagePath.toFile());
if (this.log.isTraceEnable()) {
this.log.info(this, "original md5 is " + originalMD5 + " new md5 is " + newMD5);
}
if (!originalMD5.trim().equals(newMD5)) {
throw new UpgradeException("MD5 dismatched");
}
if (this.log.isTraceEnable()) {
this.log.info(this, "Upgrade package integrity check was successful");
}
}
use of com.creditease.uav.feature.upgrade.exception.UpgradeException in project uavstack by uavorg.
the class ThirdpartySoftwareOverrideFileAction method overrideFiles.
@Override
protected void overrideFiles(Path source) throws Exception {
if (log.isTraceEnable()) {
log.info(this, "start overriding files from " + source + " to " + this.getParentDirOfRoot());
}
if (Files.notExists(source)) {
throw new UpgradeException("The source of override file action does not exit");
}
// 解压前清除原目录文件
String regex = "(" + UpgradeConstants.BACKUP_FOLDER + "|" + UpgradeConstants.UPGRADE_FILE_LOCK_NAME + "|" + UpgradeConstants.UPGRADE_RECORD_FILE_NAME + ")";
File rootDir = new File(this.getRootDir());
String[] files = rootDir.list();
if (files != null && files.length > 0) {
if (log.isTraceEnable()) {
log.info(this, "Delete all the old files in the root folder: " + this.getRootDir());
}
for (int i = 0; i < files.length; i++) {
File file = new File(this.getRootDir() + "/" + files[i]);
if (!file.getName().matches(regex)) {
if (file.isDirectory()) {
IOHelper.deleteFolder(file.getAbsolutePath());
} else {
IOHelper.deleteFile(file.getAbsolutePath());
}
}
}
}
ZIPHelper.decompressZipToDir(source.toString(), this.getParentDirOfRoot());
if (this.upgradeContext.canWriteOperationRecord()) {
this.writeProcessRecord(this.cName, source.toString());
}
this.addAppVersionToCurrentVersionFile(UpgradeUtil.getVersionFromPackageName(source.getFileName().toString()));
}
use of com.creditease.uav.feature.upgrade.exception.UpgradeException 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