Skip to content

Commit

Permalink
137582169 mainly addressed here
Browse files Browse the repository at this point in the history
Runaway processes. Update to reload-cluster.js in order to get some consistency of processes management. Helps to normalize the problem if it does not fix it itself.

Some minor code quality changes, but very little extra after jshint fixes.
Update to test-functional files to make sure that tests run locally rather than on the npm version of a previous release.

Added test-stress directory for reload-cluster.js. Added unit tests for reload-cluster.js

Update npm dev dependencies to include rewire, which makes functions and variables internal to a module available to unit tests.
  • Loading branch information
rleddy authored and Indraneel Dey committed Aug 1, 2019
1 parent ed5ddfd commit 52fb89d
Show file tree
Hide file tree
Showing 33 changed files with 2,574 additions and 804 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ logging-report.txt
logstuf.txt
quick.sh
.nyc_output
test-e2e-local
test-e2e/e2evars.sh
test-e2e-local/test.yaml
test-e2e-local/test2.yaml
test-e2e-local/test3.yaml
test-e2e-local/leddyr-eval-test-config-BK.yaml
test-e2e-local/tmp_emg_file.yaml
test-stress/rateset.txt
2 changes: 1 addition & 1 deletion cli/cmd-cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const setup = function setup() {

var running = false;
commander.commands.forEach(function(command) {
if (command._name == commander.rawArgs[2]) {
if (command._name === commander.rawArgs[2]) {
running = true;
}
});
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd-private.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var app = require('commander');
var privateOperations = require('./lib/private')();
const debug = require('debug')('configure');
//const debug = require('debug')('configure');
const upgradekvm = require('./lib/upgrade-kvm')();
const upgradeauth = require('./lib/upgrade-edgeauth')();
const rotatekey = require('./lib/rotate-key')();
Expand Down Expand Up @@ -208,7 +208,7 @@ module.exports = function() {

var running = false;
app.commands.forEach(function(command) {
if (command._name == app.rawArgs[2]) {
if (command._name === app.rawArgs[2]) {
running = true;
}
});
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const setup = function setup() {

var running = false;
commander.commands.forEach(function (command) {
if (command._name == commander.rawArgs[2]) {
if (command._name === commander.rawArgs[2]) {
running = true;
}
});
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ const setup = function setup() {
*/

var child = new(forever.Monitor)(path.join(__dirname, '..', 'app.js'), foreverOptions);
if (options.action == "start") {
if (options.action === "start") {
try {
fs.appendFileSync(pidpath, process.pid + '|');
child.start();
Expand Down Expand Up @@ -578,7 +578,7 @@ const setup = function setup() {

var running = false;
commander.commands.forEach(function(command) {
if (command._name == commander.rawArgs[2]) {
if (command._name === commander.rawArgs[2]) {
running = true;
}
});
Expand Down
8 changes: 4 additions & 4 deletions cli/lib/cert-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const request = require('request');
const util = require('util');
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const prompt = require('cli-prompt');
const url = require('url');
const pem = require('pem');
const crypto = require('crypto');
const async = require('async');
const debug = require('debug')('cert')
//const yaml = require('js-yaml');
//const prompt = require('cli-prompt');

const ERR_STORE_EXISTS = 'com.apigee.secure-store.storekey.already.exists';
const ERR_STORE_MISSING = 'com.apigee.secure-store.securestore_does_not_exist';
Expand Down Expand Up @@ -176,8 +176,8 @@ CertLogic.prototype.installCertWithPassword = function(options, callback) {

CertLogic.prototype.generateKeysWithPassword = function generateKeysWithPassword(options, cb) {

const keySecretMessage = this.keySecretMessage;
const bootstrapMessage = this.bootstrapMessage;
//const keySecretMessage = this.keySecretMessage;
// bootstrapMessage = this.bootstrapMessage;
const managementUri = this.baseUri;

function genkey(cb) {
Expand Down
11 changes: 6 additions & 5 deletions cli/lib/cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

const cert = require('./cert-lib')
const edgeconfig = require('microgateway-config');
const prompt = require('cli-prompt');
const path = require('path');
const apigeetool = require('apigeetool');
const _ = require('lodash');
const async = require('async');
const util = require('util');
const configLocations = require('../../config/locations');
const assert = require('assert')
//const prompt = require('cli-prompt');
//const path = require('path');
//const apigeetool = require('apigeetool');
//const _ = require('lodash');
//const async = require('async');



const Cert = function() {
Expand Down
28 changes: 16 additions & 12 deletions cli/lib/configure.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

const edgeconfig = require('microgateway-config')
const prompt = require('cli-prompt');
const path = require('path');
const apigeetool = require('apigeetool');
const _ = require('lodash');
//const prompt = require('cli-prompt');
//const path = require('path');
//const apigeetool = require('apigeetool');
//const _ = require('lodash');
const async = require('async')
const util = require('util')
const fs = require('fs')
Expand All @@ -15,6 +15,9 @@ const BATCHSIZE = 500;
const FLUSHINTERVAL = 5000;
var defaultConfig ;




var certLib = require('./cert-lib')
var cert;
var deployAuthLib = require('./deploy-auth')
Expand Down Expand Up @@ -86,7 +89,7 @@ Configure.prototype.configure = function configure(options, cb) {
targetDir: configFileDirectory,
targetFile: targetFile,
overwrite: true
}, function (err, configPath) {
}, function (/* err, configPath */) {
options.deployed = false;
deployAuth.checkDeployedProxies(options, (err, options) => {
if (err) {
Expand All @@ -111,7 +114,7 @@ function configureEdgemicroWithCreds(options, cb) {
var tasks = [],
agentConfigPath;

if (options.deployed == false) {
if (options.deployed === false) {
tasks.push(function (callback) {
deployAuth.deployWithLeanPayload(options, callback);
});
Expand All @@ -121,7 +124,7 @@ function configureEdgemicroWithCreds(options, cb) {
function (callback) {
setTimeout(() => {
console.log('checking org for existing KVM');
cert.checkCertWithPassword(options, function (err, certs) {
cert.checkCertWithPassword(options, function (err/*, certs */) {
if (err) {
console.log('error checking for cert. Installing new cert.');
cert.installCertWithPassword(options, callback);
Expand Down Expand Up @@ -156,7 +159,7 @@ function configureEdgemicroWithCreds(options, cb) {

addEnvVars(agentConfig);

if (options.deployed == false) {
if (options.deployed === false) {
agentConfig['edge_config']['jwt_public_key'] = (options.url ? options.url+"/edgemicro-auth/publicKey" : results[0]); // get deploy results
agentConfig['edge_config'].bootstrap = results[2].bootstrap; // get genkeys results
} else {
Expand All @@ -168,15 +171,15 @@ function configureEdgemicroWithCreds(options, cb) {
if (publicKeyUri) {
agentConfig['edge_config']['products'] = publicKeyUri.replace('publicKey', 'products');

if (!agentConfig.hasOwnProperty('oauth') || agentConfig['oauth'] == null) {
if (!agentConfig.hasOwnProperty('oauth') || agentConfig['oauth'] === null) {
agentConfig['oauth'] = {};
}
agentConfig['oauth']['verify_api_key_url'] = publicKeyUri.replace('publicKey', 'verifyApiKey');
}

var bootstrapUri = agentConfig['edge_config']['bootstrap'];
if (bootstrapUri) {
if (!agentConfig.hasOwnProperty('analytics') || agentConfig['analytics'] == null) {
if (!agentConfig.hasOwnProperty('analytics') || agentConfig['analytics'] === null) {
agentConfig['analytics'] = {};
}

Expand All @@ -191,7 +194,7 @@ function configureEdgemicroWithCreds(options, cb) {
edgeconfig.save(agentConfig, agentConfigPath); // if it didn't throw, save succeeded
console.log();

if (options.deployed == true) {
if (options.deployed === true) {
console.log('vault info:\n', results[0]);
} else {
console.log('vault info:\n', results[1]);
Expand Down Expand Up @@ -219,11 +222,12 @@ function addEnvVars(config) {
config.edge_config.authUri = process.env.AUTH_URI || config.edge_config.authUri;
config.edge_config.baseUri = process.env.BASE_URI || config.edge_config.baseUri;
}

/*
function printError(err) {
if (err.response) {
console.log(err.response.error);
} else {
console.log(err);
}
}
*/
35 changes: 19 additions & 16 deletions cli/lib/deploy-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ const tmp = require('tmp');
const cpr = require('cpr');
const rimraf = require('rimraf');
const apigeetool = require('apigeetool');
const request = require('request');
//const request = require('request');
const assert = require('assert');
const path = require('path');
const async = require('async')
const util = require('util')
const fs = require('fs')
const DEFAULT_HOSTS = 'default,secure';
const url = require('url');
//const url = require('url');
const debug = require('debug')('edgemicro-auth')
const _ = require('lodash')
//const _ = require('lodash')
var exec = require('child_process').exec;

var run = function(cmd, cb) {
//console.log('run %s',cmd)
var child = exec(cmd, {
// var child =
exec(cmd, {
maxBuffer: 1024 * 500
}, function(error, stdout, stderr) {
}, function(error /*, stdout, stderr */) {
cb(error)
});
};
Expand Down Expand Up @@ -69,7 +70,7 @@ Deployment.prototype.deployEdgeMicroInternalProxy = function deployEdgeMicroInte
Deployment.prototype.deployWithLeanPayload = function deployWithLeanPayload(options, callback) {
const authUri = this.authUri;
const managementUri = this.managementUri;
const homeDir = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
const homeDir = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
var tmpDir = tmp.dirSync({
keep: true,
dir: path.resolve(homeDir, '.edgemicro')
Expand Down Expand Up @@ -114,7 +115,7 @@ Deployment.prototype.deployWithLeanPayload = function deployWithLeanPayload(opti
rimraf(tmpDir.name, cb);
})

async.series(tasks, function(err, results) {
async.series(tasks, function(err /*, results */) {
if (err) {
return callback(err);
}
Expand All @@ -140,8 +141,8 @@ Deployment.prototype.checkDeployedInternalProxies = function checkDeployedIntern
opts.username = options.username;
opts.password = options.password;
}
const that = this;
apigeetool.listDeployments(opts, function(err, proxies) {
// const that = this;
apigeetool.listDeployments(opts, function(err /*, proxies */) {
if (err) {
if (err.message.includes("404")) {
return cb(null, options);
Expand Down Expand Up @@ -172,8 +173,8 @@ Deployment.prototype.checkDeployedProxies = function checkDeployedProxies(option
opts.username = options.username;
opts.password = options.password;
}
const that = this;
apigeetool.listDeployments(opts, function(err, proxies) {
//const that = this;
apigeetool.listDeployments(opts, function(err /*, proxies */) {
if (err) {
if (err.message.includes("404")) {
return cb(null, options);
Expand All @@ -198,7 +199,7 @@ function setEdgeMicroInternalEndpoint(file, runtimeUrl) {
}

function editVirtualHosts(file, virtualhosts) {
if (virtualhosts == DEFAULT_HOSTS) return;
if (virtualhosts === DEFAULT_HOSTS) return;
var beginVH = "<VirtualHost>";
var endVH = "</VirtualHost>";
var defaultVH = "<VirtualHost>default</VirtualHost>";
Expand All @@ -207,10 +208,10 @@ function editVirtualHosts(file, virtualhosts) {
var virtualhost = virtualhosts.split(",");
var newcontent;

if (virtualhost.length == 1 && !virtualhost.includes('default') && !virtualhost.includes('secure')) {
if (virtualhost.length === 1 && !virtualhost.includes('default') && !virtualhost.includes('secure')) {
content = content.replace(defaultVH, beginVH + virtualhost[0] + endVH);
newcontent = content.replace(secureVH, '');
} else if (virtualhost.length == 1) {
} else if (virtualhost.length === 1) {
if (!virtualhost.includes('default')) {
//remove default
content = content.replace(defaultVH, '');
Expand Down Expand Up @@ -291,7 +292,7 @@ Deployment.prototype.deployProxyWithPassword = function deployProxyWithPassword(
});
}


/*
function installJavaCallout(managementUri, opts, cb) {
var jarName = 'micro-gateway-products-javacallout-1.0.0.jar';
Expand Down Expand Up @@ -355,6 +356,7 @@ function installJavaCallout(managementUri, opts, cb) {
fileStream.pipe(httpReq);
}
function translateError(err, res) {
if (!err && res.statusCode >= 400) {
Expand All @@ -364,4 +366,5 @@ function translateError(err, res) {
res.error = err;
}
return err;
}
}
*/
Loading

0 comments on commit 52fb89d

Please sign in to comment.