Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public interface EventsCmd extends DockerCmd<ExecutorService> {

public EventsCmd withEventCallback(EventCallback eventCallback);

public String getFilters();

public EventsCmd withFilters(String filters);

public static interface Exec extends DockerCmdExec<EventsCmd, ExecutorService> {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.dockerjava.core.command;

import static com.google.common.base.Preconditions.*;

import java.util.concurrent.ExecutorService;

import com.github.dockerjava.api.command.EventCallback;
Expand All @@ -16,6 +18,8 @@ public class EventsCmdImpl extends AbstrDockerCmd<EventsCmd, ExecutorService> im

private EventCallback eventCallback;

private String filters;

public EventsCmdImpl(EventsCmd.Exec exec, EventCallback eventCallback) {
super(exec);
withEventCallback(eventCallback);
Expand All @@ -39,6 +43,13 @@ public EventsCmd withEventCallback(EventCallback eventCallback) {
return this;
}

@Override
public EventsCmd withFilters(String filters) {
checkNotNull(filters, "filters have not been specified");
this.filters = filters;
return this;
}

@Override
public String getSince() {
return since;
Expand All @@ -54,6 +65,11 @@ public EventCallback getEventCallback() {
return eventCallback;
}

@Override
public String getFilters() {
return filters;
}

@Override
public ExecutorService exec() {
return super.exec();
Expand All @@ -62,6 +78,7 @@ public ExecutorService exec() {
@Override
public String toString() {
return new StringBuilder("events").append(since != null ? " --since=" + since : "")
.append(until != null ? " --until=" + until : "").toString();
.append(until != null ? " --until=" + until : "")
.append(filters != null ? " --filters=" + filters : "").toString();
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/github/dockerjava/jaxrs/EventsCmdExec.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.dockerjava.jaxrs;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.net.UrlEscapers.*;

import java.io.InputStream;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -36,6 +37,9 @@ protected ExecutorService execute(EventsCmd command) {
WebTarget webResource = getBaseResource().path("/events").queryParam("since", command.getSince())
.queryParam("until", command.getUntil());

if (command.getFilters() != null)
webResource = webResource.queryParam("filters", urlPathSegmentEscaper().escape(command.getFilters()));

LOGGER.trace("GET: {}", webResource);
EventNotifier eventNotifier = EventNotifier.create(command.getEventCallback(), webResource);
executorService.submit(eventNotifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ public void testEventStreaming1() throws InterruptedException, IOException {
assertTrue(zeroCount, "Received only: " + eventCallback.getEvents());
}

@Test
public void testEventStreamingWithFilter() throws InterruptedException, IOException {
// Don't include other tests events
TimeUnit.SECONDS.sleep(1);

CountDownLatch countDownLatch = new CountDownLatch(1);
EventCallbackTest eventCallback = new EventCallbackTest(countDownLatch);

EventsCmd eventsCmd = dockerClient.eventsCmd(eventCallback).withFilters("{\"event\":[\"start\"]}");
ExecutorService executorService = eventsCmd.exec();

generateEvents();

boolean zeroCount = countDownLatch.await(10, TimeUnit.SECONDS);
executorService.shutdown();
eventCallback.close();
assertTrue(zeroCount, "Received only: " + eventCallback.getEvents());
}

@Test(groups = "ignoreInCircleCi")
public void testEventStreaming2() throws InterruptedException, IOException {
// Don't include other tests events
Expand Down