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