diff --git a/bootstrap-app/src/cmr/bootstrap/system.clj b/bootstrap-app/src/cmr/bootstrap/system.clj index 707c466c2d..6e20b41604 100644 --- a/bootstrap-app/src/cmr/bootstrap/system.clj +++ b/bootstrap-app/src/cmr/bootstrap/system.clj @@ -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])) @@ -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) diff --git a/bootstrap-app/src/config/bootstrap_migrate_config.clj b/bootstrap-app/src/config/bootstrap_migrate_config.clj index c9405c3b06..a812d6872d 100644 --- a/bootstrap-app/src/config/bootstrap_migrate_config.clj +++ b/bootstrap-app/src/config/bootstrap_migrate_config.clj @@ -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))) @@ -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) diff --git a/ingest-app/project.clj b/ingest-app/project.clj index 8497213d1c..0caf9b3f6b 100644 --- a/ingest-app/project.clj +++ b/ingest-app/project.clj @@ -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"] diff --git a/ingest-app/src/cmr/ingest/system.clj b/ingest-app/src/cmr/ingest/system.clj index 8d2cb1fb30..a953c17d20 100644 --- a/ingest-app/src/cmr/ingest/system.clj +++ b/ingest-app/src/cmr/ingest/system.clj @@ -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] @@ -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) diff --git a/ingest-app/src/config/ingest_migrate_config.clj b/ingest-app/src/config/ingest_migrate_config.clj index b734458fbe..c7e398abfa 100644 --- a/ingest-app/src/config/ingest_migrate_config.clj +++ b/ingest-app/src/config/ingest_migrate_config.clj @@ -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))) @@ -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) diff --git a/metadata-db-app/src/cmr/metadata_db/config.clj b/metadata-db-app/src/cmr/metadata_db/config.clj index dd159d2619..0ae26c5dc2 100644 --- a/metadata-db-app/src/cmr/metadata_db/config.clj +++ b/metadata-db-app/src/cmr/metadata_db/config.clj @@ -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"}) diff --git a/metadata-db-app/src/cmr/metadata_db/services/util.clj b/metadata-db-app/src/cmr/metadata_db/services/util.clj index 2cbb0cdf37..ad43bd70b7 100644 --- a/metadata-db-app/src/cmr/metadata_db/services/util.clj +++ b/metadata-db-app/src/cmr/metadata_db/services/util.clj @@ -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 @@ -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))) diff --git a/metadata-db-app/src/cmr/metadata_db/system.clj b/metadata-db-app/src/cmr/metadata_db/system.clj index 4c55c9b55f..066e650618 100644 --- a/metadata-db-app/src/cmr/metadata_db/system.clj +++ b/metadata-db-app/src/cmr/metadata_db/system.clj @@ -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])) @@ -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)) diff --git a/metadata-db-app/src/config/mdb_migrate_config.clj b/metadata-db-app/src/config/mdb_migrate_config.clj index 0863327adb..424079c063 100644 --- a/metadata-db-app/src/config/mdb_migrate_config.clj +++ b/metadata-db-app/src/config/mdb_migrate_config.clj @@ -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]]) @@ -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 diff --git a/metadata-db-app/test/cmr/metadata_db/test/data/oracle/concepts.clj b/metadata-db-app/test/cmr/metadata_db/test/data/oracle/concepts.clj index 368e10580b..610d87c8e2 100644 --- a/metadata-db-app/test/cmr/metadata_db/test/data/oracle/concepts.clj +++ b/metadata-db-app/test/cmr/metadata_db/test/data/oracle/concepts.clj @@ -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 @@ -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 "") - :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 "" - :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 "") - :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 "" - :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) diff --git a/system-int-test/src/cmr/system_int_test/system.clj b/system-int-test/src/cmr/system_int_test/system.clj index cc78c872fd..455f47c0dd 100644 --- a/system-int-test/src/cmr/system_int_test/system.clj +++ b/system-int-test/src/cmr/system_int_test/system.clj @@ -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])) @@ -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 {})