From b5625534efdeb6752f8556065de1641d8f207c4c Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Sat, 28 Jun 2014 01:06:22 -0700 Subject: [PATCH] Rename statusCode to installationState --- src/appdb.js | 8 +++--- src/apphealthtask.js | 10 +++---- src/apps.js | 6 ++-- src/apptask.js | 56 +++++++++++++++++++------------------- src/schema.sql | 2 +- src/test/database-test.js | 26 +++++++++--------- webadmin/views/myapps.html | 3 +- 7 files changed, 55 insertions(+), 56 deletions(-) diff --git a/src/appdb.js b/src/appdb.js index 13c464a0e..4d52d61de 100644 --- a/src/appdb.js +++ b/src/appdb.js @@ -107,10 +107,10 @@ function getAll(callback) { }); } -function add(id, statusCode, location, portBindings, callback) { +function add(id, installationState, location, portBindings, callback) { assert(db !== null); assert(typeof id === 'string'); - assert(typeof statusCode === 'string'); + assert(typeof installationState === 'string'); assert(typeof location === 'string'); assert(util.isArray(portBindings)); assert(typeof callback === 'function'); @@ -119,13 +119,13 @@ function add(id, statusCode, location, portBindings, callback) { var appData = { $id: id, - $statusCode: statusCode, + $installationState: installationState, $location: location }; var conn = database.newTransaction(); - conn.run('INSERT INTO apps (id, statusCode, location) VALUES ($id, $statusCode, $location)', + conn.run('INSERT INTO apps (id, installationState, location) VALUES ($id, $installationState, $location)', appData, function (error) { if (error) database.rollback(conn); diff --git a/src/apphealthtask.js b/src/apphealthtask.js index 1d451d9c7..1298bfd7f 100644 --- a/src/apphealthtask.js +++ b/src/apphealthtask.js @@ -53,13 +53,13 @@ function checkAppHealth(app, callback) { container.inspect(function (err, data) { if (err || !data || !data.State) { debug('Error inspecting container'); - updateApp(app, { statusCode: appdb.STATUS_IMAGE_ERROR }, FATAL_CALLBACK); + updateApp(app, { installationState: appdb.STATUS_IMAGE_ERROR }, FATAL_CALLBACK); return callback(err); } if (data.State.Running !== true) { debug(app.id + ' has exited'); - updateApp(app, { statusCode: appdb.STATUS_EXITED }, FATAL_CALLBACK); + updateApp(app, { installationState: appdb.STATUS_EXITED }, FATAL_CALLBACK); return callback(null); } @@ -71,11 +71,11 @@ function checkAppHealth(app, callback) { if (error || res.status !== 200) { debug('Marking application as dead: ' + app.id); - updateApp(app, { statusCode: appdb.STATUS_NOT_RESPONDING }, FATAL_CALLBACK); + updateApp(app, { installationState: appdb.STATUS_NOT_RESPONDING }, FATAL_CALLBACK); callback(null); } else { debug('healthy app:' + app.id); - updateApp(app, { statusCode: appdb.STATUS_RUNNING }, FATAL_CALLBACK); + updateApp(app, { installationState: appdb.STATUS_RUNNING }, FATAL_CALLBACK); callback(null); } }); @@ -87,7 +87,7 @@ function processApps(callback) { if (error) return callback(error); async.each(apps, function (app, done) { - switch (app.statusCode) { + switch (app.installationState) { case appdb.STATUS_RUNNING: case appdb.STATUS_NOT_RESPONDING: case appdb.STATUS_EXITED: diff --git a/src/apps.js b/src/apps.js index 28948de0b..9aeffea5b 100644 --- a/src/apps.js +++ b/src/apps.js @@ -35,8 +35,8 @@ function resume() { appdb.getAll(function (error, apps) { if (error) throw error; apps.forEach(function (app) { - if (app.statusCode === appdb.STATUS_RUNNING || app.statusCode === appdb.STATUS_DEAD || app.statusCode === appdb.STATUS_NOT_RESPONDING) return; - debug('Creating process for ' + app.id + ' with state ' + app.statusCode); + if (app.installationState === appdb.STATUS_RUNNING || app.installationState === appdb.STATUS_DEAD || app.installationState === appdb.STATUS_NOT_RESPONDING) return; + debug('Creating process for ' + app.id + ' with state ' + app.installationState); tasks[app.id] = child_process.fork(__dirname + '/apptask.js', [ app.id ]); }); }); @@ -135,7 +135,7 @@ function uninstall(appId, callback) { stopTask(appId); - appdb.update(appId, { statusCode: appdb.STATUS_PENDING_UNINSTALL }, function (error) { + appdb.update(appId, { installationState: appdb.STATUS_PENDING_UNINSTALL }, function (error) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError('No such app', AppsError.NOT_FOUND)); if (error) return callback(new AppsError('Internal error:' + error.message, AppsError.INTERNAL_ERROR)); diff --git a/src/apptask.js b/src/apptask.js index 992415a12..ada3e7524 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -323,12 +323,12 @@ function processAppState(app, callback) { app[value] = values[value]; } - debug(app.id + ' code:' + app.statusCode); + debug(app.id + ' code:' + app.installationState); appdb.update(app.id, values, callback); } - switch (app.statusCode) { + switch (app.installationState) { case appdb.STATUS_PENDING_INSTALL: case appdb.STATUS_NGINX_ERROR: getFreePort(function (error, freePort) { @@ -336,10 +336,10 @@ function processAppState(app, callback) { configureNginx(app, freePort, function (error) { if (error) { debug('Error configuring nginx: ' + error); - return updateApp(app, { statusCode: appdb.STATUS_NGINX_ERROR }, callback); + return updateApp(app, { installationState: appdb.STATUS_NGINX_ERROR }, callback); } - updateApp(app, { statusCode: appdb.STATUS_NGINX_CONFIGURED, httpPort: freePort }, callback); + updateApp(app, { installationState: appdb.STATUS_NGINX_CONFIGURED, httpPort: freePort }, callback); }); }); break; @@ -347,16 +347,16 @@ function processAppState(app, callback) { case appdb.STATUS_NGINX_CONFIGURED: case appdb.STATUS_REGISTERING_SUBDOMAIN: case appdb.STATUS_SUBDOMAIN_ERROR: - updateApp(app, { statusCode: appdb.STATUS_REGISTERING_SUBDOMAIN }, function (error) { + updateApp(app, { installationState: appdb.STATUS_REGISTERING_SUBDOMAIN }, function (error) { if (error) return callback(error); registerSubdomain(app, function (error) { if (error) { debug('Error registering subdomain: ' + error); - return updateApp(app, { statusCode: appdb.STATUS_SUBDOMAIN_ERROR }, callback); + return updateApp(app, { installationState: appdb.STATUS_SUBDOMAIN_ERROR }, callback); } - updateApp(app, { statusCode: appdb.STATUS_REGISTERED_SUBDOMAIN }, callback); + updateApp(app, { installationState: appdb.STATUS_REGISTERED_SUBDOMAIN }, callback); }); }); break; @@ -366,32 +366,32 @@ function processAppState(app, callback) { case appdb.STATUS_IMAGE_ERROR: case appdb.STATUS_DOWNLOAD_ERROR: case appdb.STATUS_DOWNLOADING_MANIFEST: - updateApp(app, { statusCode: appdb.STATUS_DOWNLOADING_MANIFEST }, function (error) { + updateApp(app, { installationState: appdb.STATUS_DOWNLOADING_MANIFEST }, function (error) { if (error) return callback(error); downloadManifest(app, function (error, manifestJson) { if (error) { debug('Error downloading manifest:' + error); - return updateApp(app, { statusCode: appdb.STATUS_MANIFEST_ERROR }, callback); + return updateApp(app, { installationState: appdb.STATUS_MANIFEST_ERROR }, callback); } - updateApp(app, { statusCode: appdb.STATUS_DOWNLOADED_MANIFEST, manifestJson: manifestJson }, callback); + updateApp(app, { installationState: appdb.STATUS_DOWNLOADED_MANIFEST, manifestJson: manifestJson }, callback); }); }); break; case appdb.STATUS_DOWNLOADING_IMAGE: case appdb.STATUS_DOWNLOADED_MANIFEST: - updateApp(app, { statusCode: appdb.STATUS_DOWNLOADING_IMAGE }, function (error) { + updateApp(app, { installationState: appdb.STATUS_DOWNLOADING_IMAGE }, function (error) { if (error) return callback(error); downloadImage(app, function (error) { if (error) { debug('Error downloading image:' + error); - return updateApp(app, { statusCode: appdb.STATUS_MANIFEST_ERROR}, callback); + return updateApp(app, { installationState: appdb.STATUS_MANIFEST_ERROR}, callback); } - updateApp(app, { statusCode: appdb.STATUS_DOWNLOADED_IMAGE }, callback); + updateApp(app, { installationState: appdb.STATUS_DOWNLOADED_IMAGE }, callback); }); }); break; @@ -401,16 +401,16 @@ function processAppState(app, callback) { appdb.getPortBindings(app.id, function (error, portBindings) { if (error) return callback(error); - updateApp(app, { statusCode: appdb.STATUS_CREATING_CONTAINER }, function (error) { + updateApp(app, { installationState: appdb.STATUS_CREATING_CONTAINER }, function (error) { if (error) return callback(error); createContainer(app, portBindings, function (error, containerId) { if (error) { debug('Error creating container:' + error); - return updateApp(app, { statusCode: appdb.STATUS_CONTAINER_ERROR }, callback); + return updateApp(app, { installationState: appdb.STATUS_CONTAINER_ERROR }, callback); } - updateApp(app, { containerId: containerId, statusCode: appdb.STATUS_CREATED_CONTAINER }, callback); + updateApp(app, { containerId: containerId, installationState: appdb.STATUS_CREATED_CONTAINER }, callback); }); }); }); @@ -419,16 +419,16 @@ function processAppState(app, callback) { case appdb.STATUS_CREATED_CONTAINER: case appdb.STATUS_CREATING_VOLUME: case appdb.STATUS_VOLUME_ERROR: - updateApp(app, { statusCode: appdb.STATUS_CREATING_VOLUME }, function (error) { + updateApp(app, { installationState: appdb.STATUS_CREATING_VOLUME }, function (error) { if (error) return callback(error); createVolume(app, function (error) { if (error) { debug('Error creating volume: ' + error); - return updateApp(app, { statusCode: appdb.STATUS_VOLUME_ERROR }, callback); + return updateApp(app, { installationState: appdb.STATUS_VOLUME_ERROR }, callback); } - updateApp(app, { statusCode: appdb.STATUS_CREATED_VOLUME }, callback); + updateApp(app, { installationState: appdb.STATUS_CREATED_VOLUME }, callback); }); }); break; @@ -440,30 +440,30 @@ function processAppState(app, callback) { appdb.getPortBindings(app.id, function (error, portBindings) { if (error) return callback(error); - updateApp(app, { statusCode: appdb.STATUS_STARTING_CONTAINER }, function (error) { + updateApp(app, { installationState: appdb.STATUS_STARTING_CONTAINER }, function (error) { if (error) return callback(error); startContainer(app, portBindings, function (error) { if (error) { debug('Error creating container:' + error); - return updateApp(app, { statusCode: appdb.STATUS_CONTAINER_ERROR }, callback); + return updateApp(app, { installationState: appdb.STATUS_CONTAINER_ERROR }, callback); } - updateApp(app, { statusCode: appdb.STATUS_STARTED_CONTAINER }, callback); + updateApp(app, { installationState: appdb.STATUS_STARTED_CONTAINER }, callback); }); }); }); break; case appdb.STATUS_STARTED_CONTAINER: - updateApp(app, { statusCode: appdb.STATUS_RUNNING }, callback); + updateApp(app, { installationState: appdb.STATUS_RUNNING }, callback); break; case appdb.STATUS_PENDING_UNINSTALL: uninstall(app, function (error) { if (error) return callback(error); - app.statusCode = appdb.STATUS_UNINSTALLED; + app.installationState = appdb.STATUS_UNINSTALLED; callback(null); }); break; @@ -471,7 +471,7 @@ function processAppState(app, callback) { case appdb.STATUS_RUNNING: case appdb.STATUS_NOT_RESPONDING: case appdb.STATUS_EXITED: - assert(true, 'Should not reach this state: ' + app.statusCode); + assert(true, 'Should not reach this state: ' + app.installationState); break; } } @@ -481,18 +481,18 @@ function processApp(app, callback) { processAppState(app, function (error) { if (error) return callback(error); // fatal error (not install error) - if (app.statusCode === appdb.STATUS_UNINSTALLED) { + if (app.installationState === appdb.STATUS_UNINSTALLED) { debug('app uninstalled, stopping'); return callback(null); } - if (app.statusCode.indexOf('_error', app.statusCode.length - 6) !== -1) { + if (app.installationState.indexOf('_error', app.installationState.length - 6) !== -1) { debug('app is in error state, stopping'); return callback(null); } // move on - if (app.statusCode === appdb.STATUS_RUNNING || app.statusCode === appdb.STATUS_NOT_RESPONDING || app.statusCode === appdb.STATUS_EXITED) { + if (app.installationState === appdb.STATUS_RUNNING || app.installationState === appdb.STATUS_NOT_RESPONDING || app.installationState === appdb.STATUS_EXITED) { debug('app installed, stopping'); return callback(null); } diff --git a/src/schema.sql b/src/schema.sql index 019df6ecf..db88e7770 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -28,7 +28,7 @@ CREATE TABLE IF NOT EXISTS clients( CREATE TABLE IF NOT EXISTS apps( id VARCHAR(512) NOT NULL UNIQUE, - statusCode VARCHAR(512) NOT NULL, + installationState VARCHAR(512) NOT NULL, containerId VARCHAR(128), manifestJson VARCHAR, httpPort INTEGER, diff --git a/src/test/database-test.js b/src/test/database-test.js index 7940766ce..40abfeb36 100644 --- a/src/test/database-test.js +++ b/src/test/database-test.js @@ -235,7 +235,7 @@ describe('database', function () { describe('app', function () { var APP_0 = { id: 'appid-0', - statusCode: 'some-status-0', + installationState: 'some-status-0', location: 'some-location-0', manifestJson: null, httpPort: null, @@ -243,7 +243,7 @@ describe('database', function () { }; var APP_1 = { id: 'appid-1', - statusCode: 'some-status-1', + installationState: 'some-status-1', location: 'some-location-1', manifestJson: null, httpPort: null, @@ -251,21 +251,21 @@ describe('database', function () { }; it('add fails due to missing arguments', function () { - expect(function () { appdb.add(APP_0.id, APP_0.statusCode, function () {}); }).to.throwError(); + expect(function () { appdb.add(APP_0.id, APP_0.installationState, function () {}); }).to.throwError(); expect(function () { appdb.add(APP_0.id, function () {}); }).to.throwError(); }); // This needs to be tested in the api layer? xit('add fails due to bad arguments', function () { - expect(function () { appdb.add(APP_0.id, APP_0.statusCode, 'loc', { "5555": "10" }, function () {}); }).to.throwError(); - expect(function () { appdb.add(APP_0.id, APP_0.statusCode, 'loc', { 5555: 10 }, function () {}); }).to.throwError(); - expect(function () { appdb.add(APP_0.id, APP_0.statusCode, 'loc', { "mango": 4000 }, function () {}); }).to.throwError(); - expect(function () { appdb.add(APP_0.id, APP_0.statusCode, 'loc', { "1000": "grape" }, function () {}); }).to.throwError(); + expect(function () { appdb.add(APP_0.id, APP_0.installationState, 'loc', { "5555": "10" }, function () {}); }).to.throwError(); + expect(function () { appdb.add(APP_0.id, APP_0.installationState, 'loc', { 5555: 10 }, function () {}); }).to.throwError(); + expect(function () { appdb.add(APP_0.id, APP_0.installationState, 'loc', { "mango": 4000 }, function () {}); }).to.throwError(); + expect(function () { appdb.add(APP_0.id, APP_0.installationState, 'loc', { "1000": "grape" }, function () {}); }).to.throwError(); }); it('add succeeds', function (done) { - appdb.add(APP_0.id, APP_0.statusCode, APP_0.location, [ { containerPort: 1234, hostPort: 5678 } ], function (error) { + appdb.add(APP_0.id, APP_0.installationState, APP_0.location, [ { containerPort: 1234, hostPort: 5678 } ], function (error) { expect(error).to.be(null); done(); }); @@ -281,7 +281,7 @@ describe('database', function () { }); it('add of same app fails', function (done) { - appdb.add(APP_0.id, APP_0.statusCode, APP_0.location, [ ], function (error) { + appdb.add(APP_0.id, APP_0.installationState, APP_0.location, [ ], function (error) { expect(error).to.be.a(DatabaseError); expect(error.reason).to.be(DatabaseError.ALREADY_EXISTS); done(); @@ -307,10 +307,10 @@ describe('database', function () { }); it('update succeeds', function (done) { - APP_0.statusCode = 'some-other-status'; + APP_0.installationState = 'some-other-status'; APP_0.location = 'some-other-location'; - appdb.update(APP_0.id, { statusCode: APP_0.statusCode, location: APP_0.location }, function (error) { + appdb.update(APP_0.id, { installationState: APP_0.installationState, location: APP_0.location }, function (error) { expect(error).to.be(null); appdb.get(APP_0.id, function (error, result) { @@ -323,7 +323,7 @@ describe('database', function () { }); it('update of nonexisting app fails', function (done) { - appdb.update(APP_1.id, { statusCode: APP_1.statusCode, location: APP_1.location }, function (error) { + appdb.update(APP_1.id, { installationState: APP_1.installationState, location: APP_1.location }, function (error) { expect(error).to.be.a(DatabaseError); expect(error.reason).to.be(DatabaseError.NOT_FOUND); done(); @@ -331,7 +331,7 @@ describe('database', function () { }); it('add second app succeeds', function (done) { - appdb.add(APP_1.id, APP_1.statusCode, APP_1.location, [ ], function (error) { + appdb.add(APP_1.id, APP_1.installationState, APP_1.location, [ ], function (error) { expect(error).to.be(null); done(); }); diff --git a/webadmin/views/myapps.html b/webadmin/views/myapps.html index 173fa9710..e259cf642 100644 --- a/webadmin/views/myapps.html +++ b/webadmin/views/myapps.html @@ -15,8 +15,7 @@
{{ app.id }}
-
{{ app.statusCode }}
-
{{ app.statusMessage }}
+
{{ app.installationState }}