diff --git a/lib/services/storageManagement2/lib/models/getLastSyncTimeResult.js b/lib/services/storageManagement2/lib/models/getLastSyncTimeResult.js new file mode 100644 index 0000000000..a672f710bd --- /dev/null +++ b/lib/services/storageManagement2/lib/models/getLastSyncTimeResult.js @@ -0,0 +1,73 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * The response from the get last synctime operation. + * + */ +class GetLastSyncTimeResult { + /** + * Create a GetLastSyncTimeResult. + * @member {string} [status] The status of the secondary location of the + * Storage Account. Live: Indicates that the secondary location is active and + * operational; Bootstrap: Indicates initial synchronization from the primary + * location to the secondary location is in progress, this typically occurs + * when replication is first enabled; Unavailable: Indicates that the + * secondary location is temporarily unavailable. Possible values include: + * 'Live', 'Bootstrap', 'Unavailable' + * @member {date} [lastSyncTime] All primary writes preceding this value are + * guaranteed to be replicated to secondary. Primary writes after this point + * in time may or may not be replicated. It is the minimum last sync time of + * the account’s Blob/Table/Queue/File endpoints. The value may be account’s + * creation time if LastSyncTime is not available. This can happen if the + * replication status is bootstrap or unavailable. + */ + constructor() { + } + + /** + * Defines the metadata of GetLastSyncTimeResult + * + * @returns {object} metadata of GetLastSyncTimeResult + * + */ + mapper() { + return { + required: false, + serializedName: 'GetLastSyncTimeResult', + type: { + name: 'Composite', + className: 'GetLastSyncTimeResult', + modelProperties: { + status: { + required: false, + readOnly: true, + serializedName: 'status', + type: { + name: 'String' + } + }, + lastSyncTime: { + required: false, + readOnly: true, + serializedName: 'lastSyncTime', + type: { + name: 'DateTime' + } + } + } + } + }; + } +} + +module.exports = GetLastSyncTimeResult; diff --git a/lib/services/storageManagement2/lib/models/index.d.ts b/lib/services/storageManagement2/lib/models/index.d.ts index e346d22de5..9f9e746378 100644 --- a/lib/services/storageManagement2/lib/models/index.d.ts +++ b/lib/services/storageManagement2/lib/models/index.d.ts @@ -793,6 +793,8 @@ export interface TrackedResource extends Resource { * 'Allow', 'Deny' * @member {boolean} [isHnsEnabled] Account HierarchicalNamespace enabled if * sets to true. + * @member {boolean} [failoverInProgress] If the failover is in progress, the + * value will be true, otherwise, it will be null. */ export interface StorageAccount extends TrackedResource { readonly sku?: Sku; @@ -814,6 +816,7 @@ export interface StorageAccount extends TrackedResource { enableHttpsTrafficOnly?: boolean; readonly networkRuleSet?: NetworkRuleSet; isHnsEnabled?: boolean; + readonly failoverInProgress?: boolean; } /** @@ -1156,6 +1159,31 @@ export interface ListServiceSasResponse { readonly serviceSasToken?: string; } +/** + * @class + * Initializes a new instance of the GetLastSyncTimeResult class. + * @constructor + * The response from the get last synctime operation. + * + * @member {string} [status] The status of the secondary location of the + * Storage Account. Live: Indicates that the secondary location is active and + * operational; Bootstrap: Indicates initial synchronization from the primary + * location to the secondary location is in progress, this typically occurs + * when replication is first enabled; Unavailable: Indicates that the secondary + * location is temporarily unavailable. Possible values include: 'Live', + * 'Bootstrap', 'Unavailable' + * @member {date} [lastSyncTime] All primary writes preceding this value are + * guaranteed to be replicated to secondary. Primary writes after this point in + * time may or may not be replicated. It is the minimum last sync time of the + * account’s Blob/Table/Queue/File endpoints. The value may be account’s + * creation time if LastSyncTime is not available. This can happen if the + * replication status is bootstrap or unavailable. + */ +export interface GetLastSyncTimeResult { + readonly status?: string; + readonly lastSyncTime?: Date; +} + /** * @class * Initializes a new instance of the ProxyResource class. diff --git a/lib/services/storageManagement2/lib/models/index.js b/lib/services/storageManagement2/lib/models/index.js index 4d2443cbe9..94a70a3818 100644 --- a/lib/services/storageManagement2/lib/models/index.js +++ b/lib/services/storageManagement2/lib/models/index.js @@ -52,6 +52,7 @@ exports.AccountSasParameters = require('./accountSasParameters'); exports.ListAccountSasResponse = require('./listAccountSasResponse'); exports.ServiceSasParameters = require('./serviceSasParameters'); exports.ListServiceSasResponse = require('./listServiceSasResponse'); +exports.GetLastSyncTimeResult = require('./getLastSyncTimeResult'); exports.ProxyResource = require('./proxyResource'); exports.AzureEntityResource = require('./azureEntityResource'); exports.UpdateHistoryProperty = require('./updateHistoryProperty'); diff --git a/lib/services/storageManagement2/lib/models/storageAccount.js b/lib/services/storageManagement2/lib/models/storageAccount.js index 8ff0c24b3a..46eefffb25 100644 --- a/lib/services/storageManagement2/lib/models/storageAccount.js +++ b/lib/services/storageManagement2/lib/models/storageAccount.js @@ -168,6 +168,8 @@ class StorageAccount extends models['TrackedResource'] { * include: 'Allow', 'Deny' * @member {boolean} [isHnsEnabled] Account HierarchicalNamespace enabled if * sets to true. + * @member {boolean} [failoverInProgress] If the failover is in progress, the + * value will be true, otherwise, it will be null. */ constructor() { super(); @@ -391,6 +393,14 @@ class StorageAccount extends models['TrackedResource'] { type: { name: 'Boolean' } + }, + failoverInProgress: { + required: false, + readOnly: true, + serializedName: 'properties.failoverInProgress', + type: { + name: 'Boolean' + } } } } diff --git a/lib/services/storageManagement2/lib/operations/index.d.ts b/lib/services/storageManagement2/lib/operations/index.d.ts index b6a3c984b4..958e2bc256 100644 --- a/lib/services/storageManagement2/lib/operations/index.d.ts +++ b/lib/services/storageManagement2/lib/operations/index.d.ts @@ -1466,6 +1466,141 @@ export interface StorageAccounts { listServiceSAS(resourceGroupName: string, accountName: string, parameters: models.ServiceSasParameters, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + failoverWithHttpOperationResponse(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + failover(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + failover(resourceGroupName: string, accountName: string, callback: ServiceCallback): void; + failover(resourceGroupName: string, accountName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Retrieve last sync time for his or her RA-GRS and GRS accounts. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + getLastSyncTimeWithHttpOperationResponse(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Retrieve last sync time for his or her RA-GRS and GRS accounts. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {GetLastSyncTimeResult} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {GetLastSyncTimeResult} [result] - The deserialized result object if an error did not occur. + * See {@link GetLastSyncTimeResult} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + getLastSyncTime(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getLastSyncTime(resourceGroupName: string, accountName: string, callback: ServiceCallback): void; + getLastSyncTime(resourceGroupName: string, accountName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + /** * Asynchronously creates a new storage account with the specified parameters. * If an account is already created and a subsequent create request is issued @@ -1751,6 +1886,76 @@ export interface StorageAccounts { beginCreate(resourceGroupName: string, accountName: string, parameters: models.StorageAccountCreateParameters, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; beginCreate(resourceGroupName: string, accountName: string, parameters: models.StorageAccountCreateParameters, callback: ServiceCallback): void; beginCreate(resourceGroupName: string, accountName: string, parameters: models.StorageAccountCreateParameters, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + beginFailoverWithHttpOperationResponse(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + beginFailover(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + beginFailover(resourceGroupName: string, accountName: string, callback: ServiceCallback): void; + beginFailover(resourceGroupName: string, accountName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } /** diff --git a/lib/services/storageManagement2/lib/operations/storageAccounts.js b/lib/services/storageManagement2/lib/operations/storageAccounts.js index 176c3f95b9..143b1a2de6 100644 --- a/lib/services/storageManagement2/lib/operations/storageAccounts.js +++ b/lib/services/storageManagement2/lib/operations/storageAccounts.js @@ -2170,6 +2170,251 @@ function _listServiceSAS(resourceGroupName, accountName, parameters, options, ca }); } + +/** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _failover(resourceGroupName, accountName, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + + if (!callback) { + throw new Error('callback cannot be null.'); + } + + // Send request + this.beginFailover(resourceGroupName, accountName, options, (err, parsedResult, httpRequest, response) => { + if (err) return callback(err); + + let initialResult = new msRest.HttpOperationResponse(); + initialResult.request = httpRequest; + initialResult.response = response; + initialResult.body = response.body; + client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => { + if (err) return callback(err); + + // Create Result + let result = null; + + httpRequest = pollingResult.request; + response = pollingResult.response; + let responseBody = pollingResult.body; + if (responseBody === '') responseBody = null; + + // Deserialize Response + + return callback(null, result, httpRequest, response); + }); + }); +} + +/** + * Retrieve last sync time for his or her RA-GRS and GRS accounts. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link GetLastSyncTimeResult} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _getLastSyncTime(resourceGroupName, accountName, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + let apiVersion = '2018-07-01'; + // Validate + try { + if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') { + throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.'); + } + if (resourceGroupName !== null && resourceGroupName !== undefined) { + if (resourceGroupName.length > 90) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90'); + } + if (resourceGroupName.length < 1) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1'); + } + if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/'); + } + } + if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') { + throw new Error('accountName cannot be null or undefined and it must be of type string.'); + } + if (accountName !== null && accountName !== undefined) { + if (accountName.length > 24) + { + throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24'); + } + if (accountName.length < 3) + { + throw new Error('"accountName" should satisfy the constraint - "MinLength": 3'); + } + } + if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') { + throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.'); + } + if (this.client.subscriptionId !== null && this.client.subscriptionId !== undefined) { + if (this.client.subscriptionId.length < 1) + { + throw new Error('"this.client.subscriptionId" should satisfy the constraint - "MinLength": 1'); + } + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/lastSyncTime'; + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName)); + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['GetLastSyncTimeResult']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + /** * Asynchronously creates a new storage account with the specified parameters. * If an account is already created and a subsequent create request is issued @@ -2478,6 +2723,167 @@ function _beginCreate(resourceGroupName, accountName, parameters, options, callb }); } +/** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _beginFailover(resourceGroupName, accountName, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + let apiVersion = '2018-07-01'; + // Validate + try { + if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') { + throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.'); + } + if (resourceGroupName !== null && resourceGroupName !== undefined) { + if (resourceGroupName.length > 90) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90'); + } + if (resourceGroupName.length < 1) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1'); + } + if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/'); + } + } + if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') { + throw new Error('accountName cannot be null or undefined and it must be of type string.'); + } + if (accountName !== null && accountName !== undefined) { + if (accountName.length > 24) + { + throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24'); + } + if (accountName.length < 3) + { + throw new Error('"accountName" should satisfy the constraint - "MinLength": 3'); + } + } + if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') { + throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.'); + } + if (this.client.subscriptionId !== null && this.client.subscriptionId !== undefined) { + if (this.client.subscriptionId.length < 1) + { + throw new Error('"this.client.subscriptionId" should satisfy the constraint - "MinLength": 1'); + } + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/failover'; + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName)); + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200 && statusCode !== 202) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + + return callback(null, result, httpRequest, response); + }); +} + /** Class representing a StorageAccounts. */ class StorageAccounts { /** @@ -2497,7 +2903,10 @@ class StorageAccounts { this._regenerateKey = _regenerateKey; this._listAccountSAS = _listAccountSAS; this._listServiceSAS = _listServiceSAS; + this._failover = _failover; + this._getLastSyncTime = _getLastSyncTime; this._beginCreate = _beginCreate; + this._beginFailover = _beginFailover; } /** @@ -4120,6 +4529,195 @@ class StorageAccounts { } } + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + failoverWithHttpOperationResponse(resourceGroupName, accountName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._failover(resourceGroupName, accountName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + failover(resourceGroupName, accountName, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._failover(resourceGroupName, accountName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._failover(resourceGroupName, accountName, options, optionalCallback); + } + } + + /** + * Retrieve last sync time for his or her RA-GRS and GRS accounts. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + getLastSyncTimeWithHttpOperationResponse(resourceGroupName, accountName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getLastSyncTime(resourceGroupName, accountName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Retrieve last sync time for his or her RA-GRS and GRS accounts. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {GetLastSyncTimeResult} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link GetLastSyncTimeResult} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + getLastSyncTime(resourceGroupName, accountName, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._getLastSyncTime(resourceGroupName, accountName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getLastSyncTime(resourceGroupName, accountName, options, optionalCallback); + } + } + /** * Asynchronously creates a new storage account with the specified parameters. * If an account is already created and a subsequent create request is issued @@ -4434,6 +5032,103 @@ class StorageAccounts { } } + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + beginFailoverWithHttpOperationResponse(resourceGroupName, accountName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._beginFailover(resourceGroupName, accountName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + beginFailover(resourceGroupName, accountName, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._beginFailover(resourceGroupName, accountName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._beginFailover(resourceGroupName, accountName, options, optionalCallback); + } + } + } module.exports = StorageAccounts;