Code coverage report for app/views/common/quick_view_link_view.js

Statements: 57.89% (198 / 342)      Branches: 49.54% (107 / 216)      Functions: 71.67% (43 / 60)      Lines: 58.75% (198 / 337)      Ignored: none     

All files » app/views/common/ » quick_view_link_view.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    1   1                                     1                   1                                                                                                                   1       1       2 2 2                       76   76 1 1 1                                                             2 2 2 2 2 2 2 1 1 1 1         2 2 2 2 2 2     2 2               4 4 3 3 2                       2   2 2     2     2       2                                     6 6 6 6 6 6 6 6             6     6     6   6 1 5 3 2 1   1         5 5 2                         2 2                   1 1                                                         6 6 6                                                                                                                         3 3 3 2   1                       1     1 1                                                                                                                                                                                                                                                                                                                                                                         2   2 2 2     2 1   2                     2   2 2       2 1   2 1   2                         3 3 3 3 3   3 1 2 1   3                       3 3 3 3 1 2 1   3                           27 27 27 27 26 26 26 28 28   3 3   3 3   3 3   3 3             16 16       27                     1 1 1 1 1 2 2 2               1                         8 5   3 2   1                         24 24 1   23 23 2   21 8   13                         13   13 13 13     13       13   13 1   12 1     11   11 11 11     11 17 17 17 17 17 8       11                         4     4 4 4 4   4       4 4 2 2 1     4 4 4 4 4 4                   1   1 1                              
'use strict';
 
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
 
;require.register("views/common/quick_view_link_view", 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');
 
  /**
   * @typedef {object} hostForQuickLink
   * @property {string} hostName
   * @property {string} publicHostName
   * @property {string} componentName
   * @property {?string} status
   */
 
  App.QuickLinksView = Em.View.extend({
 
    /**
     * @type {boolean}
     */
    isLoaded: false,
 
    /**
     * @type {boolean}
     */
    showQuickLinks: false,
 
    /**
     * @type {boolean}
     */
    showNoLinks: false,
 
    /**
     * @type {string}
     */
    quickLinksErrorMessage: '',
 
    /**
     * Updated quick links. Here we put correct hostname to url
     *
     * @type {object[]}
     */
    quickLinks: [],
 
    /**
     * @type {object[]}
     */
    configProperties: [],
 
    /**
     * list of files that contains properties for enabling/disabling ssl
     *
     * @type {string[]}
     */
    requiredSiteNames: [],
 
    /**
     * services that supports security. this array is used to find out protocol.
     * besides YARN, MAPREDUCE2, ACCUMULO. These services use
     * their properties to know protocol
     */
    servicesSupportsHttps: ["HDFS", "HBASE"],
 
    masterGroups: [],
 
    tooltipAttribute: 'quick-links-title-tooltip',
 
    shouldSetGroupedLinks: false,
 
    /**
     * @type {object}
     */
    ambariProperties: function () {
      return App.router.get('clusterController.ambariProperties');
    }.property().volatile(),
 
    didInsertElement: function didInsertElement() {
      this.loadQuickLinksConfigurations();
    },
 
    willDestroyElement: function willDestroyElement() {
      this.get('configProperties').clear();
      this.get('quickLinks').clear();
      this.get('requiredSiteNames').clear();
    },
 
    /**
     * The flags responsible for data to build quick links:
     * - App.router.clusterController.isServiceMetricsLoaded
     *
     * The flags responsible for correct, up-to-date state of quick links:
     * - App.currentStackVersionNumber
     * - App.router.clusterController.isHostComponentMetricsLoaded
     */
    setQuickLinks: function () {
      var _this = this;
 
      if (App.get('router.clusterController.isServiceMetricsLoaded')) {
        this.setConfigProperties().done(function (configProperties) {
          _this.get('configProperties').pushObjects(configProperties);
          _this.getQuickLinksHosts();
        });
      }
    }.observes('App.currentStackVersionNumber', 'App.router.clusterController.isServiceMetricsLoaded', 'App.router.clusterController.isHostComponentMetricsLoaded', 'App.router.clusterController.quickLinksUpdateCounter'),
 
    /**
    * Request for quick-links config
    *
    * @returns {$.ajax}
    * @method loadQuickLinksConfigurations
    */
    loadQuickLinksConfigurations: function loadQuickLinksConfigurations() {
      var serviceName = this.get('content.serviceName');
      return App.ajax.send({
        name: 'configs.quicklinksconfig',
        sender: this,
        data: {
          serviceName: serviceName,
          stackVersionUrl: App.get('stackVersionURL')
        },
        success: 'loadQuickLinksConfigSuccessCallback'
      });
    },
 
    /**
     * Sucess-callback for quick-links config request
     *
     * @param {object} data
     * @method loadQuickLinksConfigSuccessCallback
     */
    loadQuickLinksConfigSuccessCallback: function loadQuickLinksConfigSuccessCallback(data) {
      App.quicklinksMapper.map(data);
      var quickLinksConfig = this.getQuickLinksConfiguration();
      Eif (!Em.isNone(quickLinksConfig)) {
        var protocolConfig = Em.get(quickLinksConfig, 'protocol');
        var checks = Em.get(protocolConfig, 'checks');
        var sites = ['core-site', 'hdfs-site', 'admin-properties'];
        if (checks) {
          checks.forEach(function (check) {
            var protocolConfigSiteProp = Em.get(check, 'site');
            Eif (sites.indexOf(protocolConfigSiteProp) < 0) {
              sites.push(protocolConfigSiteProp);
            }
          }, this);
        }
 
        var links = Em.get(quickLinksConfig, 'links');
        Eif (!Em.isEmpty(links)) {
          links.forEach(function (link) {
            Eif (!link.remove) {
              this.addSite(link, 'host', sites);
              this.addSite(link, 'port', sites);
            }
          }, this);
          this.set('requiredSiteNames', this.get('requiredSiteNames').pushObjects(sites).uniq());
          this.setQuickLinks();
        }
      } else {
        this.set('showNoLinks', true);
      }
    },
 
    addSite: function addSite(link, linkPropertyName, sites) {
      var config = Em.get(link, linkPropertyName);
      if (config) {
        var siteName = Em.get(config, 'site');
        if (!sites.contains(siteName)) {
          sites.push(siteName);
        }
      }
    },
 
    /**
     * call for public host names
     *
     * @returns {$.ajax}
     * @method getQuickLinksHosts
     */
    getQuickLinksHosts: function getQuickLinksHosts() {
      var links = App.QuickLinksConfig.find().mapProperty('links'),
          components = links.reduce(function (componentsArray, currentLinksArray) {
        var componentNames = currentLinksArray.mapProperty('component_name').uniq();
        return [].concat(_toConsumableArray(componentsArray), _toConsumableArray(componentNames));
      }, []),
          hosts = App.HostComponent.find().filter(function (component) {
        return components.contains(component.get('componentName'));
      }).mapProperty('hostName').uniq();
 
      Iif (hosts.length === 0) {
        return $.Deferred().reject().promise();
      }
 
      return App.ajax.send({
        name: 'hosts.for_quick_links',
        sender: this,
        data: {
          clusterName: App.get('clusterName'),
          hosts: hosts.join(','),
          urlParams: this.get('content.serviceName') === 'HBASE' ? ',host_components/metrics/hbase/master/IsActiveMaster' : ''
        },
        success: 'setQuickLinksSuccessCallback'
      });
    },
 
    /**
     * Success-callback for quick-links hosts request
     *
     * @param {object} response
     * @method setQuickLinksSuccessCallback
     */
    setQuickLinksSuccessCallback: function setQuickLinksSuccessCallback(response) {
      var serviceName = this.get('content.serviceName');
      var hosts = this.getHosts(response, serviceName);
      var hasQuickLinks = this.hasQuickLinksConfig(serviceName, hosts);
      var hasHosts = false;
      var componentNames = hosts.mapProperty('componentName');
      componentNames.forEach(function (_componentName) {
        var component = App.MasterComponent.find().findProperty('componentName', _componentName) || App.SlaveComponent.find().findProperty('componentName', _componentName);
        Iif (component) {
          hasHosts = hasHosts || !!component.get('totalCount');
        }
      });
      // no need to set quicklinks if
      // 1)current service does not have quick links configured
      // 2)No host component present for the configured quicklinks and has no overridden hosts
      Iif (hasQuickLinks && (hasHosts || this.hasOverriddenHost())) {
        this.set('showQuickLinks', true);
      } else {
        this.set('showNoLinks', true);
      }
 
      var isMultipleComponentsInLinks = componentNames.uniq().length > 1;
 
      if (hosts.length === 0 && !this.hasOverriddenHost()) {
        this.setEmptyLinks();
      } else if (hosts.length === 1 || isMultipleComponentsInLinks || this.hasOverriddenHost()) {
        this.setSingleHostLinks(hosts, response);
      } else if (this.get('masterGroups.length') > 1 || this.get('shouldSetGroupedLinks')) {
        this.setMultipleGroupLinks(hosts);
      } else {
        this.setMultipleHostLinks(hosts);
      }
    },
 
    hasOverriddenHost: function hasOverriddenHost() {
      var links = Em.get(this.getQuickLinksConfiguration(), 'links');
      return links && links.some(function (each) {
        return each.host;
      });
    },
 
    /**
     * Get public host name by its host name.
     *
     * @method getPublicHostName
     * @param {Object[]} hosts - list of hosts from response
     * @param {string} hostName
     * @return {?string}
     **/
    getPublicHostName: function getPublicHostName(hosts, hostName) {
      var host = hosts.findProperty('Hosts.host_name', hostName);
      return host ? Em.get(host, 'Hosts.public_host_name') : null;
    },
 
    /**
     * Get configs from `configurationController` for provided list of the tags
     *
     * @returns {$.Deferred}
     * @method setConfigProperties
     */
    setConfigProperties: function setConfigProperties() {
      this.get('configProperties').clear();
      return App.router.get('configurationController').getCurrentConfigsBySites(this.get('requiredSiteNames'));
    },
 
    /**
     * Get quick links config for <code>content.serviceName</code>
     *
     * @returns {?App.QuickLinksConfig}
     * @method getQuickLinksConfiguration
     */
    getQuickLinksConfiguration: function getQuickLinksConfiguration() {
      var serviceName = this.get('content.serviceName');
      var self = this;
      var quicklinks = {};
      if (self.hasQuickLinksConfig(serviceName)) {
        quicklinks = App.QuickLinksConfig.find().findProperty('id', serviceName);
        Em.set(quicklinks, 'links', Em.get(quicklinks, 'links').filterProperty('visible', true));
        return quicklinks;
      }
      return null;
    },
 
    /**
     * Check if <code>serviceName</code> has quick-links config
     *
     * @param {string} serviceName
     * @returns {boolean}
     * @method hasQuickLinksConfig
     */
    hasQuickLinksConfig: function hasQuickLinksConfig(serviceName) {
      var result = App.QuickLinksConfig.find().findProperty('id', serviceName);
      Eif (!result) {
        return false;
      }
      var links = result.get('links');
      return Em.isEmpty(links) ? false : links.length !== links.filterProperty('remove').length;
    },
 
    /**
     *
     * @param {object} link
     * @param {string} host
     * @param {string} protocol
     * @param {object[]} configProperties
     * @param {object} response
     * @returns {?object}
     * @method getHostLink
     */
    getHostLink: function getHostLink(link, host, protocol, configProperties, response) {
      var serviceName = this.get('content.serviceName');
      if (serviceName === 'MAPREDUCE2' && response) {
        var portConfig = Em.get(link, 'port');
        var siteName = Em.get(portConfig, 'site');
        var siteConfigs = this.get('configProperties').findProperty('type', siteName).properties;
        var hostPortConfigValue = siteConfigs[Em.get(portConfig, protocol + '_config')];
        if (!Em.isNone(hostPortConfigValue)) {
          var hostPortValue = hostPortConfigValue.match(new RegExp('([\\w\\d.-]*):(\\d+)'));
          var hostObj = response.items.findProperty('Hosts.host_name', hostPortValue[1]);
          if (!Em.isNone(hostObj)) {
            host = hostObj.Hosts.public_host_name;
          }
        }
      } else if (serviceName === 'RANGER') {
        var _siteConfigs = this.get('configProperties').findProperty('type', 'admin-properties').properties;
        if (_siteConfigs['policymgr_external_url']) {
          return {
            label: link.label,
            url: _siteConfigs['policymgr_external_url']
          };
        }
      }
 
      var linkPort = this.setPort(Em.get(link, 'port'), protocol, configProperties);
      if (Em.get(link, 'url') && !Em.get(link, 'removed')) {
        var newItem = {};
        var requiresUserName = Em.get(link, 'requires_user_name');
        var template = Em.get(link, 'url');
        if ('true' === requiresUserName) {
          newItem.url = template.fmt(protocol, host, linkPort, App.router.get('loginName'));
        } else {
          newItem.url = template.fmt(protocol, host, linkPort);
        }
        newItem.label = link.label;
        newItem.url = this.resolvePlaceholders(newItem.url);
        return newItem;
      }
      return null;
    },
 
    /**
     * Replace placeholders like ${config-type/property-name} in the given URL
     */
    resolvePlaceholders: function resolvePlaceholders(url) {
      return url.replace(/\$\{(\S+)\/(\S+)\}/g, function (match, configType, propertyName) {
        var config = this.get('configProperties').findProperty('type', configType);
        if (config) {
          return config.properties[propertyName] ? config.properties[propertyName] : match;
        } else {
          return match;
        }
      }.bind(this));
    },
 
    /**
     * set empty links
     *
     * @method setEmptyLinks
     */
    setEmptyLinks: function setEmptyLinks() {
      //display an error message
      var quickLinks = [{
        label: this.get('quickLinksErrorMessage')
      }];
      this.set('quickLinks', quickLinks);
      this.set('isLoaded', true);
    },
 
    /**
     * set links that contain only one host
     *
     * @param {hostForQuickLink[]} hosts
     * @param {object} response
     * @method setSingleHostLinks
     */
    setSingleHostLinks: function setSingleHostLinks(hosts, response) {
      var quickLinksConfig = this.getQuickLinksConfiguration();
      if (!Em.isNone(quickLinksConfig)) {
        var quickLinks = [];
        var configProperties = this.get('configProperties');
        var protocol = this.setProtocol(configProperties, quickLinksConfig.get('protocol'));
 
        var links = Em.get(quickLinksConfig, 'links');
        links.forEach(function (link) {
          var isRelatedComponentInstalled = this.isRelatedComponentInstalled(link);
          if (isRelatedComponentInstalled) {
            var publicHostName = this.publicHostName(link, hosts, protocol);
            if (publicHostName) {
              if (link.protocol) {
                protocol = this.setProtocol(configProperties, link.protocol);
              }
              var newItem = this.getHostLink(link, publicHostName, protocol, configProperties, response); //quicklink generated for the hbs template
              if (!Em.isNone(newItem)) {
                quickLinks.push(newItem);
              }
            }
          }
        }, this);
        this.set('quickLinks', quickLinks);
        this.set('isLoaded', true);
      } else {
        this.set('quickLinks', []);
        this.set('isLoaded', false);
      }
    },
 
    publicHostName: function publicHostName(link, hosts, protocol) {
      if (link.host) {
        // if quicklink overrides hostcomponent host name, get host from config
        var configProperties = this.get('configProperties');
        var hostProperty = Em.get(link.host, protocol + '_property');
        var site = configProperties.findProperty('type', Em.get(link.host, 'site'));
        return site && site.properties ? this.parseHostFromUri(site.properties[hostProperty]) : null;
      } else {
        var hostNameForComponent = hosts.findProperty('componentName', link.component_name);
        return hostNameForComponent ? hostNameForComponent.publicHostName : null;
      }
    },
 
    /**
     * @param {string} uri
     */
    parseHostFromUri: function parseHostFromUri(uri) {
      if (uri) {
        var match = uri.match(/:\/\/([^/:]+)/i);
        return match != null && match.length == 2 ? match[1] : uri;
      } else {
        return null;
      }
    },
 
    getMultipleHostLinks: function getMultipleHostLinks(hosts) {
      var quickLinksConfig = this.getQuickLinksConfiguration();
      if (Em.isNone(quickLinksConfig)) {
        return;
      }
 
      var quickLinksArray = [];
      hosts.forEach(function (host) {
        var publicHostName = host.publicHostName;
        var quickLinks = [];
        var configProperties = this.get('configProperties');
 
        var protocol = this.setProtocol(configProperties, quickLinksConfig.get('protocol'));
        var serviceName = Em.get(quickLinksConfig, 'serviceName');
        var links = Em.get(quickLinksConfig, 'links');
        links.forEach(function (link) {
          var linkRemoved = Em.get(link, 'removed');
          var url = Em.get(link, 'url');
          var isRelatedComponentInstalled = this.isRelatedComponentInstalled(link);
          if (url && !linkRemoved && isRelatedComponentInstalled) {
            var hostNameRegExp = new RegExp('([\\w\\W]*):\\d+');
            if (serviceName === 'HDFS') {
              var config;
              var configPropertiesObject = configProperties.findProperty('type', 'hdfs-site');
              if (configPropertiesObject && configPropertiesObject.properties) {
                var properties = configPropertiesObject.properties;
                var nnKeyRegex = new RegExp('^dfs\.namenode\.' + protocol + '-address\.');
                var nnProperties = Object.keys(properties).filter(function (key) {
                  return nnKeyRegex.test(key);
                });
                var nnPropertiesLength = nnProperties.length;
                for (var i = nnPropertiesLength; i--;) {
                  var propertyName = nnProperties[i];
                  var hostNameMatch = properties[propertyName] && properties[propertyName].match(hostNameRegExp);
                  if (hostNameMatch && hostNameMatch[1] === host.publicHostName) {
                    config = propertyName;
                    break;
                  }
                }
              }
              var portConfig = Em.get(link, 'port');
              Em.set(portConfig, protocol + '_property', config);
              Em.set(link, 'port', portConfig);
            }
 
            var newItem = this.getHostLink(link, publicHostName, protocol, configProperties); //quicklink generated for the hbs template
            if (!Em.isNone(newItem)) {
              quickLinks.push(newItem);
            }
          }
        }, this);
 
        if (host.status) {
          quickLinks.set('publicHostNameLabel', Em.I18n.t('quick.links.publicHostName').format(host.publicHostName, host.status));
        } else {
          quickLinks.set('publicHostNameLabel', host.publicHostName);
        }
        quickLinksArray.push(quickLinks);
      }, this);
      return quickLinksArray;
    },
 
    /**
     * set links that contain multiple hosts
     *
     * @param {hostForQuickLink[]} hosts
     * @method setMultipleHostLinks
     */
    setMultipleHostLinks: function setMultipleHostLinks(hosts) {
      var quickLinks = this.getMultipleHostLinks(hosts);
      this.setProperties({
        quickLinksArray: [{
          links: quickLinks || []
        }],
        isLoaded: !!quickLinks
      });
    },
 
    /**
     * set links that contain for multiple grouped hosts
     *
     * @param {hostForQuickLink[]} hosts
     * @method setMultipleGroupLinks
     */
    setMultipleGroupLinks: function setMultipleGroupLinks(hosts) {
      var _this2 = this;
 
      var isLoaded = true;
      var quickLinksArray = this.get('masterGroups').map(function (group) {
        var groupHosts = hosts.filter(function (host) {
          return group.hosts.contains(host.hostName);
        }),
            links = _this2.getMultipleHostLinks(groupHosts);
        if (!links) {
          isLoaded = false;
        }
        return {
          title: group.title,
          links: links || []
        };
      });
      this.setProperties({
        quickLinksArray: quickLinksArray,
        isLoaded: isLoaded
      });
    },
 
    /**
     * set status to hosts with OOZIE_SERVER
     *
     * @param {object[]} hosts
     * @returns {object[]}
     * @method processOozieHosts
     */
    processOozieHosts: function processOozieHosts(hosts) {
      var activeOozieServers = this.get('content.hostComponents').filterProperty('componentName', 'OOZIE_SERVER').filterProperty('workStatus', 'STARTED').mapProperty('hostName');
 
      var oozieHostsArray = hosts.filter(function (host) {
        host.status = Em.I18n.t('quick.links.label.active');
        return activeOozieServers.contains(host.hostName);
      }, this);
 
      if (!oozieHostsArray.length) {
        this.set('quickLinksErrorMessage', Em.I18n.t('quick.links.error.oozie.label'));
      }
      return oozieHostsArray;
    },
 
    /**
     * set status to hosts with NAMENODE
     *
     * @param {hostForQuickLink[]} hosts
     * @returns {object[]}
     * @method hostForQuickLink
     */
    processHdfsHosts: function processHdfsHosts(hosts) {
      var _this3 = this;
 
      return hosts.map(function (host) {
        var hostName = host.hostName,
            isActiveNameNode = Em.get(_this3, 'content.activeNameNodes').someProperty('hostName', hostName),
            isStandbyNameNode = Em.get(_this3, 'content.standbyNameNodes').someProperty('hostName', hostName);
 
        if (isActiveNameNode) {
          host.status = Em.I18n.t('quick.links.label.active');
        }
        if (isStandbyNameNode) {
          host.status = Em.I18n.t('quick.links.label.standby');
        }
        return host;
      });
    },
 
    /**
     * set status to hosts with HBASE_MASTER
     *
     * @param {hostForQuickLink[]} hosts
     * @param {object} response
     * @returns {hostForQuickLink[]}
     * @method processHbaseHosts
     */
    processHbaseHosts: function processHbaseHosts(hosts, response) {
      return hosts.map(function (host) {
        var isActiveMaster;
        response.items.filterProperty('Hosts.host_name', host.hostName).filter(function (item) {
          var hbaseMaster = item.host_components.findProperty('HostRoles.component_name', 'HBASE_MASTER');
          isActiveMaster = hbaseMaster && Em.get(hbaseMaster, 'metrics.hbase.master.IsActiveMaster');
        });
        if (isActiveMaster === 'true') {
          host.status = Em.I18n.t('quick.links.label.active');
        } else if (isActiveMaster === 'false') {
          host.status = Em.I18n.t('quick.links.label.standby');
        }
        return host;
      }, this);
    },
 
    /**
     * set status to hosts with RESOURCEMANAGER
     *
     * @param {hostForQuickLink[]} hosts
     * @returns {hostForQuickLink[]}
     * @method processYarnHosts
     */
    processYarnHosts: function processYarnHosts(hosts) {
      return hosts.map(function (host) {
        var resourceManager = this.get('content.hostComponents').filterProperty('componentName', 'RESOURCEMANAGER').findProperty('hostName', host.hostName);
        var haStatus = resourceManager && resourceManager.get('haStatus');
        if (haStatus === 'ACTIVE') {
          host.status = Em.I18n.t('quick.links.label.active');
        } else if (haStatus === 'STANDBY') {
          host.status = Em.I18n.t('quick.links.label.standby');
        }
        return host;
      }, this);
    },
 
    /**
     * sets public host names for required masters of current service
     *
     * @param {object} response
     * @param {string} serviceName - selected serviceName
     * @returns {hostForQuickLink[]} containing hostName(s)
     * @method getHosts
     */
    getHosts: function getHosts(response, serviceName) {
      //The default error message when we cannot obtain the host information for the given service
      this.set('quickLinksErrorMessage', Em.I18n.t('quick.links.error.nohosts.label').format(serviceName));
      var hosts = [];
      var quickLinkConfigs = App.QuickLinksConfig.find().findProperty("id", serviceName);
      if (quickLinkConfigs) {
        var links = quickLinkConfigs.get('links');
        var componentNames = links.mapProperty('component_name').uniq();
        componentNames.forEach(function (_componentName) {
          var componentHosts = this.findHosts(_componentName, response);
          switch (serviceName) {
            case 'OOZIE':
              hosts = hosts.concat(this.processOozieHosts(componentHosts));
              break;
            case "HDFS":
              hosts = hosts.concat(this.processHdfsHosts(componentHosts));
              break;
            case "HBASE":
              hosts = hosts.concat(this.processHbaseHosts(componentHosts, response));
              break;
            case "YARN":
              hosts = hosts.concat(this.processYarnHosts(componentHosts));
              break;
            case "SMARTSENSE":
              if (!App.MasterComponent.find().findProperty('componentName', _componentName)) {
                hosts = [];
                break;
              }
            default:
              hosts = hosts.concat(componentHosts);
              break;
          }
        }, this);
      }
      return hosts;
    },
 
    /**
     * find host public names
     *
     * @param {string} componentName
     * @param {object} response
     * @returns {hostForQuickLink[]}
     */
    findHosts: function findHosts(componentName, response) {
      var hosts = [];
      var component = App.MasterComponent.find().findProperty('componentName', componentName) || App.SlaveComponent.find().findProperty('componentName', componentName);
      Eif (component) {
        var hostComponents = component.get('hostNames') || [];
        hostComponents.forEach(function (_hostName) {
          var host = this.getPublicHostName(response.items, _hostName);
          Eif (host) {
            hosts.push({
              hostName: _hostName,
              publicHostName: host,
              componentName: componentName
            });
          }
        }, this);
      }
      return hosts;
    },
 
    /**
     * 'http' for 'https'
     * 'https' for 'https'
     * empty string otherwise
     *
     * @param {string} type
     * @returns {string}
     * @method reverseType
     */
    reverseType: function reverseType(type) {
      if ('https' === type) {
        return 'http';
      }
      if ('http' === type) {
        return 'https';
      }
      return '';
    },
 
    /**
     *
     * @param {object[]} configProperties
     * @param {string} configType
     * @param {string} property
     * @param {string} desiredState
     * @returns {boolean}
     * @method meetDesired
     */
    meetDesired: function meetDesired(configProperties, configType, property, desiredState) {
      var currentConfig = configProperties.findProperty('type', configType);
      if (!currentConfig) {
        return false;
      }
      var currentPropertyValue = currentConfig.properties[property];
      if ('NOT_EXIST' === desiredState) {
        return Em.isNone(currentPropertyValue);
      }
      if ('EXIST' === desiredState) {
        return !Em.isNone(currentPropertyValue);
      }
      return desiredState === currentPropertyValue;
    },
 
    /**
     * setProtocol - if cluster is secure for some services (GANGLIA, MAPREDUCE2, YARN and servicesSupportsHttps)
     * protocol becomes "https" otherwise "http" (by default)
     *
     * @param {Object} configProperties
     * @param {Object} protocolConfig
     * @returns {string} "https" or "http" only!
     * @method setProtocol
     */
    setProtocol: function setProtocol(configProperties, protocolConfig) {
      var hadoopSslEnabled = false;
 
      Eif (!Em.isEmpty(configProperties)) {
        var hdfsSite = configProperties.findProperty('type', 'hdfs-site');
        hadoopSslEnabled = hdfsSite && Em.get(hdfsSite, 'properties') && hdfsSite.properties['dfs.http.policy'] === 'HTTPS_ONLY';
      }
 
      Iif (!protocolConfig) {
        return hadoopSslEnabled ? 'https' : 'http';
      }
 
      var protocolType = Em.get(protocolConfig, 'type');
 
      if ('HTTPS_ONLY' === protocolType) {
        return 'https';
      }
      if ('HTTP_ONLY' === protocolType) {
        return 'http';
      }
 
      protocolType = protocolType.toLowerCase();
 
      var count = 0;
      var checks = Em.get(protocolConfig, 'checks');
      Iif (!checks) {
        return hadoopSslEnabled ? 'https' : 'http';
      }
      checks.forEach(function (check) {
        var configType = Em.get(check, 'site');
        var property = Em.get(check, 'property');
        var desiredState = Em.get(check, 'desired');
        var checkMeet = this.meetDesired(configProperties, configType, property, desiredState);
        if (!checkMeet) {
          count++;
        }
      }, this);
 
      return count ? this.reverseType(protocolType) : protocolType;
    },
 
    /**
     * sets the port of quick link
     *
     * @param {object} portConfigs
     * @param {string} protocol
     * @param {object[]} configProperties
     * @returns {string}
     * @method setPort
     */
    setPort: function setPort(portConfigs, protocol, configProperties) {
      Iif (!portConfigs) {
        return '';
      }
      var defaultPort = Em.get(portConfigs, protocol + '_default_port');
      var portProperty = Em.get(portConfigs, protocol + '_property');
      var site = configProperties.findProperty('type', Em.get(portConfigs, 'site'));
      var propertyValue = site && site.properties && site.properties[portProperty];
 
      Iif (!propertyValue) {
        return defaultPort;
      }
 
      var regexValue = Em.get(portConfigs, 'regex');
      if (protocol === 'https') {
        var httpsRegex = Em.get(portConfigs, 'https_regex');
        if (httpsRegex) {
          regexValue = httpsRegex;
        }
      }
      regexValue = regexValue.trim();
      Eif (regexValue) {
        var re = new RegExp(regexValue);
        var portValue = propertyValue.match(re);
        try {
          return portValue[1];
        } catch (err) {
          return defaultPort;
        }
      } else {
        return propertyValue;
      }
    },
 
    setTooltip: function () {
      var _this4 = this;
 
      Em.run.next(function () {
        Iif (_this4.get('showQuickLinks') && _this4.get('isLoaded') && _this4.get('quickLinksArray.length')) {
          App.tooltip($('[rel="' + _this4.get('tooltipAttribute') + '"]'));
        }
      });
    }.observes('showQuickLinks', 'isLoaded', 'quickLinksArray.length'),
 
    /**
     * Check if host component related to quickLink is installed
     * @param quickLink
     * @returns {Boolean}
     */
    isRelatedComponentInstalled: function isRelatedComponentInstalled(quickLink) {
      return App.HostComponent.find().someProperty('componentName', quickLink.component_name);
    }
  });
});