Skip to content

Conversation

@wtrocki
Copy link
Contributor

@wtrocki wtrocki commented Mar 29, 2017

Motivation

Initial implementation of the file storage solution interface.
Interface initializes different client depending on the configuration passed in application.
Supported storage engineers:

  • AWS S3 storage
  s3: {
    s3Options: {
      accessKeyId: process.env.AWS_S3_ACCESS_KEY,
      secretAccessKey: process.env.AWS_S3_ACCESS_KEY_SECRET,
      region: process.env.AWS_S3_REGION
    },
    bucket: "raincatcher-files"
  }
  • Gridfs storage
var storageConfig = {
  gridFs: {
    mongoUrl: "mongodb://localhost:27017/files"
  }
};

Storage engine would be enabled only when file module would have flag in config set to true:

 usePersistentStorage: true

If flag is set to false files would be served from temporary storage (this would be used for demo apps for convenience and simplified setup). Alternative would be to have some localFile storage engine.

Notes

Implementation requires local file to be cached.
Buffer support on the way here: andrewrk/node-s3-client#154

@wtrocki wtrocki requested review from witmicko and removed request for austincunningham April 3, 2017 09:13
Copy link

@witmicko witmicko left a comment

Choose a reason for hiding this comment

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

looks good. Just a few comments.

}
};

var deferred = q.defer();
Copy link

Choose a reason for hiding this comment

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

We are migrating to using bluebird vs q.deffered as it is an antipattern https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-deferred-anti-pattern

Copy link
Contributor Author

@wtrocki wtrocki Apr 5, 2017

Choose a reason for hiding this comment

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

Bluebird developer telling that q api is anti pattern is not surprising.
We need to migrate to bluebird, but possibly using similar patterns across the all modules. Let's address this in our backlog as there are multiple migration steps and we should be consistent.

Copy link

Choose a reason for hiding this comment

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

@witmicko KISS. We should not focus on choosing whats worse anti-pattern. If we need then we should create follow up task with refactoring after having POC that bluebird is our choice

Copy link
Collaborator

@nialldonnellyfh nialldonnellyfh left a comment

Choose a reason for hiding this comment

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

Added some comments. Generally looks good though.


var params = {
localFile: fileLocation,
ACL: 'authenticated-read',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be a constant?

awsClient = s3.createClient(config);
}

function writeFile(namespace, fileName, fileLocation) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could probably use a comment here describing the function and parameters.

console.log(err);
deferred.reject(err.stack);
});
uploader.on('progress', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we doing anything with this progress event? If not we can probably remove the listener.

Key: file
};
try {
var buffer = awsClient.downloadStream(paramsStream);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a buffer or a stream ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's ReadableStream :)

if (!config || !config.mongoUrl) {
throw Error("Missing mongoUrl parameter for GridFs storage");
}
MongoClient.connect(config.mongoUrl, function(err, connection) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be passing back a Promise as MongoClient.connect is asynchronous?

}

function writeFile(namespace, fileName, fileLocation) {
if (!gfs) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think gfs should be a promise to take account of the async mongo connection.

Then you could have gfs.then(...)

package.json Outdated
"license": "MIT",
"dependencies": {
"debug": "^2.6.3",
"fh-wfm-mediator": "0.3.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

fh-wfm-mediator is a devDependency as the mediator is passed from the consuming application.

Copy link
Collaborator

@nialldonnellyfh nialldonnellyfh left a comment

Choose a reason for hiding this comment

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

Generally looks good. Would be good to add some unit tests.

Copy link

@vchepeli vchepeli left a comment

Choose a reason for hiding this comment

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

LGTM, small comments, needs to be validated and then unit tests added

```javascript
var parameters = {
// File namespace (folder)
namespace:null,
Copy link

Choose a reason for hiding this comment

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

what means null as namespace?

Copy link
Contributor Author

@wtrocki wtrocki Apr 6, 2017

Choose a reason for hiding this comment

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

default (root), no namespace etc.

@@ -0,0 +1 @@
// TODO Add code to support offline storage capabilities for client applications. No newline at end of file
Copy link

Choose a reason for hiding this comment

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

create JIRA for this task and put here JIRA#

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is jira and I'm going to work on this after merging this PR

}
};

var deferred = q.defer();
Copy link

Choose a reason for hiding this comment

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

@witmicko KISS. We should not focus on choosing whats worse anti-pattern. If we need then we should create follow up task with refactoring after having POC that bluebird is our choice

@wtrocki wtrocki force-pushed the RAINCATCH-652 branch 2 times, most recently from 4b12220 to ebabfc5 Compare April 6, 2017 13:42
@wtrocki wtrocki merged commit 65eb24f into master Apr 6, 2017
@wtrocki wtrocki deleted the RAINCATCH-652 branch April 6, 2017 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants