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