Search in sources :

Example 1 with ApplicationEnvRequest

use of com.orion.ops.entity.request.ApplicationEnvRequest in project orion-ops by lijiahangmax.

the class ApplicationEnvServiceImpl method configAppEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public void configAppEnv(ApplicationConfigRequest request) {
    ApplicationEnvService self = SpringHolder.getBean(ApplicationEnvService.class);
    StageType stageType = StageType.of(request.getStageType());
    List<ApplicationEnvRequest> list = Lists.newList();
    Long appId = request.getAppId();
    Long profileId = request.getProfileId();
    ApplicationConfigEnvRequest requestEnv = request.getEnv();
    // 构建产物目录
    String bundlePath = requestEnv.getBundlePath();
    if (!Strings.isBlank(bundlePath)) {
        ApplicationEnvRequest bundlePathEnv = new ApplicationEnvRequest();
        bundlePathEnv.setKey(ApplicationEnvAttr.BUNDLE_PATH.getKey());
        bundlePathEnv.setValue(bundlePath);
        bundlePathEnv.setDescription(ApplicationEnvAttr.BUNDLE_PATH.getDescription());
        list.add(bundlePathEnv);
    }
    // 产物传输目录
    String transferPath = requestEnv.getTransferPath();
    if (!Strings.isBlank(transferPath)) {
        ApplicationEnvRequest transferPathEnv = new ApplicationEnvRequest();
        transferPathEnv.setKey(ApplicationEnvAttr.TRANSFER_PATH.getKey());
        transferPathEnv.setValue(transferPath);
        transferPathEnv.setDescription(ApplicationEnvAttr.TRANSFER_PATH.getDescription());
        list.add(transferPathEnv);
    }
    // 产物传输类型
    String transferDirType = requestEnv.getTransferDirType();
    if (!Strings.isBlank(transferDirType)) {
        ApplicationEnvRequest transferDirTypeEnv = new ApplicationEnvRequest();
        transferDirTypeEnv.setKey(ApplicationEnvAttr.TRANSFER_DIR_TYPE.getKey());
        transferDirTypeEnv.setValue(TransferDirType.of(transferDirType).getValue());
        transferDirTypeEnv.setDescription(ApplicationEnvAttr.TRANSFER_DIR_TYPE.getDescription());
        list.add(transferDirTypeEnv);
    }
    // 发布序列
    Integer releaseSerial = requestEnv.getReleaseSerial();
    if (releaseSerial != null) {
        ApplicationEnvRequest releaseSerialEnv = new ApplicationEnvRequest();
        releaseSerialEnv.setKey(ApplicationEnvAttr.RELEASE_SERIAL.getKey());
        releaseSerialEnv.setValue(SerialType.of(releaseSerial).getValue());
        releaseSerialEnv.setDescription(ApplicationEnvAttr.RELEASE_SERIAL.getDescription());
        list.add(releaseSerialEnv);
    }
    // 异常处理
    Integer exceptionHandler = requestEnv.getExceptionHandler();
    if (exceptionHandler != null) {
        ApplicationEnvRequest exceptionHandlerEnv = new ApplicationEnvRequest();
        exceptionHandlerEnv.setKey(ApplicationEnvAttr.EXCEPTION_HANDLER.getKey());
        exceptionHandlerEnv.setValue(ExceptionHandlerType.of(exceptionHandler).getValue());
        exceptionHandlerEnv.setDescription(ApplicationEnvAttr.EXCEPTION_HANDLER.getDescription());
        list.add(exceptionHandlerEnv);
    }
    // 构建检查是否有构建序列
    if (StageType.BUILD.equals(stageType)) {
        self.checkInitSystemEnv(appId, profileId);
    }
    // 添加环境变量
    for (ApplicationEnvRequest env : list) {
        env.setAppId(appId);
        env.setProfileId(profileId);
        self.addAppEnv(env);
    }
}
Also used : ApplicationConfigEnvRequest(com.orion.ops.entity.request.ApplicationConfigEnvRequest) ApplicationEnvRequest(com.orion.ops.entity.request.ApplicationEnvRequest) StageType(com.orion.ops.consts.app.StageType) ApplicationEnvService(com.orion.ops.service.api.ApplicationEnvService) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ApplicationEnvRequest

use of com.orion.ops.entity.request.ApplicationEnvRequest in project orion-ops by lijiahangmax.

the class ApplicationEnvServiceImpl method syncAppEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public void syncAppEnv(Long id, Long appId, Long profileId, List<Long> targetProfileIdList) {
    ApplicationEnvService self = SpringHolder.getBean(ApplicationEnvService.class);
    List<ApplicationEnvDO> envList;
    // 查询数据
    if (Const.N_N_L_1.equals(id)) {
        // 全量同步
        LambdaQueryWrapper<ApplicationEnvDO> wrapper = new LambdaQueryWrapper<ApplicationEnvDO>().eq(ApplicationEnvDO::getAppId, appId).eq(ApplicationEnvDO::getProfileId, profileId).eq(ApplicationEnvDO::getSystemEnv, Const.NOT_SYSTEM).orderByAsc(ApplicationEnvDO::getUpdateTime);
        envList = applicationEnvDAO.selectList(wrapper);
    } else {
        // 查询数据
        ApplicationEnvDO env = applicationEnvDAO.selectById(id);
        Valid.notNull(env, MessageConst.UNKNOWN_DATA);
        envList = Lists.singleton(env);
    }
    // 同步数据
    for (Long targetProfileId : targetProfileIdList) {
        // 同步环境变量
        for (ApplicationEnvDO syncEnv : envList) {
            ApplicationEnvRequest request = new ApplicationEnvRequest();
            request.setAppId(syncEnv.getAppId());
            request.setProfileId(targetProfileId);
            request.setKey(syncEnv.getAttrKey());
            request.setValue(syncEnv.getAttrValue());
            request.setDescription(syncEnv.getDescription());
            self.addAppEnv(request);
        }
        // 初始化系统变量
        self.checkInitSystemEnv(appId, targetProfileId);
    }
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.ID, id);
    EventParamsHolder.addParam(EventKeys.APP_ID, appId);
    EventParamsHolder.addParam(EventKeys.PROFILE_ID, profileId);
    EventParamsHolder.addParam(EventKeys.ID_LIST, targetProfileIdList);
    EventParamsHolder.addParam(EventKeys.ENV_COUNT, envList.size());
    EventParamsHolder.addParam(EventKeys.PROFILE_COUNT, targetProfileIdList.size());
}
Also used : ApplicationEnvRequest(com.orion.ops.entity.request.ApplicationEnvRequest) ApplicationEnvDO(com.orion.ops.entity.domain.ApplicationEnvDO) ApplicationEnvService(com.orion.ops.service.api.ApplicationEnvService) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ApplicationEnvRequest

use of com.orion.ops.entity.request.ApplicationEnvRequest in project orion-ops by lijiahangmax.

the class ApplicationEnvServiceImpl method getBuildSeqAndIncrement.

@Override
public Integer getBuildSeqAndIncrement(Long appId, Long profileId) {
    // 构建序号
    int seq;
    String buildSeqValue = this.getAppEnvValue(appId, profileId, ApplicationEnvAttr.BUILD_SEQ.getKey());
    if (!Strings.isBlank(buildSeqValue)) {
        if (Strings.isInteger(buildSeqValue)) {
            seq = Integer.parseInt(buildSeqValue);
        } else {
            seq = Const.N_0;
        }
    } else {
        seq = Const.N_0;
    }
    seq++;
    // 修改构建序列
    ApplicationEnvRequest update = new ApplicationEnvRequest();
    update.setAppId(appId);
    update.setProfileId(profileId);
    update.setKey(ApplicationEnvAttr.BUILD_SEQ.getKey());
    update.setValue(seq + Const.EMPTY);
    update.setDescription(ApplicationEnvAttr.BUILD_SEQ.getDescription());
    this.addAppEnv(update);
    return seq;
}
Also used : ApplicationEnvRequest(com.orion.ops.entity.request.ApplicationEnvRequest)

Example 4 with ApplicationEnvRequest

use of com.orion.ops.entity.request.ApplicationEnvRequest in project orion-ops by lijiahangmax.

the class ApplicationEnvServiceImpl method saveEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public void saveEnv(Long appId, Long profileId, Map<String, String> env) {
    ApplicationEnvService self = SpringHolder.getBean(ApplicationEnvService.class);
    // 倒排
    List<Map.Entry<String, String>> entries = Lists.newList(env.entrySet());
    for (int i = entries.size() - 1; i >= 0; i--) {
        // 更新
        Map.Entry<String, String> entry = entries.get(i);
        ApplicationEnvRequest request = new ApplicationEnvRequest();
        request.setAppId(appId);
        request.setProfileId(profileId);
        request.setKey(entry.getKey());
        request.setValue(entry.getValue());
        self.addAppEnv(request);
    }
}
Also used : ApplicationEnvRequest(com.orion.ops.entity.request.ApplicationEnvRequest) ApplicationEnvService(com.orion.ops.service.api.ApplicationEnvService) Map(java.util.Map) MutableLinkedHashMap(com.orion.lang.collect.MutableLinkedHashMap) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ApplicationEnvRequest

use of com.orion.ops.entity.request.ApplicationEnvRequest in project orion-ops by lijiahangmax.

the class HistoryValueServiceImpl method rollback.

@Override
public void rollback(Long id) {
    HistoryValueSnapshotDO historyValue = historyValueSnapshotDAO.selectById(id);
    Valid.notNull(historyValue, MessageConst.HISTORY_VALUE_ABSENT);
    // 设置修改值
    HistoryOperator operator = HistoryOperator.of(historyValue.getOperatorType());
    String updateValue;
    switch(operator) {
        case ADD:
            updateValue = historyValue.getAfterValue();
            break;
        case UPDATE:
        case DELETE:
        default:
            updateValue = historyValue.getBeforeValue();
    }
    // 修改值
    Long valueId = historyValue.getValueId();
    HistoryValueType valueType = HistoryValueType.of(historyValue.getValueType());
    switch(valueType) {
        case MACHINE_ENV:
            MachineEnvRequest machineEnvRequest = new MachineEnvRequest();
            machineEnvRequest.setId(valueId);
            machineEnvRequest.setValue(updateValue);
            machineEnvService.updateEnv(machineEnvRequest);
            return;
        case APP_ENV:
            ApplicationEnvRequest appEnvRequest = new ApplicationEnvRequest();
            appEnvRequest.setId(valueId);
            appEnvRequest.setValue(updateValue);
            applicationEnvService.updateAppEnv(appEnvRequest);
            return;
        case SYSTEM_ENV:
            SystemEnvRequest systemRequest = new SystemEnvRequest();
            systemRequest.setId(valueId);
            systemRequest.setValue(updateValue);
            systemEnvService.updateEnv(systemRequest);
            return;
        default:
    }
}
Also used : ApplicationEnvRequest(com.orion.ops.entity.request.ApplicationEnvRequest) MachineEnvRequest(com.orion.ops.entity.request.MachineEnvRequest) HistoryValueSnapshotDO(com.orion.ops.entity.domain.HistoryValueSnapshotDO) HistoryOperator(com.orion.ops.consts.history.HistoryOperator) SystemEnvRequest(com.orion.ops.entity.request.SystemEnvRequest) HistoryValueType(com.orion.ops.consts.history.HistoryValueType)

Aggregations

ApplicationEnvRequest (com.orion.ops.entity.request.ApplicationEnvRequest)5 ApplicationEnvService (com.orion.ops.service.api.ApplicationEnvService)3 Transactional (org.springframework.transaction.annotation.Transactional)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 MutableLinkedHashMap (com.orion.lang.collect.MutableLinkedHashMap)1 StageType (com.orion.ops.consts.app.StageType)1 HistoryOperator (com.orion.ops.consts.history.HistoryOperator)1 HistoryValueType (com.orion.ops.consts.history.HistoryValueType)1 ApplicationEnvDO (com.orion.ops.entity.domain.ApplicationEnvDO)1 HistoryValueSnapshotDO (com.orion.ops.entity.domain.HistoryValueSnapshotDO)1 ApplicationConfigEnvRequest (com.orion.ops.entity.request.ApplicationConfigEnvRequest)1 MachineEnvRequest (com.orion.ops.entity.request.MachineEnvRequest)1 SystemEnvRequest (com.orion.ops.entity.request.SystemEnvRequest)1 Map (java.util.Map)1