Search in sources :

Example 11 with IOutgoingBatchService

use of org.jumpmind.symmetric.service.IOutgoingBatchService in project symmetric-ds by JumpMind.

the class SimpleIntegrationTest method test16SuspendIgnorePullLocalBatches.

@Test(timeout = 120000)
public void test16SuspendIgnorePullLocalBatches() throws Exception {
    // test suspend / ignore with local database specifying suspends and
    // ignores
    logTestRunning();
    // Should not sync when status = null
    Date date = DateUtils.parseDate("2009-09-30", new String[] { "yyyy-MM-dd" });
    Order order = new Order("44", 100, "C", date);
    serverTestService.insertOrder(order);
    clientPull();
    IOutgoingBatchService rootOutgoingBatchService = getServer().getOutgoingBatchService();
    OutgoingBatches batches = rootOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_CLIENT_NODE.getNodeId(), false);
    assertNotNull(clientTestService.getOrder(order.getOrderId()));
    assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
    // Suspend the channel...
    IConfigurationService clientConfigurationService = getClient().getConfigurationService();
    NodeChannel c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(true);
    clientConfigurationService.saveNodeChannel(c, true);
    order = new Order("45", 100, "C", date);
    serverTestService.insertOrder(order);
    clientPull();
    batches = rootOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_CLIENT_NODE.getNodeId(), false);
    assertNull(clientTestService.getOrder(order.getOrderId()));
    assertEquals("There should be 1 outgoing batches", 1, batches.getBatches().size());
    c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setIgnoreEnabled(true);
    clientConfigurationService.saveNodeChannel(c, true);
    // ignore
    clientPull();
    assertNoPendingBatchesOnServer();
    c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(false);
    c.setIgnoreEnabled(false);
    clientConfigurationService.saveNodeChannel(c, true);
    clientPull();
}
Also used : FixMethodOrder(org.junit.FixMethodOrder) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) Date(java.util.Date) Test(org.junit.Test)

Example 12 with IOutgoingBatchService

use of org.jumpmind.symmetric.service.IOutgoingBatchService in project symmetric-ds by JumpMind.

the class AbstractIntegrationTest method assertNoPendingBatchesOnClient.

protected void assertNoPendingBatchesOnClient() {
    IOutgoingBatchService outgoingBatchService = getClient().getOutgoingBatchService();
    OutgoingBatches batches = outgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
}
Also used : IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches)

Example 13 with IOutgoingBatchService

use of org.jumpmind.symmetric.service.IOutgoingBatchService in project symmetric-ds by JumpMind.

the class AcknowledgeService method ack.

public BatchAckResult ack(final BatchAck batch) {
    IRegistrationService registrationService = engine.getRegistrationService();
    IStagingManager stagingManager = engine.getStagingManager();
    IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
    BatchAckResult result = new BatchAckResult(batch);
    for (IAcknowledgeEventListener listener : engine.getExtensionService().getExtensionPointList(IAcknowledgeEventListener.class)) {
        listener.onAcknowledgeEvent(batch);
    }
    if (batch.getBatchId() == Constants.VIRTUAL_BATCH_FOR_REGISTRATION) {
        if (batch.getStatus() == Status.OK) {
            registrationService.markNodeAsRegistered(batch.getNodeId());
        }
    } else {
        OutgoingBatch outgoingBatch = outgoingBatchService.findOutgoingBatch(batch.getBatchId(), batch.getNodeId());
        Status status = batch.getStatus();
        if (outgoingBatch != null) {
            // is OK.
            if (outgoingBatch.getStatus() != Status.OK && outgoingBatch.getStatus() != Status.IG) {
                outgoingBatch.setStatus(status);
                outgoingBatch.setErrorFlag(batch.getStatus() == Status.ER);
            } else {
                // clearing the error flag in case the user set the batch
                // status to OK
                Status oldStatus = outgoingBatch.getStatus();
                outgoingBatch.setStatus(Status.OK);
                outgoingBatch.setErrorFlag(false);
                log.info("Batch {} for {} was set to {}.  Updating the status to OK", new Object[] { batch.getBatchId(), batch.getNodeId(), oldStatus.name() });
            }
            if (batch.isIgnored()) {
                outgoingBatch.incrementIgnoreCount();
            }
            outgoingBatch.setNetworkMillis(batch.getNetworkMillis());
            outgoingBatch.setFilterMillis(batch.getFilterMillis());
            outgoingBatch.setLoadMillis(batch.getDatabaseMillis());
            outgoingBatch.setSqlCode(batch.getSqlCode());
            outgoingBatch.setSqlState(batch.getSqlState());
            outgoingBatch.setSqlMessage(batch.getSqlMessage());
            if (batch.getStatus() == Status.ER && batch.getErrorLine() != 0) {
                List<Number> ids = sqlTemplate.query(getSql("selectDataIdSql"), new NumberMapper(), outgoingBatch.getBatchId());
                if (ids.size() >= batch.getErrorLine()) {
                    outgoingBatch.setFailedDataId(ids.get((int) batch.getErrorLine() - 1).longValue());
                }
            }
            if (status == Status.ER) {
                log.error("The outgoing batch {} failed{}", outgoingBatch.getNodeBatchId(), batch.getSqlMessage() != null ? ". " + batch.getSqlMessage() : "");
                RouterStats routerStats = engine.getStatisticManager().getRouterStatsByBatch(batch.getBatchId());
                if (routerStats != null) {
                    log.info("Router stats for batch " + outgoingBatch.getBatchId() + ": " + routerStats.toString());
                }
            } else if (!outgoingBatch.isCommonFlag()) {
                IStagedResource stagingResource = stagingManager.find(Constants.STAGING_CATEGORY_OUTGOING, outgoingBatch.getNodeId(), outgoingBatch.getBatchId());
                if (stagingResource != null) {
                    stagingResource.setState(State.DONE);
                }
            }
            outgoingBatchService.updateOutgoingBatch(outgoingBatch);
            if (status == Status.OK) {
                Channel channel = engine.getConfigurationService().getChannel(outgoingBatch.getChannelId());
                if (channel != null && channel.isFileSyncFlag()) {
                    /* Acknowledge the file_sync in case the file needs deleted. */
                    engine.getFileSyncService().acknowledgeFiles(outgoingBatch);
                }
                engine.getStatisticManager().removeRouterStatsByBatch(batch.getBatchId());
            }
        } else {
            log.error("Could not find batch {}-{} to acknowledge as {}", new Object[] { batch.getNodeId(), batch.getBatchId(), status.name() });
            result.setOk(false);
        }
    }
    return result;
}
Also used : Status(org.jumpmind.symmetric.model.OutgoingBatch.Status) NumberMapper(org.jumpmind.db.sql.mapper.NumberMapper) IAcknowledgeEventListener(org.jumpmind.symmetric.transport.IAcknowledgeEventListener) IRegistrationService(org.jumpmind.symmetric.service.IRegistrationService) Channel(org.jumpmind.symmetric.model.Channel) IStagingManager(org.jumpmind.symmetric.io.stage.IStagingManager) BatchAckResult(org.jumpmind.symmetric.model.BatchAckResult) RouterStats(org.jumpmind.symmetric.statistic.RouterStats) IStagedResource(org.jumpmind.symmetric.io.stage.IStagedResource) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Aggregations

IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)13 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)8 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)7 Test (org.junit.Test)7 Date (java.util.Date)6 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)6 FixMethodOrder (org.junit.FixMethodOrder)5 INodeService (org.jumpmind.symmetric.service.INodeService)3 BigDecimal (java.math.BigDecimal)2 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)2 IRegistrationService (org.jumpmind.symmetric.service.IRegistrationService)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 NumberMapper (org.jumpmind.db.sql.mapper.NumberMapper)1 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)1 IStagedResource (org.jumpmind.symmetric.io.stage.IStagedResource)1 IStagingManager (org.jumpmind.symmetric.io.stage.IStagingManager)1 BatchAckResult (org.jumpmind.symmetric.model.BatchAckResult)1 Channel (org.jumpmind.symmetric.model.Channel)1 Node (org.jumpmind.symmetric.model.Node)1 NodeHost (org.jumpmind.symmetric.model.NodeHost)1