Search in sources :

Example 1 with IOutgoingTransport

use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.

the class FileSyncPullUriHandler method handle.

public void handle(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    String nodeId = ServletUtils.getParameter(req, WebConstants.NODE_ID);
    if (StringUtils.isBlank(nodeId)) {
        ServletUtils.sendError(res, HttpServletResponse.SC_BAD_REQUEST, "Node must be specified");
        return;
    } else {
        log.debug("File sync pull request received from {}", nodeId);
    }
    IOutgoingTransport outgoingTransport = createOutgoingTransport(res.getOutputStream(), req.getHeader(WebConstants.HEADER_ACCEPT_CHARSET), engine.getConfigurationService().getSuspendIgnoreChannelLists(nodeId));
    ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), nodeId, ProcessType.FILE_SYNC_PULL_HANDLER));
    try {
        res.setContentType("application/zip");
        res.addHeader("Content-Disposition", "attachment; filename=\"file-sync.zip\"");
        engine.getFileSyncService().sendFiles(processInfo, engine.getNodeService().findNode(nodeId), outgoingTransport);
        processInfo.setStatus(Status.OK);
    } catch (RuntimeException ex) {
        processInfo.setStatus(Status.ERROR);
        throw ex;
    } finally {
        if (outgoingTransport != null) {
            outgoingTransport.close();
        }
    }
}
Also used : ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOutgoingTransport(org.jumpmind.symmetric.transport.IOutgoingTransport)

Example 2 with IOutgoingTransport

use of org.jumpmind.symmetric.transport.IOutgoingTransport 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 3 with IOutgoingTransport

use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.

the class InternalTransportManager method getPullTransport.

public IIncomingTransport getPullTransport(Node remote, final Node local, String securityToken, Map<String, String> requestProperties, String registrationUrl) throws IOException {
    final PipedOutputStream respOs = new PipedOutputStream();
    final PipedInputStream respIs = new PipedInputStream(respOs);
    final ChannelMap suspendIgnoreChannels = symmetricEngine.getConfigurationService().getSuspendIgnoreChannelLists(remote.getNodeId());
    runAtClient(remote.getSyncUrl(), null, respOs, new IClientRunnable() {

        public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
            IOutgoingTransport transport = new InternalOutgoingTransport(respOs, suspendIgnoreChannels, IoConstants.ENCODING);
            ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), local.getNodeId(), ProcessType.PULL_HANDLER));
            try {
                engine.getDataExtractorService().extract(processInfo, local, transport);
                processInfo.setStatus(Status.OK);
            } catch (RuntimeException ex) {
                processInfo.setStatus(Status.ERROR);
                throw ex;
            }
            transport.close();
        }
    });
    return new InternalIncomingTransport(respIs);
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) NotImplementedException(org.apache.commons.lang.NotImplementedException) IOException(java.io.IOException) IOutgoingTransport(org.jumpmind.symmetric.transport.IOutgoingTransport)

Example 4 with IOutgoingTransport

use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.

the class InternalTransportManager method getFilePullTransport.

public IIncomingTransport getFilePullTransport(Node remote, final Node local, String securityToken, Map<String, String> requestProperties, String registrationUrl) throws IOException {
    final PipedOutputStream respOs = new PipedOutputStream();
    final PipedInputStream respIs = new PipedInputStream(respOs);
    runAtClient(remote.getSyncUrl(), null, respOs, new IClientRunnable() {

        public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
            IOutgoingTransport transport = new InternalOutgoingTransport(respOs, null);
            ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), local.getNodeId(), ProcessType.FILE_SYNC_PULL_HANDLER));
            try {
                engine.getFileSyncService().sendFiles(processInfo, local, transport);
                processInfo.setStatus(Status.OK);
            } catch (RuntimeException ex) {
                processInfo.setStatus(Status.ERROR);
                throw ex;
            }
            transport.close();
        }
    });
    return new InternalIncomingTransport(respIs);
}
Also used : PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) NotImplementedException(org.apache.commons.lang.NotImplementedException) IOException(java.io.IOException) IOutgoingTransport(org.jumpmind.symmetric.transport.IOutgoingTransport)

Example 5 with IOutgoingTransport

use of org.jumpmind.symmetric.transport.IOutgoingTransport in project symmetric-ds by JumpMind.

the class PullUriHandler method pull.

public void pull(String nodeId, String remoteHost, String remoteAddress, OutputStream outputStream, String encoding, ChannelMap map) throws IOException {
    NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId);
    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(), nodeId, ProcessType.PULL_HANDLER));
                try {
                    Node targetNode = nodeService.findNode(nodeId);
                    List<OutgoingBatch> batchList = dataExtractorService.extract(processInfo, targetNode, outgoingTransport);
                    logDataReceivedFromPush(targetNode, batchList);
                    if (processInfo.getStatus() != Status.ERROR) {
                        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)

Aggregations

ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)5 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)5 IOutgoingTransport (org.jumpmind.symmetric.transport.IOutgoingTransport)5 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 PipedInputStream (java.io.PipedInputStream)2 PipedOutputStream (java.io.PipedOutputStream)2 NotImplementedException (org.apache.commons.lang.NotImplementedException)2 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)2 Node (org.jumpmind.symmetric.model.Node)2 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)2 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)2