Search in sources :

Example 1 with IOutgoingBatchService

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

the class PushService method push.

public synchronized RemoteNodeStatuses push(boolean force) {
    IConfigurationService configurationService = engine.getConfigurationService();
    IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
    INodeService nodeService = engine.getNodeService();
    IClusterService clusterService = engine.getClusterService();
    int availableThreadPairs = parameterService.getInt(ParameterConstants.PUSH_THREAD_COUNT_PER_SERVER);
    long minimumPeriodBetweenPushesMs = parameterService.getLong(ParameterConstants.PUSH_MINIMUM_PERIOD_MS, -1);
    RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
    Node identityNode = nodeService.findIdentity(false);
    if (identityNode != null && identityNode.isSyncEnabled()) {
        List<NodeHost> hosts = nodeService.findNodeHosts(identityNode.getNodeId());
        int clusterInstanceCount = hosts != null && hosts.size() > 0 ? hosts.size() : 1;
        NodeSecurity identitySecurity = nodeService.findNodeSecurity(identityNode.getNodeId());
        if (identitySecurity != null && (force || !clusterService.isInfiniteLocked(ClusterConstants.PUSH))) {
            Iterator<OutgoingBatchByNodeChannelCount> nodeChannels = outgoingBatchService.getOutgoingBatchByNodeChannelCount(availableThreadPairs * clusterInstanceCount, NodeGroupLinkAction.P, true).iterator();
            // based on percentage
            while (nodeChannels.hasNext() && pushWorkersWorking.size() < availableThreadPairs) {
                OutgoingBatchByNodeChannelCount batchCount = nodeChannels.next();
                String nodeId = batchCount.getNodeId();
                String channelId = batchCount.getChannelId();
                Node remoteNode = nodeService.findNode(nodeId);
                NodeChannel nodeChannel = configurationService.getNodeChannel(channelId, nodeId, false);
                if (nodeChannel != null && !nodeChannel.isFileSyncFlag() && !pushWorkersWorking.contains(nodeChannel)) {
                    boolean meetsMinimumTime = true;
                    // TODO error backoff logic
                    if (minimumPeriodBetweenPushesMs > 0 && nodeChannel.getLastExtractTime() != null && (System.currentTimeMillis() - nodeChannel.getLastExtractTime().getTime()) < minimumPeriodBetweenPushesMs) {
                        meetsMinimumTime = false;
                    }
                    if (meetsMinimumTime && clusterService.lockNodeChannel(ClusterConstants.PUSH, nodeId, channelId)) {
                        NodeChannelExtractForPushWorker worker = new NodeChannelExtractForPushWorker(remoteNode, identityNode, identitySecurity, nodeChannel, statuses.add(nodeId, channelId));
                        pushWorkersWorking.add(nodeChannel);
                        nodeChannelExtractForPushWorker.execute(worker);
                    }
                }
            }
        }
    }
    return statuses;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) NodeHost(org.jumpmind.symmetric.model.NodeHost) OutgoingBatchByNodeChannelCount(org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount) RemoteNodeStatuses(org.jumpmind.symmetric.model.RemoteNodeStatuses) INodeService(org.jumpmind.symmetric.service.INodeService) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) IClusterService(org.jumpmind.symmetric.service.IClusterService)

Example 2 with IOutgoingBatchService

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

the class SimpleIntegrationTest method test11SuspendIgnorePushRemoteBatches.

@Test(timeout = 120000)
public void test11SuspendIgnorePushRemoteBatches() throws Exception {
    // test suspend / ignore with remote database specifying the suspends
    // and ignores
    logTestRunning();
    Date date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
    Order order = new Order("101", 100, null, date);
    order.getOrderDetails().add(new OrderDetail("101", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
    assertNull(serverTestService.getOrder(order.getOrderId()));
    clientTestService.insertOrder(order);
    boolean pushedData = clientPush();
    logger.error("Done pushing data");
    assertTrue("Client data was not batched and pushed", pushedData);
    assertNotNull(serverTestService.getOrder(order.getOrderId()));
    IConfigurationService rootConfigurationService = getServer().getConfigurationService();
    IOutgoingBatchService clientOutgoingBatchService = getClient().getOutgoingBatchService();
    date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
    order = new Order("102", 100, null, date);
    order.getOrderDetails().add(new OrderDetail("102", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
    assertNull(serverTestService.getOrder(order.getOrderId()));
    clientTestService.insertOrder(order);
    getClient().route();
    NodeChannel c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(true);
    rootConfigurationService.saveNodeChannel(c, true);
    OutgoingBatches batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be 1 outgoing batches.", 1, batches.getBatches().size());
    pushedData = clientPush();
    assertNull("The order record was synchronized when it should not have been", serverTestService.getOrder(order.getOrderId()));
    c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setIgnoreEnabled(true);
    rootConfigurationService.saveNodeChannel(c, true);
    clientPush();
    batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches", 1, batches.getBatches().size());
    assertNull("The order record was synchronized when it should not have been", serverTestService.getOrder(order.getOrderId()));
    // Cleanup!
    c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(false);
    c.setIgnoreEnabled(false);
    rootConfigurationService.saveNodeChannel(c, true);
    clientPush();
    batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
    assertNotNull("The order record was synchronized when it should not have been", serverTestService.getOrder(order.getOrderId()));
}
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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with IOutgoingBatchService

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

the class SimpleIntegrationTest method test03InitialLoad.

@Test(timeout = 120000)
public void test03InitialLoad() {
    logTestRunning();
    serverTestService.insertIntoTestUseStreamLob(100, "test_use_stream_lob", THIS_IS_A_TEST);
    serverTestService.insertIntoTestUseStreamLob(100, "test_use_capture_lob", THIS_IS_A_TEST);
    Customer customer = new Customer(301, "Linus", true, "42 Blanket Street", "Santa Claus", "IN", 90009, new Date(), new Date(), THIS_IS_A_TEST, BINARY_DATA);
    serverTestService.insertCustomer(customer);
    serverTestService.insertIntoTestTriggerTable(new Object[] { 1, "wow", "mom" });
    serverTestService.insertIntoTestTriggerTable(new Object[] { 2, "mom", "wow" });
    INodeService rootNodeService = getServer().getNodeService();
    INodeService clientNodeService = getClient().getNodeService();
    String nodeId = rootNodeService.findNodeByExternalId(TestConstants.TEST_CLIENT_NODE_GROUP, TestConstants.TEST_CLIENT_EXTERNAL_ID).getNodeId();
    getServer().reloadNode(nodeId, "test");
    IOutgoingBatchService rootOutgoingBatchService = getServer().getOutgoingBatchService();
    assertFalse(rootOutgoingBatchService.isInitialLoadComplete(nodeId));
    assertTrue(rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isInitialLoadEnabled());
    do {
        clientPull();
    } while (!rootOutgoingBatchService.isInitialLoadComplete(nodeId));
    assertFalse(rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isInitialLoadEnabled());
    NodeSecurity clientNodeSecurity = clientNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID);
    assertFalse(clientNodeSecurity.isInitialLoadEnabled());
    assertNotNull(clientNodeSecurity.getInitialLoadTime());
    IIncomingBatchService clientIncomingBatchService = getClient().getIncomingBatchService();
    assertEquals("The initial load errored out." + printRootAndClientDatabases(), 0, clientIncomingBatchService.countIncomingBatchesInError());
    assertEquals("test_triggers_table on the client did not contain the expected number of rows", 2, clientTestService.countTestTriggersTable());
    assertEquals("test_customer on the client did not contain the expected number of rows", 2, clientTestService.count("test_customer"));
    assertEquals("Initial load was not successful according to the client", NodeStatus.DATA_LOAD_COMPLETED, clientNodeService.getNodeStatus());
    assertEquals("Initial load was not successful accordign to the root", false, rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isInitialLoadEnabled());
    clientTestService.assertTestBlobIsInDatabase(100, "test_use_capture_lob", THIS_IS_A_TEST);
    clientTestService.assertTestBlobIsInDatabase(100, "test_use_stream_lob", THIS_IS_A_TEST);
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) IIncomingBatchService(org.jumpmind.symmetric.service.IIncomingBatchService) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) Date(java.util.Date) Test(org.junit.Test)

Example 4 with IOutgoingBatchService

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

the class SimpleIntegrationTest method test12SuspendIgnorePushLocalBatches.

@Test(timeout = 120000)
public void test12SuspendIgnorePushLocalBatches() throws Exception {
    // test suspend / ignore with local database specifying the suspends
    // and ignores
    logTestRunning();
    Date date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
    Order order = new Order("105", 100, null, date);
    order.getOrderDetails().add(new OrderDetail("105", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
    assertNull(serverTestService.getOrder(order.getOrderId()));
    clientTestService.insertOrder(order);
    clientPush();
    assertNotNull(serverTestService.getOrder(order.getOrderId()));
    IConfigurationService clientConfigurationService = getClient().getConfigurationService();
    IOutgoingBatchService clientOutgoingBatchService = getClient().getOutgoingBatchService();
    NodeChannel c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(true);
    clientConfigurationService.saveNodeChannel(c, true);
    order = new Order("106", 100, null, date);
    order.getOrderDetails().add(new OrderDetail("106", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
    clientPush();
    OutgoingBatches batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches since suspended locally", 0, batches.getBatches().size());
    assertNull(serverTestService.getOrder(order.getOrderId()));
    c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setIgnoreEnabled(true);
    clientConfigurationService.saveNodeChannel(c, true);
    clientPush();
    batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches since suspended locally", 0, batches.getBatches().size());
    assertNull(serverTestService.getOrder(order.getOrderId()));
    // Cleanup!
    c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(false);
    c.setIgnoreEnabled(false);
    clientConfigurationService.saveNodeChannel(c, true);
    clientPush();
}
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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 5 with IOutgoingBatchService

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

the class AbstractIntegrationTest method assertNoPendingBatchesOnServer.

protected void assertNoPendingBatchesOnServer() {
    IOutgoingBatchService outgoingBatchService = getServer().getOutgoingBatchService();
    OutgoingBatches batches = outgoingBatchService.getOutgoingBatches(TestConstants.TEST_CLIENT_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)

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