From 66a967b06756d3917845bf3bdb8e66827a8397e3 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 21 Feb 2019 13:08:26 +0000 Subject: [PATCH] Refs #16123: Migrate SmartExecutorPersistence from OrientDB 2.2.X to 3.0.X Task-Url: https://support.d4science.org/issues/16123 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@177207 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 2 +- pom.xml | 3 - ...SmartExecutorPersistenceConfiguration.java | 2 +- .../OrientDBPersistenceConnector.java | 100 +++++++++--------- 4 files changed, 53 insertions(+), 54 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index 2a0a4aa..4efbc63 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -2,7 +2,7 @@ - + Migrated Code from OrientDB 2.2.X APIs OrientDB 3.0.X APIs #16123 Added REST interface to Smart Executor #5109 diff --git a/pom.xml b/pom.xml index 71c4d5f..8ce323d 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,6 @@ pom import - @@ -149,12 +148,10 @@ javax.ws.rs javax.ws.rs-api - 2.0.1 org.glassfish.jersey.containers jersey-container-servlet - 2.13 javax.servlet diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java index d905c3e..fa24eb4 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java @@ -8,7 +8,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.gcube.common.encryption.StringEncrypter; +import org.gcube.common.encryption.encrypter.StringEncrypter; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; import org.gcube.common.resources.gcore.ServiceEndpoint.Property; diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/orientdb/OrientDBPersistenceConnector.java b/src/main/java/org/gcube/vremanagement/executor/persistence/orientdb/OrientDBPersistenceConnector.java index e9ec781..2dfd9f8 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/orientdb/OrientDBPersistenceConnector.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/orientdb/OrientDBPersistenceConnector.java @@ -25,8 +25,8 @@ import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.orientechnologies.orient.core.db.OPartitionedDatabasePool; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.orient.core.db.ODatabasePool; +import com.orientechnologies.orient.core.db.ODatabaseSession; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; @@ -47,7 +47,7 @@ public class OrientDBPersistenceConnector extends protected final String RUN_ON = "runOn"; - protected OPartitionedDatabasePool oPartitionedDatabasePool; + protected ODatabasePool oDatabasePool; public OrientDBPersistenceConnector(SmartExecutorPersistenceConfiguration configuration) throws Exception { @@ -63,20 +63,20 @@ public class OrientDBPersistenceConnector extends String url = configuration.getURL(); String username = configuration.getUsername(); String password = configuration.getPassword(); - this.oPartitionedDatabasePool = new OPartitionedDatabasePool(url, - username, password); + + oDatabasePool = new ODatabasePool(url, username, password); } @Override public void close() throws Exception { - oPartitionedDatabasePool.close(); + oDatabasePool.close(); } public PluginStateEvolution getPluginInstanceState(UUID uuid, Integer iterationNumber) throws PluginInstanceNotFoundException, ExecutorException { - ODatabaseDocumentTx db = null; + ODatabaseSession oDatabaseSession = null; try { - db = oPartitionedDatabasePool.acquire(); + oDatabaseSession = oDatabasePool.acquire(); String type = PluginStateEvolution.class.getSimpleName(); Map params = new HashMap(); params.put(UUID, uuid.toString()); @@ -123,17 +123,18 @@ public class OrientDBPersistenceConnector extends } catch (Exception e) { throw new PluginInstanceNotFoundException(); } finally { - db.close(); + if(oDatabaseSession!=null) { + oDatabaseSession.close(); + } } } @Override public void pluginStateEvolution(PluginStateEvolution pluginStateEvolution, Exception exception) throws Exception { - ODatabaseDocumentTx db = null; + ODatabaseSession oDatabaseSession = null; try { - db = oPartitionedDatabasePool.acquire(); - + oDatabaseSession = oDatabasePool.acquire(); ODocument doc = new ODocument( PluginStateEvolution.class.getSimpleName()); String json = ObjectMapperManager.getObjectMapper().writeValueAsString(pluginStateEvolution); @@ -141,15 +142,15 @@ public class OrientDBPersistenceConnector extends doc.field(SCOPE, SmartExecutorInitializator.getCurrentScope()); doc.save(); - db.commit(); + oDatabaseSession.commit(); } catch (Exception e) { - if (db != null) { - db.rollback(); + if (oDatabaseSession != null) { + oDatabaseSession.rollback(); } throw e; } finally { - if (db != null) { - db.close(); + if (oDatabaseSession != null) { + oDatabaseSession.close(); } } } @@ -157,9 +158,9 @@ public class OrientDBPersistenceConnector extends @Override public void addScheduledTask(ScheduledTask scheduledTask) throws SchedulePersistenceException { - ODatabaseDocumentTx db = null; + ODatabaseSession oDatabaseSession = null; try { - db = oPartitionedDatabasePool.acquire(); + oDatabaseSession = oDatabasePool.acquire(); ODocument doc = new ODocument(ScheduledTask.class.getSimpleName()); @@ -170,14 +171,16 @@ public class OrientDBPersistenceConnector extends doc.fromJSON(json); doc.save(); - db.commit(); + oDatabaseSession.commit(); } catch (Exception e) { - if (db != null) { - db.rollback(); + if (oDatabaseSession != null) { + oDatabaseSession.rollback(); } throw new SchedulePersistenceException(e); } finally { - db.close(); + if (oDatabaseSession != null) { + oDatabaseSession.close(); + } } } @@ -186,9 +189,9 @@ public class OrientDBPersistenceConnector extends public List getOrphanScheduledTasks( Collection pluginDeclarations) throws SchedulePersistenceException { - ODatabaseDocumentTx db = null; + ODatabaseSession oDatabaseSession = null; try { - db = oPartitionedDatabasePool.acquire(); + oDatabaseSession = oDatabasePool.acquire(); String type = ScheduledTask.class.getSimpleName(); String queryString = String.format("SELECT * FROM %s WHERE %s = '%s'", type, "scope", SmartExecutorInitializator.getCurrentScope()); @@ -241,14 +244,13 @@ public class OrientDBPersistenceConnector extends } catch (Exception e) { throw new SchedulePersistenceException(e); } finally { - if (db != null) { - db.close(); + if (oDatabaseSession != null) { + oDatabaseSession.close(); } } } - protected ODocument getScheduledTaskDocument(ODatabaseDocumentTx db, - UUID uuid) throws SchedulePersistenceException { + protected ODocument getScheduledTaskDocument(UUID uuid) throws SchedulePersistenceException { try { String type = ScheduledTask.class.getSimpleName(); Map params = new HashMap(); @@ -283,17 +285,17 @@ public class OrientDBPersistenceConnector extends @Override public ScheduledTask getScheduledTask(UUID uuid) throws SchedulePersistenceException { - ODatabaseDocumentTx db = null; + ODatabaseSession oDatabaseSession = null; try { - db = oPartitionedDatabasePool.acquire(); - ODocument doc = getScheduledTaskDocument(db, uuid); + oDatabaseSession = oDatabasePool.acquire(); + ODocument doc = getScheduledTaskDocument(uuid); String json = doc.toJSON("class"); return ObjectMapperManager.getObjectMapper().readValue(json, ScheduledTask.class); } catch (Exception e) { throw new SchedulePersistenceException(e); } finally { - if (db != null) { - db.close(); + if (oDatabaseSession != null) { + oDatabaseSession.close(); } } } @@ -307,20 +309,20 @@ public class OrientDBPersistenceConnector extends @Override public void removeScheduledTask(UUID uuid) throws SchedulePersistenceException { - ODatabaseDocumentTx db = null; + ODatabaseSession oDatabaseSession = null; try { - db = oPartitionedDatabasePool.acquire(); - ODocument doc = getScheduledTaskDocument(db, uuid); + oDatabaseSession = oDatabasePool.acquire(); + ODocument doc = getScheduledTaskDocument(uuid); doc.delete(); - db.commit(); + oDatabaseSession.commit(); } catch (Exception e) { - if (db != null) { - db.rollback(); + if (oDatabaseSession != null) { + oDatabaseSession.rollback(); } throw new SchedulePersistenceException(e); } finally { - if (db != null) { - db.close(); + if (oDatabaseSession != null) { + oDatabaseSession.close(); } } } @@ -335,20 +337,20 @@ public class OrientDBPersistenceConnector extends @Override public void releaseScheduledTask(UUID uuid) throws SchedulePersistenceException { - ODatabaseDocumentTx db = null; + ODatabaseSession oDatabaseSession = null; try { - db = oPartitionedDatabasePool.acquire(); - ODocument doc = getScheduledTaskDocument(db, uuid); + oDatabaseSession = oDatabasePool.acquire(); + ODocument doc = getScheduledTaskDocument(uuid); doc.removeField(RUN_ON); doc.save(); } catch (Exception e) { - if (db != null) { - db.rollback(); + if (oDatabaseSession != null) { + oDatabaseSession.rollback(); } throw new SchedulePersistenceException(e); } finally { - if (db != null) { - db.close(); + if (oDatabaseSession != null) { + oDatabaseSession.close(); } } }