Search in sources :

Example 21 with ProcessInfo

use of org.jumpmind.symmetric.model.ProcessInfo 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 22 with ProcessInfo

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

the class DataExtractorService method extractOnlyOutgoingBatch.

/**
     * This method will extract an outgoing batch, but will not update the outgoing batch status
     */
public boolean extractOnlyOutgoingBatch(String nodeId, long batchId, Writer writer) {
    boolean extracted = false;
    Node targetNode = null;
    if (Constants.UNROUTED_NODE_ID.equals(nodeId)) {
        targetNode = new Node(nodeId, parameterService.getNodeGroupId());
    } else {
        targetNode = nodeService.findNode(nodeId);
    }
    if (targetNode != null) {
        OutgoingBatch batch = outgoingBatchService.findOutgoingBatch(batchId, nodeId);
        if (batch != null) {
            IDataWriter dataWriter = new ProtocolDataWriter(nodeService.findIdentityNodeId(), writer, targetNode.requires13Compatiblity());
            List<OutgoingBatch> batches = new ArrayList<OutgoingBatch>(1);
            batches.add(batch);
            batches = extract(new ProcessInfo(), targetNode, batches, dataWriter, null, ExtractMode.EXTRACT_ONLY);
            extracted = batches.size() > 0;
        }
    }
    return extracted;
}
Also used : ProtocolDataWriter(org.jumpmind.symmetric.io.data.writer.ProtocolDataWriter) Node(org.jumpmind.symmetric.model.Node) ArrayList(java.util.ArrayList) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IDataWriter(org.jumpmind.symmetric.io.data.IDataWriter)

Example 23 with ProcessInfo

use of org.jumpmind.symmetric.model.ProcessInfo 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 24 with ProcessInfo

use of org.jumpmind.symmetric.model.ProcessInfo 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 25 with ProcessInfo

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

Aggregations

ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)32 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)22 Node (org.jumpmind.symmetric.model.Node)18 IOException (java.io.IOException)10 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)10 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)8 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)7 ArrayList (java.util.ArrayList)5 IoException (org.jumpmind.exception.IoException)5 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)5 SymmetricException (org.jumpmind.symmetric.SymmetricException)5 INodeService (org.jumpmind.symmetric.service.INodeService)5 MalformedURLException (java.net.MalformedURLException)4 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)4 Date (java.util.Date)3 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)3 IOutgoingTransport (org.jumpmind.symmetric.transport.IOutgoingTransport)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 PipedInputStream (java.io.PipedInputStream)2