@cumulus/integration-tests 20.3.1 → 21.0.1
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/cmr.js +74 -24
- package/dist/index.js +586 -382
- package/index.js +1 -0
- package/package.json +12 -12
package/cmr.js
CHANGED
|
@@ -182,11 +182,13 @@ async function waitForConceptExistsOutcome(cmrLink, expectation) {
|
|
|
182
182
|
* @param {Object} granule - granule object
|
|
183
183
|
* @param {Object} collection - collection object
|
|
184
184
|
* @param {Array<string>} additionalUrls - URLs to convert to online resources
|
|
185
|
+
* @param {boolean} matchFilesWithProducerGranuleId - When set to true, use the 'producerGranuleId'
|
|
185
186
|
* @returns {Promise<Array<string>>} - Promise of the generated granule xml string
|
|
186
187
|
* CMR xml files
|
|
187
188
|
*/
|
|
188
|
-
function generateCmrXml(granule, collection, additionalUrls
|
|
189
|
-
|
|
189
|
+
function generateCmrXml(granule, collection, additionalUrls,
|
|
190
|
+
matchFilesWithProducerGranuleId = false) {
|
|
191
|
+
const xmlObject = structuredClone(sampleEcho10Granule);
|
|
190
192
|
const oldGranuleId = xmlObject.Granule.GranuleUR;
|
|
191
193
|
xmlObject.Granule.GranuleUR = granule.granuleId;
|
|
192
194
|
|
|
@@ -196,8 +198,10 @@ function generateCmrXml(granule, collection, additionalUrls) {
|
|
|
196
198
|
};
|
|
197
199
|
|
|
198
200
|
xmlObject.Granule.OnlineAccessURLs.forEach((url) => {
|
|
201
|
+
const replacementId = (matchFilesWithProducerGranuleId && granule.producerGranuleId)
|
|
202
|
+
? granule.producerGranuleId : granule.granuleId;
|
|
199
203
|
// eslint-disable-next-line no-param-reassign
|
|
200
|
-
url.OnlineAccessURL.URL = url.OnlineAccessURL.URL.replace(oldGranuleId,
|
|
204
|
+
url.OnlineAccessURL.URL = url.OnlineAccessURL.URL.replace(oldGranuleId, replacementId);
|
|
201
205
|
});
|
|
202
206
|
|
|
203
207
|
if (additionalUrls) {
|
|
@@ -220,21 +224,28 @@ function generateCmrXml(granule, collection, additionalUrls) {
|
|
|
220
224
|
* @param {Object} collection - collection object
|
|
221
225
|
* @param {string} bucket - bucket to save the xml file to
|
|
222
226
|
* @param {Array<string>} additionalUrls - URLs to convert to online resources
|
|
227
|
+
* @param {string} stagingDir - staging directory
|
|
228
|
+
* @param {boolean} matchFilesWithProducerGranuleId - When set to true, use the 'producerGranuleId'
|
|
229
|
+
* instead default behavior of using 'granuleId' when generating filenames.
|
|
223
230
|
* @returns {Promise<Array<string>>} - Promise of a list of granule files including the created
|
|
224
231
|
* CMR xml files
|
|
225
232
|
*/
|
|
226
|
-
async function generateAndStoreCmrXml(granule, collection, bucket, additionalUrls, stagingDir = 'file-staging'
|
|
227
|
-
|
|
233
|
+
async function generateAndStoreCmrXml(granule, collection, bucket, additionalUrls, stagingDir = 'file-staging',
|
|
234
|
+
matchFilesWithProducerGranuleId = false) {
|
|
235
|
+
const xml = generateCmrXml(granule, collection, additionalUrls, matchFilesWithProducerGranuleId);
|
|
228
236
|
const granuleFiles = granule.files.map((f) => `s3://${f.bucket}/${f.key}`);
|
|
229
237
|
|
|
230
|
-
const
|
|
238
|
+
const id = (matchFilesWithProducerGranuleId && granule.producerGranuleId)
|
|
239
|
+
? granule.producerGranuleId
|
|
240
|
+
: granule.granuleId;
|
|
241
|
+
const fileKey = `${stagingDir}/${granule.granuleId}/${id}.cmr.xml`;
|
|
231
242
|
|
|
232
243
|
const params = {
|
|
233
244
|
Bucket: bucket,
|
|
234
245
|
Key: fileKey,
|
|
235
246
|
Body: xml,
|
|
236
247
|
ContentType: 'application/xml',
|
|
237
|
-
Tagging: `granuleId=${
|
|
248
|
+
Tagging: `granuleId=${id}`,
|
|
238
249
|
};
|
|
239
250
|
|
|
240
251
|
await s3().putObject(params);
|
|
@@ -268,6 +279,16 @@ function isUMMGMetadataFormat(cmrMetadataFormat) {
|
|
|
268
279
|
return cmrMetadataFormat && cmrMetadataFormat.match(/umm_json_v/);
|
|
269
280
|
}
|
|
270
281
|
|
|
282
|
+
async function getCmrMetadataECHO10(cmrLink) {
|
|
283
|
+
const response = await got.get(cmrLink);
|
|
284
|
+
|
|
285
|
+
if (response.statusCode !== 200) {
|
|
286
|
+
console.log(`Error fetching CMR metadata, status code: ${response.statusCode}, response: ${JSON.stringify(response.body)}`);
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return JSON.parse(response.body);
|
|
291
|
+
}
|
|
271
292
|
/**
|
|
272
293
|
* Get the online resource links from the CMR objects for ECH010
|
|
273
294
|
*
|
|
@@ -280,15 +301,17 @@ function isUMMGMetadataFormat(cmrMetadataFormat) {
|
|
|
280
301
|
href: 'https://opendap.cr.usgs.gov/opendap/hyrax/MYD13Q1.006/contents.html' }
|
|
281
302
|
*/
|
|
282
303
|
async function getOnlineResourcesECHO10(cmrLink) {
|
|
283
|
-
const
|
|
304
|
+
const body = await getCmrMetadataECHO10(cmrLink);
|
|
305
|
+
return body.links;
|
|
306
|
+
}
|
|
284
307
|
|
|
308
|
+
async function getCmrMetadataUMMG(cmrLink) {
|
|
309
|
+
const response = await got.get(cmrLink);
|
|
285
310
|
if (response.statusCode !== 200) {
|
|
311
|
+
console.log(`Error fetching CMR metadata, status code: ${response.statusCode}, response: ${JSON.stringify(response.body)}`);
|
|
286
312
|
return null;
|
|
287
313
|
}
|
|
288
|
-
|
|
289
|
-
const body = JSON.parse(response.body);
|
|
290
|
-
|
|
291
|
-
return body.links;
|
|
314
|
+
return JSON.parse(response.body);
|
|
292
315
|
}
|
|
293
316
|
|
|
294
317
|
/**
|
|
@@ -302,20 +325,36 @@ async function getOnlineResourcesECHO10(cmrLink) {
|
|
|
302
325
|
Type: "GET DATA" }
|
|
303
326
|
*/
|
|
304
327
|
async function getOnlineResourcesUMMG(cmrLink) {
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
if (response.statusCode !== 200) {
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const body = JSON.parse(response.body);
|
|
312
|
-
|
|
328
|
+
const body = await getCmrMetadataUMMG(cmrLink);
|
|
313
329
|
const links = body.items.map((item) => item.umm.RelatedUrls);
|
|
314
330
|
|
|
315
331
|
// Links is a list of a list, so flatten to be one list
|
|
316
332
|
return [].concat(...links);
|
|
317
333
|
}
|
|
318
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Fetches full granule object from CMR based on file type (ECHO10, UMM-G)
|
|
337
|
+
*
|
|
338
|
+
* @param {Object} granule
|
|
339
|
+
* @param {string} granule.cmrMetadataFormat - the cmr file type (e.g. echo10, umm-g)
|
|
340
|
+
* @param {Object} granule.cmrConceptId - the CMR granule concept ID
|
|
341
|
+
* @param {Object} granule.cmrLink - the metadata's granuleId
|
|
342
|
+
*
|
|
343
|
+
* @returns {Promise<Array<Object>>} - Promise returning array of links
|
|
344
|
+
*/
|
|
345
|
+
async function getCmrMetadata({ cmrMetadataFormat, cmrConceptId, cmrLink }) {
|
|
346
|
+
console.log('Running getCmrMetadata');
|
|
347
|
+
console.log(cmrLink);
|
|
348
|
+
console.log(`${getSearchUrl()}granules.umm_json?concept_id=${cmrConceptId}`);
|
|
349
|
+
if (cmrMetadataFormat === 'echo10') {
|
|
350
|
+
return await getCmrMetadataECHO10(cmrLink.replace(/(.echo10)$/, '.json'));
|
|
351
|
+
}
|
|
352
|
+
if (isUMMGMetadataFormat(cmrMetadataFormat)) {
|
|
353
|
+
return await getCmrMetadataUMMG(`${getSearchUrl()}granules.umm_json?concept_id=${cmrConceptId}`);
|
|
354
|
+
}
|
|
355
|
+
throw new Error(`Invalid cmrMetadataFormat passed to getOnlineResources: ${cmrMetadataFormat}`);
|
|
356
|
+
}
|
|
357
|
+
|
|
319
358
|
/**
|
|
320
359
|
* Fetches online resources from CMR based on file type (ECHO10, UMM-G)
|
|
321
360
|
*
|
|
@@ -347,6 +386,9 @@ async function getOnlineResources({ cmrMetadataFormat, cmrConceptId, cmrLink })
|
|
|
347
386
|
* @param {string} bucket - bucket to save the xml file to
|
|
348
387
|
* @param {Array<string>} additionalUrls - URLs to convert to related urls
|
|
349
388
|
* @param {string} cmrMetadataFormat - CMR UMM-G version string <umm_json_v[x.y]>
|
|
389
|
+
* @param {string} stagingDir - staging directory
|
|
390
|
+
* @param {boolean} matchFilesWithProducerGranuleId - When set to true, use the 'producerGranuleId'
|
|
391
|
+
* instead default behavior of using 'granuleId' when generating filenames.
|
|
350
392
|
* @returns {Promise<Array<string>>} - Promise of a list of granule files including the created
|
|
351
393
|
* CMR files
|
|
352
394
|
*/
|
|
@@ -356,7 +398,8 @@ async function generateAndStoreCmrUmmJson(
|
|
|
356
398
|
bucket,
|
|
357
399
|
additionalUrls,
|
|
358
400
|
cmrMetadataFormat,
|
|
359
|
-
stagingDir = 'file-staging'
|
|
401
|
+
stagingDir = 'file-staging',
|
|
402
|
+
matchFilesWithProducerGranuleId = false
|
|
360
403
|
) {
|
|
361
404
|
const versionString = metadataFormatToVersion(cmrMetadataFormat);
|
|
362
405
|
const jsonObject = sampleUmmGranule;
|
|
@@ -384,7 +427,10 @@ async function generateAndStoreCmrUmmJson(
|
|
|
384
427
|
};
|
|
385
428
|
}
|
|
386
429
|
|
|
387
|
-
const
|
|
430
|
+
const fileNameBase = matchFilesWithProducerGranuleId
|
|
431
|
+
? granule.producerGranuleId
|
|
432
|
+
: granule.granuleId;
|
|
433
|
+
const fileKey = `${stagingDir}/${granule.granuleId}/${fileNameBase}.cmr.json`;
|
|
388
434
|
|
|
389
435
|
const params = {
|
|
390
436
|
Bucket: bucket,
|
|
@@ -423,6 +469,7 @@ async function generateCmrFilesForGranules({
|
|
|
423
469
|
cmrMetadataFormat,
|
|
424
470
|
additionalUrls,
|
|
425
471
|
stagingDir,
|
|
472
|
+
matchFilesWithProducerGranuleId = false,
|
|
426
473
|
}) {
|
|
427
474
|
let files;
|
|
428
475
|
|
|
@@ -437,7 +484,8 @@ async function generateCmrFilesForGranules({
|
|
|
437
484
|
bucket,
|
|
438
485
|
additionalUrls,
|
|
439
486
|
cmrMetadataFormat,
|
|
440
|
-
stagingDir
|
|
487
|
+
stagingDir,
|
|
488
|
+
matchFilesWithProducerGranuleId
|
|
441
489
|
))
|
|
442
490
|
);
|
|
443
491
|
} else {
|
|
@@ -448,7 +496,8 @@ async function generateCmrFilesForGranules({
|
|
|
448
496
|
collection,
|
|
449
497
|
bucket,
|
|
450
498
|
additionalUrls,
|
|
451
|
-
stagingDir
|
|
499
|
+
stagingDir,
|
|
500
|
+
matchFilesWithProducerGranuleId
|
|
452
501
|
))
|
|
453
502
|
);
|
|
454
503
|
}
|
|
@@ -459,6 +508,7 @@ async function generateCmrFilesForGranules({
|
|
|
459
508
|
module.exports = {
|
|
460
509
|
conceptExists,
|
|
461
510
|
getOnlineResources,
|
|
511
|
+
getCmrMetadata,
|
|
462
512
|
generateCmrFilesForGranules,
|
|
463
513
|
generateCmrXml,
|
|
464
514
|
waitForConceptExistsOutcome,
|