Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polaris first commit #1

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions:
contents: write

# Always force the use of Go modules
env:
GO111MODULE: on

jobs:

build:
runs-on: ubuntu-latest
steps:
# Setup the environment.
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.15
# Checkout latest code
- name: Checkout repo
uses: actions/checkout@v2

# Execute vert check
- name: vert check
run: bash vert.sh -install && bash vert.sh

# Run tests
- name: run tests
run: |
cd ./test
go test

# TODO: Examine coverage
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
polaris-server
polaris-server-release
polaris-server-release.tar.gz

/log
/statis

*.swp
*.code-workspace

.idea
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing
---
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.

[Tencent Open Source Incentive Program](https://opensource.tencent.com/contribution) Encourage developers to participate and contribute, and look forward to your joining.

## Issue
#### For contributors

Please ensure that the following conditions are met before submitting an issue:

* Must be a bug or new feature
* Have searched in the issue, and did not find a similar issue or solution
* When creating a new issue, please provide a detailed description, screenshot or short video to help us locate the problem

## Pull Request
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.

Please confirm before completing a PR:

1. Fork your own branch from the master branch.
2. Please modify the corresponding documents and comments after modifying the code.
3. Please add License and Copyright declarations in the newly created file.
4. Ensure a consistent code style.
5. Do adequate testing.
6. Then, you can submit your code to the dev branch.
5 changes: 5 additions & 0 deletions Code-of-Conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PolarisMesh Community Code of Conduct
PolarisMesh follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).


Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the PolarisMesh Code of Conduct Committee via email: PolarisMesh_Community@qq.com
892 changes: 892 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<img src="images/polaris_logo_white.png" width="50%" height="50%" />

___
# 北极星服务治理中心
北极星是一个支持多种开发语言、兼容主流开发框架的服务治理中心。支持嵌入式和非嵌入式两种使用方式,嵌入式使用服务治理SDK,非嵌入式使用流量代理Sidecar

## 概述
北极星的治理功能是基于服务维度来提供的,北极星的服务可对应到业界主流的框架/平台服务的实现,如[gRPC],[SPRING CLOUD],以及[Kubernetes Service]。基于这些框架/平台开发的应用可以快速接入北极星服务治理。

北极星服务端提供以下主流功能特性:

* ** 服务数据管理

执行可视化控制台或者管理员基于HTTP管理端接口对于服务数据(标签,健康状态,实例信息,治理规则)进行读写操作。

* ** 服务注册发现

提供多协议(HTTP,gRPC)接口供被调端服务进行自注册,以及主调端应用发现并拉取其他被调端服务的服务数据,以便接下来进行服务调用。

* ** 健康检查

提供多协议(HTTP,gRPC)接口供被调端进行心跳上报,服务端会实时监测心跳记录,对超时的实例进行健康状态变更。

## 快速入门

### 前置准备

#### 准备数据库

需要下载并安装MySQL,版本号要求>=5.7,可以在这里进行下载:https://dev.mysql.com/downloads/mysql/5.7.html

#### 导入数据库建表脚本

建表脚本为./store/defaultStore/polaris_server.sql,可通过mysql命令或者admin客户端进行导入

#### 准备golang编译环境

北极星服务端编译需要golang编译环境,版本号要求>=1.12,可以在这里进行下载:https://golang.org/dl/#featured

### 编译构建

````shell script
chmod +x build.sh
./build.sh
````
构建完后,可以在当前目录看到polaris-server-release_${version}.tar.gz的软件包。

### 安装

#### 解压软件包

获取polaris-server-release_${version}.tar.gz,并解压

#### 修改数据库配置

进入解压后的目录,打开polaris-server.yaml,替换DB配置相关的几个变量为实际的数据库参数;##DB_USER##(数据库用户名),##DB_PWD##(数据库密码),##DB_ADDR##(数据库地址),##DB_NAME##(数据库名称)

#### 执行安装脚本

````shell script
chmod +x ./tool/*.sh
#进行安装
./tool/install.sh
#测试进程是否启动成功
./tool/p.sh
````
最后一步运行p.sh后,返回Polaris Server,证明启动成功。

#### 验证安装

````shell script
curl http://127.0.0.1:8080
````
返回Polaris Server,证明功能正常

## License

The polaris is licensed under the BSD 3-Clause License. Copyright and license information can be found in the file [LICENSE](LICENSE)







86 changes: 83 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,83 @@
# polaris

test
<img src="images/polaris_logo_white.png" width="50%" height="50%" />

___
# Polaris
Polaris is an operation centre that supports multiple programming languages, with high compatibility to different application framework.
It supports accessing with SDK or sidecar proxy.

## Overview
Polaris's operation features provided are based on the dimension of the service,
Polaris's service can actualize industry standard framework and service platform, like [gRPC],[SPRING CLOUD],and [Kubernetes Service].
These applications can switch in Polaris with no downtime.

Polaris provide features listed as below:

* ** Service Data Management

Bringing visibility to the control panel, admin can configure HTTP port (label, health status, instance information, policy).

* ** Registration and Discovery

Provide multi-protocol(HTTP,gRPC), self-registration, and caller server's ability to discover and distribute other server end's data for invocation.

* ** Health Check

Provide multi-protocol(HTTP,gRPC), provide heartbeat report, server end will monitor heartbeat record, configure overtime health status.

## Quick Guide

### Preconditions

#### Prepare database

Please download and install MySQL, version requirement >=5.7, download available here:
https://dev.mysql.com/downloads/mysql/5.7.html

#### Import SQL script

Point Script: ./store/defaultStore/polaris_server.sql, one can import through mysql admin or console.

#### Prepare golang compile environment

Polaris server end needs golang compile environment, version number needs >=1.12, download available here: https://golang.org/dl/#featured.

### Build

````shell script
chmod +x build.sh
./build.sh
````
After built, one can see 'polaris-server-release_${version}.tar.gz' package from the list.

### Installation

#### Unzip package

Obtain polaris-server-release_${version}.tar.gz, and unzip.

#### Change polaris configuration

After unzipped, vi polaris-server.yaml, replace DB configuration's variable to real database information
: ##DB_USER## (database username), ##DB_PWD##(database password), ##DB_ADDR##(database address), ##DB_NAME##(database name)

#### Execute Installation Script

````shell script
chmod +x ./tool/*.sh
# install
./tool/install.sh
# test whether the process is successful
./tool/p.sh
````
After all, run ./p.sh, prompt Polaris Server, proof the installation is successful

#### Verify installation

````shell script
curl http://127.0.0.1:8080
````
Return text is 'Polaris Server', proof features run smoothly

## License

The polaris is licensed under the BSD 3-Clause License. Copyright and license information can be found in the file [LICENSE](LICENSE)
1 change: 1 addition & 0 deletions apiserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# API Server
111 changes: 111 additions & 0 deletions apiserver/apiserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package apiserver

import (
"context"
"errors"
"fmt"
"github.com/polarismesh/polaris-server/common/log"
"strings"
)

const (
DiscoverAccess string = "discover"
RegisterAccess string = "register"
HealthcheckAccess string = "healthcheck"
)

/**
* @brief API服务器配置
*/
type Config struct {
Name string
Option map[string]interface{}
API map[string]APIConfig
}

/**
* @brief API配置
*/
type APIConfig struct {
Enable bool
Include []string
}

/**
* @brief API服务器接口
*/
type Apiserver interface {
GetProtocol() string
GetPort() uint32
Initialize(ctx context.Context, option map[string]interface{}, api map[string]APIConfig) error
Run(errCh chan error)
Stop()
Restart(option map[string]interface{}, api map[string]APIConfig, errCh chan error) error
}

var (
Slots = make(map[string]Apiserver)
)

/**
* @brief 注册API服务器
*/
func Register(name string, server Apiserver) error {
if _, exist := Slots[name]; exist {
err := errors.New("apiserver name exist")
return err
}

Slots[name] = server

return nil
}

/**
* @brief 获取客户端openMethod
*/
func GetClientOpenMethod(include []string, protocol string) (map[string]bool, error) {
clientAccess := make(map[string][]string)
clientAccess[DiscoverAccess] = []string{"Discover", "ReportClient"}
clientAccess[RegisterAccess] = []string{"RegisterInstance", "DeregisterInstance"}
clientAccess[HealthcheckAccess] = []string{"Heartbeat"}

openMethod := make(map[string]bool)
// 如果为空,开启全部接口
if len(include) == 0 {
for key := range clientAccess {
include = append(include, key)
}
}

for _, item := range include {
if methods, ok := clientAccess[item]; ok {
for _, method := range methods {
method = "/v1.Polaris" + strings.ToUpper(protocol) + "/" + method
openMethod[method] = true
}
} else {
log.Errorf("method %s does not exist in %sserver client access", item, protocol)
return nil, fmt.Errorf("method %s does not exist in %sserver client access", item, protocol)
}
}

return openMethod, nil
}
Loading