forked from ConsoleCatzirl/jenkins-logstash-plugin
-
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
move configuration from ToolInstallation to GlobalConfiguration #43
Merged
Merged
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
371e27b
properly get displayname of node
mwinter69 67bc346
displayname of node in pipeline
mwinter69 c252ac8
refactoring
mwinter69 faf30cd
Merge branch 'master' into configuration
mwinter69 6b4c6d7
Merge pull request #1 from jenkinsci/master
mwinter69 333ca41
jenkins and java
mwinter69 ca4eca8
fix findbugs issues in buildData
mwinter69 45a03ac
Merge branch 'master' of https://github.com/jenkinsci/logstash-plugin…
mwinter69 59d1a77
Merge branch 'jenkinsci-master'
mwinter69 96deff1
Merge pull request #3 from jenkinsci/master
mwinter69 379c5e4
Merge branch 'master' into configuration
mwinter69 1321104
javadoc and readme
mwinter69 4974276
remove unnecessary dependency to workflow-step-api
mwinter69 227611b
do the comparison if something has changed in the configuration class
mwinter69 d602a6e
incorporate feedback
mwinter69 7340194
Merge branch 'configuration2' into configuration
mwinter69 6116410
adjust link to plugin page
mwinter69 ac70407
simplify equals
mwinter69 87c93cb
host based indexers vs uri
mwinter69 f021a43
add some todos
mwinter69 fdc79cc
use URL instead of URI
mwinter69 dac27f1
use URI as persistence for elastic search url
mwinter69 f2c4a24
fix test
mwinter69 add8146
use ExpectedException rule
mwinter69 d28cab4
Merge branch 'master' into configuration
jakub-bochenski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
src/main/java/jenkins/plugins/logstash/LogstashConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package jenkins.plugins.logstash; | ||
|
||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import javax.annotation.CheckForNull; | ||
|
||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import com.cloudbees.syslog.MessageFormat; | ||
|
||
import hudson.Extension; | ||
import hudson.init.InitMilestone; | ||
import hudson.init.Initializer; | ||
import jenkins.model.GlobalConfiguration; | ||
import jenkins.plugins.logstash.LogstashInstallation.Descriptor; | ||
import jenkins.plugins.logstash.configuration.ElasticSearch; | ||
import jenkins.plugins.logstash.configuration.LogstashIndexer; | ||
import jenkins.plugins.logstash.configuration.RabbitMq; | ||
import jenkins.plugins.logstash.configuration.Redis; | ||
import jenkins.plugins.logstash.configuration.Syslog; | ||
import jenkins.plugins.logstash.persistence.LogstashIndexerDao; | ||
import jenkins.plugins.logstash.persistence.LogstashIndexerDao.IndexerType; | ||
import net.sf.json.JSONObject; | ||
|
||
@Extension | ||
public class LogstashConfiguration extends GlobalConfiguration | ||
{ | ||
private static final Logger LOGGER = Logger.getLogger(LogstashConfiguration.class.getName()); | ||
private LogstashIndexer<?> logstashIndexer; | ||
private boolean dataMigrated = false; | ||
private transient LogstashIndexer<?> activeIndexer; | ||
|
||
public LogstashConfiguration() | ||
{ | ||
load(); | ||
if (logstashIndexer != null) | ||
{ | ||
activeIndexer = logstashIndexer; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the current logstash indexer configuration. | ||
* | ||
* @return configuration instance | ||
*/ | ||
public LogstashIndexer<?> getLogstashIndexer() | ||
{ | ||
return logstashIndexer; | ||
} | ||
|
||
public void setLogstashIndexer(LogstashIndexer<?> logstashIndexer) | ||
{ | ||
this.logstashIndexer = logstashIndexer; | ||
} | ||
|
||
/** | ||
* Returns the actual instance of the logstash dao. | ||
* @return dao instance | ||
*/ | ||
@CheckForNull | ||
public LogstashIndexerDao getIndexerInstance() | ||
{ | ||
if (activeIndexer != null) | ||
{ | ||
return activeIndexer.getInstance(); | ||
} | ||
return null; | ||
} | ||
|
||
public List<?> getIndexerTypes() | ||
{ | ||
return LogstashIndexer.all(); | ||
} | ||
|
||
@Initializer(after = InitMilestone.JOB_LOADED) | ||
public void migrateData() | ||
{ | ||
if (!dataMigrated) | ||
{ | ||
Descriptor descriptor = LogstashInstallation.getLogstashDescriptor(); | ||
if (descriptor.getType() != null) | ||
{ | ||
IndexerType type = descriptor.getType(); | ||
switch (type) | ||
{ | ||
case REDIS: | ||
LOGGER.log(Level.INFO, "Migrating logstash configuration for Redis"); | ||
Redis redis = new Redis(); | ||
redis.setHost(descriptor.getHost()); | ||
redis.setPort(descriptor.getPort()); | ||
redis.setKey(descriptor.getKey()); | ||
redis.setPassword(descriptor.getPassword()); | ||
logstashIndexer = redis; | ||
break; | ||
case ELASTICSEARCH: | ||
LOGGER.log(Level.INFO, "Migrating logstash configuration for Elastic Search"); | ||
ElasticSearch es = new ElasticSearch(); | ||
es.setHost(descriptor.getHost()); | ||
es.setPort(descriptor.getPort()); | ||
es.setKey(descriptor.getKey()); | ||
es.setUsername(descriptor.getUsername()); | ||
es.setPassword(descriptor.getPassword()); | ||
logstashIndexer = es; | ||
break; | ||
case RABBIT_MQ: | ||
LOGGER.log(Level.INFO, "Migrating logstash configuration for RabbitMQ"); | ||
RabbitMq rabbitMq = new RabbitMq(); | ||
rabbitMq.setHost(descriptor.getHost()); | ||
rabbitMq.setPort(descriptor.getPort()); | ||
rabbitMq.setQueue(descriptor.getKey()); | ||
rabbitMq.setUsername(descriptor.getUsername()); | ||
rabbitMq.setPassword(descriptor.getPassword()); | ||
logstashIndexer = rabbitMq; | ||
break; | ||
case SYSLOG: | ||
LOGGER.log(Level.INFO, "Migrating logstash configuration for SYSLOG"); | ||
Syslog syslog = new Syslog(); | ||
syslog.setHost(descriptor.getHost()); | ||
syslog.setPort(descriptor.getPort()); | ||
syslog.setSyslogProtocol(descriptor.getSyslogProtocol()); | ||
switch (descriptor.getSyslogFormat()) | ||
{ | ||
case RFC3164: | ||
syslog.setMessageFormat(MessageFormat.RFC_3164); | ||
break; | ||
case RFC5424: | ||
syslog.setMessageFormat(MessageFormat.RFC_5424); | ||
break; | ||
default: | ||
syslog.setMessageFormat(MessageFormat.RFC_3164); | ||
break; | ||
} | ||
logstashIndexer = syslog; | ||
break; | ||
default: | ||
LOGGER.log(Level.INFO, "unknown logstash Indexer type: " + type); | ||
break; | ||
} | ||
activeIndexer = logstashIndexer; | ||
} | ||
dataMigrated = true; | ||
save(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean configure(StaplerRequest staplerRequest, JSONObject json) throws FormException | ||
{ | ||
// when we bind the stapler request we get a new instance of logstashIndexer | ||
staplerRequest.bindJSON(this, json); | ||
|
||
if (logstashIndexer != null && !logstashIndexer.equals(activeIndexer)) | ||
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.
|
||
{ | ||
activeIndexer = logstashIndexer; | ||
} | ||
save(); | ||
return true; | ||
} | ||
|
||
public static LogstashConfiguration getInstance() | ||
{ | ||
return GlobalConfiguration.all().get(LogstashConfiguration.class); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why not always assign? I don't see how
activeIndexer
could be non-null hereThere 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.
It can be null when you install the plugin. But the activeIndexer being null is not a problem