Search in sources :

Example 16 with NodeGroupLink

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

the class DataService method insertHeartbeatEvent.

/**
     * Because we can't add a trigger on the _node table, we are artificially
     * generating heartbeat events.
     * 
     * @param node
     */
public void insertHeartbeatEvent(Node node, boolean isReload) {
    ISqlTransaction transaction = null;
    try {
        transaction = sqlTemplate.startSqlTransaction();
        String tableName = TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST);
        List<NodeGroupLink> links = engine.getConfigurationService().getNodeGroupLinksFor(parameterService.getNodeGroupId(), false);
        for (NodeGroupLink nodeGroupLink : links) {
            if (nodeGroupLink.getDataEventAction() == NodeGroupLinkAction.P) {
                Set<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(nodeGroupLink, null, null, tableName, false);
                if (triggerRouters != null && triggerRouters.size() > 0) {
                    Data data = createData(transaction, triggerRouters.iterator().next().getTrigger(), String.format(" t.node_id = '%s'", node.getNodeId()));
                    if (data != null) {
                        insertData(transaction, data);
                    } else {
                        log.warn("Not generating data/data events for table {} " + "because a trigger or trigger hist is not created yet.", tableName);
                    }
                } else {
                    log.warn("Not generating data/data events for table {} " + "because a trigger or trigger hist is not created yet.", tableName);
                }
            }
        }
        transaction.commit();
    } catch (Error ex) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw ex;
    } catch (RuntimeException ex) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw ex;
    } finally {
        close(transaction);
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Example 17 with NodeGroupLink

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

the class TransformService method readInCacheIfExpired.

private Map<NodeGroupLink, Map<TransformPoint, List<TransformTableNodeGroupLink>>> readInCacheIfExpired() {
    // get the cache timeout
    long cacheTimeoutInMs = parameterService.getLong(ParameterConstants.CACHE_TIMEOUT_TRANSFORM_IN_MS);
    Map<NodeGroupLink, Map<TransformPoint, List<TransformTableNodeGroupLink>>> byByLinkByTransformPoint = transformsCacheByNodeGroupLinkByTransformPoint;
    synchronized (this) {
        if (System.currentTimeMillis() - lastCacheTimeInMs >= cacheTimeoutInMs || byByLinkByTransformPoint == null) {
            byByLinkByTransformPoint = new HashMap<NodeGroupLink, Map<TransformPoint, List<TransformTableNodeGroupLink>>>(2);
            List<TransformTableNodeGroupLink> transforms = getTransformTablesFromDB(true, true);
            for (TransformTableNodeGroupLink transformTable : transforms) {
                NodeGroupLink nodeGroupLink = transformTable.getNodeGroupLink();
                Map<TransformPoint, List<TransformTableNodeGroupLink>> byTransformPoint = byByLinkByTransformPoint.get(nodeGroupLink);
                if (byTransformPoint == null) {
                    byTransformPoint = new HashMap<TransformPoint, List<TransformTableNodeGroupLink>>(2);
                    byByLinkByTransformPoint.put(nodeGroupLink, byTransformPoint);
                }
                List<TransformTableNodeGroupLink> byTableName = byTransformPoint.get(transformTable.getTransformPoint());
                if (byTableName == null) {
                    byTableName = new ArrayList<TransformTableNodeGroupLink>();
                    byTransformPoint.put(transformTable.getTransformPoint(), byTableName);
                }
                byTableName.add(transformTable);
            }
            lastCacheTimeInMs = System.currentTimeMillis();
            this.transformsCacheByNodeGroupLinkByTransformPoint = byByLinkByTransformPoint;
        }
    }
    return byByLinkByTransformPoint;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) Map(java.util.Map) HashMap(java.util.HashMap) TransformPoint(org.jumpmind.symmetric.io.data.transform.TransformPoint)

Example 18 with NodeGroupLink

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

the class TransformService method findTransformsFor.

public List<TransformTableNodeGroupLink> findTransformsFor(String sourceNodeGroupId, String targetNodeGroupId, String table) {
    NodeGroupLink nodeGroupLink = new NodeGroupLink(sourceNodeGroupId, targetNodeGroupId);
    List<TransformTableNodeGroupLink> transformsForNodeGroupLink = findTransformsFor(nodeGroupLink);
    if (!CollectionUtils.isEmpty(transformsForNodeGroupLink)) {
        List<TransformTableNodeGroupLink> transforms = new ArrayList<TransformTableNodeGroupLink>();
        for (TransformTableNodeGroupLink transform : transformsForNodeGroupLink) {
            if (StringUtils.equalsIgnoreCase(table, transform.getSourceTableName())) {
                transforms.add(transform);
            }
        }
        if (!transforms.isEmpty()) {
            return transforms;
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Example 19 with NodeGroupLink

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

the class TriggerRouterService method getConfigurationTablesTriggerRoutersForCurrentNode.

/**
     * Create a list of {@link TriggerRouter} for the SymmetricDS tables that
     * should have triggers created for them on the current node.
     */
protected List<TriggerRouter> getConfigurationTablesTriggerRoutersForCurrentNode(String sourceNodeGroupId) {
    List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>();
    List<NodeGroupLink> links = configurationService.getNodeGroupLinksFor(sourceNodeGroupId, false);
    for (NodeGroupLink nodeGroupLink : links) {
        triggerRouters.addAll(buildTriggerRoutersForSymmetricTables(Version.version(), nodeGroupLink));
    }
    return triggerRouters;
}
Also used : ArrayList(java.util.ArrayList) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Example 20 with NodeGroupLink

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

the class ConfigurationChangedDataRouterTest method buildTestableRouter.

protected IDataRouter buildTestableRouter(final Node nodeThatIsRouting, final List<NodeGroupLink> links, final NetworkedNode root) {
    IConfigurationService configService = mock(IConfigurationService.class);
    when(configService.isMasterToMaster()).thenReturn(false);
    ISymmetricEngine engine = mock(ISymmetricEngine.class);
    when(engine.getConfigurationService()).thenReturn(configService);
    when(engine.getTablePrefix()).thenReturn("sym");
    ConfigurationChangedDataRouter router = new ConfigurationChangedDataRouter(engine) {

        @Override
        protected Node findIdentity() {
            return nodeThatIsRouting;
        }

        @Override
        protected List<NodeGroupLink> getNodeGroupLinksFromContext(SimpleRouterContext routingContext) {
            return links;
        }

        @Override
        protected NetworkedNode getRootNetworkNodeFromContext(SimpleRouterContext routingContext) {
            return root;
        }
    };
    return router;
}
Also used : ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Aggregations

NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)22 Node (org.jumpmind.symmetric.model.Node)11 ArrayList (java.util.ArrayList)9 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)7 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)5 TransformTableNodeGroupLink (org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)5 List (java.util.List)4 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 TransformTable (org.jumpmind.symmetric.io.data.transform.TransformTable)3 Trigger (org.jumpmind.symmetric.model.Trigger)3 INodeService (org.jumpmind.symmetric.service.INodeService)3 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)3 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)2 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)2 CsvData (org.jumpmind.symmetric.io.data.CsvData)2 TransformPoint (org.jumpmind.symmetric.io.data.transform.TransformPoint)2 TransformWriter (org.jumpmind.symmetric.io.data.writer.TransformWriter)2