2 * Copyright © 2017-2018 AT&T Intellectual Property.
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.
17 package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow
19 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
20 import org.onap.ccsdk.sli.core.sli.*
21 import org.onap.ccsdk.sli.core.sli.provider.base.*
22 import org.slf4j.LoggerFactory
24 import org.springframework.beans.factory.annotation.Autowired
25 import org.springframework.context.ApplicationContext
26 import org.springframework.stereotype.Service
28 import javax.annotation.PostConstruct
30 interface BlueprintSvcLogicService : SvcLogicServiceBase {
32 fun registerDefaultExecutors()
34 fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor)
36 fun unRegisterExecutors(name: String)
38 fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any
40 @Deprecated("Populate Graph Dynamically from Blueprints, No need to get from Database Store ")
41 override fun getStore(): SvcLogicStore {
42 TODO("not implemented")
45 @Deprecated("Not used in Micro service Implementation")
46 override fun hasGraph(module: String, rpc: String, version: String?, mode: String): Boolean {
47 TODO("not implemented")
50 @Deprecated("Not used in Micro service Implementation")
51 override fun execute(p0: String?, p1: String?, p2: String?, p3: String?, p4: Properties?): Properties {
52 TODO("not implemented")
58 class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService {
60 private val log = LoggerFactory.getLogger(DefaultBlueprintSvcLogicService::class.java)
62 private val nodeExecutors: MutableMap<String, AbstractSvcLogicNodeExecutor> = hashMapOf()
65 private lateinit var context: ApplicationContext
68 override fun registerDefaultExecutors() {
70 val executeNodeExecutor = context.getBean(ExecuteNodeExecutor::class.java)
71 registerExecutors("execute", executeNodeExecutor)
72 registerExecutors("block", BlockNodeExecutor())
73 registerExecutors("return", ReturnNodeExecutor())
74 registerExecutors("break", BreakNodeExecutor())
75 registerExecutors("exit", ExitNodeExecutor())
78 override fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor) {
79 log.info("Registering executors($name) with type(${svcLogicNodeExecutor.javaClass}")
80 nodeExecutors[name] = svcLogicNodeExecutor
83 override fun unRegisterExecutors(name: String) {
84 if (nodeExecutors.containsKey(name)) {
85 log.info("UnRegistering executors($name)")
86 nodeExecutors.remove(name)
90 override fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any {
91 //Initialise BlueprintSvcLogic Context with Blueprint Runtime Service and Input Request
92 val blueprintSvcLogicContext = BlueprintSvcLogicContext()
93 blueprintSvcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
94 blueprintSvcLogicContext.setRequest(input)
96 execute(graph, blueprintSvcLogicContext)
98 return blueprintSvcLogicContext.getResponse()
101 override fun executeNode(node: SvcLogicNode?, ctx: SvcLogicContext): SvcLogicNode? {
105 if (log.isDebugEnabled) {
106 log.debug("Executing node {}", node.nodeId)
109 val executor = this.nodeExecutors[node.nodeType]
111 if (executor != null) {
112 log.debug("Executing node executor for node type {} - {}", node.nodeType, executor.javaClass.name)
113 return executor.execute(this, node, ctx)
115 throw SvcLogicException("Attempted to execute a node of type " + node.nodeType + ", but no executor was registered for this type")
120 override fun execute(graph: SvcLogicGraph, svcLogicContext: SvcLogicContext): SvcLogicContext {
121 MDC.put("currentGraph", graph.toString())
123 var curNode: SvcLogicNode? = graph.rootNode
124 log.info("About to execute graph {}", graph.toString())
127 while (curNode != null) {
128 MDC.put("nodeId", curNode.nodeId.toString() + " (" + curNode.nodeType + ")")
129 log.info("About to execute node # {} ({})", curNode.nodeId, curNode.nodeType)
130 val nextNode = this.executeNode(curNode, svcLogicContext)
133 } catch (var5: ExitNodeException) {
134 log.debug("SvcLogicServiceImpl caught ExitNodeException")
138 MDC.remove("currentGraph")
139 return svcLogicContext