Skip to content

Commit

Permalink
issue #3437 db-type arg now required when running schema tool
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Arnold <robin.arnold@ibm.com>
  • Loading branch information
punktilious committed Jun 8, 2022
1 parent fe03611 commit 1644408
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 67 deletions.
10 changes: 5 additions & 5 deletions build/docker/deploySchemaAndTenant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ while [ "$not_ready" == "true" ]
do
EXIT_CODE="-1"
java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --schema-name FHIRDATA --create-schemas | tee -a ${TMP_FILE}
--db-type db2 --prop-file db2.properties --schema-name FHIRDATA --create-schemas | tee -a ${TMP_FILE}
EXIT_CODE="${PIPESTATUS[0]}"
LOG_OUT=`cat ${TMP_FILE}`
if [[ "$EXIT_CODE" == "0" ]]
Expand Down Expand Up @@ -54,18 +54,18 @@ then
fi

java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --schema-name FHIRDATA --update-schema --pool-size 2
--db-type db2 --prop-file db2.properties --schema-name FHIRDATA --update-schema --pool-size 2

java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --schema-name FHIRDATA --grant-to FHIRSERVER --pool-size 2
--db-type db2 --prop-file db2.properties --schema-name FHIRDATA --grant-to FHIRSERVER --pool-size 2

java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --schema-name FHIRDATA --allocate-tenant default --pool-size 2
--db-type db2 --prop-file db2.properties --schema-name FHIRDATA --allocate-tenant default --pool-size 2

# The regex in the following command will output the capture group between "key=" and "]"
# With GNU grep, the following would work as well: grep -oP 'key=\K\S+(?=])'
tenantKey=$(java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --schema-name FHIRDATA --add-tenant-key default 2>&1 \
--db-type db2 --prop-file db2.properties --schema-name FHIRDATA --add-tenant-key default 2>&1 \
| grep "key=" | sed -e 's/.*key\=\(.*\)\].*/\1/')

# Creating a backup file is the easiest way to make in-place sed portable across OSX and Linux
Expand Down
8 changes: 4 additions & 4 deletions build/docker/updateSchema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ cd ${DIR}
# For #1366 the migration hits deadlock issues if run in parallel, so
# to avoid this, serialize the steps using --pool-size 1
java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --schema-name FHIRDATA --update-schema \
--db-type db2 --prop-file db2.properties --schema-name FHIRDATA --update-schema \
--pool-size 1

# Rerun grants to cover any new tables added by the above migration step
java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --schema-name FHIRDATA --grant-to FHIRSERVER --pool-size 2
--db-type db2 --prop-file db2.properties --schema-name FHIRDATA --grant-to FHIRSERVER --pool-size 2

# And make sure that the new tables have partitions for existing tenants
java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --refresh-tenants
--db-type db2 --prop-file db2.properties --refresh-tenants

java -jar schema/fhir-persistence-schema-*-cli.jar \
--prop-file db2.properties --schema-name FHIRDATA --grant-to FHIRSERVER \
--db-type db2 --prop-file db2.properties --schema-name FHIRDATA --grant-to FHIRSERVER \
--pool-size 20
125 changes: 71 additions & 54 deletions fhir-persistence-schema/docs/SchemaToolUsageGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,18 @@ The following sections include common values for `OPTIONS`.
For Db2:

```
--prop-file db2.properties
--schema-name FHIRDATA
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--create-schemas
```

For PostgreSQL:

```
--prop-file postgresql.properties
--schema-name fhirdata
--create-schemas
--prop-file postgresql.properties \
--schema-name fhirdata \
--create-schemas \
--db-type postgresql
```

Expand All @@ -141,9 +142,10 @@ for the IBM FHIR Server to operate. The FHIRADMIN user should only be used
for schema updates, not for IBM FHIR Server access.

```
--prop-file db2.properties
--schema-name FHIRDATA
--update-schema
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--update-schema \
--grant-to FHIRSERVER
```

Expand All @@ -161,10 +163,10 @@ for the IBM FHIR Server to operate. The FHIRADMIN user should only be used
for schema updates, not for IBM FHIR Server access.

```
--prop-file postgresql.properties
--schema-name FHIRDATA
--update-schema
--grant-to FHIRSERVER
--prop-file postgresql.properties \
--schema-name FHIRDATA \
--update-schema \
--grant-to FHIRSERVER \
--db-type postgresql
```
If the --grant-to is provided, the grants will be processed after the schema
Expand All @@ -178,16 +180,18 @@ When updating the postgres schema, the autovacuum settings are configured.
### Grant privileges to another data access user

```
--prop-file db2.properties
--schema-name FHIRDATA
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--grant-to FHIRSERVER
```

### Add a new tenant (e.g. default) (Db2 only)

```
--prop-file db2.properties
--schema-name FHIRDATA
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--allocate-tenant default
```

Expand All @@ -209,6 +213,7 @@ After a schema update you must run the refresh-tenants command to ensure that an

```
java -jar schema/fhir-persistence-schema-*-cli.jar \
--db-type db2 \
--prop-file db2.properties --refresh-tenants
```

Expand Down Expand Up @@ -243,9 +248,10 @@ Edit `wlp/usr/servers/fhir-server/config/default/fhir-server-config.json` and ad
### Test a tenant (Db2 only)

```
--prop-file db2.properties
--schema-name FHIRDATA
--test-tenant default
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--test-tenant default \
--tenant-key "<the-base64-tenant-key>"
```

Expand All @@ -255,8 +261,9 @@ Use `--tenant-key-file tenant.key` to read the tenant-key to a file. You do not
To add a tenant key for an existing tenant, replace FHIRDATA with your client schema, and change default to your tenant's name.

```
--prop-file db2.properties
--schema-name FHIRDATA
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--add-tenant-key default
```

Expand All @@ -277,9 +284,9 @@ Use `--tenant-key-file tenant.key.file` to direct the action to read the tenant-
To remove all tenant keys for an existing tenant, replace FHIRDATA with your client schema, and change default to your tenant's name.

```
--prop-file db2.properties
--schema-name FHIRDATA
--db-type db2
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--revoke-all-tenant-keys default
```

Expand All @@ -295,10 +302,10 @@ To remove all tenant keys for an existing tenant, replace FHIRDATA with your cli
To remove a tenant key for an existing tenant, replace FHIRDATA with your client schema, and change default to your tenant's name.

```
--prop-file db2.properties
--schema-name FHIRDATA
--db-type db2
--revoke-tenant-key default
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--revoke-tenant-key default \
--tenant-key rZ59TLyEpjU+FAKEtgVk8J44J0=
```

Expand All @@ -317,8 +324,9 @@ Use `--tenant-key-file tenant.key.file` to direct the action to read the tenant-
For Db2:

```
--prop-file db2.properties
--schema-name FHIRDATA
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--update-proc
```

Expand All @@ -335,9 +343,10 @@ For PostgreSQL:
For Db2:

```
--prop-file db2.properties
--schema-name FHIRDATA
--drop-schema-fhir
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--drop-schema-fhir \
--confirm-drop
```

Expand All @@ -355,12 +364,13 @@ For PostgreSQL:
For Db2:

```
--prop-file db2.properties
--schema-name FHIRDATA
--drop-schema-fhir
--drop-schema-batch
--drop-schema-oauth
--drop-admin
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--drop-schema-fhir \
--drop-schema-batch \
--drop-schema-oauth \
--drop-admin \
--confirm-drop
```

Expand All @@ -387,43 +397,48 @@ For those using multiple schemas for each customer, for instance, customer 2 nee

```
java -jar ./fhir-persistence-schema-${VERSION}-cli.jar \
--prop-file db2.properties
--create-schemas
--create-schema-batch FHIR_JBATCH_2ND
--create-schema-oauth FHIR_OAUTH_2ND
--db-type db2 \
--prop-file db2.properties \
--create-schemas \
--create-schema-batch FHIR_JBATCH_2ND \
--create-schema-oauth FHIR_OAUTH_2ND \
--create-schema-fhir FHIRDATA_2ND
```

### Deploy the additional schema

```
java -jar ./fhir-persistence-schema-${VERSION}-cli.jar \
--prop-file db2.properties
--schema-name FHIRDATA
--update-schema-batch FHIR_JBATCH_2ND
--update-schema-oauth FHIR_OAUTH_2ND
--db-type db2 \
--prop-file db2.properties \
--schema-name FHIRDATA \
--update-schema-batch FHIR_JBATCH_2ND \
--update-schema-oauth FHIR_OAUTH_2ND \
--update-schema-fhir FHIRDATA_2ND
```

### Grant privileges to data access user
```
java -jar ./fhir-persistence-schema-${VERSION}-cli.jar \
--prop-file db2.properties
--grant-to FHIRSERVER
--db-type db2 \
--prop-file db2.properties \
--grant-to FHIRSERVER \
--target BATCH FHIR_JBATCH_2ND
```

```
java -jar ./fhir-persistence-schema-${VERSION}-cli.jar \
--prop-file db2.properties
--grant-to FHIRSERVER
--db-type db2 \
--prop-file db2.properties \
--grant-to FHIRSERVER \
--target OAUTH FHIR_OAUTH_2ND
```

```
java -jar ./fhir-persistence-schema-${VERSION}-cli.jar \
--prop-file db2.properties
--grant-to FHIRSERVER
--db-type db2 \
--prop-file db2.properties \
--grant-to FHIRSERVER \
--target DATA FHIRDATA_2ND
```

Expand Down Expand Up @@ -560,6 +575,7 @@ java -jar ./fhir-persistence-schema-${VERSION}-cli.jar \

``` shell
java -jar ./fhir-persistence-schema-${VERSION}-cli.jar \
--db-type db2 \
--prop-file fhiradmin.properties \
--db-type db2 \
--schema-name FHIRDATA \
Expand Down Expand Up @@ -597,7 +613,8 @@ and grants permission to the username|
|--tenant-key|tenantKey|the tenant-key in the queries|
|--tenant-key-file|tenant-key-file-location|sets the tenant key file location|
|--list-tenants||fetches list of tenants and current status|
|--db-type|dbType|Either derby, postgresql, db2|
|--db-type|dbType|Either derby, postgresql, db2. Required.|
|--schema-type|schemaType|Override the default schema type created for the configured database type. PostgresSQL->PLAIN, Derby->PLAIN, Db2->MULTITENANT, Citus->DISTRIBUTED |
|--delete-tenant-meta|tenantName|deletes tenant metadata given the tenantName|
|--drop-detached|tenantName|(phase 2) drops the detached tenant partition tables given the tenantName|
|--freeze-tenant||Changes the tenant state to frozen, and subsequently (Db2 only)|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ public class Main {
// How many seconds to wait to obtain the update lease
private int waitForUpdateLeaseSeconds = 10;

// The database type being populated (default: Db2)
private DbType dbType = DbType.DB2;
private IDatabaseTranslator translator = new Db2Translator();
// The database type being populated. Now a required parameter.
private DbType dbType;
private IDatabaseTranslator translator;

// Optional subset of resource types (for faster schema builds when testing)
private Set<String> resourceTypeSubset;
Expand Down Expand Up @@ -1137,7 +1137,7 @@ protected void grantPrivileges() {
* @return
*/
protected boolean isMultitenant() {
return MULTITENANT_FEATURE_ENABLED.contains(this.dbType);
return dataSchemaType == SchemaType.MULTITENANT;
}

/**
Expand Down Expand Up @@ -2228,6 +2228,7 @@ protected void parseArgs(String[] args) {
dataSchemaType = SchemaType.DISTRIBUTED; // by default
break;
case DB2:
translator = new Db2Translator();
dataSchemaType = SchemaType.MULTITENANT;
break;
default:
Expand Down Expand Up @@ -2267,6 +2268,10 @@ protected void parseArgs(String[] args) {
this.maxConnectionPoolSize = threadPoolSize + FhirSchemaConstants.CONNECTION_POOL_HEADROOM;
logger.warning("Connection pool size below minimum headroom. Setting it to " + this.maxConnectionPoolSize);
}

if (this.dbType == null) {
throw new IllegalArgumentException(DB_TYPE + " <type> is required");
}
}

/**
Expand Down

0 comments on commit 1644408

Please sign in to comment.