Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions demo/src/main/groovy/4_Jobs.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//TODO: Migrate to JCasC once it supports disabling via system property

import hudson.model.FreeStyleProject
import jenkins.model.Jenkins
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition
import org.jenkinsci.plugins.workflow.job.WorkflowJob
Expand All @@ -11,8 +13,8 @@ if (!Boolean.getBoolean("io.jenkins.demo.external-task-logging-elk.enabled")) {
println("-- Creating Jobs")
//TODO: Classes do not work here, so some copy-paste for now

if(Jenkins.instance.getItem("Demo_master") == null) {
WorkflowJob project1 = Jenkins.instance.createProject(WorkflowJob.class, "Demo_master")
if(Jenkins.instance.getItem("Pipeline_master") == null) {
WorkflowJob project1 = Jenkins.instance.createProject(WorkflowJob.class, "Pipeline_master")
project1.definition = new CpsFlowDefinition(
"node('master') {\n" +
" sh \"ping -c 20 google.com\"\n" +
Expand All @@ -22,8 +24,8 @@ if(Jenkins.instance.getItem("Demo_master") == null) {
project1.save()
}

if(Jenkins.instance.getItem("Demo_agent") == null) {
WorkflowJob project2 = Jenkins.instance.createProject(WorkflowJob.class, "Demo_agent")
if(Jenkins.instance.getItem("Pipeline_agent") == null) {
WorkflowJob project2 = Jenkins.instance.createProject(WorkflowJob.class, "Pipeline_agent")
project2.definition = new CpsFlowDefinition(
"node('agent') {\n" +
" sh \"echo Hello, world!\"\n" +
Expand All @@ -35,8 +37,8 @@ if(Jenkins.instance.getItem("Demo_agent") == null) {
project2.save()
}

if(Jenkins.instance.getItem("Demo_parallel") == null) {
WorkflowJob project3 = Jenkins.instance.createProject(WorkflowJob.class, "Demo_parallel")
if(Jenkins.instance.getItem("Pipeline_parallel") == null) {
WorkflowJob project3 = Jenkins.instance.createProject(WorkflowJob.class, "Pipeline_parallel")
project3.definition = new CpsFlowDefinition(
"parallel local: {\n" +
" node('master') {\n" +
Expand Down
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<properties>
<revision>1.0-alpha-1</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.131-SNAPSHOT</jenkins.version>
<jenkins-core.version>2.137-20180807.141417-2</jenkins-core.version>
<jenkins-war.version>2.137-20180807.141447-2</jenkins-war.version>
<java.level>8</java.level>
<useBeta>true</useBeta>
</properties>
Expand All @@ -43,7 +44,7 @@
<dependency>
<groupId>io.jenkins.plugins.external-logging</groupId>
<artifactId>external-logging-api</artifactId>
<version>1.0-alpha-1-SNAPSHOT</version>
<version>1.0-alpha-1-20180807.155933-3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -118,6 +119,10 @@
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
<repository>
<id>incrementals</id>
<url>https://repo.jenkins-ci.org/incrementals/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.Map;
import java.util.logging.Level;
Expand All @@ -32,7 +33,9 @@ public class ElasticsearchEventWriter extends ExternalLoggingEventWriter {
private boolean connectionBroken;

public ElasticsearchEventWriter(@CheckForNull String prefix,
@Nonnull ElasticSearchDao dao) {
@Nonnull ElasticSearchDao dao,
@Nonnull Charset charset) {
super(charset);
this.prefix = prefix;
this.dao = dao;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package io.jenkins.plugins.extlogging.elasticsearch;

import hudson.console.AnnotatedLargeText;
import io.jenkins.plugins.extlogging.api.ExternalLogBrowser;
import io.jenkins.plugins.extlogging.elasticsearch.util.ElasticSearchDao;
import jenkins.model.logging.LogBrowser;
import jenkins.model.logging.Loggable;
import jenkins.model.logging.impl.BrokenAnnotatedLargeText;

import javax.annotation.CheckForNull;
import java.io.IOException;

/**
* Log browser for Elasticsearch.
* @author Oleg Nenashev
* @since TODO
*/
public class ElasticsearchLogBrowser extends LogBrowser {
public class ElasticsearchLogBrowser extends ExternalLogBrowser {

//TODO(oleg-nenashev): jglick requests example of several implementations
public ElasticsearchLogBrowser(Loggable loggable) {
super(loggable);
}
Expand Down Expand Up @@ -43,4 +45,10 @@ public AnnotatedLargeText stepLog(@CheckForNull String stepId, boolean b) {

return new ElasticsearchLogLargeTextProvider(dao, getOwner(), stepId).getLogText();
}

@Override
public boolean deleteLog() {
// Not supported
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import hudson.Extension;
import hudson.model.Run;
import io.jenkins.plugins.extlogging.api.ExternalLogBrowser;
import io.jenkins.plugins.extlogging.api.ExternalLogBrowserFactory;
import io.jenkins.plugins.extlogging.api.ExternalLogBrowserFactoryDescriptor;
import jenkins.model.logging.LogBrowser;
import jenkins.model.logging.Loggable;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand All @@ -25,15 +25,15 @@ public ElasticsearchLogBrowserFactory() {

@CheckForNull
@Override
public LogBrowser create(Loggable loggable) {
public ExternalLogBrowser create(Loggable loggable) {
if (loggable instanceof Run<?, ?>) {
return new ElasticsearchLogBrowser((Run<?, ?>) loggable);
}
return null;
}

@Extension
@Symbol("logstashElasticsearch")
@Symbol("elasticsearch")
public static class DescriptorImpl extends ExternalLogBrowserFactoryDescriptor {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.io.OutputStream;
import java.util.List;

import io.jenkins.plugins.extlogging.api.ExternalLogBrowser;
import io.jenkins.plugins.extlogging.api.ExternalLoggingEventWriter;
import io.jenkins.plugins.extlogging.api.OutputStreamWrapper;
import io.jenkins.plugins.extlogging.api.ExternalLoggingMethod;
import io.jenkins.plugins.extlogging.api.impl.ExternalLoggingOutputStream;
import io.jenkins.plugins.extlogging.elasticsearch.util.ElasticSearchDao;
import jenkins.model.logging.LogBrowser;
import jenkins.model.logging.Loggable;

import javax.annotation.CheckForNull;
Expand All @@ -31,14 +31,14 @@ public ElasticsearchLoggingMethod(Loggable loggable, @CheckForNull String prefix
}

@Override
public LogBrowser getDefaultLogBrowser() {
public ExternalLogBrowser getDefaultLogBrowser() {
return new ElasticsearchLogBrowser(getOwner());
}

@Override
protected ExternalLoggingEventWriter _createWriter() throws IOException {
ElasticSearchDao dao = ElasticsearchGlobalConfiguration.getInstance().toDao();
return new ElasticsearchEventWriter(prefix, dao);
return new ElasticsearchEventWriter(prefix, dao, getOwner().getCharset());
}

// @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public UncompressedAnnotatedLargeText(ByteBuffer memory, Charset charset, boolea
public long writeHtmlTo(long start, Writer w) throws IOException {
ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(
w, createAnnotator(Stapler.getCurrentRequest()), context, charset);
long r = super.writeLogTo(start, caw);
super.writeLogTo(start, caw);
caw.flush();
long initial = memory.length();
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package io.jenkins.plugins.extlogging.elasticsearch.util;

import com.google.common.collect.Range;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
Expand Down Expand Up @@ -54,6 +55,8 @@
* @author Liam Newman
* @author Oleg Nenashev
*/
//TODO: fix before the release
@SuppressFBWarnings(value = "SE_NO_SERIALVERSIONID", justification = "To be set before the release")
public class ElasticSearchDao implements Serializable {

private static final Range<Integer> SUCCESS_CODES = closedOpen(200,300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void eol(byte[] b, int len) throws IOException {
try {
this.flush();
if (!logstash.isConnectionBroken()) {
String line = new String(b, 0, len).trim();
String line = new String(b, 0, len, logstash.getCharset()).trim();
line = ConsoleNote.removeNotes(line);
logstash.writeMessage(prefix + line);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

/**
* @author Oleg Nenashev
* @since TODO
Expand Down Expand Up @@ -41,6 +44,7 @@ public void spotcheck_Default() throws Exception {
//to automate handling of such use-cases
Thread.sleep(10000);
j.assertLogContains("Hello", build);
assertThat(build.getLog(), not(containsString("[[")));
}

@Test
Expand Down