Search in sources :

Example 36 with OutgoingBatch

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

the class PullUriHandler method pull.

public void pull(String nodeId, String remoteHost, String remoteAddress, OutputStream outputStream, String encoding, HttpServletResponse res, ChannelMap map) throws IOException {
    NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId, true);
    long ts = System.currentTimeMillis();
    try {
        ChannelMap remoteSuspendIgnoreChannelsList = configurationService.getSuspendIgnoreChannelLists(nodeId);
        map.addSuspendChannels(remoteSuspendIgnoreChannelsList.getSuspendChannels());
        map.addIgnoreChannels(remoteSuspendIgnoreChannelsList.getIgnoreChannels());
        if (nodeSecurity != null) {
            String createdAtNodeId = nodeSecurity.getCreatedAtNodeId();
            if (nodeSecurity.isRegistrationEnabled() && (createdAtNodeId == null || createdAtNodeId.equals(nodeService.findIdentityNodeId()))) {
                registrationService.registerNode(nodeService.findNode(nodeId), remoteHost, remoteAddress, outputStream, false);
            } else {
                IOutgoingTransport outgoingTransport = createOutgoingTransport(outputStream, encoding, map);
                ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), map.getThreadChannel(), nodeId, ProcessType.PULL_HANDLER));
                try {
                    Node targetNode = nodeService.findNode(nodeId, true);
                    List<OutgoingBatch> batchList = dataExtractorService.extract(processInfo, targetNode, map.getThreadChannel(), outgoingTransport);
                    logDataReceivedFromPush(targetNode, batchList);
                    if (processInfo.getStatus() != Status.ERROR) {
                        addPendingBatchCounts(targetNode.getNodeId(), res);
                        processInfo.setStatus(Status.OK);
                    }
                } finally {
                    if (processInfo.getStatus() != Status.OK) {
                        processInfo.setStatus(Status.ERROR);
                    }
                }
                outgoingTransport.close();
            }
        } else {
            log.warn("Node {} does not exist", nodeId);
        }
    } finally {
        statisticManager.incrementNodesPulled(1);
        statisticManager.incrementTotalNodesPulledTime(System.currentTimeMillis() - ts);
    }
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) IOutgoingTransport(org.jumpmind.symmetric.transport.IOutgoingTransport)

Example 37 with OutgoingBatch

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

the class FileSyncTest method testManual.

protected void testManual(ISymmetricEngine rootServer, ISymmetricEngine clientServer) throws Exception {
    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/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));
    OutgoingBatches batchesInError = rootServer.getOutgoingBatchService().getOutgoingBatchErrors(10);
    List<OutgoingBatch> batches = batchesInError.getBatchesForChannel(Constants.CHANNEL_FILESYNC);
    assertEquals(1, batches.size());
    allFile1Target.delete();
    pullFiles();
    assertEquals("server 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

OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)37 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)12 ArrayList (java.util.ArrayList)10 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)9 Node (org.jumpmind.symmetric.model.Node)8 IStagedResource (org.jumpmind.symmetric.io.stage.IStagedResource)6 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)6 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)5 SymmetricException (org.jumpmind.symmetric.SymmetricException)4 ProtocolDataWriter (org.jumpmind.symmetric.io.data.writer.ProtocolDataWriter)4 BatchAck (org.jumpmind.symmetric.model.BatchAck)4 Channel (org.jumpmind.symmetric.model.Channel)4 File (java.io.File)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 CancellationException (java.util.concurrent.CancellationException)3 IoException (org.jumpmind.exception.IoException)3 DataContext (org.jumpmind.symmetric.io.data.DataContext)3 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)3 BufferedReader (java.io.BufferedReader)2