Blame SOURCES/bz1231858-03-resourcefence-agent-options-form-needs-an-overhau.patch

15f218
From 0d440890ade31a2050ac861270a39be5c91d4bbb Mon Sep 17 00:00:00 2001
15f218
From: Ivan Devat <idevat@redhat.com>
15f218
Date: Wed, 14 Sep 2016 15:29:06 +0200
15f218
Subject: [PATCH] squash bz1231858 resource/fence agent options form
15f218
15f218
6007fba70212 web UI: treat resource as managed by default
15f218
15f218
f1b60c3a2bac WebUI: fix node standby for pcs 0.9.138 and older
15f218
15f218
73adbedf268e webUI: allow change groups, clone and unclone of resource on clusters running older pcsd
15f218
15f218
1302b4e62e19 webUI: fix group list when managing cluster running older pcsd
15f218
15f218
f639c0dded12 webUI: don't show group selector in case cluster doesn't support it
15f218
15f218
584092ce7d04 webUI: consolidate backward compatibility code
15f218
---
15f218
 pcsd/cluster_entity.rb        |   2 +-
15f218
 pcsd/pcs.rb                   |  20 ++++-
15f218
 pcsd/pcsd.rb                  | 169 +++++++++++++++++++++++++++++++++++++-----
15f218
 pcsd/public/js/nodes-ember.js |  11 ++-
15f218
 pcsd/remote.rb                |   6 +-
15f218
 pcsd/views/main.erb           |  20 ++---
15f218
 6 files changed, 194 insertions(+), 34 deletions(-)
15f218
15f218
diff --git a/pcsd/cluster_entity.rb b/pcsd/cluster_entity.rb
15f218
index 4ffcd4b..b8f363a 100644
15f218
--- a/pcsd/cluster_entity.rb
15f218
+++ b/pcsd/cluster_entity.rb
15f218
@@ -120,7 +120,7 @@ module ClusterEntity
15f218
       status = ClusterEntity::CRMResourceStatus.new
15f218
       status.id = primitive.id
15f218
       status.resource_agent = primitive.agentname
15f218
-      status.managed = false
15f218
+      status.managed = true
15f218
       status.failed = resource[:failed]
15f218
       status.role = nil
15f218
       status.active = resource[:active]
15f218
diff --git a/pcsd/pcs.rb b/pcsd/pcs.rb
15f218
index 137bb3d..e05f3ef 100644
15f218
--- a/pcsd/pcs.rb
15f218
+++ b/pcsd/pcs.rb
15f218
@@ -1864,7 +1864,7 @@ end
15f218
 def status_v1_to_v2(status)
15f218
   new_status = status.select { |k,_|
15f218
     [:cluster_name, :username, :is_cman_with_udpu_transport,
15f218
-     :need_ring1_address, :cluster_settings, :constraints, :groups,
15f218
+     :need_ring1_address, :cluster_settings, :constraints,
15f218
      :corosync_online, :corosync_offline, :pacemaker_online, :pacemaker_standby,
15f218
      :pacemaker_offline, :acls, :fence_levels
15f218
     ].include?(k)
15f218
@@ -1885,6 +1885,8 @@ def status_v1_to_v2(status)
15f218
     ].include?(k)
15f218
   }
15f218
 
15f218
+  new_status[:groups] = get_group_list_from_tree_of_resources(resources)
15f218
+
15f218
   new_status[:node].update(
15f218
     {
15f218
       :id => status[:node_id],
15f218
@@ -1901,6 +1903,22 @@ def status_v1_to_v2(status)
15f218
   return new_status
15f218
 end
15f218
 
15f218
+def get_group_list_from_tree_of_resources(tree)
15f218
+  group_list = []
15f218
+  tree.each { |resource|
15f218
+    if resource.instance_of?(ClusterEntity::Group)
15f218
+      group_list << resource.id
15f218
+    end
15f218
+    if (
15f218
+      resource.kind_of?(ClusterEntity::MultiInstance) and
15f218
+      resource.member.instance_of?(ClusterEntity::Group)
15f218
+    )
15f218
+      group_list << resource.member.id
15f218
+    end
15f218
+  }
15f218
+  return group_list
15f218
+end
15f218
+
15f218
 def allowed_for_local_cluster(auth_user, action)
15f218
   pcs_config = PCSConfig.new(Cfgsync::PcsdSettings.from_file().text())
15f218
   return pcs_config.permissions_local.allows?(
15f218
diff --git a/pcsd/pcsd.rb b/pcsd/pcsd.rb
15f218
index 287cf03..dcfd5a0 100644
15f218
--- a/pcsd/pcsd.rb
15f218
+++ b/pcsd/pcsd.rb
15f218
@@ -908,7 +908,7 @@ already been added to pcsd.  You may not add two clusters with the same name int
15f218
             'type' => 'boolean',
15f218
             'shortdesc' => 'Should deleted actions be cancelled',
15f218
             'longdesc' => 'Should deleted actions be cancelled',
15f218
-            'readable_name' => 'top Orphan Actions',
15f218
+            'readable_name' => 'Stop Orphan Actions',
15f218
             'advanced' => false
15f218
           },
15f218
           'start-failure-is-fatal' => {
15f218
@@ -1215,33 +1215,168 @@ already been added to pcsd.  You may not add two clusters with the same name int
15f218
     return [200, "Node added successfully."]
15f218
   end
15f218
 
15f218
+  def pcs_0_9_142_resource_change_group(auth_user, params)
15f218
+    parameters = {
15f218
+      :resource_id => params[:resource_id],
15f218
+      :resource_group => '',
15f218
+      :_orig_resource_group => '',
15f218
+    }
15f218
+    parameters[:resource_group] = params[:group_id] if params[:group_id]
15f218
+    if params[:old_group_id]
15f218
+      parameters[:_orig_resource_group] = params[:old_group_id]
15f218
+    end
15f218
+    return send_cluster_request_with_token(
15f218
+      auth_user, params[:cluster], 'update_resource', true, parameters
15f218
+    )
15f218
+  end
15f218
+
15f218
+  def pcs_0_9_142_resource_clone(auth_user, params)
15f218
+    parameters = {
15f218
+      :resource_id => params[:resource_id],
15f218
+      :resource_clone => true,
15f218
+      :_orig_resource_clone => 'false',
15f218
+    }
15f218
+    return send_cluster_request_with_token(
15f218
+      auth_user, params[:cluster], 'update_resource', true, parameters
15f218
+    )
15f218
+  end
15f218
+
15f218
+  def pcs_0_9_142_resource_unclone(auth_user, params)
15f218
+    parameters = {
15f218
+      :resource_id => params[:resource_id],
15f218
+      :resource_clone => nil,
15f218
+      :_orig_resource_clone => 'true',
15f218
+    }
15f218
+    return send_cluster_request_with_token(
15f218
+      auth_user, params[:cluster], 'update_resource', true, parameters
15f218
+    )
15f218
+  end
15f218
+
15f218
+  def pcs_0_9_142_resource_master(auth_user, params)
15f218
+    parameters = {
15f218
+      :resource_id => params[:resource_id],
15f218
+      :resource_ms => true,
15f218
+      :_orig_resource_ms => 'false',
15f218
+    }
15f218
+    return send_cluster_request_with_token(
15f218
+      auth_user, params[:cluster], 'update_resource', true, parameters
15f218
+    )
15f218
+  end
15f218
+
15f218
+  # There is a bug in pcs-0.9.138 and older in processing the standby and
15f218
+  # unstandby request. JS of that pcsd always sent nodename in "node"
15f218
+  # parameter, which caused pcsd daemon to run the standby command locally with
15f218
+  # param["node"] as node name. This worked fine if the local cluster was
15f218
+  # managed from JS, as pacemaker simply put the requested node into standby.
15f218
+  # However it didn't work for managing non-local clusters, as the command was
15f218
+  # run on the local cluster everytime. Pcsd daemon would send the request to a
15f218
+  # remote cluster if the param["name"] variable was set, and that never
15f218
+  # happened. That however wouldn't work either, as then the required parameter
15f218
+  # "node" wasn't sent in the request causing an exception on the receiving
15f218
+  # node. This is fixed in commit 053f63ca109d9ef9e7f0416e90aab8e140480f5b
15f218
+  #
15f218
+  # In order to be able to put nodes running pcs-0.9.138 into standby, the
15f218
+  # nodename must be sent in "node" param, and the "name" must not be sent.
15f218
+  def pcs_0_9_138_node_standby(auth_user, params)
15f218
+    translated_params = {
15f218
+      'node' => params[:name],
15f218
+    }
15f218
+    return send_cluster_request_with_token(
15f218
+      auth_user, params[:cluster], 'node_standby', true, translated_params
15f218
+    )
15f218
+  end
15f218
+
15f218
+  def pcs_0_9_138_node_unstandby(auth_user, params)
15f218
+    translated_params = {
15f218
+      'node' => params[:name],
15f218
+    }
15f218
+    return send_cluster_request_with_token(
15f218
+      auth_user, params[:cluster], 'node_unstandby', true, translated_params
15f218
+    )
15f218
+  end
15f218
+
15f218
   post '/managec/:cluster/?*' do
15f218
     auth_user = PCSAuth.sessionToAuthUser(session)
15f218
     raw_data = request.env["rack.input"].read
15f218
     if params[:cluster]
15f218
       request = "/" + params[:splat].join("/")
15f218
-      code, out = send_cluster_request_with_token(
15f218
-        auth_user, params[:cluster], request, true, params, true, raw_data
15f218
-      )
15f218
 
15f218
       # backward compatibility layer BEGIN
15f218
-      # This code correctly remove constraints on pcs/pcsd version 0.9.137 and older
15f218
-      redirection = {
15f218
-          "/remove_constraint_remote" => "/resource_cmd/rm_constraint",
15f218
-          "/remove_constraint_rule_remote" => "/resource_cmd/rm_constraint_rule"
15f218
+      translate_for_version = {
15f218
+        '/node_standby' => [
15f218
+          [[0, 9, 138], method(:pcs_0_9_138_node_standby)],
15f218
+        ],
15f218
+        '/node_unstandby' => [
15f218
+          [[0, 9, 138], method(:pcs_0_9_138_node_unstandby)],
15f218
+        ],
15f218
       }
15f218
-      if code == 404 and redirection.key?(request)
15f218
+      if translate_for_version.key?(request)
15f218
+        target_pcsd_version = [0, 0, 0]
15f218
+        version_code, version_out = send_cluster_request_with_token(
15f218
+          auth_user, params[:cluster], 'get_sw_versions'
15f218
+        )
15f218
+        if version_code == 200
15f218
+          begin
15f218
+            versions = JSON.parse(version_out)
15f218
+            target_pcsd_version = versions['pcs'] if versions['pcs']
15f218
+          rescue JSON::ParserError
15f218
+          end
15f218
+        end
15f218
+        translate_function = nil
15f218
+        translate_for_version[request].each { |pair|
15f218
+          if (target_pcsd_version <=> pair[0]) != 1 # target <= pair
15f218
+            translate_function = pair[1]
15f218
+            break
15f218
+          end
15f218
+        }
15f218
+      end
15f218
+      # backward compatibility layer END
15f218
+
15f218
+      if translate_function
15f218
+        code, out = translate_function.call(auth_user, params)
15f218
+      else
15f218
         code, out = send_cluster_request_with_token(
15f218
-          auth_user,
15f218
-          params[:cluster],
15f218
-          redirection[request],
15f218
-          true,
15f218
-          params,
15f218
-          false,
15f218
-          raw_data
15f218
+          auth_user, params[:cluster], request, true, params, true, raw_data
15f218
         )
15f218
       end
15f218
-      # bcl END
15f218
+
15f218
+      # backward compatibility layer BEGIN
15f218
+      if code == 404
15f218
+        case request
15f218
+          # supported since pcs-0.9.143 (tree view of resources)
15f218
+          when '/resource_change_group'
15f218
+            code, out =  pcs_0_9_142_resource_change_group(auth_user, params)
15f218
+          # supported since pcs-0.9.143 (tree view of resources)
15f218
+          when '/resource_clone'
15f218
+            code, out = pcs_0_9_142_resource_clone(auth_user, params)
15f218
+          # supported since pcs-0.9.143 (tree view of resources)
15f218
+          when '/resource_unclone'
15f218
+            code, out = pcs_0_9_142_resource_unclone(auth_user, params)
15f218
+          # supported since pcs-0.9.143 (tree view of resources)
15f218
+          when '/resource_master'
15f218
+            code, out = pcs_0_9_142_resource_master(auth_user, params)
15f218
+          else
15f218
+            redirection = {
15f218
+              # constraints removal for pcs-0.9.137 and older
15f218
+              "/remove_constraint_remote" => "/resource_cmd/rm_constraint",
15f218
+              # constraints removal for pcs-0.9.137 and older
15f218
+              "/remove_constraint_rule_remote" => "/resource_cmd/rm_constraint_rule"
15f218
+            }
15f218
+            if redirection.key?(request)
15f218
+              code, out = send_cluster_request_with_token(
15f218
+                auth_user,
15f218
+                params[:cluster],
15f218
+                redirection[request],
15f218
+                true,
15f218
+                params,
15f218
+                false,
15f218
+                raw_data
15f218
+              )
15f218
+            end
15f218
+        end
15f218
+      end
15f218
+      # backward compatibility layer END
15f218
+
15f218
       return code, out
15f218
     end
15f218
   end
15f218
diff --git a/pcsd/public/js/nodes-ember.js b/pcsd/public/js/nodes-ember.js
15f218
index 19caf14..6ef49e2 100644
15f218
--- a/pcsd/public/js/nodes-ember.js
15f218
+++ b/pcsd/public/js/nodes-ember.js
15f218
@@ -922,6 +922,15 @@ Pcs.ResourceObj = Ember.Object.extend({
15f218
         return "";
15f218
     }
15f218
   }.property("status_val"),
15f218
+  show_group_selector: function() {
15f218
+    var parent = this.get("parent");
15f218
+    return !(
15f218
+      parent &&
15f218
+      parent.is_group &&
15f218
+      parent.get("parent") &&
15f218
+      Pcs.resourcesContainer.get("is_version_1")
15f218
+    );
15f218
+  }.property(),
15f218
 
15f218
   location_constraints: [],
15f218
   ordering_constraints: [],
15f218
@@ -1012,7 +1021,7 @@ Pcs.PrimitiveObj = Pcs.ResourceObj.extend({
15f218
   is_unmanaged: function() {
15f218
     var instance_status_list = this.get("instance_status");
15f218
     if (!instance_status_list) {
15f218
-      return false;
15f218
+      return true;
15f218
     }
15f218
     var is_managed = true;
15f218
     $.each(instance_status_list, function(_, instance_status) {
15f218
diff --git a/pcsd/remote.rb b/pcsd/remote.rb
15f218
index 7dc7951..97e63f1 100644
15f218
--- a/pcsd/remote.rb
15f218
+++ b/pcsd/remote.rb
15f218
@@ -334,9 +334,8 @@ end
15f218
 def node_standby(params, request, auth_user)
15f218
   if params[:name]
15f218
     code, response = send_request_with_token(
15f218
-      auth_user, params[:name], 'node_standby', true, {"node"=>params[:name]}
15f218
+      auth_user, params[:name], 'node_standby', true
15f218
     )
15f218
-    # data={"node"=>params[:name]} for backward compatibility with older versions of pcs/pcsd
15f218
   else
15f218
     if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
15f218
       return 403, 'Permission denied'
15f218
@@ -350,9 +349,8 @@ end
15f218
 def node_unstandby(params, request, auth_user)
15f218
   if params[:name]
15f218
     code, response = send_request_with_token(
15f218
-      auth_user, params[:name], 'node_unstandby', true, {"node"=>params[:name]}
15f218
+      auth_user, params[:name], 'node_unstandby', true
15f218
     )
15f218
-    # data={"node"=>params[:name]} for backward compatibility with older versions of pcs/pcsd
15f218
   else
15f218
     if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
15f218
       return 403, 'Permission denied'
15f218
diff --git a/pcsd/views/main.erb b/pcsd/views/main.erb
15f218
index 8de1c60..a138f68 100644
15f218
--- a/pcsd/views/main.erb
15f218
+++ b/pcsd/views/main.erb
15f218
@@ -246,7 +246,6 @@
15f218
             Current Location:
15f218
             {{resource.nodes_running_on_string}}
15f218
           
15f218
-          {{#unless old_pcsd}}
15f218
           {{#unless resource.parent}}
15f218
             
15f218
               Clone:
15f218
@@ -268,6 +267,7 @@
15f218
             
15f218
           {{else}}
15f218
             {{#if resource.parent.is_group}}
15f218
+            {{#if resource.show_group_selector}}
15f218
             
15f218
               Group:
15f218
               
15f218
@@ -275,11 +275,10 @@
15f218
               
15f218
             
15f218
             {{/if}}
15f218
-          {{/unless}}
15f218
+            {{/if}}
15f218
           {{/unless}}
15f218
         {{/if}}
15f218
         {{/unless}}
15f218
-        {{#unless old_pcsd}}
15f218
         {{#if resource.is_group}}
15f218
         {{#unless resource.parent}}
15f218
           
15f218
@@ -294,12 +293,14 @@
15f218
               <input type="button" onclick="resource_master(curResource());" value="Create master/slave">
15f218
             
15f218
           
15f218
-          
15f218
-            Group:
15f218
-            
15f218
-              <input type="button" onclick="resource_ungroup(curResource());" value="Ungroup">
15f218
-            
15f218
-          
15f218
+          {{#unless old_pcsd}}
15f218
+            
15f218
+              Group:
15f218
+              
15f218
+                <input type="button" onclick="resource_ungroup(curResource());" value="Ungroup">
15f218
+              
15f218
+            
15f218
+          {{/unless}}
15f218
         {{/unless}}
15f218
         {{/if}}
15f218
         {{#if resource.is_multi_instance}}
15f218
@@ -310,7 +311,6 @@
15f218
             
15f218
           
15f218
         {{/if}}
15f218
-        {{/unless}}
15f218
       
15f218
       {{#unless resource.stonith}}
15f218
         {{location_constraints-table constraints=resource.location_constraints}}
15f218
-- 
15f218
1.8.3.1
15f218