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
20 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
21 import org.onap.ccsdk.sli.core.sli.*
22 import org.onap.ccsdk.sli.core.sli.provider.base.*
23 import org.slf4j.LoggerFactory
25 import org.springframework.beans.factory.annotation.Autowired
26 import org.springframework.context.ApplicationContext
27 import org.springframework.stereotype.Service
29 import javax.annotation.PostConstruct
31 interface BlueprintSvcLogicService : SvcLogicServiceBase {
33 fun registerDefaultExecutors()
35 fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor)
37 fun unRegisterExecutors(name: String)
39 suspend fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any
41 @Deprecated("Populate Graph Dynamically from Blueprints, No need to get from Database Store ")
42 override fun getStore(): SvcLogicStore {
43 TODO("not implemented")
46 @Deprecated("Not used in Micro service Implementation")
47 override fun hasGraph(module: String, rpc: String, version: String?, mode: String): Boolean {
48 TODO("not implemented")
51 @Deprecated("Not used in Micro service Implementation")
52 override fun execute(p0: String?, p1: String?, p2: String?, p3: String?, p4: Properties?): Properties {
53 TODO("not implemented")
59 class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService {
61 private val log = LoggerFactory.getLogger(DefaultBlueprintSvcLogicService::class.java)
63 private val nodeExecutors: MutableMap<String, AbstractSvcLogicNodeExecutor> = hashMapOf()
66 private lateinit var context: ApplicationContext
69 override fun registerDefaultExecutors() {
71 val executeNodeExecutor = context.getBean(ExecuteNodeExecutor::class.java)
72 registerExecutors("execute", executeNodeExecutor)
73 registerExecutors("block", BlockNodeExecutor())
74 registerExecutors("return", ReturnNodeExecutor())
75 registerExecutors("break", BreakNodeExecutor())
76 registerExecutors("exit", ExitNodeExecutor())
79 override fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor) {
80 log.info("Registering executors($name) with type(${svcLogicNodeExecutor.javaClass}")
81 nodeExecutors[name] = svcLogicNodeExecutor
84 override fun unRegisterExecutors(name: String) {
85 if (nodeExecutors.containsKey(name)) {
86 log.info("UnRegistering executors($name)")
87 nodeExecutors.remove(name)
91 override suspend fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>,
93 //Initialise BlueprintSvcLogic Context with Blueprint Runtime Service and Input Request
94 val blueprintSvcLogicContext = BlueprintSvcLogicContext()
95 blueprintSvcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
96 blueprintSvcLogicContext.setRequest(input)
98 execute(graph, blueprintSvcLogicContext)
100 return blueprintSvcLogicContext.getResponse()
103 override fun executeNode(node: SvcLogicNode?, ctx: SvcLogicContext): SvcLogicNode? {
107 if (log.isDebugEnabled) {
108 log.debug("Executing node {}", node.nodeId)
111 val executor = this.nodeExecutors[node.nodeType]
113 if (executor != null) {
114 log.debug("Executing node executor for node type {} - {}", node.nodeType, executor.javaClass.name)
115 return executor.execute(this, node, ctx)
117 throw SvcLogicException("Attempted to execute a node of type " + node.nodeType + ", but no executor was registered for this type")
122 override fun execute(graph: SvcLogicGraph, svcLogicContext: SvcLogicContext): SvcLogicContext {
123 MDC.put("currentGraph", graph.toString())
125 var curNode: SvcLogicNode? = graph.rootNode
126 log.info("About to execute graph {}", graph.toString())
129 while (curNode != null) {
130 MDC.put("nodeId", curNode.nodeId.toString() + " (" + curNode.nodeType + ")")
131 log.info("About to execute node # {} ({})", curNode.nodeId, curNode.nodeType)
132 val nextNode = this.executeNode(curNode, svcLogicContext)
135 } catch (var5: ExitNodeException) {
136 log.debug("SvcLogicServiceImpl caught ExitNodeException")
140 MDC.remove("currentGraph")
141 return svcLogicContext