You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ab...@apache.org on 2014/11/24 11:39:41 UTC

ambari git commit: AMBARI-8410 For SSH bootstrap, UI should allow to customize 'run as user'

Repository: ambari
Updated Branches:
  refs/heads/trunk b5755a54d -> 88a872215


AMBARI-8410
For SSH bootstrap, UI should allow to customize 'run as user'


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/88a87221
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/88a87221
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/88a87221

Branch: refs/heads/trunk
Commit: 88a872215b79f1cc6c2b8f87bdeef4fa45dc3a83
Parents: b5755a5
Author: aBabiichuk <ab...@cybervisiontech.com>
Authored: Fri Nov 21 14:53:30 2014 +0200
Committer: aBabiichuk <ab...@cybervisiontech.com>
Committed: Mon Nov 24 11:48:30 2014 +0200

----------------------------------------------------------------------
 ambari-web/app/controllers/wizard.js            |   6 +-
 .../app/controllers/wizard/step2_controller.js  |  33 ++++-
 .../app/controllers/wizard/step3_controller.js  |   3 +-
 ambari-web/app/messages.js                      |   1 +
 ambari-web/app/templates/wizard/step2.hbs       |  22 ++-
 .../test/controllers/wizard/step2_test.js       | 139 +++++++++++++++----
 .../test/controllers/wizard/step3_test.js       |  16 +++
 7 files changed, 184 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/88a87221/ambari-web/app/controllers/wizard.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/wizard.js b/ambari-web/app/controllers/wizard.js
index 94ac83d..e87984d 100644
--- a/ambari-web/app/controllers/wizard.js
+++ b/ambari-web/app/controllers/wizard.js
@@ -515,7 +515,8 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, {
     localRepo: false, //true, false
     sshKey: "", //string
     bootRequestId: null, //string
-    sshUser: "root" //string
+    sshUser: "root", //string
+    agentUser: "root" //string
   },
 
   installWindowsOptionsTemplate: {
@@ -526,7 +527,8 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, {
     localRepo: false, //true, false
     sshKey: "", //string
     bootRequestId: null, //string
-    sshUser: "" //string
+    sshUser: "", //string
+    agentUser: "" //string
   },
 
   loadedServiceComponents: null,

http://git-wip-us.apache.org/repos/asf/ambari/blob/88a87221/ambari-web/app/controllers/wizard/step2_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/wizard/step2_controller.js b/ambari-web/app/controllers/wizard/step2_controller.js
index 5c38a9a..c408b37 100644
--- a/ambari-web/app/controllers/wizard/step2_controller.js
+++ b/ambari-web/app/controllers/wizard/step2_controller.js
@@ -94,6 +94,14 @@ App.WizardStep2Controller = Em.Controller.extend({
   }.property('content.installOptions.sshUser'),
 
   /**
+   * "Shortcut" to <code>content.installOptions.agentUser</code>
+   * @type {string}
+   */
+  agentUser: function () {
+    return this.get('content.installOptions.agentUser');
+  }.property('content.installOptions.agentUser'),
+
+  /**
    * Installed type based on <code>manualInstall</code>
    * @type {string}
    */
@@ -140,12 +148,23 @@ App.WizardStep2Controller = Em.Controller.extend({
   }.property('sshUser', 'hasSubmitted', 'manualInstall'),
 
   /**
+   * Error-message if <code>agentUser</code> is empty, null otherwise
+   * @type {string|null}
+   */
+  agentUserError: function () {
+    if (this.get('manualInstall') === false && Em.isEmpty(this.get('agentUser').trim())) {
+      return Em.I18n.t('installer.step2.sshUser.required');
+    }
+    return null;
+  }.property('agentUser', 'hasSubmitted', 'manualInstall'),
+
+  /**
    * is Submit button disabled
    * @type {bool}
    */
   isSubmitDisabled: function () {
-    return (this.get('hostsError') || this.get('sshKeyError') || this.get('sshUserError'));
-  }.property('hostsError', 'sshKeyError', 'sshUserError'),
+    return (this.get('hostsError') || this.get('sshKeyError') || this.get('sshUserError') || this.get('agentUserError'));
+  }.property('hostsError', 'sshKeyError', 'sshUserError', 'agentUserError'),
 
   installedHostNames: function () {
     var installedHostsName = [];
@@ -273,7 +292,7 @@ App.WizardStep2Controller = Em.Controller.extend({
       this.set('hostsError', Em.I18n.t('installer.step2.hostName.error.already_installed'));
     }
 
-    if (this.get('hostsError') || this.get('sshUserError') || this.get('sshKeyError')) {
+    if (this.get('hostsError') || this.get('sshUserError') || this.get('agentUserError') || this.get('sshKeyError')) {
       return false;
     }
 
@@ -361,7 +380,13 @@ App.WizardStep2Controller = Em.Controller.extend({
    */
   setupBootStrap: function () {
     var self = this;
-    var bootStrapData = JSON.stringify({'verbose': true, 'sshKey': this.get('sshKey'), 'hosts': this.get('hostNameArr'), 'user': this.get('sshUser')});
+    var bootStrapData = JSON.stringify({
+      'verbose': true,
+      'sshKey': this.get('sshKey'),
+      'hosts': this.get('hostNameArr'),
+      'user': this.get('sshUser'),
+      'userRunAs': this.get('agentUser')
+    });
     App.router.get(this.get('content.controllerName')).launchBootstrap(bootStrapData, function (requestId) {
       if (requestId == '0') {
         var controller = App.router.get(App.clusterStatus.wizardControllerName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/88a87221/ambari-web/app/controllers/wizard/step3_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/wizard/step3_controller.js b/ambari-web/app/controllers/wizard/step3_controller.js
index 11b67ca..0caf756 100644
--- a/ambari-web/app/controllers/wizard/step3_controller.js
+++ b/ambari-web/app/controllers/wizard/step3_controller.js
@@ -349,7 +349,8 @@ App.WizardStep3Controller = Em.Controller.extend({
         'verbose': true,
         'sshKey': this.get('content.installOptions.sshKey'),
         'hosts': hosts.mapProperty('name'),
-        'user': this.get('content.installOptions.sshUser')}
+        'user': this.get('content.installOptions.sshUser'),
+        'userRunAs': this.get('content.installOptions.agentUser')}
     );
     this.set('numPolls', 0);
     this.set('registrationStartedAt', null);

http://git-wip-us.apache.org/repos/asf/ambari/blob/88a87221/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 8947b3b..42f8da1 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -474,6 +474,7 @@ Em.I18n.translations = {
   'installer.step2.sshUser.toolTip':'An account that can execute sudo without entering a password',
   'installer.step2.sshUser.placeholder':'Enter user name',
   'installer.step2.sshUser.required':'User name is required',
+  'installer.step2.agentUser':'Ambari Agent user (root or',
   'installer.step2.bootStrap.error':'Errors were encountered while setting up Ambari Agents on the hosts.',
   'installer.step2.bootStrap.inProgress':'Please wait while Ambari Agents are being set up on the hosts. This can take several minutes depending on the number of hosts.',
   'installer.step2.bootStrap.header':'Setting Up Ambari Agents',

http://git-wip-us.apache.org/repos/asf/ambari/blob/88a87221/ambari-web/app/templates/wizard/step2.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/wizard/step2.hbs b/ambari-web/app/templates/wizard/step2.hbs
index 911eae4..dbf425c 100644
--- a/ambari-web/app/templates/wizard/step2.hbs
+++ b/ambari-web/app/templates/wizard/step2.hbs
@@ -68,8 +68,8 @@
               <span class="help-inline">{{sshKeyError}}</span>
             {{/if}}
           </div>
-          <div>
-            <label class="ssh-user pull-left">
+          <div class="row-fluid">
+            <label class="ssh-user pull-left span5">
               {{t installer.step2.sshUser}}
               <a href="javascript:void(null)"
                  rel="popover"
@@ -85,6 +85,24 @@
               {{/if}}
             </div>
           </div>
+          <div class="row-fluid">
+            <label class="ssh-user pull-left span5">
+              {{t installer.step2.agentUser}}
+              <a href="javascript:void(null)"
+                 rel="popover"
+                {{translateAttr title="installer.step2.sshUser.link" data-content="installer.step2.sshUser.toolTip"}}>
+                {{t installer.step2.sshUser.link}}</a>
+              {{t installer.step2.sshUser.account}}
+            </label>
+
+            <div {{bindAttr class="agentUserError:error :control-group"}}>
+              {{view view.textFieldView valueBinding="content.installOptions.agentUser" isEnabledBinding="content.installOptions.useSsh"}}
+              {{#if agentUserError}}
+                <span class="help-inline">{{agentUserError}}</span>
+              {{/if}}
+            </div>
+          </div>
+
         </div>
       {{/if}}
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/88a87221/ambari-web/test/controllers/wizard/step2_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/wizard/step2_test.js b/ambari-web/test/controllers/wizard/step2_test.js
index 1d91570..da7cd6a 100644
--- a/ambari-web/test/controllers/wizard/step2_test.js
+++ b/ambari-web/test/controllers/wizard/step2_test.js
@@ -25,6 +25,30 @@ require('messages');
 var c;
 describe('App.WizardStep2Controller', function () {
 
+  var userErrorTests = Em.A([
+    {
+      manualInstall: false,
+      user: '',
+      e: ''
+    },
+    {
+      manualInstall: true,
+      user: '',
+      e: null
+    },
+    {
+      manualInstall: true,
+      user: 'nobody',
+      e: null
+    },
+    {
+      manualInstall: false,
+      user: 'nobody',
+      e: null
+    }
+  ]);
+
+
   beforeEach(function() {
     c = App.WizardStep2Controller.create();
   });
@@ -76,6 +100,15 @@ describe('App.WizardStep2Controller', function () {
     });
   });
 
+  describe('#agentUser', function() {
+    it('should be equal to content.installOptions.agentUser', function() {
+      var controller = App.WizardStep2Controller.create({content: {installOptions: {agentUser: '123'}}});
+      expect(controller.get('agentUser')).to.equal('123');
+      controller.set('content.installOptions.agentUser', '321');
+      expect(controller.get('agentUser')).to.equal('321');
+    });
+  });
+
   describe('#installType', function() {
     it('should be manualDriven if manualInstall is selected', function() {
       var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: true}}});
@@ -238,32 +271,9 @@ describe('App.WizardStep2Controller', function () {
 
   describe('#sshUserError', function () {
 
-    var tests = Em.A([
-      {
-        manualInstall: false,
-        sshUser: '',
-        e: ''
-      },
-      {
-        manualInstall: true,
-        sshUser: '',
-        e: null
-      },
-      {
-        manualInstall: true,
-        sshUser: 'nobody',
-        e: null
-      },
-      {
-        manualInstall: false,
-        sshUser: 'nobody',
-        e: null
-      }
-    ]);
-
-    tests.forEach(function(test) {
+    userErrorTests.forEach(function(test) {
       it('', function() {
-        var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshUser: test.sshUser}}});
+        var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshUser: test.user}}});
         if(Em.isNone(test.e)) {
           expect(controller.get('sshUserError')).to.equal(null);
         }
@@ -275,6 +285,22 @@ describe('App.WizardStep2Controller', function () {
 
   });
 
+  describe('#agentUserError', function () {
+
+    userErrorTests.forEach(function(test) {
+      it('', function() {
+        var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, agentUser: test.user}}});
+        if(Em.isNone(test.e)) {
+          expect(controller.get('agentUserError')).to.equal(null);
+        }
+        else {
+          expect(controller.get('agentUserError').length).to.be.above(2);
+        }
+      });
+    });
+
+  });
+
   describe('#getHostInfo()', function () {
 
     it('should return object with bootStatus, installType and name for every element in hostNameArr', function () {
@@ -331,6 +357,24 @@ describe('App.WizardStep2Controller', function () {
       expect(controller.evaluateStep()).to.equal(false);
     });
 
+    it('should return false if sshUserError is not empty', function () {
+      var controller = App.WizardStep2Controller.create({
+        hostNames: 'apache.ambari',
+        parseHostNamesAsPatternExpression: Em.K
+      });
+      controller.reopen({sshUserError: 'error'});
+      expect(controller.evaluateStep()).to.equal(false);
+    });
+
+    it('should return false if agentUserError is not empty', function () {
+      var controller = App.WizardStep2Controller.create({
+        hostNames: 'apache.ambari',
+        parseHostNamesAsPatternExpression: Em.K
+      });
+      controller.reopen({agentUserError: 'error'});
+      expect(controller.evaluateStep()).to.equal(false);
+    });
+
     it('should return false if hostNameArr is empty', function () {
       var controller = App.WizardStep2Controller.create({
         hostNames: '',
@@ -448,7 +492,9 @@ describe('App.WizardStep2Controller', function () {
 
     var controller = App.WizardStep2Controller.create({
       hostsError: '',
-      sshKeyError: ''
+      sshKeyError: '',
+      sshUserError: '',
+      agentUserError: ''
     });
 
     it('should return value if hostsError is not empty', function () {
@@ -460,7 +506,19 @@ describe('App.WizardStep2Controller', function () {
       controller.set('sshKeyError', 'error');
       controller.set('hostsError', '');
       expect(controller.get('isSubmitDisabled').length).to.above(0);
-    })
+    });
+
+    it('should return value if sshUserError is not empty', function () {
+      controller.set('sshUserError', 'error');
+      controller.set('sshKeyError', '');
+      expect(controller.get('isSubmitDisabled').length).to.above(0);
+    });
+
+    it('should return value if agentUserError is not empty', function () {
+      controller.set('agentUserError', 'error');
+      controller.set('sshUserError', '');
+      expect(controller.get('isSubmitDisabled').length).to.above(0);
+    });
   });
 
   describe('#installedHostsPopup', function() {
@@ -616,4 +674,31 @@ describe('App.WizardStep2Controller', function () {
     });
   });
 
+  describe('#setupBootStrap', function () {
+
+    var controller = App.WizardStep2Controller.create({
+      sshKey: 'key',
+      hostNameArr: ['host0', 'host1'],
+      sshUser: 'root',
+      agentUser: 'user',
+      content: {
+        controllerName: 'installerController'
+      }
+    });
+
+    it('bootstrap data passed correctly', function () {
+      sinon.spy(App.router.get('installerController'), 'launchBootstrap');
+      controller.setupBootStrap();
+      expect(App.router.get('installerController.launchBootstrap').firstCall.args[0]).to.equal(JSON.stringify({
+        verbose: true,
+        sshKey: 'key',
+        hosts: ['host0', 'host1'],
+        user: 'root',
+        userRunAs: 'user'
+      }));
+      App.router.get('installerController.launchBootstrap').restore();
+    });
+
+  });
+
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/88a87221/ambari-web/test/controllers/wizard/step3_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/wizard/step3_test.js b/ambari-web/test/controllers/wizard/step3_test.js
index d635911..742b4d6 100644
--- a/ambari-web/test/controllers/wizard/step3_test.js
+++ b/ambari-web/test/controllers/wizard/step3_test.js
@@ -473,6 +473,22 @@ describe('App.WizardStep3Controller', function () {
       c.retryHosts(Em.A([]));
       expect(installer.launchBootstrap.calledOnce).to.be.true;
     });
+    it('bootstrap data passed correctly', function () {
+      var controller = App.WizardStep2Controller.create({
+        sshKey: 'key',
+        hostNameArr: ['host0', 'host1'],
+        sshUser: 'root',
+        agentUser: 'user'
+      });
+      controller.setupBootStrap();
+      expect(installer.launchBootstrap.firstCall.args[0]).to.equal(JSON.stringify({
+        verbose: true,
+        sshKey: 'key',
+        hosts: ['host0', 'host1'],
+        user: 'root',
+        userRunAs: 'user'
+      }));
+    });
   });
 
   describe('#retryHost', function() {