Search in sources :

Example 11 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class AbstractTriggerRouterServiceTest method test02SchemaSync.

@Test
public void test02SchemaSync() throws Exception {
    ITriggerRouterService service = getTriggerRouterService();
    // baseline
    service.syncTriggers();
    // get the current number of hist rows
    int origCount = getTriggerHistTableRowCount();
    Thread.sleep(1000);
    Calendar lastUpdateTime = Calendar.getInstance();
    // force the triggers to rebuild
    int expectedCount = origCount + getSqlTemplate().update("update sym_trigger set last_update_time=? where trigger_id in (select trigger_id from sym_trigger_router where router_id in (select router_id from sym_router where source_node_group_id=?))", new Object[] { lastUpdateTime.getTime(), TestConstants.TEST_ROOT_NODE_GROUP });
    service.syncTriggers();
    Assert.assertEquals("Wrong trigger_hist row count. The original count was " + origCount + ".", expectedCount, getTriggerHistTableRowCount());
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 12 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class AbstractTriggerRouterServiceTest method test03SchemaSyncNoChanges.

@Test
public void test03SchemaSyncNoChanges() throws Exception {
    ITriggerRouterService service = getTriggerRouterService();
    service.syncTriggers();
    int origCount = getTriggerHistTableRowCount();
    Thread.sleep(1000);
    service.syncTriggers();
    Assert.assertEquals("Wrong trigger_hist row count.  No new triggers should have been generated.", origCount, getTriggerHistTableRowCount());
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) Test(org.junit.Test)

Example 13 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class AbstractTriggerRouterServiceTest method test11BinaryColumnTypesForOracle.

@Test
public void test11BinaryColumnTypesForOracle() {
    ISymmetricDialect dialect = getDbDialect();
    if (DatabaseNamesConstants.ORACLE.equals(dialect.getName())) {
        getSqlTemplate().update(CREATE_ORACLE_BINARY_TYPE);
        TriggerRouter trouter = new TriggerRouter();
        Trigger trigger = trouter.getTrigger();
        trigger.setSourceTableName("test_oracle_binary_types");
        trigger.setChannelId(TestConstants.TEST_CHANNEL_ID);
        Router router = trouter.getRouter();
        router.getNodeGroupLink().setSourceNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
        router.getNodeGroupLink().setTargetNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
        getTriggerRouterService().saveTriggerRouter(trouter);
        ITriggerRouterService triggerService = getTriggerRouterService();
        triggerService.syncTriggers();
        Assert.assertEquals("Some triggers must have failed to build.", 0, triggerService.getFailedTriggers().size());
        getSqlTemplate().update(INSERT_ORACLE_BINARY_TYPE_1);
        String csvString = getNextDataRow();
        Assert.assertEquals(EXPECTED_INSERT_ORALCE_BINARY_TYPE_1, csvString);
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) Trigger(org.jumpmind.symmetric.model.Trigger) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Test(org.junit.Test)

Example 14 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class AbstractTriggerRouterServiceTest method test12BinaryColumnTypesForPostgres.

@Test
public void test12BinaryColumnTypesForPostgres() {
    ISymmetricDialect dialect = getDbDialect();
    if (DatabaseNamesConstants.POSTGRESQL.equals(dialect.getName())) {
        getSqlTemplate().update(DROP_POSTGRES_BINARY_TYPE);
        getSqlTemplate().update(CREATE_POSTGRES_BINARY_TYPE);
        TriggerRouter trouter = new TriggerRouter();
        Trigger trigger = trouter.getTrigger();
        trigger.setSourceTableName("test_postgres_binary_types");
        trigger.setChannelId(TestConstants.TEST_CHANNEL_ID);
        Router router = trouter.getRouter();
        router.getNodeGroupLink().setSourceNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
        router.getNodeGroupLink().setTargetNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
        getTriggerRouterService().saveTriggerRouter(trouter);
        ITriggerRouterService triggerService = getTriggerRouterService();
        triggerService.syncTriggers();
        Assert.assertEquals("Some triggers must have failed to build.", 0, triggerService.getFailedTriggers().size());
        // new SerialBlob("test 1 2 3".getBytes())
        ISqlTransaction transaction = getSqlTemplate().startSqlTransaction();
        try {
            getSqlTemplate().update(INSERT_POSTGRES_BINARY_TYPE_1, "test 1 2 3".getBytes());
            transaction.commit();
        } finally {
            transaction.close();
        }
        String csvString = getNextDataRow();
        Assert.assertEquals(EXPECTED_INSERT_POSTGRES_BINARY_TYPE_1, csvString);
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Trigger(org.jumpmind.symmetric.model.Trigger) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Test(org.junit.Test)

Example 15 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class RestService method sendSchemaImpl.

private SendSchemaResponse sendSchemaImpl(ISymmetricEngine engine, SendSchemaRequest request) {
    IConfigurationService configurationService = engine.getConfigurationService();
    INodeService nodeService = engine.getNodeService();
    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    IDataService dataService = engine.getDataService();
    SendSchemaResponse response = new SendSchemaResponse();
    org.jumpmind.symmetric.model.Node identity = nodeService.findIdentity();
    if (identity != null) {
        List<org.jumpmind.symmetric.model.Node> nodesToSendTo = new ArrayList<org.jumpmind.symmetric.model.Node>();
        List<String> nodeIds = request.getNodeIdsToSendTo();
        if (nodeIds == null || nodeIds.size() == 0) {
            nodeIds = new ArrayList<String>();
            String nodeGroupIdToSendTo = request.getNodeGroupIdToSendTo();
            if (isNotBlank(nodeGroupIdToSendTo)) {
                NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), nodeGroupIdToSendTo, false);
                if (link != null) {
                    Collection<org.jumpmind.symmetric.model.Node> nodes = nodeService.findEnabledNodesFromNodeGroup(nodeGroupIdToSendTo);
                    nodesToSendTo.addAll(nodes);
                } else {
                    log.warn("Could not send schema to all nodes in the '" + nodeGroupIdToSendTo + "' node group.  No node group link exists");
                }
            } else {
                log.warn("Could not send schema to nodes.  There are none that were provided and the nodeGroupIdToSendTo was also not provided");
            }
        } else {
            for (String nodeIdToValidate : nodeIds) {
                org.jumpmind.symmetric.model.Node node = nodeService.findNode(nodeIdToValidate);
                if (node != null) {
                    NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), node.getNodeGroupId(), false);
                    if (link != null) {
                        nodesToSendTo.add(node);
                    } else {
                        log.warn("Could not send schema to node '" + nodeIdToValidate + "'. No node group link exists");
                    }
                } else {
                    log.warn("Could not send schema to node '" + nodeIdToValidate + "'.  It was not present in the database");
                }
            }
        }
        Map<String, List<TableName>> results = response.getNodeIdsSentTo();
        List<String> nodeIdsToSendTo = toNodeIds(nodesToSendTo);
        for (String nodeId : nodeIdsToSendTo) {
            results.put(nodeId, new ArrayList<TableName>());
        }
        if (nodesToSendTo.size() > 0) {
            List<TableName> tablesToSend = request.getTablesToSend();
            List<TriggerRouter> triggerRouters = triggerRouterService.getTriggerRouters(true, false);
            for (TriggerRouter triggerRouter : triggerRouters) {
                Trigger trigger = triggerRouter.getTrigger();
                NodeGroupLink link = triggerRouter.getRouter().getNodeGroupLink();
                if (link.getSourceNodeGroupId().equals(identity.getNodeGroupId())) {
                    for (org.jumpmind.symmetric.model.Node node : nodesToSendTo) {
                        if (link.getTargetNodeGroupId().equals(node.getNodeGroupId())) {
                            if (tablesToSend == null || tablesToSend.size() == 0 || contains(trigger, tablesToSend)) {
                                dataService.sendSchema(node.getNodeId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName(), false);
                                results.get(node.getNodeId()).add(new TableName(trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()));
                            }
                        }
                    }
                }
            }
        }
    }
    return response;
}
Also used : Node(org.jumpmind.symmetric.web.rest.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) ArrayList(java.util.ArrayList) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) Trigger(org.jumpmind.symmetric.model.Trigger) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList) EngineList(org.jumpmind.symmetric.web.rest.model.EngineList) NodeList(org.jumpmind.symmetric.web.rest.model.NodeList) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) IDataService(org.jumpmind.symmetric.service.IDataService) TableName(org.jumpmind.symmetric.web.rest.model.TableName) INodeService(org.jumpmind.symmetric.service.INodeService) SendSchemaResponse(org.jumpmind.symmetric.web.rest.model.SendSchemaResponse)

Aggregations

ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)27 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)12 Trigger (org.jumpmind.symmetric.model.Trigger)11 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)9 Node (org.jumpmind.symmetric.model.Node)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 Router (org.jumpmind.symmetric.model.Router)5 Table (org.jumpmind.db.model.Table)4 INodeService (org.jumpmind.symmetric.service.INodeService)4 File (java.io.File)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)3 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 IoException (org.jumpmind.exception.IoException)2