Browse Source

AMBARI-1145. Cluster Management refactoring. (yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1431778 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako 12 years ago
parent
commit
1e8c9308b5

+ 2 - 2
ambari-web/app/controllers/installer.js

@@ -39,11 +39,11 @@ App.InstallerController = App.WizardController.extend({
   }),
 
   getCluster: function(){
-    return jQuery.extend(this.get('clusterStatusTemplate'), {});
+    return jQuery.extend({}, this.get('clusterStatusTemplate'));
   },
 
   getInstallOptions: function(){
-    return jQuery.extend(this.get('installOptionsTemplate'), {});
+    return jQuery.extend({}, this.get('installOptionsTemplate'));
   },
 
   getHosts: function(){

+ 2 - 4
ambari-web/app/controllers/main/host/add_controller.js

@@ -55,12 +55,10 @@ App.AddHostController = App.WizardController.extend({
   }),
 
   getCluster: function(){
-    return jQuery.extend(this.get('clusterStatusTemplate'), {
-      name: App.router.getClusterName()
-    });
+    return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
   },
   getInstallOptions: function(){
-    return jQuery.extend(this.get('installOptionsTemplate'), {});
+    return jQuery.extend({}, this.get('installOptionsTemplate'));
   },
 
   getHosts: function(){

+ 1 - 3
ambari-web/app/controllers/main/service/add_controller.js

@@ -55,9 +55,7 @@ App.AddServiceController = App.WizardController.extend({
   }),
 
   getCluster: function(){
-    return jQuery.extend(this.get('clusterStatusTemplate'), {
-      name: App.router.getClusterName()
-    });
+    return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
   },
 
   /**

+ 2 - 0
ambari-web/app/controllers/main/service/item.js

@@ -76,6 +76,7 @@ App.MainServiceItemController = Em.Controller.extend({
       primary: 'Yes',
       secondary: 'No',
       onPrimary: function () {
+        self.get('content.components').setEach('workStatus', App.Component.Status.starting);
         self.sendCommandToServer('/services/' + self.get('content.serviceName').toUpperCase(), "PUT", {
           ServiceInfo: {
             state: 'STARTED'
@@ -131,6 +132,7 @@ App.MainServiceItemController = Em.Controller.extend({
       primary: 'Yes',
       secondary: 'No',
       onPrimary: function() {
+        self.get('content.components').setEach('workStatus', App.Component.Status.stopping);
         self.sendCommandToServer('/services/' + self.get('content.serviceName').toUpperCase(), "PUT",{
           ServiceInfo:{
             state: 'INSTALLED'

+ 1 - 1
ambari-web/app/controllers/wizard.js

@@ -207,7 +207,7 @@ App.WizardController = Em.Controller.extend({
    * Remove all data for installOptions step
    */
   clearInstallOptions: function () {
-    var installOptions = jQuery.extend(this.get('installOptionsTemplate'), {});
+    var installOptions = jQuery.extend({}, this.get('installOptionsTemplate'));
     this.set('content.installOptions', installOptions);
     this.save('installOptions');
     this.set('content.hosts', []);

+ 25 - 16
ambari-web/app/controllers/wizard/step2_controller.js

@@ -66,23 +66,27 @@ App.WizardStep2Controller = Em.Controller.extend({
     return result;
   },
 
-  checkHosts: function() {
-    if (this.get('hostNames').trim() !== '') {
-      App.db.setStep2WizardFirstRun(false);
-    }
-  }.observes('hostNames'),
+  hostsError: null,
 
-  hostsError: function () {
-    if (App.db.getStep2WizardFirstRun()) {
-      return null;
+  checkHostError: function () {
+    if (this.get('hostNames').trim() === '') {
+      this.set('hostsError', Em.I18n.t('installer.step2.hostName.error.required'));
     }
-    if (this.get('hasSubmitted') && this.get('hostNames').trim() === '') {
-      return Em.I18n.t('installer.step2.hostName.error.required');
-    } else if (this.isAllHostNamesValid() === false) {
-      return Em.I18n.t('installer.step2.hostName.error.invalid');
+    else {
+      if (this.isAllHostNamesValid() === false) {
+        this.set('hostsError', Em.I18n.t('installer.step2.hostName.error.invalid'));
+      }
+      else {
+        this.set('hostsError', null);
+      }
     }
-    return null;
-  }.property('hostNames', 'hasSubmitted'),
+  },
+
+  checkHostAfterSubmitHandler: function() {
+    if (this.get('hasSubmitted')) {
+      this.checkHostError();
+    }
+  }.observes('hasSubmitted', 'hostNames'),
 
   sshKeyError: function () {
     if (this.get('hasSubmitted') && this.get('manualInstall') === false && this.get('sshKey').trim() === '') {
@@ -128,8 +132,14 @@ App.WizardStep2Controller = Em.Controller.extend({
     if (this.get('isSubmitDisabled')) {
       return false;
     }
+
     this.set('hasSubmitted', true);
 
+    this.checkHostError();
+    if (this.get('hostsError')) {
+      return false;
+    }
+
     this.updateHostNameArr();
 
     if(this.isPattern)
@@ -139,7 +149,6 @@ App.WizardStep2Controller = Em.Controller.extend({
     }
 
     this.proceedNext();
-
   },
 
   patternExpression: function(){
@@ -226,7 +235,7 @@ App.WizardStep2Controller = Em.Controller.extend({
   },
 
   isSubmitDisabled: function () {
-    return (this.get('hostsError') || this.get('sshKeyError') || (this.get('hostNames').trim() === '' && App.db.getStep2WizardFirstRun()));
+    return (this.get('hostsError') || this.get('sshKeyError'));
   }.property('hostsError', 'sshKeyError'),
 
   saveHosts: function(){

+ 1 - 1
ambari-web/app/controllers/wizard/step8_controller.js

@@ -226,7 +226,7 @@ App.WizardStep8Controller = Em.Controller.extend({
           var key = _keyValue.match(/(.+)=/);
           var value = _keyValue.match(/=(.*)/);
           if (key) {
-            this.setSiteProperty(key[1], value[1], _site.filename);
+            this.setSiteProperty(key[1], value[1], _site.name + '.xml');
           }
 
         }, this);

+ 2 - 0
ambari-web/app/data/config_mapping.js

@@ -718,6 +718,7 @@ module.exports = [
     "value": "rs\/_HOST@<templateName[0]>",
     "filename": "hbase-site.xml"
   },
+  /*
   {
     "name": "hbase.coprocessor.region.classes",
     "templateName": ["preloaded_regioncoprocessor_classes"],
@@ -725,6 +726,7 @@ module.exports = [
     "value": "<templateName[0]>",
     "filename": "hbase-site.xml"
   },
+  */
   {
     "name": "dfs.support.append",
     "templateName": ["hdfs_support_append"],

+ 1 - 1
ambari-web/app/data/config_properties.js

@@ -371,7 +371,7 @@ module.exports =
     },
     {
       "id": "puppet var",
-      "name": "regionserver_memstore_upperlimitt",
+      "name": "regionserver_memstore_upperlimit",
       "displayName": "regionserver_memstore_upperlimit",
       "description": "",
       "defaultValue": "0.4",

+ 126 - 71
ambari-web/app/mappers/service_mapper.js

@@ -145,54 +145,41 @@ App.servicesMapper = App.QuickDataMapper.create({
     }
 
     if (json.items) {
-      var result = [];
-      json.items.forEach(function (item) {
-        var finalConfig = jQuery.extend({}, this.config);
-        var finalJson = [];
-        item.host_components = [];
-//        var json = this.parseIt(item, this.config);
-//        if(App.Service.find().someProperty('id', json.id)){
-//          var fieldsToUpdate = [
-//            'work_status',
-//            'components',
-//            'host_components'
-//          ]
-//          this.updateRecord(App.Service.find().findProperty('id', json.id), json, fieldsToUpdate);
-//          return;
-//        }
 
-        if (this.get('model').find(item.ServiceInfo.service_name).get('isLoaded')) {
-          this.update(item);
-          return;
-        }
-        item.components.forEach(function (component) {
-          component.host_components.forEach(function (host_component) {
-            host_component.id = host_component.HostRoles.component_name + "_" + host_component.HostRoles.host_name;
-            item.host_components.push(host_component.id);
+      // Host components
+      var result = [];
+      json.items.forEach(function(item){
+        item.components.forEach(function(component){
+          component.host_components.forEach(function(host_component){
+            result.push(this.parseIt(host_component, this.config3));
           }, this)
-        }, this);
-
-        if (item && item.ServiceInfo && item.ServiceInfo.service_name == "HDFS") {
-          // Change the JSON so that it is easy to map
-          finalJson = this.hdfsMapper(item);
-          result.push(finalJson);
-          App.store.load(App.HDFSService, finalJson);
-        } else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "MAPREDUCE") {
-          finalJson = this.mapreduceMapper(item);
-          result.push(finalJson);
-          App.store.load(App.MapReduceService, finalJson);
-        } else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "HBASE") {
-          finalJson = this.hbaseMapper(item);
-          result.push(finalJson);
-          App.store.load(App.HBaseService, finalJson);
+        }, this)
+      }, this);
+      var newHostComponents = [];
+      result.forEach(function(hcJson){
+        hcJson.id = hcJson.component_name + '_' + hcJson.host_id;
+        var component = App.HostComponent.find(hcJson.id);
+        if (component && component.get('isLoaded')) { // UPDATE
+          if (hcJson.work_status) {
+            component.set('workStatus', hcJson.work_status);
+          }
+          if (hcJson.component_name) {
+            component.set('componentName', hcJson.component_name);
+          }
+          if (hcJson.host_id) {
+            component.set('host', App.Host.find(hcJson.host_id));
+          }
+          if (hcJson.service_id) {
+            component.set('service', App.Service.find(hcJson.service_id));
+          }
         } else {
-          result.push(this.parseIt(item, this.config));
+          newHostComponents.push(hcJson);
         }
-      }, this);
-
+      });
 
-      result = this.sortByOrder(this.get('servicesSortOrder'), result);
-      App.store.loadMany(this.get('model'), result);
+      if (newHostComponents.length > 0) {
+        App.store.loadMany(this.get('model3'), newHostComponents);
+      }
 
       // Service components
       result = [];
@@ -215,43 +202,110 @@ App.servicesMapper = App.QuickDataMapper.create({
           newComponents.push(componentJson);
         }
       });
+
       if (newComponents.length > 0) {
         App.store.loadMany(this.get('model2'), newComponents);
       }
 
-      // Host components
-      result = [];
-      json.items.forEach(function(item){
-        item.components.forEach(function(component){
-          component.host_components.forEach(function(host_component){
-            result.push(this.parseIt(host_component, this.config3));
-          }, this)
-        }, this)
-      }, this);
-      var newHostComponents = [];
-      result.forEach(function(hcJson){
-        hcJson.id = hcJson.component_name + '_' + hcJson.host_id;
-        var component = App.HostComponent.find(hcJson.id);
-        if (component && component.get('isLoaded')) { // UPDATE
-          if (hcJson.work_status) {
-            component.set('workStatus', hcJson.work_status);
-          }
-          if (hcJson.component_name) {
-            component.set('componentName', hcJson.component_name);
+      //Services
+      var newServices = [];
+      json.items.forEach(function (item) {
+        var finalJson = {};
+        var serviceJson = this.parseIt(item, this.config);
+        var serviceFields = [
+          'work_status',
+          'components',
+          'host_components'
+        ]
+        if (item && item.ServiceInfo && item.ServiceInfo.service_name == "HDFS") {
+          // Change the JSON so that it is easy to map
+          finalJson = this.hdfsMapper(item);
+          if(App.Service.find().someProperty('id', serviceJson.id)){
+            var hdfsFields = [
+              'version',
+              'name_node_start_time',
+              'jvm_memory_heap_committed',
+              'jvm_memory_heap_used',
+              'capacity_used',
+              'capacity_total',
+              'dfs_total_blocks',
+              'dfs_corrupt_blocks',
+              'dfs_missing_blocks',
+              'dfs_under_replicated_blocks',
+              'dfs_total_files',
+              'upgrade_status',
+              'safe_mode_status',
+              'decommission_data_nodes',
+              'live_data_nodes',
+              'dead_data_nodes'
+            ];
+            this.updateRecord(App.Service.find().findProperty('id', serviceJson.id), serviceJson, serviceFields);
+            this.updateRecord(App.HDFSService.find().findProperty('id', finalJson.id), finalJson, hdfsFields);
+          } else {
+            newServices.push(serviceJson);
+            App.store.load(App.HDFSService, finalJson);
           }
-          if (hcJson.host_id) {
-            component.set('host', App.Host.find(hcJson.host_id));
+        } else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "MAPREDUCE") {
+          finalJson = this.mapreduceMapper(item);
+          if(App.Service.find().someProperty('id', serviceJson.id)){
+            var mapReduceFields = [
+              'version',
+              'job_tracker_start_time',
+              'job_tracker_heap_used)',
+              'job_tracker_heap_max',
+              'map_slots',
+              'reduce_slots',
+              'jobs_submitted',
+              'jobs_completed',
+              'map_slots_occupied',
+              'map_slots_reserved',
+              'reduce_slots_occupied',
+              'reduce_slots_reserved)',
+              'maps_running',
+              'maps_waiting',
+              'reduces_running',
+              'reduces_waiting',
+              'trackers_decommissioned'
+            ]
+            this.updateRecord(App.Service.find().findProperty('id', finalJson.id), serviceJson, serviceFields);
+            this.updateRecord(App.MapReduceService.find().findProperty('id', finalJson.id), finalJson, mapReduceFields);
+          } else {
+            newServices.push(serviceJson);
+            App.store.load(App.MapReduceService, finalJson);
           }
-          if (hcJson.service_id) {
-            component.set('service', App.Service.find(hcJson.service_id));
+        } else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "HBASE") {
+          finalJson = this.hbaseMapper(item);
+          if(App.Service.find().someProperty('id', serviceJson.id)){
+            var hbaseFields = [
+              'version',
+              'master_start_time',
+              'master_active_time',
+              'average_load',
+              'regions_in_transition',
+              'revision',
+              'heap_memory_used',
+              'heap_memory_max'
+            ]
+            this.updateRecord(App.Service.find().findProperty('id', serviceJson.id), serviceJson, serviceFields);
+            this.updateRecord(App.HBaseService.find().findProperty('id', finalJson.id), finalJson, hbaseFields);
+          } else {
+            newServices.push(serviceJson);
+            App.store.load(App.HBaseService, finalJson);
           }
         } else {
-          newHostComponents.push(hcJson);
+          if(App.Service.find().someProperty('id', serviceJson.id)){
+            this.updateRecord(App.Service.find().findProperty('id', serviceJson.id), serviceJson, serviceFields);
+          } else {
+            newServices.push(serviceJson);
+          }
         }
-      });
-      if (newHostComponents.length > 0) {
-        App.store.loadMany(this.get('model3'), newHostComponents);
+      }, this);
+
+      if(newServices.length){
+        newServices = this.sortByOrder(this.get('servicesSortOrder'), newServices);
+        App.store.loadMany(this.get('model'), newServices);
       }
+      //App.store.commit();
     }
   },
   update: function (service) {
@@ -477,7 +531,8 @@ App.servicesMapper = App.QuickDataMapper.create({
     return finalJson;
   },
   updateRecord: function (record, json, fieldsToUpdate) {
-    for (var field in fieldsToUpdate) {
+    for (var i = 0; i < fieldsToUpdate.length; i++) {
+      var field = fieldsToUpdate[i];
       if (json[field] !== undefined) {
         if(json[field] instanceof Array){
           this.updateHasMany(record, stringUtils.underScoreToCamelCase(field), json[field]);

+ 0 - 1
ambari-web/app/routes/add_host_routes.js

@@ -24,7 +24,6 @@ module.exports = Em.Route.extend({
 
     Ember.run.next(function () {
       var addHostController = router.get('addHostController');
-      App.db.setStep2WizardFirstRun(true);
       App.router.get('updateController').set('isWorking', false);
       App.ModalPopup.show({
         classNames: ['full-width-modal'],

+ 0 - 14
ambari-web/app/utils/db.js

@@ -212,14 +212,6 @@ App.db.setCluster = function (status) {
   localStorage.setObject('ambari', App.db.data);
 };
 
-
-App.db.setStep2WizardFirstRun = function(status) {
-  App.db.data = localStorage.getObject('ambari');
-  App.db.data.Installer.step2WizardFirstRun = status;
-  console.log('db.setStep2WizardFirstRun called: ' + status);
-  localStorage.setObject('ambari', App.db.data);
-};
-
 /**
  * Set current step value for specified Wizard Type
  * @param wizardType
@@ -364,10 +356,4 @@ App.db.getCluster = function () {
   return App.db.data.Installer.clusterStatus;
 };
 
-App.db.getStep2WizardFirstRun = function() {
-  App.db.data = localStorage.getObject('ambari');
-  console.log('TRACE: Entering db:setStep2WizardFirstRun function');
-  return App.db.data.Installer.step2WizardFirstRun;
-};
-
 module.exports = App.db;

+ 0 - 1
ambari-web/app/utils/validator.js

@@ -53,7 +53,6 @@ module.exports = {
    */
   isHostname: function(value) {
     var regex = /^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/;
-    console.warn("HOSTNAME:", value, "   VALUE:" ,regex.test(value));
     return regex.test(value);
   },
 

+ 2 - 1
ambari-web/app/views/main/service/info/summary.js

@@ -307,7 +307,8 @@ App.MainServiceInfoSummaryView = Em.View.extend({
       }
     }
     return graphs;
-  }.property('service'),
+    //we don't need to bind graphs to service property they update by themselves
+  }.property(),
 
   loadServiceSummary:function (serviceName) {