Rename internal to update and external to provision

This commit is contained in:
Girish Ramakrishnan
2014-11-21 14:09:19 -08:00
parent b3569ee57f
commit 04cef32cdd
2 changed files with 34 additions and 34 deletions
+21 -21
View File
@@ -25,8 +25,8 @@ exports = module.exports = {
stop: stop
};
var gHttpsServer = null, // external server; used for install/restore
gHttpServer = null; // internal server; used for updates
var gHttpsServer = null, // provision server; used for install/restore
gHttpServer = null; // update server; used for updates
function restore(req, res, next) {
assert(typeof req.body === 'object');
@@ -44,7 +44,7 @@ function restore(req, res, next) {
installer.restore(req.body, function (error) {
if (error) console.error(error);
stopExternalServer(function () { });
stopProvisionServer(function () { });
});
announce.stop(function () { });
@@ -67,7 +67,7 @@ function provision(req, res, next) {
installer.provision(req.body, function (error) {
if (error) console.error(error);
stopExternalServer(function () { });
stopProvisionServer(function () { });
});
announce.stop(function () { });
@@ -94,10 +94,10 @@ function update(req, res, next) {
next(new HttpSuccess(202, { }));
}
function startInternalServer(callback) {
function startUpdateServer(callback) {
assert(typeof callback === 'function');
debug('Starting internal server');
debug('Starting update server');
var app = express();
@@ -118,10 +118,10 @@ function startInternalServer(callback) {
gHttpServer.listen(2020, '127.0.0.1', callback);
}
function startExternalServer(callback) {
function startProvisionServer(callback) {
assert(typeof callback === 'function');
debug('Starting external server');
debug('Starting provision server');
var app = express();
@@ -148,10 +148,10 @@ function startExternalServer(callback) {
gHttpsServer.listen(process.env.NODE_ENV === 'test' ? 4443 : 443, '0.0.0.0', callback);
}
function stopExternalServer(callback) {
function stopProvisionServer(callback) {
assert(typeof callback === 'function');
debug('Stopping external server');
debug('Stopping provision server');
if (!gHttpsServer) return callback(null);
@@ -159,10 +159,10 @@ function stopExternalServer(callback) {
gHttpsServer = null;
}
function stopInternalServer(callback) {
function stopUpdateServer(callback) {
assert(typeof callback === 'function');
debug('Stopping internal server');
debug('Stopping update server');
if (!gHttpServer) return callback(null);
@@ -171,15 +171,15 @@ function stopInternalServer(callback) {
}
function start(mode, callback) {
assert(mode === 'internal' || mode == 'external', 'invalid mode');
assert(mode === 'update' || mode == 'provision', 'invalid mode');
assert(typeof callback === 'function');
if (mode === 'internal') {
debug('starting in internal mode');
return startInternalServer(callback);
if (mode === 'update') {
debug('starting in update mode');
return startUpdateServer(callback);
}
debug('starting in external mode');
debug('starting in provision mode');
superagent.get('http://169.254.169.254/metadata/v1.json').end(function (error, result) {
if (error || result.statusCode !== 200) {
@@ -192,7 +192,7 @@ function start(mode, callback) {
async.series([
announce.start.bind(null, appServerUrl),
startExternalServer
startProvisionServer
], callback);
});
}
@@ -202,14 +202,14 @@ function stop(callback) {
async.series([
announce.stop,
stopInternalServer,
stopExternalServer
stopUpdateServer,
stopProvisionServer
], callback);
}
if (require.main === module) {
if (process.argv.length !== 3) {
console.log('Usage: node server.js [internal|external]');
console.log('Usage: node server.js [update|provision]');
return;
}
+13 -13
View File
@@ -35,9 +35,9 @@ describe('Server', function () {
done();
});
describe('external - starts and stop', function () {
describe('provision - starts and stop', function () {
it('starts', function (done) {
server.start('external', done);
server.start('provision', done);
});
it('stops', function (done) {
@@ -45,9 +45,9 @@ describe('Server', function () {
});
});
describe('internal - starts and stop', function () {
describe('update - starts and stop', function () {
it('starts', function (done) {
server.start('internal', done);
server.start('update', done);
});
it('stops', function (done) {
@@ -55,9 +55,9 @@ describe('Server', function () {
});
});
describe('internal', function () {
describe('update', function () {
before(function (done) {
server.start('internal', done);
server.start('update', done);
});
after(function (done) {
server.stop(done);
@@ -113,7 +113,7 @@ describe('Server', function () {
});
});
describe('external - announce', function () {
describe('provision - announce', function () {
var failingGet = null;
before(function (done) {
@@ -123,7 +123,7 @@ describe('Server', function () {
failingGet = scope.get('/api/v1/boxes/' + FQDN + '/announce');
failingGet.times(5).reply(502);
server.start('external', done);
server.start('provision', done);
});
after(function (done) {
@@ -134,13 +134,13 @@ describe('Server', function () {
it('sends announce request repeatedly', function (done) {
setTimeout(function () {
expect(failingGet.counter).to.be.below(6); // counter is nock internal
expect(failingGet.counter).to.be.below(6); // counter is nock update
done();
}, 100);
});
});
describe('external - restore', function () {
describe('provision - restore', function () {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var data = {
@@ -157,7 +157,7 @@ describe('Server', function () {
};
before(function (done) {
server.start('external', done);
server.start('provision', done);
});
after(function (done) {
@@ -186,7 +186,7 @@ describe('Server', function () {
});
});
describe('external - provision', function () {
describe('provision - provision', function () {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var data = {
@@ -202,7 +202,7 @@ describe('Server', function () {
};
before(function (done) {
server.start('external', done);
server.start('provision', done);
});
after(function (done) {