Search in sources :

Example 21 with NodeSecurity

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

the class NodeService method findOrCreateNodeSecurity.

public NodeSecurity findOrCreateNodeSecurity(String nodeId) {
    try {
        if (nodeId != null) {
            NodeSecurity security = findNodeSecurity(nodeId, false);
            if (security == null) {
                insertNodeSecurity(nodeId);
                security = findNodeSecurity(nodeId, true);
            }
            return security;
        } else {
            log.debug("A 'null' node id was passed into findNodeSecurity");
            return null;
        }
    } catch (UniqueKeyException ex) {
        log.error("Could not find a node security row for '{}'", nodeId);
        throw ex;
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException)

Example 22 with NodeSecurity

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

the class NodeService method isNodeAuthorized.

/**
     * Check that the given node and password match in the node_security table.
     * A node must authenticate before it's allowed to sync data.
     */
public boolean isNodeAuthorized(String nodeId, String password) {
    Map<String, NodeSecurity> nodeSecurities = findAllNodeSecurity(true);
    NodeSecurity nodeSecurity = nodeSecurities.get(nodeId);
    if (nodeSecurity != null && !nodeId.equals(findIdentityNodeId()) && ((nodeSecurity.getNodePassword() != null && !nodeSecurity.getNodePassword().equals("") && nodeSecurity.getNodePassword().equals(password)) || nodeSecurity.isRegistrationEnabled())) {
        return true;
    }
    return false;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity)

Example 23 with NodeSecurity

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

the class PushService method pushToNode.

private void pushToNode(Node remote, RemoteNodeStatus status) {
    Node identity = nodeService.findIdentity();
    NodeSecurity identitySecurity = nodeService.findNodeSecurity(identity.getNodeId(), true);
    IOutgoingWithResponseTransport transport = null;
    ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(identity.getNodeId(), status.getChannelId(), remote.getNodeId(), ProcessType.PUSH_JOB));
    Map<String, String> requestProperties = new HashMap<String, String>();
    requestProperties.put(WebConstants.THREAD_CHANNEL, status.getChannelId());
    try {
        transport = transportManager.getPushTransport(remote, identity, identitySecurity.getNodePassword(), requestProperties, parameterService.getRegistrationUrl());
        List<OutgoingBatch> extractedBatches = dataExtractorService.extract(processInfo, remote, status.getChannelId(), transport);
        if (extractedBatches.size() > 0) {
            log.info("Push data sent to {}", remote);
            List<BatchAck> batchAcks = readAcks(extractedBatches, transport, transportManager, acknowledgeService);
            status.updateOutgoingStatus(extractedBatches, batchAcks);
        }
        if (processInfo.getStatus() != Status.ERROR) {
            processInfo.setStatus(Status.OK);
        }
        fireOnline(remote, status);
    } catch (Exception ex) {
        processInfo.setStatus(Status.ERROR);
        fireOffline(ex, remote, status);
    } finally {
        try {
            transport.close();
        } catch (Exception e) {
        }
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) HashMap(java.util.HashMap) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) BatchAck(org.jumpmind.symmetric.model.BatchAck) IOutgoingWithResponseTransport(org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 24 with NodeSecurity

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

the class OutgoingBatchService method areAllLoadBatchesComplete.

public boolean areAllLoadBatchesComplete(String nodeId) {
    NodeSecurity security = nodeService.findNodeSecurity(nodeId);
    if (security == null || security.isInitialLoadEnabled()) {
        return false;
    }
    List<String> statuses = (List<String>) sqlTemplate.query(getSql("initialLoadStatusSql"), new StringMapper(), nodeId, 1);
    if (statuses == null || statuses.size() == 0) {
        throw new RuntimeException("The initial load has not been started for " + nodeId);
    }
    for (String status : statuses) {
        if (!Status.OK.name().equals(status)) {
            return false;
        }
    }
    return true;
}
Also used : StringMapper(org.jumpmind.db.sql.mapper.StringMapper) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with NodeSecurity

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

the class TriggerRouterService method syncTriggers.

public void syncTriggers(StringBuilder sqlBuffer, boolean force) {
    if ((parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS) || isCalledFromSymmetricAdminTool())) {
        synchronized (this) {
            if (clusterService.lock(ClusterConstants.SYNCTRIGGERS)) {
                try {
                    String additionalMessage = "";
                    if (isCalledFromSymmetricAdminTool() && !parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
                        additionalMessage = " " + ParameterConstants.AUTO_SYNC_TRIGGERS + " is set to false, but the sync triggers process will run so that needed changes can be written to a file so they can be applied manually.  Once all of the triggers have been successfully applied this process should not show triggers being created";
                    }
                    log.info("Synchronizing triggers{}", additionalMessage);
                    // make sure all tables are freshly read in
                    platform.resetCachedTableModel();
                    clearCache();
                    // make sure channels are read from the database
                    configurationService.clearCache();
                    List<Trigger> triggersForCurrentNode = getTriggersForCurrentNode();
                    boolean createTriggersForTables = false;
                    String nodeId = nodeService.findIdentityNodeId();
                    if (StringUtils.isNotBlank(nodeId)) {
                        NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId);
                        if (nodeSecurity != null && (nodeSecurity.isInitialLoadEnabled() || nodeSecurity.getInitialLoadTime() == null)) {
                            createTriggersForTables = parameterService.is(ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD);
                            if (!createTriggersForTables) {
                                log.info("Trigger creation has been disabled by " + ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD + " because an initial load is in progress or has not yet been requested");
                            }
                        } else {
                            createTriggersForTables = true;
                        }
                    }
                    if (!createTriggersForTables) {
                        triggersForCurrentNode.clear();
                    }
                    List<TriggerHistory> activeTriggerHistories = getActiveTriggerHistories();
                    inactivateTriggers(triggersForCurrentNode, sqlBuffer, activeTriggerHistories);
                    updateOrCreateDatabaseTriggers(triggersForCurrentNode, sqlBuffer, force, true, activeTriggerHistories, true);
                    resetTriggerRouterCacheByNodeGroupId();
                    if (createTriggersForTables) {
                        updateOrCreateDdlTriggers(sqlBuffer);
                    }
                } finally {
                    clusterService.unlock(ClusterConstants.SYNCTRIGGERS);
                    log.info("Done synchronizing triggers");
                }
            } else {
                Lock lock = clusterService.findLocks().get(ClusterConstants.SYNCTRIGGERS);
                if (lock != null) {
                    log.info("Sync triggers was locked by the cluster service.  The locking server id was: {}.  The lock time was: {}", lock.getLockingServerId(), lock.getLockTime());
                } else {
                    log.info("Sync triggers was locked by something but lock details were found");
                }
            }
        }
    } else {
        log.info("Not synchronizing triggers.  {} is set to false", ParameterConstants.AUTO_SYNC_TRIGGERS);
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Lock(org.jumpmind.symmetric.model.Lock)

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