Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Merge "Remove lock out of the congested/reuse case"
[controller.git]
/
opendaylight
/
md-sal
/
sal-dom-xsql
/
src
/
main
/
java
/
org
/
opendaylight
/
controller
/
md
/
sal
/
dom
/
xsql
/
XSQLAdapter.java
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 496f27ecaa1defe4f49d1cd724b58e8a3f673794..a5658ccc9ed661b9b2d616f2ca70a2303e875bb0 100644
(file)
--- 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
@@
-30,6
+30,8
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
private static final int SLEEP = 10000;
private static XSQLAdapter a = new XSQLAdapter();
private static PrintStream l = null;
private static final int SLEEP = 10000;
private static XSQLAdapter a = new XSQLAdapter();
private static PrintStream l = null;
+ private static String tmpDir = null;
+ private static File xqlLog = null;
public boolean stopped = false;
private List<String> elementHosts = new ArrayList<String>();
private String username;
public boolean stopped = false;
private List<String> elementHosts = new ArrayList<String>();
private String username;
@@
-63,10
+65,28
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
}
}
+ public void loadBluePrint(){
+ try{
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream("BluePrintCache.dat");
+ if(in!=null){
+ this.bluePrint = XSQLBluePrint.load(in);
+ }
+ in.close();
+ }catch(Exception err){
+ err.printStackTrace();
+ }
+ }
+
public static XSQLAdapter getInstance() {
return a;
}
public static XSQLAdapter getInstance() {
return a;
}
+ public static File getXQLLogfile() {
+ tmpDir = System.getProperty("java.io.tmpdir");
+ xqlLog = new File(tmpDir + "/xql.log");
+ return xqlLog;
+ }
+
public static void main(String args[]) {
XSQLAdapter adapter = new XSQLAdapter();
adapter.start();
public static void main(String args[]) {
XSQLAdapter adapter = new XSQLAdapter();
adapter.start();
@@
-78,7
+98,7
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
synchronized (XSQLAdapter.class) {
if (l == null) {
l = new PrintStream(
synchronized (XSQLAdapter.class) {
if (l == null) {
l = new PrintStream(
- new FileOutputStream(
"/tmp/xql.log"
));
+ new FileOutputStream(
getXQLLogfile()
));
}
}
}
}
}
}
@@
-96,7
+116,7
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
synchronized (XSQLAdapter.class) {
if (l == null) {
l = new PrintStream(
synchronized (XSQLAdapter.class) {
if (l == null) {
l = new PrintStream(
- new FileOutputStream(
"/tmp/xql.log"
));
+ new FileOutputStream(
getXQLLogfile()
));
}
}
}
}
}
}
@@
-126,7
+146,7
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
return this.bluePrint;
}
return this.bluePrint;
}
- public List<Object> collectModuleRoots(XSQLBluePrintNode table) {
+ public List<Object> collectModuleRoots(XSQLBluePrintNode table
,LogicalDatastoreType type
) {
if (table.getParent().isModule()) {
try {
List<Object> result = new LinkedList<Object>();
if (table.getParent().isModule()) {
try {
List<Object> result = new LinkedList<Object>();
@@
-136,20
+156,22
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
.toInstance();
DOMDataReadTransaction t = this.domDataBroker
.newReadOnlyTransaction();
.toInstance();
DOMDataReadTransaction t = this.domDataBroker
.newReadOnlyTransaction();
- Object node = t.read(
LogicalDatastoreType.OPERATIONAL
,
+ Object node = t.read(
type
,
instanceIdentifier).get();
instanceIdentifier).get();
+
node = XSQLODLUtils.get(node, "reference");
if (node == null) {
return result;
}
node = XSQLODLUtils.get(node, "reference");
if (node == null) {
return result;
}
- // XSQLAdapter.log(""+node);
Map<?, ?> children = XSQLODLUtils.getChildren(node);
for (Object c : children.values()) {
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);
Map<?, ?> sons = XSQLODLUtils.getChildren(c);
for (Object child : sons.values()) {
result.add(child);
- }
+ }
*/
}
return result;
}
return result;
@@
-157,14
+179,22
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
XSQLAdapter.log(err);
}
} else {
XSQLAdapter.log(err);
}
} else {
- return collectModuleRoots(table.getParent());
+ return collectModuleRoots(table.getParent()
,type
);
}
return null;
}
public void execute(JDBCResultSet rs) {
}
return null;
}
public void execute(JDBCResultSet rs) {
+ if(this.domDataBroker==null){
+ rs.setFinished(true);
+ return;
+ }
List<XSQLBluePrintNode> tables = rs.getTables();
List<XSQLBluePrintNode> tables = rs.getTables();
- List<Object> roots = collectModuleRoots(tables.get(0));
+ List<Object> roots = collectModuleRoots(tables.get(0),LogicalDatastoreType.OPERATIONAL);
+ roots.addAll(collectModuleRoots(tables.get(0),LogicalDatastoreType.CONFIGURATION));
+ if(roots.isEmpty()){
+ rs.setFinished(true);
+ }
XSQLBluePrintNode main = rs.getMainTable();
List<NETask> tasks = new LinkedList<XSQLAdapter.NETask>();
XSQLBluePrintNode main = rs.getMainTable();
List<NETask> tasks = new LinkedList<XSQLAdapter.NETask>();
@@
-277,6
+307,8
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
sout.close();
} catch (Exception err) {
}
sout.close();
} catch (Exception err) {
}
+ } else if (input.equals("save")) {
+ XSQLBluePrint.save(this.bluePrint);
} else if (input.equals("tocsv")) {
toCsv = !toCsv;
sout.println("to csv file is " + toCsv);
} else if (input.equals("tocsv")) {
toCsv = !toCsv;
sout.println("to csv file is " + toCsv);
@@
-318,7
+350,7
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
JDBCResultSet rs = new JDBCResultSet(sql);
try {
int count = 0;
JDBCResultSet rs = new JDBCResultSet(sql);
try {
int count = 0;
-
jdbc
Server.execute(rs, this);
+
JDBC
Server.execute(rs, this);
boolean isFirst = true;
int loc = rs.getFields().size() - 1;
int totalWidth = 0;
boolean isFirst = true;
int loc = rs.getFields().size() - 1;
int totalWidth = 0;
@@
-487,13
+519,15
@@
public class XSQLAdapter extends Thread implements SchemaContextListener {
out.print(prompt);
char c = 0;
byte data[] = new byte[1];
out.print(prompt);
char c = 0;
byte data[] = new byte[1];
- while (c != '\n') {
+ while (
!socket.isClosed() && socket.isConnected() && !socket.isInputShutdown() &&
c != '\n') {
try {
in.read(data);
c = (char) data[0];
inputString.append(c);
} catch (Exception err) {
err.printStackTrace(out);
try {
in.read(data);
c = (char) data[0];
inputString.append(c);
} catch (Exception err) {
err.printStackTrace(out);
+ stopped = true;
+ break;
}
}
}
}