installer does not announce anymore

This commit is contained in:
Girish Ramakrishnan
2015-08-25 15:06:39 -07:00
parent af8f4b64c0
commit 3b7ef4615a
3 changed files with 1 additions and 98 deletions
-65
View File
@@ -1,65 +0,0 @@
/* jslint node: true */
'use strict';
var assert = require('assert'),
debug = require('debug')('installer:announce'),
fs = require('fs'),
os = require('os'),
superagent = require('superagent');
exports = module.exports = {
start: start,
stop: stop
};
var gAnnounceTimerId = null;
var ANNOUNCE_INTERVAL = parseInt(process.env.ANNOUNCE_INTERVAL, 10) || 60000; // exported for testing
function start(apiServerOrigin, callback) {
assert.strictEqual(typeof apiServerOrigin, 'string');
assert.strictEqual(typeof callback, 'function');
if (fs.existsSync('/home/yellowtent/box')) {
debug('already provisioned, skipping announce');
return callback(null);
}
debug('started');
gAnnounceTimerId = setInterval(doAnnounce.bind(null, apiServerOrigin), ANNOUNCE_INTERVAL);
doAnnounce(apiServerOrigin);
callback(null);
}
function stop(callback) {
assert.strictEqual(typeof callback, 'function');
debug('Stopping announce');
clearInterval(gAnnounceTimerId);
gAnnounceTimerId = null;
callback(null);
}
function doAnnounce(apiServerOrigin) {
// On Digital Ocean, the only value which we can give a new droplet is the hostname.
// We use that value to identify the droplet by the appstore server when the droplet
// announce itself. This identifier can look different for other box providers.
var hostname = os.hostname();
var url = apiServerOrigin + '/api/v1/boxes/' + hostname + '/announce';
debug('box with %s.', url);
superagent.get(url).timeout(10000).end(function (error, result) {
if (error || result.statusCode !== 200) {
debug('unable to announce to app server, try again.', error);
return;
}
debug('success');
});
}
+1 -6
View File
@@ -4,8 +4,7 @@
'use strict';
var announce = require('./announce.js'),
assert = require('assert'),
var assert = require('assert'),
async = require('async'),
debug = require('debug')('installer:server'),
express = require('express'),
@@ -62,8 +61,6 @@ function provision(req, res, next) {
debug('provision: received from appstore %j', req.body);
announce.stop(function () { });
next(new HttpSuccess(202, { }));
}
@@ -228,7 +225,6 @@ function start(callback) {
debug('Using apiServerOrigin from metadata: %s', apiServerOrigin);
async.series([
announce.start.bind(null, apiServerOrigin),
startUpdateServer,
startProvisionServer,
installer.provision.bind(null, userData)
@@ -240,7 +236,6 @@ function stop(callback) {
assert.strictEqual(typeof callback, 'function');
async.series([
announce.stop,
stopUpdateServer,
stopProvisionServer
], callback);
-27
View File
@@ -108,33 +108,6 @@ describe('Server', function () {
});
});
describe('provision - announce', function () {
var failingGet = null;
before(function (done) {
process.env.ANNOUNCE_INTERVAL = 20;
var scope = nock(APPSERVER_ORIGIN);
failingGet = scope.get('/api/v1/boxes/' + FQDN + '/announce');
failingGet.times(5).reply(502);
server.start(done);
});
after(function (done) {
process.env.ANNOUNCE_INTERVAL = 60000;
// failingGet.removeInterceptor({ hostname: 'appserver' });
server.stop(done);
});
it('sends announce request repeatedly', function (done) {
setTimeout(function () {
expect(failingGet.counter).to.be.below(6); // counter is nock update
done();
}, 100);
});
});
describe('provision - restore', function () {
var data = {
sourceTarballUrl: 'https://sourceTarballUrl',