Code coverage report for app/controllers/main/service/reassign/step6_controller.js

Statements: 82.35% (56 / 68)      Branches: 75% (24 / 32)      Functions: 68.75% (11 / 16)      Lines: 81.82% (54 / 66)      Ignored: none     

All files » app/controllers/main/service/reassign/ » step6_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    1                                     1   1                         9 1   8     9 6 6     6     6     9       2 2 2       2 2 1 1                             2 2       2 2 2 2         2 2         63 63 1         2 2 1                 1       2 2 2 2 2                           2 1   1         2 2 2 2 1                                                                 1   1 1 1 1 1   1                            
"use strict";
 
;require.register("controllers/main/service/reassign/step6_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');
 
  App.ReassignMasterWizardStep6Controller = App.HighAvailabilityProgressPageController.extend(App.WizardEnableDone, {
 
    name: "reassignMasterWizardStep6Controller",
 
    commands: ['stopMysqlService', 'putHostComponentsInMaintenanceMode', 'stopHostComponentsInMaintenanceMode', 'deleteHostComponents', 'startDatanodes', 'startAllServices'],
 
    clusterDeployState: 'REASSIGN_MASTER_INSTALLING',
 
    multiTaskCounter: 0,
 
    hostComponents: [],
 
    loadStep: function loadStep() {
      if (this.get('content.reassign.component_name') === 'NAMENODE' && App.get('isHaEnabled')) {
        this.set('hostComponents', ['NAMENODE', 'ZKFC']);
      } else {
        this.set('hostComponents', [this.get('content.reassign.component_name')]);
      }
 
      if (App.Service.find().someProperty('serviceName', 'PXF') && this.get('content.reassign.component_name') === 'NAMENODE') {
        var pxfHosts = App.HostComponent.find().filterProperty('componentName', 'PXF').mapProperty('hostName');
        var dataNodeHosts = App.HostComponent.find().filterProperty('componentName', 'DATANODE').mapProperty('hostName');
 
        // If NAMENODE is being moved and source host does not have DATANODE, PXF should be removed from source host
        if (pxfHosts.contains(this.get('content.reassignHosts.source')) && !dataNodeHosts.contains(this.get('content.reassignHosts.source'))) this.get('hostComponents').push('PXF');
 
        // If NAMENODE is being moved and target host does not have PXF, PXF should be added to target host
        if (!pxfHosts.contains(this.get('content.reassignHosts.target'))) this.get('commands').splice(this.get('commands').indexOf('startAllServices'), 0, 'installPxf');
      }
 
      this._super();
    },
 
    initializeTasks: function initializeTasks() {
      var commands = this.get('commands');
      var hostComponentsNames = '';
      this.get('hostComponents').forEach(function (comp, index) {
        hostComponentsNames += index ? '+' : '';
        hostComponentsNames += comp === 'ZKFC' ? comp : App.format.role(comp, false);
      }, this);
      var currentStep = App.router.get('reassignMasterController.currentStep');
      for (var i = 0; i < commands.length; i++) {
        var title = Em.I18n.t('services.reassign.step6.tasks.' + commands[i] + '.title').format(hostComponentsNames);
        this.get('tasks').pushObject(Ember.Object.create({
          title: title,
          status: 'PENDING',
          id: i,
          command: commands[i],
          showRetry: false,
          showRollback: false,
          name: title,
          displayName: title,
          progress: 0,
          isRunning: false,
          hosts: []
        }));
      }
 
      this.removeUnneededTasks();
      this.set('isLoaded', true);
    },
 
    removeUnneededTasks: function removeUnneededTasks() {
      Eif (this.get('content.reassign.component_name') !== 'MYSQL_SERVER') {
        this.removeTasks(['putHostComponentsInMaintenanceMode', 'stopMysqlService']);
        Eif (!this.get('content.reassignComponentsInMM.length')) {
          this.removeTasks(['stopHostComponentsInMaintenanceMode']);
        }
      } else {
        this.removeTasks(['stopHostComponentsInMaintenanceMode']);
      }
      Eif (!(this.get('content.reassign.component_name') === 'NAMENODE' && App.get('isHaEnabled'))) {
        this.removeTasks(['startDatanodes']);
      }
    },
 
    hideRollbackButton: function () {
      var failedTask = this.get('tasks').findProperty('showRollback');
      if (failedTask) {
        failedTask.set('showRollback', false);
      }
    }.observes('tasks.@each.showRollback'),
 
    onComponentsTasksSuccess: function onComponentsTasksSuccess() {
      this.decrementProperty('multiTaskCounter');
      if (this.get('multiTaskCounter') <= 0) {
        this.onTaskCompleted();
      }
    },
 
    installPxf: function installPxf() {
      this.createInstallComponentTask('PXF', this.get('content.reassignHosts.target'), "PXF");
    },
 
    startAllServices: function startAllServices() {
      this.startServices(true);
    },
 
    deleteHostComponents: function deleteHostComponents() {
      var hostComponents = this.get('hostComponents');
      var hostName = this.get('content.reassignHosts.source');
      this.set('multiTaskCounter', hostComponents.length);
      for (var i = 0; i < hostComponents.length; i++) {
        App.ajax.send({
          name: 'common.delete.host_component',
          sender: this,
          data: {
            hostName: hostName,
            componentName: hostComponents[i]
          },
          success: 'onComponentsTasksSuccess',
          error: 'onDeleteHostComponentsError'
        });
      }
    },
 
    onDeleteHostComponentsError: function onDeleteHostComponentsError(error) {
      if (error.responseText.indexOf('org.apache.ambari.server.controller.spi.NoSuchResourceException') !== -1) {
        this.onComponentsTasksSuccess();
      } else {
        this.onTaskError();
      }
    },
 
    putHostComponentsInMaintenanceMode: function putHostComponentsInMaintenanceMode() {
      var hostComponents = this.get('hostComponents');
      var hostName = this.get('content.reassignHosts.source');
      this.set('multiTaskCounter', hostComponents.length);
      for (var i = 0; i < hostComponents.length; i++) {
        App.ajax.send({
          name: 'common.host.host_component.passive',
          sender: this,
          data: {
            hostName: hostName,
            passive_state: "ON",
            componentName: hostComponents[i]
          },
          success: 'onComponentsTasksSuccess',
          error: 'onTaskError'
        });
      }
    },
 
    stopHostComponentsInMaintenanceMode: function stopHostComponentsInMaintenanceMode() {
      var hostComponentsInMM = this.get('content.reassignComponentsInMM');
      var hostName = this.get('content.reassignHosts.source');
      var serviceName = this.get('content.reassign.service_id');
      hostComponentsInMM = hostComponentsInMM.map(function (componentName) {
        return {
          hostName: hostName,
          serviceName: serviceName,
          componentName: componentName
        };
      });
      this.set('multiTaskCounter', hostComponentsInMM.length);
      this.updateComponentsState(hostComponentsInMM, 'INSTALLED');
    },
 
    /**
     * make server call to stop services
     */
    stopMysqlService: function stopMysqlService() {
      var data = {};
 
      data.context = "Stop required services";
      data.hostName = this.get('content.reassignHosts.source');
      data.serviceName = 'HIVE';
      data.HostRoles = { "state": "INSTALLED" };
      data.componentName = "MYSQL_SERVER";
 
      App.ajax.send({
        name: 'common.host.host_component.update',
        sender: this,
        data: data,
        success: 'startPolling',
        error: 'onTaskError'
      });
    },
 
    startDatanodes: function startDatanodes() {
      this.updateComponent('DATANODE', null, 'HDFS', 'Start');
    }
 
  });
});