diff --git a/back-end/database/dev-db.db b/back-end/database/dev-db.db index daa6921..e1a8f5d 100644 Binary files a/back-end/database/dev-db.db and b/back-end/database/dev-db.db differ diff --git a/back-end/database/models/models.py b/back-end/database/models/models.py index 1d2d762..bf2a8f3 100644 --- a/back-end/database/models/models.py +++ b/back-end/database/models/models.py @@ -4,7 +4,7 @@ from ..init_db import Base -class CamType(enum.Enum): +class CamType(enum.IntEnum): webcam = 1 ip_cam = 2 local_file = 3 diff --git a/back-end/rabbitmq/rabbitMQ.py b/back-end/rabbitmq/rabbitMQ.py index f85379b..9e33c0e 100644 --- a/back-end/rabbitmq/rabbitMQ.py +++ b/back-end/rabbitmq/rabbitMQ.py @@ -1,7 +1,7 @@ from kombu import Exchange, Queue # Default RabbitMQ server URI -rabbit_url = 'amqp://rabbitmq:rabbitmq@localhost:5672//' +rabbit_url = 'amqp://rabbitmq:rabbitmq@192.168.99.100:5672//' # Define queues that will be used in the future feed_queue = Queue('feed-queue', Exchange("feed-exchange", type="direct"), routing_key='feed') diff --git a/back-end/resources/configuration.py b/back-end/resources/configuration.py index 586dac9..85d6822 100644 --- a/back-end/resources/configuration.py +++ b/back-end/resources/configuration.py @@ -45,7 +45,7 @@ def post(self): # relationship if detectiontypes is not None: for item in detectiontypes: - dt = DetectionTypes(detectionType=item) + dt = DetectionTypes(detectiontype=item) config.detections.append(dt) # commit the changes @@ -101,7 +101,7 @@ def put(self, config_ID): configuration.detections.clear() for item in detectiontypes: dt = DetectionTypes(detectionType=item) - config.detections.append(dt) + configuration.detections.append(dt) configuration.name = json_data['name'] configuration.resolution = json_data['resolution'] diff --git a/back-end/resources/feed.py b/back-end/resources/feed.py index 7c5d5e7..75a00e4 100644 --- a/back-end/resources/feed.py +++ b/back-end/resources/feed.py @@ -5,10 +5,11 @@ from flask_restful import Resource from database.models.models import Feed from database.init_db import db_session -from database.schemas.Schemas import FeedSchema +from database.schemas.Schemas import FeedSchema, DetectionTypesSchema # rabbitMQ from rabbitmq.rabbitMQ import rabbit_url, feed_queue from kombu import Connection +import json class VideoFeedListAPI(Resource): @@ -94,6 +95,9 @@ def put(self, feed_ID): if feed_ID is None: return abort(400, description="missing required parameter") else: + # get a scoped DB session + scoped_session = db_session() + feed = Feed.query.filter_by(id=feed_ID).first() if feed is None: abort(404, description=f"Feed {feed_ID} not found") @@ -104,20 +108,19 @@ def put(self, feed_ID): with Connection(rabbit_url, heartbeat=4) as conn: # flip boolean feed.active = not feed.active + # fetch schema for dumping database model class to json + dt_schema = DetectionTypesSchema() # Produce a message to RabbitMQ so detection manager can consume and start the approriate feed # with the given data. producer = conn.Producer(serializer='json') producer.publish( - # TODO: fix json serializer, for now we mock it. - #{feed.id, feed.feed_type, feed.url, feed.active}, - { 'id' : '1', 'feed_type': 'IP_CAM', 'url': 'http://test.com/file.mp4', 'active': 'true'}, + {'id': feed.id, 'feed_type': json.dumps(feed.feed_type), 'url': feed.url, 'active': feed.active, 'detections': dt_schema.dump(feed.configuration.detections, many=True), 'drawables': feed.configuration.drawables}, retry=True, exchange=feed_queue.exchange, routing_key=feed_queue.routing_key, declare=[feed_queue], # declares exchange, queue and binds. ) - # set feed to active, TODO : add active/inactive to the queue - db_session.commit() + scoped_session.commit() conn.release()