handlers.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package service
  15. import (
  16. "yunion.io/x/onecloud/pkg/appsrv"
  17. "yunion.io/x/onecloud/pkg/appsrv/dispatcher"
  18. app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
  19. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  20. "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
  21. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  22. "yunion.io/x/onecloud/pkg/image/models"
  23. "yunion.io/x/onecloud/pkg/image/options"
  24. "yunion.io/x/onecloud/pkg/image/usages"
  25. )
  26. const (
  27. API_VERSION = "v1"
  28. )
  29. func InitHandlers(app *appsrv.Application, isSlave bool) {
  30. db.InitAllManagers()
  31. // add version handler with API_VERSION prefix
  32. app.AddDefaultHandler("GET", API_VERSION+"/version", appsrv.VersionHandler, "version")
  33. db.RegistUserCredCacheUpdater()
  34. db.AddScopeResourceCountHandler(API_VERSION, app)
  35. quotas.AddQuotaHandler(&models.QuotaManager.SQuotaBaseManager, API_VERSION, app, isSlave)
  36. usages.AddUsageHandler(API_VERSION, app)
  37. taskman.AddTaskHandler(API_VERSION, app, isSlave)
  38. app_common.ExportOptionsHandler(app, &options.Options)
  39. for _, manager := range []db.IModelManager{
  40. taskman.TaskManager,
  41. taskman.SubTaskManager,
  42. taskman.TaskObjectManager,
  43. taskman.ArchivedTaskManager,
  44. db.UserCacheManager,
  45. db.TenantCacheManager,
  46. db.SharedResourceManager,
  47. models.ImageTagManager,
  48. models.ImageMemberManager,
  49. models.ImagePropertyManager,
  50. models.ImageSubformatManager,
  51. models.GuestImageJointManager,
  52. models.QuotaManager,
  53. models.QuotaUsageManager,
  54. models.QuotaPendingUsageManager,
  55. } {
  56. db.RegisterModelManager(manager)
  57. }
  58. for _, manager := range []db.IModelManager{
  59. db.OpsLog,
  60. db.Metadata,
  61. models.ImageManager,
  62. models.GuestImageManager,
  63. } {
  64. db.RegisterModelManager(manager)
  65. handler := db.NewModelHandler(manager)
  66. dispatcher.AddModelDispatcher(API_VERSION, app, handler, isSlave)
  67. }
  68. }