-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathdeployments.js
197 lines (172 loc) · 9.92 KB
/
deployments.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
'use strict';
/**
* @ngdoc function
* @name openshiftConsole.controller:DeploymentsController
* @description
* # ProjectController
* Controller of the openshiftConsole
*/
angular.module('openshiftConsole')
.controller('DeploymentsController', function ($scope,
$filter,
$routeParams,
APIService,
DataService,
DeploymentsService,
LabelFilter,
Logger,
OwnerReferencesService,
ProjectsService) {
$scope.projectName = $routeParams.project;
$scope.replicationControllers = {};
$scope.unfilteredDeploymentConfigs = {};
$scope.unfilteredDeployments = {};
$scope.replicationControllersByDC = {};
$scope.labelSuggestions = {};
$scope.emptyMessage = "Loading...";
$scope.expandedDeploymentConfigRow = {};
$scope.unfilteredReplicaSets = {};
$scope.unfilteredReplicationControllers = {};
$scope.showEmptyState = true;
$scope.clearFilter = function() {
LabelFilter.clear();
};
var replicaSets, deploymentsByUID;
var annotation = $filter('annotation');
var deploymentsVersion = APIService.getPreferredVersion('deployments');
var deploymentConfigsVersion = APIService.getPreferredVersion('deploymentconfigs');
var replicationControllersVersion = APIService.getPreferredVersion('replicationcontrollers');
var replicaSetsVersion = APIService.getPreferredVersion('replicasets');
function updateFilterMessage() {
var unfilteredDeploymentsEmpty =
_.isEmpty($scope.unfilteredDeploymentConfigs) &&
_.isEmpty($scope.unfilteredReplicationControllers) &&
_.isEmpty($scope.unfilteredDeployments) &&
_.isEmpty($scope.unfilteredReplicaSets);
var isFiltering = !LabelFilter.getLabelSelector().isEmpty();
var filteredDeploymentsEmpty =
_.isEmpty($scope.deploymentConfigs) &&
_.isEmpty($scope.replicationControllersByDC['']) &&
_.isEmpty($scope.deployments) &&
_.isEmpty($scope.replicaSets);
$scope.showEmptyState = unfilteredDeploymentsEmpty;
$scope.filterWithZeroResults = isFiltering && filteredDeploymentsEmpty && !unfilteredDeploymentsEmpty;
}
var groupReplicaSets = function() {
if (!replicaSets || !deploymentsByUID) {
return;
}
$scope.replicaSetsByDeploymentUID = OwnerReferencesService.groupByControllerUID(replicaSets);
$scope.unfilteredReplicaSets = _.get($scope, ['replicaSetsByDeploymentUID', ''], {});
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredReplicaSets, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
$scope.replicaSets = LabelFilter.getLabelSelector().select($scope.unfilteredReplicaSets);
$scope.latestReplicaSetByDeploymentUID = {};
_.each($scope.replicaSetsByDeploymentUID, function(replicaSets, deploymentUID) {
if (!deploymentUID) {
return;
}
$scope.latestReplicaSetByDeploymentUID[deploymentUID] =
DeploymentsService.getActiveReplicaSet(replicaSets, deploymentsByUID[deploymentUID]);
});
updateFilterMessage();
};
var watches = [];
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
watches.push(DataService.watch(replicationControllersVersion, context, function(replicationControllers, action, replicationController) {
$scope.replicationControllers = replicationControllers.by("metadata.name");
var dcName, rcName;
if (replicationController) {
dcName = annotation(replicationController, 'deploymentConfig');
rcName = replicationController.metadata.name;
}
$scope.replicationControllersByDC = DeploymentsService.associateDeploymentsToDeploymentConfig($scope.replicationControllers, $scope.deploymentConfigs, true);
if ($scope.replicationControllersByDC['']) {
$scope.unfilteredReplicationControllers = $scope.replicationControllersByDC[''];
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredReplicationControllers, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
$scope.replicationControllersByDC[''] = LabelFilter.getLabelSelector().select($scope.replicationControllersByDC['']);
}
updateFilterMessage();
if (!action) {
// Loading of the page that will create deploymentConfigDeploymentsInProgress structure, which will associate running deployment to his deploymentConfig.
$scope.deploymentConfigDeploymentsInProgress = DeploymentsService.associateRunningDeploymentToDeploymentConfig($scope.replicationControllersByDC);
} else if (action === 'ADDED' || (action === 'MODIFIED' && ['New', 'Pending', 'Running'].indexOf($filter('deploymentStatus')(replicationController)) > -1)) {
// When new deployment id instantiated/cloned, or in case of a retry, associate him to his deploymentConfig and add him into deploymentConfigDeploymentsInProgress structure.
$scope.deploymentConfigDeploymentsInProgress[dcName] = $scope.deploymentConfigDeploymentsInProgress[dcName] || {};
$scope.deploymentConfigDeploymentsInProgress[dcName][rcName] = replicationController;
} else if (action === 'MODIFIED') {
// After the deployment ends remove him from the deploymentConfigDeploymentsInProgress structure.
var status = $filter('deploymentStatus')(replicationController);
if (status === "Complete" || status === "Failed"){
delete $scope.deploymentConfigDeploymentsInProgress[dcName][rcName];
}
}
// Extract the causes from the encoded deployment config
if (replicationController) {
if (action !== "DELETED") {
replicationController.causes = $filter('deploymentCauses')(replicationController);
}
}
else {
angular.forEach($scope.replicationControllers, function(replicationController) {
replicationController.causes = $filter('deploymentCauses')(replicationController);
});
}
Logger.log("replicationControllers (subscribe)", $scope.replicationControllers);
}));
watches.push(DataService.watch(replicaSetsVersion, context, function(replicaSetsData) {
replicaSets = replicaSetsData.by("metadata.name");
groupReplicaSets();
Logger.log("replicasets (subscribe)", $scope.replicaSets);
}));
watches.push(DataService.watch(deploymentConfigsVersion, context, function(deploymentConfigs) {
$scope.deploymentConfigsLoaded = true;
$scope.unfilteredDeploymentConfigs = deploymentConfigs.by("metadata.name");
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredDeploymentConfigs, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
$scope.deploymentConfigs = LabelFilter.getLabelSelector().select($scope.unfilteredDeploymentConfigs);
$scope.emptyMessage = "No deployment configurations to show";
$scope.replicationControllersByDC = DeploymentsService.associateDeploymentsToDeploymentConfig($scope.replicationControllers, $scope.deploymentConfigs, true);
if ($scope.replicationControllersByDC['']) {
$scope.unfilteredReplicationControllers = $scope.replicationControllersByDC[''];
$scope.replicationControllersByDC[''] = LabelFilter.getLabelSelector().select($scope.replicationControllersByDC['']);
}
updateFilterMessage();
Logger.log("deploymentconfigs (subscribe)", $scope.deploymentConfigs);
}));
watches.push(DataService.watch(deploymentsVersion, context, function(deploymentData) {
deploymentsByUID = $scope.unfilteredDeployments = deploymentData.by("metadata.uid");
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredDeployments, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
$scope.deployments = LabelFilter.getLabelSelector().select($scope.unfilteredDeployments);
groupReplicaSets();
Logger.log("deployments (subscribe)", $scope.unfilteredDeployments);
}));
// Does the deployment config table have content?
$scope.showDeploymentConfigTable = function() {
var size = _.size($scope.replicationControllersByDC);
return size > 1 || (size === 1 && !$scope.replicationControllersByDC['']);
};
LabelFilter.onActiveFiltersChanged(function(labelSelector) {
// trigger a digest loop
$scope.$evalAsync(function() {
$scope.deploymentConfigs = labelSelector.select($scope.unfilteredDeploymentConfigs);
$scope.replicationControllersByDC = DeploymentsService.associateDeploymentsToDeploymentConfig($scope.replicationControllers, $scope.deploymentConfigs, true);
if ($scope.replicationControllersByDC['']) {
$scope.unfilteredReplicationControllers = $scope.replicationControllersByDC[''];
$scope.replicationControllersByDC[''] = LabelFilter.getLabelSelector().select($scope.replicationControllersByDC['']);
}
$scope.deployments = labelSelector.select($scope.unfilteredDeployments);
$scope.replicaSets = labelSelector.select($scope.unfilteredReplicaSets);
updateFilterMessage();
});
});
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
});