use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class RouterService method onlyDefaultRoutersAssigned.
protected boolean onlyDefaultRoutersAssigned(Channel channel, String nodeGroupId, List<TriggerRouter> triggerRouters) {
String channelId = channel.getChannelId();
Boolean onlyDefaultRoutersAssigned = defaultRouterOnlyLastKnownState.get(channelId);
long cacheTime = parameterService.getLong(ParameterConstants.CACHE_CHANNEL_DEFAULT_ROUTER_IN_MS);
if (onlyDefaultRoutersAssigned == null || System.currentTimeMillis() - defaultRoutersCacheTime > cacheTime) {
onlyDefaultRoutersAssigned = !Constants.CHANNEL_CONFIG.equals(channelId) && !channel.isFileSyncFlag() && !channel.isReloadFlag() && !Constants.CHANNEL_HEARTBEAT.equals(channelId) ? true : false;
if (onlyDefaultRoutersAssigned && triggerRouters != null) {
for (TriggerRouter triggerRouter : triggerRouters) {
if (triggerRouter.getTrigger().getChannelId().equals(channel.getChannelId()) && triggerRouter.getRouter().getNodeGroupLink().getSourceNodeGroupId().equals(nodeGroupId) && !"default".equals(triggerRouter.getRouter().getRouterType())) {
onlyDefaultRoutersAssigned = false;
}
}
}
if (!onlyDefaultRoutersAssigned.equals(defaultRouterOnlyLastKnownState.get(channelId))) {
if (onlyDefaultRoutersAssigned) {
log.info("The '{}' channel for the '{}' node group has only default routers assigned to it. Change data won't be selected during routing", channelId, nodeGroupId);
}
defaultRouterOnlyLastKnownState.put(channelId, onlyDefaultRoutersAssigned);
}
defaultRoutersCacheTime = System.currentTimeMillis();
}
return onlyDefaultRoutersAssigned;
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class RouterService method findAvailableNodes.
protected Set<Node> findAvailableNodes(TriggerRouter triggerRouter, ChannelRouterContext context) {
Set<Node> nodes = context.getAvailableNodes().get(triggerRouter);
if (nodes == null) {
nodes = new HashSet<Node>();
Router router = triggerRouter.getRouter();
NodeGroupLink link = engine.getConfigurationService().getNodeGroupLinkFor(router.getNodeGroupLink().getSourceNodeGroupId(), router.getNodeGroupLink().getTargetNodeGroupId(), false);
if (link != null) {
nodes.addAll(engine.getNodeService().findEnabledNodesFromNodeGroup(router.getNodeGroupLink().getTargetNodeGroupId()));
} else {
log.error("The router {} has no node group link configured from {} to {}", new Object[] { router.getRouterId(), router.getNodeGroupLink().getSourceNodeGroupId(), router.getNodeGroupLink().getTargetNodeGroupId() });
}
context.getAvailableNodes().put(triggerRouter, nodes);
}
return engine.getGroupletService().getTargetEnabled(triggerRouter, nodes);
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class DbCompare method getTriggerRouterFor.
protected TriggerRouter getTriggerRouterFor(Table sourceTable) {
// TODO get routers.
Set<TriggerRouter> triggerRouters = sourceEngine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(sourceTable.getCatalog(), sourceTable.getSchema(), sourceTable.getName(), false);
for (TriggerRouter triggerRouter : triggerRouters) {
String routerTargetNodeGroupId = triggerRouter.getRouter().getNodeGroupLink().getTargetNodeGroupId();
String compareTargetNodeGroupId = targetEngine.getNodeService().getCachedIdentity().getNodeGroupId();
if (StringUtils.equals(compareTargetNodeGroupId, routerTargetNodeGroupId)) {
return triggerRouter;
}
}
return null;
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class LookupTableDataRouter method routeToNodes.
public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
Set<String> nodeIds = null;
Router router = dataMetaData.getRouter();
Map<String, String> params = null;
params = getParams(router, routingContext);
Map<String, String> dataMap = getDataMap(dataMetaData, symmetricDialect);
Map<String, Set<String>> lookupTable = getLookupTable(params, router, routingContext);
String column = params.get(PARAM_KEY_COLUMN);
if (dataMap.containsKey(column)) {
String keyData = dataMap.get(column);
Set<String> externalIds = lookupTable.get(keyData);
if (externalIds != null) {
for (Node node : nodes) {
if (externalIds.contains(node.getExternalId())) {
nodeIds = addNodeId(node.getNodeId(), nodeIds, nodes);
}
}
}
} else {
log.error("Could not route data with an id of {} using the {} router because the column {} was not captured for the {} table", new Object[] { dataMetaData.getData().getDataId(), getClass().getSimpleName(), column, dataMetaData.getTable().getName() });
}
return nodeIds;
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class DataService method insertLoadBatchesForReload.
private void insertLoadBatchesForReload(Node targetNode, long loadId, String createBy, List<TriggerHistory> triggerHistories, Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId, boolean transactional, ISqlTransaction transaction, Map<String, TableReloadRequest> reloadRequests, ProcessInfo processInfo) {
Map<String, Channel> channels = engine.getConfigurationService().getChannels(false);
for (TriggerHistory triggerHistory : triggerHistories) {
List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
processInfo.incrementCurrentDataCount();
for (TriggerRouter triggerRouter : triggerRouters) {
if (triggerRouter.getInitialLoadOrder() >= 0 && engine.getGroupletService().isTargetEnabled(triggerRouter, targetNode)) {
String selectSql = null;
if (reloadRequests != null) {
TableReloadRequest reloadRequest = reloadRequests.get(triggerRouter.getTriggerId() + triggerRouter.getRouterId());
selectSql = reloadRequest != null ? reloadRequest.getReloadSelect() : null;
}
if (StringUtils.isBlank(selectSql)) {
selectSql = StringUtils.isBlank(triggerRouter.getInitialLoadSelect()) ? Constants.ALWAYS_TRUE_CONDITION : triggerRouter.getInitialLoadSelect();
}
if (parameterService.is(ParameterConstants.INITIAL_LOAD_USE_EXTRACT_JOB)) {
Trigger trigger = triggerRouter.getTrigger();
String reloadChannel = getReloadChannelIdForTrigger(trigger, channels);
Channel channel = channels.get(reloadChannel);
Table table = platform.getTableFromCache(triggerHistory.getSourceCatalogName(), triggerHistory.getSourceSchemaName(), triggerHistory.getSourceTableName(), false);
processInfo.setCurrentTableName(table.getName());
int numberOfBatches = getNumberOfReloadBatches(table, triggerRouter, channel, targetNode, selectSql);
long startBatchId = -1;
long endBatchId = -1;
for (int i = 0; i < numberOfBatches; i++) {
// needs to grab the start and end batch id
endBatchId = insertReloadEvent(transaction, targetNode, triggerRouter, triggerHistory, selectSql, true, loadId, createBy, Status.RQ);
if (startBatchId == -1) {
startBatchId = endBatchId;
}
}
engine.getDataExtractorService().requestExtractRequest(transaction, targetNode.getNodeId(), channel.getQueue(), triggerRouter, startBatchId, endBatchId);
} else {
insertReloadEvent(transaction, targetNode, triggerRouter, triggerHistory, selectSql, true, loadId, createBy, Status.NE);
}
if (!transactional) {
transaction.commit();
}
}
}
}
}
Aggregations