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