From f05854345598a2be3978557d41c39e34c3f61b65 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Tue, 22 Mar 2016 16:47:05 -0700 Subject: [PATCH 01/12] fix async patch and post run --- .../ms-rest-azure/lib/azureServiceClient.js | 201 ++++++++---------- .../NodeJS/ms-rest-azure/lib/pollingState.js | 65 +++--- 2 files changed, 128 insertions(+), 138 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index ae1798dc5e56a..4b967ca5cd373 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -32,15 +32,15 @@ function AzureServiceClient(credentials, options) { if (!credentials) { throw new Error('Azure clients require credentials.'); } - + AzureServiceClient['super_'].call(this, credentials, options); - + this.acceptLanguage = 'en-US'; this.generateClientRequestId = true; this.longRunningOperationRetryTimeout = 30; if (!options) options = {}; - + if (options.acceptLanguage !== null && options.acceptLanguage !== undefined) { this.acceptLanguage = options.acceptLanguage; } @@ -62,68 +62,73 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfInitialRequest, options, callback) { var self = this; - if(!callback && typeof options === 'function') { + if (!callback && typeof options === 'function') { callback = options; options = null; } if (!callback) { throw new Error('Missing callback'); } - + if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - + + if (!resultOfInitialRequest.response) { + return callback(new Error('Missing resultOfInitialRequest.response')); + } + if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 201 && - resultOfInitialRequest.response.statusCode !== 202) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', + resultOfInitialRequest.response.statusCode !== 201 && + resultOfInitialRequest.response.statusCode !== 202 && + resultOfInitialRequest.response.statusCode !== 204) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', resultOfInitialRequest.response.statusCode))); } + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } - var resourceUrl = resultOfInitialRequest.request.url; this._options = options; - + async.whilst( - //while condition - function () { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function (e) { - return pollingState.status === e; + function() { + var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { + return e === pollingState.status; }); return !finished; }, - //while loop body - function (callback) { - setTimeout(function () { + function(callback) { + setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, false, function (err) { + self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeaderOnPut(pollingState, function (err) { + self._updateStateFromLocationHeader(pollingState, function(err) { return callback(err); }); - } else { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function (err) { + } else if (resultOfInitialRequest.request.method === "PUT") { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); + } else { + return callback(new Error('Location header is missing from long running operation.')); } }, pollingState.getTimeout()); }, //when done - function (err) { + function(err) { if (pollingState.status === LroStates.Succeeded) { - if (!pollingState.resource) { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function (err) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== "DELETE" && resultOfInitialRequest.request.method !== "POST") { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); } else { @@ -142,9 +147,9 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfInitialRequest, options, callback) { var self = this; - + if (!callback && typeof options === 'function') { callback = options; options = null; @@ -152,45 +157,52 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf if (!callback) { throw new Error('Missing callback'); } - + if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - + if (!resultOfInitialRequest.response) { return callback(new Error('Missing resultOfInitialRequest.response')); } - + if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 202 && - resultOfInitialRequest.response.statusCode !== 204) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', + resultOfInitialRequest.response.statusCode !== 201 && + resultOfInitialRequest.response.statusCode !== 202 && + resultOfInitialRequest.response.statusCode !== 204) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', resultOfInitialRequest.response.statusCode))); } - + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } + + var resourceUrl = resultOfInitialRequest.request.url; this._options = options; async.whilst( - function () { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function (e) { + function() { + var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { return e === pollingState.status; }); return !finished; }, - function (callback) { - setTimeout(function () { + function(callback) { + setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function (err) { + self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeaderOnPostOrDelete(pollingState, function (err) { + self._updateStateFromLocationHeader(pollingState, function(err) { + return callback(err); + }); + } else if (resultOfInitialRequest.request.method === "PUT") { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); } else { @@ -198,9 +210,16 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf } }, pollingState.getTimeout()); }, - function (err) { - if (pollingState.status === LroStates.Succeeded ) { - return callback(null, pollingState.getOperationResponse()); + //when done + function(err) { + if (pollingState.status === LroStates.Succeeded) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== "DELETE" && resultOfInitialRequest.request.method !== "POST") { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { + return callback(err, pollingState.getOperationResponse()); + }); + } else { + return callback(null, pollingState.getOperationResponse()); + } } else { return callback(pollingState.getCloudError(err)); } @@ -212,14 +231,14 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf * @param {object} [pollingState] - The object to persist current operation state. * @param {boolean} [inPostOrDelete] - Invoked by Post Or Delete operation. */ -AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = function (pollingState, inPostOrDelete, callback) { - this._getStatus(pollingState.azureAsyncOperationHeaderLink, function (err, result) { +AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = function(pollingState, inPostOrDelete, callback) { + this._getStatus(pollingState.azureAsyncOperationHeaderLink, function(err, result) { if (err) return callback(err); - + if (!result.body || !result.body.status) { return callback(new Error('The response from long running operation does not contain a body.')); } - + pollingState.status = result.body.status; pollingState.error = result.body.error; pollingState.response = result.response; @@ -233,36 +252,25 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio }; /** - * Retrieve PUT operation status by polling from 'location' header. + * Retrieve PUT/POST/PATCH/DELETE operation status by polling from 'location' header. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromLocationHeaderOnPut = function (pollingState, callback) { - this._getStatus(pollingState.locationHeaderLink, function (err, result) { +AzureServiceClient.prototype._updateStateFromLocationHeader = function(pollingState, callback) { + this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); - + pollingState.updateResponse(result.response); pollingState.request = result.request; - + var statusCode = result.response.statusCode; if (statusCode === 202) { pollingState.status = LroStates.InProgress; - } - else if (statusCode === 200 || - statusCode === 201) { - - if (!result.body) { - return callback(new Error('The response from long running operation does not contain a body.')); - } - - // In 202 pattern on PUT ProvisioningState may not be present in - // the response. In that case the assumption is the status is Succeeded. - if (result.body.properties && result.body.properties.provisioningState) { - pollingState.status = result.body.properties.provisioningState; - } - else { - pollingState.status = LroStates.Succeeded; - } - + } else if (statusCode === 200 || + statusCode === 201 || + statusCode === 204) { + + pollingState.status = LroStates.Succeeded; + pollingState.error = { code: pollingState.Status, message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) @@ -273,59 +281,34 @@ AzureServiceClient.prototype._updateStateFromLocationHeaderOnPut = function (pol }); }; -/** - * Retrieve POST or DELETE operation status by polling from 'location' header. - * @param {object} [pollingState] - The object to persist current operation state. - */ -AzureServiceClient.prototype._updateStateFromLocationHeaderOnPostOrDelete = function (pollingState, callback) { - this._getStatus(pollingState.locationHeaderLink, function (err, result) { - if (err) return callback(err); - - pollingState.updateResponse(result.response); - pollingState.request = result.request; - - var statusCode = result.response.statusCode; - if (statusCode === 202) { - pollingState.status = LroStates.InProgress; - } - else if (statusCode === 200 || - statusCode === 201 || - statusCode === 204) { - pollingState.status = LroStates.Succeeded; - pollingState.resource = result.body; - } - callback(null); - }); -}; - /** * Polling for resource status. * @param {function} [resourceUrl] - The url of resource. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromGetResourceOperation = function (resourceUrl, pollingState, callback) { - this._getStatus(resourceUrl, function (err, result) { +AzureServiceClient.prototype._updateStateFromGetResourceOperation = function(resourceUrl, pollingState, callback) { + this._getStatus(resourceUrl, function(err, result) { if (err) return callback(err); if (!result.body) { return callback(new Error('The response from long running operation does not contain a body.')); } - + if (result.body.properties && result.body.properties.provisioningState) { pollingState.status = result.body.properties.provisioningState; } else { pollingState.status = LroStates.Succeeded; } - + //we might not throw an error, but initialize here just in case. pollingState.error = { code: pollingState.status, message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) }; - + pollingState.updateResponse(result.response); pollingState.request = result.request; pollingState.resource = result.body; - + //nothing to return, the 'pollingState' has all the info we care. callback(null); }); @@ -335,21 +318,21 @@ AzureServiceClient.prototype._updateStateFromGetResourceOperation = function (re * Retrieve operation status by querying the operation URL. * @param {string} [operationUrl] - URL used to poll operation result. */ -AzureServiceClient.prototype._getStatus = function (operationUrl, callback) { +AzureServiceClient.prototype._getStatus = function(operationUrl, callback) { var self = this; if (!operationUrl) { return callback(new Error('operationUrl cannot be null.')); } - + // Construct URL var requestUrl = operationUrl.replace(' ', '%20'); - + // Create HTTP transport objects var httpRequest = new WebResource(); httpRequest.method = 'GET'; httpRequest.headers = {}; httpRequest.url = requestUrl; - if(this._options) { + if (this._options) { for (var headerName in this._options['customHeaders']) { if (this._options['customHeaders'].hasOwnProperty(headerName)) { httpRequest.headers[headerName] = this._options['customHeaders'][headerName]; @@ -357,13 +340,13 @@ AzureServiceClient.prototype._getStatus = function (operationUrl, callback) { } } // Send Request - return self.pipeline(httpRequest, function (err, response, responseBody) { + return self.pipeline(httpRequest, function(err, response, responseBody) { if (err) { return callback(err); } var statusCode = response.statusCode; if (statusCode !== 200 && statusCode !== 201 && statusCode !== 202 && statusCode !== 204) { - var error = new Error(util.format('Invalid status code with response body "%s" occurred ' + + var error = new Error(util.format('Invalid status code with response body "%s" occurred ' + 'when polling for operation status.', responseBody)); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -388,8 +371,8 @@ AzureServiceClient.prototype._getStatus = function (operationUrl, callback) { try { result.body = JSON.parse(responseBody); } catch (deserializationError) { - var parseError = new Error(util.format('Error "%s" occurred in deserializing the response body - "%s" -' + - ' when polling for operation status.', deserializationError, responseBody)); + var parseError = new Error(util.format('Error "%s" occurred in deserializing the response body - "%s" -' + + ' when polling for operation status.', deserializationError, responseBody)); parseError.request = msRest.stripRequest(httpRequest); parseError.response = msRest.stripResponse(response); parseError.body = responseBody; diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js index 87a68bf6dfc25..0d7c48fd1df0b 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js @@ -25,39 +25,46 @@ function PollingState(resultOfInitialRequest, retryTimeout) { this.request = resultOfInitialRequest.request; //Parse response.body & assign it as the resource try { - if (resultOfInitialRequest.body && - typeof resultOfInitialRequest.body.valueOf() === 'string' && - resultOfInitialRequest.body.length > 0) { + if (resultOfInitialRequest.body && + typeof resultOfInitialRequest.body.valueOf() === 'string' && + resultOfInitialRequest.body.length > 0) { this.resource = JSON.parse(resultOfInitialRequest.body); } else { this.resource = resultOfInitialRequest.body; - } + } } catch (error) { - var deserializationError = new Error(util.format('Error "%s" occurred in parsing the responseBody ' + + var deserializationError = new Error(util.format('Error "%s" occurred in parsing the responseBody ' + 'while creating the PollingState for Long Running Operation- "%s"', error, resultOfInitialRequest.body)); deserializationError.request = resultOfInitialRequest.request; deserializationError.response = resultOfInitialRequest.response; throw deserializationError; } - - if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { - this.status = this.resource.properties.provisioningState; - } else { - switch (this.response.statusCode) { - case 202: - this.status = LroStates.InProgress; - break; - case 204: - case 201: - case 200: - this.status = LroStates.Succeeded; - break; + switch (this.response.statusCode) { + case 202: + this.status = LroStates.InProgress; + break; - default: - this.status = LroStates.Failed; - break; - } + case 204: + this.status = LroStates.Succeeded; + break; + case 201: + if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { + this.status = this.resource.properties.provisioningState; + } else { + this.status = LroStates.InProgress; + } + break; + case 200: + if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { + this.status = this.resource.properties.provisioningState; + } else { + this.status = LroStates.Succeeded; + } + break; + default: + this.status = LroStates.Failed; + break; } } @@ -65,7 +72,7 @@ function PollingState(resultOfInitialRequest, retryTimeout) { * Gets timeout in milliseconds. * @returns {number} timeout */ -PollingState.prototype.getTimeout = function () { +PollingState.prototype.getTimeout = function() { if (this._retryTimeout || this._retryTimeout === 0) { return this._retryTimeout * 1000; } @@ -79,13 +86,13 @@ PollingState.prototype.getTimeout = function () { * Update cached data using the provided response object * @param {object} [response] - provider response object. */ -PollingState.prototype.updateResponse = function (response) { +PollingState.prototype.updateResponse = function(response) { this.response = response; if (response && response.headers) { if (response.headers['azure-asyncoperation']) { this.azureAsyncOperationHeaderLink = response.headers['azure-asyncoperation']; } - + if (response.headers['location']) { this.locationHeaderLink = response.headers['location']; } @@ -96,7 +103,7 @@ PollingState.prototype.updateResponse = function (response) { * Returns long running operation result. * @returns {object} HttpOperationResponse */ -PollingState.prototype.getOperationResponse = function () { +PollingState.prototype.getOperationResponse = function() { var result = new msRest.HttpOperationResponse(); result.request = this.request; result.response = this.response; @@ -112,7 +119,7 @@ PollingState.prototype.getOperationResponse = function () { * Returns an Error on operation failure. * @returns {object} Error */ -PollingState.prototype.getCloudError = function (err) { +PollingState.prototype.getCloudError = function(err) { var errMsg; var errCode; @@ -126,11 +133,11 @@ PollingState.prototype.getCloudError = function (err) { parsedResponse = JSON.parse(this.response.body); } } catch (err) { - error.message = util.format('Error "%s" occurred while deserializing the error ' + + error.message = util.format('Error "%s" occurred while deserializing the error ' + 'message "%s" for long running operation.', err.message, this.response.body); return error; } - + if (err && err.message) { errMsg = util.format('Long running operation failed with error: \'%s\'.', err.message); } else { From b789377b723611732d63266140f6592fd817d837 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 23 Mar 2016 10:43:45 -0700 Subject: [PATCH 02/12] add test for fixing the post/patch async operation --- .../ms-rest-azure/lib/azureServiceClient.js | 8 +-- .../test/azureServiceClientTests.js | 50 ++++++++++++++++++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index 4b967ca5cd373..4a7ce94cf713a 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -115,7 +115,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfIni self._updateStateFromLocationHeader(pollingState, function(err) { return callback(err); }); - } else if (resultOfInitialRequest.request.method === "PUT") { + } else if (resultOfInitialRequest.request.method === 'PUT') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); @@ -127,7 +127,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfIni //when done function(err) { if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== "DELETE" && resultOfInitialRequest.request.method !== "POST") { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); @@ -201,7 +201,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI self._updateStateFromLocationHeader(pollingState, function(err) { return callback(err); }); - } else if (resultOfInitialRequest.request.method === "PUT") { + } else if (resultOfInitialRequest.request.method === 'PUT') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); @@ -213,7 +213,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI //when done function(err) { if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== "DELETE" && resultOfInitialRequest.request.method !== "POST") { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index e28f44bf5ad68..bab92dc1e627c 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -156,11 +156,56 @@ describe('AzureServiceClient', function () { }); }); + describe('Patch', function () { + resultOfInitialRequest.response.statusCode = 202; + resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + + it('works by polling from azure-asyncoperation header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; + resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + should.not.exist(err); + JSON.parse(result.body).name.should.equal(testResourceName); + should.exist(result.response.randomFieldFromPollLocationHeader); + done(); + }); + }); + + it('works by polling from location header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; + resultOfInitialRequest.response.headers['location'] = ''; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + should.not.exist(err); + JSON.parse(result.body).name.should.equal(testResourceName); + done(); + }); + }); + + it('returns error if failed to poll from the azure-asyncoperation header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; + resultOfInitialRequest.response.headers['location'] = ''; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + err.message.should.containEql(testError); + done(); + }); + }); + + it('returns error if failed to poll from the location header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; + resultOfInitialRequest.response.headers['location'] = url_ReturnError; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + err.message.should.containEql(testError); + done(); + }); + }); + }); + describe('Post-or-Delete', function () { resultOfInitialRequest.response.statusCode = 202; - + resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + it('throw on not Lro related status code', function (done) { - client.getPostOrDeleteOperationResult({ response: { statusCode: 201 } }, function (err, result) { + client.getPostOrDeleteOperationResult({ response: { statusCode: 203 }, request: {url: url_resource}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -169,6 +214,7 @@ describe('AzureServiceClient', function () { it('works by polling from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; + resultOfInitialRequest.request.method = 'POST'; client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollAsyncOpHeader); From 9c7e28b27cdc5b49900ce005b1c4c6a06290264c Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Thu, 24 Mar 2016 10:09:33 -0700 Subject: [PATCH 03/12] code revise --- .../ms-rest-azure/lib/azureServiceClient.js | 83 ++++++++++--------- .../NodeJS/ms-rest-azure/lib/pollingState.js | 26 +++--- .../test/azureServiceClientTests.js | 4 +- 3 files changed, 60 insertions(+), 53 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index 4a7ce94cf713a..dabedd8d3217c 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -32,15 +32,15 @@ function AzureServiceClient(credentials, options) { if (!credentials) { throw new Error('Azure clients require credentials.'); } - + AzureServiceClient['super_'].call(this, credentials, options); - + this.acceptLanguage = 'en-US'; this.generateClientRequestId = true; this.longRunningOperationRetryTimeout = 30; if (!options) options = {}; - + if (options.acceptLanguage !== null && options.acceptLanguage !== undefined) { this.acceptLanguage = options.acceptLanguage; } @@ -62,7 +62,7 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; if (!callback && typeof options === 'function') { @@ -81,12 +81,10 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfIni return callback(new Error('Missing resultOfInitialRequest.response')); } - if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 201 && - resultOfInitialRequest.response.statusCode !== 202 && - resultOfInitialRequest.response.statusCode !== 204) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', - resultOfInitialRequest.response.statusCode))); + if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', + resultOfInitialRequest.response.statusCode, + resultOfInitialRequest.request.method))); } var pollingState = null; @@ -147,7 +145,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfIni * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; if (!callback && typeof options === 'function') { @@ -166,12 +164,10 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI return callback(new Error('Missing resultOfInitialRequest.response')); } - if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 201 && - resultOfInitialRequest.response.statusCode !== 202 && - resultOfInitialRequest.response.statusCode !== 204) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', - resultOfInitialRequest.response.statusCode))); + if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', + resultOfInitialRequest.response.statusCode, + resultOfInitialRequest.request.method))); } var pollingState = null; @@ -180,7 +176,6 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI } catch (error) { callback(error); } - var resourceUrl = resultOfInitialRequest.request.url; this._options = options; @@ -226,19 +221,31 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI }); }; +AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) { + if (initialRequest.response.statusCode === 200 || + initialRequest.response.statusCode === 202 || + (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || + (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { + return false; + } else { + return true; + } +}; + + /** * Retrieve operation status by polling from 'azure-asyncoperation' header. * @param {object} [pollingState] - The object to persist current operation state. * @param {boolean} [inPostOrDelete] - Invoked by Post Or Delete operation. */ -AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = function(pollingState, inPostOrDelete, callback) { - this._getStatus(pollingState.azureAsyncOperationHeaderLink, function(err, result) { +AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = function (pollingState, inPostOrDelete, callback) { + this._getStatus(pollingState.azureAsyncOperationHeaderLink, function (err, result) { if (err) return callback(err); - + if (!result.body || !result.body.status) { return callback(new Error('The response from long running operation does not contain a body.')); } - + pollingState.status = result.body.status; pollingState.error = result.body.error; pollingState.response = result.response; @@ -252,10 +259,10 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio }; /** - * Retrieve PUT/POST/PATCH/DELETE operation status by polling from 'location' header. + * Retrieve PUT operation status by polling from 'location' header. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromLocationHeader = function(pollingState, callback) { +AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) { this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); @@ -286,29 +293,29 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function(pollingSt * @param {function} [resourceUrl] - The url of resource. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromGetResourceOperation = function(resourceUrl, pollingState, callback) { - this._getStatus(resourceUrl, function(err, result) { +AzureServiceClient.prototype._updateStateFromGetResourceOperation = function (resourceUrl, pollingState, callback) { + this._getStatus(resourceUrl, function (err, result) { if (err) return callback(err); if (!result.body) { return callback(new Error('The response from long running operation does not contain a body.')); } - + if (result.body.properties && result.body.properties.provisioningState) { pollingState.status = result.body.properties.provisioningState; } else { pollingState.status = LroStates.Succeeded; } - + //we might not throw an error, but initialize here just in case. pollingState.error = { code: pollingState.status, message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) }; - + pollingState.updateResponse(result.response); pollingState.request = result.request; pollingState.resource = result.body; - + //nothing to return, the 'pollingState' has all the info we care. callback(null); }); @@ -318,21 +325,21 @@ AzureServiceClient.prototype._updateStateFromGetResourceOperation = function(res * Retrieve operation status by querying the operation URL. * @param {string} [operationUrl] - URL used to poll operation result. */ -AzureServiceClient.prototype._getStatus = function(operationUrl, callback) { +AzureServiceClient.prototype._getStatus = function (operationUrl, callback) { var self = this; if (!operationUrl) { return callback(new Error('operationUrl cannot be null.')); } - + // Construct URL var requestUrl = operationUrl.replace(' ', '%20'); - + // Create HTTP transport objects var httpRequest = new WebResource(); httpRequest.method = 'GET'; httpRequest.headers = {}; httpRequest.url = requestUrl; - if (this._options) { + if(this._options) { for (var headerName in this._options['customHeaders']) { if (this._options['customHeaders'].hasOwnProperty(headerName)) { httpRequest.headers[headerName] = this._options['customHeaders'][headerName]; @@ -340,13 +347,13 @@ AzureServiceClient.prototype._getStatus = function(operationUrl, callback) { } } // Send Request - return self.pipeline(httpRequest, function(err, response, responseBody) { + return self.pipeline(httpRequest, function (err, response, responseBody) { if (err) { return callback(err); } var statusCode = response.statusCode; if (statusCode !== 200 && statusCode !== 201 && statusCode !== 202 && statusCode !== 204) { - var error = new Error(util.format('Invalid status code with response body "%s" occurred ' + + var error = new Error(util.format('Invalid status code with response body "%s" occurred ' + 'when polling for operation status.', responseBody)); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -371,8 +378,8 @@ AzureServiceClient.prototype._getStatus = function(operationUrl, callback) { try { result.body = JSON.parse(responseBody); } catch (deserializationError) { - var parseError = new Error(util.format('Error "%s" occurred in deserializing the response body - "%s" -' + - ' when polling for operation status.', deserializationError, responseBody)); + var parseError = new Error(util.format('Error "%s" occurred in deserializing the response body - "%s" -' + + ' when polling for operation status.', deserializationError, responseBody)); parseError.request = msRest.stripRequest(httpRequest); parseError.response = msRest.stripResponse(response); parseError.body = responseBody; diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js index 0d7c48fd1df0b..114eedf25c573 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js @@ -25,21 +25,21 @@ function PollingState(resultOfInitialRequest, retryTimeout) { this.request = resultOfInitialRequest.request; //Parse response.body & assign it as the resource try { - if (resultOfInitialRequest.body && - typeof resultOfInitialRequest.body.valueOf() === 'string' && - resultOfInitialRequest.body.length > 0) { + if (resultOfInitialRequest.body && + typeof resultOfInitialRequest.body.valueOf() === 'string' && + resultOfInitialRequest.body.length > 0) { this.resource = JSON.parse(resultOfInitialRequest.body); } else { this.resource = resultOfInitialRequest.body; - } + } } catch (error) { - var deserializationError = new Error(util.format('Error "%s" occurred in parsing the responseBody ' + + var deserializationError = new Error(util.format('Error "%s" occurred in parsing the responseBody ' + 'while creating the PollingState for Long Running Operation- "%s"', error, resultOfInitialRequest.body)); deserializationError.request = resultOfInitialRequest.request; deserializationError.response = resultOfInitialRequest.response; throw deserializationError; } - + switch (this.response.statusCode) { case 202: this.status = LroStates.InProgress; @@ -72,7 +72,7 @@ function PollingState(resultOfInitialRequest, retryTimeout) { * Gets timeout in milliseconds. * @returns {number} timeout */ -PollingState.prototype.getTimeout = function() { +PollingState.prototype.getTimeout = function () { if (this._retryTimeout || this._retryTimeout === 0) { return this._retryTimeout * 1000; } @@ -86,13 +86,13 @@ PollingState.prototype.getTimeout = function() { * Update cached data using the provided response object * @param {object} [response] - provider response object. */ -PollingState.prototype.updateResponse = function(response) { +PollingState.prototype.updateResponse = function (response) { this.response = response; if (response && response.headers) { if (response.headers['azure-asyncoperation']) { this.azureAsyncOperationHeaderLink = response.headers['azure-asyncoperation']; } - + if (response.headers['location']) { this.locationHeaderLink = response.headers['location']; } @@ -103,7 +103,7 @@ PollingState.prototype.updateResponse = function(response) { * Returns long running operation result. * @returns {object} HttpOperationResponse */ -PollingState.prototype.getOperationResponse = function() { +PollingState.prototype.getOperationResponse = function () { var result = new msRest.HttpOperationResponse(); result.request = this.request; result.response = this.response; @@ -119,7 +119,7 @@ PollingState.prototype.getOperationResponse = function() { * Returns an Error on operation failure. * @returns {object} Error */ -PollingState.prototype.getCloudError = function(err) { +PollingState.prototype.getCloudError = function (err) { var errMsg; var errCode; @@ -133,11 +133,11 @@ PollingState.prototype.getCloudError = function(err) { parsedResponse = JSON.parse(this.response.body); } } catch (err) { - error.message = util.format('Error "%s" occurred while deserializing the error ' + + error.message = util.format('Error "%s" occurred while deserializing the error ' + 'message "%s" for long running operation.', err.message, this.response.body); return error; } - + if (err && err.message) { errMsg = util.format('Long running operation failed with error: \'%s\'.', err.message); } else { diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index bab92dc1e627c..f358540bb6aae 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -92,7 +92,7 @@ describe('AzureServiceClient', function () { describe('Put', function () { resultOfInitialRequest.response.statusCode = 201; - + it('throw on not Lro related status code', function (done) { client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); @@ -205,7 +205,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; it('throw on not Lro related status code', function (done) { - client.getPostOrDeleteOperationResult({ response: { statusCode: 203 }, request: {url: url_resource}}, function (err, result) { + client.getPostOrDeleteOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); From 6e478d4e7c98b1a625715aeebf6809116e297110 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Tue, 22 Mar 2016 16:47:05 -0700 Subject: [PATCH 04/12] fix async patch and post run --- .../ms-rest-azure/lib/azureServiceClient.js | 168 ++++++++---------- .../NodeJS/ms-rest-azure/lib/pollingState.js | 39 ++-- .../test/azureServiceClientTests.js | 52 +++++- 3 files changed, 151 insertions(+), 108 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index ae1798dc5e56a..dabedd8d3217c 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -65,65 +65,68 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; - if(!callback && typeof options === 'function') { + if (!callback && typeof options === 'function') { callback = options; options = null; } if (!callback) { throw new Error('Missing callback'); } - + if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - - if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 201 && - resultOfInitialRequest.response.statusCode !== 202) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', - resultOfInitialRequest.response.statusCode))); + + if (!resultOfInitialRequest.response) { + return callback(new Error('Missing resultOfInitialRequest.response')); + } + + if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', + resultOfInitialRequest.response.statusCode, + resultOfInitialRequest.request.method))); } + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } - var resourceUrl = resultOfInitialRequest.request.url; this._options = options; - + async.whilst( - //while condition - function () { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function (e) { - return pollingState.status === e; + function() { + var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { + return e === pollingState.status; }); return !finished; }, - //while loop body - function (callback) { - setTimeout(function () { + function(callback) { + setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, false, function (err) { + self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeaderOnPut(pollingState, function (err) { + self._updateStateFromLocationHeader(pollingState, function(err) { return callback(err); }); - } else { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function (err) { + } else if (resultOfInitialRequest.request.method === 'PUT') { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); + } else { + return callback(new Error('Location header is missing from long running operation.')); } }, pollingState.getTimeout()); }, //when done - function (err) { + function(err) { if (pollingState.status === LroStates.Succeeded) { - if (!pollingState.resource) { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function (err) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); } else { @@ -144,7 +147,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn */ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; - + if (!callback && typeof options === 'function') { callback = options; options = null; @@ -152,45 +155,49 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf if (!callback) { throw new Error('Missing callback'); } - + if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - + if (!resultOfInitialRequest.response) { return callback(new Error('Missing resultOfInitialRequest.response')); } - - if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 202 && - resultOfInitialRequest.response.statusCode !== 204) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', - resultOfInitialRequest.response.statusCode))); + + if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', + resultOfInitialRequest.response.statusCode, + resultOfInitialRequest.request.method))); } - + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } + var resourceUrl = resultOfInitialRequest.request.url; this._options = options; async.whilst( - function () { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function (e) { + function() { + var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { return e === pollingState.status; }); return !finished; }, - function (callback) { - setTimeout(function () { + function(callback) { + setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function (err) { + self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeaderOnPostOrDelete(pollingState, function (err) { + self._updateStateFromLocationHeader(pollingState, function(err) { + return callback(err); + }); + } else if (resultOfInitialRequest.request.method === 'PUT') { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); } else { @@ -198,15 +205,34 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf } }, pollingState.getTimeout()); }, - function (err) { - if (pollingState.status === LroStates.Succeeded ) { - return callback(null, pollingState.getOperationResponse()); + //when done + function(err) { + if (pollingState.status === LroStates.Succeeded) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { + return callback(err, pollingState.getOperationResponse()); + }); + } else { + return callback(null, pollingState.getOperationResponse()); + } } else { return callback(pollingState.getCloudError(err)); } }); }; +AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) { + if (initialRequest.response.statusCode === 200 || + initialRequest.response.statusCode === 202 || + (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || + (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { + return false; + } else { + return true; + } +}; + + /** * Retrieve operation status by polling from 'azure-asyncoperation' header. * @param {object} [pollingState] - The object to persist current operation state. @@ -236,33 +262,22 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio * Retrieve PUT operation status by polling from 'location' header. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromLocationHeaderOnPut = function (pollingState, callback) { - this._getStatus(pollingState.locationHeaderLink, function (err, result) { +AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) { + this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); - + pollingState.updateResponse(result.response); pollingState.request = result.request; - + var statusCode = result.response.statusCode; if (statusCode === 202) { pollingState.status = LroStates.InProgress; - } - else if (statusCode === 200 || - statusCode === 201) { - - if (!result.body) { - return callback(new Error('The response from long running operation does not contain a body.')); - } - - // In 202 pattern on PUT ProvisioningState may not be present in - // the response. In that case the assumption is the status is Succeeded. - if (result.body.properties && result.body.properties.provisioningState) { - pollingState.status = result.body.properties.provisioningState; - } - else { - pollingState.status = LroStates.Succeeded; - } - + } else if (statusCode === 200 || + statusCode === 201 || + statusCode === 204) { + + pollingState.status = LroStates.Succeeded; + pollingState.error = { code: pollingState.Status, message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) @@ -273,31 +288,6 @@ AzureServiceClient.prototype._updateStateFromLocationHeaderOnPut = function (pol }); }; -/** - * Retrieve POST or DELETE operation status by polling from 'location' header. - * @param {object} [pollingState] - The object to persist current operation state. - */ -AzureServiceClient.prototype._updateStateFromLocationHeaderOnPostOrDelete = function (pollingState, callback) { - this._getStatus(pollingState.locationHeaderLink, function (err, result) { - if (err) return callback(err); - - pollingState.updateResponse(result.response); - pollingState.request = result.request; - - var statusCode = result.response.statusCode; - if (statusCode === 202) { - pollingState.status = LroStates.InProgress; - } - else if (statusCode === 200 || - statusCode === 201 || - statusCode === 204) { - pollingState.status = LroStates.Succeeded; - pollingState.resource = result.body; - } - callback(null); - }); -}; - /** * Polling for resource status. * @param {function} [resourceUrl] - The url of resource. diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js index 87a68bf6dfc25..114eedf25c573 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js @@ -40,24 +40,31 @@ function PollingState(resultOfInitialRequest, retryTimeout) { throw deserializationError; } - if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { - this.status = this.resource.properties.provisioningState; - } else { - switch (this.response.statusCode) { - case 202: - this.status = LroStates.InProgress; - break; + switch (this.response.statusCode) { + case 202: + this.status = LroStates.InProgress; + break; - case 204: - case 201: - case 200: + case 204: + this.status = LroStates.Succeeded; + break; + case 201: + if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { + this.status = this.resource.properties.provisioningState; + } else { + this.status = LroStates.InProgress; + } + break; + case 200: + if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { + this.status = this.resource.properties.provisioningState; + } else { this.status = LroStates.Succeeded; - break; - - default: - this.status = LroStates.Failed; - break; - } + } + break; + default: + this.status = LroStates.Failed; + break; } } diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index e28f44bf5ad68..f358540bb6aae 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -92,7 +92,7 @@ describe('AzureServiceClient', function () { describe('Put', function () { resultOfInitialRequest.response.statusCode = 201; - + it('throw on not Lro related status code', function (done) { client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); @@ -156,11 +156,56 @@ describe('AzureServiceClient', function () { }); }); + describe('Patch', function () { + resultOfInitialRequest.response.statusCode = 202; + resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + + it('works by polling from azure-asyncoperation header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; + resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + should.not.exist(err); + JSON.parse(result.body).name.should.equal(testResourceName); + should.exist(result.response.randomFieldFromPollLocationHeader); + done(); + }); + }); + + it('works by polling from location header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; + resultOfInitialRequest.response.headers['location'] = ''; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + should.not.exist(err); + JSON.parse(result.body).name.should.equal(testResourceName); + done(); + }); + }); + + it('returns error if failed to poll from the azure-asyncoperation header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; + resultOfInitialRequest.response.headers['location'] = ''; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + err.message.should.containEql(testError); + done(); + }); + }); + + it('returns error if failed to poll from the location header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; + resultOfInitialRequest.response.headers['location'] = url_ReturnError; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + err.message.should.containEql(testError); + done(); + }); + }); + }); + describe('Post-or-Delete', function () { resultOfInitialRequest.response.statusCode = 202; - + resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + it('throw on not Lro related status code', function (done) { - client.getPostOrDeleteOperationResult({ response: { statusCode: 201 } }, function (err, result) { + client.getPostOrDeleteOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -169,6 +214,7 @@ describe('AzureServiceClient', function () { it('works by polling from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; + resultOfInitialRequest.request.method = 'POST'; client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollAsyncOpHeader); From 4ab8892519dfbb10ce902be4471ea9f45ca83ef4 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Thu, 24 Mar 2016 10:21:36 -0700 Subject: [PATCH 05/12] style change --- .../ms-rest-azure/lib/azureServiceClient.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index dabedd8d3217c..fa2e530176f81 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -65,7 +65,7 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; - if (!callback && typeof options === 'function') { + if(!callback && typeof options === 'function') { callback = options; options = null; } @@ -86,13 +86,14 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn resultOfInitialRequest.response.statusCode, resultOfInitialRequest.request.method))); } - + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } + var resourceUrl = resultOfInitialRequest.request.url; this._options = options; @@ -123,7 +124,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn }, pollingState.getTimeout()); }, //when done - function(err) { + function (err) { if (pollingState.status === LroStates.Succeeded) { if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { @@ -147,7 +148,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn */ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; - + if (!callback && typeof options === 'function') { callback = options; options = null; @@ -159,7 +160,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - + if (!resultOfInitialRequest.response) { return callback(new Error('Missing resultOfInitialRequest.response')); } @@ -169,7 +170,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf resultOfInitialRequest.response.statusCode, resultOfInitialRequest.request.method))); } - + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); @@ -186,7 +187,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf }); return !finished; }, - function(callback) { + function (callback) { setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { @@ -206,7 +207,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf }, pollingState.getTimeout()); }, //when done - function(err) { + function (err) { if (pollingState.status === LroStates.Succeeded) { if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { @@ -265,10 +266,10 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) { this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); - + pollingState.updateResponse(result.response); pollingState.request = result.request; - + var statusCode = result.response.statusCode; if (statusCode === 202) { pollingState.status = LroStates.InProgress; From 39b4b190dfe0098bdb93c3075b93b651ba554d7d Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 6 Apr 2016 15:54:30 -0700 Subject: [PATCH 06/12] code revise --- .../NodeJS/ms-rest-azure/lib/azureServiceClient.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index fa2e530176f81..5d462e43b35c8 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -229,7 +229,7 @@ AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = func (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { return false; } else { - return true; + return true; } }; @@ -274,8 +274,8 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS if (statusCode === 202) { pollingState.status = LroStates.InProgress; } else if (statusCode === 200 || - statusCode === 201 || - statusCode === 204) { + (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || + (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { pollingState.status = LroStates.Succeeded; From d1ff9419ecaa9313a8bc33c20ff7b7cd03b9846e Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 6 Apr 2016 15:57:47 -0700 Subject: [PATCH 07/12] fix the naming issue in azure serviceClientTest --- .../NodeJS/ms-rest-azure/test/azureServiceClientTests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index f358540bb6aae..98c1e78c2d474 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -160,7 +160,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.statusCode = 202; resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; - it('works by polling from azure-asyncoperation header', function (done) { + it('works by polling from location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { @@ -171,7 +171,7 @@ describe('AzureServiceClient', function () { }); }); - it('works by polling from location header', function (done) { + it('works by polling from azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { From 9573dee1b9fe3d1cbf7c8dc03b7c4957048691e0 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 6 Apr 2016 16:16:25 -0700 Subject: [PATCH 08/12] code revise --- ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index 5d462e43b35c8..c81827aa1906b 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -274,8 +274,8 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS if (statusCode === 202) { pollingState.status = LroStates.InProgress; } else if (statusCode === 200 || - (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || - (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { + (statusCode === 201 && pollingState.request.method === 'PUT') || + (statusCode === 204 && pollingState.request.method === 'DELETE')) { pollingState.status = LroStates.Succeeded; From b9d642d3a779a9fe980717263ce357b1b4de2fbc Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 6 Apr 2016 17:37:27 -0700 Subject: [PATCH 09/12] add 204 poll state for post --- .../ms-rest-azure/lib/azureServiceClient.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index c81827aa1906b..7e07c3aea86a5 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -111,7 +111,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeader(pollingState, function(err) { + self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) { return callback(err); }); } else if (resultOfInitialRequest.request.method === 'PUT') { @@ -194,7 +194,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeader(pollingState, function(err) { + self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) { return callback(err); }); } else if (resultOfInitialRequest.request.method === 'PUT') { @@ -223,10 +223,11 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf }; AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) { - if (initialRequest.response.statusCode === 200 || - initialRequest.response.statusCode === 202 || - (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || - (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { + var statusCode = initialRequest.response.statusCode; + var method = initialRequest.request.method; + if (statusCode === 200 || statusCode === 202 || + (statusCode === 201 && method === 'PUT') || + (statusCode === 204 && (method === 'DELETE' || method === 'POST'))) { return false; } else { return true; @@ -263,7 +264,7 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio * Retrieve PUT operation status by polling from 'location' header. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) { +AzureServiceClient.prototype._updateStateFromLocationHeader = function (method, pollingState, callback) { this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); @@ -274,8 +275,8 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS if (statusCode === 202) { pollingState.status = LroStates.InProgress; } else if (statusCode === 200 || - (statusCode === 201 && pollingState.request.method === 'PUT') || - (statusCode === 204 && pollingState.request.method === 'DELETE')) { + (statusCode === 201 && method === 'PUT') || + (statusCode === 204 && (method === 'DELETE' || method === 'POST'))) { pollingState.status = LroStates.Succeeded; @@ -284,7 +285,9 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) }; pollingState.resource = result.body; - } + } else { + return callback(new Error('The response from long running operation does not have a valid status code.')); + } callback(null); }); }; From 5b4ca29a393a30f1f452436996d952e0aa868c3a Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Thu, 7 Apr 2016 14:13:09 -0700 Subject: [PATCH 10/12] change code gen in node js to merge LRO operations into one method --- .../Lro/operations/lRORetrys.js | 14 +-- .../AcceptanceTests/Lro/operations/lROSADs.js | 50 +++++------ .../AcceptanceTests/Lro/operations/lROs.js | 72 +++++++-------- .../Lro/operations/lROsCustomHeader.js | 8 +- .../AzureMethodTemplateModel.cs | 9 +- .../ms-rest-azure/lib/azureServiceClient.js | 88 +------------------ .../test/azureServiceClientTests.js | 36 ++++---- 7 files changed, 93 insertions(+), 184 deletions(-) diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js index f3cb1fecfb34b..bacca9fd614ab 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js @@ -81,7 +81,7 @@ LRORetrys.prototype.put201CreatingSucceeded200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -334,7 +334,7 @@ LRORetrys.prototype.putAsyncRelativeRetrySucceeded = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -562,7 +562,7 @@ LRORetrys.prototype.deleteProvisioning202Accepted200Succeeded = function (option initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -782,7 +782,7 @@ LRORetrys.prototype.delete202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -952,7 +952,7 @@ LRORetrys.prototype.deleteAsyncRelativeRetrySucceeded = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1130,7 +1130,7 @@ LRORetrys.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1332,7 +1332,7 @@ LRORetrys.prototype.postAsyncRelativeRetrySucceeded = function (options, callbac initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js index 33fff6078369c..850509ad638ea 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js @@ -78,7 +78,7 @@ LROSADs.prototype.putNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -326,7 +326,7 @@ LROSADs.prototype.putNonRetry201Creating400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -576,7 +576,7 @@ LROSADs.prototype.putAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -799,7 +799,7 @@ LROSADs.prototype.deleteNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -965,7 +965,7 @@ LROSADs.prototype.delete202NonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1133,7 +1133,7 @@ LROSADs.prototype.deleteAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1309,7 +1309,7 @@ LROSADs.prototype.postNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1506,7 +1506,7 @@ LROSADs.prototype.post202NonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1705,7 +1705,7 @@ LROSADs.prototype.postAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1906,7 +1906,7 @@ LROSADs.prototype.putError201NoProvisioningStatePayload = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2156,7 +2156,7 @@ LROSADs.prototype.putAsyncRelativeRetryNoStatus = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2390,7 +2390,7 @@ LROSADs.prototype.putAsyncRelativeRetryNoStatusPayload = function (options, call initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2614,7 +2614,7 @@ LROSADs.prototype.delete204Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2783,7 +2783,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryNoStatus = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2960,7 +2960,7 @@ LROSADs.prototype.post202NoLocation = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3160,7 +3160,7 @@ LROSADs.prototype.postAsyncRelativeRetryNoPayload = function (options, callback) initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3361,7 +3361,7 @@ LROSADs.prototype.put200InvalidJson = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3594,7 +3594,7 @@ LROSADs.prototype.putAsyncRelativeRetryInvalidHeader = function (options, callba initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3828,7 +3828,7 @@ LROSADs.prototype.putAsyncRelativeRetryInvalidJsonPolling = function (options, c initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4052,7 +4052,7 @@ LROSADs.prototype.delete202RetryInvalidHeader = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4220,7 +4220,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryInvalidHeader = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4389,7 +4389,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryInvalidJsonPolling = function (options initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4566,7 +4566,7 @@ LROSADs.prototype.post202RetryInvalidHeader = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4766,7 +4766,7 @@ LROSADs.prototype.postAsyncRelativeRetryInvalidHeader = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4967,7 +4967,7 @@ LROSADs.prototype.postAsyncRelativeRetryInvalidJsonPolling = function (options, initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js index b0cc6a272fd58..f403121e6dfec 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js @@ -79,7 +79,7 @@ LROs.prototype.put200Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -311,7 +311,7 @@ LROs.prototype.put200SucceededNoState = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -544,7 +544,7 @@ LROs.prototype.put202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -779,7 +779,7 @@ LROs.prototype.put201CreatingSucceeded200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1032,7 +1032,7 @@ LROs.prototype.put200UpdatingSucceeded204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1268,7 +1268,7 @@ LROs.prototype.put201CreatingFailed200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1521,7 +1521,7 @@ LROs.prototype.put200Acceptedcanceled200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1756,7 +1756,7 @@ LROs.prototype.putNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1990,7 +1990,7 @@ LROs.prototype.putAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2224,7 +2224,7 @@ LROs.prototype.putAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2458,7 +2458,7 @@ LROs.prototype.putAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2692,7 +2692,7 @@ LROs.prototype.putAsyncNoRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2926,7 +2926,7 @@ LROs.prototype.putAsyncNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3156,7 +3156,7 @@ LROs.prototype.putNonResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3382,7 +3382,7 @@ LROs.prototype.putAsyncNonResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3606,7 +3606,7 @@ LROs.prototype.putSubResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3828,7 +3828,7 @@ LROs.prototype.putAsyncSubResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4049,7 +4049,7 @@ LROs.prototype.deleteProvisioning202Accepted200Succeeded = function (options, ca initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4271,7 +4271,7 @@ LROs.prototype.deleteProvisioning202DeletingFailed200 = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4493,7 +4493,7 @@ LROs.prototype.deleteProvisioning202Deletingcanceled200 = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4711,7 +4711,7 @@ LROs.prototype.delete204Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4880,7 +4880,7 @@ LROs.prototype.delete202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5083,7 +5083,7 @@ LROs.prototype.delete202NoRetry204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5285,7 +5285,7 @@ LROs.prototype.deleteNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5455,7 +5455,7 @@ LROs.prototype.deleteAsyncNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5625,7 +5625,7 @@ LROs.prototype.deleteAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5795,7 +5795,7 @@ LROs.prototype.deleteAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5965,7 +5965,7 @@ LROs.prototype.deleteAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6135,7 +6135,7 @@ LROs.prototype.deleteAsyncRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6306,7 +6306,7 @@ LROs.prototype.post200WithPayload = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6533,7 +6533,7 @@ LROs.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6734,7 +6734,7 @@ LROs.prototype.post202NoRetry204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6967,7 +6967,7 @@ LROs.prototype.postAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7201,7 +7201,7 @@ LROs.prototype.postAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7434,7 +7434,7 @@ LROs.prototype.postAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7635,7 +7635,7 @@ LROs.prototype.postAsyncRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js index 9dc6656111ba1..3d4d296e68aaa 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js @@ -82,7 +82,7 @@ LROsCustomHeader.prototype.putAsyncRetrySucceeded = function (options, callback) initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -320,7 +320,7 @@ LROsCustomHeader.prototype.put201CreatingSucceeded200 = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -573,7 +573,7 @@ LROsCustomHeader.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -777,7 +777,7 @@ LROsCustomHeader.prototype.postAsyncRetrySucceeded = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS/TemplateModels/AzureMethodTemplateModel.cs b/AutoRest/Generators/NodeJS/Azure.NodeJS/TemplateModels/AzureMethodTemplateModel.cs index 95a519d366c9d..a6fbcc9e356e9 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS/TemplateModels/AzureMethodTemplateModel.cs +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS/TemplateModels/AzureMethodTemplateModel.cs @@ -86,14 +86,7 @@ public string LongRunningOperationMethodNameInRuntime string result = null; if (this.IsLongRunningOperation) { - if (HttpMethod == HttpMethod.Post || HttpMethod == HttpMethod.Delete) - { - result = "getPostOrDeleteOperationResult"; - } - else if (HttpMethod == HttpMethod.Put || HttpMethod == HttpMethod.Patch) - { - result = "getPutOrPatchOperationResult"; - } + result = "getLongRunningOperationResult"; } return result; } diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index 7e07c3aea86a5..e0207511c4c34 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -57,96 +57,12 @@ function AzureServiceClient(credentials, options) { util.inherits(AzureServiceClient, msRest.ServiceClient); /** - * Poll Azure long running PUT operation. - * @param {object} [resultOfInitialRequest] - Response of the initial request for the long running operation. - * @param {object} [options] - * @param {object} [options.customHeaders] headers that will be added to request - */ -AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { - var self = this; - - if(!callback && typeof options === 'function') { - callback = options; - options = null; - } - if (!callback) { - throw new Error('Missing callback'); - } - - if (!resultOfInitialRequest) { - return callback(new Error('Missing resultOfInitialRequest parameter')); - } - - if (!resultOfInitialRequest.response) { - return callback(new Error('Missing resultOfInitialRequest.response')); - } - - if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', - resultOfInitialRequest.response.statusCode, - resultOfInitialRequest.request.method))); - } - - var pollingState = null; - try { - pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); - } catch (error) { - callback(error); - } - - var resourceUrl = resultOfInitialRequest.request.url; - this._options = options; - - async.whilst( - function() { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { - return e === pollingState.status; - }); - return !finished; - }, - function(callback) { - setTimeout(function() { - if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { - return callback(err); - }); - } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) { - return callback(err); - }); - } else if (resultOfInitialRequest.request.method === 'PUT') { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { - return callback(err); - }); - } else { - return callback(new Error('Location header is missing from long running operation.')); - } - }, pollingState.getTimeout()); - }, - //when done - function (err) { - if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { - return callback(err, pollingState.getOperationResponse()); - }); - } else { - return callback(null, pollingState.getOperationResponse()); - } - } else { - return callback(pollingState.getCloudError(err)); - } - }); -}; - - -/** - * Poll Azure long running POST or DELETE operations. + * Poll Azure long running GET, PATCH, POST or DELETE operations. * @param {object} [resultOfInitialRequest] - result of the initial request. * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; if (!callback && typeof options === 'function') { diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index 98c1e78c2d474..3a56e378e4d9c 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -94,7 +94,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.statusCode = 201; it('throw on not Lro related status code', function (done) { - client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { + client.getLongRunningOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -103,7 +103,7 @@ describe('AzureServiceClient', function () { it('works by polling from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); done(); @@ -118,7 +118,7 @@ describe('AzureServiceClient', function () { 'testCustomField': testCustomFieldValue } }; - client.getPutOrPatchOperationResult(resultOfInitialRequest, options, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, options, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); result.response.testCustomField.should.equal(testCustomFieldValue); @@ -129,7 +129,7 @@ describe('AzureServiceClient', function () { it('works by polling from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); should.exist(result.response.randomFieldFromPollLocationHeader); @@ -140,7 +140,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -149,7 +149,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -163,7 +163,7 @@ describe('AzureServiceClient', function () { it('works by polling from location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); should.exist(result.response.randomFieldFromPollLocationHeader); @@ -174,7 +174,7 @@ describe('AzureServiceClient', function () { it('works by polling from azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); done(); @@ -184,7 +184,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -193,7 +193,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -205,7 +205,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; it('throw on not Lro related status code', function (done) { - client.getPostOrDeleteOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { + client.getLongRunningOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -215,7 +215,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; resultOfInitialRequest.request.method = 'POST'; - client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollAsyncOpHeader); done(); @@ -225,7 +225,7 @@ describe('AzureServiceClient', function () { it('works by polling from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollLocationHeader); JSON.parse(result.body).name.should.equal(testResourceName); @@ -236,7 +236,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -245,7 +245,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -265,7 +265,7 @@ describe('AzureServiceClient', function () { negativeClient.addFilter(mockFilter({ statusCode: 200, body: badResponseBody }, badResponseBody)); resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - negativeClient.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + negativeClient.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.exist(err); should.exist(err.response); should.exist(err.message); @@ -280,7 +280,7 @@ describe('AzureServiceClient', function () { negativeClient.addFilter(mockFilter({ statusCode: 200, body: badResponseBody }, badResponseBody)); resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - negativeClient.getPutOrPatchOperationResult(resultOfInitialRequest, negativeClient._getStatus, function (err, result) { + negativeClient.getLongRunningOperationResult(resultOfInitialRequest, negativeClient._getStatus, function (err, result) { should.exist(err); should.exist(err.response); should.exist(err.message); @@ -295,7 +295,7 @@ describe('AzureServiceClient', function () { negativeClient.addFilter(mockFilter({ statusCode: 203, body: badResponseBody }, badResponseBody)); resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - negativeClient.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + negativeClient.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.exist(err); should.exist(err.response); should.exist(err.message); From 2f7d3e4680f2688e3fa237b72b1e50db0e53593a Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Tue, 26 Apr 2016 17:42:57 -0700 Subject: [PATCH 11/12] Deprecate two old functions --- .../Lro/operations/lRORetrys.js | 16 ++-- .../AcceptanceTests/Lro/operations/lROSADs.js | 52 ++++++------- .../AcceptanceTests/Lro/operations/lROs.js | 74 +++++++++---------- .../Lro/operations/lROsCustomHeader.js | 10 +-- .../ms-rest-azure/lib/azureServiceClient.js | 46 ++++++++++-- .../test/azureServiceClientTests.js | 22 +++--- 6 files changed, 126 insertions(+), 94 deletions(-) diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js index bacca9fd614ab..91416004b938f 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js @@ -81,7 +81,7 @@ LRORetrys.prototype.put201CreatingSucceeded200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -334,7 +334,7 @@ LRORetrys.prototype.putAsyncRelativeRetrySucceeded = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -562,7 +562,7 @@ LRORetrys.prototype.deleteProvisioning202Accepted200Succeeded = function (option initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -782,7 +782,7 @@ LRORetrys.prototype.delete202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -952,7 +952,7 @@ LRORetrys.prototype.deleteAsyncRelativeRetrySucceeded = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1130,7 +1130,7 @@ LRORetrys.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1332,7 +1332,7 @@ LRORetrys.prototype.postAsyncRelativeRetrySucceeded = function (options, callbac initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1485,4 +1485,4 @@ LRORetrys.prototype.beginPostAsyncRelativeRetrySucceeded = function (options, ca }; -module.exports = LRORetrys; +module.exports = LRORetrys; \ No newline at end of file diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js index 850509ad638ea..44a7ef1d9e6fc 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js @@ -78,7 +78,7 @@ LROSADs.prototype.putNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -326,7 +326,7 @@ LROSADs.prototype.putNonRetry201Creating400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -576,7 +576,7 @@ LROSADs.prototype.putAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -799,7 +799,7 @@ LROSADs.prototype.deleteNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -965,7 +965,7 @@ LROSADs.prototype.delete202NonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1133,7 +1133,7 @@ LROSADs.prototype.deleteAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1309,7 +1309,7 @@ LROSADs.prototype.postNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1506,7 +1506,7 @@ LROSADs.prototype.post202NonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1705,7 +1705,7 @@ LROSADs.prototype.postAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1906,7 +1906,7 @@ LROSADs.prototype.putError201NoProvisioningStatePayload = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2156,7 +2156,7 @@ LROSADs.prototype.putAsyncRelativeRetryNoStatus = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2390,7 +2390,7 @@ LROSADs.prototype.putAsyncRelativeRetryNoStatusPayload = function (options, call initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2614,7 +2614,7 @@ LROSADs.prototype.delete204Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2783,7 +2783,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryNoStatus = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2960,7 +2960,7 @@ LROSADs.prototype.post202NoLocation = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3160,7 +3160,7 @@ LROSADs.prototype.postAsyncRelativeRetryNoPayload = function (options, callback) initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3361,7 +3361,7 @@ LROSADs.prototype.put200InvalidJson = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3594,7 +3594,7 @@ LROSADs.prototype.putAsyncRelativeRetryInvalidHeader = function (options, callba initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3828,7 +3828,7 @@ LROSADs.prototype.putAsyncRelativeRetryInvalidJsonPolling = function (options, c initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4052,7 +4052,7 @@ LROSADs.prototype.delete202RetryInvalidHeader = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4220,7 +4220,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryInvalidHeader = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4389,7 +4389,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryInvalidJsonPolling = function (options initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4566,7 +4566,7 @@ LROSADs.prototype.post202RetryInvalidHeader = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4766,7 +4766,7 @@ LROSADs.prototype.postAsyncRelativeRetryInvalidHeader = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4967,7 +4967,7 @@ LROSADs.prototype.postAsyncRelativeRetryInvalidJsonPolling = function (options, initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5119,4 +5119,4 @@ LROSADs.prototype.beginPostAsyncRelativeRetryInvalidJsonPolling = function (opti }; -module.exports = LROSADs; +module.exports = LROSADs; \ No newline at end of file diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js index f403121e6dfec..7655fc4191aa2 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js @@ -79,7 +79,7 @@ LROs.prototype.put200Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -311,7 +311,7 @@ LROs.prototype.put200SucceededNoState = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -544,7 +544,7 @@ LROs.prototype.put202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -779,7 +779,7 @@ LROs.prototype.put201CreatingSucceeded200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1032,7 +1032,7 @@ LROs.prototype.put200UpdatingSucceeded204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1268,7 +1268,7 @@ LROs.prototype.put201CreatingFailed200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1521,7 +1521,7 @@ LROs.prototype.put200Acceptedcanceled200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1756,7 +1756,7 @@ LROs.prototype.putNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1990,7 +1990,7 @@ LROs.prototype.putAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2224,7 +2224,7 @@ LROs.prototype.putAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2458,7 +2458,7 @@ LROs.prototype.putAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2692,7 +2692,7 @@ LROs.prototype.putAsyncNoRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2926,7 +2926,7 @@ LROs.prototype.putAsyncNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3156,7 +3156,7 @@ LROs.prototype.putNonResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3382,7 +3382,7 @@ LROs.prototype.putAsyncNonResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3606,7 +3606,7 @@ LROs.prototype.putSubResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3828,7 +3828,7 @@ LROs.prototype.putAsyncSubResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4049,7 +4049,7 @@ LROs.prototype.deleteProvisioning202Accepted200Succeeded = function (options, ca initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4271,7 +4271,7 @@ LROs.prototype.deleteProvisioning202DeletingFailed200 = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4493,7 +4493,7 @@ LROs.prototype.deleteProvisioning202Deletingcanceled200 = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4711,7 +4711,7 @@ LROs.prototype.delete204Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4880,7 +4880,7 @@ LROs.prototype.delete202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5083,7 +5083,7 @@ LROs.prototype.delete202NoRetry204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5285,7 +5285,7 @@ LROs.prototype.deleteNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5455,7 +5455,7 @@ LROs.prototype.deleteAsyncNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5625,7 +5625,7 @@ LROs.prototype.deleteAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5795,7 +5795,7 @@ LROs.prototype.deleteAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5965,7 +5965,7 @@ LROs.prototype.deleteAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6135,7 +6135,7 @@ LROs.prototype.deleteAsyncRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6306,7 +6306,7 @@ LROs.prototype.post200WithPayload = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6533,7 +6533,7 @@ LROs.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6734,7 +6734,7 @@ LROs.prototype.post202NoRetry204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6967,7 +6967,7 @@ LROs.prototype.postAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7201,7 +7201,7 @@ LROs.prototype.postAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7434,7 +7434,7 @@ LROs.prototype.postAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7635,7 +7635,7 @@ LROs.prototype.postAsyncRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7787,4 +7787,4 @@ LROs.prototype.beginPostAsyncRetrycanceled = function (options, callback) { }; -module.exports = LROs; +module.exports = LROs; \ No newline at end of file diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js index 3d4d296e68aaa..0c25e2df3bb0c 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js @@ -82,7 +82,7 @@ LROsCustomHeader.prototype.putAsyncRetrySucceeded = function (options, callback) initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -320,7 +320,7 @@ LROsCustomHeader.prototype.put201CreatingSucceeded200 = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -573,7 +573,7 @@ LROsCustomHeader.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -777,7 +777,7 @@ LROsCustomHeader.prototype.postAsyncRetrySucceeded = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -931,4 +931,4 @@ LROsCustomHeader.prototype.beginPostAsyncRetrySucceeded = function (options, cal }; -module.exports = LROsCustomHeader; +module.exports = LROsCustomHeader; \ No newline at end of file diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index e0207511c4c34..fcc09299d1c03 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -57,7 +57,27 @@ function AzureServiceClient(credentials, options) { util.inherits(AzureServiceClient, msRest.ServiceClient); /** - * Poll Azure long running GET, PATCH, POST or DELETE operations. + * Poll Azure long running PUT or PATCH operation. (Deprecated, new version of the code-gen will generate code to call getLongRunningOperationResult) + * @param {object} [resultOfInitialRequest] - Response of the initial request for the long running operation. + * @param {object} [options] + * @param {object} [options.customHeaders] headers that will be added to request + */ +AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { + return this.getLongRunningOperationResult(resultOfInitialRequest, options, callback); +} + +/** + * Poll Azure long running POST or DELETE operations. (Deprecated, new version of the code-gen will generate code to call getLongRunningOperationResult) + * @param {object} [resultOfInitialRequest] - result of the initial request. + * @param {object} [options] + * @param {object} [options.customHeaders] headers that will be added to request + */ +AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { + return this.getLongRunningOperationResult(resultOfInitialRequest, options, callback); +} + +/** + * Poll Azure long running PUT, PATCH, POST or DELETE operations. * @param {object} [resultOfInitialRequest] - result of the initial request. * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request @@ -80,14 +100,25 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI if (!resultOfInitialRequest.response) { return callback(new Error('Missing resultOfInitialRequest.response')); } + + if (!resultOfInitialRequest.request) { + return callback(new Error('Missing resultOfInitialRequest.request')); + } + + if (!resultOfInitialRequest.request.method) { + return callback(new Error('Missing resultOfInitialRequest.request.method')); + } - if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + var initialRequestMethod = resultOfInitialRequest.request.method; + + if (this._checkResponseStatusCodeFailed(resultOfInitialRequest)) { return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', resultOfInitialRequest.response.statusCode, - resultOfInitialRequest.request.method))); + initialRequestMethod))); } var pollingState = null; + try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { @@ -110,10 +141,10 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) { + self._updateStateFromLocationHeader(initialRequestMethod, pollingState, function(err) { return callback(err); }); - } else if (resultOfInitialRequest.request.method === 'PUT') { + } else if (initialRequestMethod === 'PUT') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); @@ -125,7 +156,8 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI //when done function (err) { if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) + && (initialRequestMethod === 'PUT' || initialRequestMethod === 'PATCH')) { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); @@ -138,7 +170,7 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI }); }; -AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) { +AzureServiceClient.prototype._checkResponseStatusCodeFailed = function (initialRequest) { var statusCode = initialRequest.response.statusCode; var method = initialRequest.request.method; if (statusCode === 200 || statusCode === 202 || diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index 3a56e378e4d9c..954032749dcfd 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -94,7 +94,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.statusCode = 201; it('throw on not Lro related status code', function (done) { - client.getLongRunningOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { + client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -103,7 +103,7 @@ describe('AzureServiceClient', function () { it('works by polling from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); done(); @@ -118,7 +118,7 @@ describe('AzureServiceClient', function () { 'testCustomField': testCustomFieldValue } }; - client.getLongRunningOperationResult(resultOfInitialRequest, options, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, options, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); result.response.testCustomField.should.equal(testCustomFieldValue); @@ -129,7 +129,7 @@ describe('AzureServiceClient', function () { it('works by polling from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); should.exist(result.response.randomFieldFromPollLocationHeader); @@ -140,7 +140,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -149,7 +149,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -205,7 +205,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; it('throw on not Lro related status code', function (done) { - client.getLongRunningOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { + client.getPostOrDeleteOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -215,7 +215,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; resultOfInitialRequest.request.method = 'POST'; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollAsyncOpHeader); done(); @@ -225,7 +225,7 @@ describe('AzureServiceClient', function () { it('works by polling from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollLocationHeader); JSON.parse(result.body).name.should.equal(testResourceName); @@ -236,7 +236,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -245,7 +245,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); From 1a6bf4e79d9daa64ecf3fc4d6e9492ab7cc57b44 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 27 Apr 2016 10:36:56 -0700 Subject: [PATCH 12/12] code revise --- .../NodeJS/ms-rest-azure/lib/azureServiceClient.js | 8 ++++---- .../NodeJS/ms-rest-azure/test/azureServiceClientTests.js | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index fcc09299d1c03..ca4413b85a00b 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -64,7 +64,7 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); */ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { return this.getLongRunningOperationResult(resultOfInitialRequest, options, callback); -} +}; /** * Poll Azure long running POST or DELETE operations. (Deprecated, new version of the code-gen will generate code to call getLongRunningOperationResult) @@ -74,7 +74,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn */ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { return this.getLongRunningOperationResult(resultOfInitialRequest, options, callback); -} +}; /** * Poll Azure long running PUT, PATCH, POST or DELETE operations. @@ -156,8 +156,8 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI //when done function (err) { if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) - && (initialRequestMethod === 'PUT' || initialRequestMethod === 'PATCH')) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && + (initialRequestMethod === 'PUT' || initialRequestMethod === 'PATCH')) { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index 954032749dcfd..8e11e689690b7 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -92,9 +92,10 @@ describe('AzureServiceClient', function () { describe('Put', function () { resultOfInitialRequest.response.statusCode = 201; + resultOfInitialRequest.request.method = 'PUT'; it('throw on not Lro related status code', function (done) { - client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { + client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo", method:'PUT' }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -159,6 +160,7 @@ describe('AzureServiceClient', function () { describe('Patch', function () { resultOfInitialRequest.response.statusCode = 202; resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + resultOfInitialRequest.request.method = 'PATCH'; it('works by polling from location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = '';