Code coverage report for app/controllers/wizard/step9_controller.js

Statements: 83.61% (357 / 427)      Branches: 77.32% (208 / 269)      Functions: 77.14% (54 / 70)      Lines: 83.8% (357 / 426)      Ignored: 42 statements, 38 branches     

All files » app/controllers/wizard/ » step9_controller.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243    1                                   1 1   1                                                                                                                                                                               25 25 25 12   25                                                               353                                                                                                                                     109 109 16 93 2 1   1   91 20   109               1               2 1                                       4           4 4 4 3 1         1   4 4                 4 4 4 4 4 4               2 2               4 4 8 8 8 8     4               3     3   3 12 6               6                     3 3                   4   4   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1     1   1   1   1   1   1   1   1   1   1   1   1   1     4                   3 3 3 3   1 1 1 1 86       1         1   1 1 1   1 1         1   1 1             3 3     3                             7 7 3 3           3 3   4 4         4 4 4     7           7 3                   4 8 8 8 12 12 4     8 6 6                           3 3         3 3 6   3   3 3                             7 7 2                         8 8 4   8 1                     5 5 14 1     5                   6 6 5   6 4   6 4 4                       22 22 22 22 22 22 22 1626 1626 1626               22   8 8   12 12   2 2   22 22                   4                       10 10 10 12 1   11 11     9 9 9 9 4   2   1     10                                                                       3 3 2 2         2 1 1 1   1   2 2 2   1               6 6   6 6         6 1 1 1       1 1   1     1   5 4 4 4 4 16 16 16   4 4 4   1 1       1     4                   6 9 9 6 6 6 6   3                     3 3 3 3 3 3         1 1   2 2 2 4 2   2       2 2 2 1 1 1 1   1         1   2 2 2 2 2 2 1 1     2 2 2 2               5 5               1 1     1               2 2 2 2 1   1                                     4 4 3 3 2 2 1 1 1 1       4               1                                                                                                                                 1 1     1                 2 2                     2                 6         6 6 6 6 12   6 6 12 12 12 24 24   12 12 12 6     6 6 6 12 12       12   6 6                               1         1 1 6 6 6     1                                                                                                     2 2 2          
'use strict';
 
;require.register("controllers/wizard/step9_controller", function (exports, require, module) {
  /**
   * 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', 'START_SKIPPED'];
      var controllerName = this.get('content.controllerName');
      if (controllerName == 'addHostController' || controllerName == 'addServiceController') {
        validStates.push('INSTALL FAILED');
      }
      return !validStates.contains(this.get('content.cluster.status')) || App.get('router.btnClickInProgress');
    }.property('content.cluster.status'),
 
    isNextButtonDisabled: Em.computed.or('App.router.nextBtnClickInProgress', 'isSubmitDisabled'),
 
    /**
     * 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: Em.computed.equal('content.cluster.status', 'INSTALL FAILED'),
 
    /**
     * 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 changeParseHostInfo(value) {
      this.set('parseHostInfo', value);
      this.parseHostInfoPolling();
    },
 
    parseHostInfoPolling: function parseHostInfoPolling() {
      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 submit() {
      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 back() {
      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 navigateStep() {
      Iif (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');
      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 clearStep() {
      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 loadStep() {
      this.clearStep();
      this.loadHosts();
    },
 
    /**
     * Reset status and message of all hosts when retry install
     * @method resetHostsForRetry
     */
    resetHostsForRetry: function resetHostsForRetry() {
      var hosts = this.get('content.hosts');
      for (var name in hosts) {
        Eif (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 loadHosts() {
      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 replacePolledData(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 displayMessage(task) {
      var role = App.format.role(task.role, false);
      /* 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 'CUSTOM_COMMAND':
          role = App.format.commandDetail(task.command_detail, task.request_input, task.ops_display_name);
        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 launchStartServices(callback) {
      var data = {};
      var name = '';
      callback = callback || Em.K;
      switch (this.get('content.controllerName')) {
        case 'addHostController':
          name = 'common.host_components.update';
          var hostnames = [];
          var hosts = this.get('wizardController').getDBProperty('hosts');
          for (var hostname in hosts) {
            Iif (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');
          Eif (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(",") + ")&params/run_smoke_test=true&params/reconfigure_client=false"
          };
          break;
        default:
          name = 'common.services.update';
          data = {
            "context": Em.I18n.t("requestInfo.startServices"),
            "ServiceInfo": { "state": "STARTED" },
            "urlParams": "ServiceInfo/state=INSTALLED&params/run_smoke_test=" + !this.get('skipServiceChecks') + "&params/reconfigure_client=false"
          };
      }
 
      Eif (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 launchStartServicesSuccessCallback(jsonData) {
      var clusterStatus = {};
      if (jsonData) {
        var requestId = jsonData.Requests.id;
        clusterStatus = {
          status: 'INSTALLED',
          requestId: requestId,
          isStartError: false,
          isCompleted: false
        };
        this.hostHasClientsOnly(false);
        this.saveClusterStatus(clusterStatus);
      } else {
        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 hostHasClientsOnly(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 launchStartServicesErrorCallback(jqXHR, ajaxOptions, error, opt) {
      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');
 
      console.log("Error starting installed services: ", jqXHR, ajaxOptions, error, opt);
      App.ModalPopup.show({
        encodeBody: false,
        primary: Em.I18n.t('ok'),
        header: Em.I18n.t('installer.step9.service.start.header'),
        secondary: false,
        body: Em.I18n.t('installer.step9.service.start.failed'),
        'data-qa': 'start-failed-modal'
      });
    },
 
    /**
     * Marks a host's status as "success" if all tasks are in COMPLETED state
     * @method onSuccessPerHost
     */
    onSuccessPerHost: function onSuccessPerHost(actions, contentHost) {
      var status = this.get('content.cluster.status');
      if (actions.everyProperty('Tasks.status', 'COMPLETED') && (status === 'INSTALLED' || status === 'STARTED') || App.get('supports.skipComponentStartAfterInstall')) {
        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 onErrorPerHost(actions, contentHost) {
      Iif (!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 isMasterFailed(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 onInProgressPerHost(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 progressPerHost(actions, contentHost) {
      var progress = 0;
      var actionsPerHost = actions.length;
      var completedActions = 0;
      var queuedActions = 0;
      var inProgressActions = 0;
      var installProgressFactor = App.get('supports.skipComponentStartAfterInstall') ? 100 : 33;
      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 * installProgressFactor) : installProgressFactor;
          break;
        case 'INSTALLED':
          progress = actionsPerHost ? 33 + Math.floor((queuedActions * 0.09 + inProgressActions * 0.35 + completedActions) / actionsPerHost * 67) : 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 isSuccess(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 isStepFailed() {
      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 setFinishState(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 isServicesStarted(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 setIsServicesInstalled(polledData) {
      var clusterStatus = {};
      var self = this;
 
      Eif (!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;
        }
        if (App.get('supports.skipComponentStartAfterInstall')) {
          clusterStatus.status = 'START_SKIPPED';
          clusterStatus.isCompleted = true;
          this.saveClusterStatus(clusterStatus);
          this.get('hosts').forEach(function (host) {
            host.set('status', 'success');
            host.set('message', Em.I18n.t('installer.step9.host.status.success'));
            host.set('progress', '100');
          });
          this.set('progress', '100');
          self.saveInstalledHosts(self);
          this.changeParseHostInfo(true);
        } else {
          this.set('progress', '34');
          this.isAllComponentsInstalled().done(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 setLogTasksStatePerHost(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 setParseHostInfo(polledData) {
      var self = this;
      var totalProgress = 0;
      var tasksData = polledData.tasks || [];
      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) {
          Eif (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');
          }
          Iif (this.get('content.cluster.status') === 'INSTALLED' || this.get('content.cluster.status') === 'FAILED' || App.get('supports.skipComponentStartAfterInstall')) {
            _host.set('progress', '100');
            _host.set('status', 'success');
          }
        } 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());
      this.setFinishState(tasksData);
    },
 
    /**
     * Starts polling to the API
     * @method startPolling
     */
    startPolling: function startPolling() {
      this.set('isSubmitDisabled', true);
      this.doPolling();
    },
 
    /**
     * This function calls API just once to fetch log data of all tasks.
     * @method loadLogData
     */
    loadLogData: function loadLogData(startPolling) {
      var requestsId = this.get('wizardController').getDBProperty('cluster').oldRequestsId;
      Iif (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 loadCurrentTaskLog() {
      var taskId = this.get('currentOpenTaskId');
      var requestId = this.get('currentOpenTaskRequestId');
      var clusterName = this.get('content.cluster.name');
      if (!taskId) {
        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 loadCurrentTaskLogSuccessCallback(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 loadCurrentTaskLogErrorCallback() {
      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 getLogsByRequest(polling, requestId) {
      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'),
          callback: this.getLogsByRequest,
          args: [polling, requestId],
          timeout: 3000
        },
        success: 'reloadSuccessCallback',
        error: 'reloadErrorCallback'
      });
    },
 
    /**
     * Success callback for get log by request
     * @param {object} data
     * @param {object} opt
     * @param {object} params
     * @method reloadSuccessCallback
     */
    reloadSuccessCallback: function reloadSuccessCallback(data, opt, params) {
      var parsedData = jQuery.parseJSON(data);
      this._super();
      this.set('isPolling', params.polling);
      this.setParseHostInfo(parsedData);
    },
 
    /**
     * Error-callback for get log by request
     * @param {object} jqXHR
     * @param {string} ajaxOptions
     * @param {string} error
     * @param {object} opt
     * @param {object} params
     * @method reloadErrorCallback
     */
    reloadErrorCallback: function reloadErrorCallback(jqXHR, ajaxOptions, error, opt, params) {
      if (jqXHR.status) {
        this.closeReloadPopup();
        this.loadLogData(true);
      } else {
        this._super(jqXHR, ajaxOptions, error, opt, params);
      }
    },
 
    /**
     * Delegates the function call to {getLogsByRequest} with appropriate params
     * @method doPolling
     */
    doPolling: function doPolling() {
      var requestId = this.get('content.cluster.requestId');
      Iif (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 isAllComponentsInstalled() {
      var dfd = $.Deferred();
      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 isAllComponentsInstalledSuccessCallback(jsonData) {
      var clusterStatus = {
        status: 'INSTALL FAILED',
        isStartError: true,
        isCompleted: false
      };
      var usedHostWithHeartbeatLost = false;
      var hostsWithHeartbeatLost = [];
      var usedHosts = this.get('content.masterComponentHosts').filterProperty('isInstalled', false).mapProperty('hostName');
      this.get('content.slaveComponentHosts').forEach(function (component) {
        usedHosts = usedHosts.concat(component.hosts.filterProperty('isInstalled', false).mapProperty('hostName'));
      });
      usedHosts = usedHosts.uniq();
      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, false);
          componentArr.pushObject(componentName);
        }, this);
        hostComponentObj.componentNames = stringUtils.getFormattedStringFromArray(componentArr);
        hostsWithHeartbeatLost.pushObject(hostComponentObj);
        if (!usedHostWithHeartbeatLost && usedHosts.contains(host.Hosts.host_name)) {
          usedHostWithHeartbeatLost = true;
        }
      }, this);
      this.set('hostsWithHeartbeatLost', hostsWithHeartbeatLost);
      Eif (usedHostWithHeartbeatLost) {
        this.get('hosts').forEach(function (host) {
          Eif (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')) {
        if (App.get('supports.skipComponentStartAfterInstall')) {
          this.set('progress', '100');
          this.changeParseHostInfo(true);
        } else {
          this.launchStartServices();
        }
      }
    },
 
    /**
     * Error callback function for API checking host state and host_components state
     * @method isAllComponentsInstalledErrorCallback
     */
    isAllComponentsInstalledErrorCallback: function isAllComponentsInstalledErrorCallback() {
      var clusterStatus = {
        status: 'INSTALL FAILED',
        isStartError: true,
        isCompleted: false
      };
      this.set('progress', '100');
      this.get('hosts').forEach(function (host) {
        Eif (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 saveClusterStatus(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 saveInstalledHosts(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 loadDoServiceChecksFlag() {
      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 loadDoServiceChecksFlagSuccessCallback(data) {
      var properties = Em.get(data, 'RootServiceComponents.properties');
      Eif (properties && properties.hasOwnProperty('skip.service.checks')) {
        this.set('skipServiceChecks', properties['skip.service.checks'] === 'true');
      }
    }
 
  });
});