handlers.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  19. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  20. "yunion.io/x/onecloud/pkg/notify/models"
  21. _ "yunion.io/x/onecloud/pkg/notify/sender"
  22. )
  23. const (
  24. API_VERSION = "v2"
  25. )
  26. func InitHandlers(app *appsrv.Application, isSlave bool) {
  27. db.InitAllManagers()
  28. models.InitEventLog()
  29. models.InitEmailQueue()
  30. db.RegistUserCredCacheUpdater()
  31. taskman.AddTaskHandler(API_VERSION, app, isSlave)
  32. db.AddScopeResourceCountHandler(API_VERSION, app)
  33. for _, manager := range []db.IModelManager{
  34. taskman.TaskManager,
  35. taskman.SubTaskManager,
  36. taskman.TaskObjectManager,
  37. taskman.ArchivedTaskManager,
  38. db.UserCacheManager,
  39. db.TenantCacheManager,
  40. db.RoleCacheManager,
  41. models.SubContactManager,
  42. db.SharedResourceManager,
  43. models.VerificationManager,
  44. models.EventManager,
  45. models.EmailQueueStatusManager,
  46. models.TopicActionManager,
  47. models.TopicResourceManager,
  48. } {
  49. db.RegisterModelManager(manager)
  50. }
  51. for _, manager := range []db.IModelManager{
  52. db.OpsLog,
  53. db.Metadata,
  54. models.ReceiverManager,
  55. models.NotificationManager,
  56. models.ConfigManager,
  57. models.TemplateManager,
  58. models.TopicManager,
  59. models.RobotManager,
  60. models.SubscriberManager,
  61. models.EmailQueueManager,
  62. models.NotificationGroupManager,
  63. } {
  64. db.RegisterModelManager(manager)
  65. handler := db.NewModelHandler(manager)
  66. dispatcher.AddModelDispatcher(API_VERSION, app, handler, isSlave)
  67. }
  68. for _, manager := range []db.IJointModelManager{
  69. models.SubscriberReceiverManager,
  70. } {
  71. db.RegisterModelManager(manager)
  72. }
  73. for _, manager := range []db.IJointModelManager{
  74. models.ReceiverNotificationManager,
  75. } {
  76. db.RegisterModelManager(manager)
  77. handler := db.NewJointModelHandler(manager)
  78. dispatcher.AddJointModelDispatcher(API_VERSION, app, handler, isSlave)
  79. }
  80. }