Search in sources :

Example 1 with SystemEnvDO

use of com.orion.ops.entity.domain.SystemEnvDO in project orion-ops by lijiahangmax.

the class SystemEnvServiceImpl method deleteEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public Integer deleteEnv(List<Long> idList) {
    int effect = 0;
    for (Long id : idList) {
        // 获取元数据
        SystemEnvDO env = systemEnvDAO.selectById(id);
        Valid.notNull(env, MessageConst.ENV_ABSENT);
        String key = env.getAttrKey();
        Valid.isTrue(SystemEnvAttr.of(key) == null, "{} " + MessageConst.FORBID_DELETE, key);
        // 删除
        effect += systemEnvDAO.deleteById(id);
        // 插入历史值
        historyValueService.addHistory(id, HistoryValueType.SYSTEM_ENV, HistoryOperator.DELETE, env.getAttrValue(), null);
    }
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.ID_LIST, idList);
    EventParamsHolder.addParam(EventKeys.COUNT, effect);
    return effect;
}
Also used : SystemEnvDO(com.orion.ops.entity.domain.SystemEnvDO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SystemEnvDO

use of com.orion.ops.entity.domain.SystemEnvDO 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 3 with SystemEnvDO

use of com.orion.ops.entity.domain.SystemEnvDO in project orion-ops by lijiahangmax.

the class SystemEnvServiceImpl method getEnvDetail.

@Override
public SystemEnvVO getEnvDetail(Long id) {
    SystemEnvDO env = systemEnvDAO.selectById(id);
    Valid.notNull(env, MessageConst.UNKNOWN_DATA);
    return Converts.to(env, SystemEnvVO.class);
}
Also used : SystemEnvDO(com.orion.ops.entity.domain.SystemEnvDO)

Example 4 with SystemEnvDO

use of com.orion.ops.entity.domain.SystemEnvDO in project orion-ops by lijiahangmax.

the class SystemServiceImpl method configIpList.

@Override
@Transactional(rollbackFor = Exception.class)
public void configIpList(ConfigIpListRequest request) {
    // 检查名单
    String blackIpList = request.getBlackIpList();
    String whiteIpList = request.getWhiteIpList();
    this.validIpConfig(blackIpList);
    this.validIpConfig(whiteIpList);
    // 设置黑名单
    SystemEnvDO blackEnv = systemEnvService.selectByName(SystemEnvAttr.BLACK_IP_LIST.getKey());
    SystemEnvRequest updateBlack = new SystemEnvRequest();
    updateBlack.setValue(blackIpList);
    systemEnvService.updateEnv(blackEnv, updateBlack);
    SystemEnvAttr.BLACK_IP_LIST.setValue(blackIpList);
    // 设置白名单
    SystemEnvDO whiteEnv = systemEnvService.selectByName(SystemEnvAttr.WHITE_IP_LIST.getKey());
    SystemEnvRequest updateWhite = new SystemEnvRequest();
    updateWhite.setValue(whiteIpList);
    systemEnvService.updateEnv(whiteEnv, updateWhite);
    SystemEnvAttr.WHITE_IP_LIST.setValue(whiteIpList);
    // 更改启用状态
    EnableType enableIpFilter = EnableType.of(request.getEnableIpFilter());
    SystemEnvDO filterEnv = systemEnvService.selectByName(SystemEnvAttr.ENABLE_IP_FILTER.getKey());
    SystemEnvRequest updateFilter = new SystemEnvRequest();
    updateFilter.setValue(enableIpFilter.getLabel());
    systemEnvService.updateEnv(filterEnv, updateFilter);
    SystemEnvAttr.ENABLE_IP_FILTER.setValue(enableIpFilter.getLabel());
    // 更改启用列表
    EnableType enableWhiteIp = EnableType.of(request.getEnableWhiteIpList());
    SystemEnvDO enableWhiteIpEnv = systemEnvService.selectByName(SystemEnvAttr.ENABLE_WHITE_IP_LIST.getKey());
    SystemEnvRequest updateEnableWhiteIp = new SystemEnvRequest();
    updateEnableWhiteIp.setValue(enableWhiteIp.getLabel());
    systemEnvService.updateEnv(enableWhiteIpEnv, updateEnableWhiteIp);
    SystemEnvAttr.ENABLE_WHITE_IP_LIST.setValue(enableWhiteIp.getLabel());
    // 设置日志参数
    EventParamsHolder.addParams(request);
    // 设置 ip 过滤器
    Boolean enableIpFilterValue = enableIpFilter.getValue();
    Boolean enableWhiteIpValue = enableWhiteIp.getValue();
    ipFilterInterceptor.set(enableIpFilterValue, enableWhiteIpValue, enableWhiteIpValue ? whiteIpList : blackIpList);
}
Also used : SystemEnvDO(com.orion.ops.entity.domain.SystemEnvDO) EnableType(com.orion.ops.consts.EnableType) SystemEnvRequest(com.orion.ops.entity.request.SystemEnvRequest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SystemEnvDO

use of com.orion.ops.entity.domain.SystemEnvDO in project orion-ops by lijiahangmax.

the class SystemEnvServiceImpl method addEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public Long addEnv(SystemEnvRequest request) {
    // 查询
    String key = request.getKey();
    // 重复检查
    SystemEnvDO env = systemEnvDAO.selectOneRel(key);
    // 修改
    if (env != null) {
        SpringHolder.getBean(SystemEnvService.class).updateEnv(env, request);
        return env.getId();
    }
    // 新增
    SystemEnvDO insert = new SystemEnvDO();
    insert.setAttrKey(key);
    insert.setAttrValue(request.getValue());
    insert.setDescription(request.getDescription());
    systemEnvDAO.insert(insert);
    // 插入历史值
    Long id = insert.getId();
    historyValueService.addHistory(id, HistoryValueType.SYSTEM_ENV, HistoryOperator.ADD, null, request.getValue());
    // 设置日志参数
    EventParamsHolder.addParams(insert);
    return id;
}
Also used : SystemEnvDO(com.orion.ops.entity.domain.SystemEnvDO) SystemEnvService(com.orion.ops.service.api.SystemEnvService) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SystemEnvDO (com.orion.ops.entity.domain.SystemEnvDO)8 Transactional (org.springframework.transaction.annotation.Transactional)4 SystemEnvAttr (com.orion.ops.consts.system.SystemEnvAttr)2 SystemEnvRequest (com.orion.ops.entity.request.SystemEnvRequest)2 SystemEnvService (com.orion.ops.service.api.SystemEnvService)2 EnableType (com.orion.ops.consts.EnableType)1 Date (java.util.Date)1