mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix: endpoint mode slave (#24016)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -66,7 +66,7 @@ func init() {
|
||||
type EndpointCreateOptions struct {
|
||||
SERVICE string `help:"Service ID or Name"`
|
||||
REGION string `help:"Region"`
|
||||
INTERFACE string `help:"Interface types" choices:"internal|public|admin|console"`
|
||||
INTERFACE string `help:"Interface types" choices:"internal|public|admin|console|slave"`
|
||||
URL string `help:"URL"`
|
||||
Zone string `help:"Zone"`
|
||||
Name string `help:"Name"`
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
"yunion.io/x/pkg/util/signalutils"
|
||||
|
||||
@@ -76,7 +77,7 @@ func init() {
|
||||
svcUrl string
|
||||
)
|
||||
if len(opts.Service) > 0 {
|
||||
svcUrl, err = s.GetServiceURL(opts.Service, "")
|
||||
svcUrl, err = s.GetServiceURL(opts.Service, "", httputils.GET)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "get service %s url", opts.Service)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
db.RegisterModelManager(db.OpsLog)
|
||||
@@ -51,6 +51,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
@@ -24,7 +24,9 @@ import (
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/appctx"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
@@ -149,12 +151,11 @@ func (h *SBackendServiceProxyHandler) fetchReverseEndpoint() *proxy.SEndpointFac
|
||||
zone = path[:slashPos]
|
||||
}
|
||||
}
|
||||
endpointType := "internalURL"
|
||||
session := auth.GetAdminSession(ctx, region)
|
||||
if len(zone) > 0 {
|
||||
session.SetZone(zone)
|
||||
}
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType)
|
||||
ep, err := session.GetServiceURL(serviceName, identity.EndpointInterfaceInternal, httputils.THttpMethod(r.Method))
|
||||
if err != nil {
|
||||
return "", httperrors.NewBadRequestError("invalid service %s: %s", serviceName, err)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/proxy"
|
||||
@@ -67,9 +70,8 @@ func getEndpointSchemeHost(endpoint string) (string, error) {
|
||||
|
||||
func fetchReverseEndpoint(serviceName string) *proxy.SEndpointFactory {
|
||||
f := func(ctx context.Context, r *http.Request) (string, error) {
|
||||
endpointType := "internalURL"
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r))
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType)
|
||||
ep, err := session.GetServiceURL(serviceName, identity.EndpointInterfaceInternal, httputils.THttpMethod(r.Method))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ const (
|
||||
|
||||
EndpointInterfaceApigateway = "apigateway"
|
||||
|
||||
EndpointInterfaceSlave = "slave"
|
||||
|
||||
KeystoneDomainRoot = "<<keystone.domain.root>>"
|
||||
|
||||
IdMappingEntityUser = "user"
|
||||
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
)
|
||||
|
||||
func AddModelDispatcher(prefix string, app *appsrv.Application, manager IModelDispatchHandler) {
|
||||
func AddModelDispatcher(prefix string, app *appsrv.Application, manager IModelDispatchHandler, isSlave bool) {
|
||||
metadata := map[string]interface{}{"manager": manager}
|
||||
tags := map[string]string{"resource": manager.KeywordPlural()}
|
||||
// list
|
||||
@@ -69,6 +69,12 @@ func AddModelDispatcher(prefix string, app *appsrv.Application, manager IModelDi
|
||||
fmt.Sprintf("%s/%s/<resid>/<spec>", prefix, manager.KeywordPlural()),
|
||||
manager.Filter(getSpecHandler), metadata, "get_specific", tags)
|
||||
manager.CustomizeHandlerInfo(h)
|
||||
|
||||
if isSlave {
|
||||
// slave node only support get and head
|
||||
return
|
||||
}
|
||||
|
||||
// create
|
||||
// create multi
|
||||
h = app.AddHandler2("POST",
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
)
|
||||
|
||||
func AddJointModelDispatcher(prefix string, app *appsrv.Application, manager IJointModelDispatchHandler) {
|
||||
func AddJointModelDispatcher(prefix string, app *appsrv.Application, manager IJointModelDispatchHandler, isSlave bool) {
|
||||
metadata := map[string]interface{}{"manager": manager}
|
||||
tags := map[string]string{"resource": manager.KeywordPlural()}
|
||||
// list
|
||||
@@ -64,6 +64,12 @@ func AddJointModelDispatcher(prefix string, app *appsrv.Application, manager IJo
|
||||
manager.MasterKeywordPlural()),
|
||||
manager.Filter(jointGetHandler),
|
||||
metadata, "get_joint", tags)
|
||||
|
||||
if isSlave {
|
||||
// slave node only support get and head
|
||||
return
|
||||
}
|
||||
|
||||
// joint attach
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s/<master_id>/%s/<slave_id>", prefix,
|
||||
|
||||
@@ -1155,7 +1155,7 @@ func (b *SBaremetalInstance) getHTTPFileUrl(filename string) string {
|
||||
|
||||
func (b *SBaremetalInstance) GetImageUrl(disableImageCache bool) string {
|
||||
if disableImageCache {
|
||||
url, err := b.GetPublicClientSession().GetServiceURL(apis.SERVICE_TYPE_IMAGE, apiidenty.EndpointInterfacePublic)
|
||||
url, err := b.GetPublicClientSession().GetServiceURL(apis.SERVICE_TYPE_IMAGE, apiidenty.EndpointInterfacePublic, httputils.GET)
|
||||
if err != nil {
|
||||
log.Errorf("Get image public url: %v", err)
|
||||
return ""
|
||||
@@ -2388,7 +2388,7 @@ func (b *SBaremetalInstance) getBootIsoImagePath() string {
|
||||
func (b *SBaremetalInstance) DoNTPConfig() error {
|
||||
var urls []string
|
||||
for _, ep := range []string{"internal", "public"} {
|
||||
urls, _ = auth.GetServiceURLs("ntp", o.Options.Region, "", ep)
|
||||
urls, _ = auth.GetServiceURLs("ntp", o.Options.Region, "", ep, httputils.POST)
|
||||
if len(urls) > 0 {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
@@ -113,7 +114,7 @@ func FetchEtcdServiceInfo() (*identity.EndpointDetails, error) {
|
||||
|
||||
func startEtcdEndpointPuller() {
|
||||
retryInterval := 60
|
||||
etecdUrl, err := auth.GetServiceURL(apis.SERVICE_TYPE_ETCD, consts.GetRegion(), "", identity.EndpointInterfaceInternal)
|
||||
etecdUrl, err := auth.GetServiceURL(apis.SERVICE_TYPE_ETCD, consts.GetRegion(), "", identity.EndpointInterfaceInternal, httputils.POST)
|
||||
if err != nil {
|
||||
log.Errorf("[etcd] GetServiceURL fail %s, retry after %d seconds", err, retryInterval)
|
||||
} else if len(etecdUrl) == 0 {
|
||||
|
||||
@@ -72,7 +72,7 @@ type SBaseQuotaQueryInput struct {
|
||||
Refresh bool `json:"refresh"`
|
||||
}
|
||||
|
||||
func AddQuotaHandler(manager *SQuotaBaseManager, prefix string, app *appsrv.Application) {
|
||||
func AddQuotaHandler(manager *SQuotaBaseManager, prefix string, app *appsrv.Application, isSlave bool) {
|
||||
app.AddHandler2("GET",
|
||||
fmt.Sprintf("%s/%s", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.getQuotaHandler), nil, "get_quota", nil)
|
||||
@@ -85,21 +85,23 @@ func AddQuotaHandler(manager *SQuotaBaseManager, prefix string, app *appsrv.Appl
|
||||
fmt.Sprintf("%s/%s/domains/<domainid>", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.getQuotaHandler), nil, "get_quota_for_domain", nil)
|
||||
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.setQuotaHandler), nil, "set_quota", nil)
|
||||
if !isSlave {
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.setQuotaHandler), nil, "set_quota", nil)
|
||||
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s/domains/<domainid>", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.setQuotaHandler), nil, "set_quota_for_domain", nil)
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s/domains/<domainid>", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.setQuotaHandler), nil, "set_quota_for_domain", nil)
|
||||
|
||||
app.AddHandler2("DELETE",
|
||||
fmt.Sprintf("%s/%s/pending", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.cleanPendingUsageHandler), nil, "clean_pending_usage", nil)
|
||||
app.AddHandler2("DELETE",
|
||||
fmt.Sprintf("%s/%s/pending", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.cleanPendingUsageHandler), nil, "clean_pending_usage", nil)
|
||||
|
||||
app.AddHandler2("DELETE",
|
||||
fmt.Sprintf("%s/%s/domains/<domainid>/pending", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.cleanPendingUsageHandler), nil, "clean_pending_usage_for_domain", nil)
|
||||
app.AddHandler2("DELETE",
|
||||
fmt.Sprintf("%s/%s/domains/<domainid>/pending", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.cleanPendingUsageHandler), nil, "clean_pending_usage_for_domain", nil)
|
||||
}
|
||||
|
||||
if manager.scope == rbacscope.ScopeProject {
|
||||
app.AddHandler2("GET",
|
||||
@@ -114,17 +116,19 @@ func AddQuotaHandler(manager *SQuotaBaseManager, prefix string, app *appsrv.Appl
|
||||
fmt.Sprintf("%s/%s/projects/<tenantid>", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.getQuotaHandler), nil, "get_quota_for_project", nil)
|
||||
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s/<tenantid>", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.setQuotaHandler), nil, "set_quota_for_project", nil)
|
||||
if !isSlave {
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s/<tenantid>", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.setQuotaHandler), nil, "set_quota_for_project", nil)
|
||||
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s/projects/<tenantid>", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.setQuotaHandler), nil, "set_quota_for_project", nil)
|
||||
app.AddHandler2("POST",
|
||||
fmt.Sprintf("%s/%s/projects/<tenantid>", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.setQuotaHandler), nil, "set_quota_for_project", nil)
|
||||
|
||||
app.AddHandler2("DELETE",
|
||||
fmt.Sprintf("%s/%s/projects/<tenantid>/pending", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.cleanPendingUsageHandler), nil, "clean_pending_usage_for_project", nil)
|
||||
app.AddHandler2("DELETE",
|
||||
fmt.Sprintf("%s/%s/projects/<tenantid>/pending", prefix, manager.KeywordPlural()),
|
||||
auth.Authenticate(manager.cleanPendingUsageHandler), nil, "clean_pending_usage_for_project", nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
)
|
||||
|
||||
func AddTaskHandler(prefix string, app *appsrv.Application) {
|
||||
func AddTaskHandler(prefix string, app *appsrv.Application, isSlave bool) {
|
||||
handler := db.NewModelHandler(TaskManager)
|
||||
dispatcher.AddModelDispatcher(prefix, app, handler)
|
||||
dispatcher.AddModelDispatcher(prefix, app, handler, isSlave)
|
||||
|
||||
{
|
||||
initArchivedTaskManager()
|
||||
archiveHandler := db.NewModelHandler(ArchivedTaskManager)
|
||||
dispatcher.AddModelDispatcher(prefix, app, archiveHandler)
|
||||
dispatcher.AddModelDispatcher(prefix, app, archiveHandler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"math/rand"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -38,7 +39,7 @@ func NewTSDBServiceSource(t string, urls []string) *TSDBServiceSource {
|
||||
func GetDefaultServiceSource(s *mcclient.ClientSession, endpointType string) (*TSDBServiceSource, error) {
|
||||
errs := []error{}
|
||||
for _, sType := range []string{apis.SERVICE_TYPE_INFLUXDB, apis.SERVICE_TYPE_VICTORIA_METRICS} {
|
||||
urls, err := s.GetServiceURLs(sType, endpointType)
|
||||
urls, err := s.GetServiceURLs(sType, endpointType, httputils.POST)
|
||||
if err != nil {
|
||||
errs = append(errs, errors.Wrapf(err, "get %s service type %q", endpointType, sType))
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudevent/models"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
models.InitCloudevent()
|
||||
|
||||
taskman.AddTaskHandler("v1", app)
|
||||
taskman.AddTaskHandler("v1", app, isSlave)
|
||||
|
||||
for _, manager := range []db.IModelManager{
|
||||
taskman.TaskManager,
|
||||
@@ -67,6 +67,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func StartService() {
|
||||
|
||||
app := common_app.InitApp(baseOpts, false)
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
@@ -37,10 +37,10 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudid/models"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
taskman.AddTaskHandler("v1", app)
|
||||
taskman.AddTaskHandler("v1", app, isSlave)
|
||||
|
||||
db.AddScopeResourceCountHandler("", app)
|
||||
|
||||
@@ -72,7 +72,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
|
||||
for _, manager := range []db.IJointModelManager{
|
||||
@@ -82,7 +82,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewJointModelHandler(manager)
|
||||
dispatcher.AddJointModelDispatcher("", app, handler)
|
||||
dispatcher.AddJointModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
@@ -75,17 +75,17 @@ func StartService() {
|
||||
return
|
||||
}
|
||||
|
||||
models.CloudaccountManager.StartWatchSAMLInRegion()
|
||||
if err != nil {
|
||||
log.Fatalf("StartWatchSAMLInRegion error: %v", err)
|
||||
}
|
||||
|
||||
models.CloudproviderManager.StartWatchInRegion()
|
||||
if err != nil {
|
||||
log.Fatalf("StartWatchInRegion error: %v", err)
|
||||
}
|
||||
|
||||
if !opts.IsSlaveNode {
|
||||
models.CloudaccountManager.StartWatchSAMLInRegion()
|
||||
if err != nil {
|
||||
log.Fatalf("StartWatchSAMLInRegion error: %v", err)
|
||||
}
|
||||
|
||||
models.CloudproviderManager.StartWatchInRegion()
|
||||
if err != nil {
|
||||
log.Fatalf("StartWatchInRegion error: %v", err)
|
||||
}
|
||||
|
||||
err := taskman.TaskManager.InitializeData()
|
||||
if err != nil {
|
||||
log.Fatalf("TaskManager.InitializeData fail %s", err)
|
||||
|
||||
@@ -22,11 +22,11 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/etcd/models/base"
|
||||
)
|
||||
|
||||
func initHandlers(app *appsrv.Application) {
|
||||
func initHandlers(app *appsrv.Application, isSlave bool) {
|
||||
for _, manager := range []base.IEtcdModelManager{
|
||||
models.ServiceRegistryManager,
|
||||
} {
|
||||
handler := handler.NewEtcdModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func StartService() {
|
||||
}
|
||||
|
||||
app := app_common.InitApp(baseOpts, false)
|
||||
initHandlers(app)
|
||||
initHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
app_common.ServeForeverWithCleanup(app, baseOpts, func() {
|
||||
etcd.CloseDefaultEtcdClient()
|
||||
|
||||
@@ -35,7 +35,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudnet/models"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
db.RegisterModelManager(db.OpsLog)
|
||||
@@ -52,6 +52,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudproxy/models"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
db.RegisterModelManager(db.OpsLog)
|
||||
@@ -36,6 +36,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
@@ -78,7 +79,7 @@ func getBmPrepareScript(ctx context.Context, w http.ResponseWriter, r *http.Requ
|
||||
httperrors.NotAcceptableError(ctx, w, "Baremetal package not prepared")
|
||||
return
|
||||
}
|
||||
regionUrl, err := auth.GetPublicServiceURL("compute_v2", options.Options.Region, "")
|
||||
regionUrl, err := auth.GetPublicServiceURL("compute_v2", options.Options.Region, "", httputils.POST)
|
||||
if err != nil {
|
||||
httperrors.InternalServerError(ctx, w, "%v", err)
|
||||
return
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
@@ -611,7 +612,7 @@ func joinPath(ep, path string) string {
|
||||
}
|
||||
|
||||
func (bucket *SBucket) getMoreDetails(out api.BucketDetails) api.BucketDetails {
|
||||
s3gwUrl, _ := auth.GetServiceURL("s3gateway", options.Options.Region, "", identity_apis.EndpointInterfacePublic)
|
||||
s3gwUrl, _ := auth.GetServiceURL("s3gateway", options.Options.Region, "", identity_apis.EndpointInterfacePublic, httputils.POST)
|
||||
|
||||
if len(s3gwUrl) > 0 {
|
||||
accessUrls := make([]cloudprovider.SBucketAccessUrl, 0)
|
||||
|
||||
@@ -55,6 +55,7 @@ import (
|
||||
hostapi "yunion.io/x/onecloud/pkg/apis/host"
|
||||
napi "yunion.io/x/onecloud/pkg/apis/notify"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
@@ -1452,7 +1453,7 @@ func (hh *SHostManager) GetPropertyK8sMasterNodeIps(ctx context.Context, userCre
|
||||
}
|
||||
|
||||
func (hh *SHostManager) GetPropertyBmStartRegisterScript(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
regionUri, err := auth.GetPublicServiceURL("compute_v2", options.Options.Region, "")
|
||||
regionUri, err := auth.GetPublicServiceURL(consts.GetServiceType(), options.Options.Region, "", httputils.POST)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -32,20 +32,22 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/compute/usages"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
db.RegistUserCredCacheUpdater()
|
||||
|
||||
db.AddScopeResourceCountHandler("", app)
|
||||
db.AddHistoryDataCleanHandler("", app)
|
||||
if !isSlave {
|
||||
db.AddHistoryDataCleanHandler("", app)
|
||||
}
|
||||
|
||||
quotas.AddQuotaHandler(&models.QuotaManager.SQuotaBaseManager, "", app)
|
||||
quotas.AddQuotaHandler(&models.RegionQuotaManager.SQuotaBaseManager, "", app)
|
||||
quotas.AddQuotaHandler(&models.ZoneQuotaManager.SQuotaBaseManager, "", app)
|
||||
quotas.AddQuotaHandler(&models.ProjectQuotaManager.SQuotaBaseManager, "", app)
|
||||
quotas.AddQuotaHandler(&models.DomainQuotaManager.SQuotaBaseManager, "", app)
|
||||
quotas.AddQuotaHandler(&models.InfrasQuotaManager.SQuotaBaseManager, "", app)
|
||||
quotas.AddQuotaHandler(&models.QuotaManager.SQuotaBaseManager, "", app, isSlave)
|
||||
quotas.AddQuotaHandler(&models.RegionQuotaManager.SQuotaBaseManager, "", app, isSlave)
|
||||
quotas.AddQuotaHandler(&models.ZoneQuotaManager.SQuotaBaseManager, "", app, isSlave)
|
||||
quotas.AddQuotaHandler(&models.ProjectQuotaManager.SQuotaBaseManager, "", app, isSlave)
|
||||
quotas.AddQuotaHandler(&models.DomainQuotaManager.SQuotaBaseManager, "", app, isSlave)
|
||||
quotas.AddQuotaHandler(&models.InfrasQuotaManager.SQuotaBaseManager, "", app, isSlave)
|
||||
|
||||
usages.AddUsageHandler("", app)
|
||||
usages.AddHistoryUsageHandler("", app)
|
||||
@@ -53,7 +55,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
specs.AddSpecHandler("", app)
|
||||
sshkeys.AddSshKeysHandler("", app)
|
||||
|
||||
taskman.AddTaskHandler("", app)
|
||||
taskman.AddTaskHandler("", app, isSlave)
|
||||
|
||||
misc.AddMiscHandler("", app)
|
||||
|
||||
@@ -261,7 +263,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
|
||||
for _, manager := range []db.IJointModelManager{
|
||||
@@ -295,6 +297,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewJointModelHandler(manager)
|
||||
dispatcher.AddJointModelDispatcher("", app, handler)
|
||||
dispatcher.AddJointModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
_ "yunion.io/x/sqlchemy/backends"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
@@ -85,7 +86,7 @@ func StartServiceWithJobsAndApp(jobs func(cron *cronman.SCronJobManager), appCll
|
||||
})
|
||||
common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, options.OnOptionsChange)
|
||||
|
||||
serviceUrl, err := auth.GetServiceURL(apis.SERVICE_TYPE_REGION, opts.Region, "", identity.EndpointInterfaceInternal)
|
||||
serviceUrl, err := auth.GetServiceURL(apis.SERVICE_TYPE_REGION, opts.Region, "", identity.EndpointInterfaceInternal, httputils.POST)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to get service url: %v", err)
|
||||
}
|
||||
@@ -115,7 +116,7 @@ func StartServiceWithJobsAndApp(jobs func(cron *cronman.SCronJobManager), appCll
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
if appCllback != nil {
|
||||
appCllback(app)
|
||||
}
|
||||
@@ -123,10 +124,18 @@ func StartServiceWithJobsAndApp(jobs func(cron *cronman.SCronJobManager), appCll
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
if !opts.IsSlaveNode {
|
||||
startMasterTasks(opts, dbOpts, jobs)
|
||||
}
|
||||
|
||||
common_app.ServeForever(app, baseOpts)
|
||||
}
|
||||
|
||||
func startMasterTasks(opts *options.ComputeOptions, dbOpts *common_options.DBOptions, jobs func(cron *cronman.SCronJobManager)) {
|
||||
setInfluxdbRetentionPolicy()
|
||||
|
||||
models.InitSyncWorkers(options.Options.CloudSyncWorkerCount)
|
||||
cloudaccount_tasks.InitCloudproviderSyncWorkers(options.Options.CloudProviderSyncWorkerCount)
|
||||
models.InitSyncWorkers(opts.CloudSyncWorkerCount)
|
||||
cloudaccount_tasks.InitCloudproviderSyncWorkers(opts.CloudProviderSyncWorkerCount)
|
||||
|
||||
var (
|
||||
electObj *elect.Elect
|
||||
@@ -229,11 +238,8 @@ func StartServiceWithJobsAndApp(jobs func(cron *cronman.SCronJobManager), appCll
|
||||
|
||||
go cron.Start2(ctx, electObj)
|
||||
}
|
||||
if !opts.IsSlaveNode {
|
||||
go cronFunc()
|
||||
}
|
||||
|
||||
common_app.ServeForever(app, baseOpts)
|
||||
go cronFunc()
|
||||
}
|
||||
|
||||
func initDefaultEtcdClient(opts *common_options.DBOptions) error {
|
||||
|
||||
@@ -22,10 +22,10 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/devtool/models"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
taskman.AddTaskHandler("", app)
|
||||
taskman.AddTaskHandler("", app, isSlave)
|
||||
|
||||
for _, manager := range []db.IModelManager{
|
||||
taskman.TaskManager,
|
||||
@@ -54,6 +54,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func StartService() {
|
||||
app := app_common.InitApp(&opts.BaseOptions, false)
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
"yunion.io/x/pkg/util/version"
|
||||
"yunion.io/x/pkg/utils"
|
||||
@@ -2516,7 +2517,7 @@ func (h *SHostInfo) OnCatalogChanged(catalog mcclient.KeystoneServiceCatalogV3)
|
||||
|
||||
if options.HostOptions.ManageNtpConfiguration {
|
||||
ntpd := system_service.GetService("ntpd")
|
||||
urls, _ := s.GetServiceURLs("ntp", defaultEndpointType)
|
||||
urls, _ := s.GetServiceURLs("ntp", defaultEndpointType, httputils.POST)
|
||||
if len(urls) > 0 {
|
||||
log.Infof("Get Ntp urls: %v", urls)
|
||||
} else {
|
||||
@@ -2553,7 +2554,7 @@ func (h *SHostInfo) OnCatalogChanged(catalog mcclient.KeystoneServiceCatalogV3)
|
||||
hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR: options.HostOptions.HostType,
|
||||
}
|
||||
conf["nics"] = h.getNicsTelegrafConf()
|
||||
urls, _ := s.GetServiceURLs("kafka", defaultEndpointType)
|
||||
urls, _ := s.GetServiceURLs("kafka", defaultEndpointType, httputils.POST)
|
||||
if len(urls) > 0 {
|
||||
kafkaConf := map[string]interface{}{
|
||||
"brokers": urls,
|
||||
@@ -2571,7 +2572,7 @@ func (h *SHostInfo) OnCatalogChanged(catalog mcclient.KeystoneServiceCatalogV3)
|
||||
conf["kafka"] = kafkaConf
|
||||
}
|
||||
|
||||
urls, _ = s.GetServiceURLs("opentsdb", defaultEndpointType)
|
||||
urls, _ = s.GetServiceURLs("opentsdb", defaultEndpointType, httputils.POST)
|
||||
if len(urls) > 0 {
|
||||
conf["opentsdb"] = map[string]interface{}{
|
||||
"url": urls[0],
|
||||
|
||||
@@ -199,7 +199,7 @@ func (l *SLocalImageCache) prepare(ctx context.Context, input api.CacheImageInpu
|
||||
l.consumerCount++
|
||||
return true, nil
|
||||
}
|
||||
url, err := auth.GetServiceURL(apis.SERVICE_TYPE_IMAGE, "", input.Zone, "")
|
||||
url, err := auth.GetServiceURL(apis.SERVICE_TYPE_IMAGE, "", input.Zone, "", httputils.GET)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "GetServiceURL(%s)", apis.SERVICE_TYPE_IMAGE)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ const (
|
||||
API_VERSION = "v1"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
// add version handler with API_VERSION prefix
|
||||
@@ -40,10 +40,10 @@ func InitHandlers(app *appsrv.Application) {
|
||||
|
||||
db.AddScopeResourceCountHandler(API_VERSION, app)
|
||||
|
||||
quotas.AddQuotaHandler(&models.QuotaManager.SQuotaBaseManager, API_VERSION, app)
|
||||
quotas.AddQuotaHandler(&models.QuotaManager.SQuotaBaseManager, API_VERSION, app, isSlave)
|
||||
usages.AddUsageHandler(API_VERSION, app)
|
||||
|
||||
taskman.AddTaskHandler(API_VERSION, app)
|
||||
taskman.AddTaskHandler(API_VERSION, app, isSlave)
|
||||
|
||||
app_common.ExportOptionsHandler(app, &options.Options)
|
||||
|
||||
@@ -80,6 +80,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher(API_VERSION, app, handler)
|
||||
dispatcher.AddModelDispatcher(API_VERSION, app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,18 +104,8 @@ func StartService() {
|
||||
procutils.SetRemoteExecutor()
|
||||
}
|
||||
|
||||
log.Infof("Target image formats %#v", opts.TargetImageFormats)
|
||||
if !opts.IsSlaveNode {
|
||||
|
||||
if ok, err := hasVmwareAccount(); err != nil {
|
||||
log.Errorf("failed get vmware cloudaccounts: %v", err)
|
||||
} else if ok {
|
||||
if !utils.IsInStringArray(string(qemuimgfmt.VMDK), options.Options.TargetImageFormats) {
|
||||
if err = models.UpdateImageConfigTargetImageFormats(context.Background(), auth.AdminCredential()); err != nil {
|
||||
log.Errorf("failed update target_image_formats %s", err)
|
||||
} else {
|
||||
options.Options.TargetImageFormats = append(options.Options.TargetImageFormats, string(qemuimgfmt.VMDK))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trackers := torrent.GetTrackers()
|
||||
@@ -128,7 +118,7 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
|
||||
@@ -139,35 +129,8 @@ func StartService() {
|
||||
deployclient.Init(options.Options.DeployServerSocketPath)
|
||||
}
|
||||
|
||||
go func() {
|
||||
if options.Options.HasValidS3Options() {
|
||||
initS3()
|
||||
}
|
||||
// check image after s3 mounted
|
||||
models.CheckImages()
|
||||
}()
|
||||
|
||||
if !opts.IsSlaveNode {
|
||||
err := taskman.TaskManager.InitializeData()
|
||||
if err != nil {
|
||||
log.Fatalf("TaskManager.InitializeData fail %s", err)
|
||||
}
|
||||
|
||||
cachesync.StartTenantCacheSync(opts.TenantCacheExpireSeconds)
|
||||
|
||||
cron := cronman.InitCronJobManager(true, options.Options.CronJobWorkerCount, options.Options.TimeZone)
|
||||
cron.AddJobAtIntervals("CleanPendingDeleteImages", time.Duration(options.Options.PendingDeleteCheckSeconds)*time.Second, models.ImageManager.CleanPendingDeleteImages)
|
||||
cron.AddJobAtIntervals("CalculateQuotaUsages", time.Duration(opts.CalculateQuotaUsageIntervalSeconds)*time.Second, models.QuotaManager.CalculateQuotaUsages)
|
||||
cron.AddJobAtIntervals("CleanPendingDeleteGuestImages",
|
||||
time.Duration(options.Options.PendingDeleteCheckSeconds)*time.Second, models.GuestImageManager.CleanPendingDeleteImages)
|
||||
|
||||
cron.AddJobEveryFewHour("AutoPurgeSplitable", 4, 30, 0, db.AutoPurgeSplitable, false)
|
||||
|
||||
cron.AddJobAtIntervalsWithStartRun("TaskCleanupJob", time.Duration(options.Options.TaskArchiveIntervalMinutes)*time.Minute, taskman.TaskManager.TaskCleanupJob, true)
|
||||
|
||||
cron.AddJobAtIntervals("MarkDataImage", time.Duration(options.Options.VerifyImageStatusIntervalMinutes)*time.Minute, models.ImageManager.VerifyActiveImageStatus)
|
||||
|
||||
cron.Start()
|
||||
startMasterTasks(opts)
|
||||
}
|
||||
|
||||
app_common.ServeForeverWithCleanup(app, baseOpts, func() {
|
||||
@@ -184,6 +147,51 @@ func StartService() {
|
||||
})
|
||||
}
|
||||
|
||||
func startMasterTasks(opts *options.SImageOptions) {
|
||||
log.Infof("Target image formats %#v", opts.TargetImageFormats)
|
||||
|
||||
if ok, err := hasVmwareAccount(); err != nil {
|
||||
log.Errorf("failed get vmware cloudaccounts: %v", err)
|
||||
} else if ok {
|
||||
if !utils.IsInStringArray(string(qemuimgfmt.VMDK), options.Options.TargetImageFormats) {
|
||||
if err = models.UpdateImageConfigTargetImageFormats(context.Background(), auth.AdminCredential()); err != nil {
|
||||
log.Errorf("failed update target_image_formats %s", err)
|
||||
} else {
|
||||
options.Options.TargetImageFormats = append(options.Options.TargetImageFormats, string(qemuimgfmt.VMDK))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
if options.Options.HasValidS3Options() {
|
||||
initS3()
|
||||
}
|
||||
// check image after s3 mounted
|
||||
models.CheckImages()
|
||||
}()
|
||||
|
||||
err := taskman.TaskManager.InitializeData()
|
||||
if err != nil {
|
||||
log.Fatalf("TaskManager.InitializeData fail %s", err)
|
||||
}
|
||||
|
||||
cachesync.StartTenantCacheSync(opts.TenantCacheExpireSeconds)
|
||||
|
||||
cron := cronman.InitCronJobManager(true, options.Options.CronJobWorkerCount, options.Options.TimeZone)
|
||||
cron.AddJobAtIntervals("CleanPendingDeleteImages", time.Duration(options.Options.PendingDeleteCheckSeconds)*time.Second, models.ImageManager.CleanPendingDeleteImages)
|
||||
cron.AddJobAtIntervals("CalculateQuotaUsages", time.Duration(opts.CalculateQuotaUsageIntervalSeconds)*time.Second, models.QuotaManager.CalculateQuotaUsages)
|
||||
cron.AddJobAtIntervals("CleanPendingDeleteGuestImages",
|
||||
time.Duration(options.Options.PendingDeleteCheckSeconds)*time.Second, models.GuestImageManager.CleanPendingDeleteImages)
|
||||
|
||||
cron.AddJobEveryFewHour("AutoPurgeSplitable", 4, 30, 0, db.AutoPurgeSplitable, false)
|
||||
|
||||
cron.AddJobAtIntervalsWithStartRun("TaskCleanupJob", time.Duration(options.Options.TaskArchiveIntervalMinutes)*time.Minute, taskman.TaskManager.TaskCleanupJob, true)
|
||||
|
||||
cron.AddJobAtIntervals("MarkDataImage", time.Duration(options.Options.VerifyImageStatusIntervalMinutes)*time.Minute, models.ImageManager.VerifyActiveImageStatus)
|
||||
|
||||
cron.Start()
|
||||
}
|
||||
|
||||
func hasVmwareAccount() (bool, error) {
|
||||
q := jsonutils.NewDict()
|
||||
q.Add(jsonutils.NewString("system"), "scope")
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
|
||||
identity_apis "yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
@@ -61,7 +62,7 @@ func (stat *STorrentProcessState) StopAndWait() error {
|
||||
}
|
||||
|
||||
func GetTrackers() []string {
|
||||
urls, err := auth.GetServiceURLs(TORRENT_TRACKER_SERVICE, options.Options.Region, "", "")
|
||||
urls, err := auth.GetServiceURLs(TORRENT_TRACKER_SERVICE, options.Options.Region, "", "", httputils.POST)
|
||||
if err != nil {
|
||||
log.Errorf("fail to get torrent-tracker")
|
||||
return nil
|
||||
@@ -98,7 +99,7 @@ func SeedTorrent(torrentpath string, imageId, format string) error {
|
||||
}
|
||||
|
||||
func seedTorrent(torrentpath string, imageId, format string) error {
|
||||
url, err := auth.GetServiceURL("image", options.Options.Region, "", identity_apis.EndpointInterfacePublic)
|
||||
url, err := auth.GetServiceURL("image", options.Options.Region, "", identity_apis.EndpointInterfacePublic, httputils.POST)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -269,15 +269,15 @@ func (ep *SEndpoint) getService() *SService {
|
||||
}
|
||||
|
||||
type SEndpointExtended struct {
|
||||
Id string
|
||||
Name string
|
||||
Interface string
|
||||
Url string
|
||||
Region string
|
||||
RegionId string
|
||||
ServiceId string
|
||||
ServiceType string
|
||||
ServiceName string
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Interface string `json:"interface"`
|
||||
Url string `json:"url"`
|
||||
Region string `json:"region"`
|
||||
RegionId string `json:"region_id"`
|
||||
ServiceId string `json:"service_id"`
|
||||
ServiceType string `json:"service_type"`
|
||||
ServiceName string `json:"service_name"`
|
||||
}
|
||||
|
||||
type SServiceCatalog []SEndpointExtended
|
||||
@@ -493,7 +493,8 @@ func (manager *SEndpointManager) ValidateCreateData(
|
||||
}
|
||||
service := servObj.(*SService)
|
||||
if !data.Contains("name") {
|
||||
data.Set("name", jsonutils.NewString(fmt.Sprintf("%s-%s", service.Type, infname)))
|
||||
nameStr := fmt.Sprintf("%s-%s", service.Type, infname)
|
||||
data.Set("name", jsonutils.NewString(nameStr))
|
||||
}
|
||||
data.Set("service_id", jsonutils.NewString(service.Id))
|
||||
} else {
|
||||
@@ -550,10 +551,7 @@ func (manager *SEndpointManager) ListItemFilter(
|
||||
}
|
||||
}
|
||||
if len(query.Interface) > 0 {
|
||||
infType := query.Interface
|
||||
if strings.HasSuffix(infType, "URL") {
|
||||
infType = infType[0 : len(infType)-3]
|
||||
}
|
||||
infType := strings.TrimSuffix(query.Interface, "URL")
|
||||
q = q.Equals("interface", infType)
|
||||
}
|
||||
return q, nil
|
||||
|
||||
@@ -32,18 +32,18 @@ const (
|
||||
API_VERSION = "v3"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
// add version handler with API_VERSION prefix
|
||||
app.AddDefaultHandler("GET", API_VERSION+"/version", appsrv.VersionHandler, "version")
|
||||
cronjobs.AddRefreshHandler(API_VERSION, app)
|
||||
|
||||
quotas.AddQuotaHandler(&models.IdentityQuotaManager.SQuotaBaseManager, API_VERSION, app)
|
||||
quotas.AddQuotaHandler(&models.IdentityQuotaManager.SQuotaBaseManager, API_VERSION, app, isSlave)
|
||||
|
||||
usages.AddUsageHandler(API_VERSION, app)
|
||||
|
||||
taskman.AddTaskHandler(API_VERSION, app)
|
||||
taskman.AddTaskHandler(API_VERSION, app, isSlave)
|
||||
|
||||
app_common.ExportOptionsHandlerWithPrefix(app, API_VERSION, &options.Options)
|
||||
|
||||
@@ -108,7 +108,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher(API_VERSION, app, handler)
|
||||
dispatcher.AddModelDispatcher(API_VERSION, app, handler, isSlave)
|
||||
}
|
||||
|
||||
models.AddAdhocHandlers(API_VERSION, app)
|
||||
|
||||
@@ -86,7 +86,7 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(&opts.DBOptions)
|
||||
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, &opts.DBOptions, models.InitDB)
|
||||
|
||||
@@ -94,7 +94,7 @@ func StartService() {
|
||||
|
||||
common_options.StartOptionManagerWithSessionDriver(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, "", options.OnOptionsChange, models.NewServiceConfigSession())
|
||||
|
||||
{
|
||||
if !opts.IsSlaveNode {
|
||||
err := models.UserManager.EnforceUserMfa(context.Background())
|
||||
if err != nil {
|
||||
log.Errorf("EnforceUserMfa fail %s", err)
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/llm/models"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
db.RegistUserCredCacheUpdater()
|
||||
|
||||
taskman.AddTaskHandler("", app)
|
||||
taskman.AddTaskHandler("", app, isSlave)
|
||||
|
||||
for _, manager := range []db.IModelManager{
|
||||
taskman.TaskManager,
|
||||
@@ -44,6 +44,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func StartService() {
|
||||
app := app_common.InitApp(&opts.BaseOptions, false)
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/logger/options"
|
||||
)
|
||||
|
||||
func initHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
models.InitActionLog()
|
||||
@@ -48,6 +48,6 @@ func initHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
initHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
@@ -298,16 +298,16 @@ func (a *authManager) reAuth() {
|
||||
a.SyncOnce(false, false)
|
||||
}
|
||||
|
||||
func (a *authManager) GetServiceURL(service, region, zone, endpointType string) (string, error) {
|
||||
return a.getAdminSession(context.Background(), region, zone, endpointType).GetServiceURL(service, endpointType)
|
||||
func (a *authManager) GetServiceURL(service, region, zone, endpointType string, method httputils.THttpMethod) (string, error) {
|
||||
return a.getAdminSession(context.Background(), region, zone, endpointType).GetServiceURL(service, endpointType, method)
|
||||
}
|
||||
|
||||
func (a *authManager) GetServiceURLs(service, region, zone, endpointType string) ([]string, error) {
|
||||
return a.getAdminSession(context.Background(), region, zone, endpointType).GetServiceURLs(service, endpointType)
|
||||
func (a *authManager) GetServiceURLs(service, region, zone, endpointType string, method httputils.THttpMethod) ([]string, error) {
|
||||
return a.getAdminSession(context.Background(), region, zone, endpointType).GetServiceURLs(service, endpointType, method)
|
||||
}
|
||||
|
||||
func (a *authManager) getServiceIPs(service, region, zone, endpointType string, needResolve bool) ([]string, error) {
|
||||
urls, err := a.GetServiceURLs(service, region, zone, endpointType)
|
||||
urls, err := a.GetServiceURLs(service, region, zone, endpointType, httputils.POST)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetServiceURLs")
|
||||
}
|
||||
@@ -384,16 +384,16 @@ func VerifyRequest(req http.Request, virtualHost bool) (mcclient.TokenCredential
|
||||
return manager.verifyRequest(req, virtualHost)
|
||||
}
|
||||
|
||||
func GetServiceURL(service, region, zone, endpointType string) (string, error) {
|
||||
return manager.GetServiceURL(service, region, zone, endpointType)
|
||||
func GetServiceURL(service, region, zone, endpointType string, method httputils.THttpMethod) (string, error) {
|
||||
return manager.GetServiceURL(service, region, zone, endpointType, method)
|
||||
}
|
||||
|
||||
func GetPublicServiceURL(service, region, zone string) (string, error) {
|
||||
return manager.GetServiceURL(service, region, zone, identity.EndpointInterfacePublic)
|
||||
func GetPublicServiceURL(service, region, zone string, method httputils.THttpMethod) (string, error) {
|
||||
return manager.GetServiceURL(service, region, zone, identity.EndpointInterfacePublic, method)
|
||||
}
|
||||
|
||||
func GetServiceURLs(service, region, zone, endpointType string) ([]string, error) {
|
||||
return manager.GetServiceURLs(service, region, zone, endpointType)
|
||||
func GetServiceURLs(service, region, zone, endpointType string, method httputils.THttpMethod) ([]string, error) {
|
||||
return manager.GetServiceURLs(service, region, zone, endpointType, method)
|
||||
}
|
||||
|
||||
func GetDNSServers(region, zone string) ([]string, error) {
|
||||
|
||||
@@ -128,9 +128,9 @@ func (this *BaseManager) rawRequest(session *mcclient.ClientSession,
|
||||
header, body)
|
||||
}
|
||||
|
||||
func (this *BaseManager) GetBaseUrl(s *mcclient.ClientSession) (string, error) {
|
||||
/*func (this *BaseManager) GetBaseUrl(s *mcclient.ClientSession) (string, error) {
|
||||
return s.GetBaseUrl(this.serviceType, this.endpointType)
|
||||
}
|
||||
}*/
|
||||
|
||||
func (this *BaseManager) rawBaseUrlRequest(s *mcclient.ClientSession,
|
||||
method httputils.THttpMethod, path string,
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/printutils"
|
||||
"yunion.io/x/pkg/util/sets"
|
||||
|
||||
@@ -301,7 +302,7 @@ func _getModule(session *mcclient.ClientSession, name string) (IBaseManager, err
|
||||
}
|
||||
|
||||
for _, mod := range mods {
|
||||
url, e := session.GetServiceURL(mod.ServiceType(), mod.EndpointType())
|
||||
url, e := session.GetServiceURL(mod.ServiceType(), mod.EndpointType(), httputils.POST)
|
||||
if e != nil {
|
||||
return nil, errors.Wrap(e, "session.GetServiceURL")
|
||||
}
|
||||
@@ -352,7 +353,7 @@ func GetJointModule2(session *mcclient.ClientSession, mod1 Manager, mod2 Manager
|
||||
continue
|
||||
}
|
||||
for _, mod := range mods {
|
||||
url, e := session.GetServiceVersionURL(mod.ServiceType(), mod.EndpointType())
|
||||
url, e := session.GetServiceVersionURL(mod.ServiceType(), mod.EndpointType(), httputils.POST)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/printutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
@@ -96,7 +97,7 @@ func (this *MetadataManager) getModule(session *mcclient.ClientSession, params j
|
||||
}
|
||||
}
|
||||
|
||||
_, err := session.GetServiceURL(service, "")
|
||||
_, err := session.GetServiceURL(service, "", httputils.POST)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewNotFoundError("service %s not found error: %v", service, err)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func (self *SkusManager) GetSkus(s *mcclient.ClientSession, providerId, regionId
|
||||
}
|
||||
|
||||
func (self *OfflineCloudmetaManager) GetSkuSourcesMeta(s *mcclient.ClientSession, client *http.Client) (jsonutils.JSONObject, error) {
|
||||
baseUrl, err := s.GetServiceVersionURL(self.ServiceType(), self.EndpointType())
|
||||
baseUrl, err := s.GetServiceVersionURL(self.ServiceType(), self.EndpointType(), httputils.GET)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
|
||||
compute_api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
webconsole_api "yunion.io/x/onecloud/pkg/apis/webconsole"
|
||||
@@ -198,7 +199,7 @@ func (m WebConsoleManager) doActionWithClimcPod(
|
||||
|
||||
func (m WebConsoleManager) doCloudShell(s *mcclient.ClientSession, info *webconsole_api.SK8sShellDisplayInfo, cmd string, args ...string) (jsonutils.JSONObject, error) {
|
||||
endpointType := "internal"
|
||||
authUrl, err := s.GetServiceURL("identity", endpointType)
|
||||
authUrl, err := s.GetServiceURL("identity", endpointType, httputils.POST)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewNotFoundError("auth_url not found")
|
||||
}
|
||||
|
||||
@@ -129,8 +129,8 @@ func (cliss *ClientSession) GetServiceName(service string) string {
|
||||
return service
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) GetServiceURL(service, endpointType string) (string, error) {
|
||||
return cliss.GetServiceVersionURL(service, endpointType)
|
||||
func (cliss *ClientSession) GetServiceURL(service, endpointType string, method httputils.THttpMethod) (string, error) {
|
||||
return cliss.GetServiceVersionURL(service, endpointType, method)
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) SetServiceCatalog(catalog IServiceCatalog) {
|
||||
@@ -144,33 +144,43 @@ func (cliss *ClientSession) GetServiceCatalog() IServiceCatalog {
|
||||
return cliss.client.GetServiceCatalog()
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) GetServiceVersionURL(service, endpointType string) (string, error) {
|
||||
urls, err := cliss.GetServiceVersionURLs(service, endpointType)
|
||||
func (cliss *ClientSession) GetServiceVersionURL(service, endpointType string, method httputils.THttpMethod) (string, error) {
|
||||
urls, err := cliss.GetServiceVersionURLs(service, endpointType, method)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "GetServiceVersionURLs")
|
||||
}
|
||||
return urls[rand.Intn(len(urls))], nil
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) GetServiceURLs(service, endpointType string) ([]string, error) {
|
||||
return cliss.GetServiceVersionURLs(service, endpointType)
|
||||
func (cliss *ClientSession) GetServiceURLs(service, endpointType string, method httputils.THttpMethod) ([]string, error) {
|
||||
return cliss.GetServiceVersionURLs(service, endpointType, method)
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) GetServiceVersionURLs(service, endpointType string) ([]string, error) {
|
||||
func (cliss *ClientSession) GetServiceVersionURLs(service, endpointType string, method httputils.THttpMethod) ([]string, error) {
|
||||
return cliss.GetServiceVersionURLsByMethod(service, endpointType, method)
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) GetServiceVersionURLsByMethod(service, endpointType string, method httputils.THttpMethod) ([]string, error) {
|
||||
if len(cliss.endpointType) > 0 {
|
||||
// session specific endpoint type should override the input endpointType, which is supplied by manager
|
||||
endpointType = cliss.endpointType
|
||||
}
|
||||
service = cliss.GetServiceName(service)
|
||||
if endpointType == api.EndpointInterfaceApigateway {
|
||||
return cliss.getApigatewayServiceURLs(service, cliss.region, cliss.zone, endpointType)
|
||||
return cliss.getApigatewayServiceURLs(service, cliss.region, cliss.zone)
|
||||
} else {
|
||||
if (endpointType == "" || endpointType == api.EndpointInterfaceInternal) && (method == httputils.GET || method == httputils.HEAD) {
|
||||
urls, _ := cliss.getServiceVersionURLs(service, cliss.region, cliss.zone, api.EndpointInterfaceSlave)
|
||||
if len(urls) > 0 {
|
||||
return urls, nil
|
||||
}
|
||||
}
|
||||
return cliss.getServiceVersionURLs(service, cliss.region, cliss.zone, endpointType)
|
||||
}
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) getApigatewayServiceURLs(service, region, zone, endpointType string) ([]string, error) {
|
||||
urls, err := cliss.getServiceVersionURLs(service, region, zone, "")
|
||||
func (cliss *ClientSession) getApigatewayServiceURLs(service, region, zone string) ([]string, error) {
|
||||
urls, err := cliss.getServiceVersionURLs(service, region, zone, api.EndpointInterfaceInternal)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getServiceVersionURLs")
|
||||
}
|
||||
@@ -231,14 +241,14 @@ func (cliss *ClientSession) getServiceVersionURLs(service, region, zone, endpoin
|
||||
return urls, err
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) GetBaseUrl(service, endpointType string) (string, error) {
|
||||
func (cliss *ClientSession) GetBaseUrl(service, endpointType string, method httputils.THttpMethod) (string, error) {
|
||||
if len(service) > 0 {
|
||||
if strings.HasPrefix(service, "http://") || strings.HasPrefix(service, "https://") {
|
||||
return service, nil
|
||||
} else if url, ok := cliss.customizeServiceUrl[service]; ok {
|
||||
return url, nil
|
||||
} else {
|
||||
return cliss.GetServiceVersionURL(service, endpointType)
|
||||
return cliss.GetServiceVersionURL(service, endpointType, method)
|
||||
}
|
||||
} else {
|
||||
return "", fmt.Errorf("Empty service type or baseURL")
|
||||
@@ -251,7 +261,7 @@ func (cliss *ClientSession) RawBaseUrlRequest(
|
||||
headers http.Header, body io.Reader,
|
||||
baseurlFactory func(string) string,
|
||||
) (*http.Response, error) {
|
||||
baseurl, err := cliss.GetBaseUrl(service, endpointType)
|
||||
baseurl, err := cliss.GetBaseUrl(service, endpointType, method)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -288,7 +298,7 @@ func (cliss *ClientSession) JSONVersionRequest(
|
||||
service, endpointType string, method httputils.THttpMethod, url string,
|
||||
headers http.Header, body jsonutils.JSONObject,
|
||||
) (http.Header, jsonutils.JSONObject, error) {
|
||||
baseUrl, err := cliss.GetBaseUrl(service, endpointType)
|
||||
baseUrl, err := cliss.GetBaseUrl(service, endpointType, method)
|
||||
if err != nil {
|
||||
return headers, nil, err
|
||||
}
|
||||
@@ -372,7 +382,7 @@ func (cliss *ClientSession) SetServiceUrl(service, url string) {
|
||||
}
|
||||
|
||||
func (cliss *ClientSession) WithTaskCallback(taskId string, req func() error) error {
|
||||
baseUrl, err := cliss.GetBaseUrl(consts.GetServiceType(), api.EndpointInterfacePublic)
|
||||
baseUrl, err := cliss.GetBaseUrl(consts.GetServiceType(), api.EndpointInterfacePublic, httputils.POST)
|
||||
if err != nil {
|
||||
log.Errorf("GetServiceURLs error: %s", err)
|
||||
return errors.Wrap(err, "GetServiceURLs")
|
||||
|
||||
@@ -23,19 +23,19 @@ import (
|
||||
)
|
||||
|
||||
type ExternalService struct {
|
||||
Name string
|
||||
Url string
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
|
||||
Service string
|
||||
Service string `json:"service"`
|
||||
}
|
||||
|
||||
type Endpoint struct {
|
||||
Id string
|
||||
RegionId string
|
||||
ServiceId string
|
||||
ServiceName string
|
||||
Url string
|
||||
Interface string
|
||||
Id string `json:"id"`
|
||||
RegionId string `json:"region_id"`
|
||||
ServiceId string `json:"service_id"`
|
||||
ServiceName string `json:"service_name"`
|
||||
Url string `json:"url"`
|
||||
Interface string `json:"interface"`
|
||||
}
|
||||
|
||||
func OwnerIdString(owner IIdentityProvider, scope rbacscope.TRbacScope) string {
|
||||
|
||||
@@ -42,6 +42,7 @@ type KeystoneEndpointV3 struct {
|
||||
// | public | 外部接口 |
|
||||
// | admin | 管理类型接口,deprecated |
|
||||
// | console | web控制台接口,指定显示在web控制台的外部服务的接口地址 |
|
||||
// | slave | 从节点接口,用于读取数据 |
|
||||
//
|
||||
Interface string `json:"interface"`
|
||||
// 区域名称
|
||||
@@ -360,12 +361,12 @@ func (catalog KeystoneServiceCatalogV3) getEndpoints(region string, endpointType
|
||||
endpoint := catalog[i].Endpoints[j]
|
||||
if (endpoint.RegionId == region || strings.HasPrefix(endpoint.RegionId, region+"-")) && endpoint.Interface == endpointType {
|
||||
endpoints = append(endpoints, Endpoint{
|
||||
endpoint.Id,
|
||||
endpoint.RegionId,
|
||||
catalog[i].Id,
|
||||
catalog[i].Name,
|
||||
endpoint.Url,
|
||||
endpoint.Interface,
|
||||
Id: endpoint.Id,
|
||||
RegionId: endpoint.RegionId,
|
||||
ServiceId: catalog[i].Id,
|
||||
ServiceName: catalog[i].Name,
|
||||
Url: endpoint.Url,
|
||||
Interface: endpoint.Interface,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -405,14 +406,14 @@ func (catalog KeystoneServiceCatalogV3) getServiceURL(service, region, zone, end
|
||||
|
||||
func (catalog KeystoneServiceCatalogV3) getServiceURLs(service, region, zone, endpointType string) ([]string, error) {
|
||||
if endpointType == "" {
|
||||
endpointType = "internalURL"
|
||||
endpointType = "internal"
|
||||
}
|
||||
const MAX_ENDPOINTS = 4
|
||||
for i := 0; i < len(catalog); i++ {
|
||||
if service == catalog[i].Type {
|
||||
if len(catalog[i].Endpoints) == 0 {
|
||||
continue
|
||||
}
|
||||
var selected []string
|
||||
regeps := make(map[string][]string)
|
||||
regionzone := ""
|
||||
if len(zone) > 0 {
|
||||
@@ -426,32 +427,33 @@ func (catalog KeystoneServiceCatalogV3) getServiceURLs(service, region, zone, en
|
||||
len(region) == 0) {
|
||||
_, ok := regeps[ep.RegionId]
|
||||
if !ok {
|
||||
regeps[ep.RegionId] = make([]string, 0)
|
||||
regeps[ep.RegionId] = make([]string, 0, MAX_ENDPOINTS)
|
||||
}
|
||||
regeps[ep.RegionId] = append(regeps[ep.RegionId], ep.Url)
|
||||
}
|
||||
}
|
||||
if len(region) == 0 {
|
||||
if len(regeps) >= 1 {
|
||||
for _, v := range regeps {
|
||||
selected = v
|
||||
break
|
||||
for k := range regeps {
|
||||
return regeps[k], nil
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("No default region for region(%s) zone(%s)", region, zone)
|
||||
}
|
||||
} else {
|
||||
var selected []string
|
||||
_, ok := regeps[regionzone]
|
||||
if ok {
|
||||
selected = regeps[regionzone]
|
||||
} else if _, ok := regeps[region]; ok {
|
||||
selected = regeps[region]
|
||||
}
|
||||
if len(selected) == 0 {
|
||||
return nil, fmt.Errorf("No valid %s endpoints for %s in region %s", endpointType, service, RegionID(region, zone))
|
||||
} else {
|
||||
selected, ok = regeps[region]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("No valid %s endpoints for %s in region %s", endpointType, service, RegionID(region, zone))
|
||||
}
|
||||
return selected, nil
|
||||
}
|
||||
}
|
||||
return selected, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(httperrors.ErrNotFound, "No such service %s", service)
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/stringutils"
|
||||
"yunion.io/x/pkg/util/wait"
|
||||
|
||||
@@ -153,7 +154,7 @@ func (man *dataSourceManager) initDefaultDataSource(ctx context.Context) error {
|
||||
if err := tsdb.IsValidDataSource(dsSvc); err != nil {
|
||||
return errors.Wrapf(err, "invalid type %q", dsSvc)
|
||||
}
|
||||
url, err := s.GetServiceURL(dsSvc, epType)
|
||||
url, err := s.GetServiceURL(dsSvc, epType, httputils.POST)
|
||||
if err != nil {
|
||||
return errors.Errorf("get %q public url: %v", dsSvc, err)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/monitor/options"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
db.RegisterModelManager(db.TenantCacheManager)
|
||||
@@ -41,7 +41,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
db.RegisterModelManager(db.RoleCacheManager)
|
||||
db.RegistUserCredCacheUpdater()
|
||||
|
||||
taskman.AddTaskHandler("", app)
|
||||
taskman.AddTaskHandler("", app, isSlave)
|
||||
|
||||
for _, manager := range []db.IModelManager{
|
||||
taskman.TaskManager,
|
||||
@@ -73,14 +73,14 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
|
||||
for _, manager := range []db.IModelManager{
|
||||
models.UnifiedMonitorManager,
|
||||
} {
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
|
||||
for _, manager := range []db.IJointModelManager{
|
||||
@@ -92,7 +92,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewJointModelHandler(manager)
|
||||
dispatcher.AddJointModelDispatcher("", app, handler)
|
||||
dispatcher.AddJointModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,14 +70,14 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
go startServices()
|
||||
|
||||
if !opts.IsSlaveNode {
|
||||
go startServices()
|
||||
|
||||
err := taskman.TaskManager.InitializeData()
|
||||
if err != nil {
|
||||
log.Fatalf("TaskManager.InitializeData fail %s", err)
|
||||
|
||||
@@ -27,7 +27,7 @@ const (
|
||||
API_VERSION = "v2"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
models.InitEventLog()
|
||||
@@ -35,7 +35,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
|
||||
db.RegistUserCredCacheUpdater()
|
||||
|
||||
taskman.AddTaskHandler(API_VERSION, app)
|
||||
taskman.AddTaskHandler(API_VERSION, app, isSlave)
|
||||
|
||||
db.AddScopeResourceCountHandler(API_VERSION, app)
|
||||
|
||||
@@ -74,7 +74,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher(API_VERSION, app, handler)
|
||||
dispatcher.AddModelDispatcher(API_VERSION, app, handler, isSlave)
|
||||
}
|
||||
for _, manager := range []db.IJointModelManager{
|
||||
models.SubscriberReceiverManager,
|
||||
@@ -86,6 +86,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewJointModelHandler(manager)
|
||||
dispatcher.AddJointModelDispatcher(API_VERSION, app, handler)
|
||||
dispatcher.AddJointModelDispatcher(API_VERSION, app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,20 +57,20 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(applicaion)
|
||||
InitHandlers(applicaion, opts.IsSlaveNode)
|
||||
|
||||
// init database
|
||||
db.EnsureAppSyncDB(applicaion, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
if options.Options.EnableWatchUser {
|
||||
err := models.ReceiverManager.StartWatchUserInKeystone()
|
||||
if err != nil {
|
||||
log.Errorln(errors.Wrap(err, "StartWatchUserInKeystone"))
|
||||
}
|
||||
}
|
||||
|
||||
if !opts.IsSlaveNode {
|
||||
if options.Options.EnableWatchUser {
|
||||
err := models.ReceiverManager.StartWatchUserInKeystone()
|
||||
if err != nil {
|
||||
log.Errorln(errors.Wrap(err, "StartWatchUserInKeystone"))
|
||||
}
|
||||
}
|
||||
|
||||
err := taskman.TaskManager.InitializeData()
|
||||
if err != nil {
|
||||
log.Fatalf("TaskManager.InitializeData fail %s", err)
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/scheduledtask/models"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
db.RegistUserCredCacheUpdater()
|
||||
db.AddScopeResourceCountHandler("", app)
|
||||
@@ -42,6 +42,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,15 +46,18 @@ func StartService() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
InitHandlers(applicaion)
|
||||
InitHandlers(applicaion, opts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(applicaion, dbOpts, nil)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
cron := cronman.InitCronJobManager(true, 4, opts.TimeZone)
|
||||
cron.AddJobAtIntervalsWithStartRun("ScheduledTaskCheck", time.Duration(60)*time.Second, models.ScheduledTaskManager.Timer, true)
|
||||
cron.AddJobEveryFewHour("AutoPurgeSplitable", 4, 30, 0, db.AutoPurgeSplitable, false)
|
||||
if !opts.IsSlaveNode {
|
||||
cron := cronman.InitCronJobManager(true, 4, opts.TimeZone)
|
||||
cron.AddJobAtIntervalsWithStartRun("ScheduledTaskCheck", time.Duration(60)*time.Second, models.ScheduledTaskManager.Timer, true)
|
||||
cron.AddJobEveryFewHour("AutoPurgeSplitable", 4, 30, 0, db.AutoPurgeSplitable, false)
|
||||
|
||||
go cron.Start()
|
||||
}
|
||||
|
||||
go cron.Start()
|
||||
app.ServeForever(applicaion, baseOpts)
|
||||
}
|
||||
|
||||
@@ -59,25 +59,28 @@ const (
|
||||
WebsocketProxyPathPrefix = "/wsproxy/"
|
||||
)
|
||||
|
||||
func initHandlers(app *appsrv.Application) {
|
||||
app.AddHandler("POST", ApiPathPrefix+"k8s/<podName>/shell", auth.Authenticate(handleK8sShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"climc/shell", auth.Authenticate(handleClimcShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"k8s/<podName>/log", auth.Authenticate(handleK8sLog))
|
||||
app.AddHandler("POST", ApiPathPrefix+"baremetal/<id>", auth.Authenticate(handleBaremetalShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"ssh/<ip>", auth.Authenticate(handleSshShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"server/<id>", auth.Authenticate(handleServerRemoteConsole))
|
||||
app.AddHandler("POST", ApiPathPrefix+"adb/<id>/shell", auth.Authenticate(handleAdbShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"server-rdp/<id>", auth.Authenticate(handleServerRemoteRDPConsole))
|
||||
func initHandlers(app *appsrv.Application, isSlave bool) {
|
||||
app.AddHandler("GET", ApiPathPrefix+"sftp/<session-id>/list", server.HandleSftpList)
|
||||
app.AddHandler("GET", ApiPathPrefix+"sftp/<session-id>/download", server.HandleSftpDownload)
|
||||
app.AddHandler("POST", ApiPathPrefix+"sftp/<session-id>/upload", server.HandleSftpUpload)
|
||||
|
||||
if !isSlave {
|
||||
app.AddHandler("POST", ApiPathPrefix+"k8s/<podName>/shell", auth.Authenticate(handleK8sShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"climc/shell", auth.Authenticate(handleClimcShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"k8s/<podName>/log", auth.Authenticate(handleK8sLog))
|
||||
app.AddHandler("POST", ApiPathPrefix+"baremetal/<id>", auth.Authenticate(handleBaremetalShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"ssh/<ip>", auth.Authenticate(handleSshShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"server/<id>", auth.Authenticate(handleServerRemoteConsole))
|
||||
app.AddHandler("POST", ApiPathPrefix+"adb/<id>/shell", auth.Authenticate(handleAdbShell))
|
||||
app.AddHandler("POST", ApiPathPrefix+"server-rdp/<id>", auth.Authenticate(handleServerRemoteRDPConsole))
|
||||
app.AddHandler("POST", ApiPathPrefix+"sftp/<session-id>/upload", server.HandleSftpUpload)
|
||||
}
|
||||
|
||||
for _, man := range []db.IModelManager{
|
||||
models.GetCommandLogManager(),
|
||||
} {
|
||||
db.RegisterModelManager(man)
|
||||
handler := db.NewModelHandler(man)
|
||||
dispatcher.AddModelDispatcher(ApiPathPrefix, app, handler)
|
||||
dispatcher.AddModelDispatcher(ApiPathPrefix, app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ func start() {
|
||||
|
||||
cloudcommon.InitDB(dbOpts)
|
||||
|
||||
initHandlers(app)
|
||||
initHandlers(app, baseOpts.IsSlaveNode)
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
|
||||
@@ -100,12 +100,14 @@ func start() {
|
||||
// misc handler
|
||||
appsrv.AddMiscHandlersToMuxRouter(app, root, o.Options.EnableAppProfiling)
|
||||
|
||||
cron := cronman.InitCronJobManager(true, o.Options.CronJobWorkerCount, o.Options.TimeZone)
|
||||
if !baseOpts.IsSlaveNode {
|
||||
cron := cronman.InitCronJobManager(true, o.Options.CronJobWorkerCount, o.Options.TimeZone)
|
||||
|
||||
cron.AddJobEveryFewHour("AutoPurgeSplitable", 4, 30, 0, db.AutoPurgeSplitable, false)
|
||||
cron.AddJobEveryFewHour("AutoPurgeSplitable", 4, 30, 0, db.AutoPurgeSplitable, false)
|
||||
|
||||
cron.Start()
|
||||
defer cron.Stop()
|
||||
cron.Start()
|
||||
defer cron.Stop()
|
||||
}
|
||||
|
||||
addr := net.JoinHostPort(o.Options.Address, strconv.Itoa(o.Options.Port))
|
||||
log.Infof("Start listen on %s", addr)
|
||||
|
||||
@@ -32,11 +32,11 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/yunionconf/models"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
func InitHandlers(app *appsrv.Application, isSlave bool) {
|
||||
db.InitAllManagers()
|
||||
|
||||
db.AddScopeResourceCountHandler("", app)
|
||||
addBugReportHandler("", app)
|
||||
addBugReportHandler("", app, isSlave)
|
||||
|
||||
for _, manager := range []db.IModelManager{
|
||||
db.UserCacheManager,
|
||||
@@ -55,16 +55,19 @@ func InitHandlers(app *appsrv.Application) {
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
dispatcher.AddModelDispatcher("", app, handler)
|
||||
dispatcher.AddModelDispatcher("", app, handler, isSlave)
|
||||
if manager == models.ParameterManager {
|
||||
dispatcher.AddModelDispatcher("/users/<user_id>", app, handler)
|
||||
dispatcher.AddModelDispatcher("/services/<service_id>", app, handler)
|
||||
dispatcher.AddModelDispatcher("/users/<user_id>", app, handler, isSlave)
|
||||
dispatcher.AddModelDispatcher("/services/<service_id>", app, handler, isSlave)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addBugReportHandler(prefix string, app *appsrv.Application) {
|
||||
func addBugReportHandler(prefix string, app *appsrv.Application, isSlave bool) {
|
||||
app.AddHandler("GET", fmt.Sprintf("%s/bug-report-status", prefix), bugReportStatusHandler)
|
||||
if isSlave {
|
||||
return
|
||||
}
|
||||
app.AddHandler("POST", fmt.Sprintf("%s/enable-bug-report", prefix), enableBugReportHandler)
|
||||
app.AddHandler("POST", fmt.Sprintf("%s/disable-bug-report", prefix), disableBugReportHandler)
|
||||
app.AddHandler("POST", fmt.Sprintf("%s/send-bug-report", prefix), sendBugReportHandler)
|
||||
|
||||
@@ -55,7 +55,7 @@ func StartService() {
|
||||
session := auth.GetAdminSession(ctx, baseOpts.Region)
|
||||
notifyclient.EventNotifyServiceAbnormal(ctx, session.GetToken(), consts.GetServiceType(), method, path, body, err)
|
||||
})
|
||||
InitHandlers(app)
|
||||
InitHandlers(app, opts.IsSlaveNode)
|
||||
db.AppDBInit(app)
|
||||
|
||||
if db.CheckSync(opts.AutoSyncTable, opts.EnableDBChecksumTables, opts.DBChecksumSkipInit) {
|
||||
|
||||
Reference in New Issue
Block a user