Search in sources :

Example 1 with NodeDO

use of com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO in project otter by alibaba.

the class NodeSerivceTest method testListAllNodes.

@Test
public void testListAllNodes() {
    new NonStrictExpectations() {

        {
            nodeDao.listAll();
            List<NodeDO> nodeDos = new ArrayList<NodeDO>();
            for (int i = 0; i < 10; i++) {
                NodeDO nodeDo = new NodeDO();
                nodeDo.setId(Long.valueOf(1));
                nodeDo.setIp("127.0.0.1");
                nodeDos.add(nodeDo);
            }
            returns(nodeDos);
            arbitrateManageService.nodeEvent();
            returns(new NodeArbitrateEvent() {

                @Override
                public List<Long> liveNodes() {
                    return Arrays.asList(1L);
                }
            });
        }
    };
    want.number(nodeService.listAll().size()).isEqualTo(10);
    want.string(nodeService.listAll().get(0).getIp()).isEqualTo("127.0.0.1");
}
Also used : NodeDO(com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.manager.biz.BaseOtterTest)

Example 2 with NodeDO

use of com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO in project otter by alibaba.

the class NodeServiceImpl method listByCondition.

public List<Node> listByCondition(Map condition) {
    List<NodeDO> nodeDos = nodeDao.listByCondition(condition);
    if (nodeDos.isEmpty()) {
        logger.debug("DEBUG ## couldn't query any node by the condition:" + JsonUtils.marshalToString(condition));
        return new ArrayList<Node>();
    }
    // 验证zk的node信息
    List<Long> nodeIds = arbitrateManageService.nodeEvent().liveNodes();
    for (NodeDO nodeDo : nodeDos) {
        if (null != nodeIds && nodeIds.contains(nodeDo.getId())) {
            nodeDo.setStatus(NodeStatus.START);
        } else {
            nodeDo.setStatus(NodeStatus.STOP);
        }
    }
    return doToModel(nodeDos);
}
Also used : NodeDO(com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO) ArrayList(java.util.ArrayList)

Example 3 with NodeDO

use of com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO in project otter by alibaba.

the class NodeServiceImpl method modelToDo.

/**
 * 用于Model对象转化为DO对象
 *
 * @param node
 * @return NodeDO
 */
private NodeDO modelToDo(Node node) {
    NodeDO nodeDo = new NodeDO();
    try {
        nodeDo.setId(node.getId());
        nodeDo.setIp(node.getIp());
        nodeDo.setName(node.getName());
        nodeDo.setPort(node.getPort());
        nodeDo.setDescription(node.getDescription());
        nodeDo.setStatus(node.getStatus());
        nodeDo.setParameters(node.getParameters());
        nodeDo.setGmtCreate(node.getGmtCreate());
        nodeDo.setGmtModified(node.getGmtModified());
    } catch (Exception e) {
        logger.error("ERROR ## change the node Model to Do has an exception");
        throw new ManagerException(e);
    }
    return nodeDo;
}
Also used : NodeDO(com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 4 with NodeDO

use of com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO in project otter by alibaba.

the class NodeServiceImpl method listByIds.

public List<Node> listByIds(Long... identities) {
    List<Node> nodes = new ArrayList<Node>();
    try {
        List<NodeDO> nodeDos = null;
        if (identities.length < 1) {
            nodeDos = nodeDao.listAll();
            if (nodeDos.isEmpty()) {
                logger.debug("DEBUG ## couldn't query any node, maybe hasn't create any channel.");
                return nodes;
            }
        } else {
            nodeDos = nodeDao.listByMultiId(identities);
            if (nodeDos.isEmpty()) {
                String exceptionCause = "couldn't query any node by nodeIds:" + Arrays.toString(identities);
                logger.error("ERROR ## " + exceptionCause);
                throw new ManagerException(exceptionCause);
            }
        }
        // 验证zk的node信息
        List<Long> nodeIds = arbitrateManageService.nodeEvent().liveNodes();
        for (NodeDO nodeDo : nodeDos) {
            if (nodeIds.contains(nodeDo.getId())) {
                nodeDo.setStatus(NodeStatus.START);
            } else {
                nodeDo.setStatus(NodeStatus.STOP);
            }
        }
        nodes = doToModel(nodeDos);
    } catch (Exception e) {
        logger.error("ERROR ## query nodes has an exception!");
        throw new ManagerException(e);
    }
    return nodes;
}
Also used : Node(com.alibaba.otter.shared.common.model.config.node.Node) ArrayList(java.util.ArrayList) NodeDO(com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 5 with NodeDO

use of com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO in project otter by alibaba.

the class NodeServiceImpl method create.

/**
 * 添加
 */
public void create(final Node node) {
    Assert.assertNotNull(node);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                NodeDO nodeDo = modelToDo(node);
                nodeDo.setId(0L);
                if (!nodeDao.checkUnique(nodeDo)) {
                    String exceptionCause = "exist the same repeat node in the database.";
                    logger.warn("WARN ## " + exceptionCause);
                    throw new RepeatConfigureException(exceptionCause);
                }
                nodeDao.insert(nodeDo);
            } catch (RepeatConfigureException rce) {
                throw rce;
            } catch (Exception e) {
                logger.error("ERROR ## create node has an exception!");
                throw new ManagerException(e);
            }
        }
    });
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) NodeDO(com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO) TransactionStatus(org.springframework.transaction.TransactionStatus) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Aggregations

NodeDO (com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO)6 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)4 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)4 ArrayList (java.util.ArrayList)3 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 BaseOtterTest (com.alibaba.otter.manager.biz.BaseOtterTest)1 NodeArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent)1 Node (com.alibaba.otter.shared.common.model.config.node.Node)1 List (java.util.List)1 Test (org.testng.annotations.Test)1