2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
22 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTemplateComponentScriptExecutor
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
25 import org.slf4j.LoggerFactory
26 import org.springframework.beans.factory.config.ConfigurableBeanFactory
27 import org.springframework.context.annotation.Bean
28 import org.springframework.context.annotation.Configuration
29 import org.springframework.context.annotation.Scope
30 import org.springframework.stereotype.Component
32 fun mockNodeTemplateComponentScriptExecutor(id: String, script: String) = BluePrintTypes.nodeTemplateComponentScriptExecutor(id,
33 "mock($id) component function") {
34 definedOperation("") {
37 scriptClassReference(script)
43 open class MockComponentConfiguration {
45 @Bean(name = ["component-resource-resolution", "component-netconf-executor", "component-jython-executor"])
46 open fun createComponentFunction(): AbstractComponentFunction {
47 return MockComponentFunction()
51 class MockComponentFunction : AbstractComponentFunction() {
53 private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
55 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
56 log.info("Processing component : $operationInputs")
58 bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,
59 "assignment-params", "params".asJsonPrimitive())
62 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
63 log.info("Recovering component..")
67 @Component("singleton-function")
68 @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
69 class SingletonComponentFunction : AbstractComponentFunction() {
71 private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
73 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
74 log.info("Processing component : $operationInputs")
77 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
78 log.info("Recovering component..")
82 @Component("prototype-function")
83 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
84 class PrototypeComponentFunction : AbstractComponentFunction() {
86 private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
88 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
89 log.info("Processing component : $operationInputs")
92 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
93 log.info("Recovering component..")