Search in sources :

Example 16 with OutgoingBatch

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

the class OutgoingBatchService method markAllAsSentForNode.

public void markAllAsSentForNode(String nodeId, boolean includeConfigChannel) {
    OutgoingBatches batches = null;
    int configCount;
    do {
        configCount = 0;
        batches = getOutgoingBatches(nodeId, true);
        List<OutgoingBatch> list = batches.getBatches();
        /*
             * Sort in reverse order so we don't get fk errors for batches that
             * are currently processing. We don't make the update transactional
             * to prevent contention in highly loaded systems
             */
        Collections.sort(list, new Comparator<OutgoingBatch>() {

            public int compare(OutgoingBatch o1, OutgoingBatch o2) {
                return -new Long(o1.getBatchId()).compareTo(o2.getBatchId());
            }
        });
        for (OutgoingBatch outgoingBatch : list) {
            if (includeConfigChannel || !outgoingBatch.getChannelId().equals(Constants.CHANNEL_CONFIG)) {
                outgoingBatch.setStatus(Status.OK);
                outgoingBatch.setErrorFlag(false);
                updateOutgoingBatch(outgoingBatch);
            } else {
                configCount++;
            }
        }
    } while (batches.getBatches().size() > configCount);
}
Also used : OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 17 with OutgoingBatch

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

the class OutgoingBatchService method getBatchesForChannelWindows.

public List<OutgoingBatch> getBatchesForChannelWindows(OutgoingBatches batches, String targetNodeId, NodeChannel channel, List<NodeGroupChannelWindow> windows) {
    List<OutgoingBatch> keeping = new ArrayList<OutgoingBatch>();
    List<OutgoingBatch> current = batches.getBatches();
    if (current != null && current.size() > 0) {
        if (inTimeWindow(windows, targetNodeId)) {
            int maxBatchesToSend = channel.getMaxBatchToSend();
            for (OutgoingBatch outgoingBatch : current) {
                if (channel.getChannelId().equals(outgoingBatch.getChannelId()) && maxBatchesToSend > 0) {
                    keeping.add(outgoingBatch);
                    maxBatchesToSend--;
                }
            }
        }
    }
    return keeping;
}
Also used : ArrayList(java.util.ArrayList) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 18 with OutgoingBatch

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

the class DataService method insertDataEventAndOutgoingBatch.

protected long insertDataEventAndOutgoingBatch(ISqlTransaction transaction, long dataId, String channelId, String nodeId, DataEventType eventType, String routerId, boolean isLoad, long loadId, String createBy, Status status, String tableName) {
    OutgoingBatch outgoingBatch = new OutgoingBatch(nodeId, channelId, status);
    outgoingBatch.setLoadId(loadId);
    outgoingBatch.setCreateBy(createBy);
    outgoingBatch.setLoadFlag(isLoad);
    outgoingBatch.incrementEventCount(eventType);
    if (tableName != null) {
        outgoingBatch.incrementTableCount(tableName.toLowerCase());
    }
    if (status == Status.RQ) {
        outgoingBatch.setExtractJobFlag(true);
    }
    engine.getOutgoingBatchService().insertOutgoingBatch(transaction, outgoingBatch);
    insertDataEvent(transaction, new DataEvent(dataId, outgoingBatch.getBatchId(), routerId));
    return outgoingBatch.getBatchId();
}
Also used : OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) DataEvent(org.jumpmind.symmetric.model.DataEvent)

Example 19 with OutgoingBatch

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

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

the class RouterService method insertDataEvents.

protected int insertDataEvents(ProcessInfo processInfo, ChannelRouterContext context, DataMetaData dataMetaData, Collection<String> nodeIds) {
    int numberOfDataEventsInserted = 0;
    if (nodeIds == null || nodeIds.size() == 0) {
        nodeIds = new HashSet<String>(1);
        nodeIds.add(Constants.UNROUTED_NODE_ID);
    }
    long ts = System.currentTimeMillis();
    long batchIdToReuse = -1;
    boolean dataEventAdded = false;
    for (String nodeId : nodeIds) {
        if (nodeId != null) {
            Map<String, OutgoingBatch> batches = context.getBatchesByNodes();
            OutgoingBatch batch = batches.get(nodeId);
            if (batch == null) {
                batch = new OutgoingBatch(nodeId, dataMetaData.getNodeChannel().getChannelId(), Status.RT);
                batch.setBatchId(batchIdToReuse);
                batch.setCommonFlag(context.isProduceCommonBatches());
                log.debug("About to insert a new batch for node {} on the '{}' channel.  Batches in progress are: {}.", new Object[] { nodeId, batch.getChannelId(), context.getBatchesByNodes().values() });
                engine.getOutgoingBatchService().insertOutgoingBatch(batch);
                processInfo.incrementBatchCount();
                context.getBatchesByNodes().put(nodeId, batch);
                // if in reuse mode, then share the batch id
                if (context.isProduceCommonBatches()) {
                    batchIdToReuse = batch.getBatchId();
                }
            }
            if (dataMetaData.getData().getDataEventType() == DataEventType.RELOAD) {
                long loadId = context.getLastLoadId();
                if (loadId < 0) {
                    loadId = engine.getSequenceService().nextVal(context.getSqlTransaction(), Constants.SEQUENCE_OUTGOING_BATCH_LOAD_ID);
                    context.setLastLoadId(loadId);
                }
                batch.setLoadId(loadId);
            } else {
                context.setLastLoadId(-1);
            }
            batch.incrementEventCount(dataMetaData.getData().getDataEventType());
            batch.incrementDataEventCount();
            batch.incrementTableCount(dataMetaData.getTable().getNameLowerCase());
            if (!context.isProduceCommonBatches() || (context.isProduceCommonBatches() && !dataEventAdded)) {
                Router router = dataMetaData.getRouter();
                context.addDataEvent(dataMetaData.getData().getDataId(), batch.getBatchId(), router != null ? router.getRouterId() : Constants.UNKNOWN_ROUTER_ID);
                numberOfDataEventsInserted++;
                dataEventAdded = true;
            }
            Map<String, IBatchAlgorithm> batchAlgorithms = extensionService.getExtensionPointMap(IBatchAlgorithm.class);
            if (batchAlgorithms.get(context.getChannel().getBatchAlgorithm()).isBatchComplete(batch, dataMetaData, context)) {
                context.setNeedsCommitted(true);
            }
        }
    }
    context.incrementStat(System.currentTimeMillis() - ts, ChannelRouterContext.STAT_INSERT_DATA_EVENTS_MS);
    return numberOfDataEventsInserted;
}
Also used : IBatchAlgorithm(org.jumpmind.symmetric.route.IBatchAlgorithm) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) AuditTableDataRouter(org.jumpmind.symmetric.route.AuditTableDataRouter) LookupTableDataRouter(org.jumpmind.symmetric.route.LookupTableDataRouter) AbstractFileParsingRouter(org.jumpmind.symmetric.route.AbstractFileParsingRouter) ConfigurationChangedDataRouter(org.jumpmind.symmetric.route.ConfigurationChangedDataRouter) SubSelectDataRouter(org.jumpmind.symmetric.route.SubSelectDataRouter) FileSyncDataRouter(org.jumpmind.symmetric.route.FileSyncDataRouter) ColumnMatchDataRouter(org.jumpmind.symmetric.route.ColumnMatchDataRouter) Router(org.jumpmind.symmetric.model.Router) DefaultDataRouter(org.jumpmind.symmetric.route.DefaultDataRouter) BshDataRouter(org.jumpmind.symmetric.route.BshDataRouter) IDataRouter(org.jumpmind.symmetric.route.IDataRouter) DBFRouter(org.jumpmind.symmetric.route.DBFRouter) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Aggregations

OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)37 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)12 ArrayList (java.util.ArrayList)10 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)9 Node (org.jumpmind.symmetric.model.Node)8 IStagedResource (org.jumpmind.symmetric.io.stage.IStagedResource)6 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)6 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)5 SymmetricException (org.jumpmind.symmetric.SymmetricException)4 ProtocolDataWriter (org.jumpmind.symmetric.io.data.writer.ProtocolDataWriter)4 BatchAck (org.jumpmind.symmetric.model.BatchAck)4 Channel (org.jumpmind.symmetric.model.Channel)4 File (java.io.File)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 CancellationException (java.util.concurrent.CancellationException)3 IoException (org.jumpmind.exception.IoException)3 DataContext (org.jumpmind.symmetric.io.data.DataContext)3 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)3 BufferedReader (java.io.BufferedReader)2