/* jshint latedef:false */
/* jshint forin:false */
/* jshint noempty:false */

// 
// Copyright (c) Microsoft and contributors.  All rights reserved.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//   http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 
// See the License for the specific language governing permissions and
// limitations under the License.
// 

// Warning: This code was generated by a tool.
// 
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

'use strict';

var util = require('util');
var azureCommon = require('azure-common');
var xml = azureCommon.xml2js;
var js2xml = azureCommon.js2xml;
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;

var HDInsightClusterManagementClient = ( /** @lends HDInsightClusterManagementClient */ function() {
  /**
   * @class
   * Initializes a new instance of the HDInsightClusterManagementClient class.
   * @constructor
   * 
   * @param {string} cloudServiceName
   * 
   * @param {SubscriptionCloudCredentials} credentials Gets subscription
   * credentials which uniquely identify Microsoft Azure subscription. The
   * subscription ID forms part of the URI for every service call.
   * 
   * @param {string} [credentials.subscriptionId]
   * 
   * @param {string} [baseUri] Gets the URI used as the base for all cloud
   * service requests.
   * 
   * @param {Array} filters
   */
  function HDInsightClusterManagementClient(credentials, baseUri, filters) {

    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    HDInsightClusterManagementClient['super_'].call(this, credentials, filters);
    
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://management.core.windows.net/';
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = '2014-10-01';
    }
    if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
      this.longRunningOperationInitialTimeout = -1;
    }
    if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
      this.longRunningOperationRetryTimeout = -1;
    }
    /**
     * Provides an instance of the [ClusterOperations](-ClusterOperations.html)
     * object.
     * @type {object}
     */
    this.clusterManagement = new ClusterOperations(this);
  }
  
  util.inherits(HDInsightClusterManagementClient, Service);
  
  /**
   * The Get Operation Status operation returns the status of the specified
   * operation. After calling an asynchronous operation, you can call Get
   * Operation Status to determine whether the operation has succeeded,
   * failed, or is still in progress.
   * 
   * @param {string} requestId The request ID for the request you wish to
   * track. The request ID is returned in the x-ms-request-id response header
   * for every request.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  HDInsightClusterManagementClient.prototype.getOperationStatus = function(requestId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (requestId === null || requestId === undefined) {
      return callback(new Error('requestId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.credentials.subscriptionId !== null && this.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.credentials.subscriptionId);
    }
    url2 = url2 + '/operations/';
    url2 = url2 + encodeURIComponent(requestId);
    var baseUrl = this.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-08-01';
    
    // Send Request
    return this.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var operationElement = js2xml.getElement(responseDoc, responseDoc, 'OPERATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (operationElement !== null && operationElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, operationElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.id = idInstance;
            }
            
            var statusElement = js2xml.getElement(responseDoc, operationElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (statusElement !== null && statusElement !== undefined && statusElement.length !== 0) {
              var statusInstance = statusElement;
              result.status = statusInstance;
            }
            
            var httpStatusCodeElement = js2xml.getElement(responseDoc, operationElement, 'HTTPSTATUSCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (httpStatusCodeElement !== null && httpStatusCodeElement !== undefined && httpStatusCodeElement.length !== 0) {
              var httpStatusCodeInstance = httpStatusCodeElement;
              result.httpStatusCode = httpStatusCodeInstance;
            }
            
            var errorElement = js2xml.getElement(responseDoc, operationElement, 'ERROR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (errorElement !== null && errorElement !== undefined) {
              var errorInstance = {};
              result.error = errorInstance;
              
              var codeElement = js2xml.getElement(responseDoc, errorElement, 'CODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (codeElement !== null && codeElement !== undefined) {
                var codeInstance = codeElement;
                errorInstance.code = codeInstance;
              }
              
              var messageElement = js2xml.getElement(responseDoc, errorElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (messageElement !== null && messageElement !== undefined) {
                var messageInstance = messageElement;
                errorInstance.message = messageInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return HDInsightClusterManagementClient;
})();
exports.HDInsightClusterManagementClient = HDInsightClusterManagementClient;

var ClusterOperations = ( /** @lends ClusterOperations */ function() {
  /**
   * @class
   * Operations for managing HDInsight clusters.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [HDInsightClusterManagementClient] {@link
   * HDInsightClusterManagementClient~HDInsightClusterManagementClient}.
   * See [clusterManagement] {@link
   * HDInsightClusterManagementClient~HDInsightClusterManagementClient#clusterManagement}.
   * Initializes a new instance of the ClusterOperations class.
   * @constructor
   * 
   * @param {HDInsightClusterManagementClient} client Reference to the service
   * client.
   */
  function ClusterOperations(client) {
    this.client = client;
  }
  
  /**
   * Creates an HDInsight cluster.
   * 
   * @param {string} clusterName Cluster name to create.
   * 
   * @param {ClusterCreationParameters} parameters Parameters supplied to the
   * Create Cluster operation.
   * 
   * @param {string} parameters.payload
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.beginCreating = function(clusterName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.payload === null || parameters.payload === undefined) {
      return callback(new Error('parameters.payload cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/cloudservices/';
    url2 = url2 + encodeURIComponent(this.client.cloudServiceName);
    url2 = url2 + '/resources/HDInsight/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-08-01';
    
    // Serialize Request
    var requestContent = parameters.payload;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 202) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Deletes an HDInsight cluster.
   * 
   * @param {string} clusterName Parameters supplied to the Delete Cluster
   * operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.beginDeleting = function(clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId.toString());
    }
    url2 = url2 + '/cloudservices/';
    url2 = url2 + encodeURIComponent(this.client.cloudServiceName);
    url2 = url2 + '/resources/hdinsight/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['schema-version'] = '1.0';
    httpRequest.headers['x-ms-version'] = '2012-08-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 202) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Creates an HDInsight cluster.
   * 
   * @param {string} clusterName Cluster name to create.
   * 
   * @param {ClusterCreationParameters} parameters Parameters supplied to the
   * Create Cluster operation.
   * 
   * @param {string} parameters.payload
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.create = function(clusterName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.clusterManagement.beginCreating(clusterName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Deletes an HDInsight cluster.
   * 
   * @param {string} clusterName Parameters supplied to the Delete Cluster
   * operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.deleteMethod = function(clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.clusterManagement.beginDeleting(clusterName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Get Clusters operation gets the details of the specified cluster.
   * (see http://msdn.microsoft.com/en-us/library/windowsazure/ee460787.aspx
   * for more information)
   * 
   * @param {string} clusterName Name of the clusters for which details are to
   * be retrieved.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.get = function(clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/cloudservices/';
    url2 = url2 + encodeURIComponent(this.client.cloudServiceName);
    url2 = url2 + '/resources/hdinsight/~/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-08-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var passthroughResponseElement = js2xml.getElement(responseDoc, responseDoc, 'PASSTHROUGHRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2013/05/MANAGEMENT');
          if (passthroughResponseElement !== null && passthroughResponseElement !== undefined) {
            var passthroughResponseInstance = {};
            result.passthroughResponse = passthroughResponseInstance;
            
            var dataElement = js2xml.getElement(responseDoc, passthroughResponseElement, 'DATA', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2013/05/MANAGEMENT');
            if (dataElement !== null && dataElement !== undefined) {
              var dataInstance = { clusterRoles: [] };
              passthroughResponseInstance.data = dataInstance;
              
              var dnsNameElement = js2xml.getElement(responseDoc, dataElement, 'DNSNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (dnsNameElement !== null && dnsNameElement !== undefined) {
                var dnsNameInstance = dnsNameElement;
                dataInstance.dnsName = dnsNameInstance;
              }
              
              var locationElement = js2xml.getElement(responseDoc, dataElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (locationElement !== null && locationElement !== undefined) {
                var locationInstance = locationElement;
                dataInstance.location = locationInstance;
              }
              
              var versionElement = js2xml.getElement(responseDoc, dataElement, 'VERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (versionElement !== null && versionElement !== undefined) {
                var versionInstance = versionElement;
                dataInstance.version = versionInstance;
              }
              
              var clusterRoleCollectionSequenceElement = js2xml.getElement(responseDoc, dataElement, 'CLUSTERROLECOLLECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (clusterRoleCollectionSequenceElement !== null && clusterRoleCollectionSequenceElement !== undefined) {
                for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, clusterRoleCollectionSequenceElement, 'CLUSTERROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT').length; loweredIndex1 = loweredIndex1 + 1) {
                  var clusterRoleCollectionElement = js2xml.getElements(responseDoc, clusterRoleCollectionSequenceElement, 'CLUSTERROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT')[loweredIndex1];
                  var clusterRoleInstance = {};
                  dataInstance.clusterRoles.push(clusterRoleInstance);
                  
                  var friendlyNameElement = js2xml.getElement(responseDoc, clusterRoleCollectionElement, 'FRIENDLYNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (friendlyNameElement !== null && friendlyNameElement !== undefined) {
                    var friendlyNameInstance = friendlyNameElement;
                    clusterRoleInstance.friendlyName = friendlyNameInstance;
                  }
                  
                  var instanceCountElement = js2xml.getElement(responseDoc, clusterRoleCollectionElement, 'INSTANCECOUNT', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (instanceCountElement !== null && instanceCountElement !== undefined && instanceCountElement.length !== 0) {
                    var instanceCountInstance = parseInt(instanceCountElement, 10);
                    clusterRoleInstance.instanceCount = instanceCountInstance;
                  }
                  
                  var remoteDesktopSettingsElement = js2xml.getElement(responseDoc, clusterRoleCollectionElement, 'REMOTEDESKTOPSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (remoteDesktopSettingsElement !== null && remoteDesktopSettingsElement !== undefined) {
                    var remoteDesktopSettingsInstance = {};
                    clusterRoleInstance.remoteDesktopSettings = remoteDesktopSettingsInstance;
                    
                    var authenticationCredentialElement = js2xml.getElement(responseDoc, remoteDesktopSettingsElement, 'AUTHENTICATIONCREDENTIAL', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                    if (authenticationCredentialElement !== null && authenticationCredentialElement !== undefined) {
                      var authenticationCredentialInstance = {};
                      remoteDesktopSettingsInstance.authenticationCredential = authenticationCredentialInstance;
                      
                      var passwordElement = js2xml.getElement(responseDoc, authenticationCredentialElement, 'PASSWORD', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                      if (passwordElement !== null && passwordElement !== undefined) {
                        var passwordInstance = passwordElement;
                        authenticationCredentialInstance.password = passwordInstance;
                      }
                      
                      var usernameElement = js2xml.getElement(responseDoc, authenticationCredentialElement, 'USERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                      if (usernameElement !== null && usernameElement !== undefined) {
                        var usernameInstance = usernameElement;
                        authenticationCredentialInstance.username = usernameInstance;
                      }
                    }
                    
                    var isEnabledElement = js2xml.getElement(responseDoc, remoteDesktopSettingsElement, 'ISENABLED', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                    if (isEnabledElement !== null && isEnabledElement !== undefined && isEnabledElement.length !== 0) {
                      var isEnabledInstance = isEnabledElement === 'true';
                      remoteDesktopSettingsInstance.isEnabled = isEnabledInstance;
                    }
                    
                    var remoteAccessExpiryElement = js2xml.getElement(responseDoc, remoteDesktopSettingsElement, 'REMOTEACCESSEXPIRY', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                    if (remoteAccessExpiryElement !== null && remoteAccessExpiryElement !== undefined) {
                      var remoteAccessExpiryInstance = remoteAccessExpiryElement;
                      remoteDesktopSettingsInstance.remoteAccessExpiry = remoteAccessExpiryInstance;
                    }
                  }
                  
                  var vMSizeElement = js2xml.getElement(responseDoc, clusterRoleCollectionElement, 'VMSIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (vMSizeElement !== null && vMSizeElement !== undefined) {
                    var vMSizeInstance = vMSizeElement;
                    clusterRoleInstance.vMSize = vMSizeInstance;
                  }
                }
              }
              
              var componentsElement = js2xml.getElement(responseDoc, dataElement, 'COMPONENTS', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (componentsElement !== null && componentsElement !== undefined) {
                var componentsInstance = {};
                dataInstance.components = componentsInstance;
                
                var yarnElement = js2xml.getElement(responseDoc, componentsElement, 'YARN', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                if (yarnElement !== null && yarnElement !== undefined) {
                  var yarnInstance = {};
                  componentsInstance.yarn = yarnInstance;
                  
                  var applicationsElement = js2xml.getElement(responseDoc, yarnElement, 'APPLICATIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (applicationsElement !== null && applicationsElement !== undefined) {
                    var applicationsInstance = {};
                    yarnInstance.applications = applicationsInstance;
                    
                    var yarnApplicationElement = js2xml.getElement(responseDoc, applicationsElement, 'YARNAPPLICATION', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                    if (yarnApplicationElement !== null && yarnApplicationElement !== undefined) {
                      var yarnApplicationInstance = {};
                      applicationsInstance.yarnApplication = yarnApplicationInstance;
                      
                      var additionalStorageContainersElement = js2xml.getElement(responseDoc, yarnApplicationElement, 'ADDITIONALSTORAGECONTAINERS', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                      if (additionalStorageContainersElement !== null && additionalStorageContainersElement !== undefined) {
                        var additionalStorageContainersInstance = additionalStorageContainersElement;
                        yarnApplicationInstance.additionalStorageContainers = additionalStorageContainersInstance;
                      }
                      
                      var capacitySchedulerConfigurationElement = js2xml.getElement(responseDoc, yarnApplicationElement, 'CAPACITYSCHEDULERCONFIGURATION', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                      if (capacitySchedulerConfigurationElement !== null && capacitySchedulerConfigurationElement !== undefined) {
                        var capacitySchedulerConfigurationInstance = capacitySchedulerConfigurationElement;
                        yarnApplicationInstance.capacitySchedulerConfiguration = capacitySchedulerConfigurationInstance;
                      }
                      
                      var defaultStorageAccountAndContainerElement = js2xml.getElement(responseDoc, yarnApplicationElement, 'DEFAULTSTORAGEACCOUNTANDCONTAINER', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                      if (defaultStorageAccountAndContainerElement !== null && defaultStorageAccountAndContainerElement !== undefined) {
                        var defaultStorageAccountAndContainerInstance = {};
                        yarnApplicationInstance.defaultStorageAccountAndContainer = defaultStorageAccountAndContainerInstance;
                        
                        var accountDnsNameElement = js2xml.getElement(responseDoc, defaultStorageAccountAndContainerElement, 'ACCOUNTDNSNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                        if (accountDnsNameElement !== null && accountDnsNameElement !== undefined) {
                          var accountDnsNameInstance = accountDnsNameElement;
                          defaultStorageAccountAndContainerInstance.accountDnsName = accountDnsNameInstance;
                        }
                        
                        var blobContainerNameElement = js2xml.getElement(responseDoc, defaultStorageAccountAndContainerElement, 'BLOBCONTAINERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                        if (blobContainerNameElement !== null && blobContainerNameElement !== undefined) {
                          var blobContainerNameInstance = blobContainerNameElement;
                          defaultStorageAccountAndContainerInstance.blobContainerName = blobContainerNameInstance;
                        }
                        
                        var keyElement = js2xml.getElement(responseDoc, defaultStorageAccountAndContainerElement, 'KEY', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                        if (keyElement !== null && keyElement !== undefined) {
                          var keyInstance = keyElement;
                          defaultStorageAccountAndContainerInstance.key = keyInstance;
                        }
                      }
                      
                      var mapRedSiteXmlPropertiesElement = js2xml.getElement(responseDoc, yarnApplicationElement, 'MAPREDSITEXMLPROPERTIES', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                      if (mapRedSiteXmlPropertiesElement !== null && mapRedSiteXmlPropertiesElement !== undefined) {
                        var mapRedSiteXmlPropertiesInstance = mapRedSiteXmlPropertiesElement;
                        yarnApplicationInstance.mapRedSiteXmlProperties = mapRedSiteXmlPropertiesInstance;
                      }
                    }
                  }
                  
                  var capacitySchedulerConfigurationElement2 = js2xml.getElement(responseDoc, yarnElement, 'CAPACITYSCHEDULERCONFIGURATION', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (capacitySchedulerConfigurationElement2 !== null && capacitySchedulerConfigurationElement2 !== undefined) {
                    var capacitySchedulerConfigurationInstance2 = capacitySchedulerConfigurationElement2;
                    yarnInstance.capacitySchedulerConfiguration = capacitySchedulerConfigurationInstance2;
                  }
                  
                  var configurationElement = js2xml.getElement(responseDoc, yarnElement, 'CONFIGURATION', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (configurationElement !== null && configurationElement !== undefined) {
                    var configurationInstance = configurationElement;
                    yarnInstance.configuration = configurationInstance;
                  }
                  
                  var nodeManagerRoleElement = js2xml.getElement(responseDoc, yarnElement, 'NODEMANAGERROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (nodeManagerRoleElement !== null && nodeManagerRoleElement !== undefined) {
                    var nodeManagerRoleInstance = nodeManagerRoleElement;
                    yarnInstance.nodeManagerRole = nodeManagerRoleInstance;
                  }
                  
                  var resourceManagerRoleElement = js2xml.getElement(responseDoc, yarnElement, 'RESOURCEMANAGERROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (resourceManagerRoleElement !== null && resourceManagerRoleElement !== undefined) {
                    var resourceManagerRoleInstance = resourceManagerRoleElement;
                    yarnInstance.resourceManagerRole = resourceManagerRoleInstance;
                  }
                }
                
                var gatewayElement = js2xml.getElement(responseDoc, componentsElement, 'GATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                if (gatewayElement !== null && gatewayElement !== undefined) {
                  var gatewayInstance = {};
                  componentsInstance.gateway = gatewayInstance;
                  
                  var isEnabledElement2 = js2xml.getElement(responseDoc, gatewayElement, 'ISENABLED', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (isEnabledElement2 !== null && isEnabledElement2 !== undefined && isEnabledElement2.length !== 0) {
                    var isEnabledInstance2 = isEnabledElement2 === 'true';
                    gatewayInstance.isEnabled = isEnabledInstance2;
                  }
                  
                  var restAuthCredentialElement = js2xml.getElement(responseDoc, gatewayElement, 'RESTAUTHCREDENTIAL', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (restAuthCredentialElement !== null && restAuthCredentialElement !== undefined) {
                    var restAuthCredentialInstance = {};
                    gatewayInstance.restAuthCredential = restAuthCredentialInstance;
                    
                    var passwordElement2 = js2xml.getElement(responseDoc, restAuthCredentialElement, 'PASSWORD', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                    if (passwordElement2 !== null && passwordElement2 !== undefined) {
                      var passwordInstance2 = passwordElement2;
                      restAuthCredentialInstance.password = passwordInstance2;
                    }
                    
                    var usernameElement2 = js2xml.getElement(responseDoc, restAuthCredentialElement, 'USERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                    if (usernameElement2 !== null && usernameElement2 !== undefined) {
                      var usernameInstance2 = usernameElement2;
                      restAuthCredentialInstance.username = usernameInstance2;
                    }
                  }
                  
                  var restUriElement = js2xml.getElement(responseDoc, gatewayElement, 'RESTURI', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (restUriElement !== null && restUriElement !== undefined) {
                    var restUriInstance = restUriElement;
                    gatewayInstance.restUri = restUriInstance;
                  }
                }
                
                var oozieElement = js2xml.getElement(responseDoc, componentsElement, 'OOZIE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                if (oozieElement !== null && oozieElement !== undefined) {
                  var oozieInstance = {};
                  componentsInstance.oozie = oozieInstance;
                  
                  var configurationElement2 = js2xml.getElement(responseDoc, oozieElement, 'CONFIGURATION', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (configurationElement2 !== null && configurationElement2 !== undefined && configurationElement2.length !== 0) {
                    var configurationInstance2 = configurationElement2 === 'true';
                    oozieInstance.configuration = configurationInstance2;
                  }
                  
                  var headNodeRoleElement = js2xml.getElement(responseDoc, oozieElement, 'HEADNODEROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (headNodeRoleElement !== null && headNodeRoleElement !== undefined) {
                    var headNodeRoleInstance = headNodeRoleElement;
                    oozieInstance.headNodeRole = headNodeRoleInstance;
                  }
                }
                
                var hiveElement = js2xml.getElement(responseDoc, componentsElement, 'HIVE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                if (hiveElement !== null && hiveElement !== undefined) {
                  var hiveInstance = {};
                  componentsInstance.hive = hiveInstance;
                  
                  var headNodeRoleElement2 = js2xml.getElement(responseDoc, hiveElement, 'HEADNODEROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (headNodeRoleElement2 !== null && headNodeRoleElement2 !== undefined) {
                    var headNodeRoleInstance2 = headNodeRoleElement2;
                    hiveInstance.headNodeRole = headNodeRoleInstance2;
                  }
                  
                  var hiveSiteXmlPropertiesElement = js2xml.getElement(responseDoc, hiveElement, 'HIVESITEXMLPROPERTIES', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (hiveSiteXmlPropertiesElement !== null && hiveSiteXmlPropertiesElement !== undefined) {
                    var hiveSiteXmlPropertiesInstance = hiveSiteXmlPropertiesElement;
                    hiveInstance.hiveSiteXmlProperties = hiveSiteXmlPropertiesInstance;
                  }
                }
                
                var hdfsElement = js2xml.getElement(responseDoc, componentsElement, 'HDFS', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                if (hdfsElement !== null && hdfsElement !== undefined) {
                  var hdfsInstance = {};
                  componentsInstance.hdfs = hdfsInstance;
                  
                  var hdfsSiteXmlPropertiesElement = js2xml.getElement(responseDoc, hdfsElement, 'HDFSSITEXMLPROPERTIES', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (hdfsSiteXmlPropertiesElement !== null && hdfsSiteXmlPropertiesElement !== undefined) {
                    var hdfsSiteXmlPropertiesInstance = hdfsSiteXmlPropertiesElement;
                    hdfsInstance.hdfsSiteXmlProperties = hdfsSiteXmlPropertiesInstance;
                  }
                  
                  var headNodeRoleElement3 = js2xml.getElement(responseDoc, hdfsElement, 'HEADNODEROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (headNodeRoleElement3 !== null && headNodeRoleElement3 !== undefined) {
                    var headNodeRoleInstance3 = headNodeRoleElement3;
                    hdfsInstance.headNodeRole = headNodeRoleInstance3;
                  }
                  
                  var workerNodeRoleElement = js2xml.getElement(responseDoc, hdfsElement, 'WORKERNODEROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (workerNodeRoleElement !== null && workerNodeRoleElement !== undefined) {
                    var workerNodeRoleInstance = workerNodeRoleElement;
                    hdfsInstance.workerNodeRole = workerNodeRoleInstance;
                  }
                }
                
                var hadoopcoreElement = js2xml.getElement(responseDoc, componentsElement, 'HADOOPCORE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                if (hadoopcoreElement !== null && hadoopcoreElement !== undefined) {
                  var hadoopcoreInstance = {};
                  componentsInstance.hadoopcore = hadoopcoreInstance;
                  
                  var coreSiteXmlPropertiesElement = js2xml.getElement(responseDoc, hadoopcoreElement, 'CORESITEXMLPROPERTIES', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (coreSiteXmlPropertiesElement !== null && coreSiteXmlPropertiesElement !== undefined) {
                    var coreSiteXmlPropertiesInstance = coreSiteXmlPropertiesElement;
                    hadoopcoreInstance.coreSiteXmlProperties = coreSiteXmlPropertiesInstance;
                  }
                }
                
                var zookeeperElement = js2xml.getElement(responseDoc, componentsElement, 'ZOOKEEPER', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                if (zookeeperElement !== null && zookeeperElement !== undefined) {
                  var zookeeperInstance = {};
                  componentsInstance.zookeeper = zookeeperInstance;
                  
                  var zookeeperRoleElement = js2xml.getElement(responseDoc, zookeeperElement, 'ZOOKEEPERROLE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (zookeeperRoleElement !== null && zookeeperRoleElement !== undefined) {
                    var zookeeperRoleInstance = zookeeperRoleElement;
                    zookeeperInstance.zookeeperRole = zookeeperRoleInstance;
                  }
                }
                
                var dashboardElement = js2xml.getElement(responseDoc, componentsElement, 'DASHBOARD', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                if (dashboardElement !== null && dashboardElement !== undefined) {
                  var dashboardInstance = {};
                  componentsInstance.dashboard = dashboardInstance;
                  
                  var authenticationCredentialElement2 = js2xml.getElement(responseDoc, dashboardElement, 'AUTHENTICATIONCREDENTIAL', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (authenticationCredentialElement2 !== null && authenticationCredentialElement2 !== undefined) {
                    var authenticationCredentialInstance2 = {};
                    dashboardInstance.authenticationCredential = authenticationCredentialInstance2;
                    
                    var passwordElement3 = js2xml.getElement(responseDoc, authenticationCredentialElement2, 'PASSWORD', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                    if (passwordElement3 !== null && passwordElement3 !== undefined) {
                      var passwordInstance3 = passwordElement3;
                      authenticationCredentialInstance2.password = passwordInstance3;
                    }
                    
                    var usernameElement3 = js2xml.getElement(responseDoc, authenticationCredentialElement2, 'USERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                    if (usernameElement3 !== null && usernameElement3 !== undefined) {
                      var usernameInstance3 = usernameElement3;
                      authenticationCredentialInstance2.username = usernameInstance3;
                    }
                  }
                  
                  var uriElement = js2xml.getElement(responseDoc, dashboardElement, 'URI', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
                  if (uriElement !== null && uriElement !== undefined) {
                    var uriInstance = uriElement;
                    dashboardInstance.uri = uriInstance;
                  }
                }
              }
              
              var createdTimeElement = js2xml.getElement(responseDoc, dataElement, 'CREATEDTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (createdTimeElement !== null && createdTimeElement !== undefined && createdTimeElement.length !== 0) {
                var createdTimeInstance = new Date(createdTimeElement);
                dataInstance.createdTime = createdTimeInstance;
              }
              
              var fullyQualifiedDnsNameElement = js2xml.getElement(responseDoc, dataElement, 'FULLYQUALIFIEDDNSNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (fullyQualifiedDnsNameElement !== null && fullyQualifiedDnsNameElement !== undefined) {
                var fullyQualifiedDnsNameInstance = fullyQualifiedDnsNameElement;
                dataInstance.fullyQualifiedDnsName = fullyQualifiedDnsNameInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, dataElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                dataInstance.state = stateInstance;
              }
              
              var updatedTimeElement = js2xml.getElement(responseDoc, dataElement, 'UPDATEDTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2014/05/MANAGEMENT');
              if (updatedTimeElement !== null && updatedTimeElement !== undefined) {
                var updatedTimeInstance = updatedTimeElement;
                dataInstance.updatedTime = updatedTimeInstance;
              }
            }
            
            var errorElement = js2xml.getElement(responseDoc, passthroughResponseElement, 'ERROR', 'HTTP://SCHEMAS.MICROSOFT.COM/HDINSIGHT/2013/05/MANAGEMENT');
            if (errorElement !== null && errorElement !== undefined) {
              var errorInstance = errorElement;
              passthroughResponseInstance.error = errorInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Clusters operation lists the storage accounts available under the
   * current subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/ee460787.aspx for
   * more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/cloudservices';
    var queryParameters = [];
    queryParameters.push('resourceProviderNamespace=hdinsight');
    queryParameters.push('resourceType=clusters');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-08-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { cloudService: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var cloudServicesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'CLOUDSERVICES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (cloudServicesSequenceElement !== null && cloudServicesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, cloudServicesSequenceElement, 'CLOUDSERVICE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var cloudServicesElement = js2xml.getElements(responseDoc, cloudServicesSequenceElement, 'CLOUDSERVICE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var cloudServiceInstance = { resources: [] };
              result.cloudService.push(cloudServiceInstance);
              
              var nameElement = js2xml.getElement(responseDoc, cloudServicesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                cloudServiceInstance.name = nameInstance;
              }
              
              var labelElement = js2xml.getElement(responseDoc, cloudServicesElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (labelElement !== null && labelElement !== undefined) {
                var labelInstance = labelElement;
                cloudServiceInstance.label = labelInstance;
              }
              
              var descriptionElement = js2xml.getElement(responseDoc, cloudServicesElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (descriptionElement !== null && descriptionElement !== undefined) {
                var descriptionInstance = descriptionElement;
                cloudServiceInstance.description = descriptionInstance;
              }
              
              var geoRegionElement = js2xml.getElement(responseDoc, cloudServicesElement, 'GEOREGION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (geoRegionElement !== null && geoRegionElement !== undefined) {
                var geoRegionInstance = geoRegionElement;
                cloudServiceInstance.geoRegion = geoRegionInstance;
              }
              
              var resourcesSequenceElement = js2xml.getElement(responseDoc, cloudServicesElement, 'RESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (resourcesSequenceElement !== null && resourcesSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, resourcesSequenceElement, 'RESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var resourcesElement = js2xml.getElements(responseDoc, resourcesSequenceElement, 'RESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  var resourceInstance = { outputItems: [] };
                  cloudServiceInstance.resources.push(resourceInstance);
                  
                  var resourceProviderNamespaceElement = js2xml.getElement(responseDoc, resourcesElement, 'RESOURCEPROVIDERNAMESPACE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (resourceProviderNamespaceElement !== null && resourceProviderNamespaceElement !== undefined) {
                    var resourceProviderNamespaceInstance = resourceProviderNamespaceElement;
                    resourceInstance.resourceProviderNamespace = resourceProviderNamespaceInstance;
                  }
                  
                  var typeElement = js2xml.getElement(responseDoc, resourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (typeElement !== null && typeElement !== undefined) {
                    var typeInstance = typeElement;
                    resourceInstance.type = typeInstance;
                  }
                  
                  var nameElement2 = js2xml.getElement(responseDoc, resourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (nameElement2 !== null && nameElement2 !== undefined) {
                    var nameInstance2 = nameElement2;
                    resourceInstance.name = nameInstance2;
                  }
                  
                  var planElement = js2xml.getElement(responseDoc, resourcesElement, 'PLAN', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (planElement !== null && planElement !== undefined) {
                    var planInstance = planElement;
                    resourceInstance.plan = planInstance;
                  }
                  
                  var schemaVersionElement = js2xml.getElement(responseDoc, resourcesElement, 'SCHEMAVERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (schemaVersionElement !== null && schemaVersionElement !== undefined && schemaVersionElement.length !== 0) {
                    var schemaVersionInstance = parseFloat(schemaVersionElement, 10);
                    resourceInstance.schemaVersion = schemaVersionInstance;
                  }
                  
                  var eTagElement = js2xml.getElement(responseDoc, resourcesElement, 'ETAG', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (eTagElement !== null && eTagElement !== undefined) {
                    var eTagInstance = eTagElement;
                    resourceInstance.eTag = eTagInstance;
                  }
                  
                  var stateElement = js2xml.getElement(responseDoc, resourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (stateElement !== null && stateElement !== undefined) {
                    var stateInstance = stateElement;
                    resourceInstance.state = stateInstance;
                  }
                  
                  var subStateElement = js2xml.getElement(responseDoc, resourcesElement, 'SUBSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (subStateElement !== null && subStateElement !== undefined) {
                    var subStateInstance = subStateElement;
                    resourceInstance.subState = subStateInstance;
                  }
                  
                  var intrinsicSettingsElement = js2xml.getElement(responseDoc, resourcesElement, 'INTRINSICSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (intrinsicSettingsElement !== null && intrinsicSettingsElement !== undefined) {
                    var intrinsicSettingsInstance = {};
                    resourceInstance.intrinsicSettings = intrinsicSettingsInstance;
                    
                    var arrayOfOutputItemElement = js2xml.getElement(responseDoc, intrinsicSettingsElement, 'ARRAYOFOUTPUTITEM', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (arrayOfOutputItemElement !== null && arrayOfOutputItemElement !== undefined) {
                      var arrayOfOutputItemInstance = {};
                      intrinsicSettingsInstance.arrayOfOutputItem = arrayOfOutputItemInstance;
                      
                      var outputItemElement = js2xml.getElement(responseDoc, arrayOfOutputItemElement, 'OUTPUTITEM', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                      if (outputItemElement !== null && outputItemElement !== undefined) {
                        var outputItemInstance = {};
                        arrayOfOutputItemInstance.outputItem = outputItemInstance;
                        
                        var keyElement = js2xml.getElement(responseDoc, outputItemElement, 'KEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                        if (keyElement !== null && keyElement !== undefined) {
                          var keyInstance = keyElement;
                          outputItemInstance.key = keyInstance;
                        }
                        
                        var valueElement = js2xml.getElement(responseDoc, outputItemElement, 'VALUE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                        if (valueElement !== null && valueElement !== undefined) {
                          var valueInstance = valueElement;
                          outputItemInstance.value = valueInstance;
                        }
                      }
                    }
                  }
                  
                  var outputItemsSequenceElement = js2xml.getElement(responseDoc, resourcesElement, 'OUTPUTITEMS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (outputItemsSequenceElement !== null && outputItemsSequenceElement !== undefined) {
                    for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, outputItemsSequenceElement, 'OUTPUTITEM', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                      var outputItemsElement = js2xml.getElements(responseDoc, outputItemsSequenceElement, 'OUTPUTITEM', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                      var outputItemInstance2 = {};
                      resourceInstance.outputItems.push(outputItemInstance2);
                      
                      var keyElement2 = js2xml.getElement(responseDoc, outputItemsElement, 'KEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                      if (keyElement2 !== null && keyElement2 !== undefined) {
                        var keyInstance2 = keyElement2;
                        outputItemInstance2.key = keyInstance2;
                      }
                      
                      var valueElement2 = js2xml.getElement(responseDoc, outputItemsElement, 'VALUE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                      if (valueElement2 !== null && valueElement2 !== undefined) {
                        var valueInstance2 = valueElement2;
                        outputItemInstance2.value = valueInstance2;
                      }
                    }
                  }
                  
                  var clusterOperationStatusElement = js2xml.getElement(responseDoc, resourcesElement, 'CLUSTEROPERATIONSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (clusterOperationStatusElement !== null && clusterOperationStatusElement !== undefined) {
                    var clusterOperationStatusInstance = {};
                    resourceInstance.clusterOperationStatus = clusterOperationStatusInstance;
                    
                    var typeElement2 = js2xml.getElement(responseDoc, clusterOperationStatusElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (typeElement2 !== null && typeElement2 !== undefined) {
                      var typeInstance2 = typeElement2;
                      clusterOperationStatusInstance.type = typeInstance2;
                    }
                    
                    var resultElement = js2xml.getElement(responseDoc, clusterOperationStatusElement, 'RESULT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (resultElement !== null && resultElement !== undefined) {
                      var resultInstance = resultElement;
                      clusterOperationStatusInstance.result = resultInstance;
                    }
                  }
                  
                  var labelElement2 = js2xml.getElement(responseDoc, resourcesElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (labelElement2 !== null && labelElement2 !== undefined) {
                    var labelInstance2 = labelElement2;
                    resourceInstance.label = labelInstance2;
                  }
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  return ClusterOperations;
})();
