Search in sources :

Example 36 with Node

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

the class RegistrationService method openRegistration.

protected String openRegistration(Node node, String remoteHost, String remoteAddress) {
    Node me = nodeService.findIdentity();
    if (me != null) {
        String nodeId = extensionService.getExtensionPoint(INodeIdCreator.class).generateNodeId(node, remoteHost, remoteAddress);
        Node existingNode = nodeService.findNode(nodeId);
        if (existingNode == null) {
            node.setNodeId(nodeId);
            node.setSyncEnabled(false);
            boolean masterToMasterOnly = configurationService.containsMasterToMaster();
            node.setCreatedAtNodeId(masterToMasterOnly ? null : me.getNodeId());
            nodeService.save(node);
            // make sure there isn't a node security row lying around w/out
            // a node row
            nodeService.deleteNodeSecurity(nodeId);
            String password = extensionService.getExtensionPoint(INodeIdCreator.class).generatePassword(node);
            password = filterPasswordOnSaveIfNeeded(password);
            sqlTemplate.update(getSql("openRegistrationNodeSecuritySql"), new Object[] { nodeId, password, masterToMasterOnly ? null : me.getNodeId() });
            if (isNotBlank(remoteHost)) {
                NodeHost nodeHost = new NodeHost(node.getNodeId());
                nodeHost.setHeartbeatTime(new Date());
                nodeHost.setIpAddress(remoteAddress);
                nodeHost.setHostName(remoteHost);
                nodeService.updateNodeHost(nodeHost);
            }
            nodeService.flushNodeAuthorizedCache();
            nodeService.flushNodeCache();
            nodeService.insertNodeGroup(node.getNodeGroupId(), null);
            nodeService.flushNodeGroupCache();
            log.info("Just opened registration for external id of {} and a node group of {} and a node id of {}", new Object[] { node.getExternalId(), node.getNodeGroupId(), nodeId });
        } else {
            reOpenRegistration(nodeId, remoteHost, remoteAddress);
        }
        return nodeId;
    } else {
        throw new IllegalStateException("This node has not been configured.  Could not find a row in the identity table");
    }
}
Also used : INodeIdCreator(org.jumpmind.symmetric.config.INodeIdCreator) Node(org.jumpmind.symmetric.model.Node) Date(java.util.Date) NodeHost(org.jumpmind.symmetric.model.NodeHost)

Example 37 with Node

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

the class RegistrationService method openRegistration.

public synchronized String openRegistration(String nodeGroup, String externalId, String remoteHost, String remoteAddress) {
    Node node = new Node();
    node.setExternalId(externalId);
    node.setNodeGroupId(nodeGroup);
    return openRegistration(node, remoteHost, remoteAddress);
}
Also used : Node(org.jumpmind.symmetric.model.Node)

Example 38 with Node

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

the class RegistrationService method getRegistrationRequests.

public List<RegistrationRequest> getRegistrationRequests(boolean includeNodesWithOpenRegistrations) {
    List<RegistrationRequest> requests = sqlTemplate.query(getSql("selectRegistrationRequestSql"), new RegistrationRequestMapper());
    if (!includeNodesWithOpenRegistrations) {
        Collection<Node> nodes = nodeService.findNodesWithOpenRegistration();
        Iterator<RegistrationRequest> i = requests.iterator();
        while (i.hasNext()) {
            RegistrationRequest registrationRequest = (RegistrationRequest) i.next();
            for (Node node : nodes) {
                if (node.getNodeGroupId().equals(registrationRequest.getNodeGroupId()) && node.getExternalId().equals(registrationRequest.getExternalId())) {
                    i.remove();
                }
            }
        }
    }
    return requests;
}
Also used : Node(org.jumpmind.symmetric.model.Node) RegistrationRequest(org.jumpmind.symmetric.model.RegistrationRequest)

Example 39 with Node

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

the class RegistrationService method processRegistration.

protected Node processRegistration(Node nodePriorToRegistration, String remoteHost, String remoteAddress, boolean isRequestedRegistration, String deploymentType) throws IOException {
    Node processedNode = new Node();
    processedNode.setSyncEnabled(false);
    Node identity = nodeService.findIdentity();
    if (identity == null) {
        RegistrationRequest req = new RegistrationRequest(nodePriorToRegistration, RegistrationStatus.ER, remoteHost, remoteAddress);
        req.setErrorMessage("Cannot register a client node until this node is registered");
        saveRegistrationRequest(req);
        log.warn(req.getErrorMessage());
        return processedNode;
    }
    try {
        if (!nodeService.isRegistrationServer()) {
            /*
                 * registration is not allowed until this node has an identity
                 * and an initial load
                 */
            NodeSecurity security = nodeService.findNodeSecurity(identity.getNodeId());
            if (security == null || security.getInitialLoadTime() == null) {
                RegistrationRequest req = new RegistrationRequest(nodePriorToRegistration, RegistrationStatus.ER, remoteHost, remoteAddress);
                req.setErrorMessage("Cannot register a client node until this node has an initial load (ie. node_security.initial_load_time is a non null value)");
                saveRegistrationRequest(req);
                log.warn(req.getErrorMessage());
                return processedNode;
            }
        }
        String redirectUrl = getRedirectionUrlFor(nodePriorToRegistration.getExternalId());
        if (redirectUrl != null) {
            log.info("Redirecting {} to {} for registration.", nodePriorToRegistration.getExternalId(), redirectUrl);
            saveRegistrationRequest(new RegistrationRequest(nodePriorToRegistration, RegistrationStatus.RR, remoteHost, remoteAddress));
            throw new RegistrationRedirectException(redirectUrl);
        }
        /*
             * Check to see if there is a link that exists to service the node
             * that is requesting registration
             */
        NodeGroupLink link = configurationService.getNodeGroupLinkFor(identity.getNodeGroupId(), nodePriorToRegistration.getNodeGroupId(), false);
        if (link == null && parameterService.is(ParameterConstants.REGISTRATION_REQUIRE_NODE_GROUP_LINK, true)) {
            RegistrationRequest req = new RegistrationRequest(nodePriorToRegistration, RegistrationStatus.ER, remoteHost, remoteAddress);
            req.setErrorMessage(String.format("Cannot register a client node unless a node group link exists so the registering node can receive configuration updates.  Please add a group link where the source group id is %s and the target group id is %s", identity.getNodeGroupId(), nodePriorToRegistration.getNodeGroupId()));
            saveRegistrationRequest(req);
            log.warn(req.getErrorMessage());
            return processedNode;
        }
        String nodeId = StringUtils.isBlank(nodePriorToRegistration.getNodeId()) ? extensionService.getExtensionPoint(INodeIdCreator.class).selectNodeId(nodePriorToRegistration, remoteHost, remoteAddress) : nodePriorToRegistration.getNodeId();
        Node foundNode = nodeService.findNode(nodeId);
        NodeSecurity security = nodeService.findNodeSecurity(nodeId);
        if ((foundNode == null || security == null || !security.isRegistrationEnabled()) && parameterService.is(ParameterConstants.AUTO_REGISTER_ENABLED)) {
            openRegistration(nodePriorToRegistration, remoteHost, remoteAddress);
            nodeId = StringUtils.isBlank(nodePriorToRegistration.getNodeId()) ? extensionService.getExtensionPoint(INodeIdCreator.class).selectNodeId(nodePriorToRegistration, remoteHost, remoteAddress) : nodePriorToRegistration.getNodeId();
            security = nodeService.findNodeSecurity(nodeId);
            foundNode = nodeService.findNode(nodeId);
        } else if (foundNode == null || security == null || !security.isRegistrationEnabled()) {
            saveRegistrationRequest(new RegistrationRequest(nodePriorToRegistration, RegistrationStatus.RQ, remoteHost, remoteAddress));
            return processedNode;
        }
        foundNode.setSyncEnabled(true);
        if (Constants.DEPLOYMENT_TYPE_REST.equalsIgnoreCase(deploymentType)) {
            foundNode.setSymmetricVersion(null);
            foundNode.setDeploymentType(deploymentType);
        }
        foundNode.setSyncUrl(nodePriorToRegistration.getSyncUrl());
        foundNode.setDatabaseType(nodePriorToRegistration.getDatabaseType());
        foundNode.setDatabaseVersion(nodePriorToRegistration.getDatabaseVersion());
        foundNode.setSymmetricVersion(nodePriorToRegistration.getSymmetricVersion());
        nodeService.save(foundNode);
        /**
             * Only send automatic initial load once or if the client is really
             * re-registering
             */
        if ((security != null && security.getInitialLoadTime() == null) || isRequestedRegistration) {
            if (parameterService.is(ParameterConstants.AUTO_RELOAD_ENABLED)) {
                nodeService.setInitialLoadEnabled(nodeId, true, false, -1, "registration");
            }
            if (parameterService.is(ParameterConstants.AUTO_RELOAD_REVERSE_ENABLED)) {
                nodeService.setReverseInitialLoadEnabled(nodeId, true, false, -1, "registration");
            }
        }
        saveRegistrationRequest(new RegistrationRequest(foundNode, RegistrationStatus.OK, remoteHost, remoteAddress));
        statisticManager.incrementNodesRegistered(1);
        return foundNode;
    } catch (RegistrationNotOpenException ex) {
        if (StringUtils.isNotBlank(ex.getMessage())) {
            log.warn("Registration not allowed for {} because {}", nodePriorToRegistration.toString(), ex.getMessage());
        }
        return processedNode;
    }
}
Also used : RegistrationNotOpenException(org.jumpmind.symmetric.service.RegistrationNotOpenException) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) INodeIdCreator(org.jumpmind.symmetric.config.INodeIdCreator) Node(org.jumpmind.symmetric.model.Node) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) RegistrationRequest(org.jumpmind.symmetric.model.RegistrationRequest) RegistrationRedirectException(org.jumpmind.symmetric.service.RegistrationRedirectException)

Example 40 with Node

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

the class PushService method pushData.

public synchronized RemoteNodeStatuses pushData(boolean force) {
    RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
    Node identity = nodeService.findIdentity();
    if (identity != null && identity.isSyncEnabled()) {
        long minimumPeriodMs = parameterService.getLong(ParameterConstants.PUSH_MINIMUM_PERIOD_MS, -1);
        if (force || !clusterService.isInfiniteLocked(ClusterConstants.PUSH)) {
            List<NodeCommunication> nodes = nodeCommunicationService.list(CommunicationType.PUSH);
            if (nodes.size() > 0) {
                NodeSecurity identitySecurity = nodeService.findNodeSecurity(identity.getNodeId(), true);
                if (identitySecurity != null) {
                    int availableThreads = nodeCommunicationService.getAvailableThreads(CommunicationType.PUSH);
                    for (NodeCommunication nodeCommunication : nodes) {
                        boolean meetsMinimumTime = true;
                        if (minimumPeriodMs > 0 && nodeCommunication.getLastLockTime() != null && (System.currentTimeMillis() - nodeCommunication.getLastLockTime().getTime()) < minimumPeriodMs) {
                            meetsMinimumTime = false;
                        }
                        if (availableThreads > 0 && meetsMinimumTime) {
                            if (nodeCommunicationService.execute(nodeCommunication, statuses, this)) {
                                availableThreads--;
                            }
                        }
                    }
                } else {
                    log.error("Could not find a node security row for '{}'.  A node needs a matching security row in both the local and remote nodes if it is going to authenticate to push data", identity.getNodeId());
                }
            }
        } else {
            log.debug("Did not run the push process because it has been stopped");
        }
    }
    return statuses;
}
Also used : RemoteNodeStatuses(org.jumpmind.symmetric.model.RemoteNodeStatuses) NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node)

Aggregations

Node (org.jumpmind.symmetric.model.Node)129 HashSet (java.util.HashSet)18 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)18 Test (org.junit.Test)18 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)17 ArrayList (java.util.ArrayList)14 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)14 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)13 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)13 Table (org.jumpmind.db.model.Table)12 Data (org.jumpmind.symmetric.model.Data)12 Router (org.jumpmind.symmetric.model.Router)12 Date (java.util.Date)11 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)11 IOException (java.io.IOException)10 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)10 HashMap (java.util.HashMap)9 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)9 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)8