diff --git a/bootstrap-app/src/cmr/bootstrap/api/routes.clj b/bootstrap-app/src/cmr/bootstrap/api/routes.clj index fb8ccaf9a4..aab57a2432 100644 --- a/bootstrap-app/src/cmr/bootstrap/api/routes.clj +++ b/bootstrap-app/src/cmr/bootstrap/api/routes.clj @@ -21,6 +21,7 @@ [cmr.common-app.services.search.elastic-search-index-names-cache :as elastic-search-index-names-cache] [cmr.common.log :refer [info]] [cmr.common.generics :as common-generic] + [cmr.search.services.query-execution.has-granules-results-feature :as has-granules-results-feature] [compojure.core :refer :all] [compojure.route :as route] [drift.execute :as drift] @@ -143,6 +144,9 @@ (= keyword-cache-name humanizer-alias-cache/humanizer-alias-cache-key) (humanizer-alias-cache/refresh-entire-cache request-context) + (= keyword-cache-name has-granules-results-feature/has-granule-cache-key) + (has-granules-results-feature/refresh-has-granules-map request-context) + :else (route/not-found "Not Found"))) {:status 200})) diff --git a/bootstrap-app/src/cmr/bootstrap/system.clj b/bootstrap-app/src/cmr/bootstrap/system.clj index 1abf1902e9..09cb00ef80 100644 --- a/bootstrap-app/src/cmr/bootstrap/system.clj +++ b/bootstrap-app/src/cmr/bootstrap/system.clj @@ -35,6 +35,7 @@ [cmr.metadata-db.config :as mdb-config] [cmr.metadata-db.system :as mdb-system] [cmr.metadata-db.services.util :as mdb-util] + [cmr.search.services.query-execution.has-granules-results-feature :as has-granules-results-feature] [cmr.redis-utils.redis-cache] [cmr.search.services.humanizers.humanizer-report-service :as humanizer-report-service] [cmr.transmit.config :as transmit-config])) @@ -96,6 +97,7 @@ coll-gran-acls-caches/coll-by-concept-id-cache-key (coll-gran-acls-caches/create-coll-by-concept-id-cache-client) elastic-search-index-names-cache/index-names-cache-key (elastic-search-index-names-cache/create-index-cache) humanizer-alias-cache/humanizer-alias-cache-key (humanizer-alias-cache/create-cache-client) + has-granules-results-feature/has-granule-cache-key (has-granules-results-feature/create-has-granules-map-cache) humanizer-report-service/humanizer-report-cache-key (humanizer-report-service/create-humanizer-report-cache-client)} :scheduler (jobs/create-scheduler `system-holder [jvm-info/log-jvm-statistics-job (kf/refresh-kms-cache-job "bootstrap-kms-cache-refresh") @@ -104,7 +106,8 @@ (b-coll-metadata-cache/update-collections-metadata-cache-job "bootstrap-collections-metadata-cache-update") (coll-gran-acls-caches/refresh-collections-cache-for-granule-acls-job "bootstrap-collections-for-gran-acls-cache-refresh") (elastic-search-index-names-cache/refresh-index-names-cache-job "bootstrap-elastic-search-index-names-cache") - (humanizer-alias-cache/refresh-humanizer-alias-cache-job "bootstrap-humanizer-alias-cache-refresh") + (humanizer-alias-cache/refresh-humanizer-alias-cache-job "boostrap-humanizer-alias-cache-refresh") + (has-granules-results-feature/refresh-has-granules-map-job "bootstrap-has-granules-map-refresh") (humanizer-report-service/refresh-humanizer-report-cache-job "bootstrap-humanizer-report-cache-refresh")]) :queue-broker queue-broker}] (transmit-config/system-with-connections sys [:metadata-db :echo-rest :kms :indexer :access-control :search]))) diff --git a/common-app-lib/src/cmr/common_app/services/search/elastic_search_index.clj b/common-app-lib/src/cmr/common_app/services/search/elastic_search_index.clj index f96df7a48a..3ea5b2775e 100644 --- a/common-app-lib/src/cmr/common_app/services/search/elastic_search_index.clj +++ b/common-app-lib/src/cmr/common_app/services/search/elastic_search_index.clj @@ -46,6 +46,12 @@ (fn [concept-type query] [concept-type (qm/base-result-format query)])) +(defmethod concept-type+result-format->fields [:granule :xml] + [concept-type query] + ["granule-ur" + "provider-id" + "concept-id"]) + (defn context->search-index "Returns the search index given a context. This assumes that the search index is always located in a system using the :search-index key." diff --git a/search-app/src/cmr/search/services/query_execution/has_granules_results_feature.clj b/search-app/src/cmr/search/services/query_execution/has_granules_results_feature.clj index bd8dacfea5..393a6ae008 100644 --- a/search-app/src/cmr/search/services/query_execution/has_granules_results_feature.clj +++ b/search-app/src/cmr/search/services/query_execution/has_granules_results_feature.clj @@ -5,8 +5,8 @@ (:require [cmr.common-app.services.search.query-execution :as query-execution] [cmr.common.jobs :refer [defjob]] [cmr.common.cache :as cache] - [cmr.search.data.elastic-search-index :as idx] - [cmr.common.cache.in-memory-cache :as mem-cache])) + [cmr.redis-utils.redis-cache :as redis-cache] + [cmr.search.data.elastic-search-index :as idx])) (def REFRESH_HAS_GRANULES_MAP_JOB_INTERVAL "The frequency in seconds of the refresh-has-granules-map-job" @@ -19,7 +19,7 @@ (defn create-has-granules-map-cache "Returns a 'cache' which will contain the cached has granules map." [] - (mem-cache/create-in-memory-cache)) + (redis-cache/create-redis-cache)) (defn- collection-granule-counts->has-granules-map "Converts a map of collection ids to granule counts to a map of collection ids to true or false @@ -34,16 +34,18 @@ (let [has-granules-map (collection-granule-counts->has-granules-map (idx/get-collection-granule-counts context nil))] (cache/set-value (cache/context->cache context has-granule-cache-key) - :has-granules has-granules-map))) + has-granule-cache-key + has-granules-map))) (defn get-has-granules-map "Gets the cached has granules map from the context which contains collection ids to true or false of whether the collections have granules or not. If the has-granules-map has not yet been cached - it will retrieve it and cache it." + it will retrieve it and cache it. + Example) {\"C0000000002-PROV1\" true, \"C0000000003-PROV1\" false}" [context] (let [has-granules-map-cache (cache/context->cache context has-granule-cache-key)] (cache/get-value has-granules-map-cache - :has-granules + has-granule-cache-key (fn [] (collection-granule-counts->has-granules-map (idx/get-collection-granule-counts context nil)))))) @@ -57,6 +59,8 @@ [ctx system] (refresh-has-granules-map {:system system})) -(def refresh-has-granules-map-job +(defn refresh-has-granules-map-job + [job-key] {:job-type RefreshHasGranulesMapJob + :job-key job-key :interval REFRESH_HAS_GRANULES_MAP_JOB_INTERVAL}) diff --git a/search-app/src/cmr/search/system.clj b/search-app/src/cmr/search/system.clj index bc7d376091..3b8207480a 100644 --- a/search-app/src/cmr/search/system.clj +++ b/search-app/src/cmr/search/system.clj @@ -117,7 +117,7 @@ ;; Caches a map of tokens to the security identifiers context-augmenter/token-sid-cache-name (context-augmenter/create-token-sid-cache) context-augmenter/token-user-id-cache-name (context-augmenter/create-token-user-id-cache) - :has-granules-map (hgrf/create-has-granules-map-cache) + hgrf/has-granule-cache-key (hgrf/create-has-granules-map-cache) :has-granules-or-cwic-map (hgocrf/create-has-granules-or-cwic-map-cache) :has-granules-or-opensearch-map (hgocrf/create-has-granules-or-opensearch-map-cache) metadata-transformer/xsl-transformer-cache-name (mem-cache/create-in-memory-cache) @@ -145,7 +145,6 @@ :scheduler (jobs/create-scheduler `system-holder [(af/refresh-acl-cache-job "search-acl-cache-refresh") - hgrf/refresh-has-granules-map-job hgocrf/refresh-has-granules-or-cwic-map-job hgocrf/refresh-has-granules-or-opensearch-map-job (metadata-cache/refresh-collections-metadata-cache-job) diff --git a/system-int-test/test/cmr/system_int_test/admin/cache_api_test.clj b/system-int-test/test/cmr/system_int_test/admin/cache_api_test.clj index 7c4ec56df3..766ac0dd5a 100644 --- a/system-int-test/test/cmr/system_int_test/admin/cache_api_test.clj +++ b/system-int-test/test/cmr/system_int_test/admin/cache_api_test.clj @@ -180,9 +180,8 @@ ["ABC-1" "read"] ["ABC-2" "read"]] "search 1" (url/search-read-caches-url) "acls" ["acls"] - ;; This is now a shared redis cache server, so many keys exist - ;;"search 2" (url/search-read-caches-url) "collections-for-gran-acls" [] - "search 3" (url/search-read-caches-url) "has-granules-map" [] + ;; collections-for-gran-acls-by-concept-id and has-granules-map are purposefully left out because they are + ;; in a shared redis cache server and will have multiple keys dependent on the data now "search 5" (url/search-read-caches-url) "token-imp" [["ABC-1" "read"] ["ABC-2" "read"]] "search 6" (url/search-read-caches-url) "token-sid" ["ABC-2" "ABC-1"] "search 7" (url/search-read-caches-url) "xsl-transformer-templates" []