-
Notifications
You must be signed in to change notification settings - Fork 375
/
monitor_kafka.go
83 lines (68 loc) · 2.71 KB
/
monitor_kafka.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
// Copyright (c) 2021 Terminus, 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 monitorkafka
import (
"strings"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/modules/msp/instance/db"
"github.com/erda-project/erda/modules/msp/resource/deploy/handlers"
"github.com/erda-project/erda/modules/msp/resource/utils"
"github.com/erda-project/erda/pkg/parser/diceyml"
)
func (p *provider) IsMatch(tmc *db.Tmc) bool {
return tmc.Engine == handlers.ResourceMonitorKafka
}
func (p *provider) BuildServiceGroupRequest(resourceInfo *handlers.ResourceInfo, tmcInstance *db.Instance, clusterConfig map[string]string) interface{} {
req := p.DefaultDeployHandler.BuildServiceGroupRequest(resourceInfo, tmcInstance, clusterConfig).(*apistructs.ServiceGroupCreateV2Request)
req.GroupLabels["ADDON_GROUPS"] = "3"
instanceOptions := map[string]string{}
utils.JsonConvertObjToType(tmcInstance.Options, &instanceOptions)
for _, service := range resourceInfo.Dice.Services {
nodeId := utils.GetRandomId()
// envs
env := map[string]string{
"ADDON_ID": tmcInstance.ID,
"ADDON_NODE_ID": nodeId,
"KAFKA_LOG_DIRS": "/kafka/data",
"KAFKA_ZOOKEEPER_CONNECT": instanceOptions["ZK_HOSTS"],
}
utils.AppendMap(service.Envs, env)
// volumes
if p.IsNotDCOSCluster(clusterConfig["DICE_CLUSTER_TYPE"]) {
service.Binds = diceyml.Binds{
nodeId + "_data:/kafka/data:rw",
}
} else {
service.Binds = diceyml.Binds{
clusterConfig["DICE_STORAGE_MOUNTPOINT"] + "/addon/kafka/" + nodeId + "/kafka/data:/kafka/data:rw",
}
}
}
return req
}
func (p *provider) BuildTmcInstanceConfig(tmcInstance *db.Instance, serviceGroupDeployResult interface{},
clusterConfig map[string]string, additionalConfig map[string]string) map[string]string {
instanceOptions := map[string]string{}
utils.JsonConvertObjToType(tmcInstance.Options, &instanceOptions)
var hosts []string
serviceGroup := serviceGroupDeployResult.(*apistructs.ServiceGroup)
for _, service := range serviceGroup.Services {
hosts = append(hosts, service.Vip+":9092")
}
config := map[string]string{
"KAFKA_HOSTS": strings.Join(hosts, ","),
"ZK_HOSTS": instanceOptions["ZK_HOSTS"],
}
return config
}