Enable celery for vesagent workers for ocata 05/55805/1
authorYun Huang <yun.huang@windriver.com>
Wed, 4 Jul 2018 09:45:51 +0000 (17:45 +0800)
committerYun Huang <yun.huang@windriver.com>
Wed, 4 Jul 2018 09:45:51 +0000 (17:45 +0800)
Change-Id: Ibf07426ec3fa8b9c8b866d95a1e49537094cef70
Issue-ID: MULTICLOUD-230
Signed-off-by: Yun Huang <yun.huang@windriver.com>
ocata/docker/Dockerfile
ocata/ocata/__init__.py
ocata/ocata/celery.py [new file with mode: 0644]
ocata/requirements.txt
ocata/run.sh

index cca1cf8..97bbc7b 100644 (file)
@@ -18,7 +18,7 @@ ENV AAI_PASSWORD "AAI"
 EXPOSE 9006
 
 WORKDIR /opt/ocata
-RUN apt-get update && apt-get install -y memcached unzip
+RUN apt-get update && apt-get install -y memcached unzip rabbitmq-server
 RUN wget -O /opt/multicloud-openstack-ocata.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.multicloud.openstack&a=multicloud-openstack-ocata&e=zip&v=LATEST" && \
     unzip -q -o -B /opt/multicloud-openstack-ocata.zip -d /opt/ && \
     rm -f /opt/multicloud-openstack-ocata.zip
index afa702d..f7fd66a 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import, unicode_literals
+
+# This will make sure the app is always imported when
+# Django starts so that shared_task will use this app.
+from .celery import app as celery_app
+
+__all__ = ['celery_app']
diff --git a/ocata/ocata/celery.py b/ocata/ocata/celery.py
new file mode 100644 (file)
index 0000000..ee533b5
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (c) 2017-2018 Wind River Systems, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from __future__ import absolute_import, unicode_literals
+import os
+from celery import Celery
+import logging
+
+# set the default Django settings module for the 'celery' program.
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ocata.settings')
+
+app = Celery('ocata')
+
+# Using a string here means the worker doesn't have to serialize
+# the configuration object to child processes.
+# - namespace='CELERY' means all celery-related configuration keys
+#   should have a `CELERY_` prefix.
+app.config_from_object('django.conf:settings', namespace='CELERY')
+
+# Load task modules from all registered Django app configs.
+app.autodiscover_tasks()
+
+logger = logging.getLogger(__name__)
+
+@app.task(bind=True)
+def debug_task(self):
+    logger.debug("self.request")
index 5408c53..260e1ba 100644 (file)
@@ -21,3 +21,7 @@ unittest_xml_reporting==1.12.0
 
 # for onap logging 
 onappylog>=1.0.6
+
+# for background tasks
+celery >= 4.0
+
index 70af4df..541eaf1 100755 (executable)
@@ -15,4 +15,9 @@
 
 memcached -d -m 2048 -u root -c 1024 -p 11211 -P /tmp/memcached1.pid
 export PYTHONPATH=lib/share
+
+service rabbitmq-server restart
+# make sure only 1 worker due to missing the synchronization between workers now
+nohup celery -A ocata worker --concurrency=1 --loglevel=debug &
+
 uwsgi --http :9006 --module ocata.wsgi --master --processes 4