diff --git a/build/docker/deploySchemaAndTenant.sh b/build/docker/deploySchemaAndTenant.sh index d57a19a6c67..e95248ac74b 100755 --- a/build/docker/deploySchemaAndTenant.sh +++ b/build/docker/deploySchemaAndTenant.sh @@ -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" ]] @@ -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 diff --git a/build/docker/updateSchema.sh b/build/docker/updateSchema.sh index e8dc21f4849..df2c401286d 100755 --- a/build/docker/updateSchema.sh +++ b/build/docker/updateSchema.sh @@ -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 diff --git a/fhir-persistence-schema/docs/SchemaToolUsageGuide.md b/fhir-persistence-schema/docs/SchemaToolUsageGuide.md index 53b3df9c1f7..76af693b8a7 100644 --- a/fhir-persistence-schema/docs/SchemaToolUsageGuide.md +++ b/fhir-persistence-schema/docs/SchemaToolUsageGuide.md @@ -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 ``` @@ -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 ``` @@ -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 @@ -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 ``` @@ -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 ``` @@ -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 "" ``` @@ -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 ``` @@ -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 ``` @@ -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= ``` @@ -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 ``` @@ -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 ``` @@ -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 ``` @@ -387,10 +397,11 @@ 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 ``` @@ -398,32 +409,36 @@ java -jar ./fhir-persistence-schema-${VERSION}-cli.jar \ ``` 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 ``` @@ -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 \ @@ -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)| diff --git a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java index d0f3f88fe22..37bc9854dc4 100644 --- a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java +++ b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java @@ -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 resourceTypeSubset; @@ -1137,7 +1137,7 @@ protected void grantPrivileges() { * @return */ protected boolean isMultitenant() { - return MULTITENANT_FEATURE_ENABLED.contains(this.dbType); + return dataSchemaType == SchemaType.MULTITENANT; } /** @@ -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: @@ -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 + " is required"); + } } /**