SDNC-11 merge 93/4493/2 19/1219/edit-4493/1
authorKevin Smokowski <ks6305@att.com>
Thu, 25 May 2017 20:54:07 +0000 (20:54 +0000)
committerKevin Smokowski <ks6305@att.com>
Thu, 25 May 2017 21:21:01 +0000 (21:21 +0000)
Change-Id: I8ac404a2a13469d77f117fd1d90162e5b7c4f7a0
Signed-off-by: Kevin Smokowski <ks6305@att.com>
sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicParser.java
sli/common/src/main/resources/svclogic.xsd
sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/CallNodeExecutor.java
sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java
sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/WhileNodeExecutor.java [new file with mode: 0644]
sliPluginUtils/provider/src/main/java/org/openecomp/sdnc/sli/SliPluginUtils/DME2.java

index 0e06b9e..3aa4068 100644 (file)
-/*-
+/*-\r
  * ============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
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
  * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdnc.sli;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.LinkedList;
-
-import javax.xml.XMLConstants;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * @author dt5972
- *
- */
-public class SvcLogicParser {
-
-    SvcLogicStore store = null;
-    static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
-    static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
-    static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
-    static final String JAXP_DYNAMIC_VALIDATION = "http://apache.org/xml/features/validation/dynamic";
-    static final String JAXP_SCHEMA_VALIDATION = "http://apache.org/xml/features/validation/schema";
-
-    private static final String LOAD_MESSAGE = "Getting SvcLogicGraph from database - ";
-    private static final String LOAD_ERROR_MESSAGE = "SvcLogicGraph not found - ";
-    private static final String ACTIVATION_ERROR_MESSAGE = "Could not activate SvcLogicGraph - ";
-    private static final String PRINT_ERROR_MESSAGE = "Could not print SvcLogicGraph - ";
-    private static final String SVC_LOGIC_STORE_ERROR = "Could not get service logic store";
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(SvcLogicParser.class);
-    private static final String SLI_VALIDATING_PARSER = "org.openecomp.sdnc.sli.parser.validate";
-    private static final String SVCLOGIC_XSD = "/svclogic.xsd";
-
-    private class SvcLogicHandler extends DefaultHandler {
-    private Locator locator = null;
-    private String module = null;
-    private String version = null;
-    private LinkedList<SvcLogicGraph> graphs = null;
-    private SvcLogicGraph curGraph = null;
-    private SvcLogicNode curNode = null;
-    private LinkedList<SvcLogicNode> nodeStack = null;
-    private int curNodeId = 0;
-    private String outcomeValue = null;
-    private LinkedList<String> outcomeStack = null;
-    private SvcLogicStore svcLogicStore = null;
-
-    public SvcLogicHandler(LinkedList<SvcLogicGraph> graphs, SvcLogicStore store) {
-        this.graphs = graphs;
-        this.curNode = null;
-        this.nodeStack = new LinkedList<>();
-        this.outcomeStack = new LinkedList<>();
-        this.curNodeId = 1;
-        this.outcomeValue = null;
-        this.svcLogicStore = store;
-
-    }
-
-    @Override
-       public void setDocumentLocator(Locator locator) {
-        this.locator = locator;
-    }
-
-    @Override
-    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
-
-        // Handle service-logic (graph) tag
-        if ("service-logic".equalsIgnoreCase(qName)) {
-
-        module = attributes.getValue("module");
-        if (module == null || module.length() == 0) {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Missing 'module' attribute from service-logic tag");
-        }
-
-        version = attributes.getValue("version");
-        if (version == null || version.length() == 0) {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Missing 'version' attribute from service-logic tag");
-        }
-
-        return;
-        }
-
-        if ("method".equalsIgnoreCase(qName)) {
-        if (curGraph != null) {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Cannot nest module tags");
-        }
-        curGraph = new SvcLogicGraph();
-        curGraph.setModule(module);
-        curGraph.setVersion(version);
-        this.curNodeId = 1;
-
-        String attrValue = attributes.getValue("rpc");
-        if (attrValue == null || attrValue.length() == 0) {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Missing 'rpc' attribute for method tag");
-        }
-        curGraph.setRpc(attrValue);
-
-        attrValue = attributes.getValue("mode");
-        if (attrValue == null || attrValue.length() == 0) {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Missing 'mode' attribute for method tag");
-        }
-        curGraph.setMode(attrValue);
-
-        return;
-
-        }
-
-        // Handle outcome (edge) tag
-        if ("outcome".equalsIgnoreCase(qName)) {
-        String refValue = attributes.getValue("ref");
-
-        if (refValue != null) {
-            SvcLogicNode refNode = curGraph.getNamedNode(refValue);
-
-            if (refNode != null) {
-            try {
-                curNode.addOutcome(attributes.getValue("value"), refNode);
-            } catch (SvcLogicException e) {
-                throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Cannot add outcome", e);
-            }
-            } else {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "ref to unknown node " + refValue);
-            }
-            return;
-        }
-
-        if (outcomeValue != null) {
-            outcomeStack.push(outcomeValue);
-        }
-        outcomeValue = attributes.getValue("value");
-
-        return;
-        }
-
-        // Handle parameter tag
-        if ("parameter".equalsIgnoreCase(qName)) {
-        String parmName = attributes.getValue("name");
-        String parmValue = attributes.getValue("value");
-
-        if (parmName != null && parmName.length() > 0 && parmValue != null) {
-            try {
-
-            curNode.mapParameter(parmName, parmValue);
-            } catch (Exception e) {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + " cannot set parameter " + parmName + " to " + parmValue + " [" + e.getMessage() + "]");
-            }
-        }
-
-        return;
-        }
-
-        // Handle node tags
-
-        String nodeName = attributes.getValue("name");
-        SvcLogicNode thisNode = null;
-
-        try {
-        if (!svcLogicStore.isValidNodeType(qName)) {
-            throw new SAXNotRecognizedException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Unknown tag " + qName);
-        }
-        } catch (Exception e) {
-        throw new SAXNotRecognizedException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Cannot validate node type " + qName);
-        }
-
-        try {
-        if (nodeName != null && nodeName.length() > 0) {
-            thisNode = new SvcLogicNode(curNodeId++, qName, nodeName, curGraph);
-        } else {
-            thisNode = new SvcLogicNode(curNodeId++, qName, curGraph);
-        }
-
-        if (curGraph.getRootNode() == null) {
-            curGraph.setRootNode(thisNode);
-        }
-        } catch (SvcLogicException e) {
-        throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + e.getMessage());
-
-        }
-
-        int numAttributes = attributes.getLength();
-
-        for (int i = 0; i < numAttributes; i++) {
-        String attrName = attributes.getQName(i);
-        if (!"name".equalsIgnoreCase(attrName)) {
-            try {
-
-            String attrValueStr = attributes.getValue(i);
-            SvcLogicExpression attrValue = null;
-            if (attrValueStr.trim().startsWith("`")) {
-                int lastParen = attrValueStr.lastIndexOf("`");
-                String evalExpr = attrValueStr.trim().substring(1, lastParen);
-                attrValue = SvcLogicExpressionFactory.parse(evalExpr);
-
-            } else {
-                if (Character.isDigit(attrValueStr.charAt(0))) {
-                attrValue = new SvcLogicAtom("NUMBER", attrValueStr);
-                } else {
-                attrValue = new SvcLogicAtom("STRING", attrValueStr);
-                }
-            }
-            thisNode.setAttribute(attrName, attrValue);
-            } catch (Exception e) {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Cannot set attribute " + attrName, e);
-            }
-        }
-        }
-
-        if (curNode != null) {
-        try {
-            if ("block".equalsIgnoreCase(curNode.getNodeType()) || "for".equalsIgnoreCase(curNode.getNodeType())) {
-            curNode.addOutcome("" + (curNode.getNumOutcomes() + 1), thisNode);
-            } else {
-            if (outcomeValue == null) {
-                throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + curNode.getNodeType() + " node expects outcome, instead found " + thisNode.getNodeType());
-            }
-            curNode.addOutcome(outcomeValue, thisNode);
-            }
-        } catch (SvcLogicException e) {
-            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + e.getMessage());
-        }
-        nodeStack.push(curNode);
-        }
-        curNode = thisNode;
-
-    }
-
-    @Override
-    public void endElement(String uri, String localName, String qName) throws SAXException {
-
-        // Handle close of service-logic tag
-        if ("service-logic".equalsIgnoreCase(qName)) {
-        // Nothing more to do
-        return;
-        }
-
-        // Handle close of method tag
-        if ("method".equalsIgnoreCase(qName)) {
-        graphs.add(curGraph);
-        curGraph = null;
-        return;
-        }
-
-        // Handle close of outcome tag
-        if ("outcome".equalsIgnoreCase(qName)) {
-        // Finished this outcome - pop the outcome stack
-        if (outcomeStack.isEmpty()) {
-            outcomeValue = null;
-        } else {
-            outcomeValue = outcomeStack.pop();
-        }
-        return;
-        }
-
-        // Handle close of parameter tag - do nothing
-        if ("parameter".equalsIgnoreCase(qName)) {
-        return;
-        }
-
-        // Handle close of a node tag
-        if (nodeStack.isEmpty()) {
-        curNode = null;
-        } else {
-        curNode = nodeStack.pop();
-        }
-    }
-
-    @Override
-    public void error(SAXParseException arg0) throws SAXException {
-        throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + arg0.getMessage());
-    }
-
-    }
-
-    public SvcLogicParser(SvcLogicStore store) {
-    this.store = store;
-    }
-
-    public SvcLogicParser(String propFile) {
-
-    try {
-        this.store = SvcLogicStoreFactory.getSvcLogicStore(propFile);
-    } catch (Exception e) {
-        LOGGER.error(SVC_LOGIC_STORE_ERROR, e);
-
-    }
-
-    }
-
-    public SvcLogicParser(InputStream propStr) {
-
-    try {
-        this.store = SvcLogicStoreFactory.getSvcLogicStore(propStr);
-    } catch (Exception e) {
-        LOGGER.error(SVC_LOGIC_STORE_ERROR, e);
-
-    }
-
-    }
-
-    public LinkedList<SvcLogicGraph> parse(String fileName) throws SvcLogicException {
-    LinkedList<SvcLogicGraph> graphs = null;
-
-    URL xsdUrl = null;
-    Schema schema = null;
-    String validateSchema = System.getProperty(SLI_VALIDATING_PARSER, "true");
-
-    if (validateSchema != null || validateSchema.equalsIgnoreCase("true")) {
-        xsdUrl = getClass().getResource(SVCLOGIC_XSD);
-
-    }
-
-    if (xsdUrl != null) {
-        try {
-        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-        schema = schemaFactory.newSchema(xsdUrl);
-        } catch (Exception e) {
-        LOGGER.warn("Could not validate using schema " + xsdUrl.getPath(), e);
-        }
-    } else {
-        LOGGER.warn("Could not find resource " + SVCLOGIC_XSD);
-    }
-
-    try {
-        SAXParserFactory factory = SAXParserFactory.newInstance();
-
-        if (schema != null) {
-        factory.setNamespaceAware(true);
-        factory.setSchema(schema);
-        }
-        SAXParser saxParser = factory.newSAXParser();
-
-        if (saxParser.isValidating()) {
-        LOGGER.info("Validating against schema " + xsdUrl.getPath());
-        }
-        graphs = new LinkedList<>();
-
-        saxParser.parse(fileName, new SvcLogicHandler(graphs, store));
-
-    } catch (Exception e) {
-        String msg = e.getMessage();
-        if (msg != null) {
-        LOGGER.error(msg);
-        throw new SvcLogicException("Compiler error: " + fileName + " @ " + msg);
-        } else {
-        LOGGER.info("Caught exception parsing " + fileName, e);
-        throw new SvcLogicException("Compiler error: " + fileName, e);
-        }
-    }
-
-    return graphs;
-    }
-
-    public static void main(String argv[]) {
-
-    if (argv.length == 0) {
-        SvcLogicParser.usage();
-    }
-
-    if ("load".equalsIgnoreCase(argv[0])) {
-        if (argv.length == 3) {
-        String xmlfile = argv[1];
-        String propfile = argv[2];
-
-        SvcLogicStore store = SvcLogicParser.getStore(propfile);
-        try {
-            SvcLogicParser.load(xmlfile, store);
-        } catch (Exception e) {
-            LOGGER.error(e.getMessage(), e);
-        }
-        } else {
-        SvcLogicParser.usage();
-        }
-    } else if ("print".equalsIgnoreCase(argv[0])) {
-        String version = null;
-        String propfile = null;
-
-        switch (argv.length) {
-        case 6:
-        version = argv[4];
-        propfile = argv[5];
-        case 5:
-        if (propfile == null) {
-            propfile = argv[4];
-        }
-        SvcLogicStore store = SvcLogicParser.getStore(propfile);
-        SvcLogicParser.print(argv[1], argv[2], argv[3], version, store);
-        break;
-        default:
-        SvcLogicParser.usage();
-        }
-    } else if ("get-source".equalsIgnoreCase(argv[0])) {
-
-        switch (argv.length) {
-        case 6:
-        SvcLogicStore store = SvcLogicParser.getStore(argv[5]);
-        SvcLogicParser.getSource(argv[1], argv[2], argv[3], argv[4], store);
-        break;
-        default:
-        SvcLogicParser.usage();
-        }
-    } else if ("activate".equalsIgnoreCase(argv[0])) {
-        if (argv.length == 6) {
-        SvcLogicStore store = SvcLogicParser.getStore(argv[5]);
-        SvcLogicParser.activate(argv[1], argv[2], argv[3], argv[4], store);
-        } else {
-        SvcLogicParser.usage();
-        }
-    } else if ("validate".equalsIgnoreCase(argv[0])) {
-        if (argv.length == 3) {
-        String xmlfile = argv[1];
-        String propfile = argv[2];
-
-        System.setProperty(SLI_VALIDATING_PARSER, "true");
-        SvcLogicStore store = SvcLogicParser.getStore(propfile);
-        try {
-            SvcLogicParser.validate(xmlfile, store);
-        } catch (Exception e) {
-            LOGGER.error(e.getMessage(), e);
-        }
-        } else {
-        SvcLogicParser.usage();
-        }
-    }
-
-    System.exit(0);
-    }
-
-    private static SvcLogicStore getStore(String propfile) {
-
-    SvcLogicStore store = null;
-
-    try {
-        store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
-    } catch (Exception e) {
-        LOGGER.error(SVC_LOGIC_STORE_ERROR, e);
-        System.exit(1);
-    }
-
-    return store;
-
-    }
-
-    public static void load(String xmlfile, SvcLogicStore store) throws SvcLogicException {
-    File xmlFile = new File(xmlfile);
-    if (!xmlFile.canRead()) {
-        throw new ConfigurationException("Cannot read xml file (" + xmlfile + ")");
-    }
-
-    SvcLogicParser parser = new SvcLogicParser(store);
-    LinkedList<SvcLogicGraph> graphs = null;
-    try {
-        graphs = parser.parse(xmlfile);
-    } catch (Exception e) {
-        throw new SvcLogicException(e.getMessage(), e);
-    }
-
-    if (graphs == null) {
-        throw new SvcLogicException("Could not parse " + xmlfile);
-    }
-
-    for (SvcLogicGraph graph : graphs) {
-
-        String module = graph.getModule();
-        String rpc = graph.getRpc();
-        String version = graph.getVersion();
-        String mode = graph.getMode();
-        try {
-        LOGGER.info("Saving SvcLogicGraph to database (module:" + module + ",rpc:" + rpc + ",version:" + version + ",mode:" + mode + ")");
-        store.store(graph);
-        } catch (Exception e) {
-        throw new SvcLogicException(e.getMessage(), e);
-        }
-
-    }
-
-    }
-
-    public static void validate(String xmlfile, SvcLogicStore store) throws SvcLogicException {
-    File xmlFile = new File(xmlfile);
-    if (!xmlFile.canRead()) {
-        throw new ConfigurationException("Cannot read xml file (" + xmlfile + ")");
-    }
-
-    SvcLogicParser parser = new SvcLogicParser(store);
-    LinkedList<SvcLogicGraph> graphs = null;
-    try {
-        LOGGER.info("Validating " + xmlfile);
-        graphs = parser.parse(xmlfile);
-    } catch (Exception e) {
-        throw new SvcLogicException(e.getMessage(), e);
-    }
-
-    if (graphs == null) {
-        throw new SvcLogicException("Could not parse " + xmlfile);
-    } else {
-        LOGGER.info("Compilation successful for " + xmlfile);
-    }
-
-    }
-
-    private static void print(String module, String rpc, String mode, String version, SvcLogicStore store) {
-    String details = "(module:" + module + ", rpc:" + rpc + ", version:" + version + ", mode:" + mode + ")";
-
-    try {
-        LOGGER.info(LOAD_MESSAGE + details);
-
-        SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
-        if (graph == null) {
-        LOGGER.error(LOAD_ERROR_MESSAGE + details);
-        System.exit(1);
-        }
-        graph.printAsGv(System.out);
-    } catch (Exception e) {
-        LOGGER.error(PRINT_ERROR_MESSAGE + details, e);
-        System.exit(1);
-    }
-
-    }
-
-    private static void getSource(String module, String rpc, String mode, String version, SvcLogicStore store) {
-    String details = "(module:" + module + ", rpc:" + rpc + ", version:" + version + ", mode:" + mode + ")";
-
-    try {
-        LOGGER.info(LOAD_MESSAGE + details);
-
-        SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
-        if (graph == null) {
-        LOGGER.error(LOAD_ERROR_MESSAGE + details);
-        System.exit(1);
-        }
-        graph.printAsXml(System.out);
-    } catch (Exception e) {
-        LOGGER.error(PRINT_ERROR_MESSAGE + details, e);
-        System.exit(1);
-    }
-
-    }
-
-    private static void activate(String module, String rpc, String version, String mode, SvcLogicStore store) {
-    String details = "(module:" + module + ", rpc:" + rpc + ", version:" + version + ", mode:" + mode + ")";
-
-    try {
-        LOGGER.info(LOAD_MESSAGE + details);
-
-        SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
-        if (graph == null) {
-        LOGGER.error(LOAD_ERROR_MESSAGE + details);
-        System.exit(1);
-        }
-        store.activate(graph);
-    } catch (Exception e) {
-        LOGGER.error(ACTIVATION_ERROR_MESSAGE + details, e);
-        System.exit(1);
-    }
-
-    }
-
-    private static void usage() {
-    System.err.println("Usage: SvcLogicParser load <xml-file> <prop-file>");
-    System.err.println(" OR    SvcLogicParser print <module> <rpc> <mode> [<version>] <prop-file>");
-    System.err.println(" OR    SvcLogicParser get-source <module> <rpc> <mode> <version> <prop-file>");
-    System.err.println(" OR    SvcLogicParser activate <module> <rpc> <version> <mode>");
-    System.exit(1);
-    }
-
-}
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.sdnc.sli;\r
+\r
+import java.io.File;\r
+import java.io.InputStream;\r
+import java.net.URL;\r
+import java.util.LinkedList;\r
+\r
+import javax.xml.XMLConstants;\r
+import javax.xml.parsers.SAXParser;\r
+import javax.xml.parsers.SAXParserFactory;\r
+import javax.xml.validation.Schema;\r
+import javax.xml.validation.SchemaFactory;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.xml.sax.Attributes;\r
+import org.xml.sax.Locator;\r
+import org.xml.sax.SAXException;\r
+import org.xml.sax.SAXNotRecognizedException;\r
+import org.xml.sax.SAXParseException;\r
+import org.xml.sax.helpers.DefaultHandler;\r
+\r
+/**\r
+ * @author dt5972\r
+ *\r
+ */\r
+public class SvcLogicParser {\r
+\r
+    SvcLogicStore store = null;\r
+    static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";\r
+    static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";\r
+    static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";\r
+    static final String JAXP_DYNAMIC_VALIDATION = "http://apache.org/xml/features/validation/dynamic";\r
+    static final String JAXP_SCHEMA_VALIDATION = "http://apache.org/xml/features/validation/schema";\r
+\r
+    private static final String LOAD_MESSAGE = "Getting SvcLogicGraph from database - ";\r
+    private static final String LOAD_ERROR_MESSAGE = "SvcLogicGraph not found - ";\r
+    private static final String ACTIVATION_ERROR_MESSAGE = "Could not activate SvcLogicGraph - ";\r
+    private static final String PRINT_ERROR_MESSAGE = "Could not print SvcLogicGraph - ";\r
+    private static final String SVC_LOGIC_STORE_ERROR = "Could not get service logic store";\r
+\r
+    private static final Logger LOGGER = LoggerFactory.getLogger(SvcLogicParser.class);\r
+    private static final String SLI_VALIDATING_PARSER = "org.openecomp.sdnc.sli.parser.validate";\r
+    private static final String SVCLOGIC_XSD = "/svclogic.xsd";\r
+\r
+    private class SvcLogicHandler extends DefaultHandler {\r
+    private Locator locator = null;\r
+    private String module = null;\r
+    private String version = null;\r
+    private LinkedList<SvcLogicGraph> graphs = null;\r
+    private SvcLogicGraph curGraph = null;\r
+    private SvcLogicNode curNode = null;\r
+    private LinkedList<SvcLogicNode> nodeStack = null;\r
+    private int curNodeId = 0;\r
+    private String outcomeValue = null;\r
+    private LinkedList<String> outcomeStack = null;\r
+    private SvcLogicStore svcLogicStore = null;\r
+\r
+    public SvcLogicHandler(LinkedList<SvcLogicGraph> graphs, SvcLogicStore store) {\r
+        this.graphs = graphs;\r
+        this.curNode = null;\r
+        this.nodeStack = new LinkedList<>();\r
+        this.outcomeStack = new LinkedList<>();\r
+        this.curNodeId = 1;\r
+        this.outcomeValue = null;\r
+        this.svcLogicStore = store;\r
+\r
+    }\r
+\r
+    @Override\r
+       public void setDocumentLocator(Locator locator) {\r
+        this.locator = locator;\r
+    }\r
+\r
+    @Override\r
+    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {\r
+\r
+        // Handle service-logic (graph) tag\r
+        if ("service-logic".equalsIgnoreCase(qName)) {\r
+\r
+        module = attributes.getValue("module");\r
+        if (module == null || module.length() == 0) {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Missing 'module' attribute from service-logic tag");\r
+        }\r
+\r
+        version = attributes.getValue("version");\r
+        if (version == null || version.length() == 0) {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Missing 'version' attribute from service-logic tag");\r
+        }\r
+\r
+        return;\r
+        }\r
+\r
+        if ("method".equalsIgnoreCase(qName)) {\r
+        if (curGraph != null) {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Cannot nest module tags");\r
+        }\r
+        curGraph = new SvcLogicGraph();\r
+        curGraph.setModule(module);\r
+        curGraph.setVersion(version);\r
+        this.curNodeId = 1;\r
+\r
+        String attrValue = attributes.getValue("rpc");\r
+        if (attrValue == null || attrValue.length() == 0) {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Missing 'rpc' attribute for method tag");\r
+        }\r
+        curGraph.setRpc(attrValue);\r
+\r
+        attrValue = attributes.getValue("mode");\r
+        if (attrValue == null || attrValue.length() == 0) {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Missing 'mode' attribute for method tag");\r
+        }\r
+        curGraph.setMode(attrValue);\r
+\r
+        return;\r
+\r
+        }\r
+\r
+        // Handle outcome (edge) tag\r
+        if ("outcome".equalsIgnoreCase(qName)) {\r
+        String refValue = attributes.getValue("ref");\r
+\r
+        if (refValue != null) {\r
+            SvcLogicNode refNode = curGraph.getNamedNode(refValue);\r
+\r
+            if (refNode != null) {\r
+            try {\r
+                curNode.addOutcome(attributes.getValue("value"), refNode);\r
+            } catch (SvcLogicException e) {\r
+                throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Cannot add outcome", e);\r
+            }\r
+            } else {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "ref to unknown node " + refValue);\r
+            }\r
+            return;\r
+        }\r
+\r
+        if (outcomeValue != null) {\r
+            outcomeStack.push(outcomeValue);\r
+        }\r
+        outcomeValue = attributes.getValue("value");\r
+\r
+        return;\r
+        }\r
+\r
+        // Handle parameter tag\r
+        if ("parameter".equalsIgnoreCase(qName)) {\r
+        String parmName = attributes.getValue("name");\r
+        String parmValue = attributes.getValue("value");\r
+\r
+        if (parmName != null && parmName.length() > 0 && parmValue != null) {\r
+            try {\r
+\r
+            curNode.mapParameter(parmName, parmValue);\r
+            } catch (Exception e) {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + " cannot set parameter " + parmName + " to " + parmValue + " [" + e.getMessage() + "]");\r
+            }\r
+        }\r
+\r
+        return;\r
+        }\r
+\r
+        // Handle node tags\r
+\r
+        String nodeName = attributes.getValue("name");\r
+        SvcLogicNode thisNode = null;\r
+\r
+        try {\r
+        if (!svcLogicStore.isValidNodeType(qName)) {\r
+            throw new SAXNotRecognizedException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Unknown tag " + qName);\r
+        }\r
+        } catch (Exception e) {\r
+        throw new SAXNotRecognizedException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Cannot validate node type " + qName);\r
+        }\r
+\r
+        try {\r
+        if (nodeName != null && nodeName.length() > 0) {\r
+            thisNode = new SvcLogicNode(curNodeId++, qName, nodeName, curGraph);\r
+        } else {\r
+            thisNode = new SvcLogicNode(curNodeId++, qName, curGraph);\r
+        }\r
+\r
+        if (curGraph.getRootNode() == null) {\r
+            curGraph.setRootNode(thisNode);\r
+        }\r
+        } catch (SvcLogicException e) {\r
+        throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + e.getMessage());\r
+\r
+        }\r
+\r
+        int numAttributes = attributes.getLength();\r
+\r
+        for (int i = 0; i < numAttributes; i++) {\r
+        String attrName = attributes.getQName(i);\r
+        if (!"name".equalsIgnoreCase(attrName)) {\r
+            try {\r
+\r
+            String attrValueStr = attributes.getValue(i);\r
+            SvcLogicExpression attrValue = null;\r
+            if (attrValueStr.trim().startsWith("`")) {\r
+                int lastParen = attrValueStr.lastIndexOf("`");\r
+                String evalExpr = attrValueStr.trim().substring(1, lastParen);\r
+                attrValue = SvcLogicExpressionFactory.parse(evalExpr);\r
+\r
+            } else {\r
+                if (Character.isDigit(attrValueStr.charAt(0))) {\r
+                attrValue = new SvcLogicAtom("NUMBER", attrValueStr);\r
+                } else {\r
+                attrValue = new SvcLogicAtom("STRING", attrValueStr);\r
+                }\r
+            }\r
+            thisNode.setAttribute(attrName, attrValue);\r
+            } catch (Exception e) {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + "Cannot set attribute " + attrName, e);\r
+            }\r
+        }\r
+        }\r
+\r
+        if (curNode != null) {\r
+        try {\r
+            if ("block".equalsIgnoreCase(curNode.getNodeType()) || "for".equalsIgnoreCase(curNode.getNodeType()) || "while".equalsIgnoreCase(curNode.getNodeType())) {\r
+            curNode.addOutcome("" + (curNode.getNumOutcomes() + 1), thisNode);\r
+            } else {\r
+            if (outcomeValue == null) {\r
+                throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + curNode.getNodeType() + " node expects outcome, instead found " + thisNode.getNodeType());\r
+            }\r
+            curNode.addOutcome(outcomeValue, thisNode);\r
+            }\r
+        } catch (SvcLogicException e) {\r
+            throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + e.getMessage());\r
+        }\r
+        nodeStack.push(curNode);\r
+        }\r
+        curNode = thisNode;\r
+\r
+    }\r
+\r
+    @Override\r
+    public void endElement(String uri, String localName, String qName) throws SAXException {\r
+\r
+        // Handle close of service-logic tag\r
+        if ("service-logic".equalsIgnoreCase(qName)) {\r
+        // Nothing more to do\r
+        return;\r
+        }\r
+\r
+        // Handle close of method tag\r
+        if ("method".equalsIgnoreCase(qName)) {\r
+        graphs.add(curGraph);\r
+        curGraph = null;\r
+        return;\r
+        }\r
+\r
+        // Handle close of outcome tag\r
+        if ("outcome".equalsIgnoreCase(qName)) {\r
+        // Finished this outcome - pop the outcome stack\r
+        if (outcomeStack.isEmpty()) {\r
+            outcomeValue = null;\r
+        } else {\r
+            outcomeValue = outcomeStack.pop();\r
+        }\r
+        return;\r
+        }\r
+\r
+        // Handle close of parameter tag - do nothing\r
+        if ("parameter".equalsIgnoreCase(qName)) {\r
+        return;\r
+        }\r
+\r
+        // Handle close of a node tag\r
+        if (nodeStack.isEmpty()) {\r
+        curNode = null;\r
+        } else {\r
+        curNode = nodeStack.pop();\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void error(SAXParseException arg0) throws SAXException {\r
+        throw new SAXException("line " + locator.getLineNumber() + ":" + locator.getColumnNumber() + " " + arg0.getMessage());\r
+    }\r
+\r
+    }\r
+\r
+    public SvcLogicParser(SvcLogicStore store) {\r
+    this.store = store;\r
+    }\r
+\r
+    public SvcLogicParser(String propFile) {\r
+\r
+    try {\r
+        this.store = SvcLogicStoreFactory.getSvcLogicStore(propFile);\r
+    } catch (Exception e) {\r
+        LOGGER.error(SVC_LOGIC_STORE_ERROR, e);\r
+\r
+    }\r
+\r
+    }\r
+\r
+    public SvcLogicParser(InputStream propStr) {\r
+\r
+    try {\r
+        this.store = SvcLogicStoreFactory.getSvcLogicStore(propStr);\r
+    } catch (Exception e) {\r
+        LOGGER.error(SVC_LOGIC_STORE_ERROR, e);\r
+\r
+    }\r
+\r
+    }\r
+\r
+    public LinkedList<SvcLogicGraph> parse(String fileName) throws SvcLogicException {\r
+    LinkedList<SvcLogicGraph> graphs = null;\r
+\r
+    URL xsdUrl = null;\r
+    Schema schema = null;\r
+    String validateSchema = System.getProperty(SLI_VALIDATING_PARSER, "true");\r
+\r
+    if (validateSchema != null || validateSchema.equalsIgnoreCase("true")) {\r
+        xsdUrl = getClass().getResource(SVCLOGIC_XSD);\r
+\r
+    }\r
+\r
+    if (xsdUrl != null) {\r
+        try {\r
+        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\r
+        schema = schemaFactory.newSchema(xsdUrl);\r
+        } catch (Exception e) {\r
+        LOGGER.warn("Could not validate using schema " + xsdUrl.getPath(), e);\r
+        }\r
+    } else {\r
+        LOGGER.warn("Could not find resource " + SVCLOGIC_XSD);\r
+    }\r
+\r
+    try {\r
+        SAXParserFactory factory = SAXParserFactory.newInstance();\r
+\r
+        if (schema != null) {\r
+        factory.setNamespaceAware(true);\r
+        factory.setSchema(schema);\r
+        }\r
+        SAXParser saxParser = factory.newSAXParser();\r
+\r
+        if (saxParser.isValidating()) {\r
+        LOGGER.info("Validating against schema " + xsdUrl.getPath());\r
+        }\r
+        graphs = new LinkedList<>();\r
+\r
+        saxParser.parse(fileName, new SvcLogicHandler(graphs, store));\r
+\r
+    } catch (Exception e) {\r
+        String msg = e.getMessage();\r
+        if (msg != null) {\r
+        LOGGER.error(msg);\r
+        throw new SvcLogicException("Compiler error: " + fileName + " @ " + msg);\r
+        } else {\r
+        LOGGER.info("Caught exception parsing " + fileName, e);\r
+        throw new SvcLogicException("Compiler error: " + fileName, e);\r
+        }\r
+    }\r
+\r
+    return graphs;\r
+    }\r
+\r
+    public static void main(String argv[]) {\r
+\r
+    if (argv.length == 0) {\r
+        SvcLogicParser.usage();\r
+    }\r
+\r
+    if ("load".equalsIgnoreCase(argv[0])) {\r
+        if (argv.length == 3) {\r
+        String xmlfile = argv[1];\r
+        String propfile = argv[2];\r
+\r
+        SvcLogicStore store = SvcLogicParser.getStore(propfile);\r
+        try {\r
+            SvcLogicParser.load(xmlfile, store);\r
+        } catch (Exception e) {\r
+            LOGGER.error(e.getMessage(), e);\r
+        }\r
+        } else {\r
+        SvcLogicParser.usage();\r
+        }\r
+    } else if ("print".equalsIgnoreCase(argv[0])) {\r
+        String version = null;\r
+        String propfile = null;\r
+\r
+        switch (argv.length) {\r
+        case 6:\r
+        version = argv[4];\r
+        propfile = argv[5];\r
+        case 5:\r
+        if (propfile == null) {\r
+            propfile = argv[4];\r
+        }\r
+        SvcLogicStore store = SvcLogicParser.getStore(propfile);\r
+        SvcLogicParser.print(argv[1], argv[2], argv[3], version, store);\r
+        break;\r
+        default:\r
+        SvcLogicParser.usage();\r
+        }\r
+    } else if ("get-source".equalsIgnoreCase(argv[0])) {\r
+\r
+        switch (argv.length) {\r
+        case 6:\r
+        SvcLogicStore store = SvcLogicParser.getStore(argv[5]);\r
+        SvcLogicParser.getSource(argv[1], argv[2], argv[3], argv[4], store);\r
+        break;\r
+        default:\r
+        SvcLogicParser.usage();\r
+        }\r
+    } else if ("activate".equalsIgnoreCase(argv[0])) {\r
+        if (argv.length == 6) {\r
+        SvcLogicStore store = SvcLogicParser.getStore(argv[5]);\r
+        SvcLogicParser.activate(argv[1], argv[2], argv[3], argv[4], store);\r
+        } else {\r
+        SvcLogicParser.usage();\r
+        }\r
+    } else if ("validate".equalsIgnoreCase(argv[0])) {\r
+        if (argv.length == 3) {\r
+        String xmlfile = argv[1];\r
+        String propfile = argv[2];\r
+\r
+        System.setProperty(SLI_VALIDATING_PARSER, "true");\r
+        SvcLogicStore store = SvcLogicParser.getStore(propfile);\r
+        try {\r
+            SvcLogicParser.validate(xmlfile, store);\r
+        } catch (Exception e) {\r
+            LOGGER.error(e.getMessage(), e);\r
+        }\r
+        } else {\r
+        SvcLogicParser.usage();\r
+        }\r
+    }\r
+\r
+    System.exit(0);\r
+    }\r
+\r
+    private static SvcLogicStore getStore(String propfile) {\r
+\r
+    SvcLogicStore store = null;\r
+\r
+    try {\r
+        store = SvcLogicStoreFactory.getSvcLogicStore(propfile);\r
+    } catch (Exception e) {\r
+        LOGGER.error(SVC_LOGIC_STORE_ERROR, e);\r
+        System.exit(1);\r
+    }\r
+\r
+    return store;\r
+\r
+    }\r
+\r
+    public static void load(String xmlfile, SvcLogicStore store) throws SvcLogicException {\r
+    File xmlFile = new File(xmlfile);\r
+    if (!xmlFile.canRead()) {\r
+        throw new ConfigurationException("Cannot read xml file (" + xmlfile + ")");\r
+    }\r
+\r
+    SvcLogicParser parser = new SvcLogicParser(store);\r
+    LinkedList<SvcLogicGraph> graphs = null;\r
+    try {\r
+        graphs = parser.parse(xmlfile);\r
+    } catch (Exception e) {\r
+        throw new SvcLogicException(e.getMessage(), e);\r
+    }\r
+\r
+    if (graphs == null) {\r
+        throw new SvcLogicException("Could not parse " + xmlfile);\r
+    }\r
+\r
+    for (SvcLogicGraph graph : graphs) {\r
+\r
+        String module = graph.getModule();\r
+        String rpc = graph.getRpc();\r
+        String version = graph.getVersion();\r
+        String mode = graph.getMode();\r
+        try {\r
+        LOGGER.info("Saving SvcLogicGraph to database (module:" + module + ",rpc:" + rpc + ",version:" + version + ",mode:" + mode + ")");\r
+        store.store(graph);\r
+        } catch (Exception e) {\r
+        throw new SvcLogicException(e.getMessage(), e);\r
+        }\r
+\r
+    }\r
+\r
+    }\r
+\r
+    public static void validate(String xmlfile, SvcLogicStore store) throws SvcLogicException {\r
+    File xmlFile = new File(xmlfile);\r
+    if (!xmlFile.canRead()) {\r
+        throw new ConfigurationException("Cannot read xml file (" + xmlfile + ")");\r
+    }\r
+\r
+    SvcLogicParser parser = new SvcLogicParser(store);\r
+    LinkedList<SvcLogicGraph> graphs = null;\r
+    try {\r
+        LOGGER.info("Validating " + xmlfile);\r
+        graphs = parser.parse(xmlfile);\r
+    } catch (Exception e) {\r
+        throw new SvcLogicException(e.getMessage(), e);\r
+    }\r
+\r
+    if (graphs == null) {\r
+        throw new SvcLogicException("Could not parse " + xmlfile);\r
+    } else {\r
+        LOGGER.info("Compilation successful for " + xmlfile);\r
+    }\r
+\r
+    }\r
+\r
+    private static void print(String module, String rpc, String mode, String version, SvcLogicStore store) {\r
+    String details = "(module:" + module + ", rpc:" + rpc + ", version:" + version + ", mode:" + mode + ")";\r
+\r
+    try {\r
+        LOGGER.info(LOAD_MESSAGE + details);\r
+\r
+        SvcLogicGraph graph = store.fetch(module, rpc, version, mode);\r
+        if (graph == null) {\r
+        LOGGER.error(LOAD_ERROR_MESSAGE + details);\r
+        System.exit(1);\r
+        }\r
+        graph.printAsGv(System.out);\r
+    } catch (Exception e) {\r
+        LOGGER.error(PRINT_ERROR_MESSAGE + details, e);\r
+        System.exit(1);\r
+    }\r
+\r
+    }\r
+\r
+    private static void getSource(String module, String rpc, String mode, String version, SvcLogicStore store) {\r
+    String details = "(module:" + module + ", rpc:" + rpc + ", version:" + version + ", mode:" + mode + ")";\r
+\r
+    try {\r
+        LOGGER.info(LOAD_MESSAGE + details);\r
+\r
+        SvcLogicGraph graph = store.fetch(module, rpc, version, mode);\r
+        if (graph == null) {\r
+        LOGGER.error(LOAD_ERROR_MESSAGE + details);\r
+        System.exit(1);\r
+        }\r
+        graph.printAsXml(System.out);\r
+    } catch (Exception e) {\r
+        LOGGER.error(PRINT_ERROR_MESSAGE + details, e);\r
+        System.exit(1);\r
+    }\r
+\r
+    }\r
+\r
+    private static void activate(String module, String rpc, String version, String mode, SvcLogicStore store) {\r
+    String details = "(module:" + module + ", rpc:" + rpc + ", version:" + version + ", mode:" + mode + ")";\r
+\r
+    try {\r
+        LOGGER.info(LOAD_MESSAGE + details);\r
+\r
+        SvcLogicGraph graph = store.fetch(module, rpc, version, mode);\r
+        if (graph == null) {\r
+        LOGGER.error(LOAD_ERROR_MESSAGE + details);\r
+        System.exit(1);\r
+        }\r
+        store.activate(graph);\r
+    } catch (Exception e) {\r
+        LOGGER.error(ACTIVATION_ERROR_MESSAGE + details, e);\r
+        System.exit(1);\r
+    }\r
+\r
+    }\r
+\r
+    private static void usage() {\r
+    System.err.println("Usage: SvcLogicParser load <xml-file> <prop-file>");\r
+    System.err.println(" OR    SvcLogicParser print <module> <rpc> <mode> [<version>] <prop-file>");\r
+    System.err.println(" OR    SvcLogicParser get-source <module> <rpc> <mode> <version> <prop-file>");\r
+    System.err.println(" OR    SvcLogicParser activate <module> <rpc> <version> <mode>");\r
+    System.exit(1);\r
+    }\r
+\r
+}\r
index 0743089..f74bd5d 100755 (executable)
@@ -30,6 +30,7 @@
                        <xsd:element ref="call" />\r
                        <xsd:element ref="notify" />\r
                        <xsd:element ref="break" />\r
+                       <xsd:element ref="while" />\r
                </xsd:choice>\r
        </xsd:group>\r
 \r
                <xsd:complexType />\r
        </xsd:element>\r
 \r
+       <xsd:element name="while">\r
+               <xsd:complexType>\r
+                       <xsd:sequence>\r
+                               <xsd:group ref="node" minOccurs="0" maxOccurs="unbounded" />\r
+                       </xsd:sequence>\r
+                       <xsd:attribute name="test" use="required" type="xsd:string" />\r
+                       <xsd:attribute name="do" use="optional" type="xsd:boolean" />\r
+               </xsd:complexType>\r
+       </xsd:element>\r
+\r
 </xsd:schema>\r
index b6fa374..a500b6f 100644 (file)
@@ -78,16 +78,7 @@ public class CallNodeExecutor extends SvcLogicNodeExecutor {
                {
                        rpc  = SvcLogicExpressionResolver.evaluate(rpcExpr, node, ctx);
                }
-               
-               if ((rpc == null) || (rpc.length() == 0))
-               {
-                       if (myGraph != null)
-                       {
-                               rpc = myGraph.getRpc();
-                               LOG.debug("myGraph.getRpc() returned "+rpc);
-                       }
-               }
-               
+
                String mode = null;
                
                moduleExpr = node.getAttribute("mode");
@@ -122,8 +113,8 @@ public class CallNodeExecutor extends SvcLogicNodeExecutor {
         if (store != null) {
             SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode);
             if (calledGraph != null) {
-                LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString());
                 svc.execute(calledGraph, ctx);
+                LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString());
                 ctx.setAttribute("currentGraph", calledGraph.toString());
                 outValue = ctx.getStatus();
             } else {
index 691ad40..8996095 100644 (file)
-/*-
+/*-\r
  * ============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
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
  * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdnc.sli.provider;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Properties;
-
-import org.openecomp.sdnc.sli.ConfigurationException;
-import org.openecomp.sdnc.sli.SvcLogicAdaptor;
-import org.openecomp.sdnc.sli.SvcLogicException;
-import org.openecomp.sdnc.sli.SvcLogicStore;
-import org.openecomp.sdnc.sli.SvcLogicStoreFactory;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.mysql.jdbc.Driver;
-
-public class SvcLogicActivator implements BundleActivator {
-
-       private static final String SVCLOGIC_PROP_VAR = "SDNC_SLI_PROPERTIES";
-       private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
-
-       private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() {
-               {
-                       put("block", new BlockNodeExecutor());
-                       put("call", new CallNodeExecutor());
-                       put("configure", new ConfigureNodeExecutor());
-                       put("delete", new DeleteNodeExecutor());
-                       put("execute", new ExecuteNodeExecutor());
-                       put("exists", new ExistsNodeExecutor());
-                       put("for", new ForNodeExecutor());
-                       put("get-resource", new GetResourceNodeExecutor());
-                       put("is-available", new IsAvailableNodeExecutor());
-                       put("notify", new NotifyNodeExecutor());
-                       put("record", new RecordNodeExecutor());
-                       put("release", new ReleaseNodeExecutor());
-                       put("reserve", new ReserveNodeExecutor());
-                       put("return", new ReturnNodeExecutor());
-                       put("save", new SaveNodeExecutor());
-                       put("set", new SetNodeExecutor());
-                       put("switch", new SwitchNodeExecutor());
-                       put("update", new UpdateNodeExecutor());
-            put("break", new BreakNodeExecutor());
-
-               }
-       };
-
-       private static LinkedList<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
-
-       private static HashMap<String, SvcLogicAdaptor> adaptorMap = null;
-       
-       private static final Logger LOG = LoggerFactory
-                       .getLogger(SvcLogicActivator.class);
-       
-       private static Properties props = null;
-
-       private static BundleContext bundleCtx = null;
-       
-       private static SvcLogicService svcLogicServiceImpl = null;
-       
-       @Override
-       public void start(BundleContext ctx) throws Exception {
-
-               LOG.info("Activating SLI");
-               
-               bundleCtx = ctx;
-
-               // Read properties
-               props = new Properties();
-               String propPath = System.getenv(SVCLOGIC_PROP_VAR);
-               
-               if (propPath == null) {
-                       String propDir = System.getenv(SDNC_CONFIG_DIR);
-                       if (propDir == null) {
-                               
-                               propDir = "/opt/sdnc/data/properties";
-                       }
-                       propPath = propDir + "/svclogic.properties";
-                       LOG.warn("Environment variable "+SVCLOGIC_PROP_VAR+" unset - defaulting to "+propPath);
-               }
-               
-               File propFile = new File(propPath);
-               
-               if (!propFile.exists()) {
-                       
-                       throw new ConfigurationException(
-                                       "Missing configuration properties file : "
-                                                       + propFile);
-               }
-               try {
-                       
-                       props.load(new FileInputStream(propFile));
-               } catch (Exception e) {
-                       throw new ConfigurationException(
-                                       "Could not load properties file " + propPath, e);
-
-               }
-
-
-               if (registrations == null) {
-
-                       registrations = new LinkedList<ServiceRegistration>();
-               }
-
-               // Advertise SvcLogicService
-               svcLogicServiceImpl = new SvcLogicServiceImpl();
-
-               LOG.info("SLI: Registering service " + SvcLogicService.NAME
-                               + " in bundle " + ctx.getBundle().getSymbolicName());
-               ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME,
-                               svcLogicServiceImpl, null);
-               registrations.add(reg);
-
-               // Initialize SvcLogicStore
-               try {
-                       SvcLogicStore store = getStore();
-                       registerNodeTypes(store);
-               } catch (ConfigurationException e) {
-                       LOG.warn("Could not initialize SvcLogicScore", e);
-               }
-
-               LOG.info("SLI - done registering services");
-       }
-
-       @Override
-       public void stop(BundleContext ctx) throws Exception {
-
-               if (registrations != null) {
-                       for (ServiceRegistration reg : registrations) {
-                               ServiceReference regRef = reg.getReference();
-                               /* Don't bother to remove node types from table
-                               String nodeType = (String) regRef.getProperty("nodeType");
-                               if (nodeType != null) {
-                                       LOG.info("SLI - unregistering node type " + nodeType);
-                                       store.unregisterNodeType(nodeType);
-                               }
-                               */
-                               reg.unregister();
-                       }
-                       registrations = null;
-               }
-       }
-       
-       public static SvcLogicStore getStore() throws SvcLogicException {
-               // Create and initialize SvcLogicStore object - used to access
-               // saved service logic.
-               
-               SvcLogicStore store = null;
-               
-               try {
-                       Driver dvr = new Driver();
-                       store = SvcLogicStoreFactory.getSvcLogicStore(props);
-               } catch (Exception e) {
-                       throw new ConfigurationException(
-                                       "Could not get service logic store", e);
-
-               }
-
-               try {
-                       store.init(props);
-               } catch (Exception e) {
-                       throw new ConfigurationException(
-                                       "Could not get service logic store", e);
-               }
-               
-               return(store);
-       }
-       
-       private static void registerNodeTypes(SvcLogicStore store) throws SvcLogicException {
-               
-               if (store == null) {
-                       return;
-               }
-               // Advertise built-in node executors
-               LOG.info("SLI : Registering built-in node executors");
-               Hashtable propTable = new Hashtable();
-
-               for (String nodeType : BUILTIN_NODES.keySet()) {
-                       LOG.info("SLI - registering node type " + nodeType);
-                       propTable.clear();
-                       propTable.put("nodeType", nodeType);
-
-                       ServiceRegistration reg = bundleCtx.registerService(SvcLogicNodeExecutor.class.getName(),
-                                       BUILTIN_NODES.get(nodeType), propTable);
-                       registrations.add(reg);
-
-                       store.registerNodeType(nodeType);
-                       
-                       LOG.info("SLI - registering node executor");
-                       
-                       ((SvcLogicServiceImpl)svcLogicServiceImpl).registerExecutor(nodeType, BUILTIN_NODES.get(nodeType));
-
-               }
-               
-       }
-
-}
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.sdnc.sli.provider;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.net.URL;\r
+import java.util.HashMap;\r
+import java.util.Hashtable;\r
+import java.util.LinkedList;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
+import org.openecomp.sdnc.sli.ConfigurationException;\r
+import org.openecomp.sdnc.sli.SvcLogicAdaptor;\r
+import org.openecomp.sdnc.sli.SvcLogicException;\r
+import org.openecomp.sdnc.sli.SvcLogicStore;\r
+import org.openecomp.sdnc.sli.SvcLogicStoreFactory;\r
+import org.osgi.framework.BundleActivator;\r
+import org.osgi.framework.BundleContext;\r
+import org.osgi.framework.ServiceReference;\r
+import org.osgi.framework.ServiceRegistration;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import com.mysql.jdbc.Driver;\r
+\r
+public class SvcLogicActivator implements BundleActivator {\r
+\r
+       private static final String SVCLOGIC_PROP_VAR = "SDNC_SLI_PROPERTIES";\r
+       private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";\r
+\r
+       private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() {\r
+               {\r
+                       put("block", new BlockNodeExecutor());\r
+                       put("call", new CallNodeExecutor());\r
+                       put("configure", new ConfigureNodeExecutor());\r
+                       put("delete", new DeleteNodeExecutor());\r
+                       put("execute", new ExecuteNodeExecutor());\r
+                       put("exists", new ExistsNodeExecutor());\r
+                       put("for", new ForNodeExecutor());\r
+                       put("get-resource", new GetResourceNodeExecutor());\r
+                       put("is-available", new IsAvailableNodeExecutor());\r
+                       put("notify", new NotifyNodeExecutor());\r
+                       put("record", new RecordNodeExecutor());\r
+                       put("release", new ReleaseNodeExecutor());\r
+                       put("reserve", new ReserveNodeExecutor());\r
+                       put("return", new ReturnNodeExecutor());\r
+                       put("save", new SaveNodeExecutor());\r
+                       put("set", new SetNodeExecutor());\r
+                       put("switch", new SwitchNodeExecutor());\r
+                       put("update", new UpdateNodeExecutor());\r
+            put("break", new BreakNodeExecutor());\r
+            put("while", new WhileNodeExecutor());\r
+               }\r
+       };\r
+\r
+       private static LinkedList<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();\r
+\r
+       private static HashMap<String, SvcLogicAdaptor> adaptorMap = null;\r
+       \r
+       private static final Logger LOG = LoggerFactory\r
+                       .getLogger(SvcLogicActivator.class);\r
+       \r
+       private static Properties props = null;\r
+\r
+       private static BundleContext bundleCtx = null;\r
+       \r
+       private static SvcLogicService svcLogicServiceImpl = null;\r
+       \r
+       @Override\r
+       public void start(BundleContext ctx) throws Exception {\r
+\r
+               LOG.info("Activating SLI");\r
+               \r
+               bundleCtx = ctx;\r
+\r
+               // Read properties\r
+               props = new Properties();\r
+               String propPath = System.getenv(SVCLOGIC_PROP_VAR);\r
+               \r
+               if (propPath == null) {\r
+                       String propDir = System.getenv(SDNC_CONFIG_DIR);\r
+                       if (propDir == null) {\r
+                               \r
+                               propDir = "/opt/sdnc/data/properties";\r
+                       }\r
+                       propPath = propDir + "/svclogic.properties";\r
+                       LOG.warn("Environment variable "+SVCLOGIC_PROP_VAR+" unset - defaulting to "+propPath);\r
+               }\r
+               \r
+               File propFile = new File(propPath);\r
+               \r
+               if (!propFile.exists()) {\r
+                       \r
+                       throw new ConfigurationException(\r
+                                       "Missing configuration properties file : "\r
+                                                       + propFile);\r
+               }\r
+               try {\r
+                       \r
+                       props.load(new FileInputStream(propFile));\r
+               } catch (Exception e) {\r
+                       throw new ConfigurationException(\r
+                                       "Could not load properties file " + propPath, e);\r
+\r
+               }\r
+\r
+\r
+               if (registrations == null) {\r
+\r
+                       registrations = new LinkedList<ServiceRegistration>();\r
+               }\r
+\r
+               // Advertise SvcLogicService\r
+               svcLogicServiceImpl = new SvcLogicServiceImpl();\r
+\r
+               LOG.info("SLI: Registering service " + SvcLogicService.NAME\r
+                               + " in bundle " + ctx.getBundle().getSymbolicName());\r
+               ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME,\r
+                               svcLogicServiceImpl, null);\r
+               registrations.add(reg);\r
+\r
+               // Initialize SvcLogicStore\r
+               try {\r
+                       SvcLogicStore store = getStore();\r
+                       registerNodeTypes(store);\r
+               } catch (ConfigurationException e) {\r
+                       LOG.warn("Could not initialize SvcLogicScore", e);\r
+               }\r
+\r
+               LOG.info("SLI - done registering services");\r
+       }\r
+\r
+       @Override\r
+       public void stop(BundleContext ctx) throws Exception {\r
+\r
+               if (registrations != null) {\r
+                       for (ServiceRegistration reg : registrations) {\r
+                               ServiceReference regRef = reg.getReference();\r
+                               /* Don't bother to remove node types from table\r
+                               String nodeType = (String) regRef.getProperty("nodeType");\r
+                               if (nodeType != null) {\r
+                                       LOG.info("SLI - unregistering node type " + nodeType);\r
+                                       store.unregisterNodeType(nodeType);\r
+                               }\r
+                               */\r
+                               reg.unregister();\r
+                       }\r
+                       registrations = null;\r
+               }\r
+       }\r
+       \r
+       public static SvcLogicStore getStore() throws SvcLogicException {\r
+               // Create and initialize SvcLogicStore object - used to access\r
+               // saved service logic.\r
+               \r
+               SvcLogicStore store = null;\r
+               \r
+               try {\r
+                       Driver dvr = new Driver();\r
+                       store = SvcLogicStoreFactory.getSvcLogicStore(props);\r
+               } catch (Exception e) {\r
+                       throw new ConfigurationException(\r
+                                       "Could not get service logic store", e);\r
+\r
+               }\r
+\r
+               try {\r
+                       store.init(props);\r
+               } catch (Exception e) {\r
+                       throw new ConfigurationException(\r
+                                       "Could not get service logic store", e);\r
+               }\r
+               \r
+               return(store);\r
+       }\r
+       \r
+       private static void registerNodeTypes(SvcLogicStore store) throws SvcLogicException {\r
+               \r
+               if (store == null) {\r
+                       return;\r
+               }\r
+               // Advertise built-in node executors\r
+               LOG.info("SLI : Registering built-in node executors");\r
+               Hashtable propTable = new Hashtable();\r
+\r
+               for (String nodeType : BUILTIN_NODES.keySet()) {\r
+                       LOG.info("SLI - registering node type " + nodeType);\r
+                       propTable.clear();\r
+                       propTable.put("nodeType", nodeType);\r
+\r
+                       ServiceRegistration reg = bundleCtx.registerService(SvcLogicNodeExecutor.class.getName(),\r
+                                       BUILTIN_NODES.get(nodeType), propTable);\r
+                       registrations.add(reg);\r
+\r
+                       store.registerNodeType(nodeType);\r
+                       \r
+                       LOG.info("SLI - registering node executor");\r
+                       \r
+                       ((SvcLogicServiceImpl)svcLogicServiceImpl).registerExecutor(nodeType, BUILTIN_NODES.get(nodeType));\r
+\r
+               }\r
+               \r
+       }\r
+\r
+}\r
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/WhileNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/WhileNodeExecutor.java
new file mode 100644 (file)
index 0000000..7ec36e1
--- /dev/null
@@ -0,0 +1,76 @@
+/*-\r
+ * ============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");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.sdnc.sli.provider;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import org.openecomp.sdnc.sli.BreakNodeException;\r
+import org.openecomp.sdnc.sli.SvcLogicContext;\r
+import org.openecomp.sdnc.sli.SvcLogicException;\r
+import org.openecomp.sdnc.sli.SvcLogicExpression;\r
+import org.openecomp.sdnc.sli.SvcLogicNode;\r
+\r
+public class WhileNodeExecutor extends SvcLogicNodeExecutor {\r
+\r
+    private static final Logger LOG = LoggerFactory.getLogger(WhileNodeExecutor.class);\r
+\r
+    @Override\r
+    public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException {\r
+\r
+        String testResult = evaluateNodeTest(node, ctx);\r
+        SvcLogicExpression silentFailureExpr = node.getAttribute("do");\r
+        String doWhile = SvcLogicExpressionResolver.evaluate(silentFailureExpr, node, ctx);\r
+        if ("true".equals(doWhile)) {\r
+            LOG.debug("While loop will execute once regardless of expression because do is set to true");\r
+        }\r
+\r
+        try {\r
+            while ("true".equals(testResult) || "true".equals(doWhile)) {\r
+                if (!"true".equals(doWhile)) {\r
+                    LOG.debug("Test expression (" + node.getAttribute("test") + ") evaluates to true, executing loop.");\r
+                }\r
+                int numOutcomes = node.getNumOutcomes() + 1;\r
+                for (int i = 0; i < numOutcomes; i++) {\r
+                    SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1));\r
+                    if (nextNode != null) {\r
+                        while (nextNode != null) {\r
+                            nextNode = svc.executeNode(nextNode, ctx);\r
+                        }\r
+                    } else {\r
+                        if ("true".equals(doWhile)) {\r
+                            LOG.debug("Do executed, will only execute again if test expression is true.");\r
+                            doWhile = "false";\r
+                        }\r
+                        testResult = evaluateNodeTest(node, ctx);\r
+                        LOG.debug("test expression (" + node.getAttribute("test") + ") evaluates to " + testResult);\r
+                    }\r
+                }\r
+            }\r
+            LOG.debug("testResult was " + testResult + " which is not equal to true, exiting while loop.");\r
+        } catch (BreakNodeException e) {\r
+            LOG.debug("WhileNodeExecutor caught break");\r
+        }\r
+        return (null);\r
+    }\r
+\r
+}\r
index 0acaf5f..3961271 100644 (file)
@@ -88,6 +88,7 @@ public class DME2 implements SvcLogicJavaPlugin {
         if (this.partner != null) {
             sb.append("&dme2.partner=" + this.partner);
         }
+        sb.append("&dme2.allowhttpcode=true");
         return (sb.toString());
     }