Browse Source

AMBARI-3156. NameNode HA wizard (rollback): Create API calls for Restore HDFSconfigs, Enable Secondary NN, Stop JournalNodes

Alex Antonenko 11 years ago
parent
commit
f8e39c72c9

+ 1 - 1
ambari-web/app/controllers/main/admin/highAvailability/progress_controller.js

@@ -18,7 +18,7 @@
 
 var App = require('app');
 
-App.HighAvailabilityProgressPageController = Em.Controller.extend({
+App.HighAvailabilityProgressPageController = App.HighAvailabilityWizardController.extend({
 
   name: 'highAvailabilityProgressPageController',
 

+ 187 - 4
ambari-web/app/controllers/main/admin/highAvailability/rollback_controller.js

@@ -24,6 +24,14 @@ App.HighAvailabilityRollbackController = App.HighAvailabilityProgressPageControl
   name: "highAvailabilityRollbackController",
 
   failedTask: null,
+  configsSaved: false,
+  deletedHdfsClients: 0,
+  numOfDelOperations: 0,
+
+
+  content: Em.Object.create({
+    masterComponentHosts: null
+  }),
 
   commands: [
     'stopAllServices',
@@ -41,13 +49,19 @@ App.HighAvailabilityRollbackController = App.HighAvailabilityProgressPageControl
   ],
 
   loadStep: function () {
-    this.loadFailedTask();
+    this.initData();
     this.clearStep();
     this.loadTasks();
     this.addObserver('tasks.@each.status', this, 'onTaskStatusChange');
     this.onTaskStatusChange();
   },
 
+  initData: function () {
+    this.loadMasterComponentHosts();
+    this.loadFailedTask();
+    this.loadHdfsClientHosts();
+  },
+
   setCommandsAndTasks: function(tmpTasks) {
     var fTask = this.get('failedTask');
     var newCommands = [];
@@ -184,13 +198,15 @@ App.HighAvailabilityRollbackController = App.HighAvailabilityProgressPageControl
 
   },
   restoreHDFSConfigs: function(){
-
+    this.unInstallHDFSClients();
   },
   enableSecondaryNameNode: function(){
-
+    var hostName = this.get('content.masterComponentHosts').findProperty('component', 'SECONDARY_NAMENODE').hostName;
+    this.installComponent('SECONDARY_NAMENODE', hostName, hostName.length);
   },
   stopJournalNodes: function(){
-
+    var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
+    this.stopComponent('JOURNALNODE', hostNames);
   },
   deleteJournalNodes: function(){
 
@@ -200,6 +216,173 @@ App.HighAvailabilityRollbackController = App.HighAvailabilityProgressPageControl
   },
   startAllServices: function(){
 
+  },
+
+  onLoadHbaseConfigs: function (data) {
+    var hbaseSiteProperties = data.items.findProperty('type', 'hbase-site').properties;
+    App.ajax.send({
+      name: 'admin.high_availability.save_configs',
+      sender: this,
+      data: {
+        siteName: 'hbase-site',
+        properties: hbaseSiteProperties
+      },
+      success: 'onTaskCompleted',
+      error: 'onTaskError'
+    });
+  },
+
+  stopComponent: function (componentName, hostName) {
+    if (!(hostName instanceof Array)) {
+      hostName = [hostName];
+    }
+    for (var i = 0; i < hostName.length; i++) {
+      App.ajax.send({
+        name: 'admin.high_availability.stop_component',
+        sender: this,
+        data: {
+          hostName: hostName[i],
+          componentName: componentName,
+          displayName: App.format.role(componentName),
+          taskNum: hostName.length
+        },
+        success: 'startPolling',
+        error: 'onTaskError'
+      });
+    }
+  },
+
+  onDeletedHDFSClient: function () {
+    var deletedHdfsClients = this.get('deletedHdfsClients');
+    var hostName = this.get("content.hdfsClientHostNames");
+    var notDeletedHdfsClients = hostName.length - deletedHdfsClients;
+    if (notDeletedHdfsClients > 1 && hostName.length != 1 ) {
+      this.set('deletedHdfsClients', deletedHdfsClients+1);
+      return;
+    }
+    this.loadConfigTag("hdfsSiteTag");
+    this.loadConfigTag("coreSiteTag");
+    var hdfsSiteTag = this.get("content.hdfsSiteTag");
+    var coreSiteTag = this.get("content.coreSiteTag");
+    App.ajax.send({
+      name: 'admin.high_availability.load_configs',
+      sender: this,
+      data: {
+        hdfsSiteTag: hdfsSiteTag,
+        coreSiteTag: coreSiteTag
+      },
+      success: 'onLoadConfigs',
+      error: 'onTaskError'
+    });
+  },
+
+  onLoadConfigs: function (data) {
+    this.set('configsSaved', false);
+    App.ajax.send({
+      name: 'admin.high_availability.save_configs',
+      sender: this,
+      data: {
+        siteName: 'hdfs-site',
+        properties: data.items.findProperty('type', 'hdfs-site').properties
+      },
+      success: 'onHdfsConfigsSaved',
+      error: 'onTaskError'
+    });
+    App.ajax.send({
+      name: 'admin.high_availability.save_configs',
+      sender: this,
+      data: {
+        siteName: 'core-site',
+        properties: data.items.findProperty('type', 'core-site').properties
+      },
+      success: 'onHdfsConfigsSaved',
+      error: 'onTaskError'
+    });
+  },
+
+  onHdfsConfigsSaved: function () {
+    if (!this.get('configsSaved')) {
+      this.set('configsSaved', true);
+      return;
+    }
+    this.onTaskCompleted();
+  },
+
+  unInstallHDFSClients: function () {
+    var hostName = this.get("content.hdfsClientHostNames");
+    for (var i = 0; i < hostName.length; i++) {
+      App.ajax.send({
+        name: 'admin.high_availability.delete_component',
+        sender: this,
+        data: {
+          componentName: 'HDFS_CLIENT',
+          hostName: hostName[i]
+        },
+        success: 'onDeletedHDFSClient',
+        error: 'onTaskError'
+      });
+    }
+  },
+
+  unInstallComponent: function (componentName, hostName) {
+    if (!(hostName instanceof Array)) {
+      hostName = [hostName];
+    }
+    var hostComponents = [];
+    for (var i = 0; i < hostName.length; i++) {
+      hostComponents = App.HostComponent.find().filterProperty('componentName', componentName);
+      if (!hostComponents.length || !hostComponents.mapProperty('host.hostName').contains(hostName[i])) {
+        App.ajax.send({
+          name: 'admin.high_availability.maintenance_mode',
+          sender: this,
+          data: {
+            hostName: hostName[i],
+            componentName: componentName,
+            taskNum: hostName.length
+          },
+          success: 'onMaintenanceComponent',
+          error: 'onTaskError'
+        });
+      } else {
+        var taskNum = hostName.length;
+        this.deleteComponent(componentName, hostName[i], taskNum);
+      }
+    }
+  },
+
+  onMaintenanceComponent: function () {
+    var hostName = arguments[2].hostName;
+    var componentName = arguments[2].componentName;
+    var taskNum = arguments[2].taskNum;
+    this.deleteComponent(componentName, hostName, taskNum);
+  },
+
+  deleteComponent: function (componentName, hostName, taskNum) {
+    if (!(hostName instanceof Array)) {
+      hostName = [hostName];
+    }
+    this.set('numOfDelOperations', hostName.length);
+    for (var i = 0; i < hostName.length; i++) {
+      App.ajax.send({
+        name: 'admin.high_availability.delete_component',
+        sender: this,
+        data: {
+          componentName: componentName,
+          hostName: hostName[i]
+        },
+        success: 'onDeleteComplete',
+        error: 'onTaskError'
+      });
+    }
+  },
+
+  onDeleteComplete: function () {
+    var leftOp = this.get('numOfDelOperations');
+    if(leftOp > 1){
+      this.set('numOfDelOperations', leftOp-1);
+      return;
+    }
+    this.onTaskCompleted();
   }
 
 });

+ 1 - 1
ambari-web/app/controllers/main/admin/highAvailability/step5_controller.js

@@ -162,9 +162,9 @@ App.HighAvailabilityWizardStep5Controller = App.HighAvailabilityProgressPageCont
     }
     var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName');
     this.createComponent('HDFS_CLIENT', hostNames);
-    //highAvailabilityWizardController
     App.router.get(this.get('content.controllerName')).saveConfigTag(this.get("hdfsSiteTag"));
     App.router.get(this.get('content.controllerName')).saveConfigTag(this.get("coreSiteTag"));
+    App.router.get(this.get('content.controllerName')).saveHdfsClientHosts(hostNames);
     App.clusterStatus.setClusterStatus({
       clusterName: this.get('content.cluster.name'),
       clusterState: 'HIGH_AVAILABILITY_DEPLOY',

+ 2 - 1
ambari-web/app/controllers/main/admin/highAvailability/step9_controller.js

@@ -126,9 +126,10 @@ App.HighAvailabilityWizardStep9Controller = App.HighAvailabilityProgressPageCont
   deleteSNameNode: function () {
     var hostName = this.get('content.masterComponentHosts').findProperty('component', 'SECONDARY_NAMENODE').hostName;
     App.ajax.send({
-      name: 'admin.high_availability.delete_snamenode',
+      name: 'admin.high_availability.delete_component',
       sender: this,
       data: {
+        componentName: 'SECONDARY_NAMENODE',
         hostName: hostName
       },
       success: 'onTaskCompleted',

+ 18 - 2
ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js

@@ -169,6 +169,24 @@ App.HighAvailabilityWizardController = App.WizardController.extend({
     this.set('content.'+[tag.name], tag.value);
   },
 
+  saveHdfsClientHosts: function(hostNames){
+    App.db.setHighAvailabilityWizardHdfsClientHosts(hostNames);
+    this.set('content.hdfsClientHostNames', hostNames);
+  },
+
+  loadHdfsClientHosts: function(){
+    var hostNames = App.db.getHighAvailabilityWizardHdfsClientHosts();
+    if (!(hostNames instanceof Array)) {
+      hostNames = [hostNames];
+    }
+    this.set('content.hdfsClientHostNames', hostNames);
+  },
+
+  loadConfigTag: function(tag){
+    var tagVal = App.db.getHighAvailabilityWizardConfigTag(tag);
+    this.set('content.'+tag, tagVal);
+  },
+
   loadTasksStatuses: function(){
     var statuses = App.db.getHighAvailabilityWizardTasksStatuses();
     this.set('content.tasksStatuses', statuses);
@@ -235,8 +253,6 @@ App.HighAvailabilityWizardController = App.WizardController.extend({
   finish: function () {
     this.setCurrentStep('1');
     this.clearAllSteps();
-    this.clearStorageData();
     App.router.get('updateController').updateAll();
   }
-
 });

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

@@ -244,6 +244,7 @@ module.exports = Em.Route.extend({
     next: function (router) {
       var controller = router.get('highAvailabilityWizardController');
       controller.finish();
+      controller.clearStorageData();
       controller.get('popup').hide();
       App.clusterStatus.setClusterStatus({
         clusterName: controller.get('content.cluster.name'),

+ 21 - 2
ambari-web/app/utils/ajax.js

@@ -731,6 +731,25 @@ var urls = {
       }
     }
   },
+  'admin.high_availability.stop_component': {
+    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
+    'mock': '',
+    'type': 'PUT',
+    'format': function (data) {
+      return {
+        data: JSON.stringify({
+          RequestInfo: {
+            "context": "Stop " + data.displayName
+          },
+          Body: {
+            "HostRoles": {
+              "state": "INSTALLED"
+            }
+          }
+        })
+      }
+    }
+  },
   'admin.high_availability.load_configs': {
     'real': '/clusters/{clusterName}/configurations?(type=core-site&tag={coreSiteTag})|(type=hdfs-site&tag={hdfsSiteTag})',
     'mock': '',
@@ -760,8 +779,8 @@ var urls = {
     'mock': '',
     'type': 'GET'
   },
-  'admin.high_availability.delete_snamenode': {
-    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/SECONDARY_NAMENODE',
+  'admin.high_availability.delete_component': {
+    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
     'mock': '',
     'type': 'DELETE'
   },

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

@@ -355,11 +355,17 @@ App.db.setHighAvailabilityWizardConfigTag = function (tag) {
   App.db.data.HighAvailabilityWizard[tag.name] = tag.value;
   localStorage.setObject('ambari', App.db.data);
 };
+
 App.db.setHighAvailabilityWizardFailedTask = function (task) {
   App.db.data = localStorage.getObject('ambari');
   App.db.data.HighAvailabilityWizard.failedTask = task;
   localStorage.setObject('ambari', App.db.data);
 };
+App.db.setHighAvailabilityWizardHdfsClientHosts = function (hostNames) {
+  App.db.data = localStorage.getObject('ambari');
+  App.db.data.HighAvailabilityWizard.hdfsClientHostNames = hostNames;
+  localStorage.setObject('ambari', App.db.data);
+};
 
 App.db.setHighAvailabilityWizardTasksStatuses = function (tasksStatuses) {
   App.db.data = localStorage.getObject('ambari');
@@ -602,6 +608,16 @@ App.db.getHighAvailabilityWizardFailedTask = function () {
   return App.db.data.HighAvailabilityWizard.failedTask;
 };
 
+App.db.getHighAvailabilityWizardHdfsClientHosts = function () {
+  App.db.data = localStorage.getObject('ambari');
+  return App.db.data.HighAvailabilityWizard.hdfsClientHostNames;
+};
+
+App.db.getHighAvailabilityWizardConfigTag = function (tag) {
+  App.db.data = localStorage.getObject('ambari');
+  return App.db.data.HighAvailabilityWizard[tag];
+};
+
 App.db.getHighAvailabilityWizardRequestIds = function () {
   App.db.data = localStorage.getObject('ambari');
   return App.db.data.HighAvailabilityWizard.requestIds;