Search in sources :

Example 26 with TriggerRouter

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

the class RouterServiceTest method testProducesCommonBatchesSameTablesTwoChannelsMultipleRoutersDifferentTableIncomingOnAnotherChannel.

@Test
public void testProducesCommonBatchesSameTablesTwoChannelsMultipleRoutersDifferentTableIncomingOnAnotherChannel() {
    List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>();
    Trigger tableTrigger1 = new Trigger("a", CHANNEL_2_TEST.getChannelId(), true);
    Trigger tableTrigger2 = new Trigger("b", "anotherchannel");
    Trigger tableTrigger3 = new Trigger("c", CHANNEL_2_TEST.getChannelId());
    triggerRouters.add(new TriggerRouter(tableTrigger1, new Router("test", SOURCE_NODE_GROUP, TARGET_NODE_GROUP, "default")));
    triggerRouters.add(new TriggerRouter(tableTrigger2, new Router("test", TARGET_NODE_GROUP, SOURCE_NODE_GROUP, "default")));
    triggerRouters.add(new TriggerRouter(tableTrigger3, new Router("test", TARGET_NODE_GROUP, SOURCE_NODE_GROUP, "default")));
    assertTrue(routerService.producesCommonBatches(CHANNEL_2_TEST, SOURCE_NODE_GROUP, triggerRouters));
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) ArrayList(java.util.ArrayList) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Test(org.junit.Test)

Example 27 with TriggerRouter

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

the class RouterServiceTest method testProducesCommonBatchesMultipleTablesTwoChannelsMultipleRoutersBidirectional.

@Test
public void testProducesCommonBatchesMultipleTablesTwoChannelsMultipleRoutersBidirectional() {
    List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>();
    triggerRouters.add(new TriggerRouter(new Trigger("a", CHANNEL_2_TEST.getChannelId()), new Router("test", SOURCE_NODE_GROUP, TARGET_NODE_GROUP, "default")));
    triggerRouters.add(new TriggerRouter(new Trigger("a", CHANNEL_2_TEST.getChannelId()), new Router("test", TARGET_NODE_GROUP, SOURCE_NODE_GROUP, "default")));
    assertTrue(routerService.producesCommonBatches(CHANNEL_2_TEST, SOURCE_NODE_GROUP, triggerRouters));
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) ArrayList(java.util.ArrayList) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Test(org.junit.Test)

Example 28 with TriggerRouter

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

the class RouterServiceTest method testProducesCommonBatchesMultipleTablesTwoChannelsMultipleRouters.

@Test
public void testProducesCommonBatchesMultipleTablesTwoChannelsMultipleRouters() {
    List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>();
    triggerRouters.add(new TriggerRouter(new Trigger("a", CHANNEL_2_TEST.getChannelId()), new Router("test1", SOURCE_NODE_GROUP, TARGET_NODE_GROUP, "default")));
    triggerRouters.add(new TriggerRouter(new Trigger("b", "anotherchannel"), new Router("test2", SOURCE_NODE_GROUP, TARGET_NODE_GROUP, "column")));
    assertTrue(routerService.producesCommonBatches(CHANNEL_2_TEST, SOURCE_NODE_GROUP, triggerRouters));
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) ArrayList(java.util.ArrayList) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Test(org.junit.Test)

Example 29 with TriggerRouter

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

the class RouterService method routeData.

@SuppressWarnings("unchecked")
protected int routeData(ProcessInfo processInfo, Data data, ChannelRouterContext context) {
    int numberOfDataEventsInserted = 0;
    List<TriggerRouter> triggerRouters = getTriggerRoutersForData(data);
    Table table = symmetricDialect.getTable(data.getTriggerHistory(), true);
    if (table == null) {
        table = buildTableFromTriggerHistory(data.getTriggerHistory());
    }
    if (triggerRouters != null && triggerRouters.size() > 0) {
        for (TriggerRouter triggerRouter : triggerRouters) {
            DataMetaData dataMetaData = new DataMetaData(data, table, triggerRouter.getRouter(), context.getChannel());
            Collection<String> nodeIds = null;
            if (!context.getChannel().isIgnoreEnabled() && triggerRouter.isRouted(data.getDataEventType())) {
                String targetNodeIds = data.getNodeList();
                if (StringUtils.isNotBlank(targetNodeIds)) {
                    List<String> targetNodeIdsList = Arrays.asList(targetNodeIds.split(","));
                    nodeIds = CollectionUtils.intersection(targetNodeIdsList, toNodeIds(findAvailableNodes(triggerRouter, context)));
                    if (nodeIds.size() == 0) {
                        log.info("None of the target nodes specified in the data.node_list field ({}) were qualified nodes. Data id {} for table '{}' will not be routed using the {} router", new Object[] { targetNodeIds, data.getDataId(), data.getTableName(), triggerRouter.getRouter().getRouterId() });
                    }
                } else {
                    try {
                        IDataRouter dataRouter = getDataRouter(triggerRouter.getRouter());
                        context.addUsedDataRouter(dataRouter);
                        long ts = System.currentTimeMillis();
                        nodeIds = dataRouter.routeToNodes(context, dataMetaData, findAvailableNodes(triggerRouter, context), false, false, triggerRouter);
                        context.incrementStat(System.currentTimeMillis() - ts, ChannelRouterContext.STAT_DATA_ROUTER_MS);
                    } catch (DelayRoutingException ex) {
                        throw ex;
                    } catch (RuntimeException ex) {
                        StringBuilder failureMessage = new StringBuilder("Failed to route data: ");
                        failureMessage.append(data.getDataId());
                        failureMessage.append(" for table: ");
                        failureMessage.append(data.getTableName());
                        failureMessage.append(".\n");
                        data.writeCsvDataDetails(failureMessage);
                        throw new SymmetricException(failureMessage.toString(), ex);
                    }
                }
                if (nodeIds != null) {
                    if (!triggerRouter.isPingBackEnabled() && data.getSourceNodeId() != null) {
                        nodeIds.remove(data.getSourceNodeId());
                    }
                    // should never route to self
                    nodeIds.remove(engine.getNodeService().findIdentityNodeId());
                }
            }
            numberOfDataEventsInserted += insertDataEvents(processInfo, context, dataMetaData, nodeIds);
        }
    } else {
        log.warn("Could not find trigger routers for trigger history id of {} (table {}).  " + "Data with the id of {} and channel id {} will be assigned to an unrouted batch. " + "There is a good chance that data was captured and the trigger router link was removed before the data could be routed, or " + "that there is an orphaned symmetric trigger on the table.", data.getTriggerHistory().getTriggerHistoryId(), data.getTableName(), data.getDataId(), data.getChannelId());
        numberOfDataEventsInserted += insertDataEvents(processInfo, context, new DataMetaData(data, table, null, context.getChannel()), new HashSet<String>(0));
    }
    context.incrementStat(numberOfDataEventsInserted, ChannelRouterContext.STAT_DATA_EVENTS_INSERTED);
    return numberOfDataEventsInserted;
}
Also used : Table(org.jumpmind.db.model.Table) IDataRouter(org.jumpmind.symmetric.route.IDataRouter) SymmetricException(org.jumpmind.symmetric.SymmetricException) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) DelayRoutingException(org.jumpmind.symmetric.route.DelayRoutingException) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) HashSet(java.util.HashSet)

Example 30 with TriggerRouter

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

the class RouterService method getTriggerRoutersForData.

protected List<TriggerRouter> getTriggerRoutersForData(Data data) {
    List<TriggerRouter> triggerRouters = null;
    if (data != null) {
        if (data.getTriggerHistory() != null) {
            triggerRouters = engine.getTriggerRouterService().getTriggerRoutersForCurrentNode(false).get((data.getTriggerHistory().getTriggerId()));
            if (triggerRouters == null && data.getTriggerHistory().getTriggerId() != null && data.getTriggerHistory().getTriggerId().equals(AbstractFileParsingRouter.TRIGGER_ID_FILE_PARSER)) {
                TriggerRouter dynamicTriggerRouter = new TriggerRouter();
                String routerId = AbstractFileParsingRouter.getRouterIdFromExternalData(data.getExternalData());
                dynamicTriggerRouter.setRouter(engine.getTriggerRouterService().getRouterById(routerId));
                dynamicTriggerRouter.setTrigger(new Trigger());
                triggerRouters = new ArrayList<TriggerRouter>();
                triggerRouters.add(dynamicTriggerRouter);
                data.setDataEventType(DataEventType.INSERT);
            }
            if (triggerRouters == null || triggerRouters.size() == 0) {
                triggerRouters = engine.getTriggerRouterService().getTriggerRoutersForCurrentNode(true).get((data.getTriggerHistory().getTriggerId()));
            }
        } else {
            log.warn("Could not find a trigger hist record for recorded data {}.  Was the trigger hist record deleted manually?", data.getDataId());
        }
    }
    return triggerRouters;
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter)

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