initdb.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 models
  15. import (
  16. "time"
  17. "yunion.io/x/log"
  18. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  19. "yunion.io/x/onecloud/pkg/cloudcommon/db/proxy"
  20. "yunion.io/x/onecloud/pkg/compute/models/baremetal"
  21. )
  22. func InitDB() error {
  23. for _, manager := range []db.IModelManager{
  24. /*
  25. * Important!!!
  26. * initialization order matters, do not change the order
  27. */
  28. db.TenantCacheManager,
  29. db.Metadata,
  30. proxy.ProxySettingManager,
  31. QuotaManager,
  32. CloudaccountManager,
  33. CloudproviderManager,
  34. CloudregionManager,
  35. ZoneManager,
  36. VpcManager,
  37. WireManager,
  38. StorageManager,
  39. SecurityGroupManager,
  40. NetworkManager,
  41. NetworkAddressManager,
  42. NetworkIpMacManager,
  43. GuestManager,
  44. GuestnetworkManager,
  45. HostManager,
  46. HostDmesgLogManager,
  47. LoadbalancerCertificateManager,
  48. LoadbalancerAclManager,
  49. LoadbalancerManager,
  50. LoadbalancerListenerManager,
  51. LoadbalancerListenerRuleManager,
  52. LoadbalancerBackendGroupManager,
  53. LoadbalancerBackendManager,
  54. LoadbalancerClusterManager,
  55. SchedtagManager,
  56. DynamicschedtagManager,
  57. ServerSkuManager,
  58. ElasticcacheSkuManager,
  59. ExternalProjectManager,
  60. CachedimageManager,
  61. StoragecachedimageManager,
  62. NetworkinterfacenetworkManager,
  63. DBInstanceNetworkManager,
  64. DBInstanceAccountManager,
  65. DBInstanceDatabaseManager,
  66. SnapshotPolicyDiskManager,
  67. AccessGroupManager,
  68. AccessGroupRuleManager,
  69. GroupnetworkManager,
  70. ElasticcacheManager,
  71. baremetal.BaremetalProfileManager,
  72. } {
  73. now := time.Now()
  74. err := manager.InitializeData()
  75. if err != nil {
  76. log.Errorf("%s initializeData fail %s", manager.Keyword(), err)
  77. }
  78. if cost := time.Now().Sub(now); cost > time.Duration(time.Second)*15 {
  79. log.Infof("%s initializeData cost %s", manager.Keyword(), cost.Round(time.Second))
  80. }
  81. }
  82. return nil
  83. }