Search in sources :

Example 16 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException in project main by JohnPeng739.

the class TopologyManageResource method saveTopology.

/**
 * 保存输入的拓扑配置信息
 *
 * @param userCode              操作用户代码
 * @param topologyId            拓扑关键字ID,如果是新增,则为null
 * @param topologyConfigJsonStr 计算拓扑配置信息
 * @return 保存成功返回提交的拓扑对象,否则返回错误信息。
 */
@Path("topology/save")
@POST
public DataVO<TopologyVO> saveTopology(@QueryParam("userCode") String userCode, @QueryParam("topologyId") String topologyId, String topologyConfigJsonStr) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        Topology topology = topologyManageService.save(topologyId, topologyConfigJsonStr);
        TopologyVO topologyVO = new TopologyVO();
        TopologyVO.transform(topology, topologyVO);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(topologyVO);
    } catch (UserInterfaceErrorException ex) {
        return new DataVO<>(ex);
    }
}
Also used : PaginationDataVO(org.mx.rest.vo.PaginationDataVO) DataVO(org.mx.rest.vo.DataVO) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) Topology(com.ds.retl.dal.entity.Topology) TopologyVO(com.ds.retl.rest.vo.topology.TopologyVO)

Example 17 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException in project main by JohnPeng739.

the class UserManageResource method initUser.

/**
 * 初始化用户
 *
 * @return 初始化的管理员用户
 */
@Path("init")
@GET
public DataVO<UserVO> initUser() {
    try {
        sessionDataStore.setCurrentUserCode("SYSTEM");
        User user = userManageService.initUser();
        UserVO userVO = new UserVO();
        UserVO.transform(user, userVO);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(userVO);
    } catch (UserInterfaceErrorException ex) {
        return new DataVO<>(ex);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserVO(com.ds.retl.rest.vo.user.UserVO) PaginationDataVO(org.mx.rest.vo.PaginationDataVO) DataVO(org.mx.rest.vo.DataVO) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException)

Example 18 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException in project main by JohnPeng739.

the class ServerManageServiceImpl method serviceStatusRest.

/**
 * {@inheritDoc}
 *
 * @see ServerManageService#serviceStatusRest(String)
 */
@Override
public Map<String, ServiceStatus> serviceStatusRest(String machineIp) throws UserInterfaceErrorException {
    if (StringUtils.isBlank(machineIp)) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
    }
    JSONObject data = serviceStatusRestJson(machineIp);
    Map<String, ServiceStatus> status = new HashMap<>();
    if (data.containsKey("zookeeper")) {
        JSONObject zookeeper = data.getJSONObject("zookeeper");
        status.put("zookeeper", new ServiceStatus(zookeeper.getBooleanValue("enabled"), zookeeper.getBooleanValue("active")));
    }
    if (data.containsKey("storm")) {
        JSONObject storm = data.getJSONObject("storm");
        status.put("storm", new ServiceStatus(storm.getBooleanValue("enabled"), storm.getBooleanValue("active")));
    }
    return status;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) HashMap(java.util.HashMap)

Example 19 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException 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)

Example 20 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException in project main by JohnPeng739.

the class ServerManageServiceImpl method serviceStatusRestJson.

private JSONObject serviceStatusRestJson(String machineIp) throws UserInterfaceErrorException {
    if (StringUtils.isBlank(machineIp)) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
    }
    RestClientInvoke invoke = new RestClientInvoke();
    try {
        int restPort = env.getProperty("restful.port", Integer.class, 9999);
        String url = String.format("http://%s:%d/rest/server/status/local", machineIp, restPort);
        JSONObject json = invoke.get(url, JSONObject.class);
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("From %s response: %s.", url, json.toJSONString()));
        }
        return json.getJSONObject("data");
    } catch (RestInvokeException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        throw new UserInterfaceErrorException(UserInterfaceErrors.SERVICE_STATUS_FAIL);
    } finally {
        invoke.close();
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) RestInvokeException(org.mx.rest.client.RestInvokeException) RestClientInvoke(org.mx.rest.client.RestClientInvoke)

Aggregations

UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)35 JSONObject (com.alibaba.fastjson.JSONObject)17 EntityAccessException (org.mx.dal.exception.EntityAccessException)15 PaginationDataVO (org.mx.rest.vo.PaginationDataVO)13 DataVO (org.mx.rest.vo.DataVO)12 Topology (com.ds.retl.dal.entity.Topology)8 User (com.ds.retl.dal.entity.User)7 Transactional (org.springframework.transaction.annotation.Transactional)6 TopologyVO (com.ds.retl.rest.vo.topology.TopologyVO)5 ServerInfoVO (com.ds.retl.rest.vo.server.ServerInfoVO)3 UserVO (com.ds.retl.rest.vo.user.UserVO)3 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 EntityInstantiationException (org.mx.dal.exception.EntityInstantiationException)3 RestInvokeException (org.mx.rest.client.RestInvokeException)3 JSONArray (com.alibaba.fastjson.JSONArray)2 ConfigJson (com.ds.retl.dal.entity.ConfigJson)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintStream (java.io.PrintStream)2