Blob Blame History Raw
From aeb87c63c2f37bdc241b2c9add7cf0e9be9d7789 Mon Sep 17 00:00:00 2001
From: Marek Grac <mgrac@redhat.com>
Date: Thu, 7 Jul 2016 14:05:14 +0200
Subject: [PATCH] gui: add constraint colocation set support

---
 pcsd/pcs.rb                   | 19 ++++++++++++++++++-
 pcsd/public/js/nodes-ember.js |  9 +++++++++
 pcsd/public/js/pcsd.js        |  1 +
 pcsd/remote.rb                |  5 +++++
 pcsd/views/main.erb           | 44 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/pcsd/pcs.rb b/pcsd/pcs.rb
index 7c25e10..57082be 100644
--- a/pcsd/pcs.rb
+++ b/pcsd/pcs.rb
@@ -131,6 +131,19 @@ def add_order_set_constraint(
   return retval, stderr.join(' ')
 end
 
+def add_colocation_set_constraint(
+  auth_user, resource_set_list, force=false, autocorrect=true
+)
+  command = [PCS, "constraint", "colocation"]
+  resource_set_list.each { |resource_set|
+    command << "set"
+    command.concat(resource_set)
+  }
+  command << '--force' if force
+  command << '--autocorrect' if autocorrect
+  stdout, stderr, retval = run_cmd(auth_user, *command)
+  return retval, stderr.join(' ')
+end
 
 def add_ticket_constraint(
     auth_user, ticket, resource_id, role, loss_policy,
@@ -1681,7 +1694,11 @@ def get_node_status(auth_user, cib_dom)
       :node_attr => node_attrs_to_v2(get_node_attributes(auth_user, cib_dom)),
       :nodes_utilization => get_nodes_utilization(cib_dom),
       :known_nodes => [],
-      :available_features => ['sbd', 'ticket_constraints']
+      :available_features => [
+        'constraint_colocation_set',
+        'sbd',
+        'ticket_constraints',
+      ]
   }
 
   nodes = get_nodes_status()
diff --git a/pcsd/public/js/nodes-ember.js b/pcsd/public/js/nodes-ember.js
index bf1bb92..cb62806 100644
--- a/pcsd/public/js/nodes-ember.js
+++ b/pcsd/public/js/nodes-ember.js
@@ -47,6 +47,11 @@ Pcs = Ember.Application.createWithMixins({
       this.get("available_features").indexOf("ticket_constraints") != -1
     );
   }.property("available_features"),
+  is_supported_constraint_colocation_set: function() {
+    return (
+      this.get("available_features").indexOf("constraint_colocation_set") != -1
+    );
+  }.property("available_features"),
   is_sbd_running: false,
   is_sbd_enabled: false,
   is_sbd_enabled_or_running: function() {
@@ -767,6 +772,7 @@ Pcs.ResourceObj = Ember.Object.extend({
   ordering_constraints: [],
   ordering_set_constraints: [],
   colocation_constraints: [],
+  colocation_set_constraints: [],
 
   get_map: function() {
     var self = this;
@@ -2381,6 +2387,7 @@ function constraint_resort(constraints){
       ordering_constraints: {},
       ordering_set_constraints: {},
       colocation_constraints: {},
+      colocation_set_constraints: {},
     };
   }
 
@@ -2391,6 +2398,7 @@ function constraint_resort(constraints){
 
   var colocations = constraint_resort_part(constraints.rsc_colocation, {
     plain: constraint_colocation_create_resource_keyed_map,
+    with_sets: constraint_set_create_resource_keyed_map,
   });
 
   var locations = constraint_resort_part(constraints.rsc_location, {
@@ -2409,5 +2417,6 @@ function constraint_resort(constraints){
     ticket_constraints: tickets.plain,
     ticket_set_constraints: tickets.with_sets,
     colocation_constraints: colocations.plain,
+    colocation_set_constraints: colocations.with_sets,
   };
 }
diff --git a/pcsd/public/js/pcsd.js b/pcsd/public/js/pcsd.js
index 41c481e..6c88888 100644
--- a/pcsd/public/js/pcsd.js
+++ b/pcsd/public/js/pcsd.js
@@ -2046,6 +2046,7 @@ function auto_show_hide_constraints() {
     "ordering_constraints",
     "ordering_set_constraints",
     "colocation_constraints",
+    "colocation_set_constraints",
     "ticket_constraints",
     "ticket_set_constraints",
     "meta_attributes",
diff --git a/pcsd/remote.rb b/pcsd/remote.rb
index b1e00fa..75c9465 100644
--- a/pcsd/remote.rb
+++ b/pcsd/remote.rb
@@ -1821,6 +1821,11 @@ def add_constraint_set_remote(params, request, auth_user)
       auth_user,
       params["resources"].values, params["force"], !params['disable_autocorrect']
     )
+  when "col"
+    retval, error = add_colocation_set_constraint(
+      auth_user,
+      params["resources"].values, params["force"], !params['disable_autocorrect']
+    )
   when "ticket"
     unless params["options"]["ticket"]
       return [400, "Error adding constraint ticket: option ticket missing"]
diff --git a/pcsd/views/main.erb b/pcsd/views/main.erb
index 5461515..52c1900 100644
--- a/pcsd/views/main.erb
+++ b/pcsd/views/main.erb
@@ -291,6 +291,9 @@
         {{ordering_constraints-table constraints=resource.ordering_constraints resource_id=resource._id}}
         {{ordering_set_constraints-table constraints=resource.ordering_set_constraints}}
         {{colocation_constraints-table constraints=resource.colocation_constraints}}
+        {{#if Pcs.is_supported_constraint_colocation_set}}
+          {{colocation_set_constraints-table constraints=resource.colocation_set_constraints}}
+        {{/if}}
         {{#if Pcs.is_ticket_constraints_supported}}
           {{ticket_constraints-table constraints=resource.ticket_constraints resource_id=resource._id}}
           {{ticket_set_constraints-table constraints=resource.ticket_set_constraints}}
@@ -696,6 +699,47 @@ Use the 'Add' button to submit the form.">
 	      </table>
   </script>
 
+  <script type="text/x-handlebars" data-template-name="components/colocation_set_constraints-table">
+    <table style="clear:left;float:left;">
+          <tr><td style="display: block;" onclick="show_hide_constraints(this)" class="datatable_header hover-pointer" id="colocation_set_constraints"><span style="" class="downarrow sprites"></span><span style="display: none;" class="rightarrow sprites"></span>Resource Colocation Set Preferences ({{#if constraints.length}}{{constraints.length}}{{else}}0{{/if}})</td></tr>
+          <tr><td>
+            <div id="locationdep">
+              <table class="datatable">
+                <tr>
+                  <th>Preference Name/Set of Resources</th>
+                  <th style="text-align: center;">Remove</th>
+                </tr>
+                {{#each cons in constraints}}
+                <tr>
+                  <td>{{cons.id}}</td>
+                  <td {{bind-attr constraint_id="cons.id"}} style="text-align:center;">
+                    <a onclick="return remove_constraint_action(this);" href="#" class="remove">X</a>
+                  </td>
+                </tr>
+                {{#each set in cons.sets}}
+                <tr>
+                  <td style="padding-left:2em;">Set:{{#each rsc in set.resources}} {{rsc}}{{/each}}</td>
+                  <td></td>
+                </tr>
+                {{/each}}
+                {{else}}
+                <tr><td style="color: gray;">NONE</td><td></td></tr>
+                {{/each}}
+                <tr id="new_res_col_set" title="Enter the resources you want to be in one set into the 'Set' field separated by space.
+Use the 'New Set' button to create more sets.
+Use the 'Add' button to submit the form.">
+                  <td>Set: <input type="text" name="resource_ids[]"></td>
+                  <td style="vertical-align: bottom;">
+                    <button type="button" onclick="new_constraint_set_row('#new_res_col_set');" name="new-row">New Set</button>
+                    <button type="button" onclick="add_constraint_set('#new_res_col_set', 'col', false);" name="add">Add</button>
+                  </td>
+                </tr>
+              </table>
+            </div>
+          </td></tr>
+        </table>
+  </script>
+
   <script type="text/x-handlebars" data-template-name="components/meta_attributes-table">
     <table style="clear:left;float:left">
 		<tr><td onclick="show_hide_constraints(this)" class="datatable_header hover-pointer" id="meta_attributes"><span style="" class="downarrow sprites"></span><span style="display: none;" class="rightarrow sprites"></span>Resource Meta Attributes ({{#if resource.meta_attr.length}}{{resource.meta_attr.length}}{{else}}0{{/if}})</td></tr>
-- 
1.8.3.1