Class PostgreSQLPersistenceConnector
java.lang.Object
org.gcube.vremanagement.executor.plugin.PluginStateNotification
org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector
org.gcube.vremanagement.executor.persistence.postgresql.PostgreSQLPersistenceConnector
- All Implemented Interfaces:
ScheduledTaskPersistence
Keeps the scheduled tasks and the states of their executions in a PostgreSQL database, in two
tables the connector creates when they are missing. Each row holds the JSON of the object and the
columns the queries select on; every value of a query is a parameter. A caller reaches only the
rows of the Context of its request.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DataSourceprotected static final Stringprotected static final String[]protected static final Stringprotected static final StringFields inherited from class org.gcube.vremanagement.executor.plugin.PluginStateNotification
inputs -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoidaddScheduledTask(ScheduledTask scheduledTask) Create a Scheduled Task on persistencevoidclose()Close the connection to DBcountFinalStates(Long since) Counts the executions of the current Context that reached a final state, by that state: each execution of aPluginrecords its final state once.protected DataSourcecreateDataSource(SmartExecutorPersistenceConfiguration configuration) protected voidprotected static StringlongdeleteStatesBefore(long before) Deletes the states of the executions of the current Context recorded before a time, except the last state of each task, so that the state of every task can still be read.org.gcube.vremanagement.executor.plugin.PluginStateEvolutiongetPluginInstanceState(UUID uuid, Integer iterationNumber) Retrieve the status of the iterationNumber (passed as parameter) of a running/runPluginwhich is/was identified by the UUID passed as parametergetScheduledTask(UUID uuid) Return the Scheduled Task if any, null otherwiseprotected StringgetScheduledTaskJSON(Connection connection, UUID uuid) getScheduledTasks(Collection<String> plugins) Retrieve from the #SmartExecutorPersistenceConnector the orphaned Scheduled tasksvoidpluginStateEvolution(org.gcube.vremanagement.executor.plugin.PluginStateEvolution pluginStateEvolution, Exception exception) voidreleaseScheduledTask(UUID uuid) Release the Scheduled Task leaving it as orphan on persistencevoidreleaseScheduledTask(ScheduledTask scheduledTask) Release the Scheduled Task leaving it as orphan on persistencevoidremoveScheduledTask(UUID uuid) Remove from persistence the Scheduled Task.voidremoveScheduledTask(ScheduledTask scheduledTask) Remove from persistence the Scheduled Task.voidreserveScheduledTask(ScheduledTask scheduledTask) Reserve an orphan Scheduled tasks
-
Field Details
-
STATE_TABLE
- See Also:
-
TASK_TABLE
- See Also:
-
RUN_ON
- See Also:
-
SCHEMA
-
dataSource
-
-
Constructor Details
-
PostgreSQLPersistenceConnector
public PostgreSQLPersistenceConnector(SmartExecutorPersistenceConfiguration configuration) throws Exception - Throws:
Exception
-
-
Method Details
-
createDataSource
- Parameters:
configuration- the address and the credentials of the database- Returns:
- the source of the connections to the database
-
createSchema
- Throws:
SQLException
-
close
Description copied from class:SmartExecutorPersistenceConnectorClose the connection to DB- Specified by:
closein classSmartExecutorPersistenceConnector- Throws:
Exception- if fails
-
currentContext
-
getPluginInstanceState
public org.gcube.vremanagement.executor.plugin.PluginStateEvolution getPluginInstanceState(UUID uuid, Integer iterationNumber) throws org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundException, org.gcube.vremanagement.executor.exception.ExecutorException Description copied from class:SmartExecutorPersistenceConnectorRetrieve the status of the iterationNumber (passed as parameter) of a running/runPluginwhich is/was identified by the UUID passed as parameter- Specified by:
getPluginInstanceStatein classSmartExecutorPersistenceConnector- Parameters:
uuid- the execution identifier of the running/runPluginiterationNumber- the iterationNumber (null to get the last)- Returns:
- the actual/last
PluginStateof the Plugin - Throws:
org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundException- if the plugin instance is not foundorg.gcube.vremanagement.executor.exception.ExecutorException- if the operation fails
-
pluginStateEvolution
public void pluginStateEvolution(org.gcube.vremanagement.executor.plugin.PluginStateEvolution pluginStateEvolution, Exception exception) throws Exception - Specified by:
pluginStateEvolutionin classorg.gcube.vremanagement.executor.plugin.PluginStateNotification- Throws:
Exception
-
countFinalStates
public Map<org.gcube.vremanagement.executor.plugin.PluginState,Long> countFinalStates(Long since) throws org.gcube.vremanagement.executor.exception.ExecutorException Description copied from class:SmartExecutorPersistenceConnectorCounts the executions of the current Context that reached a final state, by that state: each execution of aPluginrecords its final state once.- Specified by:
countFinalStatesin classSmartExecutorPersistenceConnector- Parameters:
since- only the executions that reached their final state at this time or later, in milliseconds since the epoch;nullcounts all the executions in the database- Returns:
- the number of executions by final state, with every final state present
- Throws:
org.gcube.vremanagement.executor.exception.ExecutorException- if the operation fails
-
deleteStatesBefore
public long deleteStatesBefore(long before) throws org.gcube.vremanagement.executor.exception.ExecutorException Description copied from class:SmartExecutorPersistenceConnectorDeletes the states of the executions of the current Context recorded before a time, except the last state of each task, so that the state of every task can still be read.- Specified by:
deleteStatesBeforein classSmartExecutorPersistenceConnector- Parameters:
before- the time, in milliseconds since the epoch- Returns:
- the number of states deleted
- Throws:
org.gcube.vremanagement.executor.exception.ExecutorException- if the operation fails
-
addScheduledTask
Description copied from interface:ScheduledTaskPersistenceCreate a Scheduled Task on persistence- Parameters:
scheduledTask- to create on persistence- Throws:
SchedulePersistenceException- if fails
-
getScheduledTasks
public List<ScheduledTask> getScheduledTasks(Collection<String> plugins) throws SchedulePersistenceException Description copied from interface:ScheduledTaskPersistenceRetrieve from the #SmartExecutorPersistenceConnector the orphaned Scheduled tasks- Returns:
- the list of orphaned Scheduled
- Throws:
SchedulePersistenceException- if fails
-
getScheduledTaskJSON
protected String getScheduledTaskJSON(Connection connection, UUID uuid) throws SQLException, SchedulePersistenceException - Returns:
- the JSON of the task with the UUID, only in the Context of the caller: an UUID does not reach the tasks of other Contexts
- Throws:
SQLExceptionSchedulePersistenceException
-
getScheduledTask
Description copied from interface:ScheduledTaskPersistenceReturn the Scheduled Task if any, null otherwise- Parameters:
uuid- which identify the Scheduled Task- Returns:
- LaunchParameter of the Scheduled task if any, null otherwise
- Throws:
SchedulePersistenceException- if fails
-
reserveScheduledTask
Description copied from interface:ScheduledTaskPersistenceReserve an orphan Scheduled tasks- Throws:
SchedulePersistenceException- if fails
-
removeScheduledTask
Description copied from interface:ScheduledTaskPersistenceRemove from persistence the Scheduled Task.- Parameters:
uuid- the uuid which (will) identify the task on the SmartExecutor instance- Throws:
SchedulePersistenceException
-
removeScheduledTask
Description copied from interface:ScheduledTaskPersistenceRemove from persistence the Scheduled Task.- Throws:
SchedulePersistenceException
-
releaseScheduledTask
Description copied from interface:ScheduledTaskPersistenceRelease the Scheduled Task leaving it as orphan on persistence- Parameters:
uuid- the uuid which (will) identify the task on the SmartExecutor instance- Throws:
SchedulePersistenceException
-
releaseScheduledTask
Description copied from interface:ScheduledTaskPersistenceRelease the Scheduled Task leaving it as orphan on persistence- Throws:
SchedulePersistenceException
-