/
provider.go
123 lines (107 loc) · 4.55 KB
/
provider.go
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
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed 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 dop
import (
"embed"
"os"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
"github.com/erda-project/erda-infra/base/logs"
"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda-infra/base/version"
componentprotocol "github.com/erda-project/erda-infra/providers/component-protocol"
"github.com/erda-project/erda-infra/providers/component-protocol/protocol"
"github.com/erda-project/erda-infra/providers/etcd"
"github.com/erda-project/erda-infra/providers/i18n"
dashboardPb "github.com/erda-project/erda-proto-go/cmp/dashboard/pb"
cmspb "github.com/erda-project/erda-proto-go/core/pipeline/cms/pb"
addonmysqlpb "github.com/erda-project/erda-proto-go/orchestrator/addon/mysql/pb"
"github.com/erda-project/erda/bundle"
"github.com/erda-project/erda/modules/dop/bdl"
"github.com/erda-project/erda/modules/dop/component-protocol/types"
"github.com/erda-project/erda/modules/dop/conf"
"github.com/erda-project/erda/modules/dop/providers/autotest/testplan"
"github.com/erda-project/erda/modules/pipeline/providers/definition_client"
"github.com/erda-project/erda/pkg/discover"
"github.com/erda-project/erda/pkg/dumpstack"
"github.com/erda-project/erda/pkg/http/httpclient"
)
//go:embed component-protocol/scenarios
var scenarioFS embed.FS
type provider struct {
Log logs.Logger
PipelineCms cmspb.CmsServiceServer `autowired:"erda.core.pipeline.cms.CmsService" optional:"true"`
PipelineDs definition_client.Processor `autowired:"erda.core.pipeline.definition-process-client" optional:"true"`
TestPlanSvc *testplan.TestPlanService `autowired:"erda.core.dop.autotest.testplan.TestPlanService"`
Cmp dashboardPb.ClusterResourceServer `autowired:"erda.cmp.dashboard.resource.ClusterResource"`
AddonMySQLSvc addonmysqlpb.AddonMySQLServiceServer `autowired:"erda.orchestrator.addon.mysql.AddonMySQLService"`
Protocol componentprotocol.Interface
CPTran i18n.I18n `autowired:"i18n@cp"`
IssueTan i18n.Translator `translator:"issue-manage"`
ResourceTrans i18n.Translator `translator:"resource-trans"`
DB *gorm.DB `autowired:"mysql-client"`
ETCD etcd.Interface // autowired
EtcdClient *clientv3.Client // autowired
}
func (p *provider) Init(ctx servicehub.Context) error {
p.Log.Info("init dop")
// component-protocol
p.Log.Info("init component-protocol")
p.Protocol.SetI18nTran(p.CPTran) // use custom i18n translator
// compatible for legacy protocol context bundle
bdl.Init(
// bundle.WithDOP(), // TODO change to internal method invoke in component-protocol
bundle.WithHepa(),
bundle.WithOrchestrator(),
bundle.WithEventBox(),
bundle.WithGittar(),
bundle.WithPipeline(),
bundle.WithMonitor(),
bundle.WithCollector(),
bundle.WithHTTPClient(httpclient.New(
httpclient.WithTimeout(time.Second*15, time.Duration(conf.BundleTimeoutSecond())*time.Second), // bundle 默认 (time.Second, time.Second*3)
)),
bundle.WithKMS(),
bundle.WithCoreServices(),
bundle.WithHTTPClient(
httpclient.New(
httpclient.WithTimeout(time.Second, time.Second*90),
httpclient.WithEnableAutoRetry(false),
)),
// TODO remove it after internal bundle invoke inside cp issue-manage adjusted
bundle.WithCustom(discover.EnvDOP, "localhost:9527"),
)
p.Protocol.WithContextValue(types.GlobalCtxKeyBundle, bdl.Bdl)
protocol.MustRegisterProtocolsFromFS(scenarioFS)
p.Log.Info("init component-protocol done")
p.Protocol.WithContextValue(types.AddonMySQLService, p.AddonMySQLSvc)
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05.000000000",
})
logrus.SetOutput(os.Stdout)
dumpstack.Open()
logrus.Infoln(version.String())
return p.Initialize(ctx)
}
func init() {
servicehub.Register("dop", &servicehub.Spec{
Services: []string{"dop"},
Dependencies: []string{"etcd"},
Creator: func() servicehub.Provider { return &provider{} },
})
}