Class AExperimenterSQLHandle
- java.lang.Object
-
- ai.libs.jaicore.experiments.databasehandle.AExperimenterSQLHandle
-
- All Implemented Interfaces:
IExperimentDatabaseHandle
,org.api4.java.common.control.ILoggingCustomizable
- Direct Known Subclasses:
ExperimenterMySQLHandle
,ExperimenterRestSQLHandle
public abstract class AExperimenterSQLHandle extends java.lang.Object implements IExperimentDatabaseHandle, org.api4.java.common.control.ILoggingCustomizable
-
-
Field Summary
Fields Modifier and Type Field Description protected ai.libs.jaicore.db.IDatabaseAdapter
adapter
static java.lang.String
FIELD_EXECUTOR
static java.lang.String
FIELD_HOST
static java.lang.String
FIELD_NUMCPUS
protected java.lang.String
tablename
-
Constructor Summary
Constructors Modifier Constructor Description protected
AExperimenterSQLHandle(ai.libs.jaicore.db.IDatabaseAdapter adapter, java.lang.String tablename)
protected
AExperimenterSQLHandle(ai.libs.jaicore.db.IDatabaseConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
assertSetup()
Checks if this instance has been configured.ExperimentDBEntry
createAndGetExperiment(Experiment experiment)
Creates a new experiment entry and returns it.ExperimentDBEntry
createAndGetExperiment(java.util.Map<java.lang.String,java.lang.String> values)
java.util.List<ExperimentDBEntry>
createOrGetExperiments(java.util.List<Experiment> experiments)
Creates or fetches the experiment entries from the database.void
deleteDatabase()
Deletes everything known to the experiment database.void
deleteExperiment(ExperimentDBEntry exp)
Deletes an experiment from the databasevoid
finishExperiment(ExperimentDBEntry expEntry)
Signals that an experiment has been finished successfully.void
finishExperiment(ExperimentDBEntry expEntry, java.lang.Throwable error)
Signals that an experiment has failed with an exception.java.util.List<ExperimentDBEntry>
getAllExperiments()
Returns a list of all experiments contained in the databasejava.util.List<ExperimentDBEntry>
getConductedExperiments()
Returns a list of all experiments contained in the database marked as being conducted.java.util.List<ExperimentDBEntry>
getConductedExperiments(java.util.Map<java.lang.String,java.lang.Object> fieldFilter)
Returns a list of all experiments contained in the database marked as being conducted and with the attribute values specified as in the map.java.util.Collection<java.lang.String>
getConsideredValuesForKey(java.lang.String key)
protected java.lang.String
getDatabaseFieldnameForConfigEntry(java.lang.String configKey)
protected java.util.List<ExperimentDBEntry>
getExperimentsForSQLQuery(java.lang.String sql)
ExperimentDBEntry
getExperimentWithId(int id)
Gets the experiment with the given id.java.util.List<ExperimentDBEntry>
getFailedExperiments()
Returns a list of all experiments contained in the database marked as being conducted and with an exception.java.util.List<ExperimentDBEntry>
getFailedExperiments(java.util.Map<java.lang.String,java.lang.Object> fieldFilter)
Returns a list of all experiments contained in the database marked as being conducted and with an exception and with the attribute values specified as in the map.java.lang.String
getLoggerName()
int
getNumberOfAllExperiments()
Returns the number of all experiments contained in the databasejava.util.List<ExperimentDBEntry>
getOpenExperiments()
Returns a list of all experiments contained in the database that have not been started yet.java.util.List<ExperimentDBEntry>
getRandomOpenExperiments(int limit)
Returns a list of all experiments contained in the database that have not been started yet.java.util.List<ExperimentDBEntry>
getRunningExperiments()
Returns a list of all experiments that are currently being conducted.protected java.lang.String
getSetupCreateTableQuery()
protected java.lang.String
getSQLFromTable()
protected java.lang.String
getSQLPrefixForKeySelectQuery()
protected java.lang.String
getSQLPrefixForSelectQuery()
boolean
hasExperimentStarted(ExperimentDBEntry exp)
Checks if the given experiment has been started already.void
setLoggerName(java.lang.String name)
void
setup(IExperimentSetConfig config)
Prepares everything so that upcoming calls for create and update will be managed according to the specified configuration.void
startExperiment(ExperimentDBEntry exp, java.lang.String executorInfo)
Starts the given experimentjava.util.Optional<ExperimentDBEntry>
startNextExperiment(java.lang.String executorInfo)
Picks an unstarted experiment, marks it as started and returns it.void
updateExperiment(ExperimentDBEntry exp, java.util.Map<java.lang.String,? extends java.lang.Object> values)
Updates non-keyfield values of the experiment.boolean
updateExperimentConditionally(ExperimentDBEntry exp, java.util.Map<java.lang.String,java.lang.String> conditions, java.util.Map<java.lang.String,? extends java.lang.Object> values)
-
-
-
Field Detail
-
FIELD_HOST
public static final java.lang.String FIELD_HOST
- See Also:
- Constant Field Values
-
FIELD_EXECUTOR
public static final java.lang.String FIELD_EXECUTOR
- See Also:
- Constant Field Values
-
FIELD_NUMCPUS
public static final java.lang.String FIELD_NUMCPUS
- See Also:
- Constant Field Values
-
adapter
protected final ai.libs.jaicore.db.IDatabaseAdapter adapter
-
tablename
protected final java.lang.String tablename
-
-
Method Detail
-
getSetupCreateTableQuery
protected java.lang.String getSetupCreateTableQuery()
-
assertSetup
protected void assertSetup()
Checks if this instance has been configured. That is it throws an exception iff the setup method hasn't been successfully called yet.- Throws:
java.lang.IllegalStateException
- thrown if setup wasn't called.
-
setup
public void setup(IExperimentSetConfig config) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Prepares everything so that upcoming calls for create and update will be managed according to the specified configuration.- Specified by:
setup
in interfaceIExperimentDatabaseHandle
- Parameters:
config
- Description of the experiment setup- Throws:
ExperimentDBInteractionFailedException
-
getSQLPrefixForKeySelectQuery
protected java.lang.String getSQLPrefixForKeySelectQuery()
-
getSQLFromTable
protected java.lang.String getSQLFromTable()
-
getSQLPrefixForSelectQuery
protected java.lang.String getSQLPrefixForSelectQuery()
-
getConsideredValuesForKey
public java.util.Collection<java.lang.String> getConsideredValuesForKey(java.lang.String key) throws ExperimentDBInteractionFailedException
- Specified by:
getConsideredValuesForKey
in interfaceIExperimentDatabaseHandle
- Parameters:
key
- The key attribute- Throws:
ExperimentDBInteractionFailedException
-
getNumberOfAllExperiments
public int getNumberOfAllExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns the number of all experiments contained in the database- Specified by:
getNumberOfAllExperiments
in interfaceIExperimentDatabaseHandle
- Throws:
ExperimentDBInteractionFailedException
-
getAllExperiments
public java.util.List<ExperimentDBEntry> getAllExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns a list of all experiments contained in the database- Specified by:
getAllExperiments
in interfaceIExperimentDatabaseHandle
- Returns:
- List of all experiments
- Throws:
ExperimentDBInteractionFailedException
-
getOpenExperiments
public java.util.List<ExperimentDBEntry> getOpenExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns a list of all experiments contained in the database that have not been started yet.- Specified by:
getOpenExperiments
in interfaceIExperimentDatabaseHandle
- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
getRandomOpenExperiments
public java.util.List<ExperimentDBEntry> getRandomOpenExperiments(int limit) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns a list of all experiments contained in the database that have not been started yet.- Specified by:
getRandomOpenExperiments
in interfaceIExperimentDatabaseHandle
- Parameters:
limit
- Maximum number of open experiments that should be returned- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
startNextExperiment
public java.util.Optional<ExperimentDBEntry> startNextExperiment(java.lang.String executorInfo) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Picks an unstarted experiment, marks it as started and returns it. These operations happen atomically, so if a experiment is returned, then ownership on it can be assumed. If no experiment is returned, i.e. an empty optional, then no experiment is remaining.- Specified by:
startNextExperiment
in interfaceIExperimentDatabaseHandle
- Parameters:
executorInfo
- The identifier of the executor who evaluates this experiment; important for tracking of experiments in compute centers- Returns:
- A started experiment if there are any left, or else an empty optional.
- Throws:
ExperimentDBInteractionFailedException
-
getRunningExperiments
public java.util.List<ExperimentDBEntry> getRunningExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns a list of all experiments that are currently being conducted.- Specified by:
getRunningExperiments
in interfaceIExperimentDatabaseHandle
- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
getConductedExperiments
public java.util.List<ExperimentDBEntry> getConductedExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns a list of all experiments contained in the database marked as being conducted.- Specified by:
getConductedExperiments
in interfaceIExperimentDatabaseHandle
- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
getConductedExperiments
public java.util.List<ExperimentDBEntry> getConductedExperiments(java.util.Map<java.lang.String,java.lang.Object> fieldFilter) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns a list of all experiments contained in the database marked as being conducted and with the attribute values specified as in the map.- Specified by:
getConductedExperiments
in interfaceIExperimentDatabaseHandle
- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
getFailedExperiments
public java.util.List<ExperimentDBEntry> getFailedExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns a list of all experiments contained in the database marked as being conducted and with an exception.- Specified by:
getFailedExperiments
in interfaceIExperimentDatabaseHandle
- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
getFailedExperiments
public java.util.List<ExperimentDBEntry> getFailedExperiments(java.util.Map<java.lang.String,java.lang.Object> fieldFilter) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Returns a list of all experiments contained in the database marked as being conducted and with an exception and with the attribute values specified as in the map.- Specified by:
getFailedExperiments
in interfaceIExperimentDatabaseHandle
- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
getExperimentsForSQLQuery
protected java.util.List<ExperimentDBEntry> getExperimentsForSQLQuery(java.lang.String sql) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
createAndGetExperiment
public ExperimentDBEntry createAndGetExperiment(java.util.Map<java.lang.String,java.lang.String> values) throws ExperimentDBInteractionFailedException, ExperimentAlreadyExistsInDatabaseException
-
createAndGetExperiment
public ExperimentDBEntry createAndGetExperiment(Experiment experiment) throws ExperimentDBInteractionFailedException, ExperimentAlreadyExistsInDatabaseException
Description copied from interface:IExperimentDatabaseHandle
Creates a new experiment entry and returns it.- Specified by:
createAndGetExperiment
in interfaceIExperimentDatabaseHandle
- Returns:
- The id of the created experiment
- Throws:
ExperimentDBInteractionFailedException
ExperimentAlreadyExistsInDatabaseException
-
createOrGetExperiments
public java.util.List<ExperimentDBEntry> createOrGetExperiments(java.util.List<Experiment> experiments) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Creates or fetches the experiment entries from the database. The "or" is exclusive, i.e. that if any entry exist it won't be created. In comparison to other createAndGet methods, this doesn't throw a ExperimentAlreadyExistsInDatabaseException.- Specified by:
createOrGetExperiments
in interfaceIExperimentDatabaseHandle
- Parameters:
experiments
- the experiments to be created- Returns:
- The id of the created experiment
- Throws:
ExperimentDBInteractionFailedException
-
updateExperiment
public void updateExperiment(ExperimentDBEntry exp, java.util.Map<java.lang.String,? extends java.lang.Object> values) throws ExperimentUpdateFailedException
Description copied from interface:IExperimentDatabaseHandle
Updates non-keyfield values of the experiment.- Specified by:
updateExperiment
in interfaceIExperimentDatabaseHandle
- Parameters:
exp
- The experiment entry in the databasevalues
- A key-value store where keys are names of result fields. The values will be associated to each key in the database.- Throws:
ExperimentUpdateFailedException
-
updateExperimentConditionally
public boolean updateExperimentConditionally(ExperimentDBEntry exp, java.util.Map<java.lang.String,java.lang.String> conditions, java.util.Map<java.lang.String,? extends java.lang.Object> values) throws ExperimentUpdateFailedException
- Specified by:
updateExperimentConditionally
in interfaceIExperimentDatabaseHandle
- Throws:
ExperimentUpdateFailedException
-
finishExperiment
public void finishExperiment(ExperimentDBEntry expEntry, java.lang.Throwable error) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Signals that an experiment has failed with an exception. The timestamp and the exception will be stored with the experiment.- Specified by:
finishExperiment
in interfaceIExperimentDatabaseHandle
- Parameters:
expEntry
- Experiment to be marked as finishederror
- If not null, the experiment- Throws:
ExperimentDBInteractionFailedException
-
finishExperiment
public void finishExperiment(ExperimentDBEntry expEntry) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Signals that an experiment has been finished successfully. A corresponding timestamp will be attached to the experiment entry.- Specified by:
finishExperiment
in interfaceIExperimentDatabaseHandle
- Throws:
ExperimentDBInteractionFailedException
-
getDatabaseFieldnameForConfigEntry
protected java.lang.String getDatabaseFieldnameForConfigEntry(java.lang.String configKey)
-
deleteExperiment
public void deleteExperiment(ExperimentDBEntry exp) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Deletes an experiment from the database- Specified by:
deleteExperiment
in interfaceIExperimentDatabaseHandle
- Parameters:
exp
- Experiment to be deleted- Throws:
ExperimentDBInteractionFailedException
-
deleteDatabase
public void deleteDatabase() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Deletes everything known to the experiment database. Note that database is understood as an abstract term. In a true database, this could just be a table.- Specified by:
deleteDatabase
in interfaceIExperimentDatabaseHandle
- Throws:
ExperimentDBInteractionFailedException
-
hasExperimentStarted
public boolean hasExperimentStarted(ExperimentDBEntry exp) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Checks if the given experiment has been started already.- Specified by:
hasExperimentStarted
in interfaceIExperimentDatabaseHandle
- Parameters:
exp
- Experiment used for the query.- Returns:
- true iff experiment has been marked as started.
- Throws:
ExperimentDBInteractionFailedException
-
startExperiment
public void startExperiment(ExperimentDBEntry exp, java.lang.String executorInfo) throws ExperimentUpdateFailedException, ExperimentAlreadyStartedException
Description copied from interface:IExperimentDatabaseHandle
Starts the given experiment- Specified by:
startExperiment
in interfaceIExperimentDatabaseHandle
- Parameters:
exp
- The experiment that is started on the current machineexecutorInfo
- The identifier of the executor who evaluates this experiment; important for tracking of experiments in compute centers- Throws:
ExperimentUpdateFailedException
ExperimentAlreadyStartedException
-
getLoggerName
public java.lang.String getLoggerName()
- Specified by:
getLoggerName
in interfaceorg.api4.java.common.control.ILoggingCustomizable
-
setLoggerName
public void setLoggerName(java.lang.String name)
- Specified by:
setLoggerName
in interfaceorg.api4.java.common.control.ILoggingCustomizable
-
getExperimentWithId
public ExperimentDBEntry getExperimentWithId(int id) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandle
Gets the experiment with the given id.- Specified by:
getExperimentWithId
in interfaceIExperimentDatabaseHandle
- Returns:
- Throws:
ExperimentDBInteractionFailedException
-
-