From 45ce177a38b674f961d60cf8f630979146e4599a Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 24 Jul 2018 17:58:36 -0400 Subject: [PATCH 01/28] fix API url when dynamically generating --- packages/api-lib/libs/api.js | 13 ++++--------- packages/api/index.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/api-lib/libs/api.js b/packages/api-lib/libs/api.js index b249f45..1cd72d2 100644 --- a/packages/api-lib/libs/api.js +++ b/packages/api-lib/libs/api.js @@ -15,7 +15,7 @@ function Search(event, esClient) { params = event.body } - this.headers = event.headers + this.endpoint = event.endpoint this.merge = false if (_.has(params, 'merge')) { @@ -129,20 +129,15 @@ Search.prototype.search = (index, callback) => { props = _.omit(props, ['bbox', 'geometry', 'assets', 'links', 'eo:bands']) const links = body.hits.hits[i]._source.links || [] // add self and collection links - const host = ( - 'X-Forwarded-Host' in self.headers ? - self.headers['X-Forwarded-Host'] : self.headers.Host - ) - const apiUrl = `${self.headers['X-Forwarded-Proto']}://${host}` let prefix = '/search/stac' if (index === 'collections') { prefix = '/collections' - links.self = { rel: 'self', href: `${apiUrl}${prefix}?c:id=${props.collection}` } + links.self = { rel: 'self', href: `${self.endpoint}${prefix}?c:id=${props.collection}` } } else { - links.self = { rel: 'self', href: `${apiUrl}${prefix}?id=${props.id}` } + links.self = { rel: 'self', href: `${self.endpoint}${prefix}?id=${props.id}` } if (_.has(props, 'c:id')) { - links.collection = { href: `${apiUrl}/collections/${props['c:id']}/definition` } + links.collection = { href: `${self.endpoint}/collections/${props['c:id']}/definition` } } } return { diff --git a/packages/api/index.js b/packages/api/index.js index e8b4c33..2d91091 100644 --- a/packages/api/index.js +++ b/packages/api/index.js @@ -11,7 +11,16 @@ module.exports.handler = (event, context, cb) => { // get payload const method = event.httpMethod - const payload = { query: {}, headers: event.headers } + const host = ( + 'X-Forwarded-Host' in event.headers ? + event.headers['X-Forwarded-Host'] : event.headers.Host + ) + let endpoint = `${event.headers['X-Forwarded-Proto']}://${host}` + if ('stage' in event.requestContext) { + endpoint = `${event.headers.Endpoint}/${event.requestContext['stage']}` + } + + const payload = { query: {}, headers: event.headers, endpoint: endpoint } if (method === 'POST' && event.body) { payload.query = JSON.parse(event.body) } From 32331fd038fc52fbfacd9e42ac9f0df2ea2b17e9 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 24 Jul 2018 18:25:57 -0400 Subject: [PATCH 02/28] use dot notation --- packages/api/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/index.js b/packages/api/index.js index 2d91091..8bd7404 100644 --- a/packages/api/index.js +++ b/packages/api/index.js @@ -17,7 +17,7 @@ module.exports.handler = (event, context, cb) => { ) let endpoint = `${event.headers['X-Forwarded-Proto']}://${host}` if ('stage' in event.requestContext) { - endpoint = `${event.headers.Endpoint}/${event.requestContext['stage']}` + endpoint = `${event.headers.Endpoint}/${event.requestContext.stage}` } const payload = { query: {}, headers: event.headers, endpoint: endpoint } From 89d5b12e5b9a12a7d28b2b6486946322763d940c Mon Sep 17 00:00:00 2001 From: Scisco Date: Tue, 31 Jul 2018 10:29:35 -0400 Subject: [PATCH 03/28] fix changelog --- CHANGES.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4430b97..28c853f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [v0.0.2] + ### Added - Added support for [STAC specification](https://github.com/radiantearth/stac-spec/) - The following packages are released @@ -25,19 +27,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - /geojson endpoint - /count endpoint - - -## [v2.0.0] - 2017-06-14 +## [legacy-v2.0.0] - 2018-01-01 - Moves all the metadata indexing logics to the same repo - Uses CloudFormation for full deployment - Includes a better ApiGateway support - -## [v1.0.0] - 2016-10-20 - Use streams to read, transform, and write into elasticsearch - Use batches of lambdas to speed up processing - Refactor several modules: metadata, landsat, sentinel - Refactor and improve splitting -[Unreleased]: https://github.com/cumulus-nasa/cumulus/compare/v2.0.0...HEAD -[v2.0.0]: https://github.com/cumulus-nasa/cumulus/compare/v1.0.0...v2.0.0 \ No newline at end of file +[Unreleased]: https://github.com/cumulus-nasa/cumulus/compare/v0.0.2...HEAD +[v0.0.2]: https://github.com/cumulus-nasa/cumulus/compare/v0.0.1...v0.0.2 +[legacy-v2.0.0]: https://github.com/sat-utils/sat-api/tree/legacy \ No newline at end of file From 1bb903933f448772393e201da48d0f6043ec61bc Mon Sep 17 00:00:00 2001 From: Scisco Date: Tue, 31 Jul 2018 10:30:14 -0400 Subject: [PATCH 04/28] more link fixing --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 28c853f..ea78d05 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Refactor several modules: metadata, landsat, sentinel - Refactor and improve splitting -[Unreleased]: https://github.com/cumulus-nasa/cumulus/compare/v0.0.2...HEAD -[v0.0.2]: https://github.com/cumulus-nasa/cumulus/compare/v0.0.1...v0.0.2 +[Unreleased]: https://github.com/sat-utils/sat-api/compare/v0.0.2...HEAD +[v0.0.2]: https://github.com/sat-utils/sat-api/compare/legacy-v2.0.0...v0.0.2 [legacy-v2.0.0]: https://github.com/sat-utils/sat-api/tree/legacy \ No newline at end of file From 01dd0c146e2fbe8760b83f9afbc59a4980b4ceac Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Thu, 23 Aug 2018 16:29:46 +0300 Subject: [PATCH 05/28] remove v1 text from stackname --- example/.kes/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/.kes/config.yml b/example/.kes/config.yml index a9d9b9c..b5fee67 100644 --- a/example/.kes/config.yml +++ b/example/.kes/config.yml @@ -6,7 +6,7 @@ default: project: sat-api dev: - stackName: sat-api-v1-dev + stackName: sat-api-dev system_bucket: sat-api es: instanceCount: 2 @@ -14,9 +14,9 @@ dev: volumeSize: 80 prod: - stackName: sat-api-v1 + stackName: sat-api system_bucket: sat-api es: instanceCount: 2 instanceType: m3.medium.elasticsearch - volumeSize: 80 \ No newline at end of file + volumeSize: 80 From 7b5ba440405c476ff94e17dc0a9793f9b268427b Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Thu, 23 Aug 2018 17:38:05 +0300 Subject: [PATCH 06/28] fix introduced bug of ingesting all files every time --- packages/ingest/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ingest/index.js b/packages/ingest/index.js index 63c6b8f..8c1eac3 100644 --- a/packages/ingest/index.js +++ b/packages/ingest/index.js @@ -40,7 +40,7 @@ module.exports.handler = function handler(event, context, cb) { bucket, key, arn, - maxFiles, + inMaxFiles: maxFiles, linesPerFile, maxLambdas, reverse, From b307134a84e9888acb19ad8f08c02504d4919b78 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 28 Aug 2018 16:28:08 +0300 Subject: [PATCH 07/28] landsat csv back to descending order --- packages/ingest/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/ingest/index.js b/packages/ingest/index.js index 8c1eac3..cc68aa6 100644 --- a/packages/ingest/index.js +++ b/packages/ingest/index.js @@ -23,10 +23,11 @@ module.exports.handler = function handler(event, context, cb) { const arn = _.get(event, 'arn', '') let url - const reverse = true + let reverse = true switch (sat) { case 'landsat': url = 'https://landsat.usgs.gov/landsat/metadata_service/bulk_metadata_files/LANDSAT_8_C1.csv' + reverse = false break case 'sentinel': url = 'https://storage.googleapis.com/gcp-public-data-sentinel-2/index.csv.gz' From 26b1c459c61c1945911452d8ba3d68b9726d433e Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 28 Aug 2018 16:29:54 +0300 Subject: [PATCH 08/28] fix passing of es client, fixes issue #75 --- packages/landsat/index.js | 8 ++++++-- packages/sentinel/index.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/landsat/index.js b/packages/landsat/index.js index f8d9319..a946034 100644 --- a/packages/landsat/index.js +++ b/packages/landsat/index.js @@ -318,9 +318,13 @@ function handler(event, context, cb) { esClient = client return satlib.es.putMapping(esClient, 'collections') }) - .then(() => satlib.es.saveRecords(esClient, [collection], 'collections', 'c:id')) + .then(() => { + satlib.es.saveRecords(esClient, [collection], 'collections', 'c:id', (err) => { + if (err) console.log('Warning: ', err) + }) + }) .then(() => satlib.ingestcsv.update({ - esClient, + client: esClient, bucket, key, transform: _transform, diff --git a/packages/sentinel/index.js b/packages/sentinel/index.js index d793548..cb4be65 100644 --- a/packages/sentinel/index.js +++ b/packages/sentinel/index.js @@ -253,7 +253,7 @@ function handler(event, context, cb) { }) .then(() => satlib.es.saveRecords(esClient, [collection], 'collections', 'c:id')) .then(() => satlib.ingestcsv.update({ - esClient, + client: esClient, bucket, key, transform: _transform, From 7e3cbef3b9f5a8e57eac567be6d7bd1100f6498a Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 28 Aug 2018 18:43:29 +0300 Subject: [PATCH 09/28] revert lambda invocations as promises --- packages/api-lib/libs/ingest-csv.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/api-lib/libs/ingest-csv.js b/packages/api-lib/libs/ingest-csv.js index fd60eea..d375bfb 100644 --- a/packages/api-lib/libs/ingest-csv.js +++ b/packages/api-lib/libs/ingest-csv.js @@ -34,10 +34,9 @@ function invokeLambda(bucket, key, nextFileNum, lastFileNum, arn, retries) { else { console.log(`launched ${JSON.stringify(params)}`) } - }).promise() + }) } - - return Promise.resolve() + return 0 } // split a CSV to multiple files and trigger lambdas @@ -128,7 +127,6 @@ function split({ newStream.on('error', (e) => cb(e)) return newStream.on('end', () => { - const limit = pLimit(3) //set concurrent call to 3 at a time // write the last records if (lineCounter > 0) { fileCounter += 1 @@ -158,16 +156,13 @@ function split({ `${extra} extra (Files ${startFile}-${maxEndFile})` ) - const promises = lodash.range(numLambdas).map((i) => limit(() => { - endFile = (i < extra) ? startFile + batchSize : (startFile + batchSize) - 1 + for (let i = 0; i < numLambdas; i++) { + endFile = (i < extra) ? (startFile + batchSize) : ((startFile + batchSize) - 1) + invokeLambda(bucket, key, startFile, Math.min(endFile, maxEndFile), arn) startFile = endFile + 1 - return invokeLambda(bucket, key, startFile - 1, Math.min(endFile, maxEndFile), arn) - })) - - return Promise.all(promises).then(() => cb()).catch(cb) + } } cb() - return Promise.resolve() }) } From 5c3e91b075ed5346cd4db834a855849070a1d3d3 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 28 Aug 2018 19:29:40 +0300 Subject: [PATCH 10/28] fix bug introduced in padding --- packages/landsat/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/landsat/index.js b/packages/landsat/index.js index a946034..beccbe8 100644 --- a/packages/landsat/index.js +++ b/packages/landsat/index.js @@ -136,8 +136,8 @@ function arrayIterate(values, fn) { function awsLinks(data) { // generates links for the data on AWS - const row = _.pad(data.row, 3, '0') - const _path = _.pad(data.path, 3, '0') + const row = _.padStart(data.row, 3, '0') + const _path = _.padStart(data.path, 3, '0') const sceneId = data.sceneID const productId = data.LANDSAT_PRODUCT_ID @@ -171,7 +171,7 @@ function awsLinks(data) { // check that file exists fileExists(c1.index).then(() => resolve(c1)) .catch((e) => { - const error = new Error(`${c1.index} not available: `) + const error = new Error(`${c1.index} not available: ${JSON.stringify(data)}`) reject(error, e) }) } @@ -334,7 +334,7 @@ function handler(event, context, cb) { arn, retries })) - .catch((e) => console.log('Error: ', e)) + .catch((e) => console.log(e)) } From e1172fe48905dc4561ef4cc0cfa2e99aaf1a9c91 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 4 Sep 2018 15:06:31 -0400 Subject: [PATCH 11/28] consistent https --- packages/landsat/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/landsat/index.js b/packages/landsat/index.js index beccbe8..cc43175 100644 --- a/packages/landsat/index.js +++ b/packages/landsat/index.js @@ -98,7 +98,7 @@ const collection = { function fileExists(url) { const params = { Bucket: 'landsat-pds', - Key: url.slice(36) + Key: url.slice(37) } return new Promise(((resolve, reject) => { s3.headObject(params, (err) => { @@ -171,6 +171,7 @@ function awsLinks(data) { // check that file exists fileExists(c1.index).then(() => resolve(c1)) .catch((e) => { + console.log(`not avail: ${JSON.stringify(c1)}`) const error = new Error(`${c1.index} not available: ${JSON.stringify(data)}`) reject(error, e) }) @@ -180,7 +181,7 @@ function awsLinks(data) { let sid let newKey const rev = sceneId.slice(-2) - let prefix = `http://landsat-pds.s3.amazonaws.com/L8/${path.join(_path, row, _sceneId)}` + let prefix = `https://landsat-pds.s3.amazonaws.com/L8/${path.join(_path, row, _sceneId)}` const links = _.range(rev, -1, -1).map((r) => `${prefix}${_.pad(r, 2, '0')}/index.html`) arrayIterate(links.reverse(), fileExists).then((value) => { From 3b735a9675b441e9765e3ccfad84360a3e4c6d05 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 4 Sep 2018 15:58:12 -0400 Subject: [PATCH 12/28] cannot use arrow notation shortcut with through2, expects a this object --- packages/api-lib/libs/es.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api-lib/libs/es.js b/packages/api-lib/libs/es.js index 753f92e..176858c 100644 --- a/packages/api-lib/libs/es.js +++ b/packages/api-lib/libs/es.js @@ -134,7 +134,7 @@ function streamToEs(stream, transform, client, index) { let nRecords = 0 let nTransformed = 0 - const toEs = through2({ objectMode: true, consume: true }, (data, encoding, next) => { + const toEs = through2({ objectMode: true, consume: true }, function(data, encoding, next) { const record = { index, type: 'doc', From 7247583375874fda72c861557a2fceac902e06ac Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 4 Sep 2018 17:20:38 -0400 Subject: [PATCH 13/28] do not use arrow notation for functions because this object is needed --- packages/api-lib/libs/api.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/api-lib/libs/api.js b/packages/api-lib/libs/api.js index 1cd72d2..5cf8ed5 100644 --- a/packages/api-lib/libs/api.js +++ b/packages/api-lib/libs/api.js @@ -35,16 +35,13 @@ function Search(event, esClient) { this.queries = queries(this.params) - console.log(`Queries: ${JSON.stringify(this.queries)}`) } // search for items using collection and items -Search.prototype.search_items = (callback) => { +Search.prototype.search_items = function (callback) { // check collection first this.search_collections((err, resp) => { const collections = resp.features.map((c) => c.properties['c:id']) - console.log('matched collections', collections) - console.log('queries before', JSON.stringify(this.queries)) let qs if (collections.length === 0) { qs = { bool: { must_not: { exists: { field: 'c:id' } } } } @@ -62,7 +59,7 @@ Search.prototype.search_items = (callback) => { } -Search.prototype.search_collections = (callback) => { +Search.prototype.search_collections = function (callback) { // hacky way to get all collections const sz = this.size const frm = this.frm @@ -92,7 +89,7 @@ Search.prototype.search_collections = (callback) => { } -Search.prototype.search = (index, callback) => { +Search.prototype.search = function(index, callback) { const self = this const searchParams = { From 37fa51f0a4f9ddef789edb30ee43ed62d3b12ecd Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 11 Sep 2018 19:08:09 -0400 Subject: [PATCH 14/28] fix endpoint --- packages/api/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/index.js b/packages/api/index.js index 8bd7404..6d18cfb 100644 --- a/packages/api/index.js +++ b/packages/api/index.js @@ -17,7 +17,7 @@ module.exports.handler = (event, context, cb) => { ) let endpoint = `${event.headers['X-Forwarded-Proto']}://${host}` if ('stage' in event.requestContext) { - endpoint = `${event.headers.Endpoint}/${event.requestContext.stage}` + endpoint = `${endpoint}/${event.requestContext.stage}` } const payload = { query: {}, headers: event.headers, endpoint: endpoint } From b6491c1e0160c77351be87e6948c61e5bc1c0d56 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 11 Sep 2018 19:08:19 -0400 Subject: [PATCH 15/28] syntax, typo --- README.md | 2 +- packages/api-lib/libs/api.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 10149dc..79d27e4 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Sat-api includes a number of NPM packages (in the packages/ directory) that are $ yarn docs-serve -On Linux, if you get the message "Error: watch *path*/book.json ENOSPC", issue the following command (require sudo access). +On Linux, if you get the message "Error: watch *path*/book.json ENOSPC", issue the following command (requires sudo access). $ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p diff --git a/packages/api-lib/libs/api.js b/packages/api-lib/libs/api.js index 5cf8ed5..7abcc03 100644 --- a/packages/api-lib/libs/api.js +++ b/packages/api-lib/libs/api.js @@ -89,7 +89,7 @@ Search.prototype.search_collections = function (callback) { } -Search.prototype.search = function(index, callback) { +Search.prototype.search = function (index, callback) { const self = this const searchParams = { From 67ff819e72fffe6dedb0b705b8e6e46a7d9703be Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 11 Sep 2018 22:11:54 -0400 Subject: [PATCH 16/28] fix geojson not being set from argument --- packages/api-lib/libs/queries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api-lib/libs/queries.js b/packages/api-lib/libs/queries.js index dcda21f..505b0aa 100644 --- a/packages/api-lib/libs/queries.js +++ b/packages/api-lib/libs/queries.js @@ -87,7 +87,7 @@ const geometryQuery = (field, geometry) => { const intersects = (inGeojson, queries) => { - let geojson + let geojson = inGeojson // if we receive an object, assume it's GeoJSON, if not, try and parse if (typeof geojson === 'string') { try { From 573421342edada8aefa57b4cb5ac934f164d0575 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 11 Sep 2018 22:12:20 -0400 Subject: [PATCH 17/28] add function back to saveRecords --- packages/sentinel/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/sentinel/index.js b/packages/sentinel/index.js index cb4be65..70ebdbe 100644 --- a/packages/sentinel/index.js +++ b/packages/sentinel/index.js @@ -251,7 +251,11 @@ function handler(event, context, cb) { esClient = client return satlib.es.putMapping(esClient, 'collections') }) - .then(() => satlib.es.saveRecords(esClient, [collection], 'collections', 'c:id')) + .then(() => { + satlib.es.saveRecords(esClient, [collection], 'collections', 'c:id', (err) => { + if (err) console.log('Warning: ', err) + }) + }) .then(() => satlib.ingestcsv.update({ client: esClient, bucket, From 7f8e24fe86286038461c1e5c8221f887ff8db56f Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 11 Sep 2018 22:12:33 -0400 Subject: [PATCH 18/28] dev deploy to sat-api-v1-dev stack, for now --- example/.kes/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/.kes/config.yml b/example/.kes/config.yml index b5fee67..cd8eeaa 100644 --- a/example/.kes/config.yml +++ b/example/.kes/config.yml @@ -6,7 +6,7 @@ default: project: sat-api dev: - stackName: sat-api-dev + stackName: sat-api-v1-dev system_bucket: sat-api es: instanceCount: 2 From 3a726c6483501735304ff47a72dfe0d070430178 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Wed, 12 Sep 2018 00:24:36 -0400 Subject: [PATCH 19/28] use public endpoint to get sentinel metadata --- packages/sentinel/index.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/packages/sentinel/index.js b/packages/sentinel/index.js index 70ebdbe..0e66388 100644 --- a/packages/sentinel/index.js +++ b/packages/sentinel/index.js @@ -140,19 +140,6 @@ function getTileUrl(tilePath) { } -function getSentinelInfo(url) { - /*return new Promise(function(resolve, reject) { - got(url, { json: true }).then(response => { - resolve(response) - }).catch(e => { - console.log(`error getting metadata: ${e}`) - resolve() - }) - })*/ - return got(url, { json: true }) -} - - function reproject(inputGeojson) { let geojson = clone(inputGeojson) const crs = geojson.crs.properties.name.replace( @@ -191,22 +178,23 @@ function transform(data, encoding, next) { const parsedMgrs = parseMgrs(mgrs) const tilePath = getTilePath(dt, parsedMgrs) const tileBaseUrl = getTileUrl(tilePath) + const rodaBaseUrl = tileBaseUrl.replace('sentinel-s2-l1c.s3.amazonaws.com', 'roda.sentinel-hub.com/sentinel-s2-l1c') const bands = range(1, 13).map((i) => pad(i, 3, 'B0')) bands.push('B8A') - getSentinelInfo(`${tileBaseUrl}/tileInfo.json`).then((body) => { - const info = body - const sat = info.productName.slice(0, 3) + const tileInfo = `${rodaBaseUrl}/tileInfo.json` + got(tileInfo, { json: true }).then((info) => { + const sat = info.body.productName.slice(0, 3) const satname = `Sentinel-2${sat.slice(-1)}` let val const files = fromPairs(bands.map((b) => { val = { href: `${tileBaseUrl}/${b}.jp2`, 'eo:bands': [b] } return [b, val] })) - files.thumbnail = { href: `${tileBaseUrl}/preview.jpg` } + files.thumbnail = { href: `${rodaBaseUrl}/preview.jpg` } files.tki = { href: `${tileBaseUrl}/TKI.jp2`, description: 'True Color Image' } - files.metadata = { href: `${tileBaseUrl}/metadata.xml` } + files.metadata = { href: `${rodaBaseUrl}/metadata.xml` } // reproject to EPSG:4326 - const geom = reproject(info.tileDataGeometry) + const geom = reproject(info.body.tileDataGeometry) const lons = geom.coordinates[0].map((pt) => pt[0]) const lats = geom.coordinates[0].map((pt) => pt[1]) const record = { From 8eb3f276d95aed28d4cd0f7e5851d8cab8cb4aee Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Wed, 12 Sep 2018 00:48:00 -0400 Subject: [PATCH 20/28] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 929ee2b..55aff24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sat-api", - "version": "1.0.0", + "version": "0.1.0", "description": "One API to search public Satellites metadata", "main": "index.js", "repository": "https://github.com/sat-utils/sat-api", From 80297ce4c5a5bcccbb4d493774b6df72fb227f4d Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Wed, 12 Sep 2018 00:54:15 -0400 Subject: [PATCH 21/28] bump ingest Lambda to 1600MB --- packages/api/template/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/template/config.yml b/packages/api/template/config.yml index d41a3e3..a5cb428 100644 --- a/packages/api/template/config.yml +++ b/packages/api/template/config.yml @@ -38,7 +38,7 @@ default: source: 'node_modules/@sat-utils/ingest/dist/' handler: index.handler timeout: 300 - memory: 1024 + memory: 1600 envs: bucket: '{{system_bucket}}' prefix: '{{stackName}}' From ef6c4cb2ede3a672d8c98189ecb122274ca6fa41 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 18 Sep 2018 16:40:18 -0400 Subject: [PATCH 22/28] fix linting errors --- packages/api-lib/libs/api.js | 1 - packages/api-lib/libs/es.js | 2 +- packages/api-lib/libs/ingest-csv.js | 4 +--- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/api-lib/libs/api.js b/packages/api-lib/libs/api.js index 7abcc03..aa51686 100644 --- a/packages/api-lib/libs/api.js +++ b/packages/api-lib/libs/api.js @@ -34,7 +34,6 @@ function Search(event, esClient) { this.client = esClient this.queries = queries(this.params) - } // search for items using collection and items diff --git a/packages/api-lib/libs/es.js b/packages/api-lib/libs/es.js index 176858c..763d36a 100644 --- a/packages/api-lib/libs/es.js +++ b/packages/api-lib/libs/es.js @@ -134,7 +134,7 @@ function streamToEs(stream, transform, client, index) { let nRecords = 0 let nTransformed = 0 - const toEs = through2({ objectMode: true, consume: true }, function(data, encoding, next) { + const toEs = through2({ objectMode: true, consume: true }, function (data, encoding, next) { const record = { index, type: 'doc', diff --git a/packages/api-lib/libs/ingest-csv.js b/packages/api-lib/libs/ingest-csv.js index d375bfb..d5d45a2 100644 --- a/packages/api-lib/libs/ingest-csv.js +++ b/packages/api-lib/libs/ingest-csv.js @@ -3,8 +3,6 @@ const csv = require('fast-csv') const AWS = require('aws-sdk') const zlib = require('zlib') -const pLimit = require('p-limit') -const lodash = require('lodash') const es = require('./es') let esClient @@ -156,7 +154,7 @@ function split({ `${extra} extra (Files ${startFile}-${maxEndFile})` ) - for (let i = 0; i < numLambdas; i++) { + for (let i = 0; i < numLambdas; i += 1) { endFile = (i < extra) ? (startFile + batchSize) : ((startFile + batchSize) - 1) invokeLambda(bucket, key, startFile, Math.min(endFile, maxEndFile), arn) startFile = endFile + 1 From 499ade824eb3577a4f373cdebae713fa3de335ed Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 18 Sep 2018 18:42:35 -0400 Subject: [PATCH 23/28] bump version to 0.1.0 --- lerna.json | 2 +- packages/api-lib/package.json | 2 +- packages/api/package.json | 12 ++++++------ packages/ingest/package.json | 4 ++-- packages/landsat/package.json | 4 ++-- packages/manager/package.json | 4 ++-- packages/sentinel/package.json | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lerna.json b/lerna.json index 9a530a3..543442c 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "lerna": "2.11.0", - "version": "0.0.2", + "version": "0.1.0", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/api-lib/package.json b/packages/api-lib/package.json index 33bb86c..9e9102d 100644 --- a/packages/api-lib/package.json +++ b/packages/api-lib/package.json @@ -1,6 +1,6 @@ { "name": "@sat-utils/api-lib", - "version": "0.0.2", + "version": "0.1.0", "description": "A library for creating a search API of public Satellites metadata using Elasticsearch", "main": "index.js", "scripts": { diff --git a/packages/api/package.json b/packages/api/package.json index d808faf..68c20bc 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "@sat-utils/api", - "version": "0.0.2", + "version": "0.1.0", "description": "The api lambda function for sat-api", "main": "index.js", "repository": { @@ -20,11 +20,11 @@ }, "homepage": "https://github.com/sat-utils/sat-api#readme", "dependencies": { - "@sat-utils/api-lib": "^0.0.2", - "@sat-utils/ingest": "^0.0.2", - "@sat-utils/landsat": "^0.0.2", - "@sat-utils/manager": "^0.0.2", - "@sat-utils/sentinel": "^0.0.2", + "@sat-utils/api-lib": "^0.1.0", + "@sat-utils/ingest": "^0.1.0", + "@sat-utils/landsat": "^0.1.0", + "@sat-utils/manager": "^0.1.0", + "@sat-utils/sentinel": "^0.1.0", "lambda-proxy-utils": "^1.2.4", "lodash.get": "^4.4.2" }, diff --git a/packages/ingest/package.json b/packages/ingest/package.json index ae4c248..30a7f4f 100644 --- a/packages/ingest/package.json +++ b/packages/ingest/package.json @@ -1,6 +1,6 @@ { "name": "@sat-utils/ingest", - "version": "0.0.2", + "version": "0.1.0", "description": "ingest lambda function of sat-api", "main": "index.js", "repository": { @@ -20,7 +20,7 @@ }, "homepage": "https://github.com/sat-utils/sat-api#readme", "dependencies": { - "@sat-utils/api-lib": "^0.0.2" + "@sat-utils/api-lib": "^0.1.0" }, "devDependencies": { "webpack": "~4.5.0", diff --git a/packages/landsat/package.json b/packages/landsat/package.json index ae8cade..0fb89bc 100644 --- a/packages/landsat/package.json +++ b/packages/landsat/package.json @@ -1,6 +1,6 @@ { "name": "@sat-utils/landsat", - "version": "0.0.2", + "version": "0.1.0", "description": "Lambda function for ingesting landsat metadata to sat-api", "main": "index.js", "repository": { @@ -20,7 +20,7 @@ }, "homepage": "https://github.com/sat-utils/sat-api#readme", "dependencies": { - "@sat-utils/api-lib": "^0.0.2", + "@sat-utils/api-lib": "^0.1.0", "got": "^8.3.2", "lodash": "^4.17.10", "moment": "^2.22.2", diff --git a/packages/manager/package.json b/packages/manager/package.json index ff97e01..259d553 100644 --- a/packages/manager/package.json +++ b/packages/manager/package.json @@ -1,6 +1,6 @@ { "name": "@sat-utils/manager", - "version": "0.0.2", + "version": "0.1.0", "description": "Lambda function for managing elasticsearch of sat-api", "main": "index.js", "repository": { @@ -20,7 +20,7 @@ }, "homepage": "https://github.com/sat-utils/sat-api#readme", "dependencies": { - "@sat-utils/api-lib": "^0.0.2" + "@sat-utils/api-lib": "^0.1.0" }, "devDependencies": { "webpack": "~4.5.0", diff --git a/packages/sentinel/package.json b/packages/sentinel/package.json index 5fd0a0e..9656df1 100644 --- a/packages/sentinel/package.json +++ b/packages/sentinel/package.json @@ -1,6 +1,6 @@ { "name": "@sat-utils/sentinel", - "version": "0.0.2", + "version": "0.1.0", "description": "Lambda function for ingesting sentinel metadata to sat-api", "main": "index.js", "repository": { @@ -20,7 +20,7 @@ }, "homepage": "https://github.com/sat-utils/sat-api#readme", "dependencies": { - "@sat-utils/api-lib": "^0.0.2", + "@sat-utils/api-lib": "^0.1.0", "epsg": "^0.3.0", "got": "^8.3.2", "lodash.clonedeep": "^4.5.0", From 047d885ca2ec9e2fc3e45569f4367e4e2136036e Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 18 Sep 2018 18:56:48 -0400 Subject: [PATCH 24/28] remove top level package name and version --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 55aff24..92ffabe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,4 @@ { - "name": "sat-api", - "version": "0.1.0", "description": "One API to search public Satellites metadata", "main": "index.js", "repository": "https://github.com/sat-utils/sat-api", From ad63c20c231f39811eaa8eb79e2d5e694acf51a8 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 18 Sep 2018 18:57:05 -0400 Subject: [PATCH 25/28] ci: publish to npm on merge to master --- .circleci/config.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 971e585..4e84e0a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,8 +35,11 @@ jobs: name: Deploy example to aws command: | if [[ "$CIRCLE_BRANCH" == 'master' ]]; then - cd example - yarn - ./node_modules/.bin/kes cf deploy --template node_modules/@sat-utils/api/template --deployment dev --region us-east-1 --role arn:aws:iam::552819999234:role/sat-api-deployer-role-DeployerRole-JBBKUABAELDR + #cd example + #yarn + #./node_modules/.bin/kes cf deploy --template node_modules/@sat-utils/api/template --deployment dev --region us-east-1 --role arn:aws:iam::552819999234:role/sat-api-deployer-role-DeployerRole-JBBKUABAELDR + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + VERSION=$(jq --raw-output .version lerna.json) + node_modules/.bin/lerna publish --skip-git --repo-version $VERSION --yes --force-publish=* fi From 651e07e1167bd515833d404dd4a606038097e9ca Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Tue, 18 Sep 2018 19:00:42 -0400 Subject: [PATCH 26/28] change log --- CHANGES.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ea78d05..cd3f5bf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [v0.1.0] - 2018-09-18 + +### Fixed +- Fixed broken ingests for Landsat and Sentinel + ## [v0.0.2] ### Added @@ -37,6 +42,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Refactor several modules: metadata, landsat, sentinel - Refactor and improve splitting -[Unreleased]: https://github.com/sat-utils/sat-api/compare/v0.0.2...HEAD +[Unreleased]: https://github.com/sat-utils/sat-api/compare/v0.1.0...HEAD +[v0.1.0]: https://github.com/sat-utils/sat-api/compare/v0.0.2...v0.1.0 [v0.0.2]: https://github.com/sat-utils/sat-api/compare/legacy-v2.0.0...v0.0.2 [legacy-v2.0.0]: https://github.com/sat-utils/sat-api/tree/legacy \ No newline at end of file From 994010624529151705f311e01585faef3bef3777 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Fri, 28 Sep 2018 15:11:23 -0400 Subject: [PATCH 27/28] fix generated endpoint for links --- packages/api/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/api/index.js b/packages/api/index.js index 6d18cfb..0cac4d4 100644 --- a/packages/api/index.js +++ b/packages/api/index.js @@ -11,13 +11,15 @@ module.exports.handler = (event, context, cb) => { // get payload const method = event.httpMethod - const host = ( - 'X-Forwarded-Host' in event.headers ? - event.headers['X-Forwarded-Host'] : event.headers.Host - ) - let endpoint = `${event.headers['X-Forwarded-Proto']}://${host}` - if ('stage' in event.requestContext) { - endpoint = `${endpoint}/${event.requestContext.stage}` + let endpoint + if ('X-Forwarded-Host' in event.headers) { + endpoint = `${event.headers['X-Forwarded-Proto']}://${event.headers['X-Forwarded-Host']}` + if ('stage' in event.requestContext) { + endpoint = `${endpoint}/${event.requestContext.stage}` + } + } + else { + endpoint = `${event.headers['X-Forwarded-Proto']}://${event.headers.Host}` } const payload = { query: {}, headers: event.headers, endpoint: endpoint } From ef07c655f144cd1328207571a0b26a29cde5d4b1 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Mon, 1 Oct 2018 18:46:45 -0400 Subject: [PATCH 28/28] fix endpoint --- packages/api/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/api/index.js b/packages/api/index.js index 0cac4d4..6176d1f 100644 --- a/packages/api/index.js +++ b/packages/api/index.js @@ -14,12 +14,12 @@ module.exports.handler = (event, context, cb) => { let endpoint if ('X-Forwarded-Host' in event.headers) { endpoint = `${event.headers['X-Forwarded-Proto']}://${event.headers['X-Forwarded-Host']}` - if ('stage' in event.requestContext) { - endpoint = `${endpoint}/${event.requestContext.stage}` - } } else { endpoint = `${event.headers['X-Forwarded-Proto']}://${event.headers.Host}` + if ('stage' in event.requestContext) { + endpoint = `${endpoint}/${event.requestContext.stage}` + } } const payload = { query: {}, headers: event.headers, endpoint: endpoint }