diff --git a/lib/commands/deployExistingRevision.js b/lib/commands/deployExistingRevision.js index e8806db..9f22eb8 100644 --- a/lib/commands/deployExistingRevision.js +++ b/lib/commands/deployExistingRevision.js @@ -9,7 +9,7 @@ var defaults = require('../defaults'); var options = require('../options'); var parseDeployments = require('./parsedeployments'); -var DeploymentDelay = 60; +var DefaultDeploymentDelay = 0; var descriptor = defaults.defaultDescriptor({ api: { name: 'API Name', @@ -28,6 +28,12 @@ var descriptor = defaults.defaultDescriptor({ shortOption: 'r', required: true, prompt: true + }, + deploymentDelay: { + name: 'DeploymentDelay (default=' + DefaultDeploymentDelay + ")", + shortOption: 'z', + required: false, + prompt: true } }); module.exports.descriptor = descriptor; @@ -74,9 +80,12 @@ module.exports.run = function(opts, cb) { } function deployProxy(opts, request, done) { + if( !opts.deploymentDelay ) { + opts.deploymentDelay = DefaultDeploymentDelay; + } if (opts.verbose) { - console.log('Deploying revision %d of %s to %s', opts.revision, - opts.api, opts.environments); + console.log('Deploying revision %d of %s to %s, delaying %s', + opts.revision, opts.api, opts.environments, opts.deploymentDelay); } var environments = opts.environments.split(','); @@ -87,7 +96,7 @@ function deployProxy(opts, request, done) { opts.baseuri, opts.organization, environment, opts.api, opts.revision); if (opts.debug) { console.log('Going to POST to %s', uri); } - var deployCmd = util.format('action=deploy&override=true&delay=%d', DeploymentDelay); + var deployCmd = util.format('action=deploy&override=true&delay=%d', opts.deploymentDelay); if (opts['base-path']) { deployCmd = util.format('%s&basepath=%s', deployCmd, opts['base-path']); } diff --git a/lib/commands/deployhostedtarget.js b/lib/commands/deployhostedtarget.js index 97a7ce7..4fa66be 100644 --- a/lib/commands/deployhostedtarget.js +++ b/lib/commands/deployhostedtarget.js @@ -69,6 +69,12 @@ var descriptor = defaults.defaultDescriptor({ name: 'Upload Modules', shortOption: 'U', toggle: true + }, + zeroDowntimeDelay: { + name: 'Delay N seconds for zero downtime deployment (default=60)', + shortOption: 'Z', + required: false, + prompt: true } }); module.exports.descriptor = descriptor; diff --git a/lib/commands/deployproxy.js b/lib/commands/deployproxy.js index d0d124c..77222c9 100644 --- a/lib/commands/deployproxy.js +++ b/lib/commands/deployproxy.js @@ -20,7 +20,7 @@ var cleanResults = require('../utils').cleanResults; var ProxyBase = 'apiproxy'; var XmlExp = /(.+)\.xml$/i; -var DeploymentDelay = 60; +var DefaultZeroDowntimeDelay = 60; var BASE_PATH_REGEXP = /]*>(.*?)<\/BasePath>/; // By default, do not run NPM remotely @@ -71,6 +71,12 @@ var descriptor = defaults.defaultDescriptor({ name: 'Wait N seconds after importing proxy before deploying', shortOption: 'W', required: false + }, + zeroDowntimeDelay: { + name: 'Delay N seconds for zero downtime deployment (default=' + DefaultZeroDowntimeDelay + ")", + shortOption: 'Z', + required: false, + prompt: true } }); module.exports.descriptor = descriptor; @@ -693,9 +699,13 @@ function deployProxy(opts, request, done) { return; } + if( !opts.zeroDowntimeDelay ) { + opts.zeroDowntimeDelay = DefaultZeroDowntimeDelay; + } + if (opts.verbose) { - console.log('Deploying revision %d of %s to %s', opts.deploymentVersion, - opts.api, opts.environments); + console.log('Deploying revision %d of %s to %s, delaying %s seconds for zero downtime deployment.', + opts.deploymentVersion, opts.api, opts.environments, opts.zeroDowntimeDelay); } var environments = opts.environments.split(','); @@ -706,7 +716,7 @@ function deployProxy(opts, request, done) { opts.baseuri, opts.organization, environment, opts.api, opts.deploymentVersion); if (opts.debug) { console.log('Going to POST to %s', uri); } - var deployCmd = util.format('action=deploy&override=true&delay=%d', DeploymentDelay); + var deployCmd = util.format('action=deploy&override=true&delay=%d', opts.zeroDowntimeDelay); if (opts['base-path']) { deployCmd = util.format('%s&basepath=%s', deployCmd, opts['base-path']); } @@ -753,7 +763,7 @@ function deployProxy(opts, request, done) { tasks[env] = deployToEnvironment.bind(this, env); }); - if (opts.verbose) { console.log('Delaying deployment for %d seconds', opts.waitAfterImportDelay); } + if (opts.verbose) { console.log('Waiting %d seconds after import to deploy', opts.waitAfterImportDelay); } setTimeout(function () { async.parallel(tasks, done); }, opts.waitAfterImportDelay*1000); diff --git a/lib/commands/deploysharedflow.js b/lib/commands/deploysharedflow.js index 4b32b89..a86667a 100644 --- a/lib/commands/deploysharedflow.js +++ b/lib/commands/deploysharedflow.js @@ -17,7 +17,7 @@ var parseDeployments = require('./parsedeployments'); var SharedFlowBase = 'sharedflowbundle'; var XmlExp = /(.+)\.xml$/i; -var DeploymentDelay = 60; +var DefaultZeroDowntimeDelay = 60; var descriptor = defaults.defaultDescriptor({ name: { @@ -39,6 +39,12 @@ var descriptor = defaults.defaultDescriptor({ name: 'Import Only', shortOption: 'i', toggle: true + }, + zeroDowntimeDelay: { + name: 'Delay N seconds for zero downtime deployment (default=' + DefaultZeroDowntimeDelay + ")", + shortOption: 'Z', + required: false, + prompt: true } }); module.exports.descriptor = descriptor; @@ -434,9 +440,13 @@ function deploySharedFlow(opts, request, done) { return; } + if( !opts.zeroDowntimeDelay ) { + opts.zeroDowntimeDelay = DefaultZeroDowntimeDelay; + } + if (opts.verbose) { - console.log('Deploying revision %d of %s to %s', opts.deploymentVersion, - opts.name, opts.environments); + console.log('Deploying revision %d of %s to %s, delaying %s seconds for zero downtime deployment.', + opts.deploymentVersion, opts.name, opts.environments, opts.zeroDowntimeDelay); } var environments = opts.environments.split(','); @@ -449,7 +459,7 @@ function deploySharedFlow(opts, request, done) { console.log('Going to POST to %s', uri); } - var deployCmd = util.format('action=deploy&override=true&delay=%d', DeploymentDelay); + var deployCmd = util.format('action=deploy&override=true&delay=%d', opts.zeroDowntimeDelay); if (opts['base-path']) { deployCmd = util.format('%s&basepath=%s', deployCmd, opts['base-path']); } diff --git a/lib/deploycommon.js b/lib/deploycommon.js index a500a94..680c5e3 100644 --- a/lib/deploycommon.js +++ b/lib/deploycommon.js @@ -16,7 +16,7 @@ tmp.setGracefulCleanup(); var ziputils = require('./ziputils'); -var DeploymentDelay = 60 +var DefaultZeroDowntimeDelay = 60; var ProxyBase = 'apiproxy'; module.exports.createApiProxy = function(opts, request, done) { @@ -104,9 +104,13 @@ module.exports.deployProxy = function(opts, request, done) { return; } + if( !opts.zeroDowntimeDelay ) { + opts.zeroDowntimeDelay = DefaultZeroDowntimeDelay; + } + if (opts.verbose) { - console.log('Deploying revision %d of %s to %s', opts.deploymentVersion, - opts.api, opts.environments); + console.log('Deploying revision %d of %s to %s, delaying %s seconds for zero downtime deployment.', + opts.deploymentVersion, opts.api, opts.environments, opts.zeroDowntimeDelay); } var environments = opts.environments.split(','); @@ -120,7 +124,7 @@ module.exports.deployProxy = function(opts, request, done) { if (opts.debug) { console.log('Going to POST to %s', uri); } // Unlike "deployproxy" command, ignore the base path here, because we baked it into the proxy definition. - var deployCmd = util.format('action=deploy&override=true&delay=%d', DeploymentDelay); + var deployCmd = util.format('action=deploy&override=true&delay=%d', opts.zeroDowntimeDelay); if (opts.debug) { console.log('Going go send command %s', deployCmd); } diff --git a/package-lock.json b/package-lock.json index c62a2ca..63952e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "apigeetool", - "version": "0.14.1", + "version": "0.14.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 65dfedf..604c1e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apigeetool", - "version": "0.14.2", + "version": "0.14.3", "description": "A CLI for Apigee Edge", "main": "lib/main.js", "bin": {