Blob Blame History Raw
From 52b6ec5ac3ffc03d42217f85cda4fdff0f441735 Mon Sep 17 00:00:00 2001
From: Ivan Devat <idevat@redhat.com>
Date: Fri, 11 Jan 2019 15:13:09 +0100
Subject: [PATCH] squash bz1664057 [GUI] Issues in 'create new clust

2dfc71c34bd5 refresh changed node addresses in link details

17241fa845f6 omit empty node addresses in api call

90558e69fb9f remove old err messages after successfull setup

b073db339cf2 omit "addrs" in webui api call on empty addresses
---
 pcsd/public/js/api.js                     | 10 ++--
 pcsd/public/js/cluster-setup.js           | 60 ++++++++++++++++++-----
 pcsd/public/js/dev/tests-cluster-setup.js | 25 ++++++++--
 pcsd/views/manage.erb                     |  2 +-
 4 files changed, 75 insertions(+), 22 deletions(-)

diff --git a/pcsd/public/js/api.js b/pcsd/public/js/api.js
index c6eb20d6..6c433b54 100644
--- a/pcsd/public/js/api.js
+++ b/pcsd/public/js/api.js
@@ -212,10 +212,12 @@ api.clusterSetup = function(submitData, processOptions){
   var data = {
     cluster_name: setupData.clusterName,
     nodes: setupData.nodeList.map(function(node){
-      return {
-        name: node.name,
-        addrs: node.addrs,
-      };
+      apiNode = { name: node.name };
+      var addrs = node.addrs.filter(function(addr){return addr.length > 0});
+      if (addrs.length > 0) {
+        apiNode["addrs"] = addrs;
+      }
+      return apiNode;
     }),
     transport_type: setupData.transportType,
     transport_options: setupData.transportType == "knet"
diff --git a/pcsd/public/js/cluster-setup.js b/pcsd/public/js/cluster-setup.js
index e14b314d..2b7b0a4e 100644
--- a/pcsd/public/js/cluster-setup.js
+++ b/pcsd/public/js/cluster-setup.js
@@ -50,12 +50,7 @@ clusterSetup.link.detail.create = function(transportType, nodesNames){
   var addrList = detail.find(".transport-addresses");
 
   $(nodesNames).each(function(j, nodeName){
-    var address = tools.snippet.take("transport-addr").find("tr");
-    $(".node-name", address).text(nodeName+":");
-    $(".address", address)
-      .attr("name", clusterSetup.link.detail.addressName(nodeName))
-    ;
-    $(addrList).append(address);
+    $(addrList).append(clusterSetup.link.detail.createAddress(nodeName));
   });
 
   detail.find(".options").append(
@@ -67,6 +62,34 @@ clusterSetup.link.detail.create = function(transportType, nodesNames){
   return detail;
 };
 
+clusterSetup.link.detail.createAddress = function(nodeName){
+  var address = tools.snippet.take("transport-addr").find("tr");
+  address.attr("data-transport-addr-host", nodeName)
+  $(".node-name", address).text(nodeName+":");
+  $(".address", address)
+    .attr("name", clusterSetup.link.detail.addressName(nodeName))
+  ;
+  return address;
+};
+
+clusterSetup.link.detail.refreshNodesNames = function(linkDetail, nodesNames){
+  // Is fast enough. No cache required.
+  var previousNodesNames = $.makeArray(
+    linkDetail
+      .find(".transport-addresses [data-transport-addr-host]")
+      .map(function(){return $(this).attr("data-transport-addr-host")})
+  );
+
+  var newAddresses = nodesNames.map(function(nodeName){
+    return previousNodesNames.contains(nodeName)
+      ? linkDetail.find("[data-transport-addr-host="+nodeName+"]")
+      : clusterSetup.link.detail.createAddress(nodeName)
+    ;
+  });
+
+  linkDetail.find(".transport-addresses").empty().append(newAddresses);
+};
+
 //------------------------------------------------------------------------------
 clusterSetup.netmap.updateAddLinkAbility = function(transportType, linkList){
   var addLinkButton = $("#csetup-transport-netmaps .add-link");
@@ -108,10 +131,16 @@ clusterSetup.netmap.current.get = function(){
   return $(clusterSetup.netmap.current.selector());
 };
 
-clusterSetup.netmap.current.detailList = function(){
+clusterSetup.netmap.current.detailsContainer = function(){
   return $(clusterSetup.netmap.current.selector() +" .link-detail-list");
 };
 
+clusterSetup.netmap.current.detailList = function(){
+  return $(
+    clusterSetup.netmap.current.selector() +" .link-detail-list .detail"
+  );
+};
+
 clusterSetup.netmap.current.linksContainer = function(){
   return $(clusterSetup.netmap.current.selector() +" .link-container");
 };
@@ -143,7 +172,7 @@ clusterSetup.netmap.current.createLink = function(id, nodesNames){
       .attr(clusterSetup.link.pairAttr, id)
   );
 
-  clusterSetup.netmap.current.detailList().append(
+  clusterSetup.netmap.current.detailsContainer().append(
     clusterSetup.link.detail
       .create(clusterSetup.transportType.current(), nodesNames)
       .attr(clusterSetup.link.pairAttr, id)
@@ -171,8 +200,8 @@ clusterSetup.netmap.current.setCurrentLink = function(id){
   linkList.children().each(function(){ $(this).removeClass("current") });
   linkList.children(pairSelector).addClass("current");
 
-  clusterSetup.netmap.current.detailList().find(".detail").hide();
-  clusterSetup.netmap.current.detailList().find(pairSelector).show()
+  clusterSetup.netmap.current.detailList().hide();
+  clusterSetup.netmap.current.detailsContainer().find(pairSelector).show()
   ;
 };
 
@@ -320,7 +349,7 @@ clusterSetup.data.settings = function(clusterName, nodesNames){
     {
       clusterName: clusterName,
       nodeList: clusterSetup.data.nodes(nodesNames, function(nodeName){
-        return clusterSetup.netmap.current.detailList()
+        return clusterSetup.netmap.current.detailsContainer()
           .find("[name='"+clusterSetup.link.detail.addressName(nodeName)+"']")
           .map(function(){ return $(this).val().trim() })
           .toArray()
@@ -371,7 +400,7 @@ clusterSetup.data.settings = function(clusterName, nodesNames){
     clusterSetup.transportType.current() === "knet"
 
     ? {
-      linkList: clusterSetup.netmap.current.detailList().find(".detail")
+      linkList: clusterSetup.netmap.current.detailList()
         .map(function(linknumber, form){
           return $.extend({linknumber: linknumber}, fromForm(form, [
             "ip_version",
@@ -414,7 +443,7 @@ clusterSetup.data.settings = function(clusterName, nodesNames){
       ),
       compression: {},
       crypto: {},
-      linkList: clusterSetup.netmap.current.detailList().find(".detail")
+      linkList: clusterSetup.netmap.current.detailList()
         .map(function(linknumber, form){
           return fromForm(
             form,
@@ -481,6 +510,10 @@ clusterSetup.step.clusterSettings = function(clusterName, nodesNames, actions){
 
   $("#csetup .cluster-settings").tabs();
 
+  clusterSetup.netmap.current.detailList().each(function(){
+    clusterSetup.link.detail.refreshNodesNames($(this), nodesNames);
+  });
+
   $("#csetup-transport-netmaps .add-link").unbind("click").click(function(){
     clusterSetup.netmap.current.createLink(
       clusterSetup.generateUid(),
@@ -688,6 +721,7 @@ clusterSetup.submit.run = function(useAdvancedOptions){
     );
 
   }).then(function(){
+    clusterSetup.dialog.resetMessages([]);
     return api.rememberCluster(formData.clusterName, formData.nodesNames);
 
   }).then(function(){
diff --git a/pcsd/public/js/dev/tests-cluster-setup.js b/pcsd/public/js/dev/tests-cluster-setup.js
index 54b7fbdd..b3b9f5c8 100644
--- a/pcsd/public/js/dev/tests-cluster-setup.js
+++ b/pcsd/public/js/dev/tests-cluster-setup.js
@@ -16,15 +16,16 @@ dev.utils.clusterSetupDialog.prefill = function(url, nodesNames){
     clusterSetup.submit.run(true);
 
     setTimeout(function(){
-      // dev.utils.clusterSetupDialog.prefillKnet();
+      dev.utils.clusterSetupDialog.prefillKnet();
+      dev.utils.clusterSetupDialog.prefillTransportOptionsKnet();
       dev.utils.clusterSetupDialog.prefillCompression();
       dev.utils.clusterSetupDialog.prefillCrypto();
       dev.utils.clusterSetupDialog.prefillTotem();
       dev.utils.clusterSetupDialog.prefillQuorum();
-      dev.utils.clusterSetupDialog.prefillTransportOptionsUdp("udp");
-      $("[href='#csetup-transport-options']").trigger("click");
+      // dev.utils.clusterSetupDialog.prefillTransportOptionsUdp("udp");
+      // $("[href='#csetup-transport-options']").trigger("click");
       // $("[href='#csetup-quorum']").trigger("click");
-      dev.utils.clusterSetupDialog.prefillUdp("udpu");
+      // dev.utils.clusterSetupDialog.prefillUdp("udpu");
       $(".ui-dialog:has('#csetup') button:contains('Create cluster')")
         // .trigger("click")
       ;
@@ -390,6 +391,21 @@ testClusterSetup.clusterSetupUnforcible = function(url, data, success, fail){
   }
 };
 
+testClusterSetup.clusterSetupUnforcibleFirstTime =
+function(url, data, success, fail){
+  switch(url){
+    case "/manage/cluster-setup":
+      if (dev.flags.cluster_setup_test_setup_first_time_was_run === undefined) {
+        dev.flags.cluster_setup_test_setup_first_time_was_run = true;
+        return success(
+          JSON.stringify(dev.fixture.libErrorUnforcibleLarge)
+        );
+      }
+    default:
+      return testClusterSetup.successPath(url, data, success, fail);
+  }
+};
+
 testClusterSetup.clusterSetupException = function(url, data, success, fail){
   switch(url){
     case "/manage/cluster-setup":
@@ -467,6 +483,7 @@ dev.runScenario(
   // testClusterSetup.clusterSetup403
   // testClusterSetup.clusterSetup500
   // testClusterSetup.clusterSetupUnforcible
+  // testClusterSetup.clusterSetupUnforcibleFirstTime
   // testClusterSetup.clusterSetupException
   // testClusterSetup.clusterSetupForceFail
   // testClusterSetup.clusterSetupForceFailForcible
diff --git a/pcsd/views/manage.erb b/pcsd/views/manage.erb
index 7b0c9daa..c0569d40 100644
--- a/pcsd/views/manage.erb
+++ b/pcsd/views/manage.erb
@@ -1075,7 +1075,7 @@ It is very useful when combined with Last Man Standing.
 <table data-snippet="transport-addr">
   <tr>
     <td class="node-name"></td>
-    <td><input type="text" class="address"/></td>
+    <td class="node-addr"><input type="text" class="address"/></td>
   </tr>
 </table>
 
-- 
2.17.0