Code coverage report for app/utils/configs/nn_ha_config_initializer.js

Statements: 92.5% (74 / 80)      Branches: 65.38% (17 / 26)      Functions: 93.75% (15 / 16)      Lines: 92.5% (74 / 80)      Ignored: none     

All files » app/utils/configs/ » nn_ha_config_initializer.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    1                                     1 1 1                             1 8                             1 3 3 3                                 1 1                     1       1                                                                                           10 10 10 10 10 10 10 10       10                                                                               2 2 2 2 2 2       2                             4 4 4 2   2 2                                 2 2 2         2                             2 2 2 2 2 2   2         2                             2 2 2         2                             2 2 2 2         2                             2 2 2 2 2         2                               2 2 2         2                             2 2     2 2 2 2         2        
'use strict';
 
;require.register("utils/configs/nn_ha_config_initializer", 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');
  require('utils/configs/ha_config_initializer_class');
  require('utils/configs/hosts_based_initializer_mixin');
 
  /**
   * @typedef {topologyLocalDB} extendedTopologyLocalDB
   * @property {string[]} installedServices list of installed service names
   */
 
  /**
   * Setting for <code>rename</code>-initializer
   * Used for configs which should be renamed
   * Replace some part if their names with <code>namespaceId</code> (provided by user on the wizard's 1st step)
   *
   * @param {string} toReplace
   * @returns {{type: string, toReplace: string}}
   */
  function getRenameWithNamespaceConfig(toReplace) {
    return {
      type: 'rename',
      toReplace: toReplace
    };
  }
 
  /**
   * Settings for <code>namespace</code>-initializer
   * Used for configs with value equal to the <code>namespaceId</code> (provided by user on the wizard's 1st step)
   * Value may be customized with prefix and suffix
   *
   * @param {string} [prefix=''] substring added before namespace in the replace
   * @param {string} [suffix=''] substring added after namespace in the replace
   * @returns {{type: string, modifier: {prefix: (string), suffix: (string)}}}
   */
  function getNamespaceConfig(prefix, suffix) {
    prefix = prefix || '';
    suffix = suffix || '';
    return {
      type: 'namespace',
      modifier: {
        prefix: prefix,
        suffix: suffix
      }
    };
  }
 
  /**
   * Settings for <code>replace_namespace</code>
   * Used for configs with values that have to be modified with replacing some part of them
   * to the <code>namespaceId</code> (provided by user on the wizard's 1st step)
   *
   * @param {string} toReplace
   * @returns {{type: string, toReplace: *}}
   */
  function getReplaceNamespaceConfig(toReplace) {
    return {
      type: 'replace_namespace',
      toReplace: toReplace
    };
  }
 
  /**
   * Initializer for configs that are updated when NameNode HA-mode is activated
   *
   * @class {NnHaConfigInitializer}
   */
  App.NnHaConfigInitializer = App.HaConfigInitializerClass.create(App.HostsBasedInitializerMixin, {
 
    initializers: function () {
 
      return {
        'dfs.ha.namenodes.${dfs.nameservices}': getRenameWithNamespaceConfig('${dfs.nameservices}'),
        'dfs.namenode.rpc-address.${dfs.nameservices}.nn1': [this.getHostWithPortConfig('NAMENODE', true, '', '', 'nnRpcPort', true), getRenameWithNamespaceConfig('${dfs.nameservices}')],
        'dfs.namenode.rpc-address.${dfs.nameservices}.nn2': [this.getHostWithPortConfig('NAMENODE', false, '', '', '8020', false), getRenameWithNamespaceConfig('${dfs.nameservices}')],
        'dfs.namenode.http-address.${dfs.nameservices}.nn1': [this.getHostWithPortConfig('NAMENODE', true, '', '', 'nnHttpPort', true), getRenameWithNamespaceConfig('${dfs.nameservices}')],
        'dfs.namenode.http-address.${dfs.nameservices}.nn2': [this.getHostWithPortConfig('NAMENODE', false, '', '', '50070', false), getRenameWithNamespaceConfig('${dfs.nameservices}')],
        'dfs.namenode.https-address.${dfs.nameservices}.nn1': [this.getHostWithPortConfig('NAMENODE', true, '', '', 'nnHttpsPort', true), getRenameWithNamespaceConfig('${dfs.nameservices}')],
        'dfs.namenode.https-address.${dfs.nameservices}.nn2': [this.getHostWithPortConfig('NAMENODE', false, '', '', '50470', false), getRenameWithNamespaceConfig('${dfs.nameservices}')],
        'dfs.client.failover.proxy.provider.${dfs.nameservices}': getRenameWithNamespaceConfig('${dfs.nameservices}'),
        'dfs.nameservices': getNamespaceConfig(),
        'dfs.internal.nameservices': getNamespaceConfig(),
        'fs.defaultFS': getNamespaceConfig('hdfs://'),
        'dfs.namenode.shared.edits.dir': [this.getHostsWithPortConfig('JOURNALNODE', 'qjournal://', '/${dfs.nameservices}', ';', '8485', false), getReplaceNamespaceConfig('${dfs.nameservices}')],
        'ha.zookeeper.quorum': this.getHostsWithPortConfig('ZOOKEEPER_SERVER', '', '', ',', 'zkClientPort', true)
      };
    }.property(),
 
    uniqueInitializers: {
      'hbase.rootdir': '_initHbaseRootDir',
      'hawq_dfs_url': '_initHawqDfsUrl',
      'instance.volumes': '_initInstanceVolumes',
      'instance.volumes.replacements': '_initInstanceVolumesReplacements',
      'dfs.journalnode.edits.dir': '_initDfsJnEditsDir',
      'xasecure.audit.destination.hdfs.dir': '_initXasecureAuditDestinationHdfsDir'
    },
 
    initializerTypes: [{ name: 'rename', method: '_initWithRename' }, { name: 'namespace', method: '_initAsNamespace' }, { name: 'replace_namespace', method: '_initWithNamespace' }],
 
    /**
     * Initializer for configs that should be renamed
     * Some part of their names should be replaced with <code>namespaceId</code> (user input this value on the wizard's 1st step)
     * Affects both - name and displayName
     * <b>Important! It's not the same as <code>_updateInitializers</code>!</b>
     * Main diff - this initializer used for configs
     * with names that come with some "predicates" in their names. <code>_updateInitializers</code> is used to determine needed
     * config name that depends on other config values or someting else
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @returns {object}
     * @private
     * @method _initWithRename
     */
    _initWithRename: function _initWithRename(configProperty, localDB, dependencies, initializer) {
      var replaceWith = dependencies.namespaceId;
      var toReplace = initializer.toReplace;
      Em.assert('`dependencies.namespaceId` should be not empty string', !!replaceWith);
      var name = Em.getWithDefault(configProperty, 'name', '');
      var displayName = Em.getWithDefault(configProperty, 'displayName', '');
      name = name.replace(toReplace, replaceWith);
      displayName = displayName.replace(toReplace, replaceWith);
      Em.setProperties(configProperty, {
        name: name,
        displayName: displayName
      });
      return configProperty;
    },
 
    /**
     * Initializer for configs wih value equal to the <code>namespaceId</code> (user input this value on the wizard's 1st step)
     * Value may be customized with prefix and suffix (see <code>initializer.modifier</code>)
     * Value-examples: 'SOME_COOL_PREFIXmy_namespaceSOME_COOL_SUFFIX', 'my_namespace'
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @returns {object}
     * @private
     * @method _initAsNamespace
     */
    _initAsNamespace: function _initAsNamespace(configProperty, localDB, dependencies, initializer) {
      var value = dependencies.namespaceId;
      Em.assert('`dependencies.namespaceId` should be not empty string', !!value);
      value = initializer.modifier.prefix + value + initializer.modifier.suffix;
      Em.setProperties(configProperty, {
        value: value,
        recommendedValue: value
      });
      return configProperty;
    },
 
    /**
     * Initializer for configs with value that should be modified with replacing some substring
     * to the <code>namespaceId</code> (user input this value on the wizard's 1st step)
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @returns {object}
     * @private
     * @method _initWithNamespace
     */
    _initWithNamespace: function _initWithNamespace(configProperty, localDB, dependencies, initializer) {
      var replaceWith = dependencies.namespaceId;
      var toReplace = initializer.toReplace;
      Em.assert('`dependencies.namespaceId` should be not empty string', !!replaceWith);
      var value = Em.get(configProperty, 'value').replace(toReplace, replaceWith);
      var recommendedValue = Em.get(configProperty, 'recommendedValue').replace(toReplace, replaceWith);
      Em.setProperties(configProperty, {
        value: value,
        recommendedValue: recommendedValue
      });
      return configProperty;
    },
 
    /**
     * Unique initializer for <code>hbase.rootdir</code>
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @method _initHbaseRootDir
     * @return {object}
     * @private
     */
    _initHbaseRootDir: function _initHbaseRootDir(configProperty, localDB, dependencies, initializer) {
      var fileName = Em.get(configProperty, 'filename');
      var args = [].slice.call(arguments);
      if ('hbase-site' === fileName) {
        return this._initHbaseRootDirForHbase.apply(this, args);
      }
      Eif ('ams-hbase-site' === fileName) {
        return this._initHbaseRootDirForAMS.apply(this, args);
      }
      return configProperty;
    },
 
    /**
     * Unique initializer for <code>hbase.rootdir</code> (HBASE-service)
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @method _initHbaseRootDirForHbase
     * @return {object}
     * @private
     */
    _initHbaseRootDirForHbase: function _initHbaseRootDirForHbase(configProperty, localDB, dependencies, initializer) {
      Eif (localDB.installedServices.contains('HBASE')) {
        var value = dependencies.serverConfigs.findProperty('type', 'hbase-site').properties['hbase.rootdir'].replace(/\/\/[^\/]*/, '//' + dependencies.namespaceId);
        Em.setProperties(configProperty, {
          value: value,
          recommendedValue: value
        });
      }
      return configProperty;
    },
 
    /**
     * Unique initializer for <code>hbase.rootdir</code> (Ambari Metrics-service)
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @method _initHbaseRootDirForAMS
     * @return {object}
     * @private
     */
    _initHbaseRootDirForAMS: function _initHbaseRootDirForAMS(configProperty, localDB, dependencies, initializer) {
      Eif (localDB.installedServices.contains('AMBARI_METRICS')) {
        var value = dependencies.serverConfigs.findProperty('type', 'ams-hbase-site').properties['hbase.rootdir'];
        var currentNameNodeHost = localDB.masterComponentHosts.filterProperty('component', 'NAMENODE').findProperty('isInstalled', true).hostName;
        Eif (value.contains("hdfs://" + currentNameNodeHost)) {
          value = value.replace(/\/\/[^\/]*/, '//' + dependencies.namespaceId);
          configProperty.isVisible = true;
        }
        Em.setProperties(configProperty, {
          value: value,
          recommendedValue: value
        });
      }
      return configProperty;
    },
 
    /**
     * Unique initializer for <code>hawq_dfs_url</code> (Hawq service)
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @method _initHawqDfsUrl
     * @return {object}
     * @private
     */
    _initHawqDfsUrl: function _initHawqDfsUrl(configProperty, localDB, dependencies, initializer) {
      Eif (localDB.installedServices.contains('HAWQ')) {
        var value = dependencies.serverConfigs.findProperty('type', 'hawq-site').properties['hawq_dfs_url'].replace(/(^.*:[0-9]+)(?=\/)/, dependencies.namespaceId);
        Em.setProperties(configProperty, {
          value: value,
          recommendedValue: value
        });
      }
      return configProperty;
    },
 
    /**
     * Unique initializer for <code>instance.volumes</code>
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @method _initInstanceVolumes
     * @return {object}
     * @private
     */
    _initInstanceVolumes: function _initInstanceVolumes(configProperty, localDB, dependencies, initializer) {
      Eif (localDB.installedServices.contains('ACCUMULO')) {
        var oldValue = dependencies.serverConfigs.findProperty('type', 'accumulo-site').properties['instance.volumes'];
        var value = oldValue.replace(/\/\/[^\/]*/, '//' + dependencies.namespaceId);
        Em.setProperties(configProperty, {
          value: value,
          recommendedValue: value
        });
      }
      return configProperty;
    },
 
    /**
     * Unique initializer for <code>instance.volumes.replacements</code>
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @method _initInstanceVolumesReplacements
     * @return {object}
     * @private
     */
    _initInstanceVolumesReplacements: function _initInstanceVolumesReplacements(configProperty, localDB, dependencies, initializer) {
      Eif (localDB.installedServices.contains('ACCUMULO')) {
        var oldValue = dependencies.serverConfigs.findProperty('type', 'accumulo-site').properties['instance.volumes'];
        var value = oldValue.replace(/\/\/[^\/]*/, '//' + dependencies.namespaceId);
        var replacements = oldValue + " " + value;
        Em.setProperties(configProperty, {
          value: replacements,
          recommendedValue: replacements
        });
      }
      return configProperty;
    },
 
    /**
     * Unique initializer for <code>dfs.journalnode.edits.dir</code>
     * Used only for Windows Stacks
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @method _initDfsJnEditsDir
     * @return {object}
     * @private
     */
    _initDfsJnEditsDir: function _initDfsJnEditsDir(configProperty, localDB, dependencies, initializer) {
      Eif (App.get('isHadoopWindowsStack') && localDB.installedServices.contains('HDFS')) {
        var value = dependencies.serverConfigs.findProperty('type', 'hdfs-site').properties['dfs.journalnode.edits.dir'];
        Em.setProperties(configProperty, {
          value: value,
          recommendedValue: value
        });
      }
      return configProperty;
    },
 
    /**
     * Unique initializer for <code>xasecure.audit.destination.hdfs.dir</code>
     *
     * @param {configProperty} configProperty
     * @param {extendedTopologyLocalDB} localDB
     * @param {nnHaConfigDependencies} dependencies
     * @param {object} initializer
     * @method _initXasecureAuditDestinationHdfsDir
     * @return {object}
     * @private
     */
    _initXasecureAuditDestinationHdfsDir: function _initXasecureAuditDestinationHdfsDir(configProperty, localDB, dependencies, initializer) {
      Eif (localDB.installedServices.contains('RANGER')) {
        var oldValue = dependencies.serverConfigs.findProperty('type', 'ranger-env').properties['xasecure.audit.destination.hdfs.dir'];
        // Example of value - hdfs://c6401.ambari.apache.org:8020/ranger/audit
        // Replace hostname and port with Namespace
        var valueArray = oldValue.split("/");
        valueArray[2] = dependencies.namespaceId;
        var newValue = valueArray.join("/");
        Em.setProperties(configProperty, {
          value: newValue,
          recommendedValue: newValue
        });
      }
      return configProperty;
    }
 
  });
});