Skip to content
Snippets Groups Projects
pndStore.go 1.21 KiB
Newer Older
  • Learn to ignore specific revisions
  • package nucleus
    
    import (
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain"
    	"code.fbi.h-da.de/danet/gosdn/controller/store"
    	"github.com/google/uuid"
    	log "github.com/sirupsen/logrus"
    )
    
    const (
    	pndStoreName = "pnd"
    )
    
    // LoadedPnd represents a Principal Network Domain that was loaeded by using
    // the Load() method of the PndStore.
    type LoadedPnd struct {
    	ID          string `json:"id" bson:"_id,omitempty"`
    	Name        string `json:"name,omitempty"`
    	Description string `json:"description,omitempty"`
    }
    
    // PndStore is used to store PrincipalNetworkDomains
    type PndStore struct {
    	pndStoreName    string
    	pendingChannels map[uuid.UUID]chan device.Details
    }
    
    // NewPndStore returns a PndStore
    func NewPndStore() networkdomain.PndStore {
    	storeMode := store.GetStoreMode()
    	log.Debugf("StoreMode: %s", storeMode)
    
    	switch storeMode {
    	case store.Filesystem:
    		store := NewMemoryPndStore()
    
    		return &store
    	case store.Database:
    
    		return &DatabasePndStore{
    
    			pendingChannels: make(map[uuid.UUID]chan device.Details),
    			pndStoreName:    "pnd-store.json"}
    	case store.Memory:
    		store := NewMemoryPndStore()
    
    		return &store
    	default:
    		return nil
    	}
    }