Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
Move Event Type enum from DockerClient to Event
Browse files Browse the repository at this point in the history
  • Loading branch information
johnflavin committed Jan 3, 2017
1 parent bc11d95 commit 06ef7c8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
26 changes: 3 additions & 23 deletions src/main/java/com/spotify/docker/client/DockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.spotify.docker.client.messages.ContainerExit;
import com.spotify.docker.client.messages.ContainerInfo;
import com.spotify.docker.client.messages.ContainerStats;
import com.spotify.docker.client.messages.Event;
import com.spotify.docker.client.messages.ExecCreation;
import com.spotify.docker.client.messages.ExecState;
import com.spotify.docker.client.messages.Image;
Expand Down Expand Up @@ -2322,7 +2323,7 @@ public static EventsParam daemon(final String daemon) {
* Show events of a given type. For instance, "type=image" for all image events.
* @param type A type of event. Possible values: container, image, volume, network, or daemon
* @return EventsParam
* @deprecated Use {@link #type(EventType)}.
* @deprecated Use {@link #type(Event.Type)}.
* @since API 1.22
*/
@Deprecated
Expand All @@ -2336,7 +2337,7 @@ public static EventsParam type(final String type) {
* @return EventsParam
* @since API 1.22
*/
public static EventsParam type(final EventType type) {
public static EventsParam type(final Event.Type type) {
return filter("type", type.getName());
}

Expand All @@ -2363,27 +2364,6 @@ public static EventsParam label(final String label) {
return label(label, null);
}

/**
* Valid event types for EventsParam.type
*/
public enum EventType {
CONTAINER("container"),
IMAGE("image"),
VOLUME("volume"),
NETWORK("network"),
DAEMON("daemon");

private final String name;

EventType(final String name) {
this.name = name;
}

public String getName() {
return name;
}
}

}

/**
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/spotify/docker/client/messages/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
Expand All @@ -39,7 +41,7 @@ public class Event {
@JsonProperty("status") private String status;
@JsonProperty("id") private String id;
@JsonProperty("from") private String from;
@JsonProperty("Type") private String type;
@JsonProperty("Type") private Type type;
@JsonProperty("Action") private String action;
@JsonProperty("Actor") private Actor actor;
@JsonProperty("time")
Expand Down Expand Up @@ -80,7 +82,7 @@ public String from() {
return from;
}

public String type() {
public Type type() {
return type;
}

Expand Down Expand Up @@ -189,4 +191,24 @@ public String toString() {
.toString();
}
}

public enum Type {
CONTAINER("container"),
IMAGE("image"),
VOLUME("volume"),
NETWORK("network"),
DAEMON("daemon");

private final String name;

@JsonCreator
Type(final String name) {
this.name = name;
}

@JsonValue
public String getName() {
return name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.Lists.newArrayList;
import static com.spotify.docker.client.DefaultDockerClient.NO_TIMEOUT;
import static com.spotify.docker.client.DockerClient.EventsParam.EventType.CONTAINER;
import static com.spotify.docker.client.DockerClient.EventsParam.EventType.IMAGE;
import static com.spotify.docker.client.DockerClient.EventsParam.EventType.NETWORK;
import static com.spotify.docker.client.DockerClient.EventsParam.EventType.VOLUME;
import static com.spotify.docker.client.DockerClient.EventsParam.since;
import static com.spotify.docker.client.DockerClient.EventsParam.type;
import static com.spotify.docker.client.DockerClient.EventsParam.until;
Expand All @@ -53,6 +49,10 @@
import static com.spotify.docker.client.DockerClient.LogsParam.tail;
import static com.spotify.docker.client.DockerClient.LogsParam.timestamps;
import static com.spotify.docker.client.VersionCompare.compareVersion;
import static com.spotify.docker.client.messages.Event.Type.CONTAINER;
import static com.spotify.docker.client.messages.Event.Type.IMAGE;
import static com.spotify.docker.client.messages.Event.Type.NETWORK;
import static com.spotify.docker.client.messages.Event.Type.VOLUME;
import static com.spotify.docker.client.messages.RemovedImage.Type.UNTAGGED;
import static java.lang.Long.toHexString;
import static java.lang.String.format;
Expand Down Expand Up @@ -1994,7 +1994,7 @@ public void testEventTypes() throws Exception {
stream.hasNext());

final Event volumeCreate = stream.next();
assertEquals(VOLUME.getName(), volumeCreate.type());
assertEquals(VOLUME, volumeCreate.type());
assertEquals("create", volumeCreate.action());
assertEquals(volumeName, volumeCreate.actor().id());
assertThat(volumeCreate.actor().attributes(), hasEntry("driver", "local"));
Expand All @@ -2004,7 +2004,7 @@ public void testEventTypes() throws Exception {
+ "Expected a volume mount event.",
stream.hasNext());
final Event volumeMount = stream.next();
assertEquals(VOLUME.getName(), volumeMount.type());
assertEquals(VOLUME, volumeMount.type());
assertEquals("mount", volumeMount.action());
assertEquals(volumeName, volumeMount.actor().id());
final Map<String, String> mountAttributes = volumeMount.actor().attributes();
Expand All @@ -2019,7 +2019,7 @@ public void testEventTypes() throws Exception {
+ "Expected a volume unmount event.",
stream.hasNext());
final Event volumeUnmount = stream.next();
assertEquals(VOLUME.getName(), volumeUnmount.type());
assertEquals(VOLUME, volumeUnmount.type());
assertEquals("unmount", volumeUnmount.action());
assertEquals(volumeName, volumeUnmount.actor().id());
assertThat(volumeUnmount.actor().attributes(), hasEntry("driver", "local"));
Expand All @@ -2035,7 +2035,7 @@ public void testEventTypes() throws Exception {
assertTrue("Docker did not return any network events.",
stream.hasNext());
final Event networkConnect = stream.next();
assertEquals(NETWORK.getName(), networkConnect.type());
assertEquals(NETWORK, networkConnect.type());
assertEquals("connect", networkConnect.action());
assertNotNull(networkConnect.actor().id()); // not sure how to get the network id
assertThat(networkConnect.actor().attributes(), hasEntry("container", containerId));
Expand All @@ -2046,7 +2046,7 @@ public void testEventTypes() throws Exception {
+ "Expected a network disconnect event.",
stream.hasNext());
final Event networkDisconnect = stream.next();
assertEquals(NETWORK.getName(), networkDisconnect.type());
assertEquals(NETWORK, networkDisconnect.type());
assertEquals("disconnect", networkDisconnect.action());
assertEquals(networkDisconnect.actor().id(), networkDisconnect.actor().id());
assertThat(networkDisconnect.actor().attributes(), hasEntry("container", containerId));
Expand Down Expand Up @@ -2079,7 +2079,7 @@ private void imageEventAssertions(final Event event,
final String action) throws Exception {
assertThat(event.time(), notNullValue());
if (dockerApiVersionAtLeast("1.22")) {
assertEquals(IMAGE.getName(), event.type());
assertEquals(IMAGE, event.type());
assertEquals(action, event.action());
assertEquals(imageName, event.actor().id());

Expand All @@ -2098,7 +2098,7 @@ private void containerEventAssertions(final Event event,
final String imageName) throws Exception {
assertThat(event.time(), notNullValue());
if (dockerApiVersionAtLeast("1.22")) {
assertEquals(CONTAINER.getName(), event.type());
assertEquals(CONTAINER, event.type());
assertEquals(action, event.action());

assertNotNull(event.actor());
Expand Down

0 comments on commit 06ef7c8

Please sign in to comment.