diff --git a/lib/services/hanaonazureManagement/LICENSE.txt b/lib/services/hanaonazureManagement/LICENSE.txt index 5431ba98b9..8f3d856145 100644 --- a/lib/services/hanaonazureManagement/LICENSE.txt +++ b/lib/services/hanaonazureManagement/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 Microsoft +Copyright (c) 2019 Microsoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/services/hanaonazureManagement/lib/operations/hanaInstances.js b/lib/services/hanaonazureManagement/lib/operations/hanaInstances.js index 7eefd78c01..0322b42db3 100644 --- a/lib/services/hanaonazureManagement/lib/operations/hanaInstances.js +++ b/lib/services/hanaonazureManagement/lib/operations/hanaInstances.js @@ -618,6 +618,7 @@ function _update(resourceGroupName, hanaInstanceName, tagsParameter, options, ca }); } + /** * The operation to restart a SAP HANA instance. * @@ -649,6 +650,68 @@ function _restart(resourceGroupName, hanaInstanceName, options, callback) { callback = options; options = null; } + + if (!callback) { + throw new Error('callback cannot be null.'); + } + + // Send request + this.beginRestart(resourceGroupName, hanaInstanceName, 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); + }); + }); +} + +/** + * The operation to restart a SAP HANA instance. + * + * @param {string} resourceGroupName Name of the resource group. + * + * @param {string} hanaInstanceName Name of the SAP HANA on Azure instance. + * + * @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 _beginRestart(resourceGroupName, hanaInstanceName, 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.'); } @@ -712,7 +775,7 @@ function _restart(resourceGroupName, hanaInstanceName, options, callback) { return callback(err); } let statusCode = response.statusCode; - if (statusCode !== 202) { + if (statusCode !== 200 && statusCode !== 202) { let error = new Error(responseBody); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -1024,6 +1087,7 @@ class HanaInstances { this._get = _get; this._update = _update; this._restart = _restart; + this._beginRestart = _beginRestart; this._listNext = _listNext; this._listByResourceGroupNext = _listByResourceGroupNext; } @@ -1485,6 +1549,91 @@ class HanaInstances { } } + /** + * The operation to restart a SAP HANA instance. + * + * @param {string} resourceGroupName Name of the resource group. + * + * @param {string} hanaInstanceName Name of the SAP HANA on Azure instance. + * + * @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. + */ + beginRestartWithHttpOperationResponse(resourceGroupName, hanaInstanceName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._beginRestart(resourceGroupName, hanaInstanceName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * The operation to restart a SAP HANA instance. + * + * @param {string} resourceGroupName Name of the resource group. + * + * @param {string} hanaInstanceName Name of the SAP HANA on Azure instance. + * + * @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. + */ + beginRestart(resourceGroupName, hanaInstanceName, 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._beginRestart(resourceGroupName, hanaInstanceName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._beginRestart(resourceGroupName, hanaInstanceName, options, optionalCallback); + } + } + /** * @summary Gets a list of SAP HANA instances in the specified subscription. * diff --git a/lib/services/hanaonazureManagement/lib/operations/index.d.ts b/lib/services/hanaonazureManagement/lib/operations/index.d.ts index f69736bc34..016eead722 100644 --- a/lib/services/hanaonazureManagement/lib/operations/index.d.ts +++ b/lib/services/hanaonazureManagement/lib/operations/index.d.ts @@ -403,6 +403,64 @@ export interface HanaInstances { restart(resourceGroupName: string, hanaInstanceName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + /** + * The operation to restart a SAP HANA instance. + * + * @param {string} resourceGroupName Name of the resource group. + * + * @param {string} hanaInstanceName Name of the SAP HANA on Azure instance. + * + * @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. + */ + beginRestartWithHttpOperationResponse(resourceGroupName: string, hanaInstanceName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * The operation to restart a SAP HANA instance. + * + * @param {string} resourceGroupName Name of the resource group. + * + * @param {string} hanaInstanceName Name of the SAP HANA on Azure instance. + * + * @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. + */ + beginRestart(resourceGroupName: string, hanaInstanceName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + beginRestart(resourceGroupName: string, hanaInstanceName: string, callback: ServiceCallback): void; + beginRestart(resourceGroupName: string, hanaInstanceName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + /** * @summary Gets a list of SAP HANA instances in the specified subscription. *