Search in sources :

Example 1 with MachineEnvService

use of com.orion.ops.service.api.MachineEnvService 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 MachineEnvService

use of com.orion.ops.service.api.MachineEnvService 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

MachineEnvRequest (com.orion.ops.entity.request.MachineEnvRequest)2 MachineEnvService (com.orion.ops.service.api.MachineEnvService)2 Transactional (org.springframework.transaction.annotation.Transactional)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 MutableLinkedHashMap (com.orion.lang.collect.MutableLinkedHashMap)1 MachineEnvDO (com.orion.ops.entity.domain.MachineEnvDO)1 Map (java.util.Map)1