diff --git a/src/main/java/de/hsh/inform/orientdb_project/ImportMain.java b/src/main/java/de/hsh/inform/orientdb_project/ImportMain.java new file mode 100644 index 0000000..901717d --- /dev/null +++ b/src/main/java/de/hsh/inform/orientdb_project/ImportMain.java @@ -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."); + } + +} diff --git a/src/main/java/de/hsh/inform/orientdb_project/Main.java b/src/main/java/de/hsh/inform/orientdb_project/Main.java index 72bca5a..405d629 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/Main.java +++ b/src/main/java/de/hsh/inform/orientdb_project/Main.java @@ -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."); } - + } diff --git a/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnectionModel.java b/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnectionModel.java index 5651711..8ca9f83 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnectionModel.java +++ b/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnectionModel.java @@ -59,6 +59,11 @@ public class TcpConnectionModel { this.knownTcpPacketVertices = new LinkedList(); } + public TcpConnectionModel(Vertex v) { + // TODO! + } + + public void setStart(long ts, int ms) { this.startTs = ts; this.startMs = ms; diff --git a/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java b/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java index 671c913..e6a9382 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java +++ b/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java @@ -158,5 +158,5 @@ public class OrientDbHelperService { // We're done creating classes and types, shut down the database graph. og.shutdown(); } - + } diff --git a/src/main/java/de/hsh/inform/orientdb_project/repository/TcpConnectionRepository.java b/src/main/java/de/hsh/inform/orientdb_project/repository/TcpConnectionRepository.java new file mode 100644 index 0000000..8a006aa --- /dev/null +++ b/src/main/java/de/hsh/inform/orientdb_project/repository/TcpConnectionRepository.java @@ -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; + } + +}