Support Scheduled Task take in charge from Orphaned RIs


git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@142808 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-02-20 16:54:07 +00:00
parent 7c91d6f819
commit 0ad1385c73
2 changed files with 5 additions and 97 deletions

View File

@ -20,7 +20,6 @@ import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConf
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
import org.gcube.vremanagement.executor.plugin.RunOn;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -49,7 +48,7 @@ public class OrientDBPersistenceConnector extends
protected final String UUID = "uuid";
protected final String ITERATION = "iteration";
protected final String TIMESTAMP = "timestamp";
protected final String RUN_ON = "runOn";
protected OPartitionedDatabasePool oPartitionedDatabasePool;
@ -329,46 +328,11 @@ public class OrientDBPersistenceConnector extends
}
}
}
@Override
public void reserveScheduledTask(ScheduledTask scheduledTask)
throws SchedulePersistenceException {
ODatabaseDocumentTx db = null;
try {
db = oPartitionedDatabasePool.acquire();
UUID uuid = scheduledTask.getUUID();
ODocument doc = getScheduledTaskDocument(db, uuid);
Long timestamp = doc.field(TIMESTAMP);
if (timestamp!=null && timestamp.compareTo(scheduledTask.getTimestamp())!=0) {
throw new SchedulePersistenceException(
"The ScheduledTask has been already reserved.");
}
RunOn runOn = ScheduledTask.generateRunOn();
ODocument runOnDocument = new ODocument();
runOnDocument.fromJSON(mapper.writeValueAsString(runOn));
doc.field(RUN_ON, runOnDocument);
timestamp = Calendar.getInstance().getTimeInMillis();
doc.field(TIMESTAMP, timestamp);
doc.save();
db.commit();
} catch (Exception e) {
if (db != null) {
db.rollback();
}
throw new SchedulePersistenceException(e);
} finally {
if (db != null) {
db.close();
}
}
releaseScheduledTask(scheduledTask);
}
@Override
@ -396,31 +360,7 @@ public class OrientDBPersistenceConnector extends
@Override
public void removeScheduledTask(ScheduledTask scheduledTask)
throws SchedulePersistenceException {
ODatabaseDocumentTx db = null;
try {
db = oPartitionedDatabasePool.acquire();
UUID uuid = scheduledTask.getUUID();
ODocument doc = getScheduledTaskDocument(db, uuid);
Long timestamp = doc.field(TIMESTAMP);
if (timestamp!=null && timestamp.compareTo(scheduledTask.getTimestamp())!=0) {
throw new SchedulePersistenceException(
"The ScheduledTask has been changed.");
}
doc.delete();
db.commit();
} catch (Exception e) {
if (db != null) {
db.rollback();
}
throw new SchedulePersistenceException(e);
} finally {
if (db != null) {
db.close();
}
}
removeScheduledTask(scheduledTask.getUUID());
}
@Override
@ -447,29 +387,6 @@ public class OrientDBPersistenceConnector extends
@Override
public void releaseScheduledTask(ScheduledTask scheduledTask)
throws SchedulePersistenceException {
ODatabaseDocumentTx db = null;
try {
db = oPartitionedDatabasePool.acquire();
UUID uuid = scheduledTask.getUUID();
ODocument doc = getScheduledTaskDocument(db, uuid);
Long timestamp = doc.field(TIMESTAMP);
if (timestamp!=null && timestamp.compareTo(scheduledTask.getTimestamp())!=0) {
throw new SchedulePersistenceException(
"The ScheduledTask has been changed.");
}
doc.removeField(RUN_ON);
doc.save();
} catch (Exception e) {
if (db != null) {
db.rollback();
}
throw new SchedulePersistenceException(e);
} finally {
if (db != null) {
db.close();
}
}
releaseScheduledTask(scheduledTask.getUUID());
}
}

View File

@ -30,8 +30,6 @@ public class ScheduledTask {
public static final String LAUNCH_PARAMETER = "launchParameter";
protected Long timestamp;
protected UUID uuid;
@JsonProperty(value=LAUNCH_PARAMETER)
protected LaunchParameter launchParameter;
@ -57,13 +55,6 @@ public class ScheduledTask {
this.runOn = runOn;
}
/**
* @return the timestamp
*/
public Long getTimestamp() {
return timestamp;
}
/**
* @return the uuid
*/