[VOL-1417]
Fix to the issue where discovery events were not being processed.
Also some minor tweaks to the affinity router's build system.
Change-Id: I73bd9ea5e747dcfacb2bc5c2c8e77a7edbf318a3
diff --git a/Makefile b/Makefile
index 3583c94..4704796 100644
--- a/Makefile
+++ b/Makefile
@@ -86,10 +86,10 @@
docker build $(DOCKER_BUILD_ARGS) -t base:latest -f docker/Dockerfile.base .
afrouter:
- docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}arouter:${TAG} -f docker/Dockerfile.arouter .
+ docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouter:${TAG} -f docker/Dockerfile.arouter .
arouterd:
- docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}arouterd:${TAG} -f docker/Dockerfile.arouterd .
+ docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}afrouterd:${TAG} -f docker/Dockerfile.arouterd .
rw_core:
docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-rw-core:${TAG} -f docker/Dockerfile.rw_core .
diff --git a/arouterd/arouterd.go b/arouterd/arouterd.go
index 0ea0b49..06f4628 100644
--- a/arouterd/arouterd.go
+++ b/arouterd/arouterd.go
@@ -671,23 +671,44 @@
}
}
+func getBackendForCore(coreId string, coreGroups [][]*rwPod) string {
+ for _,v := range(coreGroups) {
+ for _,v2 := range(v) {
+ if v2.name == coreId {
+ return v2.backend
+ }
+ }
+ }
+ log.Errorf("No backend found for core %s\n", coreId)
+ return ""
+}
+
func monitorDiscovery(client pb.ConfigurationClient,
- ch <-chan *ic.InterContainerMessage) {
+ ch <-chan *ic.InterContainerMessage,
+ coreGroups [][]*rwPod) {
+ var id map[string]struct{} = make(map[string]struct{})
+
select {
case msg := <-ch:
log.Debugf("Received a device discovery notification")
- _ = msg
- requestBody := &ic.InterContainerRequestBody{}
- if err := ptypes.UnmarshalAny(msg.Body, requestBody); err != nil {
+ device := &ic.DeviceDiscovered{}
+ if err := ptypes.UnmarshalAny(msg.Body, device); err != nil {
log.Errorf("Could not unmarshal received notification %v", msg)
} else {
- // Do something with the message here
+ // Set the affinity of the discovered device.
+ if be := getBackendForCore(device.Id, coreGroups); be != "" {
+ id[device.Id]=struct{}{}
+ setAffinity(client, id, be)
+ } else {
+ log.Error("Cant use an empty string as a backend name")
+ }
}
break
}
}
-func startDiscoveryMonitor(client pb.ConfigurationClient) error {
+func startDiscoveryMonitor(client pb.ConfigurationClient,
+ coreGroups [][]*rwPod) error {
var ch <-chan *ic.InterContainerMessage
// Connect to kafka for discovery events
topic := &kafka.Topic{Name: "AffinityRouter"}
@@ -698,7 +719,7 @@
log.Error("Could not subscribe to the 'AffinityRouter' channel, discovery disabled")
return err
}
- go monitorDiscovery(client, ch)
+ go monitorDiscovery(client, ch, coreGroups)
return nil
}
@@ -816,7 +837,7 @@
}
log.Debug("Starting discovery monitoring")
- startDiscoveryMonitor(client)
+ startDiscoveryMonitor(client, coreGroups)
log.Debugf("Starting core monitoring")
startCoreMonitor(client, clientset, coreFltr, coreGroups) // Never returns
diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base
index 0a37a23..3e6098c 100644
--- a/docker/Dockerfile.base
+++ b/docker/Dockerfile.base
@@ -13,6 +13,7 @@
RUN ["mkdir", "-p", "/src", "src/protos"]
RUN ["mkdir", "-p", "$GOPATH/src", "$GOPATH/pkg", "$GOPATH/bin"]
RUN ["mkdir", "-p", "$GOPATH/src/github.com/opencord/voltha/protos/go"]
+RUN ["mkdir", "-p", "/share"]
# Install golang protobuf
#RUN go get github.com/golang/protobuf/protoc-gen-go
@@ -49,26 +50,4 @@
# Compile protobuf files
RUN sh /src/protos/build_protos.sh /src/protos
-# Build rw_core
-#RUN cd afrouter && go build -o /src/afrouter
-
-
-# -------------
-# Image creation stage
-
-#FROM alpine:3.6
-
-# Set the working directory
-#WORKDIR /app
-
-# Copy required files
-#COPY --from=build-env /src/afrouter /app/
-#COPY --from=build-env /src/arouter.json /app/
-#COPY --from=build-env /src/protos/voltha.pb /app/
-#WORKDIR config
-#WORKDIR /app
-
-#CMD cd /app && ./arouter -config config/arouter.voltha2.json
-
-# Set the config volume
-
+VOLUME /share