-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathapplicationsService.js
80 lines (70 loc) · 3.15 KB
/
applicationsService.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
'use strict';
angular.module("openshiftCommonServices").
service("ApplicationsService", function(
$q,
APIService,
DataService) {
var deploymentsVersion = APIService.getPreferredVersion('deployments');
var deploymentConfigsVersion = APIService.getPreferredVersion('deploymentconfigs');
var replicationControllersVersion = APIService.getPreferredVersion('replicationcontrollers');
var replicaSetsVersion = APIService.getPreferredVersion('replicasets');
var statefulSetsVersion = APIService.getPreferredVersion('statefulsets');
// List replication controllers in a namespace that are NOT managed by a
// deployment config. Note: This will not return replication controllers that
// have been orphaned by `oc delete dc/foo --cascade=false`.
var listStandaloneReplicationControllers = function(context) {
return DataService.list(replicationControllersVersion, context, null, {
http: {
params: {
// If the replica set has a `openshift.io/deployment-config-name`
// label, it's managed by a deployment config.
labelSelector: "!openshift.io/deployment-config.name"
}
}
});
};
// List replica sets in a namespace that are NOT managed by a deployment.
// Note: This will not return replica sets that have been orphaned by
// `oc delete deployment/foo --cascade=false`.
var listStandaloneReplicaSets = function(context) {
return DataService.list(replicaSetsVersion, context, null, {
http: {
params: {
// If the replica set has a `pod-template-hash` label, it's managed
// by a deployment.
labelSelector: "!pod-template-hash"
}
}
});
};
var getApplications = function(context) {
var deferred = $q.defer();
var promises = [];
// Load all the "application" types
promises.push(DataService.list(deploymentConfigsVersion, context));
promises.push(listStandaloneReplicationControllers(context));
promises.push(DataService.list(deploymentsVersion, context));
promises.push(listStandaloneReplicaSets(context));
promises.push(DataService.list(statefulSetsVersion, context));
$q.all(promises).then(_.spread(function(deploymentConfigData, replicationControllerData, deploymentData, replicaSetData, statefulSetData) {
var deploymentConfigs = _.toArray(deploymentConfigData.by('metadata.name'));
var replicationControllers = _.toArray(replicationControllerData.by('metadata.name'));
var deployments = _.toArray(deploymentData.by('metadata.name'));
var replicaSets = _.toArray(replicaSetData.by('metadata.name'));
var statefulSets = _.toArray(statefulSetData.by('metadata.name'));
var apiObjects = deploymentConfigs.concat(deployments)
.concat(replicationControllers)
.concat(replicaSets)
.concat(statefulSets);
deferred.resolve(_.sortBy(apiObjects, ['metadata.name', 'kind']));
}), function(e) {
deferred.reject(e);
});
return deferred.promise;
};
return {
listStandaloneReplicationControllers: listStandaloneReplicationControllers,
listStandaloneReplicaSets: listStandaloneReplicaSets,
getApplications: getApplications
};
});