ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [08/12] ambari git commit: AMBARI-18627. Add service wizard hung at Choose services page as no ClusterStackVersion is available with state=CURRENT (alexantonenko)
Date Tue, 18 Oct 2016 19:33:00 GMT
AMBARI-18627. Add service wizard hung at Choose services page as no ClusterStackVersion is
available with state=CURRENT (alexantonenko)


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

Branch: refs/heads/branch-feature-AMBARI-18456
Commit: ee2a12527864dd1238b18366badfec89465444b3
Parents: 3fc0b3e
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Tue Oct 18 17:00:16 2016 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Tue Oct 18 18:03:24 2016 +0300

----------------------------------------------------------------------
 .../main/admin/stack_and_upgrade_controller.js  |  22 ++-
 ambari-web/app/controllers/wizard.js            |  12 +-
 ambari-web/app/utils/ajax/ajax.js               |   2 +-
 .../admin/stack_and_upgrade_controller_test.js  | 154 ++++++++++++++++---
 4 files changed, 156 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ee2a1252/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js b/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
index 01feb14..58344b2 100644
--- a/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
+++ b/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
@@ -678,7 +678,7 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
       },
       error: errorCallback
     });
-  },  
+  },
 
   /**
    * error callback of <code>abortUpgrade()</code>
@@ -1430,7 +1430,7 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
       stackVersionNumber = App.get('currentStackVersion');
     return stackVersionNumber;
   },
-  
+
   /**
    * perform validation if <code>skip<code> is  false and run save if
    * validation successfull or run save without validation is <code>skip<code>
is true
@@ -1447,7 +1447,7 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
       } else {
         var repoVersion = self.prepareRepoForSaving(repo);
         var stackVersionNumber = self.getStackVersionNumber(repo);
-        
+
         App.ajax.send({
           name: 'admin.stack_versions.edit.repo',
           sender: this,
@@ -1464,7 +1464,7 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
     });
     return deferred.promise();
   },
-  
+
   /**
    * send request for validation for each repository
    * @param {Em.Object} repo
@@ -1475,7 +1475,7 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
     var deferred = $.Deferred(),
       totalCalls = 0,
       invalidUrls = [];
-    
+
     if (skip) {
       deferred.resolve(invalidUrls);
     } else {
@@ -1903,10 +1903,16 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
    * @param {object|null} jsonData
    */
   loadServiceVersionFromVersionDefinitionsSuccessCallback: function (jsonData) {
-    var rv = jsonData.items[0].repository_versions[0].RepositoryVersions;
+    var versions = Em.getWithDefault(jsonData, 'items', []);
+    var currentVersion = versions.filterProperty('ClusterStackVersions.state', 'CURRENT')[0];
+    var rv = currentVersion || versions.filter(function(i) {
+      return i.ClusterStackVersions.stack === App.get('currentStackName') &&
+       i.ClusterStackVersions.version === App.get('currentStackVersionNumber');
+    })[0];
     var map = this.get('serviceVersionsMap');
-    if (rv) {
-      rv.stack_services.forEach(function (item) {
+    var stackServices = Em.getWithDefault(rv || {}, 'repository_versions.0.RepositoryVersions.stack_services',
false);
+    if (stackServices) {
+      stackServices.forEach(function (item) {
         map[item.name] = item.versions[0];
       });
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/ee2a1252/ambari-web/app/controllers/wizard.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/wizard.js b/ambari-web/app/controllers/wizard.js
index e0df4fa..05cd35c 100644
--- a/ambari-web/app/controllers/wizard.js
+++ b/ambari-web/app/controllers/wizard.js
@@ -696,10 +696,16 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingM
 
   serviceVersionsMap: {},
   loadServiceVersionFromVersionDefinitionsSuccessCallback: function (jsonData) {
-    var rv = jsonData.items[0].repository_versions[0].RepositoryVersions;
+    var versions = Em.getWithDefault(jsonData, 'items', []);
+    var currentVersion = versions.filterProperty('ClusterStackVersions.state', 'CURRENT')[0];
+    var rv = currentVersion || versions.filter(function(i) {
+      return i.ClusterStackVersions.stack === App.get('currentStackName') &&
+       i.ClusterStackVersions.version === App.get('currentStackVersionNumber');
+    })[0];
     var map = this.get('serviceVersionsMap');
-    if (rv) {
-      rv.stack_services.forEach(function (item) {
+    var stackServices = Em.getWithDefault(rv || {}, 'repository_versions.0.RepositoryVersions.stack_services',
false);
+    if (stackServices) {
+      stackServices.forEach(function (item) {
         map[item.name] = item.versions[0];
       });
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/ee2a1252/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index a5eafef..b761a14 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -1387,7 +1387,7 @@ var urls = {
     'mock': '/data/stack_versions/stack_version_all.json'
   },
   'cluster.load_current_repo_stack_services': {
-    'real': '/clusters/{clusterName}/stack_versions?ClusterStackVersions/state=CURRENT&fields=repository_versions/RepositoryVersions/stack_services',
+    'real': '/clusters/{clusterName}/stack_versions?fields=repository_versions/RepositoryVersions/stack_services,ClusterStackVersions/state',
     'mock': '/data/stack_versions/stack_version_all.json'
   },
   'cluster.save_provisioning_state': {

http://git-wip-us.apache.org/repos/asf/ambari/blob/ee2a1252/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js b/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
index ecf861d..21942d4 100644
--- a/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
+++ b/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
@@ -3121,31 +3121,141 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   });
 
   describe("#loadServiceVersionFromVersionDefinitionsSuccessCallback()", function () {
+    var cases;
+    beforeEach(function() {
+      this.appGetStub = sinon.stub(App, 'get');
+    });
 
-    it("serviceVersionsMap should be set", function() {
+    afterEach(function() {
+      App.get.restore();
       controller.set('serviceVersionsMap', {});
-      var data = {
-        items: [
-          {
-            repository_versions: [
-              {
-                RepositoryVersions: {
-                  stack_services: [
-                    {
-                      name: 'S1',
-                      versions: ['v1']
-                    }
-                  ]
+    });
+    cases = [
+      {
+        jsonData: {
+          items: [
+            {
+              ClusterStackVersions: {
+                state: 'CURRENT'
+              },
+              repository_versions: [
+                {
+                  RepositoryVersions: {
+                    stack_services: [
+                      { name: 'S1', versions: ['v1']}
+                    ]
+                  }
                 }
-              }
-            ]
-          }
-        ]
-      };
-      controller.loadServiceVersionFromVersionDefinitionsSuccessCallback(data);
-      expect(controller.get('serviceVersionsMap')).to.be.eql({
-        "S1": "v1"
-      });
+              ]
+            }
+          ]
+        },
+        currentStackData: {
+          currentStackVersionNumber: '2.2',
+          currentStackName: 'HDP'
+        },
+        m: 'should add stack services from stack version with state CURRENT',
+        e: { "S1": "v1"}
+      },
+      {
+        jsonData: {
+          items: [
+            {
+              ClusterStackVersions: {
+                version: '2.3',
+                stack: 'HDP',
+                state: 'INIT'
+              },
+              repository_versions: [
+                {
+                  RepositoryVersions: {
+                    stack_services: [
+                      { name: 'S3', versions: ['v3']}
+                    ]
+                  }
+                }
+              ]
+            },
+            {
+              ClusterStackVersions: {
+                version: '2.2',
+                stack: 'HDP',
+                state: 'INIT'
+              },
+              repository_versions: [
+                {
+                  RepositoryVersions: {
+                    stack_services: [
+                      { name: 'S2', versions: ['v2']}
+                    ]
+                  }
+                }
+              ]
+            }
+          ]
+        },
+        currentStackData: {
+          currentStackVersionNumber: '2.2',
+          currentStackName: 'HDP'
+        },
+        m: 'should add stack services from stack version by current stack name and version
number' +
+           'when CURRENT version not available',
+        e: { "S2": "v2"}
+      },
+      {
+        jsonData: {
+          items: [
+            {
+              ClusterStackVersions: {
+                version: '2.3',
+                stack: 'HDP',
+                state: 'CURRENT'
+              },
+              repository_versions: [
+                {
+                  RepositoryVersions: {
+                    stack_services: [
+                      { name: 'S3', versions: ['v3']}
+                    ]
+                  }
+                }
+              ]
+            },
+            {
+              ClusterStackVersions: {
+                version: '2.2',
+                stack: 'HDP',
+                state: 'INIT'
+              },
+              repository_versions: [
+                {
+                  RepositoryVersions: {
+                    stack_services: [
+                      { name: 'S2', versions: ['v2']}
+                    ]
+                  }
+                }
+              ]
+            }
+          ]
+        },
+        currentStackData: {
+          currentStackVersionNumber: '2.2',
+          currentStackName: 'HDP'
+        },
+        m: 'should add stack services by state CURRENT even when there is stack version with
' +
+           'current stack name and version number',
+        e: { "S3": "v3"}
+      }
+    ];
+
+    cases.forEach(function(test) {
+      it(test.m, function() {
+        this.appGetStub.withArgs('currentStackName').returns(test.currentStackData.currentStackName)
+          .withArgs('currentStackVersionNumber').returns(test.currentStackData.currentStackVersionNumber);
+        controller.loadServiceVersionFromVersionDefinitionsSuccessCallback(test.jsonData);
+        expect(controller.get('serviceVersionsMap')).to.be.eql(test.e);
+      })
     });
   });
 


Mime
View raw message