@@ -6,6 +6,8 @@ def cu_collection_update
6
6
7
7
return unless load_edit ( "cu_edit__collection" , "replace_cell__explorer" )
8
8
9
+ cu_collection_get_form_vars
10
+
9
11
if params [ :button ] == "save"
10
12
# C & U collection settings
11
13
if @edit [ :new ] [ :all_clusters ] != @edit [ :current ] [ :all_clusters ]
@@ -39,11 +41,6 @@ def cu_collection_update
39
41
add_flash ( _ ( "Capacity and Utilization Collection settings saved" ) )
40
42
get_node_info ( x_node )
41
43
replace_right_cell ( :nodetype => @nodetype )
42
- elsif params [ :button ] == "reset"
43
- @changed = false
44
- add_flash ( _ ( "All changes have been reset" ) , :warning )
45
- get_node_info ( x_node )
46
- replace_right_cell ( :nodetype => @nodetype )
47
44
end
48
45
end
49
46
@@ -58,22 +55,82 @@ def set_perf_collection_for_clusters
58
55
end
59
56
end
60
57
61
- def cu_collection_field_changed
62
- assert_privileges ( "region_edit" )
58
+ def cu_collection_fetch
59
+ @edit = { }
60
+ @edit [ :new ] = { }
61
+ @edit [ :current ] = { }
62
+ @edit [ :key ] = "cu_edit__collection"
63
+ @edit [ :current ] [ :all_clusters ] = Metric ::Targets . perf_capture_always [ :host_and_cluster ]
64
+ @edit [ :current ] [ :all_storages ] = Metric ::Targets . perf_capture_always [ :storage ]
65
+ @edit [ :current ] [ :clusters ] = [ ]
66
+ @cl_hash = EmsCluster . get_perf_collection_object_list
67
+ @cl_hash . each_with_index do |h , j |
68
+ _cid , cl_hash = h
69
+ c = cl_hash [ :cl_rec ]
70
+ enabled = cl_hash [ :ho_enabled ]
71
+ enabled_host_ids = enabled . collect ( &:id )
72
+ hosts = ( cl_hash [ :ho_enabled ] + cl_hash [ :ho_disabled ] ) . sort_by { |ho | ho . name . downcase }
73
+ cl_enabled = enabled_host_ids . length == hosts . length
74
+ en_flg = cl_enabled && !enabled . empty?
75
+ @edit [ :current ] [ :clusters ] . push ( :id => c . id , :capture => en_flg )
76
+ @edit [ :current ] [ c . id ] = [ ]
77
+ hosts . each do |host |
78
+ host_capture = enabled_host_ids . include? ( host . id . to_i )
79
+ @edit [ :current ] [ c . id ] . push ( :id => host . id , :capture => host_capture )
80
+ end
81
+ flg = true
82
+ count = 0
83
+ @edit [ :current ] [ c . id ] . each do |host |
84
+ unless host [ :capture ]
85
+ count += 1 # checking if all hosts are unchecked then cluster capture will be false else undefined
86
+ flg = count == @edit [ :current ] [ c . id ] . length ? false : "undefined"
87
+ end
88
+ @edit [ :current ] [ :clusters ] [ j ] [ :capture ] = flg
89
+ end
90
+ end
91
+ @edit [ :current ] [ :clusters ] . sort_by! { |c | c [ :name ] }
63
92
64
- return unless load_edit ( "cu_edit__collection" , "replace_cell__explorer" )
93
+ # ##################### Adding Non-Clustered hosts node
94
+ @edit [ :current ] [ :non_cl_hosts ] ||= [ ]
95
+ ExtManagementSystem . in_my_region . each do |e |
96
+ all = e . non_clustered_hosts
97
+ all . each do |h |
98
+ @edit [ :current ] [ :non_cl_hosts ] << { :id => h . id , :capture => h . perf_capture_enabled? }
99
+ end
100
+ end
101
+ if @edit [ :current ] [ :clusters ] . present?
102
+ @cluster_tree = TreeBuilderClusters . new ( :cluster_tree , @sb , true , :root => @cl_hash )
103
+ end
104
+ @edit [ :current ] [ :storages ] = { }
105
+ Storage . in_my_region . includes ( :taggings , :tags , :hosts ) . select ( :id , :name , :location ) . sort_by { |s | s . name . downcase } . each do |s |
106
+ @edit [ :current ] [ :storages ] [ s . id ] = { :id => s . id , :capture => s . perf_capture_enabled? }
107
+ end
108
+ if @edit [ :current ] [ :storages ] . present?
109
+ @datastore_tree = TreeBuilderDatastores . new ( :datastore_tree , @sb , true , :root => @edit [ :current ] [ :storages ] )
110
+ end
111
+ @edit [ :new ] = copy_hash ( @edit [ :current ] )
65
112
66
- cu_collection_get_form_vars
67
- @changed = ( @edit [ :new ] != @edit [ :current ] ) # UI edit form, C&U collection form
68
- # C&U tab
69
- # need to create an array of items, if their or their children's capture has been changed then make the changed one blue.
70
- render :update do |page |
71
- page << javascript_prologue
72
- page . replace_html ( @refresh_div , :partial => @refresh_partial ) if @refresh_div
73
- page << "$('#clusters_div').#{ params [ :all_clusters ] == 'true' ? "hide" : "show" } ()" if params [ :all_clusters ]
74
- page << "$('#storages_div').#{ params [ :all_storages ] == 'true' ? "hide" : "show" } ()" if params [ :all_storages ]
75
- page << javascript_for_miq_button_visibility ( @changed )
113
+ clusters = [ ]
114
+ @edit [ :current ] . each do |key , value |
115
+ if key . is_a? ( Numeric )
116
+ clusters << value
117
+ end
76
118
end
119
+ hosts = [ ]
120
+ clusters . each do |cluster |
121
+ if !cluster . empty?
122
+ cluster . each do |host |
123
+ hosts << host
124
+ end
125
+ else
126
+ hosts << cluster
127
+ end
128
+ end
129
+
130
+ render :json => {
131
+ :hosts => hosts ,
132
+ :datastores => @edit [ :current ] [ :storages ] . values
133
+ }
77
134
end
78
135
79
136
private
@@ -136,38 +193,40 @@ def cu_build_edit_screen
136
193
end
137
194
138
195
def cu_collection_get_form_vars
139
- @edit [ :new ] [ :all_clusters ] = params [ :all_clusters ] == 'true' if params [ :all_clusters ]
140
- @edit [ :new ] [ :all_storages ] = params [ :all_storages ] == 'true' if params [ :all_storages ]
196
+ @edit [ :new ] [ :all_clusters ] = params [ :all_clusters ]
197
+ @edit [ :new ] [ :all_storages ] = params [ :all_datastores ]
141
198
142
- if params [ :id ]
143
- model , id , _ = TreeBuilder . extract_node_model_and_id ( params [ :id ] )
144
-
145
- if model == 'Storage'
146
- @edit [ :new ] [ :storages ] [ id . to_i ] [ :capture ] = params [ :check ] == "1"
147
- else
148
- cluster_tree_settings ( model , id )
149
- end
199
+ params [ :clusters_checked ] . each do |cluster |
200
+ model , id , _ = TreeBuilder . extract_node_model_and_id ( cluster [ :id ] )
201
+ cluster_tree_settings ( model , id , cluster )
202
+ end
203
+ params [ :datastores_checked ] . each do |storage |
204
+ model , id , _ = TreeBuilder . extract_node_model_and_id ( storage [ :id ] )
205
+ @edit [ :new ] [ :storages ] [ id . to_i ] [ :capture ] = storage [ :capture ]
206
+ end
207
+ params [ :hosts_checked ] . each do |host |
208
+ model , id , _ = TreeBuilder . extract_node_model_and_id ( host [ :id ] )
209
+ cluster_tree_settings ( model , id , host )
150
210
end
151
211
end
152
212
153
- def cluster_tree_settings ( model , id )
213
+ def cluster_tree_settings ( model , id , cluster_or_host )
154
214
if id == "NonCluster" # Clicked on all non-clustered hosts
155
- @edit [ :new ] [ :non_cl_hosts ] . each { |c | c [ :capture ] = params [ :check ] == "1" }
215
+ @edit [ :new ] [ :non_cl_hosts ] . each { |c | c [ :capture ] = cluster_or_host [ :capture ] }
156
216
elsif model == "EmsCluster" # Clicked on a cluster
157
- @edit [ :new ] [ id . to_i ] . each { |h | h [ :capture ] = params [ :check ] == "1" }
217
+ @edit [ :new ] [ id . to_i ] . each { |h | h [ :capture ] = cluster_or_host [ :capture ] }
158
218
elsif model == "Host" # Clicked on a host
159
219
nc_host = @edit [ :new ] [ :non_cl_hosts ] . find { |x | x [ :id ] == id . to_i }
160
220
# The host is among the non-clustered ones
161
- return nc_host [ :capture ] = params [ :check ] == "1" if nc_host
162
-
221
+ return nc_host [ :capture ] = cluster_or_host [ :capture ] if nc_host
163
222
# The host is under a cluster, find it and change it
164
223
@edit [ :new ] [ :clusters ] . find do |cl |
165
224
@edit [ :new ] [ cl [ :id ] ] . find do |h |
166
225
found = h [ :id ] == id . to_i
167
- h [ :capture ] = params [ :check ] == "1" if found
226
+ h [ :capture ] = cluster_or_host [ :capture ] if found
168
227
found
169
228
end
170
229
end
171
230
end
172
231
end
173
- end
232
+ end
0 commit comments