use of com.ds.retl.dal.entity.ConfigJson in project main by JohnPeng739.
the class ServerManageServiceImpl method deleteServerInfo.
/**
* {@inheritDoc}
*
* @see ServerManageService#deleteServerInfo(String)
*/
@Override
public JSONObject deleteServerInfo(String machineName) throws UserInterfaceErrorException {
try {
ConfigJson config = accessor.getByCode(createMachineConfigField(machineName), ConfigJson.class);
if (config == null) {
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_CONFIG_NOT_FOUND);
} else {
JSONObject json = parseJson(config.getConfigContent());
String machineIp = json.getString("machineIp");
accessor.remove(config);
operateLogService.writeLog(String.format("删除服务器[name=%s, ip=%s]成功。", machineName, machineIp));
return json;
}
} catch (EntityAccessException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
}
}
use of com.ds.retl.dal.entity.ConfigJson in project main by JohnPeng739.
the class ServerManageServiceImpl method saveServerInfo.
/**
* {@inheritDoc}
*
* @see ServerManageService#saveServerInfo(String)
*/
@Override
public JSONObject saveServerInfo(String info) throws UserInterfaceErrorException {
if (StringUtils.isBlank(info)) {
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
}
JSONObject json;
try {
json = JSON.parseObject(info);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error(String.format("Parse json fail, %s.", info), ex);
}
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
}
String machineName = json.getString("machineName"), machineIp = json.getString("machineIp");
if (StringUtils.isBlank(machineName)) {
if (logger.isErrorEnabled()) {
logger.error("The machine's name is blank.");
}
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
}
try {
ConfigJson config = accessor.getByCode(createMachineConfigField(machineName), ConfigJson.class);
if (config == null) {
config = EntityFactory.createEntity(ConfigJson.class);
config.setCode(createMachineConfigField(machineName));
}
config.setConfigContent(info);
accessor.save(config);
config = accessor.getByCode(createMachineConfigField(machineName), ConfigJson.class);
if (config == null) {
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_CONFIG_NOT_FOUND);
}
operateLogService.writeLog(String.format("保存服务器[name=%s, ip=%s]配置信息成功。", machineName, machineIp));
return JSON.parseObject(config.getConfigContent());
} catch (EntityAccessException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
} catch (EntityInstantiationException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_ENTITY_INSTANCE_FAIL);
}
}
Aggregations