@@ -32,6 +32,9 @@ import (
3232 "github.com/nordix/meridio/pkg/configuration/registry"
3333 "github.com/nordix/meridio/pkg/health"
3434 "github.com/nordix/meridio/pkg/nsp"
35+ nspRegistry "github.com/nordix/meridio/pkg/nsp/registry"
36+ "github.com/nordix/meridio/pkg/nsp/watchhandler"
37+ "github.com/pkg/errors"
3538
3639 keepAliveRegistry "github.com/nordix/meridio/pkg/nsp/registry/keepalive"
3740 sqliteRegistry "github.com/nordix/meridio/pkg/nsp/registry/sqlite"
@@ -97,31 +100,18 @@ func main() {
97100 ctx = health .CreateChecker (ctx )
98101
99102 // configuration
100- configurationEventChan := make (chan * registry.ConfigurationEvent , 10 )
101- configurationRegistry := registry .New (configurationEventChan )
102- configurationMonitor , err := monitor .New (config .ConfigMapName , config .Namespace , configurationRegistry )
103+ configurationManagerServer , err := CreateConfigurationManagerServer (ctx , & config )
103104 if err != nil {
104- logrus .Fatalf ("Unable to start configuration monitor : %v" , err )
105+ logrus .Fatalf ("CreateConfigurationManagerServer err : %v" , err )
105106 }
106- go configurationMonitor .Start (context .Background ())
107- watcherNotifier := manager .NewWatcherNotifier (configurationRegistry , configurationEventChan )
108- go watcherNotifier .Start (context .Background ())
109- configurationManagerServer := manager .NewServer (watcherNotifier )
110107
111108 // target registry
112- sqlr , err := sqliteRegistry . New ( config . Datasource )
109+ targetRegistryServer , err := CreateTargetRegistryServer ( ctx , & config )
113110 if err != nil {
114- logrus .Fatalf ("Unable create sqlite registry : %v" , err )
111+ logrus .Fatalf ("CreateTargetRegistryServer err : %v" , err )
115112 }
116- keepAliveRegistry , err := keepAliveRegistry .New (
117- keepAliveRegistry .WithRegistry (sqlr ),
118- keepAliveRegistry .WithTimeout (config .EntryTimeout ),
119- )
120- if err != nil {
121- logrus .Fatalf ("Unable create keepalive registry: %v" , err )
122- }
123- targetRegistryServer := nsp .NewServer (keepAliveRegistry )
124113
114+ // Create Server
125115 server := grpc .NewServer (grpc .Creds (
126116 credentials .GetServer (context .Background ()),
127117 ))
@@ -141,3 +131,34 @@ func main() {
141131
142132 <- ctx .Done ()
143133}
134+
135+ func CreateTargetRegistryServer (ctx context.Context , config * Config ) (nspAPI.TargetRegistryServer , error ) {
136+ sqlr , err := sqliteRegistry .New (config .Datasource )
137+ if err != nil {
138+ return nil , errors .Wrap (err , "Unable create sqlite registry" )
139+ }
140+ keepAliveRegistry , err := keepAliveRegistry .New (
141+ keepAliveRegistry .WithRegistry (sqlr ),
142+ keepAliveRegistry .WithTimeout (config .EntryTimeout ),
143+ )
144+ if err != nil {
145+ return nil , errors .Wrap (err , "Unable create keepalive registry" )
146+ }
147+ return nsp .NewServer (
148+ nspRegistry .NewServer (keepAliveRegistry ),
149+ watchhandler .NewServer (keepAliveRegistry ),
150+ ), nil
151+ }
152+
153+ func CreateConfigurationManagerServer (ctx context.Context , config * Config ) (nspAPI.ConfigurationManagerServer , error ) {
154+ configurationEventChan := make (chan * registry.ConfigurationEvent , 10 )
155+ configurationRegistry := registry .New (configurationEventChan )
156+ configurationMonitor , err := monitor .New (config .ConfigMapName , config .Namespace , configurationRegistry )
157+ if err != nil {
158+ return nil , errors .Wrap (err , "Unable to start configuration monitor" )
159+ }
160+ go configurationMonitor .Start (context .Background ())
161+ watcherNotifier := manager .NewWatcherNotifier (configurationRegistry , configurationEventChan )
162+ go watcherNotifier .Start (context .Background ())
163+ return manager .NewServer (watcherNotifier ), nil
164+ }
0 commit comments