diff --git a/.classpath b/.classpath
index d5e94bc..0eb9cab 100644
--- a/.classpath
+++ b/.classpath
@@ -7,6 +7,6 @@
-
+
diff --git a/etc/build.properties b/etc/build.properties
index cdf2eef..2eac27c 100755
--- a/etc/build.properties
+++ b/etc/build.properties
@@ -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
diff --git a/etc/deploy-jndi-config.xml b/etc/deploy-jndi-config.xml
index 65bac54..c45dd10 100755
--- a/etc/deploy-jndi-config.xml
+++ b/etc/deploy-jndi-config.xml
@@ -134,6 +134,7 @@
+
diff --git a/etc/deploy-server.wsdd b/etc/deploy-server.wsdd
index aeae175..f765705 100755
--- a/etc/deploy-server.wsdd
+++ b/etc/deploy-server.wsdd
@@ -15,6 +15,15 @@
share/schema/org.gcube.informationsystem.collector/XMLCollectionAccess_service.wsdl
+
+
+
+
+
+
+ share/schema/org.gcube.informationsystem.collector/XMLStorageAccess_service.wsdl
+
+
diff --git a/schema/XMLCollectionAccess.wsdl b/schema/XMLCollectionAccess.wsdl
index 9699c97..b0d6f48 100755
--- a/schema/XMLCollectionAccess.wsdl
+++ b/schema/XMLCollectionAccess.wsdl
@@ -39,12 +39,7 @@
-
-
-
-
-
-
+
@@ -69,13 +64,6 @@
M E S S A G E S
============================================================-->
-
-
-
-
-
-
-
@@ -104,10 +92,7 @@
============================================================-->
-
-
-
-
+
diff --git a/schema/XMLStorageAccess.wsdl b/schema/XMLStorageAccess.wsdl
index e69de29..062c1d5 100644
--- a/schema/XMLStorageAccess.wsdl
+++ b/schema/XMLStorageAccess.wsdl
@@ -0,0 +1,110 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/schema/XQueryAccess.wsdl b/schema/XQueryAccess.wsdl
index 5dc7fb2..c67a7b3 100644
--- a/schema/XQueryAccess.wsdl
+++ b/schema/XQueryAccess.wsdl
@@ -45,7 +45,7 @@
-
+
@@ -71,9 +71,9 @@
-
+
-
+
diff --git a/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java b/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java
index 881016b..133f11b 100755
--- a/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java
+++ b/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java
@@ -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 {
diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/OldService.java b/src/org/gcube/informationsystem/collector/impl/porttypes/OldService.java
index 56fda2f..868327b 100644
--- a/src/org/gcube/informationsystem/collector/impl/porttypes/OldService.java
+++ b/src/org/gcube/informationsystem/collector/impl/porttypes/OldService.java
@@ -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("\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");
diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/XMLCollectionAccess.java b/src/org/gcube/informationsystem/collector/impl/porttypes/XMLCollectionAccess.java
index 27c7231..be43bfe 100755
--- a/src/org/gcube/informationsystem/collector/impl/porttypes/XMLCollectionAccess.java
+++ b/src/org/gcube/informationsystem/collector/impl/porttypes/XMLCollectionAccess.java
@@ -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 <Resultset> tag. Each record is
- * wrapped with a <Recordt>
- * @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("\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("\n" + xmlres.getContent()+ "\n\n");
- }
- response.append("");
-
- } 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;
- }
+ } */
}
/**
diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/XMLStorageAccess.java b/src/org/gcube/informationsystem/collector/impl/porttypes/XMLStorageAccess.java
index e0dfca7..161b65a 100644
--- a/src/org/gcube/informationsystem/collector/impl/porttypes/XMLStorageAccess.java
+++ b/src/org/gcube/informationsystem/collector/impl/porttypes/XMLStorageAccess.java
@@ -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;
- }
+ } */
}
}
diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/XQueryAccess.java b/src/org/gcube/informationsystem/collector/impl/porttypes/XQueryAccess.java
index 1b7a0f2..a67eed0 100644
--- a/src/org/gcube/informationsystem/collector/impl/porttypes/XQueryAccess.java
+++ b/src/org/gcube/informationsystem/collector/impl/porttypes/XQueryAccess.java
@@ -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("\n");
- for (int i = 0; i < (int) result.getSize(); i++) {
- XMLResource xmlres = (XMLResource) result.getResource((long) i);
- dataset.append("\n" + xmlres.getContent() + "\n\n");
- }
- dataset.append("");
- 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();
+ }
+
}
diff --git a/src/org/gcube/informationsystem/collector/impl/state/AggregatorRegisteredResource.java b/src/org/gcube/informationsystem/collector/impl/state/AggregatorRegisteredResource.java
index 593a373..598f528 100755
--- a/src/org/gcube/informationsystem/collector/impl/state/AggregatorRegisteredResource.java
+++ b/src/org/gcube/informationsystem/collector/impl/state/AggregatorRegisteredResource.java
@@ -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) {
diff --git a/src/org/gcube/informationsystem/collector/impl/state/ICAggregatorRemoveCallback.java b/src/org/gcube/informationsystem/collector/impl/state/ICAggregatorRemoveCallback.java
index 8956857..b494956 100755
--- a/src/org/gcube/informationsystem/collector/impl/state/ICAggregatorRemoveCallback.java
+++ b/src/org/gcube/informationsystem/collector/impl/state/ICAggregatorRemoveCallback.java
@@ -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);
}
}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/BackupFolder.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/BackupFolder.java
new file mode 100644
index 0000000..ff58b85
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/BackupFolder.java
@@ -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;}
+
+}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/BackupsRootFolder.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/BackupsRootFolder.java
new file mode 100644
index 0000000..7f190e5
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/BackupsRootFolder.java
@@ -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 getLastBackup(Class 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 clazz = (Class) Class.forName(backupType.getSimpleName());
+ Constructor 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();
+ }
+}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/Scheduler.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/Scheduler.java
new file mode 100644
index 0000000..09240e5
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/backup/Scheduler.java
@@ -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;
+ }
+ }
+}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java
new file mode 100644
index 0000000..590bcb6
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java
@@ -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);
+
+ }
+}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/ExistBackupFolder.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/ExistBackupFolder.java
new file mode 100644
index 0000000..44c768a
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/ExistBackupFolder.java
@@ -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;
+ }
+
+}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/ExistScheduler.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/ExistScheduler.java
new file mode 100644
index 0000000..a99c1ab
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/ExistScheduler.java
@@ -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);
+ }
+
+
+}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java
new file mode 100644
index 0000000..4755707
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java
@@ -0,0 +1,11 @@
+package org.gcube.informationsystem.collector.impl.xmlstorage.exist;
+
+/**
+ * Query Manager
+ *
+ * @author Manuele Simi (ISTI-CNR)
+ *
+ */
+public class QueryManager extends XMLStorageManager {
+
+}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java
index 60eac35..fce5f8d 100755
--- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java
@@ -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
*/
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java
index a524121..e924c3d 100755
--- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java
@@ -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) {
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java
index e9b7cb1..031f944 100755
--- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java
@@ -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)
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XQuery.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XQuery.java
index b4c6c31..1ba5dd5 100755
--- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XQuery.java
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XQuery.java
@@ -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));
- }
+
}
diff --git a/src/org/gcube/informationsystem/collector/testsuite/BackupTester.java b/src/org/gcube/informationsystem/collector/testsuite/BackupTester.java
new file mode 100644
index 0000000..d962f12
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/testsuite/BackupTester.java
@@ -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 Backup operation of the
+ * gcube/informationsystem/collector/XMLStorageAccess portType
+ *
+ * @author Manuele Simi (ISTI-CNR)
+ *
+ */
+public class BackupTester {
+
+ private static GCUBEClientLog logger = new GCUBEClientLog(BackupTester.class);
+
+ /**
+ * @param args
+ *
+ * - IC host
+ *
- IC port
+ *
- Caller Scope
+ *
+ */
+ public static void main(String[] args) {
+
+ /*if (args.length != 3) {
+ logger.fatal("Usage: BackupTester ");
+ 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);
+ }
+
+ }
+
+}
diff --git a/src/org/gcube/informationsystem/collector/testsuite/Client.java b/src/org/gcube/informationsystem/collector/testsuite/Client.java
deleted file mode 100644
index 02b14eb..0000000
--- a/src/org/gcube/informationsystem/collector/testsuite/Client.java
+++ /dev/null
@@ -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
- *
- * - to compile: javac -classpath MYPATH/org_diligentproject_informationservice_disic_stubs.jar:$CLASSPATH testsuite/Client.java
- *
- *
- to run (make sure that the DIS-IC stub classes are in your CLASSPATH):
- *
- *
- * - 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
- *
- *
- 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
- * (allowed type are: "DHN", "RI", "SERVICE", "CS", "CSInstance", "Collection", "gLiteResource"
- *
- 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
- *
- *
- 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
- *
- *
- * @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
-}
diff --git a/src/org/gcube/informationsystem/collector/testsuite/ServiceMap_CNRPrivate.xml b/src/org/gcube/informationsystem/collector/testsuite/ServiceMap_CNRPrivate.xml
index 35ff6f5..97f7047 100644
--- a/src/org/gcube/informationsystem/collector/testsuite/ServiceMap_CNRPrivate.xml
+++ b/src/org/gcube/informationsystem/collector/testsuite/ServiceMap_CNRPrivate.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/src/org/gcube/informationsystem/collector/testsuite/ShutdownTester.java b/src/org/gcube/informationsystem/collector/testsuite/ShutdownTester.java
new file mode 100644
index 0000000..2426a4b
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/testsuite/ShutdownTester.java
@@ -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) {
+
+
+ }
+
+}
diff --git a/src/org/gcube/informationsystem/collector/testsuite/XQueryExecuteTester.java b/src/org/gcube/informationsystem/collector/testsuite/XQueryExecuteTester.java
new file mode 100644
index 0000000..b0166ca
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/testsuite/XQueryExecuteTester.java
@@ -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 XQueryExecute operation of the gcube/informationsystem/collector/XQueryAccess portType
+ *
+ * @author Manuele Simi (ISTI-CNR)
+ *
+ */
+public class XQueryExecuteTester {
+
+ private static GCUBEClientLog logger = new GCUBEClientLog(XQueryExecuteTester.class);
+ /**
+ * @param args
+ *
+ * - IC host
+ *
- IC port
+ *
- Caller Scope
+ *
- File including the XQuery to submit
+ *
+ */
+ public static void main(String[] args) {
+
+ if (args.length != 4) {
+ logger.fatal("Usage: XQueryExecuteTester " );
+ 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;
+
+ }
+
+}
diff --git a/src/org/gcube/informationsystem/collector/testsuite/query-example.xq b/src/org/gcube/informationsystem/collector/testsuite/query-example.xq
index 18557c0..9b03535 100644
--- a/src/org/gcube/informationsystem/collector/testsuite/query-example.xq
+++ b/src/org/gcube/informationsystem/collector/testsuite/query-example.xq
@@ -1,3 +1,7 @@
-xquery version "1.0";
-
- for $doc in collection("/db/Properties")//Document return $doc
\ No newline at end of file
+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
+