Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r4731 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: . level0 level1

Subject: perfsonar development work

List archive

perfsonar: r4731 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: . level0 level1


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r4731 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: . level0 level1
  • Date: Tue, 2 Dec 2008 12:49:55 -0500

Author: michael.bischoff
Date: 2008-12-02 12:49:54 -0500 (Tue, 02 Dec 2008)
New Revision: 4731

Modified:

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/LsClientImpl.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/Level0Impl.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/SOAPEndpoint.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/Level1Impl.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/LsQuery.java
Log:
Fixed bug - wrong level0 method beeign called raw vs discovery
improved logging
added eager loading.

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/LsClientImpl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/LsClientImpl.java
2008-12-02 17:47:22 UTC (rev 4730)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/LsClientImpl.java
2008-12-02 17:49:54 UTC (rev 4731)
@@ -39,6 +39,9 @@
} else {
logger.info("Creating LSClient.");
}
+ if(logger.isTraceEnabled()) {
+ logger.warn("Because we are tracing performance is crippled
some what as streams are buffered as a whole and used for logging. - Don't
enable tracing for the LSClient in production environment.");
+ }
}

@Override

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/Level0Impl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/Level0Impl.java
2008-12-02 17:47:22 UTC (rev 4730)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/Level0Impl.java
2008-12-02 17:49:54 UTC (rev 4731)
@@ -44,7 +44,7 @@
public InputStream getRawQueryResult(LookupService lookupService,
String xquery) throws LsQueryException, IllegalArgumentException {
String xml = makeXml("<xquery:subject id=\"sub1\">", xquery,
"</xquery:subject>", QUERY_EVENTTYPE);
SOAPMessage message = createMessage(xml);
- logger.debug("Executing raw xquery ["+xml+"]");
+ logger.debug("Executing raw xquery ["+xquery+"]");
InputStream inputStream = send(message, lookupService);
return new BufferedSoapStrippingStream(inputStream);
}
@@ -140,7 +140,7 @@
public InputStream getRawDiscoveryResponse(LookupService
lookupService, String summaryDescription) throws LsQueryException {
String xml = makeDiscoveryXml(summaryDescription);
SOAPMessage message = createMessage(xml);
- logger.debug("Executing raw discovery query ["+xml+"]");
+ logger.debug("Executing raw discovery query
["+summaryDescription+"]");
InputStream inputStream = send(message, lookupService);
return new BufferedSoapStrippingStream(inputStream);
}

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/SOAPEndpoint.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/SOAPEndpoint.java
2008-12-02 17:47:22 UTC (rev 4730)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/SOAPEndpoint.java
2008-12-02 17:49:54 UTC (rev 4731)
@@ -1,9 +1,12 @@
package org.perfsonar.ri.lsclient.level0;

+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.io.StringBufferInputStream;
+import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
@@ -53,11 +56,13 @@
boolean success = checkResponse(httpConnection);
InputStream httpIn = (success ? httpConnection.getInputStream() :
httpConnection.getErrorStream());

- StringBuilder builder = new StringBuilder();
- int i;
- while((i = httpIn.read())!=-1) builder.append((char)i);
- System.out.println(builder.toString());
- httpIn = new StringBufferInputStream(builder.toString());
+ if(logger.isTraceEnabled()) {
+ Reader reader = new InputStreamReader(httpIn);
+ StringBuilder builder = new StringBuilder();
+ int i; while((i = reader.read())!=-1) builder.append((char)i);
+ logger.trace("Recieved Message ["+builder.toString()+"]");
+ httpIn = new
ByteArrayInputStream(builder.toString().getBytes());
+ }

return httpIn;
}
@@ -75,6 +80,11 @@
}

protected void sendMessage(SOAPMessage message, HttpURLConnection
httpConnection) throws IOException, SOAPException {
+ if(logger.isTraceEnabled()) {
+ ByteArrayOutputStream log = new
ByteArrayOutputStream();
+ message.writeTo(log);
+ logger.trace("Sending message
["+log.toString("UTF-8")+"]");
+ }
OutputStream out = httpConnection.getOutputStream();
httpConnection.connect();
message.writeTo(out);

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/Level1Impl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/Level1Impl.java
2008-12-02 17:47:22 UTC (rev 4730)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/Level1Impl.java
2008-12-02 17:49:54 UTC (rev 4731)
@@ -2,7 +2,6 @@

import java.io.IOException;
import java.io.InputStream;
-import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URLConnection;
import java.util.Arrays;
@@ -33,7 +32,6 @@
import org.perfsonar.lsclient.data.ServiceType;
import org.perfsonar.lsclient.data.TopologyElement;
import org.perfsonar.lsclient.helpers.AbstractLevel1;
-import org.perfsonar.ri.lsclient.level1.jaxb.Datum;
import org.perfsonar.ri.lsclient.level1.jaxb.JaxbTools;
import org.perfsonar.ri.lsclient.level1.jaxb.ServiceImpl;
import org.slf4j.Logger;
@@ -43,13 +41,21 @@

protected class RootGlses implements Iterable<LookupService> {
private final ConcurrentLinkedQueue<LookupService> data = new
ConcurrentLinkedQueue<LookupService>();
-
+ private final Object timerMutex;
+ private final Object mutex;
+ protected volatile Timer timer;
+
+ public RootGlses() {
+ this.mutex = this;
+ this.timerMutex = new Object();
+ }
+
public boolean isEmpty() {
return data.isEmpty();
}

public void replace(Collection<LookupService> values) {
- synchronized (this) {
+ synchronized (mutex) {
//TODO speed up by using parallel requests. +
add cutoff points.
SortedMap<Long, LookupService> timedServices
= new TreeMap<Long, LookupService>();
for(LookupService service : values) {
@@ -86,7 +92,7 @@
* @param e
*/
public void demote(LookupService service, LsQueryException e)
{
- synchronized (this) {
+ synchronized (mutex) {
logger.warn("Demoting serivce", e);
if(!data.contains(service)) return;
if(data.peek() == service) {
@@ -97,35 +103,49 @@
}

public void ensureFilled() {
- if(rootGlses.isEmpty()) {
- synchronized (this) {
- if(rootGlses.isEmpty()) {
- fill();
- }
+ if(data.isEmpty()) synchronized (mutex) {
+ if(data.isEmpty()) {
+ fill();
}
}
}

protected void fill() {
- timer = new Timer("Ls-GlsList-refresher");
replace(getDefaultLookupServices());
- timer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- synchronized (this) {
- if(timer==null) return;
-
replace(getDefaultLookupServices());
- }
- }
- }, 600000, 600000);
+ if(timer==null) synchronized(timerMutex) {
+ if(timer==null) {
+ timer = new
Timer("Ls-GlsList-refresher");
+ timer.scheduleAtFixedRate(new
TimerTask() {
+ @Override
+ public void run() {
+ synchronized (this) {
+
if(timer==null) return;
+
replace(getDefaultLookupServices());
+ }
+ }

+ }, 600000, 600000);
+ }
+ }
+ }
+
+ public void stopAutoRefresh() {
+ if(timer!=null) synchronized(timerMutex) {
+ if(timer!=null) {
+ logger.debug("Stopping auto-refresh
from root.hints");
+ timer.cancel();
+ timer = null;
+ }
+ }
}
}
+
+ private static final String EAGER_SYSTEM_KEY =
"application.perfsonar.lsclient.eagerRootLses";

protected final Logger logger = LoggerFactory.getLogger(getClass());

protected final RootGlses rootGlses = new RootGlses();
protected final JAXBContext context;
- protected Timer timer;

+ @SuppressWarnings("boxing")
public Level1Impl(Level0LsClientInterface level0) {
super(level0);
JAXBContext newContext = null;
@@ -136,6 +156,15 @@
} catch (JAXBException e) {
logger.error("Can't load JAXB context",e);
}
+ try {
+ String value = System.getProperty(EAGER_SYSTEM_KEY);
+ if(Boolean.valueOf(value)) {
+ rootGlses.ensureFilled();
+ }
+ } catch (SecurityException e) {
+ logger.warn("Wasn't allowed to read system property
\"application.perfsonar.lsclient.eagerRootLses\"");
+ }
+
this.context = newContext;
}

@@ -196,33 +225,12 @@
" serviceType is any "+ (type == null
? "" : Arrays.toString(type.toArray()))
);
}
-// DiscoveryQuery query = new
DiscoveryQuery(elements,eventTypes,type);
-
- LsQuery query = new LsQuery(elements,eventTypes,type) {
- @Override
- public String toString() {
- String selectIds =
"/nmwg:store[@type=\'LSStore\']/nmwg:data["+eventTypeCondition+"]/@metadataIdRef";
- return
- "declare namespace
perfsonar=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\";; \n" +
- "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; \n" +
- "declare namespace
psservice=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/\";; \n" +
- "declare namespace
nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\";; \n" +
- "declare namespace
netutil=\"http://ggf.org/ns/nmwg/characteristic/utilization/2.0/\";; \n" +
- "declare namespace
summary=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/summarization/2.0/\";;
\n" +
- "\n" +
-
"/nmwg:store[@type='LSStore']/nmwg:metadata[@id
= " + selectIds + "]/perfsonar:subject/psservice:service";
- }
- };
-
+ DiscoveryQuery query = new
DiscoveryQuery(elements,eventTypes,type);
try {
- InputStream stream =
level0.getRawQueryResult(hls,query.toString());
-// return new
HashSet<Service>(JaxbTools.unMarshallPerfsonarMessage(context, stream,
ServiceImpl.class));
-
- Collection<Datum> data =
JaxbTools.unMarshallPerfsonarMessage(context, stream, Datum.class);
- for(Datum datum : data) {
- Set<Service> services = new
HashSet<Service>(JaxbTools.unMarshall(context, new
StringReader("<result>"+datum.getValue()+"</result>"), ServiceImpl.class));
- return services;
- }
+ InputStream stream =
level0.getRawDiscoveryResponse(hls,query.toString());
+ Collection<ServiceImpl> result =
JaxbTools.unMarshallPerfsonarMessage(context, stream, ServiceImpl.class);
+ for(ServiceImpl service : result)
service.setAuthorativeLookupservice(hls);
+ return new HashSet<Service>(result);
} catch (JAXBException e) {
logger.error("JAXB exception occoured while quering
for location", e);
return Collections.emptySet(); //TODO
@@ -233,16 +241,12 @@
logger.error("LsQuery exception occoured while
quering for location", e);
return Collections.emptySet(); //TODO
}
- return Collections.emptySet();
}

public void setKnownLookupServices(Set<LookupService> rootServices) {
if(rootServices==null) throw new
IllegalArgumentException("new rootServices set cannot be null");
if(rootServices.isEmpty()) throw new
IllegalArgumentException("new rootServices set cannot be empty");
- synchronized (rootGlses) {
- timer.cancel();
- timer = null;
- }
+ rootGlses.stopAutoRefresh();
rootGlses.replace(rootServices);
}
public Set<LookupService> getDefaultLookupServices() {

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/LsQuery.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/LsQuery.java
2008-12-02 17:47:22 UTC (rev 4730)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/LsQuery.java
2008-12-02 17:49:54 UTC (rev 4731)
@@ -26,7 +26,7 @@
}

private String getEventTypeCondition(Set<EventType> eventTypes) {
- if(eventTypes == null || !eventTypes.isEmpty()) {
+ if(eventTypes == null || eventTypes.isEmpty()) {
return "true()";
}

@@ -46,5 +46,16 @@
}

@Override
- public abstract String toString();
+ public String toString() {
+ String selectIds =
"/nmwg:store[@type=\'LSStore\']/nmwg:data["+eventTypeCondition+"]/@metadataIdRef";
+ return
+ "declare namespace
perfsonar=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\";; \n" +
+ "declare namespace nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";;
\n" +
+ "declare namespace
psservice=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/\";; \n" +
+ "declare namespace
nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\";; \n" +
+ "declare namespace
netutil=\"http://ggf.org/ns/nmwg/characteristic/utilization/2.0/\";; \n" +
+ "declare namespace
summary=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/summarization/2.0/\";;
\n" +
+ "\n" +
+
"/nmwg:store[@type='LSStore']/nmwg:metadata[@id
= " + selectIds + "]/perfsonar:subject/psservice:service";
+ }
}



  • perfsonar: r4731 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: . level0 level1, svnlog, 12/02/2008

Archive powered by MHonArc 2.6.16.

Top of Page