use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class DataService method sendSchema.
public boolean sendSchema(String nodeId, String catalogName, String schemaName, String tableName, boolean isLoad) {
Node sourceNode = engine.getNodeService().findIdentity();
Node targetNode = engine.getNodeService().findNode(nodeId);
if (targetNode == null) {
log.error("Could not send schema to the node {}. It does not exist", nodeId);
return false;
}
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;
for (TriggerHistory triggerHistory : triggerHistories) {
List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
for (TriggerRouter triggerRouter : triggerRouters) {
eventCount++;
insertCreateEvent(targetNode, triggerHistory, triggerRouter.getRouter().getRouterId(), false, -1, null);
}
}
if (eventCount > 0) {
return true;
} else {
return false;
}
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class DataService method insertReloadEvents.
public void insertReloadEvents(Node targetNode, boolean reverse) {
if (engine.getClusterService().lock(ClusterConstants.SYNCTRIGGERS)) {
try {
synchronized (engine.getTriggerRouterService()) {
engine.getClusterService().lock(ClusterConstants.SYNCTRIGGERS);
if (!reverse) {
log.info("Queueing up an initial load to " + targetNode.getNodeId());
} else {
log.info("Queueing up a reverse initial load to " + targetNode.getNodeId());
}
/*
* Outgoing data events are pointless because we are
* reloading all data
*/
engine.getOutgoingBatchService().markAllAsSentForNode(targetNode.getNodeId(), false);
INodeService nodeService = engine.getNodeService();
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
Node sourceNode = nodeService.findIdentity();
boolean transactional = parameterService.is(ParameterConstants.DATA_RELOAD_IS_BATCH_INSERT_TRANSACTIONAL);
String nodeIdRecord = reverse ? nodeService.findIdentityNodeId() : targetNode.getNodeId();
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeIdRecord);
ISqlTransaction transaction = null;
try {
transaction = platform.getSqlTemplate().startSqlTransaction();
long loadId = engine.getSequenceService().nextVal(transaction, Constants.SEQUENCE_OUTGOING_BATCH_LOAD_ID);
String createBy = reverse ? nodeSecurity.getRevInitialLoadCreateBy() : nodeSecurity.getInitialLoadCreateBy();
List<TriggerHistory> triggerHistories = triggerRouterService.getActiveTriggerHistories();
Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = triggerRouterService.fillTriggerRoutersByHistIdAndSortHist(sourceNode.getNodeGroupId(), targetNode.getNodeGroupId(), triggerHistories);
callReloadListeners(true, targetNode, transactional, transaction, loadId);
insertCreateSchemaScriptPriorToReload(targetNode, nodeIdRecord, loadId, createBy, transactional, transaction);
insertSqlEventsPriorToReload(targetNode, nodeIdRecord, loadId, createBy, transactional, transaction, reverse);
insertCreateBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction);
insertDeleteBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction);
insertLoadBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction);
String afterSql = parameterService.getString(reverse ? ParameterConstants.INITIAL_LOAD_REVERSE_AFTER_SQL : ParameterConstants.INITIAL_LOAD_AFTER_SQL);
if (isNotBlank(afterSql)) {
insertSqlEvent(transaction, targetNode, afterSql, true, loadId, createBy);
}
insertFileSyncBatchForReload(targetNode, loadId, createBy, transactional, transaction);
callReloadListeners(false, targetNode, transactional, transaction, loadId);
if (!reverse) {
nodeService.setInitialLoadEnabled(transaction, nodeIdRecord, false, false, loadId, createBy);
} else {
nodeService.setReverseInitialLoadEnabled(transaction, nodeIdRecord, false, false, loadId, createBy);
}
if (!Constants.DEPLOYMENT_TYPE_REST.equals(targetNode.getDeploymentType())) {
insertNodeSecurityUpdate(transaction, nodeIdRecord, targetNode.getNodeId(), true, loadId, createBy);
}
engine.getStatisticManager().incrementNodesLoaded(1);
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 (!reverse) {
/*
* Remove all incoming events for the node that we are
* starting a reload for
*/
engine.getPurgeService().purgeAllIncomingEventsForNode(targetNode.getNodeId());
}
}
} finally {
engine.getClusterService().unlock(ClusterConstants.SYNCTRIGGERS);
}
} else {
log.info("Not attempting to insert reload events because sync trigger is currently running");
}
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class DataService method sendSQL.
public String sendSQL(String nodeId, String catalogName, String schemaName, String tableName, String sql) {
Node sourceNode = engine.getNodeService().findIdentity();
Node targetNode = engine.getNodeService().findNode(nodeId);
if (targetNode == null) {
return "Unknown node " + nodeId;
}
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
TriggerHistory triggerHistory = triggerRouterService.findTriggerHistory(catalogName, schemaName, tableName);
if (triggerHistory == null) {
return "Trigger for table " + tableName + " does not exist from node " + sourceNode.getNodeGroupId();
} else {
Trigger trigger = triggerRouterService.getTriggerById(true, triggerHistory.getTriggerId());
if (trigger != null) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
insertSqlEvent(transaction, triggerHistory, trigger.getChannelId(), targetNode, sql, false, -1, null);
transaction.commit();
return "Successfully create SQL event for node " + targetNode.getNodeId();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
close(transaction);
}
} else {
return "Trigger for table " + tableName + " does not exist from node " + sourceNode.getNodeGroupId();
}
}
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class RestService method syncTriggersImpl.
private void syncTriggersImpl(ISymmetricEngine engine, boolean force) {
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
StringBuilder buffer = new StringBuilder();
triggerRouterService.syncTriggers(buffer, force);
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class RestService method dropTriggersImpl.
private void dropTriggersImpl(ISymmetricEngine engine) {
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
triggerRouterService.dropTriggers();
}
Aggregations