forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceInstances.js
158 lines (135 loc) · 5.95 KB
/
serviceInstances.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'use strict';
angular.module("openshiftConsole")
.factory("ServiceInstancesService", function($filter,
$q,
$uibModal,
APIService,
BindingService,
CatalogService,
DataService,
Logger,
NotificationsService) {
var serviceClassesVersion = APIService.getPreferredVersion('clusterserviceclasses');
var servicePlansVersion = APIService.getPreferredVersion('clusterserviceplans');
var getServiceClassNameForInstance = function(serviceInstance) {
return _.get(serviceInstance, 'spec.clusterServiceClassRef.name');
};
var fetchServiceClassForInstance = function(serviceInstance) {
var serviceClassName = getServiceClassNameForInstance(serviceInstance);
return DataService.get(serviceClassesVersion, serviceClassName, {});
};
var getServicePlanNameForInstance = function(serviceInstance) {
return _.get(serviceInstance, 'spec.clusterServicePlanRef.name');
};
var fetchServicePlanForInstance = function(serviceInstance) {
var servicePlanName = getServicePlanNameForInstance(serviceInstance);
return DataService.get(servicePlansVersion, servicePlanName, {});
};
// Checks if this plan is currently the one the instance references.
var isCurrentPlan = function(serviceInstance, servicePlan) {
var servicePlanName = getServicePlanNameForInstance(serviceInstance);
return servicePlanName === _.get(servicePlan, 'metadata.name');
};
var getBindingsIfNecessary = function(apiObject, bindings) {
if (angular.isDefined(bindings)) {
return $q.when(bindings);
}
var context = {namespace: apiObject.metadata.namespace};
var resource = APIService.getPreferredVersion('servicebindings');
return DataService.list(resource, context).then(function(serviceBindings) {
bindings = serviceBindings.by('metadata.name');
return BindingService.getBindingsForResource(bindings, apiObject);
});
};
var deprovisionInstance = function(apiObject) {
var context = {namespace: apiObject.metadata.namespace};
var resource = APIService.getPreferredVersion('serviceinstances');
NotificationsService.hideNotification("deprovision-service-error");
// TODO - remove once this is resolved https://github.com/kubernetes-incubator/service-catalog/issues/942
var opts = {
propagationPolicy: null
};
return DataService.delete(resource, apiObject.metadata.name, context, opts).then(function() {
NotificationsService.addNotification({
type: "success",
message: "Provisioned service '" + apiObject.metadata.name + "' was marked for deletion."
});
}, function(err) {
NotificationsService.addNotification({
id: "deprovision-service-error",
type: "error",
message: "An error occurred while deleting provisioned service " + apiObject.metadata.name + ".",
details: $filter('getErrorDetails')(err)
});
Logger("An error occurred while deleting provisioned service " + apiObject.metadata.name + ".", err);
});
};
var deprovisionBindings = function(apiObject, bindings) {
if (!CatalogService.SERVICE_CATALOG_ENABLED) {
return;
}
var context = {namespace: apiObject.metadata.namespace};
var resource = APIService.getPreferredVersion('servicebindings');
getBindingsIfNecessary(apiObject, bindings).then(function(serviceBindings) {
_.each(serviceBindings, function (binding) {
if (binding.metadata.deletionTimestamp) {
return;
}
// TODO - remove once this is resolved https://github.com/kubernetes-incubator/service-catalog/issues/942
var opts = {
propagationPolicy: null
};
DataService.delete(resource, binding.metadata.name, context, opts)
.then(function () {
NotificationsService.addNotification({
type: "success",
message: 'Binding ' + binding.metadata.name + "' was marked for deletion."
});
})
.catch(function (err) {
NotificationsService.addNotification({
type: "error",
message: 'Binding ' + binding.metadata.name + "' could not be deleted.",
details: $filter('getErrorDetails')(err)
});
Logger.error('Binding ' + binding.metadata.name + "' could not be deleted.", err);
});
});
});
};
var deprovision = function (apiObject, bindings) {
var modalInstance;
var modalScope = {
kind: apiObject.kind,
displayName: apiObject.metadata.name,
okButtonText: 'Delete',
okButtonClass: 'btn-danger',
cancelButtonText: 'Cancel',
delete: function() {
modalInstance.close('delete');
}
};
modalInstance = $uibModal.open({
animation: true,
templateUrl: 'views/modals/delete-resource.html',
controller: 'ConfirmModalController',
resolve: {
modalConfig: function() {
return modalScope;
}
}
});
return modalInstance.result.then(function() {
deprovisionBindings(apiObject, bindings);
deprovisionInstance(apiObject);
});
};
return {
getServiceClassNameForInstance: getServiceClassNameForInstance,
fetchServiceClassForInstance: fetchServiceClassForInstance,
getServicePlanNameForInstance: getServicePlanNameForInstance,
fetchServicePlanForInstance: fetchServicePlanForInstance,
isCurrentPlan: isCurrentPlan,
deprovision: deprovision
};
});