Search in sources :

Example 1 with MachineEnvDO

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

the class MachineEnvServiceImpl method updateEnv.

@Override
public Integer updateEnv(MachineEnvRequest request) {
    // 查询
    Long id = request.getId();
    MachineEnvDO before = machineEnvDAO.selectById(id);
    Valid.notNull(before, MessageConst.ENV_ABSENT);
    return SpringHolder.getBean(MachineEnvService.class).updateEnv(before, request);
}
Also used : MachineEnvService(com.orion.ops.service.api.MachineEnvService) MachineEnvDO(com.orion.ops.entity.domain.MachineEnvDO)

Example 2 with MachineEnvDO

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

the class MachineEnvServiceImpl method deleteEnv.

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

Example 3 with MachineEnvDO

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

the class MachineEnvServiceImpl method getEnvDetail.

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

Example 4 with MachineEnvDO

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

the class MachineEnvServiceImpl method updateEnv.

@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateEnv(MachineEnvDO before, MachineEnvRequest request) {
    // 检查是否修改了值
    Long id = before.getId();
    String beforeValue = before.getAttrValue();
    String afterValue = request.getValue();
    if (Const.IS_DELETED.equals(before.getDeleted())) {
        // 设置新增历史值
        historyValueService.addHistory(id, HistoryValueType.MACHINE_ENV, HistoryOperator.ADD, null, afterValue);
        // 恢复
        machineEnvDAO.setDeleted(id, Const.NOT_DELETED);
    } else if (afterValue != null && !afterValue.equals(beforeValue)) {
        // 检查是否修改了值 增加历史值
        historyValueService.addHistory(id, HistoryValueType.MACHINE_ENV, HistoryOperator.UPDATE, beforeValue, afterValue);
    }
    // 修改
    MachineEnvDO update = new MachineEnvDO();
    update.setId(id);
    update.setAttrValue(afterValue);
    update.setDescription(request.getDescription());
    update.setUpdateTime(new Date());
    return machineEnvDAO.updateById(update);
}
Also used : MachineEnvDO(com.orion.ops.entity.domain.MachineEnvDO) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with MachineEnvDO

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

Aggregations

MachineEnvDO (com.orion.ops.entity.domain.MachineEnvDO)10 Transactional (org.springframework.transaction.annotation.Transactional)5 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)4 MachineEnvService (com.orion.ops.service.api.MachineEnvService)4 MachineInfoDO (com.orion.ops.entity.domain.MachineInfoDO)3 MachineEnvAttr (com.orion.ops.consts.machine.MachineEnvAttr)2 MachineEnvRequest (com.orion.ops.entity.request.MachineEnvRequest)2 Date (java.util.Date)2 MutableLinkedHashMap (com.orion.lang.collect.MutableLinkedHashMap)1 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 HistoryOperator (com.orion.ops.consts.history.HistoryOperator)1 HistoryValueType (com.orion.ops.consts.history.HistoryValueType)1 MachineEnvDAO (com.orion.ops.dao.MachineEnvDAO)1 MachineInfoDAO (com.orion.ops.dao.MachineInfoDAO)1