aboutsummaryrefslogtreecommitdiffstats
path: root/sli
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-03-31 15:03:13 -0400
committerDan Timoney <dtimoney@att.com>2017-03-31 15:11:48 -0400
commit974b67dd4021e6e839eaad25366bffe6d7a414c8 (patch)
treec16b969e86323ed8b0914253b1c74d42d31a7ed1 /sli
parente0451f75b26082418757f279351c2d3e29c0a5c8 (diff)
[SDNC-5] Rebase sdnc-core
Upgrade to OpenDaylight Boron release, and sync changes made since 16.10 release to ONAP SDN-C distribution Change-Id: I20bef9e6d0008c4436b5624ce839bbb70ecc20a5 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'sli')
-rwxr-xr-xsli/common/pom.xml2
-rw-r--r--sli/common/src/main/java/org/openecomp/sdnc/sli/BreakNodeException.java46
-rw-r--r--sli/common/src/main/java/org/openecomp/sdnc/sli/MessageWriter.java302
-rw-r--r--sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExprListener.java60
-rw-r--r--sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExpressionFactory.java2
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BreakNodeExecutor.java42
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java23
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java30
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java93
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java27
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ForNodeExecutor.java24
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java28
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/IsAvailableNodeExecutor.java27
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/MdsalHelper.java2193
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java30
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/RecordNodeExecutor.java38
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReleaseNodeExecutor.java30
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ReserveNodeExecutor.java27
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SaveNodeExecutor.java27
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SetNodeExecutor.java2
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java1
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolver.java8
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicServiceImpl.java2
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SwitchNodeExecutor.java3
-rw-r--r--sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/UpdateNodeExecutor.java26
-rw-r--r--sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/BadPlugin.java56
-rw-r--r--sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutorTest.java57
-rw-r--r--sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/LunchSelectorPlugin.java78
-rw-r--r--sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTest.java43
-rw-r--r--sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTesterUtil.java37
-rw-r--r--sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/PluginTest.java106
-rw-r--r--sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/VoidDummyPlugin.java38
32 files changed, 2106 insertions, 1402 deletions
diff --git a/sli/common/pom.xml b/sli/common/pom.xml
index 7a08c34..eb06e6b 100755
--- a/sli/common/pom.xml
+++ b/sli/common/pom.xml
@@ -44,7 +44,7 @@
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
- <version>${odl.yangtools.version}</version>
+ <version>${odl.mdsal.yang.binding.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
diff --git a/sli/common/src/main/java/org/openecomp/sdnc/sli/BreakNodeException.java b/sli/common/src/main/java/org/openecomp/sdnc/sli/BreakNodeException.java
new file mode 100644
index 0000000..3e355ba
--- /dev/null
+++ b/sli/common/src/main/java/org/openecomp/sdnc/sli/BreakNodeException.java
@@ -0,0 +1,46 @@
+/*-
+ * ============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;
+
+public class BreakNodeException extends SvcLogicException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public BreakNodeException()
+ {
+ super();
+ }
+
+ public BreakNodeException(String message)
+ {
+ super(message);
+ }
+
+ public BreakNodeException(String message, Throwable t)
+ {
+ super(message, t);
+ }
+
+}
diff --git a/sli/common/src/main/java/org/openecomp/sdnc/sli/MessageWriter.java b/sli/common/src/main/java/org/openecomp/sdnc/sli/MessageWriter.java
new file mode 100644
index 0000000..5e5b621
--- /dev/null
+++ b/sli/common/src/main/java/org/openecomp/sdnc/sli/MessageWriter.java
@@ -0,0 +1,302 @@
+/*-
+ * ============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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Properties;
+
+import javax.sql.rowset.CachedRowSet;
+
+import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
+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 MessageWriter {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MessageWriter.class);
+
+ private static final String DBLIB_SERVICE = "org.openecomp.sdnc.sli.resource.dblib.DBResourceManager";
+ private static final String SVCLOGIC_PROP_VAR = "SDNC_SLI_PROPERTIES";
+ private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
+
+ private static final String INCOMING_PROPERTY_NAME = "org.openecomp.sdnc.sli.MessageWriter.writeIncomingRequests";
+ private static final String OUTGOING_PROPERTY_NAME = "org.openecomp.sdnc.sli.MessageWriter.writeOutgoingRequests";
+
+ private static final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+
+ private static DbLibService dbLibService = null;
+
+ private static boolean incomingEnabled = false;
+ private static boolean outgoingEnabled = false;
+
+ private static boolean initialized = false;
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private static void init() {
+ if (initialized)
+ return;
+
+ initialized = true;
+
+ // Read properties
+ 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()) {
+ LOG.warn("Property file does not exist: " + propPath);
+ }
+
+ try {
+ props.load(new FileInputStream(propFile));
+ } catch (Exception e) {
+ LOG.warn("Error loading property file: " + propPath, e);
+ }
+
+ incomingEnabled = Boolean.valueOf(props.getProperty(INCOMING_PROPERTY_NAME, "false"));
+ outgoingEnabled = Boolean.valueOf(props.getProperty(OUTGOING_PROPERTY_NAME, "false"));
+
+ LOG.info(INCOMING_PROPERTY_NAME + ": " + incomingEnabled);
+ LOG.info(OUTGOING_PROPERTY_NAME + ": " + outgoingEnabled);
+
+ if (dbLibService != null)
+ return;
+
+ BundleContext bctx = FrameworkUtil.getBundle(MessageWriter.class).getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(DBLIB_SERVICE);
+
+ if (sref == null) {
+ LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
+ } else {
+ dbLibService = (DbLibService) bctx.getService(sref);
+ if (dbLibService == null) {
+ LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
+ }
+ }
+ }
+
+ public static void saveOutgoingRequest(
+ String requestId,
+ String serviceInstanceId,
+ String targetUrl,
+ String request) {
+ try {
+ init();
+
+ if (!outgoingEnabled)
+ return;
+
+ if (serviceInstanceId == null || serviceInstanceId.trim().length() == 0)
+ serviceInstanceId = "NA";
+
+ int seqnum = getLastSequenceNumber("OUTGOING_MESSAGE", requestId) + 1;
+ String now = df.format(new Date());
+
+ String sql = "INSERT INTO OUTGOING_MESSAGE (\n" +
+ " request_id, sequence_number, service_instance_id, target_url, request, start_time)\n" +
+ "VALUES (?, ?, ?, ?, ?, ?)";
+
+ ArrayList<String> data = new ArrayList<>();
+ data.add(requestId);
+ data.add(String.valueOf(seqnum));
+ data.add(serviceInstanceId);
+ data.add(targetUrl);
+ data.add(request);
+ data.add(now);
+
+ dbLibService.writeData(sql, data, null);
+
+ } catch (Exception e) {
+ LOG.warn("Failed to save outgoing request for request-id: " + requestId, e);
+ }
+ }
+
+ public static void saveOutgoingResponse(String requestId, int httpResponseCode, String response) {
+ try {
+ init();
+
+ if (!outgoingEnabled)
+ return;
+
+ int seqnum = getLastSequenceNumber("OUTGOING_MESSAGE", requestId);
+ if (seqnum == 0) {
+ LOG.warn("Failed to save outgoing response for request-id: " + requestId +
+ ": Request record not found in OUTGOING_MESSAGE");
+ return;
+ }
+
+ String now = df.format(new Date());
+
+ String sql = "UPDATE OUTGOING_MESSAGE SET http_response_code = ?, response = ?,\n" +
+ " duration = timestampdiff(MICROSECOND, start_time, ?) / 1000\n" +
+ "WHERE request_id = ? AND sequence_number = ?";
+
+ ArrayList<String> data = new ArrayList<>();
+ data.add(String.valueOf(httpResponseCode));
+ data.add(response);
+ data.add(now);
+ data.add(requestId);
+ data.add(String.valueOf(seqnum));
+
+ dbLibService.writeData(sql, data, null);
+
+ } catch (Exception e) {
+ LOG.warn("Failed to save outgoing response for request-id: " + requestId, e);
+ }
+ }
+
+ public static void saveIncomingRequest(
+ String requestId,
+ String serviceInstanceId,
+ String requestHost,
+ String request) {
+ try {
+ init();
+
+ if (!incomingEnabled)
+ return;
+
+ if (serviceInstanceId == null || serviceInstanceId.trim().length() == 0)
+ serviceInstanceId = "NA";
+
+ int seqnum = getLastSequenceNumber("INCOMING_MESSAGE", requestId) + 1;
+ String now = df.format(new Date());
+
+ String sql = "INSERT INTO INCOMING_MESSAGE (\n" +
+ " request_id, sequence_number, service_instance_id, request_host, request, start_time)\n" +
+ "VALUES (?, ?, ?, ?, ?, ?)";
+
+ ArrayList<String> data = new ArrayList<>();
+ data.add(requestId);
+ data.add(String.valueOf(seqnum));
+ data.add(serviceInstanceId);
+ data.add(requestHost);
+ data.add(request);
+ data.add(now);
+
+ dbLibService.writeData(sql, data, null);
+
+ } catch (Exception e) {
+ LOG.warn("Failed to save incoming request for request-id: " + requestId, e);
+ }
+ }
+
+ public static void saveIncomingResponse(String requestId, int httpResponseCode, String response) {
+ try {
+ init();
+
+ if (!incomingEnabled)
+ return;
+
+ int seqnum = getLastSequenceNumber("INCOMING_MESSAGE", requestId);
+ if (seqnum == 0) {
+ LOG.warn("Failed to save response for request-id: " + requestId +
+ ": Request record not found in INCOMING_MESSAGE");
+ return;
+ }
+
+ String now = df.format(new Date());
+
+ String sql = "UPDATE INCOMING_MESSAGE SET http_response_code = ?, response = ?,\n" +
+ " duration = timestampdiff(MICROSECOND, start_time, ?) / 1000\n" +
+ "WHERE request_id = ? AND sequence_number = ?";
+
+ ArrayList<String> data = new ArrayList<>();
+ data.add(String.valueOf(httpResponseCode));
+ data.add(response);
+ data.add(now);
+ data.add(requestId);
+ data.add(String.valueOf(seqnum));
+
+ dbLibService.writeData(sql, data, null);
+
+ } catch (Exception e) {
+ LOG.warn("Failed to save response for request-id: " + requestId, e);
+ }
+ }
+
+ public static String getServiceInstanceId(String requestId) throws SQLException {
+ init();
+
+ String sql = "SELECT service_instance_id FROM OUTGOING_MESSAGE WHERE request_id = '" + requestId +
+ "' ORDER BY sequence_number DESC";
+
+ CachedRowSet rs = null;
+ try {
+ rs = dbLibService.getData(sql, null, null);
+ if (rs.next()) {
+ return rs.getString("service_instance_id");
+ }
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (Exception e) {
+ LOG.warn("Failed to close CachedRowSet", e);
+ }
+ }
+ }
+ return null;
+ }
+
+ private static int getLastSequenceNumber(String tableName, String requestId) throws SQLException {
+ String sql = "SELECT sequence_number FROM " + tableName + " WHERE request_id = '" + requestId +
+ "' ORDER BY sequence_number DESC";
+
+ CachedRowSet rs = null;
+ try {
+ rs = dbLibService.getData(sql, null, null);
+ if (rs.next()) {
+ return rs.getInt("sequence_number");
+ }
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (Exception e) {
+ LOG.warn("Failed to close CachedRowSet", e);
+ }
+ }
+ }
+ return 0;
+ }
+}
diff --git a/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExprListener.java b/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExprListener.java
index d8d3384..4fef12f 100644
--- a/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExprListener.java
+++ b/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExprListener.java
@@ -77,7 +77,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
private void pushExpr(SvcLogicExpression expr)
{
- LOG.debug("Pushing expression ["+expr.getClass().getName()+"]");
+ LOG.trace("Pushing expression ["+expr.getClass().getName()+"]");
if (curExpr != null)
{
exprStack.push(curExpr);
@@ -89,7 +89,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
{
if (exprStack.isEmpty())
{
- LOG.debug("Popping last expression");
+ LOG.trace("Popping last expression");
topExpr = curExpr;
}
else
@@ -97,7 +97,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
SvcLogicExpression lastExpr = curExpr;
curExpr = exprStack.pop();
curExpr.addOperand(lastExpr);
- LOG.debug("New curExpr is ["+curExpr.getClass().getName()+"]");
+ LOG.trace("New curExpr is ["+curExpr.getClass().getName()+"]");
}
}
@@ -107,7 +107,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
String atomText = ctx.getText();
- LOG.debug("enterAtom: text = "+atomText);
+ LOG.trace("enterAtom: text = "+atomText);
SvcLogicAtom newAtom = new SvcLogicAtom(atomText);
@@ -118,7 +118,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void enterMultExpr(MultExprContext ctx) {
- LOG.debug("enterMultExpr: text = "+ctx.getText());
+ LOG.trace("enterMultExpr: text = "+ctx.getText());
SvcLogicBinaryExpression curBinExpr = new SvcLogicBinaryExpression();
pushExpr(curBinExpr);
@@ -127,7 +127,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
for (TerminalNode nd : opList)
{
- LOG.debug("enterMultExpr: operator - "+nd.getText());
+ LOG.trace("enterMultExpr: operator - "+nd.getText());
curBinExpr.addOperator(nd.getText());
}
@@ -136,7 +136,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void exitMultExpr(MultExprContext ctx) {
- LOG.debug("exitMultExpr: text = "+ctx.getText());
+ LOG.trace("exitMultExpr: text = "+ctx.getText());
popExpr();
@@ -144,13 +144,13 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void exitAtom(AtomContext ctx) {
- LOG.debug("exitAtom: text = "+ctx.getText());
+ LOG.trace("exitAtom: text = "+ctx.getText());
popExpr();
}
@Override
public void enterAddExpr(AddExprContext ctx) {
- LOG.debug("enterAddExpr: text = "+ctx.getText());
+ LOG.trace("enterAddExpr: text = "+ctx.getText());
List<TerminalNode> opList = ctx.ADDOP();
@@ -160,7 +160,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
for (TerminalNode nd : opList)
{
- LOG.debug("enterAddExpr: operator - "+nd.getText());
+ LOG.trace("enterAddExpr: operator - "+nd.getText());
curBinExpr.addOperator(nd.getText());
}
@@ -168,19 +168,19 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void exitAddExpr(AddExprContext ctx) {
- LOG.debug("exitAddExpr: text = "+ctx.getText());
+ LOG.trace("exitAddExpr: text = "+ctx.getText());
popExpr();
}
@Override
public void enterFuncExpr(FuncExprContext ctx) {
- LOG.debug("enterFuncExpr: text = "+ctx.getText());
- LOG.debug("enterFuncExpr - IDENTIFIER : "+ctx.IDENTIFIER().getText());
+ LOG.trace("enterFuncExpr: text = "+ctx.getText());
+ LOG.trace("enterFuncExpr - IDENTIFIER : "+ctx.IDENTIFIER().getText());
for (ExprContext expr: ctx.expr())
{
- LOG.debug("enterFuncExpr - expr = "+expr.getText());
+ LOG.trace("enterFuncExpr - expr = "+expr.getText());
}
@@ -189,25 +189,25 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void exitFuncExpr(FuncExprContext ctx) {
- LOG.debug("exitFuncExpr: text = "+ctx.getText());
+ LOG.trace("exitFuncExpr: text = "+ctx.getText());
popExpr();
}
@Override
public void enterParenExpr(ParenExprContext ctx) {
- LOG.debug("enterParenExpr: text = "+ctx.getText());
- LOG.debug("enterParenExpr: expr = "+ctx.expr().getText());
+ LOG.trace("enterParenExpr: text = "+ctx.getText());
+ LOG.trace("enterParenExpr: expr = "+ctx.expr().getText());
}
@Override
public void exitParenExpr(ParenExprContext ctx) {
- LOG.debug("exitParenExpr: text = "+ctx.getText());
+ LOG.trace("exitParenExpr: text = "+ctx.getText());
}
@Override
public void enterRelExpr(RelExprContext ctx) {
- LOG.debug("enterRelExpr: text = "+ctx.getText());
+ LOG.trace("enterRelExpr: text = "+ctx.getText());
List<TerminalNode> opList = ctx.RELOP();
@@ -218,7 +218,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
for (TerminalNode nd : opList)
{
- LOG.debug("enterRelExpr: operator - "+nd.getText());
+ LOG.trace("enterRelExpr: operator - "+nd.getText());
curBinExpr.addOperator(nd.getText());
}
@@ -226,28 +226,28 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void exitRelExpr(RelExprContext ctx) {
- LOG.debug("exitRelExpr: text = "+ctx.getText());
+ LOG.trace("exitRelExpr: text = "+ctx.getText());
popExpr();
}
@Override
public void enterCompareExpr(CompareExprContext ctx) {
- LOG.debug("enterCompareExpr: text = "+ctx.getText());
+ LOG.trace("enterCompareExpr: text = "+ctx.getText());
TerminalNode nd = ctx.COMPAREOP();
SvcLogicBinaryExpression curBinExpr = new SvcLogicBinaryExpression();
pushExpr(curBinExpr);
- LOG.debug("enterCompareExpr: operator - "+nd.getText());
+ LOG.trace("enterCompareExpr: operator - "+nd.getText());
curBinExpr.addOperator(nd.getText());
}
@Override
public void exitCompareExpr(CompareExprContext ctx) {
- LOG.debug("exitCompareExpr : text = "+ctx.getText());
+ LOG.trace("exitCompareExpr : text = "+ctx.getText());
popExpr();
}
@@ -256,18 +256,18 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void enterConstant(ConstantContext ctx) {
- LOG.debug("enterConstant: text = "+ctx.getText());
+ LOG.trace("enterConstant: text = "+ctx.getText());
}
@Override
public void exitConstant(ConstantContext ctx) {
- LOG.debug("exitConstant: text = "+ctx.getText());
+ LOG.trace("exitConstant: text = "+ctx.getText());
}
@Override
public void enterVariable(VariableContext ctx) {
- LOG.debug("enterVariable: text = "+ctx.getText());
+ LOG.trace("enterVariable: text = "+ctx.getText());
}
@@ -290,12 +290,12 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void exitVariableLead(VariableLeadContext ctx) {
- LOG.debug("exitVariableLead: text ="+ctx.getText());
+ LOG.trace("exitVariableLead: text ="+ctx.getText());
}
@Override
public void enterVariableTerm(VariableTermContext ctx) {
- LOG.debug("enterVariableTerm: text ="+ctx.getText());
+ LOG.trace("enterVariableTerm: text ="+ctx.getText());
String name = ctx.getText();
@@ -310,7 +310,7 @@ public class SvcLogicExprListener extends ExprGrammarBaseListener
@Override
public void exitVariableTerm(VariableTermContext ctx) {
- LOG.debug("exitVariableTerm: text="+ctx.getText());
+ LOG.trace("exitVariableTerm: text="+ctx.getText());
popExpr();
}
}
diff --git a/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExpressionFactory.java b/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExpressionFactory.java
index 751564b..cce8e04 100644
--- a/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExpressionFactory.java
+++ b/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExpressionFactory.java
@@ -42,7 +42,7 @@ public class SvcLogicExpressionFactory {
public static SvcLogicExpression parse(String exprStr) throws IOException
{
- LOG.debug("parse("+exprStr+")");
+ LOG.trace("parse("+exprStr+")");
InputStream exprStream = new ByteArrayInputStream(exprStr.getBytes());
CharStream input = new ANTLRInputStream(exprStream);
ExprGrammarLexer lexer = new ExprGrammarLexer(input);
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BreakNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BreakNodeExecutor.java
new file mode 100644
index 0000000..0f8719c
--- /dev/null
+++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/BreakNodeExecutor.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.BreakNodeException;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BreakNodeExecutor extends SvcLogicNodeExecutor {
+
+ private static final Logger LOG = LoggerFactory.getLogger(BreakNodeExecutor.class);
+
+ @Override
+ public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException {
+ String message = "BreakNodeExecutor encountered break with nodeId " + node.getNodeId();
+ LOG.debug(message);
+ throw new BreakNodeException(message);
+ }
+
+}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java
index 2ce4f0a..da0bc56 100644
--- 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
@@ -114,24 +114,21 @@ public class CallNodeExecutor extends SvcLogicNodeExecutor {
version = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
}
+ String parentGraph = ctx.getAttribute("currentGraph");
+ ctx.setAttribute("parentGraph", parentGraph);
SvcLogicStore store = SvcLogicActivator.getStore();
- LOG.debug("Calling ["+module+","+rpc+","+version+","+mode+"]");
-
- if (store != null)
- {
+ if (store != null) {
SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode);
-
- if (calledGraph != null)
- {
+ LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString());
+ ctx.setAttribute("currentGraph", calledGraph.toString());
+ 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.error("Could not find service logic for [" + module + "," + rpc + "," + version + "," + mode + "]");
}
}
else
@@ -144,6 +141,7 @@ public class CallNodeExecutor extends SvcLogicNodeExecutor {
if (LOG.isDebugEnabled()) {
LOG.debug("about to execute " + outValue + " branch");
}
+ ctx.setAttribute("currentGraph", parentGraph);
return (nextNode);
}
@@ -157,6 +155,9 @@ public class CallNodeExecutor extends SvcLogicNodeExecutor {
LOG.debug("no " + outValue + " or Other branch found");
}
}
+ ctx.setAttribute("currentGraph", parentGraph);
+ ctx.setAttribute("parentGraph", null);
+
return (nextNode);
}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/DeleteNodeExecutor.java
index 97da2a6..375c631 100644
--- 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
@@ -53,15 +53,8 @@ public class DeleteNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
-
- ServiceReference sref = bctx.getServiceReference(plugin);
-
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
if (resourcePlugin != null) {
try {
@@ -85,10 +78,7 @@ public class DeleteNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -110,6 +100,22 @@ public class DeleteNodeExecutor extends SvcLogicNodeExecutor {
}
return (nextNode);
}
+
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
}
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
index 158c843..85aede7 100644
--- 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
@@ -21,6 +21,7 @@
package org.openecomp.sdnc.sli.provider;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
@@ -44,6 +45,7 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor {
private static final Logger LOG = LoggerFactory
.getLogger(ExecuteNodeExecutor.class);
+ private static final String pluginErrorMessage = "Could not execute plugin. SvcLogic status will be set to failure.";
public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
SvcLogicContext ctx) throws SvcLogicException {
@@ -55,35 +57,30 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor {
LOG.debug("execute node encountered - looking for plugin "
+ pluginName);
}
-
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
- ServiceReference sref = bctx.getServiceReference(pluginName);
+ SvcLogicJavaPlugin plugin = getSvcLogicJavaPlugin(pluginName);
- if (sref == null) {
+ if (plugin == null) {
outValue = "not-found";
} else {
- SvcLogicJavaPlugin plugin = (SvcLogicJavaPlugin) bctx
- .getService(sref);
-
- String methodName = SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx);
-
+
+ String methodName = evaluate(node.getAttribute("method"), node, ctx);
+
Class pluginClass = plugin.getClass();
-
+
Method pluginMethod = null;
-
+
try {
pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class);
- } catch (Exception e) {
- LOG.error("Caught exception looking for method "+pluginName+"."+methodName+"(Map, SvcLogicContext)");
+ } catch (NoSuchMethodException e) {
+ LOG.error(pluginErrorMessage, e);
}
-
+
if (pluginMethod == null) {
outValue = "unsupported-method";
} else {
try {
-
+
Map<String, String> parmMap = new HashMap<String, String>();
Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
@@ -95,21 +92,34 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor {
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);
-
+
+ Object o = pluginMethod.invoke(plugin, parmMap, ctx);
+ String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
+
+ outValue = mapOutcome(o, emitsOutcome);
+
+ } catch (InvocationTargetException e) {
+ if(e.getCause() != null){
+ LOG.error(pluginErrorMessage, e.getCause());
+ }else{
+ LOG.error(pluginErrorMessage, e);
+ }
outValue = "failure";
ctx.setStatus("failure");
- }
+ } catch (IllegalAccessException e) {
+ LOG.error(pluginErrorMessage, e);
+ outValue = "failure";
+ ctx.setStatus("failure");
+ } catch (IllegalArgumentException e) {
+ LOG.error(pluginErrorMessage, e);
+ outValue = "failure";
+ ctx.setStatus("failure");
+ }
}
}
@@ -135,4 +145,37 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor {
return (nextNode);
}
+ protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(pluginName);
+
+ if (sref == null) {
+ LOG.warn("Could not find service reference object for plugin " + pluginName);
+ return null;
+ } else {
+ SvcLogicJavaPlugin plugin = (SvcLogicJavaPlugin) bctx
+ .getService(sref);
+ return plugin;
+ }
+ }
+ protected String evaluate(SvcLogicExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException {
+ return SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx);
+ }
+
+ public String mapOutcome(Object o, String emitsOutcome) {
+ if (emitsOutcome != null) {
+ Boolean nodeEmitsOutcome = Boolean.valueOf(emitsOutcome);
+ if (nodeEmitsOutcome) {
+ return (String) o;
+ } else {
+ return "success";
+ }
+
+ } else {
+ return "success";
+ }
+ }
+
}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExistsNodeExecutor.java
index 48b511e..464c676 100644
--- 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
@@ -55,14 +55,9 @@ public class ExistsNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
- ServiceReference sref = bctx.getServiceReference(plugin);
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
if (resourcePlugin != null) {
@@ -87,10 +82,6 @@ public class ExistsNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -114,5 +105,21 @@ public class ExistsNodeExecutor extends SvcLogicNodeExecutor {
return (nextNode);
}
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
+
}
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
index a669712..e9fdc55 100644
--- 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
@@ -21,6 +21,7 @@
package org.openecomp.sdnc.sli.provider;
+import org.openecomp.sdnc.sli.BreakNodeException;
import org.openecomp.sdnc.sli.SvcLogicContext;
import org.openecomp.sdnc.sli.SvcLogicException;
import org.openecomp.sdnc.sli.SvcLogicExpression;
@@ -40,7 +41,7 @@ public class ForNodeExecutor extends SvcLogicNodeExecutor {
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);
@@ -59,21 +60,30 @@ public class ForNodeExecutor extends SvcLogicNodeExecutor {
startIdx = Integer.parseInt(startVal);
endIdx = Integer.parseInt(endVal);
} catch (NumberFormatException e) {
- throw new SvcLogicException("Invalid index values [" + startVal
- + "," + endVal + "]");
+ SvcLogicExpression silentFailureExpr = node.getAttribute("silentFailure");
+ String silentFailure = SvcLogicExpressionResolver.evaluate(silentFailureExpr, node, ctx);
+ boolean isSilentFailure = Boolean.parseBoolean(silentFailure);
+ String message = "Invalid index values [" + startVal + "," + endVal + "]";
+ if(!isSilentFailure){
+ throw new SvcLogicException(message);
+ }else{
+ LOG.debug(message + ". Not exiting because silentFailure was set to true.");
+ return(null);
+ }
}
+ try {
for (int ctr = startIdx; ctr < endIdx; ctr++) {
ctx.setAttribute(idxVar, "" + ctr);
for (int i = 0; i < numOutcomes; i++) {
-
+
if ("failure".equals(ctx.getStatus()) && isAtomic) {
LOG.info("For - stopped executing nodes due to failure status");
return(null);
}
-
+
SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1));
if (nextNode != null) {
if (LOG.isDebugEnabled()) {
@@ -83,7 +93,6 @@ public class ForNodeExecutor extends SvcLogicNodeExecutor {
while (innerNextNode != null) {
innerNextNode = svc.executeNode(innerNextNode, ctx);
}
-
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("For - done: no outcome " + (i + 1));
@@ -91,6 +100,9 @@ public class ForNodeExecutor extends SvcLogicNodeExecutor {
}
}
}
+ } catch (BreakNodeException br) {
+ LOG.debug("ForNodeExecutor caught break");
+ }
return (null);
}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/GetResourceNodeExecutor.java
index ce0fe68..c260db2 100644
--- 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
@@ -84,14 +84,8 @@ public class GetResourceNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
- ServiceReference sref = bctx.getServiceReference(plugin);
-
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
if (resourcePlugin != null) {
@@ -116,9 +110,7 @@ public class GetResourceNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -141,6 +133,22 @@ public class GetResourceNodeExecutor extends SvcLogicNodeExecutor {
}
return (nextNode);
}
+
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
}
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
index 47eebe4..00c7e66 100644
--- 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
@@ -56,14 +56,8 @@ public class IsAvailableNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
- ServiceReference sref = bctx.getServiceReference(plugin);
-
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
if (resourcePlugin != null) {
try {
@@ -86,10 +80,6 @@ public class IsAvailableNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -113,5 +103,20 @@ public class IsAvailableNodeExecutor extends SvcLogicNodeExecutor {
return (nextNode);
}
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
}
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
index 9847416..4c5ee06 100644
--- 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
@@ -47,1359 +47,1140 @@ 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));
+ private static final Logger LOG = LoggerFactory.getLogger(MdsalHelper.class);
+ private static Properties yangMappingProperties = new Properties();
+
+ @Deprecated
+ public static void setProperties(Properties input) {
+ setYangMappingProperties(input);
+ }
+
+ public static void setYangMappingProperties(Properties properties) {
+ for (Object propNameObj : properties.keySet()) {
+ String propName = (String) propNameObj;
+ MdsalHelper.yangMappingProperties.setProperty(propName, properties.getProperty(propName));
+ }
+ }
+
+ public static void loadProperties(String propertiesFile) {
+ File file = new File(propertiesFile);
+ Properties properties = new Properties();
+ InputStream input = null;
+ if (file.isFile() && file.canRead()) {
+ try {
+ input = new FileInputStream(file);
+ properties.load(input);
+ MdsalHelper.setYangMappingProperties(properties);
+ LOG.info("Loaded properties from " + propertiesFile);
+ } catch (Exception e) {
+ LOG.error("Failed to load properties " + propertiesFile + "\n", e);
+ } finally {
+ if (input != null) {
+ try {
+ input.close();
+ } catch (IOException e) {
+ LOG.error("Failed to close properties file " + propertiesFile + "\n", e);
+ }
}
+ }
+ }else{
+ LOG.error("Failed to load the properties file " + propertiesFile + "\n");
+ LOG.error("Either isFile or canRead returned false for " + propertiesFile + "\n");
}
+ }
- public static 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();
}
-
- public static Properties toProperties(Properties props, Object fromObj) {
- Class fromClass = null;
-
- if (fromObj != null)
- {
- fromClass = fromObj.getClass();
- }
- return (toProperties(props, "", fromObj, fromClass));
+ return (toProperties(props, "", fromObj, fromClass));
+ }
+
+ public static Properties toProperties(Properties props, String pfx, Object fromObj) {
+ Class fromClass = null;
+
+ if (fromObj != null) {
+ fromClass = fromObj.getClass();
}
-
- 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));
+
+ return (toProperties(props, pfx, fromObj, fromClass));
+ }
+
+ public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass) {
+
+ if (fromObj == null) {
+ return (props);
}
- public static Properties toProperties(Properties props, String pfx,
- Object fromObj, Class fromClass) {
+ 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());
- if (fromObj == null) {
- return (props);
+ } 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());
}
-
-
- String simpleName = fromClass.getSimpleName();
- LOG.trace("Extracting properties from " + fromClass.getName()
- + " class");
- if (fromObj instanceof List) {
+ if (propNamePfx.endsWith("-builder")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length());
+ }
- // Class is a List. List should contain yang-generated classes.
- LOG.trace(fromClass.getName() + " is a List");
+ if (propNamePfx.endsWith("-impl")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-impl".length());
+ }
+ }
- List fromList = (List) fromObj;
+ // Iterate through getter methods to figure out values we need to
+ // save from
- for (int i = 0; i < fromList.size(); i++) {
- toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass);
- }
- props.setProperty(pfx + "_length", "" + fromList.size());
+ int numGetters = 0;
+ String lastGetterName = null;
+ String propVal = null;
- } else if (isYangGenerated(fromClass)) {
- // Class is yang generated.
- LOG.trace(fromClass.getName() + " is a Yang-generated class");
+ for (Method m : fromClass.getMethods()) {
+ if (isGetter(m)) {
- String propNamePfx = null;
+ numGetters++;
+ lastGetterName = m.getName();
- // 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());
- }
+ Class returnType = m.getReturnType();
+ String fieldName;
+ if (m.getName().startsWith("get")) {
+ fieldName = toLowerHyphen(m.getName().substring(3));
+ } else {
- if (propNamePfx.endsWith("-builder")) {
- propNamePfx = propNamePfx.substring(0, propNamePfx.length()
- - "-builder".length());
+ 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);
}
- if (propNamePfx.endsWith("-impl")) {
- propNamePfx = propNamePfx.substring(0, propNamePfx.length()
- - "-impl".length());
+ Object retValue = m.invoke(fromObj);
+
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ if (retValue != null) {
+ String propName = propNamePfx + "." + fieldName;
+ propVal = retValue.toString();
+ props.setProperty(propName, mapEnumeratedValue(fieldName, propVal));
+ }
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to convert Yang-generated enum returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e);
+ }
+ } else if (isIpv4Address(returnType)) {
+ // Save its value
+ try {
+ String propName = propNamePfx + "." + fieldName;
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ Ipv4Address retValue = (Ipv4Address) m.invoke(fromObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
}
- }
-
- // 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)) {
+ if (retValue != null) {
+ propVal = retValue.getValue().toString();
+ LOG.debug("Setting property " + propName + " to " + propVal);
+ props.setProperty(propName, propVal);
- LOG.trace(m.getName()
- + " returns a Class object - not interested");
+ }
+ } 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);
+ }
- } else if (List.class.isAssignableFrom(returnType)) {
+ if (retValue != null) {
+ propVal = retValue.getValue().toString();
+ LOG.debug("Setting property " + propName + " to " + propVal);
+ props.setProperty(propName, propVal);
- // 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);
- }
+ }
+ } 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);
+ }
- } else {
+ if (retValue != null) {
+ propVal = new String(retValue.getValue());
+ LOG.debug("Setting property " + propName + " to " + propVal);
+ props.setProperty(propName, propVal);
- // 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);
- }
+ }
+ } 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 (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 );
+ if (retValue != null) {
+ propVal = new String(retValue.getValue());
+ LOG.debug("Setting property " + propName + " to " + propVal);
+ props.setProperty(propName, propVal);
- } else {
- propVal = propValObj.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 {
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ Object retValue = m.invoke(fromObj);
- }
- } 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);
- }
- }
- }
+ 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);
}
+ }
}
-
- // 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 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 {
- // 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 {
+
+ // 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);
- } else {
- fromVal = fromObj.toString();
+ }
+ } 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);
+ }
}
- LOG.debug("Setting property " + pfx
- + " to " + fromVal);
- props.setProperty(pfx, fromVal);
+ }
+
+ }
+ }
+
+ // 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();
}
- return (props);
+ } else {
+ fromVal = fromObj.toString();
+ }
+ LOG.debug("Setting property " + pfx + " to " + fromVal);
+ props.setProperty(pfx, fromVal);
}
- public static Object toBuilder(Properties props, Object toObj) {
+ return (props);
+ }
- return (toBuilder(props, "", toObj));
- }
+ public static Object toBuilder(Properties props, Object toObj) {
- public static List toList(Properties props, String pfx, List toObj,
- Class elemType) {
+ return (toBuilder(props, "", toObj));
+ }
- int maxIdx = -1;
- boolean foundValue = false;
+ public static List toList(Properties props, String pfx, List toObj, Class elemType) {
- LOG.trace("Saving properties to List<" + elemType.getName()
- + "> from " + pfx);
+ int maxIdx = -1;
+ boolean foundValue = false;
- 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
+ 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);
+ }
+
}
-
- 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;
}
-
+ }
- LOG.trace(pfx + " has max index of " + maxIdx);
- for (int i = 0; i <= maxIdx; i++) {
+ }
- String curBase = pfx + "[" + i + "]";
+ if (foundValue) {
+ return (toObj);
+ } else {
+ return (null);
+ }
- 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;
- }
- }
+ 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");
- if (foundValue) {
- return (toObj);
+ String propNamePfx = null;
+ if (preservePfx) {
+ propNamePfx = pfx;
+ } else {
+
+ if ((pfx != null) && (pfx.length() > 0)) {
+ propNamePfx = pfx + "." + toLowerHyphen(toClass.getSimpleName());
} else {
- return (null);
+ propNamePfx = toLowerHyphen(toClass.getSimpleName());
}
- }
-
- public static Object toBuilder(Properties props, String pfx, Object toObj) {
- return(toBuilder(props, pfx, toObj, false));
- }
+ if (propNamePfx.endsWith("-builder")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length());
+ }
- public static Object toBuilder(Properties props, String pfx, Object toObj, boolean preservePfx) {
- Class toClass = toObj.getClass();
- boolean foundValue = false;
+ if (propNamePfx.endsWith("-impl")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-impl".length());
+ }
+ }
- LOG.trace("Saving properties to " + toClass.getName() + " class from "
- + pfx);
+ if (toObj instanceof Identifier) {
+ LOG.trace(toClass.getName() + " is a Key - skipping");
+ return (toObj);
+ }
- Ipv4Address addr;
+ // Iterate through getter methods to figure out values we need to
+ // set
- if (isYangGenerated(toClass)) {
- // Class is yang generated.
- LOG.trace(toClass.getName() + " is a Yang-generated class");
+ for (Method m : toClass.getMethods()) {
+ if (isSetter(m)) {
+ Class paramTypes[] = m.getParameterTypes();
+ Class paramClass = paramTypes[0];
- String propNamePfx = null;
- if (preservePfx) {
- propNamePfx = pfx;
- } else {
+ String fieldName = toLowerHyphen(m.getName().substring(3));
+ fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);
- if ((pfx != null) && (pfx.length() > 0)) {
- propNamePfx = pfx + "."
- + toLowerHyphen(toClass.getSimpleName());
- } else {
- propNamePfx = toLowerHyphen(toClass.getSimpleName());
- }
+ String propName = propNamePfx + "." + fieldName;
- if (propNamePfx.endsWith("-builder")) {
- propNamePfx = propNamePfx.substring(0, propNamePfx.length()
- - "-builder".length());
- }
+ String paramValue = props.getProperty(propName);
+ if (paramValue == null) {
+ LOG.trace(propName + " is unset");
+ } else {
+ LOG.trace(propName + " = " + paramValue);
+ }
- if (propNamePfx.endsWith("-impl")) {
- propNamePfx = propNamePfx.substring(0, propNamePfx.length()
- - "-impl".length());
+ // Is the return type a yang generated class?
+ if (isYangGenerated(paramClass)) {
+ // Is it an enum?
+ if (paramClass.isEnum()) {
+
+ LOG.trace(m.getName() + " expects an Enum");
+ // Param type is a typedef.
+ if ((paramValue != null) && (paramValue.length() > 0)) {
+ Object paramObj = null;
+
+ try {
+ paramObj = Enum.valueOf(paramClass, toJavaEnum(paramValue));
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to convert field " + propName + " to enum " + paramClass.getName(), e);
}
- }
- if (toObj instanceof Identifier) {
- LOG.trace(toClass.getName() + " is a Key - skipping");
- return (toObj);
- }
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+
+ LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue + ")");
+ m.invoke(toObj, paramObj);
- // Iterate through getter methods to figure out values we need to
- // set
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
- for (Method m : toClass.getMethods()) {
- if (isSetter(m)) {
- Class paramTypes[] = m.getParameterTypes();
- Class paramClass = paramTypes[0];
+ } 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)) {
- String fieldName = toLowerHyphen(m.getName().substring(3));
- fieldName = fieldName.substring(0, 1).toLowerCase()
- + fieldName.substring(1);
+ if ((paramValue != null) && (paramValue.length() > 0)) {
+ try {
+ IpAddress ipAddr = IpAddressBuilder.getDefaultInstance(paramValue);
- String propName = propNamePfx + "." + fieldName;
+ if ("Ipv4Address".equals(simpleName)) {
+ m.invoke(toObj, ipAddr.getIpv4Address());
+ } else if ("Ipv6Address".equals(simpleName)) {
+ m.invoke(toObj, ipAddr.getIpv6Address());
- String paramValue = props.getProperty(propName);
- if (paramValue == null) {
- LOG.trace(propName + " is unset");
} else {
- LOG.trace(propName + " = " + paramValue);
+ m.invoke(toObj, ipAddr);
}
+ foundValue = true;
+ } catch (Exception e) {
+ LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + "(" + paramValue + ")", e);
- // 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 {
+ }
+ } 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;
- // Setter's argument is not a yang-generated class. See
- // if it is a List.
+ } 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.
- if (List.class.isAssignableFrom(paramClass)) {
+ String builderName = paramClass.getName() + "Builder";
+ Class builderClass = null;
+ Object builderObj = null;
+ Object paramObj = null;
- LOG.trace("Parameter class " + paramClass.getName()
- + " is a List");
+ Object constObj = null;
- // Figure out what type of args are in List and pass
- // that to toList().
+ 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) {
- 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 (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 (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);
- }
+ }
+ 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);
}
- } // 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);
- }
- }
+ 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");
- public static void printPropertyList(PrintStream pstr, String pfx,
- Class toClass) {
- boolean foundValue = false;
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to create builder " + builderName, e);
+ }
- LOG.trace("Analyzing " + toClass.getName() + " class : pfx " + pfx);
+ if (paramObj != null) {
- if (isYangGenerated(toClass)
- && (!Identifier.class.isAssignableFrom(toClass))) {
- // Class is yang generated.
- LOG.trace(toClass.getName() + " is a Yang-generated class");
+ try {
- if (toClass.getName().endsWith("Key")) {
- if (Identifier.class.isAssignableFrom(toClass)) {
- LOG.trace(Identifier.class.getName()
- + " is assignable from " + toClass.getName());
- } else {
+ Method buildMethod = builderClass.getMethod("build");
+ LOG.trace("Calling " + paramObj.getClass().getName() + "." + buildMethod.getName() + "()");
+ Object builtObj = buildMethod.invoke(paramObj);
- LOG.trace(Identifier.class.getName()
- + " is NOT assignable from " + toClass.getName());
- }
- }
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
- String propNamePfx = null;
- if (pfx.endsWith("]")) {
- propNamePfx = pfx;
- } else {
+ LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "()");
+ m.invoke(toObj, builtObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
- if ((pfx != null) && (pfx.length() > 0)) {
- propNamePfx = pfx + "."
- + toLowerHyphen(toClass.getSimpleName());
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to set Yang-generated class expected by" + toClass.getName() + "." + m.getName() + "() from Properties entry", e);
+ }
} else {
- propNamePfx = toLowerHyphen(toClass.getSimpleName());
- }
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
- if (propNamePfx.endsWith("-builder")) {
- propNamePfx = propNamePfx.substring(0, propNamePfx.length()
- - "-builder".length());
- }
+ if (constObj != null) {
- if (propNamePfx.endsWith("-impl")) {
- propNamePfx = propNamePfx.substring(0, propNamePfx.length()
- - "-impl".length());
+ 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 {
- // 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);
- }
+ // Setter's argument is not a yang-generated class. See
+ // if it is a List.
- }
- } else {
+ if (List.class.isAssignableFrom(paramClass)) {
- // Setter's argument is not a yang-generated class. See
- // if it is a List.
+ LOG.trace("Parameter class " + paramClass.getName() + " is a List");
- if (List.class.isAssignableFrom(returnClass)) {
+ // Figure out what type of args are in List and pass
+ // that to toList().
- LOG.trace("Parameter class "
- + returnClass.getName() + " is a List");
+ 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());
+ }
- // Figure out what type of args are in List and pass
- // that to toList().
+ 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;
- 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);
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to convert List returned by" + toClass.getName() + "." + m.getName() + "() to Properties entry", e);
+ }
+ }
+ } else {
- } else if (!returnClass.equals(Class.class)) {
+ // Setter expects something that is not a List and
+ // not yang-generated. Just pass the parameter value
- // 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");
- LOG.trace("Parameter class "
- + returnClass.getName()
- + " is not a yang-generated class or a List");
+ if ((paramValue != null) && (paramValue.length() > 0)) {
- pstr.print("\n\n * " + propName);
+ 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));
}
+ }
}
- } // End of section handling "setter" method
- } // End of loop through Methods
- } // End of section handling yang-generated class
+ }
+
+ 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);
- public static boolean isYangGenerated(Class c) {
- if (c == null) {
- return (false);
+ 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 {
- return (c.getName().startsWith("org.opendaylight.yang.gen."));
+
+ LOG.trace(Identifier.class.getName() + " is NOT assignable from " + toClass.getName());
}
- }
-
- public static boolean isIpPrefix(Class c) {
-
- if (c == null ) {
- return (false);
+ }
+
+ 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());
}
- String simpleName = c.getSimpleName();
- return ("IpPrefix".equals(simpleName)) ;
- }
-
-
-
- public static boolean isIpv4Address(Class c) {
-
- if (c == null ) {
- return (false);
+
+ if (propNamePfx.endsWith("-builder")) {
+ propNamePfx = propNamePfx.substring(0, propNamePfx.length() - "-builder".length());
}
- String simpleName = c.getSimpleName();
- return ("Ipv4Address".equals(simpleName)) ;
+
+ 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 isIpv6Address(Class c) {
-
- if (c == null ) {
- return (false);
- }
- String simpleName = c.getSimpleName();
- return ("Ipv6Address".equals(simpleName)) ;
+ }
+
+ public static boolean isIpPrefix(Class c) {
+
+ if (c == null) {
+ return (false);
}
-
- public static boolean isIpAddress(Class c) {
-
- if (c == null ) {
- return (false);
- }
- String simpleName = c.getSimpleName();
- return ("IpAddress".equals(simpleName)) ;
+ 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 String toLowerHyphen(String inStr) {
- if (inStr == null) {
- return (null);
- }
+ public static boolean isIpv6Address(Class c) {
- String str = inStr.substring(0, 1).toLowerCase();
- if (inStr.length() > 1) {
- str = str + inStr.substring(1);
- }
+ if (c == null) {
+ return (false);
+ }
+ String simpleName = c.getSimpleName();
+ return ("Ipv6Address".equals(simpleName));
+ }
+
+ public static boolean isIpAddress(Class c) {
- String regex = "(([a-z0-9])([A-Z]))";
- String replacement = "$2-$3";
+ if (c == null) {
+ return (false);
+ }
+ String simpleName = c.getSimpleName();
+ return ("IpAddress".equals(simpleName));
+ }
- String retval = str.replaceAll(regex, replacement).toLowerCase();
+ public static String toLowerHyphen(String inStr) {
+ if (inStr == null) {
+ return (null);
+ }
- LOG.trace("Converting " + inStr + " => " + str + " => " + retval);
- return (retval);
+ String str = inStr.substring(0, 1).toLowerCase();
+ if (inStr.length() > 1) {
+ str = str + inStr.substring(1);
}
- public static String toUpperCamelCase(String inStr) {
- if (inStr == null) {
- return (null);
- } else if (inStr.length() == 0) {
- return(inStr);
- }
+ String regex = "(([a-z0-9])([A-Z]))";
+ String replacement = "$2-$3";
- 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());
+ String retval = str.replaceAll(regex, replacement).toLowerCase();
+
+ LOG.trace("Converting " + inStr + " => " + str + " => " + retval);
+ return (retval);
+ }
+ //This is called when mapping the yang value back to a valid java enumeration
+ public static String toJavaEnum(String inStr) {
+ if (inStr == null) {
+ return (null);
+ } else if (inStr.length() == 0) {
+ return (inStr);
}
- public static boolean isGetter(Method m) {
- if (m == null) {
- return (false);
- }
+ //This will strip out all periods, which cannot be in a java enum
+ inStr = inStr.replaceAll("\\.", "");
- 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);
- }
- }
+ String[] terms = inStr.split("-");
+ StringBuffer sbuff = new StringBuffer();
- 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);
- }
- }
+ //appends an _ if the string starts with a digit to make it a valid java enum
+ if (Character.isDigit(inStr.charAt(0))) {
+ sbuff.append('_');
+ }
+ //If the string contains hyphens it will convert the string to upperCamelCase without hyphens
+ for (String term : terms) {
+ sbuff.append(term.substring(0, 1).toUpperCase());
+ if (term.length() > 1) {
+ sbuff.append(term.substring(1));
+ }
+ }
+ return (sbuff.toString());
+
+ }
- return (false);
+ public static boolean isGetter(Method m) {
+ if (m == null) {
+ return (false);
}
- public static boolean isSetter(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 (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);
- }
- }
+ 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);
}
+ return (false);
+ }
+
+ public static String getFullPropertiesPath(String propertiesFileName) {
+ return "/opt/bvc/controller/configuration/" + propertiesFileName;
+ }
+
+ //This is called when mapping a valid java enumeration back to the yang model value
+ public static String mapEnumeratedValue(String propertyName, String propertyValue) {
+ LOG.info("mapEnumeratedValue called with propertyName=" + propertyName + " and value=" + propertyValue);
+ String mappingKey = "yang." + propertyName + "." + propertyValue;
+ if (yangMappingProperties.containsKey(mappingKey)) {
+ return (yangMappingProperties.getProperty(mappingKey));
+ } else {
+ LOG.info("yangMappingProperties did not contain the key " + mappingKey + " returning the original value.");
+ return propertyValue;
+ }
+ }
+
}
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/NotifyNodeExecutor.java
index 5002604..4dc4a93 100644
--- 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
@@ -56,15 +56,7 @@ public class NotifyNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
-
- ServiceReference sref = bctx.getServiceReference(plugin);
-
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
-
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
if (resourcePlugin != null) {
try {
@@ -88,10 +80,6 @@ public class NotifyNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -114,5 +102,21 @@ public class NotifyNodeExecutor extends SvcLogicNodeExecutor {
return (nextNode);
}
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
+
}
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
index d07a4d6..f75752b 100644
--- 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
@@ -50,8 +50,8 @@ public class RecordNodeExecutor extends SvcLogicNodeExecutor {
node.getAttribute("plugin"), node, ctx);
String outValue = "failure";
- if (LOG.isDebugEnabled()) {
- LOG.debug(node.getNodeType()
+ if (LOG.isTraceEnabled()) {
+ LOG.trace(node.getNodeType()
+ " node encountered - looking for recorder class "
+ plugin);
}
@@ -71,21 +71,15 @@ public class RecordNodeExecutor extends SvcLogicNodeExecutor {
String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr,
node, ctx);
- if (LOG.isDebugEnabled()) {
- LOG.debug("executeRecordNode : parameter " + curName + " = "
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("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);
+ SvcLogicRecorder recorder = getSvcLogicResource(plugin);
if (recorder != null) {
@@ -99,9 +93,6 @@ public class RecordNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -117,13 +108,28 @@ public class RecordNodeExecutor extends SvcLogicNodeExecutor {
LOG.debug("about to execute Other branch");
}
} else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("no failure or Other branch found");
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("no failure or Other branch found");
}
}
return (nextNode);
}
+ protected SvcLogicRecorder getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicRecorder resourcePlugin = (SvcLogicRecorder) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ return null;
+ }
+ }
+
}
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
index 12e85db..b51cf9f 100644
--- 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
@@ -53,15 +53,7 @@ public class ReleaseNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
-
- ServiceReference sref = bctx.getServiceReference(plugin);
-
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
-
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
if (resourcePlugin != null) {
try {
@@ -85,10 +77,6 @@ public class ReleaseNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -112,5 +100,21 @@ public class ReleaseNodeExecutor extends SvcLogicNodeExecutor {
return (nextNode);
}
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
+
}
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
index aa5d5ef..7db233f 100644
--- 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
@@ -65,14 +65,9 @@ public class ReserveNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
- ServiceReference sref = bctx.getServiceReference(plugin);
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
if (resourcePlugin != null) {
@@ -96,10 +91,6 @@ public class ReserveNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -123,5 +114,21 @@ public class ReserveNodeExecutor extends SvcLogicNodeExecutor {
return (nextNode);
}
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
+
}
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
index fc3adcc..f57eac8 100644
--- 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
@@ -93,14 +93,9 @@ public class SaveNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
- ServiceReference sref = bctx.getServiceReference(plugin);
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
if (resourcePlugin != null) {
@@ -125,10 +120,6 @@ public class SaveNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -151,4 +142,20 @@ public class SaveNodeExecutor extends SvcLogicNodeExecutor {
return (nextNode);
}
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
+
}
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
index 0de109b..55ad737 100644
--- 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
@@ -173,7 +173,7 @@ public class SetNodeExecutor extends SvcLogicNodeExecutor {
curEnt.getValue(), node, ctx);
if (LOG.isDebugEnabled()) {
- LOG.debug("Parameter value "
+ LOG.trace("Parameter value "
+ curEnt.getValue().asParsedExpr()
+ " resolves to " + curValue);
LOG.debug("Setting context attribute " + lhsVarName
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
index 33de964..691ad40 100644
--- 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
@@ -69,6 +69,7 @@ public class SvcLogicActivator implements BundleActivator {
put("set", new SetNodeExecutor());
put("switch", new SwitchNodeExecutor());
put("update", new UpdateNodeExecutor());
+ put("break", new BreakNodeExecutor());
}
};
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
index f248a59..29bd9b4 100644
--- 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
@@ -65,12 +65,12 @@ public class SvcLogicExpressionResolver {
if (atomType == AtomType.CONTEXT_VAR)
{
- LOG.debug("Evaluating context variable $"+varName);
+ LOG.trace("Evaluating context variable $"+varName);
String varValue = ctx.getAttribute(varName);
if (varValue == null) {
- LOG.debug("Context variable $"+varName+" unset - treating as empty string");
+ LOG.trace("Context variable $"+varName+" unset - treating as empty string");
varValue = "";
}
@@ -78,7 +78,7 @@ public class SvcLogicExpressionResolver {
}
SvcLogicExpression parm = node.getParameter(varName);
if (parm != null) {
- LOG.debug("Evaluating value of parameter "+varName+": "+parm.asParsedExpr());
+ LOG.trace("Evaluating value of parameter "+varName+": "+parm.asParsedExpr());
return (evaluate(parm, node, ctx));
}
@@ -98,7 +98,7 @@ public class SvcLogicExpressionResolver {
List<SvcLogicExpression> operands = binExpr.getOperands();
if (operands.size() == 1)
{
- LOG.debug("SvcLogicBinaryExpression as no operator and one operand - evaluating its operand");
+ LOG.trace("SvcLogicBinaryExpression as no operator and one operand - evaluating its operand");
return(evaluate(operands.get(0), node, ctx));
}
else
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
index 14366a9..6ee264e 100644
--- 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
@@ -268,6 +268,8 @@ public class SvcLogicServiceImpl implements SvcLogicService {
LOG.info("Executing root node");
SvcLogicContext ctx = new SvcLogicContext(props);
+ ctx.setAttribute("currentGraph", graph.toString());
+ ctx.setAttribute("X-ECOMP-RequestID", MDC.get("X-ECOMP-RequestID"));
ctx.setDomDataBroker(domDataBroker);
SvcLogicNode curNode = graph.getRootNode();
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
index 4ea851f..2e32a58 100644
--- 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
@@ -55,8 +55,7 @@ public class SwitchNodeExecutor extends SvcLogicNodeExecutor {
if (LOG.isDebugEnabled()) {
if (nextNode != null) {
- LOG.debug("Next node to execute is node "
- + nextNode.getNodeId());
+ LOG.debug("Next node to execute is node " + nextNode.getNodeId());
} else {
LOG.debug("No next node found");
}
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
index ac1144c..e7a6621 100644
--- 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
@@ -87,14 +87,9 @@ public class UpdateNodeExecutor extends SvcLogicNodeExecutor {
+ plugin);
}
- BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
- .getBundleContext();
- ServiceReference sref = bctx.getServiceReference(plugin);
+ SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
- if (sref != null) {
- SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
- .getService(sref);
if (resourcePlugin != null) {
@@ -119,10 +114,6 @@ public class UpdateNodeExecutor extends SvcLogicNodeExecutor {
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) {
@@ -145,4 +136,19 @@ public class UpdateNodeExecutor extends SvcLogicNodeExecutor {
return (nextNode);
}
+ protected SvcLogicResource getSvcLogicResource(String plugin) {
+ BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
+ .getBundleContext();
+
+ ServiceReference sref = bctx.getServiceReference(plugin);
+ if (sref != null) {
+ SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
+ .getService(sref);
+ return resourcePlugin;
+ }
+ else {
+ LOG.warn("Could not find service reference object for plugin " + plugin);
+ return null;
+ }
+ }
}
diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/BadPlugin.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/BadPlugin.java
new file mode 100644
index 0000000..d1ab4cf
--- /dev/null
+++ b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/BadPlugin.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.Map;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+
+public class BadPlugin implements SvcLogicJavaPlugin {
+ public String selectLunch(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String day = parameters.get("day");
+ if (day == null || day.length() < 1) {
+ throw new SvcLogicException("What day is it?");
+ }
+ switch (day) {
+ case ("monday"): {
+ return "pizza";
+ }
+ case ("tuesday"): {
+ return "soup";
+ }
+ case ("wednesday"): {
+ return "salad";
+ }
+ case ("thursday"): {
+ return "sushi";
+ }
+ case ("friday"): {
+ return "bbq";
+ }
+ }
+ throw new SvcLogicException("Lunch cannot be served");
+ }
+}
diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutorTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutorTest.java
new file mode 100644
index 0000000..3d43ee1
--- /dev/null
+++ b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutorTest.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.Map.Entry;
+
+import org.openecomp.sdnc.sli.DuplicateValueException;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicGraph;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+
+import junit.framework.TestCase;
+
+public class ExecuteNodeExecutorTest extends TestCase {
+ public class MockExecuteNodeExecutor extends ExecuteNodeExecutor {
+
+ protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName) {
+ return (SvcLogicJavaPlugin) new LunchSelectorPlugin();
+ }
+
+ protected String evaluate(SvcLogicExpression expr, SvcLogicNode node,
+ SvcLogicContext ctx) throws SvcLogicException {
+ return "selectLunch";
+ }
+ }
+
+ public void testBadPlugin() throws DuplicateValueException, SvcLogicException {
+ LunchSelectorPlugin p = new LunchSelectorPlugin();
+ MockExecuteNodeExecutor execute = new MockExecuteNodeExecutor();
+ SvcLogicNode node = new SvcLogicNode(0, "", "", new SvcLogicGraph());
+ node.setAttribute("method", "selectLunch");
+ execute.execute(new SvcLogicServiceImpl(), new SvcLogicNode(0, "", "", new SvcLogicGraph()), new SvcLogicContext());
+ }
+
+}
diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/LunchSelectorPlugin.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/LunchSelectorPlugin.java
new file mode 100644
index 0000000..b9156bc
--- /dev/null
+++ b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/LunchSelectorPlugin.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.Map;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+
+
+public class LunchSelectorPlugin implements SvcLogicJavaPlugin {
+ public class UnknownLunchDayException extends Exception{
+
+ public UnknownLunchDayException(String string) {
+ super(string);
+ }
+
+ }
+ class Sandwhich {
+ String meat;
+ String cheese;
+
+ public Sandwhich(String meat, String cheese) {
+ this.meat = meat;
+ this.cheese = cheese;
+ }
+ }
+
+ public String selectLunch(Map<String, String> parameters, SvcLogicContext ctx) throws Exception {
+ String day = parameters.get("day");
+ if (day == null || day.length() < 1) {
+ throw new UnknownLunchDayException("What day is it?");
+ }
+ switch (day) {
+ case ("monday"): {
+ return "pizza";
+ }
+ case ("tuesday"): {
+ return "soup";
+ }
+ case ("wednesday"): {
+ return "salad";
+ }
+ case ("thursday"): {
+ return "sushi";
+ }
+ case ("friday"): {
+ return "bbq";
+ }
+ }
+ throw new SvcLogicException("Lunch cannot be served");
+ }
+
+ public Sandwhich makeLunch(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ return new Sandwhich("ham", "american");
+ }
+}
diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTest.java
new file mode 100644
index 0000000..a4e41bb
--- /dev/null
+++ b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTest.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 junit.framework.TestCase;
+
+public class MdsalHelperTest extends TestCase {
+
+ public static final String pathToSdnPropertiesFile = "./src/test/resources/l3sdn.properties";
+
+ public void testSdnProperties() {
+ MdsalHelperTesterUtil.loadProperties(pathToSdnPropertiesFile);
+ assertEquals("synccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "Synccomplete"));
+ assertEquals("asynccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "asynccomplete"));
+ assertEquals("notifycomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "notifycomplete"));
+ assertEquals("service-configuration-operation", MdsalHelperTesterUtil.mapEnumeratedValue("rpc-name",
+ "ServiceConfigurationOperation"));
+ }
+
+ public void testNegativeSdnProperties() {
+ assertNotSame("synccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "Synccomplete"));
+ }
+
+}
diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTesterUtil.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTesterUtil.java
new file mode 100644
index 0000000..01e333f
--- /dev/null
+++ b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/MdsalHelperTesterUtil.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import org.openecomp.sdnc.sli.provider.MdsalHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MdsalHelperTesterUtil extends MdsalHelper {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MdsalHelperTesterUtil.class);
+
+ //Normally static init of classes goes here for some weird classloader thing
+ static {
+ String str = "Hello World!";
+ }
+
+}
diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/PluginTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/PluginTest.java
new file mode 100644
index 0000000..035cd3e
--- /dev/null
+++ b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/PluginTest.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicGraph;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+import org.openecomp.sdnc.sli.SvcLogicNode;
+
+import junit.framework.TestCase;
+
+public class PluginTest extends TestCase {
+
+ // The existing plugins work just like a VoidDummyPlugin
+ // They will return null simply because they are all void
+ // The attribute emitsOutcome will not be present, the expected outcome is success when no exception is thrown by the plugin
+ public void testOldPlugin() throws Exception {
+ ExecuteNodeExecutor executor = new ExecuteNodeExecutor();
+ SvcLogicJavaPlugin plugin = new VoidDummyPlugin();
+
+ Class pluginClass = plugin.getClass();
+ Method pluginMethod = pluginClass.getMethod("dummy", Map.class, SvcLogicContext.class);
+ Map<String, String> parmMap = new HashMap<String, String>();
+ SvcLogicContext ctx = new SvcLogicContext();
+ Object o = pluginMethod.invoke(plugin, parmMap, ctx);
+
+ SvcLogicGraph graph = new SvcLogicGraph();
+ SvcLogicNode node = new SvcLogicNode(1, "return", graph);
+ String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
+ String outValue = executor.mapOutcome(o, emitsOutcome);
+ assertEquals("success",outValue);
+ }
+
+ //Newer plugins can set the attribute emitsOutcome to true, if so they should return a string
+ //The string represents the outcome value
+ public void testNewPlugin() throws Exception {
+ ExecuteNodeExecutor executor = new ExecuteNodeExecutor();
+ SvcLogicJavaPlugin plugin = new LunchSelectorPlugin();
+
+ Class pluginClass = plugin.getClass();
+ Method pluginMethod = pluginClass.getMethod("selectLunch", Map.class, SvcLogicContext.class);
+
+ Map<String, String> parmMap = new HashMap<String, String>();
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ parmMap.put("day", "monday");
+ Object o = pluginMethod.invoke(plugin, parmMap, ctx);
+ SvcLogicGraph graph = new SvcLogicGraph();
+ SvcLogicNode node = new SvcLogicNode(1, "return", graph);
+ node.setAttribute("emitsOutcome", "true");
+ String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
+ String outValue = executor.mapOutcome(o, emitsOutcome);
+ assertEquals("pizza", outValue);
+
+ parmMap.put("day", "tuesday");
+ outValue = (String) pluginMethod.invoke(plugin, parmMap, ctx);
+ o = pluginMethod.invoke(plugin, parmMap, ctx);
+ outValue = executor.mapOutcome(o, emitsOutcome);
+ assertEquals("soup",outValue);
+
+ }
+
+ //APPC had some legacy plugins returning objects which should not be treated as outcomes
+ //The attribute emitsOutcome will not be set
+ //The outcome should be success as it has always been
+ public void testObjPlugin() throws Exception{
+ ExecuteNodeExecutor executor = new ExecuteNodeExecutor();
+ SvcLogicJavaPlugin plugin = new LunchSelectorPlugin();
+
+ Class pluginClass = plugin.getClass();
+ Method pluginMethod = pluginClass.getMethod("makeLunch", Map.class, SvcLogicContext.class);
+
+ Map<String, String> parmMap = new HashMap<String, String>();
+ SvcLogicContext ctx = new SvcLogicContext();
+ Object o = pluginMethod.invoke(plugin, parmMap, ctx);
+ SvcLogicGraph graph = new SvcLogicGraph();
+ SvcLogicNode node = new SvcLogicNode(1, "return", graph);
+ String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
+ String outValue = executor.mapOutcome(o, emitsOutcome);
+ assertEquals("success",outValue);
+ }
+
+}
diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/VoidDummyPlugin.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/VoidDummyPlugin.java
new file mode 100644
index 0000000..6c8214a
--- /dev/null
+++ b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/VoidDummyPlugin.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.provider;
+
+import java.util.Map;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+
+
+public class VoidDummyPlugin implements SvcLogicJavaPlugin {
+
+ public void dummy(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ return;
+ }
+
+}