From 32f16144e17d2df0831f14d9e65a83756a6ef844 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Thu, 27 Jul 2017 16:32:20 -0400 Subject: Refactor dblib Changed openecomp references in dblib, filters and sli to onap. Note: these must be committed together to get a clean compile. Issue: CCSDK-11 Change-Id: Ibe0f64fb20f3ae9cdda2f7ea969ca722bbde0d15 Signed-off-by: Dan Timoney --- .../sli/core/sli/provider/BlockNodeExecutor.java | 74 ++ .../sli/core/sli/provider/BreakNodeExecutor.java | 41 + .../sli/core/sli/provider/CallNodeExecutor.java | 164 +++ .../core/sli/provider/ConfigureNodeExecutor.java | 247 ++++ .../sli/core/sli/provider/DeleteNodeExecutor.java | 100 ++ .../sli/core/sli/provider/ExecuteNodeExecutor.java | 160 +++ .../sli/core/sli/provider/ExistsNodeExecutor.java | 104 ++ .../sli/core/sli/provider/ForNodeExecutor.java | 108 ++ .../core/sli/provider/GetResourceNodeExecutor.java | 133 +++ .../core/sli/provider/IsAvailableNodeExecutor.java | 102 ++ .../ccsdk/sli/core/sli/provider/MdsalHelper.java | 1185 +++++++++++++++++++ .../sli/core/sli/provider/NotifyNodeExecutor.java | 101 ++ .../sli/core/sli/provider/RecordNodeExecutor.java | 118 ++ .../sli/core/sli/provider/ReleaseNodeExecutor.java | 99 ++ .../sli/core/sli/provider/ReserveNodeExecutor.java | 113 ++ .../sli/core/sli/provider/ReturnNodeExecutor.java | 77 ++ .../sli/core/sli/provider/SaveNodeExecutor.java | 141 +++ .../sli/core/sli/provider/SetNodeExecutor.java | 188 ++++ .../sli/core/sli/provider/SvcLogicActivator.java | 224 ++++ .../core/sli/provider/SvcLogicAdaptorFactory.java | 85 ++ .../sli/provider/SvcLogicExpressionResolver.java | 604 ++++++++++ .../core/sli/provider/SvcLogicNodeExecutor.java | 109 ++ .../sli/core/sli/provider/SvcLogicService.java | 75 ++ .../sli/core/sli/provider/SvcLogicServiceImpl.java | 272 +++++ .../sli/core/sli/provider/SwitchNodeExecutor.java | 62 + .../sli/core/sli/provider/UpdateNodeExecutor.java | 135 +++ .../sli/core/sli/provider/WhileNodeExecutor.java | 74 ++ .../sdnc/sli/provider/BlockNodeExecutor.java | 75 -- .../sdnc/sli/provider/BreakNodeExecutor.java | 42 - .../sdnc/sli/provider/CallNodeExecutor.java | 165 --- .../sdnc/sli/provider/ConfigureNodeExecutor.java | 248 ---- .../sdnc/sli/provider/DeleteNodeExecutor.java | 101 -- .../sdnc/sli/provider/ExecuteNodeExecutor.java | 161 --- .../sdnc/sli/provider/ExistsNodeExecutor.java | 105 -- .../sdnc/sli/provider/ForNodeExecutor.java | 109 -- .../sdnc/sli/provider/GetResourceNodeExecutor.java | 134 --- .../sdnc/sli/provider/IsAvailableNodeExecutor.java | 103 -- .../openecomp/sdnc/sli/provider/MdsalHelper.java | 1186 -------------------- .../sdnc/sli/provider/NotifyNodeExecutor.java | 102 -- .../sdnc/sli/provider/RecordNodeExecutor.java | 119 -- .../sdnc/sli/provider/ReleaseNodeExecutor.java | 100 -- .../sdnc/sli/provider/ReserveNodeExecutor.java | 114 -- .../sdnc/sli/provider/ReturnNodeExecutor.java | 78 -- .../sdnc/sli/provider/SaveNodeExecutor.java | 142 --- .../sdnc/sli/provider/SetNodeExecutor.java | 189 ---- .../sdnc/sli/provider/SvcLogicActivator.java | 225 ---- .../sdnc/sli/provider/SvcLogicAdaptorFactory.java | 86 -- .../sli/provider/SvcLogicExpressionResolver.java | 605 ---------- .../sdnc/sli/provider/SvcLogicNodeExecutor.java | 110 -- .../sdnc/sli/provider/SvcLogicService.java | 76 -- .../sdnc/sli/provider/SvcLogicServiceImpl.java | 273 ----- .../sdnc/sli/provider/SwitchNodeExecutor.java | 63 -- .../sdnc/sli/provider/UpdateNodeExecutor.java | 136 --- .../sdnc/sli/provider/WhileNodeExecutor.java | 75 -- .../ccsdk/sli/core/sli/provider/BadPlugin.java | 55 + .../core/sli/provider/ExecuteNodeExecutorTest.java | 58 + .../sli/core/sli/provider/LunchSelectorPlugin.java | 77 ++ .../sli/core/sli/provider/MdsalHelperTest.java | 42 + .../core/sli/provider/MdsalHelperTesterUtil.java | 36 + .../ccsdk/sli/core/sli/provider/PluginTest.java | 107 ++ .../provider/SvcLogicExpressionResolverTest.java | 122 ++ .../sli/provider/SvcLogicGraphExecutorTest.java | 211 ++++ .../sli/core/sli/provider/VoidDummyPlugin.java | 37 + .../org/openecomp/sdnc/sli/provider/BadPlugin.java | 56 - .../sdnc/sli/provider/ExecuteNodeExecutorTest.java | 57 - .../sdnc/sli/provider/LunchSelectorPlugin.java | 78 -- .../sdnc/sli/provider/MdsalHelperTest.java | 43 - .../sdnc/sli/provider/MdsalHelperTesterUtil.java | 37 - .../openecomp/sdnc/sli/provider/PluginTest.java | 106 -- .../provider/SvcLogicExpressionResolverTest.java | 123 -- .../sli/provider/SvcLogicGraphExecutorTest.java | 212 ---- .../sdnc/sli/provider/VoidDummyPlugin.java | 38 - .../src/test/resources/l3sdn_logic_v10.xml | 5 +- .../src/test/resources/simplelogger.properties | 5 +- .../src/test/resources/svclogic.properties | 5 +- 75 files changed, 5646 insertions(+), 5681 deletions(-) create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicAdaptorFactory.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolver.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java create mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BlockNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BreakNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ConfigureNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReturnNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicAdaptorFactory.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicService.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/WhileNodeExecutor.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTesterUtil.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicGraphExecutorTest.java create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/BadPlugin.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutorTest.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/LunchSelectorPlugin.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTest.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTesterUtil.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/PluginTest.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicGraphExecutorTest.java delete mode 100644 sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/VoidDummyPlugin.java (limited to 'sli/provider/src') diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java new file mode 100644 index 00000000..7132950f --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BlockNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(BlockNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + throws SvcLogicException { + + SvcLogicExpression atomicExpr = node.getAttribute("atomic"); + String atomicStr = SvcLogicExpressionResolver.evaluate(atomicExpr, node, ctx); + boolean isAtomic = "true".equalsIgnoreCase(atomicStr); + + // Initialize status to success so that at least one outcome will execute + ctx.setStatus("success"); + + int numOutcomes = node.getNumOutcomes(); + + for (int i = 0; i < numOutcomes; i++) { + if ("failure".equals(ctx.getStatus()) && isAtomic) { + LOG.info("Block - stopped executing nodes due to failure status"); + return(null); + } + + SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1)); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Block - executing outcome " + (i + 1)); + } + while (nextNode != null) + { + nextNode = svc.executeNode(nextNode, ctx); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Block - done: no outcome " + (i + 1)); + } + } + } + + return (null); + } + + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java new file mode 100644 index 00000000..ec0a5daa --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.BreakNodeException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BreakNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(BreakNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + String message = "BreakNodeExecutor encountered break with nodeId " + node.getNodeId(); + LOG.debug(message); + throw new BreakNodeException(message); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java new file mode 100644 index 00000000..9498d676 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java @@ -0,0 +1,164 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicStore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CallNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(CallNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) + throws SvcLogicException { + + String outValue = "not-found"; + + SvcLogicGraph myGraph = node.getGraph(); + + if (myGraph == null) + { + LOG.debug("execute: getGraph returned null"); + } + else + { + LOG.debug("execute: got SvcLogicGraph"); + } + + SvcLogicExpression moduleExpr = null; + + String module = null; + + moduleExpr = node.getAttribute("module"); + if (moduleExpr != null) + { + module = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx); + } + + if ((module == null) || (module.length() == 0)) + { + if (myGraph != null) + { + module = myGraph.getModule(); + LOG.debug("myGraph.getModule() returned "+module); + } + } + + SvcLogicExpression rpcExpr = null; + String rpc = null; + rpcExpr = node.getAttribute("rpc"); + if (rpcExpr != null) + { + rpc = SvcLogicExpressionResolver.evaluate(rpcExpr, node, ctx); + } + + if ((rpc == null) || (rpc.length() == 0)) + { + if (myGraph != null) + { + rpc = myGraph.getRpc(); + LOG.debug("myGraph.getRpc() returned "+rpc); + } + } + + String mode = null; + + moduleExpr = node.getAttribute("mode"); + if (moduleExpr != null) + { + mode = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx); + } + + if ((mode == null) || (mode.length() == 0)) + { + if (myGraph != null) + { + mode = myGraph.getMode(); + + LOG.debug("myGraph.getMode() returned "+mode); + } + } + + String version = null; + + moduleExpr = node.getAttribute("version"); + if (moduleExpr != null) + { + version = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx); + } + + String parentGraph = ctx.getAttribute("currentGraph"); + ctx.setAttribute("parentGraph", parentGraph); + + SvcLogicStore store = getStore(); + + if (store != null) { + SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode); + LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString()); + ctx.setAttribute("currentGraph", calledGraph.toString()); + if (calledGraph != null) { + svc.execute(calledGraph, ctx); + + outValue = ctx.getStatus(); + } else { + LOG.error("Could not find service logic for [" + module + "," + rpc + "," + version + "," + mode + "]"); + } + } + else + { + LOG.debug("Could not get SvcLogicStore reference"); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + ctx.setAttribute("currentGraph", parentGraph); + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no " + outValue + " or Other branch found"); + } + } + ctx.setAttribute("currentGraph", parentGraph); + ctx.setAttribute("parentGraph", null); + + return (nextNode); + + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java new file mode 100644 index 00000000..21b63d4f --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java @@ -0,0 +1,247 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConfigureNodeExecutor extends SvcLogicNodeExecutor { + private static final Logger LOG = LoggerFactory + .getLogger(ConfigureNodeExecutor.class); + + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String adaptorName = SvcLogicExpressionResolver.evaluate( + node.getAttribute("adaptor"), node, ctx); + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("configure node encountered - looking for adaptor " + + adaptorName); + } + + SvcLogicAdaptor adaptor = getAdaptor(adaptorName); + + if (adaptor != null) { + String activate = SvcLogicExpressionResolver.evaluate( + node.getAttribute("activate"), node, ctx); + String key = SvcLogicExpressionResolver.evaluate( + node.getAttribute("key"), node, ctx); + + Map parmMap = new HashMap(); + + Set> parmSet = node + .getParameterSet(); + boolean hasParms = false; + + for (Iterator> iter = parmSet + .iterator(); iter.hasNext();) { + hasParms = true; + Map.Entry curEnt = iter.next(); + String curName = curEnt.getKey(); + SvcLogicExpression curExpr = curEnt.getValue(); + String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx); + + LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue); + + parmMap.put(curName,curExprValue); + } + + if (hasParms) { + SvcLogicAdaptor.ConfigStatus confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + + try { + confStatus = adaptor.configure(key, parmMap, ctx); + } catch (Exception e) { + LOG.warn("Caught exception from "+adaptorName+".configure", e); + confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + } + + switch (confStatus) { + case SUCCESS: + outValue = "success"; + if ((activate != null) && (activate.length() > 0)) { + if ("true".equalsIgnoreCase(activate)) { + SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + + try { + activateStatus = adaptor.activate(key, ctx); + } catch (Exception e) { + + LOG.warn("Caught exception from "+adaptorName+".activate", e); + activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + } + switch (activateStatus) { + case SUCCESS: + break; + case ALREADY_ACTIVE: + outValue = "already-active"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case NOT_READY: + outValue = "not-ready"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } else if ("false".equalsIgnoreCase(activate)) { + SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + + try { + deactivateStatus = adaptor.deactivate(key, ctx); + } catch (Exception e) { + + LOG.warn("Caught exception from "+adaptorName+".deactivate", e); + deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + } + switch (deactivateStatus) { + case SUCCESS: + break; + case ALREADY_ACTIVE: + outValue = "already-active"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case NOT_READY: + outValue = "not-ready"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } + } + break; + case ALREADY_ACTIVE: + outValue = "already-active"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case NOT_READY: + outValue = "not-ready"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } else { + if ((activate != null) && (activate.length() > 0)) { + if ("true".equalsIgnoreCase(activate)) { + SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + try { + activateStatus = adaptor.activate(key, ctx); + } catch (Exception e) { + LOG.warn("Caught exception from "+adaptorName+".activate", e); + activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + } + switch (activateStatus) { + case SUCCESS: + outValue = "success"; + break; + case ALREADY_ACTIVE: + outValue = "already-active"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case NOT_READY: + outValue = "not-ready"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } else if ("false".equalsIgnoreCase(activate)) { + SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + + try { + deactivateStatus = adaptor.deactivate(key, ctx); + } catch (Exception e) { + LOG.warn("Caught exception from "+adaptorName+".deactivate", e); + deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; + } + switch (deactivateStatus) { + case SUCCESS: + outValue = "success"; + break; + case ALREADY_ACTIVE: + outValue = "already-active"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case NOT_READY: + outValue = "not-ready"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } + } else { + LOG.warn("Nothing to configure - no parameters passed, and activate attribute is not set"); + outValue = "success"; + } + } + } else { + if (LOG.isWarnEnabled()) { + LOG.warn("Adaptor for " + adaptorName + " not found"); + } + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no " + outValue + " or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java new file mode 100644 index 00000000..caba0943 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DeleteNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(DeleteNodeExecutor.class); + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("delete node encountered - looking for resource class " + + plugin); + } + + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + if (resourcePlugin != null) { + + try { + + switch (resourcePlugin.delete(resourceType, key, ctx)) { + case SUCCESS: + outValue = "success"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java new file mode 100644 index 00000000..19868ed7 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ExecuteNodeExecutor extends SvcLogicNodeExecutor { + private static final Logger LOG = LoggerFactory + .getLogger(ExecuteNodeExecutor.class); + + private static final String pluginErrorMessage = "Could not execute plugin. SvcLogic status will be set to failure."; + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String pluginName = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("execute node encountered - looking for plugin " + + pluginName); + } + + SvcLogicJavaPlugin plugin = getSvcLogicJavaPlugin(pluginName); + + if (plugin == null) { + outValue = "not-found"; + } else { + + String methodName = evaluate(node.getAttribute("method"), node, ctx); + + Class pluginClass = plugin.getClass(); + + Method pluginMethod = null; + + try { + pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class); + } catch (NoSuchMethodException e) { + LOG.error(pluginErrorMessage, e); + } + + if (pluginMethod == null) { + outValue = "unsupported-method"; + } else { + try { + + Map parmMap = new HashMap(); + + Set> parmSet = node + .getParameterSet(); + + for (Iterator> iter = parmSet + .iterator(); iter.hasNext();) { + Map.Entry curEnt = iter.next(); + String curName = curEnt.getKey(); + SvcLogicExpression curExpr = curEnt.getValue(); + String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx); + + LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue); + + parmMap.put(curName,curExprValue); + } + + Object o = pluginMethod.invoke(plugin, parmMap, ctx); + String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); + + outValue = mapOutcome(o, emitsOutcome); + + } catch (InvocationTargetException e) { + if(e.getCause() != null){ + LOG.error(pluginErrorMessage, e.getCause()); + }else{ + LOG.error(pluginErrorMessage, e); + } + outValue = "failure"; + ctx.setStatus("failure"); + } catch (IllegalAccessException e) { + LOG.error(pluginErrorMessage, e); + outValue = "failure"; + ctx.setStatus("failure"); + } catch (IllegalArgumentException e) { + LOG.error(pluginErrorMessage, e); + outValue = "failure"; + ctx.setStatus("failure"); + } + } + + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no " + outValue + " or Other branch found"); + } + } + return (nextNode); + } + + protected String evaluate(SvcLogicExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + return SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx); + } + + public String mapOutcome(Object o, String emitsOutcome) { + if (emitsOutcome != null) { + Boolean nodeEmitsOutcome = Boolean.valueOf(emitsOutcome); + if (nodeEmitsOutcome) { + return (String) o; + } else { + return "success"; + } + + } else { + return "success"; + } + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java new file mode 100644 index 00000000..1798d50a --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ExistsNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(ExistsNodeExecutor.class); + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + String pfx = SvcLogicExpressionResolver.evaluate( + node.getAttribute("pfx"), node, ctx); + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("exists node encountered - looking for resource class " + + plugin); + } + + + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + + if (resourcePlugin != null) { + + try { + + switch (resourcePlugin.exists(resourceType, key, pfx, ctx)) { + case SUCCESS: + outValue = "true"; + break; + case NOT_FOUND: + outValue = "false"; + break; + case FAILURE: + default: + outValue = "false"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java new file mode 100644 index 00000000..a9ee0076 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.BreakNodeException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ForNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(ForNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + SvcLogicExpression atomicExpr = node.getAttribute("atomic"); + String atomicStr = SvcLogicExpressionResolver.evaluate(atomicExpr, node, ctx); + boolean isAtomic = !("false".equalsIgnoreCase(atomicStr)); + + int numOutcomes = node.getNumOutcomes(); + String idxVar = SvcLogicExpressionResolver.evaluate( + node.getAttribute("index"), node, ctx); + String startVal = SvcLogicExpressionResolver.evaluate( + node.getAttribute("start"), node, ctx); + String endVal = SvcLogicExpressionResolver.evaluate( + node.getAttribute("end"), node, ctx); + + LOG.debug("Executing "+ (isAtomic ? "atomic" : "non-atomic") + " for loop - for (int " + idxVar + " = " + startVal + + "; " + idxVar + " < " + endVal + "; " + idxVar + "++)"); + + int startIdx = 0; + int endIdx = 0; + + try { + startIdx = Integer.parseInt(startVal); + endIdx = Integer.parseInt(endVal); + } catch (NumberFormatException e) { + SvcLogicExpression silentFailureExpr = node.getAttribute("silentFailure"); + String silentFailure = SvcLogicExpressionResolver.evaluate(silentFailureExpr, node, ctx); + boolean isSilentFailure = Boolean.parseBoolean(silentFailure); + String message = "Invalid index values [" + startVal + "," + endVal + "]"; + if(!isSilentFailure){ + throw new SvcLogicException(message); + }else{ + LOG.debug(message + ". Not exiting because silentFailure was set to true."); + return(null); + } + } + + try { + for (int ctr = startIdx; ctr < endIdx; ctr++) { + + ctx.setAttribute(idxVar, "" + ctr); + + for (int i = 0; i < numOutcomes; i++) { + + if ("failure".equals(ctx.getStatus()) && isAtomic) { + LOG.info("For - stopped executing nodes due to failure status"); + return(null); + } + + SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1)); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("For - executing outcome " + (i + 1)); + } + SvcLogicNode innerNextNode = nextNode; + while (innerNextNode != null) { + innerNextNode = svc.executeNode(innerNextNode, ctx); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("For - done: no outcome " + (i + 1)); + } + } + } + } + } catch (BreakNodeException br) { + LOG.debug("ForNodeExecutor caught break"); + } + return (null); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java new file mode 100644 index 00000000..7ecc76c5 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GetResourceNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(GetResourceNodeExecutor.class); + + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + String pfx = SvcLogicExpressionResolver.evaluate( + node.getAttribute("pfx"), node, ctx); + + String localOnlyStr = SvcLogicExpressionResolver.evaluate( + node.getAttribute("local-only"), node, ctx); + + // Note: for get-resource, only refresh from A&AI if the DG explicitly set + // local-only to false. Otherwise, just read from local database. + boolean localOnly = true; + + if ("false".equalsIgnoreCase(localOnlyStr)) { + localOnly = false; + } + + SvcLogicExpression selectExpr = node.getAttribute("select"); + String select = null; + + if (selectExpr != null) { + select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node, + ctx); + } + + SvcLogicExpression orderByExpr = node.getAttribute("order-by"); + String orderBy = null; + + if (orderByExpr != null) { + orderBy = SvcLogicExpressionResolver.evaluateAsKey(orderByExpr, node, + ctx); + } + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug(node.getNodeType() + + " node encountered - looking for resource class " + + plugin); + } + + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + + if (resourcePlugin != null) { + + try { + switch (resourcePlugin.query(resourceType, localOnly, select, key, + pfx, orderBy, ctx)) { + case SUCCESS: + outValue = "success"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java new file mode 100644 index 00000000..7bc15d8a --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class IsAvailableNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(IsAvailableNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + String pfx = SvcLogicExpressionResolver.evaluate( + node.getAttribute("pfx"), node, ctx); + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("is-available node encountered - looking for resource class " + + plugin); + } + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + + + if (resourcePlugin != null) { + try { + switch (resourcePlugin.isAvailable(resourceType, key, pfx, ctx)) { + case SUCCESS: + outValue = "true"; + break; + case NOT_FOUND: + outValue = "false"; + break; + case FAILURE: + default: + outValue = "false"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java new file mode 100644 index 00000000..a35c0524 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java @@ -0,0 +1,1185 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; +import org.opendaylight.yangtools.yang.binding.Identifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MdsalHelper { + + private static final Logger LOG = LoggerFactory.getLogger(MdsalHelper.class); + private static Properties yangMappingProperties = new Properties(); + + @Deprecated + public static void setProperties(Properties input) { + setYangMappingProperties(input); + } + + public static void setYangMappingProperties(Properties properties) { + for (Object propNameObj : properties.keySet()) { + String propName = (String) propNameObj; + MdsalHelper.yangMappingProperties.setProperty(propName, properties.getProperty(propName)); + } + } + + public static void loadProperties(String propertiesFile) { + File file = new File(propertiesFile); + Properties properties = new Properties(); + InputStream input = null; + if (file.isFile() && file.canRead()) { + try { + input = new FileInputStream(file); + properties.load(input); + MdsalHelper.setYangMappingProperties(properties); + LOG.info("Loaded properties from " + propertiesFile); + } catch (Exception e) { + LOG.error("Failed to load properties " + propertiesFile + "\n", e); + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException e) { + LOG.error("Failed to close properties file " + propertiesFile + "\n", e); + } + } + } + }else{ + LOG.error("Failed to load the properties file " + propertiesFile + "\n"); + LOG.error("Either isFile or canRead returned false for " + propertiesFile + "\n"); + } + } + + public static Properties toProperties(Properties props, Object fromObj) { + Class fromClass = null; + + if (fromObj != null) { + fromClass = fromObj.getClass(); + } + return (toProperties(props, "", fromObj, fromClass)); + } + + public static Properties toProperties(Properties props, String pfx, Object fromObj) { + Class fromClass = null; + + if (fromObj != null) { + fromClass = fromObj.getClass(); + } + + return (toProperties(props, pfx, fromObj, fromClass)); + } + + public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass) { + + if (fromObj == null) { + return (props); + } + + String simpleName = fromClass.getSimpleName(); + + LOG.trace("Extracting properties from " + fromClass.getName() + " class"); + if (fromObj instanceof List) { + + // Class is a List. List should contain yang-generated classes. + LOG.trace(fromClass.getName() + " is a List"); + + List fromList = (List) fromObj; + + for (int i = 0; i < fromList.size(); i++) { + toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass); + } + props.setProperty(pfx + "_length", "" + fromList.size()); + + } else if (isYangGenerated(fromClass)) { + // Class is yang generated. + LOG.trace(fromClass.getName() + " is a Yang-generated class"); + + String propNamePfx = null; + + // If called from a list (so prefix ends in ']'), don't + // add class name again + if (pfx.endsWith("]")) { + propNamePfx = pfx; + } else { + if ((pfx != null) && (pfx.length() > 0)) { + propNamePfx = pfx; + } else { + propNamePfx = toLowerHyphen(fromClass.getSimpleName()); + } + + if (propNamePfx.endsWith("-builder")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length()); + } + + if (propNamePfx.endsWith("-impl")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-impl".length()); + } + } + + // Iterate through getter methods to figure out values we need to + // save from + + int numGetters = 0; + String lastGetterName = null; + String propVal = null; + + for (Method m : fromClass.getMethods()) { + if (isGetter(m)) { + + numGetters++; + lastGetterName = m.getName(); + + Class returnType = m.getReturnType(); + String fieldName; + if (m.getName().startsWith("get")) { + fieldName = toLowerHyphen(m.getName().substring(3)); + } else { + + fieldName = toLowerHyphen(m.getName().substring(2)); + } + + fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1); + + // Is the return type a yang generated class? + if (isYangGenerated(returnType)) { + // Is it an enum? + if (returnType.isEnum()) { + // Return type is a typedef. Save its value. + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + + Object retValue = m.invoke(fromObj); + + if (!isAccessible) { + m.setAccessible(isAccessible); + } + if (retValue != null) { + String propName = propNamePfx + "." + fieldName; + propVal = retValue.toString(); + props.setProperty(propName, mapEnumeratedValue(fieldName, propVal)); + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert Yang-generated enum returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } else if (isIpv4Address(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Ipv4Address retValue = (Ipv4Address) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + propVal = retValue.getValue().toString(); + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } else if (isIpv6Address(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Ipv6Address retValue = (Ipv6Address) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + propVal = retValue.getValue().toString(); + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } else if (isIpAddress(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + IpAddress retValue = (IpAddress) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + propVal = new String(retValue.getValue()); + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } else if (isIpPrefix(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + IpPrefix retValue = (IpPrefix) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + propVal = new String(retValue.getValue()); + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } else { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Object retValue = m.invoke(fromObj); + + if (retValue instanceof byte[]) { + LOG.trace(m.getName() + " returns a byte[]"); + retValue = new String((byte[]) retValue, "UTF-8"); + LOG.trace("Converted byte array " + propNamePfx + "." + fieldName + "to string " + retValue); + } + if (!isAccessible) { + m.setAccessible(isAccessible); + } + if (retValue != null) { + toProperties(props, propNamePfx + "." + fieldName, retValue, returnType); + } + } catch (Exception e) { + + if (m.getName().equals("getKey")) { + LOG.trace("Caught " + e.getClass().getName() + " exception trying to convert results from getKey() - ignoring"); + } else { + LOG.error("Caught exception trying to convert Yang-generated class returned by" + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } + } + } else if (returnType.equals(Class.class)) { + + LOG.trace(m.getName() + " returns a Class object - not interested"); + + } else if (List.class.isAssignableFrom(returnType)) { + + // This getter method returns a list. + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Object retList = m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + // Figure out what type of elements are stored in + // this array. + Type paramType = m.getGenericReturnType(); + Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0]; + toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType); + } catch (Exception e) { + LOG.error("Caught exception trying to convert List returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + + } else { + + // Method returns something that is not a List and not + // yang-generated. + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Object propValObj = m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (propValObj != null) { + if (propValObj instanceof byte[]) { + LOG.trace(m.getName() + " returns a byte[]"); + propVal = new String((byte[]) propValObj, "UTF-8"); + LOG.trace("Converted byte array " + propNamePfx + "." + fieldName + "to string " + propVal); + + } else { + propVal = propValObj.toString(); + } + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + if (m.getName().equals("getKey")) { + LOG.trace("Caught " + e.getClass().getName() + " exception trying to convert results from getKey() - ignoring"); + } else { + LOG.error("Caught exception trying to convert value returned by" + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } + } + + } + } + + // End of method loop. If there was only one getter, named + // "getValue", then + // set value identified by "prefix" to that one value. + if ((numGetters == 1) && ("getValue".equals(lastGetterName))) { + LOG.trace("getValueFIX : " + propNamePfx + " only has getValue() getter - setting " + propNamePfx + " = " + propVal); + props.setProperty(propNamePfx, propVal); + } else { + LOG.trace("getValueFIX : " + propNamePfx + " has " + numGetters + " getter(s), last one found was " + lastGetterName); + + } + + } else { + // Class is not yang generated and not a list + // It must be an element of a leaf list - set "prefix" to value + String fromVal = null; + if (fromObj instanceof byte[]) { + try { + fromVal = new String((byte[]) fromObj, "UTF-8"); + LOG.trace("Converted byte array " + pfx + "to string " + fromVal); + } catch (Exception e) { + LOG.warn("Caught exception trying to convert " + pfx + " from byte[] to String", e); + fromVal = fromObj.toString(); + } + + } else { + fromVal = fromObj.toString(); + } + LOG.debug("Setting property " + pfx + " to " + fromVal); + props.setProperty(pfx, fromVal); + } + + return (props); + } + + public static Object toBuilder(Properties props, Object toObj) { + + return (toBuilder(props, "", toObj)); + } + + public static List toList(Properties props, String pfx, List toObj, Class elemType) { + + int maxIdx = -1; + boolean foundValue = false; + + LOG.trace("Saving properties to List<" + elemType.getName() + "> from " + pfx); + + if (props.contains(pfx + "_length")) { + try { + int listLength = Integer.parseInt(props.getProperty(pfx + "_length")); + + if (listLength > 0) { + maxIdx = listLength - 1; + } + } catch (Exception e) { + // Ignore exception + } + } + + if (maxIdx == -1) { + // Figure out array size + for (Object pNameObj : props.keySet()) { + String key = (String) pNameObj; + + if (key.startsWith(pfx + "[")) { + String idxStr = key.substring(pfx.length() + 1); + int endloc = idxStr.indexOf("]"); + if (endloc != -1) { + idxStr = idxStr.substring(0, endloc); + } + + try { + int curIdx = Integer.parseInt(idxStr); + if (curIdx > maxIdx) { + maxIdx = curIdx; + } + } catch (Exception e) { + LOG.error("Illegal subscript in property " + key); + } + + } + } + } + + LOG.trace(pfx + " has max index of " + maxIdx); + for (int i = 0; i <= maxIdx; i++) { + + String curBase = pfx + "[" + i + "]"; + + if (isYangGenerated(elemType)) { + String builderName = elemType.getName() + "Builder"; + try { + Class builderClass = Class.forName(builderName); + Object builderObj = builderClass.newInstance(); + Method buildMethod = builderClass.getMethod("build"); + builderObj = toBuilder(props, curBase, builderObj, true); + if (builderObj != null) { + LOG.trace("Calling " + builderObj.getClass().getName() + "." + buildMethod.getName() + "()"); + Object builtObj = buildMethod.invoke(builderObj); + toObj.add(builtObj); + foundValue = true; + } + + } catch (ClassNotFoundException e) { + LOG.warn("Could not find builder class " + builderName, e); + } catch (Exception e) { + LOG.error("Caught exception trying to populate list from " + pfx); + } + } else { + // Must be a leaf list + String curValue = props.getProperty(curBase, ""); + + toObj.add(curValue); + + if ((curValue != null) && (curValue.length() > 0)) { + foundValue = true; + } + } + + } + + if (foundValue) { + return (toObj); + } else { + return (null); + } + + } + + public static Object toBuilder(Properties props, String pfx, Object toObj) { + return (toBuilder(props, pfx, toObj, false)); + } + + public static Object toBuilder(Properties props, String pfx, Object toObj, boolean preservePfx) { + Class toClass = toObj.getClass(); + boolean foundValue = false; + + LOG.trace("Saving properties to " + toClass.getName() + " class from " + pfx); + + Ipv4Address addr; + + if (isYangGenerated(toClass)) { + // Class is yang generated. + LOG.trace(toClass.getName() + " is a Yang-generated class"); + + String propNamePfx = null; + if (preservePfx) { + propNamePfx = pfx; + } else { + + if ((pfx != null) && (pfx.length() > 0)) { + propNamePfx = pfx + "." + toLowerHyphen(toClass.getSimpleName()); + } else { + propNamePfx = toLowerHyphen(toClass.getSimpleName()); + } + + if (propNamePfx.endsWith("-builder")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length()); + } + + if (propNamePfx.endsWith("-impl")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-impl".length()); + } + } + + if (toObj instanceof Identifier) { + LOG.trace(toClass.getName() + " is a Key - skipping"); + return (toObj); + } + + // Iterate through getter methods to figure out values we need to + // set + + for (Method m : toClass.getMethods()) { + if (isSetter(m)) { + Class paramTypes[] = m.getParameterTypes(); + Class paramClass = paramTypes[0]; + + String fieldName = toLowerHyphen(m.getName().substring(3)); + fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1); + + String propName = propNamePfx + "." + fieldName; + + String paramValue = props.getProperty(propName); + if (paramValue == null) { + LOG.trace(propName + " is unset"); + } else { + LOG.trace(propName + " = " + paramValue); + } + + // Is the return type a yang generated class? + if (isYangGenerated(paramClass)) { + // Is it an enum? + if (paramClass.isEnum()) { + + LOG.trace(m.getName() + " expects an Enum"); + // Param type is a typedef. + if ((paramValue != null) && (paramValue.length() > 0)) { + Object paramObj = null; + + try { + paramObj = Enum.valueOf(paramClass, toJavaEnum(paramValue)); + } catch (Exception e) { + LOG.error("Caught exception trying to convert field " + propName + " to enum " + paramClass.getName(), e); + } + + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); + m.invoke(toObj, paramObj); + + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error("Caught exception trying to create Yang-generated enum expected by" + toClass.getName() + "." + m.getName() + "() from Properties entry", e); + } + } + } else { + + String simpleName = paramClass.getSimpleName(); + + if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress".equals(simpleName)) { + + if ((paramValue != null) && (paramValue.length() > 0)) { + try { + IpAddress ipAddr = IpAddressBuilder.getDefaultInstance(paramValue); + + if ("Ipv4Address".equals(simpleName)) { + m.invoke(toObj, ipAddr.getIpv4Address()); + } else if ("Ipv6Address".equals(simpleName)) { + m.invoke(toObj, ipAddr.getIpv6Address()); + + } else { + m.invoke(toObj, ipAddr); + } + foundValue = true; + } catch (Exception e) { + LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + "(" + paramValue + ")", e); + + } + } else { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); + m.invoke(toObj, paramValue); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error("Caught exception trying to call " + toClass.getName() + "." + m.getName() + "() with Properties entry", e); + } + } + } else if ("IpPrefix".equals(simpleName)) { + if ((paramValue != null) && (paramValue.length() > 0)) { + try { + IpPrefix ipPrefix = IpPrefixBuilder.getDefaultInstance(paramValue); + m.invoke(toObj, ipPrefix); + foundValue = true; + } catch (Exception e) { + LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + "(" + paramValue + ")", e); + } + } + } else { + // setter expects a yang-generated class. Need + // to + // create a builder to set it. + + String builderName = paramClass.getName() + "Builder"; + Class builderClass = null; + Object builderObj = null; + Object paramObj = null; + + Object constObj = null; + + LOG.trace(m.getName() + " expects a yang-generated class - looking for builder " + builderName); + try { + builderClass = Class.forName(builderName); + builderObj = builderClass.newInstance(); + paramObj = toBuilder(props, propNamePfx, builderObj); + } catch (ClassNotFoundException e) { + + if (paramValue == null) { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(null)"); + m.invoke(toObj, new Object[] { null }); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e1) { + LOG.error("Caught exception trying to cally" + toClass.getName() + "." + m.getName() + "() with Properties entry", e1); + } + } else { + try { + // See if I can find a constructor I + // can + // use + Constructor[] constructors = paramClass.getConstructors(); + // Is there a String constructor? + for (Constructor c : constructors) { + Class[] cParms = c.getParameterTypes(); + if ((cParms != null) && (cParms.length == 1)) { + if (String.class.isAssignableFrom(cParms[0])) { + constObj = c.newInstance(paramValue); + } + } + } + + if (constObj == null) { + // Is there a Long constructor? + for (Constructor c : constructors) { + Class[] cParms = c.getParameterTypes(); + if ((cParms != null) && (cParms.length == 1)) { + if (Long.class.isAssignableFrom(cParms[0])) { + constObj = c.newInstance(Long.parseLong(paramValue)); + } + } + } + + } + + if (constObj == null) { + + // Last chance - see if + // parameter class has a static + // method + // getDefaultInstance(String) + try { + Method gm = paramClass.getMethod("getDefaultInstance", String.class); + + int gmodifier = gm.getModifiers(); + if (Modifier.isStatic(gmodifier)) { + // Invoke static + // getDefaultInstance(String) + paramObj = gm.invoke(null, paramValue); + } + + } catch (Exception gme) { + // Ignore exceptions + } + } + + } catch (Exception e1) { + LOG.warn("Could not find a suitable constructor for " + paramClass.getName(), e1); + } + + if (constObj == null) { + LOG.warn("Could not find builder class " + builderName + " and could not find a String or Long constructor or static getDefaultInstance(String) - trying just to set passing paramValue"); + + } + } + } catch (Exception e) { + LOG.error("Caught exception trying to create builder " + builderName, e); + } + + if (paramObj != null) { + + try { + + Method buildMethod = builderClass.getMethod("build"); + LOG.trace("Calling " + paramObj.getClass().getName() + "." + buildMethod.getName() + "()"); + Object builtObj = buildMethod.invoke(paramObj); + + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "()"); + m.invoke(toObj, builtObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error("Caught exception trying to set Yang-generated class expected by" + toClass.getName() + "." + m.getName() + "() from Properties entry", e); + } + } else { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + + if (constObj != null) { + + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + constObj.toString() + ")"); + m.invoke(toObj, constObj); + } else { + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); + m.invoke(toObj, paramValue); + + } + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by" + toClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } + } + } + } else { + + // Setter's argument is not a yang-generated class. See + // if it is a List. + + if (List.class.isAssignableFrom(paramClass)) { + + LOG.trace("Parameter class " + paramClass.getName() + " is a List"); + + // Figure out what type of args are in List and pass + // that to toList(). + + Type paramType = m.getGenericParameterTypes()[0]; + Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0]; + Object paramObj = new LinkedList(); + try { + paramObj = toList(props, propName, (List) paramObj, (Class) elementType); + } catch (Exception e) { + LOG.error("Caught exception trying to create list expected as argument to " + toClass.getName() + "." + m.getName()); + } + + if (paramObj != null) { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); + m.invoke(toObj, paramObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error("Caught exception trying to convert List returned by" + toClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } + } else { + + // Setter expects something that is not a List and + // not yang-generated. Just pass the parameter value + + LOG.trace("Parameter class " + paramClass.getName() + " is not a yang-generated class or a List"); + + if ((paramValue != null) && (paramValue.length() > 0)) { + + Object constObj = null; + + try { + // See if I can find a constructor I can use + Constructor[] constructors = paramClass.getConstructors(); + // Is there a String constructor? + for (Constructor c : constructors) { + Class[] cParms = c.getParameterTypes(); + if ((cParms != null) && (cParms.length == 1)) { + if (String.class.isAssignableFrom(cParms[0])) { + constObj = c.newInstance(paramValue); + } + } + } + + if (constObj == null) { + // Is there a Long constructor? + for (Constructor c : constructors) { + Class[] cParms = c.getParameterTypes(); + if ((cParms != null) && (cParms.length == 1)) { + if (Long.class.isAssignableFrom(cParms[0])) { + constObj = c.newInstance(Long.parseLong(paramValue)); + } + } + } + + } + + if (constObj != null) { + try { + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + constObj + ")"); + m.invoke(toObj, constObj); + foundValue = true; + } catch (Exception e2) { + LOG.error("Caught exception trying to call " + m.getName(), e2); + } + } else { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); + m.invoke(toObj, paramValue); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by" + toClass.getName() + "." + m.getName() + "() to Properties entry", e); + } + } + } catch (Exception e1) { + LOG.warn("Could not find a suitable constructor for " + paramClass.getName(), e1); + } + + } + } + } + } // End of section handling "setter" method + } // End of loop through Methods + } // End of section handling yang-generated class + + if (foundValue) { + return (toObj); + } else { + return (null); + } + } + + public static void printPropertyList(PrintStream pstr, String pfx, Class toClass) { + boolean foundValue = false; + + LOG.trace("Analyzing " + toClass.getName() + " class : pfx " + pfx); + + if (isYangGenerated(toClass) && (!Identifier.class.isAssignableFrom(toClass))) { + // Class is yang generated. + LOG.trace(toClass.getName() + " is a Yang-generated class"); + + if (toClass.getName().endsWith("Key")) { + if (Identifier.class.isAssignableFrom(toClass)) { + LOG.trace(Identifier.class.getName() + " is assignable from " + toClass.getName()); + } else { + + LOG.trace(Identifier.class.getName() + " is NOT assignable from " + toClass.getName()); + } + } + + String propNamePfx = null; + if (pfx.endsWith("]")) { + propNamePfx = pfx; + } else { + + if ((pfx != null) && (pfx.length() > 0)) { + propNamePfx = pfx + "." + toLowerHyphen(toClass.getSimpleName()); + } else { + propNamePfx = toLowerHyphen(toClass.getSimpleName()); + } + + if (propNamePfx.endsWith("-builder")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length()); + } + + if (propNamePfx.endsWith("-impl")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-impl".length()); + } + } + + // Iterate through getter methods to figure out values we need to + // set + + for (Method m : toClass.getMethods()) { + LOG.trace("Is " + m.getName() + " method a getter?"); + if (isGetter(m)) { + LOG.trace(m.getName() + " is a getter"); + Class returnClass = m.getReturnType(); + + String fieldName = toLowerHyphen(m.getName().substring(3)); + fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1); + + String propName = propNamePfx + "." + fieldName; + + // Is the return type a yang generated class? + if (isYangGenerated(returnClass)) { + // Is it an enum? + if (returnClass.isEnum()) { + + LOG.trace(m.getName() + " is an Enum"); + pstr.print("\n\n * " + propName); + + } else { + + String simpleName = returnClass.getSimpleName(); + + if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress".equals(simpleName) || "IpPrefix".equals(simpleName)) { + LOG.trace(m.getName() + " is an " + simpleName); + pstr.print("\n\n * " + propName); + } else { + printPropertyList(pstr, propNamePfx, returnClass); + } + + } + } else { + + // Setter's argument is not a yang-generated class. See + // if it is a List. + + if (List.class.isAssignableFrom(returnClass)) { + + LOG.trace("Parameter class " + returnClass.getName() + " is a List"); + + // Figure out what type of args are in List and pass + // that to toList(). + + Type returnType = m.getGenericReturnType(); + Type elementType = ((ParameterizedType) returnType).getActualTypeArguments()[0]; + Class elementClass = (Class) elementType; + LOG.trace("Calling printPropertyList on list type (" + elementClass.getName() + "), pfx is (" + pfx + "), toClass is (" + toClass.getName() + ")"); + printPropertyList(pstr, propNamePfx + "." + toLowerHyphen(elementClass.getSimpleName()) + "[]", elementClass); + + } else if (!returnClass.equals(Class.class)) { + + // Setter expects something that is not a List and + // not yang-generated. Just pass the parameter value + + LOG.trace("Parameter class " + returnClass.getName() + " is not a yang-generated class or a List"); + + pstr.print("\n\n * " + propName); + + } + } + } // End of section handling "setter" method + } // End of loop through Methods + } // End of section handling yang-generated class + + } + + public static boolean isYangGenerated(Class c) { + if (c == null) { + return (false); + } else { + return (c.getName().startsWith("org.opendaylight.yang.gen.")); + } + } + + public static boolean isIpPrefix(Class c) { + + if (c == null) { + return (false); + } + String simpleName = c.getSimpleName(); + return ("IpPrefix".equals(simpleName)); + } + + public static boolean isIpv4Address(Class c) { + + if (c == null) { + return (false); + } + String simpleName = c.getSimpleName(); + return ("Ipv4Address".equals(simpleName)); + } + + public static boolean isIpv6Address(Class c) { + + if (c == null) { + return (false); + } + String simpleName = c.getSimpleName(); + return ("Ipv6Address".equals(simpleName)); + } + + public static boolean isIpAddress(Class c) { + + if (c == null) { + return (false); + } + String simpleName = c.getSimpleName(); + return ("IpAddress".equals(simpleName)); + } + + public static String toLowerHyphen(String inStr) { + if (inStr == null) { + return (null); + } + + String str = inStr.substring(0, 1).toLowerCase(); + if (inStr.length() > 1) { + str = str + inStr.substring(1); + } + + String regex = "(([a-z0-9])([A-Z]))"; + String replacement = "$2-$3"; + + String retval = str.replaceAll(regex, replacement).toLowerCase(); + + LOG.trace("Converting " + inStr + " => " + str + " => " + retval); + return (retval); + } + + //This is called when mapping the yang value back to a valid java enumeration + public static String toJavaEnum(String inStr) { + if (inStr == null) { + return (null); + } else if (inStr.length() == 0) { + return (inStr); + } + + //This will strip out all periods, which cannot be in a java enum + inStr = inStr.replaceAll("\\.", ""); + + String[] terms = inStr.split("-"); + StringBuffer sbuff = new StringBuffer(); + + //appends an _ if the string starts with a digit to make it a valid java enum + if (Character.isDigit(inStr.charAt(0))) { + sbuff.append('_'); + } + //If the string contains hyphens it will convert the string to upperCamelCase without hyphens + for (String term : terms) { + sbuff.append(term.substring(0, 1).toUpperCase()); + if (term.length() > 1) { + sbuff.append(term.substring(1)); + } + } + return (sbuff.toString()); + + } + + public static boolean isGetter(Method m) { + if (m == null) { + return (false); + } + + if (Modifier.isPublic(m.getModifiers()) && (m.getParameterTypes().length == 0)) { + if (m.getName().matches("^get[A-Z].*") && !m.getReturnType().equals(void.class)) { + if (!"getClass".equals(m.getName())) { + return (true); + } + } + + if (m.getName().matches("^get[A-Z].*") && m.getReturnType().equals(boolean.class)) { + return (true); + } + + if (m.getName().matches("^is[A-Z].*") && m.getReturnType().equals(Boolean.class)) { + return (true); + } + } + + return (false); + } + + public static boolean isSetter(Method m) { + if (m == null) { + return (false); + } + + if (Modifier.isPublic(m.getModifiers()) && (m.getParameterTypes().length == 1)) { + if (m.getName().matches("^set[A-Z].*")) { + Class[] paramTypes = m.getParameterTypes(); + if (paramTypes[0].isAssignableFrom(Identifier.class) || Identifier.class.isAssignableFrom(paramTypes[0])) { + return (false); + } else { + return (true); + } + } + + } + + return (false); + } + + public static String getFullPropertiesPath(String propertiesFileName) { + return "/opt/bvc/controller/configuration/" + propertiesFileName; + } + + //This is called when mapping a valid java enumeration back to the yang model value + public static String mapEnumeratedValue(String propertyName, String propertyValue) { + LOG.info("mapEnumeratedValue called with propertyName=" + propertyName + " and value=" + propertyValue); + String mappingKey = "yang." + propertyName + "." + propertyValue; + if (yangMappingProperties.containsKey(mappingKey)) { + return (yangMappingProperties.getProperty(mappingKey)); + } else { + LOG.info("yangMappingProperties did not contain the key " + mappingKey + " returning the original value."); + return propertyValue; + } + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java new file mode 100644 index 00000000..9f50547b --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NotifyNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(NotifyNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String action = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("action"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("release node encountered - looking for resource class " + + plugin); + } + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + if (resourcePlugin != null) { + + try { + + switch (resourcePlugin.notify(resourceType, action, key, ctx)) { + case SUCCESS: + outValue = "success"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java new file mode 100644 index 00000000..3c8c4c06 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RecordNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(RecordNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String outValue = "failure"; + + if (LOG.isTraceEnabled()) { + LOG.trace(node.getNodeType() + + " node encountered - looking for recorder class " + + plugin); + } + + Map parmMap = new HashMap(); + + Set> parmSet = node + .getParameterSet(); + boolean hasParms = false; + + for (Iterator> iter = parmSet + .iterator(); iter.hasNext();) { + hasParms = true; + Map.Entry curEnt = iter.next(); + String curName = curEnt.getKey(); + SvcLogicExpression curExpr = curEnt.getValue(); + String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, + node, ctx); + + if (LOG.isTraceEnabled()) { + LOG.trace("executeRecordNode : parameter " + curName + " = " + + curExpr + " => " + curExprValue); + } + parmMap.put(curName, curExprValue); + } + + + SvcLogicRecorder recorder = getSvcLogicRecorder(plugin); + + if (recorder != null) { + + try { + recorder.record(parmMap); + } catch (SvcLogicException e) { + LOG.error("Caught exception from recorder plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicRecorder object for plugin " + + plugin); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isTraceEnabled()) { + LOG.trace("no failure or Other branch found"); + } + } + return (nextNode); + } + + + + + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java new file mode 100644 index 00000000..4fee9aa8 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ReleaseNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(ReleaseNodeExecutor.class); + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("release node encountered - looking for resource class " + + plugin); + } + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + if (resourcePlugin != null) { + + try { + + switch (resourcePlugin.release(resourceType, key, ctx)) { + case SUCCESS: + outValue = "success"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java new file mode 100644 index 00000000..6d8035e2 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ReserveNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(ReserveNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + String pfx = SvcLogicExpressionResolver.evaluate(node.getAttribute("pfx"),node,ctx); + + + SvcLogicExpression selectExpr = node.getAttribute("select"); + String select = null; + + if (selectExpr != null) + { + select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node, ctx); + } + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("reserve node encountered - looking for resource class " + + plugin); + } + + + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + + if (resourcePlugin != null) { + + try { + switch (resourcePlugin.reserve(resourceType, select, key, pfx, ctx)) { + case SUCCESS: + outValue = "success"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java new file mode 100644 index 00000000..b1a2b902 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ReturnNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(ReturnNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String status = SvcLogicExpressionResolver.evaluate( + node.getAttribute("status"), node, ctx); + + if (status != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Returning status " + status); + } + ctx.setStatus(status); + } else { + if (LOG.isWarnEnabled()) { + LOG.warn("Return node has no status attribute set"); + } + } + + Set> parameterSet = node + .getParameterSet(); + + for (Iterator> iter = parameterSet + .iterator(); iter.hasNext();) { + Map.Entry curEnt = iter.next(); + String curName = curEnt.getKey(); + String curValue = SvcLogicExpressionResolver.evaluate( + curEnt.getValue(), node, ctx); + + if (LOG.isDebugEnabled()) { + LOG.debug("Setting context attribute " + curName + " to " + + curValue); + } + ctx.setAttribute(curName, curValue); + } + return null; + } + + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java new file mode 100644 index 00000000..0dd55525 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java @@ -0,0 +1,141 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SaveNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(SaveNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + String forceStr = SvcLogicExpressionResolver.evaluate( + node.getAttribute("force"), node, ctx); + String localOnlyStr = SvcLogicExpressionResolver.evaluate( + node.getAttribute("local-only"), node, ctx); + String pfx = SvcLogicExpressionResolver.evaluate( + node.getAttribute("pfx"), node, ctx); + + boolean force = "true".equalsIgnoreCase(forceStr); + boolean localOnly = "true".equalsIgnoreCase(localOnlyStr); + + Map parmMap = new HashMap(); + + Set> parmSet = node + .getParameterSet(); + boolean hasParms = false; + + for (Iterator> iter = parmSet + .iterator(); iter.hasNext();) { + hasParms = true; + Map.Entry curEnt = iter.next(); + String curName = curEnt.getKey(); + SvcLogicExpression curExpr = curEnt.getValue(); + if (curExpr != null) { + String curExprValue = SvcLogicExpressionResolver.evaluate( + curExpr, node, ctx); + + LOG.debug("Parameter " + curName + " = " + + curExpr.asParsedExpr() + " resolves to " + + curExprValue); + + parmMap.put(curName, curExprValue); + } + } + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("save node encountered - looking for resource class " + + plugin); + } + + + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + + if (resourcePlugin != null) { + + try { + switch (resourcePlugin.save(resourceType, force, localOnly, key, + parmMap, pfx, ctx)) { + case SUCCESS: + outValue = "success"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java new file mode 100644 index 00000000..18ca3d0d --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java @@ -0,0 +1,188 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpressionFactory; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SetNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(SetNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String ifunsetStr = SvcLogicExpressionResolver.evaluate( + node.getAttribute("only-if-unset"), node, ctx); + + boolean ifunset = "true".equalsIgnoreCase(ifunsetStr); + + Set> parameterSet = node + .getParameterSet(); + + for (Iterator> iter = parameterSet + .iterator(); iter.hasNext();) { + Map.Entry curEnt = iter.next(); + String curName = curEnt.getKey(); + String lhsVarName = curName; + + // Resolve LHS of assignment (could contain index variables) + try { + SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(curName); + lhsVarName = SvcLogicExpressionResolver.resolveVariableName(lhsExpr, node, ctx); + } catch (Exception e) { + LOG.warn("Caught exception trying to resolve variable name ("+curName+")", e); + } + + + boolean setValue = true; + + if (curName.endsWith(".")) { + + // Copy subtree - value should be a variable name + SvcLogicExpression curValue = curEnt.getValue(); + + if (curValue != null) { + String rhsRoot = curValue.toString(); + + if ((rhsRoot != null) && (rhsRoot.length() > 0)) { + if (rhsRoot.endsWith(".")) { + rhsRoot = rhsRoot + .substring(0, rhsRoot.length() - 1); + } + + + // SDNGC-2321 : rhsRoot is variable name, possibly with subscript(s) to be resolved + try { + SvcLogicExpression rhsExpr = SvcLogicExpressionFactory.parse(rhsRoot); + rhsRoot = SvcLogicExpressionResolver.resolveVariableName(rhsExpr, node, ctx); + } catch (Exception e) { + LOG.warn("Caught exception trying to resolve variable name ("+rhsRoot+")", e); + } + + // See if the parameters are reversed (copying service-data to input) .. this + // was done as a workaround to earlier issue + if (curName.endsWith("-input.") && rhsRoot.startsWith("service-data")) { + LOG.warn("Arguments appear to be reversed .. will copy input to service-data instead"); + lhsVarName = rhsRoot + "."; + rhsRoot = curName.substring(0, curName.length()-1); + } + + rhsRoot = rhsRoot + "."; + String lhsPrefix = lhsVarName; + + if (lhsPrefix.endsWith(".")) { + lhsPrefix = lhsPrefix.substring(0, + lhsPrefix.length()-1); + } + int lhsPfxLength = lhsPrefix.length(); + HashMap parmsToAdd = new HashMap(); + + for (String sourceVarName : ctx.getAttributeKeySet()) { + + if (sourceVarName.startsWith(rhsRoot)) { + + String targetVar = lhsPrefix + + "." + + sourceVarName + .substring(rhsRoot.length()); + + LOG.debug("Copying " + sourceVarName + + " value to " + targetVar); + + parmsToAdd.put(targetVar, + ctx.getAttribute(sourceVarName)); + } + } + + for (String newParmName : parmsToAdd.keySet()) { + ctx.setAttribute(newParmName, parmsToAdd.get(newParmName)); + } + + } else { + // If RHS is empty, unset attributes in LHS + String lhsPrefix = lhsVarName.substring(0, + lhsVarName.length() - 1); + int lhsPfxLength = lhsPrefix.length(); + + LinkedList parmsToRemove = new LinkedList (); + + for (String curCtxVarname : ctx.getAttributeKeySet()) { + + if (curCtxVarname.startsWith(lhsPrefix)) { + LOG.debug("Unsetting " + curCtxVarname); + parmsToRemove.add(curCtxVarname); + } + } + + for (String parmName : parmsToRemove) { + ctx.setAttribute(parmName, null); + } + + } + } + + } else { + + if (ifunset) { + String ctxValue = ctx.getAttribute(lhsVarName); + + if ((ctxValue != null) && (ctxValue.length() > 0)) { + setValue = false; + LOG.debug("Attribute " + + lhsVarName + + " already set and only-if-unset is true, so not overriding"); + } + } + + if (setValue) { + String curValue = SvcLogicExpressionResolver.evaluate( + curEnt.getValue(), node, ctx); + + if (LOG.isDebugEnabled()) { + LOG.trace("Parameter value " + + curEnt.getValue().asParsedExpr() + + " resolves to " + curValue); + LOG.debug("Setting context attribute " + lhsVarName + + " to " + curValue); + } + ctx.setAttribute(lhsVarName, curValue); + } + } + } + + return null; + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java new file mode 100644 index 00000000..3bc8f092 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java @@ -0,0 +1,224 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.io.File; +import java.io.FileInputStream; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.LinkedList; +import java.util.Map; +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.ConfigurationException; +import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicStore; +import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.mysql.jdbc.Driver; + +public class SvcLogicActivator implements BundleActivator { + + private static final String SVCLOGIC_PROP_VAR = "SDNC_SLI_PROPERTIES"; + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + + private static final Map BUILTIN_NODES = new HashMap() { + { + put("block", new BlockNodeExecutor()); + put("call", new CallNodeExecutor()); + put("configure", new ConfigureNodeExecutor()); + put("delete", new DeleteNodeExecutor()); + put("execute", new ExecuteNodeExecutor()); + put("exists", new ExistsNodeExecutor()); + put("for", new ForNodeExecutor()); + put("get-resource", new GetResourceNodeExecutor()); + put("is-available", new IsAvailableNodeExecutor()); + put("notify", new NotifyNodeExecutor()); + put("record", new RecordNodeExecutor()); + put("release", new ReleaseNodeExecutor()); + put("reserve", new ReserveNodeExecutor()); + put("return", new ReturnNodeExecutor()); + put("save", new SaveNodeExecutor()); + put("set", new SetNodeExecutor()); + put("switch", new SwitchNodeExecutor()); + put("update", new UpdateNodeExecutor()); + put("break", new BreakNodeExecutor()); + + } + }; + + private static LinkedList registrations = new LinkedList(); + + private static HashMap adaptorMap = null; + + private static final Logger LOG = LoggerFactory + .getLogger(SvcLogicActivator.class); + + private static Properties props = null; + + private static BundleContext bundleCtx = null; + + private static SvcLogicService svcLogicServiceImpl = null; + + @Override + public void start(BundleContext ctx) throws Exception { + + LOG.info("Activating SLI"); + + bundleCtx = ctx; + + // Read properties + props = new Properties(); + String propPath = System.getenv(SVCLOGIC_PROP_VAR); + + if (propPath == null) { + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { + + propDir = "/opt/sdnc/data/properties"; + } + propPath = propDir + "/svclogic.properties"; + LOG.warn("Environment variable "+SVCLOGIC_PROP_VAR+" unset - defaulting to "+propPath); + } + + File propFile = new File(propPath); + + if (!propFile.exists()) { + + throw new ConfigurationException( + "Missing configuration properties file : " + + propFile); + } + try { + + props.load(new FileInputStream(propFile)); + } catch (Exception e) { + throw new ConfigurationException( + "Could not load properties file " + propPath, e); + + } + + + if (registrations == null) { + + registrations = new LinkedList(); + } + + // Advertise SvcLogicService + svcLogicServiceImpl = new SvcLogicServiceImpl(); + + LOG.info("SLI: Registering service " + SvcLogicService.NAME + + " in bundle " + ctx.getBundle().getSymbolicName()); + ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME, + svcLogicServiceImpl, null); + registrations.add(reg); + + // Initialize SvcLogicStore + try { + SvcLogicStore store = getStore(); + registerNodeTypes(store); + } catch (ConfigurationException e) { + LOG.warn("Could not initialize SvcLogicScore", e); + } + + LOG.info("SLI - done registering services"); + } + + @Override + public void stop(BundleContext ctx) throws Exception { + + if (registrations != null) { + for (ServiceRegistration reg : registrations) { + ServiceReference regRef = reg.getReference(); + /* Don't bother to remove node types from table + String nodeType = (String) regRef.getProperty("nodeType"); + if (nodeType != null) { + LOG.info("SLI - unregistering node type " + nodeType); + store.unregisterNodeType(nodeType); + } + */ + reg.unregister(); + } + registrations = null; + } + } + + public static SvcLogicStore getStore() throws SvcLogicException { + // Create and initialize SvcLogicStore object - used to access + // saved service logic. + + SvcLogicStore store = null; + + try { + Driver dvr = new Driver(); + store = SvcLogicStoreFactory.getSvcLogicStore(props); + } catch (Exception e) { + throw new ConfigurationException( + "Could not get service logic store", e); + + } + + try { + store.init(props); + } catch (Exception e) { + throw new ConfigurationException( + "Could not get service logic store", e); + } + + return(store); + } + + private static void registerNodeTypes(SvcLogicStore store) throws SvcLogicException { + + if (store == null) { + return; + } + // Advertise built-in node executors + LOG.info("SLI : Registering built-in node executors"); + Hashtable propTable = new Hashtable(); + + for (String nodeType : BUILTIN_NODES.keySet()) { + LOG.info("SLI - registering node type " + nodeType); + propTable.clear(); + propTable.put("nodeType", nodeType); + + ServiceRegistration reg = bundleCtx.registerService(SvcLogicNodeExecutor.class.getName(), + BUILTIN_NODES.get(nodeType), propTable); + registrations.add(reg); + + store.registerNodeType(nodeType); + + LOG.info("SLI - registering node executor"); + + ((SvcLogicServiceImpl)svcLogicServiceImpl).registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); + + } + + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicAdaptorFactory.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicAdaptorFactory.java new file mode 100644 index 00000000..1bc8e0f8 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicAdaptorFactory.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.HashMap; + +import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SvcLogicAdaptorFactory { + + private static final Logger LOG = LoggerFactory + .getLogger(SvcLogicAdaptorFactory.class); + + private static HashMap adaptorMap = new HashMap(); + + public static void registerAdaptor(SvcLogicAdaptor adaptor) { + String name = adaptor.getClass().getName(); + LOG.info("Registering adaptor " + name); + adaptorMap.put(name, adaptor); + + } + + public static void unregisterAdaptor(String name) { + if (adaptorMap.containsKey(name)) { + LOG.info("Unregistering " + name); + adaptorMap.remove(name); + } + } + + public static SvcLogicAdaptor getInstance(String name) { + if (adaptorMap.containsKey(name)) { + return (adaptorMap.get(name)); + } else { + BundleContext bctx = null; + try + { + bctx = FrameworkUtil.getBundle(SvcLogicAdaptorFactory.class) + .getBundleContext(); + } + catch (Exception e) + { + LOG.debug("Caught exception trying to locate device adaptor "+name, e); + return(null); + } + + ServiceReference sref = bctx.getServiceReference(name); + + if (sref != null) { + SvcLogicAdaptor adaptor = (SvcLogicAdaptor) bctx + .getService(sref); + + if (adaptor != null) { + registerAdaptor(adaptor); + + return (adaptor); + } + return (null); + } + } + return(null); + } +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolver.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolver.java new file mode 100644 index 00000000..01851cc6 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolver.java @@ -0,0 +1,604 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicAtom; +import org.onap.ccsdk.sli.core.sli.SvcLogicBinaryExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicFunctionCall; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicVariableTerm; +import org.onap.ccsdk.sli.core.sli.SvcLogicAtom.AtomType; +import org.onap.ccsdk.sli.core.sli.SvcLogicBinaryExpression.OperatorType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SvcLogicExpressionResolver { + + private static final Logger LOG = LoggerFactory + .getLogger(SvcLogicExpressionResolver.class); + + public static String evaluate(SvcLogicExpression expr, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + if (expr == null) { + return (null); + } + + + + if (expr instanceof SvcLogicAtom) { + SvcLogicAtom atom = (SvcLogicAtom) expr; + + AtomType atomType = atom.getAtomType(); + switch (atomType) { + case NUMBER: + case STRING: + return (atom.toString()); + case CONTEXT_VAR: + case IDENTIFIER: + + String varName = resolveVariableName(atom, node, ctx); + + if (atomType == AtomType.CONTEXT_VAR) + { + LOG.trace("Evaluating context variable $"+varName); + + String varValue = ctx.getAttribute(varName); + + if (varValue == null) { + LOG.trace("Context variable $"+varName+" unset - treating as empty string"); + varValue = ""; + } + + return (varValue); + } + SvcLogicExpression parm = node.getParameter(varName); + if (parm != null) { + LOG.trace("Evaluating value of parameter "+varName+": "+parm.asParsedExpr()); + + return (evaluate(parm, node, ctx)); + } + else + { + return(varName); + } + default: + return(null); + } + + } else if (expr instanceof SvcLogicBinaryExpression) { + SvcLogicBinaryExpression binExpr = (SvcLogicBinaryExpression) expr; + List operators = binExpr.getOperators(); + if (operators.isEmpty()) + { + List operands = binExpr.getOperands(); + if (operands.size() == 1) + { + LOG.trace("SvcLogicBinaryExpression as no operator and one operand - evaluating its operand"); + return(evaluate(operands.get(0), node, ctx)); + } + else + { + if (operands.isEmpty()) + { + LOG.error("SvcLogicBinaryExpression has no operators and no operands - evaluating value as null"); + } + else + { + LOG.error("SvcLogicBinaryExpression has no operators and "+operands.size()+" operands - evaluating value as null"); + } + return(null); + } + } + switch (operators.get(0)) { + case addOp: + case subOp: + case multOp: + case divOp: + return(evalArithExpression(binExpr, node, ctx)); + case equalOp: + case neOp: + case ltOp: + case leOp: + case gtOp: + case geOp: + return (evalCompareExpression(binExpr, node, ctx)); + case andOp: + case orOp: + return(evalLogicExpression(binExpr, node, ctx)); + + default: + return(null); + } + } + else if (expr instanceof SvcLogicFunctionCall) + { + return(evalFunctionCall((SvcLogicFunctionCall)expr, node, ctx)); + } + else + { + throw new SvcLogicException("Unrecognized expression type ["+expr+"]"); + } + } + + private static String evalArithExpression(SvcLogicBinaryExpression binExpr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + List operands = binExpr.getOperands(); + List operators = binExpr.getOperators(); + if (operands.size() != (operators.size()+1)) + { + throw new SvcLogicException("Invalid expression ("+binExpr+")"); + } + String retval = evaluate(operands.get(0), node, ctx); + String retsval = retval; + long retlval = 0; + boolean valueIsLong = false; + + int i = 1; + try + { + + if ((retval.length() > 0) && StringUtils.isNumeric(retval)) + { + retlval = Long.parseLong(retval); + valueIsLong = true; + } + for (OperatorType operator: operators) + { + String curOperandValue = evaluate(operands.get(i++), node, ctx); + switch(operator) { + case addOp: + retsval = retsval + curOperandValue; + if (valueIsLong) + { + if ((curOperandValue.length() > 0) && StringUtils.isNumeric(curOperandValue) ) + { + retlval = retlval + Long.parseLong(curOperandValue); + } + else + { + valueIsLong = false; + } + } + break; + case subOp: + retlval = retlval - Long.parseLong(curOperandValue); + break; + case multOp: + retlval = retlval * Long.parseLong(curOperandValue); + break; + case divOp: + retlval = retlval / Long.parseLong(curOperandValue); + break; + } + + } + } + catch (NumberFormatException e1) + { + throw new SvcLogicException("Illegal value in arithmetic expression", e1); + } + + if (valueIsLong) + { + return("" + retlval); + } + else + { + return(retsval); + } + + } + + + + private static String evalCompareExpression(SvcLogicBinaryExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException + { + + List operators = expr.getOperators(); + List operands = expr.getOperands(); + + if ((operators.size() != 1) || (operands.size() != 2)) + { + throw new SvcLogicException ("Invalid comparison expression : "+expr); + } + + OperatorType operator = operators.get(0); + String op1Value = evaluate(operands.get(0), node, ctx); + String op2Value = evaluate(operands.get(1), node, ctx); + + if ((StringUtils.isNotEmpty(op1Value) && StringUtils.isNumeric(op1Value) && StringUtils.isNotEmpty(op2Value) && StringUtils.isNumeric(op2Value))) + { + try + { + double op1dbl = Double.parseDouble(op1Value); + double op2dbl = Double.parseDouble(op2Value); + + switch(operator) + { + case equalOp: + return(Boolean.toString(op1dbl == op2dbl)); + case neOp: + return(Boolean.toString(op1dbl != op2dbl)); + case ltOp: + return(Boolean.toString(op1dbl < op2dbl)); + case leOp: + return(Boolean.toString(op1dbl <= op2dbl)); + case gtOp: + return(Boolean.toString(op1dbl > op2dbl)); + case geOp: + return(Boolean.toString(op1dbl >= op2dbl)); + default: + return(null); + } + } + catch (NumberFormatException e) + { + throw new SvcLogicException("Caught exception trying to compare numeric values", e); + } + } + else + { + + int compResult = 0; + + if (op1Value == null) { + compResult = -1; + } else if (op2Value == null ) { + compResult = 1; + } else { + compResult = op1Value.compareToIgnoreCase(op2Value); + } + + switch(operator) + { + case equalOp: + return(Boolean.toString(compResult == 0)); + case neOp: + return(Boolean.toString(compResult != 0)); + case ltOp: + return(Boolean.toString(compResult < 0)); + case leOp: + return(Boolean.toString(compResult <= 0)); + case gtOp: + return(Boolean.toString(compResult > 0)); + case geOp: + return(Boolean.toString(compResult >= 0)); + default: + return(null); + } + } + + } + + private static String evalLogicExpression(SvcLogicBinaryExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException + { + boolean retval; + + List operands = expr.getOperands(); + List operators = expr.getOperators(); + + if (operands.size() != (operators.size()+1)) + { + throw new SvcLogicException("Invalid expression ("+expr+")"); + } + + try + { + retval = Boolean.parseBoolean(evaluate(operands.get(0), node, ctx)); + int i = 1; + for (OperatorType operator : operators) + { + if (operator == OperatorType.andOp) + { + retval = retval && Boolean.parseBoolean(evaluate(operands.get(i++), node, ctx)); + } + else + { + + retval = retval || Boolean.parseBoolean(evaluate(operands.get(i++), node, ctx)); + } + + } + } + catch (Exception e) + { + throw new SvcLogicException("Invalid expression ("+expr+")"); + } + + + return(Boolean.toString(retval)); + } + + private static String evalFunctionCall(SvcLogicFunctionCall func, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException + { + String funcName = func.getFunctionName(); + List operands = func.getOperands(); + + if ("length".equalsIgnoreCase(funcName)) + { + + if (operands.size() == 1) + { + String opValue = evaluate(operands.get(0), node, ctx); + return(""+opValue.length()); + } + else + { + throw new SvcLogicException("Invalid call to length() function"); + } + } + else if ("substr".equalsIgnoreCase(funcName)) + { + if (operands.size() == 3) + { + String op1Value = evaluate(operands.get(0), node, ctx); + String op2Value = evaluate(operands.get(1), node, ctx); + String op3Value = evaluate(operands.get(2), node, ctx); + + if (!StringUtils.isNumeric(op2Value) || !StringUtils.isNumeric(op3Value)) + { + throw new SvcLogicException("Invalid arguments to substr() function"); + } + + try + { + return(op1Value.substring(Integer.parseInt(op2Value), Integer.parseInt(op3Value))); + } + catch (Exception e) + { + throw new SvcLogicException("Caught exception trying to take substring", e); + } + } + else + { + + throw new SvcLogicException("Invalid call to substr() function"); + } + + } + else if ("toUpperCase".equalsIgnoreCase(funcName)) + { + if (operands.size() == 1) + { + String opValue = evaluate(operands.get(0), node, ctx); + if (opValue != null) { + return(opValue.toUpperCase()); + } else { + return(""); + } + } + else + { + throw new SvcLogicException("Invalid call to toUpperCase() function"); + } + } + else if ("toLowerCase".equalsIgnoreCase(funcName)) + { + if (operands.size() == 1) + { + String opValue = evaluate(operands.get(0), node, ctx); + if (opValue != null) { + return(opValue.toLowerCase()); + } else { + return(""); + } + } + else + { + throw new SvcLogicException("Invalid call to toLowerCase() function"); + } + } + else if ("convertBase".equalsIgnoreCase(funcName)) { + int fromBase = 10; + int toBase = 10; + String srcString = ""; + + if (operands.size() == 2) + { + fromBase = 10; + srcString = evaluate(operands.get(0), node, ctx); + toBase = Integer.parseInt(evaluate(operands.get(1), node, ctx)); + } else if (operands.size() == 3) { + + srcString = evaluate(operands.get(0), node, ctx); + fromBase = Integer.parseInt(evaluate(operands.get(1), node, ctx)); + toBase = Integer.parseInt(evaluate(operands.get(2), node, ctx)); + } else { + throw new SvcLogicException("Invalid call to convertBase() function"); + } + + long srcValue = Long.parseLong(srcString, fromBase); + return(Long.toString(srcValue, toBase)); + } + else + { + throw new SvcLogicException("Unrecognized function ("+funcName+")"); + } + + } + + public static String evaluateAsKey(SvcLogicExpression expr, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + if (expr == null) { + return (null); + } + + + + if (expr instanceof SvcLogicAtom) { + SvcLogicAtom atom = (SvcLogicAtom) expr; + + AtomType atomType = atom.getAtomType(); + StringBuffer varNameBuff = new StringBuffer(); + switch (atomType) { + case NUMBER: + return (atom.toString()); + case STRING: + return("'"+atom.toString()+"'"); + case CONTEXT_VAR: + case IDENTIFIER: + boolean needDot = false; + for (SvcLogicExpression term : atom.getOperands()) + { + if (needDot) + { + varNameBuff.append("."); + } + if (term instanceof SvcLogicVariableTerm) + { + SvcLogicVariableTerm vterm = (SvcLogicVariableTerm) term; + varNameBuff.append(vterm.getName()); + if (vterm.numOperands() > 0) + { + varNameBuff.append("["); + varNameBuff.append(evaluate(vterm.getSubscript(), node, ctx)); + varNameBuff.append("]"); + + } + } + else + { + varNameBuff.append(term.toString()); + } + needDot = true; + } + + String varName = varNameBuff.toString(); + LOG.debug("Evaluating context variable $"+varName); + String ctxValue = ctx.getAttribute(varName); + if (ctxValue == null) + { + return(null); + } + if (StringUtils.isNumeric(ctxValue)) + { + return(ctxValue); + } + else + { + return("'"+ctxValue+"'"); + } + + default: + return(null); + } + + } else if (expr instanceof SvcLogicBinaryExpression) { + SvcLogicBinaryExpression binExpr = (SvcLogicBinaryExpression) expr; + List operators = binExpr.getOperators(); + List operands = binExpr.getOperands(); + if (operators.isEmpty()) + { + if (operands.size() == 1) + { + LOG.debug("SvcLogicBinaryExpression as no operator and one operand - evaluating its operand"); + return(evaluateAsKey(operands.get(0), node, ctx)); + } + else + { + if (operands.isEmpty()) + { + LOG.error("SvcLogicBinaryExpression has no operators and no operands - evaluating value as null"); + } + else + { + LOG.error("SvcLogicBinaryExpression has no operators and "+operands.size()+" operands - evaluating value as null"); + } + return(null); + } + } + StringBuffer sbuff = new StringBuffer(); + sbuff.append(evaluateAsKey(operands.get(0), node, ctx)); + int i = 1; + for (OperatorType operator : operators) + { + sbuff.append(" "); + sbuff.append(operator.toString()); + sbuff.append(" "); + sbuff.append(evaluateAsKey(operands.get(i++), node,ctx)); + } + return(sbuff.toString()); + } + else if (expr instanceof SvcLogicFunctionCall) + { + StringBuffer sbuff = new StringBuffer(); + SvcLogicFunctionCall funcCall = (SvcLogicFunctionCall) expr; + sbuff.append(funcCall.getFunctionName()); + sbuff.append("("); + boolean needComma = false; + for (SvcLogicExpression operand : funcCall.getOperands()) + { + if (needComma) + { + sbuff.append(","); + } + else + { + needComma = true; + } + sbuff.append(evaluateAsKey(operand, node, ctx)); + } + sbuff.append(")"); + return(sbuff.toString()); + } + else + { + throw new SvcLogicException("Unrecognized expression type ["+expr+"]"); + } + } + + public static String resolveVariableName(SvcLogicExpression atom, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException + { + StringBuffer varNameBuff = new StringBuffer(); + + boolean needDot = false; + for (SvcLogicExpression term : atom.getOperands()) + { + if (needDot) + { + varNameBuff.append("."); + } + if (term instanceof SvcLogicVariableTerm) + { + SvcLogicVariableTerm vterm = (SvcLogicVariableTerm) term; + varNameBuff.append(vterm.getName()); + if (vterm.numOperands() > 0) + { + varNameBuff.append("["); + varNameBuff.append(evaluate(vterm.getSubscript(), node, ctx)); + varNameBuff.append("]"); + } + } + else + { + varNameBuff.append(term.toString()); + } + needDot = true; + } + return(varNameBuff.toString()); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java new file mode 100644 index 00000000..8d72f7a8 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicStore; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class SvcLogicNodeExecutor { + + public abstract SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException; + + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicNodeExecutor.class); + + protected String evaluateNodeTest(SvcLogicNode node, SvcLogicContext ctx) + throws SvcLogicException { + if (node == null) { + return null; + } + + return (SvcLogicExpressionResolver.evaluate(node.getAttribute("test"), + node, ctx)); + + } + + protected SvcLogicStore getStore() throws SvcLogicException { + return SvcLogicActivator.getStore(); + } + + protected SvcLogicAdaptor getAdaptor(String adaptorName) { + return SvcLogicAdaptorFactory.getInstance(adaptorName); + } + + protected SvcLogicResource getSvcLogicResource(String plugin) { + BundleContext bctx = FrameworkUtil.getBundle(this.getClass()) + .getBundleContext(); + + ServiceReference sref = bctx.getServiceReference(plugin); + if (sref != null) { + SvcLogicResource resourcePlugin = (SvcLogicResource) bctx + .getService(sref); + return resourcePlugin; + } + else { + LOG.warn("Could not find service reference object for plugin " + plugin); + return null; + } + } + + protected SvcLogicRecorder getSvcLogicRecorder(String plugin) { + BundleContext bctx = FrameworkUtil.getBundle(this.getClass()) + .getBundleContext(); + + ServiceReference sref = bctx.getServiceReference(plugin); + if (sref != null) { + SvcLogicRecorder resourcePlugin = (SvcLogicRecorder) bctx + .getService(sref); + return resourcePlugin; + } + else { + return null; + } + } + + protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){ + BundleContext bctx = FrameworkUtil.getBundle(this.getClass()) + .getBundleContext(); + + ServiceReference sref = bctx.getServiceReference(pluginName); + + if (sref == null) { + LOG.warn("Could not find service reference object for plugin " + pluginName); + return null; + } else { + SvcLogicJavaPlugin plugin = (SvcLogicJavaPlugin) bctx + .getService(sref); + return plugin; + } + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java new file mode 100644 index 00000000..cfba5866 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; + +public interface SvcLogicService { + + public static final String NAME = "org.openecomp.sdnc.sli.provider.SvcLogicService"; + + // public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException; + /** + * Check for existence of a directed graph + * @param module - module name + * @param rpc - rpc name + * @param version - version. If null, looks for active version + * @param mode - mode (sync/async) + * @return true if directed graph found, false otherwise + * @throws SvcLogicException + */ + public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException; + + /** + * Execute a directed graph + * + * @param module - module name + * @param rpc - rpc name + * @param version - version. If null, use active version + * @param mode - mode (sync/async) + * @param parms - parameters, used to set SvcLogicContext attributes + * @return final values of attributes from SvcLogicContext, as Properties + * @throws SvcLogicException + * + * + * @deprecated use execute(String module, String rpc, String version, String mode, DOMDataBroker dataBroker) instead + */ + @Deprecated + public Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException; + + /** + * Execute a directed graph + * + * @param module - module name + * @param rpc - rpc name + * @param version - version. If null, use active version + * @param mode - mode (sync/async) + * @param parms - parameters, used to set SvcLogicContext attributes + * @param domDataBroker - DOMDataBroker object + * @return final values of attributes from SvcLogicContext, as Properties + * @throws SvcLogicException + */ + public Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException; + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java new file mode 100644 index 00000000..c0ee4c2c --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java @@ -0,0 +1,272 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.HashMap; +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.MetricLogger; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicStore; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + +public class SvcLogicServiceImpl implements SvcLogicService { + + private static final Logger LOG = LoggerFactory + .getLogger(SvcLogicServiceImpl.class); + + private HashMap nodeExecutors = null; + + private BundleContext bctx = null; + + private void registerExecutors() { + + LOG.info("Entered register executors"); + if (bctx == null) { + bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); + } + + if (nodeExecutors == null) { + nodeExecutors = new HashMap(); + } + + LOG.info("Opening service tracker"); + ServiceTracker tracker = new ServiceTracker(bctx, + SvcLogicNodeExecutor.class.getName(), null); + + tracker.open(); + + ServiceListener listener = new ServiceListener() { + + public void serviceChanged(ServiceEvent ev) { + ServiceReference sr = ev.getServiceReference(); + switch (ev.getType()) { + case ServiceEvent.REGISTERED: { + registerExecutor(sr); + } + break; + case ServiceEvent.UNREGISTERING: { + unregisterExecutor(sr); + } + break; + } + } + }; + + LOG.info("Adding service listener"); + String filter = "(objectclass=" + SvcLogicNodeExecutor.class.getName() + + ")"; + try { + bctx.addServiceListener(listener, filter); + ServiceReference[] srl = bctx.getServiceReferences( + SvcLogicNodeExecutor.class.getName(), null); + for (int i = 0; srl != null && i < srl.length; i++) { + listener.serviceChanged(new ServiceEvent( + ServiceEvent.REGISTERED, srl[i])); + } + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + } + LOG.info("Done registerExecutors"); + } + + public void registerExecutor(ServiceReference sr) { + + String nodeName = (String) sr.getProperty("nodeType"); + if (nodeName != null) { + + SvcLogicNodeExecutor executor = null; + + try { + executor = (SvcLogicNodeExecutor) bctx.getService(sr); + } catch (Exception e) { + LOG.error("Cannot get service executor for " + nodeName); + return; + } + + registerExecutor(nodeName, executor); + + } + } + + public void registerExecutor(String nodeName, SvcLogicNodeExecutor executor) + { + if (nodeExecutors == null) { + nodeExecutors = new HashMap(); + } + LOG.info("SLI - registering executor for node type "+nodeName); + nodeExecutors.put(nodeName, executor); + } + + public void unregisterExecutor(ServiceReference sr) { + String nodeName = (String) sr.getProperty("nodeType"); + + if (nodeName != null) { + + unregisterExecutor(nodeName); + + } + + } + + public void unregisterExecutor(String nodeName) + { + + LOG.info("SLI - unregistering executor for node type "+nodeName); + nodeExecutors.remove(nodeName); + } + + + + + public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) + throws SvcLogicException { + + if (nodeExecutors == null) { + registerExecutors(); + } + + // Set service name in MDC to reference current working directed graph + MDC.put(MetricLogger.SERVICE_NAME, graph.getModule()+":"+graph.getRpc()+"/v"+graph.getVersion()); + + SvcLogicNode curNode = graph.getRootNode(); + LOG.info("About to execute graph " + graph.toString()); + + + + while (curNode != null) { + LOG.info("About to execute node # "+curNode.getNodeId()+" ("+curNode.getNodeType()+")"); + + SvcLogicNode nextNode = executeNode(curNode, ctx); + curNode = nextNode; + } + + return (ctx); + } + + + public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx) + throws SvcLogicException { + if (node == null) { + return (null); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Executing node " + node.getNodeId()); + } + + SvcLogicNodeExecutor executor = nodeExecutors.get(node.getNodeType()); + + if (executor != null) { + LOG.debug("Executing node executor for node type "+node.getNodeType()+" - "+executor.getClass().getName()); + return (executor.execute(this, node, ctx)); + } else { + if (LOG.isDebugEnabled()) { + LOG.debug(node.getNodeType() + " node not implemented"); + } + SvcLogicNode nextNode = node.getOutcomeValue("failure"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute failure branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no failure or Other branch found"); + } + } + return (nextNode); + } + + } + + @Override + public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException + { + SvcLogicStore store = SvcLogicActivator.getStore(); + + return (store.hasGraph(module, rpc, version, mode)); + } + + @Override + public Properties execute(String module, String rpc, String version, String mode, Properties props) + throws SvcLogicException { + return(execute(module, rpc, version, mode, props, null)); + } + + + @Override + public Properties execute(String module, String rpc, String version, String mode, + Properties props, DOMDataBroker domDataBroker) throws SvcLogicException { + + + // See if there is a service logic defined + // + SvcLogicStore store = SvcLogicActivator.getStore(); + + LOG.info("Fetching service logic from data store"); + SvcLogicGraph graph = store.fetch(module, rpc, version, mode); + + + + if (graph == null) + { + Properties retProps = new Properties(); + retProps.setProperty("error-code", "401"); + retProps.setProperty("error-message", "No service logic found for ["+module+","+rpc+","+version+","+mode+"]"); + return(retProps); + + } + + SvcLogicContext ctx = new SvcLogicContext(props); + ctx.setAttribute("currentGraph", graph.toString()); + ctx.setAttribute("X-ECOMP-RequestID", MDC.get("X-ECOMP-RequestID")); + ctx.setDomDataBroker(domDataBroker); + + execute(graph, ctx); + + return(ctx.toProperties()); + } + + + + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java new file mode 100644 index 00000000..ac0c428b --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SwitchNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(SwitchNodeExecutor.class); + + @Override + + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + + String testResult = evaluateNodeTest(node, ctx); + + if (LOG.isDebugEnabled()) { + LOG.debug("Executing switch node"); + + + LOG.debug("test expression (" + node.getAttribute("test") + + ") evaluates to " + testResult); + } + + SvcLogicNode nextNode = node.getOutcomeValue(testResult); + + if (LOG.isDebugEnabled()) { + if (nextNode != null) { + LOG.debug("Next node to execute is node " + nextNode.getNodeId()); + } else { + LOG.debug("No next node found"); + } + } + return (nextNode); + + } +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java new file mode 100644 index 00000000..48510e60 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java @@ -0,0 +1,135 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UpdateNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(UpdateNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + + String plugin = SvcLogicExpressionResolver.evaluate( + node.getAttribute("plugin"), node, ctx); + String resourceType = SvcLogicExpressionResolver.evaluate( + node.getAttribute("resource"), node, ctx); + String key = SvcLogicExpressionResolver.evaluateAsKey( + node.getAttribute("key"), node, ctx); + String pfx = SvcLogicExpressionResolver.evaluate( + node.getAttribute("pfx"), node, ctx); + + + Map parmMap = new HashMap(); + + Set> parmSet = node + .getParameterSet(); + boolean hasParms = false; + + for (Iterator> iter = parmSet + .iterator(); iter.hasNext();) { + hasParms = true; + Map.Entry curEnt = iter.next(); + String curName = curEnt.getKey(); + SvcLogicExpression curExpr = curEnt.getValue(); + if (curExpr != null) { + String curExprValue = SvcLogicExpressionResolver.evaluate( + curExpr, node, ctx); + + LOG.debug("Parameter " + curName + " = " + + curExpr.asParsedExpr() + " resolves to " + + curExprValue); + + parmMap.put(curName, curExprValue); + } + } + + String outValue = "failure"; + + if (LOG.isDebugEnabled()) { + LOG.debug("save node encountered - looking for resource class " + + plugin); + } + + + SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); + + + if (resourcePlugin != null) { + + try { + switch (resourcePlugin.update(resourceType, key, + parmMap, pfx, ctx)) { + case SUCCESS: + outValue = "success"; + break; + case NOT_FOUND: + outValue = "not-found"; + break; + case FAILURE: + default: + outValue = "failure"; + } + } catch (SvcLogicException e) { + LOG.error("Caught exception from resource plugin", e); + outValue = "failure"; + } + } else { + LOG.warn("Could not find SvcLogicResource object for plugin " + + plugin); + } + + SvcLogicNode nextNode = node.getOutcomeValue(outValue); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute " + outValue + " branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no "+outValue+" or Other branch found"); + } + } + return (nextNode); + } + +} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java new file mode 100644 index 00000000..bc3cc773 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.BreakNodeException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class WhileNodeExecutor extends SvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(WhileNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + + String testResult = evaluateNodeTest(node, ctx); + SvcLogicExpression silentFailureExpr = node.getAttribute("do"); + String doWhile = SvcLogicExpressionResolver.evaluate(silentFailureExpr, node, ctx); + if ("true".equals(doWhile)) { + LOG.debug("While loop will execute once regardless of expression because do is set to true"); + } + + try { + while ("true".equals(testResult) || "true".equals(doWhile)) { + if (!"true".equals(doWhile)) { + LOG.debug("Test expression (" + node.getAttribute("test") + ") evaluates to true, executing loop."); + } + int numOutcomes = node.getNumOutcomes() + 1; + for (int i = 0; i < numOutcomes; i++) { + SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1)); + if (nextNode != null) { + while (nextNode != null) { + nextNode = svc.executeNode(nextNode, ctx); + } + } else { + if ("true".equals(doWhile)) { + LOG.debug("Do executed, will only execute again if test expression is true."); + doWhile = "false"; + } + testResult = evaluateNodeTest(node, ctx); + LOG.debug("test expression (" + node.getAttribute("test") + ") evaluates to " + testResult); + } + } + } + LOG.debug("testResult was " + testResult + " which is not equal to true, exiting while loop."); + } catch (BreakNodeException e) { + LOG.debug("WhileNodeExecutor caught break"); + } + return (null); + } + +} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BlockNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BlockNodeExecutor.java deleted file mode 100644 index f83154d9..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BlockNodeExecutor.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BlockNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(BlockNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) - throws SvcLogicException { - - SvcLogicExpression atomicExpr = node.getAttribute("atomic"); - String atomicStr = SvcLogicExpressionResolver.evaluate(atomicExpr, node, ctx); - boolean isAtomic = "true".equalsIgnoreCase(atomicStr); - - // Initialize status to success so that at least one outcome will execute - ctx.setStatus("success"); - - int numOutcomes = node.getNumOutcomes(); - - for (int i = 0; i < numOutcomes; i++) { - if ("failure".equals(ctx.getStatus()) && isAtomic) { - LOG.info("Block - stopped executing nodes due to failure status"); - return(null); - } - - SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1)); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Block - executing outcome " + (i + 1)); - } - while (nextNode != null) - { - nextNode = svc.executeNode(nextNode, ctx); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("Block - done: no outcome " + (i + 1)); - } - } - } - - return (null); - } - - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BreakNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BreakNodeExecutor.java deleted file mode 100644 index 0f8719c8..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BreakNodeExecutor.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.BreakNodeException; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BreakNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory.getLogger(BreakNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { - String message = "BreakNodeExecutor encountered break with nodeId " + node.getNodeId(); - LOG.debug(message); - throw new BreakNodeException(message); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java deleted file mode 100644 index 7b79c19f..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicGraph; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicStore; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CallNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(CallNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) - throws SvcLogicException { - - String outValue = "not-found"; - - SvcLogicGraph myGraph = node.getGraph(); - - if (myGraph == null) - { - LOG.debug("execute: getGraph returned null"); - } - else - { - LOG.debug("execute: got SvcLogicGraph"); - } - - SvcLogicExpression moduleExpr = null; - - String module = null; - - moduleExpr = node.getAttribute("module"); - if (moduleExpr != null) - { - module = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx); - } - - if ((module == null) || (module.length() == 0)) - { - if (myGraph != null) - { - module = myGraph.getModule(); - LOG.debug("myGraph.getModule() returned "+module); - } - } - - SvcLogicExpression rpcExpr = null; - String rpc = null; - rpcExpr = node.getAttribute("rpc"); - if (rpcExpr != null) - { - rpc = SvcLogicExpressionResolver.evaluate(rpcExpr, node, ctx); - } - - if ((rpc == null) || (rpc.length() == 0)) - { - if (myGraph != null) - { - rpc = myGraph.getRpc(); - LOG.debug("myGraph.getRpc() returned "+rpc); - } - } - - String mode = null; - - moduleExpr = node.getAttribute("mode"); - if (moduleExpr != null) - { - mode = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx); - } - - if ((mode == null) || (mode.length() == 0)) - { - if (myGraph != null) - { - mode = myGraph.getMode(); - - LOG.debug("myGraph.getMode() returned "+mode); - } - } - - String version = null; - - moduleExpr = node.getAttribute("version"); - if (moduleExpr != null) - { - version = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx); - } - - String parentGraph = ctx.getAttribute("currentGraph"); - ctx.setAttribute("parentGraph", parentGraph); - - SvcLogicStore store = getStore(); - - if (store != null) { - SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode); - LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString()); - ctx.setAttribute("currentGraph", calledGraph.toString()); - if (calledGraph != null) { - svc.execute(calledGraph, ctx); - - outValue = ctx.getStatus(); - } else { - LOG.error("Could not find service logic for [" + module + "," + rpc + "," + version + "," + mode + "]"); - } - } - else - { - LOG.debug("Could not get SvcLogicStore reference"); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - ctx.setAttribute("currentGraph", parentGraph); - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("no " + outValue + " or Other branch found"); - } - } - ctx.setAttribute("currentGraph", parentGraph); - ctx.setAttribute("parentGraph", null); - - return (nextNode); - - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ConfigureNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ConfigureNodeExecutor.java deleted file mode 100644 index a3f2874f..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ConfigureNodeExecutor.java +++ /dev/null @@ -1,248 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.openecomp.sdnc.sli.SvcLogicAdaptor; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ConfigureNodeExecutor extends SvcLogicNodeExecutor { - private static final Logger LOG = LoggerFactory - .getLogger(ConfigureNodeExecutor.class); - - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String adaptorName = SvcLogicExpressionResolver.evaluate( - node.getAttribute("adaptor"), node, ctx); - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("configure node encountered - looking for adaptor " - + adaptorName); - } - - SvcLogicAdaptor adaptor = getAdaptor(adaptorName); - - if (adaptor != null) { - String activate = SvcLogicExpressionResolver.evaluate( - node.getAttribute("activate"), node, ctx); - String key = SvcLogicExpressionResolver.evaluate( - node.getAttribute("key"), node, ctx); - - Map parmMap = new HashMap(); - - Set> parmSet = node - .getParameterSet(); - boolean hasParms = false; - - for (Iterator> iter = parmSet - .iterator(); iter.hasNext();) { - hasParms = true; - Map.Entry curEnt = iter.next(); - String curName = curEnt.getKey(); - SvcLogicExpression curExpr = curEnt.getValue(); - String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx); - - LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue); - - parmMap.put(curName,curExprValue); - } - - if (hasParms) { - SvcLogicAdaptor.ConfigStatus confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - - try { - confStatus = adaptor.configure(key, parmMap, ctx); - } catch (Exception e) { - LOG.warn("Caught exception from "+adaptorName+".configure", e); - confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - } - - switch (confStatus) { - case SUCCESS: - outValue = "success"; - if ((activate != null) && (activate.length() > 0)) { - if ("true".equalsIgnoreCase(activate)) { - SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - - try { - activateStatus = adaptor.activate(key, ctx); - } catch (Exception e) { - - LOG.warn("Caught exception from "+adaptorName+".activate", e); - activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - } - switch (activateStatus) { - case SUCCESS: - break; - case ALREADY_ACTIVE: - outValue = "already-active"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case NOT_READY: - outValue = "not-ready"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } else if ("false".equalsIgnoreCase(activate)) { - SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - - try { - deactivateStatus = adaptor.deactivate(key, ctx); - } catch (Exception e) { - - LOG.warn("Caught exception from "+adaptorName+".deactivate", e); - deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - } - switch (deactivateStatus) { - case SUCCESS: - break; - case ALREADY_ACTIVE: - outValue = "already-active"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case NOT_READY: - outValue = "not-ready"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } - } - break; - case ALREADY_ACTIVE: - outValue = "already-active"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case NOT_READY: - outValue = "not-ready"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } else { - if ((activate != null) && (activate.length() > 0)) { - if ("true".equalsIgnoreCase(activate)) { - SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - try { - activateStatus = adaptor.activate(key, ctx); - } catch (Exception e) { - LOG.warn("Caught exception from "+adaptorName+".activate", e); - activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - } - switch (activateStatus) { - case SUCCESS: - outValue = "success"; - break; - case ALREADY_ACTIVE: - outValue = "already-active"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case NOT_READY: - outValue = "not-ready"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } else if ("false".equalsIgnoreCase(activate)) { - SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - - try { - deactivateStatus = adaptor.deactivate(key, ctx); - } catch (Exception e) { - LOG.warn("Caught exception from "+adaptorName+".deactivate", e); - deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE; - } - switch (deactivateStatus) { - case SUCCESS: - outValue = "success"; - break; - case ALREADY_ACTIVE: - outValue = "already-active"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case NOT_READY: - outValue = "not-ready"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } - } else { - LOG.warn("Nothing to configure - no parameters passed, and activate attribute is not set"); - outValue = "success"; - } - } - } else { - if (LOG.isWarnEnabled()) { - LOG.warn("Adaptor for " + adaptorName + " not found"); - } - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("no " + outValue + " or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java deleted file mode 100644 index 081cbcfa..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DeleteNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(DeleteNodeExecutor.class); - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("delete node encountered - looking for resource class " - + plugin); - } - - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - if (resourcePlugin != null) { - - try { - - switch (resourcePlugin.delete(resourceType, key, ctx)) { - case SUCCESS: - outValue = "success"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java deleted file mode 100644 index 7ae4d0db..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java +++ /dev/null @@ -1,161 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExecuteNodeExecutor extends SvcLogicNodeExecutor { - private static final Logger LOG = LoggerFactory - .getLogger(ExecuteNodeExecutor.class); - - private static final String pluginErrorMessage = "Could not execute plugin. SvcLogic status will be set to failure."; - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String pluginName = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("execute node encountered - looking for plugin " - + pluginName); - } - - SvcLogicJavaPlugin plugin = getSvcLogicJavaPlugin(pluginName); - - if (plugin == null) { - outValue = "not-found"; - } else { - - String methodName = evaluate(node.getAttribute("method"), node, ctx); - - Class pluginClass = plugin.getClass(); - - Method pluginMethod = null; - - try { - pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class); - } catch (NoSuchMethodException e) { - LOG.error(pluginErrorMessage, e); - } - - if (pluginMethod == null) { - outValue = "unsupported-method"; - } else { - try { - - Map parmMap = new HashMap(); - - Set> parmSet = node - .getParameterSet(); - - for (Iterator> iter = parmSet - .iterator(); iter.hasNext();) { - Map.Entry curEnt = iter.next(); - String curName = curEnt.getKey(); - SvcLogicExpression curExpr = curEnt.getValue(); - String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx); - - LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue); - - parmMap.put(curName,curExprValue); - } - - Object o = pluginMethod.invoke(plugin, parmMap, ctx); - String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); - - outValue = mapOutcome(o, emitsOutcome); - - } catch (InvocationTargetException e) { - if(e.getCause() != null){ - LOG.error(pluginErrorMessage, e.getCause()); - }else{ - LOG.error(pluginErrorMessage, e); - } - outValue = "failure"; - ctx.setStatus("failure"); - } catch (IllegalAccessException e) { - LOG.error(pluginErrorMessage, e); - outValue = "failure"; - ctx.setStatus("failure"); - } catch (IllegalArgumentException e) { - LOG.error(pluginErrorMessage, e); - outValue = "failure"; - ctx.setStatus("failure"); - } - } - - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("no " + outValue + " or Other branch found"); - } - } - return (nextNode); - } - - protected String evaluate(SvcLogicExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { - return SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx); - } - - public String mapOutcome(Object o, String emitsOutcome) { - if (emitsOutcome != null) { - Boolean nodeEmitsOutcome = Boolean.valueOf(emitsOutcome); - if (nodeEmitsOutcome) { - return (String) o; - } else { - return "success"; - } - - } else { - return "success"; - } - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java deleted file mode 100644 index 688a86e5..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExistsNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(ExistsNodeExecutor.class); - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - String pfx = SvcLogicExpressionResolver.evaluate( - node.getAttribute("pfx"), node, ctx); - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("exists node encountered - looking for resource class " - + plugin); - } - - - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - - if (resourcePlugin != null) { - - try { - - switch (resourcePlugin.exists(resourceType, key, pfx, ctx)) { - case SUCCESS: - outValue = "true"; - break; - case NOT_FOUND: - outValue = "false"; - break; - case FAILURE: - default: - outValue = "false"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java deleted file mode 100644 index e9fdc55e..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.BreakNodeException; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ForNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(ForNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - SvcLogicExpression atomicExpr = node.getAttribute("atomic"); - String atomicStr = SvcLogicExpressionResolver.evaluate(atomicExpr, node, ctx); - boolean isAtomic = !("false".equalsIgnoreCase(atomicStr)); - - int numOutcomes = node.getNumOutcomes(); - String idxVar = SvcLogicExpressionResolver.evaluate( - node.getAttribute("index"), node, ctx); - String startVal = SvcLogicExpressionResolver.evaluate( - node.getAttribute("start"), node, ctx); - String endVal = SvcLogicExpressionResolver.evaluate( - node.getAttribute("end"), node, ctx); - - LOG.debug("Executing "+ (isAtomic ? "atomic" : "non-atomic") + " for loop - for (int " + idxVar + " = " + startVal - + "; " + idxVar + " < " + endVal + "; " + idxVar + "++)"); - - int startIdx = 0; - int endIdx = 0; - - try { - startIdx = Integer.parseInt(startVal); - endIdx = Integer.parseInt(endVal); - } catch (NumberFormatException e) { - SvcLogicExpression silentFailureExpr = node.getAttribute("silentFailure"); - String silentFailure = SvcLogicExpressionResolver.evaluate(silentFailureExpr, node, ctx); - boolean isSilentFailure = Boolean.parseBoolean(silentFailure); - String message = "Invalid index values [" + startVal + "," + endVal + "]"; - if(!isSilentFailure){ - throw new SvcLogicException(message); - }else{ - LOG.debug(message + ". Not exiting because silentFailure was set to true."); - return(null); - } - } - - try { - for (int ctr = startIdx; ctr < endIdx; ctr++) { - - ctx.setAttribute(idxVar, "" + ctr); - - for (int i = 0; i < numOutcomes; i++) { - - if ("failure".equals(ctx.getStatus()) && isAtomic) { - LOG.info("For - stopped executing nodes due to failure status"); - return(null); - } - - SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1)); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("For - executing outcome " + (i + 1)); - } - SvcLogicNode innerNextNode = nextNode; - while (innerNextNode != null) { - innerNextNode = svc.executeNode(innerNextNode, ctx); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("For - done: no outcome " + (i + 1)); - } - } - } - } - } catch (BreakNodeException br) { - LOG.debug("ForNodeExecutor caught break"); - } - return (null); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java deleted file mode 100644 index d431a18a..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java +++ /dev/null @@ -1,134 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GetResourceNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(GetResourceNodeExecutor.class); - - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - String pfx = SvcLogicExpressionResolver.evaluate( - node.getAttribute("pfx"), node, ctx); - - String localOnlyStr = SvcLogicExpressionResolver.evaluate( - node.getAttribute("local-only"), node, ctx); - - // Note: for get-resource, only refresh from A&AI if the DG explicitly set - // local-only to false. Otherwise, just read from local database. - boolean localOnly = true; - - if ("false".equalsIgnoreCase(localOnlyStr)) { - localOnly = false; - } - - SvcLogicExpression selectExpr = node.getAttribute("select"); - String select = null; - - if (selectExpr != null) { - select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node, - ctx); - } - - SvcLogicExpression orderByExpr = node.getAttribute("order-by"); - String orderBy = null; - - if (orderByExpr != null) { - orderBy = SvcLogicExpressionResolver.evaluateAsKey(orderByExpr, node, - ctx); - } - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug(node.getNodeType() - + " node encountered - looking for resource class " - + plugin); - } - - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - - if (resourcePlugin != null) { - - try { - switch (resourcePlugin.query(resourceType, localOnly, select, key, - pfx, orderBy, ctx)) { - case SUCCESS: - outValue = "success"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java deleted file mode 100644 index 0df73682..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class IsAvailableNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(IsAvailableNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - String pfx = SvcLogicExpressionResolver.evaluate( - node.getAttribute("pfx"), node, ctx); - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("is-available node encountered - looking for resource class " - + plugin); - } - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - - - if (resourcePlugin != null) { - try { - switch (resourcePlugin.isAvailable(resourceType, key, pfx, ctx)) { - case SUCCESS: - outValue = "true"; - break; - case NOT_FOUND: - outValue = "false"; - break; - case FAILURE: - default: - outValue = "false"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java deleted file mode 100644 index 4c5ee068..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java +++ /dev/null @@ -1,1186 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; - -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; -import org.opendaylight.yangtools.yang.binding.Identifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MdsalHelper { - - private static final Logger LOG = LoggerFactory.getLogger(MdsalHelper.class); - private static Properties yangMappingProperties = new Properties(); - - @Deprecated - public static void setProperties(Properties input) { - setYangMappingProperties(input); - } - - public static void setYangMappingProperties(Properties properties) { - for (Object propNameObj : properties.keySet()) { - String propName = (String) propNameObj; - MdsalHelper.yangMappingProperties.setProperty(propName, properties.getProperty(propName)); - } - } - - public static void loadProperties(String propertiesFile) { - File file = new File(propertiesFile); - Properties properties = new Properties(); - InputStream input = null; - if (file.isFile() && file.canRead()) { - try { - input = new FileInputStream(file); - properties.load(input); - MdsalHelper.setYangMappingProperties(properties); - LOG.info("Loaded properties from " + propertiesFile); - } catch (Exception e) { - LOG.error("Failed to load properties " + propertiesFile + "\n", e); - } finally { - if (input != null) { - try { - input.close(); - } catch (IOException e) { - LOG.error("Failed to close properties file " + propertiesFile + "\n", e); - } - } - } - }else{ - LOG.error("Failed to load the properties file " + propertiesFile + "\n"); - LOG.error("Either isFile or canRead returned false for " + propertiesFile + "\n"); - } - } - - public static Properties toProperties(Properties props, Object fromObj) { - Class fromClass = null; - - if (fromObj != null) { - fromClass = fromObj.getClass(); - } - return (toProperties(props, "", fromObj, fromClass)); - } - - public static Properties toProperties(Properties props, String pfx, Object fromObj) { - Class fromClass = null; - - if (fromObj != null) { - fromClass = fromObj.getClass(); - } - - return (toProperties(props, pfx, fromObj, fromClass)); - } - - public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass) { - - if (fromObj == null) { - return (props); - } - - String simpleName = fromClass.getSimpleName(); - - LOG.trace("Extracting properties from " + fromClass.getName() + " class"); - if (fromObj instanceof List) { - - // Class is a List. List should contain yang-generated classes. - LOG.trace(fromClass.getName() + " is a List"); - - List fromList = (List) fromObj; - - for (int i = 0; i < fromList.size(); i++) { - toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass); - } - props.setProperty(pfx + "_length", "" + fromList.size()); - - } else if (isYangGenerated(fromClass)) { - // Class is yang generated. - LOG.trace(fromClass.getName() + " is a Yang-generated class"); - - String propNamePfx = null; - - // If called from a list (so prefix ends in ']'), don't - // add class name again - if (pfx.endsWith("]")) { - propNamePfx = pfx; - } else { - if ((pfx != null) && (pfx.length() > 0)) { - propNamePfx = pfx; - } else { - propNamePfx = toLowerHyphen(fromClass.getSimpleName()); - } - - if (propNamePfx.endsWith("-builder")) { - propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length()); - } - - if (propNamePfx.endsWith("-impl")) { - propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-impl".length()); - } - } - - // Iterate through getter methods to figure out values we need to - // save from - - int numGetters = 0; - String lastGetterName = null; - String propVal = null; - - for (Method m : fromClass.getMethods()) { - if (isGetter(m)) { - - numGetters++; - lastGetterName = m.getName(); - - Class returnType = m.getReturnType(); - String fieldName; - if (m.getName().startsWith("get")) { - fieldName = toLowerHyphen(m.getName().substring(3)); - } else { - - fieldName = toLowerHyphen(m.getName().substring(2)); - } - - fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1); - - // Is the return type a yang generated class? - if (isYangGenerated(returnType)) { - // Is it an enum? - if (returnType.isEnum()) { - // Return type is a typedef. Save its value. - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - - Object retValue = m.invoke(fromObj); - - if (!isAccessible) { - m.setAccessible(isAccessible); - } - if (retValue != null) { - String propName = propNamePfx + "." + fieldName; - propVal = retValue.toString(); - props.setProperty(propName, mapEnumeratedValue(fieldName, propVal)); - } - } catch (Exception e) { - LOG.error("Caught exception trying to convert Yang-generated enum returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } else if (isIpv4Address(returnType)) { - // Save its value - try { - String propName = propNamePfx + "." + fieldName; - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - Ipv4Address retValue = (Ipv4Address) m.invoke(fromObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - - if (retValue != null) { - propVal = retValue.getValue().toString(); - LOG.debug("Setting property " + propName + " to " + propVal); - props.setProperty(propName, propVal); - - } - } catch (Exception e) { - LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } else if (isIpv6Address(returnType)) { - // Save its value - try { - String propName = propNamePfx + "." + fieldName; - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - Ipv6Address retValue = (Ipv6Address) m.invoke(fromObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - - if (retValue != null) { - propVal = retValue.getValue().toString(); - LOG.debug("Setting property " + propName + " to " + propVal); - props.setProperty(propName, propVal); - - } - } catch (Exception e) { - LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } else if (isIpAddress(returnType)) { - // Save its value - try { - String propName = propNamePfx + "." + fieldName; - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - IpAddress retValue = (IpAddress) m.invoke(fromObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - - if (retValue != null) { - propVal = new String(retValue.getValue()); - LOG.debug("Setting property " + propName + " to " + propVal); - props.setProperty(propName, propVal); - - } - } catch (Exception e) { - LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } else if (isIpPrefix(returnType)) { - // Save its value - try { - String propName = propNamePfx + "." + fieldName; - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - IpPrefix retValue = (IpPrefix) m.invoke(fromObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - - if (retValue != null) { - propVal = new String(retValue.getValue()); - LOG.debug("Setting property " + propName + " to " + propVal); - props.setProperty(propName, propVal); - - } - } catch (Exception e) { - LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } else { - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - Object retValue = m.invoke(fromObj); - - if (retValue instanceof byte[]) { - LOG.trace(m.getName() + " returns a byte[]"); - retValue = new String((byte[]) retValue, "UTF-8"); - LOG.trace("Converted byte array " + propNamePfx + "." + fieldName + "to string " + retValue); - } - if (!isAccessible) { - m.setAccessible(isAccessible); - } - if (retValue != null) { - toProperties(props, propNamePfx + "." + fieldName, retValue, returnType); - } - } catch (Exception e) { - - if (m.getName().equals("getKey")) { - LOG.trace("Caught " + e.getClass().getName() + " exception trying to convert results from getKey() - ignoring"); - } else { - LOG.error("Caught exception trying to convert Yang-generated class returned by" + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } - } - } else if (returnType.equals(Class.class)) { - - LOG.trace(m.getName() + " returns a Class object - not interested"); - - } else if (List.class.isAssignableFrom(returnType)) { - - // This getter method returns a list. - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - Object retList = m.invoke(fromObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - // Figure out what type of elements are stored in - // this array. - Type paramType = m.getGenericReturnType(); - Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0]; - toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType); - } catch (Exception e) { - LOG.error("Caught exception trying to convert List returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - - } else { - - // Method returns something that is not a List and not - // yang-generated. - // Save its value - try { - String propName = propNamePfx + "." + fieldName; - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - Object propValObj = m.invoke(fromObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - - if (propValObj != null) { - if (propValObj instanceof byte[]) { - LOG.trace(m.getName() + " returns a byte[]"); - propVal = new String((byte[]) propValObj, "UTF-8"); - LOG.trace("Converted byte array " + propNamePfx + "." + fieldName + "to string " + propVal); - - } else { - propVal = propValObj.toString(); - } - LOG.debug("Setting property " + propName + " to " + propVal); - props.setProperty(propName, propVal); - - } - } catch (Exception e) { - if (m.getName().equals("getKey")) { - LOG.trace("Caught " + e.getClass().getName() + " exception trying to convert results from getKey() - ignoring"); - } else { - LOG.error("Caught exception trying to convert value returned by" + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } - } - - } - } - - // End of method loop. If there was only one getter, named - // "getValue", then - // set value identified by "prefix" to that one value. - if ((numGetters == 1) && ("getValue".equals(lastGetterName))) { - LOG.trace("getValueFIX : " + propNamePfx + " only has getValue() getter - setting " + propNamePfx + " = " + propVal); - props.setProperty(propNamePfx, propVal); - } else { - LOG.trace("getValueFIX : " + propNamePfx + " has " + numGetters + " getter(s), last one found was " + lastGetterName); - - } - - } else { - // Class is not yang generated and not a list - // It must be an element of a leaf list - set "prefix" to value - String fromVal = null; - if (fromObj instanceof byte[]) { - try { - fromVal = new String((byte[]) fromObj, "UTF-8"); - LOG.trace("Converted byte array " + pfx + "to string " + fromVal); - } catch (Exception e) { - LOG.warn("Caught exception trying to convert " + pfx + " from byte[] to String", e); - fromVal = fromObj.toString(); - } - - } else { - fromVal = fromObj.toString(); - } - LOG.debug("Setting property " + pfx + " to " + fromVal); - props.setProperty(pfx, fromVal); - } - - return (props); - } - - public static Object toBuilder(Properties props, Object toObj) { - - return (toBuilder(props, "", toObj)); - } - - public static List toList(Properties props, String pfx, List toObj, Class elemType) { - - int maxIdx = -1; - boolean foundValue = false; - - LOG.trace("Saving properties to List<" + elemType.getName() + "> from " + pfx); - - if (props.contains(pfx + "_length")) { - try { - int listLength = Integer.parseInt(props.getProperty(pfx + "_length")); - - if (listLength > 0) { - maxIdx = listLength - 1; - } - } catch (Exception e) { - // Ignore exception - } - } - - if (maxIdx == -1) { - // Figure out array size - for (Object pNameObj : props.keySet()) { - String key = (String) pNameObj; - - if (key.startsWith(pfx + "[")) { - String idxStr = key.substring(pfx.length() + 1); - int endloc = idxStr.indexOf("]"); - if (endloc != -1) { - idxStr = idxStr.substring(0, endloc); - } - - try { - int curIdx = Integer.parseInt(idxStr); - if (curIdx > maxIdx) { - maxIdx = curIdx; - } - } catch (Exception e) { - LOG.error("Illegal subscript in property " + key); - } - - } - } - } - - LOG.trace(pfx + " has max index of " + maxIdx); - for (int i = 0; i <= maxIdx; i++) { - - String curBase = pfx + "[" + i + "]"; - - if (isYangGenerated(elemType)) { - String builderName = elemType.getName() + "Builder"; - try { - Class builderClass = Class.forName(builderName); - Object builderObj = builderClass.newInstance(); - Method buildMethod = builderClass.getMethod("build"); - builderObj = toBuilder(props, curBase, builderObj, true); - if (builderObj != null) { - LOG.trace("Calling " + builderObj.getClass().getName() + "." + buildMethod.getName() + "()"); - Object builtObj = buildMethod.invoke(builderObj); - toObj.add(builtObj); - foundValue = true; - } - - } catch (ClassNotFoundException e) { - LOG.warn("Could not find builder class " + builderName, e); - } catch (Exception e) { - LOG.error("Caught exception trying to populate list from " + pfx); - } - } else { - // Must be a leaf list - String curValue = props.getProperty(curBase, ""); - - toObj.add(curValue); - - if ((curValue != null) && (curValue.length() > 0)) { - foundValue = true; - } - } - - } - - if (foundValue) { - return (toObj); - } else { - return (null); - } - - } - - public static Object toBuilder(Properties props, String pfx, Object toObj) { - return (toBuilder(props, pfx, toObj, false)); - } - - public static Object toBuilder(Properties props, String pfx, Object toObj, boolean preservePfx) { - Class toClass = toObj.getClass(); - boolean foundValue = false; - - LOG.trace("Saving properties to " + toClass.getName() + " class from " + pfx); - - Ipv4Address addr; - - if (isYangGenerated(toClass)) { - // Class is yang generated. - LOG.trace(toClass.getName() + " is a Yang-generated class"); - - String propNamePfx = null; - if (preservePfx) { - propNamePfx = pfx; - } else { - - if ((pfx != null) && (pfx.length() > 0)) { - propNamePfx = pfx + "." + toLowerHyphen(toClass.getSimpleName()); - } else { - propNamePfx = toLowerHyphen(toClass.getSimpleName()); - } - - if (propNamePfx.endsWith("-builder")) { - propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length()); - } - - if (propNamePfx.endsWith("-impl")) { - propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-impl".length()); - } - } - - if (toObj instanceof Identifier) { - LOG.trace(toClass.getName() + " is a Key - skipping"); - return (toObj); - } - - // Iterate through getter methods to figure out values we need to - // set - - for (Method m : toClass.getMethods()) { - if (isSetter(m)) { - Class paramTypes[] = m.getParameterTypes(); - Class paramClass = paramTypes[0]; - - String fieldName = toLowerHyphen(m.getName().substring(3)); - fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1); - - String propName = propNamePfx + "." + fieldName; - - String paramValue = props.getProperty(propName); - if (paramValue == null) { - LOG.trace(propName + " is unset"); - } else { - LOG.trace(propName + " = " + paramValue); - } - - // Is the return type a yang generated class? - if (isYangGenerated(paramClass)) { - // Is it an enum? - if (paramClass.isEnum()) { - - LOG.trace(m.getName() + " expects an Enum"); - // Param type is a typedef. - if ((paramValue != null) && (paramValue.length() > 0)) { - Object paramObj = null; - - try { - paramObj = Enum.valueOf(paramClass, toJavaEnum(paramValue)); - } catch (Exception e) { - LOG.error("Caught exception trying to convert field " + propName + " to enum " + paramClass.getName(), e); - } - - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); - m.invoke(toObj, paramObj); - - if (!isAccessible) { - m.setAccessible(isAccessible); - } - foundValue = true; - - } catch (Exception e) { - LOG.error("Caught exception trying to create Yang-generated enum expected by" + toClass.getName() + "." + m.getName() + "() from Properties entry", e); - } - } - } else { - - String simpleName = paramClass.getSimpleName(); - - if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress".equals(simpleName)) { - - if ((paramValue != null) && (paramValue.length() > 0)) { - try { - IpAddress ipAddr = IpAddressBuilder.getDefaultInstance(paramValue); - - if ("Ipv4Address".equals(simpleName)) { - m.invoke(toObj, ipAddr.getIpv4Address()); - } else if ("Ipv6Address".equals(simpleName)) { - m.invoke(toObj, ipAddr.getIpv6Address()); - - } else { - m.invoke(toObj, ipAddr); - } - foundValue = true; - } catch (Exception e) { - LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + "(" + paramValue + ")", e); - - } - } else { - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); - m.invoke(toObj, paramValue); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - foundValue = true; - - } catch (Exception e) { - LOG.error("Caught exception trying to call " + toClass.getName() + "." + m.getName() + "() with Properties entry", e); - } - } - } else if ("IpPrefix".equals(simpleName)) { - if ((paramValue != null) && (paramValue.length() > 0)) { - try { - IpPrefix ipPrefix = IpPrefixBuilder.getDefaultInstance(paramValue); - m.invoke(toObj, ipPrefix); - foundValue = true; - } catch (Exception e) { - LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + "(" + paramValue + ")", e); - } - } - } else { - // setter expects a yang-generated class. Need - // to - // create a builder to set it. - - String builderName = paramClass.getName() + "Builder"; - Class builderClass = null; - Object builderObj = null; - Object paramObj = null; - - Object constObj = null; - - LOG.trace(m.getName() + " expects a yang-generated class - looking for builder " + builderName); - try { - builderClass = Class.forName(builderName); - builderObj = builderClass.newInstance(); - paramObj = toBuilder(props, propNamePfx, builderObj); - } catch (ClassNotFoundException e) { - - if (paramValue == null) { - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(null)"); - m.invoke(toObj, new Object[] { null }); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - foundValue = true; - - } catch (Exception e1) { - LOG.error("Caught exception trying to cally" + toClass.getName() + "." + m.getName() + "() with Properties entry", e1); - } - } else { - try { - // See if I can find a constructor I - // can - // use - Constructor[] constructors = paramClass.getConstructors(); - // Is there a String constructor? - for (Constructor c : constructors) { - Class[] cParms = c.getParameterTypes(); - if ((cParms != null) && (cParms.length == 1)) { - if (String.class.isAssignableFrom(cParms[0])) { - constObj = c.newInstance(paramValue); - } - } - } - - if (constObj == null) { - // Is there a Long constructor? - for (Constructor c : constructors) { - Class[] cParms = c.getParameterTypes(); - if ((cParms != null) && (cParms.length == 1)) { - if (Long.class.isAssignableFrom(cParms[0])) { - constObj = c.newInstance(Long.parseLong(paramValue)); - } - } - } - - } - - if (constObj == null) { - - // Last chance - see if - // parameter class has a static - // method - // getDefaultInstance(String) - try { - Method gm = paramClass.getMethod("getDefaultInstance", String.class); - - int gmodifier = gm.getModifiers(); - if (Modifier.isStatic(gmodifier)) { - // Invoke static - // getDefaultInstance(String) - paramObj = gm.invoke(null, paramValue); - } - - } catch (Exception gme) { - // Ignore exceptions - } - } - - } catch (Exception e1) { - LOG.warn("Could not find a suitable constructor for " + paramClass.getName(), e1); - } - - if (constObj == null) { - LOG.warn("Could not find builder class " + builderName + " and could not find a String or Long constructor or static getDefaultInstance(String) - trying just to set passing paramValue"); - - } - } - } catch (Exception e) { - LOG.error("Caught exception trying to create builder " + builderName, e); - } - - if (paramObj != null) { - - try { - - Method buildMethod = builderClass.getMethod("build"); - LOG.trace("Calling " + paramObj.getClass().getName() + "." + buildMethod.getName() + "()"); - Object builtObj = buildMethod.invoke(paramObj); - - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "()"); - m.invoke(toObj, builtObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - foundValue = true; - - } catch (Exception e) { - LOG.error("Caught exception trying to set Yang-generated class expected by" + toClass.getName() + "." + m.getName() + "() from Properties entry", e); - } - } else { - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - - if (constObj != null) { - - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + constObj.toString() + ")"); - m.invoke(toObj, constObj); - } else { - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); - m.invoke(toObj, paramValue); - - } - if (!isAccessible) { - m.setAccessible(isAccessible); - } - foundValue = true; - - } catch (Exception e) { - LOG.error("Caught exception trying to convert value returned by" + toClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } - } - } - } else { - - // Setter's argument is not a yang-generated class. See - // if it is a List. - - if (List.class.isAssignableFrom(paramClass)) { - - LOG.trace("Parameter class " + paramClass.getName() + " is a List"); - - // Figure out what type of args are in List and pass - // that to toList(). - - Type paramType = m.getGenericParameterTypes()[0]; - Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0]; - Object paramObj = new LinkedList(); - try { - paramObj = toList(props, propName, (List) paramObj, (Class) elementType); - } catch (Exception e) { - LOG.error("Caught exception trying to create list expected as argument to " + toClass.getName() + "." + m.getName()); - } - - if (paramObj != null) { - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); - m.invoke(toObj, paramObj); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - foundValue = true; - - } catch (Exception e) { - LOG.error("Caught exception trying to convert List returned by" + toClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } - } else { - - // Setter expects something that is not a List and - // not yang-generated. Just pass the parameter value - - LOG.trace("Parameter class " + paramClass.getName() + " is not a yang-generated class or a List"); - - if ((paramValue != null) && (paramValue.length() > 0)) { - - Object constObj = null; - - try { - // See if I can find a constructor I can use - Constructor[] constructors = paramClass.getConstructors(); - // Is there a String constructor? - for (Constructor c : constructors) { - Class[] cParms = c.getParameterTypes(); - if ((cParms != null) && (cParms.length == 1)) { - if (String.class.isAssignableFrom(cParms[0])) { - constObj = c.newInstance(paramValue); - } - } - } - - if (constObj == null) { - // Is there a Long constructor? - for (Constructor c : constructors) { - Class[] cParms = c.getParameterTypes(); - if ((cParms != null) && (cParms.length == 1)) { - if (Long.class.isAssignableFrom(cParms[0])) { - constObj = c.newInstance(Long.parseLong(paramValue)); - } - } - } - - } - - if (constObj != null) { - try { - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + constObj + ")"); - m.invoke(toObj, constObj); - foundValue = true; - } catch (Exception e2) { - LOG.error("Caught exception trying to call " + m.getName(), e2); - } - } else { - try { - boolean isAccessible = m.isAccessible(); - if (!isAccessible) { - m.setAccessible(true); - } - LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")"); - m.invoke(toObj, paramValue); - if (!isAccessible) { - m.setAccessible(isAccessible); - } - foundValue = true; - - } catch (Exception e) { - LOG.error("Caught exception trying to convert value returned by" + toClass.getName() + "." + m.getName() + "() to Properties entry", e); - } - } - } catch (Exception e1) { - LOG.warn("Could not find a suitable constructor for " + paramClass.getName(), e1); - } - - } - } - } - } // End of section handling "setter" method - } // End of loop through Methods - } // End of section handling yang-generated class - - if (foundValue) { - return (toObj); - } else { - return (null); - } - } - - public static void printPropertyList(PrintStream pstr, String pfx, Class toClass) { - boolean foundValue = false; - - LOG.trace("Analyzing " + toClass.getName() + " class : pfx " + pfx); - - if (isYangGenerated(toClass) && (!Identifier.class.isAssignableFrom(toClass))) { - // Class is yang generated. - LOG.trace(toClass.getName() + " is a Yang-generated class"); - - if (toClass.getName().endsWith("Key")) { - if (Identifier.class.isAssignableFrom(toClass)) { - LOG.trace(Identifier.class.getName() + " is assignable from " + toClass.getName()); - } else { - - LOG.trace(Identifier.class.getName() + " is NOT assignable from " + toClass.getName()); - } - } - - String propNamePfx = null; - if (pfx.endsWith("]")) { - propNamePfx = pfx; - } else { - - if ((pfx != null) && (pfx.length() > 0)) { - propNamePfx = pfx + "." + toLowerHyphen(toClass.getSimpleName()); - } else { - propNamePfx = toLowerHyphen(toClass.getSimpleName()); - } - - if (propNamePfx.endsWith("-builder")) { - propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length()); - } - - if (propNamePfx.endsWith("-impl")) { - propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-impl".length()); - } - } - - // Iterate through getter methods to figure out values we need to - // set - - for (Method m : toClass.getMethods()) { - LOG.trace("Is " + m.getName() + " method a getter?"); - if (isGetter(m)) { - LOG.trace(m.getName() + " is a getter"); - Class returnClass = m.getReturnType(); - - String fieldName = toLowerHyphen(m.getName().substring(3)); - fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1); - - String propName = propNamePfx + "." + fieldName; - - // Is the return type a yang generated class? - if (isYangGenerated(returnClass)) { - // Is it an enum? - if (returnClass.isEnum()) { - - LOG.trace(m.getName() + " is an Enum"); - pstr.print("\n\n * " + propName); - - } else { - - String simpleName = returnClass.getSimpleName(); - - if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress".equals(simpleName) || "IpPrefix".equals(simpleName)) { - LOG.trace(m.getName() + " is an " + simpleName); - pstr.print("\n\n * " + propName); - } else { - printPropertyList(pstr, propNamePfx, returnClass); - } - - } - } else { - - // Setter's argument is not a yang-generated class. See - // if it is a List. - - if (List.class.isAssignableFrom(returnClass)) { - - LOG.trace("Parameter class " + returnClass.getName() + " is a List"); - - // Figure out what type of args are in List and pass - // that to toList(). - - Type returnType = m.getGenericReturnType(); - Type elementType = ((ParameterizedType) returnType).getActualTypeArguments()[0]; - Class elementClass = (Class) elementType; - LOG.trace("Calling printPropertyList on list type (" + elementClass.getName() + "), pfx is (" + pfx + "), toClass is (" + toClass.getName() + ")"); - printPropertyList(pstr, propNamePfx + "." + toLowerHyphen(elementClass.getSimpleName()) + "[]", elementClass); - - } else if (!returnClass.equals(Class.class)) { - - // Setter expects something that is not a List and - // not yang-generated. Just pass the parameter value - - LOG.trace("Parameter class " + returnClass.getName() + " is not a yang-generated class or a List"); - - pstr.print("\n\n * " + propName); - - } - } - } // End of section handling "setter" method - } // End of loop through Methods - } // End of section handling yang-generated class - - } - - public static boolean isYangGenerated(Class c) { - if (c == null) { - return (false); - } else { - return (c.getName().startsWith("org.opendaylight.yang.gen.")); - } - } - - public static boolean isIpPrefix(Class c) { - - if (c == null) { - return (false); - } - String simpleName = c.getSimpleName(); - return ("IpPrefix".equals(simpleName)); - } - - public static boolean isIpv4Address(Class c) { - - if (c == null) { - return (false); - } - String simpleName = c.getSimpleName(); - return ("Ipv4Address".equals(simpleName)); - } - - public static boolean isIpv6Address(Class c) { - - if (c == null) { - return (false); - } - String simpleName = c.getSimpleName(); - return ("Ipv6Address".equals(simpleName)); - } - - public static boolean isIpAddress(Class c) { - - if (c == null) { - return (false); - } - String simpleName = c.getSimpleName(); - return ("IpAddress".equals(simpleName)); - } - - public static String toLowerHyphen(String inStr) { - if (inStr == null) { - return (null); - } - - String str = inStr.substring(0, 1).toLowerCase(); - if (inStr.length() > 1) { - str = str + inStr.substring(1); - } - - String regex = "(([a-z0-9])([A-Z]))"; - String replacement = "$2-$3"; - - String retval = str.replaceAll(regex, replacement).toLowerCase(); - - LOG.trace("Converting " + inStr + " => " + str + " => " + retval); - return (retval); - } - - //This is called when mapping the yang value back to a valid java enumeration - public static String toJavaEnum(String inStr) { - if (inStr == null) { - return (null); - } else if (inStr.length() == 0) { - return (inStr); - } - - //This will strip out all periods, which cannot be in a java enum - inStr = inStr.replaceAll("\\.", ""); - - String[] terms = inStr.split("-"); - StringBuffer sbuff = new StringBuffer(); - - //appends an _ if the string starts with a digit to make it a valid java enum - if (Character.isDigit(inStr.charAt(0))) { - sbuff.append('_'); - } - //If the string contains hyphens it will convert the string to upperCamelCase without hyphens - for (String term : terms) { - sbuff.append(term.substring(0, 1).toUpperCase()); - if (term.length() > 1) { - sbuff.append(term.substring(1)); - } - } - return (sbuff.toString()); - - } - - public static boolean isGetter(Method m) { - if (m == null) { - return (false); - } - - if (Modifier.isPublic(m.getModifiers()) && (m.getParameterTypes().length == 0)) { - if (m.getName().matches("^get[A-Z].*") && !m.getReturnType().equals(void.class)) { - if (!"getClass".equals(m.getName())) { - return (true); - } - } - - if (m.getName().matches("^get[A-Z].*") && m.getReturnType().equals(boolean.class)) { - return (true); - } - - if (m.getName().matches("^is[A-Z].*") && m.getReturnType().equals(Boolean.class)) { - return (true); - } - } - - return (false); - } - - public static boolean isSetter(Method m) { - if (m == null) { - return (false); - } - - if (Modifier.isPublic(m.getModifiers()) && (m.getParameterTypes().length == 1)) { - if (m.getName().matches("^set[A-Z].*")) { - Class[] paramTypes = m.getParameterTypes(); - if (paramTypes[0].isAssignableFrom(Identifier.class) || Identifier.class.isAssignableFrom(paramTypes[0])) { - return (false); - } else { - return (true); - } - } - - } - - return (false); - } - - public static String getFullPropertiesPath(String propertiesFileName) { - return "/opt/bvc/controller/configuration/" + propertiesFileName; - } - - //This is called when mapping a valid java enumeration back to the yang model value - public static String mapEnumeratedValue(String propertyName, String propertyValue) { - LOG.info("mapEnumeratedValue called with propertyName=" + propertyName + " and value=" + propertyValue); - String mappingKey = "yang." + propertyName + "." + propertyValue; - if (yangMappingProperties.containsKey(mappingKey)) { - return (yangMappingProperties.getProperty(mappingKey)); - } else { - LOG.info("yangMappingProperties did not contain the key " + mappingKey + " returning the original value."); - return propertyValue; - } - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java deleted file mode 100644 index 706014a3..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class NotifyNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(NotifyNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String action = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("action"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("release node encountered - looking for resource class " - + plugin); - } - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - if (resourcePlugin != null) { - - try { - - switch (resourcePlugin.notify(resourceType, action, key, ctx)) { - case SUCCESS: - outValue = "success"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java deleted file mode 100644 index 8ba14d27..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java +++ /dev/null @@ -1,119 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicRecorder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RecordNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(RecordNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String outValue = "failure"; - - if (LOG.isTraceEnabled()) { - LOG.trace(node.getNodeType() - + " node encountered - looking for recorder class " - + plugin); - } - - Map parmMap = new HashMap(); - - Set> parmSet = node - .getParameterSet(); - boolean hasParms = false; - - for (Iterator> iter = parmSet - .iterator(); iter.hasNext();) { - hasParms = true; - Map.Entry curEnt = iter.next(); - String curName = curEnt.getKey(); - SvcLogicExpression curExpr = curEnt.getValue(); - String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, - node, ctx); - - if (LOG.isTraceEnabled()) { - LOG.trace("executeRecordNode : parameter " + curName + " = " - + curExpr + " => " + curExprValue); - } - parmMap.put(curName, curExprValue); - } - - - SvcLogicRecorder recorder = getSvcLogicRecorder(plugin); - - if (recorder != null) { - - try { - recorder.record(parmMap); - } catch (SvcLogicException e) { - LOG.error("Caught exception from recorder plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicRecorder object for plugin " - + plugin); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isTraceEnabled()) { - LOG.trace("no failure or Other branch found"); - } - } - return (nextNode); - } - - - - - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java deleted file mode 100644 index 0d8416cd..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ReleaseNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(ReleaseNodeExecutor.class); - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("release node encountered - looking for resource class " - + plugin); - } - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - if (resourcePlugin != null) { - - try { - - switch (resourcePlugin.release(resourceType, key, ctx)) { - case SUCCESS: - outValue = "success"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java deleted file mode 100644 index f0bbda88..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java +++ /dev/null @@ -1,114 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ReserveNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(ReserveNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - String pfx = SvcLogicExpressionResolver.evaluate(node.getAttribute("pfx"),node,ctx); - - - SvcLogicExpression selectExpr = node.getAttribute("select"); - String select = null; - - if (selectExpr != null) - { - select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node, ctx); - } - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("reserve node encountered - looking for resource class " - + plugin); - } - - - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - - if (resourcePlugin != null) { - - try { - switch (resourcePlugin.reserve(resourceType, select, key, pfx, ctx)) { - case SUCCESS: - outValue = "success"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReturnNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReturnNodeExecutor.java deleted file mode 100644 index 5cca4712..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReturnNodeExecutor.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ReturnNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(ReturnNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String status = SvcLogicExpressionResolver.evaluate( - node.getAttribute("status"), node, ctx); - - if (status != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Returning status " + status); - } - ctx.setStatus(status); - } else { - if (LOG.isWarnEnabled()) { - LOG.warn("Return node has no status attribute set"); - } - } - - Set> parameterSet = node - .getParameterSet(); - - for (Iterator> iter = parameterSet - .iterator(); iter.hasNext();) { - Map.Entry curEnt = iter.next(); - String curName = curEnt.getKey(); - String curValue = SvcLogicExpressionResolver.evaluate( - curEnt.getValue(), node, ctx); - - if (LOG.isDebugEnabled()) { - LOG.debug("Setting context attribute " + curName + " to " - + curValue); - } - ctx.setAttribute(curName, curValue); - } - return null; - } - - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java deleted file mode 100644 index 57eac7f7..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SaveNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(SaveNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - String forceStr = SvcLogicExpressionResolver.evaluate( - node.getAttribute("force"), node, ctx); - String localOnlyStr = SvcLogicExpressionResolver.evaluate( - node.getAttribute("local-only"), node, ctx); - String pfx = SvcLogicExpressionResolver.evaluate( - node.getAttribute("pfx"), node, ctx); - - boolean force = "true".equalsIgnoreCase(forceStr); - boolean localOnly = "true".equalsIgnoreCase(localOnlyStr); - - Map parmMap = new HashMap(); - - Set> parmSet = node - .getParameterSet(); - boolean hasParms = false; - - for (Iterator> iter = parmSet - .iterator(); iter.hasNext();) { - hasParms = true; - Map.Entry curEnt = iter.next(); - String curName = curEnt.getKey(); - SvcLogicExpression curExpr = curEnt.getValue(); - if (curExpr != null) { - String curExprValue = SvcLogicExpressionResolver.evaluate( - curExpr, node, ctx); - - LOG.debug("Parameter " + curName + " = " - + curExpr.asParsedExpr() + " resolves to " - + curExprValue); - - parmMap.put(curName, curExprValue); - } - } - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("save node encountered - looking for resource class " - + plugin); - } - - - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - - if (resourcePlugin != null) { - - try { - switch (resourcePlugin.save(resourceType, force, localOnly, key, - parmMap, pfx, ctx)) { - case SUCCESS: - outValue = "success"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java deleted file mode 100644 index 013997ed..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java +++ /dev/null @@ -1,189 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import java.util.Set; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicExpressionFactory; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SetNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(SetNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String ifunsetStr = SvcLogicExpressionResolver.evaluate( - node.getAttribute("only-if-unset"), node, ctx); - - boolean ifunset = "true".equalsIgnoreCase(ifunsetStr); - - Set> parameterSet = node - .getParameterSet(); - - for (Iterator> iter = parameterSet - .iterator(); iter.hasNext();) { - Map.Entry curEnt = iter.next(); - String curName = curEnt.getKey(); - String lhsVarName = curName; - - // Resolve LHS of assignment (could contain index variables) - try { - SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(curName); - lhsVarName = SvcLogicExpressionResolver.resolveVariableName(lhsExpr, node, ctx); - } catch (Exception e) { - LOG.warn("Caught exception trying to resolve variable name ("+curName+")", e); - } - - - boolean setValue = true; - - if (curName.endsWith(".")) { - - // Copy subtree - value should be a variable name - SvcLogicExpression curValue = curEnt.getValue(); - - if (curValue != null) { - String rhsRoot = curValue.toString(); - - if ((rhsRoot != null) && (rhsRoot.length() > 0)) { - if (rhsRoot.endsWith(".")) { - rhsRoot = rhsRoot - .substring(0, rhsRoot.length() - 1); - } - - - // SDNGC-2321 : rhsRoot is variable name, possibly with subscript(s) to be resolved - try { - SvcLogicExpression rhsExpr = SvcLogicExpressionFactory.parse(rhsRoot); - rhsRoot = SvcLogicExpressionResolver.resolveVariableName(rhsExpr, node, ctx); - } catch (Exception e) { - LOG.warn("Caught exception trying to resolve variable name ("+rhsRoot+")", e); - } - - // See if the parameters are reversed (copying service-data to input) .. this - // was done as a workaround to earlier issue - if (curName.endsWith("-input.") && rhsRoot.startsWith("service-data")) { - LOG.warn("Arguments appear to be reversed .. will copy input to service-data instead"); - lhsVarName = rhsRoot + "."; - rhsRoot = curName.substring(0, curName.length()-1); - } - - rhsRoot = rhsRoot + "."; - String lhsPrefix = lhsVarName; - - if (lhsPrefix.endsWith(".")) { - lhsPrefix = lhsPrefix.substring(0, - lhsPrefix.length()-1); - } - int lhsPfxLength = lhsPrefix.length(); - HashMap parmsToAdd = new HashMap(); - - for (String sourceVarName : ctx.getAttributeKeySet()) { - - if (sourceVarName.startsWith(rhsRoot)) { - - String targetVar = lhsPrefix - + "." - + sourceVarName - .substring(rhsRoot.length()); - - LOG.debug("Copying " + sourceVarName - + " value to " + targetVar); - - parmsToAdd.put(targetVar, - ctx.getAttribute(sourceVarName)); - } - } - - for (String newParmName : parmsToAdd.keySet()) { - ctx.setAttribute(newParmName, parmsToAdd.get(newParmName)); - } - - } else { - // If RHS is empty, unset attributes in LHS - String lhsPrefix = lhsVarName.substring(0, - lhsVarName.length() - 1); - int lhsPfxLength = lhsPrefix.length(); - - LinkedList parmsToRemove = new LinkedList (); - - for (String curCtxVarname : ctx.getAttributeKeySet()) { - - if (curCtxVarname.startsWith(lhsPrefix)) { - LOG.debug("Unsetting " + curCtxVarname); - parmsToRemove.add(curCtxVarname); - } - } - - for (String parmName : parmsToRemove) { - ctx.setAttribute(parmName, null); - } - - } - } - - } else { - - if (ifunset) { - String ctxValue = ctx.getAttribute(lhsVarName); - - if ((ctxValue != null) && (ctxValue.length() > 0)) { - setValue = false; - LOG.debug("Attribute " - + lhsVarName - + " already set and only-if-unset is true, so not overriding"); - } - } - - if (setValue) { - String curValue = SvcLogicExpressionResolver.evaluate( - curEnt.getValue(), node, ctx); - - if (LOG.isDebugEnabled()) { - LOG.trace("Parameter value " - + curEnt.getValue().asParsedExpr() - + " resolves to " + curValue); - LOG.debug("Setting context attribute " + lhsVarName - + " to " + curValue); - } - ctx.setAttribute(lhsVarName, curValue); - } - } - } - - return null; - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java deleted file mode 100644 index ae42e2c7..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java +++ /dev/null @@ -1,225 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.io.File; -import java.io.FileInputStream; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.LinkedList; -import java.util.Map; -import java.util.Properties; - -import org.openecomp.sdnc.sli.ConfigurationException; -import org.openecomp.sdnc.sli.SvcLogicAdaptor; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicStore; -import org.openecomp.sdnc.sli.SvcLogicStoreFactory; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.mysql.jdbc.Driver; - -public class SvcLogicActivator implements BundleActivator { - - private static final String SVCLOGIC_PROP_VAR = "SDNC_SLI_PROPERTIES"; - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - - private static final Map BUILTIN_NODES = new HashMap() { - { - put("block", new BlockNodeExecutor()); - put("call", new CallNodeExecutor()); - put("configure", new ConfigureNodeExecutor()); - put("delete", new DeleteNodeExecutor()); - put("execute", new ExecuteNodeExecutor()); - put("exists", new ExistsNodeExecutor()); - put("for", new ForNodeExecutor()); - put("get-resource", new GetResourceNodeExecutor()); - put("is-available", new IsAvailableNodeExecutor()); - put("notify", new NotifyNodeExecutor()); - put("record", new RecordNodeExecutor()); - put("release", new ReleaseNodeExecutor()); - put("reserve", new ReserveNodeExecutor()); - put("return", new ReturnNodeExecutor()); - put("save", new SaveNodeExecutor()); - put("set", new SetNodeExecutor()); - put("switch", new SwitchNodeExecutor()); - put("update", new UpdateNodeExecutor()); - put("break", new BreakNodeExecutor()); - - } - }; - - private static LinkedList registrations = new LinkedList(); - - private static HashMap adaptorMap = null; - - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicActivator.class); - - private static Properties props = null; - - private static BundleContext bundleCtx = null; - - private static SvcLogicService svcLogicServiceImpl = null; - - @Override - public void start(BundleContext ctx) throws Exception { - - LOG.info("Activating SLI"); - - bundleCtx = ctx; - - // Read properties - props = new Properties(); - String propPath = System.getenv(SVCLOGIC_PROP_VAR); - - if (propPath == null) { - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - propPath = propDir + "/svclogic.properties"; - LOG.warn("Environment variable "+SVCLOGIC_PROP_VAR+" unset - defaulting to "+propPath); - } - - File propFile = new File(propPath); - - if (!propFile.exists()) { - - throw new ConfigurationException( - "Missing configuration properties file : " - + propFile); - } - try { - - props.load(new FileInputStream(propFile)); - } catch (Exception e) { - throw new ConfigurationException( - "Could not load properties file " + propPath, e); - - } - - - if (registrations == null) { - - registrations = new LinkedList(); - } - - // Advertise SvcLogicService - svcLogicServiceImpl = new SvcLogicServiceImpl(); - - LOG.info("SLI: Registering service " + SvcLogicService.NAME - + " in bundle " + ctx.getBundle().getSymbolicName()); - ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME, - svcLogicServiceImpl, null); - registrations.add(reg); - - // Initialize SvcLogicStore - try { - SvcLogicStore store = getStore(); - registerNodeTypes(store); - } catch (ConfigurationException e) { - LOG.warn("Could not initialize SvcLogicScore", e); - } - - LOG.info("SLI - done registering services"); - } - - @Override - public void stop(BundleContext ctx) throws Exception { - - if (registrations != null) { - for (ServiceRegistration reg : registrations) { - ServiceReference regRef = reg.getReference(); - /* Don't bother to remove node types from table - String nodeType = (String) regRef.getProperty("nodeType"); - if (nodeType != null) { - LOG.info("SLI - unregistering node type " + nodeType); - store.unregisterNodeType(nodeType); - } - */ - reg.unregister(); - } - registrations = null; - } - } - - public static SvcLogicStore getStore() throws SvcLogicException { - // Create and initialize SvcLogicStore object - used to access - // saved service logic. - - SvcLogicStore store = null; - - try { - Driver dvr = new Driver(); - store = SvcLogicStoreFactory.getSvcLogicStore(props); - } catch (Exception e) { - throw new ConfigurationException( - "Could not get service logic store", e); - - } - - try { - store.init(props); - } catch (Exception e) { - throw new ConfigurationException( - "Could not get service logic store", e); - } - - return(store); - } - - private static void registerNodeTypes(SvcLogicStore store) throws SvcLogicException { - - if (store == null) { - return; - } - // Advertise built-in node executors - LOG.info("SLI : Registering built-in node executors"); - Hashtable propTable = new Hashtable(); - - for (String nodeType : BUILTIN_NODES.keySet()) { - LOG.info("SLI - registering node type " + nodeType); - propTable.clear(); - propTable.put("nodeType", nodeType); - - ServiceRegistration reg = bundleCtx.registerService(SvcLogicNodeExecutor.class.getName(), - BUILTIN_NODES.get(nodeType), propTable); - registrations.add(reg); - - store.registerNodeType(nodeType); - - LOG.info("SLI - registering node executor"); - - ((SvcLogicServiceImpl)svcLogicServiceImpl).registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); - - } - - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicAdaptorFactory.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicAdaptorFactory.java deleted file mode 100644 index aa8c005a..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicAdaptorFactory.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.HashMap; - -import org.openecomp.sdnc.sli.SvcLogicAdaptor; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SvcLogicAdaptorFactory { - - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicAdaptorFactory.class); - - private static HashMap adaptorMap = new HashMap(); - - public static void registerAdaptor(SvcLogicAdaptor adaptor) { - String name = adaptor.getClass().getName(); - LOG.info("Registering adaptor " + name); - adaptorMap.put(name, adaptor); - - } - - public static void unregisterAdaptor(String name) { - if (adaptorMap.containsKey(name)) { - LOG.info("Unregistering " + name); - adaptorMap.remove(name); - } - } - - public static SvcLogicAdaptor getInstance(String name) { - if (adaptorMap.containsKey(name)) { - return (adaptorMap.get(name)); - } else { - BundleContext bctx = null; - try - { - bctx = FrameworkUtil.getBundle(SvcLogicAdaptorFactory.class) - .getBundleContext(); - } - catch (Exception e) - { - LOG.debug("Caught exception trying to locate device adaptor "+name, e); - return(null); - } - - ServiceReference sref = bctx.getServiceReference(name); - - if (sref != null) { - SvcLogicAdaptor adaptor = (SvcLogicAdaptor) bctx - .getService(sref); - - if (adaptor != null) { - registerAdaptor(adaptor); - - return (adaptor); - } - return (null); - } - } - return(null); - } -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java deleted file mode 100644 index 5c17c799..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java +++ /dev/null @@ -1,605 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.openecomp.sdnc.sli.SvcLogicAtom; -import org.openecomp.sdnc.sli.SvcLogicAtom.AtomType; -import org.openecomp.sdnc.sli.SvcLogicBinaryExpression; -import org.openecomp.sdnc.sli.SvcLogicBinaryExpression.OperatorType; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicFunctionCall; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicVariableTerm; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SvcLogicExpressionResolver { - - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicExpressionResolver.class); - - public static String evaluate(SvcLogicExpression expr, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - if (expr == null) { - return (null); - } - - - - if (expr instanceof SvcLogicAtom) { - SvcLogicAtom atom = (SvcLogicAtom) expr; - - AtomType atomType = atom.getAtomType(); - switch (atomType) { - case NUMBER: - case STRING: - return (atom.toString()); - case CONTEXT_VAR: - case IDENTIFIER: - - String varName = resolveVariableName(atom, node, ctx); - - if (atomType == AtomType.CONTEXT_VAR) - { - LOG.trace("Evaluating context variable $"+varName); - - String varValue = ctx.getAttribute(varName); - - if (varValue == null) { - LOG.trace("Context variable $"+varName+" unset - treating as empty string"); - varValue = ""; - } - - return (varValue); - } - SvcLogicExpression parm = node.getParameter(varName); - if (parm != null) { - LOG.trace("Evaluating value of parameter "+varName+": "+parm.asParsedExpr()); - - return (evaluate(parm, node, ctx)); - } - else - { - return(varName); - } - default: - return(null); - } - - } else if (expr instanceof SvcLogicBinaryExpression) { - SvcLogicBinaryExpression binExpr = (SvcLogicBinaryExpression) expr; - List operators = binExpr.getOperators(); - if (operators.isEmpty()) - { - List operands = binExpr.getOperands(); - if (operands.size() == 1) - { - LOG.trace("SvcLogicBinaryExpression as no operator and one operand - evaluating its operand"); - return(evaluate(operands.get(0), node, ctx)); - } - else - { - if (operands.isEmpty()) - { - LOG.error("SvcLogicBinaryExpression has no operators and no operands - evaluating value as null"); - } - else - { - LOG.error("SvcLogicBinaryExpression has no operators and "+operands.size()+" operands - evaluating value as null"); - } - return(null); - } - } - switch (operators.get(0)) { - case addOp: - case subOp: - case multOp: - case divOp: - return(evalArithExpression(binExpr, node, ctx)); - case equalOp: - case neOp: - case ltOp: - case leOp: - case gtOp: - case geOp: - return (evalCompareExpression(binExpr, node, ctx)); - case andOp: - case orOp: - return(evalLogicExpression(binExpr, node, ctx)); - - default: - return(null); - } - } - else if (expr instanceof SvcLogicFunctionCall) - { - return(evalFunctionCall((SvcLogicFunctionCall)expr, node, ctx)); - } - else - { - throw new SvcLogicException("Unrecognized expression type ["+expr+"]"); - } - } - - private static String evalArithExpression(SvcLogicBinaryExpression binExpr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { - List operands = binExpr.getOperands(); - List operators = binExpr.getOperators(); - if (operands.size() != (operators.size()+1)) - { - throw new SvcLogicException("Invalid expression ("+binExpr+")"); - } - String retval = evaluate(operands.get(0), node, ctx); - String retsval = retval; - long retlval = 0; - boolean valueIsLong = false; - - int i = 1; - try - { - - if ((retval.length() > 0) && StringUtils.isNumeric(retval)) - { - retlval = Long.parseLong(retval); - valueIsLong = true; - } - for (OperatorType operator: operators) - { - String curOperandValue = evaluate(operands.get(i++), node, ctx); - switch(operator) { - case addOp: - retsval = retsval + curOperandValue; - if (valueIsLong) - { - if ((curOperandValue.length() > 0) && StringUtils.isNumeric(curOperandValue) ) - { - retlval = retlval + Long.parseLong(curOperandValue); - } - else - { - valueIsLong = false; - } - } - break; - case subOp: - retlval = retlval - Long.parseLong(curOperandValue); - break; - case multOp: - retlval = retlval * Long.parseLong(curOperandValue); - break; - case divOp: - retlval = retlval / Long.parseLong(curOperandValue); - break; - } - - } - } - catch (NumberFormatException e1) - { - throw new SvcLogicException("Illegal value in arithmetic expression", e1); - } - - if (valueIsLong) - { - return("" + retlval); - } - else - { - return(retsval); - } - - } - - - - private static String evalCompareExpression(SvcLogicBinaryExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException - { - - List operators = expr.getOperators(); - List operands = expr.getOperands(); - - if ((operators.size() != 1) || (operands.size() != 2)) - { - throw new SvcLogicException ("Invalid comparison expression : "+expr); - } - - OperatorType operator = operators.get(0); - String op1Value = evaluate(operands.get(0), node, ctx); - String op2Value = evaluate(operands.get(1), node, ctx); - - if ((StringUtils.isNotEmpty(op1Value) && StringUtils.isNumeric(op1Value) && StringUtils.isNotEmpty(op2Value) && StringUtils.isNumeric(op2Value))) - { - try - { - double op1dbl = Double.parseDouble(op1Value); - double op2dbl = Double.parseDouble(op2Value); - - switch(operator) - { - case equalOp: - return(Boolean.toString(op1dbl == op2dbl)); - case neOp: - return(Boolean.toString(op1dbl != op2dbl)); - case ltOp: - return(Boolean.toString(op1dbl < op2dbl)); - case leOp: - return(Boolean.toString(op1dbl <= op2dbl)); - case gtOp: - return(Boolean.toString(op1dbl > op2dbl)); - case geOp: - return(Boolean.toString(op1dbl >= op2dbl)); - default: - return(null); - } - } - catch (NumberFormatException e) - { - throw new SvcLogicException("Caught exception trying to compare numeric values", e); - } - } - else - { - - int compResult = 0; - - if (op1Value == null) { - compResult = -1; - } else if (op2Value == null ) { - compResult = 1; - } else { - compResult = op1Value.compareToIgnoreCase(op2Value); - } - - switch(operator) - { - case equalOp: - return(Boolean.toString(compResult == 0)); - case neOp: - return(Boolean.toString(compResult != 0)); - case ltOp: - return(Boolean.toString(compResult < 0)); - case leOp: - return(Boolean.toString(compResult <= 0)); - case gtOp: - return(Boolean.toString(compResult > 0)); - case geOp: - return(Boolean.toString(compResult >= 0)); - default: - return(null); - } - } - - } - - private static String evalLogicExpression(SvcLogicBinaryExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException - { - boolean retval; - - List operands = expr.getOperands(); - List operators = expr.getOperators(); - - if (operands.size() != (operators.size()+1)) - { - throw new SvcLogicException("Invalid expression ("+expr+")"); - } - - try - { - retval = Boolean.parseBoolean(evaluate(operands.get(0), node, ctx)); - int i = 1; - for (OperatorType operator : operators) - { - if (operator == OperatorType.andOp) - { - retval = retval && Boolean.parseBoolean(evaluate(operands.get(i++), node, ctx)); - } - else - { - - retval = retval || Boolean.parseBoolean(evaluate(operands.get(i++), node, ctx)); - } - - } - } - catch (Exception e) - { - throw new SvcLogicException("Invalid expression ("+expr+")"); - } - - - return(Boolean.toString(retval)); - } - - private static String evalFunctionCall(SvcLogicFunctionCall func, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException - { - String funcName = func.getFunctionName(); - List operands = func.getOperands(); - - if ("length".equalsIgnoreCase(funcName)) - { - - if (operands.size() == 1) - { - String opValue = evaluate(operands.get(0), node, ctx); - return(""+opValue.length()); - } - else - { - throw new SvcLogicException("Invalid call to length() function"); - } - } - else if ("substr".equalsIgnoreCase(funcName)) - { - if (operands.size() == 3) - { - String op1Value = evaluate(operands.get(0), node, ctx); - String op2Value = evaluate(operands.get(1), node, ctx); - String op3Value = evaluate(operands.get(2), node, ctx); - - if (!StringUtils.isNumeric(op2Value) || !StringUtils.isNumeric(op3Value)) - { - throw new SvcLogicException("Invalid arguments to substr() function"); - } - - try - { - return(op1Value.substring(Integer.parseInt(op2Value), Integer.parseInt(op3Value))); - } - catch (Exception e) - { - throw new SvcLogicException("Caught exception trying to take substring", e); - } - } - else - { - - throw new SvcLogicException("Invalid call to substr() function"); - } - - } - else if ("toUpperCase".equalsIgnoreCase(funcName)) - { - if (operands.size() == 1) - { - String opValue = evaluate(operands.get(0), node, ctx); - if (opValue != null) { - return(opValue.toUpperCase()); - } else { - return(""); - } - } - else - { - throw new SvcLogicException("Invalid call to toUpperCase() function"); - } - } - else if ("toLowerCase".equalsIgnoreCase(funcName)) - { - if (operands.size() == 1) - { - String opValue = evaluate(operands.get(0), node, ctx); - if (opValue != null) { - return(opValue.toLowerCase()); - } else { - return(""); - } - } - else - { - throw new SvcLogicException("Invalid call to toLowerCase() function"); - } - } - else if ("convertBase".equalsIgnoreCase(funcName)) { - int fromBase = 10; - int toBase = 10; - String srcString = ""; - - if (operands.size() == 2) - { - fromBase = 10; - srcString = evaluate(operands.get(0), node, ctx); - toBase = Integer.parseInt(evaluate(operands.get(1), node, ctx)); - } else if (operands.size() == 3) { - - srcString = evaluate(operands.get(0), node, ctx); - fromBase = Integer.parseInt(evaluate(operands.get(1), node, ctx)); - toBase = Integer.parseInt(evaluate(operands.get(2), node, ctx)); - } else { - throw new SvcLogicException("Invalid call to convertBase() function"); - } - - long srcValue = Long.parseLong(srcString, fromBase); - return(Long.toString(srcValue, toBase)); - } - else - { - throw new SvcLogicException("Unrecognized function ("+funcName+")"); - } - - } - - public static String evaluateAsKey(SvcLogicExpression expr, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - if (expr == null) { - return (null); - } - - - - if (expr instanceof SvcLogicAtom) { - SvcLogicAtom atom = (SvcLogicAtom) expr; - - AtomType atomType = atom.getAtomType(); - StringBuffer varNameBuff = new StringBuffer(); - switch (atomType) { - case NUMBER: - return (atom.toString()); - case STRING: - return("'"+atom.toString()+"'"); - case CONTEXT_VAR: - case IDENTIFIER: - boolean needDot = false; - for (SvcLogicExpression term : atom.getOperands()) - { - if (needDot) - { - varNameBuff.append("."); - } - if (term instanceof SvcLogicVariableTerm) - { - SvcLogicVariableTerm vterm = (SvcLogicVariableTerm) term; - varNameBuff.append(vterm.getName()); - if (vterm.numOperands() > 0) - { - varNameBuff.append("["); - varNameBuff.append(evaluate(vterm.getSubscript(), node, ctx)); - varNameBuff.append("]"); - - } - } - else - { - varNameBuff.append(term.toString()); - } - needDot = true; - } - - String varName = varNameBuff.toString(); - LOG.debug("Evaluating context variable $"+varName); - String ctxValue = ctx.getAttribute(varName); - if (ctxValue == null) - { - return(null); - } - if (StringUtils.isNumeric(ctxValue)) - { - return(ctxValue); - } - else - { - return("'"+ctxValue+"'"); - } - - default: - return(null); - } - - } else if (expr instanceof SvcLogicBinaryExpression) { - SvcLogicBinaryExpression binExpr = (SvcLogicBinaryExpression) expr; - List operators = binExpr.getOperators(); - List operands = binExpr.getOperands(); - if (operators.isEmpty()) - { - if (operands.size() == 1) - { - LOG.debug("SvcLogicBinaryExpression as no operator and one operand - evaluating its operand"); - return(evaluateAsKey(operands.get(0), node, ctx)); - } - else - { - if (operands.isEmpty()) - { - LOG.error("SvcLogicBinaryExpression has no operators and no operands - evaluating value as null"); - } - else - { - LOG.error("SvcLogicBinaryExpression has no operators and "+operands.size()+" operands - evaluating value as null"); - } - return(null); - } - } - StringBuffer sbuff = new StringBuffer(); - sbuff.append(evaluateAsKey(operands.get(0), node, ctx)); - int i = 1; - for (OperatorType operator : operators) - { - sbuff.append(" "); - sbuff.append(operator.toString()); - sbuff.append(" "); - sbuff.append(evaluateAsKey(operands.get(i++), node,ctx)); - } - return(sbuff.toString()); - } - else if (expr instanceof SvcLogicFunctionCall) - { - StringBuffer sbuff = new StringBuffer(); - SvcLogicFunctionCall funcCall = (SvcLogicFunctionCall) expr; - sbuff.append(funcCall.getFunctionName()); - sbuff.append("("); - boolean needComma = false; - for (SvcLogicExpression operand : funcCall.getOperands()) - { - if (needComma) - { - sbuff.append(","); - } - else - { - needComma = true; - } - sbuff.append(evaluateAsKey(operand, node, ctx)); - } - sbuff.append(")"); - return(sbuff.toString()); - } - else - { - throw new SvcLogicException("Unrecognized expression type ["+expr+"]"); - } - } - - public static String resolveVariableName(SvcLogicExpression atom, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException - { - StringBuffer varNameBuff = new StringBuffer(); - - boolean needDot = false; - for (SvcLogicExpression term : atom.getOperands()) - { - if (needDot) - { - varNameBuff.append("."); - } - if (term instanceof SvcLogicVariableTerm) - { - SvcLogicVariableTerm vterm = (SvcLogicVariableTerm) term; - varNameBuff.append(vterm.getName()); - if (vterm.numOperands() > 0) - { - varNameBuff.append("["); - varNameBuff.append(evaluate(vterm.getSubscript(), node, ctx)); - varNameBuff.append("]"); - } - } - else - { - varNameBuff.append(term.toString()); - } - needDot = true; - } - return(varNameBuff.toString()); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicNodeExecutor.java deleted file mode 100644 index 0c8166ae..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicNodeExecutor.java +++ /dev/null @@ -1,110 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicAdaptor; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicRecorder; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.openecomp.sdnc.sli.SvcLogicStore; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class SvcLogicNodeExecutor { - - public abstract SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException; - - private static final Logger LOG = LoggerFactory.getLogger(SvcLogicNodeExecutor.class); - - protected String evaluateNodeTest(SvcLogicNode node, SvcLogicContext ctx) - throws SvcLogicException { - if (node == null) { - return null; - } - - return (SvcLogicExpressionResolver.evaluate(node.getAttribute("test"), - node, ctx)); - - } - - protected SvcLogicStore getStore() throws SvcLogicException { - return SvcLogicActivator.getStore(); - } - - protected SvcLogicAdaptor getAdaptor(String adaptorName) { - return SvcLogicAdaptorFactory.getInstance(adaptorName); - } - - protected SvcLogicResource getSvcLogicResource(String plugin) { - BundleContext bctx = FrameworkUtil.getBundle(this.getClass()) - .getBundleContext(); - - ServiceReference sref = bctx.getServiceReference(plugin); - if (sref != null) { - SvcLogicResource resourcePlugin = (SvcLogicResource) bctx - .getService(sref); - return resourcePlugin; - } - else { - LOG.warn("Could not find service reference object for plugin " + plugin); - return null; - } - } - - protected SvcLogicRecorder getSvcLogicRecorder(String plugin) { - BundleContext bctx = FrameworkUtil.getBundle(this.getClass()) - .getBundleContext(); - - ServiceReference sref = bctx.getServiceReference(plugin); - if (sref != null) { - SvcLogicRecorder resourcePlugin = (SvcLogicRecorder) bctx - .getService(sref); - return resourcePlugin; - } - else { - return null; - } - } - - protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){ - BundleContext bctx = FrameworkUtil.getBundle(this.getClass()) - .getBundleContext(); - - ServiceReference sref = bctx.getServiceReference(pluginName); - - if (sref == null) { - LOG.warn("Could not find service reference object for plugin " + pluginName); - return null; - } else { - SvcLogicJavaPlugin plugin = (SvcLogicJavaPlugin) bctx - .getService(sref); - return plugin; - } - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicService.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicService.java deleted file mode 100644 index f30b3fc0..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicService.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.Properties; - -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.openecomp.sdnc.sli.SvcLogicException; - -public interface SvcLogicService { - - public static final String NAME = "org.openecomp.sdnc.sli.provider.SvcLogicService"; - - // public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException; - /** - * Check for existence of a directed graph - * @param module - module name - * @param rpc - rpc name - * @param version - version. If null, looks for active version - * @param mode - mode (sync/async) - * @return true if directed graph found, false otherwise - * @throws SvcLogicException - */ - public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException; - - /** - * Execute a directed graph - * - * @param module - module name - * @param rpc - rpc name - * @param version - version. If null, use active version - * @param mode - mode (sync/async) - * @param parms - parameters, used to set SvcLogicContext attributes - * @return final values of attributes from SvcLogicContext, as Properties - * @throws SvcLogicException - * - * - * @deprecated use execute(String module, String rpc, String version, String mode, DOMDataBroker dataBroker) instead - */ - @Deprecated - public Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException; - - /** - * Execute a directed graph - * - * @param module - module name - * @param rpc - rpc name - * @param version - version. If null, use active version - * @param mode - mode (sync/async) - * @param parms - parameters, used to set SvcLogicContext attributes - * @param domDataBroker - DOMDataBroker object - * @return final values of attributes from SvcLogicContext, as Properties - * @throws SvcLogicException - */ - public Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException; - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java deleted file mode 100644 index ba929bae..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java +++ /dev/null @@ -1,273 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.HashMap; -import java.util.Properties; - -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.openecomp.sdnc.sli.MetricLogger; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicGraph; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicStore; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; - -public class SvcLogicServiceImpl implements SvcLogicService { - - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicServiceImpl.class); - - private HashMap nodeExecutors = null; - - private BundleContext bctx = null; - - private void registerExecutors() { - - LOG.info("Entered register executors"); - if (bctx == null) { - bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); - } - - if (nodeExecutors == null) { - nodeExecutors = new HashMap(); - } - - LOG.info("Opening service tracker"); - ServiceTracker tracker = new ServiceTracker(bctx, - SvcLogicNodeExecutor.class.getName(), null); - - tracker.open(); - - ServiceListener listener = new ServiceListener() { - - public void serviceChanged(ServiceEvent ev) { - ServiceReference sr = ev.getServiceReference(); - switch (ev.getType()) { - case ServiceEvent.REGISTERED: { - registerExecutor(sr); - } - break; - case ServiceEvent.UNREGISTERING: { - unregisterExecutor(sr); - } - break; - } - } - }; - - LOG.info("Adding service listener"); - String filter = "(objectclass=" + SvcLogicNodeExecutor.class.getName() - + ")"; - try { - bctx.addServiceListener(listener, filter); - ServiceReference[] srl = bctx.getServiceReferences( - SvcLogicNodeExecutor.class.getName(), null); - for (int i = 0; srl != null && i < srl.length; i++) { - listener.serviceChanged(new ServiceEvent( - ServiceEvent.REGISTERED, srl[i])); - } - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - } - LOG.info("Done registerExecutors"); - } - - public void registerExecutor(ServiceReference sr) { - - String nodeName = (String) sr.getProperty("nodeType"); - if (nodeName != null) { - - SvcLogicNodeExecutor executor = null; - - try { - executor = (SvcLogicNodeExecutor) bctx.getService(sr); - } catch (Exception e) { - LOG.error("Cannot get service executor for " + nodeName); - return; - } - - registerExecutor(nodeName, executor); - - } - } - - public void registerExecutor(String nodeName, SvcLogicNodeExecutor executor) - { - if (nodeExecutors == null) { - nodeExecutors = new HashMap(); - } - LOG.info("SLI - registering executor for node type "+nodeName); - nodeExecutors.put(nodeName, executor); - } - - public void unregisterExecutor(ServiceReference sr) { - String nodeName = (String) sr.getProperty("nodeType"); - - if (nodeName != null) { - - unregisterExecutor(nodeName); - - } - - } - - public void unregisterExecutor(String nodeName) - { - - LOG.info("SLI - unregistering executor for node type "+nodeName); - nodeExecutors.remove(nodeName); - } - - - - - public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) - throws SvcLogicException { - - if (nodeExecutors == null) { - registerExecutors(); - } - - // Set service name in MDC to reference current working directed graph - MDC.put(MetricLogger.SERVICE_NAME, graph.getModule()+":"+graph.getRpc()+"/v"+graph.getVersion()); - - SvcLogicNode curNode = graph.getRootNode(); - LOG.info("About to execute graph " + graph.toString()); - - - - while (curNode != null) { - LOG.info("About to execute node # "+curNode.getNodeId()+" ("+curNode.getNodeType()+")"); - - SvcLogicNode nextNode = executeNode(curNode, ctx); - curNode = nextNode; - } - - return (ctx); - } - - - public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx) - throws SvcLogicException { - if (node == null) { - return (null); - } - - if (LOG.isDebugEnabled()) { - LOG.debug("Executing node " + node.getNodeId()); - } - - SvcLogicNodeExecutor executor = nodeExecutors.get(node.getNodeType()); - - if (executor != null) { - LOG.debug("Executing node executor for node type "+node.getNodeType()+" - "+executor.getClass().getName()); - return (executor.execute(this, node, ctx)); - } else { - if (LOG.isDebugEnabled()) { - LOG.debug(node.getNodeType() + " node not implemented"); - } - SvcLogicNode nextNode = node.getOutcomeValue("failure"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute failure branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("no failure or Other branch found"); - } - } - return (nextNode); - } - - } - - @Override - public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException - { - SvcLogicStore store = SvcLogicActivator.getStore(); - - return (store.hasGraph(module, rpc, version, mode)); - } - - @Override - public Properties execute(String module, String rpc, String version, String mode, Properties props) - throws SvcLogicException { - return(execute(module, rpc, version, mode, props, null)); - } - - - @Override - public Properties execute(String module, String rpc, String version, String mode, - Properties props, DOMDataBroker domDataBroker) throws SvcLogicException { - - - // See if there is a service logic defined - // - SvcLogicStore store = SvcLogicActivator.getStore(); - - LOG.info("Fetching service logic from data store"); - SvcLogicGraph graph = store.fetch(module, rpc, version, mode); - - - - if (graph == null) - { - Properties retProps = new Properties(); - retProps.setProperty("error-code", "401"); - retProps.setProperty("error-message", "No service logic found for ["+module+","+rpc+","+version+","+mode+"]"); - return(retProps); - - } - - SvcLogicContext ctx = new SvcLogicContext(props); - ctx.setAttribute("currentGraph", graph.toString()); - ctx.setAttribute("X-ECOMP-RequestID", MDC.get("X-ECOMP-RequestID")); - ctx.setDomDataBroker(domDataBroker); - - execute(graph, ctx); - - return(ctx.toProperties()); - } - - - - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java deleted file mode 100644 index e8ae7c89..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SwitchNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(SwitchNodeExecutor.class); - - @Override - - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - - String testResult = evaluateNodeTest(node, ctx); - - if (LOG.isDebugEnabled()) { - LOG.debug("Executing switch node"); - - - LOG.debug("test expression (" + node.getAttribute("test") - + ") evaluates to " + testResult); - } - - SvcLogicNode nextNode = node.getOutcomeValue(testResult); - - if (LOG.isDebugEnabled()) { - if (nextNode != null) { - LOG.debug("Next node to execute is node " + nextNode.getNodeId()); - } else { - LOG.debug("No next node found"); - } - } - return (nextNode); - - } -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java deleted file mode 100644 index 9eeab65a..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java +++ /dev/null @@ -1,136 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class UpdateNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory - .getLogger(UpdateNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - - String plugin = SvcLogicExpressionResolver.evaluate( - node.getAttribute("plugin"), node, ctx); - String resourceType = SvcLogicExpressionResolver.evaluate( - node.getAttribute("resource"), node, ctx); - String key = SvcLogicExpressionResolver.evaluateAsKey( - node.getAttribute("key"), node, ctx); - String pfx = SvcLogicExpressionResolver.evaluate( - node.getAttribute("pfx"), node, ctx); - - - Map parmMap = new HashMap(); - - Set> parmSet = node - .getParameterSet(); - boolean hasParms = false; - - for (Iterator> iter = parmSet - .iterator(); iter.hasNext();) { - hasParms = true; - Map.Entry curEnt = iter.next(); - String curName = curEnt.getKey(); - SvcLogicExpression curExpr = curEnt.getValue(); - if (curExpr != null) { - String curExprValue = SvcLogicExpressionResolver.evaluate( - curExpr, node, ctx); - - LOG.debug("Parameter " + curName + " = " - + curExpr.asParsedExpr() + " resolves to " - + curExprValue); - - parmMap.put(curName, curExprValue); - } - } - - String outValue = "failure"; - - if (LOG.isDebugEnabled()) { - LOG.debug("save node encountered - looking for resource class " - + plugin); - } - - - SvcLogicResource resourcePlugin = getSvcLogicResource(plugin); - - - if (resourcePlugin != null) { - - try { - switch (resourcePlugin.update(resourceType, key, - parmMap, pfx, ctx)) { - case SUCCESS: - outValue = "success"; - break; - case NOT_FOUND: - outValue = "not-found"; - break; - case FAILURE: - default: - outValue = "failure"; - } - } catch (SvcLogicException e) { - LOG.error("Caught exception from resource plugin", e); - outValue = "failure"; - } - } else { - LOG.warn("Could not find SvcLogicResource object for plugin " - + plugin); - } - - SvcLogicNode nextNode = node.getOutcomeValue(outValue); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute " + outValue + " branch"); - } - return (nextNode); - } - - nextNode = node.getOutcomeValue("Other"); - if (nextNode != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("about to execute Other branch"); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("no "+outValue+" or Other branch found"); - } - } - return (nextNode); - } - -} diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/WhileNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/WhileNodeExecutor.java deleted file mode 100644 index 5bbab323..00000000 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/WhileNodeExecutor.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.BreakNodeException; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class WhileNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory.getLogger(WhileNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { - - String testResult = evaluateNodeTest(node, ctx); - SvcLogicExpression silentFailureExpr = node.getAttribute("do"); - String doWhile = SvcLogicExpressionResolver.evaluate(silentFailureExpr, node, ctx); - if ("true".equals(doWhile)) { - LOG.debug("While loop will execute once regardless of expression because do is set to true"); - } - - try { - while ("true".equals(testResult) || "true".equals(doWhile)) { - if (!"true".equals(doWhile)) { - LOG.debug("Test expression (" + node.getAttribute("test") + ") evaluates to true, executing loop."); - } - int numOutcomes = node.getNumOutcomes() + 1; - for (int i = 0; i < numOutcomes; i++) { - SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1)); - if (nextNode != null) { - while (nextNode != null) { - nextNode = svc.executeNode(nextNode, ctx); - } - } else { - if ("true".equals(doWhile)) { - LOG.debug("Do executed, will only execute again if test expression is true."); - doWhile = "false"; - } - testResult = evaluateNodeTest(node, ctx); - LOG.debug("test expression (" + node.getAttribute("test") + ") evaluates to " + testResult); - } - } - } - LOG.debug("testResult was " + testResult + " which is not equal to true, exiting while loop."); - } catch (BreakNodeException e) { - LOG.debug("WhileNodeExecutor caught break"); - } - return (null); - } - -} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java new file mode 100644 index 00000000..87273d0b --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.Map; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + +public class BadPlugin implements SvcLogicJavaPlugin { + public String selectLunch(Map parameters, SvcLogicContext ctx) throws SvcLogicException { + String day = parameters.get("day"); + if (day == null || day.length() < 1) { + throw new SvcLogicException("What day is it?"); + } + switch (day) { + case ("monday"): { + return "pizza"; + } + case ("tuesday"): { + return "soup"; + } + case ("wednesday"): { + return "salad"; + } + case ("thursday"): { + return "sushi"; + } + case ("friday"): { + return "bbq"; + } + } + throw new SvcLogicException("Lunch cannot be served"); + } +} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java new file mode 100644 index 00000000..4c16222b --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.Map.Entry; + +import org.onap.ccsdk.sli.core.sli.DuplicateValueException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.provider.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl; + +import junit.framework.TestCase; + +public class ExecuteNodeExecutorTest extends TestCase { + public class MockExecuteNodeExecutor extends ExecuteNodeExecutor { + + protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName) { + return (SvcLogicJavaPlugin) new LunchSelectorPlugin(); + } + + protected String evaluate(SvcLogicExpression expr, SvcLogicNode node, + SvcLogicContext ctx) throws SvcLogicException { + return "selectLunch"; + } + } + + public void testBadPlugin() throws DuplicateValueException, SvcLogicException { + LunchSelectorPlugin p = new LunchSelectorPlugin(); + MockExecuteNodeExecutor execute = new MockExecuteNodeExecutor(); + SvcLogicNode node = new SvcLogicNode(0, "", "", new SvcLogicGraph()); + node.setAttribute("method", "selectLunch"); + execute.execute(new SvcLogicServiceImpl(), new SvcLogicNode(0, "", "", new SvcLogicGraph()), new SvcLogicContext()); + } + +} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java new file mode 100644 index 00000000..4d6b0b4d --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.Map; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + + +public class LunchSelectorPlugin implements SvcLogicJavaPlugin { + public class UnknownLunchDayException extends Exception{ + + public UnknownLunchDayException(String string) { + super(string); + } + + } + class Sandwhich { + String meat; + String cheese; + + public Sandwhich(String meat, String cheese) { + this.meat = meat; + this.cheese = cheese; + } + } + + public String selectLunch(Map parameters, SvcLogicContext ctx) throws Exception { + String day = parameters.get("day"); + if (day == null || day.length() < 1) { + throw new UnknownLunchDayException("What day is it?"); + } + switch (day) { + case ("monday"): { + return "pizza"; + } + case ("tuesday"): { + return "soup"; + } + case ("wednesday"): { + return "salad"; + } + case ("thursday"): { + return "sushi"; + } + case ("friday"): { + return "bbq"; + } + } + throw new SvcLogicException("Lunch cannot be served"); + } + + public Sandwhich makeLunch(Map parameters, SvcLogicContext ctx) throws SvcLogicException { + return new Sandwhich("ham", "american"); + } +} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java new file mode 100644 index 00000000..8057dbd1 --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import junit.framework.TestCase; + +public class MdsalHelperTest extends TestCase { + + public static final String pathToSdnPropertiesFile = "./src/test/resources/l3sdn.properties"; + + public void testSdnProperties() { + MdsalHelperTesterUtil.loadProperties(pathToSdnPropertiesFile); + assertEquals("synccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "Synccomplete")); + assertEquals("asynccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "asynccomplete")); + assertEquals("notifycomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "notifycomplete")); + assertEquals("service-configuration-operation", MdsalHelperTesterUtil.mapEnumeratedValue("rpc-name", + "ServiceConfigurationOperation")); + } + + public void testNegativeSdnProperties() { + assertNotSame("synccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "Synccomplete")); + } + +} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTesterUtil.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTesterUtil.java new file mode 100644 index 00000000..75517a1e --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTesterUtil.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MdsalHelperTesterUtil extends MdsalHelper { + + private static final Logger LOG = LoggerFactory.getLogger(MdsalHelperTesterUtil.class); + + //Normally static init of classes goes here for some weird classloader thing + static { + String str = "Hello World!"; + } + +} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java new file mode 100644 index 00000000..08ab5eeb --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.provider.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicExpressionResolver; + +import junit.framework.TestCase; + +public class PluginTest extends TestCase { + + // The existing plugins work just like a VoidDummyPlugin + // They will return null simply because they are all void + // The attribute emitsOutcome will not be present, the expected outcome is success when no exception is thrown by the plugin + public void testOldPlugin() throws Exception { + ExecuteNodeExecutor executor = new ExecuteNodeExecutor(); + SvcLogicJavaPlugin plugin = new VoidDummyPlugin(); + + Class pluginClass = plugin.getClass(); + Method pluginMethod = pluginClass.getMethod("dummy", Map.class, SvcLogicContext.class); + Map parmMap = new HashMap(); + SvcLogicContext ctx = new SvcLogicContext(); + Object o = pluginMethod.invoke(plugin, parmMap, ctx); + + SvcLogicGraph graph = new SvcLogicGraph(); + SvcLogicNode node = new SvcLogicNode(1, "return", graph); + String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); + String outValue = executor.mapOutcome(o, emitsOutcome); + assertEquals("success",outValue); + } + + //Newer plugins can set the attribute emitsOutcome to true, if so they should return a string + //The string represents the outcome value + public void testNewPlugin() throws Exception { + ExecuteNodeExecutor executor = new ExecuteNodeExecutor(); + SvcLogicJavaPlugin plugin = new LunchSelectorPlugin(); + + Class pluginClass = plugin.getClass(); + Method pluginMethod = pluginClass.getMethod("selectLunch", Map.class, SvcLogicContext.class); + + Map parmMap = new HashMap(); + SvcLogicContext ctx = new SvcLogicContext(); + + parmMap.put("day", "monday"); + Object o = pluginMethod.invoke(plugin, parmMap, ctx); + SvcLogicGraph graph = new SvcLogicGraph(); + SvcLogicNode node = new SvcLogicNode(1, "return", graph); + node.setAttribute("emitsOutcome", "true"); + String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); + String outValue = executor.mapOutcome(o, emitsOutcome); + assertEquals("pizza", outValue); + + parmMap.put("day", "tuesday"); + outValue = (String) pluginMethod.invoke(plugin, parmMap, ctx); + o = pluginMethod.invoke(plugin, parmMap, ctx); + outValue = executor.mapOutcome(o, emitsOutcome); + assertEquals("soup",outValue); + + } + + //APPC had some legacy plugins returning objects which should not be treated as outcomes + //The attribute emitsOutcome will not be set + //The outcome should be success as it has always been + public void testObjPlugin() throws Exception{ + ExecuteNodeExecutor executor = new ExecuteNodeExecutor(); + SvcLogicJavaPlugin plugin = new LunchSelectorPlugin(); + + Class pluginClass = plugin.getClass(); + Method pluginMethod = pluginClass.getMethod("makeLunch", Map.class, SvcLogicContext.class); + + Map parmMap = new HashMap(); + SvcLogicContext ctx = new SvcLogicContext(); + Object o = pluginMethod.invoke(plugin, parmMap, ctx); + SvcLogicGraph graph = new SvcLogicGraph(); + SvcLogicNode node = new SvcLogicNode(1, "return", graph); + String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); + String outValue = executor.mapOutcome(o, emitsOutcome); + assertEquals("success",outValue); + } + +} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java new file mode 100644 index 00000000..1705e790 --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicExprListener; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; +import org.onap.ccsdk.sli.core.sli.SvcLogicExpressionFactory; +import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicExpressionResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import junit.framework.Assert; +import junit.framework.TestCase; + +public class SvcLogicExpressionResolverTest extends TestCase { + + + private static final Logger LOG = LoggerFactory + .getLogger(SvcLogicExpressionResolver.class); + + public void testEvaluate() + { + InputStream testStr = getClass().getResourceAsStream("/expression.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + SvcLogicGraph graph = new SvcLogicGraph(); + SvcLogicNode node = new SvcLogicNode(1, "return", graph); + graph.setRootNode(node); + + String line = null; + int lineNo = 0; + while ((line = testsReader.readLine()) != null) { + ++lineNo; + if (line.startsWith("#")) + { + String testExpr = line.trim().substring(1).trim(); + String[] nameValue = testExpr.split("="); + String name = nameValue[0].trim(); + String value = nameValue[1].trim(); + + if (name.startsWith("$")) + { + LOG.info("Setting context attribute "+name+" = "+value); + ctx.setAttribute(name.substring(1), value); + } + else + { + + LOG.info("Setting node attribute "+name+" = "+value); + node.setAttribute(name, value); + + } + } + else + { + // if the line contains #, what comes before is the expression to evaluate, and what comes after + // is the expected value + String[] substrings = line.split("#"); + String expectedValue = substrings.length > 1 ? substrings[1].trim() : null; + String testExpr = substrings[0].trim(); + + LOG.info("Parsing expression "+testExpr); + SvcLogicExpression expr = SvcLogicExpressionFactory.parse(testExpr); + if (expr == null) + { + fail("Unable to parse expression "+testExpr); + } + else + { + LOG.info("Evaluating parsed expression "+expr.asParsedExpr()); + String exprValue = SvcLogicExpressionResolver.evaluate(expr, node, ctx); + if (exprValue == null) + { + fail("Unable to evaluate expression "+testExpr); + } + else + { + LOG.info("Expression " + testExpr + " evaluates to " + exprValue); + if (expectedValue != null) { + Assert.assertEquals("Line " + lineNo + ": " + testExpr, expectedValue, exprValue); + } + } + } + } + } + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + +} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicGraphExecutorTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicGraphExecutorTest.java new file mode 100644 index 00000000..b54f2846 --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicGraphExecutorTest.java @@ -0,0 +1,211 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.MetricLogger; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; +import org.onap.ccsdk.sli.core.sli.SvcLogicNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicParser; +import org.onap.ccsdk.sli.core.sli.SvcLogicStore; +import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; +import org.onap.ccsdk.sli.core.sli.provider.BlockNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.CallNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ConfigureNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.DeleteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ExistsNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ForNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.GetResourceNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.IsAvailableNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.NotifyNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.RecordNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ReleaseNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ReserveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ReturnNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SaveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SetNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl; +import org.onap.ccsdk.sli.core.sli.provider.SwitchNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.UpdateNodeExecutor; +import org.osgi.framework.ServiceRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import junit.framework.TestCase; + +public class SvcLogicGraphExecutorTest extends TestCase { + private static final Logger LOG = LoggerFactory + .getLogger(SvcLogicGraph.class); + + private static final Map BUILTIN_NODES = new HashMap() { + { + put("block", new BlockNodeExecutor()); + put("call", new CallNodeExecutor()); + put("configure", new ConfigureNodeExecutor()); + put("delete", new DeleteNodeExecutor()); + put("execute", new ExecuteNodeExecutor()); + put("exists", new ExistsNodeExecutor()); + put("for", new ForNodeExecutor()); + put("get-resource", new GetResourceNodeExecutor()); + put("is-available", new IsAvailableNodeExecutor()); + put("notify", new NotifyNodeExecutor()); + put("record", new RecordNodeExecutor()); + put("release", new ReleaseNodeExecutor()); + put("reserve", new ReserveNodeExecutor()); + put("return", new ReturnNodeExecutor()); + put("save", new SaveNodeExecutor()); + put("set", new SetNodeExecutor()); + put("switch", new SwitchNodeExecutor()); + put("update", new UpdateNodeExecutor()); + + } + }; + + public void testExecute() { + + try { + InputStream testStr = getClass().getResourceAsStream("/executor.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + + InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); + + SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr); + + assertNotNull(store); + + store.registerNodeType("switch"); + store.registerNodeType("block"); + store.registerNodeType("get-resource"); + store.registerNodeType("reserve"); + store.registerNodeType("is-available"); + store.registerNodeType("exists"); + store.registerNodeType("configure"); + store.registerNodeType("return"); + store.registerNodeType("record"); + store.registerNodeType("allocate"); + store.registerNodeType("release"); + store.registerNodeType("for"); + store.registerNodeType("set"); + SvcLogicParser parser = new SvcLogicParser(store); + + // Loop through executor tests + + SvcLogicServiceImpl svc = new SvcLogicServiceImpl(); + + for (String nodeType : BUILTIN_NODES.keySet()) { + + LOG.info("SLI - registering node executor for node type "+nodeType); + + svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); + + } + String testCaseLine = null; + while ((testCaseLine = testsReader.readLine()) != null) { + + String[] testCaseFields = testCaseLine.split(":"); + String testCaseFile = testCaseFields[0]; + String testCaseMethod = testCaseFields[1]; + String testCaseParameters = null; + + if (testCaseFields.length > 2) { + testCaseParameters = testCaseFields[2]; + } + + SvcLogicContext ctx = new SvcLogicContext(); + if (testCaseParameters != null) { + String[] testCaseParameterSettings = testCaseParameters.split(","); + + for (int i = 0 ; i < testCaseParameterSettings.length ; i++) { + String[] nameValue = testCaseParameterSettings[i].split("="); + if (nameValue != null) { + String name = nameValue[0]; + String value = ""; + if (nameValue.length > 1) { + value = nameValue[1]; + } + + ctx.setAttribute(name, value); + } + } + } + + testCaseFile = testCaseFile.trim(); + + if (testCaseFile.length() > 0) { + if (!testCaseFile.startsWith("/")) { + testCaseFile = "/"+testCaseFile; + } + URL testCaseUrl = getClass().getResource(testCaseFile); + if (testCaseUrl == null) { + fail("Could not resolve test case file "+testCaseFile); + } + + LinkedList graphs = parser.parse(testCaseUrl.getPath()); + + + assertNotNull(graphs); + + for (SvcLogicGraph graph: graphs) { + if (graph.getRpc().equals(testCaseMethod)) { + Properties props = ctx.toProperties(); + LOG.info("SvcLogicContext before executing "+testCaseMethod+":"); + for (Enumeration e1 = props.propertyNames(); e1.hasMoreElements() ; ) { + String propName = (String) e1.nextElement(); + LOG.info(propName+" = "+props.getProperty(propName)); + } + + svc.execute(graph, ctx); + + props = ctx.toProperties(); + LOG.info("SvcLogicContext after executing "+testCaseMethod+":"); + for (Enumeration e2 = props.propertyNames(); e2.hasMoreElements() ; ) { + String propName = (String) e2.nextElement(); + LOG.info(propName+" = "+props.getProperty(propName)); + } + } + } + + } + + + } + + + } catch (Exception e) { + LOG.error("Caught exception executing directed graphs", e); + fail("Exception executing graphs"); + } + } + + +} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java new file mode 100644 index 00000000..7c6eee9a --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 ONAP + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli.provider; + +import java.util.Map; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + + +public class VoidDummyPlugin implements SvcLogicJavaPlugin { + + public void dummy(Map parameters, SvcLogicContext ctx) throws SvcLogicException { + return; + } + +} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/BadPlugin.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/BadPlugin.java deleted file mode 100644 index d1ab4cfd..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/BadPlugin.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.Map; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; - - -public class BadPlugin implements SvcLogicJavaPlugin { - public String selectLunch(Map parameters, SvcLogicContext ctx) throws SvcLogicException { - String day = parameters.get("day"); - if (day == null || day.length() < 1) { - throw new SvcLogicException("What day is it?"); - } - switch (day) { - case ("monday"): { - return "pizza"; - } - case ("tuesday"): { - return "soup"; - } - case ("wednesday"): { - return "salad"; - } - case ("thursday"): { - return "sushi"; - } - case ("friday"): { - return "bbq"; - } - } - throw new SvcLogicException("Lunch cannot be served"); - } -} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutorTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutorTest.java deleted file mode 100644 index 3d43ee11..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutorTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.Map.Entry; - -import org.openecomp.sdnc.sli.DuplicateValueException; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicGraph; -import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; -import org.openecomp.sdnc.sli.SvcLogicNode; - -import junit.framework.TestCase; - -public class ExecuteNodeExecutorTest extends TestCase { - public class MockExecuteNodeExecutor extends ExecuteNodeExecutor { - - protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName) { - return (SvcLogicJavaPlugin) new LunchSelectorPlugin(); - } - - protected String evaluate(SvcLogicExpression expr, SvcLogicNode node, - SvcLogicContext ctx) throws SvcLogicException { - return "selectLunch"; - } - } - - public void testBadPlugin() throws DuplicateValueException, SvcLogicException { - LunchSelectorPlugin p = new LunchSelectorPlugin(); - MockExecuteNodeExecutor execute = new MockExecuteNodeExecutor(); - SvcLogicNode node = new SvcLogicNode(0, "", "", new SvcLogicGraph()); - node.setAttribute("method", "selectLunch"); - execute.execute(new SvcLogicServiceImpl(), new SvcLogicNode(0, "", "", new SvcLogicGraph()), new SvcLogicContext()); - } - -} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/LunchSelectorPlugin.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/LunchSelectorPlugin.java deleted file mode 100644 index b9156bcd..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/LunchSelectorPlugin.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.Map; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; - - - -public class LunchSelectorPlugin implements SvcLogicJavaPlugin { - public class UnknownLunchDayException extends Exception{ - - public UnknownLunchDayException(String string) { - super(string); - } - - } - class Sandwhich { - String meat; - String cheese; - - public Sandwhich(String meat, String cheese) { - this.meat = meat; - this.cheese = cheese; - } - } - - public String selectLunch(Map parameters, SvcLogicContext ctx) throws Exception { - String day = parameters.get("day"); - if (day == null || day.length() < 1) { - throw new UnknownLunchDayException("What day is it?"); - } - switch (day) { - case ("monday"): { - return "pizza"; - } - case ("tuesday"): { - return "soup"; - } - case ("wednesday"): { - return "salad"; - } - case ("thursday"): { - return "sushi"; - } - case ("friday"): { - return "bbq"; - } - } - throw new SvcLogicException("Lunch cannot be served"); - } - - public Sandwhich makeLunch(Map parameters, SvcLogicContext ctx) throws SvcLogicException { - return new Sandwhich("ham", "american"); - } -} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTest.java deleted file mode 100644 index a4e41bba..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import junit.framework.TestCase; - -public class MdsalHelperTest extends TestCase { - - public static final String pathToSdnPropertiesFile = "./src/test/resources/l3sdn.properties"; - - public void testSdnProperties() { - MdsalHelperTesterUtil.loadProperties(pathToSdnPropertiesFile); - assertEquals("synccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "Synccomplete")); - assertEquals("asynccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "asynccomplete")); - assertEquals("notifycomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "notifycomplete")); - assertEquals("service-configuration-operation", MdsalHelperTesterUtil.mapEnumeratedValue("rpc-name", - "ServiceConfigurationOperation")); - } - - public void testNegativeSdnProperties() { - assertNotSame("synccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "Synccomplete")); - } - -} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTesterUtil.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTesterUtil.java deleted file mode 100644 index 01e333f6..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTesterUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import org.openecomp.sdnc.sli.provider.MdsalHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MdsalHelperTesterUtil extends MdsalHelper { - - private static final Logger LOG = LoggerFactory.getLogger(MdsalHelperTesterUtil.class); - - //Normally static init of classes goes here for some weird classloader thing - static { - String str = "Hello World!"; - } - -} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/PluginTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/PluginTest.java deleted file mode 100644 index 035cd3e7..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/PluginTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicGraph; -import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; -import org.openecomp.sdnc.sli.SvcLogicNode; - -import junit.framework.TestCase; - -public class PluginTest extends TestCase { - - // The existing plugins work just like a VoidDummyPlugin - // They will return null simply because they are all void - // The attribute emitsOutcome will not be present, the expected outcome is success when no exception is thrown by the plugin - public void testOldPlugin() throws Exception { - ExecuteNodeExecutor executor = new ExecuteNodeExecutor(); - SvcLogicJavaPlugin plugin = new VoidDummyPlugin(); - - Class pluginClass = plugin.getClass(); - Method pluginMethod = pluginClass.getMethod("dummy", Map.class, SvcLogicContext.class); - Map parmMap = new HashMap(); - SvcLogicContext ctx = new SvcLogicContext(); - Object o = pluginMethod.invoke(plugin, parmMap, ctx); - - SvcLogicGraph graph = new SvcLogicGraph(); - SvcLogicNode node = new SvcLogicNode(1, "return", graph); - String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); - String outValue = executor.mapOutcome(o, emitsOutcome); - assertEquals("success",outValue); - } - - //Newer plugins can set the attribute emitsOutcome to true, if so they should return a string - //The string represents the outcome value - public void testNewPlugin() throws Exception { - ExecuteNodeExecutor executor = new ExecuteNodeExecutor(); - SvcLogicJavaPlugin plugin = new LunchSelectorPlugin(); - - Class pluginClass = plugin.getClass(); - Method pluginMethod = pluginClass.getMethod("selectLunch", Map.class, SvcLogicContext.class); - - Map parmMap = new HashMap(); - SvcLogicContext ctx = new SvcLogicContext(); - - parmMap.put("day", "monday"); - Object o = pluginMethod.invoke(plugin, parmMap, ctx); - SvcLogicGraph graph = new SvcLogicGraph(); - SvcLogicNode node = new SvcLogicNode(1, "return", graph); - node.setAttribute("emitsOutcome", "true"); - String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); - String outValue = executor.mapOutcome(o, emitsOutcome); - assertEquals("pizza", outValue); - - parmMap.put("day", "tuesday"); - outValue = (String) pluginMethod.invoke(plugin, parmMap, ctx); - o = pluginMethod.invoke(plugin, parmMap, ctx); - outValue = executor.mapOutcome(o, emitsOutcome); - assertEquals("soup",outValue); - - } - - //APPC had some legacy plugins returning objects which should not be treated as outcomes - //The attribute emitsOutcome will not be set - //The outcome should be success as it has always been - public void testObjPlugin() throws Exception{ - ExecuteNodeExecutor executor = new ExecuteNodeExecutor(); - SvcLogicJavaPlugin plugin = new LunchSelectorPlugin(); - - Class pluginClass = plugin.getClass(); - Method pluginMethod = pluginClass.getMethod("makeLunch", Map.class, SvcLogicContext.class); - - Map parmMap = new HashMap(); - SvcLogicContext ctx = new SvcLogicContext(); - Object o = pluginMethod.invoke(plugin, parmMap, ctx); - SvcLogicGraph graph = new SvcLogicGraph(); - SvcLogicNode node = new SvcLogicNode(1, "return", graph); - String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); - String outValue = executor.mapOutcome(o, emitsOutcome); - assertEquals("success",outValue); - } - -} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java deleted file mode 100644 index 61815488..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicExprListener; -import org.openecomp.sdnc.sli.SvcLogicExpression; -import org.openecomp.sdnc.sli.SvcLogicExpressionFactory; -import org.openecomp.sdnc.sli.SvcLogicGraph; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.provider.SvcLogicExpressionResolver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import junit.framework.Assert; -import junit.framework.TestCase; - -public class SvcLogicExpressionResolverTest extends TestCase { - - - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicExpressionResolver.class); - - public void testEvaluate() - { - InputStream testStr = getClass().getResourceAsStream("/expression.tests"); - BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); - - try - { - SvcLogicContext ctx = new SvcLogicContext(); - SvcLogicGraph graph = new SvcLogicGraph(); - SvcLogicNode node = new SvcLogicNode(1, "return", graph); - graph.setRootNode(node); - - String line = null; - int lineNo = 0; - while ((line = testsReader.readLine()) != null) { - ++lineNo; - if (line.startsWith("#")) - { - String testExpr = line.trim().substring(1).trim(); - String[] nameValue = testExpr.split("="); - String name = nameValue[0].trim(); - String value = nameValue[1].trim(); - - if (name.startsWith("$")) - { - LOG.info("Setting context attribute "+name+" = "+value); - ctx.setAttribute(name.substring(1), value); - } - else - { - - LOG.info("Setting node attribute "+name+" = "+value); - node.setAttribute(name, value); - - } - } - else - { - // if the line contains #, what comes before is the expression to evaluate, and what comes after - // is the expected value - String[] substrings = line.split("#"); - String expectedValue = substrings.length > 1 ? substrings[1].trim() : null; - String testExpr = substrings[0].trim(); - - LOG.info("Parsing expression "+testExpr); - SvcLogicExpression expr = SvcLogicExpressionFactory.parse(testExpr); - if (expr == null) - { - fail("Unable to parse expression "+testExpr); - } - else - { - LOG.info("Evaluating parsed expression "+expr.asParsedExpr()); - String exprValue = SvcLogicExpressionResolver.evaluate(expr, node, ctx); - if (exprValue == null) - { - fail("Unable to evaluate expression "+testExpr); - } - else - { - LOG.info("Expression " + testExpr + " evaluates to " + exprValue); - if (expectedValue != null) { - Assert.assertEquals("Line " + lineNo + ": " + testExpr, expectedValue, exprValue); - } - } - } - } - } - } - catch (Exception e) - { - LOG.error("Caught exception", e); - fail("Caught exception"); - } - } - -} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicGraphExecutorTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicGraphExecutorTest.java deleted file mode 100644 index 2e8b35e1..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicGraphExecutorTest.java +++ /dev/null @@ -1,212 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Properties; - -import org.openecomp.sdnc.sli.MetricLogger; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicGraph; -import org.openecomp.sdnc.sli.SvcLogicNode; -import org.openecomp.sdnc.sli.SvcLogicParser; -import org.openecomp.sdnc.sli.SvcLogicStore; -import org.openecomp.sdnc.sli.SvcLogicStoreFactory; -import org.openecomp.sdnc.sli.provider.BlockNodeExecutor; -import org.openecomp.sdnc.sli.provider.CallNodeExecutor; -import org.openecomp.sdnc.sli.provider.ConfigureNodeExecutor; -import org.openecomp.sdnc.sli.provider.DeleteNodeExecutor; -import org.openecomp.sdnc.sli.provider.ExecuteNodeExecutor; -import org.openecomp.sdnc.sli.provider.ExistsNodeExecutor; -import org.openecomp.sdnc.sli.provider.ForNodeExecutor; -import org.openecomp.sdnc.sli.provider.GetResourceNodeExecutor; -import org.openecomp.sdnc.sli.provider.IsAvailableNodeExecutor; -import org.openecomp.sdnc.sli.provider.NotifyNodeExecutor; -import org.openecomp.sdnc.sli.provider.RecordNodeExecutor; -import org.openecomp.sdnc.sli.provider.ReleaseNodeExecutor; -import org.openecomp.sdnc.sli.provider.ReserveNodeExecutor; -import org.openecomp.sdnc.sli.provider.ReturnNodeExecutor; -import org.openecomp.sdnc.sli.provider.SaveNodeExecutor; -import org.openecomp.sdnc.sli.provider.SetNodeExecutor; -import org.openecomp.sdnc.sli.provider.SvcLogicNodeExecutor; -import org.openecomp.sdnc.sli.provider.SvcLogicServiceImpl; -import org.openecomp.sdnc.sli.provider.SwitchNodeExecutor; -import org.openecomp.sdnc.sli.provider.UpdateNodeExecutor; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import junit.framework.TestCase; - -public class SvcLogicGraphExecutorTest extends TestCase { - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicGraph.class); - - private static final Map BUILTIN_NODES = new HashMap() { - { - put("block", new BlockNodeExecutor()); - put("call", new CallNodeExecutor()); - put("configure", new ConfigureNodeExecutor()); - put("delete", new DeleteNodeExecutor()); - put("execute", new ExecuteNodeExecutor()); - put("exists", new ExistsNodeExecutor()); - put("for", new ForNodeExecutor()); - put("get-resource", new GetResourceNodeExecutor()); - put("is-available", new IsAvailableNodeExecutor()); - put("notify", new NotifyNodeExecutor()); - put("record", new RecordNodeExecutor()); - put("release", new ReleaseNodeExecutor()); - put("reserve", new ReserveNodeExecutor()); - put("return", new ReturnNodeExecutor()); - put("save", new SaveNodeExecutor()); - put("set", new SetNodeExecutor()); - put("switch", new SwitchNodeExecutor()); - put("update", new UpdateNodeExecutor()); - - } - }; - - public void testExecute() { - - try { - InputStream testStr = getClass().getResourceAsStream("/executor.tests"); - BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); - - InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr); - - assertNotNull(store); - - store.registerNodeType("switch"); - store.registerNodeType("block"); - store.registerNodeType("get-resource"); - store.registerNodeType("reserve"); - store.registerNodeType("is-available"); - store.registerNodeType("exists"); - store.registerNodeType("configure"); - store.registerNodeType("return"); - store.registerNodeType("record"); - store.registerNodeType("allocate"); - store.registerNodeType("release"); - store.registerNodeType("for"); - store.registerNodeType("set"); - SvcLogicParser parser = new SvcLogicParser(store); - - // Loop through executor tests - - SvcLogicServiceImpl svc = new SvcLogicServiceImpl(); - - for (String nodeType : BUILTIN_NODES.keySet()) { - - LOG.info("SLI - registering node executor for node type "+nodeType); - - svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); - - } - String testCaseLine = null; - while ((testCaseLine = testsReader.readLine()) != null) { - - String[] testCaseFields = testCaseLine.split(":"); - String testCaseFile = testCaseFields[0]; - String testCaseMethod = testCaseFields[1]; - String testCaseParameters = null; - - if (testCaseFields.length > 2) { - testCaseParameters = testCaseFields[2]; - } - - SvcLogicContext ctx = new SvcLogicContext(); - if (testCaseParameters != null) { - String[] testCaseParameterSettings = testCaseParameters.split(","); - - for (int i = 0 ; i < testCaseParameterSettings.length ; i++) { - String[] nameValue = testCaseParameterSettings[i].split("="); - if (nameValue != null) { - String name = nameValue[0]; - String value = ""; - if (nameValue.length > 1) { - value = nameValue[1]; - } - - ctx.setAttribute(name, value); - } - } - } - - testCaseFile = testCaseFile.trim(); - - if (testCaseFile.length() > 0) { - if (!testCaseFile.startsWith("/")) { - testCaseFile = "/"+testCaseFile; - } - URL testCaseUrl = getClass().getResource(testCaseFile); - if (testCaseUrl == null) { - fail("Could not resolve test case file "+testCaseFile); - } - - LinkedList graphs = parser.parse(testCaseUrl.getPath()); - - - assertNotNull(graphs); - - for (SvcLogicGraph graph: graphs) { - if (graph.getRpc().equals(testCaseMethod)) { - Properties props = ctx.toProperties(); - LOG.info("SvcLogicContext before executing "+testCaseMethod+":"); - for (Enumeration e1 = props.propertyNames(); e1.hasMoreElements() ; ) { - String propName = (String) e1.nextElement(); - LOG.info(propName+" = "+props.getProperty(propName)); - } - - svc.execute(graph, ctx); - - props = ctx.toProperties(); - LOG.info("SvcLogicContext after executing "+testCaseMethod+":"); - for (Enumeration e2 = props.propertyNames(); e2.hasMoreElements() ; ) { - String propName = (String) e2.nextElement(); - LOG.info(propName+" = "+props.getProperty(propName)); - } - } - } - - } - - - } - - - } catch (Exception e) { - LOG.error("Caught exception executing directed graphs", e); - fail("Exception executing graphs"); - } - } - - -} diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/VoidDummyPlugin.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/VoidDummyPlugin.java deleted file mode 100644 index 6c8214ab..00000000 --- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/VoidDummyPlugin.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli.provider; - -import java.util.Map; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; - - - -public class VoidDummyPlugin implements SvcLogicJavaPlugin { - - public void dummy(Map parameters, SvcLogicContext ctx) throws SvcLogicException { - return; - } - -} diff --git a/sli/provider/src/test/resources/l3sdn_logic_v10.xml b/sli/provider/src/test/resources/l3sdn_logic_v10.xml index d81b8b78..56e1a81e 100644 --- a/sli/provider/src/test/resources/l3sdn_logic_v10.xml +++ b/sli/provider/src/test/resources/l3sdn_logic_v10.xml @@ -1,10 +1,9 @@