Search in sources :

Example 1 with Topology

use of com.ds.retl.dal.entity.Topology in project main by JohnPeng739.

the class TopologyManageServiceImpl method kill.

/**
 * {@inheritDoc}
 *
 * @see TopologyManageServiceImpl#kill(String)
 */
@Override
public Topology kill(String id) throws UserInterfaceErrorException {
    try {
        Topology topology = accessor.getById(id, Topology.class);
        if (topology == null) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_NOT_FOUND);
        }
        if (StringUtils.isBlank(topology.getTopologyId()) || !topology.isSubmitted()) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_NOT_SUBMITTED);
        }
        JSONObject result = stormClient.getTopology(topology.getTopologyId());
        if (result == null) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_NOT_SUBMITTED);
        }
        result = stormClient.kill(topology.getTopologyId());
        if (result == null || !"success".equals(result.getString("status"))) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_KILL_FAIL);
        }
        topology.setSubmitted(false);
        topology.setSubmitInfo(null);
        topology.setTopologyId(null);
        topology = accessor.save(topology);
        operateLogService.writeLog(String.format("杀死计算拓扑[%s]操作成功。", topology.getName()));
        return topology;
    } catch (EntityAccessException 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)

Example 2 with Topology

use of com.ds.retl.dal.entity.Topology 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 3 with Topology

use of com.ds.retl.dal.entity.Topology 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 4 with Topology

use of com.ds.retl.dal.entity.Topology in project main by JohnPeng739.

the class TopologyManageResource method submitTopology.

/**
 * 提交输入的拓扑配置信息到Storm集群中
 *
 * @param userCode              操作用户代码
 * @param topologyId            拓扑关键字ID,如果是新增,则为null
 * @param topologyConfigJsonStr 计算拓扑配置信息
 * @return 提交成功返回提交的拓扑对象,否则返回错误信息。
 */
@Path("topology/submit")
@POST
public DataVO<TopologyVO> submitTopology(@QueryParam("userCode") String userCode, @QueryParam("topologyId") String topologyId, String topologyConfigJsonStr) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        Topology topology = topologyManageService.submit(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 5 with Topology

use of com.ds.retl.dal.entity.Topology in project main by JohnPeng739.

the class TopologyManageResource method submitTopology.

/**
 * 提交指定关键字ID的计算拓扑到Storm集群中
 *
 * @param userCode   操作用户代码
 * @param simulation 设置为true表示本地仿真,否则真正提交集群
 * @param id         拓扑的关键字ID
 * @return 提交成功返回提交的拓扑对象,否则返回错误信息。
 */
@Path("topology/submit/{id}")
@GET
public DataVO<TopologyVO> submitTopology(@QueryParam("userCode") String userCode, @QueryParam("simulation") boolean simulation, @PathParam("id") String id) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        Topology topology = topologyManageService.submit(id, simulation);
        TopologyVO topologyVO = new TopologyVO();
        TopologyVO.transform(topology, topologyVO);
        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)

Aggregations

Topology (com.ds.retl.dal.entity.Topology)8 UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)8 TopologyVO (com.ds.retl.rest.vo.topology.TopologyVO)5 DataVO (org.mx.rest.vo.DataVO)5 PaginationDataVO (org.mx.rest.vo.PaginationDataVO)5 EntityAccessException (org.mx.dal.exception.EntityAccessException)4 JSONObject (com.alibaba.fastjson.JSONObject)2 EntityInstantiationException (org.mx.dal.exception.EntityInstantiationException)1 Transactional (org.springframework.transaction.annotation.Transactional)1