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);
}
}
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());
}
Aggregations