Blame SOURCES/bz1281364-01-gui-add-constraint-colocation-set-support.patch

15f218
From aeb87c63c2f37bdc241b2c9add7cf0e9be9d7789 Mon Sep 17 00:00:00 2001
15f218
From: Marek Grac <mgrac@redhat.com>
15f218
Date: Thu, 7 Jul 2016 14:05:14 +0200
15f218
Subject: [PATCH] gui: add constraint colocation set support
15f218
15f218
---
15f218
 pcsd/pcs.rb                   | 19 ++++++++++++++++++-
15f218
 pcsd/public/js/nodes-ember.js |  9 +++++++++
15f218
 pcsd/public/js/pcsd.js        |  1 +
15f218
 pcsd/remote.rb                |  5 +++++
15f218
 pcsd/views/main.erb           | 44 +++++++++++++++++++++++++++++++++++++++++++
15f218
 5 files changed, 77 insertions(+), 1 deletion(-)
15f218
15f218
diff --git a/pcsd/pcs.rb b/pcsd/pcs.rb
15f218
index 7c25e10..57082be 100644
15f218
--- a/pcsd/pcs.rb
15f218
+++ b/pcsd/pcs.rb
15f218
@@ -131,6 +131,19 @@ def add_order_set_constraint(
15f218
   return retval, stderr.join(' ')
15f218
 end
15f218
 
15f218
+def add_colocation_set_constraint(
15f218
+  auth_user, resource_set_list, force=false, autocorrect=true
15f218
+)
15f218
+  command = [PCS, "constraint", "colocation"]
15f218
+  resource_set_list.each { |resource_set|
15f218
+    command << "set"
15f218
+    command.concat(resource_set)
15f218
+  }
15f218
+  command << '--force' if force
15f218
+  command << '--autocorrect' if autocorrect
15f218
+  stdout, stderr, retval = run_cmd(auth_user, *command)
15f218
+  return retval, stderr.join(' ')
15f218
+end
15f218
 
15f218
 def add_ticket_constraint(
15f218
     auth_user, ticket, resource_id, role, loss_policy,
15f218
@@ -1681,7 +1694,11 @@ def get_node_status(auth_user, cib_dom)
15f218
       :node_attr => node_attrs_to_v2(get_node_attributes(auth_user, cib_dom)),
15f218
       :nodes_utilization => get_nodes_utilization(cib_dom),
15f218
       :known_nodes => [],
15f218
-      :available_features => ['sbd', 'ticket_constraints']
15f218
+      :available_features => [
15f218
+        'constraint_colocation_set',
15f218
+        'sbd',
15f218
+        'ticket_constraints',
15f218
+      ]
15f218
   }
15f218
 
15f218
   nodes = get_nodes_status()
15f218
diff --git a/pcsd/public/js/nodes-ember.js b/pcsd/public/js/nodes-ember.js
15f218
index bf1bb92..cb62806 100644
15f218
--- a/pcsd/public/js/nodes-ember.js
15f218
+++ b/pcsd/public/js/nodes-ember.js
15f218
@@ -47,6 +47,11 @@ Pcs = Ember.Application.createWithMixins({
15f218
       this.get("available_features").indexOf("ticket_constraints") != -1
15f218
     );
15f218
   }.property("available_features"),
15f218
+  is_supported_constraint_colocation_set: function() {
15f218
+    return (
15f218
+      this.get("available_features").indexOf("constraint_colocation_set") != -1
15f218
+    );
15f218
+  }.property("available_features"),
15f218
   is_sbd_running: false,
15f218
   is_sbd_enabled: false,
15f218
   is_sbd_enabled_or_running: function() {
15f218
@@ -767,6 +772,7 @@ Pcs.ResourceObj = Ember.Object.extend({
15f218
   ordering_constraints: [],
15f218
   ordering_set_constraints: [],
15f218
   colocation_constraints: [],
15f218
+  colocation_set_constraints: [],
15f218
 
15f218
   get_map: function() {
15f218
     var self = this;
15f218
@@ -2381,6 +2387,7 @@ function constraint_resort(constraints){
15f218
       ordering_constraints: {},
15f218
       ordering_set_constraints: {},
15f218
       colocation_constraints: {},
15f218
+      colocation_set_constraints: {},
15f218
     };
15f218
   }
15f218
 
15f218
@@ -2391,6 +2398,7 @@ function constraint_resort(constraints){
15f218
 
15f218
   var colocations = constraint_resort_part(constraints.rsc_colocation, {
15f218
     plain: constraint_colocation_create_resource_keyed_map,
15f218
+    with_sets: constraint_set_create_resource_keyed_map,
15f218
   });
15f218
 
15f218
   var locations = constraint_resort_part(constraints.rsc_location, {
15f218
@@ -2409,5 +2417,6 @@ function constraint_resort(constraints){
15f218
     ticket_constraints: tickets.plain,
15f218
     ticket_set_constraints: tickets.with_sets,
15f218
     colocation_constraints: colocations.plain,
15f218
+    colocation_set_constraints: colocations.with_sets,
15f218
   };
15f218
 }
15f218
diff --git a/pcsd/public/js/pcsd.js b/pcsd/public/js/pcsd.js
15f218
index 41c481e..6c88888 100644
15f218
--- a/pcsd/public/js/pcsd.js
15f218
+++ b/pcsd/public/js/pcsd.js
15f218
@@ -2046,6 +2046,7 @@ function auto_show_hide_constraints() {
15f218
     "ordering_constraints",
15f218
     "ordering_set_constraints",
15f218
     "colocation_constraints",
15f218
+    "colocation_set_constraints",
15f218
     "ticket_constraints",
15f218
     "ticket_set_constraints",
15f218
     "meta_attributes",
15f218
diff --git a/pcsd/remote.rb b/pcsd/remote.rb
15f218
index b1e00fa..75c9465 100644
15f218
--- a/pcsd/remote.rb
15f218
+++ b/pcsd/remote.rb
15f218
@@ -1821,6 +1821,11 @@ def add_constraint_set_remote(params, request, auth_user)
15f218
       auth_user,
15f218
       params["resources"].values, params["force"], !params['disable_autocorrect']
15f218
     )
15f218
+  when "col"
15f218
+    retval, error = add_colocation_set_constraint(
15f218
+      auth_user,
15f218
+      params["resources"].values, params["force"], !params['disable_autocorrect']
15f218
+    )
15f218
   when "ticket"
15f218
     unless params["options"]["ticket"]
15f218
       return [400, "Error adding constraint ticket: option ticket missing"]
15f218
diff --git a/pcsd/views/main.erb b/pcsd/views/main.erb
15f218
index 5461515..52c1900 100644
15f218
--- a/pcsd/views/main.erb
15f218
+++ b/pcsd/views/main.erb
15f218
@@ -291,6 +291,9 @@
15f218
         {{ordering_constraints-table constraints=resource.ordering_constraints resource_id=resource._id}}
15f218
         {{ordering_set_constraints-table constraints=resource.ordering_set_constraints}}
15f218
         {{colocation_constraints-table constraints=resource.colocation_constraints}}
15f218
+        {{#if Pcs.is_supported_constraint_colocation_set}}
15f218
+          {{colocation_set_constraints-table constraints=resource.colocation_set_constraints}}
15f218
+        {{/if}}
15f218
         {{#if Pcs.is_ticket_constraints_supported}}
15f218
           {{ticket_constraints-table constraints=resource.ticket_constraints resource_id=resource._id}}
15f218
           {{ticket_set_constraints-table constraints=resource.ticket_set_constraints}}
15f218
@@ -696,6 +699,47 @@ Use the 'Add' button to submit the form.">
15f218
 	      
15f218
   </script>
15f218
 
15f218
+  <script type="text/x-handlebars" data-template-name="components/colocation_set_constraints-table">
15f218
+    
15f218
+          Resource Colocation Set Preferences ({{#if constraints.length}}{{constraints.length}}{{else}}0{{/if}})
15f218
+          
15f218
+            
15f218
+              
15f218
+                
15f218
+                  Preference Name/Set of Resources
15f218
+                  Remove
15f218
+                
15f218
+                {{#each cons in constraints}}
15f218
+                
15f218
+                  {{cons.id}}
15f218
+                  
15f218
+                    X
15f218
+                  
15f218
+                
15f218
+                {{#each set in cons.sets}}
15f218
+                
15f218
+                  Set:{{#each rsc in set.resources}} {{rsc}}{{/each}}
15f218
+                  
15f218
+                
15f218
+                {{/each}}
15f218
+                {{else}}
15f218
+                NONE
15f218
+                {{/each}}
15f218
+                
15f218
+Use the 'New Set' button to create more sets.
15f218
+Use the 'Add' button to submit the form.">
15f218
+                  Set: <input type="text" name="resource_ids[]">
15f218
+                  
15f218
+                    <button type="button" onclick="new_constraint_set_row('#new_res_col_set');" name="new-row">New Set</button>
15f218
+                    <button type="button" onclick="add_constraint_set('#new_res_col_set', 'col', false);" name="add">Add</button>
15f218
+                  
15f218
+                
15f218
+              
15f218
+            
15f218
+          
15f218
+        
15f218
+  </script>
15f218
+
15f218
   <script type="text/x-handlebars" data-template-name="components/meta_attributes-table">
15f218
     
15f218
 		Resource Meta Attributes ({{#if resource.meta_attr.length}}{{resource.meta_attr.length}}{{else}}0{{/if}})
15f218
-- 
15f218
1.8.3.1
15f218