robocanic commented on code in PR #1370:
URL: https://github.com/apache/dubbo-admin/pull/1370#discussion_r2637517268
##########
pkg/core/bootstrap/bootstrap.go:
##########
@@ -34,106 +34,136 @@ func Bootstrap(appCtx context.Context, cfg
app.AdminConfig) (runtime.Runtime, er
if err != nil {
return nil, err
}
- // 0. initialize event bus
- if err := initEventBus(builder); err != nil {
- return nil, err
- }
- // 1. initialize resource store
- if err := initResourceStore(cfg, builder); err != nil {
- return nil, err
- }
- // 2. initialize discovery
- if err := initializeResourceDiscovery(builder); err != nil {
- return nil, err
- }
- // 3. initialize engine
- if err := initializeResourceEngine(builder); err != nil {
- return nil, err
- }
- // 4. initialize resource manager
- if err := initResourceManager(builder); err != nil {
- return nil, err
- }
- // 5. initialize console
- if err := initializeConsole(builder); err != nil {
- return nil, err
- }
- // 6. initialize counter manager
- if err := initializeCounterManager(builder); err != nil {
+
+ // Use smart bootstrapper for intelligent component initialization
+ bootstrapper := NewSmartBootstrapper(builder)
+
+ // Initialize all components in dependency order
+ if err := bootstrapper.bootstrapComponents(appCtx, cfg); err != nil {
return nil, err
}
- // 7. initialize diagnostics
- if err := initializeDiagnoticsServer(builder); err != nil {
- logger.Errorf("got error when init diagnotics server %s", err)
- }
+
+ // Build and return runtime
rt, err := builder.Build()
if err != nil {
return nil, err
}
return rt, nil
}
-func initEventBus(builder *runtime.Builder) error {
- comp, err := runtime.ComponentRegistry().EventBus()
- if err != nil {
- return err
- }
- return initAndActivateComponent(builder, comp)
+// SmartBootstrapper handles intelligent component initialization
+type SmartBootstrapper struct {
+ builder *runtime.Builder
}
-func initResourceStore(cfg app.AdminConfig, builder *runtime.Builder) error {
- comp, err := runtime.ComponentRegistry().ResourceStore()
- if err != nil {
- return errors.Wrapf(err, "could not retrieve resource store %s
component", cfg.Store.Type)
+// NewSmartBootstrapper creates a new smart bootstrapper
+func NewSmartBootstrapper(builder *runtime.Builder) *SmartBootstrapper {
+ return &SmartBootstrapper{
+ builder: builder,
}
- return initAndActivateComponent(builder, comp)
}
-func initResourceManager(builder *runtime.Builder) error {
- comp, err := runtime.ComponentRegistry().ResourceManager()
+
+// bootstrapComponents initializes all components in dependency order
+func (sb *SmartBootstrapper) bootstrapComponents(
+ ctx context.Context,
+ cfg app.AdminConfig,
+) error {
+ logger.Info("Starting smart component bootstrap...")
+
+ // Gather all components to initialize
+ components, err := sb.gatherComponents()
if err != nil {
- return err
+ return errors.Wrap(err, "failed to gather components")
}
- return initAndActivateComponent(builder, comp)
-}
-func initializeConsole(builder *runtime.Builder) error {
- comp, err := runtime.ComponentRegistry().Console()
+ // Sort components by dependencies
+ ordered, err := sb.sortComponents(components)
if err != nil {
- return err
+ return errors.Wrap(err, "failed to sort components by
dependencies")
Review Comment:
Suggestion: use pkg/common/bizerror/error.go instead for better issue
tracking, the same goes for other similar `errors. Wrap` and `errors. New`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]