UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

280 lines (142 loc) 19 kB
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ "use strict"; var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var utils = require("../../util/utils"); var serviceFabricUtils = require("./serviceFabricUtils"); var serviceFabricClient = require("azure-servicefabric"); var util = require("util"); var path = require("path"); var fs = require("fs"); var request = require("request"); var url = require("url"); var async = require("async"); var $ = utils.getLocaleString; exports.init = function(cli) { var log = cli.output; var serviceFabric = cli.category("servicefabric").description($("Commands to manage your Azure Service Fabric")); var application = serviceFabric.category("application").description($("Commands to manage your application")); var applicationPackage = application.category("package").description($("Commands to manage your application package")); applicationPackage.command("copy [applicationPackagePath] [imageStoreConnectionString]").description($("Copy application package, Example: azure servicefabric application package copy --application-package-path /tmp/package1 --image-store-connection-string fabric:ImageStore")).option("-p --application-package-path <applicationPackagePath>", $("the path of the application package")).option("-c --image-store-connection-string <imageStoreConnectionString>", $("the string of the image store connection")).execute(function __1(applicationPackagePath, imageStoreConnectionString, options, _) { var progress, config, connectionUrl, clientOptions, files, totalSize, isApplicationPackagePathDir, currentTotalSize, currentSize, currentFilesCount, res; var __frame = { name: "__1", line: 47 }; return __func(_, this, arguments, __1, 3, __frame, function __$__1() { return cli.interaction.promptIfNotGiven($("applicationPackagePath:"), applicationPackagePath, __cb(_, __frame, 1, 47, function ___(__0, __2) { applicationPackagePath = __2; return cli.interaction.promptIfNotGiven($("imageStoreConnectionString:"), imageStoreConnectionString, __cb(_, __frame, 2, 51, function ___(__0, __3) { imageStoreConnectionString = __3; applicationPackagePath = path.resolve(applicationPackagePath); progress = cli.interaction.progress($("Copy application package")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return serviceFabricUtils.readServiceFabricConfig(progress, __cb(_, __frame, 8, 40, function ___(__0, __4) { config = __4; return serviceFabricUtils.createConnectionUrl(config, __cb(_, __frame, 10, 47, function ___(__0, __5) { connectionUrl = __5; return serviceFabricUtils.getClientOptions(config, __cb(_, __frame, 11, 47, function ___(__0, __6) { clientOptions = __6.requestOptions; files = serviceFabricUtils.walkDirTree(applicationPackagePath); totalSize = 0; return files.forEach_(__cb(_, __frame, 15, 14, function __$__1() { isApplicationPackagePathDir = fs.statSync(applicationPackagePath).isDirectory(); currentTotalSize = 0; currentSize = 0; currentFilesCount = 0; return async.eachSeries(files, function(file, callback) { var finalPath = url.resolve("/ImageStore/", (((isApplicationPackagePathDir ? path.join(path.basename(applicationPackagePath), file.path) : file.path)) + "?api-version=1.0")); var finalUrl = url.resolve(connectionUrl, finalPath); clientOptions.url = finalUrl; clientOptions.headers = { "Content-Type": "application/octet-stream" }; clientOptions.forever = true; var updateProgress = function() { progress.write(function() { }, util.format("[%d%%] %d/%d files, %d/%d KBs", Math.floor(((((currentTotalSize + currentSize)) / totalSize) * 100)), currentFilesCount, files.length, Math.round((((currentTotalSize + currentSize)) / 1024)), Math.round((totalSize / 1024)))); }; if (file.path.endsWith("_.dir")) { request.put(clientOptions, function() { currentFilesCount++; updateProgress(); callback(); }); } else { var fullFilePath = (isApplicationPackagePathDir ? path.join(applicationPackagePath, file.path) : path.join(path.dirname(applicationPackagePath), file.path)); var readStream = fs.createReadStream(fullFilePath); var writeStream = readStream.pipe(request.put(clientOptions)); var progressInterval = setInterval(function() { if (((!writeStream.req || !writeStream.req.connection) || !writeStream.req.connection._bytesDispatched)) { return; } ; currentSize = (writeStream.req.connection._bytesDispatched - currentTotalSize); updateProgress(); }, 100); writeStream.on("end", function() { currentSize = (writeStream.req.connection._bytesDispatched - currentTotalSize); var bytesDiff = (currentSize - file.size); totalSize += bytesDiff; currentSize = 0; currentTotalSize = writeStream.req.connection._bytesDispatched; currentFilesCount++; clearInterval(progressInterval); updateProgress(); callback(); }); writeStream.on("error", function(err) { callback(err); }); } ; }, __cb(_, __frame, 22, 24, function ___(__0, __7) { res = __7; progress.end(); cli.interaction.formatOutput(res, function(data) { log.json(data); }); __then(); }, true)); }, true), function __1(_, file) { var __frame = { name: "__1", line: 62 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { totalSize += file.size; _(); }); }); }, true)); }, true)); }, true)); }); })(function ___(e, __result) { __catch(function __$__1() { if (e) { progress.end(); return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__1() { _(); }); }); }, true)); }, true)); }); }); var code = serviceFabric.category("code").description($("Commands to manage your code")); var codePackage = code.category("package").description($("Commands to manage your code package")); var codePackageDeployed = codePackage.category("deployed").description($("Commands to manage your deployed code package")); codePackageDeployed.command("show [nodeName] [applicationName]").description($("Show deployed application health")).option("-n --node-name <nodeName>", $("the name of the node")).option("-a --application-name <applicationName>", $("the name of the application")).option("--select <fields>", $("select fields to show, call without this parameter to see all fields")).execute(function __2(nodeName, applicationName, options, _) { var progress, config, client, res; var __frame = { name: "__2", line: 140 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() { progress = cli.interaction.progress($("Show deployed code package")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() { return serviceFabricUtils.readServiceFabricConfig(progress, __cb(_, __frame, 4, 40, function ___(__0, __1) { config = __1; return serviceFabricUtils.createConnectionUrl(config, __cb(_, __frame, 6, 79, function ___(__0, __2) { return serviceFabricUtils.getClientOptions(config, __cb(_, __frame, 6, 130, function ___(__0, __3) { client = new serviceFabricClient("3.0-preview", __2, __3); return serviceFabricUtils.parseUrl(applicationName, __cb(_, __frame, 7, 45, function ___(__0, __4) { applicationName = __4; return client.deployedCodePackages.get(nodeName, applicationName, options, __cb(_, __frame, 8, 46, function ___(__0, __5) { res = __5; return (function __$__2(__then) { if (options.select) { return serviceFabricUtils.pick(res, options.select, __cb(_, __frame, 10, 35, function ___(__0, __6) { res = __6; __then(); }, true)); } else { __then(); } ; })(function __$__2() { serviceFabricUtils.setPackageEnumVal(res); progress.end(); cli.interaction.formatOutput(res, function(data) { log.json(data); }); __then(); }); }, true)); }, true)); }, true)); }, true)); }, true)); }); })(function ___(e, __result) { __catch(function __$__2() { if (e) { progress.end(); return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__2() { _(); }); }); }); }); var service = serviceFabric.category("service").description($("Commands to manage your service")); var servicePackage = service.category("package").description($("Commands to send your service package")); var servicePackageDeployed = servicePackage.category("deployed").description($("Commands to send your deployed service package")); servicePackageDeployed.command("show [nodeName] [applicationName]").description($("Show deployed service package")).option("-n --node-name <nodeName>", $("the name of the node")).option("-a --application-name <applicationName>", $("the name of the application")).option("--select <fields>", $("select fields to show, call without this parameter to see all fields")).execute(function __3(nodeName, applicationName, options, _) { var progress, config, client, res; var __frame = { name: "__3", line: 179 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() { progress = cli.interaction.progress($("Show deployed service package")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() { return serviceFabricUtils.readServiceFabricConfig(progress, __cb(_, __frame, 4, 40, function ___(__0, __1) { config = __1; return serviceFabricUtils.createConnectionUrl(config, __cb(_, __frame, 6, 79, function ___(__0, __2) { return serviceFabricUtils.getClientOptions(config, __cb(_, __frame, 6, 130, function ___(__0, __3) { client = new serviceFabricClient("3.0-preview", __2, __3); return serviceFabricUtils.parseUrl(applicationName, __cb(_, __frame, 7, 45, function ___(__0, __4) { applicationName = __4; return client.deployedServicePackages.get(nodeName, applicationName, options, __cb(_, __frame, 8, 49, function ___(__0, __5) { res = __5; return (function __$__3(__then) { if (options.select) { return serviceFabricUtils.pick(res, options.select, __cb(_, __frame, 10, 35, function ___(__0, __6) { res = __6; __then(); }, true)); } else { __then(); } ; })(function __$__3() { serviceFabricUtils.setPackageEnumVal(res); progress.end(); cli.interaction.formatOutput(res, function(data) { log.json(data); }); __then(); }); }, true)); }, true)); }, true)); }, true)); }, true)); }); })(function ___(e, __result) { __catch(function __$__3() { if (e) { progress.end(); return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__3() { _(); }); }); }); }); var servicePackageDeployedHealth = servicePackageDeployed.category("health").description($("Commands to manage your deployed service package health")); servicePackageDeployedHealth.command("show [nodeName] [applicationName] [servicePackageName]").description($("Show deployed service package health")).option("-n --node-name <nodeName>", $("the name of the node")).option("-a --application-name <applicationName>", $("the name of the application")).option("-p --service-package-name <servicePackageName>", $("the name of the service package")).option("-f --events-health-state-filter <eventsHealthStateFilter>", $("the filter of the events health state, values are [Default|None|Ok|Warning|Error|All]")).option("--select <fields>", $("select fields to show, call without this parameter to see all fields")).execute(function __4(nodeName, applicationName, servicePackageName, options, _) { var progress, config, client, res; var __frame = { name: "__4", line: 214 }; return __func(_, this, arguments, __4, 4, __frame, function __$__4() { progress = cli.interaction.progress($("Show deployed service package")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() { return serviceFabricUtils.readServiceFabricConfig(progress, __cb(_, __frame, 4, 40, function ___(__0, __1) { config = __1; return serviceFabricUtils.createConnectionUrl(config, __cb(_, __frame, 6, 79, function ___(__0, __2) { return serviceFabricUtils.getClientOptions(config, __cb(_, __frame, 6, 130, function ___(__0, __3) { client = new serviceFabricClient("3.0-preview", __2, __3); return serviceFabricUtils.parseUrl(applicationName, __cb(_, __frame, 7, 45, function ___(__0, __4) { applicationName = __4; if (servicePackageName) { options.servicePackageName = servicePackageName; } ; return client.deployedServicePackageHealths.get(nodeName, applicationName, options, __cb(_, __frame, 9, 55, function ___(__0, __5) { res = __5; return (function __$__4(__then) { if (options.select) { return serviceFabricUtils.pick(res, options.select, __cb(_, __frame, 11, 35, function ___(__0, __6) { res = __6; __then(); }, true)); } else { __then(); } ; })(function __$__4() { serviceFabricUtils.setPackageEnumVal(res); progress.end(); cli.interaction.formatOutput(res, function(data) { log.json(data); }); __then(); }); }, true)); }, true)); }, true)); }, true)); }, true)); }); })(function ___(e, __result) { __catch(function __$__4() { if (e) { progress.end(); return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__4() { _(); }); }); }); }); servicePackageDeployedHealth.command("send [nodeName] [applicationName] [serviceManifestName] [sourceId] [property] [healthState]").description($("Send deployed service package health, Example: azure servicefabric application health send --node-name node1 fabric:app --source-id monitor --property pc --health-state Ok --description healthy")).option("-n --node-name <nodeName>", $("the name of the node")).option("-a --application-name <applicationName>", $("the name of the application")).option("-m --service-manifest-name <serviceManifestName>", $("the name of the service manifest")).option("-i --source-id <sourceId>", $("the id of the source")).option("-p --property <property>", $("the property")).option("-e --health-state <healthState>", $("the state of the health, values are [Ok|Warning|Error|Unknown]")).option("-d --description <description>", $("the description")).option("-l --time-to-live-in-milliseconds <timeToLiveInMilliseconds>", $("the time in milliseconds for live")).option("-q --sequence-number <sequenceNumber>", $("the number of the sequence")).option("-w --remove-when-expired", $("the boolean of the remove when expired")).execute(function __5(nodeName, applicationName, serviceManifestName, sourceId, property, healthState, options, _) { var progress, config, client, applicationHealthReport, res; var __frame = { name: "__5", line: 252 }; return __func(_, this, arguments, __5, 7, __frame, function __$__5() { progress = cli.interaction.progress($("Send deployed service package health")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() { return serviceFabricUtils.readServiceFabricConfig(progress, __cb(_, __frame, 4, 40, function ___(__0, __1) { config = __1; return serviceFabricUtils.createConnectionUrl(config, __cb(_, __frame, 5, 79, function ___(__0, __2) { return serviceFabricUtils.getClientOptions(config, __cb(_, __frame, 5, 130, function ___(__0, __3) { client = new serviceFabricClient("3.0-preview", __2, __3); return serviceFabricUtils.parseUrl(applicationName, __cb(_, __frame, 6, 45, function ___(__0, __4) { applicationName = __4; applicationHealthReport = { }; if (sourceId) { applicationHealthReport.sourceId = sourceId; } ; if (property) { applicationHealthReport.property = property; } ; if (healthState) { applicationHealthReport.healthState = serviceFabricUtils.getEnumVal("healthState", healthState); } ; if (options.description) { applicationHealthReport.description = options.description; } ; if (options.timeToLiveInMilliseconds) { applicationHealthReport.timeToLiveInMilliSeconds = options.timeToLiveInMilliseconds; } ; if (options.sequenceNumber) { applicationHealthReport.sequenceNumber = options.sequenceNumber; } ; if (options.removeWhenExpired) { applicationHealthReport.removeWhenExpired = true; } ; return client.deployedServicePackageHealths.send(nodeName, applicationName, serviceManifestName, applicationHealthReport, options, __cb(_, __frame, 17, 55, function ___(__0, __5) { res = __5; serviceFabricUtils.setPackageEnumVal(res); progress.end(); cli.interaction.formatOutput(res, function(data) { log.json(data); }); __then(); }, true)); }, true)); }, true)); }, true)); }, true)); }); })(function ___(e, __result) { __catch(function __$__5() { if (e) { progress.end(); return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__5() { _(); }); }); }); });};