You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

controller.go 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright 2021 The KubeEdge Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package globalmanager
  14. import (
  15. "fmt"
  16. "os"
  17. "k8s.io/klog/v2"
  18. "github.com/kubeedge/sedna/pkg/globalmanager/config"
  19. websocket "github.com/kubeedge/sedna/pkg/globalmanager/messagelayer/ws"
  20. )
  21. // MainController defines the main controller
  22. type MainController struct {
  23. Config *config.ControllerConfig
  24. }
  25. // NewController creates a new main controller
  26. func NewController(cc *config.ControllerConfig) *MainController {
  27. config.InitConfigure(cc)
  28. return &MainController{
  29. Config: cc,
  30. }
  31. }
  32. // Start starts the main controller
  33. func (c *MainController) Start() {
  34. type newFunc func(cfg *config.ControllerConfig) (FeatureControllerI, error)
  35. for _, featureFunc := range []newFunc{
  36. NewUpstreamController,
  37. NewDownstreamController,
  38. NewFederatedController,
  39. NewJointController,
  40. NewIncrementalJobController,
  41. } {
  42. f, _ := featureFunc(c.Config)
  43. err := f.Start()
  44. if err != nil {
  45. klog.Warningf("failed to start controller %s: %+v", f.GetName(), err)
  46. } else {
  47. klog.Infof("started controller %s", f.GetName())
  48. }
  49. }
  50. addr := fmt.Sprintf("%s:%d", c.Config.WebSocket.Address, c.Config.WebSocket.Port)
  51. ws := websocket.NewServer(addr)
  52. err := ws.ListenAndServe()
  53. if err != nil {
  54. klog.Fatalf("failed to listen websocket at %s", addr)
  55. os.Exit(1)
  56. }
  57. }