Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store interactive tool sessions in PostgreSQL database "gxitproxy" #1251

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kysrpex
Copy link
Contributor

@kysrpex kysrpex commented Jul 4, 2024

Use PostgreSQL instead of SQLite to store interactive tool sessions. Requires galaxyproject/galaxy#18481, galaxyproject/gx-it-proxy#21. Closes usegalaxy-eu/issues#422.

Before merging, pay attention to the following.

Migration procedure:

  1. On Postgres, create the database gxitproxy and set the galaxy user as its owner. Create also the table gxitproxy on beforehand (gx-it-proxy refuses to run without it). For greater details you may have a look at the updated GTN training.
  2. Copy the migration script below to sn06.
  3. Use inotifywait to watch "/opt/galaxy/mutable-config/interactivetools_map.sqlite" and run the migration script on every modification to the file. This will guarantee that all entries present in the SQLite database will be also present in Postgres. psql will complain about rows that already exist in the target table, but despite the complaint it will copy the rows which still are not in the target table.
  4. Run Jenkins so that the handlers are restarted. Ensure Gunicorn handlers are restarted as well.
  5. Once everything is restarted, Galaxy will not be using the SQLite mapping anymore. Deletions are not synced by the migration script, therefore, there may be leftover rows in Postgres. Optionally (they do not cause any issues), you may delete them as follows: query the PostgreSQL table "gxitproxy" to get all values of the "key" column. Decode them (for example using gxadmin). The resulting values are ids for interactive tool entry points (the id column on table "interactivetool_entry_point"). Filter this table by those values and do an inner join with the table "job" on interactivetool_entry_point.job_id=job.id. Filter the result by state different than "running". Encode all ids for interactive tool entry points and delete them from the gxitproxy table.

Migration script:

#!/bin/bash

set -e

# Set variables
SQLITE_DB="/opt/galaxy/mutable-config/interactivetools_map.sqlite"
SQLITE_TABLE="gxitproxy"
PG_DB="gxitproxy"
# PG_USER="your_pg_user"
# PG_PASSWORD="your_pg_password"
# PG_HOST="your_pg_host"
# PG_PORT="your_pg_port"
PG_TABLE="gxitproxy"

# Function to export SQLite data to a CSV file
export_sqlite_to_csv() {
    sqlite3 -header -csv "$SQLITE_DB" "SELECT * FROM $SQLITE_TABLE;" > /tmp/interactivetools_map.csv
    chmod 660 /tmp/interactivetools_map.csv;
}

# Function to import CSV data to PostgreSQL
import_csv_to_postgresql() {
    # export PGPASSWORD="$PG_PASSWORD"
    # psql -h "$PG_HOST" -p "$PG_PORT" -U "$PG_USER" -d "$PG_DB" -c "\copy $PG_TABLE FROM 'data.csv' CSV HEADER"
    psql -d "$PG_DB" -c "\copy $PG_TABLE FROM '/tmp/interactivetools_map.csv' CSV HEADER"
}

# Main script execution
export_sqlite_to_csv
set +e
import_csv_to_postgresql
set -e

# Clean up
rm /tmp/interactivetools_map.csv

@kysrpex
Copy link
Contributor Author

kysrpex commented Jul 4, 2024

This is a draft because none of the requirements have been merged nor deployed, that will still take a while. Otherwise it should work.

@kysrpex kysrpex force-pushed the interactivetools_postgres branch from 2e98fc4 to ea9e1c1 Compare July 4, 2024 13:09
@kysrpex kysrpex changed the title Store interactive tool sessions in PostgreSQL table "gxitproxy" Store interactive tool sessions in PostgreSQL database "gxitproxy" Jul 19, 2024
@kysrpex
Copy link
Contributor Author

kysrpex commented Oct 29, 2024

gyp: Call to 'which pg_config || find /usr/bin /usr/local/bin /usr/pg* /opt -executable -name pg_config -print -quit' returned exit status 1 while in binding.gyp. while trying to load binding.gyp\nnpm ERR! gyp ERR! configure error 

Packages to interact with PostgreSQL need to be added to the Ansible playbooks or the Ansible role for the proxy before marking this PR as ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant