VOL-1900 lint warning fixes ro_core
Change-Id: I5ce82f2d188d215ba9620d0923a1101ed4e5e4a8
diff --git a/ro_core/config/config.go b/ro_core/config/config.go
index 03dedf2..5084130 100644
--- a/ro_core/config/config.go
+++ b/ro_core/config/config.go
@@ -13,44 +13,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package config
import (
"flag"
"fmt"
- "github.com/opencord/voltha-lib-go/v2/pkg/log"
"os"
"time"
+
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
)
// RO Core service default constants
const (
- ConsulStoreName = "consul"
- EtcdStoreName = "etcd"
- default_InstanceID = "rocore001"
- default_GrpcPort = 50057
- default_GrpcHost = ""
- default_KVStoreType = EtcdStoreName
- default_KVStoreTimeout = 5 //in seconds
- default_KVStoreHost = "127.0.0.1"
- default_KVStorePort = 2379 // Consul = 8500; Etcd = 2379
- default_KVTxnKeyDelTime = 60
- default_LogLevel = 0
- default_Banner = false
- default_DisplayVersionOnly = false
- default_CoreTopic = "rocore"
- default_ROCoreEndpoint = "rocore"
- default_ROCoreKey = "pki/voltha.key"
- default_ROCoreCert = "pki/voltha.crt"
- default_ROCoreCA = "pki/voltha-CA.pem"
- default_Affinity_Router_Topic = "affinityRouter"
- default_ProbeHost = ""
- default_ProbePort = 8080
- default_LiveProbeInterval = 60 * time.Second
- default_NotLiveProbeInterval = 5 * time.Second // Probe more frequently to detect Recovery early
- default_CoreTimeout = 59 * time.Second
- default_MaxConnectionRetries = -1 // retries forever
- default_ConnectionRetryInterval = 2 * time.Second // in seconds
+ ConsulStoreName = "consul"
+ EtcdStoreName = "etcd"
+ defaultInstanceID = "rocore001"
+ defaultGrpcPort = 50057
+ defaultGrpcHost = ""
+ defaultKVStoreType = EtcdStoreName
+ defaultKVStoreTimeout = 5 //in seconds
+ defaultKVStoreHost = "127.0.0.1"
+ defaultKVStorePort = 2379 // Consul = 8500; Etcd = 2379
+ defaultKVTxnKeyDelTime = 60
+ defaultLogLevel = 0
+ defaultBanner = false
+ defaultDisplayVersionOnly = false
+ defaultCoreTopic = "rocore"
+ defaultROCoreEndpoint = "rocore"
+ defaultROCoreKey = "pki/voltha.key"
+ defaultROCoreCert = "pki/voltha.crt"
+ defaultROCoreCA = "pki/voltha-CA.pem"
+ defaultAffinityRouterTopic = "affinityRouter"
+ defaultProbeHost = ""
+ defaultProbePort = 8080
+ defaultLiveProbeInterval = 60 * time.Second
+ defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently to detect Recovery early
+ defaultCoreTimeout = 59 * time.Second
+ defaultMaxConnectionRetries = -1 // retries forever
+ defaultConnectionRetryInterval = 2 * time.Second // in seconds
)
// ROCoreFlags represents the set of configurations used by the read-only core service
@@ -83,36 +85,39 @@
}
func init() {
- log.AddPackage(log.JSON, log.WarnLevel, nil)
+ _, err := log.AddPackage(log.JSON, log.WarnLevel, nil)
+ if err != nil {
+ log.Errorw("unable-to-register-package-to-the-log-map", log.Fields{"error": err})
+ }
}
// NewROCoreFlags returns a new ROCore config
func NewROCoreFlags() *ROCoreFlags {
var roCoreFlag = ROCoreFlags{ // Default values
- InstanceID: default_InstanceID,
- ROCoreEndpoint: default_ROCoreEndpoint,
- GrpcHost: default_GrpcHost,
- GrpcPort: default_GrpcPort,
- KVStoreType: default_KVStoreType,
- KVStoreTimeout: default_KVStoreTimeout,
- KVStoreHost: default_KVStoreHost,
- KVStorePort: default_KVStorePort,
- KVTxnKeyDelTime: default_KVTxnKeyDelTime,
- CoreTopic: default_CoreTopic,
- LogLevel: default_LogLevel,
- Banner: default_Banner,
- DisplayVersionOnly: default_DisplayVersionOnly,
- ROCoreKey: default_ROCoreKey,
- ROCoreCert: default_ROCoreCert,
- ROCoreCA: default_ROCoreCA,
- AffinityRouterTopic: default_Affinity_Router_Topic,
- ProbeHost: default_ProbeHost,
- ProbePort: default_ProbePort,
- LiveProbeInterval: default_LiveProbeInterval,
- NotLiveProbeInterval: default_NotLiveProbeInterval,
- CoreTimeout: default_CoreTimeout,
- MaxConnectionRetries: default_MaxConnectionRetries,
- ConnectionRetryInterval: default_ConnectionRetryInterval,
+ InstanceID: defaultInstanceID,
+ ROCoreEndpoint: defaultROCoreEndpoint,
+ GrpcHost: defaultGrpcHost,
+ GrpcPort: defaultGrpcPort,
+ KVStoreType: defaultKVStoreType,
+ KVStoreTimeout: defaultKVStoreTimeout,
+ KVStoreHost: defaultKVStoreHost,
+ KVStorePort: defaultKVStorePort,
+ KVTxnKeyDelTime: defaultKVTxnKeyDelTime,
+ CoreTopic: defaultCoreTopic,
+ LogLevel: defaultLogLevel,
+ Banner: defaultBanner,
+ DisplayVersionOnly: defaultDisplayVersionOnly,
+ ROCoreKey: defaultROCoreKey,
+ ROCoreCert: defaultROCoreCert,
+ ROCoreCA: defaultROCoreCA,
+ AffinityRouterTopic: defaultAffinityRouterTopic,
+ ProbeHost: defaultProbeHost,
+ ProbePort: defaultProbePort,
+ LiveProbeInterval: defaultLiveProbeInterval,
+ NotLiveProbeInterval: defaultNotLiveProbeInterval,
+ CoreTimeout: defaultCoreTimeout,
+ MaxConnectionRetries: defaultMaxConnectionRetries,
+ ConnectionRetryInterval: defaultConnectionRetryInterval,
}
return &roCoreFlag
}
@@ -120,67 +125,65 @@
// ParseCommandArguments parses the arguments when running read-only core service
func (cf *ROCoreFlags) ParseCommandArguments() {
- var help string
-
- help = fmt.Sprintf("RO core endpoint address")
- flag.StringVar(&(cf.ROCoreEndpoint), "vcore-endpoint", default_ROCoreEndpoint, help)
+ help := fmt.Sprintf("RO core endpoint address")
+ flag.StringVar(&(cf.ROCoreEndpoint), "vcore-endpoint", defaultROCoreEndpoint, help)
help = fmt.Sprintf("GRPC server - host")
- flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help)
+ flag.StringVar(&(cf.GrpcHost), "grpc_host", defaultGrpcHost, help)
help = fmt.Sprintf("GRPC server - port")
- flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help)
+ flag.IntVar(&(cf.GrpcPort), "grpc_port", defaultGrpcPort, help)
help = fmt.Sprintf("RO Core topic")
- flag.StringVar(&(cf.CoreTopic), "ro_core_topic", default_CoreTopic, help)
+ flag.StringVar(&(cf.CoreTopic), "ro_core_topic", defaultCoreTopic, help)
help = fmt.Sprintf("Affinity Router topic")
- flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", default_Affinity_Router_Topic, help)
+ flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", defaultAffinityRouterTopic, help)
help = fmt.Sprintf("KV store type")
- flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help)
+ flag.StringVar(&(cf.KVStoreType), "kv_store_type", defaultKVStoreType, help)
help = fmt.Sprintf("The default timeout when making a kv store request")
- flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
+ flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", defaultKVStoreTimeout, help)
help = fmt.Sprintf("KV store host")
- flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
+ flag.StringVar(&(cf.KVStoreHost), "kv_store_host", defaultKVStoreHost, help)
help = fmt.Sprintf("KV store port")
- flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help)
+ flag.IntVar(&(cf.KVStorePort), "kv_store_port", defaultKVStorePort, help)
help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
- flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", default_KVTxnKeyDelTime, help)
+ flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", defaultKVTxnKeyDelTime, help)
help = fmt.Sprintf("Log level")
- flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help)
+ flag.IntVar(&(cf.LogLevel), "log_level", defaultLogLevel, help)
help = fmt.Sprintf("Show startup banner log lines")
- flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
+ flag.BoolVar(&cf.Banner, "banner", defaultBanner, help)
help = fmt.Sprintf("Show version information and exit")
- flag.BoolVar(&cf.DisplayVersionOnly, "version", default_DisplayVersionOnly, help)
+ flag.BoolVar(&cf.DisplayVersionOnly, "version", defaultDisplayVersionOnly, help)
help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
- flag.StringVar(&(cf.ProbeHost), "probe_host", default_ProbeHost, help)
+ flag.StringVar(&(cf.ProbeHost), "probe_host", defaultProbeHost, help)
help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
- flag.IntVar(&(cf.ProbePort), "probe_port", default_ProbePort, help)
+ flag.IntVar(&(cf.ProbePort), "probe_port", defaultProbePort, help)
help = fmt.Sprintf("Time interval between liveness probes while in a live state")
- flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", default_LiveProbeInterval, help)
+ flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
help = fmt.Sprintf("Time interval between liveness probes while in a not live state")
- flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", default_NotLiveProbeInterval, help)
+ flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
help = fmt.Sprintf("The maximum time the core will wait while attempting to connect to a dependent component duration")
- flag.DurationVar(&(cf.CoreTimeout), "core_timeout", default_CoreTimeout, help)
+ flag.DurationVar(&(cf.CoreTimeout), "core_timeout", defaultCoreTimeout, help)
help = fmt.Sprintf("The number of retries to connect to a dependent component")
- flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", default_MaxConnectionRetries, help)
+ flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", defaultMaxConnectionRetries, help)
help = fmt.Sprintf("The duration between each connection retry attempt ")
- flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", default_ConnectionRetryInterval, help)
+ flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", defaultConnectionRetryInterval, help)
flag.Parse()
diff --git a/ro_core/config/config_test.go b/ro_core/config/config_test.go
index c1dbc9a..2ebcfbb 100644
--- a/ro_core/config/config_test.go
+++ b/ro_core/config/config_test.go
@@ -33,13 +33,13 @@
* useful.
*/
- VOLTHA_LOGLEVEL = log.FatalLevel
+ VOLTHALogLevel = log.FatalLevel
)
func localInit() {
// Logger must be configured or bad things happen
- _, err := log.SetDefaultLogger(log.JSON, VOLTHA_LOGLEVEL, log.Fields{"instanceId": 1})
+ _, err := log.SetDefaultLogger(log.JSON, VOLTHALogLevel, log.Fields{"instanceId": 1})
if err != nil {
panic(err)
}
@@ -47,59 +47,59 @@
func checkConfigFlags(t *testing.T, cf *ROCoreFlags) {
- if cf.ROCoreEndpoint != default_ROCoreEndpoint {
- t.Errorf("ROCoreEndpoint want %s, got %s", default_ROCoreEndpoint, cf.ROCoreEndpoint)
+ if cf.ROCoreEndpoint != defaultROCoreEndpoint {
+ t.Errorf("ROCoreEndpoint want %s, got %s", defaultROCoreEndpoint, cf.ROCoreEndpoint)
}
- if cf.GrpcHost != default_GrpcHost {
- t.Errorf("GrpcHost want %s, got %s", default_GrpcHost, cf.GrpcHost)
+ if cf.GrpcHost != defaultGrpcHost {
+ t.Errorf("GrpcHost want %s, got %s", defaultGrpcHost, cf.GrpcHost)
}
- if cf.GrpcPort != default_GrpcPort {
- t.Errorf("GrpcPort want %d, got %d", default_GrpcPort, cf.GrpcPort)
+ if cf.GrpcPort != defaultGrpcPort {
+ t.Errorf("GrpcPort want %d, got %d", defaultGrpcPort, cf.GrpcPort)
}
- if cf.KVStoreType != default_KVStoreType {
- t.Errorf("KVStoreType want %s, got %s", default_KVStoreType, cf.KVStoreType)
+ if cf.KVStoreType != defaultKVStoreType {
+ t.Errorf("KVStoreType want %s, got %s", defaultKVStoreType, cf.KVStoreType)
}
- if cf.KVStoreTimeout != default_KVStoreTimeout {
- t.Errorf("KVStoreTimeout want %d, got %d", default_KVStoreTimeout, cf.KVStoreTimeout)
+ if cf.KVStoreTimeout != defaultKVStoreTimeout {
+ t.Errorf("KVStoreTimeout want %d, got %d", defaultKVStoreTimeout, cf.KVStoreTimeout)
}
- if cf.KVStoreHost != default_KVStoreHost {
- t.Errorf("KVStoreHost want %s, got %s", default_KVStoreHost, cf.KVStoreHost)
+ if cf.KVStoreHost != defaultKVStoreHost {
+ t.Errorf("KVStoreHost want %s, got %s", defaultKVStoreHost, cf.KVStoreHost)
}
- if cf.KVStorePort != default_KVStorePort {
- t.Errorf("KVStorePort want %d, got %d", default_KVStorePort, cf.KVStorePort)
+ if cf.KVStorePort != defaultKVStorePort {
+ t.Errorf("KVStorePort want %d, got %d", defaultKVStorePort, cf.KVStorePort)
}
- if cf.KVTxnKeyDelTime != default_KVTxnKeyDelTime {
- t.Errorf("KVTxnKeyDelTime want %d, got %d", default_KVTxnKeyDelTime, cf.KVTxnKeyDelTime)
+ if cf.KVTxnKeyDelTime != defaultKVTxnKeyDelTime {
+ t.Errorf("KVTxnKeyDelTime want %d, got %d", defaultKVTxnKeyDelTime, cf.KVTxnKeyDelTime)
}
- if cf.CoreTopic != default_CoreTopic {
- t.Errorf("CoreTopic want %s, got %s", default_CoreTopic, cf.CoreTopic)
+ if cf.CoreTopic != defaultCoreTopic {
+ t.Errorf("CoreTopic want %s, got %s", defaultCoreTopic, cf.CoreTopic)
}
- if cf.LogLevel != default_LogLevel {
- t.Errorf("LogLevel want %d, got %d", default_LogLevel, cf.LogLevel)
+ if cf.LogLevel != defaultLogLevel {
+ t.Errorf("LogLevel want %d, got %d", defaultLogLevel, cf.LogLevel)
}
- if cf.Banner != default_Banner {
- t.Errorf("Banner want %v, got %v", default_Banner, cf.Banner)
+ if cf.Banner != defaultBanner {
+ t.Errorf("Banner want %v, got %v", defaultBanner, cf.Banner)
}
- if cf.DisplayVersionOnly != default_DisplayVersionOnly {
- t.Errorf("DisplayVersionOnly want %v, got %v", default_DisplayVersionOnly, cf.DisplayVersionOnly)
+ if cf.DisplayVersionOnly != defaultDisplayVersionOnly {
+ t.Errorf("DisplayVersionOnly want %v, got %v", defaultDisplayVersionOnly, cf.DisplayVersionOnly)
}
- if cf.ROCoreKey != default_ROCoreKey {
- t.Errorf("ROCoreKey want %s, got %s", default_ROCoreKey, cf.ROCoreKey)
+ if cf.ROCoreKey != defaultROCoreKey {
+ t.Errorf("ROCoreKey want %s, got %s", defaultROCoreKey, cf.ROCoreKey)
}
- if cf.ROCoreCert != default_ROCoreCert {
- t.Errorf("ROCoreCert want %s, got %s", default_ROCoreCert, cf.ROCoreCert)
+ if cf.ROCoreCert != defaultROCoreCert {
+ t.Errorf("ROCoreCert want %s, got %s", defaultROCoreCert, cf.ROCoreCert)
}
- if cf.ROCoreCA != default_ROCoreCA {
- t.Errorf("ROCoreCA want %s, got %s", default_ROCoreCA, cf.ROCoreCA)
+ if cf.ROCoreCA != defaultROCoreCA {
+ t.Errorf("ROCoreCA want %s, got %s", defaultROCoreCA, cf.ROCoreCA)
}
- if cf.AffinityRouterTopic != default_Affinity_Router_Topic {
- t.Errorf("AffinityRouterTopic want %s, got %s", default_Affinity_Router_Topic, cf.AffinityRouterTopic)
+ if cf.AffinityRouterTopic != defaultAffinityRouterTopic {
+ t.Errorf("AffinityRouterTopic want %s, got %s", defaultAffinityRouterTopic, cf.AffinityRouterTopic)
}
- if cf.ProbeHost != default_ProbeHost {
- t.Errorf("ProbeHost want %s, got %s", default_ProbeHost, cf.ProbeHost)
+ if cf.ProbeHost != defaultProbeHost {
+ t.Errorf("ProbeHost want %s, got %s", defaultProbeHost, cf.ProbeHost)
}
- if cf.ProbePort != default_ProbePort {
- t.Errorf("ProbePort want %d, got %d", default_ProbePort, cf.ProbePort)
+ if cf.ProbePort != defaultProbePort {
+ t.Errorf("ProbePort want %d, got %d", defaultProbePort, cf.ProbePort)
}
}
diff --git a/ro_core/core/common_test.go b/ro_core/core/common_test.go
index 9bef64f..bf7c7c1 100644
--- a/ro_core/core/common_test.go
+++ b/ro_core/core/common_test.go
@@ -30,14 +30,14 @@
* useful.
*/
- VOLTHA_LOGLEVEL = log.FatalLevel
+ VolthaLogLevel = log.FatalLevel
)
// Unit test initialization. This init() function handles all unit tests in
// the current directory.
func init() {
// Logger must be configured or bad things happen
- _, err := log.SetDefaultLogger(log.JSON, VOLTHA_LOGLEVEL, log.Fields{"instanceId": 1})
+ _, err := log.SetDefaultLogger(log.JSON, VolthaLogLevel, log.Fields{"instanceID": 1})
if err != nil {
panic(err)
}
diff --git a/ro_core/core/core.go b/ro_core/core/core.go
index 797c05a..da9fead 100644
--- a/ro_core/core/core.go
+++ b/ro_core/core/core.go
@@ -13,10 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
+
+ "time"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-go/ro_core/config"
"github.com/opencord/voltha-lib-go/v2/pkg/db"
@@ -28,11 +32,11 @@
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "time"
)
+// Core holds all information of read only core service
type Core struct {
- instanceId string
+ instanceID string
genericMgr *ModelProxyManager
deviceMgr *DeviceManager
logicalDeviceMgr *LogicalDeviceManager
@@ -49,12 +53,16 @@
}
func init() {
- log.AddPackage(log.JSON, log.DebugLevel, nil)
+ _, err := log.AddPackage(log.JSON, log.DebugLevel, nil)
+ if err != nil {
+ log.Errorw("unable-to-register-package-to-the-log-map", log.Fields{"error": err})
+ }
}
+// NewCore instantiates core service parameters
func NewCore(id string, cf *config.ROCoreFlags, kvClient kvstore.Client) *Core {
var core Core
- core.instanceId = id
+ core.instanceID = id
core.exitChannel = make(chan int, 1)
core.config = cf
core.kvClient = kvClient
@@ -101,7 +109,7 @@
return status.Error(codes.Unavailable, "kv store unreachable")
}
}
- count += 1
+ count++
// Take a nap before retrying
time.Sleep(retryInterval)
log.Infow("retry-KV-store-connectivity", log.Fields{"retryCount": count, "maxRetries": maxRetries, "retryInterval": retryInterval})
@@ -114,8 +122,9 @@
return nil
}
+// Start will start core adapter services
func (core *Core) Start(ctx context.Context) {
- log.Info("starting-adaptercore", log.Fields{"coreId": core.instanceId})
+ log.Info("starting-adaptercore", log.Fields{"coreId": core.instanceID})
// Wait until connection to KV Store is up
if err := core.waitUntilKVStoreReachableOrMaxTries(ctx, core.config.MaxConnectionRetries, core.config.ConnectionRetryInterval); err != nil {
@@ -125,7 +134,7 @@
probe.UpdateStatusFromContext(ctx, "kv-store", probe.ServiceStatusRunning)
core.genericMgr = newModelProxyManager(core.clusterDataProxy)
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
core.logicalDeviceMgr = newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy)
go core.startDeviceManager(ctx)
go core.startLogicalDeviceManager(ctx)
@@ -135,6 +144,7 @@
log.Info("adaptercore-started")
}
+// Stop will stop core services
func (core *Core) Stop(ctx context.Context) {
log.Info("stopping-adaptercore")
if core.exitChannel != nil {
diff --git a/ro_core/core/core_test.go b/ro_core/core/core_test.go
index 88bd561..d88a7de 100644
--- a/ro_core/core/core_test.go
+++ b/ro_core/core/core_test.go
@@ -19,15 +19,15 @@
"context"
"errors"
"fmt"
+ "testing"
+
"github.com/opencord/voltha-go/ro_core/config"
"github.com/opencord/voltha-lib-go/v2/pkg/db/kvstore"
- grpcserver "github.com/opencord/voltha-lib-go/v2/pkg/grpc"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-lib-go/v2/pkg/mocks"
ic "github.com/opencord/voltha-protos/v2/go/inter_container"
"github.com/phayes/freeport"
"github.com/stretchr/testify/assert"
- "testing"
)
type roCore struct {
@@ -35,8 +35,6 @@
config *config.ROCoreFlags
halted bool
exitChannel chan int
- grpcServer *grpcserver.GrpcServer
- core *Core
//For test
receiverChannels []<-chan *ic.InterContainerMessage
}
@@ -62,7 +60,7 @@
return nil, errors.New("unsupported-kv-store")
}
-func MakeTestNewCore() (*config.ROCoreFlags, *roCore) {
+func makeTestNewCore() (*config.ROCoreFlags, *roCore) {
clientPort, err := freeport.GetFreePort()
if err == nil {
@@ -84,11 +82,8 @@
roC.kvClient = cli
return roCoreFlgs, roC
}
- if err != nil {
- etcdServer.Stop()
- log.Fatal("Failed to create an Etcd client")
- }
-
+ etcdServer.Stop()
+ log.Fatal("Failed to create an Etcd client")
}
}
return nil, nil
@@ -96,7 +91,7 @@
func TestNewCore(t *testing.T) {
- roCoreFlgs, roC := MakeTestNewCore()
+ roCoreFlgs, roC := makeTestNewCore()
assert.NotNil(t, roCoreFlgs)
assert.NotNil(t, roC)
core := NewCore("ro_core", roCoreFlgs, roC.kvClient)
@@ -107,7 +102,7 @@
var ctx context.Context
- roCoreFlgs, roC := MakeTestNewCore()
+ roCoreFlgs, roC := makeTestNewCore()
assert.NotNil(t, roCoreFlgs)
assert.NotNil(t, roC)
core := NewCore("ro_core", roCoreFlgs, roC.kvClient)
diff --git a/ro_core/core/device_agent.go b/ro_core/core/device_agent.go
index 63af020..345e424 100644
--- a/ro_core/core/device_agent.go
+++ b/ro_core/core/device_agent.go
@@ -13,21 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
+ "sync"
+
"github.com/gogo/protobuf/proto"
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/voltha"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "sync"
)
+// DeviceAgent holds device specific information
type DeviceAgent struct {
- deviceId string
+ deviceID string
deviceType string
lastData *voltha.Device
deviceMgr *DeviceManager
@@ -40,7 +43,7 @@
//preprovisioning
func newDeviceAgent(device *voltha.Device, deviceMgr *DeviceManager, cdProxy *model.Proxy) *DeviceAgent {
var agent DeviceAgent
- agent.deviceId = device.Id
+ agent.deviceID = device.Id
agent.deviceType = device.Type
agent.lastData = device
agent.deviceMgr = deviceMgr
@@ -56,13 +59,13 @@
defer agent.lockDevice.Unlock()
log.Debugw("starting-device-agent", log.Fields{"device": agent.lastData})
if loadFromDb {
- if device := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceId, 0, false, ""); device != nil {
+ if device := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceID, 0, false, ""); device != nil {
if d, ok := device.(*voltha.Device); ok {
agent.lastData = proto.Clone(d).(*voltha.Device)
}
} else {
- log.Errorw("failed-to-load-device", log.Fields{"deviceId": agent.deviceId})
- return status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ log.Errorw("failed-to-load-device", log.Fields{"deviceID": agent.deviceID})
+ return status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
log.Debugw("device-loaded-from-dB", log.Fields{"device": agent.lastData})
}
@@ -83,123 +86,95 @@
func (agent *DeviceAgent) getDevice() (*voltha.Device, error) {
agent.lockDevice.Lock()
defer agent.lockDevice.Unlock()
- if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceId, 0, false, ""); device != nil {
+ if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 0, false, ""); device != nil {
if d, ok := device.(*voltha.Device); ok {
cloned := proto.Clone(d).(*voltha.Device)
return cloned, nil
}
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
-}
-
-// getDeviceWithoutLock is a helper function to be used ONLY by any device agent function AFTER it has acquired the device lock.
-// This function is meant so that we do not have duplicate code all over the device agent functions
-func (agent *DeviceAgent) getDeviceWithoutLock() (*voltha.Device, error) {
- if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceId, 0, false, ""); device != nil {
- if d, ok := device.(*voltha.Device); ok {
- cloned := proto.Clone(d).(*voltha.Device)
- return cloned, nil
- }
- }
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
-}
-
-// getPorts retrieves the ports information of the device based on the port type.
-func (agent *DeviceAgent) getPorts(ctx context.Context, portType voltha.Port_PortType) *voltha.Ports {
- log.Debugw("getPorts", log.Fields{"id": agent.deviceId, "portType": portType})
- ports := &voltha.Ports{}
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
- for _, port := range device.Ports {
- if port.Type == portType {
- ports.Items = append(ports.Items, port)
- }
- }
- }
- return ports
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// ListDevicePorts retrieves the ports information for a particular device.
func (agent *DeviceAgent) ListDevicePorts(ctx context.Context) (*voltha.Ports, error) {
- log.Debugw("ListDevicePorts", log.Fields{"id": agent.deviceId})
+ log.Debugw("ListDevicePorts", log.Fields{"id": agent.deviceID})
ports := &voltha.Ports{}
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
- for _, entry := range device.GetPorts() {
- ports.Items = append(ports.Items, entry)
- }
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
+ ports.Items = append(ports.Items, device.GetPorts()...)
return ports, nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// ListDevicePmConfigs retrieves the ports information for a particular device.
func (agent *DeviceAgent) ListDevicePmConfigs(ctx context.Context) (*voltha.PmConfigs, error) {
- log.Debugw("ListDevicePmConfigs", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("ListDevicePmConfigs", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return device.GetPmConfigs(), nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// ListDeviceFlows retrieves the ports information for a particular device.
func (agent *DeviceAgent) ListDeviceFlows(ctx context.Context) (*voltha.Flows, error) {
- log.Debugw("ListDeviceFlows", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("ListDeviceFlows", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return device.GetFlows(), nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
-// ListDeviceFlows retrieves the ports information for a particular device.
+// ListDeviceFlowGroups retrieves the ports information for a particular device.
func (agent *DeviceAgent) ListDeviceFlowGroups(ctx context.Context) (*voltha.FlowGroups, error) {
- log.Debugw("ListDeviceFlowGroups", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("ListDeviceFlowGroups", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return device.GetFlowGroups(), nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// GetImageDownloadStatus retrieves the download status of an image of a particular device.
func (agent *DeviceAgent) GetImageDownloadStatus(ctx context.Context, imageName string) (*voltha.ImageDownload, error) {
- log.Debugw("GetImageDownloadStatus", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("GetImageDownloadStatus", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
for _, img := range device.GetImageDownloads() {
if img.GetName() == imageName {
return img, nil
}
}
- return nil, status.Errorf(codes.NotFound, "device-%s, image-%s", agent.deviceId, imageName)
+ return nil, status.Errorf(codes.NotFound, "device-%s, image-%s", agent.deviceID, imageName)
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// GetImageDownload retrieves the image download for a particular device.
func (agent *DeviceAgent) GetImageDownload(ctx context.Context, imageName string) (*voltha.ImageDownload, error) {
- log.Debugw("GetImageDownload", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("GetImageDownload", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
for _, img := range device.GetImageDownloads() {
if img.GetName() == imageName {
return img, nil
}
}
- return nil, status.Errorf(codes.NotFound, "device-%s, image-%s", agent.deviceId, imageName)
+ return nil, status.Errorf(codes.NotFound, "device-%s, image-%s", agent.deviceID, imageName)
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// ListImageDownloads retrieves the image downloads for a particular device.
func (agent *DeviceAgent) ListImageDownloads(ctx context.Context) (*voltha.ImageDownloads, error) {
- log.Debugw("ListImageDownloads", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("ListImageDownloads", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return &voltha.ImageDownloads{Items: device.GetImageDownloads()}, nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// GetImages retrieves the list of images for a particular device.
func (agent *DeviceAgent) GetImages(ctx context.Context) (*voltha.Images, error) {
- log.Debugw("GetImages", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("GetImages", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return device.GetImages(), nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
diff --git a/ro_core/core/device_agent_test.go b/ro_core/core/device_agent_test.go
index bb87fac..246737f 100644
--- a/ro_core/core/device_agent_test.go
+++ b/ro_core/core/device_agent_test.go
@@ -16,18 +16,19 @@
package core
import (
+ "testing"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-go/ro_core/config"
"github.com/opencord/voltha-lib-go/v2/pkg/db"
"github.com/opencord/voltha-protos/v2/go/voltha"
"github.com/stretchr/testify/assert"
- "testing"
)
func TestNewDeviceAgent(t *testing.T) {
var core Core
- core.instanceId = "ro_core"
+ core.instanceID = "ro_core"
core.config = config.NewROCoreFlags()
backend := db.Backend{
Client: core.kvClient,
@@ -38,7 +39,7 @@
PathPrefix: "service/voltha"}
core.clusterDataRoot = model.NewRoot(&voltha.Voltha{}, &backend)
core.genericMgr = newModelProxyManager(core.clusterDataProxy)
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
devAgent := newDeviceAgent(&voltha.Device{Id: "new_device"}, core.deviceMgr, core.clusterDataProxy)
assert.NotNil(t, devAgent)
diff --git a/ro_core/core/device_manager.go b/ro_core/core/device_manager.go
index fd69705..634566c 100644
--- a/ro_core/core/device_manager.go
+++ b/ro_core/core/device_manager.go
@@ -13,31 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
+ "sync"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-lib-go/v2/pkg/probe"
"github.com/opencord/voltha-protos/v2/go/voltha"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "sync"
)
+// DeviceManager represents device manager related information
type DeviceManager struct {
deviceAgents sync.Map
logicalDeviceMgr *LogicalDeviceManager
clusterDataProxy *model.Proxy
- coreInstanceId string
+ coreInstanceID string
exitChannel chan int
}
-func newDeviceManager(cdProxy *model.Proxy, coreInstanceId string) *DeviceManager {
+func newDeviceManager(cdProxy *model.Proxy, coreInstanceID string) *DeviceManager {
var deviceMgr DeviceManager
deviceMgr.exitChannel = make(chan int, 1)
- deviceMgr.coreInstanceId = coreInstanceId
+ deviceMgr.coreInstanceID = coreInstanceID
deviceMgr.clusterDataProxy = cdProxy
return &deviceMgr
}
@@ -69,31 +72,30 @@
}
func (dMgr *DeviceManager) addDeviceAgentToMap(agent *DeviceAgent) {
- if _, exist := dMgr.deviceAgents.Load(agent.deviceId); !exist {
- dMgr.deviceAgents.Store(agent.deviceId, agent)
+ if _, exist := dMgr.deviceAgents.Load(agent.deviceID); !exist {
+ dMgr.deviceAgents.Store(agent.deviceID, agent)
}
}
func (dMgr *DeviceManager) deleteDeviceAgentToMap(agent *DeviceAgent) {
- dMgr.deviceAgents.Delete(agent.deviceId)
+ dMgr.deviceAgents.Delete(agent.deviceID)
}
-func (dMgr *DeviceManager) getDeviceAgent(deviceId string) *DeviceAgent {
- if agent, ok := dMgr.deviceAgents.Load(deviceId); ok {
+func (dMgr *DeviceManager) getDeviceAgent(deviceID string) *DeviceAgent {
+ if agent, ok := dMgr.deviceAgents.Load(deviceID); ok {
return agent.(*DeviceAgent)
- } else {
- // Try to load into memory - loading will also create the device agent
- if err := dMgr.load(deviceId); err == nil {
- if agent, ok = dMgr.deviceAgents.Load(deviceId); ok {
- return agent.(*DeviceAgent)
- }
+ }
+ // Try to load into memory - loading will also create the device agent
+ if err := dMgr.load(deviceID); err == nil {
+ if agent, ok := dMgr.deviceAgents.Load(deviceID); ok {
+ return agent.(*DeviceAgent)
}
}
return nil
}
-// listDeviceIdsFromMap returns the list of device IDs that are in memory
-func (dMgr *DeviceManager) listDeviceIdsFromMap() *voltha.IDs {
+// listDeviceIDsFromMap returns the list of device IDs that are in memory
+func (dMgr *DeviceManager) listDeviceIDsFromMap() *voltha.IDs {
result := &voltha.IDs{Items: make([]*voltha.ID, 0)}
dMgr.deviceAgents.Range(func(key, value interface{}) bool {
result.Items = append(result.Items, &voltha.ID{Id: key.(string)})
@@ -111,11 +113,13 @@
return nil, status.Errorf(codes.NotFound, "%s", id)
}
+// IsDeviceInCache returns true if device exists in cache
func (dMgr *DeviceManager) IsDeviceInCache(id string) bool {
_, exist := dMgr.deviceAgents.Load(id)
return exist
}
+// IsRootDevice returns true if root device is present in either memory or db
func (dMgr *DeviceManager) IsRootDevice(id string) (bool, error) {
device, err := dMgr.GetDevice(id)
if err != nil {
@@ -133,9 +137,9 @@
// If device is not in memory then set it up
if !dMgr.IsDeviceInCache(device.(*voltha.Device).Id) {
agent := newDeviceAgent(device.(*voltha.Device), dMgr, dMgr.clusterDataProxy)
- if err := agent.start(nil, true); err != nil {
- log.Warnw("failure-starting-agent", log.Fields{"deviceId": device.(*voltha.Device).Id})
- agent.stop(nil)
+ if err := agent.start(context.TODO(), true); err != nil {
+ log.Warnw("failure-starting-agent", log.Fields{"deviceID": device.(*voltha.Device).Id})
+ agent.stop(context.TODO())
} else {
dMgr.addDeviceAgentToMap(agent)
}
@@ -146,67 +150,67 @@
return result, nil
}
-// loadDevice loads the deviceId in memory, if not present
-func (dMgr *DeviceManager) loadDevice(deviceId string) (*DeviceAgent, error) {
- log.Debugw("loading-device", log.Fields{"deviceId": deviceId})
+// loadDevice loads the deviceID in memory, if not present
+func (dMgr *DeviceManager) loadDevice(deviceID string) (*DeviceAgent, error) {
+ log.Debugw("loading-device", log.Fields{"deviceID": deviceID})
// Sanity check
- if deviceId == "" {
- return nil, status.Error(codes.InvalidArgument, "deviceId empty")
+ if deviceID == "" {
+ return nil, status.Error(codes.InvalidArgument, "deviceID empty")
}
- if !dMgr.IsDeviceInCache(deviceId) {
- agent := newDeviceAgent(&voltha.Device{Id: deviceId}, dMgr, dMgr.clusterDataProxy)
- if err := agent.start(nil, true); err != nil {
- agent.stop(nil)
+ if !dMgr.IsDeviceInCache(deviceID) {
+ agent := newDeviceAgent(&voltha.Device{Id: deviceID}, dMgr, dMgr.clusterDataProxy)
+ if err := agent.start(context.TODO(), true); err != nil {
+ agent.stop(context.TODO())
return nil, err
}
dMgr.addDeviceAgentToMap(agent)
}
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent, nil
}
- return nil, status.Error(codes.NotFound, deviceId) // This should nto happen
+ return nil, status.Error(codes.NotFound, deviceID) // This should nto happen
}
// loadRootDeviceParentAndChildren loads the children and parents of a root device in memory
func (dMgr *DeviceManager) loadRootDeviceParentAndChildren(device *voltha.Device) error {
- log.Debugw("loading-parent-and-children", log.Fields{"deviceId": device.Id})
+ log.Debugw("loading-parent-and-children", log.Fields{"deviceID": device.Id})
if device.Root {
// Scenario A
if device.ParentId != "" {
// Load logical device if needed.
if err := dMgr.logicalDeviceMgr.load(device.ParentId); err != nil {
- log.Warnw("failure-loading-logical-device", log.Fields{"lDeviceId": device.ParentId})
+ log.Warnw("failure-loading-logical-device", log.Fields{"lDeviceID": device.ParentId})
}
} else {
- log.Debugw("no-parent-to-load", log.Fields{"deviceId": device.Id})
+ log.Debugw("no-parent-to-load", log.Fields{"deviceID": device.Id})
}
// Load all child devices, if needed
- if childDeviceIds, err := dMgr.getAllChildDeviceIds(device); err == nil {
- for _, childDeviceId := range childDeviceIds {
- if _, err := dMgr.loadDevice(childDeviceId); err != nil {
- log.Warnw("failure-loading-device", log.Fields{"deviceId": childDeviceId})
+ if childDeviceIDs, err := dMgr.getAllChildDeviceIDs(device); err == nil {
+ for _, childDeviceID := range childDeviceIDs {
+ if _, err := dMgr.loadDevice(childDeviceID); err != nil {
+ log.Warnw("failure-loading-device", log.Fields{"deviceID": childDeviceID})
return err
}
}
- log.Debugw("loaded-children", log.Fields{"deviceId": device.Id, "numChildren": len(childDeviceIds)})
+ log.Debugw("loaded-children", log.Fields{"deviceID": device.Id, "numChildren": len(childDeviceIDs)})
} else {
- log.Debugw("no-child-to-load", log.Fields{"deviceId": device.Id})
+ log.Debugw("no-child-to-load", log.Fields{"deviceID": device.Id})
}
}
return nil
}
-// load loads the deviceId in memory, if not present, and also loads its accompanying parents and children. Loading
+// load loads the deviceID in memory, if not present, and also loads its accompanying parents and children. Loading
// in memory is for improved performance. It is not imperative that a device needs to be in memory when a request
// acting on the device is received by the core. In such a scenario, the Core will load the device in memory first
// and the proceed with the request.
-func (dMgr *DeviceManager) load(deviceId string) error {
+func (dMgr *DeviceManager) load(deviceID string) error {
log.Debug("load...")
// First load the device - this may fail in case the device was deleted intentionally by the other core
var dAgent *DeviceAgent
var err error
- if dAgent, err = dMgr.loadDevice(deviceId); err != nil {
- log.Warnw("failure-loading-device", log.Fields{"deviceId": deviceId})
+ if dAgent, err = dMgr.loadDevice(deviceID); err != nil {
+ log.Warnw("failure-loading-device", log.Fields{"deviceID": deviceID})
return err
}
// Get the loaded device details
@@ -224,12 +228,12 @@
if device.Root {
// Load all children as well as the parent of this device (logical_device)
if err := dMgr.loadRootDeviceParentAndChildren(device); err != nil {
- log.Warnw("failure-loading-device-parent-and-children", log.Fields{"deviceId": deviceId})
+ log.Warnw("failure-loading-device-parent-and-children", log.Fields{"deviceID": deviceID})
return err
}
- log.Debugw("successfully-loaded-parent-and-children", log.Fields{"deviceId": deviceId})
+ log.Debugw("successfully-loaded-parent-and-children", log.Fields{"deviceID": deviceID})
} else {
- // Scenario B - use the parentId of that device (root device) to trigger the loading
+ // Scenario B - use the parentID of that device (root device) to trigger the loading
if device.ParentId != "" {
return dMgr.load(device.ParentId)
}
@@ -237,11 +241,11 @@
return nil
}
-// ListDeviceIds retrieves the latest device IDs information from the data model (memory data only)
-func (dMgr *DeviceManager) ListDeviceIds() (*voltha.IDs, error) {
+// ListDeviceIDs retrieves the latest device IDs information from the data model (memory data only)
+func (dMgr *DeviceManager) ListDeviceIDs() (*voltha.IDs, error) {
log.Debug("ListDeviceIDs")
// Report only device IDs that are in the device agent map
- return dMgr.listDeviceIdsFromMap(), nil
+ return dMgr.listDeviceIDsFromMap(), nil
}
//ReconcileDevices is a request to a voltha core to managed a list of devices based on their IDs
@@ -254,19 +258,19 @@
for _, id := range ids.Items {
// Act on the device only if its not present in the agent map
if !dMgr.IsDeviceInCache(id.Id) {
- // Device Id not in memory
+ // Device ID not in memory
log.Debugw("reconciling-device", log.Fields{"id": id.Id})
// Load device from dB
agent := newDeviceAgent(&voltha.Device{Id: id.Id}, dMgr, dMgr.clusterDataProxy)
- if err := agent.start(nil, true); err != nil {
- log.Warnw("failure-loading-device", log.Fields{"deviceId": id.Id})
- agent.stop(nil)
+ if err := agent.start(context.TODO(), true); err != nil {
+ log.Warnw("failure-loading-device", log.Fields{"deviceID": id.Id})
+ agent.stop(context.TODO())
} else {
dMgr.addDeviceAgentToMap(agent)
- reconciled += 1
+ reconciled++
}
} else {
- reconciled += 1
+ reconciled++
}
}
if toReconcile != reconciled {
@@ -278,83 +282,82 @@
sendResponse(ctx, ch, res)
}
-func (dMgr *DeviceManager) getPorts(ctx context.Context, deviceId string, portType voltha.Port_PortType) (*voltha.Ports, error) {
- log.Debugw("getPorts", log.Fields{"deviceid": deviceId, "portType": portType})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
- return agent.getPorts(ctx, portType), nil
- }
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
-
-}
-
-func (dMgr *DeviceManager) ListDevicePorts(ctx context.Context, deviceId string) (*voltha.Ports, error) {
- log.Debugw("ListDevicePorts", log.Fields{"deviceid": deviceId})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListDevicePorts returns ports details for a specific device
+func (dMgr *DeviceManager) ListDevicePorts(ctx context.Context, deviceID string) (*voltha.Ports, error) {
+ log.Debugw("ListDevicePorts", log.Fields{"deviceid": deviceID})
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent.ListDevicePorts(ctx)
}
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+ return nil, status.Errorf(codes.NotFound, "%s", deviceID)
}
-func (dMgr *DeviceManager) ListDevicePmConfigs(ctx context.Context, deviceId string) (*voltha.PmConfigs, error) {
- log.Debugw("ListDevicePmConfigs", log.Fields{"deviceid": deviceId})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListDevicePmConfigs returns PM config details for a specific device
+func (dMgr *DeviceManager) ListDevicePmConfigs(ctx context.Context, deviceID string) (*voltha.PmConfigs, error) {
+ log.Debugw("ListDevicePmConfigs", log.Fields{"deviceid": deviceID})
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent.ListDevicePmConfigs(ctx)
}
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+ return nil, status.Errorf(codes.NotFound, "%s", deviceID)
}
-func (dMgr *DeviceManager) ListDeviceFlows(ctx context.Context, deviceId string) (*voltha.Flows, error) {
- log.Debugw("ListDeviceFlows", log.Fields{"deviceid": deviceId})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListDeviceFlows returns flow details for a specific device
+func (dMgr *DeviceManager) ListDeviceFlows(ctx context.Context, deviceID string) (*voltha.Flows, error) {
+ log.Debugw("ListDeviceFlows", log.Fields{"deviceid": deviceID})
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent.ListDeviceFlows(ctx)
}
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+ return nil, status.Errorf(codes.NotFound, "%s", deviceID)
}
-func (dMgr *DeviceManager) ListDeviceFlowGroups(ctx context.Context, deviceId string) (*voltha.FlowGroups, error) {
- log.Debugw("ListDeviceFlowGroups", log.Fields{"deviceid": deviceId})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListDeviceFlowGroups returns flow group details for a specific device
+func (dMgr *DeviceManager) ListDeviceFlowGroups(ctx context.Context, deviceID string) (*voltha.FlowGroups, error) {
+ log.Debugw("ListDeviceFlowGroups", log.Fields{"deviceid": deviceID})
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent.ListDeviceFlowGroups(ctx)
}
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+ return nil, status.Errorf(codes.NotFound, "%s", deviceID)
}
-func (dMgr *DeviceManager) GetImageDownloadStatus(ctx context.Context, deviceId string, imageName string) (*voltha.ImageDownload, error) {
- log.Debugw("GetImageDownloadStatus", log.Fields{"deviceid": deviceId, "imagename": imageName})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// GetImageDownloadStatus returns the download status of an image of a particular device
+func (dMgr *DeviceManager) GetImageDownloadStatus(ctx context.Context, deviceID string, imageName string) (*voltha.ImageDownload, error) {
+ log.Debugw("GetImageDownloadStatus", log.Fields{"deviceid": deviceID, "imagename": imageName})
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent.GetImageDownloadStatus(ctx, imageName)
}
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+ return nil, status.Errorf(codes.NotFound, "%s", deviceID)
}
-func (dMgr *DeviceManager) GetImageDownload(ctx context.Context, deviceId string, imageName string) (*voltha.ImageDownload, error) {
- log.Debugw("GetImageDownload", log.Fields{"deviceid": deviceId, "imagename": imageName})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// GetImageDownload return the download details for a specific image entry
+func (dMgr *DeviceManager) GetImageDownload(ctx context.Context, deviceID string, imageName string) (*voltha.ImageDownload, error) {
+ log.Debugw("GetImageDownload", log.Fields{"deviceid": deviceID, "imagename": imageName})
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent.GetImageDownload(ctx, imageName)
}
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+ return nil, status.Errorf(codes.NotFound, "%s", deviceID)
}
-func (dMgr *DeviceManager) ListImageDownloads(ctx context.Context, deviceId string) (*voltha.ImageDownloads, error) {
- log.Debugw("ListImageDownloads", log.Fields{"deviceid": deviceId})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListImageDownloads returns all image downloads known to the system
+func (dMgr *DeviceManager) ListImageDownloads(ctx context.Context, deviceID string) (*voltha.ImageDownloads, error) {
+ log.Debugw("ListImageDownloads", log.Fields{"deviceid": deviceID})
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent.ListImageDownloads(ctx)
}
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+ return nil, status.Errorf(codes.NotFound, "%s", deviceID)
}
-func (dMgr *DeviceManager) GetImages(ctx context.Context, deviceId string) (*voltha.Images, error) {
- log.Debugw("GetImages", log.Fields{"deviceid": deviceId})
- if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// GetImages returns all images for a specific device entry
+func (dMgr *DeviceManager) GetImages(ctx context.Context, deviceID string) (*voltha.Images, error) {
+ log.Debugw("GetImages", log.Fields{"deviceid": deviceID})
+ if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
return agent.GetImages(ctx)
}
- return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+ return nil, status.Errorf(codes.NotFound, "%s", deviceID)
}
@@ -368,16 +371,16 @@
return parentDevice
}
-//getAllChildDeviceIds is a helper method to get all the child device IDs from the device passed as parameter
-func (dMgr *DeviceManager) getAllChildDeviceIds(parentDevice *voltha.Device) ([]string, error) {
- log.Debugw("getAllChildDeviceIds", log.Fields{"parentDeviceId": parentDevice.Id})
- childDeviceIds := make([]string, 0)
+//getAllChildDeviceIDs is a helper method to get all the child device IDs from the device passed as parameter
+func (dMgr *DeviceManager) getAllChildDeviceIDs(parentDevice *voltha.Device) ([]string, error) {
+ log.Debugw("getAllChildDeviceIDs", log.Fields{"parentDeviceID": parentDevice.Id})
+ childDeviceIDs := make([]string, 0)
if parentDevice != nil {
for _, port := range parentDevice.Ports {
for _, peer := range port.Peers {
- childDeviceIds = append(childDeviceIds, peer.DeviceId)
+ childDeviceIDs = append(childDeviceIDs, peer.DeviceId)
}
}
}
- return childDeviceIds, nil
+ return childDeviceIDs, nil
}
diff --git a/ro_core/core/device_manager_test.go b/ro_core/core/device_manager_test.go
index cef848c..da58e67 100644
--- a/ro_core/core/device_manager_test.go
+++ b/ro_core/core/device_manager_test.go
@@ -16,17 +16,18 @@
package core
import (
+ "testing"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-go/ro_core/config"
"github.com/opencord/voltha-lib-go/v2/pkg/db"
"github.com/opencord/voltha-protos/v2/go/voltha"
"github.com/stretchr/testify/assert"
- "testing"
)
func MakeTestDevManagerConfig() (*Core, error) {
var core Core
- core.instanceId = "ro_core"
+ core.instanceID = "ro_core"
core.config = config.NewROCoreFlags()
backend := db.Backend{
Client: core.kvClient,
@@ -44,7 +45,7 @@
core, _ := MakeTestDevManagerConfig()
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
assert.NotNil(t, core.deviceMgr)
}
@@ -52,10 +53,10 @@
core, _ := MakeTestDevManagerConfig()
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
assert.NotNil(t, core.deviceMgr)
- myIds, _ := core.deviceMgr.ListDeviceIds()
+ myIds, _ := core.deviceMgr.ListDeviceIDs()
assert.NotNil(t, myIds)
}
@@ -67,7 +68,7 @@
core, _ := MakeTestDevManagerConfig()
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
assert.NotNil(t, core.deviceMgr)
devAgent := newDeviceAgent(&voltha.Device{Id: "new_device"}, core.deviceMgr, core.clusterDataProxy)
@@ -77,11 +78,11 @@
core.deviceMgr.addDeviceAgentToMap(devAgent)
// listDeviceIdsFromMap
- myIDs := core.deviceMgr.listDeviceIdsFromMap()
+ myIDs := core.deviceMgr.listDeviceIDsFromMap()
assert.NotNil(t, myIDs)
// getDeviceAgent
- myDevAgent := core.deviceMgr.getDeviceAgent(devAgent.deviceId)
+ myDevAgent := core.deviceMgr.getDeviceAgent(devAgent.deviceID)
assert.NotNil(t, myDevAgent)
// deleteDeviceAgentToMap
@@ -92,7 +93,7 @@
core, _ := MakeTestDevManagerConfig()
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
assert.NotNil(t, core.deviceMgr)
devAgent := newDeviceAgent(&voltha.Device{Id: "new_device"}, core.deviceMgr, core.clusterDataProxy)
@@ -114,7 +115,7 @@
core, _ := MakeTestDevManagerConfig()
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
assert.NotNil(t, core.deviceMgr)
devAgent := newDeviceAgent(&voltha.Device{Id: "new_device"}, core.deviceMgr, core.clusterDataProxy)
@@ -123,13 +124,13 @@
// addDeviceAgentToMap
core.deviceMgr.addDeviceAgentToMap(devAgent)
- isInCache := core.deviceMgr.IsDeviceInCache(devAgent.deviceId)
+ isInCache := core.deviceMgr.IsDeviceInCache(devAgent.deviceID)
assert.True(t, isInCache)
// deleteDeviceAgentToMap
core.deviceMgr.deleteDeviceAgentToMap(devAgent)
- isInCacheDel := core.deviceMgr.IsDeviceInCache(devAgent.deviceId)
+ isInCacheDel := core.deviceMgr.IsDeviceInCache(devAgent.deviceID)
assert.False(t, isInCacheDel)
}
@@ -137,7 +138,7 @@
core, _ := MakeTestDevManagerConfig()
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
assert.NotNil(t, core.deviceMgr)
devAgent := newDeviceAgent(&voltha.Device{Id: "new_device"}, core.deviceMgr, core.clusterDataProxy)
@@ -154,7 +155,7 @@
core, _ := MakeTestDevManagerConfig()
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
assert.NotNil(t, core.deviceMgr)
devAgent := newDeviceAgent(&voltha.Device{Id: "new_device"}, core.deviceMgr, core.clusterDataProxy)
@@ -171,7 +172,7 @@
core, _ := MakeTestDevManagerConfig()
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
assert.NotNil(t, core.deviceMgr)
devAgent := newDeviceAgent(&voltha.Device{Id: "new_device"}, core.deviceMgr, core.clusterDataProxy)
@@ -180,7 +181,7 @@
// addDeviceAgentToMap
core.deviceMgr.addDeviceAgentToMap(devAgent)
- myIds, err := core.deviceMgr.getAllChildDeviceIds(devAgent.lastData)
+ myIds, err := core.deviceMgr.getAllChildDeviceIDs(devAgent.lastData)
assert.NotNil(t, myIds)
assert.Nil(t, err)
}
diff --git a/ro_core/core/grpc_nbi_api_handler.go b/ro_core/core/grpc_nbi_api_handler.go
index 335623d..ee8d736 100644
--- a/ro_core/core/grpc_nbi_api_handler.go
+++ b/ro_core/core/grpc_nbi_api_handler.go
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
"errors"
+
"github.com/golang/protobuf/ptypes/empty"
da "github.com/opencord/voltha-go/common/core/northbound/grpc"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
@@ -30,6 +32,7 @@
"google.golang.org/grpc/status"
)
+// APIHandler represents API handler related information
type APIHandler struct {
commonMgr *ModelProxyManager
deviceMgr *DeviceManager
@@ -37,6 +40,7 @@
da.DefaultAPIHandler
}
+// NewAPIHandler creates API handler
func NewAPIHandler(generalMgr *ModelProxyManager, deviceMgr *DeviceManager, lDeviceMgr *LogicalDeviceManager) *APIHandler {
handler := &APIHandler{
commonMgr: generalMgr,
@@ -73,7 +77,8 @@
}
}
-func (handler *APIHandler) UpdateLogLevel(ctx context.Context, logging *voltha.Logging) (*empty.Empty, error) {
+// UpdateLogLevel updates log level to the requested level in specific packaged if mentioned
+func (*APIHandler) UpdateLogLevel(ctx context.Context, logging *voltha.Logging) (*empty.Empty, error) {
log.Debugw("UpdateLogLevel-request", log.Fields{"package": logging.PackageName, "intval": int(logging.Level)})
out := new(empty.Empty)
if logging.PackageName == "" {
@@ -88,7 +93,8 @@
return out, nil
}
-func (aa APIHandler) GetLogLevels(ctx context.Context, in *voltha.LoggingComponent) (*voltha.Loggings, error) {
+// GetLogLevels returns log levels for requested packages
+func (APIHandler) GetLogLevels(ctx context.Context, in *voltha.LoggingComponent) (*voltha.Loggings, error) {
logLevels := &voltha.Loggings{}
// do the per-package log levels
@@ -157,7 +163,7 @@
out := &voltha.IDs{Items: make([]*voltha.ID, 0)}
return out, nil
}
- return handler.deviceMgr.ListDeviceIds()
+ return handler.deviceMgr.ListDeviceIDs()
}
// ListDevicePorts returns the ports details for a specific device entry
@@ -287,6 +293,7 @@
return handler.logicalDeviceMgr.ListLogicalDeviceFlowGroups(ctx, id.Id)
}
+// SelfTest - TODO
func (handler *APIHandler) SelfTest(ctx context.Context, id *voltha.ID) (*voltha.SelfTestResponse, error) {
log.Debugw("SelfTest-request", log.Fields{"id": id})
if isTestMode(ctx) {
@@ -296,7 +303,7 @@
return nil, errors.New("UnImplemented")
}
-//@TODO useless stub, what should this actually do?
+// GetAlarmDeviceData - @TODO useless stub, what should this actually do?
func (handler *APIHandler) GetAlarmDeviceData(
ctx context.Context,
in *common.ID,
@@ -305,7 +312,7 @@
return nil, nil
}
-//@TODO useless stub, what should this actually do?
+// GetMeterStatsOfLogicalDevice - @TODO useless stub, what should this actually do?
func (handler *APIHandler) GetMeterStatsOfLogicalDevice(
ctx context.Context,
in *common.ID,
@@ -314,7 +321,7 @@
return nil, nil
}
-//@TODO useless stub, what should this actually do?
+// GetMibDeviceData - @TODO useless stub, what should this actually do?
func (handler *APIHandler) GetMibDeviceData(
ctx context.Context,
in *common.ID,
@@ -323,7 +330,7 @@
return nil, nil
}
-//@TODO useless stub, what should this actually do?
+// SimulateAlarm - @TODO useless stub, what should this actually do?
func (handler *APIHandler) SimulateAlarm(
ctx context.Context,
in *voltha.SimulateAlarmRequest,
diff --git a/ro_core/core/grpc_nbi_api_handler_test.go b/ro_core/core/grpc_nbi_api_handler_test.go
index bc40ce8..3244fd3 100644
--- a/ro_core/core/grpc_nbi_api_handler_test.go
+++ b/ro_core/core/grpc_nbi_api_handler_test.go
@@ -17,14 +17,15 @@
import (
"context"
+ "strconv"
+ "testing"
+
"github.com/opencord/voltha-go/ro_core/config"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/common"
"github.com/opencord/voltha-protos/v2/go/voltha"
"github.com/phayes/freeport"
"github.com/stretchr/testify/assert"
- "strconv"
- "testing"
)
func MakeTestGrpcNbiConfig() *Core {
@@ -77,7 +78,7 @@
ComponentName: "testing",
PackageName: "testing",
Level: voltha.LogLevel_LogLevel(log.GetDefaultLogLevel())}
- testLog_3 := &voltha.Logging{
+ testLog3 := &voltha.Logging{
ComponentName: "testing",
PackageName: "github.com/opencord/voltha-go/ro_core/core",
Level: 3 /*voltha.LogLevel_LogLevel(log.GetDefaultLogLevel())*/}
@@ -97,7 +98,7 @@
{"TestUpdateLogLevel-1", ahndl, args{testCtx, testLogDef}, 0, nil},
{"TestUpdateLogLevel-2", ahndl, args{testCtx, testLogEmpty}, 5, nil},
{"TestUpdateLogLevel-3", ahndl, args{testCtx, testLog}, 5, nil},
- {"TestUpdateLogLevel-4", ahndl, args{testCtx, testLog_3}, 3, nil},
+ {"TestUpdateLogLevel-4", ahndl, args{testCtx, testLog3}, 3, nil},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
diff --git a/ro_core/core/logical_device_agent.go b/ro_core/core/logical_device_agent.go
index 635379a..829aa6b 100644
--- a/ro_core/core/logical_device_agent.go
+++ b/ro_core/core/logical_device_agent.go
@@ -13,23 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
+ "sync"
+
"github.com/gogo/protobuf/proto"
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/voltha"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "sync"
)
+// LogicalDeviceAgent represents logical device agent related information
type LogicalDeviceAgent struct {
- logicalDeviceId string
+ logicalDeviceID string
lastData *voltha.LogicalDevice
- rootDeviceId string
+ rootDeviceID string
deviceMgr *DeviceManager
ldeviceMgr *LogicalDeviceManager
clusterDataProxy *model.Proxy
@@ -37,11 +40,11 @@
lockLogicalDevice sync.RWMutex
}
-func newLogicalDeviceAgent(id string, deviceId string, ldeviceMgr *LogicalDeviceManager, deviceMgr *DeviceManager, cdProxy *model.Proxy) *LogicalDeviceAgent {
+func newLogicalDeviceAgent(id string, deviceID string, ldeviceMgr *LogicalDeviceManager, deviceMgr *DeviceManager, cdProxy *model.Proxy) *LogicalDeviceAgent {
var agent LogicalDeviceAgent
agent.exitChannel = make(chan int, 1)
- agent.logicalDeviceId = id
- agent.rootDeviceId = deviceId
+ agent.logicalDeviceID = id
+ agent.rootDeviceID = deviceID
agent.deviceMgr = deviceMgr
agent.clusterDataProxy = cdProxy
agent.ldeviceMgr = ldeviceMgr
@@ -51,19 +54,19 @@
// start creates the logical device and add it to the data model
func (agent *LogicalDeviceAgent) start(ctx context.Context, loadFromDb bool) error {
- log.Infow("starting-logical_device-agent", log.Fields{"logicaldeviceId": agent.logicalDeviceId, "loadFromdB": loadFromDb})
+ log.Infow("starting-logical_device-agent", log.Fields{"logicaldeviceID": agent.logicalDeviceID, "loadFromdB": loadFromDb})
agent.lockLogicalDevice.Lock()
defer agent.lockLogicalDevice.Unlock()
if loadFromDb {
// load from dB - the logical may not exist at this time. On error, just return and the calling function
// will destroy this agent.
- if logicalDevice := agent.clusterDataProxy.Get(ctx, "/logical_devices/"+agent.logicalDeviceId, 0, false, ""); logicalDevice != nil {
+ if logicalDevice := agent.clusterDataProxy.Get(ctx, "/logical_devices/"+agent.logicalDeviceID, 0, false, ""); logicalDevice != nil {
if lDevice, ok := logicalDevice.(*voltha.LogicalDevice); ok {
agent.lastData = proto.Clone(lDevice).(*voltha.LogicalDevice)
}
} else {
- log.Errorw("failed-to-load-device", log.Fields{"logicaldeviceId": agent.logicalDeviceId})
- return status.Errorf(codes.NotFound, "logicaldeviceId-%s", agent.logicalDeviceId)
+ log.Errorw("failed-to-load-device", log.Fields{"logicaldeviceID": agent.logicalDeviceID})
+ return status.Errorf(codes.NotFound, "logicaldeviceID-%s", agent.logicalDeviceID)
}
}
log.Info("logical_device-agent-started")
@@ -85,40 +88,39 @@
log.Debug("GetLogicalDevice")
agent.lockLogicalDevice.Lock()
defer agent.lockLogicalDevice.Unlock()
- if logicalDevice := agent.clusterDataProxy.Get(context.Background(), "/logical_devices/"+agent.logicalDeviceId, 0, false, ""); logicalDevice != nil {
+ if logicalDevice := agent.clusterDataProxy.Get(context.Background(), "/logical_devices/"+agent.logicalDeviceID, 0, false, ""); logicalDevice != nil {
if lDevice, ok := logicalDevice.(*voltha.LogicalDevice); ok {
return lDevice, nil
}
}
- return nil, status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceId)
+ return nil, status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceID)
}
+// ListLogicalDevicePorts returns all logical device ports details
func (agent *LogicalDeviceAgent) ListLogicalDevicePorts() (*voltha.LogicalPorts, error) {
log.Debug("ListLogicalDevicePorts")
- if logicalDevice, _ := agent.ldeviceMgr.getLogicalDevice(agent.logicalDeviceId); logicalDevice != nil {
+ if logicalDevice, _ := agent.ldeviceMgr.getLogicalDevice(agent.logicalDeviceID); logicalDevice != nil {
lPorts := make([]*voltha.LogicalPort, 0)
- for _, port := range logicalDevice.Ports {
- lPorts = append(lPorts, port)
- }
+ lPorts = append(lPorts, logicalDevice.Ports...)
return &voltha.LogicalPorts{Items: lPorts}, nil
}
- return nil, status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceId)
+ return nil, status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceID)
}
-// listFlows locks the logical device model and then retrieves the latest flow information
+// ListLogicalDeviceFlows - listFlows locks the logical device model and then retrieves the latest flow information
func (agent *LogicalDeviceAgent) ListLogicalDeviceFlows() (*voltha.Flows, error) {
log.Debug("ListLogicalDeviceFlows")
- if logicalDevice, _ := agent.ldeviceMgr.getLogicalDevice(agent.logicalDeviceId); logicalDevice != nil {
+ if logicalDevice, _ := agent.ldeviceMgr.getLogicalDevice(agent.logicalDeviceID); logicalDevice != nil {
return logicalDevice.GetFlows(), nil
}
- return nil, status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceId)
+ return nil, status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceID)
}
-// listFlowGroups locks the logical device model and then retrieves the latest flow groups information
+// ListLogicalDeviceFlowGroups - listFlowGroups locks the logical device model and then retrieves the latest flow groups information
func (agent *LogicalDeviceAgent) ListLogicalDeviceFlowGroups() (*voltha.FlowGroups, error) {
log.Debug("ListLogicalDeviceFlowGroups")
- if logicalDevice, _ := agent.ldeviceMgr.getLogicalDevice(agent.logicalDeviceId); logicalDevice != nil {
+ if logicalDevice, _ := agent.ldeviceMgr.getLogicalDevice(agent.logicalDeviceID); logicalDevice != nil {
return logicalDevice.GetFlowGroups(), nil
}
- return nil, status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceId)
+ return nil, status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceID)
}
diff --git a/ro_core/core/logical_device_manager.go b/ro_core/core/logical_device_manager.go
index d12c2a5..97bc603 100644
--- a/ro_core/core/logical_device_manager.go
+++ b/ro_core/core/logical_device_manager.go
@@ -13,19 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
+ "sync"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-lib-go/v2/pkg/probe"
"github.com/opencord/voltha-protos/v2/go/voltha"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "sync"
)
+// LogicalDeviceManager represents logical device manager related information
type LogicalDeviceManager struct {
logicalDeviceAgents sync.Map
deviceMgr *DeviceManager
@@ -62,29 +65,29 @@
}
func (ldMgr *LogicalDeviceManager) addLogicalDeviceAgentToMap(agent *LogicalDeviceAgent) {
- if _, exist := ldMgr.logicalDeviceAgents.Load(agent.logicalDeviceId); !exist {
- ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceId, agent)
+ if _, exist := ldMgr.logicalDeviceAgents.Load(agent.logicalDeviceID); !exist {
+ ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent)
}
}
// getLogicalDeviceAgent returns the logical device agent. If the device is not in memory then the device will
// be loaded from dB and a logical device agent created to managed it.
-func (ldMgr *LogicalDeviceManager) getLogicalDeviceAgent(logicalDeviceId string) *LogicalDeviceAgent {
- if agent, ok := ldMgr.logicalDeviceAgents.Load(logicalDeviceId); ok {
+func (ldMgr *LogicalDeviceManager) getLogicalDeviceAgent(logicalDeviceID string) *LogicalDeviceAgent {
+ agent, ok := ldMgr.logicalDeviceAgents.Load(logicalDeviceID)
+ if ok {
return agent.(*LogicalDeviceAgent)
- } else {
- // Try to load into memory - loading will also create the logical device agent
- if err := ldMgr.load(logicalDeviceId); err == nil {
- if agent, ok = ldMgr.logicalDeviceAgents.Load(logicalDeviceId); ok {
- return agent.(*LogicalDeviceAgent)
- }
+ }
+ // Try to load into memory - loading will also create the logical device agent
+ if err := ldMgr.load(logicalDeviceID); err == nil {
+ if agent, ok = ldMgr.logicalDeviceAgents.Load(logicalDeviceID); ok {
+ return agent.(*LogicalDeviceAgent)
}
}
return nil
}
-func (ldMgr *LogicalDeviceManager) deleteLogicalDeviceAgent(logicalDeviceId string) {
- ldMgr.logicalDeviceAgents.Delete(logicalDeviceId)
+func (ldMgr *LogicalDeviceManager) deleteLogicalDeviceAgent(logicalDeviceID string) {
+ ldMgr.logicalDeviceAgents.Delete(logicalDeviceID)
}
// GetLogicalDevice provides a cloned most up to date logical device
@@ -109,24 +112,24 @@
}
// load loads a logical device manager in memory
-func (ldMgr *LogicalDeviceManager) load(lDeviceId string) error {
- log.Debugw("loading-logical-device", log.Fields{"lDeviceId": lDeviceId})
+func (ldMgr *LogicalDeviceManager) load(lDeviceID string) error {
+ log.Debugw("loading-logical-device", log.Fields{"lDeviceID": lDeviceID})
// To prevent a race condition, let's hold the logical device agent map lock. This will prevent a loading and
// a create logical device callback from occurring at the same time.
- if ldAgent, _ := ldMgr.logicalDeviceAgents.Load(lDeviceId); ldAgent == nil {
+ if ldAgent, _ := ldMgr.logicalDeviceAgents.Load(lDeviceID); ldAgent == nil {
// Logical device not in memory - create a temp logical device Agent and let it load from memory
- agent := newLogicalDeviceAgent(lDeviceId, "", ldMgr, ldMgr.deviceMgr, ldMgr.clusterDataProxy)
- if err := agent.start(nil, true); err != nil {
- agent.stop(nil)
+ agent := newLogicalDeviceAgent(lDeviceID, "", ldMgr, ldMgr.deviceMgr, ldMgr.clusterDataProxy)
+ if err := agent.start(context.TODO(), true); err != nil {
+ agent.stop(context.TODO())
return err
}
- ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceId, agent)
+ ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent)
}
// TODO: load the child device
return nil
}
-func (ldMgr *LogicalDeviceManager) getLogicalDeviceId(device *voltha.Device) (*string, error) {
+func (ldMgr *LogicalDeviceManager) getLogicalDeviceID(device *voltha.Device) (*string, error) {
// Device can either be a parent or a child device
if device.Root {
// Parent device. The ID of a parent device is the logical device ID
@@ -140,26 +143,27 @@
return nil, status.Errorf(codes.NotFound, "%s", device.Id)
}
-func (ldMgr *LogicalDeviceManager) getLogicalPortId(device *voltha.Device) (*voltha.LogicalPortId, error) {
+func (ldMgr *LogicalDeviceManager) getLogicalPortID(device *voltha.Device) (*voltha.LogicalPortId, error) {
// Get the logical device where this device is attached
- var lDeviceId *string
+ var lDeviceID *string
var err error
- if lDeviceId, err = ldMgr.getLogicalDeviceId(device); err != nil {
+ if lDeviceID, err = ldMgr.getLogicalDeviceID(device); err != nil {
return nil, err
}
var lDevice *voltha.LogicalDevice
- if lDevice, err = ldMgr.getLogicalDevice(*lDeviceId); err != nil {
+ if lDevice, err = ldMgr.getLogicalDevice(*lDeviceID); err != nil {
return nil, err
}
// Go over list of ports
for _, port := range lDevice.Ports {
if port.DeviceId == device.Id {
- return &voltha.LogicalPortId{Id: *lDeviceId, PortId: port.Id}, nil
+ return &voltha.LogicalPortId{Id: *lDeviceID, PortId: port.Id}, nil
}
}
return nil, status.Errorf(codes.NotFound, "%s", device.Id)
}
+// ListLogicalDevicePorts returns port details for a specific logical device entry
func (ldMgr *LogicalDeviceManager) ListLogicalDevicePorts(ctx context.Context, id string) (*voltha.LogicalPorts, error) {
log.Debugw("ListLogicalDevicePorts", log.Fields{"logicaldeviceid": id})
if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil {
@@ -169,6 +173,7 @@
}
+// ListLogicalDeviceFlows returns flow details for a specific logical device entry
func (ldMgr *LogicalDeviceManager) ListLogicalDeviceFlows(ctx context.Context, id string) (*voltha.Flows, error) {
log.Debugw("ListLogicalDeviceFlows", log.Fields{"logicaldeviceid": id})
if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil {
@@ -178,6 +183,7 @@
}
+// ListLogicalDeviceFlowGroups returns flow group details for a specific logical device entry
func (ldMgr *LogicalDeviceManager) ListLogicalDeviceFlowGroups(ctx context.Context, id string) (*voltha.FlowGroups, error) {
log.Debugw("ListLogicalDeviceFlowGroups", log.Fields{"logicaldeviceid": id})
if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil {
@@ -187,18 +193,18 @@
}
-func (ldMgr *LogicalDeviceManager) getLogicalPort(lPortId *voltha.LogicalPortId) (*voltha.LogicalPort, error) {
+func (ldMgr *LogicalDeviceManager) getLogicalPort(lPortID *voltha.LogicalPortId) (*voltha.LogicalPort, error) {
// Get the logical device where this device is attached
var err error
var lDevice *voltha.LogicalDevice
- if lDevice, err = ldMgr.getLogicalDevice(lPortId.Id); err != nil {
+ if lDevice, err = ldMgr.getLogicalDevice(lPortID.Id); err != nil {
return nil, err
}
// Go over list of ports
for _, port := range lDevice.Ports {
- if port.Id == lPortId.PortId {
+ if port.Id == lPortID.PortId {
return port, nil
}
}
- return nil, status.Errorf(codes.NotFound, "%s-%s", lPortId.Id, lPortId.PortId)
+ return nil, status.Errorf(codes.NotFound, "%s-%s", lPortID.Id, lPortID.PortId)
}
diff --git a/ro_core/core/logical_device_manager_test.go b/ro_core/core/logical_device_manager_test.go
index b9fb2a1..e7b33bc 100644
--- a/ro_core/core/logical_device_manager_test.go
+++ b/ro_core/core/logical_device_manager_test.go
@@ -17,23 +17,24 @@
import (
"context"
+ "reflect"
+ "testing"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-go/ro_core/config"
"github.com/opencord/voltha-protos/v2/go/openflow_13"
"github.com/opencord/voltha-protos/v2/go/voltha"
"github.com/stretchr/testify/assert"
- "reflect"
- "testing"
)
func MakeTestNewCoreConfig() *Core {
var core Core
- core.instanceId = "ro_core"
+ core.instanceID = "ro_core"
core.config = config.NewROCoreFlags()
core.clusterDataRoot = model.NewRoot(&voltha.Voltha{}, nil)
core.clusterDataProxy = core.clusterDataRoot.CreateProxy(context.Background(), "/", false)
core.genericMgr = newModelProxyManager(core.clusterDataProxy)
- core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceId)
+ core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
return &core
}
@@ -62,7 +63,7 @@
// Verify ADD is successful
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID)
}
func TestGetLogicalDeviceAgent(t *testing.T) {
@@ -80,7 +81,7 @@
ldMgr.addLogicalDeviceAgentToMap(ldAgent)
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID)
}
func TestDeleteLogicalDeviceAgent(t *testing.T) {
@@ -102,7 +103,7 @@
// Verify ADD is successful
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID)
// Method under Test
ldMgr.deleteLogicalDeviceAgent("id")
@@ -142,7 +143,7 @@
// Verify Add is successful
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID)
// Verify getLogicalDevice() is NOT NIL
logicalDevNotNil, errNil := ldMgr.getLogicalDevice("id")
@@ -187,12 +188,12 @@
assert.NotNil(t, ldMgr)
/*** Case: Logical Device Id Found ***/
- result0, error0 := ldMgr.getLogicalDeviceId(&voltha.Device{Id: "id", Root: true, ParentId: "parent_id"})
+ result0, error0 := ldMgr.getLogicalDeviceID(&voltha.Device{Id: "id", Root: true, ParentId: "parent_id"})
assert.NotNil(t, result0)
assert.Nil(t, error0)
/*** Case: Logical Device Id Not Found ***/
- result1, error1 := ldMgr.getLogicalDeviceId(&voltha.Device{Id: "id", ParentId: "parent_id"})
+ result1, error1 := ldMgr.getLogicalDeviceID(&voltha.Device{Id: "id", ParentId: "parent_id"})
assert.Nil(t, result1)
assert.NotNil(t, error1)
}
@@ -205,12 +206,12 @@
assert.NotNil(t, ldMgr)
/*** Case: Logical Port Id Not Found: getLogicalDeviceId() Error ***/
- result0, error0 := ldMgr.getLogicalPortId(&voltha.Device{Id: "id", ParentId: "parent_id"})
+ result0, error0 := ldMgr.getLogicalPortID(&voltha.Device{Id: "id", ParentId: "parent_id"})
assert.Nil(t, result0)
assert.NotNil(t, error0)
/*** Case: Logical Port Id Not Found: getLogicalDevice() Error ***/
- result1, error1 := ldMgr.getLogicalPortId(&voltha.Device{Id: "id", Root: true, ParentId: "parent_id"})
+ result1, error1 := ldMgr.getLogicalPortID(&voltha.Device{Id: "id", Root: true, ParentId: "parent_id"})
assert.Nil(t, result1)
assert.NotNil(t, error1)
@@ -240,10 +241,10 @@
// Verify Add is successful
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("parent_id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "parent_id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "parent_id", ldAgentNotNil.logicalDeviceID)
// Verify getLogicalPortId() is Success
- result2, error2 := ldMgr.getLogicalPortId(device)
+ result2, error2 := ldMgr.getLogicalPortID(device)
assert.NotNil(t, result2)
assert.Nil(t, error2)
if reflect.TypeOf(result2) != reflect.TypeOf(wantResult) {
@@ -292,7 +293,7 @@
// Verify Add is successful
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID)
// Verify ListLogicalDevicePorts() is Success
result1, error1 := ldMgr.ListLogicalDevicePorts(context.Background(), "id")
@@ -340,7 +341,7 @@
// Verify Add is successful
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID)
// Verify ListLogicalDeviceFlows() is Success
result1, error1 := ldMgr.ListLogicalDeviceFlows(context.Background(), "id")
@@ -390,7 +391,7 @@
// Verify Add is successful
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID)
// Verify ListLogicalDeviceFlowGroups() is Success
result1, error1 := ldMgr.ListLogicalDeviceFlowGroups(context.Background(), "id")
@@ -436,7 +437,7 @@
// Verify Add is successful
ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id")
assert.NotNil(t, ldAgentNotNil)
- assert.Equal(t, "id", ldAgentNotNil.logicalDeviceId)
+ assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID)
// Verify getLogicalPort() is Success
result1, error1 := ldMgr.getLogicalPort(&voltha.LogicalPortId{Id: "id", PortId: "123"})
diff --git a/ro_core/core/model_proxy.go b/ro_core/core/model_proxy.go
index 7f78a5d..eb93e44 100644
--- a/ro_core/core/model_proxy.go
+++ b/ro_core/core/model_proxy.go
@@ -13,16 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
+ "strings"
+ "sync"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "strings"
- "sync"
)
// ModelProxy controls requests made to the data model
diff --git a/ro_core/core/model_proxy_manager.go b/ro_core/core/model_proxy_manager.go
index fcf1c78..d3b278d 100644
--- a/ro_core/core/model_proxy_manager.go
+++ b/ro_core/core/model_proxy_manager.go
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
"encoding/json"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-lib-go/v2/pkg/version"
@@ -26,7 +28,7 @@
"google.golang.org/grpc/status"
)
-// Enumerated type to keep track of miscellaneous data path agents
+// DataModelType - Enumerated type to keep track of miscellaneous data path agents
type DataModelType int
// Enumerated list of data path agents
@@ -39,7 +41,8 @@
Voltha
)
-const SENTINEL_ADAPTER_ID = "adapter_sentinel"
+// SentinelAdapterID is used to watch adapters in kv
+const SentinelAdapterID = "adapter_sentinel"
// String equivalent for data path agents
var commonTypes = []string{
@@ -56,6 +59,7 @@
return commonTypes[t-1]
}
+// MultipleValuesMsg represents multiple values message
const MultipleValuesMsg = "Expected a single value for KV query for an instance (%s) of type '%s', but received multiple values"
// ModelProxyManager controls requests made to the miscellaneous data path agents
@@ -71,7 +75,7 @@
return &mgr
}
-// GetDeviceType returns the device type associated to the provided id
+// GetVoltha - GetDeviceType returns the device type associated to the provided id
func (mpMgr *ModelProxyManager) GetVoltha(ctx context.Context) (*voltha.Voltha, error) {
log.Debug("GetVoltha")
@@ -135,7 +139,7 @@
}
for _, item := range list {
adapter = item.(*voltha.Adapter)
- if adapter.Id != SENTINEL_ADAPTER_ID { // don't report the sentinel
+ if adapter.Id != SentinelAdapterID { // don't report the sentinel
adapters.Items = append(adapters.Items, adapter)
}
}
diff --git a/ro_core/core/model_proxy_test.go b/ro_core/core/model_proxy_test.go
index 8215fb8..a9caa00 100644
--- a/ro_core/core/model_proxy_test.go
+++ b/ro_core/core/model_proxy_test.go
@@ -17,12 +17,13 @@
import (
"context"
+ "reflect"
+ "testing"
+
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-protos/v2/go/voltha"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "reflect"
- "testing"
)
type fields struct {
@@ -33,9 +34,9 @@
func getModelProxyPathNotFound() *fields {
var modelProxy fields
- TestProxy_Root := model.NewRoot(&voltha.Voltha{}, nil)
- TestProxy_Root_Proxy := TestProxy_Root.CreateProxy(context.Background(), "/", false)
- modelProxy.rootProxy = TestProxy_Root_Proxy
+ TestProxyRoot := model.NewRoot(&voltha.Voltha{}, nil)
+ TestProxyRootProxy := TestProxyRoot.CreateProxy(context.Background(), "/", false)
+ modelProxy.rootProxy = TestProxyRootProxy
modelProxy.basePath = "base_path"
return &modelProxy
@@ -44,9 +45,9 @@
func getModelProxyPathFound() *fields {
var modelProxy fields
- TestProxy_Root := model.NewRoot(&voltha.Voltha{}, nil)
- TestProxy_Root_Proxy := TestProxy_Root.CreateProxy(context.Background(), "/", false)
- modelProxy.rootProxy = TestProxy_Root_Proxy
+ TestProxyRoot := model.NewRoot(&voltha.Voltha{}, nil)
+ TestProxyRootProxy := TestProxyRoot.CreateProxy(context.Background(), "/", false)
+ modelProxy.rootProxy = TestProxyRootProxy
modelProxy.basePath = "devices"
return &modelProxy
diff --git a/ro_core/main.go b/ro_core/main.go
index f1e00d2..dc78302 100644
--- a/ro_core/main.go
+++ b/ro_core/main.go
@@ -13,25 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package main
import (
"context"
"errors"
"fmt"
- "github.com/opencord/voltha-go/ro_core/config"
- c "github.com/opencord/voltha-go/ro_core/core"
- "github.com/opencord/voltha-lib-go/v2/pkg/db/kvstore"
- grpcserver "github.com/opencord/voltha-lib-go/v2/pkg/grpc"
- "github.com/opencord/voltha-lib-go/v2/pkg/log"
- "github.com/opencord/voltha-lib-go/v2/pkg/probe"
- "github.com/opencord/voltha-lib-go/v2/pkg/version"
- ic "github.com/opencord/voltha-protos/v2/go/inter_container"
"os"
"os/signal"
"strconv"
"syscall"
"time"
+
+ "github.com/opencord/voltha-go/ro_core/config"
+ c "github.com/opencord/voltha-go/ro_core/core"
+ "github.com/opencord/voltha-lib-go/v2/pkg/db/kvstore"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
+ "github.com/opencord/voltha-lib-go/v2/pkg/probe"
+ "github.com/opencord/voltha-lib-go/v2/pkg/version"
+ ic "github.com/opencord/voltha-protos/v2/go/inter_container"
)
type roCore struct {
@@ -39,14 +40,16 @@
config *config.ROCoreFlags
halted bool
exitChannel chan int
- grpcServer *grpcserver.GrpcServer
core *c.Core
//For test
receiverChannels []<-chan *ic.InterContainerMessage
}
func init() {
- log.AddPackage(log.JSON, log.DebugLevel, nil)
+ _, err := log.AddPackage(log.JSON, log.DebugLevel, nil)
+ if err != nil {
+ log.Errorw("unable-to-register-package-to-the-log-map", log.Fields{"error": err})
+ }
}
func newKVClient(storeType string, address string, timeout int) (kvstore.Client, error) {
@@ -82,17 +85,6 @@
return nil
}
-func toString(value interface{}) (string, error) {
- switch t := value.(type) {
- case []byte:
- return string(value.([]byte)), nil
- case string:
- return value.(string), nil
- default:
- return "", fmt.Errorf("unexpected-type-%T", t)
- }
-}
-
func (ro *roCore) start(ctx context.Context) {
log.Info("Starting RW Core components")
@@ -203,18 +195,23 @@
//// Setup logging
//Setup default logger - applies for packages that do not have specific logger set
- if _, err := log.SetDefaultLogger(log.JSON, cf.LogLevel, log.Fields{"instanceId": cf.InstanceID}); err != nil {
+ if _, err := log.SetDefaultLogger(log.JSON, cf.LogLevel, log.Fields{"instanceID": cf.InstanceID}); err != nil {
log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
}
// Update all loggers (provisionned via init) with a common field
- if err := log.UpdateAllLoggers(log.Fields{"instanceId": cf.InstanceID}); err != nil {
+ if err := log.UpdateAllLoggers(log.Fields{"instanceID": cf.InstanceID}); err != nil {
log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
}
log.SetPackageLogLevel("github.com/opencord/voltha-go/ro_core/core", log.DebugLevel)
- defer log.CleanUp()
+ defer func() {
+ err := log.CleanUp()
+ if err != nil {
+ log.Errorw("unable-to-flush-any-buffered-log-entries", log.Fields{"error": err})
+ }
+ }()
// Print verison / build information and exit
if cf.DisplayVersionOnly {