Skip to content
Merged
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
184 changes: 171 additions & 13 deletions src/main/java/com/github/dockerjava/api/model/Event.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,78 @@
package com.github.dockerjava.api.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import javax.annotation.CheckForNull;

import static org.apache.commons.lang.builder.ToStringStyle.SHORT_PREFIX_STYLE;

/**
* Representation of a Docker event.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class Event {

/**
* @since 1.16
*/
@JsonProperty("status")
private String status;

/**
* @since 1.16
*/
@JsonProperty("id")
private String id;

/**
* @since 1.16
*/
@JsonProperty("from")
private String from;

/**
* ??
*/
@JsonProperty("node")
private Node node;

/*
* @since 1.
*/
@JsonProperty("Type")
private EventType type;

/**
* @since 1.22
*/
@JsonProperty("Action")
private String action;

/**
* @since 1.22
*/
@JsonProperty("Actor")
private EventActor actor;

/**
* @since 1.16
*/
@JsonProperty("time")
private Long time;

@JsonIgnoreProperties
private Node node;
/**
* @since 1.21
*/
@JsonProperty("timeNano")
private Long timeNano;

/**
* Default constructor for the deserialization.
Expand All @@ -32,16 +83,12 @@ public Event() {
/**
* Constructor.
*
* @param id
* Container ID
* @param status
* Status string. List of statuses is available in <a
* href="https://docs.docker.com/reference/api/docker_remote_api_v1.16/#monitor-dockers-events">Docker API v.1.16</a>
* @param from
* Image, from which the container has been created
* @param time
* Event time The time is specified in milliseconds since January 1, 1970, 00:00:00 GMT
* @since TODO
* @param id Container ID
* @param status Status string. List of statuses is available in <a
* href="https://docs.docker.com/reference/api/docker_remote_api_v1.16/#monitor-dockers-events">Docker API v.1.16</a>
* @param from Image, from which the container has been created
* @param time Event time The time is specified in milliseconds since January 1, 1970, 00:00:00 GMT
* @since 1.16
*/
public Event(String status, String id, String from, Long time) {
this.status = status;
Expand All @@ -60,6 +107,14 @@ public String getStatus() {
return status;
}

/**
* @see #status
*/
public Event withStatus(String status) {
this.status = status;
return this;
}

/**
* Get ID of docker container.
*
Expand All @@ -69,6 +124,14 @@ public String getId() {
return id;
}

/**
* @see #id
*/
public Event withId(String id) {
this.id = id;
return this;
}

/**
* Get source image of the container.
*
Expand All @@ -78,6 +141,14 @@ public String getFrom() {
return from;
}

/**
* @see #from
*/
public Event withFrom(String from) {
this.from = from;
return this;
}

/**
* Get the event time. The time is specified in milliseconds since January 1, 1970, 00:00:00 GMT
*
Expand All @@ -87,15 +158,102 @@ public Long getTime() {
return time;
}

/**
* @see #time
*/
public Event withTime(Long time) {
this.time = time;
return this;
}

/**
* @see #timeNano
*/
@CheckForNull
public Long getTimeNano() {
return timeNano;
}

/**
* @see #timeNano
*/
public Event withTimenano(Long timenano) {
this.timeNano = timenano;
return this;
}

/**
* Returns the node when working against docker swarm
*/
public Node getNode() {
return node;
}

/**
* @see #node
*/
public Event withNode(Node node) {
this.node = node;
return this;
}

@CheckForNull
public EventType getType() {
return type;
}

/**
* @see #type
*/
public Event withType(EventType type) {
this.type = type;
return this;
}

/**
* @see #action
*/
@CheckForNull
public String getAction() {
return action;
}

/**
* @see #action
*/
public Event withAction(String action) {
this.action = action;
return this;
}

/**
* @see #actor
*/
@CheckForNull
public EventActor getActor() {
return actor;
}

/**
* @see #actor
*/
public Event withEventActor(EventActor actor) {
this.actor = actor;
return this;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
return ToStringBuilder.reflectionToString(this, SHORT_PREFIX_STYLE);
}

@Override
public boolean equals(Object o) {
return EqualsBuilder.reflectionEquals(this, o);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
77 changes: 77 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/EventActor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.annotation.CheckForNull;
import java.io.Serializable;
import java.util.Map;

/**
* @author Kanstantsin Shautsou
* @since 1.22
*/
public class EventActor implements Serializable {
private static final long serialVersionUID = 1L;

/**
* @since 1.22
*/
@JsonProperty("ID")
private String id;

/**
* @since 1.22
*/
@JsonProperty("Attributes")
private Map<String, String> attributes;

/**
* @see #id
*/
@CheckForNull
public String getId() {
return id;
}

/**
* @see #id
*/
public EventActor withId(String id) {
this.id = id;
return this;
}

/**
* @see #attributes
*/
@CheckForNull
public Map<String, String> getAttributes() {
return attributes;
}

/**
* @see #attributes
*/
public EventActor withAttributes(Map<String, String> attributes) {
this.attributes = attributes;
return this;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}

@Override
public boolean equals(Object o) {
return EqualsBuilder.reflectionEquals(this, o);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
55 changes: 55 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/EventType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;

/**
* @since 1.24
*/
public enum EventType {
/**
* @since 1.24
*/
CONTAINER("container"),

/**
* @since 1.24
*/
DAEMON("daemon"),

/**
* @since 1.24
*/
IMAGE("image"),
NETWORK("network"),
PLUGIN("plugin"),
VOLUME("volume");

private static final Map<String, EventType> EVENT_TYPES = new HashMap<>();

static {
for (EventType t : values()) {
EVENT_TYPES.put(t.name().toLowerCase(), t);
}
}

private String value;

EventType(@Nonnull String value) {
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}

@JsonCreator
public static EventType forValue(String s) {
return EVENT_TYPES.get(s);
}
}
Loading