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.BluePrintConstants
20 import org.onap.ccsdk.cds.controllerblueprints.core.data.Activity
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.Step
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
25 class WorkflowBuilder(private val id: String, private val description: String) {
27 private var workflow = Workflow()
28 private var steps: MutableMap<String, Step>? = null
29 private var inputs: MutableMap<String, PropertyDefinition>? = null
30 private var outputs: MutableMap<String, PropertyDefinition>? = null
33 fun nodeTemplateStep(nodeTemplateName: String, description: String) {
34 step(nodeTemplateName, nodeTemplateName, "$description step")
37 fun step(id: String, target: String, description: String) {
40 steps!![id] = StepBuilder(id, target, description).build()
43 fun step(id: String, target: String, description: String, block: StepBuilder.() -> Unit) {
46 steps!![id] = StepBuilder(id, target, description).apply(block).build()
49 fun inputs(block: PropertiesDefinitionBuilder.() -> Unit) {
50 inputs = PropertiesDefinitionBuilder().apply(block).build()
53 fun outputs(block: PropertiesDefinitionBuilder.() -> Unit) {
54 outputs = PropertiesDefinitionBuilder().apply(block).build()
57 fun build(): Workflow {
59 workflow.description = description
60 workflow.steps = steps
61 workflow.inputs = inputs
62 workflow.outputs = outputs
68 class StepBuilder(private val id: String, private val target: String,
69 private val description: String) {
71 private var step = Step()
72 private var activities: ArrayList<Activity> = arrayListOf()
73 private var onSuccess: ArrayList<String>? = null
74 private var onFailure: ArrayList<String>? = null
76 fun activity(callOperation: String) {
77 val activity = Activity()
78 activity.callOperation = callOperation
79 activities.add(activity)
82 fun success(vararg successTargets: String) {
83 if (onSuccess == null)
84 onSuccess = arrayListOf()
85 successTargets.forEach {
90 fun failure(vararg failureTargets: String) {
91 if (onFailure == null)
92 onFailure = arrayListOf()
93 failureTargets.forEach {
101 // Add Default Activity, Assumption is only one Operation
102 activity(".${BluePrintConstants.DEFAULT_STEP_OPERATION}")
103 step.description = description
104 step.activities = activities
105 step.onSuccess = onSuccess
106 step.onFailure = onFailure