Manuele Simi 2009-08-25 01:33:19 +00:00
parent 640d3b8050
commit 7e56114be2
31 changed files with 760 additions and 309 deletions

View File

@ -7,6 +7,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/EXISTLIBS"/>
<classpathentry combineaccessrules="false" kind="src" path="/GCUBE_CORE"/>
<classpathentry combineaccessrules="false" kind="src" path="/GCF.05x"/>
<classpathentry kind="lib" path="/Dependencies/ISIC/org.gcube.informationsystem.collector.stubs.jar"/>
<classpathentry kind="lib" path="/Dependencies/ISCollector/org.gcube.informationsystem.collector.stubs.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,12 +1,13 @@
package = org.gcube.informationsystem.collector
previous-package = org.diligentproject.informationservice.disic
lib.dir = Dependencies/ISIC
lib.dir = Dependencies/ISCollector
wsdl.1 = XMLCollectionAccess
wsdl.2 = Sink_service
wsdl.3 = SinkEntry_service
wsdl.4 = DISICService
wsdl.5 = XQueryAccess
wsdl.6 = XMLStorageAccess
namespace.1=http://gcube-system.org/namespaces/informationsystem/collector
namespace.2=http://gcube-system.org/namespaces/informationsystem/collector/Sink
namespace.3=http://mds.globus.org/index/2004/07/12

View File

@ -134,6 +134,7 @@
</resourceParams>
</resource>
<resourceLink name="groupHome" target="java:comp/env/services/gcube/informationsystem/collector/Sink/home"/>
<resourceLink name="entryHome" target="java:comp/env/services/gcube/informationsystem/collector/SinkEntry/home"/>
<resourceLink name="configuration" target="java:comp/env/configuration"/>
</service>

View File

@ -15,6 +15,15 @@
<wsdlFile>share/schema/org.gcube.informationsystem.collector/XMLCollectionAccess_service.wsdl</wsdlFile>
</service>
<service name="gcube/informationsystem/collector/XMLStorageAccess" provider="Handler" use="literal" style="document">
<parameter name="handlerClass" value="org.globus.axis.providers.RPCProvider"/>
<parameter name="scope" value="Application"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="className" value="org.gcube.informationsystem.collector.impl.porttypes.XMLStorageAccess"/>
<parameter name="loadOnStartup" value="false"/>
<wsdlFile>share/schema/org.gcube.informationsystem.collector/XMLStorageAccess_service.wsdl</wsdlFile>
</service>
<service name="gcube/informationsystem/collector/XQueryAccess" provider="Handler" use="literal" style="document">
<parameter name="handlerClass" value="org.globus.axis.providers.RPCProvider"/>
<parameter name="scope" value="Application"/>

View File

@ -39,12 +39,7 @@
<import namespace="http://mds.globus.org/aggregator/types" schemaLocation="../mds/aggregator/aggregator-types.xsd"/>
<import namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ServiceGroup-1.2-draft-01.xsd" schemaLocation="../wsrf/servicegroup/WS-ServiceGroup.xsd"/>
<xsd:element name="XQuery" type="xsd:string"/>
<xsd:element name="XQueryResponse" type="xsd:string"/>
<xsd:element name="resourceID" type="xsd:string"/>
<xsd:element name="deleteResponse" type="xsd:boolean"/>
@ -69,13 +64,6 @@
M E S S A G E S
============================================================-->
<wsdl:message name="ExecuteXQueryInputMessage">
<part name="parameters" element="tns:XQuery"/>
</wsdl:message>
<wsdl:message name="ExecuteXQueryOutputMessage">
<part name="parameters" element="tns:XQueryResponse"/>
</wsdl:message>
<wsdl:message name="DeleteResourceInputMessage">
<part name="parameters" element="tns:resourceID"/>
@ -104,10 +92,7 @@
============================================================-->
<wsdl:portType name="XMLCollectionAccessPortType">
<wsdl:operation name="ExecuteXQuery">
<wsdl:input message="tns:ExecuteXQueryInputMessage"/>
<wsdl:output message="tns:ExecuteXQueryOutputMessage"/>
</wsdl:operation>
<wsdl:operation name="DeleteResource">
<wsdl:input message="tns:DeleteResourceInputMessage"/>
<wsdl:output message="tns:DeleteResourceOutputMessage"/>

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="XMLStorageAccess" targetNamespace="http://gcube-system.org/namespaces/informationsystem/collector/XMLStorageAccess"
xmlns:tns="http://gcube-system.org/namespaces/informationsystem/collector/XMLStorageAccess"
xmlns:corefaults="http://gcube-system.org/namespaces/common/core/faults"
xmlns:coretypes="http://gcube-system.org/namespaces/common/core/types"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
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:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<wsdl:import namespace="http://gcube-system.org/namespaces/common/core/faults" location="../gcube/common/core/faults/GCUBEFaults.wsdl"/>
<wsdl:types>
<xsd:schema targetNamespace="http://gcube-system.org/namespaces/informationsystem/collector/XMLStorageAccess"
xmlns:tns="http://gcube-system.org/namespaces/informationsystem/collector/XMLStorageAccess"
xmlns:coretypes="http://gcube-system.org/namespaces/common/core/types"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://gcube-system.org/namespaces/common/core/types" schemaLocation="../gcube/common/core/types/GCUBETypes.xsd"/>
<xsd:element name="BackupRequest" type="coretypes:VOID"/>
<xsd:element name="BackupResponse" type="coretypes:VOID"/>
<xsd:element name="XMLStorageUnavailableFaultType">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="corefaults:GCUBEUnrecoverableFault">
<xsd:sequence/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="BackupFailedFaultType">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="corefaults:GCUBERetrySameFault">
<xsd:sequence/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<!--============================================================
M E S S A G E S
============================================================-->
<wsdl:message name="BackupInputMessage">
<part name="parameters" element="tns:BackupRequest"/>
</wsdl:message>
<wsdl:message name="BackupOutputMessage">
<part name="parameters" element="tns:BackupResponse"/>
</wsdl:message>
<wsdl:message name="XMLStorageUnavailableFaultTypeMessage">
<part name="fault" element="tns:XMLStorageUnavailableFaultType"/>
</wsdl:message>
<wsdl:message name="BackupFailedFaultTypeMessage">
<part name="fault" element="tns:BackupFailedFaultType"/>
</wsdl:message>
<!--============================================================
P O R T T Y P E
============================================================-->
<wsdl:portType name="XMLStorageAccessPortType">
<wsdl:operation name="Backup">
<wsdl:input message="tns:BackupInputMessage"/>
<wsdl:output message="tns:BackupOutputMessage"/>
<wsdl:fault name="fault" message="tns:XMLStorageUnavailableFaultTypeMessage"/>
<wsdl:fault name="fault2" message="tns:BackupFailedFaultTypeMessage"/>
</wsdl:operation>
<!--
<wsdl:operation name="Restore">
<wsdl:input message="tns:RestoreInputMessage"/>
<wsdl:output message="tns:RestoreOutputMessage"/>
<wsdl:fault name="fault" message="tns:XMLStorageUnavailableFaultTypeMessage"/>
</wsdl:operation>
<wsdl:operation name="Shutdown">
<wsdl:input message="tns:ShutdownInputMessage"/>
<wsdl:output message="tns:ShutdownOutputMessage"/>
<wsdl:fault name="fault" message="tns:XMLStorageUnavailableFaultTypeMessage"/>
</wsdl:operation>
<wsdl:operation name="Restart">
<wsdl:input message="tns:RestartInputMessage"/>
<wsdl:output message="tns:RestartOutputMessage"/>
<wsdl:fault name="fault" message="tns:XMLStorageUnavailableFaultTypeMessage"/>
</wsdl:operation>
-->
</wsdl:portType>
</wsdl:definitions>

View File

@ -45,7 +45,7 @@
<xsd:element name="XQueryFaultType">
<xsd:complexType name="profileAlreadyRegisteredFault">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="corefaults:GCUBEUnrecoverableFault">
<xsd:sequence/>
@ -71,9 +71,9 @@
<part name="parameters" element="tns:XQueryExecuteResponse"/>
</wsdl:message>
<message name="XQueryFaultTypeMessage">
<wsdl:message name="XQueryFaultTypeMessage">
<part name="fault" element="tns:XQueryFaultType"/>
</message>
</wsdl:message>

View File

@ -2,7 +2,6 @@ package org.gcube.informationsystem.collector.impl.persistence;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
import org.xmldb.api.modules.XMLResource;
import org.xmldb.api.base.XMLDBException;
@ -52,8 +51,7 @@ public class AggregatorPersistentResource extends PersistentResource {
private Calendar terminationTime = null, lastUpdateTime = null;
private static GCUBELog logger = new GCUBELog(
AggregatorPersistentResource.class);
private static GCUBELog logger = new GCUBELog(AggregatorPersistentResource.class);
// the source XMLResource (if any)
private XMLResource originalSource = null;
@ -124,8 +122,7 @@ public class AggregatorPersistentResource extends PersistentResource {
FileInputStream fin = new FileInputStream(f);
this.data = fin.toString();
} catch (IOException ioe) {
System.out.print(State.logPrefix
+ "unable to set content from file " + f.getAbsolutePath());
logger.error("Unable to set content from file " + f.getAbsolutePath());
throw ioe;
}
}
@ -354,21 +351,12 @@ public class AggregatorPersistentResource extends PersistentResource {
Document internalDOM = builder.parse(source);
// gets the type
XPath path = XPathFactory.newInstance().newXPath();
this.profile_type = path
.evaluate(
"/Document/Data/child::*[local-name()='Profile']/Resource/Type",
internalDOM);
// uses the DILIGENT ID as resource ID
this.resourceID = path
.evaluate(
"/Document/Data/child::*[local-name()='Profile']/Resource/ID",
internalDOM);
this.profile_type = path.evaluate("/Document/Data/child::*[local-name()='Profile']/Resource/Type", internalDOM);
// uses the GCUBEResource ID as local resource ID
this.resourceID = path.evaluate("/Document/Data/child::*[local-name()='Profile']/Resource/ID", internalDOM);
} catch (Exception e) {
logger
.error(State.logPrefix
+ "Unable to extract the profile type from the resource "
+ e.getMessage());
logger.error("Unable to extract the profile type from the resource " + e.getMessage());
}
}
@ -424,8 +412,8 @@ public class AggregatorPersistentResource extends PersistentResource {
try {
value = path.evaluate("Document/LastUpdateMs", this.internalDOM);
} catch (XPathExpressionException xpee) {
logger.error(State.logPrefix + "" + xpee.getMessage());
logger.error(State.logPrefix + "" + xpee.getStackTrace());
logger.error("" + xpee.getMessage());
logger.error("" + xpee.getStackTrace());
throw new Exception("XPath evaluation error");
}
try {

View File

@ -57,7 +57,7 @@ public class OldService extends GCUBEPortType {
logger.debug("executing XQuery: " + xquery);
XQuery q = new XQuery(xquery);
ResourceSet result = State.query_manager.executeXQuery(q);
ResourceSet result = State.getQueryManager().executeXQuery(q);
logger.debug("number of returned documents: " + result.getSize());
response.append("<Resultset>\n");
for (int i = 0; i < (int) result.getSize(); i++) {
@ -115,7 +115,7 @@ public class OldService extends GCUBEPortType {
try {
logger.debug("deleting profile " + id + " from collection " + type);
State.storage_manager.retrieveAndDeleteProfileFromID(id, type);
State.getDataManager().retrieveAndDeleteProfileFromID(id, type);
if (type.equalsIgnoreCase("RunningInstance"))
Sweeper.cleanResourceForRI(id);
@ -155,7 +155,7 @@ public class OldService extends GCUBEPortType {
try {
logger.debug("deleting resource: " + id);
State.storage_manager.retrieveAndDeleteResourceFromID(id);
State.getDataManager().retrieveAndDeleteResourceFromID(id);
} catch (Exception e) {
logger.error("unable to remove resource: " + id, e);
BaseFaultType fault = new BaseFaultType();
@ -200,12 +200,10 @@ public class OldService extends GCUBEPortType {
logger.info("Dispose operation invoked");
logger.info("trying to shutdown the storage instances...");
try {
State.storage_manager.shutdown();
State.query_manager.shutdown();
State.getDataManager().shutdown();
State.getQueryManager().shutdown();
} catch (NullPointerException se) {/* nothng to do */
}
State.storage_manager = null;
State.query_manager = null;
}
// request the interruption of the sweeper thread
State.sweeperT.interrupt();
logger.info("done");

View File

@ -11,14 +11,10 @@ import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.Sweeper;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XQuery;
import org.gcube.informationsystem.collector.stubs.DeleteProfileParams;
import org.globus.wsrf.utils.FaultHelper;
import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.modules.XMLResource;
/**
* State service implementation class
*
@ -36,48 +32,6 @@ public class XMLCollectionAccess extends GCUBEPortType {
private final GCUBELog logger = new GCUBELog(XMLCollectionAccess.class);
/**
* Executes the given XQuery on the embedded eXist DB instance
*
* @param xquery
* - a valid XQuery. It must be compliant with the syntax (with
* the exception of XML Schema-related features) as specified in
* W3C's recommendations outlined in the June 2006 candidate
* recommendation
* @return the result set wrapped in a &lt;Resultset&gt; tag. Each record is
* wrapped with a &lt;Recordt&gt;
* @throws BaseFaultType
* if the XQuery is not valid or the connection to eXist is
* broken
*/
public String executeXQuery(String xquery) throws BaseFaultType {
StringBuilder response = new StringBuilder();
try {
logger.debug("executing XQuery: " + xquery);
XQuery q = new XQuery(xquery);
ResourceSet result = State.query_manager.executeXQuery(q);
logger.debug("number of returned documents: " + result.getSize());
response.append("<Resultset>\n");
for (int i = 0; i < (int) result.getSize(); i++) {
XMLResource xmlres = (XMLResource) result.getResource((long) i);
// logger.debug("retrieved resource - " + xmlres.getContent());
response.append("<Record>\n" + xmlres.getContent()+ "\n</Record>\n");
}
response.append("</Resultset>");
} catch (Exception e) {
BaseFaultType fault = new BaseFaultType();
FaultHelper faultHelper = new FaultHelper(fault);
faultHelper.addFaultCause(e);
faultHelper.addDescription("IC service: Exception when executing the requested XQuery");
throw fault;
}
return response.toString();
}
/**
* Removes a profile from the Storage given its DILIGENT Resource ID
*
@ -117,7 +71,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
try {
logger.debug("deleting profile " + id + " from collection " + type);
State.storage_manager.retrieveAndDeleteProfileFromID(id, type);
State.getDataManager().retrieveAndDeleteProfileFromID(id, type);
if (type.equalsIgnoreCase("RunningInstance"))
Sweeper.cleanResourceForRI(id);
@ -157,7 +111,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
try {
logger.debug("deleting resource: " + id);
State.storage_manager.retrieveAndDeleteResourceFromID(id);
State.getDataManager().retrieveAndDeleteResourceFromID(id);
} catch (Exception e) {
logger.error("unable to remove resource: " + id, e);
BaseFaultType fault = new BaseFaultType();
@ -198,13 +152,13 @@ public class XMLCollectionAccess extends GCUBEPortType {
* if the shutdown fails
*/
public void dispose() throws BaseFaultType {
try {
/*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) {/* nothng to do */
} catch (NullPointerException se) {
}
State.storage_manager = null;
State.query_manager = null;
@ -219,7 +173,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
faultHelper
.addDescription("-IC service: Unable to pose the service");
throw fault;
}
} */
}
/**

View File

@ -1,10 +1,13 @@
package org.gcube.informationsystem.collector.impl.porttypes;
import org.globus.wsrf.utils.FaultHelper;
import org.oasis.wsrf.faults.BaseFaultType;
import org.xmldb.api.base.XMLDBException;
import org.gcube.informationsystem.collector.stubs.BackupFailedFaultType;
import org.gcube.informationsystem.collector.stubs.XMLStorageUnavailableFaultType;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.porttypes.GCUBEPortType;
import org.gcube.common.core.types.VOID;
import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
@ -23,19 +26,41 @@ public class XMLStorageAccess extends GCUBEPortType {
return ICServiceContext.getContext();
}
/**
* Backups the current content of the XMLStorage
* @throws BackupFailedFaultType if the backup fails
* @throws XMLStorageUnavailableFaultType if the XMLStorage is not available (may be corrupted)
*/
public VOID backup(VOID params) throws BackupFailedFaultType, XMLStorageUnavailableFaultType {
try {
State.getDataManager().backup();
} catch (XMLDBException e) {
logger.error("Failed to backup", e);
throw new XMLStorageUnavailableFaultType();
} catch (Exception e) {
logger.error("Failed to backup", e);
BackupFailedFaultType fault = new BackupFailedFaultType();
fault.addFaultDetailString("");
throw fault;
}
return new VOID();
}
/**
* Disposes the XMLStorage
*
* @throws BaseFaultType if the shutdown fails
*/
public void dispose() throws BaseFaultType {
try {
/*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) {/* nothng to do */
} catch (NullPointerException se) {
}
State.storage_manager = null;
State.query_manager = null;
@ -50,6 +75,6 @@ public class XMLStorageAccess extends GCUBEPortType {
faultHelper
.addDescription("-IC service: Unable to pose the service");
throw fault;
}
} */
}
}

View File

@ -1,6 +1,5 @@
package org.gcube.informationsystem.collector.impl.porttypes;
import org.globus.wsrf.utils.FaultHelper;
import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.modules.XMLResource;
@ -32,36 +31,50 @@ public class XQueryAccess extends GCUBEPortType {
/**
* Executes a XQuery expression in the XML storage
* @param XQueryExpression the XQuery expression
*
* @param XQueryExpression
* the XQuery expression
* @return a formatted XML document
* @throws XQueryFaultType if the execution fails
* @throws XQueryFaultType
* if the execution fails
*/
public XQueryExecuteResponse XQueryExecute(XQueryExecuteRequest request) throws XQueryFaultType {
StringBuilder dataset = new StringBuilder();
public XQueryExecuteResponse XQueryExecute(final XQueryExecuteRequest request) throws XQueryFaultType {
XQueryExecuteResponse response = new XQueryExecuteResponse();
try {
logger.debug("executing XQuery: " + request.getXQueryExpression());
XQuery q = new XQuery(request.getXQueryExpression());
ResourceSet result = State.query_manager.executeXQuery(q);
ResourceSet result = State.getQueryManager().executeXQuery(q);
response.setSize(result.getSize());
logger.debug("number of returned documents: " + result.getSize());
dataset.append("<Resultset>\n");
for (int i = 0; i < (int) result.getSize(); i++) {
XMLResource xmlres = (XMLResource) result.getResource((long) i);
dataset.append("<Record>\n" + xmlres.getContent() + "\n</Record>\n");
}
dataset.append("</Resultset>");
response.setDataset(dataset.toString());
response.setDataset(buildDataSet(result));
} catch (Exception e) {
XQueryFaultType fault = new XQueryFaultType();
FaultHelper faultHelper = new FaultHelper(fault);
faultHelper.addFaultCause(e);
faultHelper.addDescription("IC service: Exception when executing the requested XQuery");
fault.addFaultDetailString("Exception when executing the requested XQuery");
throw fault;
}
return response;
}
/**
* Builds the output dataset for XQueryExecute operation
* @param result the query results
* @return the dataset to return
* @throws XMLDBException
*/
private String buildDataSet(final ResourceSet result) throws Exception {
final String rootElement = "Resultset";
final String recordElement = "Record";
StringBuilder dataset = new StringBuilder();
dataset.append("<" + rootElement + ">\n");
for (int i = 0; i < (int) result.getSize(); i++) {
XMLResource xmlres = (XMLResource) result.getResource((long) i);
dataset.append("<"+recordElement+">\n" + xmlres.getContent() + "\n</"+recordElement+"\n");
}
dataset.append("</"+rootElement+">");
return dataset.toString();
}
}

View File

@ -86,7 +86,7 @@ public class AggregatorRegisteredResource extends AggregatorServiceGroupResource
this.loadCompatibleSources(this);
} catch (Exception e) {
logger.error(State.logPrefix + "Error during DISICResource creation: ", e);
logger.error("Error during DISICResource creation: ", e);
}
}
@ -121,8 +121,7 @@ public class AggregatorRegisteredResource extends AggregatorServiceGroupResource
* @param time the new termination time
*/
public void setTerminationTime(Calendar time) {
logger.debug(State.logPrefix + "Set Termination time called: " + time.getTime());
logger.debug("Set Termination time called: " + time.getTime());
this.terminationTime = time;
}
@ -249,7 +248,7 @@ public class AggregatorRegisteredResource extends AggregatorServiceGroupResource
logger.trace("Resource: " + res.toString());
// store/update the new resource
State.storage_manager.storeResource(res);
State.getDataManager().storeResource(res);
aentry.dispose();
logger.info("Delivered resource stored with success");
} catch (Exception e) {

View File

@ -52,9 +52,9 @@ public class ICAggregatorRemoveCallback implements AggregatorServiceGroupEntryRe
// delete the resource from the database
try {
State.storage_manager.retrieveAndDeleteResourceFromID(res.getID());
State.getDataManager().retrieveAndDeleteResourceFromID(res.getID());
} catch (Exception e) {
logger.error(State.logPrefix + "unable to remove resource: " + res.getID(), e);
logger.error("Unable to remove resource: " + res.getID(), e);
}
}

View File

@ -0,0 +1,36 @@
package org.gcube.informationsystem.collector.impl.xmlstorage.backup;
import java.io.File;
import java.io.IOException;
/**
* An abstract representation of a folder
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class BackupFolder extends File {
private static final long serialVersionUID = 4774672121228681814L;
/**
* @param pathname
* @throws IOException
*/
public BackupFolder(String pathname) throws IOException {
super(pathname);
if (! this.isDirectory())
throw new IOException();
if (! this.isValid())
throw new IOException();
}
/**
* Validates the backup folder
* @return true if this is a valid backup folder
*/
//gives a chance to subclasses to perform custom validation
protected boolean isValid() { return true;}
}

View File

@ -0,0 +1,86 @@
package org.gcube.informationsystem.collector.impl.xmlstorage.backup;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Calendar;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext;
/**
* An abstract representation of the backups root folder
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class BackupsRootFolder {
private static final long serialVersionUID = 6054398926161291140L;
private final static String backupsRoot = ICServiceContext.getContext().getPersistenceRoot().getAbsolutePath() + File.separator + "backups" + File.separator;
private static GCUBELog logger = new GCUBELog(BackupsRootFolder.class);
/**
* Creates a new backup folder
*
* @return the new backup Folder
* @throws IOException if the creation fails
*/
public static BackupFolder createBackupFolder() throws IOException {
final String backupFolder = backupsRoot + File.separator + buildBackupFolderName();
File backup = new File(backupFolder);
if (!backup.mkdirs())
throw new IOException("Unable to create the backup folder");
return new BackupFolder(backup.getAbsolutePath());
}
@SuppressWarnings("unchecked")
public <T extends BackupFolder> T getLastBackup(Class<T> backupType) throws IOException {
File rootFolder = new File(backupsRoot);
if (!rootFolder.exists())
throw new IOException("Unable to read the backup folder");
//look for the most recent backup
File[] files = rootFolder.listFiles();
long lastModified = 0;
T lastBackup = null;
for (File file : files) {
if (file.lastModified() >= lastModified) {
try {
Class<T> clazz = (Class<T>) Class.forName(backupType.getSimpleName());
Constructor<T> constructor = clazz.getConstructor(new Class[] {String.class});
lastBackup = constructor.newInstance(file.getAbsolutePath());
}catch (Exception e) {
logger.warn("invalid backup folder ("+ file.getAbsolutePath() +"): " + e.getMessage());
}
}
}
if (lastBackup == null)
throw new IOException("Unable to find a valid backup folder");
logger.debug("last backup found in " + lastBackup.getAbsolutePath());
return lastBackup;
}
private static String buildBackupFolderName() {
Calendar date = Calendar.getInstance();
StringBuilder name = new StringBuilder();
name.append(date.get(Calendar.DAY_OF_MONTH));
name.append("-");
name.append(Calendar.getInstance().get(Calendar.MONTH) + 1 );
name.append("-");
name.append(Calendar.getInstance().get(Calendar.YEAR));
name.append("-");
name.append(System.currentTimeMillis());
return name.toString();
}
}

View File

@ -0,0 +1,39 @@
package org.gcube.informationsystem.collector.impl.xmlstorage.backup;
import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler;
/**
* Scheduler for periodic XMLStorage backups
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public abstract class Scheduler extends GCUBEScheduledHandler {
/**
* @param interval
* @param mode
* @param handler
*/
public Scheduler(Configuration configuration) {
super(configuration.getInterval(), Mode.EAGER);
}
public class Configuration {
long interval;
/**
* @return the interval
*/
public long getInterval() {
return interval;
}
/**
* @param interval the interval to set
*/
public void setInterval(long interval) {
this.interval = interval;
}
}
}

View File

@ -0,0 +1,97 @@
package org.gcube.informationsystem.collector.impl.xmlstorage.exist;
import java.io.IOException;
import java.util.Properties;
import javax.xml.parsers.ParserConfigurationException;
import org.exist.backup.Restore;
import org.exist.storage.BrokerPool;
import org.exist.storage.ConsistencyCheckTask;
import org.xml.sax.SAXException;
import org.xmldb.api.base.XMLDBException;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.xmlstorage.backup.BackupsRootFolder;
/**
* Data Manager
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class DataManager extends XMLStorageManager {
private static GCUBELog logger = new GCUBELog(DataManager.class);
/**
* Backups the current content of the XMLStorage
* @throws Exception
*/
public void backup() throws IOException, Exception {
//run the eXist's ConsistencyCheckTask
//info: http://www.exist-db.org/backup.html
//source: http://exist.svn.sourceforge.net/viewvc/exist/branches/eXist-stable-1.2/src/org/exist/backup/ExportMain.java?revision=8695&view=markup
logger.info("backup requested");
ConsistencyCheckTask check = new ConsistencyCheckTask();
Properties props = new Properties();
props.setProperty("output", BackupsRootFolder.createBackupFolder().getAbsolutePath()); //The directory to which the backup is written
props.setProperty("backup", "yes"); //Create a database backup in addition to running the system checks
props.setProperty("incremental", "no"); //Create a full backup
check.configure(null, props); //configuration is null, since we pass an absolute path as backup folder
check.execute(BrokerPool.getInstance().get(org.exist.security.SecurityManager.SYSTEM_USER));
//alternative backup way
/*Backup backup = new Backup("admin", "admin", BackupsRootFolder.createBackupFolder().getAbsolutePath(), XmldbURI.create(URI + DBBroker.ROOT_COLLECTION));
try {
backup.backup(false, null);
} catch (XMLDBException e) {
throw new Exception("Unable to backup");
} catch (IOException e) {
throw new Exception("Unable to backup");
} catch (SAXException e) {
throw new Exception("Unable to backup");
} */
}
/**
* Restore from the latest backup
* @throws IOException
* @throws XMLDBException
* @throws SAXException
* @throws ParserConfigurationException
* @throws Exception
*/
public void restore() throws IOException {
ExistBackupFolder lastBackup = this.getLastBackup();
Restore restore = null;
try {
restore = new Restore("admin", "admin","admin", lastBackup, URI);
} catch (ParserConfigurationException e) {
logger.error(e);
} catch (SAXException e1) {
logger.error(e1);
} catch (XMLDBException e1) {
logger.error("XMLStorage exception", e1);
} catch (Exception e1) {
logger.error(e1);
}
try {
restore.restore(false, null);
} catch (XMLDBException e) {
logger.error(e);
} catch (SAXException e) {
logger.error(e);
}
}
private ExistBackupFolder getLastBackup() throws IOException {
return new BackupsRootFolder().getLastBackup(ExistBackupFolder.class);
}
}

View File

@ -0,0 +1,31 @@
package org.gcube.informationsystem.collector.impl.xmlstorage.exist;
import java.io.IOException;
import org.gcube.informationsystem.collector.impl.xmlstorage.backup.BackupFolder;
/**
* An abstract representation of an eXist backup folder
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class ExistBackupFolder extends BackupFolder {
private static final long serialVersionUID = -6676338091088430159L;
/** {@inheritDoc} */
public ExistBackupFolder(String pathname) throws IOException {
super(pathname);
}
/** {@inheritDoc} */
@Override
protected boolean isValid() {
//TODO: should check the existence of "db/__contents__.xml"
return true;
}
}

View File

@ -0,0 +1,21 @@
package org.gcube.informationsystem.collector.impl.xmlstorage.exist;
import org.gcube.informationsystem.collector.impl.xmlstorage.backup.Scheduler;
/**
* Exist Scheduler for periodic backups
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class ExistScheduler extends Scheduler {
/**
* @param configuration
*/
public ExistScheduler(Configuration configuration) {
super(configuration);
}
}

View File

@ -0,0 +1,11 @@
package org.gcube.informationsystem.collector.impl.xmlstorage.exist;
/**
* Query Manager
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class QueryManager extends XMLStorageManager {
}

View File

@ -12,9 +12,9 @@ import java.util.List;
import java.util.Collections;
/**
* This class groups the data globally scoped in an active RI
* The global state of an IC instance
*
* @author manuele simi
* @author Manuele Simi (ISTI-CNR)
*
*/
public class State {
@ -22,22 +22,12 @@ public class State {
/**
* Connection to eXist used to store data
*/
public static XMLStorageManager storage_manager;
private static DataManager storageManager;
/**
* Connection to eXist used to query the database
*/
public static XMLStorageManager query_manager;
/**
* DIS-IC's JNDI resource name as declared in the JNDI file
*/
public static final String JNDIResourceName = "DISICConfiguration";
/**
* Prefix to prepend to any log message
*/
public static final String logPrefix = "";
private static QueryManager queryManager;
/**
* Thread that periodically sweeps the database from expired resources
@ -62,12 +52,12 @@ public class State {
*/
public static void initialize() throws Exception {
logger.info("starting IC service initialization...");
State.initializeStorageManager();
State.initializeDataManager();
State.initializeQueryManager();
if (Boolean.valueOf((String) ICServiceContext.getContext().getProperty("deleteRPsOnStartup", true))) {
// cleanup the RPs collection
logger.info("deleting all RPs...");
State.storage_manager.deleteAllProperties();
State.storageManager.deleteAllProperties();
} else {
logger.info("all RPs previously stored are keept in the storage");
}
@ -81,16 +71,16 @@ public class State {
logger.info("IC service initialization completed");
}
private static void initializeStorageManager() throws Exception {
private static void initializeDataManager() throws Exception {
// open the connection used to store resources
State.storage_manager = new XMLStorageManager();
storage_manager.initialize();
State.storageManager = new DataManager();
storageManager.initialize();
}
private static void initializeQueryManager() throws Exception {
// open the connection used to query stored resources
State.query_manager = new XMLStorageManager();
query_manager.initialize();
State.queryManager = new QueryManager();
queryManager.initialize();
}
/**
@ -108,10 +98,25 @@ public class State {
*/
public static void dispose() throws Exception {
logger.info("Disposing IC service's resources...");
State.storage_manager.shutdown();
State.query_manager.shutdown();
State.storageManager.shutdown();
State.queryManager.shutdown();
}
/**
* @return the storageManager
*/
public static DataManager getDataManager() {
return storageManager;
}
/**
* @return the queryManager
*/
public static QueryManager getQueryManager() {
return queryManager;
}
/**
* Prints the enviromnet variables
*/

View File

@ -10,9 +10,7 @@ import java.util.TimeZone;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.persistence.PersistentResource;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.Sweeper;
@ -32,7 +30,7 @@ public class Sweeper implements Runnable {
private static long resourceExpirationTime = 1800000; // default value
private static Log logger = LogFactory.getLog(Sweeper.class.getName());
private static GCUBELog logger = new GCUBELog(Sweeper.class.getName());
private static XMLStorageManager storage = null;
@ -86,22 +84,15 @@ public class Sweeper implements Runnable {
.retrievePropertyResourceFromID(id);
if (now.getTimeInMillis() - res.getLastUpdateTimeinMills() > Sweeper.resourceExpirationTime)
// removes the resources from the database
State.storage_manager
.retrieveAndDeleteResourceFromID(id);
State.getDataManager().retrieveAndDeleteResourceFromID(id);
// break;
} catch (Exception e) {
logger.debug(State.logPrefix
+ "DIS-IC sweeper - the resource " + id
+ " is no longer available in the storage");
logger.debug("IC sweeper - the resource " + id + " is no longer available in the storage");
}
}
} catch (Exception e2) {
logger
.warn(
State.logPrefix
+ "DIS-IC sweeper - an exception was rised when trying to cleanup the storage ",
e2);
logger.warn("IC sweeper - an exception was rised when trying to cleanup the storage ", e2);
}
}
@ -123,7 +114,7 @@ public class Sweeper implements Runnable {
*/
public static void cleanRPs() {
// cleanup the RPs collection
State.storage_manager.deleteAllProperties();
State.getDataManager().deleteAllProperties();
}
/**
@ -143,7 +134,7 @@ public class Sweeper implements Runnable {
toRemove.add(res);
}
} catch (Exception e) {
logger.error(State.logPrefix, e);
logger.error("Failed to clean up the resources", e);
}
}// end loop on deletedResources
synchronized (State.deletedResources) {

View File

@ -89,7 +89,7 @@ public class XMLStorageManager {
Class<?> cl = Class.forName(driver);
this.database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(this.database);
DatabaseManager.registerDatabase(this.database);
// try to load the collections for props and profiles
logger.debug("Initializing the root collection");
@ -390,7 +390,7 @@ public class XMLStorageManager {
while ((retry) && (attempts < max_attempts)) {
try {
// wait until the DB is unlocked
while (State.storage_manager.isLocked())
while (State.getDataManager().isLocked())
Thread.sleep(1000);
// execute query and get results in ResourceSet
if (currentCollection == null)

View File

@ -13,36 +13,20 @@ import org.xmldb.api.base.Collection;
import org.xmldb.api.base.CompiledExpression;
import org.xmldb.api.base.ResourceSet;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XQuery;
import org.globus.wsrf.config.ContainerConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Reads an XQuery file or string and executes it.
* XQuery to be executed
*
*/
public class XQuery {
private String query_string = null;
private static Log logger = LogFactory.getLog(XQuery.class.getName());
private static GCUBELog logger = new GCUBELog(XQuery.class.getName());
//testsuite constructor: TO REMOVE
public XQuery() throws IOException {
try {
this.query_string = this.getStaticQuery();
} catch (Exception e) {
logger.error(State.logPrefix + "Unable to read the XQuery file");
throw new IOException("Unable to read the XQuery file "
+ e.getStackTrace()[0].toString());
}
}
public XQuery(String xquery) {
this.query_string = xquery;
@ -52,7 +36,7 @@ public class XQuery {
try {
this.query_string = this.readFile(file);
} catch (IOException ioe) {
logger.error(State.logPrefix + "Unable to read the XQuery file");
logger.error("Unable to read the XQuery file");
throw new IOException("Unable to read the XQuery file "
+ ioe.getStackTrace()[0].toString());
}
@ -72,7 +56,7 @@ public class XQuery {
*/
public ResourceSet execute(Collection col) throws Exception {
logger.info(State.logPrefix + "executing query on collection " + col.getName());
logger.info("Executing query on collection " + col.getName());
XQueryService service = (XQueryService) col.getService("XQueryService", "1.0");
@ -97,8 +81,8 @@ public class XQuery {
SerializerPool.getInstance().returnObject(serializer); */
//long rtime = System.currentTimeMillis() - start;
logger.info(State.logPrefix + "hits: " + result.getSize());
logger.info(State.logPrefix + "query time: " + qtime + "ms");
logger.trace("hits: " + result.getSize());
logger.trace("query time: " + qtime + "ms");
//logger.info(State.logPrefix + "retrieve time: " + rtime);
return result;
@ -116,14 +100,6 @@ public class XQuery {
f.close();
return xml.toString();
}
/**
* Retrives the query from a local file
*
* @return the query
*/
private String getStaticQuery() throws Exception {
String file = ContainerConfig.getBaseDirectory() + "/etc/org_diligentproject_informationservice_disic/query-example.xq";
return this.readFile(new FileReader(file));
}
}

View File

@ -0,0 +1,66 @@
package org.gcube.informationsystem.collector.testsuite;
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.types.VOID;
import org.gcube.common.core.utils.logging.GCUBEClientLog;
import org.gcube.informationsystem.collector.stubs.BackupFailedFaultType;
import org.gcube.informationsystem.collector.stubs.XMLStorageAccessPortType;
import org.gcube.informationsystem.collector.stubs.XMLStorageUnavailableFaultType;
import org.gcube.informationsystem.collector.stubs.service.XMLStorageAccessServiceLocator;
/**
* Tester for <em>Backup</em> operation of the
* <em>gcube/informationsystem/collector/XMLStorageAccess</em> portType
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class BackupTester {
private static GCUBEClientLog logger = new GCUBEClientLog(BackupTester.class);
/**
* @param args
* <ol>
* <li> IC host
* <li> IC port
* <li> Caller Scope
* </ol>
*/
public static void main(String[] args) {
/*if (args.length != 3) {
logger.fatal("Usage: BackupTester <host> <port> <Scope>");
return;
}*/
//final String portTypeURI = "http://" + args[0] + ":" + args[1] + "/wsrf/services/gcube/informationsystem/collector/XMLStorageAccess";
String portTypeURI = "http://node10.d.d4science.research-infrastructures.eu:8080/wsrf/services/gcube/informationsystem/collector/XMLStorageAccess";
XMLStorageAccessPortType port = null;
try {
port = new XMLStorageAccessServiceLocator().getXMLStorageAccessPortTypePort(new URL(portTypeURI));
port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope("/CNRPrivate"));
} catch (Exception e) {
e.printStackTrace();
}
logger.info("Submitting backup request...");
try {
port.backup(new VOID());
} catch (XMLStorageUnavailableFaultType e) {
logger.error("",e);
} catch (BackupFailedFaultType e) {
logger.error("",e);
} catch (RemoteException e) {
logger.error("",e);
}
}
}

View File

@ -1,105 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.collector.testsuite;
import java.net.URL;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import org.gcube.informationsystem.collector.stubs.DeleteProfileParams;
import org.gcube.informationsystem.collector.stubs.XMLCollectionAccessPortType;
import org.gcube.informationsystem.collector.stubs.holders.VoidTypeHolder;
import org.gcube.informationsystem.collector.stubs.service.XMLCollectionAccessServiceAddressingLocator;
/**
*
* DIS-IC client testsuite class
* <ol>
* <li> <b>to compile</b>: javac -classpath MYPATH/org_diligentproject_informationservice_disic_stubs.jar:$CLASSPATH testsuite/Client.java
*
* <li> <b>to run</b> (make sure that the DIS-IC stub classes are in your CLASSPATH):
* </ol>
* <ul>
* <li> DELETE ALL RPs: java -classpath MYPATH//org_diligentproject_informationservice_disic_stubs.jar:$CLASSPATH testsuite/Client deleteAllRPs http://MYHOST:MYPORT/wsrf/services/diligentproject/informationservice/disic/DISICService
*
* <li> DELETE A PROFILE: java -classpath MYPATH//org_diligentproject_informationservice_disic_stubs.jar:$CLASSPATH testsuite/Client deleteprofile http://MYHOST:MYPORT/wsrf/services/diligentproject/informationservice/disic/DISICService <PROFILE ID> <PROFILE TYPE>
* (allowed type are: "DHN", "RI", "SERVICE", "CS", "CSInstance", "Collection", "gLiteResource"
* <li> DELETE A RESOURCE: java -classpath MYPATH//lib/org_diligentproject_informationservice_disic_stubs.jar:$CLASSPATH testsuite/Client delete http://MYHOST:MYPORT/wsrf/services/diligentproject/informationservice/disic/DISICService <RESOURCE_ID>
*
* <li> SEND A QUERY: java -classpath ./build/lib/org_diligentproject_informationservice_disic_stubs.jar:$CLASSPATH testsuite/Client query http://MYHOST:MYPORT/wsrf/services/diligentproject/informationservice/disic/DISICService <xquery-file>
* </ul>
*
* @author manuele simi
*
* @version 1.0 July 2006
*
* @link http://www.diligentproject.com
*/
public class Client {
public Client() {
}
/**
*
* @param file the file that contains the query
* @return a String with the file content
* @throws IOException
*/
protected static String readFile(String file) throws IOException {
BufferedReader f = new BufferedReader(new FileReader(file));
String line;
StringBuffer xml = new StringBuffer();
while ((line = f.readLine()) != null)
xml.append(line + " ");
f.close();
return xml.toString();
}
/**
* @param args
* 0 - the URI of an active DIS-IC service 1 - the file that
* contains the query to execute
*/
public static void main(String[] args) {
XMLCollectionAccessServiceAddressingLocator locator = new XMLCollectionAccessServiceAddressingLocator();
String uri = args[1];
try {
URL dis_ic_url = new URL(uri);
XMLCollectionAccessPortType ic = locator.getXMLCollectionAccessPortTypePort(dis_ic_url);
if (args[0].equalsIgnoreCase("delete")) {
ic.deleteResource(args[2]);
}
if (args[0].equalsIgnoreCase("deleteAllRPs")) {
ic.deleteAllRPs(new VoidTypeHolder());
}
if (args[0].equalsIgnoreCase("deleteprofile")) {
DeleteProfileParams prof = new DeleteProfileParams();
prof.setID(args[2]);
prof.setProfileType(args[3]);
ic.deleteProfile(prof);
}
if (args[0].equalsIgnoreCase("query")) {
String query = Client.readFile(args[2]);
String resp = ic.executeXQuery(query);
System.out.println(resp);
}
if (args[0].equalsIgnoreCase("dispose")) {
ic.dispose(new VoidTypeHolder());
}
if (args[0].equalsIgnoreCase("initialize")) {
ic.initialize(new VoidTypeHolder());
}
} catch (Exception e) {
e.printStackTrace();
}
}// end main
}

View File

@ -1,5 +1,5 @@
<ServiceMap>
<Service name ="ISICAllQueryPT" endpoint ="http://node10.d.d4science.research-infrastructures.eu:8080/wsrf/services/gcube/informationsystem/collector/XMLCollectionAccess"/>
<Service name ="ISICAllQueryPT" endpoint ="http://node10.d.d4science.research-infrastructures.eu:8080/wsrf/services/gcube/informationsystem/collector/XQueryAccess"/>
<Service name ="ISICAllRegistrationPT" endpoint ="http://node10.d.d4science.research-infrastructures.eu:8080/wsrf/services/gcube/informationsystem/collector/Sink"/>
<!-- <Service name ="ISRegistry" endpoint="http://node6.d.d4science.research-infrastructures.eu:8080/wsrf/services/gcube/informationsystem/registry/RegistryFactory" /> -->
</ServiceMap>

View File

@ -0,0 +1,19 @@
package org.gcube.informationsystem.collector.testsuite;
/**
* TODO: Manuele, don't forget to add a comment for this new type!!
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class ShutdownTester {
/**
* @param args
*/
public static void main(String[] args) {
}
}

View File

@ -0,0 +1,91 @@
package org.gcube.informationsystem.collector.testsuite;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
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.XQueryAccessPortType;
import org.gcube.informationsystem.collector.stubs.XQueryExecuteRequest;
import org.gcube.informationsystem.collector.stubs.XQueryExecuteResponse;
import org.gcube.informationsystem.collector.stubs.XQueryFaultType;
import org.gcube.informationsystem.collector.stubs.service.XQueryAccessServiceLocator;
/**
* Tester for <em>XQueryExecute</em> operation of the <em>gcube/informationsystem/collector/XQueryAccess</em> portType
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class XQueryExecuteTester {
private static GCUBEClientLog logger = new GCUBEClientLog(XQueryExecuteTester.class);
/**
* @param args
* <ol>
* <li> IC host
* <li> IC port
* <li> Caller Scope
* <li> File including the XQuery to submit
* </ol>
*/
public static void main(String[] args) {
if (args.length != 4) {
logger.fatal("Usage: XQueryExecuteTester <host> <port> <Scope> <XQueryExpressionFile>" );
return;
}
String portTypeURI = "http://"+args[0]+":"+ args[1]+"/wsrf/services/gcube/informationsystem/collector/XQueryAccess";
XQueryAccessPortType port = null;
try {
port = new XQueryAccessServiceLocator().getXQueryAccessPortTypePort(new URL(portTypeURI));
port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope(args[2]));
} catch (Exception e) {
e.printStackTrace();
}
XQueryExecuteRequest request = new XQueryExecuteRequest();
request.setXQueryExpression(readQuery(args[3]));
try {
logger.info("Submitting query in scope " + GCUBEScope.getScope(args[2]).getName() + "....");
XQueryExecuteResponse response = port.XQueryExecute(request);
logger.info("Number of returned records: " + response.getSize());
logger.info("Dataset: \n" + response.getDataset());
} catch (XQueryFaultType e) {
logger.error("XQuery Fault Error received", e);
} catch (RemoteException e) {
logger.error(e);
}
}
private static String readQuery(final String filename) {
String queryString = null;
try {
BufferedReader input = new BufferedReader(new FileReader(filename));
StringBuilder contents = new StringBuilder();
String line;
while (( line = input.readLine()) != null){
contents.append(line);
contents.append(System.getProperty("line.separator"));
}
input.close();
queryString = contents.toString();
} catch (FileNotFoundException e1) {
logger.fatal("invalid file: " + filename);
} catch (IOException e) {
logger.fatal("an error occurred when reading " + filename);
}
return queryString;
}
}

View File

@ -1,3 +1,7 @@
xquery version "1.0";
for $doc in collection("/db/Properties")//Document return $doc
declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';
declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider';
for $result in collection("/db/Profiles/RunningInstance")//Document/Data/is:Profile/Resource
where ($result/Profile/DeploymentData/Status/string() eq "ready") and ($result//ServiceName/string() eq "IS-Registry")
and ($result//ServiceClass/string() eq "InformationSystem")
return $result