Search in sources :

Example 1 with ConfigJson

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);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) ConfigJson(com.ds.retl.dal.entity.ConfigJson) EntityAccessException(org.mx.dal.exception.EntityAccessException)

Example 2 with ConfigJson

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);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) ConfigJson(com.ds.retl.dal.entity.ConfigJson) EntityAccessException(org.mx.dal.exception.EntityAccessException) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) EntityAccessException(org.mx.dal.exception.EntityAccessException) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) IOException(java.io.IOException) RestInvokeException(org.mx.rest.client.RestInvokeException)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)2 ConfigJson (com.ds.retl.dal.entity.ConfigJson)2 UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)2 EntityAccessException (org.mx.dal.exception.EntityAccessException)2 IOException (java.io.IOException)1 EntityInstantiationException (org.mx.dal.exception.EntityInstantiationException)1 RestInvokeException (org.mx.rest.client.RestInvokeException)1