[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/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()