Skip to content

Commit 966bdf3

Browse files
committed
Merge branch 'CMR-10636' of https://github.com/nasa/Common-Metadata-Repository into CMR-10636-main
2 parents 22d48c9 + 2ce472f commit 966bdf3

16 files changed

Lines changed: 71 additions & 44 deletions

File tree

access-control-app/src/cmr/access_control/api/routes.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@
271271
{:status 204})
272272
(POST "/db-migrate" {ctx :request-context}
273273
(acl/verify-ingest-management-permission ctx :update)
274-
(println "10636- we are in /db-migrate")
275274
;; TODO 10636 fix me we are defaulting to the gran-search-index only for now
276275
(index/create-index-or-update-mappings (-> ctx :system :gran-search-index))
277276
{:status 204})))

access-control-app/src/cmr/access_control/data/bulk_index.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
* :force-version? - true indicates that we should overwrite whatever is in elasticsearch with the
4141
latest regardless of whether the version in the database is older than the _version in elastic.
4242
Returns a map with keys of :num-indexed and :max-revision-date."
43-
([context concept-batches]
44-
(bulk-index-with-revision-date context concept-batches nil))
45-
([context concept-batches options]
43+
([context concept-batches es-cluster-name]
44+
(bulk-index-with-revision-date context concept-batches es-cluster-name nil))
45+
([context concept-batches es-cluster-name options]
4646
(reduce (fn [{:keys [num-indexed max-revision-date]} batch]
4747
(let [max-revision-date (get-max-revision-date batch max-revision-date)
4848
batch (prepare-batch context batch options)]
49-
(es/bulk-index-documents context batch)
49+
(es/bulk-index-documents context batch es-cluster-name)
5050
{:num-indexed (+ num-indexed (count batch))
5151
:max-revision-date max-revision-date}))
5252
{:num-indexed 0 :max-revision-date nil}

bootstrap-app/src/cmr/bootstrap/api/bulk_index.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
\"granule\", \"collection\", etc.
7575
concept_ids - a vector of concept ids."
7676
[context request-details-map params]
77+
(println "INSIDE index-concepts-by-id in api/bulk_index.clj")
7778
(let [dispatcher (api-util/get-dispatcher context params :index-concepts-by-id)
7879
provider-id (get request-details-map "provider_id")
7980
concept-type (keyword (get request-details-map "concept_type"))

bootstrap-app/src/cmr/bootstrap/api/messages.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888

8989
(defn index-concepts-by-id
9090
[params result]
91+
(println "INSIDE index-concepts-by-id in api/messages.clj")
9192
(if (api-util/synchronous? params)
9293
(format "Processed %s concepts for bulk indexing." result)
9394
(str "Processing concepts for bulk indexing.")))

bootstrap-app/src/cmr/bootstrap/data/bulk_index.clj

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[cmr.common.concepts :as cc]
99
[cmr.common.log :refer (info warn error)]
1010
[cmr.common.util :as util]
11+
[cmr.elastic-utils.config :as es-config]
1112
[cmr.elastic-utils.es-helper :as es-helper]
1213
[cmr.indexer.indexer-util :as indexer-util]
1314
[cmr.indexer.data.elasticsearch :as es]
@@ -138,10 +139,10 @@
138139
;; TODO CMR-10636 fix this. We need to separate out the concepts and go to each seperate cluster
139140
(defn- bulk-index-concept-batches
140141
"Bulk index the given concept batches in both regular index and all revisions index."
141-
[system concept-batches]
142+
[system concept-batches es-cluster-name]
142143
(let [indexer-context {:system (helper/get-indexer system)}]
143-
(index/bulk-index indexer-context concept-batches nil {:all-revisions-index? true})
144-
(index/bulk-index indexer-context concept-batches nil {})))
144+
(index/bulk-index indexer-context concept-batches es-cluster-name {:all-revisions-index? true})
145+
(index/bulk-index indexer-context concept-batches es-cluster-name {})))
145146

146147
(defn- index-concepts-by-provider
147148
"Bulk index concepts for the given provider and concept-type."
@@ -158,7 +159,10 @@
158159
db provider
159160
params
160161
(:db-batch-size system))
161-
num-concepts (bulk-index-concept-batches system concept-batches)
162+
es-cluster-name (if (= concept-type :granule)
163+
cmr.elastic-utils.config/gran-elastic-name
164+
cmr.elastic-utils.config/non-gran-elastic-name)
165+
num-concepts (bulk-index-concept-batches system concept-batches es-cluster-name)
162166
msg (format "Indexing of %s %s revisions for provider %s completed."
163167
num-concepts
164168
(name concept-type)
@@ -184,14 +188,15 @@
184188
"Bulk index ACLs or access groups"
185189
[system concept-batches]
186190
(info "Indexing concepts")
187-
(ac-bulk-index/bulk-index-with-revision-date {:system (helper/get-indexer system)} concept-batches))
191+
(ac-bulk-index/bulk-index-with-revision-date {:system (helper/get-indexer system)} concept-batches cmr.elastic-utils.config/non-gran-elastic-name))
188192

189193
(defn- index-concepts
190194
"Bulk index the given concepts using the indexer-app"
191-
[system concept-batches]
195+
[system concept-batches es-cluster-name]
192196
(info "Indexing concepts")
193-
(index/bulk-index-with-revision-date {:system (helper/get-indexer system)} concept-batches))
197+
(index/bulk-index-with-revision-date {:system (helper/get-indexer system)} concept-batches es-cluster-name))
194198

199+
;; TODO CMR-10636 -- This whole series of index funcs need to be tested thoroughly.
195200
(defn- fetch-and-index-new-concepts
196201
"Get batches of concepts for a given provider/concept type that have a revision-date
197202
newer than the given date time and then index them."
@@ -206,9 +211,13 @@
206211
params)
207212
concept-batches (db/find-concepts-in-batches
208213
db provider params (:db-batch-size system))
214+
es-cluster-name (if (= concept-type :granule)
215+
cmr.elastic-utils.config/gran-elastic-name
216+
cmr.elastic-utils.config/non-gran-elastic-name)
217+
_ (println "INSIDE fetch-and-index-new-concepts with concept-type = " concept-type " and concept batches = " concept-batches " and es-cluster-name = " es-cluster-name)
209218
{:keys [max-revision-date num-indexed]} (if (contains? #{:acl :access-group} concept-type)
210219
(index-access-control-concepts system concept-batches)
211-
(index-concepts system concept-batches))]
220+
(index-concepts system concept-batches es-cluster-name))]
212221

213222
(info (format (str "Indexed %d %s(s) for provider %s with revision-date later than %s and max "
214223
"revision date was %s.")
@@ -242,6 +251,7 @@
242251
(defn index-concepts-by-id
243252
"Index concepts of the given type for the given provider with the given concept-ids."
244253
[system provider-id concept-type concept-ids]
254+
(println "INSIDE index-concepts-by-id in data/bulk_index.clj")
245255
(let [db (helper/get-metadata-db-db system)
246256
provider (helper/get-provider system provider-id)
247257
;; Oracle only allows 1000 values in an 'in' clause, so we partition here
@@ -254,7 +264,11 @@
254264
{:concept-type concept-type :concept-id batch}
255265
(:db-batch-size system))]
256266
concept-batch)
257-
total (index/bulk-index {:system (helper/get-indexer system)} concept-batches nil)]
267+
es-cluster-name (if (= :granule concept-type)
268+
cmr.elastic-utils.config/gran-elastic-name
269+
cmr.elastic-utils.config/non-gran-elastic-name)
270+
_ (println "es-cluster-name selected = " es-cluster-name " for concept-batches in index-concepts-by-id = " concept-batches)
271+
total (index/bulk-index {:system (helper/get-indexer system)} concept-batches es-cluster-name)]
258272

259273
;; for concept types that have all revisions index, also index the all revisions index
260274
(when-not (#{:tag :granule} concept-type)

bootstrap-app/src/cmr/bootstrap/services/bootstrap_service.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
(defn index-concepts-by-id
101101
"Bulk index the concepts given by the concept-ids"
102102
[context dispatcher provider-id concept-type concept-ids]
103+
(println "INSIDE index-concepts-by-id in bootstrap_service.clj")
103104
(dispatch/index-concepts-by-id dispatcher context provider-id concept-type concept-ids))
104105

105106
(defn index-variables

bootstrap-app/src/cmr/bootstrap/services/dispatch/impl/async.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
(defn index-concepts-by-id
5656
"Bulk index the concepts given by the concept-ids"
5757
[this context provider-id concept-type concept-ids]
58+
(println "INSIDE index-concepts-by-id in async.clj")
5859
(let [channel (:concept-id-channel this)]
5960
(info "Adding bulk index request to concept-id channel.")
6061
(async/go (>! channel {:provider-id provider-id

elastic-utils-lib/src/cmr/elastic_utils/config.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,15 @@
120120
;; to retry again
121121
:retry-handler nil
122122
:admin-token (elastic-admin-token)})
123+
124+
;; TODO 10636 unit test
125+
(defn es-cluster-name-str->keyword
126+
[es-cluster-name]
127+
(let [es-cluster-name-keyword (if (keyword? es-cluster-name)
128+
es-cluster-name
129+
(keyword es-cluster-name))]
130+
(if (or (= es-cluster-name-keyword (keyword cmr.elastic-utils.config/gran-elastic-name))
131+
(= es-cluster-name-keyword (keyword cmr.elastic-utils.config/non-gran-elastic-name)))
132+
es-cluster-name-keyword
133+
(throw (Exception. (str "Expected es-cluster-name to be gran-elastic or non-gran-elastic, but got value of " es-cluster-name " instead.")))
134+
)))

elastic-utils-lib/src/cmr/elastic_utils/search/ac_elasticsearch.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[cmr.common.concepts :as cs]
77
[cmr.common.log :refer [error]]
88
[cmr.common.services.errors :as errors]
9+
[cmr.elastic-utils.config]
910
[cmr.elastic-utils.es-helper :as es-helper]))
1011

1112
(def MAX_BULK_OPERATIONS_PER_REQUEST
@@ -70,11 +71,11 @@
7071
;: TODO 10636 - need to fix this func.
7172
(defn bulk-index-documents
7273
"Save a batch of documents in Elasticsearch."
73-
[context docs]
74+
[context docs es-cluster-name]
7475
(doseq [docs-batch (partition-all MAX_BULK_OPERATIONS_PER_REQUEST docs)]
7576
(let [bulk-operations (cmr-bulk/create-bulk-index-operations docs-batch)
76-
;; TODO 10636- this conn will not work anymore there is no :db, it's either gran or non-gran cluster, so need to change
77-
conn (get-in context [:system :db :conn])
77+
;; TODO 10636- technically this func to do this conversion already exists in context->es-store in indexer-util.clj, need to organize this later
78+
conn (get-in context [:system (cmr.elastic-utils.config/es-cluster-name-str->keyword es-cluster-name)])
7879
response (es-helper/bulk conn bulk-operations)
7980
;; we don't care about version conflicts or deletes that aren't found
8081
bad-errors (some (fn [item]

elastic-utils-lib/src/cmr/elastic_utils/search/es_index.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@
142142
[ex _scroll-id]
143143
(throw ex))
144144

145-
;; TODO 10636 Fix
145+
;; TODO 10636 - Test
146146
(defn- scroll-search
147147
"Performs a scroll search, handling errors where possible."
148-
[context scroll-id]
148+
[context scroll-id es-cluster-name]
149149
(try
150150
(es-helper/scroll
151-
(context->conn context cmr.elastic-utils.config/gran-elastic-name)
151+
(context->conn context es-cluster-name)
152152
scroll-id
153153
{:scroll (es-config/elastic-scroll-timeout)})
154154
(catch ExceptionInfo e
@@ -189,7 +189,7 @@
189189
(try
190190
(if (pos? max-retries)
191191
(if-let [scroll-id (:scroll-id query)]
192-
(scroll-search context scroll-id)
192+
(scroll-search context scroll-id (get-es-cluster-name-by-index-info-type-name index-info))
193193
(es-helper/search
194194
(context->conn context (get-es-cluster-name-by-index-info-type-name index-info))
195195
(:index-name index-info)

0 commit comments

Comments
 (0)