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.*
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker
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 : SvcLogicService {
33 fun registerDefaultExecutors()
35 fun registerExecutors(name: String, svcLogicNodeExecutor: SvcLogicNodeExecutor)
37 fun unRegisterExecutors(name: String)
39 fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>): 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")
56 @Deprecated("Not used in Micro service Implementation")
57 override fun execute(p0: String?, p1: String?, p2: String?, p3: String?, p4: Properties?, p5: DOMDataBroker?): Properties {
58 TODO("not implemented")
64 class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService {
66 private val log = LoggerFactory.getLogger(DefaultBlueprintSvcLogicService::class.java)
68 private val nodeExecutors: MutableMap<String, SvcLogicNodeExecutor> = hashMapOf()
71 private lateinit var context: ApplicationContext
74 override fun registerDefaultExecutors() {
76 val executeNodeExecutor = context.getBean(ExecuteNodeExecutor::class.java)
77 registerExecutors("execute", executeNodeExecutor)
78 registerExecutors("block", BlockNodeExecutor())
79 registerExecutors("return", ReturnNodeExecutor())
80 registerExecutors("break", BreakNodeExecutor())
81 registerExecutors("exit", ExitNodeExecutor())
84 override fun registerExecutors(name: String, svcLogicNodeExecutor: SvcLogicNodeExecutor) {
85 log.info("Registering executors($name) with type(${svcLogicNodeExecutor.javaClass}")
86 nodeExecutors.put(name, svcLogicNodeExecutor)
89 override fun unRegisterExecutors(name: String) {
90 if (nodeExecutors.containsKey(name)) {
91 log.info("UnRegistering executors($name)")
92 nodeExecutors.remove(name)
96 override fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>): Any {
97 //Initialise BlueprintSvcLogic Context
98 val blueprintSvcLogicContext = BlueprintSvcLogicContext()
99 blueprintSvcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
101 execute(graph, blueprintSvcLogicContext)
103 return blueprintSvcLogicContext.getResponse()
106 override fun executeNode(node: SvcLogicNode?, ctx: SvcLogicContext): SvcLogicNode? {
110 if (log.isDebugEnabled()) {
111 log.debug("Executing node {}", node.getNodeId())
114 val executor = this.nodeExecutors[node.getNodeType()]
116 if (executor != null) {
117 log.debug("Executing node executor for node type {} - {}", node.getNodeType(), executor.javaClass.name)
118 return executor.execute(this, node, ctx)
120 throw SvcLogicException("Attempted to execute a node of type " + node.getNodeType() + ", but no executor was registered for this type")
125 override fun execute(graph: SvcLogicGraph, svcLogicContext: SvcLogicContext): SvcLogicContext {
126 MDC.put("currentGraph", graph.toString())
128 var curNode: SvcLogicNode? = graph.getRootNode()
129 log.info("About to execute graph {}", graph.toString())
132 while (curNode != null) {
133 MDC.put("nodeId", curNode.nodeId.toString() + " (" + curNode.nodeType + ")")
134 log.info("About to execute node # {} ({})", curNode.nodeId, curNode.nodeType)
135 val nextNode = this.executeNode(curNode, svcLogicContext)
138 } catch (var5: ExitNodeException) {
139 log.debug("SvcLogicServiceImpl caught ExitNodeException")
143 MDC.remove("currentGraph")
144 return svcLogicContext