-
Notifications
You must be signed in to change notification settings - Fork 58
/
configmap.go
111 lines (94 loc) · 3.18 KB
/
configmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Copyright 2021-present, StarRocks 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
http://www.apache.org/licenses/LICENSE-2.0
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 resource_utils
import (
"bytes"
"strconv"
"github.com/spf13/viper"
corev1 "k8s.io/api/core/v1"
)
// the fe ports key
const (
HTTP_PORT = "http_port"
RPC_PORT = "rpc_port"
QUERY_PORT = "query_port"
EDIT_LOG_PORT = "edit_log_port"
)
// the cn or be ports key
const (
// THRIFT_PORT is the old name in CN.
// From StarRocks 3.1, both CN and BE use the same port name be_port.
THRIFT_PORT = "thrift_port"
BE_PORT = "be_port"
// WEBSERVER_PORT and BE_HTTP_PORT
// From StarRocks 3.0, the name of HTTP port is changed to be_http_port in BE and CN.
WEBSERVER_PORT = "webserver_port"
BE_HTTP_PORT = "be_http_port"
// HEARTBEAT_SERVICE_PORT and BRPC_PORT
// both BE and CN have the these ports
HEARTBEAT_SERVICE_PORT = "heartbeat_service_port"
BRPC_PORT = "brpc_port"
)
// the fe proxy ports key
const (
FE_PROXY_HTTP_PORT = 8080
FE_PORXY_HTTP_PORT_NAME = "http-port"
)
// DefMap the default port about abilities.
var DefMap = map[string]int32{
HTTP_PORT: 8030,
RPC_PORT: 9020,
QUERY_PORT: 9030,
EDIT_LOG_PORT: 9010,
THRIFT_PORT: 9060,
BE_PORT: 9060,
WEBSERVER_PORT: 8040,
BE_HTTP_PORT: 8040,
HEARTBEAT_SERVICE_PORT: 9050,
BRPC_PORT: 8060,
}
func ResolveConfigMap(configMap *corev1.ConfigMap, key string) (map[string]interface{}, error) {
res := make(map[string]interface{})
data := configMap.Data
if _, ok := data[key]; !ok {
return res, nil
}
value := data[key]
// We use a new viper instance, not the global one, in order to avoid concurrency problems: concurrent map iteration
// and map write,
v := viper.New()
v.SetConfigType("properties")
if err := v.ReadConfig(bytes.NewBuffer([]byte(value))); err != nil {
return nil, err
}
return v.AllSettings(), nil
}
// GetPort get ports from config file.
func GetPort(config map[string]interface{}, key string) int32 {
if v, ok := config[key]; ok {
if port, err := strconv.ParseInt(v.(string), 10, 32); err == nil && port != 0 {
return int32(port)
}
}
if key == THRIFT_PORT {
// from StarRocks 3.1, the name of thrift_port is changed to be_port.
// If both be_port and thrift_port are set, the thrift_port will be used in StarRocks.
// see https://github.com/StarRocks/starrocks/pull/31747
return GetPort(config, BE_PORT)
} else if key == WEBSERVER_PORT {
// If both webserver_port and be_http_port are set, the be_http_port will be used in StarRocks.
// todo(yandongxiao): Call GetPort(config, BE_HTTP_PORT) not GetPort(config, WEBSERVER_PORT).
return GetPort(config, BE_HTTP_PORT)
}
return DefMap[key]
}