Commit 03c9c83b authored by Spiros Koulouzis's avatar Spiros Koulouzis

change some attributes back to properties

parent 5b6644ae
tosca_definitions_version: tosca_simple_yaml_1_0
description: TOSCA example description: TOSCA example
imports: imports:
- nodes: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/nodes.yaml - nodes: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/nodes.yaml
- capabilities: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/capabilities.yaml - 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 - 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 - interfaces: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/interfaces.yml
repositories:
docker_hub: https://hub.docker.com/
topology_template: topology_template:
node_templates: node_templates:
compute: compute:
...@@ -19,8 +15,6 @@ topology_template: ...@@ -19,8 +15,6 @@ topology_template:
mem_size: 6000 MB mem_size: 6000 MB
num_cores: 2 num_cores: 2
os: ubuntu 16 os: ubuntu 16
attributes:
private_ip: 192.168.1.10
type: tosca.nodes.ARTICONF.VM.Compute type: tosca.nodes.ARTICONF.VM.Compute
compute_1: compute_1:
interfaces: interfaces:
...@@ -31,19 +25,7 @@ topology_template: ...@@ -31,19 +25,7 @@ topology_template:
mem_size: 6000 MB mem_size: 6000 MB
num_cores: 2 num_cores: 2
os: ubuntu 16 os: ubuntu 16
attributes:
private_ip: 192.168.1.11
type: tosca.nodes.ARTICONF.VM.Compute type: tosca.nodes.ARTICONF.VM.Compute
compute_2:
interfaces:
Standard:
create: dumy.yaml
properties:
disk_size: 50000 MB
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
type: tosca.nodes.ARTICONF.VM.Compute
kubernetes: kubernetes:
interfaces: interfaces:
Standard: Standard:
...@@ -53,11 +35,27 @@ topology_template: ...@@ -53,11 +35,27 @@ topology_template:
capability: tosca.capabilities.ARTICONF.VM.topology capability: tosca.capabilities.ARTICONF.VM.topology
node: topology node: topology
relationship: tosca.relationships.HostedOn relationship: tosca.relationships.HostedOn
- host:
capability: tosca.capabilities.ARTICONF.VM.topology
node: topology_1
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Orchestrator.Kubernetes type: tosca.nodes.ARTICONF.Orchestrator.Kubernetes
logspout:
artifacts:
image:
file: gliderlabs/logspout:latest
repository: docker_hub
type: tosca.artifacts.Deployment.Image.Container.Docker
properties:
environment:
publish: 127.0.0.1:8000:80
ports:
- 8000:80
volumes:
- /etc/hostname:/etc/host_hostname:ro
- /var/run/docker.sock:/var/run/docker.sock
requirements:
- host:
capability: tosca.capabilities.ARTICONF.Orchestrator
node: kubernetes
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker
mysql: mysql:
artifacts: artifacts:
image: image:
...@@ -84,6 +82,9 @@ topology_template: ...@@ -84,6 +82,9 @@ topology_template:
interfaces: interfaces:
Standard: Standard:
create: dumy.yaml create: dumy.yaml
properties:
domain: UvA (Amsterdam, The Netherlands) XO Rack
provider: ExoGeni
requirements: requirements:
- vm: - vm:
capability: tosca.capabilities.ARTICONF.VM capability: tosca.capabilities.ARTICONF.VM
...@@ -93,17 +94,7 @@ topology_template: ...@@ -93,17 +94,7 @@ topology_template:
capability: tosca.capabilities.ARTICONF.VM capability: tosca.capabilities.ARTICONF.VM
node: compute_1 node: compute_1
relationship: tosca.relationships.DependsOn relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology type: tosca.nodes.ARTICONF.VM.topology
topology_1:
interfaces:
Standard:
create: dumy.yaml
requirements:
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute_2
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
wordpress: wordpress:
artifacts: artifacts:
image: image:
...@@ -128,21 +119,18 @@ topology_template: ...@@ -128,21 +119,18 @@ topology_template:
node: kubernetes node: kubernetes
relationship: tosca.relationships.HostedOn relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker type: tosca.nodes.ARTICONF.Container.Application.Docker
policies: policies:
- scalability: - scalability:
properties: properties:
fault_tolerance_level: 0 constraint_name: cpu_load
max_value: 90
targets:
- wordpress
type: tosca.policies.ARTICONF.Performance.CPU
- faultTolerance:
properties:
level: 1
targets: targets:
- mysql - mysql
type: tosca.policies.ARTICONF.FaultTolerance type: tosca.policies.ARTICONF.FaultTolerance
tosca_definitions_version: tosca_simple_yaml_1_0
outputs:
private_ip:
description: The private IP address of the application’s first tier.
value: { get_attribute: [compute, private_ip] }
private_ip_1:
description: The private IP address of the application’s first tier.
value: { get_attribute: [compute_1, private_ip] }
...@@ -2,13 +2,10 @@ ...@@ -2,13 +2,10 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e478ccae-5352-4e8e-9efb-3f5cda44e877" name="Default Changelist" comment="added matplotlib"> <list default="true" id="e478ccae-5352-4e8e-9efb-3f5cda44e877" name="Default Changelist" comment="added matplotlib">
<change beforePath="$PROJECT_DIR$/../build.sh" beforeDir="false" afterPath="$PROJECT_DIR$/../build.sh" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../TOSCA/application_example_2_topologies.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/application_example_2_topologies.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" /> <change beforePath="$PROJECT_DIR$/__main__.py" beforeDir="false" afterPath="$PROJECT_DIR$/__main__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/service/simple_spec_alayzer.py" beforeDir="false" afterPath="$PROJECT_DIR$/service/simple_spec_alayzer.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/service/simple_spec_alayzer.py" beforeDir="false" afterPath="$PROJECT_DIR$/service/simple_spec_alayzer.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../jenkins_pipeline" beforeDir="false" afterPath="$PROJECT_DIR$/../jenkins_pipeline" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/test-requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/test-requirements.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../test.sh" beforeDir="false" afterPath="$PROJECT_DIR$/../test.sh" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -206,18 +203,38 @@ ...@@ -206,18 +203,38 @@
<breakpoints> <breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/service/simple_spec_alayzer.py</url> <url>file://$PROJECT_DIR$/service/simple_spec_alayzer.py</url>
<line>45</line> <line>47</line>
<option name="timeStamp" value="1" /> <option name="timeStamp" value="1" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/planner/planner.py</url> <url>file://$PROJECT_DIR$/planner/planner.py</url>
<line>36</line> <line>66</line>
<option name="timeStamp" value="3" /> <option name="timeStamp" value="8" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/planner/planner.py</url>
<line>61</line>
<option name="timeStamp" value="9" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/__main__.py</url>
<line>124</line>
<option name="timeStamp" value="10" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/service/simple_spec_alayzer.py</url>
<line>25</line>
<option name="timeStamp" value="20" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/service/simple_spec_alayzer.py</url>
<line>127</line>
<option name="timeStamp" value="22" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/service/simple_spec_alayzer.py</url> <url>file://$PROJECT_DIR$/service/simple_spec_alayzer.py</url>
<line>26</line> <line>160</line>
<option name="timeStamp" value="5" /> <option name="timeStamp" value="26" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>
......
...@@ -115,7 +115,7 @@ if __name__ == "__main__": ...@@ -115,7 +115,7 @@ 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":
tosca_path = "../TOSCA/" tosca_path = "../TOSCA/"
input_tosca_file_path = tosca_path + '/application_example_2_topologies.yaml' input_tosca_file_path = tosca_path + '/application_example_updated.yaml'
conf = {'url': "http://host"} conf = {'url': "http://host"}
spec_service = SpecService(conf) spec_service = SpecService(conf)
test_planner = Planner(input_tosca_file_path, spec_service) test_planner = Planner(input_tosca_file_path, spec_service)
...@@ -129,18 +129,18 @@ if __name__ == "__main__": ...@@ -129,18 +129,18 @@ if __name__ == "__main__":
except NameError: except NameError:
import sys import sys
tosca_folder_path = os.path.dirname(os.path.abspath(sys.argv[0])) + os.path.join(tempfile.gettempdir(), # tosca_folder_path = os.path.dirname(os.path.abspath(sys.argv[0])) + os.path.join(tempfile.gettempdir(),
tosca_path) # tosca_path)
tosca_file_name = 'tosca_template' # tosca_file_name = 'tosca_template'
input_tosca_file_path = tosca_path + '/application_example_2_topologies.yaml' # input_tosca_file_path = tosca_path + '/application_example_2_topologies.yaml'
#
with open(input_tosca_file_path, 'w') as outfile: # with open(input_tosca_file_path, 'w') as outfile:
outfile.write(yaml.dump(template_dict)) # outfile.write(yaml.dump(template_dict))
#
ToscaTemplate(input_tosca_file_path) # ToscaTemplate(input_tosca_file_path)
#
test_response = {'toscaTemplate': template_dict} # test_response = {'toscaTemplate': template_dict}
logger.info("Output message:" + json.dumps(test_response)) # logger.info("Output message:" + json.dumps(test_response))
else: else:
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) channel = init_chanel(sys.argv)
......
...@@ -20,19 +20,21 @@ class SimpleAnalyzer(SpecificationAnalyzer): ...@@ -20,19 +20,21 @@ class SimpleAnalyzer(SpecificationAnalyzer):
# nodes_with_occurrences_in_requirements = tosca_util.get_nodes_with_occurrences_in_requirements( # nodes_with_occurrences_in_requirements = tosca_util.get_nodes_with_occurrences_in_requirements(
# self.tosca_template.nodetemplates) # 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.Orchestrator',
self.tosca_template.nodetemplates, self.all_node_types, self.tosca_template.nodetemplates, self.all_node_types,
self.all_custom_def) self.all_custom_def)
orchestrator_nodes[0].type_definition if 'properties' in orchestrator_nodes[0].entity_tpl:
if 'attributes' in orchestrator_nodes[0].entity_tpl: if 'min_masters_num' in orchestrator_nodes[0].entity_tpl['properties']:
if 'masters_num' in orchestrator_nodes[0].entity_tpl['attributes']: min_masters_num = orchestrator_nodes[0].entity_tpl['properties']['min_masters_num']
masters_num = orchestrator_nodes[0].entity_tpl['attributes']['masters_num'] if 'min_workers_num' in orchestrator_nodes[0].entity_tpl['properties']:
if 'workers_num' in orchestrator_nodes[0].entity_tpl['attributes']: workers_num = orchestrator_nodes[0].entity_tpl['properties']['min_workers_num']
workers_num = orchestrator_nodes[0].entity_tpl['attributes']['workers_num'] else:
min_masters_num = orchestrator_nodes[0].get_property_value('min_masters_num')
workers_num = orchestrator_nodes[0].get_property_value('min_workers_num')
topology_nodes = tosca_helper.get_nodes_by_type('tosca.nodes.ARTICONF.VM.topology', topology_nodes = tosca_helper.get_nodes_by_type('tosca.nodes.ARTICONF.VM.topology',
self.tosca_template.nodetemplates, self.all_node_types, self.tosca_template.nodetemplates, self.all_node_types,
self.all_custom_def) self.all_custom_def)
# for requirement in topology_nodes[0].requirements: # for requirement in topology_nodes[0].requirements:
# requirement_dict = requirement[next(iter(requirement))] # requirement_dict = requirement[next(iter(requirement))]
...@@ -40,10 +42,10 @@ class SimpleAnalyzer(SpecificationAnalyzer): ...@@ -40,10 +42,10 @@ class SimpleAnalyzer(SpecificationAnalyzer):
# requirement_dict['occurrences'] = min_num_of_vm # requirement_dict['occurrences'] = min_num_of_vm
vm_nodes = tosca_helper.get_nodes_by_type('tosca.nodes.ARTICONF.VM.Compute', vm_nodes = tosca_helper.get_nodes_by_type('tosca.nodes.ARTICONF.VM.Compute',
self.tosca_template.nodetemplates, self.all_node_types, self.tosca_template.nodetemplates, self.all_node_types,
self.all_custom_def) self.all_custom_def)
if vm_nodes: if vm_nodes:
for i in range(len(vm_nodes), masters_num): for i in range(len(vm_nodes), min_masters_num):
old_vm_name = vm_nodes[0].name old_vm_name = vm_nodes[0].name
new_vm = copy.deepcopy(vm_nodes[0]) new_vm = copy.deepcopy(vm_nodes[0])
new_vm_name = new_vm.name + '_' + str(i) new_vm_name = new_vm.name + '_' + str(i)
...@@ -116,12 +118,12 @@ class SimpleAnalyzer(SpecificationAnalyzer): ...@@ -116,12 +118,12 @@ class SimpleAnalyzer(SpecificationAnalyzer):
ancestors_types = tosca_helper.get_all_ancestors_types(affected_node, self.all_node_types, self.all_custom_def) 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: # if 'tosca.nodes.ARTICONF.Orchestrator' in ancestors_types:
# logging.info('Do Something') # logging.info('Do Something')
properties = tosca_helper.get_all_ancestors_properties(affected_node, self.all_node_types, ancestors_properties = tosca_helper.get_all_ancestors_properties(affected_node, self.all_node_types,
self.all_custom_def) self.all_custom_def)
default_properties = {} default_properties = {}
for node_property in properties: for ancestors_property in ancestors_properties:
default_property = self.get_defult_value(node_property) default_property = self.get_defult_value(ancestors_property)
if default_property: if default_property:
default_properties[next(iter(default_property))] = default_property[next(iter(default_property))] default_properties[next(iter(default_property))] = default_property[next(iter(default_property))]
...@@ -156,25 +158,36 @@ class SimpleAnalyzer(SpecificationAnalyzer): ...@@ -156,25 +158,36 @@ class SimpleAnalyzer(SpecificationAnalyzer):
return affected_node return affected_node
def get_defult_value(self, node_property): def get_defult_value(self, node_property):
if isinstance(node_property.value, if node_property and node_property.required and isinstance(node_property.value, dict) and 'required' in \
dict) and 'required' in node_property.value and 'type' in node_property.value: node_property.value and 'type' in node_property.value:
if node_property.value['required']: if node_property.default:
default_prop = {} return {node_property.name: node_property.default}
if 'default' in node_property.value: if node_property.constraints:
if node_property.value['type'] == 'integer': for constraint in node_property.constraints:
default_prop = int(node_property.value['default']) print(constraint)
else: # if isinstance(node_property.value,
default_prop = str(node_property.value['default']) # dict) and 'required' in node_property.value and 'type' in node_property.value:
elif 'constraints' in node_property.value: # if node_property.value['required']:
constraints = node_property.value['constraints'] # default_prop = {}
for constraint in constraints: # if 'default' in node_property.value:
for constraint_key in constraint: # if node_property.value['type'] == 'integer':
if 'equal' in constraint_key: # default_prop = int(node_property.value['default'])
if node_property.value['type'] == 'integer': # else:
default_prop = int(constraint[constraint_key]) # default_prop = str(node_property.value['default'])
else: # elif 'constraints' in node_property.value:
default_prop = str(constraint[constraint_key]) # constraints = node_property.value['constraints']
name = node_property.name # for constraint in constraints:
node_property = {name: default_prop} # for constraint_key in constraint:
return node_property # if 'equal' in constraint_key:
# if node_property.value['type'] == 'integer':
# default_prop = int(constraint[constraint_key])
# else:
# default_prop = str(constraint[constraint_key])
# name = node_property.name
# node_property = {name: default_prop}
# return node_property
# if node_property.value:
# name = node_property.name
# node_property = {name: node_property.value}
# return node_property
return None return None
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