TT Bigdata TT Bigdata
首页
GitHub (opens new window)
JaneTTR

JaneTTR

数据酿造智慧,每一滴都是沉淀!
  • Ambari 深度专题

  • Bigtop 方法论

  • 自定义集成

  • Ambari Server 与 Web

    • 方法论

    • 代码生命周期-metainfo

      • 加载原理深度剖析[一]
      • 加载原理深度剖析[二]
      • 加载原理深度剖析[三]
      • 结构与层级深入解读
      • configFile详解[一]
      • configFile详解[二]
      • cardinality详解[一]
      • cardinality详解[二]
      • cardinality详解[三]
      • category详解[一]
      • category详解[二]
      • category详解[三]
      • theme详解[一]
      • theme详解[二]
      • theme详解[三]
      • commandScript详解[二]
      • commandScript详解[一]
      • commandScript详解[三]
      • customCommand详解[一]
      • customCommand详解[二]
      • customCommand详解[三]
      • requiredServices详解[一]
      • requiredServices详解[二]
      • osSpecifics详解[一]
      • osSpecifics详解[二]
      • osSpecifics详解[三]
      • quicklinks详解[一]
      • quicklinks详解[二]
        • 3. 实操与代码解析 🔧
          • 3.1 从实战角度理解
          • 3.1.1 请求环节解析
          • 3.1.1.1 请求分析
          • 3.1.1.2 响应结果
          • 3.1.2 触发程序追踪
          • 3.1.2.1 前端触发点
          • 3.1.2.2 推导请求来源
      • quicklinks详解[三]
      • quicklinks详解[四]
      • versionAdvertised详解
    • 架构剖析

    • UI样式

  • Ambari Metrics

  • Ambari Plus 思考

  • Redis集成实战

  • 通用代码模板

  • 各组件代码

  • 技术专题
  • Ambari Server 与 Web
  • 代码生命周期-metainfo
JaneTTR
2025-06-03
目录
3. 实操与代码解析 🔧
3.1 从实战角度理解
3.1.1 请求环节解析
3.1.1.1 请求分析
3.1.1.2 响应结果
3.1.2 触发程序追踪
3.1.2.1 前端触发点
3.1.2.2 推导请求来源

quicklinks详解[二]

# 3. 实操与代码解析 🔧

# 3.1 从实战角度理解

QuickLinks 的整个生命周期,从 API 请求、模板解析到前端渲染,都是 Ambari 平台“配置即页面”理念的典型体现。本节将围绕* *接口调用、前后端协同、动态参数解析**等维度,带你理解其幕后逻辑,并结合实际案例,拆解流程细节。

提示

理解 QuickLinks,不仅仅是知道如何配,还要清楚每个环节出现问题时怎么排查、如何实现高可用的“自动适配”。

我们按照如下步骤进行逐层剖析:

  1. 请求环节解析:QuickLinks API 的实际调用与返回机制
  2. 触发程序追踪:前端 JS 如何发起请求,以及如何将模板转为页面链接
  3. 模板来源解析:QuickLinks 配置文件的实际存放与加载逻辑
  4. 模板解析流程:前端如何动态解析模板参数、渲染最终链接
  5. 参数详细解读:每个关键属性(如 protocol、port、url)的含义和最佳实践

# 3.1.1 请求环节解析

运维或开发可直接通过浏览器开发者工具(Network)或者 curl 抓包,获得 QuickLinks 的 API 请求与响应。

# 3.1.1.1 请求分析
curl 'http://localhost:28080/api/v1/stacks/BIGTOP/versions/3.1.0/services/HDFS/quicklinks?QuickLinkInfo/default=true&fields=*&_=1735612056333' \
  -H 'Accept: application/json, text/javascript, */*; q=0.01' \
  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: text/plain' \
  -H 'Cookie: _ga=GA1.1.1039361229.1720495067; apt.uid=AP-YFGMCGUNNIFB-2-1732688353177-48447658.0.2.a2e3917a-4f22-4c24-8671-436b74b600a2; _ga_0C4M1PWYZ7=GS1.1.1732691986.16.0.1732691986.0.0.0; _ga_T11SF3WXX2=GS1.1.1732691986.15.0.1732691986.60.0.0; _ga_K2SPJK2C73=GS1.1.1732691986.15.0.1732691986.60.0.0; AMBARISESSIONID=node01d544tvt60a5n1ichl7mcslkv80.node0' \
  -H 'Pragma: no-cache' \
  -H 'Referer: http://localhost:28080/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0' \
  -H 'X-Requested-By: X-Requested-By' \
  -H 'X-Requested-With: XMLHttpRequest' \
  -H 'sec-ch-ua: "Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  • 请求 URL: http://localhost:28080/api/v1/stacks/BIGTOP/versions/3.1.0/services/HDFS/quicklinks

    • 这里请求的是 BIGTOP 3.1.0 栈下 HDFS 服务的 QuickLinks 信息
  • 请求参数:

    • QuickLinkInfo/default=true:仅获取默认 QuickLinks 配置
    • fields=*:返回全部字段内容
# 3.1.1.2 响应结果

接口返回值为完整 JSON,包括所有 QuickLinks 配置与参数,内容丰富且高度结构化:

image-20241231100907324

{
  "href": "http://localhost:28080/api/v1/stacks/BIGTOP/versions/3.1.0/services/HDFS/quicklinks?QuickLinkInfo/default=true&fields=*&_=1735612056333",
  "items": [
    {
      "href": "http://localhost:28080/api/v1/stacks/BIGTOP/versions/3.1.0/services/HDFS/quicklinks/quicklinks.json",
      "QuickLinkInfo": {
        "default": true,
        "file_name": "quicklinks.json",
        "service_name": "HDFS",
        "stack_name": "BIGTOP",
        "stack_version": "3.1.0",
        "quicklink_data": {
          "QuickLinksConfiguration": {
            "description": "default quick links configuration",
            "name": "default",
            "configuration": {
              "protocol": {
                "type": "https",
                "checks": [
                  {
                    "property": "dfs.http.policy",
                    "desired": "HTTPS_ONLY",
                    "site": "hdfs-site"
                  }
                ]
              },
              "links": [
                {
                  "name": "namenode_ui",
                  "label": "NameNode UI",
                  "url": "%@://%@:%@",
                  "port": {
                    "regex": "\\w*:(\\d+)",
                    "site": "hdfs-site",
                    "http_property": "dfs.namenode.http-address",
                    "http_default_port": "50070",
                    "https_property": "dfs.namenode.https-address",
                    "https_default_port": "50470"
                  },
                  "visible": true,
                  "removed": false,
                  "component_name": "NAMENODE",
                  "requires_user_name": "false"
                },
                {
                  "name": "namenode_logs",
                  "label": "NameNode Logs",
                  "url": "%@://%@:%@/logs",
                  "port": {
                    "regex": "\\w*:(\\d+)",
                    "site": "hdfs-site",
                    "http_property": "dfs.namenode.http-address",
                    "http_default_port": "50070",
                    "https_property": "dfs.namenode.https-address",
                    "https_default_port": "50470"
                  },
                  "visible": true,
                  "removed": false,
                  "component_name": "NAMENODE",
                  "requires_user_name": "false"
                },
                {
                  "name": "namenode_jmx",
                  "label": "NameNode JMX",
                  "url": "%@://%@:%@/jmx",
                  "port": {
                    "regex": "\\w*:(\\d+)",
                    "site": "hdfs-site",
                    "http_property": "dfs.namenode.http-address",
                    "http_default_port": "50070",
                    "https_property": "dfs.namenode.https-address",
                    "https_default_port": "50470"
                  },
                  "visible": true,
                  "removed": false,
                  "component_name": "NAMENODE",
                  "requires_user_name": "false"
                },
                {
                  "name": "Thread Stacks",
                  "label": "Thread Stacks",
                  "url": "%@://%@:%@/stacks",
                  "port": {
                    "regex": "\\w*:(\\d+)",
                    "site": "hdfs-site",
                    "http_property": "dfs.namenode.http-address",
                    "http_default_port": "50070",
                    "https_property": "dfs.namenode.https-address",
                    "https_default_port": "50470"
                  },
                  "visible": true,
                  "removed": false,
                  "component_name": "NAMENODE",
                  "requires_user_name": "false"
                }
              ]
            }
          }
        }
      }
    }
  ]
}
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

# 3.1.2 触发程序追踪

# 3.1.2.1 前端触发点

QuickLinks 的 API 调用实际上是由前端 JS 逻辑自动发起。开发/运维如需追溯或自定义,可参考如下主干函数(典型为 Ember/Handlebars 体系,以下为伪代码简化版):

image-20241231104304926

// 获取当前服务所有 QuickLinks 组件名和主机名
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();

    if (hosts.length === 0) {
        return $.Deferred().reject().promise();
    }

    // 触发 ajax 请求
    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'
    });
}
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
  • App.QuickLinksConfig.find() 获取 QuickLinks 模板配置
  • App.ajax.send() 触发后端接口,携带主机与组件等参数
  • setQuickLinksSuccessCallback 为处理 QuickLinks 成功返回的回调

image-20241231104522722

# 3.1.2.2 推导请求来源

通过接口返回中的 QuickLinksConfiguration 字段,实际的 QuickLinks 配置模板均直接来源于 stacks 目录下的 JSON 文件。例如:

  • 文件路径:stacks/BIGTOP/3.1.0/services/HDFS/quicklinks.json
  • 文件内容结构:

image-20241231103006150

笔记

QuickLinks 的可维护性极强——只需修改 stacks 下 JSON 配置,前端 UI 自动适配,无需任何重启或二次开发。这正是大数据平台“高可观测性”与“低代码运维”的核心体现。

#Ambari#源码解析#metainfo
quicklinks详解[一]
quicklinks详解[三]

← quicklinks详解[一] quicklinks详解[三]→

最近更新
01
当前版本 2026/08
08-29
02
把 Ambari Server HA 稳稳地跑起来
08-17
03
从一次启用操作追到主备就绪
08-17
更多文章>
Theme by Vdoing | Copyright © 2017-2026 JaneTTR | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式