Search in sources :

Example 1 with RegistrationNotOpenException

use of org.jumpmind.symmetric.service.RegistrationNotOpenException in project symmetric-ds by JumpMind.

the class RegistrationService method attemptToRegisterWithServer.

public synchronized boolean attemptToRegisterWithServer(int maxNumberOfAttempts) {
    List<INodeRegistrationListener> registrationListeners = extensionService.getExtensionPointList(INodeRegistrationListener.class);
    boolean registered = isRegisteredWithServer();
    if (!registered) {
        try {
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationStarting();
            }
            log.info("This node is unregistered.  It will attempt to register using the registration.url");
            String channelId = null;
            registered = dataLoaderService.loadDataFromPull(null, channelId).getStatus() == Status.DATA_PROCESSED;
        } catch (ConnectException e) {
            log.warn("The request to register failed because the client failed to connect to the server.  The connection error message was: {}", e.getMessage());
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationFailed("The request to register failed because the client failed to connect to the server.  The connection error message was: " + e.getMessage());
            }
        } catch (UnknownHostException e) {
            log.warn("The request to register failed because the host was unknown.  The unknown host exception was: {}", e.getMessage());
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationFailed("The request to register failed because the host was unknown.  The unknown host exception was: " + e.getMessage());
            }
        } catch (ConnectionRejectedException e) {
            log.warn("The request to register was rejected by the server.  Either the server node is not started, the server is not configured properly or the registration url is incorrect");
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationFailed("The request to register was rejected by the server.  Either the server node is not started, the server is not configured properly or the registration url is incorrect");
            }
        } catch (RegistrationNotOpenException e) {
            log.warn("Unable to register with server because registration is not open.");
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationFailed("Unable to register with server because registration is not open.");
            }
        } catch (ServiceUnavailableException e) {
            log.warn("Unable to register with server because the service is not available.  It may be starting up.");
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationFailed("Unable to register with server because the service is not available.  It may be starting up.");
            }
        } catch (Exception e) {
            log.error("Unexpected error during registration: " + (StringUtils.isNotBlank(e.getMessage()) ? e.getMessage() : e.getClass().getName()), e);
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationFailed("Unexpected error during registration: " + (StringUtils.isNotBlank(e.getMessage()) ? e.getMessage() : e.getClass().getName()));
            }
        }
        registered = checkRegistrationSuccessful(registered, maxNumberOfAttempts);
    }
    return registered;
}
Also used : RegistrationNotOpenException(org.jumpmind.symmetric.service.RegistrationNotOpenException) UnknownHostException(java.net.UnknownHostException) INodeRegistrationListener(org.jumpmind.symmetric.ext.INodeRegistrationListener) ServiceUnavailableException(org.jumpmind.symmetric.transport.ServiceUnavailableException) ConnectionRejectedException(org.jumpmind.symmetric.transport.ConnectionRejectedException) ConnectionRejectedException(org.jumpmind.symmetric.transport.ConnectionRejectedException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RegistrationNotOpenException(org.jumpmind.symmetric.service.RegistrationNotOpenException) UnknownHostException(java.net.UnknownHostException) RegistrationRedirectException(org.jumpmind.symmetric.service.RegistrationRedirectException) ServiceUnavailableException(org.jumpmind.symmetric.transport.ServiceUnavailableException) RegistrationFailedException(org.jumpmind.symmetric.service.RegistrationFailedException) ConnectException(java.net.ConnectException)

Example 2 with RegistrationNotOpenException

use of org.jumpmind.symmetric.service.RegistrationNotOpenException 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)

Aggregations

RegistrationNotOpenException (org.jumpmind.symmetric.service.RegistrationNotOpenException)2 RegistrationRedirectException (org.jumpmind.symmetric.service.RegistrationRedirectException)2 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 UnknownHostException (java.net.UnknownHostException)1 INodeIdCreator (org.jumpmind.symmetric.config.INodeIdCreator)1 INodeRegistrationListener (org.jumpmind.symmetric.ext.INodeRegistrationListener)1 Node (org.jumpmind.symmetric.model.Node)1 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)1 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)1 RegistrationRequest (org.jumpmind.symmetric.model.RegistrationRequest)1 RegistrationFailedException (org.jumpmind.symmetric.service.RegistrationFailedException)1 ConnectionRejectedException (org.jumpmind.symmetric.transport.ConnectionRejectedException)1 ServiceUnavailableException (org.jumpmind.symmetric.transport.ServiceUnavailableException)1