mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-05 06:35:44 +00:00
Implementation of config file loading.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package info.fetter.logstashforwarder.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class Configuration {
|
||||
private NetworkSection network;
|
||||
private List<FilesSection> files;
|
||||
/**
|
||||
* @return the network
|
||||
*/
|
||||
public NetworkSection getNetwork() {
|
||||
return network;
|
||||
}
|
||||
/**
|
||||
* @param network the network to set
|
||||
*/
|
||||
public void setNetwork(NetworkSection network) {
|
||||
this.network = network;
|
||||
}
|
||||
/**
|
||||
* @return the files
|
||||
*/
|
||||
public List<FilesSection> getFiles() {
|
||||
return files;
|
||||
}
|
||||
/**
|
||||
* @param files the files to set
|
||||
*/
|
||||
public void setFiles(List<FilesSection> files) {
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).
|
||||
append("network", network).
|
||||
append("files", files).
|
||||
toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package info.fetter.logstashforwarder.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class ConfigurationManager {
|
||||
private File configFile;
|
||||
private Configuration config;
|
||||
private ObjectMapper mapper;
|
||||
|
||||
public ConfigurationManager(String configFilePath) {
|
||||
this(new File(configFilePath));
|
||||
}
|
||||
|
||||
public ConfigurationManager(File file) {
|
||||
configFile = file;
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
|
||||
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
|
||||
}
|
||||
|
||||
public void readConfiguration() throws JsonParseException, JsonMappingException, IOException {
|
||||
config = mapper.readValue(configFile, Configuration.class);
|
||||
}
|
||||
|
||||
public void writeConfiguration() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the config
|
||||
*/
|
||||
public Configuration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package info.fetter.logstashforwarder.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class FilesSection {
|
||||
private List<String> paths;
|
||||
private Map<String,String> fields;
|
||||
/**
|
||||
* @return the paths
|
||||
*/
|
||||
public List<String> getPaths() {
|
||||
return paths;
|
||||
}
|
||||
/**
|
||||
* @param paths the paths to set
|
||||
*/
|
||||
public void setPaths(List<String> paths) {
|
||||
this.paths = paths;
|
||||
}
|
||||
/**
|
||||
* @return the fields
|
||||
*/
|
||||
public Map<String, String> getFields() {
|
||||
return fields;
|
||||
}
|
||||
/**
|
||||
* @param fields the fields to set
|
||||
*/
|
||||
public void setFields(Map<String, String> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).
|
||||
append("paths", paths).
|
||||
append("fields", fields).
|
||||
toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package info.fetter.logstashforwarder.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class NetworkSection {
|
||||
private List<String> servers;
|
||||
@JsonProperty("ssl certificate")
|
||||
private String sslCertificate;
|
||||
@JsonProperty("ssl ca")
|
||||
private String sslCA;
|
||||
@JsonProperty("ssl key")
|
||||
private String sslKey;
|
||||
private int timeout;
|
||||
/**
|
||||
* @return the servers
|
||||
*/
|
||||
public List<String> getServers() {
|
||||
return servers;
|
||||
}
|
||||
/**
|
||||
* @param servers the servers to set
|
||||
*/
|
||||
public void setServers(List<String> servers) {
|
||||
this.servers = servers;
|
||||
}
|
||||
/**
|
||||
* @return the sslCertificate
|
||||
*/
|
||||
public String getSslCertificate() {
|
||||
return sslCertificate;
|
||||
}
|
||||
/**
|
||||
* @param sslCertificate the sslCertificate to set
|
||||
*/
|
||||
public void setSslCertificate(String sslCertificate) {
|
||||
this.sslCertificate = sslCertificate;
|
||||
}
|
||||
/**
|
||||
* @return the sslCA
|
||||
*/
|
||||
public String getSslCA() {
|
||||
return sslCA;
|
||||
}
|
||||
/**
|
||||
* @param sslCA the sslCA to set
|
||||
*/
|
||||
public void setSslCA(String sslCA) {
|
||||
this.sslCA = sslCA;
|
||||
}
|
||||
/**
|
||||
* @return the timeout
|
||||
*/
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
/**
|
||||
* @param timeout the timeout to set
|
||||
*/
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sslKey
|
||||
*/
|
||||
public String getSslKey() {
|
||||
return sslKey;
|
||||
}
|
||||
/**
|
||||
* @param sslKey the sslKey to set
|
||||
*/
|
||||
public void setSslKey(String sslKey) {
|
||||
this.sslKey = sslKey;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).
|
||||
append("servers", servers).
|
||||
append("sslCertificate", sslCertificate).
|
||||
append("sslCA", sslCA).
|
||||
append("timeout", timeout).
|
||||
toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user