Add src/resources/config.properties to allow userdefined configuration

This commit is contained in:
Jan Philipp Timme 2016-12-05 21:30:09 +01:00
parent ad178727f1
commit baa41c5ff7
Signed by untrusted user: JPT
GPG Key ID: 5F2C85EC6F3754B7
5 changed files with 72 additions and 5 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
.settings .settings
.project .project
/target/ /target/
src/resources/config.properties

View File

@ -2,3 +2,4 @@
This is an application to import a tcpdump file into an orientdb server instance. This is an application to import a tcpdump file into an orientdb server instance.
In order to run this project, import it into ecplise and configure it to use maven to install the dependencies from `pom.xml` In order to run this project, import it into ecplise and configure it to use maven to install the dependencies from `pom.xml`
Also make sure to make `src/resources` a source folder so that the configuration file `config.properties` is within the class path. (Use `config.properties.sample` to create your own `config.properties` file)

View File

@ -11,13 +11,15 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import de.hsh.inform.orientdb_project.netdata.AbstractNetdataImportService; import de.hsh.inform.orientdb_project.netdata.AbstractNetdataImportService;
import de.hsh.inform.orientdb_project.orientdb.NodeBasedImportService; import de.hsh.inform.orientdb_project.orientdb.NodeBasedImportService;
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService; import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
// TODO: Make this configurable or easy to exchange. ConfigPropertiesReader config = new ConfigPropertiesReader();
String filename = "/home/jpt/Temp/tcpdump_2"; String filename = config.filename;
OrientDbHelperService odhs = new OrientDbHelperService("192.168.0.110", "hshtest", "root", "root"); 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 // Clean up existing database and set up schema from scratch
odhs.cleanUpServer(); odhs.cleanUpServer();
@ -26,8 +28,7 @@ public class Main {
// Get "handle" for database to pass to import service // Get "handle" for database to pass to import service
OrientGraphNoTx ogf = odhs.getOrientGraphNoTx(); OrientGraphNoTx ogf = odhs.getOrientGraphNoTx();
//AbstractNetdataImportService importService = new DummyImportService(filename); //AbstractNetdataImportService importService = new DummyImportService(filename); // Only for comparison reasons
//AbstractNetdataImportService importService = new LowPerformanceOrientDbNetdataImportService(filename, ogf);
AbstractNetdataImportService importService = new NodeBasedImportService(filename, ogf); AbstractNetdataImportService importService = new NodeBasedImportService(filename, ogf);
// Go go gadget import service! // Go go gadget import service!
@ -38,6 +39,7 @@ public class Main {
} catch (EOFException | PcapNativeException | TimeoutException | NotOpenException e) { } catch (EOFException | PcapNativeException | TimeoutException | NotOpenException e) {
e.printStackTrace(); e.printStackTrace();
} }
// Done // Done
odhs.close(); odhs.close();
System.out.println(System.currentTimeMillis()/1000L + ": End of program."); System.out.println(System.currentTimeMillis()/1000L + ": End of program.");

View File

@ -0,0 +1,53 @@
package de.hsh.inform.orientdb_project.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ConfigPropertiesReader {
public String dbuser;
public String dbpass;
public String dbname;
public String dbhost;
public String filename;
public boolean limitedImport;
public int importLimit;
public ConfigPropertiesReader() {
Properties props = null;
try {
props = this.readProperties();
} catch (IOException e) {
e.printStackTrace();
}
this.dbuser = props.getProperty("dbuser");
this.dbpass = props.getProperty("dbpass");
this.dbname = props.getProperty("dbname");
this.dbhost = props.getProperty("dbhost");
this.filename = props.getProperty("filename");
this.limitedImport = Boolean.valueOf(props.getProperty("limitedImport"));
this.importLimit = Integer.valueOf(props.getProperty("importLimit"));
}
private Properties readProperties() throws IOException {
String propFileName = "config.properties";
Properties properties = null;
InputStream inputStream = null;
try {
properties = new Properties();
inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
if(inputStream != null) {
properties.load(inputStream);
} else {
throw new FileNotFoundException("Property file '" + propFileName + "' not found in the classpath! Make sure to use src/resources as source folder!");
}
} catch (Exception e) {
System.err.println("Exception: " + e);
} finally {
inputStream.close();
}
return properties;
}
}

View File

@ -0,0 +1,9 @@
#OrientDb config settings
dbuser=root
dbpass=root
dbname=root
dbhost=127.0.0.1
filename=/home/jpt/Temp/tcpdump_2
limitedImport=true
importLimit=10000