2 * Copyright © 2019 IBM.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.controllerblueprints.core.dsl
19 import org.onap.ccsdk.cds.controllerblueprints.core.data.Activity
20 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.Step
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
24 class WorkflowBuilder(private val id: String, private val description: String) {
26 private var workflow = Workflow()
27 private var steps: MutableMap<String, Step>? = null
28 private var inputs: MutableMap<String, PropertyDefinition>? = null
29 private var outputs: MutableMap<String, PropertyDefinition>? = null
32 fun nodeTemplateStep(nodeTemplateName: String, description: String) {
33 step(nodeTemplateName, nodeTemplateName, "")
36 fun step(id: String, target: String, description: String) {
39 steps!![id] = StepBuilder(id, target, description).build()
42 fun step(id: String, target: String, description: String, block: StepBuilder.() -> Unit) {
45 steps!![id] = StepBuilder(id, target, description).apply(block).build()
48 fun inputs(block: PropertiesDefinitionBuilder.() -> Unit) {
49 inputs = PropertiesDefinitionBuilder().apply(block).build()
52 fun outputs(block: PropertiesDefinitionBuilder.() -> Unit) {
53 outputs = PropertiesDefinitionBuilder().apply(block).build()
56 fun build(): Workflow {
58 workflow.description = description
59 workflow.steps = steps
60 workflow.inputs = inputs
61 workflow.outputs = outputs
67 class StepBuilder(private val id: String, private val target: String,
68 private val description: String) {
70 private var step = Step()
71 private var activities: ArrayList<Activity> = arrayListOf()
72 private var onSuccess: ArrayList<String>? = null
73 private var onFailure: ArrayList<String>? = null
75 fun activity(callOperation: String) {
76 val activity = Activity()
77 activity.callOperation = callOperation
78 activities.add(activity)
81 fun success(vararg successTargets: String) {
82 if (onSuccess == null)
83 onSuccess = arrayListOf()
84 successTargets.forEach {
89 fun failure(vararg failureTargets: String) {
90 if (onFailure == null)
91 onFailure = arrayListOf()
92 failureTargets.forEach {
100 // Add Default Activity, Assumption is only one Operation
102 step.description = description
103 step.activities = activities
104 step.onSuccess = onSuccess
105 step.onFailure = onFailure