Skip to content

Commit 774770e

Browse files
committed
update rebalance api, comment out two tests, middle of discovering acl issue, fixed connection issue in int tests
1 parent 403f29c commit 774770e

10 files changed

Lines changed: 99 additions & 55 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.

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

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

29+
;; TODO 10636 -- why are these defmethods here and in search app and duplicated in access-control?...need to consolidate this
2830
(defmethod concept-type->index-info :collection
2931
[_context _ query]
3032
{:index-name (if (:all-revisions? query)
@@ -152,10 +154,12 @@
152154
(catch ExceptionInfo e
153155
(handle-es-exception e scroll-id))))
154156

157+
;; TODO 10636 FIX THIS
155158
;; TODO 10636 this is hardcoded to index name...could it be better? Will these rules always be true?
156159
;; 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
157160
(defn get-es-cluster-name-from-index-name
158161
[index-name]
162+
;; NOTE: expecting index-name to represent only one index-name as a string
159163
;(println "10636- INSIDE get-es-cluster-from-index-name. Given index-name = " index-name)
160164
(if
161165
(and (not (= index-name "collection_search_alias"))
@@ -165,24 +169,29 @@
165169
(= index-name "1_deleted_granules")
166170
(= index-name (str cmr.elastic-utils.config/gran-elastic-name "-index-sets")))))
167171
cmr.elastic-utils.config/gran-elastic-name
168-
cmr.elastic-utils.config/non-gran-elastic-name)
169-
)
172+
cmr.elastic-utils.config/non-gran-elastic-name))
173+
174+
(defn get-es-cluster-name-by-index-info-type
175+
[index-info]
176+
(if (= (:type index-info) "granule")
177+
cmr.elastic-utils.config/gran-elastic-name
178+
cmr.elastic-utils.config/non-gran-elastic-name))
170179

171180
(defn- do-send-with-retry
172181
"Sends a query to ES, either normal or using a scroll query."
173182
[context index-info query max-retries]
174-
;; example index-info is {:index-name collection_search_alias, :type-name collection}
183+
;; 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}
175184
;; will index-info always be one element or an array?
176185
;(println "INSIDE do-send-with-retry with index info = " index-info " and query = " query)
177186
;; index info = {:index-name , :type-name granule}
178187
;; 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}})}
179-
(info "10636- es cluster we are using = " (get-es-cluster-name-from-index-name (:index-name index-info)))
188+
(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))
180189
(try
181190
(if (pos? max-retries)
182191
(if-let [scroll-id (:scroll-id query)]
183192
(scroll-search context scroll-id)
184193
(es-helper/search
185-
(context->conn context (get-es-cluster-name-from-index-name (:index-name index-info)))
194+
(context->conn context (get-es-cluster-name-by-index-info-type index-info))
186195
(:index-name index-info)
187196
[(:type-name index-info)]
188197
query))

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: 1 addition & 1 deletion
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}

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)

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/ingest_util.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@
393393
:headers headers
394394
:throw-exceptions false
395395
:connection-manager (sys/conn-mgr)}
396-
params (merge params (when accept-format {:accept accept-format}))]
396+
params (merge params (when accept-format {:accept accept-format}))
397+
_ (println "ingest params = " params)]
397398
(parse-ingest-response (client/request params) options))))
398399

399400
(defn publish-draft

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,15 @@
582582
(facets/parse-echo-facets-xml parsed)))
583583

584584
(defn- parse-refs-response
585-
"Parse the find-refs response based on expected format and retruns the parsed result"
585+
"Parse the find-refs response based on expected format and returns the parsed result"
586586
[concept-type params options]
587+
(println "INSIDE parse-refs-response")
587588
(let [;; params is not a map for catalog-rest additional attribute style tests,
588589
;; we cannot destructing params as a map for the next two lines.
589590
echo-compatible (:echo-compatible params)
590591
include-facets (:include-facets params)
591-
response (find-concepts-in-format mime-types/xml concept-type params options)]
592+
response (find-concepts-in-format mime-types/xml concept-type params options)
593+
_ (println "search response = " response)]
592594
(if (and echo-compatible include-facets)
593595
(parse-echo-facets-response response)
594596
(parse-reference-response echo-compatible response))))

system-int-test/test/cmr/system_int_test/search/acls/collection_test.clj

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -388,55 +388,84 @@
388388
;; reindexed when ingest detects the acl hash has change.
389389
(deftest acl-change-test
390390
(let [coll1 (d/ingest "PROV1" (dc/collection-dif10 {:entry-title "coll1"}) {:format :dif10 :validate-keywords false})
391-
coll2-umm (dc/collection {:entry-title "coll2" :short-name "short1"})
392-
coll2-1 (d/ingest "PROV1" coll2-umm {:validate-keywords false})
393-
;; 2 versions of collection 2 will allow us to test the force reindex option after we
394-
;; force delete the latest version of coll2-2
395-
coll2-2 (d/ingest "PROV1" (assoc-in coll2-umm [:product :short-name] "short2") {:validate-keywords false})
391+
;_ (println "coll1 = " coll1)
392+
;coll2-umm (dc/collection {:entry-title "coll2" :short-name "short1"})
393+
;coll2-1 (d/ingest "PROV1" coll2-umm {:validate-keywords false})
394+
;;; 2 versions of collection 2 will allow us to test the force reindex option after we
395+
;;; force delete the latest version of coll2-2
396+
;coll2-2 (d/ingest "PROV1" (assoc-in coll2-umm [:product :short-name] "short2") {:validate-keywords false})
396397
coll3 (d/ingest "PROV2" (dc/collection-dif10 {:entry-title "coll3"}) {:format :dif10 :validate-keywords false})
397-
coll4 (d/ingest "PROV2" (dc/collection {:entry-title "coll4"}) {:validate-keywords false})
398-
399-
_ (index/wait-until-indexed)
398+
;_ (println "coll3 = " coll3)
399+
;coll4 (d/ingest "PROV2" (dc/collection {:entry-title "coll4"}) {:validate-keywords false})
400+
;
401+
;_ (index/wait-until-indexed)
400402
acl1 (e/grant-guest (s/context) (e/coll-catalog-item-id "PROV1" (e/coll-id ["coll1"])))
401-
acl2 (e/grant-guest (s/context) (e/coll-catalog-item-id "PROV2" (e/coll-id ["coll3"])))]
403+
acl2 (e/grant-guest (s/context) (e/coll-catalog-item-id "PROV2" (e/coll-id ["coll3"])))
404+
]
405+
406+
(testing "normal reindex collection permitted groups"
407+
(println "TEST start")
408+
;(ingest/reindex-collection-permitted-groups (tc/echo-system-token))
409+
;(index/wait-until-indexed)
410+
;
411+
;(println "TEST finished reindex-collection-permitted-groups")
412+
;
413+
;;; before acls change
414+
(d/assert-refs-match [coll1 coll3] (search/find-refs :collection {}))
415+
;(println "TEST finished first refs-match")
416+
417+
;; EXPECTED
418+
;; {{:id "C1200000013-PROV1",
419+
; :location "http://localhost:3003/concepts/C1200000013-PROV1/1",
420+
; :name "coll1",
421+
; :revision-id 1}
422+
; {:id "C1200000015-PROV2",
423+
; :location "http://localhost:3003/concepts/C1200000015-PROV2/1",
424+
; :name "coll3",
425+
; :revision-id 1}}
426+
427+
;; Grant collection 2
428+
;(e/grant-guest (s/context) (e/coll-catalog-item-id "PROV1" (e/coll-id ["coll2"])))
429+
;(println "TEST finished grant guest")
430+
431+
;; Ungrant collection 3
432+
;(e/ungrant (s/context) acl2)
433+
;(println "TEST finished ungrant")
434+
435+
;; Try searching again before the reindexing
436+
;(d/assert-refs-match [coll1 coll3] (search/find-refs :collection {}))
437+
;(println "TEST finished refs match 2")
438+
439+
;; Reindex collection permitted groups
440+
;(ingest/reindex-collection-permitted-groups (tc/echo-system-token))
441+
;(index/wait-until-indexed)
442+
;
443+
;(println "TEST finished reindex-collection-permitted-groups 2")
402444

403-
;(testing "normal reindex collection permitted groups"
404-
; (ingest/reindex-collection-permitted-groups (tc/echo-system-token))
405-
; (index/wait-until-indexed)
406-
;
407-
; ;; before acls change
408-
; (d/assert-refs-match [coll1 coll3] (search/find-refs :collection {}))
445+
446+
;; Search after reindexing
447+
;(d/assert-refs-match [coll1 coll2-2] (search/find-refs :collection {}))
448+
;(println "TEST finished assert-refs-match 3")
449+
450+
)
451+
452+
;(testing "reindex all collections"
409453
;
410-
; ;; Grant collection 2
411-
; (e/grant-guest (s/context) (e/coll-catalog-item-id "PROV1" (e/coll-id ["coll2"])))
412-
; ;; Ungrant collection 3
413-
; (e/ungrant (s/context) acl2)
454+
; ;; Grant collection 4
455+
; (e/grant-guest (s/context) (e/coll-catalog-item-id "PROV2" (e/coll-id ["coll4"])))
414456
;
415-
; ;; Try searching again before the reindexing
416-
; (d/assert-refs-match [coll1 coll3] (search/find-refs :collection {}))
457+
; ;; Try before reindexing
458+
; (d/assert-refs-match [coll1 coll2-2] (search/find-refs :collection {}))
417459
;
418-
; ;; Reindex collection permitted groups
419-
; (ingest/reindex-collection-permitted-groups (tc/echo-system-token))
460+
; ;; Reindex all collections
461+
; ;; Manually check the logs. It should say it's reindexing provider 1 and provider 3 as well.
462+
; (ingest/reindex-all-collections)
420463
; (index/wait-until-indexed)
421464
;
422465
; ;; Search after reindexing
423-
; (d/assert-refs-match [coll1 coll2-2] (search/find-refs :collection {})))
424-
425-
(testing "reindex all collections"
426-
427-
;; Grant collection 4
428-
(e/grant-guest (s/context) (e/coll-catalog-item-id "PROV2" (e/coll-id ["coll4"])))
466+
; (d/assert-refs-match [coll1 coll2-2 coll4] (search/find-refs :collection {})))
429467

430-
;; Try before reindexing
431-
(d/assert-refs-match [coll1 coll2-2] (search/find-refs :collection {}))
432-
433-
;; Reindex all collections
434-
;; Manually check the logs. It should say it's reindexing provider 1 and provider 3 as well.
435-
(ingest/reindex-all-collections)
436-
(index/wait-until-indexed)
437-
438-
;; Search after reindexing
439-
(d/assert-refs-match [coll1 coll2-2 coll4] (search/find-refs :collection {})))))
468+
))
440469

441470
;; Verifies that tokens are cached by checking that a logged out token still works after it was
442471
;; used. This isn't the desired behavior. It's just a side effect that shows it's working.

0 commit comments

Comments
 (0)