Skip to content

Commit

Permalink
0005198: table constants for version each table introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Jan 21, 2022
1 parent 971344d commit 9a7598c
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 195 deletions.
Expand Up @@ -32,6 +32,7 @@
import org.jumpmind.symmetric.io.stage.IStagedResource;
import org.jumpmind.symmetric.job.IJobManager;
import org.jumpmind.symmetric.model.JobDefinition;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.model.OutgoingBatch;
import org.jumpmind.symmetric.model.Trigger;
import org.jumpmind.symmetric.service.ClusterConstants;
Expand Down Expand Up @@ -64,10 +65,12 @@ public class ConfigurationChangedHelper {
private static final String CTX_KEY_CLUSTER_NEEDED = "ClusterEnable." + SUFFIX;
private ISymmetricEngine engine;
private String tablePrefix;
private ConfigurationVersionHelper versionHelper;

public ConfigurationChangedHelper(ISymmetricEngine engine) {
this.engine = engine;
tablePrefix = engine.getTablePrefix();
versionHelper = new ConfigurationVersionHelper(tablePrefix);
}

public void handleChange(Context context, Table table, CsvData data) {
Expand Down Expand Up @@ -318,4 +321,8 @@ public boolean isSyncTriggersAllowed(Context context) {
public void setSyncTriggersNeeded(Context context) {
context.put(CTX_KEY_RESYNC_NEEDED, true);
}

public Set<Node> filterNodes(Set<Node> nodes, String tableName) {
return versionHelper.filterNodes(nodes, tableName);
}
}
@@ -0,0 +1,79 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jumpmind.symmetric.common;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.jumpmind.symmetric.Version;
import org.jumpmind.symmetric.model.Node;

public class ConfigurationVersionHelper {
protected Set<String> proTables;
protected Map<String, String> tablesByVersion;
protected boolean isTargetNodePro;
protected String targetNodeVersion;

public ConfigurationVersionHelper(String tablePrefix) {
proTables = TableConstants.getTablesForConsole(tablePrefix);
tablesByVersion = TableConstants.getConfigTablesByVersion(tablePrefix);
}

public ConfigurationVersionHelper(String tablePrefix, Node targetNode) {
this(tablePrefix);
setTargetNode(targetNode);
}

public boolean shouldSendTable(String tableName) {
if (!isTargetNodePro && proTables.contains(tableName)) {
return false;
}
String tableVersion = tablesByVersion.get(tableName);
if (tableVersion != null && Version.isOlderThanVersion(targetNodeVersion, tableVersion)) {
return false;
}
return true;
}

public Set<Node> filterNodes(Set<Node> nodes, String tableName) {
boolean isProTable = proTables.contains(tableName);
String tableVersion = tablesByVersion.get(tableName);
if (isProTable || tableVersion != null) {
Set<Node> targetNodes = new HashSet<Node>(nodes.size());
for (Node node : nodes) {
setTargetNode(node);
if ((!isProTable || isTargetNodePro) && (tableVersion == null || !Version.isOlderThanVersion(targetNodeVersion, tableVersion))) {
targetNodes.add(node);
}
}
return targetNodes;
} else {
return nodes;
}
}

public void setTargetNode(Node targetNode) {
targetNodeVersion = targetNode.getSymmetricVersion();
isTargetNodePro = StringUtils.equals(targetNode.getDeploymentType(), Constants.DEPLOYMENT_TYPE_PROFESSIONAL);
}
}
Expand Up @@ -22,8 +22,10 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -81,7 +83,6 @@ public class TableConstants {
public static final String SYM_CONSOLE_TABLE_STATS = "console_table_stats";
public static final String SYM_DESIGN_DIAGRAM = "design_diagram";
public static final String SYM_DIAGRAM_GROUP = "diagram_group";
public static final String SYM_DIAGRAM_GROUP_LINK = "diagram_group_link";
public static final String SYM_EXTENSION = "extension";
public static final String SYM_MONITOR = "monitor";
public static final String SYM_MONITOR_EVENT = "monitor_event";
Expand All @@ -104,12 +105,21 @@ public static final Set<String> getTables(String tablePrefix) {
SYM_REGISTRATION_REDIRECT, SYM_REGISTRATION_REQUEST, SYM_ROUTER, SYM_SEQUENCE, SYM_TABLE_RELOAD_REQUEST, SYM_TABLE_RELOAD_STATUS,
SYM_TRANSFORM_TABLE, SYM_TRANSFORM_COLUMN, SYM_TRIGGER, SYM_TRIGGER_HIST, SYM_TRIGGER_ROUTER, SYM_TRIGGER_ROUTER_GROUPLET);
if (hasConsoleSchema) {
addPrefixToTableNames(tables, tablePrefix, SYM_CONSOLE_EVENT, SYM_CONSOLE_USER, SYM_CONSOLE_USER_HIST, SYM_CONSOLE_ROLE,
SYM_CONSOLE_ROLE_PRIVILEGE, SYM_CONSOLE_TABLE_STATS, SYM_DESIGN_DIAGRAM, SYM_DIAGRAM_GROUP);
tables.addAll(getTablesForConsole(tablePrefix));
}
return tables;
}

/**
* Set of all SymmetricDS configuration and runtime tables used in professional console.
*/
public static final Set<String> getTablesForConsole(String tablePrefix) {
Set<String> tables = new HashSet<String>();
addPrefixToTableNames(tables, tablePrefix, SYM_CONSOLE_EVENT, SYM_CONSOLE_USER, SYM_CONSOLE_USER_HIST, SYM_CONSOLE_ROLE,
SYM_CONSOLE_ROLE_PRIVILEGE, SYM_CONSOLE_TABLE_STATS, SYM_DESIGN_DIAGRAM, SYM_DIAGRAM_GROUP);
return tables;
}

public static final Set<String> getTablesWithoutPrefix() {
return getTables("");
}
Expand All @@ -132,6 +142,23 @@ public static final List<String> getConfigTables(String tablePrefix) {
return tables;
}

/**
* Map with key of each configuration table and value of the SymmetricDS version when they were introduced.
*/
public static final Map<String, String> getConfigTablesByVersion(String tablePrefix) {
Map<String, String> map = new HashMap<String, String>();
addPrefixToTableNames(map, tablePrefix, "3.3.0", SYM_GROUPLET, SYM_GROUPLET_LINK, SYM_TRIGGER_ROUTER_GROUPLET);
addPrefixToTableNames(map, tablePrefix, "3.5.0", SYM_FILE_TRIGGER, SYM_FILE_TRIGGER_ROUTER, SYM_FILE_SNAPSHOT, SYM_EXTRACT_REQUEST,
SYM_NODE_GROUP_CHANNEL_WND);
addPrefixToTableNames(map, tablePrefix, "3.7.0", SYM_EXTENSION);
addPrefixToTableNames(map, tablePrefix, "3.8.0", SYM_NOTIFICATION, SYM_MONITOR, SYM_MONITOR_EVENT, SYM_CONSOLE_EVENT);
addPrefixToTableNames(map, tablePrefix, "3.8.18", SYM_CONSOLE_USER_HIST);
addPrefixToTableNames(map, tablePrefix, "3.9.0", SYM_JOB);
addPrefixToTableNames(map, tablePrefix, "3.10.0", SYM_TABLE_RELOAD_STATUS);
addPrefixToTableNames(map, tablePrefix, "3.12.0", SYM_CONSOLE_ROLE, SYM_CONSOLE_ROLE_PRIVILEGE, SYM_DESIGN_DIAGRAM, SYM_DIAGRAM_GROUP);
return map;
}

/**
* Which tables from getConfigTables() should not be sent during registration. These tables will still have a trigger installed for capturing and sending
* changes.
Expand All @@ -154,8 +181,8 @@ public static final Set<String> getConfigTablesWithoutCapture(String tablePrefix
* Which tables from getConfigTables() should be excluded from a configuration export.
*/
public static final String[] getConfigTablesExcludedFromExport() {
return new String[] { SYM_NODE, SYM_NODE_SECURITY, SYM_NODE_IDENTITY, SYM_NODE_HOST, SYM_NODE_CHANNEL_CTL, SYM_FILE_SNAPSHOT, SYM_CONSOLE_USER,
SYM_CONSOLE_ROLE, SYM_CONSOLE_ROLE_PRIVILEGE, SYM_CONSOLE_USER_HIST, SYM_TABLE_RELOAD_REQUEST, SYM_CONSOLE_EVENT, SYM_MONITOR_EVENT };
return new String[] { SYM_NODE, SYM_NODE_SECURITY, SYM_NODE_IDENTITY, SYM_NODE_HOST, SYM_FILE_SNAPSHOT, SYM_CONSOLE_USER,
SYM_CONSOLE_ROLE, SYM_CONSOLE_ROLE_PRIVILEGE, SYM_CONSOLE_USER_HIST, SYM_TABLE_RELOAD_REQUEST, SYM_MONITOR_EVENT };
}

/**
Expand All @@ -169,6 +196,12 @@ public static final List<String> getConfigTablesForExport(String tablePrefix) {
return tables;
}

protected static final void addPrefixToTableNames(Map<String, String> map, String tablePrefix, String version, String... names) {
for (String name : names) {
map.put(getTableName(tablePrefix, name), version);
}
}

protected static final void addPrefixToTableNames(Collection<String> collection, String tablePrefix, String... names) {
for (String name : names) {
collection.add(getTableName(tablePrefix, name));
Expand Down
Expand Up @@ -27,7 +27,6 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.extension.IBuiltInExtensionPoint;
import org.jumpmind.symmetric.ISymmetricEngine;
Expand Down Expand Up @@ -67,8 +66,7 @@ public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData
engine.getParameterService().is(ParameterConstants.AUTO_SYNC_TRIGGERS_AFTER_CONFIG_CHANGED));
}
helper.handleChange(routingContext, dataMetaData.getTable(), dataMetaData.getData());
possibleTargetNodes = filterOutOlderNodes(dataMetaData, possibleTargetNodes);
possibleTargetNodes = filterOutNodesByDeploymentType(dataMetaData, possibleTargetNodes);
possibleTargetNodes = helper.filterNodes(possibleTargetNodes, tableName(dataMetaData.getTable().getNameLowerCase()));
// the list of nodeIds that we will return
Set<String> nodeIds = new HashSet<String>();
// the inbound data
Expand Down Expand Up @@ -237,59 +235,6 @@ private TriggerRouter findTriggerRouter(List<TriggerRouter> triggerRouters, Stri
return null;
}

protected Set<Node> filterOutNodesByDeploymentType(DataMetaData dataMetaData, Set<Node> possibleTargetNodes) {
if (tableMatches(dataMetaData, TableConstants.SYM_CONSOLE_USER)
|| tableMatches(dataMetaData, TableConstants.SYM_CONSOLE_USER_HIST)
|| tableMatches(dataMetaData, TableConstants.SYM_CONSOLE_ROLE)
|| tableMatches(dataMetaData, TableConstants.SYM_CONSOLE_ROLE_PRIVILEGE)
|| tableMatches(dataMetaData, TableConstants.SYM_DESIGN_DIAGRAM)
|| tableMatches(dataMetaData, TableConstants.SYM_DIAGRAM_GROUP)) {
Set<Node> targetNodes = new HashSet<Node>(possibleTargetNodes.size());
for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
boolean isTargetProfessional = StringUtils.equals(nodeThatMayBeRoutedTo.getDeploymentType(),
Constants.DEPLOYMENT_TYPE_PROFESSIONAL);
if (isTargetProfessional) {
targetNodes.add(nodeThatMayBeRoutedTo);
}
}
return targetNodes;
} else {
return possibleTargetNodes;
}
}

protected Set<Node> filterOutOlderNodes(DataMetaData dataMetaData, Set<Node> possibleTargetNodes) {
if (tableMatches(dataMetaData, TableConstants.SYM_MONITOR)
|| tableMatches(dataMetaData, TableConstants.SYM_MONITOR_EVENT)
|| tableMatches(dataMetaData, TableConstants.SYM_NOTIFICATION)
|| tableMatches(dataMetaData, TableConstants.SYM_JOB)
|| tableMatches(dataMetaData, TableConstants.SYM_CONSOLE_ROLE)
|| tableMatches(dataMetaData, TableConstants.SYM_CONSOLE_ROLE_PRIVILEGE)
|| tableMatches(dataMetaData, TableConstants.SYM_DIAGRAM_GROUP)
|| tableMatches(dataMetaData, TableConstants.SYM_DESIGN_DIAGRAM)) {
Set<Node> targetNodes = new HashSet<Node>(possibleTargetNodes.size());
for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
if (tableMatches(dataMetaData, TableConstants.SYM_JOB)) {
if (nodeThatMayBeRoutedTo.isVersionGreaterThanOrEqualTo(3, 9, 0)) {
targetNodes.add(nodeThatMayBeRoutedTo);
}
} else if (tableMatches(dataMetaData, TableConstants.SYM_CONSOLE_ROLE)
|| tableMatches(dataMetaData, TableConstants.SYM_CONSOLE_ROLE_PRIVILEGE)
|| tableMatches(dataMetaData, TableConstants.SYM_DIAGRAM_GROUP)
|| tableMatches(dataMetaData, TableConstants.SYM_DESIGN_DIAGRAM)) {
if (nodeThatMayBeRoutedTo.isVersionGreaterThanOrEqualTo(3, 12, 0)) {
targetNodes.add(nodeThatMayBeRoutedTo);
}
} else if (nodeThatMayBeRoutedTo.isVersionGreaterThanOrEqualTo(3, 8, 0)) {
targetNodes.add(nodeThatMayBeRoutedTo);
}
}
return targetNodes;
} else {
return possibleTargetNodes;
}
}

protected void routeNodeTables(Set<String> nodeIds, Map<String, String> columnValues,
NetworkedNode rootNetworkedNode, Node me, SimpleRouterContext routingContext,
DataMetaData dataMetaData, Set<Node> possibleTargetNodes, boolean initialLoad) {
Expand Down

0 comments on commit 9a7598c

Please sign in to comment.