ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhew...@apache.org
Subject ambari git commit: AMBARI-16282 Refactor the VDF installer code to handle multi-stack and multi-version scenario (zhewang)
Date Fri, 06 May 2016 17:29:01 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 3c12461db -> abe7eb50f


AMBARI-16282 Refactor the VDF installer code to handle multi-stack and multi-version scenario
(zhewang)


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

Branch: refs/heads/trunk
Commit: abe7eb50fdf06f8410717476261ff8e952f4b174
Parents: 3c12461
Author: Zhe (Joe) Wang <zhewang@apache.org>
Authored: Fri May 6 10:27:59 2016 -0700
Committer: Zhe (Joe) Wang <zhewang@apache.org>
Committed: Fri May 6 10:27:59 2016 -0700

----------------------------------------------------------------------
 ambari-web/app/controllers/installer.js      | 112 ++++++++++------------
 ambari-web/app/mappers/stack_mapper.js       |  83 ++++++++--------
 ambari-web/app/views/wizard/step1_view.js    |   4 +-
 ambari-web/test/mappers/stack_mapper_test.js |   4 +-
 4 files changed, 96 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/abe7eb50/ambari-web/app/controllers/installer.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/installer.js b/ambari-web/app/controllers/installer.js
index 369e319..8981845 100644
--- a/ambari-web/app/controllers/installer.js
+++ b/ambari-web/app/controllers/installer.js
@@ -304,9 +304,9 @@ App.InstallerController = App.WizardController.extend({
    * Parse loaded data and create array of stacks objects
    */
   loadStacksVersionsDefinitionsSuccessCallback: function (data) {
-    var self = this;
     var stacks = App.db.getStacks();
     var repos = App.db.getRepos();
+    this.decrementProperty('loadStacksRequestsCounter');
     var isStacksExistInDb = stacks && stacks.length;
     if (isStacksExistInDb) {
       stacks.forEach(function (_stack) {
@@ -317,40 +317,14 @@ App.InstallerController = App.WizardController.extend({
       }, this);
     }
 
-    var versionDefinition = data.items[0];
-    // to display repos panel, should map all available operating systems including empty
ones
-    this.getSupportedOSList(versionDefinition.VersionDefinition.stack_name, versionDefinition.VersionDefinition.stack_version).complete(function
() {
-      var existedOS = versionDefinition.operating_systems;
-      var existedMap = {};
-      existedOS.map(function (existedOS) {
-        existedOS.isSelected = true;
-        existedMap[existedOS.OperatingSystems.os_type] = existedOS;
-      });
-      self.get('allSupportedOS').forEach(function(supportedOS) {
-        if(!existedMap[supportedOS.OperatingSystems.os_type]) {
-          supportedOS.isSelected = false;
-          supportedOS.repositories.forEach(function(repo) {
-            repo.Repositories.base_url = '';
-          });
-          existedOS.push(supportedOS);
-        }
-      });
-      App.stackMapper.map(data.items, "VersionDefinition");
-      if (!self.decrementProperty('loadStacksRequestsCounter')) {
-
-        var versionData = self.getSelectedRepoVersionData();
-        if (versionData) {
-          self.postVersionDefinitionFile(versionData.isXMLdata, versionData.data).done(function
(versionInfo) {
-            self.mergeChanges(repos, stacks);
-            App.Stack.find().setEach('isSelected', false);
-            App.Stack.find().findProperty('id', versionInfo.stackNameVersion + "-" + versionInfo.actualVersion).set('isSelected',
true);
-            self.setSelected(isStacksExistInDb);
-          });
-        } else {
-          self.setSelected(isStacksExistInDb);
-        }
-      }
-    });
+    data.items.sortProperty('VersionDefinition.stack_version').reverse().forEach(function
(versionDefinition) {
+      // to display repos panel, should map all available operating systems including empty
ones
+      var stackInfo = {};
+      stackInfo.isStacksExistInDb = isStacksExistInDb;
+      stackInfo.stacks = stacks;
+      stackInfo.repos = repos;
+      this.getSupportedOSList(versionDefinition, stackInfo);
+    }, this);
   },
 
   mergeChanges: function (repos, stacks) {
@@ -653,25 +627,10 @@ App.InstallerController = App.WizardController.extend({
       response.services = services;
 
       // to display repos panel, should map all available operating systems including empty
ones
-      this.getSupportedOSList(response.stackName, response.stackVersion).complete(function
() {
-        var existedOS = data.operating_systems;
-        var existedMap = {};
-        existedOS.map(function (existedOS) {
-          existedOS.isSelected = true;
-          existedMap[existedOS.OperatingSystems.os_type] = existedOS;
-        });
-        self.get('allSupportedOS').forEach(function(supportedOS) {
-          if(!existedMap[supportedOS.OperatingSystems.os_type]) {
-            supportedOS.isSelected = false;
-            supportedOS.repositories.forEach(function(repo) {
-              repo.Repositories.base_url = '';
-            });
-            existedOS.push(supportedOS);
-          }
-        });
-        App.stackMapper.map(_data.resources, "VersionDefinition");
-        dataInfo.dfd.resolve(response);
-      });
+      var stackInfo = {};
+      stackInfo.dfd = dataInfo.dfd;
+      stackInfo.response = response;
+      this.getSupportedOSList(data, stackInfo);
     }
   },
 
@@ -723,13 +682,16 @@ App.InstallerController = App.WizardController.extend({
     App.showAlertPopup(header, body);
   },
 
-  getSupportedOSList: function (stackName, stackVersion) {
+  getSupportedOSList: function (versionDefinition, stackInfo) {
+    this.incrementProperty('loadStacksRequestsCounter');
     return  App.ajax.send({
       name: 'wizard.step1.get_supported_os_types',
       sender: this,
       data: {
-        stackName: stackName,
-        stackVersion: stackVersion
+        stackName: versionDefinition.VersionDefinition.stack_name,
+        stackVersion: versionDefinition.VersionDefinition.stack_version,
+        versionDefinition: versionDefinition,
+        stackInfo: stackInfo
       },
       success: 'getSupportedOSListSuccessCallback',
       error: 'getSupportedOSListErrorCallback'
@@ -740,8 +702,40 @@ App.InstallerController = App.WizardController.extend({
    * onSuccess callback for getSupportedOSList.
    */
   getSupportedOSListSuccessCallback: function (response, request, data) {
-    if (response.operating_systems) {
-      this.set('allSupportedOS', response.operating_systems);
+    var self = this;
+    var existedOS = data.versionDefinition.operating_systems;
+    var existedMap = {};
+    existedOS.map(function (existedOS) {
+      existedOS.isSelected = true;
+      existedMap[existedOS.OperatingSystems.os_type] = existedOS;
+    });
+    response.operating_systems.forEach(function(supportedOS) {
+      if(!existedMap[supportedOS.OperatingSystems.os_type]) {
+        supportedOS.isSelected = false;
+        supportedOS.repositories.forEach(function(repo) {
+          repo.Repositories.base_url = '';
+        });
+        existedOS.push(supportedOS);
+      }
+    });
+    App.stackMapper.map(data.versionDefinition);
+
+    if (!this.decrementProperty('loadStacksRequestsCounter')) {
+      if (data.stackInfo.dfd) {
+        data.stackInfo.dfd.resolve(data.stackInfo.response);
+      } else {
+        var versionData = this.getSelectedRepoVersionData();
+        if (versionData) {
+          this.postVersionDefinitionFile(versionData.isXMLdata, versionData.data).done(function
(versionInfo) {
+            self.mergeChanges(data.stackInfo.repos, data.stackInfo.stacks);
+            App.Stack.find().setEach('isSelected', false);
+            App.Stack.find().findProperty('id', versionInfo.stackNameVersion + "-" + versionInfo.actualVersion).set('isSelected',
true);
+            self.setSelected(data.stackInfo.isStacksExistInDb);
+          });
+        } else {
+          this.setSelected(data.stackInfo.isStacksExistInDb);
+        }
+      }
     }
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/abe7eb50/ambari-web/app/mappers/stack_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/stack_mapper.js b/ambari-web/app/mappers/stack_mapper.js
index a430ea5..f9400c4 100644
--- a/ambari-web/app/mappers/stack_mapper.js
+++ b/ambari-web/app/mappers/stack_mapper.js
@@ -85,70 +85,63 @@ App.stackMapper = App.QuickDataMapper.create({
     operating_system_id: 'os_id'
   },
   
-  map: function(json, key) {
+  map: function(json) {
     var modelStack = this.get('modelStack');
     var modelOS = this.get('modelOS');
     var modelRepo = this.get('modelRepo');
     var modelServices = this.get('modelServices');
-    var resultStack = [];
     var resultOS = [];
     var resultRepo = [];
     var resultServices = [];
 
-    var stackVersions = json;
-    var propertiesKey = key;
-    stackVersions.sortProperty(key + '.stack_version').reverse().forEach(function(item) {
-      var stack = item[key];
-      var operatingSystemsArray = [];
-      var servicesArray = [];
+    var item = json;
+    var stack = item.VersionDefinition;
+    var operatingSystemsArray = [];
+    var servicesArray = [];
 
-      stack.id = stack.stack_name + "-" + stack.stack_version + "-" + stack.repository_version;
//HDP-2.5-2.5.0.0
+    stack.id = stack.stack_name + "-" + stack.stack_version + "-" + stack.repository_version;
//HDP-2.5-2.5.0.0
 
-      item.operating_systems.forEach(function(ops) {
-        var operatingSystems = ops.OperatingSystems;
+    item.operating_systems.forEach(function(ops) {
+      var operatingSystems = ops.OperatingSystems;
 
-        var repositoriesArray = [];
-        ops.repositories.forEach(function(repo) {
-          repo.Repositories.id = [stack.id, repo.Repositories.os_type, repo.Repositories.repo_id].join('-');
-          repo.Repositories.os_id = [stack.id, repo.Repositories.os_type].join('-');
-          if (!repo.Repositories.latest_base_url)  repo.Repositories.latest_base_url = repo.Repositories.base_url;
-          resultRepo.push(this.parseIt(repo.Repositories, this.get('configRepository')));
-          repositoriesArray.pushObject(repo.Repositories);
-        }, this);
-
-
-        operatingSystems.id = stack.id + "-" + operatingSystems.os_type;
-        operatingSystems.stack_id = operatingSystems.stack_name + "-" + operatingSystems.stack_version;
-        operatingSystems.repositories = repositoriesArray;
-        operatingSystems.is_selected = (ops.isSelected == true || ops.isSelected == undefined);
-        resultOS.push(this.parseIt(operatingSystems, this.get('configOS')));
-        operatingSystemsArray.pushObject(operatingSystems);
-        
+      var repositoriesArray = [];
+      ops.repositories.forEach(function(repo) {
+        repo.Repositories.id = [stack.id, repo.Repositories.os_type, repo.Repositories.repo_id].join('-');
+        repo.Repositories.os_id = [stack.id, repo.Repositories.os_type].join('-');
+        if (!repo.Repositories.latest_base_url)  repo.Repositories.latest_base_url = repo.Repositories.base_url;
+        resultRepo.push(this.parseIt(repo.Repositories, this.get('configRepository')));
+        repositoriesArray.pushObject(repo.Repositories);
       }, this);
 
-      stack.stack_services.forEach(function(service) {
-        var serviceObj = {
-          id: service.name + '-' + stack.id,
-          name: service.name,
-          display_name: service.display_name,
-          latest_version: service.versions? service.versions[0] : ''
-        };
-        resultServices.push(this.parseIt(serviceObj, this.get('configService')));
-        servicesArray.pushObject(serviceObj);
-      }, this);
+      operatingSystems.id = stack.id + "-" + operatingSystems.os_type;
+      operatingSystems.stack_id = operatingSystems.stack_name + "-" + operatingSystems.stack_version;
+      operatingSystems.repositories = repositoriesArray;
+      operatingSystems.is_selected = (ops.isSelected == true || ops.isSelected == undefined);
+      resultOS.push(this.parseIt(operatingSystems, this.get('configOS')));
+      operatingSystemsArray.pushObject(operatingSystems);
+        
+    }, this);
 
-      //In case ambari_managed_repositories is undefined, set use_redhat_satellite to be
false
-      stack.use_redhat_satellite = item.operating_systems[0].OperatingSystems.ambari_managed_repositories
=== false;
-      stack.stack_services = servicesArray;
-      stack.operating_systems = operatingSystemsArray;
-      resultStack.push(this.parseIt(stack, this.get('configStack')));
-      
+    stack.stack_services.forEach(function(service) {
+      var serviceObj = {
+        id: service.name + '-' + stack.id,
+        name: service.name,
+        display_name: service.display_name,
+        latest_version: service.versions? service.versions[0] : ''
+      };
+      resultServices.push(this.parseIt(serviceObj, this.get('configService')));
+      servicesArray.pushObject(serviceObj);
     }, this);
 
+    //In case ambari_managed_repositories is undefined, set use_redhat_satellite to be false
+    stack.use_redhat_satellite = item.operating_systems[0].OperatingSystems.ambari_managed_repositories
=== false;
+    stack.stack_services = servicesArray;
+    stack.operating_systems = operatingSystemsArray;
+
     App.store.commit();
     App.store.loadMany(modelRepo, resultRepo);
     App.store.loadMany(modelOS, resultOS);
     App.store.loadMany(modelServices, resultServices);
-    App.store.loadMany(modelStack, resultStack);
+    App.store.load(modelStack, this.parseIt(stack, this.get('configStack')));
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/abe7eb50/ambari-web/app/views/wizard/step1_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/wizard/step1_view.js b/ambari-web/app/views/wizard/step1_view.js
index 96dcf39..a7af383 100644
--- a/ambari-web/app/views/wizard/step1_view.js
+++ b/ambari-web/app/views/wizard/step1_view.js
@@ -26,11 +26,11 @@ App.WizardStep1View = Em.View.extend({
   didInsertElement: function () {
     $("[rel=skip-validation-tooltip]").tooltip({ placement: 'right'});
     $("[rel=use-redhat-tooltip]").tooltip({ placement: 'right'});
-    if (this.get('controller.selectedStack').get("showAvailable")) {
+    if (this.get('controller.selectedStack') && this.get('controller.selectedStack.showAvailable'))
{
       // first time load
       this.set('controller.latestSelectedPublicRepoId',this.get('controller.selectedStack.id'));
     } else {
-      var selected = this.get('controller.content.stacks').findProperty('showAvailable');
+      var selected = this.get('controller.content.stacks') && this.get('controller.content.stacks').findProperty('showAvailable');
       if (selected) {
         // get back from other steps, set default public repo as selected public
         this.set('controller.latestSelectedPublicRepoId', selected.get('id'));

http://git-wip-us.apache.org/repos/asf/ambari/blob/abe7eb50/ambari-web/test/mappers/stack_mapper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/stack_mapper_test.js b/ambari-web/test/mappers/stack_mapper_test.js
index 63f7516..37138ee 100644
--- a/ambari-web/test/mappers/stack_mapper_test.js
+++ b/ambari-web/test/mappers/stack_mapper_test.js
@@ -587,7 +587,9 @@ describe('App.stackMapper', function () {
       App.resetDsStoreTypeMap(App.Stack);
       App.resetDsStoreTypeMap(App.ServiceSimple);
       sinon.stub(App.store, 'commit', Em.K);
-      App.stackMapper.map(testData.items, "VersionDefinition");
+      testData.items.sortProperty('VersionDefinition.stack_version').reverse().forEach(function
(versionDefinition) {
+        App.stackMapper.map(versionDefinition);
+      });
     });
     afterEach(function(){
       App.store.commit.restore();


Mime
View raw message