Search in sources :

Example 1 with Node

use of org.jumpmind.symmetric.web.rest.model.Node in project symmetric-ds by JumpMind.

the class RestService method sendSchemaImpl.

private SendSchemaResponse sendSchemaImpl(ISymmetricEngine engine, SendSchemaRequest request) {
    IConfigurationService configurationService = engine.getConfigurationService();
    INodeService nodeService = engine.getNodeService();
    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    IDataService dataService = engine.getDataService();
    SendSchemaResponse response = new SendSchemaResponse();
    org.jumpmind.symmetric.model.Node identity = nodeService.findIdentity();
    if (identity != null) {
        List<org.jumpmind.symmetric.model.Node> nodesToSendTo = new ArrayList<org.jumpmind.symmetric.model.Node>();
        List<String> nodeIds = request.getNodeIdsToSendTo();
        if (nodeIds == null || nodeIds.size() == 0) {
            nodeIds = new ArrayList<String>();
            String nodeGroupIdToSendTo = request.getNodeGroupIdToSendTo();
            if (isNotBlank(nodeGroupIdToSendTo)) {
                NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), nodeGroupIdToSendTo, false);
                if (link != null) {
                    Collection<org.jumpmind.symmetric.model.Node> nodes = nodeService.findEnabledNodesFromNodeGroup(nodeGroupIdToSendTo);
                    nodesToSendTo.addAll(nodes);
                } else {
                    log.warn("Could not send schema to all nodes in the '" + nodeGroupIdToSendTo + "' node group.  No node group link exists");
                }
            } else {
                log.warn("Could not send schema to nodes.  There are none that were provided and the nodeGroupIdToSendTo was also not provided");
            }
        } else {
            for (String nodeIdToValidate : nodeIds) {
                org.jumpmind.symmetric.model.Node node = nodeService.findNode(nodeIdToValidate);
                if (node != null) {
                    NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), node.getNodeGroupId(), false);
                    if (link != null) {
                        nodesToSendTo.add(node);
                    } else {
                        log.warn("Could not send schema to node '" + nodeIdToValidate + "'. No node group link exists");
                    }
                } else {
                    log.warn("Could not send schema to node '" + nodeIdToValidate + "'.  It was not present in the database");
                }
            }
        }
        Map<String, List<TableName>> results = response.getNodeIdsSentTo();
        List<String> nodeIdsToSendTo = toNodeIds(nodesToSendTo);
        for (String nodeId : nodeIdsToSendTo) {
            results.put(nodeId, new ArrayList<TableName>());
        }
        if (nodesToSendTo.size() > 0) {
            List<TableName> tablesToSend = request.getTablesToSend();
            List<TriggerRouter> triggerRouters = triggerRouterService.getTriggerRouters(true, false);
            for (TriggerRouter triggerRouter : triggerRouters) {
                Trigger trigger = triggerRouter.getTrigger();
                NodeGroupLink link = triggerRouter.getRouter().getNodeGroupLink();
                if (link.getSourceNodeGroupId().equals(identity.getNodeGroupId())) {
                    for (org.jumpmind.symmetric.model.Node node : nodesToSendTo) {
                        if (link.getTargetNodeGroupId().equals(node.getNodeGroupId())) {
                            if (tablesToSend == null || tablesToSend.size() == 0 || contains(trigger, tablesToSend)) {
                                dataService.sendSchema(node.getNodeId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName(), false);
                                results.get(node.getNodeId()).add(new TableName(trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()));
                            }
                        }
                    }
                }
            }
        }
    }
    return response;
}
Also used : Node(org.jumpmind.symmetric.web.rest.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) ArrayList(java.util.ArrayList) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) Trigger(org.jumpmind.symmetric.model.Trigger) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList) EngineList(org.jumpmind.symmetric.web.rest.model.EngineList) NodeList(org.jumpmind.symmetric.web.rest.model.NodeList) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) IDataService(org.jumpmind.symmetric.service.IDataService) TableName(org.jumpmind.symmetric.web.rest.model.TableName) INodeService(org.jumpmind.symmetric.service.INodeService) SendSchemaResponse(org.jumpmind.symmetric.web.rest.model.SendSchemaResponse)

Example 2 with Node

use of org.jumpmind.symmetric.web.rest.model.Node in project symmetric-ds by JumpMind.

the class RestService method childrenImpl.

private NodeList childrenImpl(ISymmetricEngine engine) {
    NodeList children = new NodeList();
    Node xmlChildNode = null;
    INodeService nodeService = engine.getNodeService();
    org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
    if (isRegistered(engine)) {
        if (isRootNode(engine, modelNode)) {
            NetworkedNode networkedNode = nodeService.getRootNetworkedNode();
            Set<NetworkedNode> childNetwork = networkedNode.getChildren();
            if (childNetwork != null) {
                for (NetworkedNode child : childNetwork) {
                    List<NodeHost> nodeHosts = nodeService.findNodeHosts(child.getNode().getNodeId());
                    NodeSecurity nodeSecurity = nodeService.findNodeSecurity(child.getNode().getNodeId());
                    xmlChildNode = new Node();
                    xmlChildNode.setNodeId(child.getNode().getNodeId());
                    xmlChildNode.setExternalId(child.getNode().getExternalId());
                    xmlChildNode.setRegistrationServer(false);
                    xmlChildNode.setSyncUrl(child.getNode().getSyncUrl());
                    xmlChildNode.setBatchInErrorCount(child.getNode().getBatchInErrorCount());
                    xmlChildNode.setBatchToSendCount(child.getNode().getBatchToSendCount());
                    if (nodeHosts.size() > 0) {
                        xmlChildNode.setLastHeartbeat(nodeHosts.get(0).getHeartbeatTime());
                    }
                    xmlChildNode.setRegistered(nodeSecurity.hasRegistered());
                    xmlChildNode.setInitialLoaded(nodeSecurity.hasInitialLoaded());
                    xmlChildNode.setReverseInitialLoaded(nodeSecurity.hasReverseInitialLoaded());
                    if (child.getNode().getCreatedAtNodeId() == null) {
                        xmlChildNode.setRegistrationServer(true);
                    }
                    children.addNode(xmlChildNode);
                }
            }
        }
    } else {
        throw new NotFoundException();
    }
    return children;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) NodeList(org.jumpmind.symmetric.web.rest.model.NodeList) Node(org.jumpmind.symmetric.web.rest.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) INodeService(org.jumpmind.symmetric.service.INodeService) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) NodeHost(org.jumpmind.symmetric.model.NodeHost)

Example 3 with Node

use of org.jumpmind.symmetric.web.rest.model.Node in project symmetric-ds by JumpMind.

the class RestService method nodeImpl.

private Node nodeImpl(ISymmetricEngine engine) {
    Node xmlNode = new Node();
    if (isRegistered(engine)) {
        INodeService nodeService = engine.getNodeService();
        org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity(false);
        List<NodeHost> nodeHosts = nodeService.findNodeHosts(modelNode.getNodeId());
        NodeSecurity nodeSecurity = nodeService.findNodeSecurity(modelNode.getNodeId());
        xmlNode.setNodeId(modelNode.getNodeId());
        xmlNode.setExternalId(modelNode.getExternalId());
        xmlNode.setSyncUrl(modelNode.getSyncUrl());
        xmlNode.setRegistrationUrl(engine.getParameterService().getRegistrationUrl());
        xmlNode.setBatchInErrorCount(modelNode.getBatchInErrorCount());
        xmlNode.setBatchToSendCount(modelNode.getBatchToSendCount());
        if (nodeHosts.size() > 0) {
            xmlNode.setLastHeartbeat(nodeHosts.get(0).getHeartbeatTime());
        }
        xmlNode.setHeartbeatInterval(engine.getParameterService().getInt(ParameterConstants.HEARTBEAT_JOB_PERIOD_MS));
        xmlNode.setRegistered(nodeSecurity.hasRegistered());
        xmlNode.setInitialLoaded(nodeSecurity.hasInitialLoaded());
        xmlNode.setReverseInitialLoaded(nodeSecurity.hasReverseInitialLoaded());
        if (modelNode.getCreatedAtNodeId() == null) {
            xmlNode.setRegistrationServer(true);
        } else {
            xmlNode.setRegistrationServer(false);
        }
        xmlNode.setCreatedAtNodeId(modelNode.getCreatedAtNodeId());
    } else {
        throw new NotFoundException();
    }
    return xmlNode;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.web.rest.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) INodeService(org.jumpmind.symmetric.service.INodeService) NodeHost(org.jumpmind.symmetric.model.NodeHost)

Aggregations

NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)3 INodeService (org.jumpmind.symmetric.service.INodeService)3 Node (org.jumpmind.symmetric.web.rest.model.Node)3 NodeHost (org.jumpmind.symmetric.model.NodeHost)2 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)2 NodeList (org.jumpmind.symmetric.web.rest.model.NodeList)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)1 Trigger (org.jumpmind.symmetric.model.Trigger)1 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)1 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)1 IDataService (org.jumpmind.symmetric.service.IDataService)1 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)1 EngineList (org.jumpmind.symmetric.web.rest.model.EngineList)1 SendSchemaResponse (org.jumpmind.symmetric.web.rest.model.SendSchemaResponse)1 TableName (org.jumpmind.symmetric.web.rest.model.TableName)1