From ecb12b2c72a4c94e283bd944fe6f8bcd2c349d29 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 28 Nov 2016 20:22:29 +0100 Subject: [PATCH] Create model package, prepare structure for a batch import --- .../{orientdb => model}/TcpConnection.java | 2 +- .../orientdb/BatchNetdataImportService.java | 67 +++++++++++++++++++ ...anceKappaOrientDbNetdataImportService.java | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) rename src/main/java/de/hsh/inform/orientdb_project/{orientdb => model}/TcpConnection.java (96%) create mode 100644 src/main/java/de/hsh/inform/orientdb_project/orientdb/BatchNetdataImportService.java diff --git a/src/main/java/de/hsh/inform/orientdb_project/orientdb/TcpConnection.java b/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnection.java similarity index 96% rename from src/main/java/de/hsh/inform/orientdb_project/orientdb/TcpConnection.java rename to src/main/java/de/hsh/inform/orientdb_project/model/TcpConnection.java index d65468d..5685a29 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/orientdb/TcpConnection.java +++ b/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnection.java @@ -1,4 +1,4 @@ -package de.hsh.inform.orientdb_project.orientdb; +package de.hsh.inform.orientdb_project.model; import org.pcap4j.packet.TcpPacket; diff --git a/src/main/java/de/hsh/inform/orientdb_project/orientdb/BatchNetdataImportService.java b/src/main/java/de/hsh/inform/orientdb_project/orientdb/BatchNetdataImportService.java new file mode 100644 index 0000000..d773cc8 --- /dev/null +++ b/src/main/java/de/hsh/inform/orientdb_project/orientdb/BatchNetdataImportService.java @@ -0,0 +1,67 @@ +package de.hsh.inform.orientdb_project.orientdb; + +import java.util.HashMap; +import java.util.Map; + +import org.pcap4j.packet.ArpPacket; +import org.pcap4j.packet.IcmpV4CommonPacket; +import org.pcap4j.packet.TcpPacket; +import org.pcap4j.packet.UdpPacket; + +import com.orientechnologies.orient.graph.batch.OGraphBatchInsert; + +import de.hsh.inform.orientdb_project.netdata.AbstractNetdataImportService; + +public class BatchNetdataImportService extends AbstractNetdataImportService { + + public BatchNetdataImportService(String filename) { + super(filename); + } + + @Override + public void handleArpPacket(ArpPacket arp, long timestamp, int milliseconds) { + + } + + @Override + public void handleTcpPacket(TcpPacket tcp, long timestamp, int milliseconds) { + + } + + @Override + public void handleUdpPacket(UdpPacket udp, long timestamp, int milliseconds) { + + } + + @Override + public void handleIcmpPacket(IcmpV4CommonPacket icmp, long timestamp, int milliseconds) { + + } + + @Override + public void afterImport() { + OGraphBatchInsert batch = new OGraphBatchInsert("plocal:your/db", "admin", "admin"); + //phase 1: begin + batch.begin(); + //phase 2: create edges + Map edgeProps = new HashMap(); + edgeProps.put("foo", "bar"); + batch.createEdge(0L, 1L, edgeProps); + batch.createVertex(2L); + batch.createEdge(3L, 4L, null); + //phase 3: set properties on vertices, THIS CAN BE DONE ONLY AFTER EDGE AND VERTEX CREATION + Map vertexProps = new HashMap(); + vertexProps.put("foo", "bar"); + batch.setVertexProperties(0L, vertexProps); + //phase 4: end + batch.end(); + //There is no need to create vertices before connecting them: + batch.createVertex(0L); + batch.createVertex(1L); + batch.createEdge(0L, 1L, props); + // is equivalent to (but less performing than) + batch.createEdge(0L, 1L, props); + //batch.createVertex(Long) is needed only if you want to create unconnected vertices + } + +} diff --git a/src/main/java/de/hsh/inform/orientdb_project/orientdb/HighPerformanceKappaOrientDbNetdataImportService.java b/src/main/java/de/hsh/inform/orientdb_project/orientdb/HighPerformanceKappaOrientDbNetdataImportService.java index cca48b3..24b31ff 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/orientdb/HighPerformanceKappaOrientDbNetdataImportService.java +++ b/src/main/java/de/hsh/inform/orientdb_project/orientdb/HighPerformanceKappaOrientDbNetdataImportService.java @@ -15,6 +15,7 @@ import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; +import de.hsh.inform.orientdb_project.model.TcpConnection; import de.hsh.inform.orientdb_project.netdata.AbstractNetdataImportService; public class HighPerformanceKappaOrientDbNetdataImportService extends AbstractNetdataImportService {