-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates for Service Instance & Bindings
Updates for service instances. Prep to allow updates to chosen parameters for instance and bindings.
- Loading branch information
Showing
12 changed files
with
891 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
angular.module('openshiftConsole') | ||
.controller('ProvisionedServiceController', function ($scope, | ||
$filter, | ||
$routeParams, | ||
DataService, | ||
ProjectsService) { | ||
$scope.alerts = {}; | ||
$scope.displayName = null; | ||
$scope.projectName = $routeParams.project; | ||
$scope.serviceInstance = null; | ||
$scope.serviceInstances = null; | ||
$scope.serviceClasses = {}; | ||
|
||
$scope.breadcrumbs = [ | ||
{ | ||
title: "Provisioned Services", | ||
link: "project/" + $routeParams.project + "/browse/service-instances" | ||
}, | ||
{ | ||
title: $routeParams.instance | ||
} | ||
]; | ||
|
||
var watches = []; | ||
|
||
var setDisplayName = function() { | ||
if(!$scope.serviceInstance || !$scope.serviceClasses) { | ||
return; | ||
} | ||
|
||
$scope.displayName = $filter('serviceInstanceDisplayName')($scope.serviceInstance, $scope.serviceClasses); | ||
}; | ||
|
||
var serviceResolved = function(service, action) { | ||
$scope.loaded = true; | ||
$scope.serviceInstance = service; | ||
|
||
if (action === "DELETED") { | ||
$scope.alerts["deleted"] = { | ||
type: "warning", | ||
message: "This provisioned service has been deleted." | ||
}; | ||
} | ||
}; | ||
|
||
ProjectsService | ||
.get($routeParams.project) | ||
.then(_.spread(function(project, context) { | ||
$scope.project = project; | ||
$scope.projectContext = context; | ||
|
||
DataService | ||
.get({ | ||
group: 'servicecatalog.k8s.io', | ||
resource: 'instances' | ||
}, $routeParams.instance, context, { errorNotification: false }) | ||
.then(function(service) { | ||
serviceResolved(service); | ||
setDisplayName(); | ||
watches.push(DataService.watchObject({ | ||
group: 'servicecatalog.k8s.io', | ||
resource: 'instances' | ||
}, $routeParams.instance, context, serviceResolved)); | ||
|
||
}, function(error) { | ||
$scope.loaded = true; | ||
$scope.alerts["load"] = { | ||
type: "error", | ||
message: "The service details could not be loaded.", | ||
details: $filter('getErrorDetails')(error) | ||
}; | ||
}); | ||
|
||
DataService.list({ | ||
group: 'servicecatalog.k8s.io', | ||
resource: 'serviceclasses' | ||
}, context, function(serviceClasses) { | ||
$scope.serviceClasses = serviceClasses.by('metadata.name'); | ||
setDisplayName(); | ||
}); | ||
|
||
watches.push(DataService.watch({ | ||
group: 'servicecatalog.k8s.io', | ||
resource: 'instances' | ||
}, context, function(services) { | ||
$scope.serviceInstances = services.by("metadata.name"); | ||
})); | ||
|
||
$scope.$on('$destroy', function(){ | ||
DataService.unwatchAll(watches); | ||
}); | ||
|
||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
'use strict'; | ||
|
||
angular.module('openshiftConsole') | ||
.controller('ProvisionedServicesController', function ($scope, | ||
$filter, | ||
$routeParams, | ||
APIService, | ||
BindingService, | ||
Constants, | ||
DataService, | ||
LabelFilter, | ||
Logger, | ||
ProjectsService) { | ||
$scope.alerts = $scope.alerts || {}; | ||
$scope.applicationsByBinding = {}; | ||
$scope.bindings = {}; | ||
$scope.bindableServiceInstances = {}; | ||
//$scope.bindingsByApplicationUID = {}; | ||
$scope.bindingsByInstanceRef = {}; | ||
$scope.emptyMessage = "Loading..."; | ||
$scope.labelSuggestions = {}; | ||
//$scope.notificationsByObjectUID = {}; | ||
$scope.projectName = $routeParams.project; | ||
$scope.serviceClasses = {}; | ||
$scope.serviceInstances = {}; | ||
$scope.unfilteredServiceInstances = {}; | ||
|
||
var watches = []; | ||
|
||
/*var getUID = function(apiObject) { | ||
return _.get(apiObject, 'metadata.uid'); | ||
}; | ||
var setNotifications = function(apiObject, notifications) { | ||
var uid = getUID(apiObject); | ||
$scope.notificationsByObjectUID[uid] = notifications || {}; | ||
}; | ||
var getNotifications = function(apiObject) { | ||
var uid = getUID(apiObject); | ||
if (!uid) { | ||
return {}; | ||
} | ||
return _.get(state, ['notificationsByObjectUID', uid], {}); | ||
};*/ | ||
|
||
var updateFilter = function() { | ||
$scope.serviceInstances = LabelFilter.getLabelSelector().select($scope.unfilteredServiceInstances); | ||
}; | ||
|
||
var sortServiceInstances = function() { | ||
$scope.bindableServiceInstances = BindingService.filterBindableServiceInstances($scope.unfilteredServiceInstances, $scope.serviceClasses); | ||
$scope.unfilteredServiceInstances = BindingService.sortServiceInstances($scope.unfilteredServiceInstances, $scope.serviceClasses); | ||
}; | ||
|
||
/*var refreshSecrets = _.debounce(function(context) { | ||
DataService.list("secrets", context, null, { errorNotification: false }).then(function(secretData) { | ||
state.secrets = secretData.by("metadata.name"); | ||
}); | ||
}, 300);*/ | ||
|
||
var groupBindings = function() { | ||
// Build two maps: | ||
// - Bindings by the UID of the target object | ||
// - API objects by binding name | ||
/* | ||
state.bindingsByApplicationUID = {}; | ||
state.applicationsByBinding = {}; | ||
//state.deleteableBindingsByApplicationUID = {}; | ||
// If there are no bindings, nothing to do. | ||
if (_.isEmpty(state.bindings)) { | ||
return; | ||
} | ||
// All objects that can be a target for bindings. | ||
var objectsByKind = [ | ||
overview.deployments, | ||
overview.deploymentConfigs, | ||
overview.vanillaReplicationControllers, | ||
overview.vanillaReplicaSets, | ||
overview.statefulSets | ||
]; | ||
// Make sure all the binding targets have loaded first. | ||
if (_.some(objectsByKind, function(collection) { return !collection; })) { | ||
return; | ||
} | ||
// Build a map of pod preset selectors by binding name. | ||
var podPresetSelectors = {}; | ||
_.each(state.bindings, function(binding) { | ||
var podPresetSelector = _.get(binding, 'spec.alphaPodPresetTemplate.selector'); | ||
if (podPresetSelector) { | ||
podPresetSelectors[binding.metadata.name] = new LabelSelector(podPresetSelector); | ||
} | ||
}); | ||
_.each(objectsByKind, function(collection) { | ||
_.each(collection, function(apiObject) { | ||
// Key by UID since name is not unique across different kinds. | ||
var applicationUID = getUID(apiObject); | ||
// Create a selector for the potential binding target to check if the | ||
// pod preset covers the selector. | ||
var applicationSelector = new LabelSelector(_.get(apiObject, 'spec.selector')); | ||
state.bindingsByApplicationUID[applicationUID] = []; | ||
state.deleteableBindingsByApplicationUID[applicationUID] = []; | ||
// Look at each pod preset selector to see if it covers this API object selector. | ||
_.each(podPresetSelectors, function(podPresetSelector, bindingName) { | ||
if (podPresetSelector.covers(applicationSelector)) { | ||
// Keep a map of the target UID to the binding and the binding to | ||
// the target. We want to show bindings both in the "application" | ||
// object rows and the service instance rows. | ||
state.bindingsByApplicationUID[applicationUID].push(state.bindings[bindingName]); | ||
if (!_.get(state.bindings[bindingName], 'metadata.deletionTimestamp')) { | ||
state.deleteableBindingsByApplicationUID[applicationUID].push(state.bindings[bindingName]); | ||
} | ||
state.applicationsByBinding[bindingName] = state.applicationsByBinding[bindingName] || []; | ||
state.applicationsByBinding[bindingName].push(apiObject); | ||
} | ||
}); | ||
}); | ||
}); | ||
$scope.bindingsByInstanceRef = _.reduce(state.bindingsByInstanceRef, function(result, bindingList, key) { | ||
result[key] = _.sortBy(bindingList, function(binding) { | ||
var apps = _.get(state.applicationsByBinding, [binding.metadata.name]); | ||
var firstName = _.get(_.head(apps), ['metadata', 'name']); | ||
return firstName || binding.metadata.name; | ||
}); | ||
return result; | ||
}, {});*/ | ||
}; | ||
|
||
ProjectsService | ||
.get($routeParams.project) | ||
.then(_.spread(function(project, context) { | ||
$scope.project = project; | ||
$scope.projectContext = context; | ||
|
||
watches.push(DataService.watch({ | ||
group: 'servicecatalog.k8s.io', | ||
resource: 'bindings' | ||
}, context, function(bindings) { | ||
$scope.bindings = bindings.by('metadata.name'); | ||
$scope.bindingsByInstanceRef = _.groupBy($scope.bindings, 'spec.instanceRef.name'); | ||
groupBindings(); | ||
//refreshSecrets(context); | ||
})); | ||
|
||
watches.push(DataService.watch({ | ||
group: 'servicecatalog.k8s.io', | ||
resource: 'instances' | ||
}, context, function(serviceInstances) { | ||
$scope.emptyMessage = "No provisioned services to show"; | ||
$scope.unfilteredServiceInstances = serviceInstances.by('metadata.name'); | ||
|
||
//_.each($scope.unfilteredServiceInstances, function (instance) { | ||
// var notifications = ResourceAlertsService.getServiceInstanceAlerts(instance); | ||
// setNotifications(instance, notifications); | ||
//}); | ||
|
||
sortServiceInstances(); | ||
updateFilter(); | ||
updateFilterWarning(); | ||
|
||
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredServiceInstances, $scope.labelSuggestions); | ||
LabelFilter.setLabelSuggestions($scope.labelSuggestions); | ||
|
||
Logger.log("provisioned services (subscribe)", $scope.unfilteredServiceInstances); | ||
})); | ||
|
||
DataService.list({ | ||
group: 'servicecatalog.k8s.io', | ||
resource: 'serviceclasses' | ||
}, context, function(serviceClasses) { | ||
$scope.serviceClasses = serviceClasses.by('metadata.name'); | ||
sortServiceInstances(); | ||
updateFilter(); | ||
}); | ||
|
||
function updateFilterWarning() { | ||
if (!LabelFilter.getLabelSelector().isEmpty() && _.isEmpty($scope.serviceInstances) && !_.isEmpty($scope.unfilteredServiceInstances)) { | ||
$scope.alerts["all-instances-filtered"] = { | ||
type: "warning", | ||
details: "The active filters are hiding all provisioned services." | ||
}; | ||
} | ||
else { | ||
delete $scope.alerts["all-instances-filtered"]; | ||
} | ||
} | ||
|
||
LabelFilter.onActiveFiltersChanged(function(labelSelector) { | ||
// trigger a digest loop | ||
$scope.$apply(function() { | ||
$scope.serviceInstances = labelSelector.select($scope.unfilteredServiceInstances); | ||
updateFilterWarning(); | ||
}); | ||
}); | ||
|
||
$scope.$on('$destroy', function(){ | ||
DataService.unwatchAll(watches); | ||
}); | ||
|
||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.