2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018-2019 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 @file:Suppress("unused")
19 package org.onap.ccsdk.cds.controllerblueprints.core.data
21 import com.fasterxml.jackson.annotation.JsonIgnore
22 import com.fasterxml.jackson.annotation.JsonProperty
23 import com.fasterxml.jackson.annotation.JsonPropertyOrder
24 import com.fasterxml.jackson.databind.JsonNode
25 import io.swagger.annotations.ApiModelProperty
26 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
27 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
32 * @author Brinda Santh
34 open class EntityType {
37 var id: String? = null
38 var description: String? = null
39 var version: String = "1.0.0"
40 var metadata: MutableMap<String, String>? = null
42 @get:JsonProperty("derived_from")
43 lateinit var derivedFrom: String
44 var attributes: MutableMap<String, AttributeDefinition>? = null
45 var properties: MutableMap<String, PropertyDefinition>? = null
49 5.3.2 tosca.datatypes.Credential
50 The Credential type is a complex TOSCA data Type used when describing
51 authorization credentials used to access network accessible resources.
56 var id: String? = null
57 var protocol: String? = null
59 @get:JsonProperty("token_type")
60 lateinit var tokenType: String
61 lateinit var token: String
62 var keys: MutableMap<String, String>? = null
63 lateinit var user: String
67 3.5.2 Constraint clause
68 A constraint clause defines an operation along with one or more compatible values that can be used to define a constraint on a property or parameter’s allowed values when it is defined in a TOSCA Service Template or one of its entities.
70 class ConstraintClause {
72 var equal: JsonNode? = null
74 @get:JsonProperty("greater_than")
75 var greaterThan: JsonNode? = null
77 @get:JsonProperty("greater_or_equal")
78 var greaterOrEqual: JsonNode? = null
80 @get:JsonProperty("less_than")
81 var lessThan: JsonNode? = null
83 @get:JsonProperty("less_or_equal")
84 var lessOrEqual: JsonNode? = null
86 @get:JsonProperty("in_range")
87 var inRange: MutableList<JsonNode>? = null
89 @get:JsonProperty("valid_values")
90 var validValues: MutableList<JsonNode>? = null
91 var length: JsonNode? = null
93 @get:JsonProperty("min_length")
94 var minLength: JsonNode? = null
96 @get:JsonProperty("max_length")
97 var maxLength: JsonNode? = null
98 var pattern: String? = null
99 var schema: String? = null
103 3.5.4 Node Filter definition
104 A node filter definition defines criteria for selection of a TOSCA Node Template based upon the template’s property values, capabilities and capability properties.
107 class NodeFilterDefinition {
109 var properties: MutableMap<String, PropertyDefinition>? = null
110 var capabilities: MutableList<String>? = null
114 3.5.5 Repository definition
115 A repository definition defines a named external repository which contains deployment
116 and implementation artifacts that are referenced within the TOSCA Service Template.
118 class RepositoryDefinition {
121 var id: String? = null
122 var description: String? = null
123 lateinit var url: String
124 var credential: Credential? = null
128 3.5.6 Artifact definition
129 An artifact definition defines a named, typed file that can be associated with Node Type
130 or Node Template and used by orchestration engine to facilitate deployment and implementation of interface operations.
132 class ArtifactDefinition {
135 var id: String? = null
136 lateinit var type: String
137 lateinit var file: String
138 var repository: String? = null
139 var description: String? = null
141 @get:JsonProperty("deploy_Path")
142 var deployPath: String? = null
143 var properties: MutableMap<String, JsonNode>? = null
147 3.5.7 Import definition
148 An import definition is used within a TOSCA Service Template to locate and uniquely name
149 another TOSCA Service Template file which has type and template definitions to be imported (included)
150 and referenced within another Service Template.
152 class ImportDefinition {
155 var id: String? = null
156 lateinit var file: String
157 var repository: String? = null
159 @get:JsonProperty("namespace_uri")
160 var namespaceUri: String? = null
162 @get:JsonProperty("namespace_prefix")
163 var namespacePrefix: String? = null
167 3.5.8 Property definition A property definition defines a named, typed value and related data that can be associated with an
168 entity defined in this specification (e.g., Node Types, Relationship Types, Capability Types, etc.).
169 Properties are used by template authors to provide input values to TOSCA entities which indicate their “desired state” when they are
170 instantiated. The value of a property can be retrieved using the get_property function within TOSCA Service Templates.
172 class PropertyDefinition {
175 var id: String? = null
176 var description: String? = null
177 var required: Boolean? = null
178 lateinit var type: String
180 @get:JsonProperty("input-param")
181 var inputparam: Boolean? = null
183 @get:JsonProperty("default")
184 var defaultValue: JsonNode? = null
185 var status: String? = null
186 var constraints: MutableList<ConstraintClause>? = null
188 @get:JsonProperty("entry_schema")
189 var entrySchema: EntrySchema? = null
191 @get:JsonProperty("external-schema")
192 var externalSchema: String? = null
193 var metadata: MutableMap<String, String>? = null
195 // Mainly used in Workflow Outputs
196 @get:ApiModelProperty(notes = "Property Value, It may be Expression or Json type values")
197 var value: JsonNode? = null
201 3.5.10 Attribute definition
203 An attribute definition defines a named, typed value that can be associated with an entity defined in this
204 specification (e.g., a Node, Relationship or Capability Type). Specifically, it is used to expose the
205 “actual state” of some property of a TOSCA entity after it has been deployed and instantiated
206 (as set by the TOSCA orchestrator). Attribute values can be retrieved via the get_attribute function
207 from the instance model and used as values to other entities within TOSCA Service Templates.
210 class AttributeDefinition {
213 var id: String? = null
214 var description: String? = null
215 var required: Boolean? = null
216 lateinit var type: String
218 @JsonProperty("default")
219 var defaultValue: JsonNode? = null
220 var status: String? = null
221 var constraints: MutableList<ConstraintClause>? = null
223 @JsonProperty("entry_schema")
224 var entrySchema: EntrySchema? = null
226 // Mainly used in DSL definitions
227 @get:ApiModelProperty(notes = "Attribute Value, It may be Expression or Json type values")
228 var value: JsonNode? = null
232 3.5.13 Operation definition
233 An operation definition defines a named function or procedure that can be bound to an implementation artifact (e.g., a script).
235 class OperationDefinition {
238 var id: String? = null
239 var description: String? = null
240 var implementation: Implementation? = null
241 var inputs: MutableMap<String, PropertyDefinition>? = null
242 var outputs: MutableMap<String, PropertyDefinition>? = null
245 class Implementation {
247 var primary: String? = null
248 var dependencies: MutableList<String>? = null
250 @get:JsonProperty("operation_host")
251 var operationHost: String = BluePrintConstants.PROPERTY_SELF
253 // Timeout value in seconds
254 var timeout: Int = 180
255 var lock: LockAssignment? = null
258 class LockAssignment {
260 lateinit var key: JsonNode
261 var acquireTimeout: JsonNode = Integer(180).asJsonType()
265 3.5.14 Interface definition
266 An interface definition defines a named interface that can be associated with a Node or Relationship Type
268 class InterfaceDefinition {
271 var id: String? = null
272 var type: String? = null
273 var operations: MutableMap<String, OperationDefinition>? = null
274 var inputs: MutableMap<String, PropertyDefinition>? = null
278 3.5.15 Event Filter definition
279 An event filter definition defines criteria for selection of an attribute, for the purpose of monitoring it, within a TOSCA entity, or one its capabilities.
281 class EventFilterDefinition {
284 var id: String? = null
285 lateinit var node: String
286 var requirement: String? = null
287 var capability: String? = null
291 3.5.16 Trigger definition TODO
292 A trigger definition defines the event, condition and action that is used to “trigger” a policy it is associated with.
294 class TriggerDefinition {
297 var id: String? = null
298 var description: String? = null
300 @get:JsonProperty("event_type")
301 lateinit var eventType: String
303 @get:JsonProperty("target_filter")
304 var targetFilter: EventFilterDefinition? = null
305 var condition: ConditionClause? = null
306 var constraint: ConditionClause? = null
307 var method: String? = null
308 lateinit var action: String
312 3.5.17 Workflow activity definition
313 A workflow activity defines an operation to be performed in a TOSCA workflow. Activities allows to:
314 · Delegate the workflow for a node expected to be provided by the orchestrator
315 · Set the state of a node
316 · Call an operation defined on a TOSCA interface of a node, relationship or group
317 · Inline another workflow defined in the topology (to allow reusability)
321 var delegate: String? = null
323 @get:JsonProperty("set_state")
324 var setState: String? = null
326 @get:JsonProperty("call_operation")
327 var callOperation: String? = null
328 var inlines: ArrayList<String>? = null
332 3.5.20 Workflow precondition definition
333 A workflow condition can be used as a filter or precondition to check if a workflow can be processed or not based on the state of the instances of a TOSCA topology deployment. When not met, the workflow will not be triggered.
335 class PreConditionDefinition {
338 var id: String? = null
339 lateinit var target: String
341 @get:JsonProperty("target_relationship")
342 lateinit var targetRelationship: String
343 lateinit var condition: ArrayList<ConditionClause>
347 3.5.21 Workflow step definition
348 A workflow step allows to define one or multiple sequenced activities in a workflow and how they are connected to other steps in the workflow. They are the building blocks of a declarative workflow.
353 var id: String? = null
354 var description: String? = null
355 var target: String? = null
357 @JsonProperty("target_relationship")
358 var targetRelationship: String? = null
360 @JsonProperty("operation_host")
361 var operationHost: String? = null
362 var activities: ArrayList<Activity>? = null
364 @get:JsonProperty("on_success")
365 var onSuccess: ArrayList<String>? = null
367 @get:JsonProperty("on_failure")
368 var onFailure: ArrayList<String>? = null
372 3.6.2 Capability definition
373 A capability definition defines a named, typed set of data that can be associated with Node Type or Node Template to describe a transparent capability or feature of the software component the node describes.
376 class CapabilityDefinition {
379 var id: String? = null
380 lateinit var type: String
381 var description: String? = null
382 var properties: MutableMap<String, PropertyDefinition>? = null
384 @get:JsonProperty("valid_source_types")
385 var validSourceTypes: MutableList<String>? = null
386 var occurrences: MutableList<Any>? = null
390 3.6.3 Requirement definition
391 The Requirement definition describes a named requirement (dependencies) of a TOSCA Node Type or Node template which needs to be fulfilled by a matching Capability definition declared by another TOSCA modelable entity. The requirement definition may itself include the specific name of the fulfilling entity (explicitly) or provide an abstract type, along with additional filtering characteristics, that a TOSCA orchestrator can use to fulfill the capability at runtime (implicitly).
393 class RequirementDefinition {
396 var id: String? = null
397 var description: String? = null
398 var capability: String? = null
399 var node: String? = null
400 var relationship: String? = null
401 var occurrences: MutableList<Any>? = null
406 An Artifact Type is a reusable entity that defines the type of one or more files that are used to define implementation or deployment artifacts that are referenced by nodes or relationships on their operations.
408 class ArtifactType : EntityType() {
410 @get:JsonProperty("mime_type")
411 var mimeType: String? = null
413 @get:JsonProperty("file_ext")
414 var fileExt: MutableList<String>? = null
419 A Data Type definition defines the schema for new named datatypes in TOSCA.
422 class DataType : EntityType() {
424 var constraints: MutableList<ConstraintClause>? = null
429 A Node Type is a reusable entity that defines the type of one or more Node Templates. As such, a Node Type defines the structure of observable properties via a Properties Definition, the Requirements and Capabilities of the node as well as its supported interfaces.
433 class NodeType : EntityType() {
435 var capabilities: MutableMap<String, CapabilityDefinition>? = null
436 var requirements: MutableMap<String, RequirementDefinition>? = null
437 var interfaces: MutableMap<String, InterfaceDefinition>? = null
438 var artifacts: MutableMap<String, ArtifactDefinition>? = null
442 3.6.8 Requirement Type
443 A Requirement Type is a reusable entity that describes a kind of requirement that a Node Type can declare to expose.
444 The TOSCA Simple Profile seeks to simplify the need for declaring specific Requirement Types
445 from nodes and instead rely upon nodes declaring their features sets using TOSCA Capability Types
446 along with a named Feature notation.
449 class RequirementType : EntityType() {
451 var requirements: MutableMap<String, RequirementDefinition>? = null
452 var capabilities: MutableMap<String, CapabilityDefinition>? = null
453 var interfaces: MutableMap<String, InterfaceDefinition>? = null
454 var artifacts: MutableMap<String, ArtifactDefinition>? = null
458 3.6.10 Relationship Type
459 A Relationship Type is a reusable entity that defines the type of one or more relationships between Node Types or Node Templates.
462 class RelationshipType : EntityType() {
464 var interfaces: MutableMap<String, InterfaceDefinition>? = null
466 @get:JsonProperty("valid_target_types")
467 var validTargetTypes: MutableList<String>? = null
472 A Group Type defines logical grouping types for nodes, typically for different management purposes.
473 Groups can effectively be viewed as logical nodes that are not part of the physical deployment topology
474 of an application, yet can have capabilities and the ability to attach policies and interfaces
475 that can be applied (depending on the group type) to its member nodes.
478 class GroupType : EntityType() {
480 var members: MutableList<String>? = null
481 var requirements: ArrayList<RequirementDefinition>? = null
482 var capabilities: MutableMap<String, CapabilityDefinition>? = null
483 var interfaces: MutableMap<String, InterfaceDefinition>? = null
488 A Policy Type defines a type of requirement that affects or governs an application or service’s
489 topology at some stage of its lifecycle, but is not explicitly part of the topology itself
490 (i.e., it does not prevent the application or service from being deployed or run if it did not exist).
492 class PolicyType : EntityType() {
494 lateinit var targets: MutableList<String>
498 3.7.1 Capability assignment
499 A capability assignment allows node template authors to assign values to properties and attributes for a named capability definition that is part of a Node Template’s type definition.
501 class CapabilityAssignment {
504 var id: String? = null
505 var attributes: MutableMap<String, JsonNode>? = null
506 var properties: MutableMap<String, JsonNode>? = null
510 3.7.4 Relationship Template
511 A Relationship Template specifies the occurrence of a manageable relationship between node templates as part of an application’s topology model that is defined in a TOSCA Service Template. A Relationship template is an instance of a specified Relationship Type and can provide customized properties, constraints or operations which override the defaults provided by its Relationship Type and its implementations.
513 class GroupDefinition {
516 var id: String? = null
517 lateinit var type: String
518 var description: String? = null
519 var metadata: MutableMap<String, String>? = null
520 var properties: MutableMap<String, JsonNode>? = null
521 var members = ArrayList<String>()
522 var interfaces: MutableMap<String, InterfaceDefinition>? = null
526 3.7.6 Policy definition
527 A policy definition defines a policy that can be associated with a TOSCA topology or top-level entity definition (e.g., group definition, node template, etc.).
529 class PolicyDefinition {
532 var id: String? = null
533 lateinit var type: String
534 var description: String? = null
535 var metadata: MutableMap<String, String>? = null
536 var properties: MutableMap<String, JsonNode>? = null
537 var targets: MutableList<String>? = null
541 3.8 Topology Template definition
542 This section defines the topology template of a cloud application. The main ingredients of the topology template are node templates representing components of the application and relationship templates representing links between the components. These elements are defined in the nested node_templates section and the nested relationship_templates sections, respectively. Furthermore, a topology template allows for defining input parameters, output parameters as well as grouping of node templates.
544 class TopologyTemplate {
547 var id: String? = null
548 var description: String? = null
549 var inputs: MutableMap<String, PropertyDefinition>? = null
551 @get:JsonProperty("node_templates")
552 var nodeTemplates: MutableMap<String, NodeTemplate>? = null
554 @get:JsonProperty("relationship_templates")
555 var relationshipTemplates: MutableMap<String, RelationshipTemplate>? = null
556 var policies: MutableMap<String, PolicyDefinition>? = null
557 var outputs: MutableMap<String, PropertyDefinition>? = null
559 @get:JsonProperty("substitution_mappings")
560 var substitutionMappings: Any? = null
561 var workflows: MutableMap<String, Workflow>? = null
564 class SubstitutionMapping {
566 @get:JsonProperty("node_type")
567 lateinit var nodeType: String
568 lateinit var capabilities: ArrayList<String>
569 lateinit var requirements: ArrayList<String>
574 lateinit var type: String
575 var constraints: MutableList<ConstraintClause>? = null
578 class InterfaceAssignment {
581 var id: String? = null
582 var operations: MutableMap<String, OperationAssignment>? = null
583 var inputs: MutableMap<String, JsonNode>? = null
588 A Node Template specifies the occurrence of a manageable software component as part of an application’s topology model which is defined in a TOSCA Service Template. A Node template is an instance of a specified Node Type and can provide customized properties, constraints or operations which override the defaults provided by its Node Type and its implementations.
591 open class NodeTemplate {
594 var id: String? = null
595 var description: String? = null
596 lateinit var type: String
597 var metadata: MutableMap<String, String>? = null
598 var directives: MutableList<String>? = null
600 // @get:JsonSerialize(using = PropertyDefinitionValueSerializer::class)
601 var properties: MutableMap<String, JsonNode>? = null
602 var attributes: MutableMap<String, JsonNode>? = null
603 var capabilities: MutableMap<String, CapabilityAssignment>? = null
604 var requirements: MutableMap<String, RequirementAssignment>? = null
605 var interfaces: MutableMap<String, InterfaceAssignment>? = null
606 var artifacts: MutableMap<String, ArtifactDefinition>? = null
608 @get:JsonProperty("node_filter")
609 var nodeFilter: NodeFilterDefinition? = null
610 var copy: String? = null
613 class OperationAssignment {
616 var id: String? = null
617 var description: String? = null
618 var implementation: Implementation? = null
619 var inputs: MutableMap<String, JsonNode>? = null
620 var outputs: MutableMap<String, JsonNode>? = null
624 3.7.4 Relationship Template
625 A Relationship Template specifies the occurrence of a manageable relationship between node templates as part of an application’s topology model that is defined in a TOSCA Service Template. A Relationship template is an instance of a specified Relationship Type and can provide customized properties, constraints or operations which override the defaults provided by its Relationship Type and its implementations.
628 class RelationshipTemplate {
631 var id: String? = null
632 lateinit var type: String
633 var description: String? = null
634 var metadata: MutableMap<String, String>? = null
635 var properties: MutableMap<String, JsonNode>? = null
636 var attributes: MutableMap<String, JsonNode>? = null
637 var interfaces: MutableMap<String, InterfaceDefinition>? = null
638 var copy: String? = null
642 3.7.2 Requirement assignment
643 A Requirement assignment allows template authors to provide either concrete names of TOSCA templates or provide abstract selection criteria for providers to use to find matching TOSCA templates that are used to fulfill a named requirement’s declared TOSCA Node Type.
646 class RequirementAssignment {
649 var id: String? = null
650 var capability: String? = null
651 var node: String? = null
653 // Relationship Type or Relationship Template
654 var relationship: String? = null
660 var id: String? = null
661 var description: String? = null
662 var steps: MutableMap<String, Step>? = null
663 var preconditions: ArrayList<PreConditionDefinition>? = null
664 var inputs: MutableMap<String, PropertyDefinition>? = null
665 var outputs: MutableMap<String, PropertyDefinition>? = null
668 class ConditionClause {
670 var and: ArrayList<MutableMap<String, Any>>? = null
671 var or: ArrayList<MutableMap<String, Any>>? = null
673 @get:JsonProperty("assert")
674 var assertConditions: ArrayList<MutableMap<String, Any>>? = null
678 3.9 Service Template definition
679 A TOSCA Service Template (YAML) document contains element definitions of building blocks for cloud application, or complete models of cloud applications. This section describes the top-level structural elements (TOSCA keynames) along with their grammars, which are allowed to appear in a TOSCA Service Template document.
684 "toscaDefinitionsVersion", "description", "metadata", "imports", "dsl_definitions",
688 class ServiceTemplate : Cloneable {
691 var id: String? = null
693 @get:JsonProperty("tosca_definitions_version")
694 var toscaDefinitionsVersion: String = "controller_blueprint_1_0_0"
695 var metadata: MutableMap<String, String>? = null
696 var description: String? = null
698 @get:JsonProperty("dsl_definitions")
699 var dslDefinitions: MutableMap<String, JsonNode>? = null
700 var repositories: MutableMap<String, RepositoryDefinition>? = null
701 var imports: MutableList<ImportDefinition>? = null
703 @get:JsonProperty("artifact_types")
704 var artifactTypes: MutableMap<String, ArtifactType>? = null
706 @get:JsonProperty("data_types")
707 var dataTypes: MutableMap<String, DataType>? = null
709 @get:JsonProperty("relationship_types")
710 var relationshipTypes: MutableMap<String, RelationshipType>? = null
712 @get:JsonProperty("node_types")
713 var nodeTypes: MutableMap<String, NodeType>? = null
715 @get:JsonProperty("policy_types")
716 var policyTypes: MutableMap<String, PolicyType>? = null
718 @get:JsonProperty("topology_template")
719 var topologyTemplate: TopologyTemplate? = null
721 public override fun clone(): ServiceTemplate {
722 return super.clone() as ServiceTemplate
726 class ToscaMetaData {
728 lateinit var toscaMetaFileVersion: String
729 lateinit var csarVersion: String
730 lateinit var createdBy: String
731 lateinit var entityDefinitions: String
732 lateinit var templateName: String
733 lateinit var templateVersion: String
734 lateinit var templateTags: String
735 var templateType: String = BluePrintConstants.BLUEPRINT_TYPE_DEFAULT