Search in sources :

Example 76 with Node

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

the class LookupTableDataRouter method routeToNodes.

public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
    Set<String> nodeIds = null;
    Router router = dataMetaData.getRouter();
    Map<String, String> params = null;
    params = getParams(router, routingContext);
    Map<String, String> dataMap = getDataMap(dataMetaData, symmetricDialect);
    Map<String, Set<String>> lookupTable = getLookupTable(params, router, routingContext);
    String column = params.get(PARAM_KEY_COLUMN);
    if (dataMap.containsKey(column)) {
        String keyData = dataMap.get(column);
        Set<String> externalIds = lookupTable.get(keyData);
        if (externalIds != null) {
            for (Node node : nodes) {
                if (externalIds.contains(node.getExternalId())) {
                    nodeIds = addNodeId(node.getNodeId(), nodeIds, nodes);
                }
            }
        }
    } else {
        log.error("Could not route data with an id of {} using the {} router because the column {} was not captured for the {} table", new Object[] { dataMetaData.getData().getDataId(), getClass().getSimpleName(), column, dataMetaData.getTable().getName() });
    }
    return nodeIds;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter)

Example 77 with Node

use of org.jumpmind.symmetric.model.Node 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;
}
Also used : TableReloadRequestKey(org.jumpmind.symmetric.model.TableReloadRequestKey) Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) ArrayList(java.util.ArrayList) List(java.util.List) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) HashSet(java.util.HashSet)

Example 78 with Node

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

the class ColumnMatchDataRouter method routeToNodes.

public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
    Set<String> nodeIds = null;
    if (initialLoadSelectUsed && initialLoad) {
        nodeIds = toNodeIds(nodes, null);
    } else {
        List<Expression> expressions = getExpressions(dataMetaData.getRouter(), routingContext);
        Map<String, String> columnValues = getDataMap(dataMetaData, symmetricDialect);
        if (columnValues != null) {
            for (Expression e : expressions) {
                String column = e.tokens[0].trim();
                String value = e.tokens[1];
                String columnValue = columnValues.get(column);
                if (value.equalsIgnoreCase(TokenConstants.NODE_ID)) {
                    for (Node node : nodes) {
                        nodeIds = runExpression(e, columnValue, node.getNodeId(), nodes, nodeIds, node);
                    }
                } else if (value.equalsIgnoreCase(TokenConstants.EXTERNAL_ID)) {
                    for (Node node : nodes) {
                        nodeIds = runExpression(e, columnValue, node.getExternalId(), nodes, nodeIds, node);
                    }
                } else if (value.equalsIgnoreCase(TokenConstants.NODE_GROUP_ID)) {
                    for (Node node : nodes) {
                        nodeIds = runExpression(e, columnValue, node.getNodeGroupId(), nodes, nodeIds, node);
                    }
                } else if (e.hasEquals && value.equalsIgnoreCase(TokenConstants.REDIRECT_NODE)) {
                    Map<String, String> redirectMap = getRedirectMap(routingContext);
                    String nodeId = redirectMap.get(columnValue);
                    if (nodeId != null) {
                        nodeIds = addNodeId(nodeId, nodeIds, nodes);
                    }
                } else {
                    String compareValue = value;
                    if (value.equalsIgnoreCase(TokenConstants.EXTERNAL_DATA)) {
                        compareValue = dataMetaData.getData().getExternalData();
                    } else if (value.startsWith(":")) {
                        compareValue = columnValues.get(value.substring(1));
                    } else if (value.equals(NULL_VALUE)) {
                        compareValue = null;
                    }
                    nodeIds = runExpression(e, columnValue, compareValue, nodes, nodeIds, null);
                }
            }
        } else {
            log.warn("There were no columns to match for the data_id of {}", dataMetaData.getData().getDataId());
        }
    }
    if (nodeIds != null) {
        nodeIds.remove(null);
    } else {
        nodeIds = Collections.emptySet();
    }
    return nodeIds;
}
Also used : Node(org.jumpmind.symmetric.model.Node) Map(java.util.Map)

Example 79 with Node

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

the class ConfigurationService method isMasterToMasterOnly.

@Override
public boolean isMasterToMasterOnly() {
    Node me = nodeService.findIdentity();
    int masterCount = 0;
    int otherCount = 0;
    if (me != null) {
        for (NodeGroupLink nodeGroupLink : getNodeGroupLinksFor(me.getNodeGroupId(), false)) {
            if (nodeGroupLink.getTargetNodeGroupId().equals(me.getNodeGroupId())) {
                masterCount++;
            } else {
                otherCount++;
            }
        }
    }
    return masterCount > 1 && otherCount == 0;
}
Also used : Node(org.jumpmind.symmetric.model.Node) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Example 80 with Node

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

the class DataLoaderService method buildDataWriter.

protected IDataWriter buildDataWriter(ProcessInfo processInfo, String sourceNodeId, String channelId, long batchId, boolean isRetry) {
    TransformTable[] transforms = null;
    NodeGroupLink link = null;
    List<ResolvedData> resolvedDatas = new ArrayList<ResolvedData>();
    List<IDatabaseWriterFilter> filters = extensionService.getExtensionPointList(IDatabaseWriterFilter.class);
    List<IDatabaseWriterFilter> dynamicFilters = filters;
    List<IDatabaseWriterErrorHandler> errorHandlers = extensionService.getExtensionPointList(IDatabaseWriterErrorHandler.class);
    List<IDatabaseWriterErrorHandler> dynamicErrorHandlers = errorHandlers;
    if (sourceNodeId != null) {
        Node sourceNode = nodeService.findNode(sourceNodeId, true);
        if (sourceNode != null) {
            link = new NodeGroupLink(sourceNode.getNodeGroupId(), parameterService.getNodeGroupId());
        }
        Map<LoadFilterType, Map<String, List<LoadFilter>>> loadFilters = loadFilterService.findLoadFiltersFor(link, true);
        List<DynamicDatabaseWriterFilter> databaseWriterFilters = DynamicDatabaseWriterFilter.getDatabaseWriterFilters(engine, loadFilters);
        if (loadFilters != null && loadFilters.size() > 0) {
            dynamicFilters = new ArrayList<IDatabaseWriterFilter>(filters.size() + 1);
            dynamicFilters.addAll(filters);
            dynamicFilters.addAll(databaseWriterFilters);
            dynamicErrorHandlers = new ArrayList<IDatabaseWriterErrorHandler>(errorHandlers.size() + 1);
            dynamicErrorHandlers.addAll(errorHandlers);
            dynamicErrorHandlers.addAll(databaseWriterFilters);
        }
        List<TransformTableNodeGroupLink> transformsList = transformService.findTransformsFor(link, TransformPoint.LOAD);
        transforms = transformsList != null ? transformsList.toArray(new TransformTable[transformsList.size()]) : null;
        if (isRetry) {
            List<IncomingError> incomingErrors = getIncomingErrors(batchId, sourceNodeId);
            for (IncomingError incomingError : incomingErrors) {
                if (incomingError.isResolveIgnore() || StringUtils.isNotBlank(incomingError.getResolveData())) {
                    resolvedDatas.add(new ResolvedData(incomingError.getFailedRowNumber(), incomingError.getResolveData(), incomingError.isResolveIgnore()));
                }
            }
        }
    }
    TransformWriter transformWriter = new TransformWriter(platform, TransformPoint.LOAD, null, transformService.getColumnTransforms(), transforms);
    IDataWriter targetWriter = getFactory(channelId).getDataWriter(sourceNodeId, symmetricDialect, transformWriter, dynamicFilters, dynamicErrorHandlers, getConflictSettingsNodeGroupLinks(link, false), resolvedDatas);
    transformWriter.setNestedWriter(new ProcessInfoDataWriter(targetWriter, processInfo));
    return transformWriter;
}
Also used : ResolvedData(org.jumpmind.symmetric.io.data.writer.ResolvedData) Node(org.jumpmind.symmetric.model.Node) ArrayList(java.util.ArrayList) TransformTable(org.jumpmind.symmetric.io.data.transform.TransformTable) DynamicDatabaseWriterFilter(org.jumpmind.symmetric.load.DynamicDatabaseWriterFilter) IncomingError(org.jumpmind.symmetric.model.IncomingError) IDatabaseWriterErrorHandler(org.jumpmind.symmetric.io.data.writer.IDatabaseWriterErrorHandler) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) IDatabaseWriterFilter(org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter) ProcessInfoDataWriter(org.jumpmind.symmetric.model.ProcessInfoDataWriter) LoadFilterType(org.jumpmind.symmetric.model.LoadFilter.LoadFilterType) LoadFilter(org.jumpmind.symmetric.model.LoadFilter) TransformWriter(org.jumpmind.symmetric.io.data.writer.TransformWriter) ChannelMap(org.jumpmind.symmetric.model.ChannelMap) Map(java.util.Map) HashMap(java.util.HashMap) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink) IDataWriter(org.jumpmind.symmetric.io.data.IDataWriter)

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