123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- /**
- * 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.WizardStep9Controller = Em.Controller.extend({
- name:'wizardStep9Controller',
- hosts:[],
- progress:'0',
- isStepCompleted:false,
- isSubmitDisabled:function () {
- return !this.get('isStepCompleted');
- }.property('isStepCompleted'),
- mockHostData:require('data/mock/step9_hosts'),
- pollData_1:require('data/mock/step9_pollData_1'),
- pollData_2:require('data/mock/step9_pollData_2'),
- pollDataCounter:0,
- status:function () {
- if (this.hosts.everyProperty('status', 'success')) {
- return 'success';
- } else if (this.hosts.someProperty('status', 'failed')) {
- return 'failed';
- } else if (this.hosts.someProperty('status', 'warning')) {
- return 'warning';
- } else {
- return 'info';
- }
- }.property('hosts.@each.status'),
- navigateStep:function () {
- this.loadStep();
- //TODO: uncomment following line after the hook up with the API call
- if (this.get('content.cluster.isCompleted') === false) {
- //this.startPolling();
- } else {
- this.set('isStepCompleted', true);
- this.set('progress', '100');
- }
- },
- clearStep:function () {
- this.hosts.clear();
- this.set('status', 'info');
- this.set('progress', '0');
- this.set('isStepCompleted', false);
- },
- loadStep:function () {
- console.log("TRACE: Loading step9: Install, Start and Test");
- this.clearStep();
- this.renderHosts(this.loadHosts());
- },
- loadHosts:function () {
- var hostInfo = [];
- hostInfo = this.get('content.hostsInfo');
- var hosts = new Ember.Set();
- for (var index in hostInfo) {
- hosts.add(hostInfo[index]);
- console.log("TRACE: host name is: " + hostInfo[index].name);
- }
- return hosts.filterProperty('bootStatus', 'success');
- },
- renderHosts:function (hostsInfo) {
- var self = this;
- hostsInfo.forEach(function (_hostInfo) {
- var hostInfo = App.HostInfo.create({
- name:_hostInfo.name,
- status:_hostInfo.status,
- message:_hostInfo.message,
- progress:_hostInfo.progress
- });
- console.log('pushing ' + hostInfo.name);
- self.hosts.pushObject(hostInfo);
- });
- },
- onSuccessPerHost:function (actions, contentHost) {
- if (actions.everyProperty('status', 'completed')) {
- contentHost.set('status', 'success');
- }
- },
- onWarningPerHost:function (actions, contentHost) {
- if (actions.findProperty('status', 'failed') || actions.findProperty('status', 'aborted')) {
- contentHost.set('status', 'warning');
- this.set('status', 'warning');
- }
- },
- onInProgressPerHost:function (actions, contentHost) {
- var runningAction = actions.findProperty('status', 'inprogress');
- if (runningAction !== null && runningAction !== undefined) {
- contentHost.set('message', runningAction.message);
- }
- },
- progressPerHost:function (actions, contentHost) {
- var totalProgress = 0;
- var actionsPerHost = actions.length;
- var completedActions = actions.filterProperty('status', 'completed').length
- + actions.filterProperty('status', 'failed').length +
- actions.filterProperty('status', 'aborted').length;
- var progress = Math.floor((completedActions / actionsPerHost) * 100);
- console.log('INFO: progressPerHost is: ' + progress);
- contentHost.set('progress', progress.toString());
- return progress;
- },
- isSuccess:function (polledData) {
- return polledData.everyProperty('status', 'success');
- },
- isStepFailed:function (polledData) {
- var self = this;
- var result = false;
- polledData.forEach(function (_polledData) {
- var successFactor = _polledData.sf;
- var actionsPerRole = polledData.filterProperty('role', _polledData.role);
- var actionsFailed = actionsPerRole.filterProperty('status', 'failed');
- var actionsAborted = actionsPerRole.filterProperty('status', 'aborted');
- if ((((actionsFailed.length + actionsAborted.length) / actionsPerRole.length) * 100) <= successFactor) {
- console.log('TRACE: Entering success factor and result is failed');
- result = true;
- }
- });
- return result;
- },
- getFailedHostsForFailedRoles:function (polledData) {
- var hostArr = new Ember.Set();
- polledData.forEach(function (_polledData) {
- var successFactor = _polledData.sf;
- var actionsPerRole = polledData.filterProperty('role', _polledData.role);
- var actionsFailed = actionsPerRole.filterProperty('status', 'failed');
- var actionsAborted = actionsPerRole.filterProperty('status', 'aborted');
- if ((((actionsFailed.length + actionsAborted.length) / actionsPerRole.length) * 100) <= successFactor) {
- actionsFailed.forEach(function (_actionFailed) {
- hostArr.add(_actionFailed.name);
- });
- actionsAborted.forEach(function (_actionFailed) {
- hostArr.add(_actionFailed.name);
- });
- }
- });
- return hostArr;
- },
- setHostsStatus:function (hosts, status) {
- var self = this;
- hosts.forEach(function (_host) {
- var host = self.hosts.findProperty('name', _host);
- host.set('status', status);
- });
- },
- // polling from ui stops only when no action has 'pending', 'queued' or 'inprogress' status
- finishStep:function (polledData) {
- var self = this;
- if (!polledData.someProperty('status', 'pending') && !polledData.someProperty('status', 'queued') && !polledData.someProperty('status', 'inprogress')) {
- this.set('progress', '100');
- if (this.isSuccess(polledData)) {
- this.set('status', 'success');
- } else {
- if (this.isStepFailed(polledData)) {
- self.set('status', 'failed');
- this.setHostsStatus(this.getFailedHostsForFailedRoles(polledData), 'failed');
- }
- }
- this.set('isStepCompleted', true);
- }
- },
- parseHostInfo:function (polledData) {
- console.log('TRACE: Entering host info function');
- var self = this;
- var result = false;
- var totalProgress = 0;
- this.hosts.forEach(function (_content) {
- var actions = polledData.filterProperty('name', _content.name);
- if (actions.length === 0) {
- alert('For testing with mockData follow the sequence: hit referesh,"mockData btn", "pollData btn", again "pollData btn"');
- //exit();
- }
- if (actions !== null && actions !== undefined && actions.length !== 0) {
- this.onSuccessPerHost(actions, _content); // every action should be a success
- this.onWarningPerHost(actions, _content); // any action should be a faliure
- this.onInProgressPerHost(actions, _content); // current running action for a host
- totalProgress = totalProgress + self.progressPerHost(actions, _content);
- }
- }, this);
- totalProgress = Math.floor(totalProgress / this.hosts.length);
- this.set('progress', totalProgress.toString());
- console.log("INFO: right now the progress is: " + this.get('progress'));
- this.finishStep(polledData);
- return this.get('isStepCompleted');
- },
- retry:function () {
- if (this.get('isSubmitDisabled')) {
- return;
- }
- this.hosts.clear();
- this.renderHosts(this.loadHosts());
- //this.startPolling();
- },
- startPolling:function () {
- this.set('isSubmitDisabled', true);
- this.doPolling();
- },
- doPolling:function () {
- var self = this;
- $.ajax({
- type:'GET',
- url:'/ambari_server/api/polling',
- async:false,
- timeout:5000,
- success:function (data) {
- console.log("TRACE: In success function for the GET bootstrap call");
- var result = self.parseHostInfo(data);
- if (result !== true) {
- window.setTimeout(self.doPolling, 3000);
- } else {
- self.stopPolling();
- }
- },
- error:function () {
- console.log("ERROR");
- self.stopPolling();
- },
- statusCode:{
- 404:function () {
- console.log("URI not found.");
- }
- },
- dataType:'application/json'
- });
- },
- stopPolling:function () {
- //TODO: uncomment following line after the hook up with the API call
- // this.set('isStepCompleted',true);
- },
- submit:function () {
- if (!this.get('isSubmitDisabled')) {
- this.set('content.cluster.status', this.get('status'));
- this.set('content.cluster.isCompleted', true);
- App.router.send('next');
- }
- },
- back:function () {
- if (!this.get('isSubmitDisabled')) {
- App.router.send('back');
- }
- },
- hostLogPopup:function (event) {
- App.ModalPopup.show({
- header:Em.I18n.t('installer.step3.hostLog.popup.header'),
- onPrimary:function () {
- this.hide();
- },
- bodyClass:Ember.View.extend({
- templateName:require('templates/installer/step3HostLogPopup')
- })
- });
- },
- mockBtn:function () {
- this.set('isSubmitDisabled', false);
- this.hosts.clear();
- var hostInfo = this.mockHostData;
- this.renderHosts(hostInfo);
- },
- pollBtn:function () {
- this.set('isSubmitDisabled', false);
- var data1 = this.pollData_1;
- var data2 = this.pollData_2;
- if ((this.get('pollDataCounter') / 2) === 0) {
- console.log("TRACE: In pollBtn function data1");
- var counter = parseInt(this.get('pollDataCounter')) + 1;
- this.set('pollDataCounter', counter.toString());
- this.parseHostInfo(data1);
- } else {
- console.log("TRACE: In pollBtn function data2");
- var counter = parseInt(this.get('pollDataCounter')) + 1;
- this.set('pollDataCounter', counter.toString());
- this.parseHostInfo(data2);
- }
- }
- });
|