diff options
author | Smokowski, Kevin (ks6305) <ks6305@us.att.com> | 2018-11-30 18:00:42 +0000 |
---|---|---|
committer | Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> | 2018-12-03 17:03:26 +0000 |
commit | 7f8fd751c9272c33be0b74f02cd962dd615b63d3 (patch) | |
tree | 226b421ffe5d8972f472614d5a64ead0b27b105f | |
parent | a8ba189dac17a5627e6e1cf102e63e7f9f29e8e1 (diff) |
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) <kevin.smokowski@att.com>
58 files changed, 603 insertions, 315 deletions
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 @@ </organization> <modules> + <module>provider-base</module> <module>model</module> <module>common</module> <module>provider</module> 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 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.ccsdk.parent</groupId> + <artifactId>binding-parent</artifactId> + <version>1.2.0-SNAPSHOT</version> + <relativePath /> + </parent> + + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider-base</artifactId> + <version>0.4.0-SNAPSHOT</version> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>dblib-provider</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-common</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <scope>compile</scope> + </dependency> + + <!-- Testing Dependencies --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/AbstractSvcLogicNodeExecutor.java index 34fdb537..a51accbb 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/AbstractSvcLogicNodeExecutor.java @@ -19,9 +19,8 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; -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; @@ -32,11 +31,11 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class SvcLogicNodeExecutor { +public abstract class AbstractSvcLogicNodeExecutor { + protected SvcLogicResolver resolver; + public abstract SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException; - public abstract SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException; - - private static final Logger LOG = LoggerFactory.getLogger(SvcLogicNodeExecutor.class); + private static final Logger LOG = LoggerFactory.getLogger(AbstractSvcLogicNodeExecutor.class); protected String evaluateNodeTest(SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { @@ -49,28 +48,27 @@ public abstract class SvcLogicNodeExecutor { } + public void setResolver(SvcLogicResolver resolver) { + this.resolver = resolver; + } - - protected SvcLogicAdaptor getAdaptor(String adaptorName) { - return SvcLogicAdaptorFactory.getInstance(adaptorName); + protected SvcLogicAdaptor getAdaptor(String adaptorName) { + return resolver.getSvcLogicAdaptor(adaptorName); } - protected SvcLogicResource getSvcLogicResource(String plugin) { - - return((SvcLogicResource) SvcLogicClassResolver.resolve(plugin)); + protected SvcLogicResource getSvcLogicResource(String resourceName) { + return resolver.getSvcLogicResource(resourceName); } - protected SvcLogicRecorder getSvcLogicRecorder(String plugin) { - return((SvcLogicRecorder) SvcLogicClassResolver.resolve(plugin)); + protected SvcLogicRecorder getSvcLogicRecorder(String recorderName) { + return resolver.getSvcLogicRecorder(recorderName); } protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){ - return((SvcLogicJavaPlugin) SvcLogicClassResolver.resolve(pluginName)); - + return resolver.getSvcLogicJavaPlugin(pluginName); } protected SvcLogicNode getNextNode(SvcLogicNode node, String outValue) { - MetricLogger.resetContext(); SvcLogicNode nextNode = node.getOutcomeValue(outValue); if (nextNode != null) { if (LOG.isDebugEnabled()) { @@ -91,4 +89,5 @@ public abstract class SvcLogicNodeExecutor { } return (nextNode); } + } diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BlockNodeExecutor.java index e5ae021f..7aaf795b 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BlockNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BlockNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -28,13 +28,13 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class BlockNodeExecutor extends SvcLogicNodeExecutor { +public class BlockNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory .getLogger(BlockNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { SvcLogicExpression atomicExpr = node.getAttribute("atomic"); @@ -72,4 +72,5 @@ public class BlockNodeExecutor extends SvcLogicNodeExecutor { } + } diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BreakNodeExecutor.java index fc6f0a50..603d7abc 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/BreakNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/BreakNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -28,12 +28,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class BreakNodeExecutor extends SvcLogicNodeExecutor { +public class BreakNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(BreakNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + 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/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/CallNodeExecutor.java index c8e6548f..284795bd 100755..100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/CallNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/CallNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -30,13 +30,13 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class CallNodeExecutor extends SvcLogicNodeExecutor { +public class CallNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory .getLogger(CallNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String outValue = "not-found"; diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ConfigureNodeExecutor.java index 337b7064..5b1d9efe 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ConfigureNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ConfigureNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.HashMap; import java.util.Iterator; @@ -34,11 +34,11 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ConfigureNodeExecutor extends SvcLogicNodeExecutor { +public class ConfigureNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory .getLogger(ConfigureNodeExecutor.class); - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String adaptorName = SvcLogicExpressionResolver.evaluate( diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/DeleteNodeExecutor.java index 18f1ce9a..2393a159 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/DeleteNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/DeleteNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -28,13 +28,13 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class DeleteNodeExecutor extends SvcLogicNodeExecutor { +public class DeleteNodeExecutor extends AbstractSvcLogicNodeExecutor { 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) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java index ed75c335..357f11d0 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -36,12 +36,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ExecuteNodeExecutor extends SvcLogicNodeExecutor { +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(SvcLogicService svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String pluginName = SvcLogicExpressionResolver.evaluate( diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExistsNodeExecutor.java index 80aec075..397c5f32 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExistsNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExistsNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -28,12 +28,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ExistsNodeExecutor extends SvcLogicNodeExecutor { +public class ExistsNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(ExistsNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExitNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExitNodeExecutor.java index fc667f40..828e1015 100755..100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExitNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExitNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -28,12 +28,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ExitNodeExecutor extends SvcLogicNodeExecutor { +public class ExitNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(ExitNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + 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/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ForNodeExecutor.java index a73fadcf..8ca1f32d 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ForNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ForNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -29,13 +29,13 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ForNodeExecutor extends SvcLogicNodeExecutor { +public class ForNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory .getLogger(ForNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { SvcLogicExpression atomicExpr = node.getAttribute("atomic"); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/GetResourceNodeExecutor.java index 468a6fff..a2f1c63d 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/GetResourceNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/GetResourceNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -29,11 +29,11 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class GetResourceNodeExecutor extends SvcLogicNodeExecutor { +public class GetResourceNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(GetResourceNodeExecutor.class); - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/IsAvailableNodeExecutor.java index 72d99e4f..a93c0d6f 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/IsAvailableNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/IsAvailableNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -28,12 +28,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class IsAvailableNodeExecutor extends SvcLogicNodeExecutor { +public class IsAvailableNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(IsAvailableNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/NotifyNodeExecutor.java index 44d1ec8f..de59a4b7 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/NotifyNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/NotifyNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -28,12 +28,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NotifyNodeExecutor extends SvcLogicNodeExecutor { +public class NotifyNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(NotifyNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/RecordNodeExecutor.java index e3941446..3522c0a7 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/RecordNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/RecordNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.HashMap; import java.util.Iterator; @@ -33,12 +33,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RecordNodeExecutor extends SvcLogicNodeExecutor { +public class RecordNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(RecordNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReleaseNodeExecutor.java index b0453fad..ed9d7d7d 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReleaseNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReleaseNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -28,12 +28,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ReleaseNodeExecutor extends SvcLogicNodeExecutor { +public class ReleaseNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(ReleaseNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReserveNodeExecutor.java index 00355cd0..8e21a459 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReserveNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReserveNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -29,12 +29,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ReserveNodeExecutor extends SvcLogicNodeExecutor { +public class ReserveNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(ReserveNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReturnNodeExecutor.java index e05692d5..d2fe35d7 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ReturnNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ReturnNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.Iterator; import java.util.Map; @@ -32,13 +32,13 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ReturnNodeExecutor extends SvcLogicNodeExecutor { +public class ReturnNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory .getLogger(ReturnNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String status = SvcLogicExpressionResolver.evaluate( diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SaveNodeExecutor.java index 1b5219be..2dfc4074 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SaveNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SaveNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.HashMap; import java.util.Iterator; @@ -33,12 +33,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SaveNodeExecutor extends SvcLogicNodeExecutor { +public class SaveNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(SaveNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutor.java index 8275a8e4..8bebb336 100755..100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.HashMap; import java.util.Iterator; @@ -34,13 +34,13 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SetNodeExecutor extends SvcLogicNodeExecutor { +public class SetNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(SetNodeExecutor.class); protected final String arrayPattern = "\\[\\d*\\]"; @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { execute(node,ctx); return null; diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolver.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolver.java index c9446bda..779be9e9 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolver.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolver.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.List; diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicPropertiesProvider.java index 9debd6bc..fc108f95 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicPropertiesProvider.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicPropertiesProvider.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.Properties; 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<String, AbstractSvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, AbstractSvcLogicNodeExecutor>() { + { + 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<String, AbstractSvcLogicNodeExecutor> 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/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SwitchNodeExecutor.java index 592fb288..2186a38e 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SwitchNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SwitchNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -27,14 +27,14 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SwitchNodeExecutor extends SvcLogicNodeExecutor { +public class SwitchNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory .getLogger(SwitchNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/UpdateNodeExecutor.java index a783df41..c4c8faa8 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/UpdateNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/UpdateNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.HashMap; import java.util.Iterator; @@ -33,12 +33,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class UpdateNodeExecutor extends SvcLogicNodeExecutor { +public class UpdateNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(UpdateNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx); diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/WhileNodeExecutor.java index b717aa98..c01e2f51 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/WhileNodeExecutor.java +++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/WhileNodeExecutor.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -29,12 +29,12 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class WhileNodeExecutor extends SvcLogicNodeExecutor { +public class WhileNodeExecutor extends AbstractSvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory.getLogger(WhileNodeExecutor.class); @Override - public SvcLogicNode execute(SvcLogicService svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { String testResult = evaluateNodeTest(node, ctx); SvcLogicExpression silentFailureExpr = node.getAttribute("do"); diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/BadPlugin.java index f5a39f50..6c5877eb 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/BadPlugin.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.Map; diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyAdaptor.java index 0f3893ef..58582e0e 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyAdaptor.java @@ -1,7 +1,7 @@ /** * */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.Map; import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyRecorder.java index e87f9628..52bc123a 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyRecorder.java @@ -1,4 +1,4 @@ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.Map; import org.onap.ccsdk.sli.core.sli.SvcLogicException; diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyResource.java index 2f784186..2e15f3fb 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/DummyResource.java @@ -1,7 +1,7 @@ /** * */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.Map; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutorTest.java index 33ce6f69..474136d5 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutorTest.java @@ -19,9 +19,10 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +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; @@ -30,8 +31,9 @@ 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 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; @@ -53,8 +55,15 @@ public class ExecuteNodeExecutorTest extends TestCase { 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()); + 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/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/LunchSelectorPlugin.java index b86edb06..0f4cab74 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/LunchSelectorPlugin.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.Map; diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/PluginTest.java index 98e0753d..cbeb5971 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/PluginTest.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.lang.reflect.Method; import java.util.HashMap; @@ -29,8 +29,8 @@ 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 org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicExpressionResolver; import junit.framework.TestCase; diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutorTest.java index 7c6f4ce5..115989a8 100755..100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SetNodeExecutorTest.java @@ -1,4 +1,4 @@ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -8,6 +8,7 @@ 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 diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java index a08144ee..bf4a2622 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.io.BufferedReader; import java.io.InputStream; @@ -31,7 +31,7 @@ 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.onap.ccsdk.sli.core.sli.provider.base.SvcLogicExpressionResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/VoidDummyPlugin.java index 8c7b0d30..b2332e05 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/VoidDummyPlugin.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.sli.core.sli.provider; +package org.onap.ccsdk.sli.core.sli.provider.base; import java.util.Map; diff --git a/sli/provider/src/test/resources/clearMultipleArrayValues.xml b/sli/provider-base/src/test/resources/clearMultipleArrayValues.xml index 8f40058f..8f40058f 100644 --- a/sli/provider/src/test/resources/clearMultipleArrayValues.xml +++ b/sli/provider-base/src/test/resources/clearMultipleArrayValues.xml diff --git a/sli/provider/src/test/resources/clearNestedSubArrayValues.xml b/sli/provider-base/src/test/resources/clearNestedSubArrayValues.xml index a80b3e56..a80b3e56 100644 --- a/sli/provider/src/test/resources/clearNestedSubArrayValues.xml +++ b/sli/provider-base/src/test/resources/clearNestedSubArrayValues.xml diff --git a/sli/provider/src/test/resources/clearSingleArrayValues.xml b/sli/provider-base/src/test/resources/clearSingleArrayValues.xml index 56781a06..56781a06 100644 --- a/sli/provider/src/test/resources/clearSingleArrayValues.xml +++ b/sli/provider-base/src/test/resources/clearSingleArrayValues.xml diff --git a/sli/provider/src/test/resources/clearSingleSubArrayValues.xml b/sli/provider-base/src/test/resources/clearSingleSubArrayValues.xml index 22f14f37..22f14f37 100644 --- a/sli/provider/src/test/resources/clearSingleSubArrayValues.xml +++ b/sli/provider-base/src/test/resources/clearSingleSubArrayValues.xml diff --git a/sli/provider/src/test/resources/clearSubArrayValues.xml b/sli/provider-base/src/test/resources/clearSubArrayValues.xml index cb25f38a..cb25f38a 100644 --- a/sli/provider/src/test/resources/clearSubArrayValues.xml +++ b/sli/provider-base/src/test/resources/clearSubArrayValues.xml diff --git a/sli/provider/src/test/resources/clearValues.xml b/sli/provider-base/src/test/resources/clearValues.xml index dc7f5c8a..dc7f5c8a 100644 --- a/sli/provider/src/test/resources/clearValues.xml +++ b/sli/provider-base/src/test/resources/clearValues.xml diff --git a/sli/provider/src/test/resources/copyValues.xml b/sli/provider-base/src/test/resources/copyValues.xml index f56f7140..f56f7140 100644 --- a/sli/provider/src/test/resources/copyValues.xml +++ b/sli/provider-base/src/test/resources/copyValues.xml diff --git a/sli/provider/src/test/resources/expression.tests b/sli/provider-base/src/test/resources/expression.tests index 848a0e7a..848a0e7a 100755..100644 --- a/sli/provider/src/test/resources/expression.tests +++ b/sli/provider-base/src/test/resources/expression.tests 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 @@ <version>${project.version}</version> <scope>compile</scope> </dependency> - + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider-base</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> 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/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<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() { - { - 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<String, SvcLogicNodeExecutor> 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/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<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() { + private static final Map<String, AbstractSvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, AbstractSvcLogicNodeExecutor>() { { put("block", new BlockNodeExecutor()); put("break", new BreakNodeExecutor()); 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 @@ -62,6 +62,11 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider-base</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.opendaylight.controller</groupId> <artifactId>sal-core-api</artifactId> </dependency> 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<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() { + private static final Map<String, AbstractSvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, AbstractSvcLogicNodeExecutor>() { { put("block", new BlockNodeExecutor()); put("call", new CallNodeExecutor()); |