2 * Copyright © 20201 Bell Canada.
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.
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
25 import org.onap.ccsdk.cds.controllerblueprints.core.logger
27 open class TestScript : AbstractScriptComponentFunction() {
29 private val log = logger(TestScript::class)
31 private val FAILED = "FAILED".asJsonPrimitive()
32 private val SUCCEEDED = "SUCCEEDED".asJsonPrimitive()
34 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
35 val failingSteps = inputValue("failing-steps")
36 var shouldFail = false
37 if (failingSteps?.has(this.stepName) == true) {
38 shouldFail = failingSteps[this.stepName].asBoolean()
40 log.info("running step ${this.stepName}, should fail: $shouldFail")
41 setAttribute("response-data", if (shouldFail) FAILED else SUCCEEDED)
44 throw BluePrintException("Step failed: ${this.stepName}")
48 fun inputValue(name: String): JsonNode? {
50 return bluePrintRuntimeService.getInputValue(name)
51 } catch (e: BluePrintProcessorException) { null }
54 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
55 log.info("Executing Recovery for step ${this.stepName}")
56 addError(runtimeException.message ?: "Failed without error message")