@cumulus/es-client 10.1.0 → 10.1.2-alpha.0
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/indexer.js +467 -52
- package/package.json +3 -4
- package/search.js +24 -4
- package/testUtils.js +3 -2
- package/LICENSE +0 -60
package/indexer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* functions for transforming and indexing Cumulus Payloads
|
|
2
|
-
* in
|
|
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
|
|
49
|
+
* Indexes a given record to the specified Elasticsearch index and type
|
|
50
50
|
*
|
|
51
|
-
* @param {Object} esClient -
|
|
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,11 +84,99 @@ 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
|
+
|
|
87
175
|
/**
|
|
88
176
|
* Indexes a step function message to Elastic Search. The message must
|
|
89
177
|
* comply with the cumulus message protocol
|
|
90
178
|
*
|
|
91
|
-
* @param {Object} esClient -
|
|
179
|
+
* @param {Object} esClient - Elasticsearch Connection object
|
|
92
180
|
* @param {Object} payload - Cumulus Step Function message
|
|
93
181
|
* @param {string} index - Elasticsearch index alias (default defined in search.js)
|
|
94
182
|
* @param {string} type - Elasticsearch type (default: execution)
|
|
@@ -99,9 +187,9 @@ function indexExecution(esClient, payload, index = defaultIndexAlias, type = 'ex
|
|
|
99
187
|
}
|
|
100
188
|
|
|
101
189
|
/**
|
|
102
|
-
* Indexes the asyncOperation type on
|
|
190
|
+
* Indexes the asyncOperation type on Elasticsearch
|
|
103
191
|
*
|
|
104
|
-
* @param {Object} esClient -
|
|
192
|
+
* @param {Object} esClient - Elasticsearch Connection object
|
|
105
193
|
* @param {Object} payload - Cumulus Step Function message
|
|
106
194
|
* @param {string} index - Elasticsearch index alias (default defined in search.js)
|
|
107
195
|
* @param {string} type - Elasticsearch type (default: asyncOperation)
|
|
@@ -112,23 +200,23 @@ function indexAsyncOperation(esClient, payload, index = defaultIndexAlias, type
|
|
|
112
200
|
}
|
|
113
201
|
|
|
114
202
|
/**
|
|
115
|
-
* Indexes the collection on
|
|
203
|
+
* Indexes the collection on Elasticsearch
|
|
116
204
|
*
|
|
117
|
-
* @param {Object} esClient -
|
|
118
|
-
* @param {Object}
|
|
119
|
-
* @param {string} index
|
|
120
|
-
* @param {string} type
|
|
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)
|
|
121
209
|
* @returns {Promise} Elasticsearch response
|
|
122
210
|
*/
|
|
123
|
-
function indexCollection(esClient,
|
|
124
|
-
const collectionId = constructCollectionId(
|
|
125
|
-
return genericRecordUpdate(esClient, collectionId,
|
|
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);
|
|
126
214
|
}
|
|
127
215
|
|
|
128
216
|
/**
|
|
129
|
-
* Indexes the provider type on
|
|
217
|
+
* Indexes the provider type on Elasticsearch
|
|
130
218
|
*
|
|
131
|
-
* @param {Object} esClient -
|
|
219
|
+
* @param {Object} esClient - Elasticsearch Connection object
|
|
132
220
|
* @param {Object} payload - the provider record
|
|
133
221
|
* @param {string} index - Elasticsearch index alias (default defined in search.js)
|
|
134
222
|
* @param {string} type - Elasticsearch type (default: provider)
|
|
@@ -139,9 +227,9 @@ function indexProvider(esClient, payload, index = defaultIndexAlias, type = 'pro
|
|
|
139
227
|
}
|
|
140
228
|
|
|
141
229
|
/**
|
|
142
|
-
* Indexes the reconciliationReport type on
|
|
230
|
+
* Indexes the reconciliationReport type on Elasticsearch
|
|
143
231
|
*
|
|
144
|
-
* @param {Object} esClient -
|
|
232
|
+
* @param {Object} esClient - Elasticsearch Connection object
|
|
145
233
|
* @param {Object} payload - the ReconciliationReport record
|
|
146
234
|
* @param {string} index - Elasticsearch index alias (default defined in search.js)
|
|
147
235
|
* @param {string} type - Elasticsearch type (default: reconciliationReport)
|
|
@@ -152,9 +240,9 @@ function indexReconciliationReport(esClient, payload, index = defaultIndexAlias,
|
|
|
152
240
|
}
|
|
153
241
|
|
|
154
242
|
/**
|
|
155
|
-
* Indexes the rule type on
|
|
243
|
+
* Indexes the rule type on Elasticsearch
|
|
156
244
|
*
|
|
157
|
-
* @param {Object} esClient -
|
|
245
|
+
* @param {Object} esClient - Elasticsearch Connection object
|
|
158
246
|
* @param {Object} payload - the Rule record
|
|
159
247
|
* @param {string} index - Elasticsearch index alias (default defined in search.js)
|
|
160
248
|
* @param {string} type - Elasticsearch type (default: rule)
|
|
@@ -166,9 +254,9 @@ function indexRule(esClient, payload, index = defaultIndexAlias, type = 'rule')
|
|
|
166
254
|
}
|
|
167
255
|
|
|
168
256
|
/**
|
|
169
|
-
* Indexes the granule type on
|
|
257
|
+
* Indexes the granule type on Elasticsearch
|
|
170
258
|
*
|
|
171
|
-
* @param {Object} esClient -
|
|
259
|
+
* @param {Object} esClient - Elasticsearch Connection object
|
|
172
260
|
* @param {Object} payload - Cumulus Step Function message
|
|
173
261
|
* @param {string} index - Elasticsearch index alias (default defined in search.js)
|
|
174
262
|
* @param {string} type - Elasticsearch type (default: granule)
|
|
@@ -197,9 +285,67 @@ async function indexGranule(esClient, payload, index = defaultIndexAlias, type =
|
|
|
197
285
|
}
|
|
198
286
|
|
|
199
287
|
/**
|
|
200
|
-
*
|
|
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
|
|
201
347
|
*
|
|
202
|
-
* @param {Object} esClient -
|
|
348
|
+
* @param {Object} esClient - Elasticsearch Connection object
|
|
203
349
|
* @param {Object} payload - Cumulus Step Function message
|
|
204
350
|
* @param {string} index - Elasticsearch index alias (default defined in search.js)
|
|
205
351
|
* @param {string} type - Elasticsearch type (default: pdr)
|
|
@@ -216,10 +362,58 @@ async function indexPdr(esClient, payload, index = defaultIndexAlias, type = 'pd
|
|
|
216
362
|
}
|
|
217
363
|
|
|
218
364
|
/**
|
|
219
|
-
*
|
|
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
|
|
220
414
|
*
|
|
221
415
|
* @param {Object} params
|
|
222
|
-
* @param {Object} params.esClient -
|
|
416
|
+
* @param {Object} params.esClient - Elasticsearch Connection object
|
|
223
417
|
* @param {string} params.id - id of the Elasticsearch record
|
|
224
418
|
* @param {string} params.type - Elasticsearch type (default: execution)
|
|
225
419
|
* @param {strint} params.parent - id of the parent (optional)
|
|
@@ -248,50 +442,271 @@ async function deleteRecord({
|
|
|
248
442
|
if (ignore) options = { ignore };
|
|
249
443
|
|
|
250
444
|
const actualEsClient = esClient || (await Search.es());
|
|
251
|
-
|
|
252
|
-
const getResponse = await actualEsClient.get(params, options);
|
|
253
445
|
const deleteResponse = await actualEsClient.delete(params, options);
|
|
254
|
-
|
|
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
446
|
return deleteResponse.body;
|
|
271
447
|
}
|
|
272
448
|
|
|
273
449
|
/**
|
|
274
|
-
*
|
|
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
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Deletes the provider in Elasticsearch
|
|
275
478
|
*
|
|
276
|
-
* @param
|
|
277
|
-
* @param
|
|
278
|
-
* @
|
|
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
|
|
279
486
|
*/
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
+
}
|
|
610
|
+
|
|
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
|
+
});
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Deletes the granule in Elasticsearch
|
|
640
|
+
*
|
|
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
|
|
649
|
+
*/
|
|
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
|
+
});
|
|
283
687
|
}
|
|
284
688
|
|
|
285
689
|
module.exports = {
|
|
286
|
-
addToLocalES,
|
|
287
690
|
createIndex,
|
|
288
691
|
indexCollection,
|
|
289
692
|
indexProvider,
|
|
290
693
|
indexReconciliationReport,
|
|
291
694
|
indexRule,
|
|
292
695
|
indexGranule,
|
|
696
|
+
upsertGranule,
|
|
293
697
|
indexPdr,
|
|
698
|
+
upsertPdr,
|
|
294
699
|
indexExecution,
|
|
295
700
|
indexAsyncOperation,
|
|
296
701
|
deleteRecord,
|
|
702
|
+
deleteAsyncOperation,
|
|
703
|
+
updateAsyncOperation,
|
|
704
|
+
upsertExecution,
|
|
705
|
+
deleteCollection,
|
|
706
|
+
deleteProvider,
|
|
707
|
+
deleteRule,
|
|
708
|
+
deletePdr,
|
|
709
|
+
deleteGranule,
|
|
710
|
+
deleteExecution,
|
|
711
|
+
deleteReconciliationReport,
|
|
297
712
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/es-client",
|
|
3
|
-
"version": "10.1.0",
|
|
3
|
+
"version": "10.1.2-alpha.0",
|
|
4
4
|
"description": "Utilities for working with Elasticsearch",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CUMULUS",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@elastic/elasticsearch": "^5.6.20",
|
|
38
38
|
"aws-elasticsearch-connector": "8.2.0",
|
|
39
39
|
"aws-sdk": "^2.585.0",
|
|
40
|
-
"lodash": "~4.17.
|
|
40
|
+
"lodash": "~4.17.21",
|
|
41
41
|
"moment": "2.29.1",
|
|
42
42
|
"p-limit": "^1.2.0"
|
|
43
43
|
},
|
|
@@ -45,6 +45,5 @@
|
|
|
45
45
|
"@cumulus/aws-client": "10.1.0",
|
|
46
46
|
"@cumulus/test-data": "10.1.0",
|
|
47
47
|
"p-each-series": "^2.1.0"
|
|
48
|
-
}
|
|
49
|
-
"gitHead": "765ba4733ec97540e28cd64dac702eea3b96c654"
|
|
48
|
+
}
|
|
50
49
|
}
|
package/search.js
CHANGED
|
@@ -197,15 +197,30 @@ class BaseSearch {
|
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
async get(id) {
|
|
200
|
+
async get(id, parentId) {
|
|
201
201
|
const body = {
|
|
202
202
|
query: {
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
bool: {
|
|
204
|
+
must: [{
|
|
205
|
+
term: {
|
|
206
|
+
_id: id,
|
|
207
|
+
},
|
|
208
|
+
}],
|
|
205
209
|
},
|
|
206
210
|
},
|
|
207
211
|
};
|
|
208
212
|
|
|
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
|
+
|
|
209
224
|
logDetails.granuleId = id;
|
|
210
225
|
|
|
211
226
|
if (!this.client) {
|
|
@@ -215,7 +230,7 @@ class BaseSearch {
|
|
|
215
230
|
const result = await this.client.search({
|
|
216
231
|
index: this.index,
|
|
217
232
|
type: this.type,
|
|
218
|
-
body
|
|
233
|
+
body,
|
|
219
234
|
}).then((response) => response.body);
|
|
220
235
|
|
|
221
236
|
if (result.hits.total > 1) {
|
|
@@ -230,6 +245,11 @@ class BaseSearch {
|
|
|
230
245
|
return resp;
|
|
231
246
|
}
|
|
232
247
|
|
|
248
|
+
async exists(id, parentId) {
|
|
249
|
+
const response = await this.get(id, parentId);
|
|
250
|
+
return response.detail !== 'Record not found';
|
|
251
|
+
}
|
|
252
|
+
|
|
233
253
|
async granulesStats(key, value) {
|
|
234
254
|
const body = {
|
|
235
255
|
query: {
|
package/testUtils.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
const { randomString } = require('@cumulus/common/test-utils');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const bootstrap = require('./bootstrap');
|
|
4
|
+
|
|
4
5
|
const { Search } = require('./search');
|
|
5
6
|
|
|
6
7
|
const createTestIndex = async () => {
|
|
7
8
|
const esIndex = randomString();
|
|
8
9
|
const esAlias = randomString();
|
|
9
10
|
process.env.ES_INDEX = esIndex;
|
|
10
|
-
await bootstrapElasticSearch('fakehost', esIndex, esAlias);
|
|
11
|
+
await bootstrap.bootstrapElasticSearch('fakehost', esIndex, esAlias);
|
|
11
12
|
const esClient = await Search.es('fakehost');
|
|
12
13
|
return { esIndex, esClient };
|
|
13
14
|
};
|
package/LICENSE
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
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
|