GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #123 from markwei-ucloud/feature/1797 · ucloud/ucloud-cli@306215f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cmd
    • products.gen.go
  • products/uhadoop
    • TEST.md
    • internal/uhadoop
      • add_node.go
      • cmd.go
      • create.go
      • delete.go
      • describe.go
      • list.go
      • list_framework_app.go
      • list_node_type.go
      • poll.go
      • restart_service.go
      • rows.go
      • status.go
      • upgrade_disk.go
      • upgrade_node.go
    • product.go
    • product.yaml
    • testdata
      • cmdtree.golden
      • completion.golden
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/products.gen.go‎

Copy file name to clipboardExpand all lines: cmd/products.gen.go
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎products/uhadoop/TEST.md‎

Copy file name to clipboard
+241Lines changed: 241 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
## UHadoop CLI 测试清单
2+
3+
### 准备工作
4+
5+
```bash
6+
# 1. 确认凭据已配置
7+
ucloud config list
8+
9+
# 2. 查看可用地域
10+
ucloud region
11+
12+
13+
# 3. 替换测试参数
14+
# --region cn-bj2 --zone cn-bj2-02
15+
```
16+
17+
---
18+
19+
### 一、查询命令
20+
21+
#### 1.1 list-framework-app — 查询框架和应用
22+
23+
```bash
24+
go run . uhadoop list-framework-app --region <region> --zone <zone>
25+
go run . uhadoop list-framework-app --region <region> --zone <zone> --output json
26+
```
27+
28+
#### 1.2 list-node-type — 查询可用机型
29+
30+
```bash
31+
go run . uhadoop list-node-type --region <region> --zone <zone>
32+
go run . uhadoop list-node-type --region <region> --zone <zone> --node-role master
33+
go run . uhadoop list-node-type --region <region> --zone <zone> --framework Hadoop --framework-version 3.3.4-udh3.2
34+
```
35+
36+
#### 1.3 list — 列出集群
37+
38+
```bash
39+
go run . uhadoop list --region <region>
40+
go run . uhadoop list --region <region> --zone <zone> --limit 5
41+
go run . uhadoop list --region <region> --id-only
42+
go run . uhadoop list --all-region --output json
43+
```
44+
45+
#### 1.4 describe — 查询集群详情
46+
47+
```bash
48+
go run . uhadoop describe <instance-id> --region <region> --zone <zone>
49+
go run . uhadoop describe <instance-id> --region <region> --zone <zone> --output json
50+
```
51+
52+
---
53+
54+
### 二、修改命令
55+
56+
> ⚠️ 会对真实资源产生修改
57+
58+
#### 2.1 create — 创建集群
59+
60+
| 参数 | 必填 | 说明 |
61+
|------|:--:|------|
62+
| `--region` | ✅ | 地域 |
63+
| `--zone` | ✅ | 可用区 |
64+
| `--name` | ✅ | 集群名称 |
65+
| `--framework` | ✅ | Hadoop / HDFS / MR / StarRocks-* |
66+
| `--framework-version` | ✅ | 如 `3.3.4-udh3.2` |
67+
| `--password` | ✅ | 登录密码(明文,自动 base64) |
68+
| `--master-node-type` | | Master 机型,默认 `o.hadoop4m.xlarge` |
69+
| `--core-node-type` | | Core 机型,默认 `o.hadoop2m.xlarge` |
70+
| `--task-node-type` | | Task 机型(可选) |
71+
| `--master-count` | | 默认 2(StarRocks 默认 3) |
72+
| `--core-count` | | 默认 3 |
73+
| `--task-count` | | 默认 0 |
74+
| `--cluster-case` | | Spark / Hbase / Core-Hadoop |
75+
| `--app-config` | | 手动指定组件,格式 `App#Version` |
76+
| `--master-boot-disk-size` | | 系统盘 GB,默认 50 |
77+
| `--master-data-disk-size` | | 数据盘 GB,默认 100 |
78+
| `--core-boot-disk-size` | | 系统盘 GB,默认 50 |
79+
| `--core-data-disk-size` | | 数据盘 GB,默认 200 |
80+
| `--vpc-id` | | 可选 |
81+
| `--subnet-id` | | 可选 |
82+
| `--async` | | 异步模式,不等待创建完成 |
83+
84+
```bash
85+
# Spark 模板创建
86+
go run . uhadoop create \
87+
--region <region> --zone <zone> \
88+
--name test-spark --framework Hadoop \
89+
--framework-version 3.3.4-udh3.2 \
90+
--password 'YourPass123!' \
91+
--cluster-case Spark
92+
93+
# 手动指定 app-config
94+
go run . uhadoop create \
95+
--region <region> --zone <zone> \
96+
--name test-manual --framework Hadoop \
97+
--framework-version 3.3.4-udh3.2 \
98+
--password 'YourPass123!' \
99+
--app-config Spark#3.5.3 --app-config Hive#3.1.3
100+
101+
# MR 集群(需要 --storage-cluster-id)
102+
go run . uhadoop create \
103+
--region <region> --zone <zone> \
104+
--name test-mr --framework MR \
105+
--framework-version 3.3.4-udh3.2 \
106+
--password 'YourPass123!' \
107+
--storage-cluster-id <id> \
108+
--cluster-case Spark
109+
```
110+
111+
#### 2.2 delete — 删除集群
112+
113+
| 参数 | 必填 | 说明 |
114+
|------|:--:|------|
115+
| `<instance-id>` | ✅ | 位置参数 |
116+
| `--region` | ✅ | 地域 |
117+
| `--zone` | ✅ | 可用区 |
118+
| `--release-eip` | | 释放 EIP |
119+
| `--yes` / `-y` | | 跳过确认 |
120+
121+
```bash
122+
go run . uhadoop delete <instance-id> --region <region> --zone <zone>
123+
go run . uhadoop delete <instance-id> --region <region> --zone <zone> --release-eip -y
124+
```
125+
126+
#### 2.3 add-node — 扩容节点
127+
128+
| 参数 | 必填 | 说明 |
129+
|------|:--:|------|
130+
| `--region` | ✅ | 地域 |
131+
| `--zone` | ✅ | 可用区 |
132+
| `--instance-id` | ✅ | 集群 ID |
133+
| `--node-role` | ✅ | core / task / client |
134+
| `--node-type` | ✅ | 机型 |
135+
| `--node-count` | | 默认 1 |
136+
| `--password` | | Client 角色需要(明文) |
137+
| `--boot-disk-size` | | 系统盘 GB,默认 50 |
138+
| `--data-disk-size` | | 数据盘 GB,默认 200 |
139+
| `--async` | | 异步模式 |
140+
141+
```bash
142+
go run . uhadoop add-node \
143+
--region <region> --zone <zone> \
144+
--instance-id <id> --node-role core \
145+
--node-type o.hadoop2m.xlarge
146+
```
147+
148+
#### 2.4 restart-service — 启停服务
149+
150+
| 参数 | 必填 | 说明 |
151+
|------|:--:|------|
152+
| `--region` | ✅ | 地域 |
153+
| `--zone` | ✅ | 可用区 |
154+
| `--instance-id` | ✅ | 集群 ID |
155+
| `--service-name` | ✅ | 服务名 |
156+
| `--only-start` / `--only-stop` | | 只启/只停 |
157+
| `--yes` / `-y` | | 跳过确认 |
158+
159+
```bash
160+
go run . uhadoop restart-service \
161+
--region <region> --zone <zone> \
162+
--instance-id <id> --service-name Hive
163+
```
164+
165+
#### 2.5 upgrade-node — 升级节点
166+
167+
| 参数 | 必填 | 说明 |
168+
|------|:--:|------|
169+
| `--region` | ✅ | 地域 |
170+
| `--zone` | ✅ | 可用区 |
171+
| `--instance-id` | ✅ | 集群 ID |
172+
| `--node-role` | ✅ | master / core / task / client |
173+
| `--node-type` | ✅ | 新机型 |
174+
| `--node-name` | | 节点名(非 master 必填) |
175+
| `--yes` / `-y` | | 跳过确认 |
176+
177+
```bash
178+
go run . uhadoop upgrade-node \
179+
--region <region> --zone <zone> \
180+
--instance-id <id> --node-role master \
181+
--node-type o.hadoop2m.xlarge
182+
```
183+
184+
#### 2.6 upgrade-disk — 扩容磁盘
185+
186+
| 参数 | 必填 | 说明 |
187+
|------|:--:|------|
188+
| `--region` | ✅ | 地域 |
189+
| `--zone` | ✅ | 可用区 |
190+
| `--instance-id` | ✅ | 集群 ID |
191+
| `--node-role` | ✅ | master / core / task / client |
192+
| `--data-disk-size` | ✅ | 新数据盘大小 GB |
193+
| `--boot-disk-size` | | 新系统盘大小 GB |
194+
| `--node-name` | | 节点名(非 master 必填) |
195+
| `--yes` / `-y` | | 跳过确认 |
196+
197+
```bash
198+
go run . uhadoop upgrade-disk \
199+
--region <region> --zone <zone> \
200+
--instance-id <id> --node-role core \
201+
--data-disk-size 500 --node-name <id>-core1
202+
```
203+
204+
---
205+
206+
### 三、校验
207+
208+
```bash
209+
# 编译
210+
go build ./...
211+
212+
# golden 测试
213+
GOROOT=/Users/user/.g/go GOTOOLCHAIN=local go test ./hack/snapshot -v -run 'uhadoop'
214+
215+
# 缺参立即报错
216+
go run . uhadoop create --name test
217+
# → required flag(s) "framework", "framework-version", "password", "region", "zone" not set
218+
```
219+
220+
---
221+
222+
### 测试结果
223+
224+
| # | 命令 | 状态 |
225+
|---|------|------|
226+
| 1 | `list-framework-app` | ✅ |
227+
| 2 | `list-node-type` | ✅ |
228+
| 3 | `list` | ✅ |
229+
| 4 | `describe` | ✅ |
230+
| 5 | `create --cluster-case Spark` | ✅ |
231+
| 6 | `create --app-config ...` | ✅ |
232+
| 7 | `delete` | ✅ |
233+
| 8 | `add-node` | ✅ |
234+
| 9 | `restart-service` | ✅ |
235+
| 10 | `upgrade-node` | ✅ |
236+
| 11 | `upgrade-disk` | ✅ |
237+
| 12 | `create` 缺参 | ✅ |
238+
| 13 | `go build ./...` | ✅ |
239+
| 14 | `go test ./hack/snapshot -v` | ✅ |
240+
241+
> ⬜ = 待测试 &ensp; ✅ = 通过 &ensp; ❌ = 失败
Collapse file

‎products/uhadoop/internal/uhadoop/add_node.go‎

Copy file name to clipboard
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package uhadoop
2+
3+
import (
4+
"encoding/base64"
5+
"fmt"
6+
"time"
7+
8+
"github.com/spf13/cobra"
9+
sdk "github.com/ucloud/ucloud-sdk-go/ucloud"
10+
11+
uhadoopsdk "github.com/ucloud/ucloud-sdk-go/services/uhadoop"
12+
13+
"github.com/ucloud/ucloud-cli/pkg/cli"
14+
"github.com/ucloud/ucloud-cli/pkg/command"
15+
)
16+
17+
func newAddNode(ctx *cli.Context) *cobra.Command {
18+
var (
19+
async *bool
20+
rawPassword string
21+
)
22+
client := cli.NewServiceClient(ctx, uhadoopsdk.NewClient)
23+
req := client.NewAddUHadoopInstanceNodeRequest()
24+
cmd := &cobra.Command{
25+
Use: "add-node",
26+
Short: "Add nodes to a UHadoop cluster",
27+
Long: `Add a number of nodes to an existing UHadoop cluster`,
28+
SilenceUsage: true,
29+
Run: func(cmd *cobra.Command, args []string) {
30+
w := ctx.ProgressWriter()
31+
if rawPassword != "" {
32+
req.Password = sdk.String(base64.StdEncoding.EncodeToString([]byte(rawPassword)))
33+
}
34+
resp, err := client.AddUHadoopInstanceNode(req)
35+
if err != nil {
36+
ctx.HandleError(err)
37+
return
38+
}
39+
if resp.RetCode != 0 {
40+
ctx.HandleError(fmt.Errorf("[%d] %s", resp.RetCode, resp.Message))
41+
return
42+
}
43+
text := fmt.Sprintf("uhadoop[%s] adding %d %s node(s)", *req.InstanceId, *req.NodeCount, *req.NodeRole)
44+
if *async {
45+
fmt.Fprintln(w, text)
46+
} else {
47+
ctx.PollerTo(w, describeClusterForPoll(ctx, client), cli.WithTimeout(60*time.Minute)).Spoll(*req.InstanceId, text, []string{stateRunning})
48+
}
49+
ctx.EmitResult(cli.OpResultRow{ResourceID: *req.InstanceId, Action: "add-node", Status: "Scaling"})
50+
},
51+
}
52+
flags := cmd.Flags()
53+
flags.SortFlags = false
54+
req.Region = flags.String("region", ctx.DefaultRegion(), "Optional. Assign region")
55+
req.Zone = flags.String("zone", "", "Optional. Assign availability zone")
56+
req.ProjectId = flags.String("project-id", ctx.DefaultProjectID(), "Optional. Assign project-id")
57+
req.InstanceId = flags.String("instance-id", "", "Required. Cluster instance ID")
58+
req.NodeRole = flags.String("node-role", "", "Required. Node role: core|task|client")
59+
req.NodeType = flags.String("node-type", "", "Required. Node type")
60+
req.NodeCount = flags.Int("node-count", 1, "Number of nodes, default 1")
61+
flags.StringVar(&rawPassword, "password", "", "Login password (client role requires)")
62+
req.BootDiskSize = flags.String("boot-disk-size", "50", "Boot disk GB, default 50")
63+
req.BootDiskType = flags.String("boot-disk-type", "CLOUD_RSSD", "Boot disk type, default CLOUD_RSSD")
64+
req.DataDiskSize = flags.String("data-disk-size", "200", "Data disk GB, default 200")
65+
req.DataDiskNum = flags.String("data-disk-num", "1", "Data disk num, default 1")
66+
req.DataDiskType = flags.String("data-disk-type", "CLOUD_RSSD", "Data disk type, default CLOUD_RSSD")
67+
async = flags.Bool("async", false, "Optional. Do not wait for node addition to finish")
68+
command.SetFlagValues(cmd, "node-role", "core", "task", "client")
69+
cmd.MarkFlagRequired("instance-id")
70+
cmd.MarkFlagRequired("node-role")
71+
cmd.MarkFlagRequired("node-type")
72+
cmd.MarkFlagRequired("region")
73+
cmd.MarkFlagRequired("zone")
74+
return cmd
75+
}
Collapse file

‎products/uhadoop/internal/uhadoop/cmd.go‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package uhadoop
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/ucloud/ucloud-cli/pkg/cli"
7+
)
8+
9+
// NewCommand builds the top-level `uhadoop` command.
10+
func NewCommand(ctx *cli.Context) *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "uhadoop",
13+
Short: "List,create,delete,describe UHadoop clusters and manage nodes and services",
14+
Long: `List,create,delete,describe UHadoop clusters and manage nodes and services`,
15+
Args: cobra.NoArgs,
16+
}
17+
cmd.AddCommand(newList(ctx))
18+
cmd.AddCommand(newDescribe(ctx))
19+
cmd.AddCommand(newCreate(ctx))
20+
cmd.AddCommand(newDelete(ctx))
21+
cmd.AddCommand(newAddNode(ctx))
22+
cmd.AddCommand(newListNodeType(ctx))
23+
cmd.AddCommand(newListFrameworkApp(ctx))
24+
cmd.AddCommand(newRestartService(ctx))
25+
cmd.AddCommand(newUpgradeNode(ctx))
26+
cmd.AddCommand(newUpgradeDisk(ctx))
27+
return cmd
28+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.