Search in sources :

Example 6 with ProcessInfoKey

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

the class FileSyncService method loadFilesFromPush.

public void loadFilesFromPush(String nodeId, InputStream in, OutputStream out) {
    INodeService nodeService = engine.getNodeService();
    Node local = nodeService.findIdentity();
    Node sourceNode = nodeService.findNode(nodeId, true);
    if (local != null && sourceNode != null) {
        ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeId, local.getNodeId(), ProcessInfoKey.ProcessType.FILE_SYNC_PUSH_HANDLER));
        try {
            List<IncomingBatch> list = processZip(in, nodeId, processInfo);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId(), true);
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            engine.getTransportManager().writeAcknowledgement(out, sourceNode, list, local, security != null ? security.getNodePassword() : null);
            processInfo.setStatus(ProcessInfo.Status.OK);
        } catch (Throwable e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            if (e instanceof IOException) {
                throw new IoException((IOException) e);
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new RuntimeException(e);
            }
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) IoException(org.jumpmind.exception.IoException) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 7 with ProcessInfoKey

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

the class FileSyncService method pushFilesToNode.

protected void pushFilesToNode(NodeCommunication nodeCommunication, RemoteNodeStatus status, Node identity, NodeSecurity security) {
    ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeCommunication.getNodeId(), identity.getNodeId(), ProcessType.FILE_SYNC_PUSH_JOB));
    IOutgoingWithResponseTransport transport = null;
    ITransportManager transportManager = null;
    try {
        if (!engine.getParameterService().is(ParameterConstants.NODE_OFFLINE)) {
            transportManager = engine.getTransportManager();
            transport = transportManager.getFilePushTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), parameterService.getRegistrationUrl());
        } else {
            transportManager = ((AbstractSymmetricEngine) engine).getOfflineTransportManager();
            transport = transportManager.getFilePushTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), parameterService.getRegistrationUrl());
        }
        List<OutgoingBatch> batches = sendFiles(processInfo, nodeCommunication.getNode(), transport);
        if (batches.size() > 0) {
            if (transport instanceof FileOutgoingTransport) {
                ((FileOutgoingTransport) transport).setProcessedBatches(batches);
            }
            List<BatchAck> batchAcks = readAcks(batches, transport, transportManager, engine.getAcknowledgeService());
            status.updateOutgoingStatus(batches, batchAcks);
        }
        if (!status.failed() && batches.size() > 0) {
            log.info("Pushed files to {}. {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
        } else if (status.failed()) {
            log.info("There was a failure while pushing files to {}. {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
        }
    } catch (Exception e) {
        fireOffline(e, nodeCommunication.getNode(), status);
    } finally {
        if (processInfo.getStatus() != ProcessInfo.Status.ERROR) {
            processInfo.setStatus(ProcessInfo.Status.OK);
        }
        if (transport != null) {
            transport.close();
            if (transport instanceof FileOutgoingTransport) {
                ((FileOutgoingTransport) transport).complete(processInfo.getStatus() == ProcessInfo.Status.OK);
            }
        }
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) ITransportManager(org.jumpmind.symmetric.transport.ITransportManager) IOutgoingWithResponseTransport(org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport) FileOutgoingTransport(org.jumpmind.symmetric.transport.file.FileOutgoingTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) FileConflictException(org.jumpmind.symmetric.file.FileConflictException) NoContentException(org.jumpmind.symmetric.transport.NoContentException) SymmetricException(org.jumpmind.symmetric.SymmetricException) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException)

Example 8 with ProcessInfoKey

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

the class FileSyncService method pullFilesFromNode.

protected void pullFilesFromNode(NodeCommunication nodeCommunication, RemoteNodeStatus status, Node identity, NodeSecurity security) {
    IIncomingTransport transport = null;
    ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeCommunication.getNodeId(), identity.getNodeId(), ProcessType.FILE_SYNC_PULL_JOB));
    try {
        processInfo.setStatus(ProcessInfo.Status.TRANSFERRING);
        ITransportManager transportManager;
        if (!engine.getParameterService().is(ParameterConstants.NODE_OFFLINE)) {
            transportManager = engine.getTransportManager();
            transport = transportManager.getFilePullTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), null, parameterService.getRegistrationUrl());
        } else {
            transportManager = ((AbstractSymmetricEngine) engine).getOfflineTransportManager();
            transport = transportManager.getFilePullTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), null, parameterService.getRegistrationUrl());
        }
        List<IncomingBatch> batchesProcessed = processZip(transport.openStream(), nodeCommunication.getNodeId(), processInfo);
        if (batchesProcessed.size() > 0) {
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            status.updateIncomingStatus(batchesProcessed);
            sendAck(nodeCommunication.getNode(), identity, security, batchesProcessed, transportManager);
        }
        if (!status.failed() && batchesProcessed.size() > 0) {
            log.info("Pull files received from {}.  {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
        } else if (status.failed()) {
            log.info("There was a failure while pulling files from {}.  {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
        }
    } catch (NoContentException noContentEx) {
        log.debug("Server reported no batches. " + noContentEx);
    } catch (Exception e) {
        fireOffline(e, nodeCommunication.getNode(), status);
    } finally {
        if (transport != null) {
            transport.close();
            if (processInfo.getStatus() != ProcessInfo.Status.ERROR) {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
            if (transport instanceof FileIncomingTransport) {
                ((FileIncomingTransport) transport).complete(!status.failed());
            }
        }
    }
}
Also used : IIncomingTransport(org.jumpmind.symmetric.transport.IIncomingTransport) ITransportManager(org.jumpmind.symmetric.transport.ITransportManager) FileIncomingTransport(org.jumpmind.symmetric.transport.file.FileIncomingTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) NoContentException(org.jumpmind.symmetric.transport.NoContentException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) FileConflictException(org.jumpmind.symmetric.file.FileConflictException) NoContentException(org.jumpmind.symmetric.transport.NoContentException) SymmetricException(org.jumpmind.symmetric.SymmetricException) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException)

Example 9 with ProcessInfoKey

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

the class RouterService method insertInitialLoadEvents.

/**
     * If a load has been queued up by setting the initial load enabled or
     * reverse initial load enabled flags, then the router service will insert
     * the reload events. This process will not run at the same time sync
     * triggers is running.
     */
protected void insertInitialLoadEvents() {
    ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), null, ProcessType.INSERT_LOAD_EVENTS));
    processInfo.setStatus(ProcessInfo.Status.PROCESSING);
    try {
        INodeService nodeService = engine.getNodeService();
        Node identity = nodeService.findIdentity();
        if (identity != null) {
            boolean isClusteringEnabled = parameterService.is(ParameterConstants.CLUSTER_LOCKING_ENABLED);
            NodeSecurity identitySecurity = nodeService.findNodeSecurity(identity.getNodeId(), !isClusteringEnabled);
            if (engine.getParameterService().isRegistrationServer() || (identitySecurity != null && !identitySecurity.isRegistrationEnabled() && identitySecurity.getRegistrationTime() != null)) {
                List<NodeSecurity> nodeSecurities = findNodesThatAreReadyForInitialLoad();
                if (nodeSecurities != null && nodeSecurities.size() > 0) {
                    gapDetector.setFullGapAnalysis(true);
                    boolean reverseLoadFirst = parameterService.is(ParameterConstants.INITIAL_LOAD_REVERSE_FIRST);
                    boolean isInitialLoadQueued = false;
                    for (NodeSecurity security : nodeSecurities) {
                        if (engine.getTriggerRouterService().getActiveTriggerHistories().size() > 0) {
                            boolean thisMySecurityRecord = security.getNodeId().equals(identity.getNodeId());
                            boolean reverseLoadQueued = security.isRevInitialLoadEnabled();
                            boolean initialLoadQueued = security.isInitialLoadEnabled();
                            boolean registered = security.getRegistrationTime() != null;
                            if (thisMySecurityRecord && reverseLoadQueued && (reverseLoadFirst || !initialLoadQueued)) {
                                sendReverseInitialLoad(processInfo);
                            } else if (!thisMySecurityRecord && registered && initialLoadQueued && (!reverseLoadFirst || !reverseLoadQueued)) {
                                long ts = System.currentTimeMillis();
                                engine.getDataService().insertReloadEvents(engine.getNodeService().findNode(security.getNodeId()), false, processInfo);
                                isInitialLoadQueued = true;
                                ts = System.currentTimeMillis() - ts;
                                if (ts > Constants.LONG_OPERATION_THRESHOLD) {
                                    log.warn("Inserted reload events for node {} took longer than expected.  It took {} ms", security.getNodeId(), ts);
                                } else {
                                    log.info("Inserted reload events for node {} in {} ms", security.getNodeId(), ts);
                                }
                            }
                        } else {
                            List<NodeGroupLink> links = engine.getConfigurationService().getNodeGroupLinksFor(parameterService.getNodeGroupId(), false);
                            if (links == null || links.size() == 0) {
                                log.warn("Could not queue up a load for {} because a node group link is NOT configured over which a load could be delivered", security.getNodeId());
                            } else {
                                log.warn("Could not queue up a load for {} because sync triggers has not yet run", security.getNodeId());
                                if (!syncTriggersBeforeInitialLoadAttempted) {
                                    syncTriggersBeforeInitialLoadAttempted = true;
                                    engine.getTriggerRouterService().syncTriggers();
                                }
                            }
                        }
                    }
                    if (isInitialLoadQueued) {
                        gapDetector.setFullGapAnalysis(true);
                    }
                }
                processTableRequestLoads(identity, processInfo);
            }
        }
        processInfo.setStatus(ProcessInfo.Status.OK);
    } catch (Exception ex) {
        processInfo.setStatus(ProcessInfo.Status.ERROR);
        log.error("", ex);
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) SyntaxParsingException(org.jumpmind.symmetric.SyntaxParsingException) SymmetricException(org.jumpmind.symmetric.SymmetricException) DelayRoutingException(org.jumpmind.symmetric.route.DelayRoutingException)

Example 10 with ProcessInfoKey

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

the class DataGapFastDetector method beforeRouting.

public void beforeRouting() {
    maxDataToSelect = parameterService.getLong(ParameterConstants.ROUTING_LARGEST_GAP_SIZE);
    detectInvalidGaps = parameterService.is(ParameterConstants.ROUTING_DETECT_INVALID_GAPS);
    reset();
    if (isFullGapAnalysis()) {
        ProcessInfo processInfo = this.statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), null, ProcessType.GAP_DETECT));
        processInfo.setStatus(Status.QUERYING);
        log.info("Full gap analysis is running");
        long ts = System.currentTimeMillis();
        gaps = dataService.findDataGaps();
        if (detectInvalidGaps) {
            fixOverlappingGaps(gaps, processInfo);
        }
        queryDataIdMap();
        processInfo.setStatus(Status.OK);
        log.info("Querying data in gaps from database took {} ms", System.currentTimeMillis() - ts);
        afterRouting();
        reset();
        log.info("Full gap analysis is done after {} ms", System.currentTimeMillis() - ts);
    } else if (gaps == null || parameterService.is(ParameterConstants.CLUSTER_LOCKING_ENABLED)) {
        ProcessInfo processInfo = this.statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), null, ProcessType.GAP_DETECT));
        processInfo.setStatus(Status.QUERYING);
        gaps = dataService.findDataGaps();
        if (detectInvalidGaps) {
            fixOverlappingGaps(gaps, processInfo);
        }
        processInfo.setStatus(Status.OK);
    }
}
Also used : ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo)

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