use of org.jumpmind.symmetric.service.IConfigurationService 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()));
}
use of org.jumpmind.symmetric.service.IConfigurationService 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();
}
use of org.jumpmind.symmetric.service.IConfigurationService in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouterTest method buildTestableRouter.
protected IDataRouter buildTestableRouter(final Node nodeThatIsRouting, final List<NodeGroupLink> links, final NetworkedNode root) {
IConfigurationService configService = mock(IConfigurationService.class);
when(configService.isMasterToMaster()).thenReturn(false);
ISymmetricEngine engine = mock(ISymmetricEngine.class);
when(engine.getConfigurationService()).thenReturn(configService);
when(engine.getTablePrefix()).thenReturn("sym");
ConfigurationChangedDataRouter router = new ConfigurationChangedDataRouter(engine) {
@Override
protected Node findIdentity() {
return nodeThatIsRouting;
}
@Override
protected List<NodeGroupLink> getNodeGroupLinksFromContext(SimpleRouterContext routingContext) {
return links;
}
@Override
protected NetworkedNode getRootNetworkNodeFromContext(SimpleRouterContext routingContext) {
return root;
}
};
return router;
}
use of org.jumpmind.symmetric.service.IConfigurationService in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouter method routeToNodes.
@SuppressWarnings("unchecked")
public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> possibleTargetNodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
// the list of nodeIds that we will return
Set<String> nodeIds = new HashSet<String>();
// the inbound data
Map<String, String> columnValues = getDataMap(dataMetaData, engine != null ? engine.getSymmetricDialect() : null);
Node me = findIdentity();
if (me != null) {
NetworkedNode rootNetworkedNode = getRootNetworkNodeFromContext(routingContext);
if (tableMatches(dataMetaData, TableConstants.SYM_NODE) || tableMatches(dataMetaData, TableConstants.SYM_NODE_SECURITY) || tableMatches(dataMetaData, TableConstants.SYM_NODE_HOST)) {
/*
* If this is sym_node or sym_node_security determine which
* nodes it goes to.
*/
routeNodeTables(nodeIds, columnValues, rootNetworkedNode, me, routingContext, dataMetaData, possibleTargetNodes, initialLoad);
} else if (tableMatches(dataMetaData, TableConstants.SYM_TABLE_RELOAD_REQUEST)) {
String sourceNodeId = columnValues.get("SOURCE_NODE_ID");
String reloadEnabled = columnValues.get("RELOAD_ENABLED");
if (me.getNodeId().equals(sourceNodeId)) {
if ("1".equals(reloadEnabled)) {
List<TableReloadRequestKey> list = (List<TableReloadRequestKey>) routingContext.get(CTX_KEY_TABLE_RELOAD_NEEDED);
if (list == null) {
list = new ArrayList<TableReloadRequestKey>();
routingContext.put(CTX_KEY_TABLE_RELOAD_NEEDED, list);
}
String targetNodeId = columnValues.get("TARGET_NODE_ID");
String routerId = columnValues.get("ROUTER_ID");
String triggerId = columnValues.get("TRIGGER_ID");
list.add(new TableReloadRequestKey(targetNodeId, sourceNodeId, triggerId, routerId, dataMetaData.getData().getSourceNodeId()));
}
} else {
for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeThatMayBeRoutedTo.requires13Compatiblity() && nodeThatMayBeRoutedTo.getNodeId().equals(sourceNodeId)) {
nodeIds.add(sourceNodeId);
}
}
}
} else {
IConfigurationService configurationService = engine.getConfigurationService();
for (Node nodeThatMayBeRoutedTo : possibleTargetNodes) {
if (!Constants.DEPLOYMENT_TYPE_REST.equals(nodeThatMayBeRoutedTo.getDeploymentType()) && !nodeThatMayBeRoutedTo.requires13Compatiblity() && (initialLoad || !isSameNumberOfLinksAwayFromRoot(nodeThatMayBeRoutedTo, rootNetworkedNode, me))) {
NodeGroupLink link = configurationService.getNodeGroupLinkFor(me.getNodeGroupId(), nodeThatMayBeRoutedTo.getNodeGroupId(), false);
if (initialLoad || (link != null && link.isSyncConfigEnabled())) {
nodeIds.add(nodeThatMayBeRoutedTo.getNodeId());
}
}
}
if (StringUtils.isBlank(dataMetaData.getData().getSourceNodeId())) {
queueSyncTriggers(routingContext, dataMetaData, columnValues);
}
if (tableMatches(dataMetaData, TableConstants.SYM_CHANNEL)) {
routingContext.put(CTX_KEY_FLUSH_CHANNELS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_CONFLICT)) {
routingContext.put(CTX_KEY_FLUSH_CONFLICTS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_LOAD_FILTER)) {
routingContext.put(CTX_KEY_FLUSH_LOADFILTERS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_PARAMETER)) {
routingContext.put(CTX_KEY_FLUSH_PARAMETERS_NEEDED, Boolean.TRUE);
if (me.getExternalId().equals(columnValues.get("EXTERNAL_ID")) && me.getNodeGroupId().equals(columnValues.get("NODE_GROUP_ID"))) {
nodeIds.clear();
}
if (StringUtils.isBlank(dataMetaData.getData().getSourceNodeId()) && (dataMetaData.getData().getRowData() != null && dataMetaData.getData().getRowData().contains("job."))) {
routingContext.put(CTX_KEY_RESTART_JOBMANAGER_NEEDED, Boolean.TRUE);
}
}
if (tableMatches(dataMetaData, TableConstants.SYM_TRANSFORM_COLUMN) || tableMatches(dataMetaData, TableConstants.SYM_TRANSFORM_TABLE)) {
routingContext.put(CTX_KEY_FLUSH_TRANSFORMS_NEEDED, Boolean.TRUE);
}
if (tableMatches(dataMetaData, TableConstants.SYM_EXTENSION)) {
routingContext.put(CTX_KEY_REFRESH_EXTENSIONS_NEEDED, Boolean.TRUE);
}
}
}
return nodeIds;
}
use of org.jumpmind.symmetric.service.IConfigurationService in project symmetric-ds by JumpMind.
the class CopyNodeUriHandler method handle.
public void handle(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
IRegistrationService registrationService = engine.getRegistrationService();
IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
INodeService nodeService = engine.getNodeService();
IConfigurationService configurationService = engine.getConfigurationService();
String identityNodeId = nodeService.findIdentityNodeId();
String copyFromNodeId = req.getParameter(WebConstants.NODE_ID);
String newExternalId = req.getParameter(WebConstants.EXTERNAL_ID);
String newGroupId = req.getParameter(WebConstants.NODE_GROUP_ID);
String newNodeId = registrationService.openRegistration(newGroupId, newExternalId);
log.info("Received a copy request. New external_id={}, new node_group_id={}, old node_id={}, new node_id={}", new Object[] { newExternalId, newGroupId, copyFromNodeId, newNodeId });
Set<String> channelIds = configurationService.getChannels(false).keySet();
for (String channelId : channelIds) {
String batchId = req.getParameter(channelId + "-" + identityNodeId);
if (isNotBlank(batchId)) {
outgoingBatchService.copyOutgoingBatches(channelId, NumberUtils.toLong(batchId.trim()), copyFromNodeId, newNodeId);
}
}
}
Aggregations