Search in sources :

Example 1 with ConnectionRejectedException

use of org.jumpmind.symmetric.transport.ConnectionRejectedException 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 ConnectionRejectedException

use of org.jumpmind.symmetric.transport.ConnectionRejectedException in project symmetric-ds by JumpMind.

the class RegistrationService method registerWithServer.

/**
 * @see IRegistrationService#registerWithServer()
 */
public void registerWithServer() {
    boolean registered = isRegisteredWithServer();
    int maxNumberOfAttempts = parameterService.getInt(ParameterConstants.REGISTRATION_NUMBER_OF_ATTEMPTS);
    while (!registered && (maxNumberOfAttempts < 0 || maxNumberOfAttempts > 0) && engine.isStarted()) {
        try {
            log.info("This node is unregistered.  It will attempt to register using the registration.url");
            registered = dataLoaderService.loadDataFromPull(null).getStatus() == Status.DATA_PROCESSED;
        } catch (ConnectException e) {
            log.warn("The request to register failed because the client failed to connect to the server");
        } catch (UnknownHostException e) {
            log.warn("The request to register failed because the host was unknown");
        } catch (ConnectionRejectedException ex) {
            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");
        } catch (Exception e) {
            log.error("", e);
        }
        maxNumberOfAttempts--;
        if (!registered && (maxNumberOfAttempts < 0 || maxNumberOfAttempts > 0)) {
            registered = isRegisteredWithServer();
            if (registered) {
                log.info("We registered, but were not able to acknowledge our registration.  Sending a sql event to the node where we registered to indicate that we are alive and registered");
                Node identity = nodeService.findIdentity();
                Node parentNode = nodeService.findNode(identity.getCreatedAtNodeId());
                dataService.insertSqlEvent(parentNode, "update " + tablePrefix + "_node_security set registration_enabled=1, registration_time=current_timestamp where node_id='" + identity.getNodeId() + "'", false, -1, null);
            }
        }
        if (registered) {
            Node node = nodeService.findIdentity();
            if (node != null) {
                log.info("Successfully registered node [id={}]", node.getNodeId());
                dataService.heartbeat(true);
            } else {
                log.error("Node identity is missing after registration.  The registration server may be misconfigured or have an error");
                registered = false;
            }
        }
        if (!registered && maxNumberOfAttempts != 0) {
            sleepBeforeRegistrationRetry();
        }
    }
    if (!registered) {
        throw new RegistrationFailedException(String.format("Failed after trying to register %s times.", parameterService.getString(ParameterConstants.REGISTRATION_NUMBER_OF_ATTEMPTS)));
    }
}
Also used : RegistrationFailedException(org.jumpmind.symmetric.service.RegistrationFailedException) UnknownHostException(java.net.UnknownHostException) Node(org.jumpmind.symmetric.model.Node) 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) RegistrationFailedException(org.jumpmind.symmetric.service.RegistrationFailedException) ConnectException(java.net.ConnectException)

Example 3 with ConnectionRejectedException

use of org.jumpmind.symmetric.transport.ConnectionRejectedException in project symmetric-ds by JumpMind.

the class RegistrationService method requestNodeCopy.

public void requestNodeCopy() {
    Node copyFrom = nodeService.findIdentity();
    if (copyFrom == null) {
        throw new IllegalStateException("No identity found.  Can only copy if the node has an identity");
    }
    boolean copied = false;
    int maxNumberOfAttempts = parameterService.getInt(ParameterConstants.REGISTRATION_NUMBER_OF_ATTEMPTS);
    while (!copied && (maxNumberOfAttempts < 0 || maxNumberOfAttempts > 0)) {
        try {
            log.info("Detected that node '{}' should be copied to a new node id.  Attempting to contact server to accomplish this", copyFrom.getNodeId());
            copied = transportManager.sendCopyRequest(copyFrom) == HttpURLConnection.HTTP_OK;
            if (copied) {
                nodeService.deleteIdentity();
            }
        } catch (ConnectException e) {
            log.warn("The request to copy failed because the client failed to connect to the server");
        } catch (UnknownHostException e) {
            log.warn("The request to copy failed because the host was unknown");
        } catch (ConnectionRejectedException ex) {
            log.warn("The request to copy 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 (Exception e) {
            log.error("", e);
        }
        maxNumberOfAttempts--;
        if (!copied) {
            long sleepTimeInMs = DateUtils.MILLIS_PER_SECOND * randomTimeSlot.getRandomValueSeededByExternalId();
            log.warn("Copy failed.  Sleeping before attempting again.", sleepTimeInMs);
            log.info("Sleeping for {}ms", sleepTimeInMs);
            AppUtils.sleep(sleepTimeInMs);
        }
    }
    if (!copied) {
        throw new RegistrationFailedException(String.format("Failed after trying to copy %s times.", parameterService.getString(ParameterConstants.REGISTRATION_NUMBER_OF_ATTEMPTS)));
    }
}
Also used : RegistrationFailedException(org.jumpmind.symmetric.service.RegistrationFailedException) UnknownHostException(java.net.UnknownHostException) Node(org.jumpmind.symmetric.model.Node) 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) RegistrationFailedException(org.jumpmind.symmetric.service.RegistrationFailedException) ConnectException(java.net.ConnectException)

Aggregations

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