/* 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 Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;

var HDInsightManagementClient = ( /** @lends HDInsightManagementClient */ function() {
  /**
   * @class
   * The HDInsight Management Client.
   * Initializes a new instance of the HDInsightManagementClient class.
   * @constructor
   * 
   * @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 HDInsightManagementClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    HDInsightManagementClient['super_'].call(this, credentials, filters);
    
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://management.azure.com';
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = '2015-03-01-preview';
    }
    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.clusters = new ClusterOperations(this);
  }
  
  util.inherits(HDInsightManagementClient, 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} operationStatusLink Location value returned by the Begin
   * operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  HDInsightManagementClient.prototype.getLongRunningOperationStatus = function(operationStatusLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (operationStatusLink === null || operationStatusLink === undefined) {
      return callback(new Error('operationStatusLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + operationStatusLink;
    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'] = '2015-03-01-preview';
    
    // 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 responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var statusValue = responseDoc['status'];
          if (statusValue !== null && statusValue !== undefined) {
            var statusInstance = statusValue;
            result.state = statusInstance;
          }
          
          var errorValue = responseDoc['error'];
          if (errorValue !== null && errorValue !== undefined) {
            var errorInstance = {};
            result.errorInfo = errorInstance;
            
            var codeValue = errorValue['code'];
            if (codeValue !== null && codeValue !== undefined) {
              var codeInstance = codeValue;
              errorInstance.code = codeInstance;
            }
            
            var messageValue = errorValue['message'];
            if (messageValue !== null && messageValue !== undefined) {
              var messageInstance = messageValue;
              errorInstance.message = messageInstance;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return HDInsightManagementClient;
})();
exports.HDInsightManagementClient = HDInsightManagementClient;

var ClusterOperations = ( /** @lends ClusterOperations */ function() {
  /**
   * @class
   * Contains all the cluster operations.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [HDInsightManagementClient] {@link
   * HDInsightManagementClient~HDInsightManagementClient}.
   * See [clusters] {@link
   * HDInsightManagementClient~HDInsightManagementClient#clusters}.
   * Initializes a new instance of the ClusterOperations class.
   * @constructor
   * 
   * @param {HDInsightManagementClient} client Reference to the service client.
   */
  function ClusterOperations(client) {
    this.client = client;
  }
  
  /**
   * Begins configuring the HTTP settings on the specified cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {HttpSettingsParameters} httpSettingsParameters The name of the
   * resource group.
   * 
   * @param {boolean} httpSettingsParameters.httpUserEnabled Gets or sets the
   * whether or not HTTP is enabled.
   * 
   * @param {string} [httpSettingsParameters.httpUsername] Gets or sets the
   * http username.
   * 
   * @param {string} [httpSettingsParameters.httpPassword] Gets or sets the
   * http user password.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.beginConfiguringHttpSettings = function(resourceGroupName, clusterName, httpSettingsParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (httpSettingsParameters === null || httpSettingsParameters === undefined) {
      return callback(new Error('httpSettingsParameters cannot be null.'));
    }
    if (httpSettingsParameters.httpUserEnabled === null || httpSettingsParameters.httpUserEnabled === undefined) {
      return callback(new Error('httpSettingsParameters.httpUserEnabled cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/configurations/gateway';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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 = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var httpSettingsParametersValue = {};
    requestDoc = httpSettingsParametersValue;
    
    httpSettingsParametersValue['restAuthCredential.isEnabled'] = httpSettingsParameters.httpUserEnabled;
    
    if (httpSettingsParameters.httpUsername !== null && httpSettingsParameters.httpUsername !== undefined) {
      httpSettingsParametersValue['restAuthCredential.username'] = httpSettingsParameters.httpUsername;
    }
    
    if (httpSettingsParameters.httpPassword !== null && httpSettingsParameters.httpPassword !== undefined) {
      httpSettingsParametersValue['restAuthCredential.password'] = httpSettingsParameters.httpPassword;
    }
    
    requestContent = JSON.stringify(requestDoc);
    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 !== 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.operationStatusLink = response.headers['azure-asyncoperation'];
      result.retryAfter = parseInt(response.headers['retryafter'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Begins configuring the RDP settings on the specified cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {RDPSettingsParameters} rdpParameters The OS profile for RDP.
   * 
   * @param {OsProfile} rdpParameters.osProfile Gets or sets the definition of
   * a data factory gateway to be created or updated.
   * 
   * @param {WindowsOperatingSystemProfile}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile] Gets or sets the
   * Windows OS profile.
   * 
   * @param {RdpSettings}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings] Gets
   * or sets the RDP settings.
   * 
   * @param {string}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.userName]
   * Gets or sets the username for the RDP user.
   * 
   * @param {string}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.password]
   * Gets or sets the password for the RDP user.
   * 
   * @param {date}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.expiryDate]
   * Gets or sets the RDP expiry date.
   * 
   * @param {LinuxOperatingSystemProfile}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile] Gets or sets the
   * Linux OS profile.
   * 
   * @param {string}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile.userName] Gets or
   * sets the username.
   * 
   * @param {string}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile.password] Gets or
   * sets the password.
   * 
   * @param {SshProfile}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile] Gets or
   * sets the SSH profile.
   * 
   * @param {array}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys]
   * Gets or sets the list of SSH public keys.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.beginConfiguringRdpSettings = function(resourceGroupName, clusterName, rdpParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (rdpParameters === null || rdpParameters === undefined) {
      return callback(new Error('rdpParameters cannot be null.'));
    }
    if (rdpParameters.osProfile === null || rdpParameters.osProfile === undefined) {
      return callback(new Error('rdpParameters.osProfile cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/';
    url2 = url2 + 'clusters';
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/changerdpsetting';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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 = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var rDPSettingsParametersValue = {};
    requestDoc = rDPSettingsParametersValue;
    
    var osProfileValue = {};
    rDPSettingsParametersValue['osProfile'] = osProfileValue;
    
    if (rdpParameters.osProfile.windowsOperatingSystemProfile !== null && rdpParameters.osProfile.windowsOperatingSystemProfile !== undefined) {
      var windowsOperatingSystemProfileValue = {};
      osProfileValue['windowsOperatingSystemProfile'] = windowsOperatingSystemProfileValue;
      
      if (rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings !== null && rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings !== undefined) {
        var rdpSettingsValue = {};
        windowsOperatingSystemProfileValue['rdpSettings'] = rdpSettingsValue;
        
        if (rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.userName !== null && rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.userName !== undefined) {
          rdpSettingsValue['username'] = rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.userName;
        }
        
        if (rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.password !== null && rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.password !== undefined) {
          rdpSettingsValue['password'] = rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.password;
        }
        
        if (rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.expiryDate !== null && rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.expiryDate !== undefined) {
          rdpSettingsValue['expiryDate'] = rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.expiryDate;
        }
      }
    }
    
    if (rdpParameters.osProfile.linuxOperatingSystemProfile !== null && rdpParameters.osProfile.linuxOperatingSystemProfile !== undefined) {
      var linuxOperatingSystemProfileValue = {};
      osProfileValue['linuxOperatingSystemProfile'] = linuxOperatingSystemProfileValue;
      
      if (rdpParameters.osProfile.linuxOperatingSystemProfile.userName !== null && rdpParameters.osProfile.linuxOperatingSystemProfile.userName !== undefined) {
        linuxOperatingSystemProfileValue['username'] = rdpParameters.osProfile.linuxOperatingSystemProfile.userName;
      }
      
      if (rdpParameters.osProfile.linuxOperatingSystemProfile.password !== null && rdpParameters.osProfile.linuxOperatingSystemProfile.password !== undefined) {
        linuxOperatingSystemProfileValue['password'] = rdpParameters.osProfile.linuxOperatingSystemProfile.password;
      }
      
      if (rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile !== null && rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile !== undefined) {
        var sshProfileValue = {};
        linuxOperatingSystemProfileValue['sshProfile'] = sshProfileValue;
        
        if (rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys !== null && rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys !== undefined) {
          var publicKeysArray = [];
          for (var loweredIndex1 = 0; loweredIndex1 < rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys.length; loweredIndex1 = loweredIndex1 + 1) {
            var publicKeysItem = rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys[loweredIndex1];
            var sshPublicKeyValue = {};
            publicKeysArray.push(sshPublicKeyValue);
            
            if (publicKeysItem.certificateData !== null && publicKeysItem.certificateData !== undefined) {
              sshPublicKeyValue['certificateData'] = publicKeysItem.certificateData;
            }
          }
          sshProfileValue['publicKeys'] = publicKeysArray;
        }
      }
    }
    
    requestContent = JSON.stringify(requestDoc);
    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 !== 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.operationStatusLink = response.headers['azure-asyncoperation'];
      result.retryAfter = parseInt(response.headers['retryafter'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Begins creating a new HDInsight cluster with the specified parameters.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {ClusterCreateParametersExtended} clusterCreateParameters The
   * cluster create request.
   * 
   * @param {string} [clusterCreateParameters.location] Gets or sets the
   * location of the cluster.
   * 
   * @param {object} [clusterCreateParameters.tags] Gets or sets the resource
   * tags.
   * 
   * @param {ClusterCreateProperties} [clusterCreateParameters.properties] Gets
   * or sets the cluster create parameters.
   * 
   * @param {string} [clusterCreateParameters.properties.clusterVersion] Gets
   * or sets the version of the cluster.
   * 
   * @param {OSType} [clusterCreateParameters.properties.operatingSystemType]
   * Gets or sets the type of operating system.
   * 
   * @param {ClusterDefinition}
   * [clusterCreateParameters.properties.clusterDefinition] Gets or sets the
   * cluster definition.
   * 
   * @param {string}
   * [clusterCreateParameters.properties.clusterDefinition.blueprintUri] Gets
   * or sets the link to the blueprint.
   * 
   * @param {string}
   * [clusterCreateParameters.properties.clusterDefinition.clusterType] Gets
   * or sets the type of cluster.
   * 
   * @param {string}
   * [clusterCreateParameters.properties.clusterDefinition.configurations]
   * Gets or sets the cluster configurations.
   * 
   * @param {Tier} [clusterCreateParameters.properties.clusterTier] Gets or
   * sets the cluster tier.
   * 
   * @param {ComputeProfile}
   * [clusterCreateParameters.properties.computeProfile] Gets or sets the
   * compute profile.
   * 
   * @param {array} [clusterCreateParameters.properties.computeProfile.roles]
   * Gets or sets the list of roles in the cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.beginCreating = function(resourceGroupName, clusterName, clusterCreateParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (clusterCreateParameters === null || clusterCreateParameters === undefined) {
      return callback(new Error('clusterCreateParameters cannot be null.'));
    }
    if (clusterCreateParameters.properties !== null && clusterCreateParameters.properties !== undefined) {
      if (clusterCreateParameters.properties.computeProfile !== null && clusterCreateParameters.properties.computeProfile !== undefined) {
        if (clusterCreateParameters.properties.computeProfile.roles !== null && clusterCreateParameters.properties.computeProfile.roles !== undefined) {
          for (var loweredIndex1 = 0; loweredIndex1 < clusterCreateParameters.properties.computeProfile.roles.length; loweredIndex1 = loweredIndex1 + 1) {
            var rolesParameterItem = clusterCreateParameters.properties.computeProfile.roles[loweredIndex1];
            if (rolesParameterItem.scriptActions !== null && rolesParameterItem.scriptActions !== undefined) {
              for (var loweredIndex2 = 0; loweredIndex2 < rolesParameterItem.scriptActions.length; loweredIndex2 = loweredIndex2 + 1) {
                var scriptActionsParameterItem = rolesParameterItem.scriptActions[loweredIndex2];
                if (scriptActionsParameterItem.name === null || scriptActionsParameterItem.name === undefined) {
                  return callback(new Error('clusterCreateParameters.properties.computeProfile.roles.scriptActions.name cannot be null.'));
                }
                if (scriptActionsParameterItem.parameters === null || scriptActionsParameterItem.parameters === undefined) {
                  return callback(new Error('clusterCreateParameters.properties.computeProfile.roles.scriptActions.parameters cannot be null.'));
                }
                if (scriptActionsParameterItem.uri === null || scriptActionsParameterItem.uri === undefined) {
                  return callback(new Error('clusterCreateParameters.properties.computeProfile.roles.scriptActions.uri cannot be null.'));
                }
              }
            }
          }
        }
      }
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/';
    url2 = url2 + 'clusters';
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(clusterName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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 = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var clusterCreateParametersExtendedValue = {};
    requestDoc = clusterCreateParametersExtendedValue;
    
    if (clusterCreateParameters.location !== null && clusterCreateParameters.location !== undefined) {
      clusterCreateParametersExtendedValue['location'] = clusterCreateParameters.location;
    }
    
    if (clusterCreateParameters.tags !== null && clusterCreateParameters.tags !== undefined) {
      var tagsDictionary = {};
      for (var tagsKey in clusterCreateParameters.tags) {
        var tagsValue = clusterCreateParameters.tags[tagsKey];
        tagsDictionary[tagsKey] = tagsValue;
      }
      clusterCreateParametersExtendedValue['tags'] = tagsDictionary;
    }
    
    if (clusterCreateParameters.properties !== null && clusterCreateParameters.properties !== undefined) {
      var propertiesValue = {};
      clusterCreateParametersExtendedValue['properties'] = propertiesValue;
      
      if (clusterCreateParameters.properties.clusterVersion !== null && clusterCreateParameters.properties.clusterVersion !== undefined) {
        propertiesValue['clusterVersion'] = clusterCreateParameters.properties.clusterVersion;
      }
      
      if (clusterCreateParameters.properties.operatingSystemType !== null && clusterCreateParameters.properties.operatingSystemType !== undefined) {
        propertiesValue['osType'] = clusterCreateParameters.properties.operatingSystemType !== null && clusterCreateParameters.properties.operatingSystemType !== undefined ? clusterCreateParameters.properties.operatingSystemType.toString() : 'Windows';
      }
      
      if (clusterCreateParameters.properties.clusterDefinition !== null && clusterCreateParameters.properties.clusterDefinition !== undefined) {
        var clusterDefinitionValue = {};
        propertiesValue['clusterDefinition'] = clusterDefinitionValue;
        
        if (clusterCreateParameters.properties.clusterDefinition.blueprintUri !== null && clusterCreateParameters.properties.clusterDefinition.blueprintUri !== undefined) {
          clusterDefinitionValue['blueprint'] = clusterCreateParameters.properties.clusterDefinition.blueprintUri;
        }
        
        if (clusterCreateParameters.properties.clusterDefinition.clusterType !== null && clusterCreateParameters.properties.clusterDefinition.clusterType !== undefined) {
          clusterDefinitionValue['kind'] = clusterCreateParameters.properties.clusterDefinition.clusterType;
        }
        
        if (clusterCreateParameters.properties.clusterDefinition.configurations !== null && clusterCreateParameters.properties.clusterDefinition.configurations !== undefined) {
          clusterDefinitionValue['configurations'] = clusterCreateParameters.properties.clusterDefinition.configurations;
        }
      }
      
      if (clusterCreateParameters.properties.clusterTier !== null && clusterCreateParameters.properties.clusterTier !== undefined) {
        propertiesValue['tier'] = clusterCreateParameters.properties.clusterTier !== null && clusterCreateParameters.properties.clusterTier !== undefined ? clusterCreateParameters.properties.clusterTier.toString() : 'Standard';
      }
      
      if (clusterCreateParameters.properties.computeProfile !== null && clusterCreateParameters.properties.computeProfile !== undefined) {
        var computeProfileValue = {};
        propertiesValue['computeProfile'] = computeProfileValue;
        
        if (clusterCreateParameters.properties.computeProfile.roles !== null && clusterCreateParameters.properties.computeProfile.roles !== undefined) {
          var rolesArray = [];
          for (var loweredIndex3 = 0; loweredIndex3 < clusterCreateParameters.properties.computeProfile.roles.length; loweredIndex3 = loweredIndex3 + 1) {
            var rolesItem = clusterCreateParameters.properties.computeProfile.roles[loweredIndex3];
            var roleValue = {};
            rolesArray.push(roleValue);
            
            if (rolesItem.name !== null && rolesItem.name !== undefined) {
              roleValue['name'] = rolesItem.name;
            }
            
            if (rolesItem.targetInstanceCount !== null && rolesItem.targetInstanceCount !== undefined) {
              roleValue['targetInstanceCount'] = rolesItem.targetInstanceCount;
            }
            
            if (rolesItem.hardwareProfile !== null && rolesItem.hardwareProfile !== undefined) {
              var hardwareProfileValue = {};
              roleValue['hardwareProfile'] = hardwareProfileValue;
              
              if (rolesItem.hardwareProfile.vmSize !== null && rolesItem.hardwareProfile.vmSize !== undefined) {
                hardwareProfileValue['vmSize'] = rolesItem.hardwareProfile.vmSize;
              }
            }
            
            if (rolesItem.osProfile !== null && rolesItem.osProfile !== undefined) {
              var osProfileValue = {};
              roleValue['osProfile'] = osProfileValue;
              
              if (rolesItem.osProfile.windowsOperatingSystemProfile !== null && rolesItem.osProfile.windowsOperatingSystemProfile !== undefined) {
                var windowsOperatingSystemProfileValue = {};
                osProfileValue['windowsOperatingSystemProfile'] = windowsOperatingSystemProfileValue;
                
                if (rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings !== null && rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings !== undefined) {
                  var rdpSettingsValue = {};
                  windowsOperatingSystemProfileValue['rdpSettings'] = rdpSettingsValue;
                  
                  if (rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.userName !== null && rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.userName !== undefined) {
                    rdpSettingsValue['username'] = rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.userName;
                  }
                  
                  if (rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.password !== null && rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.password !== undefined) {
                    rdpSettingsValue['password'] = rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.password;
                  }
                  
                  if (rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.expiryDate !== null && rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.expiryDate !== undefined) {
                    rdpSettingsValue['expiryDate'] = rolesItem.osProfile.windowsOperatingSystemProfile.rdpSettings.expiryDate;
                  }
                }
              }
              
              if (rolesItem.osProfile.linuxOperatingSystemProfile !== null && rolesItem.osProfile.linuxOperatingSystemProfile !== undefined) {
                var linuxOperatingSystemProfileValue = {};
                osProfileValue['linuxOperatingSystemProfile'] = linuxOperatingSystemProfileValue;
                
                if (rolesItem.osProfile.linuxOperatingSystemProfile.userName !== null && rolesItem.osProfile.linuxOperatingSystemProfile.userName !== undefined) {
                  linuxOperatingSystemProfileValue['username'] = rolesItem.osProfile.linuxOperatingSystemProfile.userName;
                }
                
                if (rolesItem.osProfile.linuxOperatingSystemProfile.password !== null && rolesItem.osProfile.linuxOperatingSystemProfile.password !== undefined) {
                  linuxOperatingSystemProfileValue['password'] = rolesItem.osProfile.linuxOperatingSystemProfile.password;
                }
                
                if (rolesItem.osProfile.linuxOperatingSystemProfile.sshProfile !== null && rolesItem.osProfile.linuxOperatingSystemProfile.sshProfile !== undefined) {
                  var sshProfileValue = {};
                  linuxOperatingSystemProfileValue['sshProfile'] = sshProfileValue;
                  
                  if (rolesItem.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys !== null && rolesItem.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys !== undefined) {
                    var publicKeysArray = [];
                    for (var loweredIndex4 = 0; loweredIndex4 < rolesItem.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys.length; loweredIndex4 = loweredIndex4 + 1) {
                      var publicKeysItem = rolesItem.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys[loweredIndex4];
                      var sshPublicKeyValue = {};
                      publicKeysArray.push(sshPublicKeyValue);
                      
                      if (publicKeysItem.certificateData !== null && publicKeysItem.certificateData !== undefined) {
                        sshPublicKeyValue['certificateData'] = publicKeysItem.certificateData;
                      }
                    }
                    sshProfileValue['publicKeys'] = publicKeysArray;
                  }
                }
              }
            }
            
            if (rolesItem.virtualNetworkProfile !== null && rolesItem.virtualNetworkProfile !== undefined) {
              var virtualNetworkProfileValue = {};
              roleValue['virtualNetworkProfile'] = virtualNetworkProfileValue;
              
              if (rolesItem.virtualNetworkProfile.id !== null && rolesItem.virtualNetworkProfile.id !== undefined) {
                virtualNetworkProfileValue['id'] = rolesItem.virtualNetworkProfile.id;
              }
              
              if (rolesItem.virtualNetworkProfile.subnetName !== null && rolesItem.virtualNetworkProfile.subnetName !== undefined) {
                virtualNetworkProfileValue['subnet'] = rolesItem.virtualNetworkProfile.subnetName;
              }
            }
            
            if (rolesItem.scriptActions !== null && rolesItem.scriptActions !== undefined) {
              var scriptActionsArray = [];
              for (var loweredIndex5 = 0; loweredIndex5 < rolesItem.scriptActions.length; loweredIndex5 = loweredIndex5 + 1) {
                var scriptActionsItem = rolesItem.scriptActions[loweredIndex5];
                var scriptActionValue = {};
                scriptActionsArray.push(scriptActionValue);
                
                scriptActionValue['name'] = scriptActionsItem.name;
                
                scriptActionValue['uri'] = scriptActionsItem.uri;
                
                scriptActionValue['parameters'] = scriptActionsItem.parameters;
              }
              roleValue['scriptActions'] = scriptActionsArray;
            }
          }
          computeProfileValue['roles'] = rolesArray;
        }
      }
    }
    
    requestContent = JSON.stringify(requestDoc);
    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 !== 412) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 412) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var clusterInstance = { tags: {} };
          result.cluster = clusterInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            clusterInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            clusterInstance.name = nameInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            clusterInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            clusterInstance.location = locationInstance;
          }
          
          var etagValue = responseDoc['etag'];
          if (etagValue !== null && etagValue !== undefined) {
            var etagInstance = etagValue;
            clusterInstance.eTag = etagInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey2 = property;
              var tagsValue2 = tagsSequenceElement[property];
              clusterInstance.tags[tagsKey2] = tagsValue2;
            }
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var propertiesInstance = { connectivityEndpoints: [], errorInfos: [] };
            clusterInstance.properties = propertiesInstance;
            
            var clusterVersionValue = propertiesValue2['clusterVersion'];
            if (clusterVersionValue !== null && clusterVersionValue !== undefined) {
              var clusterVersionInstance = clusterVersionValue;
              propertiesInstance.clusterVersion = clusterVersionInstance;
            }
            
            var osTypeValue = propertiesValue2['osType'];
            if (osTypeValue !== null && osTypeValue !== undefined) {
              var osTypeInstance = osTypeValue;
              propertiesInstance.operatingSystemType = osTypeInstance;
            }
            
            var tierValue = propertiesValue2['tier'];
            if (tierValue !== null && tierValue !== undefined) {
              var tierInstance = tierValue;
              propertiesInstance.clusterTier = tierInstance;
            }
            
            var clusterDefinitionValue2 = propertiesValue2['clusterDefinition'];
            if (clusterDefinitionValue2 !== null && clusterDefinitionValue2 !== undefined) {
              var clusterDefinitionInstance = {};
              propertiesInstance.clusterDefinition = clusterDefinitionInstance;
              
              var blueprintValue = clusterDefinitionValue2['blueprint'];
              if (blueprintValue !== null && blueprintValue !== undefined) {
                var blueprintInstance = blueprintValue;
                clusterDefinitionInstance.blueprintUri = blueprintInstance;
              }
              
              var kindValue = clusterDefinitionValue2['kind'];
              if (kindValue !== null && kindValue !== undefined) {
                var kindInstance = kindValue;
                clusterDefinitionInstance.clusterType = kindInstance;
              }
              
              var configurationsValue = clusterDefinitionValue2['configurations'];
              if (configurationsValue !== null && configurationsValue !== undefined) {
                var configurationsInstance = configurationsValue;
                clusterDefinitionInstance.configurations = configurationsInstance;
              }
            }
            
            var computeProfileValue2 = propertiesValue2['computeProfile'];
            if (computeProfileValue2 !== null && computeProfileValue2 !== undefined) {
              var computeProfileInstance = { roles: [] };
              propertiesInstance.computeProfile = computeProfileInstance;
              
              var rolesArray2 = computeProfileValue2['roles'];
              if (rolesArray2 !== null && rolesArray2 !== undefined) {
                for (var loweredIndex6 = 0; loweredIndex6 < rolesArray2.length; loweredIndex6 = loweredIndex6 + 1) {
                  var rolesValue = rolesArray2[loweredIndex6];
                  var roleInstance = { scriptActions: [] };
                  computeProfileInstance.roles.push(roleInstance);
                  
                  var nameValue2 = rolesValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    roleInstance.name = nameInstance2;
                  }
                  
                  var targetInstanceCountValue = rolesValue['targetInstanceCount'];
                  if (targetInstanceCountValue !== null && targetInstanceCountValue !== undefined) {
                    var targetInstanceCountInstance = targetInstanceCountValue;
                    roleInstance.targetInstanceCount = targetInstanceCountInstance;
                  }
                  
                  var hardwareProfileValue2 = rolesValue['hardwareProfile'];
                  if (hardwareProfileValue2 !== null && hardwareProfileValue2 !== undefined) {
                    var hardwareProfileInstance = {};
                    roleInstance.hardwareProfile = hardwareProfileInstance;
                    
                    var vmSizeValue = hardwareProfileValue2['vmSize'];
                    if (vmSizeValue !== null && vmSizeValue !== undefined) {
                      var vmSizeInstance = vmSizeValue;
                      hardwareProfileInstance.vmSize = vmSizeInstance;
                    }
                  }
                  
                  var osProfileValue2 = rolesValue['osProfile'];
                  if (osProfileValue2 !== null && osProfileValue2 !== undefined) {
                    var osProfileInstance = {};
                    roleInstance.osProfile = osProfileInstance;
                    
                    var windowsOperatingSystemProfileValue2 = osProfileValue2['windowsOperatingSystemProfile'];
                    if (windowsOperatingSystemProfileValue2 !== null && windowsOperatingSystemProfileValue2 !== undefined) {
                      var windowsOperatingSystemProfileInstance = {};
                      osProfileInstance.windowsOperatingSystemProfile = windowsOperatingSystemProfileInstance;
                      
                      var rdpSettingsValue2 = windowsOperatingSystemProfileValue2['rdpSettings'];
                      if (rdpSettingsValue2 !== null && rdpSettingsValue2 !== undefined) {
                        var rdpSettingsInstance = {};
                        windowsOperatingSystemProfileInstance.rdpSettings = rdpSettingsInstance;
                        
                        var usernameValue = rdpSettingsValue2['username'];
                        if (usernameValue !== null && usernameValue !== undefined) {
                          var usernameInstance = usernameValue;
                          rdpSettingsInstance.userName = usernameInstance;
                        }
                        
                        var passwordValue = rdpSettingsValue2['password'];
                        if (passwordValue !== null && passwordValue !== undefined) {
                          var passwordInstance = passwordValue;
                          rdpSettingsInstance.password = passwordInstance;
                        }
                        
                        var expiryDateValue = rdpSettingsValue2['expiryDate'];
                        if (expiryDateValue !== null && expiryDateValue !== undefined) {
                          var expiryDateInstance = expiryDateValue;
                          rdpSettingsInstance.expiryDate = expiryDateInstance;
                        }
                      }
                    }
                    
                    var linuxOperatingSystemProfileValue2 = osProfileValue2['linuxOperatingSystemProfile'];
                    if (linuxOperatingSystemProfileValue2 !== null && linuxOperatingSystemProfileValue2 !== undefined) {
                      var linuxOperatingSystemProfileInstance = {};
                      osProfileInstance.linuxOperatingSystemProfile = linuxOperatingSystemProfileInstance;
                      
                      var usernameValue2 = linuxOperatingSystemProfileValue2['username'];
                      if (usernameValue2 !== null && usernameValue2 !== undefined) {
                        var usernameInstance2 = usernameValue2;
                        linuxOperatingSystemProfileInstance.userName = usernameInstance2;
                      }
                      
                      var passwordValue2 = linuxOperatingSystemProfileValue2['password'];
                      if (passwordValue2 !== null && passwordValue2 !== undefined) {
                        var passwordInstance2 = passwordValue2;
                        linuxOperatingSystemProfileInstance.password = passwordInstance2;
                      }
                      
                      var sshProfileValue2 = linuxOperatingSystemProfileValue2['sshProfile'];
                      if (sshProfileValue2 !== null && sshProfileValue2 !== undefined) {
                        var sshProfileInstance = { sshPublicKeys: [] };
                        linuxOperatingSystemProfileInstance.sshProfile = sshProfileInstance;
                        
                        var publicKeysArray2 = sshProfileValue2['publicKeys'];
                        if (publicKeysArray2 !== null && publicKeysArray2 !== undefined) {
                          for (var loweredIndex7 = 0; loweredIndex7 < publicKeysArray2.length; loweredIndex7 = loweredIndex7 + 1) {
                            var publicKeysValue = publicKeysArray2[loweredIndex7];
                            var sshPublicKeyInstance = {};
                            sshProfileInstance.sshPublicKeys.push(sshPublicKeyInstance);
                            
                            var certificateDataValue = publicKeysValue['certificateData'];
                            if (certificateDataValue !== null && certificateDataValue !== undefined) {
                              var certificateDataInstance = certificateDataValue;
                              sshPublicKeyInstance.certificateData = certificateDataInstance;
                            }
                          }
                        }
                      }
                    }
                  }
                  
                  var virtualNetworkProfileValue2 = rolesValue['virtualNetworkProfile'];
                  if (virtualNetworkProfileValue2 !== null && virtualNetworkProfileValue2 !== undefined) {
                    var virtualNetworkProfileInstance = {};
                    roleInstance.virtualNetworkProfile = virtualNetworkProfileInstance;
                    
                    var idValue2 = virtualNetworkProfileValue2['id'];
                    if (idValue2 !== null && idValue2 !== undefined) {
                      var idInstance2 = idValue2;
                      virtualNetworkProfileInstance.id = idInstance2;
                    }
                    
                    var subnetValue = virtualNetworkProfileValue2['subnet'];
                    if (subnetValue !== null && subnetValue !== undefined) {
                      var subnetInstance = subnetValue;
                      virtualNetworkProfileInstance.subnetName = subnetInstance;
                    }
                  }
                  
                  var scriptActionsArray2 = rolesValue['scriptActions'];
                  if (scriptActionsArray2 !== null && scriptActionsArray2 !== undefined) {
                    for (var loweredIndex8 = 0; loweredIndex8 < scriptActionsArray2.length; loweredIndex8 = loweredIndex8 + 1) {
                      var scriptActionsValue = scriptActionsArray2[loweredIndex8];
                      var scriptActionInstance = {};
                      roleInstance.scriptActions.push(scriptActionInstance);
                      
                      var nameValue3 = scriptActionsValue['name'];
                      if (nameValue3 !== null && nameValue3 !== undefined) {
                        var nameInstance3 = nameValue3;
                        scriptActionInstance.name = nameInstance3;
                      }
                      
                      var uriValue = scriptActionsValue['uri'];
                      if (uriValue !== null && uriValue !== undefined) {
                        var uriInstance = uriValue;
                        scriptActionInstance.uri = uriInstance;
                      }
                      
                      var parametersValue = scriptActionsValue['parameters'];
                      if (parametersValue !== null && parametersValue !== undefined) {
                        var parametersInstance = parametersValue;
                        scriptActionInstance.parameters = parametersInstance;
                      }
                    }
                  }
                }
              }
            }
            
            var provisioningStateValue = propertiesValue2['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              propertiesInstance.provisioningState = provisioningStateInstance;
            }
            
            var createdDateValue = propertiesValue2['createdDate'];
            if (createdDateValue !== null && createdDateValue !== undefined) {
              var createdDateInstance = createdDateValue;
              propertiesInstance.createdDate = createdDateInstance;
            }
            
            var clusterStateValue = propertiesValue2['clusterState'];
            if (clusterStateValue !== null && clusterStateValue !== undefined) {
              var clusterStateInstance = clusterStateValue;
              propertiesInstance.clusterState = clusterStateInstance;
            }
            
            var quotaInfoValue = propertiesValue2['quotaInfo'];
            if (quotaInfoValue !== null && quotaInfoValue !== undefined) {
              var quotaInfoInstance = {};
              propertiesInstance.quotaInfo = quotaInfoInstance;
              
              var coresUsedValue = quotaInfoValue['coresUsed'];
              if (coresUsedValue !== null && coresUsedValue !== undefined) {
                var coresUsedInstance = coresUsedValue;
                quotaInfoInstance.coresUsed = coresUsedInstance;
              }
            }
            
            var errorsArray = propertiesValue2['errors'];
            if (errorsArray !== null && errorsArray !== undefined) {
              for (var loweredIndex9 = 0; loweredIndex9 < errorsArray.length; loweredIndex9 = loweredIndex9 + 1) {
                var errorsValue = errorsArray[loweredIndex9];
                var errorInfoInstance = {};
                propertiesInstance.errorInfos.push(errorInfoInstance);
                
                var codeValue = errorsValue['code'];
                if (codeValue !== null && codeValue !== undefined) {
                  var codeInstance = codeValue;
                  errorInfoInstance.code = codeInstance;
                }
                
                var messageValue = errorsValue['message'];
                if (messageValue !== null && messageValue !== undefined) {
                  var messageInstance = messageValue;
                  errorInfoInstance.message = messageInstance;
                }
              }
            }
            
            var connectivityEndpointsArray = propertiesValue2['connectivityEndpoints'];
            if (connectivityEndpointsArray !== null && connectivityEndpointsArray !== undefined) {
              for (var loweredIndex10 = 0; loweredIndex10 < connectivityEndpointsArray.length; loweredIndex10 = loweredIndex10 + 1) {
                var connectivityEndpointsValue = connectivityEndpointsArray[loweredIndex10];
                var connectivityEndpointInstance = {};
                propertiesInstance.connectivityEndpoints.push(connectivityEndpointInstance);
                
                var nameValue4 = connectivityEndpointsValue['name'];
                if (nameValue4 !== null && nameValue4 !== undefined) {
                  var nameInstance4 = nameValue4;
                  connectivityEndpointInstance.name = nameInstance4;
                }
                
                var protocolValue = connectivityEndpointsValue['protocol'];
                if (protocolValue !== null && protocolValue !== undefined) {
                  var protocolInstance = protocolValue;
                  connectivityEndpointInstance.protocol = protocolInstance;
                }
                
                var locationValue2 = connectivityEndpointsValue['location'];
                if (locationValue2 !== null && locationValue2 !== undefined) {
                  var locationInstance2 = locationValue2;
                  connectivityEndpointInstance.location = locationInstance2;
                }
                
                var portValue = connectivityEndpointsValue['port'];
                if (portValue !== null && portValue !== undefined) {
                  var portInstance = portValue;
                  connectivityEndpointInstance.port = portInstance;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.operationStatusLink = response.headers['x-ms-hdi-clusteruri'];
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Begins deleting the specified HDInsight cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.beginDeleting = function(resourceGroupName, clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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 = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // 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 !== 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.operationStatusLink = response.headers['azure-asyncoperation'];
      result.retryAfter = parseInt(response.headers['retryafter'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Begins executing script actions on the specified HDInsight cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {ExecuteScriptActionParameters} executeScriptActionParameters The
   * parameters for executing script actions.
   * 
   * @param {array} [executeScriptActionParameters.scriptActions] Gets or sets
   * the list of run time script actions.
   * 
   * @param {boolean} executeScriptActionParameters.persistOnSuccess Gets or
   * sets if the scripts needs to be persisted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.beginExecuteScriptActions = function(resourceGroupName, clusterName, executeScriptActionParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (executeScriptActionParameters === null || executeScriptActionParameters === undefined) {
      return callback(new Error('executeScriptActionParameters cannot be null.'));
    }
    if (executeScriptActionParameters.persistOnSuccess === null || executeScriptActionParameters.persistOnSuccess === undefined) {
      return callback(new Error('executeScriptActionParameters.persistOnSuccess cannot be null.'));
    }
    if (executeScriptActionParameters.scriptActions !== null && executeScriptActionParameters.scriptActions !== undefined) {
      for (var loweredIndex1 = 0; loweredIndex1 < executeScriptActionParameters.scriptActions.length; loweredIndex1 = loweredIndex1 + 1) {
        var scriptActionsParameterItem = executeScriptActionParameters.scriptActions[loweredIndex1];
        if (scriptActionsParameterItem.name === null || scriptActionsParameterItem.name === undefined) {
          return callback(new Error('executeScriptActionParameters.scriptActions.name cannot be null.'));
        }
        if (scriptActionsParameterItem.roles === null || scriptActionsParameterItem.roles === undefined) {
          return callback(new Error('executeScriptActionParameters.scriptActions.roles cannot be null.'));
        }
        if (scriptActionsParameterItem.uri === null || scriptActionsParameterItem.uri === undefined) {
          return callback(new Error('executeScriptActionParameters.scriptActions.uri cannot be null.'));
        }
      }
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/executeScriptActions';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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 = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var executeScriptActionParametersValue = {};
    requestDoc = executeScriptActionParametersValue;
    
    if (executeScriptActionParameters.scriptActions !== null && executeScriptActionParameters.scriptActions !== undefined) {
      var scriptActionsArray = [];
      for (var loweredIndex2 = 0; loweredIndex2 < executeScriptActionParameters.scriptActions.length; loweredIndex2 = loweredIndex2 + 1) {
        var scriptActionsItem = executeScriptActionParameters.scriptActions[loweredIndex2];
        var runtimeScriptActionValue = {};
        scriptActionsArray.push(runtimeScriptActionValue);
        
        runtimeScriptActionValue['name'] = scriptActionsItem.name;
        
        runtimeScriptActionValue['uri'] = scriptActionsItem.uri;
        
        if (scriptActionsItem.parameters !== null && scriptActionsItem.parameters !== undefined) {
          runtimeScriptActionValue['parameters'] = scriptActionsItem.parameters;
        }
        
        if (scriptActionsItem.roles !== null && scriptActionsItem.roles !== undefined) {
          var rolesArray = [];
          for (var loweredIndex3 = 0; loweredIndex3 < scriptActionsItem.roles.length; loweredIndex3 = loweredIndex3 + 1) {
            var rolesItem = scriptActionsItem.roles[loweredIndex3];
            rolesArray.push(rolesItem);
          }
          runtimeScriptActionValue['roles'] = rolesArray;
        }
        
        if (scriptActionsItem.applicationName !== null && scriptActionsItem.applicationName !== undefined) {
          runtimeScriptActionValue['applicationName'] = scriptActionsItem.applicationName;
        }
      }
      executeScriptActionParametersValue['scriptActions'] = scriptActionsArray;
    }
    
    executeScriptActionParametersValue['persistOnSuccess'] = executeScriptActionParameters.persistOnSuccess;
    
    requestContent = JSON.stringify(requestDoc);
    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 !== 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.operationStatusLink = response.headers['azure-asyncoperation'];
      result.retryAfter = parseInt(response.headers['retryafter'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Begins a resize operation on the specified HDInsight cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {ClusterResizeParameters} resizeParameters The parameters for the
   * resize operation.
   * 
   * @param {number} [resizeParameters.targetInstanceCount] Gets or sets the
   * target instance count for the operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.beginResizing = function(resourceGroupName, clusterName, resizeParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (resizeParameters === null || resizeParameters === undefined) {
      return callback(new Error('resizeParameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/roles/workernode/resize';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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 = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var clusterResizeParametersValue = {};
    requestDoc = clusterResizeParametersValue;
    
    if (resizeParameters.targetInstanceCount !== null && resizeParameters.targetInstanceCount !== undefined) {
      clusterResizeParametersValue['targetInstanceCount'] = resizeParameters.targetInstanceCount;
    }
    
    requestContent = JSON.stringify(requestDoc);
    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 !== 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.operationStatusLink = response.headers['azure-asyncoperation'];
      result.retryAfter = parseInt(response.headers['retryafter'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Configures the HTTP settings on the specified cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {HttpSettingsParameters} httpSettingsParameters The name of the
   * resource group.
   * 
   * @param {boolean} httpSettingsParameters.httpUserEnabled Gets or sets the
   * whether or not HTTP is enabled.
   * 
   * @param {string} [httpSettingsParameters.httpUsername] Gets or sets the
   * http username.
   * 
   * @param {string} [httpSettingsParameters.httpPassword] Gets or sets the
   * http user password.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.configureHttpSettings = function(resourceGroupName, clusterName, httpSettingsParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.clusters.beginConfiguringHttpSettings(resourceGroupName, clusterName, httpSettingsParameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 60;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getLongRunningOperationStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.state !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = 60;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Configures the RDP settings on the specified cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {RDPSettingsParameters} rdpParameters The OS profile for RDP. Use
   * null to turn RDP off.
   * 
   * @param {OsProfile} rdpParameters.osProfile Gets or sets the definition of
   * a data factory gateway to be created or updated.
   * 
   * @param {WindowsOperatingSystemProfile}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile] Gets or sets the
   * Windows OS profile.
   * 
   * @param {RdpSettings}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings] Gets
   * or sets the RDP settings.
   * 
   * @param {string}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.userName]
   * Gets or sets the username for the RDP user.
   * 
   * @param {string}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.password]
   * Gets or sets the password for the RDP user.
   * 
   * @param {date}
   * [rdpParameters.osProfile.windowsOperatingSystemProfile.rdpSettings.expiryDate]
   * Gets or sets the RDP expiry date.
   * 
   * @param {LinuxOperatingSystemProfile}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile] Gets or sets the
   * Linux OS profile.
   * 
   * @param {string}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile.userName] Gets or
   * sets the username.
   * 
   * @param {string}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile.password] Gets or
   * sets the password.
   * 
   * @param {SshProfile}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile] Gets or
   * sets the SSH profile.
   * 
   * @param {array}
   * [rdpParameters.osProfile.linuxOperatingSystemProfile.sshProfile.sshPublicKeys]
   * Gets or sets the list of SSH public keys.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.configureRdpSettings = function(resourceGroupName, clusterName, rdpParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.clusters.beginConfiguringRdpSettings(resourceGroupName, clusterName, rdpParameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 60;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getLongRunningOperationStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.state !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = 60;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Creates a new HDInsight cluster with the specified parameters.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {ClusterCreateParametersExtended} clusterCreateParameters The
   * cluster create request.
   * 
   * @param {string} [clusterCreateParameters.location] Gets or sets the
   * location of the cluster.
   * 
   * @param {object} [clusterCreateParameters.tags] Gets or sets the resource
   * tags.
   * 
   * @param {ClusterCreateProperties} [clusterCreateParameters.properties] Gets
   * or sets the cluster create parameters.
   * 
   * @param {string} [clusterCreateParameters.properties.clusterVersion] Gets
   * or sets the version of the cluster.
   * 
   * @param {OSType} [clusterCreateParameters.properties.operatingSystemType]
   * Gets or sets the type of operating system.
   * 
   * @param {ClusterDefinition}
   * [clusterCreateParameters.properties.clusterDefinition] Gets or sets the
   * cluster definition.
   * 
   * @param {string}
   * [clusterCreateParameters.properties.clusterDefinition.blueprintUri] Gets
   * or sets the link to the blueprint.
   * 
   * @param {string}
   * [clusterCreateParameters.properties.clusterDefinition.clusterType] Gets
   * or sets the type of cluster.
   * 
   * @param {string}
   * [clusterCreateParameters.properties.clusterDefinition.configurations]
   * Gets or sets the cluster configurations.
   * 
   * @param {Tier} [clusterCreateParameters.properties.clusterTier] Gets or
   * sets the cluster tier.
   * 
   * @param {ComputeProfile}
   * [clusterCreateParameters.properties.computeProfile] Gets or sets the
   * compute profile.
   * 
   * @param {array} [clusterCreateParameters.properties.computeProfile.roles]
   * Gets or sets the list of roles in the cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.create = function(resourceGroupName, clusterName, clusterCreateParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.clusters.beginCreating(resourceGroupName, clusterName, clusterCreateParameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 60;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.clusters.getCreateStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.cluster.properties.provisioningState !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = 60;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Deletes the specified HDInsight cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.deleteMethod = function(resourceGroupName, clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.clusters.beginDeleting(resourceGroupName, clusterName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 60;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.clusters.getDeleteStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.state !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = 60;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Deletes a given persisted script action of the cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {string} scriptName The name of the script.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.deletePersistedScript = function(resourceGroupName, clusterName, scriptName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (scriptName === null || scriptName === undefined) {
      return callback(new Error('scriptName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '//clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/scriptActions/';
    url2 = url2 + encodeURIComponent(scriptName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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 = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // 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
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Executes script actions on the specified HDInsight cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {ExecuteScriptActionParameters} executeScriptActionParameters The
   * parameters for executing script actions.
   * 
   * @param {array} [executeScriptActionParameters.scriptActions] Gets or sets
   * the list of run time script actions.
   * 
   * @param {boolean} executeScriptActionParameters.persistOnSuccess Gets or
   * sets if the scripts needs to be persisted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.executeScriptActions = function(resourceGroupName, clusterName, executeScriptActionParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.clusters.beginExecuteScriptActions(resourceGroupName, clusterName, executeScriptActionParameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 60;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getLongRunningOperationStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.state !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = 60;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Gets the specified cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.get = function(resourceGroupName, clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // 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 responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var clusterInstance = { tags: {} };
          result.cluster = clusterInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            clusterInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            clusterInstance.name = nameInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            clusterInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            clusterInstance.location = locationInstance;
          }
          
          var etagValue = responseDoc['etag'];
          if (etagValue !== null && etagValue !== undefined) {
            var etagInstance = etagValue;
            clusterInstance.eTag = etagInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey = property;
              var tagsValue = tagsSequenceElement[property];
              clusterInstance.tags[tagsKey] = tagsValue;
            }
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var propertiesInstance = { connectivityEndpoints: [], errorInfos: [] };
            clusterInstance.properties = propertiesInstance;
            
            var clusterVersionValue = propertiesValue['clusterVersion'];
            if (clusterVersionValue !== null && clusterVersionValue !== undefined) {
              var clusterVersionInstance = clusterVersionValue;
              propertiesInstance.clusterVersion = clusterVersionInstance;
            }
            
            var osTypeValue = propertiesValue['osType'];
            if (osTypeValue !== null && osTypeValue !== undefined) {
              var osTypeInstance = osTypeValue;
              propertiesInstance.operatingSystemType = osTypeInstance;
            }
            
            var tierValue = propertiesValue['tier'];
            if (tierValue !== null && tierValue !== undefined) {
              var tierInstance = tierValue;
              propertiesInstance.clusterTier = tierInstance;
            }
            
            var clusterDefinitionValue = propertiesValue['clusterDefinition'];
            if (clusterDefinitionValue !== null && clusterDefinitionValue !== undefined) {
              var clusterDefinitionInstance = {};
              propertiesInstance.clusterDefinition = clusterDefinitionInstance;
              
              var blueprintValue = clusterDefinitionValue['blueprint'];
              if (blueprintValue !== null && blueprintValue !== undefined) {
                var blueprintInstance = blueprintValue;
                clusterDefinitionInstance.blueprintUri = blueprintInstance;
              }
              
              var kindValue = clusterDefinitionValue['kind'];
              if (kindValue !== null && kindValue !== undefined) {
                var kindInstance = kindValue;
                clusterDefinitionInstance.clusterType = kindInstance;
              }
              
              var configurationsValue = clusterDefinitionValue['configurations'];
              if (configurationsValue !== null && configurationsValue !== undefined) {
                var configurationsInstance = configurationsValue;
                clusterDefinitionInstance.configurations = configurationsInstance;
              }
            }
            
            var computeProfileValue = propertiesValue['computeProfile'];
            if (computeProfileValue !== null && computeProfileValue !== undefined) {
              var computeProfileInstance = { roles: [] };
              propertiesInstance.computeProfile = computeProfileInstance;
              
              var rolesArray = computeProfileValue['roles'];
              if (rolesArray !== null && rolesArray !== undefined) {
                for (var loweredIndex1 = 0; loweredIndex1 < rolesArray.length; loweredIndex1 = loweredIndex1 + 1) {
                  var rolesValue = rolesArray[loweredIndex1];
                  var roleInstance = { scriptActions: [] };
                  computeProfileInstance.roles.push(roleInstance);
                  
                  var nameValue2 = rolesValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    roleInstance.name = nameInstance2;
                  }
                  
                  var targetInstanceCountValue = rolesValue['targetInstanceCount'];
                  if (targetInstanceCountValue !== null && targetInstanceCountValue !== undefined) {
                    var targetInstanceCountInstance = targetInstanceCountValue;
                    roleInstance.targetInstanceCount = targetInstanceCountInstance;
                  }
                  
                  var hardwareProfileValue = rolesValue['hardwareProfile'];
                  if (hardwareProfileValue !== null && hardwareProfileValue !== undefined) {
                    var hardwareProfileInstance = {};
                    roleInstance.hardwareProfile = hardwareProfileInstance;
                    
                    var vmSizeValue = hardwareProfileValue['vmSize'];
                    if (vmSizeValue !== null && vmSizeValue !== undefined) {
                      var vmSizeInstance = vmSizeValue;
                      hardwareProfileInstance.vmSize = vmSizeInstance;
                    }
                  }
                  
                  var osProfileValue = rolesValue['osProfile'];
                  if (osProfileValue !== null && osProfileValue !== undefined) {
                    var osProfileInstance = {};
                    roleInstance.osProfile = osProfileInstance;
                    
                    var windowsOperatingSystemProfileValue = osProfileValue['windowsOperatingSystemProfile'];
                    if (windowsOperatingSystemProfileValue !== null && windowsOperatingSystemProfileValue !== undefined) {
                      var windowsOperatingSystemProfileInstance = {};
                      osProfileInstance.windowsOperatingSystemProfile = windowsOperatingSystemProfileInstance;
                      
                      var rdpSettingsValue = windowsOperatingSystemProfileValue['rdpSettings'];
                      if (rdpSettingsValue !== null && rdpSettingsValue !== undefined) {
                        var rdpSettingsInstance = {};
                        windowsOperatingSystemProfileInstance.rdpSettings = rdpSettingsInstance;
                        
                        var usernameValue = rdpSettingsValue['username'];
                        if (usernameValue !== null && usernameValue !== undefined) {
                          var usernameInstance = usernameValue;
                          rdpSettingsInstance.userName = usernameInstance;
                        }
                        
                        var passwordValue = rdpSettingsValue['password'];
                        if (passwordValue !== null && passwordValue !== undefined) {
                          var passwordInstance = passwordValue;
                          rdpSettingsInstance.password = passwordInstance;
                        }
                        
                        var expiryDateValue = rdpSettingsValue['expiryDate'];
                        if (expiryDateValue !== null && expiryDateValue !== undefined) {
                          var expiryDateInstance = expiryDateValue;
                          rdpSettingsInstance.expiryDate = expiryDateInstance;
                        }
                      }
                    }
                    
                    var linuxOperatingSystemProfileValue = osProfileValue['linuxOperatingSystemProfile'];
                    if (linuxOperatingSystemProfileValue !== null && linuxOperatingSystemProfileValue !== undefined) {
                      var linuxOperatingSystemProfileInstance = {};
                      osProfileInstance.linuxOperatingSystemProfile = linuxOperatingSystemProfileInstance;
                      
                      var usernameValue2 = linuxOperatingSystemProfileValue['username'];
                      if (usernameValue2 !== null && usernameValue2 !== undefined) {
                        var usernameInstance2 = usernameValue2;
                        linuxOperatingSystemProfileInstance.userName = usernameInstance2;
                      }
                      
                      var passwordValue2 = linuxOperatingSystemProfileValue['password'];
                      if (passwordValue2 !== null && passwordValue2 !== undefined) {
                        var passwordInstance2 = passwordValue2;
                        linuxOperatingSystemProfileInstance.password = passwordInstance2;
                      }
                      
                      var sshProfileValue = linuxOperatingSystemProfileValue['sshProfile'];
                      if (sshProfileValue !== null && sshProfileValue !== undefined) {
                        var sshProfileInstance = { sshPublicKeys: [] };
                        linuxOperatingSystemProfileInstance.sshProfile = sshProfileInstance;
                        
                        var publicKeysArray = sshProfileValue['publicKeys'];
                        if (publicKeysArray !== null && publicKeysArray !== undefined) {
                          for (var loweredIndex2 = 0; loweredIndex2 < publicKeysArray.length; loweredIndex2 = loweredIndex2 + 1) {
                            var publicKeysValue = publicKeysArray[loweredIndex2];
                            var sshPublicKeyInstance = {};
                            sshProfileInstance.sshPublicKeys.push(sshPublicKeyInstance);
                            
                            var certificateDataValue = publicKeysValue['certificateData'];
                            if (certificateDataValue !== null && certificateDataValue !== undefined) {
                              var certificateDataInstance = certificateDataValue;
                              sshPublicKeyInstance.certificateData = certificateDataInstance;
                            }
                          }
                        }
                      }
                    }
                  }
                  
                  var virtualNetworkProfileValue = rolesValue['virtualNetworkProfile'];
                  if (virtualNetworkProfileValue !== null && virtualNetworkProfileValue !== undefined) {
                    var virtualNetworkProfileInstance = {};
                    roleInstance.virtualNetworkProfile = virtualNetworkProfileInstance;
                    
                    var idValue2 = virtualNetworkProfileValue['id'];
                    if (idValue2 !== null && idValue2 !== undefined) {
                      var idInstance2 = idValue2;
                      virtualNetworkProfileInstance.id = idInstance2;
                    }
                    
                    var subnetValue = virtualNetworkProfileValue['subnet'];
                    if (subnetValue !== null && subnetValue !== undefined) {
                      var subnetInstance = subnetValue;
                      virtualNetworkProfileInstance.subnetName = subnetInstance;
                    }
                  }
                  
                  var scriptActionsArray = rolesValue['scriptActions'];
                  if (scriptActionsArray !== null && scriptActionsArray !== undefined) {
                    for (var loweredIndex3 = 0; loweredIndex3 < scriptActionsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                      var scriptActionsValue = scriptActionsArray[loweredIndex3];
                      var scriptActionInstance = {};
                      roleInstance.scriptActions.push(scriptActionInstance);
                      
                      var nameValue3 = scriptActionsValue['name'];
                      if (nameValue3 !== null && nameValue3 !== undefined) {
                        var nameInstance3 = nameValue3;
                        scriptActionInstance.name = nameInstance3;
                      }
                      
                      var uriValue = scriptActionsValue['uri'];
                      if (uriValue !== null && uriValue !== undefined) {
                        var uriInstance = uriValue;
                        scriptActionInstance.uri = uriInstance;
                      }
                      
                      var parametersValue = scriptActionsValue['parameters'];
                      if (parametersValue !== null && parametersValue !== undefined) {
                        var parametersInstance = parametersValue;
                        scriptActionInstance.parameters = parametersInstance;
                      }
                    }
                  }
                }
              }
            }
            
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              propertiesInstance.provisioningState = provisioningStateInstance;
            }
            
            var createdDateValue = propertiesValue['createdDate'];
            if (createdDateValue !== null && createdDateValue !== undefined) {
              var createdDateInstance = createdDateValue;
              propertiesInstance.createdDate = createdDateInstance;
            }
            
            var clusterStateValue = propertiesValue['clusterState'];
            if (clusterStateValue !== null && clusterStateValue !== undefined) {
              var clusterStateInstance = clusterStateValue;
              propertiesInstance.clusterState = clusterStateInstance;
            }
            
            var quotaInfoValue = propertiesValue['quotaInfo'];
            if (quotaInfoValue !== null && quotaInfoValue !== undefined) {
              var quotaInfoInstance = {};
              propertiesInstance.quotaInfo = quotaInfoInstance;
              
              var coresUsedValue = quotaInfoValue['coresUsed'];
              if (coresUsedValue !== null && coresUsedValue !== undefined) {
                var coresUsedInstance = coresUsedValue;
                quotaInfoInstance.coresUsed = coresUsedInstance;
              }
            }
            
            var errorsArray = propertiesValue['errors'];
            if (errorsArray !== null && errorsArray !== undefined) {
              for (var loweredIndex4 = 0; loweredIndex4 < errorsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                var errorsValue = errorsArray[loweredIndex4];
                var errorInfoInstance = {};
                propertiesInstance.errorInfos.push(errorInfoInstance);
                
                var codeValue = errorsValue['code'];
                if (codeValue !== null && codeValue !== undefined) {
                  var codeInstance = codeValue;
                  errorInfoInstance.code = codeInstance;
                }
                
                var messageValue = errorsValue['message'];
                if (messageValue !== null && messageValue !== undefined) {
                  var messageInstance = messageValue;
                  errorInfoInstance.message = messageInstance;
                }
              }
            }
            
            var connectivityEndpointsArray = propertiesValue['connectivityEndpoints'];
            if (connectivityEndpointsArray !== null && connectivityEndpointsArray !== undefined) {
              for (var loweredIndex5 = 0; loweredIndex5 < connectivityEndpointsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                var connectivityEndpointsValue = connectivityEndpointsArray[loweredIndex5];
                var connectivityEndpointInstance = {};
                propertiesInstance.connectivityEndpoints.push(connectivityEndpointInstance);
                
                var nameValue4 = connectivityEndpointsValue['name'];
                if (nameValue4 !== null && nameValue4 !== undefined) {
                  var nameInstance4 = nameValue4;
                  connectivityEndpointInstance.name = nameInstance4;
                }
                
                var protocolValue = connectivityEndpointsValue['protocol'];
                if (protocolValue !== null && protocolValue !== undefined) {
                  var protocolInstance = protocolValue;
                  connectivityEndpointInstance.protocol = protocolInstance;
                }
                
                var locationValue2 = connectivityEndpointsValue['location'];
                if (locationValue2 !== null && locationValue2 !== undefined) {
                  var locationInstance2 = locationValue2;
                  connectivityEndpointInstance.location = locationInstance2;
                }
                
                var portValue = connectivityEndpointsValue['port'];
                if (portValue !== null && portValue !== undefined) {
                  var portInstance = portValue;
                  connectivityEndpointInstance.port = portInstance;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the capabilities for the specified location.
   * 
   * @param {string} location The location to get capabilities for.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.getCapabilities = function(location, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (location === null || location === undefined) {
      return callback(new Error('location cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/locations/';
    url2 = url2 + encodeURIComponent(location);
    url2 = url2 + '/capabilities';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // 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 = { features: [], regions: {}, versions: {}, vmSizeCompatibilityFilters: [], vmSizes: {} };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var versionsSequenceElement = responseDoc['versions'];
          if (versionsSequenceElement !== null && versionsSequenceElement !== undefined) {
            for (var property in versionsSequenceElement) {
              var versionsKey = property;
              var varToken = versionsSequenceElement[property];
              var versionsCapabilityInstance = { availableVersions: [] };
              result.versions[versionsKey] = versionsCapabilityInstance;
              
              var availableArray = varToken['available'];
              if (availableArray !== null && availableArray !== undefined) {
                for (var loweredIndex1 = 0; loweredIndex1 < availableArray.length; loweredIndex1 = loweredIndex1 + 1) {
                  var availableValue = availableArray[loweredIndex1];
                  var versionSpecInstance = { componentVerions: {} };
                  versionsCapabilityInstance.availableVersions.push(versionSpecInstance);
                  
                  var friendlyNameValue = availableValue['friendlyName'];
                  if (friendlyNameValue !== null && friendlyNameValue !== undefined) {
                    var friendlyNameInstance = friendlyNameValue;
                    versionSpecInstance.friendlyName = friendlyNameInstance;
                  }
                  
                  var displayNameValue = availableValue['displayName'];
                  if (displayNameValue !== null && displayNameValue !== undefined) {
                    var displayNameInstance = displayNameValue;
                    versionSpecInstance.displayName = displayNameInstance;
                  }
                  
                  var isDefaultValue = availableValue['isDefault'];
                  if (isDefaultValue !== null && isDefaultValue !== undefined) {
                    var isDefaultInstance = isDefaultValue;
                    versionSpecInstance.isDefault = isDefaultInstance;
                  }
                  
                  var componentVersionsSequenceElement = availableValue['componentVersions'];
                  if (componentVersionsSequenceElement !== null && componentVersionsSequenceElement !== undefined) {
                    for (var property2 in componentVersionsSequenceElement) {
                      var componentVersionsKey = property2;
                      var componentVersionsValue = componentVersionsSequenceElement[property2];
                      versionSpecInstance.componentVerions[componentVersionsKey] = componentVersionsValue;
                    }
                  }
                }
              }
            }
          }
          
          var regionsSequenceElement = responseDoc['regions'];
          if (regionsSequenceElement !== null && regionsSequenceElement !== undefined) {
            for (var property3 in regionsSequenceElement) {
              var regionsKey = property3;
              var varToken2 = regionsSequenceElement[property3];
              var regionsCapabilityInstance = { availableRegions: [] };
              result.regions[regionsKey] = regionsCapabilityInstance;
              
              var availableArray2 = varToken2['available'];
              if (availableArray2 !== null && availableArray2 !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < availableArray2.length; loweredIndex2 = loweredIndex2 + 1) {
                  var availableValue2 = availableArray2[loweredIndex2];
                  regionsCapabilityInstance.availableRegions.push(availableValue2);
                }
              }
            }
          }
          
          var vmsizesSequenceElement = responseDoc['vmsizes'];
          if (vmsizesSequenceElement !== null && vmsizesSequenceElement !== undefined) {
            for (var property4 in vmsizesSequenceElement) {
              var vmsizesKey = property4;
              var varToken3 = vmsizesSequenceElement[property4];
              var vmSizesCapabilityInstance = { availableVmSizes: [] };
              result.vmSizes[vmsizesKey] = vmSizesCapabilityInstance;
              
              var availableArray3 = varToken3['available'];
              if (availableArray3 !== null && availableArray3 !== undefined) {
                for (var loweredIndex3 = 0; loweredIndex3 < availableArray3.length; loweredIndex3 = loweredIndex3 + 1) {
                  var availableValue3 = availableArray3[loweredIndex3];
                  vmSizesCapabilityInstance.availableVmSizes.push(availableValue3);
                }
              }
            }
          }
          
          var vmsizeFiltersArray = responseDoc['vmsize_filters'];
          if (vmsizeFiltersArray !== null && vmsizeFiltersArray !== undefined) {
            for (var loweredIndex4 = 0; loweredIndex4 < vmsizeFiltersArray.length; loweredIndex4 = loweredIndex4 + 1) {
              var vmsizeFiltersValue = vmsizeFiltersArray[loweredIndex4];
              var vmSizeCompatibilityFilterInstance = { clusterFlavors: [], clusterVersions: [], nodeTypes: [], regions: [], vMSizes: [] };
              result.vmSizeCompatibilityFilters.push(vmSizeCompatibilityFilterInstance);
              
              var filterModeValue = vmsizeFiltersValue['FilterMode'];
              if (filterModeValue !== null && filterModeValue !== undefined) {
                var filterModeInstance = filterModeValue;
                vmSizeCompatibilityFilterInstance.filterMode = filterModeInstance;
              }
              
              var regionsArray = vmsizeFiltersValue['Regions'];
              if (regionsArray !== null && regionsArray !== undefined) {
                for (var loweredIndex5 = 0; loweredIndex5 < regionsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                  var regionsValue = regionsArray[loweredIndex5];
                  vmSizeCompatibilityFilterInstance.regions.push(regionsValue);
                }
              }
              
              var clusterFlavorsArray = vmsizeFiltersValue['ClusterFlavors'];
              if (clusterFlavorsArray !== null && clusterFlavorsArray !== undefined) {
                for (var loweredIndex6 = 0; loweredIndex6 < clusterFlavorsArray.length; loweredIndex6 = loweredIndex6 + 1) {
                  var clusterFlavorsValue = clusterFlavorsArray[loweredIndex6];
                  vmSizeCompatibilityFilterInstance.clusterFlavors.push(clusterFlavorsValue);
                }
              }
              
              var nodeTypesArray = vmsizeFiltersValue['NodeTypes'];
              if (nodeTypesArray !== null && nodeTypesArray !== undefined) {
                for (var loweredIndex7 = 0; loweredIndex7 < nodeTypesArray.length; loweredIndex7 = loweredIndex7 + 1) {
                  var nodeTypesValue = nodeTypesArray[loweredIndex7];
                  vmSizeCompatibilityFilterInstance.nodeTypes.push(nodeTypesValue);
                }
              }
              
              var clusterVersionsArray = vmsizeFiltersValue['ClusterVersions'];
              if (clusterVersionsArray !== null && clusterVersionsArray !== undefined) {
                for (var loweredIndex8 = 0; loweredIndex8 < clusterVersionsArray.length; loweredIndex8 = loweredIndex8 + 1) {
                  var clusterVersionsValue = clusterVersionsArray[loweredIndex8];
                  vmSizeCompatibilityFilterInstance.clusterVersions.push(clusterVersionsValue);
                }
              }
              
              var vMSizesArray = vmsizeFiltersValue['VMSizes'];
              if (vMSizesArray !== null && vMSizesArray !== undefined) {
                for (var loweredIndex9 = 0; loweredIndex9 < vMSizesArray.length; loweredIndex9 = loweredIndex9 + 1) {
                  var vMSizesValue = vMSizesArray[loweredIndex9];
                  vmSizeCompatibilityFilterInstance.vMSizes.push(vMSizesValue);
                }
              }
            }
          }
          
          var featuresArray = responseDoc['features'];
          if (featuresArray !== null && featuresArray !== undefined) {
            for (var loweredIndex10 = 0; loweredIndex10 < featuresArray.length; loweredIndex10 = loweredIndex10 + 1) {
              var featuresValue = featuresArray[loweredIndex10];
              result.features.push(featuresValue);
            }
          }
          
          var quotaValue = responseDoc['quota'];
          if (quotaValue !== null && quotaValue !== undefined) {
            var quotaInstance = { regionalQuotas: [] };
            result.quotaCapability = quotaInstance;
            
            var regionalQuotasArray = quotaValue['regionalQuotas'];
            if (regionalQuotasArray !== null && regionalQuotasArray !== undefined) {
              for (var loweredIndex11 = 0; loweredIndex11 < regionalQuotasArray.length; loweredIndex11 = loweredIndex11 + 1) {
                var regionalQuotasValue = regionalQuotasArray[loweredIndex11];
                var regionalQuotaCapabilityInstance = {};
                quotaInstance.regionalQuotas.push(regionalQuotaCapabilityInstance);
                
                var regionNameValue = regionalQuotasValue['region_name'];
                if (regionNameValue !== null && regionNameValue !== undefined) {
                  var regionNameInstance = regionNameValue;
                  regionalQuotaCapabilityInstance.regionName = regionNameInstance;
                }
                
                var coresUsedValue = regionalQuotasValue['cores_used'];
                if (coresUsedValue !== null && coresUsedValue !== undefined) {
                  var coresUsedInstance = coresUsedValue;
                  regionalQuotaCapabilityInstance.coresUsed = coresUsedInstance;
                }
                
                var coresAvailableValue = regionalQuotasValue['cores_available'];
                if (coresAvailableValue !== null && coresAvailableValue !== undefined) {
                  var coresAvailableInstance = coresAvailableValue;
                  regionalQuotaCapabilityInstance.coresAvailable = coresAvailableInstance;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the configuration for the specified cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {string} configurationName The type name of the hadoop
   * configuration.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.getClusterConfigurations = function(resourceGroupName, clusterName, configurationName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (configurationName === null || configurationName === undefined) {
      return callback(new Error('configurationName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/configurations/';
    url2 = url2 + encodeURIComponent(configurationName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // 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 = { configuration: {} };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var configurationSequenceElement = responseDoc;
          if (configurationSequenceElement !== null && configurationSequenceElement !== undefined) {
            for (var property in configurationSequenceElement) {
              var configurationKey = property;
              var configurationValue = configurationSequenceElement[property];
              result.configuration[configurationKey] = configurationValue;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the connectivity settings for the specified cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.getConnectivitySettings = function(resourceGroupName, clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/configurations/gateway';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // 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 responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var restAuthCredentialisEnabledValue = responseDoc['restAuthCredential.isEnabled'];
          if (restAuthCredentialisEnabledValue !== null && restAuthCredentialisEnabledValue !== undefined) {
            var restAuthCredentialisEnabledInstance = restAuthCredentialisEnabledValue;
            result.httpUserEnabled = restAuthCredentialisEnabledInstance;
          }
          
          var restAuthCredentialusernameValue = responseDoc['restAuthCredential.username'];
          if (restAuthCredentialusernameValue !== null && restAuthCredentialusernameValue !== undefined) {
            var restAuthCredentialusernameInstance = restAuthCredentialusernameValue;
            result.httpUsername = restAuthCredentialusernameInstance;
          }
          
          var restAuthCredentialpasswordValue = responseDoc['restAuthCredential.password'];
          if (restAuthCredentialpasswordValue !== null && restAuthCredentialpasswordValue !== undefined) {
            var restAuthCredentialpasswordInstance = restAuthCredentialpasswordValue;
            result.httpPassword = restAuthCredentialpasswordInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the status of the Create operation.
   * 
   * @param {string} operationStatusLink Location value returned by the Begin
   * operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.getCreateStatus = function(operationStatusLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (operationStatusLink === null || operationStatusLink === undefined) {
      return callback(new Error('operationStatusLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + operationStatusLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // 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 responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var clusterInstance = { tags: {} };
          result.cluster = clusterInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            clusterInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            clusterInstance.name = nameInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            clusterInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            clusterInstance.location = locationInstance;
          }
          
          var etagValue = responseDoc['etag'];
          if (etagValue !== null && etagValue !== undefined) {
            var etagInstance = etagValue;
            clusterInstance.eTag = etagInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey = property;
              var tagsValue = tagsSequenceElement[property];
              clusterInstance.tags[tagsKey] = tagsValue;
            }
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var propertiesInstance = { connectivityEndpoints: [], errorInfos: [] };
            clusterInstance.properties = propertiesInstance;
            
            var clusterVersionValue = propertiesValue['clusterVersion'];
            if (clusterVersionValue !== null && clusterVersionValue !== undefined) {
              var clusterVersionInstance = clusterVersionValue;
              propertiesInstance.clusterVersion = clusterVersionInstance;
            }
            
            var osTypeValue = propertiesValue['osType'];
            if (osTypeValue !== null && osTypeValue !== undefined) {
              var osTypeInstance = osTypeValue;
              propertiesInstance.operatingSystemType = osTypeInstance;
            }
            
            var tierValue = propertiesValue['tier'];
            if (tierValue !== null && tierValue !== undefined) {
              var tierInstance = tierValue;
              propertiesInstance.clusterTier = tierInstance;
            }
            
            var clusterDefinitionValue = propertiesValue['clusterDefinition'];
            if (clusterDefinitionValue !== null && clusterDefinitionValue !== undefined) {
              var clusterDefinitionInstance = {};
              propertiesInstance.clusterDefinition = clusterDefinitionInstance;
              
              var blueprintValue = clusterDefinitionValue['blueprint'];
              if (blueprintValue !== null && blueprintValue !== undefined) {
                var blueprintInstance = blueprintValue;
                clusterDefinitionInstance.blueprintUri = blueprintInstance;
              }
              
              var kindValue = clusterDefinitionValue['kind'];
              if (kindValue !== null && kindValue !== undefined) {
                var kindInstance = kindValue;
                clusterDefinitionInstance.clusterType = kindInstance;
              }
              
              var configurationsValue = clusterDefinitionValue['configurations'];
              if (configurationsValue !== null && configurationsValue !== undefined) {
                var configurationsInstance = configurationsValue;
                clusterDefinitionInstance.configurations = configurationsInstance;
              }
            }
            
            var computeProfileValue = propertiesValue['computeProfile'];
            if (computeProfileValue !== null && computeProfileValue !== undefined) {
              var computeProfileInstance = { roles: [] };
              propertiesInstance.computeProfile = computeProfileInstance;
              
              var rolesArray = computeProfileValue['roles'];
              if (rolesArray !== null && rolesArray !== undefined) {
                for (var loweredIndex1 = 0; loweredIndex1 < rolesArray.length; loweredIndex1 = loweredIndex1 + 1) {
                  var rolesValue = rolesArray[loweredIndex1];
                  var roleInstance = { scriptActions: [] };
                  computeProfileInstance.roles.push(roleInstance);
                  
                  var nameValue2 = rolesValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    roleInstance.name = nameInstance2;
                  }
                  
                  var targetInstanceCountValue = rolesValue['targetInstanceCount'];
                  if (targetInstanceCountValue !== null && targetInstanceCountValue !== undefined) {
                    var targetInstanceCountInstance = targetInstanceCountValue;
                    roleInstance.targetInstanceCount = targetInstanceCountInstance;
                  }
                  
                  var hardwareProfileValue = rolesValue['hardwareProfile'];
                  if (hardwareProfileValue !== null && hardwareProfileValue !== undefined) {
                    var hardwareProfileInstance = {};
                    roleInstance.hardwareProfile = hardwareProfileInstance;
                    
                    var vmSizeValue = hardwareProfileValue['vmSize'];
                    if (vmSizeValue !== null && vmSizeValue !== undefined) {
                      var vmSizeInstance = vmSizeValue;
                      hardwareProfileInstance.vmSize = vmSizeInstance;
                    }
                  }
                  
                  var osProfileValue = rolesValue['osProfile'];
                  if (osProfileValue !== null && osProfileValue !== undefined) {
                    var osProfileInstance = {};
                    roleInstance.osProfile = osProfileInstance;
                    
                    var windowsOperatingSystemProfileValue = osProfileValue['windowsOperatingSystemProfile'];
                    if (windowsOperatingSystemProfileValue !== null && windowsOperatingSystemProfileValue !== undefined) {
                      var windowsOperatingSystemProfileInstance = {};
                      osProfileInstance.windowsOperatingSystemProfile = windowsOperatingSystemProfileInstance;
                      
                      var rdpSettingsValue = windowsOperatingSystemProfileValue['rdpSettings'];
                      if (rdpSettingsValue !== null && rdpSettingsValue !== undefined) {
                        var rdpSettingsInstance = {};
                        windowsOperatingSystemProfileInstance.rdpSettings = rdpSettingsInstance;
                        
                        var usernameValue = rdpSettingsValue['username'];
                        if (usernameValue !== null && usernameValue !== undefined) {
                          var usernameInstance = usernameValue;
                          rdpSettingsInstance.userName = usernameInstance;
                        }
                        
                        var passwordValue = rdpSettingsValue['password'];
                        if (passwordValue !== null && passwordValue !== undefined) {
                          var passwordInstance = passwordValue;
                          rdpSettingsInstance.password = passwordInstance;
                        }
                        
                        var expiryDateValue = rdpSettingsValue['expiryDate'];
                        if (expiryDateValue !== null && expiryDateValue !== undefined) {
                          var expiryDateInstance = expiryDateValue;
                          rdpSettingsInstance.expiryDate = expiryDateInstance;
                        }
                      }
                    }
                    
                    var linuxOperatingSystemProfileValue = osProfileValue['linuxOperatingSystemProfile'];
                    if (linuxOperatingSystemProfileValue !== null && linuxOperatingSystemProfileValue !== undefined) {
                      var linuxOperatingSystemProfileInstance = {};
                      osProfileInstance.linuxOperatingSystemProfile = linuxOperatingSystemProfileInstance;
                      
                      var usernameValue2 = linuxOperatingSystemProfileValue['username'];
                      if (usernameValue2 !== null && usernameValue2 !== undefined) {
                        var usernameInstance2 = usernameValue2;
                        linuxOperatingSystemProfileInstance.userName = usernameInstance2;
                      }
                      
                      var passwordValue2 = linuxOperatingSystemProfileValue['password'];
                      if (passwordValue2 !== null && passwordValue2 !== undefined) {
                        var passwordInstance2 = passwordValue2;
                        linuxOperatingSystemProfileInstance.password = passwordInstance2;
                      }
                      
                      var sshProfileValue = linuxOperatingSystemProfileValue['sshProfile'];
                      if (sshProfileValue !== null && sshProfileValue !== undefined) {
                        var sshProfileInstance = { sshPublicKeys: [] };
                        linuxOperatingSystemProfileInstance.sshProfile = sshProfileInstance;
                        
                        var publicKeysArray = sshProfileValue['publicKeys'];
                        if (publicKeysArray !== null && publicKeysArray !== undefined) {
                          for (var loweredIndex2 = 0; loweredIndex2 < publicKeysArray.length; loweredIndex2 = loweredIndex2 + 1) {
                            var publicKeysValue = publicKeysArray[loweredIndex2];
                            var sshPublicKeyInstance = {};
                            sshProfileInstance.sshPublicKeys.push(sshPublicKeyInstance);
                            
                            var certificateDataValue = publicKeysValue['certificateData'];
                            if (certificateDataValue !== null && certificateDataValue !== undefined) {
                              var certificateDataInstance = certificateDataValue;
                              sshPublicKeyInstance.certificateData = certificateDataInstance;
                            }
                          }
                        }
                      }
                    }
                  }
                  
                  var virtualNetworkProfileValue = rolesValue['virtualNetworkProfile'];
                  if (virtualNetworkProfileValue !== null && virtualNetworkProfileValue !== undefined) {
                    var virtualNetworkProfileInstance = {};
                    roleInstance.virtualNetworkProfile = virtualNetworkProfileInstance;
                    
                    var idValue2 = virtualNetworkProfileValue['id'];
                    if (idValue2 !== null && idValue2 !== undefined) {
                      var idInstance2 = idValue2;
                      virtualNetworkProfileInstance.id = idInstance2;
                    }
                    
                    var subnetValue = virtualNetworkProfileValue['subnet'];
                    if (subnetValue !== null && subnetValue !== undefined) {
                      var subnetInstance = subnetValue;
                      virtualNetworkProfileInstance.subnetName = subnetInstance;
                    }
                  }
                  
                  var scriptActionsArray = rolesValue['scriptActions'];
                  if (scriptActionsArray !== null && scriptActionsArray !== undefined) {
                    for (var loweredIndex3 = 0; loweredIndex3 < scriptActionsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                      var scriptActionsValue = scriptActionsArray[loweredIndex3];
                      var scriptActionInstance = {};
                      roleInstance.scriptActions.push(scriptActionInstance);
                      
                      var nameValue3 = scriptActionsValue['name'];
                      if (nameValue3 !== null && nameValue3 !== undefined) {
                        var nameInstance3 = nameValue3;
                        scriptActionInstance.name = nameInstance3;
                      }
                      
                      var uriValue = scriptActionsValue['uri'];
                      if (uriValue !== null && uriValue !== undefined) {
                        var uriInstance = uriValue;
                        scriptActionInstance.uri = uriInstance;
                      }
                      
                      var parametersValue = scriptActionsValue['parameters'];
                      if (parametersValue !== null && parametersValue !== undefined) {
                        var parametersInstance = parametersValue;
                        scriptActionInstance.parameters = parametersInstance;
                      }
                    }
                  }
                }
              }
            }
            
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              propertiesInstance.provisioningState = provisioningStateInstance;
            }
            
            var createdDateValue = propertiesValue['createdDate'];
            if (createdDateValue !== null && createdDateValue !== undefined) {
              var createdDateInstance = createdDateValue;
              propertiesInstance.createdDate = createdDateInstance;
            }
            
            var clusterStateValue = propertiesValue['clusterState'];
            if (clusterStateValue !== null && clusterStateValue !== undefined) {
              var clusterStateInstance = clusterStateValue;
              propertiesInstance.clusterState = clusterStateInstance;
            }
            
            var quotaInfoValue = propertiesValue['quotaInfo'];
            if (quotaInfoValue !== null && quotaInfoValue !== undefined) {
              var quotaInfoInstance = {};
              propertiesInstance.quotaInfo = quotaInfoInstance;
              
              var coresUsedValue = quotaInfoValue['coresUsed'];
              if (coresUsedValue !== null && coresUsedValue !== undefined) {
                var coresUsedInstance = coresUsedValue;
                quotaInfoInstance.coresUsed = coresUsedInstance;
              }
            }
            
            var errorsArray = propertiesValue['errors'];
            if (errorsArray !== null && errorsArray !== undefined) {
              for (var loweredIndex4 = 0; loweredIndex4 < errorsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                var errorsValue = errorsArray[loweredIndex4];
                var errorInfoInstance = {};
                propertiesInstance.errorInfos.push(errorInfoInstance);
                
                var codeValue = errorsValue['code'];
                if (codeValue !== null && codeValue !== undefined) {
                  var codeInstance = codeValue;
                  errorInfoInstance.code = codeInstance;
                }
                
                var messageValue = errorsValue['message'];
                if (messageValue !== null && messageValue !== undefined) {
                  var messageInstance = messageValue;
                  errorInfoInstance.message = messageInstance;
                }
              }
            }
            
            var connectivityEndpointsArray = propertiesValue['connectivityEndpoints'];
            if (connectivityEndpointsArray !== null && connectivityEndpointsArray !== undefined) {
              for (var loweredIndex5 = 0; loweredIndex5 < connectivityEndpointsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                var connectivityEndpointsValue = connectivityEndpointsArray[loweredIndex5];
                var connectivityEndpointInstance = {};
                propertiesInstance.connectivityEndpoints.push(connectivityEndpointInstance);
                
                var nameValue4 = connectivityEndpointsValue['name'];
                if (nameValue4 !== null && nameValue4 !== undefined) {
                  var nameInstance4 = nameValue4;
                  connectivityEndpointInstance.name = nameInstance4;
                }
                
                var protocolValue = connectivityEndpointsValue['protocol'];
                if (protocolValue !== null && protocolValue !== undefined) {
                  var protocolInstance = protocolValue;
                  connectivityEndpointInstance.protocol = protocolInstance;
                }
                
                var locationValue2 = connectivityEndpointsValue['location'];
                if (locationValue2 !== null && locationValue2 !== undefined) {
                  var locationInstance2 = locationValue2;
                  connectivityEndpointInstance.location = locationInstance2;
                }
                
                var portValue = connectivityEndpointsValue['port'];
                if (portValue !== null && portValue !== undefined) {
                  var portInstance = portValue;
                  connectivityEndpointInstance.port = portInstance;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the status of the Delete operation.
   * 
   * @param {string} operationStatusLink Location value returned by the Begin
   * operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.getDeleteStatus = function(operationStatusLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (operationStatusLink === null || operationStatusLink === undefined) {
      return callback(new Error('operationStatusLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + operationStatusLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    httpRequest.headers['x-ms-version'] = '2015-03-01-preview';
    
    // 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 responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var statusValue = responseDoc['status'];
          if (statusValue !== null && statusValue !== undefined) {
            var statusInstance = statusValue;
            result.state = statusInstance;
          }
          
          var errorValue = responseDoc['error'];
          if (errorValue !== null && errorValue !== undefined) {
            var errorInstance = {};
            result.errorInfo = errorInstance;
            
            var codeValue = errorValue['code'];
            if (codeValue !== null && codeValue !== undefined) {
              var codeInstance = codeValue;
              errorInstance.code = codeInstance;
            }
            
            var messageValue = errorValue['message'];
            if (messageValue !== null && messageValue !== undefined) {
              var messageInstance = messageValue;
              errorInstance.message = messageInstance;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the script execution detail for the given script execution id.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {Number} scriptExecutionId The script execution Id
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.getScriptExecutionDetail = function(resourceGroupName, clusterName, scriptExecutionId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (scriptExecutionId === null || scriptExecutionId === undefined) {
      return callback(new Error('scriptExecutionId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '//clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/scriptExecutionHistory/';
    url2 = url2 + encodeURIComponent(scriptExecutionId.toString());
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    
    // 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 responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var runtimeScriptActionDetailInstance = { executionSummary: [], roles: [] };
          result.runtimeScriptActionDetail = runtimeScriptActionDetailInstance;
          
          var scriptExecutionIdValue = responseDoc['scriptExecutionId'];
          if (scriptExecutionIdValue !== null && scriptExecutionIdValue !== undefined) {
            var scriptExecutionIdInstance = scriptExecutionIdValue;
            runtimeScriptActionDetailInstance.scriptExecutionId = scriptExecutionIdInstance;
          }
          
          var startTimeValue = responseDoc['startTime'];
          if (startTimeValue !== null && startTimeValue !== undefined) {
            var startTimeInstance = startTimeValue;
            runtimeScriptActionDetailInstance.startTime = startTimeInstance;
          }
          
          var endTimeValue = responseDoc['endTime'];
          if (endTimeValue !== null && endTimeValue !== undefined) {
            var endTimeInstance = endTimeValue;
            runtimeScriptActionDetailInstance.endTime = endTimeInstance;
          }
          
          var statusValue = responseDoc['status'];
          if (statusValue !== null && statusValue !== undefined) {
            var statusInstance = statusValue;
            runtimeScriptActionDetailInstance.status = statusInstance;
          }
          
          var operationValue = responseDoc['operation'];
          if (operationValue !== null && operationValue !== undefined) {
            var operationInstance = operationValue;
            runtimeScriptActionDetailInstance.operation = operationInstance;
          }
          
          var executionSummaryArray = responseDoc['executionSummary'];
          if (executionSummaryArray !== null && executionSummaryArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < executionSummaryArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var executionSummaryValue = executionSummaryArray[loweredIndex1];
              var scriptActionExecutionSummaryInstance = {};
              runtimeScriptActionDetailInstance.executionSummary.push(scriptActionExecutionSummaryInstance);
              
              var statusValue2 = executionSummaryValue['status'];
              if (statusValue2 !== null && statusValue2 !== undefined) {
                var statusInstance2 = statusValue2;
                scriptActionExecutionSummaryInstance.status = statusInstance2;
              }
              
              var instanceCountValue = executionSummaryValue['instanceCount'];
              if (instanceCountValue !== null && instanceCountValue !== undefined) {
                var instanceCountInstance = instanceCountValue;
                scriptActionExecutionSummaryInstance.instanceCount = instanceCountInstance;
              }
            }
          }
          
          var debugInformationValue = responseDoc['debugInformation'];
          if (debugInformationValue !== null && debugInformationValue !== undefined) {
            var debugInformationInstance = debugInformationValue;
            runtimeScriptActionDetailInstance.debugInformation = debugInformationInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            runtimeScriptActionDetailInstance.name = nameInstance;
          }
          
          var uriValue = responseDoc['uri'];
          if (uriValue !== null && uriValue !== undefined) {
            var uriInstance = uriValue;
            runtimeScriptActionDetailInstance.uri = uriInstance;
          }
          
          var parametersValue = responseDoc['parameters'];
          if (parametersValue !== null && parametersValue !== undefined) {
            var parametersInstance = parametersValue;
            runtimeScriptActionDetailInstance.parameters = parametersInstance;
          }
          
          var rolesArray = responseDoc['roles'];
          if (rolesArray !== null && rolesArray !== undefined) {
            for (var loweredIndex2 = 0; loweredIndex2 < rolesArray.length; loweredIndex2 = loweredIndex2 + 1) {
              var rolesValue = rolesArray[loweredIndex2];
              runtimeScriptActionDetailInstance.roles.push(rolesValue);
            }
          }
          
          var applicationNameValue = responseDoc['applicationName'];
          if (applicationNameValue !== null && applicationNameValue !== undefined) {
            var applicationNameInstance = applicationNameValue;
            runtimeScriptActionDetailInstance.applicationName = applicationNameInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Lists HDInsight clusters under the subscription.
   * 
   * @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 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // 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 = { clusters: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var clusterInstance = { tags: {} };
              result.clusters.push(clusterInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                clusterInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                clusterInstance.name = nameInstance;
              }
              
              var typeValue = valueValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                clusterInstance.type = typeInstance;
              }
              
              var locationValue = valueValue['location'];
              if (locationValue !== null && locationValue !== undefined) {
                var locationInstance = locationValue;
                clusterInstance.location = locationInstance;
              }
              
              var etagValue = valueValue['etag'];
              if (etagValue !== null && etagValue !== undefined) {
                var etagInstance = etagValue;
                clusterInstance.eTag = etagInstance;
              }
              
              var tagsSequenceElement = valueValue['tags'];
              if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                for (var property in tagsSequenceElement) {
                  var tagsKey = property;
                  var tagsValue = tagsSequenceElement[property];
                  clusterInstance.tags[tagsKey] = tagsValue;
                }
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var propertiesInstance = { connectivityEndpoints: [], errorInfos: [] };
                clusterInstance.properties = propertiesInstance;
                
                var clusterVersionValue = propertiesValue['clusterVersion'];
                if (clusterVersionValue !== null && clusterVersionValue !== undefined) {
                  var clusterVersionInstance = clusterVersionValue;
                  propertiesInstance.clusterVersion = clusterVersionInstance;
                }
                
                var osTypeValue = propertiesValue['osType'];
                if (osTypeValue !== null && osTypeValue !== undefined) {
                  var osTypeInstance = osTypeValue;
                  propertiesInstance.operatingSystemType = osTypeInstance;
                }
                
                var tierValue = propertiesValue['tier'];
                if (tierValue !== null && tierValue !== undefined) {
                  var tierInstance = tierValue;
                  propertiesInstance.clusterTier = tierInstance;
                }
                
                var clusterDefinitionValue = propertiesValue['clusterDefinition'];
                if (clusterDefinitionValue !== null && clusterDefinitionValue !== undefined) {
                  var clusterDefinitionInstance = {};
                  propertiesInstance.clusterDefinition = clusterDefinitionInstance;
                  
                  var blueprintValue = clusterDefinitionValue['blueprint'];
                  if (blueprintValue !== null && blueprintValue !== undefined) {
                    var blueprintInstance = blueprintValue;
                    clusterDefinitionInstance.blueprintUri = blueprintInstance;
                  }
                  
                  var kindValue = clusterDefinitionValue['kind'];
                  if (kindValue !== null && kindValue !== undefined) {
                    var kindInstance = kindValue;
                    clusterDefinitionInstance.clusterType = kindInstance;
                  }
                  
                  var configurationsValue = clusterDefinitionValue['configurations'];
                  if (configurationsValue !== null && configurationsValue !== undefined) {
                    var configurationsInstance = configurationsValue;
                    clusterDefinitionInstance.configurations = configurationsInstance;
                  }
                }
                
                var computeProfileValue = propertiesValue['computeProfile'];
                if (computeProfileValue !== null && computeProfileValue !== undefined) {
                  var computeProfileInstance = { roles: [] };
                  propertiesInstance.computeProfile = computeProfileInstance;
                  
                  var rolesArray = computeProfileValue['roles'];
                  if (rolesArray !== null && rolesArray !== undefined) {
                    for (var loweredIndex2 = 0; loweredIndex2 < rolesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                      var rolesValue = rolesArray[loweredIndex2];
                      var roleInstance = { scriptActions: [] };
                      computeProfileInstance.roles.push(roleInstance);
                      
                      var nameValue2 = rolesValue['name'];
                      if (nameValue2 !== null && nameValue2 !== undefined) {
                        var nameInstance2 = nameValue2;
                        roleInstance.name = nameInstance2;
                      }
                      
                      var targetInstanceCountValue = rolesValue['targetInstanceCount'];
                      if (targetInstanceCountValue !== null && targetInstanceCountValue !== undefined) {
                        var targetInstanceCountInstance = targetInstanceCountValue;
                        roleInstance.targetInstanceCount = targetInstanceCountInstance;
                      }
                      
                      var hardwareProfileValue = rolesValue['hardwareProfile'];
                      if (hardwareProfileValue !== null && hardwareProfileValue !== undefined) {
                        var hardwareProfileInstance = {};
                        roleInstance.hardwareProfile = hardwareProfileInstance;
                        
                        var vmSizeValue = hardwareProfileValue['vmSize'];
                        if (vmSizeValue !== null && vmSizeValue !== undefined) {
                          var vmSizeInstance = vmSizeValue;
                          hardwareProfileInstance.vmSize = vmSizeInstance;
                        }
                      }
                      
                      var osProfileValue = rolesValue['osProfile'];
                      if (osProfileValue !== null && osProfileValue !== undefined) {
                        var osProfileInstance = {};
                        roleInstance.osProfile = osProfileInstance;
                        
                        var windowsOperatingSystemProfileValue = osProfileValue['windowsOperatingSystemProfile'];
                        if (windowsOperatingSystemProfileValue !== null && windowsOperatingSystemProfileValue !== undefined) {
                          var windowsOperatingSystemProfileInstance = {};
                          osProfileInstance.windowsOperatingSystemProfile = windowsOperatingSystemProfileInstance;
                          
                          var rdpSettingsValue = windowsOperatingSystemProfileValue['rdpSettings'];
                          if (rdpSettingsValue !== null && rdpSettingsValue !== undefined) {
                            var rdpSettingsInstance = {};
                            windowsOperatingSystemProfileInstance.rdpSettings = rdpSettingsInstance;
                            
                            var usernameValue = rdpSettingsValue['username'];
                            if (usernameValue !== null && usernameValue !== undefined) {
                              var usernameInstance = usernameValue;
                              rdpSettingsInstance.userName = usernameInstance;
                            }
                            
                            var passwordValue = rdpSettingsValue['password'];
                            if (passwordValue !== null && passwordValue !== undefined) {
                              var passwordInstance = passwordValue;
                              rdpSettingsInstance.password = passwordInstance;
                            }
                            
                            var expiryDateValue = rdpSettingsValue['expiryDate'];
                            if (expiryDateValue !== null && expiryDateValue !== undefined) {
                              var expiryDateInstance = expiryDateValue;
                              rdpSettingsInstance.expiryDate = expiryDateInstance;
                            }
                          }
                        }
                        
                        var linuxOperatingSystemProfileValue = osProfileValue['linuxOperatingSystemProfile'];
                        if (linuxOperatingSystemProfileValue !== null && linuxOperatingSystemProfileValue !== undefined) {
                          var linuxOperatingSystemProfileInstance = {};
                          osProfileInstance.linuxOperatingSystemProfile = linuxOperatingSystemProfileInstance;
                          
                          var usernameValue2 = linuxOperatingSystemProfileValue['username'];
                          if (usernameValue2 !== null && usernameValue2 !== undefined) {
                            var usernameInstance2 = usernameValue2;
                            linuxOperatingSystemProfileInstance.userName = usernameInstance2;
                          }
                          
                          var passwordValue2 = linuxOperatingSystemProfileValue['password'];
                          if (passwordValue2 !== null && passwordValue2 !== undefined) {
                            var passwordInstance2 = passwordValue2;
                            linuxOperatingSystemProfileInstance.password = passwordInstance2;
                          }
                          
                          var sshProfileValue = linuxOperatingSystemProfileValue['sshProfile'];
                          if (sshProfileValue !== null && sshProfileValue !== undefined) {
                            var sshProfileInstance = { sshPublicKeys: [] };
                            linuxOperatingSystemProfileInstance.sshProfile = sshProfileInstance;
                            
                            var publicKeysArray = sshProfileValue['publicKeys'];
                            if (publicKeysArray !== null && publicKeysArray !== undefined) {
                              for (var loweredIndex3 = 0; loweredIndex3 < publicKeysArray.length; loweredIndex3 = loweredIndex3 + 1) {
                                var publicKeysValue = publicKeysArray[loweredIndex3];
                                var sshPublicKeyInstance = {};
                                sshProfileInstance.sshPublicKeys.push(sshPublicKeyInstance);
                                
                                var certificateDataValue = publicKeysValue['certificateData'];
                                if (certificateDataValue !== null && certificateDataValue !== undefined) {
                                  var certificateDataInstance = certificateDataValue;
                                  sshPublicKeyInstance.certificateData = certificateDataInstance;
                                }
                              }
                            }
                          }
                        }
                      }
                      
                      var virtualNetworkProfileValue = rolesValue['virtualNetworkProfile'];
                      if (virtualNetworkProfileValue !== null && virtualNetworkProfileValue !== undefined) {
                        var virtualNetworkProfileInstance = {};
                        roleInstance.virtualNetworkProfile = virtualNetworkProfileInstance;
                        
                        var idValue2 = virtualNetworkProfileValue['id'];
                        if (idValue2 !== null && idValue2 !== undefined) {
                          var idInstance2 = idValue2;
                          virtualNetworkProfileInstance.id = idInstance2;
                        }
                        
                        var subnetValue = virtualNetworkProfileValue['subnet'];
                        if (subnetValue !== null && subnetValue !== undefined) {
                          var subnetInstance = subnetValue;
                          virtualNetworkProfileInstance.subnetName = subnetInstance;
                        }
                      }
                      
                      var scriptActionsArray = rolesValue['scriptActions'];
                      if (scriptActionsArray !== null && scriptActionsArray !== undefined) {
                        for (var loweredIndex4 = 0; loweredIndex4 < scriptActionsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                          var scriptActionsValue = scriptActionsArray[loweredIndex4];
                          var scriptActionInstance = {};
                          roleInstance.scriptActions.push(scriptActionInstance);
                          
                          var nameValue3 = scriptActionsValue['name'];
                          if (nameValue3 !== null && nameValue3 !== undefined) {
                            var nameInstance3 = nameValue3;
                            scriptActionInstance.name = nameInstance3;
                          }
                          
                          var uriValue = scriptActionsValue['uri'];
                          if (uriValue !== null && uriValue !== undefined) {
                            var uriInstance = uriValue;
                            scriptActionInstance.uri = uriInstance;
                          }
                          
                          var parametersValue = scriptActionsValue['parameters'];
                          if (parametersValue !== null && parametersValue !== undefined) {
                            var parametersInstance = parametersValue;
                            scriptActionInstance.parameters = parametersInstance;
                          }
                        }
                      }
                    }
                  }
                }
                
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  propertiesInstance.provisioningState = provisioningStateInstance;
                }
                
                var createdDateValue = propertiesValue['createdDate'];
                if (createdDateValue !== null && createdDateValue !== undefined) {
                  var createdDateInstance = createdDateValue;
                  propertiesInstance.createdDate = createdDateInstance;
                }
                
                var clusterStateValue = propertiesValue['clusterState'];
                if (clusterStateValue !== null && clusterStateValue !== undefined) {
                  var clusterStateInstance = clusterStateValue;
                  propertiesInstance.clusterState = clusterStateInstance;
                }
                
                var quotaInfoValue = propertiesValue['quotaInfo'];
                if (quotaInfoValue !== null && quotaInfoValue !== undefined) {
                  var quotaInfoInstance = {};
                  propertiesInstance.quotaInfo = quotaInfoInstance;
                  
                  var coresUsedValue = quotaInfoValue['coresUsed'];
                  if (coresUsedValue !== null && coresUsedValue !== undefined) {
                    var coresUsedInstance = coresUsedValue;
                    quotaInfoInstance.coresUsed = coresUsedInstance;
                  }
                }
                
                var errorsArray = propertiesValue['errors'];
                if (errorsArray !== null && errorsArray !== undefined) {
                  for (var loweredIndex5 = 0; loweredIndex5 < errorsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                    var errorsValue = errorsArray[loweredIndex5];
                    var errorInfoInstance = {};
                    propertiesInstance.errorInfos.push(errorInfoInstance);
                    
                    var codeValue = errorsValue['code'];
                    if (codeValue !== null && codeValue !== undefined) {
                      var codeInstance = codeValue;
                      errorInfoInstance.code = codeInstance;
                    }
                    
                    var messageValue = errorsValue['message'];
                    if (messageValue !== null && messageValue !== undefined) {
                      var messageInstance = messageValue;
                      errorInfoInstance.message = messageInstance;
                    }
                  }
                }
                
                var connectivityEndpointsArray = propertiesValue['connectivityEndpoints'];
                if (connectivityEndpointsArray !== null && connectivityEndpointsArray !== undefined) {
                  for (var loweredIndex6 = 0; loweredIndex6 < connectivityEndpointsArray.length; loweredIndex6 = loweredIndex6 + 1) {
                    var connectivityEndpointsValue = connectivityEndpointsArray[loweredIndex6];
                    var connectivityEndpointInstance = {};
                    propertiesInstance.connectivityEndpoints.push(connectivityEndpointInstance);
                    
                    var nameValue4 = connectivityEndpointsValue['name'];
                    if (nameValue4 !== null && nameValue4 !== undefined) {
                      var nameInstance4 = nameValue4;
                      connectivityEndpointInstance.name = nameInstance4;
                    }
                    
                    var protocolValue = connectivityEndpointsValue['protocol'];
                    if (protocolValue !== null && protocolValue !== undefined) {
                      var protocolInstance = protocolValue;
                      connectivityEndpointInstance.protocol = protocolInstance;
                    }
                    
                    var locationValue2 = connectivityEndpointsValue['location'];
                    if (locationValue2 !== null && locationValue2 !== undefined) {
                      var locationInstance2 = locationValue2;
                      connectivityEndpointInstance.location = locationInstance2;
                    }
                    
                    var portValue = connectivityEndpointsValue['port'];
                    if (portValue !== null && portValue !== undefined) {
                      var portInstance = portValue;
                      connectivityEndpointInstance.port = portInstance;
                    }
                  }
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the HDInsight clusters in a resource group.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.listByResourceGroup = function(resourceGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    httpRequest.headers['User-Agent'] = 'ARM SDK Node v0.2.0';
    
    // 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 = { clusters: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var clusterInstance = { tags: {} };
              result.clusters.push(clusterInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                clusterInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                clusterInstance.name = nameInstance;
              }
              
              var typeValue = valueValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                clusterInstance.type = typeInstance;
              }
              
              var locationValue = valueValue['location'];
              if (locationValue !== null && locationValue !== undefined) {
                var locationInstance = locationValue;
                clusterInstance.location = locationInstance;
              }
              
              var etagValue = valueValue['etag'];
              if (etagValue !== null && etagValue !== undefined) {
                var etagInstance = etagValue;
                clusterInstance.eTag = etagInstance;
              }
              
              var tagsSequenceElement = valueValue['tags'];
              if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                for (var property in tagsSequenceElement) {
                  var tagsKey = property;
                  var tagsValue = tagsSequenceElement[property];
                  clusterInstance.tags[tagsKey] = tagsValue;
                }
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var propertiesInstance = { connectivityEndpoints: [], errorInfos: [] };
                clusterInstance.properties = propertiesInstance;
                
                var clusterVersionValue = propertiesValue['clusterVersion'];
                if (clusterVersionValue !== null && clusterVersionValue !== undefined) {
                  var clusterVersionInstance = clusterVersionValue;
                  propertiesInstance.clusterVersion = clusterVersionInstance;
                }
                
                var osTypeValue = propertiesValue['osType'];
                if (osTypeValue !== null && osTypeValue !== undefined) {
                  var osTypeInstance = osTypeValue;
                  propertiesInstance.operatingSystemType = osTypeInstance;
                }
                
                var tierValue = propertiesValue['tier'];
                if (tierValue !== null && tierValue !== undefined) {
                  var tierInstance = tierValue;
                  propertiesInstance.clusterTier = tierInstance;
                }
                
                var clusterDefinitionValue = propertiesValue['clusterDefinition'];
                if (clusterDefinitionValue !== null && clusterDefinitionValue !== undefined) {
                  var clusterDefinitionInstance = {};
                  propertiesInstance.clusterDefinition = clusterDefinitionInstance;
                  
                  var blueprintValue = clusterDefinitionValue['blueprint'];
                  if (blueprintValue !== null && blueprintValue !== undefined) {
                    var blueprintInstance = blueprintValue;
                    clusterDefinitionInstance.blueprintUri = blueprintInstance;
                  }
                  
                  var kindValue = clusterDefinitionValue['kind'];
                  if (kindValue !== null && kindValue !== undefined) {
                    var kindInstance = kindValue;
                    clusterDefinitionInstance.clusterType = kindInstance;
                  }
                  
                  var configurationsValue = clusterDefinitionValue['configurations'];
                  if (configurationsValue !== null && configurationsValue !== undefined) {
                    var configurationsInstance = configurationsValue;
                    clusterDefinitionInstance.configurations = configurationsInstance;
                  }
                }
                
                var computeProfileValue = propertiesValue['computeProfile'];
                if (computeProfileValue !== null && computeProfileValue !== undefined) {
                  var computeProfileInstance = { roles: [] };
                  propertiesInstance.computeProfile = computeProfileInstance;
                  
                  var rolesArray = computeProfileValue['roles'];
                  if (rolesArray !== null && rolesArray !== undefined) {
                    for (var loweredIndex2 = 0; loweredIndex2 < rolesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                      var rolesValue = rolesArray[loweredIndex2];
                      var roleInstance = { scriptActions: [] };
                      computeProfileInstance.roles.push(roleInstance);
                      
                      var nameValue2 = rolesValue['name'];
                      if (nameValue2 !== null && nameValue2 !== undefined) {
                        var nameInstance2 = nameValue2;
                        roleInstance.name = nameInstance2;
                      }
                      
                      var targetInstanceCountValue = rolesValue['targetInstanceCount'];
                      if (targetInstanceCountValue !== null && targetInstanceCountValue !== undefined) {
                        var targetInstanceCountInstance = targetInstanceCountValue;
                        roleInstance.targetInstanceCount = targetInstanceCountInstance;
                      }
                      
                      var hardwareProfileValue = rolesValue['hardwareProfile'];
                      if (hardwareProfileValue !== null && hardwareProfileValue !== undefined) {
                        var hardwareProfileInstance = {};
                        roleInstance.hardwareProfile = hardwareProfileInstance;
                        
                        var vmSizeValue = hardwareProfileValue['vmSize'];
                        if (vmSizeValue !== null && vmSizeValue !== undefined) {
                          var vmSizeInstance = vmSizeValue;
                          hardwareProfileInstance.vmSize = vmSizeInstance;
                        }
                      }
                      
                      var osProfileValue = rolesValue['osProfile'];
                      if (osProfileValue !== null && osProfileValue !== undefined) {
                        var osProfileInstance = {};
                        roleInstance.osProfile = osProfileInstance;
                        
                        var windowsOperatingSystemProfileValue = osProfileValue['windowsOperatingSystemProfile'];
                        if (windowsOperatingSystemProfileValue !== null && windowsOperatingSystemProfileValue !== undefined) {
                          var windowsOperatingSystemProfileInstance = {};
                          osProfileInstance.windowsOperatingSystemProfile = windowsOperatingSystemProfileInstance;
                          
                          var rdpSettingsValue = windowsOperatingSystemProfileValue['rdpSettings'];
                          if (rdpSettingsValue !== null && rdpSettingsValue !== undefined) {
                            var rdpSettingsInstance = {};
                            windowsOperatingSystemProfileInstance.rdpSettings = rdpSettingsInstance;
                            
                            var usernameValue = rdpSettingsValue['username'];
                            if (usernameValue !== null && usernameValue !== undefined) {
                              var usernameInstance = usernameValue;
                              rdpSettingsInstance.userName = usernameInstance;
                            }
                            
                            var passwordValue = rdpSettingsValue['password'];
                            if (passwordValue !== null && passwordValue !== undefined) {
                              var passwordInstance = passwordValue;
                              rdpSettingsInstance.password = passwordInstance;
                            }
                            
                            var expiryDateValue = rdpSettingsValue['expiryDate'];
                            if (expiryDateValue !== null && expiryDateValue !== undefined) {
                              var expiryDateInstance = expiryDateValue;
                              rdpSettingsInstance.expiryDate = expiryDateInstance;
                            }
                          }
                        }
                        
                        var linuxOperatingSystemProfileValue = osProfileValue['linuxOperatingSystemProfile'];
                        if (linuxOperatingSystemProfileValue !== null && linuxOperatingSystemProfileValue !== undefined) {
                          var linuxOperatingSystemProfileInstance = {};
                          osProfileInstance.linuxOperatingSystemProfile = linuxOperatingSystemProfileInstance;
                          
                          var usernameValue2 = linuxOperatingSystemProfileValue['username'];
                          if (usernameValue2 !== null && usernameValue2 !== undefined) {
                            var usernameInstance2 = usernameValue2;
                            linuxOperatingSystemProfileInstance.userName = usernameInstance2;
                          }
                          
                          var passwordValue2 = linuxOperatingSystemProfileValue['password'];
                          if (passwordValue2 !== null && passwordValue2 !== undefined) {
                            var passwordInstance2 = passwordValue2;
                            linuxOperatingSystemProfileInstance.password = passwordInstance2;
                          }
                          
                          var sshProfileValue = linuxOperatingSystemProfileValue['sshProfile'];
                          if (sshProfileValue !== null && sshProfileValue !== undefined) {
                            var sshProfileInstance = { sshPublicKeys: [] };
                            linuxOperatingSystemProfileInstance.sshProfile = sshProfileInstance;
                            
                            var publicKeysArray = sshProfileValue['publicKeys'];
                            if (publicKeysArray !== null && publicKeysArray !== undefined) {
                              for (var loweredIndex3 = 0; loweredIndex3 < publicKeysArray.length; loweredIndex3 = loweredIndex3 + 1) {
                                var publicKeysValue = publicKeysArray[loweredIndex3];
                                var sshPublicKeyInstance = {};
                                sshProfileInstance.sshPublicKeys.push(sshPublicKeyInstance);
                                
                                var certificateDataValue = publicKeysValue['certificateData'];
                                if (certificateDataValue !== null && certificateDataValue !== undefined) {
                                  var certificateDataInstance = certificateDataValue;
                                  sshPublicKeyInstance.certificateData = certificateDataInstance;
                                }
                              }
                            }
                          }
                        }
                      }
                      
                      var virtualNetworkProfileValue = rolesValue['virtualNetworkProfile'];
                      if (virtualNetworkProfileValue !== null && virtualNetworkProfileValue !== undefined) {
                        var virtualNetworkProfileInstance = {};
                        roleInstance.virtualNetworkProfile = virtualNetworkProfileInstance;
                        
                        var idValue2 = virtualNetworkProfileValue['id'];
                        if (idValue2 !== null && idValue2 !== undefined) {
                          var idInstance2 = idValue2;
                          virtualNetworkProfileInstance.id = idInstance2;
                        }
                        
                        var subnetValue = virtualNetworkProfileValue['subnet'];
                        if (subnetValue !== null && subnetValue !== undefined) {
                          var subnetInstance = subnetValue;
                          virtualNetworkProfileInstance.subnetName = subnetInstance;
                        }
                      }
                      
                      var scriptActionsArray = rolesValue['scriptActions'];
                      if (scriptActionsArray !== null && scriptActionsArray !== undefined) {
                        for (var loweredIndex4 = 0; loweredIndex4 < scriptActionsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                          var scriptActionsValue = scriptActionsArray[loweredIndex4];
                          var scriptActionInstance = {};
                          roleInstance.scriptActions.push(scriptActionInstance);
                          
                          var nameValue3 = scriptActionsValue['name'];
                          if (nameValue3 !== null && nameValue3 !== undefined) {
                            var nameInstance3 = nameValue3;
                            scriptActionInstance.name = nameInstance3;
                          }
                          
                          var uriValue = scriptActionsValue['uri'];
                          if (uriValue !== null && uriValue !== undefined) {
                            var uriInstance = uriValue;
                            scriptActionInstance.uri = uriInstance;
                          }
                          
                          var parametersValue = scriptActionsValue['parameters'];
                          if (parametersValue !== null && parametersValue !== undefined) {
                            var parametersInstance = parametersValue;
                            scriptActionInstance.parameters = parametersInstance;
                          }
                        }
                      }
                    }
                  }
                }
                
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  propertiesInstance.provisioningState = provisioningStateInstance;
                }
                
                var createdDateValue = propertiesValue['createdDate'];
                if (createdDateValue !== null && createdDateValue !== undefined) {
                  var createdDateInstance = createdDateValue;
                  propertiesInstance.createdDate = createdDateInstance;
                }
                
                var clusterStateValue = propertiesValue['clusterState'];
                if (clusterStateValue !== null && clusterStateValue !== undefined) {
                  var clusterStateInstance = clusterStateValue;
                  propertiesInstance.clusterState = clusterStateInstance;
                }
                
                var quotaInfoValue = propertiesValue['quotaInfo'];
                if (quotaInfoValue !== null && quotaInfoValue !== undefined) {
                  var quotaInfoInstance = {};
                  propertiesInstance.quotaInfo = quotaInfoInstance;
                  
                  var coresUsedValue = quotaInfoValue['coresUsed'];
                  if (coresUsedValue !== null && coresUsedValue !== undefined) {
                    var coresUsedInstance = coresUsedValue;
                    quotaInfoInstance.coresUsed = coresUsedInstance;
                  }
                }
                
                var errorsArray = propertiesValue['errors'];
                if (errorsArray !== null && errorsArray !== undefined) {
                  for (var loweredIndex5 = 0; loweredIndex5 < errorsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                    var errorsValue = errorsArray[loweredIndex5];
                    var errorInfoInstance = {};
                    propertiesInstance.errorInfos.push(errorInfoInstance);
                    
                    var codeValue = errorsValue['code'];
                    if (codeValue !== null && codeValue !== undefined) {
                      var codeInstance = codeValue;
                      errorInfoInstance.code = codeInstance;
                    }
                    
                    var messageValue = errorsValue['message'];
                    if (messageValue !== null && messageValue !== undefined) {
                      var messageInstance = messageValue;
                      errorInfoInstance.message = messageInstance;
                    }
                  }
                }
                
                var connectivityEndpointsArray = propertiesValue['connectivityEndpoints'];
                if (connectivityEndpointsArray !== null && connectivityEndpointsArray !== undefined) {
                  for (var loweredIndex6 = 0; loweredIndex6 < connectivityEndpointsArray.length; loweredIndex6 = loweredIndex6 + 1) {
                    var connectivityEndpointsValue = connectivityEndpointsArray[loweredIndex6];
                    var connectivityEndpointInstance = {};
                    propertiesInstance.connectivityEndpoints.push(connectivityEndpointInstance);
                    
                    var nameValue4 = connectivityEndpointsValue['name'];
                    if (nameValue4 !== null && nameValue4 !== undefined) {
                      var nameInstance4 = nameValue4;
                      connectivityEndpointInstance.name = nameInstance4;
                    }
                    
                    var protocolValue = connectivityEndpointsValue['protocol'];
                    if (protocolValue !== null && protocolValue !== undefined) {
                      var protocolInstance = protocolValue;
                      connectivityEndpointInstance.protocol = protocolInstance;
                    }
                    
                    var locationValue2 = connectivityEndpointsValue['location'];
                    if (locationValue2 !== null && locationValue2 !== undefined) {
                      var locationInstance2 = locationValue2;
                      connectivityEndpointInstance.location = locationInstance2;
                    }
                    
                    var portValue = connectivityEndpointsValue['port'];
                    if (portValue !== null && portValue !== undefined) {
                      var portInstance = portValue;
                      connectivityEndpointInstance.port = portInstance;
                    }
                  }
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Lists all persisted script actions for the given cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.listPersistedScripts = function(resourceGroupName, clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '/clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/scriptActions';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    
    // 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 = { persistedScriptActions: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var runtimeScriptActionInstance = { roles: [] };
              result.persistedScriptActions.push(runtimeScriptActionInstance);
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                runtimeScriptActionInstance.name = nameInstance;
              }
              
              var uriValue = valueValue['uri'];
              if (uriValue !== null && uriValue !== undefined) {
                var uriInstance = uriValue;
                runtimeScriptActionInstance.uri = uriInstance;
              }
              
              var parametersValue = valueValue['parameters'];
              if (parametersValue !== null && parametersValue !== undefined) {
                var parametersInstance = parametersValue;
                runtimeScriptActionInstance.parameters = parametersInstance;
              }
              
              var rolesArray = valueValue['roles'];
              if (rolesArray !== null && rolesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < rolesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var rolesValue = rolesArray[loweredIndex2];
                  runtimeScriptActionInstance.roles.push(rolesValue);
                }
              }
              
              var applicationNameValue = valueValue['applicationName'];
              if (applicationNameValue !== null && applicationNameValue !== undefined) {
                var applicationNameInstance = applicationNameValue;
                runtimeScriptActionInstance.applicationName = applicationNameInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Lists all scripts execution history for the given cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.listScriptExecutionHistory = function(resourceGroupName, clusterName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '//clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/scriptExecutionHistory';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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['Content-Type'] = 'application/json';
    
    // 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 = { runtimeScriptActionDetail: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var runtimeScriptActionDetailInstance = { executionSummary: [], roles: [] };
              result.runtimeScriptActionDetail.push(runtimeScriptActionDetailInstance);
              
              var scriptExecutionIdValue = valueValue['scriptExecutionId'];
              if (scriptExecutionIdValue !== null && scriptExecutionIdValue !== undefined) {
                var scriptExecutionIdInstance = scriptExecutionIdValue;
                runtimeScriptActionDetailInstance.scriptExecutionId = scriptExecutionIdInstance;
              }
              
              var startTimeValue = valueValue['startTime'];
              if (startTimeValue !== null && startTimeValue !== undefined) {
                var startTimeInstance = startTimeValue;
                runtimeScriptActionDetailInstance.startTime = startTimeInstance;
              }
              
              var endTimeValue = valueValue['endTime'];
              if (endTimeValue !== null && endTimeValue !== undefined) {
                var endTimeInstance = endTimeValue;
                runtimeScriptActionDetailInstance.endTime = endTimeInstance;
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = statusValue;
                runtimeScriptActionDetailInstance.status = statusInstance;
              }
              
              var operationValue = valueValue['operation'];
              if (operationValue !== null && operationValue !== undefined) {
                var operationInstance = operationValue;
                runtimeScriptActionDetailInstance.operation = operationInstance;
              }
              
              var executionSummaryArray = valueValue['executionSummary'];
              if (executionSummaryArray !== null && executionSummaryArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < executionSummaryArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var executionSummaryValue = executionSummaryArray[loweredIndex2];
                  var scriptActionExecutionSummaryInstance = {};
                  runtimeScriptActionDetailInstance.executionSummary.push(scriptActionExecutionSummaryInstance);
                  
                  var statusValue2 = executionSummaryValue['status'];
                  if (statusValue2 !== null && statusValue2 !== undefined) {
                    var statusInstance2 = statusValue2;
                    scriptActionExecutionSummaryInstance.status = statusInstance2;
                  }
                  
                  var instanceCountValue = executionSummaryValue['instanceCount'];
                  if (instanceCountValue !== null && instanceCountValue !== undefined) {
                    var instanceCountInstance = instanceCountValue;
                    scriptActionExecutionSummaryInstance.instanceCount = instanceCountInstance;
                  }
                }
              }
              
              var debugInformationValue = valueValue['debugInformation'];
              if (debugInformationValue !== null && debugInformationValue !== undefined) {
                var debugInformationInstance = debugInformationValue;
                runtimeScriptActionDetailInstance.debugInformation = debugInformationInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                runtimeScriptActionDetailInstance.name = nameInstance;
              }
              
              var uriValue = valueValue['uri'];
              if (uriValue !== null && uriValue !== undefined) {
                var uriInstance = uriValue;
                runtimeScriptActionDetailInstance.uri = uriInstance;
              }
              
              var parametersValue = valueValue['parameters'];
              if (parametersValue !== null && parametersValue !== undefined) {
                var parametersInstance = parametersValue;
                runtimeScriptActionDetailInstance.parameters = parametersInstance;
              }
              
              var rolesArray = valueValue['roles'];
              if (rolesArray !== null && rolesArray !== undefined) {
                for (var loweredIndex3 = 0; loweredIndex3 < rolesArray.length; loweredIndex3 = loweredIndex3 + 1) {
                  var rolesValue = rolesArray[loweredIndex3];
                  runtimeScriptActionDetailInstance.roles.push(rolesValue);
                }
              }
              
              var applicationNameValue = valueValue['applicationName'];
              if (applicationNameValue !== null && applicationNameValue !== undefined) {
                var applicationNameInstance = applicationNameValue;
                runtimeScriptActionDetailInstance.applicationName = applicationNameInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Promote ad-hoc script execution to a persisted script.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {Number} scriptExecutionId The script execution Id
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.promoteScript = function(resourceGroupName, clusterName, scriptExecutionId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (clusterName === null || clusterName === undefined) {
      return callback(new Error('clusterName cannot be null.'));
    }
    if (scriptExecutionId === null || scriptExecutionId === undefined) {
      return callback(new Error('scriptExecutionId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.HDInsight';
    url2 = url2 + '//clusters/';
    url2 = url2 + encodeURIComponent(clusterName);
    url2 = url2 + '/scriptExecutionHistory/';
    url2 = url2 + encodeURIComponent(scriptExecutionId.toString());
    url2 = url2 + '/promote';
    var queryParameters = [];
    queryParameters.push('api-version=2015-03-01-preview');
    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 = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // 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
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Resizes the specified HDInsight cluster.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} clusterName The name of the cluster.
   * 
   * @param {ClusterResizeParameters} resizeParameters The parameters for the
   * resize operation.
   * 
   * @param {number} [resizeParameters.targetInstanceCount] Gets or sets the
   * target instance count for the operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClusterOperations.prototype.resize = function(resourceGroupName, clusterName, resizeParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.clusters.beginResizing(resourceGroupName, clusterName, resizeParameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 60;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getLongRunningOperationStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.state !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = 60;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  return ClusterOperations;
})();
