diff --git a/pkg/apigateway/handler/backendproxy.go b/pkg/apigateway/handler/backendproxy.go index 355ea1db65..ebd535ef08 100644 --- a/pkg/apigateway/handler/backendproxy.go +++ b/pkg/apigateway/handler/backendproxy.go @@ -20,6 +20,7 @@ import ( "net/http" "net/url" "strings" + "time" "yunion.io/x/log" @@ -84,7 +85,25 @@ func (h *SBackendServiceProxyHandler) requestManipulator(ctx context.Context, r } func (h *SBackendServiceProxyHandler) Bind(app *appsrv.Application) { - app.AddReverseProxyHandler(h.prefix, h.fetchReverseEndpoint(), h.requestManipulator) + app.AddReverseProxyHandlerWithCallbackConfig( + h.prefix, h.fetchReverseEndpoint(), h.requestManipulator, + func(method string, hi *appsrv.SHandlerInfo) *appsrv.SHandlerInfo { + if method == "OPTIONS" { + return nil + } + if method == "GET" || method == "PUT" || method == "POST" { + hi.SetProcessTimeout(6 * time.Hour) + } + var worker *appsrv.SWorkerManager + if method == "GET" || method == "HEAD" { + worker = appsrv.NewWorkerManager("apigateway-backend-api-read", 8, appsrv.DEFAULT_BACKLOG, false) + } else { + worker = appsrv.NewWorkerManager("apigateway-backend-api-write", 4, appsrv.DEFAULT_BACKLOG, false) + } + hi.SetWorkerManager(worker) + return hi + }, + ) } func (h *SBackendServiceProxyHandler) fetchReverseEndpoint() *proxy.SEndpointFactory { diff --git a/pkg/appsrv/appsrv.go b/pkg/appsrv/appsrv.go index 1448ecd990..2a5e8a24cd 100644 --- a/pkg/appsrv/appsrv.go +++ b/pkg/appsrv/appsrv.go @@ -150,9 +150,24 @@ func (app *Application) getRoot(method string) *RadixNode { } func (app *Application) AddReverseProxyHandler(prefix string, ef *proxy.SEndpointFactory, m proxy.RequestManipulator) { + app.AddReverseProxyHandlerWithCallbackConfig(prefix, ef, m, + func(method string, hi *SHandlerInfo) *SHandlerInfo { + return hi + }, + ) +} + +func (app *Application) AddReverseProxyHandlerWithCallbackConfig(prefix string, ef *proxy.SEndpointFactory, m proxy.RequestManipulator, confCb func(string, *SHandlerInfo) *SHandlerInfo) { handler := proxy.NewHTTPReverseProxy(ef, m).ServeHTTP for _, method := range []string{"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"} { - app.AddHandler(method, prefix, handler) + hi := &SHandlerInfo{} + hi = confCb(method, hi) + if hi != nil { + hi.SetMethod(method) + hi.SetPath(prefix) + hi.SetHandler(handler) + app.AddHandler3(hi) + } } } diff --git a/pkg/hostman/hostutils/hostutils.go b/pkg/hostman/hostutils/hostutils.go index 27cdaa90ce..35d07b2d3f 100644 --- a/pkg/hostman/hostutils/hostutils.go +++ b/pkg/hostman/hostutils/hostutils.go @@ -63,15 +63,15 @@ type IHost interface { } func GetComputeSession(ctx context.Context) *mcclient.ClientSession { - return auth.GetAdminSessionWithInternal(ctx, options.HostOptions.Region) + return auth.GetAdminSession(ctx, options.HostOptions.Region) } func GetK8sSession(ctx context.Context) *mcclient.ClientSession { - return auth.GetAdminSessionWithInternal(ctx, options.HostOptions.Region) + return auth.GetAdminSession(ctx, options.HostOptions.Region) } func GetImageSession(ctx context.Context, zone string) *mcclient.ClientSession { - return auth.AdminSessionWithInternal(ctx, options.HostOptions.Region, "") + return auth.AdminSession(ctx, options.HostOptions.Region, zone, "") } func TaskFailed(ctx context.Context, reason string) { diff --git a/pkg/mcclient/token3.go b/pkg/mcclient/token3.go index 3c1364ca92..d181ed1de3 100644 --- a/pkg/mcclient/token3.go +++ b/pkg/mcclient/token3.go @@ -370,7 +370,7 @@ func (catalog KeystoneServiceCatalogV3) getEndpoints(region string, endpointType } func RegionID(region, zone string) string { - if len(zone) > 0 { + if len(region) > 0 && len(zone) > 0 { return fmt.Sprintf("%s%c%s", region, REGION_ZONE_SEP, zone) } else { return region @@ -415,9 +415,10 @@ func (catalog KeystoneServiceCatalogV3) GetServiceURLs(service, region, zone, en } for j := 0; j < len(catalog[i].Endpoints); j++ { ep := catalog[i].Endpoints[j] - if strings.HasPrefix(endpointType, ep.Interface) && (ep.RegionId == region || - ep.RegionId == regionzone || - len(region) == 0) { + if strings.HasPrefix(endpointType, ep.Interface) && + (ep.RegionId == region || + ep.RegionId == regionzone || + len(region) == 0) { _, ok := regeps[ep.RegionId] if !ok { regeps[ep.RegionId] = make([]string, 0) @@ -432,7 +433,7 @@ func (catalog KeystoneServiceCatalogV3) GetServiceURLs(service, region, zone, en break } } else { - return nil, fmt.Errorf("No default region") + return nil, fmt.Errorf("No default region for region(%s) zone(%s)", region, zone) } } else { _, ok := regeps[regionzone]