Package: skasip-config-db
# SKA SDP SIP Configuration Database library## IntroductionThis package contains a library providing specialised functions forinterfacing with data objects in the SKA SDP SIP Execution ControlConfiguration Database service. The Configuration Database is a backingservice for use by SKA SDP SIP Execution Control and Tango Control components.For a description of the Data Model used by this library see Sections 7.4.4and 7.5.6 of the SIP Report.This library provides modules for each of the data objects stored withinthe EC configuration database. These are built on top of a simple low-levelwrapper to the [Python Redis API](https://redis-py.readthedocs.io/en/latest/),which handles connections to the database and abstraction from the PythonRedis API.## InstallationThis library can be installed using `pip` with the following command:```bashpip install -U skasip-config-db```## UsageExample usage:```python# coding: utf-8"""Example usage."""from sip_config_db.scheduling import Subarray, SchedulingBlockInstancefrom sip_config_db.states import SDPStatefrom sip_config_db.utils.generate_sbi_config import generate_sbi_configsdp_state = SDPState()print(sdp_state.current_state)subarray = Subarray(0)subarray.activate()print(subarray.active)sbi_config = generate_sbi_config(register_workflows=True)sbi = SchedulingBlockInstance.from_config(sbi_config)print(sbi.id)```## Utility ScriptsThe package installs a number of utility scripts, described below:#### Initialise the database.`skasip_config_db_init [--data-path=PATH]`Can be used to initialise the configuration database. The optional`--data-path=PATH` argument, can be used to defined a custompath containing the initial set of SDP services and workflows used toinitialise the database. If specifying `--data-path`, and the specified `PATH`does not exist a copy of the default data pat will be created at the specifiedpath.#### Register workflowsRegister workflows from the specified workflow path.```bashskasip_config_db_register_workflows [workflow path]```#### Add an SBI to the databaseAdds an SBI to the database.```bashskasip_config_db_add_sbi [--subarray N] [--activate] [--help]```#### Generate an SBI JSON configurationGenerate an SBI JSON configuration.```bashskasip_config_db_sbi_json```#### Update the current stateUpdates the current state of SDP or a specified service.```bashskasip_config_db_update_state [--service SUBSYSTEM.NAME.VERSION] [--help] new_state```#### List workflow definitionsList known workflow definitions.```bashskasip_config_db_workflow_definitions```## Running testsUnit tests are run automatically the[SIP CI/CD service](https://travis-ci.com/SKA-ScienceDataProcessor/integration-prototype).It is also possible to run them manually with the following commands from theroot SIP:***Note**: a Redis db container must be started first in order for most ofthese tests to pass (See below)*```bashvirtualenv -p python3 venvsource venv/bin/activatepip install -r testing_requirements.txtpip install -r sip/execution_control/configuration_db/requirements.txtpython3 -m pytest --pylint --codestyle --docstyle -s -v \--pylint-rcfile=.pylintrc --rootdir=. \sip/execution_control/configuration_db```## Starting Configuration Database Redis containers.To start Docker containers for a Redis Db instance (with a persistent volume)as well as a [Redis Commander](https://github.com/joeferner/redis-commander)instance (useful for debugging) issue the following command:```bashdocker stack deploy -c docker-compose.yml [stack name]```Once finished, to clean up.```bashdocker stack rm [stack name]```It is also possible to run redis server natively (without Docker) with:```bashredis-server```