Rainbond/api/handler/handler.go

227 lines
6.9 KiB
Go
Raw Normal View History

2018-03-14 14:12:26 +08:00
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
2018-03-04 22:48:50 +08:00
// RAINBOND, Application Management Platform
2018-03-14 14:33:31 +08:00
2018-03-04 22:48:50 +08:00
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
2018-03-14 14:33:31 +08:00
2018-03-04 22:48:50 +08:00
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
2018-03-14 14:33:31 +08:00
2018-03-04 22:48:50 +08:00
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package handler
import (
2020-01-18 21:26:46 +08:00
"github.com/coreos/etcd/clientv3"
2020-09-24 21:09:00 +08:00
"github.com/goodrain/rainbond/api/client/prometheus"
api_db "github.com/goodrain/rainbond/api/db"
"github.com/goodrain/rainbond/api/handler/group"
"github.com/goodrain/rainbond/api/handler/share"
"github.com/goodrain/rainbond/cmd/api/option"
"github.com/goodrain/rainbond/db"
2021-04-16 16:27:21 +08:00
"github.com/goodrain/rainbond/pkg/generated/clientset/versioned"
2019-12-24 22:41:19 +08:00
etcdutil "github.com/goodrain/rainbond/util/etcd"
"github.com/goodrain/rainbond/worker/client"
2020-09-24 21:09:00 +08:00
"github.com/sirupsen/logrus"
2020-06-17 12:57:41 +08:00
"k8s.io/client-go/kubernetes"
2021-05-07 21:41:09 +08:00
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
2018-03-04 22:48:50 +08:00
)
//InitHandle 初始化handle
2020-06-17 12:57:41 +08:00
func InitHandle(conf option.Config,
etcdClientArgs *etcdutil.ClientArgs,
statusCli *client.AppRuntimeSyncClient,
etcdcli *clientv3.Client,
kubeClient *kubernetes.Clientset,
2021-04-16 16:27:21 +08:00
rainbondClient versioned.Interface,
2021-05-07 21:41:09 +08:00
k8sClient k8sclient.Client,
2020-06-17 12:57:41 +08:00
) error {
2018-03-04 22:48:50 +08:00
mq := api_db.MQManager{
2019-12-24 22:41:19 +08:00
EtcdClientArgs: etcdClientArgs,
DefaultServer: conf.MQAPI,
2018-03-04 22:48:50 +08:00
}
mqClient, errMQ := mq.NewMQManager()
if errMQ != nil {
logrus.Errorf("new MQ manager failed, %v", errMQ)
return errMQ
}
2020-09-24 21:09:00 +08:00
prometheusCli, err := prometheus.NewPrometheus(&prometheus.Options{
Endpoint: conf.PrometheusEndpoint,
})
if err != nil {
logrus.Errorf("new prometheus client failure, %v", err)
return err
}
dbmanager := db.GetManager()
2020-09-24 21:09:00 +08:00
defaultServieHandler = CreateManager(conf, mqClient, etcdcli, statusCli, prometheusCli)
2018-03-04 22:48:50 +08:00
defaultPluginHandler = CreatePluginManager(mqClient)
defaultAppHandler = CreateAppManager(mqClient)
2021-05-07 21:41:09 +08:00
defaultTenantHandler = CreateTenManager(mqClient, statusCli, &conf, kubeClient, prometheusCli, k8sClient)
2020-01-18 21:26:46 +08:00
defaultNetRulesHandler = CreateNetRulesManager(etcdcli)
2018-03-04 22:48:50 +08:00
defaultCloudHandler = CreateCloudManager(conf)
2020-01-18 21:26:46 +08:00
defaultAPPBackupHandler = group.CreateBackupHandle(mqClient, statusCli, etcdcli)
2020-02-03 13:47:13 +08:00
defaultEventHandler = CreateLogManager(etcdcli)
2020-01-18 21:26:46 +08:00
shareHandler = &share.ServiceShareHandle{MQClient: mqClient, EtcdCli: etcdcli}
pluginShareHandler = &share.PluginShareHandle{MQClient: mqClient, EtcdCli: etcdcli}
2018-03-04 22:48:50 +08:00
if err := CreateTokenIdenHandler(conf); err != nil {
logrus.Errorf("create token identification mannager error, %v", err)
return err
}
2020-01-18 21:26:46 +08:00
defaultGatewayHandler = CreateGatewayManager(dbmanager, mqClient, etcdcli)
2019-03-09 22:17:52 +08:00
def3rdPartySvcHandler = Create3rdPartySvcHandler(dbmanager, statusCli)
2019-03-09 13:51:36 +08:00
operationHandler = CreateOperationHandler(mqClient)
2021-05-26 11:00:44 +08:00
batchOperationHandler = CreateBatchOperationHandler(mqClient, statusCli, operationHandler)
defaultAppRestoreHandler = NewAppRestoreHandler()
2019-08-21 15:07:20 +08:00
defPodHandler = NewPodHandler(statusCli)
2020-09-11 21:21:19 +08:00
defClusterHandler = NewClusterHandler(kubeClient, conf.RbdNamespace)
defaultVolumeTypeHandler = CreateVolumeTypeManger(statusCli)
2020-02-04 21:00:03 +08:00
defaultEtcdHandler = NewEtcdHandler(etcdcli)
2020-09-24 21:09:00 +08:00
defaultmonitorHandler = NewMonitorHandler(prometheusCli)
2021-04-17 15:47:59 +08:00
defApplicationHandler = NewApplicationHandler(statusCli, prometheusCli, rainbondClient, kubeClient)
2018-03-04 22:48:50 +08:00
return nil
}
var defaultServieHandler ServiceHandler
var shareHandler *share.ServiceShareHandle
2018-05-29 12:51:10 +08:00
var pluginShareHandler *share.PluginShareHandle
2020-09-24 21:09:00 +08:00
var defaultmonitorHandler MonitorHandler
//GetMonitorHandle get monitor handler
func GetMonitorHandle() MonitorHandler {
return defaultmonitorHandler
}
2018-03-04 22:48:50 +08:00
//GetShareHandle get share handle
func GetShareHandle() *share.ServiceShareHandle {
return shareHandler
}
2018-05-29 12:51:10 +08:00
//GetPluginShareHandle get plugin share handle
func GetPluginShareHandle() *share.PluginShareHandle {
return pluginShareHandler
}
2018-03-04 22:48:50 +08:00
//GetServiceManager get manager
func GetServiceManager() ServiceHandler {
return defaultServieHandler
}
var defaultPluginHandler PluginHandler
//GetPluginManager get manager
func GetPluginManager() PluginHandler {
return defaultPluginHandler
}
var defaultTenantHandler TenantHandler
//GetTenantManager get manager
func GetTenantManager() TenantHandler {
return defaultTenantHandler
}
var defaultNetRulesHandler NetRulesHandler
//GetRulesManager get manager
func GetRulesManager() NetRulesHandler {
return defaultNetRulesHandler
}
var defaultCloudHandler CloudHandler
//GetCloudManager get manager
func GetCloudManager() CloudHandler {
return defaultCloudHandler
}
var defaultEventHandler EventHandler
//GetEventHandler get event handler
func GetEventHandler() EventHandler {
return defaultEventHandler
}
var defaultAppHandler *AppAction
//GetAppHandler GetAppHandler
func GetAppHandler() *AppAction {
return defaultAppHandler
}
var defaultAPPBackupHandler *group.BackupHandle
//GetAPPBackupHandler GetAPPBackupHandler
func GetAPPBackupHandler() *group.BackupHandle {
return defaultAPPBackupHandler
}
2018-11-21 15:04:03 +08:00
var defaultGatewayHandler GatewayHandler
// GetGatewayHandler returns a default GatewayHandler
func GetGatewayHandler() GatewayHandler {
return defaultGatewayHandler
}
var def3rdPartySvcHandler *ThirdPartyServiceHanlder
// Get3rdPartySvcHandler returns the defalut ThirdParthServiceHanlder
func Get3rdPartySvcHandler() *ThirdPartyServiceHanlder {
return def3rdPartySvcHandler
}
2019-03-08 19:22:22 +08:00
var batchOperationHandler *BatchOperationHandler
//GetBatchOperationHandler get handler
func GetBatchOperationHandler() *BatchOperationHandler {
return batchOperationHandler
}
2019-03-09 13:51:36 +08:00
var operationHandler *OperationHandler
//GetOperationHandler get handler
func GetOperationHandler() *OperationHandler {
return operationHandler
}
var defaultAppRestoreHandler AppRestoreHandler
// GetAppRestoreHandler returns a default AppRestoreHandler
func GetAppRestoreHandler() AppRestoreHandler {
return defaultAppRestoreHandler
}
2019-08-21 15:07:20 +08:00
var defPodHandler PodHandler
// GetPodHandler returns the defalut PodHandler
func GetPodHandler() PodHandler {
return defPodHandler
}
2020-02-04 21:00:03 +08:00
var defaultEtcdHandler *EtcdHandler
2020-06-03 23:03:50 +08:00
// GetEtcdHandler returns the default etcd handler.
2020-02-04 21:00:03 +08:00
func GetEtcdHandler() *EtcdHandler {
return defaultEtcdHandler
}
2020-07-13 16:07:06 +08:00
var defClusterHandler ClusterHandler
// GetClusterHandler returns the default cluster handler.
func GetClusterHandler() ClusterHandler {
return defClusterHandler
}
2020-09-17 15:45:46 +08:00
2020-09-28 16:43:27 +08:00
var defApplicationHandler ApplicationHandler
2020-09-17 15:45:46 +08:00
// GetApplicationHandler returns the default tenant application handler.
2020-09-28 16:43:27 +08:00
func GetApplicationHandler() ApplicationHandler {
return defApplicationHandler
2020-09-17 15:45:46 +08:00
}