diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8af2eba --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,153 @@ +name: Build and Release + +on: + push: + branches: [ main, develop ] + tags: [ 'v*' ] + pull_request: + branches: [ main ] + +env: + GO_VERSION: '1.25' + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod download + + - name: Run tests + run: go test -v ./... + + - name: Run go vet + run: go vet ./... + + - name: Run go fmt check + run: | + if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then + echo "Code is not formatted properly:" + gofmt -s -l . + exit 1 + fi + + build: + name: Build + runs-on: ubuntu-latest + needs: test + strategy: + matrix: + goos: [ linux, darwin, windows ] + goarch: [ amd64, arm64 ] + exclude: + - goos: windows + goarch: arm64 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Get build info + id: build_info + run: | + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + echo "build_time=$(date '+%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT + echo "git_commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + if [[ $GITHUB_REF == refs/tags/* ]]; then + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + else + echo "version=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + fi + + - name: Build binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + VERSION: ${{ steps.build_info.outputs.version }} + BUILD_TIME: ${{ steps.build_info.outputs.build_time }} + GIT_COMMIT: ${{ steps.build_info.outputs.git_commit }} + run: | + mkdir -p dist + binary_name="stargo-${{ matrix.goos }}-${{ matrix.goarch }}" + if [ "${{ matrix.goos }}" = "windows" ]; then + binary_name="${binary_name}.exe" + fi + + go build -ldflags "-w -s -X 'main.Version=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GitCommit=${GIT_COMMIT}'" \ + -o "dist/${binary_name}" . + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: stargo-${{ matrix.goos }}-${{ matrix.goarch }} + path: dist/stargo-${{ matrix.goos }}-${{ matrix.goarch }}* + + release: + name: Release + runs-on: ubuntu-latest + needs: build + if: startsWith(github.ref, 'refs/tags/') + + steps: + - uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v3 + with: + path: dist + + - name: Prepare release assets + run: | + mkdir -p release + cd dist + for dir in */; do + cd "$dir" + if [[ -f *.exe ]]; then + zip "../../release/${dir%/}.zip" * + else + tar -czf "../../release/${dir%/}.tar.gz" * + fi + cd .. + done + cd .. + ls -la release/ + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + files: release/* + draft: false + prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }} + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db9cb5e --- /dev/null +++ b/.gitignore @@ -0,0 +1,75 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Build artifacts +/dist/ +/release/ +stargo +stargo-* +*.tar.gz +*.zip + +# Logs +*.log + +# Temporary files +tmp/ +temp/ + +# Environment files +.env +.env.local +.env.*.local + +# Coverage reports +coverage.txt +coverage.html + +# Profiling data +*.prof + +# Debug files +debug +*.debug + +# Local configuration files +config.local.* + +# Backup files +*.bak +*.backup + +# Package files +*.pkg.tar.xz \ No newline at end of file diff --git a/BUILD_GUIDE.md b/BUILD_GUIDE.md new file mode 100644 index 0000000..77e22ce --- /dev/null +++ b/BUILD_GUIDE.md @@ -0,0 +1,273 @@ +# StarGo 构建指南 + +本文档详细说明如何构建和打包 StarGo - StarRocks 集群管理工具。 + +## 🎯 项目概述 + +StarGo 是一个用 Go 语言开发的 StarRocks 集群管理工具,提供以下功能: + +- 🚀 **集群部署**: 快速部署 StarRocks 集群 +- 🔧 **集群管理**: 启动、停止、升级、降级集群 +- 📊 **状态监控**: 实时查看集群状态和节点信息 +- 🔄 **弹性伸缩**: 支持集群扩容和缩容 +- 🎮 **Playground**: 快速启动测试环境 + +## 📋 构建要求 + +### 系统要求 + +- Go 1.25+ +- Make (可选,用于 Makefile 构建) +- Git (用于版本信息) + +### 依赖包 + +项目依赖以下 Go 包: + +- `github.com/go-sql-driver/mysql v1.9.3` +- `github.com/pkg/sftp v1.13.10` +- `golang.org/x/crypto v0.43.0` +- `gopkg.in/yaml.v2 v2.4.0` + +## 🔧 构建方法 + +### 方法1: 使用 Makefile (推荐) + +```bash +# 构建当前平台版本 +make build + +# 构建所有平台版本 +make build-all + +# 构建并设置版本号 +make build VERSION=1.0.0 + +# 查看所有可用命令 +make help +``` + +### 方法2: 使用构建脚本 + +```bash +# 给脚本执行权限 +chmod +x build.sh + +# 运行构建脚本 +./build.sh + +# 设置版本号 +VERSION=1.0.0 ./build.sh +``` + +### 方法3: 直接使用 Go 命令 + +```bash +# 简单构建 +go build -o stargo . + +# 带版本信息的构建 +go build -ldflags "-X 'main.Version=1.0.0' -X 'main.BuildTime=$(date '+%Y-%m-%d %H:%M:%S')' -X 'main.GitCommit=$(git rev-parse --short HEAD)'" -o stargo . + +# 交叉编译示例 +GOOS=linux GOARCH=amd64 go build -o stargo-linux-amd64 . +GOOS=windows GOARCH=amd64 go build -o stargo-windows-amd64.exe . +GOOS=darwin GOARCH=amd64 go build -o stargo-darwin-amd64 . +``` + +## 📦 支持的平台 + +StarGo 支持以下平台的交叉编译: + +| 操作系统 | 架构 | 文件名 | +|---------|-------|----------------------------| +| Linux | amd64 | `stargo-linux-amd64` | +| Linux | arm64 | `stargo-linux-arm64` | +| macOS | amd64 | `stargo-darwin-amd64` | +| macOS | arm64 | `stargo-darwin-arm64` | +| Windows | amd64 | `stargo-windows-amd64.exe` | + +## 🏗️ 构建产物 + +构建完成后,会生成以下文件: + +``` +stargo/ +├── stargo # 当前平台可执行文件 +├── dist/ # 所有平台构建产物 +│ ├── stargo-linux-amd64 +│ ├── stargo-linux-arm64 +│ ├── stargo-darwin-amd64 +│ ├── stargo-darwin-arm64 +│ └── stargo-windows-amd64.exe +└── release/ # 发布包 (使用 make release) + ├── stargo-v1.0.0-linux-amd64.tar.gz + ├── stargo-v1.0.0-linux-arm64.tar.gz + ├── stargo-v1.0.0-darwin-amd64.tar.gz + ├── stargo-v1.0.0-darwin-arm64.tar.gz + └── stargo-v1.0.0-windows-amd64.zip +``` + +## 🔍 版本信息 + +StarGo 支持在构建时注入版本信息: + +- **Version**: 版本号 (通过 `main.Version` 注入) +- **BuildTime**: 构建时间 (通过 `main.BuildTime` 注入) +- **GitCommit**: Git 提交哈希 (通过 `main.GitCommit` 注入) + +查看版本信息: + +```bash +./stargo version +``` + +输出示例: + +``` +stargo version 1.0.0 +Build time: 2025-10-27 11:09:35 +Git commit: e792373 +Go version: 1.25.0 +``` + +## 🚀 快速开始 + +### 1. 克隆仓库 + +```bash +git clone https://github.com/your-username/stargo.git +cd stargo +``` + +### 2. 安装依赖 + +```bash +go mod download +``` + +### 3. 构建 + +```bash +make build +``` + +### 4. 测试 + +```bash +./stargo version +./stargo help +``` + +## 📋 Makefile 目标 + +| 目标 | 描述 | +|--------------|-------------| +| `build` | 构建当前平台版本 | +| `build-all` | 构建所有平台版本 | +| `build-fast` | 快速构建(无版本信息) | +| `test` | 运行测试 | +| `fmt` | 格式化代码 | +| `vet` | 代码检查 | +| `deps` | 下载依赖 | +| `clean` | 清理构建文件 | +| `install` | 安装到系统 | +| `uninstall` | 从系统卸载 | +| `release` | 创建发布包 | +| `help` | 显示帮助信息 | + +## 🔧 开发工作流 + +### 日常开发 + +```bash +# 下载依赖 +make deps + +# 格式化代码 +make fmt + +# 代码检查 +make vet + +# 运行测试 +make test + +# 构建测试 +make build +``` + +### 发布流程 + +```bash +# 1. 更新版本号 +export VERSION=v1.0.0 + +# 2. 构建所有平台 +make build-all VERSION=$VERSION + +# 3. 创建发布包 +make release VERSION=$VERSION + +# 4. 测试构建产物 +./dist/stargo-linux-amd64 version +``` + +## 🐛 故障排除 + +### 网络问题 + +如果遇到依赖下载问题,可以设置 Go 代理: + +```bash +export GOPROXY=https://goproxy.cn,direct +go mod download +``` + +### 权限问题 + +如果安装时遇到权限问题: + +```bash +# 使用 sudo 安装 +sudo make install + +# 或安装到用户目录 +mkdir -p ~/bin +cp stargo ~/bin/ +export PATH=$PATH:~/bin +``` + +### 交叉编译问题 + +确保目标平台的 Go 工具链已安装: + +```bash +# 查看支持的平台 +go tool dist list + +# 安装特定平台工具链 +GOOS=windows GOARCH=amd64 go install std +``` + +## 📚 相关文档 + +- [README.md](README.md) - 项目介绍和使用说明 +- [install.sh](install.sh) - 自动安装脚本 +- [build.sh](build.sh) - 构建脚本 +- [Makefile](Makefile) - Make 构建文件 + +## 🤝 贡献 + +欢迎提交 Issue 和 Pull Request! + +构建相关的改进建议: + +1. 优化构建速度 +2. 添加更多平台支持 +3. 改进版本管理 +4. 增强错误处理 + +## 📄 许可证 + +本项目采用 MIT 许可证。 \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b0bdc81 --- /dev/null +++ b/Makefile @@ -0,0 +1,123 @@ +# stargo 项目 Makefile + +# 项目信息 +PROJECT_NAME := stargo +VERSION ?= v2.4.0 +BUILD_TIME := $(shell date '+%Y-%m-%d %H:%M:%S') +GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") + +# Go 构建参数 +LDFLAGS := -ldflags "-X 'main.Version=$(VERSION)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)'" +GOFLAGS := -v + +# 默认目标 +.PHONY: all +all: build + +# 构建当前平台版本 +.PHONY: build +build: + @echo "构建 $(PROJECT_NAME) $(VERSION)..." + go build $(GOFLAGS) $(LDFLAGS) -o $(PROJECT_NAME) . + @echo "构建完成: $(PROJECT_NAME)" + +# 构建 Linux amd64 版本 +.PHONY: build-all +build-all: clean + @echo "构建 Linux amd64 版本..." + @mkdir -p dist + + @echo "构建 Linux amd64..." + GOOS=linux GOARCH=amd64 go build $(GOFLAGS) $(LDFLAGS) -o dist/$(PROJECT_NAME)-linux-amd64 . + + @echo "Linux amd64 构建完成!" + @ls -la dist/ + +# 快速构建(不包含版本信息) +.PHONY: build-fast +build-fast: + @echo "快速构建..." + go build -o $(PROJECT_NAME) . + +# 运行测试 +.PHONY: test +test: + @echo "运行测试..." + go test -v ./... + +# 代码格式化 +.PHONY: fmt +fmt: + @echo "格式化代码..." + go fmt ./... + +# 代码检查 +.PHONY: vet +vet: + @echo "代码检查..." + go vet ./... + +# 下载依赖 +.PHONY: deps +deps: + @echo "下载依赖..." + go mod download + go mod tidy + +# 清理构建文件 +.PHONY: clean +clean: + @echo "清理构建文件..." + rm -f $(PROJECT_NAME) + rm -rf dist/ + +# 安装到系统 +.PHONY: install +install: build + @echo "安装到系统..." + sudo cp $(PROJECT_NAME) /usr/local/bin/ + @echo "安装完成,可以使用 'stargo' 命令" + +# 卸载 +.PHONY: uninstall +uninstall: + @echo "从系统卸载..." + sudo rm -f /usr/local/bin/$(PROJECT_NAME) + @echo "卸载完成" + +# 创建发布包 +.PHONY: release +release: build-all + @echo "创建发布包..." + @mkdir -p release + + # 创建 tar.gz 包 + cd dist && tar -czf ../release/$(PROJECT_NAME)-$(VERSION)-linux-amd64.tar.gz $(PROJECT_NAME)-linux-amd64 + + @echo "发布包创建完成:" + @ls -la release/ + +# 显示帮助信息 +.PHONY: help +help: + @echo "stargo 项目构建命令:" + @echo "" + @echo " make build - 构建当前平台版本" + @echo " make build-all - 构建 Linux amd64 版本" + @echo " make build-fast - 快速构建(无版本信息)" + @echo " make test - 运行测试" + @echo " make fmt - 格式化代码" + @echo " make vet - 代码检查" + @echo " make deps - 下载依赖" + @echo " make clean - 清理构建文件" + @echo " make install - 安装到系统" + @echo " make uninstall - 从系统卸载" + @echo " make release - 创建发布包" + @echo " make help - 显示此帮助信息" + @echo "" + @echo "环境变量:" + @echo " VERSION=x.x.x - 设置版本号" + @echo "" + @echo "示例:" + @echo " make build VERSION=1.0.0" + @echo " make build-all VERSION=1.0.0" \ No newline at end of file diff --git a/README.md b/README.md index 0fcb94a..78804ce 100644 --- a/README.md +++ b/README.md @@ -1 +1,153 @@ -# stargo \ No newline at end of file +# StarGo + +StarGo is a StarRocks deployment and cluster management tool. This branch restores the old stargo codebase for modern StarRocks versions and adds shared-data support through FE + CN deployments. + +## Current Scope + +Supported and validated: + +- StarRocks 3.5.15 shared-nothing, 1FE + 1BE, ubuntu-amd64 +- StarRocks 4.0.0 shared-data, 1FE + 1CN + MinIO, ubuntu-amd64 +- StarRocks 4.0.0 shared-data, 3FE + 2CN + MinIO, ubuntu-amd64 +- CN deploy, display, start, stop, scale-in, scale-out, and import metadata handling +- Shared-data readiness checks after deploy and role-level CN start + +Compatibility targets not yet fully validated: + +- Additional 3.x versions +- Latest 4.x stable beyond 4.0.0 +- CentOS packages + +## Build And Test + +```bash +go test ./... +go build ./... +``` + +CI runs: + +- `gofmt` +- `go test ./...` +- `go build ./...` + +## Deploy Shared-Data + +Shared-data mode uses FE + CN. Do not configure BE nodes for a normal shared-data deployment. + +```bash +stargo cluster deploy sr-sd v4.0.0 deploy-template.yaml +stargo cluster display sr-sd +``` + +FE config must include: + +```yaml +config: + run_mode: "shared_data" + cloud_native_meta_port: "6090" +``` + +CN nodes use the StarRocks BE package layout, with `be/conf/cn.conf` and `be/bin/start_cn.sh`. + +Object storage is required by StarRocks shared-data. Configure the storage volume settings in FE config according to your StarRocks version and object storage provider. The Multipass validation used MinIO. + +After deploy, stargo waits for: + +- CN nodes to report `Alive=true` +- a minimal CRUD probe to succeed + +If readiness times out, the command exits nonzero. + +## Deploy Shared-Nothing + +Shared-nothing mode uses FE + BE. + +```bash +stargo cluster deploy sr-sn v3.5.15 shared-nothing.yaml +stargo cluster display sr-sn +``` + +Do not set FE `run_mode: shared_data` for shared-nothing clusters. + +## Daily Operations + +```bash +stargo cluster display sr-sd +stargo cluster start sr-sd +stargo cluster stop sr-sd +stargo cluster start sr-sd -role CN +stargo cluster stop sr-sd -role CN +stargo cluster start sr-sd -node +stargo cluster stop sr-sd -node +``` + +Shared-data clusters reject BE role operations because BE is not part of the FE + CN architecture. + +CN start and stop operations aggregate per-node errors. If any CN cannot be reached or does not reach the expected state, the command exits nonzero. + +## Import + +```bash +stargo cluster import sr-imported import.yaml +stargo cluster display sr-imported +``` + +Import reads runtime FE/CN metadata where available, but preserves user-provided data and log directories from YAML: + +- FE `meta_dir` +- FE `log_dir` +- CN `storage_dir` +- CN `log_dir` + +This avoids replacing intentional deployment paths with runtime defaults reported by `/variable` or `/varz`. + +## Upgrade And Downgrade + +Shared-nothing clusters keep the existing FE + BE upgrade path. + +Shared-data clusters now avoid the BE path and process: + +1. FE nodes +2. CN nodes +3. shared-data readiness + +The implementation performs library replacement in place and restarts nodes. It does not perform StarRocks metadata migrations or guarantee arbitrary cross-version compatibility. Follow the official StarRocks upgrade notes before using this on production data. + +Downgrade follows the same boundary. Use it only when the target StarRocks version officially supports the downgrade path. + +## Validation Matrix + +See `docs/validation/version-matrix.md`. + +Manual Multipass helper scripts: + +```bash +scripts/validate-multipass-shared-data.sh +scripts/validate-multipass-shared-nothing.sh +``` + +These scripts intentionally leave SQL CRUD checks as an explicit operator step because FE query ports may not be exposed on every validation host. + +## Known Boundaries + +- Default CI does not start real StarRocks processes. +- CentOS packages are not yet part of the P0 validation record. +- Object storage failures are surfaced through readiness errors, but stargo does not provision object storage. +- Upgrade and downgrade do not replace official StarRocks release-note checks. + +## Official Release URLs + +Ubuntu examples: + +- https://releases.starrocks.io/starrocks/StarRocks-4.0.0-ubuntu-amd64.tar.gz +- https://releases.starrocks.io/starrocks/StarRocks-3.5.8-ubuntu-amd64.tar.gz +- https://releases.starrocks.io/starrocks/StarRocks-3.4.8-ubuntu-amd64.tar.gz +- https://releases.starrocks.io/starrocks/StarRocks-3.3.19-ubuntu-amd64.tar.gz + +CentOS examples: + +- https://releases.starrocks.io/starrocks/StarRocks-4.0.0-centos-amd64.tar.gz +- https://releases.starrocks.io/starrocks/StarRocks-3.5.8-centos-amd64.tar.gz +- https://releases.starrocks.io/starrocks/StarRocks-3.4.8-centos-amd64.tar.gz +- https://releases.starrocks.io/starrocks/StarRocks-3.3.19-centos-amd64.tar.gz diff --git a/README.template.md b/README.template.md new file mode 100644 index 0000000..faff515 --- /dev/null +++ b/README.template.md @@ -0,0 +1,60 @@ +# StarGo {{VERSION}} + +StarGo 是一个用于 StarRocks 集群部署和管理的工具。 + +## 版本信息 + +- **版本**: {{VERSION}} +- **构建时间**: {{BUILD_TIME}} +- **Git 提交**: {{GIT_COMMIT}} +- **Go 版本**: 1.25.0 + +## 文件说明 + +- `{{PROJECT_NAME}}`: StarGo 主程序(Linux amd64 版本) +- `deploy-template.yaml`: 部署模板配置文件 +- `repo.yaml`: 仓库配置文件 +- `env_check.sh`: 环境检查脚本 +- `README.md`: 本说明文件 + +## 快速开始 + +1. **检查环境**: + ```bash + ./env_check.sh + ``` + +2. **查看版本信息**: + ```bash + ./{{PROJECT_NAME}} version + ``` + +3. **查看帮助信息**: + ```bash + ./{{PROJECT_NAME}} --help + ``` + +4. **部署 shared-data 集群**: + ```bash + ./{{PROJECT_NAME}} cluster deploy sr-c1 v4.0.0 deploy-template.yaml + ``` + +5. **查看集群状态**: + ```bash + ./{{PROJECT_NAME}} cluster display sr-c1 + ``` + +## 重要说明 + +- 当前模板默认按官方 shared-data 模型组织,即 `FE + CN` +- shared-data 模式下,`FE` 需要 `run_mode = shared_data` +- `CN` 使用 StarRocks 的 `BE` 部署文件,并使用 `be/conf/cn.conf` 与 `be/bin/start_cn.sh` +- 真实环境已验证最小 `1FE + 1CN + MinIO` 拓扑可完成部署,并可执行最小 `CREATE / INSERT / SELECT` +- shared-data 集群在初次部署后可能存在短暂预热期,系统表初始化会先占用 `CN` 建表队列 +- 当前 `deploy` 已增加 shared-data readiness 检查,会等待 `CN Alive` 和最小 CRUD 探针成功后再认为部署完成 +- 当前版本仍建议先在测试环境验证后再用于生产 +- 本版本仅支持 Linux amd64 架构 + +## 支持 + +如有问题,请联系开发团队或查看项目文档。 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..477a097 --- /dev/null +++ b/build.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# stargo 项目构建脚本 +# 用于生成可执行文件 + +set -e + +PROJECT_NAME="stargo" +VERSION=${VERSION:-"v2.4.0"} +BUILD_TIME=$(date '+%Y-%m-%d %H:%M:%S') +GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") + +echo "开始构建 ${PROJECT_NAME}..." +echo "版本: ${VERSION}" +echo "构建时间: ${BUILD_TIME}" +echo "Git 提交: ${GIT_COMMIT}" + +# 清理之前的构建 +echo "清理之前的构建文件..." +rm -f ${PROJECT_NAME} +rm -rf dist/ + +# 创建输出目录 +mkdir -p dist + +# 构建 Linux amd64 版本 +echo "构建 Linux amd64 版本..." +GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.Version=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GitCommit=${GIT_COMMIT}'" -o dist/${PROJECT_NAME}-linux-amd64 . + +# 构建当前平台版本(用于本地测试) +echo "构建当前平台版本..." +go build -ldflags "-X 'main.Version=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GitCommit=${GIT_COMMIT}'" -o ${PROJECT_NAME} . + +echo "构建完成!" +echo "生成的文件:" +ls -la dist/ +ls -la ${PROJECT_NAME} 2>/dev/null || true + +echo "" +echo "使用方法:" +echo " 本地测试: ./${PROJECT_NAME}" +echo " 查看版本: ./${PROJECT_NAME} version" +echo " 部署集群: ./${PROJECT_NAME} cluster deploy " +echo " 运行 playground: ./${PROJECT_NAME} playground" \ No newline at end of file diff --git a/cluster/checkStatus/checkBeStatus.go b/cluster/checkStatus/checkBeStatus.go index 830fd23..4b8393c 100644 --- a/cluster/checkStatus/checkBeStatus.go +++ b/cluster/checkStatus/checkBeStatus.go @@ -1,15 +1,14 @@ package checkStatus -import( - "fmt" - "strings" - "strconv" - "stargo/sr-utl" - "stargo/module" -// "database/sql" +import ( + "fmt" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" + // "database/sql" ) - // 哪个大聪明在 2.2 版本改了 show backends // 我真是谢谢你,艹 @@ -43,35 +42,34 @@ type BeStatusStruct struct{ } */ - //var GBeStatArr []BeStatusStruct func CheckBePortStatus(beId int) (checkPortRes bool, err error) { - var infoMess string + var infoMess string - tmpUser := module.GYamlConf.Global.User - tmpKeyRsa := module.GSshKeyRsa - tmpBeHost := module.GYamlConf.BeServers[beId].Host - tmpSshPort := module.GYamlConf.BeServers[beId].SshPort - tmpHeartbeatServicePort := module.GYamlConf.BeServers[beId].HeartbeatServicePort - checkCMD := fmt.Sprintf("netstat -an | grep ':%d ' | grep -v ESTABLISHED", tmpHeartbeatServicePort) + tmpUser := module.GYamlConf.Global.User + tmpKeyRsa := module.GSshKeyRsa + tmpBeHost := module.GYamlConf.BeServers[beId].Host + tmpSshPort := module.GYamlConf.BeServers[beId].SshPort + tmpHeartbeatServicePort := module.GYamlConf.BeServers[beId].HeartbeatServicePort + checkCMD := portListenCmd(tmpHeartbeatServicePort) - output, err := utl.SshRun(tmpUser, tmpKeyRsa, tmpBeHost, tmpSshPort, checkCMD) + output, err := utl.SshRun(tmpUser, tmpKeyRsa, tmpBeHost, tmpSshPort, checkCMD) - if err != nil { - infoMess = fmt.Sprintf("Error in run cmd when check BE port status [BeHost = %s, error = %v]", tmpBeHost, err) - utl.Log("DEBUG", infoMess) - return false, err - } + if err != nil { + infoMess = fmt.Sprintf("Error in run cmd when check BE port status [BeHost = %s, error = %v]", tmpBeHost, err) + utl.Log("DEBUG", infoMess) + return false, err + } - if strings.Contains(string(output), ":" + strconv.Itoa(tmpHeartbeatServicePort)) { - infoMess = fmt.Sprintf("Check the BE query port %s:%d run successfully", tmpBeHost, tmpHeartbeatServicePort) - utl.Log("DEBUG", infoMess) - return true, nil - } + if strings.Contains(string(output), ":"+strconv.Itoa(tmpHeartbeatServicePort)) { + infoMess = fmt.Sprintf("Check the BE query port %s:%d run successfully", tmpBeHost, tmpHeartbeatServicePort) + utl.Log("DEBUG", infoMess) + return true, nil + } - return false, err + return false, err } /* @@ -135,98 +133,86 @@ func GetBeStatJDBC(beId int) (beStat BeStatusStruct, err error) { */ - func GetBeStatJDBC(beId int) (beStatus map[string]string, err error) { - var infoMess string - //var tmpBeStat map[string]interface{} - var queryCMD string - var tmpBeHost string - var tmpHeartbeatServicePort int - - - queryCMD = "show backends" - tmpBeHost = module.GYamlConf.BeServers[beId].Host - tmpHeartbeatServicePort = module.GYamlConf.BeServers[beId].HeartbeatServicePort - - - rows, err := utl.RunSQL(module.GJdbcUser, module.GJdbcPasswd, module.GFeEntryHost, module.GFeEntryQueryPort, module.GJdbcDb, queryCMD) - - - if err != nil{ - infoMess = fmt.Sprintf("Error in run sql when check BE status: [BeHost = %s, error = %v]", tmpBeHost, err) - utl.Log("DEBUG", infoMess) - return beStatus, err - } - - - columns, _ := rows.Columns() - columnLength := len(columns) - cache := make([]interface{}, columnLength) - - for index, _ := range cache { - var tmpVal interface{} - cache[index] = &tmpVal - } + var infoMess string + //var tmpBeStat map[string]interface{} + var queryCMD string + var tmpBeHost string + var tmpHeartbeatServicePort int + queryCMD = "show backends" + tmpBeHost = module.GYamlConf.BeServers[beId].Host + tmpHeartbeatServicePort = module.GYamlConf.BeServers[beId].HeartbeatServicePort - for rows.Next(){ - err = rows.Scan(cache...) + rows, err := utl.RunSQL(module.GJdbcUser, module.GJdbcPasswd, module.GFeEntryHost, module.GFeEntryQueryPort, module.GJdbcDb, queryCMD) - if err != nil { - infoMess = fmt.Sprintf("Error in scan sql result [BeHost = %s, error = %v]", tmpBeHost, err) - utl.Log("DEBUG", infoMess) - return beStatus, err - } - - /* - if string(tmpBeStat.IP) == tmpBeHost && tmpBeStat.HeartbeatServicePort == tmpHeartbeatServicePort { - beStat = tmpBeStat - //GFeStatusArr[feId] = feStat - return beStat, nil - } - */ - - beStatus = make(map[string]string) - for i, data := range cache { - beStatus[columns[i]] = fmt.Sprintf("%s", *data.(*interface{})) - } - - - hertbeatPort, _ := strconv.Atoi(beStatus["HeartbeatPort"]) - if beStatus["IP"] == tmpBeHost && hertbeatPort == tmpHeartbeatServicePort { - return beStatus, err + if err != nil { + infoMess = fmt.Sprintf("Error in run sql when check BE status: [BeHost = %s, error = %v]", tmpBeHost, err) + utl.Log("DEBUG", infoMess) + return beStatus, err } - //statList = append(statList, item) - } + columns, _ := rows.Columns() + columnLength := len(columns) + cache := make([]interface{}, columnLength) + for index, _ := range cache { + var tmpVal interface{} + cache[index] = &tmpVal + } + for rows.Next() { + err = rows.Scan(cache...) + + if err != nil { + infoMess = fmt.Sprintf("Error in scan sql result [BeHost = %s, error = %v]", tmpBeHost, err) + utl.Log("DEBUG", infoMess) + return beStatus, err + } + + /* + if string(tmpBeStat.IP) == tmpBeHost && tmpBeStat.HeartbeatServicePort == tmpHeartbeatServicePort { + beStat = tmpBeStat + //GFeStatusArr[feId] = feStat + return beStat, nil + } + */ + + beStatus = make(map[string]string) + for i, data := range cache { + beStatus[columns[i]] = fmt.Sprintf("%s", *data.(*interface{})) + } + + hertbeatPort, _ := strconv.Atoi(beStatus["HeartbeatPort"]) + if beStatus["IP"] == tmpBeHost && hertbeatPort == tmpHeartbeatServicePort { + return beStatus, err + } + //statList = append(statList, item) + } - return beStatus, err + return beStatus, err } - func CheckBeStatus(beId int) (beStat map[string]string, err error) { - var bePortRun bool - bePortRun, err = CheckBePortStatus(beId) + var bePortRun bool + bePortRun, err = CheckBePortStatus(beId) - if bePortRun { - beStat, err = GetBeStatJDBC(beId) - } + if bePortRun { + beStat, err = GetBeStatJDBC(beId) + } - return beStat, err + return beStat, err } - func TestBeStatus() { - module.InitConf("sr-c1", "") - feEntryId, _ := GetFeEntry(-1) - module.SetFeEntry(feEntryId) + module.InitConf("sr-c1", "") + feEntryId, _ := GetFeEntry(-1) + module.SetFeEntry(feEntryId) - aaa, _ := CheckBeStatus(0) - fmt.Println(aaa) + aaa, _ := CheckBeStatus(0) + fmt.Println(aaa) } diff --git a/cluster/checkStatus/checkCnStatus.go b/cluster/checkStatus/checkCnStatus.go new file mode 100644 index 0000000..123c9fb --- /dev/null +++ b/cluster/checkStatus/checkCnStatus.go @@ -0,0 +1,118 @@ +package checkStatus + +import ( + "fmt" + "stargo/module" + utl "stargo/sr-utl" + "strconv" + "strings" +) + +// CheckCnPortStatus checks if CN node port is listening +func CheckCnPortStatus(cnId int) (checkPortRes bool, err error) { + + var infoMess string + + tmpUser := module.GYamlConf.Global.User + tmpKeyRsa := module.GSshKeyRsa + tmpCnHost := module.GYamlConf.CnServers[cnId].Host + tmpSshPort := module.GYamlConf.CnServers[cnId].SshPort + tmpHeartbeatServicePort := module.GYamlConf.CnServers[cnId].HeartbeatServicePort + checkCMD := portListenCmd(tmpHeartbeatServicePort) + + output, err := utl.SshRun(tmpUser, tmpKeyRsa, tmpCnHost, tmpSshPort, checkCMD) + + if err != nil { + infoMess = fmt.Sprintf("Error in run cmd when check CN port status [CnHost = %s, error = %v]", tmpCnHost, err) + utl.Log("DEBUG", infoMess) + return false, err + } + + if strings.Contains(string(output), ":"+strconv.Itoa(tmpHeartbeatServicePort)) { + infoMess = fmt.Sprintf("Check the CN query port %s:%d run successfully", tmpCnHost, tmpHeartbeatServicePort) + utl.Log("DEBUG", infoMess) + return true, nil + } + + return false, err +} + +// GetCnStatJDBC gets CN node status from StarRocks using "show compute nodes" command +func GetCnStatJDBC(cnId int) (cnStatus map[string]string, err error) { + + var infoMess string + tmpCnHost := module.GYamlConf.CnServers[cnId].Host + tmpHeartbeatServicePort := module.GYamlConf.CnServers[cnId].HeartbeatServicePort + + // Use "show compute nodes" for StarRocks CN instead of "show backends" + queryCMD := "show compute nodes" + + rows, err := utl.RunSQL(module.GJdbcUser, module.GJdbcPasswd, module.GFeEntryHost, module.GFeEntryQueryPort, module.GJdbcDb, queryCMD) + if err != nil { + infoMess = fmt.Sprintf("Error in run sql when check CN status: [CnHost = %s, error = %v]", tmpCnHost, err) + utl.Log("DEBUG", infoMess) + return cnStatus, err + } + + columns, _ := rows.Columns() + columnLength := len(columns) + cache := make([]interface{}, columnLength) + + for index, _ := range cache { + var tmpVal interface{} + cache[index] = &tmpVal + } + + for rows.Next() { + err = rows.Scan(cache...) + + if err != nil { + infoMess = fmt.Sprintf("Error in scan sql result [CnHost = %s, error = %v]", tmpCnHost, err) + utl.Log("DEBUG", infoMess) + return cnStatus, err + } + + cnStatus = make(map[string]string) + for i, data := range cache { + cnStatus[columns[i]] = fmt.Sprintf("%s", *data.(*interface{})) + } + + // Match CN node by IP and HeartbeatPort + hertbeatPort, _ := strconv.Atoi(cnStatus["HeartbeatPort"]) + if cnStatus["IP"] == tmpCnHost && hertbeatPort == tmpHeartbeatServicePort { + infoMess = fmt.Sprintf("Found matching CN node: IP=%s, HeartbeatPort=%d, Alive=%s", cnStatus["IP"], hertbeatPort, cnStatus["Alive"]) + utl.Log("DEBUG", infoMess) + return cnStatus, err + } + } + + // If no matching CN node found, return empty map + infoMess = fmt.Sprintf("No matching CN node found for IP=%s, HeartbeatPort=%d", tmpCnHost, tmpHeartbeatServicePort) + utl.Log("DEBUG", infoMess) + cnStatus = make(map[string]string) + return cnStatus, err +} + +// CheckCnStatus checks CN node status by combining port check and JDBC query +func CheckCnStatus(cnId int) (cnStat map[string]string, err error) { + + var cnPortRun bool + cnPortRun, err = CheckCnPortStatus(cnId) + + if cnPortRun { + cnStat, err = GetCnStatJDBC(cnId) + } + + return cnStat, err +} + +// TestCnStatus is a test function for CN status checking +func TestCnStatus() { + + module.InitConf("sr-c1", "") + feEntryId, _ := GetFeEntry(-1) + module.SetFeEntry(feEntryId) + + cnStat, _ := CheckCnStatus(0) + fmt.Println("CN Status:", cnStat) +} diff --git a/cluster/checkStatus/checkFeStatus.go b/cluster/checkStatus/checkFeStatus.go index 3c1743d..d1d2c05 100644 --- a/cluster/checkStatus/checkFeStatus.go +++ b/cluster/checkStatus/checkFeStatus.go @@ -1,12 +1,12 @@ package checkStatus import ( - "fmt" - "strings" - "strconv" - "stargo/sr-utl" - "stargo/module" - //"database/sql" + "fmt" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" + //"database/sql" ) /* @@ -33,38 +33,35 @@ type FeStatusStruct struct { } */ - - //var GFeStatusArr []FeStatusStruct - func CheckFePortStatus(feId int) (checkPortRes bool, err error) { - var infoMess string + var infoMess string - tmpUser := module.GYamlConf.Global.User - tmpKeyRsa := module.GSshKeyRsa - tmpFeHost := module.GYamlConf.FeServers[feId].Host - tmpSshPort := module.GYamlConf.FeServers[feId].SshPort - tmpQueryPort := module.GYamlConf.FeServers[feId].QueryPort + tmpUser := module.GYamlConf.Global.User + tmpKeyRsa := module.GSshKeyRsa + tmpFeHost := module.GYamlConf.FeServers[feId].Host + tmpSshPort := module.GYamlConf.FeServers[feId].SshPort + tmpQueryPort := module.GYamlConf.FeServers[feId].QueryPort - // check Port stat by [netstat -nltp | grep 9030] - checkCMD := fmt.Sprintf("netstat -an | grep ':%d ' | grep -v ESTABLISHED", tmpQueryPort) - output, err := utl.SshRun(tmpUser, tmpKeyRsa, tmpFeHost, tmpSshPort, checkCMD) + // check Port stat by [netstat -nltp | grep 9030] + checkCMD := portListenCmd(tmpQueryPort) + output, err := utl.SshRun(tmpUser, tmpKeyRsa, tmpFeHost, tmpSshPort, checkCMD) - if err != nil { - infoMess = fmt.Sprintf("Error in run cmd when check FE port status [FeHost = %s, error = %v]", tmpFeHost, err) - utl.Log("DEBUG", infoMess) - return false, err - } + if err != nil { + infoMess = fmt.Sprintf("Error in run cmd when check FE port status [FeHost = %s, error = %v]", tmpFeHost, err) + utl.Log("DEBUG", infoMess) + return false, err + } - if strings.Contains(string(output), ":" + strconv.Itoa(tmpQueryPort)) { - infoMess = fmt.Sprintf("Check the fe query port %s:%d run successfully", tmpFeHost, tmpQueryPort) - utl.Log("DEBUG", infoMess) - return true, nil - } + if strings.Contains(string(output), ":"+strconv.Itoa(tmpQueryPort)) { + infoMess = fmt.Sprintf("Check the fe query port %s:%d run successfully", tmpFeHost, tmpQueryPort) + utl.Log("DEBUG", infoMess) + return true, nil + } - return false, err + return false, err } @@ -125,95 +122,92 @@ func GetFeStatJDBC(feId int) (feStat FeStatusStruct, err error) { func GetFeStatJDBC(feId int) (feStat map[string]string, err error) { - var infoMess string - var tmpFeStat map[string]string - var feStatus map[string]string - //GJdbcUser = "root" - //GJdbcPasswd = "" - //GJdbcDb = "" - queryCMD := "show frontends" - tmpFeHost := module.GYamlConf.FeServers[feId].Host - tmpQueryPort := module.GYamlConf.FeServers[feId].QueryPort - - rows, err := utl.RunSQL(module.GJdbcUser, module.GJdbcPasswd, tmpFeHost, tmpQueryPort, module.GJdbcDb, queryCMD) - if err != nil{ - infoMess = fmt.Sprintf("Error in run sql when check fe status: [FeHost = %s, error = %v]", tmpFeHost, err) - utl.Log("DEBUG", infoMess) - return feStat, err - } + var infoMess string + var tmpFeStat map[string]string + var feStatus map[string]string + //GJdbcUser = "root" + //GJdbcPasswd = "" + //GJdbcDb = "" + queryCMD := "show frontends" + tmpFeHost := module.GYamlConf.FeServers[feId].Host + tmpQueryPort := module.GYamlConf.FeServers[feId].QueryPort + + rows, err := utl.RunSQL(module.GJdbcUser, module.GJdbcPasswd, tmpFeHost, tmpQueryPort, module.GJdbcDb, queryCMD) + if err != nil { + infoMess = fmt.Sprintf("Error in run sql when check fe status: [FeHost = %s, error = %v]", tmpFeHost, err) + utl.Log("DEBUG", infoMess) + return feStat, err + } - columns, _ := rows.Columns() - columnLength := len(columns) - cache := make([]interface{}, columnLength) + columns, _ := rows.Columns() + columnLength := len(columns) + cache := make([]interface{}, columnLength) - for index, _ := range cache { - var tmpVal interface{} - cache[index] = &tmpVal - } + for index, _ := range cache { + var tmpVal interface{} + cache[index] = &tmpVal + } + for rows.Next() { + err = rows.Scan(cache...) - for rows.Next(){ - err = rows.Scan(cache...) + if err != nil { + infoMess = fmt.Sprintf("Error in scan sql result [FeHost = %s, error = %v]", tmpFeHost, err) + utl.Log("DEBUG", infoMess) + return feStatus, err + } - if err != nil { - infoMess = fmt.Sprintf("Error in scan sql result [FeHost = %s, error = %v]", tmpFeHost, err) - utl.Log("DEBUG", infoMess) - return feStatus, err - } - - feStatus = make(map[string]string) - for i, data := range cache { - feStatus[columns[i]] = fmt.Sprintf("%s", *data.(*interface{})) - } + feStatus = make(map[string]string) + for i, data := range cache { + feStatus[columns[i]] = fmt.Sprintf("%s", *data.(*interface{})) + } - queryPort, _ := strconv.Atoi(feStatus["QueryPort"]) - if feStatus["IP"] == tmpFeHost && queryPort == tmpQueryPort { - feStat = tmpFeStat - //GFeStatusArr[feId] = feStat - return feStatus, nil - } + queryPort, _ := strconv.Atoi(feStatus["QueryPort"]) + if feStatus["IP"] == tmpFeHost && queryPort == tmpQueryPort { + feStat = tmpFeStat + //GFeStatusArr[feId] = feStat + return feStatus, nil + } - } + } - return feStatus, err + return feStatus, err } - - func CheckFeStatus(feId int) (feStat map[string]string, err error) { - //var infoMess string - var fePortRun bool - // CheckFePort - fePortRun, err = CheckFePortStatus(feId) + //var infoMess string + var fePortRun bool + // CheckFePort + fePortRun, err = CheckFePortStatus(feId) - // getFeStat by JDBC - if fePortRun { - feStat, err = GetFeStatJDBC(feId) - } - return feStat, err + // getFeStat by JDBC + if fePortRun { + feStat, err = GetFeStatJDBC(feId) + } + return feStat, err } - func TestFeStatus() { - module.InitConf("sr-c1", "") - feEntryId, _ := GetFeEntry(-1) - module.SetFeEntry(feEntryId) + module.InitConf("sr-c1", "") + feEntryId, _ := GetFeEntry(-1) + module.SetFeEntry(feEntryId) - aaa, _ := CheckFeStatus(0) - fmt.Println(aaa) + aaa, _ := CheckFeStatus(0) + fmt.Println(aaa) } + /* func CheckFeStatus(feId int, user string, keyRsa string, sshHost string, sshPort int, feQueryPort int) (feStat FeStatusStruct, err error) { var infoMess string var tmpFeStat FeStatusStruct - // check port stat by [netstat -nltp | grep 9030] + // check port stat by [netstat -nltp | grep 9030] portStat := CheckFePort(feId) - + cmd := fmt.Sprintf("netstat -an | grep ':%d ' | grep -v ESTABLISHED", feQueryPort) output, err := utl.SshRun(user, keyRsa, sshHost, sshPort, cmd) @@ -229,7 +223,7 @@ func CheckFeStatus(feId int, user string, keyRsa string, sshHost string, sshPort err = errors.New(infoMess) return feStat, err } - + // check fe status by jdbc (from the master fe node) @@ -299,4 +293,3 @@ func CheckFeStatus(feId int, user string, keyRsa string, sshHost string, sshPort } */ - diff --git a/cluster/checkStatus/deploySuccess.go b/cluster/checkStatus/deploySuccess.go index 3747f36..181a2f8 100644 --- a/cluster/checkStatus/deploySuccess.go +++ b/cluster/checkStatus/deploySuccess.go @@ -1,13 +1,12 @@ package checkStatus -import( - "fmt" +import ( + "fmt" ) func DeploySuccess() { - - fmt.Printf(`旅行者,当你重新踏上旅途之后,一定要记得旅途本身的意义。 + fmt.Printf(`旅行者,当你重新踏上旅途之后,一定要记得旅途本身的意义。 提瓦特的飞鸟、诗和城邦,女皇、愚人和怪物 ... 都是你旅途的一部分。 终点并不意味着一切,在抵达终点之前,用你的眼睛,多多观察这个世界吧 ... REPEST OPENSOURCE ......\n`) diff --git a/cluster/checkStatus/getFeEntry.go b/cluster/checkStatus/getFeEntry.go index 71ec231..b42a5e8 100644 --- a/cluster/checkStatus/getFeEntry.go +++ b/cluster/checkStatus/getFeEntry.go @@ -1,47 +1,51 @@ package checkStatus -import( - "fmt" - "errors" - "strings" - "strconv" - "stargo/module" - "stargo/sr-utl" +import ( + "errors" + "fmt" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" ) -func GetFeEntry(blackFeNodeId int) (feEntryId int, err error) { - - // get a usable FE host & query port for checking FE/BE status by [show frontends] & [show backends] command - - var infoMess string - - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - if i == blackFeNodeId { - continue - } - - tmpSshHost := module.GYamlConf.FeServers[i].Host - tmpSshPort := module.GYamlConf.FeServers[i].SshPort - tmpQueryPort := module.GYamlConf.FeServers[i].QueryPort - tmpUser := module.GYamlConf.Global.User - tmpKeyRsa := module.GSshKeyRsa - // check port stat by [netstat -nltp | grep 9030 | grep -v ESTABLISHED] - cmd := fmt.Sprintf("netstat -an | grep ':%d ' | grep -v ESTABLISHED", tmpQueryPort) +func portListenCmd(port int) string { + return fmt.Sprintf("if command -v ss >/dev/null 2>&1; then ss -ltn | grep ':%d '; else netstat -an | grep ':%d ' | grep -v ESTABLISHED; fi", port, port) +} - output, err := utl.SshRun(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, cmd) - if err != nil { - infoMess = fmt.Sprintf("Error in get FE entry, checking query port failed. [FeHost = %s, QueryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) - utl.Log("DEBUG", infoMess) - } +func GetFeEntry(blackFeNodeId int) (feEntryId int, err error) { - if strings.Contains(string(output), ":" + strconv.Itoa(tmpQueryPort)) { - infoMess = fmt.Sprintf("Get a useable FE entry. [FeID = %d, FeHost = %s, QueryPort = %d]", i, tmpSshHost, tmpQueryPort) - utl.Log("DEBUG", infoMess) - return i, nil + // get a usable FE host & query port for checking FE/BE status by [show frontends] & [show backends] command + + var infoMess string + + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + if i == blackFeNodeId { + continue + } + + tmpSshHost := module.GYamlConf.FeServers[i].Host + tmpSshPort := module.GYamlConf.FeServers[i].SshPort + tmpQueryPort := module.GYamlConf.FeServers[i].QueryPort + tmpUser := module.GYamlConf.Global.User + tmpKeyRsa := module.GSshKeyRsa + // check port stat by [netstat -nltp | grep 9030 | grep -v ESTABLISHED] + cmd := portListenCmd(tmpQueryPort) + + output, err := utl.SshRun(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, cmd) + if err != nil { + infoMess = fmt.Sprintf("Error in get FE entry, checking query port failed. [FeHost = %s, QueryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) + utl.Log("DEBUG", infoMess) + } + + if strings.Contains(string(output), ":"+strconv.Itoa(tmpQueryPort)) { + infoMess = fmt.Sprintf("Get a useable FE entry. [FeID = %d, FeHost = %s, QueryPort = %d]", i, tmpSshHost, tmpQueryPort) + utl.Log("DEBUG", infoMess) + return i, nil + } } - } - err = errors.New("There is no useable FE entry.") - return -1, err + err = errors.New("There is no useable FE entry.") + return -1, err } diff --git a/cluster/checkStatus/getNodeInfo.go b/cluster/checkStatus/getNodeInfo.go index b05f295..2db41ed 100644 --- a/cluster/checkStatus/getNodeInfo.go +++ b/cluster/checkStatus/getNodeInfo.go @@ -1,63 +1,73 @@ package checkStatus -import( - "strings" - "fmt" - "os" - "strconv" - "stargo/module" - "stargo/sr-utl" +import ( + "fmt" + "os" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" ) - func CheckClusterName(clusterName string) bool { - clusterPath := fmt.Sprintf("%s/cluster/%s", module.GSRCtlRoot, clusterName) - _, err := os.Stat(clusterPath) - if err != nil { - // the file doesn't exist, the cluster name can be used - return true - } + clusterPath := fmt.Sprintf("%s/cluster/%s", module.GSRCtlRoot, clusterName) + _, err := os.Stat(clusterPath) + if err != nil { + // the file doesn't exist, the cluster name can be used + return true + } - return false + return false } - func GetNodeType(nodeId string) (nodeType string, nodeInd int) { - // FEID: module.GYamlConf.FeServers[i].EditLogPort, module.GYamlConf.FeServers[i].QueryPort - // BEID: module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].BePort - var infoMess string - tmpNodeId := strings.Split(nodeId, ":") - - // check FE - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - - if tmpNodeId[0] == module.GYamlConf.FeServers[i].Host && - tmpNodeId[1] == strconv.Itoa(module.GYamlConf.FeServers[i].EditLogPort) { - nodeType = "FE" - //ip = module.GYamlConf.FeServers[i].Host - //port = tmpNodeId[1] == module.GYamlConf.FeServers[i].EditLogPort - nodeInd = i - break - } - } - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - - if tmpNodeId[0] == module.GYamlConf.BeServers[i].Host && - tmpNodeId[1] == strconv.Itoa(module.GYamlConf.BeServers[i].BePort) { - nodeType = "BE" - //ip = module.GYamlConf.BeServers[i].Host - //port = module.GYamlConf.BeServers[i].BePort - nodeInd = i - break - } - } - - infoMess = fmt.Sprintf("Get the node type [nodeid = %s, nodetype = %s, nodeindex = %d]\n", nodeId, nodeType, nodeInd) - utl.Log("DEBUG", infoMess) - return nodeType, nodeInd + // FEID: module.GYamlConf.FeServers[i].EditLogPort, module.GYamlConf.FeServers[i].QueryPort + // BEID: module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].BePort + var infoMess string + tmpNodeId := strings.Split(nodeId, ":") -} + // check FE + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + + if tmpNodeId[0] == module.GYamlConf.FeServers[i].Host && + tmpNodeId[1] == strconv.Itoa(module.GYamlConf.FeServers[i].EditLogPort) { + nodeType = "FE" + //ip = module.GYamlConf.FeServers[i].Host + //port = tmpNodeId[1] == module.GYamlConf.FeServers[i].EditLogPort + nodeInd = i + break + } + } + + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + if tmpNodeId[0] == module.GYamlConf.BeServers[i].Host && + tmpNodeId[1] == strconv.Itoa(module.GYamlConf.BeServers[i].BePort) { + nodeType = "BE" + //ip = module.GYamlConf.BeServers[i].Host + //port = module.GYamlConf.BeServers[i].BePort + nodeInd = i + break + } + } + + // check CN + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + + if tmpNodeId[0] == module.GYamlConf.CnServers[i].Host && + tmpNodeId[1] == strconv.Itoa(module.GYamlConf.CnServers[i].BePort) { + nodeType = "CN" + //ip = module.GYamlConf.CnServers[i].Host + //port = module.GYamlConf.CnServers[i].BePort + nodeInd = i + break + } + } + + infoMess = fmt.Sprintf("Get the node type [nodeid = %s, nodetype = %s, nodeindex = %d]\n", nodeId, nodeType, nodeInd) + utl.Log("DEBUG", infoMess) + return nodeType, nodeInd + +} diff --git a/cluster/clusterOption/deploy.go b/cluster/clusterOption/deploy.go index d7d5645..343c658 100644 --- a/cluster/clusterOption/deploy.go +++ b/cluster/clusterOption/deploy.go @@ -1,43 +1,51 @@ package clusterOption import ( - - "fmt" - "stargo/module" - "stargo/cluster/prepareOption" - "stargo/cluster/modifyConfig" - "stargo/cluster/startCluster" - + "fmt" + "os" + "stargo/cluster/modifyConfig" + "stargo/cluster/prepareOption" + "stargo/cluster/startCluster" + "stargo/module" ) - // sr-ctl-cluster deploy sr-c1 v2.0.1 /tmp/sr-c1.yaml func Deploy(clusterName string, clusterVersion string, metaFile string) { + module.InitConf(clusterName, metaFile) + module.SetGlobalVar("GSRVersion", clusterVersion) + + prepareOption.PreCheckSR() + prepareOption.CreateDir() + prepareOption.PrepareSRPkg() + prepareOption.DistributeSrDir() + module.WriteBackMeta(module.GYamlConf, module.GWriteBackMetaPath) + + //### recover.sh ##############################") + modifyConfig.ModifyClusterConfig() + + fmt.Println("############################################# START FE CLUSTER #############################################") + fmt.Println("############################################# START FE CLUSTER #############################################") + + startCluster.InitFeCluster(module.GYamlConf) + if len(module.GYamlConf.BeServers) > 0 && !module.IsSharedDataCluster() { + fmt.Println("############################################# START BE CLUSTER #############################################") + fmt.Println("############################################# START BE CLUSTER #############################################") + startCluster.InitBeCluster(module.GYamlConf) + } + if len(module.GYamlConf.CnServers) > 0 { + fmt.Println("############################################# START CN CLUSTER #############################################") + fmt.Println("############################################# START CN CLUSTER #############################################") + startCluster.InitCnCluster(module.GYamlConf) + } + if module.IsSharedDataCluster() && len(module.GYamlConf.CnServers) > 0 { + fmt.Println("############################################# WAIT SHARED-DATA READY #############################################") + fmt.Println("############################################# WAIT SHARED-DATA READY #############################################") + if err := startCluster.WaitSharedDataReady(module.GYamlConf); err != nil { + os.Exit(1) + } + } + //checkStatus.DeploySuccess() - module.InitConf(clusterName, metaFile) - module.SetGlobalVar("GSRVersion", clusterVersion) - - prepareOption.PreCheckSR() - prepareOption.CreateDir() - prepareOption.PrepareSRPkg() - prepareOption.DistributeSrDir() - module.WriteBackMeta(module.GYamlConf, module.GWriteBackMetaPath) - - //### recover.sh ##############################") - modifyConfig.ModifyClusterConfig() - - fmt.Println("############################################# START FE CLUSTER #############################################") - fmt.Println("############################################# START FE CLUSTER #############################################") - - startCluster.InitFeCluster(module.GYamlConf) - fmt.Println("############################################# START BE CLUSTER #############################################") - fmt.Println("############################################# START BE CLUSTER #############################################") - startCluster.InitBeCluster(module.GYamlConf) - //checkStatus.DeploySuccess() - - - } - diff --git a/cluster/clusterOption/destroy.go b/cluster/clusterOption/destroy.go index d36e530..1dec973 100644 --- a/cluster/clusterOption/destroy.go +++ b/cluster/clusterOption/destroy.go @@ -1,27 +1,24 @@ package clusterOption - -import( - "stargo/cluster/destroyCluster" - "stargo/module" - "stargo/sr-utl" - "os" - "stargo/cluster/checkStatus" +import ( + "os" + "stargo/cluster/checkStatus" + "stargo/cluster/destroyCluster" + "stargo/module" + "stargo/sr-utl" ) func Destroy(clusterName string) { - var infoMess string - module.InitConf(clusterName, "") - + var infoMess string + module.InitConf(clusterName, "") - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) + } - Stop(clusterName, module.NULLSTR, module.NULLSTR) - destroyCluster.DestroyCluster(clusterName) + Stop(clusterName, module.NULLSTR, module.NULLSTR) + destroyCluster.DestroyCluster(clusterName) } - diff --git a/cluster/clusterOption/display.go b/cluster/clusterOption/display.go index e869613..36fe089 100644 --- a/cluster/clusterOption/display.go +++ b/cluster/clusterOption/display.go @@ -1,32 +1,29 @@ package clusterOption - -import( - "stargo/cluster/displayCluster" - "stargo/cluster/checkStatus" - "stargo/module" - "stargo/sr-utl" - "os" +import ( + "os" + "stargo/cluster/checkStatus" + "stargo/cluster/displayCluster" + "stargo/module" + "stargo/sr-utl" ) func Display(clusterName string) { - var infoMess string - module.InitConf(clusterName, "") - - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } + var infoMess string + module.InitConf(clusterName, "") - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) + } + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) + } - clusterStatus.ClusterStat(clusterName) + clusterStatus.ClusterStat(clusterName) } - diff --git a/cluster/clusterOption/downgrade.go b/cluster/clusterOption/downgrade.go index f1847b4..1aa8d41 100644 --- a/cluster/clusterOption/downgrade.go +++ b/cluster/clusterOption/downgrade.go @@ -1,46 +1,55 @@ package clusterOption -import( - - "fmt" - "os" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" - "stargo/cluster/prepareOption" - "stargo/cluster/downgradeCluster" +import ( + "fmt" + "os" + "stargo/cluster/checkStatus" + "stargo/cluster/downgradeCluster" + "stargo/cluster/prepareOption" + "stargo/cluster/startCluster" + "stargo/module" + "stargo/sr-utl" ) func Downgrade(clusterName string, clusterVersion string) { - var infoMess string - //var err error - - - module.InitConf(clusterName, "") - module.SetGlobalVar("GSRVersion", clusterVersion) - - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - oldVersion := module.GYamlConf.ClusterInfo.Version - newVersion := clusterVersion - if !(oldVersion > newVersion) { - infoMess = fmt.Sprintf("OldVersion = %s NewVersion = %s, the NewVersion is not higher than OldVersion", oldVersion, newVersion) - utl.Log("ERROR", infoMess) - os.Exit(1) - } else { - infoMess = fmt.Sprintf("Downgrade StarRocks Cluster %s, from version %s to version %s", clusterName, oldVersion, newVersion) - utl.Log("OUTPUT", infoMess) - } - - prepareOption.PrepareSRPkg() - downgradeCluster.DowngradeBeCluster() - downgradeCluster.DowngradeFeCluster() - - module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + var infoMess string + //var err error + + module.InitConf(clusterName, "") + module.SetGlobalVar("GSRVersion", clusterVersion) + + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + oldVersion := module.GYamlConf.ClusterInfo.Version + newVersion := clusterVersion + if module.CompareStarRocksVersions(oldVersion, newVersion) <= 0 { + infoMess = fmt.Sprintf("OldVersion = %s NewVersion = %s, the NewVersion is not lower than OldVersion", oldVersion, newVersion) + utl.Log("ERROR", infoMess) + os.Exit(1) + } else { + infoMess = fmt.Sprintf("Downgrade StarRocks Cluster %s, from version %s to version %s", clusterName, oldVersion, newVersion) + utl.Log("OUTPUT", infoMess) + } + + prepareOption.PrepareSRPkg() + if module.IsSharedDataCluster() { + downgradeCluster.DowngradeFeCluster() + downgradeCluster.DowngradeCnCluster() + if err := startCluster.WaitSharedDataReady(module.GYamlConf); err != nil { + os.Exit(1) + } + module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + return + } + + downgradeCluster.DowngradeBeCluster() + downgradeCluster.DowngradeFeCluster() + + module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) } diff --git a/cluster/clusterOption/import.go b/cluster/clusterOption/import.go index f5a5a6b..7e632f5 100644 --- a/cluster/clusterOption/import.go +++ b/cluster/clusterOption/import.go @@ -1,68 +1,62 @@ package clusterOption - import ( - - "fmt" - "time" - "os" - "os/user" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" - "stargo/cluster/importCluster" - + "fmt" + "os" + "os/user" + "stargo/cluster/checkStatus" + "stargo/cluster/importCluster" + "stargo/module" + "stargo/sr-utl" + "time" ) - - func ImportCluster(clusterName string, metaFile string) { - - var infoMess string - - osUser, _ := user.Current() - module.GSRCtlRoot = os.Getenv("SRCTLROOT") - if module.GSRCtlRoot == "" { - module.GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) - } - - - // check cluster exist - if !checkStatus.CheckClusterName(clusterName) { - infoMess = fmt.Sprintf("Error in importing the cluster. The cluster exist, pls change another namne. [ClusterName = %s, MetaFile = %s]", clusterName, metaFile) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - // check the metaFile exists - _, err := os.Stat(metaFile) - if err != nil { - // the metafile doesn't exist - infoMess = fmt.Sprintf("Error in importing cluster. The MetaFile doesn't exist. [ClusterName = %s, MetaFile = %s]", clusterName, metaFile) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - module.InitConf(clusterName, metaFile) - //fmt.Println(module.GYamlConf.FeServers) - feEntryId, err := checkStatus.GetFeEntry(-1) - module.SetFeEntry(feEntryId) - if err != nil { - infoMess = fmt.Sprintf("Error in get FE Entry ID when import cluter info.") - utl.Log("ERROR", infoMess) - } - - - module.GYamlConf.ClusterInfo.User = module.GYamlConf.Global.User - module.GYamlConf.ClusterInfo.CreateDate = time.Unix(time.Now().Unix(), 0,).Format("2006-01-02 15:04:05") - module.GYamlConf.ClusterInfo.MetaPath = module.GWriteBackMetaPath - module.GYamlConf.ClusterInfo.PrivateKey = module.GSshKeyRsa - - - importCluster.GetFeConf() - importCluster.GetBeConf() - - module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + var infoMess string + + osUser, _ := user.Current() + module.GSRCtlRoot = os.Getenv("SRCTLROOT") + if module.GSRCtlRoot == "" { + module.GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) + } + + // check cluster exist + if !checkStatus.CheckClusterName(clusterName) { + infoMess = fmt.Sprintf("Error in importing the cluster. The cluster exist, pls change another namne. [ClusterName = %s, MetaFile = %s]", clusterName, metaFile) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + // check the metaFile exists + _, err := os.Stat(metaFile) + if err != nil { + // the metafile doesn't exist + infoMess = fmt.Sprintf("Error in importing cluster. The MetaFile doesn't exist. [ClusterName = %s, MetaFile = %s]", clusterName, metaFile) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + module.InitConf(clusterName, metaFile) + //fmt.Println(module.GYamlConf.FeServers) + feEntryId, err := checkStatus.GetFeEntry(-1) + module.SetFeEntry(feEntryId) + if err != nil { + infoMess = fmt.Sprintf("Error in get FE Entry ID when import cluter info.") + utl.Log("ERROR", infoMess) + } + + module.GYamlConf.ClusterInfo.User = module.GYamlConf.Global.User + module.GYamlConf.ClusterInfo.CreateDate = time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05") + module.GYamlConf.ClusterInfo.MetaPath = module.GWriteBackMetaPath + module.GYamlConf.ClusterInfo.PrivateKey = module.GSshKeyRsa + + importCluster.GetFeConf() + if len(module.GYamlConf.BeServers) > 0 && !module.IsSharedDataCluster() { + importCluster.GetBeConf() + } + importCluster.GetCnConf() + + module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) } diff --git a/cluster/clusterOption/list.go b/cluster/clusterOption/list.go index 99804e2..78a54d8 100644 --- a/cluster/clusterOption/list.go +++ b/cluster/clusterOption/list.go @@ -1,21 +1,21 @@ package clusterOption import ( - "os" - "os/user" - "fmt" - "stargo/cluster/listCluster" - "stargo/module" + "fmt" + "os" + "os/user" + "stargo/cluster/listCluster" + "stargo/module" ) func List() { - // get sr-ctl root dir - osUser, _ := user.Current() - module.GSRCtlRoot = os.Getenv("SRCTLROOT") - if module.GSRCtlRoot == "" { - module.GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) - } + // get sr-ctl root dir + osUser, _ := user.Current() + module.GSRCtlRoot = os.Getenv("SRCTLROOT") + if module.GSRCtlRoot == "" { + module.GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) + } - listCluster.ListCluster() + listCluster.ListCluster() } diff --git a/cluster/clusterOption/scaleIn.go b/cluster/clusterOption/scaleIn.go index d5ab8b2..229a108 100644 --- a/cluster/clusterOption/scaleIn.go +++ b/cluster/clusterOption/scaleIn.go @@ -1,152 +1,187 @@ package clusterOption import ( - "fmt" - "time" -// "strings" - "os" - "stargo/sr-utl" - "stargo/module" - "stargo/cluster/checkStatus" - "stargo/cluster/stopCluster" + "fmt" + "time" + // "strings" + "os" + "stargo/cluster/checkStatus" + "stargo/cluster/stopCluster" + "stargo/module" + "stargo/sr-utl" ) - func ScaleIn(clusterName string, nodeId string) { - var feEntryId int - var err error - var tmpNodeType string - var nid int - var dropCmd string - var infoMess string - var user string - var keyRsa string - var sshHost string - var sshPort int - var beHeartbeatServicePort int - var feDeployDir string - var beDeployDir string - - - module.InitConf(clusterName, "") - - - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - tmpNodeType, nid = checkStatus.GetNodeType(nodeId) - feEntryId, err = checkStatus.GetFeEntry(nid) - - if err != nil || feEntryId == -1 { - //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." - //utl.Log("WARN", infoMess) - module.SetFeEntry(0) - } else { - module.SetFeEntry(feEntryId) - } - - - sqlIp := module.GFeEntryHost - sqlPort := module.GFeEntryQueryPort - sqlUserName := "root" - sqlPassword := "" - sqlDbName := "" - user = module.GYamlConf.Global.User - keyRsa = module.GSshKeyRsa - - if tmpNodeType == "FE" { - - // stop fe node first - sshHost = module.GYamlConf.FeServers[nid].Host - sshPort = module.GYamlConf.FeServers[nid].SshPort - feDeployDir = module.GYamlConf.FeServers[nid].DeployDir - err = stopCluster.StopFeNode(user, keyRsa, sshHost, sshPort, feDeployDir) - if err != nil { - infoMess = fmt.Sprintf("Error in stop FE node. [nodeId = %s, error = %v]", nodeId, err) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - time.Sleep(time.Duration(10) * time.Second) - // drop BE node - dropCmd = fmt.Sprintf("ALTER SYSTEM DROP FOLLOWER '%s'", nodeId) - _, err := utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, dropCmd) - - if err != nil { - infoMess = fmt.Sprintf("Error in scale in FE node. [clusterName = %s, nodeId = %s, error = %s]", clusterName, nodeId, err) - utl.Log("ERROR", infoMess) - } - - - // remove FE dir: data, deploy, log - utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf " + module.GYamlConf.FeServers[nid].LogDir) - utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf " + module.GYamlConf.FeServers[nid].MetaDir) - utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf " + module.GYamlConf.FeServers[nid].DeployDir) - - - if nid != len(module.GYamlConf.FeServers) - 1 { - module.GYamlConf.FeServers = append(module.GYamlConf.FeServers[:nid], module.GYamlConf.FeServers[nid+1:]...) - } else { - module.GYamlConf.FeServers = module.GYamlConf.FeServers[:nid] - } - module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) - - infoMess = fmt.Sprintf("Scale in FE node successfully. [clusterName = %s, nodeId = %s]", clusterName, nodeId) - utl.Log("OUTPUT", infoMess) - - } else if tmpNodeType == "BE" { - // stop BE node first - sshHost = module.GYamlConf.BeServers[nid].Host - sshPort = module.GYamlConf.BeServers[nid].SshPort - sshHost = module.GYamlConf.BeServers[nid].Host - beDeployDir = module.GYamlConf.BeServers[nid].DeployDir - beHeartbeatServicePort = module.GYamlConf.BeServers[nid].HeartbeatServicePort - err = stopCluster.StopBeNode(user, keyRsa, sshHost, sshPort, beDeployDir) - - if err != nil { - infoMess = fmt.Sprintf("Error in stop BE node. [nodeId = %s, error = %v]", nodeId, err) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - time.Sleep(time.Duration(10) * time.Second) - - // drop BE node - dropCmd = fmt.Sprintf("ALTER SYSTEM DROP BACKEND '%s:%d'", sshHost, beHeartbeatServicePort) - - _, err := utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, dropCmd) - - if err != nil { - infoMess = fmt.Sprintf("Error in scale in BE node. [clusterName = %s, nodeId = %s, error = %s]", clusterName, nodeId, err) - utl.Log("ERROR", infoMess) - } - - - - // remove dir: data, deploy, log - utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf " + module.GYamlConf.BeServers[nid].LogDir) - utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf " + module.GYamlConf.BeServers[nid].StorageDir) - utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf " + module.GYamlConf.BeServers[nid].DeployDir) - - if nid != len(module.GYamlConf.BeServers) - 1 { - module.GYamlConf.BeServers = append(module.GYamlConf.BeServers[:nid], module.GYamlConf.BeServers[nid+1:]...) - } else { - module.GYamlConf.BeServers = module.GYamlConf.BeServers[:nid] - } - // module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) - - module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) - infoMess = fmt.Sprintf("Scale in BE node successfully. [clusterName = %s, nodeId = %s]", clusterName, nodeId) - utl.Log("OUTPUT", infoMess) - - } else { - infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) - utl.Log("ERROR", infoMess) - } + var feEntryId int + var err error + var tmpNodeType string + var nid int + var dropCmd string + var infoMess string + var user string + var keyRsa string + var sshHost string + var sshPort int + var beHeartbeatServicePort int + var feDeployDir string + var beDeployDir string + + module.InitConf(clusterName, "") + isSharedData := module.IsSharedDataCluster() + + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + tmpNodeType, nid = checkStatus.GetNodeType(nodeId) + feEntryId, err = checkStatus.GetFeEntry(nid) + + if err != nil || feEntryId == -1 { + //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." + //utl.Log("WARN", infoMess) + module.SetFeEntry(0) + } else { + module.SetFeEntry(feEntryId) + } + + sqlIp := module.GFeEntryHost + sqlPort := module.GFeEntryQueryPort + sqlUserName := "root" + sqlPassword := "" + sqlDbName := "" + user = module.GYamlConf.Global.User + keyRsa = module.GSshKeyRsa + + if tmpNodeType == "FE" { + + // stop fe node first + sshHost = module.GYamlConf.FeServers[nid].Host + sshPort = module.GYamlConf.FeServers[nid].SshPort + feDeployDir = module.GYamlConf.FeServers[nid].DeployDir + err = stopCluster.StopFeNode(user, keyRsa, sshHost, sshPort, feDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stop FE node. [nodeId = %s, error = %v]", nodeId, err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + time.Sleep(time.Duration(10) * time.Second) + // drop BE node + dropCmd = fmt.Sprintf("ALTER SYSTEM DROP FOLLOWER '%s'", nodeId) + _, err := utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, dropCmd) + + if err != nil { + infoMess = fmt.Sprintf("Error in scale in FE node. [clusterName = %s, nodeId = %s, error = %s]", clusterName, nodeId, err) + utl.Log("ERROR", infoMess) + } + + // remove FE dir: data, deploy, log + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.FeServers[nid].LogDir) + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.FeServers[nid].MetaDir) + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.FeServers[nid].DeployDir) + + if nid != len(module.GYamlConf.FeServers)-1 { + module.GYamlConf.FeServers = append(module.GYamlConf.FeServers[:nid], module.GYamlConf.FeServers[nid+1:]...) + } else { + module.GYamlConf.FeServers = module.GYamlConf.FeServers[:nid] + } + module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + + infoMess = fmt.Sprintf("Scale in FE node successfully. [clusterName = %s, nodeId = %s]", clusterName, nodeId) + utl.Log("OUTPUT", infoMess) + + } else if tmpNodeType == "BE" { + if isSharedData { + infoMess = "Shared-data cluster does not use BE nodes. Please scale CN nodes instead." + utl.Log("ERROR", infoMess) + os.Exit(1) + } + // stop BE node first + sshHost = module.GYamlConf.BeServers[nid].Host + sshPort = module.GYamlConf.BeServers[nid].SshPort + sshHost = module.GYamlConf.BeServers[nid].Host + beDeployDir = module.GYamlConf.BeServers[nid].DeployDir + beHeartbeatServicePort = module.GYamlConf.BeServers[nid].HeartbeatServicePort + err = stopCluster.StopBeNode(user, keyRsa, sshHost, sshPort, beDeployDir) + + if err != nil { + infoMess = fmt.Sprintf("Error in stop BE node. [nodeId = %s, error = %v]", nodeId, err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + time.Sleep(time.Duration(10) * time.Second) + + // drop BE node + dropCmd = fmt.Sprintf("ALTER SYSTEM DROP BACKEND '%s:%d'", sshHost, beHeartbeatServicePort) + + _, err := utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, dropCmd) + + if err != nil { + infoMess = fmt.Sprintf("Error in scale in BE node. [clusterName = %s, nodeId = %s, error = %s]", clusterName, nodeId, err) + utl.Log("ERROR", infoMess) + } + + // remove dir: data, deploy, log + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.BeServers[nid].LogDir) + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.BeServers[nid].StorageDir) + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.BeServers[nid].DeployDir) + + if nid != len(module.GYamlConf.BeServers)-1 { + module.GYamlConf.BeServers = append(module.GYamlConf.BeServers[:nid], module.GYamlConf.BeServers[nid+1:]...) + } else { + module.GYamlConf.BeServers = module.GYamlConf.BeServers[:nid] + } + // module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + + module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + infoMess = fmt.Sprintf("Scale in BE node successfully. [clusterName = %s, nodeId = %s]", clusterName, nodeId) + utl.Log("OUTPUT", infoMess) + + } else if tmpNodeType == "CN" { + sshHost = module.GYamlConf.CnServers[nid].Host + sshPort = module.GYamlConf.CnServers[nid].SshPort + beDeployDir = module.GYamlConf.CnServers[nid].DeployDir + beHeartbeatServicePort = module.GYamlConf.CnServers[nid].HeartbeatServicePort + err = stopCluster.StopCnNode(user, keyRsa, sshHost, sshPort, beDeployDir) + + if err != nil { + infoMess = fmt.Sprintf("Error in stop CN node. [nodeId = %s, error = %v]", nodeId, err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + time.Sleep(time.Duration(10) * time.Second) + + dropCmd = fmt.Sprintf("ALTER SYSTEM DROP COMPUTE NODE '%s:%d'", sshHost, beHeartbeatServicePort) + + _, err := utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, dropCmd) + + if err != nil { + infoMess = fmt.Sprintf("Error in scale in CN node. [clusterName = %s, nodeId = %s, error = %s]", clusterName, nodeId, err) + utl.Log("ERROR", infoMess) + } + + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.CnServers[nid].LogDir) + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.CnServers[nid].StorageDir) + utl.SshRun(user, keyRsa, sshHost, sshPort, "rm -rf "+module.GYamlConf.CnServers[nid].DeployDir) + + if nid != len(module.GYamlConf.CnServers)-1 { + module.GYamlConf.CnServers = append(module.GYamlConf.CnServers[:nid], module.GYamlConf.CnServers[nid+1:]...) + } else { + module.GYamlConf.CnServers = module.GYamlConf.CnServers[:nid] + } + + module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + infoMess = fmt.Sprintf("Scale in CN node successfully. [clusterName = %s, nodeId = %s]", clusterName, nodeId) + utl.Log("OUTPUT", infoMess) + + } else { + infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) + utl.Log("ERROR", infoMess) + } } - diff --git a/cluster/clusterOption/scaleOut.go b/cluster/clusterOption/scaleOut.go index 20b13f0..59ddde1 100644 --- a/cluster/clusterOption/scaleOut.go +++ b/cluster/clusterOption/scaleOut.go @@ -1,66 +1,62 @@ package clusterOption import ( - - "fmt" - "os" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" - "stargo/cluster/prepareOption" - "stargo/cluster/modifyConfig" - "stargo/cluster/startCluster" - + "fmt" + "os" + "stargo/cluster/checkStatus" + "stargo/cluster/modifyConfig" + "stargo/cluster/prepareOption" + "stargo/cluster/startCluster" + "stargo/module" + "stargo/sr-utl" ) func ScaleOut(clusterName string, scaleMetaFile string) { - var clusterVersion string - var infoMess string - // Get the cluster version - module.AppendConf(clusterName) - clusterVersion = module.GYamlConfAppend.ClusterInfo.Version - module.SetGlobalVar("GSRVersion", clusterVersion) - module.InitConf(clusterName, scaleMetaFile) - - - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - module.GYamlConf.Global = module.GYamlConfAppend.Global - - prepareOption.PreCheckSR() - prepareOption.CreateDir() - prepareOption.PrepareSRPkg() - prepareOption.DistributeSrDir() - - tmpYamlConf := module.GYamlConfAppend - module.GYamlConfAppend = module.GYamlConf - module.GYamlConf = tmpYamlConf - - tmpYamlConf.FeServers = append(module.GYamlConf.FeServers, module.GYamlConfAppend.FeServers[0:]...) - tmpYamlConf.BeServers = append(module.GYamlConf.BeServers, module.GYamlConfAppend.BeServers[0:]...) - //fmt.Println("DEBUG >>> tmpYamlConf", tmpYamlConf) - module.WriteBackMeta(tmpYamlConf, module.GYamlConf.ClusterInfo.MetaPath) - -// fmt.Println("DEBUG >>> GYamlConfAppend.FeServers", module.GYamlConfAppend.FeServers) -// fmt.Println("################################################") -// fmt.Println("DEBUG >>> GYamlConf.FeServers", module.GYamlConf.FeServers) -// fmt.Println("################################################") -// fmt.Println("DEBUG >>> tmpYamlConf.FeServers", tmpYamlConf.FeServers) - - - - modifyConfig.ModifyClusterConfig() - fmt.Println("############################################# SCALE OUT FE CLUSTER #############################################") - fmt.Println("############################################# SCALE OUT FE CLUSTER #############################################") - startCluster.InitFeCluster(module.GYamlConfAppend) - fmt.Println("############################################# START BE CLUSTER #############################################") - fmt.Println("############################################# START BE CLUSTER #############################################") - startCluster.InitBeCluster(module.GYamlConfAppend) - + var clusterVersion string + var infoMess string + // Get the cluster version + module.AppendConf(clusterName) + clusterVersion = module.GYamlConfAppend.ClusterInfo.Version + module.SetGlobalVar("GSRVersion", clusterVersion) + module.InitConf(clusterName, scaleMetaFile) + isSharedData := module.IsSharedDataCluster() + + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + module.GYamlConf.Global = module.GYamlConfAppend.Global + + prepareOption.PreCheckSR() + prepareOption.CreateDir() + prepareOption.PrepareSRPkg() + prepareOption.DistributeSrDir() + + tmpYamlConf := module.GYamlConfAppend + module.GYamlConfAppend = module.GYamlConf + module.GYamlConf = tmpYamlConf + + tmpYamlConf.FeServers = append(module.GYamlConf.FeServers, module.GYamlConfAppend.FeServers[0:]...) + tmpYamlConf.BeServers = append(module.GYamlConf.BeServers, module.GYamlConfAppend.BeServers[0:]...) + tmpYamlConf.CnServers = append(module.GYamlConf.CnServers, module.GYamlConfAppend.CnServers[0:]...) + module.WriteBackMeta(tmpYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + + modifyConfig.ModifyClusterConfig() + fmt.Println("############################################# SCALE OUT FE CLUSTER #############################################") + fmt.Println("############################################# SCALE OUT FE CLUSTER #############################################") + startCluster.InitFeCluster(module.GYamlConfAppend) + if len(module.GYamlConfAppend.BeServers) > 0 && !isSharedData { + fmt.Println("############################################# START BE CLUSTER #############################################") + fmt.Println("############################################# START BE CLUSTER #############################################") + startCluster.InitBeCluster(module.GYamlConfAppend) + } + if len(module.GYamlConfAppend.CnServers) > 0 { + fmt.Println("############################################# START CN CLUSTER #############################################") + fmt.Println("############################################# START CN CLUSTER #############################################") + startCluster.InitCnCluster(module.GYamlConfAppend) + } } diff --git a/cluster/clusterOption/start.go b/cluster/clusterOption/start.go index ba1da27..1f519b7 100644 --- a/cluster/clusterOption/start.go +++ b/cluster/clusterOption/start.go @@ -1,148 +1,153 @@ package clusterOption -import( - "stargo/cluster/startCluster" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" - "os" - "fmt" +import ( + "fmt" + "os" + "stargo/cluster/checkStatus" + "stargo/cluster/startCluster" + "stargo/module" + "stargo/sr-utl" ) - func Start(clusterName string, nodeId string, role string) { - var infoMess string - //var tmpNodeType string - var tmpNodeHost string - var tmpNodePort int - var tmpUser string - var tmpKeyRsa string - var tmpSshPort int - var tmpDeployDir string - //var tmpNodeInd int - - module.InitConf(clusterName, "") - - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } - // start all cluster: sr-ctl-cluster start sr-c1 - // start 1 node: sr-ctl-cluster start sr-c1 --node 192.168.88.33:9010 - // start all FE node: sr-ctl-cluster start sr-c1 --role FE - // start all BE node: sr-ctl-cluster start sr-c1 --role BE - - // start all cluster: sr-ctl-cluster start sr-c1 - - - // ----------------------------------------------------------------------------------------- - // | case id | node id | role | option | - // ----------------------------------------------------------------------------------------- - // | 1 | null | null | start all cluster | - // | 2 | null | !null | start FE or BE cluster | - // | 3 | !null | null | start the FE/BE node (BE only) | - // | 4 | !null | !null | error | - // ----------------------------------------------------------------------------------------- - if nodeId == module.NULLSTR && role == module.NULLSTR { - // case id 1: - start all cluster: sr-ctl-cluster start sr-c1 - startCluster.StartFeCluster() - startCluster.StartBeCluster() - } // end of case 1 - - if nodeId == module.NULLSTR && role != module.NULLSTR { - // case id 2: start FE or BE cluster - if role == "FE" { - infoMess = "Starting FE cluster ...." - utl.Log("INFO", infoMess) - startCluster.StartFeCluster() - } else if role == "BE" { - startCluster.StartBeCluster() - infoMess = "Starting BE cluster ..." - utl.Log("INFO", infoMess) - } else { - infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) - utl.Log("ERROR", infoMess) - } - } // end of case 2 - - if nodeId != module.NULLSTR && role == module.NULLSTR { - // case id 3: start the FE/BE node - // get the node type - tmpNodeType, i := checkStatus.GetNodeType(nodeId) - if tmpNodeType == "FE" { - infoMess = "Please use --role FE to start all the FE node." - utl.Log("ERROR", infoMess) - os.Exit(1) - //tmpNodeHost = module.GYamlConf.FeServers[i].Host - //tmpSshPort = module.GYamlConf.FeServers[i].SshPort - //tmpNodePort = module.GYamlConf.FeServers[i].EditLogPort - //tmpDeployDir = module.GYamlConf.FeServers[i].DeployDir - //startCluster.StartFeNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpNodePort, tmpDeployDir) - } else if tmpNodeType == "BE" { - tmpNodeHost = module.GYamlConf.BeServers[i].Host - tmpSshPort = module.GYamlConf.BeServers[i].SshPort - tmpNodePort = module.GYamlConf.BeServers[i].HeartbeatServicePort - tmpDeployDir = module.GYamlConf.BeServers[i].DeployDir - infoMess = fmt.Sprintf("Start BE node. [BeHost = %s, HeartbeatServicePort = %d]", tmpNodeHost, tmpNodePort) - utl.Log("INFO", infoMess) - startCluster.StartBeNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpNodePort, tmpDeployDir) - } else { - infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) - utl.Log("ERROR", infoMess) + var infoMess string + //var tmpNodeType string + var tmpNodeHost string + var tmpNodePort int + var tmpUser string + var tmpKeyRsa string + var tmpSshPort int + var tmpDeployDir string + //var tmpNodeInd int + + module.InitConf(clusterName, "") + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + isSharedData := module.IsSharedDataCluster() + + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) } - }// end of case 3 - - if nodeId != module.NULLSTR && role != module.NULLSTR { - infoMess = "Detect both --node & --role option." - utl.Log("ERROR", infoMess) - } // end of case 4 + // start all cluster: sr-ctl-cluster start sr-c1 + // start 1 node: sr-ctl-cluster start sr-c1 --node 192.168.88.33:9010 + // start all FE node: sr-ctl-cluster start sr-c1 --role FE + // start all BE node: sr-ctl-cluster start sr-c1 --role BE + + // start all cluster: sr-ctl-cluster start sr-c1 + + // ----------------------------------------------------------------------------------------- + // | case id | node id | role | option | + // ----------------------------------------------------------------------------------------- + // | 1 | null | null | start all cluster | + // | 2 | null | !null | start FE or BE cluster | + // | 3 | !null | null | start the FE/BE node (BE only) | + // | 4 | !null | !null | error | + // ----------------------------------------------------------------------------------------- + if nodeId == module.NULLSTR && role == module.NULLSTR { + // case id 1: - start all cluster: sr-ctl-cluster start sr-c1 + startCluster.StartFeCluster() + if !isSharedData { + startCluster.StartBeCluster() + } + if err := startCluster.StartCnCluster(); err != nil { + utl.Log("ERROR", err.Error()) + os.Exit(1) + } + if isSharedData && len(module.GYamlConf.CnServers) > 0 { + if err := startCluster.WaitSharedDataReady(module.GYamlConf); err != nil { + os.Exit(1) + } + } + } // end of case 1 + + if nodeId == module.NULLSTR && role != module.NULLSTR { + // case id 2: start FE or BE or CN cluster + if role == "FE" { + infoMess = "Starting FE cluster ...." + utl.Log("INFO", infoMess) + startCluster.StartFeCluster() + } else if role == "BE" { + if isSharedData { + infoMess = "Shared-data cluster does not use BE nodes. Please use role FE or CN." + utl.Log("ERROR", infoMess) + os.Exit(1) + } + startCluster.StartBeCluster() + infoMess = "Starting BE cluster ..." + utl.Log("INFO", infoMess) + } else if role == "CN" { + if err := startCluster.StartCnCluster(); err != nil { + utl.Log("ERROR", err.Error()) + os.Exit(1) + } + if isSharedData { + if err := startCluster.WaitSharedDataReady(module.GYamlConf); err != nil { + os.Exit(1) + } + } + infoMess = "Starting CN cluster ..." + utl.Log("INFO", infoMess) + } else { + infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) + utl.Log("ERROR", infoMess) + } + } // end of case 2 + + if nodeId != module.NULLSTR && role == module.NULLSTR { + // case id 3: start the FE/BE/CN node + // get the node type + tmpNodeType, i := checkStatus.GetNodeType(nodeId) + if tmpNodeType == "FE" { + infoMess = "Please use --role FE to start all the FE node." + utl.Log("ERROR", infoMess) + os.Exit(1) + //tmpNodeHost = module.GYamlConf.FeServers[i].Host + //tmpSshPort = module.GYamlConf.FeServers[i].SshPort + //tmpNodePort = module.GYamlConf.FeServers[i].EditLogPort + //tmpDeployDir = module.GYamlConf.FeServers[i].DeployDir + //startCluster.StartFeNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpNodePort, tmpDeployDir) + } else if tmpNodeType == "BE" { + if isSharedData { + infoMess = "Shared-data cluster does not use BE nodes. Please use CN nodes for compute capacity." + utl.Log("ERROR", infoMess) + os.Exit(1) + } + tmpNodeHost = module.GYamlConf.BeServers[i].Host + tmpSshPort = module.GYamlConf.BeServers[i].SshPort + tmpNodePort = module.GYamlConf.BeServers[i].HeartbeatServicePort + tmpDeployDir = module.GYamlConf.BeServers[i].DeployDir + infoMess = fmt.Sprintf("Start BE node. [BeHost = %s, HeartbeatServicePort = %d]", tmpNodeHost, tmpNodePort) + utl.Log("INFO", infoMess) + startCluster.StartBeNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpNodePort, tmpDeployDir) + } else if tmpNodeType == "CN" { + tmpNodeHost = module.GYamlConf.CnServers[i].Host + tmpSshPort = module.GYamlConf.CnServers[i].SshPort + tmpNodePort = module.GYamlConf.CnServers[i].HeartbeatServicePort + tmpDeployDir = module.GYamlConf.CnServers[i].DeployDir + infoMess = fmt.Sprintf("Start CN node. [CnHost = %s, HeartbeatServicePort = %d]", tmpNodeHost, tmpNodePort) + utl.Log("INFO", infoMess) + if portStat, _ := checkStatus.CheckCnPortStatus(i); !portStat { + if err := startCluster.StartCnNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpNodePort, tmpDeployDir); err != nil { + utl.Log("ERROR", err.Error()) + os.Exit(1) + } + } else { + infoMess = fmt.Sprintf("CN node already running [CnHost = %s, HeartbeatServicePort = %d]", tmpNodeHost, tmpNodePort) + utl.Log("INFO", infoMess) + } + } else { + infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) + utl.Log("ERROR", infoMess) + } + } // end of case 3 + + if nodeId != module.NULLSTR && role != module.NULLSTR { + infoMess = "Detect both --node & --role option." + utl.Log("ERROR", infoMess) + } // end of case 4 } - - -/* -func getNodeType(nodeId string) (nodeType string, nodeInd int) { - - // FEID: module.GYamlConf.FeServers[i].EditLogPort, module.GYamlConf.FeServers[i].QueryPort - // BEID: module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].BePort - - tmpNodeId := strings.Split(nodeId, ":") - fmt.Println("DEBUG>>>>>>>>>>>>>>>>>>>>>>>>>", tmpNodeId) - - // check FE - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - - if tmpNodeId[0] == module.GYamlConf.FeServers[i].Host && - tmpNodeId[1] == strconv.Itoa(module.GYamlConf.FeServers[i].EditLogPort) { - nodeType = "FE" - //ip = module.GYamlConf.FeServers[i].Host - //port = tmpNodeId[1] == module.GYamlConf.FeServers[i].EditLogPort - nodeInd = i - break - } - } - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - - if tmpNodeId[0] == module.GYamlConf.BeServers[i].Host && - tmpNodeId[1] == strconv.Itoa(module.GYamlConf.BeServers[i].BePort) { - nodeType = "BE" - //ip = module.GYamlConf.BeServers[i].Host - //port = module.GYamlConf.BeServers[i].BePort - nodeInd = i - break - } - } - - return nodeType, nodeInd - -} - -*/ - - diff --git a/cluster/clusterOption/stop.go b/cluster/clusterOption/stop.go index 19decbb..541b2d7 100644 --- a/cluster/clusterOption/stop.go +++ b/cluster/clusterOption/stop.go @@ -1,146 +1,134 @@ package clusterOption -import( - "stargo/cluster/stopCluster" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" - "fmt" - "os" +import ( + "fmt" + "os" + "stargo/cluster/checkStatus" + "stargo/cluster/stopCluster" + "stargo/module" + "stargo/sr-utl" ) - func Stop(clusterName string, nodeId string, role string) { - var infoMess string - //var tmpNodeType string - var tmpNodeHost string - var tmpUser string - var tmpKeyRsa string - var tmpSshPort int - var tmpDeployDir string - //var tmpNodeInd int - - module.InitConf(clusterName, "") - - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - // stop all cluster: sr-ctl-cluster stop sr-c1 - // stop 1 node: sr-ctl-cluster stop sr-c1 --node 192.168.88.33:9010 - // stop all FE node: sr-ctl-cluster stop sr-c1 --role FE - // stop all BE node: sr-ctl-cluster stop sr-c1 --role BE - - - - // ----------------------------------------------------------------------------------------- - // | case id | node id | role | option | - // ----------------------------------------------------------------------------------------- - // | 1 | null | null | stop all cluster | - // | 2 | null | !null | stop FE or BE cluster | - // | 3 | !null | null | stop the FE/BE node (BE only) | - // | 4 | !null | !null | error | - // ----------------------------------------------------------------------------------------- - if nodeId == module.NULLSTR && role == module.NULLSTR { - // case id 1: - stop all cluster: sr-ctl-cluster stop sr-c1 - stopCluster.StopFeCluster(clusterName) - stopCluster.StopBeCluster(clusterName) - } // end of case 1 - - if nodeId == module.NULLSTR && role != module.NULLSTR { - // case id 2: stop FE or BE cluster - if role == "FE" { - infoMess = "Stopping FE cluster ...." - utl.Log("INFO", infoMess) - stopCluster.StopFeCluster(clusterName) - } else if role == "BE" { - infoMess = "Stopping BE cluster ..." - utl.Log("INFO", infoMess) - stopCluster.StopBeCluster(clusterName) - } else { - infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) - utl.Log("ERROR", infoMess) - } - } // end of case 2 - - if nodeId != module.NULLSTR && role == module.NULLSTR { - // case id 3: stop the FE/BE node - // get the node type - tmpNodeType, i := checkStatus.GetNodeType(nodeId) - if tmpNodeType == "FE" { - tmpNodeHost = module.GYamlConf.FeServers[i].Host - tmpSshPort = module.GYamlConf.FeServers[i].SshPort - tmpDeployDir = module.GYamlConf.FeServers[i].DeployDir - // func StopFeNode(user string, keyRsa string, sshHost string, sshPort int, feDeployDir string) (err error) - // func StopBeNode(user string, keyRsa string, sshHost string, sshPort int, beDeployDir string) (err error) - infoMess = fmt.Sprintf("Stopping FE node. [BeHost = %s]", tmpNodeHost) - utl.Log("INFO", infoMess) - stopCluster.StopFeNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpDeployDir) - } else if tmpNodeType == "BE" { - tmpNodeHost = module.GYamlConf.BeServers[i].Host - tmpSshPort = module.GYamlConf.BeServers[i].SshPort - tmpDeployDir = module.GYamlConf.BeServers[i].DeployDir - infoMess = fmt.Sprintf("Stopping BE node. [BeHost = %s]", tmpNodeHost) - utl.Log("INFO", infoMess) - stopCluster.StopBeNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpDeployDir) - } else { - infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) - utl.Log("ERROR", infoMess) + var infoMess string + //var tmpNodeType string + var tmpNodeHost string + var tmpUser string + var tmpKeyRsa string + var tmpSshPort int + var tmpDeployDir string + //var tmpNodeInd int + + module.InitConf(clusterName, "") + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + isSharedData := module.IsSharedDataCluster() + + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) } - }// end of case 3 - if nodeId != module.NULLSTR && role != module.NULLSTR { - infoMess = "Detect both --node & --role option." - utl.Log("ERROR", infoMess) - } // end of case 4 + // stop all cluster: sr-ctl-cluster stop sr-c1 + // stop 1 node: sr-ctl-cluster stop sr-c1 --node 192.168.88.33:9010 + // stop all FE node: sr-ctl-cluster stop sr-c1 --role FE + // stop all BE node: sr-ctl-cluster stop sr-c1 --role BE + + // ----------------------------------------------------------------------------------------- + // | case id | node id | role | option | + // ----------------------------------------------------------------------------------------- + // | 1 | null | null | stop all cluster | + // | 2 | null | !null | stop FE or BE cluster | + // | 3 | !null | null | stop the FE/BE node (BE only) | + // | 4 | !null | !null | error | + // ----------------------------------------------------------------------------------------- + if nodeId == module.NULLSTR && role == module.NULLSTR { + // case id 1: - stop all cluster: sr-ctl-cluster stop sr-c1 + stopCluster.StopFeCluster(clusterName) + if !isSharedData { + stopCluster.StopBeCluster(clusterName) + } + if err := stopCluster.StopCnCluster(clusterName); err != nil { + utl.Log("ERROR", err.Error()) + os.Exit(1) + } + } // end of case 1 + + if nodeId == module.NULLSTR && role != module.NULLSTR { + // case id 2: stop FE or BE or CN cluster + if role == "FE" { + infoMess = "Stopping FE cluster ...." + utl.Log("INFO", infoMess) + stopCluster.StopFeCluster(clusterName) + } else if role == "BE" { + if isSharedData { + infoMess = "Shared-data cluster does not use BE nodes. Please use role FE or CN." + utl.Log("ERROR", infoMess) + os.Exit(1) + } + infoMess = "Stopping BE cluster ..." + utl.Log("INFO", infoMess) + stopCluster.StopBeCluster(clusterName) + } else if role == "CN" { + infoMess = "Stopping CN cluster ..." + utl.Log("INFO", infoMess) + if err := stopCluster.StopCnCluster(clusterName); err != nil { + utl.Log("ERROR", err.Error()) + os.Exit(1) + } + } else { + infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) + utl.Log("ERROR", infoMess) + } + } // end of case 2 + + if nodeId != module.NULLSTR && role == module.NULLSTR { + // case id 3: stop the FE/BE/CN node + // get the node type + tmpNodeType, i := checkStatus.GetNodeType(nodeId) + if tmpNodeType == "FE" { + tmpNodeHost = module.GYamlConf.FeServers[i].Host + tmpSshPort = module.GYamlConf.FeServers[i].SshPort + tmpDeployDir = module.GYamlConf.FeServers[i].DeployDir + // func StopFeNode(user string, keyRsa string, sshHost string, sshPort int, feDeployDir string) (err error) + // func StopBeNode(user string, keyRsa string, sshHost string, sshPort int, beDeployDir string) (err error) + infoMess = fmt.Sprintf("Stopping FE node. [BeHost = %s]", tmpNodeHost) + utl.Log("INFO", infoMess) + stopCluster.StopFeNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpDeployDir) + } else if tmpNodeType == "BE" { + if isSharedData { + infoMess = "Shared-data cluster does not use BE nodes. Please use CN nodes for compute capacity." + utl.Log("ERROR", infoMess) + os.Exit(1) + } + tmpNodeHost = module.GYamlConf.BeServers[i].Host + tmpSshPort = module.GYamlConf.BeServers[i].SshPort + tmpDeployDir = module.GYamlConf.BeServers[i].DeployDir + infoMess = fmt.Sprintf("Stopping BE node. [BeHost = %s]", tmpNodeHost) + utl.Log("INFO", infoMess) + stopCluster.StopBeNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpDeployDir) + } else if tmpNodeType == "CN" { + tmpNodeHost = module.GYamlConf.CnServers[i].Host + tmpSshPort = module.GYamlConf.CnServers[i].SshPort + tmpDeployDir = module.GYamlConf.CnServers[i].DeployDir + infoMess = fmt.Sprintf("Stopping CN node. [CnHost = %s]", tmpNodeHost) + utl.Log("INFO", infoMess) + if err := stopCluster.StopCnNode(tmpUser, tmpKeyRsa, tmpNodeHost, tmpSshPort, tmpDeployDir); err != nil { + utl.Log("ERROR", err.Error()) + os.Exit(1) + } + } else { + infoMess = fmt.Sprintf("Error in get Node type. Please check the nodeId. You can use 'sr-ctl-cluster display %s ' to check the node id.[NodeId = %s]", clusterName, nodeId) + utl.Log("ERROR", infoMess) + } + } // end of case 3 + + if nodeId != module.NULLSTR && role != module.NULLSTR { + infoMess = "Detect both --node & --role option." + utl.Log("ERROR", infoMess) + } // end of case 4 } - - -/* -func getNodeType(nodeId string) (nodeType string, nodeInd int) { - - // FEID: module.GYamlConf.FeServers[i].EditLogPort, module.GYamlConf.FeServers[i].QueryPort - // BEID: module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].BePort - - tmpNodeId := strings.Split(nodeId, ":") - fmt.Println("DEBUG>>>>>>>>>>>>>>>>>>>>>>>>>", tmpNodeId) - - // check FE - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - - if tmpNodeId[0] == module.GYamlConf.FeServers[i].Host && - tmpNodeId[1] == strconv.Itoa(module.GYamlConf.FeServers[i].EditLogPort) { - nodeType = "FE" - //ip = module.GYamlConf.FeServers[i].Host - //port = tmpNodeId[1] == module.GYamlConf.FeServers[i].EditLogPort - nodeInd = i - break - } - } - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - - if tmpNodeId[0] == module.GYamlConf.BeServers[i].Host && - tmpNodeId[1] == strconv.Itoa(module.GYamlConf.BeServers[i].BePort) { - nodeType = "BE" - //ip = module.GYamlConf.BeServers[i].Host - //port = module.GYamlConf.BeServers[i].BePort - nodeInd = i - break - } - } - - return nodeType, nodeInd - -} - -*/ - - diff --git a/cluster/clusterOption/test.go b/cluster/clusterOption/test.go index df30775..cec78c3 100644 --- a/cluster/clusterOption/test.go +++ b/cluster/clusterOption/test.go @@ -1,21 +1,17 @@ package clusterOption import ( - - "stargo/module" - "stargo/cluster/prepareOption" - + "stargo/cluster/prepareOption" + "stargo/module" ) - // sr-ctl-cluster deploy sr-c1 v2.0.1 /tmp/sr-c1.yaml func TestOpt() { - clusterName := "test-sr" - metaFile := "sr-c1.yaml" - module.InitConf(clusterName, metaFile) - prepareOption.PreCheckSR() - -} + clusterName := "test-sr" + metaFile := "sr-c1.yaml" + module.InitConf(clusterName, metaFile) + prepareOption.PreCheckSR() +} diff --git a/cluster/clusterOption/upgrade.go b/cluster/clusterOption/upgrade.go index 6f6a4bc..6c82d18 100644 --- a/cluster/clusterOption/upgrade.go +++ b/cluster/clusterOption/upgrade.go @@ -1,46 +1,55 @@ package clusterOption -import( - - "fmt" - "os" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" - "stargo/cluster/prepareOption" - "stargo/cluster/upgradeCluster" +import ( + "fmt" + "os" + "stargo/cluster/checkStatus" + "stargo/cluster/prepareOption" + "stargo/cluster/startCluster" + "stargo/cluster/upgradeCluster" + "stargo/module" + "stargo/sr-utl" ) func Upgrade(clusterName string, clusterVersion string) { - var infoMess string - //var err error - - - module.InitConf(clusterName, "") - module.SetGlobalVar("GSRVersion", clusterVersion) - - if checkStatus.CheckClusterName(clusterName) { - infoMess = "Don't find the Cluster " + clusterName - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - oldVersion := module.GYamlConf.ClusterInfo.Version - newVersion := clusterVersion - if !(oldVersion < newVersion) { - infoMess = fmt.Sprintf("OldVersion = %s NewVersion = %s, the NewVersion is not higher than OldVersion", oldVersion, newVersion) - utl.Log("ERROR", infoMess) - os.Exit(1) - } else { - infoMess = fmt.Sprintf("Upgrade StarRocks Cluster %s, from version %s to version %s", clusterName, oldVersion, newVersion) - utl.Log("OUTPUT", infoMess) - } - - prepareOption.PrepareSRPkg() - upgradeCluster.UpgradeBeCluster() - upgradeCluster.UpgradeFeCluster() - - module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + var infoMess string + //var err error + + module.InitConf(clusterName, "") + module.SetGlobalVar("GSRVersion", clusterVersion) + + if checkStatus.CheckClusterName(clusterName) { + infoMess = "Don't find the Cluster " + clusterName + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + oldVersion := module.GYamlConf.ClusterInfo.Version + newVersion := clusterVersion + if module.CompareStarRocksVersions(oldVersion, newVersion) >= 0 { + infoMess = fmt.Sprintf("OldVersion = %s NewVersion = %s, the NewVersion is not higher than OldVersion", oldVersion, newVersion) + utl.Log("ERROR", infoMess) + os.Exit(1) + } else { + infoMess = fmt.Sprintf("Upgrade StarRocks Cluster %s, from version %s to version %s", clusterName, oldVersion, newVersion) + utl.Log("OUTPUT", infoMess) + } + + prepareOption.PrepareSRPkg() + if module.IsSharedDataCluster() { + upgradeCluster.UpgradeFeCluster() + upgradeCluster.UpgradeCnCluster() + if err := startCluster.WaitSharedDataReady(module.GYamlConf); err != nil { + os.Exit(1) + } + module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) + return + } + + upgradeCluster.UpgradeBeCluster() + upgradeCluster.UpgradeFeCluster() + + module.WriteBackMeta(module.GYamlConf, module.GYamlConf.ClusterInfo.MetaPath) } diff --git a/cluster/destroyCluster/destroyCluster.go b/cluster/destroyCluster/destroyCluster.go index 96c7674..b004a03 100644 --- a/cluster/destroyCluster/destroyCluster.go +++ b/cluster/destroyCluster/destroyCluster.go @@ -1,112 +1,107 @@ package destroyCluster -import( - "fmt" - "os" - "stargo/sr-utl" - "stargo/module" +import ( + "fmt" + "os" + "stargo/module" + "stargo/sr-utl" ) func DestroyCluster(clusterName string) { - rmFeDir(clusterName) - rmBeDir(clusterName) - rmMeta(clusterName) + rmFeDir(clusterName) + rmBeDir(clusterName) + rmMeta(clusterName) } - func rmFeDir(clusterName string) { - var infoMess string - var tmpFeDeployDir string - var tmpFeMetaDir string - var tmpUser string - var tmpKeyRsa string - var tmpFeHost string - var tmpFeSshPort int - var tmpRemoveDeployCmd string - var tmpRemoveMetaCmd string - - - - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - - tmpFeDeployDir = module.GYamlConf.FeServers[i].DeployDir - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - tmpFeMetaDir = module.GYamlConf.FeServers[i].MetaDir - tmpFeHost = module.GYamlConf.FeServers[i].Host - tmpFeSshPort = module.GYamlConf.FeServers[i].SshPort - tmpRemoveDeployCmd = "rm -rf " + tmpFeDeployDir - tmpRemoveMetaCmd = "rm -rf " + tmpFeMetaDir - - // remove deploy dir - infoMess = fmt.Sprintf("Waiting for remove FE deploy dir. [FeHost = %s, DeployDir = %s]", tmpFeHost, tmpRemoveDeployCmd) - utl.Log("INFO", infoMess) - _, _ = utl.SshRun(tmpUser, tmpKeyRsa, tmpFeHost, tmpFeSshPort, tmpRemoveDeployCmd) - - infoMess = fmt.Sprintf("Waiting for remove FE meta dir. [FeHost = %s, MetaDir = %s]", tmpFeHost, tmpRemoveMetaCmd) - utl.Log("INFO", infoMess) - _, _ = utl.SshRun(tmpUser, tmpKeyRsa, tmpFeHost, tmpFeSshPort, tmpRemoveMetaCmd) - - infoMess = fmt.Sprintf("Fe node removed. [FeHost = %s]", tmpFeHost) - utl.Log("OUTPUT", infoMess) - } + var infoMess string + var tmpFeDeployDir string + var tmpFeMetaDir string + var tmpUser string + var tmpKeyRsa string + var tmpFeHost string + var tmpFeSshPort int + var tmpRemoveDeployCmd string + var tmpRemoveMetaCmd string + + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + + tmpFeDeployDir = module.GYamlConf.FeServers[i].DeployDir + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + tmpFeMetaDir = module.GYamlConf.FeServers[i].MetaDir + tmpFeHost = module.GYamlConf.FeServers[i].Host + tmpFeSshPort = module.GYamlConf.FeServers[i].SshPort + tmpRemoveDeployCmd = "rm -rf " + tmpFeDeployDir + tmpRemoveMetaCmd = "rm -rf " + tmpFeMetaDir + + // remove deploy dir + infoMess = fmt.Sprintf("Waiting for remove FE deploy dir. [FeHost = %s, DeployDir = %s]", tmpFeHost, tmpRemoveDeployCmd) + utl.Log("INFO", infoMess) + _, _ = utl.SshRun(tmpUser, tmpKeyRsa, tmpFeHost, tmpFeSshPort, tmpRemoveDeployCmd) + + infoMess = fmt.Sprintf("Waiting for remove FE meta dir. [FeHost = %s, MetaDir = %s]", tmpFeHost, tmpRemoveMetaCmd) + utl.Log("INFO", infoMess) + _, _ = utl.SshRun(tmpUser, tmpKeyRsa, tmpFeHost, tmpFeSshPort, tmpRemoveMetaCmd) + + infoMess = fmt.Sprintf("Fe node removed. [FeHost = %s]", tmpFeHost) + utl.Log("OUTPUT", infoMess) + } } func rmBeDir(clusterName string) { - var infoMess string - var tmpBeDeployDir string - var tmpBeStorageDir string - var tmpUser string - var tmpKeyRsa string - var tmpBeHost string - var tmpBeSshPort int - var tmpRemoveDeployCmd string - var tmpRemoveStorageCmd string - - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - - tmpBeDeployDir = module.GYamlConf.BeServers[i].DeployDir - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - tmpBeStorageDir = module.GYamlConf.BeServers[i].StorageDir - tmpBeHost = module.GYamlConf.BeServers[i].Host - tmpBeSshPort = module.GYamlConf.BeServers[i].SshPort - tmpRemoveDeployCmd = "rm -rf " + tmpBeDeployDir - tmpRemoveStorageCmd = "rm -rf " + tmpBeStorageDir - - // remove deploy dir - infoMess = fmt.Sprintf("Waiting for remove BE deploy dir. [BeHost = %s, DeployDir = %s]", tmpBeHost, tmpRemoveDeployCmd) - utl.Log("INFO", infoMess) - _, _ = utl.SshRun(tmpUser, tmpKeyRsa, tmpBeHost, tmpBeSshPort, tmpRemoveDeployCmd) - - infoMess = fmt.Sprintf("Waiting for remove BE storage dir. [BeHost = %s, StorageDir = %s]", tmpBeHost, tmpRemoveStorageCmd) - utl.Log("INFO", infoMess) - _, _ = utl.SshRun(tmpUser, tmpKeyRsa, tmpBeHost, tmpBeSshPort, tmpRemoveStorageCmd) - - infoMess = fmt.Sprintf("Be node removed. [BeHost = %s]", tmpBeHost) - utl.Log("OUTPUT", infoMess) - } + var infoMess string + var tmpBeDeployDir string + var tmpBeStorageDir string + var tmpUser string + var tmpKeyRsa string + var tmpBeHost string + var tmpBeSshPort int + var tmpRemoveDeployCmd string + var tmpRemoveStorageCmd string + + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + + tmpBeDeployDir = module.GYamlConf.BeServers[i].DeployDir + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + tmpBeStorageDir = module.GYamlConf.BeServers[i].StorageDir + tmpBeHost = module.GYamlConf.BeServers[i].Host + tmpBeSshPort = module.GYamlConf.BeServers[i].SshPort + tmpRemoveDeployCmd = "rm -rf " + tmpBeDeployDir + tmpRemoveStorageCmd = "rm -rf " + tmpBeStorageDir + + // remove deploy dir + infoMess = fmt.Sprintf("Waiting for remove BE deploy dir. [BeHost = %s, DeployDir = %s]", tmpBeHost, tmpRemoveDeployCmd) + utl.Log("INFO", infoMess) + _, _ = utl.SshRun(tmpUser, tmpKeyRsa, tmpBeHost, tmpBeSshPort, tmpRemoveDeployCmd) + + infoMess = fmt.Sprintf("Waiting for remove BE storage dir. [BeHost = %s, StorageDir = %s]", tmpBeHost, tmpRemoveStorageCmd) + utl.Log("INFO", infoMess) + _, _ = utl.SshRun(tmpUser, tmpKeyRsa, tmpBeHost, tmpBeSshPort, tmpRemoveStorageCmd) + + infoMess = fmt.Sprintf("Be node removed. [BeHost = %s]", tmpBeHost) + utl.Log("OUTPUT", infoMess) + } } - func rmMeta(clusterName string) { - var infoMess string - var metaFileDir string - - metaFileDir = fmt.Sprintf("%s/cluster/%s", module.GSRCtlRoot, clusterName) - err := os.RemoveAll(metaFileDir) - if err != nil { - infoMess = fmt.Sprintf("Error in remove the meta dir. [Dir = %s]", metaFileDir) - utl.Log("ERROR", infoMess) - } else { - infoMess = fmt.Sprintf("Meta Dir removed. [Dir = %s]", metaFileDir) - utl.Log("OUTPUT", infoMess) - } + var infoMess string + var metaFileDir string + + metaFileDir = fmt.Sprintf("%s/cluster/%s", module.GSRCtlRoot, clusterName) + err := os.RemoveAll(metaFileDir) + if err != nil { + infoMess = fmt.Sprintf("Error in remove the meta dir. [Dir = %s]", metaFileDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("Meta Dir removed. [Dir = %s]", metaFileDir) + utl.Log("OUTPUT", infoMess) + } } diff --git a/cluster/displayCluster/clusterStatus.go b/cluster/displayCluster/clusterStatus.go index 98c2f95..56d4d83 100644 --- a/cluster/displayCluster/clusterStatus.go +++ b/cluster/displayCluster/clusterStatus.go @@ -1,128 +1,167 @@ package clusterStatus -import( - "fmt" -// "errors" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" +import ( + "fmt" + "stargo/cluster/checkStatus" + + // "errors" + "stargo/module" + utl "stargo/sr-utl" ) func ClusterStat(clusterName string) { - var infoMess string - fmt.Printf("clusterName = %s\n", clusterName) - fmt.Printf("clusterVerison = %s\n", module.GYamlConf.ClusterInfo.Version) - //metaFile := "/tmp/c1-meta.yaml" - //module.InitConf(metaFile) - - var tmpID string - var tmpRole string - var tmpHost string - var tmpPort string - var tmpStat string - var tmpDataDir string - var tmpDeployDir string - var feEntryId int - var noFeEntry bool - var err error - - // Get FE entry - feEntryId, err = checkStatus.GetFeEntry(-1) - if err != nil || feEntryId == -1 { - infoMess = "All FE nodes are down, please start FE node and display the cluster status again." - utl.Log("WARN", infoMess) - noFeEntry = true - } else { - // feEntryHost = module.GYamlConf.FeServers[feEntryId].Host - // feEntryQueryPort = module.GYamlConf.FeServers[feEntryId].QueryPort - module.SetFeEntry(feEntryId) - } - - tmpMinus := []byte("------------------------------------------------------------------------------------------------------") - fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", "ID", "ROLE", "HOST", "PORT", "STAT", "DATADIR", "DEPLOYDIR") - fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", tmpMinus[:26], tmpMinus[:6], tmpMinus[:20], tmpMinus[:15], tmpMinus[:10], tmpMinus[:50], tmpMinus[:50]) - // Get FE status - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - tmpID = fmt.Sprintf("%s:%d", module.GYamlConf.FeServers[i].Host, module.GYamlConf.FeServers[i].EditLogPort) - tmpRole = "FE" - tmpHost = module.GYamlConf.FeServers[i].Host - tmpPort = fmt.Sprintf("%d/%d", module.GYamlConf.FeServers[i].EditLogPort, module.GYamlConf.FeServers[i].QueryPort) - tmpDataDir = module.GYamlConf.FeServers[i].MetaDir - tmpDeployDir = module.GYamlConf.FeServers[i].DeployDir - - - if !noFeEntry { - - // If we can get a FE entry(more than one FE node is running), we can use [show frontends] command by JDBC) - // CheckFeStatus(feId int, user string, keyRsa string, sshHost string, sshPort int, feQueryPort int) (feStat FeStatusStruct, err error) - feStatStruct, err := checkStatus.CheckFeStatus(i) - if err != nil { - infoMess = fmt.Sprintf("Error in checking FE status [FeHost = %s, error = %v]", tmpHost, err) - utl.Log("DEBUG", infoMess) - } - - if feStatStruct["Alive"] == "true" { - if feStatStruct["IsMaster"] == "true" { - tmpStat = "UP/L" - } else { - tmpStat = "UP" - } - } else { - tmpStat = "DOWN" - } - - } else { - - // If we cannot get a FE entry, it means no FE node is running, so we don't need to check FE status using [show frontends] command - tmpStat = "DOWN" + var infoMess string + fmt.Printf("clusterName = %s\n", clusterName) + fmt.Printf("clusterVersion = %s\n", module.GYamlConf.ClusterInfo.Version) + //metaFile := "/tmp/c1-meta.yaml" + //module.InitConf(metaFile) + + var tmpID string + var tmpRole string + var tmpHost string + var tmpPort string + var tmpStat string + var tmpDataDir string + var tmpDeployDir string + var feEntryId int + var noFeEntry bool + var err error + + // Get FE entry + feEntryId, err = checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + infoMess = "All FE nodes are down, please start FE node and display the cluster status again." + utl.Log("WARN", infoMess) + noFeEntry = true + } else { + // feEntryHost = module.GYamlConf.FeServers[feEntryId].Host + // feEntryQueryPort = module.GYamlConf.FeServers[feEntryId].QueryPort + module.SetFeEntry(feEntryId) + } + + tmpMinus := []byte("------------------------------------------------------------------------------------------------------") + fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", "ID", "ROLE", "HOST", "PORT", "STAT", "DEPLOYDIR", "DATADIR") + fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", tmpMinus[:26], tmpMinus[:6], tmpMinus[:20], tmpMinus[:15], tmpMinus[:10], tmpMinus[:50], tmpMinus[:50]) + // Get FE status + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + tmpID = fmt.Sprintf("%s:%d", module.GYamlConf.FeServers[i].Host, module.GYamlConf.FeServers[i].EditLogPort) + tmpRole = "FE" + tmpHost = module.GYamlConf.FeServers[i].Host + tmpPort = fmt.Sprintf("%d/%d", module.GYamlConf.FeServers[i].EditLogPort, module.GYamlConf.FeServers[i].QueryPort) + tmpDataDir = module.GYamlConf.FeServers[i].MetaDir + tmpDeployDir = module.GYamlConf.FeServers[i].DeployDir + + if !noFeEntry { + + // If we can get a FE entry(more than one FE node is running), we can use [show frontends] command by JDBC) + // CheckFeStatus(feId int, user string, keyRsa string, sshHost string, sshPort int, feQueryPort int) (feStat FeStatusStruct, err error) + feStatStruct, err := checkStatus.CheckFeStatus(i) + if err != nil { + infoMess = fmt.Sprintf("Error in checking FE status [FeHost = %s, error = %v]", tmpHost, err) + utl.Log("DEBUG", infoMess) + } + + if feStatStruct["Alive"] == "true" { + if feStatStruct["IsMaster"] == "true" { + tmpStat = "UP/L" + } else { + tmpStat = "UP" + } + } else { + tmpStat = "DOWN" + } + + } else { + + // If we cannot get a FE entry, it means no FE node is running, so we don't need to check FE status using [show frontends] command + tmpStat = "DOWN" + } + // get the Dir output string + // if the dir output string is too long, only display the tail 43 chars + // for example, the tmpDeployDir is "/opt/starrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrocks/fe", + // it will show the tmpDeployDir "... rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrocks/fe" + + fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", tmpID, tmpRole, tmpHost, tmpPort, tmpStat, tmpDeployDir, tmpDataDir) + } - // get the Dir output string - // if the dir output string is too long, only display the tail 43 chars - // for example, the tmpDeployDir is "/opt/starrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrocks/fe", - // it will show the tmpDeployDir "... rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrocks/fe" - - fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", tmpID, tmpRole, tmpHost, tmpPort, tmpStat, tmpDeployDir, tmpDataDir) - - } - - // check BE status - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - - tmpID = fmt.Sprintf("%s:%d", module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].BePort) - tmpRole = "BE" - tmpHost = module.GYamlConf.BeServers[i].Host - tmpPort = fmt.Sprintf("%d/%d", module.GYamlConf.BeServers[i].BePort, module.GYamlConf.BeServers[i].HeartbeatServicePort) - tmpDataDir = module.GYamlConf.BeServers[i].StorageDir - tmpDeployDir = module.GYamlConf.BeServers[i].DeployDir - - - if !noFeEntry { - // If we can get a FE entry(more than one FE node is running), we can use [show backends] command by JDBC - // CheckBeStatus(beId int, user string, keyRsa string, sshHost string, sshPort int, heartbeatServicePort int) (beStat BeStatusStruct, err error) - beStat, err := checkStatus.CheckBeStatus(i) - if err != nil { - infoMess = fmt.Sprintf("Error in checking BE status [BeHost = %s, error = %v]", tmpHost, err) - utl.Log("DEBUG", infoMess) - } - - if beStat["Alive"] == "true" { - tmpStat = "UP" - } else { - tmpStat = "DOWN" - } - //fmt.Printf("id = %s\t role = %s\t host = %s\t tmpPort = %s\t tmpStat = %s\t tmpDataDir = %s\t tmpDeployDir = %s\n", tmpID, tmpRole, tmpHost, tmpPort, tmpStat, tmpDataDir, tmpDeployDir) - } else { - - // If we cannot get a FE entry, it means no FE node is running, so we don't need to check BE status using [show frontends] command, the BE status is "WAITING FE" - bePortRun, _ := checkStatus.CheckBePortStatus(i) - if bePortRun { - tmpStat = "WAITING FE" - } else { - tmpStat = "DOWN" - } + + // check BE status + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + + tmpID = fmt.Sprintf("%s:%d", module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].BePort) + tmpRole = "BE" + tmpHost = module.GYamlConf.BeServers[i].Host + tmpPort = fmt.Sprintf("%d/%d", module.GYamlConf.BeServers[i].BePort, module.GYamlConf.BeServers[i].HeartbeatServicePort) + tmpDataDir = module.GYamlConf.BeServers[i].StorageDir + tmpDeployDir = module.GYamlConf.BeServers[i].DeployDir + + if !noFeEntry { + // If we can get a FE entry(more than one FE node is running), we can use [show backends] command by JDBC + // CheckBeStatus(beId int, user string, keyRsa string, sshHost string, sshPort int, heartbeatServicePort int) (beStat BeStatusStruct, err error) + beStat, err := checkStatus.CheckBeStatus(i) + if err != nil { + infoMess = fmt.Sprintf("Error in checking BE status [BeHost = %s, error = %v]", tmpHost, err) + utl.Log("DEBUG", infoMess) + } + + if beStat["Alive"] == "true" { + tmpStat = "UP" + } else { + tmpStat = "DOWN" + infoMess = fmt.Sprintf("BE Status DOWN [BeHost = %s]: Alive field value = '%s'", tmpHost, beStat["Alive"]) + utl.Log("DEBUG", infoMess) + } + //fmt.Printf("id = %s\t role = %s\t host = %s\t tmpPort = %s\t tmpStat = %s\t tmpDataDir = %s\t tmpDeployDir = %s\n", tmpID, tmpRole, tmpHost, tmpPort, tmpStat, tmpDataDir, tmpDeployDir) + } else { + + // If we cannot get a FE entry, it means no FE node is running, so we don't need to check BE status using [show frontends] command, the BE status is "WAITING FE" + bePortRun, _ := checkStatus.CheckBePortStatus(i) + if bePortRun { + tmpStat = "WAITING FE" + } else { + tmpStat = "DOWN" + } + } + fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", tmpID, tmpRole, tmpHost, tmpPort, tmpStat, tmpDeployDir, tmpDataDir) + } + + // check CN status (Compute Nodes) + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + + tmpID = fmt.Sprintf("%s:%d", module.GYamlConf.CnServers[i].Host, module.GYamlConf.CnServers[i].BePort) + tmpRole = "CN" + tmpHost = module.GYamlConf.CnServers[i].Host + tmpPort = fmt.Sprintf("%d/%d", module.GYamlConf.CnServers[i].BePort, module.GYamlConf.CnServers[i].HeartbeatServicePort) + tmpDataDir = module.GYamlConf.CnServers[i].StorageDir + tmpDeployDir = module.GYamlConf.CnServers[i].DeployDir + + if !noFeEntry { + // If we can get a FE entry(more than one FE node is running), we can use [show compute nodes] command by JDBC + cnStat, err := checkStatus.CheckCnStatus(i) + if err != nil { + infoMess = fmt.Sprintf("Error in checking CN status [CnHost = %s, error = %v]", tmpHost, err) + utl.Log("DEBUG", infoMess) + } + + if cnStat["Alive"] == "true" { + tmpStat = "UP" + } else { + tmpStat = "DOWN" + infoMess = fmt.Sprintf("CN Status DOWN [CnHost = %s]: Alive field value = '%s'", tmpHost, cnStat["Alive"]) + utl.Log("DEBUG", infoMess) + } + } else { + + // If we cannot get a FE entry, it means no FE node is running, so we don't need to check CN status using [show compute nodes] command, the CN status is "WAITING FE" + cnPortRun, _ := checkStatus.CheckCnPortStatus(i) + if cnPortRun { + tmpStat = "WAITING FE" + } else { + tmpStat = "DOWN" + } + } + fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", tmpID, tmpRole, tmpHost, tmpPort, tmpStat, tmpDeployDir, tmpDataDir) } - fmt.Printf("%-26s %-6s %-20s %-15s %-10s %-50s %-50s\n", tmpID, tmpRole, tmpHost, tmpPort, tmpStat, tmpDeployDir, tmpDataDir) - } } diff --git a/cluster/downgradeCluster/downgradeBe.go b/cluster/downgradeCluster/downgradeBe.go index 4200da7..ddbd205 100644 --- a/cluster/downgradeCluster/downgradeBe.go +++ b/cluster/downgradeCluster/downgradeBe.go @@ -1,162 +1,142 @@ package downgradeCluster import ( - - "fmt" - "time" - "strings" - //"errors" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/stopCluster" - "stargo/cluster/startCluster" - "stargo/cluster/checkStatus" - //"stargo/cluster/prepareOption" - + "fmt" + "stargo/cluster/checkStatus" + "stargo/cluster/startCluster" + "stargo/cluster/stopCluster" + "strings" + "time" + //"errors" + "stargo/module" + "stargo/sr-utl" + //"stargo/cluster/prepareOption" ) - func DowngradeBeCluster() { //(err error){ - var infoMess string - var err error - var beStat map[string]string - var feEntryId int - - - feEntryId, err = checkStatus.GetFeEntry(-1) - if err != nil || feEntryId == -1 { - //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." - //utl.Log("WARN", infoMess) - module.SetFeEntry(0) - } else { - module.SetFeEntry(feEntryId) - } - - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - infoMess = fmt.Sprintf("Starting downgrade BE node. [beId = %d]", i) - utl.Log("OUTPUT", infoMess) - err = DowngradeBeNode(i) - if err != nil { - infoMess = fmt.Sprintf("Error in downgrade be node. [nodeid = %d]", i) - utl.Log("ERROR", infoMess) - } - - beStat, err = checkStatus.CheckBeStatus(i) - - - for j := 0; j < 3; j++ { - infoMess = fmt.Sprintf("The %d time to check be status: %v", j, beStat["Alive"]) - utl.Log("DEBUG", infoMess) - if beStat["Alive"] == "true" { - break - } else { - infoMess = fmt.Sprintf("The BE node doesn't work, wait for 10s and check the status again. [beId = %d]\n", i) - utl.Log("DEBUG", infoMess) - time.Sleep(10 * time.Second) - beStat, err = checkStatus.CheckBeStatus(i) - } - } - - - if err != nil { - infoMess = fmt.Sprintf("Error in get the Be status [beId = %d, error = %v]", i, err) - utl.Log("DEBUG", infoMess) - //return err - } - if beStat["Alive"] == "false" { - infoMess = fmt.Sprintf("The BE node downgrade failed. The BE node doesn't work. [beId = %d]\n", i) - utl.Log("ERROR", infoMess) - //return errors.New(infoMess) - } else if ! strings.Contains(beStat["Version"], strings.Replace(module.GSRVersion, "v", "", -1)) { - infoMess = fmt.Sprintf("The BE node downgrade failed. [beId = %d, targetVersion = %s, currentVersion = v%s]", i, module.GSRVersion, beStat["Version"]) - utl.Log("ERROR", infoMess) - //return errors.New(infoMess) - } else { - infoMess = fmt.Sprintf("The Be node downgrade successfully. [beId = %d, currentVersion = v%s]", i, beStat["Version"]) - utl.Log("OUTPUT", infoMess) - } - } - - //return nil - + var infoMess string + var err error + var beStat map[string]string + var feEntryId int + + feEntryId, err = checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." + //utl.Log("WARN", infoMess) + module.SetFeEntry(0) + } else { + module.SetFeEntry(feEntryId) + } + + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + infoMess = fmt.Sprintf("Starting downgrade BE node. [beId = %d]", i) + utl.Log("OUTPUT", infoMess) + err = DowngradeBeNode(i) + if err != nil { + infoMess = fmt.Sprintf("Error in downgrade be node. [nodeid = %d]", i) + utl.Log("ERROR", infoMess) + } + + beStat, err = checkStatus.CheckBeStatus(i) + + for j := 0; j < 3; j++ { + infoMess = fmt.Sprintf("The %d time to check be status: %v", j, beStat["Alive"]) + utl.Log("DEBUG", infoMess) + if beStat["Alive"] == "true" { + break + } else { + infoMess = fmt.Sprintf("The BE node doesn't work, wait for 10s and check the status again. [beId = %d]\n", i) + utl.Log("DEBUG", infoMess) + time.Sleep(10 * time.Second) + beStat, err = checkStatus.CheckBeStatus(i) + } + } + + if err != nil { + infoMess = fmt.Sprintf("Error in get the Be status [beId = %d, error = %v]", i, err) + utl.Log("DEBUG", infoMess) + //return err + } + if beStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The BE node downgrade failed. The BE node doesn't work. [beId = %d]\n", i) + utl.Log("ERROR", infoMess) + //return errors.New(infoMess) + } else if !strings.Contains(beStat["Version"], strings.Replace(module.GSRVersion, "v", "", -1)) { + infoMess = fmt.Sprintf("The BE node downgrade failed. [beId = %d, targetVersion = %s, currentVersion = v%s]", i, module.GSRVersion, beStat["Version"]) + utl.Log("ERROR", infoMess) + //return errors.New(infoMess) + } else { + infoMess = fmt.Sprintf("The Be node downgrade successfully. [beId = %d, currentVersion = v%s]", i, beStat["Version"]) + utl.Log("OUTPUT", infoMess) + } + } + + //return nil } - func DowngradeBeNode(beId int) (err error) { - // step 1. backup be lib - // step 2. upload new be lib - // step 3. stop be node - // step 4. start be node - - var infoMess string - var user string - var sourceDir string - var targetDir string - var sshHost string - var sshPort int - var beDeployDir string - var beHeartBeatServicePort int - var keyRsa string - - - user = module.GYamlConf.Global.User - keyRsa = module.GSshKeyRsa - sshHost = module.GYamlConf.BeServers[beId].Host - sshPort = module.GYamlConf.BeServers[beId].SshPort - beDeployDir = module.GYamlConf.BeServers[beId].DeployDir - beHeartBeatServicePort = module.GYamlConf.BeServers[beId].HeartbeatServicePort - - - - - // step1. backup be lib - sourceDir = fmt.Sprintf("%s/lib", beDeployDir) - targetDir = fmt.Sprintf("%s/lib.bak-%s", beDeployDir, time.Now().Format("20060102150405")) - - err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) - if err != nil { - infoMess = fmt.Sprintf("Error in rename dir when backup be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("ERROR", infoMess) - return err - } else { - infoMess = fmt.Sprintf("downgrade be node - backup be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("INFO", infoMess) - } - - - // step2. upload new be lib - sourceDir = fmt.Sprintf("%s/StarRocks-%s/be/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // sourceDir = fmt.Sprintf("%s/download/StarRocks-%s/be/lib", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) - targetDir = fmt.Sprintf("%s/lib", beDeployDir) - utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) - infoMess = fmt.Sprintf("downgrade be node - upload new be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("INFO", infoMess) - - - - // step3. stop be node - err = stopCluster.StopBeNode(user, keyRsa, sshHost, sshPort, beDeployDir) - if err != nil { - infoMess = fmt.Sprintf("Error in stop be node when downgrade be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) - utl.Log("ERROR", infoMess) - return err - } else { - infoMess = fmt.Sprintf("downgrade be node - stop be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) - utl.Log("INFO", infoMess) - } - - // step4. start be node - startCluster.StartBeNode(user, keyRsa, sshHost, sshPort, beHeartBeatServicePort, beDeployDir) - infoMess = fmt.Sprintf("downgrade be node - start be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) - utl.Log("INFO", infoMess) - - return nil + // step 1. backup be lib + // step 2. upload new be lib + // step 3. stop be node + // step 4. start be node + + var infoMess string + var user string + var sourceDir string + var targetDir string + var sshHost string + var sshPort int + var beDeployDir string + var beHeartBeatServicePort int + var keyRsa string + + user = module.GYamlConf.Global.User + keyRsa = module.GSshKeyRsa + sshHost = module.GYamlConf.BeServers[beId].Host + sshPort = module.GYamlConf.BeServers[beId].SshPort + beDeployDir = module.GYamlConf.BeServers[beId].DeployDir + beHeartBeatServicePort = module.GYamlConf.BeServers[beId].HeartbeatServicePort + + // step1. backup be lib + sourceDir = fmt.Sprintf("%s/lib", beDeployDir) + targetDir = fmt.Sprintf("%s/lib.bak-%s", beDeployDir, time.Now().Format("20060102150405")) + + err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir when backup be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("ERROR", infoMess) + return err + } else { + infoMess = fmt.Sprintf("downgrade be node - backup be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + } + + // step2. upload new be lib + sourceDir = fmt.Sprintf("%s/StarRocks-%s/be/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + // sourceDir = fmt.Sprintf("%s/download/StarRocks-%s/be/lib", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) + targetDir = fmt.Sprintf("%s/lib", beDeployDir) + utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + infoMess = fmt.Sprintf("downgrade be node - upload new be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + + // step3. stop be node + err = stopCluster.StopBeNode(user, keyRsa, sshHost, sshPort, beDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stop be node when downgrade be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) + utl.Log("ERROR", infoMess) + return err + } else { + infoMess = fmt.Sprintf("downgrade be node - stop be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) + utl.Log("INFO", infoMess) + } + + // step4. start be node + startCluster.StartBeNode(user, keyRsa, sshHost, sshPort, beHeartBeatServicePort, beDeployDir) + infoMess = fmt.Sprintf("downgrade be node - start be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) + utl.Log("INFO", infoMess) + + return nil } - - - - diff --git a/cluster/downgradeCluster/downgradeCn.go b/cluster/downgradeCluster/downgradeCn.go new file mode 100644 index 0000000..6641d25 --- /dev/null +++ b/cluster/downgradeCluster/downgradeCn.go @@ -0,0 +1,109 @@ +package downgradeCluster + +import ( + "fmt" + "stargo/cluster/checkStatus" + "stargo/cluster/startCluster" + "stargo/cluster/stopCluster" + "stargo/module" + "stargo/sr-utl" + "strings" + "time" +) + +func DowngradeCnCluster() { + var infoMess string + var err error + var feEntryId int + + feEntryId, err = checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + module.SetFeEntry(0) + } else { + module.SetFeEntry(feEntryId) + } + + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + infoMess = fmt.Sprintf("Starting downgrade CN node. [cnId = %d]", i) + utl.Log("OUTPUT", infoMess) + DowngradeCnNode(i) + } +} + +func DowngradeCnNode(cnId int) { + var infoMess string + var user string + var sourceDir string + var targetDir string + var sshHost string + var sshPort int + var cnDeployDir string + var heartbeatServicePort int + var keyRsa string + var cnStat map[string]string + var err error + + user = module.GYamlConf.Global.User + keyRsa = module.GSshKeyRsa + sshHost = module.GYamlConf.CnServers[cnId].Host + sshPort = module.GYamlConf.CnServers[cnId].SshPort + cnDeployDir = module.GYamlConf.CnServers[cnId].DeployDir + heartbeatServicePort = module.GYamlConf.CnServers[cnId].HeartbeatServicePort + + sourceDir = fmt.Sprintf("%s/lib", cnDeployDir) + targetDir = fmt.Sprintf("%s/lib.bak-%s", cnDeployDir, time.Now().Format("20060102150405")) + + err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir when backup CN lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("downgrade CN node - backup CN lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + } + + sourceDir = fmt.Sprintf("%s/StarRocks-%s/be/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + targetDir = fmt.Sprintf("%s/lib", cnDeployDir) + utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + infoMess = fmt.Sprintf("downgrade CN node - upload target CN lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + + err = stopCluster.StopCnNode(user, keyRsa, sshHost, sshPort, cnDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stop CN node when downgrade CN node. [host = %s, cnDeployDir = %s]", sshHost, cnDeployDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("downgrade CN node - stop CN node. [host = %s, cnDeployDir = %s]", sshHost, cnDeployDir) + utl.Log("INFO", infoMess) + } + + for j := 0; j < 3; j++ { + err = startCluster.StartCnNode(user, keyRsa, sshHost, sshPort, heartbeatServicePort, cnDeployDir) + infoMess = fmt.Sprintf("downgrade CN node - start CN node. [host = %s, cnDeployDir = %s]", sshHost, cnDeployDir) + utl.Log("INFO", infoMess) + + cnStat, err = checkStatus.CheckCnStatus(cnId) + if err == nil && cnStat["Alive"] == "true" && versionMatches(cnStat["Version"]) { + break + } + time.Sleep(10 * time.Second) + } + + if err != nil { + infoMess = fmt.Sprintf("Error in get the CN status [cnId = %d, error = %v]", cnId, err) + utl.Log("DEBUG", infoMess) + } else if cnStat["Alive"] != "true" { + infoMess = fmt.Sprintf("The CN node downgrade failed. The CN node doesn't work. [cnId = %d]", cnId) + utl.Log("ERROR", infoMess) + } else if !versionMatches(cnStat["Version"]) { + infoMess = fmt.Sprintf("The CN node downgrade failed. [cnId = %d, targetVersion = %s, currentVersion = v%s]", cnId, module.GSRVersion, cnStat["Version"]) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("The CN node downgrade successfully. [cnId = %d, currentVersion = v%s]", cnId, cnStat["Version"]) + utl.Log("OUTPUT", infoMess) + } +} + +func versionMatches(currentVersion string) bool { + return strings.Contains(currentVersion, strings.Replace(module.GSRVersion, "v", "", -1)) +} diff --git a/cluster/downgradeCluster/downgradeFe.go b/cluster/downgradeCluster/downgradeFe.go index bbfd80b..e9faee7 100644 --- a/cluster/downgradeCluster/downgradeFe.go +++ b/cluster/downgradeCluster/downgradeFe.go @@ -1,163 +1,142 @@ package downgradeCluster import ( - - "fmt" - "time" - "strings" - //"errors" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/stopCluster" - "stargo/cluster/startCluster" - "stargo/cluster/checkStatus" - //"stargo/cluster/prepareOption" - + "fmt" + "stargo/cluster/checkStatus" + "stargo/cluster/startCluster" + "stargo/cluster/stopCluster" + "strings" + "time" + //"errors" + "stargo/module" + "stargo/sr-utl" + //"stargo/cluster/prepareOption" ) - func DowngradeFeCluster() { //(err error){ - var infoMess string - var err error - var feStat map[string]string - var feEntryId int - - - feEntryId, err = checkStatus.GetFeEntry(-1) - if err != nil || feEntryId == -1 { - //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." - //utl.Log("WARN", infoMess) - module.SetFeEntry(0) - } else { - module.SetFeEntry(feEntryId) - } - - - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - infoMess = fmt.Sprintf("Starting downgrade FE node. [feId = %d]", i) - utl.Log("OUTPUT", infoMess) - err = DowngradeFeNode(i) - if err != nil { - infoMess = fmt.Sprintf("Error in downgrade FE node. [nodeid = %d]", i) - utl.Log("ERROR", infoMess) - } - - feStat, err = checkStatus.CheckFeStatus(i) - - - for j := 0; j < 3; j++ { - infoMess = fmt.Sprintf("The %d time to check FE status: %v", j, feStat["Alive"]) - utl.Log("DEBUG", infoMess) - if feStat["Alive"] == "true"{ - break - } else { - infoMess = fmt.Sprintf("The FE node doesn't work, wait for 10s and check the status again. [feId = %d]\n", i) - utl.Log("DEBUG", infoMess) - time.Sleep(10 * time.Second) - feStat, err = checkStatus.CheckFeStatus(i) - } - } - - - if err != nil { - infoMess = fmt.Sprintf("Error in get the FE status [feId = %d, error = %v]", i, err) - utl.Log("DEBUG", infoMess) - //return err - } - if feStat["Alive"] == "false" { - infoMess = fmt.Sprintf("The FE node downgrade failed. The FE node doesn't work. [feId = %d]\n", i) - utl.Log("ERROR", infoMess) - //return errors.New(infoMess) - } else if ! strings.Contains(feStat["FeVersion"], strings.Replace(module.GSRVersion, "v", "", -1)) { - infoMess = fmt.Sprintf("The FE node downgrade failed. [feId = %d, targetVersion = %s, currentVersion = v%s]", i, module.GSRVersion, feStat["FeVersion"]) - utl.Log("ERROR", infoMess) - //return errors.New(infoMess) - } else { - infoMess = fmt.Sprintf("The Fe node downgrade successfully. [feId = %d, currentVersion = v%s]", i, feStat["FeVersion"]) - utl.Log("OUTPUT", infoMess) - } - } - - //return nil - + var infoMess string + var err error + var feStat map[string]string + var feEntryId int + + feEntryId, err = checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." + //utl.Log("WARN", infoMess) + module.SetFeEntry(0) + } else { + module.SetFeEntry(feEntryId) + } + + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + infoMess = fmt.Sprintf("Starting downgrade FE node. [feId = %d]", i) + utl.Log("OUTPUT", infoMess) + err = DowngradeFeNode(i) + if err != nil { + infoMess = fmt.Sprintf("Error in downgrade FE node. [nodeid = %d]", i) + utl.Log("ERROR", infoMess) + } + + feStat, err = checkStatus.CheckFeStatus(i) + + for j := 0; j < 3; j++ { + infoMess = fmt.Sprintf("The %d time to check FE status: %v", j, feStat["Alive"]) + utl.Log("DEBUG", infoMess) + if feStat["Alive"] == "true" { + break + } else { + infoMess = fmt.Sprintf("The FE node doesn't work, wait for 10s and check the status again. [feId = %d]\n", i) + utl.Log("DEBUG", infoMess) + time.Sleep(10 * time.Second) + feStat, err = checkStatus.CheckFeStatus(i) + } + } + + if err != nil { + infoMess = fmt.Sprintf("Error in get the FE status [feId = %d, error = %v]", i, err) + utl.Log("DEBUG", infoMess) + //return err + } + if feStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The FE node downgrade failed. The FE node doesn't work. [feId = %d]\n", i) + utl.Log("ERROR", infoMess) + //return errors.New(infoMess) + } else if !strings.Contains(feStat["FeVersion"], strings.Replace(module.GSRVersion, "v", "", -1)) { + infoMess = fmt.Sprintf("The FE node downgrade failed. [feId = %d, targetVersion = %s, currentVersion = v%s]", i, module.GSRVersion, feStat["FeVersion"]) + utl.Log("ERROR", infoMess) + //return errors.New(infoMess) + } else { + infoMess = fmt.Sprintf("The Fe node downgrade successfully. [feId = %d, currentVersion = v%s]", i, feStat["FeVersion"]) + utl.Log("OUTPUT", infoMess) + } + } + + //return nil } - func DowngradeFeNode(feId int) (err error) { - // step 1. backup fe lib - // step 2. download new fe lib - // step 3. stop fe node - // step 4. start fe node - - var infoMess string - var user string - var sourceDir string - var targetDir string - var sshHost string - var sshPort int - var feDeployDir string - var feEditLogPort int - var keyRsa string - - - user = module.GYamlConf.Global.User - keyRsa = module.GSshKeyRsa - sshHost = module.GYamlConf.FeServers[feId].Host - sshPort = module.GYamlConf.FeServers[feId].SshPort - feDeployDir = module.GYamlConf.FeServers[feId].DeployDir - feEditLogPort = module.GYamlConf.FeServers[feId].EditLogPort - - - - - // step1. backup fe lib - sourceDir = fmt.Sprintf("%s/lib", feDeployDir) - targetDir = fmt.Sprintf("%s/lib.bak-%s", feDeployDir, time.Now().Format("20060102150405")) - - err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) - if err != nil { - infoMess = fmt.Sprintf("Error in rename dir when backup FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("ERROR", infoMess) - return err - } else { - infoMess = fmt.Sprintf("downgrade FE node - backup FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("INFO", infoMess) - } - - - // step2. download new FE lib - sourceDir = fmt.Sprintf("%s/StarRocks-%s/fe/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // sourceDir = fmt.Sprintf("%s/download/StarRocks-%s/fe/lib", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) - targetDir = fmt.Sprintf("%s/lib", feDeployDir) - utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) - infoMess = fmt.Sprintf("downgrade FE node - download new FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("INFO", infoMess) - - - - // step3. stop FE node - err = stopCluster.StopFeNode(user, keyRsa, sshHost, sshPort, feDeployDir) - if err != nil { - infoMess = fmt.Sprintf("Error in stop FE node when downgrade FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) - utl.Log("ERROR", infoMess) - return err - } else { - infoMess = fmt.Sprintf("downgrade FE node - stop FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) - utl.Log("INFO", infoMess) - } - - // step4. start FE node - startCluster.StartFeNode(user, keyRsa, sshHost, sshPort, feEditLogPort, feDeployDir) - infoMess = fmt.Sprintf("downgrade FE node - start FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) - utl.Log("INFO", infoMess) - - - return nil + // step 1. backup fe lib + // step 2. download new fe lib + // step 3. stop fe node + // step 4. start fe node + + var infoMess string + var user string + var sourceDir string + var targetDir string + var sshHost string + var sshPort int + var feDeployDir string + var feEditLogPort int + var keyRsa string + + user = module.GYamlConf.Global.User + keyRsa = module.GSshKeyRsa + sshHost = module.GYamlConf.FeServers[feId].Host + sshPort = module.GYamlConf.FeServers[feId].SshPort + feDeployDir = module.GYamlConf.FeServers[feId].DeployDir + feEditLogPort = module.GYamlConf.FeServers[feId].EditLogPort + + // step1. backup fe lib + sourceDir = fmt.Sprintf("%s/lib", feDeployDir) + targetDir = fmt.Sprintf("%s/lib.bak-%s", feDeployDir, time.Now().Format("20060102150405")) + + err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir when backup FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("ERROR", infoMess) + return err + } else { + infoMess = fmt.Sprintf("downgrade FE node - backup FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + } + + // step2. download new FE lib + sourceDir = fmt.Sprintf("%s/StarRocks-%s/fe/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + // sourceDir = fmt.Sprintf("%s/download/StarRocks-%s/fe/lib", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) + targetDir = fmt.Sprintf("%s/lib", feDeployDir) + utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + infoMess = fmt.Sprintf("downgrade FE node - download new FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + + // step3. stop FE node + err = stopCluster.StopFeNode(user, keyRsa, sshHost, sshPort, feDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stop FE node when downgrade FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) + utl.Log("ERROR", infoMess) + return err + } else { + infoMess = fmt.Sprintf("downgrade FE node - stop FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) + utl.Log("INFO", infoMess) + } + + // step4. start FE node + startCluster.StartFeNode(user, keyRsa, sshHost, sshPort, feEditLogPort, feDeployDir) + infoMess = fmt.Sprintf("downgrade FE node - start FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) + utl.Log("INFO", infoMess) + + return nil } - - - - diff --git a/cluster/importCluster/importBe.go b/cluster/importCluster/importBe.go index a416036..27493c7 100644 --- a/cluster/importCluster/importBe.go +++ b/cluster/importCluster/importBe.go @@ -1,65 +1,83 @@ package importCluster import ( - - "fmt" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" - "io/ioutil" - "net/http" - "regexp" - "os" - "strings" - "strconv" - + "fmt" + "io/ioutil" + "net/http" + "os" + "regexp" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" ) - func GetBeConf() { - var infoMess string - var beHttpUrl string - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - - beStat, err := checkStatus.CheckBeStatus(i) - module.GYamlConf.BeServers[i].WebServerPort, _ = strconv.Atoi(beStat["HttpPort"]) - module.GYamlConf.BeServers[i].BrpcPort, _ = strconv.Atoi(beStat["BrpcPort"]) - module.GYamlConf.BeServers[i].BePort, _ = strconv.Atoi(beStat["BePort"]) - - rootPasswd := "" - - beHttpUrl = fmt.Sprintf("http://root:%s@%s:%d/varz", rootPasswd, module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].WebServerPort) - res, err := http.Get(beHttpUrl) - defer res.Body.Close() - if err != nil { - infoMess = fmt.Sprintf("Error in create http get request when get BE conf. [beHttpUrl = %s, error = %v]", beHttpUrl, err) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - robots, err := ioutil.ReadAll(res.Body) - if err != nil{ - infoMess = fmt.Sprintf("Error in read body.[error = %v]", err) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - //fmt.Println(string(robots)) - // get priority_networks - r, _ := regexp.Compile("priority_networks=.*") - module.GYamlConf.BeServers[i].PriorityNetworks = strings.Replace(r.FindString(string(robots)), "priority_networks=", "", -1) - - // get MetaDir - r, _ = regexp.Compile("storage_root_path=.*") - module.GYamlConf.BeServers[i].StorageDir = strings.Replace(r.FindString(string(robots)), "storage_root_path=", "", -1) - - // get LogDir - r, _ = regexp.Compile("sys_log_dir=.*") - module.GYamlConf.BeServers[i].LogDir = strings.Replace(r.FindString(string(robots)), "sys_log_dir=", "", -1) - - - } + var infoMess string + var beHttpUrl string + + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + + infoMess = fmt.Sprintf("Processing BE server %d: Host=%s, WebServerPort=%d (from config)", + i, module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].WebServerPort) + utl.Log("DEBUG", infoMess) + + beStat, err := checkStatus.CheckBeStatus(i) + if err == nil && len(beStat) > 0 { + if httpPort, exists := beStat["HttpPort"]; exists && httpPort != "" { + module.GYamlConf.BeServers[i].WebServerPort, _ = strconv.Atoi(httpPort) + } else if webPort, exists := beStat["WebServerPort"]; exists && webPort != "" { + module.GYamlConf.BeServers[i].WebServerPort, _ = strconv.Atoi(webPort) + } + + if brpcPort, exists := beStat["BrpcPort"]; exists && brpcPort != "" { + module.GYamlConf.BeServers[i].BrpcPort, _ = strconv.Atoi(brpcPort) + } + + if bePort, exists := beStat["BePort"]; exists && bePort != "" { + module.GYamlConf.BeServers[i].BePort, _ = strconv.Atoi(bePort) + } + + infoMess = fmt.Sprintf("Successfully got BE status from database for %s, WebServerPort: %d", + module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].WebServerPort) + utl.Log("DEBUG", infoMess) + } else { + infoMess = fmt.Sprintf("Failed to get BE status from database for %s (error: %v), using config file values. WebServerPort: %d", + module.GYamlConf.BeServers[i].Host, err, module.GYamlConf.BeServers[i].WebServerPort) + utl.Log("DEBUG", infoMess) + } + + if module.GYamlConf.BeServers[i].WebServerPort == 0 { + infoMess = fmt.Sprintf("WebServerPort is 0 for BE server %s, skipping this node", module.GYamlConf.BeServers[i].Host) + utl.Log("WARNING", infoMess) + continue + } + + rootPasswd := "" + + beHttpUrl = fmt.Sprintf("http://root:%s@%s:%d/varz", rootPasswd, module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].WebServerPort) + res, err := http.Get(beHttpUrl) + if err != nil { + infoMess = fmt.Sprintf("Error in create http get request when get BE conf. [beHttpUrl = %s, error = %v]", beHttpUrl, err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + defer res.Body.Close() + + robots, err := ioutil.ReadAll(res.Body) + if err != nil { + infoMess = fmt.Sprintf("Error in read body.[error = %v]", err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + //fmt.Println(string(robots)) + // get priority_networks + r, _ := regexp.Compile("priority_networks=.*") + module.GYamlConf.BeServers[i].PriorityNetworks = strings.Replace(r.FindString(string(robots)), "priority_networks=", "", -1) + + } } diff --git a/cluster/importCluster/importCn.go b/cluster/importCluster/importCn.go new file mode 100644 index 0000000..1f7668c --- /dev/null +++ b/cluster/importCluster/importCn.go @@ -0,0 +1,94 @@ +package importCluster + +import ( + "fmt" + "io/ioutil" + "net/http" + "os" + "regexp" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" +) + +func GetCnConf() { + + var infoMess string + var cnHttpUrl string + + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + + infoMess = fmt.Sprintf("Processing CN server %d: Host=%s, WebServerPort=%d (from config)", + i, module.GYamlConf.CnServers[i].Host, module.GYamlConf.CnServers[i].WebServerPort) + utl.Log("DEBUG", infoMess) + + cnStat, err := checkStatus.CheckCnStatus(i) + if err == nil && len(cnStat) > 0 { + if httpPort, exists := cnStat["HttpPort"]; exists && httpPort != "" { + module.GYamlConf.CnServers[i].WebServerPort, _ = strconv.Atoi(httpPort) + } else if webPort, exists := cnStat["WebServerPort"]; exists && webPort != "" { + module.GYamlConf.CnServers[i].WebServerPort, _ = strconv.Atoi(webPort) + } + + if brpcPort, exists := cnStat["BrpcPort"]; exists && brpcPort != "" { + module.GYamlConf.CnServers[i].BrpcPort, _ = strconv.Atoi(brpcPort) + } + + if bePort, exists := cnStat["BePort"]; exists && bePort != "" { + module.GYamlConf.CnServers[i].BePort, _ = strconv.Atoi(bePort) + } + + if starletPort, exists := cnStat["StarletPort"]; exists && starletPort != "" { + module.GYamlConf.CnServers[i].StarletPort, _ = strconv.Atoi(starletPort) + } + + infoMess = fmt.Sprintf("Successfully got CN status from database for %s, WebServerPort: %d", + module.GYamlConf.CnServers[i].Host, module.GYamlConf.CnServers[i].WebServerPort) + utl.Log("DEBUG", infoMess) + } else { + infoMess = fmt.Sprintf("Failed to get CN status from database for %s (error: %v), using config file values. WebServerPort: %d", + module.GYamlConf.CnServers[i].Host, err, module.GYamlConf.CnServers[i].WebServerPort) + utl.Log("DEBUG", infoMess) + } + + if module.GYamlConf.CnServers[i].WebServerPort == 0 { + infoMess = fmt.Sprintf("WebServerPort is 0 for CN server %s, skipping this node", module.GYamlConf.CnServers[i].Host) + utl.Log("WARNING", infoMess) + continue + } + + rootPasswd := "" + + cnHttpUrl = fmt.Sprintf("http://root:%s@%s:%d/varz", rootPasswd, module.GYamlConf.CnServers[i].Host, module.GYamlConf.CnServers[i].WebServerPort) + res, err := http.Get(cnHttpUrl) + if err != nil { + infoMess = fmt.Sprintf("Error in create http get request when get CN conf. [cnHttpUrl = %s, error = %v]", cnHttpUrl, err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + defer res.Body.Close() + + robots, err := ioutil.ReadAll(res.Body) + if err != nil { + infoMess = fmt.Sprintf("Error in read body.[error = %v]", err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + //fmt.Println(string(robots)) + // get priority_networks + r, _ := regexp.Compile("priority_networks=.*") + module.GYamlConf.CnServers[i].PriorityNetworks = strings.Replace(r.FindString(string(robots)), "priority_networks=", "", -1) + + // get WarehouseName (specific to CN nodes) + r, _ = regexp.Compile("warehouse_name=.*") + warehouseName := strings.Replace(r.FindString(string(robots)), "warehouse_name=", "", -1) + if warehouseName != "" { + module.GYamlConf.CnServers[i].WarehouseName = warehouseName + } + + } + +} diff --git a/cluster/importCluster/importFe.go b/cluster/importCluster/importFe.go index f4be3dc..240bddc 100644 --- a/cluster/importCluster/importFe.go +++ b/cluster/importCluster/importFe.go @@ -1,64 +1,69 @@ package importCluster import ( - - "fmt" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/checkStatus" - "io/ioutil" - "net/http" - "regexp" - "os" - "strings" - "strconv" - + "fmt" + "io/ioutil" + "net/http" + "os" + "regexp" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" ) - func GetFeConf() { - var infoMess string - var feHttpUrl string - + var infoMess string + var feHttpUrl string - for i := 0; i < len(module.GYamlConf.FeServers); i++ { + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + if module.GYamlConf.FeServers[i].Config == nil { + module.GYamlConf.FeServers[i].Config = make(map[string]string) + } - feStat, err := checkStatus.CheckFeStatus(i) - module.GYamlConf.FeServers[i].HttpPort, _ = strconv.Atoi(feStat["HttpPort"]) - module.GYamlConf.FeServers[i].RpcPort, _ = strconv.Atoi(feStat["RpcPort"]) - module.GYamlConf.FeServers[i].EditLogPort, _ = strconv.Atoi(feStat["EditLogPort"]) - module.GSRVersion = "v" + strings.Split(feStat["Version"], "-")[0] - rootPasswd := "" + feStat, err := checkStatus.CheckFeStatus(i) + module.GYamlConf.FeServers[i].HttpPort, _ = strconv.Atoi(feStat["HttpPort"]) + module.GYamlConf.FeServers[i].RpcPort, _ = strconv.Atoi(feStat["RpcPort"]) + module.GYamlConf.FeServers[i].EditLogPort, _ = strconv.Atoi(feStat["EditLogPort"]) + module.GSRVersion = "v" + strings.Split(feStat["Version"], "-")[0] + rootPasswd := "" - feHttpUrl = fmt.Sprintf("http://root:%s@%s:%d/variable", rootPasswd, module.GYamlConf.FeServers[i].Host, module.GYamlConf.FeServers[i].HttpPort) - res, err := http.Get(feHttpUrl) - defer res.Body.Close() - if err != nil { - infoMess = fmt.Sprintf("Error in create http get request when get FE conf. [feHttpUrl = %s, error = %v]", feHttpUrl, err) - utl.Log("ERROR", infoMess) - os.Exit(1) - } + feHttpUrl = fmt.Sprintf("http://root:%s@%s:%d/variable", rootPasswd, module.GYamlConf.FeServers[i].Host, module.GYamlConf.FeServers[i].HttpPort) + res, err := http.Get(feHttpUrl) + if err != nil { + infoMess = fmt.Sprintf("Error in create http get request when get FE conf. [feHttpUrl = %s, error = %v]", feHttpUrl, err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + defer res.Body.Close() - robots, err := ioutil.ReadAll(res.Body) - if err != nil { - infoMess = fmt.Sprintf("Error in read body.[error = %v]", err) - utl.Log("ERROR", infoMess) - os.Exit(1) - } + robots, err := ioutil.ReadAll(res.Body) + if err != nil { + infoMess = fmt.Sprintf("Error in read body.[error = %v]", err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } - //fmt.Println(string(robots)) - // get priority_networks - r, _ := regexp.Compile("priority_networks=.*") - module.GYamlConf.FeServers[i].PriorityNetworks = strings.Replace(r.FindString(string(robots)), "priority_networks=", "", -1) + //fmt.Println(string(robots)) + // get priority_networks + r, _ := regexp.Compile("priority_networks=.*") + module.GYamlConf.FeServers[i].PriorityNetworks = strings.Replace(r.FindString(string(robots)), "priority_networks=", "", -1) - // get MetaDir - r, _ = regexp.Compile("meta_dir=.*") - module.GYamlConf.FeServers[i].MetaDir = strings.Replace(r.FindString(string(robots)), "meta_dir=", "", -1) + // get run_mode + r, _ = regexp.Compile("run_mode=.*") + runMode := strings.Replace(r.FindString(string(robots)), "run_mode=", "", -1) + if runMode != "" { + module.GYamlConf.FeServers[i].Config["run_mode"] = runMode + } - // get LogDir - r, _ = regexp.Compile("sys_log_dir=.*") - module.GYamlConf.FeServers[i].LogDir = strings.Replace(r.FindString(string(robots)), "sys_log_dir=", "", -1) - } + // get cloud_native_meta_port + r, _ = regexp.Compile("cloud_native_meta_port=.*") + cloudNativeMetaPort := strings.Replace(r.FindString(string(robots)), "cloud_native_meta_port=", "", -1) + if cloudNativeMetaPort != "" { + module.GYamlConf.FeServers[i].Config["cloud_native_meta_port"] = cloudNativeMetaPort + } + } } diff --git a/cluster/listCluster/listCluster.go b/cluster/listCluster/listCluster.go index 2e80e99..e4c0d13 100644 --- a/cluster/listCluster/listCluster.go +++ b/cluster/listCluster/listCluster.go @@ -1,41 +1,41 @@ package listCluster import ( - "fmt" - "stargo/module" - "stargo/sr-utl" - "io/ioutil" + "fmt" + "io/ioutil" + "stargo/module" + "stargo/sr-utl" ) func ListCluster() { - // module.GSRCtlRoot - var infoMess string - var clusterName string - var metaFile string - metaPath := fmt.Sprintf("%s/cluster", module.GSRCtlRoot) - - dir, err := ioutil.ReadDir(metaPath) - if err != nil { - infoMess = fmt.Sprintf("Error in read dir [DirPath = %s]", metaPath) - utl.Log("ERROR", infoMess) - } - - tmpMinus := []byte("----------------------------------------------------------------------------------------") - fmt.Printf("%-15s %-10s %-10s %-25s %-60s %-50s\n", "ClusterName", "Version", "User", "CreateDate", "MetaPath", "PrivateKey") - fmt.Printf("%-15s %-10s %-10s %-25s %-60s %-50s\n", tmpMinus[:15], tmpMinus[:10], tmpMinus[:10], tmpMinus[:25], tmpMinus[:60], tmpMinus[:50]) - - for _, info := range dir { - clusterName = info.Name() - metaFile = fmt.Sprintf("%s/cluster/%s/meta.yaml", module.GSRCtlRoot, clusterName) - - module.InitConf(clusterName, metaFile) - fmt.Printf("%-15s %-10s %-10s %-25s %-60s %-50s\n", clusterName, - module.GYamlConf.ClusterInfo.Version, - module.GYamlConf.ClusterInfo.User, - module.GYamlConf.ClusterInfo.CreateDate, - module.GYamlConf.ClusterInfo.MetaPath, - module.GYamlConf.ClusterInfo.PrivateKey) - } + // module.GSRCtlRoot + var infoMess string + var clusterName string + var metaFile string + metaPath := fmt.Sprintf("%s/cluster", module.GSRCtlRoot) + + dir, err := ioutil.ReadDir(metaPath) + if err != nil { + infoMess = fmt.Sprintf("Error in read dir [DirPath = %s]", metaPath) + utl.Log("ERROR", infoMess) + } + + tmpMinus := []byte("----------------------------------------------------------------------------------------") + fmt.Printf("%-15s %-10s %-10s %-25s %-60s %-50s\n", "ClusterName", "Version", "User", "CreateDate", "MetaPath", "PrivateKey") + fmt.Printf("%-15s %-10s %-10s %-25s %-60s %-50s\n", tmpMinus[:15], tmpMinus[:10], tmpMinus[:10], tmpMinus[:25], tmpMinus[:60], tmpMinus[:50]) + + for _, info := range dir { + clusterName = info.Name() + metaFile = fmt.Sprintf("%s/cluster/%s/meta.yaml", module.GSRCtlRoot, clusterName) + + module.InitConf(clusterName, metaFile) + fmt.Printf("%-15s %-10s %-10s %-25s %-60s %-50s\n", clusterName, + module.GYamlConf.ClusterInfo.Version, + module.GYamlConf.ClusterInfo.User, + module.GYamlConf.ClusterInfo.CreateDate, + module.GYamlConf.ClusterInfo.MetaPath, + module.GYamlConf.ClusterInfo.PrivateKey) + } } diff --git a/cluster/modifyConfig/modifyConfig.go b/cluster/modifyConfig/modifyConfig.go index 1db5b0c..d2fe186 100644 --- a/cluster/modifyConfig/modifyConfig.go +++ b/cluster/modifyConfig/modifyConfig.go @@ -1,179 +1,249 @@ -package modifyConfig +package modifyConfig + import ( - "fmt" - "strconv" - "strings" - "stargo/module" - "stargo/sr-utl" + "fmt" + "os" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" ) - - - func ModifyTest() { - /* - var configMap map[string] string - configMap = make(map[string] string) - - i := 0 - configMap["priority_networks"] = module.GYamlConf.FeServers[i].PriorityNetworks - configMap["http_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].HttpPort) - configMap["rpc_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].RpcPort) - configMap["edit_log_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].EditLogPort) - fmt.Printf("%s:%d\n", "http_port", module.GYamlConf.FeServers[i].HttpPort) - fmt.Printf("%s:%d\n", "rpc_port", module.GYamlConf.FeServers[i].RpcPort) - fmt.Println("[TEST] #########################################################################") - for key, val := range configMap { - fmt.Printf("key:%s\tvalue:%s\n", key, val) - } - */ - i := 0 - for k, v := range module.GYamlConf.FeServers[i].Config { - fmt.Printf("%s:%s\n", k, v) - } - //fmt.Println("[TEST]", module.GYamlConf.FeServers[i].Config) + /* + var configMap map[string] string + configMap = make(map[string] string) + + i := 0 + configMap["priority_networks"] = module.GYamlConf.FeServers[i].PriorityNetworks + configMap["http_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].HttpPort) + configMap["rpc_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].RpcPort) + configMap["edit_log_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].EditLogPort) + fmt.Printf("%s:%d\n", "http_port", module.GYamlConf.FeServers[i].HttpPort) + fmt.Printf("%s:%d\n", "rpc_port", module.GYamlConf.FeServers[i].RpcPort) + fmt.Println("[TEST] #########################################################################") + for key, val := range configMap { + fmt.Printf("key:%s\tvalue:%s\n", key, val) + } + */ + i := 0 + for k, v := range module.GYamlConf.FeServers[i].Config { + fmt.Printf("%s:%s\n", k, v) + } + //fmt.Println("[TEST]", module.GYamlConf.FeServers[i].Config) } - func ModifyClusterConfig() { - var infoMess string - //var tmpConfigKey string - //var tmpConfigValue string - var tmpUser string = module.GYamlConf.Global.User - var tmpKeyFile string = module.GSshKeyRsa - var configMap map[string] string - - infoMess = "Modify configuration for FE nodes & BE nodes ..." - utl.Log("OUTPUT", infoMess) - // modify FE config - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - // copy fe config file - tmpFeHost := module.GYamlConf.FeServers[i].Host - tmpFeQueryPort := module.GYamlConf.FeServers[i].QueryPort - tmpFeSourceConfFile := fmt.Sprintf("%s/StarRocks-%s/fe/conf/fe.conf", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // tmpFeSourceConfFile := fmt.Sprintf("%s/download/StarRocks-%s/fe/conf/fe.conf", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) - tmpFeTargetConfFile := fmt.Sprintf("%s/tmp/fe.conf-%s-%d", module.GSRCtlRoot, tmpFeHost, tmpFeQueryPort) - - err := copyConfigFile(tmpFeSourceConfFile, tmpFeTargetConfFile) - if err != nil { - infoMess = fmt.Sprintf("Error in modifing fe cluster configuration. Copy configuration file failed [sourceFile = %s, targetFile = %s]", tmpFeSourceConfFile, tmpFeTargetConfFile) - utl.Log("ERROR", infoMess) - panic(err) + var infoMess string + //var tmpConfigKey string + //var tmpConfigValue string + var tmpUser string = module.GYamlConf.Global.User + var tmpKeyFile string = module.GSshKeyRsa + var configMap map[string]string + + infoMess = "Modify configuration for FE nodes, BE nodes & CN nodes ..." + utl.Log("OUTPUT", infoMess) + // modify FE config + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + // copy fe config file + tmpFeHost := module.GYamlConf.FeServers[i].Host + tmpFeQueryPort := module.GYamlConf.FeServers[i].QueryPort + tmpFeSourceConfFile := fmt.Sprintf("%s/StarRocks-%s/fe/conf/fe.conf", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + // tmpFeSourceConfFile := fmt.Sprintf("%s/download/StarRocks-%s/fe/conf/fe.conf", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) + tmpFeTargetConfFile := fmt.Sprintf("%s/tmp/fe.conf-%s-%d", module.GSRCtlRoot, tmpFeHost, tmpFeQueryPort) + + err := copyConfigFile(tmpFeSourceConfFile, tmpFeTargetConfFile) + if err != nil { + infoMess = fmt.Sprintf("Error in modifing fe cluster configuration. Copy configuration file failed [sourceFile = %s, targetFile = %s]", tmpFeSourceConfFile, tmpFeTargetConfFile) + utl.Log("ERROR", infoMess) + panic(err) + } + + // append new config into tmp configuration file + + // add network priority config + //tmpConfigKey = "priority_networks" + //tmpConfigValue = module.GYamlConf.FeServers[i].PriorityNetworks + //appendConfig(tmpFeTargetConfFile, tmpConfigKey, tmpConfigValue) + + configMap = make(map[string]string) + configMap["priority_networks"] = module.GYamlConf.FeServers[i].PriorityNetworks + configMap["http_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].HttpPort) + configMap["rpc_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].RpcPort) + configMap["edit_log_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].EditLogPort) + configMap["query_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].QueryPort) + if module.IsSharedDataCluster() { + configMap["run_mode"] = "shared_data" + configMap["cloud_native_meta_port"] = module.DefaultCloudNativeMetaPort + } + + for k, v := range configMap { + if v != "0" { + appendConfig(tmpFeTargetConfFile, k, v) + } + } + + for k, v := range module.GYamlConf.FeServers[i].Config { + appendConfig(tmpFeTargetConfFile, k, v) + } + + // distribute tmp fe configuration file + tmpUser := module.GYamlConf.Global.User + tmpFeSshPort := module.GYamlConf.FeServers[i].SshPort + tmpTargetFeConfPath := module.GYamlConf.FeServers[i].DeployDir + "/conf/fe.conf" + utl.UploadFile(tmpUser, tmpKeyFile, tmpFeHost, tmpFeSshPort, tmpFeTargetConfFile, tmpTargetFeConfPath) + } - // append new config into tmp configuration file + // modify BE config + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + // copy BE config file + tmpBeHost := module.GYamlConf.BeServers[i].Host + tmpBeHeartbeatServicePort := module.GYamlConf.BeServers[i].HeartbeatServicePort + tmpBeSourceConfFile := fmt.Sprintf("%s/StarRocks-%s/be/conf/be.conf", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + // tmpBeSourceConfFile := fmt.Sprintf("%s/download/StarRocks-%s/be/conf/be.conf", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) + tmpBeTargetConfFile := fmt.Sprintf("%s/tmp/be.conf-%s-%d", module.GSRCtlRoot, tmpBeHost, tmpBeHeartbeatServicePort) + + err := copyConfigFile(tmpBeSourceConfFile, tmpBeTargetConfFile) + if err != nil { + infoMess = fmt.Sprintf("Error in modifing BE cluster configuration. Copy configuration file failed [sourceFile = %s, targetFile = %s]", tmpBeSourceConfFile, tmpBeTargetConfFile) + utl.Log("ERROR", infoMess) + panic(err) + } + + // append new config into tmp configuration file + // add network priority config + //tmpConfigKey = "priority_networks" + //tmpConfigValue = module.GYamlConf.BeServers[i].PriorityNetworks + //appendConfig(tmpBeTargetConfFile, tmpConfigKey, tmpConfigValue) + configMap = make(map[string]string) + configMap["priority_networks"] = module.GYamlConf.BeServers[i].PriorityNetworks + configMap["be_port"] = strconv.Itoa(module.GYamlConf.BeServers[i].BePort) + configMap["be_http_port"] = strconv.Itoa(module.GYamlConf.BeServers[i].WebServerPort) + configMap["heartbeat_service_port"] = strconv.Itoa(module.GYamlConf.BeServers[i].HeartbeatServicePort) + configMap["brpc_port"] = strconv.Itoa(module.GYamlConf.BeServers[i].BrpcPort) + for k, v := range configMap { + if v != "0" { + appendConfig(tmpBeTargetConfFile, k, v) + } + } + + for k, v := range module.GYamlConf.BeServers[i].Config { + appendConfig(tmpBeTargetConfFile, k, v) + } + + // distribute tmp fe configuration file + tmpBeSshPort := module.GYamlConf.BeServers[i].SshPort + tmpTargetBeConfPath := module.GYamlConf.BeServers[i].DeployDir + "/conf/be.conf" + utl.UploadFile(tmpUser, tmpKeyFile, tmpBeHost, tmpBeSshPort, tmpBeTargetConfFile, tmpTargetBeConfPath) - // add network priority config - //tmpConfigKey = "priority_networks" - //tmpConfigValue = module.GYamlConf.FeServers[i].PriorityNetworks - //appendConfig(tmpFeTargetConfFile, tmpConfigKey, tmpConfigValue) + } - configMap = make(map[string] string) - configMap["priority_networks"] = module.GYamlConf.FeServers[i].PriorityNetworks - configMap["http_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].HttpPort) - configMap["rpc_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].RpcPort) - configMap["edit_log_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].EditLogPort) - configMap["query_port"] = strconv.Itoa(module.GYamlConf.FeServers[i].QueryPort) + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + tmpCnHost := module.GYamlConf.CnServers[i].Host + tmpCnHeartbeatServicePort := module.GYamlConf.CnServers[i].HeartbeatServicePort + tmpCnSourceConfFile := resolveConfigSourceFile("cn") + tmpCnTargetConfFile := fmt.Sprintf("%s/tmp/cn.conf-%s-%d", module.GSRCtlRoot, tmpCnHost, tmpCnHeartbeatServicePort) + + err := copyConfigFile(tmpCnSourceConfFile, tmpCnTargetConfFile) + if err != nil { + infoMess = fmt.Sprintf("Error in modifing CN cluster configuration. Copy configuration file failed [sourceFile = %s, targetFile = %s]", tmpCnSourceConfFile, tmpCnTargetConfFile) + utl.Log("ERROR", infoMess) + panic(err) + } + + configMap = make(map[string]string) + configMap["priority_networks"] = module.GYamlConf.CnServers[i].PriorityNetworks + configMap["be_port"] = strconv.Itoa(module.GYamlConf.CnServers[i].BePort) + configMap["be_http_port"] = strconv.Itoa(module.GYamlConf.CnServers[i].WebServerPort) + configMap["heartbeat_service_port"] = strconv.Itoa(module.GYamlConf.CnServers[i].HeartbeatServicePort) + configMap["brpc_port"] = strconv.Itoa(module.GYamlConf.CnServers[i].BrpcPort) + configMap["starlet_port"] = strconv.Itoa(module.GYamlConf.CnServers[i].StarletPort) + configMap["warehouse_name"] = module.GYamlConf.CnServers[i].WarehouseName + if _, exists := module.GYamlConf.CnServers[i].Config["storage_root_path"]; !exists { + configMap["storage_root_path"] = module.GYamlConf.CnServers[i].StorageDir + } + for k, v := range configMap { + if v != "" && v != "0" { + appendConfig(tmpCnTargetConfFile, k, v) + } + } + + for k, v := range module.GYamlConf.CnServers[i].Config { + appendConfig(tmpCnTargetConfFile, k, v) + } + + tmpCnSshPort := module.GYamlConf.CnServers[i].SshPort + tmpTargetCnConfPath := module.GYamlConf.CnServers[i].DeployDir + "/conf/cn.conf" + utl.UploadFile(tmpUser, tmpKeyFile, tmpCnHost, tmpCnSshPort, tmpCnTargetConfFile, tmpTargetCnConfPath) + } - for k, v := range configMap { - if v != "0" { - appendConfig(tmpFeTargetConfFile, k, v) - } +} + +func resolveConfigSourceFile(role string) string { + + version := strings.Replace(module.GSRVersion, "v", "", -1) + candidates := []string{} + + switch role { + case "fe": + candidates = []string{ + fmt.Sprintf("%s/StarRocks-%s/fe/conf/fe.conf", module.GDownloadPath, version), + } + case "be": + candidates = []string{ + fmt.Sprintf("%s/StarRocks-%s/be/conf/be.conf", module.GDownloadPath, version), + } + case "cn": + candidates = []string{ + fmt.Sprintf("%s/StarRocks-%s/be/conf/cn.conf", module.GDownloadPath, version), + fmt.Sprintf("%s/StarRocks-%s/cn/conf/cn.conf", module.GDownloadPath, version), + fmt.Sprintf("%s/StarRocks-%s/be/conf/be.conf", module.GDownloadPath, version), + } } - for k, v := range module.GYamlConf.FeServers[i].Config { - appendConfig(tmpFeTargetConfFile, k, v) - } - - - // distribute tmp fe configuration file - tmpUser := module.GYamlConf.Global.User - tmpFeSshPort := module.GYamlConf.FeServers[i].SshPort - tmpTargetFeConfPath := module.GYamlConf.FeServers[i].DeployDir + "/conf/fe.conf" - utl.UploadFile(tmpUser, tmpKeyFile, tmpFeHost, tmpFeSshPort, tmpFeTargetConfFile, tmpTargetFeConfPath) - - - } - - // modify BE config - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - // copy BE config file - tmpBeHost := module.GYamlConf.BeServers[i].Host - tmpBeHeartbeatServicePort := module.GYamlConf.BeServers[i].HeartbeatServicePort - tmpBeSourceConfFile := fmt.Sprintf("%s/StarRocks-%s/be/conf/be.conf", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // tmpBeSourceConfFile := fmt.Sprintf("%s/download/StarRocks-%s/be/conf/be.conf", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) - tmpBeTargetConfFile := fmt.Sprintf("%s/tmp/be.conf-%s-%d", module.GSRCtlRoot, tmpBeHost, tmpBeHeartbeatServicePort) - - err := copyConfigFile(tmpBeSourceConfFile, tmpBeTargetConfFile) - if err != nil { - infoMess = fmt.Sprintf("Error in modifing BE cluster configuration. Copy configuration file failed [sourceFile = %s, targetFile = %s]", tmpBeSourceConfFile, tmpBeTargetConfFile) - utl.Log("ERROR", infoMess) - panic(err) - } - - // append new config into tmp configuration file - // add network priority config - //tmpConfigKey = "priority_networks" - //tmpConfigValue = module.GYamlConf.BeServers[i].PriorityNetworks - //appendConfig(tmpBeTargetConfFile, tmpConfigKey, tmpConfigValue) - configMap = make(map[string] string) - configMap["priority_networks"] = module.GYamlConf.BeServers[i].PriorityNetworks - configMap["be_port"] = strconv.Itoa(module.GYamlConf.BeServers[i].BePort) - configMap["webserver_port"] = strconv.Itoa(module.GYamlConf.BeServers[i].WebServerPort) - configMap["heartbeat_service_port"] = strconv.Itoa(module.GYamlConf.BeServers[i].HeartbeatServicePort) - configMap["brpc_port"] = strconv.Itoa(module.GYamlConf.BeServers[i].BrpcPort) - for k, v := range configMap { - if v != "0" { - appendConfig(tmpBeTargetConfFile, k, v) - } - } - - for k, v := range module.GYamlConf.BeServers[i].Config { - appendConfig(tmpBeTargetConfFile, k, v) - } - - - // distribute tmp fe configuration file - tmpBeSshPort := module.GYamlConf.BeServers[i].SshPort - tmpTargetBeConfPath := module.GYamlConf.BeServers[i].DeployDir + "/conf/be.conf" - utl.UploadFile(tmpUser, tmpKeyFile, tmpBeHost, tmpBeSshPort, tmpBeTargetConfFile, tmpTargetBeConfPath) - - } + for _, candidate := range candidates { + if _, err := os.Stat(candidate); err == nil { + return candidate + } + } + if len(candidates) > 0 { + return candidates[0] + } + return "" } -func copyConfigFile(sourceFile string, targetFile string) (err error){ +func copyConfigFile(sourceFile string, targetFile string) (err error) { - var infoMess string + var infoMess string - fileByte, err := utl.CopyFile(sourceFile, targetFile) - if err != nil || fileByte == 0 { - infoMess = fmt.Sprintf("Error in copy fe config file, [sourceFile = %s, targetFile = %s, fileByte = %d, error = %v]", sourceFile, targetFile, fileByte, err) - utl.Log("ERROR", infoMess) - return err - } + fileByte, err := utl.CopyFile(sourceFile, targetFile) + if err != nil || fileByte == 0 { + infoMess = fmt.Sprintf("Error in copy fe config file, [sourceFile = %s, targetFile = %s, fileByte = %d, error = %v]", sourceFile, targetFile, fileByte, err) + utl.Log("ERROR", infoMess) + return err + } - return nil + return nil } func appendConfig(configFile string, configKey string, configValue string) { - var infoMess string + var infoMess string - err := utl.AppendConfig(configFile, configKey, configValue) - if err != nil { - infoMess = fmt.Sprintf("Error in append new configuration to tmp config file [configFile = %s, configKey = %s, configValue = %s]", configFile, configKey, configValue) - utl.Log("ERROR", infoMess) - panic(err) - } - infoMess = fmt.Sprintf("Append new configuration to tmp config file [configFile = %s, configKey = %s, configValue = %s]", configFile, configKey, configValue) - utl.Log("DEBUG", infoMess) + err := utl.AppendConfig(configFile, configKey, configValue) + if err != nil { + infoMess = fmt.Sprintf("Error in append new configuration to tmp config file [configFile = %s, configKey = %s, configValue = %s]", configFile, configKey, configValue) + utl.Log("ERROR", infoMess) + panic(err) + } + infoMess = fmt.Sprintf("Append new configuration to tmp config file [configFile = %s, configKey = %s, configValue = %s]", configFile, configKey, configValue) + utl.Log("DEBUG", infoMess) } - - diff --git a/cluster/parseConfig/.getConfig.go.swp b/cluster/parseConfig/.getConfig.go.swp deleted file mode 100644 index 5d97e35..0000000 Binary files a/cluster/parseConfig/.getConfig.go.swp and /dev/null differ diff --git a/cluster/prepareOption/createDir.go b/cluster/prepareOption/createDir.go index 5133553..9d58a4a 100644 --- a/cluster/prepareOption/createDir.go +++ b/cluster/prepareOption/createDir.go @@ -1,165 +1,222 @@ package prepareOption -import( - "stargo/sr-utl" - "stargo/module" - "fmt" +import ( + "fmt" + "stargo/module" + "stargo/sr-utl" ) - func CreateDir() { - var infoMess string + var infoMess string - infoMess = "Create the deploy folder ..." - utl.Log("OUTPUT", infoMess) - CreateiSrCtlDir() - CreateFeDir() - CreateBeDir() + infoMess = "Create the deploy folder ..." + utl.Log("OUTPUT", infoMess) + CreateiSrCtlDir() + CreateFeDir() + CreateBeDir() + CreateCnDir() } func CreateiSrCtlDir() { - // create SrCtlDir - // SRCTLROOT/{download,tmp} + // create SrCtlDir + // SRCTLROOT/{download,tmp} - utl.MkDir(module.GSRCtlRoot+"/tmp") - utl.MkDir(module.GSRCtlRoot+"/download") - utl.MkDir(module.GSRCtlRoot+"/cluster") + utl.MkDir(module.GSRCtlRoot + "/tmp") + utl.MkDir(module.GSRCtlRoot + "/download") + utl.MkDir(module.GSRCtlRoot + "/cluster") } func CreateFeDir() { - var infoMess string - var errMess string - var cmd string - var err error - //var outPut []byte - - sshUser := module.GYamlConf.Global.User - sshKeyRsaFile := module.GSshKeyRsa - - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - sshHost := module.GYamlConf.FeServers[i].Host - sshPort := module.GYamlConf.FeServers[i].SshPort - - // create DEPLOY dir for FE nodes - cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.FeServers[i].DeployDir) - infoMess = fmt.Sprintf("Create DEPLOY Folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("DEBUG", infoMess) - - _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) - if err != nil { - errMess = fmt.Sprintf("ERROR in creating DEPLOY folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("ERROR", errMess) - panic(err) - } - - // create META dir for FE nodes - cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.FeServers[i].MetaDir) - infoMess = fmt.Sprintf("Create META Folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("DEBUG", infoMess) - - _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) - if err != nil { - errMess = fmt.Sprintf("ERROR in creating META folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("ERROR", errMess) - panic(err) - } - - if module.GYamlConf.FeServers[i].DeployDir + "/meta" != module.GYamlConf.FeServers[i].MetaDir { - cmd = fmt.Sprintf("ln -s %s %s", module.GYamlConf.FeServers[i].MetaDir, module.GYamlConf.FeServers[i].DeployDir + "/meta") - infoMess = fmt.Sprintf("Detect MetaDir isn't under DeployDir, Create the soft link, CMD %s", cmd) - utl.Log("DEBUG", infoMess) - _, err := utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) - if err != nil { - errMess = fmt.Sprintf("Error in create soft link for MetaDir, CMD %s", cmd) - utl.Log("ERROR", errMess) - panic(err) - } - } - - // create LOG dir for FE nodes - cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.FeServers[i].LogDir) - infoMess = fmt.Sprintf("Create LOG Folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("DEBUG", infoMess) - - _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) - if err != nil { - errMess = fmt.Sprintf("ERROR in creating LOG folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("ERROR", errMess) - panic(err) - } - } + var infoMess string + var errMess string + var cmd string + var err error + //var outPut []byte + + sshUser := module.GYamlConf.Global.User + sshKeyRsaFile := module.GSshKeyRsa + + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + sshHost := module.GYamlConf.FeServers[i].Host + sshPort := module.GYamlConf.FeServers[i].SshPort + + // create DEPLOY dir for FE nodes + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.FeServers[i].DeployDir) + infoMess = fmt.Sprintf("Create DEPLOY Folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating DEPLOY folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + + // create META dir for FE nodes + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.FeServers[i].MetaDir) + infoMess = fmt.Sprintf("Create META Folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating META folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + + if module.GYamlConf.FeServers[i].DeployDir+"/meta" != module.GYamlConf.FeServers[i].MetaDir { + cmd = fmt.Sprintf("ln -s %s %s", module.GYamlConf.FeServers[i].MetaDir, module.GYamlConf.FeServers[i].DeployDir+"/meta") + infoMess = fmt.Sprintf("Detect MetaDir isn't under DeployDir, Create the soft link, CMD %s", cmd) + utl.Log("DEBUG", infoMess) + _, err := utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("Error in create soft link for MetaDir, CMD %s", cmd) + utl.Log("ERROR", errMess) + panic(err) + } + } + + // create LOG dir for FE nodes + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.FeServers[i].LogDir) + infoMess = fmt.Sprintf("Create LOG Folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating LOG folder for FE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + } } - - - func CreateBeDir() { - var infoMess string - var errMess string - var cmd string - var err error - //var outPut []byte - - sshUser := module.GYamlConf.Global.User - sshKeyRsaFile := module.GSshKeyRsa - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - sshHost := module.GYamlConf.BeServers[i].Host - sshPort := module.GYamlConf.BeServers[i].SshPort - - // create DEPLOY dir for BE nodes - cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.BeServers[i].DeployDir) - infoMess = fmt.Sprintf("Create DEPLOY Folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("DEBUG", infoMess) - - _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) - if err != nil { - errMess = fmt.Sprintf("ERROR in creating DEPLOY folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("ERROR", errMess) - panic(err) - } - - // create STORAGE dir for BE nodes - cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.BeServers[i].StorageDir) - infoMess = fmt.Sprintf("Create Storage Folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("DEBUG", infoMess) - - _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) - if err != nil { - errMess = fmt.Sprintf("ERROR in creating STORAGE folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("ERROR", errMess) - panic(err) - } - - if module.GYamlConf.BeServers[i].DeployDir + "/storage" != module.GYamlConf.BeServers[i].StorageDir { - cmd = fmt.Sprintf("ln -s %s %s", module.GYamlConf.BeServers[i].StorageDir, module.GYamlConf.BeServers[i].DeployDir + "/storage") - infoMess = fmt.Sprintf("Detect StorageDir isn't under DeployDir, Create the soft link, CMD %s", cmd) - utl.Log("DEBUG", infoMess) - _, err := utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) - if err != nil { - errMess = fmt.Sprintf("Error in create soft link for StorageDir, CMD %s", cmd) - utl.Log("ERROR", errMess) - panic(err) - } - } - - // create LOG dir for BE nodes - cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.BeServers[i].LogDir) - infoMess = fmt.Sprintf("Create LOG Folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("DEBUG", infoMess) - - _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) - if err != nil { - errMess = fmt.Sprintf("ERROR in creating LOG folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) - utl.Log("ERROR", errMess) - panic(err) - } - - } + var infoMess string + var errMess string + var cmd string + var err error + //var outPut []byte + + sshUser := module.GYamlConf.Global.User + sshKeyRsaFile := module.GSshKeyRsa + + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + sshHost := module.GYamlConf.BeServers[i].Host + sshPort := module.GYamlConf.BeServers[i].SshPort + + // create DEPLOY dir for BE nodes + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.BeServers[i].DeployDir) + infoMess = fmt.Sprintf("Create DEPLOY Folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating DEPLOY folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + + // create STORAGE dir for BE nodes + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.BeServers[i].StorageDir) + infoMess = fmt.Sprintf("Create Storage Folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating STORAGE folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + + if module.GYamlConf.BeServers[i].DeployDir+"/storage" != module.GYamlConf.BeServers[i].StorageDir { + cmd = fmt.Sprintf("ln -s %s %s", module.GYamlConf.BeServers[i].StorageDir, module.GYamlConf.BeServers[i].DeployDir+"/storage") + infoMess = fmt.Sprintf("Detect StorageDir isn't under DeployDir, Create the soft link, CMD %s", cmd) + utl.Log("DEBUG", infoMess) + _, err := utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("Error in create soft link for StorageDir, CMD %s", cmd) + utl.Log("ERROR", errMess) + panic(err) + } + } + + // create LOG dir for BE nodes + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.BeServers[i].LogDir) + infoMess = fmt.Sprintf("Create LOG Folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating LOG folder for BE node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + + } + +} +func CreateCnDir() { + var infoMess string + var errMess string + var cmd string + var err error + + sshUser := module.GYamlConf.Global.User + sshKeyRsaFile := module.GSshKeyRsa + + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + sshHost := module.GYamlConf.CnServers[i].Host + sshPort := module.GYamlConf.CnServers[i].SshPort + + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.CnServers[i].DeployDir) + infoMess = fmt.Sprintf("Create DEPLOY Folder for CN node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating DEPLOY folder for CN node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.CnServers[i].StorageDir) + infoMess = fmt.Sprintf("Create Storage Folder for CN node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating STORAGE folder for CN node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + + if module.GYamlConf.CnServers[i].DeployDir+"/storage" != module.GYamlConf.CnServers[i].StorageDir { + cmd = fmt.Sprintf("ln -s %s %s", module.GYamlConf.CnServers[i].StorageDir, module.GYamlConf.CnServers[i].DeployDir+"/storage") + infoMess = fmt.Sprintf("Detect StorageDir isn't under DeployDir, Create the soft link, CMD %s", cmd) + utl.Log("DEBUG", infoMess) + _, err := utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("Error in create soft link for StorageDir, CMD %s", cmd) + utl.Log("ERROR", errMess) + panic(err) + } + } + + cmd = fmt.Sprintf("mkdir -p %s", module.GYamlConf.CnServers[i].LogDir) + infoMess = fmt.Sprintf("Create LOG Folder for CN node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("DEBUG", infoMess) + + _, err = utl.SshRun(sshUser, sshKeyRsaFile, sshHost, sshPort, cmd) + if err != nil { + errMess = fmt.Sprintf("ERROR in creating LOG folder for CN node: %s@%s:%d \"%s\"", sshUser, sshHost, sshPort, cmd) + utl.Log("ERROR", errMess) + panic(err) + } + } } diff --git a/cluster/prepareOption/deploySr.go b/cluster/prepareOption/deploySr.go index a28e2a6..65485b9 100644 --- a/cluster/prepareOption/deploySr.go +++ b/cluster/prepareOption/deploySr.go @@ -1,115 +1,138 @@ package prepareOption -import( - "fmt" - "strings" - "stargo/module" - "stargo/sr-utl" +import ( + "fmt" + "stargo/jdk" + "stargo/module" + "stargo/sr-utl" + "strings" ) - func DistributeSrDir() { - var infoMess string + var infoMess string + + infoMess = "Distribute FE Dir ..." + utl.Log("OUTPUT", infoMess) + DistributeFeDir() - infoMess = "Distribute FE Dir ..." - utl.Log("OUTPUT", infoMess) - DistributeFeDir() + infoMess = "Distribute BE Dir ..." + utl.Log("OUTPUT", infoMess) + DistributeBeDir() - infoMess = "Distribute BE Dir ..." - utl.Log("OUTPUT", infoMess) - DistributeBeDir() + infoMess = "Distribute CN Dir ..." + utl.Log("OUTPUT", infoMess) + DistributeCnDir() - //module.WriteBackMeta(module.GYamlConf, module.GWriteBackMetaPath) + //module.WriteBackMeta(module.GYamlConf, module.GWriteBackMetaPath) } func DistributeFeDir() { - var infoMess string - // scp -r -P 22 -i rsaKey sourceDir root@nd1:targetDir - // distribute FE folder - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - - sshUser := module.GYamlConf.Global.User - rsaKey := module.GSshKeyRsa - sshPort := module.GYamlConf.FeServers[i].SshPort - sshHost := module.GYamlConf.FeServers[i].Host - - //utl.UploadDir(user string, keyFile string, host string, port int, sourceDir string, targetDir string) - // upload fe dir - feSourceDir := fmt.Sprintf("%s/StarRocks-%s/fe", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // feSourceDir := fmt.Sprintf("%s/download/StarRocks-%s/fe", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) - feTargetDir := module.GYamlConf.FeServers[i].DeployDir - utl.UploadDir(sshUser, rsaKey, sshHost, sshPort, feSourceDir, feTargetDir) - infoMess = fmt.Sprintf("Upload dir feSourceDir = [%s] to feTargetDir = [%s] on FeHost = [%s]", feSourceDir, feTargetDir, sshHost) - utl.Log("INFO", infoMess) - - // upload jdk dir - jdkSourceDir := fmt.Sprintf("%s/jdk1.8.0_301", module.GDownloadPath) - // jdkSourceDir := fmt.Sprintf("%s/download/jdk1.8.0_301", module.GSRCtlRoot) - jdkTargetDir := fmt.Sprintf("%s/jdk", module.GYamlConf.FeServers[i].DeployDir) - utl.UploadDir(sshUser, rsaKey, sshHost, sshPort, jdkSourceDir, jdkTargetDir) - infoMess = fmt.Sprintf("Upload dir JDKSourceDir = [%s] to JDKTargetDir = [%s] on FeHost = [%s]", jdkSourceDir, jdkTargetDir, sshHost) - utl.Log("INFO", infoMess) - - - // modify JAVA_HOME - startFeFilePath := fmt.Sprintf("%s/bin/start_fe.sh", module.GYamlConf.FeServers[i].DeployDir) - jdkPath := fmt.Sprintf("%s/jdk", module.GYamlConf.FeServers[i].DeployDir) - modifyJavaHome(sshUser, rsaKey, sshHost, sshPort, startFeFilePath, jdkPath) - infoMess = fmt.Sprintf("Modify JAVA_HOME: host = [%s], filePath = [%s]", sshHost, startFeFilePath) - utl.Log("INFO", infoMess) - - } + var infoMess string + jdkInfo := jdk.ResolveInfo(module.GYamlConf.Global.JDKVersion) + hasCustomJDKHome := strings.TrimSpace(module.GYamlConf.Global.JDKHome) != "" + // scp -r -P 22 -i rsaKey sourceDir root@nd1:targetDir + // distribute FE folder + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + + sshUser := module.GYamlConf.Global.User + rsaKey := module.GSshKeyRsa + sshPort := module.GYamlConf.FeServers[i].SshPort + sshHost := module.GYamlConf.FeServers[i].Host + + //utl.UploadDir(user string, keyFile string, host string, port int, sourceDir string, targetDir string) + // upload fe dir + feSourceDir := fmt.Sprintf("%s/StarRocks-%s/fe", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + // feSourceDir := fmt.Sprintf("%s/download/StarRocks-%s/fe", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) + feTargetDir := module.GYamlConf.FeServers[i].DeployDir + utl.UploadDir(sshUser, rsaKey, sshHost, sshPort, feSourceDir, feTargetDir) + infoMess = fmt.Sprintf("Upload dir feSourceDir = [%s] to feTargetDir = [%s] on FeHost = [%s]", feSourceDir, feTargetDir, sshHost) + utl.Log("INFO", infoMess) + + if !hasCustomJDKHome { + // upload jdk dir + jdkSourceDir := fmt.Sprintf("%s/%s", module.GDownloadPath, jdkInfo.DownloadFolder) + // jdkSourceDir := fmt.Sprintf("%s/download/%s", module.GSRCtlRoot, jdkInfo.DownloadFolder) + jdkTargetDir := fmt.Sprintf("%s/%s", module.GYamlConf.FeServers[i].DeployDir, jdkInfo.DeployDirName) + utl.UploadDir(sshUser, rsaKey, sshHost, sshPort, jdkSourceDir, jdkTargetDir) + infoMess = fmt.Sprintf("Upload dir JDKSourceDir = [%s] to JDKTargetDir = [%s] on FeHost = [%s]", jdkSourceDir, jdkTargetDir, sshHost) + utl.Log("INFO", infoMess) + } else { + infoMess = fmt.Sprintf("Skip JDK dir upload on FeHost = [%s], use configured JDK_HOME [%s]", sshHost, strings.TrimSpace(module.GYamlConf.Global.JDKHome)) + utl.Log("INFO", infoMess) + } + + // modify JAVA_HOME + startFeFilePath := fmt.Sprintf("%s/bin/start_fe.sh", module.GYamlConf.FeServers[i].DeployDir) + jdkPath := module.ResolveJDKHome(module.GYamlConf.FeServers[i].DeployDir) + modifyJavaHome(sshUser, rsaKey, sshHost, sshPort, startFeFilePath, jdkPath) + infoMess = fmt.Sprintf("Modify JAVA_HOME: host = [%s], filePath = [%s]", sshHost, startFeFilePath) + utl.Log("INFO", infoMess) + + } } +func DistributeBeDir() { + var infoMess string + // scp -r -P 22 -i rsaKey sourceDir root@nd1:targetDir + // distribute FE folder + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + sshUser := module.GYamlConf.Global.User + rsaKey := module.GSshKeyRsa + sshPort := module.GYamlConf.BeServers[i].SshPort + sshHost := module.GYamlConf.BeServers[i].Host + beSourceDir := fmt.Sprintf("%s/StarRocks-%s/be", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + // beSourceDir := fmt.Sprintf("%s/download/StarRocks-%s/be", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) + beTargetDir := module.GYamlConf.BeServers[i].DeployDir -func DistributeBeDir() { + //utl.UploadDir(user string, keyFile string, host string, port int, sourceDir string, targetDir string) + utl.UploadDir(sshUser, rsaKey, sshHost, sshPort, beSourceDir, beTargetDir) + infoMess = fmt.Sprintf("Upload dir BeSourceDir = [%s] to BeTargetDir = [%s] on BeHost = [%s]", beSourceDir, beTargetDir, sshHost) + utl.Log("INFO", infoMess) + + } - var infoMess string - // scp -r -P 22 -i rsaKey sourceDir root@nd1:targetDir - // distribute FE folder - for i := 0; i < len(module.GYamlConf.BeServers); i++ { +} - sshUser := module.GYamlConf.Global.User - rsaKey := module.GSshKeyRsa - sshPort := module.GYamlConf.BeServers[i].SshPort - sshHost := module.GYamlConf.BeServers[i].Host - beSourceDir := fmt.Sprintf("%s/StarRocks-%s/be", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // beSourceDir := fmt.Sprintf("%s/download/StarRocks-%s/be", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) - beTargetDir := module.GYamlConf.BeServers[i].DeployDir +func DistributeCnDir() { - //utl.UploadDir(user string, keyFile string, host string, port int, sourceDir string, targetDir string) - utl.UploadDir(sshUser, rsaKey, sshHost, sshPort, beSourceDir, beTargetDir) - infoMess = fmt.Sprintf("Upload dir BeSourceDir = [%s] to BeTargetDir = [%s] on BeHost = [%s]", beSourceDir, beTargetDir, sshHost) - utl.Log("INFO", infoMess) + var infoMess string + for i := 0; i < len(module.GYamlConf.CnServers); i++ { - } + sshUser := module.GYamlConf.Global.User + rsaKey := module.GSshKeyRsa + sshPort := module.GYamlConf.CnServers[i].SshPort + sshHost := module.GYamlConf.CnServers[i].Host + cnSourceDir := fmt.Sprintf("%s/StarRocks-%s/be", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + cnTargetDir := module.GYamlConf.CnServers[i].DeployDir -} + utl.UploadDir(sshUser, rsaKey, sshHost, sshPort, cnSourceDir, cnTargetDir) + infoMess = fmt.Sprintf("Upload dir CnSourceDir = [%s] to CnTargetDir = [%s] on CnHost = [%s]", cnSourceDir, cnTargetDir, sshHost) + utl.Log("INFO", infoMess) + } +} func modifyJavaHome(sshUser string, rsaKey string, host string, sshPort int, startFeFilePath string, jdkFilePath string) { - var infoMess string - var cmd string - var err error + var infoMess string + var cmd string + var err error - // filePath = module.GYamlConf.FeServers[i].DeployDir - // sed -i 's$# java$# java\nJAVA_HOME=module.GYamlConf.FeServers[i].DeployDir/fe/jdk1.8.0\n$g' filePath - cmd = fmt.Sprintf("sed -i 's$# java$# java\\nJAVA_HOME=%s\\n$g' %s", jdkFilePath, startFeFilePath) - - _, err = utl.SshRun(sshUser, rsaKey, host, sshPort, cmd) - if err != nil { - infoMess = fmt.Sprintf("Error in modify JAVA_HOME. [FeHost = %s, cmd = %s, Error = %v]", host, cmd, err) - utl.Log("ERROR", infoMess) - panic(err) - } + // filePath = module.GYamlConf.FeServers[i].DeployDir + // sed -i 's$# java$# java\nJAVA_HOME=module.GYamlConf.FeServers[i].DeployDir/fe/jdk1.8.0\n$g' filePath + cmd = fmt.Sprintf("sed -i 's$# java$# java\\nJAVA_HOME=%s\\n$g' %s", jdkFilePath, startFeFilePath) + _, err = utl.SshRun(sshUser, rsaKey, host, sshPort, cmd) + if err != nil { + infoMess = fmt.Sprintf("Error in modify JAVA_HOME. [FeHost = %s, cmd = %s, Error = %v]", host, cmd, err) + utl.Log("ERROR", infoMess) + panic(err) + } } - diff --git a/cluster/prepareOption/downloadPkg.go b/cluster/prepareOption/downloadPkg.go index 77b1b99..203a3b6 100644 --- a/cluster/prepareOption/downloadPkg.go +++ b/cluster/prepareOption/downloadPkg.go @@ -1,140 +1,372 @@ package prepareOption - import ( - "stargo/sr-utl" - "stargo/module" - "fmt" - "os" - "io/ioutil" - "net/http" - "strings" + "fmt" + "io/ioutil" + "net/http" + "os" + "path/filepath" + "stargo/jdk" + "stargo/module" + "stargo/sr-utl" + "strings" ) +type srPackageFormat int +const ( + pkgFormatUnknown srPackageFormat = iota + pkgFormatQuickStart + pkgFormatRelease +) func PrepareSRPkg() { - var infoMess string + var infoMess string - infoMess = "Download StarRocks package & jdk ..." - utl.Log("OUTPUT", infoMess) - DownloadSRPkg() + infoMess = "Download StarRocks package & jdk ..." + utl.Log("OUTPUT", infoMess) + archiveName, pkgFormat := DownloadSRPkg() - infoMess = "Decompress StarRocks pakcage & jdk ..." - utl.Log("OUTPUT", infoMess) - DecompressSRPkg() + infoMess = "Decompress StarRocks pakcage & jdk ..." + utl.Log("OUTPUT", infoMess) + DecompressSRPkg(archiveName, pkgFormat) } +func GetDownloadUrl(srVersion string) (downloadUrl string, archiveName string) { + + var infoMess string + var repoUrl string + + module.GetRepo() + + // deal with + if strings.Contains(module.GRepo.Repo, "file://") { + return "", "" + } + + repoUrl = module.GRepo.Repo + "/packageVersion.list" + res, err := http.Get(repoUrl) + if err != nil { + infoMess = fmt.Sprintf("Error in create http get request when download the repo list. [error = %v]", err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + defer res.Body.Close() + + robots, err := ioutil.ReadAll(res.Body) + if err != nil { + infoMess = fmt.Sprintf("Error in read body.[error = %v]", err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + versionList := strings.Split(string(robots), "\n") + vLabel := fmt.Sprintf("[%s]", srVersion) + + for i := 0; i < len(versionList); i++ { + if strings.Contains(versionList[i], vLabel) { + downloadUrl = strings.Replace(versionList[i], vLabel, "", -1) + downloadUrl = strings.Replace(downloadUrl, " ", "", -1) + archiveName = filepath.Base(strings.Split(downloadUrl, "?")[0]) + break + } else { + downloadUrl = "" + } + } + + if downloadUrl == "" { + downloadUrl, archiveName = resolveOfficialReleaseURL(srVersion) + } + + if downloadUrl == "" { + infoMess = fmt.Sprintf("Error in get version %s package, pls check it again.", srVersion) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + return downloadUrl, archiveName -func GetDownloadUrl(srVersion string) (downloadUrl string) { - - var infoMess string - var repoUrl string - - module.GetRepo() - - // deal with - if strings.Contains(module.GRepo.Repo, "file://") { - downloadUrl = "" - return downloadUrl - } - - repoUrl = module.GRepo.Repo + "/packageVersion.list" - res, err := http.Get(repoUrl) - defer res.Body.Close() - if err != nil { - infoMess = fmt.Sprintf("Error in create http get request when download the repo list. [error = %v]", err) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - robots, err := ioutil.ReadAll(res.Body) - if err != nil{ - infoMess = fmt.Sprintf("Error in read body.[error = %v]", err) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - - - versionList := strings.Split(string(robots), "\n") - vLabel := fmt.Sprintf("[%s]", srVersion) - - for i := 0; i < len(versionList); i++ { - if strings.Contains(versionList[i], vLabel) { - downloadUrl = strings.Replace(versionList[i], vLabel, "", -1) - downloadUrl = strings.Replace(downloadUrl, " ", "", -1) - break - } else { - downloadUrl = "" - } - } - - if downloadUrl == "" { - infoMess = fmt.Sprintf("Error in get version %s package, pls check it again. [DownloadUrl = %s]", srVersion, downloadUrl) - utl.Log("ERROR", infoMess) - os.Exit(1) - } - return downloadUrl +} +func DownloadSRPkg() (archiveName string, format srPackageFormat) { + + // download sr & jdk union package + // "http://cdn-thirdparty.starrocks.com/starrocks-2.0.1-quickstart.tar.gz?Expires=10282764349&OSSAccessKeyId=LTAI4GFYjbX9e7QmFnAAvkt8&Signature=kXpA4RHT3sg4Lz9vyRJtbnPdmqM%3D" + // "http://cdn-thirdparty.starrocks.com/starrocks-2.1.3-quickstart.tar.gz?Expires=2511847820&OSSAccessKeyId=LTAI4GFYjbX9e7QmFnAAvkt8&Signature=izihf34yKm7ppk5DENn8jEO2vuw%3D" + // fmt.Sprintf("http://192.168.88.89:9000/starrocks-quick-start/starrocks-%s-quickstart.tar.gz", strings.Replace(module.GSRVersion, "v", "", -1)) + + var infoMess string + version := normalizeVersion(module.GSRVersion) + pkgUrl, inferredName := GetDownloadUrl(module.GSRVersion) + archiveName = inferredName + + if pkgUrl != "" { + if archiveName == "" { + archiveName = filepath.Base(strings.Split(pkgUrl, "?")[0]) + } + if err := utl.DownloadFile(pkgUrl, module.GDownloadPath, archiveName); err != nil { + infoMess = fmt.Sprintf("Error downloading StarRocks package: %v", err) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + infoMess = fmt.Sprintf("Download %s done.", archiveName) + utl.Log("OUTPUT", infoMess) + } else { + archiveName = findExistingPackageArchive(version) + } + + if archiveName == "" { + infoMess = fmt.Sprintf("Could not locate StarRocks package for version %s under %s", version, module.GDownloadPath) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + + return archiveName, detectPackageFormat(archiveName) } -func DownloadSRPkg() { +func DecompressSRPkg(archiveName string, format srPackageFormat) { + + var infoMess string + + tarFileName := filepath.Join(module.GDownloadPath, archiveName) + utl.UnTargz(tarFileName, module.GDownloadPath) + infoMess = fmt.Sprintf("The tar file %s has been decompressed under %s", tarFileName, module.GDownloadPath) + utl.Log("INFO", infoMess) + version := normalizeVersion(module.GSRVersion) + if format == pkgFormatQuickStart { + srTarFile := filepath.Join(module.GDownloadPath, fmt.Sprintf("StarRocks-%s.tar.gz", version)) + if !jdk.Exists(srTarFile) { + infoMess = fmt.Sprintf("StarRocks package [%s] not found after extracting quickstart archive, please verify package content.", srTarFile) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + utl.UnTargz(srTarFile, module.GDownloadPath) + infoMess = fmt.Sprintf("The tar file %s has been decompressed under %s", srTarFile, module.GDownloadPath) + utl.Log("INFO", infoMess) + } else { + normalizeStarRocksDirectory(version) + } - // download sr & jdk union package - // "http://cdn-thirdparty.starrocks.com/starrocks-2.0.1-quickstart.tar.gz?Expires=10282764349&OSSAccessKeyId=LTAI4GFYjbX9e7QmFnAAvkt8&Signature=kXpA4RHT3sg4Lz9vyRJtbnPdmqM%3D" - // "http://cdn-thirdparty.starrocks.com/starrocks-2.1.3-quickstart.tar.gz?Expires=2511847820&OSSAccessKeyId=LTAI4GFYjbX9e7QmFnAAvkt8&Signature=izihf34yKm7ppk5DENn8jEO2vuw%3D" - // fmt.Sprintf("http://192.168.88.89:9000/starrocks-quick-start/starrocks-%s-quickstart.tar.gz", strings.Replace(module.GSRVersion, "v", "", -1)) + decompressJDKPackage() - var infoMess string - pkgUrl := GetDownloadUrl(module.GSRVersion) +} - // downloadPath := module.GSRCtlRoot + "/download" - if pkgUrl != "" { - downloadFile := fmt.Sprintf("starrocks-%s-quickstart.tar.gz", strings.Replace(module.GSRVersion, "v", "", -1)) - utl.DownloadFile(pkgUrl, module.GDownloadPath, downloadFile) - infoMess = fmt.Sprintf("Download done.") - utl.Log("OUTPUT", infoMess) - } +func decompressJDKPackage() { + var infoMess string + if module.GYamlConf != nil && strings.TrimSpace(module.GYamlConf.Global.JDKHome) != "" { + infoMess = fmt.Sprintf("Skip JDK package preparation, use configured JDK_HOME [%s]", strings.TrimSpace(module.GYamlConf.Global.JDKHome)) + utl.Log("INFO", infoMess) + return + } + requestedVersion := "" + if module.GYamlConf != nil { + requestedVersion = strings.TrimSpace(module.GYamlConf.Global.JDKVersion) + } + jdkInfo := jdk.ResolveInfo(requestedVersion) + tarFileName := ensureJDKTarball(jdkInfo) + if tarFileName == "" || !jdk.Exists(tarFileName) { + legacyInfo := jdk.ResolveInfo("8") + infoMess = fmt.Sprintf("JDK tarball [%s] missing, fallback to legacy bundle [%s]", jdkInfo.TarballName, legacyInfo.TarballName) + utl.Log("WARN", infoMess) + tarFileName = ensureJDKTarball(legacyInfo) + jdkInfo = legacyInfo + } + if tarFileName == "" || !jdk.Exists(tarFileName) { + infoMess = fmt.Sprintf("Error in preparing JDK package, tarball [%s] not found", jdkInfo.TarballName) + utl.Log("ERROR", infoMess) + os.Exit(1) + } + utl.UnTargz(tarFileName, module.GDownloadPath) + infoMess = fmt.Sprintf("The tar file %s has been decompressed under %s", tarFileName, module.GDownloadPath) + utl.Log("INFO", infoMess) } +func ensureJDKTarball(info jdk.Info) string { + tarFilePath := fmt.Sprintf("%s/%s", module.GDownloadPath, info.TarballName) + if jdk.Exists(tarFilePath) { + return tarFilePath + } + + if acquireJDKFromRepo(info) && jdk.Exists(tarFilePath) { + return tarFilePath + } + + if info.DownloadURL != "" { + if err := utl.DownloadFile(info.DownloadURL, module.GDownloadPath, info.TarballName); err == nil && jdk.Exists(tarFilePath) { + return tarFilePath + } else if err != nil { + logManualJDKInstruction(info, tarFilePath, err) + } + } else { + logManualJDKInstruction(info, tarFilePath, fmt.Errorf("missing JDK download URL")) + } + + return "" +} -func DecompressSRPkg() { - - - var tarFileName string - var destFilePath string - var infoMess string - - // Decompress SR & JDK union pakcage - tarFileName = fmt.Sprintf("%s/starrocks-%s-quickstart.tar.gz", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - //tarFileName = module.GSRCtlRoot + fmt.Sprintf("/download/starrocks-%s-quickstart.tar.gz", strings.Replace(module.GSRVersion, "v", "", -1)) - // destFilePath = module.GSRCtlRoot + "/download" - destFilePath = module.GDownloadPath - utl.UnTargz(tarFileName, destFilePath) - infoMess = fmt.Sprintf("The tar file %s has been decompressed under %s", tarFileName, destFilePath) - utl.Log("INFO", infoMess) - - // Decompress StarRocks Package - tarFileName = fmt.Sprintf("%s/StarRocks-%s.tar.gz", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // tarFileName = module.GSRCtlRoot + fmt.Sprintf("/download/StarRocks-%s.tar.gz", strings.Replace(module.GSRVersion, "v", "", -1)) - // destFilePath = module.GSRCtlRoot + "/download" - destFilePath = module.GDownloadPath - utl.UnTargz(tarFileName, destFilePath) - infoMess = fmt.Sprintf("The tar file %s has been decompressed under %s", tarFileName, destFilePath) - utl.Log("INFO", infoMess) - - // Decompress JDK Package - tarFileName = module.GDownloadPath + "/jdk-8u301-linux-x64.tar.gz" - // tarFileName = module.GSRCtlRoot + "/download/jdk-8u301-linux-x64.tar.gz" - destFilePath = module.GDownloadPath - // destFilePath = module.GSRCtlRoot + "/download" - utl.UnTargz(tarFileName, destFilePath) - infoMess = fmt.Sprintf("The tar file %s has been decompressed under %s", tarFileName, destFilePath) - utl.Log("INFO", infoMess) +func acquireJDKFromRepo(info jdk.Info) bool { + module.GetRepo() + repo := strings.TrimSpace(module.GRepo.Repo) + if repo == "" { + return false + } + + var err error + if strings.HasPrefix(repo, "file://") { + localRepo := strings.TrimSuffix(strings.TrimPrefix(repo, "file://"), "/") + sourceFile := fmt.Sprintf("%s/%s", localRepo, info.TarballName) + if !jdk.Exists(sourceFile) { + return false + } + _, err = utl.CopyFile(sourceFile, fmt.Sprintf("%s/%s", module.GDownloadPath, info.TarballName)) + } else { + repo = strings.TrimSuffix(repo, "/") + downloadURL := fmt.Sprintf("%s/%s", repo, info.TarballName) + err = utl.DownloadFile(downloadURL, module.GDownloadPath, info.TarballName) + } + + if err != nil { + utl.Log("ERROR", fmt.Sprintf("Error acquiring JDK package [%s]: %v", info.TarballName, err)) + return false + } + return true +} +func logManualJDKInstruction(info jdk.Info, targetPath string, downloadErr error) { + if downloadErr != nil { + utl.Log("ERROR", fmt.Sprintf("Failed to download JDK package [%s]: %v", info.TarballName, downloadErr)) + } + if info.DownloadURL != "" { + utl.Log("INFO", fmt.Sprintf("You can manually download it from: %s", info.DownloadURL)) + } + utl.Log("INFO", fmt.Sprintf("After downloading, place the file at: %s", targetPath)) } +func detectPackageFormat(fileName string) srPackageFormat { + name := strings.ToLower(fileName) + if strings.Contains(name, "quickstart") { + return pkgFormatQuickStart + } + return pkgFormatRelease +} +func normalizeVersion(version string) string { + v := strings.TrimSpace(version) + v = strings.TrimPrefix(v, "v") + v = strings.TrimPrefix(v, "V") + return v +} +func findExistingPackageArchive(version string) string { + candidates := []string{ + fmt.Sprintf("starrocks-%s-quickstart.tar.gz", version), + fmt.Sprintf("StarRocks-%s.tar.gz", version), + fmt.Sprintf("StarRocks-%s-ubuntu-amd64.tar.gz", version), + fmt.Sprintf("StarRocks-%s-centos-amd64.tar.gz", version), + } + for _, candidate := range candidates { + if candidate == "" { + continue + } + if jdk.Exists(filepath.Join(module.GDownloadPath, candidate)) { + return candidate + } + } + + dirEntries, err := os.ReadDir(module.GDownloadPath) + if err != nil { + return "" + } + for _, entry := range dirEntries { + if entry.IsDir() { + continue + } + name := entry.Name() + if strings.HasSuffix(name, ".tar.gz") && strings.Contains(name, version) { + return name + } + } + return "" +} + +func normalizeStarRocksDirectory(version string) { + expectedDir := filepath.Join(module.GDownloadPath, fmt.Sprintf("StarRocks-%s", version)) + if jdk.Exists(expectedDir) { + return + } + + dirEntries, err := os.ReadDir(module.GDownloadPath) + if err != nil { + utl.Log("ERROR", fmt.Sprintf("Failed to scan download directory: %v", err)) + return + } + prefix := fmt.Sprintf("StarRocks-%s", version) + for _, entry := range dirEntries { + if !entry.IsDir() { + continue + } + if !strings.HasPrefix(entry.Name(), prefix) { + continue + } + sourcePath := filepath.Join(module.GDownloadPath, entry.Name()) + if err := os.Rename(sourcePath, expectedDir); err != nil { + utl.Log("ERROR", fmt.Sprintf("Failed to normalize StarRocks dir [%s -> %s]: %v", sourcePath, expectedDir, err)) + } + return + } +} + +func resolveOfficialReleaseURL(srVersion string) (string, string) { + version := normalizeVersion(srVersion) + osKey := getConfiguredOSType() + if osMap, ok := starrocksOfficialURLs[osKey]; ok { + if url := osMap[version]; url != "" { + return url, filepath.Base(url) + } + } + if osMap, ok := starrocksOfficialURLs["generic"]; ok { + if url := osMap[version]; url != "" { + return url, filepath.Base(url) + } + } + return "", "" +} + +func getConfiguredOSType() string { + if module.GYamlConf != nil { + osType := strings.ToLower(strings.TrimSpace(module.GYamlConf.Global.OSType)) + switch osType { + case "ubuntu", "debian": + return "ubuntu" + case "centos", "rhel", "redhat", "rocky", "alma": + return "centos" + } + } + return "centos" +} + +var starrocksOfficialURLs = map[string]map[string]string{ + "ubuntu": { + "4.0.0": "https://releases.starrocks.io/starrocks/StarRocks-4.0.0-ubuntu-amd64.tar.gz", + "3.5.8": "https://releases.starrocks.io/starrocks/StarRocks-3.5.8-ubuntu-amd64.tar.gz", + "3.4.8": "https://releases.starrocks.io/starrocks/StarRocks-3.4.8-ubuntu-amd64.tar.gz", + "3.3.19": "https://releases.starrocks.io/starrocks/StarRocks-3.3.19-ubuntu-amd64.tar.gz", + "3.2.16": "https://releases.starrocks.io/starrocks/StarRocks-3.2.16-ubuntu-amd64.tar.gz", + "3.1.17": "https://releases.starrocks.io/starrocks/StarRocks-3.1.17-ubuntu-amd64.tar.gz", + }, + "centos": { + "4.0.0": "https://releases.starrocks.io/starrocks/StarRocks-4.0.0-centos-amd64.tar.gz", + "3.5.8": "https://releases.starrocks.io/starrocks/StarRocks-3.5.8-centos-amd64.tar.gz", + "3.4.8": "https://releases.starrocks.io/starrocks/StarRocks-3.4.8-centos-amd64.tar.gz", + "3.3.19": "https://releases.starrocks.io/starrocks/StarRocks-3.3.19-centos-amd64.tar.gz", + "3.2.16": "https://releases.starrocks.io/starrocks/StarRocks-3.2.16-centos-amd64.tar.gz", + "3.1.17": "https://releases.starrocks.io/starrocks/StarRocks-3.1.17-centos-amd64.tar.gz", + "3.0.9": "https://releases.starrocks.io/starrocks/StarRocks-3.0.9.tar.gz", + "2.5.22": "https://releases.starrocks.io/starrocks/StarRocks-2.5.22.tar.gz", + }, + "generic": { + "3.0.9": "https://releases.starrocks.io/starrocks/StarRocks-3.0.9.tar.gz", + "2.5.22": "https://releases.starrocks.io/starrocks/StarRocks-2.5.22.tar.gz", + }, +} diff --git a/cluster/prepareOption/preCheck.go b/cluster/prepareOption/preCheck.go index 62a07ca..515928d 100644 --- a/cluster/prepareOption/preCheck.go +++ b/cluster/prepareOption/preCheck.go @@ -1,542 +1,741 @@ package prepareOption -import( - "fmt" - "os" - "strings" - "strconv" - "path" - "regexp" - "stargo/module" - "stargo/sr-utl" +import ( + "fmt" + "os" + "path" + "regexp" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" ) - -// check dir: +// check dir: // SRCTLROOT: tmp & download & log - nothing need to precheck // FE ssh auth // FE user & sudo privileges // FE Deploy Dir // FE port -// BE Deploy Dir +// BE Deploy Dir // BE port -const CHECKPASS string = "PASS" -const CHECKFAILED string = "FAILED" - +const CHECKPASS string = "PASS" +const CHECKFAILED string = "FAILED" type FePreCheckStruct struct { - - SshAuthRes string // check ssh auth - SshAuthInfo string - MetaDirRes string // check meta dir - MetaDirInfo string - DeployDirRes string // check deploy dir - DeployDirInfo string - HttpPortRes string // check http port used - HttpPortInfo string - RpcPortRes string // check rpc port used - RpcPortInfo string - QueryPortRes string // check query port used - QueryPortInfo string - EditLogPortRes string // check edit log port used - EditLogPortInfo string - OpenFilesRes string // check open files count - OpenFilesInfo string + SshAuthRes string // check ssh auth + SshAuthInfo string + MetaDirRes string // check meta dir + MetaDirInfo string + DeployDirRes string // check deploy dir + DeployDirInfo string + HttpPortRes string // check http port used + HttpPortInfo string + RpcPortRes string // check rpc port used + RpcPortInfo string + QueryPortRes string // check query port used + QueryPortInfo string + EditLogPortRes string // check edit log port used + EditLogPortInfo string + CloudMetaPortRes string // check cloud native meta port used + CloudMetaPortInfo string + OpenFilesRes string // check open files count + OpenFilesInfo string } type BePreCheckStruct struct { - - SshAuthRes string // check ssh auth - SshAuthInfo string - storageDirRes string // check storageDir - storageDirInfo string - DeployDirRes string // check deploy dir - DeployDirInfo string - WebServerPortRes string // check web server port - WebServerPortInfo string - HeartbeatServicePortRes string // check heartbeat service port - HeartbeatServicePortInfo string - BrpcPortRes string // check brpc port - BrpcPortInfo string - BePortRes string // check be port - BePortInfo string - OpenFilesRes string // check open files count - OpenFilesInfo string - + SshAuthRes string // check ssh auth + SshAuthInfo string + storageDirRes string // check storageDir + storageDirInfo string + DeployDirRes string // check deploy dir + DeployDirInfo string + WebServerPortRes string // check web server port + WebServerPortInfo string + HeartbeatServicePortRes string // check heartbeat service port + HeartbeatServicePortInfo string + BrpcPortRes string // check brpc port + BrpcPortInfo string + BePortRes string // check be port + BePortInfo string + OpenFilesRes string // check open files count + OpenFilesInfo string } +type CnPreCheckStruct struct { + SshAuthRes string // check ssh auth + SshAuthInfo string + storageDirRes string // check storageDir + storageDirInfo string + DeployDirRes string // check deploy dir + DeployDirInfo string + WebServerPortRes string // check web server port + WebServerPortInfo string + HeartbeatServicePortRes string // check heartbeat service port + HeartbeatServicePortInfo string + BrpcPortRes string // check brpc port + BrpcPortInfo string + BePortRes string // check be port + BePortInfo string + StarletPortRes string // check starlet port + StarletPortInfo string + OpenFilesRes string // check open files count + OpenFilesInfo string +} - -func PreCheckSR () { - - //var preCheckRes bool - var infoMess string - var serverId string - - var preCheckFeAdv FePreCheckStruct - var preCheckBeAdv BePreCheckStruct - var checkFeMess string - var checkBeMess string - - - tmpMinus := []byte("---------------------------------------") - fePreCheckStat := preCheckFe() - bePreCheckStat := preCheckBe() - infoMess = fmt.Sprintf("PreCheck FE:\n") - infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", "server id", "ssh auth", "meta dir", "deploy dir", "http port", "rpc port", "query port", "edit log port", "open files count") - infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", tmpMinus[:20], tmpMinus[:15], tmpMinus[:30], tmpMinus[:30], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15]) - for i := 0; i < len(fePreCheckStat); i++ { - - serverId = fmt.Sprintf("%s:%d", module.GYamlConf.FeServers[i].Host, module.GYamlConf.FeServers[i].EditLogPort) - infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", - serverId, - fePreCheckStat[i].SshAuthRes, - fePreCheckStat[i].MetaDirRes, - fePreCheckStat[i].DeployDirRes, - fePreCheckStat[i].HttpPortRes, - fePreCheckStat[i].RpcPortRes, - fePreCheckStat[i].QueryPortRes, - fePreCheckStat[i].EditLogPortRes, - fePreCheckStat[i].OpenFilesRes) - - if fePreCheckStat[i].SshAuthRes != CHECKPASS { - fmt.Println("DEUBG >>>>>> ssh auth ", i, fePreCheckStat[i].SshAuthRes) - preCheckFeAdv.SshAuthRes = CHECKFAILED - preCheckFeAdv.SshAuthInfo = preCheckFeAdv.SshAuthInfo + fePreCheckStat[i].SshAuthInfo + "\n" +func PreCheckSR() { + + //var preCheckRes bool + var infoMess string + var serverId string + + var preCheckFeAdv FePreCheckStruct + var preCheckBeAdv BePreCheckStruct + var preCheckCnAdv CnPreCheckStruct + var checkFeMess string + var checkBeMess string + var checkCnMess string + + tmpMinus := []byte("---------------------------------------") + fePreCheckStat := preCheckFe() + bePreCheckStat := preCheckBe() + cnPreCheckStat := preCheckCn() + infoMess = fmt.Sprintf("PreCheck FE:\n") + if module.IsSharedDataCluster() { + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s %-15s\n", "server id", "ssh auth", "meta dir", "deploy dir", "http port", "rpc port", "query port", "edit log port", "cloud meta", "open files count") + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s %-15s\n", tmpMinus[:20], tmpMinus[:15], tmpMinus[:30], tmpMinus[:30], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15]) + } else { + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", "server id", "ssh auth", "meta dir", "deploy dir", "http port", "rpc port", "query port", "edit log port", "open files count") + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", tmpMinus[:20], tmpMinus[:15], tmpMinus[:30], tmpMinus[:30], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15]) } - - if fePreCheckStat[i].MetaDirRes != CHECKPASS { - preCheckFeAdv.MetaDirRes = CHECKFAILED - preCheckFeAdv.MetaDirInfo = preCheckFeAdv.MetaDirInfo + fePreCheckStat[i].MetaDirInfo + "\n" + for i := 0; i < len(fePreCheckStat); i++ { + + serverId = fmt.Sprintf("%s:%d", module.GYamlConf.FeServers[i].Host, module.GYamlConf.FeServers[i].EditLogPort) + if module.IsSharedDataCluster() { + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s %-15s\n", + serverId, + fePreCheckStat[i].SshAuthRes, + fePreCheckStat[i].MetaDirRes, + fePreCheckStat[i].DeployDirRes, + fePreCheckStat[i].HttpPortRes, + fePreCheckStat[i].RpcPortRes, + fePreCheckStat[i].QueryPortRes, + fePreCheckStat[i].EditLogPortRes, + fePreCheckStat[i].CloudMetaPortRes, + fePreCheckStat[i].OpenFilesRes) + } else { + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", + serverId, + fePreCheckStat[i].SshAuthRes, + fePreCheckStat[i].MetaDirRes, + fePreCheckStat[i].DeployDirRes, + fePreCheckStat[i].HttpPortRes, + fePreCheckStat[i].RpcPortRes, + fePreCheckStat[i].QueryPortRes, + fePreCheckStat[i].EditLogPortRes, + fePreCheckStat[i].OpenFilesRes) + } + + if fePreCheckStat[i].SshAuthRes != CHECKPASS { + fmt.Println("DEUBG >>>>>> ssh auth ", i, fePreCheckStat[i].SshAuthRes) + preCheckFeAdv.SshAuthRes = CHECKFAILED + preCheckFeAdv.SshAuthInfo = preCheckFeAdv.SshAuthInfo + fePreCheckStat[i].SshAuthInfo + "\n" + } + + if fePreCheckStat[i].MetaDirRes != CHECKPASS { + preCheckFeAdv.MetaDirRes = CHECKFAILED + preCheckFeAdv.MetaDirInfo = preCheckFeAdv.MetaDirInfo + fePreCheckStat[i].MetaDirInfo + "\n" + } + + if fePreCheckStat[i].DeployDirRes != CHECKPASS { + preCheckFeAdv.DeployDirRes = CHECKFAILED + preCheckFeAdv.DeployDirInfo = preCheckFeAdv.DeployDirInfo + fePreCheckStat[i].DeployDirInfo + "\n" + } + + if fePreCheckStat[i].HttpPortRes != CHECKPASS { + preCheckFeAdv.HttpPortRes = CHECKFAILED + preCheckFeAdv.HttpPortInfo = preCheckFeAdv.HttpPortInfo + fePreCheckStat[i].HttpPortInfo + "\n" + } + + if fePreCheckStat[i].RpcPortRes != CHECKPASS { + preCheckFeAdv.RpcPortRes = CHECKFAILED + preCheckFeAdv.RpcPortInfo = preCheckFeAdv.RpcPortInfo + fePreCheckStat[i].RpcPortInfo + "\n" + } + + if fePreCheckStat[i].QueryPortRes != CHECKPASS { + preCheckFeAdv.QueryPortRes = CHECKFAILED + preCheckFeAdv.QueryPortInfo = preCheckFeAdv.QueryPortInfo + fePreCheckStat[i].QueryPortInfo + "\n" + } + + if fePreCheckStat[i].EditLogPortRes != CHECKPASS { + preCheckFeAdv.EditLogPortRes = CHECKFAILED + preCheckFeAdv.EditLogPortInfo = preCheckFeAdv.EditLogPortInfo + fePreCheckStat[i].EditLogPortInfo + "\n" + } + + if fePreCheckStat[i].CloudMetaPortRes != CHECKPASS { + preCheckFeAdv.CloudMetaPortRes = CHECKFAILED + preCheckFeAdv.CloudMetaPortInfo = preCheckFeAdv.CloudMetaPortInfo + fePreCheckStat[i].CloudMetaPortInfo + "\n" + } + + if fePreCheckStat[i].OpenFilesRes != CHECKPASS { + preCheckFeAdv.OpenFilesRes = CHECKFAILED + preCheckFeAdv.OpenFilesInfo = preCheckFeAdv.OpenFilesInfo + fePreCheckStat[i].OpenFilesInfo + "\n" + } } - if fePreCheckStat[i].DeployDirRes != CHECKPASS { - preCheckFeAdv.DeployDirRes = CHECKFAILED - preCheckFeAdv.DeployDirInfo = preCheckFeAdv.DeployDirInfo + fePreCheckStat[i].DeployDirInfo + "\n" + infoMess = infoMess + fmt.Sprintf("\n") + infoMess = infoMess + fmt.Sprintf("PreCheck BE:\n") + + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", "server id", "ssh auth", "storage dir", "deploy dir", "webSer port", "heartbeat port", "brpc port", "be port", "open files count") + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", tmpMinus[:20], tmpMinus[:15], tmpMinus[:30], tmpMinus[:30], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15]) + + for i := 0; i < len(bePreCheckStat); i++ { + serverId = fmt.Sprintf("%s:%d", module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].BePort) + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", + serverId, + bePreCheckStat[i].SshAuthRes, + bePreCheckStat[i].storageDirRes, + bePreCheckStat[i].DeployDirRes, + bePreCheckStat[i].WebServerPortRes, + bePreCheckStat[i].HeartbeatServicePortRes, + bePreCheckStat[i].BrpcPortRes, + bePreCheckStat[i].BePortRes, + bePreCheckStat[i].OpenFilesRes) + if bePreCheckStat[i].SshAuthRes != CHECKPASS { + preCheckBeAdv.SshAuthRes = CHECKFAILED + preCheckBeAdv.SshAuthInfo = preCheckBeAdv.SshAuthInfo + bePreCheckStat[i].SshAuthInfo + "\n" + } + + if bePreCheckStat[i].storageDirRes != CHECKPASS { + preCheckBeAdv.storageDirRes = CHECKFAILED + preCheckBeAdv.storageDirInfo = preCheckBeAdv.storageDirInfo + bePreCheckStat[i].storageDirInfo + "\n" + } + + if bePreCheckStat[i].DeployDirRes != CHECKPASS { + preCheckBeAdv.DeployDirRes = CHECKFAILED + preCheckBeAdv.DeployDirInfo = preCheckBeAdv.DeployDirInfo + bePreCheckStat[i].DeployDirInfo + "\n" + } + + if bePreCheckStat[i].WebServerPortRes != CHECKPASS { + preCheckBeAdv.WebServerPortRes = CHECKFAILED + preCheckBeAdv.WebServerPortInfo = preCheckBeAdv.WebServerPortInfo + bePreCheckStat[i].WebServerPortInfo + "\n" + } + + if bePreCheckStat[i].HeartbeatServicePortRes != CHECKPASS { + preCheckBeAdv.HeartbeatServicePortRes = CHECKFAILED + preCheckBeAdv.HeartbeatServicePortInfo = preCheckBeAdv.HeartbeatServicePortInfo + bePreCheckStat[i].HeartbeatServicePortInfo + "\n" + } + + if bePreCheckStat[i].BrpcPortRes != CHECKPASS { + preCheckBeAdv.BrpcPortRes = CHECKFAILED + preCheckBeAdv.BrpcPortInfo = preCheckBeAdv.BrpcPortInfo + bePreCheckStat[i].BrpcPortInfo + "\n" + } + + if bePreCheckStat[i].BePortRes != CHECKPASS { + preCheckBeAdv.BePortRes = CHECKFAILED + preCheckBeAdv.BePortInfo = preCheckBeAdv.BePortInfo + bePreCheckStat[i].BePortInfo + "\n" + } + + if bePreCheckStat[i].OpenFilesRes != CHECKPASS { + preCheckBeAdv.OpenFilesRes = CHECKFAILED + preCheckBeAdv.OpenFilesInfo = preCheckBeAdv.OpenFilesInfo + bePreCheckStat[i].OpenFilesInfo + "\n" + } } - if fePreCheckStat[i].HttpPortRes != CHECKPASS { - preCheckFeAdv.HttpPortRes = CHECKFAILED - preCheckFeAdv.HttpPortInfo = preCheckFeAdv.HttpPortInfo + fePreCheckStat[i].HttpPortInfo + "\n" + if len(cnPreCheckStat) > 0 { + infoMess = infoMess + fmt.Sprintf("\n") + infoMess = infoMess + fmt.Sprintf("PreCheck CN:\n") + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s %-15s\n", "server id", "ssh auth", "storage dir", "deploy dir", "webSer port", "heartbeat port", "brpc port", "be port", "starlet port", "open files count") + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s %-15s\n", tmpMinus[:20], tmpMinus[:15], tmpMinus[:30], tmpMinus[:30], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15]) + + for i := 0; i < len(cnPreCheckStat); i++ { + serverId = fmt.Sprintf("%s:%d", module.GYamlConf.CnServers[i].Host, module.GYamlConf.CnServers[i].BePort) + infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s %-15s\n", + serverId, + cnPreCheckStat[i].SshAuthRes, + cnPreCheckStat[i].storageDirRes, + cnPreCheckStat[i].DeployDirRes, + cnPreCheckStat[i].WebServerPortRes, + cnPreCheckStat[i].HeartbeatServicePortRes, + cnPreCheckStat[i].BrpcPortRes, + cnPreCheckStat[i].BePortRes, + cnPreCheckStat[i].StarletPortRes, + cnPreCheckStat[i].OpenFilesRes) + if cnPreCheckStat[i].SshAuthRes != CHECKPASS { + preCheckCnAdv.SshAuthRes = CHECKFAILED + preCheckCnAdv.SshAuthInfo = preCheckCnAdv.SshAuthInfo + cnPreCheckStat[i].SshAuthInfo + "\n" + } + + if cnPreCheckStat[i].storageDirRes != CHECKPASS { + preCheckCnAdv.storageDirRes = CHECKFAILED + preCheckCnAdv.storageDirInfo = preCheckCnAdv.storageDirInfo + cnPreCheckStat[i].storageDirInfo + "\n" + } + + if cnPreCheckStat[i].DeployDirRes != CHECKPASS { + preCheckCnAdv.DeployDirRes = CHECKFAILED + preCheckCnAdv.DeployDirInfo = preCheckCnAdv.DeployDirInfo + cnPreCheckStat[i].DeployDirInfo + "\n" + } + + if cnPreCheckStat[i].WebServerPortRes != CHECKPASS { + preCheckCnAdv.WebServerPortRes = CHECKFAILED + preCheckCnAdv.WebServerPortInfo = preCheckCnAdv.WebServerPortInfo + cnPreCheckStat[i].WebServerPortInfo + "\n" + } + + if cnPreCheckStat[i].HeartbeatServicePortRes != CHECKPASS { + preCheckCnAdv.HeartbeatServicePortRes = CHECKFAILED + preCheckCnAdv.HeartbeatServicePortInfo = preCheckCnAdv.HeartbeatServicePortInfo + cnPreCheckStat[i].HeartbeatServicePortInfo + "\n" + } + + if cnPreCheckStat[i].BrpcPortRes != CHECKPASS { + preCheckCnAdv.BrpcPortRes = CHECKFAILED + preCheckCnAdv.BrpcPortInfo = preCheckCnAdv.BrpcPortInfo + cnPreCheckStat[i].BrpcPortInfo + "\n" + } + + if cnPreCheckStat[i].BePortRes != CHECKPASS { + preCheckCnAdv.BePortRes = CHECKFAILED + preCheckCnAdv.BePortInfo = preCheckCnAdv.BePortInfo + cnPreCheckStat[i].BePortInfo + "\n" + } + + if cnPreCheckStat[i].StarletPortRes != CHECKPASS { + preCheckCnAdv.StarletPortRes = CHECKFAILED + preCheckCnAdv.StarletPortInfo = preCheckCnAdv.StarletPortInfo + cnPreCheckStat[i].StarletPortInfo + "\n" + } + + if cnPreCheckStat[i].OpenFilesRes != CHECKPASS { + preCheckCnAdv.OpenFilesRes = CHECKFAILED + preCheckCnAdv.OpenFilesInfo = preCheckCnAdv.OpenFilesInfo + cnPreCheckStat[i].OpenFilesInfo + "\n" + } + } } - if fePreCheckStat[i].RpcPortRes != CHECKPASS { - preCheckFeAdv.RpcPortRes = CHECKFAILED - preCheckFeAdv.RpcPortInfo = preCheckFeAdv.RpcPortInfo + fePreCheckStat[i].RpcPortInfo + "\n" - } + infoMess = "PRE CHECK DEPLOY ENV:\n" + infoMess + fmt.Sprintf("\n") + utl.Log("OUTPUT", infoMess) - if fePreCheckStat[i].QueryPortRes != CHECKPASS { - preCheckFeAdv.QueryPortRes = CHECKFAILED - preCheckFeAdv.QueryPortInfo = preCheckFeAdv.QueryPortInfo + fePreCheckStat[i].QueryPortInfo + "\n" + checkFeMess = getFeAdvMess(preCheckFeAdv) + if checkFeMess != "" { + checkFeMess = "Please use bellowing promption to fix the issue for FE servers:\n" + checkFeMess + utl.Log("ERROR", checkFeMess) } - if fePreCheckStat[i].EditLogPortRes != CHECKPASS { - preCheckFeAdv.EditLogPortRes = CHECKFAILED - preCheckFeAdv.EditLogPortInfo = preCheckFeAdv.EditLogPortInfo + fePreCheckStat[i].EditLogPortInfo + "\n" + checkBeMess = getBeAdvMess(preCheckBeAdv) + if checkBeMess != "" { + checkBeMess = "Please use bellowing promption to fix the issue for BE servers:\n" + checkBeMess + utl.Log("ERROR", checkBeMess) } - if fePreCheckStat[i].OpenFilesRes != CHECKPASS { - preCheckFeAdv.OpenFilesRes = CHECKFAILED - preCheckFeAdv.OpenFilesInfo = preCheckFeAdv.OpenFilesInfo + fePreCheckStat[i].OpenFilesInfo + "\n" + checkCnMess = getCnAdvMess(preCheckCnAdv) + if checkCnMess != "" { + checkCnMess = "Please use bellowing promption to fix the issue for CN servers:\n" + checkCnMess + utl.Log("ERROR", checkCnMess) } - } + if strings.Contains(infoMess, CHECKFAILED) { + infoMess = "PreCheck failed." + utl.Log("ERROR", infoMess) + os.Exit(1) + } else { + infoMess = "PreCheck successfully. RESPECT" + utl.Log("OUTPUT", infoMess) + } - infoMess = infoMess + fmt.Sprintf("\n") - infoMess = infoMess + fmt.Sprintf("PreCheck BE:\n") +} - infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", "server id", "ssh auth", "storage dir", "deploy dir", "webSer port", "heartbeat port", "brpc port", "be port", "open files count") - infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", tmpMinus[:20], tmpMinus[:15], tmpMinus[:30], tmpMinus[:30], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15], tmpMinus[:15]) +func getFeAdvMess(preCheckFeAdv FePreCheckStruct) string { + var checkMess string - for i := 0; i < len(bePreCheckStat); i++ { - serverId = fmt.Sprintf("%s:%d", module.GYamlConf.BeServers[i].Host, module.GYamlConf.BeServers[i].BePort) - infoMess = infoMess + fmt.Sprintf("%-25s %-15s %-30s %-30s %-15s %-15s %-15s %-15s %-15s\n", - serverId, - bePreCheckStat[i].SshAuthRes, - bePreCheckStat[i].storageDirRes, - bePreCheckStat[i].DeployDirRes, - bePreCheckStat[i].WebServerPortRes, - bePreCheckStat[i].HeartbeatServicePortRes, - bePreCheckStat[i].BrpcPortRes, - bePreCheckStat[i].BePortRes, - bePreCheckStat[i].OpenFilesRes) - if bePreCheckStat[i].SshAuthRes != CHECKPASS { - preCheckBeAdv.SshAuthRes = CHECKFAILED - preCheckBeAdv.SshAuthInfo = preCheckBeAdv.SshAuthInfo + bePreCheckStat[i].SshAuthInfo + "\n" + if preCheckFeAdv.SshAuthRes == CHECKFAILED { + checkMess = checkMess + "Detect no SSH Auth. Use bellowing command to check or fix the issue:\n" + preCheckFeAdv.SshAuthInfo } - if bePreCheckStat[i].storageDirRes != CHECKPASS { - preCheckBeAdv.storageDirRes = CHECKFAILED - preCheckBeAdv.storageDirInfo = preCheckBeAdv.storageDirInfo + bePreCheckStat[i].storageDirInfo + "\n" + if preCheckFeAdv.MetaDirRes == CHECKFAILED { + checkMess = checkMess + "Detect the FE META FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckFeAdv.MetaDirInfo } - if bePreCheckStat[i].DeployDirRes != CHECKPASS { - preCheckBeAdv.DeployDirRes = CHECKFAILED - preCheckBeAdv.DeployDirInfo = preCheckBeAdv.DeployDirInfo + bePreCheckStat[i].DeployDirInfo + "\n" + if preCheckFeAdv.DeployDirRes == CHECKFAILED { + checkMess = checkMess + "Detect the FE DEPLOY FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckFeAdv.DeployDirInfo } - if bePreCheckStat[i].WebServerPortRes != CHECKPASS { - preCheckBeAdv.WebServerPortRes = CHECKFAILED - preCheckBeAdv.WebServerPortInfo = preCheckBeAdv.WebServerPortInfo + bePreCheckStat[i].WebServerPortInfo + "\n" + if preCheckFeAdv.HttpPortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE HTTP PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.HttpPortInfo } - - if bePreCheckStat[i].HeartbeatServicePortRes != CHECKPASS { - preCheckBeAdv.HeartbeatServicePortRes = CHECKFAILED - preCheckBeAdv.HeartbeatServicePortInfo = preCheckBeAdv.HeartbeatServicePortInfo + bePreCheckStat[i].HeartbeatServicePortInfo + "\n" + if preCheckFeAdv.RpcPortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE RPC PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.RpcPortInfo } - - if bePreCheckStat[i].BrpcPortRes != CHECKPASS { - preCheckBeAdv.BrpcPortRes = CHECKFAILED - preCheckBeAdv.BrpcPortInfo = preCheckBeAdv.BrpcPortInfo + bePreCheckStat[i].BrpcPortInfo + "\n" + if preCheckFeAdv.QueryPortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE QUERY PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.QueryPortInfo } - if bePreCheckStat[i].BePortRes != CHECKPASS { - preCheckBeAdv.BePortRes = CHECKFAILED - preCheckBeAdv.BePortInfo = preCheckBeAdv.BePortInfo + bePreCheckStat[i].BePortInfo + "\n" + if preCheckFeAdv.EditLogPortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE EDIT LOG PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.EditLogPortInfo } - if bePreCheckStat[i].OpenFilesRes != CHECKPASS { - preCheckBeAdv.OpenFilesRes = CHECKFAILED - preCheckBeAdv.OpenFilesInfo = preCheckBeAdv.OpenFilesInfo + bePreCheckStat[i].OpenFilesInfo + "\n" + if preCheckFeAdv.CloudMetaPortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE CLOUD NATIVE META PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.CloudMetaPortInfo } - } - - infoMess = "PRE CHECK DEPLOY ENV:\n" + infoMess + fmt.Sprintf("\n") - utl.Log("OUTPUT", infoMess) - checkFeMess = getFeAdvMess(preCheckFeAdv) - if checkFeMess != "" { - checkFeMess = "Please use bellowing promption to fix the issue for FE servers:\n" + checkFeMess - utl.Log("ERROR", checkFeMess) - } - - checkBeMess = getBeAdvMess(preCheckBeAdv) - if checkBeMess != "" { - checkBeMess = "Please use bellowing promption to fix the issue for BE servers:\n" + checkBeMess - utl.Log("ERROR", checkBeMess) - } - - - if strings.Contains(infoMess, CHECKFAILED) { - infoMess = "PreCheck failed." - utl.Log("ERROR", infoMess) - os.Exit(1) - } else { - infoMess = "PreCheck successfully. RESPECT" - utl.Log("OUTPUT", infoMess) - } + if preCheckFeAdv.OpenFilesRes == CHECKFAILED { + checkMess = checkMess + "Detect FE OPEN FILES COUNT not enought:\n" + preCheckFeAdv.OpenFilesInfo + } + return checkMess } +func getCnAdvMess(preCheckCnAdv CnPreCheckStruct) string { + var checkMess string -func getFeAdvMess(preCheckFeAdv FePreCheckStruct) string { + if preCheckCnAdv.SshAuthRes == CHECKFAILED { + checkMess = checkMess + "Detect no SSH Auth. Use bellowing command to check or fix the issue:\n" + preCheckCnAdv.SshAuthInfo + } - var checkMess string + if preCheckCnAdv.storageDirRes == CHECKFAILED { + checkMess = checkMess + "Detect the CN STORAGE FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckCnAdv.storageDirInfo + } - if preCheckFeAdv.SshAuthRes == CHECKFAILED { - checkMess = checkMess + "Detect no SSH Auth. Use bellowing command to check or fix the issue:\n" + preCheckFeAdv.SshAuthInfo - } + if preCheckCnAdv.DeployDirRes == CHECKFAILED { + checkMess = checkMess + "Detect the CN DEPLOY FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckCnAdv.DeployDirInfo + } - if preCheckFeAdv.MetaDirRes == CHECKFAILED { - checkMess = checkMess + "Detect the FE META FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckFeAdv.MetaDirInfo - } + if preCheckCnAdv.WebServerPortRes == CHECKFAILED { + checkMess = checkMess + "Detect CN WEB SERVICE PORT used. Use bellowing command to check the prot:\n" + preCheckCnAdv.WebServerPortInfo + } - if preCheckFeAdv.DeployDirRes == CHECKFAILED { - checkMess = checkMess + "Detect the FE DEPLOY FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckFeAdv.DeployDirInfo - } + if preCheckCnAdv.HeartbeatServicePortRes == CHECKFAILED { + checkMess = checkMess + "Detect CN HEARTBEAT SERVICE PORT used. Use bellowing command to check the prot:\n" + preCheckCnAdv.HeartbeatServicePortInfo + } - if preCheckFeAdv.HttpPortRes == CHECKFAILED { - checkMess = checkMess + "Detect FE HTTP PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.HttpPortInfo - } - if preCheckFeAdv.RpcPortRes == CHECKFAILED { - checkMess = checkMess + "Detect FE RPC PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.RpcPortInfo - } - if preCheckFeAdv.QueryPortRes == CHECKFAILED { - checkMess = checkMess + "Detect FE QUERY PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.QueryPortInfo - } + if preCheckCnAdv.BrpcPortRes == CHECKFAILED { + checkMess = checkMess + "Detect CN BRPC PORT used. Use bellowing command to check the prot:\n" + preCheckCnAdv.BrpcPortInfo + } - if preCheckFeAdv.EditLogPortRes == CHECKFAILED { - checkMess = checkMess + "Detect FE EDIT LOG PORT used. Use bellowing command to check the prot:\n" + preCheckFeAdv.EditLogPortInfo - } + if preCheckCnAdv.BePortRes == CHECKFAILED { + checkMess = checkMess + "Detect CN BE PORT used. Use bellowing command to check the prot:\n" + preCheckCnAdv.BePortInfo + } - if preCheckFeAdv.OpenFilesRes == CHECKFAILED { - checkMess = checkMess + "Detect FE OPEN FILES COUNT not enought:\n" + preCheckFeAdv.OpenFilesInfo - } + if preCheckCnAdv.StarletPortRes == CHECKFAILED { + checkMess = checkMess + "Detect CN STARLET PORT used. Use bellowing command to check the prot:\n" + preCheckCnAdv.StarletPortInfo + } - return checkMess -} + if preCheckCnAdv.OpenFilesRes == CHECKFAILED { + checkMess = checkMess + "Detect CN OPEN FILES COUNT not enought:\n" + preCheckCnAdv.OpenFilesInfo + } + return checkMess +} func getBeAdvMess(preCheckBeAdv BePreCheckStruct) string { - var checkMess string + var checkMess string - if preCheckBeAdv.SshAuthRes == CHECKFAILED { - checkMess = checkMess + "Detect no SSH Auth. Use bellowing command to check or fix the issue:\n" + preCheckBeAdv.SshAuthInfo - } + if preCheckBeAdv.SshAuthRes == CHECKFAILED { + checkMess = checkMess + "Detect no SSH Auth. Use bellowing command to check or fix the issue:\n" + preCheckBeAdv.SshAuthInfo + } - if preCheckBeAdv.storageDirRes == CHECKFAILED { - checkMess = checkMess + "Detect the BE STORAGE FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckBeAdv.storageDirInfo - } + if preCheckBeAdv.storageDirRes == CHECKFAILED { + checkMess = checkMess + "Detect the BE STORAGE FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckBeAdv.storageDirInfo + } - if preCheckBeAdv.DeployDirRes == CHECKFAILED { - checkMess = checkMess + "Detect the BE DEPLOY FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckBeAdv.DeployDirInfo - } + if preCheckBeAdv.DeployDirRes == CHECKFAILED { + checkMess = checkMess + "Detect the BE DEPLOY FOLDER exist or no privilege. Use bellowing command to check or fix the issue:\n" + preCheckBeAdv.DeployDirInfo + } - if preCheckBeAdv.WebServerPortRes == CHECKFAILED { - checkMess = checkMess + "Detect FE WEB SERVICE PORT used. Use bellowing command to check the prot:\n" + preCheckBeAdv.WebServerPortInfo - } + if preCheckBeAdv.WebServerPortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE WEB SERVICE PORT used. Use bellowing command to check the prot:\n" + preCheckBeAdv.WebServerPortInfo + } - if preCheckBeAdv.HeartbeatServicePortRes == CHECKFAILED { - checkMess = checkMess + "Detect FE HEARTBEAT SERVICE PORT used. Use bellowing command to check the prot:\n" + preCheckBeAdv.HeartbeatServicePortInfo - } + if preCheckBeAdv.HeartbeatServicePortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE HEARTBEAT SERVICE PORT used. Use bellowing command to check the prot:\n" + preCheckBeAdv.HeartbeatServicePortInfo + } - if preCheckBeAdv.BrpcPortRes == CHECKFAILED { - checkMess = checkMess + "Detect FE BRPC PORT used. Use bellowing command to check the prot:\n" + preCheckBeAdv.BrpcPortInfo - } + if preCheckBeAdv.BrpcPortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE BRPC PORT used. Use bellowing command to check the prot:\n" + preCheckBeAdv.BrpcPortInfo + } - if preCheckBeAdv.BePortRes == CHECKFAILED { - checkMess = checkMess + "Detect FE BE PORT used. Use bellowing command to check the prot:\n" + preCheckBeAdv.BePortInfo - } + if preCheckBeAdv.BePortRes == CHECKFAILED { + checkMess = checkMess + "Detect FE BE PORT used. Use bellowing command to check the prot:\n" + preCheckBeAdv.BePortInfo + } - if preCheckBeAdv.OpenFilesRes == CHECKFAILED { - checkMess = checkMess + "Detect FE OPEN FILES COUNT not enought:\n" + preCheckBeAdv.OpenFilesInfo - } + if preCheckBeAdv.OpenFilesRes == CHECKFAILED { + checkMess = checkMess + "Detect FE OPEN FILES COUNT not enought:\n" + preCheckBeAdv.OpenFilesInfo + } - return checkMess + return checkMess } - func preCheckFe() (fePreCheckRes []FePreCheckStruct) { - var tmpSshHost string - var tmpSshPort int - var tmpDetectDir string - var tmpDetectPort int - var tmpUser string - var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpDetectDir string + var tmpDetectPort int + var tmpUser string + var tmpKeyRsa string + + fePreCheckRes = make([]FePreCheckStruct, len(module.GYamlConf.FeServers)) + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + + var tmpCheckRes FePreCheckStruct + tmpSshHost = module.GYamlConf.FeServers[i].Host + tmpSshPort = module.GYamlConf.FeServers[i].SshPort + + // check ssh auth + tmpCheckRes.SshAuthRes, tmpCheckRes.SshAuthInfo = sshAuth(tmpSshHost, tmpSshPort) + + // check sudo privilege + // tmpCheckRes.UserSudo = sudoPriv(tmpSshHost, tmpSshPort, tmpUser) + + // check FE deploy folder + tmpDetectDir = module.GYamlConf.FeServers[i].DeployDir + tmpCheckRes.DeployDirRes, tmpCheckRes.DeployDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "FE deploy folder") + //tmpCheckRes.DeployDir = dirPriv(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "FE deploy folder") + + // check meta folder + tmpDetectDir = module.GYamlConf.FeServers[i].MetaDir + tmpCheckRes.MetaDirRes, tmpCheckRes.MetaDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "FE meta folder") + //tmpCheckRes.MetaDir = dirPriv(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "FE meta folder") + + // check FE HttpPort + tmpDetectPort = module.GYamlConf.FeServers[i].HttpPort + tmpCheckRes.HttpPortRes, tmpCheckRes.HttpPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "FE Http Port") + + // check FE RpcPort + tmpDetectPort = module.GYamlConf.FeServers[i].RpcPort + tmpCheckRes.RpcPortRes, tmpCheckRes.RpcPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "FE RPC Port") + + // check FE EditLogPort + tmpDetectPort = module.GYamlConf.FeServers[i].EditLogPort + tmpCheckRes.EditLogPortRes, tmpCheckRes.EditLogPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "FE Edit Log Port") + + // check FE QueryPort + tmpDetectPort = module.GYamlConf.FeServers[i].QueryPort + tmpCheckRes.QueryPortRes, tmpCheckRes.QueryPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "FE Query Port") + + // check FE open files count + tmpCheckRes.OpenFilesRes, tmpCheckRes.OpenFilesInfo = openFile(tmpSshHost, tmpSshPort) + + if module.IsSharedDataCluster() { + cloudNativeMetaPort := module.DefaultCloudNativeMetaPort + if val, exists := module.GYamlConf.FeServers[i].Config["cloud_native_meta_port"]; exists && strings.TrimSpace(val) != "" { + cloudNativeMetaPort = strings.TrimSpace(val) + } + if port, err := strconv.Atoi(cloudNativeMetaPort); err == nil { + tmpCheckRes.CloudMetaPortRes, tmpCheckRes.CloudMetaPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, port, "FE Cloud Native Meta Port") + } + } + + fePreCheckRes[i] = tmpCheckRes + } - fePreCheckRes = make([]FePreCheckStruct, len(module.GYamlConf.FeServers)) - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa + return fePreCheckRes +} - for i := 0; i < len(module.GYamlConf.FeServers); i++ { +func preCheckBe() (bePreCheckRes []BePreCheckStruct) { + var tmpSshHost string + var tmpSshPort int + var tmpDetectDir string + var tmpDetectPort int + var tmpUser string + var tmpKeyRsa string - var tmpCheckRes FePreCheckStruct - tmpSshHost = module.GYamlConf.FeServers[i].Host - tmpSshPort = module.GYamlConf.FeServers[i].SshPort + bePreCheckRes = make([]BePreCheckStruct, len(module.GYamlConf.BeServers)) + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + for i := 0; i < len(module.GYamlConf.BeServers); i++ { - // check ssh auth - tmpCheckRes.SshAuthRes, tmpCheckRes.SshAuthInfo = sshAuth(tmpSshHost, tmpSshPort) + var tmpCheckRes BePreCheckStruct + tmpSshHost = module.GYamlConf.BeServers[i].Host + tmpSshPort = module.GYamlConf.BeServers[i].SshPort - // check sudo privilege - // tmpCheckRes.UserSudo = sudoPriv(tmpSshHost, tmpSshPort, tmpUser) + // check ssh auth + tmpCheckRes.SshAuthRes, tmpCheckRes.SshAuthInfo = sshAuth(tmpSshHost, tmpSshPort) - // check FE deploy folder - tmpDetectDir = module.GYamlConf.FeServers[i].DeployDir - tmpCheckRes.DeployDirRes, tmpCheckRes.DeployDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "FE deploy folder") - //tmpCheckRes.DeployDir = dirPriv(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "FE deploy folder") + // Check BE deploy user exist + // tmpCheckRes.UserSudo = sudoPriv(tmpSshHost, tmpSshPort, tmpUser) + // check BE deploy folder + tmpDetectDir = module.GYamlConf.BeServers[i].DeployDir + tmpCheckRes.DeployDirRes, tmpCheckRes.DeployDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "BE deploy folder") - // check meta folder - tmpDetectDir = module.GYamlConf.FeServers[i].MetaDir - tmpCheckRes.MetaDirRes, tmpCheckRes.MetaDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "FE meta folder") - //tmpCheckRes.MetaDir = dirPriv(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "FE meta folder") + // check BE storage folder + tmpDetectDir = module.GYamlConf.BeServers[i].StorageDir + tmpCheckRes.storageDirRes, tmpCheckRes.storageDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "BE storage folder") - // check FE HttpPort - tmpDetectPort = module.GYamlConf.FeServers[i].HttpPort - tmpCheckRes.HttpPortRes, tmpCheckRes.HttpPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "FE Http Port") + // check BePort + tmpDetectPort = module.GYamlConf.BeServers[i].BePort + tmpCheckRes.BePortRes, tmpCheckRes.BePortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "BE Port") - // check FE RpcPort - tmpDetectPort = module.GYamlConf.FeServers[i].RpcPort - tmpCheckRes.RpcPortRes, tmpCheckRes.RpcPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "FE RPC Port") + // check BE WebServerPort + tmpDetectPort = module.GYamlConf.BeServers[i].WebServerPort + tmpCheckRes.WebServerPortRes, tmpCheckRes.WebServerPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "BE Web Server Port") - // check FE EditLogPort - tmpDetectPort = module.GYamlConf.FeServers[i].EditLogPort - tmpCheckRes.EditLogPortRes, tmpCheckRes.EditLogPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "FE Edit Log Port") + // check HeartbeatServicePort + tmpDetectPort = module.GYamlConf.BeServers[i].HeartbeatServicePort + tmpCheckRes.HeartbeatServicePortRes, tmpCheckRes.HeartbeatServicePortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "BE Heartbeat Service Port") - // check FE QueryPort - tmpDetectPort = module.GYamlConf.FeServers[i].QueryPort - tmpCheckRes.QueryPortRes, tmpCheckRes.QueryPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "FE Query Port") + // check BE brpc port + tmpDetectPort = module.GYamlConf.BeServers[i].BrpcPort + tmpCheckRes.BrpcPortRes, tmpCheckRes.BrpcPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "BE brpc Port") - // check FE open files count - tmpCheckRes.OpenFilesRes, tmpCheckRes.OpenFilesInfo = openFile(tmpSshHost, tmpSshPort) + // check BE open files count + tmpCheckRes.OpenFilesRes, tmpCheckRes.OpenFilesInfo = openFile(tmpSshHost, tmpSshPort) + bePreCheckRes[i] = tmpCheckRes - fePreCheckRes[i] = tmpCheckRes - } - - return fePreCheckRes + } + return bePreCheckRes } +func preCheckCn() (cnPreCheckRes []CnPreCheckStruct) { -func preCheckBe() (bePreCheckRes []BePreCheckStruct) { - - var tmpSshHost string - var tmpSshPort int - var tmpDetectDir string - var tmpDetectPort int - var tmpUser string - var tmpKeyRsa string - - bePreCheckRes = make([]BePreCheckStruct, len(module.GYamlConf.BeServers)) - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa + var tmpSshHost string + var tmpSshPort int + var tmpDetectDir string + var tmpDetectPort int + var tmpUser string + var tmpKeyRsa string + cnPreCheckRes = make([]CnPreCheckStruct, len(module.GYamlConf.CnServers)) + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + for i := 0; i < len(module.GYamlConf.CnServers); i++ { - for i := 0; i < len(module.GYamlConf.BeServers); i++ { + var tmpCheckRes CnPreCheckStruct + tmpSshHost = module.GYamlConf.CnServers[i].Host + tmpSshPort = module.GYamlConf.CnServers[i].SshPort - var tmpCheckRes BePreCheckStruct - tmpSshHost = module.GYamlConf.BeServers[i].Host - tmpSshPort = module.GYamlConf.BeServers[i].SshPort - - // check ssh auth - tmpCheckRes.SshAuthRes, tmpCheckRes.SshAuthInfo = sshAuth(tmpSshHost, tmpSshPort) + tmpCheckRes.SshAuthRes, tmpCheckRes.SshAuthInfo = sshAuth(tmpSshHost, tmpSshPort) - // Check BE deploy user exist - // tmpCheckRes.UserSudo = sudoPriv(tmpSshHost, tmpSshPort, tmpUser) + tmpDetectDir = module.GYamlConf.CnServers[i].DeployDir + tmpCheckRes.DeployDirRes, tmpCheckRes.DeployDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "CN deploy folder") - // check BE deploy folder - tmpDetectDir = module.GYamlConf.BeServers[i].DeployDir - tmpCheckRes.DeployDirRes, tmpCheckRes.DeployDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "BE deploy folder") + tmpDetectDir = module.GYamlConf.CnServers[i].StorageDir + tmpCheckRes.storageDirRes, tmpCheckRes.storageDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "CN storage folder") - // check BE storage folder - tmpDetectDir = module.GYamlConf.BeServers[i].StorageDir - tmpCheckRes.storageDirRes, tmpCheckRes.storageDirInfo = dirExist(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectDir, "BE storage folder") + tmpDetectPort = module.GYamlConf.CnServers[i].BePort + tmpCheckRes.BePortRes, tmpCheckRes.BePortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "CN Port") - // check BePort - tmpDetectPort = module.GYamlConf.BeServers[i].BePort - tmpCheckRes.BePortRes, tmpCheckRes.BePortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "BE Port") + tmpDetectPort = module.GYamlConf.CnServers[i].WebServerPort + tmpCheckRes.WebServerPortRes, tmpCheckRes.WebServerPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "CN Web Server Port") - // check BE WebServerPort - tmpDetectPort = module.GYamlConf.BeServers[i].WebServerPort - tmpCheckRes.WebServerPortRes, tmpCheckRes.WebServerPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "BE Web Server Port") + tmpDetectPort = module.GYamlConf.CnServers[i].HeartbeatServicePort + tmpCheckRes.HeartbeatServicePortRes, tmpCheckRes.HeartbeatServicePortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "CN Heartbeat Service Port") - // check HeartbeatServicePort - tmpDetectPort = module.GYamlConf.BeServers[i].HeartbeatServicePort - tmpCheckRes.HeartbeatServicePortRes, tmpCheckRes.HeartbeatServicePortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "BE Heartbeat Service Port") + tmpDetectPort = module.GYamlConf.CnServers[i].BrpcPort + tmpCheckRes.BrpcPortRes, tmpCheckRes.BrpcPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "CN brpc Port") - // check BE brpc port - tmpDetectPort = module.GYamlConf.BeServers[i].BrpcPort - tmpCheckRes.BrpcPortRes, tmpCheckRes.BrpcPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "BE brpc Port") + tmpDetectPort = module.GYamlConf.CnServers[i].StarletPort + tmpCheckRes.StarletPortRes, tmpCheckRes.StarletPortInfo = portUsed(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpDetectPort, "CN starlet Port") - // check BE open files count - tmpCheckRes.OpenFilesRes, tmpCheckRes.OpenFilesInfo = openFile(tmpSshHost, tmpSshPort) - bePreCheckRes[i] = tmpCheckRes - - } + tmpCheckRes.OpenFilesRes, tmpCheckRes.OpenFilesInfo = openFile(tmpSshHost, tmpSshPort) + cnPreCheckRes[i] = tmpCheckRes + } - return bePreCheckRes + return cnPreCheckRes } - func dirPriv(user string, keyRsa string, sshHost string, sshPort int, dirName string, logStr string) (res string) { - var infoMess string - var cmd string - var dirBase string - - dirBase = path.Dir(dirName) - // dirBase = dirName - cmd = fmt.Sprintf("ls -al %s | grep 'd.* .$'", dirBase) - output, _ := utl.SshRun(user, keyRsa, sshHost, sshPort, cmd) - reg := regexp.MustCompile("\\s+") - dirStatArr := reg.Split(string(output), -1) - - if strings.Contains(dirStatArr[0], "drwx") && dirStatArr[2] == user { - infoMess = fmt.Sprintf("Detect the %-20s don't have create folder privileges [Host = %-20s, Dir = %-30s]\n", logStr, sshHost, dirName) - utl.Log("DEBUG", infoMess) - return CHECKPASS - } else { - if dirBase != "/" { - res = dirPriv(user, keyRsa, sshHost, sshPort, dirBase, logStr) - if res == CHECKPASS { - return CHECKPASS - } + var infoMess string + var cmd string + var dirBase string + + dirBase = path.Dir(dirName) + // dirBase = dirName + cmd = fmt.Sprintf("ls -al %s | grep 'd.* .$'", dirBase) + output, _ := utl.SshRun(user, keyRsa, sshHost, sshPort, cmd) + reg := regexp.MustCompile("\\s+") + dirStatArr := reg.Split(string(output), -1) + + if strings.Contains(dirStatArr[0], "drwx") && dirStatArr[2] == user { + infoMess = fmt.Sprintf("Detect the %-20s don't have create folder privileges [Host = %-20s, Dir = %-30s]\n", logStr, sshHost, dirName) + utl.Log("DEBUG", infoMess) + return CHECKPASS } else { - return "Priv failed" + if dirBase != "/" { + res = dirPriv(user, keyRsa, sshHost, sshPort, dirBase, logStr) + if res == CHECKPASS { + return CHECKPASS + } + } else { + return "Priv failed" + } } - } - return "Priv failed" + return "Priv failed" } - - func dirExist(user string, keyRsa string, sshHost string, sshPort int, dirName string, logStr string) (string, string) { - var infoMess string - var cmd string - var res string = CHECKPASS - var resExist string = CHECKPASS - var resPrivs string = CHECKPASS - var checkMess string - - - // check dir exist - cmd = "ls -l " + dirName - // SshRun(user string, keyFile string, host string, port int, command string) (outPut []byte, err error) - output, _ := utl.SshRun(user, keyRsa, sshHost, sshPort, cmd) - if strings.Contains(string(output), "total") { - infoMess = fmt.Sprintf("Detect the %-20s exist [Host = %-20s, Dir = %-30s]\n", logStr, sshHost, dirName) - utl.Log("DEBUG", infoMess) - //return CHECKFAILED - resExist = "Dir exist" - } - // check dir privs - resPrivs = dirPriv(user, keyRsa, sshHost, sshPort, dirName, logStr) - - if resPrivs == CHECKPASS && resExist == CHECKPASS { - res = CHECKPASS - } else if resPrivs == CHECKPASS && resExist != CHECKPASS { - // priv ok, dir exist. - res = fmt.Sprintf("%s: %s", CHECKFAILED, resExist) - checkMess = fmt.Sprintf(" [Host = %s] mkdir %s.bak && mv %s/* %s.bak/", sshHost, dirName, dirName, dirName) - } else if resPrivs != CHECKPASS && resExist == CHECKPASS { - // dir ok, no priv - res = fmt.Sprintf("%s: %s", CHECKFAILED, resPrivs) - checkMess = fmt.Sprintf(" [Host = %s] chown -R %s %s", sshHost, user, dirName) - } else if resPrivs != CHECKPASS && resExist != CHECKPASS { - res = fmt.Sprintf("%s: %s/%s", CHECKFAILED, resExist, resPrivs) - // dir exist, no priv - checkMess = fmt.Sprintf(" [Host = %s] mkdir %s.bak && mv %s/* %s.bak/ && chown -R %s %s", sshHost, dirName, dirName, dirName, user, dirName) - - } + var infoMess string + var cmd string + var res string = CHECKPASS + var resExist string = CHECKPASS + var resPrivs string = CHECKPASS + var checkMess string + + // check dir exist + cmd = "ls -l " + dirName + // SshRun(user string, keyFile string, host string, port int, command string) (outPut []byte, err error) + output, _ := utl.SshRun(user, keyRsa, sshHost, sshPort, cmd) + if strings.Contains(string(output), "total") { + infoMess = fmt.Sprintf("Detect the %-20s exist [Host = %-20s, Dir = %-30s]\n", logStr, sshHost, dirName) + utl.Log("DEBUG", infoMess) + //return CHECKFAILED + resExist = "Dir exist" + } + // check dir privs + resPrivs = dirPriv(user, keyRsa, sshHost, sshPort, dirName, logStr) + + if resPrivs == CHECKPASS && resExist == CHECKPASS { + res = CHECKPASS + } else if resPrivs == CHECKPASS && resExist != CHECKPASS { + // priv ok, dir exist. + res = fmt.Sprintf("%s: %s", CHECKFAILED, resExist) + checkMess = fmt.Sprintf(" [Host = %s] mkdir %s.bak && mv %s/* %s.bak/", sshHost, dirName, dirName, dirName) + } else if resPrivs != CHECKPASS && resExist == CHECKPASS { + // dir ok, no priv + res = fmt.Sprintf("%s: %s", CHECKFAILED, resPrivs) + checkMess = fmt.Sprintf(" [Host = %s] chown -R %s %s", sshHost, user, dirName) + } else if resPrivs != CHECKPASS && resExist != CHECKPASS { + res = fmt.Sprintf("%s: %s/%s", CHECKFAILED, resExist, resPrivs) + // dir exist, no priv + checkMess = fmt.Sprintf(" [Host = %s] mkdir %s.bak && mv %s/* %s.bak/ && chown -R %s %s", sshHost, dirName, dirName, dirName, user, dirName) + } - return res, checkMess - //return CHECKPASS + return res, checkMess + //return CHECKPASS } +func portUsed(user string, keyRsa string, sshHost string, sshPort int, detectPort int, logStr string) (string, string) { + var infoMess string + var checkMess string -func portUsed(user string, keyRsa string, sshHost string, sshPort int, detectPort int, logStr string) (string, string){ - - var infoMess string - var checkMess string + cmd := fmt.Sprintf("netstat -an | grep ':%d ' | grep -v ESTABLISHED", detectPort) - cmd := fmt.Sprintf("netstat -an | grep ':%d ' | grep -v ESTABLISHED", detectPort) + // SshRun(user string, keyFile string, host string, port int, command string) (outPut []byte, err error) - // SshRun(user string, keyFile string, host string, port int, command string) (outPut []byte, err error) - - output, _ := utl.SshRun(user, keyRsa, sshHost, sshPort, cmd) - if strings.Contains(string(output), ":" + strconv.Itoa(detectPort)) { - infoMess = fmt.Sprintf("Detect the %s used [Host = %s, Port = %d]\n", logStr, sshHost, detectPort) - utl.Log("DEBUG", infoMess) - checkMess = fmt.Sprintf(" [Host = %s] netstat -nltp ':%d '", sshHost, detectPort) - return CHECKFAILED, checkMess - } + output, _ := utl.SshRun(user, keyRsa, sshHost, sshPort, cmd) + if strings.Contains(string(output), ":"+strconv.Itoa(detectPort)) { + infoMess = fmt.Sprintf("Detect the %s used [Host = %s, Port = %d]\n", logStr, sshHost, detectPort) + utl.Log("DEBUG", infoMess) + checkMess = fmt.Sprintf(" [Host = %s] netstat -nltp ':%d '", sshHost, detectPort) + return CHECKFAILED, checkMess + } - return CHECKPASS, checkMess + return CHECKPASS, checkMess } @@ -565,75 +764,72 @@ func sudoPriv(sshHost string, sshPort int, userName string) string { } */ - func sshAuth(sshHost string, sshPort int) (string, string) { - // check ssh auth - var infoMess string - var checkMess string - keyRsa := module.GSshKeyRsa - sshUser := module.GYamlConf.Global.User - - output, _ := utl.SshRun(sshUser, keyRsa, sshHost, sshPort, "date") + // check ssh auth + var infoMess string + var checkMess string + keyRsa := module.GSshKeyRsa + sshUser := module.GYamlConf.Global.User + + output, _ := utl.SshRun(sshUser, keyRsa, sshHost, sshPort, "date") + + if strings.Contains(string(output), "202") { + // detect the result has the year 202X, return PASS + infoMess = fmt.Sprintf("SSH auth check successfully, [host = %s]", sshHost) + utl.Log("DEBUG", infoMess) + return CHECKPASS, checkMess + } - if strings.Contains(string(output), "202") { - // detect the result has the year 202X, return PASS - infoMess = fmt.Sprintf("SSH auth check successfully, [host = %s]", sshHost) + infoMess = fmt.Sprintf("SSH auth check failed, [host = %s]", sshHost) utl.Log("DEBUG", infoMess) - return CHECKPASS, checkMess - } - - infoMess = fmt.Sprintf("SSH auth check failed, [host = %s]", sshHost) - utl.Log("DEBUG", infoMess) - checkMess = fmt.Sprintf(" [Host = 127.0.01] ssh-copy-id %s@%s", sshHost, sshUser) + checkMess = fmt.Sprintf(" [Host = 127.0.01] ssh-copy-id %s@%s", sshHost, sshUser) - return CHECKFAILED, checkMess + return CHECKFAILED, checkMess } - func openFile(sshHost string, sshPort int) (string, string) { - var infoMess string - var checkMess string + var infoMess string + var checkMess string - keyRsa := module.GSshKeyRsa - sshUser := module.GYamlConf.Global.User + keyRsa := module.GSshKeyRsa + sshUser := module.GYamlConf.Global.User - output, err := utl.SshRun(sshUser, keyRsa, sshHost, sshPort, "ulimit -n") - if err != nil { - infoMess = fmt.Sprintf("Error in get open file limit. [Host = %s]", sshHost) - utl.Log("ERROR", infoMess) - } - openFiles, err := strconv.Atoi(strings.Replace(string(output), "\n", "", -1)) + output, err := utl.SshRun(sshUser, keyRsa, sshHost, sshPort, "bash -lc 'ulimit -n'") + if err != nil { + infoMess = fmt.Sprintf("Error in get open file limit. [Host = %s]", sshHost) + utl.Log("ERROR", infoMess) + } + openFiles, err := strconv.Atoi(strings.Replace(string(output), "\n", "", -1)) - if err != nil { - infoMess = fmt.Sprintf("Error in convert the open files count. [host = %s, openFiles = %s, error = %v]", strings.Replace(string(output), "\n", "", -1), err) - utl.Log("DEBUG", infoMess) - checkMess = fmt.Sprintf(" [Host = %s, User = %s] Cannot get the open files count. Please use command 'ulimit -n' on user %s to check the copnfiguration.", sshHost, sshUser, sshUser) - return CHECKFAILED, checkMess - } + if err != nil { + infoMess = fmt.Sprintf("Error in convert the open files count. [host = %s, openFiles = %s, error = %v]", sshHost, strings.Replace(string(output), "\n", "", -1), err) + utl.Log("DEBUG", infoMess) + checkMess = fmt.Sprintf(" [Host = %s, User = %s] Cannot get the open files count. Please use command 'ulimit -n' on user %s to check the copnfiguration.", sshHost, sshUser, sshUser) + return CHECKFAILED, checkMess + } - if openFiles >= 65535 { - return CHECKPASS, checkMess - } + if openFiles >= 65535 { + return CHECKPASS, checkMess + } - infoMess = fmt.Sprintf("Open files count check failed. Make it more than 65535. [host = %s, openFiles = %d]", sshHost, openFiles) - utl.Log("DEBUG", infoMess) - checkMess = fmt.Sprintf(" [Host = %s, User = %s] Please add bellowing line in /etc/security/limits.conf\n%s soft nofile 65535\n%s hard nofile 65535", sshHost, sshUser, sshUser, sshUser) - return CHECKFAILED, checkMess + infoMess = fmt.Sprintf("Open files count check failed. Make it more than 65535. [host = %s, openFiles = %d]", sshHost, openFiles) + utl.Log("DEBUG", infoMess) + checkMess = fmt.Sprintf(" [Host = %s, User = %s] Please add bellowing line in /etc/security/limits.conf\n%s soft nofile 65535\n%s hard nofile 65535", sshHost, sshUser, sshUser, sshUser) + return CHECKFAILED, checkMess } - func TestPreCheck() { - module.InitConf("sr-c1", "sr-c1.yaml") - module.SetGlobalVar("GSRVersion", "v2.2.0") + module.InitConf("sr-c1", "sr-c1.yaml") + module.SetGlobalVar("GSRVersion", "v2.2.0") - PreCheckSR() - //aaa := preCheckFe() - //fmt.Println(aaa) - //bbb := preCheckBe() - //fmt.Println(bbb) + PreCheckSR() + //aaa := preCheckFe() + //fmt.Println(aaa) + //bbb := preCheckBe() + //fmt.Println(bbb) } diff --git a/cluster/scaleOut.bak/.scaleFe.go.swp b/cluster/scaleOut.bak/.scaleFe.go.swp deleted file mode 100644 index e02ffdd..0000000 Binary files a/cluster/scaleOut.bak/.scaleFe.go.swp and /dev/null differ diff --git a/cluster/scaleOut.bak/scaleOutFe.go b/cluster/scaleOut.bak/scaleOutFe.go index 2b56b4f..fa1ecf4 100644 --- a/cluster/scaleOut.bak/scaleOutFe.go +++ b/cluster/scaleOut.bak/scaleOutFe.go @@ -1,82 +1,82 @@ +//go:build ignore +// +build ignore + package scaleOutCluster import ( - "fmt" - "time" - "stargo/sr-utl" - "stargo/module" - "stargo/cluster/startCluster" - "stargo/cluster/checkStatus" + "fmt" + "stargo/cluster/checkStatus" + "stargo/cluster/startCluster" + "stargo/module" + "stargo/sr-utl" + "time" ) - - func ScaleOutFeCluster() { - var infoMess string - var err error - var feStat checkStatus.FeStatusStruct - - // start Fe node one by one - var tmpUser string - var tmpKeyRsa string - var tmpSshHost string - var tmpSshPort int - var tmpEditLogPort int - var tmpQueryPort int - var tmpFeDeployDir string - var feStatusList string - - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - // GYamlConfAppend is for scale-out.yaml (node6) - // GYamlConf is for sr-c1/meta.yaml (node3,4,5) - - - for i := 0; i < len(module.GYamlConfAppend.FeServers); i++ { - - tmpSshHost = module.GYamlConfAppend.FeServers[i].Host - tmpSshPort = module.GYamlConfAppend.FeServers[i].SshPort - tmpEditLogPort = module.GYamlConfAppend.FeServers[i].EditLogPort - tmpQueryPort = module.GYamlConfAppend.FeServers[i].QueryPort - tmpFeDeployDir = module.GYamlConfAppend.FeServers[i].DeployDir - - //infoMess = fmt.Sprintf("Starting FE node [FeHost = %s, FeEditLogPort = %d]", tmpSshHost, tmpEditLogPort) - //utl.Log("INFO", infoMess) - - for startTimeInd := 0; startTimeInd < 3; startTimeInd++ { - // initFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) - infoMess = fmt.Sprintf("The %d time to start [%s]", (startTimeInd + 1), tmpSshHost) - utl.Log("DEBUG", infoMess) - err = startCluster.InitFeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpEditLogPort, tmpFeDeployDir) - startWaitTime := time.Duration(20 - startTimeInd * 5) - time.Sleep(startWaitTime * time.Second) - - feStat, err = checkStatus.CheckFeStatus(i) - - if err != nil { - infoMess = fmt.Sprintf("Error in get the fe status [FeHost = %s, error = %v]", tmpSshHost, err) - utl.Log("DEBUG", infoMess) - } - if feStat.FeAlive { - infoMess = fmt.Sprintf("The FE node start succefully [host = %s, queryPort = %d]", tmpSshHost, tmpQueryPort) - utl.Log("INFO", infoMess) - break - } else { - infoMess = fmt.Sprintf("The FE node doesn't start, wait for 10s [FeHost = %s, FeQueryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) - utl.Log("WARN", infoMess) - } - } // FOR-END: 3 time to restart FE node - - if !feStat.FeAlive { - infoMess = fmt.Sprintf("The FE node start failed [host = %s, queryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) - utl.Log("ERROR", infoMess) - } - feStatusList = feStatusList + " " + fmt.Sprintf("feHost = %-20sfeQueryPort = %d feStatus = true\n", tmpSshHost, tmpQueryPort) - } // FOR-END: list all FE node - - feStatusList = "List all FE status:\n" + feStatusList - utl.Log("INFO", feStatusList) + var infoMess string + var err error + var feStat checkStatus.FeStatusStruct + + // start Fe node one by one + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpEditLogPort int + var tmpQueryPort int + var tmpFeDeployDir string + var feStatusList string + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + // GYamlConfAppend is for scale-out.yaml (node6) + // GYamlConf is for sr-c1/meta.yaml (node3,4,5) + + for i := 0; i < len(module.GYamlConfAppend.FeServers); i++ { + + tmpSshHost = module.GYamlConfAppend.FeServers[i].Host + tmpSshPort = module.GYamlConfAppend.FeServers[i].SshPort + tmpEditLogPort = module.GYamlConfAppend.FeServers[i].EditLogPort + tmpQueryPort = module.GYamlConfAppend.FeServers[i].QueryPort + tmpFeDeployDir = module.GYamlConfAppend.FeServers[i].DeployDir + + //infoMess = fmt.Sprintf("Starting FE node [FeHost = %s, FeEditLogPort = %d]", tmpSshHost, tmpEditLogPort) + //utl.Log("INFO", infoMess) + + for startTimeInd := 0; startTimeInd < 3; startTimeInd++ { + // initFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) + infoMess = fmt.Sprintf("The %d time to start [%s]", (startTimeInd + 1), tmpSshHost) + utl.Log("DEBUG", infoMess) + err = startCluster.InitFeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpEditLogPort, tmpFeDeployDir) + startWaitTime := time.Duration(20 - startTimeInd*5) + time.Sleep(startWaitTime * time.Second) + + feStat, err = checkStatus.CheckFeStatus(i) + + if err != nil { + infoMess = fmt.Sprintf("Error in get the fe status [FeHost = %s, error = %v]", tmpSshHost, err) + utl.Log("DEBUG", infoMess) + } + if feStat.FeAlive { + infoMess = fmt.Sprintf("The FE node start succefully [host = %s, queryPort = %d]", tmpSshHost, tmpQueryPort) + utl.Log("INFO", infoMess) + break + } else { + infoMess = fmt.Sprintf("The FE node doesn't start, wait for 10s [FeHost = %s, FeQueryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) + utl.Log("WARN", infoMess) + } + } // FOR-END: 3 time to restart FE node + + if !feStat.FeAlive { + infoMess = fmt.Sprintf("The FE node start failed [host = %s, queryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) + utl.Log("ERROR", infoMess) + } + feStatusList = feStatusList + " " + fmt.Sprintf("feHost = %-20sfeQueryPort = %d feStatus = true\n", tmpSshHost, tmpQueryPort) + } // FOR-END: list all FE node + + feStatusList = "List all FE status:\n" + feStatusList + utl.Log("INFO", feStatusList) } diff --git a/cluster/startCluster/.startFe.go.swp b/cluster/startCluster/.startFe.go.swp deleted file mode 100644 index d87c0c5..0000000 Binary files a/cluster/startCluster/.startFe.go.swp and /dev/null differ diff --git a/cluster/startCluster/initBe.go b/cluster/startCluster/initBe.go index 14dff08..5de219f 100644 --- a/cluster/startCluster/initBe.go +++ b/cluster/startCluster/initBe.go @@ -1,114 +1,107 @@ - package startCluster -import( - "fmt" - "time" - "errors" - "stargo/sr-utl" - "stargo/module" - "stargo/cluster/checkStatus" +import ( + "errors" + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" + "time" ) - - - func InitBeCluster(yamlConf *module.ConfStruct) { - var infoMess string - var err error - var beStat map[string]string - - // start Fe node one by one - var tmpUser string - var tmpKeyRsa string - var tmpSshHost string - var tmpSshPort int - var tmpHeartbeatServicePort int - var tmpBeDeployDir string - var beStatusList string - // var tmpFeEntryHost string - // var tmpFeEntryPort int - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - // get FE entry - feEntryId, err := checkStatus.GetFeEntry(-1) - //tmpFeEntryHost = yamlConf.FeServers[feEntryId].Host - //tmpFeEntryPort = yamlConf.FeServers[feEntryId].QueryPort - module.SetFeEntry(feEntryId) - if err != nil || feEntryId == -1 { - infoMess = "Error in get the FE entry, pls check FE status." - utl.Log("ERROR", infoMess) - err = errors.New(infoMess) - panic(err) - } - - - - for i := 0; i < len(yamlConf.BeServers); i++ { - - tmpSshHost = yamlConf.BeServers[i].Host - tmpSshPort = yamlConf.BeServers[i].SshPort - tmpHeartbeatServicePort = yamlConf.BeServers[i].HeartbeatServicePort - tmpBeDeployDir = yamlConf.BeServers[i].DeployDir - - infoMess = fmt.Sprintf("Starting BE node [BeHost = %s HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) - utl.Log("INFO", infoMess) - - for startTimeInd := 0; startTimeInd < 3; startTimeInd++ { - - infoMess = fmt.Sprintf("The %d time to start [%s]",(startTimeInd + 1), tmpSshHost) - utl.Log("DEBUG", infoMess) - // startBeNode(user string, keyRsa string, sshHost string, sshPort int, heartbeatServicePort int, beDeployDir string) (err error) - err = initBeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpHeartbeatServicePort, tmpBeDeployDir) - - startWaitTime := time.Duration(20 - startTimeInd * 5) - // the be process need 20s to startup - time.Sleep(startWaitTime * time.Second) - - beStat, _ = checkStatus.CheckBeStatus(i) - if beStat["Alive"] == "true" { - infoMess = fmt.Sprintf("The BE node start succefully [host = %s, heartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) - utl.Log("INFO", infoMess) - break - } else { - infoMess = fmt.Sprintf("The BE node doesn't start, wait for 10s [BeHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) - utl.Log("WARN", infoMess) - } - } // FOR-END: 3 time to restart BE node - - if beStat["Alive"] == "false" { - infoMess = fmt.Sprintf("The BE node start failed [BeHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) - } - - beStatusList = beStatusList + " " + fmt.Sprintf("beHost = %-20sbeHeartbeatServicePort = %d\tbeStatus = %v\n", tmpSshHost, tmpHeartbeatServicePort, beStat["Alive"]) - } - beStatusList = "List all BE status:\n" + beStatusList - utl.Log("OUTPUT", beStatusList) + var infoMess string + var err error + var beStat map[string]string + + // start Fe node one by one + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpHeartbeatServicePort int + var tmpBeDeployDir string + var beStatusList string + // var tmpFeEntryHost string + // var tmpFeEntryPort int + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + // get FE entry + feEntryId, err := checkStatus.GetFeEntry(-1) + //tmpFeEntryHost = yamlConf.FeServers[feEntryId].Host + //tmpFeEntryPort = yamlConf.FeServers[feEntryId].QueryPort + module.SetFeEntry(feEntryId) + if err != nil || feEntryId == -1 { + infoMess = "Error in get the FE entry, pls check FE status." + utl.Log("ERROR", infoMess) + err = errors.New(infoMess) + panic(err) + } + + for i := 0; i < len(yamlConf.BeServers); i++ { + + tmpSshHost = yamlConf.BeServers[i].Host + tmpSshPort = yamlConf.BeServers[i].SshPort + tmpHeartbeatServicePort = yamlConf.BeServers[i].HeartbeatServicePort + tmpBeDeployDir = yamlConf.BeServers[i].DeployDir + + infoMess = fmt.Sprintf("Starting BE node [BeHost = %s HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + + for startTimeInd := 0; startTimeInd < 3; startTimeInd++ { + + infoMess = fmt.Sprintf("The %d time to start [%s]", (startTimeInd + 1), tmpSshHost) + utl.Log("DEBUG", infoMess) + // startBeNode(user string, keyRsa string, sshHost string, sshPort int, heartbeatServicePort int, beDeployDir string) (err error) + err = initBeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpHeartbeatServicePort, tmpBeDeployDir) + + startWaitTime := time.Duration(20 - startTimeInd*5) + // the be process need 20s to startup + time.Sleep(startWaitTime * time.Second) + + beStat, _ = checkStatus.CheckBeStatus(i) + if beStat["Alive"] == "true" { + infoMess = fmt.Sprintf("The BE node start successfully [host = %s, heartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + break + } else { + infoMess = fmt.Sprintf("The BE node doesn't start, wait for 10s [BeHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) + utl.Log("WARN", infoMess) + } + } // FOR-END: 3 time to restart BE node + + if beStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The BE node start failed [BeHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) + } + + beStatusList = beStatusList + " " + fmt.Sprintf("beHost = %-20sbeHeartbeatServicePort = %d\tbeStatus = %v\n", tmpSshHost, tmpHeartbeatServicePort, beStat["Alive"]) + } + beStatusList = "List all BE status:\n" + beStatusList + utl.Log("OUTPUT", beStatusList) } func initBeNode(user string, keyRsa string, sshHost string, sshPort int, heartbeatServicePort int, beDeployDir string) (err error) { - var infoMess string - + var infoMess string - addBeSQL := fmt.Sprintf("alter system add backend \"%s:%d\"", sshHost, heartbeatServicePort) - addBeCMD := fmt.Sprintf("%s/bin/start_be.sh --daemon", beDeployDir) + addBeSQL := fmt.Sprintf("alter system add backend \"%s:%d\"", sshHost, heartbeatServicePort) + addBeCMD := fmt.Sprintf("%s/bin/start_be.sh --daemon", beDeployDir) - //infoMess = fmt.Sprintf("Starting BE node [host = %s, heartbeatServicePort = %d]", sshHost, heartbeatServicePort) - //utl.Log("INFO", infoMess) + //infoMess = fmt.Sprintf("Starting BE node [host = %s, heartbeatServicePort = %d]", sshHost, heartbeatServicePort) + //utl.Log("INFO", infoMess) - // alter system add backend "sshHost:heartbeatServicePort" - sqlUserName := "root" - sqlPassword := "" - sqlIp := module.GFeEntryHost - sqlPort := module.GFeEntryQueryPort - sqlDbName := "" + // alter system add backend "sshHost:heartbeatServicePort" + sqlUserName := "root" + sqlPassword := "" + sqlIp := module.GFeEntryHost + sqlPort := module.GFeEntryQueryPort + sqlDbName := "" - _, err = utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, addBeSQL) - if err != nil { - infoMess = fmt.Sprintf(`Error in add follower BE node, [ + _, err = utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, addBeSQL) + if err != nil { + infoMess = fmt.Sprintf(`Error in add follower BE node, [ sqlUserName = %s sqlPassword = %s sqlIP = %s @@ -116,25 +109,25 @@ func initBeNode(user string, keyRsa string, sshHost string, sshPort int, heartbe sqlDBName = %s addFollowerSQL =%s errMess = %v]`, sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, addBeSQL, err) - utl.Log("ERROR", infoMess) - return err - } - - // run beDeploy/bin/start_be.sh --daemon - _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, addBeCMD) - if err != nil { - infoMess = fmt.Sprintf(`Waiting for startMastertFeNode: + utl.Log("ERROR", infoMess) + return err + } + + // run beDeploy/bin/start_be.sh --daemon + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, addBeCMD) + if err != nil { + infoMess = fmt.Sprintf(`Waiting for startMastertFeNode: user = %s keyRsa = %s sshHost = %s sshPort = %d beDeployDir = %s`, - user, keyRsa, sshHost, sshPort, beDeployDir) - utl.Log("WARN", infoMess) - return err - } + user, keyRsa, sshHost, sshPort, beDeployDir) + utl.Log("WARN", infoMess) + return err + } - // time.Sleep(5 * time.Second) - return nil + // time.Sleep(5 * time.Second) + return nil } diff --git a/cluster/startCluster/initCn.go b/cluster/startCluster/initCn.go new file mode 100644 index 0000000..282df28 --- /dev/null +++ b/cluster/startCluster/initCn.go @@ -0,0 +1,131 @@ +package startCluster + +import ( + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + utl "stargo/sr-utl" + "strings" + "time" +) + +func InitCnCluster(yamlConf *module.ConfStruct) { + + var infoMess string + var err error + var cnStat map[string]string + + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpHeartbeatServicePort int + var tmpCnDeployDir string + var cnStatusList string + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + feEntryId, err := checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + infoMess = "Error in get the FE entry, pls check FE status." + utl.Log("ERROR", infoMess) + panic(err) + } + module.SetFeEntry(feEntryId) + + for i := 0; i < len(yamlConf.CnServers); i++ { + + tmpSshHost = yamlConf.CnServers[i].Host + tmpSshPort = yamlConf.CnServers[i].SshPort + tmpHeartbeatServicePort = yamlConf.CnServers[i].HeartbeatServicePort + tmpCnDeployDir = yamlConf.CnServers[i].DeployDir + + infoMess = fmt.Sprintf("Starting CN node [CnHost = %s HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + + for startTimeInd := 0; startTimeInd < 3; startTimeInd++ { + infoMess = fmt.Sprintf("The %d time to start [%s]", startTimeInd+1, tmpSshHost) + utl.Log("DEBUG", infoMess) + err = initCnNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpHeartbeatServicePort, tmpCnDeployDir) + + startWaitTime := time.Duration(20 - startTimeInd*5) + time.Sleep(startWaitTime * time.Second) + + cnStat, _ = checkStatus.CheckCnStatus(i) + if cnStat["Alive"] == "true" { + infoMess = fmt.Sprintf("The CN node start successfully [host = %s, heartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + break + } + + infoMess = fmt.Sprintf("The CN node doesn't start, wait for 10s [CnHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) + utl.Log("WARN", infoMess) + } + + if cnStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The CN node start failed [CnHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) + utl.Log("ERROR", infoMess) + } + + cnStatusList = cnStatusList + " " + fmt.Sprintf("cnHost = %-20scnHeartbeatServicePort = %d\tcnStatus = %v\n", tmpSshHost, tmpHeartbeatServicePort, cnStat["Alive"]) + } + + cnStatusList = "List all CN status:\n" + cnStatusList + utl.Log("OUTPUT", cnStatusList) +} + +func initCnNode(user string, keyRsa string, sshHost string, sshPort int, heartbeatServicePort int, cnDeployDir string) (err error) { + + var infoMess string + + startCnCMD := fmt.Sprintf("%s/bin/start_cn.sh --daemon", cnDeployDir) + addCnSQL := fmt.Sprintf("alter system add compute node \"%s:%d\"", sshHost, heartbeatServicePort) + + sqlUserName := "root" + sqlPassword := "" + sqlIP := module.GFeEntryHost + sqlPort := module.GFeEntryQueryPort + sqlDBName := "" + + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, startCnCMD) + if err != nil { + infoMess = fmt.Sprintf(`Waiting for start CN node: + user = %s + keyRsa = %s + sshHost = %s + sshPort = %d + cnDeployDir = %s`, user, keyRsa, sshHost, sshPort, cnDeployDir) + utl.Log("WARN", infoMess) + return err + } + + _, err = utl.RunSQL(sqlUserName, sqlPassword, sqlIP, sqlPort, sqlDBName, addCnSQL) + if err != nil { + if isComputeNodeAlreadyRegistered(err) { + infoMess = fmt.Sprintf("CN node is already registered [CnHost = %s, HeartbeatServicePort = %d]", sshHost, heartbeatServicePort) + utl.Log("INFO", infoMess) + return nil + } + infoMess = fmt.Sprintf(`Error in add CN node, [ + sqlUserName = %s + sqlPassword = %s + sqlIP = %s + sqlPort = %d + sqlDBName = %s + addComputeNodeSQL = %s + errMess = %v]`, sqlUserName, sqlPassword, sqlIP, sqlPort, sqlDBName, addCnSQL, err) + utl.Log("ERROR", infoMess) + return err + } + + return nil +} + +func isComputeNodeAlreadyRegistered(err error) bool { + if err == nil { + return false + } + errText := strings.ToLower(err.Error()) + return strings.Contains(errText, "already") && strings.Contains(errText, "compute") +} diff --git a/cluster/startCluster/initCn_test.go b/cluster/startCluster/initCn_test.go new file mode 100644 index 0000000..a178867 --- /dev/null +++ b/cluster/startCluster/initCn_test.go @@ -0,0 +1,18 @@ +package startCluster + +import ( + "errors" + "testing" +) + +func TestIsComputeNodeAlreadyRegistered(t *testing.T) { + if !isComputeNodeAlreadyRegistered(errors.New("Compute node already exists")) { + t.Fatalf("expected already registered error to be detected") + } + if isComputeNodeAlreadyRegistered(errors.New("network timeout")) { + t.Fatalf("expected unrelated error not to be detected") + } + if isComputeNodeAlreadyRegistered(nil) { + t.Fatalf("expected nil error not to be detected") + } +} diff --git a/cluster/startCluster/initFe.go b/cluster/startCluster/initFe.go index c548461..ca5693f 100644 --- a/cluster/startCluster/initFe.go +++ b/cluster/startCluster/initFe.go @@ -1,149 +1,138 @@ package startCluster import ( - "fmt" - "time" - "strings" - "stargo/sr-utl" - "stargo/module" - "stargo/cluster/checkStatus" + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" + "strings" + "time" ) - func InitFeCluster(yamlConf *module.ConfStruct) { - var infoMess string - var err error - var feStat map[string]string - - // start Fe node one by one - var tmpUser string - var tmpKeyRsa string - var tmpSshHost string - var tmpSshPort int - var tmpEditLogPort int - var tmpQueryPort int - var tmpFeDeployDir string - var feStatusList string - var feEntryId int - tmpUser = yamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - - // get FE entry - feEntryId, err = checkStatus.GetFeEntry(-1) - - if err != nil || feEntryId == -1 { - //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." - //utl.Log("WARN", infoMess) - module.SetFeEntry(0) - } else { - module.SetFeEntry(feEntryId) - } - - for i := 0; i < len(yamlConf.FeServers); i++ { - // for i := 0; i < 1; i++ { ## debug leader node - - tmpSshHost = yamlConf.FeServers[i].Host - tmpSshPort = yamlConf.FeServers[i].SshPort - tmpEditLogPort = yamlConf.FeServers[i].EditLogPort - tmpQueryPort = yamlConf.FeServers[i].QueryPort - tmpFeDeployDir = yamlConf.FeServers[i].DeployDir - - //infoMess = fmt.Sprintf("Starting FE node [FeHost = %s, FeEditLogPort = %d]", tmpSshHost, tmpEditLogPort) - //utl.Log("INFO", infoMess) - - for startTimeInd := 0; startTimeInd < 3; startTimeInd++ { - // initFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) - infoMess = fmt.Sprintf("The %d time to start [%s]", (startTimeInd + 1), tmpSshHost) - utl.Log("DEBUG", infoMess) - err = InitFeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpEditLogPort, tmpFeDeployDir) - startWaitTime := time.Duration(20 - startTimeInd * 5) - time.Sleep(startWaitTime * time.Second) - - feStat, err = checkStatus.CheckFeStatus(i) - - if err != nil { - infoMess = fmt.Sprintf("Error in get the fe status [FeHost = %s, error = %v]", tmpSshHost, err) - utl.Log("DEBUG", infoMess) - } - if feStat["Alive"] == "true" { - infoMess = fmt.Sprintf("The FE node start succefully [host = %s, queryPort = %d]", tmpSshHost, tmpQueryPort) - utl.Log("INFO", infoMess) - break - } else { - infoMess = fmt.Sprintf("The FE node doesn't start, wait for 10s [FeHost = %s, FeQueryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) - utl.Log("WARN", infoMess) - } - } // FOR-END: 3 time to restart FE node - - if feStat["Alive"] == "false" { - infoMess = fmt.Sprintf("The FE node start failed [host = %s, queryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) - utl.Log("ERROR", infoMess) - } - feStatusList = feStatusList + " " + fmt.Sprintf("feHost = %-20sfeQueryPort = %d feStatus = true\n", tmpSshHost, tmpQueryPort) - } // FOR-END: list all FE node - - feStatusList = "List all FE status:\n" + feStatusList - utl.Log("INFO", feStatusList) + var infoMess string + var err error + var feStat map[string]string + + // start Fe node one by one + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpEditLogPort int + var tmpQueryPort int + var tmpFeDeployDir string + var feStatusList string + var feEntryId int + tmpUser = yamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + // get FE entry + feEntryId, err = checkStatus.GetFeEntry(-1) + + if err != nil || feEntryId == -1 { + //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." + //utl.Log("WARN", infoMess) + module.SetFeEntry(0) + } else { + module.SetFeEntry(feEntryId) + } + + for i := 0; i < len(yamlConf.FeServers); i++ { + // for i := 0; i < 1; i++ { ## debug leader node + + tmpSshHost = yamlConf.FeServers[i].Host + tmpSshPort = yamlConf.FeServers[i].SshPort + tmpEditLogPort = yamlConf.FeServers[i].EditLogPort + tmpQueryPort = yamlConf.FeServers[i].QueryPort + tmpFeDeployDir = yamlConf.FeServers[i].DeployDir + + //infoMess = fmt.Sprintf("Starting FE node [FeHost = %s, FeEditLogPort = %d]", tmpSshHost, tmpEditLogPort) + //utl.Log("INFO", infoMess) + + for startTimeInd := 0; startTimeInd < 3; startTimeInd++ { + // initFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) + infoMess = fmt.Sprintf("The %d time to start [%s]", (startTimeInd + 1), tmpSshHost) + utl.Log("DEBUG", infoMess) + err = InitFeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpEditLogPort, tmpFeDeployDir) + startWaitTime := time.Duration(20 - startTimeInd*5) + time.Sleep(startWaitTime * time.Second) + + feStat, err = checkStatus.CheckFeStatus(i) + + if err != nil { + infoMess = fmt.Sprintf("Error in get the fe status [FeHost = %s, error = %v]", tmpSshHost, err) + utl.Log("DEBUG", infoMess) + } + if feStat["Alive"] == "true" { + infoMess = fmt.Sprintf("The FE node start successfully [host = %s, queryPort = %d]", tmpSshHost, tmpQueryPort) + utl.Log("INFO", infoMess) + break + } else { + infoMess = fmt.Sprintf("The FE node doesn't start, wait for 10s [FeHost = %s, FeQueryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) + utl.Log("WARN", infoMess) + } + } // FOR-END: 3 time to restart FE node + + if feStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The FE node start failed [host = %s, queryPort = %d, error = %v]", tmpSshHost, tmpQueryPort, err) + utl.Log("ERROR", infoMess) + } + feStatusList = feStatusList + " " + fmt.Sprintf("feHost = %-20sfeQueryPort = %d feStatus = %v\n", tmpSshHost, tmpQueryPort, feStat["Alive"]) + } // FOR-END: list all FE node + + feStatusList = "List all FE status:\n" + feStatusList + utl.Log("INFO", feStatusList) } - - - func InitFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) { - - var infoMess string - //var isMasterFe bool - var startFeCmd string - // check master node - if sshHost == module.GYamlConf.FeServers[0].Host && editLogPort == module.GYamlConf.FeServers[0].EditLogPort { - //isMasterFe = true - infoMess = fmt.Sprintf("Starting leader FE node [host = %s, editLogPort = %d]", module.GYamlConf.FeServers[0].Host, module.GYamlConf.FeServers[0].EditLogPort) - utl.Log("INFO", infoMess) - startFeCmd = fmt.Sprintf("%s/bin/start_fe.sh --daemon", feDeployDir) - // time.Sleep(30 * time.Second) - } else { - infoMess = fmt.Sprintf("Starting follower FE node [host = %s, editLogPort = %d]", sshHost, editLogPort) - utl.Log("INFO", infoMess) - - startFeCmd = fmt.Sprintf("%s/bin/start_fe.sh --helper %s:%d --daemon", feDeployDir, module.GFeEntryHost, module.GFeEntryEditLogPort) - - // if the start node is follower node, ALTER SYSTEM ADD FOLLOWER "host:editLogPort"; - // func RunSQL(userName string, password string, ip string, port int, dbName string, sqlStat string) (rows *sql.Rows, err error) - - sqlUserName := "root" - sqlPassword := "" - sqlIp := module.GFeEntryHost - sqlPort := module.GFeEntryQueryPort - sqlDbName := "" - addFollowerSql := fmt.Sprintf("ALTER SYSTEM ADD FOLLOWER \"%s:%d\"", sshHost, editLogPort) - _, err := utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, addFollowerSql) - if err != nil { - if strings.Contains(err.Error(), "frontend already exists name") { - } else { - infoMess = fmt.Sprintf("Error in add follower fe node [FeHost = %s, Error = %v", sqlIp, err) - utl.Log("ERROR", infoMess) - return err - } - } - - } - - - // run feDeploy/bin/start_fe.sh --daemon --helper hsot:edit_log_port - - _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, startFeCmd) - if err != nil { - infoMess = fmt.Sprintf("Waiting for starting FE node [FeHost = %s]", sshHost) - utl.Log("DEBUG", infoMess) - return err - } - return nil + var infoMess string + //var isMasterFe bool + var startFeCmd string + // check master node + if sshHost == module.GYamlConf.FeServers[0].Host && editLogPort == module.GYamlConf.FeServers[0].EditLogPort { + //isMasterFe = true + infoMess = fmt.Sprintf("Starting leader FE node [host = %s, editLogPort = %d]", module.GYamlConf.FeServers[0].Host, module.GYamlConf.FeServers[0].EditLogPort) + utl.Log("INFO", infoMess) + startFeCmd = fmt.Sprintf("%s/bin/start_fe.sh --daemon", feDeployDir) + // time.Sleep(30 * time.Second) + } else { + infoMess = fmt.Sprintf("Starting follower FE node [host = %s, editLogPort = %d]", sshHost, editLogPort) + utl.Log("INFO", infoMess) + + startFeCmd = fmt.Sprintf("%s/bin/start_fe.sh --helper %s:%d --daemon", feDeployDir, module.GFeEntryHost, module.GFeEntryEditLogPort) + + // if the start node is follower node, ALTER SYSTEM ADD FOLLOWER "host:editLogPort"; + // func RunSQL(userName string, password string, ip string, port int, dbName string, sqlStat string) (rows *sql.Rows, err error) + + sqlUserName := "root" + sqlPassword := "" + sqlIp := module.GFeEntryHost + sqlPort := module.GFeEntryQueryPort + sqlDbName := "" + addFollowerSql := fmt.Sprintf("ALTER SYSTEM ADD FOLLOWER \"%s:%d\"", sshHost, editLogPort) + _, err := utl.RunSQL(sqlUserName, sqlPassword, sqlIp, sqlPort, sqlDbName, addFollowerSql) + if err != nil { + if strings.Contains(err.Error(), "frontend already exists name") { + } else { + infoMess = fmt.Sprintf("Error in add follower fe node [FeHost = %s, Error = %v", sqlIp, err) + utl.Log("ERROR", infoMess) + return err + } + } + + } + + // run feDeploy/bin/start_fe.sh --daemon --helper hsot:edit_log_port + + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, startFeCmd) + if err != nil { + infoMess = fmt.Sprintf("Waiting for starting FE node [FeHost = %s]", sshHost) + utl.Log("DEBUG", infoMess) + return err + } + return nil } - - - - diff --git a/cluster/startCluster/sharedDataReady.go b/cluster/startCluster/sharedDataReady.go new file mode 100644 index 0000000..6b156ff --- /dev/null +++ b/cluster/startCluster/sharedDataReady.go @@ -0,0 +1,118 @@ +package startCluster + +import ( + "errors" + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + utl "stargo/sr-utl" + "strings" + "time" +) + +const ( + sharedDataReadyTimeout = 5 * time.Minute + sharedDataReadyInterval = 5 * time.Second +) + +func WaitSharedDataReady(yamlConf *module.ConfStruct) error { + startAt := time.Now() + + for { + if time.Since(startAt) > sharedDataReadyTimeout { + infoMess := fmt.Sprintf("Shared-data cluster readiness probe timed out after %s", sharedDataReadyTimeout) + utl.Log("ERROR", infoMess) + return errors.New(infoMess) + } + + if !allCnAlive(yamlConf) { + time.Sleep(sharedDataReadyInterval) + continue + } + + if probeSharedDataCRUD() { + infoMess := fmt.Sprintf("Shared-data cluster is ready for CRUD traffic, probe succeeded after %s", time.Since(startAt).Round(time.Second)) + utl.Log("INFO", infoMess) + return nil + } + + time.Sleep(sharedDataReadyInterval) + } +} + +func allCnAlive(yamlConf *module.ConfStruct) bool { + feEntryId, err := checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + utl.Log("DEBUG", fmt.Sprintf("Shared-data readiness waits for FE entry: %v", err)) + return false + } + module.SetFeEntry(feEntryId) + + for i := 0; i < len(yamlConf.CnServers); i++ { + cnStat, err := checkStatus.CheckCnStatus(i) + if err != nil { + utl.Log("DEBUG", fmt.Sprintf("Shared-data readiness waits for CN[%d]: %v", i, err)) + return false + } + if strings.TrimSpace(cnStat["Alive"]) != "true" { + utl.Log("DEBUG", fmt.Sprintf("Shared-data readiness waits for CN[%d] to become alive", i)) + return false + } + } + + return true +} + +func probeSharedDataCRUD() bool { + dbName := "stargo_readiness" + tableName := fmt.Sprintf("probe_%d", time.Now().UnixNano()) + statements := []string{ + fmt.Sprintf("create database if not exists %s", dbName), + fmt.Sprintf("create table %s.%s (id int, name string) duplicate key(id) distributed by hash(id) buckets 1 properties(\"replication_num\"=\"1\")", dbName, tableName), + fmt.Sprintf("insert into %s.%s values (1, 'ok')", dbName, tableName), + fmt.Sprintf("select id, name from %s.%s where id = 1", dbName, tableName), + } + + for idx, sql := range statements { + rows, err := utl.RunSQL(module.GJdbcUser, module.GJdbcPasswd, module.GFeEntryHost, module.GFeEntryQueryPort, module.GJdbcDb, sql) + if err != nil { + utl.Log("DEBUG", fmt.Sprintf("Shared-data readiness probe step %d failed [sql = %s, error = %v]", idx+1, sql, err)) + return false + } + if rows != nil { + if idx == len(statements)-1 { + if !rows.Next() { + rows.Close() + utl.Log("DEBUG", "Shared-data readiness probe select returned no rows") + return false + } + var id int + var name string + if err = rows.Scan(&id, &name); err != nil { + rows.Close() + utl.Log("DEBUG", fmt.Sprintf("Shared-data readiness probe select scan failed: %v", err)) + return false + } + if id != 1 || name != "ok" { + rows.Close() + utl.Log("DEBUG", fmt.Sprintf("Shared-data readiness probe select returned unexpected row [id=%d name=%s]", id, name)) + return false + } + } + rows.Close() + } + } + + cleanupStatements := []string{ + fmt.Sprintf("drop table if exists %s.%s", dbName, tableName), + fmt.Sprintf("drop database if exists %s", dbName), + } + for _, sql := range cleanupStatements { + rows, err := utl.RunSQL(module.GJdbcUser, module.GJdbcPasswd, module.GFeEntryHost, module.GFeEntryQueryPort, module.GJdbcDb, sql) + if err == nil && rows != nil { + rows.Close() + } + } + + return true +} diff --git a/cluster/startCluster/startBe.go b/cluster/startCluster/startBe.go index d376598..22ff66d 100644 --- a/cluster/startCluster/startBe.go +++ b/cluster/startCluster/startBe.go @@ -1,79 +1,71 @@ - package startCluster -import( - "fmt" - "time" -// "errors" - "stargo/sr-utl" - "stargo/module" - "stargo/cluster/checkStatus" +import ( + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + "time" + // "errors" + "stargo/sr-utl" ) - - - func StartBeCluster() { - - // start Be node one by one - var infoMess string - var tmpUser string - var tmpKeyRsa string - var tmpSshHost string - var tmpSshPort int - var tmpHeartbeatServicePort int - //var tmpQueryPort int - var tmpBeDeployDir string - - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - // for i := 0; i < 1; i++ { ## debug leader node - - tmpSshHost = module.GYamlConf.BeServers[i].Host - tmpSshPort = module.GYamlConf.BeServers[i].SshPort - tmpHeartbeatServicePort = module.GYamlConf.BeServers[i].HeartbeatServicePort - tmpBeDeployDir = module.GYamlConf.BeServers[i].DeployDir - - infoMess = fmt.Sprintf("Starting BE node [BeHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) - utl.Log("INFO", infoMess) - - _ = StartBeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpHeartbeatServicePort, tmpBeDeployDir) - for j := 0; j < 3; j++ { - portStat, _ := checkStatus.CheckBePortStatus(i) - if portStat { - break - //time.Sleep(10 * time.Second) - } else { - time.Sleep(10 * time.Second) - } - } - } + // start Be node one by one + var infoMess string + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpHeartbeatServicePort int + //var tmpQueryPort int + var tmpBeDeployDir string + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + // for i := 0; i < 1; i++ { ## debug leader node + + tmpSshHost = module.GYamlConf.BeServers[i].Host + tmpSshPort = module.GYamlConf.BeServers[i].SshPort + tmpHeartbeatServicePort = module.GYamlConf.BeServers[i].HeartbeatServicePort + tmpBeDeployDir = module.GYamlConf.BeServers[i].DeployDir + + infoMess = fmt.Sprintf("Starting BE node [BeHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + + _ = StartBeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpHeartbeatServicePort, tmpBeDeployDir) + for j := 0; j < 3; j++ { + portStat, _ := checkStatus.CheckBePortStatus(i) + if portStat { + break + //time.Sleep(10 * time.Second) + } else { + time.Sleep(10 * time.Second) + } + } + } } - func StartBeNode(user string, keyRsa string, sshHost string, sshPort int, heartbeatServicePort int, beDeployDir string) (err error) { - var infoMess string - - - startBeCMD := fmt.Sprintf("%s/bin/start_be.sh --daemon", beDeployDir) + var infoMess string - infoMess = fmt.Sprintf("Starting BE node [host = %s, heartbeatServicePort = %d]", sshHost, heartbeatServicePort) - utl.Log("DEBUG", infoMess) + startBeCMD := fmt.Sprintf("%s/bin/start_be.sh --daemon", beDeployDir) + infoMess = fmt.Sprintf("Starting BE node [host = %s, heartbeatServicePort = %d]", sshHost, heartbeatServicePort) + utl.Log("DEBUG", infoMess) - // run beDeploy/bin/start_be.sh --daemon - _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, startBeCMD) - if err != nil { - infoMess = fmt.Sprintf("Waiting for start BE node.[BeHost = %s, Error = %v", sshHost, err) - utl.Log("DEBUG", infoMess) - return err - } + // run beDeploy/bin/start_be.sh --daemon + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, startBeCMD) + if err != nil { + infoMess = fmt.Sprintf("Waiting for start BE node.[BeHost = %s, Error = %v", sshHost, err) + utl.Log("DEBUG", infoMess) + return err + } - // time.Sleep(5 * time.Second) - return nil + // time.Sleep(5 * time.Second) + return nil } diff --git a/cluster/startCluster/startCn.go b/cluster/startCluster/startCn.go new file mode 100644 index 0000000..89bbee8 --- /dev/null +++ b/cluster/startCluster/startCn.go @@ -0,0 +1,93 @@ +package startCluster + +import ( + "errors" + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" + "strings" + "time" +) + +// StartCnCluster starts all CN nodes in the cluster +func StartCnCluster() error { + + // start CN node one by one + var infoMess string + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpHeartbeatServicePort int + var tmpCnDeployDir string + var failedNodes []string + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + + tmpSshHost = module.GYamlConf.CnServers[i].Host + tmpSshPort = module.GYamlConf.CnServers[i].SshPort + tmpHeartbeatServicePort = module.GYamlConf.CnServers[i].HeartbeatServicePort + tmpCnDeployDir = module.GYamlConf.CnServers[i].DeployDir + + infoMess = fmt.Sprintf("Starting CN node [CnHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + + if portStat, _ := checkStatus.CheckCnPortStatus(i); portStat { + infoMess = fmt.Sprintf("CN node already running [CnHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + continue + } + + err := StartCnNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpHeartbeatServicePort, tmpCnDeployDir) + if err != nil { + failedNodes = append(failedNodes, fmt.Sprintf("%s:%d start failed: %v", tmpSshHost, tmpHeartbeatServicePort, err)) + continue + } + + portReady := false + for j := 0; j < 3; j++ { + portStat, _ := checkStatus.CheckCnPortStatus(i) + if portStat { + portReady = true + break + } else { + time.Sleep(10 * time.Second) + } + } + if !portReady { + failedNodes = append(failedNodes, fmt.Sprintf("%s:%d port not ready", tmpSshHost, tmpHeartbeatServicePort)) + } + } + + if len(failedNodes) > 0 { + return errors.New("failed to start CN nodes: " + strings.Join(failedNodes, "; ")) + } + + return nil +} + +// StartCnNode starts a single CN node +func StartCnNode(user string, keyRsa string, sshHost string, sshPort int, heartbeatServicePort int, cnDeployDir string) (err error) { + + var infoMess string + + startCnCMD := fmt.Sprintf("%s/bin/start_cn.sh --daemon", cnDeployDir) + + infoMess = fmt.Sprintf("Starting CN node [host = %s, heartbeatServicePort = %d]", sshHost, heartbeatServicePort) + utl.Log("DEBUG", infoMess) + + // run cnDeploy/bin/start_cn.sh --daemon + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, startCnCMD) + if err != nil { + infoMess = fmt.Sprintf("Waiting for start CN node.[CnHost = %s, Error = %v", sshHost, err) + utl.Log("DEBUG", infoMess) + return err + } + + return nil + +} diff --git a/cluster/startCluster/startFe.go b/cluster/startCluster/startFe.go index 0535fde..ae4fa26 100644 --- a/cluster/startCluster/startFe.go +++ b/cluster/startCluster/startFe.go @@ -1,83 +1,74 @@ package startCluster import ( - "fmt" - "time" - "stargo/sr-utl" - "stargo/module" - "stargo/cluster/checkStatus" + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" + "time" ) - - func StartFeCluster() { - var infoMess string - //var err error - //var feStat checkStatus.FeStatusStruct - - // start Fe node one by one - var tmpUser string - var tmpKeyRsa string - var tmpSshHost string - var tmpSshPort int - var tmpEditLogPort int - //var tmpQueryPort int - var tmpFeDeployDir string - - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - // for i := 0; i < 1; i++ { ## debug leader node - - tmpSshHost = module.GYamlConf.FeServers[i].Host - tmpSshPort = module.GYamlConf.FeServers[i].SshPort - tmpEditLogPort = module.GYamlConf.FeServers[i].EditLogPort - //tmpQueryPort = module.GYamlConf.FeServers[i].QueryPort - tmpFeDeployDir = module.GYamlConf.FeServers[i].DeployDir - - infoMess = fmt.Sprintf("Starting FE node [FeHost = %s, EditLogPort = %d]", tmpSshHost, tmpEditLogPort) - utl.Log("INFO", infoMess) - - // startFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) - _ = StartFeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpEditLogPort, tmpFeDeployDir) - for j := 0; j < 3; j++ { - portStat, _ := checkStatus.CheckFePortStatus(i) - if portStat { - break - //time.Sleep(10 * time.Second) - } else { - time.Sleep(10 * time.Second) - } - } - } + var infoMess string + //var err error + //var feStat checkStatus.FeStatusStruct + + // start Fe node one by one + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpEditLogPort int + //var tmpQueryPort int + var tmpFeDeployDir string + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + // for i := 0; i < 1; i++ { ## debug leader node + + tmpSshHost = module.GYamlConf.FeServers[i].Host + tmpSshPort = module.GYamlConf.FeServers[i].SshPort + tmpEditLogPort = module.GYamlConf.FeServers[i].EditLogPort + //tmpQueryPort = module.GYamlConf.FeServers[i].QueryPort + tmpFeDeployDir = module.GYamlConf.FeServers[i].DeployDir + + infoMess = fmt.Sprintf("Starting FE node [FeHost = %s, EditLogPort = %d]", tmpSshHost, tmpEditLogPort) + utl.Log("INFO", infoMess) + + // startFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) + _ = StartFeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpEditLogPort, tmpFeDeployDir) + for j := 0; j < 3; j++ { + portStat, _ := checkStatus.CheckFePortStatus(i) + if portStat { + break + //time.Sleep(10 * time.Second) + } else { + time.Sleep(10 * time.Second) + } + } + } } - - - - - func StartFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) { + var infoMess string + //var isMasterFe bool + var startFeCmd string - var infoMess string - //var isMasterFe bool - var startFeCmd string - - // check master node - startFeCmd = fmt.Sprintf("%s/bin/start_fe.sh --daemon", feDeployDir) - infoMess = fmt.Sprintf("Run starting FE process [host = %s, editLogPort = %d]", sshHost, editLogPort) - utl.Log("DEBUG", infoMess) - _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, startFeCmd) + // check master node + startFeCmd = fmt.Sprintf("%s/bin/start_fe.sh --daemon", feDeployDir) + infoMess = fmt.Sprintf("Run starting FE process [host = %s, editLogPort = %d]", sshHost, editLogPort) + utl.Log("DEBUG", infoMess) + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, startFeCmd) - if err != nil { - infoMess = fmt.Sprintf("Waiting for starting FE node [FeHost = %s]", sshHost) - utl.Log("DEBUG", infoMess) - return err - } - return nil + if err != nil { + infoMess = fmt.Sprintf("Waiting for starting FE node [FeHost = %s]", sshHost) + utl.Log("DEBUG", infoMess) + return err + } + return nil } - diff --git a/cluster/stopCluster/stopBe.go b/cluster/stopCluster/stopBe.go index fdc8091..f8f150f 100644 --- a/cluster/stopCluster/stopBe.go +++ b/cluster/stopCluster/stopBe.go @@ -1,81 +1,80 @@ package stopCluster import ( - "fmt" - "stargo/sr-utl" - "stargo/module" - "stargo/cluster/checkStatus" + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" ) // func startFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) { -func StopBeNode(user string, keyRsa string, sshHost string, sshPort int, beDeployDir string) (err error){ +func StopBeNode(user string, keyRsa string, sshHost string, sshPort int, beDeployDir string) (err error) { - var infoMess string - var stopBeCmd string + var infoMess string + var stopBeCmd string - // /opt/starrocks/be/bin/stop_be.sh - stopBeCmd = fmt.Sprintf("%s/bin/stop_be.sh", beDeployDir) - - infoMess = fmt.Sprintf("Waiting for stoping BE node [BeHost = %s]", sshHost) - utl.Log("INFO", infoMess) - _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, stopBeCmd) - if err != nil { - infoMess = fmt.Sprintf("Stop BE failed [BeHost = %s, error = %v]", sshHost, err) - utl.Log("DEBUG", infoMess) - return err - } - return nil + // /opt/starrocks/be/bin/stop_be.sh + stopBeCmd = fmt.Sprintf("%s/bin/stop_be.sh", beDeployDir) + + infoMess = fmt.Sprintf("Waiting for stopping BE node [BeHost = %s]", sshHost) + utl.Log("INFO", infoMess) + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, stopBeCmd) + if err != nil { + infoMess = fmt.Sprintf("Stop BE failed [BeHost = %s, error = %v]", sshHost, err) + utl.Log("DEBUG", infoMess) + return err + } + return nil } func StopBeCluster(clusterName string) { - var infoMess string - var err error - var beStat map[string]string - - - // Stop BE node one by one - var tmpUser string - var tmpKeyRsa string - var tmpSshHost string - var tmpSshPort int - var tmpBeDeployDir string - var tmpHeartbeatServicePort int - //var beStatusList string - - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - infoMess = "Stop cluster " + clusterName - utl.Log("OUTPUT", infoMess) - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - - tmpSshHost = module.GYamlConf.BeServers[i].Host - tmpSshPort = module.GYamlConf.BeServers[i].SshPort - tmpBeDeployDir = module.GYamlConf.BeServers[i].DeployDir - tmpHeartbeatServicePort = module.GYamlConf.BeServers[i].HeartbeatServicePort - // func StopFeNode(user string, keyRsa string, sshHost string, sshPort int, feDeployDir string) (err error) - err = StopBeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpBeDeployDir) - if err != nil { - infoMess = fmt.Sprintf("Error in stoping BE node [BeHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) - utl.Log("DEBUG", infoMess) - } - - beStat, err = checkStatus.CheckBeStatus(i) - - if err != nil { - infoMess = fmt.Sprintf("Error in get the Be status [BeHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) - utl.Log("DEBUG", infoMess) - } - if beStat["Alive"] == "false" { - infoMess = fmt.Sprintf("The BE node stop succefully [BeHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) - utl.Log("INFO", infoMess) - } else { - infoMess = fmt.Sprintf("The BE node stop failed [BeHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) - utl.Log("DEBUG", infoMess) - } - } + var infoMess string + var err error + var beStat map[string]string + + // Stop BE node one by one + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpBeDeployDir string + var tmpHeartbeatServicePort int + //var beStatusList string + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + infoMess = "Stop cluster " + clusterName + utl.Log("OUTPUT", infoMess) + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + + tmpSshHost = module.GYamlConf.BeServers[i].Host + tmpSshPort = module.GYamlConf.BeServers[i].SshPort + tmpBeDeployDir = module.GYamlConf.BeServers[i].DeployDir + tmpHeartbeatServicePort = module.GYamlConf.BeServers[i].HeartbeatServicePort + // func StopFeNode(user string, keyRsa string, sshHost string, sshPort int, feDeployDir string) (err error) + err = StopBeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpBeDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stopping BE node [BeHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) + utl.Log("DEBUG", infoMess) + } + + beStat, err = checkStatus.CheckBeStatus(i) + + if err != nil { + infoMess = fmt.Sprintf("Error in get the Be status [BeHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) + utl.Log("DEBUG", infoMess) + } + if beStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The BE node stop successfully [BeHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + } else { + infoMess = fmt.Sprintf("The BE node stop failed [BeHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("DEBUG", infoMess) + } + } } diff --git a/cluster/stopCluster/stopCn.go b/cluster/stopCluster/stopCn.go new file mode 100644 index 0000000..7763f0f --- /dev/null +++ b/cluster/stopCluster/stopCn.go @@ -0,0 +1,84 @@ +package stopCluster + +import ( + "errors" + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" + "strings" +) + +// StopCnNode stops a single CN node +func StopCnNode(user string, keyRsa string, sshHost string, sshPort int, cnDeployDir string) (err error) { + + var infoMess string + var stopCnCmd string + + // /opt/starrocks/cn/bin/stop_cn.sh + stopCnCmd = fmt.Sprintf("%s/bin/stop_cn.sh", cnDeployDir) + + infoMess = fmt.Sprintf("Waiting for stopping CN node [CnHost = %s]", sshHost) + utl.Log("INFO", infoMess) + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, stopCnCmd) + if err != nil { + infoMess = fmt.Sprintf("Stop CN failed [CnHost = %s, error = %v]", sshHost, err) + utl.Log("DEBUG", infoMess) + return err + } + return nil + +} + +// StopCnCluster stops all CN nodes in the cluster +func StopCnCluster(clusterName string) error { + + var infoMess string + var err error + + // Stop CN node one by one + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpCnDeployDir string + var tmpHeartbeatServicePort int + var failedNodes []string + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + infoMess = "Stop CN cluster " + clusterName + utl.Log("OUTPUT", infoMess) + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + + tmpSshHost = module.GYamlConf.CnServers[i].Host + tmpSshPort = module.GYamlConf.CnServers[i].SshPort + tmpCnDeployDir = module.GYamlConf.CnServers[i].DeployDir + tmpHeartbeatServicePort = module.GYamlConf.CnServers[i].HeartbeatServicePort + + err = StopCnNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpCnDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stopping CN node [CnHost = %s, HeartbeatServicePort = %d, error = %v]", tmpSshHost, tmpHeartbeatServicePort, err) + utl.Log("DEBUG", infoMess) + failedNodes = append(failedNodes, fmt.Sprintf("%s:%d stop failed: %v", tmpSshHost, tmpHeartbeatServicePort, err)) + continue + } + + portRun, err := checkStatus.CheckCnPortStatus(i) + if err != nil || !portRun { + infoMess = fmt.Sprintf("The CN node stop successfully [CnHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("INFO", infoMess) + } else { + infoMess = fmt.Sprintf("The CN node stop failed [CnHost = %s, HeartbeatServicePort = %d]", tmpSshHost, tmpHeartbeatServicePort) + utl.Log("DEBUG", infoMess) + failedNodes = append(failedNodes, fmt.Sprintf("%s:%d port still listening", tmpSshHost, tmpHeartbeatServicePort)) + } + } + + if len(failedNodes) > 0 { + return errors.New("failed to stop CN nodes: " + strings.Join(failedNodes, "; ")) + } + + return nil +} diff --git a/cluster/stopCluster/stopFe.go b/cluster/stopCluster/stopFe.go index 9582ce1..a028839 100644 --- a/cluster/stopCluster/stopFe.go +++ b/cluster/stopCluster/stopFe.go @@ -1,80 +1,80 @@ package stopCluster import ( - "fmt" - "stargo/sr-utl" - "stargo/module" - "stargo/cluster/checkStatus" + "fmt" + "stargo/cluster/checkStatus" + "stargo/module" + "stargo/sr-utl" ) // func startFeNode(user string, keyRsa string, sshHost string, sshPort int, editLogPort int, feDeployDir string) (err error) { -func StopFeNode(user string, keyRsa string, sshHost string, sshPort int, feDeployDir string) (err error){ +func StopFeNode(user string, keyRsa string, sshHost string, sshPort int, feDeployDir string) (err error) { - var infoMess string - var stopFeCmd string + var infoMess string + var stopFeCmd string - // /opt/starrocks/fe/bin/stop_fe.sh - stopFeCmd = fmt.Sprintf("%s/bin/stop_fe.sh", feDeployDir) + // /opt/starrocks/fe/bin/stop_fe.sh + stopFeCmd = fmt.Sprintf("%s/bin/stop_fe.sh", feDeployDir) - infoMess = fmt.Sprintf("Waiting for stoping FE node [FeHost = %s]", sshHost) - utl.Log("INFO", infoMess) - _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, stopFeCmd) - if err != nil { - infoMess = fmt.Sprintf("Stop FE failed [FeHost = %s, error = %v]", sshHost, err) - utl.Log("INFO", infoMess) - return err - } - return nil + infoMess = fmt.Sprintf("Waiting for stopping FE node [FeHost = %s]", sshHost) + utl.Log("INFO", infoMess) + _, err = utl.SshRun(user, keyRsa, sshHost, sshPort, stopFeCmd) + if err != nil { + infoMess = fmt.Sprintf("Stop FE failed [FeHost = %s, error = %v]", sshHost, err) + utl.Log("INFO", infoMess) + return err + } + return nil } func StopFeCluster(clusterName string) { - var infoMess string - var err error - var feStat map[string]string - - // start Fe node one by one - var tmpUser string - var tmpKeyRsa string - var tmpSshHost string - var tmpSshPort int - var tmpFeDeployDir string - var tmpFeQueryPort int - //var feStatusList string - - tmpUser = module.GYamlConf.Global.User - tmpKeyRsa = module.GSshKeyRsa - - infoMess = "Stop cluster " + clusterName - utl.Log("OUTPUT", infoMess) - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - - tmpSshHost = module.GYamlConf.FeServers[i].Host - tmpSshPort = module.GYamlConf.FeServers[i].SshPort - tmpFeQueryPort = module.GYamlConf.FeServers[i].QueryPort - tmpFeDeployDir = module.GYamlConf.FeServers[i].DeployDir - - // func StopFeNode(user string, keyRsa string, sshHost string, sshPort int, feDeployDir string) (err error) - err = StopFeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpFeDeployDir) - if err != nil { - infoMess = fmt.Sprintf("Error in stoing FE node [FeHost = %s]", tmpSshHost) - } - - feStat, err = checkStatus.CheckFeStatus(i) - - if err != nil { - infoMess = fmt.Sprintf("Error in get the fe status [FeHost = %s, error = %v]", tmpSshHost, err) - utl.Log("DEBUG", infoMess) - } - if feStat["Alive"] == "false" { - infoMess = fmt.Sprintf("The FE node stop succefully [host = %s, queryPort = %d]", tmpSshHost, tmpFeQueryPort) - utl.Log("OUTPUT", infoMess) - } else { - infoMess = fmt.Sprintf("The FE node stop failed [host = %s, queryPort = %d]", tmpSshHost, tmpFeQueryPort) - utl.Log("DEBUG", infoMess) - } - } + var infoMess string + var err error + var feStat map[string]string + + // start Fe node one by one + var tmpUser string + var tmpKeyRsa string + var tmpSshHost string + var tmpSshPort int + var tmpFeDeployDir string + var tmpFeQueryPort int + //var feStatusList string + + tmpUser = module.GYamlConf.Global.User + tmpKeyRsa = module.GSshKeyRsa + + infoMess = "Stop cluster " + clusterName + utl.Log("OUTPUT", infoMess) + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + + tmpSshHost = module.GYamlConf.FeServers[i].Host + tmpSshPort = module.GYamlConf.FeServers[i].SshPort + tmpFeQueryPort = module.GYamlConf.FeServers[i].QueryPort + tmpFeDeployDir = module.GYamlConf.FeServers[i].DeployDir + + // func StopFeNode(user string, keyRsa string, sshHost string, sshPort int, feDeployDir string) (err error) + err = StopFeNode(tmpUser, tmpKeyRsa, tmpSshHost, tmpSshPort, tmpFeDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stoing FE node [FeHost = %s]", tmpSshHost) + } + + feStat, err = checkStatus.CheckFeStatus(i) + + if err != nil { + infoMess = fmt.Sprintf("Error in get the fe status [FeHost = %s, error = %v]", tmpSshHost, err) + utl.Log("DEBUG", infoMess) + } + if feStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The FE node stop successfully [host = %s, queryPort = %d]", tmpSshHost, tmpFeQueryPort) + utl.Log("OUTPUT", infoMess) + } else { + infoMess = fmt.Sprintf("The FE node stop failed [host = %s, queryPort = %d]", tmpSshHost, tmpFeQueryPort) + utl.Log("DEBUG", infoMess) + } + } } diff --git a/cluster/upgradeCluster/upgradeBe.go b/cluster/upgradeCluster/upgradeBe.go index 0d47360..dda2df0 100644 --- a/cluster/upgradeCluster/upgradeBe.go +++ b/cluster/upgradeCluster/upgradeBe.go @@ -1,140 +1,123 @@ package upgradeCluster import ( - - "fmt" - "time" - "strings" - //"errors" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/stopCluster" - "stargo/cluster/startCluster" - "stargo/cluster/checkStatus" - //"stargo/cluster/prepareOption" - + "fmt" + "stargo/cluster/checkStatus" + "stargo/cluster/startCluster" + "stargo/cluster/stopCluster" + "strings" + "time" + //"errors" + "stargo/module" + "stargo/sr-utl" + //"stargo/cluster/prepareOption" ) - func UpgradeBeCluster() { //(err error){ - var infoMess string - var err error - var feEntryId int - - - feEntryId, err = checkStatus.GetFeEntry(-1) - if err != nil || feEntryId == -1 { - //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." - //utl.Log("WARN", infoMess) - module.SetFeEntry(0) - } else { - module.SetFeEntry(feEntryId) - } - - - for i := 0; i < len(module.GYamlConf.BeServers); i++ { - infoMess = fmt.Sprintf("Starting upgrade BE node. [beId = %d]", i) - utl.Log("OUTPUT", infoMess) - UpgradeBeNode(i) - } + var infoMess string + var err error + var feEntryId int + + feEntryId, err = checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." + //utl.Log("WARN", infoMess) + module.SetFeEntry(0) + } else { + module.SetFeEntry(feEntryId) + } + + for i := 0; i < len(module.GYamlConf.BeServers); i++ { + infoMess = fmt.Sprintf("Starting upgrade BE node. [beId = %d]", i) + utl.Log("OUTPUT", infoMess) + UpgradeBeNode(i) + } } - func UpgradeBeNode(beId int) { - // step 1. backup be lib - // step 2. upload new be lib - // step 3. stop be node - // step 4. start be node - - var infoMess string - var user string - var sourceDir string - var targetDir string - var sshHost string - var sshPort int - var beDeployDir string - var beHeartBeatServicePort int - var keyRsa string - var beStat map[string]string - var err error - - - user = module.GYamlConf.Global.User - keyRsa = module.GSshKeyRsa - sshHost = module.GYamlConf.BeServers[beId].Host - sshPort = module.GYamlConf.BeServers[beId].SshPort - beDeployDir = module.GYamlConf.BeServers[beId].DeployDir - beHeartBeatServicePort = module.GYamlConf.BeServers[beId].HeartbeatServicePort - - - - - // step1. backup be lib - sourceDir = fmt.Sprintf("%s/lib", beDeployDir) - targetDir = fmt.Sprintf("%s/lib.bak-%s", beDeployDir, time.Now().Format("20060102150405")) - - err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) - if err != nil { - infoMess = fmt.Sprintf("Error in rename dir when backup be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("ERROR", infoMess) - } else { - infoMess = fmt.Sprintf("upgrade be node - backup be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("INFO", infoMess) - } - - - // step2. upload new be lib - sourceDir = fmt.Sprintf("%s/StarRocks-%s/be/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // sourceDir = fmt.Sprintf("%s/download/StarRocks-%s/be/lib", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) - targetDir = fmt.Sprintf("%s/lib", beDeployDir) - utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) - infoMess = fmt.Sprintf("upgrade be node - upload new be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("INFO", infoMess) - - - - // step3. stop be node - err = stopCluster.StopBeNode(user, keyRsa, sshHost, sshPort, beDeployDir) - if err != nil { - infoMess = fmt.Sprintf("Error in stop be node when upgrade be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) - utl.Log("ERROR", infoMess) - } else { - infoMess = fmt.Sprintf("upgrade be node - stop be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) - utl.Log("INFO", infoMess) - } - - // step4. start be node - - for j := 0; j < 3; j++ { - startCluster.StartBeNode(user, keyRsa, sshHost, sshPort, beHeartBeatServicePort, beDeployDir) - infoMess = fmt.Sprintf("upgrade be node - start be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) - utl.Log("INFO", infoMess) - - beStat, err = checkStatus.CheckBeStatus(beId) - if beStat["Alive"] == "true" && strings.Contains(beStat["Version"], strings.Replace(module.GSRVersion, "v", "", -1)) { - break - } - time.Sleep(10 * time.Second) - } - - if err != nil { - infoMess = fmt.Sprintf("Error in get the Be status [beId = %d, error = %v]", beId, err) - utl.Log("DEBUG", infoMess) - } else if beStat["Alive"] == "false" { - infoMess = fmt.Sprintf("The BE node upgrade failed. The BE node doesn't work. [beId = %d]\n", beId) - utl.Log("ERROR", infoMess) - } else if ! strings.Contains(beStat["Version"], strings.Replace(module.GSRVersion, "v", "", -1)) { - infoMess = fmt.Sprintf("The BE node upgrade failed. [beId = %d, targetVersion = %s, currentVersion = v%s]", beId, module.GSRVersion, beStat["Version"]) - utl.Log("ERROR", infoMess) - } else { - infoMess = fmt.Sprintf("The Be node upgrade successfully. [beId = %d, currentVersion = v%s]", beId, beStat["Version"]) - utl.Log("OUTPUT", infoMess) - } + // step 1. backup be lib + // step 2. upload new be lib + // step 3. stop be node + // step 4. start be node + + var infoMess string + var user string + var sourceDir string + var targetDir string + var sshHost string + var sshPort int + var beDeployDir string + var beHeartBeatServicePort int + var keyRsa string + var beStat map[string]string + var err error + + user = module.GYamlConf.Global.User + keyRsa = module.GSshKeyRsa + sshHost = module.GYamlConf.BeServers[beId].Host + sshPort = module.GYamlConf.BeServers[beId].SshPort + beDeployDir = module.GYamlConf.BeServers[beId].DeployDir + beHeartBeatServicePort = module.GYamlConf.BeServers[beId].HeartbeatServicePort + + // step1. backup be lib + sourceDir = fmt.Sprintf("%s/lib", beDeployDir) + targetDir = fmt.Sprintf("%s/lib.bak-%s", beDeployDir, time.Now().Format("20060102150405")) + + err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir when backup be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("upgrade be node - backup be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + } + + // step2. upload new be lib + sourceDir = fmt.Sprintf("%s/StarRocks-%s/be/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + // sourceDir = fmt.Sprintf("%s/download/StarRocks-%s/be/lib", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) + targetDir = fmt.Sprintf("%s/lib", beDeployDir) + utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + infoMess = fmt.Sprintf("upgrade be node - upload new be lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + + // step3. stop be node + err = stopCluster.StopBeNode(user, keyRsa, sshHost, sshPort, beDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stop be node when upgrade be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("upgrade be node - stop be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) + utl.Log("INFO", infoMess) + } + + // step4. start be node + + for j := 0; j < 3; j++ { + startCluster.StartBeNode(user, keyRsa, sshHost, sshPort, beHeartBeatServicePort, beDeployDir) + infoMess = fmt.Sprintf("upgrade be node - start be node. [host = %s, beDeployDir = %s]", sshHost, beDeployDir) + utl.Log("INFO", infoMess) + + beStat, err = checkStatus.CheckBeStatus(beId) + if beStat["Alive"] == "true" && strings.Contains(beStat["Version"], strings.Replace(module.GSRVersion, "v", "", -1)) { + break + } + time.Sleep(10 * time.Second) + } + + if err != nil { + infoMess = fmt.Sprintf("Error in get the Be status [beId = %d, error = %v]", beId, err) + utl.Log("DEBUG", infoMess) + } else if beStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The BE node upgrade failed. The BE node doesn't work. [beId = %d]\n", beId) + utl.Log("ERROR", infoMess) + } else if !strings.Contains(beStat["Version"], strings.Replace(module.GSRVersion, "v", "", -1)) { + infoMess = fmt.Sprintf("The BE node upgrade failed. [beId = %d, targetVersion = %s, currentVersion = v%s]", beId, module.GSRVersion, beStat["Version"]) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("The Be node upgrade successfully. [beId = %d, currentVersion = v%s]", beId, beStat["Version"]) + utl.Log("OUTPUT", infoMess) + } } - - - - diff --git a/cluster/upgradeCluster/upgradeCn.go b/cluster/upgradeCluster/upgradeCn.go new file mode 100644 index 0000000..d020cd1 --- /dev/null +++ b/cluster/upgradeCluster/upgradeCn.go @@ -0,0 +1,109 @@ +package upgradeCluster + +import ( + "fmt" + "stargo/cluster/checkStatus" + "stargo/cluster/startCluster" + "stargo/cluster/stopCluster" + "stargo/module" + "stargo/sr-utl" + "strings" + "time" +) + +func UpgradeCnCluster() { + var infoMess string + var err error + var feEntryId int + + feEntryId, err = checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + module.SetFeEntry(0) + } else { + module.SetFeEntry(feEntryId) + } + + for i := 0; i < len(module.GYamlConf.CnServers); i++ { + infoMess = fmt.Sprintf("Starting upgrade CN node. [cnId = %d]", i) + utl.Log("OUTPUT", infoMess) + UpgradeCnNode(i) + } +} + +func UpgradeCnNode(cnId int) { + var infoMess string + var user string + var sourceDir string + var targetDir string + var sshHost string + var sshPort int + var cnDeployDir string + var heartbeatServicePort int + var keyRsa string + var cnStat map[string]string + var err error + + user = module.GYamlConf.Global.User + keyRsa = module.GSshKeyRsa + sshHost = module.GYamlConf.CnServers[cnId].Host + sshPort = module.GYamlConf.CnServers[cnId].SshPort + cnDeployDir = module.GYamlConf.CnServers[cnId].DeployDir + heartbeatServicePort = module.GYamlConf.CnServers[cnId].HeartbeatServicePort + + sourceDir = fmt.Sprintf("%s/lib", cnDeployDir) + targetDir = fmt.Sprintf("%s/lib.bak-%s", cnDeployDir, time.Now().Format("20060102150405")) + + err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir when backup CN lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("upgrade CN node - backup CN lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + } + + sourceDir = fmt.Sprintf("%s/StarRocks-%s/be/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + targetDir = fmt.Sprintf("%s/lib", cnDeployDir) + utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + infoMess = fmt.Sprintf("upgrade CN node - upload new CN lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + + err = stopCluster.StopCnNode(user, keyRsa, sshHost, sshPort, cnDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stop CN node when upgrade CN node. [host = %s, cnDeployDir = %s]", sshHost, cnDeployDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("upgrade CN node - stop CN node. [host = %s, cnDeployDir = %s]", sshHost, cnDeployDir) + utl.Log("INFO", infoMess) + } + + for j := 0; j < 3; j++ { + err = startCluster.StartCnNode(user, keyRsa, sshHost, sshPort, heartbeatServicePort, cnDeployDir) + infoMess = fmt.Sprintf("upgrade CN node - start CN node. [host = %s, cnDeployDir = %s]", sshHost, cnDeployDir) + utl.Log("INFO", infoMess) + + cnStat, err = checkStatus.CheckCnStatus(cnId) + if err == nil && cnStat["Alive"] == "true" && versionMatches(cnStat["Version"]) { + break + } + time.Sleep(10 * time.Second) + } + + if err != nil { + infoMess = fmt.Sprintf("Error in get the CN status [cnId = %d, error = %v]", cnId, err) + utl.Log("DEBUG", infoMess) + } else if cnStat["Alive"] != "true" { + infoMess = fmt.Sprintf("The CN node upgrade failed. The CN node doesn't work. [cnId = %d]", cnId) + utl.Log("ERROR", infoMess) + } else if !versionMatches(cnStat["Version"]) { + infoMess = fmt.Sprintf("The CN node upgrade failed. [cnId = %d, targetVersion = %s, currentVersion = v%s]", cnId, module.GSRVersion, cnStat["Version"]) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("The CN node upgrade successfully. [cnId = %d, currentVersion = v%s]", cnId, cnStat["Version"]) + utl.Log("OUTPUT", infoMess) + } +} + +func versionMatches(currentVersion string) bool { + return strings.Contains(currentVersion, strings.Replace(module.GSRVersion, "v", "", -1)) +} diff --git a/cluster/upgradeCluster/upgradeFe.go b/cluster/upgradeCluster/upgradeFe.go index 43de83d..bcb2fa8 100644 --- a/cluster/upgradeCluster/upgradeFe.go +++ b/cluster/upgradeCluster/upgradeFe.go @@ -1,141 +1,122 @@ package upgradeCluster import ( - - "fmt" - "time" - "strings" - //"errors" - "stargo/module" - "stargo/sr-utl" - "stargo/cluster/stopCluster" - "stargo/cluster/startCluster" - "stargo/cluster/checkStatus" - //"stargo/cluster/prepareOption" - + "fmt" + "stargo/cluster/checkStatus" + "stargo/cluster/startCluster" + "stargo/cluster/stopCluster" + "strings" + "time" + //"errors" + "stargo/module" + "stargo/sr-utl" + //"stargo/cluster/prepareOption" ) - func UpgradeFeCluster() { //(err error){ - var infoMess string - var err error - var feEntryId int - - - feEntryId, err = checkStatus.GetFeEntry(-1) - if err != nil || feEntryId == -1 { - //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." - //utl.Log("WARN", infoMess) - module.SetFeEntry(0) - } else { - module.SetFeEntry(feEntryId) - } - - - for i := 0; i < len(module.GYamlConf.FeServers); i++ { - infoMess = fmt.Sprintf("Starting upgrade FE node. [feId = %d]", i) - utl.Log("OUTPUT", infoMess) - UpgradeFeNode(i) - } - - + var infoMess string + var err error + var feEntryId int + + feEntryId, err = checkStatus.GetFeEntry(-1) + if err != nil || feEntryId == -1 { + //infoMess = "All FE nodes are down, please start FE node and display the cluster status again." + //utl.Log("WARN", infoMess) + module.SetFeEntry(0) + } else { + module.SetFeEntry(feEntryId) + } + + for i := 0; i < len(module.GYamlConf.FeServers); i++ { + infoMess = fmt.Sprintf("Starting upgrade FE node. [feId = %d]", i) + utl.Log("OUTPUT", infoMess) + UpgradeFeNode(i) + } } - func UpgradeFeNode(feId int) { - // step 1. backup fe lib - // step 2. upload new fe lib - // step 3. stop fe node - // step 4. start fe node - - var infoMess string - var user string - var sourceDir string - var targetDir string - var sshHost string - var sshPort int - var feDeployDir string - var feEditLogPort int - var keyRsa string - var feStat map[string]string - var err error - - user = module.GYamlConf.Global.User - keyRsa = module.GSshKeyRsa - sshHost = module.GYamlConf.FeServers[feId].Host - sshPort = module.GYamlConf.FeServers[feId].SshPort - feDeployDir = module.GYamlConf.FeServers[feId].DeployDir - feEditLogPort = module.GYamlConf.FeServers[feId].EditLogPort - - - - - // step1. backup fe lib - sourceDir = fmt.Sprintf("%s/lib", feDeployDir) - targetDir = fmt.Sprintf("%s/lib.bak-%s", feDeployDir, time.Now().Format("20060102150405")) - - err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) - if err != nil { - infoMess = fmt.Sprintf("Error in rename dir when backup FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("ERROR", infoMess) - } else { - infoMess = fmt.Sprintf("upgrade FE node - backup FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("INFO", infoMess) - } - - - // step2. upload new FE lib - sourceDir = fmt.Sprintf("%s/StarRocks-%s/fe/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) - // sourceDir = fmt.Sprintf("%s/download/StarRocks-%s/fe/lib", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) - targetDir = fmt.Sprintf("%s/lib", feDeployDir) - utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) - infoMess = fmt.Sprintf("upgrade FE node - upload new FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) - utl.Log("INFO", infoMess) - - - - // step3. stop FE node - err = stopCluster.StopFeNode(user, keyRsa, sshHost, sshPort, feDeployDir) - if err != nil { - infoMess = fmt.Sprintf("Error in stop FE node when upgrade FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) - utl.Log("ERROR", infoMess) - } else { - infoMess = fmt.Sprintf("upgrade FE node - stop FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) - utl.Log("INFO", infoMess) - } - - // step4. start FE node - for j := 0; j < 3; j++ { - startCluster.StartFeNode(user, keyRsa, sshHost, sshPort, feEditLogPort, feDeployDir) - infoMess = fmt.Sprintf("upgrade FE node - start FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) - utl.Log("INFO", infoMess) - - feStat, err = checkStatus.CheckFeStatus(feId) - if feStat["Alive"] == "true" { - break - } - time.Sleep(10 * time.Second) - } - - if err != nil { - infoMess = fmt.Sprintf("Error in get the FE status [feId = %d, error = %v]", feId, err) - utl.Log("DEBUG", infoMess) - } else if feStat["Alive"] == "false" { - infoMess = fmt.Sprintf("The FE node upgrade failed. The FE node doesn't work. [feId = %d]\n", feId) - utl.Log("ERROR", infoMess) - } else if ! strings.Contains(feStat["FeVersion"], strings.Replace(module.GSRVersion, "v", "", -1)) { - infoMess = fmt.Sprintf("The FE node upgrade failed. [feId = %d, targetVersion = %s, currentVersion = v%s]", feId, module.GSRVersion, feStat["FeVersion"]) - utl.Log("ERROR", infoMess) - } else { - infoMess = fmt.Sprintf("The Be node upgrade successfully. [feId = %d, currentVersion = v%s]", feId, feStat["FeVersion"]) - utl.Log("OUTPUT", infoMess) - } - + // step 1. backup fe lib + // step 2. upload new fe lib + // step 3. stop fe node + // step 4. start fe node + + var infoMess string + var user string + var sourceDir string + var targetDir string + var sshHost string + var sshPort int + var feDeployDir string + var feEditLogPort int + var keyRsa string + var feStat map[string]string + var err error + + user = module.GYamlConf.Global.User + keyRsa = module.GSshKeyRsa + sshHost = module.GYamlConf.FeServers[feId].Host + sshPort = module.GYamlConf.FeServers[feId].SshPort + feDeployDir = module.GYamlConf.FeServers[feId].DeployDir + feEditLogPort = module.GYamlConf.FeServers[feId].EditLogPort + + // step1. backup fe lib + sourceDir = fmt.Sprintf("%s/lib", feDeployDir) + targetDir = fmt.Sprintf("%s/lib.bak-%s", feDeployDir, time.Now().Format("20060102150405")) + + err = utl.RenameDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir when backup FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("upgrade FE node - backup FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + } + + // step2. upload new FE lib + sourceDir = fmt.Sprintf("%s/StarRocks-%s/fe/lib", module.GDownloadPath, strings.Replace(module.GSRVersion, "v", "", -1)) + // sourceDir = fmt.Sprintf("%s/download/StarRocks-%s/fe/lib", module.GSRCtlRoot, strings.Replace(module.GSRVersion, "v", "", -1)) + targetDir = fmt.Sprintf("%s/lib", feDeployDir) + utl.UploadDir(user, keyRsa, sshHost, sshPort, sourceDir, targetDir) + infoMess = fmt.Sprintf("upgrade FE node - upload new FE lib. [host = %s, sourceDir = %s, targetDir = %s]", sshHost, sourceDir, targetDir) + utl.Log("INFO", infoMess) + + // step3. stop FE node + err = stopCluster.StopFeNode(user, keyRsa, sshHost, sshPort, feDeployDir) + if err != nil { + infoMess = fmt.Sprintf("Error in stop FE node when upgrade FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("upgrade FE node - stop FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) + utl.Log("INFO", infoMess) + } + + // step4. start FE node + for j := 0; j < 3; j++ { + startCluster.StartFeNode(user, keyRsa, sshHost, sshPort, feEditLogPort, feDeployDir) + infoMess = fmt.Sprintf("upgrade FE node - start FE node. [host = %s, feDeployDir = %s]", sshHost, feDeployDir) + utl.Log("INFO", infoMess) + + feStat, err = checkStatus.CheckFeStatus(feId) + if feStat["Alive"] == "true" { + break + } + time.Sleep(10 * time.Second) + } + + if err != nil { + infoMess = fmt.Sprintf("Error in get the FE status [feId = %d, error = %v]", feId, err) + utl.Log("DEBUG", infoMess) + } else if feStat["Alive"] == "false" { + infoMess = fmt.Sprintf("The FE node upgrade failed. The FE node doesn't work. [feId = %d]\n", feId) + utl.Log("ERROR", infoMess) + } else if !strings.Contains(feStat["FeVersion"], strings.Replace(module.GSRVersion, "v", "", -1)) { + infoMess = fmt.Sprintf("The FE node upgrade failed. [feId = %d, targetVersion = %s, currentVersion = v%s]", feId, module.GSRVersion, feStat["FeVersion"]) + utl.Log("ERROR", infoMess) + } else { + infoMess = fmt.Sprintf("The Be node upgrade successfully. [feId = %d, currentVersion = v%s]", feId, feStat["FeVersion"]) + utl.Log("OUTPUT", infoMess) + } } - - - - diff --git a/deploy-template.yaml b/deploy-template.yaml index 31bc8a9..d428286 100644 --- a/deploy-template.yaml +++ b/deploy-template.yaml @@ -1,6 +1,9 @@ global: - user: "starrocks" - ssh_port: 22 + user: "starrocks" + ssh_port: 22 + jdk_version: "17.0.8" + jdk_home: "" + os_type: "centos" fe_servers: - host: 192.168.88.81 @@ -14,7 +17,13 @@ fe_servers: log_dir: /data/starrocks/fe/log priority_networks: 192.168.88.0/24 config: + run_mode: "shared_data" + cloud_native_meta_port: "6090" sys_log_level: "INFO" + # Configure StarRocks shared-data storage volume settings for your environment. + # Example keys depend on the target StarRocks version and object storage provider. + # For MinIO/S3 validation, set the S3 endpoint, bucket, access key, secret key, + # region, and path-style-access options required by StarRocks. - host: 192.168.88.82 ssh_port: 22 http_port: 8030 @@ -26,7 +35,10 @@ fe_servers: log_dir: /data/starrocks/fe/log priority_networks: 192.168.88.0/24 config: + run_mode: "shared_data" + cloud_native_meta_port: "6090" sys_log_level: "INFO" + # Keep storage volume settings consistent across FE nodes. - host: 192.168.88.83 ssh_port: 22 http_port: 8030 @@ -38,43 +50,37 @@ fe_servers: log_dir: /data/starrocks/fe/log priority_networks: 192.168.88.0/24 config: + run_mode: "shared_data" + cloud_native_meta_port: "6090" sys_log_level: "INFO" + # Keep storage volume settings consistent across FE nodes. -be_servers: - - host: 192.168.88.81 +cn_servers: + - host: 192.168.88.84 ssh_port: 22 be_port: 9060 webserver_port: 8040 heartbeat_service_port: 9050 brpc_port: 8060 - deploy_dir : /opt/starrocks/be - storage_dir: /data/starrocks/be/storage - log_dir: /data/starrocks/be/log + starlet_port: 9070 + deploy_dir: /opt/starrocks/cn + storage_dir: /data/starrocks/cn/storage + log_dir: /data/starrocks/cn/log priority_networks: 192.168.88.0/24 + warehouse_name: default_warehouse config: create_tablet_worker_count: 3 - - host: 192.168.88.82 + - host: 192.168.88.85 ssh_port: 22 be_port: 9060 webserver_port: 8040 heartbeat_service_port: 9050 brpc_port: 8060 - deploy_dir : /opt/starrocks/be - storage_dir: /data/starrocks/be/storage - log_dir: /data/starrocks/be/log + starlet_port: 9070 + deploy_dir: /opt/starrocks/cn + storage_dir: /data/starrocks/cn/storage + log_dir: /data/starrocks/cn/log priority_networks: 192.168.88.0/24 + warehouse_name: default_warehouse config: create_tablet_worker_count: 3 - - host: 192.168.88.83 - ssh_port: 22 - be_port: 9060 - webserver_port: 8040 - heartbeat_service_port: 9050 - brpc_port: 8060 - deploy_dir : /opt/starrocks/be - storage_dir: /data/starrocks/be/storage - log_dir: /data/starrocks/be/log - priority_networks: 192.168.88.0/24 - config: - create_tablet_worker_count: 3 - diff --git a/docs/validation/version-matrix.md b/docs/validation/version-matrix.md new file mode 100644 index 0000000..7774ad5 --- /dev/null +++ b/docs/validation/version-matrix.md @@ -0,0 +1,40 @@ +# StarGo Validation Matrix + +This matrix records the StarRocks versions and deployment modes that are expected to work with this branch. + +## Support Levels + +- P0: must pass before this branch is considered deliverable. +- P1: should pass before an upstream PR if resources are available. +- P2: compatibility target, validated on demand. + +## Matrix + +| StarRocks version | Mode | Topology | Package | Priority | Status | +| --- | --- | --- | --- | --- | --- | +| 3.5.15 | shared-nothing | 1FE + 1BE | ubuntu-amd64 | P0 | Passed manually on 2026-04-20 | +| 4.0.0 | shared-data | 1FE + 1CN + MinIO | ubuntu-amd64 | P0 | Passed manually on 2026-04-20 | +| 4.0.0 | shared-data | 3FE + 2CN + MinIO | ubuntu-amd64 | P0 | Passed manually on 2026-04-20 | +| 3.3.x or 3.4.x | shared-nothing | 1FE + 1BE | ubuntu-amd64 | P1 | Not yet validated | +| latest 4.x stable | shared-data | 1FE + 1CN + MinIO | ubuntu-amd64 | P1 | Not yet validated | +| 3.5.15 | shared-nothing | 1FE + 1BE | centos-amd64 | P2 | Not yet validated | +| 4.0.0 | shared-data | 1FE + 1CN + MinIO | centos-amd64 | P2 | Not yet validated | + +## Required Checks + +Each validated item should record: + +1. `stargo cluster deploy` +2. `stargo cluster display` +3. SQL CRUD: create database, create table, insert, select, drop table, drop database +4. `stargo cluster stop` +5. `stargo cluster start` +6. `stargo cluster import` +7. `display` after import +8. role or node level start/stop for FE/BE/CN where applicable + +## Known Boundaries + +- The default PR CI does not start StarRocks processes. +- Multipass validation scripts are manual because they need local VM resources. +- CentOS packages are listed as compatibility targets until a CentOS validation host is available. diff --git a/env_check.sh b/env_check.sh new file mode 100755 index 0000000..6abc9b1 --- /dev/null +++ b/env_check.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# StarGo Environment Check Script +# This script checks if the environment is ready for StarRocks deployment + +echo "StarGo Environment Check" +echo "========================" + +# Check if running as root +if [ "$EUID" -eq 0 ]; then + echo "✓ Running with root privileges" +else + echo "✗ Not running as root. Some operations may require sudo." +fi + +# Check Docker +if command -v docker &> /dev/null; then + echo "✓ Docker is installed" + if docker info &> /dev/null; then + echo "✓ Docker daemon is running" + else + echo "✗ Docker daemon is not running" + fi +else + echo "✗ Docker is not installed" +fi + +# Check Kubernetes +if command -v kubectl &> /dev/null; then + echo "✓ kubectl is installed" + if kubectl cluster-info &> /dev/null; then + echo "✓ Kubernetes cluster is accessible" + else + echo "✗ Cannot access Kubernetes cluster" + fi +else + echo "✗ kubectl is not installed" +fi + +# Check Git +if command -v git &> /dev/null; then + echo "✓ Git is installed" +else + echo "✗ Git is not installed" +fi + +# Check network connectivity +if ping -c 1 google.com &> /dev/null; then + echo "✓ Network connectivity is available" +else + echo "✗ No network connectivity" +fi + +echo "" +echo "Environment check completed." \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c74939a --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module stargo + +go 1.25.0 + +require ( + github.com/go-sql-driver/mysql v1.9.3 + github.com/pkg/sftp v1.13.10 + golang.org/x/crypto v0.43.0 + gopkg.in/yaml.v2 v2.4.0 +) + +require ( + filippo.io/edwards25519 v1.1.0 // indirect + github.com/kr/fs v0.1.0 // indirect + golang.org/x/sys v0.37.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f0a4871 --- /dev/null +++ b/go.sum @@ -0,0 +1,26 @@ +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo= +github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= +github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/pkg/sftp v1.13.10 h1:+5FbKNTe5Z9aspU88DPIKJ9z2KZoaGCu6Sr6kKR/5mU= +github.com/pkg/sftp v1.13.10/go.mod h1:bJ1a7uDhrX/4OII+agvy28lzRvQrmIQuaHrcI1HbeGA= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= +golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= +golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/importTest.yaml b/importTest.yaml index e47a372..b46548f 100644 --- a/importTest.yaml +++ b/importTest.yaml @@ -1,29 +1,29 @@ global: user: starrocks fe_servers: -- host: 192.168.88.83 - ssh_port: 22 - query_port: 9030 - deploy_dir: /opt/starrocks/fe -- host: 192.168.88.84 - ssh_port: 22 - query_port: 9030 - deploy_dir: /opt/starrocks/fe -- host: 192.168.88.85 - ssh_port: 22 - query_port: 9030 - deploy_dir: /opt/starrocks/fe + - host: 192.168.88.83 + ssh_port: 22 + query_port: 9030 + deploy_dir: /opt/starrocks/fe + - host: 192.168.88.84 + ssh_port: 22 + query_port: 9030 + deploy_dir: /opt/starrocks/fe + - host: 192.168.88.85 + ssh_port: 22 + query_port: 9030 + deploy_dir: /opt/starrocks/fe be_servers: -- host: 192.168.88.83 - ssh_port: 22 - heartbeat_service_port: 9050 - deploy_dir: /opt/starrocks/be -- host: 192.168.88.84 - ssh_port: 22 - heartbeat_service_port: 9050 - deploy_dir: /opt/starrocks/be -- host: 192.168.88.85 - ssh_port: 22 - heartbeat_service_port: 9050 - deploy_dir: /opt/starrocks/be + - host: 192.168.88.83 + ssh_port: 22 + heartbeat_service_port: 9050 + deploy_dir: /opt/starrocks/be + - host: 192.168.88.84 + ssh_port: 22 + heartbeat_service_port: 9050 + deploy_dir: /opt/starrocks/be + - host: 192.168.88.85 + ssh_port: 22 + heartbeat_service_port: 9050 + deploy_dir: /opt/starrocks/be diff --git a/install-local.sh b/install-local.sh new file mode 100755 index 0000000..1b1f671 --- /dev/null +++ b/install-local.sh @@ -0,0 +1,211 @@ +#!/bin/bash + +# StarGo 本地安装脚本 +# 用于从当前构建目录安装 StarGo + +set -e + +# 颜色定义 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# 打印带颜色的消息 +print_message() { + local color=$1 + local message=$2 + echo -e "${color}${message}${NC}" +} + +print_header() { + echo + print_message $BLUE "==========================================" + print_message $BLUE " StarGo 本地安装脚本" + print_message $BLUE " StarRocks 集群管理工具" + print_message $BLUE "==========================================" + echo +} + +# 检测操作系统和架构 +detect_platform() { + local os=$(uname -s | tr '[:upper:]' '[:lower:]') + local arch=$(uname -m) + + case $os in + linux) + OS="linux" + ;; + darwin) + OS="darwin" + ;; + *) + print_message $RED "错误: 不支持的操作系统 $os" + exit 1 + ;; + esac + + case $arch in + x86_64|amd64) + ARCH="amd64" + ;; + arm64|aarch64) + ARCH="arm64" + ;; + *) + print_message $RED "错误: 不支持的架构 $arch" + exit 1 + ;; + esac + + PLATFORM="${OS}-${ARCH}" + print_message $GREEN "检测到平台: $PLATFORM" +} + +# 检查依赖 +check_dependencies() { + print_message $YELLOW "检查依赖..." + + if ! command -v curl >/dev/null 2>&1; then + print_message $RED "错误: 需要安装 curl" + exit 1 + fi +} + +# 查找可执行文件 +find_executable() { + local current_dir=$(pwd) + + # 检查当前目录的可执行文件 + if [[ -f "$current_dir/stargo" ]]; then + EXECUTABLE="$current_dir/stargo" + print_message $GREEN "找到可执行文件: $EXECUTABLE" + return 0 + fi + + # 检查 dist 目录 + local dist_file="$current_dir/dist/stargo-$PLATFORM" + if [[ "$OS" == "windows" ]]; then + dist_file="${dist_file}.exe" + fi + + if [[ -f "$dist_file" ]]; then + EXECUTABLE="$dist_file" + print_message $GREEN "找到可执行文件: $EXECUTABLE" + return 0 + fi + + print_message $RED "错误: 未找到 StarGo 可执行文件" + print_message $YELLOW "请先运行以下命令之一构建项目:" + print_message $YELLOW " make build" + print_message $YELLOW " ./build.sh" + print_message $YELLOW " go build -o stargo ." + exit 1 +} + +# 安装到系统 +install_to_system() { + local install_dir="/usr/local/bin" + local target_file="$install_dir/stargo" + + print_message $YELLOW "安装到 $install_dir..." + + # 检查是否需要 sudo + if [[ ! -w "$install_dir" ]]; then + print_message $YELLOW "需要管理员权限安装到系统目录" + sudo cp "$EXECUTABLE" "$target_file" + sudo chmod +x "$target_file" + else + cp "$EXECUTABLE" "$target_file" + chmod +x "$target_file" + fi + + print_message $GREEN "安装完成!" +} + +# 验证安装 +verify_installation() { + print_message $YELLOW "验证安装..." + + if command -v stargo >/dev/null 2>&1; then + print_message $GREEN "✓ StarGo 安装成功!" + echo + print_message $BLUE "版本信息:" + stargo version + echo + print_message $BLUE "使用方法:" + print_message $YELLOW " stargo help # 查看帮助" + print_message $YELLOW " stargo version # 查看版本" + print_message $YELLOW " stargo cluster # 集群管理" + else + print_message $RED "✗ 安装验证失败" + print_message $YELLOW "请检查 /usr/local/bin 是否在 PATH 中" + exit 1 + fi +} + +# 卸载 +uninstall() { + local install_file="/usr/local/bin/stargo" + + if [[ -f "$install_file" ]]; then + print_message $YELLOW "卸载 StarGo..." + if [[ ! -w "/usr/local/bin" ]]; then + sudo rm -f "$install_file" + else + rm -f "$install_file" + fi + print_message $GREEN "✓ StarGo 已卸载" + else + print_message $YELLOW "StarGo 未安装" + fi +} + +# 显示帮助 +show_help() { + echo "StarGo 本地安装脚本" + echo + echo "用法:" + echo " $0 [选项]" + echo + echo "选项:" + echo " -h, --help 显示此帮助信息" + echo " -u, --uninstall 卸载 StarGo" + echo + echo "示例:" + echo " $0 # 安装 StarGo" + echo " $0 --uninstall # 卸载 StarGo" + echo +} + +# 主函数 +main() { + case "${1:-}" in + -h|--help) + show_help + exit 0 + ;; + -u|--uninstall) + print_header + uninstall + exit 0 + ;; + "") + print_header + detect_platform + check_dependencies + find_executable + install_to_system + verify_installation + ;; + *) + print_message $RED "错误: 未知选项 $1" + show_help + exit 1 + ;; + esac +} + +# 运行主函数 +main "$@" \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..cb19a59 --- /dev/null +++ b/install.sh @@ -0,0 +1,204 @@ +#!/bin/bash + +# StarGo 安装脚本 +# 用于快速安装 StarGo - StarRocks 集群管理工具 + +set -e + +# 颜色定义 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# 项目信息 +PROJECT_NAME="stargo" +GITHUB_REPO="your-username/stargo" # 请替换为实际的 GitHub 仓库 +INSTALL_DIR="/usr/local/bin" + +# 检测系统架构 +detect_platform() { + local os=$(uname -s | tr '[:upper:]' '[:lower:]') + local arch=$(uname -m) + + case $os in + linux*) + OS="linux" + ;; + darwin*) + OS="darwin" + ;; + *) + echo -e "${RED}错误: 不支持的操作系统 $os${NC}" + exit 1 + ;; + esac + + case $arch in + x86_64|amd64) + ARCH="amd64" + ;; + arm64|aarch64) + ARCH="arm64" + ;; + *) + echo -e "${RED}错误: 不支持的架构 $arch${NC}" + exit 1 + ;; + esac + + PLATFORM="${OS}-${ARCH}" + echo -e "${BLUE}检测到平台: ${PLATFORM}${NC}" +} + +# 检查依赖 +check_dependencies() { + echo -e "${BLUE}检查依赖...${NC}" + + if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then + echo -e "${RED}错误: 需要 curl 或 wget 来下载文件${NC}" + exit 1 + fi + + if ! command -v tar >/dev/null 2>&1; then + echo -e "${RED}错误: 需要 tar 来解压文件${NC}" + exit 1 + fi +} + +# 获取最新版本 +get_latest_version() { + echo -e "${BLUE}获取最新版本信息...${NC}" + + if command -v curl >/dev/null 2>&1; then + VERSION=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + elif command -v wget >/dev/null 2>&1; then + VERSION=$(wget -qO- "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + fi + + if [ -z "$VERSION" ]; then + echo -e "${YELLOW}警告: 无法获取最新版本,使用默认版本 v1.0.0${NC}" + VERSION="v1.0.0" + fi + + echo -e "${GREEN}最新版本: ${VERSION}${NC}" +} + +# 下载文件 +download_file() { + local url=$1 + local output=$2 + + echo -e "${BLUE}下载 ${url}...${NC}" + + if command -v curl >/dev/null 2>&1; then + curl -L -o "$output" "$url" + elif command -v wget >/dev/null 2>&1; then + wget -O "$output" "$url" + else + echo -e "${RED}错误: 无法下载文件${NC}" + exit 1 + fi +} + +# 安装 stargo +install_stargo() { + local binary_name="${PROJECT_NAME}-${PLATFORM}" + local download_url="https://github.com/${GITHUB_REPO}/releases/download/${VERSION}/${binary_name}" + local temp_file="/tmp/${binary_name}" + + echo -e "${BLUE}开始安装 StarGo ${VERSION}...${NC}" + + # 下载二进制文件 + download_file "$download_url" "$temp_file" + + # 检查文件是否下载成功 + if [ ! -f "$temp_file" ]; then + echo -e "${RED}错误: 下载失败${NC}" + exit 1 + fi + + # 设置执行权限 + chmod +x "$temp_file" + + # 移动到安装目录 + echo -e "${BLUE}安装到 ${INSTALL_DIR}...${NC}" + sudo mv "$temp_file" "${INSTALL_DIR}/${PROJECT_NAME}" + + echo -e "${GREEN}安装完成!${NC}" +} + +# 验证安装 +verify_installation() { + echo -e "${BLUE}验证安装...${NC}" + + if command -v $PROJECT_NAME >/dev/null 2>&1; then + echo -e "${GREEN}✓ StarGo 安装成功!${NC}" + echo -e "${BLUE}版本信息:${NC}" + $PROJECT_NAME version + else + echo -e "${RED}✗ 安装失败,请检查 ${INSTALL_DIR} 是否在 PATH 中${NC}" + exit 1 + fi +} + +# 显示使用说明 +show_usage() { + echo -e "${GREEN}" + echo "==========================================" + echo " StarGo 安装完成!" + echo "==========================================" + echo -e "${NC}" + echo "使用方法:" + echo " stargo version - 查看版本信息" + echo " stargo help - 查看帮助信息" + echo " stargo playground - 运行 playground" + echo " stargo cluster deploy - 部署集群" + echo "" + echo "更多信息请访问: https://github.com/${GITHUB_REPO}" +} + +# 卸载函数 +uninstall_stargo() { + echo -e "${YELLOW}卸载 StarGo...${NC}" + + if [ -f "${INSTALL_DIR}/${PROJECT_NAME}" ]; then + sudo rm -f "${INSTALL_DIR}/${PROJECT_NAME}" + echo -e "${GREEN}StarGo 已卸载${NC}" + else + echo -e "${YELLOW}StarGo 未安装${NC}" + fi +} + +# 主函数 +main() { + echo -e "${GREEN}" + echo "==========================================" + echo " StarGo 安装脚本" + echo " StarRocks 集群管理工具" + echo "==========================================" + echo -e "${NC}" + + # 检查参数 + if [ "$1" = "uninstall" ]; then + uninstall_stargo + exit 0 + fi + + # 检查是否为 root 用户(需要 sudo 权限) + if [ "$EUID" -eq 0 ]; then + echo -e "${YELLOW}警告: 不建议以 root 用户运行此脚本${NC}" + fi + + # 执行安装步骤 + detect_platform + check_dependencies + get_latest_version + install_stargo + verify_installation + show_usage +} + +# 运行主函数 +main "$@" \ No newline at end of file diff --git a/jdk/manager.go b/jdk/manager.go new file mode 100644 index 0000000..0c6f055 --- /dev/null +++ b/jdk/manager.go @@ -0,0 +1,101 @@ +package jdk + +import ( + "fmt" + "os" + "strings" +) + +// Info holds the expected layout information for a supported JDK bundle. +type Info struct { + DeployDirName string + PlaygroundDir string + DownloadFolder string + TarballName string + DownloadURL string +} + +var jdkLayouts = map[string]Info{ + "8": { + DeployDirName: "jdk", + PlaygroundDir: "jdk1.8.0", + DownloadFolder: "jdk1.8.0_301", + TarballName: "jdk-8u301-linux-x64.tar.gz", + }, + "11": { + DeployDirName: "jdk11", + PlaygroundDir: "jdk11", + DownloadFolder: "jdk11.0.18", + TarballName: "jdk-11.0.18_linux-x64_bin.tar.gz", + }, + "17": { + DeployDirName: "jdk17", + PlaygroundDir: "jdk17", + DownloadFolder: "jdk17.0.8", + TarballName: "jdk-17.0.8_linux-x64_bin.tar.gz", + DownloadURL: "https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz", + }, +} + +// resolveInfo returns layout info for the requested version, falling back to the legacy JDK8 layout. +func resolveInfo(jdkVersion string) Info { + key := strings.TrimSpace(strings.ToLower(jdkVersion)) + key = strings.TrimPrefix(key, "jdk") + switch { + case strings.HasPrefix(key, "17"): + return jdkLayouts["17"] + case strings.HasPrefix(key, "11"): + return jdkLayouts["11"] + default: + return jdkLayouts["8"] + } +} + +// ResolveInfo exposes layout information for the requested JDK version. +func ResolveInfo(jdkVersion string) Info { + return resolveInfo(jdkVersion) +} + +// ResolveJDKHomeForDeploy returns the JAVA_HOME path used in deployment scripts. +func ResolveJDKHomeForDeploy(deployDir string, jdkVersion string, jdkHome string) string { + if strings.TrimSpace(jdkHome) != "" { + return jdkHome + } + info := resolveInfo(jdkVersion) + return fmt.Sprintf("%s/%s", deployDir, info.DeployDirName) +} + +// ResolvePlaygroundDir returns the playground JDK directory name. +func ResolvePlaygroundDir(jdkVersion string) string { + info := resolveInfo(jdkVersion) + return info.PlaygroundDir +} + +// Exists checks whether a given path exists. +func Exists(path string) bool { + _, err := os.Stat(path) + return err == nil +} + +// SelectDownloadFolderName decides which JDK folder name is expected in download cache. +// This provides a convention used by PreparePlaygroundDir to pick the right source. +func SelectDownloadFolderName(jdkVersion string) string { + info := resolveInfo(jdkVersion) + return info.DownloadFolder +} + +// SelectTarballName returns the tarball file name packaged inside the quickstart archive. +func SelectTarballName(jdkVersion string) string { + info := resolveInfo(jdkVersion) + return info.TarballName +} + +// DownloadOrPrepare is a placeholder for future JDK acquisition (download/decompress). +// For now, the project uses external logic to populate download cache. +func DownloadOrPrepare(jdkVersion string) (string, error) { + src := SelectDownloadFolderName(jdkVersion) + if strings.TrimSpace(src) == "" { + return src, fmt.Errorf("empty jdk source folder name") + } + return src, nil +} diff --git a/main.go b/main.go index fecf78f..7761afb 100644 --- a/main.go +++ b/main.go @@ -1,162 +1,212 @@ package main import ( + "flag" + "fmt" + "os" + "stargo/cluster/clusterOption" + "stargo/playground" + "stargo/sr-utl" + //"stargo/cluster/checkStatus" + // "stargo/module" + //"stargo/cluster/prepareOption" +) - "fmt" - "os" - "flag" - "stargo/sr-utl" - "stargo/playground" - "stargo/cluster/clusterOption" - //"stargo/cluster/checkStatus" - // "stargo/module" - //"stargo/cluster/prepareOption" - +// 版本信息变量,在构建时通过 ldflags 注入 +var ( + Version = "v2.4.0" + BuildTime = "unknown" + GitCommit = "unknown" ) + +// 显示版本信息 +func showVersion() { + fmt.Printf("stargo version %s\n", Version) + fmt.Printf("Build time: %s\n", BuildTime) + fmt.Printf("Git commit: %s\n", GitCommit) + fmt.Printf("Go version: %s\n", "1.25.0") +} func main() { - // sr-ctl-cluster deploy sr-c1 v2.0.1 /tmp/sr-c1.yaml - // sr-ctl-cluster start sr-c1 - // sr-ctl-cluster stop sr-c1 - // sr-ctl-cluster display sr-c1 - - // sr-ctl playground v2.0.1 - - - var component string - var command string - var clusterName string - var clusterVersion string - var metaFile string - var infoMess string - var node string - var role string - var firstArgWithDash int - - component = os.Args[1] - //command = os.Args[2] - - - switch component { - - case "playground": - playground.RunPlayground() - case "cluster": - command = os.Args[2] - switch command { - - case "deploy": - clusterName = os.Args[3] - clusterVersion = os.Args[4] - metaFile = os.Args[5] - infoMess = fmt.Sprintf("Deploy cluster [clusterName = %s, clusterVersion = %s, metaFile = %s]\n", clusterName, clusterVersion, metaFile) - utl.Log("OUTPUT", infoMess) - clusterOption.Deploy(clusterName, clusterVersion, metaFile) - - case "start": - clusterName = os.Args[3] - infoMess = fmt.Sprintf("Start cluster [clusterName = %s]", clusterName) - utl.Log("OUTPUT", infoMess) - firstArgWithDash = 1 - for i := 1; i < len(os.Args); i++ { - firstArgWithDash = i - if len(os.Args[i]) > 0 && os.Args[i][0] == '-' { - break - } - } - flag.StringVar(&node, "node", "", "The Node ID. Use display command to check the node id.") - flag.StringVar(&role, "role", "", "The start component type. You can input FE or BE.") - flag.CommandLine.Parse(os.Args[firstArgWithDash:]) - clusterOption.Start(clusterName, node, role) - - case "stop": - clusterName = os.Args[3] - infoMess = fmt.Sprintf("Stop cluster [clusterName = %s]", clusterName) - utl.Log("OUTPUT", infoMess) - firstArgWithDash = 1 - for i := 1; i < len(os.Args); i++ { - firstArgWithDash = i - if len(os.Args[i]) > 0 && os.Args[i][0] == '-' { - break - } - } - flag.StringVar(&node, "node", "", "The Node ID. Use display command to check the node id.") - flag.StringVar(&role, "role", "", "The start component type. You can input FE or BE.") - flag.CommandLine.Parse(os.Args[firstArgWithDash:]) - clusterOption.Stop(clusterName, node, role) - - case "display": - clusterName = os.Args[3] - infoMess = fmt.Sprintf("Display cluster [clusterName = %s]", clusterName) - utl.Log("OUTPUT", infoMess) - clusterOption.Display(clusterName) - - case "list": - infoMess = fmt.Sprintf("List all clusters") - utl.Log("OUTPUT", infoMess) - clusterOption.List() - - case "destroy": - clusterName = os.Args[3] - infoMess = fmt.Sprintf("Destroy cluster. [ClusterName = %s]", clusterName) - utl.Log("OUTPUT", infoMess) - clusterOption.Destroy(clusterName) - - case "upgrade": - clusterName = os.Args[3] - clusterVersion = os.Args[4] - infoMess = fmt.Sprintf("Upgrade cluster. [ClusterName = %s, TargetVersion = %s]", clusterName, clusterVersion) - utl.Log("OUTPUT", infoMess) - clusterOption.Upgrade(clusterName, clusterVersion) - - case "downgrade": - clusterName = os.Args[3] - clusterVersion = os.Args[4] - infoMess = fmt.Sprintf("Downgrade cluster. [ClusterName = %s, TargetVersion = %s]", clusterName, clusterVersion) - utl.Log("OUTPUT", infoMess) - clusterOption.Downgrade(clusterName, clusterVersion) - - case "scale-out": - clusterName = os.Args[3] - //clusterVersion = os.Args[4] - metaFile = os.Args[4] - infoMess = fmt.Sprintf("Scale out cluster. [ClusterName = %s]", clusterName) - utl.Log("OUTPUT", infoMess) - clusterOption.ScaleOut(clusterName, metaFile) - - case "scale-in": - clusterName = os.Args[3] - firstArgWithDash = 1 - for i := 1; i < len(os.Args); i++ { - firstArgWithDash = i - if len(os.Args[i]) > 0 && os.Args[i][0] == '-' { - break - } - } - flag.StringVar(&node, "node", "", "The Node ID. Use display command to check the node id.") - flag.CommandLine.Parse(os.Args[firstArgWithDash:]) - infoMess = fmt.Sprintf("Scale in cluster [clusterName = %s, nodeId = %s]", clusterName, node) - utl.Log("OUTPUT", infoMess) - clusterOption.ScaleIn(clusterName, node) - - case "import": - clusterName = os.Args[3] - metaFile = os.Args[4] - infoMess = fmt.Sprintf("Import the cluster [clusterName = %s, metaFile = %s]", clusterName, metaFile) - utl.Log("OUTPUT", infoMess) - clusterOption.ImportCluster(clusterName, metaFile) - case "test": - utl.Log("OUTPUT", "TEST >>>>>>>>>") - // checkStatus.TestFeStatus() - //prepareOption.TestPreCheck() - //prepareOption.PreCheckSR() - //playground.DeployPlayground() - default: - infoMess = fmt.Sprintf("ERROR, sr-ctl-cluster don't support %s option", command) - utl.Log("ERROR", infoMess) - } // end of switch command, end of case cluster + // sr-ctl-cluster deploy sr-c1 v2.0.1 /tmp/sr-c1.yaml + // sr-ctl-cluster start sr-c1 + // sr-ctl-cluster stop sr-c1 + // sr-ctl-cluster display sr-c1 + + // sr-ctl playground v2.0.1 + + var component string + var command string + var clusterName string + var clusterVersion string + var metaFile string + var infoMess string + var node string + var role string + var firstArgWithDash int + + // 检查参数数量 + if len(os.Args) < 2 { + fmt.Printf("stargo - StarRocks 集群管理工具\n\n") + fmt.Printf("使用方法:\n") + fmt.Printf(" stargo [options]\n\n") + fmt.Printf("组件:\n") + fmt.Printf(" playground - 运行 playground 模式\n") + fmt.Printf(" cluster - 集群管理\n") + fmt.Printf(" version - 显示版本信息\n") + fmt.Printf(" help - 显示帮助信息\n\n") + fmt.Printf("集群管理命令:\n") + fmt.Printf(" stargo cluster deploy - 部署集群\n") + fmt.Printf(" stargo cluster start - 启动集群\n") + fmt.Printf(" stargo cluster stop - 停止集群\n") + fmt.Printf(" stargo cluster display - 显示集群状态\n") + fmt.Printf(" stargo cluster list - 列出所有集群\n") + fmt.Printf(" stargo cluster destroy - 销毁集群\n") + fmt.Printf(" stargo cluster upgrade - 升级集群\n") + fmt.Printf(" stargo cluster downgrade - 降级集群\n") + fmt.Printf(" stargo cluster scale-out - 扩容集群\n") + fmt.Printf(" stargo cluster scale-in -node - 缩容集群\n") + fmt.Printf(" stargo cluster import - 导入集群\n\n") + fmt.Printf("示例:\n") + fmt.Printf(" stargo playground\n") + fmt.Printf(" stargo cluster deploy sr-c1 v2.2.0 /tmp/sr-c1.yaml\n") + fmt.Printf(" stargo cluster start sr-c1\n") + fmt.Printf(" stargo version\n") + os.Exit(0) + } + + component = os.Args[1] + //command = os.Args[2] + + switch component { + + case "version", "-v", "--version": + showVersion() + return + + case "help", "-h", "--help": + fmt.Printf("stargo - StarRocks 集群管理工具\n\n") + fmt.Printf("详细使用方法请运行: stargo\n") + return + + case "playground": + playground.RunPlayground() + case "cluster": + command = os.Args[2] + switch command { + + case "deploy": + clusterName = os.Args[3] + clusterVersion = os.Args[4] + metaFile = os.Args[5] + infoMess = fmt.Sprintf("Deploy cluster [clusterName = %s, clusterVersion = %s, metaFile = %s]\n", clusterName, clusterVersion, metaFile) + utl.Log("OUTPUT", infoMess) + clusterOption.Deploy(clusterName, clusterVersion, metaFile) + + case "start": + clusterName = os.Args[3] + infoMess = fmt.Sprintf("Start cluster [clusterName = %s]", clusterName) + utl.Log("OUTPUT", infoMess) + firstArgWithDash = 1 + for i := 1; i < len(os.Args); i++ { + firstArgWithDash = i + if len(os.Args[i]) > 0 && os.Args[i][0] == '-' { + break + } + } + flag.StringVar(&node, "node", "", "The Node ID. Use display command to check the node id.") + flag.StringVar(&role, "role", "", "The start component type. You can input FE or BE.") + flag.CommandLine.Parse(os.Args[firstArgWithDash:]) + clusterOption.Start(clusterName, node, role) + + case "stop": + clusterName = os.Args[3] + infoMess = fmt.Sprintf("Stop cluster [clusterName = %s]", clusterName) + utl.Log("OUTPUT", infoMess) + firstArgWithDash = 1 + for i := 1; i < len(os.Args); i++ { + firstArgWithDash = i + if len(os.Args[i]) > 0 && os.Args[i][0] == '-' { + break + } + } + flag.StringVar(&node, "node", "", "The Node ID. Use display command to check the node id.") + flag.StringVar(&role, "role", "", "The start component type. You can input FE or BE.") + flag.CommandLine.Parse(os.Args[firstArgWithDash:]) + clusterOption.Stop(clusterName, node, role) + + case "display": + clusterName = os.Args[3] + infoMess = fmt.Sprintf("Display cluster [clusterName = %s]", clusterName) + utl.Log("OUTPUT", infoMess) + clusterOption.Display(clusterName) + + case "list": + infoMess = fmt.Sprintf("List all clusters") + utl.Log("OUTPUT", infoMess) + clusterOption.List() + + case "destroy": + clusterName = os.Args[3] + infoMess = fmt.Sprintf("Destroy cluster. [ClusterName = %s]", clusterName) + utl.Log("OUTPUT", infoMess) + clusterOption.Destroy(clusterName) + + case "upgrade": + clusterName = os.Args[3] + clusterVersion = os.Args[4] + infoMess = fmt.Sprintf("Upgrade cluster. [ClusterName = %s, TargetVersion = %s]", clusterName, clusterVersion) + utl.Log("OUTPUT", infoMess) + clusterOption.Upgrade(clusterName, clusterVersion) + + case "downgrade": + clusterName = os.Args[3] + clusterVersion = os.Args[4] + infoMess = fmt.Sprintf("Downgrade cluster. [ClusterName = %s, TargetVersion = %s]", clusterName, clusterVersion) + utl.Log("OUTPUT", infoMess) + clusterOption.Downgrade(clusterName, clusterVersion) + + case "scale-out": + clusterName = os.Args[3] + //clusterVersion = os.Args[4] + metaFile = os.Args[4] + infoMess = fmt.Sprintf("Scale out cluster. [ClusterName = %s]", clusterName) + utl.Log("OUTPUT", infoMess) + clusterOption.ScaleOut(clusterName, metaFile) + + case "scale-in": + clusterName = os.Args[3] + firstArgWithDash = 1 + for i := 1; i < len(os.Args); i++ { + firstArgWithDash = i + if len(os.Args[i]) > 0 && os.Args[i][0] == '-' { + break + } + } + flag.StringVar(&node, "node", "", "The Node ID. Use display command to check the node id.") + flag.CommandLine.Parse(os.Args[firstArgWithDash:]) + infoMess = fmt.Sprintf("Scale in cluster [clusterName = %s, nodeId = %s]", clusterName, node) + utl.Log("OUTPUT", infoMess) + clusterOption.ScaleIn(clusterName, node) + + case "import": + clusterName = os.Args[3] + metaFile = os.Args[4] + infoMess = fmt.Sprintf("Import the cluster [clusterName = %s, metaFile = %s]", clusterName, metaFile) + utl.Log("OUTPUT", infoMess) + clusterOption.ImportCluster(clusterName, metaFile) + case "test": + utl.Log("OUTPUT", "TEST >>>>>>>>>") + // checkStatus.TestFeStatus() + //prepareOption.TestPreCheck() + //prepareOption.PreCheckSR() + //playground.DeployPlayground() + default: + infoMess = fmt.Sprintf("ERROR, sr-ctl-cluster don't support %s option", command) + utl.Log("ERROR", infoMess) + } // end of switch command, end of case cluster default: - fmt.Printf("ERROR component input.\n") - } // end of switch component + fmt.Printf("ERROR component input.\n") + } // end of switch component } diff --git a/module/.yamlConfigModule.go.swp b/module/.yamlConfigModule.go.swp deleted file mode 100644 index 800ccc2..0000000 Binary files a/module/.yamlConfigModule.go.swp and /dev/null differ diff --git a/module/yamlConfigModule.go b/module/yamlConfigModule.go index ba258d8..543c451 100644 --- a/module/yamlConfigModule.go +++ b/module/yamlConfigModule.go @@ -1,358 +1,448 @@ package module - import ( - "io/ioutil" - "gopkg.in/yaml.v2" - "fmt" - "os" - "os/user" - "time" - "strings" - "errors" - "stargo/sr-utl" + "errors" + "fmt" + "io/ioutil" + "os" + "os/user" + "stargo/jdk" + "stargo/sr-utl" + "strconv" + "strings" + "time" + + "gopkg.in/yaml.v2" ) - - const NULLSTR = "" +const DefaultCloudNativeMetaPort = "6090" + +var GClusterName string +var GYamlConf *ConfStruct +var GYamlConfAppend *ConfStruct +var GSshKeyRsa string +var GSRCtlRoot string +var GSRVersion string +var GWriteBackMetaPath string +var GJdbcUser string +var GJdbcPasswd string +var GJdbcDb string +var GFeEntryHost string +var GFeEntryQueryPort int +var GFeEntryEditLogPort int +var GRepo *RepoStruct +var GDownloadPath string -var GClusterName string -var GYamlConf *ConfStruct -var GYamlConfAppend *ConfStruct -var GSshKeyRsa string -var GSRCtlRoot string -var GSRVersion string -var GWriteBackMetaPath string -var GJdbcUser string -var GJdbcPasswd string -var GJdbcDb string -var GFeEntryHost string -var GFeEntryQueryPort int -var GFeEntryEditLogPort int -var GRepo *RepoStruct -var GDownloadPath string - - - - type RepoStruct struct { - Repo string `yaml:"repo"` + Repo string `yaml:"repo"` } - type ConfStruct struct { - - ClusterInfo struct { - User string `yaml:"user"` - Version string `yaml:"version"` - CreateDate string `yaml:"create_date"` - MetaPath string `yaml:"meta_path"` - PrivateKey string `yaml:"private_key"` - } `yaml:"clusterinfo"` - - Global struct { - User string `yaml:"user"` - SshPort int `yaml:"ssh_port"` - } `yaml:"global"` - - ServerConfig struct { - Fe map[string]string `yaml:"fe"` - Be map[string]string `yaml:"be"` - } `yaml:"server_configs"` - - FeServers []struct { - Host string `yaml:"host"` - SshPort int `yaml:"ssh_port"` - HttpPort int `yaml:"http_port"` - RpcPort int `yaml:"rpc_port"` - QueryPort int `yaml:"query_port"` - EditLogPort int `yaml:"edit_log_port"` - DeployDir string `yaml:"deploy_dir"` - MetaDir string `yaml:"meta_dir"` - LogDir string `yaml:"log_dir"` - PriorityNetworks string `yaml:"priority_networks"` - Config map[string]string `yaml:"config"` - } `yaml:"fe_servers"` - - BeServers []struct { - Host string `yaml:"host"` - SshPort int `yaml:"ssh_port"` - BePort int `yaml:"be_port"` - WebServerPort int `yaml:"webserver_port"` - HeartbeatServicePort int `yaml:"heartbeat_service_port"` - BrpcPort int `yaml:"brpc_port"` - DeployDir string `yaml:"deploy_dir"` - StorageDir string `yaml:"storage_dir"` - LogDir string `yaml:"log_dir"` - PriorityNetworks string `yaml:"priority_networks"` - Config map[string]string `yaml:"configs` - } `yaml:"be_servers"` - - PrometheusServer struct { - Host string `yaml:"host"` - SshPort int `yaml:"ssh_port"` - HttpPort int `yaml:"http_port"` - DeployDir string `yaml:"deploy_dir"` - DataDir string `yaml:"data_dir"` - LogDir string `yaml:"log_dir"` - } `yaml:"prometheus_servers"` - - GrafanaServer struct { - Host string `yaml:"host"` - SshPort int `yaml:"ssh_port"` - HttpPort int `yaml:"http_port"` - DeployDir string `yaml:"deploy_dir"` - } `yaml:"grafana_servers"` - - AlertManagerServer struct { - Host string `yaml:"host"` - SshPort int `yaml:"ssh_port"` - WebPort int `yaml:"web_port"` - ClusterPort int `yaml:"cluster_port"` - DeployDir string `yaml:"deploy_dir"` - DataDir string `yaml:"data_dir"` - LogDir string `yaml:"log_dir"` - } `yaml:"alertmanager_servers"` + ClusterInfo struct { + User string `yaml:"user"` + Version string `yaml:"version"` + CreateDate string `yaml:"create_date"` + MetaPath string `yaml:"meta_path"` + PrivateKey string `yaml:"private_key"` + } `yaml:"clusterinfo"` + + Global struct { + User string `yaml:"user"` + SshPort int `yaml:"ssh_port"` + JDKVersion string `yaml:"jdk_version"` + JDKHome string `yaml:"jdk_home"` + OSType string `yaml:"os_type"` + } `yaml:"global"` + + ServerConfig struct { + Fe map[string]string `yaml:"fe"` + Be map[string]string `yaml:"be"` + } `yaml:"server_configs"` + + FeServers []struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + HttpPort int `yaml:"http_port"` + RpcPort int `yaml:"rpc_port"` + QueryPort int `yaml:"query_port"` + EditLogPort int `yaml:"edit_log_port"` + DeployDir string `yaml:"deploy_dir"` + MetaDir string `yaml:"meta_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + Config map[string]string `yaml:"config"` + } `yaml:"fe_servers"` + + BeServers []struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + BePort int `yaml:"be_port"` + WebServerPort int `yaml:"webserver_port"` + HeartbeatServicePort int `yaml:"heartbeat_service_port"` + BrpcPort int `yaml:"brpc_port"` + DeployDir string `yaml:"deploy_dir"` + StorageDir string `yaml:"storage_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + Config map[string]string `yaml:"config"` + } `yaml:"be_servers"` + + CnServers []struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + BePort int `yaml:"be_port"` + WebServerPort int `yaml:"webserver_port"` + HeartbeatServicePort int `yaml:"heartbeat_service_port"` + BrpcPort int `yaml:"brpc_port"` + StarletPort int `yaml:"starlet_port"` + DeployDir string `yaml:"deploy_dir"` + StorageDir string `yaml:"storage_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + WarehouseName string `yaml:"warehouse_name"` + Config map[string]string `yaml:"config"` + } `yaml:"cn_servers"` + + PrometheusServer struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + HttpPort int `yaml:"http_port"` + DeployDir string `yaml:"deploy_dir"` + DataDir string `yaml:"data_dir"` + LogDir string `yaml:"log_dir"` + } `yaml:"prometheus_servers"` + + GrafanaServer struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + HttpPort int `yaml:"http_port"` + DeployDir string `yaml:"deploy_dir"` + } `yaml:"grafana_servers"` + + AlertManagerServer struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + WebPort int `yaml:"web_port"` + ClusterPort int `yaml:"cluster_port"` + DeployDir string `yaml:"deploy_dir"` + DataDir string `yaml:"data_dir"` + LogDir string `yaml:"log_dir"` + } `yaml:"alertmanager_servers"` } - func (rr *RepoStruct) getRepo() *RepoStruct { - - repoFile, err := ioutil.ReadFile("repo.yaml") - if err != nil { panic(err) } - err = yaml.Unmarshal(repoFile, rr) - if err != nil { panic(err) } + repoFile, err := ioutil.ReadFile("repo.yaml") + if err != nil { + panic(err) + } + + err = yaml.Unmarshal(repoFile, rr) + if err != nil { + panic(err) + } - return rr + return rr } func GetRepo() { - var rp RepoStruct - GRepo = rp.getRepo() + var rp RepoStruct + GRepo = rp.getRepo() - if strings.Contains(GRepo.Repo, "file://") { - GDownloadPath = strings.Replace(GRepo.Repo, "file://", "", -1) - } else { - GDownloadPath = GSRCtlRoot + "/download" - } + if strings.Contains(GRepo.Repo, "file://") { + GDownloadPath = strings.Replace(GRepo.Repo, "file://", "", -1) + } else { + GDownloadPath = GSRCtlRoot + "/download" + } } - func (cc *ConfStruct) GetConf(fileName string) *ConfStruct { - yamlFile, err := ioutil.ReadFile(fileName) - if err != nil { panic(err) } + yamlFile, err := ioutil.ReadFile(fileName) + if err != nil { + panic(err) + } - err = yaml.Unmarshal(yamlFile, cc) - if err != nil { panic(err) } + err = yaml.Unmarshal(yamlFile, cc) + if err != nil { + panic(err) + } - return cc + return cc } - - - func InitConf(clusterName string, fileName string) { - var confS ConfStruct + var confS ConfStruct - // get home dir & ssh auth key - osUser, _ := user.Current() - GSshKeyRsa = fmt.Sprintf("%s/.ssh/id_rsa", osUser.HomeDir) + // get home dir & ssh auth key + osUser, _ := user.Current() + GSshKeyRsa = fmt.Sprintf("%s/.ssh/id_rsa", osUser.HomeDir) - // get sr-ctl root dir - GSRCtlRoot = os.Getenv("SRCTLROOT") - if GSRCtlRoot == "" { - GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) - } + // get sr-ctl root dir + GSRCtlRoot = os.Getenv("SRCTLROOT") + if GSRCtlRoot == "" { + GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) + } - // get the write back meta path - GClusterName = clusterName - GWriteBackMetaPath = fmt.Sprintf("%s/cluster/%s", GSRCtlRoot, GClusterName) + // get the write back meta path + GClusterName = clusterName + GWriteBackMetaPath = fmt.Sprintf("%s/cluster/%s", GSRCtlRoot, GClusterName) - // get the FE jdbc connection parameters - GJdbcUser = "root" - GJdbcPasswd = "" - GJdbcDb = "" + // get the FE jdbc connection parameters + GJdbcUser = "root" + GJdbcPasswd = "" + GJdbcDb = "" - // parse config yaml file - if fileName == "" { - GYamlConf = confS.GetConf(GWriteBackMetaPath + "/meta.yaml") - } else { - GYamlConf = confS.GetConf(fileName) - } + // parse config yaml file + if fileName == "" { + GYamlConf = confS.GetConf(GWriteBackMetaPath + "/meta.yaml") + } else { + GYamlConf = confS.GetConf(fileName) + } } - - func AppendConf(clusterName string) { - var confS ConfStruct - var metaFile string + var confS ConfStruct + var metaFile string - osUser, _ := user.Current() - GSshKeyRsa = fmt.Sprintf("%s/.ssh/id_rsa", osUser.HomeDir) - GSRCtlRoot = os.Getenv("SRCTLROOT") - if GSRCtlRoot == "" { - GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) - } - metaFile = fmt.Sprintf("%s/cluster/%s/meta.yaml", GSRCtlRoot, clusterName) + osUser, _ := user.Current() + GSshKeyRsa = fmt.Sprintf("%s/.ssh/id_rsa", osUser.HomeDir) + GSRCtlRoot = os.Getenv("SRCTLROOT") + if GSRCtlRoot == "" { + GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) + } + metaFile = fmt.Sprintf("%s/cluster/%s/meta.yaml", GSRCtlRoot, clusterName) - - GYamlConfAppend = confS.GetConf(metaFile) + GYamlConfAppend = confS.GetConf(metaFile) } - - - func WriteBackMeta(cc *ConfStruct, metaFilePath string) { - var infoMess string - var metaFileName string - // check the metaFile exist, if the file doesn't exist, create a new one. - metaFileName = metaFilePath + "/meta.yaml" - _ = os.MkdirAll(metaFilePath, 0751) - _, err := os.Create(metaFileName) - if err != nil { - infoMess = fmt.Sprintf("Error in create the meta file [fileName = %s]", metaFileName) - utl.Log("ERROR", infoMess) - } - - metaF, err := os.OpenFile(metaFileName, os.O_RDWR, 0644) - if err != nil { - infoMess = fmt.Sprintf("Error in opening write-back meta file [fileName = %s]", metaFileName) - utl.Log("ERROR", infoMess) - clusterNameArr := strings.Split(metaFilePath, "/") - clusterName := clusterNameArr[len(clusterNameArr)-1] - infoMess = fmt.Sprintf(`You can shoot the trouble as bellowing step: + var infoMess string + var metaFileName string + // check the metaFile exist, if the file doesn't exist, create a new one. + metaFileName = metaFilePath + "/meta.yaml" + _ = os.MkdirAll(metaFilePath, 0751) + _, err := os.Create(metaFileName) + if err != nil { + infoMess = fmt.Sprintf("Error in create the meta file [fileName = %s]", metaFileName) + utl.Log("ERROR", infoMess) + } + + metaF, err := os.OpenFile(metaFileName, os.O_RDWR, 0644) + if err != nil { + infoMess = fmt.Sprintf("Error in opening write-back meta file [fileName = %s]", metaFileName) + utl.Log("ERROR", infoMess) + clusterNameArr := strings.Split(metaFilePath, "/") + clusterName := clusterNameArr[len(clusterNameArr)-1] + infoMess = fmt.Sprintf(`You can shoot the trouble as bellowing step: 1. check the meta file status [fileName = %s] 2. check the cluster name you input [clusterName = %s] 3. check the os env $SRCTLROOT, if you don't set this env variable, please check the ~/.stargo folder `, metaFileName, clusterName) - // panic(err) - } - defer metaF.Close() + // panic(err) + } + defer metaF.Close() + + // write back cluster info + cc.ClusterInfo.User = GYamlConf.Global.User + cc.ClusterInfo.CreateDate = time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05") + cc.ClusterInfo.Version = GSRVersion + cc.ClusterInfo.MetaPath = GWriteBackMetaPath + cc.ClusterInfo.PrivateKey = GSshKeyRsa + + yamlStr, err := yaml.Marshal(cc) + if err != nil { + infoMess = fmt.Sprintf("Error in marshalling yaml structure.") + utl.Log("ERROR", infoMess) + } + + _, err = metaF.WriteString(string(yamlStr)) + if err != nil { + infoMess = fmt.Sprintf("Error in writing back to meta file [fileName = %s]", metaFileName) + utl.Log("ERROR", infoMess) + } +} +func IsSharedDataCluster() bool { + if GYamlConf == nil { + return false + } - // write back cluster info - cc.ClusterInfo.User = GYamlConf.Global.User - cc.ClusterInfo.CreateDate = time.Unix(time.Now().Unix(), 0,).Format("2006-01-02 15:04:05") - cc.ClusterInfo.Version = GSRVersion - cc.ClusterInfo.MetaPath = GWriteBackMetaPath - cc.ClusterInfo.PrivateKey = GSshKeyRsa + if len(GYamlConf.FeServers) > 0 { + if runMode, exists := GYamlConf.FeServers[0].Config["run_mode"]; exists && strings.TrimSpace(runMode) == "shared_data" { + return true + } + } - yamlStr, err := yaml.Marshal(cc) - if err != nil { - infoMess = fmt.Sprintf("Error in marshalling yaml structure.") - utl.Log("ERROR", infoMess) - } + return len(GYamlConf.CnServers) > 0 && len(GYamlConf.BeServers) == 0 +} - _, err = metaF.WriteString(string(yamlStr)) - if err != nil { - infoMess = fmt.Sprintf("Error in writing back to meta file [fileName = %s]", metaFileName) - utl.Log("ERROR", infoMess) - } +func CompareStarRocksVersions(left string, right string) int { + leftParts := parseVersionParts(left) + rightParts := parseVersionParts(right) + maxLen := len(leftParts) + if len(rightParts) > maxLen { + maxLen = len(rightParts) + } + + for i := 0; i < maxLen; i++ { + leftPart := 0 + rightPart := 0 + if i < len(leftParts) { + leftPart = leftParts[i] + } + if i < len(rightParts) { + rightPart = rightParts[i] + } + if leftPart > rightPart { + return 1 + } + if leftPart < rightPart { + return -1 + } + } + + return 0 +} +func parseVersionParts(version string) []int { + version = strings.TrimSpace(version) + version = strings.TrimPrefix(version, "v") + version = strings.TrimPrefix(version, "V") + version = strings.TrimPrefix(version, "StarRocks-") + version = strings.Split(version, "-")[0] + + rawParts := strings.Split(version, ".") + parts := make([]int, 0, len(rawParts)) + for _, rawPart := range rawParts { + partText := strings.TrimSpace(rawPart) + if partText == "" { + parts = append(parts, 0) + continue + } + part, err := strconv.Atoi(partText) + if err != nil { + break + } + parts = append(parts, part) + } + return parts } func SetGlobalVar(key string, value string) { - - var infoMess string - - switch key { - case "GSRVersion": - GSRVersion = value - case "GDownloadPath": - GDownloadPath = value - default: - infoMess = fmt.Sprintf("Error in set global variables. Now we only support \" GSRVERSION | GRepo\". [key = %s, value = %s]", key, value) - panic(errors.New(infoMess)) - } + + var infoMess string + + switch key { + case "GSRVersion": + GSRVersion = value + case "GDownloadPath": + GDownloadPath = value + default: + infoMess = fmt.Sprintf("Error in set global variables. Now we only support \" GSRVERSION | GRepo\". [key = %s, value = %s]", key, value) + panic(errors.New(infoMess)) + } } func SetFeEntry(feEntryId int) { - GFeEntryHost = GYamlConf.FeServers[feEntryId].Host - GFeEntryQueryPort = GYamlConf.FeServers[feEntryId].QueryPort - GFeEntryEditLogPort = GYamlConf.FeServers[feEntryId].EditLogPort + GFeEntryHost = GYamlConf.FeServers[feEntryId].Host + GFeEntryQueryPort = GYamlConf.FeServers[feEntryId].QueryPort + GFeEntryEditLogPort = GYamlConf.FeServers[feEntryId].EditLogPort } - - func TestParseYamlConfig(fileName string) { + var confS ConfStruct + yamlConf := confS.GetConf(fileName) + + // Print configuration + fmt.Println("[TEST] >>>>>>>>", yamlConf) + fmt.Println("[TEST] ######################### GLOBAL #########################") + fmt.Printf("[TEST] Global -> User: %s\n", yamlConf.Global.User) + fmt.Printf("[TEST] Global -> ssh_port: %d\n", yamlConf.Global.SshPort) + fmt.Println("[TEST] ######################### SERVER CONFIG #########################") + fmt.Println("[TEST] ServerConfig -> FE -> sys_log_level: ", yamlConf.ServerConfig.Fe["sys_log_level"]) + fmt.Println("[TEST] ServerConfig -> FE -> fe_sys_log_1: ", yamlConf.ServerConfig.Fe["fe_sys_log_1"]) + fmt.Println("[TEST] ServerConfig -> BE -> sys_log_level: ", yamlConf.ServerConfig.Be["sys_log_level"]) + fmt.Println("[TEST] ServerConfig -> BE -> sys_log_level: ", yamlConf.ServerConfig.Be["be_sys_log_2"]) + fmt.Println("[TEST] ######################### FE SERVER #########################") + for i := 0; i < 3; i++ { + fmt.Printf("[TEST] FeServer -> [%d] -> host: %s\n", i, yamlConf.FeServers[i].Host) + fmt.Printf("[TEST] FeServer -> [%d] -> ssh_port: %d\n", i, yamlConf.FeServers[i].SshPort) + fmt.Printf("[TEST] FeServer -> [%d] -> http_port: %d\n", i, yamlConf.FeServers[i].HttpPort) + fmt.Printf("[TEST] FeServer -> [%d] -> rpc_port: %d\n", i, yamlConf.FeServers[i].RpcPort) + fmt.Printf("[TEST] FeServer -> [%d] -> query_port: %d\n", i, yamlConf.FeServers[i].QueryPort) + fmt.Printf("[TEST] FeServer -> [%d] -> edit_log_port: %d\n", i, yamlConf.FeServers[i].EditLogPort) + fmt.Printf("[TEST] FeServer -> [%d] -> deploy_dir: %s\n", i, yamlConf.FeServers[i].DeployDir) + fmt.Printf("[TEST] FeServer -> [%d] -> meta_dir: %s\n", i, yamlConf.FeServers[i].MetaDir) + fmt.Printf("[TEST] FeServer -> [%d] -> log_dir: %s\n", i, yamlConf.FeServers[i].LogDir) + fmt.Printf("[TEST] FeServer -> [%d] -> priority_networks: %s\n", i, yamlConf.FeServers[i].PriorityNetworks) + fmt.Printf("[TEST] FeServer -> [%d] -> config -> sys_log_level: %s\n", i, yamlConf.FeServers[i].Config["sys_log_level"]) + fmt.Printf("[TEST] FeServer -> [%d] -> config -> sys_log_delete_age: %s\n", i, yamlConf.FeServers[i].Config["sys_log_delete_age"]) + } + + fmt.Println("[TEST] ######################### BE SERVER #########################") + for i := 0; i < 3; i++ { + fmt.Printf("[TEST] BeServer -> [%d] -> host: %s\n", i, yamlConf.BeServers[i].Host) + fmt.Printf("[TEST] BeServer -> [%d] -> ssh_port: %d\n", i, yamlConf.BeServers[i].SshPort) + fmt.Printf("[TEST] BeServer -> [%d] -> be_port: %d\n", i, yamlConf.BeServers[i].BePort) + fmt.Printf("[TEST] BeServer -> [%d] -> webserver_port: %d\n", i, yamlConf.BeServers[i].WebServerPort) + fmt.Printf("[TEST] BeServer -> [%d] -> heartbeat_service_port: %d\n", i, yamlConf.BeServers[i].HeartbeatServicePort) + fmt.Printf("[TEST] BeServer -> [%d] -> deploy_dir: %s\n", i, yamlConf.BeServers[i].DeployDir) + fmt.Printf("[TEST] BeServer -> [%d] -> storage_dir: %s\n", i, yamlConf.BeServers[i].StorageDir) + fmt.Printf("[TEST] BeServer -> [%d] -> PriorityNetworks %s\n", i, yamlConf.BeServers[i].PriorityNetworks) + fmt.Printf("[TEST] BeServer -> [%d] -> log_dir: %s\n", i, yamlConf.BeServers[i].LogDir) + fmt.Printf("[TEST] BeServer -> [%d] -> config -> sys_log_level: %s\n", i, yamlConf.BeServers[i].Config["create_tablet_worker_count"]) + fmt.Printf("[TEST] BeServer -> [%d] -> config -> sys_log_delete_age: %s\n", i, yamlConf.BeServers[i].Config["sys_log_delete_age"]) + } + + fmt.Println("[TEST] ######################### PROMETHEUS SERVER #########################") + fmt.Println("[TEST] PrometheusServer -> host: ", yamlConf.PrometheusServer.Host) + fmt.Println("[TEST] PrometheusServer -> ssh_port: ", yamlConf.PrometheusServer.SshPort) + fmt.Println("[TEST] PrometheusServer -> http_port: ", yamlConf.PrometheusServer.HttpPort) + fmt.Println("[TEST] PrometheusServer -> deploy_dir: ", yamlConf.PrometheusServer.DeployDir) + fmt.Println("[TEST] PrometheusServer -> data_dir: ", yamlConf.PrometheusServer.DataDir) + fmt.Println("[TEST] PrometheusServer -> log_dir: ", yamlConf.PrometheusServer.LogDir) + + fmt.Println("[TEST] ######################### GRAFANA SERVER #########################") + fmt.Println("[TEST] GrafanaServer -> host: ", yamlConf.GrafanaServer.Host) + fmt.Println("[TEST] GrafanaServer -> ssh_port: ", yamlConf.GrafanaServer.SshPort) + fmt.Println("[TEST] GrafanaServer -> http_port: ", yamlConf.GrafanaServer.HttpPort) + fmt.Println("[TEST] GrafanaServer -> deploy_dir: ", yamlConf.GrafanaServer.DeployDir) + + fmt.Println("[TEST] ######################### ALERTMANAGER SERVER #########################") + fmt.Println("[TEST] AlertManagerServer -> host: ", yamlConf.AlertManagerServer.Host) + fmt.Println("[TEST] AlertManagerServer -> ssh_port: ", yamlConf.AlertManagerServer.SshPort) + fmt.Println("[TEST] AlertManagerServer -> web_port: ", yamlConf.AlertManagerServer.WebPort) + fmt.Println("[TEST] AlertManagerServer -> cluster_port: ", yamlConf.AlertManagerServer.ClusterPort) + fmt.Println("[TEST] AlertManagerServer -> deploy_dir: ", yamlConf.AlertManagerServer.DeployDir) + fmt.Println("[TEST] AlertManagerServer -> data_dir: ", yamlConf.AlertManagerServer.DataDir) + fmt.Println("[TEST] AlertManagerServer -> log_dir: ", yamlConf.AlertManagerServer.LogDir) - var confS ConfStruct - yamlConf := confS.GetConf(fileName) - - // Print configuration - fmt.Println("[TEST] >>>>>>>>", yamlConf) - fmt.Println("[TEST] ######################### GLOBAL #########################") - fmt.Println("[TEST] Global -> User: %s\n", yamlConf.Global.User) - fmt.Println("[TEST] Global -> ssh_port: %s\n", yamlConf.Global.SshPort) - fmt.Println("[TEST] ######################### SERVER CONFIG #########################") - fmt.Println("[TEST] ServerConfig -> FE -> sys_log_level: ", yamlConf.ServerConfig.Fe["sys_log_level"]) - fmt.Println("[TEST] ServerConfig -> FE -> fe_sys_log_1: ", yamlConf.ServerConfig.Fe["fe_sys_log_1"]) - fmt.Println("[TEST] ServerConfig -> BE -> sys_log_level: ", yamlConf.ServerConfig.Be["sys_log_level"]) - fmt.Println("[TEST] ServerConfig -> BE -> sys_log_level: ", yamlConf.ServerConfig.Be["be_sys_log_2"]) - fmt.Println("[TEST] ######################### FE SERVER #########################") - for i := 0; i < 3; i++ { - fmt.Printf("[TEST] FeServer -> [%d] -> host: %s\n", i, yamlConf.FeServers[i].Host) - fmt.Printf("[TEST] FeServer -> [%d] -> ssh_port: %s\n", i, yamlConf.FeServers[i].SshPort) - fmt.Printf("[TEST] FeServer -> [%d] -> http_port: %s\n", i, yamlConf.FeServers[i].HttpPort) - fmt.Printf("[TEST] FeServer -> [%d] -> rpc_port: %s\n", i, yamlConf.FeServers[i].RpcPort) - fmt.Printf("[TEST] FeServer -> [%d] -> query_port: %s\n", i, yamlConf.FeServers[i].QueryPort) - fmt.Printf("[TEST] FeServer -> [%d] -> edit_log_port: %s\n", i, yamlConf.FeServers[i].EditLogPort) - fmt.Printf("[TEST] FeServer -> [%d] -> deploy_dir: %s\n", i, yamlConf.FeServers[i].DeployDir) - fmt.Printf("[TEST] FeServer -> [%d] -> meta_dir: %s\n", i, yamlConf.FeServers[i].MetaDir) - fmt.Printf("[TEST] FeServer -> [%d] -> log_dir: %s\n", i, yamlConf.FeServers[i].LogDir) - fmt.Printf("[TEST] FeServer -> [%d] -> priority_networks: %s\n", i, yamlConf.FeServers[i].PriorityNetworks) - fmt.Printf("[TEST] FeServer -> [%d] -> config -> sys_log_level: %s\n", i, yamlConf.FeServers[i].Config["sys_log_level"]) - fmt.Printf("[TEST] FeServer -> [%d] -> config -> sys_log_delete_age: %s\n", i, yamlConf.FeServers[i].Config["sys_log_delete_age"]) - } - - fmt.Println("[TEST] ######################### BE SERVER #########################") - for i := 0; i < 3; i++ { - fmt.Printf("[TEST] BeServer -> [%d] -> host: %s\n", i, yamlConf.BeServers[i].Host) - fmt.Printf("[TEST] BeServer -> [%d] -> ssh_port: %s\n", i, yamlConf.BeServers[i].SshPort) - fmt.Printf("[TEST] BeServer -> [%d] -> be_port: %s\n", i, yamlConf.BeServers[i].BePort) - fmt.Printf("[TEST] BeServer -> [%d] -> webserver_port: %s\n", i, yamlConf.BeServers[i].WebServerPort) - fmt.Printf("[TEST] BeServer -> [%d] -> heartbeat_service_port: %s\n", i, yamlConf.BeServers[i].HeartbeatServicePort) - fmt.Printf("[TEST] BeServer -> [%d] -> deploy_dir: %s\n", i, yamlConf.BeServers[i].DeployDir) - fmt.Printf("[TEST] BeServer -> [%d] -> storage_dir: %s\n", i, yamlConf.BeServers[i].StorageDir) - fmt.Printf("[TEST] BeServer -> [%d] -> PriorityNetworks %s\n", i, yamlConf.BeServers[i].PriorityNetworks) - fmt.Printf("[TEST] BeServer -> [%d] -> log_dir: %s\n", i, yamlConf.BeServers[i].LogDir) - fmt.Printf("[TEST] BeServer -> [%d] -> config -> sys_log_level: %s\n", i, yamlConf.BeServers[i].Config["create_tablet_worker_count"]) - fmt.Printf("[TEST] BeServer -> [%d] -> config -> sys_log_delete_age: %s\n", i, yamlConf.BeServers[i].Config["sys_log_delete_age"]) - } - - fmt.Println("[TEST] ######################### PROMETHEUS SERVER #########################") - fmt.Println("[TEST] PrometheusServer -> host: ", yamlConf.PrometheusServer.Host) - fmt.Println("[TEST] PrometheusServer -> ssh_port: ", yamlConf.PrometheusServer.SshPort) - fmt.Println("[TEST] PrometheusServer -> http_port: ", yamlConf.PrometheusServer.HttpPort) - fmt.Println("[TEST] PrometheusServer -> deploy_dir: ", yamlConf.PrometheusServer.DeployDir) - fmt.Println("[TEST] PrometheusServer -> data_dir: ", yamlConf.PrometheusServer.DataDir) - fmt.Println("[TEST] PrometheusServer -> log_dir: ", yamlConf.PrometheusServer.LogDir) - - fmt.Println("[TEST] ######################### GRAFANA SERVER #########################") - fmt.Println("[TEST] GrafanaServer -> host: ", yamlConf.GrafanaServer.Host) - fmt.Println("[TEST] GrafanaServer -> ssh_port: ", yamlConf.GrafanaServer.SshPort) - fmt.Println("[TEST] GrafanaServer -> http_port: ", yamlConf.GrafanaServer.HttpPort) - fmt.Println("[TEST] GrafanaServer -> deploy_dir: ", yamlConf.GrafanaServer.DeployDir) - - fmt.Println("[TEST] ######################### ALERTMANAGER SERVER #########################") - fmt.Println("[TEST] AlertManagerServer -> host: ", yamlConf.AlertManagerServer.Host) - fmt.Println("[TEST] AlertManagerServer -> ssh_port: ", yamlConf.AlertManagerServer.SshPort) - fmt.Println("[TEST] AlertManagerServer -> web_port: ", yamlConf.AlertManagerServer.WebPort) - fmt.Println("[TEST] AlertManagerServer -> cluster_port: ", yamlConf.AlertManagerServer.ClusterPort) - fmt.Println("[TEST] AlertManagerServer -> deploy_dir: ", yamlConf.AlertManagerServer.DeployDir) - fmt.Println("[TEST] AlertManagerServer -> data_dir: ", yamlConf.AlertManagerServer.DataDir) - fmt.Println("[TEST] AlertManagerServer -> log_dir: ", yamlConf.AlertManagerServer.LogDir) +} +func ResolveJDKHome(deployDir string) string { + version := "" + homeOverride := "" + if GYamlConf != nil { + version = strings.TrimSpace(GYamlConf.Global.JDKVersion) + homeOverride = strings.TrimSpace(GYamlConf.Global.JDKHome) + } + return jdk.ResolveJDKHomeForDeploy(deployDir, version, homeOverride) +} +func ResolvePlaygroundJDKDir() string { + version := "" + if GYamlConf != nil { + version = strings.TrimSpace(GYamlConf.Global.JDKVersion) + } + return jdk.ResolvePlaygroundDir(version) } diff --git a/module/yamlConfigModule_test.go b/module/yamlConfigModule_test.go new file mode 100644 index 0000000..13bd472 --- /dev/null +++ b/module/yamlConfigModule_test.go @@ -0,0 +1,165 @@ +package module + +import ( + "testing" +) + +func TestResolveJDKHome_DefaultLegacy(t *testing.T) { + GYamlConf = &ConfStruct{} + home := ResolveJDKHome("/opt/starrocks/fe") + if home != "/opt/starrocks/fe/jdk" { + t.Fatalf("expected legacy jdk path, got %s", home) + } +} + +func TestResolveJDKHome_GlobalHome(t *testing.T) { + GYamlConf = &ConfStruct{} + GYamlConf.Global.JDKHome = "/opt/jdk17" + home := ResolveJDKHome("/opt/starrocks/fe") + if home != "/opt/jdk17" { + t.Fatalf("expected global jdk home override, got %s", home) + } +} + +func TestResolveJDKHome_Version17(t *testing.T) { + GYamlConf = &ConfStruct{} + GYamlConf.Global.JDKVersion = "17.0.8" + home := ResolveJDKHome("/opt/starrocks/fe") + if home != "/opt/starrocks/fe/jdk17" { + t.Fatalf("expected jdk17 path, got %s", home) + } +} + +func TestResolveJDKHome_Version11(t *testing.T) { + GYamlConf = &ConfStruct{} + GYamlConf.Global.JDKVersion = "11.0.18" + home := ResolveJDKHome("/opt/starrocks/fe") + if home != "/opt/starrocks/fe/jdk11" { + t.Fatalf("expected jdk11 path, got %s", home) + } +} + +func TestResolvePlaygroundJDKDir_DefaultLegacy(t *testing.T) { + GYamlConf = &ConfStruct{} + dir := ResolvePlaygroundJDKDir() + if dir != "jdk1.8.0" { + t.Fatalf("expected legacy jdk dir, got %s", dir) + } +} + +func TestResolvePlaygroundJDKDir_Version17(t *testing.T) { + GYamlConf = &ConfStruct{} + GYamlConf.Global.JDKVersion = "17.0.3" + dir := ResolvePlaygroundJDKDir() + if dir != "jdk17" { + t.Fatalf("expected jdk17 dir, got %s", dir) + } +} + +func TestResolvePlaygroundJDKDir_Version11(t *testing.T) { + GYamlConf = &ConfStruct{} + GYamlConf.Global.JDKVersion = "11" + dir := ResolvePlaygroundJDKDir() + if dir != "jdk11" { + t.Fatalf("expected jdk11 dir, got %s", dir) + } +} + +func TestIsSharedDataCluster_RunMode(t *testing.T) { + GYamlConf = &ConfStruct{} + GYamlConf.FeServers = append(GYamlConf.FeServers, struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + HttpPort int `yaml:"http_port"` + RpcPort int `yaml:"rpc_port"` + QueryPort int `yaml:"query_port"` + EditLogPort int `yaml:"edit_log_port"` + DeployDir string `yaml:"deploy_dir"` + MetaDir string `yaml:"meta_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + Config map[string]string `yaml:"config"` + }{Config: map[string]string{"run_mode": "shared_data"}}) + + if !IsSharedDataCluster() { + t.Fatalf("expected shared-data cluster from FE run_mode") + } +} + +func TestIsSharedDataCluster_CnWithoutBe(t *testing.T) { + GYamlConf = &ConfStruct{} + GYamlConf.CnServers = append(GYamlConf.CnServers, struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + BePort int `yaml:"be_port"` + WebServerPort int `yaml:"webserver_port"` + HeartbeatServicePort int `yaml:"heartbeat_service_port"` + BrpcPort int `yaml:"brpc_port"` + StarletPort int `yaml:"starlet_port"` + DeployDir string `yaml:"deploy_dir"` + StorageDir string `yaml:"storage_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + WarehouseName string `yaml:"warehouse_name"` + Config map[string]string `yaml:"config"` + }{Host: "127.0.0.1"}) + + if !IsSharedDataCluster() { + t.Fatalf("expected CN-only topology to be shared-data") + } +} + +func TestIsSharedDataCluster_CnWithBeIsNotSharedData(t *testing.T) { + GYamlConf = &ConfStruct{} + GYamlConf.CnServers = append(GYamlConf.CnServers, struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + BePort int `yaml:"be_port"` + WebServerPort int `yaml:"webserver_port"` + HeartbeatServicePort int `yaml:"heartbeat_service_port"` + BrpcPort int `yaml:"brpc_port"` + StarletPort int `yaml:"starlet_port"` + DeployDir string `yaml:"deploy_dir"` + StorageDir string `yaml:"storage_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + WarehouseName string `yaml:"warehouse_name"` + Config map[string]string `yaml:"config"` + }{Host: "127.0.0.1"}) + GYamlConf.BeServers = append(GYamlConf.BeServers, struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + BePort int `yaml:"be_port"` + WebServerPort int `yaml:"webserver_port"` + HeartbeatServicePort int `yaml:"heartbeat_service_port"` + BrpcPort int `yaml:"brpc_port"` + DeployDir string `yaml:"deploy_dir"` + StorageDir string `yaml:"storage_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + Config map[string]string `yaml:"config"` + }{Host: "127.0.0.2"}) + + if IsSharedDataCluster() { + t.Fatalf("expected mixed BE/CN topology without shared_data run_mode to stay non-shared-data") + } +} + +func TestCompareStarRocksVersions(t *testing.T) { + tests := []struct { + left string + right string + want int + }{ + {left: "v3.10.0", right: "v3.9.9", want: 1}, + {left: "3.5.15", right: "3.5.15", want: 0}, + {left: "StarRocks-4.0.0-ubuntu-amd64", right: "v3.5.15", want: 1}, + {left: "v3.5", right: "v3.5.1", want: -1}, + } + + for _, tt := range tests { + if got := CompareStarRocksVersions(tt.left, tt.right); got != tt.want { + t.Fatalf("CompareStarRocksVersions(%q, %q) = %d, want %d", tt.left, tt.right, got, tt.want) + } + } +} diff --git a/package.sh b/package.sh new file mode 100755 index 0000000..a8e63f0 --- /dev/null +++ b/package.sh @@ -0,0 +1,123 @@ +#!/bin/bash + +# StarGo 一键打包脚本 +# 自动构建二进制文件并生成发布zip包 + +set -e # 遇到错误立即退出 + +PROJECT_NAME="stargo" +BUILD_TIME=$(date '+%Y-%m-%d %H:%M:%S') +GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") + +# 从 main.go 中读取版本号 +get_version() { + local version=$(grep -E '^[[:space:]]*Version[[:space:]]*=' main.go | sed -E 's/.*"([^"]+)".*/\1/') + if [ -z "$version" ]; then + echo "错误: 无法从 main.go 中读取版本号" + exit 1 + fi + echo "$version" +} + +VERSION=$(get_version) +RELEASE_DIR="dist/${PROJECT_NAME}-${VERSION}" +ZIP_FILE="dist/${PROJECT_NAME}-${VERSION}.zip" + +echo "=========================================" +echo "StarGo 一键打包脚本" +echo "=========================================" +echo "项目名称: $PROJECT_NAME" +echo "版本号: $VERSION" +echo "构建时间: $BUILD_TIME" +echo "Git提交: $GIT_COMMIT" +echo "发布目录: $RELEASE_DIR" +echo "ZIP文件: $ZIP_FILE" +echo "=========================================" + +# 1. 清理并构建二进制文件 +echo "🔨 构建二进制文件..." +make build-all + +# 检查构建是否成功 +if [ ! -f "dist/${PROJECT_NAME}-linux-amd64" ]; then + echo "❌ 构建失败: 找不到二进制文件" + exit 1 +fi + +# 2. 创建发布目录 +echo "📁 创建发布目录..." +rm -rf "$RELEASE_DIR" +mkdir -p "$RELEASE_DIR" + +# 3. 复制二进制文件 +echo "📦 复制二进制文件..." +cp "dist/${PROJECT_NAME}-linux-amd64" "$RELEASE_DIR/$PROJECT_NAME" +chmod +x "$RELEASE_DIR/$PROJECT_NAME" + +# 4. 复制配置文件 +echo "📋 复制配置文件..." +if [ -f "deploy-template.yaml" ]; then + cp deploy-template.yaml "$RELEASE_DIR/" +fi + +if [ -f "repo.yaml" ]; then + cp repo.yaml "$RELEASE_DIR/" +fi + +# 5. 复制环境检查脚本 +echo "🔧 复制环境检查脚本..." +if [ -f "env_check.sh" ]; then + cp env_check.sh "$RELEASE_DIR/" + chmod +x "$RELEASE_DIR/env_check.sh" +else + echo "⚠️ 警告: 找不到 env_check.sh 文件" +fi + +# 6. 生成README文件 +echo "📝 生成README文件..." +if [ -f "README.template.md" ]; then + # 从模板生成README,替换占位符 + sed -e "s/{{VERSION}}/$VERSION/g" \ + -e "s/{{BUILD_TIME}}/$BUILD_TIME/g" \ + -e "s/{{GIT_COMMIT}}/$GIT_COMMIT/g" \ + -e "s/{{PROJECT_NAME}}/$PROJECT_NAME/g" \ + README.template.md > "$RELEASE_DIR/README.md" +else + echo "⚠️ 警告: 找不到 README.template.md 文件" +fi + +# 7. 验证二进制文件版本 +echo "🔍 验证二进制文件版本..." +BINARY_VERSION=$("$RELEASE_DIR/$PROJECT_NAME" version 2>/dev/null | head -1 | awk '{print $3}' || echo "unknown") +if [ "$BINARY_VERSION" != "$VERSION" ]; then + echo "⚠️ 警告: 二进制文件版本 ($BINARY_VERSION) 与预期版本 ($VERSION) 不匹配" +fi + +# 8. 创建ZIP包 +echo "🗜️ 创建ZIP包..." +rm -f "$ZIP_FILE" +cd dist +zip -r "$(basename "$ZIP_FILE")" "$(basename "$RELEASE_DIR")/" +cd .. + +# 9. 验证ZIP包 +if [ -f "$ZIP_FILE" ]; then + ZIP_SIZE=$(ls -lh "$ZIP_FILE" | awk '{print $5}') + echo "✅ ZIP包创建成功!" + echo "📍 文件位置: $ZIP_FILE" + echo "📏 文件大小: $ZIP_SIZE" + echo "" + echo "📋 ZIP包内容:" + unzip -l "$ZIP_FILE" +else + echo "❌ ZIP包创建失败" + exit 1 +fi + +echo "" +echo "🎉 打包完成!" +echo "=========================================" +echo "发布包: $ZIP_FILE" +echo "版本: $VERSION" +echo "大小: $ZIP_SIZE" +echo "=========================================" \ No newline at end of file diff --git a/playground/generateConf.go b/playground/generateConf.go index 92459bf..d779a60 100644 --- a/playground/generateConf.go +++ b/playground/generateConf.go @@ -1,102 +1,91 @@ package playground import ( - - "stargo/module" - "time" - "fmt" - _ "embed" - "os/user" - "os" - + _ "embed" + "fmt" + "os" + "os/user" + "stargo/module" + "time" ) - - -func InitPlaygroundConf(){ - - var tmp module.ConfStruct - - - osUser, _ := user.Current() - module.GSshKeyRsa = fmt.Sprintf("%s/.ssh/id_rsa", osUser.HomeDir) - module.GSRCtlRoot = os.Getenv("SRCTLROOT") - if module.GSRCtlRoot == "" { - module.GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) - } - tmpDeployDir := fmt.Sprintf("%s/playground", module.GSRCtlRoot) - - // ClusterInfo - tmp.ClusterInfo.User = osUser.Username - tmp.ClusterInfo.Version = "2.2.0" - tmp.ClusterInfo.CreateDate = time.Unix(time.Now().Unix(), 0,).Format("2006-01-02 15:04:05") - tmp.ClusterInfo.MetaPath = fmt.Sprintf("%s/cluster/sr-playground", module.GSRCtlRoot) - tmp.ClusterInfo.PrivateKey = module.GSshKeyRsa - - - tmp.Global.User = osUser.Username - tmp.Global.SshPort = 22 - - tmp.FeServers = append(tmp.FeServers, - struct { - Host string `yaml:"host"` - SshPort int `yaml:"ssh_port"` - HttpPort int `yaml:"http_port"` - RpcPort int `yaml:"rpc_port"` - QueryPort int `yaml:"query_port"` - EditLogPort int `yaml:"edit_log_port"` - DeployDir string `yaml:"deploy_dir"` - MetaDir string `yaml:"meta_dir"` - LogDir string `yaml:"log_dir"` - PriorityNetworks string `yaml:"priority_networks"` - Config map[string]string `yaml:"config"` - } { - Host: "127.0.0.1", - SshPort: 22, - HttpPort: 8030, - RpcPort: 9020, - QueryPort: 9030, - EditLogPort: 9010, - DeployDir: tmpDeployDir + "/fe", - MetaDir: tmpDeployDir + "/fe/meta", - LogDir: tmpDeployDir + "/fe/log", - PriorityNetworks: "127.0.0.1/32", - Config: nil, - }) - - tmp.BeServers = append(tmp.BeServers, - struct { - Host string `yaml:"host"` - SshPort int `yaml:"ssh_port"` - BePort int `yaml:"be_port"` - WebServerPort int `yaml:"webserver_port"` - HeartbeatServicePort int `yaml:"heartbeat_service_port"` - BrpcPort int `yaml:"brpc_port"` - DeployDir string `yaml:"deploy_dir"` - StorageDir string `yaml:"storage_dir"` - LogDir string `yaml:"log_dir"` - PriorityNetworks string `yaml:"priority_networks"` - Config map[string]string `yaml:"configs` - } { - Host: "127.0.0.1", - SshPort: 22, - BePort: 9060, - WebServerPort: 8040, - HeartbeatServicePort: 9050, - BrpcPort: 8060, - DeployDir: tmpDeployDir + "/be", - StorageDir: tmpDeployDir + "/be/storage", - LogDir: tmpDeployDir + "/be/log", - PriorityNetworks: "127.0.0.1/32", - Config: nil, - }) - - - module.GYamlConf = &tmp - module.GSRVersion = "v" + module.GYamlConf.ClusterInfo.Version +func InitPlaygroundConf() { + + var tmp module.ConfStruct + + osUser, _ := user.Current() + module.GSshKeyRsa = fmt.Sprintf("%s/.ssh/id_rsa", osUser.HomeDir) + module.GSRCtlRoot = os.Getenv("SRCTLROOT") + if module.GSRCtlRoot == "" { + module.GSRCtlRoot = fmt.Sprintf("%s/.stargo", osUser.HomeDir) + } + tmpDeployDir := fmt.Sprintf("%s/playground", module.GSRCtlRoot) + + // ClusterInfo + tmp.ClusterInfo.User = osUser.Username + tmp.ClusterInfo.Version = "2.2.0" + tmp.ClusterInfo.CreateDate = time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05") + tmp.ClusterInfo.MetaPath = fmt.Sprintf("%s/cluster/sr-playground", module.GSRCtlRoot) + tmp.ClusterInfo.PrivateKey = module.GSshKeyRsa + + tmp.Global.User = osUser.Username + tmp.Global.SshPort = 22 + tmp.Global.JDKVersion = "17.0.8" + + tmp.FeServers = append(tmp.FeServers, + struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + HttpPort int `yaml:"http_port"` + RpcPort int `yaml:"rpc_port"` + QueryPort int `yaml:"query_port"` + EditLogPort int `yaml:"edit_log_port"` + DeployDir string `yaml:"deploy_dir"` + MetaDir string `yaml:"meta_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + Config map[string]string `yaml:"config"` + }{ + Host: "127.0.0.1", + SshPort: 22, + HttpPort: 8030, + RpcPort: 9020, + QueryPort: 9030, + EditLogPort: 9010, + DeployDir: tmpDeployDir + "/fe", + MetaDir: tmpDeployDir + "/fe/meta", + LogDir: tmpDeployDir + "/fe/log", + PriorityNetworks: "127.0.0.1/32", + Config: nil, + }) + + tmp.BeServers = append(tmp.BeServers, + struct { + Host string `yaml:"host"` + SshPort int `yaml:"ssh_port"` + BePort int `yaml:"be_port"` + WebServerPort int `yaml:"webserver_port"` + HeartbeatServicePort int `yaml:"heartbeat_service_port"` + BrpcPort int `yaml:"brpc_port"` + DeployDir string `yaml:"deploy_dir"` + StorageDir string `yaml:"storage_dir"` + LogDir string `yaml:"log_dir"` + PriorityNetworks string `yaml:"priority_networks"` + Config map[string]string `yaml:"config"` + }{ + Host: "127.0.0.1", + SshPort: 22, + BePort: 9060, + WebServerPort: 8040, + HeartbeatServicePort: 9050, + BrpcPort: 8060, + DeployDir: tmpDeployDir + "/be", + StorageDir: tmpDeployDir + "/be/storage", + LogDir: tmpDeployDir + "/be/log", + PriorityNetworks: "127.0.0.1/32", + Config: nil, + }) + + module.GYamlConf = &tmp + module.GSRVersion = "v" + module.GYamlConf.ClusterInfo.Version } - - - - - diff --git a/playground/playground.go b/playground/playground.go index 3406a38..0999b57 100644 --- a/playground/playground.go +++ b/playground/playground.go @@ -1,49 +1,42 @@ package playground import ( - - "fmt" - "stargo/sr-utl" - + "fmt" + "stargo/sr-utl" ) - - func StartFePlayground() bool { - ModifyFEConfig() - RunFEProcess() - res := CheckFEStatus() - return res + ModifyFEConfig() + RunFEProcess() + res := CheckFEStatus() + return res } - func StartBePlayground() bool { - ModifyBEConfig() - AddBENode() - RunBEProcess() - res := CheckBEStatus() - return res + ModifyBEConfig() + AddBENode() + RunBEProcess() + res := CheckBEStatus() + return res } - func RunPlayground() { + var infoMess string + InitPlaygroundConf() - var infoMess string - InitPlaygroundConf() - - PrecheckPlayground() - PreparePlaygroundDir() - feSuccess := StartFePlayground() - beSuccess := StartBePlayground() + PrecheckPlayground() + PreparePlaygroundDir() + feSuccess := StartFePlayground() + beSuccess := StartBePlayground() - if feSuccess && beSuccess { - infoMess = fmt.Sprintf("Playground run successfully. Please use bellowing command to connect StarRocks playground cluster:\nmysql -uroot -P9030 -h127.0.0.1") - utl.Log("OUTPUT", infoMess) - } + if feSuccess && beSuccess { + infoMess = fmt.Sprintf("Playground run successfully. Please use bellowing command to connect StarRocks playground cluster:\nmysql -uroot -P9030 -h127.0.0.1") + utl.Log("OUTPUT", infoMess) + } } diff --git a/playground/precheck.go b/playground/precheck.go index 0492b05..fbb9db5 100644 --- a/playground/precheck.go +++ b/playground/precheck.go @@ -1,96 +1,91 @@ package playground import ( - "fmt" - "os" - "stargo/sr-utl" - "stargo/module" - "strconv" - "strings" + "fmt" + "os" + "stargo/module" + "stargo/sr-utl" + "strconv" + "strings" ) - func precheckPortUsed() bool { - // FE Port: 8030 9020 9030 9010 - // BE Port: 8040 8060 9050 9060 - var portNoUsed bool = true + // FE Port: 8030 9020 9030 9010 + // BE Port: 8040 8060 9050 9060 + var portNoUsed bool = true - portArr := [8] string{":8060", ":8040", ":9010", ":9050", ":9020", ":8030", ":9060", ":9030"} - for _, portStr := range portArr { - if utl.PortUsed(portStr) { - fmt.Println("Detect the port " + portStr + " used. Please stop it first.") - portNoUsed = false - } - } + portArr := [8]string{":8060", ":8040", ":9010", ":9050", ":9020", ":8030", ":9060", ":9030"} + for _, portStr := range portArr { + if utl.PortUsed(portStr) { + fmt.Println("Detect the port " + portStr + " used. Please stop it first.") + portNoUsed = false + } + } - return portNoUsed + return portNoUsed } func precheckOpenFiles() bool { - var infoMess string - var execCMD string - var cmdRes string - var err error - - execCMD = "ulimit -n" - cmdRes, err = utl.RunShellScript(execCMD) - if err != nil { - infoMess = fmt.Sprintf("Failed to run command. [cmd = %s]", execCMD) - utl.Log("ERROR", infoMess) - } - - fileCount, err := strconv.Atoi(strings.Replace(cmdRes, "\n", "", -1)) - if err != nil { - infoMess = fmt.Sprintf("Failed to convert string to int.[res = %s]", fileCount) - utl.Log("ERROR", infoMess) - } - - - if fileCount >= 65535 { - return true - } else { - infoMess = fmt.Sprintf("Error in check the open file count. Please use the command [ulimit -n] to check the openfile count and make sure more than 65535.") - utl.Log("ERROR", infoMess) - return false - } + var infoMess string + var execCMD string + var cmdRes string + var err error + + execCMD = "ulimit -n" + cmdRes, err = utl.RunShellScript(execCMD) + if err != nil { + infoMess = fmt.Sprintf("Failed to run command. [cmd = %s]", execCMD) + utl.Log("ERROR", infoMess) + } + + fileCount, err := strconv.Atoi(strings.Replace(cmdRes, "\n", "", -1)) + if err != nil { + infoMess = fmt.Sprintf("Failed to convert string to int.[res = %s]", strings.Replace(cmdRes, "\n", "", -1)) + utl.Log("ERROR", infoMess) + } + + if fileCount >= 65535 { + return true + } else { + infoMess = fmt.Sprintf("Error in check the open file count. Please use the command [ulimit -n] to check the openfile count and make sure more than 65535.") + utl.Log("ERROR", infoMess) + return false + } } - func playgroundDirExist() bool { - var infoMess string - var playgroundDir string + var infoMess string + var playgroundDir string - playgroundDir = module.GSRCtlRoot + "/playground" - _, err := os.Stat(playgroundDir) + playgroundDir = module.GSRCtlRoot + "/playground" + _, err := os.Stat(playgroundDir) - if err == nil { - infoMess = fmt.Sprintf("Detect the playground dir exists. Please delete first. [playground dir = %s]", playgroundDir) - utl.Log("ERROR", infoMess) - return false - } + if err == nil { + infoMess = fmt.Sprintf("Detect the playground dir exists. Please delete first. [playground dir = %s]", playgroundDir) + utl.Log("ERROR", infoMess) + return false + } - // dir exists - return true + // dir exists + return true } - func PrecheckPlayground() { - var playgroundDir bool - var openFileCount bool - var portNoUsed bool - // var infoMess string - - - playgroundDir = playgroundDirExist() - openFileCount = precheckOpenFiles() - portNoUsed = precheckPortUsed() - if !playgroundDir || !openFileCount || !portNoUsed { - os.Exit(1) - } + var playgroundDir bool + var openFileCount bool + var portNoUsed bool + // var infoMess string + + playgroundDir = playgroundDirExist() + openFileCount = precheckOpenFiles() + portNoUsed = precheckPortUsed() + if !playgroundDir || !openFileCount || !portNoUsed { + os.Exit(1) + } } diff --git a/playground/prepareDir.go b/playground/prepareDir.go index 15c93c3..d4f986a 100644 --- a/playground/prepareDir.go +++ b/playground/prepareDir.go @@ -1,57 +1,66 @@ package playground import ( - - "fmt" - "os" - "stargo/cluster/prepareOption" - "stargo/module" + "fmt" + "os" + "stargo/cluster/prepareOption" + "stargo/jdk" + "stargo/module" ) - - func PreparePlaygroundDir() { - // mkdir sr ctl dir - prepareOption.CreateiSrCtlDir() - _ = os.MkdirAll(module.GSRCtlRoot+"/playground", 0751) - // download & decompress sr package - prepareOption.PrepareSRPkg() - DistributePlaygroundBinary() + // mkdir sr ctl dir + prepareOption.CreateiSrCtlDir() + _ = os.MkdirAll(module.GSRCtlRoot+"/playground", 0751) + // download & decompress sr package + prepareOption.PrepareSRPkg() + DistributePlaygroundBinary() } - - - func DistributePlaygroundBinary() { - var sourceDir string - var targetDir string - var err error - - // module.GDownloadPath is the folder /home/sr-dev/.stargo/download - - // deploy jdk folder - sourceDir = module.GDownloadPath + "/jdk1.8.0_301" - targetDir = module.GSRCtlRoot + "/playground/jdk1.8.0" - err = os.Rename(sourceDir, targetDir) - if err != nil { panic(err) } - - // deploy fe folder - sourceDir = fmt.Sprintf("%s/StarRocks-%s/fe", module.GDownloadPath, module.GYamlConf.ClusterInfo.Version) - targetDir = module.GSRCtlRoot + "/playground/fe" - err = os.Rename(sourceDir, targetDir) - if err != nil { panic(err) } - - // deploy be folder - sourceDir = fmt.Sprintf("%s/StarRocks-%s/be", module.GDownloadPath, module.GYamlConf.ClusterInfo.Version) - targetDir = module.GSRCtlRoot + "/playground/be" - err = os.Rename(sourceDir, targetDir) - if err != nil { panic(err) } + var sourceDir string + var targetDir string + var err error + var jdkVersion string + + // module.GDownloadPath is the folder /home/sr-dev/.stargo/download + + // deploy jdk folder (支持JDK17优先) + if module.GYamlConf != nil { + jdkVersion = module.GYamlConf.Global.JDKVersion + } + info := jdk.ResolveInfo(jdkVersion) + sourceDir = fmt.Sprintf("%s/%s", module.GDownloadPath, info.DownloadFolder) + targetDir = module.GSRCtlRoot + "/playground/" + module.ResolvePlaygroundJDKDir() + err = os.Rename(sourceDir, targetDir) + if err != nil { + // 回退到旧版JDK布局 + legacy := jdk.ResolveInfo("8") + sourceDir = fmt.Sprintf("%s/%s", module.GDownloadPath, legacy.DownloadFolder) + targetDir = module.GSRCtlRoot + "/playground/" + module.ResolvePlaygroundJDKDir() + err = os.Rename(sourceDir, targetDir) + if err != nil { + panic(err) + } + } + + // deploy fe folder + sourceDir = fmt.Sprintf("%s/StarRocks-%s/fe", module.GDownloadPath, module.GYamlConf.ClusterInfo.Version) + targetDir = module.GSRCtlRoot + "/playground/fe" + err = os.Rename(sourceDir, targetDir) + if err != nil { + panic(err) + } + + // deploy be folder + sourceDir = fmt.Sprintf("%s/StarRocks-%s/be", module.GDownloadPath, module.GYamlConf.ClusterInfo.Version) + targetDir = module.GSRCtlRoot + "/playground/be" + err = os.Rename(sourceDir, targetDir) + if err != nil { + panic(err) + } } - - - - diff --git a/playground/startBe.go b/playground/startBe.go index 5e33458..756ad5f 100644 --- a/playground/startBe.go +++ b/playground/startBe.go @@ -1,108 +1,106 @@ package playground import ( - "stargo/sr-utl" - "stargo/module" - "fmt" - "time" - "strings" - "os" + "fmt" + "os" + "stargo/module" + "stargo/sr-utl" + "strings" + "time" ) func ModifyBEConfig() { - var modFile string - var srcConfig string - var tarConfig string - var infoMess string - - // modify priority_networks for be.conf - modFile = module.GSRCtlRoot + "/playground/be/conf/be.conf" - srcConfig = "# priority_networks = 10.10.10.0/24;192.168.0.0/16" - tarConfig = "# priority_networks = 10.10.10.0/24;192.168.0.0/16\npriority_networks = 127.0.0.1/32" - err := utl.ModifyConfig(modFile, srcConfig, tarConfig) - if err != nil { - infoMess = fmt.Sprintf("Error in modifing BE config [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) - utl.Log("ERROR", infoMess) - panic(err) - } - infoMess = fmt.Sprintf("Modify BE config [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) - utl.Log("DEBUG", infoMess) + var modFile string + var srcConfig string + var tarConfig string + var infoMess string + + // modify priority_networks for be.conf + modFile = module.GSRCtlRoot + "/playground/be/conf/be.conf" + srcConfig = "# priority_networks = 10.10.10.0/24;192.168.0.0/16" + tarConfig = "# priority_networks = 10.10.10.0/24;192.168.0.0/16\npriority_networks = 127.0.0.1/32" + err := utl.ModifyConfig(modFile, srcConfig, tarConfig) + if err != nil { + infoMess = fmt.Sprintf("Error in modifing BE config [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) + utl.Log("ERROR", infoMess) + panic(err) + } + infoMess = fmt.Sprintf("Modify BE config [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) + utl.Log("DEBUG", infoMess) } - func AddBENode() { - var infoMess string - // add be node in fe - addExecCMD := "mysql -uroot -P9030 -h127.0.0.1 -e 'alter system add backend \"127.0.0.1:9050\"'" - _, err := utl.RunShellScript(addExecCMD) - if err != nil{ - infoMess = fmt.Sprintf("Error in running cmd, cmd = %s, err = %v", addExecCMD, err) - utl.Log("ERROR", infoMess) - } - - time.Sleep(time.Duration(5) * time.Second) - checkExecCMD := "mysql -uroot -P9030 -h127.0.0.1 -e 'show backends \\G'" - res, err := utl.RunShellScript(checkExecCMD) - if err != nil{ - infoMess = fmt.Sprintf("Error in running cmd.[cmd = %s, err = %v]", checkExecCMD, err) - utl.Log("ERROR", infoMess) - } - - if strings.Contains(res, "127.0.0.1") { - utl.Log("OUTPUT", "BE node 127.0.0.1 added successfully.") - } + var infoMess string + // add be node in fe + addExecCMD := "mysql -uroot -P9030 -h127.0.0.1 -e 'alter system add backend \"127.0.0.1:9050\"'" + _, err := utl.RunShellScript(addExecCMD) + if err != nil { + infoMess = fmt.Sprintf("Error in running cmd, cmd = %s, err = %v", addExecCMD, err) + utl.Log("ERROR", infoMess) + } + + time.Sleep(time.Duration(5) * time.Second) + checkExecCMD := "mysql -uroot -P9030 -h127.0.0.1 -e 'show backends \\G'" + res, err := utl.RunShellScript(checkExecCMD) + if err != nil { + infoMess = fmt.Sprintf("Error in running cmd.[cmd = %s, err = %v]", checkExecCMD, err) + utl.Log("ERROR", infoMess) + } + + if strings.Contains(res, "127.0.0.1") { + utl.Log("OUTPUT", "BE node 127.0.0.1 added successfully.") + } } - func RunBEProcess() { - var infoMess string - // mkdir /root/.stargo/playground/fe/meta - storageDir := module.GSRCtlRoot + "/playground/be/storage" - _, err := os.Stat(storageDir) - if err == nil { - infoMess = fmt.Sprintf("Detect meta folder %s exists, delete it\n", storageDir) - utl.Log("ERROR", infoMess) - err = os.RemoveAll(storageDir) - } - - err = os.Mkdir(storageDir, 0751) - if err != nil { panic(err) } - - // run start_fe.sh - execCMD := module.GSRCtlRoot + "/playground/be/bin/start_be.sh --daemon" - _, err = utl.RunShellScript(execCMD) - if err != nil { - infoMess = fmt.Sprintf("Error in running be process, cmd = %s, err = %v", execCMD, err) - utl.Log("ERROR", infoMess ) - } - - time.Sleep(time.Duration(15) * time.Second) + var infoMess string + // mkdir /root/.stargo/playground/fe/meta + storageDir := module.GSRCtlRoot + "/playground/be/storage" + _, err := os.Stat(storageDir) + if err == nil { + infoMess = fmt.Sprintf("Detect meta folder %s exists, delete it\n", storageDir) + utl.Log("ERROR", infoMess) + err = os.RemoveAll(storageDir) + } + + err = os.Mkdir(storageDir, 0751) + if err != nil { + panic(err) + } + + // run start_fe.sh + execCMD := module.GSRCtlRoot + "/playground/be/bin/start_be.sh --daemon" + _, err = utl.RunShellScript(execCMD) + if err != nil { + infoMess = fmt.Sprintf("Error in running be process, cmd = %s, err = %v", execCMD, err) + utl.Log("ERROR", infoMess) + } + + time.Sleep(time.Duration(15) * time.Second) } func CheckBEStatus() bool { - var res string - execCMD := "mysql -uroot -h127.0.0.1 -P9030 -e 'show backends\\G' | grep Alive" - for i := 0; i < 5; i++ { - res, _ = utl.RunShellScript(execCMD) - if strings.Contains(res, "true") { - utl.Log("OUTPUT", "BE start successfully.") - return true - } - time.Sleep(time.Duration(5) * time.Second) - } + var res string + execCMD := "mysql -uroot -h127.0.0.1 -P9030 -e 'show backends\\G' | grep Alive" + for i := 0; i < 5; i++ { + res, _ = utl.RunShellScript(execCMD) + if strings.Contains(res, "true") { + utl.Log("OUTPUT", "BE start successfully.") + return true + } + time.Sleep(time.Duration(5) * time.Second) + } - if !strings.Contains(res, "true") { - utl.Log("ERROR", "BE start failed.") - } - - return false + if !strings.Contains(res, "true") { + utl.Log("ERROR", "BE start failed.") + } + return false } - diff --git a/playground/startFe.go b/playground/startFe.go index f944218..4047ebc 100644 --- a/playground/startFe.go +++ b/playground/startFe.go @@ -1,111 +1,104 @@ package playground import ( - - "stargo/sr-utl" - "stargo/module" - "fmt" - "os" - "time" - "strings" - + "fmt" + "os" + "stargo/module" + "stargo/sr-utl" + "strings" + "time" ) - func ModifyFEConfig() { - var modFile string - var srcConfig string - var tarConfig string - var infoMess string - - // modify JAVA_OPS for fe.conf - modFile = module.GSRCtlRoot + "/playground/fe/conf/fe.conf" - srcConfig = "-Xmx8192m" - tarConfig = "-Xmx512m" - err := utl.ModifyConfig(modFile, srcConfig, tarConfig) - if err != nil { - infoMess = fmt.Sprintf("Error in modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) - utl.Log("ERROR", infoMess) - panic(err) - } - infoMess = fmt.Sprintf("Modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) - utl.Log("DEBUG", infoMess) - - // modify priority_networks for fe.conf - modFile = module.GSRCtlRoot + "/playground/fe/conf/fe.conf" - srcConfig = "# priority_networks = 10.10.10.0/24;192.168.0.0/16" - tarConfig = "# priority_networks = 10.10.10.0/24;192.168.0.0/16\npriority_networks = 127.0.0.1/32" - err = utl.ModifyConfig(modFile, srcConfig, tarConfig) - if err != nil { - infoMess = fmt.Sprintf("Error in modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) - utl.Log("ERROR", infoMess) - panic(err) - } - infoMess = fmt.Sprintf("Modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) - utl.Log("DEBUG", infoMess) - - // modify JAVA_HOME for start_fe.sh - modFile = module.GSRCtlRoot + "/playground/fe/bin/start_fe.sh" - srcConfig = "# java" - tarConfig = fmt.Sprintf("# java\nJAVA_HOME=%s/playground/jdk1.8.0\n", module.GSRCtlRoot) - err = utl.ModifyConfig(modFile, srcConfig, tarConfig) - if err != nil { - infoMess = fmt.Sprintf("Error in modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) - utl.Log("ERROR", infoMess) - panic(err) - } - infoMess = fmt.Sprintf("Modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) - utl.Log("DEBUG", infoMess) + var modFile string + var srcConfig string + var tarConfig string + var infoMess string + + // modify JAVA_OPS for fe.conf + modFile = module.GSRCtlRoot + "/playground/fe/conf/fe.conf" + srcConfig = "-Xmx8192m" + tarConfig = "-Xmx512m" + err := utl.ModifyConfig(modFile, srcConfig, tarConfig) + if err != nil { + infoMess = fmt.Sprintf("Error in modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) + utl.Log("ERROR", infoMess) + panic(err) + } + infoMess = fmt.Sprintf("Modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) + utl.Log("DEBUG", infoMess) + + // modify priority_networks for fe.conf + modFile = module.GSRCtlRoot + "/playground/fe/conf/fe.conf" + srcConfig = "# priority_networks = 10.10.10.0/24;192.168.0.0/16" + tarConfig = "# priority_networks = 10.10.10.0/24;192.168.0.0/16\npriority_networks = 127.0.0.1/32" + err = utl.ModifyConfig(modFile, srcConfig, tarConfig) + if err != nil { + infoMess = fmt.Sprintf("Error in modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) + utl.Log("ERROR", infoMess) + panic(err) + } + infoMess = fmt.Sprintf("Modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) + utl.Log("DEBUG", infoMess) + + // modify JAVA_HOME for start_fe.sh + modFile = module.GSRCtlRoot + "/playground/fe/bin/start_fe.sh" + srcConfig = "# java" + tarConfig = fmt.Sprintf("# java\nJAVA_HOME=%s/playground/%s\n", module.GSRCtlRoot, module.ResolvePlaygroundJDKDir()) + err = utl.ModifyConfig(modFile, srcConfig, tarConfig) + if err != nil { + infoMess = fmt.Sprintf("Error in modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) + utl.Log("ERROR", infoMess) + panic(err) + } + infoMess = fmt.Sprintf("Modify FE configuration [modFile = %s, srcConfig = %s, tarConfig = %s]", modFile, srcConfig, tarConfig) + utl.Log("DEBUG", infoMess) } - - - func RunFEProcess() { - var infoMess string - // mkdir /root/.stargo/playground/fe/meta - metaDir := module.GSRCtlRoot + "/playground/fe/meta" - _, err := os.Stat(metaDir) - if err == nil { - fmt.Printf("Detect meta folder %s exists, delete it\n", metaDir) - err = os.RemoveAll(metaDir) - } + var infoMess string + // mkdir /root/.stargo/playground/fe/meta + metaDir := module.GSRCtlRoot + "/playground/fe/meta" + _, err := os.Stat(metaDir) + if err == nil { + fmt.Printf("Detect meta folder %s exists, delete it\n", metaDir) + err = os.RemoveAll(metaDir) + } - err = os.Mkdir(metaDir, 0751) - if err != nil { panic(err) } + err = os.Mkdir(metaDir, 0751) + if err != nil { + panic(err) + } - // run start_fe.sh - execCMD := module.GSRCtlRoot + "/playground/fe/bin/start_fe.sh --daemon" - _, err = utl.RunShellScript(execCMD) - if err != nil { - infoMess = fmt.Sprintf("Error in running cmd, cmd = %s, err = %v\n", execCMD, err) - utl.Log("ERROR", infoMess) + // run start_fe.sh + execCMD := module.GSRCtlRoot + "/playground/fe/bin/start_fe.sh --daemon" + _, err = utl.RunShellScript(execCMD) + if err != nil { + infoMess = fmt.Sprintf("Error in running cmd, cmd = %s, err = %v\n", execCMD, err) + utl.Log("ERROR", infoMess) - } + } - time.Sleep(time.Duration(15) * time.Second) + time.Sleep(time.Duration(15) * time.Second) } - func CheckFEStatus() bool { - execCMD := "mysql -uroot -h127.0.0.1 -P9030 -e 'show frontends\\G' | grep Alive" - for i := 0; i < 5; i++ { - res, _:= utl.RunShellScript(execCMD) + execCMD := "mysql -uroot -h127.0.0.1 -P9030 -e 'show frontends\\G' | grep Alive" + for i := 0; i < 5; i++ { + res, _ := utl.RunShellScript(execCMD) - if strings.Contains(res, "true") { - utl.Log("OUTPUT", "fe start successfully.") - return true - } - time.Sleep(time.Duration(5) * time.Second) - } + if strings.Contains(res, "true") { + utl.Log("OUTPUT", "fe start successfully.") + return true + } + time.Sleep(time.Duration(5) * time.Second) + } - return false + return false } - - diff --git a/scripts/validate-multipass-shared-data.sh b/scripts/validate-multipass-shared-data.sh new file mode 100755 index 0000000..dbceb4c --- /dev/null +++ b/scripts/validate-multipass-shared-data.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ $# -ne 3 ]]; then + echo "usage: $0 " + exit 2 +fi + +cluster_name="$1" +version="$2" +config_yaml="$3" +bin="${STARGO_BIN:-./stargo}" + +"$bin" cluster deploy "$cluster_name" "$version" "$config_yaml" +"$bin" cluster display "$cluster_name" + +echo "Run SQL CRUD validation from an FE host after deploy if this environment does not expose FE query_port locally." +echo "Then run:" +echo " $bin cluster stop $cluster_name" +echo " $bin cluster start $cluster_name" +echo " $bin cluster import ${cluster_name}-imported $config_yaml" diff --git a/scripts/validate-multipass-shared-nothing.sh b/scripts/validate-multipass-shared-nothing.sh new file mode 100755 index 0000000..dbceb4c --- /dev/null +++ b/scripts/validate-multipass-shared-nothing.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ $# -ne 3 ]]; then + echo "usage: $0 " + exit 2 +fi + +cluster_name="$1" +version="$2" +config_yaml="$3" +bin="${STARGO_BIN:-./stargo}" + +"$bin" cluster deploy "$cluster_name" "$version" "$config_yaml" +"$bin" cluster display "$cluster_name" + +echo "Run SQL CRUD validation from an FE host after deploy if this environment does not expose FE query_port locally." +echo "Then run:" +echo " $bin cluster stop $cluster_name" +echo " $bin cluster start $cluster_name" +echo " $bin cluster import ${cluster_name}-imported $config_yaml" diff --git a/sr-c1.yaml b/sr-c1.yaml index b382120..36d52f6 100644 --- a/sr-c1.yaml +++ b/sr-c1.yaml @@ -1,6 +1,9 @@ global: - user: "starrocks" - ssh_port: 22 + user: "starrocks" + ssh_port: 22 + jdk_version: "17.0.8" + jdk_home: "" + os_type: "centos" fe_servers: - host: 192.168.88.83 @@ -14,6 +17,8 @@ fe_servers: log_dir: /data/starrocks/fe/log priority_networks: 192.168.88.0/24 config: + run_mode: "shared_data" + cloud_native_meta_port: "6090" sys_log_level: "INFO" sys_log_delete_age: "1d" - host: 192.168.88.84 @@ -27,6 +32,8 @@ fe_servers: log_dir: /data/starrocks/fe/log priority_networks: 192.168.88.0/24 config: + run_mode: "shared_data" + cloud_native_meta_port: "6090" sys_log_delete_age: "2d" - host: 192.168.88.85 ssh_port: 22 @@ -39,43 +46,38 @@ fe_servers: log_dir: /data/starrocks/fe/log priority_networks: 192.168.88.0/24 config: + run_mode: "shared_data" + cloud_native_meta_port: "6090" sys_log_delete_age: "3d" -be_servers: - - host: 192.168.88.83 +cn_servers: + - host: 10.149.50.223 ssh_port: 22 be_port: 9060 webserver_port: 8040 heartbeat_service_port: 9050 brpc_port: 8060 - deploy_dir : /opt/starrocks/be - storage_dir: /data/starrocks/be/storage - log_dir: /data/starrocks/be/log - priority_networks: 192.168.88.0/24 + starlet_port: 9070 + deploy_dir: /opt/starrocks/cn + storage_dir: /data/starrocks/cn/storage + log_dir: /data/starrocks/cn/log + priority_networks: 10.149.50.0/24 + warehouse_name: default_warehouse config: + storage_root_path: "/data/starrocks/cn/storage" create_tablet_worker_count: 3 - - host: 192.168.88.84 + - host: 10.149.50.153 ssh_port: 22 be_port: 9060 webserver_port: 8040 heartbeat_service_port: 9050 brpc_port: 8060 - deploy_dir : /opt/starrocks/be - storage_dir: /data/starrocks/be/storage - log_dir: /data/starrocks/be/log - priority_networks: 192.168.88.0/24 + starlet_port: 9070 + deploy_dir: /opt/starrocks/cn + storage_dir: /data/starrocks/cn/storage + log_dir: /data/starrocks/cn/log + priority_networks: 10.149.50.0/24 + warehouse_name: default_warehouse config: + storage_root_path: "/data/starrocks/cn/storage" create_tablet_worker_count: 3 - - host: 192.168.88.85 - ssh_port: 22 - be_port: 9060 - webserver_port: 8040 - heartbeat_service_port: 9050 - brpc_port: 8060 - deploy_dir : /opt/starrocks/be - storage_dir: /data/starrocks/be/storage - log_dir: /data/starrocks/be/log - priority_networks: 192.168.88.0/24 - config: - create_tablet_worker_count: 3 - diff --git a/sr-test.yaml b/sr-test.yaml index d40cd9d..e6a9424 100644 --- a/sr-test.yaml +++ b/sr-test.yaml @@ -1,7 +1,6 @@ - global: - user: "starrocks" - ssh_port: 22 + user: "starrocks" + ssh_port: 22 fe_servers: - host: 192.168.88.81 @@ -25,7 +24,7 @@ be_servers: webserver_port: 8040 heartbeat_service_port: 9050 brpc_port: 8060 - deploy_dir : /opt/starrocks/be + deploy_dir: /opt/starrocks/be storage_dir: /opt/starrocks/be/storage log_dir: /opt/starrocks/be/log priority_networks: 192.168.88.80/24 diff --git a/sr-utl/dbConnect.go b/sr-utl/dbConnect.go index c661d72..19fe413 100644 --- a/sr-utl/dbConnect.go +++ b/sr-utl/dbConnect.go @@ -1,41 +1,41 @@ -package utl +package utl -import( - "fmt" - "database/sql" - _ "github.com/go-sql-driver/mysql" +import ( + "database/sql" + "fmt" + + _ "github.com/go-sql-driver/mysql" ) -func RunSQL(userName string, password string, ip string, port int, dbName string, sqlStat string) (rows *sql.Rows, err error){ - - var infoMess string - dbPath := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", userName, password, ip, port, dbName) - DB, err := sql.Open("mysql", dbPath) - if err != nil{ - infoMess = fmt.Sprintf("Error in open db [dbPath = %s], error = %v", dbPath, err) - Log("ERROR", infoMess) - return nil, err - } - defer DB.Close() - - - err = DB.Ping() - if err != nil{ - infoMess = fmt.Sprintf("Error in ping db [dbPath = %s], error = %v", dbPath, err) - Log("ERROR", infoMess) - return nil, err - } - - rows, err = DB.Query(sqlStat) - if err != nil{ - infoMess = fmt.Sprintf(`Error in run sql: +func RunSQL(userName string, password string, ip string, port int, dbName string, sqlStat string) (rows *sql.Rows, err error) { + + var infoMess string + dbPath := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", userName, password, ip, port, dbName) + DB, err := sql.Open("mysql", dbPath) + if err != nil { + infoMess = fmt.Sprintf("Error in open db [dbPath = %s], error = %v", dbPath, err) + Log("ERROR", infoMess) + return nil, err + } + defer DB.Close() + + err = DB.Ping() + if err != nil { + infoMess = fmt.Sprintf("Error in ping db [dbPath = %s], error = %v", dbPath, err) + Log("ERROR", infoMess) + return nil, err + } + + rows, err = DB.Query(sqlStat) + if err != nil { + infoMess = fmt.Sprintf(`Error in run sql: dbPath = %s SQL = %s error = %v`, dbPath, sqlStat, err) - Log("DEBUG", infoMess) - return nil, err - } + Log("DEBUG", infoMess) + return nil, err + } - return rows, err + return rows, err } diff --git a/sr-utl/decompress.go b/sr-utl/decompress.go index 241a4b1..d9c27da 100644 --- a/sr-utl/decompress.go +++ b/sr-utl/decompress.go @@ -1,67 +1,69 @@ package utl import ( - "archive/tar" - "compress/gzip" - "fmt" - "io" - "os" - "path/filepath" - "strings" + "archive/tar" + "compress/gzip" + "fmt" + "io" + "os" + "path/filepath" + "strings" ) - func UnTargz(tarFile string, targetPath string) (err error) { - file, err := os.Open(tarFile) - if err != nil { return err } - gz, err := gzip.NewReader(file) - if err != nil { return err } - // This does not close file - defer gz.Close() + file, err := os.Open(tarFile) + if err != nil { + return err + } + gz, err := gzip.NewReader(file) + if err != nil { + return err + } + // This does not close file + defer gz.Close() - tarReader := tar.NewReader(gz) + tarReader := tar.NewReader(gz) - for { - header, err := tarReader.Next() - if err == io.EOF { - break - } else if err != nil { - return err - } + for { + header, err := tarReader.Next() + if err == io.EOF { + break + } else if err != nil { + return err + } - path := filepath.Join(targetPath, header.Name) + path := filepath.Join(targetPath, header.Name) - if !strings.HasPrefix(path, filepath.Clean(targetPath)+string(os.PathSeparator)) { - err = fmt.Errorf("%s: illegal file path", path) - return err - } + if !strings.HasPrefix(path, filepath.Clean(targetPath)+string(os.PathSeparator)) { + err = fmt.Errorf("%s: illegal file path", path) + return err + } - info := header.FileInfo() - if info.IsDir() { - if err = os.MkdirAll(path, info.Mode()); err != nil { - return err - } - continue - } + info := header.FileInfo() + if info.IsDir() { + if err = os.MkdirAll(path, info.Mode()); err != nil { + return err + } + continue + } - file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode()) - if err != nil { - return err - } + file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode()) + if err != nil { + return err + } - _, err = io.Copy(file, tarReader) - if err != nil { - file.Close() - return err - } + _, err = io.Copy(file, tarReader) + if err != nil { + file.Close() + return err + } - err = file.Close() - if err != nil { - return err - } - } + err = file.Close() + if err != nil { + return err + } + } - return nil + return nil } - diff --git a/sr-utl/dirOption.go b/sr-utl/dirOption.go index 311dd3d..e1304d9 100644 --- a/sr-utl/dirOption.go +++ b/sr-utl/dirOption.go @@ -1,72 +1,71 @@ package utl import ( - "os" - "io" - "fmt" + "fmt" + "io" + "os" ) - func MkDir(dirPath string) { - // check dir exists - mess := "" - dir, _ := os.Stat(dirPath) - if dir == nil { - // dir doesn't exist, create new one - e := os.MkdirAll(dirPath, 0755) - if e != nil { - mess = "Error in create folder [" + dirPath + "]" - Log("ERROR", mess) - panic(e) - } - } else { - mess = "Detect the folder [" + dirPath + "] exists" - Log("DEBUG", mess) - } + // check dir exists + mess := "" + dir, _ := os.Stat(dirPath) + if dir == nil { + // dir doesn't exist, create new one + e := os.MkdirAll(dirPath, 0755) + if e != nil { + mess = "Error in create folder [" + dirPath + "]" + Log("ERROR", mess) + panic(e) + } + } else { + mess = "Detect the folder [" + dirPath + "] exists" + Log("DEBUG", mess) + } } func CopyFile(sourceFileName string, targetFileName string) (fileByte int64, err error) { - var infoMess string + var infoMess string - sourceFileStat, err := os.Stat(sourceFileName) + sourceFileStat, err := os.Stat(sourceFileName) - if err != nil { - infoMess = fmt.Sprintf("Error in copy file, the source file doesn't exist [sourceFile = %, targetFile = %s]", sourceFileName, targetFileName) - Log("ERROR", infoMess) - return 0, err - } + if err != nil { + infoMess = fmt.Sprintf("Error in copy file, the source file doesn't exist [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) + Log("ERROR", infoMess) + return 0, err + } - if !sourceFileStat.Mode().IsRegular() { - infoMess = fmt.Sprintf("Error in copy file, the source file isn't a regular file [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) - Log("ERROR", infoMess) - return 0, err - } + if !sourceFileStat.Mode().IsRegular() { + infoMess = fmt.Sprintf("Error in copy file, the source file isn't a regular file [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) + Log("ERROR", infoMess) + return 0, err + } - src, err := os.Open(sourceFileName) - if err != nil { - infoMess = fmt.Sprintf("Error in copy file, the source file cannot be opened [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) - Log("ERROR", infoMess) - return 0, err - } - defer src.Close() + src, err := os.Open(sourceFileName) + if err != nil { + infoMess = fmt.Sprintf("Error in copy file, the source file cannot be opened [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) + Log("ERROR", infoMess) + return 0, err + } + defer src.Close() - dest, err := os.Create(targetFileName) - if err != nil { - infoMess = fmt.Sprintf("Error in copy file, the target file cannot be created [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) - Log("ERROR", infoMess) - return 0, err - } - defer dest.Close() + dest, err := os.Create(targetFileName) + if err != nil { + infoMess = fmt.Sprintf("Error in copy file, the target file cannot be created [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) + Log("ERROR", infoMess) + return 0, err + } + defer dest.Close() - fileByte, err = io.Copy(dest, src) - if err != nil { - infoMess = fmt.Sprintf("Error in copy file [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) - Log("ERROR", infoMess) - return 0, err - } + fileByte, err = io.Copy(dest, src) + if err != nil { + infoMess = fmt.Sprintf("Error in copy file [sourceFile = %s, targetFile = %s]", sourceFileName, targetFileName) + Log("ERROR", infoMess) + return 0, err + } - return fileByte, err + return fileByte, err } diff --git a/sr-utl/download.go b/sr-utl/download.go index 5cc4215..643a189 100644 --- a/sr-utl/download.go +++ b/sr-utl/download.go @@ -1,103 +1,112 @@ package utl import ( - - "io" - "net/http" - "os" - "fmt" - "strconv" - + "fmt" + "io" + "net/http" + "os" + "strconv" ) - func IsFileExist(absFileName string, fileSize int64) bool { - var infoMess string - info, err := os.Stat(absFileName) + var infoMess string + info, err := os.Stat(absFileName) - if os.IsNotExist(err) { - infoMess = fmt.Sprintf("Detect file %s doesn't exist.", absFileName) - Log("DEBUG", infoMess) - return false - } + if os.IsNotExist(err) { + infoMess = fmt.Sprintf("Detect file %s doesn't exist.", absFileName) + Log("DEBUG", infoMess) + return false + } - if fileSize == info.Size() { - infoMess = fmt.Sprintf("The package has already exist [fileName = %v, fileSize = %v, fileModTime = %v]", info.Name(), info.Size(), info.ModTime()) - Log("INFO", infoMess) - return true - } + if fileSize > 0 && fileSize == info.Size() { + infoMess = fmt.Sprintf("The package has already exist [fileName = %v, fileSize = %v, fileModTime = %v]", info.Name(), info.Size(), info.ModTime()) + Log("INFO", infoMess) + return true + } - del := os.Remove(absFileName) - if del != nil { - infoMess = fmt.Sprintf("Delete file %s", absFileName) - Log("WARN", infoMess) - } + del := os.Remove(absFileName) + if del != nil { + infoMess = fmt.Sprintf("Delete file %s", absFileName) + Log("WARN", infoMess) + } - return false + return false } - -func DownloadFile(fileUrl string, localPath string, fileName string) { - - var infoMess string - tmpFileName := localPath + "/" + fileName + ".download" - absFileName := localPath + "/" + fileName - - client := new(http.Client) - resp, err := client.Get(fileUrl) - if err != nil { - infoMess = fmt.Sprintf("Error in get the response for %s", fileUrl) - Log("ERROR", infoMess) - panic(err) - } - - fileSize, err := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 32) - if err != nil { - infoMess = fmt.Sprintf("Error in parsing the size for file %s", fileUrl) - Log("ERROR", infoMess) - } - - if IsFileExist(absFileName, fileSize) { - // the file exist, it doesn't need to download the one - return - } - - tmpFile, err := os.Create(tmpFileName) - if err != nil { - infoMess = fmt.Sprintf("Error in create the tmp file %s", tmpFileName) - Log("ERROR", infoMess) - panic(err) - } - defer tmpFile.Close() - - - if resp.Body == nil { - Log("ERROR", "The download file Body is null.") - Log("ERROR", infoMess) - panic(err) - } - - io.Copy(tmpFile, resp.Body) - info, err := os.Stat(tmpFileName) - if err != nil { - infoMess = fmt.Sprintf("Cannot get the tmp file stat [fileName = %s]", tmpFileName) - Log("ERROR", infoMess) - panic(err) - } - - if info.Size() != fileSize { - infoMess = fmt.Sprintf("Error in download, pls check your network connection.") - Log("ERROR", infoMess) - panic(err) - } - - if err == nil { - err = os.Rename(tmpFileName, absFileName) - } - - infoMess = fmt.Sprintf("The file %s [%d] download successfully", fileName, fileSize) - Log("INFO", infoMess) - +func DownloadFile(fileUrl string, localPath string, fileName string) error { + + var infoMess string + tmpFileName := localPath + "/" + fileName + ".download" + absFileName := localPath + "/" + fileName + + client := new(http.Client) + resp, err := client.Get(fileUrl) + if err != nil { + infoMess = fmt.Sprintf("Error in get the response for %s", fileUrl) + Log("ERROR", infoMess) + return err + } + defer resp.Body.Close() + + fileSize := int64(-1) + if contentLength := resp.Header.Get("Content-Length"); contentLength != "" { + fileSize, err = strconv.ParseInt(contentLength, 10, 32) + if err != nil { + infoMess = fmt.Sprintf("Error in parsing the size for file %s", fileUrl) + Log("WARN", infoMess) + fileSize = -1 + } + } + + if IsFileExist(absFileName, fileSize) { + // the file exist, it doesn't need to download the one + return nil + } + + tmpFile, err := os.Create(tmpFileName) + if err != nil { + infoMess = fmt.Sprintf("Error in create the tmp file %s", tmpFileName) + Log("ERROR", infoMess) + return err + } + defer tmpFile.Close() + + if resp.Body == nil { + Log("ERROR", "The download file Body is null.") + return fmt.Errorf("response body is empty for %s", fileUrl) + } + + if _, err = io.Copy(tmpFile, resp.Body); err != nil { + infoMess = fmt.Sprintf("Error while downloading file %s", fileUrl) + Log("ERROR", infoMess) + return err + } + + info, err := os.Stat(tmpFileName) + if err != nil { + infoMess = fmt.Sprintf("Cannot get the tmp file stat [fileName = %s]", tmpFileName) + Log("ERROR", infoMess) + return err + } + + if fileSize > 0 && info.Size() != fileSize { + infoMess = fmt.Sprintf("Error in download, pls check your network connection.") + Log("ERROR", infoMess) + return fmt.Errorf("download incomplete for %s", fileUrl) + } + + if err == nil { + err = os.Rename(tmpFileName, absFileName) + if err != nil { + infoMess = fmt.Sprintf("Error in rename tmp file %s", tmpFileName) + Log("ERROR", infoMess) + return err + } + } + + infoMess = fmt.Sprintf("The file %s [%d] download successfully", fileName, fileSize) + Log("INFO", infoMess) + + return nil } - diff --git a/sr-utl/message.go b/sr-utl/message.go index 7d67c3f..75dad41 100644 --- a/sr-utl/message.go +++ b/sr-utl/message.go @@ -1,17 +1,17 @@ package utl -import( - "fmt" - "time" - "os" -// "io" -// "io/ioutil" - "bufio" +import ( + "fmt" + "os" + "time" + // "io" + // "io/ioutil" + "bufio" ) /* -LogLevel +LogLevel - DEBUG 10 - INFO 20 - WARN 30 @@ -23,55 +23,46 @@ var GLOGLEVEL string = "DEBUG" func Log(logLevel string, mess string) { + dt := string(time.Now().Format("20060102-150405")) - dt := string(time.Now().Format("20060102-150405")) + debugFile := "debug.log" - debugFile := "debug.log" + if GLOGLEVEL == "DEBUG" { - if GLOGLEVEL == "DEBUG" { - - /* - file, err := os.OpenFile(debugFile, os.O_APPEND|os.O_CREATE, 0666) - if err != nil { - fmt.Printf("Error in open debug.log") + /* + file, err := os.OpenFile(debugFile, os.O_APPEND|os.O_CREATE, 0666) + if err != nil { + fmt.Printf("Error in open debug.log") + } + defer file.Close() + logMess := fmt.Sprintf("[%s %s] %s", dt, logLevel, mess) + _, _ = io.WriteString(file, logMess) + */ + logMess := fmt.Sprintf("[%s %s] %s\n", dt, logLevel, mess) + file, err := os.OpenFile(debugFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + if err == nil { + defer file.Close() + write := bufio.NewWriter(file) + _, _ = write.WriteString(logMess) + _ = write.Flush() + } } - defer file.Close() - logMess := fmt.Sprintf("[%s %s] %s", dt, logLevel, mess) - _, _ = io.WriteString(file, logMess) - */ - logMess := fmt.Sprintf("[%s %s] %s", dt, logLevel, mess) - file, _ := os.OpenFile(debugFile, os.O_WRONLY|os.O_APPEND, 0666) - defer file.Close() - write := bufio.NewWriter(file) - write.WriteString(logMess) - write.Flush() - } - // logLevel: DEBUG INFO WARN ERROR + // logLevel: DEBUG INFO WARN ERROR - switch logLevel { - case "DEBUG": - // output: DEBUG INFO WARN ERROR - //fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) - debugFile = "debug.log" - case "INFO": - if logLevel != "DEBUG" { - fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) - } + switch logLevel { + case "DEBUG": + return + case "INFO": + fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) case "WARN": - if logLevel != "DEBUG" || logLevel != "INFO" { - fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) - } + fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) case "ERROR": - if logLevel != "DEBUG" || logLevel != "INFO" || logLevel != "WARN" { - fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) - } + fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) default: - fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) - } - //fmt.Printf("%s %8s %15s %s\n", dt, logLevel, process, mess) - //fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) + fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) + } + //fmt.Printf("%s %8s %15s %s\n", dt, logLevel, process, mess) + //fmt.Printf("[\x1b[47;30m%s\x1b[0m\x1b[43;30m%8s\x1b[0m] %s\n", dt, logLevel, mess) } - - diff --git a/sr-utl/modifyConfig.go b/sr-utl/modifyConfig.go index 14d4eef..180fbb7 100644 --- a/sr-utl/modifyConfig.go +++ b/sr-utl/modifyConfig.go @@ -1,43 +1,43 @@ package utl import ( - "bytes" - "fmt" - "strings" - "io/ioutil" - "os" - "regexp" + "bytes" + "fmt" + "io/ioutil" + "os" + "regexp" + "strings" ) - -func ModifyConfig(fileName string, sourceStr string, targetStr string) (err error){ - - var infoMess string - _, err = os.Stat(fileName) - if err != nil { - infoMess = fmt.Sprintf("Error in modifing configuration, the configuration file doesn't exist [fileName = %s, sourceStr = %s, targetStr = %s]", fileName, sourceStr, targetStr) - Log("ERROR", infoMess) - return err - } - - input, err := ioutil.ReadFile(fileName) - if err != nil { - infoMess = fmt.Sprintf("Error in modifing configuration, cannot read file [fileName = %s, sourceStr = %s, targetStr = %s]", fileName, sourceStr, targetStr) - Log("ERROR", infoMess) - return err - } - - output := bytes.Replace(input, []byte(sourceStr), []byte(targetStr), -1) - - err = ioutil.WriteFile(fileName, output, 0644) - if err != nil { - infoMess = fmt.Sprintf("Error in modifing configuration, cannot read file [fileName = %s, output = %s]", fileName, output) - Log("ERROR", infoMess) - return err - } - - return nil +func ModifyConfig(fileName string, sourceStr string, targetStr string) (err error) { + + var infoMess string + _, err = os.Stat(fileName) + if err != nil { + infoMess = fmt.Sprintf("Error in modifing configuration, the configuration file doesn't exist [fileName = %s, sourceStr = %s, targetStr = %s]", fileName, sourceStr, targetStr) + Log("ERROR", infoMess) + return err + } + + input, err := ioutil.ReadFile(fileName) + if err != nil { + infoMess = fmt.Sprintf("Error in modifing configuration, cannot read file [fileName = %s, sourceStr = %s, targetStr = %s]", fileName, sourceStr, targetStr) + Log("ERROR", infoMess) + return err + } + + output := bytes.Replace(input, []byte(sourceStr), []byte(targetStr), -1) + + err = ioutil.WriteFile(fileName, output, 0644) + if err != nil { + infoMess = fmt.Sprintf("Error in modifing configuration, cannot read file [fileName = %s, output = %s]", fileName, output) + Log("ERROR", infoMess) + return err + } + + return nil } + /* func AppendConfig(fileName string, configStr string) (err error){ @@ -59,7 +59,7 @@ func AppendConfig(fileName string, configStr string) (err error){ // if the config exists - + _, err = file.WriteString(configStr + "\n") if err != nil { infoMess = fmt.Sprintf("Error in appending configuration, cannot write configStr [fileName = %s, configStr = %s]", fileName, configStr) @@ -70,55 +70,51 @@ func AppendConfig(fileName string, configStr string) (err error){ return err -} +} */ - -func AppendConfig(fileName string, configKey string, configValue string) (err error){ - - var infoMess string - _, err = os.Stat(fileName) - if err != nil { - infoMess = fmt.Sprintf("Error in appending configuration, the configuration file doesn't exist [fileName = %s, configkey = %s, configValue = %s]", fileName, configKey, configValue) - Log("ERROR", infoMess) - return err - } - - - configFile, err := ioutil.ReadFile(fileName) - if err != nil { - infoMess = fmt.Sprintf("Error in appending configuration, read configuration file failed [fileName = %s, configKey = %s, configValue = %s]", fileName, configKey, configValue) - Log("ERROR", infoMess) - return err - } - - lines := strings.Split(string(configFile), "\n") - - for i, line := range lines { - pattern := fmt.Sprintf("^%s.*", configKey) - match, _ := regexp.MatchString(pattern, line) - if match { - infoMess := fmt.Sprintf("Comment the default value [fileName = %s, configKey = %s, configValue = %s]", fileName, configKey, configValue) - Log("DEBUG", infoMess) - lines[i] = "# " + lines[i] + "\t\t\t## comment by stargo" - } - } - - configStr := fmt.Sprintf("\n%s = %s\n", configKey, configValue) - output := strings.Join(lines, "\n") - output = output + configStr - - err = ioutil.WriteFile(fileName, []byte(output), 0644) - if err != nil { - infoMess = fmt.Sprintf("Error in appending configuration, write the result to config file failed [fileName = %s, configStr= %s]", fileName, configStr) - Log("ERROR", infoMess) - } - - infoMess = fmt.Sprintf("Append configuration [fileName = %s, configStr= %s]", fileName, strings.Replace(configStr, "\n", "", -1)) - Log("DEBUG", infoMess) - - return nil - +func AppendConfig(fileName string, configKey string, configValue string) (err error) { + + var infoMess string + _, err = os.Stat(fileName) + if err != nil { + infoMess = fmt.Sprintf("Error in appending configuration, the configuration file doesn't exist [fileName = %s, configkey = %s, configValue = %s]", fileName, configKey, configValue) + Log("ERROR", infoMess) + return err + } + + configFile, err := ioutil.ReadFile(fileName) + if err != nil { + infoMess = fmt.Sprintf("Error in appending configuration, read configuration file failed [fileName = %s, configKey = %s, configValue = %s]", fileName, configKey, configValue) + Log("ERROR", infoMess) + return err + } + + lines := strings.Split(string(configFile), "\n") + + for i, line := range lines { + pattern := fmt.Sprintf("^%s.*", configKey) + match, _ := regexp.MatchString(pattern, line) + if match { + infoMess := fmt.Sprintf("Comment the default value [fileName = %s, configKey = %s, configValue = %s]", fileName, configKey, configValue) + Log("DEBUG", infoMess) + lines[i] = "# " + lines[i] + "\t\t\t## comment by stargo" + } + } + + configStr := fmt.Sprintf("\n%s = %s\n", configKey, configValue) + output := strings.Join(lines, "\n") + output = output + configStr + + err = ioutil.WriteFile(fileName, []byte(output), 0644) + if err != nil { + infoMess = fmt.Sprintf("Error in appending configuration, write the result to config file failed [fileName = %s, configStr= %s]", fileName, configStr) + Log("ERROR", infoMess) + } + + infoMess = fmt.Sprintf("Append configuration [fileName = %s, configStr= %s]", fileName, strings.Replace(configStr, "\n", "", -1)) + Log("DEBUG", infoMess) + + return nil } - diff --git a/sr-utl/precheck.go b/sr-utl/precheck.go index 0006fa0..977918f 100644 --- a/sr-utl/precheck.go +++ b/sr-utl/precheck.go @@ -1,18 +1,16 @@ package utl import ( - "os/exec" + "os/exec" ) - func PortUsed(portStr string) bool { - output, _ := exec.Command("/bin/bash", "-c", "netstat -na | grep " + portStr + " | grep -v ESTABLISHED").CombinedOutput() + output, _ := exec.Command("/bin/bash", "-c", "netstat -na | grep "+portStr+" | grep -v ESTABLISHED").CombinedOutput() - if len(output) > 0 { - return true - } else { - return false - } + if len(output) > 0 { + return true + } else { + return false + } } - diff --git a/sr-utl/runProcesser.go b/sr-utl/runProcesser.go index 0dea6e3..f73782b 100644 --- a/sr-utl/runProcesser.go +++ b/sr-utl/runProcesser.go @@ -1,26 +1,23 @@ package utl import ( - "os/exec" - "fmt" + "fmt" + "os/exec" ) // Run local shell command func RunShellScript(scriptName string) (string, error) { - var errmess string - cmd := exec.Command("/bin/bash", "-c", scriptName) - res, err := cmd.Output() - if err != nil { - errmess = fmt.Sprintf("Error in run command [ %s ], err = %v", scriptName, err) - Log("DEBUG", errmess) - //panic(err) - return "", err - } + var errmess string + cmd := exec.Command("/bin/bash", "-c", scriptName) + res, err := cmd.Output() + if err != nil { + errmess = fmt.Sprintf("Error in run command [ %s ], err = %v", scriptName, err) + Log("DEBUG", errmess) + //panic(err) + return "", err + } - - return string(res), nil + return string(res), nil } // Run ssh shell command - - diff --git a/sr-utl/sshRun.go b/sr-utl/sshRun.go index 26c91f0..7daf59f 100644 --- a/sr-utl/sshRun.go +++ b/sr-utl/sshRun.go @@ -1,397 +1,385 @@ package utl import ( - "fmt" - "os" - "path" - "golang.org/x/crypto/ssh" - "github.com/pkg/sftp" - "io/ioutil" -) - - + "fmt" + "io/ioutil" + "os" + "path" + "github.com/pkg/sftp" + "golang.org/x/crypto/ssh" +) -func NewConfig(keyFile string, user string)(config *ssh.ClientConfig, err error) { +func NewConfig(keyFile string, user string) (config *ssh.ClientConfig, err error) { - var errmess string + var errmess string - key, err := ioutil.ReadFile(keyFile) - if err != nil { - errmess = fmt.Sprint("unable to read private key: %v", err) - Log("ERROR", errmess) - return nil, err - } + key, err := ioutil.ReadFile(keyFile) + if err != nil { + errmess = fmt.Sprintf("unable to read private key: %v", err) + Log("ERROR", errmess) + return nil, err + } - signer, err := ssh.ParsePrivateKey(key) - if err != nil { - errmess = fmt.Sprint("unable to parse private key: %v", err) - Log("ERROR", errmess) - return nil, err - } + signer, err := ssh.ParsePrivateKey(key) + if err != nil { + errmess = fmt.Sprintf("unable to parse private key: %v", err) + Log("ERROR", errmess) + return nil, err + } - config = &ssh.ClientConfig{ - User: user, - Auth: []ssh.AuthMethod{ - ssh.PublicKeys(signer), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - } + config = &ssh.ClientConfig{ + User: user, + Auth: []ssh.AuthMethod{ + ssh.PublicKeys(signer), + }, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), + } - return config, nil + return config, nil } func sshRun(config *ssh.ClientConfig, host string, port int, command string) (outPut []byte, err error) { - var errmess string - var infoMess string - client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", host, port), config) - if err != nil { - errmess = fmt.Sprintf("unable to connect: %s error %v", host, err) - Log("ERROR", errmess) - return nil, err - } - defer client.Close() - - session, err := client.NewSession() - if err != nil{ - errmess = fmt.Sprint("ssh new session error %v", err) - Log("ERROR", errmess) - return nil, err - } - defer session.Close() - - outPut, err = session.CombinedOutput(command) - if err != nil { - if v, ok := err.(*ssh.ExitError); ok { - errmess = v.Msg() - } - } - - infoMess = fmt.Sprintf(`ssh run: + var errmess string + var infoMess string + client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", host, port), config) + if err != nil { + errmess = fmt.Sprintf("unable to connect: %s error %v", host, err) + Log("ERROR", errmess) + return nil, err + } + defer client.Close() + + session, err := client.NewSession() + if err != nil { + errmess = fmt.Sprintf("ssh new session error %v", err) + Log("ERROR", errmess) + return nil, err + } + defer session.Close() + + outPut, err = session.CombinedOutput(command) + if err != nil { + if v, ok := err.(*ssh.ExitError); ok { + errmess = v.Msg() + } + } + + infoMess = fmt.Sprintf(`ssh run: host = %s cmd = %s error = %v result = %v`, host, command, errmess, string(outPut)) - Log("DEBUG", infoMess) + Log("DEBUG", infoMess) - return outPut, err + return outPut, err } func SshRun(user string, keyFile string, host string, port int, command string) (outPut []byte, err error) { - var infoMess string + var infoMess string - sshConfig, err := NewConfig(keyFile, user) - if err != nil { - infoMess = fmt.Sprintf("Failed to get the ssh config when run command [user = %s, host = %s, port = %d, cmd = %s], error = %v", user, host, port, command, err) - Log("DEBUG", infoMess) - } + sshConfig, err := NewConfig(keyFile, user) + if err != nil { + infoMess = fmt.Sprintf("Failed to get the ssh config when run command [user = %s, host = %s, port = %d, cmd = %s], error = %v", user, host, port, command, err) + Log("DEBUG", infoMess) + } - output, err := sshRun(sshConfig, host, port, command) - if err != nil { - infoMess = fmt.Sprintf("Failed to run command. [host = %s, cmd = %s, error = %v]", host, command, err) - Log("DEBUG", infoMess) - } - return output, err + output, err := sshRun(sshConfig, host, port, command) + if err != nil { + infoMess = fmt.Sprintf("Failed to run command. [host = %s, cmd = %s, error = %v]", host, command, err) + Log("DEBUG", infoMess) + } + return output, err } func sftpConnect(config *ssh.ClientConfig, host string, port int) (sfpClient *sftp.Client, err error) { - var infoMess string - addr := fmt.Sprintf("%s:%d", host, port) + var infoMess string + addr := fmt.Sprintf("%s:%d", host, port) - sshClient, err := ssh.Dial("tcp", addr, config) - if err != nil { - infoMess = fmt.Sprintf("Error in dail %s, %s", addr, config) - Log("ERROR", infoMess) - return nil, err - } + sshClient, err := ssh.Dial("tcp", addr, config) + if err != nil { + infoMess = fmt.Sprintf("Error in dial %s: %v", addr, err) + Log("ERROR", infoMess) + return nil, err + } - sftpClient, err := sftp.NewClient(sshClient) - if err != nil { - infoMess = fmt.Sprintf("Error in get sftp client") - Log("ERROR", infoMess) - return nil, err - } + sftpClient, err := sftp.NewClient(sshClient) + if err != nil { + infoMess = fmt.Sprintf("Error in get sftp client") + Log("ERROR", infoMess) + return nil, err + } - return sftpClient, nil + return sftpClient, nil } - func uploadFile(sftpClient *sftp.Client, localFileName string, remoteFileName string) (err error) { - var infoMess string + var infoMess string - srcFile, err := os.Open(localFileName) - if err != nil { - infoMess = fmt.Sprintf("Error in open file %s", localFileName) - Log("ERROR", infoMess) - return err - } - defer srcFile.Close() + srcFile, err := os.Open(localFileName) + if err != nil { + infoMess = fmt.Sprintf("Error in open file %s", localFileName) + Log("ERROR", infoMess) + return err + } + defer srcFile.Close() - dstFile, err := sftpClient.Create(remoteFileName) - if err != nil { - infoMess = fmt.Sprintf("sftpClient.Create error : %s, error = %v", remoteFileName, err) - Log("ERROR", infoMess) - return err - } - defer dstFile.Close() + dstFile, err := sftpClient.Create(remoteFileName) + if err != nil { + infoMess = fmt.Sprintf("sftpClient.Create error : %s, error = %v", remoteFileName, err) + Log("ERROR", infoMess) + return err + } + defer dstFile.Close() - ff, err := ioutil.ReadAll(srcFile) - if err != nil { - infoMess = fmt.Sprintf("ReadAll error : %s", localFileName) - Log("ERROR", infoMess) - return err - } - - dstFile.Write(ff) - //infoMess = localFileName + " copy file to remote server finished!" - //Log("DEBUG", infoMess) - // Chmod remoteFile - fileStat, err := os.Stat(localFileName) - if err != nil { - infoMess = fmt.Sprintf("Error in get file stat when upload file: [sourceFile = %s targetFile = %s]", localFileName, remoteFileName) - Log("ERROR", infoMess) - return err - } + ff, err := ioutil.ReadAll(srcFile) + if err != nil { + infoMess = fmt.Sprintf("ReadAll error : %s", localFileName) + Log("ERROR", infoMess) + return err + } + + dstFile.Write(ff) + //infoMess = localFileName + " copy file to remote server finished!" + //Log("DEBUG", infoMess) + // Chmod remoteFile + fileStat, err := os.Stat(localFileName) + if err != nil { + infoMess = fmt.Sprintf("Error in get file stat when upload file: [sourceFile = %s targetFile = %s]", localFileName, remoteFileName) + Log("ERROR", infoMess) + return err + } - err = sftpClient.Chmod(remoteFileName, fileStat.Mode()) - if err != nil { - infoMess = fmt.Sprintf("Error in chmod file stat when upload file: [sourceFile = %s targetFile = %s]", localFileName, remoteFileName) - Log("ERROR", infoMess) + err = sftpClient.Chmod(remoteFileName, fileStat.Mode()) + if err != nil { + infoMess = fmt.Sprintf("Error in chmod file stat when upload file: [sourceFile = %s targetFile = %s]", localFileName, remoteFileName) + Log("ERROR", infoMess) + return err + } + //infoMess = fmt.Sprintf("chmod file [%s] to %s", remoteFileName, fileStat.Mode()) + //Log("DEBUG", infoMess) + //Log("INFO", infoMess) return err - } - //infoMess = fmt.Sprintf("chmod file [%s] to %s", remoteFileName, fileStat.Mode()) - //Log("DEBUG", infoMess) - //Log("INFO", infoMess) - return err } - func uploadDirectory(sftpClient *sftp.Client, localPath string, remotePath string) (err error) { - var infoMess string - - localFiles, err := ioutil.ReadDir(localPath) - if err != nil { - infoMess = "Read dir list fail." - Log("ERROR", infoMess) - return err - } + var infoMess string - for _, backupDir := range localFiles { - - localFilePath := path.Join(localPath, backupDir.Name()) - remoteFilePath := path.Join(remotePath, backupDir.Name()) - - if backupDir.IsDir() { - sftpClient.Mkdir(remoteFilePath) - err = uploadDirectory(sftpClient, localFilePath, remoteFilePath) - if err != nil { - infoMess = fmt.Sprintf("Error in upload dir %s\t%s\t%s", sftpClient, localFilePath, remoteFilePath) - Log("ERROR", infoMess) - return err - } - } else { - localFileName := path.Join(localPath, backupDir.Name()) - remoteFileName := path.Join(remotePath, backupDir.Name()) - err = uploadFile(sftpClient, localFileName, remoteFileName) - if err != nil { - infoMess = fmt.Sprintf("Error in upload file %s\t%s\t%s", sftpClient, path.Join(localPath, backupDir.Name()), remotePath) + localFiles, err := ioutil.ReadDir(localPath) + if err != nil { + infoMess = "Read dir list fail." Log("ERROR", infoMess) return err - } - } - - } - - //infoMess = localPath + " copy directory to remote server finished!" - //Log("INFO", infoMess) - return err + } + + for _, backupDir := range localFiles { + + localFilePath := path.Join(localPath, backupDir.Name()) + remoteFilePath := path.Join(remotePath, backupDir.Name()) + + if backupDir.IsDir() { + sftpClient.Mkdir(remoteFilePath) + err = uploadDirectory(sftpClient, localFilePath, remoteFilePath) + if err != nil { + infoMess = fmt.Sprintf("Error in upload dir [%s -> %s]: %v", localFilePath, remoteFilePath, err) + Log("ERROR", infoMess) + return err + } + } else { + localFileName := path.Join(localPath, backupDir.Name()) + remoteFileName := path.Join(remotePath, backupDir.Name()) + err = uploadFile(sftpClient, localFileName, remoteFileName) + if err != nil { + infoMess = fmt.Sprintf("Error in upload file [%s -> %s]: %v", localFileName, remoteFileName, err) + Log("ERROR", infoMess) + return err + } + } + + } + + //infoMess = localPath + " copy directory to remote server finished!" + //Log("INFO", infoMess) + return err } - - func UploadFile(user string, keyFile string, host string, port int, sourceFile string, targetFile string) { - var infoMess string - - sshConfig, err := NewConfig(keyFile, user) - if err != nil { - infoMess = fmt.Sprintf("Error in upload file, fail to get ssh config [keyfile = %s, user = %s]", keyFile, user) - Log("ERROR", infoMess) - panic(err) - } - - sftpClient, err := sftpConnect(sshConfig, host, port) - if err != nil { - infoMess = fmt.Sprintf("Error in upload file, fail to get sftp client [keyfile = %s, user = %s, host = %s, port = %d]", keyFile, user, host, port) - Log("ERROR", infoMess) - panic(err) - } - - err = uploadFile(sftpClient, sourceFile, targetFile) - if err != nil { - infoMess = fmt.Sprintf("Error in upload file [user = %s, keyFile = %s, host = %s, port = %d, sourceFile = %s, targetFile = %s]", user, keyFile, host, port, sourceFile, targetFile) - Log("ERROR", infoMess) - panic(err) - } + var infoMess string -} + sshConfig, err := NewConfig(keyFile, user) + if err != nil { + infoMess = fmt.Sprintf("Error in upload file, fail to get ssh config [keyfile = %s, user = %s]", keyFile, user) + Log("ERROR", infoMess) + panic(err) + } + sftpClient, err := sftpConnect(sshConfig, host, port) + if err != nil { + infoMess = fmt.Sprintf("Error in upload file, fail to get sftp client [keyfile = %s, user = %s, host = %s, port = %d]", keyFile, user, host, port) + Log("ERROR", infoMess) + panic(err) + } + err = uploadFile(sftpClient, sourceFile, targetFile) + if err != nil { + infoMess = fmt.Sprintf("Error in upload file [user = %s, keyFile = %s, host = %s, port = %d, sourceFile = %s, targetFile = %s]", user, keyFile, host, port, sourceFile, targetFile) + Log("ERROR", infoMess) + panic(err) + } + +} func UploadDir(user string, keyFile string, host string, port int, sourceDir string, targetDir string) { - var infoMess string - var err error - // check the folder exist - cmd := fmt.Sprintf("ls %s", targetDir) - _, err = SshRun(user, keyFile, host, port, cmd) - if err != nil { - infoMess = fmt.Sprintf("The target dir [%s] doesn't exist on [%s:%d], create a new one", targetDir, host, port) - Log("DEBUG", infoMess) - cmd = fmt.Sprintf("mkdir -p %s", targetDir) - _, err := SshRun(user, keyFile, host, port, cmd) - if err != nil { - infoMess = fmt.Sprintf("Error in create folder [%s] on [%s:%d]", targetDir, host, port) - Log("ERROR", infoMess) - panic(err) - } - infoMess = fmt.Sprintf("Create folder [%s] on [%s:%d]", targetDir, host, port) - Log("DEBUG", infoMess) - } - - sshConfig, err := NewConfig(keyFile, user) - if err != nil { - infoMess = fmt.Sprintf(`Error in upload dir, failed to get the ssh config :user = %s, + var infoMess string + var err error + // check the folder exist + cmd := fmt.Sprintf("ls %s", targetDir) + _, err = SshRun(user, keyFile, host, port, cmd) + if err != nil { + infoMess = fmt.Sprintf("The target dir [%s] doesn't exist on [%s:%d], create a new one", targetDir, host, port) + Log("DEBUG", infoMess) + cmd = fmt.Sprintf("mkdir -p %s", targetDir) + _, err := SshRun(user, keyFile, host, port, cmd) + if err != nil { + infoMess = fmt.Sprintf("Error in create folder [%s] on [%s:%d]", targetDir, host, port) + Log("ERROR", infoMess) + panic(err) + } + infoMess = fmt.Sprintf("Create folder [%s] on [%s:%d]", targetDir, host, port) + Log("DEBUG", infoMess) + } + + sshConfig, err := NewConfig(keyFile, user) + if err != nil { + infoMess = fmt.Sprintf(`Error in upload dir, failed to get the ssh config :user = %s, keyFile = %s host = %s port = %d sourceDir = %s targetDir = %s error = %v`, user, keyFile, host, port, sourceDir, targetDir, err) - } - sftpClient, err := sftpConnect(sshConfig, host, port) - if err != nil { - infoMess = fmt.Sprintf(`Error in upload dir[sftp client]: user = %s + Log("ERROR", infoMess) + panic(err) + } + sftpClient, err := sftpConnect(sshConfig, host, port) + if err != nil { + infoMess = fmt.Sprintf(`Error in upload dir[sftp client]: user = %s keyFile = %s host = %s port = %d sourceDir = %s targetDir = %s error = %v`, user, keyFile, host, port, sourceDir, targetDir, err) - Log("ERROR", infoMess) - panic(err) - } + Log("ERROR", infoMess) + panic(err) + } - err = uploadDirectory(sftpClient, sourceDir, targetDir) - if err != nil { - infoMess = fmt.Sprintf(`Error in upload dir[upload dir]: user = %s + err = uploadDirectory(sftpClient, sourceDir, targetDir) + if err != nil { + infoMess = fmt.Sprintf(`Error in upload dir[upload dir]: user = %s keyFile = %s host = %s port = %d sourceDir = %s targetDir = %s error = %v`, user, keyFile, host, port, sourceDir, targetDir, err) - Log("ERROR", infoMess) - panic(err) - } + Log("ERROR", infoMess) + panic(err) + } } -func RenameDir(user string, keyFile string, host string, port int, sourceDir string, targetDir string) (err error){ - - var infoMess string - - cmd := fmt.Sprintf("ls %s", sourceDir) - _, err = SshRun(user, keyFile, host, port, cmd) - - if err != nil { - infoMess = fmt.Sprintf("The source dir [%s] doesn't exist on [%s:%d], create a new one", sourceDir, host, port) - Log("ERROR", infoMess) - return err - } - - sshConfig, err := NewConfig(keyFile, user) - if err != nil { - infoMess = fmt.Sprintf("Error in rename dir, failed to get the ssh config. [host = %s, sourceDir = %s, targetDir = %s, err = %v]", host, sourceDir, targetDir, err) - Log("ERROR", infoMess) - return err - } - - sftpClient, err := sftpConnect(sshConfig, host, port) - if err != nil { - infoMess = fmt.Sprintf("Error in rename dir when create sftp client.[host = %s, sourceDir = %s, targetDir = %s, error = %v", host, sourceDir, targetDir, err) - Log("ERROR", infoMess) - return err - } - err = sftpClient.Rename(sourceDir, targetDir) - if err != nil { - infoMess = fmt.Sprintf("Error in rename dir.[host = %s, sourceDir = %s, targetDir = %s, error = %v", host, sourceDir, targetDir, err) - Log("ERROR", infoMess) - return err - } - - return nil +func RenameDir(user string, keyFile string, host string, port int, sourceDir string, targetDir string) (err error) { -} + var infoMess string + cmd := fmt.Sprintf("ls %s", sourceDir) + _, err = SshRun(user, keyFile, host, port, cmd) -func RemoveDir(user string, keyFile string, host string, port int, dirName string) (err error) { + if err != nil { + infoMess = fmt.Sprintf("The source dir [%s] doesn't exist on [%s:%d], create a new one", sourceDir, host, port) + Log("ERROR", infoMess) + return err + } - var infoMess string - cmd := fmt.Sprintf("ls %s", dirName) - _, err = SshRun(user, keyFile, host, port, cmd) + sshConfig, err := NewConfig(keyFile, user) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir, failed to get the ssh config. [host = %s, sourceDir = %s, targetDir = %s, err = %v]", host, sourceDir, targetDir, err) + Log("ERROR", infoMess) + return err + } - if err != nil { - infoMess = fmt.Sprintf("The dir [%s] doesn't exist on [%s:%d]", dirName, host, port) - Log("DEBUG", infoMess) - } + sftpClient, err := sftpConnect(sshConfig, host, port) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir when create sftp client.[host = %s, sourceDir = %s, targetDir = %s, error = %v", host, sourceDir, targetDir, err) + Log("ERROR", infoMess) + return err + } + err = sftpClient.Rename(sourceDir, targetDir) + if err != nil { + infoMess = fmt.Sprintf("Error in rename dir.[host = %s, sourceDir = %s, targetDir = %s, error = %v", host, sourceDir, targetDir, err) + Log("ERROR", infoMess) + return err + } - sshConfig, err := NewConfig(keyFile, user) - if err != nil { - infoMess = fmt.Sprintf("Error in remove dir, failed to get the ssh config. [host = %s, dirName, err = %v]", host, dirName, err) - Log("ERROR", infoMess) - return err - } + return nil - sftpClient, err := sftpConnect(sshConfig, host, port) - if err != nil { - infoMess = fmt.Sprintf("Error in remove dir when create sftp client.[host = %s, dirName = %s, error = %v", host, dirName, err) - Log("ERROR", infoMess) - return err - } +} - err = sftpClient.RemoveDirectory(dirName) +func RemoveDir(user string, keyFile string, host string, port int, dirName string) (err error) { - if err != nil { - infoMess = fmt.Sprintf("Error in remove dir.[host = %s, dirName = %s, error = %v", host, dirName, err) - Log("ERROR", infoMess) - return err - } + var infoMess string + cmd := fmt.Sprintf("ls %s", dirName) + _, err = SshRun(user, keyFile, host, port, cmd) - return nil + if err != nil { + infoMess = fmt.Sprintf("The dir [%s] doesn't exist on [%s:%d]", dirName, host, port) + Log("DEBUG", infoMess) + } -} + sshConfig, err := NewConfig(keyFile, user) + if err != nil { + infoMess = fmt.Sprintf("Error in remove dir, failed to get the ssh config. [host = %s, dirName = %s, err = %v]", host, dirName, err) + Log("ERROR", infoMess) + return err + } + sftpClient, err := sftpConnect(sshConfig, host, port) + if err != nil { + infoMess = fmt.Sprintf("Error in remove dir when create sftp client.[host = %s, dirName = %s, error = %v", host, dirName, err) + Log("ERROR", infoMess) + return err + } + err = sftpClient.RemoveDirectory(dirName) -func TestDir(dirName string) { + if err != nil { + infoMess = fmt.Sprintf("Error in remove dir.[host = %s, dirName = %s, error = %v", host, dirName, err) + Log("ERROR", infoMess) + return err + } + return nil - // check targetDir exist - user := "starrocks" - keyFile := "/home/sr-dev/.ssh/id_rsa" - host := "192.168.88.83" - port := 22 - //dirName := "/opt/starrocks/fe" - _ = RemoveDir(user, keyFile, host, port, dirName) } +func TestDir(dirName string) { + // check targetDir exist + user := "starrocks" + keyFile := "/home/sr-dev/.ssh/id_rsa" + host := "192.168.88.83" + port := 22 + //dirName := "/opt/starrocks/fe" + _ = RemoveDir(user, keyFile, host, port, dirName) +} diff --git a/stargo-pkg.tar.gz b/stargo-pkg.tar.gz deleted file mode 100644 index daafea5..0000000 Binary files a/stargo-pkg.tar.gz and /dev/null differ