123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233 |
- /**
- * 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');
- var stringUtils = require('utils/string_utils');
- App.WizardStep9Controller = Em.Controller.extend(App.ReloadPopupMixin, {
- name: 'wizardStep9Controller',
- /**
- * Array of host Objects that are successfully registered on "Confirm Host Options" page
- * <code>
- * {
- * name: {String} host name.
- * status: {String} Current status of the host. This field is used in the step 9 view to set the css class of the
- * host progress bar and set the appropriate message. Possible values: info, warning, failed, heartbeat_lost and success
- * logTasks: {Array} Tasks that are scheduled on the host for the current request.
- * message: {String} Message to be shown in front of the host name.
- * progress: {Int} Progress of the tasks on the host. Amount of tasks completed for all the tasks scheduled on the host.
- * isNoTasksForInstall: {Boolean} Gets set when no task is scheduled for the host on install phase.
- * }
- * </code>
- * @type {Array.<{name: string, status: string, logTasks: object[], message: string, progress: number, isNoTasksForInstall: bool}>}
- */
- hosts: [],
- /**
- * Overall progress of <Install,Start and Test> page shown as progress bar on the top of the page
- * @type {string}
- */
- progress: '0',
- /**
- * Json file for the mock data to be used in mock mode
- * @type {string}
- */
- mockDataPrefix: '/data/wizard/deploy/5_hosts',
- /**
- * Current Request data polled from the API: api/v1/clusters/{clusterName}/requests/{RequestId}?fields=tasks/Tasks/command,
- * tasks/Tasks/exit_code,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,
- * tasks/Tasks/status&minimal_response=true
- * @type {Object[]}
- */
- polledData: [],
- /**
- * This flag is only used in UI mock mode as a counter for number of polls.
- * @type {number}
- */
- numPolls: 1,
- /**
- * Interval in milliseconds between API calls While polling the request status for Install and, Start and Test tasks
- * @type {number}
- */
- POLL_INTERVAL: 4000,
- /**
- * Array of objects
- * <code>
- * {
- * hostName: {String} Name of host that has stopped heartbeating to ambari-server
- * componentNames: {Sting} Name of all components that are on the host
- * }
- * </code>
- * @type {Object[]}
- */
- hostsWithHeartbeatLost: [],
- /**
- * Flag is set in the start all services error callback function
- * @type {bool}
- */
- startCallFailed: false,
- /**
- * Status of the page. Possible values: <info, warning, failed and success>.
- * This property is used in the step-9 view for displaying the appropriate color of the overall progress bar and
- * the appropriate result message at the bottom of the page
- * @type {string}
- */
- status: 'info',
- skipServiceChecks: false,
- /**
- * This computed property is used to determine if the Next button and back button on the page should be disabled. The property is
- * used in the template to grey out Next and Back buttons. Although clicking on the greyed out button do trigger the event and
- * calls submit and back function of the controller.
- * @type {bool}
- */
- isSubmitDisabled: function () {
- var validStates = ['STARTED', 'START FAILED'];
- var controllerName = this.get('content.controllerName');
- if (controllerName == 'addHostController' || controllerName == 'addServiceController') {
- validStates.push('INSTALL FAILED');
- }
- return !validStates.contains(this.get('content.cluster.status'));
- }.property('content.cluster.status'),
- /**
- * Observer function: Enables previous steps link if install task failed in installer wizard.
- * @method togglePreviousSteps
- */
- togglePreviousSteps: function () {
- if (App.get('testMode')) {
- return;
- }
- var installerController = App.router.get('installerController');
- if ('INSTALL FAILED' === this.get('content.cluster.status') && this.get('content.controllerName') == 'installerController') {
- installerController.setStepsEnable();
- } else {
- installerController.setLowerStepsDisable(9);
- }
- }.observes('content.cluster.status', 'content.controllerName'),
- /**
- * Computed property to determine if the Retry button should be made visible on the page.
- * @type {bool}
- */
- showRetry: function () {
- return this.get('content.cluster.status') == 'INSTALL FAILED';
- }.property('content.cluster.status'),
- /**
- * Observer function: Calls {hostStatusUpdates} function once with change in a host status from any registered hosts.
- * @method hostStatusObserver
- */
- hostStatusObserver: function () {
- Em.run.once(this, 'updateStatus');
- }.observes('hosts.@each.status'),
- /**
- * A flag that gets set with installation failure.
- * @type {bool}
- */
- installFailed: false,
- /**
- * Incremental flag that triggers an event in step 9 view to change the tasks related data and icons of hosts.
- * @type {number}
- */
- logTasksChangesCounter: 0,
- /**
- * <code>taskId</code> of current open task
- * @type {number}
- */
- currentOpenTaskId: 0,
- /**
- * <code>requestId</code> of current open task
- * @type {number}
- */
- currentOpenTaskRequestId: 0,
- /**
- * True if stage transition is completed.
- * On true, polling will be stopped.
- * @type {bool}s
- */
- parseHostInfo: false,
- isPolling: true,
- changeParseHostInfo: function (value) {
- this.set('parseHostInfo', value);
- this.parseHostInfoPolling();
- },
- parseHostInfoPolling: function () {
- var self = this;
- var result = this.get('parseHostInfo');
- if (!this.get('isPolling')) {
- if (this.get('content.cluster.status') === 'INSTALL FAILED') {
- this.isAllComponentsInstalled();
- }
- return;
- }
- if (result !== true) {
- window.setTimeout(function () {
- if (self.get('currentOpenTaskId')) {
- self.loadCurrentTaskLog();
- }
- if (App.router.loggedIn) {
- self.doPolling();
- }
- }, this.get('POLL_INTERVAL'));
- }
- },
- /**
- * Observer function: Updates {status} field of the controller.
- * @method updateStatus
- */
- updateStatus: function () {
- var status = 'info';
- if (this.get('hosts').someProperty('status', 'failed')
- || this.get('hosts').someProperty('status', 'heartbeat_lost')
- || this.get('startCallFailed')) {
- status = 'failed';
- } else if (this.get('hosts').someProperty('status', 'warning')) {
- if (this.isStepFailed()) {
- status = 'failed';
- } else {
- status = 'warning';
- }
- } else if (this.get('progress') == '100' && this.get('content.cluster.status') !== 'INSTALL FAILED') {
- status = 'success';
- }
- this.set('status', status);
- }.observes('progress'),
- /**
- * This function is called when a click event happens on Next button of "Install, Start and Test" page
- * @method submit
- */
- submit: function () {
- App.router.send('next');
- },
- /**
- * This function is called when a click event happens on back button of "Install, Start and Test" page
- * @method back
- */
- back: function () {
- if (!this.get('isSubmitDisabled')) {
- App.router.send('back');
- }
- },
- /**
- * navigateStep is called by App.WizardStep9View's didInsertElement and "retry" from router.
- * content.cluster.status can be:
- * PENDING: set upon successful transition from step 1 to step 2
- * INSTALLED: set upon successful completion of install phase as well as successful invocation of start services API
- * STARTED: set up on successful completion of start phase
- * INSTALL FAILED: set up upon encountering a failure in install phase
- * START FAILED: set upon unsuccessful invocation of start services API and also upon encountering a failure
- * during start phase
- * content.cluster.isCompleted
- * set to false upon successful transition from step 1 to step 2
- * set to true upon successful start of services in this step
- * note: looks like this is the same thing as checking content.cluster.status == 'STARTED'
- * @method navigateStep
- */
- navigateStep: function () {
- if (App.get('testMode')) {
- // this is for repeatedly testing out installs in test mode
- this.set('content.cluster.status', 'PENDING');
- this.set('content.cluster.isCompleted', false);
- this.set('content.cluster.requestId', 1);
- }
- var needPolling = false;
- var clusterStatus = this.get('content.cluster.status');
- console.log('navigateStep: clusterStatus = ' + clusterStatus);
- if (this.get('content.cluster.isCompleted') === false) {
- if (clusterStatus !== 'INSTALL FAILED' && clusterStatus !== 'START FAILED') {
- needPolling = true;
- }
- } else {
- // handle STARTED
- // the cluster has successfully installed and started
- this.set('progress', '100');
- }
- this.loadStep();
- this.loadLogData(needPolling);
- },
- /**
- * This is called on initial page load, refreshes and retry event.
- * clears all in memory stale data for retry event.
- * @method clearStep
- */
- clearStep: function () {
- this.get('hosts').clear();
- this.set('hostsWithHeartbeatLost', []);
- this.set('startCallFailed', false);
- this.set('status', 'info');
- this.set('progress', '0');
- this.set('numPolls', 1);
- },
- /**
- * This is called on initial page load, refreshes and retry event.
- * @method loadStep
- */
- loadStep: function () {
- console.log("TRACE: Loading step9: Install, Start and Test");
- this.clearStep();
- this.loadHosts();
- },
- /**
- * Reset status and message of all hosts when retry install
- * @method resetHostsForRetry
- */
- resetHostsForRetry: function () {
- var hosts = this.get('content.hosts');
- for (var name in hosts) {
- if (hosts.hasOwnProperty(name)) {
- hosts[name].status = "pending";
- hosts[name].message = 'Waiting';
- hosts[name].isNoTasksForInstall = false;
- }
- }
- this.set('content.hosts', hosts);
- },
- /**
- * Sets the <code>hosts</code> array for the controller
- * @method loadHosts
- */
- loadHosts: function () {
- var hosts = this.get('content.hosts');
- //flag identify whether get all hosts or only NewHosts(newly added) hosts
- var getOnlyNewHosts = (this.get('content.controllerName') !== 'addServiceController');
- for (var index in hosts) {
- if (hosts[index].bootStatus === 'REGISTERED' && (!getOnlyNewHosts || !hosts[index].isInstalled)) {
- var hostInfo = App.HostInfo.create({
- name: hosts[index].name,
- status: (hosts[index].status) ? hosts[index].status : 'info',
- logTasks: [],
- message: (hosts[index].message) ? hosts[index].message : 'Waiting',
- progress: 0,
- isNoTasksForInstall: false
- });
- this.get('hosts').pushObject(hostInfo);
- }
- }
- },
- /**
- * Set new polled data
- * @param polledData sets the <code>polledData</code> object of the controller
- * @method replacePolledData
- */
- replacePolledData: function (polledData) {
- this.get('polledData').clear();
- this.set('polledData', polledData);
- },
- /**
- * Get the appropriate message for the host as per the running task
- * @param {object} task
- * @returns {String}
- * @method displayMessage
- */
- displayMessage: function (task) {
- var role = App.format.role(task.role);
- /* istanbul ignore next */
- switch (task.command) {
- case 'INSTALL':
- switch (task.status) {
- case 'PENDING':
- return Em.I18n.t('installer.step9.serviceStatus.install.pending') + role;
- case 'QUEUED' :
- return Em.I18n.t('installer.step9.serviceStatus.install.queued') + role;
- case 'IN_PROGRESS':
- return Em.I18n.t('installer.step9.serviceStatus.install.inProgress') + role;
- case 'COMPLETED' :
- return Em.I18n.t('installer.step9.serviceStatus.install.completed') + role;
- case 'FAILED':
- return Em.I18n.t('installer.step9.serviceStatus.install.failed') + role;
- }
- break;
- case 'UNINSTALL':
- switch (task.status) {
- case 'PENDING':
- return Em.I18n.t('installer.step9.serviceStatus.uninstall.pending') + role;
- case 'QUEUED' :
- return Em.I18n.t('installer.step9.serviceStatus.uninstall.queued') + role;
- case 'IN_PROGRESS':
- return Em.I18n.t('installer.step9.serviceStatus.uninstall.inProgress') + role;
- case 'COMPLETED' :
- return Em.I18n.t('installer.step9.serviceStatus.uninstall.completed') + role;
- case 'FAILED':
- return Em.I18n.t('installer.step9.serviceStatus.uninstall.failed') + role;
- }
- break;
- case 'START' :
- switch (task.status) {
- case 'PENDING':
- return Em.I18n.t('installer.step9.serviceStatus.start.pending') + role;
- case 'QUEUED' :
- return Em.I18n.t('installer.step9.serviceStatus.start.queued') + role;
- case 'IN_PROGRESS':
- return Em.I18n.t('installer.step9.serviceStatus.start.inProgress') + role;
- case 'COMPLETED' :
- return role + Em.I18n.t('installer.step9.serviceStatus.start.completed');
- case 'FAILED':
- return role + Em.I18n.t('installer.step9.serviceStatus.start.failed');
- }
- break;
- case 'STOP' :
- switch (task.status) {
- case 'PENDING':
- return Em.I18n.t('installer.step9.serviceStatus.stop.pending') + role;
- case 'QUEUED' :
- return Em.I18n.t('installer.step9.serviceStatus.stop.queued') + role;
- case 'IN_PROGRESS':
- return Em.I18n.t('installer.step9.serviceStatus.stop.inProgress') + role;
- case 'COMPLETED' :
- return role + Em.I18n.t('installer.step9.serviceStatus.stop.completed');
- case 'FAILED':
- return role + Em.I18n.t('installer.step9.serviceStatus.stop.failed');
- }
- break;
- case 'EXECUTE' :
- case 'SERVICE_CHECK' :
- switch (task.status) {
- case 'PENDING':
- return Em.I18n.t('installer.step9.serviceStatus.execute.pending') + role;
- case 'QUEUED' :
- return Em.I18n.t('installer.step9.serviceStatus.execute.queued') + role;
- case 'IN_PROGRESS':
- return Em.I18n.t('installer.step9.serviceStatus.execute.inProgress') + role;
- case 'COMPLETED' :
- return role + Em.I18n.t('installer.step9.serviceStatus.execute.completed');
- case 'FAILED':
- return role + Em.I18n.t('installer.step9.serviceStatus.execute.failed');
- }
- break;
- case 'ABORT' :
- switch (task.status) {
- case 'PENDING':
- return Em.I18n.t('installer.step9.serviceStatus.abort.pending') + role;
- case 'QUEUED' :
- return Em.I18n.t('installer.step9.serviceStatus.abort.queued') + role;
- case 'IN_PROGRESS':
- return Em.I18n.t('installer.step9.serviceStatus.abort.inProgress') + role;
- case 'COMPLETED' :
- return role + Em.I18n.t('installer.step9.serviceStatus.abort.completed');
- case 'FAILED':
- return role + Em.I18n.t('installer.step9.serviceStatus.abort.failed');
- }
- }
- return '';
- },
- /**
- * Run start/check services after installation phase.
- * Does Ajax call to start all services
- * @return {$.ajax|null}
- * @method launchStartServices
- */
- launchStartServices: function (callback) {
- var data = {};
- var name = '';
- callback = callback || Em.K;
- switch(this.get('content.controllerName')) {
- case 'addHostController':
- name = 'common.host_components.update';
- var hostnames = [];
- for (var hostname in this.get('wizardController').getDBProperty('hosts')) {
- if(this.get('hosts').findProperty('name', hostname)){
- hostnames.push(hostname);
- }
- }
- data = {
- "context": Em.I18n.t("requestInfo.startHostComponents"),
- "query": "HostRoles/component_name.in(" + App.get('components.slaves').join(',') + ")&HostRoles/state=INSTALLED&HostRoles/host_name.in(" + hostnames.join(',') + ")",
- "HostRoles": { "state": "STARTED"}
- };
- break;
- case 'addServiceController':
- var servicesList = this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
- if (servicesList.contains('OOZIE')) {
- servicesList = servicesList.concat(['HDFS', 'YARN', 'MAPREDUCE2']);
- }
- name = 'common.services.update';
- data = {
- "context": Em.I18n.t("requestInfo.startAddedServices"),
- "ServiceInfo": { "state": "STARTED" },
- "urlParams": "ServiceInfo/state=INSTALLED&ServiceInfo/service_name.in(" + servicesList.join(",") + ")¶ms/run_smoke_test=true¶ms/reconfigure_client=false"
- };
- break;
- default:
- name = 'common.services.update';
- data = {
- "context": Em.I18n.t("requestInfo.startServices"),
- "ServiceInfo": { "state": "STARTED" },
- "urlParams": "ServiceInfo/state=INSTALLED¶ms/run_smoke_test=" + !this.get('skipServiceChecks') + "¶ms/reconfigure_client=false"
- };
- }
- if (App.get('testMode')) {
- this.set('numPolls', 6);
- }
- return App.ajax.send({
- name: name,
- sender: this,
- data: data,
- success: 'launchStartServicesSuccessCallback',
- error: 'launchStartServicesErrorCallback'
- }).then(callback, callback);
- },
- /**
- * Success callback function for start services task.
- * @param {object} jsonData Contains Request id to poll.
- * @method launchStartServicesSuccessCallback
- */
- launchStartServicesSuccessCallback: function (jsonData) {
- var clusterStatus = {};
- if (jsonData) {
- console.log("TRACE: Step9 -> In success function for the startService call");
- console.log("TRACE: Step9 -> value of the received data is: " + jsonData);
- var requestId = jsonData.Requests.id;
- console.log('requestId is: ' + requestId);
- clusterStatus = {
- status: 'INSTALLED',
- requestId: requestId,
- isStartError: false,
- isCompleted: false
- };
- this.hostHasClientsOnly(false);
- this.saveClusterStatus(clusterStatus);
- }
- else {
- console.log('ERROR: Error occurred in parsing JSON data');
- this.hostHasClientsOnly(true);
- clusterStatus = {
- status: 'STARTED',
- isStartError: false,
- isCompleted: true
- };
- this.saveClusterStatus(clusterStatus);
- this.set('status', 'success');
- this.set('progress', '100');
- }
- // We need to do recovery if there is a browser crash
- App.clusterStatus.setClusterStatus({
- clusterState: 'SERVICE_STARTING_3',
- wizardControllerName: this.get('content.controllerName'),
- localdb: App.db.data
- });
- if (jsonData) {
- this.startPolling();
- }
- },
- /**
- * This function will be called for Add host wizard only.
- * @param {bool} jsonError Boolean is true when API to start services returns 200 ok and no json data
- * @method hostHasClientsOnly
- */
- hostHasClientsOnly: function (jsonError) {
- this.get('hosts').forEach(function (host) {
- var OnlyClients = true;
- var tasks = host.get('logTasks');
- tasks.forEach(function (task) {
- var component = App.StackServiceComponent.find().findProperty('componentName', task.Tasks.role);
- if (!(component && component.get('isClient'))) {
- OnlyClients = false;
- }
- });
- if (OnlyClients || jsonError) {
- host.set('status', 'success');
- host.set('progress', '100');
- }
- });
- },
- /**
- * Error callback function for start services task.
- * @param {object} jqXHR
- * @param {object} ajaxOptions
- * @param {string} error
- * @param {object} opt
- * @method launchStartServicesErrorCallback
- */
- launchStartServicesErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
- console.log("ERROR");
- this.set('startCallFailed', true);
- var clusterStatus = {
- status: 'INSTALL FAILED',
- isStartError: false,
- isCompleted: false
- };
- this.saveClusterStatus(clusterStatus);
- this.get('hosts').forEach(function (host) {
- host.set('progress', '100');
- });
- this.set('progress', '100');
- App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.method, jqXHR.status);
- },
- /**
- * Marks a host's status as "success" if all tasks are in COMPLETED state
- * @method onSuccessPerHost
- */
- onSuccessPerHost: function (actions, contentHost) {
- var status = this.get('content.cluster.status');
- if (actions.everyProperty('Tasks.status', 'COMPLETED') &&
- (status === 'INSTALLED' || status === 'STARTED') ) {
- contentHost.set('status', 'success');
- }
- },
- /**
- * marks a host's status as "warning" if at least one of the tasks is FAILED, ABORTED, or TIMEDOUT and marks host's status as "failed" if at least one master component install task is FAILED.
- * note that if the master failed to install because of ABORTED or TIMEDOUT, we don't mark it as failed, because this would mark all hosts as "failed" and makes it difficult for the user
- * to find which host FAILED occurred on, if any
- * @param actions {Array} of tasks retrieved from polled data
- * @param contentHost {Object} A host object
- * @method onErrorPerHost
- */
- onErrorPerHost: function (actions, contentHost) {
- if (!actions) return;
- if (actions.someProperty('Tasks.status', 'FAILED') || actions.someProperty('Tasks.status', 'ABORTED') || actions.someProperty('Tasks.status', 'TIMEDOUT')) {
- contentHost.set('status', 'warning');
- }
- if ((this.get('content.cluster.status') === 'PENDING' && actions.someProperty('Tasks.status', 'FAILED')) || (this.isMasterFailed(actions))) {
- contentHost.get('status') !== 'heartbeat_lost' ? contentHost.set('status', 'failed') : '';
- }
- },
- /**
- * Check if some master component is failed
- * @param {object} polledData data polled from API.
- * @returns {bool} true if there is at least one FAILED task of master component install
- * @method isMasterFailed
- */
- isMasterFailed: function (polledData) {
- var result = false;
- polledData.filterProperty('Tasks.command', 'INSTALL').filterProperty('Tasks.status', 'FAILED').mapProperty('Tasks.role').forEach(
- function (role) {
- if (!App.get('components.slaves').contains(role)) {
- result = true;
- }
- }
- );
- return result;
- },
- /**
- * Mark a host status as in_progress if the any task on the host if either in IN_PROGRESS, QUEUED or PENDONG state.
- * @param actions {Array} of tasks retrieved from polled data
- * @param contentHost {Object} A host object
- * @method onInProgressPerHost
- */
- onInProgressPerHost: function (actions, contentHost) {
- var runningAction = actions.findProperty('Tasks.status', 'IN_PROGRESS');
- if (runningAction === undefined || runningAction === null) {
- runningAction = actions.findProperty('Tasks.status', 'QUEUED');
- }
- if (runningAction === undefined || runningAction === null) {
- runningAction = actions.findProperty('Tasks.status', 'PENDING');
- }
- if (runningAction !== null && runningAction !== undefined) {
- contentHost.set('status', 'in_progress');
- contentHost.set('message', this.displayMessage(runningAction.Tasks));
- }
- },
- /**
- * Calculate progress of tasks per host
- * @param {object} actions
- * @param {object} contentHost
- * @return {Number}
- * @method progressPerHost
- */
- progressPerHost: function (actions, contentHost) {
- var progress = 0;
- var actionsPerHost = actions.length;
- var completedActions = 0;
- var queuedActions = 0;
- var inProgressActions = 0;
- actions.forEach(function (action) {
- completedActions += +(['COMPLETED', 'FAILED', 'ABORTED', 'TIMEDOUT'].contains(action.Tasks.status));
- queuedActions += +(action.Tasks.status === 'QUEUED');
- inProgressActions += +(action.Tasks.status === 'IN_PROGRESS');
- }, this);
- /** for the install phase (PENDING), % completed per host goes up to 33%; floor(100 / 3)
- * for the start phase (INSTALLED), % completed starts from 34%
- * when task in queued state means it's completed on 9%
- * in progress - 35%
- * completed - 100%
- */
- switch (this.get('content.cluster.status')) {
- case 'PENDING':
- progress = actionsPerHost ? (Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 33)) : 33;
- break;
- case 'INSTALLED':
- progress = actionsPerHost ? (34 + Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 66)) : 100;
- break;
- default:
- progress = 100;
- break;
- }
- contentHost.set('progress', progress.toString());
- return progress;
- },
- /**
- * Check if step completed successfully
- * @param {object} polledData data retrieved from API
- * @returns {bool}
- * @method isSuccess
- */
- isSuccess: function (polledData) {
- return polledData.everyProperty('Tasks.status', 'COMPLETED');
- },
- /**
- * Check if step is failed
- * Return true if:
- * 1. any of the master/client components failed to install
- * OR
- * 2. at least 50% of the slave host components for the particular service component fails to install
- * @method isStepFailed
- */
- isStepFailed: function () {
- var failed = false;
- var polledData = this.get('polledData');
- polledData.filterProperty('Tasks.command', 'INSTALL').mapProperty('Tasks.role').uniq().forEach(function (role) {
- if (failed) {
- return;
- }
- var actionsPerRole = polledData.filterProperty('Tasks.role', role);
- if (App.get('components.slaves').contains(role)) {
- // check slave components for success factor.
- // partial failure for slave components are allowed.
- var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
- var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
- var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
- if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > 50) {
- failed = true;
- }
- } else if (actionsPerRole.someProperty('Tasks.status', 'FAILED') || actionsPerRole.someProperty('Tasks.status', 'ABORTED') ||
- actionsPerRole.someProperty('Tasks.status', 'TIMEDOUT')) {
- // check non-salve components (i.e., masters and clients). all of these must be successfully installed.
- failed = true;
- }
- }, this);
- return failed;
- },
- /**
- * polling from ui stops only when no action has 'PENDING', 'QUEUED' or 'IN_PROGRESS' status
- * Makes a state transition
- * PENDING -> INSTALLED
- * PENDING -> INSTALL FAILED
- * INSTALLED -> STARTED
- * INSTALLED -> START_FAILED
- * @param polledData json data retrieved from API
- * @method setFinishState
- */
- setFinishState: function (polledData) {
- if (this.get('content.cluster.status') === 'INSTALLED') {
- Em.run.next(this, function(){
- this.changeParseHostInfo(this.isServicesStarted(polledData));
- });
- return;
- } else if (this.get('content.cluster.status') === 'PENDING') {
- this.setIsServicesInstalled(polledData);
- return;
- } else if (this.get('content.cluster.status') === 'INSTALL FAILED' || this.get('content.cluster.status') === 'START FAILED'
- || this.get('content.cluster.status') === 'STARTED') {
- this.set('progress', '100');
- this.changeParseHostInfo(true);
- return;
- }
- this.changeParseHostInfo(true);
- },
- /**
- * @param polledData JSON data retrieved from API
- * @returns {bool} Has "Start All Services" request completed successfully
- * @method isServicesStarted
- */
- isServicesStarted: function (polledData) {
- var clusterStatus = {};
- if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
- this.set('progress', '100');
- clusterStatus = {
- status: 'INSTALLED',
- requestId: this.get('content.cluster.requestId'),
- isCompleted: true
- };
- if (this.isSuccess(polledData)) {
- clusterStatus.status = 'STARTED';
- var serviceStartTime = App.dateTime();
- clusterStatus.installTime = ((parseInt(serviceStartTime) - parseInt(this.get('content.cluster.installStartTime'))) / 60000).toFixed(2);
- }
- else {
- clusterStatus.status = 'START FAILED'; // 'START FAILED' implies to step10 that installation was successful but start failed
- }
- this.saveClusterStatus(clusterStatus);
- this.saveInstalledHosts(this);
- return true;
- }
- return false;
- },
- /**
- * @param polledData Json data retrieved from API
- * @method setIsServicesInstalled
- */
- setIsServicesInstalled: function (polledData) {
- var clusterStatus = {};
- var self = this;
- if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
- clusterStatus = {
- status: 'PENDING',
- requestId: this.get('content.cluster.requestId'),
- isCompleted: false
- };
- if (this.get('status') === 'failed') {
- clusterStatus.status = 'INSTALL FAILED';
- this.saveClusterStatus(clusterStatus);
- this.setProperties({
- progress: '100',
- isPolling: false
- });
- this.get('hosts').forEach(function (host) {
- host.set('progress', '100');
- });
- this.isAllComponentsInstalled().done(function(){
- self.changeParseHostInfo(false);
- });
- return;
- } else {
- this.set('progress', '34');
- if (this.get('content.controllerName') === 'installerController') {
- this.isAllComponentsInstalled().done(function(){
- self.saveInstalledHosts(self);
- self.changeParseHostInfo(true);
- });
- return;
- } else {
- this.launchStartServices(function () {
- self.saveInstalledHosts(self);
- self.changeParseHostInfo(true);
- });
- return;
- }
- }
- }
- this.changeParseHostInfo(false);
- },
- /**
- * This is done at HostRole level.
- * @param {Ember.Enumerable} tasksPerHost
- * @param {Object} host
- * @method setLogTasksStatePerHost
- */
- setLogTasksStatePerHost: function (tasksPerHost, host) {
- tasksPerHost.forEach(function (_task) {
- var task = host.logTasks.findProperty('Tasks.id', _task.Tasks.id);
- if (task) {
- task.Tasks.status = _task.Tasks.status;
- task.Tasks.start_time = _task.Tasks.start_time;
- task.Tasks.end_time = _task.Tasks.end_time;
- task.Tasks.exit_code = _task.Tasks.exit_code;
- } else {
- host.logTasks.pushObject(_task);
- }
- }, this);
- },
- /**
- * Parses the Json data retrieved from API and sets the task on the host of {hosts} array binded to template
- * @param polledData Json data retrieved from API
- * @method setParseHostInfo
- */
- setParseHostInfo: function (polledData) {
- console.log('TRACE: Entering host info function');
- var self = this;
- var totalProgress = 0;
- var tasksData = polledData.tasks || [];
- console.log("The value of tasksData is: ", tasksData);
- var requestId = this.get('content.cluster.requestId');
- tasksData.setEach('Tasks.request_id', requestId);
- if (polledData.Requests && polledData.Requests.id && polledData.Requests.id != requestId) {
- // We don't want to use non-current requestId's tasks data to
- // determine the current install status.
- // Also, we don't want to keep polling if it is not the
- // current requestId.
- this.changeParseHostInfo(false);
- return;
- }
- this.replacePolledData(tasksData);
- var tasksHostMap = {};
- tasksData.forEach(function (task) {
- if (tasksHostMap[task.Tasks.host_name]) {
- tasksHostMap[task.Tasks.host_name].push(task);
- } else {
- tasksHostMap[task.Tasks.host_name] = [task];
- }
- });
- this.get('hosts').forEach(function (_host) {
- var actionsPerHost = tasksHostMap[_host.name] || []; // retrieved from polled Data
- if (actionsPerHost.length === 0) {
- if (this.get('content.cluster.status') === 'PENDING' || this.get('content.cluster.status') === 'INSTALL FAILED') {
- _host.set('progress', '33');
- _host.set('isNoTasksForInstall', true);
- _host.set('status', 'pending');
- }
- if (this.get('content.cluster.status') === 'INSTALLED' || this.get('content.cluster.status') === 'FAILED') {
- _host.set('progress', '100');
- _host.set('status', 'success');
- }
- console.log("INFO: No task is hosted on the host");
- } else {
- _host.set('isNoTasksForInstall', false);
- }
- this.setLogTasksStatePerHost(actionsPerHost, _host);
- this.onSuccessPerHost(actionsPerHost, _host); // every action should be a success
- this.onErrorPerHost(actionsPerHost, _host); // any action should be a failure
- this.onInProgressPerHost(actionsPerHost, _host); // current running action for a host
- totalProgress += self.progressPerHost(actionsPerHost, _host);
- if (_host.get('progress') == '33' && _host.get('status') != 'failed' && _host.get('status') != 'warning') {
- _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
- _host.set('status', 'pending');
- }
- }, this);
- this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
- totalProgress = Math.floor(totalProgress / this.get('hosts.length'));
- this.set('progress', totalProgress.toString());
- console.log("INFO: right now the progress is: " + this.get('progress'));
- this.setFinishState(tasksData);
- },
- /**
- * Starts polling to the API
- * @method startPolling
- */
- startPolling: function () {
- this.set('isSubmitDisabled', true);
- this.doPolling();
- },
- /**
- * This function calls API just once to fetch log data of all tasks.
- * @method loadLogData
- */
- loadLogData: function (startPolling) {
- var requestsId = this.get('wizardController').getDBProperty('cluster').oldRequestsId;
- if (App.get('testMode')) {
- this.set('POLL_INTERVAL', 1);
- }
- this.getLogsByRequest(!!startPolling, requestsId[requestsId.length-1]);
- },
- /**
- * Load form server <code>stderr, stdout</code> of current open task
- * @method loadCurrentTaskLog
- */
- loadCurrentTaskLog: function () {
- var taskId = this.get('currentOpenTaskId');
- var requestId = this.get('currentOpenTaskRequestId');
- var clusterName = this.get('content.cluster.name');
- if (!taskId) {
- console.log('taskId is null.');
- return;
- }
- App.ajax.send({
- name: 'background_operations.get_by_task',
- sender: this,
- data: {
- 'taskId': taskId,
- 'requestId': requestId,
- 'clusterName': clusterName
- },
- success: 'loadCurrentTaskLogSuccessCallback',
- error: 'loadCurrentTaskLogErrorCallback'
- });
- },
- /**
- * success callback function for getting log data of the opened task
- * @param {object} data
- * @method loadCurrentTaskLogSuccessCallback
- */
- loadCurrentTaskLogSuccessCallback: function (data) {
- var taskId = this.get('currentOpenTaskId');
- if (taskId) {
- var host = this.get('hosts').findProperty('name', data.Tasks.host_name);
- if (host) {
- var currentTask = host.get('logTasks').findProperty('Tasks.id', data.Tasks.id);
- if (currentTask) {
- currentTask.Tasks.stderr = data.Tasks.stderr;
- currentTask.Tasks.stdout = data.Tasks.stdout;
- currentTask.Tasks.output_log = data.Tasks.output_log;
- currentTask.Tasks.error_log = data.Tasks.error_log;
- }
- }
- }
- this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
- },
- /**
- * Error callback function for getting log data of the opened task
- * @method loadCurrentTaskLogErrorCallback
- */
- loadCurrentTaskLogErrorCallback: function () {
- this.set('currentOpenTaskId', 0);
- },
- /**
- * Function polls the API to retrieve data for the request.
- * @param {bool} polling whether to continue polling for status or not
- * @param {number} requestId
- * @method getLogsByRequest
- * @return {$.ajax|null}
- */
- getLogsByRequest: function (polling, requestId) {
- var self = this;
- return App.ajax.send({
- name: 'wizard.step9.load_log',
- sender: this,
- data: {
- polling: polling,
- cluster: this.get('content.cluster.name'),
- requestId: requestId,
- numPolls: this.get('numPolls')
- },
- success: 'getLogsByRequestSuccessCallback',
- error: 'getLogsByRequestErrorCallback'
- }).retry({times: App.maxRetries, timeout: 3000}).then(
- function () {
- self.closeReloadPopup();
- },
- function () {
- self.showReloadPopup();
- console.log('Install services all retries failed');
- }
- );
- },
- /**
- * Success callback for get log by request
- * @param {object} data
- * @param {object} opt
- * @param {object} params
- * @method getLogsByRequestSuccessCallback
- */
- getLogsByRequestSuccessCallback: function (data, opt, params) {
- var parsedData = jQuery.parseJSON(data);
- console.log("TRACE: In success function for the GET logs data");
- console.log("TRACE: Step9 -> The value is: ", parsedData);
- this.set('isPolling', params.polling);
- this.setParseHostInfo(parsedData);
- },
- /**
- * Error-callback for get log by request
- * @method getLogsByRequestErrorCallback
- */
- getLogsByRequestErrorCallback: function () {
- this.loadLogData(true);
- },
- /**
- * Delegates the function call to {getLogsByRequest} with appropriate params
- * @method doPolling
- */
- doPolling: function () {
- var requestId = this.get('content.cluster.requestId');
- if (App.get('testMode')) {
- this.incrementProperty('numPolls');
- }
- this.getLogsByRequest(true, requestId);
- },
- /**
- * Check that all components are in INSTALLED state before issuing start command
- * @method isAllComponentsInstalled
- * @return {$.ajax|null}
- */
- isAllComponentsInstalled: function () {
- var dfd = $.Deferred();
- if (this.get('content.controllerName') !== 'installerController' && this.get('content.controllerName') !== 'addHostController') {
- dfd.resolve();
- } else {
- App.ajax.send({
- name: 'wizard.step9.installer.get_host_status',
- sender: this,
- data: {
- cluster: this.get('content.cluster.name')
- },
- success: 'isAllComponentsInstalledSuccessCallback',
- error: 'isAllComponentsInstalledErrorCallback'
- }).complete(function(){
- dfd.resolve();
- });
- }
- return dfd.promise();
- },
- /**
- * Success callback function for API checking host state and host_components state.
- * @param {Object} jsonData
- * @method isAllComponentsInstalledSuccessCallback
- */
- isAllComponentsInstalledSuccessCallback: function (jsonData) {
- var clusterStatus = {
- status: 'INSTALL FAILED',
- isStartError: true,
- isCompleted: false
- };
- var hostsWithHeartbeatLost = [];
- jsonData.items.filterProperty('Hosts.host_state', 'HEARTBEAT_LOST').forEach(function (host) {
- var hostComponentObj = {hostName: host.Hosts.host_name};
- var componentArr = [];
- host.host_components.forEach(function (_hostComponent) {
- var componentName = App.format.role(_hostComponent.HostRoles.component_name);
- componentArr.pushObject(componentName);
- }, this);
- hostComponentObj.componentNames = stringUtils.getFormattedStringFromArray(componentArr);
- hostsWithHeartbeatLost.pushObject(hostComponentObj);
- }, this);
- this.set('hostsWithHeartbeatLost', hostsWithHeartbeatLost);
- if (hostsWithHeartbeatLost.length) {
- this.get('hosts').forEach(function (host) {
- if (hostsWithHeartbeatLost.someProperty(('hostName'), host.get('name'))) {
- host.set('status', 'heartbeat_lost');
- } else if (host.get('status') !== 'failed' && host.get('status') !== 'warning') {
- host.set('message', Em.I18n.t('installer.step9.host.status.startAborted'));
- }
- host.set('progress', '100');
- });
- this.set('progress', '100');
- this.saveClusterStatus(clusterStatus);
- } else if (this.get('content.cluster.status') === 'PENDING' && this.get('isPolling')) {
- this.launchStartServices();
- }
- },
- /**
- * Error callback function for API checking host state and host_components state
- * @method isAllComponentsInstalledErrorCallback
- */
- isAllComponentsInstalledErrorCallback: function () {
- var clusterStatus = {
- status: 'INSTALL FAILED',
- isStartError: true,
- isCompleted: false
- };
- this.set('progress', '100');
- this.get('hosts').forEach(function (host) {
- if (host.get('status') !== 'failed' && host.get('status') !== 'warning') {
- host.set('message', Em.I18n.t('installer.step9.host.status.startAborted'));
- host.set('progress', '100');
- }
- });
- this.saveClusterStatus(clusterStatus);
- },
- /**
- * save cluster status in the parentController and localdb
- * @param {object} clusterStatus
- * @method saveClusterStatus
- */
- saveClusterStatus: function (clusterStatus) {
- if (!App.get('testMode')) {
- App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
- }
- else {
- this.set('content.cluster', clusterStatus);
- }
- },
- /**
- * save cluster status in the parentController and localdb
- * @param {object} context
- * @method saveInstalledHosts
- */
- saveInstalledHosts: function (context) {
- if (!App.get('testMode')) {
- App.router.get(this.get('content.controllerName')).saveInstalledHosts(context);
- }
- },
- /**
- * Load ambari property to determine if we should run service checks on deploy
- */
- loadDoServiceChecksFlag: function () {
- var def = $.Deferred();
- App.ajax.send({
- name: 'ambari.service',
- sender: this,
- data: {
- fields: '?fields=RootServiceComponents/properties/skip.service.checks'
- },
- success: 'loadDoServiceChecksFlagSuccessCallback'
- }).complete(function(){
- def.resolve();
- });
- return def.promise();
- },
- /**
- * Callback function Load ambari property to determine if we should run service checks on deploy
- * @param {Object} data
- * @method loadDoServiceChecksFlagSuccessCallback
- */
- loadDoServiceChecksFlagSuccessCallback: function (data) {
- var properties = Em.get(data, 'RootServiceComponents.properties');
- if(properties && properties.hasOwnProperty('skip.service.checks')){
- this.set('skipServiceChecks', properties['skip.service.checks'] === 'true');
- }
- }
- });
|