[VOL-1667] Fix instance Id and other minor fixes
This commit fixes the following:
1) Remove the instance ID as an input parameter and let the code
sets it to hostname
2) Removes logs settings in the rw_core that were overwriting the
input parameter setting
3) Removes unnecessary device loading at creation time (applies to
the core in a core-pair that is only monitoring the transaction).
The device ID is not know by that Core at that time.
4) Some minor cleanups
Change-Id: If781103bfb449dcae5421284456c4b0fe67704fd
diff --git a/rw_core/core/core.go b/rw_core/core/core.go
index f03c7d2..938d8e9 100644
--- a/rw_core/core/core.go
+++ b/rw_core/core/core.go
@@ -89,7 +89,7 @@
if err := core.startKafkaMessagingProxy(ctx); err != nil {
log.Fatal("Failure-starting-kafkaMessagingProxy")
}
- log.Info("values", log.Fields{"kmp": core.kmp})
+ log.Debugw("values", log.Fields{"kmp": core.kmp})
core.adapterMgr = newAdapterManager(core.clusterDataProxy, core.instanceId)
core.deviceMgr = newDeviceManager(core)
core.logicalDeviceMgr = newLogicalDeviceManager(core, core.deviceMgr, core.kmp, core.clusterDataProxy, core.config.DefaultCoreTimeout)
@@ -120,14 +120,12 @@
log.Info("adaptercore-stopped")
}
-//startGRPCService creates the grpc service handlers, registers it to the grpc server
-// and starts the server
+//startGRPCService creates the grpc service handlers, registers it to the grpc server and starts the server
func (core *Core) startGRPCService(ctx context.Context) {
// create an insecure gserver server
core.grpcServer = grpcserver.NewGrpcServer(core.config.GrpcHost, core.config.GrpcPort, nil, false)
log.Info("grpc-server-created")
- //core.grpcNBIAPIHandler = NewAPIHandler(core.deviceMgr, core.logicalDeviceMgr, core.adapterMgr, core.config.InCompetingMode, core.config.LongRunningRequestTimeout, core.config.DefaultRequestTimeout)
core.grpcNBIAPIHandler = NewAPIHandler(core)
log.Infow("grpc-handler", log.Fields{"core_binding_key": core.config.CoreBindingKey})
core.logicalDeviceMgr.setGrpcNbiHandler(core.grpcNBIAPIHandler)
@@ -230,9 +228,6 @@
}
func (core *Core) startDeviceManager(ctx context.Context) {
- // TODO: Interaction between the logicaldevicemanager and devicemanager should mostly occur via
- // callbacks. For now, until the model is ready, devicemanager will keep a reference to the
- // logicaldevicemanager to initiate the creation of logical devices
log.Info("DeviceManager-Starting...")
core.deviceMgr.start(ctx, core.logicalDeviceMgr)
log.Info("DeviceManager-Started")
diff --git a/rw_core/core/device_ownership.go b/rw_core/core/device_ownership.go
index 49d860a..6efbdb8 100644
--- a/rw_core/core/device_ownership.go
+++ b/rw_core/core/device_ownership.go
@@ -47,10 +47,10 @@
deviceMgr *DeviceManager
logicalDeviceMgr *LogicalDeviceManager
deviceMap map[string]*ownership
- deviceMapLock *sync.RWMutex
+ deviceMapLock sync.RWMutex
deviceToKeyMap map[string]string
- deviceToKeyMapLock *sync.RWMutex
- ownershipLock *sync.RWMutex
+ deviceToKeyMapLock sync.RWMutex
+ ownershipLock sync.RWMutex
}
func NewDeviceOwnership(id string, kvClient kvstore.Client, deviceMgr *DeviceManager, logicalDeviceMgr *LogicalDeviceManager, ownershipPrefix string, reservationTimeout int64) *DeviceOwnership {
@@ -63,10 +63,10 @@
deviceOwnership.ownershipPrefix = ownershipPrefix
deviceOwnership.reservationTimeout = reservationTimeout
deviceOwnership.deviceMap = make(map[string]*ownership)
- deviceOwnership.deviceMapLock = &sync.RWMutex{}
+ deviceOwnership.deviceMapLock = sync.RWMutex{}
deviceOwnership.deviceToKeyMap = make(map[string]string)
- deviceOwnership.deviceToKeyMapLock = &sync.RWMutex{}
- deviceOwnership.ownershipLock = &sync.RWMutex{}
+ deviceOwnership.deviceToKeyMapLock = sync.RWMutex{}
+ deviceOwnership.ownershipLock = sync.RWMutex{}
return &deviceOwnership
}
diff --git a/rw_core/core/grpc_nbi_api_handler.go b/rw_core/core/grpc_nbi_api_handler.go
index 8f7b328..d5e0305 100755
--- a/rw_core/core/grpc_nbi_api_handler.go
+++ b/rw_core/core/grpc_nbi_api_handler.go
@@ -121,8 +121,9 @@
return handler.coreInCompetingMode
}
-// acquireRequestForList handles transaction processing for list requests, i.e. when there are no specific id requested.
-func (handler *APIHandler) acquireRequestForList(ctx context.Context, maxTimeout ...int64) (*KVTransaction, error) {
+// acquireRequest handles transaction processing for device creation and list requests, i.e. when there are no
+// specific id requested (list scenario) or id present in the request (creation use case).
+func (handler *APIHandler) acquireRequest(ctx context.Context, maxTimeout ...int64) (*KVTransaction, error) {
timeout := handler.defaultRequestTimeout
if len(maxTimeout) > 0 {
timeout = maxTimeout[0]
@@ -138,37 +139,6 @@
}
}
-// acquireRequest handles transaction processing for creation of new devices
-func (handler *APIHandler) acquireRequest(ctx context.Context, id interface{}, maxTimeout ...int64) (*KVTransaction, error) {
- timeout := handler.defaultRequestTimeout
- if len(maxTimeout) > 0 {
- timeout = maxTimeout[0]
- }
- log.Debugw("transaction-timeout", log.Fields{"timeout": timeout})
- txn, err := handler.createKvTransaction(ctx)
- if txn == nil {
- return nil, err
- } else if txn.Acquired(timeout) {
- return txn, nil
- } else {
- if id != nil {
- // The id can either be a device Id or a logical device id.
- if dId, ok := id.(*utils.DeviceID); ok {
- // Since this core has not processed this request, let's load the device, along with its extended
- // family (parents and children) in memory. This will keep this core in-sync with its paired core as
- // much as possible. The watch feature in the core model will ensure that the contents of those objects in
- // memory are in sync.
- time.Sleep(2 * time.Second)
- go handler.deviceMgr.load(dId.Id)
- } else if ldId, ok := id.(*utils.LogicalDeviceID); ok {
- // This will load the logical device along with its children and grandchildren
- go handler.logicalDeviceMgr.load(ldId.Id)
- }
- }
- return nil, errors.New("failed-to-seize-request")
- }
-}
-
// takeRequestOwnership creates a transaction in the dB for this request and handles the logic of transaction
// acquisition. If the device is owned by this Core (in a core-pair) then acquire the transaction with a
// timeout value (in the event of a timeout the other Core in the core-pair will proceed with the transaction). If the
@@ -404,7 +374,7 @@
func (handler *APIHandler) ListLogicalDevices(ctx context.Context, empty *empty.Empty) (*voltha.LogicalDevices, error) {
log.Debug("ListLogicalDevices-request")
if handler.competeForTransaction() {
- if txn, err := handler.acquireRequestForList(ctx); err != nil {
+ if txn, err := handler.acquireRequest(ctx); err != nil {
return &voltha.LogicalDevices{}, err
} else {
defer txn.Close()
@@ -468,7 +438,8 @@
}
if handler.competeForTransaction() {
- if txn, err := handler.acquireRequest(ctx, &utils.DeviceID{Id: device.Id}); err != nil {
+ // There are no device Id present in this function.
+ if txn, err := handler.acquireRequest(ctx); err != nil {
return &voltha.Device{}, err
} else {
defer txn.Close()