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.asPropertyDefinitionMap
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.Activity
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.Step
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
25 import kotlin.reflect.KClass
27 class WorkflowBuilder(private val id: String, private val description: String) {
29 private var workflow = Workflow()
30 private var steps: MutableMap<String, Step>? = null
31 private var inputs: MutableMap<String, PropertyDefinition>? = null
32 private var outputs: MutableMap<String, PropertyDefinition>? = null
35 fun nodeTemplateStep(nodeTemplateName: String, description: String) {
36 step(nodeTemplateName, nodeTemplateName, "$description step")
39 fun step(id: String, target: String, description: String) {
42 steps!![id] = StepBuilder(id, target, description).build()
45 fun step(id: String, target: String, description: String, block: StepBuilder.() -> Unit) {
48 steps!![id] = StepBuilder(id, target, description).apply(block).build()
51 fun inputs(kClazz: KClass<*>) {
52 inputs = kClazz.asPropertyDefinitionMap()
55 fun inputs(block: PropertiesDefinitionBuilder.() -> Unit) {
56 inputs = PropertiesDefinitionBuilder().apply(block).build()
59 fun outputs(block: PropertiesDefinitionBuilder.() -> Unit) {
60 outputs = PropertiesDefinitionBuilder().apply(block).build()
63 fun outputs(kClazz: KClass<*>) {
64 outputs = kClazz.asPropertyDefinitionMap()
67 fun build(): Workflow {
69 workflow.description = description
70 workflow.steps = steps
71 workflow.inputs = inputs
72 workflow.outputs = outputs
78 private val id: String,
79 private val target: String,
80 private val description: String
83 private var step = Step()
84 private var activities: ArrayList<Activity> = arrayListOf()
85 private var onSuccess: ArrayList<String>? = null
86 private var onFailure: ArrayList<String>? = null
88 fun activity(callOperation: String) {
89 val activity = Activity()
90 activity.callOperation = callOperation
91 activities.add(activity)
94 fun success(vararg successTargets: String) {
95 if (onSuccess == null)
96 onSuccess = arrayListOf()
97 successTargets.forEach {
102 fun failure(vararg failureTargets: String) {
103 if (onFailure == null)
104 onFailure = arrayListOf()
105 failureTargets.forEach {
113 // Add Default Activity, Assumption is only one Operation
114 activity(".${BlueprintConstants.DEFAULT_STEP_OPERATION}")
115 step.description = description
116 step.activities = activities
117 step.onSuccess = onSuccess
118 step.onFailure = onFailure