[REV] optimize build api proxy in api

This commit is contained in:
bay1ts 2017-12-12 10:07:25 +08:00
parent 6a5731f0bc
commit 76cf3e527f
3 changed files with 16 additions and 0 deletions

View File

@ -33,6 +33,7 @@ type Config struct {
DBConnectionInfo string
EventLogServers []string
NodeAPI []string
BuilderAPI []string
EntranceAPI []string
V1API string
MQAPI string
@ -77,6 +78,7 @@ func (a *APIServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.WebsocketKeyFile, "ws-ssl-keyfile", "/etc/ssl/goodrain.com/goodrain.com.key", "websocket and fileserver ssl key file")
fs.StringVar(&a.V1API, "v1-api", "127.0.0.1:8887", "the region v1 api")
fs.StringSliceVar(&a.NodeAPI, "node-api", []string{"127.0.0.1:6100"}, "the node server api")
fs.StringSliceVar(&a.BuilderAPI, "builder-api", []string{"127.0.0.1:3228"}, "the builder api")
fs.StringSliceVar(&a.EntranceAPI, "entrance-api", []string{"127.0.0.1:6200"}, "the entrance api")
fs.StringSliceVar(&a.EventLogServers, "event-servers", []string{"127.0.0.1:6367"}, "event log server address. simple lb")
fs.StringVar(&a.MQAPI, "mq-api", "127.0.0.1:6300", "acp_mq api")

View File

@ -133,6 +133,10 @@ func Proxy(next http.Handler) http.Handler {
GetNodeProxy().Proxy(w, r)
return
}
if strings.HasPrefix(r.RequestURI, "/v2/builder") {
GetBuilderProxy().Proxy(w, r)
return
}
if strings.HasPrefix(r.RequestURI, "/v2/tasks") {
GetNodeProxy().Proxy(w, r)
return

View File

@ -25,6 +25,8 @@ import (
)
var nodeProxy proxy.Proxy
var builderProxy proxy.Proxy
//InitProxy 初始化
func InitProxy(conf option.Config) {
@ -32,9 +34,17 @@ func InitProxy(conf option.Config) {
nodeProxy = proxy.CreateProxy("acp_node", "http", conf.NodeAPI)
discover.GetEndpointDiscover(conf.EtcdEndpoint).AddProject("acp_node", nodeProxy)
}
if builderProxy == nil {
builderProxy = proxy.CreateProxy("builder", "http", conf.NodeAPI)
discover.GetEndpointDiscover(conf.EtcdEndpoint).AddProject("acp_node", nodeProxy)
}
}
//GetNodeProxy GetNodeProxy
func GetNodeProxy() proxy.Proxy {
return nodeProxy
}
//GetNodeProxy GetNodeProxy
func GetBuilderProxy() proxy.Proxy {
return builderProxy
}