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"
|
2018-04-24 16:44:59 +08:00
|
|
|
api_db "github.com/goodrain/rainbond/api/db"
|
2019-04-30 14:50:33 +08:00
|
|
|
"github.com/goodrain/rainbond/api/handler/group"
|
|
|
|
"github.com/goodrain/rainbond/api/handler/share"
|
2018-05-23 11:08:44 +08:00
|
|
|
"github.com/goodrain/rainbond/cmd/api/option"
|
2019-04-30 14:50:33 +08:00
|
|
|
"github.com/goodrain/rainbond/db"
|
2019-12-24 22:41:19 +08:00
|
|
|
etcdutil "github.com/goodrain/rainbond/util/etcd"
|
2018-11-19 18:56:28 +08:00
|
|
|
"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"
|
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,
|
|
|
|
) 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
|
|
|
|
}
|
2018-11-22 14:33:29 +08:00
|
|
|
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)
|
2018-05-10 11:08:49 +08:00
|
|
|
defaultAppHandler = CreateAppManager(mqClient)
|
2020-09-24 21:09:00 +08:00
|
|
|
defaultTenantHandler = CreateTenManager(mqClient, statusCli, &conf, kubeClient, prometheusCli)
|
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)
|
|
|
|
batchOperationHandler = CreateBatchOperationHandler(mqClient, operationHandler)
|
2019-04-30 14:50:33 +08:00
|
|
|
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)
|
2019-12-12 11:59:02 +08:00
|
|
|
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)
|
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
|
|
|
|
}
|
2018-05-10 11:08:49 +08:00
|
|
|
|
2018-05-10 17:45:23 +08:00
|
|
|
var defaultAppHandler *AppAction
|
|
|
|
|
2018-05-23 11:08:44 +08:00
|
|
|
//GetAppHandler GetAppHandler
|
2018-05-10 17:45:23 +08:00
|
|
|
func GetAppHandler() *AppAction {
|
2018-05-10 11:08:49 +08:00
|
|
|
return defaultAppHandler
|
2018-05-23 11:08:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2019-02-24 05:13:54 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2019-04-30 14:50:33 +08:00
|
|
|
|
|
|
|
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-21 13:58:08 +08:00
|
|
|
var defApplicationHandler *ApplicationAction
|
2020-09-17 15:45:46 +08:00
|
|
|
|
2020-09-21 13:58:08 +08:00
|
|
|
// GetApplicationHandler returns the default tenant application handler.
|
|
|
|
func GetApplicationHandler() *ApplicationAction {
|
|
|
|
return defApplicationHandler
|
2020-09-17 15:45:46 +08:00
|
|
|
}
|