Commit 0bb072e4 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added thread to keep connection alive

parent 757553a2
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8 (deployer)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
......
FROM python:3.7-buster
FROM python:3.8-buster
RUN apt-get install ansible
RUN apt update -y && apt-get install ansible -y
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
......@@ -11,6 +11,4 @@ RUN pip3 install --no-cache-dir -r requirements.txt
COPY . /usr/src/app
EXPOSE 8081
ENTRYPOINT ["python3 __main__.py $RABBITMQ_HOST deployer_queue"]
CMD python3 __main__.py $RABBITMQ_HOST deployer
......@@ -41,10 +41,13 @@ def init_chanel(args):
def start(this_channel):
this_channel.basic_qos(prefetch_count=1)
this_channel.basic_consume(queue=queue_name, on_message_callback=on_request)
logger.info(" [x] Awaiting RPC requests")
this_channel.start_consuming()
try:
this_channel.basic_qos(prefetch_count=1)
this_channel.basic_consume(queue=queue_name, on_message_callback=on_request)
logger.info(" [x] Awaiting RPC requests")
this_channel.start_consuming()
except:
exit(-1)
def on_request(ch, method, props, body):
......@@ -93,7 +96,7 @@ def handle_delivery(message):
tosca_template_dict = tosca.add_tokens(tokens, tosca_template_dict)
tosca_template_dict = tosca.add_dashboard_url(k8s_service.get_dashboard_url(vms),tosca_template_dict)
tosca_template_dict = tosca.add_dashboard_url(k8s_service.get_dashboard_url(vms), tosca_template_dict)
response = {'toscaTemplate': tosca_template_dict}
output_current_milli_time = int(round(time.time() * 1000))
......
......@@ -2,4 +2,8 @@ pika==1.1.0
names==0.3.0
networkx==2.4
requests==2.22.0
ansible==2.9.2
\ No newline at end of file
wheel==0.34.1
pyyaml==5.3
tosca-parser ==1.7.0
matplotlib==3.1.2
ansible==2.9.4
version: '3'
version: '3.7'
services:
mongo:
image: mongo:4
ports:
- "27017:27017"
- "27017:27017"
rabbit:
image: rabbitmq:3.8-management
......@@ -12,8 +12,7 @@ services:
- "5671-5672:5671-5672"
- "15672:15672"
- "4369:4369"
- "15671:15671"
- "15671:15671"
planner:
depends_on:
......@@ -21,8 +20,8 @@ services:
- sure-tosca
image: alogo53/planner:3.0.0
environment:
RABBITMQ_HOST: rabbit
RABBITMQ_HOST: rabbit
provisioner:
depends_on:
- rabbit
......@@ -38,7 +37,7 @@ services:
- sure-tosca
image: alogo53/deployer:3.0.0
environment:
RABBITMQ_HOST: rabbit
RABBITMQ_HOST: rabbit
manager:
depends_on:
......@@ -51,12 +50,12 @@ services:
MONGO_HOST: mongo
SURE_TOSCA_BASE_PATH: http://sure-tosca:8081/tosca-sure/1.0.0
ports:
- "30000:8080"
- "30000:8080"
sure-tosca:
image: alogo53/sure-tosca:3.0.0
ports:
- "30001:8081"
- "30001:8081"
logspout:
ports:
......@@ -66,9 +65,4 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
environment:
publish: "127.0.0.1:30002:80"
image: gliderlabs/logspout:latest
#docker-compose build
#docker-compose up -d
image: gliderlabs/logspout:latest
#!/bin/bash
echo "----------Building manager Docker--------------"
cd manager && mvn -Dmaven.test.skip=true dockerfile:build
status=$?
[ $status -eq 0 ] && echo "build successful" || exit -1
cd ../
echo "----------Building provisioner Docker--------------"
cd provisioner && mvn -Dmaven.test.skip=true dockerfile:build
[ $status -eq 0 ] && echo "build successful" || exit -1
cd ../
echo "----------Building sure_tosca-flask-server Docker--------------"
cd sure_tosca-flask-server && docker build -t alogo53/sure-tosca:3.0.0 .
[ $status -eq 0 ] && echo "build successful" || exit -1
echo "----------Building planner Docker--------------"
cd ../
cd planner && docker build -t alogo53/planner:3.0.0 .
[ $status -eq 0 ] && echo "build successful" || exit -1
echo "----------Building deployer Docker--------------"
cd ../
cd planner && docker build -t alogo53/deployer:3.0.0 .
cd deployer && docker build -t alogo53/deployer:3.0.0 .
[ $status -eq 0 ] && echo "build successful" || exit -1
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (planner)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (planner)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.6 (planner)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.8 (planner)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
FROM python:3.7-buster
FROM python:3.8-buster
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
......
......@@ -7,11 +7,16 @@ import os.path
import tempfile
import time
import logging
from concurrent.futures import thread
from threading import Thread
import pika
import yaml
import sys
import copy
from time import sleep
from toscaparser.tosca_template import ToscaTemplate
from planner.planner import Planner
......@@ -20,7 +25,6 @@ from util import tosca_helper
logger = logging.getLogger(__name__)
# if not getattr(logger, 'handler_set', None):
# logger.setLevel(logging.INFO)
# h = logging.StreamHandler()
......@@ -29,6 +33,8 @@ logger = logging.getLogger(__name__)
# logger.addHandler(h)
# logger.handler_set = True
done = False
def init_chanel(args):
global rabbitmq_host
......@@ -41,7 +47,7 @@ def init_chanel(args):
connection = pika.BlockingConnection(pika.ConnectionParameters(host=rabbitmq_host))
channel = connection.channel()
channel.queue_declare(queue=queue_name)
return channel
return channel, connection
def start(this_channel):
......@@ -113,6 +119,12 @@ def handle_delivery(message):
return json.dumps(response)
def threaded_function(args):
while not done:
connection.process_data_events()
sleep(5)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
if sys.argv[1] == "test_local":
......@@ -133,7 +145,20 @@ if __name__ == "__main__":
else:
print("Input args: " + sys.argv[0] + ' ' + sys.argv[1] + ' ' + sys.argv[2])
logger.info("Input args: " + sys.argv[0] + ' ' + sys.argv[1] + ' ' + sys.argv[2])
channel = init_chanel(sys.argv)
global channel
global connection
channel, connection = init_chanel(sys.argv)
global queue_name
queue_name = sys.argv[2]
start(channel)
# start(channel)
thread = Thread(target=threaded_function, args=(1,))
thread.start()
logger.info("Awaiting RPC requests")
try:
channel.start_consuming()
except KeyboardInterrupt:
# thread.stop()
done = True
thread.join()
logger.info("Threads successfully closed")
......@@ -3,8 +3,11 @@ COPY target/provisioner-3.0.0-jar-with-dependencies.jar provisioner-3.0.0-jar-wi
COPY etc/ etc
CMD jar -xf provisioner-3.0.0-jar-with-dependencies.jar application.properties && \
cat application.properties && \
sed -ie "s#^message.broker.host=.*#message.broker.host=$RABBITMQ_HOST#" application.properties && \
sed -ie "s#^sure_tosca.base.path=.*#sure-tosca.base.path=$SURE_TOSCA_BASE_PATH#" application.properties && \
echo "cloud.storm.db.path=/etc/UD" >> application.properties && \
cat application.properties && \
jar -uf provisioner-3.0.0-jar-with-dependencies.jar application.properties && \
sleep 5 && \
java -jar provisioner-3.0.0-jar-with-dependencies.jar
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (sure_tosca-flask-server)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (sure_tosca-flask-server)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
......
......@@ -4,10 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (sure_tosca-flask-server)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.8 (sure_tosca-flask-server)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
......@@ -391,7 +391,7 @@ def set_node_properties(id, properties, node_name): # noqa: E501
if res:
return res
return 'Not Found', 404
k
def upload_tosca_template(file): # noqa: E501
"""upload a tosca template description file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment