Search in sources :

Example 6 with NodeSecurity

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

the class NodeService method setInitialLoadEnabled.

public boolean setInitialLoadEnabled(ISqlTransaction transaction, String nodeId, boolean initialLoadEnabled, boolean syncChange, long loadId, String createBy) {
    try {
        if (!syncChange) {
            symmetricDialect.disableSyncTriggers(transaction, nodeId);
        }
        NodeSecurity nodeSecurity = findOrCreateNodeSecurity(nodeId);
        if (nodeSecurity != null) {
            nodeSecurity.setInitialLoadEnabled(initialLoadEnabled);
            nodeSecurity.setInitialLoadId(loadId);
            if (initialLoadEnabled) {
                nodeSecurity.setInitialLoadTime(null);
                nodeSecurity.setInitialLoadCreateBy(createBy);
            } else {
                nodeSecurity.setInitialLoadTime(new Date());
            }
            return updateNodeSecurity(transaction, nodeSecurity);
        }
        return false;
    } finally {
        if (!syncChange) {
            symmetricDialect.enableSyncTriggers(transaction);
        }
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Date(java.util.Date)

Example 7 with NodeSecurity

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

the class NodeService method setReverseInitialLoadEnabled.

public boolean setReverseInitialLoadEnabled(ISqlTransaction transaction, String nodeId, boolean initialLoadEnabled, boolean syncChange, long loadId, String createBy) {
    try {
        if (!syncChange) {
            symmetricDialect.disableSyncTriggers(transaction, nodeId);
        }
        NodeSecurity nodeSecurity = findOrCreateNodeSecurity(nodeId);
        if (nodeSecurity != null) {
            nodeSecurity.setRevInitialLoadEnabled(initialLoadEnabled);
            nodeSecurity.setRevInitialLoadId(loadId);
            if (initialLoadEnabled) {
                nodeSecurity.setRevInitialLoadTime(null);
                nodeSecurity.setRevInitialLoadCreateBy(createBy);
            } else {
                nodeSecurity.setRevInitialLoadTime(new Date());
            }
            return updateNodeSecurity(transaction, nodeSecurity);
        }
        return false;
    } finally {
        if (!syncChange) {
            symmetricDialect.enableSyncTriggers(transaction);
        }
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Date(java.util.Date)

Example 8 with NodeSecurity

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

the class DataLoaderService method loadDataFromPush.

/**
     * Load database from input stream and write acknowledgment to output
     * stream. This is used for a "push" request with a response of an
     * acknowledgment.
     */
public void loadDataFromPush(Node sourceNode, String channelId, InputStream in, OutputStream out) throws IOException {
    Node local = nodeService.findIdentity();
    if (local != null) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(sourceNode.getNodeId(), channelId, local.getNodeId(), ProcessInfoKey.ProcessType.PUSH_HANDLER));
        try {
            List<IncomingBatch> batchList = loadDataFromTransport(processInfo, sourceNode, new InternalIncomingTransport(in), out);
            logDataReceivedFromPush(sourceNode, batchList);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId());
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            transportManager.writeAcknowledgement(out, sourceNode, batchList, local, security != null ? security.getNodePassword() : null);
            if (containsError(batchList)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
        } catch (Exception e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof IOException) {
                throw (IOException) e;
            }
            throw new RuntimeException(e);
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) InternalIncomingTransport(org.jumpmind.symmetric.transport.internal.InternalIncomingTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) SymmetricException(org.jumpmind.symmetric.SymmetricException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) ConflictException(org.jumpmind.symmetric.io.data.writer.ConflictException) IOException(java.io.IOException) RegistrationNotOpenException(org.jumpmind.symmetric.service.RegistrationNotOpenException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ServiceUnavailableException(org.jumpmind.symmetric.transport.ServiceUnavailableException) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) SqlException(org.jumpmind.db.sql.SqlException) TransportException(org.jumpmind.symmetric.transport.TransportException) RegistrationRequiredException(org.jumpmind.symmetric.service.RegistrationRequiredException) ConnectionRejectedException(org.jumpmind.symmetric.transport.ConnectionRejectedException) SyncDisabledException(org.jumpmind.symmetric.transport.SyncDisabledException) IoException(org.jumpmind.exception.IoException) MalformedURLException(java.net.MalformedURLException) AuthenticationException(org.jumpmind.symmetric.transport.AuthenticationException)

Example 9 with NodeSecurity

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

the class FileSyncService method loadFilesFromPush.

public void loadFilesFromPush(String nodeId, InputStream in, OutputStream out) {
    INodeService nodeService = engine.getNodeService();
    Node local = nodeService.findIdentity();
    Node sourceNode = nodeService.findNode(nodeId, true);
    if (local != null && sourceNode != null) {
        ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeId, local.getNodeId(), ProcessInfoKey.ProcessType.FILE_SYNC_PUSH_HANDLER));
        try {
            List<IncomingBatch> list = processZip(in, nodeId, processInfo);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId(), true);
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            engine.getTransportManager().writeAcknowledgement(out, sourceNode, list, local, security != null ? security.getNodePassword() : null);
            processInfo.setStatus(ProcessInfo.Status.OK);
        } catch (Throwable e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            if (e instanceof IOException) {
                throw new IoException((IOException) e);
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new RuntimeException(e);
            }
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeService(org.jumpmind.symmetric.service.INodeService) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) IoException(org.jumpmind.exception.IoException) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 10 with NodeSecurity

use of org.jumpmind.symmetric.model.NodeSecurity 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)

Aggregations

NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)31 Node (org.jumpmind.symmetric.model.Node)13 INodeService (org.jumpmind.symmetric.service.INodeService)12 Date (java.util.Date)7 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)7 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 IoException (org.jumpmind.exception.IoException)4 SymmetricException (org.jumpmind.symmetric.SymmetricException)4 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)4 NodeHost (org.jumpmind.symmetric.model.NodeHost)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 UniqueKeyException (org.jumpmind.db.sql.UniqueKeyException)3 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)2 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)2 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)2 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)2