Search in sources :

Example 11 with DataMetaData

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

the class ColumnMatchDataRouterTest method testExpressionEqualsExternalId.

@Test
public void testExpressionEqualsExternalId() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("1000", "client"));
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("10", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,STORE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,Super Dooper");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("STORE_ID = :EXTERNAL_ID");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(1, result.size());
    assertEquals(true, result.contains("100"));
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 12 with DataMetaData

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

the class ColumnMatchDataRouterTest method testExpressionNotContains.

@Test
public void testExpressionNotContains() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("200", "client"));
    nodes.add(new Node("300", "client"));
    nodes.add(new Node("1000", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,Super Dooper");
    data.setExternalData("1000,200");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("EXTERNAL_DATA not contains :NODE_ID");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(2, result.size());
    assertEquals(true, result.contains("100"));
    assertEquals(true, result.contains("300"));
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 13 with DataMetaData

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

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

the class ColumnMatchDataRouterTest method testExpressionNotEqualsNodeId.

@Test
public void testExpressionNotEqualsNodeId() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("200", "client"));
    nodes.add(new Node("300", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,Super Dooper");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("NODE_ID != :NODE_ID");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(2, result.size());
    assertEquals(true, result.contains("200"));
    assertEquals(true, result.contains("300"));
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 15 with DataMetaData

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

the class ConfigurationChangedDataRouterTest method buildDataMetaData.

protected DataMetaData buildDataMetaData(String tableName, String nodeId) {
    Data data = new Data();
    data.setTableName(tableName);
    data.setDataEventType(DataEventType.UPDATE);
    data.setTriggerHistory(new TriggerHistory(tableName, "NODE_ID", "NODE_ID"));
    data.setPkData(nodeId);
    data.setRowData(nodeId);
    return new DataMetaData(data, new Table(tableName), null, null);
}
Also used : Table(org.jumpmind.db.model.Table) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) DataMetaData(org.jumpmind.symmetric.model.DataMetaData)

Aggregations

DataMetaData (org.jumpmind.symmetric.model.DataMetaData)16 Data (org.jumpmind.symmetric.model.Data)15 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)13 Table (org.jumpmind.db.model.Table)12 Test (org.junit.Test)12 HashSet (java.util.HashSet)11 Node (org.jumpmind.symmetric.model.Node)9 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)9 Router (org.jumpmind.symmetric.model.Router)9 File (java.io.File)2 CsvData (org.jumpmind.symmetric.io.data.CsvData)2 ArrayList (java.util.ArrayList)1 SymmetricException (org.jumpmind.symmetric.SymmetricException)1 FileSnapshot (org.jumpmind.symmetric.model.FileSnapshot)1 FileTrigger (org.jumpmind.symmetric.model.FileTrigger)1 FileTriggerRouter (org.jumpmind.symmetric.model.FileTriggerRouter)1 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)1 DelayRoutingException (org.jumpmind.symmetric.route.DelayRoutingException)1 IDataRouter (org.jumpmind.symmetric.route.IDataRouter)1 IContextService (org.jumpmind.symmetric.service.IContextService)1