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.
17 ARIA modeling service common module
20 # pylint: disable=no-self-argument, no-member, abstract-method
22 from sqlalchemy import (
27 from sqlalchemy.ext.declarative import declared_attr
33 from .mixins import InstanceModelMixin, TemplateModelMixin, ParameterMixin
34 from . import relationship
37 class OutputBase(ParameterMixin):
39 Output parameter or declaration for an output parameter.
42 __tablename__ = 'output'
44 # region many_to_one relationships
47 def service_template(cls):
49 Containing service template (can be ``None``).
51 :type: :class:`ServiceTemplate`
53 return relationship.many_to_one(cls, 'service_template')
58 Containing service (can be ``None``).
60 :type: :class:`ServiceTemplate`
62 return relationship.many_to_one(cls, 'service')
69 def service_template_fk(cls):
70 return relationship.foreign_key('service_template', nullable=True)
74 return relationship.foreign_key('service', nullable=True)
79 class InputBase(ParameterMixin):
81 Input parameter or declaration for an input parameter.
84 __tablename__ = 'input'
86 required = Column(Boolean, doc="""
87 Is the input mandatory.
93 def wrap(cls, name, value, description=None, required=True): # pylint: disable=arguments-differ
94 input = super(InputBase, cls).wrap(name, value, description)
95 input.required = required
98 # region many_to_one relationships
101 def service_template(cls):
103 Containing service template (can be ``None``).
105 :type: :class:`ServiceTemplate`
107 return relationship.many_to_one(cls, 'service_template')
112 Containing service (can be ``None``).
114 :type: :class:`Service`
116 return relationship.many_to_one(cls, 'service')
121 Containing interface (can be ``None``).
123 :type: :class:`Interface`
125 return relationship.many_to_one(cls, 'interface')
130 Containing operation (can be ``None``).
132 :type: :class:`Operation`
134 return relationship.many_to_one(cls, 'operation')
137 def interface_template(cls):
139 Containing interface template (can be ``None``).
141 :type: :class:`InterfaceTemplate`
143 return relationship.many_to_one(cls, 'interface_template')
146 def operation_template(cls):
148 Containing operation template (can be ``None``).
150 :type: :class:`OperationTemplate`
152 return relationship.many_to_one(cls, 'operation_template')
157 Containing execution (can be ``None``).
159 :type: :class:`Execution`
161 return relationship.many_to_one(cls, 'execution')
165 # region foreign keys
168 def service_template_fk(cls):
169 return relationship.foreign_key('service_template', nullable=True)
173 return relationship.foreign_key('service', nullable=True)
176 def interface_fk(cls):
177 return relationship.foreign_key('interface', nullable=True)
180 def operation_fk(cls):
181 return relationship.foreign_key('operation', nullable=True)
184 def interface_template_fk(cls):
185 return relationship.foreign_key('interface_template', nullable=True)
188 def operation_template_fk(cls):
189 return relationship.foreign_key('operation_template', nullable=True)
192 def execution_fk(cls):
193 return relationship.foreign_key('execution', nullable=True)
197 return relationship.foreign_key('task', nullable=True)
202 class ConfigurationBase(ParameterMixin):
204 Configuration parameter.
207 __tablename__ = 'configuration'
209 # region many_to_one relationships
212 def operation_template(cls):
214 Containing operation template (can be ``None``).
216 :type: :class:`OperationTemplate`
218 return relationship.many_to_one(cls, 'operation_template')
223 Containing operation (can be ``None``).
225 :type: :class:`Operation`
227 return relationship.many_to_one(cls, 'operation')
231 # region foreign keys
234 def operation_template_fk(cls):
235 return relationship.foreign_key('operation_template', nullable=True)
238 def operation_fk(cls):
239 return relationship.foreign_key('operation', nullable=True)
244 class PropertyBase(ParameterMixin):
246 Property parameter or declaration for a property parameter.
249 __tablename__ = 'property'
251 # region many_to_one relationships
254 def node_template(cls):
256 Containing node template (can be ``None``).
258 :type: :class:`NodeTemplate`
260 return relationship.many_to_one(cls, 'node_template')
263 def group_template(cls):
265 Containing group template (can be ``None``).
267 :type: :class:`GroupTemplate`
269 return relationship.many_to_one(cls, 'group_template')
272 def policy_template(cls):
274 Containing policy template (can be ``None``).
276 :type: :class:`PolicyTemplate`
278 return relationship.many_to_one(cls, 'policy_template')
281 def relationship_template(cls):
283 Containing relationship template (can be ``None``).
285 :type: :class:`RelationshipTemplate`
287 return relationship.many_to_one(cls, 'relationship_template')
290 def capability_template(cls):
292 Containing capability template (can be ``None``).
294 :type: :class:`CapabilityTemplate`
296 return relationship.many_to_one(cls, 'capability_template')
299 def artifact_template(cls):
301 Containing artifact template (can be ``None``).
303 :type: :class:`ArtifactTemplate`
305 return relationship.many_to_one(cls, 'artifact_template')
310 Containing node (can be ``None``).
314 return relationship.many_to_one(cls, 'node')
319 Containing group (can be ``None``).
321 :type: :class:`Group`
323 return relationship.many_to_one(cls, 'group')
328 Containing policy (can be ``None``).
330 :type: :class:`Policy`
332 return relationship.many_to_one(cls, 'policy')
335 def relationship(cls):
337 Containing relationship (can be ``None``).
339 :type: :class:`Relationship`
341 return relationship.many_to_one(cls, 'relationship')
346 Containing capability (can be ``None``).
348 :type: :class:`Capability`
350 return relationship.many_to_one(cls, 'capability')
355 Containing artifact (can be ``None``).
357 :type: :class:`Artifact`
359 return relationship.many_to_one(cls, 'artifact')
363 # region foreign keys
366 def node_template_fk(cls):
367 return relationship.foreign_key('node_template', nullable=True)
370 def group_template_fk(cls):
371 return relationship.foreign_key('group_template', nullable=True)
374 def policy_template_fk(cls):
375 return relationship.foreign_key('policy_template', nullable=True)
378 def relationship_template_fk(cls):
379 return relationship.foreign_key('relationship_template', nullable=True)
382 def capability_template_fk(cls):
383 return relationship.foreign_key('capability_template', nullable=True)
386 def artifact_template_fk(cls):
387 return relationship.foreign_key('artifact_template', nullable=True)
391 return relationship.foreign_key('node', nullable=True)
395 return relationship.foreign_key('group', nullable=True)
399 return relationship.foreign_key('policy', nullable=True)
402 def relationship_fk(cls):
403 return relationship.foreign_key('relationship', nullable=True)
406 def capability_fk(cls):
407 return relationship.foreign_key('capability', nullable=True)
410 def artifact_fk(cls):
411 return relationship.foreign_key('artifact', nullable=True)
416 class AttributeBase(ParameterMixin):
418 Attribute parameter or declaration for an attribute parameter.
421 __tablename__ = 'attribute'
423 # region many_to_one relationships
426 def node_template(cls):
428 Containing node template (can be ``None``).
430 :type: :class:`NodeTemplate`
432 return relationship.many_to_one(cls, 'node_template')
437 Containing node (can be ``None``).
441 return relationship.many_to_one(cls, 'node')
445 # region foreign keys
448 def node_template_fk(cls):
449 """For Attribute many-to-one to NodeTemplate"""
450 return relationship.foreign_key('node_template', nullable=True)
454 """For Attribute many-to-one to Node"""
455 return relationship.foreign_key('node', nullable=True)
460 class TypeBase(InstanceModelMixin):
462 Type and its children. Can serve as the root for a type hierarchy.
465 __tablename__ = 'type'
467 __private_fields__ = ('parent_type_fk',)
469 variant = Column(Text, nullable=False)
471 description = Column(Text, doc="""
472 Human-readable description.
474 :type: :obj:`basestring`
477 _role = Column(Text, name='role')
479 # region one_to_one relationships
484 Parent type (will be ``None`` for the root of a type hierarchy).
488 return relationship.one_to_one_self(cls, 'parent_type_fk')
492 # region one_to_many relationships
499 :type: [:class:`Type`]
501 return relationship.one_to_many(cls, other_fk='parent_type_fk', self=True)
505 # region foreign keys
508 def parent_type_fk(cls):
509 """For Type one-to-many to Type"""
510 return relationship.foreign_key('type', nullable=True)
516 def get_role(the_type):
519 elif the_type._role is None:
520 return get_role(the_type.parent)
521 return the_type._role
523 return get_role(self)
526 def role(self, value):
529 def is_descendant(self, base_name, name):
530 base = self.get_descendant(base_name)
532 if base.get_descendant(name) is not None:
536 def get_descendant(self, name):
537 if self.name == name:
539 for child in self.children:
540 found = child.get_descendant(name)
541 if found is not None:
545 def iter_descendants(self):
546 for child in self.children:
548 for descendant in child.iter_descendants():
553 return collections.OrderedDict((
555 ('description', self.description),
556 ('role', self.role)))
559 def as_raw_all(self):
561 self._append_raw_children(types)
564 def _append_raw_children(self, types):
565 for child in self.children:
566 raw_child = formatting.as_raw(child)
567 raw_child['parent'] = self.name
568 types.append(raw_child)
569 child._append_raw_children(types)
574 Type hierarchy as a list beginning with this type and ending in the root.
576 :type: [:class:`Type`]
578 return [self] + (self.parent.hierarchy if self.parent else [])
581 class MetadataBase(TemplateModelMixin):
583 Custom values associated with the service.
585 This model is used by both service template and service instance elements.
588 :vartype name: basestring
590 :vartype value: basestring
593 __tablename__ = 'metadata'
599 return collections.OrderedDict((
601 ('value', self.value)))