Search in sources :

Example 1 with IRouterService

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

the class FileSyncDataRouter method routeToNodes.

public Set<String> routeToNodes(SimpleRouterContext context, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
    Set<String> nodeIds = new HashSet<String>();
    IFileSyncService fileSyncService = engine.getFileSyncService();
    IRouterService routerService = engine.getRouterService();
    Map<String, String> newData = getNewDataAsString(null, dataMetaData, engine.getSymmetricDialect());
    String triggerId = newData.get("TRIGGER_ID");
    String routerId = newData.get("ROUTER_ID");
    String sourceNodeId = newData.get("LAST_UPDATE_BY");
    String lastEventType = newData.get("LAST_EVENT_TYPE");
    if (triggerId == null) {
        Map<String, String> oldData = getOldDataAsString(null, dataMetaData, engine.getSymmetricDialect());
        triggerId = oldData.get("TRIGGER_ID");
        routerId = oldData.get("ROUTER_ID");
        sourceNodeId = oldData.get("LAST_UPDATE_BY");
        lastEventType = oldData.get("LAST_EVENT_TYPE");
    }
    LastEventType eventType = LastEventType.fromCode(lastEventType);
    FileTriggerRouter fileTriggerRouter = fileSyncService.getFileTriggerRouter(triggerId, routerId);
    if (fileTriggerRouter != null && fileTriggerRouter.isEnabled()) {
        if (fileTriggerRouter.getRouter().getNodeGroupLink().equals(triggerRouter.getRouter().getNodeGroupLink())) {
            if (eventType == null || eventType == LastEventType.DELETE && fileTriggerRouter.getFileTrigger().isSyncOnDelete() || eventType == LastEventType.MODIFY && fileTriggerRouter.getFileTrigger().isSyncOnModified() || eventType == LastEventType.CREATE && fileTriggerRouter.getFileTrigger().isSyncOnCreate()) {
                Router router = fileTriggerRouter.getRouter();
                Map<String, IDataRouter> routers = routerService.getRouters();
                IDataRouter dataRouter = null;
                if (StringUtils.isNotBlank(router.getRouterType())) {
                    dataRouter = routers.get(router.getRouterType());
                }
                if (dataRouter == null) {
                    dataRouter = routers.get("default");
                }
                if (context instanceof ChannelRouterContext) {
                    ((ChannelRouterContext) context).addUsedDataRouter(dataRouter);
                }
                dataMetaData.setRouter(router);
                nodeIds.addAll(dataRouter.routeToNodes(context, dataMetaData, nodes, false, false, triggerRouter));
                nodeIds.remove(sourceNodeId);
            }
        }
    } else {
        log.error("Could not find a trigger router with a trigger_id of {} and a router_id of {}.  The file snapshot will not be routed", triggerId, routerId);
    }
    return nodeIds;
}
Also used : LastEventType(org.jumpmind.symmetric.model.FileSnapshot.LastEventType) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) IFileSyncService(org.jumpmind.symmetric.service.IFileSyncService) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) HashSet(java.util.HashSet) IRouterService(org.jumpmind.symmetric.service.IRouterService)

Example 2 with IRouterService

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

the class DataGapRouteReaderTest method buildReader.

protected DataGapRouteReader buildReader(int peekAheadMemoryThreshold, List<DataGap> dataGaps) throws Exception {
    when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
    when(parameterService.is(ParameterConstants.SYNCHRONIZE_ALL_JOBS)).thenReturn(true);
    when(parameterService.getInt(ParameterConstants.ROUTING_WAIT_FOR_DATA_TIMEOUT_SECONDS)).thenReturn(330);
    when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_MEMORY_THRESHOLD)).thenReturn(peekAheadMemoryThreshold);
    when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAPS_TO_QUALIFY_IN_SQL)).thenReturn(100);
    when(parameterService.getInt(ParameterConstants.ROUTING_DATA_READER_THRESHOLD_GAPS_TO_USE_GREATER_QUERY)).thenReturn(100);
    when(parameterService.is(ParameterConstants.ROUTING_DATA_READER_ORDER_BY_DATA_ID_ENABLED)).thenReturn(true);
    IStatisticManager statisticManager = mock(StatisticManager.class);
    when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
    INodeService nodeService = mock(NodeService.class);
    when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
    IDatabasePlatform platform = mock(IDatabasePlatform.class);
    when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
    when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    ISymmetricDialect symmetricDialect = mock(AbstractSymmetricDialect.class);
    when(symmetricDialect.supportsTransactionId()).thenReturn(true);
    when(symmetricDialect.getPlatform()).thenReturn(platform);
    IExtensionService extensionService = mock(ExtensionService.class);
    ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getStatisticManager()).thenReturn(statisticManager);
    when(engine.getNodeService()).thenReturn(nodeService);
    when(engine.getDataService()).thenReturn(dataService);
    when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
    when(engine.getExtensionService()).thenReturn(extensionService);
    IRouterService routerService = new RouterService(engine);
    when(engine.getRouterService()).thenReturn(routerService);
    ChannelRouterContext context = new ChannelRouterContext(NODE_ID, nodeChannel, mock(ISqlTransaction.class));
    context.setDataGaps(dataGaps);
    return new DataGapRouteReader(context, engine);
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) RouterService(org.jumpmind.symmetric.service.impl.RouterService) IRouterService(org.jumpmind.symmetric.service.IRouterService) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IRouterService(org.jumpmind.symmetric.service.IRouterService) IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) INodeService(org.jumpmind.symmetric.service.INodeService) IExtensionService(org.jumpmind.symmetric.service.IExtensionService)

Example 3 with IRouterService

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

the class DataGapRouteReaderTest method buildReader.

protected DataGapRouteReader buildReader(int peekAheadMemoryThreshold) throws Exception {
    when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
    when(parameterService.is(ParameterConstants.SYNCHRONIZE_ALL_JOBS)).thenReturn(true);
    when(parameterService.getInt(ParameterConstants.ROUTING_WAIT_FOR_DATA_TIMEOUT_SECONDS)).thenReturn(330);
    when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_MEMORY_THRESHOLD)).thenReturn(peekAheadMemoryThreshold);
    when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAPS_TO_QUALIFY_IN_SQL)).thenReturn(100);
    when(parameterService.getInt(ParameterConstants.ROUTING_DATA_READER_THRESHOLD_GAPS_TO_USE_GREATER_QUERY)).thenReturn(100);
    when(parameterService.is(ParameterConstants.ROUTING_DATA_READER_ORDER_BY_DATA_ID_ENABLED)).thenReturn(true);
    IStatisticManager statisticManager = mock(StatisticManager.class);
    when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
    INodeService nodeService = mock(NodeService.class);
    when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
    IDatabasePlatform platform = mock(IDatabasePlatform.class);
    when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
    when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    ISymmetricDialect symmetricDialect = mock(AbstractSymmetricDialect.class);
    when(symmetricDialect.supportsTransactionId()).thenReturn(true);
    when(symmetricDialect.getPlatform()).thenReturn(platform);
    IExtensionService extensionService = mock(ExtensionService.class);
    ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getStatisticManager()).thenReturn(statisticManager);
    when(engine.getNodeService()).thenReturn(nodeService);
    when(engine.getDataService()).thenReturn(dataService);
    when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
    when(engine.getExtensionService()).thenReturn(extensionService);
    IRouterService routerService = new RouterService(engine);
    when(engine.getRouterService()).thenReturn(routerService);
    ChannelRouterContext context = new ChannelRouterContext(NODE_ID, nodeChannel, mock(ISqlTransaction.class));
    return new DataGapRouteReader(context, engine);
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) RouterService(org.jumpmind.symmetric.service.impl.RouterService) IRouterService(org.jumpmind.symmetric.service.IRouterService) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IRouterService(org.jumpmind.symmetric.service.IRouterService) IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) INodeService(org.jumpmind.symmetric.service.INodeService) IExtensionService(org.jumpmind.symmetric.service.IExtensionService)

Aggregations

IRouterService (org.jumpmind.symmetric.service.IRouterService)3 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)2 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)2 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)2 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)2 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)2 Node (org.jumpmind.symmetric.model.Node)2 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)2 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)2 INodeService (org.jumpmind.symmetric.service.INodeService)2 RouterService (org.jumpmind.symmetric.service.impl.RouterService)2 IStatisticManager (org.jumpmind.symmetric.statistic.IStatisticManager)2 HashSet (java.util.HashSet)1 LastEventType (org.jumpmind.symmetric.model.FileSnapshot.LastEventType)1 FileTriggerRouter (org.jumpmind.symmetric.model.FileTriggerRouter)1 Router (org.jumpmind.symmetric.model.Router)1 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)1 IFileSyncService (org.jumpmind.symmetric.service.IFileSyncService)1