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