Skip to content

Commit 6bb0079

Browse files
committed
polaris first commit
1 parent b25484a commit 6bb0079

File tree

278 files changed

+64876
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+64876
-3
lines changed

.github/workflows/testing.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
permissions:
10+
contents: write
11+
12+
# Always force the use of Go modules
13+
env:
14+
GO111MODULE: on
15+
16+
jobs:
17+
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
# Setup the environment.
22+
- name: Setup Go
23+
uses: actions/setup-go@v2
24+
with:
25+
go-version: 1.15
26+
# Checkout latest code
27+
- name: Checkout repo
28+
uses: actions/checkout@v2
29+
30+
# Execute vert check
31+
- name: vert check
32+
run: bash vert.sh -install && bash vert.sh
33+
34+
# Run tests
35+
- name: run tests
36+
run: |
37+
cd ./test
38+
go test
39+
40+
# TODO: Examine coverage

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
polaris-server
2+
polaris-server-release
3+
polaris-server-release.tar.gz
4+
5+
/log
6+
/statis
7+
8+
*.swp
9+
*.code-workspace
10+
11+
.idea

CONTRIBUTING.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing
2+
---
3+
If you have good comments or suggestions, welcome to create [Issues](https://github.com/Tencent/polaris/issues) or [Pull Requests](https://github.com/Tencent/polaris/pulls),contribute to the polaris open source community. Polaris continues to recruit contributors, even if it is answering questions in the issue, or doing some simple bugfixes, it will be of great help to polaris.
4+
5+
[Tencent Open Source Incentive Program](https://opensource.tencent.com/contribution) Encourage developers to participate and contribute, and look forward to your joining.
6+
7+
## Issue
8+
#### For contributors
9+
10+
Please ensure that the following conditions are met before submitting an issue:
11+
12+
* Must be a bug or new feature
13+
* Have searched in the issue, and did not find a similar issue or solution
14+
* When creating a new issue, please provide a detailed description, screenshot or short video to help us locate the problem
15+
16+
## Pull Request
17+
We welcome everyone to contribute code to make our product more powerful. The code team will monitor all pull requests, and we will do the corresponding code inspection and testing. After the test passes, we will accept the PR, but will not immediately merge into the master branch.
18+
19+
Please confirm before completing a PR:
20+
21+
1. Fork your own branch from the master branch.
22+
2. Please modify the corresponding documents and comments after modifying the code.
23+
3. Please add License and Copyright declarations in the newly created file.
24+
4. Ensure a consistent code style.
25+
5. Do adequate testing.
26+
6. Then, you can submit your code to the dev branch.

Code-of-Conduct.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# PolarisMesh Community Code of Conduct
2+
PolarisMesh follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
3+
4+
5+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the PolarisMesh Code of Conduct Committee via email: [email protected]

LICENSE

+892
Large diffs are not rendered by default.

README-zh.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<img src="images/polaris_logo_white.png" width="50%" height="50%" />
2+
3+
___
4+
# 北极星服务治理中心
5+
北极星是一个支持多种开发语言、兼容主流开发框架的服务治理中心。支持嵌入式和非嵌入式两种使用方式,嵌入式使用服务治理SDK,非嵌入式使用流量代理Sidecar
6+
7+
## 概述
8+
北极星的治理功能是基于服务维度来提供的,北极星的服务可对应到业界主流的框架/平台服务的实现,如[gRPC][SPRING CLOUD],以及[Kubernetes Service]。基于这些框架/平台开发的应用可以快速接入北极星服务治理。
9+
10+
北极星服务端提供以下主流功能特性:
11+
12+
* ** 服务数据管理
13+
14+
执行可视化控制台或者管理员基于HTTP管理端接口对于服务数据(标签,健康状态,实例信息,治理规则)进行读写操作。
15+
16+
* ** 服务注册发现
17+
18+
提供多协议(HTTP,gRPC)接口供被调端服务进行自注册,以及主调端应用发现并拉取其他被调端服务的服务数据,以便接下来进行服务调用。
19+
20+
* ** 健康检查
21+
22+
提供多协议(HTTP,gRPC)接口供被调端进行心跳上报,服务端会实时监测心跳记录,对超时的实例进行健康状态变更。
23+
24+
## 快速入门
25+
26+
### 前置准备
27+
28+
#### 准备数据库
29+
30+
需要下载并安装MySQL,版本号要求>=5.7,可以在这里进行下载:https://dev.mysql.com/downloads/mysql/5.7.html
31+
32+
#### 导入数据库建表脚本
33+
34+
建表脚本为./store/defaultStore/polaris_server.sql,可通过mysql命令或者admin客户端进行导入
35+
36+
#### 准备golang编译环境
37+
38+
北极星服务端编译需要golang编译环境,版本号要求>=1.12,可以在这里进行下载:https://golang.org/dl/#featured
39+
40+
### 编译构建
41+
42+
````shell script
43+
chmod +x build.sh
44+
./build.sh
45+
````
46+
构建完后,可以在当前目录看到polaris-server-release_${version}.tar.gz的软件包。
47+
48+
### 安装
49+
50+
#### 解压软件包
51+
52+
获取polaris-server-release_${version}.tar.gz,并解压
53+
54+
#### 修改数据库配置
55+
56+
进入解压后的目录,打开polaris-server.yaml,替换DB配置相关的几个变量为实际的数据库参数;##DB_USER##(数据库用户名),##DB_PWD##(数据库密码),##DB_ADDR##(数据库地址),##DB_NAME##(数据库名称)
57+
58+
#### 执行安装脚本
59+
60+
````shell script
61+
chmod +x ./tool/*.sh
62+
#进行安装
63+
./tool/install.sh
64+
#测试进程是否启动成功
65+
./tool/p.sh
66+
````
67+
最后一步运行p.sh后,返回Polaris Server,证明启动成功。
68+
69+
#### 验证安装
70+
71+
````shell script
72+
curl http://127.0.0.1:8080
73+
````
74+
返回Polaris Server,证明功能正常
75+
76+
## License
77+
78+
The polaris is licensed under the BSD 3-Clause License. Copyright and license information can be found in the file [LICENSE](LICENSE)
79+
80+
81+
82+
83+
84+
85+

README.md

+83-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,83 @@
1-
# polaris
2-
3-
test
1+
<img src="images/polaris_logo_white.png" width="50%" height="50%" />
2+
3+
___
4+
# Polaris
5+
Polaris is an operation centre that supports multiple programming languages, with high compatibility to different application framework.
6+
It supports accessing with SDK or sidecar proxy.
7+
8+
## Overview
9+
Polaris's operation features provided are based on the dimension of the service,
10+
Polaris's service can actualize industry standard framework and service platform, like [gRPC][SPRING CLOUD],and [Kubernetes Service].
11+
These applications can switch in Polaris with no downtime.
12+
13+
Polaris provide features listed as below:
14+
15+
* ** Service Data Management
16+
17+
Bringing visibility to the control panel, admin can configure HTTP port (label, health status, instance information, policy).
18+
19+
* ** Registration and Discovery
20+
21+
Provide multi-protocol(HTTP,gRPC), self-registration, and caller server's ability to discover and distribute other server end's data for invocation.
22+
23+
* ** Health Check
24+
25+
Provide multi-protocol(HTTP,gRPC), provide heartbeat report, server end will monitor heartbeat record, configure overtime health status.
26+
27+
## Quick Guide
28+
29+
### Preconditions
30+
31+
#### Prepare database
32+
33+
Please download and install MySQL, version requirement >=5.7, download available here:
34+
https://dev.mysql.com/downloads/mysql/5.7.html
35+
36+
#### Import SQL script
37+
38+
Point Script: ./store/defaultStore/polaris_server.sql, one can import through mysql admin or console.
39+
40+
#### Prepare golang compile environment
41+
42+
Polaris server end needs golang compile environment, version number needs >=1.12, download available here: https://golang.org/dl/#featured.
43+
44+
### Build
45+
46+
````shell script
47+
chmod +x build.sh
48+
./build.sh
49+
````
50+
After built, one can see 'polaris-server-release_${version}.tar.gz' package from the list.
51+
52+
### Installation
53+
54+
#### Unzip package
55+
56+
Obtain polaris-server-release_${version}.tar.gz, and unzip.
57+
58+
#### Change polaris configuration
59+
60+
After unzipped, vi polaris-server.yaml, replace DB configuration's variable to real database information
61+
: ##DB_USER## (database username), ##DB_PWD##(database password), ##DB_ADDR##(database address), ##DB_NAME##(database name)
62+
63+
#### Execute Installation Script
64+
65+
````shell script
66+
chmod +x ./tool/*.sh
67+
# install
68+
./tool/install.sh
69+
# test whether the process is successful
70+
./tool/p.sh
71+
````
72+
After all, run ./p.sh, prompt Polaris Server, proof the installation is successful
73+
74+
#### Verify installation
75+
76+
````shell script
77+
curl http://127.0.0.1:8080
78+
````
79+
Return text is 'Polaris Server', proof features run smoothly
80+
81+
## License
82+
83+
The polaris is licensed under the BSD 3-Clause License. Copyright and license information can be found in the file [LICENSE](LICENSE)

apiserver/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# API Server

apiserver/apiserver.go

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package apiserver
19+
20+
import (
21+
"context"
22+
"errors"
23+
"fmt"
24+
"github.com/polarismesh/polaris-server/common/log"
25+
"strings"
26+
)
27+
28+
const (
29+
DiscoverAccess string = "discover"
30+
RegisterAccess string = "register"
31+
HealthcheckAccess string = "healthcheck"
32+
)
33+
34+
/**
35+
* @brief API服务器配置
36+
*/
37+
type Config struct {
38+
Name string
39+
Option map[string]interface{}
40+
API map[string]APIConfig
41+
}
42+
43+
/**
44+
* @brief API配置
45+
*/
46+
type APIConfig struct {
47+
Enable bool
48+
Include []string
49+
}
50+
51+
/**
52+
* @brief API服务器接口
53+
*/
54+
type Apiserver interface {
55+
GetProtocol() string
56+
GetPort() uint32
57+
Initialize(ctx context.Context, option map[string]interface{}, api map[string]APIConfig) error
58+
Run(errCh chan error)
59+
Stop()
60+
Restart(option map[string]interface{}, api map[string]APIConfig, errCh chan error) error
61+
}
62+
63+
var (
64+
Slots = make(map[string]Apiserver)
65+
)
66+
67+
/**
68+
* @brief 注册API服务器
69+
*/
70+
func Register(name string, server Apiserver) error {
71+
if _, exist := Slots[name]; exist {
72+
err := errors.New("apiserver name exist")
73+
return err
74+
}
75+
76+
Slots[name] = server
77+
78+
return nil
79+
}
80+
81+
/**
82+
* @brief 获取客户端openMethod
83+
*/
84+
func GetClientOpenMethod(include []string, protocol string) (map[string]bool, error) {
85+
clientAccess := make(map[string][]string)
86+
clientAccess[DiscoverAccess] = []string{"Discover", "ReportClient"}
87+
clientAccess[RegisterAccess] = []string{"RegisterInstance", "DeregisterInstance"}
88+
clientAccess[HealthcheckAccess] = []string{"Heartbeat"}
89+
90+
openMethod := make(map[string]bool)
91+
// 如果为空,开启全部接口
92+
if len(include) == 0 {
93+
for key := range clientAccess {
94+
include = append(include, key)
95+
}
96+
}
97+
98+
for _, item := range include {
99+
if methods, ok := clientAccess[item]; ok {
100+
for _, method := range methods {
101+
method = "/v1.Polaris" + strings.ToUpper(protocol) + "/" + method
102+
openMethod[method] = true
103+
}
104+
} else {
105+
log.Errorf("method %s does not exist in %sserver client access", item, protocol)
106+
return nil, fmt.Errorf("method %s does not exist in %sserver client access", item, protocol)
107+
}
108+
}
109+
110+
return openMethod, nil
111+
}

0 commit comments

Comments
 (0)