123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- /**
- * 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');
- App.InstallerStep2Controller = Em.Controller.extend({
- name: 'installerStep2Controller',
- content: [],
- hostNames: '',
- hostNameArr: [],
- hostNameEmptyError: false,
- hostNameErr: false,
- manualInstall: false,
- hostNameNotRequiredErr: false,
- hostNameErrMsg: '',
- sshKey: '',
- passphrase: '',
- confirmPassphrase: '',
- sshKeyNullErr: false,
- passphraseMatchErr: false,
- localRepo: false,
- localRepoPath: '',
- softRepoLocalPathNullErr: false,
- isSubmitDisabled: false,
- installType: function () {
- if (this.get('manualInstall') === true) {
- return 'manualDriven';
- } else {
- return 'ambariDriven';
- }
- }.observes('manualInstall'),
- hideRepoErrMsg: function () {
- if (this.get('localRepo') === false) {
- this.set('softRepoLocalPathNullErr', false);
- }
- }.observes('localRepo'),
- validateHostNames: function () {
- this.hostNameArr = this.get('hostNames').split(new RegExp("\\s"));
- for (var i = 0; i < this.hostNameArr.length; i++) {
- //TODO: other validation for hostnames will be covered over here
- // For now hostnames that start or end with '-' are not allowed
- if (/^\-/.test(this.hostNameArr[i]) || /\-$/.test(this.hostNameArr[i])) {
- console.log('Invalid host name: ' + this.hostNameArr[i]);
- this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.invalid'));
- this.set('hostNameErr', true);
- this.set('hostNameEmptyError', false);
- this.set('hostNameNotRequiredErr', false);
- return false;
- }
- }
- return true;
- },
- validateHosts: function () {
- if (this.get('hostNames') === '' && this.get('manualInstall') === false) {
- this.set('hostNameEmptyError', true);
- this.set('hostNameNotRequiredErr', false);
- this.set('hostNameErr', false);
- this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.required'));
- } else if (this.get('hostNames') !== '' && this.get('manualInstall') === true) {
- this.set('hostNameNotRequiredErr', true);
- this.set('hostNameEmptyError', false);
- this.set('hostNameErr', false);
- this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.notRequired'));
- } else {
- this.set('hostNameErr', false);
- this.set('hostNameEmptyError', false);
- this.set('hostNameNotRequiredErr', false);
- this.set('hostNameErrMsg', '');
- }
- }.observes('hostNames', 'manualInstall'),
- validateSSHKey: function () {
- if (this.get('manualInstall') === false) {
- if (this.get('sshKey') === '') {
- this.set('sshKeyNullErr', true);
- }
- else {
- this.set('sshKeyNullErr', false);
- }
- }
- }.observes('manualInstall', 'sshKey'),
- validatePassphrase: function () {
- if (this.get('manualInstall') === false) {
- if (this.get('passphrase') !== this.get('confirmPassphrase')) {
- this.set('passphraseMatchErr', true);
- } else {
- this.set('passphraseMatchErr', false);
- }
- }
- }.observes('manualInstall', 'passphrase', 'confirmPassphrase'),
- validateLocalRepo: function () {
- if (this.get('localRepo') === true) {
- if (this.get('localRepoPath') === '') {
- this.set('softRepoLocalPathNullErr', true);
- } else {
- this.set('softRepoLocalPathNullErr', false);
- }
- } else {
- this.set('softRepoLocalPathNullErr', false);
- }
- }.observes('localRepoPath'),
- validateStep2: function () {
- this.validateHosts();
- this.validateSSHKey();
- this.validatePassphrase();
- this.validateLocalRepo();
- return this.validateHostNames();
- },
- hostManageErr: function () {
- return (this.get('hostNameEmptyError') || this.get('hostNameNotRequiredErr') ||
- this.get('hostNameErr') || this.get('sshKeyNullErr') || this.get('passphraseMatchErr'));
- }.property('hostNameErrMsg', 'sshKeyNullErr', 'passphraseMatchErr'),
- sshLessInstall: function () {
- if (this.get('manualInstall') === true) {
- this.set('hostManageErr', false);
- this.set('hostNameEmptyError', false);
- this.set('sshKeyNullErr', false);
- this.set('passphraseMatchErr', false);
- }
- }.observes('manualInstall'),
- advOptErr: function () {
- return this.get('softRepoLocalPathNullErr');
- }.property('softRepoLocalPathNullErr'),
- step2Err: function () {
- if (this.get('hostManageErr') === true || this.get('advOptErr') === true) {
- this.set('isSubmitDisabled', true);
- } else {
- this.set('isSubmitDisabled', false);
- }
- }.observes('hostManageErr', 'advOptErr'),
- softRepo: function () {
- if (this.get('localRepo') === false) {
- this.set('localRepoPath', '');
- }
- }.observes('localRepo'),
- evaluateStep2: function () {
- //task1 = do primary validations on whole step before executing any further steps
- //task2 = parsing hostnames string to hostnames json array
- //task3 = check validation for every hostname and store it in localstorage
- //task4 = Storing ambari agent Install type in localStorage (installType maps at host level and so every host will have this as an property)
- //task5 = Storing path of software repository(remote/local repo) to localStorage
- //task6 = call to rest API: @Post http://ambari_server/api/bootstrap
- //task7 = On Manual Install, next button click pops up a warning with "proceed" and "close" buttons
- //task8 = On faliure of the previous call, show 'error injecting host information in server db'
- //task9 = On success of the previous call, go to step 3
- console.log('TRACE: Entering controller:InstallerStep2:evaluateStep2 function');
- console.log('value of manual install is: ' + this.get('manualInstall'));
- var validateResult = this.validateStep2();
- if (this.get('isSubmitDisabled') === true || validateResult === false) {
- console.log("ERROR: error in validation");
- return false;
- } else {
- if (this.get('manualInstall') === true) {
- this.manualInstallPopup();
- return true;
- }
- }
- var hostInfo = {};
- for (var i = 0; i < this.hostNameArr.length; i++) {
- hostInfo[this.hostNameArr[i]] = {
- name: this.hostNameArr[i],
- installType: this.get('installType')
- };
- }
- App.db.setHosts(hostInfo);
- if (this.get('localRepo') === false) {
- App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
- } else {
- App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': this.get('localRepoPath') });
- }
- // Just an additional check. If manualInstall is true, program should have not reached over here
- if (this.get('manualInstall') === false) {
- // For now using mock jquery call
- //TODO: hook up with bootstrap call
- var bootStrapData = {'sshKey': this.get('sshKey'), 'sshKeyPassphrase': this.get('passphrase'), hosts: this.get('hostNameArr')}.stringify;
- $.ajax({
- type: 'POST',
- url: '/ambari_server/api/bootstrap',
- data: bootStrapData,
- async: false,
- timeout: 2000,
- success: function () {
- console.log("TRACE: In success function for the post bootstrap function");
- App.transitionTo('step3');
- },
- error: function () {
- console.log("ERROR: bootstrap post call failed");
- return false;
- },
- statusCode: {
- 404: function () {
- console.log("URI not found.");
- alert("URI not found,. This needs to be hooked up with a @POST bootstrap call");
- //After the bootstrap call hook up change the below return statement to "return false"
- console.log("TRACE: In faliure function for the post bootstrap function");
- //Remove below line, once bootstrap has been implemented
- App.router.transitionTo('step3');
- return true;
- }
- },
- dataType: 'application/json'
- });
- } else {
- console.log("ERROR: ASSERTION FAILED -> program should have never reached over here");
- }
- },
- manualInstallPopup: function (event) {
- App.ModalPopup.show({
- header: Em.I18n.t('installer.step2.manualInstall.popup.header'),
- onPrimary: function () {
- this.hide();
- App.router.transitionTo('step3');
- },
- bodyClass: Ember.View.extend({
- templateName: require('templates/installer/step2ManualInstallPopup')
- })
- });
- }
- });
|