Search in sources :

Example 21 with Trigger

use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.

the class ConfigurationChangedDataRouter method contextCommitted.

@Override
public void contextCommitted(SimpleRouterContext routingContext) {
    if (engine.getParameterService().is(ParameterConstants.AUTO_REFRESH_AFTER_CONFIG_CHANGED, true)) {
        if (routingContext.get(CTX_KEY_FLUSH_PARAMETERS_NEEDED) != null && engine.getParameterService().is(ParameterConstants.AUTO_SYNC_CONFIGURATION)) {
            log.info("About to refresh the cache of parameters because new configuration came through the data router");
            engine.getParameterService().rereadParameters();
        }
        if (routingContext.get(CTX_KEY_FLUSH_CHANNELS_NEEDED) != null) {
            log.info("Channels flushed because new channels came through the data router");
            engine.getConfigurationService().clearCache();
        }
        Object needsSynced = routingContext.get(CTX_KEY_RESYNC_NEEDED);
        if (needsSynced != null && engine.getParameterService().is(ParameterConstants.AUTO_SYNC_TRIGGERS) && engine.getParameterService().is(ParameterConstants.AUTO_SYNC_TRIGGERS_AFTER_CONFIG_CHANGED)) {
            if (Boolean.TRUE.equals(needsSynced)) {
                log.info("About to syncTriggers because new configuration came through the data router");
                engine.getTriggerRouterService().syncTriggers();
            } else if (needsSynced instanceof Set) {
                @SuppressWarnings("unchecked") Set<Trigger> triggers = (Set<Trigger>) needsSynced;
                for (Trigger trigger : triggers) {
                    log.info("About to sync the " + trigger.getTriggerId() + " trigger because a change was detected by the config data router");
                    engine.getTriggerRouterService().syncTrigger(trigger, null, false);
                }
            }
        }
        if (routingContext.get(CTX_KEY_FLUSH_TRANSFORMS_NEEDED) != null) {
            log.info("About to refresh the cache of transformation because new configuration came through the data router");
            engine.getTransformService().clearCache();
            log.info("About to clear the staging area because new transform configuration came through the data router");
            engine.getStagingManager().clean(0);
        }
        if (routingContext.get(CTX_KEY_FLUSH_CONFLICTS_NEEDED) != null) {
            log.info("About to refresh the cache of conflict settings because new configuration came through the data router");
            engine.getDataLoaderService().clearCache();
        }
        if (routingContext.get(CTX_KEY_FLUSH_LOADFILTERS_NEEDED) != null) {
            log.info("About to refresh the cache of load filters because new configuration came through the data router");
            engine.getLoadFilterService().clearCache();
        }
        if (routingContext.get(CTX_KEY_RESTART_JOBMANAGER_NEEDED) != null) {
            IJobManager jobManager = engine.getJobManager();
            if (jobManager != null) {
                log.info("About to restart jobs because new configuration come through the data router");
                jobManager.stopJobs();
                jobManager.startJobs();
            }
        }
        if (routingContext.get(CTX_KEY_REFRESH_EXTENSIONS_NEEDED) != null) {
            log.info("About to refresh the cache of extensions because new configuration came through the data router");
            engine.getExtensionService().refresh();
        }
        if (routingContext.get(CTX_KEY_FLUSH_MONITORS_NEEDED) != null) {
            log.info("About to refresh the cache of monitors because new configuration came through the data router");
            engine.getMonitorService().flushMonitorCache();
        }
        if (routingContext.get(CTX_KEY_FLUSH_NOTIFICATIONS_NEEDED) != null) {
            log.info("About to refresh the cache of notifications because new configuration came through the data router");
            engine.getMonitorService().flushNotificationCache();
        }
        if (routingContext.get(CTX_KEY_FLUSH_NODES_NEEDED) != null) {
            log.info("About to refresh the cache of nodes because new configuration came through the data router");
            engine.getNodeService().flushNodeCache();
            engine.getNodeService().flushNodeGroupCache();
        }
        if (routingContext.get(CTX_KEY_FLUSH_NODE_SECURITYS_NEEDED) != null) {
            log.info("About to refresh the cache of node security because new configuration came through the data router");
            engine.getNodeService().flushNodeAuthorizedCache();
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Trigger(org.jumpmind.symmetric.model.Trigger) IJobManager(org.jumpmind.symmetric.job.IJobManager)

Example 22 with Trigger

use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.

the class DbCompare method loadTablesFromConfig.

protected List<DbCompareTables> loadTablesFromConfig() {
    List<Trigger> triggers = sourceEngine.getTriggerRouterService().getTriggersForCurrentNode(true);
    List<String> configTables = TableConstants.getConfigTables(sourceEngine.getTablePrefix());
    List<String> tableNames = new ArrayList<String>();
    for (Trigger trigger : triggers) {
        if (!configTables.contains(trigger.getFullyQualifiedSourceTableName())) {
            tableNames.add(trigger.getFullyQualifiedSourceTableName());
        }
    }
    return loadTables(tableNames);
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) ArrayList(java.util.ArrayList)

Example 23 with Trigger

use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.

the class DataService method insertSqlEvent.

public void insertSqlEvent(Node targetNode, String sql, boolean isLoad, long loadId, String createBy) {
    TriggerHistory history = engine.getTriggerRouterService().findTriggerHistoryForGenericSync();
    Trigger trigger = engine.getTriggerRouterService().getTriggerById(history.getTriggerId(), false);
    String reloadChannelId = getReloadChannelIdForTrigger(trigger, engine.getConfigurationService().getChannels(false));
    Data data = new Data(history.getSourceTableName(), DataEventType.SQL, CsvUtils.escapeCsvData(sql), null, history, isLoad ? reloadChannelId : Constants.CHANNEL_CONFIG, null, null);
    if (isLoad) {
        insertDataAndDataEventAndOutgoingBatch(data, targetNode.getNodeId(), Constants.UNKNOWN_ROUTER_ID, isLoad, loadId, createBy);
    } else {
        data.setNodeList(targetNode.getNodeId());
        insertData(data);
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData)

Example 24 with Trigger

use of org.jumpmind.symmetric.model.Trigger 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();
                }
            }
        }
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) Table(org.jumpmind.db.model.Table) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Channel(org.jumpmind.symmetric.model.Channel) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) TableReloadRequest(org.jumpmind.symmetric.model.TableReloadRequest)

Example 25 with Trigger

use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.

the class DataService method insertCreateEvent.

public void insertCreateEvent(ISqlTransaction transaction, Node targetNode, TriggerHistory triggerHistory, String routerId, boolean isLoad, long loadId, String createBy) {
    Trigger trigger = engine.getTriggerRouterService().getTriggerById(triggerHistory.getTriggerId(), false);
    String reloadChannelId = getReloadChannelIdForTrigger(trigger, engine.getConfigurationService().getChannels(false));
    Data data = new Data(triggerHistory.getSourceTableName(), DataEventType.CREATE, null, null, triggerHistory, isLoad ? reloadChannelId : Constants.CHANNEL_CONFIG, null, null);
    data.setNodeList(targetNode.getNodeId());
    try {
        if (isLoad) {
            insertDataAndDataEventAndOutgoingBatch(transaction, data, targetNode.getNodeId(), routerId, isLoad, loadId, createBy, Status.NE);
        } else {
            insertData(transaction, data);
        }
    } catch (UniqueKeyException e) {
        if (e.getRootCause() != null && e.getRootCause() instanceof DataTruncation) {
            log.error("Table data definition XML was too large and failed.  The feature to send table creates during the initial load may be limited on your platform.  You may need to set the initial.load.create.first parameter to false.");
        }
        throw e;
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData) DataTruncation(java.sql.DataTruncation)

Aggregations

Trigger (org.jumpmind.symmetric.model.Trigger)42 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)20 ArrayList (java.util.ArrayList)17 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)14 Router (org.jumpmind.symmetric.model.Router)13 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)11 Test (org.junit.Test)11 Date (java.util.Date)5 Table (org.jumpmind.db.model.Table)5 CsvData (org.jumpmind.symmetric.io.data.CsvData)5 Data (org.jumpmind.symmetric.model.Data)5 Node (org.jumpmind.symmetric.model.Node)5 HashSet (java.util.HashSet)4 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)4 HashMap (java.util.HashMap)3 Set (java.util.Set)3 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)3 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)3 INodeService (org.jumpmind.symmetric.service.INodeService)3 List (java.util.List)2