-
Notifications
You must be signed in to change notification settings - Fork 159
Ganga Database
This document will detail the approach and changes introduced by the database support in Ganga. The new features introduced with database support are:
- Database Backend for Ganga CLI.
- Database Backend for future expansion of Ganga for Centralized Deployment.
- Using a controller from container_controllers.py a database instance is started.
-
GangaRepositoryDatabase._read_master_cache()
loadsindex
information of themaster
jobs at once. - Upon request for a
job
,GangaRepositoryDatabase.load()
is called to load thejobjson
from database. - Upon quiting,
GangaRepositoryDatabase.index_write()
saves the updatedindexes
for all the jobs.
DStreamer.py: Json Object Loader and Dumper functions:
Class used by GangaObjects
for to_json()
method. Implementation of to_json()
method is of 3 types:
-
Objects.py
: This is the base implementation of theto_json
function for allGangaObjects
. Any object can have the either of 3objects
orattributes
attached to it, following is the way to convert them tojson
:- If
simple attribute
(eg,j.name = "foo"
). The conversion is as simple as adding thekey:value
pair in to the object dict:{"name": "foo"}
. - if
component attribute
(GangaObject
like):-
GangaList
: Since aGangaList
can have moreGangaList
s in it.GangaLists
have a seperate implementation of the this methodto_json()
. So when aGangaList
is found, the case comes down to:{"attribute_name": attribute_value.to_json()}
. -
GangaObject
which is not aGangaList
: Convertion of aGangaObject
tojson
makes use of theJsonDumper
'sobject_to_json
.
-
- If
-
Job.py
: Just callsto_json()
method of the its attributes. -
GangaList.py
: Iterates through all the elements of theGangaList
and returns its items. If any item is aGangaList
, it recurses and gets all the elements from that item.
Class used for loading GangaObject
s from json
s obtained from database retrievals. For each GangaObject
type found in the json
representation, an Empty Object of the type is created. All simple attributes
are assigned to the empty object and incase of component attributes
Empty Objects for those are created in recursion and assigned to their owner/master/parent.
-
object_to_database()
:- Converts the any
GangaObject
to correspondingjson
by calling the internalto_json()
method (for more information on the method check: TBA). - The
json
representation is updated in the database, if already exists else inserted into the database. - Raises
DatabaseError
, when the insertion fails.
- Converts the any
-
object_from_database()
:- Searches for the data in the database using the information from
_filter
param. - If the object exists in the database, the
json
representation is converted in to aGangaObject
If object is not found raisesDatabaseError
.
- Searches for the data in the database using the information from
-
index_to_database()
:- Save
cache
/index
information ofjobs
into the database. - Can store single or multiple files at once.
- If insertion fails or returns empty set,
DatabaseError
is raised.
- Save
-
index_from_database()
:- Retrieves
index
information for the object identified by the_filter
param. - If the retrieval set is empty, raises
DatabaseError
.
- Retrieves
container_controllers.py: Container/Database Service Controllers:
This file consists of implementations for 4 database controllers, where each controller is responsible for starting/shutting down the database service (except in the case of a native db
):
- Native: The database is installed locally. In this case, the controller is a blank implementation as in most cases
ganga
would not have the rights to start/close the database service running on the system. - Docker
- uDocker
- Singularity
Each controller implements two actions:
-
start
: The action responsible for starting of the container. Any controller will implement this action in the following steps:-
Check if the container matched with required specs
`name: getConfig('DatabaseConfigurations')['containerName']`
exists in the container service registry.
1.1 If does, start the container using the required command.
1.2 If it does not, create the container using the required command.
-
-
quit
: The action responsible for stopping of the container. Any controller will implement this action in the following steps:-
Check if the container is still running
1.1 If running, shutdown the container (and also delete the container if required)
1.2 if not running, skip.
-