From 7f8fd751c9272c33be0b74f02cd962dd615b63d3 Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Fri, 30 Nov 2018 18:00:42 +0000 Subject: refactor sli-provider split sli-provider into sli-provider and sli-provider-base Change-Id: I7b7edb767c04c9a6caf72a9172f49518655e33b7 Issue-ID: CCSDK-778 Signed-off-by: Smokowski, Kevin (ks6305) --- sli/pom.xml | 1 + sli/provider-base/pom.xml | 61 +++ .../base/AbstractSvcLogicNodeExecutor.java | 93 ++++ .../core/sli/provider/base/BlockNodeExecutor.java | 76 +++ .../core/sli/provider/base/BreakNodeExecutor.java | 42 ++ .../core/sli/provider/base/CallNodeExecutor.java | 175 ++++++ .../sli/provider/base/ConfigureNodeExecutor.java | 248 +++++++++ .../core/sli/provider/base/DeleteNodeExecutor.java | 74 +++ .../sli/provider/base/ExecuteNodeExecutor.java | 141 +++++ .../core/sli/provider/base/ExistsNodeExecutor.java | 75 +++ .../core/sli/provider/base/ExitNodeExecutor.java | 42 ++ .../core/sli/provider/base/ForNodeExecutor.java | 109 ++++ .../sli/provider/base/GetResourceNodeExecutor.java | 99 ++++ .../sli/provider/base/IsAvailableNodeExecutor.java | 71 +++ .../core/sli/provider/base/NotifyNodeExecutor.java | 74 +++ .../core/sli/provider/base/RecordNodeExecutor.java | 82 +++ .../sli/provider/base/ReleaseNodeExecutor.java | 73 +++ .../sli/provider/base/ReserveNodeExecutor.java | 87 +++ .../core/sli/provider/base/ReturnNodeExecutor.java | 78 +++ .../core/sli/provider/base/SaveNodeExecutor.java | 107 ++++ .../core/sli/provider/base/SetNodeExecutor.java | 179 ++++++ .../provider/base/SvcLogicExpressionResolver.java | 605 +++++++++++++++++++++ .../provider/base/SvcLogicPropertiesProvider.java | 28 + .../core/sli/provider/base/SvcLogicResolver.java | 17 + .../sli/provider/base/SvcLogicServiceBase.java | 66 +++ .../sli/provider/base/SvcLogicServiceImplBase.java | 189 +++++++ .../core/sli/provider/base/SwitchNodeExecutor.java | 63 +++ .../core/sli/provider/base/UpdateNodeExecutor.java | 103 ++++ .../core/sli/provider/base/WhileNodeExecutor.java | 75 +++ .../sli/core/sli/provider/base/BadPlugin.java | 56 ++ .../sli/core/sli/provider/base/DummyAdaptor.java | 54 ++ .../sli/core/sli/provider/base/DummyRecorder.java | 14 + .../sli/core/sli/provider/base/DummyResource.java | 97 ++++ .../sli/provider/base/ExecuteNodeExecutorTest.java | 69 +++ .../sli/provider/base/LunchSelectorPlugin.java | 78 +++ .../sli/core/sli/provider/base/PluginTest.java | 108 ++++ .../sli/provider/base/SetNodeExecutorTest.java | 220 ++++++++ .../base/SvcLogicExpressionResolverTest.java | 123 +++++ .../core/sli/provider/base/VoidDummyPlugin.java | 38 ++ .../test/resources/clearMultipleArrayValues.xml | 23 + .../test/resources/clearNestedSubArrayValues.xml | 27 + .../src/test/resources/clearSingleArrayValues.xml | 23 + .../test/resources/clearSingleSubArrayValues.xml | 27 + .../src/test/resources/clearSubArrayValues.xml | 24 + .../src/test/resources/clearValues.xml | 22 + .../src/test/resources/copyValues.xml | 16 + .../src/test/resources/expression.tests | 24 + .../src/test/resources/simplelogger.properties | 22 + sli/provider/pom.xml | 7 +- .../sli/core/sli/provider/BlockNodeExecutor.java | 75 --- .../sli/core/sli/provider/BreakNodeExecutor.java | 42 -- .../sli/core/sli/provider/CallNodeExecutor.java | 175 ------ .../core/sli/provider/ConfigureNodeExecutor.java | 248 --------- .../sli/core/sli/provider/DeleteNodeExecutor.java | 74 --- .../sli/core/sli/provider/ExecuteNodeExecutor.java | 141 ----- .../sli/core/sli/provider/ExistsNodeExecutor.java | 75 --- .../sli/core/sli/provider/ExitNodeExecutor.java | 42 -- .../sli/core/sli/provider/ForNodeExecutor.java | 109 ---- .../core/sli/provider/GetResourceNodeExecutor.java | 99 ---- .../core/sli/provider/IsAvailableNodeExecutor.java | 71 --- .../sli/core/sli/provider/NotifyNodeExecutor.java | 74 --- .../sli/core/sli/provider/RecordNodeExecutor.java | 82 --- .../sli/core/sli/provider/ReleaseNodeExecutor.java | 73 --- .../sli/core/sli/provider/ReserveNodeExecutor.java | 87 --- .../sli/core/sli/provider/ReturnNodeExecutor.java | 78 --- .../sli/core/sli/provider/SaveNodeExecutor.java | 107 ---- .../sli/core/sli/provider/SetNodeExecutor.java | 179 ------ .../core/sli/provider/SvcLogicAdaptorFactory.java | 5 +- .../core/sli/provider/SvcLogicClassResolver.java | 81 ++- .../sli/provider/SvcLogicExpressionResolver.java | 605 --------------------- .../core/sli/provider/SvcLogicNodeExecutor.java | 94 ---- .../sli/provider/SvcLogicPropertiesProvider.java | 28 - .../provider/SvcLogicPropertiesProviderImpl.java | 1 + .../sli/core/sli/provider/SvcLogicService.java | 39 +- .../sli/core/sli/provider/SvcLogicServiceImpl.java | 143 +---- .../sli/core/sli/provider/SwitchNodeExecutor.java | 63 --- .../sli/core/sli/provider/UpdateNodeExecutor.java | 103 ---- .../sli/core/sli/provider/WhileNodeExecutor.java | 75 --- .../ccsdk/sli/core/sli/provider/BadPlugin.java | 56 -- .../ccsdk/sli/core/sli/provider/DummyAdaptor.java | 54 -- .../ccsdk/sli/core/sli/provider/DummyRecorder.java | 14 - .../ccsdk/sli/core/sli/provider/DummyResource.java | 97 ---- .../core/sli/provider/ExecuteNodeExecutorTest.java | 60 -- .../sli/provider/ITCaseSvcLogicGraphExecutor.java | 30 +- .../sli/core/sli/provider/LunchSelectorPlugin.java | 78 --- .../ccsdk/sli/core/sli/provider/PluginTest.java | 108 ---- .../sli/core/sli/provider/SetNodeExecutorTest.java | 219 -------- .../provider/SvcLogicExpressionResolverTest.java | 123 ----- .../sli/core/sli/provider/VoidDummyPlugin.java | 38 -- .../test/resources/clearMultipleArrayValues.xml | 23 - .../test/resources/clearNestedSubArrayValues.xml | 27 - .../src/test/resources/clearSingleArrayValues.xml | 23 - .../test/resources/clearSingleSubArrayValues.xml | 27 - .../src/test/resources/clearSubArrayValues.xml | 24 - sli/provider/src/test/resources/clearValues.xml | 22 - sli/provider/src/test/resources/copyValues.xml | 16 - sli/provider/src/test/resources/expression.tests | 24 - sliPluginUtils/provider/testFileName | 1 - sliapi/provider/pom.xml | 5 + .../ccsdk/sli/core/sliapi/TestSliapiProvider.java | 42 +- 100 files changed, 4336 insertions(+), 4048 deletions(-) create mode 100644 sli/provider-base/pom.xml create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/AbstractSvcLogicNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BlockNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BreakNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/CallNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ConfigureNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/DeleteNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExistsNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExitNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ForNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/GetResourceNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/IsAvailableNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/NotifyNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/RecordNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReleaseNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReserveNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReturnNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SaveNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolver.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicPropertiesProvider.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicResolver.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SwitchNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/UpdateNodeExecutor.java create mode 100644 sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/WhileNodeExecutor.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/BadPlugin.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyAdaptor.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyRecorder.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyResource.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutorTest.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/LunchSelectorPlugin.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/PluginTest.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutorTest.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java create mode 100644 sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/VoidDummyPlugin.java create mode 100644 sli/provider-base/src/test/resources/clearMultipleArrayValues.xml create mode 100644 sli/provider-base/src/test/resources/clearNestedSubArrayValues.xml create mode 100644 sli/provider-base/src/test/resources/clearSingleArrayValues.xml create mode 100644 sli/provider-base/src/test/resources/clearSingleSubArrayValues.xml create mode 100644 sli/provider-base/src/test/resources/clearSubArrayValues.xml create mode 100644 sli/provider-base/src/test/resources/clearValues.xml create mode 100644 sli/provider-base/src/test/resources/copyValues.xml create mode 100644 sli/provider-base/src/test/resources/expression.tests create mode 100644 sli/provider-base/src/test/resources/simplelogger.properties delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java delete mode 100755 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java delete mode 100755 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExitNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java delete mode 100755 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolver.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java delete mode 100644 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java delete mode 100755 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java delete mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java delete mode 100644 sli/provider/src/test/resources/clearMultipleArrayValues.xml delete mode 100644 sli/provider/src/test/resources/clearNestedSubArrayValues.xml delete mode 100644 sli/provider/src/test/resources/clearSingleArrayValues.xml delete mode 100644 sli/provider/src/test/resources/clearSingleSubArrayValues.xml delete mode 100644 sli/provider/src/test/resources/clearSubArrayValues.xml delete mode 100644 sli/provider/src/test/resources/clearValues.xml delete mode 100644 sli/provider/src/test/resources/copyValues.xml delete mode 100755 sli/provider/src/test/resources/expression.tests delete mode 100644 sliPluginUtils/provider/testFileName diff --git a/sli/pom.xml b/sli/pom.xml index 7b1fd9d2..7060541a 100755 --- a/sli/pom.xml +++ b/sli/pom.xml @@ -21,6 +21,7 @@ + provider-base model common provider diff --git a/sli/provider-base/pom.xml b/sli/provider-base/pom.xml new file mode 100644 index 00000000..63cba830 --- /dev/null +++ b/sli/provider-base/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + + org.onap.ccsdk.parent + binding-parent + 1.2.0-SNAPSHOT + + + + org.onap.ccsdk.sli.core + sli-provider-base + 0.4.0-SNAPSHOT + + + + + org.onap.ccsdk.sli.core + dblib-provider + ${project.version} + + + + + + + org.onap.ccsdk.sli.core + sli-common + ${project.version} + compile + + + + org.slf4j + slf4j-api + + + commons-lang + commons-lang + compile + + + + + junit + junit + test + + + + org.mockito + mockito-core + test + + + + + diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/AbstractSvcLogicNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/AbstractSvcLogicNodeExecutor.java new file mode 100644 index 00000000..a51accbb --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/AbstractSvcLogicNodeExecutor.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class AbstractSvcLogicNodeExecutor { + protected SvcLogicResolver resolver; + public abstract SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException; + + private static final Logger LOG = LoggerFactory.getLogger(AbstractSvcLogicNodeExecutor.class); + + protected String evaluateNodeTest(SvcLogicNode node, SvcLogicContext ctx) + throws SvcLogicException { + if (node == null) { + return null; + } + + return (SvcLogicExpressionResolver.evaluate(node.getAttribute("test"), + node, ctx)); + + } + + public void setResolver(SvcLogicResolver resolver) { + this.resolver = resolver; + } + + protected SvcLogicAdaptor getAdaptor(String adaptorName) { + return resolver.getSvcLogicAdaptor(adaptorName); + } + + protected SvcLogicResource getSvcLogicResource(String resourceName) { + return resolver.getSvcLogicResource(resourceName); + } + + protected SvcLogicRecorder getSvcLogicRecorder(String recorderName) { + return resolver.getSvcLogicRecorder(recorderName); + } + + protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){ + return resolver.getSvcLogicJavaPlugin(pluginName); + } + + protected SvcLogicNode getNextNode(SvcLogicNode node, String outValue) { + 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-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BlockNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BlockNodeExecutor.java new file mode 100644 index 00000000..7aaf795b --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BlockNodeExecutor.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(BlockNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BreakNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BreakNodeExecutor.java new file mode 100644 index 00000000..603d7abc --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BreakNodeExecutor.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(BreakNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/CallNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/CallNodeExecutor.java new file mode 100644 index 00000000..284795bd --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/CallNodeExecutor.java @@ -0,0 +1,175 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(CallNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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 = svc.getStore(); + String errorMessage = "Parent " + parentGraph + " failed to call child [" + module + "," + rpc + "," + version + "," + mode + "] because the graph could not be found"; + boolean graphWasCalled = false; + if (store != null) { + SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode); + if (calledGraph != null) { + LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString()); + ctx.setAttribute("currentGraph", calledGraph.toString()); + svc.execute(calledGraph, ctx); + outValue = ctx.getStatus(); + graphWasCalled = true; + } else { + LOG.debug(errorMessage); + } + } 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"); + } + } + + if (graphWasCalled == false) { + if (node.getOutcomeValue("catch") != null) { + nextNode = node.getOutcomeValue("catch"); + LOG.debug("graph could not be called, but catch node was found and will be executed"); + } else { + LOG.debug("graph could not be called and no catch node was found, throwing exception"); + throw new SvcLogicException(errorMessage); + } + } + + ctx.setAttribute("currentGraph", parentGraph); + ctx.setAttribute("parentGraph", null); + + return (nextNode); + + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ConfigureNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ConfigureNodeExecutor.java new file mode 100644 index 00000000..5b1d9efe --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ConfigureNodeExecutor.java @@ -0,0 +1,248 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + private static final Logger LOG = LoggerFactory + .getLogger(ConfigureNodeExecutor.class); + + public SvcLogicNode execute(SvcLogicServiceBase 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-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/DeleteNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/DeleteNodeExecutor.java new file mode 100644 index 00000000..2393a159 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/DeleteNodeExecutor.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(DeleteNodeExecutor.class); + private static final String FAILURE="failure"; + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java new file mode 100644 index 00000000..357f11d0 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java @@ -0,0 +1,141 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + 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(SvcLogicServiceBase 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"); + } + } + + } + return (getNextNode(node, outValue)); + } + + 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-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExistsNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExistsNodeExecutor.java new file mode 100644 index 00000000..397c5f32 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExistsNodeExecutor.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(ExistsNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExitNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExitNodeExecutor.java new file mode 100644 index 00000000..828e1015 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExitNodeExecutor.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +import org.onap.ccsdk.sli.core.sli.ExitNodeException; +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 ExitNodeExecutor extends AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(ExitNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + String message = "ExitNodeExecutor encountered exit with nodeId " + node.getNodeId(); + LOG.debug(message); + throw new ExitNodeException(message); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ForNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ForNodeExecutor.java new file mode 100644 index 00000000..8ca1f32d --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ForNodeExecutor.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(ForNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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.error("ForNodeExecutor caught break",br); + } + return (null); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/GetResourceNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/GetResourceNodeExecutor.java new file mode 100644 index 00000000..a2f1c63d --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/GetResourceNodeExecutor.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(GetResourceNodeExecutor.class); + + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/IsAvailableNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/IsAvailableNodeExecutor.java new file mode 100644 index 00000000..a93c0d6f --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/IsAvailableNodeExecutor.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(IsAvailableNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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"; + + 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/NotifyNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/NotifyNodeExecutor.java new file mode 100644 index 00000000..de59a4b7 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/NotifyNodeExecutor.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(NotifyNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/RecordNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/RecordNodeExecutor.java new file mode 100644 index 00000000..3522c0a7 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/RecordNodeExecutor.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(RecordNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReleaseNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReleaseNodeExecutor.java new file mode 100644 index 00000000..ed9d7d7d --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReleaseNodeExecutor.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(ReleaseNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReserveNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReserveNodeExecutor.java new file mode 100644 index 00000000..8e21a459 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReserveNodeExecutor.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(ReserveNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReturnNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReturnNodeExecutor.java new file mode 100644 index 00000000..d2fe35d7 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReturnNodeExecutor.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(ReturnNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SaveNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SaveNodeExecutor.java new file mode 100644 index 00000000..2dfc4074 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SaveNodeExecutor.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(SaveNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutor.java new file mode 100644 index 00000000..8bebb336 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutor.java @@ -0,0 +1,179 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(SetNodeExecutor.class); + protected final String arrayPattern = "\\[\\d*\\]"; + + @Override + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) + throws SvcLogicException { + execute(node,ctx); + return null; + } + + public void execute(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 { + // Backticks symbolize the variable should be handled as an expression instead of as a variable + if (curName.trim().startsWith("`")) { + int lastParen = curName.lastIndexOf("`"); + String evalExpr = curName.trim().substring(1, lastParen); + SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(evalExpr); + lhsVarName = SvcLogicExpressionResolver.evaluate(lhsExpr, node, ctx); + } else { + 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); + } + + HashMap parmsToAdd = new HashMap(); + + for (String sourceVarName : ctx.getAttributeKeySet()) { + if (sourceVarName.startsWith(rhsRoot)) { + String targetVar = lhsPrefix + "." + sourceVarName.substring(rhsRoot.length()); + LOG.debug("Copying {} value to {}", sourceVarName, 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 + LinkedList parmsToRemove = new LinkedList(); + String prefix = lhsVarName + "."; + String arrayPrefix = lhsVarName + "["; + //Clear length value in case an array exists with this prefix + String lengthParamName = lhsVarName + "_length"; + LOG.debug("Unsetting {} because prefix {} is being cleared.", lengthParamName, prefix); + + for (String curCtxVarname : ctx.getAttributeKeySet()) { + String curCtxVarnameMatchingValue = curCtxVarname; + //Special handling for reseting array values, strips out brackets and any numbers between the brackets + //when testing if a context memory value starts with a prefix + if(!prefix.contains("[") && curCtxVarnameMatchingValue.contains("[")) { + curCtxVarnameMatchingValue = curCtxVarname.replaceAll(arrayPattern, "") + "."; + } + if (curCtxVarnameMatchingValue.startsWith(prefix)) { + LOG.debug("Unsetting {} because matching value {} starts with the prefix {}", curCtxVarname, curCtxVarnameMatchingValue, prefix); + parmsToRemove.add(curCtxVarname); + }else if (curCtxVarnameMatchingValue.startsWith(lengthParamName)) { + LOG.debug("Unsetting {} because matching value {} starts with the lengthParamName {}", curCtxVarname, curCtxVarnameMatchingValue, lengthParamName); + parmsToRemove.add(curCtxVarname); + }else if (curCtxVarnameMatchingValue.startsWith(arrayPrefix)) { + LOG.debug("Unsetting {} because matching value {} starts with the arrayPrefix {}", curCtxVarname, curCtxVarnameMatchingValue, arrayPrefix); + 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 {} already set and only-if-unset is true, so not overriding", lhsVarName); + } + } + if (setValue) { + String curValue = SvcLogicExpressionResolver.evaluate(curEnt.getValue(), node, ctx); + + if (LOG.isDebugEnabled()) { + LOG.trace("Parameter value {} resolves to {}", curEnt.getValue().asParsedExpr(), curValue); + LOG.debug("Setting context attribute {} to {}", lhsVarName, curValue); + } + ctx.setAttribute(lhsVarName, curValue); + } + } + } + } +} + diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolver.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolver.java new file mode 100644 index 00000000..779be9e9 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolver.java @@ -0,0 +1,605 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicPropertiesProvider.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicPropertiesProvider.java new file mode 100644 index 00000000..fc108f95 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicPropertiesProvider.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * onap + * ================================================================================ + * Copyright (C) 2016 - 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.base; + +import java.util.Properties; + +public interface SvcLogicPropertiesProvider { + + public Properties getProperties();; +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicResolver.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicResolver.java new file mode 100644 index 00000000..08b67595 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicResolver.java @@ -0,0 +1,17 @@ +package org.onap.ccsdk.sli.core.sli.provider.base; + +import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; + +public interface SvcLogicResolver { + + abstract SvcLogicResource getSvcLogicResource(String resourceName); + + abstract SvcLogicRecorder getSvcLogicRecorder(String recorderName); + + abstract SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName); + + abstract SvcLogicAdaptor getSvcLogicAdaptor(String adaptorName); +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java new file mode 100644 index 00000000..8c436fef --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +import java.util.Properties; +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; + +public interface SvcLogicServiceBase { + + + /** + * 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 + */ + 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 + * + * + */ + Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException; + + SvcLogicStore getStore() throws SvcLogicException; + + SvcLogicContext execute(SvcLogicGraph calledGraph, SvcLogicContext ctx) throws SvcLogicException; + + SvcLogicNode executeNode(SvcLogicNode nextNode, SvcLogicContext ctx) throws SvcLogicException; + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java new file mode 100644 index 00000000..92fdb9a3 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java @@ -0,0 +1,189 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Modifications Copyright (C) 2018 IBM. + * ================================================================================ + * 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.base; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.ExitNodeException; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + +public class SvcLogicServiceImplBase implements SvcLogicServiceBase { + protected SvcLogicResolver resolver; + protected 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()); + put("while", new WhileNodeExecutor()); + put("exit", new ExitNodeExecutor()); + } + }; + + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicServiceImplBase.class); + protected HashMap nodeExecutors = null; + protected Properties properties; + protected SvcLogicStore store; + protected static final String CURRENT_GRAPH="currentGraph"; + + public SvcLogicServiceImplBase(SvcLogicStore store) { + this.store = store; + } + + protected void registerExecutors() { + + LOG.info("Entered register executors"); + for (String nodeType : BUILTIN_NODES.keySet()) { + LOG.info("SLI - registering node executor for node type " + nodeType); + registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); + } + LOG.info("Done registerExecutors"); + } + + public void registerExecutor(String nodeName, AbstractSvcLogicNodeExecutor executor) { + if (nodeExecutors == null) { + nodeExecutors = new HashMap<>(); + } + LOG.info("SLI - registering executor for node type {}", nodeName); + executor.setResolver(resolver); + nodeExecutors.put(nodeName, executor); + } + + 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()); + + MDC.put(CURRENT_GRAPH, graph.toString()); + + SvcLogicNode curNode = graph.getRootNode(); + LOG.info("About to execute graph {}", graph.toString()); + try { + while (curNode != null) { + resetContext(); + SvcLogicNode nextNode = executeNode(curNode, ctx); + curNode = nextNode; + } + } catch (ExitNodeException e) { + LOG.debug("SvcLogicServiceImpl caught ExitNodeException"); + } + MDC.remove("nodeId"); + MDC.remove(CURRENT_GRAPH); + + return (ctx); + } + + protected void resetContext() { + + } + + public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + if (node == null) { + return (null); + } + + LOG.info("About to execute node # {} ({})", node.getNodeId(), node.getNodeType()); + + if (LOG.isDebugEnabled()) { + LOG.debug("Executing node " + node.getNodeId() + " of " + node.getGraph().getRpc()); + } + + AbstractSvcLogicNodeExecutor executor = nodeExecutors.get(node.getNodeType()); + + if (executor != null) { + LOG.debug("Executing node executor for node type {} - {}", node.getNodeType(), + executor.getClass().getName()); + + MDC.put("nodeId", node.getNodeId() + " (" + node.getNodeType() + ")"); + return (executor.execute(this, node, ctx)); + } else { + throw new SvcLogicException("Attempted to execute a node of type " + node.getNodeType() + ", but no executor was registered for this type"); + } + } + + @Override + public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException { + return (store.hasGraph(module, rpc, version, mode)); + } + + @Override + public Properties execute(String module, String rpc, String version, String mode, Properties props) + throws SvcLogicException { + 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(CURRENT_GRAPH, graph.toString()); + ctx.setAttribute("X-ECOMP-RequestID", MDC.get("X-ECOMP-RequestID")); + execute(graph, ctx); + return (ctx.toProperties()); + } + + @Override + public SvcLogicStore getStore() throws SvcLogicException { + return this.store; + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SwitchNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SwitchNodeExecutor.java new file mode 100644 index 00000000..2186a38e --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SwitchNodeExecutor.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory + .getLogger(SwitchNodeExecutor.class); + + @Override + + public SvcLogicNode execute(SvcLogicServiceBase 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-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/UpdateNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/UpdateNodeExecutor.java new file mode 100644 index 00000000..c4c8faa8 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/UpdateNodeExecutor.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(UpdateNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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); + } + return (getNextNode(node, outValue)); + } + +} diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/WhileNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/WhileNodeExecutor.java new file mode 100644 index 00000000..c01e2f51 --- /dev/null +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/WhileNodeExecutor.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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 AbstractSvcLogicNodeExecutor { + + private static final Logger LOG = LoggerFactory.getLogger(WhileNodeExecutor.class); + + @Override + public SvcLogicNode execute(SvcLogicServiceBase 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-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/BadPlugin.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/BadPlugin.java new file mode 100644 index 00000000..6c5877eb --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/BadPlugin.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyAdaptor.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyAdaptor.java new file mode 100644 index 00000000..58582e0e --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyAdaptor.java @@ -0,0 +1,54 @@ +/** + * + */ +package org.onap.ccsdk.sli.core.sli.provider.base; + +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +/** + * @author dt5972 + * + */ + +public class DummyAdaptor implements SvcLogicAdaptor { + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#configure(java.lang.String, java.util.Map, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public ConfigStatus configure(String key, Map parameters, SvcLogicContext ctx) { + + if ("ALREADY_ACTIVE".equalsIgnoreCase(key)) { + return ConfigStatus.ALREADY_ACTIVE; + } else if ("NOT_FOUND".equalsIgnoreCase(key)) { + return ConfigStatus.NOT_FOUND; + }else if ("NOT_READY".equalsIgnoreCase(key)) { + return ConfigStatus.NOT_READY; + } else if ("FAILURE".equalsIgnoreCase(key)) { + return ConfigStatus.FAILURE; + } else if ("SUCCESS".equalsIgnoreCase(key)) { + return ConfigStatus.SUCCESS; + } + + return ConfigStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#activate(java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public ConfigStatus activate(String key, SvcLogicContext ctx) { + return ConfigStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#deactivate(java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public ConfigStatus deactivate(String key, SvcLogicContext ctx) { + return ConfigStatus.SUCCESS; + } + +} diff --git a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyRecorder.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyRecorder.java new file mode 100644 index 00000000..52bc123a --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyRecorder.java @@ -0,0 +1,14 @@ +package org.onap.ccsdk.sli.core.sli.provider.base; + +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder; + +public class DummyRecorder implements SvcLogicRecorder { + + @Override + public void record(Map parmMap) throws SvcLogicException { + return; + } + +} diff --git a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyResource.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyResource.java new file mode 100644 index 00000000..2e15f3fb --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyResource.java @@ -0,0 +1,97 @@ +/** + * + */ +package org.onap.ccsdk.sli.core.sli.provider.base; + +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.SvcLogicResource; + +/** + * @author dt5972 + * + */ +public class DummyResource implements SvcLogicResource { + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#isAvailable(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#exists(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#query(java.lang.String, boolean, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, + String orderBy, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#reserve(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#save(java.lang.String, boolean, boolean, java.lang.String, java.util.Map, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map parms, + String prefix, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#release(java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { + + return QueryStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#delete(java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus delete(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#notify(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) + throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + /* (non-Javadoc) + * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#update(java.lang.String, java.lang.String, java.util.Map, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) + */ + @Override + public QueryStatus update(String resource, String key, Map parms, String prefix, + SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + +} diff --git a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutorTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutorTest.java new file mode 100644 index 00000000..474136d5 --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutorTest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +import java.util.Map.Entry; +import java.util.Properties; + +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.base.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider; +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase; + +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"); + SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProvider() { + + public Properties getProperties() { + return new Properties(); + }; + }; + + + execute.execute(new SvcLogicServiceImplBase(null), new SvcLogicNode(0, "", "", new SvcLogicGraph()), new SvcLogicContext()); + } + +} diff --git a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/LunchSelectorPlugin.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/LunchSelectorPlugin.java new file mode 100644 index 00000000..0f4cab74 --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/LunchSelectorPlugin.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/PluginTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/PluginTest.java new file mode 100644 index 00000000..cbeb5971 --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/PluginTest.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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.base.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.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-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutorTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutorTest.java new file mode 100644 index 00000000..115989a8 --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutorTest.java @@ -0,0 +1,220 @@ +package org.onap.ccsdk.sli.core.sli.provider.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import java.util.LinkedList; +import org.junit.Test; +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.provider.base.SetNodeExecutor; + +public class SetNodeExecutorTest { + @Test + public void clearProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertNull(ctx.getAttribute("si.field1")); + assertNull(ctx.getAttribute("si.field2")); + assertNull(ctx.getAttribute("si.field3")); + assertNull(ctx.getAttribute("si.subarray[0]")); + assertNull(ctx.getAttribute("si.subarray[1]")); + assertNull(ctx.getAttribute("si.subarray[2]")); + assertNull(ctx.getAttribute("si.subarray_length")); + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + + @Test + public void clearMultipleArrayProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearMultipleArrayValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertNull(ctx.getAttribute("si[0].field1")); + assertNull(ctx.getAttribute("si[1].field2")); + assertNull(ctx.getAttribute("si[2].field3")); + assertNull(ctx.getAttribute("si_length")); + assertNull(ctx.getAttribute("si[0].subarray[0]")); + assertNull(ctx.getAttribute("si[0].subarray[1]")); + assertNull(ctx.getAttribute("si[0].subarray[2]")); + assertNull(ctx.getAttribute("si[0].subarray_length")); + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + + @Test + public void clearSingleArrayProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearSingleArrayValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertNull(ctx.getAttribute("si[0].field1")); + assertNull(ctx.getAttribute("si[0].subarray[0]")); + assertNull(ctx.getAttribute("si[0].subarray[1]")); + assertNull(ctx.getAttribute("si[0].subarray[2]")); + assertNull(ctx.getAttribute("si[0].subarray_length")); + + // TODO: This is just setting up elements as null but note reducing the size of Array. + assertEquals("3",ctx.getAttribute("si_length")); + + assertEquals("2",ctx.getAttribute("si[1].field2")); + assertEquals("3", ctx.getAttribute("si[2].field3")); + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + + @Test + public void clearSingleSubArrayProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearSingleSubArrayValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertEquals("1",ctx.getAttribute("tmp.si[0].field1")); + assertEquals("2",ctx.getAttribute("tmp.si[1].field2")); + assertEquals("3", ctx.getAttribute("tmp.si[2].field3")); + assertEquals("3", ctx.getAttribute("tmp.si_length")); + + assertEquals("a",ctx.getAttribute("tmp.si[0].subarray[0]")); + + // TODO: This is setting up element as Empty instead null + //assertNull(ctx.getAttribute("tmp.si[0].subarray[1]")); + assertEquals("", ctx.getAttribute("tmp.si[0].subarray[1]")); + + assertEquals("c", ctx.getAttribute("tmp.si[0].subarray[2]")); + assertEquals("3", ctx.getAttribute("tmp.si[0].subarray_length")); + + assertEquals("x",ctx.getAttribute("tmp.si[1].subarray[0]")); + assertEquals("y",ctx.getAttribute("tmp.si[1].subarray[1]")); + assertEquals("z", ctx.getAttribute("tmp.si[1].subarray[2]")); + assertEquals("3", ctx.getAttribute("tmp.si[1].subarray_length")); + + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + + @Test + public void clearSubArrayProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearSubArrayValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertEquals("1", ctx.getAttribute("si[0].field1")); + assertEquals("2",ctx.getAttribute("si[1].field2")); + assertEquals("3", ctx.getAttribute("si[2].field3")); + assertEquals("3", ctx.getAttribute("si_length")); + assertNull(ctx.getAttribute("si[0].subarray[0]")); + assertNull(ctx.getAttribute("si[0].subarray[1]")); + assertNull(ctx.getAttribute("si[0].subarray[2]")); + assertNull(ctx.getAttribute("si[0].subarray_length")); + + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + + @Test + public void arrayPattern() { + SetNodeExecutor sne = new SetNodeExecutor(); + String source = "one.two[0].three[0].four"; + assertEquals("one.two.three.four", source.replaceAll(sne.arrayPattern, "")); + } + + @Test + public void subtreeCopy() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/copyValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertEquals("1", ctx.getAttribute("si.field1")); + assertEquals("2", ctx.getAttribute("si.field2")); + assertEquals("3", ctx.getAttribute("si.field3")); + assertEquals("1", ctx.getAttribute("rootTwo.field1")); + assertEquals("2", ctx.getAttribute("rootTwo.field2")); + assertEquals("3", ctx.getAttribute("rootTwo.field3")); + } + + @Test + public void clearNestedSubArrayProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearNestedSubArrayValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertEquals("1", ctx.getAttribute("tmp.si[0].field1")); + assertEquals("2",ctx.getAttribute("tmp.si[1].field2")); + assertEquals("3", ctx.getAttribute("tmp.si[2].field3")); + assertEquals("3", ctx.getAttribute("tmp.si_length")); + + assertNull(ctx.getAttribute("tmp.si[0].subarray[0]")); + assertNull(ctx.getAttribute("tmp.si[0].subarray[1]")); + assertNull(ctx.getAttribute("tmp.si[0].subarray[2]")); + assertNull(ctx.getAttribute("tmp.si[0].subarray_length")); + + assertEquals("x", ctx.getAttribute("tmp.si[1].subarray[0]")); + assertEquals("y",ctx.getAttribute("tmp.si[1].subarray[1]")); + assertEquals("z", ctx.getAttribute("tmp.si[1].subarray[2]")); + assertEquals("3", ctx.getAttribute("tmp.si[1].subarray_length")); + + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + +} diff --git a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java new file mode 100644 index 00000000..bf4a2622 --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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.base.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-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/VoidDummyPlugin.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/VoidDummyPlugin.java new file mode 100644 index 00000000..b2332e05 --- /dev/null +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/VoidDummyPlugin.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli.provider.base; + +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-base/src/test/resources/clearMultipleArrayValues.xml b/sli/provider-base/src/test/resources/clearMultipleArrayValues.xml new file mode 100644 index 00000000..8f40058f --- /dev/null +++ b/sli/provider-base/src/test/resources/clearMultipleArrayValues.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider-base/src/test/resources/clearNestedSubArrayValues.xml b/sli/provider-base/src/test/resources/clearNestedSubArrayValues.xml new file mode 100644 index 00000000..a80b3e56 --- /dev/null +++ b/sli/provider-base/src/test/resources/clearNestedSubArrayValues.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider-base/src/test/resources/clearSingleArrayValues.xml b/sli/provider-base/src/test/resources/clearSingleArrayValues.xml new file mode 100644 index 00000000..56781a06 --- /dev/null +++ b/sli/provider-base/src/test/resources/clearSingleArrayValues.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider-base/src/test/resources/clearSingleSubArrayValues.xml b/sli/provider-base/src/test/resources/clearSingleSubArrayValues.xml new file mode 100644 index 00000000..22f14f37 --- /dev/null +++ b/sli/provider-base/src/test/resources/clearSingleSubArrayValues.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider-base/src/test/resources/clearSubArrayValues.xml b/sli/provider-base/src/test/resources/clearSubArrayValues.xml new file mode 100644 index 00000000..cb25f38a --- /dev/null +++ b/sli/provider-base/src/test/resources/clearSubArrayValues.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider-base/src/test/resources/clearValues.xml b/sli/provider-base/src/test/resources/clearValues.xml new file mode 100644 index 00000000..dc7f5c8a --- /dev/null +++ b/sli/provider-base/src/test/resources/clearValues.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider-base/src/test/resources/copyValues.xml b/sli/provider-base/src/test/resources/copyValues.xml new file mode 100644 index 00000000..f56f7140 --- /dev/null +++ b/sli/provider-base/src/test/resources/copyValues.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider-base/src/test/resources/expression.tests b/sli/provider-base/src/test/resources/expression.tests new file mode 100644 index 00000000..848a0e7a --- /dev/null +++ b/sli/provider-base/src/test/resources/expression.tests @@ -0,0 +1,24 @@ +# $uni-circuit-id = abc123 +# $uni-cir-units = 10 +# value = 1 +# $arg1 = 2 +# $network.name = vCE0001.in +# $network.segment[0].provider-segmentation-id = 1212 +# $network.segment[1].provider-segmentation-id = 1213 +# $availability-zone = mtsnj-esx-az01 +length($uni-circuit-id) > 0 # true +$uni-cir-units * 1000 * 100 / 100 # 10000 +$uni-cir-units / 1000 # 0 +$uni-cir-units - 100 # -90 +$uni-cir-units + 100 # 110 +(value * 3 - $arg1 > 0) and (length($uni-circuit-id) == 0) # true +'pg-'+$network.name # pg-vCE0001.in +$network.segment[0].provider-segmentation-id # 1212 +toUpperCase($network.name) # VCE0001.IN +toLowerCase($network.name) # vce0001.in +toUpperCase(substr($availability-zone, 0, 5)) # MTSNJ +convertBase(1234, 10) # 1234 +convertBase(10, 16, 10) # 16 +convertBase(ZZ, 36, 10) # 1295 +convertBase(10, 10, 36) # a +(0 - 1) * $arg1 # -1 diff --git a/sli/provider-base/src/test/resources/simplelogger.properties b/sli/provider-base/src/test/resources/simplelogger.properties new file mode 100644 index 00000000..07ab67f7 --- /dev/null +++ b/sli/provider-base/src/test/resources/simplelogger.properties @@ -0,0 +1,22 @@ +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# 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========================================================= +### + +org.slf4j.simpleLogger.defaultLogLevel=info diff --git a/sli/provider/pom.xml b/sli/provider/pom.xml index 3bf931a7..0a090282 100755 --- a/sli/provider/pom.xml +++ b/sli/provider/pom.xml @@ -47,7 +47,12 @@ ${project.version} compile - + + org.onap.ccsdk.sli.core + sli-provider-base + ${project.version} + compile + org.slf4j slf4j-api 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 deleted file mode 100644 index e5ae021f..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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 deleted file mode 100644 index fc6f0a50..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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 deleted file mode 100755 index c8e6548f..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java +++ /dev/null @@ -1,175 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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 = svc.getStore(); - String errorMessage = "Parent " + parentGraph + " failed to call child [" + module + "," + rpc + "," + version + "," + mode + "] because the graph could not be found"; - boolean graphWasCalled = false; - if (store != null) { - SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode); - if (calledGraph != null) { - LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString()); - ctx.setAttribute("currentGraph", calledGraph.toString()); - svc.execute(calledGraph, ctx); - outValue = ctx.getStatus(); - graphWasCalled = true; - } else { - LOG.debug(errorMessage); - } - } 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"); - } - } - - if (graphWasCalled == false) { - if (node.getOutcomeValue("catch") != null) { - nextNode = node.getOutcomeValue("catch"); - LOG.debug("graph could not be called, but catch node was found and will be executed"); - } else { - LOG.debug("graph could not be called and no catch node was found, throwing exception"); - throw new SvcLogicException(errorMessage); - } - } - - 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 deleted file mode 100644 index 337b7064..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java +++ /dev/null @@ -1,248 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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 deleted file mode 100644 index 18f1ce9a..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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); - private static final String FAILURE="failure"; - - @Override - public SvcLogicNode execute(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } - -} 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 deleted file mode 100644 index ed75c335..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java +++ /dev/null @@ -1,141 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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"); - } - } - - } - return (getNextNode(node, outValue)); - } - - 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 deleted file mode 100644 index 80aec075..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } - -} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExitNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExitNodeExecutor.java deleted file mode 100755 index fc667f40..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExitNodeExecutor.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.onap.ccsdk.sli.core.sli.provider; - -import org.onap.ccsdk.sli.core.sli.ExitNodeException; -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 ExitNodeExecutor extends SvcLogicNodeExecutor { - - private static final Logger LOG = LoggerFactory.getLogger(ExitNodeExecutor.class); - - @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { - String message = "ExitNodeExecutor encountered exit with nodeId " + node.getNodeId(); - LOG.debug(message); - throw new ExitNodeException(message); - } - -} 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 deleted file mode 100644 index a73fadcf..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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.error("ForNodeExecutor caught break",br); - } - 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 deleted file mode 100644 index 468a6fff..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } - -} 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 deleted file mode 100644 index 72d99e4f..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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"; - - 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); - } - return (getNextNode(node, outValue)); - } - -} 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 deleted file mode 100644 index 44d1ec8f..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } - -} 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 deleted file mode 100644 index e3941446..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } -} 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 deleted file mode 100644 index b0453fad..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } - -} 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 deleted file mode 100644 index 00355cd0..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } - -} 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 deleted file mode 100644 index e05692d5..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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 deleted file mode 100644 index 1b5219be..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } - -} 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 deleted file mode 100755 index 8275a8e4..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java +++ /dev/null @@ -1,179 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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); - protected final String arrayPattern = "\\[\\d*\\]"; - - @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) - throws SvcLogicException { - execute(node,ctx); - return null; - } - - public void execute(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 { - // Backticks symbolize the variable should be handled as an expression instead of as a variable - if (curName.trim().startsWith("`")) { - int lastParen = curName.lastIndexOf("`"); - String evalExpr = curName.trim().substring(1, lastParen); - SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(evalExpr); - lhsVarName = SvcLogicExpressionResolver.evaluate(lhsExpr, node, ctx); - } else { - 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); - } - - HashMap parmsToAdd = new HashMap(); - - for (String sourceVarName : ctx.getAttributeKeySet()) { - if (sourceVarName.startsWith(rhsRoot)) { - String targetVar = lhsPrefix + "." + sourceVarName.substring(rhsRoot.length()); - LOG.debug("Copying {} value to {}", sourceVarName, 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 - LinkedList parmsToRemove = new LinkedList(); - String prefix = lhsVarName + "."; - String arrayPrefix = lhsVarName + "["; - //Clear length value in case an array exists with this prefix - String lengthParamName = lhsVarName + "_length"; - LOG.debug("Unsetting {} because prefix {} is being cleared.", lengthParamName, prefix); - - for (String curCtxVarname : ctx.getAttributeKeySet()) { - String curCtxVarnameMatchingValue = curCtxVarname; - //Special handling for reseting array values, strips out brackets and any numbers between the brackets - //when testing if a context memory value starts with a prefix - if(!prefix.contains("[") && curCtxVarnameMatchingValue.contains("[")) { - curCtxVarnameMatchingValue = curCtxVarname.replaceAll(arrayPattern, "") + "."; - } - if (curCtxVarnameMatchingValue.startsWith(prefix)) { - LOG.debug("Unsetting {} because matching value {} starts with the prefix {}", curCtxVarname, curCtxVarnameMatchingValue, prefix); - parmsToRemove.add(curCtxVarname); - }else if (curCtxVarnameMatchingValue.startsWith(lengthParamName)) { - LOG.debug("Unsetting {} because matching value {} starts with the lengthParamName {}", curCtxVarname, curCtxVarnameMatchingValue, lengthParamName); - parmsToRemove.add(curCtxVarname); - }else if (curCtxVarnameMatchingValue.startsWith(arrayPrefix)) { - LOG.debug("Unsetting {} because matching value {} starts with the arrayPrefix {}", curCtxVarname, curCtxVarnameMatchingValue, arrayPrefix); - 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 {} already set and only-if-unset is true, so not overriding", lhsVarName); - } - } - if (setValue) { - String curValue = SvcLogicExpressionResolver.evaluate(curEnt.getValue(), node, ctx); - - if (LOG.isDebugEnabled()) { - LOG.trace("Parameter value {} resolves to {}", curEnt.getValue().asParsedExpr(), curValue); - LOG.debug("Setting context attribute {} to {}", lhsVarName, curValue); - } - ctx.setAttribute(lhsVarName, curValue); - } - } - } - } -} - 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 index ecfe6b69..540c04ef 100644 --- 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 @@ -24,9 +24,6 @@ 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; @@ -56,7 +53,7 @@ public class SvcLogicAdaptorFactory { return adaptorMap.get(name); } else { - SvcLogicAdaptor adaptor = (SvcLogicAdaptor) SvcLogicClassResolver.resolve(name); + SvcLogicAdaptor adaptor = (SvcLogicAdaptor) SvcLogicClassResolver.getInstance().resolve(name); if (adaptor != null) { registerAdaptor(adaptor); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java index d2b733fc..f10976a5 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java @@ -1,5 +1,10 @@ package org.onap.ccsdk.sli.core.sli.provider; +import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicResolver; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; @@ -7,35 +12,63 @@ import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SvcLogicClassResolver { - private static final Logger LOG = LoggerFactory.getLogger(SvcLogicClassResolver.class); +public class SvcLogicClassResolver implements SvcLogicResolver { + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicClassResolver.class); + private static SvcLogicClassResolver instance = new SvcLogicClassResolver(); - public static Object resolve(String className) { + private SvcLogicClassResolver() { + } - Bundle bundle = FrameworkUtil.getBundle(SvcLogicClassResolver.class); + public static SvcLogicClassResolver getInstance() { + return instance; + } - if (bundle == null) { - // Running outside OSGi container (e.g. jUnit). Use Reflection - // to resolve class - try { - return(Class.forName(className).newInstance()); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + public Object resolve(String className) { - LOG.error("Could not resolve class "+className, e); - return null; - } + Bundle bundle = FrameworkUtil.getBundle(SvcLogicClassResolver.class); - } else { - BundleContext bctx = bundle.getBundleContext(); - ServiceReference sref = bctx.getServiceReference(className); - if (sref != null) { - return bctx.getService(sref); - } else { + if (bundle == null) { + // Running outside OSGi container (e.g. jUnit). Use Reflection + // to resolve class + try { + return (Class.forName(className).newInstance()); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { - LOG.warn("Could not find service reference object for class " + className); - return null; - } - } - } + LOG.error("Could not resolve class " + className, e); + return null; + } + + } else { + BundleContext bctx = bundle.getBundleContext(); + ServiceReference sref = bctx.getServiceReference(className); + if (sref != null) { + return bctx.getService(sref); + } else { + + LOG.warn("Could not find service reference object for class " + className); + return null; + } + } + } + + @Override + public SvcLogicResource getSvcLogicResource(String resourceName) { + return (SvcLogicResource) resolve(resourceName); + } + + @Override + public SvcLogicRecorder getSvcLogicRecorder(String recorderName) { + return (SvcLogicRecorder) resolve(recorderName); + } + + @Override + public SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName) { + return (SvcLogicJavaPlugin) resolve(pluginName); + } + + @Override + public SvcLogicAdaptor getSvcLogicAdaptor(String adaptorName) { + return SvcLogicAdaptorFactory.getInstance(adaptorName); + } } 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 deleted file mode 100644 index c9446bda..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolver.java +++ /dev/null @@ -1,605 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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 deleted file mode 100644 index 34fdb537..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.onap.ccsdk.sli.core.sli.provider; - -import org.onap.ccsdk.sli.core.sli.MetricLogger; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class SvcLogicNodeExecutor { - - public abstract SvcLogicNode execute(SvcLogicService 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 SvcLogicAdaptor getAdaptor(String adaptorName) { - return SvcLogicAdaptorFactory.getInstance(adaptorName); - } - - protected SvcLogicResource getSvcLogicResource(String plugin) { - - return((SvcLogicResource) SvcLogicClassResolver.resolve(plugin)); - } - - protected SvcLogicRecorder getSvcLogicRecorder(String plugin) { - return((SvcLogicRecorder) SvcLogicClassResolver.resolve(plugin)); - } - - protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){ - return((SvcLogicJavaPlugin) SvcLogicClassResolver.resolve(pluginName)); - - } - - protected SvcLogicNode getNextNode(SvcLogicNode node, String outValue) { - MetricLogger.resetContext(); - 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/SvcLogicPropertiesProvider.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java deleted file mode 100644 index 9debd6bc..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * onap - * ================================================================================ - * Copyright (C) 2016 - 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; - -public interface SvcLogicPropertiesProvider { - - public Properties getProperties();; -} diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java index a9992a09..c4680cce 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProviderImpl.java @@ -31,6 +31,7 @@ import java.util.Vector; import org.onap.ccsdk.sli.core.dblib.DblibConfigurationException; import org.onap.ccsdk.sli.core.sli.ConfigurationException; +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider; import org.onap.ccsdk.sli.core.utils.JREFileResolver; import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; 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 index 3f24adff..a23594ee 100644 --- 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 @@ -22,43 +22,15 @@ package org.onap.ccsdk.sli.core.sli.provider; import java.util.Properties; -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.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -public interface SvcLogicService { +public interface SvcLogicService extends SvcLogicServiceBase { String NAME = "org.onap.ccsdk.sli.core.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 - */ - 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 Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException; @@ -76,10 +48,5 @@ public interface SvcLogicService { */ Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException; - SvcLogicStore getStore() throws SvcLogicException; - - SvcLogicContext execute(SvcLogicGraph calledGraph, SvcLogicContext ctx) throws SvcLogicException; - - SvcLogicNode executeNode(SvcLogicNode nextNode, SvcLogicContext ctx) 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 index c7942563..23d703c2 100755 --- 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 @@ -23,20 +23,20 @@ package org.onap.ccsdk.sli.core.sli.provider; -import java.util.HashMap; -import java.util.Map; import java.util.Properties; + import org.onap.ccsdk.sli.core.dblib.DbLibService; import org.onap.ccsdk.sli.core.sli.ConfigurationException; -import org.onap.ccsdk.sli.core.sli.ExitNodeException; import org.onap.ccsdk.sli.core.sli.MetricLogger; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicDblibStore; 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.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; +import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider; +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -44,71 +44,32 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; -public class SvcLogicServiceImpl implements SvcLogicService { - - 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()); - put("while", new WhileNodeExecutor()); - put("exit", new ExitNodeExecutor()); - } - }; +public class SvcLogicServiceImpl extends SvcLogicServiceImplBase implements SvcLogicService { private static final Logger LOG = LoggerFactory.getLogger(SvcLogicServiceImpl.class); - protected HashMap nodeExecutors = null; protected BundleContext bctx = null; - protected Properties properties; - protected SvcLogicStore store; - private static final String CURRENT_GRAPH="currentGraph"; public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider) throws SvcLogicException { + super(null); + this.resolver = SvcLogicClassResolver.getInstance(); properties = resourceProvider.getProperties(); - getStore(); + this.store = getStore(); } public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, DbLibService dbSvc) throws SvcLogicException { + super(null); + this.resolver = SvcLogicClassResolver.getInstance(); properties = resourceProvider.getProperties(); - store = new SvcLogicDblibStore(dbSvc); - } - - - protected void registerExecutors() { - - LOG.info("Entered register executors"); - for (String nodeType : BUILTIN_NODES.keySet()) { - LOG.info("SLI - registering node executor for node type " + nodeType); - registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); - } - LOG.info("Done registerExecutors"); + this.store = new SvcLogicDblibStore(dbSvc); } public void registerExecutor(ServiceReference sr) { String nodeName = (String) sr.getProperty("nodeType"); if (nodeName != null) { - - SvcLogicNodeExecutor executor; - + AbstractSvcLogicNodeExecutor executor; try { - executor = (SvcLogicNodeExecutor) bctx.getService(sr); + executor = (AbstractSvcLogicNodeExecutor) bctx.getService(sr); } catch (Exception e) { LOG.error("Cannot get service executor for {}", nodeName, e); return; @@ -117,14 +78,6 @@ public class SvcLogicServiceImpl implements SvcLogicService { } } - 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"); @@ -133,67 +86,6 @@ public class SvcLogicServiceImpl implements SvcLogicService { } } - 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()); - - MDC.put(CURRENT_GRAPH, graph.toString()); - - SvcLogicNode curNode = graph.getRootNode(); - LOG.info("About to execute graph {}", graph.toString()); - try { - while (curNode != null) { - - SvcLogicNode nextNode = executeNode(curNode, ctx); - curNode = nextNode; - } - } catch (ExitNodeException e) { - LOG.debug("SvcLogicServiceImpl caught ExitNodeException"); - } - MDC.remove("nodeId"); - MDC.remove(CURRENT_GRAPH); - - return (ctx); - } - - public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { - if (node == null) { - return (null); - } - - LOG.info("About to execute node # {} ({})", node.getNodeId(), node.getNodeType()); - - if (LOG.isDebugEnabled()) { - LOG.debug("Executing node " + node.getNodeId() + " of " + node.getGraph().getRpc()); - } - - SvcLogicNodeExecutor executor = nodeExecutors.get(node.getNodeType()); - - if (executor != null) { - LOG.debug("Executing node executor for node type {} - {}", node.getNodeType(), - executor.getClass().getName()); - - MDC.put("nodeId", node.getNodeId() + " (" + node.getNodeType() + ")"); - return (executor.execute(this, node, ctx)); - } else { - throw new SvcLogicException("Attempted to execute a node of type " + node.getNodeType() + ", but no executor was registered for this type"); - } - } - - @Override - public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException { - return (store.hasGraph(module, rpc, version, mode)); - } - @Override public Properties execute(String module, String rpc, String version, String mode, Properties props) throws SvcLogicException { @@ -218,12 +110,16 @@ public class SvcLogicServiceImpl implements SvcLogicService { ctx.setAttribute(CURRENT_GRAPH, graph.toString()); ctx.setAttribute("X-ECOMP-RequestID", MDC.get("X-ECOMP-RequestID")); ctx.setDomDataBroker(domDataBroker); - execute(graph, ctx); - return (ctx.toProperties()); } + + @Override + protected void resetContext() { + MetricLogger.resetContext(); + } + @Override public SvcLogicStore getStore() throws SvcLogicException { // Create and initialize SvcLogicStore object - used to access // saved service logic. @@ -246,4 +142,5 @@ public class SvcLogicServiceImpl implements SvcLogicService { return store; } + } 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 deleted file mode 100644 index 592fb288..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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 deleted file mode 100644 index a783df41..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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); - } - return (getNextNode(node, outValue)); - } - -} 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 deleted file mode 100644 index b717aa98..00000000 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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(SvcLogicService 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 deleted file mode 100644 index f5a39f50..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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/DummyAdaptor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java deleted file mode 100644 index 0f3893ef..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * - */ -package org.onap.ccsdk.sli.core.sli.provider; - -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -/** - * @author dt5972 - * - */ - -public class DummyAdaptor implements SvcLogicAdaptor { - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#configure(java.lang.String, java.util.Map, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public ConfigStatus configure(String key, Map parameters, SvcLogicContext ctx) { - - if ("ALREADY_ACTIVE".equalsIgnoreCase(key)) { - return ConfigStatus.ALREADY_ACTIVE; - } else if ("NOT_FOUND".equalsIgnoreCase(key)) { - return ConfigStatus.NOT_FOUND; - }else if ("NOT_READY".equalsIgnoreCase(key)) { - return ConfigStatus.NOT_READY; - } else if ("FAILURE".equalsIgnoreCase(key)) { - return ConfigStatus.FAILURE; - } else if ("SUCCESS".equalsIgnoreCase(key)) { - return ConfigStatus.SUCCESS; - } - - return ConfigStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#activate(java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public ConfigStatus activate(String key, SvcLogicContext ctx) { - return ConfigStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#deactivate(java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public ConfigStatus deactivate(String key, SvcLogicContext ctx) { - return ConfigStatus.SUCCESS; - } - -} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java deleted file mode 100644 index e87f9628..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.onap.ccsdk.sli.core.sli.provider; - -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder; - -public class DummyRecorder implements SvcLogicRecorder { - - @Override - public void record(Map parmMap) throws SvcLogicException { - return; - } - -} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java deleted file mode 100644 index 2f784186..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * - */ -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.SvcLogicResource; - -/** - * @author dt5972 - * - */ -public class DummyResource implements SvcLogicResource { - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#isAvailable(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) - throws SvcLogicException { - return QueryStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#exists(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) - throws SvcLogicException { - return QueryStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#query(java.lang.String, boolean, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, - String orderBy, SvcLogicContext ctx) throws SvcLogicException { - return QueryStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#reserve(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx) - throws SvcLogicException { - return QueryStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#save(java.lang.String, boolean, boolean, java.lang.String, java.util.Map, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map parms, - String prefix, SvcLogicContext ctx) throws SvcLogicException { - return QueryStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#release(java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { - - return QueryStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#delete(java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus delete(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { - return QueryStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#notify(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) - throws SvcLogicException { - return QueryStatus.SUCCESS; - } - - /* (non-Javadoc) - * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#update(java.lang.String, java.lang.String, java.util.Map, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext) - */ - @Override - public QueryStatus update(String resource, String key, Map parms, String prefix, - SvcLogicContext ctx) throws SvcLogicException { - return QueryStatus.SUCCESS; - } - -} 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 deleted file mode 100644 index 33ce6f69..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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"); - SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProviderImpl(); - execute.execute(new SvcLogicServiceImpl(resourceProvider), new SvcLogicNode(0, "", "", new SvcLogicGraph()), new SvcLogicContext()); - } - -} diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java index 445df36f..6d466bc7 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java @@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.core.sli.provider; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; - import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -34,27 +33,46 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Properties; + import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; 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.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceRegistration; +import org.onap.ccsdk.sli.core.sli.provider.base.BlockNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.BreakNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.CallNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ConfigureNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.DeleteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ExistsNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ForNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.GetResourceNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.IsAvailableNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.NotifyNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.RecordNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReleaseNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReserveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReturnNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SaveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SetNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider; +import org.onap.ccsdk.sli.core.sli.provider.base.SwitchNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.UpdateNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.WhileNodeExecutor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ITCaseSvcLogicGraphExecutor { private static final Logger LOG = LoggerFactory.getLogger(SvcLogicGraph.class); - private static final Map BUILTIN_NODES = new HashMap() { + private static final Map BUILTIN_NODES = new HashMap() { { put("block", new BlockNodeExecutor()); put("break", new BreakNodeExecutor()); 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 deleted file mode 100644 index b86edb06..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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/PluginTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java deleted file mode 100644 index 98e0753d..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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/SetNodeExecutorTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java deleted file mode 100755 index 7c6f4ce5..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java +++ /dev/null @@ -1,219 +0,0 @@ -package org.onap.ccsdk.sli.core.sli.provider; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import java.util.LinkedList; -import org.junit.Test; -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; - -public class SetNodeExecutorTest { - @Test - public void clearProperties() throws Exception { - SetNodeExecutor sne = new SetNodeExecutor(); - SvcLogicContext ctx = new SvcLogicContext(); - - SvcLogicParser slp = new SvcLogicParser(); - LinkedList graph = slp.parse("src/test/resources/clearValues.xml"); - SvcLogicNode root = graph.getFirst().getRootNode(); - SvcLogicNode nodeOne = root.getOutcomeValue("1"); - SvcLogicNode nodeTwo = root.getOutcomeValue("2"); - - sne.execute(nodeOne, ctx); - sne.execute(nodeTwo, ctx); - - assertNull(ctx.getAttribute("si.field1")); - assertNull(ctx.getAttribute("si.field2")); - assertNull(ctx.getAttribute("si.field3")); - assertNull(ctx.getAttribute("si.subarray[0]")); - assertNull(ctx.getAttribute("si.subarray[1]")); - assertNull(ctx.getAttribute("si.subarray[2]")); - assertNull(ctx.getAttribute("si.subarray_length")); - assertEquals("6", ctx.getAttribute("search1")); - assertEquals("KeepMe!", ctx.getAttribute("simonSays")); - } - - @Test - public void clearMultipleArrayProperties() throws Exception { - SetNodeExecutor sne = new SetNodeExecutor(); - SvcLogicContext ctx = new SvcLogicContext(); - - SvcLogicParser slp = new SvcLogicParser(); - LinkedList graph = slp.parse("src/test/resources/clearMultipleArrayValues.xml"); - SvcLogicNode root = graph.getFirst().getRootNode(); - SvcLogicNode nodeOne = root.getOutcomeValue("1"); - SvcLogicNode nodeTwo = root.getOutcomeValue("2"); - - sne.execute(nodeOne, ctx); - sne.execute(nodeTwo, ctx); - - assertNull(ctx.getAttribute("si[0].field1")); - assertNull(ctx.getAttribute("si[1].field2")); - assertNull(ctx.getAttribute("si[2].field3")); - assertNull(ctx.getAttribute("si_length")); - assertNull(ctx.getAttribute("si[0].subarray[0]")); - assertNull(ctx.getAttribute("si[0].subarray[1]")); - assertNull(ctx.getAttribute("si[0].subarray[2]")); - assertNull(ctx.getAttribute("si[0].subarray_length")); - assertEquals("6", ctx.getAttribute("search1")); - assertEquals("KeepMe!", ctx.getAttribute("simonSays")); - } - - @Test - public void clearSingleArrayProperties() throws Exception { - SetNodeExecutor sne = new SetNodeExecutor(); - SvcLogicContext ctx = new SvcLogicContext(); - - SvcLogicParser slp = new SvcLogicParser(); - LinkedList graph = slp.parse("src/test/resources/clearSingleArrayValues.xml"); - SvcLogicNode root = graph.getFirst().getRootNode(); - SvcLogicNode nodeOne = root.getOutcomeValue("1"); - SvcLogicNode nodeTwo = root.getOutcomeValue("2"); - - sne.execute(nodeOne, ctx); - sne.execute(nodeTwo, ctx); - - assertNull(ctx.getAttribute("si[0].field1")); - assertNull(ctx.getAttribute("si[0].subarray[0]")); - assertNull(ctx.getAttribute("si[0].subarray[1]")); - assertNull(ctx.getAttribute("si[0].subarray[2]")); - assertNull(ctx.getAttribute("si[0].subarray_length")); - - // TODO: This is just setting up elements as null but note reducing the size of Array. - assertEquals("3",ctx.getAttribute("si_length")); - - assertEquals("2",ctx.getAttribute("si[1].field2")); - assertEquals("3", ctx.getAttribute("si[2].field3")); - assertEquals("6", ctx.getAttribute("search1")); - assertEquals("KeepMe!", ctx.getAttribute("simonSays")); - } - - @Test - public void clearSingleSubArrayProperties() throws Exception { - SetNodeExecutor sne = new SetNodeExecutor(); - SvcLogicContext ctx = new SvcLogicContext(); - - SvcLogicParser slp = new SvcLogicParser(); - LinkedList graph = slp.parse("src/test/resources/clearSingleSubArrayValues.xml"); - SvcLogicNode root = graph.getFirst().getRootNode(); - SvcLogicNode nodeOne = root.getOutcomeValue("1"); - SvcLogicNode nodeTwo = root.getOutcomeValue("2"); - - sne.execute(nodeOne, ctx); - sne.execute(nodeTwo, ctx); - - assertEquals("1",ctx.getAttribute("tmp.si[0].field1")); - assertEquals("2",ctx.getAttribute("tmp.si[1].field2")); - assertEquals("3", ctx.getAttribute("tmp.si[2].field3")); - assertEquals("3", ctx.getAttribute("tmp.si_length")); - - assertEquals("a",ctx.getAttribute("tmp.si[0].subarray[0]")); - - // TODO: This is setting up element as Empty instead null - //assertNull(ctx.getAttribute("tmp.si[0].subarray[1]")); - assertEquals("", ctx.getAttribute("tmp.si[0].subarray[1]")); - - assertEquals("c", ctx.getAttribute("tmp.si[0].subarray[2]")); - assertEquals("3", ctx.getAttribute("tmp.si[0].subarray_length")); - - assertEquals("x",ctx.getAttribute("tmp.si[1].subarray[0]")); - assertEquals("y",ctx.getAttribute("tmp.si[1].subarray[1]")); - assertEquals("z", ctx.getAttribute("tmp.si[1].subarray[2]")); - assertEquals("3", ctx.getAttribute("tmp.si[1].subarray_length")); - - assertEquals("6", ctx.getAttribute("search1")); - assertEquals("KeepMe!", ctx.getAttribute("simonSays")); - } - - @Test - public void clearSubArrayProperties() throws Exception { - SetNodeExecutor sne = new SetNodeExecutor(); - SvcLogicContext ctx = new SvcLogicContext(); - - SvcLogicParser slp = new SvcLogicParser(); - LinkedList graph = slp.parse("src/test/resources/clearSubArrayValues.xml"); - SvcLogicNode root = graph.getFirst().getRootNode(); - SvcLogicNode nodeOne = root.getOutcomeValue("1"); - SvcLogicNode nodeTwo = root.getOutcomeValue("2"); - - sne.execute(nodeOne, ctx); - sne.execute(nodeTwo, ctx); - - assertEquals("1", ctx.getAttribute("si[0].field1")); - assertEquals("2",ctx.getAttribute("si[1].field2")); - assertEquals("3", ctx.getAttribute("si[2].field3")); - assertEquals("3", ctx.getAttribute("si_length")); - assertNull(ctx.getAttribute("si[0].subarray[0]")); - assertNull(ctx.getAttribute("si[0].subarray[1]")); - assertNull(ctx.getAttribute("si[0].subarray[2]")); - assertNull(ctx.getAttribute("si[0].subarray_length")); - - assertEquals("6", ctx.getAttribute("search1")); - assertEquals("KeepMe!", ctx.getAttribute("simonSays")); - } - - @Test - public void arrayPattern() { - SetNodeExecutor sne = new SetNodeExecutor(); - String source = "one.two[0].three[0].four"; - assertEquals("one.two.three.four", source.replaceAll(sne.arrayPattern, "")); - } - - @Test - public void subtreeCopy() throws Exception { - SetNodeExecutor sne = new SetNodeExecutor(); - SvcLogicContext ctx = new SvcLogicContext(); - - SvcLogicParser slp = new SvcLogicParser(); - LinkedList graph = slp.parse("src/test/resources/copyValues.xml"); - SvcLogicNode root = graph.getFirst().getRootNode(); - SvcLogicNode nodeOne = root.getOutcomeValue("1"); - SvcLogicNode nodeTwo = root.getOutcomeValue("2"); - - sne.execute(nodeOne, ctx); - sne.execute(nodeTwo, ctx); - - assertEquals("1", ctx.getAttribute("si.field1")); - assertEquals("2", ctx.getAttribute("si.field2")); - assertEquals("3", ctx.getAttribute("si.field3")); - assertEquals("1", ctx.getAttribute("rootTwo.field1")); - assertEquals("2", ctx.getAttribute("rootTwo.field2")); - assertEquals("3", ctx.getAttribute("rootTwo.field3")); - } - - @Test - public void clearNestedSubArrayProperties() throws Exception { - SetNodeExecutor sne = new SetNodeExecutor(); - SvcLogicContext ctx = new SvcLogicContext(); - - SvcLogicParser slp = new SvcLogicParser(); - LinkedList graph = slp.parse("src/test/resources/clearNestedSubArrayValues.xml"); - SvcLogicNode root = graph.getFirst().getRootNode(); - SvcLogicNode nodeOne = root.getOutcomeValue("1"); - SvcLogicNode nodeTwo = root.getOutcomeValue("2"); - - sne.execute(nodeOne, ctx); - sne.execute(nodeTwo, ctx); - - assertEquals("1", ctx.getAttribute("tmp.si[0].field1")); - assertEquals("2",ctx.getAttribute("tmp.si[1].field2")); - assertEquals("3", ctx.getAttribute("tmp.si[2].field3")); - assertEquals("3", ctx.getAttribute("tmp.si_length")); - - assertNull(ctx.getAttribute("tmp.si[0].subarray[0]")); - assertNull(ctx.getAttribute("tmp.si[0].subarray[1]")); - assertNull(ctx.getAttribute("tmp.si[0].subarray[2]")); - assertNull(ctx.getAttribute("tmp.si[0].subarray_length")); - - assertEquals("x", ctx.getAttribute("tmp.si[1].subarray[0]")); - assertEquals("y",ctx.getAttribute("tmp.si[1].subarray[1]")); - assertEquals("z", ctx.getAttribute("tmp.si[1].subarray[2]")); - assertEquals("3", ctx.getAttribute("tmp.si[1].subarray_length")); - - assertEquals("6", ctx.getAttribute("search1")); - assertEquals("KeepMe!", ctx.getAttribute("simonSays")); - } - -} 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 deleted file mode 100644 index a08144ee..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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/VoidDummyPlugin.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java deleted file mode 100644 index 8c7b0d30..00000000 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * 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.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/resources/clearMultipleArrayValues.xml b/sli/provider/src/test/resources/clearMultipleArrayValues.xml deleted file mode 100644 index 8f40058f..00000000 --- a/sli/provider/src/test/resources/clearMultipleArrayValues.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sli/provider/src/test/resources/clearNestedSubArrayValues.xml b/sli/provider/src/test/resources/clearNestedSubArrayValues.xml deleted file mode 100644 index a80b3e56..00000000 --- a/sli/provider/src/test/resources/clearNestedSubArrayValues.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sli/provider/src/test/resources/clearSingleArrayValues.xml b/sli/provider/src/test/resources/clearSingleArrayValues.xml deleted file mode 100644 index 56781a06..00000000 --- a/sli/provider/src/test/resources/clearSingleArrayValues.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sli/provider/src/test/resources/clearSingleSubArrayValues.xml b/sli/provider/src/test/resources/clearSingleSubArrayValues.xml deleted file mode 100644 index 22f14f37..00000000 --- a/sli/provider/src/test/resources/clearSingleSubArrayValues.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sli/provider/src/test/resources/clearSubArrayValues.xml b/sli/provider/src/test/resources/clearSubArrayValues.xml deleted file mode 100644 index cb25f38a..00000000 --- a/sli/provider/src/test/resources/clearSubArrayValues.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sli/provider/src/test/resources/clearValues.xml b/sli/provider/src/test/resources/clearValues.xml deleted file mode 100644 index dc7f5c8a..00000000 --- a/sli/provider/src/test/resources/clearValues.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sli/provider/src/test/resources/copyValues.xml b/sli/provider/src/test/resources/copyValues.xml deleted file mode 100644 index f56f7140..00000000 --- a/sli/provider/src/test/resources/copyValues.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sli/provider/src/test/resources/expression.tests b/sli/provider/src/test/resources/expression.tests deleted file mode 100755 index 848a0e7a..00000000 --- a/sli/provider/src/test/resources/expression.tests +++ /dev/null @@ -1,24 +0,0 @@ -# $uni-circuit-id = abc123 -# $uni-cir-units = 10 -# value = 1 -# $arg1 = 2 -# $network.name = vCE0001.in -# $network.segment[0].provider-segmentation-id = 1212 -# $network.segment[1].provider-segmentation-id = 1213 -# $availability-zone = mtsnj-esx-az01 -length($uni-circuit-id) > 0 # true -$uni-cir-units * 1000 * 100 / 100 # 10000 -$uni-cir-units / 1000 # 0 -$uni-cir-units - 100 # -90 -$uni-cir-units + 100 # 110 -(value * 3 - $arg1 > 0) and (length($uni-circuit-id) == 0) # true -'pg-'+$network.name # pg-vCE0001.in -$network.segment[0].provider-segmentation-id # 1212 -toUpperCase($network.name) # VCE0001.IN -toLowerCase($network.name) # vce0001.in -toUpperCase(substr($availability-zone, 0, 5)) # MTSNJ -convertBase(1234, 10) # 1234 -convertBase(10, 16, 10) # 16 -convertBase(ZZ, 36, 10) # 1295 -convertBase(10, 10, 36) # a -(0 - 1) * $arg1 # -1 diff --git a/sliPluginUtils/provider/testFileName b/sliPluginUtils/provider/testFileName deleted file mode 100644 index 674e20cc..00000000 --- a/sliPluginUtils/provider/testFileName +++ /dev/null @@ -1 +0,0 @@ -####################################### diff --git a/sliapi/provider/pom.xml b/sliapi/provider/pom.xml index e6ffaa9d..efcf321c 100755 --- a/sliapi/provider/pom.xml +++ b/sliapi/provider/pom.xml @@ -61,6 +61,11 @@ sli-provider ${project.version} + + org.onap.ccsdk.sli.core + sli-provider-base + ${project.version} + org.opendaylight.controller sal-core-api diff --git a/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java index 287f2f20..96d61933 100644 --- a/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java +++ b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java @@ -25,28 +25,28 @@ import org.junit.Test; 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.SvcLogicPropertiesProviderImpl; 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.onap.ccsdk.sli.core.sli.provider.WhileNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.BlockNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.CallNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ConfigureNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.DeleteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ExistsNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ForNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.GetResourceNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.IsAvailableNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.NotifyNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.RecordNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReleaseNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReserveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReturnNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SaveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SetNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SwitchNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.UpdateNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.WhileNodeExecutor; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; @@ -67,7 +67,7 @@ public class TestSliapiProvider { private static final String HEALTHCHECK_DG = "sli_healthcheck.xml"; - private static final Map BUILTIN_NODES = new HashMap() { + private static final Map BUILTIN_NODES = new HashMap() { { put("block", new BlockNodeExecutor()); put("call", new CallNodeExecutor()); -- cgit 1.2.3-korg