[VOL-2164] Update rw-core to use the Async Kafka API

This commit consists of the following:

1. Process per-device requests in the Core in the order they are
received. If there are lots of requests on a given device then
there will be some latencies introduced due to ordering.  With
recent changes in the model along with keeping the request lock
to a minimal then these latencies are reduced.  Testing did not
show and noticeable latencies.

2) Keep the request lock from the moment a request started
processing to the moment that request is sent to kafka (when
applicable).  Adapter responses are received and processed
asynchronously. Therefore, an adapter can takes all the time it
needs to process a transaction.  The Core still has a context
with timeout (configurable) to cater for cases where the adapter
does not return a response.

3) Adapter requests are processed to completion before sending a
reponse back to the adapter.  Previously, in some cases, a
separate go routine was created to process the request and a
successful response is sent to the adapter.  Now if the request
fails then the adapter will receive an error. The adapter
requests for a given device are therefore processed in the
order they are received.

4) Some changes are made when retrieving a handler to execute
a device state transition.  This was necessary as there was some
transition overlap found.

Update after multiple reviews.

Change-Id: I55a189efec1549a662f2d71e18e6eca9015a3a17
diff --git a/rw_core/core/grpc_nbi_api_handler_test.go b/rw_core/core/grpc_nbi_api_handler_test.go
index 1b956d2..662302c 100755
--- a/rw_core/core/grpc_nbi_api_handler_test.go
+++ b/rw_core/core/grpc_nbi_api_handler_test.go
@@ -83,8 +83,8 @@
 	defer cancel()
 	cfg := config.NewRWCoreFlags()
 	cfg.CorePairTopic = "rw_core"
-	cfg.DefaultRequestTimeout = nb.defaultTimeout.Nanoseconds() / 1000000 //TODO: change when Core changes to Duration
-	cfg.DefaultCoreTimeout = nb.defaultTimeout.Nanoseconds() / 1000000
+	cfg.DefaultRequestTimeout = nb.defaultTimeout
+	cfg.DefaultCoreTimeout = nb.defaultTimeout
 	cfg.KVStorePort = nb.kvClientPort
 	cfg.InCompetingMode = inCompeteMode
 	grpcPort, err := freeport.GetFreePort()
@@ -287,9 +287,9 @@
 	assert.NotNil(t, devices)
 	assert.Equal(t, 0, len(devices.Items))
 	adapters, err := nbi.ListAdapters(getContext(), &empty.Empty{})
+	assert.Equal(t, 0, len(adapters.Items))
 	assert.Nil(t, err)
 	assert.NotNil(t, adapters)
-	assert.Equal(t, 0, len(adapters.Items))
 }
 
 func (nb *NBTest) testAdapterRegistration(t *testing.T, nbi *APIHandler) {
@@ -362,7 +362,7 @@
 	var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool {
 		return devices != nil && len(devices.Items) == 0
 	}
-	err = waitUntilConditionForDevices(5*time.Second, nbi, vFunction)
+	err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction)
 	assert.Nil(t, err)
 }
 
@@ -385,7 +385,7 @@
 	var vdFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool {
 		return devices != nil && len(devices.Items) == 0
 	}
-	err = waitUntilConditionForDevices(5*time.Second, nbi, vdFunction)
+	err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vdFunction)
 	assert.Nil(t, err)
 
 	// Create a logical device monitor will automatically send trap and eapol flows to the devices being enables
@@ -884,6 +884,7 @@
 
 	// Listen for port events
 	processedLogicalPorts := 0
+	start := time.Now()
 	for event := range nbi.changeEventQueue {
 		startingVlan++
 		if portStatus, ok := (event.Event).(*ofp.ChangeEvent_PortStatus); ok {
@@ -896,6 +897,7 @@
 			}
 		}
 		if processedLogicalPorts >= numNNIPorts+numUNIPorts {
+			fmt.Println("Total time to send all flows:", time.Since(start))
 			break
 		}
 	}
@@ -930,6 +932,8 @@
 	}
 	defer pprof.StopCPUProfile()
 
+	//log.SetPackageLogLevel("github.com/opencord/voltha-go/rw_core/core", log.DebugLevel)
+
 	nb := newNBTest()
 	assert.NotNil(t, nb)