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