Skip to content

How to Run Decision Engine

Marco Mambelli edited this page Jun 10, 2021 · 31 revisions

Decision engine uses postgresql database back-end.

Install postgresql

Default postgresql installed on RH7 is 9.2 which is outdated. Suggest to remove it and install 11 instead :

  1. Remove old postgresql
yum erase -y postgresql*
  1. Install postgresql 11
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql11 postgresql11-server 
# optional, also: postgresql11-devel 
  1. Enable postgresql
systemctl enable postgresql-11
  1. Init db
 /usr/pgsql-11/bin/postgresql-11-setup initdb
  1. edit /var/lib/pgsql/11/data/pg_hba.conf like so:
[root@fermicloud371 ~]# diff  /var/lib/pgsql/11/data/pg_hba.conf~ /var/lib/pgsql/11/data/pg_hba.conf 
80c80
< local   all             all                                     peer
---
> local   all             all                                     trust
82c82
< host    all             all             127.0.0.1/32            ident
---
> host    all             all             127.0.0.1/32            trust
84c84
< host    all             all             ::1/128                 ident
---
> host    all             all             ::1/128                 trust

(that is setting authentication method is trust)

  1. start database
systemctl start postgresql-11
  1. create decisionengine
createdb -U postgres decisionengine
  1. create database schema
psql -U postgres decisionengine -f <full path to>/decisionengine/src/decisionengine/framework/dataspace/datasources/postgresql.sql
  1. configure database connection. Check
/etc/decisionengine/decision_engine.jsonnet

for above steps it would look like this (default decision_engine.jsonnet placed by the decisionengine RPM):

cat decision_engine.jsonnet
{
    "logger": {
	"log_file": "/var/log/decisionengine/decision_engine_log",
	"max_file_size": 200000000,
	"max_backup_count": 6,
	"log_level": "DEBUG",
        "global_channel_log_level": "DEBUG"
	},

    "channels": "/etc/decisionengine/config.d",


    "dataspace": {
	"reaper_start_delay_seconds": 1818,
	"retention_interval_in_days": 365,
	"datasource": {
	    "module": "decisionengine.framework.dataspace.datasources.postgresql",
	    "name": "Postgresql",
	    "config": {
		"user": "postgres",
		"blocking": true,
		"host": "localhost",
		"port": 5432,
		"database": "decisionengine",
		"maxconnections": 100,
		"maxcached": 10
		}
	    }
	}
}

To use the database you have to add it to the environment:

export PG_VERSION=11
export PATH="/usr/pgsql-${PG_VERSION}/bin:~/.local/bin:$PATH"

Install decision engine

These instructions are to be executed by root for a system installation.

  1. Make sure that required yum repos and some required packages (python3, gcc, ...) are there and up to date:
yum install -y http://ftp.scientificlinux.org/linux/scientific/7x/repos/x86_64/yum-conf-softwarecollections-2.0-1.el7.noarch.rpm
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# gcc, swig and make needed for dependencies (jsonnet)
yum -y install python3 python3-pip python3-setuptools python3-wheel \
    gcc gcc-c++ make \
    python3-devel swig openssl-devel git rpm-build
python3 -m pip install --upgrade --prefix=/usr pip
python3 -m pip install --upgrade --prefix=/usr setuptools wheel setuptools-scm[toml]
  1. Setup the decision engine yum repositories
wget -O /etc/yum.repos.d/ssi-hepcloud.repo http://ssi-rpm.fnal.gov/hep/ssi-hepcloud.repo
wget -O /etc/yum.repos.d/ssi-hepcloud-dev.repo http://ssi-rpm.fnal.gov/hep/ssi-hepcloud-dev.repo
  1. Install the decision engine (add --enablerepo=ssi-hepcloud-dev for the latest development version)
yum install decisionengine
yum install decisionengine-standard-library
  1. Install the required Python packages (these are taken from setup.py)
# from decisionengine
python3 -m pip install jsonnet tabulate toposort
python3 -m pip install wheel DBUtils sqlalchemy
python3 -m pip install pandas==1.1.5 numpy==1.19.5
python3 -m pip install "psycopg2-binary >= 2.8.6; platform_python_implementation == 'CPython'"
python3 -m pip install "psycopg2cffi >= 2.9.0; platform_python_implementation == 'PyPy'"
# from decisionengine_modules
python3 -m pip install packaging
python3 -m pip install boto boto3 google_auth google-api-python-client
python3 -m pip install gcs-oauth2-boto-plugin
python3 -m pip install htcondor
# This is not in pypi
python3 -m pip install https://test-files.pythonhosted.org/packages/f4/a5/17a14b4ef85bc412a0ddb771771de3f562430328b0d83da6091a4131bb26/bill_calculator_hep_mapsacosta-0.0.10-py3-none-any.whl

decisionengine --help should print the help message

Start decision engine

systemctl start decisionengine

For versions lower than 1.6 it is

systemctl start decision-engine

Add channels to decision engine

Decision engine decision cycles happen in channels. You can add channels by adding configuration files in /etc/decisionengine/config.d/ and restarting the decision engine.

Here a simple test channel configuration. This test channel is using some NOP classes currently defined in the unit tests and not distributed. First, you need to copy these classes from the Git repo:

cd YOUR_decisionengine_REPO
cp -r src/decisionengine/framework/tests /lib/python3.6/site-packages/decisionengine/framework/

Then, add the channel by placing this in /etc/decisionengine/config.d/test_channel.jsonnet:

{
  sources: {
    source1: {
      module: "decisionengine.framework.tests.SourceNOP",
      parameters: {},
      schedule: 1,
    }
  },
  transforms: {
    transform1: {
      module: "decisionengine.framework.tests.TransformNOP",
      parameters: {},
      schedule: 1
    }
  },
  logicengines: {
    le1: {
      module: "decisionengine.framework.logicengine.LogicEngine",
      parameters: {
        facts: {
          pass_all: "True"
        },
        rules: {
          r1: {
            expression: 'pass_all',
            actions: ['publisher1']
          }
        }
      }
    }
  },
  publishers: {
    publisher1: {
      module: "decisionengine.framework.tests.PublisherNOP",
      parameters: {}
    }
  }
}

Restart decision engine to start the new channel

systemctl restart decisionengine

# The service name is decision-engine for versions older than 1.6

de-client --status should sho the active test channel