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