New creates a new instance of the sync manager
(nodeID, clusterID, storeType, runnerAddr string, adminMan AdminSyncmanInterface, integrationMan integrationInterface, ssl *config.SSL)
| 47 | |
| 48 | // New creates a new instance of the sync manager |
| 49 | func New(nodeID, clusterID, storeType, runnerAddr string, adminMan AdminSyncmanInterface, integrationMan integrationInterface, ssl *config.SSL) (*Manager, error) { |
| 50 | |
| 51 | // Create a new manager instance |
| 52 | m := &Manager{nodeID: nodeID, clusterID: clusterID, storeType: storeType, runnerAddr: runnerAddr, adminMan: adminMan, integrationMan: integrationMan} |
| 53 | |
| 54 | // Initialise the consul client if enabled |
| 55 | var s Store |
| 56 | var err error |
| 57 | switch storeType { |
| 58 | case "local": |
| 59 | s, err = NewLocalStore(nodeID, ssl) |
| 60 | case "kube": |
| 61 | s, err = NewKubeStore(clusterID) |
| 62 | default: |
| 63 | return nil, helpers.Logger.LogError(helpers.GetRequestID(context.TODO()), fmt.Sprintf("Cannot initialize syncaman as invalid store type (%v) provided", storeType), nil, nil) |
| 64 | } |
| 65 | |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | m.store = s |
| 70 | m.store.Register() |
| 71 | |
| 72 | pubsubClient, err := pubsub.New("license-manager", os.Getenv("REDIS_CONN")) |
| 73 | if err != nil { |
| 74 | return nil, helpers.Logger.LogError("syncman-new", "Unable to initialize pub sub client required for sync module, ensure that redis database is running", err, nil) |
| 75 | } |
| 76 | m.pubsubClient = pubsubClient |
| 77 | m.leader = leader.New(nodeID, pubsubClient) |
| 78 | |
| 79 | return m, nil |
| 80 | } |
| 81 | |
| 82 | // Start begins the sync manager operations |
| 83 | func (s *Manager) Start(port int) error { |
nothing calls this directly
no test coverage detected