Browse Source

AMBARI-3641 Synchronize service start/stop buttons with actual status. (atkach)

atkach 11 years ago
parent
commit
0b9e3a8721

+ 38 - 6
ambari-web/app/controllers/global/background_operations_controller.js

@@ -154,26 +154,28 @@ App.BackgroundOperationsController = Em.Controller.extend({
       var isRunning = (request.Requests.task_count -
       var isRunning = (request.Requests.task_count -
         (request.Requests.aborted_task_count + request.Requests.completed_task_count + request.Requests.failed_task_count
         (request.Requests.aborted_task_count + request.Requests.completed_task_count + request.Requests.failed_task_count
          + request.Requests.timed_out_task_count - request.Requests.queued_task_count)) > 0;
          + request.Requests.timed_out_task_count - request.Requests.queued_task_count)) > 0;
+      var requestParams = this.parseRequestContext(request.Requests.request_context);
       currentRequestIds.push(request.Requests.id);
       currentRequestIds.push(request.Requests.id);
       if (rq) {
       if (rq) {
-        rq.set('progress', Math.round(request.Requests.progress_percent));
+        rq.set('progress', Math.ceil(request.Requests.progress_percent));
         rq.set('status', request.Requests.request_status);
         rq.set('status', request.Requests.request_status);
         rq.set('isRunning', isRunning);
         rq.set('isRunning', isRunning);
       } else {
       } else {
         rq = Em.Object.create({
         rq = Em.Object.create({
           id: request.Requests.id,
           id: request.Requests.id,
-          name: request.Requests.request_context || 'Request name not specified',
-          displayName: request.Requests.request_context || 'Request name not specified',
-          progress: Math.round(request.Requests.progress_percent),
+          name: requestParams.requestContext,
+          displayName: requestParams.requestContext,
+          progress: Math.ceil(request.Requests.progress_percent),
           status: request.Requests.request_status,
           status: request.Requests.request_status,
           isRunning: isRunning,
           isRunning: isRunning,
           hostsMap: {},
           hostsMap: {},
-          tasks: []
+          tasks: [],
+          dependentService: requestParams.dependentService
         });
         });
         self.get("services").unshift(rq);
         self.get("services").unshift(rq);
       }
       }
       runningServices += ~~isRunning;
       runningServices += ~~isRunning;
-    });
+    }, this);
     //remove old request if it's absent in API response
     //remove old request if it's absent in API response
     self.get('services').forEach(function(service, index, services){
     self.get('services').forEach(function(service, index, services){
       if(!currentRequestIds.contains(service.id)) {
       if(!currentRequestIds.contains(service.id)) {
@@ -184,6 +186,36 @@ App.BackgroundOperationsController = Em.Controller.extend({
     self.set('serviceTimestamp', new Date().getTime());
     self.set('serviceTimestamp', new Date().getTime());
   },
   },
 
 
+  /**
+   * parse request context and if keyword "_PARSE_" is present then format it
+   * @param requestContext
+   * @return {Object}
+   */
+  parseRequestContext: function (requestContext) {
+    var parsedRequestContext;
+    var service;
+    var command;
+    if (requestContext) {
+      if (requestContext.indexOf("_PARSE_") !== -1) {
+        command = requestContext.split('.')[1];
+        service = requestContext.split('.')[2];
+        if (service === 'ALL_SERVICES') {
+          parsedRequestContext = Em.I18n.t("requestInfo." + command.toLowerCase()).format(Em.I18n.t('common.allServices'));
+        } else {
+          parsedRequestContext = Em.I18n.t("requestInfo." + command.toLowerCase()).format(App.Service.DisplayNames[service]);
+        }
+      } else {
+        parsedRequestContext = requestContext;
+      }
+    } else {
+      parsedRequestContext = Em.I18n.t('requestInfo.unspecified');
+    }
+    return {
+      requestContext: parsedRequestContext,
+      dependentService: service
+    }
+  },
+
   popupView: null,
   popupView: null,
 
 
   /**
   /**

+ 4 - 5
ambari-web/app/controllers/main/service.js

@@ -86,11 +86,10 @@ App.MainServiceController = Em.ArrayController.extend({
 
 
   allServicesCall: function(state) {
   allServicesCall: function(state) {
     var data;
     var data;
-    if(state == 'stopAllService') {
-      data = '{"RequestInfo": {"context" :"'+ Em.I18n.t('requestInfo.stopAllServices') +'"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
-    }
-    else {
-      data = '{"RequestInfo": {"context" :"'+ Em.I18n.t('requestInfo.startAllServices') +'"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
+    if (state == 'stopAllService') {
+      data = '{"RequestInfo": {"context" :"_PARSE_.STOP.ALL_SERVICES"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
+    } else {
+      data = '{"RequestInfo": {"context" :"_PARSE_.START.ALL_SERVICES"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
     }
     }
 
 
     App.ajax.send({
     App.ajax.send({

+ 13 - 17
ambari-web/app/controllers/main/service/item.js

@@ -94,12 +94,12 @@ App.MainServiceItemController = Em.Controller.extend({
     });
     });
   },
   },
 
 
-  startStopPopupPrimary: function(serviceHealth) {
+  startStopPopupPrimary: function (serviceHealth) {
     var requestInfo = "";
     var requestInfo = "";
-    if(serviceHealth == "STARTED"){
-      requestInfo = 'Start ' + this.get('content.displayName');
-    }else{
-      requestInfo = 'Stop ' + this.get('content.displayName');
+    if (serviceHealth == "STARTED") {
+      requestInfo = '_PARSE_.START.' + this.get('content.serviceName');
+    } else {
+      requestInfo = '_PARSE_.STOP.' + this.get('content.serviceName');
     }
     }
 
 
     App.ajax.send({
     App.ajax.send({
@@ -107,13 +107,13 @@ App.MainServiceItemController = Em.Controller.extend({
       'sender': this,
       'sender': this,
       'success': 'ajaxSuccess',
       'success': 'ajaxSuccess',
       'data': {
       'data': {
-        'requestInfo':requestInfo,
+        'requestInfo': requestInfo,
         'serviceName': this.get('content.serviceName').toUpperCase(),
         'serviceName': this.get('content.serviceName').toUpperCase(),
         'state': serviceHealth
         'state': serviceHealth
       }
       }
     });
     });
-    this.set('isStopDisabled',true);
-    this.set('isStartDisabled',true);
+    this.set('isStopDisabled', true);
+    this.set('isStartDisabled', true);
   },
   },
 
 
   /**
   /**
@@ -225,18 +225,14 @@ App.MainServiceItemController = Em.Controller.extend({
 
 
   setStartStopState: function () {
   setStartStopState: function () {
     var serviceName = this.get('content.serviceName');
     var serviceName = this.get('content.serviceName');
-    var components = service_components.filterProperty('service_name', serviceName).mapProperty('component_name');
     var backgroundOperations = App.router.get('backgroundOperationsController.services');
     var backgroundOperations = App.router.get('backgroundOperationsController.services');
     if (backgroundOperations.length > 0) {
     if (backgroundOperations.length > 0) {
       for (var i = 0; i < backgroundOperations.length; i++) {
       for (var i = 0; i < backgroundOperations.length; i++) {
-        var logTasks = backgroundOperations[i].tasks;
-        for (var k = 0; k < logTasks.length; k++) {
-          if (components.contains(logTasks[k].Tasks.role)) {
-            if (logTasks[k].Tasks.status == 'PENDING' || logTasks[k].Tasks.status == 'IN_PROGRESS' || logTasks[k].Tasks.status == 'QUEUED') {
-              this.set('isPending', true);
-              return;
-            }
-          }
+        if (backgroundOperations[i].isRunning &&
+            (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
+             backgroundOperations[i].dependentService === serviceName)) {
+          this.set('isPending', true);
+          return;
         }
         }
       }
       }
       this.set('isPending', false);
       this.set('isPending', false);

+ 5 - 2
ambari-web/app/messages.js

@@ -150,6 +150,8 @@ Em.I18n.translations = {
   'common.update.error' : 'Error in retrieving web client state from ambari server',
   'common.update.error' : 'Error in retrieving web client state from ambari server',
   'common.tags': 'Tags',
   'common.tags': 'Tags',
   'common.important': 'Important',
   'common.important': 'Important',
+  'common.allServices':'All Services',
+
   'requestInfo.installComponents':'Install Components',
   'requestInfo.installComponents':'Install Components',
   'requestInfo.installServices':'Install Services',
   'requestInfo.installServices':'Install Services',
   'requestInfo.startServices':'Start Services',
   'requestInfo.startServices':'Start Services',
@@ -161,8 +163,9 @@ Em.I18n.translations = {
   'requestInfo.stopHostComponent':'Stop',
   'requestInfo.stopHostComponent':'Stop',
   'requestInfo.installHostComponent':'Install',
   'requestInfo.installHostComponent':'Install',
   'requestInfo.installNewHostComponent':'Install',
   'requestInfo.installNewHostComponent':'Install',
-  'requestInfo.stopService':'Stop',
-  'requestInfo.startService':'Start',
+  'requestInfo.stop':'Stop {0}',
+  'requestInfo.start':'Start {0}',
+  'requestInfo.unspecified':'Request name not specified',
 
 
   'hostPopup.noServicesToShow':'No services to show',
   'hostPopup.noServicesToShow':'No services to show',
   'hostPopup.noHostsToShow':'No hosts to show',
   'hostPopup.noHostsToShow':'No hosts to show',

+ 22 - 38
ambari-web/app/models/service.js

@@ -62,45 +62,9 @@ App.Service = DS.Model.extend({
   }.property('serviceName'),
   }.property('serviceName'),
 
 
   displayName: function () {
   displayName: function () {
-    switch (this.get('serviceName').toLowerCase()) {
-      case 'hdfs':
-        return 'HDFS';
-      case 'yarn':
-        return 'YARN';
-      case 'mapreduce':
-        return 'MapReduce';
-      case 'mapreduce2':
-        return 'MapReduce2';
-      case 'tez':
-        return 'Tez';
-      case 'hbase':
-        return 'HBase';
-      case 'oozie':
-        return 'Oozie';
-      case 'hive':
-        return 'Hive';
-      case 'hcatalog':
-        return 'HCat';
-      case 'zookeeper':
-        return 'ZooKeeper';
-      case 'pig':
-        return 'Pig';
-      case 'sqoop':
-        return 'Sqoop';
-      case 'webhcat':
-        return 'WebHCat';
-      case 'ganglia':
-        return 'Ganglia';
-      case 'nagios':
-        return 'Nagios';
-      case 'hue':
-        return 'Hue';
-      case 'flume':
-        return 'Flume';
-    }
-    return this.get('serviceName');
+    return App.Service.DisplayNames[this.get('serviceName')];
   }.property('serviceName'),
   }.property('serviceName'),
-  
+
   /**
   /**
    * For each host-component, if the desired_configs dont match the
    * For each host-component, if the desired_configs dont match the
    * actual_configs, then a restart is required. Except for Global site
    * actual_configs, then a restart is required. Except for Global site
@@ -179,4 +143,24 @@ App.Service.Health = {
   }
   }
 };
 };
 
 
+App.Service.DisplayNames = {
+  'HDFS': 'HDFS',
+  'YARN': 'YARN',
+  'MAPREDUCE': 'MapReduce',
+  'MAPREDUCE2': 'MapReduce2',
+  'TEZ': 'Tez',
+  'HBASE': 'HBase',
+  'OOZIE': 'Oozie',
+  'HIVE': 'Hive',
+  'HCATALOG': 'HCat',
+  'ZOOKEEPER': 'ZooKeeper',
+  'PIG': 'Pig',
+  'SQOOP': 'Sqoop',
+  'WEBHCAT': 'WebHCat',
+  'GANGLIA': 'Ganglia',
+  'NAGIOS': 'Nagios',
+  'HUE': 'Hue',
+  'FLUME': 'Flume'
+};
+
 App.Service.FIXTURES = [];
 App.Service.FIXTURES = [];