perfsonar-dev - perfsonar: r4908 - in branches/simple-service-with-base2: conf src/main/java/org/perfsonar/base2/service/registration
Subject: perfsonar development work
List archive
perfsonar: r4908 - in branches/simple-service-with-base2: conf src/main/java/org/perfsonar/base2/service/registration
Chronological Thread
- From:
- To:
- Subject: perfsonar: r4908 - in branches/simple-service-with-base2: conf src/main/java/org/perfsonar/base2/service/registration
- Date: Mon, 26 Jan 2009 07:31:53 -0500
Author: roman
Date: 2009-01-26 07:31:52 -0500 (Mon, 26 Jan 2009)
New Revision: 4908
Modified:
branches/simple-service-with-base2/conf/configuration-ma.xml
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/ExistDBRegisterDataSource.java
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
Log:
dealing with remote text file containing ls addresses
Modified: branches/simple-service-with-base2/conf/configuration-ma.xml
===================================================================
--- branches/simple-service-with-base2/conf/configuration-ma.xml
2009-01-26 10:20:20 UTC (rev 4907)
+++ branches/simple-service-with-base2/conf/configuration-ma.xml
2009-01-26 12:31:52 UTC (rev 4908)
@@ -132,13 +132,17 @@
- <extension name="registerDataSource">
+ <extension name="registerExtension-registerDataSource">
<option name="exist-config" value="exist"/>
</extension>
+ <!--
+ <extension name="registerExtension-lsAddresses">
+ <option name="url"
value="http://www.man.poznan.pl/~romradz/ls-addresses"/>
+ </extension>
+ -->
-
<!--
....................................................................................
-->
<!-- Protocol mappings, XML elements and their bingings -->
Modified:
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/ExistDBRegisterDataSource.java
===================================================================
---
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/ExistDBRegisterDataSource.java
2009-01-26 10:20:20 UTC (rev 4907)
+++
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/ExistDBRegisterDataSource.java
2009-01-26 12:31:52 UTC (rev 4908)
@@ -32,6 +32,8 @@
protected final static String DEFAULT_EXIST_COMPONENT = "exist";
+ protected final static String
REGISTER_DATA_SOURCE_EXTENSION_NAME="registerExtension-registerDataSource";
+
//private static final Logger logger =
Logger.getLogger(ExistDBRegisterDataSource.class.getName());
@@ -79,7 +81,7 @@
protected String getExistComponentName(Configuration configuration)
throws PerfSONARException {
- String name = configuration.getExtensionOption("registerDataSource",
"exist-config");
+ String name =
configuration.getExtensionOption(REGISTER_DATA_SOURCE_EXTENSION_NAME,
"exist-config");
if (name != null)
if (!name.trim().equals(""))
return name;
Modified:
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
===================================================================
---
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
2009-01-26 10:20:20 UTC (rev 4907)
+++
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
2009-01-26 12:31:52 UTC (rev 4908)
@@ -12,9 +12,15 @@
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import java.net.URL;
+import java.net.MalformedURLException;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.EOFException;
+import java.io.IOException;
import org.apache.log4j.Logger;
@@ -27,6 +33,8 @@
private static final String DEFAULT_REGISTER_DATA_SOURCE =
"org.perfsonar.base2.service.registration.DumbRegisterDataSource";
+ private static final String REGISTER_LS_ADDRESSES_EXTENSION_NAME =
"registerExtension-lsAddresses";
+
private static final Logger logger =
Logger.getLogger(LSRegistrationAction.class.getName());
protected RegisterDataSource dataSource = null;
@@ -120,9 +128,9 @@
}
- protected URL[] getLSAddresses() {
+ protected URL[] getLSAddresses() throws PerfSONARException {
- List<URL> list = new ArrayList();
+ List<URL> list = new ArrayList<URL>();
Collection<String> lsAddressNames = options.keySet();
for (String lsAddressName : lsAddressNames) {
@@ -139,11 +147,100 @@
}
}
+ // ls addresses fetched from remote file
+ URL[] lsAddressesFromUrl = getLSAddressesFromURL();
+ if (lsAddressesFromUrl != null) {
+ for (int i = 0; i < lsAddressesFromUrl.length; i++)
+ list.add(lsAddressesFromUrl[i]);
+ }
+
+ if (list.size() == 0)
+ throw new PerfSONARException(
+ "warning",
+ "No LS addresses");
+
return ((URL[])list.toArray(new URL[list.size()]));
}
+ protected URL[] getLSAddressesFromURL() throws PerfSONARException {
+ Configuration configuration =
ConfigurationManager.getInstance().getConfiguration();
+ String url = null;
+ try {
+ url =
configuration.getExtensionOption(REGISTER_LS_ADDRESSES_EXTENSION_NAME, "url");
+ } catch (Exception ex ) {
+ return null;
+ }
+ if (url != null)
+ if (!url.trim().equals(""))
+ return getLSAddressesFromURL(url);
+ return null;
+
+ }
+
+
+ protected URL[] getLSAddressesFromURL(String url) {
+
+ List<URL> list = new ArrayList<URL>();
+ BufferedReader br = null;
+
+ try {
+
+ URL urlAdr = new URL(url);
+ InputStream is = urlAdr.openStream();
+ br = new BufferedReader(new InputStreamReader(is));
+
+ } catch (MalformedURLException ex) {
+ logger.error("Bad url of the file with ls addresses: "
+ + url.toString());
+ } catch (IOException ex) {
+ logger.error("IO error while reading ls addresses from remote
file: "
+ + ex.toString());
+ }
+
+ String s = null;
+ boolean eof = false;
+
+ while( !eof ) {
+ try {
+ s = br.readLine();
+ if ( s == null ) {
+ //eof = true;
+ br.close();
+ break;
+ } else if (s.trim().equals("")) {
+ continue;
+ } else if (s.trim().startsWith("#")) {
+ continue;
+ }
+ } catch (EOFException e1) {
+ //eof = true;
+ //continue;
+ break;
+ } catch (IOException e2) {
+ logger.warn("IO error: " + e2.getMessage());
+ continue;
+ }
+
+ URL lsUrl = null;
+ try {
+ lsUrl = new URL(s);
+ list.add(lsUrl);
+ } catch (MalformedURLException ex) {
+ logger.warn("Bad url of ls address: " + url.toString());
+ }
+
+ }
+
+ if (list.size() != 0)
+ return ((URL[])list.toArray(new URL[list.size()]));
+ else
+ return null;
+
+ }
+
+
protected LSRegistrator getLSRegistrator() throws PerfSONARException {
String className = getOption("registrator").getValue();
- perfsonar: r4908 - in branches/simple-service-with-base2: conf src/main/java/org/perfsonar/base2/service/registration, svnlog, 01/26/2009
Archive powered by MHonArc 2.6.16.