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

Adopt service catalog API changes #2155

Merged
merged 1 commit into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 63 additions & 31 deletions app/scripts/controllers/overview.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading