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

rename type to ARTICONF.docker.Orchestrator

parent 545802eb
tosca_definitions_version: tosca_simple_yaml_1_0
description: TOSCA example
imports:
<<<<<<< HEAD
- nodes: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/nodes.yaml
- data: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/data.yml
- capabilities: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/capabilities.yaml
- policies: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/policies.yaml
- interfaces: https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/interfaces.yml
- nodes: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/nodes.yaml
- data: https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/TOSCA/types/data.yml
- capabilities: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/capabilities.yaml
- policies: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/policies.yaml
- interfaces: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/interfaces.yml
repositories:
docker_hub: https://hub.docker.com/
......@@ -14,63 +13,24 @@ repositories:
description: >
TOSCA example
topology_template:
node_templates:
topology_template:
#topology:
#interfaces:
#CloudsStorm:
#provision:
#inputs:
#code_type: SEQ
#object_type: SubTopology
#properties:
#domain: UvA (Amsterdam, The Netherlands) XO Rack
#provider: ExoGENI
#type: tosca.nodes.ARTICONF.VM.topology
ws-pema-lifewatch:
node_templates:
mongo:
type: tosca.nodes.ARTICONF.Container.Application.Docker
properties:
ports:
- "30001:8080"
- "30001:27017"
volumes:
- db-data:/data/db
environment:
ROOT_PASSWORD: root_passwd
DATABASE: db
USER: user
PASSWORD: passwd
artifacts:
image:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: alogo53/ws-pema-lifewatch
repository: docker_hub
requirements:
- host:
capability: tosca.capabilities.ARTICONF.docker.Orchestrator
node: kubernetes
relationship: tosca.relationships.HostedOn
kubernetes:
type: tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes
properties:
min_masters_num: 1
min_workers_num: 1
interfaces:
Kubernetes:
create:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/create_k8s.yml"
install:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/install_k8s.yml"
#topology:
#type: tosca.nodes.ARTICONF.VM.topology
#properties:
#domain: "UvA (Amsterdam, The Netherlands) XO Rack"
#provider: "ExoGENI"
#interfaces:
#CloudsStorm:
#provision:
#inputs:
#code_type: "SEQ"
#object_type: "SubTopology"
file: mongo:3
repository: docker_hub
......@@ -2,7 +2,7 @@ tosca_definitions_version: tosca_simple_yaml_1_0
capability_types:
tosca.capabilities.ARTICONF.Orchestrator:
tosca.capabilities.ARTICONF.docker.Orchestrator:
derived_from: tosca.capabilities.Container
properties:
some_properties:
......
......@@ -31,11 +31,11 @@ node_types:
required: false
requirements:
- host:
capability: tosca.capabilities.ARTICONF.Orchestrator
node: tosca.nodes.ARTICONF.Orchestrator
capability: tosca.capabilities.ARTICONF.docker.Orchestrator
node: osca.nodes.ARTICONF.docker.Orchestrator
relationship: tosca.relationships.HostedOn
tosca.nodes.ARTICONF.Orchestrator:
osca.nodes.ARTICONF.docker.Orchestrator:
derived_from: tosca.nodes.ARTICONF.Root
description: a container orchestrator
requirements:
......@@ -45,7 +45,7 @@ node_types:
relationship: tosca.relationships.HostedOn
capabilities:
orchestrator:
type: tosca.capabilities.ARTICONF.Orchestrator
type: tosca.capabilities.ARTICONF.docker.Orchestrator
host:
type: tosca.capabilities.Container.Docker
container:
......@@ -65,8 +65,8 @@ node_types:
- greater_or_equal: 1
tosca.nodes.ARTICONF.Orchestrator.Kubernetes:
derived_from: tosca.nodes.ARTICONF.Orchestrator
osca.nodes.ARTICONF.docker.Orchestrator.Kubernetes:
derived_from: osca.nodes.ARTICONF.docker.Orchestrator
description: Kubernetes orchestrator
attributes:
tokens:
......@@ -84,17 +84,17 @@ node_types:
type: tosca.interfaces.ARTICONF.Kubernetes
install:
inputs:
playbook: https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/ansible_playbooks/install_k8s.yml
playbook: https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/install_k8s.yml
create:
inputs:
playbook: https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/ansible_playbooks/create_k8s.yml
playbook: https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/create_k8s.yml
configure:
inputs:
playbook: https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/ansible_playbooks/dashboard.yaml
playbook: https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/dashboard.yaml
#tosca.nodes.ARTICONF.Orchestrator.Swarm:
#derived_from: tosca.nodes.ARTICONF.Orchestrator
#osca.nodes.ARTICONF.docker.Orchestrator.Swarm:
#derived_from: osca.nodes.ARTICONF.docker.Orchestrator
#description: swarm orchestrator
#interfaces:
#Standard:
......
......@@ -12,6 +12,33 @@ from service.simple_spec_alayzer import SimpleAnalyzer
from util import tosca_helper
def add_requirements(node, missing_requirements, capable_node_name):
"""Add the requirements to the node """
for req in missing_requirements:
req[next(iter(req))]['node'] = capable_node_name
if isinstance(node, NodeTemplate):
contains_requirement = False
for node_requirement in node.requirements:
if node_requirement == req:
contains_requirement = True
break
if not contains_requirement:
node.requirements.append(req)
elif isinstance(node, dict):
type_name = next(iter(node))
if 'requirements' not in node[type_name]:
node[type_name]['requirements'] = []
node_requirements = node[type_name]['requirements']
contains_requirement = False
for node_requirement in node_requirements:
if node_requirement == req:
contains_requirement = True
break
if not contains_requirement:
node[type_name]['requirements'].append(req)
return node
class Planner:
def __init__(self, tosca_path=None, yaml_dict_tpl=None, spec_service=None):
......@@ -105,7 +132,7 @@ class Planner:
matching_node_type_name = next(iter(matching_node))
matching_node_template = tosca_helper.node_type_2_node_template(matching_node, self.all_custom_def)
# Add the requirements to the node we analyzed. e.g. docker needed host now we added the type and name of host
node = self.add_requirements(node, all_requirements, matching_node_template.name)
node = add_requirements(node, all_requirements, matching_node_template.name)
if not tosca_helper.contains_node_type(self.required_nodes, matching_node_type_name) and \
not tosca_helper.contains_node_type(self.tosca_template.nodetemplates, matching_node_type_name):
logging.info(' Adding: ' + str(matching_node_template.name))
......@@ -185,9 +212,14 @@ class Planner:
for req in all_requirements:
if 'capability' in req[next(iter(req))]:
capability = req[next(iter(req))]['capability']
logging.info(' Looking for nodes with capability: ' + capability)
# Find all nodes in the definitions that have the capability: capability
capable_nodes = self.get_node_types_by_capability(capability)
# Find nodes in node_templates that have the capability
logging.info(' Looking for nodes in node_templates with capability: ' + capability)
capable_nodes = self.get_node_templates_by_capability(capability)
if not capable_nodes:
# Find all nodes in the definitions that have the capability: capability
logging.info(' Looking for nodes in node types with capability: ' + capability)
capable_nodes = self.get_node_types_by_capability(capability)
if capable_nodes:
# Add number of matching capabilities for each node.
# Try to score matching_nodes to return one. The more requirements a node meets the better
......@@ -223,28 +255,9 @@ class Planner:
child_nodes[tosca_node_type] = self.all_node_types[tosca_node_type]
return child_nodes
def add_requirements(self, node, missing_requirements, capable_node_name):
"""Add the requirements to the node """
for req in missing_requirements:
req[next(iter(req))]['node'] = capable_node_name
if isinstance(node, NodeTemplate):
contains_requirement = False
for node_requirement in node.requirements:
if node_requirement == req:
contains_requirement = True
break
if not contains_requirement:
node.requirements.append(req)
elif isinstance(node, dict):
type_name = next(iter(node))
if 'requirements' not in node[type_name]:
node[type_name]['requirements'] = []
node_requirements = node[type_name]['requirements']
contains_requirement = False
for node_requirement in node_requirements:
if node_requirement == req:
contains_requirement = True
break
if not contains_requirement:
node[type_name]['requirements'].append(req)
return node
def get_node_templates_by_capability(self, capability):
capable_nodes = []
for node_template in self.tosca_template.nodetemplates:
for node_capability in node_template.get_capabilities():
print(node_capability)
return capable_nodes
......@@ -10,6 +10,19 @@ from service.specification_analyzer import SpecificationAnalyzer
from util import tosca_helper
def get_default_value(node_property):
if node_property and node_property.required and isinstance(node_property.value, dict) and 'required' in \
node_property.value and 'type' in node_property.value:
if node_property.default:
return {node_property.name: node_property.default}
if node_property.constraints:
for constraint in node_property.constraints:
print(constraint)
if node_property and node_property.required and node_property.value:
return {node_property.name: node_property.value}
return None
class SimpleAnalyzer(SpecificationAnalyzer):
def __init__(self, tosca_template):
......@@ -17,9 +30,7 @@ class SimpleAnalyzer(SpecificationAnalyzer):
def set_relationship_occurrences(self):
return_nodes = []
# nodes_with_occurrences_in_requirements = tosca_util.get_nodes_with_occurrences_in_requirements(
# self.tosca_template.nodetemplates)
orchestrator_nodes = tosca_helper.get_nodes_by_type('tosca.nodes.ARTICONF.Orchestrator',
orchestrator_nodes = tosca_helper.get_nodes_by_type('tosca.nodes.ARTICONF.docker.Orchestrator',
self.tosca_template.nodetemplates, self.all_node_types,
self.all_custom_def)
......@@ -36,11 +47,6 @@ class SimpleAnalyzer(SpecificationAnalyzer):
self.tosca_template.nodetemplates, self.all_node_types,
self.all_custom_def)
# for requirement in topology_nodes[0].requirements:
# requirement_dict = requirement[next(iter(requirement))]
# if requirement_dict['capability'] == 'tosca.capabilities.ARTICONF.VM':
# requirement_dict['occurrences'] = min_num_of_vm
vm_nodes = tosca_helper.get_nodes_by_type('tosca.nodes.ARTICONF.VM.Compute',
self.tosca_template.nodetemplates, self.all_node_types,
self.all_custom_def)
......@@ -86,43 +92,18 @@ class SimpleAnalyzer(SpecificationAnalyzer):
return return_nodes
def set_node_specifications(self):
nodes_to_implement_policies = self.get_nodes_to_implement_policy()
affected_nodes = []
for node_name in nodes_to_implement_policies:
policies = nodes_to_implement_policies[node_name]
affected_node = self.set_specs(node_name, policies, self.tosca_template.nodetemplates)
if affected_node:
affected_nodes.append(affected_node)
return affected_nodes
def get_nodes_to_implement_policy(self):
nodes_to_implement_policies = {}
for policy in self.tosca_template.policies:
for target in policy.targets:
for leaf in self.leaf_nodes:
for affected_node_name in (nx.shortest_path(self.g, source=target, target=leaf)):
if affected_node_name not in nodes_to_implement_policies:
policy_list = []
nodes_to_implement_policies[affected_node_name] = policy_list
policy_list = nodes_to_implement_policies[affected_node_name]
policy_list.append(policy.type)
nodes_to_implement_policies[affected_node_name] = policy_list
return nodes_to_implement_policies
def set_node_properties_for_policy(self, affected_node, policies):
logging.info('Setting properties for: ' + str(affected_node.type))
nodes = []
for node_template in self.tosca_template.nodetemplates:
nodes.append(self.set_default_node_properties(node_template))
return nodes
# ancestors_types = tosca_helper.get_all_ancestors_types(affected_node, self.all_node_types, self.all_custom_def)
# if 'tosca.nodes.ARTICONF.Orchestrator' in ancestors_types:
# logging.info('Do Something')
def set_default_node_properties(self, affected_node):
logging.info('Setting properties for: ' + str(affected_node.type))
ancestors_properties = tosca_helper.get_all_ancestors_properties(affected_node, self.all_node_types,
self.all_custom_def)
default_properties = {}
for ancestors_property in ancestors_properties:
default_property = self.get_defult_value(ancestors_property)
default_property = get_default_value(ancestors_property)
if default_property:
default_properties[next(iter(default_property))] = default_property[next(iter(default_property))]
......@@ -138,35 +119,10 @@ class SimpleAnalyzer(SpecificationAnalyzer):
affected_node.templates[node_name]['properties'][prop_name]['required'] and \
'default' in affected_node.templates[node_name]['properties'][prop_name] and \
prop_name not in default_properties:
default_properties[prop_name] = affected_node.templates[node_name]['properties'][prop_name]['default']
default_properties[prop_name] = affected_node.templates[node_name]['properties'][prop_name][
'default']
logging.info('Adding to : ' + str(affected_node.templates[node_name])+ ' properties: '+str(default_properties))
logging.info(
'Adding to : ' + str(affected_node.templates[node_name]) + ' properties: ' + str(default_properties))
affected_node.templates[node_name]['properties'] = default_properties
return affected_node
else:
return None
def set_specs(self, node_name, policies, nodes_in_template):
logging.info('node_name: ' + str(node_name) + ' will implement policies: ' + str(len(policies)))
for node in nodes_in_template:
if node.name == node_name:
affected_node = node
break
logging.info('node: ' + str(affected_node.type) + ' will implement policies: ' + str(len(policies)))
affected_node = self.set_node_properties_for_policy(affected_node, policies)
return affected_node
def get_defult_value(self, node_property):
if node_property and node_property.required and isinstance(node_property.value, dict) and 'required' in \
node_property.value and 'type' in node_property.value:
if node_property.default:
return {node_property.name: node_property.default}
if node_property.constraints:
for constraint in node_property.constraints:
print(constraint)
if node_property and node_property.required and node_property.value:
return {node_property.name: node_property.value}
return None
......@@ -19,31 +19,16 @@ logger = logging.getLogger(__name__)
class MyTestCase(unittest.TestCase):
def test_only_docker_node(self):
file_name = 'application_example_updated.yaml'
# def test_only_docker_node(self):
# file_name = 'application_example_updated.yaml'
# input_tosca_file_path = self.get_input_tosca_file_path(file_name)
# self.run_test(input_tosca_file_path)
def test_with_existing_nodes(self):
file_name = 'lifeWatch_vre1.yaml'
input_tosca_file_path = self.get_input_tosca_file_path(file_name)
self.run_test(input_tosca_file_path)
# def test_planner(self):
# conf = {'url': "http://host"}
# spec_service = SpecService(conf)
# test_planner = Planner(input_tosca_file_path, spec_service)
# test_tosca_template = test_planner.resolve_requirements()
# test_tosca_template = test_planner.set_infrastructure_specifications()
# template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary(test_tosca_template)
# logger.info("template ----: \n" + yaml.dump(template_dict))
#
# ToscaTemplate(yaml_dict_tpl=copy.deepcopy(template_dict))
#
# test_response = {'toscaTemplate': template_dict}
#
# response = {'toscaTemplate': template_dict}
# output_current_milli_time = int(round(time.time() * 1000))
# response["creationDate"] = output_current_milli_time
# response["parameters"] = []
# print("Output message:" + json.dumps(response))
# self.assertEqual(True, True)
def get_input_tosca_file_path(self, file_name):
tosca_path = "../../TOSCA/"
input_tosca_file_path = tosca_path + file_name
......@@ -60,6 +45,7 @@ class MyTestCase(unittest.TestCase):
spec_service = SpecService(conf)
test_planner = Planner(input_tosca_file_path, spec_service)
test_tosca_template = test_planner.resolve_requirements()
template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary(test_tosca_template)
test_tosca_template = test_planner.set_infrastructure_specifications()
template_dict = tosca_helper.get_tosca_template_2_topology_template_dictionary(test_tosca_template)
logger.info("template ----: \n" + yaml.dump(template_dict))
......
......@@ -121,8 +121,8 @@ def node_type_2_node_template(node_type, all_custom_def):
node_type[next(iter(node_type))].pop('type')
node_template = NodeTemplate(name, node_template_dict, node_type)
# For some reason the tosca.nodes.ARTICONF.Orchestrator doesn't have all definitions so we need to add them
# manually. We get 'toscaparser.common.exception.InvalidTypeError: Type "tosca.nodes.ARTICONF.Orchestrator"
# For some reason the tosca.nodes.ARTICONF.docker.Orchestrator doesn't have all definitions so we need to add them
# manually. We get 'toscaparser.common.exception.InvalidTypeError: Type "tosca.nodes.ARTICONF.docker.Orchestrator"
# is not a valid type.'
if len(node_template.custom_def) < len(all_custom_def):
for def_key in all_custom_def:
......
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