Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service integration > Nodes Repo Checks page #58

Merged
Merged
38 changes: 20 additions & 18 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ var express = require('express'),

//Routes
index = require('./routes/index'),
steps = require('./routes/api/steps'),
upgrade7Steps = require('./routes/api/upgrade7/steps'),
upgrade7Prechecks = require('./routes/api/upgrade7/prechecks'),
upgrade7Backup = require('./routes/api/upgrade7/backup'),
upgrade7AdminRepoChecks = require('./routes/api/upgrade7/admin-repo-checks'),
upgrade7AdminUpgrade = require('./routes/api/upgrade7/admin-upgrade'),
upgrade7NodesRepoChecks = require('./routes/api/upgrade7/nodes-repo-checks'),
upgrade7StopOpenStackServices = require('./routes/api/upgrade7/stop-openstack-services'),
upgrade7OpenStackServicesBackup = require('./routes/api/upgrade7/openstack-services-backup'),
crowbarEntity = require('./routes/api/crowbar/entity'),
crowbarBackupCreate = require('./routes/api/crowbar/backups/create'),
crowbarBackupDownload = require('./routes/api/crowbar/backups/download'),
crowbarRepocheck = require('./routes/api/crowbar/repocheck'),
crowbarUpgrade = require('./routes/api/crowbar/upgrade'),
upgradeRepocheck = require('./routes/api/upgrade/repocheck'),
upgradePrechecks = require('./routes/api/upgrade/prechecks'),
openstackServices = require('./routes/api/openstack/services'),
openstackBackup = require('./routes/api/openstack/backup'),

app = express();

Expand All @@ -27,15 +27,17 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', index);
app.use('/api/steps', steps);
app.use('/api/upgrade7/steps', upgrade7Steps);
app.use('/api/upgrade7/prechecks', upgrade7Prechecks);
app.use('/api/upgrade7/backup', upgrade7Backup);
app.use('/api/upgrade7/admin-repo-checks', upgrade7AdminRepoChecks);
app.use('/api/upgrade7/admin-upgrade', upgrade7AdminUpgrade);
app.use('/api/upgrade7/nodes-repo-checks', upgrade7NodesRepoChecks);
app.use('/api/upgrade7/openstack-services/stop', upgrade7StopOpenStackServices);
app.use('/api/upgrade7/openstack-services/backup', upgrade7OpenStackServicesBackup);
app.use('/api/crowbar', crowbarEntity);
app.use('/api/crowbar/backups', crowbarBackupCreate);
app.use('/api/crowbar/backups/\*/download', crowbarBackupDownload);
app.use('/api/crowbar/repocheck', crowbarRepocheck);
app.use('/api/crowbar/upgrade', crowbarUpgrade);
app.use('/api/upgrade/prechecks', upgradePrechecks);
app.use('/api/upgrade/repocheck', upgradeRepocheck);
app.use('/api/openstack/services', openstackServices);
app.use('/api/openstack/backup', openstackBackup);



// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
2 changes: 1 addition & 1 deletion assets/app/crowbar-app.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
angular
.module('crowbarApp', [
'crowbarCore',
'crowbarData',
'suseData',
'crowbarWidgets',

/*
Expand Down
5 changes: 0 additions & 5 deletions assets/app/data/crowbar-data.module.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {

angular
.module('crowbarData.upgrade')
.module('suseData.crowbar')
.constant('COMMON_API_V2_HEADERS', {
'Accept': 'application/vnd.crowbar.v2.0+json'
});
Expand Down
5 changes: 5 additions & 0 deletions assets/app/data/crowbar/crowbar.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(function () {
'use strict';

angular.module('suseData.crowbar', []);
})();
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
(function() {

angular
.module('crowbarData.upgrade')
.factory('upgradeBackupFactory', upgradeBackupFactory);
.module('suseData.crowbar')
.factory('crowbarBackupFactory', crowbarBackupFactory);

upgradeBackupFactory.$inject = ['$q', '$http', '$filter', 'COMMON_API_V2_HEADERS'];
crowbarBackupFactory.$inject = ['$q', '$http', '$filter', 'COMMON_API_V2_HEADERS'];
/* @ngInject */
function upgradeBackupFactory($q, $http, $filter, COMMON_API_V2_HEADERS) {
function crowbarBackupFactory($q, $http, $filter, COMMON_API_V2_HEADERS) {
var factory = {
create: createBackup,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create -> createBackup for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end it would be used like: crowbarBackupFactory().createBackup(). Don't you think it's redundant, considering we're already operating over a backup factory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a bit redundant but as the var+function below changed their names to include backup, I was thinking more about consistency between both methods crowbarBackupFactory().createBackup() and crowbarBackupFactory().getBackup()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Itxaka here. It should be either create & download or createBackup & getBackup or downloadBackup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be updated

download: downloadBackup
get: getBackup
};

return factory;

/**
* Create a new backup of the Administration Node
*
* @return {Promise}
*/
function createBackup() {

var requestOptions = {
Expand All @@ -26,10 +31,16 @@
return $http(requestOptions);
}

function downloadBackup(id) {
/**
* Download a specific backup based on its Id
*
* @param {Number} Backup Id to be downloaded
* @return {Promise}
*/
function getBackup(id) {
// this should never happen, caller should make sure 'id' is set
if (angular.isUndefined(id)) {
throw Error('downloadBackup() called without id.');
throw Error('getBackup() called without id.');
}

var requestOptions = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*global bard $httpBackend should expect upgradeBackupFactory assert */
describe('Upgrade Backup Factory', function () {
/*global bard $httpBackend should expect crowbarBackupFactory assert */
describe('Crowbar Backup Factory', function () {

var mockedBackupFile = '--mockedBackupFile--',
mockedCreateResponse = {
Expand All @@ -9,8 +9,8 @@ describe('Upgrade Backup Factory', function () {

beforeEach(function () {
//Setup the module and dependencies to be used.
bard.appModule('crowbarData.upgrade');
bard.inject('upgradeBackupFactory', '$q', '$httpBackend');
bard.appModule('suseData.crowbar');
bard.inject('crowbarBackupFactory', '$q', '$httpBackend', 'COMMON_API_V2_HEADERS');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to inject COMMON_API_V2_HEADERS here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the API documentation, we do

});

afterEach(function() {
Expand All @@ -22,23 +22,23 @@ describe('Upgrade Backup Factory', function () {
describe('when executed', function () {

it('returns an object', function () {
should.exist(upgradeBackupFactory);
should.exist(crowbarBackupFactory);
});

it('returns an object with create function defined', function () {
expect(upgradeBackupFactory.create).toEqual(jasmine.any(Function));
expect(crowbarBackupFactory.create).toEqual(jasmine.any(Function));
});

it('returns an object with download function defined', function () {
expect(upgradeBackupFactory.download).toEqual(jasmine.any(Function));
it('returns an object with get function defined', function () {
expect(crowbarBackupFactory.get).toEqual(jasmine.any(Function));
});

describe('when create method is executed', function () {

beforeEach(function () {
$httpBackend.expect('POST', '/api/crowbar/backups')
$httpBackend.expect('POST', '/api/crowbar/backups', undefined)
.respond(200, mockedCreateResponse);
backupPromise = upgradeBackupFactory.create();
backupPromise = crowbarBackupFactory.create();
$httpBackend.flush();
});

Expand All @@ -65,7 +65,7 @@ describe('Upgrade Backup Factory', function () {
beforeEach(function () {
$httpBackend.expect('GET', '/api/crowbar/backups/42/download')
.respond(200, mockedBackupFile);
backupPromise = upgradeBackupFactory.download(42);
backupPromise = crowbarBackupFactory.get(42);
$httpBackend.flush();
});

Expand All @@ -92,7 +92,7 @@ describe('Upgrade Backup Factory', function () {
describe('when download method is executed without parameter', function () {

it('throws an exception', function () {
expect(upgradeBackupFactory.download).toThrow();
expect(crowbarBackupFactory.get).toThrow();
});
});
});
Expand Down
84 changes: 84 additions & 0 deletions assets/app/data/crowbar/services/crowbar.factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
(function() {

angular
.module('suseData.crowbar')
.factory('crowbarFactory', crowbarFactory);

crowbarFactory.$inject = ['$q', '$http', 'COMMON_API_V2_HEADERS'];
/* @ngInject */
function crowbarFactory($q, $http, COMMON_API_V2_HEADERS) {
var factory = {
getEntity: getEntity,
getRepositoriesChecks: getRepositoriesChecks,
upgrade: upgrade,
getUpgradeStatus: getUpgradeStatus
};

return factory;

/**
* Get Crowbar Entity
*
* @return {Promise}
*/
function getEntity() {

var requestOptions = {
method: 'GET',
url: '/api/crowbar',
headers: COMMON_API_V2_HEADERS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant we set $http.defaults.headers to avoid adding the headers on each function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be isolated to crowbar endpoints only, so we allow different headers for different endpoints in the future (OpenStack, for instance)
Maybe as part of suseData.crowbar specific configuration... What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, anything to avoid repetition 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skazi0 Would Restangular help us here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would simplify things a bit. We could use "decoupled service" (https://github.com/mgonto/restangular#decoupled-restangular-service) for the /api/ prefix and pre-configure it with required headers and other options if needed like I did here: https://github.com/skazi0/yaia/blob/master/app/static/js/invoices.js#L22-L27

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do it, but current implementation works fine so I'd leave migration to Restangular for the future or when we're blocked by some problem with direct $http usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #61 to track it in the future
Thanks for the input

};

return $http(requestOptions);
}

/**
* Get Administration repositories checks (Operative System and Open Stack)
*
* @return {Promise}
*/
function getRepositoriesChecks() {

var requestOptions = {
method: 'GET',
url: '/api/crowbar/repocheck',
headers: COMMON_API_V2_HEADERS
};

return $http(requestOptions);

}

/**
* Trigger the Upgrade process on the Adinistration Node (Crowbar) from Cloud6 to Cloud7
*
* @return {Promise}
*/
function upgrade() {

var requestOptions = {
method: 'POST',
url: '/api/crowbar/upgrade',
headers: COMMON_API_V2_HEADERS
};

return $http(requestOptions);
}

/**
* Get the upgrade status of the Administration Node (Crowbar)
*
* @return {Promise}
*/
function getUpgradeStatus() {

var requestOptions = {
method: 'GET',
url: '/api/crowbar/upgrade',
headers: COMMON_API_V2_HEADERS
};

return $http(requestOptions);
}
}
})();
Loading