Search in sources :

Example 51 with Node

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

the class SymmetricAdmin method sendScript.

private void sendScript(CommandLine line, List<String> args) throws Exception {
    String scriptName = popArg(args, "Script Name");
    String scriptData = FileUtils.readFileToString(new File(scriptName));
    for (Node node : getNodes(line)) {
        System.out.println("Sending script to node '" + node.getNodeId() + "'");
        getSymmetricEngine().getDataService().sendScript(node.getNodeId(), scriptData, false);
    }
}
Also used : Node(org.jumpmind.symmetric.model.Node) File(java.io.File)

Example 52 with Node

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

the class ConfigurationChangedDataRouter method routeNodeTables.

protected void routeNodeTables(Set<String> nodeIds, Map<String, String> columnValues, NetworkedNode rootNetworkedNode, Node me, SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> possibleTargetNodes, boolean initialLoad) {
    String nodeIdForRecordBeingRouted = columnValues.get("NODE_ID");
    if (dataMetaData.getData().getDataEventType() == DataEventType.DELETE) {
        String createAtNodeId = columnValues.get("CREATED_AT_NODE_ID");
        for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
            if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeIdForRecordBeingRouted.equals(nodeThatMayBeRoutedTo.getNodeId()) && !nodeThatMayBeRoutedTo.getNodeId().equals(createAtNodeId) && (nodeThatMayBeRoutedTo.getCreatedAtNodeId() == null || !nodeThatMayBeRoutedTo.getCreatedAtNodeId().equals(nodeIdForRecordBeingRouted))) {
                nodeIds.add(nodeThatMayBeRoutedTo.getNodeId());
            }
        }
    } else {
        IConfigurationService configurationService = engine.getConfigurationService();
        List<NodeGroupLink> nodeGroupLinks = getNodeGroupLinksFromContext(routingContext);
        for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
            if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeThatMayBeRoutedTo.requires13Compatiblity() && isLinked(nodeIdForRecordBeingRouted, nodeThatMayBeRoutedTo, rootNetworkedNode, me, nodeGroupLinks) && (!isSameNumberOfLinksAwayFromRoot(nodeThatMayBeRoutedTo, rootNetworkedNode, me) || configurationService.isMasterToMaster()) || (nodeThatMayBeRoutedTo.getNodeId().equals(me.getNodeId()) && initialLoad)) {
                nodeIds.add(nodeThatMayBeRoutedTo.getNodeId());
            }
        }
        if (!initialLoad && nodeIds != null) {
            if (tableMatches(dataMetaData, TableConstants.SYM_NODE_SECURITY)) {
                routeSymNodeSecurity(me, nodeIdForRecordBeingRouted, dataMetaData, nodeIds, columnValues);
            }
            /*
                 * Don't route insert events for a node to itself. They will be
                 * loaded during registration. If we route them, then an old
                 * state can override the correct state
                 * 
                 * Don't send deletes to a node. A node should be responsible
                 * for deleting itself.
                 */
            if (dataMetaData.getData().getDataEventType() == DataEventType.INSERT) {
                nodeIds.remove(nodeIdForRecordBeingRouted);
            }
        }
    }
}
Also used : Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Example 53 with Node

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

the class NotificationTypeEmail method notify.

public void notify(Notification notification, List<MonitorEvent> monitorEvents) {
    String subject = null;
    if (monitorEvents.size() == 1) {
        MonitorEvent event = monitorEvents.get(0);
        subject = "Monitor event for " + event.getType() + " from node " + event.getNodeId();
    } else {
        Set<String> nodeIds = new HashSet<String>();
        Set<String> types = new HashSet<String>();
        for (MonitorEvent event : monitorEvents) {
            nodeIds.add(event.getNodeId());
            types.add(event.getType());
        }
        StringBuilder typesString = new StringBuilder();
        Iterator<String> iter = types.iterator();
        while (iter.hasNext()) {
            typesString.append(iter.next());
            if (iter.hasNext()) {
                typesString.append(", ");
            }
        }
        subject = "Monitor events for " + typesString + " from " + nodeIds.size() + " nodes";
    }
    Map<String, Node> nodes = engine.getNodeService().findAllNodesAsMap();
    StringBuilder text = new StringBuilder();
    for (MonitorEvent event : monitorEvents) {
        Node node = nodes.get(event.getNodeId());
        String nodeString = node != null ? node.toString() : event.getNodeId();
        text.append(DATE_FORMATTER.format(event.getEventTime())).append(" [");
        text.append(Monitor.getSeverityLevelNames().get(event.getSeverityLevel())).append("] [");
        text.append(nodeString).append("] [");
        text.append(event.getHostName()).append("] ");
        text.append("Monitor event for ").append(event.getType());
        text.append(" reached threshold of ").append(event.getThreshold());
        text.append(" with a value of ").append(event.getValue()).append("\n");
    }
    String recipients = notification.getExpression();
    if (recipients != null) {
        log.info("Sending email with subject '" + subject + "' to " + recipients);
        engine.getMailService().sendEmail(subject, text.toString(), recipients);
    } else {
        log.warn("Notification " + notification.getNotificationId() + " has no email recipients configured.");
    }
}
Also used : MonitorEvent(org.jumpmind.symmetric.model.MonitorEvent) Node(org.jumpmind.symmetric.model.Node) HashSet(java.util.HashSet)

Example 54 with Node

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

the class OfflinePullService method pullData.

public synchronized RemoteNodeStatuses pullData(boolean force) {
    RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
    Node identity = nodeService.findIdentity();
    if (identity != null && identity.isSyncEnabled()) {
        if (force || !clusterService.isInfiniteLocked(ClusterConstants.OFFLINE_PULL)) {
            List<NodeCommunication> nodes = nodeCommunicationService.list(CommunicationType.OFFLN_PULL);
            int availableThreads = nodeCommunicationService.getAvailableThreads(CommunicationType.OFFLN_PULL);
            for (NodeCommunication nodeCommunication : nodes) {
                if (availableThreads > 0) {
                    if (nodeCommunicationService.execute(nodeCommunication, statuses, this)) {
                        availableThreads--;
                    }
                }
            }
        } else {
            log.debug("Did not run the offline pull process because it has been stopped");
        }
    }
    return statuses;
}
Also used : RemoteNodeStatuses(org.jumpmind.symmetric.model.RemoteNodeStatuses) NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) Node(org.jumpmind.symmetric.model.Node)

Example 55 with Node

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

the class OfflinePullService method execute.

public void execute(NodeCommunication nodeCommunication, RemoteNodeStatus status) {
    Node node = nodeCommunication.getNode();
    Node local = nodeService.findIdentity();
    try {
        long batchesProcessedCount = 0;
        do {
            batchesProcessedCount = status.getBatchesProcessed();
            log.debug("Offline pull requested for {}", node.toString());
            FileIncomingTransport transport = (FileIncomingTransport) transportManager.getPullTransport(node, local, null, null, null);
            dataLoaderService.loadDataFromOfflineTransport(node, status, transport);
            if (!status.failed() && status.getBatchesProcessed() > batchesProcessedCount) {
                log.info("Offline pull data read for {}.  {} rows and {} batches were processed", new Object[] { node.toString(), status.getDataProcessed(), status.getBatchesProcessed() });
            } else if (status.failed()) {
                log.info("There was a failure while reading pull data for {}.  {} rows and {} batches were processed", new Object[] { node.toString(), status.getDataProcessed(), status.getBatchesProcessed() });
            }
            transport.complete(!status.failed());
        } while (!status.failed() && status.getBatchesProcessed() > batchesProcessedCount);
    } catch (IOException e) {
        log.error("An IO exception happened while attempting to read offline pull data", e);
    }
}
Also used : FileIncomingTransport(org.jumpmind.symmetric.transport.file.FileIncomingTransport) Node(org.jumpmind.symmetric.model.Node) IOException(java.io.IOException)

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