diff --git a/etc/deploy-jndi-config.xml b/etc/deploy-jndi-config.xml
index c518c59..863ba18 100755
--- a/etc/deploy-jndi-config.xml
+++ b/etc/deploy-jndi-config.xml
@@ -13,7 +13,7 @@
-
+
+
+
+
+
+
+
+
@@ -51,6 +59,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -59,6 +77,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -85,6 +113,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -93,9 +137,17 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java b/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java
index 133f11b..fb770d5 100755
--- a/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java
+++ b/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java
@@ -402,7 +402,7 @@ public class AggregatorPersistentResource extends PersistentResource {
* @return the lastUpdateTime in milliseconds
* @throws Exception if an error occurs when accessing the LastUpdateMs field
*/
- public long getLastUpdateTimeinMills() throws Exception {
+ public long getLastUpdateTimeinMills() throws MalformedResourceException {
if (lastUpdateTime != null)
return lastUpdateTime.getTimeInMillis();
@@ -414,18 +414,18 @@ public class AggregatorPersistentResource extends PersistentResource {
} catch (XPathExpressionException xpee) {
logger.error("" + xpee.getMessage());
logger.error("" + xpee.getStackTrace());
- throw new Exception("XPath evaluation error");
+ throw new MalformedResourceException("XPath evaluation error");
}
try {
return Long.parseLong(value);
} catch (NumberFormatException nfe) {
logger.error("Invalid last update time format found in resource " + this.getID());
logger.error("Parsed string was " + value);
- throw new Exception("Unable to retrieve last update time for resource " + this.getID());
+ throw new MalformedResourceException("Unable to retrieve last update time for resource " + this.getID());
}
} else
- throw new Exception("unable to retrieve last update time for resource " + this.getID());
+ throw new MalformedResourceException("unable to retrieve last update time for resource " + this.getID());
}
@@ -433,13 +433,17 @@ public class AggregatorPersistentResource extends PersistentResource {
* Loads the XML DOM from the resource string
*
*/
- private void parseResource() throws Exception {
+ private void parseResource() throws MalformedResourceException {
logger.debug("Parsing resource: " + this.resource_string);
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- StringReader reader = new StringReader(this.resource_string);
- InputSource source = new InputSource(reader);
- this.internalDOM = builder.parse(source);
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ StringReader reader = new StringReader(this.resource_string);
+ InputSource source = new InputSource(reader);
+ this.internalDOM = builder.parse(source);
+ } catch (Exception e) {
+ throw new MalformedResourceException(e);
+ }
}
diff --git a/src/org/gcube/informationsystem/collector/impl/persistence/PersistentResource.java b/src/org/gcube/informationsystem/collector/impl/persistence/PersistentResource.java
index 9a7ab1d..5a6fe18 100644
--- a/src/org/gcube/informationsystem/collector/impl/persistence/PersistentResource.java
+++ b/src/org/gcube/informationsystem/collector/impl/persistence/PersistentResource.java
@@ -41,7 +41,7 @@ public abstract class PersistentResource {
* if the resource has no profile type (i.e. it is not a
* profile)
*/
- public abstract String getProfileType() throws Exception;
+ public abstract String getProfileType() throws MalformedResourceException;
/**
* Gets the publisher of the resource
@@ -62,7 +62,7 @@ public abstract class PersistentResource {
* @return
* @throws Exception
*/
- public abstract long getLastUpdateTimeinMills() throws Exception;
+ public abstract long getLastUpdateTimeinMills() throws MalformedResourceException;
/**
* {@inheritDoc}
@@ -94,5 +94,16 @@ public abstract class PersistentResource {
return false;
return true;
}
-
+ /**
+ *
+ * Malformed resource exception
+ *
+ * @author Manuele Simi (ISTI-CNR)
+ *
+ */
+ public static class MalformedResourceException extends Exception {
+ private static final long serialVersionUID = 1L;
+ public MalformedResourceException(Exception e) {super(e);}
+ public MalformedResourceException(String message) {super(message);}
+ }
}
diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/XMLStorageAccess.java b/src/org/gcube/informationsystem/collector/impl/porttypes/XMLStorageAccess.java
index 9a79942..1c10a4b 100644
--- a/src/org/gcube/informationsystem/collector/impl/porttypes/XMLStorageAccess.java
+++ b/src/org/gcube/informationsystem/collector/impl/porttypes/XMLStorageAccess.java
@@ -2,13 +2,15 @@ package org.gcube.informationsystem.collector.impl.porttypes;
import java.io.IOException;
-import org.oasis.wsrf.faults.BaseFaultType;
import org.xmldb.api.base.XMLDBException;
+import org.gcube.informationsystem.collector.stubs.AlreadyConnectedFaultType;
import org.gcube.informationsystem.collector.stubs.BackupFailedFaultType;
import org.gcube.informationsystem.collector.stubs.BackupNotAvailableFaultType;
+import org.gcube.informationsystem.collector.stubs.ShutdownFailedFaultType;
import org.gcube.informationsystem.collector.stubs.XMLStorageNotAvailableFaultType;
import org.gcube.common.core.contexts.GCUBEServiceContext;
+import org.gcube.common.core.contexts.GCUBEServiceContext.Status;
import org.gcube.common.core.porttypes.GCUBEPortType;
import org.gcube.common.core.types.VOID;
import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext;
@@ -50,6 +52,13 @@ public class XMLStorageAccess extends GCUBEPortType {
return new VOID();
}
+ /**
+ *
+ * @param params
+ * @return
+ * @throws BackupNotAvailableFaultType
+ * @throws XMLStorageNotAvailableFaultType
+ */
public VOID restore(VOID params) throws BackupNotAvailableFaultType, XMLStorageNotAvailableFaultType {
try {
@@ -61,40 +70,69 @@ public class XMLStorageAccess extends GCUBEPortType {
throw fault;
}
- return new VOID();
+ return new VOID();
+ }
+
+ /**
+ * Shutdowns the XMLStorage
+ *
+ * @throws BackupFailedFaultType if the backup before the shutdown fails
+ * @throws XMLStorageNotAvailableFaultType if the XMLStorage is not available
+ * @throws ShutdownFailedFaultType if the shutdown fails
+ */
+ public VOID shutdown(VOID params) throws BackupFailedFaultType, XMLStorageNotAvailableFaultType, ShutdownFailedFaultType {
+ logger.info("Shutdown operation invoked");
+
+ //request the backup before to shutdown
+ try {
+ State.getDataManager().backup();
+ } catch (XMLDBException e) {
+ logger.error("Unable to backup before shutting down" ,e);
+ XMLStorageNotAvailableFaultType fault = new XMLStorageNotAvailableFaultType();
+ fault.addFaultDetailString("No valid backup has been found");
+ throw fault;
+ } catch (Exception e) {
+ logger.error("Unable to backup before shutting down" ,e);
+ //should we throw here and leave?
+ BackupFailedFaultType fault = new BackupFailedFaultType();
+ fault.addFaultDetailString("No valid backup has been found");
+ throw fault;
+ }
+
+ try {
+ State.dispose();
+ ICServiceContext.getContext().setStatus(Status.DOWN);
+ } catch (Exception e) {
+ logger.error("Shutdown failed", e);
+ ShutdownFailedFaultType fault = new ShutdownFailedFaultType();
+ fault.addFaultDetailString("Shutdown failed," + e.getMessage());
+ throw fault;
+ }
+ return new VOID();
}
/**
- * Disposes the XMLStorage
*
- * @throws BaseFaultType if the shutdown fails
+ * @param params
+ * @return
+ * @throws XMLStorageNotAvailableFaultType
+ * @throws AlreadyConnectedFaultType
*/
- public void dispose() throws BaseFaultType {
+ public VOID connect(VOID params) throws XMLStorageNotAvailableFaultType, AlreadyConnectedFaultType {
- //request the backup before to shutdown
- this.backup(new VOID());
- /*try {
- logger.info("Dispose operation invoked");
- logger.info("trying to shutdown the storage instances...");
- try {
- State.storage_manager.shutdown();
- State.query_manager.shutdown();
- } catch (NullPointerException se) {
- }
- State.storage_manager = null;
- State.query_manager = null;
- // request the interruption of the sweeper thread
- State.sweeperT.interrupt();
- logger.info("done");
+ logger.info("Connect operation invoked");
+ try {
+ State.initialize();
+ ICServiceContext.getContext().setStatus(Status.READIED);
} catch (Exception e) {
- logger.error("unable to pose the IC with success ", e);
- BaseFaultType fault = new BaseFaultType();
- FaultHelper faultHelper = new FaultHelper(fault);
- faultHelper.addFaultCause(e);
- faultHelper
- .addDescription("-IC service: Unable to pose the service");
+ logger.error("Initialisation failed", e);
+ XMLStorageNotAvailableFaultType fault = new XMLStorageNotAvailableFaultType();
+ fault.addFaultDetailString("Initialisation failed," + e.getMessage());
throw fault;
- } */
+ }
+
+
+ return new VOID();
}
}
diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java
index 8586c53..41c4dfc 100644
--- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java
@@ -76,6 +76,7 @@ public class DataManager extends XMLStorageManager {
try {
ExistBackupFolder lastBackup = this.getLastBackup();
+ logger.info("Restoring from " + lastBackup.getBackupFile());
Restore restore = new Restore("admin", "admin","admin", lastBackup.getBackupFile(), URI);
restore.restore(false, null);
logger.info("Restore completed");
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 fd2a8a6..9e6a27a 100755
--- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java
@@ -91,14 +91,6 @@ public class State {
queryManager.initialize();
}
- /**
- *
- * @return the container base dir
- */
-// public static String getBaseDirectory() {
-// return ContainerConfig.getBaseDirectory();
-// }
-
/**
* Releases all the State resources
*
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 e924c3d..96f0bfc 100755
--- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java
@@ -61,6 +61,7 @@ public class Sweeper implements Runnable {
this.cleanExpiredResources();
}
} catch (InterruptedException ie) {
+ logger.error("Unable to sleep (yawn)", ie);
// thread was interrupted
storage.shutdown();
}
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 11a7225..cb2c388 100755
--- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java
+++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java
@@ -17,6 +17,7 @@ import org.exist.storage.DBBroker;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource;
import org.gcube.informationsystem.collector.impl.persistence.PersistentResource;
+import org.gcube.informationsystem.collector.impl.persistence.PersistentResource.MalformedResourceException;
import org.gcube.informationsystem.collector.impl.persistence.PersistentResource.RESOURCETYPE;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorageManager;
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XQuery;
@@ -62,6 +63,10 @@ public class XMLStorageManager {
protected static String PROFILES_COLLECTION_NAME = "Profiles";
+ enum STATUS {INITIALISED, CLOSED, SHUTDOWN};
+
+ protected static STATUS status = STATUS.CLOSED;
+
/**
* Creates a new manager
*
@@ -77,9 +82,14 @@ public class XMLStorageManager {
* @throws Exception
* if the connection to eXist or its initialization fail
*/
- public void initialize() throws Exception {
+ public void initialize() throws XMLStorageNotAvailableException {
+
+ if (status == STATUS.INITIALISED) {
+ logger.warn("XMLStorage already initialized");
+ return;
+ }
try {
- logger.info("connecting to eXist DB...");
+ logger.info("Initializing XMLStorage...");
// this.printEnv();
// lock the instance
@@ -96,7 +106,7 @@ public class XMLStorageManager {
this.rootCollection = DatabaseManager.getCollection(URI + DBBroker.ROOT_COLLECTION, "admin", "admin");
if (this.rootCollection == null) {
logger.error("invalid root collection!");
- throw new Exception("unable to load root collection");
+ throw new XMLStorageNotAvailableException("unable to load root collection");
}
logger.debug("Initializing the collection Profiles");
this.profilesRootCollection = this.rootCollection.getChildCollection(XMLStorageManager.PROFILES_COLLECTION_NAME);
@@ -106,21 +116,22 @@ public class XMLStorageManager {
logger.debug("Profiles collection created");
}
if (this.profilesRootCollection == null) {
- throw new Exception("Unable to load/create Profiles collection");
+ throw new XMLStorageNotAvailableException("Unable to load/create Profiles collection");
}
this.rootCollection.setProperty("pretty", "true");
this.rootCollection.setProperty("encoding", "UTF-8");
this.profilesRootCollection.setProperty("pretty", "true");
this.profilesRootCollection.setProperty("encoding", "UTF-8");
+ status= STATUS.INITIALISED;
} catch (XMLDBException edb) {
logger.error("unable to initialize XML storage ", edb);
- throw new Exception("unable to initialize XML storage");
+ throw new XMLStorageNotAvailableException("unable to initialize XML storage");
} catch (Exception e) {
- logger.debug("unable to initialize XML storage ", e);
- throw new Exception("unable to initialize XML storage");
+ logger.error("unable to initialize XML storage ", e);
+ throw new XMLStorageNotAvailableException("unable to initialize XML storage");
} catch (java.lang.NoClassDefFoundError ncdfe) {
- logger.debug("unable to initialize XML storage", ncdfe);
- throw new Exception("unable to initialize XML storage");
+ logger.error("unable to initialize XML storage", ncdfe);
+ throw new XMLStorageNotAvailableException("unable to initialize XML storage");
} finally {
writeLock.unlock();
}
@@ -137,6 +148,7 @@ public class XMLStorageManager {
try {
DatabaseInstanceManager manager = (DatabaseInstanceManager) rootCollection.getService("DatabaseInstanceManager", "1.0");
manager.shutdown();
+ status = STATUS.SHUTDOWN;
} catch (XMLDBException edb) {
logger.error("Unable to shutdown XML storage");
logger.error("" + edb.getCause());
@@ -257,8 +269,10 @@ public class XMLStorageManager {
* @throws Exception
* if the storing fails
*/
- public void storeResource(PersistentResource resource) throws Exception {
+ public void storeResource(PersistentResource resource) throws XMLStorageNotAvailableException, MalformedResourceException {
+ if (status != STATUS.INITIALISED)
+ throw new XMLStorageNotAvailableException("XMLStorage not initialized");
Collection currentCollection = null;
if (resource.getType() == RESOURCETYPE.Profile) {
// the entry contains a gCube resource profile
@@ -270,7 +284,7 @@ public class XMLStorageManager {
if (currentCollection == null) {
logger.error("Unable to open the Collection");
- return;
+ throw new XMLStorageNotAvailableException("Unable to open the Collection");
}
writeLock.lock();
this.locked = true;
@@ -626,4 +640,16 @@ public class XMLStorageManager {
return content.toString();
}
+ /**
+ *
+ * XMLStorage not initialized exception
+ *
+ * @author Manuele Simi (ISTI-CNR)
+ *
+ */
+ public static class XMLStorageNotAvailableException extends Exception {
+ private static final long serialVersionUID = 1L;
+ public XMLStorageNotAvailableException(String message) { super(message);}
+
+ }
}
diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/BackupTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/BackupTester.java
index 1596187..ddccaa4 100644
--- a/src/org/gcube/informationsystem/collector/stubs/testsuite/BackupTester.java
+++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/BackupTester.java
@@ -47,7 +47,7 @@ public class BackupTester {
port = new XMLStorageAccessServiceLocator().getXMLStorageAccessPortTypePort(new URL(portTypeURI));
port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope("/CNRPrivate"));
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
logger.info("Submitting backup request...");
diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/RestoreTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/RestoreTester.java
index b23c3a4..c2e6447 100644
--- a/src/org/gcube/informationsystem/collector/stubs/testsuite/RestoreTester.java
+++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/RestoreTester.java
@@ -46,7 +46,7 @@ public class RestoreTester {
port = new XMLStorageAccessServiceLocator().getXMLStorageAccessPortTypePort(new URL(portTypeURI));
port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope("/CNRPrivate"));
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
logger.info("Submitting restore request...");
diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/ShutdownTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/ShutdownTester.java
index baef53d..aa3f047 100644
--- a/src/org/gcube/informationsystem/collector/stubs/testsuite/ShutdownTester.java
+++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/ShutdownTester.java
@@ -1,18 +1,67 @@
package org.gcube.informationsystem.collector.stubs.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.ShutdownFailedFaultType;
+import org.gcube.informationsystem.collector.stubs.XMLStorageAccessPortType;
+import org.gcube.informationsystem.collector.stubs.XMLStorageNotAvailableFaultType;
+import org.gcube.informationsystem.collector.stubs.service.XMLStorageAccessServiceLocator;
+
/**
* TODO: Manuele, don't forget to add a comment for this new type!!
- *
+ *
* @author Manuele Simi (ISTI-CNR)
- *
+ *
*/
public class ShutdownTester {
+ private static GCUBEClientLog logger = new GCUBEClientLog(RestoreTester.class);
+
/**
* @param args
+ *
+ * - IC host
+ *
- IC port
+ *
- Caller Scope
+ *
*/
public static void main(String[] args) {
+ /*
+ * if (args.length != 3) { logger.fatal("Usage: RestoreTester ");
+ * return; }
+ */
+ // final String portTypeURI = "http://" + args[0] + ":" + args[1] +
+ // "/wsrf/services/gcube/informationsystem/collector/XMLStorageAccess";
+ final 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) {
+ logger.error("",e);
+ }
+
+ logger.info("Submitting shutdown request to " + portTypeURI+ "...");
+
+ try {
+ port.shutdown(new VOID());
+ } catch (XMLStorageNotAvailableFaultType e) {
+ logger.error("",e);
+ } catch (ShutdownFailedFaultType e) {
+ logger.error("",e);
+ } catch (BackupFailedFaultType e) {
+ logger.error("",e);
+ } catch (RemoteException e) {
+ logger.error("",e);
+ }
}
diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/XQueryExecuteTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/XQueryExecuteTester.java
index 18cc4bd..b16d0c5 100644
--- a/src/org/gcube/informationsystem/collector/stubs/testsuite/XQueryExecuteTester.java
+++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/XQueryExecuteTester.java
@@ -48,7 +48,7 @@ public class XQueryExecuteTester {
port = new XQueryAccessServiceLocator().getXQueryAccessPortTypePort(new URL(portTypeURI));
port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope(args[2]));
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
XQueryExecuteRequest request = new XQueryExecuteRequest();