Skip to content

Commit

Permalink
images: Override the default derby database type when postgres or mys…
Browse files Browse the repository at this point in the history
…ql has been configured

Update the Ansible role's `configure_hive_metastore.yaml` task file to
override the `_meteringconfig_hive_metastore_db_url` helper variable.
That helper variable, which is set to the `hive.spec.config.db.url`
configuration and will be overriden with any value that we set in that
task file before the MeteringConfig values have been finalized.

When we're handling postgres resources, we need to remap what we pull
from the JDBC URL as `postgresql` isn't a valid `schematool -dbType`
option, but `postgres` is so use the value from the split URL array
unless we're configuring a postgres database for Hive metastore.
  • Loading branch information
timflannagan committed Jan 13, 2021
1 parent 0a6a054 commit 0d2eb01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ _hive_metastore_db_overrides:
db:
username: "{{ _hive_metastore_db_username | default('') }}"
password: "{{ _hive_metastore_db_password | default('') }}"
type: "{{ _hive_metastore_db_type | default('derby') }}"
metastore:
storage:
create: "{{ _hive_metastore_create_default_storage | default(true) }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@
message: "Configuring hive metastore"
lastTransitionTime: "{{ now(utc=False).isoformat() + 'Z' }}"

- name: Determine the Hive underlying database
block:
- name: Split the hive.spec.config.db.url into an array
set_fact:
_url_array: "{{ _meteringconfig_hive_metastore_db_url.split(':') }}"

- name: Verify the JDBC URL is valid before parsing
assert:
that:
- '{{ _url_array[0] == "jdbc" }}'
- '{{ _url_array[1] in ["mysql", "postgresql", "derby"] }}'
msg: "Invalid JDBC URL {{ _meteringconfig_hive_metastore_db_url }} passed in the MeteringConfig.Spec"

# Note: the `schematool -dbType` option expects either `mysql`,
# `derby`, `oracle` and `postgres` as valid options. In the case
# of the JDBC URL, only `postgresql` is valid, so we need to do
# some re-mapping of naming if that is what has been specified
# in the hive.spec.config.db.url field in the MeteringConfig CR.
- name: Override the default hive metastore database type
set_fact:
_hive_metastore_db_type: "{{ 'postgres' if _url_array[1] == 'postgresql' else _url_array[1] }}"

- name: Override the default hive.spec.metastore.storage.create option to false
set_fact:
_hive_metastore_create_default_storage: false
Expand Down Expand Up @@ -69,6 +91,7 @@
_meteringconfig_hive_metastore_db_secretName: "{{ meteringconfig_spec_overrides | json_query('hive.spec.config.db.secretName') }}"
_meteringconfig_hive_metastore_db_username: "{{ meteringconfig_spec_overrides | json_query('hive.spec.config.db.username') }}"
_meteringconfig_hive_metastore_db_password: "{{ meteringconfig_spec_overrides | json_query('hive.spec.config.db.password') }}"
_meteringconfig_hive_metastore_db_url: "{{ meteringconfig_spec_overrides | json_query('hive.spec.config.db.url') }}"
_meteringconfig_hive_metastore_db_configuration: "{{ meteringconfig_spec_overrides | json_query('hive.spec.config.db') }}"
no_log: false
rescue:
Expand Down

0 comments on commit 0d2eb01

Please sign in to comment.