@cumulus/es-client 10.1.2-alpha.0 → 10.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,60 @@
1
+ Copyright © 2020 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
4
+ You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICE NSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
10
+
11
+ ---
12
+
13
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14
+
15
+ 1. Definitions.
16
+
17
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
18
+
19
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
20
+
21
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
26
+
27
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
28
+
29
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
30
+
31
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
32
+
33
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
34
+
35
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
36
+
37
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
38
+
39
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
40
+
41
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
42
+
43
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
44
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
45
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
46
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
47
+
48
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
49
+
50
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
51
+
52
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
53
+
54
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
55
+
56
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
57
+
58
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
59
+
60
+ END OF TERMS AND CONDITIONS
package/indexer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* functions for transforming and indexing Cumulus Payloads
2
- * in Elasticsearch. These functions are specifically designed
2
+ * in ElasticSearch. These functions are specifically designed
3
3
  * to transform data for use in cumulus api
4
4
  *
5
5
  * The module accepts the following kinds of workflows (state machines):
@@ -46,9 +46,9 @@ async function createIndex(esClient, indexName) {
46
46
  }
47
47
 
48
48
  /**
49
- * Indexes a given record to the specified Elasticsearch index and type
49
+ * Indexes a given record to the specified ElasticSearch index and type
50
50
  *
51
- * @param {Object} esClient - Elasticsearch Connection object
51
+ * @param {Object} esClient - ElasticSearch Connection object
52
52
  * @param {string} id - the record id
53
53
  * @param {Object} doc - the record
54
54
  * @param {string} index - Elasticsearch index alias
@@ -84,99 +84,11 @@ async function genericRecordUpdate(esClient, id, doc, index, type, parent) {
84
84
  return indexResponse.body;
85
85
  }
86
86
 
87
- /**
88
- * Updates a given record for the Elasticsearch index and type
89
- *
90
- * @param {Object} esClient - Elasticsearch Connection object
91
- * @param {string} id - the record id
92
- * @param {Object} doc - the record
93
- * @param {string} index - Elasticsearch index alias
94
- * @param {string} type - Elasticsearch type
95
- * @returns {Promise} Elasticsearch response
96
- */
97
- async function updateExistingRecord(esClient, id, doc, index, type) {
98
- return await esClient.update({
99
- index,
100
- type,
101
- id,
102
- body: {
103
- doc: {
104
- ...doc,
105
- timestamp: Date.now(),
106
- },
107
- },
108
- refresh: inTestMode(),
109
- });
110
- }
111
-
112
- /**
113
- * Updates an asyncOperation record in Elasticsearch
114
- *
115
- * @param {Object} esClient - Elasticsearch Connection object
116
- * @param {Object} id - Record ID
117
- * @param {Object} updates - Document of updates to apply
118
- * @param {string} index - Elasticsearch index alias (default defined in search.js)
119
- * @param {string} type - Elasticsearch type (default: asyncOperation)
120
- * @returns {Promise} elasticsearch update response
121
- */
122
- function updateAsyncOperation(esClient, id, updates, index = defaultIndexAlias, type = 'asyncOperation') {
123
- return updateExistingRecord(esClient, id, updates, index, type);
124
- }
125
-
126
- /**
127
- * Upsert an execution record in Elasticsearch
128
- *
129
- * @param {Object} params
130
- * @param {Object} params.esClient - Elasticsearch Connection object
131
- * @param {Object} params.updates - Document of updates to apply
132
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
133
- * @param {string} params.type - Elasticsearch type (default: execution)
134
- * @param {string} [params.refresh] - whether to refresh the index on update or not
135
- * @returns {Promise} elasticsearch update response
136
- */
137
- async function upsertExecution({
138
- esClient,
139
- updates,
140
- index = defaultIndexAlias,
141
- type = 'execution',
142
- refresh,
143
- }) {
144
- const upsertDoc = {
145
- ...updates,
146
- timestamp: Date.now(),
147
- };
148
- return await esClient.update({
149
- index,
150
- type,
151
- id: upsertDoc.arn,
152
- body: {
153
- script: {
154
- lang: 'painless',
155
- inline: `
156
- if (params.doc.status == "running") {
157
- ctx._source.updatedAt = params.doc.updatedAt;
158
- ctx._source.timestamp = params.doc.timestamp;
159
- ctx._source.originalPayload = params.doc.originalPayload;
160
- } else {
161
- ctx._source.putAll(params.doc)
162
- }
163
- `,
164
- params: {
165
- doc: upsertDoc,
166
- },
167
- },
168
- upsert: upsertDoc,
169
- },
170
- refresh: refresh !== undefined ? refresh : inTestMode(),
171
- retry_on_conflict: 3,
172
- });
173
- }
174
-
175
87
  /**
176
88
  * Indexes a step function message to Elastic Search. The message must
177
89
  * comply with the cumulus message protocol
178
90
  *
179
- * @param {Object} esClient - Elasticsearch Connection object
91
+ * @param {Object} esClient - ElasticSearch Connection object
180
92
  * @param {Object} payload - Cumulus Step Function message
181
93
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
182
94
  * @param {string} type - Elasticsearch type (default: execution)
@@ -187,9 +99,9 @@ function indexExecution(esClient, payload, index = defaultIndexAlias, type = 'ex
187
99
  }
188
100
 
189
101
  /**
190
- * Indexes the asyncOperation type on Elasticsearch
102
+ * Indexes the asyncOperation type on ElasticSearch
191
103
  *
192
- * @param {Object} esClient - Elasticsearch Connection object
104
+ * @param {Object} esClient - ElasticSearch Connection object
193
105
  * @param {Object} payload - Cumulus Step Function message
194
106
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
195
107
  * @param {string} type - Elasticsearch type (default: asyncOperation)
@@ -200,23 +112,23 @@ function indexAsyncOperation(esClient, payload, index = defaultIndexAlias, type
200
112
  }
201
113
 
202
114
  /**
203
- * Indexes the collection on Elasticsearch
115
+ * Indexes the collection on ElasticSearch
204
116
  *
205
- * @param {Object} esClient - Elasticsearch Connection object
206
- * @param {Object} collection - the collection record
207
- * @param {string} index - Elasticsearch index alias (default defined in search.js)
208
- * @param {string} type - Elasticsearch type (default: collection)
117
+ * @param {Object} esClient - ElasticSearch Connection object
118
+ * @param {Object} meta - the collection record
119
+ * @param {string} index - Elasticsearch index alias (default defined in search.js)
120
+ * @param {string} type - Elasticsearch type (default: collection)
209
121
  * @returns {Promise} Elasticsearch response
210
122
  */
211
- function indexCollection(esClient, collection, index = defaultIndexAlias, type = 'collection') {
212
- const collectionId = constructCollectionId(collection.name, collection.version);
213
- return genericRecordUpdate(esClient, collectionId, collection, index, type);
123
+ function indexCollection(esClient, meta, index = defaultIndexAlias, type = 'collection') {
124
+ const collectionId = constructCollectionId(meta.name, meta.version);
125
+ return genericRecordUpdate(esClient, collectionId, meta, index, type);
214
126
  }
215
127
 
216
128
  /**
217
- * Indexes the provider type on Elasticsearch
129
+ * Indexes the provider type on ElasticSearch
218
130
  *
219
- * @param {Object} esClient - Elasticsearch Connection object
131
+ * @param {Object} esClient - ElasticSearch Connection object
220
132
  * @param {Object} payload - the provider record
221
133
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
222
134
  * @param {string} type - Elasticsearch type (default: provider)
@@ -227,9 +139,9 @@ function indexProvider(esClient, payload, index = defaultIndexAlias, type = 'pro
227
139
  }
228
140
 
229
141
  /**
230
- * Indexes the reconciliationReport type on Elasticsearch
142
+ * Indexes the reconciliationReport type on ElasticSearch
231
143
  *
232
- * @param {Object} esClient - Elasticsearch Connection object
144
+ * @param {Object} esClient - ElasticSearch Connection object
233
145
  * @param {Object} payload - the ReconciliationReport record
234
146
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
235
147
  * @param {string} type - Elasticsearch type (default: reconciliationReport)
@@ -240,9 +152,9 @@ function indexReconciliationReport(esClient, payload, index = defaultIndexAlias,
240
152
  }
241
153
 
242
154
  /**
243
- * Indexes the rule type on Elasticsearch
155
+ * Indexes the rule type on ElasticSearch
244
156
  *
245
- * @param {Object} esClient - Elasticsearch Connection object
157
+ * @param {Object} esClient - ElasticSearch Connection object
246
158
  * @param {Object} payload - the Rule record
247
159
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
248
160
  * @param {string} type - Elasticsearch type (default: rule)
@@ -254,9 +166,9 @@ function indexRule(esClient, payload, index = defaultIndexAlias, type = 'rule')
254
166
  }
255
167
 
256
168
  /**
257
- * Indexes the granule type on Elasticsearch
169
+ * Indexes the granule type on ElasticSearch
258
170
  *
259
- * @param {Object} esClient - Elasticsearch Connection object
171
+ * @param {Object} esClient - ElasticSearch Connection object
260
172
  * @param {Object} payload - Cumulus Step Function message
261
173
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
262
174
  * @param {string} type - Elasticsearch type (default: granule)
@@ -285,67 +197,9 @@ async function indexGranule(esClient, payload, index = defaultIndexAlias, type =
285
197
  }
286
198
 
287
199
  /**
288
- * Upserts a granule in Elasticsearch
289
- *
290
- * @param {Object} params
291
- * @param {Object} params.esClient - Elasticsearch Connection object
292
- * @param {Object} params.updates - Updates to make
293
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
294
- * @param {string} params.type - Elasticsearch type (default: granule)
295
- * @param {string} [params.refresh] - whether to refresh the index on update or not
296
- * @returns {Promise} Elasticsearch response
297
- */
298
- async function upsertGranule({
299
- esClient,
300
- updates,
301
- index = defaultIndexAlias,
302
- type = 'granule',
303
- refresh,
304
- }) {
305
- // If the granule exists in 'deletedgranule', delete it first before inserting the granule
306
- // into ES. Ignore 404 error, so the deletion still succeeds if the record doesn't exist.
307
- const delGranParams = {
308
- index,
309
- type: 'deletedgranule',
310
- id: updates.granuleId,
311
- parent: updates.collectionId,
312
- refresh: inTestMode(),
313
- };
314
- await esClient.delete(delGranParams, { ignore: [404] });
315
-
316
- const upsertDoc = updates;
317
-
318
- return await esClient.update({
319
- index,
320
- type,
321
- id: updates.granuleId,
322
- parent: updates.collectionId,
323
- body: {
324
- script: {
325
- lang: 'painless',
326
- inline: `
327
- if ((ctx._source.createdAt === null || params.doc.createdAt >= ctx._source.createdAt)
328
- && (params.doc.status != 'running' || (params.doc.status == 'running' && params.doc.execution != ctx._source.execution))) {
329
- ctx._source.putAll(params.doc);
330
- } else {
331
- ctx.op = 'none';
332
- }
333
- `,
334
- params: {
335
- doc: upsertDoc,
336
- },
337
- },
338
- upsert: upsertDoc,
339
- },
340
- refresh: refresh !== undefined ? refresh : inTestMode(),
341
- retry_on_conflict: 3,
342
- });
343
- }
344
-
345
- /**
346
- * Indexes the pdr type on Elasticsearch
200
+ * Indexes the pdr type on ElasticSearch
347
201
  *
348
- * @param {Object} esClient - Elasticsearch Connection object
202
+ * @param {Object} esClient - ElasticSearch Connection object
349
203
  * @param {Object} payload - Cumulus Step Function message
350
204
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
351
205
  * @param {string} type - Elasticsearch type (default: pdr)
@@ -362,58 +216,10 @@ async function indexPdr(esClient, payload, index = defaultIndexAlias, type = 'pd
362
216
  }
363
217
 
364
218
  /**
365
- * Upsert a PDR record in Elasticsearch
366
- *
367
- * @param {Object} params
368
- * @param {Object} params.esClient - Elasticsearch Connection object
369
- * @param {Object} params.updates - Document to upsert
370
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
371
- * @param {string} params.type - Elasticsearch type (default: execution)
372
- * @param {string} [params.refresh] - whether to refresh the index on update or not
373
- * @returns {Promise} elasticsearch update response
374
- */
375
- async function upsertPdr({
376
- esClient,
377
- updates,
378
- index = defaultIndexAlias,
379
- type = 'pdr',
380
- refresh,
381
- }) {
382
- const upsertDoc = {
383
- ...updates,
384
- timestamp: Date.now(),
385
- };
386
- return await esClient.update({
387
- index,
388
- type,
389
- id: upsertDoc.pdrName,
390
- body: {
391
- script: {
392
- lang: 'painless',
393
- inline: `
394
- if ((ctx._source.createdAt === null || params.doc.createdAt >= ctx._source.createdAt)
395
- && (params.doc.execution != ctx._source.execution || params.doc.progress > ctx._source.progress)) {
396
- ctx._source.putAll(params.doc);
397
- } else {
398
- ctx.op = 'none';
399
- }
400
- `,
401
- params: {
402
- doc: upsertDoc,
403
- },
404
- },
405
- upsert: upsertDoc,
406
- },
407
- refresh: refresh !== undefined ? refresh : inTestMode(),
408
- retry_on_conflict: 3,
409
- });
410
- }
411
-
412
- /**
413
- * delete a record from Elasticsearch
219
+ * delete a record from ElasticSearch
414
220
  *
415
221
  * @param {Object} params
416
- * @param {Object} params.esClient - Elasticsearch Connection object
222
+ * @param {Object} params.esClient - ElasticSearch Connection object
417
223
  * @param {string} params.id - id of the Elasticsearch record
418
224
  * @param {string} params.type - Elasticsearch type (default: execution)
419
225
  * @param {strint} params.parent - id of the parent (optional)
@@ -442,271 +248,50 @@ async function deleteRecord({
442
248
  if (ignore) options = { ignore };
443
249
 
444
250
  const actualEsClient = esClient || (await Search.es());
445
- const deleteResponse = await actualEsClient.delete(params, options);
446
- return deleteResponse.body;
447
- }
448
-
449
- /**
450
- * Deletes the collection in Elasticsearch
451
- *
452
- * @param {Object} params
453
- * @param {Object} params.esClient - Elasticsearch Connection object
454
- * @param {string} params.collectionId - the collection ID
455
- * @param {string[]} [params.ignore] - Array of response codes to ignore
456
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
457
- * @param {string} params.type - Elasticsearch type (default: collection)
458
- * @returns {Promise} Elasticsearch response
459
- */
460
- function deleteCollection({
461
- esClient,
462
- collectionId,
463
- ignore,
464
- index = defaultIndexAlias,
465
- type = 'collection',
466
- }) {
467
- return deleteRecord({
468
- esClient,
469
- id: collectionId,
470
- index,
471
- type,
472
- ignore,
473
- });
474
- }
475
251
 
476
- /**
477
- * Deletes the provider in Elasticsearch
478
- *
479
- * @param {Object} params
480
- * @param {Object} params.esClient - Elasticsearch Connection object
481
- * @param {string} params.id - the provider ID
482
- * @param {string[]} [params.ignore] - Array of response codes to ignore
483
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
484
- * @param {string} params.type - Elasticsearch type (default: provider)
485
- * @returns {Promise} Elasticsearch response
486
- */
487
- function deleteProvider({
488
- esClient,
489
- id,
490
- ignore,
491
- index = defaultIndexAlias,
492
- type = 'provider',
493
- }) {
494
- return deleteRecord({
495
- esClient,
496
- id,
497
- index,
498
- type,
499
- ignore,
500
- });
501
- }
502
-
503
- /**
504
- * Deletes the rule in Elasticsearch
505
- *
506
- * @param {Object} params
507
- * @param {Object} params.esClient - Elasticsearch Connection object
508
- * @param {string} params.name - the rule name
509
- * @param {string[]} [params.ignore] - Array of response codes to ignore
510
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
511
- * @param {string} params.type - Elasticsearch type (default: rule)
512
- * @returns {Promise} Elasticsearch response
513
- */
514
- function deleteRule({
515
- esClient,
516
- name,
517
- ignore,
518
- index = defaultIndexAlias,
519
- type = 'rule',
520
- }) {
521
- return deleteRecord({
522
- esClient,
523
- id: name,
524
- index,
525
- type,
526
- ignore,
527
- });
528
- }
529
-
530
- /**
531
- * Deletes the PDR in Elasticsearch
532
- *
533
- * @param {Object} params
534
- * @param {Object} params.esClient - Elasticsearch Connection object
535
- * @param {string} params.name - the PDR name
536
- * @param {string[]} [params.ignore] - Array of response codes to ignore
537
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
538
- * @param {string} params.type - Elasticsearch type (default: PDR)
539
- * @returns {Promise} Elasticsearch response
540
- */
541
- function deletePdr({
542
- esClient,
543
- name,
544
- ignore,
545
- index = defaultIndexAlias,
546
- type = 'pdr',
547
- }) {
548
- return deleteRecord({
549
- esClient,
550
- id: name,
551
- index,
552
- type,
553
- ignore,
554
- });
555
- }
556
-
557
- /**
558
- * Deletes the execution in Elasticsearch
559
- *
560
- * @param {Object} params
561
- * @param {Object} params.esClient - Elasticsearch Connection object
562
- * @param {string} params.arn - execution ARN
563
- * @param {string[]} [params.ignore] - Array of response codes to ignore
564
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
565
- * @param {string} params.type - Elasticsearch type (default: execution)
566
- * @returns {Promise} Elasticsearch response
567
- */
568
- function deleteExecution({
569
- esClient,
570
- arn,
571
- ignore,
572
- index = defaultIndexAlias,
573
- type = 'execution',
574
- }) {
575
- return deleteRecord({
576
- esClient,
577
- id: arn,
578
- index,
579
- type,
580
- ignore,
581
- });
582
- }
583
-
584
- /**
585
- * Deletes the async operation in Elasticsearch
586
- *
587
- * @param {Object} params
588
- * @param {Object} params.esClient - Elasticsearch Connection object
589
- * @param {string} params.id - the async operation ID
590
- * @param {string[]} [params.ignore] - Array of response codes to ignore
591
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
592
- * @param {string} params.type - Elasticsearch type (default: asyncOperation)
593
- * @returns {Promise} Elasticsearch response
594
- */
595
- function deleteAsyncOperation({
596
- esClient,
597
- id,
598
- ignore,
599
- index = defaultIndexAlias,
600
- type = 'asyncOperation',
601
- }) {
602
- return deleteRecord({
603
- esClient,
604
- id,
605
- index,
606
- type,
607
- ignore,
608
- });
609
- }
252
+ const getResponse = await actualEsClient.get(params, options);
253
+ const deleteResponse = await actualEsClient.delete(params, options);
610
254
 
611
- /**
612
- * Deletes the reconciliation report from Elasticsearch
613
- *
614
- * @param {Object} params
615
- * @param {Object} params.esClient - Elasticsearch Connection object
616
- * @param {string} params.name - reconciliation report name
617
- * @param {string[]} [params.ignore] - Array of response codes to ignore
618
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
619
- * @param {string} params.type - Elasticsearch type (default: reconciliationReport)
620
- * @returns {Promise} Elasticsearch response
621
- */
622
- function deleteReconciliationReport({
623
- esClient,
624
- name,
625
- ignore,
626
- index = defaultIndexAlias,
627
- type = 'reconciliationReport',
628
- }) {
629
- return deleteRecord({
630
- esClient,
631
- id: name,
632
- index,
633
- type,
634
- ignore,
635
- });
255
+ if (type === 'granule' && getResponse.body.found) {
256
+ const doc = getResponse.body._source;
257
+ doc.timestamp = Date.now();
258
+ doc.deletedAt = Date.now();
259
+
260
+ // When a 'granule' record is deleted, the record is added to 'deletedgranule' type
261
+ await genericRecordUpdate(
262
+ actualEsClient,
263
+ doc.granuleId,
264
+ doc,
265
+ index,
266
+ 'deletedgranule',
267
+ parent
268
+ );
269
+ }
270
+ return deleteResponse.body;
636
271
  }
637
272
 
638
273
  /**
639
- * Deletes the granule in Elasticsearch
274
+ * Index a record to local Elasticsearch. Used when running API locally.
640
275
  *
641
- * @param {Object} params
642
- * @param {Object} params.esClient - Elasticsearch Connection object
643
- * @param {string} params.granuleId - the granule ID
644
- * @param {string} params.collectionId - the collection ID
645
- * @param {string[]} [params.ignore] - Array of response codes to ignore
646
- * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
647
- * @param {string} params.type - Elasticsearch type (default: granule)
648
- * @returns {Promise} Elasticsearch response
276
+ * @param {Object} record - Record object
277
+ * @param {function} doIndex - Function to do indexing operation
278
+ * @returns {Promise} - Promise of indexing operation
649
279
  */
650
- async function deleteGranule({
651
- esClient,
652
- granuleId,
653
- collectionId,
654
- ignore,
655
- index = defaultIndexAlias,
656
- type = 'granule',
657
- }) {
658
- const esGranulesClient = new Search(
659
- {},
660
- type,
661
- index
662
- );
663
- const granuleEsRecord = await esGranulesClient.get(granuleId, collectionId);
664
-
665
- // When a 'granule' record is deleted, the record is added to 'deletedgranule' type
666
- const deletedGranuleDoc = granuleEsRecord;
667
- delete deletedGranuleDoc._id;
668
- deletedGranuleDoc.timestamp = Date.now();
669
- deletedGranuleDoc.deletedAt = Date.now();
670
- await genericRecordUpdate(
671
- esClient,
672
- granuleId,
673
- deletedGranuleDoc,
674
- index,
675
- 'deletedgranule',
676
- collectionId
677
- );
678
-
679
- return await deleteRecord({
680
- esClient,
681
- id: granuleId,
682
- parent: collectionId,
683
- index,
684
- type,
685
- ignore,
686
- });
280
+ async function addToLocalES(record, doIndex) {
281
+ const esClient = await Search.es(process.env.ES_HOST);
282
+ return doIndex(esClient, record, process.env.ES_INDEX);
687
283
  }
688
284
 
689
285
  module.exports = {
286
+ addToLocalES,
690
287
  createIndex,
691
288
  indexCollection,
692
289
  indexProvider,
693
290
  indexReconciliationReport,
694
291
  indexRule,
695
292
  indexGranule,
696
- upsertGranule,
697
293
  indexPdr,
698
- upsertPdr,
699
294
  indexExecution,
700
295
  indexAsyncOperation,
701
296
  deleteRecord,
702
- deleteAsyncOperation,
703
- updateAsyncOperation,
704
- upsertExecution,
705
- deleteCollection,
706
- deleteProvider,
707
- deleteRule,
708
- deletePdr,
709
- deleteGranule,
710
- deleteExecution,
711
- deleteReconciliationReport,
712
297
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/es-client",
3
- "version": "10.1.2-alpha.0",
3
+ "version": "10.1.2",
4
4
  "description": "Utilities for working with Elasticsearch",
5
5
  "keywords": [
6
6
  "CUMULUS",
@@ -30,10 +30,10 @@
30
30
  "author": "Cumulus Authors",
31
31
  "license": "Apache-2.0",
32
32
  "dependencies": {
33
- "@cumulus/common": "10.1.0",
34
- "@cumulus/errors": "10.1.0",
35
- "@cumulus/logger": "10.1.0",
36
- "@cumulus/message": "10.1.0",
33
+ "@cumulus/common": "10.1.2",
34
+ "@cumulus/errors": "10.1.2",
35
+ "@cumulus/logger": "10.1.2",
36
+ "@cumulus/message": "10.1.2",
37
37
  "@elastic/elasticsearch": "^5.6.20",
38
38
  "aws-elasticsearch-connector": "8.2.0",
39
39
  "aws-sdk": "^2.585.0",
@@ -42,8 +42,9 @@
42
42
  "p-limit": "^1.2.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@cumulus/aws-client": "10.1.0",
46
- "@cumulus/test-data": "10.1.0",
45
+ "@cumulus/aws-client": "10.1.2",
46
+ "@cumulus/test-data": "10.1.2",
47
47
  "p-each-series": "^2.1.0"
48
- }
48
+ },
49
+ "gitHead": "3b59753fa85064549b70ad8ed4a4ee213c5af313"
49
50
  }
package/search.js CHANGED
@@ -197,30 +197,15 @@ class BaseSearch {
197
197
  };
198
198
  }
199
199
 
200
- async get(id, parentId) {
200
+ async get(id) {
201
201
  const body = {
202
202
  query: {
203
- bool: {
204
- must: [{
205
- term: {
206
- _id: id,
207
- },
208
- }],
203
+ term: {
204
+ _id: id,
209
205
  },
210
206
  },
211
207
  };
212
208
 
213
- if (parentId) {
214
- body.query.bool.must.push(
215
- {
216
- parent_id: {
217
- id: parentId,
218
- type: this.type,
219
- },
220
- }
221
- );
222
- }
223
-
224
209
  logDetails.granuleId = id;
225
210
 
226
211
  if (!this.client) {
@@ -230,7 +215,7 @@ class BaseSearch {
230
215
  const result = await this.client.search({
231
216
  index: this.index,
232
217
  type: this.type,
233
- body,
218
+ body: body,
234
219
  }).then((response) => response.body);
235
220
 
236
221
  if (result.hits.total > 1) {
@@ -245,11 +230,6 @@ class BaseSearch {
245
230
  return resp;
246
231
  }
247
232
 
248
- async exists(id, parentId) {
249
- const response = await this.get(id, parentId);
250
- return response.detail !== 'Record not found';
251
- }
252
-
253
233
  async granulesStats(key, value) {
254
234
  const body = {
255
235
  query: {
package/testUtils.js CHANGED
@@ -1,14 +1,13 @@
1
1
  const { randomString } = require('@cumulus/common/test-utils');
2
2
 
3
- const bootstrap = require('./bootstrap');
4
-
3
+ const { bootstrapElasticSearch } = require('./bootstrap');
5
4
  const { Search } = require('./search');
6
5
 
7
6
  const createTestIndex = async () => {
8
7
  const esIndex = randomString();
9
8
  const esAlias = randomString();
10
9
  process.env.ES_INDEX = esIndex;
11
- await bootstrap.bootstrapElasticSearch('fakehost', esIndex, esAlias);
10
+ await bootstrapElasticSearch('fakehost', esIndex, esAlias);
12
11
  const esClient = await Search.es('fakehost');
13
12
  return { esIndex, esClient };
14
13
  };