/
type.go
150 lines (128 loc) · 3.72 KB
/
type.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* 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 util
import (
"encoding/json"
"fmt"
"github.com/Tencent/bk-bcs/bcs-common/common/types"
)
type Server struct {
BindAddr string `json:"bind"`
Port uint `json:"port"`
TLS `json:"serverTLS,inline"`
}
type TLS struct {
CaFile string `json:"ca-file"`
CertFile string `json:"cert-file"`
KeyFile string `json:"key-file"`
PassWord string `json:"-"`
}
// a zone contains a collection of jobs that this node will do.
// a zone value could be a cluster-id or a self-defined string which is set by user.
type Zone string
const AllZones Zone = "all-bcs-health-zones"
func (z Zone) IsAllZone() bool {
if z == AllZones {
return true
}
return false
}
type Zones []Zone
func (z Zones) IsAllZone() bool {
for _, zone := range z {
if zone.IsAllZone() {
return true
}
}
return false
}
// health slave's meta info
type Slave struct {
// the name of the slave cluster, must be unique among all clusters.
// can be the value of cluster-id or others.
SlaveClusterName string `json:"slaveClusterName"`
// containers a collection of zone. it determines the jobs which is get from master.
Zones Zones `json:"zones"`
// details about this slave.
types.ServerInfo `json:",inline"`
}
type Protocol string
const (
HTTP Protocol = "http"
TCP Protocol = "tcp"
)
type ActionType string
const (
// this job is added now
AddAction ActionType = "add"
// this job is updated.
UpdateAction ActionType = "update"
// this job is deleted.
DeleteAction ActionType = "delete"
// this job's action(above) is already handled.
HandledAction ActionType = "handled"
)
// job contains all the info which is needed during the check.
type Job struct {
// which module this job belongs to.
Module string `json:"module"`
// job actions, include: add, update, delete, handled.
Action ActionType `json:"action"`
// zone that this job belongs to.
Zone Zone `json:"zone"`
// Protocol that this job will use.
Protocol Protocol `json:"protocol"`
// url of the checked point, ip:port
Url string `json:"url"`
// the result of this job.
Status *JobStatus `json:"status,omitempty"`
}
func (j *Job) Name() string {
return fmt.Sprintf("%s::%s::%s", j.Zone, j.Protocol, j.Url)
}
func (j *Job) String() string {
js, _ := json.Marshal(j)
return string(js)
}
func (j *Job) DeepCopy() *Job {
job := &Job{
Module: j.Module,
Action: j.Action,
Zone: j.Zone,
Protocol: j.Protocol,
Url: j.Url,
}
if j.Status != nil {
job.Status = &JobStatus{
SlaveInfo: j.Status.SlaveInfo,
Success: j.Status.Success,
Message: j.Status.Message,
FinishedAt: j.Status.FinishedAt,
}
}
return job
}
type JobStatus struct {
// slave infos that do this job
SlaveInfo *Slave `json:"slaveInfo,omitempty"`
// where the job is success or not.
Success bool `json:"success,omitempty"`
// record the check result when failed.
Message string `json:"message,omitempty"`
// time of the job is done.
FinishedAt int64 `json:"finishedAt,omitempty"`
}
type SvrResponse struct {
Error error `json:"error"`
Jobs []*Job `json:"jobs,omitempty"`
}