forked from jenkinsci/logstash-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-52697: Configuration as Code (jenkinsci#87)
- Loading branch information
1 parent
6123a61
commit 4bf1216
Showing
14 changed files
with
233 additions
and
2 deletions.
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
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
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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/jenkins/plugins/logstash/utils/URIConverter.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,22 @@ | ||
package jenkins.plugins.logstash.utils; | ||
|
||
import java.net.URI; | ||
|
||
import org.apache.commons.beanutils.converters.AbstractConverter; | ||
|
||
public class URIConverter extends AbstractConverter | ||
{ | ||
|
||
@Override | ||
protected Object convertToType(Class type, Object value) throws Throwable | ||
{ | ||
return new URI(value.toString()); | ||
} | ||
|
||
@Override | ||
protected Class getDefaultType() | ||
{ | ||
return URI.class; | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
src/test/java/jenkins/plugins/logstash/ConfigAsCodeTest.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,82 @@ | ||
package jenkins.plugins.logstash; | ||
|
||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import io.jenkins.plugins.casc.ConfigurationAsCode; | ||
import io.jenkins.plugins.casc.ConfiguratorException; | ||
import jenkins.plugins.logstash.configuration.ElasticSearch; | ||
import jenkins.plugins.logstash.configuration.Logstash; | ||
import jenkins.plugins.logstash.configuration.RabbitMq; | ||
import jenkins.plugins.logstash.configuration.Redis; | ||
|
||
public class ConfigAsCodeTest | ||
{ | ||
|
||
@Rule public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Test | ||
public void elasticSearch() throws ConfiguratorException | ||
{ | ||
ConfigurationAsCode.get().configure(ConfigAsCodeTest.class.getResource("/jcasc/elasticSearch.yaml").toString()); | ||
LogstashConfiguration c = LogstashConfiguration.getInstance(); | ||
assertThat(c.isEnabled(), is(true)); | ||
assertThat(c.isEnableGlobally(), is(true)); | ||
assertThat(c.isMilliSecondTimestamps(), is(true)); | ||
assertThat(c.getLogstashIndexer(), is(instanceOf(ElasticSearch.class))); | ||
ElasticSearch es = (ElasticSearch) c.getLogstashIndexer(); | ||
assertThat(es.getUri().toString(), is("http://localhost:9200/jenkins/test")); | ||
assertThat(es.getMimeType(), is("application/json")); | ||
assertThat(es.getUsername(), is("es")); | ||
} | ||
|
||
@Test | ||
public void logstash() throws ConfiguratorException | ||
{ | ||
ConfigurationAsCode.get().configure(ConfigAsCodeTest.class.getResource("/jcasc/logstash.yaml").toString()); | ||
LogstashConfiguration c = LogstashConfiguration.getInstance(); | ||
assertThat(c.isEnabled(), is(true)); | ||
assertThat(c.isEnableGlobally(), is(true)); | ||
assertThat(c.isMilliSecondTimestamps(), is(true)); | ||
assertThat(c.getLogstashIndexer(), is(instanceOf(Logstash.class))); | ||
Logstash logstash = (Logstash) c.getLogstashIndexer(); | ||
assertThat(logstash.getHost(), is("localhost")); | ||
assertThat(logstash.getPort(), is(9200)); | ||
} | ||
|
||
@Test | ||
public void rabbitMq() throws ConfiguratorException | ||
{ | ||
ConfigurationAsCode.get().configure(ConfigAsCodeTest.class.getResource("/jcasc/rabbitmq.yaml").toString()); | ||
LogstashConfiguration c = LogstashConfiguration.getInstance(); | ||
assertThat(c.isEnabled(), is(true)); | ||
assertThat(c.isEnableGlobally(), is(true)); | ||
assertThat(c.isMilliSecondTimestamps(), is(true)); | ||
assertThat(c.getLogstashIndexer(), is(instanceOf(RabbitMq.class))); | ||
RabbitMq rabbitMq = (RabbitMq) c.getLogstashIndexer(); | ||
assertThat(rabbitMq.getHost(), is("localhost")); | ||
assertThat(rabbitMq.getPort(), is(9200)); | ||
assertThat(rabbitMq.getVirtualHost(), is("/vhost")); | ||
assertThat(rabbitMq.getUsername(), is("rabbit")); | ||
} | ||
|
||
@Test | ||
public void redis() throws ConfiguratorException | ||
{ | ||
ConfigurationAsCode.get().configure(ConfigAsCodeTest.class.getResource("/jcasc/redis.yaml").toString()); | ||
LogstashConfiguration c = LogstashConfiguration.getInstance(); | ||
assertThat(c.isEnabled(), is(true)); | ||
assertThat(c.isEnableGlobally(), is(true)); | ||
assertThat(c.isMilliSecondTimestamps(), is(true)); | ||
assertThat(c.getLogstashIndexer(), is(instanceOf(Redis.class))); | ||
Redis redis = (Redis) c.getLogstashIndexer(); | ||
assertThat(redis.getHost(), is("localhost")); | ||
assertThat(redis.getPort(), is(9200)); | ||
assertThat(redis.getKey(), is("redis")); | ||
} | ||
} |
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,26 @@ | ||
jenkins: | ||
agentProtocols: | ||
- "JNLP4-connect" | ||
- "Ping" | ||
disableRememberMe: false | ||
mode: NORMAL | ||
numExecutors: 2 | ||
primaryView: | ||
all: | ||
name: "all" | ||
quietPeriod: 5 | ||
scmCheckoutRetryCount: 0 | ||
slaveAgentPort: 0 | ||
views: | ||
- all: | ||
name: "all" | ||
unclassified: | ||
logstashConfiguration: | ||
enableGlobally: true | ||
enabled: true | ||
logstashIndexer: | ||
elasticSearch: | ||
mimeType: "application/json" | ||
uri: "http://localhost:9200/jenkins/test" | ||
username: "es" | ||
milliSecondTimestamps: true |
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,25 @@ | ||
jenkins: | ||
agentProtocols: | ||
- "JNLP4-connect" | ||
- "Ping" | ||
disableRememberMe: false | ||
mode: NORMAL | ||
numExecutors: 2 | ||
primaryView: | ||
all: | ||
name: "all" | ||
quietPeriod: 5 | ||
scmCheckoutRetryCount: 0 | ||
slaveAgentPort: 0 | ||
views: | ||
- all: | ||
name: "all" | ||
unclassified: | ||
logstashConfiguration: | ||
enableGlobally: true | ||
enabled: true | ||
logstashIndexer: | ||
logstash: | ||
host: "localhost" | ||
port: 9200 | ||
milliSecondTimestamps: true |
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,27 @@ | ||
jenkins: | ||
agentProtocols: | ||
- "JNLP4-connect" | ||
- "Ping" | ||
disableRememberMe: false | ||
mode: NORMAL | ||
numExecutors: 2 | ||
primaryView: | ||
all: | ||
name: "all" | ||
quietPeriod: 5 | ||
scmCheckoutRetryCount: 0 | ||
slaveAgentPort: 0 | ||
views: | ||
- all: | ||
name: "all" | ||
unclassified: | ||
logstashConfiguration: | ||
enableGlobally: true | ||
enabled: true | ||
logstashIndexer: | ||
rabbitMq: | ||
host: "localhost" | ||
port: 9200 | ||
virtualHost: "/vhost" | ||
username: "rabbit" | ||
milliSecondTimestamps: true |
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,26 @@ | ||
jenkins: | ||
agentProtocols: | ||
- "JNLP4-connect" | ||
- "Ping" | ||
disableRememberMe: false | ||
mode: NORMAL | ||
numExecutors: 2 | ||
primaryView: | ||
all: | ||
name: "all" | ||
quietPeriod: 5 | ||
scmCheckoutRetryCount: 0 | ||
slaveAgentPort: 0 | ||
views: | ||
- all: | ||
name: "all" | ||
unclassified: | ||
logstashConfiguration: | ||
enableGlobally: true | ||
enabled: true | ||
logstashIndexer: | ||
redis: | ||
host: "localhost" | ||
port: 9200 | ||
key: "redis" | ||
milliSecondTimestamps: true |