Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 c3e60d3f1 -> f22ae6e8e


AMBARI-14667. Cannot add new service when kerberos is enabled w/ blueprint 
(alexantonenko)


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

Branch: refs/heads/branch-2.2
Commit: f22ae6e8e49e259c4bbaf7be441c910437237d3f
Parents: c3e60d3
Author: Alex Antonenko <[email protected]>
Authored: Thu Jan 14 16:46:57 2016 +0200
Committer: Alex Antonenko <[email protected]>
Committed: Thu Jan 14 16:54:31 2016 +0200

----------------------------------------------------------------------
 .../app/controllers/wizard/step8_controller.js  |  4 +-
 .../app/mixins/wizard/addSecurityConfigs.js     | 16 ++++
 .../admin/kerberos/step4_controller_test.js     | 85 +++++++++++++++++---
 3 files changed, 95 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f22ae6e8/ambari-web/app/controllers/wizard/step8_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/wizard/step8_controller.js 
b/ambari-web/app/controllers/wizard/step8_controller.js
index 13754c7..aa1d97b 100644
--- a/ambari-web/app/controllers/wizard/step8_controller.js
+++ b/ambari-web/app/controllers/wizard/step8_controller.js
@@ -842,8 +842,10 @@ App.WizardStep8Controller = 
Em.Controller.extend(App.AddSecurityConfigs, App.wiz
    */
   updateKerberosDescriptor: function(instant) {
     var kerberosDescriptor = App.db.get('KerberosWizard', 
'kerberosDescriptorConfigs');
+    var descriptorExists = 
this.get('wizardController').getDBProperty('isClusterDescriptorExists') === 
true;
+
     var ajaxOpts = {
-      name: 'admin.kerberos.cluster.artifact.update',
+      name: descriptorExists ? 'admin.kerberos.cluster.artifact.update' : 
'admin.kerberos.cluster.artifact.create',
       data: {
         artifactName: 'kerberos_descriptor',
         data: {

http://git-wip-us.apache.org/repos/asf/ambari/blob/f22ae6e8/ambari-web/app/mixins/wizard/addSecurityConfigs.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/wizard/addSecurityConfigs.js 
b/ambari-web/app/mixins/wizard/addSecurityConfigs.js
index 795091a..d6dd240 100644
--- a/ambari-web/app/mixins/wizard/addSecurityConfigs.js
+++ b/ambari-web/app/mixins/wizard/addSecurityConfigs.js
@@ -391,8 +391,10 @@ App.AddSecurityConfigs = Em.Mixin.create({
     this.loadStackDescriptorConfigs().then(function(data) {
       var stackArtifacts = data;
       self.loadClusterDescriptorConfigs().then(function(clusterArtifacts) {
+        self.storeClusterDescriptorStatus(true);
         
dfd.resolve(self.createServicesStackDescriptorConfigs(objectUtils.deepMerge(data,
 clusterArtifacts)));
       }, function() {
+        self.storeClusterDescriptorStatus(false);
         dfd.resolve(self.createServicesStackDescriptorConfigs(stackArtifacts));
       });
     }, function() {
@@ -401,6 +403,20 @@ App.AddSecurityConfigs = Em.Mixin.create({
     return dfd.promise();
   },
 
+
+  /**
+   * Store status of kerberos descriptor located in cluster artifacts.
+   * This status needed for Add Service Wizard to select appropriate method to 
create
+   * or update descriptor.
+   *
+   * @param  {Boolean} isExists <code>true</code> if cluster descriptor present
+   */
+  storeClusterDescriptorStatus: function(isExists) {
+    if (this.get('isWithinAddService')) {
+      this.get('wizardController').setDBProperty('isClusterDescriptorExists', 
isExists);
+    }
+  },
+
   /**
    *
    * @param {object[]} items - stack descriptor json response

http://git-wip-us.apache.org/repos/asf/ambari/blob/f22ae6e8/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js 
b/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js
index 4f36363..39c1ef3 100644
--- a/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js
+++ b/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js
@@ -19,14 +19,14 @@
 var App = require('app');
 
 describe('App.KerberosWizardStep4Controller', function() {
-  
+
   describe('#isSubmitDisabled', function() {
     var controller = App.KerberosWizardStep4Controller.create({});
     var configs = Em.A([
       App.ServiceConfigProperty.create({ name: 'prop1', value: 'someVal1', 
identityType: 'user', category: 'Ambari Principals', serviceName: 'Cluster'})
     ]);
     controller.set('stepConfigs', controller.createServiceConfig(configs));
-    
+
     it('configuration errors are absent, submit should be not disabled', 
function() {
       expect(controller.get('stepConfigs')[0].get('errorCount')).to.be.eql(0);
       expect(controller.get('isSubmitDisabled')).to.be.false;
@@ -37,7 +37,7 @@ describe('App.KerberosWizardStep4Controller', function() {
       serviceConfig.get('configs').findProperty('name', 'prop1').set('value', 
'');
       expect(serviceConfig.get('errorCount')).to.be.eql(1);
       expect(controller.get('isSubmitDisabled')).to.be.true;
-    });  
+    });
   });
 
   describe('#createServiceConfig', function() {
@@ -92,7 +92,7 @@ describe('App.KerberosWizardStep4Controller', function() {
       Em.Object.create({ name: 'hdfs_principal', value: 
'hdfs_principal_value', identityType: 'user', serviceName: 'HDFS' }),
       Em.Object.create({ name: 'hadoop.security.auth_to_local', serviceName: 
'HDFS' })
     ]);
-    
+
     var propertyValidationCases = [
       {
         property: 'spnego_keytab',
@@ -123,9 +123,9 @@ describe('App.KerberosWizardStep4Controller', function() {
         ]
       }
     ];
-    
+
     var absentPropertiesTest = ['falcon_keytab', 'mapreduce_keytab'];
-    
+
     it('should contains properties only for installed services', function() {
       
expect(this.result.mapProperty('serviceName').uniq()).to.be.eql(['Cluster', 
'HDFS']);
     });
@@ -135,7 +135,7 @@ describe('App.KerberosWizardStep4Controller', function() {
         expect(this.result.findProperty('name', item)).to.be.undefined;
       });
     }, this);
-    
+
     propertyValidationCases.forEach(function(test) {
       it('property {0} should be created'.format(test.property), function() {
         expect(this.result.findProperty('name', test.property)).to.be.ok;
@@ -151,7 +151,7 @@ describe('App.KerberosWizardStep4Controller', function() {
       }, this);
     });
   });
-  
+
   describe('#setStepConfigs', function() {
     describe('Add Service Wizard', function() {
       var res;
@@ -214,7 +214,7 @@ describe('App.KerberosWizardStep4Controller', function() {
         { name: 'admin_principal', e: true },
         { name: 'admin_password', e: true }
       ];
-      
+
       propertiesEditableTests.forEach(function(test) {
         it('Add Service: property `{0}` should be {1} 
editable'.format(test.name, !!test.e ? '' : 'not '), function() {
           expect(res.findProperty('name', 
test.name).get('isEditable')).to.eql(test.e);
@@ -330,4 +330,71 @@ describe('App.KerberosWizardStep4Controller', function() {
     });
   });
 
+  describe('#getDescriptorConfigs', function() {
+    describe('Within Add Service', function () {
+      var controller;
+      beforeEach(function () {
+        controller = App.KerberosWizardStep4Controller.create({
+          wizardController: Em.Object.create({
+            name: 'addServiceController',
+            setDBProperty: sinon.spy()
+          })
+        });
+        this.loadStackDescriptorStub = sinon.stub(controller, 
'loadStackDescriptorConfigs').returns($.Deferred().resolve().promise());
+        this.loadClusterDescriptorStub = sinon.stub(controller, 
'loadClusterDescriptorConfigs');
+        sinon.stub(controller, 'createServicesStackDescriptorConfigs', Em.K);
+      });
+
+      afterEach(function() {
+        this.loadStackDescriptorStub.restore();
+        this.loadClusterDescriptorStub.restore();
+        controller.createServicesStackDescriptorConfigs.restore();
+        controller.destroy();
+        controller = null;
+      });
+
+      var cases = [
+        {
+          wizardController: 'addServiceController',
+          clusterDescriptorExists: false,
+          m: 'Within Add Service, Cluster Descriptor not exists. Should be 
reflected in wizard controller',
+          e: {
+            setDBPropertyCalled: true,
+            setDBPropertyCalledWith: ['isClusterDescriptorExists', false]
+          }
+        },
+        {
+          wizardController: 'addServiceController',
+          clusterDescriptorExists: true,
+          m: 'Within Add Service, Cluster Descriptor is present. Should be 
reflected in wizard controller',
+          e: {
+            setDBPropertyCalled: true,
+            setDBPropertyCalledWith: ['isClusterDescriptorExists', true]
+          }
+        },
+        {
+          wizardController: 'notAddService',
+          clusterDescriptorExists: true,
+          m: 'Within another controller, nothing to store',
+          e: {
+            setDBPropertyCalled: false,
+          }
+        }
+      ];
+
+      cases.forEach(function(test) {
+        it(test.m, function () {
+          controller.get('wizardController').set('name', 
test.wizardController);
+          this.loadClusterDescriptorStub.returns(test.clusterDescriptorExists ?
+             $.Deferred().resolve().promise() :
+             $.Deferred().reject().promise());
+          controller.getDescriptorConfigs();
+          
expect(controller.get('wizardController').setDBProperty.called).to.be.eql(test.e.setDBPropertyCalled);
+          if (test.e.setDBPropertyCalled) {
+            
expect(controller.get('wizardController').setDBProperty.args[0]).to.be.eql(test.e.setDBPropertyCalledWith);
+          }
+        })
+      })
+    });
+  });
 });

Reply via email to