Skip to content

Commit

Permalink
Touch up Oracle module
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflester committed Aug 26, 2021
1 parent fa6922c commit d3ee675
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/modules/catalog/oracle/oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ services:
labels:
- "com.starburst.tests=minitrino"
- "com.starburst.tests.module.oracle=catalog-oracle"
environment:
MINITRINO_BOOTSTRAP: "bootstrap-oracle.sh"
env_file:
- "./modules/catalog/oracle/resources/oracle/oracle.env"
- "./modules/catalog/oracle/resources/oracle/ora.conf"
ports:
- "1521:1521"
6 changes: 6 additions & 0 deletions lib/modules/catalog/oracle/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ This module provisions a standalone Oracle service.

## Usage

You will want to use the `trino` schema within the `oracle` catalog.
Additionally, the Oracle server takes some time to become available after the
container boots up. If you see an `Unable to start the Universal Connection
Pool` error, wait 1-2 minutes and try querying Oracle again.

# Login with the Docker Hub account used to "purchase" the image
echo "your-password" | docker login -u <user> --password-stdindocker
minitrino --env STARBURST_VER=<ver> provision --module oracle
docker exec -it trino bash
trino-cli
trino> show schemas from oracle;
trino> create table oracle.trino.test (a int);

## Image Pull Notes

Expand Down
80 changes: 80 additions & 0 deletions lib/modules/catalog/oracle/resources/bootstrap/bootstrap-oracle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash

set -ex

function health_check() {
su - oracle -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1 as sysdba @/tmp/health-check.sql"
}

function create_user() {
su - oracle -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1 as sysdba @/tmp/create-user.sql"
}

function grant_privileges() {
su - oracle -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1 as sysdba @/tmp/grant-privileges.sql"
}

echo "Creating health check SQL script..."
cat <<EOT >> /tmp/health-check.sql
SELECT INSTANCE_NAME, STATUS, DATABASE_STATUS FROM V\$INSTANCE;
exit;
EOT

echo "Creating user-creation SQL script..."
cat <<EOT >> /tmp/create-user.sql
ALTER SESSION SET "_ORACLE_SCRIPT"=true;
CREATE USER trino IDENTIFIED BY trinoRocks15;
exit;
EOT

echo "Creating user-privilege SQL script..."
cat <<EOT >> /tmp/grant-privileges.sql
ALTER SESSION SET "_ORACLE_SCRIPT"=true;
GRANT CONNECT, RESOURCE, DBA TO trino;
GRANT CREATE SESSION, CREATE TABLE TO trino;
GRANT UNLIMITED TABLESPACE TO trino;
GRANT ALL PRIVILEGES TO trino;
exit;
EOT

echo "Performing health checks..."
COUNTER=0 && set +e
while [[ "${COUNTER}" -lt 121 ]]; do
if health_check | grep -q "trinosid\|OPEN\|ACTIVE"; then
break
elif [[ "${COUNTER}" == 121 ]]; then
echo "Database is not up and running and timed out after approx. 2 minutes. Exiting"
exit 1
else
sleep 1
((COUNTER++))
fi
done

echo "Creating user..."
COUNTER=0 && set +e
while [[ "${COUNTER}" -lt 61 ]]; do
if create_user | grep -q "ERROR"; then
sleep 1
((COUNTER++))
elif [[ "${COUNTER}" == 61 ]]; then
echo "User creation failed after approx. 1 minute. Exiting"
exit 1
else
break
fi
done

echo "Granting user privileges..."
COUNTER=0 && set +e
while [[ "${COUNTER}" -lt 61 ]]; do
if grant_privileges | grep -q "ERROR"; then
sleep 1
((COUNTER++))
elif [[ "${COUNTER}" == 61 ]]; then
echo "Privilege grant failed after approx. 1 minute. Exiting"
exit 1
else
break
fi
done
3 changes: 3 additions & 0 deletions lib/modules/catalog/oracle/resources/oracle/ora.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DB_PDB=trino
DB_SID=trinosid
DB_MEMORY=2GB
3 changes: 0 additions & 3 deletions lib/modules/catalog/oracle/resources/oracle/oracle.env

This file was deleted.

4 changes: 2 additions & 2 deletions lib/modules/catalog/oracle/resources/trino/oracle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
connector.name=oracle
connection-url=jdbc:oracle:thin:@oracle:1521:minitrino
connection-user=admin
connection-url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=trinosid.localdomain)))
connection-user=trino
connection-password=trinoRocks15

0 comments on commit d3ee675

Please sign in to comment.