perfsonar-dev - [GEANT/SA2/ps-java-services] r5498 - branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration
Subject: perfsonar development work
List archive
[GEANT/SA2/ps-java-services] r5498 - branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration
Chronological Thread
- From:
- To:
- Subject: [GEANT/SA2/ps-java-services] r5498 - branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration
- Date: Mon, 22 Feb 2010 08:53:36 GMT
Author: psnc.trzaszczka
Date: 2010-02-22 08:53:35 +0000 (Mon, 22 Feb 2010)
New Revision: 5498
Added:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration/AbstractRegistrationAction.java
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
Log:
LSRegistration action added
Added:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration/AbstractRegistrationAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration/AbstractRegistrationAction.java
(rev 0)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration/AbstractRegistrationAction.java
2010-02-22 08:53:35 UTC (rev 5498)
@@ -0,0 +1,430 @@
+package org.perfsonar.base2.service.registration;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.perfsonar.base2.service.configuration.Action;
+import org.perfsonar.base2.service.configuration.Configuration;
+import org.perfsonar.base2.service.configuration.ConfigurationManager;
+import org.perfsonar.base2.service.configuration.LookupInformation;
+import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import org.perfsonar.base2.service.requesthandler.ServiceMessage;
+import org.perfsonar.base2.service.scheduler.SchedulerAction;
+import org.perfsonar.base2.xml.Element;
+import org.perfsonar.base2.xml.nmwg.Data;
+import org.perfsonar.base2.xml.nmwg.EventType;
+import org.perfsonar.base2.xml.nmwg.Message;
+import org.perfsonar.base2.xml.nmwg.Metadata;
+import org.perfsonar.base2.xml.nmwg.NMWGNamespaceFactory;
+import org.perfsonar.base2.xml.nmwg.Subject;
+
+import edu.emory.mathcs.backport.java.util.Collections;
+
+/**
+ *
+ * This class provides support for Registration. It consists of methods
that are helpful to work with
+ * receive/process responses.
+ *
+ * LSRegistrationActions bases on configuration file - configuration.xml
where are defined addresses.
+ *
+ * This addresses can be defined in two form :
+ * - single direct address
+ * - address to hint.roots that contains addresses
+ *
+ * @author Slawomir Trzaszczka
+ *
+ */
+public abstract class AbstractRegistrationAction extends Action implements
+ SchedulerAction {
+
+ private boolean initialized = false;
+
+ private Logger logger =
Logger.getLogger(AbstractRegistrationAction.class);
+
+ /**
+ * Message type.
+ */
+ protected static final String REGISTRATION_REQUEST_MESSAGE_TYPE =
"LSRegisterRequest";
+
+ /**
+ * EventType name which is included in the metadata of
LSRegisterRequest
+ * message.
+ */
+ private static final String DEFAULT_REGISTRATION_EVENT_TYPE =
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/registration/service/2.0";
+
+ /**
+ * Provides metadatata configuration which is sent to LS(s).
+ */
+ protected RegisterDataSource dataSource = null;
+
+ protected String registrationEventType =
DEFAULT_REGISTRATION_EVENT_TYPE;
+
+ /**
+ * Set of information about the service taken from the configuration.
+ */
+ protected LookupInformation lookupInformation = null;
+
+ /**
+ * Sends messages to LS(s).
+ */
+ protected LSRegistrator registrator;
+
+ public AbstractRegistrationAction() {
+ super();
+ }
+
+ /**
+ * main action of this class, in first step initialization is
executed
+ *
+ */
+ public void runAction() {
+
+ if (!initialized) {
+ try {
+ init();
+ initialized = true;
+ } catch (PerfSONARException e) {
+ e.printStackTrace();
+ logger.warn("Cannot initialize "
+ +
this.getClass().getCanonicalName());
+ }
+ }
+ execute();
+ refresh();
+
+ }
+
+ /**
+ * initializes this class
+ *
+ * @throws PerfSONARException
+ */
+ protected abstract void init() throws PerfSONARException;
+
+ /**
+ * business logic of this class
+ */
+ protected abstract void execute();
+
+ /**
+ * Removes all existing keys
+ */
+ protected abstract void refresh();
+
+ /**
+ *
+ * returns RegisterDataSource configured in configuration.xml file
+ *
+ * @return
+ * @throws PerfSONARException
+ */
+ protected RegisterDataSource getRegisterDataSource()
+ throws PerfSONARException {
+
+ String className = getOption("registerDataSource").getValue();
+ if (className == null || className.trim().equals("")) {
+ logger
+ .warn("registerDataSource option of
register action is empty");
+ return null;
+ }
+
+ RegisterDataSource registerDataSource = null;
+
+ try {
+ registerDataSource = (RegisterDataSource)
Class.forName(className)
+ .newInstance();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ throwException(e);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ throwException(e);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ throwException(e);
+ }
+
+ return registerDataSource;
+
+ }
+
+ /**
+ * get registerEventType option value. If not present, take default
+ *
+ * @return
+ */
+ protected String getRegistrationEventType() {
+ String evt = getOption("registerEventType").getValue();
+ if (evt != null) {
+ logger
+ .debug("Found [registerEventType]
option value [" + evt
+ + "]");
+ return evt;
+ } else {
+ logger.debug("Taking default [registerEventType]
value ["
+ + DEFAULT_REGISTRATION_EVENT_TYPE +
"]");
+ return DEFAULT_REGISTRATION_EVENT_TYPE;
+ }
+ }
+
+ /**
+ *
+ * returns LookupInformation configured in configuration.xml file
+ *
+ * @return
+ * @throws PerfSONARException
+ */
+ protected LookupInformation getLookupInformation() throws
PerfSONARException {
+
+ Configuration configuration =
ConfigurationManager.getInstance()
+ .getConfiguration();
+ LookupInformation lookupInformation = (LookupInformation)
configuration
+
.getService().getEntry(Configuration.LOOKUP_INFORMATION);
+ return lookupInformation;
+ }
+
+ /**
+ *
+ * throws exception
+ *
+ * @param ex
+ * @throws PerfSONARException
+ */
+ private void throwException(Exception ex) throws PerfSONARException {
+ throw new PerfSONARException("error",
+ "Unable to create an object of : " +
className + ": "
+ + ex.toString());
+ }
+
+ /**
+ * Get list of URLs to Lookup Services to register to.
+ * Addresses returned from this method are shuffled - aim of this
operation is avoiding
+ * registration to first address
+ *
+ * @return
+ * @throws PerfSONARException
+ */
+ protected LinkedList<URL> getLSAddresses() {
+
+ List<URL> addressesList = new ArrayList<URL>();
+
+ // get values from options lsAddress-1, lsAddress-2,
lsAddress-3, ...
+ // and get LSes lists from URLs
+
+ for (String optName : options.keySet()) {
+
+ // handles lsAddress-1, lsAddress-2, lsAddress-3, ...
+ if (optName.startsWith("lsAddress")) {
+
+ try {
+ URL url = new
URL(getOption(optName).getValue());
+ addressesList.add(url);
+ } catch (MalformedURLException ex) {
+ logger.warn("Unable to convert LS
address [" + optName
+ + "] into URL object.
Exception was: "
+ + ex.getMessage());
+ }
+
+ // handles lsList-1, lsList-2, ...
+ } else if (optName.startsWith("lsList")) {
+
+ try {
+ String remoteResource =
getOption(optName).getValue();
+ addLSAddressesFromURL(addressesList,
remoteResource);
+ } catch (MalformedURLException ex) {
+ logger.warn("Unable to read LS list
from URL address ["
+ + optName + "] into
URL object. Exception was: "
+ + ex.getMessage());
+ } catch (IOException ex) {
+ logger.warn("Unable to read LS list
from URL address ["
+ + optName + "] into
URL object. Exception was: "
+ + ex.getMessage());
+ }
+
+ }
+ }
+
+ if (addressesList.size() == 0) {
+ return null;
+ } else {
+ LinkedList<URL> glsAddresses = new LinkedList<URL>();
+ // shuffle addresses to randomize order of the GLS
+ Collections.shuffle(addressesList);
+ for (URL url : addressesList) {
+ glsAddresses.add(url);
+ }
+ return glsAddresses;
+ }
+ }
+
+ /**
+ * Populates urls collection with urls/lines downloaded from urlString
+ *
+ * @param urls
+ * @param urlString
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ private void addLSAddressesFromURL(List<URL> urls, String urlString)
+ throws MalformedURLException, IOException {
+
+ URL rootHintsUrl = new URL(urlString);
+ URLConnection rhc = rootHintsUrl.openConnection();
+ BufferedReader in = new BufferedReader(new
InputStreamReader(rhc
+ .getInputStream()));
+ String line;
+ while ((line = in.readLine()) != null) {
+ String s = line.trim();
+ if ((s.length() > 0) && // not empty
+ (!s.startsWith("#")) &&
(!s.startsWith("//"))) { // not
+ // commentary
+ // # or
+ // //
+
+ URL lsUrl = new URL(line);
+ urls.add(lsUrl);
+ }
+ }
+ in.close();
+
+ }
+
+ /**
+ *
+ * returns message that will contains summarized data
+ *
+ * @return
+ * @throws PerfSONARException
+ */
+ protected ServiceMessage getLSRegisterMessage() throws
PerfSONARException {
+
+ ServiceMessage serviceMessage = new ServiceMessage();
+
+ Message message = new Message();
+ message.setType(REGISTRATION_REQUEST_MESSAGE_TYPE);
+ serviceMessage.setElement(message);
+
+ Metadata metadata = new Metadata();
+ metadata.setId("serviceLookupInfo");
+ message.setMetadata(metadata);
+
+ EventType eventType = new EventType();
+ eventType.setEventType(registrationEventType);
+ metadata.setEventType(eventType);
+
+ Subject subject = new Subject("perfsonar");
+ subject.setId("commonParameters");
+ metadata.setSubject(subject);
+
+ Element service = new Element("service", "psservice",
+
NMWGNamespaceFactory.getNamespace("psservice"));
+ service.setId("serviceParameters");
+ subject.addChild(service);
+
+ Collection<String> keys =
lookupInformation.getOptions().keySet();
+ for (String name : keys) {
+ Element element = new Element(name, "psservice",
+
NMWGNamespaceFactory.getNamespace("psservice"));
+
element.setText(lookupInformation.getOption(name).getValue());
+ service.addChild(element);
+ }
+
+ Data data = null;
+ Message msg = (Message)
dataSource.getRegisterData().getElement();
+ Collection<Metadata> c = msg.getMetadataCollection();
+ if (!c.isEmpty()) {
+ for (Metadata m : c) {
+ data = new Data();
+ data.setMetadataIdRef(metadata.getId());
+ data.addChild(m);
+ message.addChild(data);
+ }
+ } else {
+ data = new Data();
+ data.setMetadataIdRef(metadata.getId());
+ message.addChild(data);
+ }
+ return serviceMessage;
+ }
+
+ protected Element getResponseMetadata(ServiceMessage response) {
+ Element responseMessage = response.getElement();
+
+ if (responseMessage != null) {
+ Element responseMetadata = responseMessage
+ .getFirstChild("metadata");
+ return responseMetadata;
+ }
+
+ return null;
+ }
+
+ protected boolean isResponseSuccess(Element responseMetadata) {
+ Element eventType =
responseMetadata.getFirstChild("eventType");
+ if (eventType != null &&
eventType.getText().trim().contains("success")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ protected Element getKeyFromResponse(ServiceMessage response) {
+
+ Element responseMetadata = null;
+ responseMetadata = getResponseMetadata(response);
+
+ if (responseMetadata != null) {
+ if (isResponseSuccess(responseMetadata)) {
+ return responseMetadata.getFirstChild("key");
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ *
+ * returns LSRegistrator configured in configuration.xml
+ *
+ * @return
+ * @throws PerfSONARException
+ */
+ protected LSRegistrator getLSRegistrator() throws PerfSONARException {
+
+ String className = getOption("registrator").getValue();
+ LSRegistrator registrator = null;
+
+ try {
+ registrator = (LSRegistrator) Class.forName(className)
+ .newInstance();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ throw new PerfSONARException("error",
+ "Unable to create an object of : " +
className + ": "
+ + e.toString());
+
+ } catch (IllegalAccessException e) {
+ throw new PerfSONARException("error",
+ "Unable to create an object of : " +
className + ": "
+ + e.toString());
+
+ } catch (ClassNotFoundException e) {
+ throw new PerfSONARException("error",
+ "Unable to create an object of : " +
className + ": "
+ + e.toString());
+ }
+
+ return registrator;
+
+ }
+
+}
\ No newline at end of file
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
2010-02-19 12:32:12 UTC (rev 5497)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
2010-02-22 08:53:35 UTC (rev 5498)
@@ -1,430 +1,140 @@
package org.perfsonar.base2.service.registration;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLConnection;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.apache.log4j.Logger;
-import org.perfsonar.base2.service.configuration.Action;
-import org.perfsonar.base2.service.configuration.Configuration;
-import org.perfsonar.base2.service.configuration.ConfigurationManager;
-import org.perfsonar.base2.service.configuration.LookupInformation;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.requesthandler.ServiceMessage;
-import org.perfsonar.base2.service.scheduler.SchedulerAction;
import org.perfsonar.base2.xml.Element;
-import org.perfsonar.base2.xml.nmwg.Data;
-import org.perfsonar.base2.xml.nmwg.EventType;
import org.perfsonar.base2.xml.nmwg.Message;
-import org.perfsonar.base2.xml.nmwg.Metadata;
-import org.perfsonar.base2.xml.nmwg.NMWGNamespaceFactory;
-import org.perfsonar.base2.xml.nmwg.Subject;
-import edu.emory.mathcs.backport.java.util.Collections;
-
/**
*
- * This class provides support for Registration. It consists of methods
that are helpful to work with
- * receive/process responses.
- *
- * LSRegistrationActions bases on configuration file - configuration.xml
where are defined addresses.
- *
- * This addresses can be defined in two form :
- * - single direct address
- * - address to hint.roots that contains addresses
+ * Action registering to other LS. Configuration of the addresses is in
+ * configuration.xml
*
* @author Slawomir Trzaszczka
- *
*/
-public abstract class LSRegistrationAction extends Action implements
- SchedulerAction {
+public class LSRegistrationAction extends AbstractRegistrationAction {
- private boolean initialized = false;
-
private Logger logger = Logger.getLogger(LSRegistrationAction.class);
- /**
- * Message type.
- */
- protected static final String REGISTRATION_REQUEST_MESSAGE_TYPE =
"LSRegisterRequest";
+ private LinkedList<URL> lsAddresses;
/**
- * EventType name which is included in the metadata of
LSRegisterRequest
- * message.
- */
- private static final String DEFAULT_REGISTRATION_EVENT_TYPE =
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/registration/service/2.0";
-
- /**
- * Provides metadatata configuration which is sent to LS(s).
- */
- protected RegisterDataSource dataSource = null;
-
- protected String registrationEventType =
DEFAULT_REGISTRATION_EVENT_TYPE;
-
- /**
- * Set of information about the service taken from the configuration.
- */
- protected LookupInformation lookupInformation = null;
-
- /**
- * Sends messages to LS(s).
- */
- protected LSRegistrator registrator;
-
- public LSRegistrationAction() {
- super();
- }
-
- /**
- * main action of this class, in first step initialization is
executed
+ * number of registration to GLS in one iteration
*
*/
- public void runAction() {
+ private int nrOfLSRegistration = 1;
+ private List<Element> registeredKeys = new ArrayList<Element>();
- if (!initialized) {
- try {
- init();
- initialized = true;
- } catch (PerfSONARException e) {
- e.printStackTrace();
- logger.warn("Cannot initialize "
- +
this.getClass().getCanonicalName());
- }
- }
- execute();
- refresh();
-
+ public void init() throws PerfSONARException {
+ dataSource = getRegisterDataSource();
+ registrationEventType = getRegistrationEventType();
+ lookupInformation = getLookupInformation();
+ lsAddresses = getLSAddresses();
+ registrator = getLSRegistrator();
}
-
- /**
- * initializes this class
- *
- * @throws PerfSONARException
- */
- protected abstract void init() throws PerfSONARException;
- /**
- * business logic of this class
- */
- protected abstract void execute();
+ public void execute() {
+ boolean sendKeekAlive = false;
+ ServiceMessage response;
- /**
- * Removes all existing keys
- */
- protected abstract void refresh();
+ if (sendKeekAlive) {
+
+ for (int c = 0; c < registeredKeys.size(); c++) {
+ Element registeredKey = registeredKeys.get(c);
- /**
- *
- * returns RegisterDataSource configured in configuration.xml file
- *
- * @return
- * @throws PerfSONARException
- */
- protected RegisterDataSource getRegisterDataSource()
- throws PerfSONARException {
-
- String className = getOption("registerDataSource").getValue();
- if (className == null || className.trim().equals("")) {
- logger
- .warn("registerDataSource option of
register action is empty");
- return null;
- }
-
- RegisterDataSource registerDataSource = null;
-
- try {
- registerDataSource = (RegisterDataSource)
Class.forName(className)
- .newInstance();
- } catch (InstantiationException e) {
- e.printStackTrace();
- throwException(e);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- throwException(e);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- throwException(e);
- }
-
- return registerDataSource;
-
- }
-
- /**
- * get registerEventType option value. If not present, take default
- *
- * @return
- */
- protected String getRegistrationEventType() {
- String evt = getOption("registerEventType").getValue();
- if (evt != null) {
- logger
- .debug("Found [registerEventType]
option value [" + evt
- + "]");
- return evt;
- } else {
- logger.debug("Taking default [registerEventType]
value ["
- + DEFAULT_REGISTRATION_EVENT_TYPE +
"]");
- return DEFAULT_REGISTRATION_EVENT_TYPE;
- }
- }
-
- /**
- *
- * returns LookupInformation configured in configuration.xml file
- *
- * @return
- * @throws PerfSONARException
- */
- protected LookupInformation getLookupInformation() throws
PerfSONARException {
-
- Configuration configuration =
ConfigurationManager.getInstance()
- .getConfiguration();
- LookupInformation lookupInformation = (LookupInformation)
configuration
-
.getService().getEntry(Configuration.LOOKUP_INFORMATION);
- return lookupInformation;
- }
-
- /**
- *
- * throws exception
- *
- * @param ex
- * @throws PerfSONARException
- */
- private void throwException(Exception ex) throws PerfSONARException {
- throw new PerfSONARException("error",
- "Unable to create an object of : " +
className + ": "
- + ex.toString());
- }
-
- /**
- * Get list of URLs to Lookup Services to register to.
- * Addresses returned from this method are shuffled - aim of this
operation is avoiding
- * registration to first address
- *
- * @return
- * @throws PerfSONARException
- */
- protected LinkedList<URL> getLSAddresses() {
-
- List<URL> addressesList = new ArrayList<URL>();
-
- // get values from options lsAddress-1, lsAddress-2,
lsAddress-3, ...
- // and get LSes lists from URLs
-
- for (String optName : options.keySet()) {
-
- // handles lsAddress-1, lsAddress-2, lsAddress-3, ...
- if (optName.startsWith("lsAddress")) {
-
+ // send keep alive to last used GLS
+ URL glsAddress = lsAddresses.getFirst();
try {
- URL url = new
URL(getOption(optName).getValue());
- addressesList.add(url);
- } catch (MalformedURLException ex) {
- logger.warn("Unable to convert LS
address [" + optName
- + "] into URL object.
Exception was: "
- + ex.getMessage());
- }
+ response =
registrator.keepalive(registeredKey, glsAddress);
+ logger.debug("KeepAlive message
registered " + glsAddress);
- // handles lsList-1, lsList-2, ...
- } else if (optName.startsWith("lsList")) {
+ if
(isResponseSuccess(getResponseMetadata(response))) {
+ logger.debug("KEEP ALIVE
accepted");
+ } else {
+
registeredKeys.remove(registeredKey);
+ logger.debug("KEEP ALIVE
rejected !");
+ }
- try {
- String remoteResource =
getOption(optName).getValue();
- addLSAddressesFromURL(addressesList,
remoteResource);
- } catch (MalformedURLException ex) {
- logger.warn("Unable to read LS list
from URL address ["
- + optName + "] into
URL object. Exception was: "
- + ex.getMessage());
- } catch (IOException ex) {
- logger.warn("Unable to read LS list
from URL address ["
- + optName + "] into
URL object. Exception was: "
- + ex.getMessage());
+ } catch (PerfSONARException e) {
+ logger.debug("Problem with sending
KeepAlive message to :"
+ +
glsAddress.toString());
+ poolElement(lsAddresses);
+ registeredKeys.remove(registeredKey);
}
-
}
}
- if (addressesList.size() == 0) {
- return null;
- } else {
- LinkedList<URL> glsAddresses = new LinkedList<URL>();
- // shuffle addresses to randomize order of the GLS
- Collections.shuffle(addressesList);
- for (URL url : addressesList) {
- glsAddresses.add(url);
- }
- return glsAddresses;
- }
- }
+ // if registration using KeepAlive message failed or there
wasn't any
+ // registration before ...
+ if (registeredKeys.isEmpty()) {
- /**
- * Populates urls collection with urls/lines downloaded from urlString
- *
- * @param urls
- * @param urlString
- * @throws MalformedURLException
- * @throws IOException
- */
- private void addLSAddressesFromURL(List<URL> urls, String urlString)
- throws MalformedURLException, IOException {
-
- URL rootHintsUrl = new URL(urlString);
- URLConnection rhc = rootHintsUrl.openConnection();
- BufferedReader in = new BufferedReader(new
InputStreamReader(rhc
- .getInputStream()));
- String line;
- while ((line = in.readLine()) != null) {
- String s = line.trim();
- if ((s.length() > 0) && // not empty
- (!s.startsWith("#")) &&
(!s.startsWith("//"))) { // not
- // commentary
- // # or
- // //
-
- URL lsUrl = new URL(line);
- urls.add(lsUrl);
+ ServiceMessage serviceRequestMessage = null;
+ try {
+ serviceRequestMessage =
getLSRegisterMessage();
+ } catch (PerfSONARException e) {
+ logger.warn("Cannot build registration
message !");
+ logger.warn(e);
}
- }
- in.close();
- }
-
- /**
- *
- * returns message that will contains summarized data
- *
- * @return
- * @throws PerfSONARException
- */
- protected ServiceMessage getLSRegisterMessage() throws
PerfSONARException {
+ int nrOfAddresses = lsAddresses.size();
- ServiceMessage serviceMessage = new ServiceMessage();
+ if (serviceRequestMessage != null) {
+ // try to register to first n-working GLS
from list of all (n is a nrOfGLSRegistration)
+ while (nrOfAddresses > 0) {
- Message message = new Message();
- message.setType(REGISTRATION_REQUEST_MESSAGE_TYPE);
- serviceMessage.setElement(message);
+ Message requestMessage = (Message)
serviceRequestMessage
+ .getElement();
- Metadata metadata = new Metadata();
- metadata.setId("serviceLookupInfo");
- message.setMetadata(metadata);
+ URL glsAddress =
lsAddresses.get(registeredKeys.size());
+ try {
+ response =
registrator.register(requestMessage,
+ glsAddress);
- EventType eventType = new EventType();
- eventType.setEventType(registrationEventType);
- metadata.setEventType(eventType);
-
- Subject subject = new Subject("perfsonar");
- subject.setId("commonParameters");
- metadata.setSubject(subject);
-
- Element service = new Element("service", "psservice",
-
NMWGNamespaceFactory.getNamespace("psservice"));
- service.setId("serviceParameters");
- subject.addChild(service);
-
- Collection<String> keys =
lookupInformation.getOptions().keySet();
- for (String name : keys) {
- Element element = new Element(name, "psservice",
-
NMWGNamespaceFactory.getNamespace("psservice"));
-
element.setText(lookupInformation.getOption(name).getValue());
- service.addChild(element);
- }
-
- Data data = null;
- Message msg = (Message)
dataSource.getRegisterData().getElement();
- Collection<Metadata> c = msg.getMetadataCollection();
- if (!c.isEmpty()) {
- for (Metadata m : c) {
- data = new Data();
- data.setMetadataIdRef(metadata.getId());
- data.addChild(m);
- message.addChild(data);
+ logger.info("Registration
message sent");
+ Element registeredKey =
getKeyFromResponse(response);
+ if (registeredKey == null) {
+ logger
+
.debug("no registerd key in registration response");
+
poolElement(lsAddresses);
+ } else {
+ // element registered
+
registeredKeys.add(registeredKey);
+ if
(registeredKeys.size() == nrOfLSRegistration) {
+ break;
+ }
+ }
+ } catch (PerfSONARException e) {
+ logger
+
.warn("Problem with sending registration message to :"
+
+ glsAddress.toString());
+ poolElement(lsAddresses);
+ }
+ nrOfAddresses--;
+ }
+ } else {
+ logger.warn("Cannot build
glsRegistrationMessage");
}
- } else {
- data = new Data();
- data.setMetadataIdRef(metadata.getId());
- message.addChild(data);
}
- return serviceMessage;
- }
- protected Element getResponseMetadata(ServiceMessage response) {
- Element responseMessage = response.getElement();
-
- if (responseMessage != null) {
- Element responseMetadata = responseMessage
- .getFirstChild("metadata");
- return responseMetadata;
- }
-
- return null;
- }
-
- protected boolean isResponseSuccess(Element responseMetadata) {
- Element eventType =
responseMetadata.getFirstChild("eventType");
- if (eventType != null &&
eventType.getText().trim().contains("success")) {
- return true;
+ if (registeredKeys.isEmpty()) {
+ logger.warn("Registration to LS failed !!");
} else {
- return false;
+ logger.debug("Registration completed");
}
}
- protected Element getKeyFromResponse(ServiceMessage response) {
-
- Element responseMetadata = null;
- responseMetadata = getResponseMetadata(response);
-
- if (responseMetadata != null) {
- if (isResponseSuccess(responseMetadata)) {
- return responseMetadata.getFirstChild("key");
- }
- }
-
- return null;
+ private void poolElement(LinkedList<URL> glsAddresses) {
+ URL brokenGLSURL = glsAddresses.poll();
+ glsAddresses.add(brokenGLSURL);
}
-
- /**
- *
- * returns LSRegistrator configured in configuration.xml
- *
- * @return
- * @throws PerfSONARException
- */
- protected LSRegistrator getLSRegistrator() throws PerfSONARException {
- String className = getOption("registrator").getValue();
- LSRegistrator registrator = null;
+ public void refresh() {
- try {
- registrator = (LSRegistrator) Class.forName(className)
- .newInstance();
- } catch (InstantiationException e) {
- e.printStackTrace();
- throw new PerfSONARException("error",
- "Unable to create an object of : " +
className + ": "
- + e.toString());
-
- } catch (IllegalAccessException e) {
- throw new PerfSONARException("error",
- "Unable to create an object of : " +
className + ": "
- + e.toString());
-
- } catch (ClassNotFoundException e) {
- throw new PerfSONARException("error",
- "Unable to create an object of : " +
className + ": "
- + e.toString());
- }
-
- return registrator;
-
}
-
-}
\ No newline at end of file
+}
- [GEANT/SA2/ps-java-services] r5498 - branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/registration, svn-noreply, 02/22/2010
Archive powered by MHonArc 2.6.16.