Jelajahi Sumber

AMBARI-8685 Failure handling for repo distribution. (ababiichuk)

aBabiichuk 10 tahun lalu
induk
melakukan
563861f7fe

+ 7 - 5
ambari-web/app/controllers/main/admin/stack_versions/repo_versions_controller.js

@@ -126,10 +126,12 @@ App.RepoVersionsController = Em.ArrayController.extend({
    * @method installStackVersionSuccess
    */
   installStackVersionSuccess: function (data, opt, params) {
-    App.db.set('stackUpgrade', 'id', [data.Requests.id]);
-    App.get('router.mainStackVersionsController').loadStackVersionsToModel().done(function() {
-      var stackVersion = App.StackVersion.find().findProperty('repositoryVersion.id', params.id);
-      App.router.transitionTo('main.admin.adminStackVersions.version', stackVersion);
-    });
+    App.db.set('repoVersion', 'id', [data.Requests.id]);
+    if(!App.StackVersion.find().findProperty('repositoryVersion.id', params.id)) {
+      App.get('router.mainStackVersionsController').loadStackVersionsToModel().done(function() {
+        var stackVersion = App.StackVersion.find().findProperty('repositoryVersion.id', params.id);
+        App.router.transitionTo('main.admin.adminStackVersions.version', stackVersion);
+      });
+    }
   }
 });

+ 22 - 2
ambari-web/app/controllers/main/admin/stack_versions/stack_version_details_controller.js

@@ -31,6 +31,13 @@ App.MainStackVersionsDetailsController = Em.Controller.extend({
     return App.get('allHostNames.length');
   }.property('App.allHostNames.length'),
 
+  /**
+   * true if stack version install is in progress
+   * @type {Boolean}
+   */
+  installFailed: function() {
+    return this.get('content.state') == "INSTALL_FAILED";
+  }.property('content.state'),
   /**
    * true if stack version install is in progress
    * @type {Boolean}
@@ -51,21 +58,34 @@ App.MainStackVersionsDetailsController = Em.Controller.extend({
   /**
    * depending on state run or install repo request
    * or show the installation process popup
+   * @param event
    * @method installStackVersion
    */
-  installStackVersion: function() {
+  installStackVersion: function(event) {
     if (this.get('installInProgress')) {
       this.showProgressPopup();
+    } else if (this.get('installFailed')) {
+      this.installRepoVersion(event);
     }
   },
 
+  /**
+   * install repoVersion using <code>installRepoVersion()<code> method
+   * of <code>repoVersionsController<code> controller
+   * @param event
+   * @method installRepoVersion
+   */
+  installRepoVersion: function(event) {
+    App.get('router.repoVersionsController').installRepoVersion(event);
+  },
+
   /**
    * opens a popup with installations state per host
    * @method showProgressPopup
    */
   showProgressPopup: function() {
     var popupTitle = Em.I18n.t('admin.stackVersions.datails.install.hosts.popup.title').format(this.get('content.repositoryVersion.displayName'));
-    var requestIds = App.get('testMode') ? [1] : App.db.get('stackUpgrade', 'id');
+    var requestIds = App.get('testMode') ? [1] : App.db.get('repoVersion', 'id');
     var hostProgressPopupController = App.router.get('highAvailabilityProgressPopupController');
     hostProgressPopupController.initPopup(popupTitle, requestIds, this);
   }

+ 1 - 0
ambari-web/app/messages.js

@@ -1281,6 +1281,7 @@ Em.I18n.translations = {
   'admin.stackVersions.datails.not.installed.on': "Not installed on",
   'admin.stackVersions.datails.base.url': "Base Url",
 
+  'admin.stackVersions.datails.hosts.btn.reinstall': "Reinstall on failed hosts",
   'admin.stackVersions.datails.hosts.btn.install': "Install to {0} hosts",
   'admin.stackVersions.datails.hosts.btn.installing': "Installing...",
   'admin.stackVersions.datails.hosts.btn.nothing': "Installed on all hosts",

+ 1 - 1
ambari-web/app/templates/main/admin/stack_versions/stack_version_details.hbs

@@ -71,7 +71,7 @@
           </div>
         </div>
         <div class="span4 align-center">
-          <a id="repo-version-action-button" {{bindAttr class="view.statusClass :btn :stack-status-button"}} {{action installStackVersion content target="controller"}}>
+          <a id="repo-version-action-button" {{bindAttr class="view.statusClass :btn :stack-status-button"}} {{action installStackVersion content.repositoryVersion target="controller"}}>
             <i {{bindAttr class="installInProgress:icon-cog"}}>&nbsp;</i>{{view.stackTextStatus}}
           </a>
           <a href="#/main/admin/stack" {{bindAttr class="installedNotUpgraded::hidden"}} >{{t admin.stackVersions.datails.hosts.btn.goto.upgrade}}</a>

+ 6 - 0
ambari-web/app/views/main/admin/stack_versions/stack_version_details_view.js

@@ -43,6 +43,9 @@ App.MainStackVersionsDetailsView = Em.View.extend({
       case 'INIT':
         return Em.I18n.t('admin.stackVersions.datails.hosts.btn.install').format(self.get('totalHostCount') - self.get('content.installedHosts.length'));
         break;
+      case 'INSTALL_FAILED':
+        return Em.I18n.t('admin.stackVersions.datails.hosts.btn.reinstall');
+        break;
       default:
         return self.get('content.state') && self.get('content.state').toCapital();
     }
@@ -61,6 +64,9 @@ App.MainStackVersionsDetailsView = Em.View.extend({
       case 'INSTALLING':
         return 'btn-primary';
         break;
+      case 'INSTALL_FAILED':
+        return 'btn-danger';
+        break;
       default:
         return 'disabled';
     }

+ 34 - 9
ambari-web/test/controllers/main/admin/stack_version/repo_versions_controller_test.js

@@ -76,27 +76,52 @@ describe('App.RepoVersionsController', function () {
   });
 
   describe('#installStackVersionSuccess()', function () {
-    it('success callback for install stack version', function () {
-      var repoId = "1";
-      var requestId = "2";
-      var stackVersion = {repositoryVersion: {id: repoId}};
+    var repoId = "1";
+    var requestId = "2";
+    var stackVersionObject = {repositoryVersion: {id: repoId}};
+    var stackVersion;
+    beforeEach(function() {
       sinon.stub(App.db, 'set', Em.K);
-      sinon.stub(App.get('router.mainStackVersionsController'), 'loadStackVersionsToModel', function() { return $.Deferred().resolve()});
       sinon.stub(App.router, 'transitionTo', Em.K);
       sinon.stub(App.StackVersion, 'find', function() {
         return [stackVersion];
       });
+    });
+
+    afterEach(function() {
+      App.db.set.restore();
+      App.router.transitionTo.restore();
+      App.StackVersion.find.restore();
+    });
+    it('success callback for install stack version', function () {
+      stackVersion = null;
+      sinon.stub(App.get('router.mainStackVersionsController'), 'loadStackVersionsToModel', function() {
+        stackVersion = stackVersionObject;
+        return $.Deferred().resolve()});
 
       repoVersionsController.installStackVersionSuccess({Requests: {id: requestId}}, null, {id: repoId});
       expect(App.db.set.calledWith('stackUpgrade', 'id', [requestId])).to.be.true;
       expect(App.get('router.mainStackVersionsController').loadStackVersionsToModel.calledOnce).to.be.true;
-      expect(App.StackVersion.find.calledOnce).to.be.true;
+      expect(App.StackVersion.find.called).to.be.true;
       expect(App.router.transitionTo.calledWith('main.admin.adminStackVersions.version', stackVersion)).to.be.true;
 
-      App.db.set.restore();
       App.get('router.mainStackVersionsController').loadStackVersionsToModel.restore();
-      App.router.transitionTo.restore();
-      App.StackVersion.find.restore();
+    });
+
+    it('success callback for install stack version without redirect', function () {
+      stackVersion = stackVersionObject;
+      sinon.stub(App.get('router.mainStackVersionsController'), 'loadStackVersionsToModel', function() {
+        return $.Deferred().resolve()
+      });
+
+      repoVersionsController.installStackVersionSuccess({Requests: {id: requestId}}, null, {id: repoId});
+      expect(App.db.set.calledWith('stackUpgrade', 'id', [requestId])).to.be.true;
+      expect(App.get('router.mainStackVersionsController').loadStackVersionsToModel.calledOnce).to.be.false;
+      expect(App.StackVersion.find.calledOnce).to.be.true;
+      expect(App.router.transitionTo.calledWith('main.admin.adminStackVersions.version', stackVersion)).to.be.false;
+
+      App.get('router.mainStackVersionsController').loadStackVersionsToModel.restore();
+
     });
   });
 

+ 7 - 0
ambari-web/test/controllers/main/admin/stack_version/stack_version_details_controller_test.js

@@ -30,15 +30,22 @@ describe('App.MainStackVersionsDetailsController', function () {
   describe('#installStackVersion', function () {
     beforeEach(function() {
       sinon.stub(mainStackVersionsDetailsController, 'showProgressPopup', Em.K);
+      sinon.stub(mainStackVersionsDetailsController, 'installRepoVersion', Em.K);
     });
     afterEach(function() {
       mainStackVersionsDetailsController.showProgressPopup.restore();
+      mainStackVersionsDetailsController.installRepoVersion.restore();
     });
     it("shows installing proggress", function() {
       mainStackVersionsDetailsController.reopen({'installInProgress': true});
       mainStackVersionsDetailsController.installStackVersion({});
       expect(mainStackVersionsDetailsController.showProgressPopup.calledOnce).to.be.true;
     });
+    it("shows senq request to install/reinstall repoVersion", function() {
+      mainStackVersionsDetailsController.reopen({'installFailed': true});
+      mainStackVersionsDetailsController.installStackVersion({context: "1"});
+      expect(mainStackVersionsDetailsController.installRepoVersion.calledWith({context: "1"})).to.be.true;
+    });
   });
 
   describe('#showProgressPopup', function () {

+ 41 - 0
ambari-web/test/controllers/main/admin/stack_version/stack_versions_controller_test.js

@@ -52,4 +52,45 @@ describe('App.MainStackVersionsController', function () {
       App.HttpClient.get.restore();
     });
   });
+
+  describe('#filterHostsByStack()', function () {
+    beforeEach(function() {
+      sinon.stub(App.router.get('mainHostController'), 'filterByStack').returns({done: Em.K});
+      sinon.stub(App.router, 'transitionTo').returns({done: Em.K});
+    });
+    afterEach(function() {
+      App.router.get('mainHostController').filterByStack.restore();
+      App.router.transitionTo.restore();
+    });
+    var tests = [
+      {
+        version: "version1",
+        state: "state1",
+        m: 'go to hosts filtered by host stack version and host stack state',
+        runAll: true
+      },
+      {
+        version: null,
+        state: "state1",
+        m: 'doesn\'t do anything because version is missing'
+      },
+      {
+        version: "version1",
+        state: null,
+        m: 'doesn\'t do anything because state is missing'
+      }
+    ].forEach(function(t) {
+        it(t.m, function () {
+          controller.load(t.version, t.stack);
+          if (t.runAll) {
+            expect(App.router.get('mainHostController').filterByStack.calledWith('hosts.index')).to.be.true;
+            expect(App.router.transitionTo.calledWith('hosts.index')).to.be.true;
+          } else {
+            expect(App.router.get('mainHostController').filterByStack.calledOnce).to.be.false;
+            expect(App.router.transitionTo.calledOnce).to.be.false;
+          }
+
+        });
+      });
+  });
 });

+ 4 - 0
ambari-web/test/views/main/admin/stack_version/stack_version_details_test.js

@@ -40,6 +40,10 @@ describe('App.MainStackVersionsDetailsView', function () {
       {
         state: "INSTALLING",
         buttonClass: 'btn-primary'
+      },
+      {
+        state: "INSTALL_FAILED",
+        buttonClass: "btn-danger"
       }
     ].forEach(function(t) {
       it("status is " + t.status + " class is " + t.buttonClass, function() {