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

CMR-9270: As CMR DevOps I want CMR services to abstractly create a DB connection #1965

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bootstrap-app/src/cmr/bootstrap/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
[cmr.message-queue.queue.queue-broker :as queue-broker]
[cmr.metadata-db.config :as mdb-config]
[cmr.metadata-db.system :as mdb-system]
[cmr.metadata-db.services.util :as mdb-util]
[cmr.oracle.connection :as oracle]
[cmr.transmit.config :as transmit-config]))

Expand Down Expand Up @@ -70,7 +71,7 @@
:synchronous-dispatcher (dispatch/create-backend :sync)
:message-queue-dispatcher (dispatch/create-backend :message-queue)
:catalog-rest-user (mdb-config/catalog-rest-db-username)
:db (oracle/create-db (bootstrap-config/db-spec "bootstrap-pool"))
:db (mdb-util/create-db (bootstrap-config/db-spec "bootstrap-pool"))
:web (web/create-web-server (transmit-config/bootstrap-port) routes/make-api)
:nrepl (nrepl/create-nrepl-if-configured (bootstrap-config/bootstrap-nrepl-port))
:relative-root-url (transmit-config/bootstrap-relative-root-url)
Expand Down
3 changes: 2 additions & 1 deletion bootstrap-app/src/config/bootstrap_migrate_config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[cmr.bootstrap.config :as bootstrap-config]
[cmr.common.lifecycle :as lifecycle]
[cmr.oracle.connection :as oracle]
[cmr.metadata-db.services.util :as mdb-util]
[drift.builder :as drift-builder])
(:import
(java.sql SQLException)))
Expand All @@ -16,7 +17,7 @@
[]
(when-not @bootstrap-db-atom
(reset! bootstrap-db-atom (lifecycle/start
(oracle/create-db (bootstrap-config/db-spec "bootstrap-migrations"))
(mdb-util/create-db (bootstrap-config/db-spec "bootstrap-migrations"))
nil)))
@bootstrap-db-atom)

Expand Down
1 change: 1 addition & 0 deletions ingest-app/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
[nasa-cmr/cmr-acl-lib "0.1.0-SNAPSHOT"]
[nasa-cmr/cmr-common-app-lib "0.1.0-SNAPSHOT"]
[nasa-cmr/cmr-message-queue-lib "0.1.0-SNAPSHOT"]
[nasa-cmr/cmr-metadata-db-app "0.1.0-SNAPSHOT"]
[nasa-cmr/cmr-oracle-lib "0.1.0-SNAPSHOT"]
[nasa-cmr/cmr-redis-utils-lib "0.1.0-SNAPSHOT"]
[nasa-cmr/cmr-schemas "0.0.1-SNAPSHOT"]
Expand Down
3 changes: 2 additions & 1 deletion ingest-app/src/cmr/ingest/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
[cmr.ingest.services.jobs :as ingest-jobs]
[cmr.ingest.services.providers-cache :as pc]
[cmr.message-queue.queue.queue-broker :as queue-broker]
[cmr.metadata-db.services.util :as mdb-util]
[cmr.oracle.connection :as oracle]
[cmr.transmit.config :as transmit-config]
[cmr.transmit.launchpad-user-cache :as launchpad-user-cache]
Expand Down Expand Up @@ -91,7 +92,7 @@
(let [sys {:log (log/create-logger-with-log-level (log-level))
:web (web/create-web-server (transmit-config/ingest-port) routes/handlers)
:nrepl (nrepl/create-nrepl-if-configured (config/ingest-nrepl-port))
:db (oracle/create-db (config/db-spec connection-pool-name))
:db (mdb-util/create-db (config/db-spec connection-pool-name))
:scheduler (jobs/create-clustered-scheduler
`system-holder :db
(conj (ingest-jobs/jobs)
Expand Down
3 changes: 2 additions & 1 deletion ingest-app/src/config/ingest_migrate_config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[cmr.ingest.config :as ingest-config]
[cmr.oracle.config :as oracle-config]
[cmr.oracle.connection :as oracle]
[cmr.metadata-db.services.util :as mdb-util]
[drift.builder :refer [incremental-migration-number-generator]])
(:import
(java.sql SQLException)))
Expand All @@ -17,7 +18,7 @@
[]
(when-not @db-atom
(reset! db-atom (lifecycle/start
(oracle/create-db (ingest-config/db-spec "ingest-migrations")) nil)))
(mdb-util/create-db (ingest-config/db-spec "ingest-migrations")) nil)))
@db-atom)


Expand Down
4 changes: 4 additions & 0 deletions metadata-db-app/src/cmr/metadata_db/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"The database password"
{})

(defconfig metadata-db-system
"The backend system being used for metadata-db"
{:default "oracle"})

(defconfig catalog-rest-db-username
"The catalog rest db username"
{:default "DEV_52_CATALOG_REST"})
Expand Down
10 changes: 9 additions & 1 deletion metadata-db-app/src/cmr/metadata_db/services/util.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(ns cmr.metadata-db.services.util
"Utility methods for concepts."
(:require [cmr.metadata-db.services.messages :as msg]
[cmr.common.util :as util]))
[cmr.common.util :as util]
[cmr.metadata-db.config :as config]
[cmr.oracle.connection :as oracle]))

;;; Utility methods
(defn context->db
Expand All @@ -19,3 +21,9 @@
"Check to see if an entry is a tombstone (has a :deleted true entry)."
[concept]
(:deleted concept))

(defn create-db
"Calling the correct create-db function for the currently configured database system"
[spec]
(case (config/metadata-db-system)
"oracle" (oracle/create-db spec)))
3 changes: 2 additions & 1 deletion metadata-db-app/src/cmr/metadata_db/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
[cmr.metadata-db.api.routes :as routes]
[cmr.metadata-db.config :as config]
[cmr.metadata-db.services.jobs :as mdb-jobs]
[cmr.metadata-db.services.util :as mdb-util]
[cmr.oracle.config :as oracle-config]
[cmr.oracle.connection :as oracle]
[cmr.transmit.config :as transmit-config]))
Expand All @@ -42,7 +43,7 @@
([]
(create-system "metadata-db"))
([connection-pool-name]
(let [sys {:db (assoc (oracle/create-db (config/db-spec connection-pool-name))
(let [sys {:db (assoc (mdb-util/create-db (config/db-spec connection-pool-name))
:result-set-fetch-size
(config/result-set-fetch-size))
:log (log/create-logger-with-log-level (log-level))
Expand Down
3 changes: 2 additions & 1 deletion metadata-db-app/src/config/mdb_migrate_config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[cmr.common.lifecycle :as lifecycle]
[cmr.metadata-db.config :as mdb-config]
[cmr.metadata-db.data.oracle.concept-tables :as concept-tables]
[cmr.metadata-db.services.util :as mdb-util]
[cmr.oracle.config :as oracle-config]
[cmr.oracle.connection :as oracle]
[drift.builder :refer [incremental-migration-number-generator]])
Expand All @@ -18,7 +19,7 @@
[]
(when-not @db-atom
(reset! db-atom (lifecycle/start
(oracle/create-db (mdb-config/db-spec "metadata-db-migrations")) nil)))
(mdb-util/create-db (mdb-config/db-spec "metadata-db-migrations")) nil)))
@db-atom)

(defn- maybe-create-schema-table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[cmr.metadata-db.data.oracle.concepts :as c]
[cmr.metadata-db.data.oracle.concepts.collection]
[cmr.metadata-db.data.oracle.concepts.granule]
[cmr.metadata-db.services.util :as mdb-util]
[cmr.oracle.config :as oracle-config]
[cmr.oracle.connection :as oracle])
(:import
Expand All @@ -35,72 +36,6 @@
(let [vector-result (apply vector (map #(apply vector %) result))]
(update-in vector-result [1 2] #(gzip-bytes->string %))))

;; This test is commented out until CMR-1303 is resolved
#_(deftest db-result->concept-map-test
(let [db (->> (mdb-config/db-spec "metadata-db-test")
oracle/create-db
(#(lifecycle/start % nil)))]
(try
(j/with-db-transaction
[db db]
(let [revision-time (t/date-time 1986 10 14 4 3 27 456)
oracle-timestamp (TIMESTAMPTZ. ^java.sql.Connection (oracle/db->oracle-conn db)
^java.sql.Timestamp (cr/to-sql-time revision-time))]
(testing "collection results"
(let [result {:native_id "foo"
:concept_id "C5-PROV1"
:metadata (mock-blob "<foo>")
:format "ECHO10"
:revision_id 2
:revision_date oracle-timestamp
:deleted 0
:short_name "short"
:version_id "v1"
:entry_id "short_v1"
:entry_title "entry"
:delete_time oracle-timestamp}]
(is (= {:concept-type :collection
:native-id "foo"
:concept-id "C5-PROV1"
:provider-id "PROV1"
:metadata "<foo>"
:format "application/echo10+xml"
:revision-id 2
:revision-date "1986-10-14T04:03:27.456Z"
:deleted false
:extra-fields {:short-name "short"
:version-id "v1"
:entry-id "short_v1"
:entry-title "entry"
:delete-time "1986-10-14T04:03:27.456Z"}}
(c/db-result->concept-map :collection db "PROV1" result)))))
(testing "granule results"
(let [result {:native_id "foo"
:concept_id "G7-PROV1"
:metadata (mock-blob "<foo>")
:format "ECHO10"
:revision_date oracle-timestamp
:revision_id 2
:deleted 0
:parent_collection_id "C5-PROV1"
:delete_time oracle-timestamp
:granule_ur "foo-ur"}]
(is (= {:concept-type :granule
:native-id "foo"
:concept-id "G7-PROV1"
:provider-id "PROV1"
:metadata "<foo>"
:format "application/echo10+xml"
:revision-id 2
:revision-date "1986-10-14T04:03:27.456Z"
:deleted false
:extra-fields {:parent-collection-id "C5-PROV1"
:delete-time "1986-10-14T04:03:27.456Z"
:granule-ur "foo-ur"}}
(c/db-result->concept-map :granule db "PROV1" result)))))))
(finally
(lifecycle/stop db nil)))))

(deftest concept->insert-args-test
(testing "collection insert-args"
(let [revision-time (t/date-time 1986 10 14 4 3 27 456)
Expand Down
3 changes: 2 additions & 1 deletion system-int-test/src/cmr/system_int_test/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[cmr.bootstrap.config :as bootstrap-config]
[cmr.common.lifecycle :as lifecycle]
[cmr.common.log :as log :refer (debug info warn error)]
[cmr.metadata-db.services.util :as mdb-util]
[cmr.oracle.connection :as oracle]
[cmr.system-int-test.utils.url-helper :as url]
[cmr.transmit.config :as transmit-config]))
Expand All @@ -33,7 +34,7 @@
[component-type-map]
(let [sys {:log (log/create-logger {:level @logging-level-atom})
:bootstrap-db (when (= :external (:db component-type-map))
(oracle/create-db (bootstrap-config/db-spec "bootstrap-test-pool")))
(mdb-util/create-db (bootstrap-config/db-spec "bootstrap-test-pool")))
;; the HTTP connection manager to use. This allows system integration tests to use persistent
;; HTTP connections
:conn-mgr (conn-mgr/make-reusable-conn-manager {})
Expand Down