Skip to content

Commit 313264f

Browse files
authored
Merge pull request docker-java#972 from fengxx/bugfix/blkio_stats
Bugfix blkio stats
2 parents 54bd243 + bbbff92 commit 313264f

File tree

4 files changed

+144
-22
lines changed

4 files changed

+144
-22
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import org.apache.commons.lang.builder.EqualsBuilder;
7+
import org.apache.commons.lang.builder.HashCodeBuilder;
8+
import org.apache.commons.lang.builder.ToStringBuilder;
9+
import org.apache.commons.lang.builder.ToStringStyle;
10+
11+
import java.io.Serializable;
12+
13+
/**
14+
* BlkioStat is not documented in pubic docker swapper.yaml yet, reference:
15+
* https://github.com/moby/moby/blob/master/api/types/stats.go
16+
*/
17+
@JsonIgnoreProperties(ignoreUnknown = true)
18+
@JsonInclude(JsonInclude.Include.NON_NULL)
19+
public class BlkioStatEntry implements Serializable {
20+
private static final long serialVersionUID = 1L;
21+
@JsonProperty("major")
22+
Long major;
23+
@JsonProperty("minor")
24+
Long minor;
25+
@JsonProperty("op")
26+
String op;
27+
@JsonProperty("value")
28+
Long value;
29+
30+
public Long getMajor() {
31+
return major;
32+
}
33+
34+
public BlkioStatEntry withMajor(Long major) {
35+
this.major = major;
36+
return this;
37+
}
38+
39+
public Long getMinor() {
40+
return minor;
41+
}
42+
43+
public BlkioStatEntry withMinor(Long minor) {
44+
this.minor = minor;
45+
return this;
46+
}
47+
48+
public String getOp() {
49+
return op;
50+
}
51+
52+
public BlkioStatEntry withOp(String op) {
53+
this.op = op;
54+
return this;
55+
}
56+
57+
public Long getValue() {
58+
return value;
59+
}
60+
61+
public BlkioStatEntry withValue(Long value) {
62+
this.value = value;
63+
return this;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
69+
}
70+
71+
@Override
72+
public boolean equals(Object o) {
73+
return EqualsBuilder.reflectionEquals(this, o);
74+
}
75+
76+
@Override
77+
public int hashCode() {
78+
return HashCodeBuilder.reflectionHashCode(this);
79+
}
80+
}

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

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import org.apache.commons.lang.builder.EqualsBuilder;
6+
import org.apache.commons.lang.builder.HashCodeBuilder;
7+
import org.apache.commons.lang.builder.ToStringBuilder;
8+
import org.apache.commons.lang.builder.ToStringStyle;
59

610
import javax.annotation.CheckForNull;
711
import java.io.Serializable;
@@ -17,90 +21,105 @@ public class BlkioStatsConfig implements Serializable {
1721
private static final long serialVersionUID = 1L;
1822

1923
@JsonProperty("io_service_bytes_recursive")
20-
private List<Long> ioServiceBytesRecursive;
24+
private List<BlkioStatEntry> ioServiceBytesRecursive;
2125

2226
@JsonProperty("io_serviced_recursive")
23-
private List<Long> ioServicedRecursive;
27+
private List<BlkioStatEntry> ioServicedRecursive;
2428

2529
@JsonProperty("io_queue_recursive")
26-
private List<Long> ioQueueRecursive;
30+
private List<BlkioStatEntry> ioQueueRecursive;
2731

2832
@JsonProperty("io_service_time_recursive")
29-
private List<Long> ioServiceTimeRecursive;
33+
private List<BlkioStatEntry> ioServiceTimeRecursive;
3034

3135
@JsonProperty("io_wait_time_recursive")
32-
private List<Long> ioWaitTimeRecursive;
36+
private List<BlkioStatEntry> ioWaitTimeRecursive;
3337

3438
@JsonProperty("io_merged_recursive")
35-
private List<Long> ioMergedRecursive;
39+
private List<BlkioStatEntry> ioMergedRecursive;
3640

3741
@JsonProperty("io_time_recursive")
38-
private List<Long> ioTimeRecursive;
42+
private List<BlkioStatEntry> ioTimeRecursive;
3943

4044
@JsonProperty("sectors_recursive")
41-
private List<Long> sectorsRecursive;
45+
private List<BlkioStatEntry> sectorsRecursive;
4246

4347
/**
4448
* @see #ioServiceBytesRecursive
4549
*/
4650
@CheckForNull
47-
public List<Long> getIoServiceBytesRecursive() {
51+
public List<BlkioStatEntry> getIoServiceBytesRecursive() {
4852
return ioServiceBytesRecursive;
4953
}
5054

5155
/**
5256
* @see #ioServicedRecursive
5357
*/
5458
@CheckForNull
55-
public List<Long> getIoServicedRecursive() {
59+
public List<BlkioStatEntry> getIoServicedRecursive() {
5660
return ioServicedRecursive;
5761
}
5862

5963
/**
6064
* @see #ioQueueRecursive
6165
*/
6266
@CheckForNull
63-
public List<Long> getIoQueueRecursive() {
67+
public List<BlkioStatEntry> getIoQueueRecursive() {
6468
return ioQueueRecursive;
6569
}
6670

6771
/**
6872
* @see #ioServiceTimeRecursive
6973
*/
7074
@CheckForNull
71-
public List<Long> getIoServiceTimeRecursive() {
75+
public List<BlkioStatEntry> getIoServiceTimeRecursive() {
7276
return ioServiceTimeRecursive;
7377
}
7478

7579
/**
7680
* @see #ioWaitTimeRecursive
7781
*/
7882
@CheckForNull
79-
public List<Long> getIoWaitTimeRecursive() {
83+
public List<BlkioStatEntry> getIoWaitTimeRecursive() {
8084
return ioWaitTimeRecursive;
8185
}
8286

8387
/**
8488
* @see #ioMergedRecursive
8589
*/
8690
@CheckForNull
87-
public List<Long> getIoMergedRecursive() {
91+
public List<BlkioStatEntry> getIoMergedRecursive() {
8892
return ioMergedRecursive;
8993
}
9094

9195
/**
9296
* @see #ioTimeRecursive
9397
*/
9498
@CheckForNull
95-
public List<Long> getIoTimeRecursive() {
99+
public List<BlkioStatEntry> getIoTimeRecursive() {
96100
return ioTimeRecursive;
97101
}
98102

99103
/**
100104
* @see #sectorsRecursive
101105
*/
102106
@CheckForNull
103-
public List<Long> getSectorsRecursive() {
107+
public List<BlkioStatEntry> getSectorsRecursive() {
104108
return sectorsRecursive;
105109
}
110+
111+
@Override
112+
public String toString() {
113+
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
114+
}
115+
116+
@Override
117+
public boolean equals(Object o) {
118+
return EqualsBuilder.reflectionEquals(this, o);
119+
}
120+
121+
@Override
122+
public int hashCode() {
123+
return HashCodeBuilder.reflectionHashCode(this);
124+
}
106125
}

src/test/java/com/github/dockerjava/api/model/StatisticsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public void serderJson1() throws IOException {
8484
assertThat(memoryStats.getLimit(), is(2095874048L));
8585

8686
final BlkioStatsConfig blkioStats = statistics.getBlkioStats();
87-
assertThat(blkioStats.getIoServiceBytesRecursive(), is(empty()));
88-
assertThat(blkioStats.getIoServicedRecursive(), is(empty()));
87+
assertThat(blkioStats.getIoServiceBytesRecursive().size(), is(2));
88+
assertThat(blkioStats.getIoServiceBytesRecursive().get(0).getValue(), is(26214L));
89+
assertThat(blkioStats.getIoServicedRecursive().size(), is(2));
8990
assertThat(blkioStats.getIoQueueRecursive(), is(empty()));
9091
assertThat(blkioStats.getIoServiceTimeRecursive(), is(empty()));
9192
assertThat(blkioStats.getIoWaitTimeRecursive(), is(empty()));

src/test/resources/samples/1.27/containers/container/stats/stats1.json

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,33 @@
55
"current":2
66
},
77
"blkio_stats":{
8-
"io_service_bytes_recursive":[
9-
8+
"io_service_bytes_recursive": [
9+
{
10+
"major": 8,
11+
"minor": "0",
12+
"op": "Read",
13+
"value": 26214
14+
},
15+
{
16+
"major": 8,
17+
"minor": "0",
18+
"op": "Write",
19+
"value": 26214
20+
}
1021
],
11-
"io_serviced_recursive":[
12-
22+
"io_serviced_recursive": [
23+
{
24+
"major": 8,
25+
"minor": 0,
26+
"op": "Read",
27+
"value": 41771
28+
},
29+
{
30+
"major": 8,
31+
"minor": 0,
32+
"op": "Write",
33+
"value": 72796
34+
}
1335
],
1436
"io_queue_recursive":[
1537

0 commit comments

Comments
 (0)