Преглед изворни кода

AMBARI-6997. FE: Add service wizard does not provide current host-layout for recommendations

Srimanth Gunturi пре 10 година
родитељ
комит
bd2e516211

+ 0 - 7
ambari-web/app/controllers/installer.js

@@ -761,13 +761,6 @@ App.InstallerController = App.WizardController.extend({
       var step = this.get('isStepDisabled').findProperty('step', i);
       var step = this.get('isStepDisabled').findProperty('step', i);
       step.set('value', true);
       step.set('value', true);
     }
     }
-  },
-
-  /**
-   * Clear loaded recommendations
-   */
-  clearRecommendations: function() {
-    this.set('content.recommendations', undefined)
   }
   }
 });
 });
 
 

+ 25 - 4
ambari-web/app/controllers/wizard/step5_controller.js

@@ -17,10 +17,11 @@
  */
  */
 
 
 var App = require('app');
 var App = require('app');
+var blueprintUtils = require('utils/blueprint');
 var numberUtils = require('utils/number_utils');
 var numberUtils = require('utils/number_utils');
 var validationUtils = require('utils/validator');
 var validationUtils = require('utils/validator');
 
 
-App.WizardStep5Controller = Em.Controller.extend({
+App.WizardStep5Controller = Em.Controller.extend(App.BlueprintMixin, {
 
 
   name: "wizardStep5Controller",
   name: "wizardStep5Controller",
 
 
@@ -52,6 +53,14 @@ App.WizardStep5Controller = Em.Controller.extend({
     return this.get('content.controllerName') == 'highAvailabilityWizardController';
     return this.get('content.controllerName') == 'highAvailabilityWizardController';
   }.property('content.controllerName'),
   }.property('content.controllerName'),
 
 
+  /**
+   * Check if <code>installerWizard</code> used
+   * @type {bool}
+   */
+  isInstallerWizard: function () {
+    return this.get('content.controllerName') === 'installerController';
+  }.property('content.controllerName'),
+
   /**
   /**
    * Is AddServiceWizard used
    * Is AddServiceWizard used
    * @type {bool}
    * @type {bool}
@@ -154,6 +163,15 @@ App.WizardStep5Controller = Em.Controller.extend({
     return this.get('servicesMasters').some(function(m) { return m.get('warnMessage'); }) || this.get('generalWarningMessages').some(function(m) { return m; });
     return this.get('servicesMasters').some(function(m) { return m.get('warnMessage'); }) || this.get('generalWarningMessages').some(function(m) { return m; });
   }.property('servicesMasters.@each.warnMessage', 'generalWarningMessages'),
   }.property('servicesMasters.@each.warnMessage', 'generalWarningMessages'),
 
 
+    /**
+   * Clear loaded recommendations
+   */
+  clearRecommendations: function() {
+    if (this.get('content.recommendations')) {
+      this.set('content.recommendations', null);
+    }
+  },
+
   /**
   /**
    * List of host with assigned masters
    * List of host with assigned masters
    * Format:
    * Format:
@@ -223,7 +241,7 @@ App.WizardStep5Controller = Em.Controller.extend({
       self.set('submitDisabled', true);
       self.set('submitDisabled', true);
 
 
       // reset previous recommendations
       // reset previous recommendations
-      this.set('content.recommendations', null);
+      this.clearRecommendations();
 
 
       if (self.get('servicesMasters').length === 0) {
       if (self.get('servicesMasters').length === 0) {
         return;
         return;
@@ -326,7 +344,7 @@ App.WizardStep5Controller = Em.Controller.extend({
   },
   },
 
 
   /**
   /**
-   * Composes selected values of comboboxes into blueprint format
+   * Composes selected values of comboboxes into master blueprint + merge it with currenlty installed slave blueprint
    */
    */
   getCurrentBlueprint: function() {
   getCurrentBlueprint: function() {
     var self = this;
     var self = this;
@@ -359,7 +377,7 @@ App.WizardStep5Controller = Em.Controller.extend({
       res.blueprint_cluster_binding.host_groups.push(binding);
       res.blueprint_cluster_binding.host_groups.push(binding);
     });
     });
 
 
-    return res;
+    return blueprintUtils.mergeBlueprints(res, self.getCurrentSlaveBlueprint());
   },
   },
 
 
 /**
 /**
@@ -506,7 +524,10 @@ App.WizardStep5Controller = Em.Controller.extend({
       };
       };
 
 
       if (includeMasters) {
       if (includeMasters) {
+        // Made partial recommendation request for reflect in blueprint host-layout changes which were made by user in UI
         data.recommendations = self.getCurrentBlueprint();
         data.recommendations = self.getCurrentBlueprint();
+      } else if (!self.get('isInstallerWizard')) {
+        data.recommendations = self.getCurrentMasterSlaveBlueprint();
       }
       }
 
 
       return App.ajax.send({
       return App.ajax.send({

+ 2 - 33
ambari-web/app/controllers/wizard/step6_controller.js

@@ -34,7 +34,7 @@ var validationUtils = require('utils/validator');
  *   slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  *   slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  *
  *
  */
  */
-App.WizardStep6Controller = Em.Controller.extend({
+App.WizardStep6Controller = Em.Controller.extend(App.BlueprintMixin, {
 
 
   /**
   /**
    * List of hosts
    * List of hosts
@@ -557,7 +557,7 @@ App.WizardStep6Controller = Em.Controller.extend({
       var invisibleBlueprint = blueprintUtils.filterByComponents(this.get('content.recommendations'), invisibleComponents);
       var invisibleBlueprint = blueprintUtils.filterByComponents(this.get('content.recommendations'), invisibleComponents);
       masterBlueprint = blueprintUtils.mergeBlueprints(masterBlueprint, invisibleBlueprint);
       masterBlueprint = blueprintUtils.mergeBlueprints(masterBlueprint, invisibleBlueprint);
     } else if (this.get('isAddHostWizard')) {
     } else if (this.get('isAddHostWizard')) {
-      masterBlueprint = self.getMasterSlaveBlueprintForAddHostWizard();
+      masterBlueprint = self.getCurrentMasterSlaveBlueprint();
       hostNames = hostNames.concat(App.Host.find().mapProperty("hostName")).uniq();
       hostNames = hostNames.concat(App.Host.find().mapProperty("hostName")).uniq();
       slaveBlueprint = blueprintUtils.addComponentsToBlueprint(slaveBlueprint, invisibleSlaves);
       slaveBlueprint = blueprintUtils.addComponentsToBlueprint(slaveBlueprint, invisibleSlaves);
     }
     }
@@ -724,37 +724,6 @@ App.WizardStep6Controller = Em.Controller.extend({
     return res;
     return res;
   },
   },
 
 
-  getMasterSlaveBlueprintForAddHostWizard: function () {
-    var components = App.HostComponent.find();
-    var hosts = components.mapProperty("hostName").uniq();
-
-    var res = {
-      blueprint: { host_groups: [] },
-      blueprint_cluster_binding: { host_groups: [] }
-    };
-
-    var i = 0;
-    hosts.forEach(function (host) {
-      i += 1;
-      var group_name = 'host-group-' + i;
-
-      res.blueprint.host_groups.push({
-        name: group_name,
-        components: components.filterProperty("hostName", host).mapProperty("componentName").map(function (c) {
-          return { name: c };
-        })
-      });
-
-      res.blueprint_cluster_binding.host_groups.push({
-        name: group_name,
-        hosts: [
-          { fqdn: host }
-        ]
-      });
-    });
-    return res;
-  },
-
   /**
   /**
    * callClientSideValidation form. Return do we have errors or not
    * callClientSideValidation form. Return do we have errors or not
    * @return {bool}
    * @return {bool}

+ 1 - 0
ambari-web/app/mixins.js

@@ -19,6 +19,7 @@
 
 
 // load all mixins here
 // load all mixins here
 
 
+require('mixins/common/blueprint');
 require('mixins/common/localStorage');
 require('mixins/common/localStorage');
 require('mixins/common/userPref');
 require('mixins/common/userPref');
 require('mixins/common/serverValidator');
 require('mixins/common/serverValidator');

+ 70 - 0
ambari-web/app/mixins/common/blueprint.js

@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+var blueprintUtils = require('utils/blueprint');
+
+App.BlueprintMixin = Em.Mixin.create({
+  /**
+   * returns blueprint for all currenlty installed master, slave and client components
+   */
+  getCurrentMasterSlaveBlueprint: function () {
+    var components = App.HostComponent.find();
+    var hosts = components.mapProperty("hostName").uniq();
+
+    var res = {
+      blueprint: { host_groups: [] },
+      blueprint_cluster_binding: { host_groups: [] }
+    };
+
+    var i = 0;
+    hosts.forEach(function (host) {
+      i += 1;
+      var group_name = 'host-group-' + i;
+
+      res.blueprint.host_groups.push({
+        name: group_name,
+        components: components.filterProperty("hostName", host).mapProperty("componentName").map(function (c) {
+          return { name: c };
+        })
+      });
+
+      res.blueprint_cluster_binding.host_groups.push({
+        name: group_name,
+        hosts: [
+          { fqdn: host }
+        ]
+      });
+    });
+    return res;
+  },
+
+  /**
+   * returns blueprint for all currenlty installed slave and client components
+   */
+  getCurrentSlaveBlueprint: function () {
+    var self = this;
+    var fullBlueprint = self.getCurrentMasterSlaveBlueprint();
+
+    var slaveComponents = App.StackServiceComponent.find().filterProperty("isSlave").mapProperty("componentName");
+    var clientComponents = App.StackServiceComponent.find().filterProperty("isClient").mapProperty("componentName");
+    var slaveAndClientComponents = slaveComponents.concat(clientComponents);
+
+    return blueprintUtils.filterByComponents(fullBlueprint, slaveAndClientComponents);
+  }
+});

+ 2 - 2
ambari-web/app/routes/add_service_routes.js

@@ -114,8 +114,8 @@ module.exports = App.WizardRoute.extend({
       addServiceController.saveClients(wizardStep4Controller);
       addServiceController.saveClients(wizardStep4Controller);
       addServiceController.setDBProperty('masterComponentHosts', undefined);
       addServiceController.setDBProperty('masterComponentHosts', undefined);
 
 
-      var installerController = router.get('installerController');
-      installerController.clearRecommendations(); // Force reload recommendation between steps 1 and 2
+      var wizardStep5Controller = router.get('wizardStep5Controller');
+      wizardStep5Controller.clearRecommendations(); // Force reload recommendation between steps 1 and 2
       router.transitionTo('step2');
       router.transitionTo('step2');
     }
     }
   }),
   }),

+ 1 - 1
ambari-web/app/routes/installer.js

@@ -249,7 +249,7 @@ module.exports = Em.Route.extend({
       controller.saveServices(wizardStep4Controller);
       controller.saveServices(wizardStep4Controller);
       controller.saveClients(wizardStep4Controller);
       controller.saveClients(wizardStep4Controller);
 
 
-      controller.clearRecommendations(); // Force reload recommendation between steps 4 and 5
+      router.get('wizardStep5Controller').clearRecommendations(); // Force reload recommendation between steps 4 and 5
       controller.setDBProperty('recommendations', undefined);
       controller.setDBProperty('recommendations', undefined);
       controller.setDBProperty('masterComponentHosts', undefined);
       controller.setDBProperty('masterComponentHosts', undefined);
       router.transitionTo('step5');
       router.transitionTo('step5');

+ 4 - 0
ambari-web/app/utils/blueprint.js

@@ -151,6 +151,10 @@ module.exports = {
    * @param [string] components
    * @param [string] components
    */
    */
   filterByComponents: function(blueprint, components) {
   filterByComponents: function(blueprint, components) {
+    if (!blueprint) {
+      return null;
+    }
+
     var res = JSON.parse(JSON.stringify(blueprint))
     var res = JSON.parse(JSON.stringify(blueprint))
     var emptyGroups = [];
     var emptyGroups = [];