Search in sources :

Example 21 with OutgoingBatches

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

the class FileSyncService method getBatchesToProcess.

protected List<OutgoingBatch> getBatchesToProcess(Node targetNode) {
    List<OutgoingBatch> batchesToProcess = new ArrayList<OutgoingBatch>();
    List<Channel> fileSyncChannels = engine.getConfigurationService().getFileSyncChannels();
    OutgoingBatches batches = engine.getOutgoingBatchService().getOutgoingBatches(targetNode.getNodeId(), false);
    for (Channel channel : fileSyncChannels) {
        batchesToProcess.addAll(batches.filterBatchesForChannel(channel));
    }
    return batchesToProcess;
}
Also used : Channel(org.jumpmind.symmetric.model.Channel) ArrayList(java.util.ArrayList) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches)

Example 22 with OutgoingBatches

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

the class OutgoingBatchService method getOutgoingBatches.

@Override
public OutgoingBatches getOutgoingBatches(String nodeId, String channelThread, NodeGroupLinkAction eventAction, NodeGroupLinkAction defaultEventAction, boolean includeDisabledChannels) {
    long ts = System.currentTimeMillis();
    final int maxNumberOfBatchesToSelect = parameterService.getInt(ParameterConstants.OUTGOING_BATCH_MAX_BATCHES_TO_SELECT, 1000);
    String sql = null;
    Object[] params = null;
    int[] types = null;
    if (eventAction != null) {
        if (eventAction.equals(defaultEventAction)) {
            sql = getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchChannelActionNullSql");
        } else {
            sql = getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchChannelActionSql");
        }
        params = new Object[] { eventAction.name(), nodeId, channelThread, OutgoingBatch.Status.RQ.name(), OutgoingBatch.Status.NE.name(), OutgoingBatch.Status.QY.name(), OutgoingBatch.Status.SE.name(), OutgoingBatch.Status.LD.name(), OutgoingBatch.Status.ER.name(), OutgoingBatch.Status.IG.name(), OutgoingBatch.Status.RS.name() };
        types = new int[] { Types.CHAR, Types.VARCHAR, Types.VARCHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR };
    } else if (channelThread != null) {
        sql = getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchChannelSql");
        params = new Object[] { nodeId, channelThread, OutgoingBatch.Status.RQ.name(), OutgoingBatch.Status.NE.name(), OutgoingBatch.Status.QY.name(), OutgoingBatch.Status.SE.name(), OutgoingBatch.Status.LD.name(), OutgoingBatch.Status.ER.name(), OutgoingBatch.Status.IG.name(), OutgoingBatch.Status.RS.name() };
        types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR };
    } else {
        sql = getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchSql");
        params = new Object[] { nodeId, OutgoingBatch.Status.RQ.name(), OutgoingBatch.Status.NE.name(), OutgoingBatch.Status.QY.name(), OutgoingBatch.Status.SE.name(), OutgoingBatch.Status.LD.name(), OutgoingBatch.Status.ER.name(), OutgoingBatch.Status.IG.name(), OutgoingBatch.Status.RS.name() };
        types = new int[] { Types.VARCHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR };
    }
    List<OutgoingBatch> list = (List<OutgoingBatch>) sqlTemplate.query(sql, maxNumberOfBatchesToSelect, new OutgoingBatchMapper(includeDisabledChannels), params, types);
    OutgoingBatches batches = new OutgoingBatches(list);
    List<NodeChannel> channels = new ArrayList<NodeChannel>(configurationService.getNodeChannels(nodeId, true));
    batches.sortChannels(channels);
    List<IOutgoingBatchFilter> filters = extensionService.getExtensionPointList(IOutgoingBatchFilter.class);
    List<OutgoingBatch> keepers = new ArrayList<OutgoingBatch>();
    for (NodeChannel channel : channels) {
        List<OutgoingBatch> batchesForChannel = getBatchesForChannelWindows(batches, nodeId, channel, configurationService.getNodeGroupChannelWindows(parameterService.getNodeGroupId(), channel.getChannelId()));
        if (filters != null) {
            for (IOutgoingBatchFilter filter : filters) {
                batchesForChannel = filter.filter(channel, batchesForChannel);
            }
        }
        if (parameterService.is(ParameterConstants.DATA_EXTRACTOR_ENABLED) || channel.getChannelId().equals(Constants.CHANNEL_CONFIG)) {
            keepers.addAll(batchesForChannel);
        }
    }
    batches.setBatches(keepers);
    long executeTimeInMs = System.currentTimeMillis() - ts;
    if (executeTimeInMs > Constants.LONG_OPERATION_THRESHOLD) {
        log.info("Selecting {} outgoing batch rows for node {} on queue '{}' took {} ms", list.size(), nodeId, channelThread, executeTimeInMs);
    }
    return batches;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) IOutgoingBatchFilter(org.jumpmind.symmetric.ext.IOutgoingBatchFilter) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 23 with OutgoingBatches

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

the class OutgoingBatchService method markAllConfigAsSentForNode.

public void markAllConfigAsSentForNode(String nodeId) {
    int updateCount;
    do {
        updateCount = 0;
        OutgoingBatches batches = getOutgoingBatches(nodeId, false);
        List<OutgoingBatch> list = batches.getBatches();
        for (OutgoingBatch outgoingBatch : list) {
            if (outgoingBatch.getChannelId().equals(Constants.CHANNEL_CONFIG)) {
                outgoingBatch.setStatus(Status.OK);
                outgoingBatch.setErrorFlag(false);
                outgoingBatch.setIgnoreCount(1);
                updateOutgoingBatch(outgoingBatch);
                updateCount++;
            }
        }
    } while (updateCount > 0);
}
Also used : OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 24 with OutgoingBatches

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

the class OutgoingBatchService method getOutgoingBatchErrors.

public OutgoingBatches getOutgoingBatchErrors(int maxRows) {
    OutgoingBatches batches = new OutgoingBatches();
    batches.setBatches(sqlTemplate.query(getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchErrorsSql"), maxRows, new OutgoingBatchMapper(true), null, null));
    return batches;
}
Also used : OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches)

Example 25 with OutgoingBatches

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

the class AbstractRouterServiceTest method testSyncIncomingBatchWhenUnrouted.

public void testSyncIncomingBatchWhenUnrouted() throws Exception {
    resetBatches();
    TriggerRouter triggerRouter = getTestRoutingTableTrigger(TEST_TABLE_1);
    triggerRouter.getTrigger().setSyncOnIncomingBatch(true);
    triggerRouter.getRouter().setRouterType("bsh");
    triggerRouter.getRouter().setRouterExpression("return " + NODE_GROUP_NODE_1.getNodeId());
    getTriggerRouterService().saveTriggerRouter(triggerRouter);
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(1000);
    testChannel.setMaxBatchSize(50);
    testChannel.setBatchAlgorithm("default");
    getConfigurationService().saveChannel(testChannel, true);
    getTriggerRouterService().syncTriggers();
    insert(TEST_TABLE_1, 10, true, NODE_GROUP_NODE_1.getNodeId());
    int unroutedCount = countUnroutedBatches();
    getRouterService().routeData(true);
    OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals("Should have been 0.  We did the insert as if the data had come from node 1.", 0, batches.getBatches().size());
    Assert.assertTrue(countUnroutedBatches() > unroutedCount);
    resetBatches();
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Aggregations

OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)34 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)15 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)8 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Date (java.util.Date)5 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)5 FixMethodOrder (org.junit.FixMethodOrder)5 File (java.io.File)3 ProtocolDataWriter (org.jumpmind.symmetric.io.data.writer.ProtocolDataWriter)3 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 IOutgoingBatchFilter (org.jumpmind.symmetric.ext.IOutgoingBatchFilter)2 IDataWriter (org.jumpmind.symmetric.io.data.IDataWriter)2 Channel (org.jumpmind.symmetric.model.Channel)2 FileTriggerRouter (org.jumpmind.symmetric.model.FileTriggerRouter)2 IFileSyncService (org.jumpmind.symmetric.service.IFileSyncService)2