From cf5f8517dffd1a10c496325efe57541104dc63c3 Mon Sep 17 00:00:00 2001
From: Malte Bauch <malte.bauch@tbnet.works>
Date: Mon, 25 Apr 2022 12:55:33 +0000
Subject: [PATCH] Add map of changeStores to be accessed while creating new
 PNDs

See merge request danet/gosdn!292

Co-authored-by: Andre Sterba <andre.sterba@stud.h-da.de>
Co-authored-by: Malte Bauch <malte.bauch@extern.h-da.de>
---
 controller/nucleus/principalNetworkDomain.go | 22 +++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/controller/nucleus/principalNetworkDomain.go b/controller/nucleus/principalNetworkDomain.go
index 54a04a447..9f24bcc9f 100644
--- a/controller/nucleus/principalNetworkDomain.go
+++ b/controller/nucleus/principalNetworkDomain.go
@@ -39,6 +39,10 @@ import (
 	"github.com/spf13/viper"
 )
 
+// NOTE: Until we've added database support for changes, we will hold
+// changeStores in memory for now.
+var changeStoreMap = make(map[uuid.UUID]*store.ChangeStore)
+
 // NewPND creates a Principle Network Domain
 func NewPND(
 	name string,
@@ -49,12 +53,18 @@ func NewPND(
 ) (networkdomain.NetworkDomain, error) {
 	sbiStore := NewSbiStore(id)
 
+	changeStore, ok := changeStoreMap[id]
+	if !ok {
+		changeStore = store.NewChangeStore()
+		changeStoreMap[id] = changeStore
+	}
+
 	pnd := &pndImplementation{
 		Name:        name,
 		Description: description,
 		sbic:        sbiStore,
 		devices:     NewDeviceStore(id, sbiStore),
-		changes:     store.NewChangeStore(),
+		changes:     changeStore,
 		Id:          id,
 
 		csbiClient: c,
@@ -399,10 +409,12 @@ func (pnd *pndImplementation) RequestAll(path string) error {
 // ChangeOND creates a change from the provided Operation, path and value.
 // The Change is Pending and times out after the specified timeout period
 func (pnd *pndImplementation) ChangeOND(duid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) (uuid.UUID, error) {
-	d, err := pnd.devices.Get((store.Query{
-		ID:   duid,
-		Name: "",
-	}))
+	d, err := pnd.devices.Get(store.Query{
+		ID: duid,
+	})
+	if err != nil {
+		return uuid.Nil, err
+	}
 	cpy, err := ygot.DeepCopy(d.GetModel())
 	ygot.BuildEmptyTree(cpy)
 	if err != nil {
-- 
GitLab