Search in sources :

Example 1 with SystemEnvAttr

use of com.orion.ops.consts.system.SystemEnvAttr in project orion-ops by lijiahangmax.

the class SystemEnvServiceImpl method updateEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateEnv(SystemEnvDO before, SystemEnvRequest request) {
    // 检查是否修改了值
    Long id = before.getId();
    String key = before.getAttrKey();
    String beforeValue = before.getAttrValue();
    String afterValue = request.getValue();
    if (Const.IS_DELETED.equals(before.getDeleted())) {
        // 设置新增历史值
        historyValueService.addHistory(id, HistoryValueType.SYSTEM_ENV, HistoryOperator.ADD, null, afterValue);
        // 恢复
        systemEnvDAO.setDeleted(id, Const.NOT_DELETED);
    } else if (afterValue != null && !afterValue.equals(beforeValue)) {
        // 检查是否修改了值 增加历史值
        historyValueService.addHistory(id, HistoryValueType.SYSTEM_ENV, HistoryOperator.UPDATE, beforeValue, afterValue);
    }
    // 同步更新对象
    SystemEnvAttr env = SystemEnvAttr.of(key);
    if (env != null) {
        env.setValue(afterValue);
        if (afterValue != null && !afterValue.equals(beforeValue)) {
            if (SystemEnvAttr.VCS_PATH.equals(env)) {
                // 如果修改的是 vcs 则修改 vcs 状态
                applicationVcsService.syncVcsStatus();
            }
        }
    }
    // 修改
    SystemEnvDO update = new SystemEnvDO();
    update.setId(id);
    update.setAttrKey(key);
    update.setAttrValue(afterValue);
    update.setDescription(request.getDescription());
    update.setUpdateTime(new Date());
    // 设置日志参数
    EventParamsHolder.addParams(update);
    return systemEnvDAO.updateById(update);
}
Also used : SystemEnvDO(com.orion.ops.entity.domain.SystemEnvDO) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SystemEnvAttr

use of com.orion.ops.consts.system.SystemEnvAttr in project orion-ops by lijiahangmax.

the class SystemEnvInitialize method initEnv.

/**
 * 初始化环境
 */
private void initEnv() {
    // 查询所有的key
    List<String> keys = SystemEnvAttr.getKeys();
    LambdaQueryWrapper<SystemEnvDO> wrapper = new LambdaQueryWrapper<SystemEnvDO>().in(SystemEnvDO::getAttrKey, keys);
    List<SystemEnvDO> envList = systemEnvDAO.selectList(wrapper);
    // 初始化数据
    for (String key : keys) {
        SystemEnvAttr attr = SystemEnvAttr.of(key);
        SystemEnvDO env = envList.stream().filter(s -> s.getAttrKey().equals(key)).findFirst().orElse(null);
        if (env == null) {
            // 插入数据
            String value = this.getAttrValue(attr);
            SystemEnvDO insert = new SystemEnvDO();
            insert.setAttrKey(key);
            insert.setAttrValue(value);
            insert.setDescription(attr.getDescription());
            insert.setSystemEnv(attr.isSystemEnv() ? Const.IS_SYSTEM : Const.NOT_SYSTEM);
            systemEnvDAO.insert(insert);
            log.info("初始化系统变量 {} - {}", key, value);
            // 插入历史值
            Long id = insert.getId();
            historyValueService.addHistory(id, HistoryValueType.SYSTEM_ENV, HistoryOperator.ADD, null, insert.getAttrValue());
            // 设置本地值
            attr.setValue(value);
        } else {
            // 设置本地值
            attr.setValue(env.getAttrValue());
        }
    }
}
Also used : SystemEnvDO(com.orion.ops.entity.domain.SystemEnvDO) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr)

Aggregations

SystemEnvAttr (com.orion.ops.consts.system.SystemEnvAttr)2 SystemEnvDO (com.orion.ops.entity.domain.SystemEnvDO)2 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1