Search in sources :

Example 1 with UpgradeConfig

use of com.creditease.uav.feature.upgrade.beans.UpgradeConfig in project uavstack by uavorg.

the class UpgradeOperationRecordConsumer method parseOldUpgradeRecord.

private void parseOldUpgradeRecord(String feature, String upgradeInfo) throws Exception {
    String rootDir = null;
    if (!StringHelper.isEmpty(upgradeInfo)) {
        UpgradeConfig config = new UpgradeConfig(upgradeInfo);
        if (config.isUAV()) {
            if (log.isTraceEnable()) {
                log.info(this, "Parsing record: uav upgrade process");
            }
            rootDir = ConfigurationManager.getInstance().getContext(IConfigurationManager.ROOT);
        }
    }
    if (StringHelper.isEmpty(rootDir)) {
        throw new Exception("no root directory");
    }
    Path recordFilePath = Paths.get(rootDir.replace("\"", ""), UpgradeConstants.UPGRADE_RECORD_FILE_NAME);
    if (!Files.exists(recordFilePath)) {
        throw new Exception("no operation record file");
    }
    List<String> recordStrList = Files.readAllLines(recordFilePath, Charset.forName("utf-8"));
    // construct upgradeContext with the first line of record list, that is, the first record stores upgrade
    // parameters.
    this.upgradeContext = new UpgradeContext(new UpgradeConfig(recordStrList.remove(0)), true);
    for (String recordStr : recordStrList) {
        this.recordList.add(new UpgradeOperationRecord(recordStr));
    }
}
Also used : Path(java.nio.file.Path) UpgradeConfig(com.creditease.uav.feature.upgrade.beans.UpgradeConfig) UpgradeContext(com.creditease.uav.feature.upgrade.beans.UpgradeContext)

Example 2 with UpgradeConfig

use of com.creditease.uav.feature.upgrade.beans.UpgradeConfig in project uavstack by uavorg.

the class UpgradeAgent method start.

@SuppressWarnings("unused")
@Override
public void start() {
    // initial ActionEngine
    this.engine = this.getActionEngineMgr().newActionEngine("UpgradeActionEngine", this.feature);
    String restart = System.getProperty("StartByCronTask");
    String upgradeInfo = System.getProperty(UPGRADE_INFO);
    if (log.isTraceEnable()) {
        log.info(this, "Upgrade param info is " + upgradeInfo);
        log.info(this, System.getProperty("java.class.path"));
    }
    if (DataConvertHelper.toInt(restart, Integer.MIN_VALUE) == 1) {
        if (log.isTraceEnable()) {
            log.info(this, "This upgrade process was restarted by cron task ");
        }
        ThreadHelper.suspend(3000);
        UpgradeOperationRecordConsumer consumer = new UpgradeOperationRecordConsumer("UpgradeOperationRecordConsumer", this.feature, this.engine);
        consumer.handleOperationRecord(upgradeInfo);
        return;
    }
    this.upgradeContext = new UpgradeContext(new UpgradeConfig(upgradeInfo));
    this.endAction = new EndAction(this.feature, upgradeContext, engine);
    checkVersion4Upgrade(endAction);
    String host = this.getConfigManager().getFeatureConfiguration(this.feature, "http.server.host");
    int port = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.server.port"), UpgradeConstants.DEFAULT_HTTP_PORT);
    if (StringHelper.isEmpty(host)) {
        if (log.isTraceEnable()) {
            log.warn(this, "Invalid http server host");
        }
        endAction.stopUpgradeProcess();
        return;
    }
    if (!this.upgradeContext.getFileLock()) {
        if (log.isTraceEnable()) {
            log.warn(this, "Can not get the lock of " + UpgradeConstants.UPGRADE_FILE_LOCK_NAME + ", another upgrade process is running");
        }
        endAction.stopUpgradeProcess();
        return;
    }
    BackupAction backupAction = new BackupAction(this.feature, upgradeContext, engine);
    PackageDownloadAction downloadAction = new PackageDownloadAction(this.feature, upgradeContext, engine, host, port);
    registerActionsAccordingUpgradeTarget();
    workThread = new Thread(this, "Upgrade Thread");
    workThread.start();
}
Also used : UpgradeOperationRecordConsumer(com.creditease.uav.feature.upgrade.record.UpgradeOperationRecordConsumer) UpgradeConfig(com.creditease.uav.feature.upgrade.beans.UpgradeConfig) BackupAction(com.creditease.uav.feature.upgrade.action.BackupAction) EndAction(com.creditease.uav.feature.upgrade.action.EndAction) UpgradeContext(com.creditease.uav.feature.upgrade.beans.UpgradeContext) PackageDownloadAction(com.creditease.uav.feature.upgrade.action.PackageDownloadAction)

Aggregations

UpgradeConfig (com.creditease.uav.feature.upgrade.beans.UpgradeConfig)2 UpgradeContext (com.creditease.uav.feature.upgrade.beans.UpgradeContext)2 BackupAction (com.creditease.uav.feature.upgrade.action.BackupAction)1 EndAction (com.creditease.uav.feature.upgrade.action.EndAction)1 PackageDownloadAction (com.creditease.uav.feature.upgrade.action.PackageDownloadAction)1 UpgradeOperationRecordConsumer (com.creditease.uav.feature.upgrade.record.UpgradeOperationRecordConsumer)1 Path (java.nio.file.Path)1