Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r2523 - trunk/perfsonar/src/org/perfsonar/client/commons/requests/lookupService

Subject: perfsonar development work

List archive

perfsonar: r2523 - trunk/perfsonar/src/org/perfsonar/client/commons/requests/lookupService


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r2523 - trunk/perfsonar/src/org/perfsonar/client/commons/requests/lookupService
  • Date: Thu, 5 Jul 2007 10:54:21 -0400

Author: mac
Date: 2007-07-05 10:54:21 -0400 (Thu, 05 Jul 2007)
New Revision: 2523

Modified:

trunk/perfsonar/src/org/perfsonar/client/commons/requests/lookupService/LSRegisterRequestGenerator.java
Log:
supported event types added,
serious bug fixed (all parameters were necessary and they were serialized
only when null, what caused NMWG classes serialization exception).

Modified:
trunk/perfsonar/src/org/perfsonar/client/commons/requests/lookupService/LSRegisterRequestGenerator.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/client/commons/requests/lookupService/LSRegisterRequestGenerator.java
2007-07-05 13:12:15 UTC (rev 2522)
+++
trunk/perfsonar/src/org/perfsonar/client/commons/requests/lookupService/LSRegisterRequestGenerator.java
2007-07-05 14:54:21 UTC (rev 2523)
@@ -1,12 +1,14 @@
package org.perfsonar.client.commons.requests.lookupService;

+
+import java.util.Collection;
import java.util.Map;
-import java.util.Collection;

+import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Element;
-import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Message;
import org.ggf.ns.nmwg.base.v2_0.Metadata;
+import org.ggf.ns.nmwg.base.v2_0.Parameters;
import org.ggf.ns.nmwg.tools.org.perfsonar.service.v1_0.AccessPoint;
import org.ggf.ns.nmwg.tools.org.perfsonar.service.v1_0.ContactEmail;
import org.ggf.ns.nmwg.tools.org.perfsonar.service.v1_0.Organization;
@@ -15,15 +17,12 @@
import org.ggf.ns.nmwg.tools.org.perfsonar.service.v1_0.ServiceName;
import org.ggf.ns.nmwg.tools.org.perfsonar.service.v1_0.ServiceType;
import org.ggf.ns.nmwg.tools.org.perfsonar.service.v1_0.ServiceVersion;
-import org.ggf.ns.nmwg.tools.org.perfsonar.v1_0.Subject;
-
+import org.ggf.ns.nmwg.tools.org.perfsonar.service.v1_0.Subject;
import org.perfsonar.client.commons.requests.RequestGenerator;
-
import org.perfsonar.commons.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.commons.auxiliary.ComponentNames;
import
org.perfsonar.commons.auxiliary.components.configuration.ConfigurationComponent;
import org.perfsonar.commons.util.XMLUtils;
-
import org.perfsonar.service.commons.exceptions.PerfSONARException;

/**
@@ -33,12 +32,14 @@
*/
public class LSRegisterRequestGenerator implements RequestGenerator {

+ private static final String METADATA_ID = "serviceLookupInfo";
+
// ----------------------------------------------------- Instance
variables

/**
* Map of common parameters (in metadata)
*/
- private Map commonParameters;
+ private Map<String,String> commonParameters;

/**
* data blocks as Strings
@@ -46,28 +47,29 @@
private String[] metadataElements;


+ private String parserFile = null;
+
// --------------------------------------------------------- Public
Methods


public Message generateRequestMessage() throws PerfSONARException {

- System.out.println("LSRegisterRequestGenerator: generateRequest");
+ //System.out.println("LSRegisterRequestGenerator: generateRequest");

//message
Message message = new Message();
- message.setId("anId");
message.setType("LSRegisterRequest");

//metadata
Metadata metadata = new Metadata();
- metadata.setId("serviceLookupInfo");
+ metadata.setId(METADATA_ID);
message.setMetadata(metadata);

- //data
- Data data = new Data();
- data.setId("serviceLookupInfo-data");
- data.setMetadataIdRef("serviceLookupInfo");
- message.setData(data);
+// //data
+// Data data = new Data();
+// data.setId("serviceLookupInfo-data");
+// data.setMetadataIdRef(METADATA_ID);
+// message.setData(data);

Subject subject = new Subject();
subject.setId("commonParameters");
@@ -75,7 +77,7 @@

Service service = new Service();
service.setId("serviceParameters");
- subject.addChild(service);
+ subject.setService(service);

//access point -- mandatory
String
accessPointString=(String)commonParameters.get("access_point");
@@ -116,7 +118,8 @@
String param;
//service description -- optional
param=(String)commonParameters.get("service_description");
- if (param==null) {
+ if (param!=null) {
+ System.out.println(param);
ServiceDescription sd = new ServiceDescription();
sd.setServiceDescription(param);
service.setServiceDescription(sd);
@@ -124,7 +127,7 @@

//organization name - optional
param=(String)commonParameters.get("organization_name");
- if (param==null) {
+ if (param!=null) {
Organization o = new Organization();
o.setOrganization(param);
service.setOrganization(o);
@@ -132,7 +135,7 @@

//service version - optional
param=(String)commonParameters.get("service_version");
- if (param==null) {
+ if (param!=null) {
ServiceVersion sv = new ServiceVersion();
sv.setServiceVersion(param);
service.setServiceVersion(sv);
@@ -140,63 +143,99 @@

//contact-email - optional
param=(String)commonParameters.get("contact_email");
- if (param==null) {
+ if (param!=null) {
ContactEmail ce = new ContactEmail();
ce.setContactEmail(param);
service.setContactEmail(ce);
}
-

+ //add supported event types
+ param=(String)commonParameters.get("supported_event_types");
+ if (param!=null) {
+
+ String[] supportedEventTypes = param.split("\\,\\ *");
+
+ Parameters eventTypes = new Parameters();
+ eventTypes.setId("supportedEventTypes");
+
+ for (int i=0; i<supportedEventTypes.length; i++) {
+ String et=supportedEventTypes[i];
+ if (!("".equals(et)))
+ eventTypes.addParameter("supportedEventType_"+i, et);
+ }
+
+ metadata.setParameters(eventTypes);
+
+ }
+
//data fields

- System.out.println("LSRegisterRequestGenerator: ");
+ //System.out.println("LSRegisterRequestGenerator: ");

//Create DATAs
- String parserFile = ((ConfigurationComponent)
- AuxiliaryComponentManager.getInstance().
- getComponent(ComponentNames.CONFIG)).
- getProperty("service.sax_parser.config");

- for (int i=0; i<metadataElements.length; i++) {
+ if (metadataElements!=null) {
+
+ //if there are some metadata to be put inside data elements
+ //put them

- System.out.println("LSRegisterRequestGenerator: process data
"+i);
+ //TODO: get rid of getting parser file from CONFIG here
+ if (parserFile==null)
+ parserFile = ((ConfigurationComponent)
+ AuxiliaryComponentManager.getInstance().
+ getComponent(ComponentNames.CONFIG)).
+ getProperty("service.sax_parser.config");

- String xml =
- "<nmwg:message
xmlns=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\"; "
- +
"xmlns:perfsonar=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\"; "
- + "xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"; "
- + "xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\"; "
- + "xmlns:nmwgtopo=\"http://ggf.org/ns/nmwg/topology/2.0/\"; "
- + ">\n"
+ for (int i=0; i<metadataElements.length; i++) {

- + "<nmwg:data id=\"data"+i+"\"
metadataIdRef=\"serviceLookupInfo\">\n"
- + metadataElements[i]
- + "</nmwg:data>\n"
+ //System.out.println("LSRegisterRequestGenerator: process
data "+i);

- + "\n</nmwg:message>\n";
-
- Map<String, Element> dataFromXML = XMLUtils.getElementFromXML(
- xml, "data",
- parserFile);
+ String xml =
+ "<nmwg:message
xmlns=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\"; "
+ +
"xmlns:perfsonar=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\"; "
+ + "xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"; "
+ + "xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\"; "
+ +
"xmlns:nmwgtopo=\"http://ggf.org/ns/nmwg/topology/2.0/\"; "
+ + ">\n"
+
+ + "<nmwg:data id=\"data"+i+"\"
metadataIdRef=\"serviceLookupInfo\">\n"
+ + metadataElements[i]
+ + "</nmwg:data>\n"
+
+ + "\n</nmwg:message>\n";
+
+ Map<String, Element> dataFromXML =
XMLUtils.getElementFromXML(
+ xml, "data",
+ parserFile);

- if (dataFromXML!=null) {
+ if (dataFromXML!=null) {

- Collection<Element> collection = dataFromXML.values();
- for (Element elem : collection) {
- //System.out.println("LSRegisterRequestGenerator:
element " + elem);
- message.addChild(elem);
+ Collection<Element> collection = dataFromXML.values();
+ for (Element elem : collection) {
+ ////System.out.println("LSRegisterRequestGenerator:
element " + elem);
+ message.addChild(elem);
+ }
+
}
-
}

}

+ //finally if there are no data elements, create one
+ if (message.getDataArray().length==0) {
+
+ Data d = new Data();
+ d.setId("data");
+ d.setMetadataIdRef(METADATA_ID);
+ message.setData(d);
+
+ }
return message;

}


- public void setCommonParameters(Map commonParameters) {
+ public void setCommonParameters(Map<String,String> commonParameters) {

this.commonParameters = commonParameters;

@@ -220,6 +259,30 @@
return commonParameters;

}
+
+ public String getParserFile() {
+ return parserFile;
+ }
+
+
+ public void setParserFile(String parserFile) {
+ this.parserFile = parserFile;
+ }


+// public static void main(String[] s) throws PerfSONARException {
+// String parserFile =
"/home/mac/projects/perfsonar/perfsonar-trunk/src/objects.config";
+// LSRegisterRequestGenerator g = new LSRegisterRequestGenerator();
+// g.setParserFile(parserFile);
+// Map<String,String> cp = new HashMap<String,String>();
+// cp.put("access_point", "http://access_point/";);
+// cp.put("service_name", "name_of_service");
+// cp.put("service_version", "1.1");
+// cp.put("service_type", "MA");
+// cp.put("supported_event_types", "abc,def,ghi");
+// g.setCommonParameters(cp);
+// Message m = g.generateRequestMessage();
+// System.out.println(XMLUtils.serializeXML(m) );
+// }
+
} //LSRegisterRequestGenerator



  • perfsonar: r2523 - trunk/perfsonar/src/org/perfsonar/client/commons/requests/lookupService, svnlog, 07/05/2007

Archive powered by MHonArc 2.6.16.

Top of Page