Search in sources :

Example 56 with Node

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

the class NodeCommunicationService method getNodesToCommunicateWithOffline.

protected List<Node> getNodesToCommunicateWithOffline(CommunicationType communicationType) {
    List<Node> nodesToCommunicateWith = null;
    if (parameterService.is(ParameterConstants.NODE_OFFLINE) || (communicationType.equals(CommunicationType.PULL) && parameterService.is(ParameterConstants.NODE_OFFLINE_INCOMING_ACCEPT_ALL))) {
        if (communicationType.equals(CommunicationType.PUSH)) {
            nodesToCommunicateWith = nodeService.findTargetNodesFor(NodeGroupLinkAction.W);
            nodesToCommunicateWith.addAll(nodeService.findNodesToPushTo());
        } else if (communicationType.equals(CommunicationType.PULL)) {
            nodesToCommunicateWith = nodeService.findSourceNodesFor(NodeGroupLinkAction.P);
            nodesToCommunicateWith.addAll(nodeService.findNodesToPull());
        }
    } else {
        List<DatabaseParameter> parms = parameterService.getOfflineNodeParameters();
        nodesToCommunicateWith = new ArrayList<Node>(parms.size());
        if (parms.size() > 0) {
            List<Node> sourceNodes = null;
            if (communicationType.equals(CommunicationType.PUSH)) {
                sourceNodes = nodeService.findTargetNodesFor(NodeGroupLinkAction.W);
                sourceNodes.addAll(nodeService.findNodesToPushTo());
            } else if (communicationType.equals(CommunicationType.PULL)) {
                sourceNodes = nodeService.findSourceNodesFor(NodeGroupLinkAction.P);
                sourceNodes.addAll(nodeService.findNodesToPull());
            }
            if (sourceNodes != null && sourceNodes.size() > 0) {
                for (DatabaseParameter parm : parms) {
                    for (Node node : sourceNodes) {
                        if ((parm.getNodeGroupId().equals(ParameterConstants.ALL) || parm.getNodeGroupId().equals(node.getNodeGroupId()) && (parm.getExternalId().equals(ParameterConstants.ALL) || parm.getExternalId().equals(node.getExternalId())))) {
                            nodesToCommunicateWith.add(node);
                        }
                    }
                }
            }
        }
    }
    return nodesToCommunicateWith;
}
Also used : DatabaseParameter(org.jumpmind.symmetric.model.DatabaseParameter) Node(org.jumpmind.symmetric.model.Node)

Example 57 with Node

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

the class OfflinePushService method pushToNode.

private void pushToNode(Node remote, RemoteNodeStatus status) {
    Node identity = nodeService.findIdentity();
    FileOutgoingTransport transport = null;
    ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(identity.getNodeId(), status.getChannelId(), remote.getNodeId(), ProcessType.OFFLINE_PUSH));
    List<OutgoingBatch> extractedBatches = null;
    try {
        transport = (FileOutgoingTransport) transportManager.getPushTransport(remote, identity, null, null);
        extractedBatches = dataExtractorService.extract(processInfo, remote, status.getChannelId(), transport);
        if (extractedBatches.size() > 0) {
            log.info("Offline push data written for {} at {}", remote, transport.getOutgoingDir());
            List<BatchAck> batchAcks = readAcks(extractedBatches, transport, transportManager, acknowledgeService);
            status.updateOutgoingStatus(extractedBatches, batchAcks);
        }
        if (processInfo.getStatus() != Status.ERROR) {
            processInfo.setStatus(Status.OK);
        }
    } catch (Exception ex) {
        processInfo.setStatus(Status.ERROR);
        log.error("Failed to write offline file", ex);
    } finally {
        transport.close();
        transport.complete(processInfo.getStatus() == Status.OK);
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) FileOutgoingTransport(org.jumpmind.symmetric.transport.file.FileOutgoingTransport) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 58 with Node

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

the class OfflinePushService method execute.

public void execute(NodeCommunication nodeCommunication, RemoteNodeStatus status) {
    Node node = nodeCommunication.getNode();
    long batchesProcessedCount = 0;
    do {
        batchesProcessedCount = status.getBatchesProcessed();
        log.debug("Offline push requested for {}", node);
        pushToNode(node, status);
        if (!status.failed() && status.getBatchesProcessed() > batchesProcessedCount) {
            log.info("Offline push data written for {}. {} data and {} batches were processed", new Object[] { node, status.getDataProcessed(), status.getBatchesProcessed() });
        } else if (status.failed()) {
            log.info("There was a failure while writing offline push data for {}. {} data and {} batches were processed", new Object[] { node, status.getDataProcessed(), status.getBatchesProcessed() });
        }
        log.debug("Offline push completed for {}", node);
    } while (!status.failed() && status.getBatchesProcessed() > batchesProcessedCount);
}
Also used : Node(org.jumpmind.symmetric.model.Node)

Example 59 with Node

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

the class NodeService method findLastHeartbeats.

public Map<String, Date> findLastHeartbeats() {
    Map<String, Date> dates = new HashMap<String, Date>();
    Node myNode = findIdentity();
    if (myNode != null) {
        List<Row> list = sqlTemplate.query(getSql("findNodeHeartbeatsSql"));
        for (Row node : list) {
            String nodeId = node.getString("node_id");
            Date time = node.getDateTime("heartbeat_time");
            dates.put(nodeId, time);
        }
    }
    return dates;
}
Also used : HashMap(java.util.HashMap) Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) Row(org.jumpmind.db.sql.Row) Date(java.util.Date)

Example 60 with Node

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

the class NodeService method findNodesThatOriginatedFromNodeId.

public Set<Node> findNodesThatOriginatedFromNodeId(String originalNodeId, boolean recursive) {
    Set<Node> all = new HashSet<Node>();
    List<Node> list = sqlTemplate.query(getSql("selectNodePrefixSql", "findNodesCreatedByMeSql"), new NodeRowMapper(), originalNodeId);
    if (list.size() > 0) {
        all.addAll(list);
        if (recursive) {
            for (Node node : list) {
                all.addAll(findNodesThatOriginatedFromNodeId(node.getNodeId()));
            }
        }
    }
    return all;
}
Also used : Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) HashSet(java.util.HashSet)

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