-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.java
141 lines (114 loc) · 3.71 KB
/
test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
public class DiskBalancerWorkStatus {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final ObjectMapper MAPPER_WITH_INDENT_OUTPUT =
new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
private static final ObjectReader READER_WORKSTATUS =
new ObjectMapper().readerFor(DiskBalancerWorkStatus.class);
private static final ObjectReader READER_WORKENTRY = new ObjectMapper()
.readerFor(defaultInstance().constructCollectionType(List.class,
DiskBalancerWorkEntry.class));
private final List<DiskBalancerWorkEntry> currentState;
private Result result;
private String planID;
private String planFile;
public DiskBalancerWorkStatus() {
this.currentState = new LinkedList<>();
}
public DiskBalancerWorkStatus(Result result, String planID, String planFile) {
this();
this.result = result;
this.planID = planID;
this.planFile = planFile;
}
public DiskBalancerWorkStatus(Result result, String planID,
List<DiskBalancerWorkEntry> currentState) {
this.result = result;
this.planID = planID;
this.currentState = currentState;
}
public DiskBalancerWorkStatus(Result result, String planID, String planFile,
String currentState) throws IOException {
this.result = result;
this.planID = planID;
this.planFile = planFile;
this.currentState = READER_WORKENTRY.readValue(currentState);
}
public Result getResult() {
return result;
}
public String getPlanID() {
return planID;
}
public String getPlanFile() {
return planFile;
}
public List<DiskBalancerWorkEntry> getCurrentState() {
return currentState;
}
public String currentStateString() throws IOException {
return MAPPER_WITH_INDENT_OUTPUT.writeValueAsString(currentState);
}
public String toJsonString() throws IOException {
return MAPPER.writeValueAsString(this);
}
public static DiskBalancerWorkStatus parseJson(String json) throws
IOException {
return READER_WORKSTATUS.readValue(json);
}
public void addWorkEntry(DiskBalancerWorkEntry entry) {
Preconditions.checkNotNull(entry);
currentState.add(entry);
}
public enum Result {
NO_PLAN(0),
PLAN_UNDER_PROGRESS(1),
PLAN_DONE(2),
PLAN_CANCELLED(3);
private int result;
private Result(int result) {
this.result = result;
}
/**
* Get int value of result.
*
* @return int
*/
public int getIntResult() {
return result;
}
}
public static class DiskBalancerWorkEntry {
private String sourcePath;
private String destPath;
private DiskBalancerWorkItem workItem;
public DiskBalancerWorkEntry() {
}
public DiskBalancerWorkEntry(String workItem) throws IOException {
this.workItem = DiskBalancerWorkItem.parseJson(workItem);
}
public DiskBalancerWorkEntry(String sourcePath, String destPath,
DiskBalancerWorkItem workItem) {
this.sourcePath = sourcePath;
this.destPath = destPath;
this.workItem = workItem;
}
public String getSourcePath() {
return sourcePath;
}
public void setSourcePath(String sourcePath) {
this.sourcePath = sourcePath;
}
public String getDestPath() {
return destPath;
}
public void setDestPath(String destPath) {
this.destPath = destPath;
}
public DiskBalancerWorkItem getWorkItem() {
return workItem;
}
public void setWorkItem(DiskBalancerWorkItem workItem) {
this.workItem = workItem;
}
}
}