Add general load balancer service

This adds the load balancer service and moves the status mappings
into the service. The horizon decode filter is then used instead of
the custom filters. This service also includes the isActive method
for checking if a given load balancer is active.

Partially-Implements: blueprint horizon-lbaas-v2-ui
Change-Id: I2cb817c15d838715ce2d99a8f2df6a7d716d6395
This commit is contained in:
Justin Pomeroy 2016-02-03 10:43:15 -06:00
parent 904b3ff5eb
commit 3d733f2605
9 changed files with 169 additions and 140 deletions

View File

@ -23,6 +23,7 @@
LoadBalancerDetailController.$inject = [
'horizon.app.core.openstack-service-api.lbaasv2',
'horizon.dashboard.project.lbaasv2.loadbalancers.actions.rowActions',
'horizon.dashboard.project.lbaasv2.loadbalancers.service',
'$routeParams'
];
@ -35,14 +36,17 @@
*
* @param api The LBaaS v2 API service.
* @param rowActions The load balancer row actions service.
* @param loadBalancersService The LBaaS v2 load balancers service.
* @param $routeParams The angular $routeParams service.
* @returns undefined
*/
function LoadBalancerDetailController(api, rowActions, $routeParams) {
function LoadBalancerDetailController(api, rowActions, loadBalancersService, $routeParams) {
var ctrl = this;
ctrl.actions = rowActions.actions;
ctrl.operatingStatus = loadBalancersService.operatingStatus;
ctrl.provisioningStatus = loadBalancersService.provisioningStatus;
init();

View File

@ -16,11 +16,11 @@
</div>
<div>
<strong translate>Operating Status</strong>
{$ ::ctrl.loadbalancer.operating_status | operatingStatus $}
{$ ::ctrl.loadbalancer.operating_status | decode:ctrl.operatingStatus $}
</div>
<div>
<strong translate>Provisioning Status</strong>
{$ ::ctrl.loadbalancer.provisioning_status | provisioningStatus $}
{$ ::ctrl.loadbalancer.provisioning_status | decode:ctrl.provisioningStatus $}
</div>
</div>
<tabset>

View File

@ -1,79 +0,0 @@
/*
* Copyright 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function () {
'use strict';
angular
.module('horizon.dashboard.project.lbaasv2.loadbalancers')
.filter('operatingStatus', operatingStatusFilter)
.filter('provisioningStatus', provisioningStatusFilter);
operatingStatusFilter.$inject = [
'horizon.framework.util.i18n.gettext'
];
provisioningStatusFilter.$inject = [
'horizon.framework.util.i18n.gettext'
];
/**
* @ngdoc filter
* @name operatingStatusFilter
* @description
* Takes raw load balancer operating status from the API and returns the user friendly status.
* @param gettext The horizon gettext function for translation.
* @returns The function for filtering the load balancer operating status.
*/
function operatingStatusFilter(gettext) {
var statuses = {
'ONLINE': gettext('Online'),
'OFFLINE': gettext('Offline'),
'DEGRADED': gettext('Degraded'),
'ERROR': gettext('Error')
};
return function (input) {
var result = statuses[input];
return angular.isDefined(result) ? result : input;
};
}
/**
* @ngdoc filter
* @name provisioningStatusFilter
* @description
* Takes raw load balancer provisioning status from the API and returns the user friendly status.
* @param gettext The horizon gettext function for translation.
* @returns The function for filtering the load balancer provisioning status.
*/
function provisioningStatusFilter(gettext) {
var statuses = {
'ACTIVE': gettext('Active'),
'PENDING_CREATE': gettext('Pending Create'),
'PENDING_UPDATE': gettext('Pending Update'),
'PENDING_DELETE': gettext('Pending Delete'),
'ERROR': gettext('Error')
};
return function (input) {
var result = statuses[input];
return angular.isDefined(result) ? result : input;
};
}
}());

View File

@ -1,54 +0,0 @@
/*
* Copyright 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() {
'use strict';
describe('LBaaS v2 Load Balancers Filters', function () {
beforeEach(module('horizon.framework.util.i18n'));
beforeEach(module('horizon.dashboard.project.lbaasv2.loadbalancers'));
describe('operatingStatus', function () {
var operatingStatusFilter;
beforeEach(inject(function (_operatingStatusFilter_) {
operatingStatusFilter = _operatingStatusFilter_;
}));
it('Returns value when key is present', function () {
expect(operatingStatusFilter('ONLINE')).toBe('Online');
});
it('Returns input when key is not present', function () {
expect(operatingStatusFilter('unknown')).toBe('unknown');
});
});
describe('provisioningStatus', function () {
var provisioningStatusFilter;
beforeEach(inject(function (_provisioningStatusFilter_) {
provisioningStatusFilter = _provisioningStatusFilter_;
}));
it('Returns value when key is present', function () {
expect(provisioningStatusFilter('ACTIVE')).toBe('Active');
});
it('Returns input when key is not present', function () {
expect(provisioningStatusFilter('unknown')).toBe('unknown');
});
});
});
})();

View File

@ -0,0 +1,82 @@
/*
* Copyright 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function () {
'use strict';
angular
.module('horizon.dashboard.project.lbaasv2.loadbalancers')
.factory('horizon.dashboard.project.lbaasv2.loadbalancers.service', loadBalancersService);
loadBalancersService.$inject = [
'$q',
'horizon.app.core.openstack-service-api.lbaasv2',
'horizon.framework.util.i18n.gettext'
];
/**
* @ngdoc service
* @name horizon.dashboard.project.lbaasv2.loadbalancers.service
* @description General service for LBaaS v2 load balancers.
* @param $q The angular service for promises.
* @param api The LBaaS V2 service API.
* @param gettext The horizon gettext function for translation.
* @returns The load balancers service.
*/
function loadBalancersService($q, api, gettext) {
var operatingStatus = {
'ONLINE': gettext('Online'),
'OFFLINE': gettext('Offline'),
'DEGRADED': gettext('Degraded'),
'ERROR': gettext('Error')
};
var provisioningStatus = {
'ACTIVE': gettext('Active'),
'PENDING_CREATE': gettext('Pending Create'),
'PENDING_UPDATE': gettext('Pending Update'),
'PENDING_DELETE': gettext('Pending Delete'),
'ERROR': gettext('Error')
};
var service = {
operatingStatus: operatingStatus,
provisioningStatus: provisioningStatus,
isActive: isActive
};
return service;
////////////
/**
* @ngdoc method
* @name horizon.dashboard.project.lbaasv2.loadbalancers.service.isActive
* @description Returns a promise that is resolved if the load balancer is active and
* rejected if not.
* @param id The load balancer id.
* @returns {Promise}
*/
function isActive(id) {
return api.getLoadBalancer(id).then(function onLoad(response) {
if (response.data.provisioning_status !== 'ACTIVE') {
return $q.reject();
}
});
}
}
}());

View File

@ -0,0 +1,70 @@
/*
* Copyright 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() {
'use strict';
describe('LBaaS v2 Load Balancers Service', function() {
var service, $q, $scope;
beforeEach(module('horizon.framework.widgets.toast'));
beforeEach(module('horizon.framework.conf'));
beforeEach(module('horizon.framework.util'));
beforeEach(module('horizon.app.core.openstack-service-api'));
beforeEach(module('horizon.dashboard.project.lbaasv2'));
beforeEach(module(function($provide) {
$provide.value('horizon.app.core.openstack-service-api.lbaasv2', {
getLoadBalancer: function(index) {
var loadbalancers = [{ provisioning_status: 'ACTIVE' },
{ provisioning_status: 'PENDING_UPDATE' }];
var deferred = $q.defer();
deferred.resolve({ data: loadbalancers[index] });
return deferred.promise;
}
});
}));
beforeEach(inject(function ($injector) {
$q = $injector.get('$q');
$scope = $injector.get('$rootScope').$new();
service = $injector.get('horizon.dashboard.project.lbaasv2.loadbalancers.service');
}));
it('should define value mappings', function() {
expect(service.operatingStatus).toBeDefined();
expect(service.provisioningStatus).toBeDefined();
});
it('should allow checking status of load balancer', function() {
var active = null;
service.isActive(0).then(function() {
active = true;
});
$scope.$apply();
expect(active).toBe(true);
active = null;
service.isActive(1).then(angular.noop, function() {
active = false;
});
$scope.$apply();
expect(active).toBe(false);
});
});
})();

View File

@ -23,7 +23,8 @@
LoadBalancersTableController.$inject = [
'horizon.app.core.openstack-service-api.lbaasv2',
'horizon.dashboard.project.lbaasv2.loadbalancers.actions.batchActions',
'horizon.dashboard.project.lbaasv2.loadbalancers.actions.rowActions'
'horizon.dashboard.project.lbaasv2.loadbalancers.actions.rowActions',
'horizon.dashboard.project.lbaasv2.loadbalancers.service'
];
/**
@ -36,10 +37,11 @@
* @param api The LBaaS V2 service API.
* @param batchActions The load balancer batch actions service.
* @param rowActions The load balancer row actions service.
* @param loadBalancersService The LBaaS v2 load balancers service.
* @returns undefined
*/
function LoadBalancersTableController(api, batchActions, rowActions) {
function LoadBalancersTableController(api, batchActions, rowActions, loadBalancersService) {
var ctrl = this;
ctrl.items = [];
@ -47,6 +49,8 @@
ctrl.checked = {};
ctrl.batchActions = batchActions;
ctrl.rowActions = rowActions;
ctrl.operatingStatus = loadBalancersService.operatingStatus;
ctrl.provisioningStatus = loadBalancersService.provisioningStatus;
init();

View File

@ -58,6 +58,8 @@
expect(ctrl.checked).toEqual({});
expect(ctrl.batchActions).toBeDefined();
expect(ctrl.rowActions).toBeDefined();
expect(ctrl.operatingStatus).toBeDefined();
expect(ctrl.provisioningStatus).toBeDefined();
});
it('should invoke lbaasv2 apis', function() {

View File

@ -73,8 +73,8 @@
</td>
<td class="rsp-p1"><a ng-href="project/ngloadbalancersv2/{$ ::item.id $}">{$ ::(item.name || item.id) $}</a></td>
<td class="rsp-p1">{$ ::item.description | noValue $}</td>
<td class="rsp-p1">{$ ::item.operating_status | operatingStatus $}</td>
<td class="rsp-p1">{$ ::item.provisioning_status | provisioningStatus $}</td>
<td class="rsp-p1">{$ ::item.operating_status | decode:table.operatingStatus $}</td>
<td class="rsp-p1">{$ ::item.provisioning_status | decode:table.provisioningStatus $}</td>
<td class="rsp-p2">{$ ::item.vip_address $}</td>
<td class="rsp-p2">{$ item.listeners.length $}</td>
<td class="action-col">