9e934c7c74b964788fc2b01a70c5ed05e99d45d2
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2018-2019 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 @file:Suppress("unused")
18
19 package org.onap.ccsdk.cds.controllerblueprints.core.data
20
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
28 /**
29  *
30  *
31  * @author Brinda Santh
32  */
33 open class EntityType {
34     @get:JsonIgnore
35     var id: String? = null
36     var description: String? = null
37     var version: String = "1.0.0"
38     var metadata: MutableMap<String, String>? = null
39     @get:JsonProperty("derived_from")
40     lateinit var derivedFrom: String
41     var attributes: MutableMap<String, AttributeDefinition>? = null
42     var properties: MutableMap<String, PropertyDefinition>? = null
43 }
44
45 /*
46  5.3.2 tosca.datatypes.Credential
47  The Credential type is a complex TOSCA data Type used when describing
48  authorization credentials used to access network accessible resources.
49  */
50 class Credential {
51     @get:JsonIgnore
52     var id: String? = null
53     var protocol: String? = null
54     @get:JsonProperty("token_type")
55     lateinit var tokenType: String
56     lateinit var token: String
57     var keys: MutableMap<String, String>? = null
58     lateinit var user: String
59 }
60
61 /*
62 3.5.2 Constraint clause
63 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.
64  */
65 class ConstraintClause {
66     @get:JsonProperty("equal")
67     var equal: JsonNode? = null
68     @get:JsonProperty("greater_than")
69     var greaterThan: Any? = null
70     @get:JsonProperty("greater_or_equal")
71     var greaterOrEqual: Any? = null
72     @get:JsonProperty("less_than")
73     var lessThan: Any? = null
74     @get:JsonProperty("less_or_equal")
75     var lessOrEqual: Any? = null
76     @get:JsonProperty("in_range")
77     var inRange: Any? = null
78     @get:JsonProperty("valid_values")
79     var validValues: MutableList<JsonNode>? = null
80     @get:JsonProperty("length")
81     var length: Any? = null
82     @get:JsonProperty("min_length")
83     var minLength: Any? = null
84     @get:JsonProperty("max_length")
85     var maxLength: Any? = null
86     var pattern: String? = null
87     var schema: String? = null
88 }
89
90 /*
91 3.5.4 Node Filter definition
92 A node filter definition defines criteria for selection of a TOSCA Node Template based upon the template’s property values, capabilities and capability properties.
93  */
94
95 class NodeFilterDefinition {
96     var properties: MutableMap<String, PropertyDefinition>? = null
97     var capabilities: MutableList<String>? = null
98 }
99
100 /*
101 3.5.5 Repository definition
102  A repository definition defines a named external repository which contains deployment
103  and implementation artifacts that are referenced within the TOSCA Service Template.
104 */
105 class RepositoryDefinition {
106     @get:JsonIgnore
107     var id: String? = null
108     var description: String? = null
109     lateinit var url: String
110     var credential: Credential? = null
111 }
112
113
114 /*
115 3.5.6 Artifact definition
116 An artifact definition defines a named, typed file that can be associated with Node Type
117 or Node Template and used by orchestration engine to facilitate deployment and implementation of interface operations.
118  */
119 class ArtifactDefinition {
120     @get:JsonIgnore
121     var id: String? = null
122     lateinit var type: String
123     lateinit var file: String
124     var repository: String? = null
125     var description: String? = null
126     @get:JsonProperty("deploy_Path")
127     var deployPath: String? = null
128     var properties: MutableMap<String, JsonNode>? = null
129 }
130
131
132 /*
133 3.5.7 Import definition
134 An import definition is used within a TOSCA Service Template to locate and uniquely name
135 another TOSCA Service Template file which has type and template definitions to be imported (included)
136 and referenced within another Service Template.
137  */
138 class ImportDefinition {
139     @get:JsonIgnore
140     var id: String? = null
141     lateinit var file: String
142     var repository: String? = null
143     @get:JsonProperty("namespace_uri")
144     var namespaceUri: String? = null
145     @get:JsonProperty("namespace_prefix")
146     var namespacePrefix: String? = null
147 }
148
149 /*
150 3.5.8 Property definition A property definition defines a named, typed value and related data that can be associated with an
151 entity defined in this specification (e.g., Node Types, Relationship Types, Capability Types, etc.).
152 Properties are used by template authors to provide input values to TOSCA entities which indicate their “desired state” when they are
153 instantiated. The value of a property can be retrieved using the get_property function within TOSCA Service Templates.
154  */
155 class PropertyDefinition {
156     @get:JsonIgnore
157     var id: String? = null
158     var description: String? = null
159     var required: Boolean? = null
160     lateinit var type: String
161     @get:JsonProperty("default")
162     var defaultValue: JsonNode? = null
163     var status: String? = null
164     var constraints: MutableList<ConstraintClause>? = null
165     @get:JsonProperty("entry_schema")
166     var entrySchema: EntrySchema? = null
167     // Mainly used in Workflow Outputs
168     @get:ApiModelProperty(notes = "Property Value, It may be Expression or Json type values")
169     var value: JsonNode? = null
170 }
171
172
173 /*
174 3.5.10 Attribute definition
175
176 An attribute definition defines a named, typed value that can be associated with an entity defined in this
177 specification (e.g., a Node, Relationship or Capability Type).  Specifically, it is used to expose the
178 “actual state” of some property of a TOSCA entity after it has been deployed and instantiated
179 (as set by the TOSCA orchestrator). Attribute values can be retrieved via the get_attribute function
180 from the instance model and used as values to other entities within TOSCA Service Templates.
181  */
182
183 class AttributeDefinition {
184     @get:JsonIgnore
185     var id: String? = null
186     var description: String? = null
187     var required: Boolean? = null
188     lateinit var type: String
189     @JsonProperty("default")
190     var defaultValue: JsonNode? = null
191     var status: String? = null
192     var constraints: MutableList<ConstraintClause>? = null
193     @JsonProperty("entry_schema")
194     var entrySchema: EntrySchema? = null
195     // Mainly used in DSL definitions
196     @get:ApiModelProperty(notes = "Attribute Value, It may be Expression or Json type values")
197     var value: JsonNode? = null
198 }
199
200 /*
201 3.5.13 Operation definition
202 An operation definition defines a named function or procedure that can be bound to an implementation artifact (e.g., a script).
203  */
204 class OperationDefinition {
205     @get:JsonIgnore
206     var id: String? = null
207     var description: String? = null
208     var implementation: Implementation? = null
209     var inputs: MutableMap<String, PropertyDefinition>? = null
210     var outputs: MutableMap<String, PropertyDefinition>? = null
211 }
212
213 class Implementation {
214     var primary: String? = null
215     var dependencies: MutableList<String>? = null
216     @get:JsonProperty("operation_host")
217     var operationHost: String = BluePrintConstants.PROPERTY_SELF
218     //Timeout value in seconds
219     var timeout: Int = 180
220 }
221
222 /*
223 3.5.14 Interface definition
224 An interface definition defines a named interface that can be associated with a Node or Relationship Type
225  */
226 class InterfaceDefinition {
227     @get:JsonIgnore
228     var id: String? = null
229     var type: String? = null
230     var operations: MutableMap<String, OperationDefinition>? = null
231     var inputs: MutableMap<String, PropertyDefinition>? = null
232 }
233
234 /*
235 3.5.15 Event Filter definition
236 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.
237  */
238 class EventFilterDefinition {
239     @get:JsonIgnore
240     var id: String? = null
241     lateinit var node: String
242     var requirement: String? = null
243     var capability: String? = null
244 }
245
246 /*
247 3.5.16 Trigger definition TODO
248 A trigger definition defines the event, condition and action that is used to “trigger” a policy it is associated with.
249  */
250 class TriggerDefinition {
251     @get:JsonIgnore
252     var id: String? = null
253     var description: String? = null
254     @get:JsonProperty("event_type")
255     lateinit var eventType: String
256     @get:JsonProperty("target_filter")
257     var targetFilter: EventFilterDefinition? = null
258     var condition: ConditionClause? = null
259     var constraint: ConditionClause? = null
260     var method: String? = null
261     lateinit var action: String
262 }
263
264 /*
265     3.5.17 Workflow activity definition
266     A workflow activity defines an operation to be performed in a TOSCA workflow. Activities allows to:
267     · Delegate the workflow for a node expected to be provided         by the orchestrator
268     · Set the state of a node
269     · Call an operation        defined on a TOSCA interface of a node, relationship or group
270     · Inline another workflow defined in the topology (to allow reusability)
271  */
272 class Activity {
273     var delegate: String? = null
274     @get:JsonProperty("set_state")
275     var setState: String? = null
276     @get:JsonProperty("call_operation")
277     var callOperation: String? = null
278     var inlines: ArrayList<String>? = null
279 }
280
281 /*
282 3.5.20 Workflow precondition definition
283 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.
284  */
285 class PreConditionDefinition {
286     @get:JsonIgnore
287     var id: String? = null
288     lateinit var target: String
289     @get:JsonProperty("target_relationship")
290     lateinit var targetRelationship: String
291     lateinit var condition: ArrayList<ConditionClause>
292 }
293
294 /*
295 3.5.21 Workflow step definition
296 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.
297  */
298 class Step {
299     @get:JsonIgnore
300     var id: String? = null
301     var description: String? = null
302     var target: String? = null
303     @JsonProperty("target_relationship")
304     var targetRelationship: String? = null
305     @JsonProperty("operation_host")
306     var operationHost: String? = null
307     var activities: ArrayList<Activity>? = null
308     @get:JsonProperty("on_success")
309     var onSuccess: ArrayList<String>? = null
310     @get:JsonProperty("on_failure")
311     var onFailure: ArrayList<String>? = null
312 }
313
314 /*
315 3.6.2 Capability definition
316 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.
317  */
318
319 class CapabilityDefinition {
320     @get:JsonIgnore
321     var id: String? = null
322     lateinit var type: String
323     var description: String? = null
324     var properties: MutableMap<String, PropertyDefinition>? = null
325     @get:JsonProperty("valid_source_types")
326     var validSourceTypes: MutableList<String>? = null
327     var occurrences: MutableList<Any>? = null
328 }
329
330 /*
331 3.6.3 Requirement definition
332 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).
333  */
334 class RequirementDefinition {
335     @get:JsonIgnore
336     var id: String? = null
337     var description: String? = null
338     var capability: String? = null
339     var node: String? = null
340     var relationship: String? = null
341     var occurrences: MutableList<Any>? = null
342 }
343
344 /*
345 3.6.4 Artifact Type
346 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.
347  */
348 class ArtifactType : EntityType() {
349     @get:JsonProperty("mime_type")
350     var mimeType: String? = null
351     @get:JsonProperty("file_ext")
352     var fileExt: MutableList<String>? = null
353
354 }
355
356 /*
357 3.6.6 Data Type
358 A Data Type definition defines the schema for new named datatypes in TOSCA.
359  */
360
361 class DataType : EntityType() {
362     var constraints: MutableList<ConstraintClause>? = null
363 }
364
365 /*
366 3.6.9 Node Type
367 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.
368
369  */
370
371 class NodeType : EntityType() {
372     var capabilities: MutableMap<String, CapabilityDefinition>? = null
373     var requirements: MutableMap<String, RequirementDefinition>? = null
374     var interfaces: MutableMap<String, InterfaceDefinition>? = null
375     var artifacts: MutableMap<String, ArtifactDefinition>? = null
376 }
377
378 /*
379 3.6.8 Requirement Type
380 A Requirement Type is a reusable entity that describes a kind of requirement that a Node Type can declare to expose.
381 The TOSCA Simple Profile seeks to simplify the need for declaring specific Requirement Types
382 from nodes and instead rely upon nodes declaring their features sets using TOSCA Capability Types
383 along with a named Feature notation.
384  */
385
386 class RequirementType : EntityType() {
387     var requirements: MutableMap<String, RequirementDefinition>? = null
388     var capabilities: MutableMap<String, CapabilityDefinition>? = null
389     var interfaces: MutableMap<String, InterfaceDefinition>? = null
390     var artifacts: MutableMap<String, ArtifactDefinition>? = null
391 }
392
393 /*
394 3.6.10 Relationship Type
395 A Relationship Type is a reusable entity that defines the type of one or more relationships between Node Types or Node Templates.
396 */
397
398 class RelationshipType : EntityType() {
399     var interfaces: MutableMap<String, InterfaceDefinition>? = null
400     @get:JsonProperty("valid_target_types")
401     var validTargetTypes: ArrayList<String>? = null
402 }
403
404 /*
405 3.6.11 Group Type
406 A Group Type defines logical grouping types for nodes, typically for different management purposes.
407 Groups can effectively be viewed as logical nodes that are not part of the physical deployment topology
408  of an application, yet can have capabilities and the ability to attach policies and interfaces
409  that can be applied (depending on the group type) to its member nodes.
410  */
411
412 class GroupType : EntityType() {
413     var members: MutableList<String>? = null
414     var requirements: ArrayList<RequirementDefinition>? = null
415     var capabilities: MutableMap<String, CapabilityDefinition>? = null
416     var interfaces: MutableMap<String, InterfaceDefinition>? = null
417
418 }
419
420 /*
421     3.6.12 Policy Type
422     A Policy Type defines a type of requirement that affects or governs an application or service’s
423     topology at some stage of its lifecycle, but is not explicitly part of the topology itself
424     (i.e., it does not prevent the application or service from being deployed or run if it did not exist).
425  */
426 class PolicyType : EntityType() {
427     lateinit var targets: MutableList<String>
428 }
429
430 /*
431 3.7.1 Capability assignment
432 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.
433  */
434 class CapabilityAssignment {
435     @get:JsonIgnore
436     var id: String? = null
437     var attributes: MutableMap<String, JsonNode>? = null
438     var properties: MutableMap<String, JsonNode>? = null
439 }
440
441 /*
442 3.7.4 Relationship Template
443 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.
444  */
445 class GroupDefinition {
446     @get:JsonIgnore
447     var id: String? = null
448     lateinit var type: String
449     var description: String? = null
450     var metadata: MutableMap<String, String>? = null
451     var properties: MutableMap<String, JsonNode>? = null
452     var members = ArrayList<String>()
453     var interfaces: MutableMap<String, InterfaceDefinition>? = null
454 }
455
456 /*
457 3.7.6 Policy definition
458 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.).
459  */
460 class PolicyDefinition {
461     @get:JsonIgnore
462     var id: String? = null
463     lateinit var type: String
464     var description: String? = null
465     var metadata: MutableMap<String, String>? = null
466     var properties: MutableMap<String, JsonNode>? = null
467     var targets: MutableList<String>? = null
468 }
469
470
471 /*
472 3.8 Topology Template definition
473 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.
474  */
475 class TopologyTemplate {
476     @get:JsonIgnore
477     var id: String? = null
478     var description: String? = null
479     var inputs: MutableMap<String, PropertyDefinition>? = null
480     @get:JsonProperty("node_templates")
481     var nodeTemplates: MutableMap<String, NodeTemplate>? = null
482     @get:JsonProperty("relationship_templates")
483     var relationshipTemplates: MutableMap<String, RelationshipTemplate>? = null
484     var policies: MutableMap<String, PolicyDefinition>? = null
485     var outputs: MutableMap<String, PropertyDefinition>? = null
486     @get:JsonProperty("substitution_mappings")
487     var substitutionMappings: Any? = null
488     var workflows: MutableMap<String, Workflow>? = null
489 }
490
491 class SubstitutionMapping {
492     @get:JsonProperty("node_type")
493     lateinit var nodeType: String
494     lateinit var capabilities: ArrayList<String>
495     lateinit var requirements: ArrayList<String>
496 }
497
498 class EntrySchema {
499     lateinit var type: String
500     var constraints: MutableList<ConstraintClause>? = null
501 }
502
503 class InterfaceAssignment {
504     @get:JsonIgnore
505     var id: String? = null
506     var operations: MutableMap<String, OperationAssignment>? = null
507     var inputs: MutableMap<String, JsonNode>? = null
508 }
509
510 /*
511 3.7.3 Node Template
512 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.
513  */
514
515 open class NodeTemplate {
516     @get:JsonIgnore
517     var id: String? = null
518     var description: String? = null
519     lateinit var type: String
520     var metadata: MutableMap<String, String>? = null
521     var directives: MutableList<String>? = null
522     //@get:JsonSerialize(using = PropertyDefinitionValueSerializer::class)
523     var properties: MutableMap<String, JsonNode>? = null
524     var attributes: MutableMap<String, JsonNode>? = null
525     var capabilities: MutableMap<String, CapabilityAssignment>? = null
526     var requirements: MutableMap<String, RequirementAssignment>? = null
527     var interfaces: MutableMap<String, InterfaceAssignment>? = null
528     var artifacts: MutableMap<String, ArtifactDefinition>? = null
529     @get:JsonProperty("node_filter")
530     var nodeFilter: NodeFilterDefinition? = null
531     var copy: String? = null
532 }
533
534 class OperationAssignment {
535     @get:JsonIgnore
536     var id: String? = null
537     var description: String? = null
538     var implementation: Implementation? = null
539     var inputs: MutableMap<String, JsonNode>? = null
540     var outputs: MutableMap<String, JsonNode>? = null
541 }
542
543 /*
544 3.7.4 Relationship Template
545 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.
546  */
547
548 class RelationshipTemplate {
549     var type: String? = null
550     var description: String? = null
551     var metadata: MutableMap<String, String>? = null
552     var properties: MutableMap<String, PropertyDefinition>? = null
553     var attributes: MutableMap<String, JsonNode>? = null
554     var interfaces: MutableMap<String, InterfaceDefinition>? = null
555     var copy: String? = null
556 }
557
558 /*
559 3.7.2 Requirement assignment
560 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.
561  */
562
563 class RequirementAssignment {
564     @get:JsonIgnore
565     var id: String? = null
566     var capability: String? = null
567     var node: String? = null
568     //Relationship Type or Relationship Template
569     var relationship: String? = null
570 }
571
572
573 class Workflow {
574     @get:JsonIgnore
575     var id: String? = null
576     var description: String? = null
577     var steps: MutableMap<String, Step>? = null
578     var preconditions: ArrayList<PreConditionDefinition>? = null
579     var inputs: MutableMap<String, PropertyDefinition>? = null
580     var outputs: MutableMap<String, PropertyDefinition>? = null
581 }
582
583
584 class ConditionClause {
585     var and: ArrayList<MutableMap<String, Any>>? = null
586     var or: ArrayList<MutableMap<String, Any>>? = null
587     @get:JsonProperty("assert")
588     var assertConditions: ArrayList<MutableMap<String, Any>>? = null
589 }
590
591 /*
592 3.9 Service Template definition
593 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.
594  */
595
596 @JsonPropertyOrder(value = ["toscaDefinitionsVersion", "description", "metadata", "imports", "dsl_definitions",
597     "topologyTemplate"])
598 class ServiceTemplate : Cloneable {
599     @get:JsonIgnore
600     var id: String? = null
601     @get:JsonProperty("tosca_definitions_version")
602     var toscaDefinitionsVersion: String = "controller_blueprint_1_0_0"
603     var metadata: MutableMap<String, String>? = null
604     var description: String? = null
605     @get:JsonProperty("dsl_definitions")
606     var dslDefinitions: MutableMap<String, JsonNode>? = null
607     var repositories: MutableMap<String, RepositoryDefinition>? = null
608     var imports: MutableList<ImportDefinition>? = null
609     @get:JsonProperty("artifact_types")
610     var artifactTypes: MutableMap<String, ArtifactType>? = null
611     @get:JsonProperty("data_types")
612     var dataTypes: MutableMap<String, DataType>? = null
613     @get:JsonProperty("relationship_types")
614     var relationshipTypes: MutableMap<String, RelationshipType>? = null
615     @get:JsonProperty("node_types")
616     var nodeTypes: MutableMap<String, NodeType>? = null
617     @get:JsonProperty("policy_types")
618     var policyTypes: MutableMap<String, PolicyType>? = null
619     @get:JsonProperty("topology_template")
620     var topologyTemplate: TopologyTemplate? = null
621
622     override public fun clone(): ServiceTemplate {
623         return super.clone() as ServiceTemplate
624     }
625 }
626
627 class ToscaMetaData {
628     lateinit var toscaMetaFileVersion: String
629     lateinit var csarVersion: String
630     lateinit var createdBy: String
631     lateinit var entityDefinitions: String
632     var templateTags: String? = null
633 }
634