@@ -21,29 +21,33 @@ public final class ForwardFileConfig
21
21
implements IsProxyConfig , ForwarderConfig {
22
22
23
23
public static final String PROP_NAME_SUB_PATH_TEMPLATE = "subPathTemplate" ;
24
+ public static final String PROP_NAME_ATOMIC_MOVE_ENABLED = "atomicMoveEnabled" ;
24
25
public static final TemplatingMode DEFAULT_TEMPLATING_MODE = TemplatingMode .REPLACE_UNKNOWN_PARAMS ;
25
26
26
27
private static final String DEFAULT_SUB_PATH_TEMPLATE = "${year}${month}${day}/${feed}" ;
28
+ private static final boolean DEFAULT_ATOMIC_MOVE_ENABLED = true ;
27
29
private static final LivenessCheckMode DEFAULT_LIVENESS_CHECK_MODE = LivenessCheckMode .READ ;
28
30
29
31
private final boolean enabled ;
30
32
private final boolean instant ;
31
33
private final String name ;
32
34
private final String path ;
33
35
private final PathTemplateConfig subPathTemplate ;
34
- private final ForwardQueueConfig forwardQueueConfig ;
36
+ private final ForwardFileQueueConfig forwardQueueConfig ;
35
37
private final String livenessCheckPath ;
36
38
private final LivenessCheckMode livenessCheckMode ;
39
+ private final boolean atomicMoveEnabled ;
37
40
38
41
public ForwardFileConfig () {
39
42
enabled = true ;
40
43
instant = false ;
41
44
name = null ;
42
45
path = null ;
43
46
subPathTemplate = null ;
44
- forwardQueueConfig = null ; // Assume local file forwarder by default, so no queue config needed
47
+ forwardQueueConfig = new ForwardFileQueueConfig ();
45
48
livenessCheckPath = null ;
46
49
livenessCheckMode = LivenessCheckMode .READ ;
50
+ atomicMoveEnabled = DEFAULT_ATOMIC_MOVE_ENABLED ;
47
51
}
48
52
49
53
@ SuppressWarnings ("unused" )
@@ -53,17 +57,19 @@ public ForwardFileConfig(@JsonProperty("enabled") final boolean enabled,
53
57
@ JsonProperty ("name" ) final String name ,
54
58
@ JsonProperty ("path" ) final String path ,
55
59
@ JsonProperty (PROP_NAME_SUB_PATH_TEMPLATE ) final PathTemplateConfig subPathTemplate ,
56
- @ JsonProperty ("queue" ) final ForwardQueueConfig forwardQueueConfig ,
60
+ @ JsonProperty ("queue" ) final ForwardFileQueueConfig forwardQueueConfig ,
57
61
@ JsonProperty ("livenessCheckPath" ) final String livenessCheckPath ,
58
- @ JsonProperty ("livenessCheckMode" ) final LivenessCheckMode livenessCheckMode ) {
62
+ @ JsonProperty ("livenessCheckMode" ) final LivenessCheckMode livenessCheckMode ,
63
+ @ JsonProperty (PROP_NAME_ATOMIC_MOVE_ENABLED ) final Boolean atomicMoveEnabled ) {
59
64
this .enabled = enabled ;
60
65
this .instant = instant ;
61
66
this .name = name ;
62
67
this .path = path ;
63
68
this .subPathTemplate = Objects .requireNonNullElse (subPathTemplate , PathTemplateConfig .DISABLED );
64
- this .forwardQueueConfig = forwardQueueConfig ;
69
+ this .forwardQueueConfig = Objects . requireNonNullElseGet ( forwardQueueConfig , ForwardFileQueueConfig :: new ) ;
65
70
this .livenessCheckPath = livenessCheckPath ;
66
71
this .livenessCheckMode = Objects .requireNonNullElse (livenessCheckMode , DEFAULT_LIVENESS_CHECK_MODE );
72
+ this .atomicMoveEnabled = Objects .requireNonNullElse (atomicMoveEnabled , DEFAULT_ATOMIC_MOVE_ENABLED );
67
73
}
68
74
69
75
private ForwardFileConfig (final Builder builder ) {
@@ -75,6 +81,7 @@ private ForwardFileConfig(final Builder builder) {
75
81
forwardQueueConfig = builder .forwardQueueConfig ;
76
82
livenessCheckPath = builder .livenessCheckPath ;
77
83
livenessCheckMode = builder .livenessCheckMode ;
84
+ atomicMoveEnabled = builder .atomicMoveEnabled ;
78
85
}
79
86
80
87
/**
@@ -130,13 +137,14 @@ public PathTemplateConfig getSubPathTemplate() {
130
137
return subPathTemplate ;
131
138
}
132
139
140
+ @ NotNull
133
141
@ Override
134
142
@ JsonProperty ("queue" )
135
143
@ JsonPropertyDescription ("Adds multi-threading and retry control to this forwarder. Can be set to null " +
136
144
"for a local file forwarder, but should be populated if the file forwarder is " +
137
145
"forwarding to a remote file system that may fail. Defaults to null as a " +
138
146
"local file forwarder is assumed." )
139
- public ForwardQueueConfig getForwardQueueConfig () {
147
+ public ForwardFileQueueConfig getForwardQueueConfig () {
140
148
return forwardQueueConfig ;
141
149
}
142
150
@@ -169,10 +177,24 @@ public String getLivenessCheckPath() {
169
177
return livenessCheckPath ;
170
178
}
171
179
180
+ @ JsonPropertyDescription (
181
+ "The type of liveness check to perform (READ|WRITE). " +
182
+ "READ will attempt to read the file/dir specified in livenessCheckPath. " +
183
+ "WRITE will attempt to touch the file specified in livenessCheckPath." )
172
184
public LivenessCheckMode getLivenessCheckMode () {
173
185
return livenessCheckMode ;
174
186
}
175
187
188
+ @ JsonPropertyDescription (
189
+ "Stroom-Proxy will attempt to move files onto the forward destination using an atomic move. " +
190
+ "This ensures that the move does not happen more than once. If an atomic move is not possible, " +
191
+ "e.g. the destination is a remote file system that does not support an atomic move, then it will " +
192
+ "fall back to a non-atomic move with the risk of it happening more than once. If you see warnings " +
193
+ "in the logs or know the file system will not support atomic moves then set this to false." )
194
+ public boolean isAtomicMoveEnabled () {
195
+ return atomicMoveEnabled ;
196
+ }
197
+
176
198
@ Override
177
199
public boolean equals (final Object o ) {
178
200
if (this == o ) {
@@ -189,7 +211,8 @@ public boolean equals(final Object o) {
189
211
&& Objects .equals (subPathTemplate , that .subPathTemplate )
190
212
&& Objects .equals (forwardQueueConfig , that .forwardQueueConfig )
191
213
&& Objects .equals (livenessCheckPath , that .livenessCheckPath )
192
- && livenessCheckMode == that .livenessCheckMode ;
214
+ && livenessCheckMode == that .livenessCheckMode
215
+ && atomicMoveEnabled == that .atomicMoveEnabled ;
193
216
}
194
217
195
218
@ Override
@@ -201,7 +224,8 @@ public int hashCode() {
201
224
subPathTemplate ,
202
225
forwardQueueConfig ,
203
226
livenessCheckPath ,
204
- livenessCheckMode );
227
+ livenessCheckMode ,
228
+ atomicMoveEnabled );
205
229
}
206
230
207
231
@ Override
@@ -215,6 +239,7 @@ public String toString() {
215
239
", forwardQueueConfig=" + forwardQueueConfig +
216
240
", livenessCheckPath='" + livenessCheckPath + '\'' +
217
241
", livenessCheckMode=" + livenessCheckMode +
242
+ ", atomicMoveEnabled=" + atomicMoveEnabled +
218
243
'}' ;
219
244
}
220
245
@@ -232,6 +257,7 @@ public static Builder builder(final ForwardFileConfig copy) {
232
257
builder .forwardQueueConfig = copy .getForwardQueueConfig ();
233
258
builder .livenessCheckPath = copy .getLivenessCheckPath ();
234
259
builder .livenessCheckMode = copy .getLivenessCheckMode ();
260
+ builder .atomicMoveEnabled = copy .isAtomicMoveEnabled ();
235
261
return builder ;
236
262
}
237
263
@@ -241,14 +267,15 @@ public static Builder builder(final ForwardFileConfig copy) {
241
267
242
268
public static final class Builder {
243
269
244
- public String livenessCheckPath ;
245
- public LivenessCheckMode livenessCheckMode ;
270
+ private String livenessCheckPath ;
271
+ private LivenessCheckMode livenessCheckMode ;
272
+ private boolean atomicMoveEnabled ;
246
273
private boolean enabled ;
247
274
private boolean instant ;
248
275
private String name ;
249
276
private String path ;
250
277
private PathTemplateConfig subPathTemplate ;
251
- private ForwardQueueConfig forwardQueueConfig ;
278
+ private ForwardFileQueueConfig forwardQueueConfig ;
252
279
253
280
private Builder () {
254
281
}
@@ -293,7 +320,7 @@ public Builder withSubPathTemplate(final PathTemplateConfig subPathTemplate) {
293
320
return this ;
294
321
}
295
322
296
- public Builder withForwardQueueConfig (final ForwardQueueConfig forwardQueueConfig ) {
323
+ public Builder withForwardQueueConfig (final ForwardFileQueueConfig forwardQueueConfig ) {
297
324
this .forwardQueueConfig = forwardQueueConfig ;
298
325
return this ;
299
326
}
@@ -308,6 +335,11 @@ public Builder withLivenessCheckMode(final LivenessCheckMode livenessCheckMode)
308
335
return this ;
309
336
}
310
337
338
+ public Builder withAtomicMoveEnabled (final boolean atomicMoveEnabled ) {
339
+ this .atomicMoveEnabled = atomicMoveEnabled ;
340
+ return this ;
341
+ }
342
+
311
343
public ForwardFileConfig build () {
312
344
return new ForwardFileConfig (this );
313
345
}
0 commit comments