From: Sharon Aicler Date: Thu, 19 Mar 2015 17:51:59 +0000 (-0700) Subject: Fix bug bug 2651 - XSQL does not pickup augmentation data X-Git-Tag: release/lithium~311^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=204d8517566d7f4964e5c5e4060e075543e46b52;hp=-c Fix bug bug 2651 - XSQL does not pickup augmentation data Change-Id: I350de6ccf5efd8e427c5823a0f03c91e0df33f19 Signed-off-by: Sharon Aicler --- 204d8517566d7f4964e5c5e4060e075543e46b52 diff --git a/opendaylight/md-sal/sal-dom-xsql-config/src/main/resources/04-xsql.xml b/opendaylight/md-sal/sal-dom-xsql-config/src/main/resources/04-xsql.xml index d7d547d19e..1b9a37df66 100644 --- a/opendaylight/md-sal/sal-dom-xsql-config/src/main/resources/04-xsql.xml +++ b/opendaylight/md-sal/sal-dom-xsql-config/src/main/resources/04-xsql.xml @@ -8,8 +8,8 @@ XSQL - binding:binding-data-broker - binding-data-broker + binding:binding-async-data-broker + binding-data-broker dom:dom-async-data-broker diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/odl/xsql/JDBCDriver.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/odl/xsql/JDBCDriver.java index cc92b48a15..2cb2e7bfb5 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/odl/xsql/JDBCDriver.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/odl/xsql/JDBCDriver.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.odl.xsql; import java.sql.Connection; @@ -10,7 +17,9 @@ import java.util.Properties; import java.util.logging.Logger; import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCConnection; - +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ public class JDBCDriver implements Driver { public static JDBCDriver drv = new JDBCDriver(); diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/TablesResultSet.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/TablesResultSet.java index 2f28052758..938d25ec50 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/TablesResultSet.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/TablesResultSet.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.xsql; import java.io.InputStream; @@ -21,7 +28,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; import java.util.Map; - +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ public class TablesResultSet implements ResultSet { private String tables[] = null; diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLAdapter.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLAdapter.java index a5658ccc9e..05f65225ea 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLAdapter.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLAdapter.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.xsql; import java.io.File; @@ -24,7 +31,9 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; - +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ public class XSQLAdapter extends Thread implements SchemaContextListener { private static final int SLEEP = 10000; @@ -51,6 +60,7 @@ public class XSQLAdapter extends Thread implements SchemaContextListener { private String pinningFile; private ServerSocket serverSocket = null; private DOMDataBroker domDataBroker = null; + private static final String REFERENCE_FIELD_NAME = "reference"; private XSQLAdapter() { XSQLAdapter.log("Starting Adapter"); @@ -152,28 +162,18 @@ public class XSQLAdapter extends Thread implements SchemaContextListener { List result = new LinkedList(); YangInstanceIdentifier instanceIdentifier = YangInstanceIdentifier .builder() - .node(XSQLODLUtils.getPath(table.getODLNode()).get(0)) + .node(XSQLODLUtils.getPath(table.getFirstFromSchemaNodes()).get(0)) .toInstance(); DOMDataReadTransaction t = this.domDataBroker .newReadOnlyTransaction(); Object node = t.read(type, instanceIdentifier).get(); - node = XSQLODLUtils.get(node, "reference"); + node = XSQLODLUtils.get(node, REFERENCE_FIELD_NAME); if (node == null) { return result; } - - Map children = XSQLODLUtils.getChildren(node); - for (Object c : children.values()) { - result.add(c); - /* I don't remember why i did this... possibly to prevent different siblings queried together - Map sons = XSQLODLUtils.getChildren(c); - for (Object child : sons.values()) { - result.add(child); - }*/ - } - + result.add(node); return result; } catch (Exception err) { XSQLAdapter.log(err); diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java index a9c0f69fc6..76152966d0 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.xsql; import java.io.DataInputStream; @@ -23,7 +30,9 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; - +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ public class XSQLBluePrint implements DatabaseMetaData, Serializable { private static final long serialVersionUID = 1L; @@ -203,15 +212,23 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { return result; } - public void addToBluePrintCache(XSQLBluePrintNode blNode) { - this.tableNameToBluePrint.put(blNode.getBluePrintNodeName(), blNode); - Map map = this.odlNameToBluePrint.get(blNode - .getODLTableName()); - if (map == null) { - map = new HashMap(); - this.odlNameToBluePrint.put(blNode.getODLTableName(), map); + public XSQLBluePrintNode addToBluePrintCache(XSQLBluePrintNode blNode,XSQLBluePrintNode parent) { + XSQLBluePrintNode existingNode = this.tableNameToBluePrint.get(blNode.getBluePrintNodeName()); + if(existingNode!=null){ + existingNode.mergeAugmentation(blNode); + return existingNode; + }else{ + this.tableNameToBluePrint.put(blNode.getBluePrintNodeName(), blNode); + Map map = this.odlNameToBluePrint.get(blNode.getODLTableName()); + if (map == null) { + map = new HashMap(); + this.odlNameToBluePrint.put(blNode.getODLTableName(), map); + } + map.put(blNode.getBluePrintNodeName(), blNode); + if(parent!=null) + parent.addChild(blNode); + return blNode; } - map.put(blNode.getBluePrintNodeName(), blNode); } public Class getGenericType(ParameterizedType type) { diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintNode.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintNode.java index 4a56545238..d3cd91a6bd 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintNode.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintNode.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.xsql; import java.io.Serializable; @@ -8,6 +15,9 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ public class XSQLBluePrintNode implements Serializable { private static final long serialVersionUID = 1L; @@ -24,12 +34,25 @@ public class XSQLBluePrintNode implements Serializable { private Set columns = new HashSet(); private Map origNameToColumn = new HashMap(); - private transient Object odlNode = null; + private transient Object[] odlSchemaNodes = null; private boolean module = false; private String bluePrintTableName = null; private String odlTableName = null; private String origName = null; + public void mergeAugmentation(XSQLBluePrintNode aug) { + this.relations.addAll(aug.relations); + this.inheritingNodes.addAll(aug.inheritingNodes); + this.children.addAll(aug.children); + this.columns.addAll(aug.columns); + this.origNameToColumn.putAll(aug.origNameToColumn); + if (aug.odlSchemaNodes != null) { + for (Object sn : aug.odlSchemaNodes) { + addToSchemaNodes(sn); + } + } + } + public XSQLBluePrintNode(String name, String _origName, int _level) { this.level = _level; this.odlTableName = name; @@ -46,12 +69,32 @@ public class XSQLBluePrintNode implements Serializable { public XSQLBluePrintNode(Object _odlNode, int _level, XSQLBluePrintNode _parent) { - this.odlNode = _odlNode; + addToSchemaNodes(_odlNode); this.level = _level; this.module = XSQLODLUtils.isModule(_odlNode); this.parent = _parent; this.bluePrintTableName = XSQLODLUtils.getBluePrintName(_odlNode); - this.odlTableName = XSQLODLUtils.getODLNodeName(this.odlNode); + this.odlTableName = XSQLODLUtils + .getODLNodeName(getFirstFromSchemaNodes()); + } + + private void addToSchemaNodes(Object schemaObject) { + if (this.odlSchemaNodes == null) + this.odlSchemaNodes = new Object[1]; + else { + Object[] temp = new Object[this.odlSchemaNodes.length + 1]; + System.arraycopy(this.odlSchemaNodes, 0, temp, 0, + this.odlSchemaNodes.length); + this.odlSchemaNodes = temp; + } + this.odlSchemaNodes[this.odlSchemaNodes.length - 1] = schemaObject; + } + + public Object getFirstFromSchemaNodes() { + if (this.odlSchemaNodes == null) { + return null; + } + return this.odlSchemaNodes[0]; } public String getOrigName() { @@ -72,16 +115,13 @@ public class XSQLBluePrintNode implements Serializable { public String getODLTableName() { if (this.odlTableName == null) { - this.odlTableName = XSQLODLUtils.getODLNodeName(this.odlNode); + this.odlTableName = XSQLODLUtils + .getODLNodeName(getFirstFromSchemaNodes()); } return this.odlTableName; } - public Object getODLNode() { - return this.odlNode; - } - - public void AddChild(XSQLBluePrintNode ch) { + public void addChild(XSQLBluePrintNode ch) { this.children.add(ch); } @@ -218,7 +258,7 @@ public class XSQLBluePrintNode implements Serializable { if (myInterfaceName != null) { return myInterfaceName; } - if (odlNode != null) { + if (this.odlSchemaNodes != null) { return getBluePrintNodeName(); } if (odlTableName != null) { @@ -238,15 +278,14 @@ public class XSQLBluePrintNode implements Serializable { @Override public boolean equals(Object obj) { XSQLBluePrintNode other = (XSQLBluePrintNode) obj; - if (odlNode != null) { + if (this.odlSchemaNodes != null) { return getBluePrintNodeName().equals(other.getBluePrintNodeName()); } else if (this.odlTableName == null && other.odlTableName != null) { return false; } if (this.odlTableName != null && other.odlTableName == null) { return false; - } - else { + } else { return this.odlTableName.equals(other.odlTableName); } } @@ -255,7 +294,7 @@ public class XSQLBluePrintNode implements Serializable { public int hashCode() { if (myInterfaceString != null) { return myInterfaceString.hashCode(); - } else if (odlNode != null) { + } else if (this.odlSchemaNodes != null) { return bluePrintTableName.hashCode(); } return 0; diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLODLUtils.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLODLUtils.java index 17b8ae5f29..16a33b380b 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLODLUtils.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLODLUtils.java @@ -1,15 +1,27 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.xsql; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; @@ -20,7 +32,9 @@ import org.opendaylight.yangtools.yang.model.util.Uint16; import org.opendaylight.yangtools.yang.model.util.Uint32; import org.opendaylight.yangtools.yang.model.util.Uint64; import org.opendaylight.yangtools.yang.model.util.Uint8; - +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ public class XSQLODLUtils { private static Map, Class> types = @@ -113,7 +127,7 @@ public class XSQLODLUtils { public static boolean createOpenDaylightCache(XSQLBluePrint bluePrint,Object module) { XSQLBluePrintNode node = new XSQLBluePrintNode(module, 0,null); - bluePrint.addToBluePrintCache(node); + bluePrint.addToBluePrintCache(node,null); collectODL(bluePrint, node, ((Module) module).getChildNodes(), 1); return true; } @@ -124,20 +138,30 @@ public class XSQLODLUtils { return; } for (DataSchemaNode n : nodes) { - if (n instanceof DataNodeContainer /*|| n instanceof LeafListSchemaNode*/ - || n instanceof ListSchemaNode) { + if (n instanceof DataNodeContainer) { XSQLBluePrintNode bn = new XSQLBluePrintNode(n, level,parent); - bluePrint.addToBluePrintCache(bn); - parent.AddChild(bn); - if (n instanceof DataNodeContainer) { + bn = bluePrint.addToBluePrintCache(bn,parent); + if (n instanceof ListSchemaNode) { level++; - collectODL(bluePrint, bn, - ((DataNodeContainer) n).getChildNodes(), level); + collectODL(bluePrint, bn,((ListSchemaNode) n).getChildNodes(), level); + Set s = ((ListSchemaNode)n).getAvailableAugmentations(); + if(s!=null){ + for(AugmentationSchema as:s){ + collectODL(bluePrint, bn,as.getChildNodes(), level); + } + } level--; - } else if (n instanceof ListSchemaNode) { + }else{ level++; - collectODL(bluePrint, bn, - ((ListSchemaNode) n).getChildNodes(), level); + collectODL(bluePrint, bn,((DataNodeContainer) n).getChildNodes(), level); + if(n instanceof ContainerSchemaNode){ + Set s = ((ContainerSchemaNode)n).getAvailableAugmentations(); + if(s!=null){ + for(AugmentationSchema as:s){ + collectODL(bluePrint, bn,as.getChildNodes(), level); + } + } + } level--; } } else { @@ -189,7 +213,7 @@ public class XSQLODLUtils { Field f = findField(c, name); return f.get(o); } catch (Exception err) { - XSQLAdapter.log(err); + //XSQLAdapter.log(err); } return null; } @@ -207,6 +231,21 @@ public class XSQLODLUtils { return (Map) get(o, "children"); } + public static Collection getChildrenCollection(Object o) { + Object value = get(o, "children"); + if(value==null) + return Collections.emptyList(); + if(value instanceof Map) + return ((Map)value).values(); + else + if(value instanceof Collection){ + return (Collection)value; + }else{ + XSQLAdapter.log("Unknown Child Value Type="+value.getClass().getName()); + return new ArrayList(); + } + } + public static Object getValue(Object o) { return get(o, "value"); } diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCResultSet.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCResultSet.java index 6689908204..ea16e72dc9 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCResultSet.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCResultSet.java @@ -1,10 +1,16 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.xsql.jdbc; import java.io.InputStream; import java.io.Reader; import java.io.Serializable; import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.math.BigDecimal; import java.net.URL; import java.sql.Array; @@ -24,6 +30,7 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -32,14 +39,18 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter; import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrint; import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrintNode; import org.opendaylight.controller.md.sal.dom.xsql.XSQLColumn; import org.opendaylight.controller.md.sal.dom.xsql.XSQLCriteria; import org.opendaylight.controller.md.sal.dom.xsql.XSQLODLUtils; +import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; -public class JDBCResultSet implements Serializable, ResultSet, - ResultSetMetaData { +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ +public class JDBCResultSet implements Serializable, ResultSet, ResultSetMetaData { private static final long serialVersionUID = -7450200738431047057L; private static final ClassLoader CLASS_LOADER = JDBCResultSet.class.getClassLoader(); private static final Class[] PROXY_INTERFACES = new Class[] { ResultSet.class }; @@ -57,27 +68,28 @@ public class JDBCResultSet implements Serializable, ResultSet, private Map>> criteria = new ConcurrentHashMap>>(); private Exception err = null; private List EMPTY_RESULT = new LinkedList(); - private transient Map subQueries = new HashMap(); + private transient Map subQueries = new HashMap(); public ResultSet getProxy() { - return (ResultSet) Proxy.newProxyInstance(CLASS_LOADER, PROXY_INTERFACES, new JDBCProxy(this)); + return this; + //return (ResultSet) Proxy.newProxyInstance(CLASS_LOADER, PROXY_INTERFACES, new JDBCProxy(this)); } public void setSQL(String _sql) { this.sql = _sql; } - public JDBCResultSet addSubQuery(String _sql,String logicalName) { + public JDBCResultSet addSubQuery(String _sql, String logicalName) { if (subQueries == null) { - subQueries = new HashMap(); + subQueries = new HashMap(); } JDBCResultSet rs = new JDBCResultSet(_sql); - this.subQueries.put(logicalName,rs); + this.subQueries.put(logicalName, rs); return rs; } - public Map getSubQueries() { - if (this.subQueries==null) { + public Map getSubQueries() { + if (this.subQueries == null) { this.subQueries = new HashMap<>(); } return this.subQueries; @@ -112,7 +124,8 @@ public class JDBCResultSet implements Serializable, ResultSet, } } - public int isObjectFitCriteria(Map objValues, String tableName) { + public int isObjectFitCriteria(Map objValues, + String tableName) { Map> tblCriteria = criteria .get(tableName); if (tblCriteria == null) { @@ -289,19 +302,41 @@ public class JDBCResultSet implements Serializable, ResultSet, } public static class Record { + // The map container the Attribute 2 the attribute value public Map data = new HashMap<>(); + // The Element Object (Possibly some kind of NormalizedNode public Object element = null; + // Does this record fit the criteria + // In case of a list property, we first collect the list and only then + // we + // we decide which list item should be included or not. + public boolean fitCriteria = true; public Map getRecord() { return this.data; } } - private Map collectColumnValues(Object node, XSQLBluePrintNode bpn) { - Map subChildren = XSQLODLUtils.getChildren(node); - Map result = new HashMap<>(); - for (Object stc : subChildren.values()) { - if (stc.getClass().getName().endsWith("ImmutableAugmentationNode")) { + public static class RecordsContainer { + public List records = new LinkedList(); + public List fitRecords = new LinkedList(); + public Object currentObject = null; + } + + private void collectColumnValues(RecordsContainer rContainer, + XSQLBluePrintNode bpn) { + Collection subChildren = XSQLODLUtils + .getChildrenCollection(rContainer.currentObject); + Record r = new Record(); + r.element = rContainer.currentObject; + for (Object stc : subChildren) { + if (stc.getClass().getName() + .endsWith("ImmutableUnkeyedListEntryNode")) { + r.fitCriteria = false; + rContainer.currentObject = stc; + collectColumnValues(rContainer, bpn); + } else if (stc.getClass().getName() + .endsWith("ImmutableAugmentationNode")) { Map values = XSQLODLUtils.getChildren(stc); for (Object key : values.keySet()) { Object val = values.get(key); @@ -309,7 +344,7 @@ public class JDBCResultSet implements Serializable, ResultSet, Object value = XSQLODLUtils.getValue(val); String k = XSQLODLUtils.getNodeName(val); if (value != null) { - result.put(bpn.getBluePrintNodeName() + "." + k, + r.data.put(bpn.getBluePrintNodeName() + "." + k, value.toString()); } } @@ -318,16 +353,17 @@ public class JDBCResultSet implements Serializable, ResultSet, String k = XSQLODLUtils.getNodeName(stc); Object value = XSQLODLUtils.getValue(stc); if (value != null) { - result.put(bpn.getBluePrintNodeName() + "." + k, + r.data.put(bpn.getBluePrintNodeName() + "." + k, value.toString()); } } } - return result; + if (r.fitCriteria) { + rContainer.records.add(r); + } } - private void addToData(Record rec, XSQLBluePrintNode bpn, - XSQLBluePrint bluePrint, Map fullRecord) { + private void addToData(Record rec, XSQLBluePrintNode bpn,XSQLBluePrint bluePrint, Map fullRecord) { XSQLBluePrintNode eNodes[] = bluePrint .getBluePrintNodeByODLTableName(XSQLODLUtils .getNodeIdentiofier(rec.element)); @@ -386,6 +422,11 @@ public class JDBCResultSet implements Serializable, ResultSet, String odlNodeName = XSQLODLUtils.getNodeIdentiofier(child); if (odlNodeName == null) { + if (child instanceof DataContainerNode) { + List augChidlren = getChildren(child, tableName, + bluePrint); + result.addAll(augChidlren); + } continue; } @@ -407,7 +448,10 @@ public class JDBCResultSet implements Serializable, ResultSet, continue; } - if (child.getClass().getName().endsWith("ImmutableContainerNode")) { + if (child.getClass().getName().endsWith("ImmutableUnkeyedListNode")) { + result.add(child); + } else if (child.getClass().getName() + .endsWith("ImmutableContainerNode")) { result.add(child); } else if (child.getClass().getName() .endsWith("ImmutableAugmentationNode")) { @@ -420,52 +464,76 @@ public class JDBCResultSet implements Serializable, ResultSet, } } else if (child.getClass().getName().endsWith("ImmutableMapNode")) { result.addAll(XSQLODLUtils.getMChildren(child)); + } else { + XSQLAdapter.log("Missed Node Data OF Type=" + + child.getClass().getName()); } } return result; } - public List addRecords(Object element, XSQLBluePrintNode node,boolean root, String tableName, XSQLBluePrint bluePrint) { + public List addRecords(Object element, XSQLBluePrintNode node, + boolean root, String tableName, XSQLBluePrint bluePrint) { List result = new LinkedList(); - //In case this is a sibling to the requested table, the elenment type - //won't be in the path of the leaf node - if(node==null){ - return result; - } String nodeID = XSQLODLUtils.getNodeIdentiofier(element); if (node.getODLTableName().equals(nodeID)) { - XSQLBluePrintNode bluePrintNode = bluePrint.getBluePrintNodeByODLTableName(nodeID)[0]; - Record rec = new Record(); - rec.element = element; - XSQLBluePrintNode bpn = this.tablesInQueryMap.get(bluePrintNode.getBluePrintNodeName()); - if (this.criteria.containsKey(bluePrintNode.getBluePrintNodeName()) || bpn != null) { - Map allKeyValues = collectColumnValues(element, bpn); - if (!(isObjectFitCriteria(allKeyValues, - bpn.getBluePrintNodeName()) == 1)) { - return EMPTY_RESULT; + XSQLBluePrintNode bluePrintNode = bluePrint + .getBluePrintNodeByODLTableName(nodeID)[0]; + RecordsContainer rContainer = new RecordsContainer(); + rContainer.currentObject = element; + XSQLBluePrintNode bpn = this.tablesInQueryMap.get(bluePrintNode + .getBluePrintNodeName()); + if (this.criteria.containsKey(bluePrintNode.getBluePrintNodeName()) + || bpn != null) { + collectColumnValues(rContainer, bpn); + for (Record r : rContainer.records) { + if (!(isObjectFitCriteria(r.data, + bpn.getBluePrintNodeName()) == 1)) { + r.fitCriteria = false; + } + if (r.fitCriteria) { + Record rec = new Record(); + rec.element = r.element; + addToData(rec, bpn, bluePrint, r.data); + rContainer.fitRecords.add(rec); + } } - addToData(rec, bpn, bluePrint, allKeyValues); + if (rContainer.fitRecords.isEmpty()) + return EMPTY_RESULT; } - if (root) { - addRecord(rec.data); + if (rContainer.records.isEmpty()) { + Record rec = new Record(); + rec.element = rContainer.currentObject; + if (root) { + addRecord(rec.data); + } else { + result.add(rec); + } } else { - result.add(rec); + for (Record rec : rContainer.fitRecords) { + if (root) { + addRecord(rec.data); + } else { + result.add(rec); + } + } } return result; } XSQLBluePrintNode parent = node.getParent(); - List subRecords = addRecords(element, parent, false, tableName,bluePrint); + List subRecords = addRecords(element, parent, false, tableName, + bluePrint); for (Record subRec : subRecords) { List subO = getChildren(subRec.element, tableName, bluePrint); if (subO != null) { for (Object subData : subO) { - Record rec = new Record(); - rec.element = subData; - rec.data.putAll(subRec.data); + RecordsContainer rContainer = new RecordsContainer(); + rContainer.currentObject = subData; - String recID = XSQLODLUtils.getNodeIdentiofier(rec.element); + String recID = XSQLODLUtils + .getNodeIdentiofier(rContainer.currentObject); XSQLBluePrintNode eNodes[] = bluePrint .getBluePrintNodeByODLTableName(recID); XSQLBluePrintNode bpn = null; @@ -476,18 +544,24 @@ public class JDBCResultSet implements Serializable, ResultSet, break; } } - boolean isObjectInCriteria = true; if (bpn != null) { - Map allKeyValues = collectColumnValues(rec.element, bpn); - if ((isObjectFitCriteria(allKeyValues, - bpn.getBluePrintNodeName()) == 1)) { - addToData(rec, bpn, bluePrint, allKeyValues); - } else { - isObjectInCriteria = false; + collectColumnValues(rContainer, bpn); + for (Record r : rContainer.records) { + if ((isObjectFitCriteria(r.data, + bpn.getBluePrintNodeName()) == 1)) { + Record rec = new Record(); + rec.data.putAll(subRec.data); + rec.element = r.element; + addToData(rec, bpn, bluePrint, r.data); + } else { + r.fitCriteria = false; + } } } - - if (isObjectInCriteria) { + if (rContainer.records.isEmpty()) { + Record rec = new Record(); + rec.data.putAll(subRec.data); + rec.element = rContainer.currentObject; if (root) { if (!rec.data.isEmpty()) { addRecord(rec.data); @@ -495,11 +569,23 @@ public class JDBCResultSet implements Serializable, ResultSet, } else { result.add(rec); } + } else { + for (Record r : rContainer.records) { + r.data.putAll(subRec.data); + if (r.fitCriteria) { + if (root) { + if (!r.data.isEmpty()) { + addRecord(r.data); + } + } else { + result.add(r); + } + } + } } } } } - return result; } diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCServer.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCServer.java index 7b2733ccf7..31941e496b 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCServer.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCServer.java @@ -46,8 +46,7 @@ public class JDBCServer extends Thread { } } - public static void execute(JDBCResultSet rs, XSQLAdapter adapter) - throws SQLException { + public static void execute(JDBCResultSet rs, XSQLAdapter adapter)throws SQLException { if(rs.getSQL().toLowerCase().trim().equals("select 1")){ rs.setFinished(true); return; diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/xsql/XSQLProvider.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/xsql/XSQLProvider.java index cde01573f2..29a1945a6e 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/xsql/XSQLProvider.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/xsql/XSQLProvider.java @@ -1,37 +1,47 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.xsql; -import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; -import org.opendaylight.controller.sal.binding.api.data.DataProviderService; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.xsql.rev140626.XSQL; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.xsql.rev140626.XSQLBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** - * Created by root on 6/26/14. - */ + * @author Sharon Aicler(saichler@gmail.com) + **/ public class XSQLProvider implements AutoCloseable { public static final InstanceIdentifier ID = InstanceIdentifier.builder(XSQL.class).build(); - private static final Logger LOG = LoggerFactory.getLogger(XSQLProvider.class); + //public static final InstanceIdentifier ID2 = InstanceIdentifier.builder(SalTest.class).build(); public void close() { } - public XSQL buildXSQL(DataProviderService dps) { + public XSQL buildXSQL(DataBroker dps) { + XSQLAdapter.log("Building XSL..."); XSQLBuilder builder = new XSQLBuilder(); builder.setPort("34343"); XSQL xsql = builder.build(); try { if (dps != null) { - final DataModificationTransaction t = dps.beginTransaction(); - t.removeOperationalData(ID); - t.putOperationalData(ID,xsql); - t.commit().get(); + XSQLAdapter.log("Starting TRansaction..."); + WriteTransaction t = dps.newReadWriteTransaction(); + t.delete(LogicalDatastoreType.OPERATIONAL, ID); + t.put(LogicalDatastoreType.OPERATIONAL,ID,xsql); + XSQLAdapter.log("Submitting..."); + t.submit(); } } catch (Exception e) { - LOG.warn("Failed to update XSQL port status, ", e); + XSQLAdapter.log(e); } return xsql; } diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/yang/gen/v1/http/netconfcentral/org/ns/xsql/rev140626/XSQLModule.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/yang/gen/v1/http/netconfcentral/org/ns/xsql/rev140626/XSQLModule.java index c8a5a85ae6..a669345e14 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/yang/gen/v1/http/netconfcentral/org/ns/xsql/rev140626/XSQLModule.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/yang/gen/v1/http/netconfcentral/org/ns/xsql/rev140626/XSQLModule.java @@ -1,9 +1,19 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.xsql.rev140626; import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter; import org.opendaylight.xsql.XSQLProvider; - +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ public class XSQLModule extends org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.xsql.rev140626.AbstractXSQLModule { + private static final long SLEEP_TIME_BEFORE_CREATING_TRANSACTION = 10000; public XSQLModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } @@ -22,9 +32,14 @@ public class XSQLModule extends org.opendaylight.yang.gen.v1.http.netconfcentral XSQLAdapter xsqlAdapter = XSQLAdapter.getInstance(); getSchemaServiceDependency().registerSchemaContextListener(xsqlAdapter); xsqlAdapter.setDataBroker(getAsyncDataBrokerDependency()); - XSQLProvider p = new XSQLProvider(); - //p.buildXSQL(getDataBrokerDependency()); + final XSQLProvider p = new XSQLProvider(); + Runnable runthis = new Runnable() { + @Override + public void run() { + try{Thread.sleep(SLEEP_TIME_BEFORE_CREATING_TRANSACTION);}catch(Exception err){} + p.buildXSQL(getDataBrokerDependency()); + } + }; return p; } - } diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/resources/04-xsql.xml b/opendaylight/md-sal/sal-dom-xsql/src/main/resources/04-xsql.xml index d7d547d19e..1b9a37df66 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/resources/04-xsql.xml +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/resources/04-xsql.xml @@ -8,8 +8,8 @@ XSQL - binding:binding-data-broker - binding-data-broker + binding:binding-async-data-broker + binding-data-broker dom:dom-async-data-broker diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/yang/XSQL.yang b/opendaylight/md-sal/sal-dom-xsql/src/main/yang/XSQL.yang index 0437e10e34..f0f52694a6 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/yang/XSQL.yang +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/yang/XSQL.yang @@ -37,14 +37,14 @@ module XSQL{ case XSQL { when "/config:modules/config:module/config:type = 'XSQL'"; - container data-broker { + container data-broker { uses config:service-ref { refine type { mandatory false; - config:required-identity mdsal:binding-data-broker; + config:required-identity mdsal:binding-async-data-broker; } } - } + } container async-data-broker { uses config:service-ref { diff --git a/opendaylight/md-sal/sal-dom-xsql/src/test/java/org/opendaylight/xsql/test/XSQLTest.java b/opendaylight/md-sal/sal-dom-xsql/src/test/java/org/opendaylight/xsql/test/XSQLTest.java index 8a6b184f82..e3f5fbb810 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/test/java/org/opendaylight/xsql/test/XSQLTest.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/test/java/org/opendaylight/xsql/test/XSQLTest.java @@ -2,18 +2,29 @@ package org.opendaylight.xsql.test; import java.io.InputStream; import java.sql.SQLException; +import java.util.Collections; +import java.util.Set; import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter; import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrint; import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCResultSet; import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCServer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class XSQLTest { - - XSQLBluePrint bluePrint = null; + private static final String DATASTORE_TEST_YANG = "/sal-persisted-dom-test.yang"; + private XSQLBluePrint bluePrint = null; + //private static SchemaContext schemaContext = null; + @BeforeClass + public static void loadSchemaContext(){ + //schemaContext = createTestContext(); + } @Before public void before() { @@ -167,4 +178,18 @@ public class XSQLTest { System.out.print("*** XSQL Tests -"); System.out.println(str); } + + public static final InputStream getDatastoreTestInputStream() { + return getInputStream(DATASTORE_TEST_YANG); + } + + private static InputStream getInputStream(final String resourceName) { + return XSQLTest.class.getResourceAsStream(DATASTORE_TEST_YANG); + } + + public static SchemaContext createTestContext() { + YangParserImpl parser = new YangParserImpl(); + Set modules = parser.parseYangModelsFromStreams(Collections.singletonList(getDatastoreTestInputStream())); + return parser.resolveSchemaContext(modules); + } } diff --git a/opendaylight/md-sal/sal-dom-xsql/src/test/resources/BluePrintCache.dat b/opendaylight/md-sal/sal-dom-xsql/src/test/resources/BluePrintCache.dat index b6b34acfcd..152f7878df 100644 Binary files a/opendaylight/md-sal/sal-dom-xsql/src/test/resources/BluePrintCache.dat and b/opendaylight/md-sal/sal-dom-xsql/src/test/resources/BluePrintCache.dat differ