Implement more stuff

This commit is contained in:
Jan Philipp Timme 2016-12-12 14:48:12 +01:00
parent 19b6fc3e4e
commit 687df96022
Signed by untrusted user: JPT
GPG Key ID: 5F2C85EC6F3754B7
4 changed files with 26 additions and 6 deletions

View File

@ -4,8 +4,10 @@ import java.util.List;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import de.hsh.inform.orientdb_project.model.HostModel;
import de.hsh.inform.orientdb_project.model.TcpConnectionModel; import de.hsh.inform.orientdb_project.model.TcpConnectionModel;
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService; import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
import de.hsh.inform.orientdb_project.repository.HostRepository;
import de.hsh.inform.orientdb_project.repository.TcpConnectionRepository; import de.hsh.inform.orientdb_project.repository.TcpConnectionRepository;
import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader; import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader;
@ -29,6 +31,11 @@ public class Main {
long r = tcr.getTotalDataVolumePerMinuteBetweenHosts("172.16.114.207", "206.251.19.72"); long r = tcr.getTotalDataVolumePerMinuteBetweenHosts("172.16.114.207", "206.251.19.72");
System.out.println("Bytes per Second: " + r); System.out.println("Bytes per Second: " + r);
HostRepository hr = new HostRepository(ogf);
for(HostModel hm : hr.findByConnectionsTo("197.218.177.69", 25)) {
System.out.println(hm);
}
// Done // Done
odhs.close(); odhs.close();
} }

View File

@ -37,5 +37,14 @@ public class HostModel {
}; };
return arguments; return arguments;
} }
public String toString() {
StringBuilder sb = new StringBuilder("[Host ipAddress=");
sb.append(this.ipAddress);
sb.append(", internal=");
sb.append(this.internal);
sb.append("]");
return sb.toString();
}
} }

View File

@ -146,13 +146,13 @@ public class NodeBasedImportService extends AbstractNetdataImportService {
} }
private void addHostIfNew(Inet4Address ipAddress) { private void addHostIfNew(Inet4Address ipAddress) {
if(this.knownHosts.containsKey(ipAddress)) { String ipAddressStr = ipAddress.toString().split("/")[1];
if(this.knownHosts.containsKey(ipAddressStr)) {
return; // Host already known, nothing to do! return; // Host already known, nothing to do!
} else { } else {
// Check internal/external by IP // Check internal/external by IP
boolean isInternal = ipAddress.isSiteLocalAddress(); // TODO: VERIFY IF THIS IS CORRECT! boolean isInternal = ipAddress.isSiteLocalAddress(); // TODO: VERIFY IF THIS IS CORRECT!
// Create Vertex and add to HashMap // Create Vertex and add to HashMap
String ipAddressStr = ipAddress.toString().split("/")[1];
HostModel hostModel = new HostModel(ipAddressStr, isInternal); HostModel hostModel = new HostModel(ipAddressStr, isInternal);
Vertex host = this.og.addVertex("class:Host", hostModel.getArguments()); Vertex host = this.og.addVertex("class:Host", hostModel.getArguments());
this.knownHosts.put(ipAddressStr, host); this.knownHosts.put(ipAddressStr, host);

View File

@ -3,6 +3,7 @@ package de.hsh.inform.orientdb_project.repository;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.tinkerpop.blueprints.GraphQuery; import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
@ -18,10 +19,13 @@ public class HostRepository {
} }
public List<HostModel> findByConnectionsTo(String ipAddress, int port) { public List<HostModel> findByConnectionsTo(String ipAddress, int port) {
GraphQuery gq = this.ogf.query(); String sql = "" +
gq = gq.has("@class", "Host"); "SELECT EXPAND(out('isTargetHostFor')[targetPort=" + port + "].out('hasSourceHost')) " +
// TODO "FROM Host WHERE ipAddress = '" + ipAddress + "';";
return this.getListFromVertices(gq.vertices());
@SuppressWarnings("unchecked") // We know.
Iterable<Vertex> vertices = (Iterable<Vertex>) this.ogf.command(new OCommandSQL(sql)).execute();
return this.getListFromVertices(vertices);
} }
public List<HostModel> findAllByConnectionsToOutsideHosts() { public List<HostModel> findAllByConnectionsToOutsideHosts() {