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.IDatabaseAdapteradapterstatic java.lang.StringFIELD_EXECUTORstatic java.lang.StringFIELD_HOSTstatic java.lang.StringFIELD_NUMCPUSprotected java.lang.Stringtablename
-
Constructor Summary
Constructors Modifier Constructor Description protectedAExperimenterSQLHandle(ai.libs.jaicore.db.IDatabaseAdapter adapter, java.lang.String tablename)protectedAExperimenterSQLHandle(ai.libs.jaicore.db.IDatabaseConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertSetup()Checks if this instance has been configured.ExperimentDBEntrycreateAndGetExperiment(Experiment experiment)Creates a new experiment entry and returns it.ExperimentDBEntrycreateAndGetExperiment(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.voiddeleteDatabase()Deletes everything known to the experiment database.voiddeleteExperiment(ExperimentDBEntry exp)Deletes an experiment from the databasevoidfinishExperiment(ExperimentDBEntry expEntry)Signals that an experiment has been finished successfully.voidfinishExperiment(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.StringgetDatabaseFieldnameForConfigEntry(java.lang.String configKey)protected java.util.List<ExperimentDBEntry>getExperimentsForSQLQuery(java.lang.String sql)ExperimentDBEntrygetExperimentWithId(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.StringgetLoggerName()intgetNumberOfAllExperiments()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.StringgetSetupCreateTableQuery()protected java.lang.StringgetSQLFromTable()protected java.lang.StringgetSQLPrefixForKeySelectQuery()protected java.lang.StringgetSQLPrefixForSelectQuery()booleanhasExperimentStarted(ExperimentDBEntry exp)Checks if the given experiment has been started already.voidsetLoggerName(java.lang.String name)voidsetup(IExperimentSetConfig config)Prepares everything so that upcoming calls for create and update will be managed according to the specified configuration.voidstartExperiment(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.voidupdateExperiment(ExperimentDBEntry exp, java.util.Map<java.lang.String,? extends java.lang.Object> values)Updates non-keyfield values of the experiment.booleanupdateExperimentConditionally(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:IExperimentDatabaseHandlePrepares everything so that upcoming calls for create and update will be managed according to the specified configuration.- Specified by:
setupin 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:
getConsideredValuesForKeyin interfaceIExperimentDatabaseHandle- Parameters:
key- The key attribute- Throws:
ExperimentDBInteractionFailedException
-
getNumberOfAllExperiments
public int getNumberOfAllExperiments() throws ExperimentDBInteractionFailedExceptionDescription copied from interface:IExperimentDatabaseHandleReturns the number of all experiments contained in the database- Specified by:
getNumberOfAllExperimentsin interfaceIExperimentDatabaseHandle- Throws:
ExperimentDBInteractionFailedException
-
getAllExperiments
public java.util.List<ExperimentDBEntry> getAllExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandleReturns a list of all experiments contained in the database- Specified by:
getAllExperimentsin interfaceIExperimentDatabaseHandle- Returns:
- List of all experiments
- Throws:
ExperimentDBInteractionFailedException
-
getOpenExperiments
public java.util.List<ExperimentDBEntry> getOpenExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandleReturns a list of all experiments contained in the database that have not been started yet.- Specified by:
getOpenExperimentsin 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:IExperimentDatabaseHandleReturns a list of all experiments contained in the database that have not been started yet.- Specified by:
getRandomOpenExperimentsin 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:IExperimentDatabaseHandlePicks 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:
startNextExperimentin 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:IExperimentDatabaseHandleReturns a list of all experiments that are currently being conducted.- Specified by:
getRunningExperimentsin interfaceIExperimentDatabaseHandle- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
getConductedExperiments
public java.util.List<ExperimentDBEntry> getConductedExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandleReturns a list of all experiments contained in the database marked as being conducted.- Specified by:
getConductedExperimentsin 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:IExperimentDatabaseHandleReturns 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:
getConductedExperimentsin interfaceIExperimentDatabaseHandle- Returns:
- List of all experiments conducted so far
- Throws:
ExperimentDBInteractionFailedException
-
getFailedExperiments
public java.util.List<ExperimentDBEntry> getFailedExperiments() throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandleReturns a list of all experiments contained in the database marked as being conducted and with an exception.- Specified by:
getFailedExperimentsin 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:IExperimentDatabaseHandleReturns 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:
getFailedExperimentsin 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:IExperimentDatabaseHandleCreates a new experiment entry and returns it.- Specified by:
createAndGetExperimentin interfaceIExperimentDatabaseHandle- Returns:
- The id of the created experiment
- Throws:
ExperimentDBInteractionFailedExceptionExperimentAlreadyExistsInDatabaseException
-
createOrGetExperiments
public java.util.List<ExperimentDBEntry> createOrGetExperiments(java.util.List<Experiment> experiments) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandleCreates 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:
createOrGetExperimentsin 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:IExperimentDatabaseHandleUpdates non-keyfield values of the experiment.- Specified by:
updateExperimentin 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:
updateExperimentConditionallyin interfaceIExperimentDatabaseHandle- Throws:
ExperimentUpdateFailedException
-
finishExperiment
public void finishExperiment(ExperimentDBEntry expEntry, java.lang.Throwable error) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandleSignals that an experiment has failed with an exception. The timestamp and the exception will be stored with the experiment.- Specified by:
finishExperimentin 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:IExperimentDatabaseHandleSignals that an experiment has been finished successfully. A corresponding timestamp will be attached to the experiment entry.- Specified by:
finishExperimentin 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:IExperimentDatabaseHandleDeletes an experiment from the database- Specified by:
deleteExperimentin interfaceIExperimentDatabaseHandle- Parameters:
exp- Experiment to be deleted- Throws:
ExperimentDBInteractionFailedException
-
deleteDatabase
public void deleteDatabase() throws ExperimentDBInteractionFailedExceptionDescription copied from interface:IExperimentDatabaseHandleDeletes 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:
deleteDatabasein interfaceIExperimentDatabaseHandle- Throws:
ExperimentDBInteractionFailedException
-
hasExperimentStarted
public boolean hasExperimentStarted(ExperimentDBEntry exp) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandleChecks if the given experiment has been started already.- Specified by:
hasExperimentStartedin 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:IExperimentDatabaseHandleStarts the given experiment- Specified by:
startExperimentin 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:
ExperimentUpdateFailedExceptionExperimentAlreadyStartedException
-
getLoggerName
public java.lang.String getLoggerName()
- Specified by:
getLoggerNamein interfaceorg.api4.java.common.control.ILoggingCustomizable
-
setLoggerName
public void setLoggerName(java.lang.String name)
- Specified by:
setLoggerNamein interfaceorg.api4.java.common.control.ILoggingCustomizable
-
getExperimentWithId
public ExperimentDBEntry getExperimentWithId(int id) throws ExperimentDBInteractionFailedException
Description copied from interface:IExperimentDatabaseHandleGets the experiment with the given id.- Specified by:
getExperimentWithIdin interfaceIExperimentDatabaseHandle- Returns:
- Throws:
ExperimentDBInteractionFailedException
-
-