/*** 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,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var __ = require("underscore");
















var fs = require("fs");
var util = require("util");
var batchUtil = require("./batch.util");
var batchShowUtil = require("./batch.showUtil");
var utils = require("../../util/utils");
var startProgress = batchUtil.startProgress;
var endProgress = batchUtil.endProgress;

var $ = utils.getLocaleString;




exports.init = function(cli) {


  batchUtil.init(cli);




  var batch = cli.category("batch");

  var job = batch.category("job").description($("Commands to manage your Batch jobs"));

  var jobPrepAndReleaseStatus = job.category("prep-release-status").description($("Commands to manage the status of your job preparation and release tasks"));


  var logger = cli.output;

  var interaction = cli.interaction;

  job.command("create [json-file]").description($("Adds a job to the specified account")).option("-f, --json-file <json-file>", $("the file containing the job object to create in JSON format; if this parameter is specified, all other job parameters are ignored.")).option("-i, --id <jobId>", $("the Batch job id")).option("-p, --pool-id <poolId>", $("the id of an existing pool; all the tasks of the job will run on the speicfied pool")).option("--metadata <--metadata>", $("the semicolon separated list of name-value pairs associated with the job as metadata, ex: name1=value1;name2=value2")).option("--priority <priority>", $("the priority of the job, ranging from -1000 to 1000, with -1000 being the lowest priority and 1000 being the highest priority; the default value is 0.")).option("--max-wall-clock-time <max-wall-clock-time>", $("the maximum elapsed time that a job may run, in ISO 8601 duration formation")).option("--max-task-retry-count <max-task-retry-count>", $("the maximum number of times each task may be retried")).appendBatchAccountOption().execute(createJob);











  job.command("list").description($("Lists all of the jobs in the specified account")).option("-i, --job-schedule-id [jobScheduleId]", $("the id of the job schedule from which you want to get a list of jobs")).appendODataFilterOption(true, true, true).appendBatchAccountOption().execute(listJobs);






  job.command("show [jobId]").description($("Show information about the specified job")).option("-i, --id <jobId>", $("the id of the job")).appendODataFilterOption(true, false, true).appendBatchAccountOption().execute(showJob);






  job.command("delete [jobId]").description($("Delete the specified job")).option("-i, --id <jobId>", $("the id of the job to delete")).option("-q, --quiet", $("remove the specified job without confirmation")).appendCommonHeaderFilterOption(true, true).appendBatchAccountOption().execute(deleteJob);







  job.command("set [jobId] [json-file]").description($("Patch/Update the properties of a job")).option("-i, --id <jobId>", $("the id of the job whose properties you want to patch/update")).option("-p, --pool-id <poolId>", $("the id of an existing pool; all the tasks of the job will run on the speicfied pool")).option("--metadata <--metadata>", $("the semicolon separated list of name-value pairs associated with the job as metadata, ex: name1=value1;name2=value2")).option("--priority <priority>", $("the priority of the job, ranging from -1000 to 1000, with -1000 being the lowest priority and 1000 being the highest priority; the default value is 0.")).option("--max-wall-clock-time <max-wall-clock-time>", $("the maximum elapsed time that a job may run, in ISO 8601 duration formation")).option("--max-task-retry-count <max-task-retry-count>", $("the maximum number of times each task may be retried")).option("-f, --json-file <json-file>", $("the file containing the job properties to patch/update in JSON format; if this parameter is specified, all other job parameters are ignored.")).option("-r, --replace", $("uses update instead of patch")).appendCommonHeaderFilterOption(true, true).appendBatchAccountOption().execute(updateJob);













  job.command("enable <jobId>").description($("Enables the specified job, allowing new tasks to run")).appendCommonHeaderFilterOption(true, true).appendBatchAccountOption().execute(enableJob);





  job.command("disable <jobId>").description($("Disables the specified job.  Disabled jobs do not run new tasks, but may be re-enabled later.")).option("-o, --disable-option <disableOption>", $("specifies what to do with active tasks during a disable job operation, available options include \"requeue\", \"terminate\", and \"wait\"")).appendCommonHeaderFilterOption(true, true).appendBatchAccountOption().execute(disableJob);






  job.command("stop <jobId>").description($("Terminates the specified job, marking it as completed")).option("-r, --reason [reason]", $("the text you want to appear as the job's terminate reason")).appendCommonHeaderFilterOption(true, true).appendBatchAccountOption().execute(terminateJob);






  jobPrepAndReleaseStatus.command("list <jobId>").description($("Lists the execution status of the job preparation and job release task for the specified job across the compute nodes where the job has run")).appendODataFilterOption(true, true, false).appendBatchAccountOption().execute(listJobPrepAndReleaseTaskStatus);















  function createJob(jsonFile, options, _) { var parsedJson, poolId, constraintsJson, objJson, client, addJob, resultMapper, tips, batchOptions; var __frame = { name: "createJob", line: 134 }; return __func(_, this, arguments, createJob, 2, __frame, function __$createJob() {
      if (!jsonFile) {
        jsonFile = options.jsonFile; } ;

      parsedJson = { }; return (function __$createJob(__then) {

        if (!jsonFile) { return (function __$createJob(__then) {
            if (!options.id) {
              return interaction.promptIfNotGiven($("JSON file name: "), jsonFile, __cb(_, __frame, 8, 31, function ___(__0, __1) { jsonFile = __1; __then(); }, true)); } else {

              parsedJson = { id: options.id };

              poolId = options.poolId; return (function __$createJob(__then) {
                if (!poolId) {
                  return cli.interaction.promptIfNotGiven($("Pool id: "), poolId, __cb(_, __frame, 14, 35, function ___(__0, __2) { poolId = __2; __then(); }, true)); } else { __then(); } ; })(function __$createJob() {

                __.extend(parsedJson, { poolInfo: { poolId: poolId } });

                if (options.priority) {
                  __.extend(parsedJson, { priority: Number(options.priority) }); } ;


                constraintsJson = { };
                if (options.maxWallClockTime) {
                  __.extend(constraintsJson, { maxWallClockTime: options.maxWallClockTime }); } ;


                if (options.maxTaskRetryCount) {
                  __.extend(constraintsJson, { maxTaskRetryCount: Number(options.maxTaskRetryCount) }); } ;


                __.extend(parsedJson, { constraints: constraintsJson });

                if (options.metadata) {
                  ref = [];
                  options.metadata.split(";").forEach(function(entry) {
                    var item = entry.split("=");
                    ref.push({ name: item[0], value: item[1] }); });

                  __.extend(parsedJson, { metadata: ref }); } ; __then(); }); } ; })(__then); } else { __then(); } ; })(function __$createJob() {




        if (jsonFile) {
          objJson = fs.readFileSync(jsonFile).toString();
          parsedJson = JSON.parse(objJson); } ;


        client = batchUtil.createBatchServiceClient(options);

        addJob = null;
        if (((parsedJson !== null) && (parsedJson !== undefined))) {
          resultMapper = new client.models["JobAddParameter"]().mapper();
          addJob = client.deserialize(resultMapper, parsedJson, "result"); } ;


        tips = $("Creating Batch job");
        batchOptions = { };
        batchOptions.jobAddOptions = batchUtil.getBatchOperationDefaultOption();

        startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createJob() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createJob() {

                    return client.job.add(addJob, batchOptions, __cb(_, __frame, 63, 17, __then, true)); }); })(function ___(err, __result) { __catch(function __$createJob() { if (err) {

                      if (err.message) {
                        if ((typeof err.message === "object")) {
                          err.message = err.message.value; } ; } ;



                      return _(err); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$createJob() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createJob() {


                endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$createJob() {


            logger.verbose(util.format($("Job %s has been created successfully"), addJob.id));
            return showJob(addJob.id, options, __cb(_, __frame, 78, 4, function __$createJob() { _(); }, true)); }); }); }); }); };








  function showJob(jobId, options, _) { var client, tips, batchOptions, job; var __frame = { name: "showJob", line: 221 }; return __func(_, this, arguments, showJob, 2, __frame, function __$showJob() {
      client = batchUtil.createBatchServiceClient(options);
      if (!jobId) {
        jobId = options.id; } ;

      return interaction.promptIfNotGiven($("Job id: "), jobId, __cb(_, __frame, 5, 24, function ___(__0, __1) { jobId = __1;
        tips = $("Getting Batch job information");

        batchOptions = { };
        batchOptions.jobGetOptions = batchUtil.getBatchOperationDefaultOption();

        if (options.selectClause) {
          batchOptions.jobGetOptions.select = options.selectClause; } ;

        if (options.expandClause) {
          batchOptions.jobGetOptions.expand = options.expandClause; } ;


        job = null;

        startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$showJob() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$showJob() {

                    return client.job.get(jobId, batchOptions, __cb(_, __frame, 22, 23, function ___(__0, __2) { job = __2; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$showJob() { if (e) {

                      if (batchUtil.isNotFoundException(e)) {
                        return _(new Error(util.format($("Job %s does not exist"), jobId))); }
                       else {
                        if (e.message) {
                          if ((typeof e.message === "object")) {
                            e.message = e.message.value; } ; } ;



                        return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$showJob() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$showJob() {


                endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$showJob() {


            batchShowUtil.showCloudJob(job, cli.output); _(); }); }); }, true)); }); };







  function listJobs(options, _) { var client, tips, batchOptions, jobOptions, jobs, nextLink; var __frame = { name: "listJobs", line: 268 }; return __func(_, this, arguments, listJobs, 1, __frame, function __$listJobs() {
      client = batchUtil.createBatchServiceClient(options);
      tips = $("Listing Batch jobs");
      batchOptions = { };

      jobOptions = batchUtil.getBatchOperationDefaultOption();
      if (options.selectClause) {
        jobOptions.select = options.selectClause; } ;

      if (options.expandClause) {
        jobOptions.expand = options.expandClause; } ;

      if (options.filterClause) {
        jobOptions.filter = options.filterClause; } ;


      if (options.jobScheduleId) {
        batchOptions.jobListFromJobScheduleOptions = jobOptions; }
       else {
        batchOptions.jobListOptions = jobOptions; } ;


      jobs = [];
      startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listJobs() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listJobs() { return (function __$listJobs(__then) {


                    if (options.jobScheduleId) {
                      return client.job.listFromJobSchedule(options.jobScheduleId, batchOptions, __cb(_, __frame, 27, 28, function ___(__0, __1) { result = __1; __then(); }, true)); } else {

                      return client.job.list(batchOptions, __cb(_, __frame, 29, 28, function ___(__0, __2) { result = __2; __then(); }, true)); } ; })(function __$listJobs() {

                    result.forEach(function(job) {
                      jobs.push(job); });

                    nextLink = result.odatanextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$listJobs() { __more = false;

                        var __7 = nextLink; if (__7) {
                          batchOptions = { };
                          jobOptions = batchUtil.getBatchOperationDefaultOption(); return (function __$listJobs(__then) {

                            if (options.jobScheduleId) {
                              batchOptions.jobListFromJobScheduleOptions = jobOptions;
                              return client.job.listFromJobScheduleNext(nextLink, batchOptions, __cb(_, __frame, 42, 30, function ___(__0, __3) { result = __3; __then(); }, true)); } else {

                              batchOptions.jobListOptions = jobOptions;
                              return client.job.listNext(nextLink, batchOptions, __cb(_, __frame, 45, 30, function ___(__0, __4) { result = __4; __then(); }, true)); } ; })(function __$listJobs() {

                            result.forEach(function(job) {
                              jobs.push(job); });

                            nextLink = result.odatanextLink; while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); }); }); })(function ___(err, __result) { __catch(function __$listJobs() { if (err) {



                    if (err.message) {
                      if ((typeof err.message === "object")) {
                        err.message = err.message.value; } ; } ;



                    return _(err); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$listJobs() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listJobs() {

              endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$listJobs() {


          cli.interaction.formatOutput(jobs, function(outputData) {
            if ((outputData.length === 0)) {
              logger.info($("No job found")); }
             else {
              logger.table(outputData, function(row, item) {
                row.cell($("Id"), item.id);
                row.cell($("State"), item.state); }); } ; }); _(); }); }); }); };











  function deleteJob(jobId, options, _) { var client, tips, batchOptions; var __frame = { name: "deleteJob", line: 351 }; return __func(_, this, arguments, deleteJob, 2, __frame, function __$deleteJob() {
      client = batchUtil.createBatchServiceClient(options);
      if (!jobId) {
        jobId = options.id; } ;

      return interaction.promptIfNotGiven($("Job id: "), jobId, __cb(_, __frame, 5, 24, function ___(__0, __1) { jobId = __1;
        tips = util.format($("Deleting job %s"), jobId);
        batchOptions = { };
        batchOptions.jobDeleteMethodOptions = batchUtil.getBatchOperationDefaultOption();

        if (options.ifMatch) {
          batchOptions.jobDeleteMethodOptions.ifMatch = options.ifMatch; } ;

        if (options.ifNoneMatch) {
          batchOptions.jobDeleteMethodOptions.ifNoneMatch = options.ifNoneMatch; } ;

        if (options.ifModifiedSince) {
          batchOptions.jobDeleteMethodOptions.ifModifiedSince = options.ifModifiedSince; } ;

        if (options.ifUnmodifiedSince) {
          batchOptions.jobDeleteMethodOptions.ifUnmodifiedSince = options.ifUnmodifiedSince; } ; return (function __$deleteJob(__then) {


          if (!options.quiet) {
            return interaction.confirm(util.format($("Do you want to delete job %s? [y/n]: "), jobId), __cb(_, __frame, 24, 23, function ___(__0, __3) { var __2 = !__3; return (function __$deleteJob(__then) { if (__2) { return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$deleteJob() {




          startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteJob() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteJob() {


                      return client.job.deleteMethod(jobId, batchOptions, __cb(_, __frame, 32, 17, __then, true)); }); })(function ___(err, __result) { __catch(function __$deleteJob() { if (err) {

                        if (batchUtil.isNotFoundException(err)) {
                          return _(new Error(util.format($("Job %s does not exist"), jobId))); }
                         else {
                          if (err.message) {
                            if ((typeof err.message === "object")) {
                              err.message = err.message.value; } ; } ;



                          return _(err); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$deleteJob() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteJob() {


                  endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deleteJob() {


              logger.info(util.format($("Job %s has been deleted successfully"), jobId)); _(); }); }); }); }, true)); }); };









  function updateJob(jobId, jsonFile, options, _) { var parsedJson, poolId, constraintsJson, objJson, client, resultMapper, tips, jobOptions, batchOptions; var __frame = { name: "updateJob", line: 410 }; return __func(_, this, arguments, updateJob, 3, __frame, function __$updateJob() {
      if (!jobId) {
        jobId = options.id; } ;

      return interaction.promptIfNotGiven($("Job id: "), jobId, __cb(_, __frame, 4, 24, function ___(__0, __1) { jobId = __1;
        if (!jsonFile) {
          jsonFile = options.jsonFile; } ;


        parsedJson = { }; return (function __$updateJob(__then) {

          if (!jsonFile) { return (function __$updateJob(__then) {
              if (((((!options.poolId && !options.priority) && !options.maxWallClockTime) && !options.maxTaskRetryCount) && !options.metadata)) {
                return interaction.promptIfNotGiven($("JSON file name: "), jsonFile, __cb(_, __frame, 13, 31, function ___(__0, __2) { jsonFile = __2; __then(); }, true)); } else {

                poolId = options.poolId;
                if (options.poolId) {
                  __.extend(parsedJson, { poolInfo: { poolId: poolId } }); } ;


                if (options.priority) {
                  __.extend(parsedJson, { priority: Number(options.priority) }); } ;


                constraintsJson = { };
                if (options.maxWallClockTime) {
                  __.extend(constraintsJson, { maxWallClockTime: options.maxWallClockTime }); } ;


                if (options.maxTaskRetryCount) {
                  __.extend(constraintsJson, { maxTaskRetryCount: Number(options.maxTaskRetryCount) }); } ;


                __.extend(parsedJson, { constraints: constraintsJson });

                if (options.metadata) {
                  ref = [];
                  options.metadata.split(";").forEach(function(entry) {
                    var item = entry.split("=");
                    ref.push({ name: item[0], value: item[1] }); });

                  __.extend(parsedJson, { metadata: ref }); } ; __then(); } ; })(__then); } else { __then(); } ; })(function __$updateJob() {




          if (jsonFile) {
            objJson = fs.readFileSync(jsonFile).toString();
            parsedJson = JSON.parse(objJson); } ;


          client = batchUtil.createBatchServiceClient(options);




          jobOptions = batchUtil.getBatchOperationDefaultOption();
          if (options.ifMatch) {
            jobOptions.ifMatch = options.ifMatch; } ;

          if (options.ifNoneMatch) {
            jobOptions.ifNoneMatch = options.ifNoneMatch; } ;

          if (options.ifModifiedSince) {
            jobOptions.ifModifiedSince = options.ifModifiedSince; } ;

          if (options.ifUnmodifiedSince) {
            jobOptions.ifUnmodifiedSince = options.ifUnmodifiedSince; } ;


          batchOptions = { }; return (function __$updateJob(__then) {

            if (options.replace) {
              if (((parsedJson !== null) && (parsedJson !== undefined))) {
                resultMapper = new client.models["JobUpdateParameter"]().mapper();
                updateJobParam = client.deserialize(resultMapper, parsedJson, "result"); } ;


              tips = util.format($("Updating job %s"), jobId);

              batchOptions.jobUpdateOptions = jobOptions;

              startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateJob() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateJob() {


                          return client.job.update(jobId, updateJobParam, batchOptions, __cb(_, __frame, 85, 19, __then, true)); }); })(function ___(err, __result) { __catch(function __$updateJob() { if (err) {

                            if (batchUtil.isNotFoundException(err)) {
                              return _(new Error(util.format($("Job %s does not exist"), jobId))); }
                             else {
                              if (err.message) {
                                if ((typeof err.message === "object")) {
                                  err.message = err.message.value; } ; } ;



                              return _(err); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$updateJob() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$updateJob() {


                      endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, __then); }); } else {


              if (((parsedJson !== null) && (parsedJson !== undefined))) {
                resultMapper = new client.models["JobPatchParameter"]().mapper();
                updateJobParam = client.deserialize(resultMapper, parsedJson, "result"); } ;


              tips = util.format($("Patching job %s"), jobId);

              batchOptions.jobPatchOptions = jobOptions;

              startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateJob() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateJob() {


                          return client.job.patch(jobId, updateJobParam, batchOptions, __cb(_, __frame, 114, 19, __then, true)); }); })(function ___(err, __result) { __catch(function __$updateJob() { if (err) {

                            if (batchUtil.isNotFoundException(err)) {
                              return _(new Error(util.format($("Job %s does not exist"), jobId))); }
                             else {
                              if (err.message) {
                                if ((typeof err.message === "object")) {
                                  err.message = err.message.value; } ; } ;



                              return _(err); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$updateJob() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$updateJob() {


                      endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, __then); }); } ; })(function __$updateJob() {



            logger.verbose(util.format($("Job %s has been updated/patched successfully"), jobId));
            return showJob(jobId, options, __cb(_, __frame, 133, 4, function __$updateJob() { _(); }, true)); }); }); }, true)); }); };








  function enableJob(jobId, options, _) { var client, tips, batchOptions; var __frame = { name: "enableJob", line: 552 }; return __func(_, this, arguments, enableJob, 2, __frame, function __$enableJob() {
      client = batchUtil.createBatchServiceClient(options);

      tips = util.format($("Enabling job %s"), jobId);
      batchOptions = { };
      batchOptions.jobEnableOptions = batchUtil.getBatchOperationDefaultOption();

      if (options.ifMatch) {
        batchOptions.jobEnableOptions.ifMatch = options.ifMatch; } ;

      if (options.ifNoneMatch) {
        batchOptions.jobEnableOptions.ifNoneMatch = options.ifNoneMatch; } ;

      if (options.ifModifiedSince) {
        batchOptions.jobEnableOptions.ifModifiedSince = options.ifModifiedSince; } ;

      if (options.ifUnmodifiedSince) {
        batchOptions.jobEnableOptions.ifUnmodifiedSince = options.ifUnmodifiedSince; } ;


      startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$enableJob() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$enableJob() {


                  return client.job.enable(jobId, batchOptions, __cb(_, __frame, 23, 17, __then, true)); }); })(function ___(err, __result) { __catch(function __$enableJob() { if (err) {

                    if (batchUtil.isNotFoundException(err)) {
                      return _(new Error(util.format($("Job %s does not exist"), jobId))); }
                     else {
                      if (err.message) {
                        if ((typeof err.message === "object")) {
                          err.message = err.message.value; } ; } ;



                      return _(err); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$enableJob() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$enableJob() {


              endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$enableJob() {


          logger.info(util.format($("Job %s has been enabled"), jobId)); _(); }); }); }); };








  function disableJob(jobId, options, _) { var client, disableOption, tips, batchOptions; var __frame = { name: "disableJob", line: 601 }; return __func(_, this, arguments, disableJob, 2, __frame, function __$disableJob() {
      client = batchUtil.createBatchServiceClient(options);

      disableOption = options.disableOption; return (function __$disableJob(__then) {
        if (!disableOption) {
          return interaction.promptIfNotGiven($("Job disable option: "), disableOption, __cb(_, __frame, 5, 34, function ___(__0, __1) { disableOption = __1; __then(); }, true)); } else { __then(); } ; })(function __$disableJob() {


        tips = util.format($("Disabling job %s"), jobId);
        batchOptions = { };
        batchOptions.jobDisableOptions = batchUtil.getBatchOperationDefaultOption();

        if (options.ifMatch) {
          batchOptions.jobDisableOptions.ifMatch = options.ifMatch; } ;

        if (options.ifNoneMatch) {
          batchOptions.jobDisableOptions.ifNoneMatch = options.ifNoneMatch; } ;

        if (options.ifModifiedSince) {
          batchOptions.jobDisableOptions.ifModifiedSince = options.ifModifiedSince; } ;

        if (options.ifUnmodifiedSince) {
          batchOptions.jobDisableOptions.ifUnmodifiedSince = options.ifUnmodifiedSince; } ;


        startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$disableJob() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$disableJob() {


                    return client.job.disable(jobId, disableOption, batchOptions, __cb(_, __frame, 28, 17, __then, true)); }); })(function ___(err, __result) { __catch(function __$disableJob() { if (err) {

                      if (batchUtil.isNotFoundException(err)) {
                        return _(new Error(util.format($("Job %s does not exist"), jobId))); }
                       else {
                        if (err.message) {
                          if ((typeof err.message === "object")) {
                            err.message = err.message.value; } ; } ;



                        return _(err); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$disableJob() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$disableJob() {


                endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$disableJob() {


            logger.info(util.format($("Job %s has been disabled"), jobId)); _(); }); }); }); }); };








  function terminateJob(jobId, options, _) { var client, tips, batchOptions; var __frame = { name: "terminateJob", line: 655 }; return __func(_, this, arguments, terminateJob, 2, __frame, function __$terminateJob() {
      client = batchUtil.createBatchServiceClient(options);

      tips = util.format($("Terminating job %s"), jobId);
      batchOptions = { };
      batchOptions.jobTerminateOptions = batchUtil.getBatchOperationDefaultOption();

      if (options.ifMatch) {
        batchOptions.jobTerminateOptions.ifMatch = options.ifMatch; } ;

      if (options.ifNoneMatch) {
        batchOptions.jobTerminateOptions.ifNoneMatch = options.ifNoneMatch; } ;

      if (options.ifModifiedSince) {
        batchOptions.jobTerminateOptions.ifModifiedSince = options.ifModifiedSince; } ;

      if (options.ifUnmodifiedSince) {
        batchOptions.jobTerminateOptions.ifUnmodifiedSince = options.ifUnmodifiedSince; } ;


      if (options.terminateReason) {
        batchOptions.terminateReason = options.terminateReason; } ;


      startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$terminateJob() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$terminateJob() {


                  return client.job.terminate(jobId, batchOptions, __cb(_, __frame, 27, 17, __then, true)); }); })(function ___(err, __result) { __catch(function __$terminateJob() { if (err) {

                    if (batchUtil.isNotFoundException(err)) {
                      return _(new Error(util.format($("Job %s does not exist"), jobId))); }
                     else {
                      if (err.message) {
                        if ((typeof err.message === "object")) {
                          err.message = err.message.value; } ; } ;



                      return _(err); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$terminateJob() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$terminateJob() {


              endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$terminateJob() {


          logger.info(util.format($("Job %s has been terminated"), jobId)); _(); }); }); }); };








  function listJobPrepAndReleaseTaskStatus(jobId, options, _) { var client, tips, batchOptions, jobPrepReleaseExecutionInfos, nextLink; var __frame = { name: "listJobPrepAndReleaseTaskStatus", line: 708 }; return __func(_, this, arguments, listJobPrepAndReleaseTaskStatus, 2, __frame, function __$listJobPrepAndReleaseTaskStatus() {
      client = batchUtil.createBatchServiceClient(options);

      tips = util.format($("Listing Batch job preparation and release task status for job %s"), jobId);
      batchOptions = { };

      batchOptions.jobListPreparationAndReleaseTaskStatusOptions = batchUtil.getBatchOperationDefaultOption();

      if (options.selectClause) {
        batchOptions.jobListPreparationAndReleaseTaskStatusOptions.select = options.selectClause; } ;

      if (options.filterClause) {
        batchOptions.jobListPreparationAndReleaseTaskStatusOptions.filter = options.filterClause; } ;


      jobPrepReleaseExecutionInfos = [];
      startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listJobPrepAndReleaseTaskStatus() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listJobPrepAndReleaseTaskStatus() {


                  return client.job.listPreparationAndReleaseTaskStatus(jobId, batchOptions, __cb(_, __frame, 19, 26, function ___(__0, __1) { result = __1;
                    result.forEach(function(jobPrepReleaseExecutionInfo) {
                      jobPrepReleaseExecutionInfos.push(jobPrepReleaseExecutionInfo); });

                    nextLink = result.odatanextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$listJobPrepAndReleaseTaskStatus() { __more = false;

                        var __4 = nextLink; if (__4) {
                          batchOptions = batchUtil.getBatchOperationDefaultOption();

                          batchOptions.jobListPreparationAndReleaseTaskStatusNextOptions = batchOptions;
                          return client.job.listPreparationAndReleaseTaskStatusNext(nextLink, batchOptions, __cb(_, __frame, 29, 28, function ___(__0, __2) { result = __2;
                            result.forEach(function(jobPrepReleaseExecutionInfo) {
                              jobPrepReleaseExecutionInfos.push(jobPrepReleaseExecutionInfo); });

                            nextLink = result.odatanextLink; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); }, true)); }); })(function ___(err, __result) { __catch(function __$listJobPrepAndReleaseTaskStatus() { if (err) {



                    if (err.message) {
                      if ((typeof err.message === "object")) {
                        err.message = err.message.value; } ; } ;



                    return _(err); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$listJobPrepAndReleaseTaskStatus() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listJobPrepAndReleaseTaskStatus() {

              endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$listJobPrepAndReleaseTaskStatus() {


          cli.interaction.formatOutput(jobPrepReleaseExecutionInfos, function(outputData) {
            if ((outputData.length === 0)) {
              logger.info($("No job preparation or job release task execution details found")); }
             else {
              logger.table(outputData, function(row, item) {
                row.cell($("Pool id"), item.poolId);
                row.cell($("Node id"), item.nodeId);
                if (item.jobPreparationTaskExecutionInfo) {
                  row.cell($("Job Prep State"), item.jobPreparationTaskExecutionInfo.state); } ;

                if (item.jobReleaseTaskExecutionInfo) {
                  row.cell($("Job Release State"), item.jobReleaseTaskExecutionInfo.state); } ; }); } ; }); _(); }); }); }); };};
