Skip to content

Commit 9697121

Browse files
CMR-7354: Allow requester to specify verbosity of bulk granule update task status (#1257)
* Recognize three new query parameters on the ingest/granule-bulk-update/status/:task-id endpoint: show_progress, show_request, and show_granules
1 parent f4f4fc8 commit 9697121

File tree

7 files changed

+208
-34
lines changed

7 files changed

+208
-34
lines changed

ingest-app/docs/api.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,16 @@ curl -i \
13091309

13101310
To get a detailed task status for a given granule bulk update task, user can send an HTTP GET request to `%CMR-ENDPOINT%/granule-bulk-update/status/<task-id>`
13111311

1312-
This returns the status of the bulk update task including the overall task status (IN_PROGRESS or COMPLETE), an overall task status message, the original request JSON body, and the status of each granule updated. The granule status includes the granule-ur, the granule update status (PENDING, UPDATED, SKIPPED, FAILED), and a status message. FAILED indicates an error occurred either updating the granule or during granule validation. SKIPPED indicates the update didn't happen because the update operation does not apply to the granule. The error will be reported in the granule status message.
1312+
This returns the status of the bulk update task including the overall task status (IN_PROGRESS or COMPLETE), the name of the task, and the time the task began processing. Additionally, there are optional query parameters which will increase the verbosity of this response:
1313+
1314+
`show_progress=true`
1315+
When specified, this parameter will return a progress message indicating the number of granules which have been processed out of the total number of granules in the request.
1316+
1317+
`show_granules=true`
1318+
This parameter will return the individual granule status for all granules in the request, which includes the granule-ur and the granule update status (PENDING, UPDATED, SKIPPED, or FAILED). FAILED indicates an error occurred either updating the granule or during granule validation. SKIPPED indicates the update didn't happen because the update operation does not apply to the granule. The error will be reported in the granule status message. Note that this parameter can cause the response to become much larger, scaling with the size of the original bulk update request.
1319+
1320+
`show_request=true`
1321+
This parameter will return the original json body used to initiate the bulk update. Note that this parameter, like before, can cause the response to become much larger, scaling with the size of the original bulk update request.
13131322

13141323
The only supported response format for granule bulk update task status is application/json.
13151324

@@ -1319,7 +1328,7 @@ Example of granule bulk update task status:
13191328
curl -i \
13201329
-H "Echo-Token: XXXX" \
13211330
-H "Cmr-Pretty:true" \
1322-
%CMR-ENDPOINT%/granule-bulk-update/status/3
1331+
%CMR-ENDPOINT%/granule-bulk-update/status/3?show_granules=true&show_request=true
13231332
13241333
{
13251334
"status" : 200,
@@ -1347,4 +1356,3 @@ By default the bulk granule update jobs are checked for completion every 5 minut
13471356
```
13481357
curl -XPOST -i -H "Echo-Token: XXXX" %CMR-ENDPOINT%/granule-bulk-update/status
13491358
```
1350-

ingest-app/src/cmr/ingest/api/bulk.clj

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,51 @@
188188
:request-json-body (:request-json-body task-status)
189189
:collection-statuses collection-statuses}))))
190190

191+
(defn- generate-status-progress-message
192+
"Generate progress message for an in-progress bulk granule update"
193+
[granule-statuses]
194+
(let [gran-count (count granule-statuses)
195+
pending-count (count (filter #(= (:status %) "PENDING") granule-statuses))]
196+
(if (zero? pending-count)
197+
(format "Complete.")
198+
(format "Of %d total granules, %d granules have been processed and %d are still pending."
199+
gran-count (- gran-count pending-count) pending-count))))
200+
201+
202+
(defn- get-granule-task-status-response-generator
203+
"Generates the response for a bulk granule update task status request. Depending on the parameters
204+
show_request, show_progress, and show_granules, the response will be more or less verbose.
205+
show_progress and show_granules require a full query of granules in the request, which can cause
206+
this response generation to be much more expensive."
207+
[request-context task-id gran-task params]
208+
(let [{:keys [name created-at status status-message request-json-body]} gran-task
209+
{:keys [show_request show_progress show_granules]} params
210+
;this call makes the status response much more expensive to retrieve
211+
granule-statuses (when (or (= "true" show_progress) (= "true" show_granules))
212+
(data-gran-bulk-update/get-bulk-update-granule-statuses-for-task
213+
request-context task-id))
214+
response-fields {:status 200
215+
:created-at created-at
216+
:name name
217+
:task-status status
218+
:status-message status-message}
219+
extra-fields (as-> {} intermediate
220+
(if (= "true" show_progress)
221+
(assoc intermediate :progress (generate-status-progress-message
222+
granule-statuses))
223+
intermediate)
224+
(if (= "true" show_request)
225+
(assoc intermediate :request-json-body request-json-body)
226+
intermediate)
227+
(if (= "true" show_granules)
228+
(assoc intermediate :granule-statuses granule-statuses)
229+
intermediate))]
230+
(conj response-fields extra-fields)))
231+
191232
(defn get-granule-task-status
192-
"Get the status for the given task including granule statuses"
193-
[task-id request]
194-
(let [{:keys [headers request-context]} request
233+
"Get the status for the given bulk granule update task"
234+
[request task-id]
235+
(let [{:keys [headers request-context params]} request
195236
_ (validate-granule-bulk-update-result-format headers)
196237
gran-task (data-gran-bulk-update/get-granule-task-by-id request-context task-id)
197238
provider-id (:provider-id gran-task)]
@@ -203,18 +244,9 @@
203244
(api-core/verify-provider-exists request-context provider-id)
204245
(acl/verify-ingest-management-permission request-context :read :provider-object provider-id)
205246

206-
(let [{:keys [name created-at status status-message request-json-body]} gran-task
207-
granule-statuses (data-gran-bulk-update/get-bulk-update-granule-statuses-for-task
208-
request-context task-id)]
209-
(api-core/generate-ingest-response
210-
(assoc headers "accept" mt/json)
211-
{:status 200
212-
:created-at created-at
213-
:name name
214-
:task-status status
215-
:status-message status-message
216-
:request-json-body request-json-body
217-
:granule-statuses granule-statuses}))))
247+
(api-core/generate-ingest-response
248+
(assoc headers "accept" mt/json)
249+
(get-granule-task-status-response-generator request-context task-id gran-task params))))
218250

219251
(defn update-completed-granule-task-statuses
220252
"On demand capability to update granule task statuses. Marks bulk granule

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
(context "/:task-id" [task-id]
109109
(GET "/"
110110
request
111-
(bulk/get-granule-task-status task-id request)))))
111+
(bulk/get-granule-task-status request task-id)))))
112112
;; Provider ingest routes
113113
(api-core/set-default-error-format
114114
:xml
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(ns cmr.ingest.api.bulk-test
2+
"tests functions in bulk update api"
3+
(:require
4+
[clojure.test :refer :all]
5+
[cmr.common.util :as u :refer [are3]]
6+
[cmr.ingest.api.bulk :as bulk]))
7+
8+
(deftest generate-status-progress-message
9+
(are3 [granule-statuses message]
10+
(is (= message (#'bulk/generate-status-progress-message granule-statuses)))
11+
12+
"All updates complete"
13+
[{:granule-ur "GranUR1" :status "UPDATED"}
14+
{:granule-ur "GranUR2" :status "UPDATED"}]
15+
"Complete."
16+
17+
"Some updates complete"
18+
[{:granule-ur "GranUR1" :status "PENDING"}
19+
{:granule-ur "GranUR2" :status "FAILED"}
20+
{:granule-ur "GranUR3" :status "UPDATED"}]
21+
"Of 3 total granules, 2 granules have been processed and 1 are still pending."
22+
23+
"No updates complete"
24+
[{:granule-ur "GranUR1" :status "PENDING"}]
25+
"Of 1 total granules, 0 granules have been processed and 1 are still pending."))

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@
696696
"Implementation function to get the bulk update task status for the given task id"
697697
[concept-type provider-id task-id options]
698698
(let [accept-format (get options :accept-format)
699+
query-params (get options :query-params)
699700
token (:token options)
700701
task-status-url (if (= :collection concept-type)
701702
(url/ingest-collection-bulk-update-task-status-url provider-id task-id)
@@ -704,6 +705,7 @@
704705
:url task-status-url
705706
:connection-manager (s/conn-mgr)
706707
:throw-exceptions false}
708+
params (merge params (when query-params {:query-params query-params}))
707709
params (merge params (when accept-format {:accept accept-format}))
708710
params (merge params (when token {:headers {transmit-config/token-header token}}))
709711
default-result-format (if (= :collection concept-type) :xml :json)

system-int-test/test/cmr/system_int_test/ingest/granule_bulk_update/granule_bulk_update_flow_test.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,15 @@
179179
:status-message (format "Granule UR [SC:non-existent] in task-id [%s] does not exist."
180180
task3-id)}]}]
181181
(testing "default result format"
182-
(let [response (ingest/granule-bulk-update-task-status task3-id)]
182+
(let [status-req-options {:query-params {:show_granules "true" :show_request "true"}}
183+
response (ingest/granule-bulk-update-task-status task3-id status-req-options)]
183184
(is (= task3-expected
184185
(dissoc response :created-at)))))
185186

186187
(testing "JSON result format"
187-
(let [response (ingest/granule-bulk-update-task-status
188-
task3-id {:accept-format :json})]
188+
(let [status-req-options {:query-params {:show_granules "true" :show_request "true"}
189+
:accept-format :json}
190+
response (ingest/granule-bulk-update-task-status task3-id status-req-options)]
189191
(is (= task3-expected
190192
(dissoc response :created-at)))))
191193

0 commit comments

Comments
 (0)