Add first repository and a simple sample query

This commit is contained in:
Jan Philipp Timme 2016-12-12 11:18:29 +01:00
parent bbce5d2466
commit a976c1a8fe
Signed by untrusted user: JPT
GPG Key ID: 5F2C85EC6F3754B7
5 changed files with 112 additions and 33 deletions

View File

@ -0,0 +1,52 @@
package de.hsh.inform.orientdb_project;
import java.io.EOFException;
import java.util.concurrent.TimeoutException;
import org.pcap4j.core.NotOpenException;
import org.pcap4j.core.PcapNativeException;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import de.hsh.inform.orientdb_project.netdata.AbstractNetdataImportService;
import de.hsh.inform.orientdb_project.orientdb.NodeBasedImportService;
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader;
public class ImportMain {
public static void main(String[] args) {
ConfigPropertiesReader config = new ConfigPropertiesReader();
String filename = config.filename;
OrientDbHelperService odhs = new OrientDbHelperService(config.dbhost, config.dbname, config.dbuser, config.dbpass);
System.out.println("Using database: " + odhs.getDbUri(true));
// Clean up existing database and set up schema from scratch
odhs.cleanUpServer();
odhs.setupSchema();
// Get "handle" for database to pass to import service
OrientGraphNoTx ogf = odhs.getOrientGraphNoTx();
//AbstractNetdataImportService importService = new DummyImportService(filename); // Only for comparison reasons
AbstractNetdataImportService importService = new NodeBasedImportService(filename, ogf);
// Go go gadget import service!
try {
System.out.println(System.currentTimeMillis()/1000L + ": Begin import of data ...");
if(config.limitedImport) {
importService.partialRun(config.importLimit);
} else {
importService.run();
}
System.out.println(System.currentTimeMillis()/1000L + ": Import of data done!");
} catch (EOFException | PcapNativeException | TimeoutException | NotOpenException e) {
e.printStackTrace();
}
// Done
odhs.close();
System.out.println(System.currentTimeMillis()/1000L + ": End of program.");
}
}

View File

@ -1,52 +1,27 @@
package de.hsh.inform.orientdb_project;
import java.io.EOFException;
import java.util.concurrent.TimeoutException;
import org.pcap4j.core.NotOpenException;
import org.pcap4j.core.PcapNativeException;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import de.hsh.inform.orientdb_project.netdata.AbstractNetdataImportService;
import de.hsh.inform.orientdb_project.orientdb.NodeBasedImportService;
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
import de.hsh.inform.orientdb_project.repository.TcpConnectionRepository;
import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader;
public class Main {
public static void main(String[] args) {
ConfigPropertiesReader config = new ConfigPropertiesReader();
String filename = config.filename;
OrientDbHelperService odhs = new OrientDbHelperService(config.dbhost, config.dbname, config.dbuser, config.dbpass);
OrientDbHelperService odhs = new OrientDbHelperService(config.dbhost, config.dbname, config.dbuser,
config.dbpass);
System.out.println("Using database: " + odhs.getDbUri(true));
// Clean up existing database and set up schema from scratch
odhs.cleanUpServer();
odhs.setupSchema();
// Get "handle" for database to pass to import service
OrientGraphNoTx ogf = odhs.getOrientGraphNoTx();
//AbstractNetdataImportService importService = new DummyImportService(filename); // Only for comparison reasons
AbstractNetdataImportService importService = new NodeBasedImportService(filename, ogf);
// Go go gadget import service!
try {
System.out.println(System.currentTimeMillis()/1000L + ": Begin import of data ...");
if(config.limitedImport) {
importService.partialRun(config.importLimit);
} else {
importService.run();
}
System.out.println(System.currentTimeMillis()/1000L + ": Import of data done!");
} catch (EOFException | PcapNativeException | TimeoutException | NotOpenException e) {
e.printStackTrace();
}
TcpConnectionRepository tcr = new TcpConnectionRepository(ogf);
tcr.findByActiveWhen(901713642);
// Done
odhs.close();
System.out.println(System.currentTimeMillis()/1000L + ": End of program.");
}
}

View File

@ -59,6 +59,11 @@ public class TcpConnectionModel {
this.knownTcpPacketVertices = new LinkedList<Vertex>();
}
public TcpConnectionModel(Vertex v) {
// TODO!
}
public void setStart(long ts, int ms) {
this.startTs = ts;
this.startMs = ms;

View File

@ -158,5 +158,5 @@ public class OrientDbHelperService {
// We're done creating classes and types, shut down the database graph.
og.shutdown();
}
}

View File

@ -0,0 +1,47 @@
package de.hsh.inform.orientdb_project.repository;
import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Predicate;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import de.hsh.inform.orientdb_project.model.TcpConnectionModel;
public class TcpConnectionRepository {
private OrientGraphNoTx ogf;
public TcpConnectionRepository(OrientGraphNoTx ogf) {
this.ogf = ogf;
}
public Object findByActiveWhen(long ts) {
GraphQuery gq = this.ogf.query();
gq = gq.has("@class", "TcpConnection");
gq = gq.has("startTs", new Predicate() {
@Override
public boolean evaluate(Object seen, Object given) {
return (Long) seen <= (Long) given;
}
}, ts);
gq = gq.has("endTs", new Predicate() {
@Override
public boolean evaluate(Object seen, Object given) {
return (Long) seen >= (Long) given;
}
}, ts);
System.out.println("Ergebnisse:");
for(Vertex v : gq.vertices()) {
for(String key : v.getPropertyKeys()) {
System.out.print(key + ": " + v.getProperty(key) + ", ");
}
System.out.println();
}
System.out.println("----");
return null;
}
}