Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r4914 - in branches/simple-service-with-base2/src/main/java/org/perfsonar/base2: service/registration xml

Subject: perfsonar development work

List archive

perfsonar: r4914 - in branches/simple-service-with-base2/src/main/java/org/perfsonar/base2: service/registration xml


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r4914 - in branches/simple-service-with-base2/src/main/java/org/perfsonar/base2: service/registration xml
  • Date: Tue, 27 Jan 2009 09:04:59 -0500

Author: roman
Date: 2009-01-27 09:04:58 -0500 (Tue, 27 Jan 2009)
New Revision: 4914

Modified:

branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/DumbRegisterDataSource.java

branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/GenericLSRegistrator.java

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/LSRegistrator.java

branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/xml/Element.java
Log:
keepalive functionality added


Modified:
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/DumbRegisterDataSource.java
===================================================================
---
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/DumbRegisterDataSource.java
2009-01-27 12:37:27 UTC (rev 4913)
+++
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/DumbRegisterDataSource.java
2009-01-27 14:04:58 UTC (rev 4914)
@@ -29,7 +29,7 @@

Parameter parameter = new Parameter();
parameter.setParameter("name", "attr-testing");
- parameter.setText("val-testing");
+ parameter.setText("val-testing");
parameters.addParameter(parameter);
metadata.addChild(parameters);


Modified:
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/GenericLSRegistrator.java
===================================================================
---
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/GenericLSRegistrator.java
2009-01-27 12:37:27 UTC (rev 4913)
+++
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/GenericLSRegistrator.java
2009-01-27 14:04:58 UTC (rev 4914)
@@ -5,7 +5,6 @@
package org.perfsonar.base2.service.registration;

import org.perfsonar.base2.service.requesthandler.ServiceMessage;
-import org.perfsonar.base2.service.configuration.LookupInformation;
import org.perfsonar.base2.service.exceptions.PerfSONARException;

import org.perfsonar.base2.client.Client;
@@ -15,12 +14,9 @@
import org.perfsonar.base2.xml.nmwg.Message;
import org.perfsonar.base2.xml.nmwg.Metadata;
import org.perfsonar.base2.xml.nmwg.Data;
-import org.perfsonar.base2.xml.nmwg.EventType;
-import org.perfsonar.base2.xml.nmwg.Subject;
-import org.perfsonar.base2.xml.nmwg.NMWGNamespaceFactory;
+import org.perfsonar.base2.xml.nmwg.Key;

import java.net.URL;
-import java.util.Collection;

import org.apache.log4j.Logger;

@@ -30,140 +26,63 @@

// ----------------------------------------------------------- Variables

-
- protected static final String REGISTRATION_EVENT_TYPE =
-
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/registration/service/2.0";;
-
- protected static final String REGISTRATION_MESSAGE_TYPE =
"LSRegisterRequest";
-
private static final Logger logger =
Logger.getLogger(GenericLSRegistrator.class.getName());

- protected LookupInformation lookupInformation = null;
- protected RegisterDataSource dataSource = null;
- protected URL[] lsUrl = null;

-
// ----------------------------------------------------------- Methods


- public void init(LookupInformation lookupInformation, RegisterDataSource
dataSource, URL[] lsUrl)
- throws PerfSONARException {
+ public ServiceMessage register(Message requestMessage, URL lsUrl) throws
PerfSONARException {

- this.lookupInformation = lookupInformation;
- this.dataSource = dataSource;
- this.lsUrl = lsUrl;
-
+ return send(requestMessage, lsUrl);
}


- public ServiceMessage[] register() throws PerfSONARException {
+ public ServiceMessage deregister(Key key, URL lsUrl)
+ throws PerfSONARException {

- ServiceMessage serviceRequestMessage = getLSRegsiterMessage();
- Element requestElement = serviceRequestMessage.getElement();
+ //TODO
+ return null;

- ServiceMessage[] serviceResponseMessage = new
ServiceMessage[lsUrl.length];
- Element responseElement = null;
-
- Client client = new Axis2Client();
-
- for (int i = 0; i < lsUrl.length; i++) {
-
- responseElement = client.send(lsUrl[i].toString(),
requestElement);
- serviceResponseMessage[i] = new
ServiceMessage(responseElement.getCopy());
-
- logger.debug("Register request sent to the LS " +
lsUrl[i].toString());
-
- }
-
- return serviceResponseMessage;
-
}


- protected ServiceMessage getLSRegsiterMessage() throws
PerfSONARException {
-
- ServiceMessage serviceMessage = new ServiceMessage();
-
- //message
- Message message = new Message();
- message.setType(REGISTRATION_MESSAGE_TYPE);
- serviceMessage.setElement(message);
-
- //metadata
- Metadata metadata = new Metadata();
- metadata.setId("serviceLookupInfo");
- message.setMetadata(metadata);
-
- EventType eventType = new EventType();
- eventType.setEventType(REGISTRATION_EVENT_TYPE);
- 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();
- Element element = null;
- for (String name: keys) {
- element = new Element(name, "psservice",
NMWGNamespaceFactory.getNamespace("psservice"));
- element.setText(lookupInformation.getOption(name).getValue());
- service.addChild(element);
- }
-
-
- /*
- Data data = new Data();
- data.setMetadataIdRef(metadata.getId());
- message.setData(data);
- */
-
- Data data = null;
- Message msg = (Message)dataSource.getRegisterData().getElement();
- Collection<Metadata> c = msg.getMetadataCollection();
- for (Metadata m: c) {
- data = new Data();
- data.setMetadataIdRef(metadata.getId());
- data.addChild(m);
- message.setData(data);
- }
-
- return serviceMessage;
-
- }
-
-
- public ServiceMessage[] deregister(String key)
+ public ServiceMessage update(Key key, URL lsUrl)
throws PerfSONARException {

//TODO
-
return null;

}


- public ServiceMessage[] update(String key)
+ public ServiceMessage keepalive(Element key, URL lsUrl)
throws PerfSONARException {

- //TODO
+ Message requestMessage = new Message("LSKeepaliveRequest", "msg");
+ Metadata requestMetadata = new Metadata("key_to_keepalive", "nmwg");
+ requestMessage.setMetadata(requestMetadata);
+ Data requestData = new Data("d1", "key_to_keepalive", "nmwg");
+ //Data requestData = new Data("d1",
requestMetadata.getMetadataIdRef(), "nmwg");
+ requestMessage.setData(requestData);
+ requestMetadata.addChild(key);

- return null;
+ return send(requestMessage, lsUrl);

}

-
- public ServiceMessage[] keepalive(String key)
+ protected ServiceMessage send(Element element, URL lsUrl)
throws PerfSONARException {

- //TODO
+ Client client = new Axis2Client();

- return null;
+ Element responseElement = client.send(lsUrl.toString(), element);
+ ServiceMessage serviceResponseMessage = new
ServiceMessage(responseElement.getCopy());

+ logger.debug("LS request sent to the LS " + lsUrl.toString());
+ return serviceResponseMessage;
}


+
} //GenericLSRegistrator
\ No newline at end of file

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-27 12:37:27 UTC (rev 4913)
+++
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
2009-01-27 14:04:58 UTC (rev 4914)
@@ -10,7 +10,17 @@
import org.perfsonar.base2.service.configuration.ConfigurationManager;
import org.perfsonar.base2.service.scheduler.SchedulerAction;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import org.perfsonar.base2.service.requesthandler.ServiceMessage;

+import org.perfsonar.base2.xml.Element;
+import org.perfsonar.base2.xml.nmwg.Message;
+import org.perfsonar.base2.xml.nmwg.Metadata;
+import org.perfsonar.base2.xml.nmwg.Data;
+import org.perfsonar.base2.xml.nmwg.EventType;
+import org.perfsonar.base2.xml.nmwg.Subject;
+import org.perfsonar.base2.xml.nmwg.Key;
+import org.perfsonar.base2.xml.nmwg.NMWGNamespaceFactory;
+
import java.net.URL;
import java.net.MalformedURLException;
import java.util.List;
@@ -31,16 +41,22 @@
// ----------------------------------------------------------- Variables


- private static final String DEFAULT_REGISTER_DATA_SOURCE =
"org.perfsonar.base2.service.registration.DumbRegisterDataSource";
+ protected static final String DEFAULT_REGISTER_DATA_SOURCE =
"org.perfsonar.base2.service.registration.DumbRegisterDataSource";

- private static final String REGISTER_LS_ADDRESSES_EXTENSION_NAME =
"registerExtension-lsAddresses";
+ protected static final String REGISTER_LS_ADDRESSES_EXTENSION_NAME =
"registerExtension-lsAddresses";

+ protected static final String REGISTRATION_EVENT_TYPE =
+
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/registration/service/2.0";;
+
+ protected static final String REGISTRATION_MESSAGE_TYPE =
"LSRegisterRequest";
+
private static final Logger logger =
Logger.getLogger(LSRegistrationAction.class.getName());

protected RegisterDataSource dataSource = null;
protected LookupInformation lookupInformation = null;
protected LSRegistrator registrator = null;
protected URL[] lsURLs;
+ protected Element[] lsKeys;

protected boolean initiated = false;

@@ -59,13 +75,11 @@
public void runAction() {

try {
-
if (!initiated) {
init();
initiated = true;
}
- org.perfsonar.base2.service.requesthandler.ServiceMessage sm[] =
registrator.register();
-
+ execute();
} catch (Exception ex) {

logger.error(
@@ -82,13 +96,64 @@

dataSource = getRegisterDataSource();
lookupInformation = getLookupInformation();
+
lsURLs = getLSAddresses();
+ lsKeys = new Element[lsURLs.length];
+ for (int i = 0; i < lsURLs.length; i++) lsKeys[i] = null;
+
registrator = getLSRegistrator();
- registrator.init(lookupInformation, dataSource, lsURLs);

}


+ protected void execute() throws PerfSONARException {
+
+ if (lsURLs == null || lsURLs.length == 0) {
+ logger.error("No LS addresses");
+ return;
+ }
+
+ ServiceMessage serviceRequestMessage = getLSRegsiterMessage();
+ Message requestMessage = (Message)
serviceRequestMessage.getElement();
+
+ ServiceMessage[] serviceResponseMessage = new
ServiceMessage[lsURLs.length];
+
+ for (int i = 0; i < lsURLs.length; i++) {
+
+ if (lsKeys[i] == null) {
+ // sending the LsRegisterRequest
+ serviceResponseMessage[i] =
registrator.register(requestMessage, lsURLs[i]);
+ } else {
+ // sending the LSKeepaliveRequest
+ serviceResponseMessage[i] = registrator.keepalive(lsKeys[i],
lsURLs[i]);
+ }
+
+ Element responseMessage = serviceResponseMessage[i].getElement();
+
+ Element responseMetadata = null;
+ Element eventType = null;
+
+ if (responseMessage != null) {
+ responseMetadata =
responseMessage.getChildren("metadata").iterator().next();
+ if (responseMetadata != null) {
+ eventType =
responseMetadata.getChildren("eventType").iterator().next();
+ }
+ }
+ if (eventType != null) {
+ if
(eventType.getText().trim().indexOf("success.ls.register") != -1) {
+ lsKeys[i] =
responseMetadata.getChildren("key").iterator().next();
+ } else if (eventType.getText().trim().indexOf("success.ls")
== -1) {
+ lsKeys[i] = null;
+ }
+ } else {
+ lsKeys[i] = null;
+ }
+
+ }
+
+ }
+
+
protected RegisterDataSource getRegisterDataSource() throws
PerfSONARException {

String className = DEFAULT_REGISTER_DATA_SOURCE;
@@ -163,6 +228,7 @@

}

+
protected URL[] getLSAddressesFromURL() throws PerfSONARException {

Configuration configuration =
ConfigurationManager.getInstance().getConfiguration();
@@ -265,5 +331,51 @@
}


+ protected ServiceMessage getLSRegsiterMessage() throws
PerfSONARException {

+ ServiceMessage serviceMessage = new ServiceMessage();
+
+ Message message = new Message();
+ message.setType(REGISTRATION_MESSAGE_TYPE);
+ serviceMessage.setElement(message);
+
+ Metadata metadata = new Metadata();
+ metadata.setId("serviceLookupInfo");
+ message.setMetadata(metadata);
+
+ EventType eventType = new EventType();
+ eventType.setEventType(REGISTRATION_EVENT_TYPE);
+ 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();
+ Element element = null;
+ for (String name: keys) {
+ 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();
+ for (Metadata m: c) {
+ data = new Data();
+ data.setMetadataIdRef(metadata.getId());
+ data.addChild(m);
+ message.setData(data);
+ }
+
+ return serviceMessage;
+
+ }
+
+
} //LSRegistrationAction
\ No newline at end of file

Modified:
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrator.java
===================================================================
---
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrator.java
2009-01-27 12:37:27 UTC (rev 4913)
+++
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrator.java
2009-01-27 14:04:58 UTC (rev 4914)
@@ -8,29 +8,29 @@
import org.perfsonar.base2.service.configuration.LookupInformation;
import org.perfsonar.base2.service.exceptions.PerfSONARException;

+import org.perfsonar.base2.xml.Element;
+import org.perfsonar.base2.xml.nmwg.Message;
+import org.perfsonar.base2.xml.nmwg.Key;
+
import java.net.URL;


public interface LSRegistrator {


- public void init(LookupInformation lookupInformation, RegisterDataSource
dataSource, URL[] lsUrl)
+ public ServiceMessage register(Message requestMessage, URL lsUrl)
throws PerfSONARException;

-
- public ServiceMessage[] register()
- throws PerfSONARException;

-
- public ServiceMessage[] deregister(String key)
+ public ServiceMessage deregister(Key key, URL lsUrl)
throws PerfSONARException;


- public ServiceMessage[] update(String key)
+ public ServiceMessage update(Key key, URL lsUrl)
throws PerfSONARException;


- public ServiceMessage[] keepalive(String key)
+ public ServiceMessage keepalive(Element key, URL lsUrl)
throws PerfSONARException;



Modified:
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/xml/Element.java
===================================================================
---
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/xml/Element.java
2009-01-27 12:37:27 UTC (rev 4913)
+++
branches/simple-service-with-base2/src/main/java/org/perfsonar/base2/xml/Element.java
2009-01-27 14:04:58 UTC (rev 4914)
@@ -145,7 +145,7 @@
return attributes.get(name);

}
-
+
public int getAttributeAsInt(String name) {
try {
String param = getAttribute(name);



  • perfsonar: r4914 - in branches/simple-service-with-base2/src/main/java/org/perfsonar/base2: service/registration xml, svnlog, 01/27/2009

Archive powered by MHonArc 2.6.16.

Top of Page