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

storage: add storage class enums #787

Merged
merged 1 commit into from
Aug 14, 2015
Merged

storage: add storage class enums #787

merged 1 commit into from
Aug 14, 2015

Conversation

callmehiphop
Copy link
Contributor

Closes #779

Implemented per conversation in original issue, however it might be better to group these together for documentation purposes. The current implementation creates links for both dra and nearline, where I imagine it would be better to lump them together into a single property to consolidate the documentation on storage classes.

e.g.

var metadata = {
  storageClass: gcs.type.nearline
};

@callmehiphop callmehiphop added the api: storage Issues related to the Cloud Storage API. label Aug 7, 2015
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 7, 2015
@stephenplusplus
Copy link
Contributor

Thanks for doing this!

Even though I wanted all lowercase, I'm not sure that was a good call. Constants always want to be loud, and we already have gcs.acl.READER_ROLE and such. Should we maybe do that here: gcs.storageClass.DRA?

Another thing, ACLs are available for buckets and files, so it made sense to have them sit atop both at the Storage class level. With storageClass, however, this is only used when creating a bucket. Should it be localized as such: gcs.bucket.storageClass.DRA?

Example:

var gcloud = require('gcloud');
var gcs = gcloud.gcs({ projectId: 'grape-spaceship-123' });

gcs.createBucket({
  storageClass: gcs.bucket.storageClass.DRA
}, function(err, bucket, apiResponse) {});

I really don't prefer this constant system over just a property on the metadata object:

var gcloud = require('gcloud');
var gcs = gcloud.gcs({ projectId: 'grape-spaceship-123' });

gcs.createBucket({
  dra: true
}, function(err, bucket, apiResponse) {});

Or best-guessing from storageClass input:

var gcloud = require('gcloud');
var gcs = gcloud.gcs({ projectId: 'grape-spaceship-123' });

gcs.createBucket({
  storageClass: 'dra' // => we expand this to `DURABLE_REDUCED_AVAILABILITY`
}, function(err, bucket, apiResponse) {});

@jgeewax which approach do you think is best here?

@callmehiphop
Copy link
Contributor Author

So I ended up just uppercasing the constant names to DRA and NEARLINE, somehow this magically hoisted the property names in the documentation, so I think this is the way to go.

gcs.createBucket({
  storageClass: gcs.DRA
}, callback);

@stephenplusplus
Copy link
Contributor

I strongly think we should go with the second suggestion above. That's the easiest solution for the user, and won't inflate our API. These constants only affect createBucket and can only be used there.

@callmehiphop
Copy link
Contributor Author

I think we could easily support both? If we use the metadata property version we'll still need to have an alias to the expanded version.

What are your feelings on something like

Storage.DRA = 'DURABLE_REDUCED_AVAILABILITY';

Storage.prototype.createBucket = function(name, metadata, callback) {
  var body = extend(metadata, { name: name });
  ['dra', 'nearline'].forEach(function(storageClass) {
    if (body[storageClass]) {
      delete body[storageClass];
      body.storageClass = Storage[storageClass.toUpperCase()];
    }
  });
  this.makeReq_('POST, '', null, body, callback);
};

@stephenplusplus
Copy link
Contributor

I still think it's overkill. We can keep the expanded version in a map local to the createBucket function. This is a very small use case, I don't think we should stuff random metadata properties on the "global" Storage class.

@callmehiphop
Copy link
Contributor Author

@stephenplusplus Ok, I changed it to metadata properties. I updated the documentation to show they are optional properties and added links to the official doc for each. I also added a couple of unit tests for each.

Would you prefer reduce over forEach?

@stephenplusplus
Copy link
Contributor

Yay! Can you just add "@"resources for https://cloud.google.com/storage/docs/storage-classes, Nearline, and DRA?

@stephenplusplus
Copy link
Contributor

I think how you have it is good. I would have probably just done:

if (body.dra) {
  body.storageClass = 'DUR...';
  delete body.dra;
}

if (body.nearline) {
  body.storageClass = 'NEARLINE';
  delete body.nearline;
}

So any fanciness you have is good with me :)

@callmehiphop
Copy link
Contributor Author

Yay! Can you just add "@"resources for https://cloud.google.com/storage/docs/storage-classes, Nearline, and DRA?

done!

uppercased constants

changed constants to metadata properties

added resource links
stephenplusplus added a commit that referenced this pull request Aug 14, 2015
storage: add storage class enums
@stephenplusplus stephenplusplus merged commit 0b901c1 into googleapis:master Aug 14, 2015
@stephenplusplus
Copy link
Contributor

Thanks!

@callmehiphop callmehiphop deleted the storage-class branch August 18, 2015 19:53
sofisl pushed a commit that referenced this pull request Nov 11, 2022
sofisl pushed a commit that referenced this pull request Jan 10, 2023
sofisl pushed a commit that referenced this pull request Jan 24, 2023
Committer: @cherba
PiperOrigin-RevId: 389755489
sofisl pushed a commit that referenced this pull request Jan 24, 2023
sofisl pushed a commit that referenced this pull request Jan 25, 2023
Committer: @cherba
PiperOrigin-RevId: 389755489
sofisl pushed a commit that referenced this pull request Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants