Search in sources :

Example 1 with RegistrationFailedException

use of org.jumpmind.symmetric.service.RegistrationFailedException 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 2 with RegistrationFailedException

use of org.jumpmind.symmetric.service.RegistrationFailedException 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)2 ConnectException (java.net.ConnectException)2 UnknownHostException (java.net.UnknownHostException)2 Node (org.jumpmind.symmetric.model.Node)2 RegistrationFailedException (org.jumpmind.symmetric.service.RegistrationFailedException)2 RegistrationNotOpenException (org.jumpmind.symmetric.service.RegistrationNotOpenException)2 RegistrationRedirectException (org.jumpmind.symmetric.service.RegistrationRedirectException)2 ConnectionRejectedException (org.jumpmind.symmetric.transport.ConnectionRejectedException)2