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
This commit is contained in:
Luca Frosini 2019-02-21 13:08:26 +00:00
parent 43e438190c
commit 66a967b067
4 changed files with 53 additions and 54 deletions

View File

@ -2,7 +2,7 @@
<!DOCTYPE xml>
<ReleaseNotes>
<Changeset component="org.gcube.vre-management.smart-executor.1.10.0" date="${buildDate}">
<Change></Change>
<Change>Migrated Code from OrientDB 2.2.X APIs OrientDB 3.0.X APIs #16123</Change>
</Changeset>
<Changeset component="org.gcube.vre-management.smart-executor.1.9.0" date="2017-02-15">
<Change>Added REST interface to Smart Executor #5109</Change>

View File

@ -53,7 +53,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
@ -149,12 +148,10 @@
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.13</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>

View File

@ -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;

View File

@ -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<String, Object> params = new HashMap<String, Object>();
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<ScheduledTask> getOrphanScheduledTasks(
Collection<? extends PluginDeclaration> 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<String, Object> params = new HashMap<String, Object>();
@ -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();
}
}
}