summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/blueprints
diff options
context:
space:
mode:
authorJozsef Csongvai <jozsef.csongvai@bell.ca>2020-12-09 19:49:48 -0500
committerKAPIL SINGAL <ks220y@att.com>2021-03-24 01:58:57 +0000
commitaa3f6d9d6d87d265319820eaecb77dabed010a7b (patch)
treed8b070a0fb63ac9b36f871ac530f0fcd8c07032a /ms/blueprintsprocessor/modules/blueprints
parent1f5c3b30a6bcee56dcdf848e578f2f72cddd3cd7 (diff)
Refactoring to enable on_failure for imperative workflow
BlueprintError needs to associate errors with the steps in which they occurred in order for imperative workflow to handle on_failure properly. Made stepName more accessible and corrected places where stepName was assigned to nodeTemplateName. Issue-ID: CCSDK-3219 Change-Id: I7e5805745c63558cff6be533e1b99c32ad06c3db Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca> (cherry picked from commit b96b44d6d7ca11dbbc3ad4bd2194df31fba5efb6)
Diffstat (limited to 'ms/blueprintsprocessor/modules/blueprints')
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt18
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt10
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt12
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorService.kt6
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintServiceTemplateValidatorImpl.kt2
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintWorkflowValidatorImpl.kt3
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorServiceTest.kt8
7 files changed, 37 insertions, 22 deletions
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt
index b4d95ca3b..2ecdce770 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt
@@ -18,13 +18,21 @@ package org.onap.ccsdk.cds.controllerblueprints.core
class BlueprintError {
- var errors: MutableList<String> = arrayListOf()
+ private val errors: MutableMap<String, MutableList<String>> = mutableMapOf()
- fun addError(type: String, name: String, error: String) {
- this.errors.add("$type : $name : $error")
+ fun addError(type: String, name: String, error: String, stepName: String) {
+ addError("$type : $name : $error", stepName)
}
- fun addError(error: String) {
- this.errors.add(error)
+ fun addError(error: String, stepName: String) {
+ errors.getOrPut(stepName, { mutableListOf() }).add(error)
}
+
+ fun addErrors(stepName: String, errorList: List<String>) {
+ errors.getOrPut(stepName, { mutableListOf() }).addAll(errorList)
+ }
+
+ fun allErrors(): List<String> = errors.values.flatten()
+
+ fun stepErrors(stepName: String): MutableList<String>? = errors[stepName]
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt
index b79b86747..62026be88 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt
@@ -103,8 +103,11 @@ class BlueprintContext(val serviceTemplate: ServiceTemplate) {
fun workflowInputs(workFlowName: String) = workflowByName(workFlowName).inputs
+ fun workflowSteps(workFlowName: String) =
+ workflowByName(workFlowName).steps ?: throw BlueprintException("could't get steps for workflow($workFlowName)")
+
fun workflowStepByName(workFlowName: String, stepName: String): Step {
- return workflowByName(workFlowName).steps?.get(stepName)
+ return workflowSteps(workFlowName)[stepName]
?: throw BlueprintException("could't get step($stepName) for workflow($workFlowName)")
}
@@ -114,8 +117,9 @@ class BlueprintContext(val serviceTemplate: ServiceTemplate) {
}
fun workflowFirstStepNodeTemplate(workFlowName: String): String {
- val firstStepName = workflowByName(workFlowName).steps?.keys?.first()
- ?: throw BlueprintException("could't get first step for workflow($workFlowName)")
+ val firstStepName = workflowSteps(workFlowName).keys.ifEmpty {
+ throw BlueprintException("could't get first step for workflow($workFlowName)")
+ }.first()
return workflowStepNodeTemplate(workFlowName, firstStepName)
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt
index 482d21abd..94ba98603 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt
@@ -10,24 +10,24 @@ class BlueprintErrorTest {
fun testBlueprintErrorIsCreatedWithemptyList() {
val bluePrintError = BlueprintError()
- assertTrue(bluePrintError.errors.isEmpty())
+ assertTrue(bluePrintError.allErrors().isEmpty())
}
@Test
fun testAddErrorWith3Params() {
val bluePrintError = BlueprintError()
- bluePrintError.addError("type", "name", "error")
+ bluePrintError.addError("type", "name", "error", "step")
- assertEquals("type : name : error", bluePrintError.errors[0])
+ assertEquals("type : name : error", bluePrintError.stepErrors("step")!![0])
}
@Test
- fun testAddErrorWith1Params() {
+ fun testAddErrorWith2Params() {
val bluePrintError = BlueprintError()
- bluePrintError.addError("error")
+ bluePrintError.addError("error", "step")
- assertEquals("error", bluePrintError.errors[0])
+ assertEquals("error", bluePrintError.stepErrors("step")!![0])
}
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorService.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorService.kt
index fe3aeb1ed..aac1c2e97 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorService.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorService.kt
@@ -17,6 +17,7 @@
package org.onap.ccsdk.cds.controllerblueprints.validation
+import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintTypeValidatorService
@@ -57,9 +58,10 @@ open class BlueprintDesignTimeValidatorService(
// Validate Resource Definitions
validateResourceDefinitions(bluePrintRuntimeService)
- if (bluePrintRuntimeService.getBlueprintError().errors.size > 0) {
- throw BlueprintException("failed in blueprint validation : ${bluePrintRuntimeService.getBlueprintError().errors.joinToString("\n")}")
+ bluePrintRuntimeService.getBlueprintError().allErrors().ifNotEmpty {
+ throw BlueprintException("failed in blueprint validation : ${this.joinToString("\n")}")
}
+
return true
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintServiceTemplateValidatorImpl.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintServiceTemplateValidatorImpl.kt
index b9450e66d..137e6e6b9 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintServiceTemplateValidatorImpl.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintServiceTemplateValidatorImpl.kt
@@ -58,7 +58,7 @@ open class BlueprintServiceTemplateValidatorImpl(private val bluePrintTypeValida
serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) }
} catch (e: Exception) {
log.error("failed in blueprint service template validation", e)
- error.addError(BlueprintConstants.PATH_SERVICE_TEMPLATE, paths.joinToString(BlueprintConstants.PATH_DIVIDER), e.message!!)
+ error.addError(BlueprintConstants.PATH_SERVICE_TEMPLATE, paths.joinToString(BlueprintConstants.PATH_DIVIDER), e.message!!, "BlueprintServiceTemplateValidator")
}
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintWorkflowValidatorImpl.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintWorkflowValidatorImpl.kt
index 8f9cb01c5..bff09fc83 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintWorkflowValidatorImpl.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintWorkflowValidatorImpl.kt
@@ -76,7 +76,8 @@ open class BlueprintWorkflowValidatorImpl(private val bluePrintTypeValidatorServ
.addError(
"Failed to validate Workflow($workflowName)'s step($stepName)'s " +
"definition",
- paths.joinToString(BlueprintConstants.PATH_DIVIDER), e.message!!
+ paths.joinToString(BlueprintConstants.PATH_DIVIDER), e.message!!,
+ "BlueprintWorkflowValidatorImpl"
)
}
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorServiceTest.kt
index 49c12b95f..dd82ec5da 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorServiceTest.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BlueprintDesignTimeValidatorServiceTest.kt
@@ -63,10 +63,10 @@ class BlueprintDesignTimeValidatorServiceTest {
workflow.steps = mutableMapOf("test" to step)
workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
- assertEquals(1, bluePrintRuntime.getBlueprintError().errors.size)
+ assertEquals(1, bluePrintRuntime.getBlueprintError().allErrors().size)
assertEquals(
"Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : could't get node template for the name(TestCaseFailNoNodeTemplate)",
- bluePrintRuntime.getBlueprintError().errors[0]
+ bluePrintRuntime.getBlueprintError().allErrors()[0]
)
}
@@ -96,12 +96,12 @@ class BlueprintDesignTimeValidatorServiceTest {
workflow.steps = mutableMapOf("test" to step)
workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
- assertEquals(1, bluePrintRuntime.getBlueprintError().errors.size)
+ assertEquals(1, bluePrintRuntime.getBlueprintError().allErrors().size)
assertEquals(
"Failed to validate Workflow(resource-assignment)'s step(test)'s definition : " +
"resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', " +
"Expected 'tosca.nodes.Workflow' or 'tosca.nodes.Component'",
- bluePrintRuntime.getBlueprintError().errors[0]
+ bluePrintRuntime.getBlueprintError().allErrors()[0]
)
}