Search in sources :

Example 31 with TriggerRouter

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

the class RouterService method onlyDefaultRoutersAssigned.

protected boolean onlyDefaultRoutersAssigned(Channel channel, String nodeGroupId, List<TriggerRouter> triggerRouters) {
    String channelId = channel.getChannelId();
    Boolean onlyDefaultRoutersAssigned = defaultRouterOnlyLastKnownState.get(channelId);
    long cacheTime = parameterService.getLong(ParameterConstants.CACHE_CHANNEL_DEFAULT_ROUTER_IN_MS);
    if (onlyDefaultRoutersAssigned == null || System.currentTimeMillis() - defaultRoutersCacheTime > cacheTime) {
        onlyDefaultRoutersAssigned = !Constants.CHANNEL_CONFIG.equals(channelId) && !channel.isFileSyncFlag() && !channel.isReloadFlag() && !Constants.CHANNEL_HEARTBEAT.equals(channelId) ? true : false;
        if (onlyDefaultRoutersAssigned && triggerRouters != null) {
            for (TriggerRouter triggerRouter : triggerRouters) {
                if (triggerRouter.getTrigger().getChannelId().equals(channel.getChannelId()) && triggerRouter.getRouter().getNodeGroupLink().getSourceNodeGroupId().equals(nodeGroupId) && !"default".equals(triggerRouter.getRouter().getRouterType())) {
                    onlyDefaultRoutersAssigned = false;
                }
            }
        }
        if (!onlyDefaultRoutersAssigned.equals(defaultRouterOnlyLastKnownState.get(channelId))) {
            if (onlyDefaultRoutersAssigned) {
                log.info("The '{}' channel for the '{}' node group has only default routers assigned to it.  Change data won't be selected during routing", channelId, nodeGroupId);
            }
            defaultRouterOnlyLastKnownState.put(channelId, onlyDefaultRoutersAssigned);
        }
        defaultRoutersCacheTime = System.currentTimeMillis();
    }
    return onlyDefaultRoutersAssigned;
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter)

Example 32 with TriggerRouter

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

the class RouterService method findAvailableNodes.

protected Set<Node> findAvailableNodes(TriggerRouter triggerRouter, ChannelRouterContext context) {
    Set<Node> nodes = context.getAvailableNodes().get(triggerRouter);
    if (nodes == null) {
        nodes = new HashSet<Node>();
        Router router = triggerRouter.getRouter();
        NodeGroupLink link = engine.getConfigurationService().getNodeGroupLinkFor(router.getNodeGroupLink().getSourceNodeGroupId(), router.getNodeGroupLink().getTargetNodeGroupId(), false);
        if (link != null) {
            nodes.addAll(engine.getNodeService().findEnabledNodesFromNodeGroup(router.getNodeGroupLink().getTargetNodeGroupId()));
        } else {
            log.error("The router {} has no node group link configured from {} to {}", new Object[] { router.getRouterId(), router.getNodeGroupLink().getSourceNodeGroupId(), router.getNodeGroupLink().getTargetNodeGroupId() });
        }
        context.getAvailableNodes().put(triggerRouter, nodes);
    }
    return engine.getGroupletService().getTargetEnabled(triggerRouter, nodes);
}
Also used : Node(org.jumpmind.symmetric.model.Node) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) AuditTableDataRouter(org.jumpmind.symmetric.route.AuditTableDataRouter) LookupTableDataRouter(org.jumpmind.symmetric.route.LookupTableDataRouter) AbstractFileParsingRouter(org.jumpmind.symmetric.route.AbstractFileParsingRouter) ConfigurationChangedDataRouter(org.jumpmind.symmetric.route.ConfigurationChangedDataRouter) SubSelectDataRouter(org.jumpmind.symmetric.route.SubSelectDataRouter) FileSyncDataRouter(org.jumpmind.symmetric.route.FileSyncDataRouter) ColumnMatchDataRouter(org.jumpmind.symmetric.route.ColumnMatchDataRouter) Router(org.jumpmind.symmetric.model.Router) DefaultDataRouter(org.jumpmind.symmetric.route.DefaultDataRouter) BshDataRouter(org.jumpmind.symmetric.route.BshDataRouter) IDataRouter(org.jumpmind.symmetric.route.IDataRouter) DBFRouter(org.jumpmind.symmetric.route.DBFRouter) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Example 33 with TriggerRouter

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

the class DbCompare method getTriggerRouterFor.

protected TriggerRouter getTriggerRouterFor(Table sourceTable) {
    // TODO get routers.
    Set<TriggerRouter> triggerRouters = sourceEngine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(sourceTable.getCatalog(), sourceTable.getSchema(), sourceTable.getName(), false);
    for (TriggerRouter triggerRouter : triggerRouters) {
        String routerTargetNodeGroupId = triggerRouter.getRouter().getNodeGroupLink().getTargetNodeGroupId();
        String compareTargetNodeGroupId = targetEngine.getNodeService().getCachedIdentity().getNodeGroupId();
        if (StringUtils.equals(compareTargetNodeGroupId, routerTargetNodeGroupId)) {
            return triggerRouter;
        }
    }
    return null;
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter)

Example 34 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter 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 35 with TriggerRouter

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

the class DataService method insertLoadBatchesForReload.

private void insertLoadBatchesForReload(Node targetNode, long loadId, String createBy, List<TriggerHistory> triggerHistories, Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId, boolean transactional, ISqlTransaction transaction, Map<String, TableReloadRequest> reloadRequests, ProcessInfo processInfo) {
    Map<String, Channel> channels = engine.getConfigurationService().getChannels(false);
    for (TriggerHistory triggerHistory : triggerHistories) {
        List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
        processInfo.incrementCurrentDataCount();
        for (TriggerRouter triggerRouter : triggerRouters) {
            if (triggerRouter.getInitialLoadOrder() >= 0 && engine.getGroupletService().isTargetEnabled(triggerRouter, targetNode)) {
                String selectSql = null;
                if (reloadRequests != null) {
                    TableReloadRequest reloadRequest = reloadRequests.get(triggerRouter.getTriggerId() + triggerRouter.getRouterId());
                    selectSql = reloadRequest != null ? reloadRequest.getReloadSelect() : null;
                }
                if (StringUtils.isBlank(selectSql)) {
                    selectSql = StringUtils.isBlank(triggerRouter.getInitialLoadSelect()) ? Constants.ALWAYS_TRUE_CONDITION : triggerRouter.getInitialLoadSelect();
                }
                if (parameterService.is(ParameterConstants.INITIAL_LOAD_USE_EXTRACT_JOB)) {
                    Trigger trigger = triggerRouter.getTrigger();
                    String reloadChannel = getReloadChannelIdForTrigger(trigger, channels);
                    Channel channel = channels.get(reloadChannel);
                    Table table = platform.getTableFromCache(triggerHistory.getSourceCatalogName(), triggerHistory.getSourceSchemaName(), triggerHistory.getSourceTableName(), false);
                    processInfo.setCurrentTableName(table.getName());
                    int numberOfBatches = getNumberOfReloadBatches(table, triggerRouter, channel, targetNode, selectSql);
                    long startBatchId = -1;
                    long endBatchId = -1;
                    for (int i = 0; i < numberOfBatches; i++) {
                        // needs to grab the start and end batch id
                        endBatchId = insertReloadEvent(transaction, targetNode, triggerRouter, triggerHistory, selectSql, true, loadId, createBy, Status.RQ);
                        if (startBatchId == -1) {
                            startBatchId = endBatchId;
                        }
                    }
                    engine.getDataExtractorService().requestExtractRequest(transaction, targetNode.getNodeId(), channel.getQueue(), triggerRouter, startBatchId, endBatchId);
                } else {
                    insertReloadEvent(transaction, targetNode, triggerRouter, triggerHistory, selectSql, true, loadId, createBy, Status.NE);
                }
                if (!transactional) {
                    transaction.commit();
                }
            }
        }
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) Table(org.jumpmind.db.model.Table) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Channel(org.jumpmind.symmetric.model.Channel) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) TableReloadRequest(org.jumpmind.symmetric.model.TableReloadRequest)

Aggregations

TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)64 ArrayList (java.util.ArrayList)22 Trigger (org.jumpmind.symmetric.model.Trigger)20 Router (org.jumpmind.symmetric.model.Router)18 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)13 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)12 Test (org.junit.Test)12 List (java.util.List)10 Node (org.jumpmind.symmetric.model.Node)8 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)7 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)7 Table (org.jumpmind.db.model.Table)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Data (org.jumpmind.symmetric.model.Data)5 TableReloadRequest (org.jumpmind.symmetric.model.TableReloadRequest)5 ConfigurationChangedDataRouter (org.jumpmind.symmetric.route.ConfigurationChangedDataRouter)4 FileSyncDataRouter (org.jumpmind.symmetric.route.FileSyncDataRouter)4