mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 10:48:15 +08:00
[REV]调整discover服务代码结构
This commit is contained in:
parent
261ec4ff49
commit
0e3f827e79
@ -34,7 +34,6 @@ import (
|
||||
eventLog "github.com/goodrain/rainbond/pkg/event"
|
||||
|
||||
"github.com/goodrain/rainbond/pkg/node/api"
|
||||
"github.com/goodrain/rainbond/pkg/node/api/handler"
|
||||
"github.com/goodrain/rainbond/pkg/node/event"
|
||||
)
|
||||
|
||||
@ -87,10 +86,6 @@ func Run(c *option.Conf) error {
|
||||
}
|
||||
event.On(event.EXIT, ms.Stop)
|
||||
}
|
||||
//初始化discoverManager
|
||||
if err := handler.CreateDiscoverManger(c); err != nil {
|
||||
return err
|
||||
}
|
||||
//启动API服务
|
||||
apiManager := api.NewManager(*s.Conf, s.HostNode, ms)
|
||||
apiManager.Start(errChan)
|
||||
|
@ -31,6 +31,7 @@ var taskTempService *service.TaskTempService
|
||||
var taskGroupService *service.TaskGroupService
|
||||
var appService *service.AppService
|
||||
var nodeService *service.NodeService
|
||||
var discoverService *service.DiscoverAction
|
||||
|
||||
//Init 初始化
|
||||
func Init(c *option.Conf, ms *masterserver.MasterServer) {
|
||||
@ -40,6 +41,7 @@ func Init(c *option.Conf, ms *masterserver.MasterServer) {
|
||||
taskGroupService = service.CreateTaskGroupService(c)
|
||||
appService = service.CreateAppService(c)
|
||||
nodeService = service.CreateNodeService(c, ms.Cluster)
|
||||
discoverService = service.CreateDiscoverActionManager(c)
|
||||
}
|
||||
|
||||
//Exist 退出
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/goodrain/rainbond/pkg/api/util"
|
||||
"github.com/goodrain/rainbond/pkg/node/api/handler"
|
||||
"github.com/pquerna/ffjson/ffjson"
|
||||
)
|
||||
|
||||
@ -31,7 +30,7 @@ import (
|
||||
func ServiceDiscover(w http.ResponseWriter, r *http.Request) {
|
||||
serviceInfo := chi.URLParam(r, "service_name")
|
||||
//eg: serviceInfo := test_gr123456_201711031246
|
||||
sds, err := handler.GetDiscoverManager().DiscoverService(serviceInfo)
|
||||
sds, err := discoverService.DiscoverService(serviceInfo)
|
||||
if err != nil {
|
||||
err.Handle(r, w)
|
||||
return
|
||||
@ -49,7 +48,7 @@ func ServiceDiscover(w http.ResponseWriter, r *http.Request) {
|
||||
func ListenerDiscover(w http.ResponseWriter, r *http.Request) {
|
||||
tenantName := chi.URLParam(r, "tenant_name")
|
||||
serviceNodes := chi.URLParam(r, "service_nodes")
|
||||
lds, err := handler.GetDiscoverManager().DiscoverListeners(tenantName, serviceNodes)
|
||||
lds, err := discoverService.DiscoverListeners(tenantName, serviceNodes)
|
||||
if err != nil {
|
||||
err.Handle(r, w)
|
||||
return
|
||||
@ -67,7 +66,7 @@ func ListenerDiscover(w http.ResponseWriter, r *http.Request) {
|
||||
func ClusterDiscover(w http.ResponseWriter, r *http.Request) {
|
||||
tenantName := chi.URLParam(r, "tenant_name")
|
||||
serviceNodes := chi.URLParam(r, "service_nodes")
|
||||
cds, err := handler.GetDiscoverManager().DiscoverClusters(tenantName, serviceNodes)
|
||||
cds, err := discoverService.DiscoverClusters(tenantName, serviceNodes)
|
||||
if err != nil {
|
||||
err.Handle(r, w)
|
||||
return
|
||||
|
@ -1,49 +0,0 @@
|
||||
// RAINBOND, Application Management Platform
|
||||
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version. For any non-GPL usage of Rainbond,
|
||||
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
|
||||
// must be obtained first.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/goodrain/rainbond/cmd/node/option"
|
||||
"github.com/goodrain/rainbond/pkg/api/util"
|
||||
node_model "github.com/goodrain/rainbond/pkg/node/api/model"
|
||||
)
|
||||
|
||||
//DiscoverHandler DiscoverHandler
|
||||
type DiscoverHandler interface {
|
||||
DiscoverService(serviceInfo string) (*node_model.SDS, *util.APIHandleError)
|
||||
DiscoverListeners(tenantName, serviceCluster string) (*node_model.LDS, *util.APIHandleError)
|
||||
DiscoverClusters(tenantName, serviceCluster string) (*node_model.CDS, *util.APIHandleError)
|
||||
}
|
||||
|
||||
var defaultDiscoverHandler DiscoverHandler
|
||||
|
||||
//CreateDiscoverManger CreateDiscoverManger
|
||||
func CreateDiscoverManger(conf *option.Conf) error {
|
||||
var err error
|
||||
defaultDiscoverHandler, err = CreateDiscoverActionManager(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//GetDiscoverManager get manager
|
||||
func GetDiscoverManager() DiscoverHandler {
|
||||
return defaultDiscoverHandler
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package handler
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -32,11 +32,15 @@ import (
|
||||
)
|
||||
|
||||
//DiscoverAction DiscoverAction
|
||||
type DiscoverAction struct{}
|
||||
type DiscoverAction struct {
|
||||
conf *option.Conf
|
||||
}
|
||||
|
||||
//CreateDiscoverActionManager CreateDiscoverActionManager
|
||||
func CreateDiscoverActionManager(conf *option.Conf) (*DiscoverAction, error) {
|
||||
return &DiscoverAction{}, nil
|
||||
func CreateDiscoverActionManager(conf *option.Conf) *DiscoverAction {
|
||||
return &DiscoverAction{
|
||||
conf: conf,
|
||||
}
|
||||
}
|
||||
|
||||
//DiscoverService DiscoverService
|
Loading…
Reference in New Issue
Block a user