Skip to content

Conversation

@dora-korpar
Copy link
Contributor

Adds functionality to get object from specific location by passing header 'x-amz-location-constraint'

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from 926487e to 577c8fc Compare April 12, 2018 17:49
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

1 similar comment
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from fade444 to 5c9801a Compare April 17, 2018 04:15
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.


module.exports = {
locationConstraintCheck,
locationHeaderCheck,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend separating it to it's own module to keep things modular.

const location = headers['x-amz-location-constraint'];
if (location) {
const locationConstraints = Object.keys(config.locationConstraints);
const validLocation = locationConstraints.includes(location);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can just be

 const validLocation = config.locationConstraints[location];

const locationConstraints = Object.keys(config.locationConstraints);
const validLocation = locationConstraints.includes(location);
if (!validLocation) {
return errors.InvalidArgument.customizeDescription(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use errors.InvalidLocationConstraint since we already have it.

}
const locConfigObj = config.locationConstraints[location];
const bucketMatch = locConfigObj.details.bucketMatch;
let backendKey = objectKey;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ternary operators make the logic look easy here

const backendKey = bucketMatch ? objectKey : `${bucketName}/${objectKey}`;

const locMatch = replicationInfo.backends.find(
backend => backend.site === locationObj.location);
if (!locMatch) {
repBackendResult.error = errors.InvalidArgument.customizeDescription(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use InvalidLocationConstraint for this as well.

return repBackendResult;
}
if (locMatch.status === 'PENDING') {
repBackendResult.error = errors.InternalError.customizeDescription(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use errors.NoSuchKey here

* @param {string} locationObj.location - name of location constraint
* @param {string} locationObj.key - keyname of object in location constraint
* @param {string} locationObj.type - type of location constraint
* @param {object} replicationInfo - information about object replication
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please expand on the properties of this object.

* @param {object} headers - request headers
* @param {string} objectKey - key name of object
* @param {string} bucketName - name of bucket
* @return {object} - error if header location is not valid or object
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please expand on the properties of the return object and also include undefined as a return value. This seems to be the format generally used

@return {undefined|Object}
@return {any} return.value The value of the attribute
@return {boolean} return.modified If the value has been changed
etc

log.trace('invalid location constraint to get from', {
location: request.headers['x-amz-location-constraint'],
error: locCheckResult,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can return the callback early avoid any further processing.

@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

1 similar comment
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from ba79b9b to d252705 Compare April 17, 2018 20:03
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from d252705 to 1f8fc75 Compare April 17, 2018 21:46
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

1 similar comment
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@ironman-machine
Copy link
Contributor

CONFLICT (add/add): Merge conflict in tests/unit/multipleBackend/locationConstraintCheck.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/utils/gcpUtils.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/upload.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/putTagging.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/put.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/initiateMpu.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/head.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/getTagging.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/get.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/deleteTagging.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/deleteMpu.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/delete.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/copy.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/object/completeMpu.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/bucket/putVersioning.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/bucket/head.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/bucket/getVersioning.js
CONFLICT (add/add): Merge conflict in tests/functional/raw-node/test/GCP/bucket/get.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/utils.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/put/putGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/put/put.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/objectTagging/taggingAwsVersioning-putget.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/objectTagging/taggingAwsVersioning-delete.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/objectTagging/objectTagging.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/objectPutCopyPart/objectPutCopyPartGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/objectPutCopyPart/objectPutCopyPartAzure.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/objectCopy/objectCopyAwsVersioning.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/objectCopy/objectCopy.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/objectCopy/azureObjectCopy.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/mpuParts/putPartGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/mpuComplete/mpuAwsVersioning.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/mpuComplete/completeMPUGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/mpuComplete/azureCompleteMPU.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/mpuAbort/abortMPUGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/listParts/listPartsGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/listParts/azureListParts.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/initMPU/initMPUGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/initMPU/initMPUAzure.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/get/getGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/get/getAwsVersioning.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/get/get.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/delete/deleteGcp.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/delete/deleteAwsVersioning.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/delete/delete.js
CONFLICT (add/add): Merge conflict in tests/functional/aws-node-sdk/test/multipleBackend/acl/aclAwsVersioning.js
CONFLICT (add/add): Merge conflict in lib/api/objectGet.js
CONFLICT (add/add): Merge conflict in lib/api/apiUtils/object/locationConstraintCheck.js

'passed in location header');
return repBackendResult;
}
if (locMatch.status === 'PENDING') {
Copy link
Contributor

Choose a reason for hiding this comment

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

We may also want to handle FAILED status the same way, or alternatively, return the locator if status is COMPLETED, and fail otherwise and provide the replication status as an extra info in the returned message.

* @return {object} contains error if no replication backend matches or
* dataLocator object
*/
function replicationBackendCompare(locationObj, replicationInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about renaming to getReplicationBackendDataLocator, since this is the main purpose of the function (and especially since the function is exported as a utility function potentially useful for others - thinking of transient source 😄).

@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from e5beef7 to a52ce02 Compare April 18, 2018 22:15
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from a52ce02 to b102bfa Compare April 18, 2018 22:16
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from b102bfa to 6141c35 Compare April 19, 2018 22:33
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from 6141c35 to 5cf6e08 Compare April 19, 2018 22:47
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from 5cf6e08 to 4ad2032 Compare April 19, 2018 22:54
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar
Copy link
Contributor Author

@ironman-machine try

@ironman-machine
Copy link
Contributor

Hello @dora-korpar

"try": Success: Try build successfully launched on 'http://ci.ironmann.io/gh/scality/Integration/21340' with the following env. args:

{
    "DEFAULT_BRANCH": "master",
    "SCALITY_INTEGRATION_BRANCH": "ultron/master",
    "REPO_NAME": "S3",
    "SCALITY_S3_BRANCH": "ft/ZENKO-229-get-using-location"
}

@dora-korpar dora-korpar changed the title Ft/ZENKO-229 get using location ft/ZENKO-229 get using location Apr 19, 2018
Copy link

@bennettbuchanan bennettbuchanan left a comment

Choose a reason for hiding this comment

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

:shipit:

}
if (['PENDING', 'FAILED'].includes(locMatch.status)) {
repBackendResult.error = errors.NoSuchKey.customizeDescription(
'Object replication to specified backend is not complete');

Choose a reason for hiding this comment

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

I could imagine it being nice to include the status in the description, particularly if the status is failed. That way the user would know to retry the operation.

@dora-korpar
Copy link
Contributor Author

@ironman-machine try

@ironman-machine
Copy link
Contributor

Hello @dora-korpar

"try": Success: Try build successfully launched on 'http://ci.ironmann.io/gh/scality/Integration/21351' with the following env. args:

{
    "DEFAULT_BRANCH": "master",
    "SCALITY_INTEGRATION_BRANCH": "ultron/master",
    "REPO_NAME": "S3",
    "SCALITY_S3_BRANCH": "ft/ZENKO-229-get-using-location"
}

@dora-korpar
Copy link
Contributor Author

@ironman-machine try

@ironman-machine
Copy link
Contributor

Hello @dora-korpar

"try": Success: Try build successfully launched on 'http://ci.ironmann.io/gh/scality/Integration/21376' with the following env. args:

{
    "DEFAULT_BRANCH": "master",
    "SCALITY_INTEGRATION_BRANCH": "ultron/master",
    "REPO_NAME": "S3",
    "SCALITY_S3_BRANCH": "ft/ZENKO-229-get-using-location"
}

@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from a727ebc to 6c6a51e Compare April 23, 2018 17:33
@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar
Copy link
Contributor Author

@ironman-machine try

@ironman-machine
Copy link
Contributor

Hello @dora-korpar

"try": Success: Try build successfully launched on 'http://ci.ironmann.io/gh/scality/Integration/21412' with the following env. args:

{
    "DEFAULT_BRANCH": "master",
    "SCALITY_INTEGRATION_BRANCH": "ultron/master",
    "REPO_NAME": "S3",
    "SCALITY_S3_BRANCH": "ft/ZENKO-229-get-using-location"
}

@dora-korpar
Copy link
Contributor Author

@ironman-machine try

@ironman-machine
Copy link
Contributor

Hello @dora-korpar

"try": Success: Try build successfully launched on 'http://ci.ironmann.io/gh/scality/Integration/21436' with the following env. args:

{
    "DEFAULT_BRANCH": "master",
    "SCALITY_INTEGRATION_BRANCH": "ultron/master",
    "REPO_NAME": "S3",
    "SCALITY_S3_BRANCH": "ft/ZENKO-229-get-using-location"
}

@ironman-machine
Copy link
Contributor

☀️ 👍 circleCI test succeeded!

@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@dora-korpar dora-korpar changed the base branch from master to z/1.0 April 23, 2018 22:22
rahulreddy
rahulreddy previously approved these changes Apr 24, 2018
@dora-korpar dora-korpar force-pushed the ft/ZENKO-229-get-using-location branch from 719795e to d6e8201 Compare April 24, 2018 17:38
@ironman-machine ironman-machine dismissed stale reviews from jonathan-gramain, alexanderchan-scality, and rahulreddy April 24, 2018 17:38

Do it again human slave!:point_right: :runner: (Oh and the pull request has been updated, by the way.)

@ironman-machine
Copy link
Contributor

PR has been updated. Reviewers, please be cautious.

@nicolas2bert nicolas2bert merged commit d52762c into z/1.0 Apr 25, 2018
@rahulreddy rahulreddy deleted the ft/ZENKO-229-get-using-location branch April 26, 2018 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants