mirror of
https://github.com/daniviga/bite.git
synced 2024-11-26 14:56:13 +01:00
Introduce DPS and improve kafka docker setup
This commit is contained in:
parent
398a62ded3
commit
79f5c516e0
|
@ -21,7 +21,7 @@ from django.test import TestCase, Client
|
||||||
from api.models import Device, WhiteList
|
from api.models import Device, WhiteList
|
||||||
|
|
||||||
|
|
||||||
class ApiTestCase(TestCase):
|
class DPSTestCase(TestCase):
|
||||||
c = Client()
|
c = Client()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -29,17 +29,17 @@ class ApiTestCase(TestCase):
|
||||||
Device.objects.create(serial='test1234')
|
Device.objects.create(serial='test1234')
|
||||||
|
|
||||||
def test_no_whitelist(self):
|
def test_no_whitelist(self):
|
||||||
response = self.c.post('/api/device/subscribe/',
|
response = self.c.post('/api/device/provision/',
|
||||||
{'serial': 'test12345'})
|
{'serial': 'test12345'})
|
||||||
self.assertEqual(response.status_code, 400)
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
def test_subscribe_post(self):
|
def test_provision_post(self):
|
||||||
WhiteList.objects.create(serial='test12345')
|
WhiteList.objects.create(serial='test12345')
|
||||||
response = self.c.post('/api/device/subscribe/',
|
response = self.c.post('/api/device/provision/',
|
||||||
{'serial': 'test12345'})
|
{'serial': 'test12345'})
|
||||||
self.assertEqual(response.status_code, 201)
|
self.assertEqual(response.status_code, 201)
|
||||||
|
|
||||||
def test_subscribe_get(self):
|
def test_provision_get(self):
|
||||||
response = self.c.get('/api/device/list/')
|
response = self.c.get('/api/device/list/')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
response.json()[0]['serial'], 'test1234')
|
response.json()[0]['serial'], 'test1234')
|
||||||
|
|
|
@ -33,13 +33,13 @@ Including another URLconf
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from api.views import APISubscribe
|
from api.views import DPS
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('device/subscribe/',
|
path('device/provision/',
|
||||||
APISubscribe.as_view({'post': 'create'}),
|
DPS.as_view({'post': 'create'}),
|
||||||
name='device-subscribe'),
|
name='device-provision'),
|
||||||
path('device/list/',
|
path('device/list/',
|
||||||
APISubscribe.as_view({'get': 'list'}),
|
DPS.as_view({'get': 'list'}),
|
||||||
name='device-list'),
|
name='device-list'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -23,6 +23,6 @@ from api.models import Device
|
||||||
from api.serializers import DeviceSerializer
|
from api.serializers import DeviceSerializer
|
||||||
|
|
||||||
|
|
||||||
class APISubscribe(ModelViewSet):
|
class DPS(ModelViewSet):
|
||||||
queryset = Device.objects.all()
|
queryset = Device.objects.all()
|
||||||
serializer_class = DeviceSerializer
|
serializer_class = DeviceSerializer
|
||||||
|
|
|
@ -167,11 +167,12 @@ KAFKA_BROKER = {
|
||||||
'PORT': '9092',
|
'PORT': '9092',
|
||||||
}
|
}
|
||||||
|
|
||||||
# If no local_settings.py is availble in the current folder let's try to
|
try:
|
||||||
# load it from the application root
|
from bite.local_settings import *
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from bite.production import *
|
from bite.production import *
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# If a local_setting.py does not exist
|
|
||||||
# settings in this file only will be used
|
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -37,8 +37,11 @@ services:
|
||||||
- "${CUSTOM_DOCKER_IP:-0.0.0.0}:8000:8000"
|
- "${CUSTOM_DOCKER_IP:-0.0.0.0}:8000:8000"
|
||||||
|
|
||||||
kafka:
|
kafka:
|
||||||
|
environment:
|
||||||
|
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
|
||||||
|
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
|
||||||
ports:
|
ports:
|
||||||
- "${CUSTOM_DOCKER_IP:-0.0.0.0}:9092:9092"
|
- "${CUSTOM_DOCKER_IP:-0.0.0.0}:29092:29092"
|
||||||
|
|
||||||
data-migration:
|
data-migration:
|
||||||
volumes:
|
volumes:
|
||||||
|
|
|
@ -69,8 +69,6 @@ services:
|
||||||
environment:
|
environment:
|
||||||
ZOOKEEPER_CLIENT_PORT: 2181
|
ZOOKEEPER_CLIENT_PORT: 2181
|
||||||
ZOOKEEPER_TICK_TIME: 2000
|
ZOOKEEPER_TICK_TIME: 2000
|
||||||
ports:
|
|
||||||
- 22181:2181
|
|
||||||
|
|
||||||
kafka:
|
kafka:
|
||||||
image: confluentinc/cp-kafka:latest
|
image: confluentinc/cp-kafka:latest
|
||||||
|
@ -81,8 +79,8 @@ services:
|
||||||
environment:
|
environment:
|
||||||
KAFKA_BROKER_ID: 1
|
KAFKA_BROKER_ID: 1
|
||||||
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
|
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
|
||||||
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
|
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
|
||||||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
|
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
|
||||||
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
|
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
|
||||||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ def main():
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
subscribe = "/api/device/subscribe/"
|
dps = "/api/device/provision/"
|
||||||
telemetry = "/telemetry/"
|
telemetry = "/telemetry/"
|
||||||
|
|
||||||
if args.serial is None:
|
if args.serial is None:
|
||||||
|
@ -123,7 +123,7 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
data = {"serial": args.serial}
|
data = {"serial": args.serial}
|
||||||
post_json(args.endpoint, subscribe, data)
|
post_json(args.endpoint, dps, data)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = {
|
data = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user