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