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