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