From 86e489058f5a8f75f0b8fbcbd0a3eca2dbcb4470 Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Thu, 4 Oct 2018 20:12:40 +0000 Subject: [PATCH] implement exit node exit node functions similar to a return statement in most programming languages Change-Id: I2991590fb700b03a9f3d72ae0bc7b5dd9bb25f74 Issue-ID: CCSDK-611 Signed-off-by: Smokowski, Kevin (ks6305) --- .../onap/ccsdk/sli/core/sli/ExitNodeException.java | 46 ++ sli/common/src/main/resources/svclogic.xsd | 673 +++++++++++---------- sli/common/src/test/resources/svclogic.xsd | 71 ++- .../sli/core/sli/provider/ExitNodeExecutor.java | 42 ++ .../sli/core/sli/provider/SvcLogicServiceImpl.java | 45 +- 5 files changed, 500 insertions(+), 377 deletions(-) create mode 100755 sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/ExitNodeException.java create mode 100755 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/ExitNodeExecutor.java diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/ExitNodeException.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/ExitNodeException.java new file mode 100755 index 00000000..f119c181 --- /dev/null +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/ExitNodeException.java @@ -0,0 +1,46 @@ +/*- + * ============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; + +public class ExitNodeException extends SvcLogicException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public ExitNodeException() + { + super(); + } + + public ExitNodeException(String message) + { + super(message); + } + + public ExitNodeException(String message, Throwable t) + { + super(message, t); + } + +} diff --git a/sli/common/src/main/resources/svclogic.xsd b/sli/common/src/main/resources/svclogic.xsd index 2704de88..c9beae83 100755 --- a/sli/common/src/main/resources/svclogic.xsd +++ b/sli/common/src/main/resources/svclogic.xsd @@ -1,334 +1,339 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sli/common/src/test/resources/svclogic.xsd b/sli/common/src/test/resources/svclogic.xsd index 2704de88..3e109c7c 100755 --- a/sli/common/src/test/resources/svclogic.xsd +++ b/sli/common/src/test/resources/svclogic.xsd @@ -31,13 +31,14 @@ + - + @@ -47,7 +48,7 @@ - + @@ -57,7 +58,7 @@ - + @@ -66,7 +67,7 @@ - + @@ -78,7 +79,7 @@ - + @@ -90,7 +91,7 @@ - + @@ -101,8 +102,8 @@ - - + + @@ -115,7 +116,7 @@ - + @@ -127,8 +128,8 @@ - - + + @@ -138,8 +139,8 @@ - - + + @@ -152,8 +153,8 @@ - - + + @@ -169,8 +170,8 @@ - - + + @@ -190,7 +191,7 @@ - + @@ -199,7 +200,7 @@ - + @@ -208,8 +209,8 @@ - - + + @@ -224,8 +225,8 @@ - - + + @@ -242,7 +243,7 @@ - + @@ -255,7 +256,7 @@ - + @@ -265,8 +266,8 @@ - - + + @@ -277,8 +278,8 @@ - - + + @@ -293,8 +294,8 @@ - - + + @@ -306,7 +307,7 @@ - + @@ -321,10 +322,14 @@ + + + + - + 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 new file mode 100755 index 00000000..fc667f40 --- /dev/null +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/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; + +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/SvcLogicServiceImpl.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java index 000c2872..0a286958 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 @@ -26,6 +26,7 @@ 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; @@ -70,7 +71,7 @@ public class SvcLogicServiceImpl implements SvcLogicService { put("update", new UpdateNodeExecutor()); put("break", new BreakNodeExecutor()); put("while", new WhileNodeExecutor()); - + put("exit", new ExitNodeExecutor()); } }; @@ -151,14 +152,17 @@ public class SvcLogicServiceImpl implements SvcLogicService { SvcLogicNode curNode = graph.getRootNode(); LOG.info("About to execute graph {}", graph.toString()); - - while (curNode != null) { - MDC.put("nodeId", curNode.getNodeId() + " (" + curNode.getNodeType() + ")"); - LOG.info("About to execute node # {} ({})", curNode.getNodeId(), curNode.getNodeType()); - - SvcLogicNode nextNode = executeNode(curNode, ctx); - curNode = nextNode; - } + try { + while (curNode != null) { + MDC.put("nodeId", curNode.getNodeId() + " (" + curNode.getNodeType() + ")"); + LOG.info("About to execute node # {} ({})", curNode.getNodeId(), curNode.getNodeType()); + + SvcLogicNode nextNode = executeNode(curNode, ctx); + curNode = nextNode; + } + } catch (ExitNodeException e) { + LOG.debug("SvcLogicServiceImpl caught ExitNodeException"); + } MDC.remove("nodeId"); MDC.remove("currentGraph"); @@ -181,7 +185,28 @@ public class SvcLogicServiceImpl implements SvcLogicService { executor.getClass().getName()); 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"); + if (LOG.isDebugEnabled()) { + LOG.debug("{} node not implemented", node.getNodeType()); + } + SvcLogicNode nextNode = node.getOutcomeValue("failure"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute failure branch"); + } + return (nextNode); + } + + nextNode = node.getOutcomeValue("Other"); + if (nextNode != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("about to execute Other branch"); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("no failure or Other branch found"); + } + } + return (nextNode); } } -- 2.16.6