Skip to content

Commit

Permalink
TencentBlueKing#1, yovole test
Browse files Browse the repository at this point in the history
  • Loading branch information
japlee committed Nov 7, 2018
1 parent 90a5453 commit 05ec67c
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/api_server/service/v3/uri.go
Expand Up @@ -22,11 +22,12 @@ import (
type RequestType string

const (
UnknownType RequestType = "unknown"
TopoType RequestType = "topo"
HostType RequestType = "host"
ProcType RequestType = "proc"
EventType RequestType = "event"
UnknownType RequestType = "unknown"
TopoType RequestType = "topo"
HostType RequestType = "host"
ProcType RequestType = "proc"
EventType RequestType = "event"
DataCollectType RequestType = "collect"
)

type V3URLPath string
Expand All @@ -41,6 +42,8 @@ func (u V3URLPath) FilterChain(req *restful.Request) (RequestType, error) {
return ProcType, nil
case u.WithEvent(req):
return EventType, nil
case u.WithDataCollect(req):
return DataCollectType, nil
default:
return UnknownType, errors.New("unknown requested with backend process")
}
Expand Down Expand Up @@ -174,6 +177,25 @@ func (u *V3URLPath) WithProc(req *restful.Request) (isHit bool) {
return false
}

func (u *V3URLPath) WithDataCollect(req *restful.Request) (isHit bool) {
dataCollectRoot := "/collector/v3"
from, to := rootPath, dataCollectRoot

switch {
case strings.HasPrefix(string(*u), rootPath+"/collector/"):
from, to, isHit = rootPath+"/collector", dataCollectRoot, true

default:
isHit = false
}

if isHit {
u.revise(req, from, to)
return true
}
return false
}

func (u V3URLPath) revise(req *restful.Request, from, to string) {
req.Request.RequestURI = to + req.Request.RequestURI[len(from):]
req.Request.URL.Path = to + req.Request.URL.Path[len(from):]
Expand Down
20 changes: 20 additions & 0 deletions src/common/metadata/yovole.go
@@ -0,0 +1,20 @@
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 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 metadata

type YovoleTest struct {
BizID int64 `json:"bk_biz_id"`
InnerIP string `json:"bk_host_innerip"`
HostID int64 `json:"bk_host_id"`
FileContent string `json:"file_content"`
}
3 changes: 3 additions & 0 deletions src/common/tablenames.go
Expand Up @@ -78,6 +78,9 @@ const (
BKTableNameNetcollectDevice = "cc_Netcollect_Device"
BKTableNameNetcollectProperty = "cc_Netcollect_Property"

// add yovole test datacollection
BKTableNameYovoleTest = "cc_YovoleTest"

BKTableNameHostLock = "cc_HostLock"
)

Expand Down
Expand Up @@ -51,4 +51,12 @@ var tables = map[string][]dal.Index{
{Keys: map[string]interface{}{"netcollect_property_id": 1}, Background: true},
{Keys: map[string]interface{}{"bk_supplier_account": 1}, Background: true},
},

// add yovole test collection
common.BKTableNameYovoleTest: []dal.Index{
{Keys: map[string]interface{}{"bk_biz_id": 1}, Background: true},
{Keys: map[string]interface{}{"bk_host_id": 1}, Background: true},
{Keys: map[string]interface{}{"bk_host_innerip": 1}, Background: true},
{Keys: map[string]interface{}{"file_content": 1}, Background: true},
},
}
26 changes: 26 additions & 0 deletions src/scene_server/datacollection/logics/logics.go
@@ -0,0 +1,26 @@
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 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 logics

import (
"configcenter/src/common/backbone"
"configcenter/src/storage/dal"
"configcenter/src/thirdpartyclient/esbserver"
)

// logics for yovole test datacollection
type Logics struct {
*backbone.Engine
Instance dal.RDB
ESB esbserver.EsbClientInterface
}
4 changes: 4 additions & 0 deletions src/scene_server/datacollection/service/service.go
Expand Up @@ -20,6 +20,7 @@ import (
"configcenter/src/common/metric"
"configcenter/src/common/rdapi"
"configcenter/src/common/types"
"configcenter/src/scene_server/datacollection/logics"
"configcenter/src/storage/dal"

"github.com/emicklei/go-restful"
Expand All @@ -30,6 +31,7 @@ type Service struct {
*backbone.Engine
db dal.RDB
cache *redis.Client
*logics.Logics
}

func (s *Service) SetDB(db dal.RDB) {
Expand All @@ -46,6 +48,8 @@ func (s *Service) WebService() *restful.WebService {
return s.CCErr
}
ws.Path("/collector/v3").Filter(rdapi.AllGlobalFilter(getErrFun)).Produces(restful.MIME_JSON).Consumes(restful.MIME_JSON)
ws.Route(ws.POST("/yovole/test/{bk_biz_id}/filecontent").To(s.GetFileContent))

ws.Route(ws.GET("/healthz").To(s.Healthz))

return ws
Expand Down
42 changes: 42 additions & 0 deletions src/scene_server/datacollection/service/yovoleTest.go
@@ -0,0 +1,42 @@
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 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 service

import (
"configcenter/src/common/blog"
meta "configcenter/src/common/metadata"
"github.com/emicklei/go-restful"
)

/*
* get the bk_biz_id from restful request, and then use the bk_biz_id
* to get the host id list in the biz_id, and get file content of
* /root/yovole from datacollection of every host
*/
func (s *Service) GetFileContent(req *restful.Request, resp *restful.Response) {
// pheader := req.Request.Header
// defErr := s.CCErr.CreateDefaultCCErrorIf(util.GetLanguage(pheader))

bizID := req.PathParameter("bk_biz_id")
blog.Debug("Yovole, bizID: %s", bizID)

// get host id list from bk_biz_id
// this is test data for web_server api call
// hostList := [...]int{903}

// get YovoleTest from datacollection
// this is test data for web_server api call
yovoleTest := meta.YovoleTest{BizID: 14, InnerIP: "10.3.12.210", HostID: 903, FileContent: "xyz"}

resp.WriteEntity(meta.NewSuccessResp(yovoleTest))
}

0 comments on commit 05ec67c

Please sign in to comment.