Search in sources :

Example 1 with SystemEnvRequest

use of com.orion.ops.entity.request.SystemEnvRequest 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 2 with SystemEnvRequest

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

the class SystemEnvServiceImpl method saveEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public void saveEnv(Map<String, String> env) {
    SystemEnvService self = SpringHolder.getBean(SystemEnvService.class);
    // 倒排
    List<Map.Entry<String, String>> entries = Lists.newList(env.entrySet());
    int size = entries.size();
    for (int i = size - 1; i >= 0; i--) {
        // 更新
        Map.Entry<String, String> entry = entries.get(i);
        SystemEnvRequest request = new SystemEnvRequest();
        request.setKey(entry.getKey());
        request.setValue(entry.getValue());
        self.addEnv(request);
    }
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.COUNT, size);
}
Also used : SystemEnvService(com.orion.ops.service.api.SystemEnvService) Map(java.util.Map) MutableLinkedHashMap(com.orion.lang.collect.MutableLinkedHashMap) SystemEnvRequest(com.orion.ops.entity.request.SystemEnvRequest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SystemEnvRequest

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

the class SystemServiceImpl method updateSystemOption.

@Override
public void updateSystemOption(SystemEnvAttr env, String value) {
    String key = env.getKey();
    String beforeValue = env.getValue();
    // 更新系统配置
    SystemEnvDO systemEnv = systemEnvService.selectByName(key);
    SystemEnvRequest updateEnv = new SystemEnvRequest();
    updateEnv.setValue(value);
    systemEnvService.updateEnv(systemEnv, updateEnv);
    env.setValue(value);
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.KEY, env.getDescription());
    EventParamsHolder.addParam(EventKeys.LABEL, env.getDescription());
    EventParamsHolder.addParam(EventKeys.BEFORE, beforeValue);
    EventParamsHolder.addParam(EventKeys.AFTER, value);
}
Also used : SystemEnvDO(com.orion.ops.entity.domain.SystemEnvDO) SystemEnvRequest(com.orion.ops.entity.request.SystemEnvRequest)

Example 4 with SystemEnvRequest

use of com.orion.ops.entity.request.SystemEnvRequest 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

SystemEnvRequest (com.orion.ops.entity.request.SystemEnvRequest)4 SystemEnvDO (com.orion.ops.entity.domain.SystemEnvDO)2 Transactional (org.springframework.transaction.annotation.Transactional)2 MutableLinkedHashMap (com.orion.lang.collect.MutableLinkedHashMap)1 EnableType (com.orion.ops.consts.EnableType)1 HistoryOperator (com.orion.ops.consts.history.HistoryOperator)1 HistoryValueType (com.orion.ops.consts.history.HistoryValueType)1 HistoryValueSnapshotDO (com.orion.ops.entity.domain.HistoryValueSnapshotDO)1 ApplicationEnvRequest (com.orion.ops.entity.request.ApplicationEnvRequest)1 MachineEnvRequest (com.orion.ops.entity.request.MachineEnvRequest)1 SystemEnvService (com.orion.ops.service.api.SystemEnvService)1 Map (java.util.Map)1