Search in sources :

Example 1 with IFileSyncService

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

the class DataService method insertFileSyncBatchForReload.

private void insertFileSyncBatchForReload(Node targetNode, long loadId, String createBy, boolean transactional, ISqlTransaction transaction, ProcessInfo processInfo) {
    if (parameterService.is(ParameterConstants.FILE_SYNC_ENABLE) && !Constants.DEPLOYMENT_TYPE_REST.equals(targetNode.getDeploymentType())) {
        ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
        IFileSyncService fileSyncService = engine.getFileSyncService();
        if (fileSyncService.getFileTriggerRoutersForCurrentNode().size() > 0) {
            TriggerHistory fileSyncSnapshotHistory = triggerRouterService.findTriggerHistory(null, null, TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT));
            String routerid = triggerRouterService.buildSymmetricTableRouterId(fileSyncSnapshotHistory.getTriggerId(), parameterService.getNodeGroupId(), targetNode.getNodeGroupId());
            TriggerRouter fileSyncSnapshotTriggerRouter = triggerRouterService.getTriggerRouterForCurrentNode(fileSyncSnapshotHistory.getTriggerId(), routerid, true);
            List<TriggerHistory> triggerHistories = Arrays.asList(fileSyncSnapshotHistory);
            List<TriggerRouter> triggerRouters = Arrays.asList(fileSyncSnapshotTriggerRouter);
            Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = new HashMap<Integer, List<TriggerRouter>>();
            triggerRoutersByHistoryId.put(fileSyncSnapshotHistory.getTriggerHistoryId(), triggerRouters);
            if (parameterService.is(ParameterConstants.INITIAL_LOAD_USE_EXTRACT_JOB)) {
                insertLoadBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, null, processInfo);
            } else {
                List<Channel> channels = engine.getConfigurationService().getFileSyncChannels();
                for (Channel channel : channels) {
                    if (channel.isReloadFlag()) {
                        insertReloadEvent(transaction, targetNode, fileSyncSnapshotTriggerRouter, fileSyncSnapshotHistory, "reload_channel_id='" + channel.getChannelId() + "'", true, loadId, createBy, Status.NE, channel.getChannelId());
                        if (!transactional) {
                            transaction.commit();
                        }
                    }
                }
            }
        }
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) HashMap(java.util.HashMap) Channel(org.jumpmind.symmetric.model.Channel) IFileSyncService(org.jumpmind.symmetric.service.IFileSyncService) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with IFileSyncService

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

the class DataService method insertFileSyncBatchForReload.

private void insertFileSyncBatchForReload(Node targetNode, long loadId, String createBy, boolean transactional, ISqlTransaction transaction) {
    if (parameterService.is(ParameterConstants.FILE_SYNC_ENABLE) && !Constants.DEPLOYMENT_TYPE_REST.equals(targetNode.getDeploymentType())) {
        ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
        IFileSyncService fileSyncService = engine.getFileSyncService();
        if (fileSyncService.getFileTriggerRoutersForCurrentNode().size() > 0) {
            TriggerHistory fileSyncSnapshotHistory = triggerRouterService.findTriggerHistory(null, null, TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT));
            String routerid = triggerRouterService.buildSymmetricTableRouterId(fileSyncSnapshotHistory.getTriggerId(), parameterService.getNodeGroupId(), targetNode.getNodeGroupId());
            TriggerRouter fileSyncSnapshotTriggerRouter = triggerRouterService.getTriggerRouterForCurrentNode(fileSyncSnapshotHistory.getTriggerId(), routerid, true);
            List<Channel> channels = engine.getConfigurationService().getFileSyncChannels();
            for (Channel channel : channels) {
                if (channel.isReloadFlag()) {
                    insertReloadEvent(transaction, targetNode, fileSyncSnapshotTriggerRouter, fileSyncSnapshotHistory, "reload_channel_id='" + channel.getChannelId() + "'", true, loadId, createBy, Status.NE, channel.getChannelId());
                    if (!transactional) {
                        transaction.commit();
                    }
                }
            }
        }
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) IFileSyncService(org.jumpmind.symmetric.service.IFileSyncService) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Channel(org.jumpmind.symmetric.model.Channel) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter)

Example 3 with IFileSyncService

use of org.jumpmind.symmetric.service.IFileSyncService 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 4 with IFileSyncService

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

the class FileSyncTest method testTargetWins.

protected void testTargetWins(ISymmetricEngine rootServer, ISymmetricEngine clientServer) throws Exception {
    IFileSyncService fileSyncService = rootServer.getFileSyncService();
    FileTriggerRouter fileTriggerRouter = fileSyncService.getFileTriggerRouter("all", "server_2_client");
    fileTriggerRouter.setConflictStrategy(FileConflictStrategy.TARGET_WINS);
    fileSyncService.saveFileTriggerRouter(fileTriggerRouter);
    pull("client");
    File allFile1 = new File(allSvrSourceDir, "tgt_wins/test.txt");
    allFile1.getParentFile().mkdirs();
    FileUtils.write(allFile1, "server value");
    File allFile1Target = new File(allClntTargetDir, allFile1.getParentFile().getName() + "/" + allFile1.getName());
    allFile1Target.getParentFile().mkdirs();
    FileUtils.write(allFile1Target, "client value");
    pullFiles();
    assertEquals("client value", FileUtils.readFileToString(allFile1Target));
}
Also used : FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) IFileSyncService(org.jumpmind.symmetric.service.IFileSyncService) File(java.io.File)

Example 5 with IFileSyncService

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

the class FileSyncTest method testUpdateManual.

protected void testUpdateManual(ISymmetricEngine rootServer, ISymmetricEngine clientServer) throws Exception {
    OutgoingBatches batchesInError = rootServer.getOutgoingBatchService().getOutgoingBatchErrors(10);
    List<OutgoingBatch> batches = batchesInError.getBatchesForChannel(Constants.CHANNEL_FILESYNC);
    assertEquals(0, batches.size());
    IFileSyncService fileSyncService = rootServer.getFileSyncService();
    FileTriggerRouter fileTriggerRouter = fileSyncService.getFileTriggerRouter("all", "server_2_client");
    fileTriggerRouter.setConflictStrategy(FileConflictStrategy.MANUAL);
    fileSyncService.saveFileTriggerRouter(fileTriggerRouter);
    pull("client");
    File allFile1 = new File(allSvrSourceDir, "manual/test2.txt");
    allFile1.getParentFile().mkdirs();
    FileUtils.write(allFile1, "base value");
    File allFile1Target = new File(allClntTargetDir, allFile1.getParentFile().getName() + "/" + allFile1.getName());
    allFile1Target.getParentFile().mkdirs();
    pullFiles();
    assertEquals("base value", FileUtils.readFileToString(allFile1Target));
    batchesInError = rootServer.getOutgoingBatchService().getOutgoingBatchErrors(10);
    batches = batchesInError.getBatchesForChannel(Constants.CHANNEL_FILESYNC);
    assertEquals(0, batches.size());
    FileUtils.write(allFile1, "new value", true);
    pullFiles();
    assertEquals("base valuenew value", FileUtils.readFileToString(allFile1Target));
    batchesInError = rootServer.getOutgoingBatchService().getOutgoingBatchErrors(10);
    batches = batchesInError.getBatchesForChannel(Constants.CHANNEL_FILESYNC);
    assertEquals(0, batches.size());
}
Also used : FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) IFileSyncService(org.jumpmind.symmetric.service.IFileSyncService) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) File(java.io.File)

Aggregations

IFileSyncService (org.jumpmind.symmetric.service.IFileSyncService)6 FileTriggerRouter (org.jumpmind.symmetric.model.FileTriggerRouter)4 File (java.io.File)3 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)3 Channel (org.jumpmind.symmetric.model.Channel)2 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)2 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)2 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)2 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 LastEventType (org.jumpmind.symmetric.model.FileSnapshot.LastEventType)1 Router (org.jumpmind.symmetric.model.Router)1 IRouterService (org.jumpmind.symmetric.service.IRouterService)1