/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb; var __ = require("underscore");
















var fs = require("fs");
var util = require("util");
var utils = require("../../util/utils");
var profile = require("../../util/profile");
var azureCommon = require("azure-common");
var hdiHelper = require("../../util/hdinsightHelper");
var azureUtil = azureCommon.util;

var $ = utils.getLocaleString;

function getAsmWarning(spacing, showHelp) {
  if (!spacing) { spacing = " "; };
  var warning = util.format(((("help: %sHDInsight commands in ASM mode are deprecated and will be removed in January 2017. " + "Please use ARM mode instead by entering:  azure config mode arm\n") + "help: %sTo submit jobs, please use a Secure Shell (SSH) connection to your cluster.\n") + "help: %sFor more information, go to http://go.microsoft.com/fwlink/?LinkID=746541&clcid=0x404 \nhelp:"), spacing, spacing, spacing);



  if ((showHelp === false)) {
    warning = util.format(((("%sHDInsight commands in ASM mode are deprecated and will be removed in January 2017. " + "Please use ARM mode instead by entering:  azure config mode arm\n") + "%sTo submit jobs, please use a Secure Shell (SSH) connection to your cluster.\n") + "%sFor more information, go to http://go.microsoft.com/fwlink/?LinkID=746541&clcid=0x404 \nhelp:"), spacing, spacing, spacing); } ;




  return warning;};



var UserInteractor = function(cli) {
  var self = this;
  this.cli = cli;
  this.log = cli.output;
  this.progress = null;

  function logErrorAndData(err, data) {
    self.cli.interaction.formatOutput(data, function(outputData) {
      self.log.error(err);
      self.cli.interaction.logEachData("HDInsight Cluster", outputData); }); };



  function showAsmDeprecationWarning() {
    self.log.info(getAsmWarning(" ", false)); };


  this.logErrorAndData = logErrorAndData;

  this.showAsmDeprecationWarning = showAsmDeprecationWarning;

  this.checkpoint = function() {  };

  function verifyCompat(creationObject, version) {
    if (((!creationObject || !creationObject.version) || !__.isNumber(creationObject.version))) {
      return false; } ;


    if ((creationObject.version > version)) {
      return false; } ;


    if ((parseInt(creationObject.version, 10) === parseInt(version, 10))) {
      return true; } ;



    return false; };


  this.verifyCompat = verifyCompat;

  function logError(err) {
    self.cli.interaction.formatOutput(err, function() {
      self.log.error(err); }); };



  this.logError = logError;

  function logData(msg, data) {
    self.cli.interaction.formatOutput(data, function(outputData) {
      self.cli.interaction.logEachData(msg, outputData); }); };



  this.logData = logData;

  function logList(list) {
    self.cli.interaction.formatOutput(list, function(outputData) {
      if ((outputData.length === 0)) {
        self.log.info("No HDInsight clusters exist"); }
       else {
        self.log.table(list, function(row, item) {
          row.cell("Name", item.Name);
          row.cell("Location", item.Location);
          row.cell("State", item.State); }); } ; }); };





  this.logList = logList;

  function promptIfNotGiven(message, value, _) { var __frame = { name: "promptIfNotGiven", line: 118 }; return __func(_, this, arguments, promptIfNotGiven, 2, __frame, function __$promptIfNotGiven() {
      return self.cli.interaction.promptIfNotGiven(message, value, __cb(_, __frame, 1, 32, _, true)); }); };


  this.promptIfNotGiven = promptIfNotGiven;

  function startProgress(message) {
    self.progress = self.cli.interaction.progress(message); };


  this.startProgress = startProgress;

  function endProgress() {
    self.progress.end(); };


  this.endProgress = endProgress;

  function writeConfig(filePath, config) {
    var data = JSON.stringify(config, null, 2);
    fs.writeFileSync(filePath, data); };


  this.writeConfig = writeConfig;

  function readConfig(filePath) {
    var data = fs.readFileSync(filePath);
    return JSON.parse(data); };


  this.readConfig = readConfig;};


var ExecutionProcessor = function(cli) {
  var self = this;
  this.cli = cli;
  this.errorCount = 0;

  this.createHDInsightClusterManagementClient = function(regionCloudServiceName) {
    self.user.showAsmDeprecationWarning();
    return utils.getHDInsightClusterManagementClient(regionCloudServiceName, profile.current.getSubscription()); };


  this.createHDInsightCluster2ManagementClient = function(regionCloudServiceName) {
    self.user.showAsmDeprecationWarning();
    return utils.getHDInsightCluster2ManagementClient(regionCloudServiceName, profile.current.getSubscription()); };


  this.createCluster = function createCluster__1(regionCloudServiceName, clusterName, clusterCreationPayload, _) { var hdInsight, result; var __frame = { name: "createCluster__1", line: 166 }; return __func(_, this, arguments, createCluster__1, 3, __frame, function __$createCluster__1() {
      self.user.showAsmDeprecationWarning();
      hdInsight = self.createHDInsightClusterManagementClient(regionCloudServiceName);
      return hdInsight.clusterManagement.create(clusterName, clusterCreationPayload, __cb(_, __frame, 3, 45, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.createCluster2 = function createCluster2__2(regionCloudServiceName, clusterName, clusterCreationPayload, _) { var hdInsight2, result; var __frame = { name: "createCluster2__2", line: 173 }; return __func(_, this, arguments, createCluster2__2, 3, __frame, function __$createCluster2__2() {
      self.user.showAsmDeprecationWarning();
      hdInsight2 = self.createHDInsightCluster2ManagementClient(regionCloudServiceName);
      return hdInsight2.clusterManagement.create(clusterName, clusterCreationPayload, __cb(_, __frame, 3, 46, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.getCluster = function getCluster__3(regionCloudServiceName, clusterName, _) { var hdInsight, result; var __frame = { name: "getCluster__3", line: 180 }; return __func(_, this, arguments, getCluster__3, 2, __frame, function __$getCluster__3() {
      self.user.showAsmDeprecationWarning();
      hdInsight = self.createHDInsightClusterManagementClient(regionCloudServiceName);
      return hdInsight.clusterManagement.get(clusterName, __cb(_, __frame, 3, 45, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.getCluster2 = function getCluster2__4(regionCloudServiceName, clusterName, _) { var hdInsight2, result; var __frame = { name: "getCluster2__4", line: 187 }; return __func(_, this, arguments, getCluster2__4, 2, __frame, function __$getCluster2__4() {
      self.user.showAsmDeprecationWarning();
      hdInsight2 = self.createHDInsightCluster2ManagementClient(regionCloudServiceName);
      return hdInsight2.clusterManagement.get(clusterName, __cb(_, __frame, 3, 46, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.deleteCluster = function deleteCluster__5(regionCloudServiceName, clusterName, _) { var hdInsight, result; var __frame = { name: "deleteCluster__5", line: 194 }; return __func(_, this, arguments, deleteCluster__5, 2, __frame, function __$deleteCluster__5() {
      self.user.showAsmDeprecationWarning();
      hdInsight = self.createHDInsightClusterManagementClient(regionCloudServiceName);
      return hdInsight.clusterManagement.deleteMethod(clusterName, __cb(_, __frame, 3, 45, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.deleteCluster2 = function deleteCluster2__6(regionCloudServiceName, clusterName, _) { var hdInsight2, result; var __frame = { name: "deleteCluster2__6", line: 201 }; return __func(_, this, arguments, deleteCluster2__6, 2, __frame, function __$deleteCluster2__6() {
      self.user.showAsmDeprecationWarning();
      hdInsight2 = self.createHDInsightCluster2ManagementClient(regionCloudServiceName);
      return hdInsight2.clusterManagement.deleteMethod(clusterName, __cb(_, __frame, 3, 46, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.listClusters = function listClusters__7(credentials, _) { var hdInsight, result; var __frame = { name: "listClusters__7", line: 208 }; return __func(_, this, arguments, listClusters__7, 1, __frame, function __$listClusters__7() {
      self.user.showAsmDeprecationWarning();
      hdInsight = self.createHDInsightClusterManagementClient("cloudServiceName");
      return hdInsight.clusterManagement.list(__cb(_, __frame, 3, 45, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.listClusters2 = function listClusters2__8(credentials, _) { var hdInsight2, result; var __frame = { name: "listClusters2__8", line: 215 }; return __func(_, this, arguments, listClusters2__8, 1, __frame, function __$listClusters2__8() {
      self.user.showAsmDeprecationWarning();
      hdInsight2 = self.createHDInsightCluster2ManagementClient("cloudServiceName");
      return hdInsight2.clusterManagement.list(__cb(_, __frame, 3, 46, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.createHDInsightJobManagementClient = function(clusterDnsName, userName, password) {
    self.user.showAsmDeprecationWarning();
    return utils.getHDInsightJobManagementClient(clusterDnsName, userName, password); };


  this.submitHDInsightHiveJob = function submitHDInsightHiveJob__9(clusterDnsName, userName, password, parameters, _) { var hdInsightJobClient, result; var __frame = { name: "submitHDInsightHiveJob__9", line: 227 }; return __func(_, this, arguments, submitHDInsightHiveJob__9, 4, __frame, function __$submitHDInsightHiveJob__9() {
      self.user.showAsmDeprecationWarning();
      hdInsightJobClient = self.createHDInsightJobManagementClient(clusterDnsName, userName, password);

      return hdInsightJobClient.jobManagement.submitHiveJob(parameters, __cb(_, __frame, 4, 50, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.submitHDInsightPigJob = function submitHDInsightPigJob__10(clusterDnsName, userName, password, parameters, _) { var hdInsightJobClient, result; var __frame = { name: "submitHDInsightPigJob__10", line: 235 }; return __func(_, this, arguments, submitHDInsightPigJob__10, 4, __frame, function __$submitHDInsightPigJob__10() {
      self.user.showAsmDeprecationWarning();
      hdInsightJobClient = self.createHDInsightJobManagementClient(clusterDnsName, userName, password);
      return hdInsightJobClient.jobManagement.submitPigJob(parameters, __cb(_, __frame, 3, 50, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.submitHDInsightMapReduceJob = function submitHDInsightMapReduceJob__11(clusterDnsName, userName, password, parameters, _) { var hdInsightJobClient, result; var __frame = { name: "submitHDInsightMapReduceJob__11", line: 242 }; return __func(_, this, arguments, submitHDInsightMapReduceJob__11, 4, __frame, function __$submitHDInsightMapReduceJob__11() {
      self.user.showAsmDeprecationWarning();
      hdInsightJobClient = self.createHDInsightJobManagementClient(clusterDnsName, userName, password);
      return hdInsightJobClient.jobManagement.submitMapReduceJob(parameters, __cb(_, __frame, 3, 50, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.submitHDInsightStreamingMapReduceJob = function submitHDInsightStreamingMapReduceJob__12(clusterDnsName, userName, password, parameters, _) { var hdInsightJobClient, result; var __frame = { name: "submitHDInsightStreamingMapReduceJob__12", line: 249 }; return __func(_, this, arguments, submitHDInsightStreamingMapReduceJob__12, 4, __frame, function __$submitHDInsightStreamingMapReduceJob__12() {
      self.user.showAsmDeprecationWarning();
      hdInsightJobClient = self.createHDInsightJobManagementClient(clusterDnsName, userName, password);
      return hdInsightJobClient.jobManagement.submitMapReduceStreamingJob(parameters, __cb(_, __frame, 3, 50, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.getHDInsightJob = function getHDInsightJob__13(clusterDnsName, userName, password, jobId, _) { var hdInsightJobClient, result; var __frame = { name: "getHDInsightJob__13", line: 256 }; return __func(_, this, arguments, getHDInsightJob__13, 4, __frame, function __$getHDInsightJob__13() {
      self.user.showAsmDeprecationWarning();
      hdInsightJobClient = self.createHDInsightJobManagementClient(clusterDnsName, userName, password);
      return hdInsightJobClient.jobManagement.getJob(jobId, __cb(_, __frame, 3, 50, function ___(__0, __1) { result = __1;
        return _(null, result); }, true)); }); };


  this.listHDInsightJobs = function listHDInsightJobs__14(clusterDnsName, userName, password, _) { var hdInsightJobClient, result; var __frame = { name: "listHDInsightJobs__14", line: 263 }; return __func(_, this, arguments, listHDInsightJobs__14, 3, __frame, function __$listHDInsightJobs__14() {
      self.user.showAsmDeprecationWarning();
      hdInsightJobClient = self.createHDInsightJobManagementClient(clusterDnsName, userName, password);
      return hdInsightJobClient.jobManagement.listJobs(__cb(_, __frame, 3, 50, function ___(__0, __1) { result = __1;
        return _(null, result.jobList); }, true)); }); };};



var hdInsightCommandLine = function(cli, userInteractor, executionProcessor) {
  this.cli = cli;
  this.log = cli.output;
  self = this;
  if (userInteractor) {
    this.user = userInteractor; }

   else {
    this.user = new UserInteractor(this.cli); } ;


  if (executionProcessor) {
    this.processor = executionProcessor; }

   else {
    this.processor = new ExecutionProcessor(this.cli); } ;


  this.createClusterCommand = function createClusterCommand__1(clusterName, osType, storageAccountName, storageAccountKey, storageContainer, dataNodeCount, headNodeSize, dataNodeSize, location, userName, password, sshUserName, sshPassword, _) { var clusterCreationPayload, clusterPayload, subscriptionId, cluster2Payload, regionCloudServiceName, result; var __frame = { name: "createClusterCommand__1", line: 289 }; return __func(_, this, arguments, createClusterCommand__1, 13, __frame, function __$createClusterCommand__1() {

      return self.user.promptIfNotGiven($("Cluster name: "), clusterName, __cb(_, __frame, 2, 28, function ___(__0, __1) { clusterName = __1;
        return self.user.promptIfNotGiven($("OS type: "), osType, __cb(_, __frame, 3, 23, function ___(__0, __2) { osType = __2;
          return self.user.promptIfNotGiven($("storage account url: "), storageAccountName, __cb(_, __frame, 4, 35, function ___(__0, __3) { storageAccountName = __3;
            return self.user.promptIfNotGiven($("storage account key: "), storageAccountKey, __cb(_, __frame, 5, 34, function ___(__0, __4) { storageAccountKey = __4;
              return self.user.promptIfNotGiven($("storage container name: "), storageContainer, __cb(_, __frame, 6, 33, function ___(__0, __5) { storageContainer = __5;
                return self.user.promptIfNotGiven($("Number of data nodes: "), dataNodeCount, __cb(_, __frame, 7, 30, function ___(__0, __6) { dataNodeCount = __6;
                  return self.user.promptIfNotGiven($("Data center location: "), location, __cb(_, __frame, 8, 25, function ___(__0, __7) { location = __7;
                    return self.user.promptIfNotGiven($("User name: "), userName, __cb(_, __frame, 9, 25, function ___(__0, __8) { userName = __8;
                      return self.user.promptIfNotGiven($("Password: "), password, __cb(_, __frame, 10, 25, function ___(__0, __9) { password = __9;

                        clusterCreationPayload = { }; return (function __$createClusterCommand__1(__then) {
                          if ((osType === "windows")) {
                            return self.user.promptIfNotGiven($("Head node size (string): "), headNodeSize, __cb(_, __frame, 14, 31, function ___(__0, __10) { headNodeSize = __10;
                              return self.user.promptIfNotGiven($("Data node size (string): "), dataNodeSize, __cb(_, __frame, 15, 31, function ___(__0, __11) { dataNodeSize = __11;

                                clusterPayload = hdiHelper.createClusterPayloadWindows(clusterName, storageAccountName, storageAccountKey, storageContainer, dataNodeCount, headNodeSize, dataNodeSize, location, userName, password);

                                clusterCreationPayload = { payload: clusterPayload }; __then(); }, true)); }, true)); } else { return (function __$createClusterCommand__1(__then) {

                              if ((osType === "linux")) {
                                return self.user.promptIfNotGiven($("SSH user name: "), sshUserName, __cb(_, __frame, 22, 30, function ___(__0, __12) { sshUserName = __12;
                                  return self.user.promptIfNotGiven($("SSH password: "), sshPassword, __cb(_, __frame, 23, 30, function ___(__0, __13) { sshPassword = __13;
                                    subscriptionId = profile.current.getSubscription().id;

                                    cluster2Payload = hdiHelper.createClusterPayloadLinux(clusterName, storageAccountName, storageAccountKey, storageContainer, dataNodeCount, headNodeSize, dataNodeSize, location, userName, password, sshUserName, sshPassword, subscriptionId);

                                    clusterCreationPayload = { payload: cluster2Payload }; __then(); }, true)); }, true)); } else { __then(); } ; })(__then); } ; })(function __$createClusterCommand__1() {


                          regionCloudServiceName = azureUtil.getNameSpace(profile.current.getSubscription().id, "hdinsight", location);

                          self.user.startProgress($("Submitting the request to create cluster...")); return (function __$createClusterCommand__1(__then) {


                            if ((osType === "windows")) {
                              return self.processor.createCluster(regionCloudServiceName, clusterName, clusterCreationPayload, __cb(_, __frame, 37, 30, function ___(__0, __14) { result = __14; __then(); }, true)); } else { return (function __$createClusterCommand__1(__then) {

                                if ((osType === "linux")) {
                                  return self.processor.createCluster2(regionCloudServiceName, clusterName, clusterCreationPayload, __cb(_, __frame, 40, 30, function ___(__0, __15) { result = __15; __then(); }, true)); } else { __then(); } ; })(__then); } ; })(function __$createClusterCommand__1() {

                            self.user.endProgress();

                            if (self.log.format().json) {
                              self.log.json(result); }

                             else {
                              self.log.data($("Cluster ID  :"), result.id);
                              self.log.data($("Status      :"), result.status); } ; _(); }); }); }, true)); }, true)); }, true)); }, true)); }, true)); }, true)); }, true)); }, true)); }, true)); }); };



  this.showClusterCommand = function showClusterCommand__2(clusterName, osType, options, _) { var regionCloudServiceName, cluster, clusterInfo; var __frame = { name: "showClusterCommand__2", line: 342 }; return __func(_, this, arguments, showClusterCommand__2, 3, __frame, function __$showClusterCommand__2() {
      return self.user.promptIfNotGiven($("Cluster name: "), clusterName, __cb(_, __frame, 1, 28, function ___(__0, __1) { clusterName = __1;
        return self.user.promptIfNotGiven($("OS type: "), osType, __cb(_, __frame, 2, 23, function ___(__0, __2) { osType = __2;

          regionCloudServiceName = azureUtil.getNameSpace(profile.current.getSubscription().id, "hdinsight", "location");
          self.user.startProgress($("Getting HDInsight cluster details")); return (function __$showClusterCommand__2(__then) {


            if ((osType == "windows")) {
              return self.processor.getCluster(regionCloudServiceName, clusterName, __cb(_, __frame, 9, 31, function ___(__0, __3) { cluster = __3; __then(); }, true)); } else { return (function __$showClusterCommand__2(__then) {

                if ((osType == "linux")) {
                  return self.processor.getCluster2(regionCloudServiceName, clusterName, __cb(_, __frame, 12, 31, function ___(__0, __4) { cluster = __4; __then(); }, true)); } else { __then(); } ; })(__then); } ; })(function __$showClusterCommand__2() {

            self.user.endProgress();

            if (!cluster.passthroughResponse.data) {
              self.log.data($("Cluster not found.")); }

             else {
              clusterInfo = cluster.passthroughResponse.data;
              if (self.log.format().json) {
                self.log.json(clusterInfo); }

               else {
                self.log.data($("HDInsight Cluster Info"));
                self.log.data($("----------------------"));
                self.log.data($("Name          :"), (clusterInfo.id || clusterInfo.dnsName));
                self.log.data($("State         :"), clusterInfo.state);
                self.log.data($("Location      :"), clusterInfo.location);
                self.log.data($("Version       :"), (clusterInfo.version || clusterInfo.hdiVersion)); } ; } ; _(); }); }, true)); }, true)); }); };




  this.listClustersCommand = function listClustersCommand__3(options, _) { var result, clusters; var __frame = { name: "listClustersCommand__3", line: 377 }; return __func(_, this, arguments, listClustersCommand__3, 1, __frame, function __$listClustersCommand__3() {
      self.user.startProgress($("Getting HDInsight servers"));
      return self.processor.listClusters(options.subscription, __cb(_, __frame, 2, 32, function ___(__0, __1) { result = __1.cloudService;
        self.user.endProgress();


        clusters = [];
        result.forEach(function(item) {
          item.resources.forEach(function(res) {
            var cluster = { };
            cluster.name = res.name;
            cluster.state = res.state;
            cluster.subState = res.subState;
            cluster.region = item.geoRegion;
            res.outputItems.forEach(function(op) {
              if ((op.key === "OsType")) {
                cluster.osType = op.value; } ;

              if ((op.key === "Version")) {
                cluster.version = op.value; } ; });


            clusters.push(cluster); }); });


        if ((result.length === 0)) {
          self.log.data($("No clusters found.")); } else {

          if (self.log.format().json) {
            self.log.json(result); }

           else {
            self.cli.interaction.formatOutput(clusters, function(outputData) {
              self.log.table(outputData, function(row, item) {
                row.cell("Name", item.name);
                row.cell("State", item.state);
                row.cell("Substate", item.subState);
                row.cell("Region", item.region);
                row.cell("Version", item.version);
                row.cell("OsType", (item.osType || "Windows Server 2012")); }); }); } ; } ; _(); }, true)); }); };





  this.deleteClusterCommand = function deleteClusterCommand__4(clusterName, location, osType, options, _) { var regionCloudServiceName; var __frame = { name: "deleteClusterCommand__4", line: 422 }; return __func(_, this, arguments, deleteClusterCommand__4, 4, __frame, function __$deleteClusterCommand__4() {
      return self.user.promptIfNotGiven($("Cluster name: "), clusterName, __cb(_, __frame, 1, 28, function ___(__0, __1) { clusterName = __1;
        return self.user.promptIfNotGiven($("Location: "), location, __cb(_, __frame, 2, 25, function ___(__0, __2) { location = __2;
          return self.user.promptIfNotGiven($("OS type: "), osType, __cb(_, __frame, 3, 23, function ___(__0, __3) { osType = __3;

            regionCloudServiceName = azureUtil.getNameSpace(profile.current.getSubscription().id, "hdinsight", location);
            self.user.startProgress($("Deleting HDInsight Cluster")); return (function __$deleteClusterCommand__4(__then) {

              if ((osType == "windows")) {
                return self.processor.deleteCluster(regionCloudServiceName, clusterName, __cb(_, __frame, 9, 21, __then, true)); } else { __then(); } ; })(function __$deleteClusterCommand__4() { return (function __$deleteClusterCommand__4(__then) {

                if ((osType == "linux")) {
                  return self.processor.deleteCluster2(regionCloudServiceName, clusterName, __cb(_, __frame, 12, 21, __then, true)); } else { __then(); } ; })(function __$deleteClusterCommand__4() {

                self.user.endProgress(); _(); }); }); }, true)); }, true)); }, true)); }); };



  this.submitHDInsightHiveJobCommand = function submitHDInsightHiveJobCommand__5(clusterDnsName, userName, password, options, _) { var parameters, result, response; var __frame = { name: "submitHDInsightHiveJobCommand__5", line: 440 }; return __func(_, this, arguments, submitHDInsightHiveJobCommand__5, 4, __frame, function __$submitHDInsightHiveJobCommand__5() {
      return self.user.promptIfNotGiven($("Cluster name: "), clusterDnsName, __cb(_, __frame, 1, 31, function ___(__0, __1) { clusterDnsName = __1;
        return self.user.promptIfNotGiven($("User name: "), userName, __cb(_, __frame, 2, 25, function ___(__0, __2) { userName = __2;
          return self.user.promptIfNotGiven($("Password: "), password, __cb(_, __frame, 3, 25, function ___(__0, __3) { password = __3;
            parameters = { };
            parameters.userName = userName;
            parameters.enableLog = false;
            parameters.statusDir = ".";
            parameters.query = "";
            parameters.file = "";
            parameters.files = "";
            parameters.defines = "";
            parameters["arguments"] = "";

            if ((options.query && options.queryFile)) {
              return _(new Error($("Either provide the query or queryFile parameter."))); } ;

            if (options.query) {
              parameters.query = options.query; } ;

            if (options.queryFile) {
              parameters.file = options.queryFile; } ;

            if (options.defines) {
              parameters.defines = options.defines; } ;

            if (options["arguments"]) {
              parameters["arguments"] = options["arguments"]; } ;

            if (options.files) {
              parameters.files = options.files; } ;


            return self.processor.submitHDInsightHiveJob(clusterDnsName, userName, password, parameters, __cb(_, __frame, 33, 32, function ___(__0, __4) { result = __4;
              response = result.jobSubmissionJsonResponse;
              if (self.log.format().json) {
                self.log.json(response); } ;

              self.log.data($("Job Id      :"), response.id); _(); }, true)); }, true)); }, true)); }, true)); }); };


  this.submitHDInsightPigJobCommand = function submitHDInsightPigJobCommand__6(clusterDnsName, userName, password, options, _) { var parameters, result, response; var __frame = { name: "submitHDInsightPigJobCommand__6", line: 481 }; return __func(_, this, arguments, submitHDInsightPigJobCommand__6, 4, __frame, function __$submitHDInsightPigJobCommand__6() {
      return self.user.promptIfNotGiven($("Cluster name: "), clusterDnsName, __cb(_, __frame, 1, 31, function ___(__0, __1) { clusterDnsName = __1;
        return self.user.promptIfNotGiven($("User name: "), userName, __cb(_, __frame, 2, 25, function ___(__0, __2) { userName = __2;
          return self.user.promptIfNotGiven($("Password: "), password, __cb(_, __frame, 3, 25, function ___(__0, __3) { password = __3;
            parameters = { };
            parameters.userName = userName;
            parameters.query = "";
            parameters.file = "";
            parameters.files = "";
            parameters["arguments"] = "";

            if ((options.query && options.queryFile)) {
              return _(new Error($("Either provide the query or queryFile parameter."))); } ;

            if (options.query) {
              parameters.query = options.query; } ;

            if (options.queryFile) {
              parameters.file = options.queryFile; } ;

            if (options["arguments"]) {
              parameters["arguments"] = options["arguments"]; } ;

            if (options.files) {
              parameters.files = options.files; } ;

            return self.processor.submitHDInsightPigJob(clusterDnsName, userName, parameters, __cb(_, __frame, 26, 32, function ___(__0, __4) { result = __4;

              response = result.jobSubmissionJsonResponse;
              if (self.log.format().json) {
                self.log.json(response); } ;

              self.log.data($("Job Id      :"), response.id); _(); }, true)); }, true)); }, true)); }, true)); }); };


  this.submitHDInsightMapReduceJobCommand = function submitHDInsightMapReduceJobCommand__7(clusterDnsName, userName, password, options, _) { var parameters, result, response; var __frame = { name: "submitHDInsightMapReduceJobCommand__7", line: 516 }; return __func(_, this, arguments, submitHDInsightMapReduceJobCommand__7, 4, __frame, function __$submitHDInsightMapReduceJobCommand__7() {
      return self.user.promptIfNotGiven($("Cluster name: "), clusterDnsName, __cb(_, __frame, 1, 31, function ___(__0, __1) { clusterDnsName = __1;
        return self.user.promptIfNotGiven($("User name: "), userName, __cb(_, __frame, 2, 25, function ___(__0, __2) { userName = __2;
          return self.user.promptIfNotGiven($("Password: "), password, __cb(_, __frame, 3, 25, function ___(__0, __3) { password = __3;
            parameters = { };
            parameters.userName = userName;
            parameters["className"] = "";
            parameters.jarFile = "";
            parameters.libJars = "";
            parameters.files = "";
            parameters.defines = "";
            parameters["arguments"] = "";

            if (options.jarFile) {
              parameters.jarFile = options.jarFile; } ;

            if (options.libJars) {
              parameters.libJars = options.libJars; } ;

            if (options.defines) {
              parameters.defines = options.defines; } ;

            if (options["arguments"]) {
              parameters["arguments"] = options["arguments"]; } ;

            if (options["className"]) {
              parameters["className"] = options["className"]; } ;

            if (options.files) {
              parameters.files = options.files; } ;

            return self.processor.submitHDInsightMapReduceJob(clusterDnsName, userName, password, parameters, __cb(_, __frame, 31, 32, function ___(__0, __4) { result = __4;
              response = result.jobSubmissionJsonResponse;
              if (self.log.format().json) {
                self.log.json(response); } ;

              self.log.data($("Job Id      :"), response.id); _(); }, true)); }, true)); }, true)); }, true)); }); };


  this.submitHDInsightStreamingMapReduceJobCommand = function submitHDInsightStreamingMapReduceJobCommand__8(clusterDnsName, userName, password, options, _) { var parameters, result, response; var __frame = { name: "submitHDInsightStreamingMapReduceJobCommand__8", line: 555 }; return __func(_, this, arguments, submitHDInsightStreamingMapReduceJobCommand__8, 4, __frame, function __$submitHDInsightStreamingMapReduceJobCommand__8() {
      return self.user.promptIfNotGiven($("Cluster name: "), clusterDnsName, __cb(_, __frame, 1, 31, function ___(__0, __1) { clusterDnsName = __1;
        return self.user.promptIfNotGiven($("User name: "), userName, __cb(_, __frame, 2, 25, function ___(__0, __2) { userName = __2;
          return self.user.promptIfNotGiven($("Password: "), password, __cb(_, __frame, 3, 25, function ___(__0, __3) { password = __3;
            parameters = { };
            parameters.userName = userName;
            parameters["arguments"] = "";
            parameters.mapper = "";
            parameters.reducer = "";
            parameters.combiner = "";
            parameters.cmdenv = "";
            parameters.outputPath = "";
            parameters.files = "";
            parameters.defines = "";
            parameters.inputPath = "";

            if (options.mapper) {
              parameters.mapper = options.mapper; } ;

            if (options.combiner) {
              parameters.combiner = options.combiner; } ;

            if (options.reducer) {
              parameters.reducer = options.reducer; } ;

            if (options.cmdenv) {
              parameters.cmdenv = options.cmdenv; } ;

            if (options.outputPath) {
              parameters.outputPath = options.outputPath; } ;

            if (options.inputPath) {
              parameters.inputPath = options.inputPath; } ;

            if (options.defines) {
              parameters.defines = options.defines; } ;

            if (options["arguments"]) {
              parameters["arguments"] = options["arguments"]; } ;

            if (options.files) {
              parameters.files = options.files; } ;

            return self.processor.submitHDInsightStreamingMapReduceJob(clusterDnsName, userName, password, parameters, __cb(_, __frame, 43, 32, function ___(__0, __4) { result = __4;
              response = result.jobSubmissionJsonResponse;
              if (self.log.format().json) {
                self.log.json(response); } ;

              self.log.data($("Job Id      :"), response.id); _(); }, true)); }, true)); }, true)); }, true)); }); };


  this.getHDInsightJobCommand = function getHDInsightJobCommand__9(clusterDnsName, userName, password, jobId, _) { var result, jobInfo; var __frame = { name: "getHDInsightJobCommand__9", line: 606 }; return __func(_, this, arguments, getHDInsightJobCommand__9, 4, __frame, function __$getHDInsightJobCommand__9() {
      return self.user.promptIfNotGiven($("Cluster name: "), clusterDnsName, __cb(_, __frame, 1, 31, function ___(__0, __1) { clusterDnsName = __1;
        return self.user.promptIfNotGiven($("User name: "), userName, __cb(_, __frame, 2, 25, function ___(__0, __2) { userName = __2;
          return self.user.promptIfNotGiven($("Password: "), password, __cb(_, __frame, 3, 25, function ___(__0, __3) { password = __3;
            return self.user.promptIfNotGiven($("JobId: "), jobId, __cb(_, __frame, 4, 22, function ___(__0, __4) { jobId = __4;
              self.user.startProgress($(((("Listing HDInsight Job details for " + jobId) + " on ") + clusterDnsName)));
              return self.processor.getHDInsightJob(clusterDnsName, userName, password, jobId, __cb(_, __frame, 6, 32, function ___(__0, __5) { result = __5;
                self.user.endProgress();

                if (!result.jobDetail) {
                  self.log.data($("Job not found.")); }

                 else {
                  jobInfo = result.jobDetail;
                  if (self.log.format().json) {
                    self.log.json(jobInfo); }

                   else {
                    self.log.data($("HDInsight Job Info"));
                    self.log.data($("------------------"));
                    self.log.data($("Job Id      :"), jobInfo.id);
                    self.log.data($("Job State   :"), jobInfo.status.state); } ; } ; _(); }, true)); }, true)); }, true)); }, true)); }, true)); }); };




  this.listHDInsightJobsCommand = function listHDInsightJobsCommand__10(clusterDnsName, userName, password, _) { var jobList; var __frame = { name: "listHDInsightJobsCommand__10", line: 632 }; return __func(_, this, arguments, listHDInsightJobsCommand__10, 3, __frame, function __$listHDInsightJobsCommand__10() {
      return self.user.promptIfNotGiven($("Cluster name: "), clusterDnsName, __cb(_, __frame, 1, 31, function ___(__0, __1) { clusterDnsName = __1;
        return self.user.promptIfNotGiven($("User name: "), userName, __cb(_, __frame, 2, 25, function ___(__0, __2) { userName = __2;
          return self.user.promptIfNotGiven($("Password: "), password, __cb(_, __frame, 3, 25, function ___(__0, __3) { password = __3;
            self.user.startProgress($(("Listing HDInsight Jobs for cluster " + clusterDnsName)));
            return self.processor.listHDInsightJobs(clusterDnsName, userName, password, __cb(_, __frame, 5, 33, function ___(__0, __4) { jobList = __4;
              self.user.endProgress();
              self.cli.interaction.formatOutput(jobList, function(outputData) {
                if ((outputData.length === 0)) {
                  self.log.data($("No jobs found.")); }

                 else {
                  if (self.log.format().json) {
                    self.log.json(outputData); }

                   else {
                    self.log.table(outputData, function(row, item) {
                      row.cell("Job Id", item.id); }); } ; } ; }); _(); }, true)); }, true)); }, true)); }, true)); }); };};







module.exports = hdInsightCommandLine;

hdInsightCommandLine.init = function(cli) {
  var self = new hdInsightCommandLine(cli);

  var hdInsight = cli.category("hdinsight").description($(("Commands to manage HDInsight clusters and jobs.\n" + getAsmWarning("			  "))));


  var cluster = hdInsight.category("cluster").description($(("Commands to manage HDInsight clusters.\n" + getAsmWarning("		"))));


  cluster.command("create [clusterName] [osType] [storageAccountName] [storageAccountKey] [storageContainer] [dataNodeCount] [headNodeSize] [dataNodeSize] [location] [userName] [password] [sshUserName] [sshPassword]").description($(("Create a cluster.\n" + getAsmWarning("		")))).usage("[options] <clusterName> <osType> <storageAccountName> <storageAccountKey> <storageContainer> <dataNodeCount> <headNodeSize> <dataNodeSize> <location> <userName> <password> <sshUserName> <sshPassword>").option("--clusterName <clusterName>", $("HDInsight cluster name")).option("--osType <osType>", $("HDInsight cluster operating system - 'windows' or 'linux'")).option("--storageAccountName <storageAccountName>", $("Storage account url to use for default HDInsight storage")).option("--storageAccountKey <storageAccountKey>", $("Key to the storage account to use for default HDInsight storage")).option("--storageContainer <storageContainer>", $("Container in the storage account to use for HDInsight default storage")).option("--dataNodeCount <dataNodeCount>", $("Number of data nodes to use for the cluster")).option("--headNodeSize <headNodeSize>", $("NOTE: Head node size for the cluster (only allowed for 'windows' ostype)")).option("--dataNodeSize <dataNodeSize>", $("NOTE: Data node size for the cluster (only allowed for 'windows' ostype)")).option("--location <location>", $("Data center location for the cluster")).option("--userName <userName>", $("Cluster username")).option("--password <password>", $("Cluster password")).option("--sshUserName <sshUserName>", $("SSH username")).option("--sshPassword <sshPassword>", $("SSH password")).option("-s, --subscription <id>", $("the subscription id")).execute(self.createClusterCommand);


















  cluster.command("delete [clusterName] [location] [osType]").description($(("Delete a cluster.\n" + getAsmWarning("		")))).usage("[options] <clusterName> <location> <osType>").option("--clusterName <clusterName>", $("Cluster name")).option("--location <location>", $("Cluster location")).option("--osType <osType>", $("Cluster OS type")).option("-s, --subscription <id>", $("the subscription id")).execute(self.deleteClusterCommand);








  cluster.command("show [clusterName] [osType]").description($(("Show cluster details.\n" + getAsmWarning("		")))).usage("[options] <clusterName> <osType>").option("--clusterName <clusterName>", $("the HdInsight cluster name")).option("--osType <osType>", $("the HdInsight cluster operating system: windows OR linux")).option("-s, --subscription <id>", $("the subscription id")).execute(self.showClusterCommand);







  cluster.command("list").description($(("List the clusters" + getAsmWarning("		")))).execute(self.listClustersCommand);




  var job = hdInsight.category("job").description($(("Commands to manage HDInsight jobs. \n" + getAsmWarning("		"))));


  job.command("hive_create [clusterDnsName] [userName] [password]").description($(("Submits a Hive job to an HdInsight cluster.\n" + getAsmWarning("		")))).usage("[options] <clusterDnsName> <userName> <password>").option("--clusterDnsName <clusterDnsName>", $("Fully qualified cluster DNS name. Example: mycluster.azurehdinsight.net")).option("--userName <userName>", $("User name for the cluster")).option("--password <password>", $("Password for the cluster")).option("--query <query>", $("The Hive query string to be executed")).option("--queryFile <queryFile>", $("The path to a file that contains the Hive query to be executed; this parameter and the [query] parameter are mutually exclusive")).option("--arguments <arguments>", $("A comma separated string of arguments to be passed to the Hive job. For example: \"a1,a2,a3\"")).option("--defines <defines>", $("A key/value pair of Hadoop configuration values to be set during the Hive job execution. For example: \"k1=v1,k2=v2\"")).option("--files <files>", $("A comma separated string of file paths required for the Hive job to execute. For example: \"f1/f2/f3,f4/f5,f6\"")).option("-s, --subscription <id>", $("the subscription id")).execute(self.submitHDInsightHiveJobCommand);


























  job.command("mr_create [clusterDnsName] [userName] [password] [className] [jarFile]").description($(("Submits a MapReduce job to an HdInsight cluster.\n" + getAsmWarning("		")))).usage("[options] <clusterDnsName> <userName> <password> <className> <jarFile>").option("--clusterDnsName <clusterDnsName>", $("Fully qualified cluster DNS name. Example: mycluster.azurehdinsight.net")).option("--userName <userName>", $("User name for the cluster")).option("--password <password>", $("Password for the cluster")).option("--className <className>", $("Name of the job class in the job JAR file")).option("--jarFile <jarFile>", $("The fully qualified name of the JAR file that contains the code and dependencies of the MapReduce job")).option("--arguments <arguments>", $("A comma separated string of arguments to be passed to the MapReduce job. For example: \"a1,a2,a3\"")).option("--defines <defines>", $("A key/value pair of Hadoop configuration values to be set during the MapReduce job execution. For example: \"k1=v1,k2=v2\"")).option("--files <files>", $("A comma separated string of file paths required for the MapReduce job to execute. For example: \"f1/f2/f3,f4/f5,f6\"")).option("--libJars <libJars>", $("The Jar library references for the MapReduce job")).option("-s, --subscription <id>", $("the subscription id")).execute(self.submitHDInsightMapReduceJobCommand);














  job.command("mr_streaming_create [clusterDnsName] [userName] [password] [mapper] [reducer]").description($(("Submits a Streaming MapReduce job to an HdInsight cluster.\n" + getAsmWarning("		")))).usage("[options] <clusterDnsName> <userName> <password> <mapper> <reducer>").option("--clusterDnsName <clusterDnsName>", $("Fully qualified cluster DNS name. Example: mycluster.azurehdinsight.net")).option("--userName <userName>", $("User name for the cluster")).option("--password <password>", $("Password for the cluster")).option("--arguments <arguments>", $("A comma separated string of arguments to be passed to the Streaming MapReduce job. For example: \"a1,a2,a3\"")).option("--cmdenv <cmdEnv>", $("Comma separated key/value pairs of environment variables that should be set during the Streaming MapReduce job execution on data nodes")).option("--mapper <combiner>", $("Mapper executable name for the Streaming MapReduce job")).option("--reducer <reducer>", $("Reducer executable name for the Streaming MapReduce job")).option("--combiner <combiner>", $("Combiner executable name for the Streaming MapReduce job")).option("--defines <defines>", $("A comma separated key/value pair of Hadoop configuration values to be set during the Streaming MapReduce job execution. For example: \"k1=v1,k2=v2\"")).option("--files <files>", $("A comma separated string of file paths required for the Streaming MapReduce job to execute. For example: \"f1/f2/f3,f4/f5,f6\"")).option("--inputPath <inputPath>", $("Location of the input files for the Streaming MapReduce job")).option("--outputPath <outputPath>", $("Location of the output files for the Streaming MapReduce job")).option("-s, --subscription <id>", $("the subscription id")).execute(self.submitHDInsightStreamingMapReduceJobCommand);

















  job.command("show [clusterDnsName] [userName] [password] [jobId]").description($(("Retrieves the details of the specified job from an HDInsight cluster.\n" + getAsmWarning("		")))).usage("[options] <clusterDnsName> <userName> <password> <jobId>").option("--clusterDnsName <clusterDnsName>", $("Fully qualified cluster DNS name. Example: mycluster.azurehdinsight.net")).option("--userName <userName>", $("User name for the cluster")).option("--password <password>", $("Password for the cluster")).option("--jobId <jobId>", $("The Id of the job for which the details need to be retrieved")).option("-s, --subscription <id>", $("the subscription id")).execute(self.getHDInsightJobCommand);









  job.command("list [clusterDnsName] [userName] [password]").description($(("Retrieves the list of jobs from the specified HDInsight cluster.\n" + getAsmWarning("		")))).usage("[options] <clusterDnsName> <userName> <password>").option("--clusterDnsName <clusterDnsName>", $("Fully qualified cluster DNS name. Example: mycluster.azurehdinsight.net")).option("--userName <userName>", $("User name for the cluster")).option("--password <password>", $("Password for the cluster")).option("-s, --subscription <id>", $("the subscription id")).execute(self.listHDInsightJobsCommand);};
