[VOL-2356]core log_level command line argument should take log level names not int value
- StringToLogLevel method returns two arguments.
Change-Id: I83d20d645fa63363e71265b163273414f14688a7
diff --git a/VERSION b/VERSION
index c2417c3..00355e2 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.3.7-dev
+2.3.7
diff --git a/adaptercore/error.go b/adaptercore/error.go
index b696529..74bd296 100644
--- a/adaptercore/error.go
+++ b/adaptercore/error.go
@@ -51,7 +51,7 @@
type LoggableError interface {
error
Log() error
- LogAt(int) error
+ LogAt(log.LogLevel) error
}
// ErrAdapter represents a basic adapter error that combines an name, field set
@@ -110,7 +110,7 @@
}
// LogAt logs the error at the specified level and then returns the error
-func (e *ErrAdapter) LogAt(level int) error {
+func (e *ErrAdapter) LogAt(level log.LogLevel) error {
logger := log.Debugw
switch level {
case log.InfoLevel:
@@ -154,7 +154,7 @@
}
// LogAt logs the error at the specified level and then returns the error
-func (e *ErrInvalidValue) LogAt(level int) error {
+func (e *ErrInvalidValue) LogAt(level log.LogLevel) error {
_ = e.ErrAdapter.LogAt(level)
return e
}
@@ -183,7 +183,7 @@
}
// LogAt logs the error at the specified level and then returns the error
-func (e *ErrNotFound) LogAt(level int) error {
+func (e *ErrNotFound) LogAt(level log.LogLevel) error {
_ = e.ErrAdapter.LogAt(level)
return e
}
@@ -215,7 +215,7 @@
}
// LogAt logs the error at the specified level and then returns the error
-func (e *ErrPersistence) LogAt(level int) error {
+func (e *ErrPersistence) LogAt(level log.LogLevel) error {
_ = e.ErrAdapter.LogAt(level)
return e
}
@@ -245,7 +245,7 @@
}
// LogAt logs the error at the specified level and then returns the error
-func (e *ErrCommunication) LogAt(level int) error {
+func (e *ErrCommunication) LogAt(level log.LogLevel) error {
_ = e.ErrAdapter.LogAt(level)
return e
}
@@ -276,7 +276,7 @@
}
// LogAt logs the error at the specified level and then returns the error
-func (e *ErrFlowOp) LogAt(level int) error {
+func (e *ErrFlowOp) LogAt(level log.LogLevel) error {
_ = e.ErrAdapter.LogAt(level)
return e
}
@@ -305,7 +305,7 @@
}
// LogAt logs the error at the specified level and then returns the error
-func (e *ErrTimeout) LogAt(level int) error {
+func (e *ErrTimeout) LogAt(level log.LogLevel) error {
_ = e.ErrAdapter.LogAt(level)
return e
}
diff --git a/go.mod b/go.mod
index 6a7728f..b4f685f 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@
github.com/cenkalti/backoff/v3 v3.1.1
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.3.2
- github.com/opencord/voltha-lib-go/v3 v3.0.10
+ github.com/opencord/voltha-lib-go/v3 v3.0.12
github.com/opencord/voltha-protos/v3 v3.2.4
go.etcd.io/etcd v0.0.0-20190930204107-236ac2a90522
google.golang.org/grpc v1.25.1
diff --git a/go.sum b/go.sum
index 3b37920..a40d1db 100644
--- a/go.sum
+++ b/go.sum
@@ -196,8 +196,8 @@
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
-github.com/opencord/voltha-lib-go/v3 v3.0.10 h1:y735YI2Pc4uKPGPoHWAtSqiiSkoAM2IYJcthcPkKolw=
-github.com/opencord/voltha-lib-go/v3 v3.0.10/go.mod h1:69Y+rVd25Nq2SUeoY7Q1BXtwrcUPllG0erhq+aK8Qec=
+github.com/opencord/voltha-lib-go/v3 v3.0.12 h1:YGpyjl0UxdVUpKuo/VO5eCi+1+5EbMK9ZUqjDvWUQWQ=
+github.com/opencord/voltha-lib-go/v3 v3.0.12/go.mod h1:69Y+rVd25Nq2SUeoY7Q1BXtwrcUPllG0erhq+aK8Qec=
github.com/opencord/voltha-protos/v3 v3.2.3 h1:Wv73mw1Ye0bCfyhOk5svgrlE2tLizHq6tQluoDq9Vg8=
github.com/opencord/voltha-protos/v3 v3.2.3/go.mod h1:RIGHt7b80BHpHh3ceodknh0DxUjUHCWSbYbZqRx7Og0=
github.com/opencord/voltha-protos/v3 v3.2.4 h1:BTPpfwJslAY9UintQ9/f+wLD+StZ5QnPv6j7pbAk+J8=
diff --git a/main.go b/main.go
index 40bd284..536e917 100644
--- a/main.go
+++ b/main.go
@@ -440,10 +440,13 @@
// Setup logging
- loglevel := log.StringToInt(cf.LogLevel)
+ logLevel, err := log.StringToLogLevel(cf.LogLevel)
+ if err != nil {
+ log.Fatalf("Cannot setup logging, %s", err)
+ }
// Setup default logger - applies for packages that do not have specific logger set
- if _, err := log.SetDefaultLogger(log.JSON, loglevel, log.Fields{"instanceId": cf.InstanceID}); err != nil {
+ if _, err := log.SetDefaultLogger(log.JSON, logLevel, log.Fields{"instanceId": cf.InstanceID}); err != nil {
log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
}
@@ -452,7 +455,7 @@
log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
}
- log.SetAllLogLevel(loglevel)
+ log.SetAllLogLevel(logLevel)
defer log.CleanUp()
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/adapters/common/core_proxy.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/adapters/common/core_proxy.go
index 7cb933d..86f186d 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/adapters/common/core_proxy.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/adapters/common/core_proxy.go
@@ -124,7 +124,7 @@
}
// Use a device specific topic as we are the only adaptercore handling requests for this device
replyToTopic := ap.getAdapterTopic()
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, device.Id, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, device.Id, args...)
logger.Debugw("DeviceUpdate-response", log.Fields{"deviceId": device.Id, "success": success})
return unPackResponse(rpc, device.Id, success, result)
}
@@ -148,7 +148,7 @@
// Use a device specific topic as we are the only adaptercore handling requests for this device
replyToTopic := ap.getAdapterTopic()
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...)
logger.Debugw("PortCreated-response", log.Fields{"deviceId": deviceId, "success": success})
return unPackResponse(rpc, deviceId, success, result)
}
@@ -174,7 +174,7 @@
// Use a device specific topic as we are the only adaptercore handling requests for this device
replyToTopic := ap.getAdapterTopic()
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...)
logger.Debugw("PortsStateUpdate-response", log.Fields{"deviceId": deviceId, "success": success})
return unPackResponse(rpc, deviceId, success, result)
}
@@ -195,7 +195,7 @@
// Use a device specific topic as we are the only adaptercore handling requests for this device
replyToTopic := ap.getAdapterTopic()
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...)
logger.Debugw("DeleteAllPorts-response", log.Fields{"deviceId": deviceId, "success": success})
return unPackResponse(rpc, deviceId, success, result)
}
@@ -226,7 +226,7 @@
}
// Use a device specific topic as we are the only adaptercore handling requests for this device
replyToTopic := ap.getAdapterTopic()
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...)
logger.Debugw("DeviceStateUpdate-response", log.Fields{"deviceId": deviceId, "success": success})
return unPackResponse(rpc, deviceId, success, result)
}
@@ -277,7 +277,7 @@
Value: oId,
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
logger.Debugw("ChildDeviceDetected-response", log.Fields{"pDeviceId": parentDeviceId, "success": success})
if success {
@@ -315,7 +315,7 @@
Value: id,
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
logger.Debugw("ChildDevicesLost-response", log.Fields{"pDeviceId": parentDeviceId, "success": success})
return unPackResponse(rpc, parentDeviceId, success, result)
}
@@ -335,7 +335,7 @@
Value: id,
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
logger.Debugw("ChildDevicesDetected-response", log.Fields{"pDeviceId": parentDeviceId, "success": success})
return unPackResponse(rpc, parentDeviceId, success, result)
}
@@ -354,7 +354,7 @@
Value: id,
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
logger.Debugw("GetDevice-response", log.Fields{"pDeviceId": parentDeviceId, "success": success})
if success {
@@ -414,7 +414,7 @@
}
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
logger.Debugw("GetChildDevice-response", log.Fields{"pDeviceId": parentDeviceId, "success": success})
if success {
@@ -450,7 +450,7 @@
Value: id,
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
logger.Debugw("GetChildDevices-response", log.Fields{"pDeviceId": parentDeviceId, "success": success})
if success {
@@ -496,7 +496,7 @@
Key: "packet",
Value: pkt,
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...)
logger.Debugw("SendPacketIn-response", log.Fields{"pDeviceId": deviceId, "success": success})
return unPackResponse(rpc, deviceId, success, result)
}
@@ -520,7 +520,7 @@
Key: "device_reason",
Value: reason,
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...)
logger.Debugw("DeviceReason-response", log.Fields{"pDeviceId": deviceId, "success": success})
return unPackResponse(rpc, deviceId, success, result)
}
@@ -538,7 +538,7 @@
Key: "device_pm_config",
Value: pmConfigs,
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, pmConfigs.Id, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, pmConfigs.Id, args...)
logger.Debugw("DevicePMConfigUpdate-response", log.Fields{"pDeviceId": pmConfigs.Id, "success": success})
return unPackResponse(rpc, pmConfigs.Id, success, result)
}
@@ -555,7 +555,7 @@
{Key: "parent_device_id", Value: &voltha.ID{Id: parentDeviceId}},
}
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...)
logger.Debugw("ReconcileChildDevices-response", log.Fields{"pDeviceId": parentDeviceId, "success": success})
return unPackResponse(rpc, parentDeviceId, success, result)
}
@@ -592,7 +592,7 @@
// Use a device specific topic as we are the only adaptercore handling requests for this device
replyToTopic := ap.getAdapterTopic()
- success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
+ success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...)
logger.Debugw("PortStateUpdate-response", log.Fields{"deviceId": deviceId, "success": success})
return unPackResponse(rpc, deviceId, success, result)
}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
index 9bb49ac..96829c5 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
@@ -103,7 +103,7 @@
logger.Debug("update-liveness-channel-reason-change")
b.liveness <- alive
b.lastLivenessTime = time.Now()
- } else if time.Now().Sub(b.lastLivenessTime) > b.LivenessChannelInterval {
+ } else if time.Since(b.lastLivenessTime) > b.LivenessChannelInterval {
logger.Debug("update-liveness-channel-reason-interval")
b.liveness <- alive
b.lastLivenessTime = time.Now()
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
index a0f39cd..2d126f7 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
@@ -30,7 +30,6 @@
// EtcdClient represents the Etcd KV store client
type EtcdClient struct {
ectdAPI *v3Client.Client
- leaderRev v3Client.Client
keyReservations map[string]*v3Client.LeaseID
watchedChannels sync.Map
writeLock sync.Mutex
@@ -39,9 +38,6 @@
lockToMutexLock sync.Mutex
}
-// Connection Timeout in Seconds
-var connTimeout int = 2
-
// NewEtcdClient returns a new client for the Etcd KV store
func NewEtcdClient(addr string, timeout int) (*EtcdClient, error) {
duration := GetDuration(timeout)
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/flows/flow_utils.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/flows/flow_utils.go
index b9981e6..4de929f 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/flows/flow_utils.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/flows/flow_utils.go
@@ -689,7 +689,10 @@
}
var flowString = fmt.Sprintf("%d%d%d%d%s%s", flow.TableId, flow.Priority, flow.Flags, flow.Cookie, flow.Match.String(), instructionString.String())
h := md5.New()
- h.Write([]byte(flowString))
+ if _, err := h.Write([]byte(flowString)); err != nil {
+ logger.Errorw("hash-flow-status", log.Fields{"error": err})
+ return 0
+ }
hash := big.NewInt(0)
hash.SetBytes(h.Sum(nil))
return hash.Uint64()
@@ -745,7 +748,7 @@
meter.Stats.DurationSec = 0
meter.Stats.DurationNsec = 0
// band stats init
- for _, _ = range meterMod.Bands {
+ for range meterMod.Bands {
band := &ofp.OfpMeterBandStats{}
band.PacketBandCount = 0
band.ByteBandCount = 0
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/kafka/kafka_inter_container_library.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/kafka/kafka_inter_container_library.go
index d21fdd5..aa77ffb 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/kafka/kafka_inter_container_library.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/kafka/kafka_inter_container_library.go
@@ -272,7 +272,14 @@
// subscriber on that topic will receive the request in the order it was sent. The key used is the deviceId.
//key := GetDeviceIdFromTopic(*toTopic)
logger.Debugw("sending-msg", log.Fields{"rpc": rpc, "toTopic": toTopic, "replyTopic": responseTopic, "key": key, "xId": protoRequest.Header.Id})
- go kp.kafkaClient.Send(protoRequest, toTopic, key)
+ go func() {
+ if err := kp.kafkaClient.Send(protoRequest, toTopic, key); err != nil {
+ logger.Errorw("send-failed", log.Fields{
+ "topic": toTopic,
+ "key": key,
+ "error": err})
+ }
+ }()
if waitForResponse {
// Create a child context based on the parent context, if any
@@ -287,7 +294,13 @@
// Wait for response as well as timeout or cancellation
// Remove the subscription for a response on return
- defer kp.unSubscribeForResponse(protoRequest.Header.Id)
+ defer func() {
+ if err := kp.unSubscribeForResponse(protoRequest.Header.Id); err != nil {
+ logger.Errorw("response-unsubscribe-failed", log.Fields{
+ "id": protoRequest.Header.Id,
+ "error": err})
+ }
+ }()
select {
case msg, ok := <-ch:
if !ok {
@@ -378,23 +391,6 @@
return kp.deleteFromTopicRequestHandlerChannelMap(topic.Name)
}
-// setupTopicResponseChannelMap sets up single consumers channel that will act as a broadcast channel for all
-// responses from that topic.
-func (kp *interContainerProxy) setupTopicResponseChannelMap(topic string, arg <-chan *ic.InterContainerMessage) {
- kp.lockTopicResponseChannelMap.Lock()
- defer kp.lockTopicResponseChannelMap.Unlock()
- if _, exist := kp.topicToResponseChannelMap[topic]; !exist {
- kp.topicToResponseChannelMap[topic] = arg
- }
-}
-
-func (kp *interContainerProxy) isTopicSubscribedForResponse(topic string) bool {
- kp.lockTopicResponseChannelMap.RLock()
- defer kp.lockTopicResponseChannelMap.RUnlock()
- _, exist := kp.topicToResponseChannelMap[topic]
- return exist
-}
-
func (kp *interContainerProxy) deleteFromTopicResponseChannelMap(topic string) error {
kp.lockTopicResponseChannelMap.Lock()
defer kp.lockTopicResponseChannelMap.Unlock()
@@ -407,15 +403,16 @@
delete(kp.topicToResponseChannelMap, topic)
return err
} else {
- return errors.New(fmt.Sprintf("%s-Topic-not-found", topic))
+ return fmt.Errorf("%s-Topic-not-found", topic)
}
}
+// nolint: unused
func (kp *interContainerProxy) deleteAllTopicResponseChannelMap() error {
kp.lockTopicResponseChannelMap.Lock()
defer kp.lockTopicResponseChannelMap.Unlock()
var err error
- for topic, _ := range kp.topicToResponseChannelMap {
+ for topic := range kp.topicToResponseChannelMap {
// Unsubscribe to this topic first - this will close the subscribed channel
if err = kp.kafkaClient.UnSubscribe(&Topic{Name: topic}, kp.topicToResponseChannelMap[topic]); err != nil {
logger.Errorw("unsubscribing-error", log.Fields{"topic": topic, "error": err})
@@ -438,19 +435,22 @@
defer kp.lockTopicRequestHandlerChannelMap.Unlock()
if _, exist := kp.topicToRequestHandlerChannelMap[topic]; exist {
// Close the kafka client client first by unsubscribing to this topic
- kp.kafkaClient.UnSubscribe(&Topic{Name: topic}, kp.topicToRequestHandlerChannelMap[topic].ch)
+ if err := kp.kafkaClient.UnSubscribe(&Topic{Name: topic}, kp.topicToRequestHandlerChannelMap[topic].ch); err != nil {
+ return err
+ }
delete(kp.topicToRequestHandlerChannelMap, topic)
return nil
} else {
- return errors.New(fmt.Sprintf("%s-Topic-not-found", topic))
+ return fmt.Errorf("%s-Topic-not-found", topic)
}
}
+// nolint: unused
func (kp *interContainerProxy) deleteAllTopicRequestHandlerChannelMap() error {
kp.lockTopicRequestHandlerChannelMap.Lock()
defer kp.lockTopicRequestHandlerChannelMap.Unlock()
var err error
- for topic, _ := range kp.topicToRequestHandlerChannelMap {
+ for topic := range kp.topicToRequestHandlerChannelMap {
// Close the kafka client client first by unsubscribing to this topic
if err = kp.kafkaClient.UnSubscribe(&Topic{Name: topic}, kp.topicToRequestHandlerChannelMap[topic].ch); err != nil {
logger.Errorw("unsubscribing-error", log.Fields{"topic": topic, "error": err})
@@ -489,6 +489,7 @@
}
}
+// nolint: unused
func (kp *interContainerProxy) deleteAllTransactionIdToChannelMap() {
kp.lockTransactionIdToChannelMap.Lock()
defer kp.lockTransactionIdToChannelMap.Unlock()
@@ -575,11 +576,12 @@
// Go over all returned values
var marshalledReturnedVal *any.Any
var err error
- for _, returnVal := range returnedValues {
- if marshalledReturnedVal, err = encodeReturnedValue(returnVal); err != nil {
+
+ // for now we support only 1 returned value - (excluding the error)
+ if len(returnedValues) > 0 {
+ if marshalledReturnedVal, err = encodeReturnedValue(returnedValues[0]); err != nil {
logger.Warnw("cannot-marshal-response-body", log.Fields{"error": err})
}
- break // for now we support only 1 returned value - (excluding the error)
}
responseBody := &ic.InterContainerResponseBody{
@@ -730,7 +732,14 @@
key := msg.Header.KeyTopic
logger.Debugw("sending-response-to-kafka", log.Fields{"rpc": requestBody.Rpc, "header": icm.Header, "key": key})
// TODO: handle error response.
- go kp.kafkaClient.Send(icm, replyTopic, key)
+ go func() {
+ if err := kp.kafkaClient.Send(icm, replyTopic, key); err != nil {
+ logger.Errorw("send-reply-failed", log.Fields{
+ "topic": replyTopic,
+ "key": key,
+ "error": err})
+ }
+ }()
}
} else if msg.Header.Type == ic.MessageType_RESPONSE {
logger.Debugw("response-received", log.Fields{"msg-header": msg.Header})
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/kafka/sarama_client.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/kafka/sarama_client.go
index c0c16f9..deb72fd 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/kafka/sarama_client.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/kafka/sarama_client.go
@@ -32,8 +32,6 @@
ic "github.com/opencord/voltha-protos/v3/go/inter_container"
)
-type returnErrorFunction func() error
-
// consumerChannels represents one or more consumers listening on a kafka topic. Once a message is received on that
// topic, the consumer(s) broadcasts the message to all the listening channels. The consumer can be a partition
//consumer or a group consumer
@@ -48,7 +46,6 @@
// SaramaClient represents the messaging proxy
type SaramaClient struct {
cAdmin sarama.ClusterAdmin
- client sarama.Client
KafkaHost string
KafkaPort int
producer sarama.AsyncProducer
@@ -478,7 +475,7 @@
logger.Info("update-liveness-channel-because-change")
sc.liveness <- alive
sc.lastLivenessTime = time.Now()
- } else if time.Now().Sub(sc.lastLivenessTime) > sc.livenessChannelInterval {
+ } else if time.Since(sc.lastLivenessTime) > sc.livenessChannelInterval {
logger.Info("update-liveness-channel-because-interval")
sc.liveness <- alive
sc.lastLivenessTime = time.Now()
@@ -558,7 +555,7 @@
// ascertain the value interface type is a proto.Message
if protoMsg, ok = msg.(proto.Message); !ok {
logger.Warnw("message-not-proto-message", log.Fields{"msg": msg})
- return errors.New(fmt.Sprintf("not-a-proto-msg-%s", msg))
+ return fmt.Errorf("not-a-proto-msg-%s", msg)
}
var marshalled []byte
@@ -740,14 +737,6 @@
}
}
-func (sc *SaramaClient) deleteFromTopicToConsumerChannelMap(id string) {
- sc.lockTopicToConsumerChannelMap.Lock()
- defer sc.lockTopicToConsumerChannelMap.Unlock()
- if _, exist := sc.topicToConsumerChannelMap[id]; exist {
- delete(sc.topicToConsumerChannelMap, id)
- }
-}
-
func (sc *SaramaClient) getConsumerChannel(topic *Topic) *consumerChannels {
sc.lockTopicToConsumerChannelMap.RLock()
defer sc.lockTopicToConsumerChannelMap.RUnlock()
@@ -838,24 +827,6 @@
return nil
}
-func (sc *SaramaClient) clearConsumerChannelMap() error {
- sc.lockTopicToConsumerChannelMap.Lock()
- defer sc.lockTopicToConsumerChannelMap.Unlock()
- var err error
- for topic, consumerCh := range sc.topicToConsumerChannelMap {
- for _, ch := range consumerCh.channels {
- // Channel will be closed in the removeChannel method
- removeChannel(consumerCh.channels, ch)
- }
- if errTemp := closeConsumers(consumerCh.consumers); errTemp != nil {
- err = errTemp
- }
- //err = consumerCh.consumers.Close()
- delete(sc.topicToConsumerChannelMap, topic)
- }
- return err
-}
-
//createPublisher creates the publisher which is used to send a message onto kafka
func (sc *SaramaClient) createPublisher() error {
// This Creates the publisher
@@ -1082,7 +1053,13 @@
sc.addTopicToConsumerChannelMap(topic.Name, cc)
//Start a consumers to listen on that specific topic
- go sc.startConsumers(topic)
+ go func() {
+ if err := sc.startConsumers(topic); err != nil {
+ logger.Errorw("start-consumers-failed", log.Fields{
+ "topic": topic,
+ "error": err})
+ }
+ }()
return consumerListeningChannel, nil
}
@@ -1109,7 +1086,13 @@
sc.addTopicToConsumerChannelMap(topic.Name, cc)
//Start a consumers to listen on that specific topic
- go sc.startConsumers(topic)
+ go func() {
+ if err := sc.startConsumers(topic); err != nil {
+ logger.Errorw("start-consumers-failed", log.Fields{
+ "topic": topic,
+ "error": err})
+ }
+ }()
return consumerListeningChannel, nil
}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/log/log.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/log/log.go
index 43567e3..69e22a4 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/log/log.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/log/log.go
@@ -50,9 +50,11 @@
"strings"
)
+type LogLevel int8
+
const (
// DebugLevel logs a message at debug level
- DebugLevel = iota
+ DebugLevel = LogLevel(iota)
// InfoLevel logs a message at info level
InfoLevel
// WarnLevel logs a message at warning level
@@ -106,10 +108,10 @@
Warningf(string, ...interface{})
// V reports whether verbosity level l is at least the requested verbose level.
- V(l int) bool
+ V(l LogLevel) bool
//Returns the log level of this specific logger
- GetLogLevel() int
+ GetLogLevel() LogLevel
}
// Fields is used as key-value pairs for structured logging
@@ -127,7 +129,7 @@
packageName string
}
-func intToAtomicLevel(l int) zp.AtomicLevel {
+func logLevelToAtomicLevel(l LogLevel) zp.AtomicLevel {
switch l {
case DebugLevel:
return zp.NewAtomicLevelAt(zc.DebugLevel)
@@ -143,7 +145,7 @@
return zp.NewAtomicLevelAt(zc.ErrorLevel)
}
-func intToLevel(l int) zc.Level {
+func logLevelToLevel(l LogLevel) zc.Level {
switch l {
case DebugLevel:
return zc.DebugLevel
@@ -159,7 +161,7 @@
return zc.ErrorLevel
}
-func levelToInt(l zc.Level) int {
+func levelToLogLevel(l zc.Level) LogLevel {
switch l {
case zc.DebugLevel:
return DebugLevel
@@ -175,25 +177,25 @@
return ErrorLevel
}
-func StringToInt(l string) int {
- switch l {
+func StringToLogLevel(l string) (LogLevel, error) {
+ switch strings.ToUpper(l) {
case "DEBUG":
- return DebugLevel
+ return DebugLevel, nil
case "INFO":
- return InfoLevel
+ return InfoLevel, nil
case "WARN":
- return WarnLevel
+ return WarnLevel, nil
case "ERROR":
- return ErrorLevel
+ return ErrorLevel, nil
case "FATAL":
- return FatalLevel
+ return FatalLevel, nil
}
- return ErrorLevel
+ return 0, errors.New("Given LogLevel is invalid : " + l)
}
-func getDefaultConfig(outputType string, level int, defaultFields Fields) zp.Config {
+func getDefaultConfig(outputType string, level LogLevel, defaultFields Fields) zp.Config {
return zp.Config{
- Level: intToAtomicLevel(level),
+ Level: logLevelToAtomicLevel(level),
Encoding: outputType,
Development: true,
OutputPaths: []string{"stdout"},
@@ -215,7 +217,7 @@
// SetLogger needs to be invoked before the logger API can be invoked. This function
// initialize the default logger (zap's sugaredlogger)
-func SetDefaultLogger(outputType string, level int, defaultFields Fields) (Logger, error) {
+func SetDefaultLogger(outputType string, level LogLevel, defaultFields Fields) (Logger, error) {
// Build a custom config using zap
cfg = getDefaultConfig(outputType, level, defaultFields)
@@ -241,7 +243,7 @@
// be available to it, notably log tracing with filename.functionname.linenumber annotation.
//
// pkgNames parameter should be used for testing only as this function detects the caller's package.
-func AddPackage(outputType string, level int, defaultFields Fields, pkgNames ...string) (Logger, error) {
+func AddPackage(outputType string, level LogLevel, defaultFields Fields, pkgNames ...string) (Logger, error) {
if cfgs == nil {
cfgs = make(map[string]zp.Config)
}
@@ -318,12 +320,12 @@
func UpdateLogger(defaultFields Fields) (Logger, error) {
pkgName, _, _, _ := getCallerInfo()
if _, exist := loggers[pkgName]; !exist {
- return nil, errors.New(fmt.Sprintf("package-%s-not-registered", pkgName))
+ return nil, fmt.Errorf("package-%s-not-registered", pkgName)
}
// Build a new logger
if _, exist := cfgs[pkgName]; !exist {
- return nil, errors.New(fmt.Sprintf("config-%s-not-registered", pkgName))
+ return nil, fmt.Errorf("config-%s-not-registered", pkgName)
}
cfg := cfgs[pkgName]
@@ -347,7 +349,7 @@
return loggers[pkgName], nil
}
-func setLevel(cfg zp.Config, level int) {
+func setLevel(cfg zp.Config, level LogLevel) {
switch level {
case DebugLevel:
cfg.Level.SetLevel(zc.DebugLevel)
@@ -366,7 +368,7 @@
//SetPackageLogLevel dynamically sets the log level of a given package to level. This is typically invoked at an
// application level during debugging
-func SetPackageLogLevel(packageName string, level int) {
+func SetPackageLogLevel(packageName string, level LogLevel) {
// Get proper config
if cfg, ok := cfgs[packageName]; ok {
setLevel(cfg, level)
@@ -374,7 +376,7 @@
}
//SetAllLogLevel sets the log level of all registered packages to level
-func SetAllLogLevel(level int) {
+func SetAllLogLevel(level LogLevel) {
// Get proper config
for _, cfg := range cfgs {
setLevel(cfg, level)
@@ -382,7 +384,7 @@
}
//GetPackageLogLevel returns the current log level of a package.
-func GetPackageLogLevel(packageName ...string) (int, error) {
+func GetPackageLogLevel(packageName ...string) (LogLevel, error) {
var name string
if len(packageName) == 1 {
name = packageName[0]
@@ -390,21 +392,21 @@
name, _, _, _ = getCallerInfo()
}
if cfg, ok := cfgs[name]; ok {
- return levelToInt(cfg.Level.Level()), nil
+ return levelToLogLevel(cfg.Level.Level()), nil
}
- return 0, errors.New(fmt.Sprintf("unknown-package-%s", name))
+ return 0, fmt.Errorf("unknown-package-%s", name)
}
//GetDefaultLogLevel gets the log level used for packages that don't have specific loggers
-func GetDefaultLogLevel() int {
- return levelToInt(cfg.Level.Level())
+func GetDefaultLogLevel() LogLevel {
+ return levelToLogLevel(cfg.Level.Level())
}
//SetLogLevel sets the log level for the logger corresponding to the caller's package
-func SetLogLevel(level int) error {
+func SetLogLevel(level LogLevel) error {
pkgName, _, _, _ := getCallerInfo()
if _, exist := cfgs[pkgName]; !exist {
- return errors.New(fmt.Sprintf("unregistered-package-%s", pkgName))
+ return fmt.Errorf("unregistered-package-%s", pkgName)
}
cfg := cfgs[pkgName]
setLevel(cfg, level)
@@ -412,7 +414,7 @@
}
//SetDefaultLogLevel sets the log level used for packages that don't have specific loggers
-func SetDefaultLogLevel(level int) {
+func SetDefaultLogLevel(level LogLevel) {
setLevel(cfg, level)
}
@@ -641,13 +643,13 @@
}
// V reports whether verbosity level l is at least the requested verbose level.
-func (l logger) V(level int) bool {
- return l.parent.Core().Enabled(intToLevel(level))
+func (l logger) V(level LogLevel) bool {
+ return l.parent.Core().Enabled(logLevelToLevel(level))
}
// GetLogLevel returns the current level of the logger
-func (l logger) GetLogLevel() int {
- return levelToInt(cfgs[l.packageName].Level.Level())
+func (l logger) GetLogLevel() LogLevel {
+ return levelToLogLevel(cfgs[l.packageName].Level.Level())
}
// With returns a logger initialized with the key-value pairs
@@ -776,11 +778,11 @@
}
// V reports whether verbosity level l is at least the requested verbose level.
-func V(level int) bool {
+func V(level LogLevel) bool {
return getPackageLevelLogger().V(level)
}
//GetLogLevel returns the log level of the invoking package
-func GetLogLevel() int {
+func GetLogLevel() LogLevel {
return getPackageLevelLogger().GetLogLevel()
}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager/ponresourcemanager.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager/ponresourcemanager.go
index ad2150a..6ed18e9 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager/ponresourcemanager.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager/ponresourcemanager.go
@@ -411,7 +411,7 @@
if SharedPoolID != 0 {
Intf = SharedPoolID
}
- if status := PONRMgr.ClearResourceIDPool(ctx, Intf, ONU_ID); status != true {
+ if status := PONRMgr.ClearResourceIDPool(ctx, Intf, ONU_ID); !status {
log.Error("Failed to clear ONU ID resource pool")
return errors.New("Failed to clear ONU ID resource pool")
}
@@ -425,7 +425,7 @@
if SharedPoolID != 0 {
Intf = SharedPoolID
}
- if status := PONRMgr.ClearResourceIDPool(ctx, Intf, ALLOC_ID); status != true {
+ if status := PONRMgr.ClearResourceIDPool(ctx, Intf, ALLOC_ID); !status {
log.Error("Failed to clear ALLOC ID resource pool ")
return errors.New("Failed to clear ALLOC ID resource pool")
}
@@ -438,7 +438,7 @@
if SharedPoolID != 0 {
Intf = SharedPoolID
}
- if status := PONRMgr.ClearResourceIDPool(ctx, Intf, GEMPORT_ID); status != true {
+ if status := PONRMgr.ClearResourceIDPool(ctx, Intf, GEMPORT_ID); !status {
log.Error("Failed to clear GEMPORT ID resource pool")
return errors.New("Failed to clear GEMPORT ID resource pool")
}
@@ -452,7 +452,7 @@
if SharedPoolID != 0 {
Intf = SharedPoolID
}
- if status := PONRMgr.ClearResourceIDPool(ctx, Intf, FLOW_ID); status != true {
+ if status := PONRMgr.ClearResourceIDPool(ctx, Intf, FLOW_ID); !status {
log.Error("Failed to clear FLOW ID resource pool")
return errors.New("Failed to clear FLOW ID resource pool")
}
@@ -483,7 +483,7 @@
Path := PONRMgr.GetPath(Intf, ResourceType)
if Path == "" {
log.Errorf("Failed to get path for resource type %s", ResourceType)
- return errors.New(fmt.Sprintf("Failed to get path for resource type %s", ResourceType))
+ return fmt.Errorf("Failed to get path for resource type %s", ResourceType)
}
//In case of adapter reboot and reconciliation resource in kv store
@@ -563,6 +563,9 @@
}
Value, err = ToByte(Resource.Value)
+ if err != nil {
+ return nil, err
+ }
// decode resource fetched from backend store to dictionary
err = json.Unmarshal(Value, &Result)
@@ -632,7 +635,7 @@
*/
if NumIDs < 1 {
log.Error("Invalid number of resources requested")
- return nil, errors.New(fmt.Sprintf("Invalid number of resources requested %d", NumIDs))
+ return nil, fmt.Errorf("Invalid number of resources requested %d", NumIDs)
}
// delegate to the master instance if sharing enabled across instances
@@ -645,7 +648,7 @@
Path := PONRMgr.GetPath(IntfID, ResourceType)
if Path == "" {
log.Errorf("Failed to get path for resource type %s", ResourceType)
- return nil, errors.New(fmt.Sprintf("Failed to get path for resource type %s", ResourceType))
+ return nil, fmt.Errorf("Failed to get path for resource type %s", ResourceType)
}
log.Debugf("Get resource for type %s on path %s", ResourceType, Path)
var Result []uint32
@@ -682,7 +685,7 @@
//Update resource in kv store
if PONRMgr.UpdateResource(ctx, Path, Resource) != nil {
log.Errorf("Failed to update resource %s", Path)
- return nil, errors.New(fmt.Sprintf("Failed to update resource %s", Path))
+ return nil, fmt.Errorf("Failed to update resource %s", Path)
}
return Result, nil
}
@@ -706,7 +709,7 @@
:param release_content: required number of ids
:return boolean: True if all IDs in given release_content release else False
*/
- if checkValidResourceType(ResourceType) == false {
+ if !checkValidResourceType(ResourceType) {
log.Error("Invalid resource type")
return false
}
@@ -1018,7 +1021,7 @@
: return true and the index if present false otherwise.
*/
- for idx, _ := range FlowIDList {
+ for idx := range FlowIDList {
if FlowID == FlowIDList[idx] {
return true, uint32(idx)
}
@@ -1042,13 +1045,13 @@
FlowIDs := PONRMgr.GetCurrentFlowIDsForOnu(ctx, IntfONUID)
if Add {
- if RetVal, IDx = checkForFlowIDInList(FlowIDs, FlowID); RetVal == true {
- return err
+ if RetVal, _ = checkForFlowIDInList(FlowIDs, FlowID); RetVal {
+ return nil
}
FlowIDs = append(FlowIDs, FlowID)
} else {
- if RetVal, IDx = checkForFlowIDInList(FlowIDs, FlowID); RetVal == false {
- return err
+ if RetVal, IDx = checkForFlowIDInList(FlowIDs, FlowID); !RetVal {
+ return nil
}
// delete the index and shift
FlowIDs = append(FlowIDs[:IDx], FlowIDs[IDx+1:]...)
@@ -1110,8 +1113,7 @@
Len := Data.Len()
var Idx int
for Idx = 0; Idx < Len; Idx++ {
- Val := Data.Get(Idx)
- if Val == false {
+ if !Data.Get(Idx) {
break
}
}
@@ -1138,8 +1140,7 @@
log.Error("Failed to get resource pool")
return false
}
- var Idx uint32
- Idx = Id - uint32(Resource[START_IDX].(float64))
+ Idx := Id - uint32(Resource[START_IDX].(float64))
Data.Set(int(Idx), false)
Resource[POOL] = Data.Data(false)
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/probe/probe.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/probe/probe.go
index 9f00953..932c287 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/probe/probe.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/probe/probe.go
@@ -231,15 +231,26 @@
p.mutex.RLock()
defer p.mutex.RUnlock()
w.Header().Set("Content-Type", "application/json")
- w.Write([]byte("{"))
+ if _, err := w.Write([]byte("{")); err != nil {
+ log.Errorw("write-response", log.Fields{"error": err})
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
comma := ""
for c, s := range p.status {
- w.Write([]byte(fmt.Sprintf("%s\"%s\": \"%s\"", comma, c, s.String())))
+ if _, err := w.Write([]byte(fmt.Sprintf("%s\"%s\": \"%s\"", comma, c, s.String()))); err != nil {
+ log.Errorw("write-response", log.Fields{"error": err})
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
comma = ", "
}
- w.Write([]byte("}"))
+ if _, err := w.Write([]byte("}")); err != nil {
+ log.Errorw("write-response", log.Fields{"error": err})
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
w.WriteHeader(http.StatusOK)
-
}
// ListenAndServe implements 3 HTTP endpoints on the given port for healthz, readz, and detailz. Returns only on error
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/config.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/config.go
index 2df7147..4af2bd5 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/config.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/config.go
@@ -26,13 +26,9 @@
defaultVersion = 1.0
defaultLogLevel = 0
defaultGemportsCount = 1
- defaultNumTconts = 1
defaultPbits = "0b11111111"
- defaultKVStoreType = "etcd"
defaultKVStoreTimeout = 5 //in seconds
- defaultKVStoreHost = "127.0.0.1"
- defaultKVStorePort = 2379 // Consul = 8500; Etcd = 2379
// Tech profile path prefix in kv store
defaultKVPathPrefix = "service/voltha/technology_profiles"
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/tech_profile.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/tech_profile.go
index b268a4c..ba8855f 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/tech_profile.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/tech_profile.go
@@ -121,7 +121,6 @@
const (
defaultOnuInstance = "multi-instance"
defaultUniInstance = "single-instance"
- defaultNumGemPorts = 1
defaultGemPayloadSize = "auto"
)
@@ -437,8 +436,10 @@
return nil
}
} else { // "single-instance"
- tpInst, err := t.getSingleInstanceTp(ctx, tpInstPath)
- if tpInst == nil {
+ if tpInst, err := t.getSingleInstanceTp(ctx, tpInstPath); err != nil {
+ log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
+ return nil
+ } else if tpInst == nil {
// No "single-instance" tp found on one any uni port for the given TP ID
// Allocate a new TcontID or AllocID
if tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil {
diff --git a/vendor/modules.txt b/vendor/modules.txt
index b3eb4a8..d52f5da 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -63,7 +63,7 @@
github.com/mitchellh/go-homedir
# github.com/mitchellh/mapstructure v1.1.2
github.com/mitchellh/mapstructure
-# github.com/opencord/voltha-lib-go/v3 v3.0.10
+# github.com/opencord/voltha-lib-go/v3 v3.0.12
github.com/opencord/voltha-lib-go/v3/pkg/adapters
github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif
github.com/opencord/voltha-lib-go/v3/pkg/adapters/common