Search in sources :

Example 96 with Node

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

the class NodeService method insertNodeSecurity.

public void insertNodeSecurity(String id) {
    String password = extensionService.getExtensionPoint(INodeIdCreator.class).generatePassword(new Node(id, null, null));
    password = filterPasswordOnSaveIfNeeded(password);
    sqlTemplate.update(getSql("insertNodeSecuritySql"), new Object[] { id, password, null });
    flushNodeAuthorizedCache();
}
Also used : INodeIdCreator(org.jumpmind.symmetric.config.INodeIdCreator) Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode)

Example 97 with Node

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

the class NodeCommunicationService method list.

public List<NodeCommunication> list(CommunicationType communicationType) {
    initialize();
    List<NodeCommunication> communicationRows = find(communicationType);
    List<Node> nodesToCommunicateWith = null;
    switch(communicationType) {
        case PULL:
        case FILE_PULL:
            nodesToCommunicateWith = removeOfflineNodes(nodeService.findNodesToPull());
            break;
        case FILE_PUSH:
        case PUSH:
            nodesToCommunicateWith = removeOfflineNodes(nodeService.findNodesToPushTo());
            break;
        case OFFLN_PUSH:
        case OFF_FSPUSH:
            nodesToCommunicateWith = getNodesToCommunicateWithOffline(CommunicationType.PUSH);
            break;
        case OFFLN_PULL:
        case OFF_FSPULL:
            nodesToCommunicateWith = getNodesToCommunicateWithOffline(CommunicationType.PULL);
            break;
        default:
            nodesToCommunicateWith = new ArrayList<Node>(0);
            break;
    }
    List<NodeCommunication> nodesToCommunicateWithList = filterForChannelThreading(nodesToCommunicateWith);
    for (NodeCommunication nodeToCommunicateWith : nodesToCommunicateWithList) {
        NodeCommunication comm = null;
        for (NodeCommunication nodeCommunication : communicationRows) {
            if (nodeCommunication.getIdentifier().equals(nodeToCommunicateWith.getIdentifier())) {
                comm = nodeCommunication;
                break;
            }
        }
        if (comm == null) {
            comm = new NodeCommunication();
            comm.setNodeId(nodeToCommunicateWith.getNodeId());
            comm.setQueue(nodeToCommunicateWith.getQueue());
            comm.setCommunicationType(communicationType);
            save(comm, false);
            communicationRows.add(comm);
        }
        comm.setNode(nodeToCommunicateWith.getNode());
    }
    Iterator<NodeCommunication> it = communicationRows.iterator();
    while (it.hasNext()) {
        NodeCommunication nodeCommunication = it.next();
        Node node = null;
        for (NodeCommunication nodeToCommunicateWith : nodesToCommunicateWithList) {
            if (nodeCommunication.getNodeId().equals(nodeToCommunicateWith.getNodeId())) {
                node = nodeToCommunicateWith.getNode();
                break;
            }
        }
        if (node == null) {
            delete(nodeCommunication);
            it.remove();
        }
    }
    if (communicationType == CommunicationType.PULL || communicationType == CommunicationType.FILE_PULL) {
        communicationRows = removeNodesWithNoBatchesToSend(communicationRows);
    }
    return communicationRows;
}
Also used : NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) Node(org.jumpmind.symmetric.model.Node)

Example 98 with Node

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

the class NodeService method findAllNodesAsMap.

public Map<String, Node> findAllNodesAsMap() {
    List<Node> nodes = findAllNodes();
    Map<String, Node> nodeMap = new HashMap<String, Node>(nodes.size());
    for (Node node : nodes) {
        nodeMap.put(node.getNodeId(), node);
    }
    return nodeMap;
}
Also used : HashMap(java.util.HashMap) Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode)

Example 99 with Node

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

the class NodeService method getRootNetworkedNode.

public NetworkedNode getRootNetworkedNode() {
    Map<String, Node> nodes = findAllNodesAsMap();
    Map<String, NetworkedNode> leaves = new HashMap<String, NetworkedNode>(nodes.size());
    NetworkedNode nodeLeaf = null;
    for (Node node : nodes.values()) {
        nodeLeaf = leaves.get(node.getNodeId());
        if (nodeLeaf == null) {
            nodeLeaf = new NetworkedNode(node);
            nodeLeaf.addParents(nodes, leaves);
            leaves.put(node.getNodeId(), nodeLeaf);
        }
    }
    nodeLeaf = leaves.get(findIdentityNodeId());
    if (nodeLeaf != null) {
        NetworkedNode root = nodeLeaf.getRoot();
        root.setAllNetworkedNodes(leaves);
        return root;
    } else {
        return null;
    }
}
Also used : HashMap(java.util.HashMap) Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode)

Example 100 with Node

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

the class NodeService method findOfflineNodes.

public List<Node> findOfflineNodes(long minutesOffline) {
    List<Node> offlineNodeList = new ArrayList<Node>();
    Node myNode = findIdentity();
    if (myNode != null) {
        long offlineNodeDetectionMillis = minutesOffline * 60 * 1000;
        List<Row> list = sqlTemplate.query(getSql("findNodeHeartbeatsSql"));
        for (Row node : list) {
            String nodeId = node.getString("node_id");
            Date time = node.getDateTime("heartbeat_time");
            String offset = node.getString("timezone_offset");
            // Take the timezone of the client node into account when
            // checking the hearbeat time.
            Date clientNodeCurrentTime = null;
            if (offset != null) {
                clientNodeCurrentTime = AppUtils.getLocalDateForOffset(offset);
            } else {
                clientNodeCurrentTime = new Date();
            }
            long cutOffTimeMillis = clientNodeCurrentTime.getTime() - offlineNodeDetectionMillis;
            if (time == null || time.getTime() < cutOffTimeMillis) {
                offlineNodeList.add(findNode(nodeId));
            }
        }
    }
    return offlineNodeList;
}
Also used : Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) Date(java.util.Date)

Aggregations

Node (org.jumpmind.symmetric.model.Node)129 HashSet (java.util.HashSet)18 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)18 Test (org.junit.Test)18 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)17 ArrayList (java.util.ArrayList)14 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)14 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)13 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)13 Table (org.jumpmind.db.model.Table)12 Data (org.jumpmind.symmetric.model.Data)12 Router (org.jumpmind.symmetric.model.Router)12 Date (java.util.Date)11 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)11 IOException (java.io.IOException)10 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)10 HashMap (java.util.HashMap)9 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)9 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)8