Search in sources :

Example 16 with ProcessInfoKey

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

the class DataLoaderService method loadDataFromConfig.

public void loadDataFromConfig(Node remote, RemoteNodeStatus status, boolean force) throws IOException {
    if (engine.getParameterService().isRegistrationServer()) {
        return;
    }
    Node local = nodeService.findIdentity();
    try {
        NodeSecurity localSecurity = nodeService.findNodeSecurity(local.getNodeId(), true);
        String configVersion = force ? "" : local.getConfigVersion();
        IIncomingTransport transport = engine.getTransportManager().getConfigTransport(remote, local, localSecurity.getNodePassword(), Version.version(), configVersion, remote.getSyncUrl());
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(remote.getNodeId(), Constants.CHANNEL_CONFIG, local.getNodeId(), ProcessType.PULL_CONFIG_JOB));
        try {
            log.info("Requesting current configuration {symmetricVersion={}, configVersion={}}", Version.version(), local.getConfigVersion());
            List<IncomingBatch> list = loadDataFromTransport(processInfo, remote, transport, null);
            if (containsError(list)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                if (list.size() > 0) {
                    status.updateIncomingStatus(list);
                    local.setConfigVersion(Version.version());
                    nodeService.save(local);
                }
                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) {
        log.warn("Failed to pull configuration from node '{}'. It probably is missing a node security record for '{}'.", remote.getNodeId(), local.getNodeId());
    } catch (MalformedURLException e) {
        log.error("Could not connect to the {} node's transport because of a bad URL: '{}' {}", remote.getNodeId(), remote.getSyncUrl(), e);
        throw e;
    }
}
Also used : IIncomingTransport(org.jumpmind.symmetric.transport.IIncomingTransport) MalformedURLException(java.net.MalformedURLException) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) RegistrationRequiredException(org.jumpmind.symmetric.service.RegistrationRequiredException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 17 with ProcessInfoKey

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

the class FileSyncService method trackChanges.

public void trackChanges(boolean force) {
    if (force || engine.getClusterService().lock(ClusterConstants.FILE_SYNC_TRACKER)) {
        try {
            log.debug("Attempting to get exclusive lock for file sync track changes");
            if (engine.getClusterService().lock(ClusterConstants.FILE_SYNC_SHARED, ClusterConstants.TYPE_EXCLUSIVE, getParameterService().getLong(ParameterConstants.FILE_SYNC_LOCK_WAIT_MS))) {
                try {
                    log.debug("Tracking changes for file sync");
                    Node local = engine.getNodeService().findIdentity();
                    ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(local.getNodeId(), null, ProcessInfoKey.ProcessType.FILE_SYNC_TRACKER));
                    boolean useCrc = engine.getParameterService().is(ParameterConstants.FILE_SYNC_USE_CRC);
                    if (engine.getParameterService().is(ParameterConstants.FILE_SYNC_FAST_SCAN)) {
                        trackChangesFastScan(processInfo, useCrc);
                    } else {
                        trackChanges(processInfo, useCrc);
                    }
                    if (engine.getParameterService().is(ParameterConstants.FILE_SYNC_PREVENT_PING_BACK)) {
                        deleteFromFileIncoming();
                    }
                    processInfo.setStatus(ProcessInfo.Status.OK);
                } finally {
                    log.debug("Done tracking changes for file sync");
                    engine.getClusterService().unlock(ClusterConstants.FILE_SYNC_SHARED, ClusterConstants.TYPE_EXCLUSIVE);
                }
            } else {
                log.warn("Did not run the track file sync changes process because it was shared locked");
            }
        } finally {
            if (!force) {
                engine.getClusterService().unlock(ClusterConstants.FILE_SYNC_TRACKER);
            }
        }
    } else {
        log.debug("Did not run the track file sync changes process because it was cluster locked");
    }
}
Also used : Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo)

Example 18 with ProcessInfoKey

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

the class PushService method pushToNode.

private void pushToNode(Node remote, RemoteNodeStatus status) {
    Node identity = nodeService.findIdentity();
    NodeSecurity identitySecurity = nodeService.findNodeSecurity(identity.getNodeId(), true);
    IOutgoingWithResponseTransport transport = null;
    ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(identity.getNodeId(), status.getChannelId(), remote.getNodeId(), ProcessType.PUSH_JOB));
    Map<String, String> requestProperties = new HashMap<String, String>();
    requestProperties.put(WebConstants.THREAD_CHANNEL, status.getChannelId());
    try {
        transport = transportManager.getPushTransport(remote, identity, identitySecurity.getNodePassword(), requestProperties, parameterService.getRegistrationUrl());
        List<OutgoingBatch> extractedBatches = dataExtractorService.extract(processInfo, remote, status.getChannelId(), transport);
        if (extractedBatches.size() > 0) {
            log.info("Push data sent to {}", remote);
            List<BatchAck> batchAcks = readAcks(extractedBatches, transport, transportManager, acknowledgeService);
            status.updateOutgoingStatus(extractedBatches, batchAcks);
        }
        if (processInfo.getStatus() != Status.ERROR) {
            processInfo.setStatus(Status.OK);
        }
        fireOnline(remote, status);
    } catch (Exception ex) {
        processInfo.setStatus(Status.ERROR);
        fireOffline(ex, remote, status);
    } finally {
        try {
            transport.close();
        } catch (Exception e) {
        }
    }
}
Also used : 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) BatchAck(org.jumpmind.symmetric.model.BatchAck) IOutgoingWithResponseTransport(org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 19 with ProcessInfoKey

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

the class RouterService method routeDataForEachChannel.

/**
     * We route data channel by channel for two reasons. One is that if/when we
     * decide to multi-thread the routing it is a simple matter of inserting a
     * thread pool here and waiting for all channels to be processed. The other
     * reason is to reduce the number of connections we are required to have.
     */
protected int routeDataForEachChannel() {
    int dataCount = 0;
    Node sourceNode = engine.getNodeService().findIdentity();
    ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(sourceNode.getNodeId(), null, ProcessType.ROUTER_JOB));
    processInfo.setStatus(ProcessInfo.Status.PROCESSING);
    try {
        final List<NodeChannel> channels = engine.getConfigurationService().getNodeChannels(false);
        Set<String> readyChannels = null;
        if (parameterService.is(ParameterConstants.ROUTING_QUERY_CHANNELS_FIRST)) {
            readyChannels = getReadyChannels();
        }
        for (NodeChannel nodeChannel : channels) {
            if (nodeChannel.isEnabled() && (readyChannels == null || readyChannels.contains(nodeChannel.getChannelId()))) {
                processInfo.setCurrentChannelId(nodeChannel.getChannelId());
                dataCount += routeDataForChannel(processInfo, nodeChannel, sourceNode);
            } else {
                gapDetector.setIsAllDataRead(false);
                if (log.isDebugEnabled()) {
                    log.debug("Not routing the {} channel.  It is either disabled or suspended.", nodeChannel.getChannelId());
                }
            }
        }
        processInfo.setStatus(ProcessInfo.Status.OK);
    } catch (RuntimeException ex) {
        processInfo.setStatus(ProcessInfo.Status.ERROR);
        firstTimeCheckForAbandonedBatches = true;
        throw ex;
    }
    return dataCount;
}
Also used : Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 20 with ProcessInfoKey

use of org.jumpmind.symmetric.model.ProcessInfoKey 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) IOException(java.io.IOException) IOutgoingTransport(org.jumpmind.symmetric.transport.IOutgoingTransport)

Aggregations

ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)23 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)22 Node (org.jumpmind.symmetric.model.Node)13 IOException (java.io.IOException)10 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)8 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)7 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)6 IoException (org.jumpmind.exception.IoException)5 SymmetricException (org.jumpmind.symmetric.SymmetricException)5 ArrayList (java.util.ArrayList)4 IOutgoingTransport (org.jumpmind.symmetric.transport.IOutgoingTransport)4 MalformedURLException (java.net.MalformedURLException)3 Date (java.util.Date)3 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)3 BatchAck (org.jumpmind.symmetric.model.BatchAck)3 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)3 INodeService (org.jumpmind.symmetric.service.INodeService)3 RegistrationRequiredException (org.jumpmind.symmetric.service.RegistrationRequiredException)3 IIncomingTransport (org.jumpmind.symmetric.transport.IIncomingTransport)3 InputStream (java.io.InputStream)2