Skip to content

Commit e95f786

Browse files
authored
Update Events to 1.24 model (docker-java#669)
* added event type in Event class docker-java#650 * added missing import for JsonProperty * added CheckForNull * Sync event model to 1.24 Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>
1 parent 36d17ca commit e95f786

File tree

5 files changed

+384
-13
lines changed

5 files changed

+384
-13
lines changed

src/main/java/com/github/dockerjava/api/model/Event.java

Lines changed: 171 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,78 @@
11
package com.github.dockerjava.api.model;
22

3+
import org.apache.commons.lang.builder.EqualsBuilder;
4+
import org.apache.commons.lang.builder.HashCodeBuilder;
35
import org.apache.commons.lang.builder.ToStringBuilder;
46

57
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
68
import com.fasterxml.jackson.annotation.JsonInclude;
79
import com.fasterxml.jackson.annotation.JsonInclude.Include;
10+
import com.fasterxml.jackson.annotation.JsonProperty;
11+
12+
import javax.annotation.CheckForNull;
13+
14+
import static org.apache.commons.lang.builder.ToStringStyle.SHORT_PREFIX_STYLE;
815

916
/**
1017
* Representation of a Docker event.
1118
*/
1219
@JsonIgnoreProperties(ignoreUnknown = true)
1320
@JsonInclude(Include.NON_NULL)
1421
public class Event {
22+
23+
/**
24+
* @since 1.16
25+
*/
26+
@JsonProperty("status")
1527
private String status;
1628

29+
/**
30+
* @since 1.16
31+
*/
32+
@JsonProperty("id")
1733
private String id;
1834

35+
/**
36+
* @since 1.16
37+
*/
38+
@JsonProperty("from")
1939
private String from;
2040

41+
/**
42+
* ??
43+
*/
44+
@JsonProperty("node")
45+
private Node node;
46+
47+
/*
48+
* @since 1.
49+
*/
50+
@JsonProperty("Type")
51+
private EventType type;
52+
53+
/**
54+
* @since 1.22
55+
*/
56+
@JsonProperty("Action")
57+
private String action;
58+
59+
/**
60+
* @since 1.22
61+
*/
62+
@JsonProperty("Actor")
63+
private EventActor actor;
64+
65+
/**
66+
* @since 1.16
67+
*/
68+
@JsonProperty("time")
2169
private Long time;
2270

23-
@JsonIgnoreProperties
24-
private Node node;
71+
/**
72+
* @since 1.21
73+
*/
74+
@JsonProperty("timeNano")
75+
private Long timeNano;
2576

2677
/**
2778
* Default constructor for the deserialization.
@@ -32,16 +83,12 @@ public Event() {
3283
/**
3384
* Constructor.
3485
*
35-
* @param id
36-
* Container ID
37-
* @param status
38-
* Status string. List of statuses is available in <a
39-
* href="https://docs.docker.com/reference/api/docker_remote_api_v1.16/#monitor-dockers-events">Docker API v.1.16</a>
40-
* @param from
41-
* Image, from which the container has been created
42-
* @param time
43-
* Event time The time is specified in milliseconds since January 1, 1970, 00:00:00 GMT
44-
* @since TODO
86+
* @param id Container ID
87+
* @param status Status string. List of statuses is available in <a
88+
* href="https://docs.docker.com/reference/api/docker_remote_api_v1.16/#monitor-dockers-events">Docker API v.1.16</a>
89+
* @param from Image, from which the container has been created
90+
* @param time Event time The time is specified in milliseconds since January 1, 1970, 00:00:00 GMT
91+
* @since 1.16
4592
*/
4693
public Event(String status, String id, String from, Long time) {
4794
this.status = status;
@@ -60,6 +107,14 @@ public String getStatus() {
60107
return status;
61108
}
62109

110+
/**
111+
* @see #status
112+
*/
113+
public Event withStatus(String status) {
114+
this.status = status;
115+
return this;
116+
}
117+
63118
/**
64119
* Get ID of docker container.
65120
*
@@ -69,6 +124,14 @@ public String getId() {
69124
return id;
70125
}
71126

127+
/**
128+
* @see #id
129+
*/
130+
public Event withId(String id) {
131+
this.id = id;
132+
return this;
133+
}
134+
72135
/**
73136
* Get source image of the container.
74137
*
@@ -78,6 +141,14 @@ public String getFrom() {
78141
return from;
79142
}
80143

144+
/**
145+
* @see #from
146+
*/
147+
public Event withFrom(String from) {
148+
this.from = from;
149+
return this;
150+
}
151+
81152
/**
82153
* Get the event time. The time is specified in milliseconds since January 1, 1970, 00:00:00 GMT
83154
*
@@ -87,15 +158,102 @@ public Long getTime() {
87158
return time;
88159
}
89160

161+
/**
162+
* @see #time
163+
*/
164+
public Event withTime(Long time) {
165+
this.time = time;
166+
return this;
167+
}
168+
169+
/**
170+
* @see #timeNano
171+
*/
172+
@CheckForNull
173+
public Long getTimeNano() {
174+
return timeNano;
175+
}
176+
177+
/**
178+
* @see #timeNano
179+
*/
180+
public Event withTimenano(Long timenano) {
181+
this.timeNano = timenano;
182+
return this;
183+
}
184+
90185
/**
91186
* Returns the node when working against docker swarm
92187
*/
93188
public Node getNode() {
94189
return node;
95190
}
96191

192+
/**
193+
* @see #node
194+
*/
195+
public Event withNode(Node node) {
196+
this.node = node;
197+
return this;
198+
}
199+
200+
@CheckForNull
201+
public EventType getType() {
202+
return type;
203+
}
204+
205+
/**
206+
* @see #type
207+
*/
208+
public Event withType(EventType type) {
209+
this.type = type;
210+
return this;
211+
}
212+
213+
/**
214+
* @see #action
215+
*/
216+
@CheckForNull
217+
public String getAction() {
218+
return action;
219+
}
220+
221+
/**
222+
* @see #action
223+
*/
224+
public Event withAction(String action) {
225+
this.action = action;
226+
return this;
227+
}
228+
229+
/**
230+
* @see #actor
231+
*/
232+
@CheckForNull
233+
public EventActor getActor() {
234+
return actor;
235+
}
236+
237+
/**
238+
* @see #actor
239+
*/
240+
public Event withEventActor(EventActor actor) {
241+
this.actor = actor;
242+
return this;
243+
}
244+
97245
@Override
98246
public String toString() {
99-
return ToStringBuilder.reflectionToString(this);
247+
return ToStringBuilder.reflectionToString(this, SHORT_PREFIX_STYLE);
248+
}
249+
250+
@Override
251+
public boolean equals(Object o) {
252+
return EqualsBuilder.reflectionEquals(this, o);
253+
}
254+
255+
@Override
256+
public int hashCode() {
257+
return HashCodeBuilder.reflectionHashCode(this);
100258
}
101259
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import org.apache.commons.lang.builder.EqualsBuilder;
5+
import org.apache.commons.lang.builder.HashCodeBuilder;
6+
import org.apache.commons.lang.builder.ToStringBuilder;
7+
8+
import javax.annotation.CheckForNull;
9+
import java.io.Serializable;
10+
import java.util.Map;
11+
12+
/**
13+
* @author Kanstantsin Shautsou
14+
* @since 1.22
15+
*/
16+
public class EventActor implements Serializable {
17+
private static final long serialVersionUID = 1L;
18+
19+
/**
20+
* @since 1.22
21+
*/
22+
@JsonProperty("ID")
23+
private String id;
24+
25+
/**
26+
* @since 1.22
27+
*/
28+
@JsonProperty("Attributes")
29+
private Map<String, String> attributes;
30+
31+
/**
32+
* @see #id
33+
*/
34+
@CheckForNull
35+
public String getId() {
36+
return id;
37+
}
38+
39+
/**
40+
* @see #id
41+
*/
42+
public EventActor withId(String id) {
43+
this.id = id;
44+
return this;
45+
}
46+
47+
/**
48+
* @see #attributes
49+
*/
50+
@CheckForNull
51+
public Map<String, String> getAttributes() {
52+
return attributes;
53+
}
54+
55+
/**
56+
* @see #attributes
57+
*/
58+
public EventActor withAttributes(Map<String, String> attributes) {
59+
this.attributes = attributes;
60+
return this;
61+
}
62+
63+
@Override
64+
public String toString() {
65+
return ToStringBuilder.reflectionToString(this);
66+
}
67+
68+
@Override
69+
public boolean equals(Object o) {
70+
return EqualsBuilder.reflectionEquals(this, o);
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return HashCodeBuilder.reflectionHashCode(this);
76+
}
77+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
6+
import javax.annotation.Nonnull;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
/**
11+
* @since 1.24
12+
*/
13+
public enum EventType {
14+
/**
15+
* @since 1.24
16+
*/
17+
CONTAINER("container"),
18+
19+
/**
20+
* @since 1.24
21+
*/
22+
DAEMON("daemon"),
23+
24+
/**
25+
* @since 1.24
26+
*/
27+
IMAGE("image"),
28+
NETWORK("network"),
29+
PLUGIN("plugin"),
30+
VOLUME("volume");
31+
32+
private static final Map<String, EventType> EVENT_TYPES = new HashMap<>();
33+
34+
static {
35+
for (EventType t : values()) {
36+
EVENT_TYPES.put(t.name().toLowerCase(), t);
37+
}
38+
}
39+
40+
private String value;
41+
42+
EventType(@Nonnull String value) {
43+
this.value = value;
44+
}
45+
46+
@JsonValue
47+
public String getValue() {
48+
return value;
49+
}
50+
51+
@JsonCreator
52+
public static EventType forValue(String s) {
53+
return EVENT_TYPES.get(s);
54+
}
55+
}

0 commit comments

Comments
 (0)