Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion bootstrap-app/src/cmr/bootstrap/api/resharding.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
[cmr.bootstrap.api.messages :as msg]
[cmr.bootstrap.api.util :as api-util]
[cmr.bootstrap.services.bootstrap-service :as service]
[cmr.common.services.errors :as errors]))
[cmr.common.services.errors :as errors]
[cmr.elastic-utils.es-index-helper :as es-helper]
[cmr.elastic-utils.search.es-index :as es-index]))

(defn- validate-num-shards
"Validates that the number of shards is a positive integer."
Expand All @@ -27,11 +29,23 @@
(when (string/blank? es-cluster-name)
(errors/throw-service-error :bad-request "Empty elastic cluster name is not allowed.")))

(defn- validate-index-exists
[context index es-cluster-name]
(let [conn (es-index/context->conn context es-cluster-name)]
(when-not (or (es-helper/exists? conn index)
(es-helper/alias-exists? conn index))
(errors/throw-service-error
:not-found
(format "Index or alias [%s] does not exist in the Elasticsearch cluster [%s]"
index
es-cluster-name)))))

(defn start
"Kicks off resharding of an index."
[context index params]
(let [es-cluster-name (:elastic_name params)
_ (validate-es-cluster-name-not-blank es-cluster-name)
_ (validate-index-exists context index es-cluster-name)
num-shards-str (:num_shards params)
_ (validate-num-shards num-shards-str)
dispatcher (api-util/get-dispatcher context params :migrate-index)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(bootstrap/start-reshard-index "1_small_collections" {:synchronous false :num-shards "abc" :elastic-name gran-elastic-name}))))
(testing "index must exist"
(is (= {:status 404
:errors ["Index [1_non-existing-index] does not exist."]}
:errors [(format "Index or alias [%s] does not exist in the Elasticsearch cluster [%s]" "1_non-existing-index" gran-elastic-name)]}
(bootstrap/start-reshard-index "1_non-existing-index" {:synchronous false :num-shards 1 :elastic-name gran-elastic-name}))))
(testing "attempting to reshard an index that is already being resharded fails"
(is (= {:status 200
Expand Down