use of org.jumpmind.symmetric.model.NodeChannel in project symmetric-ds by JumpMind.
the class ColumnMatchDataRouterTest method testExpressionEqualsExternalId.
@Test
public void testExpressionEqualsExternalId() {
ColumnMatchDataRouter router = new ColumnMatchDataRouter();
SimpleRouterContext routingContext = new SimpleRouterContext();
HashSet<Node> nodes = new HashSet<Node>();
nodes.add(new Node("1000", "client"));
nodes.add(new Node("100", "client"));
nodes.add(new Node("10", "client"));
TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,STORE_ID,COLUMN2");
Data data = new Data();
data.setDataId(1);
data.setDataEventType(DataEventType.INSERT);
data.setRowData("1,100,Super Dooper");
data.setTriggerHistory(triggerHist);
Table table = new Table();
NodeChannel nodeChannel = new NodeChannel();
Router route = new Router();
route.setRouterExpression("STORE_ID = :EXTERNAL_ID");
route.setRouterId("route1");
DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
assertEquals(1, result.size());
assertEquals(true, result.contains("100"));
}
use of org.jumpmind.symmetric.model.NodeChannel in project symmetric-ds by JumpMind.
the class ColumnMatchDataRouterTest method testExpressionNotContains.
@Test
public void testExpressionNotContains() {
ColumnMatchDataRouter router = new ColumnMatchDataRouter();
SimpleRouterContext routingContext = new SimpleRouterContext();
HashSet<Node> nodes = new HashSet<Node>();
nodes.add(new Node("100", "client"));
nodes.add(new Node("200", "client"));
nodes.add(new Node("300", "client"));
nodes.add(new Node("1000", "client"));
TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
Data data = new Data();
data.setDataId(1);
data.setDataEventType(DataEventType.INSERT);
data.setRowData("1,100,Super Dooper");
data.setExternalData("1000,200");
data.setTriggerHistory(triggerHist);
Table table = new Table();
NodeChannel nodeChannel = new NodeChannel();
Router route = new Router();
route.setRouterExpression("EXTERNAL_DATA not contains :NODE_ID");
route.setRouterId("route1");
DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
assertEquals(2, result.size());
assertEquals(true, result.contains("100"));
assertEquals(true, result.contains("300"));
}
use of org.jumpmind.symmetric.model.NodeChannel in project symmetric-ds by JumpMind.
the class ConfigurationService method getNodeChannels.
public List<NodeChannel> getNodeChannels(final String nodeId, boolean refreshExtractMillis) {
boolean loaded = false;
long channelCacheTimeoutInMs = parameterService.getLong(ParameterConstants.CACHE_TIMEOUT_CHANNEL_IN_MS);
List<NodeChannel> nodeChannels = nodeChannelCache != null ? nodeChannelCache.get(nodeId) : null;
if (System.currentTimeMillis() - nodeChannelCacheTime >= channelCacheTimeoutInMs || nodeChannels == null) {
synchronized (this) {
if (System.currentTimeMillis() - nodeChannelCacheTime >= channelCacheTimeoutInMs || nodeChannelCache == null || nodeChannelCache.get(nodeId) == null || nodeChannels == null) {
if (System.currentTimeMillis() - nodeChannelCacheTime >= channelCacheTimeoutInMs || nodeChannelCache == null) {
nodeChannelCache = new HashMap<String, List<NodeChannel>>();
nodeChannelCacheTime = System.currentTimeMillis();
}
if (nodeId != null) {
nodeChannels = sqlTemplate.query(getSql("selectNodeChannelsSql"), new NodeChannelMapper(nodeId), nodeId);
nodeChannelCache.put(nodeId, nodeChannels);
loaded = true;
} else {
nodeChannels = new ArrayList<NodeChannel>(0);
}
}
}
}
if (!loaded && refreshExtractMillis) {
/*
* need to read last extracted time from database regardless of
* whether we used the cache or not. locate the nodes in the cache,
* and update it.
*/
final Map<String, NodeChannel> nodeChannelsMap = new HashMap<String, NodeChannel>();
boolean usingExtractPeriod = false;
for (NodeChannel nc : nodeChannels) {
nodeChannelsMap.put(nc.getChannelId(), nc);
usingExtractPeriod |= nc.getExtractPeriodMillis() > 0;
}
if (usingExtractPeriod) {
sqlTemplate.query(getSql("selectNodeChannelControlLastExtractTimeSql"), new ISqlRowMapper<Object>() {
public Object mapRow(Row row) {
String channelId = row.getString("channel_id");
Date extractTime = row.getDateTime("last_extract_time");
NodeChannel nodeChannel = nodeChannelsMap.get(channelId);
if (nodeChannel != null) {
nodeChannel.setLastExtractTime(extractTime);
}
return nodeChannelsMap;
}
;
}, nodeId);
}
}
return nodeChannels;
}
use of org.jumpmind.symmetric.model.NodeChannel in project symmetric-ds by JumpMind.
the class ConfigurationService method initDefaultChannels.
@Override
public void initDefaultChannels() {
if (defaultChannels != null) {
clearCache();
createDefaultChannels();
List<NodeChannel> channels = getNodeChannels(false);
for (Channel defaultChannel : defaultChannels.values()) {
Channel channel = defaultChannel.findInList(channels);
if (channel == null) {
log.info("Auto-configuring {} channel", defaultChannel.getChannelId());
saveChannel(defaultChannel, true);
} else if (channel.getChannelId().equals(Constants.CHANNEL_RELOAD) && !channel.isReloadFlag()) {
log.info("Setting reload flag on reload channel");
channel.setReloadFlag(true);
saveChannel(channel, true);
} else if (channel.getChannelId().equals(Constants.CHANNEL_FILESYNC) && !channel.isFileSyncFlag()) {
log.info("Setting file sync flag on file sync channel");
channel.setFileSyncFlag(true);
saveChannel(channel, true);
} else if (channel.getChannelId().equals(Constants.CHANNEL_FILESYNC_RELOAD) && (!channel.isFileSyncFlag() || !channel.isReloadFlag())) {
log.info("Setting reload and file sync flag on file sync reload channel");
channel.setFileSyncFlag(true);
saveChannel(channel, true);
} else {
log.debug("No need to create channel {}. It already exists", defaultChannel.getChannelId());
}
}
clearCache();
}
}
use of org.jumpmind.symmetric.model.NodeChannel 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;
}
Aggregations