Skip to content
Snippets Groups Projects
Commit 39f37eb0 authored by Malte Bauch's avatar Malte Bauch
Browse files

Apply review feedback

parent 1106569e
No related branches found
No related tags found
1 merge request!401Change the current gosdn plugin implementation from Go's internal plugin system to hashicorp's go-plugins
Pipeline #135996 failed
...@@ -55,7 +55,7 @@ var networkElementListCmd = &cobra.Command{ ...@@ -55,7 +55,7 @@ var networkElementListCmd = &cobra.Command{
data := pterm.TableData{[]string{"UUID", "Name", "Plugin-UUID"}} data := pterm.TableData{[]string{"UUID", "Name", "Plugin-UUID"}}
for _, mne := range resp.GetMne() { for _, mne := range resp.GetMne() {
data = append(data, []string{mne.GetId(), mne.GetName(), mne.GetPid()}) data = append(data, []string{mne.GetId(), mne.GetName(), mne.GetPluginid()})
} }
spinner.Success() spinner.Success()
......
...@@ -62,7 +62,6 @@ var pndUseCmd = &cobra.Command{ ...@@ -62,7 +62,6 @@ var pndUseCmd = &cobra.Command{
} }
viper.Set("CLI_PND", newPND) viper.Set("CLI_PND", newPND)
//viper.Set("CLI_SBI", sbi.GetSbi()[0].GetId())
err = viper.WriteConfig() err = viper.WriteConfig()
if err != nil { if err != nil {
......
...@@ -229,19 +229,6 @@ func (c ConfigurationManagementServer) createElementsFromSDNConfig(sdnConfig *lo ...@@ -229,19 +229,6 @@ func (c ConfigurationManagementServer) createElementsFromSDNConfig(sdnConfig *lo
return nil return nil
} }
//func (c ConfigurationManagementServer) createPlugins(sdnConfig *loadedSDNConfig) error {
// for _, inputPlugin := range sdnConfig.Plugins {
// plugin, err := nucleus.NewPluginThroughReattachConfig(inputPlugin)
// if err != nil {
// return err
// }
// if err := c.pluginService.Add(plugin); err != nil {
// return err
// }
// }
// return nil
//}
func (c ConfigurationManagementServer) createTopology(sdnConfig *loadedSDNConfig) error { func (c ConfigurationManagementServer) createTopology(sdnConfig *loadedSDNConfig) error {
for _, inputNode := range sdnConfig.Nodes { for _, inputNode := range sdnConfig.Nodes {
node := nodes.Node{ node := nodes.Node{
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// DatabasePluginStore is used to store SouthboundInterfaces. // DatabasePluginStore is used to store Plugins.
type DatabasePluginStore struct { type DatabasePluginStore struct {
pluginStoreName string pluginStoreName string
} }
...@@ -45,7 +45,7 @@ func (s *DatabasePluginStore) Add(pluginToAdd plugin.Plugin) (err error) { ...@@ -45,7 +45,7 @@ func (s *DatabasePluginStore) Add(pluginToAdd plugin.Plugin) (err error) {
return nil return nil
} }
// Update updates a existing network element. // Update updates an existing plugin.
func (s *DatabasePluginStore) Update(pluginToUpdate plugin.Plugin) (err error) { func (s *DatabasePluginStore) Update(pluginToUpdate plugin.Plugin) (err error) {
var updatedLoadedPlugin plugin.LoadedPlugin var updatedLoadedPlugin plugin.LoadedPlugin
......
...@@ -223,17 +223,14 @@ func (g *Gnmi) processResponseUpdates(updates []*gpb.Update) error { ...@@ -223,17 +223,14 @@ func (g *Gnmi) processResponseUpdates(updates []*gpb.Update) error {
path := update.Path path := update.Path
switch val := update.Val.Value.(type) { switch val := update.Val.Value.(type) {
case *gpb.TypedValue_JsonVal: case *gpb.TypedValue_JsonVal:
//opts := []ytypes.UnmarshalOpt{&ytypes.IgnoreExtraFields{}}
if err := g.Unmarshal(val.JsonVal, path); err != nil { if err := g.Unmarshal(val.JsonVal, path); err != nil {
errs = append(errs, err) errs = append(errs, err)
} }
case *gpb.TypedValue_JsonIetfVal: case *gpb.TypedValue_JsonIetfVal:
//opts := []ytypes.UnmarshalOpt{&ytypes.IgnoreExtraFields{}}
if err := g.Unmarshal(val.JsonIetfVal, path); err != nil { if err := g.Unmarshal(val.JsonIetfVal, path); err != nil {
errs = append(errs, err) errs = append(errs, err)
} }
default: default:
//opts := []ytypes.SetNodeOpt{&ytypes.InitMissingElements{}, &ytypes.TolerateJSONInconsistencies{}}
if err := g.SetNode(update.Path, update.Val); err != nil { if err := g.SetNode(update.Path, update.Val); err != nil {
errs = append(errs, err) errs = append(errs, err)
} }
......
...@@ -12,13 +12,13 @@ import ( ...@@ -12,13 +12,13 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// FilesystemPluginStore is used to store SouthboundInterfaces. // FilesystemPluginStore is used to store Plugins.
type FilesystemPluginStore struct { type FilesystemPluginStore struct {
fileMutex sync.Mutex fileMutex sync.Mutex
pathToPluginFile string pathToPluginFile string
} }
// NewFilesystemPluginStore returns a filesystem implementation for a pnd store. // NewFilesystemPluginStore returns a filesystem implementation for a plugin store.
func NewFilesystemPluginStore() plugin.Store { func NewFilesystemPluginStore() plugin.Store {
if err := store.EnsureFilesystemStorePathExists(store.PluginFilenameSuffix); err != nil { if err := store.EnsureFilesystemStorePathExists(store.PluginFilenameSuffix); err != nil {
log.Error(err) log.Error(err)
...@@ -84,7 +84,7 @@ func (s *FilesystemPluginStore) Add(pluginToAdd plugin.Plugin) error { ...@@ -84,7 +84,7 @@ func (s *FilesystemPluginStore) Add(pluginToAdd plugin.Plugin) error {
return nil return nil
} }
// Update updates a existing network element. // Update updates an existing plugin.
func (s *FilesystemPluginStore) Update(pluginToUpdate plugin.Plugin) error { func (s *FilesystemPluginStore) Update(pluginToUpdate plugin.Plugin) error {
s.fileMutex.Lock() s.fileMutex.Lock()
defer s.fileMutex.Unlock() defer s.fileMutex.Unlock()
...@@ -140,8 +140,8 @@ func (s *FilesystemPluginStore) Delete(pluginToDelete plugin.Plugin) error { ...@@ -140,8 +140,8 @@ func (s *FilesystemPluginStore) Delete(pluginToDelete plugin.Plugin) error {
return &customerrs.CouldNotDeleteError{Identifier: pluginToDelete.ID(), Type: pluginToDelete, Err: err} return &customerrs.CouldNotDeleteError{Identifier: pluginToDelete.ID(), Type: pluginToDelete, Err: err}
} }
// Get takes a SouthboundInterface's UUID or name and returns the SouthboundInterface. If the requested // Get takes a Plugin's UUID or name and returns the Plugin. If the requested
// SouthboundInterface does not exist an error is returned. // Plugin does not exist an error is returned.
func (s *FilesystemPluginStore) Get(query store.Query) (plugin.LoadedPlugin, error) { func (s *FilesystemPluginStore) Get(query store.Query) (plugin.LoadedPlugin, error) {
s.fileMutex.Lock() s.fileMutex.Lock()
defer s.fileMutex.Unlock() defer s.fileMutex.Unlock()
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/store" "code.fbi.h-da.de/danet/gosdn/controller/store"
) )
// NewPluginStore returns a sbiStore. // NewPluginStore returns a pluginStore.
func NewPluginStore() plugin.Store { func NewPluginStore() plugin.Store {
storeMode := store.GetStoreMode() storeMode := store.GetStoreMode()
......
package shared
import (
"errors"
"io"
"golang.org/x/net/context"
pb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/plugin"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/sirupsen/logrus"
)
type DeviceModelClient struct{ client pb.PluginClient }
func (m *DeviceModelClient) Unmarshal(json []byte, path *gpb.Path) error {
_, err := m.client.Unmarshal(context.Background(), &pb.UnmarshalRequest{
Json: json,
Path: path,
})
return err
}
func (m *DeviceModelClient) SetNode(path *gpb.Path, value *gpb.TypedValue) error {
_, err := m.client.SetNode(context.Background(), &pb.SetNodeRequest{
Path: path,
Value: value,
})
return err
}
func (m *DeviceModelClient) GetNode(path *gpb.Path) ([]*gpb.Notification, error) {
resp, err := m.client.GetNode(context.Background(), &pb.GetNodeRequest{
Path: path,
})
return resp.GetNodes(), err
}
func (m *DeviceModelClient) DeleteNode(path *gpb.Path) error {
_, err := m.client.DeleteNode(context.Background(), &pb.DeleteNodeRequest{
Path: path,
})
return err
}
func (m *DeviceModelClient) Model(filterReadOnly bool) ([]byte, error) {
resp, err := m.client.Model(context.Background(), &pb.ModelRequest{
FilterReadOnly: filterReadOnly,
})
return resp.Json, err
}
func (m *DeviceModelClient) Diff(original, modified []byte) (*gpb.Notification, error) {
resp, err := m.client.Diff(context.Background(), &pb.DiffRequest{
Original: original,
Modified: modified,
})
return resp.GetNotification(), err
}
func (m *DeviceModelClient) ValidateChange(operation ppb.ApiOperation, path *gpb.Path, value []byte) ([]byte, error) {
resp, err := m.client.ValidateChange(context.Background(), &pb.ValidateChangeRequest{
Operation: operation,
Path: path,
Value: value,
})
return resp.GetModel(), err
}
func (m *DeviceModelClient) PruneConfigFalse(value []byte) ([]byte, error) {
resp, err := m.client.PruneConfigFalse(context.Background(), &pb.PruneConfigFalseRequest{
Value: value,
})
return resp.GetModel(), err
}
func (m *DeviceModelClient) SchemaTreeGzip() ([]byte, error) {
schemaTreeGzipClient, err := m.client.SchemaTreeGzip(context.Background(), &pb.SchemaTreeGzipRequest{})
if err != nil {
return nil, err
}
sTreeBytes := []byte{}
for {
payload, err := schemaTreeGzipClient.Recv()
if err != nil {
if errors.Is(err, io.EOF) {
break
}
logrus.Error(err)
closeErr := schemaTreeGzipClient.CloseSend()
if closeErr != nil {
return nil, err
}
return nil, err
}
sTreeBytes = append(sTreeBytes, payload.Chunk...)
}
return sTreeBytes, nil
}
...@@ -8,112 +8,9 @@ import ( ...@@ -8,112 +8,9 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
pb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/plugin" pb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/plugin"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
type byteSize float64
// constants representing human friendly data sizes as per https://www.socketloop.com/tutorials/golang-how-to-declare-kilobyte-megabyte-gigabyte-terabyte-and-so-on
const (
_ = iota // ignore first value by assigning to blank identifier
KB byteSize = 1 << (10 * iota)
MB
)
type DeviceModelClient struct{ client pb.PluginClient }
func (m *DeviceModelClient) Unmarshal(json []byte, path *gpb.Path) error {
_, err := m.client.Unmarshal(context.Background(), &pb.UnmarshalRequest{
Json: json,
Path: path,
})
return err
}
func (m *DeviceModelClient) SetNode(path *gpb.Path, value *gpb.TypedValue) error {
_, err := m.client.SetNode(context.Background(), &pb.SetNodeRequest{
Path: path,
Value: value,
})
return err
}
func (m *DeviceModelClient) GetNode(path *gpb.Path) ([]*gpb.Notification, error) {
resp, err := m.client.GetNode(context.Background(), &pb.GetNodeRequest{
Path: path,
})
return resp.GetNodes(), err
}
func (m *DeviceModelClient) DeleteNode(path *gpb.Path) error {
_, err := m.client.DeleteNode(context.Background(), &pb.DeleteNodeRequest{
Path: path,
})
return err
}
func (m *DeviceModelClient) Model(filterReadOnly bool) ([]byte, error) {
resp, err := m.client.Model(context.Background(), &pb.ModelRequest{
FilterReadOnly: filterReadOnly,
})
return resp.Json, err
}
func (m *DeviceModelClient) Diff(original, modified []byte) (*gpb.Notification, error) {
resp, err := m.client.Diff(context.Background(), &pb.DiffRequest{
Original: original,
Modified: modified,
})
return resp.GetNotification(), err
}
func (m *DeviceModelClient) ValidateChange(operation ppb.ApiOperation, path *gpb.Path, value []byte) ([]byte, error) {
resp, err := m.client.ValidateChange(context.Background(), &pb.ValidateChangeRequest{
Operation: operation,
Path: path,
Value: value,
})
return resp.GetModel(), err
}
func (m *DeviceModelClient) PruneConfigFalse(value []byte) ([]byte, error) {
resp, err := m.client.PruneConfigFalse(context.Background(), &pb.PruneConfigFalseRequest{
Value: value,
})
return resp.GetModel(), err
}
func (m *DeviceModelClient) SchemaTreeGzip() ([]byte, error) {
schemaTreeGzipClient, err := m.client.SchemaTreeGzip(context.Background(), &pb.SchemaTreeGzipRequest{})
if err != nil {
return nil, err
}
sTreeBytes := []byte{}
for {
payload, err := schemaTreeGzipClient.Recv()
if err != nil {
if errors.Is(err, io.EOF) {
break
}
logrus.Error(err)
closeErr := schemaTreeGzipClient.CloseSend()
if closeErr != nil {
return nil, err
}
return nil, err
}
sTreeBytes = append(sTreeBytes, payload.Chunk...)
}
return sTreeBytes, nil
}
type DeviceModelServer struct { type DeviceModelServer struct {
Impl DeviceModel Impl DeviceModel
pb.UnimplementedPluginServer pb.UnimplementedPluginServer
......
package shared
type byteSize float64
// constants representing human friendly data sizes as per https://www.socketloop.com/tutorials/golang-how-to-declare-kilobyte-megabyte-gigabyte-terabyte-and-so-on
const (
_ = iota // ignore first value by assigning to blank identifier
KB byteSize = 1 << (10 * iota)
MB
)
...@@ -3,9 +3,11 @@ package store ...@@ -3,9 +3,11 @@ package store
const ( const (
// PndFilename is the name of the file where the pnds are stored. // PndFilename is the name of the file where the pnds are stored.
PndFilename string = "pndStore.json" PndFilename string = "pndStore.json"
// NetworkElementFilenameSuffix is the suffix of the file where the network elements are stored. // NetworkElementFilenameSuffix is the suffix of the file where the network
// elements are stored.
NetworkElementFilenameSuffix string = "networkElementStore.json" NetworkElementFilenameSuffix string = "networkElementStore.json"
// PluginFilenameSuffix is the suffix of the file where the sbis are stored. // PluginFilenameSuffix is the suffix of the file where the plugins are
// stored.
PluginFilenameSuffix string = "pluginStore.json" PluginFilenameSuffix string = "pluginStore.json"
// UserFilename is the name of the file where the users are stored. // UserFilename is the name of the file where the users are stored.
UserFilename string = "userStore.json" UserFilename string = "userStore.json"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment