-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add logstash DAO #29
add logstash DAO #29
Changes from all commits
aa1c43e
2cc1ac8
98293e4
c240576
8eb487b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package jenkins.plugins.logstash.persistence; | ||
|
||
import com.cloudbees.syslog.Facility; | ||
import com.cloudbees.syslog.MessageFormat; | ||
import com.cloudbees.syslog.Severity; | ||
import com.cloudbees.syslog.sender.UdpSyslogMessageSender; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
|
||
import java.io.*; | ||
import java.net.Socket; | ||
|
||
|
||
public class LogstashDao extends AbstractLogstashIndexerDao { | ||
|
||
final String logstashHost; | ||
final int logstashPort; | ||
Socket logstashClientSocket; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this not private? And why an instance variable? |
||
|
||
public LogstashDao(String logstashHostString, int logstashPortInt, String indexKey, String username, String password) { | ||
this(null, logstashHostString, logstashPortInt, indexKey, username, password); | ||
} | ||
|
||
public LogstashDao(HttpClientBuilder factory, String logstashHostString, int logstashPortInt, String indexKey, String username, String password) { | ||
super(logstashHostString, logstashPortInt, indexKey, username, password); | ||
this.logstashHost = logstashHostString; | ||
this.logstashPort = logstashPortInt; | ||
} | ||
|
||
@Override | ||
public void push(String data) throws IOException { | ||
|
||
try | ||
{ | ||
logstashClientSocket = new Socket(logstashHost, logstashPort); | ||
DataOutputStream outToServer = new DataOutputStream(logstashClientSocket.getOutputStream()); | ||
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(logstashClientSocket.getInputStream())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why opening a reader when you never read data? |
||
outToServer.writeBytes(data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The javadoc for this method says:
Is this really a good idea? What if we have unicode characters (very likely to happen)? |
||
logstashClientSocket.setSoTimeout(10000); | ||
logstashClientSocket.close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resources should be closed in finally block, or even better used in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a good idea to close the Socket before closing the outputstream? |
||
outToServer.close(); | ||
inFromServer.close(); | ||
} | ||
catch (Exception exc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please change this to a multi-catch with specific Exception? |
||
{ | ||
StringWriter sw = new StringWriter(); | ||
PrintWriter pw = new PrintWriter(sw); | ||
exc.printStackTrace(pw); | ||
throw new IOException(sw.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not chain the exception? |
||
} | ||
|
||
} | ||
|
||
@Override | ||
public IndexerType getIndexerType() { return IndexerType.LOGSTASH; } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These imports from com.cloudbees are not used