Search in sources :

Example 1 with MachineEnvRequest

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

the class MachineEnvServiceImpl method saveEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public void saveEnv(Long machineId, Map<String, String> env) {
    MachineEnvService self = SpringHolder.getBean(MachineEnvService.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);
        MachineEnvRequest request = new MachineEnvRequest();
        request.setMachineId(machineId);
        request.setKey(entry.getKey());
        request.setValue(entry.getValue());
        self.addEnv(request);
    }
}
Also used : MachineEnvService(com.orion.ops.service.api.MachineEnvService) MachineEnvRequest(com.orion.ops.entity.request.MachineEnvRequest) Map(java.util.Map) MutableLinkedHashMap(com.orion.lang.collect.MutableLinkedHashMap) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MachineEnvRequest

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

the class MachineEnvServiceImpl method syncMachineEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public void syncMachineEnv(MachineEnvRequest request) {
    Long id = request.getId();
    Long machineId = request.getMachineId();
    List<Long> targetMachineIdList = request.getTargetMachineIdList();
    // 获取self
    MachineEnvService self = SpringHolder.getBean(MachineEnvService.class);
    List<MachineEnvDO> envList;
    if (Const.N_N_L_1.equals(id)) {
        // 全量同步
        LambdaQueryWrapper<MachineEnvDO> wrapper = new LambdaQueryWrapper<MachineEnvDO>().eq(MachineEnvDO::getMachineId, machineId).orderByAsc(MachineEnvDO::getUpdateTime);
        envList = machineEnvDAO.selectList(wrapper);
    } else {
        // 查询数据
        MachineEnvDO env = machineEnvDAO.selectById(id);
        Valid.notNull(env, MessageConst.UNKNOWN_DATA);
        envList = Lists.singleton(env);
    }
    // 同步
    for (Long targetMachineId : targetMachineIdList) {
        for (MachineEnvDO syncEnv : envList) {
            MachineEnvRequest addRequest = new MachineEnvRequest();
            addRequest.setMachineId(targetMachineId);
            addRequest.setKey(syncEnv.getAttrKey());
            addRequest.setValue(syncEnv.getAttrValue());
            addRequest.setDescription(syncEnv.getDescription());
            self.addEnv(addRequest);
        }
    }
    // 设置日志参数
    EventParamsHolder.addParams(request);
    EventParamsHolder.addParam(EventKeys.ENV_COUNT, envList.size());
    EventParamsHolder.addParam(EventKeys.MACHINE_COUNT, targetMachineIdList.size());
}
Also used : MachineEnvService(com.orion.ops.service.api.MachineEnvService) MachineEnvRequest(com.orion.ops.entity.request.MachineEnvRequest) MachineEnvDO(com.orion.ops.entity.domain.MachineEnvDO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with MachineEnvRequest

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

Example 4 with MachineEnvRequest

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

the class MachineEnvServiceImpl method mergeEnv.

@Override
public Integer mergeEnv(Long sourceMachineId, Long targetMachineId) {
    LambdaQueryWrapper<MachineEnvDO> sourceWrapper = new LambdaQueryWrapper<MachineEnvDO>().eq(MachineEnvDO::getMachineId, sourceMachineId);
    LambdaQueryWrapper<MachineEnvDO> targetWrapper = new LambdaQueryWrapper<MachineEnvDO>().eq(MachineEnvDO::getMachineId, targetMachineId);
    List<MachineEnvDO> sourceEnvList = machineEnvDAO.selectList(sourceWrapper);
    List<MachineEnvDO> targetEnvList = machineEnvDAO.selectList(targetWrapper);
    Valid.notEmpty(sourceEnvList);
    Valid.notEmpty(targetEnvList);
    int effect = 0;
    for (MachineEnvDO sourceEnv : sourceEnvList) {
        Optional<MachineEnvDO> targetOption = targetEnvList.stream().filter(t -> t.getAttrKey().equals(sourceEnv.getAttrKey())).findFirst();
        if (targetOption.isPresent()) {
            // 更新
            MachineEnvRequest update = new MachineEnvRequest();
            update.setId(targetOption.get().getId());
            update.setValue(sourceEnv.getAttrValue());
            update.setDescription(sourceEnv.getDescription());
            effect += this.updateEnv(update);
        } else {
            // 插入
            MachineEnvDO insertEnv = new MachineEnvDO();
            insertEnv.setMachineId(targetMachineId);
            insertEnv.setAttrKey(sourceEnv.getAttrKey());
            insertEnv.setAttrValue(sourceEnv.getAttrValue());
            insertEnv.setDescription(sourceEnv.getDescription());
            effect += machineEnvDAO.insert(insertEnv);
        }
    }
    return effect;
}
Also used : EventKeys(com.orion.ops.consts.event.EventKeys) MachineEnvRequest(com.orion.ops.entity.request.MachineEnvRequest) Date(java.util.Date) MessageConst(com.orion.ops.consts.MessageConst) EnvConst(com.orion.ops.consts.env.EnvConst) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) MachineEnvAttr(com.orion.ops.consts.machine.MachineEnvAttr) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) MachineInfoDAO(com.orion.ops.dao.MachineInfoDAO) HistoryValueService(com.orion.ops.service.api.HistoryValueService) MachineEnvService(com.orion.ops.service.api.MachineEnvService) Service(org.springframework.stereotype.Service) Map(java.util.Map) SpringHolder(com.orion.spring.SpringHolder) MutableLinkedHashMap(com.orion.lang.collect.MutableLinkedHashMap) Maps(com.orion.utils.collect.Maps) Const(com.orion.ops.consts.Const) DataGrid(com.orion.lang.wrapper.DataGrid) MachineEnvDAO(com.orion.ops.dao.MachineEnvDAO) MachineEnvDO(com.orion.ops.entity.domain.MachineEnvDO) HistoryValueType(com.orion.ops.consts.history.HistoryValueType) Resource(javax.annotation.Resource) MachineEnvVO(com.orion.ops.entity.vo.MachineEnvVO) Valid(com.orion.ops.utils.Valid) MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO) DataQuery(com.orion.ops.utils.DataQuery) Converts(com.orion.utils.convert.Converts) HistoryOperator(com.orion.ops.consts.history.HistoryOperator) List(java.util.List) Charsets(com.orion.utils.Charsets) Lists(com.orion.utils.collect.Lists) Optional(java.util.Optional) CommandConst(com.orion.ops.consts.command.CommandConst) Strings(com.orion.utils.Strings) Transactional(org.springframework.transaction.annotation.Transactional) MachineEnvRequest(com.orion.ops.entity.request.MachineEnvRequest) MachineEnvDO(com.orion.ops.entity.domain.MachineEnvDO)

Aggregations

MachineEnvRequest (com.orion.ops.entity.request.MachineEnvRequest)4 MachineEnvService (com.orion.ops.service.api.MachineEnvService)3 Transactional (org.springframework.transaction.annotation.Transactional)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 MutableLinkedHashMap (com.orion.lang.collect.MutableLinkedHashMap)2 HistoryOperator (com.orion.ops.consts.history.HistoryOperator)2 HistoryValueType (com.orion.ops.consts.history.HistoryValueType)2 MachineEnvDO (com.orion.ops.entity.domain.MachineEnvDO)2 Map (java.util.Map)2 DataGrid (com.orion.lang.wrapper.DataGrid)1 Const (com.orion.ops.consts.Const)1 MessageConst (com.orion.ops.consts.MessageConst)1 CommandConst (com.orion.ops.consts.command.CommandConst)1 EnvConst (com.orion.ops.consts.env.EnvConst)1 EventKeys (com.orion.ops.consts.event.EventKeys)1 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)1 MachineEnvAttr (com.orion.ops.consts.machine.MachineEnvAttr)1 MachineEnvDAO (com.orion.ops.dao.MachineEnvDAO)1 MachineInfoDAO (com.orion.ops.dao.MachineInfoDAO)1 HistoryValueSnapshotDO (com.orion.ops.entity.domain.HistoryValueSnapshotDO)1