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:
parent
43e438190c
commit
66a967b067
|
@ -2,7 +2,7 @@
|
||||||
<!DOCTYPE xml>
|
<!DOCTYPE xml>
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
<Changeset component="org.gcube.vre-management.smart-executor.1.10.0" date="${buildDate}">
|
<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>
|
||||||
<Changeset component="org.gcube.vre-management.smart-executor.1.9.0" date="2017-02-15">
|
<Changeset component="org.gcube.vre-management.smart-executor.1.9.0" date="2017-02-15">
|
||||||
<Change>Added REST interface to Smart Executor #5109</Change>
|
<Change>Added REST interface to Smart Executor #5109</Change>
|
||||||
|
|
3
pom.xml
3
pom.xml
|
@ -53,7 +53,6 @@
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
@ -149,12 +148,10 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.ws.rs</groupId>
|
<groupId>javax.ws.rs</groupId>
|
||||||
<artifactId>javax.ws.rs-api</artifactId>
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
<version>2.0.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.containers</groupId>
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
<artifactId>jersey-container-servlet</artifactId>
|
<artifactId>jersey-container-servlet</artifactId>
|
||||||
<version>2.13</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
|
|
|
@ -25,8 +25,8 @@ import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
|
import com.orientechnologies.orient.core.db.ODatabasePool;
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
import com.orientechnologies.orient.core.db.ODatabaseSession;
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class OrientDBPersistenceConnector extends
|
||||||
|
|
||||||
protected final String RUN_ON = "runOn";
|
protected final String RUN_ON = "runOn";
|
||||||
|
|
||||||
protected OPartitionedDatabasePool oPartitionedDatabasePool;
|
protected ODatabasePool oDatabasePool;
|
||||||
|
|
||||||
public OrientDBPersistenceConnector(SmartExecutorPersistenceConfiguration configuration)
|
public OrientDBPersistenceConnector(SmartExecutorPersistenceConfiguration configuration)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
@ -63,20 +63,20 @@ public class OrientDBPersistenceConnector extends
|
||||||
String url = configuration.getURL();
|
String url = configuration.getURL();
|
||||||
String username = configuration.getUsername();
|
String username = configuration.getUsername();
|
||||||
String password = configuration.getPassword();
|
String password = configuration.getPassword();
|
||||||
this.oPartitionedDatabasePool = new OPartitionedDatabasePool(url,
|
|
||||||
username, password);
|
oDatabasePool = new ODatabasePool(url, username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws Exception {
|
public void close() throws Exception {
|
||||||
oPartitionedDatabasePool.close();
|
oDatabasePool.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginStateEvolution getPluginInstanceState(UUID uuid,
|
public PluginStateEvolution getPluginInstanceState(UUID uuid,
|
||||||
Integer iterationNumber) throws PluginInstanceNotFoundException, ExecutorException {
|
Integer iterationNumber) throws PluginInstanceNotFoundException, ExecutorException {
|
||||||
ODatabaseDocumentTx db = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
db = oPartitionedDatabasePool.acquire();
|
oDatabaseSession = oDatabasePool.acquire();
|
||||||
String type = PluginStateEvolution.class.getSimpleName();
|
String type = PluginStateEvolution.class.getSimpleName();
|
||||||
Map<String, Object> params = new HashMap<String, Object>();
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
params.put(UUID, uuid.toString());
|
params.put(UUID, uuid.toString());
|
||||||
|
@ -123,17 +123,18 @@ public class OrientDBPersistenceConnector extends
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new PluginInstanceNotFoundException();
|
throw new PluginInstanceNotFoundException();
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
if(oDatabaseSession!=null) {
|
||||||
|
oDatabaseSession.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pluginStateEvolution(PluginStateEvolution pluginStateEvolution,
|
public void pluginStateEvolution(PluginStateEvolution pluginStateEvolution,
|
||||||
Exception exception) throws Exception {
|
Exception exception) throws Exception {
|
||||||
ODatabaseDocumentTx db = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
db = oPartitionedDatabasePool.acquire();
|
oDatabaseSession = oDatabasePool.acquire();
|
||||||
|
|
||||||
ODocument doc = new ODocument(
|
ODocument doc = new ODocument(
|
||||||
PluginStateEvolution.class.getSimpleName());
|
PluginStateEvolution.class.getSimpleName());
|
||||||
String json = ObjectMapperManager.getObjectMapper().writeValueAsString(pluginStateEvolution);
|
String json = ObjectMapperManager.getObjectMapper().writeValueAsString(pluginStateEvolution);
|
||||||
|
@ -141,15 +142,15 @@ public class OrientDBPersistenceConnector extends
|
||||||
doc.field(SCOPE, SmartExecutorInitializator.getCurrentScope());
|
doc.field(SCOPE, SmartExecutorInitializator.getCurrentScope());
|
||||||
|
|
||||||
doc.save();
|
doc.save();
|
||||||
db.commit();
|
oDatabaseSession.commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.rollback();
|
oDatabaseSession.rollback();
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.close();
|
oDatabaseSession.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,9 +158,9 @@ public class OrientDBPersistenceConnector extends
|
||||||
@Override
|
@Override
|
||||||
public void addScheduledTask(ScheduledTask scheduledTask)
|
public void addScheduledTask(ScheduledTask scheduledTask)
|
||||||
throws SchedulePersistenceException {
|
throws SchedulePersistenceException {
|
||||||
ODatabaseDocumentTx db = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
db = oPartitionedDatabasePool.acquire();
|
oDatabaseSession = oDatabasePool.acquire();
|
||||||
|
|
||||||
ODocument doc = new ODocument(ScheduledTask.class.getSimpleName());
|
ODocument doc = new ODocument(ScheduledTask.class.getSimpleName());
|
||||||
|
|
||||||
|
@ -170,14 +171,16 @@ public class OrientDBPersistenceConnector extends
|
||||||
doc.fromJSON(json);
|
doc.fromJSON(json);
|
||||||
doc.save();
|
doc.save();
|
||||||
|
|
||||||
db.commit();
|
oDatabaseSession.commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.rollback();
|
oDatabaseSession.rollback();
|
||||||
}
|
}
|
||||||
throw new SchedulePersistenceException(e);
|
throw new SchedulePersistenceException(e);
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
if (oDatabaseSession != null) {
|
||||||
|
oDatabaseSession.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -186,9 +189,9 @@ public class OrientDBPersistenceConnector extends
|
||||||
public List<ScheduledTask> getOrphanScheduledTasks(
|
public List<ScheduledTask> getOrphanScheduledTasks(
|
||||||
Collection<? extends PluginDeclaration> pluginDeclarations)
|
Collection<? extends PluginDeclaration> pluginDeclarations)
|
||||||
throws SchedulePersistenceException {
|
throws SchedulePersistenceException {
|
||||||
ODatabaseDocumentTx db = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
db = oPartitionedDatabasePool.acquire();
|
oDatabaseSession = oDatabasePool.acquire();
|
||||||
String type = ScheduledTask.class.getSimpleName();
|
String type = ScheduledTask.class.getSimpleName();
|
||||||
|
|
||||||
String queryString = String.format("SELECT * FROM %s WHERE %s = '%s'", type, "scope", SmartExecutorInitializator.getCurrentScope());
|
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) {
|
} catch (Exception e) {
|
||||||
throw new SchedulePersistenceException(e);
|
throw new SchedulePersistenceException(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.close();
|
oDatabaseSession.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ODocument getScheduledTaskDocument(ODatabaseDocumentTx db,
|
protected ODocument getScheduledTaskDocument(UUID uuid) throws SchedulePersistenceException {
|
||||||
UUID uuid) throws SchedulePersistenceException {
|
|
||||||
try {
|
try {
|
||||||
String type = ScheduledTask.class.getSimpleName();
|
String type = ScheduledTask.class.getSimpleName();
|
||||||
Map<String, Object> params = new HashMap<String, Object>();
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
|
@ -283,17 +285,17 @@ public class OrientDBPersistenceConnector extends
|
||||||
@Override
|
@Override
|
||||||
public ScheduledTask getScheduledTask(UUID uuid)
|
public ScheduledTask getScheduledTask(UUID uuid)
|
||||||
throws SchedulePersistenceException {
|
throws SchedulePersistenceException {
|
||||||
ODatabaseDocumentTx db = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
db = oPartitionedDatabasePool.acquire();
|
oDatabaseSession = oDatabasePool.acquire();
|
||||||
ODocument doc = getScheduledTaskDocument(db, uuid);
|
ODocument doc = getScheduledTaskDocument(uuid);
|
||||||
String json = doc.toJSON("class");
|
String json = doc.toJSON("class");
|
||||||
return ObjectMapperManager.getObjectMapper().readValue(json, ScheduledTask.class);
|
return ObjectMapperManager.getObjectMapper().readValue(json, ScheduledTask.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SchedulePersistenceException(e);
|
throw new SchedulePersistenceException(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.close();
|
oDatabaseSession.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,20 +309,20 @@ public class OrientDBPersistenceConnector extends
|
||||||
@Override
|
@Override
|
||||||
public void removeScheduledTask(UUID uuid)
|
public void removeScheduledTask(UUID uuid)
|
||||||
throws SchedulePersistenceException {
|
throws SchedulePersistenceException {
|
||||||
ODatabaseDocumentTx db = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
db = oPartitionedDatabasePool.acquire();
|
oDatabaseSession = oDatabasePool.acquire();
|
||||||
ODocument doc = getScheduledTaskDocument(db, uuid);
|
ODocument doc = getScheduledTaskDocument(uuid);
|
||||||
doc.delete();
|
doc.delete();
|
||||||
db.commit();
|
oDatabaseSession.commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.rollback();
|
oDatabaseSession.rollback();
|
||||||
}
|
}
|
||||||
throw new SchedulePersistenceException(e);
|
throw new SchedulePersistenceException(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.close();
|
oDatabaseSession.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,20 +337,20 @@ public class OrientDBPersistenceConnector extends
|
||||||
@Override
|
@Override
|
||||||
public void releaseScheduledTask(UUID uuid)
|
public void releaseScheduledTask(UUID uuid)
|
||||||
throws SchedulePersistenceException {
|
throws SchedulePersistenceException {
|
||||||
ODatabaseDocumentTx db = null;
|
ODatabaseSession oDatabaseSession = null;
|
||||||
try {
|
try {
|
||||||
db = oPartitionedDatabasePool.acquire();
|
oDatabaseSession = oDatabasePool.acquire();
|
||||||
ODocument doc = getScheduledTaskDocument(db, uuid);
|
ODocument doc = getScheduledTaskDocument(uuid);
|
||||||
doc.removeField(RUN_ON);
|
doc.removeField(RUN_ON);
|
||||||
doc.save();
|
doc.save();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.rollback();
|
oDatabaseSession.rollback();
|
||||||
}
|
}
|
||||||
throw new SchedulePersistenceException(e);
|
throw new SchedulePersistenceException(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null) {
|
if (oDatabaseSession != null) {
|
||||||
db.close();
|
oDatabaseSession.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue