use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class DataService method reloadTable.
public String reloadTable(String nodeId, String catalogName, String schemaName, String tableName, String overrideInitialLoadSelect) {
Node sourceNode = engine.getNodeService().findIdentity();
Node targetNode = engine.getNodeService().findNode(nodeId);
if (targetNode == null) {
return "Unknown node " + nodeId;
}
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
List<TriggerHistory> triggerHistories = triggerRouterService.findTriggerHistories(catalogName, schemaName, tableName);
Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = triggerRouterService.fillTriggerRoutersByHistIdAndSortHist(sourceNode.getNodeGroupId(), targetNode.getNodeGroupId(), triggerHistories);
int eventCount = 0;
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
for (TriggerHistory triggerHistory : triggerHistories) {
List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
if (triggerRouters != null && triggerRouters.size() > 0) {
for (TriggerRouter triggerRouter : triggerRouters) {
eventCount++;
insertReloadEvent(transaction, targetNode, triggerRouter, triggerHistory, overrideInitialLoadSelect, false, -1, "reloadTable", Status.NE);
}
}
}
transaction.commit();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
close(transaction);
}
if (eventCount > 0) {
return "Successfully created " + (eventCount > 1 ? eventCount + " events" : "event") + " to reload table " + tableName + " for node " + targetNode.getNodeId();
} else {
return "Trigger for table " + tableName + " does not exist for source node group of " + sourceNode.getNodeGroupId();
}
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class DataService method insertReloadEvent.
public boolean insertReloadEvent(TableReloadRequest request, boolean deleteAtClient) {
boolean successful = false;
if (request != null && request.isReloadEnabled()) {
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
INodeService nodeService = engine.getNodeService();
Node targetNode = nodeService.findNode(request.getTargetNodeId());
if (targetNode != null) {
TriggerRouter triggerRouter = triggerRouterService.getTriggerRouterForCurrentNode(request.getTriggerId(), request.getRouterId(), false);
if (triggerRouter != null) {
Trigger trigger = triggerRouter.getTrigger();
Router router = triggerRouter.getRouter();
NodeGroupLink link = router.getNodeGroupLink();
Node me = nodeService.findIdentity();
if (link.getSourceNodeGroupId().equals(me.getNodeGroupId())) {
if (link.getTargetNodeGroupId().equals(targetNode.getNodeGroupId())) {
TriggerHistory triggerHistory = lookupTriggerHistory(trigger);
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
if (parameterService.is(ParameterConstants.INITIAL_LOAD_DELETE_BEFORE_RELOAD)) {
String overrideDeleteStatement = StringUtils.isNotBlank(request.getReloadDeleteStmt()) ? request.getReloadDeleteStmt() : null;
insertPurgeEvent(transaction, targetNode, triggerRouter, triggerHistory, false, overrideDeleteStatement, -1, null);
}
insertReloadEvent(transaction, targetNode, triggerRouter, triggerHistory, request.getReloadSelect(), false, -1, null, Status.NE);
if (!targetNode.requires13Compatiblity() && deleteAtClient) {
insertSqlEvent(transaction, triggerHistory, trigger.getChannelId(), targetNode, String.format("delete from %s where target_node_id='%s' and source_node_id='%s' and trigger_id='%s' and router_id='%s'", TableConstants.getTableName(tablePrefix, TableConstants.SYM_TABLE_RELOAD_REQUEST), request.getTargetNodeId(), request.getSourceNodeId(), request.getTriggerId(), request.getRouterId()), false, -1, null);
}
deleteTableReloadRequest(transaction, request);
transaction.commit();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
close(transaction);
}
} else {
log.error("Could not reload table for node {} because the router {} target node group id {} did not match", new Object[] { request.getTargetNodeId(), request.getRouterId(), link.getTargetNodeGroupId() });
}
} else {
log.error("Could not reload table for node {} because the router {} source node group id {} did not match", new Object[] { request.getTargetNodeId(), request.getRouterId(), link.getSourceNodeGroupId() });
}
} else {
log.error("Could not reload table for node {} because the trigger router ({}, {}) could not be found", new Object[] { request.getTargetNodeId(), request.getTriggerId(), request.getRouterId() });
}
} else {
log.error("Could not reload table for node {} because the node could not be found", request.getTargetNodeId());
}
}
return successful;
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class DataService method insertFileSyncBatchForReload.
private void insertFileSyncBatchForReload(Node targetNode, long loadId, String createBy, boolean transactional, ISqlTransaction transaction) {
if (parameterService.is(ParameterConstants.FILE_SYNC_ENABLE) && !Constants.DEPLOYMENT_TYPE_REST.equals(targetNode.getDeploymentType())) {
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
IFileSyncService fileSyncService = engine.getFileSyncService();
if (fileSyncService.getFileTriggerRoutersForCurrentNode().size() > 0) {
TriggerHistory fileSyncSnapshotHistory = triggerRouterService.findTriggerHistory(null, null, TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT));
String routerid = triggerRouterService.buildSymmetricTableRouterId(fileSyncSnapshotHistory.getTriggerId(), parameterService.getNodeGroupId(), targetNode.getNodeGroupId());
TriggerRouter fileSyncSnapshotTriggerRouter = triggerRouterService.getTriggerRouterForCurrentNode(fileSyncSnapshotHistory.getTriggerId(), routerid, true);
List<Channel> channels = engine.getConfigurationService().getFileSyncChannels();
for (Channel channel : channels) {
if (channel.isReloadFlag()) {
insertReloadEvent(transaction, targetNode, fileSyncSnapshotTriggerRouter, fileSyncSnapshotHistory, "reload_channel_id='" + channel.getChannelId() + "'", true, loadId, createBy, Status.NE, channel.getChannelId());
if (!transactional) {
transaction.commit();
}
}
}
}
}
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouter method queueSyncTriggers.
@SuppressWarnings("unchecked")
protected void queueSyncTriggers(SimpleRouterContext routingContext, DataMetaData dataMetaData, Map<String, String> columnValues) {
if ((tableMatches(dataMetaData, TableConstants.SYM_TRIGGER) || tableMatches(dataMetaData, TableConstants.SYM_TRIGGER_ROUTER))) {
Object needResync = routingContext.get(CTX_KEY_RESYNC_NEEDED);
if (needResync == null || needResync instanceof Set) {
if (needResync == null) {
needResync = new HashSet<Trigger>();
routingContext.put(CTX_KEY_RESYNC_NEEDED, needResync);
}
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
String triggerId = columnValues.get("TRIGGER_ID");
Trigger trigger = triggerRouterService.getTriggerById(true, triggerId);
if (trigger != null) {
((Set<Trigger>) needResync).add(trigger);
} else {
routingContext.put(CTX_KEY_RESYNC_NEEDED, Boolean.TRUE);
}
}
} else if (tableMatches(dataMetaData, TableConstants.SYM_ROUTER) || tableMatches(dataMetaData, TableConstants.SYM_NODE_GROUP_LINK)) {
routingContext.put(CTX_KEY_RESYNC_NEEDED, Boolean.TRUE);
}
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class AbstractDataExtractorServiceTest method setupForTest.
@Before
public void setupForTest() {
ITriggerRouterService triggerRouterService = getTriggerRouterService();
TriggerRouter triggerRouter = triggerRouterService.findTriggerRouterById(true, TEST_TABLE, TestConstants.ROUTER_ID_ROOT_2_TEST);
if (triggerRouter == null) {
triggerRouter = new TriggerRouter(new Trigger(TEST_TABLE, TestConstants.TEST_CHANNEL_ID), new Router(TestConstants.ROUTER_ID_ROOT_2_TEST, TestConstants.ROOT_2_TEST));
triggerRouterService.saveTriggerRouter(triggerRouter);
triggerRouterService.syncTriggers();
getDbDialect().truncateTable(TEST_TABLE);
}
resetBatches();
}
Aggregations