forked from apache/dubbo-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.go
More file actions
136 lines (124 loc) · 3.95 KB
/
bootstrap.go
File metadata and controls
136 lines (124 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package bootstrap
import (
"context"
"github.com/pkg/errors"
"github.com/apache/dubbo-admin/pkg/config/app"
"github.com/apache/dubbo-admin/pkg/core/logger"
"github.com/apache/dubbo-admin/pkg/core/runtime"
"github.com/apache/dubbo-admin/pkg/diagnostics"
)
func Bootstrap(appCtx context.Context, cfg app.AdminConfig) (runtime.Runtime, error) {
builder, err := runtime.BuilderFor(appCtx, cfg)
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 diagnotics
if err := initializeDiagnoticsServer(builder); err != nil {
logger.Errorf("got error when init diagnotics server %s", err)
}
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)
}
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)
}
return initAndActivateComponent(builder, comp)
}
func initResourceManager(builder *runtime.Builder) error {
comp, err := runtime.ComponentRegistry().ResourceManager()
if err != nil {
return err
}
return initAndActivateComponent(builder, comp)
}
func initializeConsole(builder *runtime.Builder) error {
comp, err := runtime.ComponentRegistry().Console()
if err != nil {
return err
}
return initAndActivateComponent(builder, comp)
}
func initializeResourceDiscovery(builder *runtime.Builder) error {
comp, err := runtime.ComponentRegistry().ResourceDiscovery()
if err != nil {
return err
}
return initAndActivateComponent(builder, comp)
}
func initializeResourceEngine(builder *runtime.Builder) error {
comp, err := runtime.ComponentRegistry().ResourceEngine()
if err != nil {
return err
}
return initAndActivateComponent(builder, comp)
}
func initializeDiagnoticsServer(builder *runtime.Builder) error {
comp, err := runtime.ComponentRegistry().Get(diagnostics.DiagnosticsServer)
if err != nil {
return err
}
return initAndActivateComponent(builder, comp)
}
func initAndActivateComponent(builder *runtime.Builder, comp runtime.Component) error {
logger.Infof("initializing %s ...", comp.Type())
if err := comp.Init(builder); err != nil {
return err
}
logger.Infof("%s initialized successfully", comp.Type())
if err := builder.ActivateComponent(comp); err != nil {
return errors.Wrapf(err, "failed to activate %s", comp.Type())
}
return nil
}