Skip to content

Commit

Permalink
Adopt service catalog API changes
Browse files Browse the repository at this point in the history
Bumps origin-web-common 0.0.63 -> 0.0.64
Bumps origin-web-catalog 0.0.52 -> 0.0.53
  • Loading branch information
spadgett committed Oct 9, 2017
1 parent 436cb11 commit a04fb60
Show file tree
Hide file tree
Showing 22 changed files with 1,006 additions and 886 deletions.
94 changes: 63 additions & 31 deletions app/scripts/controllers/overview.js
Expand Up @@ -7,6 +7,7 @@ angular.module('openshiftConsole').controller('OverviewController', [
'AlertMessageService',
'APIService',
'AppsService',
'BindingService',
'BuildsService',
'CatalogService',
'Constants',
Expand All @@ -23,9 +24,9 @@ angular.module('openshiftConsole').controller('OverviewController', [
'OwnerReferencesService',
'PodsService',
'ProjectsService',
'BindingService',
'ResourceAlertsService',
'RoutesService',
'ServiceInstancesService',
OverviewController
]);

Expand All @@ -35,6 +36,7 @@ function OverviewController($scope,
AlertMessageService,
APIService,
AppsService,
BindingService,
BuildsService,
CatalogService,
Constants,
Expand All @@ -51,9 +53,9 @@ function OverviewController($scope,
OwnerReferencesService,
PodsService,
ProjectsService,
BindingService,
ResourceAlertsService,
RoutesService) {
RoutesService,
ServiceInstancesService) {
var overview = this;
var limitWatches = $filter('isIE')() || $filter('isEdge')();
var DEFAULT_POLL_INTERVAL = 60 * 1000; // milliseconds
Expand All @@ -63,6 +65,7 @@ function OverviewController($scope,

// Filters used by this controller.
var annotation = $filter('annotation');
var canI = $filter('canI');
var getBuildConfigName = $filter('buildConfigForBuild');
var deploymentIsInProgress = $filter('deploymentIsInProgress');
var imageObjectRef = $filter('imageObjectRef');
Expand All @@ -71,6 +74,12 @@ function OverviewController($scope,
var label = $filter('label');
var getPodTemplate = $filter('podTemplate');

// API versions
var serviceBindingsVersion = APIService.getPreferredVersion('servicebindings');
var serviceClassesVersion = APIService.getPreferredVersion('clusterserviceclasses');
var serviceInstancesVersion = APIService.getPreferredVersion('serviceinstances');
var servicePlansVersion = APIService.getPreferredVersion('clusterserviceplans');

var deploymentsByUID;
var imageStreams;
var labelSuggestions = {};
Expand Down Expand Up @@ -102,6 +111,8 @@ function OverviewController($scope,
routesByService: {},
servicesByObjectUID: {},
serviceInstances: {},
serviceClasses: {},
servicePlans: {},
bindingsByInstanceRef: {},
bindingsByApplicationUID: {},
applicationsByBinding: {},
Expand Down Expand Up @@ -314,7 +325,7 @@ function OverviewController($scope,
};

// Updated on viewBy changes to include the app label when appropriate.
var filterFields = ['metadata.name', 'spec.serviceClassName'];
var filterFields = ['metadata.name', 'spec.externalServiceClassName'];
var filterByName = function(items) {
return KeywordService.filterForKeywords(items, filterFields, state.filterKeywords);
};
Expand Down Expand Up @@ -1150,8 +1161,12 @@ function OverviewController($scope,
};

var sortServiceInstances = function() {
state.bindableServiceInstances = BindingService.filterBindableServiceInstances(state.serviceInstances, state.serviceClasses);
state.orderedServiceInstances = BindingService.sortServiceInstances(state.serviceInstances, state.serviceClasses);
state.bindableServiceInstances =
BindingService.filterBindableServiceInstances(state.serviceInstances,
state.serviceClasses,
state.servicePlans);
state.orderedServiceInstances =
BindingService.sortServiceInstances(state.serviceInstances, state.serviceClasses);
};

var watches = [];
Expand Down Expand Up @@ -1312,29 +1327,60 @@ function OverviewController($scope,
setQuotaNotifications();
}, {poll: true, pollInterval: DEFAULT_POLL_INTERVAL}));

var canI = $filter('canI');
var fetchServiceClass, fetchServicePlan;

// Avoid requesting the same service class or service plan twice.
var serviceClassPromises = {};
var servicePlanPromises = {};

// The canI check on watch should be temporary until we have a different solution for handling secret parameters
if (CatalogService.SERVICE_CATALOG_ENABLED && canI({resource: 'serviceinstances', group: 'servicecatalog.k8s.io'}, 'watch')) {
watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
}, context, function(serviceInstances) {
if (CatalogService.SERVICE_CATALOG_ENABLED && canI(serviceInstancesVersion, 'watch')) {

// Get the service class for this instance.
fetchServiceClass = function(instance) {
var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(instance);

// Check if we already have the service class or if a request is already in flight.
if (!_.has(state, ['serviceClasses', serviceClassName]) && !serviceClassPromises[serviceClassName]) {
serviceClassPromises[serviceClassName] = DataService.get(serviceClassesVersion, serviceClassName, {}).then(function(serviceClass) {
state.serviceClasses[serviceClassName] = serviceClass;
}).finally(function() {
delete servicePlanPromises[serviceClassName];
});
}
};

// Get the service plan for this instance.
fetchServicePlan = function(instance) {
var servicePlanName = ServiceInstancesService.getServicePlanNameForInstance(instance);

// Check if we already have the service plan or if a request is already in flight.
if (!_.has(state, ['servicePlans', servicePlanName]) && !servicePlanPromises[servicePlanName]) {
servicePlanPromises[servicePlanName] = DataService.get(servicePlansVersion, servicePlanName, {}).then(function(servicePlan) {
state.servicePlans[servicePlanName] = servicePlan;
}).finally(function() {
delete servicePlanPromises[servicePlanName];
});
}
};

watches.push(DataService.watch(serviceInstancesVersion, context, function(serviceInstances) {
state.serviceInstances = serviceInstances.by('metadata.name');
_.each(state.serviceInstances, function(instance) {
var notifications = ResourceAlertsService.getServiceInstanceAlerts(instance);
setNotifications(instance, notifications);

fetchServiceClass(instance);
fetchServicePlan(instance);
});
sortServiceInstances();
updateLabelSuggestions(state.serviceInstances);
updateFilter();
}, {poll: limitWatches, pollInterval: DEFAULT_POLL_INTERVAL}));
}

if (CatalogService.SERVICE_CATALOG_ENABLED && canI({resource: 'serviceinstancecredentials', group: 'servicecatalog.k8s.io'}, 'watch')) {
watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstancecredentials'
}, context, function(bindings) {
if (CatalogService.SERVICE_CATALOG_ENABLED && canI(serviceBindingsVersion, 'watch')) {
watches.push(DataService.watch(serviceBindingsVersion, context, function(bindings) {
state.bindings = bindings.by('metadata.name');
overview.bindingsByInstanceRef = _.groupBy(state.bindings, 'spec.instanceRef.name');
groupBindings();
Expand All @@ -1347,20 +1393,6 @@ function OverviewController($scope,
state.limitRanges = response.by("metadata.name");
});

if (CatalogService.SERVICE_CATALOG_ENABLED && canI({resource: 'serviceinstances', group: 'servicecatalog.k8s.io'}, 'watch')) {
// TODO: update to behave like ImageStreamResolver
// - we may not even need to list these... perhaps just fetch the ones we need when needed
// If we can't watch instances don't bother getting service classes either
DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, {}, function(serviceClasses) {
state.serviceClasses = serviceClasses.by('metadata.name');
sortServiceInstances();
updateFilter();
});
}

var samplePipelineTemplate = Constants.SAMPLE_PIPELINE_TEMPLATE;
if (samplePipelineTemplate) {
DataService.get("templates", samplePipelineTemplate.name, {
Expand Down
68 changes: 31 additions & 37 deletions app/scripts/controllers/serviceInstance.js
Expand Up @@ -4,14 +4,14 @@ angular.module('openshiftConsole')
.controller('ServiceInstanceController', function ($scope,
$filter,
$routeParams,
APIService,
DataService,
ProjectsService,
ServiceInstancesService) {
$scope.alerts = {};
$scope.projectName = $routeParams.project;
$scope.serviceInstance = null;
$scope.serviceClass = null;
$scope.serviceClasses = null;

$scope.breadcrumbs = [
{
Expand All @@ -26,29 +26,42 @@ angular.module('openshiftConsole')

var watches = [];

var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName');

// API Versions
var serviceInstancesVersion = APIService.getPreferredVersion('serviceinstances');

var updateBreadcrumbs = function() {
if(!$scope.serviceInstance || !$scope.serviceClasses) {
$scope.breadcrumbs.push({
title: $scope.displayName
});
};

var updateServiceClass = function() {
if ($scope.serviceClass) {
return;
}

$scope.breadcrumbs.push({
title: $filter('serviceInstanceDisplayName')($scope.serviceInstance, $scope.serviceClasses)
ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function(serviceClass) {
$scope.serviceClass = serviceClass;
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, serviceClass);
updateBreadcrumbs();
});
};

var updateServiceClassMetadata = function() {
if(!$scope.serviceInstance || !$scope.serviceClasses) {
var updatePlan = function() {
if (ServiceInstancesService.isCurrentPlan($scope.serviceInstance, $scope.plan)) {
return;
}

var serviceClassName = _.get($scope.serviceInstance.spec, 'serviceClassName');
$scope.serviceClass = _.get($scope.serviceClasses, [serviceClassName]);
$scope.plan = _.find(_.get($scope.serviceClass, 'plans'), {name: $scope.serviceInstance.spec.planName });
ServiceInstancesService.fetchServicePlanForInstance($scope.serviceInstance).then(function(plan) {
$scope.plan = plan;
});
};

var serviceResolved = function(service, action) {
var serviceResolved = function(serviceInstance, action) {
$scope.loaded = true;
$scope.serviceInstance = service;
$scope.serviceInstance = serviceInstance;

if (action === "DELETED") {
$scope.alerts["deleted"] = {
Expand All @@ -57,7 +70,8 @@ angular.module('openshiftConsole')
};
}

updateServiceClassMetadata();
updateServiceClass();
updatePlan();
};

ProjectsService
Expand All @@ -67,41 +81,21 @@ angular.module('openshiftConsole')
$scope.projectContext = context;

DataService
.get({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
}, $routeParams.instance, context, { errorNotification: false })
.then(function(service) {

serviceResolved(service);
updateBreadcrumbs();

watches.push(DataService.watchObject({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
}, $routeParams.instance, context, serviceResolved));

.get(serviceInstancesVersion, $routeParams.instance, context, { errorNotification: false })
.then(function(serviceInstance) {
serviceResolved(serviceInstance);
watches.push(DataService.watchObject(serviceInstancesVersion, $routeParams.instance, context, serviceResolved));
}, function(error) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: "The service details could not be loaded.",
message: "The provisioned service details could not be loaded.",
details: $filter('getErrorDetails')(error)
};
});

DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, {}, function(serviceClasses) {
$scope.serviceClasses = serviceClasses.by('metadata.name');
updateServiceClassMetadata();
updateBreadcrumbs();
});

$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});

}));
});
23 changes: 11 additions & 12 deletions app/scripts/controllers/serviceInstances.js
Expand Up @@ -30,24 +30,25 @@ angular.module('openshiftConsole')
$scope.unfilteredServiceInstances = BindingService.sortServiceInstances($scope.unfilteredServiceInstances, $scope.serviceClasses);
};

$scope.getServiceClass = function(serviceInstance) {
var serviceClassName = _.get(serviceInstance, 'spec.serviceClassRef.name');
return _.get($scope, ['serviceClasses', serviceClassName]);
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
$scope.projectContext = context;

watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstancecredentials'
}, context, function(bindings) {
var serviceBindingsVersion = APIService.getPreferredVersion('servicebindings');
watches.push(DataService.watch(serviceBindingsVersion, context, function(bindings) {
var bindingsByName = bindings.by('metadata.name');
$scope.bindingsByInstanceRef = _.groupBy(bindingsByName, 'spec.instanceRef.name');
}));

watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
}, context, function(serviceInstances) {
var serviceInstancesVersion = APIService.getPreferredVersion('serviceinstances');
watches.push(DataService.watch(serviceInstancesVersion, context, function(serviceInstances) {
$scope.emptyMessage = "No provisioned services to show";
$scope.unfilteredServiceInstances = serviceInstances.by('metadata.name');

Expand All @@ -61,10 +62,8 @@ angular.module('openshiftConsole')
Logger.log("provisioned services (subscribe)", $scope.unfilteredServiceInstances);
}));

DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, {}, function(serviceClasses) {
var serviceClassesVersion = APIService.getPreferredVersion('clusterserviceclasses');
DataService.list(serviceClassesVersion, {}, function(serviceClasses) {
$scope.serviceClasses = serviceClasses.by('metadata.name');
sortServiceInstances();
updateFilter();
Expand Down

0 comments on commit a04fb60

Please sign in to comment.