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

feature: ZENKO-315 Add NFS property to BucketInfo #509

Merged
merged 1 commit into from
Jun 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 23 additions & 4 deletions lib/models/BucketInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const LifecycleConfiguration = require('./LifecycleConfiguration');

// WHEN UPDATING THIS NUMBER, UPDATE MODELVERSION.MD CHANGELOG
// MODELVERSION.MD can be found in S3 repo: lib/metadata/ModelVersion.md
const modelVersion = 8;
const modelVersion = 9;

class BucketInfo {
/**
Expand Down Expand Up @@ -53,13 +53,14 @@ class BucketInfo {
* @param {string} [uid] - unique identifier for the bucket, necessary
* @param {string} readLocationConstraint - readLocationConstraint for bucket
* addition for use with lifecycle operations
* @param {boolean} [isNFS] - whether the bucket is on NFS
*/
constructor(name, owner, ownerDisplayName, creationDate,
mdBucketModelVersion, acl, transient, deleted,
serverSideEncryption, versioningConfiguration,
locationConstraint, websiteConfiguration, cors,
replicationConfiguration, lifecycleConfiguration, uid,
readLocationConstraint) {
readLocationConstraint, isNFS) {
assert.strictEqual(typeof name, 'string');
assert.strictEqual(typeof owner, 'string');
assert.strictEqual(typeof ownerDisplayName, 'string');
Expand Down Expand Up @@ -153,6 +154,7 @@ class BucketInfo {
this._cors = cors || null;
this._lifecycleConfiguration = lifecycleConfiguration || null;
this._uid = uid || uuid();
this._isNFS = isNFS || null;
return this;
}
/**
Expand All @@ -178,6 +180,7 @@ class BucketInfo {
replicationConfiguration: this._replicationConfiguration,
lifecycleConfiguration: this._lifecycleConfiguration,
uid: this._uid,
isNFS: this._isNFS,
};
if (this._websiteConfiguration) {
bucketInfos.websiteConfiguration =
Expand All @@ -199,7 +202,7 @@ class BucketInfo {
obj.transient, obj.deleted, obj.serverSideEncryption,
obj.versioningConfiguration, obj.locationConstraint, websiteConfig,
obj.cors, obj.replicationConfiguration, obj.lifecycleConfiguration,
obj.uid, obj.readLocationConstraint);
obj.uid, obj.readLocationConstraint, obj.isNFS);
}

/**
Expand All @@ -223,7 +226,7 @@ class BucketInfo {
data._versioningConfiguration, data._locationConstraint,
data._websiteConfiguration, data._cors,
data._replicationConfiguration, data._lifecycleConfiguration,
data._uid, data._readLocationConstraint);
data._uid, data._readLocationConstraint, data._isNFS);
}

/**
Expand Down Expand Up @@ -559,6 +562,22 @@ class BucketInfo {
getUid() {
return this._uid;
}
/**
* Check if the bucket is an NFS bucket.
* @return {boolean} - Wether the bucket is NFS or not
*/
isNFS() {
return this._isNFS;
}
/**
* Set whether the bucket is an NFS bucket.
* @param {boolean} isNFS - Wether the bucket is NFS or not
* @return {BucketInfo} - bucket info instance
*/
setIsNFS(isNFS) {
this._isNFS = isNFS;
return this;
}
}

module.exports = BucketInfo;
27 changes: 25 additions & 2 deletions lib/models/ObjectMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class ObjectMD {
role: '',
storageType: '',
dataStoreVersionId: '',
isNFS: null,
},
'dataStoreName': '',
};
Expand Down Expand Up @@ -675,7 +676,10 @@ class ObjectMD {
* @return {string} The encoded object versionId
*/
getEncodedVersionId() {
return VersionIDUtils.encode(this.getVersionId());
if (this.getVersionId()) {
return VersionIDUtils.encode(this.getVersionId());
}
return undefined;
}

/**
Expand Down Expand Up @@ -706,7 +710,7 @@ class ObjectMD {
*/
setReplicationInfo(replicationInfo) {
const { status, backends, content, destination, storageClass, role,
storageType, dataStoreVersionId } = replicationInfo;
storageType, dataStoreVersionId, isNFS } = replicationInfo;
Copy link
Contributor

Choose a reason for hiding this comment

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

fromNFS could read better, along with setReplicationFromNFS()?

Copy link
Contributor

Choose a reason for hiding this comment

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

we "cross repository" agreed on "isNFS" to carry the fact that a bucket might be exported with NFS.

this._data.replicationInfo = {
status,
backends,
Expand All @@ -716,6 +720,7 @@ class ObjectMD {
role,
storageType: storageType || '',
dataStoreVersionId: dataStoreVersionId || '',
isNFS: isNFS || null,
};
return this;
}
Expand All @@ -734,6 +739,24 @@ class ObjectMD {
return this;
}

/**
* Set whether the replication is occurring from an NFS bucket.
* @param {Boolean} isNFS - Whether replication from an NFS bucket
* @return {ObjectMD} itself
*/
setReplicationIsNFS(isNFS) {
this._data.replicationInfo.isNFS = isNFS;
return this;
}

/**
* Get whether the replication is occurring from an NFS bucket.
* @return {Boolean} Whether replication from an NFS bucket
*/
getReplicationIsNFS() {
return this._data.replicationInfo.isNFS;
}

setReplicationSiteStatus(site, status) {
const backend = this._data.replicationInfo.backends
.find(o => o.site === site);
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/models/BucketInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Object.keys(acl).forEach(
testCorsConfiguration,
testReplicationConfiguration,
testLifecycleConfiguration,
testUid);
testUid, undefined, true);

describe('serialize/deSerialize on BucketInfo class', () => {
const serialized = dummyBucket.serialize();
Expand Down Expand Up @@ -164,6 +164,7 @@ Object.keys(acl).forEach(
lifecycleConfiguration:
dummyBucket._lifecycleConfiguration,
uid: dummyBucket._uid,
isNFS: dummyBucket._isNFS,
};
assert.strictEqual(serialized, JSON.stringify(bucketInfos));
done();
Expand Down Expand Up @@ -279,6 +280,13 @@ Object.keys(acl).forEach(
it('getUid should return unique id of bucket', () => {
assert.deepStrictEqual(dummyBucket.getUid(), testUid);
});
it('isNFS should return whether bucket is on NFS', () => {
assert.deepStrictEqual(dummyBucket.isNFS(), true);
});
it('setIsNFS should set whether bucket is on NFS', () => {
dummyBucket.setIsNFS(false);
assert.deepStrictEqual(dummyBucket.isNFS(), false);
});
});

describe('setters on BucketInfo class', () => {
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/models/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('ObjectMD class setters/getters', () => {
role: '',
storageType: '',
dataStoreVersionId: '',
isNFS: null,
}],
['ReplicationInfo', {
status: 'PENDING',
Expand All @@ -97,8 +98,11 @@ describe('ObjectMD class setters/getters', () => {
'arn:aws:iam::account-id:role/dest-resource',
storageType: 'aws_s3',
dataStoreVersionId: '',
isNFS: null,
}],
['DataStoreName', null, ''],
['ReplicationIsNFS', null, null],
['ReplicationIsNFS', true],
].forEach(test => {
const property = test[0];
const testValue = test[1];
Expand Down