<commit_before>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var App = require('app');

module.exports = App.WizardRoute.extend({
  route: '/enable',
  enter: function (router) {
    Em.run.next(function () {
      var kerberosWizardController = router.get('kerberosWizardController');
      App.router.get('updateController').set('isWorking', false);
      var popup = App.ModalPopup.show({
        classNames: ['full-width-modal'],
        header: Em.I18n.t('admin.kerberos.wizard.header'),
        bodyClass: App.KerberosWizardView.extend({
          controller: kerberosWizardController
        }),
        primary: Em.I18n.t('form.cancel'),
        showFooter: false,
        secondary: null,

        onClose: function () {
          var self = this;
          switch(kerberosWizardController.get('currentStep')) {
            case "2":
              var step2Controller = router.get('kerberosWizardStep2Controller');
              if (step2Controller.get('testConnectionInProgress')) {
                step2Controller.showConnectionInProgressPopup(function() {
                  kerberosWizardController.warnBeforeExitPopup(function() {
                    self.exitWizard();
                  }, false);
                });
              } else {
                kerberosWizardController.warnBeforeExitPopup(function() {
                  self.exitWizard();
                }, false);
              }
              break;
            case "6":
            case "7":
              kerberosWizardController.warnBeforeExitPopup(function() {
                self.exitWizard();
              }, true);
              break;
            default:
              kerberosWizardController.warnBeforeExitPopup(function() {
                self.exitWizard();
              }, false);
          }
        },
        didInsertElement: function () {
          this.fitHeight();
        },

        exitWizard: function () {
          var self = this;
          var kerberosProgressPageController = App.router.get('kerberosProgressPageController');
          var controller = App.router.get('kerberosWizardController');
          controller.clearTasksData();
          controller.finish();
          App.get('router.updateController').set('isWorking', true);
          if (App.get('testMode')) {
            App.get('router').transitionTo('adminKerberos.index');
            location.reload();
          }
          App.clusterStatus.setClusterStatus({
            clusterName: App.router.getClusterName(),
            clusterState: 'DEFAULT',
            localdb: App.db.data
          }, {
            alwaysCallback: function () {
              self.hide();
              App.get('router').transitionTo('adminKerberos.index');
            }
          });
        }
      });
      kerberosWizardController.set('popup', popup);
      var currentClusterStatus = App.clusterStatus.get('value');
      if (currentClusterStatus) {
        if (App.get('testMode')) {
          kerberosWizardController.setCurrentStep(App.db.data.KerberosWizard.currentStep);
        } else {
          switch (currentClusterStatus.clusterState) {
            case 'KERBEROS_DEPLOY' :
              kerberosWizardController.setCurrentStep(currentClusterStatus.localdb.KerberosWizard.currentStep);
              break;
            default:
              var currStep = App.get('router.kerberosWizardController.currentStep');
              kerberosWizardController.setCurrentStep(currStep);
              break;
          }
        }

      }
      router.transitionTo('step' + kerberosWizardController.get('currentStep'));
    });
  },

  step1: Em.Route.extend({
    route: '/step1',
    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('1');
    },

    connectOutlets: function (router) {
      console.log('in addSecurity.step1:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.loadAllPriorSteps();
        controller.connectOutlet('kerberosWizardStep1', controller.get('content'));
      });
    },

    unroutePath: function () {
      return false;
    },

    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      var kerberosStep1controller = router.get('kerberosWizardStep1Controller');
      kerberosWizardController.saveKerberosOption(kerberosStep1controller);
      kerberosWizardController.setDBProperty('serviceConfigProperties', null);
      kerberosWizardController.setDBProperty('advancedServiceConfig', null);
      router.transitionTo('step2');
    }
  }),

  step2: Em.Route.extend({
    route: '/step2',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('2');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step2:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.loadAllPriorSteps();
        var kerberosWizardStep2Controller = router.get('kerberosWizardStep2Controller');
        kerberosWizardStep2Controller.set('wizardController', controller);
        controller.connectOutlet('kerberosWizardStep2', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: function(router) {
      var controller = router.get('kerberosWizardStep2Controller');
      if (!controller.get('isBackBtnDisabled')) {
        router.transitionTo('step1')
      }
    },

    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      var kerberosWizardStep2Controller = router.get('kerberosWizardStep2Controller');
      kerberosWizardController.saveServiceConfigProperties(kerberosWizardStep2Controller);
      kerberosWizardController.clearTasksData();
      router.transitionTo('step3');
    }
  }),

  step3: Em.Route.extend({
    route: '/step3',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('3');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step3:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.loadAllPriorSteps();
        controller.connectOutlet('kerberosWizardStep3', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step2'),
    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      kerberosWizardController.setDBProperty('kerberosDescriptorConfigs', null);
      router.transitionTo('step4');
    }
  }),

  step4: Em.Route.extend({
    route: '/step4',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('4');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step4:connectOutlets');
      var controller = router.get('kerberosWizardController');
      var step4Controller = router.get('kerberosWizardStep4Controller');
      controller.setCurrentStep(4);
      controller.dataLoading().done(function () {
        controller.loadAllPriorSteps();
        controller.setLowerStepsDisable(4);
        step4Controller.set('wizardController', controller);
        controller.connectOutlet('kerberosWizardStep4', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step3'),
    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      var kerberosWizardStep4Controller = router.get('kerberosWizardStep4Controller');
      kerberosWizardController.saveServiceConfigProperties(kerberosWizardStep4Controller);
      kerberosWizardController.setDBProperty('tasksStatuses', null);
      kerberosWizardController.setDBProperty('tasksRequestIds', null);
      router.transitionTo('step5');
    }
  }),

  step5: Em.Route.extend({
    route: '/step5',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('5');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step5:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.setLowerStepsDisable(5);
        controller.loadAllPriorSteps();
        controller.connectOutlet('kerberosWizardStep5', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step4'),
    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      kerberosWizardController.setDBProperty('tasksStatuses', null);
      kerberosWizardController.setDBProperty('tasksRequestIds', null);
      var step6Controller = router.get('kerberosWizardStep6Controller');
      var kerberosDescriptor = kerberosWizardController.get('kerberosDescriptorConfigs');
      step6Controller.postKerberosDescriptor(kerberosDescriptor).always(function (data, result, request) {
        if (result === 'error' && data.status === 409) {
          step6Controller.putKerberosDescriptor(kerberosDescriptor).always(function (data) {
            step6Controller.unkerberizeCluster().always(function (data) {
              router.transitionTo('step6');
            });
          });
        } else {
          router.transitionTo('step6');
        }
      });
    }
  }),

  step6: Em.Route.extend({
    route: '/step6',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('6');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step6:connectOutlets');
      var controller = router.get('kerberosWizardController');
      var stepController = router.get('kerberosWizardStep6Controller');
      controller.dataLoading().done(function () {
        controller.setLowerStepsDisable(6);
        controller.loadAllPriorSteps();
        stepController.setRequest();
        controller.connectOutlet('kerberosWizardStep6', controller.get('content'));
      });
    },
    retry: function () {
      var router = App.get('router');
      var stepController = router.get('kerberosWizardStep6Controller');
      stepController.setRequest();
      stepController.loadStep();
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step4'),
    next: function (router) {
      router.transitionTo('step7');
    }
  }),

  step7: Em.Route.extend({
    route: '/step7',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('7');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step7:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.setLowerStepsDisable(7);
        controller.loadAllPriorSteps();
        controller.connectOutlet('kerberosWizardStep7', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step6'),
    next: function (router) {
      var controller = router.get('kerberosWizardController');
      controller.finish();
      App.clusterStatus.setClusterStatus({
        clusterName: App.get('router').getClusterName(),
        clusterState: 'DEFAULT',
        localdb: App.db.data
      }, {
        alwaysCallback: function () {
          controller.get('popup').hide();
          App.get('router').transitionTo('adminKerberos.index');
        }
      });

    }
  })
});
<commit_msg>AMBARI-9657. Add service wizard error on kerberized cluster (onechiporenko)<commit_after>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var App = require('app');

module.exports = App.WizardRoute.extend({
  route: '/enable',
  enter: function (router) {
    Em.run.next(function () {
      var kerberosWizardController = router.get('kerberosWizardController');
      App.router.get('updateController').set('isWorking', false);
      var popup = App.ModalPopup.show({
        classNames: ['full-width-modal'],
        header: Em.I18n.t('admin.kerberos.wizard.header'),
        bodyClass: App.KerberosWizardView.extend({
          controller: kerberosWizardController
        }),
        primary: Em.I18n.t('form.cancel'),
        showFooter: false,
        secondary: null,

        onClose: function () {
          var self = this;
          switch(kerberosWizardController.get('currentStep')) {
            case "2":
              var step2Controller = router.get('kerberosWizardStep2Controller');
              if (step2Controller.get('testConnectionInProgress')) {
                step2Controller.showConnectionInProgressPopup(function() {
                  kerberosWizardController.warnBeforeExitPopup(function() {
                    self.exitWizard();
                  }, false);
                });
              } else {
                kerberosWizardController.warnBeforeExitPopup(function() {
                  self.exitWizard();
                }, false);
              }
              break;
            case "6":
            case "7":
              kerberosWizardController.warnBeforeExitPopup(function() {
                self.exitWizard();
              }, true);
              break;
            default:
              kerberosWizardController.warnBeforeExitPopup(function() {
                self.exitWizard();
              }, false);
          }
        },
        didInsertElement: function () {
          this.fitHeight();
        },

        exitWizard: function () {
          var self = this;
          var kerberosProgressPageController = App.router.get('kerberosProgressPageController');
          var controller = App.router.get('kerberosWizardController');
          controller.clearTasksData();
          controller.finish();
          App.get('router.updateController').set('isWorking', true);
          if (App.get('testMode')) {
            App.get('router').transitionTo('adminKerberos.index');
            location.reload();
          }
          App.clusterStatus.setClusterStatus({
            clusterName: App.router.getClusterName(),
            clusterState: 'DEFAULT',
            localdb: App.db.data
          }, {
            alwaysCallback: function () {
              self.hide();
              App.get('router').transitionTo('adminKerberos.index');
              location.reload();
            }
          });
        }
      });
      kerberosWizardController.set('popup', popup);
      var currentClusterStatus = App.clusterStatus.get('value');
      if (currentClusterStatus) {
        if (App.get('testMode')) {
          kerberosWizardController.setCurrentStep(App.db.data.KerberosWizard.currentStep);
        } else {
          switch (currentClusterStatus.clusterState) {
            case 'KERBEROS_DEPLOY' :
              kerberosWizardController.setCurrentStep(currentClusterStatus.localdb.KerberosWizard.currentStep);
              break;
            default:
              var currStep = App.get('router.kerberosWizardController.currentStep');
              kerberosWizardController.setCurrentStep(currStep);
              break;
          }
        }

      }
      router.transitionTo('step' + kerberosWizardController.get('currentStep'));
    });
  },

  step1: Em.Route.extend({
    route: '/step1',
    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('1');
    },

    connectOutlets: function (router) {
      console.log('in addSecurity.step1:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.loadAllPriorSteps();
        controller.connectOutlet('kerberosWizardStep1', controller.get('content'));
      });
    },

    unroutePath: function () {
      return false;
    },

    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      var kerberosStep1controller = router.get('kerberosWizardStep1Controller');
      kerberosWizardController.saveKerberosOption(kerberosStep1controller);
      kerberosWizardController.setDBProperty('serviceConfigProperties', null);
      kerberosWizardController.setDBProperty('advancedServiceConfig', null);
      router.transitionTo('step2');
    }
  }),

  step2: Em.Route.extend({
    route: '/step2',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('2');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step2:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.loadAllPriorSteps();
        var kerberosWizardStep2Controller = router.get('kerberosWizardStep2Controller');
        kerberosWizardStep2Controller.set('wizardController', controller);
        controller.connectOutlet('kerberosWizardStep2', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: function(router) {
      var controller = router.get('kerberosWizardStep2Controller');
      if (!controller.get('isBackBtnDisabled')) {
        router.transitionTo('step1')
      }
    },

    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      var kerberosWizardStep2Controller = router.get('kerberosWizardStep2Controller');
      kerberosWizardController.saveServiceConfigProperties(kerberosWizardStep2Controller);
      kerberosWizardController.clearTasksData();
      router.transitionTo('step3');
    }
  }),

  step3: Em.Route.extend({
    route: '/step3',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('3');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step3:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.loadAllPriorSteps();
        controller.connectOutlet('kerberosWizardStep3', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step2'),
    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      kerberosWizardController.setDBProperty('kerberosDescriptorConfigs', null);
      router.transitionTo('step4');
    }
  }),

  step4: Em.Route.extend({
    route: '/step4',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('4');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step4:connectOutlets');
      var controller = router.get('kerberosWizardController');
      var step4Controller = router.get('kerberosWizardStep4Controller');
      controller.setCurrentStep(4);
      controller.dataLoading().done(function () {
        controller.loadAllPriorSteps();
        controller.setLowerStepsDisable(4);
        step4Controller.set('wizardController', controller);
        controller.connectOutlet('kerberosWizardStep4', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step3'),
    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      var kerberosWizardStep4Controller = router.get('kerberosWizardStep4Controller');
      kerberosWizardController.saveServiceConfigProperties(kerberosWizardStep4Controller);
      kerberosWizardController.setDBProperty('tasksStatuses', null);
      kerberosWizardController.setDBProperty('tasksRequestIds', null);
      router.transitionTo('step5');
    }
  }),

  step5: Em.Route.extend({
    route: '/step5',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('5');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step5:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.setLowerStepsDisable(5);
        controller.loadAllPriorSteps();
        controller.connectOutlet('kerberosWizardStep5', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step4'),
    next: function (router) {
      var kerberosWizardController = router.get('kerberosWizardController');
      kerberosWizardController.setDBProperty('tasksStatuses', null);
      kerberosWizardController.setDBProperty('tasksRequestIds', null);
      var step6Controller = router.get('kerberosWizardStep6Controller');
      var kerberosDescriptor = kerberosWizardController.get('kerberosDescriptorConfigs');
      step6Controller.postKerberosDescriptor(kerberosDescriptor).always(function (data, result, request) {
        if (result === 'error' && data.status === 409) {
          step6Controller.putKerberosDescriptor(kerberosDescriptor).always(function (data) {
            step6Controller.unkerberizeCluster().always(function (data) {
              router.transitionTo('step6');
            });
          });
        } else {
          router.transitionTo('step6');
        }
      });
    }
  }),

  step6: Em.Route.extend({
    route: '/step6',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('6');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step6:connectOutlets');
      var controller = router.get('kerberosWizardController');
      var stepController = router.get('kerberosWizardStep6Controller');
      controller.dataLoading().done(function () {
        controller.setLowerStepsDisable(6);
        controller.loadAllPriorSteps();
        stepController.setRequest();
        controller.connectOutlet('kerberosWizardStep6', controller.get('content'));
      });
    },
    retry: function () {
      var router = App.get('router');
      var stepController = router.get('kerberosWizardStep6Controller');
      stepController.setRequest();
      stepController.loadStep();
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step4'),
    next: function (router) {
      router.transitionTo('step7');
    }
  }),

  step7: Em.Route.extend({
    route: '/step7',

    enter: function (router) {
      router.get('kerberosWizardController').setCurrentStep('7');
    },
    connectOutlets: function (router) {
      console.log('in kerberosWizardController.step7:connectOutlets');
      var controller = router.get('kerberosWizardController');
      controller.dataLoading().done(function () {
        controller.setLowerStepsDisable(7);
        controller.loadAllPriorSteps();
        controller.connectOutlet('kerberosWizardStep7', controller.get('content'));
      });
    },
    unroutePath: function () {
      return false;
    },
    back: Em.Router.transitionTo('step6'),
    next: function (router) {
      var controller = router.get('kerberosWizardController');
      controller.finish();
      App.clusterStatus.setClusterStatus({
        clusterName: App.get('router').getClusterName(),
        clusterState: 'DEFAULT',
        localdb: App.db.data
      }, {
        alwaysCallback: function () {
          controller.get('popup').hide();
          App.get('router').transitionTo('adminKerberos.index');
        }
      });

    }
  })
});

{'fraction_non_alphanumeric': 0.1216912487708948, 'fraction_numerical': 0.0075516224188790565, 'mean_word_length': 2.9585863303752142, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '814604', 'n_tokens_mistral': 7010, 'n_tokens_neox': 6902, 'n_words': 1125}