Code coverage report for app/utils/config.js

Statements: 75.64% (326 / 431)      Branches: 61.84% (222 / 359)      Functions: 84.11% (90 / 107)      Lines: 75.89% (318 / 419)      Ignored: none     

All files » app/utils/ » config.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 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358    1                                     1 1 1 1   1 1   1                                                                 66 33             8 3 3   8                 6 6                             398 339   59 59 59                   263       2   2 4 4     2 2 2 2 2 2 4 8 2       2 2       2           2 2 121   2           1   1 19   1                                                           17 17 9011                 1   1 2   1       1 1 1 3     1                                                                                                                                   3 3 3 1   3                           36 36 36                                                                           36                       4 4 4 4                                               4   4                       5 5 146 146 124       5                             127 127 127 127 52   75 75 1   74                     37                   37                 37                     3 3 3     3                         4 4 4 4 4 8       4                   1 1   3 2 2     2         1                   4 3 3                       699                   4                               1   1           11   682                     699                                                                 16 16     4 6 4 2     4                         679 510     510                       699                                       699 901                       2                     17   17 1   16     16   2 1   1 1     1 1   1 1                   12                     14                     1 1                   1 2 2 1                               13 13                               1 1 2   1 1                                   1 1       1 1         1 1 2 2 2 1   2 1         1 1 1               11         11 33   11   11 22 22 22   22 22       11 11 11   11                           11 33   11 11                 1 1 2 1 1 2         1                     3 3 3 1   1 2 2 2 2 2 2   2                           1   2                       56 56 56 56 56     10 10   19 19   3   24 6   24   56                                                       4 8     8                   2                                 2 2 2                                 1                   37 37 35   2 2     2 2           43 43 38   5 5 3   2 2 2                   1 1 1 2 1     1 1 1 3 1     1                         10 9   8   8               8 8   8   8                   28 27   26   26   26   26 24 60       26             26 4   26   26   26 185   26 26   26                   1               1                       16 9 9 10   1 1               31   31                                                     66       66   66 13 13   53 7 7 7   53 53     66 57 84   57 31     66 66                                                                                          
'use strict';
 
;require.register("utils/config", 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_collection');
  var stringUtils = require('utils/string_utils');
  var validator = require('utils/validator');
 
  var configTagFromFileNameMap = {};
  var PASSWORD = "PASSWORD";
 
  App.config = Em.Object.create({
 
    CONFIG_GROUP_NAME_MAX_LENGTH: 18,
 
    /**
     * filename exceptions used to support substandard sitenames which don't have "xml" extension
     * @type {string[]}
     */
    filenameExceptions: ['alert_notification'],
 
    preDefinedServiceConfigs: [],
 
    /**
     * Map for methods used to parse hosts lists from certain config properties
     */
    uniqueHostsListParsers: [{
      propertyName: 'templeton.hive.properties',
      type: 'webhcat-site',
      method: 'getTempletonHiveHosts'
    }],
 
    /**
     *
     * Returns file name version that stored on server.
     *
     * Example:
     *   App.config.getOriginalFileName('core-site') // returns core-site.xml
     *   App.config.getOriginalFileName('zoo.cfg') // returns zoo.cfg
     *
     * @param {String} fileName
     * @method getOriginalFileName
     **/
    getOriginalFileName: function getOriginalFileName(fileName) {
      if (/\.xml$/.test(fileName)) return fileName;
      return this.get('filenameExceptions').contains(fileName) ? fileName : fileName + '.xml';
    },
 
    /**
     * truncate Config Group name to <CONFIG_GROUP_NAME_MAX_LENGTH> length and paste "..." in the middle
     */
    truncateGroupName: function truncateGroupName(name) {
      if (name && name.length > App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
        var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
        name = name.substring(0, middle) + "..." + name.substring(name.length - middle);
      }
      return name;
    },
 
    /**
     * Check if Hive installation with new MySQL database created via Ambari is allowed
     * @param osFamily
     * @returns {boolean}
     */
    isManagedMySQLForHiveAllowed: function isManagedMySQLForHiveAllowed(osFamily) {
      var osList = ['redhat5', 'suse11'];
      return !osList.contains(osFamily);
    },
 
    /**
     *
     * Returns the configuration tagName from supplied filename
     *
     * Example:
     *   App.config.getConfigTagFromFileName('core-site.xml') // returns core-site
     *   App.config.getConfigTagFromFileName('zoo.cfg') // returns zoo.cfg
     *
     * @param {String} fileName
     * @method getConfigTagFromFileName
     **/
    getConfigTagFromFileName: function getConfigTagFromFileName(fileName) {
      if (configTagFromFileNameMap[fileName]) {
        return configTagFromFileNameMap[fileName];
      }
      var ret = fileName.endsWith('.xml') ? fileName.slice(0, -4) : fileName;
      configTagFromFileNameMap[fileName] = ret;
      return ret;
    },
 
    /**
     *
     * @param name
     * @param fileName
     * @returns {string}
     */
    configId: function configId(name, fileName) {
      return name + "__" + App.config.getConfigTagFromFileName(fileName);
    },
 
    setPreDefinedServiceConfigs: function setPreDefinedServiceConfigs(isMiscTabToBeAdded) {
      var stackServices = App.StackService.find().filterProperty('id');
      // Only include services that has configTypes related to them for service configuration page
      var servicesWithConfigTypes = stackServices.filter(function (service) {
        var configtypes = service.get('configTypes');
        return configtypes && !!Object.keys(configtypes).length;
      }, this);
 
      var allTabs;
      Eif (isMiscTabToBeAdded) {
        var nonServiceTab = require('data/service_configs');
        var miscService = nonServiceTab.findProperty('serviceName', 'MISC');
        var tagTypes = {};
        servicesWithConfigTypes.mapProperty('configTypes').forEach(function (configTypes) {
          for (var fileName in configTypes) {
            if (fileName.endsWith('-env') && !miscService.get('configTypes')[fileName]) {
              tagTypes[fileName] = configTypes[fileName];
            }
          }
        });
        miscService.set('configTypes', $.extend(miscService.get('configTypes'), tagTypes));
        allTabs = servicesWithConfigTypes.concat(nonServiceTab);
      } else {
        allTabs = servicesWithConfigTypes;
      }
      this.set('preDefinedServiceConfigs', allTabs);
    },
 
    secureConfigs: require('data/configs/wizards/secure_mapping'),
 
    secureConfigsMap: function () {
      var ret = {};
      this.get('secureConfigs').forEach(function (sc) {
        ret[sc.name] = true;
      });
      return ret;
    }.property('secureConfigs.[]'),
 
    kerberosIdentities: require('data/configs/wizards/kerberos_identities').configProperties,
 
    kerberosIdentitiesMap: function () {
      var map = {};
 
      this.get('kerberosIdentities').forEach(function (c) {
        map[this.configId(c.name, c.filename)] = c;
      }, this);
      return map;
    }.property('kerberosIdentities'),
 
    customStackMapping: require('data/custom_stack_map'),
 
    mapCustomStack: function mapCustomStack() {
      var baseStackFolder = App.get('currentStackName'),
          singMap = {
        "1": [">", ">="],
        "-1": ["<", "<="],
        "0": ["=", ">=", "<="]
      };
 
      this.get('customStackMapping').every(function (stack) {
        if (stack.stackName == App.get('currentStackName')) {
          var versionCompare = Em.compare(App.get('currentStackVersionNumber'), stack.stackVersionNumber);
          if (singMap[versionCompare + ""].contains(stack.sign)) {
            baseStackFolder = stack.baseStackFolder;
            return false;
          }
        }
        return true;
      });
 
      return baseStackFolder;
    },
 
    allPreDefinedSiteProperties: require('data/configs/site_properties').configProperties,
 
    preDefinedSiteProperties: function () {
      var serviceNames = App.StackService.find().mapProperty('serviceName').concat('MISC');
      return this.get('allPreDefinedSiteProperties').filter(function (p) {
        return serviceNames.contains(p.serviceName);
      });
    }.property().volatile(),
 
    /**
     * map of <code>preDefinedSiteProperties</code> provide search by index
     * @type {object}
     */
    preDefinedSitePropertiesMap: function () {
      var map = {};
 
      this.get('preDefinedSiteProperties').forEach(function (c) {
        map[this.configId(c.name, c.filename)] = c;
      }, this);
      return map;
    }.property('preDefinedSiteProperties'),
 
    serviceByConfigTypeMap: function () {
      var ret = {};
      App.StackService.find().forEach(function (s) {
        s.get('configTypeList').forEach(function (ct) {
          ret[ct] = s;
        });
      });
      return ret;
    }.property(),
 
    /**
     * Generate configs collection with Ember or plain config objects
     * from config JSON
     *
     * @param configJSON
     * @param useEmberObject
     * @returns {Array}
     */
    getConfigsFromJSON: function getConfigsFromJSON(configJSON, useEmberObject) {
      var configs = [],
          filename = App.config.getOriginalFileName(configJSON.type),
          properties = configJSON.properties,
          attributes = [];
      ['FINAL', 'PASSWORD', 'USER', 'GROUP', 'TEXT', 'ADDITIONAL_USER_PROPERTY', 'NOT_MANAGED_HDFS_PATH', 'VALUE_FROM_PROPERTY_FILE'].forEach(function (attribute) {
        var json = {};
        json[attribute] = Em.get(configJSON, 'properties_attributes.' + attribute.toLowerCase()) || {};
        attributes.push(json);
      });
 
      for (var index in properties) {
        var serviceConfigObj = this.getDefaultConfig(index, filename);
 
        if (serviceConfigObj.isRequiredByAgent !== false) {
          serviceConfigObj.value = serviceConfigObj.savedValue = this.formatPropertyValue(serviceConfigObj, properties[index]);
          serviceConfigObj.isFinal = serviceConfigObj.savedIsFinal = attributes[0]['FINAL'][index] === "true";
 
          var propertyType = [];
          // iterate through all the attributes, except for FINAL
          for (var i = 1; i < attributes.length; i++) {
            for (var type in attributes[i]) {
              if (attributes[i][type][index] === "true") {
                propertyType.push(type);
 
                if (type === PASSWORD) {
                  serviceConfigObj.displayType = "password";
                }
              }
            }
          }
          serviceConfigObj.propertyType = propertyType;
          serviceConfigObj.isEditable = serviceConfigObj.isReconfigurable;
        }
 
        if (useEmberObject) {
          configs.push(App.ServiceConfigProperty.create(serviceConfigObj));
        } else {
          configs.push(serviceConfigObj);
        }
      }
      return configs;
    },
 
    /**
     * Get config from configsCollections or
     * generate new default config in collection does not contain
     * such config
     *
     * @param name
     * @param fileName
     * @param coreObject
     * @returns {*|Object}
     */
    getDefaultConfig: function getDefaultConfig(name, fileName, coreObject) {
      name = JSON.parse('"' + name + '"');
      var cfg = App.configsCollection.getConfigByName(name, fileName) || App.config.createDefaultConfig(name, fileName, false);
      if (Em.typeOf(coreObject) === 'object') {
        Em.setProperties(cfg, coreObject);
      }
      return cfg;
    },
 
    /**
     * This method sets default values for config property
     * These property values has the lowest priority and can be overridden be stack/UI
     * config property but is used when such properties are absent in stack/UI configs
     * @param {string} name
     * @param {string} fileName
     * @param {boolean} definedInStack
     * @param {Object} [coreObject]
     * @returns {Object}
     */
    createDefaultConfig: function createDefaultConfig(name, fileName, definedInStack, coreObject) {
      var service = this.get('serviceByConfigTypeMap')[App.config.getConfigTagFromFileName(fileName)];
      var serviceName = service ? service.get('serviceName') : 'MISC';
      var tpl = {
        /** core properties **/
        id: this.configId(name, fileName),
        name: name,
        filename: this.getOriginalFileName(fileName),
        value: '',
        savedValue: null,
        isFinal: false,
        savedIsFinal: null,
        /** UI and Stack properties **/
        recommendedValue: null,
        recommendedIsFinal: null,
        supportsFinal: this.shouldSupportFinal(serviceName, fileName),
        supportsAddingForbidden: this.shouldSupportAddingForbidden(serviceName, fileName),
        serviceName: serviceName,
        displayName: name,
        displayType: coreObject && coreObject.propertyType && coreObject.propertyType.contains(PASSWORD) ? 'password' : this.getDefaultDisplayType(coreObject ? coreObject.value : ''),
        description: '',
        category: this.getDefaultCategory(definedInStack, fileName),
        isSecureConfig: this.getIsSecure(name),
        showLabel: true,
        isVisible: true,
        isUserProperty: !definedInStack,
        isRequired: definedInStack,
        group: null,
        isRequiredByAgent: true,
        isReconfigurable: true,
        unit: null,
        hasInitialValue: false,
        isOverridable: true,
        index: Infinity,
        dependentConfigPattern: null,
        options: null,
        radioName: null,
        widgetType: null,
        errorMessage: '',
        warnMessage: ''
      };
      return Object.keys(coreObject || {}).length ? $.extend(tpl, coreObject) : tpl;
    },
 
    /**
     * This method creates host name properties
     * @param serviceName
     * @param componentName
     * @param value
     * @param stackComponent
     * @returns Object
     */
    createHostNameProperty: function createHostNameProperty(serviceName, componentName, value, stackComponent) {
      var hostOrHosts = stackComponent.get('isMultipleAllowed') ? 'hosts' : 'host';
      var name = componentName.toLowerCase() + '_' + hostOrHosts;
      var filename = serviceName.toLowerCase() + "-site.xml";
      return {
        "id": App.config.configId(name, filename),
        "name": name,
        "displayName": stackComponent.get('displayName') + ' ' + (value.length > 1 ? 'hosts' : 'host'),
        "value": value,
        "recommendedValue": value,
        "description": "The " + hostOrHosts + " that has been assigned to run " + stackComponent.get('displayName'),
        "displayType": "component" + hostOrHosts.capitalize(),
        "isOverridable": false,
        "isRequiredByAgent": false,
        "serviceName": serviceName,
        "filename": filename,
        "category": componentName,
        "index": 0
      };
    },
 
    /**
     * Get component name from config name string
     *
     * @param configName
     * @returns {string}
     */
    getComponentName: function getComponentName(configName) {
      var match = configName.match(/^(.*)_host[s]?$/) || [],
          component = match[1];
      return component ? component.toUpperCase() : "";
    },
 
    /**
     * This method merge properties form <code>stackConfigProperty<code> which are taken from stack
     * with <code>UIConfigProperty<code> which are hardcoded on UI
     * @param coreObject
     * @param stackProperty
     * @param preDefined
     * @param [propertiesToSkip]
     */
    mergeStaticProperties: function mergeStaticProperties(coreObject, stackProperty, preDefined, propertiesToSkip) {
      propertiesToSkip = propertiesToSkip || ['name', 'filename', 'value', 'savedValue', 'isFinal', 'savedIsFinal'];
      for (var k in coreObject) {
        Eif (coreObject.hasOwnProperty(k)) {
          if (!propertiesToSkip.contains(k)) {
            coreObject[k] = this.getPropertyIfExists(k, coreObject[k], stackProperty, preDefined);
          }
        }
      }
      return coreObject;
    },
 
    /**
     * This method using for merging some properties from two objects
     * if property exists in <code>firstPriority<code> result will be it's property
     * else if property exists in <code>secondPriority<code> result will be it's property
     * otherwise <code>defaultValue<code> will be returned
     * @param {String} propertyName
     * @param {*} defaultValue=null
     * @param {Em.Object|Object} firstPriority
     * @param {Em.Object|Object} [secondPriority=null]
     * @returns {*}
     */
    getPropertyIfExists: function getPropertyIfExists(propertyName, defaultValue, firstPriority, secondPriority) {
      firstPriority = firstPriority || {};
      secondPriority = secondPriority || {};
      var fp = Em.get(firstPriority, propertyName);
      if (firstPriority && !Em.isNone(fp)) {
        return fp;
      } else {
        var sp = Em.get(secondPriority, propertyName);
        if (secondPriority && !Em.isNone(sp)) {
          return sp;
        } else {
          return defaultValue;
        }
      }
    },
 
    /**
     * Get displayType for properties that has not defined value
     * @param value
     * @returns {string}
     */
    getDefaultDisplayType: function getDefaultDisplayType(value) {
      return value && !stringUtils.isSingleLine(value) ? 'multiLine' : 'string';
    },
 
    /**
     * Get category for properties that has not defined value
     * @param stackConfigProperty
     * @param fileName
     * @returns {string}
     */
    getDefaultCategory: function getDefaultCategory(stackConfigProperty, fileName) {
      return (stackConfigProperty ? 'Advanced ' : 'Custom ') + this.getConfigTagFromFileName(fileName);
    },
 
    /**
     * Get isSecureConfig for properties that has not defined value
     * @param propertyName
     * @returns {boolean}
     */
    getIsSecure: function getIsSecure(propertyName) {
      return !!this.get('secureConfigsMap')[propertyName];
    },
 
    /**
     * Returns description, formatted if needed
     *
     * @param {String} description
     * @param {String} displayType
     * @returns {String}
     */
    getDescription: function getDescription(description, displayType) {
      var additionalDescription = Em.I18n.t('services.service.config.password.additionalDescription');
      Eif ('password' === displayType) {
        Iif (description && !description.contains(additionalDescription)) {
          return description + '\n' + additionalDescription;
        } else {
          return additionalDescription;
        }
      }
      return description;
    },
 
    /**
     * parse Kerberos descriptor
     *
     * @param kerberosDescriptor
     * @returns {{}}
     */
    parseDescriptor: function parseDescriptor(kerberosDescriptor) {
      var identitiesMap = {};
      Em.get(kerberosDescriptor, 'KerberosDescriptor.kerberos_descriptor.services').forEach(function (service) {
        this.parseIdentities(service, identitiesMap);
        Eif (Array.isArray(service.components)) {
          service.components.forEach(function (component) {
            this.parseIdentities(component, identitiesMap);
          }, this);
        }
      }, this);
      return identitiesMap;
    },
 
    /**
     * Looking for configs identities and add them to <code>identitiesMap<code>
     *
     * @param item
     * @param identitiesMap
     */
    parseIdentities: function parseIdentities(item, identitiesMap) {
      Eif (item.identities) {
        item.identities.forEach(function (identity) {
 
          Em.keys(identity).without('name').forEach(function (item) {
            Eif (identity[item].configuration) {
              var cfg = identity[item].configuration.split('/'),
                  name = cfg[1],
                  fileName = cfg[0];
              identitiesMap[App.config.configId(name, fileName)] = true;
            }
          });
        });
      }
      return identitiesMap;
    },
 
    /**
     * Update description for disabled kerberos configs which are identities
     *
     * @param description
     * @returns {*}
     */
    kerberosIdentitiesDescription: function kerberosIdentitiesDescription(description) {
      if (!description) return Em.I18n.t('services.service.config.secure.additionalDescription');
      description = description.trim();
      return (description.endsWith('.') ? description + ' ' : description + '. ') + Em.I18n.t('services.service.config.secure.additionalDescription');
    },
 
    /**
     * Get view class based on display type of config
     *
     * @param displayType
     * @param dependentConfigPattern
     * @param unit
     * @returns {*}
     */
    getViewClass: function getViewClass(displayType, dependentConfigPattern, unit) {
      switch (displayType) {
        case 'user':
        case 'group':
          return App.ServiceConfigTextFieldUserGroupWithID;
        case 'checkbox':
        case 'boolean':
          return dependentConfigPattern ? App.ServiceConfigCheckboxWithDependencies : App.ServiceConfigCheckbox;
        case 'boolean-inverted':
          return App.ServiceConfigCheckbox;
        case 'password':
          return App.ServiceConfigPasswordField;
        case 'combobox':
          return App.ServiceConfigComboBox;
        case 'radio button':
          return App.ServiceConfigRadioButtons;
        case 'directories':
          return App.ServiceConfigTextArea;
        case 'directory':
          return App.ServiceConfigTextField;
        case 'content':
          return App.ServiceConfigTextAreaContent;
        case 'multiLine':
          return App.ServiceConfigTextArea;
        case 'custom':
          return App.ServiceConfigBigTextArea;
        case 'componentHost':
          return App.ServiceConfigMasterHostView;
        case 'label':
          return App.ServiceConfigLabelView;
        case 'componentHosts':
          return App.ServiceConfigComponentHostsView;
        case 'supportTextConnection':
          return App.checkConnectionView;
        case 'capacityScheduler':
          return App.CapacitySceduler;
        default:
          return unit ? App.ServiceConfigTextFieldWithUnit : App.ServiceConfigTextField;
      }
    },
 
    /**
     * Returns error validator function based on config type
     *
     * @param displayType
     * @returns {Function}
     */
    getErrorValidator: function getErrorValidator(displayType) {
      switch (displayType) {
        case 'checkbox':
        case 'custom':
          return function () {
            return '';
          };
        case 'int':
          return function (value) {
            return !validator.isValidInt(value) && !validator.isConfigValueLink(value) ? Em.I18n.t('errorMessage.config.number.integer') : '';
          };
        case 'float':
          return function (value) {
            return !validator.isValidFloat(value) && !validator.isConfigValueLink(value) ? Em.I18n.t('errorMessage.config.number.float') : '';
          };
        case 'directories':
        case 'directory':
          return function (value, name) {
            if (App.config.isDirHeterogeneous(name)) {
              if (!validator.isValidDataNodeDir(value)) return Em.I18n.t('errorMessage.config.directory.heterogeneous');
            } else {
              if (!validator.isValidDir(value)) return Em.I18n.t('errorMessage.config.directory.default');
            }
            if (!validator.isAllowedDir(value)) {
              return Em.I18n.t('errorMessage.config.directory.allowed');
            }
            return validator.isNotTrimmedRight(value) ? Em.I18n.t('errorMessage.config.spaces.trailing') : '';
          };
        case 'email':
          return function (value) {
            return !validator.isValidEmail(value) ? Em.I18n.t('errorMessage.config.mail') : '';
          };
        case 'supportTextConnection':
        case 'host':
          return function (value) {
            return validator.isNotTrimmed(value) ? Em.I18n.t('errorMessage.config.spaces.trim') : '';
          };
        case 'password':
          return function (value, name, retypedPassword) {
            if (name === 'ranger_admin_password') {
              if (String(value).length < 9) {
                return Em.I18n.t('errorMessage.config.password.length').format(9);
              }
            }
            return value !== retypedPassword ? Em.I18n.t('errorMessage.config.password') : '';
          };
        case 'user':
        case 'database':
        case 'db_user':
          return function (value) {
            return !validator.isValidDbName(value) ? Em.I18n.t('errorMessage.config.user') : '';
          };
        case 'ldap_url':
          return function (value) {
            return !validator.isValidLdapsURL(value) ? Em.I18n.t('errorMessage.config.ldapUrl') : '';
          };
        default:
          return function (value, name) {
            Iif (['javax.jdo.option.ConnectionURL', 'oozie.service.JPAService.jdbc.url'].contains(name) && !validator.isConfigValueLink(value) && validator.isConfigValueLink(value)) {
              return Em.I18n.t('errorMessage.config.spaces.trim');
            }
            return validator.isNotTrimmedRight(value) ? Em.I18n.t('errorMessage.config.spaces.trailing') : '';
          };
      }
    },
 
    /**
     * Returns warning validator function based on config type
     *
     * @param displayType
     * @returns {Function}
     */
    getWarningValidator: function getWarningValidator(displayType) {
      switch (displayType) {
        case 'int':
        case 'float':
          return function (value, name, filename, stackConfigProperty, unitLabel) {
            stackConfigProperty = stackConfigProperty || App.configsCollection.getConfigByName(name, filename);
            var maximum = Em.get(stackConfigProperty || {}, 'valueAttributes.maximum'),
                minimum = Em.get(stackConfigProperty || {}, 'valueAttributes.minimum'),
                min = validator.isValidFloat(minimum) ? parseFloat(minimum) : NaN,
                max = validator.isValidFloat(maximum) ? parseFloat(maximum) : NaN,
                val = validator.isValidFloat(value) ? parseFloat(value) : NaN;
 
            if (!isNaN(val) && !isNaN(max) && val > max) {
              return Em.I18n.t('config.warnMessage.outOfBoundaries.greater').format(max + unitLabel);
            }
            if (!isNaN(val) && !isNaN(min) && val < min) {
              return Em.I18n.t('config.warnMessage.outOfBoundaries.less').format(min + unitLabel);
            }
            return '';
          };
        default:
          return function () {
            return '';
          };
      }
    },
 
    /**
     * Defines if config support heterogeneous devices
     *
     * @param {string} name
     * @returns {boolean}
     */
    isDirHeterogeneous: function isDirHeterogeneous(name) {
      return ['dfs.datanode.data.dir'].contains(name);
    },
 
    /**
     * format property value depending on displayType
     * and one exception for 'kdc_type'
     * @param serviceConfigProperty
     * @param [originalValue]
     * @returns {*}
     */
    formatPropertyValue: function formatPropertyValue(serviceConfigProperty, originalValue) {
      var value = Em.isNone(originalValue) ? Em.get(serviceConfigProperty, 'value') : originalValue,
          displayType = Em.get(serviceConfigProperty, 'displayType') || Em.get(serviceConfigProperty, 'valueAttributes.type');
      if (Em.get(serviceConfigProperty, 'name') === 'kdc_type') {
        return App.router.get('mainAdminKerberosController.kdcTypesValues')[value];
      }
      Iif (/^\s+$/.test("" + value)) {
        return " ";
      }
      switch (displayType) {
        case 'int':
          if (/\d+m$/.test(value)) {
            return value.slice(0, value.length - 1);
          } else {
            var int = parseInt(value);
            return isNaN(int) ? "" : int.toString();
          }
        case 'float':
          var float = parseFloat(value);
          return isNaN(float) ? "" : float.toString();
        case 'componentHosts':
          Eif (typeof value == 'string') {
            return value.replace(/\[|]|'|&apos;/g, "").split(',');
          }
          return value;
        case 'content':
        case 'string':
        case 'multiLine':
        case 'directories':
        case 'directory':
          return this.trimProperty({ displayType: displayType, value: value });
        default:
          return value;
      }
    },
 
    /**
     * Format float value
     *
     * @param {*} value
     * @returns {string|*}
     */
    formatValue: function formatValue(value) {
      return validator.isValidFloat(value) ? parseFloat(value).toString() : value;
    },
 
    /**
     * Get step config by file name
     *
     * @param stepConfigs
     * @param fileName
     * @returns {Object|null}
     */
    getStepConfigForProperty: function getStepConfigForProperty(stepConfigs, fileName) {
      return stepConfigs.find(function (s) {
        return s.get('configTypes').contains(App.config.getConfigTagFromFileName(fileName));
      });
    },
 
    /**
     *
     * @param configs
     * @returns {Object[]}
     */
    sortConfigs: function sortConfigs(configs) {
      return configs.sort(function (a, b) {
        Iif (Em.get(a, 'index') > Em.get(b, 'index')) return 1;
        if (Em.get(a, 'index') < Em.get(b, 'index')) return -1;
        Eif (Em.get(a, 'name') > Em.get(b, 'name')) return 1;
        if (Em.get(a, 'name') < Em.get(b, 'name')) return -1;
        return 0;
      });
    },
 
    /**
     * create new ServiceConfig object by service name
     * @param {string} serviceName
     * @param {App.ServiceConfigGroup[]} [configGroups]
     * @param {App.ServiceConfigProperty[]} [configs]
     * @param {Number} [initConfigsLength]
     * @return {App.ServiceConfig}
     * @method createServiceConfig
     */
    createServiceConfig: function createServiceConfig(serviceName, configGroups, configs, initConfigsLength) {
      var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
      return App.ServiceConfig.create({
        serviceName: preDefinedServiceConfig.get('serviceName'),
        displayName: preDefinedServiceConfig.get('displayName'),
        configCategories: preDefinedServiceConfig.get('configCategories'),
        configs: configs || [],
        configGroups: configGroups || [],
        initConfigsLength: initConfigsLength || 0
      });
    },
 
    /**
     * GETs all cluster level sites in one call.
     *
     * @return {$.ajax}
     */
    loadConfigsByTags: function loadConfigsByTags(tags) {
      var urlParams = [];
      tags.forEach(function (_tag) {
        urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
      });
      var params = urlParams.join('|');
      return App.ajax.send({
        name: 'config.on_site',
        sender: this,
        data: {
          params: params
        }
      });
    },
 
    configTypesInfoMap: {},
 
    /**
     * Get config types and config type attributes from stack service
     *
     * @param service
     * @return {object}
     */
    getConfigTypesInfoFromService: function getConfigTypesInfoFromService(service) {
      var configTypesInfoMap = this.get('configTypesInfoMap');
      Iif (configTypesInfoMap[service]) {
        // don't recalculate
        return configTypesInfoMap[service];
      }
      var configTypes = service.get('configTypes');
      var configTypesInfo = {
        items: [],
        supportsFinal: [],
        supportsAddingForbidden: []
      };
      Eif (configTypes) {
        for (var key in configTypes) {
          Eif (configTypes.hasOwnProperty(key)) {
            configTypesInfo.items.push(key);
            if (configTypes[key].supports && configTypes[key].supports.final === "true") {
              configTypesInfo.supportsFinal.push(key);
            }
            if (configTypes[key].supports && configTypes[key].supports.adding_forbidden === "true") {
              configTypesInfo.supportsAddingForbidden.push(key);
            }
          }
        }
      }
      configTypesInfoMap[service] = configTypesInfo;
      this.set('configTypesInfoMap', configTypesInfoMap);
      return configTypesInfo;
    },
 
    /**
     *
     * @param configs
     */
    addYarnCapacityScheduler: function addYarnCapacityScheduler(configs) {
      var value = '',
          savedValue = '',
          recommendedValue = '',
          excludedConfigs = App.config.getPropertiesFromTheme('YARN');
 
      var connectedConfigs = configs.filter(function (config) {
        return !excludedConfigs.contains(App.config.configId(config.get('name'), config.get('filename'))) && config.get('filename') === 'capacity-scheduler.xml';
      });
      var names = connectedConfigs.mapProperty('name');
 
      connectedConfigs.forEach(function (config) {
        value += config.get('name') + '=' + config.get('value') + '\n';
        Eif (!Em.isNone(config.get('savedValue'))) {
          savedValue += config.get('name') + '=' + config.get('savedValue') + '\n';
        }
        Eif (!Em.isNone(config.get('recommendedValue'))) {
          recommendedValue += config.get('name') + '=' + config.get('recommendedValue') + '\n';
        }
      }, this);
 
      var isFinal = connectedConfigs.someProperty('isFinal', true);
      var savedIsFinal = connectedConfigs.someProperty('savedIsFinal', true);
      var recommendedIsFinal = connectedConfigs.someProperty('recommendedIsFinal', true);
 
      var cs = App.config.createDefaultConfig('capacity-scheduler', 'capacity-scheduler.xml', true, {
        'value': value,
        'serviceName': 'YARN',
        'savedValue': savedValue || null,
        'recommendedValue': recommendedValue || null,
        'isFinal': isFinal,
        'savedIsFinal': savedIsFinal,
        'recommendedIsFinal': recommendedIsFinal,
        'category': 'CapacityScheduler',
        'displayName': 'Capacity Scheduler',
        'description': 'Capacity Scheduler properties',
        'displayType': 'capacityScheduler'
      });
 
      configs = configs.filter(function (c) {
        return !(names.contains(c.get('name')) && c.get('filename') === 'capacity-scheduler.xml');
      });
      configs.push(App.ServiceConfigProperty.create(cs));
      return configs;
    },
 
    /**
     *
     * @param serviceName
     * @returns {Array}
     */
    getPropertiesFromTheme: function getPropertiesFromTheme(serviceName) {
      var properties = [];
      App.Tab.find().rejectProperty('isCategorized').forEach(function (t) {
        if (!t.get('isAdvanced') && t.get('serviceName') === serviceName) {
          t.get('sections').forEach(function (s) {
            s.get('subSections').forEach(function (ss) {
              properties = properties.concat(ss.get('configProperties'));
            });
          });
        }
      }, this);
      return properties;
    },
 
    /**
     * transform one config with textarea content
     * into set of configs of file
     * @param configs
     * @param filename
     * @return {*}
     */
    textareaIntoFileConfigs: function textareaIntoFileConfigs(configs, filename) {
      var configsTextarea = configs.findProperty('name', 'capacity-scheduler');
      var stackConfigs = App.configsCollection.getAll();
      if (configsTextarea && !App.get('testMode')) {
        var properties = configsTextarea.get('value').split('\n');
 
        properties.forEach(function (_property) {
          var name, value, isUserProperty;
          Eif (_property) {
            _property = _property.split(/=(.+)/);
            name = _property[0];
            value = _property[1] ? _property[1] : "";
            isUserProperty = !stackConfigs.filterProperty('filename', 'capacity-scheduler.xml').findProperty('name', name);
 
            configs.push(Em.Object.create({
              name: name,
              value: value,
              savedValue: value,
              serviceName: configsTextarea.get('serviceName'),
              filename: filename,
              isFinal: configsTextarea.get('isFinal'),
              isNotDefaultValue: configsTextarea.get('isNotDefaultValue'),
              isRequiredByAgent: configsTextarea.get('isRequiredByAgent'),
              isUserProperty: isUserProperty,
              group: null
            }));
          }
        });
        return configs.without(configsTextarea);
      }
      return configs;
    },
 
    /**
     * trim trailing spaces for all properties.
     * trim both trailing and leading spaces for host displayType and hive/oozie datebases url.
     * for directory or directories displayType format string for further using.
     * for password and values with spaces only do nothing.
     * @param {Object} property
     * @returns {*}
     */
    trimProperty: function trimProperty(property) {
      var displayType = Em.get(property, 'displayType');
      var value = Em.get(property, 'value');
      var name = Em.get(property, 'name');
      var rez;
      switch (displayType) {
        case 'directories':
        case 'directory':
          rez = value.replace(/,/g, ' ').trim().split(/\s+/g).join(',');
          break;
        case 'host':
          rez = value.trim();
          break;
        case 'password':
          break;
        default:
          if (name == 'javax.jdo.option.ConnectionURL' || name == 'oozie.service.JPAService.jdbc.url') {
            rez = value.trim();
          }
          rez = typeof value == 'string' ? value.replace(/(\s+$)/g, '') : value;
      }
      return rez == '' || rez == undefined ? value : rez;
    },
 
    /**
     * Generate minimal config property object used in *_properties.js files.
     * Example:
     * <code>
     *   var someProperties = App.config.generateConfigPropertiesByName([
     *    'property_1', 'property_2', 'property_3'], { category: 'General', filename: 'myFileName'});
     *   // someProperties contains Object[]
     *   [
     *    {
     *      name: 'property_1',
     *      displayName: 'property_1',
     *      isVisible: true,
     *      isReconfigurable: true,
     *      category: 'General',
     *      filename: 'myFileName'
     *    },
     *    .......
     *   ]
     * </code>
     * @param {string[]} names
     * @param {Object} properties - additional properties which will merge with base object definition
     * @returns {object[]}
     * @method generateConfigPropertiesByName
     */
    generateConfigPropertiesByName: function generateConfigPropertiesByName(names, properties) {
      return names.map(function (item) {
        var baseObj = {
          name: item
        };
        if (properties) return $.extend(baseObj, properties);else return baseObj;
      });
    },
 
    /**
     * load cluster stack configs from server and run mapper
     * @returns {$.ajax}
     * @method loadConfigsFromStack
     */
    loadClusterConfigsFromStack: function loadClusterConfigsFromStack() {
      return App.ajax.send({
        name: 'configs.stack_configs.load.cluster_configs',
        sender: this,
        data: {
          stackVersionUrl: App.get('stackVersionURL')
        },
        success: 'saveConfigsToModel'
      });
    },
 
    /**
     * load stack configs from server and run mapper
     * @param {String[]} [serviceNames=null]
     * @returns {$.ajax}
     * @method loadConfigsFromStack
     */
    loadConfigsFromStack: function loadConfigsFromStack(serviceNames) {
      serviceNames = serviceNames || [];
      var name = serviceNames.length > 0 ? 'configs.stack_configs.load.services' : 'configs.stack_configs.load.all';
      return App.ajax.send({
        name: name,
        sender: this,
        data: {
          stackVersionUrl: App.get('stackVersionURL'),
          serviceList: serviceNames.join(',')
        },
        success: 'saveConfigsToModel'
      });
    },
 
    /**
     * Runs <code>stackConfigPropertiesMapper<code>
     * @param {object} data
     * @method saveConfigsToModel
     */
    saveConfigsToModel: function saveConfigsToModel(data) {
      App.stackConfigPropertiesMapper.map(data);
    },
 
    /**
     * Check if config filename supports final attribute
     * @param serviceName
     * @param filename
     * @returns {boolean}
     */
    shouldSupportFinal: function shouldSupportFinal(serviceName, filename) {
      var unsupportedServiceNames = ['MISC', 'Cluster'];
      if (!serviceName || unsupportedServiceNames.contains(serviceName) || !filename) {
        return false;
      } else {
        var stackService = App.StackService.find(serviceName);
        Iif (!stackService) {
          return false;
        }
        return !!this.getConfigTypesInfoFromService(stackService).supportsFinal.find(function (configType) {
          return filename.startsWith(configType);
        });
      }
    },
 
    shouldSupportAddingForbidden: function shouldSupportAddingForbidden(serviceName, filename) {
      var unsupportedServiceNames = ['MISC', 'Cluster'];
      if (!serviceName || unsupportedServiceNames.contains(serviceName) || !filename) {
        return false;
      } else {
        var stackServiceName = App.StackService.find().findProperty('serviceName', serviceName);
        if (!stackServiceName) {
          return false;
        }
        var stackService = App.StackService.find(serviceName);
        return !!this.getConfigTypesInfoFromService(stackService).supportsAddingForbidden.find(function (configType) {
          return filename.startsWith(configType);
        });
      }
    },
 
    /**
     * Remove all ranger-related configs, that should be available only if Ranger is installed
     * @param configs - stepConfigs object
     */
    removeRangerConfigs: function removeRangerConfigs(configs) {
      configs.forEach(function (service) {
        var filteredConfigs = [];
        service.get('configs').forEach(function (config) {
          if (!/^ranger-/.test(config.get('filename'))) {
            filteredConfigs.push(config);
          }
        });
        service.set('configs', filteredConfigs);
        var filteredCategories = [];
        service.get('configCategories').forEach(function (category) {
          if (!/ranger-/.test(category.get('name'))) {
            filteredCategories.push(category);
          }
        });
        service.set('configCategories', filteredCategories);
      });
    },
 
    /**
     * Create config with non default config group. Some custom config properties
     * can be created and assigned to non-default config group.
     *
     * @param {Em.Object} override - config value
     * @param {Em.Object} configGroup - config group to set
     * @return {Object}
     **/
    createCustomGroupConfig: function createCustomGroupConfig(override, configGroup) {
      App.assertObject(override);
      App.assertEmberObject(configGroup);
 
      var newOverride = App.ServiceConfigProperty.create(this.createDefaultConfig(override.propertyName, override.filename, false, override));
 
      newOverride.setProperties({
        'isOriginalSCP': false,
        'overrides': null,
        'group': configGroup,
        'parentSCP': null,
        isCustomGroupConfig: true
      });
 
      Eif (!configGroup.get('properties.length')) {
        configGroup.set('properties', Em.A([]));
      }
      configGroup.set('properties', configGroup.get('properties').concat(newOverride));
 
      return newOverride;
    },
 
    /**
     * @param {App.ServiceConfigProperty} serviceConfigProperty
     * @param {Object} override - plain object with properties that is different from parent SCP
     * @param {App.ServiceConfigGroup} configGroup
     * @returns {App.ServiceConfigProperty}
     */
    createOverride: function createOverride(serviceConfigProperty, override, configGroup) {
      App.assertObject(serviceConfigProperty);
      App.assertEmberObject(configGroup);
 
      if (Em.isNone(serviceConfigProperty.get('overrides'))) serviceConfigProperty.set('overrides', []);
 
      var newOverride = App.ServiceConfigProperty.create(serviceConfigProperty);
 
      newOverride.setProperties({ 'savedValue': null, 'savedIsFinal': null });
 
      if (!Em.isNone(override)) {
        for (var key in override) {
          newOverride.set(key, override[key]);
        }
      }
 
      newOverride.setProperties({
        'isOriginalSCP': false,
        'overrides': null,
        'group': configGroup,
        'parentSCP': serviceConfigProperty
      });
 
      if (!configGroup.get('properties.length')) {
        configGroup.set('properties', Em.A([]));
      }
      configGroup.set('properties', configGroup.get('properties').concat(newOverride));
 
      serviceConfigProperty.get('overrides').pushObject(newOverride);
 
      var savedOverrides = serviceConfigProperty.get('overrides').filter(function (override) {
        return !Em.isNone(Em.get(override, 'savedValue'));
      });
      serviceConfigProperty.set('overrideValues', savedOverrides.mapProperty('savedValue'));
      serviceConfigProperty.set('overrideIsFinalValues', savedOverrides.mapProperty('savedIsFinal'));
 
      return newOverride;
    },
 
    /**
     * Merge values in "stored" to "base" if name matches, it's a value only merge.
     * @param base {Array} Em.Object
     * @param stored {Array} Object
     * @returns {Object[]|Em.Object[]} base
     */
    mergeStoredValue: function mergeStoredValue(base, stored) {
      Iif (stored) {
        base.forEach(function (p) {
          var sp = stored.filterProperty('filename', p.filename).findProperty('name', p.name);
          if (sp) {
            Em.set(p, 'value', Em.get(sp, 'value'));
          }
        });
      }
      return base;
    },
 
    /**
     * Helper method to get property from the <code>stepConfigs</code>
     *
     * @param {String} name - config property name
     * @param {String} fileName - config property filename
     * @param {Object[]} stepConfigs
     * @return {App.ServiceConfigProperty|Boolean} - App.ServiceConfigProperty instance or <code>false</code> when property not found
     */
    findConfigProperty: function findConfigProperty(stepConfigs, name, fileName) {
      if (!name || !fileName) return false;
      Eif (stepConfigs && stepConfigs.length) {
        return stepConfigs.mapProperty('configs').filter(function (item) {
          return item.length;
        }).reduce(function (p, c) {
          Eif (p) {
            return p.concat(c);
          }
        }).filterProperty('filename', fileName).findProperty('name', name);
      }
      return false;
    },
 
    getTempletonHiveHosts: function getTempletonHiveHosts(value) {
      var pattern = /thrift:\/\/.+:\d+/,
          patternMatch = value.match(pattern);
      return patternMatch ? patternMatch[0].split('\\,') : [];
    },
 
    /**
     * Update config property value based on its current value and list of zookeeper server hosts.
     * Used to prevent sort order issues.
     * <code>siteConfigs</code> object formatted according server's persist format e.g.
     *
     * <code>
     *   {
     *     'yarn-site': {
     *       'property_name1': 'property_value1'
     *       'property_name2': 'property_value2'
     *       .....
     *     }
     *   }
     * </code>
     *
     * @method updateHostsListValue
     * @param {Object} siteConfigs - prepared site config object to store
     * @param {String} propertyType - type of the property to update
     * @param {String} propertyName - name of the property to update
     * @param {String} hostsList - list of ZooKeeper Server names to set as config property value
     * @param {Boolean} isArray - determines whether value string is formatted as array
     * @return {String} - result value
     */
    updateHostsListValue: function updateHostsListValue(siteConfigs, propertyType, propertyName, hostsList, isArray) {
      var value = hostsList,
          propertyHosts = siteConfigs[propertyName] || '',
          hostsToSet = hostsList,
          parser = this.get('uniqueHostsListParsers').find(function (property) {
        return property.type === propertyType && property.propertyName === propertyName;
      });
      if (parser) {
        propertyHosts = this.get(parser.method)(propertyHosts);
        hostsToSet = this.get(parser.method)(hostsToSet);
      } else {
        if (isArray) {
          var pattern = /(^\[|]$)/g;
          propertyHosts = propertyHosts.replace(pattern, '');
          hostsToSet = hostsToSet.replace(pattern, '');
        }
        propertyHosts = propertyHosts.split(',');
        hostsToSet = hostsToSet.split(',');
      }
 
      if (!Em.isEmpty(siteConfigs[propertyName])) {
        var diffLength = propertyHosts.filter(function (hostName) {
          return !hostsToSet.contains(hostName);
        }).length;
        if (diffLength == 0 && propertyHosts.length == hostsToSet.length) {
          value = siteConfigs[propertyName];
        }
      }
      siteConfigs[propertyName] = value;
      return value;
    },
 
    /**
     * Load cluster-env configs mapped to array
     * @return {*|{then}}
     */
    getConfigsByTypes: function getConfigsByTypes(sites) {
      var _this = this;
 
      var dfd = $.Deferred();
      App.router.get('configurationController').getCurrentConfigsBySites(sites.mapProperty('site')).done(function (configs) {
        dfd.resolve(_this.getMappedConfigs(configs, sites));
      });
      return dfd.promise();
    },
 
    /**
     *
     * @param configs
     * @param sites
     */
    getMappedConfigs: function getMappedConfigs(configs, sites) {
      var result = [];
      configs.forEach(function (config) {
        var configsArray = [];
        var configsObject = config.properties;
        for (var property in configsObject) {
          if (configsObject.hasOwnProperty(property)) {
            configsArray.push(Em.Object.create({
              name: property,
              value: configsObject[property],
              filename: App.config.getOriginalFileName(config.type)
            }));
          }
        }
        result.push(Em.Object.create({
          serviceName: sites.findProperty('site', config.type).serviceName,
          configs: configsArray
        }));
      });
 
      return result;
    }
  });
});