Search in sources :

Example 1 with TriggerHistory

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

the class DatabaseUpgradeListener method dropTriggers.

protected void dropTriggers(Database currentModel, String tableName, String columnName) {
    Table table = currentModel.findTable(tableName);
    if (table != null && table.findColumn(columnName) != null) {
        TriggerHistory hist = engine.getTriggerRouterService().findTriggerHistory(null, null, tableName);
        if (hist != null) {
            log.info("Dropping triggers on " + tableName + " because " + columnName + " needs dropped");
            engine.getTriggerRouterService().dropTriggers(hist);
        }
    }
}
Also used : Table(org.jumpmind.db.model.Table) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory)

Example 2 with TriggerHistory

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

the class DataService method insertFileSyncBatchForReload.

private void insertFileSyncBatchForReload(Node targetNode, long loadId, String createBy, boolean transactional, ISqlTransaction transaction, ProcessInfo processInfo) {
    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<TriggerHistory> triggerHistories = Arrays.asList(fileSyncSnapshotHistory);
            List<TriggerRouter> triggerRouters = Arrays.asList(fileSyncSnapshotTriggerRouter);
            Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = new HashMap<Integer, List<TriggerRouter>>();
            triggerRoutersByHistoryId.put(fileSyncSnapshotHistory.getTriggerHistoryId(), triggerRouters);
            if (parameterService.is(ParameterConstants.INITIAL_LOAD_USE_EXTRACT_JOB)) {
                insertLoadBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, null, processInfo);
            } else {
                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();
                        }
                    }
                }
            }
        }
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) HashMap(java.util.HashMap) Channel(org.jumpmind.symmetric.model.Channel) IFileSyncService(org.jumpmind.symmetric.service.IFileSyncService) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with TriggerHistory

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

the class DataService method insertReloadEvents.

public void insertReloadEvents(Node targetNode, boolean reverse, List<TableReloadRequest> reloadRequests, ProcessInfo processInfo) {
    if (engine.getClusterService().lock(ClusterConstants.SYNCTRIGGERS)) {
        try {
            synchronized (engine.getTriggerRouterService()) {
                engine.getClusterService().lock(ClusterConstants.SYNCTRIGGERS);
                boolean isFullLoad = reloadRequests == null || (reloadRequests.size() == 1 && reloadRequests.get(0).isFullLoadRequest());
                if (!reverse) {
                    log.info("Queueing up " + (isFullLoad ? "an initial" : "a") + " load to node " + targetNode.getNodeId());
                } else {
                    log.info("Queueing up a reverse " + (isFullLoad ? "initial" : "") + " load to node " + targetNode.getNodeId());
                }
                /*
                     * Outgoing data events are pointless because we are
                     * reloading all data
                     */
                if (isFullLoad) {
                    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);
                    processInfo.setCurrentLoadId(loadId);
                    String createBy = reverse ? nodeSecurity.getRevInitialLoadCreateBy() : nodeSecurity.getInitialLoadCreateBy();
                    List<TriggerHistory> triggerHistories = new ArrayList<TriggerHistory>();
                    if (isFullLoad) {
                        triggerHistories = triggerRouterService.getActiveTriggerHistories();
                    } else {
                        for (TableReloadRequest reloadRequest : reloadRequests) {
                            triggerHistories.addAll(engine.getTriggerRouterService().getActiveTriggerHistories(new Trigger(reloadRequest.getTriggerId(), null)));
                        }
                    }
                    processInfo.setDataCount(triggerHistories.size());
                    Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = triggerRouterService.fillTriggerRoutersByHistIdAndSortHist(sourceNode.getNodeGroupId(), targetNode.getNodeGroupId(), triggerHistories);
                    if (isFullLoad) {
                        callReloadListeners(true, targetNode, transactional, transaction, loadId);
                        insertCreateSchemaScriptPriorToReload(targetNode, nodeIdRecord, loadId, createBy, transactional, transaction);
                    }
                    Map<String, TableReloadRequest> mapReloadRequests = convertReloadListToMap(reloadRequests);
                    String symNodeSecurityReloadChannel = null;
                    try {
                        symNodeSecurityReloadChannel = triggerRoutersByHistoryId.get(triggerHistories.get(0).getTriggerHistoryId()).get(0).getTrigger().getReloadChannelId();
                    } catch (Exception e) {
                    }
                    if (isFullLoad || (reloadRequests != null && reloadRequests.size() > 0)) {
                        insertSqlEventsPriorToReload(targetNode, nodeIdRecord, loadId, createBy, transactional, transaction, reverse, triggerHistories, triggerRoutersByHistoryId, mapReloadRequests, isFullLoad, symNodeSecurityReloadChannel);
                    }
                    insertCreateBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, mapReloadRequests);
                    insertDeleteBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, mapReloadRequests);
                    insertSQLBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, mapReloadRequests);
                    insertLoadBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, mapReloadRequests, processInfo);
                    if (isFullLoad) {
                        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, processInfo);
                    if (isFullLoad) {
                        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, symNodeSecurityReloadChannel);
                    }
                    engine.getStatisticManager().incrementNodesLoaded(1);
                    if (reloadRequests != null && reloadRequests.size() > 0) {
                        for (TableReloadRequest request : reloadRequests) {
                            transaction.prepareAndExecute(getSql("updateProcessedTableReloadRequest"), loadId, new Date(), request.getTargetNodeId(), request.getSourceNodeId(), request.getTriggerId(), request.getRouterId(), request.getCreateTime());
                        }
                        log.info("Table reload request(s) for load id " + loadId + " have been processed.");
                    }
                    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");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) Node(org.jumpmind.symmetric.model.Node) ArrayList(java.util.ArrayList) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) NotImplementedException(org.apache.commons.lang.NotImplementedException) SymmetricException(org.jumpmind.symmetric.SymmetricException) IoException(org.jumpmind.exception.IoException) Date(java.util.Date) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Trigger(org.jumpmind.symmetric.model.Trigger) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) INodeService(org.jumpmind.symmetric.service.INodeService) TableReloadRequest(org.jumpmind.symmetric.model.TableReloadRequest) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with TriggerHistory

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

the class XmlPublisherDataRouterTest method testPublishUpdateAsXml.

@Test
public void testPublishUpdateAsXml() {
    Data data = new Data();
    data.setDataEventType(DataEventType.UPDATE);
    data.setRowData("2,updated data");
    data.setTriggerHistory(new TriggerHistory(TABLE_NAME, "ID", "ID,DATA"));
    data.setTableName(TABLE_NAME);
    router.routeToNodes(context, new DataMetaData(data, table, null, null), null, false, false, null);
    router.contextCommitted(context);
    assertEquals(UPDATE_XML.trim(), output.toString().trim());
}
Also used : TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 5 with TriggerHistory

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

the class XmlPublisherDataRouterTest method testPublishInsertAsXml.

@Test
public void testPublishInsertAsXml() {
    Data data = new Data();
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,new inserted data");
    data.setTriggerHistory(new TriggerHistory(TABLE_NAME, "ID", "ID,DATA"));
    data.setTableName(TABLE_NAME);
    router.routeToNodes(context, new DataMetaData(data, table, null, null), null, false, false, null);
    router.contextCommitted(context);
    assertEquals(INSERT_XML.trim(), output.toString().trim());
}
Also used : TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Aggregations

TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)55 Table (org.jumpmind.db.model.Table)20 Data (org.jumpmind.symmetric.model.Data)19 Node (org.jumpmind.symmetric.model.Node)17 Trigger (org.jumpmind.symmetric.model.Trigger)15 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)15 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)14 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 Router (org.jumpmind.symmetric.model.Router)10 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)9 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)9 List (java.util.List)7 CsvData (org.jumpmind.symmetric.io.data.CsvData)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)5 Channel (org.jumpmind.symmetric.model.Channel)5 TableReloadRequest (org.jumpmind.symmetric.model.TableReloadRequest)5 HashMap (java.util.HashMap)4 Date (java.util.Date)3