5dc5b9dbaa890d43827c7b015b701c87bcb89758
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock
19
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.controllerblueprints.core.asJsonPrimitive
23 import org.slf4j.LoggerFactory
24 import org.springframework.beans.factory.config.ConfigurableBeanFactory
25 import org.springframework.context.annotation.Bean
26 import org.springframework.context.annotation.Configuration
27 import org.springframework.context.annotation.Scope
28 import org.springframework.stereotype.Component
29
30 @Configuration
31 open class MockComponentConfiguration {
32
33     @Bean(name = ["component-resource-resolution", "component-netconf-executor", "component-jython-executor"])
34     open fun createComponentFunction(): AbstractComponentFunction {
35         return MockComponentFunction()
36     }
37 }
38
39 class MockComponentFunction : AbstractComponentFunction() {
40
41     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
42
43     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
44         log.info("Processing component : $operationInputs")
45
46         bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,
47                 "assignment-params", "params".asJsonPrimitive())
48     }
49
50     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
51         log.info("Recovering component..")
52     }
53 }
54
55 @Component("singleton-function")
56 @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
57 class SingletonComponentFunction : AbstractComponentFunction() {
58
59     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
60
61     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
62         log.info("Processing component : $operationInputs")
63     }
64
65     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
66         log.info("Recovering component..")
67     }
68 }
69
70 @Component("prototype-function")
71 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
72 class PrototypeComponentFunction : AbstractComponentFunction() {
73
74     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
75
76     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
77         log.info("Processing component : $operationInputs")
78     }
79
80     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
81         log.info("Recovering component..")
82     }
83 }