|
7 | 7 | [cmr.common.concepts :as cs] |
8 | 8 | [cmr.common.config :as cfg :refer [defconfig]] |
9 | 9 | [cmr.common.generics :as common-generic] |
| 10 | + [cmr.common.hash-cache :as hcache] |
10 | 11 | [cmr.common.log :as log :refer (info error)] |
11 | 12 | [cmr.common.util :as util] |
12 | 13 | [cmr.common.services.errors :as errors] |
13 | 14 | [cmr.elastic-utils.index-util :as m :refer [defmapping defnestedmapping]] |
| 15 | + [cmr.elastic-utils.search.es-index-name-cache :as elastic-search-index-names-cache] |
14 | 16 | [cmr.indexer.data.index-set-generics :as index-set-gen] |
15 | 17 | [cmr.indexer.data.index-set-elasticsearch :as index-set-es] |
16 | 18 | [cmr.indexer.services.index-set-service :as index-set-service] |
|
1103 | 1105 | :indexer-index-set-cache) |
1104 | 1106 |
|
1105 | 1107 | (comment |
| 1108 | + (let [cache (cache/context->cache context1 index-set-cache-key)] |
| 1109 | + (cache/get-keys cache)) |
| 1110 | + (let [cache (cache/context->cache context1 index-set-cache-key)] |
| 1111 | + (cache/get-value cache :concept-mapping-types)) |
| 1112 | + (let [cache (cache/context->cache context1 index-set-cache-key)] |
| 1113 | + (cache/get-value cache :concept-indices)) |
1106 | 1114 | (let [cache (cache/context->cache context index-set-cache-key)] |
1107 | 1115 | (cache/get-keys cache)) |
| 1116 | + |
1108 | 1117 | (let [cache (cache/context->cache context index-set-cache-key)] |
1109 | 1118 | (cache/get-value cache :concept-mapping-types)) |
1110 | 1119 |
|
|
1122 | 1131 | (cache/get-value cache :concept-indices (partial fetch-concept-type-index-names context)))) |
1123 | 1132 |
|
1124 | 1133 | (defn set-concept-type-index-names |
1125 | | - "Fetch index names associated with concepts." |
| 1134 | + "Set index names associated with concepts." |
1126 | 1135 | [context value] |
1127 | | - (def context1 context) |
| 1136 | + (def context2 context) |
1128 | 1137 | (let [cache (cache/context->cache context index-set-cache-key)] |
1129 | 1138 | (cache/set-value cache :concept-indices value))) |
1130 | 1139 |
|
|
1167 | 1176 |
|
1168 | 1177 | ; (index-requested-index-set context index-set))) |
1169 | 1178 |
|
1170 | | -(comment |
1171 | | - (let [index-set (index-set-es/get-index-set context index-set-id)] |
1172 | | - (get-in index-set [:index-set :granule]) |
1173 | | - ;(cmr.indexer.services.index-set-service/update-index-set context index-set) |
| 1179 | +(defn set-search-index-names-cache |
| 1180 | + "" |
| 1181 | + [context index-kw index-name] |
| 1182 | + (let [cache (hcache/context->cache context elastic-search-index-names-cache/index-names-cache-key) |
| 1183 | + granule (hcache/get-value cache elastic-search-index-names-cache/index-names-cache-key "granule") |
| 1184 | + new-granule (assoc granule index-kw index-name)] |
| 1185 | + (hcache/set-value cache elastic-search-index-names-cache/index-names-cache-key "granule" new-granule))) |
| 1186 | + |
| 1187 | +(comment |
| 1188 | + (println coll-concept-id) |
| 1189 | + (let [coll-concept-id "C12323-PROV2" |
| 1190 | + {:keys [index-names rebalancing-collections]} (get-concept-type-index-names context) |
| 1191 | + indexes (:granule index-names) |
| 1192 | + provider (util/safe-lowercase (cs/concept-id->provider-id coll-concept-id)) |
| 1193 | + idx-name (str "granules_" provider) |
| 1194 | + idx (get indexes (keyword idx-name))] |
| 1195 | + idx |
1174 | 1196 | ) |
1175 | | - |
1176 | | - (println target-index-key) |
1177 | | - update-index-set |
1178 | | - (get-granule-index-names-for-collection context "C1200000001-PROV2" nil) |
1179 | | - (let [index-names (get-concept-type-index-names context)] |
1180 | | - (get-in index-names [:index-names :granule])) |
1181 | | - (let [{:keys [index-names rebalancing-collections]} (get-concept-type-index-names context) |
1182 | | - indexes (:granule index-names)] |
1183 | | - indexes) |
1184 | | - ; (get indexes :small_collections)) |
1185 | | - (get-granule-index-names-for-provider context "prov6") |
1186 | | - ) |
| 1197 | + |
| 1198 | + ) |
1187 | 1199 | (defn get-granule-index-names-for-collection |
1188 | 1200 | "Return the granule index names for the input collection concept id. Optionally a |
1189 | 1201 | target-index-key can be specified which indicates that a specific index should be returned" |
|
1200 | 1212 | (let [provider (util/safe-lowercase (cs/concept-id->provider-id coll-concept-id)) |
1201 | 1213 | idx-name (str "granules_" provider) |
1202 | 1214 | idx (get indexes (keyword idx-name))] |
1203 | | - ;(println "idx:" idx) |
1204 | 1215 | (if idx |
1205 | 1216 | idx |
1206 | | - (let [index-set (index-set-es/get-index-set context index-set-id) |
| 1217 | + (let [_ (println "idx-name:" idx-name) |
| 1218 | + _ (println "indexes:" indexes) |
| 1219 | + _ (println "coll-concept-id:" coll-concept-id) |
| 1220 | + index-set (index-set-es/get-index-set context index-set-id) |
1207 | 1221 | ;; This sets the index names in ES index. |
1208 | | - new-index-set (try |
1209 | | - (let [new-idx-set (add-new-granule-provider-index index-set idx-name)] |
1210 | | - (index-set-service/update-index-set context new-idx-set)) |
1211 | | - (catch Exception e |
1212 | | - (println (format "index %s already exists." idx-name)) |
1213 | | - index-set)) |
| 1222 | + new-index-set (let [new-idx-set (add-new-granule-provider-index index-set idx-name)] |
| 1223 | + (try |
| 1224 | + (index-set-service/update-index-set context new-idx-set) |
| 1225 | + (catch Exception _e |
| 1226 | + (println (format "index %s already exists." idx-name)) |
| 1227 | + new-idx-set))) |
1214 | 1228 | _ (println "new-index-set" new-index-set) |
| 1229 | + _ (when (nil? new-index-set) |
| 1230 | + (println "index-set is:" index-set) |
| 1231 | + (println "index-set is:" (:index-set index-set)) |
| 1232 | + (println "index-set is granule:" (:granule (:index-set index-set))) |
| 1233 | + (println "index-set is:" (:indexes (:granule (:index-set index-set))))) |
1215 | 1234 | new-index-name (str index-set-id "_" idx-name) |
1216 | 1235 | new-index-names (update-in (get-concept-type-index-names context) [:index-names :granule] #(assoc % (keyword idx-name) new-index-name)) |
1217 | 1236 | ;; This needs to set the in memory cache |
1218 | | - _ (set-concept-type-index-names context new-index-names)] |
1219 | | - new-index-name))) |
1220 | | - (get indexes :small_collections)) |
1221 | | - ] |
| 1237 | + _ (set-concept-type-index-names context new-index-names) |
| 1238 | + ;; this needs to set the search redis cache - this cache and the one above need to be combined into redis |
1222 | 1239 |
|
| 1240 | + _ (set-search-index-names-cache context (keyword idx-name) new-index-name)] |
| 1241 | + new-index-name))) |
| 1242 | + (get indexes :small_collections))] |
1223 | 1243 | (cond |
1224 | 1244 | target-index-key |
1225 | 1245 | [(get indexes target-index-key)] |
|
0 commit comments