use of org.jumpmind.symmetric.model.NetworkedNode in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouter method getRootNetworkNodeFromContext.
protected NetworkedNode getRootNetworkNodeFromContext(SimpleRouterContext routingContext) {
NetworkedNode root = (NetworkedNode) routingContext.get(NetworkedNode.class.getName());
if (root == null) {
root = engine.getNodeService().getRootNetworkedNode();
routingContext.put(NetworkedNode.class.getName(), root);
}
return root;
}
use of org.jumpmind.symmetric.model.NetworkedNode in project symmetric-ds by JumpMind.
the class ReportStatusJob method doJob.
@Override
void doJob(boolean force) throws Exception {
NetworkedNode remote = engine.getNodeService().getRootNetworkedNode();
Node identity = engine.getNodeService().findIdentity();
if (remote.getNode().getNodeId().equals(identity.getNodeId())) {
log.debug("Skipping report status job because this node is the root node. identity={}, remote={}", identity, remote);
return;
}
Map<String, Integer> batchCountPerChannel = engine.getOutgoingBatchService().countOutgoingBatchesPendingByChannel(remote.getNode().getNodeId());
log.debug("identity={} batchCountPerChannel='{}', lastBatchCountPerChannel='{}'", identity, batchCountPerChannel, lastBatchCountPerChannel);
if (force || shouldSendStatus(batchCountPerChannel)) {
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put(WebConstants.BATCH_TO_SEND_COUNT, TransportUtils.toCSV(batchCountPerChannel));
engine.getTransportManager().sendStatusRequest(identity, requestParams);
updateLastSentStatus(batchCountPerChannel);
}
}
use of org.jumpmind.symmetric.model.NetworkedNode 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.NetworkedNode in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouter method routeToNodes.
@SuppressWarnings("unchecked")
public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> possibleTargetNodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
possibleTargetNodes = filterOutOlderNodes(dataMetaData, possibleTargetNodes);
possibleTargetNodes = filterOutNodesByDeploymentType(dataMetaData, possibleTargetNodes);
// the list of nodeIds that we will return
Set<String> nodeIds = new HashSet<String>();
// the inbound data
Map<String, String> columnValues = getDataMap(dataMetaData, engine != null ? engine.getSymmetricDialect() : null);
Node me = findIdentity();
if (me != null) {
NetworkedNode rootNetworkedNode = getRootNetworkNodeFromContext(routingContext);
if (tableMatches(dataMetaData, TableConstants.SYM_NODE) && dataMetaData.getData().getDataEventType().equals(DataEventType.SQL) && dataMetaData.getData().getParsedData(CsvData.ROW_DATA).length > 1 && dataMetaData.getData().getParsedData(CsvData.ROW_DATA)[0].toUpperCase().contains("TABLE")) {
routingContext.put(CTX_KEY_RESYNC_NEEDED, Boolean.TRUE);
routeNodeTables(nodeIds, columnValues, rootNetworkedNode, me, routingContext, dataMetaData, possibleTargetNodes, initialLoad);
} else if (tableMatches(dataMetaData, TableConstants.SYM_NODE) || tableMatches(dataMetaData, TableConstants.SYM_NODE_SECURITY) || tableMatches(dataMetaData, TableConstants.SYM_NODE_HOST) || tableMatches(dataMetaData, TableConstants.SYM_MONITOR_EVENT)) {
if (tableMatches(dataMetaData, TableConstants.SYM_NODE)) {
routingContext.put(CTX_KEY_FLUSH_NODES_NEEDED, Boolean.TRUE);
} else if (tableMatches(dataMetaData, TableConstants.SYM_NODE_SECURITY)) {
routingContext.put(CTX_KEY_FLUSH_NODE_SECURITYS_NEEDED, Boolean.TRUE);
}
/*
* If this is sym_node or sym_node_security determine which
* nodes it goes to.
*/
routeNodeTables(nodeIds, columnValues, rootNetworkedNode, me, routingContext, dataMetaData, possibleTargetNodes, initialLoad);
} else if (tableMatches(dataMetaData, TableConstants.SYM_TABLE_RELOAD_REQUEST)) {
String sourceNodeId = columnValues.get("SOURCE_NODE_ID");
String reloadEnabled = columnValues.get("RELOAD_ENABLED");
if (me.getNodeId().equals(sourceNodeId)) {
if ("1".equals(reloadEnabled)) {
List<TableReloadRequestKey> list = (List<TableReloadRequestKey>) routingContext.get(CTX_KEY_TABLE_RELOAD_NEEDED);
if (list == null) {
list = new ArrayList<TableReloadRequestKey>();
routingContext.put(CTX_KEY_TABLE_RELOAD_NEEDED, list);
}
String targetNodeId = columnValues.get("TARGET_NODE_ID");
String routerId = columnValues.get("ROUTER_ID");
String triggerId = columnValues.get("TRIGGER_ID");
list.add(new TableReloadRequestKey(targetNodeId, sourceNodeId, triggerId, routerId, dataMetaData.getData().getSourceNodeId()));
}
} else {
for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeThatMayBeRoutedTo.requires13Compatiblity() && nodeThatMayBeRoutedTo.getNodeId().equals(sourceNodeId)) {
nodeIds.add(sourceNodeId);
}
}
}
} else {
IConfigurationService configurationService = engine.getConfigurationService();
for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeThatMayBeRoutedTo.requires13Compatiblity() && (initialLoad || !isSameNumberOfLinksAwayFromRoot(nodeThatMayBeRoutedTo, rootNetworkedNode, me))) {
NodeGroupLink link = configurationService.getNodeGroupLinkFor(me.getNodeGroupId(), nodeThatMayBeRoutedTo.getNodeGroupId(), false);
if (initialLoad || (link != null && link.isSyncConfigEnabled())) {
nodeIds.add(nodeThatMayBeRoutedTo.getNodeId());
}
}
}
if (StringUtils.isBlank(dataMetaData.getData().getSourceNodeId())) {
queueSyncTriggers(routingContext, dataMetaData, columnValues);
}
if (tableMatches(dataMetaData, TableConstants.SYM_CHANNEL)) {
routingContext.put(CTX_KEY_FLUSH_CHANNELS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_CONFLICT)) {
routingContext.put(CTX_KEY_FLUSH_CONFLICTS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_LOAD_FILTER)) {
routingContext.put(CTX_KEY_FLUSH_LOADFILTERS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_PARAMETER)) {
routingContext.put(CTX_KEY_FLUSH_PARAMETERS_NEEDED, Boolean.TRUE);
if (StringUtils.isBlank(dataMetaData.getData().getSourceNodeId()) && (dataMetaData.getData().getRowData() != null && dataMetaData.getData().getRowData().contains("job."))) {
routingContext.put(CTX_KEY_RESTART_JOBMANAGER_NEEDED, Boolean.TRUE);
}
}
if (tableMatches(dataMetaData, TableConstants.SYM_TRANSFORM_COLUMN) || tableMatches(dataMetaData, TableConstants.SYM_TRANSFORM_TABLE)) {
routingContext.put(CTX_KEY_FLUSH_TRANSFORMS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_EXTENSION)) {
routingContext.put(CTX_KEY_REFRESH_EXTENSIONS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_MONITOR)) {
routingContext.put(CTX_KEY_FLUSH_MONITORS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_NOTIFICATION)) {
routingContext.put(CTX_KEY_FLUSH_NOTIFICATIONS_NEEDED, Boolean.TRUE);
}
}
}
return nodeIds;
}
use of org.jumpmind.symmetric.model.NetworkedNode in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouter method isLinked.
private boolean isLinked(String nodeIdInQuestion, Node nodeThatCouldBeRoutedTo, NetworkedNode root, Node me, List<NodeGroupLink> allLinks) {
if (root != null) {
if (nodeIdInQuestion != null && nodeThatCouldBeRoutedTo != null && !nodeIdInQuestion.equals(nodeThatCouldBeRoutedTo.getNodeId())) {
NetworkedNode networkedNodeInQuestion = root.findNetworkedNode(nodeIdInQuestion);
NetworkedNode networkedNodeThatCouldBeRoutedTo = root.findNetworkedNode(nodeThatCouldBeRoutedTo.getNodeId());
if (networkedNodeInQuestion != null) {
if (networkedNodeInQuestion.isInParentHierarchy(nodeThatCouldBeRoutedTo.getNodeId())) {
// always route changes to parent nodes
return true;
}
String createdAtNodeId = networkedNodeInQuestion.getNode().getCreatedAtNodeId();
if (createdAtNodeId != null && !createdAtNodeId.equals(me.getNodeId()) && !networkedNodeInQuestion.getNode().getNodeId().equals(me.getNodeId())) {
if (createdAtNodeId.equals(nodeThatCouldBeRoutedTo.getNodeId())) {
return true;
} else if (networkedNodeThatCouldBeRoutedTo != null) {
// to get that update back to that node
return networkedNodeThatCouldBeRoutedTo.isInChildHierarchy(createdAtNodeId);
}
}
// if we haven't found a place to route by now, then we need
// to
// send the row to all nodes that have links to the node's
// group
String groupId = networkedNodeInQuestion.getNode().getNodeGroupId();
Set<String> groupsThatWillBeInterested = new HashSet<String>();
for (NodeGroupLink nodeGroupLink : allLinks) {
if (nodeGroupLink.getTargetNodeGroupId().equals(groupId)) {
groupsThatWillBeInterested.add(nodeGroupLink.getSourceNodeGroupId());
} else if (nodeGroupLink.getSourceNodeGroupId().equals(groupId)) {
groupsThatWillBeInterested.add(nodeGroupLink.getTargetNodeGroupId());
}
}
if (groupsThatWillBeInterested.contains(nodeThatCouldBeRoutedTo.getNodeGroupId())) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
}
Aggregations