Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUMULUS-175 : Dashboard providers not in sync with AWS providers #234

Merged
merged 99 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
0f6b38b
add a lambda listener to dynamoDB
Mar 1, 2018
ef9c3a5
Use aws.s3() for s3.put
abarciauskas-bgse Mar 1, 2018
68972e2
Remove es requests from endpoints/collection.js
abarciauskas-bgse Mar 1, 2018
6283b7d
Some js syntax
abarciauskas-bgse Mar 1, 2018
cb034bd
INitial test file for endpoints/collections#list
abarciauskas-bgse Mar 1, 2018
eef1b7a
First passing test for test-endpoints
abarciauskas-bgse Mar 2, 2018
112a61d
Minor formatting change
abarciauskas-bgse Mar 2, 2018
0651f32
Remove unnecessary async
abarciauskas-bgse Mar 2, 2018
0bded00
Test for list rules
abarciauskas-bgse Mar 2, 2018
dc13c6c
Add comment to authCheck bool
abarciauskas-bgse Mar 2, 2018
f355950
Update list endpoint in endpoints/rules
abarciauskas-bgse Mar 2, 2018
716236a
Add stream specification for testing
abarciauskas-bgse Mar 3, 2018
5897973
Add TODO test
abarciauskas-bgse Mar 3, 2018
aadd41d
Add archiver
abarciauskas-bgse Mar 3, 2018
835e425
Make and rename test db indexer
abarciauskas-bgse Mar 3, 2018
ec7c968
Upgrade webpack
abarciauskas-bgse Mar 3, 2018
e8782be
Fix tests
abarciauskas-bgse Mar 3, 2018
9f1585c
Working test
abarciauskas-bgse Mar 3, 2018
b221d04
Hack es search for testing
abarciauskas-bgse Mar 4, 2018
b895d5e
Hack db-indexer for testing
abarciauskas-bgse Mar 4, 2018
5d380a4
Remove promisification
abarciauskas-bgse Mar 4, 2018
aa033e5
Revert commented code
abarciauskas-bgse Mar 4, 2018
60d7971
WIP tests
abarciauskas-bgse Mar 4, 2018
a67b403
Remove obsolete test file
abarciauskas-bgse Mar 4, 2018
0109204
Remove console log
abarciauskas-bgse Mar 4, 2018
80e2a3f
Revert change to models/base
abarciauskas-bgse Mar 4, 2018
097a847
Updated (Working\!) test
abarciauskas-bgse Mar 4, 2018
b2dc9e1
Working test
abarciauskas-bgse Mar 4, 2018
1dec5d6
Remove obsolete comment
abarciauskas-bgse Mar 4, 2018
cc67847
Revert change to lambdas/kinesis-consumer
abarciauskas-bgse Mar 4, 2018
7a41c07
Add lambda env vars in test
abarciauskas-bgse Mar 4, 2018
8445180
Update readme
abarciauskas-bgse Mar 4, 2018
640e072
Update LOCALSTACK_HOST env var
abarciauskas-bgse Mar 5, 2018
72be0eb
Attempt to fixt test
abarciauskas-bgse Mar 5, 2018
3d118fb
Remove comment and remove hash definition
abarciauskas-bgse Mar 5, 2018
a016508
Try building in circleci
abarciauskas-bgse Mar 5, 2018
ba1e5f8
Add aws.dynamodbstreams export
abarciauskas-bgse Mar 5, 2018
a250d1f
Skip db-indexer test
abarciauskas-bgse Mar 5, 2018
420920d
Revert change to circleci config
abarciauskas-bgse Mar 5, 2018
6fa6168
Add tests for collections endpoints
abarciauskas-bgse Mar 5, 2018
a1025e5
Skip before and after blocks in test-db-indexer
abarciauskas-bgse Mar 5, 2018
c177d73
Add TODO tests
abarciauskas-bgse Mar 5, 2018
cde24cc
Add test and update rules POST
abarciauskas-bgse Mar 5, 2018
e821ee9
Update methods and tests for rules endpoint
abarciauskas-bgse Mar 5, 2018
6e27a3d
Attempt to fix db-indexer test
abarciauskas-bgse Mar 5, 2018
985df5b
Skip db indexer tests
abarciauskas-bgse Mar 5, 2018
539af30
Revert change to circleci config
abarciauskas-bgse Mar 5, 2018
8f33f99
Add collections GET test
abarciauskas-bgse Mar 5, 2018
d937023
DRY collections endpoints tests
abarciauskas-bgse Mar 5, 2018
86a8d99
Move testEndpoints function to testUtils
abarciauskas-bgse Mar 5, 2018
7f2bc4a
Update rules endpoint tests to use testUtils#testEndpoint
abarciauskas-bgse Mar 5, 2018
a2f59ae
Add setup_remote_docker to circleci config
abarciauskas-bgse Mar 5, 2018
c050529
Remove .only from endpoints-rules
abarciauskas-bgse Mar 5, 2018
1b260c9
Remove es from rules and provider endpoints
abarciauskas-bgse Mar 5, 2018
65641e1
Add provider endpoints test and some syntax update in other tests
abarciauskas-bgse Mar 5, 2018
9887f79
Add LAMBDA_REMOTE_DOCKER: false to circleci config
abarciauskas-bgse Mar 5, 2018
8ffe593
Revert line deletion
abarciauskas-bgse Mar 5, 2018
36c487c
Use new lines for chained methods
abarciauskas-bgse Mar 5, 2018
3506cd3
Single arguments to functions with curly brace should be wrapped in p…
abarciauskas-bgse Mar 5, 2018
ef465ba
Single arguments to functions with curly brace should be wrapped in p…
abarciauskas-bgse Mar 5, 2018
735b1f1
Remove REVIEW comment
abarciauskas-bgse Mar 5, 2018
44049ec
Use DOCKERHOST
abarciauskas-bgse Mar 5, 2018
70ff7b3
Attempt to fix mapping value
abarciauskas-bgse Mar 5, 2018
45c0d3d
Attempt to fix script
abarciauskas-bgse Mar 5, 2018
f755f66
Attempt to fix script
abarciauskas-bgse Mar 5, 2018
879b85e
Attempt to fix script
abarciauskas-bgse Mar 5, 2018
001e00e
Valid yaml
abarciauskas-bgse Mar 5, 2018
ec04089
Remove .only from db indexer test
abarciauskas-bgse Mar 5, 2018
646ca31
Skip db-indexer tests again
abarciauskas-bgse Mar 5, 2018
e2f2434
Add range to collections
abarciauskas-bgse Mar 5, 2018
9b7ee0c
Update callback
abarciauskas-bgse Mar 5, 2018
017ab82
Fix list endpoints
abarciauskas-bgse Mar 5, 2018
8da4a47
Remove obsolete test code
abarciauskas-bgse Mar 6, 2018
092544f
Use aws.s3() directly (instead of through ingest
abarciauskas-bgse Mar 6, 2018
d8416f3
Use single quotes
abarciauskas-bgse Mar 6, 2018
63005e8
Fix test in collections
abarciauskas-bgse Mar 6, 2018
db4148b
Merge branch 'master' into abarciauskas-bgse_CUMULUS-175
abarciauskas-bgse Mar 6, 2018
a75daa3
Update api tests, remove only, skip db-indexer only on CI
abarciauskas-bgse Mar 6, 2018
fd229a2
Remove obsolete comment
abarciauskas-bgse Mar 6, 2018
dda5bae
Add process.env.TEST to faking lambda invocation
abarciauskas-bgse Mar 6, 2018
c8cd6fe
Add dummy test for db-indexer
abarciauskas-bgse Mar 6, 2018
c111242
Minor changes to rules endpoints
abarciauskas-bgse Mar 6, 2018
06be378
Use elasticsearch for LIST endpoints
abarciauskas-bgse Mar 6, 2018
5ec36c7
Revert change to eventSourceArn regex
abarciauskas-bgse Mar 6, 2018
76c7c08
Catch error in db-indexer
abarciauskas-bgse Mar 6, 2018
05b89d8
Update changelog
abarciauskas-bgse Mar 6, 2018
3eb8edd
Remove undefined export
abarciauskas-bgse Mar 6, 2018
29c7182
Add skip to tests
abarciauskas-bgse Mar 7, 2018
81cafc3
Remove obsolete module export
abarciauskas-bgse Mar 7, 2018
f3c1a8d
Use shorthand return
abarciauskas-bgse Mar 7, 2018
8d864ef
Update regex for test
abarciauskas-bgse Mar 7, 2018
d35f752
Fix test
abarciauskas-bgse Mar 7, 2018
8ffed62
Modify changelog message
abarciauskas-bgse Mar 7, 2018
c6371fd
Remove comment from test
abarciauskas-bgse Mar 7, 2018
0756f53
Update TODO comment
abarciauskas-bgse Mar 7, 2018
adf4b4b
Skip DB indexer tests
abarciauskas-bgse Mar 8, 2018
05c31a6
Var should be const
abarciauskas-bgse Mar 8, 2018
7512183
Merge branch 'master' into abarciauskas-bgse_CUMULUS-175
abarciauskas-bgse Mar 8, 2018
d8174e6
Merge branch 'master' into abarciauskas-bgse_CUMULUS-175
abarciauskas-bgse Mar 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- **CUMULUS-175: "Dashboard providers not in sync with AWS providers."** The root cause of this bug - DynamoDB operations not showing up in Elasticsearch - was shared by collections and rules. The fix was to update providers', collections' and rules; POST, PUT and DELETE endpoints to operate on DynamoDB and using DynamoDB streams to update Elasticsearch. The following packages were made:
- `@cumulus/deployment` deploys DynamoDB streams for the Collections, Providers and Rules tables as well as a new lambda function called `dbIndexer`. The `dbIndexer` lambda has an event source mapping which listens to each of the DynamoDB streams. The dbIndexer lambda receives events referencing operations on the DynamoDB table and updates the elasticsearch cluster accordingly.
- The `@cumulus/api` endpoints for collections, providers and rules _only_ query DynamoDB, with the exception of LIST endpoints and the collections' GET endpoint.

### Updated
- Broke up `kes.override.js` of @cumulus/deployment to multiple modules and moved to a new location
- Expanded @cumulus/deployment test coverage
Expand Down
5 changes: 3 additions & 2 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ See [Cumulus README](https://github.com/cumulus-nasa/cumulus/blob/master/README.
Running tests for kinesis-consumer depends on localstack. Once you have installed localstack, you can start it for dynamoDB only:

```
SERVICES=dynamodb localstack start
LAMBDA_EXECUTOR=docker localstack start
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are running tests from the root level of the repo, we should add this to the main readme if necessary. Alternatively, we can add the env variable to the docker-compose.yml, to have it available as part of the docker-compose up local command.

```

Then you can run tests locally via:

```bash
LOCALSTACK_HOST=localhost npm run test
export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this, I don't think there is a way to run this locally with our main docker image. So I'm not sure anymore if we have to move this to the root level of the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the db-indexer tests need some work to get working from the root of the repo. I'm going to skip them for now in hopes of returning to get them running as part of the larger test suite. This could help testing other lambdas, especially those in @cumulus/api.

LOCALSTACK_HOST=localhost DOCKERHOST=${DOCKERHOST} IS_LOCAL=true npm run test
```
12 changes: 12 additions & 0 deletions packages/api/config/lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ sf2snsEnd:
memory: 256
source: 'node_modules/@cumulus/api/dist/'

dbIndexer:
handler: index.dbIndexer
timeout: 300
memory: 512
source: 'node_modules/@cumulus/api/dist/'
envs:
ES_HOST:
function: "Fn::GetAtt"
array:
- '{{es.name}}Domain'
- DomainEndpoint

kinesisConsumer:
handler: index.kinesisConsumer
timeout: 100
Expand Down
32 changes: 13 additions & 19 deletions packages/api/endpoints/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const models = require('../models');
const Collection = require('../es/collections');
const RecordDoesNotExist = require('../lib/errors').RecordDoesNotExist;
const examplePayload = require('../tests/data/collections_post.json');
const { indexCollection, deleteRecord } = require('../es/indexer');

/**
* List all collections.
Expand All @@ -18,9 +17,7 @@ const { indexCollection, deleteRecord } = require('../es/indexer');
*/
function list(event, cb) {
const collection = new Collection(event);
collection.query().then(res => cb(null, res)).catch((e) => {
cb(e);
});
collection.query().then(res => cb(null, res)).catch(cb);
}

/**
Expand All @@ -37,8 +34,9 @@ function get(event, cb) {
.then((res) => {
const collection = new Collection(event);
return collection.getStats([res], [res.name]);
}).then(res => cb(null, res[0]))
.catch((e) => cb(e));
})
.then(res => cb(null, res[0]))
.catch(cb);
}

/**
Expand All @@ -63,10 +61,8 @@ function post(event, cb) {
.catch((e) => {
if (e instanceof RecordDoesNotExist) {
return c.create(data)
.then(() => Collection.es())
.then(esClient => indexCollection(esClient, data))
.then(() => cb(null, { message: 'Record saved', record: data }))
.catch(err => cb(err));
.catch(cb);
}
return cb(e);
});
Expand Down Expand Up @@ -94,11 +90,11 @@ function put(event, cb) {
const c = new models.Collection();

// get the record first
return c.get({ name, version }).then((originalData) => {
data = Object.assign({}, originalData, data);
return c.create(data);
}).then(() => Collection.es())
.then(esClient => indexCollection(esClient, data))
return c.get({ name, version })
.then((originalData) => {
data = Object.assign({}, originalData, data);
return c.create(data);
})
.then(() => cb(null, data))
.catch((err) => {
if (err instanceof RecordDoesNotExist) {
Expand All @@ -111,24 +107,22 @@ function put(event, cb) {
function del(event, cb) {
const name = _get(event.pathParameters, 'collectionName');
const version = _get(event.pathParameters, 'version');
const id = `${name}___${version}`;
const c = new models.Collection();

return c.get({ name, version })
.then(() => c.delete({ name, version }))
.then(() => Collection.es())
.then((esClient) => deleteRecord(esClient, id, 'collection'))
.then(() => cb(null, { message: 'Record deleted' }))
.catch(e => cb(e));
.catch(cb);
}

function handler(event, context) {
const httpMethod = _get(event, 'httpMethod');

if (!httpMethod) {
return context.fail('HttpMethod is missing');
}

return handle(event, context, true, (cb) => {
return handle(event, context, !process.env.TEST /* authCheck */, cb => {
if (event.httpMethod === 'GET' && event.pathParameters) {
get(event, cb);
}
Expand Down
43 changes: 15 additions & 28 deletions packages/api/endpoints/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
'use strict';

const _get = require('lodash.get');
const handle = require('../lib/response').handle;
const { handle } = require('../lib/response');
const models = require('../models');
const Search = require('../es/search').Search;
const { deleteRecord, indexProvider } = require('../es/indexer');
const RecordDoesNotExist = require('../lib/errors').RecordDoesNotExist;
const { Search } = require('../es/search');

/**
* List all providers.
Expand All @@ -16,9 +15,7 @@ const RecordDoesNotExist = require('../lib/errors').RecordDoesNotExist;
*/
function list(event, cb) {
const search = new Search(event, 'provider');
search.query().then(response => cb(null, response)).catch((e) => {
cb(e);
});
search.query().then(response => cb(null, response)).catch(cb);
}

/**
Expand All @@ -38,7 +35,8 @@ function get(event, cb) {
.then((res) => {
delete res.password;
cb(null, res);
}).catch((e) => cb(e));
})
.catch(cb);
}

/**
Expand All @@ -58,12 +56,8 @@ function post(event, cb) {
.catch((e) => {
if (e instanceof RecordDoesNotExist) {
return p.create(data)
.then((r) => {
data = r;
return Search.es();
}).then(esClient => indexProvider(esClient, data))
.then(() => cb(null, { message: 'Record saved', record: data }))
.catch(err => cb(err));
.then(data => cb(null, { message: 'Record saved', record: data }))
.catch(err => cb(err));
}
return cb(e);
});
Expand Down Expand Up @@ -91,17 +85,12 @@ function put(event, cb) {
return p.get({ id }).then((d) => {
originalData = d;
return p.update({ id }, data);
}).then(() => {
data = Object.assign({}, originalData, data);
return Search.es();
}).then(esClient => indexProvider(esClient, data))
.then(() => cb(null, data))
.catch((err) => {
if (err instanceof RecordDoesNotExist) {
return cb({ message: 'Record does not exist' });
}
return cb(err);
});
})
.then(data => cb(null, data))
.catch((err) => {
if (err instanceof RecordDoesNotExist) cb({ message: 'Record does not exist' });
return cb(err);
});
}

function del(event, cb) {
Expand All @@ -110,14 +99,12 @@ function del(event, cb) {

return p.get({ id })
.then(() => p.delete({ id }))
.then(() => Search.es())
.then((esClient) => deleteRecord(esClient, id, 'provider'))
.then(() => cb(null, { message: 'Record deleted' }))
.catch(e => cb(e));
.catch(cb);
}

function handler(event, context) {
handle(event, context, true, (cb) => {
handle(event, context, !process.env.TEST /* authCheck */, (cb) => {
if (event.httpMethod === 'GET' && event.pathParameters) {
get(event, cb);
}
Expand Down
38 changes: 9 additions & 29 deletions packages/api/endpoints/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ const _get = require('lodash.get');
const { justLocalRun } = require('@cumulus/common/local-helpers');
const { handle } = require('../lib/response');
const models = require('../models');
const { Search } = require('../es/search');
const { deleteRecord, indexRule } = require('../es/indexer');
const { RecordDoesNotExist } = require('../lib/errors');
const { Search } = require('../es/search');

/**
* List all providers.
Expand All @@ -17,9 +16,7 @@ const { RecordDoesNotExist } = require('../lib/errors');
*/
function list(event, cb) {
const search = new Search(event, 'rule');
search.query().then(response => cb(null, response)).catch((e) => {
cb(e);
});
search.query().then(response => cb(null, response)).catch(cb);
}

/**
Expand All @@ -36,7 +33,8 @@ function get(event, cb) {
.then((res) => {
delete res.password;
cb(null, res);
}).catch((e) => cb(e));
})
.catch(cb);
}

/**
Expand All @@ -56,12 +54,8 @@ function post(event, cb) {
.catch((e) => {
if (e instanceof RecordDoesNotExist) {
return model.create(data)
.then((r) => {
data = r;
return Search.es();
}).then(esClient => indexRule(esClient, data))
.then(() => cb(null, { message: 'Record saved', record: data }))
.catch(err => cb(err));
.then(r => cb(null, { message: 'Record saved', record: r }))
.catch(cb);
}
return cb(e);
});
Expand Down Expand Up @@ -110,9 +104,7 @@ async function put(event) {
return;
}

data = await model.update(originalData, data);
const esClient = await Search.es();
await indexRule(esClient, data);
return model.update(originalData, data);
}

async function del(event) {
Expand All @@ -121,15 +113,12 @@ async function del(event) {

name = name.replace(/%20/g, ' ');

const record = await model.get({ name });
await model.delete(record);
const esClient = await Search.es();
await deleteRecord(esClient, name, 'rule');
await model.get({ name }).then(record => model.delete(record));
return { message: 'Record deleted' };
}

function handler(event, context) {
handle(event, context, true, (cb) => {
return handle(event, context, !process.env.TEST /* authCheck */, cb => {
if (event.httpMethod === 'GET' && event.pathParameters) {
get(event, cb);
}
Expand All @@ -149,12 +138,3 @@ function handler(event, context) {
}

module.exports = handler;


justLocalRun(() => {
//put({ pathParameters: { name: 'discover_aster' }, body: '{"action":"rerun"}' }).then(r => console.log(r)).catch(e => console.log(e)); // eslint-disable-line max-len
//handler(postPayload, {
//succeed: r => console.log(r),
//failed: e => console.log(e)
//}, (e, r) => console.log(e, r));
});
1 change: 1 addition & 0 deletions packages/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports.schemas = require('./endpoints/schemas');
exports.stats = require('./endpoints/stats');
exports.version = require('./endpoints/version');
exports.distribution = require('./endpoints/distribution');
exports.dbIndexer = require('./lambdas/db-indexer');

exports.jobs = require('./lambdas/jobs');
exports.bootstrap = require('./lambdas/bootstrap').handler;
Expand Down
Loading