Search in sources :

Example 6 with UserInterfaceErrorException

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

the class TopologyManageServiceImpl method delete.

/**
 * {@inheritDoc}
 *
 * @see TopologyManageService#delete(String)
 */
@Override
public void delete(String id) throws UserInterfaceErrorException {
    try {
        Topology topology = accessor.getById(id, Topology.class);
        if (topology == null) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_NOT_FOUND);
        }
        accessor.remove(topology);
        operateLogService.writeLog(String.format("删除计算拓扑[%s]操作成功。", topology.getName()));
    } catch (EntityAccessException ex) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
    }
}
Also used : UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) Topology(com.ds.retl.dal.entity.Topology)

Example 7 with UserInterfaceErrorException

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

the class TopologyManageServiceImpl method save.

/**
 * {@inheritDoc}
 *
 * @see TopologyManageService#save(String, String)
 */
@Transactional
@Override
public Topology save(String id, String topologyJsonStr) throws UserInterfaceErrorException {
    try {
        Topology topology;
        if (StringUtils.isBlank(id)) {
            topology = EntityFactory.createEntity(Topology.class);
        } else {
            topology = accessor.getById(id, Topology.class);
            if (topology == null) {
                throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_NOT_FOUND);
            }
        }
        JSONObject json = JSON.parseObject(topologyJsonStr);
        String name = json.getString("name");
        topology.setName(name);
        topology.setDescription(json.getString("description"));
        topology.setSubmitted(false);
        topology.setSubmitInfo("");
        topology.setTopologyId(null);
        topology.setTopologyContent(topologyJsonStr);
        topology = accessor.save(topology);
        operateLogService.writeLog(String.format("成功保存[%s]计算拓扑。", name));
        return topology;
    } catch (EntityAccessException | EntityInstantiationException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) Topology(com.ds.retl.dal.entity.Topology) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with UserInterfaceErrorException

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

the class TopologyManageServiceImpl method submit.

/**
 * 提交一个拓扑实体对象到Storm集群中
 *
 * @param topology   拓扑实体对象
 * @param simulation 是否仿真
 * @return 成功返回拓扑实体对象
 * @throws UserInterfaceErrorException 提交过程中发生的异常
 */
private Topology submit(Topology topology, boolean simulation) throws UserInterfaceErrorException {
    String topologyName = topology.getName();
    if (!simulation) {
        // 检查拓扑名字是否已经被部署到Storm集群中
        JSONObject found = foundSubmitedTopology(topologyName);
        if (found != null) {
            try {
                topology.setSubmitted(false);
                topology.setSubmittedTime(new Date().getTime());
                topology.setSubmitInfo("同名的计算拓扑已经被部署到集群中,不能重复部署。");
                accessor.save(topology);
            } catch (EntityAccessException ex) {
                if (logger.isErrorEnabled()) {
                    logger.error("Save submit information fail.", ex);
                }
            }
            throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_ALREADY_SUBMITTED);
        }
    }
    String confStr = topology.getTopologyContent();
    if (StringUtils.isBlank(confStr)) {
        if (logger.isErrorEnabled()) {
            logger.error(String.format("Topology's content is blank, name: %s.", topologyName));
        }
        throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
    }
    JSONObject topologyJson = prepareTopologyConfigJsonObject(confStr);
    if (topology == null) {
        if (logger.isErrorEnabled()) {
            logger.error(String.format("Parse JSON object fail, conf: %s.", confStr));
        }
        throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
    }
    if (!simulation) {
        String stormHome = env.getProperty("storm.home"), stormBin = env.getProperty("storm.bin"), retlHome = env.getProperty("storm.retl"), retlPlatform = env.getProperty("storm.retl.platform"), retlDeps = env.getProperty("storm.retl.deps"), retlConf = env.getProperty("storm.retl.conf");
        String configName = String.format("%s/%s/%s.json", retlHome, retlConf, topologyName);
        File file = new File(configName);
        File parent = file.getParentFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }
        try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)))) {
            bw.write(JSON.toJSONString(topologyJson, true));
        } catch (IOException ex) {
            if (logger.isErrorEnabled()) {
                logger.error(ex);
            }
            throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_FILE_OPERATE_FAIL);
        }
        try {
            int timeout = 60;
            String submitInfo = new RETLStormCli(stormHome, stormBin, retlHome, retlPlatform, retlDeps).deploy(configName, timeout);
            topology.setSubmitInfo(submitInfo);
            for (int index = 0; index < timeout; index++) {
                JSONObject submittedTopology = foundSubmitedTopology(topologyName);
                if (submittedTopology != null) {
                    topology.setSubmittedTime(new Date().getTime());
                    String topologyId = submittedTopology.getString("id");
                    topology.setTopologyId(topologyId);
                    topology.setSubmitted(true);
                    topology = accessor.save(topology);
                    operateLogService.writeLog(String.format("成功提交[%s]计算拓扑。", topologyName));
                    return topology;
                } else {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        if (logger.isErrorEnabled()) {
                            logger.error(ex);
                        }
                    }
                }
            }
            if (logger.isDebugEnabled()) {
                logger.debug("The topology can be found in cluster after wait 10s.");
            }
            topology.setSubmittedTime(new Date().getTime());
            topology.setSubmitted(false);
            accessor.save(topology);
            operateLogService.writeLog(String.format("提交[%s]计算拓扑未成功。", topologyName));
            throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_SUBMIT_FAIL);
        } catch (EntityAccessException ex) {
            if (logger.isErrorEnabled()) {
                logger.error(ex);
            }
            throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
        }
    } else {
        // 本地仿真运行
        new ETLTopologyBuilder().buildTopology(false, topologyJson);
        return topology;
    }
}
Also used : ETLTopologyBuilder(com.ds.retl.ETLTopologyBuilder) RETLStormCli(com.ds.retl.cli.RETLStormCli) JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException)

Example 9 with UserInterfaceErrorException

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

the class UserManageServiceImpl method initUser.

/**
 * {@inheritDoc}
 *
 * @see UserManageService#initUser()
 */
@Transactional
@Override
public User initUser() throws UserInterfaceErrorException {
    String userCode = "ds110";
    try {
        User user = accessor.getByCode(userCode, User.class);
        if (user == null) {
            user = EntityFactory.createEntity(User.class);
            user.setCode("ds110");
        }
        try {
            user.setPassword(DigestUtils.md5("edmund110119"));
        } catch (NoSuchAlgorithmException ex) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_DISGEST_FAIL);
        }
        user.setName("RETL管理员");
        user.setRoles("manager");
        return saveUser(user);
    } catch (EntityInstantiationException | EntityAccessException ex) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with UserInterfaceErrorException

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

the class UserManageServiceImpl method logout.

/**
 * {@inheritDoc}
 *
 * @see UserManageService#logout(String)
 */
@Transactional
@Override
public void logout(String userCode) throws UserInterfaceErrorException {
    try {
        User user = accessor.getByCode(userCode, User.class);
        if (user == null) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.USER_NOT_FOUND);
        }
        user.setOnline(false);
        accessor.save(user);
        logService.writeLog(String.format("用户[%s]成功注销退出系统。", userCode));
    } catch (EntityAccessException ex) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) Transactional(org.springframework.transaction.annotation.Transactional)

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