Skip to content

Commit 637999b

Browse files
author
breezeli
authored
Merge pull request #2718 from rentiansheng/v3.2.x_20190709
修复自定义层级查询主机错误。修复healthz接口 Former-commit-id: 02cbc3f
2 parents 3303978 + 3d50f41 commit 637999b

File tree

23 files changed

+377
-335
lines changed

23 files changed

+377
-335
lines changed

src/apimachinery/healthz/healthz.go

+5-12
Original file line numberDiff line numberDiff line change
@@ -41,54 +41,47 @@ type health struct {
4141
}
4242

4343
func (h *health) HealthCheck(moduleName string) (healthy bool, err error) {
44-
var name string
44+
4545
switch moduleName {
4646
case types.CC_MODULE_AUDITCONTROLLER:
4747
h.capability.Discover = h.disc.AuditCtrl()
48-
name = "audit"
4948

5049
case types.CC_MODULE_HOSTCONTROLLER:
5150
h.capability.Discover = h.disc.HostCtrl()
52-
name = "host"
5351

5452
case types.CC_MODULE_OBJECTCONTROLLER:
5553
h.capability.Discover = h.disc.ObjectCtrl()
56-
name = "object"
5754

5855
case types.CC_MODULE_PROCCONTROLLER:
5956
h.capability.Discover = h.disc.ProcCtrl()
60-
name = "process"
6157

6258
case types.CC_MODULE_DATACOLLECTION:
6359
h.capability.Discover = h.disc.DataCollect()
64-
name = "collector"
6560

6661
case types.CC_MODULE_HOST:
6762
h.capability.Discover = h.disc.HostServer()
68-
name = "host"
6963

7064
case types.CC_MODULE_MIGRATE:
7165
h.capability.Discover = h.disc.MigrateServer()
72-
name = "migrate"
7366

7467
case types.CC_MODULE_PROC:
7568
h.capability.Discover = h.disc.ProcServer()
76-
name = "process"
7769

7870
case types.CC_MODULE_TOPO:
7971
h.capability.Discover = h.disc.TopoServer()
80-
name = "topo"
8172

8273
case types.CC_MODULE_EVENTSERVER:
8374
h.capability.Discover = h.disc.EventServer()
84-
name = "event"
75+
76+
case types.CC_MODULE_APISERVER:
77+
h.capability.Discover = h.disc.ApiServer()
8578

8679
default:
8780
return false, fmt.Errorf("unsupported health module: %s", moduleName)
8881
}
8982

9083
resp := new(metric.HealthResponse)
91-
client := rest.NewRESTClient(h.capability, fmt.Sprintf("/%s/v3", name))
84+
client := rest.NewRESTClient(h.capability, "/")
9285
err = client.Get().
9386
WithContext(context.Background()).
9487
SubResource("/healthz").

src/apimachinery/rest/request.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (r *Request) WrapURL() *url.URL {
167167
*finalUrl = *u
168168
}
169169

170-
finalUrl.Path = finalUrl.Path + r.subPath
170+
finalUrl.Path = strings.TrimRight(finalUrl.Path, "/") + "/" + strings.Trim(r.subPath, "/")
171171

172172
query := url.Values{}
173173
for key, values := range r.params {

src/scene_server/admin_server/app/server.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import (
3232
"configcenter/src/scene_server/admin_server/configures"
3333
svc "configcenter/src/scene_server/admin_server/service"
3434
"configcenter/src/storage/dal/mongo"
35-
36-
"github.com/emicklei/go-restful"
3735
)
3836

3937
func Run(ctx context.Context, op *options.ServerOption) error {
@@ -65,7 +63,7 @@ func Run(ctx context.Context, op *options.ServerOption) error {
6563
server := backbone.Server{
6664
ListenAddr: svrInfo.IP,
6765
ListenPort: svrInfo.Port,
68-
Handler: restful.NewContainer().Add(service.WebService()),
66+
Handler: service.WebService(),
6967
TLS: backbone.TLSConfig{},
7068
}
7169

src/scene_server/admin_server/service/service.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,26 @@ func (s *Service) SetApiSrvAddr(ccApiSrvAddr string) {
4848
s.ccApiSrvAddr = ccApiSrvAddr
4949
}
5050

51-
func (s *Service) WebService() *restful.WebService {
52-
ws := new(restful.WebService)
51+
func (s *Service) WebService() *restful.Container {
52+
container := restful.NewContainer()
53+
54+
api := new(restful.WebService)
5355
getErrFunc := func() errors.CCErrorIf {
5456
return s.CCErr
5557
}
56-
ws.Path("/migrate/v3").Filter(rdapi.AllGlobalFilter(getErrFunc)).Produces(restful.MIME_JSON)
58+
api.Path("/migrate/v3").Filter(rdapi.AllGlobalFilter(getErrFunc)).Produces(restful.MIME_JSON)
59+
60+
api.Route(api.POST("/migrate/{distribution}/{ownerID}").To(s.migrate))
61+
api.Route(api.POST("/migrate/system/hostcrossbiz/{ownerID}").To(s.Set))
62+
api.Route(api.POST("/clear").To(s.clear))
63+
64+
container.Add(api)
5765

58-
ws.Route(ws.POST("/migrate/{distribution}/{ownerID}").To(s.migrate))
59-
ws.Route(ws.POST("/migrate/system/hostcrossbiz/{ownerID}").To(s.Set))
60-
ws.Route(ws.POST("/clear").To(s.clear))
61-
ws.Route(ws.GET("/healthz").To(s.Healthz))
66+
healthzAPI := new(restful.WebService).Produces(restful.MIME_JSON)
67+
healthzAPI.Route(healthzAPI.GET("/healthz").To(s.Healthz))
68+
container.Add(healthzAPI)
6269

63-
return ws
70+
return container
6471
}
6572

6673
func (s *Service) Healthz(req *restful.Request, resp *restful.Response) {

src/scene_server/datacollection/app/server.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"sync"
2020
"time"
2121

22-
"github.com/emicklei/go-restful"
23-
2422
"configcenter/src/apimachinery"
2523
"configcenter/src/apimachinery/util"
2624
"configcenter/src/common/backbone"
@@ -57,7 +55,7 @@ func Run(ctx context.Context, op *options.ServerOption) error {
5755
server := backbone.Server{
5856
ListenAddr: svrInfo.IP,
5957
ListenPort: svrInfo.Port,
60-
Handler: restful.NewContainer().Add(service.WebService()),
58+
Handler: service.WebService(),
6159
TLS: backbone.TLSConfig{},
6260
}
6361

src/scene_server/datacollection/service/service.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,24 @@ func (s *Service) SetCache(db *redis.Client) {
4040
s.cache = db
4141
}
4242

43-
func (s *Service) WebService() *restful.WebService {
44-
ws := new(restful.WebService)
43+
func (s *Service) WebService() *restful.Container {
44+
45+
container := restful.NewContainer()
4546
getErrFunc := func() errors.CCErrorIf {
4647
return s.CCErr
4748
}
48-
ws.Path("/collector/v3").Filter(rdapi.AllGlobalFilter(getErrFunc)).Produces(restful.MIME_JSON).Consumes(restful.MIME_JSON)
49-
ws.Route(ws.GET("/healthz").To(s.Healthz))
5049

51-
return ws
50+
api := new(restful.WebService)
51+
api.Path("/collector/v3").Filter(rdapi.AllGlobalFilter(getErrFunc)).Produces(restful.MIME_JSON)
52+
53+
container.Add(api)
54+
55+
healthzAPI := new(restful.WebService)
56+
healthzAPI.Route(healthzAPI.GET("/healthz").To(s.Healthz))
57+
58+
container.Add(healthzAPI)
59+
60+
return container
5261
}
5362

5463
func (s *Service) Healthz(req *restful.Request, resp *restful.Response) {

src/scene_server/event_server/app/server.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import (
3333
"configcenter/src/storage/dal/mongo"
3434
"configcenter/src/storage/dal/redis"
3535
"configcenter/src/storage/rpc"
36-
37-
"github.com/emicklei/go-restful"
3836
)
3937

4038
func Run(ctx context.Context, op *options.ServerOption) error {
@@ -59,7 +57,7 @@ func Run(ctx context.Context, op *options.ServerOption) error {
5957
server := backbone.Server{
6058
ListenAddr: svrInfo.IP,
6159
ListenPort: svrInfo.Port,
62-
Handler: restful.NewContainer().Add(service.WebService()),
60+
Handler: service.WebService(),
6361
TLS: backbone.TLSConfig{},
6462
}
6563

src/scene_server/event_server/service/service.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,29 @@ func (s *Service) SetCache(db *redis.Client) {
4949
s.cache = db
5050
}
5151

52-
func (s *Service) WebService() *restful.WebService {
53-
ws := new(restful.WebService)
52+
func (s *Service) WebService() *restful.Container {
53+
container := restful.NewContainer()
54+
55+
api := new(restful.WebService)
5456
getErrFunc := func() errors.CCErrorIf {
5557
return s.CCErr
5658
}
57-
ws.Path("/event/v3").Filter(rdapi.AllGlobalFilter(getErrFunc)).Produces(restful.MIME_JSON)
59+
api.Path("/event/v3").Filter(rdapi.AllGlobalFilter(getErrFunc)).Produces(restful.MIME_JSON)
60+
61+
api.Route(api.POST("/subscribe/search/{ownerID}/{appID}").To(s.Query))
62+
api.Route(api.POST("/subscribe/ping").To(s.Ping))
63+
api.Route(api.POST("/subscribe/telnet").To(s.Telnet))
64+
api.Route(api.POST("/subscribe/{ownerID}/{appID}").To(s.Subscribe))
65+
api.Route(api.DELETE("/subscribe/{ownerID}/{appID}/{subscribeID}").To(s.UnSubscribe))
66+
api.Route(api.PUT("/subscribe/{ownerID}/{appID}/{subscribeID}").To(s.Rebook))
5867

59-
ws.Route(ws.POST("/subscribe/search/{ownerID}/{appID}").To(s.Query))
60-
ws.Route(ws.POST("/subscribe/ping").To(s.Ping))
61-
ws.Route(ws.POST("/subscribe/telnet").To(s.Telnet))
62-
ws.Route(ws.POST("/subscribe/{ownerID}/{appID}").To(s.Subscribe))
63-
ws.Route(ws.DELETE("/subscribe/{ownerID}/{appID}/{subscribeID}").To(s.UnSubscribe))
64-
ws.Route(ws.PUT("/subscribe/{ownerID}/{appID}/{subscribeID}").To(s.Rebook))
68+
container.Add(api)
6569

66-
ws.Route(ws.GET("/healthz").To(s.Healthz))
70+
healthzAPI := new(restful.WebService).Produces(restful.MIME_JSON)
71+
healthzAPI.Route(healthzAPI.GET("/healthz").To(s.Healthz))
72+
container.Add(healthzAPI)
6773

68-
return ws
74+
return container
6975
}
7076

7177
func (s *Service) Healthz(req *restful.Request, resp *restful.Response) {

src/scene_server/host_server/app/server.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import (
2626
"configcenter/src/scene_server/host_server/app/options"
2727
"configcenter/src/scene_server/host_server/logics"
2828
hostsvc "configcenter/src/scene_server/host_server/service"
29-
30-
"github.com/emicklei/go-restful"
3129
)
3230

3331
func Run(ctx context.Context, op *options.ServerOption) error {
@@ -52,7 +50,7 @@ func Run(ctx context.Context, op *options.ServerOption) error {
5250
server := backbone.Server{
5351
ListenAddr: svrInfo.IP,
5452
ListenPort: svrInfo.Port,
55-
Handler: restful.NewContainer().Add(service.WebService()),
53+
Handler: service.WebService(),
5654
TLS: backbone.TLSConfig{},
5755
}
5856

src/scene_server/host_server/logics/object.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ func (lgc *Logics) GetSetIDByObjectCond(pheader http.Header, appID int64, object
109109
defErr := lgc.CCErr.CreateDefaultCCErrorIf(util.GetLanguage(pheader))
110110

111111
instItem := meta.ConditionItem{}
112+
// query condition has bk_inst_id field
112113
var hasInstID bool
113114
for _, i := range objectCond {
114115
if i.Field != common.BKInstIDField {
115116
continue
116117
}
118+
hasInstID = true
117119
value, err := util.GetInt64ByInterface(i.Value)
118120
if nil != err {
119121
return nil, err
@@ -129,7 +131,6 @@ func (lgc *Logics) GetSetIDByObjectCond(pheader http.Header, appID int64, object
129131
blog.Errorf("mainline miss bk_inst_id parameters. input:%#v, rid:%s", objectCond, rid)
130132
return nil, defErr.Error(common.CCErrHostSearchNeedObjectInstIDErr)
131133
}
132-
133134
nodefaultItem := meta.ConditionItem{}
134135
nodefaultItem.Field = common.BKDefaultField
135136
nodefaultItem.Operator = common.BKDBNE

0 commit comments

Comments
 (0)