Add model for well known ports plus some static data
This commit is contained in:
parent
542d5939af
commit
ed862d2f8f
|
@ -0,0 +1,35 @@
|
||||||
|
package de.hsh.inform.orientdb_project.model;
|
||||||
|
|
||||||
|
import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
|
public class WellKnownPortModel {
|
||||||
|
|
||||||
|
public int port;
|
||||||
|
public String description;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Static helper method to create type for itself in OrientDb
|
||||||
|
* Check this.getArguments() to ensure completeness.
|
||||||
|
*/
|
||||||
|
public static void createType(OrientGraphNoTx og) {
|
||||||
|
OrientVertexType portType = og.createVertexType("WellKnownPort", "V");
|
||||||
|
portType.createProperty("port", OType.INTEGER);
|
||||||
|
portType.createProperty("description", OType.STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WellKnownPortModel(int port, String description) {
|
||||||
|
this.port = port;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getArguments() {
|
||||||
|
Object[] arguments = {
|
||||||
|
"port", this.port,
|
||||||
|
"description", this.description,
|
||||||
|
};
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package de.hsh.inform.orientdb_project.orientdb;
|
package de.hsh.inform.orientdb_project.orientdb;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.orientechnologies.orient.client.remote.OServerAdmin;
|
import com.orientechnologies.orient.client.remote.OServerAdmin;
|
||||||
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
|
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
|
||||||
|
@ -17,6 +18,7 @@ import de.hsh.inform.orientdb_project.model.IpPacketModel;
|
||||||
import de.hsh.inform.orientdb_project.model.TcpConnectionModel;
|
import de.hsh.inform.orientdb_project.model.TcpConnectionModel;
|
||||||
import de.hsh.inform.orientdb_project.model.TcpPacketModel;
|
import de.hsh.inform.orientdb_project.model.TcpPacketModel;
|
||||||
import de.hsh.inform.orientdb_project.model.UdpPacketModel;
|
import de.hsh.inform.orientdb_project.model.UdpPacketModel;
|
||||||
|
import de.hsh.inform.orientdb_project.model.WellKnownPortModel;
|
||||||
|
|
||||||
public class OrientDbHelperService {
|
public class OrientDbHelperService {
|
||||||
|
|
||||||
|
@ -102,6 +104,17 @@ public class OrientDbHelperService {
|
||||||
public void setupSchema() {
|
public void setupSchema() {
|
||||||
this.createClasses();
|
this.createClasses();
|
||||||
this.createClusters();
|
this.createClusters();
|
||||||
|
this.importStaticData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importStaticData() {
|
||||||
|
int[] ports = {22, 25, 53, 80, 443};
|
||||||
|
String[] descriptions = {"SSH", "SMTP", "DNS", "HTTP", "HTTPS"};
|
||||||
|
OrientGraphNoTx og = this.getOrientGraphFactory().getNoTx();
|
||||||
|
for(int i = 0; i < ports.length; i++) {
|
||||||
|
WellKnownPortModel m = new WellKnownPortModel(ports[i], descriptions[i]);
|
||||||
|
og.addVertex("class:WellKnownPort", m.getArguments());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createClusters() {
|
private void createClusters() {
|
||||||
|
@ -132,6 +145,7 @@ public class OrientDbHelperService {
|
||||||
|
|
||||||
HostModel.createType(og);
|
HostModel.createType(og);
|
||||||
TcpConnectionModel.createType(og);
|
TcpConnectionModel.createType(og);
|
||||||
|
WellKnownPortModel.createType(og);
|
||||||
|
|
||||||
// Edges do not really need their own model (yet), they connect the vertex types
|
// Edges do not really need their own model (yet), they connect the vertex types
|
||||||
OrientEdgeType isContainedInType = og.createEdgeType("isContainedIn", "E");
|
OrientEdgeType isContainedInType = og.createEdgeType("isContainedIn", "E");
|
||||||
|
|
Loading…
Reference in New Issue