Commit ebaa5dac authored by Spiros Koulouzis's avatar Spiros Koulouzis

make sure we only update changed nodes

parent 8edc8b29
......@@ -90,18 +90,14 @@ def handle_delivery(message):
semaphore_password=semaphore_password, vms=tosca_helper.get_vms())
try:
for node_pair in nodes_pairs:
updated_node_pairs = deployService.deploy(node_pair)
for updated_node in updated_node_pairs:
updated_node = deployService.deploy(node_pair)
if isinstance(updated_node, list):
for node in updated_node:
tosca_helper.set_node(node,tosca_template_dict)
tosca_template_dict = tosca_helper.set_node(node,tosca_template_dict)
logger.info("tosca_template_dict :" + json.dumps(tosca_template_dict))
else:
tosca_helper.set_node(updated_node, tosca_template_dict)
except Exception as e:
track = traceback.format_exc()
print(track)
raise
tosca_template_dict = tosca_helper.set_node(updated_node, tosca_template_dict)
logger.info("tosca_template_dict :" + json.dumps(tosca_template_dict))
response = {'toscaTemplate': tosca_template_dict}
output_current_milli_time = int(round(time.time() * 1000))
......@@ -109,6 +105,10 @@ def handle_delivery(message):
logger.info("Returning Deployment")
logger.info("Output message:" + json.dumps(response))
return json.dumps(response)
except Exception as e:
track = traceback.format_exc()
print(track)
raise
def threaded_function(args):
......
......@@ -130,6 +130,4 @@ class AnsibleService:
logger.info('task name: ' + name + ', task status: ' + str(task.status))
last_status = this_status
sleep(3)
if 'k8s/create_k8s_dashboard.yaml' == playbook_name:
print(playbook_name)
return task_id
......@@ -38,12 +38,12 @@ class DeployService:
env_vars = self.get_env_vars(nodes_pair)
if 'Standard' in interface_types:
task_outputs = ansible_service.execute(nodes_pair, 'Standard', self.vms, env_vars=env_vars)
nodes_pair = self.set_attributes(task_outputs,nodes_pair)
source = self.set_attributes(task_outputs,source)
if 'Kubernetes' in interface_types:
task_outputs = ansible_service.execute(nodes_pair, 'Kubernetes', self.vms, env_vars=env_vars)
nodes_pair = self.set_attributes(task_outputs,nodes_pair)
source = self.set_attributes(task_outputs,source)
return nodes_pair
return source
def get_env_vars(self, nodes_pair):
target = nodes_pair[0]
......@@ -55,15 +55,17 @@ class DeployService:
env_vars['CONTAINER_PORT'] = source.node_template.properties['ports'][0].split(':')[1]
return env_vars
def set_attributes(self, task_outputs,nodes_pair):
target = nodes_pair[0]
source = nodes_pair[1]
def set_attributes(self, task_outputs,source):
# target = nodes_pair[0]
# source = nodes_pair[1]
if source.node_template.type == 'tosca.nodes.QC.docker.Orchestrator.Kubernetes':
source = self.set_kubernetes_attributes(source=source,task_outputs=task_outputs)
lst = list(nodes_pair)
lst[1] = source
nodes_pair = tuple(lst)
return nodes_pair
if source.node_template.type == 'tosca.nodes.QC.Container.Application.Docker':
source = self.set_docker_attributes(source=source, task_outputs=task_outputs)
# lst = list(nodes_pair)
# lst[1] = source
# nodes_pair = tuple(lst)
return source
......@@ -130,7 +132,7 @@ class DeployService:
if 'dashboard_url' not in source.node_template.attributes:
dashboard_url = ''
attributes['dashboard_url'] = tokens
attributes['dashboard_url'] = dashboard_url
else:
dashboard_url = attributes['dashboard_url']
......@@ -152,3 +154,18 @@ class DeployService:
attributes['dashboard_url'] = dashboard_url
logger.info('source.node_template.attributes: ' + str(attributes))
return source
def set_docker_attributes(self, source, task_outputs):
attributes = source.node_template.attributes
if 'service_url' not in source.node_template.attributes:
service_url = ''
attributes['service_url'] = service_url
for task_output_key in task_outputs:
task_output = task_outputs[task_output_key]
k8s_services = self.parse_ansible_var('k8s_services', task_output)
service_port = self.get_service_port(k8s_services, source.name, 'nodePort')
if service_port:
service_url = 'http://' + self.master_ip + ':' + str(service_port)
attributes['service_url'] = service_url
logger.info('source.node_template.attributes: ' + str(attributes))
return source
import copy
import os
import sys
import urllib.request
from sure_tosca_client import Configuration, ApiClient
from sure_tosca_client import Configuration, ApiClient, NodeTemplate
from sure_tosca_client.api import default_api
......@@ -76,7 +77,7 @@ class ToscaHelper:
node_templates = tosca_template_dict['topology_template']['node_templates']
for node_name in node_templates:
if node_name == updated_node.name:
node_templates[node_name] = updated_node.node_template
node_templates[node_name] = updated_node.node_template.to_dict()
return tosca_template_dict
......
......@@ -93,15 +93,15 @@ services:
CLOUD_STORM_SECRET: 456
CREDENTIAL_SECRET: 123
deployer:
depends_on:
- rabbit
- sure-tosca
image: deployer:3.0.0
environment:
RABBITMQ_HOST: rabbit
SURE_TOSCA_BASE_PATH: http://sure-tosca:8081/tosca-sure/1.0.0
SEMAPHORE_BASE_PATH: http://semaphore:3000/api
#deployer:
#depends_on:
#- rabbit
#- sure-tosca
#image: deployer:3.0.0
#environment:
#RABBITMQ_HOST: rabbit
#SURE_TOSCA_BASE_PATH: http://sure-tosca:8081/tosca-sure/1.0.0
#SEMAPHORE_BASE_PATH: http://semaphore:3000/api
......
......@@ -9,10 +9,10 @@ events {
http {
proxy_connect_timeout 1200;
proxy_send_timeout 1200;
proxy_read_timeout 1200;
send_timeout 1200;
proxy_connect_timeout 9200;
proxy_send_timeout 9200;
proxy_read_timeout 9200;
send_timeout 9200;
tcp_nodelay on;
......
......@@ -14,9 +14,10 @@ from __future__ import absolute_import
import os
import unittest
from urllib.error import HTTPError
import urllib3
from urllib.request import urlopen
import ssl
import sure_tosca_client
from sure_tosca_client import Configuration, ApiClient
from sure_tosca_client.api.default_api import DefaultApi # noqa: E501
......@@ -28,7 +29,7 @@ class TestDefaultApi(unittest.TestCase):
def setUp(self):
configuration = Configuration()
configuration.host = 'http://127.0.0.1:8081/tosca-sure/1.0.0' #Make sure we don't have '/' on the end of url
if self.service_is_up(configuration.host):
if self.check_service_is_up(configuration.host):
configuration.verify_ssl = False
api_client = ApiClient(configuration=configuration)
self.api = sure_tosca_client.api.default_api.DefaultApi(api_client=api_client) # noqa: E501
......@@ -190,12 +191,17 @@ class TestDefaultApi(unittest.TestCase):
return file_id
def service_is_up(self, url):
def check_service_is_up(self, url):
code = None
try:
http = urllib3.PoolManager()
r = http.request('HEAD', url)
response = urlopen(url, context=ssl._create_unverified_context())
print(response)
# http = urllib3.PoolManager()
# r = http.request('HEAD', url,context=ctx)
except Exception as e:
if isinstance(e, HTTPError) and e.code == 401:
return True
return False
return True
......
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