Rainbond/node/masterserver/server.go

77 lines
2.3 KiB
Go
Raw Normal View History

2018-03-14 14:12:26 +08:00
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
2017-11-07 11:40:44 +08:00
// RAINBOND, Application Management Platform
2018-03-14 14:33:31 +08:00
2017-11-07 11:40:44 +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
2017-11-07 11:40:44 +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
2017-11-07 11:40:44 +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 masterserver
2017-11-07 11:40:44 +08:00
import (
2017-11-09 17:32:02 +08:00
"context"
2020-09-06 11:09:48 +08:00
"github.com/sirupsen/logrus"
2017-12-18 11:10:45 +08:00
2018-07-13 17:58:06 +08:00
"github.com/goodrain/rainbond/node/kubecache"
"github.com/goodrain/rainbond/node/nodem/client"
2017-12-18 11:10:45 +08:00
"github.com/goodrain/rainbond/node/core/config"
"github.com/goodrain/rainbond/node/core/store"
"github.com/goodrain/rainbond/node/masterserver/node"
2017-11-07 11:40:44 +08:00
)
//MasterServer 主节点服务
type MasterServer struct {
*store.Client
2018-07-13 17:58:06 +08:00
*client.HostNode
2018-05-18 23:40:19 +08:00
Cluster *node.Cluster
ctx context.Context
cancel context.CancelFunc
datacenterConfig *config.DataCenterConfig
2017-11-09 17:32:02 +08:00
}
//NewMasterServer 创建master节点
2018-07-13 17:58:06 +08:00
func NewMasterServer(modelnode *client.HostNode, kubecli kubecache.KubeClient) (*MasterServer, error) {
datacenterConfig := config.GetDataCenterConfig()
2017-11-09 17:32:02 +08:00
ctx, cancel := context.WithCancel(context.Background())
2018-07-13 17:58:06 +08:00
nodecluster := node.CreateCluster(kubecli, modelnode, datacenterConfig)
2017-11-09 17:32:02 +08:00
ms := &MasterServer{
Client: store.DefalutClient,
2017-12-18 11:10:45 +08:00
HostNode: modelnode,
Cluster: nodecluster,
ctx: ctx,
cancel: cancel,
datacenterConfig: datacenterConfig,
2017-11-09 17:32:02 +08:00
}
return ms, nil
}
2018-04-18 11:12:38 +08:00
//Start master node start
func (m *MasterServer) Start(errchan chan error) error {
m.datacenterConfig.Start()
2018-05-18 23:40:19 +08:00
if err := m.Cluster.Start(errchan); err != nil {
2017-12-18 11:10:45 +08:00
logrus.Error("node cluster start error,", err.Error())
return err
}
2021-05-24 11:10:37 +08:00
return nil
2017-11-09 17:32:02 +08:00
}
//Stop 停止
func (m *MasterServer) Stop(i interface{}) {
2017-12-18 11:10:45 +08:00
if m.Cluster != nil {
m.Cluster.Stop(i)
}
2017-11-09 17:32:02 +08:00
m.cancel()
2017-11-07 11:40:44 +08:00
}