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