Skip to content

Commit

Permalink
Merge branch 'sprint8' into feature/sprint6/in-place-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
haiboumich committed Feb 14, 2022
2 parents ac1bd78 + ccb5a4f commit 83862f3
Show file tree
Hide file tree
Showing 65 changed files with 2,933 additions and 2,943 deletions.
30 changes: 27 additions & 3 deletions common/constants/cluster.go
Expand Up @@ -111,10 +111,7 @@ type ClusterRelationType string

//Constants for the relationships between clusters
const (
ClusterRelationSlaveTo ClusterRelationType = "SlaveTo"
ClusterRelationStandBy ClusterRelationType = "StandBy"
ClusterRelationCloneFrom ClusterRelationType = "CloneFrom"
ClusterRelationRecoverFrom ClusterRelationType = "RecoverFrom"
)

type ClusterCloneStrategy string
Expand Down Expand Up @@ -160,3 +157,30 @@ const (
DefaultBackupS3SecretAccessKey string = "minioadmin"
DefaultBackupS3Endpoint string = "http://minio.pingcap.net:9000"
)

type DBUserRoleType string

// DBUser role type
const (
Root DBUserRoleType = "Root" // root
DBUserBackupRestore DBUserRoleType = "EM_Backup_Restore" // user for backup and restore
DBUserParameterManagement DBUserRoleType = "EM_Parameter_Management" // user for managing parameters
DBUserCDCDataSync DBUserRoleType = "CDC_Data_Sync" // user for CDC data synchronization
)

var DBUserName = map[DBUserRoleType]string{
Root: "root",
DBUserBackupRestore: "EM_Backup_Restore",
DBUserParameterManagement: "EM_Parameter_Management",
DBUserCDCDataSync: "CDC_Data_Sync",
}

var DBUserPermission = map[DBUserRoleType][]string{
Root: {"ALL PRIVILEGES"},
DBUserBackupRestore: {"ALL PRIVILEGES", "BACKUP_ADMIN,RESTORE_ADMIN"},
DBUserParameterManagement: {"ALL PRIVILEGES", "CONFIG,RELOAD,SYSTEM_VARIABLES_ADMIN"},
DBUserCDCDataSync: {"ALL PRIVILEGES", "RESTRICTED_REPLICA_WRITER_ADMIN"},
}

// DefaultRetainedPortRange default retained port range for tiem
var DefaultRetainedPortRange = "[11000,12000]"
@@ -1,6 +1,5 @@

/******************************************************************************
* Copyright (c) 2021 PingCAP, Inc. *
* Copyright (c) 2022 PingCAP, Inc. *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
Expand All @@ -12,17 +11,27 @@
* 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 knowledge
/*******************************************************************************
* @File: cluster_test.go
* @Description:
* @Author: zhangpeijin@pingcap.com
* @Version: 1.0.0
* @Date: 2022/2/11
*******************************************************************************/

package constants

import (
"os"
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
)

func TestMain(m *testing.M) {
LoadKnowledge()
os.Exit(m.Run())
func Test_Config(t *testing.T) {
ports := make([]int, 2)
err := json.Unmarshal([]byte(DefaultRetainedPortRange), &ports)
assert.NoError(t, err)
assert.Equal(t, []int{11000, 12000}, ports)
}
24 changes: 1 addition & 23 deletions common/constants/platform.go
Expand Up @@ -36,28 +36,6 @@ const (

ConfigTelemetrySwitch string = "config_telemetry_switch"
ConfigPrometheusAddress string = "config_prometheus_address"
)

type DBUserRoleType string

// DBUser role type
const (
Root DBUserRoleType = "Root" // root
DBUserBackupRestore DBUserRoleType = "EM_Backup_Restore" // user for backup and restore
DBUserParameterManagement DBUserRoleType = "EM_Parameter_Management" // user for managing parameters
DBUserCDCDataSync DBUserRoleType = "CDC_Data_Sync" // user for CDC data synchronization
ConfigKeyRetainedPortRange string = "config_retained_port_range"
)

var DBUserName = map[DBUserRoleType]string{
Root: "root",
DBUserBackupRestore: "EM_Backup_Restore",
DBUserParameterManagement: "EM_Parameter_Management",
DBUserCDCDataSync: "CDC_Data_Sync",
}

var DBUserPermission = map[DBUserRoleType][]string{
Root: {"ALL PRIVILEGES"},
DBUserBackupRestore: {"ALL PRIVILEGES", "BACKUP_ADMIN,RESTORE_ADMIN"},
DBUserParameterManagement: {"ALL PRIVILEGES", "CONFIG,RELOAD,SYSTEM_VARIABLES_ADMIN"},
DBUserCDCDataSync: {"ALL PRIVILEGES", "RESTRICTED_REPLICA_WRITER_ADMIN"},
}
6 changes: 5 additions & 1 deletion common/errors/errorcode.go
Expand Up @@ -31,7 +31,8 @@ const (
TIEM_TASK_CONFLICT EM_ERROR_CODE = 9993
TIEM_TASK_CANCELED EM_ERROR_CODE = 9992

TIEM_SYSTEM_MISSING_DATA EM_ERROR_CODE = 9899
TIEM_SYSTEM_MISSING_DATA EM_ERROR_CODE = 9899
TIEM_SYSTEM_MISSING_CONFIG EM_ERROR_CODE = 9898

TIEM_UNRECOGNIZED_ERROR EM_ERROR_CODE = 10000
TIEM_PARAMETER_INVALID EM_ERROR_CODE = 10001
Expand Down Expand Up @@ -145,6 +146,7 @@ const (
TIEM_RESOURCE_UNINSTALL_FILEBEAT_ERROR EM_ERROR_CODE = 30132
TIEM_RESOURCE_PREPARE_HOST_ERROR EM_ERROR_CODE = 30133
TIEM_RESOURCE_INVALID_VENDOR_NAME EM_ERROR_CODE = 30134
TIEM_RESOURCE_INVALID_ZONE_INFO EM_ERROR_CODE = 30135

TIEM_MONITOR_NOT_FOUND EM_ERROR_CODE = 614

Expand Down Expand Up @@ -269,6 +271,7 @@ var explanationContainer = map[EM_ERROR_CODE]ErrorCodeExplanation{
TIEM_METADB_SERVER_CALL_ERROR: {"call metadb-Server failed", 500},
TIEM_CLUSTER_SERVER_CALL_ERROR: {"call cluster-Server failed", 500},
TIEM_SYSTEM_MISSING_DATA: {"missing system data", 500},
TIEM_SYSTEM_MISSING_CONFIG: {"missing system config", 500},

TIEM_TASK_TIMEOUT: {"task timeout", 500},
TIEM_FLOW_NOT_FOUND: {"flow not found", 500},
Expand Down Expand Up @@ -355,6 +358,7 @@ var explanationContainer = map[EM_ERROR_CODE]ErrorCodeExplanation{
TIEM_RESOURCE_UNINSTALL_FILEBEAT_ERROR: {"uninstall filebeat on host failed", 400},
TIEM_RESOURCE_PREPARE_HOST_ERROR: {"prepare host before verify failed", 500},
TIEM_RESOURCE_INVALID_VENDOR_NAME: {"invalid vendor", 400},
TIEM_RESOURCE_INVALID_ZONE_INFO: {"invalid zone info", 400},

// param group & cluster param
TIEM_DEFAULT_PARAM_GROUP_NOT_DEL: {"Not allow to deleted the default parameter group", 409},
Expand Down
22 changes: 22 additions & 0 deletions common/structs/resource.go
Expand Up @@ -25,6 +25,8 @@ package structs

import (
"fmt"
"github.com/pingcap-inc/tiem/library/framework"
"strconv"
"strings"

"github.com/pingcap-inc/tiem/common/constants"
Expand Down Expand Up @@ -112,6 +114,26 @@ type HostInfo struct {
Disks []DiskInfo `json:"disks"`
}

func ParseCpu(specCode string) int {
cpu, err := strconv.Atoi(strings.Split(specCode, "C")[0])
if err != nil {
framework.Log().Errorf("ParseCpu error, specCode = %s", specCode)
}
return cpu
}

func ParseMemory(specCode string) int {
memory, err := strconv.Atoi(strings.Split(strings.Split(specCode, "C")[1], "G")[0])
if err != nil {
framework.Log().Errorf("ParseMemory error, specCode = %s", specCode)
}
return memory
}

func GenSpecCode(cpuCores int32, mem int32) string {
return fmt.Sprintf("%dC%dG", cpuCores, mem)
}

func (h *HostInfo) GetPurposes() []string {
return strings.Split(h.Purpose, ",")
}
Expand Down
64 changes: 64 additions & 0 deletions common/structs/resource_test.go
Expand Up @@ -234,3 +234,67 @@ func Test_AddTraits(t *testing.T) {
})
}
}

func TestGenSpecCode(t *testing.T) {
type args struct {
cpuCores int32
mem int32
}
tests := []struct {
name string
args args
want string
}{
{"normal", args{3,6}, "3C6G"},
{"normal", args{999,999}, "999C999G"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GenSpecCode(tt.args.cpuCores, tt.args.mem); got != tt.want {
t.Errorf("GenSpecCode() = %v, want %v", got, tt.want)
}
})
}
}

func TestParseCpu(t *testing.T) {
type args struct {
specCode string
}
tests := []struct {
name string
args args
want int
}{
{"normal", args{"3C6G"}, 3},
{"normal", args{"999C6G"}, 999},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ParseCpu(tt.args.specCode); got != tt.want {
t.Errorf("ParseCpu() = %v, want %v", got, tt.want)
}
})
}
}

func TestParseMemory(t *testing.T) {
type args struct {
specCode string
}
tests := []struct {
name string
args args
want int
}{
{"normal", args{"3C6G"}, 6},
{"normal", args{"3C999G"}, 999},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ParseMemory(tt.args.specCode); got != tt.want {
t.Errorf("ParseMemory() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 83862f3

Please sign in to comment.