Search in sources :

Example 1 with INodeRegistrationListener

use of org.jumpmind.symmetric.ext.INodeRegistrationListener 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 INodeRegistrationListener

use of org.jumpmind.symmetric.ext.INodeRegistrationListener in project symmetric-ds by JumpMind.

the class RegistrationService method sleepBeforeRegistrationRetry.

private void sleepBeforeRegistrationRetry() {
    long sleepTimeInMs = DateUtils.MILLIS_PER_SECOND * randomTimeSlot.getRandomValueSeededByExternalId();
    log.info("Could not register.  Sleeping for {}ms before attempting again.", sleepTimeInMs);
    List<INodeRegistrationListener> registrationListeners = extensionService.getExtensionPointList(INodeRegistrationListener.class);
    for (INodeRegistrationListener l : registrationListeners) {
        l.registrationNextAttemptUpdated((int) (sleepTimeInMs / 1000));
    }
    AppUtils.sleep(sleepTimeInMs);
}
Also used : INodeRegistrationListener(org.jumpmind.symmetric.ext.INodeRegistrationListener)

Example 3 with INodeRegistrationListener

use of org.jumpmind.symmetric.ext.INodeRegistrationListener in project symmetric-ds by JumpMind.

the class DataLoaderService method loadDataFromPull.

public void loadDataFromPull(Node remote, RemoteNodeStatus status) throws IOException {
    Node local = nodeService.findIdentity();
    if (local == null) {
        local = new Node(this.parameterService, symmetricDialect);
    }
    try {
        NodeSecurity localSecurity = nodeService.findNodeSecurity(local.getNodeId(), true);
        IIncomingTransport transport = null;
        boolean isRegisterTransport = false;
        if (remote != null && localSecurity != null) {
            Map<String, String> requestProperties = new HashMap<String, String>();
            ChannelMap suspendIgnoreChannels = configurationService.getSuspendIgnoreChannelLists();
            requestProperties.put(WebConstants.SUSPENDED_CHANNELS, suspendIgnoreChannels.getSuspendChannelsAsString());
            requestProperties.put(WebConstants.IGNORED_CHANNELS, suspendIgnoreChannels.getIgnoreChannelsAsString());
            requestProperties.put(WebConstants.THREAD_CHANNEL, status.getChannelId());
            transport = transportManager.getPullTransport(remote, local, localSecurity.getNodePassword(), requestProperties, parameterService.getRegistrationUrl());
        } else {
            transport = transportManager.getRegisterTransport(local, parameterService.getRegistrationUrl());
            log.info("Using registration URL of {}", transport.getUrl());
            List<INodeRegistrationListener> registrationListeners = extensionService.getExtensionPointList(INodeRegistrationListener.class);
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationUrlUpdated(transport.getUrl());
            }
            remote = new Node();
            remote.setSyncUrl(parameterService.getRegistrationUrl());
            isRegisterTransport = true;
        }
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(remote.getNodeId(), status.getChannelId(), local.getNodeId(), ProcessType.PULL_JOB));
        try {
            List<IncomingBatch> list = loadDataFromTransport(processInfo, remote, transport, null);
            if (list.size() > 0) {
                processInfo.setStatus(ProcessInfo.Status.ACKING);
                status.updateIncomingStatus(list);
                local = nodeService.findIdentity();
                if (local != null) {
                    localSecurity = nodeService.findNodeSecurity(local.getNodeId(), !isRegisterTransport);
                    if (StringUtils.isNotBlank(transport.getRedirectionUrl())) {
                        /*
                             * We were redirected for the pull, we need to
                             * redirect for the ack
                             */
                        String url = transport.getRedirectionUrl();
                        int index = url.indexOf("/registration?");
                        if (index >= 0) {
                            url = url.substring(0, index);
                        }
                        log.info("Setting the sync url for ack to: {}", url);
                        remote.setSyncUrl(url);
                    }
                    sendAck(remote, local, localSecurity, list, transportManager);
                }
            }
            if (containsError(list)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
            updateBatchToSendCount(remote, transport);
        } catch (RuntimeException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        } catch (IOException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        }
    } catch (RegistrationRequiredException e) {
        if (StringUtils.isBlank(remote.getSyncUrl()) || remote.getSyncUrl().equals(parameterService.getRegistrationUrl())) {
            log.warn("Node information missing on the server.  Attempting to re-register remote.getSyncUrl()={}", remote.getSyncUrl());
            loadDataFromPull(null, status);
            nodeService.findIdentity(false);
        } else {
            log.warn("Failed to pull data from node '{}'. It probably is missing a node security record for '{}'.", remote.getNodeId(), local.getNodeId());
        }
    } catch (MalformedURLException e) {
        if (remote != null) {
            log.error("Could not connect to the {} node's transport because of a bad URL: '{}' {}", remote.getNodeId(), remote.getSyncUrl(), e);
        } else {
            log.error("", e);
        }
        throw e;
    }
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) MalformedURLException(java.net.MalformedURLException) 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) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) TransformPoint(org.jumpmind.symmetric.io.data.transform.TransformPoint) IIncomingTransport(org.jumpmind.symmetric.transport.IIncomingTransport) INodeRegistrationListener(org.jumpmind.symmetric.ext.INodeRegistrationListener) RegistrationRequiredException(org.jumpmind.symmetric.service.RegistrationRequiredException)

Example 4 with INodeRegistrationListener

use of org.jumpmind.symmetric.ext.INodeRegistrationListener in project symmetric-ds by JumpMind.

the class RegistrationService method markNodeAsRegistered.

/**
     * @see IRegistrationService#markNodeAsRegistered(Node)
     */
public void markNodeAsRegistered(String nodeId) {
    ISqlTransaction transaction = null;
    try {
        transaction = sqlTemplate.startSqlTransaction();
        symmetricDialect.disableSyncTriggers(transaction, nodeId);
        transaction.prepareAndExecute(getSql("registerNodeSecuritySql"), nodeId);
        transaction.commit();
        nodeService.flushNodeAuthorizedCache();
    } catch (Error ex) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw ex;
    } catch (RuntimeException ex) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw ex;
    } finally {
        List<INodeRegistrationListener> registrationListeners = extensionService.getExtensionPointList(INodeRegistrationListener.class);
        for (INodeRegistrationListener l : registrationListeners) {
            l.registrationSyncTriggers();
        }
        symmetricDialect.enableSyncTriggers(transaction);
        close(transaction);
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) INodeRegistrationListener(org.jumpmind.symmetric.ext.INodeRegistrationListener)

Example 5 with INodeRegistrationListener

use of org.jumpmind.symmetric.ext.INodeRegistrationListener in project symmetric-ds by JumpMind.

the class RegistrationService method checkRegistrationSuccessful.

protected boolean checkRegistrationSuccessful(boolean registered, int 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) {
        List<INodeRegistrationListener> registrationListeners = extensionService.getExtensionPointList(INodeRegistrationListener.class);
        Node node = nodeService.findIdentity();
        if (node != null) {
            log.info("Successfully registered node [id={}]", node.getNodeId());
            extensionService.refresh();
            dataService.heartbeat(true);
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationSuccessful();
            }
        } else {
            log.error("Node identity is missing after registration.  The registration server may be misconfigured or have an error");
            for (INodeRegistrationListener l : registrationListeners) {
                l.registrationFailed("Node identity is missing after registration.  The registration server may be misconfigured or have an error");
            }
            registered = false;
        }
    }
    return registered;
}
Also used : Node(org.jumpmind.symmetric.model.Node) INodeRegistrationListener(org.jumpmind.symmetric.ext.INodeRegistrationListener)

Aggregations

INodeRegistrationListener (org.jumpmind.symmetric.ext.INodeRegistrationListener)5 IOException (java.io.IOException)2 Node (org.jumpmind.symmetric.model.Node)2 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)1 TransformPoint (org.jumpmind.symmetric.io.data.transform.TransformPoint)1 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)1 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)1 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)1 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)1 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)1 RegistrationFailedException (org.jumpmind.symmetric.service.RegistrationFailedException)1 RegistrationNotOpenException (org.jumpmind.symmetric.service.RegistrationNotOpenException)1 RegistrationRedirectException (org.jumpmind.symmetric.service.RegistrationRedirectException)1 RegistrationRequiredException (org.jumpmind.symmetric.service.RegistrationRequiredException)1 ConnectionRejectedException (org.jumpmind.symmetric.transport.ConnectionRejectedException)1 IIncomingTransport (org.jumpmind.symmetric.transport.IIncomingTransport)1