From 715a662f0d5659ff9b392991324d7178d554a19b Mon Sep 17 00:00:00 2001 From: Manuel Imperiale Date: Wed, 5 Dec 2018 15:15:15 +0100 Subject: [PATCH] NOISSUE - Add LoRa route map validation and fix LoRa messages URL (#491) * Add route map validation and fix LoRa messages URL Signed-off-by: Manuel Imperiale * Fix reviews Signed-off-by: Manuel Imperiale * Fix reviews Signed-off-by: Manuel Imperiale * Rm private error comments Signed-off-by: Manuel Imperiale * Fix typo Signed-off-by: Manuel Imperiale * Add runlora command in Makefile Signed-off-by: Manuel Imperiale --- Makefile | 5 ++++ docker/addons/lora-adapter/docker-compose.yml | 2 +- lora/redis/streams.go | 28 ++++++++++++++++--- lora/service.go | 4 +-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 77330cb0..bee81456 100644 --- a/Makefile +++ b/Makefile @@ -96,3 +96,8 @@ rundev: run: docker-compose -f docker/docker-compose.yml up + +runlora: + docker-compose -f docker/docker-compose.yml up -d + docker-compose -f docker/addons/influxdb-writer/docker-compose.yml up -d + docker-compose -f docker/addons/lora-adapter/docker-compose.yml up diff --git a/docker/addons/lora-adapter/docker-compose.yml b/docker/addons/lora-adapter/docker-compose.yml index 95f2459e..73a1c553 100644 --- a/docker/addons/lora-adapter/docker-compose.yml +++ b/docker/addons/lora-adapter/docker-compose.yml @@ -27,7 +27,7 @@ services: MF_LORA_ADAPTER_LOG_LEVEL: debug MF_THINGS_ES_URL: things-redis:6379 MF_LORA_ADAPTER_ROUTEMAP_URL: lora-redis:6379 - MF_LORA_ADAPTER_LORA_MESSAGE_URL: tcp://159.65.205.240:1883 + MF_LORA_ADAPTER_LORA_MESSAGE_URL: tcp://lora.mqtt.mainflux.io:1883 MF_LORA_ADAPTER_HTTP_PORT: 8187 MF_NATS_URL: nats://nats:4222 ports: diff --git a/lora/redis/streams.go b/lora/redis/streams.go index c4739997..a7f11829 100644 --- a/lora/redis/streams.go +++ b/lora/redis/streams.go @@ -27,6 +27,14 @@ const ( channelRemove = channelPrefix + "remove" ) +var ( + errMetadataType = errors.New("metadatada is not of type lora") + + errMetadataAppID = errors.New("application ID not found in channel metadatada") + + errMetadataDevEUI = errors.New("device EUI not found in thing metadatada") +) + // EventStore represents event source for things and channels provisioning. type EventStore interface { // Subscribes to geven subject and receives events. @@ -155,7 +163,10 @@ func (es eventStore) handleCreateThing(cte createThingEvent) error { } if em.Type != protocol { - return errors.New("Lora protocol not found in thing metadatada") + return errMetadataType + } + if em.DevEUI != "" { + return errMetadataDevEUI } return es.svc.CreateThing(cte.id, em.DevEUI) @@ -168,7 +179,10 @@ func (es eventStore) handleUpdateThing(ute updateThingEvent) error { } if em.Type != protocol { - return errors.New("Lora protocol not found in thing metadatada") + return errMetadataType + } + if em.DevEUI != "" { + return errMetadataDevEUI } return es.svc.CreateThing(ute.id, em.DevEUI) @@ -185,7 +199,10 @@ func (es eventStore) handleCreateChannel(cce createChannelEvent) error { } if cm.Type != protocol { - return errors.New("Lora protocol not found in channel metadatada") + return errMetadataType + } + if cm.AppID != "" { + return errMetadataAppID } return es.svc.CreateChannel(cce.id, cm.AppID) @@ -198,7 +215,10 @@ func (es eventStore) handleUpdateChannel(uce updateChannelEvent) error { } if cm.Type != protocol { - return errors.New("Lora protocol not found in channel metadatada") + return errMetadataType + } + if cm.AppID != "" { + return errMetadataAppID } return es.svc.UpdateChannel(uce.id, cm.AppID) diff --git a/lora/service.go b/lora/service.go index a85ca103..aa12ea45 100644 --- a/lora/service.go +++ b/lora/service.go @@ -22,10 +22,10 @@ var ( ErrMalformedMessage = errors.New("malformed message received") // ErrNotFoundDev indicates a non-existent route map for a device EUI. - ErrNotFoundDev = errors.New("route map not found for device EUI") + ErrNotFoundDev = errors.New("route map not found for this device EUI") // ErrNotFoundApp indicates a non-existent route map for an application ID. - ErrNotFoundApp = errors.New("route map not found for application ID") + ErrNotFoundApp = errors.New("route map not found for this application ID") ) // Service specifies an API that must be fullfiled by the domain service