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;
}
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)));
}
}
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)));
}
}
Aggregations