/* 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 HDInsightJobManagementClient = ( /** @lends HDInsightJobManagementClient */ function() {
  /**
   * @class
   * The HDInsight job client manages jobs against HDInsight clusters.
   * Initializes a new instance of the HDInsightJobManagementClient class.
   * @constructor
   * 
   * @param {string} clusterDnsName The cluster dns name against which the job
   * management is to be performed.
   * 
   * @param {BasicAuthenticationCloudCredentials} credentials Basic
   * authentication credentials for job submission.
   * 
   * @param {string} [credentials.username]
   * 
   * @param {string} [credentials.password]
   * 
   * @param {Array} filters
   */
  function HDInsightJobManagementClient(clusterDnsName, credentials, filters) {
    if (clusterDnsName === null || clusterDnsName === undefined) {
      throw new Error('clusterDnsName cannot be null.');
    }
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    HDInsightJobManagementClient['super_'].call(this, credentials, filters);
    
    this.clusterDnsName = clusterDnsName;
    this.credentials = credentials;
    /**
     * Provides an instance of the [JobOperations](-JobOperations.html) object.
     * @type {object}
     */
    this.jobManagement = new JobOperations(this);
  }
  
  util.inherits(HDInsightJobManagementClient, Service);
  
  
  return HDInsightJobManagementClient;
})();
exports.HDInsightJobManagementClient = HDInsightJobManagementClient;

var JobOperations = ( /** @lends JobOperations */ function() {
  /**
   * @class
   * Operations for managing jobs against HDInsight clusters.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [HDInsightJobManagementClient] {@link
   * HDInsightJobManagementClient~HDInsightJobManagementClient}.
   * See [jobManagement] {@link
   * HDInsightJobManagementClient~HDInsightJobManagementClient#jobManagement}.
   * Initializes a new instance of the JobOperations class.
   * @constructor
   * 
   * @param {HDInsightJobManagementClient} client Reference to the service
   * client.
   */
  function JobOperations(client) {
    this.client = client;
  }
  
  /**
   * Gets the list of jobs from the specified HDInsight cluster.
   * 
   * @param {string} jobId The id of the job.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  JobOperations.prototype.getJob = function(jobId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobId === null || jobId === undefined) {
      return callback(new Error('jobId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'https://';
    url2 = url2 + encodeURIComponent(this.client.clusterDnsName);
    url2 = url2 + '/templeton/v1/jobs/';
    url2 = url2 + encodeURIComponent(jobId);
    var queryParameters = [];
    if (this.client.credentials.username !== null && this.client.credentials.username !== undefined) {
      queryParameters.push('user.name=' + encodeURIComponent(this.client.credentials.username));
    }
    queryParameters.push('fields=*');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/json';
    httpRequest.headers['useragent'] = 'xplat get job';
    httpRequest.headers['User-Agent'] = 'xplat get job';
    
    // 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 jobDetailInstance = {};
          result.jobDetail = jobDetailInstance;
          
          var statusValue = responseDoc['status'];
          if (statusValue !== null && statusValue !== undefined) {
            var statusInstance = {};
            jobDetailInstance.status = statusInstance;
            
            var jpValue = statusValue['jp'];
            if (jpValue !== null && jpValue !== undefined) {
              var jpInstance = jpValue;
              statusInstance.jobPriority = jpInstance;
            }
            
            var jobIDValue = statusValue['jobID'];
            if (jobIDValue !== null && jobIDValue !== undefined) {
              var jobIDInstance = {};
              statusInstance.jobID = jobIDInstance;
              
              var jtIdentifierValue = jobIDValue['jtIdentifier'];
              if (jtIdentifierValue !== null && jtIdentifierValue !== undefined) {
                var jtIdentifierInstance = jtIdentifierValue;
                jobIDInstance.jtIdentifier = jtIdentifierInstance;
              }
              
              var idValue = jobIDValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                jobIDInstance.id = idInstance;
              }
            }
            
            var jobIdValue = statusValue['jobId'];
            if (jobIdValue !== null && jobIdValue !== undefined) {
              var jobIdInstance = jobIdValue;
              statusInstance.jobId = jobIdInstance;
            }
            
            var runStateValue = statusValue['runState'];
            if (runStateValue !== null && runStateValue !== undefined) {
              var runStateInstance = runStateValue;
              statusInstance.runState = runStateInstance;
            }
            
            var userValue = statusValue['user'];
            if (userValue !== null && userValue !== undefined) {
              var userInstance = userValue;
              statusInstance.username = userInstance;
            }
            
            var jobFileValue = statusValue['jobFile'];
            if (jobFileValue !== null && jobFileValue !== undefined) {
              var jobFileInstance = jobFileValue;
              statusInstance.jobFile = jobFileInstance;
            }
            
            var jobCompleteValue = statusValue['jobComplete'];
            if (jobCompleteValue !== null && jobCompleteValue !== undefined) {
              var jobCompleteInstance = jobCompleteValue;
              statusInstance.jobComplete = jobCompleteInstance;
            }
            
            var priorityValue = statusValue['priority'];
            if (priorityValue !== null && priorityValue !== undefined) {
              var priorityInstance = priorityValue;
              statusInstance.priority = priorityInstance;
            }
            
            var stateValue = statusValue['state'];
            if (stateValue !== null && stateValue !== undefined) {
              var stateInstance = stateValue;
              statusInstance.state = stateInstance;
            }
            
            var numReservedSlotsValue = statusValue['numReservedSlots'];
            if (numReservedSlotsValue !== null && numReservedSlotsValue !== undefined) {
              var numReservedSlotsInstance = numReservedSlotsValue;
              statusInstance.numReservedSlots = numReservedSlotsInstance;
            }
            
            var schedulingInfoValue = statusValue['schedulingInfo'];
            if (schedulingInfoValue !== null && schedulingInfoValue !== undefined) {
              var schedulingInfoInstance = schedulingInfoValue;
              statusInstance.schedulingInfo = schedulingInfoInstance;
            }
            
            var reservedMemValue = statusValue['reservedMem'];
            if (reservedMemValue !== null && reservedMemValue !== undefined) {
              var reservedMemInstance = reservedMemValue;
              statusInstance.reservedMem = reservedMemInstance;
            }
            
            var numUsedSlotsValue = statusValue['numUsedSlots'];
            if (numUsedSlotsValue !== null && numUsedSlotsValue !== undefined) {
              var numUsedSlotsInstance = numUsedSlotsValue;
              statusInstance.numUsedSlots = numUsedSlotsInstance;
            }
            
            var failureInfoValue = statusValue['failureInfo'];
            if (failureInfoValue !== null && failureInfoValue !== undefined) {
              var failureInfoInstance = failureInfoValue;
              statusInstance.failureInfo = failureInfoInstance;
            }
            
            var usedMemValue = statusValue['usedMem'];
            if (usedMemValue !== null && usedMemValue !== undefined) {
              var usedMemInstance = usedMemValue;
              statusInstance.usedMem = usedMemInstance;
            }
            
            var neededMemValue = statusValue['neededMem'];
            if (neededMemValue !== null && neededMemValue !== undefined) {
              var neededMemInstance = neededMemValue;
              statusInstance.neededMem = neededMemInstance;
            }
            
            var finishTimeValue = statusValue['finishTime'];
            if (finishTimeValue !== null && finishTimeValue !== undefined) {
              var finishTimeInstance = finishTimeValue;
              statusInstance.finishTime = finishTimeInstance;
            }
            
            var trackingUrlValue = statusValue['trackingUrl'];
            if (trackingUrlValue !== null && trackingUrlValue !== undefined) {
              var trackingUrlInstance = trackingUrlValue;
              statusInstance.trackingUrl = trackingUrlInstance;
            }
            
            var startTimeValue = statusValue['startTime'];
            if (startTimeValue !== null && startTimeValue !== undefined) {
              var startTimeInstance = startTimeValue;
              statusInstance.startTime = startTimeInstance;
            }
            
            var jobNameValue = statusValue['jobName'];
            if (jobNameValue !== null && jobNameValue !== undefined) {
              var jobNameInstance = jobNameValue;
              statusInstance.jobName = jobNameInstance;
            }
            
            var retiredValue = statusValue['retired'];
            if (retiredValue !== null && retiredValue !== undefined) {
              var retiredInstance = retiredValue;
              statusInstance.retired = retiredInstance;
            }
            
            var jobACLsValue = statusValue['jobACLs'];
            if (jobACLsValue !== null && jobACLsValue !== undefined) {
              var jobACLsInstance = {};
              statusInstance.jobACLs = jobACLsInstance;
            }
            
            var queueValue = statusValue['queue'];
            if (queueValue !== null && queueValue !== undefined) {
              var queueInstance = queueValue;
              statusInstance.queue = queueInstance;
            }
            
            var uberValue = statusValue['uber'];
            if (uberValue !== null && uberValue !== undefined) {
              var uberInstance = uberValue;
              statusInstance.uber = uberInstance;
            }
            
            var reduceProgressValue = statusValue['reduceProgress'];
            if (reduceProgressValue !== null && reduceProgressValue !== undefined) {
              var reduceProgressInstance = reduceProgressValue;
              statusInstance.reduceProgress = reduceProgressInstance;
            }
            
            var cleanupProgressValue = statusValue['cleanupProgress'];
            if (cleanupProgressValue !== null && cleanupProgressValue !== undefined) {
              var cleanupProgressInstance = cleanupProgressValue;
              statusInstance.cleanupProgress = cleanupProgressInstance;
            }
            
            var mapProgressValue = statusValue['mapProgress'];
            if (mapProgressValue !== null && mapProgressValue !== undefined) {
              var mapProgressInstance = mapProgressValue;
              statusInstance.mapProgress = mapProgressInstance;
            }
            
            var historyFileValue = statusValue['historyFile'];
            if (historyFileValue !== null && historyFileValue !== undefined) {
              var historyFileInstance = historyFileValue;
              statusInstance.historyFile = historyFileInstance;
            }
            
            var setupProgressValue = statusValue['setupProgress'];
            if (setupProgressValue !== null && setupProgressValue !== undefined) {
              var setupProgressInstance = setupProgressValue;
              statusInstance.setupProgress = setupProgressInstance;
            }
          }
          
          var profileValue = responseDoc['profile'];
          if (profileValue !== null && profileValue !== undefined) {
            var profileInstance = {};
            jobDetailInstance.profile = profileInstance;
            
            var jobFileValue2 = profileValue['jobFile'];
            if (jobFileValue2 !== null && jobFileValue2 !== undefined) {
              var jobFileInstance2 = jobFileValue2;
              profileInstance.jobFile = jobFileInstance2;
            }
            
            var urlValue = profileValue['url'];
            if (urlValue !== null && urlValue !== undefined) {
              var urlInstance = urlValue;
              profileInstance.url = urlInstance;
            }
            
            var queueNameValue = profileValue['queueName'];
            if (queueNameValue !== null && queueNameValue !== undefined) {
              var queueNameInstance = queueNameValue;
              profileInstance.queueName = queueNameInstance;
            }
            
            var jobIDValue2 = profileValue['jobID'];
            if (jobIDValue2 !== null && jobIDValue2 !== undefined) {
              var jobIDInstance2 = {};
              profileInstance.jobID = jobIDInstance2;
              
              var jtIdentifierValue2 = jobIDValue2['jtIdentifier'];
              if (jtIdentifierValue2 !== null && jtIdentifierValue2 !== undefined) {
                var jtIdentifierInstance2 = jtIdentifierValue2;
                jobIDInstance2.jtIdentifier = jtIdentifierInstance2;
              }
              
              var idValue2 = jobIDValue2['id'];
              if (idValue2 !== null && idValue2 !== undefined) {
                var idInstance2 = idValue2;
                jobIDInstance2.id = idInstance2;
              }
            }
            
            var jobNameValue2 = profileValue['jobName'];
            if (jobNameValue2 !== null && jobNameValue2 !== undefined) {
              var jobNameInstance2 = jobNameValue2;
              profileInstance.jobName = jobNameInstance2;
            }
            
            var userValue2 = profileValue['user'];
            if (userValue2 !== null && userValue2 !== undefined) {
              var userInstance2 = userValue2;
              profileInstance.user = userInstance2;
            }
            
            var jobIdValue2 = profileValue['jobId'];
            if (jobIdValue2 !== null && jobIdValue2 !== undefined) {
              var jobIdInstance2 = jobIdValue2;
              profileInstance.jobId = jobIdInstance2;
            }
          }
          
          var idValue3 = responseDoc['id'];
          if (idValue3 !== null && idValue3 !== undefined) {
            var idInstance3 = idValue3;
            jobDetailInstance.id = idInstance3;
          }
          
          var parentIdValue = responseDoc['parentId'];
          if (parentIdValue !== null && parentIdValue !== undefined) {
            var parentIdInstance = parentIdValue;
            jobDetailInstance.parentId = parentIdInstance;
          }
          
          var percentCompleteValue = responseDoc['percentComplete'];
          if (percentCompleteValue !== null && percentCompleteValue !== undefined) {
            var percentCompleteInstance = percentCompleteValue;
            jobDetailInstance.percentComplete = percentCompleteInstance;
          }
          
          var exitValueValue = responseDoc['exitValue'];
          if (exitValueValue !== null && exitValueValue !== undefined) {
            var exitValueInstance = exitValueValue;
            jobDetailInstance.exitValue = exitValueInstance;
          }
          
          var userValue3 = responseDoc['user'];
          if (userValue3 !== null && userValue3 !== undefined) {
            var userInstance3 = userValue3;
            jobDetailInstance.user = userInstance3;
          }
          
          var callbackValue = responseDoc['callback'];
          if (callbackValue !== null && callbackValue !== undefined) {
            var callbackInstance = callbackValue;
            jobDetailInstance.callback = callbackInstance;
          }
          
          var completedValue = responseDoc['completed'];
          if (completedValue !== null && completedValue !== undefined) {
            var completedInstance = completedValue;
            jobDetailInstance.completed = completedInstance;
          }
          
          var userargsValue = responseDoc['userargs'];
          if (userargsValue !== null && userargsValue !== undefined) {
            var userargsInstance = { arg: [], define: [] };
            jobDetailInstance.userargs = userargsInstance;
            
            var argArray = userargsValue['arg'];
            if (argArray !== null && argArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < argArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var argValue = argArray[loweredIndex1];
                userargsInstance.arg.push(argValue);
              }
            }
            
            var statusdirValue = userargsValue['statusdir'];
            if (statusdirValue !== null && statusdirValue !== undefined) {
              var statusdirInstance = statusdirValue;
              userargsInstance.statusdir = statusdirInstance;
            }
            
            var filesValue = userargsValue['files'];
            if (filesValue !== null && filesValue !== undefined) {
              var filesInstance = filesValue;
              userargsInstance.files = filesInstance;
            }
            
            var defineArray = userargsValue['define'];
            if (defineArray !== null && defineArray !== undefined) {
              for (var loweredIndex2 = 0; loweredIndex2 < defineArray.length; loweredIndex2 = loweredIndex2 + 1) {
                var defineValue = defineArray[loweredIndex2];
                userargsInstance.define.push(defineValue);
              }
            }
            
            var enablelogValue = userargsValue['enablelog'];
            if (enablelogValue !== null && enablelogValue !== undefined) {
              var enablelogInstance = enablelogValue;
              userargsInstance.enablelog = enablelogInstance;
            }
            
            var executeValue = userargsValue['execute'];
            if (executeValue !== null && executeValue !== undefined) {
              var executeInstance = executeValue;
              userargsInstance.execute = executeInstance;
            }
            
            var usernameValue = userargsValue['user.name'];
            if (usernameValue !== null && usernameValue !== undefined) {
              var usernameInstance = usernameValue;
              userargsInstance.username = usernameInstance;
            }
            
            var callbackValue2 = userargsValue['callback'];
            if (callbackValue2 !== null && callbackValue2 !== undefined) {
              var callbackInstance2 = callbackValue2;
              userargsInstance.callback = callbackInstance2;
            }
            
            var fileValue = userargsValue['file'];
            if (fileValue !== null && fileValue !== undefined) {
              var fileInstance = fileValue;
              userargsInstance.file = fileInstance;
            }
            
            var jarValue = userargsValue['jar'];
            if (jarValue !== null && jarValue !== undefined) {
              var jarInstance = jarValue;
              userargsInstance.jar = jarInstance;
            }
          }
          
          var msgValue = responseDoc['msg'];
          if (msgValue !== null && msgValue !== undefined) {
            var msgInstance = msgValue;
            jobDetailInstance.msg = msgInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the list of jobs from the specified HDInsight cluster.
   * 
   * @param {string} jobId The id of the job.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  JobOperations.prototype.killJob = function(jobId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobId === null || jobId === undefined) {
      return callback(new Error('jobId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'https://';
    url2 = url2 + encodeURIComponent(this.client.clusterDnsName);
    url2 = url2 + '/templeton/v1/jobs/';
    url2 = url2 + encodeURIComponent(jobId);
    var queryParameters = [];
    if (this.client.credentials.username !== null && this.client.credentials.username !== undefined) {
      queryParameters.push('user.name=' + encodeURIComponent(this.client.credentials.username));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/json';
    httpRequest.headers['useragent'] = 'xplat get job';
    httpRequest.headers['User-Agent'] = 'xplat get job';
    
    // 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 jobDetailInstance = {};
          result.jobDetail = jobDetailInstance;
          
          var statusValue = responseDoc['status'];
          if (statusValue !== null && statusValue !== undefined) {
            var statusInstance = {};
            jobDetailInstance.status = statusInstance;
            
            var jpValue = statusValue['jp'];
            if (jpValue !== null && jpValue !== undefined) {
              var jpInstance = jpValue;
              statusInstance.jobPriority = jpInstance;
            }
            
            var jobIDValue = statusValue['jobID'];
            if (jobIDValue !== null && jobIDValue !== undefined) {
              var jobIDInstance = {};
              statusInstance.jobID = jobIDInstance;
              
              var jtIdentifierValue = jobIDValue['jtIdentifier'];
              if (jtIdentifierValue !== null && jtIdentifierValue !== undefined) {
                var jtIdentifierInstance = jtIdentifierValue;
                jobIDInstance.jtIdentifier = jtIdentifierInstance;
              }
              
              var idValue = jobIDValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                jobIDInstance.id = idInstance;
              }
            }
            
            var jobIdValue = statusValue['jobId'];
            if (jobIdValue !== null && jobIdValue !== undefined) {
              var jobIdInstance = jobIdValue;
              statusInstance.jobId = jobIdInstance;
            }
            
            var runStateValue = statusValue['runState'];
            if (runStateValue !== null && runStateValue !== undefined) {
              var runStateInstance = runStateValue;
              statusInstance.runState = runStateInstance;
            }
            
            var userValue = statusValue['user'];
            if (userValue !== null && userValue !== undefined) {
              var userInstance = userValue;
              statusInstance.username = userInstance;
            }
            
            var jobFileValue = statusValue['jobFile'];
            if (jobFileValue !== null && jobFileValue !== undefined) {
              var jobFileInstance = jobFileValue;
              statusInstance.jobFile = jobFileInstance;
            }
            
            var jobCompleteValue = statusValue['jobComplete'];
            if (jobCompleteValue !== null && jobCompleteValue !== undefined) {
              var jobCompleteInstance = jobCompleteValue;
              statusInstance.jobComplete = jobCompleteInstance;
            }
            
            var priorityValue = statusValue['priority'];
            if (priorityValue !== null && priorityValue !== undefined) {
              var priorityInstance = priorityValue;
              statusInstance.priority = priorityInstance;
            }
            
            var stateValue = statusValue['state'];
            if (stateValue !== null && stateValue !== undefined) {
              var stateInstance = stateValue;
              statusInstance.state = stateInstance;
            }
            
            var numReservedSlotsValue = statusValue['numReservedSlots'];
            if (numReservedSlotsValue !== null && numReservedSlotsValue !== undefined) {
              var numReservedSlotsInstance = numReservedSlotsValue;
              statusInstance.numReservedSlots = numReservedSlotsInstance;
            }
            
            var schedulingInfoValue = statusValue['schedulingInfo'];
            if (schedulingInfoValue !== null && schedulingInfoValue !== undefined) {
              var schedulingInfoInstance = schedulingInfoValue;
              statusInstance.schedulingInfo = schedulingInfoInstance;
            }
            
            var reservedMemValue = statusValue['reservedMem'];
            if (reservedMemValue !== null && reservedMemValue !== undefined) {
              var reservedMemInstance = reservedMemValue;
              statusInstance.reservedMem = reservedMemInstance;
            }
            
            var numUsedSlotsValue = statusValue['numUsedSlots'];
            if (numUsedSlotsValue !== null && numUsedSlotsValue !== undefined) {
              var numUsedSlotsInstance = numUsedSlotsValue;
              statusInstance.numUsedSlots = numUsedSlotsInstance;
            }
            
            var failureInfoValue = statusValue['failureInfo'];
            if (failureInfoValue !== null && failureInfoValue !== undefined) {
              var failureInfoInstance = failureInfoValue;
              statusInstance.failureInfo = failureInfoInstance;
            }
            
            var usedMemValue = statusValue['usedMem'];
            if (usedMemValue !== null && usedMemValue !== undefined) {
              var usedMemInstance = usedMemValue;
              statusInstance.usedMem = usedMemInstance;
            }
            
            var neededMemValue = statusValue['neededMem'];
            if (neededMemValue !== null && neededMemValue !== undefined) {
              var neededMemInstance = neededMemValue;
              statusInstance.neededMem = neededMemInstance;
            }
            
            var finishTimeValue = statusValue['finishTime'];
            if (finishTimeValue !== null && finishTimeValue !== undefined) {
              var finishTimeInstance = finishTimeValue;
              statusInstance.finishTime = finishTimeInstance;
            }
            
            var trackingUrlValue = statusValue['trackingUrl'];
            if (trackingUrlValue !== null && trackingUrlValue !== undefined) {
              var trackingUrlInstance = trackingUrlValue;
              statusInstance.trackingUrl = trackingUrlInstance;
            }
            
            var startTimeValue = statusValue['startTime'];
            if (startTimeValue !== null && startTimeValue !== undefined) {
              var startTimeInstance = startTimeValue;
              statusInstance.startTime = startTimeInstance;
            }
            
            var jobNameValue = statusValue['jobName'];
            if (jobNameValue !== null && jobNameValue !== undefined) {
              var jobNameInstance = jobNameValue;
              statusInstance.jobName = jobNameInstance;
            }
            
            var retiredValue = statusValue['retired'];
            if (retiredValue !== null && retiredValue !== undefined) {
              var retiredInstance = retiredValue;
              statusInstance.retired = retiredInstance;
            }
            
            var jobACLsValue = statusValue['jobACLs'];
            if (jobACLsValue !== null && jobACLsValue !== undefined) {
              var jobACLsInstance = {};
              statusInstance.jobACLs = jobACLsInstance;
            }
            
            var queueValue = statusValue['queue'];
            if (queueValue !== null && queueValue !== undefined) {
              var queueInstance = queueValue;
              statusInstance.queue = queueInstance;
            }
            
            var uberValue = statusValue['uber'];
            if (uberValue !== null && uberValue !== undefined) {
              var uberInstance = uberValue;
              statusInstance.uber = uberInstance;
            }
            
            var reduceProgressValue = statusValue['reduceProgress'];
            if (reduceProgressValue !== null && reduceProgressValue !== undefined) {
              var reduceProgressInstance = reduceProgressValue;
              statusInstance.reduceProgress = reduceProgressInstance;
            }
            
            var cleanupProgressValue = statusValue['cleanupProgress'];
            if (cleanupProgressValue !== null && cleanupProgressValue !== undefined) {
              var cleanupProgressInstance = cleanupProgressValue;
              statusInstance.cleanupProgress = cleanupProgressInstance;
            }
            
            var mapProgressValue = statusValue['mapProgress'];
            if (mapProgressValue !== null && mapProgressValue !== undefined) {
              var mapProgressInstance = mapProgressValue;
              statusInstance.mapProgress = mapProgressInstance;
            }
            
            var historyFileValue = statusValue['historyFile'];
            if (historyFileValue !== null && historyFileValue !== undefined) {
              var historyFileInstance = historyFileValue;
              statusInstance.historyFile = historyFileInstance;
            }
            
            var setupProgressValue = statusValue['setupProgress'];
            if (setupProgressValue !== null && setupProgressValue !== undefined) {
              var setupProgressInstance = setupProgressValue;
              statusInstance.setupProgress = setupProgressInstance;
            }
          }
          
          var profileValue = responseDoc['profile'];
          if (profileValue !== null && profileValue !== undefined) {
            var profileInstance = {};
            jobDetailInstance.profile = profileInstance;
            
            var jobFileValue2 = profileValue['jobFile'];
            if (jobFileValue2 !== null && jobFileValue2 !== undefined) {
              var jobFileInstance2 = jobFileValue2;
              profileInstance.jobFile = jobFileInstance2;
            }
            
            var urlValue = profileValue['url'];
            if (urlValue !== null && urlValue !== undefined) {
              var urlInstance = urlValue;
              profileInstance.url = urlInstance;
            }
            
            var queueNameValue = profileValue['queueName'];
            if (queueNameValue !== null && queueNameValue !== undefined) {
              var queueNameInstance = queueNameValue;
              profileInstance.queueName = queueNameInstance;
            }
            
            var jobIDValue2 = profileValue['jobID'];
            if (jobIDValue2 !== null && jobIDValue2 !== undefined) {
              var jobIDInstance2 = {};
              profileInstance.jobID = jobIDInstance2;
              
              var jtIdentifierValue2 = jobIDValue2['jtIdentifier'];
              if (jtIdentifierValue2 !== null && jtIdentifierValue2 !== undefined) {
                var jtIdentifierInstance2 = jtIdentifierValue2;
                jobIDInstance2.jtIdentifier = jtIdentifierInstance2;
              }
              
              var idValue2 = jobIDValue2['id'];
              if (idValue2 !== null && idValue2 !== undefined) {
                var idInstance2 = idValue2;
                jobIDInstance2.id = idInstance2;
              }
            }
            
            var jobNameValue2 = profileValue['jobName'];
            if (jobNameValue2 !== null && jobNameValue2 !== undefined) {
              var jobNameInstance2 = jobNameValue2;
              profileInstance.jobName = jobNameInstance2;
            }
            
            var userValue2 = profileValue['user'];
            if (userValue2 !== null && userValue2 !== undefined) {
              var userInstance2 = userValue2;
              profileInstance.user = userInstance2;
            }
            
            var jobIdValue2 = profileValue['jobId'];
            if (jobIdValue2 !== null && jobIdValue2 !== undefined) {
              var jobIdInstance2 = jobIdValue2;
              profileInstance.jobId = jobIdInstance2;
            }
          }
          
          var idValue3 = responseDoc['id'];
          if (idValue3 !== null && idValue3 !== undefined) {
            var idInstance3 = idValue3;
            jobDetailInstance.id = idInstance3;
          }
          
          var parentIdValue = responseDoc['parentId'];
          if (parentIdValue !== null && parentIdValue !== undefined) {
            var parentIdInstance = parentIdValue;
            jobDetailInstance.parentId = parentIdInstance;
          }
          
          var percentCompleteValue = responseDoc['percentComplete'];
          if (percentCompleteValue !== null && percentCompleteValue !== undefined) {
            var percentCompleteInstance = percentCompleteValue;
            jobDetailInstance.percentComplete = percentCompleteInstance;
          }
          
          var exitValueValue = responseDoc['exitValue'];
          if (exitValueValue !== null && exitValueValue !== undefined) {
            var exitValueInstance = exitValueValue;
            jobDetailInstance.exitValue = exitValueInstance;
          }
          
          var userValue3 = responseDoc['user'];
          if (userValue3 !== null && userValue3 !== undefined) {
            var userInstance3 = userValue3;
            jobDetailInstance.user = userInstance3;
          }
          
          var callbackValue = responseDoc['callback'];
          if (callbackValue !== null && callbackValue !== undefined) {
            var callbackInstance = callbackValue;
            jobDetailInstance.callback = callbackInstance;
          }
          
          var completedValue = responseDoc['completed'];
          if (completedValue !== null && completedValue !== undefined) {
            var completedInstance = completedValue;
            jobDetailInstance.completed = completedInstance;
          }
          
          var userargsValue = responseDoc['userargs'];
          if (userargsValue !== null && userargsValue !== undefined) {
            var userargsInstance = { arg: [], define: [] };
            jobDetailInstance.userargs = userargsInstance;
            
            var argArray = userargsValue['arg'];
            if (argArray !== null && argArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < argArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var argValue = argArray[loweredIndex1];
                userargsInstance.arg.push(argValue);
              }
            }
            
            var statusdirValue = userargsValue['statusdir'];
            if (statusdirValue !== null && statusdirValue !== undefined) {
              var statusdirInstance = statusdirValue;
              userargsInstance.statusdir = statusdirInstance;
            }
            
            var filesValue = userargsValue['files'];
            if (filesValue !== null && filesValue !== undefined) {
              var filesInstance = filesValue;
              userargsInstance.files = filesInstance;
            }
            
            var defineArray = userargsValue['define'];
            if (defineArray !== null && defineArray !== undefined) {
              for (var loweredIndex2 = 0; loweredIndex2 < defineArray.length; loweredIndex2 = loweredIndex2 + 1) {
                var defineValue = defineArray[loweredIndex2];
                userargsInstance.define.push(defineValue);
              }
            }
            
            var enablelogValue = userargsValue['enablelog'];
            if (enablelogValue !== null && enablelogValue !== undefined) {
              var enablelogInstance = enablelogValue;
              userargsInstance.enablelog = enablelogInstance;
            }
            
            var executeValue = userargsValue['execute'];
            if (executeValue !== null && executeValue !== undefined) {
              var executeInstance = executeValue;
              userargsInstance.execute = executeInstance;
            }
            
            var usernameValue = userargsValue['user.name'];
            if (usernameValue !== null && usernameValue !== undefined) {
              var usernameInstance = usernameValue;
              userargsInstance.username = usernameInstance;
            }
            
            var callbackValue2 = userargsValue['callback'];
            if (callbackValue2 !== null && callbackValue2 !== undefined) {
              var callbackInstance2 = callbackValue2;
              userargsInstance.callback = callbackInstance2;
            }
            
            var fileValue = userargsValue['file'];
            if (fileValue !== null && fileValue !== undefined) {
              var fileInstance = fileValue;
              userargsInstance.file = fileInstance;
            }
            
            var jarValue = userargsValue['jar'];
            if (jarValue !== null && jarValue !== undefined) {
              var jarInstance = jarValue;
              userargsInstance.jar = jarInstance;
            }
          }
          
          var msgValue = responseDoc['msg'];
          if (msgValue !== null && msgValue !== undefined) {
            var msgInstance = msgValue;
            jobDetailInstance.msg = msgInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the list of jobs from the specified HDInsight cluster.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  JobOperations.prototype.listJobs = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'https://';
    url2 = url2 + encodeURIComponent(this.client.clusterDnsName);
    url2 = url2 + '/templeton/v1/jobs';
    var queryParameters = [];
    if (this.client.credentials.username !== null && this.client.credentials.username !== undefined) {
      queryParameters.push('user.name=' + encodeURIComponent(this.client.credentials.username));
    }
    queryParameters.push('showall=true');
    queryParameters.push('fields=*');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/json';
    httpRequest.headers['useragent'] = 'xplat list jobs';
    httpRequest.headers['User-Agent'] = 'xplat list jobs';
    
    // 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 = { jobList: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var jobListArray = responseDoc;
          if (jobListArray !== null && jobListArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < jobListArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var jobListValue = jobListArray[loweredIndex1];
              var jobListJsonObjectInstance = {};
              result.jobList.push(jobListJsonObjectInstance);
              
              var detailValue = jobListValue['detail'];
              if (detailValue !== null && detailValue !== undefined) {
                var detailInstance = {};
                jobListJsonObjectInstance.detail = detailInstance;
                
                var statusValue = detailValue['status'];
                if (statusValue !== null && statusValue !== undefined) {
                  var statusInstance = {};
                  detailInstance.status = statusInstance;
                  
                  var jpValue = statusValue['jp'];
                  if (jpValue !== null && jpValue !== undefined) {
                    var jpInstance = jpValue;
                    statusInstance.jobPriority = jpInstance;
                  }
                  
                  var jobIDValue = statusValue['jobID'];
                  if (jobIDValue !== null && jobIDValue !== undefined) {
                    var jobIDInstance = {};
                    statusInstance.jobID = jobIDInstance;
                    
                    var jtIdentifierValue = jobIDValue['jtIdentifier'];
                    if (jtIdentifierValue !== null && jtIdentifierValue !== undefined) {
                      var jtIdentifierInstance = jtIdentifierValue;
                      jobIDInstance.jtIdentifier = jtIdentifierInstance;
                    }
                    
                    var idValue = jobIDValue['id'];
                    if (idValue !== null && idValue !== undefined) {
                      var idInstance = idValue;
                      jobIDInstance.id = idInstance;
                    }
                  }
                  
                  var jobIdValue = statusValue['jobId'];
                  if (jobIdValue !== null && jobIdValue !== undefined) {
                    var jobIdInstance = jobIdValue;
                    statusInstance.jobId = jobIdInstance;
                  }
                  
                  var runStateValue = statusValue['runState'];
                  if (runStateValue !== null && runStateValue !== undefined) {
                    var runStateInstance = runStateValue;
                    statusInstance.runState = runStateInstance;
                  }
                  
                  var userValue = statusValue['user'];
                  if (userValue !== null && userValue !== undefined) {
                    var userInstance = userValue;
                    statusInstance.username = userInstance;
                  }
                  
                  var jobFileValue = statusValue['jobFile'];
                  if (jobFileValue !== null && jobFileValue !== undefined) {
                    var jobFileInstance = jobFileValue;
                    statusInstance.jobFile = jobFileInstance;
                  }
                  
                  var jobCompleteValue = statusValue['jobComplete'];
                  if (jobCompleteValue !== null && jobCompleteValue !== undefined) {
                    var jobCompleteInstance = jobCompleteValue;
                    statusInstance.jobComplete = jobCompleteInstance;
                  }
                  
                  var priorityValue = statusValue['priority'];
                  if (priorityValue !== null && priorityValue !== undefined) {
                    var priorityInstance = priorityValue;
                    statusInstance.priority = priorityInstance;
                  }
                  
                  var stateValue = statusValue['state'];
                  if (stateValue !== null && stateValue !== undefined) {
                    var stateInstance = stateValue;
                    statusInstance.state = stateInstance;
                  }
                  
                  var numReservedSlotsValue = statusValue['numReservedSlots'];
                  if (numReservedSlotsValue !== null && numReservedSlotsValue !== undefined) {
                    var numReservedSlotsInstance = numReservedSlotsValue;
                    statusInstance.numReservedSlots = numReservedSlotsInstance;
                  }
                  
                  var schedulingInfoValue = statusValue['schedulingInfo'];
                  if (schedulingInfoValue !== null && schedulingInfoValue !== undefined) {
                    var schedulingInfoInstance = schedulingInfoValue;
                    statusInstance.schedulingInfo = schedulingInfoInstance;
                  }
                  
                  var reservedMemValue = statusValue['reservedMem'];
                  if (reservedMemValue !== null && reservedMemValue !== undefined) {
                    var reservedMemInstance = reservedMemValue;
                    statusInstance.reservedMem = reservedMemInstance;
                  }
                  
                  var numUsedSlotsValue = statusValue['numUsedSlots'];
                  if (numUsedSlotsValue !== null && numUsedSlotsValue !== undefined) {
                    var numUsedSlotsInstance = numUsedSlotsValue;
                    statusInstance.numUsedSlots = numUsedSlotsInstance;
                  }
                  
                  var failureInfoValue = statusValue['failureInfo'];
                  if (failureInfoValue !== null && failureInfoValue !== undefined) {
                    var failureInfoInstance = failureInfoValue;
                    statusInstance.failureInfo = failureInfoInstance;
                  }
                  
                  var usedMemValue = statusValue['usedMem'];
                  if (usedMemValue !== null && usedMemValue !== undefined) {
                    var usedMemInstance = usedMemValue;
                    statusInstance.usedMem = usedMemInstance;
                  }
                  
                  var neededMemValue = statusValue['neededMem'];
                  if (neededMemValue !== null && neededMemValue !== undefined) {
                    var neededMemInstance = neededMemValue;
                    statusInstance.neededMem = neededMemInstance;
                  }
                  
                  var finishTimeValue = statusValue['finishTime'];
                  if (finishTimeValue !== null && finishTimeValue !== undefined) {
                    var finishTimeInstance = finishTimeValue;
                    statusInstance.finishTime = finishTimeInstance;
                  }
                  
                  var trackingUrlValue = statusValue['trackingUrl'];
                  if (trackingUrlValue !== null && trackingUrlValue !== undefined) {
                    var trackingUrlInstance = trackingUrlValue;
                    statusInstance.trackingUrl = trackingUrlInstance;
                  }
                  
                  var startTimeValue = statusValue['startTime'];
                  if (startTimeValue !== null && startTimeValue !== undefined) {
                    var startTimeInstance = startTimeValue;
                    statusInstance.startTime = startTimeInstance;
                  }
                  
                  var jobNameValue = statusValue['jobName'];
                  if (jobNameValue !== null && jobNameValue !== undefined) {
                    var jobNameInstance = jobNameValue;
                    statusInstance.jobName = jobNameInstance;
                  }
                  
                  var retiredValue = statusValue['retired'];
                  if (retiredValue !== null && retiredValue !== undefined) {
                    var retiredInstance = retiredValue;
                    statusInstance.retired = retiredInstance;
                  }
                  
                  var jobACLsValue = statusValue['jobACLs'];
                  if (jobACLsValue !== null && jobACLsValue !== undefined) {
                    var jobACLsInstance = {};
                    statusInstance.jobACLs = jobACLsInstance;
                  }
                  
                  var queueValue = statusValue['queue'];
                  if (queueValue !== null && queueValue !== undefined) {
                    var queueInstance = queueValue;
                    statusInstance.queue = queueInstance;
                  }
                  
                  var uberValue = statusValue['uber'];
                  if (uberValue !== null && uberValue !== undefined) {
                    var uberInstance = uberValue;
                    statusInstance.uber = uberInstance;
                  }
                  
                  var reduceProgressValue = statusValue['reduceProgress'];
                  if (reduceProgressValue !== null && reduceProgressValue !== undefined) {
                    var reduceProgressInstance = reduceProgressValue;
                    statusInstance.reduceProgress = reduceProgressInstance;
                  }
                  
                  var cleanupProgressValue = statusValue['cleanupProgress'];
                  if (cleanupProgressValue !== null && cleanupProgressValue !== undefined) {
                    var cleanupProgressInstance = cleanupProgressValue;
                    statusInstance.cleanupProgress = cleanupProgressInstance;
                  }
                  
                  var mapProgressValue = statusValue['mapProgress'];
                  if (mapProgressValue !== null && mapProgressValue !== undefined) {
                    var mapProgressInstance = mapProgressValue;
                    statusInstance.mapProgress = mapProgressInstance;
                  }
                  
                  var historyFileValue = statusValue['historyFile'];
                  if (historyFileValue !== null && historyFileValue !== undefined) {
                    var historyFileInstance = historyFileValue;
                    statusInstance.historyFile = historyFileInstance;
                  }
                  
                  var setupProgressValue = statusValue['setupProgress'];
                  if (setupProgressValue !== null && setupProgressValue !== undefined) {
                    var setupProgressInstance = setupProgressValue;
                    statusInstance.setupProgress = setupProgressInstance;
                  }
                }
                
                var profileValue = detailValue['profile'];
                if (profileValue !== null && profileValue !== undefined) {
                  var profileInstance = {};
                  detailInstance.profile = profileInstance;
                  
                  var jobFileValue2 = profileValue['jobFile'];
                  if (jobFileValue2 !== null && jobFileValue2 !== undefined) {
                    var jobFileInstance2 = jobFileValue2;
                    profileInstance.jobFile = jobFileInstance2;
                  }
                  
                  var urlValue = profileValue['url'];
                  if (urlValue !== null && urlValue !== undefined) {
                    var urlInstance = urlValue;
                    profileInstance.url = urlInstance;
                  }
                  
                  var queueNameValue = profileValue['queueName'];
                  if (queueNameValue !== null && queueNameValue !== undefined) {
                    var queueNameInstance = queueNameValue;
                    profileInstance.queueName = queueNameInstance;
                  }
                  
                  var jobIDValue2 = profileValue['jobID'];
                  if (jobIDValue2 !== null && jobIDValue2 !== undefined) {
                    var jobIDInstance2 = {};
                    profileInstance.jobID = jobIDInstance2;
                    
                    var jtIdentifierValue2 = jobIDValue2['jtIdentifier'];
                    if (jtIdentifierValue2 !== null && jtIdentifierValue2 !== undefined) {
                      var jtIdentifierInstance2 = jtIdentifierValue2;
                      jobIDInstance2.jtIdentifier = jtIdentifierInstance2;
                    }
                    
                    var idValue2 = jobIDValue2['id'];
                    if (idValue2 !== null && idValue2 !== undefined) {
                      var idInstance2 = idValue2;
                      jobIDInstance2.id = idInstance2;
                    }
                  }
                  
                  var jobNameValue2 = profileValue['jobName'];
                  if (jobNameValue2 !== null && jobNameValue2 !== undefined) {
                    var jobNameInstance2 = jobNameValue2;
                    profileInstance.jobName = jobNameInstance2;
                  }
                  
                  var userValue2 = profileValue['user'];
                  if (userValue2 !== null && userValue2 !== undefined) {
                    var userInstance2 = userValue2;
                    profileInstance.user = userInstance2;
                  }
                  
                  var jobIdValue2 = profileValue['jobId'];
                  if (jobIdValue2 !== null && jobIdValue2 !== undefined) {
                    var jobIdInstance2 = jobIdValue2;
                    profileInstance.jobId = jobIdInstance2;
                  }
                }
                
                var idValue3 = detailValue['id'];
                if (idValue3 !== null && idValue3 !== undefined) {
                  var idInstance3 = idValue3;
                  detailInstance.id = idInstance3;
                }
                
                var parentIdValue = detailValue['parentId'];
                if (parentIdValue !== null && parentIdValue !== undefined) {
                  var parentIdInstance = parentIdValue;
                  detailInstance.parentId = parentIdInstance;
                }
                
                var percentCompleteValue = detailValue['percentComplete'];
                if (percentCompleteValue !== null && percentCompleteValue !== undefined) {
                  var percentCompleteInstance = percentCompleteValue;
                  detailInstance.percentComplete = percentCompleteInstance;
                }
                
                var exitValueValue = detailValue['exitValue'];
                if (exitValueValue !== null && exitValueValue !== undefined) {
                  var exitValueInstance = exitValueValue;
                  detailInstance.exitValue = exitValueInstance;
                }
                
                var userValue3 = detailValue['user'];
                if (userValue3 !== null && userValue3 !== undefined) {
                  var userInstance3 = userValue3;
                  detailInstance.user = userInstance3;
                }
                
                var callbackValue = detailValue['callback'];
                if (callbackValue !== null && callbackValue !== undefined) {
                  var callbackInstance = callbackValue;
                  detailInstance.callback = callbackInstance;
                }
                
                var completedValue = detailValue['completed'];
                if (completedValue !== null && completedValue !== undefined) {
                  var completedInstance = completedValue;
                  detailInstance.completed = completedInstance;
                }
                
                var userargsValue = detailValue['userargs'];
                if (userargsValue !== null && userargsValue !== undefined) {
                  var userargsInstance = { arg: [], define: [] };
                  detailInstance.userargs = userargsInstance;
                  
                  var argArray = userargsValue['arg'];
                  if (argArray !== null && argArray !== undefined) {
                    for (var loweredIndex2 = 0; loweredIndex2 < argArray.length; loweredIndex2 = loweredIndex2 + 1) {
                      var argValue = argArray[loweredIndex2];
                      userargsInstance.arg.push(argValue);
                    }
                  }
                  
                  var statusdirValue = userargsValue['statusdir'];
                  if (statusdirValue !== null && statusdirValue !== undefined) {
                    var statusdirInstance = statusdirValue;
                    userargsInstance.statusdir = statusdirInstance;
                  }
                  
                  var filesValue = userargsValue['files'];
                  if (filesValue !== null && filesValue !== undefined) {
                    var filesInstance = filesValue;
                    userargsInstance.files = filesInstance;
                  }
                  
                  var defineArray = userargsValue['define'];
                  if (defineArray !== null && defineArray !== undefined) {
                    for (var loweredIndex3 = 0; loweredIndex3 < defineArray.length; loweredIndex3 = loweredIndex3 + 1) {
                      var defineValue = defineArray[loweredIndex3];
                      userargsInstance.define.push(defineValue);
                    }
                  }
                  
                  var enablelogValue = userargsValue['enablelog'];
                  if (enablelogValue !== null && enablelogValue !== undefined) {
                    var enablelogInstance = enablelogValue;
                    userargsInstance.enablelog = enablelogInstance;
                  }
                  
                  var executeValue = userargsValue['execute'];
                  if (executeValue !== null && executeValue !== undefined) {
                    var executeInstance = executeValue;
                    userargsInstance.execute = executeInstance;
                  }
                  
                  var usernameValue = userargsValue['user.name'];
                  if (usernameValue !== null && usernameValue !== undefined) {
                    var usernameInstance = usernameValue;
                    userargsInstance.username = usernameInstance;
                  }
                  
                  var callbackValue2 = userargsValue['callback'];
                  if (callbackValue2 !== null && callbackValue2 !== undefined) {
                    var callbackInstance2 = callbackValue2;
                    userargsInstance.callback = callbackInstance2;
                  }
                  
                  var fileValue = userargsValue['file'];
                  if (fileValue !== null && fileValue !== undefined) {
                    var fileInstance = fileValue;
                    userargsInstance.file = fileInstance;
                  }
                  
                  var jarValue = userargsValue['jar'];
                  if (jarValue !== null && jarValue !== undefined) {
                    var jarInstance = jarValue;
                    userargsInstance.jar = jarInstance;
                  }
                }
                
                var msgValue = detailValue['msg'];
                if (msgValue !== null && msgValue !== undefined) {
                  var msgInstance = msgValue;
                  detailInstance.msg = msgInstance;
                }
              }
              
              var idValue4 = jobListValue['id'];
              if (idValue4 !== null && idValue4 !== undefined) {
                var idInstance4 = idValue4;
                jobListJsonObjectInstance.id = idInstance4;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Submits an Hive job to an HDINSIGHT cluster.
   * 
   * @param {HiveJobSubmissionParameters} parameters Hive job parameters.
   * 
   * @param {string} [parameters.query] One of either "execute" or "file" is required.
   * 
   * @param {string} [parameters.userName]
   * 
   * @param {string} [parameters.file] One of either "execute" or "file" is required.
   * 
   * @param {string} [parameters.files] optional in Hive 0.12.0+
   * 
   * @param {string} [parameters.defines]
   * 
   * @param {string} [parameters.arguments] optional in Hive 0.12.0+
   * 
   * @param {string} [parameters.statusDir] 
   * 
   * @param {string} [parameters.enableLog] optional in Hive 0.12.0+
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  JobOperations.prototype.submitHiveJob = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'https://';
    url2 = url2 + encodeURIComponent(this.client.clusterDnsName);
    url2 = url2 + '/templeton/v1/hive';
    var queryParameters = [];
    if (this.client.credentials.username !== null && this.client.credentials.username !== undefined) {
      queryParameters.push('user.name=' + encodeURIComponent(this.client.credentials.username));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/json';
    httpRequest.headers['Content-Type'] = 'application/text';
    httpRequest.headers['useragent'] = 'xplat Hive job submission';
    httpRequest.headers['User-Agent'] = 'xplat Hive job submission';
    
    // Serialize Request
    var requestContent = '';
    if (!parameters.query && !parameters.file) {
	    throw new Error('One of either "execute" or "file" is required.');
    }
    if (parameters.username) {
	    requestContent += 'user.name=' + parameters.username;
    }
    if (parameters.query) {
	    requestContent += '&execute=' + parameters.query;
    }
    if (parameters.file) {
	    requestContent += '&file=' + parameters.file;
    }
    if (parameters.arguments) {
	    requestContent += '&arg=' + parameters.arguments;
    }
    if (parameters.files) {
	    requestContent += '&files=' + parameters.files;
    }
    if (parameters.statusDir) {
	    requestContent += '&statusdir=' + parameters.statusDir;
    }
    if (parameters.enableLog) {
	    requestContent += '&enablelog=' + parameters.enableLog;
    }
    if (parameters.defines) {
	    requestContent += '&define=' + encodeURIComponent(parameters.defines);
    }
    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) {
        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 jobSubmissionJsonResponseInstance = {};
          result.jobSubmissionJsonResponse = jobSubmissionJsonResponseInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            jobSubmissionJsonResponseInstance.id = idInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Submits a MapReduce job to an HDINSIGHT cluster.
   * 
   * @param {MapReduceJobSubmissionParameters} parameters MapReduce job
   * parameters.
   * 
   * @param {string} [parameters.userName]
   * 
   * @param {string} [parameters.jarFile]
   * 
   * @param {string} [parameters.jarClass]
   * 
   * @param {string} [parameters.libJars]
   * 
   * @param {string} [parameters.files]
   * 
   * @param {string} [parameters.defines]
   * 
   * @param {string} [parameters.arguments]
   * 
   * @param {string} [parameters.statusDir]
   * 
   * @param {string} [parameters.enableLog]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  JobOperations.prototype.submitMapReduceJob = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'https://';
    url2 = url2 + encodeURIComponent(this.client.clusterDnsName);
    url2 = url2 + '/templeton/v1/mapreduce/jar';
    var queryParameters = [];
    if (this.client.credentials.username !== null && this.client.credentials.username !== undefined) {
      queryParameters.push('user.name=' + encodeURIComponent(this.client.credentials.username));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/json';
    httpRequest.headers['Content-Type'] = 'application/text';
    httpRequest.headers['useragent'] = 'xplat MapReduce job submission';
    httpRequest.headers['User-Agent'] = 'xplat MapReduce job submission';
    
    // Serialize Request
    var requestContent = 'user.name=' + parameters.userName + '&jar=' + parameters.jarFile + '&class=' + parameters.jarClass + '&define=' + parameters.defines + '&arg=' + parameters.arguments + '&statusdir=' + parameters.statusDir + '&enablelog=' + parameters.enableLog + '&LibJars=' + parameters.libJars + '&Files=' + parameters.files;
    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) {
        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 jobSubmissionJsonResponseInstance = {};
          result.jobSubmissionJsonResponse = jobSubmissionJsonResponseInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            jobSubmissionJsonResponseInstance.id = idInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Submits a MapReduce streaming job to an HDINSIGHT cluster.
   * 
   * @param {MapReduceStreamingJobSubmissionParameters} parameters MapReduce
   * job parameters.
   * 
   * @param {string} [parameters.userName]
   * 
   * @param {string} [parameters.input]
   * 
   * @param {string} [parameters.output]
   * 
   * @param {string} [parameters.mapper]
   * 
   * @param {string} [parameters.reducer]
   * 
   * @param {string} [parameters.file]
   * 
   * @param {string} [parameters.defines]
   * 
   * @param {string} [parameters.arguments]
   * 
   * @param {string} [parameters.cmdEnv]
   * 
   * @param {string} [parameters.statusDir]
   * 
   * @param {string} [parameters.enableLog]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  JobOperations.prototype.submitMapReduceStreamingJob = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'https://';
    url2 = url2 + encodeURIComponent(this.client.clusterDnsName);
    url2 = url2 + '/templeton/v1/mapreduce/streaming';
    var queryParameters = [];
    if (this.client.credentials.username !== null && this.client.credentials.username !== undefined) {
      queryParameters.push('user.name=' + encodeURIComponent(this.client.credentials.username));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/json';
    httpRequest.headers['Content-Type'] = 'application/text';
    httpRequest.headers['useragent'] = 'xplat MapReduce streaming job submission';
    httpRequest.headers['User-Agent'] = 'xplat MapReduce streaming job submission';
    
    // Serialize Request
    var requestContent = 'user.name=' + parameters.userName + '&input=' + parameters.input + '&output=' + parameters.output + '&mapper=' + parameters.mapper + '&reducer=' + parameters.reducer + '&File=' + parameters.file + '&define=' + parameters.defines + '&cmdenv=' + parameters.cmdEnv + '&arg=' + parameters.arguments + '&statusdir=' + parameters.statusDir + '&enablelog=' + parameters.enableLog;
    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) {
        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 jobSubmissionJsonResponseInstance = {};
          result.jobSubmissionJsonResponse = jobSubmissionJsonResponseInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            jobSubmissionJsonResponseInstance.id = idInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Submits an Hive job to an HDINSIGHT cluster.
   * 
   * @param {PigJobSubmissionParameters} parameters Pig job parameters.
   * 
   * @param {string} [parameters.query]
   * 
   * @param {string} [parameters.userName]
   * 
   * @param {string} [parameters.file]
   * 
   * @param {string} [parameters.files]
   * 
   * @param {string} [parameters.arguments]
   * 
   * @param {string} [parameters.statusDir]
   * 
   * @param {string} [parameters.enableLog]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  JobOperations.prototype.submitPigJob = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'https://';
    url2 = url2 + encodeURIComponent(this.client.clusterDnsName);
    url2 = url2 + '/templeton/v1/pig';
    var queryParameters = [];
    if (this.client.credentials.username !== null && this.client.credentials.username !== undefined) {
      queryParameters.push('user.name=' + encodeURIComponent(this.client.credentials.username));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['accept'] = 'application/json';
    httpRequest.headers['Content-Type'] = 'application/text';
    httpRequest.headers['useragent'] = 'xplat Hive job submission';
    httpRequest.headers['User-Agent'] = 'xplat Hive job submission';
    
    // Serialize Request
    var requestContent = 'user.name=' + parameters.userName + '&execute=' + parameters.query + '&file=' + parameters.file + '&arg=' + parameters.arguments + '&files=' + parameters.files + '&statusdir=' + parameters.statusDir + '&enablelog=' + parameters.enableLog;
    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) {
        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 jobSubmissionJsonResponseInstance = {};
          result.jobSubmissionJsonResponse = jobSubmissionJsonResponseInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            jobSubmissionJsonResponseInstance.id = idInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  return JobOperations;
})();
