Add first repository and a simple sample query
This commit is contained in:
parent
bbce5d2466
commit
a976c1a8fe
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
|
@ -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.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -158,5 +158,5 @@ public class OrientDbHelperService {
|
|||
// We're done creating classes and types, shut down the database graph.
|
||||
og.shutdown();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue