diff --git a/controller/controller.go b/controller/controller.go index d20db3bd27023ad6c208a39229130c2298f6f8d6..7b48477b18b757da291167d04e19711e7ba9b9af 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -10,7 +10,6 @@ import ( "os/signal" "sync" "syscall" - "time" "github.com/google/uuid" "github.com/sethvargo/go-password/password" @@ -102,19 +101,14 @@ func initialize() error { // Setting up signal capturing signal.Notify(c.stopChan, os.Interrupt, syscall.SIGTERM) - basePnd, err := createPrincipalNetworkDomain() + err = createPrincipalNetworkDomain() if err != nil { return err } - c.deviceWatcher = nucleus.NewDeviceWatcher(basePnd, c.pndStore) - //TODO: Just an example for testing purposes, remove these calls after complete implementation of subscription handling! + c.deviceWatcher = nucleus.NewDeviceWatcher(c.pndStore) + // TODO: udpate with actual paths to subscribe to using template/config c.deviceWatcher.SubToDevices([][]string{{"system", "config", "hostname"}}, nil) - go func() { - time.Sleep(5 * time.Second) - c.deviceWatcher.StopAndRemoveAllDeviceSubscriptions() - return - }() err = ensureDefaultRoleExists() if err != nil { @@ -190,7 +184,7 @@ func startGrpc() error { } // createPrincipalNetworkDomain initializes the controller with an initial PND -func createPrincipalNetworkDomain() (networkdomain.NetworkDomain, error) { +func createPrincipalNetworkDomain() error { basePnd, err := c.pndStore.Get(store.Query{ID: config.BasePndUUID}) if err != nil { log.Info(err) @@ -205,16 +199,16 @@ func createPrincipalNetworkDomain() (networkdomain.NetworkDomain, error) { callback, ) if err != nil { - return nil, err + return err } err = c.pndStore.Add(pnd) if err != nil { - return nil, err + return err } - return pnd, nil + return nil } - return basePnd, nil + return nil } func ensureDefaultRoleExists() error { diff --git a/controller/nucleus/deviceWatcher.go b/controller/nucleus/deviceWatcher.go index f1b16959e547e6f6fc8ccc8f0b5e4c9ba069b7ad..8442a004ec92eb98574403150857eeade1270ca0 100644 --- a/controller/nucleus/deviceWatcher.go +++ b/controller/nucleus/deviceWatcher.go @@ -20,13 +20,12 @@ const ( subscribeSampleInterval uint64 = 1000000000 // 1 second in nanoseconds // TODO: These gNMI options are adjusted to arista gNMI fork. Change when switching to native gNMI. gNMISubscribeMode string = "stream" - gNMIStreamMode string = "sample" + gNMIStreamMode string = "on_change" ) // DeviceWatcher is a component that subscribes to devices via gNMI from within the controller and handles // responses by triggering the internal event process. type DeviceWatcher struct { - pnd networkdomain.NetworkDomain pndStore networkdomain.PndStore deviceSubcriptions map[uuid.UUID]*deviceSubscriptionHelper } @@ -38,9 +37,8 @@ type deviceSubscriptionHelper struct { } // NewDeviceWatcher takes a pndStore to subscribe to device paths. -func NewDeviceWatcher(pnd networkdomain.NetworkDomain, pndStore networkdomain.PndStore) *DeviceWatcher { +func NewDeviceWatcher(pndStore networkdomain.PndStore) *DeviceWatcher { return &DeviceWatcher{ - pnd: pnd, pndStore: pndStore, deviceSubcriptions: make(map[uuid.UUID]*deviceSubscriptionHelper), } @@ -144,9 +142,6 @@ func (d *DeviceWatcher) handleSubscribeResponse(resp *gpb.SubscribeResponse, sub } func (d *DeviceWatcher) handleSubscribeResponseUpdate(resp *gpb.SubscribeResponse_Update, subscriptionInfo *transport.SubscriptionInformation) { - // Not fully implemented yet, just a simple log to see if this works for now - log.Infof("Pnd: %s, Device: %s, Message: %s", subscriptionInfo.PndID, subscriptionInfo.DeviceID, resp.Update.String()) - pndID, err := uuid.Parse(subscriptionInfo.PndID) if err != nil { log.Error(err) diff --git a/controller/nucleus/gnmi_transport.go b/controller/nucleus/gnmi_transport.go index beb213b9e20de6f1f01f8b1e25e270d9a594d6cc..029c33fa15681c318156187127cce98dd6b134a6 100644 --- a/controller/nucleus/gnmi_transport.go +++ b/controller/nucleus/gnmi_transport.go @@ -264,7 +264,6 @@ func (g *Gnmi) ProcessControlPlaneSubscribeResponse(resp *gpb.SubscribeResponse_ } } - //TODO: maybe remove and combine into one function/method! if len(notification.Delete) > 0 { if err := g.processResponseDeletes(notification.Delete, dModel, schema); err != nil { return err diff --git a/controller/nucleus/principalNetworkDomain_test.go b/controller/nucleus/principalNetworkDomain_test.go index ec1621fb754494d756982adba9c16c3a3f54a93c..f62903bd4a5871bf837be80783ed9f148f39c9cc 100644 --- a/controller/nucleus/principalNetworkDomain_test.go +++ b/controller/nucleus/principalNetworkDomain_test.go @@ -1231,7 +1231,7 @@ func Test_pndImplementation_SubscribePath(t *testing.T) { args args wantErr bool }{ - //TODO(faseid): Implement proper test here! + //TODO: Implement proper test here! // { // name: "default", // args: args{