1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from aria.modeling import models as aria_models
21 def create_simple_topology_single_node(model_storage, create_operation):
22 service_template = models.create_service_template()
23 service = models.create_service(service_template)
25 node_template = models.create_dependency_node_template(service_template)
26 interface_template = models.create_interface_template(
29 operation_kwargs=dict(
30 function=create_operation,
31 arguments={'key': aria_models.Argument.wrap('key', 'create'),
32 'value': aria_models.Argument.wrap('value', True)})
34 node_template.interface_templates[interface_template.name] = interface_template # pylint: disable=unsubscriptable-object
36 node = models.create_node(node_template, service, name=models.DEPENDENCY_NODE_NAME)
37 interface = models.create_interface(
40 operation_kwargs=dict(
41 function=create_operation,
42 arguments={'key': aria_models.Argument.wrap('key', 'create'),
43 'value': aria_models.Argument.wrap('value', True)})
45 node.interfaces[interface.name] = interface # pylint: disable=unsubscriptable-object
47 model_storage.service_template.put(service_template)
48 model_storage.service.put(service)
51 def create_simple_topology_two_nodes(model_storage):
52 service_template = models.create_service_template()
53 service = models.create_service(service_template)
55 # Creating a simple service with node -> node as a graph
57 dependency_node_template = models.create_dependency_node_template(service_template)
58 dependent_node_template = models.create_dependent_node_template(service_template,
59 dependency_node_template)
61 dependency_node = models.create_node(
62 dependency_node_template, service, models.DEPENDENCY_NODE_NAME)
63 dependent_node = models.create_node(
64 dependent_node_template, service, models.DEPENDENT_NODE_NAME)
66 dependent_node.outbound_relationships.append(models.create_relationship( # pylint: disable=no-member
67 source=dependent_node,
68 target=dependency_node
71 model_storage.service_template.put(service_template)
72 model_storage.service.put(service)
77 def create_simple_topology_three_nodes(model_storage):
78 #################################################################################
79 # Creating a simple deployment with the following topology:
83 # meaning node0 has two relationships: node1 and node2 (one each).
85 service_id = create_simple_topology_two_nodes(model_storage)
86 service = model_storage.service.get(service_id)
87 third_node_template = models.create_dependency_node_template(
88 service.service_template, name='another_dependency_node_template')
89 third_node = models.create_node(third_node_template, service, 'another_dependency_node')
90 new_relationship = models.create_relationship(
91 source=model_storage.node.get_by_name(models.DEPENDENT_NODE_NAME),
94 model_storage.relationship.put(new_relationship)