Skip to content

Commit feb5188

Browse files
committed
Sync event model to 1.24
1 parent 652510b commit feb5188

File tree

5 files changed

+373
-21
lines changed

5 files changed

+373
-21
lines changed

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

Lines changed: 160 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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;
@@ -9,28 +11,68 @@
911

1012
import javax.annotation.CheckForNull;
1113

14+
import static org.apache.commons.lang.builder.ToStringStyle.SHORT_PREFIX_STYLE;
15+
1216
/**
1317
* Representation of a Docker event.
1418
*/
1519
@JsonIgnoreProperties(ignoreUnknown = true)
1620
@JsonInclude(Include.NON_NULL)
1721
public class Event {
22+
23+
/**
24+
* @since 1.16
25+
*/
26+
@JsonProperty("status")
1827
private String status;
1928

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

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

24-
private Long time;
25-
26-
@JsonIgnoreProperties
41+
/**
42+
* ??
43+
*/
44+
@JsonProperty("node")
2745
private Node node;
2846

2947
/*
30-
* @since API Version 1.24
48+
* @since 1.
3149
*/
3250
@JsonProperty("Type")
33-
private String 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")
69+
private Long time;
70+
71+
/**
72+
* @since 1.21
73+
*/
74+
@JsonProperty("timeNano")
75+
private Long timeNano;
3476

3577
/**
3678
* Default constructor for the deserialization.
@@ -41,16 +83,12 @@ public Event() {
4183
/**
4284
* Constructor.
4385
*
44-
* @param id
45-
* Container ID
46-
* @param status
47-
* Status string. List of statuses is available in <a
48-
* href="https://docs.docker.com/reference/api/docker_remote_api_v1.16/#monitor-dockers-events">Docker API v.1.16</a>
49-
* @param from
50-
* Image, from which the container has been created
51-
* @param time
52-
* Event time The time is specified in milliseconds since January 1, 1970, 00:00:00 GMT
53-
* @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
5492
*/
5593
public Event(String status, String id, String from, Long time) {
5694
this.status = status;
@@ -69,6 +107,14 @@ public String getStatus() {
69107
return status;
70108
}
71109

110+
/**
111+
* @see #status
112+
*/
113+
public Event withStatus(String status) {
114+
this.status = status;
115+
return this;
116+
}
117+
72118
/**
73119
* Get ID of docker container.
74120
*
@@ -78,6 +124,14 @@ public String getId() {
78124
return id;
79125
}
80126

127+
/**
128+
* @see #id
129+
*/
130+
public Event withId(String id) {
131+
this.id = id;
132+
return this;
133+
}
134+
81135
/**
82136
* Get source image of the container.
83137
*
@@ -87,6 +141,14 @@ public String getFrom() {
87141
return from;
88142
}
89143

144+
/**
145+
* @see #from
146+
*/
147+
public Event withFrom(String from) {
148+
this.from = from;
149+
return this;
150+
}
151+
90152
/**
91153
* Get the event time. The time is specified in milliseconds since January 1, 1970, 00:00:00 GMT
92154
*
@@ -96,25 +158,102 @@ public Long getTime() {
96158
return time;
97159
}
98160

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+
99185
/**
100186
* Returns the node when working against docker swarm
101187
*/
102188
public Node getNode() {
103189
return node;
104190
}
105191

106-
/*
107-
* Get type of event.
108-
*
109-
* @return type of event
192+
/**
193+
* @see #node
110194
*/
195+
public Event withNode(Node node) {
196+
this.node = node;
197+
return this;
198+
}
199+
111200
@CheckForNull
112-
public String getType() {
201+
public EventType getType() {
113202
return type;
114203
}
115204

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+
116245
@Override
117246
public String toString() {
118-
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);
119258
}
120259
}
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> eventTypes = new HashMap<>();
33+
34+
static {
35+
for (EventType t : values()) {
36+
eventTypes.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 eventTypes.get(s);
54+
}
55+
}

0 commit comments

Comments
 (0)