Skip to content

Commit 8918130

Browse files
committed
Merge branch 'CMR-10636' into CMR-10636-jn
2 parents 87e6203 + 774770e commit 8918130

21 files changed

Lines changed: 155 additions & 99 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,14 @@
311311
{ctx :request-context params :params}
312312
(acl/verify-ingest-management-permission ctx :update)
313313
(pv/validate-standard-params params)
314-
(reindex-groups ctx))
314+
(reindex-groups ctx)) ;; TODO CMR-10636 -- need to change this func?
315315

316316
;; Reindex all acls
317317
(POST "/reindex-acls"
318318
{ctx :request-context params :params}
319319
(acl/verify-ingest-management-permission ctx :update)
320320
(pv/validate-standard-params params)
321-
(reindex-acls ctx))
321+
(reindex-acls ctx)) ;; TODO CMR-10636 -- need to change this func?
322322

323323
(if (access-control-config/enable-cmr-groups)
324324
(context "/groups" []

access-control-app/src/cmr/access_control/services/acl_service.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@
464464
(remove nil?)
465465
parse-single-string-multi-valued-bucket-lists)))
466466

467+
;; TODO CMR-10636 - this is a duplicate method from elastic-utils and I think we can remove this and add it as a dependency in this project... but have to really test it out to see.
467468
(defmethod common-esi/concept-type->index-info :collection
468469
[_context _ query]
469470
;; This function mirrors the multimethod definition in search.

dev-system/src/cmr/dev_system/control.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@
119119
:when (get-in system [:apps service-name])]
120120
(reset-fn (app-context system service-name)))
121121
;; After reset some elasticsearch indexes may not be initialized yet. We will check the status here
122-
(elastic-conn/wait-for-healthy-elastic (get-in system [:apps :indexer :db]))
122+
(elastic-conn/wait-for-healthy-elastic (get-in system [:apps :indexer :gran-elastic]))
123+
(elastic-conn/wait-for-healthy-elastic (get-in system [:apps :indexer :non-gran-elastic]))
123124
(debug "dev system /reset complete")
124125
{:status 200})
125126

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
(defmulti concept-type->index-info
2323
"Returns index info based on input concept type. The map should contain a :type-name key along
2424
with an :index-name key. :index-name can refer to a single index or a comma separated string of
25-
multiple index names."
25+
multiple index names.
26+
All index name strings in index-name are expected to be the same type as :type-name."
2627
(fn [_context concept-type _query]
2728
concept-type))
2829

30+
;; TODO 10636 -- why are these defmethods here and in search app and duplicated in access-control?...need to consolidate this
2931
(defmethod concept-type->index-info :collection
3032
[_context _ query]
3133
{:index-name (if (:all-revisions? query)
@@ -61,9 +63,9 @@
6163
in a system using the :search-index key."
6264
[context es-cluster-name]
6365
(cond
64-
(= es-cluster-name cmr.elastic-utils.config/non-gran-elastic-name) (get-in context [:system :non-gran-search-index])
65-
(= es-cluster-name cmr.elastic-utils.config/gran-elastic-name) (get-in context [:system :gran-search-index])
66-
:else (throw (Exception. (str "expected specific elastic name but got " es-cluster-name " instead.")))))
66+
(= es-cluster-name cmr.elastic-utils.config/non-gran-elastic-name) (get-in context [:system :non-gran-search-index])
67+
(= es-cluster-name cmr.elastic-utils.config/gran-elastic-name) (get-in context [:system :gran-search-index])
68+
:else (throw (Exception. (str "expected specific elastic name but got " es-cluster-name " instead.")))))
6769

6870
(defn context->conn
6971
"Returns the connection given a context. This assumes that the search index is always located in
@@ -153,11 +155,14 @@
153155
(catch ExceptionInfo e
154156
(handle-es-exception e scroll-id))))
155157

158+
;; TODO 10636 FIX THIS
156159
;; TODO 10636 this is hardcoded to index name...could it be better? Will these rules always be true?
157160
;; TODO unit test this -- need a sys test as well, so that if any index is created or found, we will auto warn that something could break with this
158161
(defn get-es-cluster-name-from-index-name
159162
"Returns the Elasticsearch cluster name based on the index name."
160163
[index-name]
164+
;; NOTE: expecting index-name to represent only one index-name as a string
165+
;(println "10636- INSIDE get-es-cluster-from-index-name. Given index-name = " index-name)
161166
(let [gran-cluster cmr.elastic-utils.config/gran-elastic-name
162167
non-gran-cluster cmr.elastic-utils.config/non-gran-elastic-name
163168
gran-index-set-name (str gran-cluster "-index-sets")
@@ -170,29 +175,34 @@
170175
(or (string/starts-with? index-name "1_c")
171176
(gran-specific-indices index-name)
172177
(= index-name gran-index-set-name)))]
173-
174178
(if uses-gran-cluster?
175179
gran-cluster
176180
non-gran-cluster)))
177181

182+
(defn get-es-cluster-name-by-index-info-type
183+
[index-info]
184+
(if (= (:type index-info) "granule")
185+
cmr.elastic-utils.config/gran-elastic-name
186+
cmr.elastic-utils.config/non-gran-elastic-name))
187+
178188
(defn- do-send-with-retry
179189
"Sends a query to ES, either normal or using a scroll query."
180190
[context index-info query max-retries]
181-
;; example index-info is {:index-name collection_search_alias, :type-name collection}
191+
;; example index-info is {:index-name collection_search_alias, :type-name collection} OR {:index-name 1_c*,1_small_collections,-1_collections*, :type-name granule}
182192
;; will index-info always be one element or an array?
183193
;(println "INSIDE do-send-with-retry with index info = " index-info " and query = " query)
184194
;; index info = {:index-name , :type-name granule}
185195
;; query = {:search_type query_then_fetch, :size 10, :from 0, :timeout 170s, :version true, :query {:bool {:must {:match_all {}}, :filter {:bool {:must ({:term {:collection-concept-id-doc-values C1200000001-JM_PROV1}} {:term {:concept-id G1200000002-JM_PROV1}})}}}}, :_source (:concept-id :revision-id :native-id-stored :provider-id-doc-values :metadata-format :revision-date-stored-doc-values :collection-concept-id-doc-values), :sort ({:provider-id-lowercase-doc-values {:order :asc}} {:start-date-doc-values {:order :asc}} {:concept-seq-id-long {:order asc}})}
186-
(info "10636- es cluster we are using = " (get-es-cluster-name-from-index-name (:index-name index-info)))
196+
(println "10636- INSIDE do-send-with-retry with index-info = " index-info ". Determined the es cluster is = " (get-es-cluster-name-by-index-info-type index-info))
187197
(try
188198
(if (pos? max-retries)
189199
(if-let [scroll-id (:scroll-id query)]
190200
(scroll-search context scroll-id)
191201
(es-helper/search
192-
(context->conn context (get-es-cluster-name-from-index-name (:index-name index-info)))
193-
(:index-name index-info)
194-
[(:type-name index-info)]
195-
query))
202+
(context->conn context (get-es-cluster-name-by-index-info-type index-info))
203+
(:index-name index-info)
204+
[(:type-name index-info)]
205+
query))
196206
(errors/throw-service-error :service-unavailable "Exhausted retries to execute ES query"))
197207

198208
(catch UnknownHostException _e
@@ -284,10 +294,10 @@
284294
(set/rename-keys {:search-after :search_after})
285295
util/remove-nil-keys)]
286296
(debug "Executing against indexes [" (:index-name index-info) "] the elastic query:"
287-
(pr-str elastic-query)
288-
"with sort" (pr-str sort-params)
289-
"with aggregations" (pr-str aggregations)
290-
"and highlights" (pr-str highlights))
297+
(pr-str elastic-query)
298+
"with sort" (pr-str sort-params)
299+
"with aggregations" (pr-str aggregations)
300+
"and highlights" (pr-str highlights))
291301
(when-let [scroll-id (:scroll-id query-map)]
292302
(debug "Using scroll-id" scroll-id))
293303
(when-let [search-after (:search_after query-map)]

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

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

1010
;; *************************************************************************************************
1111

12+
;; TODO CMR-10636 -- whereever this is called will have to change, we cannot just add the acls to the query anymore
1213
(defmulti add-acl-conditions-to-query
1314
"Adds conditions to the query to enforce ACLs."
1415
(fn [_context query]

indexer-app/src/cmr/indexer/api/routes.clj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
; ;;TODO 10636 fix this, we need to incorporate the non-gran-index-set resp too
4242
; (r/created gran-index-set-resp))
4343
;; In the meantime, we are not going to allow this functionality.
44-
{:status 200})
44+
{:status 500})
4545

4646
;; respond with index-sets in elastic
4747
(GET "/" {request-context :request-context}
@@ -77,26 +77,25 @@
7777
(index-set-svc/delete-index-set request-context id cmr.elastic-utils.config/non-gran-elastic-name)
7878
{:status 204})
7979

80-
;; TODO 10636 We need to update all these endpoints to work with the new clusters
80+
;; TODO 10636 Updated. Need to test that it worked.
8181
(context "/rebalancing-collections/:concept-id" [concept-id]
8282

8383
;; Marks the collection as re-balancing in the index set.
8484
(POST "/start" {request-context :request-context params :params}
85-
;(acl/verify-ingest-management-permission request-context :update)
86-
;(index-set-svc/mark-collection-as-rebalancing request-context id concept-id (:target params))
87-
;{:status 200}
85+
(acl/verify-ingest-management-permission request-context :update)
86+
(index-set-svc/mark-collection-as-rebalancing request-context id concept-id (:target params))
8887
{:status 200})
8988

9089
;; Update the status of collection being rebalanced
9190
(POST "/update-status" {request-context :request-context params :params}
92-
;(acl/verify-ingest-management-permission request-context :update)
93-
;(index-set-svc/update-collection-rebalancing-status request-context id concept-id (:status params))
91+
(acl/verify-ingest-management-permission request-context :update)
92+
(index-set-svc/update-collection-rebalancing-status request-context id concept-id (:status params))
9493
{:status 200})
9594

9695
;; Marks the collection as completed rebalancing
9796
(POST "/finalize" {request-context :request-context}
98-
;(acl/verify-ingest-management-permission request-context :update)
99-
;(index-set-svc/finalize-collection-rebalancing request-context id concept-id)
97+
(acl/verify-ingest-management-permission request-context :update)
98+
(index-set-svc/finalize-collection-rebalancing request-context id concept-id)
10099
{:status 200})))))
101100

102101
;; Note for future. We should cleanup this API. It's not very well layed out.

indexer-app/src/cmr/indexer/data/elasticsearch.clj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@
219219
[context index]
220220
(info (format "Deleting granule index %s from elastic" index))
221221
(try
222-
(let [es-cluster-name (cmr.elastic-utils.search.es-index/get-es-cluster-name-from-index-name index)]
223-
(esi/delete-index (indexer-util/context->conn context es-cluster-name) index)
224-
)
222+
(esi/delete-index (indexer-util/context->conn context cmr.elastic-utils.config/gran-elastic-name) index)
225223
(catch Throwable e
226224
(error e (str "Failed to delete granule index: "
227225
(pr-str index))))))
@@ -438,7 +436,7 @@
438436
(delete-document context es-indexes es-type concept-id revision-id elastic-version nil))
439437
([context es-indexes _es-type concept-id revision-id elastic-version options]
440438
(doseq [es-index es-indexes]
441-
;; Cannot use elastisch for deletion as we require special headers on delete
439+
;; Cannot use elasticsearch for deletion as we require special headers on delete
442440
(let [es-cluster-name (cmr.elastic-utils.search.es-index/get-es-cluster-name-from-index-name es-index)
443441
{:keys [admin-token]} (context->es-config context)
444442
{:keys [uri http-opts]} (indexer-util/context->conn context es-cluster-name)

indexer-app/src/cmr/indexer/services/index_service.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@
888888

889889
(defn reindex-all-collections
890890
"Reindexes all collections in all providers. This is only called in the indexer when humanizers
891-
are updated and we only index the latest collection revision."
891+
are updated, and we only index the latest collection revision."
892892
[context]
893893
(let [providers (map :provider-id (meta-db2/get-providers context))]
894894
(info "Sending events to reindex collections in all providers:" (pr-str providers))

search-app/src/cmr/search/api/concepts_search.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"Invokes query service to parse the JSON query, find results and return
115115
the response."
116116
[ctx path-w-extension params headers json-query]
117+
(println "INSIDE find-concepts-by-json-query")
117118
(let [concept-type (concept-type-path-w-extension->concept-type path-w-extension)
118119
params (core-api/process-params concept-type params path-w-extension headers mt/xml)
119120
_ (when (= :stac (:result-format params))
@@ -208,6 +209,7 @@
208209
"Invokes query service to parse the parameters query, find results, and
209210
return the response"
210211
[ctx path-w-extension params headers body]
212+
(println "INSIDE find-concepts-by-parameters")
211213
(let [concept-type (concept-type-path-w-extension->concept-type path-w-extension)
212214
short-scroll-id (get headers (string/lower-case common-routes/SCROLL_ID_HEADER))
213215
scroll-id-and-search-params (core-api/get-scroll-id-and-search-params-from-cache ctx short-scroll-id)
@@ -244,6 +246,7 @@
244246
in the way that we need, we have to make two queries here to support CMR
245247
Harvesting. This can later be generalized easily, should the need arise."
246248
[ctx path-w-extension params headers body]
249+
(println "INSIDE search find-concepts.")
247250
(let [content-type-header (get headers (string/lower-case common-routes/CONTENT_TYPE_HEADER))
248251
search-after (get headers (string/lower-case common-routes/SEARCH_AFTER_HEADER))
249252
_ (validate-search-after-value search-after)

system-int-test/src/cmr/system_int_test/utils/dev_system_util.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
(qb-side-api/wait-for-terminal-states)
2626
(try
2727
(client/post (url/dev-system-reset-url) (admin-connect-options))
28-
(index/refresh-elastic-index)
28+
(index/refresh-all-elastic-indexes)
2929
(load-kms-redis-cache) ;; This will cause the redis cache to reload
3030
(catch Exception e
3131
(error "Failed to send reset to dev-system\n" e)

0 commit comments

Comments
 (0)