Skip to content

Commit

Permalink
Convert clusters and datastores collection from ruby to react
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-samuel committed Nov 19, 2024
1 parent f2c46c5 commit eb0a8ad
Show file tree
Hide file tree
Showing 50 changed files with 1,254 additions and 147 deletions.
7 changes: 7 additions & 0 deletions app/controllers/ops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ def replace_right_cell(options = {})

presenter = ExplorerPresenter.new(:active_tree => x_active_tree)

if params["tab_id"] == "settings_cu_collection"
@hide_bottom_bar = true
end

replace_explorer_trees(replace_trees, presenter)
rebuild_toolbars(presenter)
handle_bottom_cell(nodetype, presenter, locals)
Expand Down Expand Up @@ -806,6 +810,9 @@ def handle_bottom_cell(nodetype, presenter, locals)
if ["settings_workers", "diagnostics_cu_repair"].include?(@sb[:active_tab])
presenter.hide(:form_buttons_div)
end
if @hide_bottom_bar
presenter.hide(:form_buttons_div)
end
end

def replace_explorer_trees(replace_trees, presenter)
Expand Down
129 changes: 94 additions & 35 deletions app/controllers/ops_controller/settings/cap_and_u.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def cu_collection_update

return unless load_edit("cu_edit__collection", "replace_cell__explorer")

cu_collection_get_form_vars

if params[:button] == "save"
# C & U collection settings
if @edit[:new][:all_clusters] != @edit[:current][:all_clusters]
Expand Down Expand Up @@ -39,11 +41,6 @@ def cu_collection_update
add_flash(_("Capacity and Utilization Collection settings saved"))
get_node_info(x_node)
replace_right_cell(:nodetype => @nodetype)
elsif params[:button] == "reset"
@changed = false
add_flash(_("All changes have been reset"), :warning)
get_node_info(x_node)
replace_right_cell(:nodetype => @nodetype)
end
end

Expand All @@ -58,22 +55,82 @@ def set_perf_collection_for_clusters
end
end

def cu_collection_field_changed
assert_privileges("region_edit")
def cu_collection_fetch
@edit = {}
@edit[:new] = {}
@edit[:current] = {}
@edit[:key] = "cu_edit__collection"
@edit[:current][:all_clusters] = Metric::Targets.perf_capture_always[:host_and_cluster]
@edit[:current][:all_storages] = Metric::Targets.perf_capture_always[:storage]
@edit[:current][:clusters] = []
@cl_hash = EmsCluster.get_perf_collection_object_list
@cl_hash.each_with_index do |h, j|
_cid, cl_hash = h
c = cl_hash[:cl_rec]
enabled = cl_hash[:ho_enabled]
enabled_host_ids = enabled.collect(&:id)
hosts = (cl_hash[:ho_enabled] + cl_hash[:ho_disabled]).sort_by { |ho| ho.name.downcase }
cl_enabled = enabled_host_ids.length == hosts.length
en_flg = cl_enabled && !enabled.empty?
@edit[:current][:clusters].push(:id => c.id, :capture => en_flg)
@edit[:current][c.id] = []
hosts.each do |host|
host_capture = enabled_host_ids.include?(host.id.to_i)
@edit[:current][c.id].push(:id => host.id, :capture => host_capture)
end
flg = true
count = 0
@edit[:current][c.id].each do |host|
unless host[:capture]
count += 1 # checking if all hosts are unchecked then cluster capture will be false else undefined
flg = count == @edit[:current][c.id].length ? false : "undefined"
end
@edit[:current][:clusters][j][:capture] = flg
end
end
@edit[:current][:clusters].sort_by! { |c| c[:name] }

return unless load_edit("cu_edit__collection", "replace_cell__explorer")
# ##################### Adding Non-Clustered hosts node
@edit[:current][:non_cl_hosts] ||= []
ExtManagementSystem.in_my_region.each do |e|
all = e.non_clustered_hosts
all.each do |h|
@edit[:current][:non_cl_hosts] << {:id => h.id, :capture => h.perf_capture_enabled?}
end
end
if @edit[:current][:clusters].present?
@cluster_tree = TreeBuilderClusters.new(:cluster_tree, @sb, true, :root => @cl_hash)
end
@edit[:current][:storages] = {}
Storage.in_my_region.includes(:taggings, :tags, :hosts).select(:id, :name, :location).sort_by { |s| s.name.downcase }.each do |s|
@edit[:current][:storages][s.id] = {:id => s.id, :capture => s.perf_capture_enabled?}
end
if @edit[:current][:storages].present?
@datastore_tree = TreeBuilderDatastores.new(:datastore_tree, @sb, true, :root => @edit[:current][:storages])
end
@edit[:new] = copy_hash(@edit[:current])

cu_collection_get_form_vars
@changed = (@edit[:new] != @edit[:current]) # UI edit form, C&U collection form
# C&U tab
# need to create an array of items, if their or their children's capture has been changed then make the changed one blue.
render :update do |page|
page << javascript_prologue
page.replace_html(@refresh_div, :partial => @refresh_partial) if @refresh_div
page << "$('#clusters_div').#{params[:all_clusters] == 'true' ? "hide" : "show"}()" if params[:all_clusters]
page << "$('#storages_div').#{params[:all_storages] == 'true' ? "hide" : "show"}()" if params[:all_storages]
page << javascript_for_miq_button_visibility(@changed)
clusters = []
@edit[:current].each do |key, value|
if key.is_a?(Numeric)
clusters << value
end
end
hosts = []
clusters.each do |cluster|
if !cluster.empty?
cluster.each do |host|
hosts << host
end
else
hosts << cluster
end
end

render :json => {
:hosts => hosts,
:datastores => @edit[:current][:storages].values
}
end

private
Expand Down Expand Up @@ -136,38 +193,40 @@ def cu_build_edit_screen
end

def cu_collection_get_form_vars
@edit[:new][:all_clusters] = params[:all_clusters] == 'true' if params[:all_clusters]
@edit[:new][:all_storages] = params[:all_storages] == 'true' if params[:all_storages]
@edit[:new][:all_clusters] = params[:all_clusters]
@edit[:new][:all_storages] = params[:all_datastores]

if params[:id]
model, id, _ = TreeBuilder.extract_node_model_and_id(params[:id])

if model == 'Storage'
@edit[:new][:storages][id.to_i][:capture] = params[:check] == "1"
else
cluster_tree_settings(model, id)
end
params[:clusters_checked].each do |cluster|
model, id, _ = TreeBuilder.extract_node_model_and_id(cluster[:id])
cluster_tree_settings(model, id, cluster)
end
params[:datastores_checked].each do |storage|
model, id, _ = TreeBuilder.extract_node_model_and_id(storage[:id])
@edit[:new][:storages][id.to_i][:capture] = storage[:capture]
end
params[:hosts_checked].each do |host|
model, id, _ = TreeBuilder.extract_node_model_and_id(host[:id])
cluster_tree_settings(model, id, host)
end
end

def cluster_tree_settings(model, id)
def cluster_tree_settings(model, id, cluster_or_host)
if id == "NonCluster" # Clicked on all non-clustered hosts
@edit[:new][:non_cl_hosts].each { |c| c[:capture] = params[:check] == "1" }
@edit[:new][:non_cl_hosts].each { |c| c[:capture] = cluster_or_host[:capture] }
elsif model == "EmsCluster" # Clicked on a cluster
@edit[:new][id.to_i].each { |h| h[:capture] = params[:check] == "1" }
@edit[:new][id.to_i].each { |h| h[:capture] = cluster_or_host[:capture] }
elsif model == "Host" # Clicked on a host
nc_host = @edit[:new][:non_cl_hosts].find { |x| x[:id] == id.to_i }
# The host is among the non-clustered ones
return nc_host[:capture] = params[:check] == "1" if nc_host

return nc_host[:capture] = cluster_or_host[:capture] if nc_host
# The host is under a cluster, find it and change it
@edit[:new][:clusters].find do |cl|
@edit[:new][cl[:id]].find do |h|
found = h[:id] == id.to_i
h[:capture] = params[:check] == "1" if found
h[:capture] = cluster_or_host[:capture] if found
found
end
end
end
end
end
end
Loading

0 comments on commit eb0a8ad

Please sign in to comment.