Search in sources :

Example 11 with ChannelMap

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

the class NodeConcurrencyInterceptor method buildSuspendIgnoreResponseHeaders.

protected void buildSuspendIgnoreResponseHeaders(final String nodeId, final ServletResponse resp) {
    HttpServletResponse httpResponse = (HttpServletResponse) resp;
    ChannelMap suspendIgnoreChannels = configurationService.getSuspendIgnoreChannelLists(nodeId);
    httpResponse.setHeader(WebConstants.SUSPENDED_CHANNELS, suspendIgnoreChannels.getSuspendChannelsAsString());
    httpResponse.setHeader(WebConstants.IGNORED_CHANNELS, suspendIgnoreChannels.getIgnoreChannelsAsString());
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 12 with ChannelMap

use of org.jumpmind.symmetric.model.ChannelMap 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)

Example 13 with ChannelMap

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

the class DataLoaderService method loadDataFromPull.

public void loadDataFromPull(Node remote, RemoteNodeStatus status) throws IOException {
    Node local = nodeService.findIdentity();
    if (local == null) {
        local = new Node(this.parameterService, symmetricDialect);
    }
    try {
        NodeSecurity localSecurity = nodeService.findNodeSecurity(local.getNodeId());
        IIncomingTransport transport = null;
        if (remote != null && localSecurity != null) {
            Map<String, String> requestProperties = new HashMap<String, String>();
            ChannelMap suspendIgnoreChannels = configurationService.getSuspendIgnoreChannelLists();
            requestProperties.put(WebConstants.SUSPENDED_CHANNELS, suspendIgnoreChannels.getSuspendChannelsAsString());
            requestProperties.put(WebConstants.IGNORED_CHANNELS, suspendIgnoreChannels.getIgnoreChannelsAsString());
            transport = transportManager.getPullTransport(remote, local, localSecurity.getNodePassword(), requestProperties, parameterService.getRegistrationUrl());
        } else {
            transport = transportManager.getRegisterTransport(local, parameterService.getRegistrationUrl());
            log.info("Using registration URL of {}", transport.getUrl());
            remote = new Node();
            remote.setSyncUrl(parameterService.getRegistrationUrl());
        }
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(remote.getNodeId(), local.getNodeId(), ProcessType.PULL_JOB));
        try {
            List<IncomingBatch> list = loadDataFromTransport(processInfo, remote, transport);
            if (list.size() > 0) {
                processInfo.setStatus(ProcessInfo.Status.ACKING);
                status.updateIncomingStatus(list);
                local = nodeService.findIdentity();
                if (local != null) {
                    localSecurity = nodeService.findNodeSecurity(local.getNodeId());
                    if (StringUtils.isNotBlank(transport.getRedirectionUrl())) {
                        /*
                             * We were redirected for the pull, we need to
                             * redirect for the ack
                             */
                        String url = transport.getRedirectionUrl();
                        url = url.replace(HttpTransportManager.buildRegistrationUrl("", local), "");
                        remote.setSyncUrl(url);
                    }
                    sendAck(remote, local, localSecurity, list, transportManager);
                }
            }
            if (containsError(list)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
        } catch (RuntimeException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        } catch (IOException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        }
    } catch (RegistrationRequiredException e) {
        if (StringUtils.isBlank(remote.getSyncUrl()) || remote.getSyncUrl().equals(parameterService.getRegistrationUrl())) {
            log.warn("Node information missing on the server.  Attempting to re-register");
            loadDataFromPull(null, status);
            nodeService.findIdentity(false);
        } else {
            log.warn("Failed to pull data from node '{}'. It probably is missing a node security record for '{}'.", remote.getNodeId(), local.getNodeId());
        }
    } catch (MalformedURLException e) {
        if (remote != null) {
            log.error("Could not connect to the {} node's transport because of a bad URL: {}", remote.getNodeId(), remote.getSyncUrl());
        } else {
            log.error("", e);
        }
        throw e;
    }
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) MalformedURLException(java.net.MalformedURLException) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) HashMap(java.util.HashMap) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) IIncomingTransport(org.jumpmind.symmetric.transport.IIncomingTransport) RegistrationRequiredException(org.jumpmind.symmetric.service.RegistrationRequiredException)

Aggregations

ChannelMap (org.jumpmind.symmetric.model.ChannelMap)13 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)5 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)5 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)4 Node (org.jumpmind.symmetric.model.Node)3 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)3 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)3 IOutgoingTransport (org.jumpmind.symmetric.transport.IOutgoingTransport)3 IOException (java.io.IOException)2 HttpURLConnection (java.net.HttpURLConnection)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 IDataWriter (org.jumpmind.symmetric.io.data.IDataWriter)2 ProtocolDataWriter (org.jumpmind.symmetric.io.data.writer.ProtocolDataWriter)2 BufferedWriter (java.io.BufferedWriter)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1