+/*
+ * 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;
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;
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;
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");
}
+ 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 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();
synchronized (XSQLAdapter.class) {
if (l == null) {
l = new PrintStream(
- new FileOutputStream("/tmp/xql.log"));
+ new FileOutputStream(getXQLLogfile()));
}
}
}
synchronized (XSQLAdapter.class) {
if (l == null) {
l = new PrintStream(
- new FileOutputStream("/tmp/xql.log"));
+ new FileOutputStream(getXQLLogfile()));
}
}
}
List<Object> result = new LinkedList<Object>();
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;
}
-
- // XSQLAdapter.log(""+node);
- Map<?, ?> children = XSQLODLUtils.getChildren(node);
- for (Object c : children.values()) {
- Map<?, ?> sons = XSQLODLUtils.getChildren(c);
- for (Object child : sons.values()) {
- result.add(child);
- }
- }
-
+ result.add(node);
return result;
} catch (Exception err) {
XSQLAdapter.log(err);
}
public void execute(JDBCResultSet rs) {
+ if(this.domDataBroker==null){
+ rs.setFinished(true);
+ return;
+ }
List<XSQLBluePrintNode> tables = rs.getTables();
List<Object> roots = collectModuleRoots(tables.get(0),LogicalDatastoreType.OPERATIONAL);
roots.addAll(collectModuleRoots(tables.get(0),LogicalDatastoreType.CONFIGURATION));
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);
JDBCResultSet rs = new JDBCResultSet(sql);
try {
int count = 0;
- jdbcServer.execute(rs, this);
+ JDBCServer.execute(rs, this);
boolean isFirst = true;
int loc = rs.getFields().size() - 1;
int totalWidth = 0;