aboutsummaryrefslogtreecommitdiffstats
path: root/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider
diff options
context:
space:
mode:
Diffstat (limited to 'sli/provider/src/main/java/org/openecomp/sdnc/sli/provider')
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BlockNodeExecutor.java75
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java165
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ConfigureNodeExecutor.java249
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java115
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java138
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java118
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java97
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java146
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java117
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java1405
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java118
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java129
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java116
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java127
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReturnNodeExecutor.java78
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java154
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java190
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java225
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicAdaptorFactory.java86
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java605
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicNodeExecutor.java43
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicService.java82
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java287
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java67
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java148
25 files changed, 5080 insertions, 0 deletions
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BlockNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BlockNodeExecutor.java
new file mode 100644
index 0000000..a70dfc8
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BlockNodeExecutor.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BlockNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(BlockNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx)
+ throws SvcLogicException {
+
+ SvcLogicExpression atomicExpr = node.getAttribute("atomic");
+ String atomicStr = SvcLogicExpressionResolver.evaluate(atomicExpr, node, ctx);
+ boolean isAtomic = "true".equalsIgnoreCase(atomicStr);
+
+ // Initialize status to success so that at least one outcome will execute
+ ctx.setStatus("success");
+
+ int numOutcomes = node.getNumOutcomes();
+
+ for (int i = 0; i < numOutcomes; i++) {
+ if ("failure".equals(ctx.getStatus()) && isAtomic) {
+ LOG.info("Block - stopped executing nodes due to failure status");
+ return(null);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1));
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Block - executing outcome " + (i + 1));
+ }
+ while (nextNode != null)
+ {
+ nextNode = svc.executeNode(nextNode, ctx);
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Block - done: no outcome " + (i + 1));
+ }
+ }
+ }
+
+ return (null);
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java
new file mode 100644
index 0000000..2a0b77a
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java
@@ -0,0 +1,165 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicGraph;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CallNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(CallNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx)
+ throws SvcLogicException {
+
+ String outValue = "not-found";
+
+ SvcLogicGraph myGraph = node.getGraph();
+
+ if (myGraph == null)
+ {
+ LOG.debug("execute: getGraph returned null");
+ }
+ else
+ {
+ LOG.debug("execute: got SvcLogicGraph");
+ }
+
+ SvcLogicExpression moduleExpr = null;
+
+ String module = null;
+
+ moduleExpr = node.getAttribute("module");
+ if (moduleExpr != null)
+ {
+ module = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
+ }
+
+ if ((module == null) || (module.length() == 0))
+ {
+ if (myGraph != null)
+ {
+ module = myGraph.getModule();
+ LOG.debug("myGraph.getModule() returned "+module);
+ }
+ }
+
+ SvcLogicExpression rpcExpr = null;
+ String rpc = null;
+ rpcExpr = node.getAttribute("rpc");
+ if (rpcExpr != null)
+ {
+ rpc = SvcLogicExpressionResolver.evaluate(rpcExpr, node, ctx);
+ }
+
+ if ((rpc == null) || (rpc.length() == 0))
+ {
+ if (myGraph != null)
+ {
+ rpc = myGraph.getRpc();
+ LOG.debug("myGraph.getRpc() returned "+rpc);
+ }
+ }
+
+ String mode = null;
+
+ moduleExpr = node.getAttribute("mode");
+ if (moduleExpr != null)
+ {
+ mode = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
+ }
+
+ if ((mode == null) || (mode.length() == 0))
+ {
+ if (myGraph != null)
+ {
+ mode = myGraph.getMode();
+
+ LOG.debug("myGraph.getMode() returned "+mode);
+ }
+ }
+
+ String version = null;
+
+ moduleExpr = node.getAttribute("version");
+ if (moduleExpr != null)
+ {
+ version = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
+ }
+
+
+ SvcLogicStore store = SvcLogicActivator.getStore();
+
+ LOG.debug("Calling ["+module+","+rpc+","+version+","+mode+"]");
+
+ if (store != null)
+ {
+ SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode);
+
+ if (calledGraph != null)
+ {
+ svc.execute(calledGraph, ctx);
+
+ outValue = ctx.getStatus();
+ }
+ else
+ {
+ LOG.debug("Could not find service logic for ["+module+","+rpc+","+version+","+mode+"]");
+ }
+ }
+ else
+ {
+ LOG.debug("Could not get SvcLogicStore reference");
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no " + outValue + " or Other branch found");
+ }
+ }
+ return (nextNode);
+
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ConfigureNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ConfigureNodeExecutor.java
new file mode 100644
index 0000000..a24b01c
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ConfigureNodeExecutor.java
@@ -0,0 +1,249 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.sdnc.sli.SvcLogicAdaptor;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ConfigureNodeExecutor extends SvcLogicNodeExecutor {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ConfigureNodeExecutor.class);
+
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String adaptorName = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("adaptor"), node, ctx);
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("configure node encountered - looking for adaptor "
+ + adaptorName);
+ }
+
+ SvcLogicAdaptor adaptor = SvcLogicAdaptorFactory
+ .getInstance(adaptorName);
+
+ if (adaptor != null) {
+ String activate = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("activate"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("key"), node, ctx);
+
+ Map<String, String> parmMap = new HashMap<String, String>();
+
+ Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
+ .getParameterSet();
+ boolean hasParms = false;
+
+ for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
+ .iterator(); iter.hasNext();) {
+ hasParms = true;
+ Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
+ String curName = curEnt.getKey();
+ SvcLogicExpression curExpr = curEnt.getValue();
+ String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
+
+ LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue);
+
+ parmMap.put(curName,curExprValue);
+ }
+
+ if (hasParms) {
+ SvcLogicAdaptor.ConfigStatus confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+
+ try {
+ confStatus = adaptor.configure(key, parmMap, ctx);
+ } catch (Exception e) {
+ LOG.warn("Caught exception from "+adaptorName+".configure", e);
+ confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+ }
+
+ switch (confStatus) {
+ case SUCCESS:
+ outValue = "success";
+ if ((activate != null) && (activate.length() > 0)) {
+ if ("true".equalsIgnoreCase(activate)) {
+ SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+
+ try {
+ activateStatus = adaptor.activate(key, ctx);
+ } catch (Exception e) {
+
+ LOG.warn("Caught exception from "+adaptorName+".activate", e);
+ activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+ }
+ switch (activateStatus) {
+ case SUCCESS:
+ break;
+ case ALREADY_ACTIVE:
+ outValue = "already-active";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case NOT_READY:
+ outValue = "not-ready";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } else if ("false".equalsIgnoreCase(activate)) {
+ SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+
+ try {
+ deactivateStatus = adaptor.deactivate(key, ctx);
+ } catch (Exception e) {
+
+ LOG.warn("Caught exception from "+adaptorName+".deactivate", e);
+ deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+ }
+ switch (deactivateStatus) {
+ case SUCCESS:
+ break;
+ case ALREADY_ACTIVE:
+ outValue = "already-active";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case NOT_READY:
+ outValue = "not-ready";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ }
+ }
+ break;
+ case ALREADY_ACTIVE:
+ outValue = "already-active";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case NOT_READY:
+ outValue = "not-ready";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } else {
+ if ((activate != null) && (activate.length() > 0)) {
+ if ("true".equalsIgnoreCase(activate)) {
+ SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+ try {
+ activateStatus = adaptor.activate(key, ctx);
+ } catch (Exception e) {
+ LOG.warn("Caught exception from "+adaptorName+".activate", e);
+ activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+ }
+ switch (activateStatus) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case ALREADY_ACTIVE:
+ outValue = "already-active";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case NOT_READY:
+ outValue = "not-ready";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } else if ("false".equalsIgnoreCase(activate)) {
+ SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+
+ try {
+ deactivateStatus = adaptor.deactivate(key, ctx);
+ } catch (Exception e) {
+ LOG.warn("Caught exception from "+adaptorName+".deactivate", e);
+ deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
+ }
+ switch (deactivateStatus) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case ALREADY_ACTIVE:
+ outValue = "already-active";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case NOT_READY:
+ outValue = "not-ready";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ }
+ } else {
+ LOG.warn("Nothing to configure - no parameters passed, and activate attribute is not set");
+ outValue = "success";
+ }
+ }
+ } else {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Adaptor for " + adaptorName + " not found");
+ }
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no " + outValue + " or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java
new file mode 100644
index 0000000..da8386c
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DeleteNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(DeleteNodeExecutor.class);
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("delete node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+
+ try {
+
+ switch (resourcePlugin.delete(resourceType, key, ctx)) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Could not find service reference object for plugin "
+ + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java
new file mode 100644
index 0000000..d6c7a8d
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java
@@ -0,0 +1,138 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.sdnc.sli.SvcLogicAdaptor;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ExecuteNodeExecutor extends SvcLogicNodeExecutor {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ExecuteNodeExecutor.class);
+
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String pluginName = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("execute node encountered - looking for plugin "
+ + pluginName);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(pluginName);
+
+ if (sref == null) {
+ outValue = "not-found";
+ } else {
+ SvcLogicJavaPlugin plugin = (SvcLogicJavaPlugin) bctx
+ .getService(sref);
+
+ String methodName = SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx);
+
+ Class pluginClass = plugin.getClass();
+
+ Method pluginMethod = null;
+
+ try {
+ pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class);
+ } catch (Exception e) {
+ LOG.error("Caught exception looking for method "+pluginName+"."+methodName+"(Map, SvcLogicContext)");
+ }
+
+ if (pluginMethod == null) {
+ outValue = "unsupported-method";
+ } else {
+ try {
+
+ Map<String, String> parmMap = new HashMap<String, String>();
+
+ Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
+ .getParameterSet();
+
+ for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
+ .iterator(); iter.hasNext();) {
+ Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
+ String curName = curEnt.getKey();
+ SvcLogicExpression curExpr = curEnt.getValue();
+ String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
+
+ LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue);
+
+ parmMap.put(curName,curExprValue);
+ }
+
+ pluginMethod.invoke(plugin, parmMap, ctx);
+
+ outValue = "success";
+ } catch (Exception e) {
+ LOG.error("Caught exception executing "+pluginName+"."+methodName, e);
+
+ outValue = "failure";
+ ctx.setStatus("failure");
+ }
+ }
+
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no " + outValue + " or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java
new file mode 100644
index 0000000..52bc372
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ExistsNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ExistsNodeExecutor.class);
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+ String pfx = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("pfx"), node, ctx);
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("exists node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+
+ try {
+
+ switch (resourcePlugin.exists(resourceType, key, pfx, ctx)) {
+ case SUCCESS:
+ outValue = "true";
+ break;
+ case NOT_FOUND:
+ outValue = "false";
+ break;
+ case FAILURE:
+ default:
+ outValue = "false";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Could not find service reference object for plugin "
+ + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java
new file mode 100644
index 0000000..e824d85
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ForNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ForNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ SvcLogicExpression atomicExpr = node.getAttribute("atomic");
+ String atomicStr = SvcLogicExpressionResolver.evaluate(atomicExpr, node, ctx);
+ boolean isAtomic = !("false".equalsIgnoreCase(atomicStr));
+
+ int numOutcomes = node.getNumOutcomes();
+ String idxVar = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("index"), node, ctx);
+ String startVal = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("start"), node, ctx);
+ String endVal = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("end"), node, ctx);
+
+ LOG.debug("Executing "+ (isAtomic ? "atomic" : "non-atomic") + " for loop - for (int " + idxVar + " = " + startVal
+ + "; " + idxVar + " < " + endVal + "; " + idxVar + "++)");
+
+ int startIdx = 0;
+ int endIdx = 0;
+
+ try {
+ startIdx = Integer.parseInt(startVal);
+ endIdx = Integer.parseInt(endVal);
+ } catch (NumberFormatException e) {
+ throw new SvcLogicException("Invalid index values [" + startVal
+ + "," + endVal + "]");
+ }
+
+ for (int ctr = startIdx; ctr < endIdx; ctr++) {
+
+ ctx.setAttribute(idxVar, "" + ctr);
+
+ for (int i = 0; i < numOutcomes; i++) {
+
+ if ("failure".equals(ctx.getStatus()) && isAtomic) {
+ LOG.info("For - stopped executing nodes due to failure status");
+ return(null);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1));
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("For - executing outcome " + (i + 1));
+ }
+ SvcLogicNode innerNextNode = nextNode;
+ while (innerNextNode != null) {
+ innerNextNode = svc.executeNode(innerNextNode, ctx);
+ }
+
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("For - done: no outcome " + (i + 1));
+ }
+ }
+ }
+ }
+ return (null);
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java
new file mode 100644
index 0000000..71fdf3a
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java
@@ -0,0 +1,146 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GetResourceNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(GetResourceNodeExecutor.class);
+
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+ String pfx = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("pfx"), node, ctx);
+
+ String localOnlyStr = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("local-only"), node, ctx);
+
+ // Note: for get-resource, only refresh from A&AI if the DG explicitly set
+ // local-only to false. Otherwise, just read from local database.
+ boolean localOnly = true;
+
+ if ("false".equalsIgnoreCase(localOnlyStr)) {
+ localOnly = false;
+ }
+
+ SvcLogicExpression selectExpr = node.getAttribute("select");
+ String select = null;
+
+ if (selectExpr != null) {
+ select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node,
+ ctx);
+ }
+
+ SvcLogicExpression orderByExpr = node.getAttribute("order-by");
+ String orderBy = null;
+
+ if (orderByExpr != null) {
+ orderBy = SvcLogicExpressionResolver.evaluateAsKey(orderByExpr, node,
+ ctx);
+ }
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(node.getNodeType()
+ + " node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+
+ try {
+ switch (resourcePlugin.query(resourceType, localOnly, select, key,
+ pfx, orderBy, ctx)) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Cound not find service reference for plugin " + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java
new file mode 100644
index 0000000..83f08b6
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java
@@ -0,0 +1,117 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IsAvailableNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(IsAvailableNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+ String pfx = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("pfx"), node, ctx);
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("is-available node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+ try {
+ switch (resourcePlugin.isAvailable(resourceType, key, pfx, ctx)) {
+ case SUCCESS:
+ outValue = "true";
+ break;
+ case NOT_FOUND:
+ outValue = "false";
+ break;
+ case FAILURE:
+ default:
+ outValue = "false";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Could not find service reference object for plugin "
+ + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java
new file mode 100644
index 0000000..af172f9
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java
@@ -0,0 +1,1405 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MdsalHelper {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MdsalHelper.class);
+ public static final String PROPERTIES_FILE="/opt/bvc/controller/configuration/l3sdn.properties";
+ private static Properties properties = new Properties();
+
+
+ public static void setProperties(Properties properties) {
+
+ for (Object propNameObj: properties.keySet()) {
+ String propName = (String) propNameObj;
+ MdsalHelper.properties.setProperty(propName, properties.getProperty(propName));
+ }
+ }
+
+ public static void loadProperties() {
+
+ File file = new File(PROPERTIES_FILE);
+ Properties properties = new Properties();
+ InputStream input = null;
+ if (file.isFile() && file.canRead()) {
+ try {
+ input = new FileInputStream(file);
+ properties.load(input);
+ MdsalHelper.setProperties(properties);
+ LOG.info("Loaded properties from " + PROPERTIES_FILE );
+ } catch (Exception e) {
+ LOG.error("Failed to load properties " + PROPERTIES_FILE +"\n",e);
+ } finally {
+ if (input != null) {
+ try {
+ input.close();
+ } catch (IOException e) {
+ LOG.error("Failed to close properties file " + PROPERTIES_FILE +"\n",e);
+ }
+ }
+ }
+ }
+ }
+
+ public static Properties toProperties(Properties props, Object fromObj) {
+ Class fromClass = null;
+
+ if (fromObj != null)
+ {
+ fromClass = fromObj.getClass();
+ }
+ return (toProperties(props, "", fromObj, fromClass));
+ }
+
+ public static Properties toProperties(Properties props, String pfx, Object fromObj)
+ {
+ Class fromClass = null;
+
+ if (fromObj != null)
+ {
+ fromClass = fromObj.getClass();
+ }
+
+ return(toProperties(props, pfx, fromObj, fromClass));
+ }
+
+ public static Properties toProperties(Properties props, String pfx,
+ Object fromObj, Class fromClass) {
+
+ if (fromObj == null) {
+ return (props);
+ }
+
+
+ String simpleName = fromClass.getSimpleName();
+
+ LOG.trace("Extracting properties from " + fromClass.getName()
+ + " class");
+ if (fromObj instanceof List) {
+
+ // Class is a List. List should contain yang-generated classes.
+ LOG.trace(fromClass.getName() + " is a List");
+
+ List fromList = (List) fromObj;
+
+ for (int i = 0; i < fromList.size(); i++) {
+ toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass);
+ }
+ props.setProperty(pfx + "_length", "" + fromList.size());
+
+ } else if (isYangGenerated(fromClass)) {
+ // Class is yang generated.
+ LOG.trace(fromClass.getName() + " is a Yang-generated class");
+
+ String propNamePfx = null;
+
+ // If called from a list (so prefix ends in ']'), don't
+ // add class name again
+ if (pfx.endsWith("]")) {
+ propNamePfx = pfx;
+ } else {
+ if ((pfx != null) && (pfx.length() > 0)) {
+ propNamePfx = pfx ;
+ } else {
+ propNamePfx = toLowerHyphen(fromClass.getSimpleName());
+ }
+
+ if (propNamePfx.endsWith("-builder")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length()
+ - "-builder".length());
+ }
+
+ if (propNamePfx.endsWith("-impl")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length()
+ - "-impl".length());
+ }
+ }
+
+ // Iterate through getter methods to figure out values we need to
+ // save from
+
+ int numGetters = 0;
+ String lastGetterName = null;
+ String propVal = null;
+
+ for (Method m : fromClass.getMethods()) {
+ if (isGetter(m)) {
+
+ numGetters++;
+ lastGetterName = m.getName();
+
+ Class returnType = m.getReturnType();
+ String fieldName;
+ if (m.getName().startsWith("get")) {
+ fieldName = toLowerHyphen(m.getName().substring(3));
+ } else {
+
+ fieldName = toLowerHyphen(m.getName().substring(2));
+ }
+
+ fieldName = fieldName.substring(0, 1).toLowerCase()
+ + fieldName.substring(1);
+
+ // Is the return type a yang generated class?
+ if (isYangGenerated(returnType)) {
+ // Is it an enum?
+ if (returnType.isEnum()) {
+ // Return type is a typedef. Save its value.
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+
+ Object retValue = m.invoke(fromObj);
+
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ if (retValue != null) {
+ String propName = propNamePfx + "."
+ + fieldName;
+ propVal = retValue.toString();
+ String yangProp = "yang." + fieldName + "." + propVal;
+ if ( properties.containsKey(yangProp)) {
+ propVal = properties.getProperty(yangProp);
+ LOG.trace("Adjusting property " + yangProp + " " + propVal);
+ }
+ LOG.debug("Setting property " + propName
+ + " to " + propVal);
+ props.setProperty(propName, propVal);
+ }
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert Yang-generated enum returned by "
+ + fromClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry", e);
+ }
+ } else if (isIpv4Address(returnType)) {
+ // Save its value
+ try {
+ String propName = propNamePfx + "." + fieldName;
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ Ipv4Address retValue = (Ipv4Address) m.invoke(fromObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+
+ if (retValue != null) {
+ propVal = retValue.getValue().toString();
+ LOG.debug("Setting property " + propName
+ + " to " + propVal);
+ props.setProperty(propName, propVal);
+
+ }
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert value returned by "
+ + fromClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry", e);
+ }
+ } else if (isIpv6Address(returnType)) {
+ // Save its value
+ try {
+ String propName = propNamePfx + "." + fieldName;
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ Ipv6Address retValue = (Ipv6Address) m.invoke(fromObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+
+ if (retValue != null) {
+ propVal = retValue.getValue().toString();
+ LOG.debug("Setting property " + propName
+ + " to " + propVal);
+ props.setProperty(propName, propVal);
+
+ }
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert value returned by "
+ + fromClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry", e);
+ }
+ } else if (isIpAddress(returnType)) {
+ // Save its value
+ try {
+ String propName = propNamePfx + "." + fieldName;
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ IpAddress retValue = (IpAddress) m.invoke(fromObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+
+ if (retValue != null) {
+ propVal = new String(retValue.getValue());
+ LOG.debug("Setting property " + propName
+ + " to " + propVal);
+ props.setProperty(propName, propVal);
+
+ }
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert value returned by "
+ + fromClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry", e);
+ }
+ } else if (isIpPrefix(returnType)) {
+ // Save its value
+ try {
+ String propName = propNamePfx + "." + fieldName;
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ IpPrefix retValue = (IpPrefix) m.invoke(fromObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+
+ if (retValue != null) {
+ propVal = new String(retValue.getValue());
+ LOG.debug("Setting property " + propName
+ + " to " + propVal);
+ props.setProperty(propName, propVal);
+
+ }
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert value returned by "
+ + fromClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry", e);
+ }
+ } else {
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ Object retValue = m.invoke(fromObj);
+
+ if (retValue instanceof byte[]) {
+ LOG.trace(m.getName()+" returns a byte[]");
+ retValue = new String((byte[]) retValue, "UTF-8");
+ LOG.trace("Converted byte array "+propNamePfx+"."+fieldName+"to string "+ retValue );
+ }
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ if (retValue != null) {
+ toProperties(props, propNamePfx + "." + fieldName, retValue, returnType);
+ }
+ } catch (Exception e) {
+
+ if (m.getName().equals("getKey")) {
+ LOG.trace("Caught "+e.getClass().getName()+" exception trying to convert results from getKey() - ignoring");
+ } else {
+ LOG.error(
+ "Caught exception trying to convert Yang-generated class returned by"
+ + fromClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry", e);
+ }
+ }
+ }
+ } else if (returnType.equals(Class.class)) {
+
+ LOG.trace(m.getName()
+ + " returns a Class object - not interested");
+
+ } else if (List.class.isAssignableFrom(returnType)) {
+
+ // This getter method returns a list.
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ Object retList = m.invoke(fromObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ // Figure out what type of elements are stored in this array.
+ Type paramType = m.getGenericReturnType();
+ Type elementType = ((ParameterizedType) paramType)
+ .getActualTypeArguments()[0];
+ toProperties(props, propNamePfx + "." + fieldName,
+ retList, (Class)elementType);
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert List returned by "
+ + fromClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry", e);
+ }
+
+ } else {
+
+ // Method returns something that is not a List and not
+ // yang-generated.
+ // Save its value
+ try {
+ String propName = propNamePfx + "." + fieldName;
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ Object propValObj = m.invoke(fromObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+
+ if (propValObj != null) {
+ if (propValObj instanceof byte[]) {
+ LOG.trace(m.getName()+" returns a byte[]");
+ propVal = new String((byte[]) propValObj, "UTF-8");
+ LOG.trace("Converted byte array "+propNamePfx+"."+fieldName+"to string "+ propVal );
+
+ } else {
+ propVal = propValObj.toString();
+ }
+ LOG.debug("Setting property " + propName
+ + " to " + propVal);
+ props.setProperty(propName, propVal);
+
+ }
+ } catch (Exception e) {
+ if (m.getName().equals("getKey")) {
+ LOG.trace("Caught "+e.getClass().getName()+" exception trying to convert results from getKey() - ignoring");
+ } else {
+ LOG.error(
+ "Caught exception trying to convert value returned by"
+ + fromClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry", e);
+ }
+ }
+ }
+
+ }
+ }
+
+ // End of method loop. If there was only one getter, named "getValue", then
+ // set value identified by "prefix" to that one value.
+ if ((numGetters == 1) && ("getValue".equals(lastGetterName))) {
+ LOG.trace("getValueFIX : "+ propNamePfx+" only has getValue() getter - setting "+propNamePfx+" = "+propVal);
+ props.setProperty(propNamePfx, propVal);
+ } else {
+ LOG.trace("getValueFIX : " + propNamePfx+" has "+numGetters+" getter(s), last one found was "+lastGetterName);
+
+ }
+
+ } else {
+ // Class is not yang generated and not a list
+ // It must be an element of a leaf list - set "prefix" to value
+ String fromVal = null;
+ if (fromObj instanceof byte[]) {
+ try {
+ fromVal = new String((byte[]) fromObj, "UTF-8");
+ LOG.trace("Converted byte array "+pfx+"to string "+ fromVal );
+ } catch (Exception e) {
+ LOG.warn("Caught exception trying to convert "+pfx+" from byte[] to String", e);
+ fromVal = fromObj.toString();
+ }
+
+ } else {
+ fromVal = fromObj.toString();
+ }
+ LOG.debug("Setting property " + pfx
+ + " to " + fromVal);
+ props.setProperty(pfx, fromVal);
+ }
+
+ return (props);
+ }
+
+ public static Object toBuilder(Properties props, Object toObj) {
+
+ return (toBuilder(props, "", toObj));
+ }
+
+ public static List toList(Properties props, String pfx, List toObj,
+ Class elemType) {
+
+ int maxIdx = -1;
+ boolean foundValue = false;
+
+ LOG.trace("Saving properties to List<" + elemType.getName()
+ + "> from " + pfx);
+
+ if (props.contains(pfx+"_length")) {
+ try {
+ int listLength = Integer.parseInt(props.getProperty(pfx+"_length"));
+
+ if (listLength > 0) {
+ maxIdx = listLength - 1;
+ }
+ } catch (Exception e) {
+ // Ignore exception
+ }
+ }
+
+ if (maxIdx == -1) {
+ // Figure out array size
+ for (Object pNameObj : props.keySet()) {
+ String key = (String) pNameObj;
+
+ if (key.startsWith(pfx + "[")) {
+ String idxStr = key.substring(pfx.length() + 1);
+ int endloc = idxStr.indexOf("]");
+ if (endloc != -1) {
+ idxStr = idxStr.substring(0, endloc);
+ }
+
+ try {
+ int curIdx = Integer.parseInt(idxStr);
+ if (curIdx > maxIdx) {
+ maxIdx = curIdx;
+ }
+ } catch (Exception e) {
+ LOG.error("Illegal subscript in property " + key);
+ }
+
+ }
+ }
+ }
+
+
+ LOG.trace(pfx + " has max index of " + maxIdx);
+ for (int i = 0; i <= maxIdx; i++) {
+
+ String curBase = pfx + "[" + i + "]";
+
+ if (isYangGenerated(elemType)) {
+ String builderName = elemType.getName() + "Builder";
+ try {
+ Class builderClass = Class.forName(builderName);
+ Object builderObj = builderClass.newInstance();
+ Method buildMethod = builderClass.getMethod("build");
+ builderObj = toBuilder(props, curBase, builderObj, true);
+ if (builderObj != null) {
+ LOG.trace("Calling " + builderObj.getClass().getName()
+ + "." + buildMethod.getName() + "()");
+ Object builtObj = buildMethod.invoke(builderObj);
+ toObj.add(builtObj);
+ foundValue = true;
+ }
+
+ } catch (ClassNotFoundException e) {
+ LOG.warn("Could not find builder class " + builderName, e);
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to populate list from "
+ + pfx);
+ }
+ } else {
+ // Must be a leaf list
+ String curValue = props.getProperty(curBase, "");
+
+ toObj.add(curValue);
+
+ if ((curValue != null) && (curValue.length() > 0)) {
+ foundValue = true;
+ }
+ }
+
+ }
+
+ if (foundValue) {
+ return (toObj);
+ } else {
+ return (null);
+ }
+
+ }
+
+ public static Object toBuilder(Properties props, String pfx, Object toObj) {
+ return(toBuilder(props, pfx, toObj, false));
+ }
+
+ public static Object toBuilder(Properties props, String pfx, Object toObj, boolean preservePfx) {
+ Class toClass = toObj.getClass();
+ boolean foundValue = false;
+
+ LOG.trace("Saving properties to " + toClass.getName() + " class from "
+ + pfx);
+
+ Ipv4Address addr;
+
+ if (isYangGenerated(toClass)) {
+ // Class is yang generated.
+ LOG.trace(toClass.getName() + " is a Yang-generated class");
+
+ String propNamePfx = null;
+ if (preservePfx) {
+ propNamePfx = pfx;
+ } else {
+
+ if ((pfx != null) && (pfx.length() > 0)) {
+ propNamePfx = pfx + "."
+ + toLowerHyphen(toClass.getSimpleName());
+ } else {
+ propNamePfx = toLowerHyphen(toClass.getSimpleName());
+ }
+
+ if (propNamePfx.endsWith("-builder")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length()
+ - "-builder".length());
+ }
+
+ if (propNamePfx.endsWith("-impl")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length()
+ - "-impl".length());
+ }
+ }
+
+ if (toObj instanceof Identifier) {
+ LOG.trace(toClass.getName() + " is a Key - skipping");
+ return (toObj);
+ }
+
+ // Iterate through getter methods to figure out values we need to
+ // set
+
+ for (Method m : toClass.getMethods()) {
+ if (isSetter(m)) {
+ Class paramTypes[] = m.getParameterTypes();
+ Class paramClass = paramTypes[0];
+
+ String fieldName = toLowerHyphen(m.getName().substring(3));
+ fieldName = fieldName.substring(0, 1).toLowerCase()
+ + fieldName.substring(1);
+
+ String propName = propNamePfx + "." + fieldName;
+
+ String paramValue = props.getProperty(propName);
+ if (paramValue == null) {
+ LOG.trace(propName + " is unset");
+ } else {
+ LOG.trace(propName + " = " + paramValue);
+ }
+
+ // Is the return type a yang generated class?
+ if (isYangGenerated(paramClass)) {
+ // Is it an enum?
+ if (paramClass.isEnum()) {
+
+ LOG.trace(m.getName() + " expects an Enum");
+ // Param type is a typedef.
+ if ((paramValue != null) && (paramValue.length() > 0)) {
+ Object paramObj = null;
+
+ try {
+ paramObj = Enum.valueOf(paramClass,
+ toUpperCamelCase(paramValue));
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert field "
+ + propName + " to enum "
+ + paramClass.getName(), e);
+ }
+
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+
+ LOG.trace("Calling "
+ + toObj.getClass().getName() + "."
+ + m.getName() + "(" + paramValue
+ + ")");
+ m.invoke(toObj, paramObj);
+
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
+
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to create Yang-generated enum expected by"
+ + toClass.getName()
+ + "."
+ + m.getName()
+ + "() from Properties entry",
+ e);
+ }
+ }
+ } else {
+
+ String simpleName = paramClass.getSimpleName();
+
+ if ("Ipv4Address".equals(simpleName)
+ || "Ipv6Address".equals(simpleName) || "IpAddress".equals(simpleName)) {
+
+ if ((paramValue != null) && (paramValue.length() > 0)) {
+ try {
+ IpAddress ipAddr = IpAddressBuilder
+ .getDefaultInstance(paramValue);
+
+
+ if ("Ipv4Address".equals(simpleName))
+ {
+ m.invoke(toObj, ipAddr.getIpv4Address());
+ }
+ else if ("Ipv6Address".equals(simpleName))
+ {
+ m.invoke(toObj, ipAddr.getIpv6Address());
+
+ }
+ else
+ {
+ m.invoke(toObj, ipAddr);
+ }
+ foundValue = true;
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception calling "
+ + toClass.getName() + "."
+ + m.getName() + "("
+ + paramValue + ")", e);
+
+ }
+ } else {
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ LOG.trace("Calling "
+ + toObj.getClass().getName()
+ + "." + m.getName() + "("
+ + paramValue + ")");
+ m.invoke(toObj, paramValue);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
+
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to call "
+ + toClass.getName()
+ + "."
+ + m.getName()
+ + "() with Properties entry",
+ e);
+ }
+ }
+ } else if ("IpPrefix".equals(simpleName)) {
+ if ((paramValue != null) && (paramValue.length() > 0)) {
+ try {
+ IpPrefix ipPrefix = IpPrefixBuilder.getDefaultInstance(paramValue);
+ m.invoke(toObj, ipPrefix);
+ foundValue = true;
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception calling "
+ + toClass.getName() + "."
+ + m.getName() + "("
+ + paramValue + ")", e);
+ }
+ }
+ } else {
+ // setter expects a yang-generated class. Need
+ // to
+ // create a builder to set it.
+
+ String builderName = paramClass.getName()
+ + "Builder";
+ Class builderClass = null;
+ Object builderObj = null;
+ Object paramObj = null;
+
+ Object constObj = null;
+
+ LOG.trace(m.getName()
+ + " expects a yang-generated class - looking for builder "
+ + builderName);
+ try {
+ builderClass = Class.forName(builderName);
+ builderObj = builderClass.newInstance();
+ paramObj = toBuilder(props, propNamePfx,
+ builderObj);
+ } catch (ClassNotFoundException e) {
+
+ if (paramValue == null) {
+ try {
+ boolean isAccessible = m
+ .isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ LOG.trace("Calling "
+ + toObj.getClass()
+ .getName() + "."
+ + m.getName() + "(null)");
+ m.invoke(toObj, new Object[]{null});
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
+
+ } catch (Exception e1) {
+ LOG.error(
+ "Caught exception trying to cally"
+ + toClass.getName()
+ + "."
+ + m.getName()
+ + "() with Properties entry",
+ e1);
+ }
+ } else {
+ try {
+ // See if I can find a constructor I
+ // can
+ // use
+ Constructor[] constructors = paramClass
+ .getConstructors();
+ // Is there a String constructor?
+ for (Constructor c : constructors) {
+ Class[] cParms = c
+ .getParameterTypes();
+ if ((cParms != null)
+ && (cParms.length == 1)) {
+ if (String.class
+ .isAssignableFrom(cParms[0])) {
+ constObj = c
+ .newInstance(paramValue);
+ }
+ }
+ }
+
+ if (constObj == null) {
+ // Is there a Long constructor?
+ for (Constructor c : constructors) {
+ Class[] cParms = c
+ .getParameterTypes();
+ if ((cParms != null)
+ && (cParms.length == 1)) {
+ if (Long.class
+ .isAssignableFrom(cParms[0])) {
+ constObj = c
+ .newInstance(Long
+ .parseLong(paramValue));
+ }
+ }
+ }
+
+ }
+
+ if (constObj == null) {
+
+ // Last chance - see if
+ // parameter class has a static
+ // method
+ // getDefaultInstance(String)
+ try {
+ Method gm = paramClass
+ .getMethod(
+ "getDefaultInstance",
+ String.class);
+
+ int gmodifier = gm
+ .getModifiers();
+ if (Modifier
+ .isStatic(gmodifier)) {
+ // Invoke static
+ // getDefaultInstance(String)
+ paramObj = gm.invoke(
+ null,
+ paramValue);
+ }
+
+ } catch (Exception gme) {
+ // Ignore exceptions
+ }
+ }
+
+
+ } catch (Exception e1) {
+ LOG.warn(
+ "Could not find a suitable constructor for "
+ + paramClass
+ .getName(),
+ e1);
+ }
+
+ if (constObj == null) {
+ LOG.warn("Could not find builder class "
+ + builderName
+ + " and could not find a String or Long constructor or static getDefaultInstance(String) - trying just to set passing paramValue");
+
+ }
+ }
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to create builder "
+ + builderName, e);
+ }
+
+ if (paramObj != null) {
+
+ try {
+
+ Method buildMethod = builderClass
+ .getMethod("build");
+ LOG.trace("Calling "
+ + paramObj.getClass().getName()
+ + "." + buildMethod.getName()
+ + "()");
+ Object builtObj = buildMethod
+ .invoke(paramObj);
+
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+
+ LOG.trace("Calling "
+ + toObj.getClass().getName()
+ + "." + m.getName() + "()");
+ m.invoke(toObj, builtObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
+
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to set Yang-generated class expected by"
+ + toClass.getName()
+ + "."
+ + m.getName()
+ + "() from Properties entry",
+ e);
+ }
+ } else {
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+
+ if (constObj != null) {
+
+ LOG.trace("Calling "
+ + toObj.getClass()
+ .getName() + "."
+ + m.getName() + "("
+ + constObj.toString() + ")");
+ m.invoke(toObj, constObj);
+ } else {
+ LOG.trace("Calling "
+ + toObj.getClass()
+ .getName() + "."
+ + m.getName() + "("
+ + paramValue + ")");
+ m.invoke(toObj, paramValue);
+
+ }
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
+
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert value returned by"
+ + toClass.getName()
+ + "."
+ + m.getName()
+ + "() to Properties entry",
+ e);
+ }
+ }
+ }
+ }
+ } else {
+
+ // Setter's argument is not a yang-generated class. See
+ // if it is a List.
+
+ if (List.class.isAssignableFrom(paramClass)) {
+
+ LOG.trace("Parameter class " + paramClass.getName()
+ + " is a List");
+
+ // Figure out what type of args are in List and pass
+ // that to toList().
+
+ Type paramType = m.getGenericParameterTypes()[0];
+ Type elementType = ((ParameterizedType) paramType)
+ .getActualTypeArguments()[0];
+ Object paramObj = new LinkedList();
+ try {
+ paramObj = toList(props, propName,
+ (List) paramObj, (Class) elementType);
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to create list expected as argument to "
+ + toClass.getName() + "." + m.getName());
+ }
+
+ if (paramObj != null) {
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ LOG.trace("Calling "
+ + toObj.getClass().getName() + "."
+ + m.getName() + "(" + paramValue
+ + ")");
+ m.invoke(toObj, paramObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
+
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert List returned by"
+ + toClass.getName() + "."
+ + m.getName()
+ + "() to Properties entry",
+ e);
+ }
+ }
+ } else {
+
+ // Setter expects something that is not a List and
+ // not yang-generated. Just pass the parameter value
+
+ LOG.trace("Parameter class "
+ + paramClass.getName()
+ + " is not a yang-generated class or a List");
+
+ if ((paramValue != null) && (paramValue.length() > 0)) {
+
+ Object constObj = null;
+
+ try {
+ // See if I can find a constructor I can use
+ Constructor[] constructors = paramClass
+ .getConstructors();
+ // Is there a String constructor?
+ for (Constructor c : constructors) {
+ Class[] cParms = c.getParameterTypes();
+ if ((cParms != null)
+ && (cParms.length == 1)) {
+ if (String.class
+ .isAssignableFrom(cParms[0])) {
+ constObj = c
+ .newInstance(paramValue);
+ }
+ }
+ }
+
+ if (constObj == null) {
+ // Is there a Long constructor?
+ for (Constructor c : constructors) {
+ Class[] cParms = c
+ .getParameterTypes();
+ if ((cParms != null)
+ && (cParms.length == 1)) {
+ if (Long.class
+ .isAssignableFrom(cParms[0])) {
+ constObj = c
+ .newInstance(Long
+ .parseLong(paramValue));
+ }
+ }
+ }
+
+ }
+
+ if (constObj != null) {
+ try {
+ LOG.trace("Calling "
+ + toObj.getClass()
+ .getName() + "."
+ + m.getName() + "("
+ + constObj + ")");
+ m.invoke(toObj, constObj);
+ foundValue = true;
+ } catch (Exception e2) {
+ LOG.error(
+ "Caught exception trying to call "
+ + m.getName(), e2);
+ }
+ } else {
+ try {
+ boolean isAccessible = m
+ .isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ LOG.trace("Calling "
+ + toObj.getClass()
+ .getName() + "."
+ + m.getName() + "("
+ + paramValue + ")");
+ m.invoke(toObj, paramValue);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
+
+ } catch (Exception e) {
+ LOG.error(
+ "Caught exception trying to convert value returned by"
+ + toClass.getName()
+ + "."
+ + m.getName()
+ + "() to Properties entry",
+ e);
+ }
+ }
+ } catch (Exception e1) {
+ LOG.warn(
+ "Could not find a suitable constructor for "
+ + paramClass.getName(), e1);
+ }
+
+
+ }
+ }
+ }
+ } // End of section handling "setter" method
+ } // End of loop through Methods
+ } // End of section handling yang-generated class
+
+ if (foundValue) {
+ return (toObj);
+ } else {
+ return (null);
+ }
+ }
+
+ public static void printPropertyList(PrintStream pstr, String pfx,
+ Class toClass) {
+ boolean foundValue = false;
+
+ LOG.trace("Analyzing " + toClass.getName() + " class : pfx " + pfx);
+
+ if (isYangGenerated(toClass)
+ && (!Identifier.class.isAssignableFrom(toClass))) {
+ // Class is yang generated.
+ LOG.trace(toClass.getName() + " is a Yang-generated class");
+
+ if (toClass.getName().endsWith("Key")) {
+ if (Identifier.class.isAssignableFrom(toClass)) {
+ LOG.trace(Identifier.class.getName()
+ + " is assignable from " + toClass.getName());
+ } else {
+
+ LOG.trace(Identifier.class.getName()
+ + " is NOT assignable from " + toClass.getName());
+ }
+ }
+
+ String propNamePfx = null;
+ if (pfx.endsWith("]")) {
+ propNamePfx = pfx;
+ } else {
+
+ if ((pfx != null) && (pfx.length() > 0)) {
+ propNamePfx = pfx + "."
+ + toLowerHyphen(toClass.getSimpleName());
+ } else {
+ propNamePfx = toLowerHyphen(toClass.getSimpleName());
+ }
+
+ if (propNamePfx.endsWith("-builder")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length()
+ - "-builder".length());
+ }
+
+ if (propNamePfx.endsWith("-impl")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length()
+ - "-impl".length());
+ }
+ }
+
+ // Iterate through getter methods to figure out values we need to
+ // set
+
+ for (Method m : toClass.getMethods()) {
+ LOG.trace("Is " + m.getName() + " method a getter?");
+ if (isGetter(m)) {
+ LOG.trace(m.getName() + " is a getter");
+ Class returnClass = m.getReturnType();
+
+ String fieldName = toLowerHyphen(m.getName().substring(3));
+ fieldName = fieldName.substring(0, 1).toLowerCase()
+ + fieldName.substring(1);
+
+ String propName = propNamePfx + "." + fieldName;
+
+ // Is the return type a yang generated class?
+ if (isYangGenerated(returnClass)) {
+ // Is it an enum?
+ if (returnClass.isEnum()) {
+
+ LOG.trace(m.getName() + " is an Enum");
+ pstr.print("\n\n * " + propName);
+
+ } else {
+
+ String simpleName = returnClass.getSimpleName();
+
+ if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress".equals(simpleName) || "IpPrefix".equals(simpleName)) {
+ LOG.trace(m.getName()+" is an "+simpleName);
+ pstr.print("\n\n * " + propName);
+ } else {
+ printPropertyList(pstr, propNamePfx, returnClass);
+ }
+
+ }
+ } else {
+
+ // Setter's argument is not a yang-generated class. See
+ // if it is a List.
+
+ if (List.class.isAssignableFrom(returnClass)) {
+
+ LOG.trace("Parameter class "
+ + returnClass.getName() + " is a List");
+
+ // Figure out what type of args are in List and pass
+ // that to toList().
+
+ Type returnType = m.getGenericReturnType();
+ Type elementType = ((ParameterizedType) returnType)
+ .getActualTypeArguments()[0];
+ Class elementClass = (Class) elementType;
+ LOG.trace("Calling printPropertyList on list type ("
+ + elementClass.getName()
+ + "), pfx is ("
+ + pfx
+ + "), toClass is ("
+ + toClass.getName() + ")");
+ printPropertyList(
+ pstr,
+ propNamePfx
+ + "."
+ + toLowerHyphen(elementClass
+ .getSimpleName()) + "[]",
+ elementClass);
+
+ } else if (!returnClass.equals(Class.class)) {
+
+ // Setter expects something that is not a List and
+ // not yang-generated. Just pass the parameter value
+
+ LOG.trace("Parameter class "
+ + returnClass.getName()
+ + " is not a yang-generated class or a List");
+
+ pstr.print("\n\n * " + propName);
+
+ }
+ }
+ } // End of section handling "setter" method
+ } // End of loop through Methods
+ } // End of section handling yang-generated class
+
+ }
+
+ public static boolean isYangGenerated(Class c) {
+ if (c == null) {
+ return (false);
+ } else {
+ return (c.getName().startsWith("org.opendaylight.yang.gen."));
+ }
+ }
+
+ public static boolean isIpPrefix(Class c) {
+
+ if (c == null ) {
+ return (false);
+ }
+ String simpleName = c.getSimpleName();
+ return ("IpPrefix".equals(simpleName)) ;
+ }
+
+
+
+ public static boolean isIpv4Address(Class c) {
+
+ if (c == null ) {
+ return (false);
+ }
+ String simpleName = c.getSimpleName();
+ return ("Ipv4Address".equals(simpleName)) ;
+ }
+
+ public static boolean isIpv6Address(Class c) {
+
+ if (c == null ) {
+ return (false);
+ }
+ String simpleName = c.getSimpleName();
+ return ("Ipv6Address".equals(simpleName)) ;
+ }
+
+ public static boolean isIpAddress(Class c) {
+
+ if (c == null ) {
+ return (false);
+ }
+ String simpleName = c.getSimpleName();
+ return ("IpAddress".equals(simpleName)) ;
+ }
+
+ public static String toLowerHyphen(String inStr) {
+ if (inStr == null) {
+ return (null);
+ }
+
+ String str = inStr.substring(0, 1).toLowerCase();
+ if (inStr.length() > 1) {
+ str = str + inStr.substring(1);
+ }
+
+ String regex = "(([a-z0-9])([A-Z]))";
+ String replacement = "$2-$3";
+
+ String retval = str.replaceAll(regex, replacement).toLowerCase();
+
+ LOG.trace("Converting " + inStr + " => " + str + " => " + retval);
+ return (retval);
+ }
+
+ public static String toUpperCamelCase(String inStr) {
+ if (inStr == null) {
+ return (null);
+ } else if (inStr.length() == 0) {
+ return(inStr);
+ }
+
+ String[] terms = inStr.split("-");
+ StringBuffer sbuff = new StringBuffer();
+ // Check if string begins with a digit
+ if (Character.isDigit(inStr.charAt(0))) {
+ sbuff.append('_');
+ }
+ for (String term : terms) {
+ sbuff.append(term.substring(0, 1).toUpperCase());
+ if (term.length() > 1) {
+ sbuff.append(term.substring(1));
+ }
+ }
+ return (sbuff.toString());
+
+ }
+
+ public static boolean isGetter(Method m) {
+ if (m == null) {
+ return (false);
+ }
+
+ if (Modifier.isPublic(m.getModifiers())
+ && (m.getParameterTypes().length == 0)) {
+ if (m.getName().matches("^get[A-Z].*")
+ && !m.getReturnType().equals(void.class)) {
+ if (!"getClass".equals(m.getName())) {
+ return (true);
+ }
+ }
+
+ if (m.getName().matches("^get[A-Z].*")
+ && m.getReturnType().equals(boolean.class)) {
+ return (true);
+ }
+
+ if (m.getName().matches("^is[A-Z].*")
+ && m.getReturnType().equals(Boolean.class)) {
+ return(true);
+ }
+ }
+
+ return (false);
+ }
+
+ public static boolean isSetter(Method m) {
+ if (m == null) {
+ return (false);
+ }
+
+ if (Modifier.isPublic(m.getModifiers())
+ && (m.getParameterTypes().length == 1)) {
+ if (m.getName().matches("^set[A-Z].*")) {
+ Class[] paramTypes = m.getParameterTypes();
+ if (paramTypes[0].isAssignableFrom(Identifier.class)
+ || Identifier.class.isAssignableFrom(paramTypes[0])) {
+ return (false);
+ } else {
+ return (true);
+ }
+ }
+
+ }
+
+ return (false);
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java
new file mode 100644
index 0000000..d80e0f9
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NotifyNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(NotifyNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String action = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("action"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("release node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+
+ try {
+
+ switch (resourcePlugin.notify(resourceType, action, key, ctx)) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Could not find service reference object for plugin "
+ + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java
new file mode 100644
index 0000000..06fbedf
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java
@@ -0,0 +1,129 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicRecorder;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RecordNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(RecordNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(node.getNodeType()
+ + " node encountered - looking for recorder class "
+ + plugin);
+ }
+
+ Map<String, String> parmMap = new HashMap<String, String>();
+
+ Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
+ .getParameterSet();
+ boolean hasParms = false;
+
+ for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
+ .iterator(); iter.hasNext();) {
+ hasParms = true;
+ Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
+ String curName = curEnt.getKey();
+ SvcLogicExpression curExpr = curEnt.getValue();
+ String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr,
+ node, ctx);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("executeRecordNode : parameter " + curName + " = "
+ + curExpr + " => " + curExprValue);
+ }
+ parmMap.put(curName, curExprValue);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicRecorder recorder = (SvcLogicRecorder) bctx
+ .getService(sref);
+
+ if (recorder != null) {
+
+ try {
+ recorder.record(parmMap);
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from recorder plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicRecorder object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Cound not find service reference for plugin " + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no failure or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java
new file mode 100644
index 0000000..f2f85cd
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReleaseNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ReleaseNodeExecutor.class);
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("release node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+
+ try {
+
+ switch (resourcePlugin.release(resourceType, key, ctx)) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Could not find service reference object for plugin "
+ + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java
new file mode 100644
index 0000000..a565e07
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReserveNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ReserveNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+ String pfx = SvcLogicExpressionResolver.evaluate(node.getAttribute("pfx"),node,ctx);
+
+
+ SvcLogicExpression selectExpr = node.getAttribute("select");
+ String select = null;
+
+ if (selectExpr != null)
+ {
+ select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node, ctx);
+ }
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("reserve node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+
+ try {
+ switch (resourcePlugin.reserve(resourceType, select, key, pfx, ctx)) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Could not find service reference object for plugin "
+ + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReturnNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReturnNodeExecutor.java
new file mode 100644
index 0000000..00864b6
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReturnNodeExecutor.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReturnNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ReturnNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String status = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("status"), node, ctx);
+
+ if (status != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Returning status " + status);
+ }
+ ctx.setStatus(status);
+ } else {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Return node has no status attribute set");
+ }
+ }
+
+ Set<Map.Entry<String, SvcLogicExpression>> parameterSet = node
+ .getParameterSet();
+
+ for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parameterSet
+ .iterator(); iter.hasNext();) {
+ Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
+ String curName = curEnt.getKey();
+ String curValue = SvcLogicExpressionResolver.evaluate(
+ curEnt.getValue(), node, ctx);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Setting context attribute " + curName + " to "
+ + curValue);
+ }
+ ctx.setAttribute(curName, curValue);
+ }
+ return null;
+ }
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java
new file mode 100644
index 0000000..f1c9f61
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java
@@ -0,0 +1,154 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SaveNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SaveNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+ String forceStr = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("force"), node, ctx);
+ String localOnlyStr = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("local-only"), node, ctx);
+ String pfx = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("pfx"), node, ctx);
+
+ boolean force = "true".equalsIgnoreCase(forceStr);
+ boolean localOnly = "true".equalsIgnoreCase(localOnlyStr);
+
+ Map<String, String> parmMap = new HashMap<String, String>();
+
+ Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
+ .getParameterSet();
+ boolean hasParms = false;
+
+ for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
+ .iterator(); iter.hasNext();) {
+ hasParms = true;
+ Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
+ String curName = curEnt.getKey();
+ SvcLogicExpression curExpr = curEnt.getValue();
+ if (curExpr != null) {
+ String curExprValue = SvcLogicExpressionResolver.evaluate(
+ curExpr, node, ctx);
+
+ LOG.debug("Parameter " + curName + " = "
+ + curExpr.asParsedExpr() + " resolves to "
+ + curExprValue);
+
+ parmMap.put(curName, curExprValue);
+ }
+ }
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("save node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+
+ try {
+ switch (resourcePlugin.save(resourceType, force, localOnly, key,
+ parmMap, pfx, ctx)) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Could not find service reference object for plugin "
+ + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java
new file mode 100644
index 0000000..647340a
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java
@@ -0,0 +1,190 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicExpressionFactory;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SetNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SetNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String ifunsetStr = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("only-if-unset"), node, ctx);
+
+ boolean ifunset = "true".equalsIgnoreCase(ifunsetStr);
+
+ Set<Map.Entry<String, SvcLogicExpression>> parameterSet = node
+ .getParameterSet();
+
+ for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parameterSet
+ .iterator(); iter.hasNext();) {
+ Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
+ String curName = curEnt.getKey();
+ String lhsVarName = curName;
+
+ // Resolve LHS of assignment (could contain index variables)
+ try {
+ SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(curName);
+ lhsVarName = SvcLogicExpressionResolver.resolveVariableName(lhsExpr, node, ctx);
+ } catch (Exception e) {
+ LOG.warn("Caught exception trying to resolve variable name ("+curName+")", e);
+ }
+
+
+ boolean setValue = true;
+
+ if (curName.endsWith(".")) {
+
+ // Copy subtree - value should be a variable name
+ SvcLogicExpression curValue = curEnt.getValue();
+
+ if (curValue != null) {
+ String rhsRoot = curValue.toString();
+
+ if ((rhsRoot != null) && (rhsRoot.length() > 0)) {
+ if (rhsRoot.endsWith(".")) {
+ rhsRoot = rhsRoot
+ .substring(0, rhsRoot.length() - 1);
+ }
+
+
+ // SDNGC-2321 : rhsRoot is variable name, possibly with subscript(s) to be resolved
+ try {
+ SvcLogicExpression rhsExpr = SvcLogicExpressionFactory.parse(rhsRoot);
+ rhsRoot = SvcLogicExpressionResolver.resolveVariableName(rhsExpr, node, ctx);
+ } catch (Exception e) {
+ LOG.warn("Caught exception trying to resolve variable name ("+rhsRoot+")", e);
+ }
+
+ // See if the parameters are reversed (copying service-data to input) .. this
+ // was done as a workaround to earlier issue
+ if (curName.endsWith("-input.") && rhsRoot.startsWith("service-data")) {
+ LOG.warn("Arguments appear to be reversed .. will copy input to service-data instead");
+ lhsVarName = rhsRoot + ".";
+ rhsRoot = curName.substring(0, curName.length()-1);
+ }
+
+ rhsRoot = rhsRoot + ".";
+ String lhsPrefix = lhsVarName;
+
+ if (lhsPrefix.endsWith(".")) {
+ lhsPrefix = lhsPrefix.substring(0,
+ lhsPrefix.length()-1);
+ }
+ int lhsPfxLength = lhsPrefix.length();
+ HashMap<String, String> parmsToAdd = new HashMap<String,String>();
+
+ for (String sourceVarName : ctx.getAttributeKeySet()) {
+
+ if (sourceVarName.startsWith(rhsRoot)) {
+
+ String targetVar = lhsPrefix
+ + "."
+ + sourceVarName
+ .substring(rhsRoot.length());
+
+ LOG.debug("Copying " + sourceVarName
+ + " value to " + targetVar);
+
+ parmsToAdd.put(targetVar,
+ ctx.getAttribute(sourceVarName));
+ }
+ }
+
+ for (String newParmName : parmsToAdd.keySet()) {
+ ctx.setAttribute(newParmName, parmsToAdd.get(newParmName));
+ }
+
+ } else {
+ // If RHS is empty, unset attributes in LHS
+ String lhsPrefix = lhsVarName.substring(0,
+ lhsVarName.length() - 1);
+ int lhsPfxLength = lhsPrefix.length();
+
+ LinkedList<String> parmsToRemove = new LinkedList<String> ();
+
+ for (String curCtxVarname : ctx.getAttributeKeySet()) {
+
+ if (curCtxVarname.startsWith(lhsPrefix)) {
+ LOG.debug("Unsetting " + curCtxVarname);
+ parmsToRemove.add(curCtxVarname);
+ }
+ }
+
+ for (String parmName : parmsToRemove) {
+ ctx.setAttribute(parmName, null);
+ }
+
+ }
+ }
+
+ } else {
+
+ if (ifunset) {
+ String ctxValue = ctx.getAttribute(lhsVarName);
+
+ if ((ctxValue != null) && (ctxValue.length() > 0)) {
+ setValue = false;
+ LOG.debug("Attribute "
+ + lhsVarName
+ + " already set and only-if-unset is true, so not overriding");
+ }
+ }
+
+ if (setValue) {
+ String curValue = SvcLogicExpressionResolver.evaluate(
+ curEnt.getValue(), node, ctx);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameter value "
+ + curEnt.getValue().asParsedExpr()
+ + " resolves to " + curValue);
+ LOG.debug("Setting context attribute " + lhsVarName
+ + " to " + curValue);
+ }
+ ctx.setAttribute(lhsVarName, curValue);
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java
new file mode 100644
index 0000000..62c6fde
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java
@@ -0,0 +1,225 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+
+import org.openecomp.sdnc.sli.ConfigurationException;
+import org.openecomp.sdnc.sli.SvcLogicAdaptor;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicStore;
+import org.openecomp.sdnc.sli.SvcLogicStoreFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.mysql.jdbc.Driver;
+
+public class SvcLogicActivator implements BundleActivator {
+
+ private static final String SVCLOGIC_PROP_VAR = "SDNC_SLI_PROPERTIES";
+ private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
+
+ private static final Map<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());
+
+ }
+ };
+
+ private static LinkedList<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
+
+ private static HashMap<String, SvcLogicAdaptor> adaptorMap = null;
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SvcLogicActivator.class);
+
+ private static Properties props = null;
+
+ private static BundleContext bundleCtx = null;
+
+ private static SvcLogicService svcLogicServiceImpl = null;
+
+ @Override
+ public void start(BundleContext ctx) throws Exception {
+
+ LOG.info("Activating SLI");
+
+ bundleCtx = ctx;
+
+ // Read properties
+ props = new Properties();
+ String propPath = System.getenv(SVCLOGIC_PROP_VAR);
+
+ if (propPath == null) {
+ String propDir = System.getenv(SDNC_CONFIG_DIR);
+ if (propDir == null) {
+
+ propDir = "/opt/sdnc/data/properties";
+ }
+ propPath = propDir + "/svclogic.properties";
+ LOG.warn("Environment variable "+SVCLOGIC_PROP_VAR+" unset - defaulting to "+propPath);
+ }
+
+ File propFile = new File(propPath);
+
+ if (!propFile.exists()) {
+
+ throw new ConfigurationException(
+ "Missing configuration properties file : "
+ + propFile);
+ }
+ try {
+
+ props.load(new FileInputStream(propFile));
+ } catch (Exception e) {
+ throw new ConfigurationException(
+ "Could not load properties file " + propPath, e);
+
+ }
+
+
+ if (registrations == null) {
+
+ registrations = new LinkedList<ServiceRegistration>();
+ }
+
+ // Advertise SvcLogicService
+ svcLogicServiceImpl = new SvcLogicServiceImpl();
+
+ LOG.info("SLI: Registering service " + SvcLogicService.NAME
+ + " in bundle " + ctx.getBundle().getSymbolicName());
+ ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME,
+ svcLogicServiceImpl, null);
+ registrations.add(reg);
+
+ // Initialize SvcLogicStore
+ try {
+ SvcLogicStore store = getStore();
+ registerNodeTypes(store);
+ } catch (ConfigurationException e) {
+ LOG.warn("Could not initialize SvcLogicScore", e);
+ }
+
+ LOG.info("SLI - done registering services");
+ }
+
+ @Override
+ public void stop(BundleContext ctx) throws Exception {
+
+ if (registrations != null) {
+ for (ServiceRegistration reg : registrations) {
+ ServiceReference regRef = reg.getReference();
+ /* Don't bother to remove node types from table
+ String nodeType = (String) regRef.getProperty("nodeType");
+ if (nodeType != null) {
+ LOG.info("SLI - unregistering node type " + nodeType);
+ store.unregisterNodeType(nodeType);
+ }
+ */
+ reg.unregister();
+ }
+ registrations = null;
+ }
+ }
+
+ public static SvcLogicStore getStore() throws SvcLogicException {
+ // Create and initialize SvcLogicStore object - used to access
+ // saved service logic.
+
+ SvcLogicStore store = null;
+
+ try {
+ Driver dvr = new Driver();
+ store = SvcLogicStoreFactory.getSvcLogicStore(props);
+ } catch (Exception e) {
+ throw new ConfigurationException(
+ "Could not get service logic store", e);
+
+ }
+
+ try {
+ store.init(props);
+ } catch (Exception e) {
+ throw new ConfigurationException(
+ "Could not get service logic store", e);
+ }
+
+ return(store);
+ }
+
+ private static void registerNodeTypes(SvcLogicStore store) throws SvcLogicException {
+
+ if (store == null) {
+ return;
+ }
+ // Advertise built-in node executors
+ LOG.info("SLI : Registering built-in node executors");
+ Hashtable propTable = new Hashtable();
+
+ for (String nodeType : BUILTIN_NODES.keySet()) {
+ LOG.info("SLI - registering node type " + nodeType);
+ propTable.clear();
+ propTable.put("nodeType", nodeType);
+
+ ServiceRegistration reg = bundleCtx.registerService(SvcLogicNodeExecutor.class.getName(),
+ BUILTIN_NODES.get(nodeType), propTable);
+ registrations.add(reg);
+
+ store.registerNodeType(nodeType);
+
+ LOG.info("SLI - registering node executor");
+
+ ((SvcLogicServiceImpl)svcLogicServiceImpl).registerExecutor(nodeType, BUILTIN_NODES.get(nodeType));
+
+ }
+
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicAdaptorFactory.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicAdaptorFactory.java
new file mode 100644
index 0000000..7589f71
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicAdaptorFactory.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.HashMap;
+
+import org.openecomp.sdnc.sli.SvcLogicAdaptor;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SvcLogicAdaptorFactory {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SvcLogicAdaptorFactory.class);
+
+ private static HashMap<String, SvcLogicAdaptor> adaptorMap = new HashMap<String, SvcLogicAdaptor>();
+
+ public static void registerAdaptor(SvcLogicAdaptor adaptor) {
+ String name = adaptor.getClass().getName();
+ LOG.info("Registering adaptor " + name);
+ adaptorMap.put(name, adaptor);
+
+ }
+
+ public static void unregisterAdaptor(String name) {
+ if (adaptorMap.containsKey(name)) {
+ LOG.info("Unregistering " + name);
+ adaptorMap.remove(name);
+ }
+ }
+
+ public static SvcLogicAdaptor getInstance(String name) {
+ if (adaptorMap.containsKey(name)) {
+ return (adaptorMap.get(name));
+ } else {
+ BundleContext bctx = null;
+ try
+ {
+ bctx = FrameworkUtil.getBundle(SvcLogicAdaptorFactory.class)
+ .getBundleContext();
+ }
+ catch (Exception e)
+ {
+ LOG.debug("Caught exception trying to locate device adaptor "+name, e);
+ return(null);
+ }
+
+ ServiceReference sref = bctx.getServiceReference(name);
+
+ if (sref != null) {
+ SvcLogicAdaptor adaptor = (SvcLogicAdaptor) bctx
+ .getService(sref);
+
+ if (adaptor != null) {
+ registerAdaptor(adaptor);
+
+ return (adaptor);
+ }
+ return (null);
+ }
+ }
+ return(null);
+ }
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java
new file mode 100644
index 0000000..1af215f
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java
@@ -0,0 +1,605 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdnc.sli.SvcLogicAtom;
+import org.openecomp.sdnc.sli.SvcLogicBinaryExpression;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicFunctionCall;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicVariableTerm;
+import org.openecomp.sdnc.sli.SvcLogicAtom.AtomType;
+import org.openecomp.sdnc.sli.SvcLogicBinaryExpression.OperatorType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SvcLogicExpressionResolver {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SvcLogicExpressionResolver.class);
+
+ public static String evaluate(SvcLogicExpression expr, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+ if (expr == null) {
+ return (null);
+ }
+
+
+
+ if (expr instanceof SvcLogicAtom) {
+ SvcLogicAtom atom = (SvcLogicAtom) expr;
+
+ AtomType atomType = atom.getAtomType();
+ switch (atomType) {
+ case NUMBER:
+ case STRING:
+ return (atom.toString());
+ case CONTEXT_VAR:
+ case IDENTIFIER:
+
+ String varName = resolveVariableName(atom, node, ctx);
+
+ if (atomType == AtomType.CONTEXT_VAR)
+ {
+ LOG.debug("Evaluating context variable $"+varName);
+
+ String varValue = ctx.getAttribute(varName);
+
+ if (varValue == null) {
+ LOG.debug("Context variable $"+varName+" unset - treating as empty string");
+ varValue = "";
+ }
+
+ return (varValue);
+ }
+ SvcLogicExpression parm = node.getParameter(varName);
+ if (parm != null) {
+ LOG.debug("Evaluating value of parameter "+varName+": "+parm.asParsedExpr());
+
+ return (evaluate(parm, node, ctx));
+ }
+ else
+ {
+ return(varName);
+ }
+ default:
+ return(null);
+ }
+
+ } else if (expr instanceof SvcLogicBinaryExpression) {
+ SvcLogicBinaryExpression binExpr = (SvcLogicBinaryExpression) expr;
+ List<OperatorType> operators = binExpr.getOperators();
+ if (operators.isEmpty())
+ {
+ List<SvcLogicExpression> operands = binExpr.getOperands();
+ if (operands.size() == 1)
+ {
+ LOG.debug("SvcLogicBinaryExpression as no operator and one operand - evaluating its operand");
+ return(evaluate(operands.get(0), node, ctx));
+ }
+ else
+ {
+ if (operands.isEmpty())
+ {
+ LOG.error("SvcLogicBinaryExpression has no operators and no operands - evaluating value as null");
+ }
+ else
+ {
+ LOG.error("SvcLogicBinaryExpression has no operators and "+operands.size()+" operands - evaluating value as null");
+ }
+ return(null);
+ }
+ }
+ switch (operators.get(0)) {
+ case addOp:
+ case subOp:
+ case multOp:
+ case divOp:
+ return(evalArithExpression(binExpr, node, ctx));
+ case equalOp:
+ case neOp:
+ case ltOp:
+ case leOp:
+ case gtOp:
+ case geOp:
+ return (evalCompareExpression(binExpr, node, ctx));
+ case andOp:
+ case orOp:
+ return(evalLogicExpression(binExpr, node, ctx));
+
+ default:
+ return(null);
+ }
+ }
+ else if (expr instanceof SvcLogicFunctionCall)
+ {
+ return(evalFunctionCall((SvcLogicFunctionCall)expr, node, ctx));
+ }
+ else
+ {
+ throw new SvcLogicException("Unrecognized expression type ["+expr+"]");
+ }
+ }
+
+ private static String evalArithExpression(SvcLogicBinaryExpression binExpr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException {
+ List<SvcLogicExpression> operands = binExpr.getOperands();
+ List<OperatorType> operators = binExpr.getOperators();
+ if (operands.size() != (operators.size()+1))
+ {
+ throw new SvcLogicException("Invalid expression ("+binExpr+")");
+ }
+ String retval = evaluate(operands.get(0), node, ctx);
+ String retsval = retval;
+ long retlval = 0;
+ boolean valueIsLong = false;
+
+ int i = 1;
+ try
+ {
+
+ if ((retval.length() > 0) && StringUtils.isNumeric(retval))
+ {
+ retlval = Long.parseLong(retval);
+ valueIsLong = true;
+ }
+ for (OperatorType operator: operators)
+ {
+ String curOperandValue = evaluate(operands.get(i++), node, ctx);
+ switch(operator) {
+ case addOp:
+ retsval = retsval + curOperandValue;
+ if (valueIsLong)
+ {
+ if ((curOperandValue.length() > 0) && StringUtils.isNumeric(curOperandValue) )
+ {
+ retlval = retlval + Long.parseLong(curOperandValue);
+ }
+ else
+ {
+ valueIsLong = false;
+ }
+ }
+ break;
+ case subOp:
+ retlval = retlval - Long.parseLong(curOperandValue);
+ break;
+ case multOp:
+ retlval = retlval * Long.parseLong(curOperandValue);
+ break;
+ case divOp:
+ retlval = retlval / Long.parseLong(curOperandValue);
+ break;
+ }
+
+ }
+ }
+ catch (NumberFormatException e1)
+ {
+ throw new SvcLogicException("Illegal value in arithmetic expression", e1);
+ }
+
+ if (valueIsLong)
+ {
+ return("" + retlval);
+ }
+ else
+ {
+ return(retsval);
+ }
+
+ }
+
+
+
+ private static String evalCompareExpression(SvcLogicBinaryExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException
+ {
+
+ List<OperatorType> operators = expr.getOperators();
+ List<SvcLogicExpression> operands = expr.getOperands();
+
+ if ((operators.size() != 1) || (operands.size() != 2))
+ {
+ throw new SvcLogicException ("Invalid comparison expression : "+expr);
+ }
+
+ OperatorType operator = operators.get(0);
+ String op1Value = evaluate(operands.get(0), node, ctx);
+ String op2Value = evaluate(operands.get(1), node, ctx);
+
+ if ((StringUtils.isNotEmpty(op1Value) && StringUtils.isNumeric(op1Value) && StringUtils.isNotEmpty(op2Value) && StringUtils.isNumeric(op2Value)))
+ {
+ try
+ {
+ double op1dbl = Double.parseDouble(op1Value);
+ double op2dbl = Double.parseDouble(op2Value);
+
+ switch(operator)
+ {
+ case equalOp:
+ return(Boolean.toString(op1dbl == op2dbl));
+ case neOp:
+ return(Boolean.toString(op1dbl != op2dbl));
+ case ltOp:
+ return(Boolean.toString(op1dbl < op2dbl));
+ case leOp:
+ return(Boolean.toString(op1dbl <= op2dbl));
+ case gtOp:
+ return(Boolean.toString(op1dbl > op2dbl));
+ case geOp:
+ return(Boolean.toString(op1dbl >= op2dbl));
+ default:
+ return(null);
+ }
+ }
+ catch (NumberFormatException e)
+ {
+ throw new SvcLogicException("Caught exception trying to compare numeric values", e);
+ }
+ }
+ else
+ {
+
+ int compResult = 0;
+
+ if (op1Value == null) {
+ compResult = -1;
+ } else if (op2Value == null ) {
+ compResult = 1;
+ } else {
+ compResult = op1Value.compareToIgnoreCase(op2Value);
+ }
+
+ switch(operator)
+ {
+ case equalOp:
+ return(Boolean.toString(compResult == 0));
+ case neOp:
+ return(Boolean.toString(compResult != 0));
+ case ltOp:
+ return(Boolean.toString(compResult < 0));
+ case leOp:
+ return(Boolean.toString(compResult <= 0));
+ case gtOp:
+ return(Boolean.toString(compResult > 0));
+ case geOp:
+ return(Boolean.toString(compResult >= 0));
+ default:
+ return(null);
+ }
+ }
+
+ }
+
+ private static String evalLogicExpression(SvcLogicBinaryExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException
+ {
+ boolean retval;
+
+ List<SvcLogicExpression> operands = expr.getOperands();
+ List<OperatorType> operators = expr.getOperators();
+
+ if (operands.size() != (operators.size()+1))
+ {
+ throw new SvcLogicException("Invalid expression ("+expr+")");
+ }
+
+ try
+ {
+ retval = Boolean.parseBoolean(evaluate(operands.get(0), node, ctx));
+ int i = 1;
+ for (OperatorType operator : operators)
+ {
+ if (operator == OperatorType.andOp)
+ {
+ retval = retval && Boolean.parseBoolean(evaluate(operands.get(i++), node, ctx));
+ }
+ else
+ {
+
+ retval = retval || Boolean.parseBoolean(evaluate(operands.get(i++), node, ctx));
+ }
+
+ }
+ }
+ catch (Exception e)
+ {
+ throw new SvcLogicException("Invalid expression ("+expr+")");
+ }
+
+
+ return(Boolean.toString(retval));
+ }
+
+ private static String evalFunctionCall(SvcLogicFunctionCall func, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException
+ {
+ String funcName = func.getFunctionName();
+ List<SvcLogicExpression> operands = func.getOperands();
+
+ if ("length".equalsIgnoreCase(funcName))
+ {
+
+ if (operands.size() == 1)
+ {
+ String opValue = evaluate(operands.get(0), node, ctx);
+ return(""+opValue.length());
+ }
+ else
+ {
+ throw new SvcLogicException("Invalid call to length() function");
+ }
+ }
+ else if ("substr".equalsIgnoreCase(funcName))
+ {
+ if (operands.size() == 3)
+ {
+ String op1Value = evaluate(operands.get(0), node, ctx);
+ String op2Value = evaluate(operands.get(1), node, ctx);
+ String op3Value = evaluate(operands.get(2), node, ctx);
+
+ if (!StringUtils.isNumeric(op2Value) || !StringUtils.isNumeric(op3Value))
+ {
+ throw new SvcLogicException("Invalid arguments to substr() function");
+ }
+
+ try
+ {
+ return(op1Value.substring(Integer.parseInt(op2Value), Integer.parseInt(op3Value)));
+ }
+ catch (Exception e)
+ {
+ throw new SvcLogicException("Caught exception trying to take substring", e);
+ }
+ }
+ else
+ {
+
+ throw new SvcLogicException("Invalid call to substr() function");
+ }
+
+ }
+ else if ("toUpperCase".equalsIgnoreCase(funcName))
+ {
+ if (operands.size() == 1)
+ {
+ String opValue = evaluate(operands.get(0), node, ctx);
+ if (opValue != null) {
+ return(opValue.toUpperCase());
+ } else {
+ return("");
+ }
+ }
+ else
+ {
+ throw new SvcLogicException("Invalid call to toUpperCase() function");
+ }
+ }
+ else if ("toLowerCase".equalsIgnoreCase(funcName))
+ {
+ if (operands.size() == 1)
+ {
+ String opValue = evaluate(operands.get(0), node, ctx);
+ if (opValue != null) {
+ return(opValue.toLowerCase());
+ } else {
+ return("");
+ }
+ }
+ else
+ {
+ throw new SvcLogicException("Invalid call to toLowerCase() function");
+ }
+ }
+ else if ("convertBase".equalsIgnoreCase(funcName)) {
+ int fromBase = 10;
+ int toBase = 10;
+ String srcString = "";
+
+ if (operands.size() == 2)
+ {
+ fromBase = 10;
+ srcString = evaluate(operands.get(0), node, ctx);
+ toBase = Integer.parseInt(evaluate(operands.get(1), node, ctx));
+ } else if (operands.size() == 3) {
+
+ srcString = evaluate(operands.get(0), node, ctx);
+ fromBase = Integer.parseInt(evaluate(operands.get(1), node, ctx));
+ toBase = Integer.parseInt(evaluate(operands.get(2), node, ctx));
+ } else {
+ throw new SvcLogicException("Invalid call to convertBase() function");
+ }
+
+ long srcValue = Long.parseLong(srcString, fromBase);
+ return(Long.toString(srcValue, toBase));
+ }
+ else
+ {
+ throw new SvcLogicException("Unrecognized function ("+funcName+")");
+ }
+
+ }
+
+ public static String evaluateAsKey(SvcLogicExpression expr, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+ if (expr == null) {
+ return (null);
+ }
+
+
+
+ if (expr instanceof SvcLogicAtom) {
+ SvcLogicAtom atom = (SvcLogicAtom) expr;
+
+ AtomType atomType = atom.getAtomType();
+ StringBuffer varNameBuff = new StringBuffer();
+ switch (atomType) {
+ case NUMBER:
+ return (atom.toString());
+ case STRING:
+ return("'"+atom.toString()+"'");
+ case CONTEXT_VAR:
+ case IDENTIFIER:
+ boolean needDot = false;
+ for (SvcLogicExpression term : atom.getOperands())
+ {
+ if (needDot)
+ {
+ varNameBuff.append(".");
+ }
+ if (term instanceof SvcLogicVariableTerm)
+ {
+ SvcLogicVariableTerm vterm = (SvcLogicVariableTerm) term;
+ varNameBuff.append(vterm.getName());
+ if (vterm.numOperands() > 0)
+ {
+ varNameBuff.append("[");
+ varNameBuff.append(evaluate(vterm.getSubscript(), node, ctx));
+ varNameBuff.append("]");
+
+ }
+ }
+ else
+ {
+ varNameBuff.append(term.toString());
+ }
+ needDot = true;
+ }
+
+ String varName = varNameBuff.toString();
+ LOG.debug("Evaluating context variable $"+varName);
+ String ctxValue = ctx.getAttribute(varName);
+ if (ctxValue == null)
+ {
+ return(null);
+ }
+ if (StringUtils.isNumeric(ctxValue))
+ {
+ return(ctxValue);
+ }
+ else
+ {
+ return("'"+ctxValue+"'");
+ }
+
+ default:
+ return(null);
+ }
+
+ } else if (expr instanceof SvcLogicBinaryExpression) {
+ SvcLogicBinaryExpression binExpr = (SvcLogicBinaryExpression) expr;
+ List<OperatorType> operators = binExpr.getOperators();
+ List<SvcLogicExpression> operands = binExpr.getOperands();
+ if (operators.isEmpty())
+ {
+ if (operands.size() == 1)
+ {
+ LOG.debug("SvcLogicBinaryExpression as no operator and one operand - evaluating its operand");
+ return(evaluateAsKey(operands.get(0), node, ctx));
+ }
+ else
+ {
+ if (operands.isEmpty())
+ {
+ LOG.error("SvcLogicBinaryExpression has no operators and no operands - evaluating value as null");
+ }
+ else
+ {
+ LOG.error("SvcLogicBinaryExpression has no operators and "+operands.size()+" operands - evaluating value as null");
+ }
+ return(null);
+ }
+ }
+ StringBuffer sbuff = new StringBuffer();
+ sbuff.append(evaluateAsKey(operands.get(0), node, ctx));
+ int i = 1;
+ for (OperatorType operator : operators)
+ {
+ sbuff.append(" ");
+ sbuff.append(operator.toString());
+ sbuff.append(" ");
+ sbuff.append(evaluateAsKey(operands.get(i++), node,ctx));
+ }
+ return(sbuff.toString());
+ }
+ else if (expr instanceof SvcLogicFunctionCall)
+ {
+ StringBuffer sbuff = new StringBuffer();
+ SvcLogicFunctionCall funcCall = (SvcLogicFunctionCall) expr;
+ sbuff.append(funcCall.getFunctionName());
+ sbuff.append("(");
+ boolean needComma = false;
+ for (SvcLogicExpression operand : funcCall.getOperands())
+ {
+ if (needComma)
+ {
+ sbuff.append(",");
+ }
+ else
+ {
+ needComma = true;
+ }
+ sbuff.append(evaluateAsKey(operand, node, ctx));
+ }
+ sbuff.append(")");
+ return(sbuff.toString());
+ }
+ else
+ {
+ throw new SvcLogicException("Unrecognized expression type ["+expr+"]");
+ }
+ }
+
+ public static String resolveVariableName(SvcLogicExpression atom, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException
+ {
+ StringBuffer varNameBuff = new StringBuffer();
+
+ boolean needDot = false;
+ for (SvcLogicExpression term : atom.getOperands())
+ {
+ if (needDot)
+ {
+ varNameBuff.append(".");
+ }
+ if (term instanceof SvcLogicVariableTerm)
+ {
+ SvcLogicVariableTerm vterm = (SvcLogicVariableTerm) term;
+ varNameBuff.append(vterm.getName());
+ if (vterm.numOperands() > 0)
+ {
+ varNameBuff.append("[");
+ varNameBuff.append(evaluate(vterm.getSubscript(), node, ctx));
+ varNameBuff.append("]");
+ }
+ }
+ else
+ {
+ varNameBuff.append(term.toString());
+ }
+ needDot = true;
+ }
+ return(varNameBuff.toString());
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicNodeExecutor.java
new file mode 100644
index 0000000..931b358
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicNodeExecutor.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+
+public abstract class SvcLogicNodeExecutor {
+
+ public abstract SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException;
+
+
+ protected String evaluateNodeTest(SvcLogicNode node, SvcLogicContext ctx)
+ throws SvcLogicException {
+ if (node == null) {
+ return null;
+ }
+
+ return (SvcLogicExpressionResolver.evaluate(node.getAttribute("test"),
+ node, ctx));
+
+ }
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicService.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicService.java
new file mode 100644
index 0000000..6351a2f
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicService.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.HashMap;
+import java.util.Properties;
+
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicGraph;
+
+
+
+
+public interface SvcLogicService {
+
+ public static final String NAME = "org.openecomp.sdnc.sli.provider.SvcLogicService";
+
+ // public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException;
+ /**
+ * Check for existence of a directed graph
+ * @param module - module name
+ * @param rpc - rpc name
+ * @param version - version. If null, looks for active version
+ * @param mode - mode (sync/async)
+ * @return true if directed graph found, false otherwise
+ * @throws SvcLogicException
+ */
+ public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException;
+
+ /**
+ * Execute a directed graph
+ *
+ * @param module - module name
+ * @param rpc - rpc name
+ * @param version - version. If null, use active version
+ * @param mode - mode (sync/async)
+ * @param parms - parameters, used to set SvcLogicContext attributes
+ * @return final values of attributes from SvcLogicContext, as Properties
+ * @throws SvcLogicException
+ *
+ *
+ * @deprecated use execute(String module, String rpc, String version, String mode, DOMDataBroker dataBroker) instead
+ */
+ @Deprecated
+ public Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException;
+
+ /**
+ * Execute a directed graph
+ *
+ * @param module - module name
+ * @param rpc - rpc name
+ * @param version - version. If null, use active version
+ * @param mode - mode (sync/async)
+ * @param parms - parameters, used to set SvcLogicContext attributes
+ * @param domDataBroker - DOMDataBroker object
+ * @return final values of attributes from SvcLogicContext, as Properties
+ * @throws SvcLogicException
+ */
+ public Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException;
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java
new file mode 100644
index 0000000..bd97224
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java
@@ -0,0 +1,287 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.HashMap;
+import java.util.Properties;
+
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.openecomp.sdnc.sli.MetricLogger;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicGraph;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicStore;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+public class SvcLogicServiceImpl implements SvcLogicService {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SvcLogicServiceImpl.class);
+
+ private HashMap<String, SvcLogicNodeExecutor> nodeExecutors = null;
+
+ private BundleContext bctx = null;
+
+ private void registerExecutors() {
+
+ LOG.info("Entered register executors");
+ if (bctx == null) {
+ bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+ }
+
+ if (nodeExecutors == null) {
+ nodeExecutors = new HashMap<String, SvcLogicNodeExecutor>();
+ }
+
+ LOG.info("Opening service tracker");
+ ServiceTracker tracker = new ServiceTracker(bctx,
+ SvcLogicNodeExecutor.class.getName(), null);
+
+ tracker.open();
+
+ ServiceListener listener = new ServiceListener() {
+
+ public void serviceChanged(ServiceEvent ev) {
+ ServiceReference sr = ev.getServiceReference();
+ switch (ev.getType()) {
+ case ServiceEvent.REGISTERED: {
+ registerExecutor(sr);
+ }
+ break;
+ case ServiceEvent.UNREGISTERING: {
+ unregisterExecutor(sr);
+ }
+ break;
+ }
+ }
+ };
+
+ LOG.info("Adding service listener");
+ String filter = "(objectclass=" + SvcLogicNodeExecutor.class.getName()
+ + ")";
+ try {
+ bctx.addServiceListener(listener, filter);
+ ServiceReference[] srl = bctx.getServiceReferences(
+ SvcLogicNodeExecutor.class.getName(), null);
+ for (int i = 0; srl != null && i < srl.length; i++) {
+ listener.serviceChanged(new ServiceEvent(
+ ServiceEvent.REGISTERED, srl[i]));
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ LOG.info("Done registerExecutors");
+ }
+
+ public void registerExecutor(ServiceReference sr) {
+
+ String nodeName = (String) sr.getProperty("nodeType");
+ if (nodeName != null) {
+
+ SvcLogicNodeExecutor executor = null;
+
+ try {
+ executor = (SvcLogicNodeExecutor) bctx.getService(sr);
+ } catch (Exception e) {
+ LOG.error("Cannot get service executor for " + nodeName);
+ return;
+ }
+
+ registerExecutor(nodeName, executor);
+
+ }
+ }
+
+ public void registerExecutor(String nodeName, SvcLogicNodeExecutor executor)
+ {
+ if (nodeExecutors == null) {
+ nodeExecutors = new HashMap<String, SvcLogicNodeExecutor>();
+ }
+ LOG.info("SLI - registering executor for node type "+nodeName);
+ nodeExecutors.put(nodeName, executor);
+ }
+
+ public void unregisterExecutor(ServiceReference sr) {
+ String nodeName = (String) sr.getProperty("nodeType");
+
+ if (nodeName != null) {
+
+ unregisterExecutor(nodeName);
+
+ }
+
+ }
+
+ public void unregisterExecutor(String nodeName)
+ {
+
+ LOG.info("SLI - unregistering executor for node type "+nodeName);
+ nodeExecutors.remove(nodeName);
+ }
+
+
+
+
+ public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx)
+ throws SvcLogicException {
+
+ if (nodeExecutors == null) {
+ registerExecutors();
+ }
+
+ // Set service name in MDC to reference current working directed graph
+ MDC.put(MetricLogger.SERVICE_NAME, graph.getModule()+":"+graph.getRpc()+"/v"+graph.getVersion());
+
+ SvcLogicNode curNode = graph.getRootNode();
+ LOG.info("About to execute graph " + graph.toString());
+
+
+
+ while (curNode != null) {
+ LOG.info("About to execute node # "+curNode.getNodeId()+" ("+curNode.getNodeType()+")");
+
+ SvcLogicNode nextNode = executeNode(curNode, ctx);
+ curNode = nextNode;
+ }
+
+ return (ctx);
+ }
+
+
+ public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx)
+ throws SvcLogicException {
+ if (node == null) {
+ return (null);
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Executing node " + node.getNodeId());
+ }
+
+ SvcLogicNodeExecutor executor = nodeExecutors.get(node.getNodeType());
+
+ if (executor != null) {
+ LOG.debug("Executing node executor for node type "+node.getNodeType()+" - "+executor.getClass().getName());
+ return (executor.execute(this, node, ctx));
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(node.getNodeType() + " node not implemented");
+ }
+ SvcLogicNode nextNode = node.getOutcomeValue("failure");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute failure branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no failure or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+ }
+
+ @Override
+ public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException
+ {
+ SvcLogicStore store = SvcLogicActivator.getStore();
+
+ return (store.hasGraph(module, rpc, version, mode));
+ }
+
+ @Override
+ public Properties execute(String module, String rpc, String version, String mode, Properties props)
+ throws SvcLogicException {
+ return(execute(module, rpc, version, mode, props, null));
+ }
+
+
+ @Override
+ public Properties execute(String module, String rpc, String version, String mode,
+ Properties props, DOMDataBroker domDataBroker) throws SvcLogicException {
+
+
+ // See if there is a service logic defined
+ //
+ SvcLogicStore store = SvcLogicActivator.getStore();
+
+ LOG.info("Fetching service logic from data store");
+ SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
+
+
+
+ if (graph == null)
+ {
+ Properties retProps = new Properties();
+ retProps.setProperty("error-code", "401");
+ retProps.setProperty("error-message", "No service logic found for ["+module+","+rpc+","+version+","+mode+"]");
+ return(retProps);
+
+ }
+
+ if (nodeExecutors == null) {
+ LOG.info("Start: registering node executors");
+ registerExecutors();
+
+ LOG.info("Done: registering node executors");
+ }
+
+ LOG.info("About to execute graph " + graph.toString());
+
+ LOG.info("Executing root node");
+ SvcLogicContext ctx = new SvcLogicContext(props);
+ ctx.setDomDataBroker(domDataBroker);
+ SvcLogicNode curNode = graph.getRootNode();
+
+ while (curNode != null) {
+ LOG.info("About to execute node # "+curNode.getNodeId()+" ("+curNode.getNodeType()+")");
+ SvcLogicNode nextNode = executeNode(curNode, ctx);
+ curNode = nextNode;
+ }
+
+
+ return(ctx.toProperties());
+ }
+
+
+
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java
new file mode 100644
index 0000000..39eda47
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SwitchNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SwitchNodeExecutor.class);
+
+ @Override
+
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+
+ String testResult = evaluateNodeTest(node, ctx);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Executing switch node");
+
+
+ LOG.debug("test expression (" + node.getAttribute("test")
+ + ") evaluates to " + testResult);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(testResult);
+
+ if (LOG.isDebugEnabled()) {
+ if (nextNode != null) {
+ LOG.debug("Next node to execute is node "
+ + nextNode.getNodeId());
+ } else {
+ LOG.debug("No next node found");
+ }
+ }
+ return (nextNode);
+
+ }
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java
new file mode 100644
index 0000000..073bb3f
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java
@@ -0,0 +1,148 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UpdateNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(UpdateNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ String plugin = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("plugin"), node, ctx);
+ String resourceType = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("resource"), node, ctx);
+ String key = SvcLogicExpressionResolver.evaluateAsKey(
+ node.getAttribute("key"), node, ctx);
+ String pfx = SvcLogicExpressionResolver.evaluate(
+ node.getAttribute("pfx"), node, ctx);
+
+
+ Map<String, String> parmMap = new HashMap<String, String>();
+
+ Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
+ .getParameterSet();
+ boolean hasParms = false;
+
+ for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
+ .iterator(); iter.hasNext();) {
+ hasParms = true;
+ Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
+ String curName = curEnt.getKey();
+ SvcLogicExpression curExpr = curEnt.getValue();
+ if (curExpr != null) {
+ String curExprValue = SvcLogicExpressionResolver.evaluate(
+ curExpr, node, ctx);
+
+ LOG.debug("Parameter " + curName + " = "
+ + curExpr.asParsedExpr() + " resolves to "
+ + curExprValue);
+
+ parmMap.put(curName, curExprValue);
+ }
+ }
+
+ String outValue = "failure";
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("save node encountered - looking for resource class "
+ + plugin);
+ }
+
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+
+ if (resourcePlugin != null) {
+
+ try {
+ switch (resourcePlugin.update(resourceType, key,
+ parmMap, pfx, ctx)) {
+ case SUCCESS:
+ outValue = "success";
+ break;
+ case NOT_FOUND:
+ outValue = "not-found";
+ break;
+ case FAILURE:
+ default:
+ outValue = "failure";
+ }
+ } catch (SvcLogicException e) {
+ LOG.error("Caught exception from resource plugin", e);
+ outValue = "failure";
+ }
+ } else {
+ LOG.warn("Could not find SvcLogicResource object for plugin "
+ + plugin);
+ }
+ } else {
+ LOG.warn("Could not find service reference object for plugin "
+ + plugin);
+ }
+
+ SvcLogicNode nextNode = node.getOutcomeValue(outValue);
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute " + outValue + " branch");
+ }
+ return (nextNode);
+ }
+
+ nextNode = node.getOutcomeValue("Other");
+ if (nextNode != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("about to execute Other branch");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("no "+outValue+" or Other branch found");
+ }
+ }
+ return (nextNode);
+ }
+
+}