Manuele Simi 2009-10-15 23:28:35 +00:00
parent 11ca4a5f4d
commit 1938782e83
8 changed files with 353 additions and 81 deletions

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>InformationCollector_previous</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>InformationCollector_branched</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -20,7 +20,7 @@
sink by collecting and exposing the information published by the
registered gCube services</Description>
<Name>IS-Collector-service</Name>
<Version>2.0.0</Version>
<Version>2.1.0</Version>
<Dependencies>
<Dependency>
<Service>
@ -29,7 +29,7 @@
<Version>1.0.0</Version>
</Service>
<Package>IS-Collector-stubs</Package>
<Version>[2.0.0]</Version>
<Version>[2.1.0]</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
@ -76,7 +76,7 @@
<Software deployable="true">
<Description>InformationCollector Stubs</Description>
<Name>IS-Collector-stubs</Name>
<Version>2.0.0</Version>
<Version>2.1.0</Version>
<MultiVersion value="true" />
<Mandatory level="VO" />
<Shareable level="VO" />
@ -88,7 +88,7 @@
<Software>
<Description>Test-suite for IS-Collector: provide sample usages of interaction with a IS-Collector instance</Description>
<Name>IS-Collector-test-suite</Name>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<MultiVersion value="true"/>
<Shareable level="VO"/>
<Type>application</Type>

View File

@ -4,6 +4,7 @@
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:asgt="http://mds.globus.org/aggregator/types"
xmlns:corefaults="http://gcube-system.org/namespaces/common/core/faults"
xmlns:wsrlw="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl"
xmlns:wsdlpp="http://www.globus.org/namespaces/2004/10/WSDLPreprocessor"
xmlns:gtwsdl1="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ServiceGroup-1.2-draft-01.wsdl"
@ -16,7 +17,7 @@
<wsdl:import namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-BaseFaults-1.2-draft-01.wsdl" location="../wsrf/faults/WS-BaseFaults.wsdl"/>
<wsdl:import namespace="http://mds.globus.org/aggregator" location="../mds/aggregator/aggregator_service_group_port_type.wsdl"/>
<wsdl:import namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ServiceGroup-1.2-draft-01.wsdl" location="../wsrf/servicegroup/WS-ServiceGroup.wsdl"/>
<wsdl:import namespace="http://gcube-system.org/namespaces/common/core/faults" location="../gcube/common/core/faults/GCUBEFaults.wsdl"/>
<!--============================================================
@ -44,6 +45,10 @@
<xsd:element name="deleteResponse" type="xsd:boolean"/>
<xsd:element name="getProfileResponse" type="xsd:string"/>
<xsd:element name="getResourceResponse" type="xsd:string"/>
<xsd:element name="deleteProfileParams">
<xsd:complexType >
<xsd:sequence>
@ -53,8 +58,37 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="GetProfileCriteria">
<xsd:complexType >
<xsd:sequence>
<xsd:element name="ID" type="xsd:string"/>
<xsd:element name="profileType" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetResourceCriteria">
<xsd:complexType >
<xsd:sequence>
<xsd:element name="ID" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="voidType"/>
<xsd:element name="voidElement" type="tns:voidType"/>
<xsd:element name="voidElement" type="tns:voidType"/>
<xsd:element name="DocumentNotFoundFaultType">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="corefaults:GCUBEUnrecoverableFault">
<xsd:sequence/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
@ -65,7 +99,7 @@
============================================================-->
<wsdl:message name="DeleteResourceInputMessage">
<wsdl:message name="DeleteResourceInputMessage">
<part name="parameters" element="tns:resourceID"/>
</wsdl:message>
@ -73,6 +107,14 @@
<part name="parameters" element="tns:deleteResponse"/>
</wsdl:message>
<wsdl:message name="GetResourceInputMessage">
<part name="parameters" element="tns:GetResourceCriteria"/>
</wsdl:message>
<wsdl:message name="GetResourceOutputMessage">
<part name="parameters" element="tns:getResourceResponse"/>
</wsdl:message>
<wsdl:message name="DeleteProfileInputMessage">
<part name="parameters" element="tns:deleteProfileParams"/>
</wsdl:message>
@ -81,9 +123,21 @@
<part name="parameters" element="tns:deleteResponse"/>
</wsdl:message>
<wsdl:message name="GetProfileInputMessage">
<part name="parameters" element="tns:GetProfileCriteria"/>
</wsdl:message>
<wsdl:message name="GetProfileOutputMessage">
<part name="parameters" element="tns:getProfileResponse"/>
</wsdl:message>
<wsdl:message name="VoidMessage">
<part name="parameters" element="tns:voidElement"/>
</wsdl:message>
<wsdl:message name="DocumentNotFoundFaultTypeMessage">
<part name="fault" element="tns:DocumentNotFoundFaultType"/>
</wsdl:message>
<!--============================================================
@ -93,6 +147,16 @@
<wsdl:portType name="XMLCollectionAccessPortType">
<wsdl:operation name="GetProfile">
<wsdl:input message="tns:GetProfileInputMessage"/>
<wsdl:output message="tns:GetProfileOutputMessage"/>
<wsdl:fault name="fault" message="tns:DocumentNotFoundFaultTypeMessage"/>
</wsdl:operation>
<wsdl:operation name="GetResource">
<wsdl:input message="tns:GetResourceInputMessage"/>
<wsdl:output message="tns:GetResourceOutputMessage"/>
<wsdl:fault name="fault" message="tns:DocumentNotFoundFaultTypeMessage"/>
</wsdl:operation>
<wsdl:operation name="DeleteResource">
<wsdl:input message="tns:DeleteResourceInputMessage"/>
<wsdl:output message="tns:DeleteResourceOutputMessage"/>

View File

@ -10,6 +10,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
@ -21,6 +22,13 @@ import org.w3c.dom.*;
import org.xml.sax.InputSource;
import javax.xml.parsers.*;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.*;
/**
@ -46,8 +54,7 @@ public class AggregatorPersistentResource extends PersistentResource {
private String profile_type = null;
// the various parts of the resource
private String data, /* service_class, service_id, ri_id, ghn_id, scope, */
entryKey, groupKey, source, sourceKey = "", completeSourceKey = "";
private String data = null, entryKey, groupKey, source, sourceKey = "", completeSourceKey = "";
private Calendar terminationTime = null, lastUpdateTime = null;
@ -95,6 +102,8 @@ public class AggregatorPersistentResource extends PersistentResource {
* if the resource is invalid
*/
public AggregatorPersistentResource(XMLResource resource) throws Exception {
if (resource == null)
throw new Exception("invalid resource");
try {
this.resourceID = resource.getId();
this.originalSource = resource;
@ -161,11 +170,35 @@ public class AggregatorPersistentResource extends PersistentResource {
* Accesses the resource content
*
* @return the content
* @throws MalformedResourceException
*/
public String getData() {
public String getData() throws MalformedResourceException {
if (this.data == null)
this.data = this.extractData();
return this.data;
}
/**
* @return
* @throws MalformedResourceException
*/
private String extractData() throws MalformedResourceException {
if (this.internalDOM != null) {
try {
if (this.getType() == RESOURCETYPE.Profile)
return nodeToString(internalDOM.getElementsByTagName("Resource").item(0)); //Data/Profile/Resource
else
return nodeToString(internalDOM.getElementsByTagName("Data").item(0)); //Data/*
} catch (Exception e) {
logger.error("",e);
throw new MalformedResourceException("unable to retrieve data for resource " + this.getID());
}
} else
throw new MalformedResourceException("unable to retrieve data for resource " + this.getID());
}
/**
*
* @return the original XMLResource from which the resource has been
@ -299,9 +332,27 @@ public class AggregatorPersistentResource extends PersistentResource {
* @return the type
*/
public RESOURCETYPE getType() {
if (this.type == null)
this.type = this.extractType();
return this.type;
}
/**
* @return
*/
private RESOURCETYPE extractType() {
if (internalDOM.getElementsByTagName("Resource").getLength() > 0) {
logger.trace("The resource is a profile");
return RESOURCETYPE.Profile;
}
else {
logger.trace("The resource is a RP");
return RESOURCETYPE.Properties;
}
}
/**
* Updates the resource body
*
@ -321,27 +372,24 @@ public class AggregatorPersistentResource extends PersistentResource {
*/
private String toXML() {
String rep = "<Document>\n";
rep += "<ID>" + this.getID() + "</ID>\n";
rep += "<Source>" + this.getSource() + "</Source>\n";
rep += "<SourceKey>" + this.getSourceKey() + "</SourceKey>\n";
rep += "<CompleteSourceKey>" + this.getCompleteSourceKey()
+ "</CompleteSourceKey>\n";
rep += "<EntryKey>" + this.getEntryKey() + "</EntryKey>\n";
rep += "<GroupKey>" + this.getGroupKey() + "</GroupKey>\n";
rep += "<TerminationTime>"
+ this.getTerminationTime().getTimeInMillis()
+ "</TerminationTime>\n";
rep += "<TerminationTimeHuman>"
+ this.getTerminationTime().getTime().toString()
+ "</TerminationTimeHuman>\n";
rep += "<LastUpdateMs>" + this.lastUpdateTime.getTimeInMillis()
+ "</LastUpdateMs>\n";
rep += "<LastUpdateHuman>" + this.lastUpdateTime.getTime().toString()
+ "</LastUpdateHuman>\n";
rep += this.getData() + "\n";
rep += "</Document>\n";
return rep;
StringBuilder resource = new StringBuilder("<Document>\n");
resource.append("<ID>" + this.getID() + "</ID>\n");
resource.append("<Source>" + this.getSource() + "</Source>\n");
resource.append("<SourceKey>" + this.getSourceKey() + "</SourceKey>\n");
resource.append("<CompleteSourceKey>" + this.getCompleteSourceKey() + "</CompleteSourceKey>\n");
resource.append("<EntryKey>" + this.getEntryKey() + "</EntryKey>\n");
resource.append("<GroupKey>" + this.getGroupKey() + "</GroupKey>\n");
resource.append("<TerminationTime>"+ this.getTerminationTime().getTimeInMillis()+ "</TerminationTime>\n");
resource.append("<TerminationTimeHuman>" + this.getTerminationTime().getTime().toString()+ "</TerminationTimeHuman>\n");
resource.append("<LastUpdateMs>" + this.lastUpdateTime.getTimeInMillis()+ "</LastUpdateMs>\n");
resource.append("<LastUpdateHuman>" + this.lastUpdateTime.getTime().toString() + "</LastUpdateHuman>\n");
try {
resource.append(this.getData() + "\n");
} catch (MalformedResourceException e) {
logger.warn("Unable to read the resource data",e);
}
resource.append( "</Document>\n");
return resource.toString();
}
/**
@ -495,4 +543,29 @@ public class AggregatorPersistentResource extends PersistentResource {
public void setPublisher(String publisher) {
}
/**
* Node to String helper
* @param node the source node
* @return the node content serialized as string
* @throws Exception if the serialization fails
*/
private String nodeToString(Node node) throws Exception{
try {
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
StringWriter buffer = new StringWriter();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(node), new StreamResult(buffer));
return buffer.toString();
} catch (TransformerConfigurationException e) {
logger.error("Unable to deserialise content data", e);
throw new Exception("Unable to deserialise content data");
} catch (TransformerException e) {
logger.error("Unable to deserialise content data", e);
throw new Exception("Unable to deserialise content data");
}
}
}

View File

@ -9,9 +9,13 @@ import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.porttypes.GCUBEPortType;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext;
import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.Sweeper;
import org.gcube.informationsystem.collector.stubs.DeleteProfileParams;
import org.gcube.informationsystem.collector.stubs.DocumentNotFoundFaultType;
import org.gcube.informationsystem.collector.stubs.GetProfileCriteria;
import org.gcube.informationsystem.collector.stubs.GetResourceCriteria;
import org.globus.wsrf.utils.FaultHelper;
@ -143,41 +147,31 @@ public class XMLCollectionAccess extends GCUBEPortType {
faultHelper.addDescription("IC service: Exception when deleting the requested resource");
throw fault;
}
}
}
/**
* Disposes the State service
*
* @throws BaseFaultType
* if the shutdown fails
*/
public void dispose() throws BaseFaultType {
/*try {
logger.info("Dispose operation invoked");
logger.info("trying to shutdown the storage instances...");
try {
State.storage_manager.shutdown();
State.query_manager.shutdown();
} catch (NullPointerException se) {
}
State.storage_manager = null;
State.query_manager = null;
// request the interruption of the sweeper thread
State.sweeperT.interrupt();
logger.info("done");
public String getResource(GetResourceCriteria criteria) throws DocumentNotFoundFaultType {
try {
AggregatorPersistentResource aresource = State.getDataManager().retrievePropertyResourceFromID(criteria.getID());
logger.debug("Returning resource:" + aresource.getData());
return aresource.getData();
} catch (Exception e) {
logger.error("unable to pose the IC with success ", e);
BaseFaultType fault = new BaseFaultType();
FaultHelper faultHelper = new FaultHelper(fault);
faultHelper.addFaultCause(e);
faultHelper
.addDescription("-IC service: Unable to pose the service");
throw fault;
} */
logger.warn("Unable to find Resource with ID=" + criteria.getID(), e);
throw new DocumentNotFoundFaultType();
}
}
public String getProfile(GetProfileCriteria criteria) throws DocumentNotFoundFaultType {
try {
AggregatorPersistentResource aresource = State.getDataManager().retrieveProfile(criteria.getID(), criteria.getProfileType());
logger.debug("Returning profile:" + aresource.getData());
return aresource.getData();
} catch (Exception e) {
logger.warn("Unable to find Profile with ID=" + criteria.getID(), e);
throw new DocumentNotFoundFaultType();
}
}
/** {@inheritDoc} */
@Override
protected GCUBEServiceContext getServiceContext() {

View File

@ -391,7 +391,7 @@ public class XMLStorageManager {
* @return
* @throws Exception
*/
public AggregatorPersistentResource retrievePropertyResourceFromID(String resourceID) throws Exception {
synchronized public AggregatorPersistentResource retrievePropertyResourceFromID(String resourceID) throws Exception {
XMLResource res = null;
Collection currentCollection = this.loadPropertiesCollection();
try {
@ -402,16 +402,36 @@ public class XMLStorageManager {
logger.error("Failed to retrieve document " + resourceID);
logger.error("" + edb.errorCode + " " + edb.getMessage(), edb);
throw new Exception();
} finally {
this.resetCollection(currentCollection);
}
return new AggregatorPersistentResource(res);
}
synchronized public AggregatorPersistentResource retrieveProfile(String profileID, String profileType) throws Exception {
XMLResource res = null;
Collection currentCollection = this.loadProfileCollection(profileType);
try {
res = (XMLResource) currentCollection.getResource(profileID);
if (res == null)
logger.warn("Profile " + profileID + " not found!");
} catch (XMLDBException edb) {
logger.error("Failed to retrieve document " + profileID);
logger.error("" + edb.errorCode + " " + edb.getMessage(), edb);
throw new Exception();
} finally {
this.resetCollection(currentCollection);
}
return new AggregatorPersistentResource(res);
}
/**
*
* @param xpathquery
* @return
*/
public AggregatorPersistentResource executeXPathQuery(String xpathquery) {
synchronized public AggregatorPersistentResource executeXPathQuery(String xpathquery) {
AggregatorPersistentResource res = null;
// ArrayList<AggregatorPersistentResource> results = new

View File

@ -0,0 +1,60 @@
package org.gcube.informationsystem.collector.stubs.testsuite.xmlcollectionaccess;
import java.net.URL;
import java.rmi.RemoteException;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBEClientLog;
import org.gcube.informationsystem.collector.stubs.DocumentNotFoundFaultType;
import org.gcube.informationsystem.collector.stubs.GetProfileCriteria;
import org.gcube.informationsystem.collector.stubs.XMLCollectionAccessPortType;
import org.gcube.informationsystem.collector.stubs.service.XMLCollectionAccessServiceLocator;
/**
* Tester for <em>GetProfile</em> operation of the
* <em>gcube/informationsystem/collector/XMLCollectionAccess</em> portType
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class GetProfileTester {
private static GCUBEClientLog logger = new GCUBEClientLog(GetProfileTester.class);
/**
* @param args
*/
public static void main(String[] args) {
if (args.length != 5) {
logger.fatal("Usage: GetProfileTester <host> <port> <Scope> <ID> <profileType>");
return;
}
final String portTypeURI = "http://" + args[0] + ":" + args[1] + "/wsrf/services/gcube/informationsystem/collector/XMLCollectionAccess";
XMLCollectionAccessPortType port = null;
try {
port = new XMLCollectionAccessServiceLocator().getXMLCollectionAccessPortTypePort(new URL(portTypeURI));
port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope(args[2]));
} catch (Exception e) {
logger.error("",e);
}
logger.info("Submitting the request...");
String profile;
try {
GetProfileCriteria criteria = new GetProfileCriteria();
criteria.setID(args[3]);
criteria.setProfileType(args[4]);
profile = port.getProfile(criteria);
logger.info("Retrieved profile: \n" + profile);
} catch (DocumentNotFoundFaultType e) {
logger.error("",e);
} catch (RemoteException e) {
logger.error("",e);
}
}
}

View File

@ -0,0 +1,61 @@
package org.gcube.informationsystem.collector.stubs.testsuite.xmlcollectionaccess;
import java.net.URL;
import java.rmi.RemoteException;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBEClientLog;
import org.gcube.informationsystem.collector.stubs.DocumentNotFoundFaultType;
import org.gcube.informationsystem.collector.stubs.GetResourceCriteria;
import org.gcube.informationsystem.collector.stubs.XMLCollectionAccessPortType;
import org.gcube.informationsystem.collector.stubs.service.XMLCollectionAccessServiceLocator;
/**
* Tester for <em>GetResource</em> operation of the
* <em>gcube/informationsystem/collector/XMLCollectionAccess</em> portType
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class GetResourceTester {
private static GCUBEClientLog logger = new GCUBEClientLog(GetResourceTester.class);
/**
* @param args
*/
public static void main(String[] args) {
if (args.length != 4) {
logger.fatal("Usage: GetResourceTester <host> <port> <Scope> <ID>");
return;
}
final String portTypeURI = "http://" + args[0] + ":" + args[1] + "/wsrf/services/gcube/informationsystem/collector/XMLCollectionAccess";
XMLCollectionAccessPortType port = null;
try {
port = new XMLCollectionAccessServiceLocator().getXMLCollectionAccessPortTypePort(new URL(portTypeURI));
port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope(args[2]));
} catch (Exception e) {
logger.error("",e);
}
logger.info("Submitting the request...");
String resource;
try {
GetResourceCriteria criteria = new GetResourceCriteria();
criteria.setID(args[3]);
resource = port.getResource(criteria);
logger.info("Retrieved resource: \n" + resource);
} catch (DocumentNotFoundFaultType e) {
logger.error("",e);
} catch (RemoteException e) {
logger.error("",e);
}
}
}