@@ -83,7 +83,7 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
83
83
public static final ParseField RESULTS_INDEX_NAME = new ParseField ("results_index_name" );
84
84
public static final ParseField DELETING = new ParseField ("deleting" );
85
85
public static final ParseField ALLOW_LAZY_OPEN = new ParseField ("allow_lazy_open" );
86
- public static final ParseField BLOCK_REASON = new ParseField ("block_reason " );
86
+ public static final ParseField BLOCKED = new ParseField ("blocked " );
87
87
88
88
// Used for QueryPage
89
89
public static final ParseField RESULTS_FIELD = new ParseField ("jobs" );
@@ -137,7 +137,7 @@ private static ObjectParser<Builder, Void> createParser(boolean ignoreUnknownFie
137
137
parser .declareString (Builder ::setResultsIndexName , RESULTS_INDEX_NAME );
138
138
parser .declareBoolean (Builder ::setDeleting , DELETING );
139
139
parser .declareBoolean (Builder ::setAllowLazyOpen , ALLOW_LAZY_OPEN );
140
- parser .declareStringOrNull (Builder ::setBlockReason , BLOCK_REASON );
140
+ parser .declareObject (Builder ::setBlocked , ignoreUnknownFields ? Blocked . LENIENT_PARSER : Blocked . STRICT_PARSER , BLOCKED );
141
141
142
142
return parser ;
143
143
}
@@ -172,17 +172,15 @@ private static ObjectParser<Builder, Void> createParser(boolean ignoreUnknownFie
172
172
private final String resultsIndexName ;
173
173
private final boolean deleting ;
174
174
private final boolean allowLazyOpen ;
175
-
176
- @ Nullable
177
- private final BlockReason blockReason ;
175
+ private final Blocked blocked ;
178
176
179
177
private Job (String jobId , String jobType , Version jobVersion , List <String > groups , String description ,
180
178
Date createTime , Date finishedTime ,
181
179
AnalysisConfig analysisConfig , AnalysisLimits analysisLimits , DataDescription dataDescription ,
182
180
ModelPlotConfig modelPlotConfig , Long renormalizationWindowDays , TimeValue backgroundPersistInterval ,
183
181
Long modelSnapshotRetentionDays , Long dailyModelSnapshotRetentionAfterDays , Long resultsRetentionDays ,
184
182
Map <String , Object > customSettings , String modelSnapshotId , Version modelSnapshotMinVersion , String resultsIndexName ,
185
- boolean deleting , boolean allowLazyOpen , BlockReason blockReason ) {
183
+ boolean deleting , boolean allowLazyOpen , Blocked blocked ) {
186
184
187
185
this .jobId = jobId ;
188
186
this .jobType = jobType ;
@@ -206,7 +204,7 @@ private Job(String jobId, String jobType, Version jobVersion, List<String> group
206
204
this .resultsIndexName = resultsIndexName ;
207
205
this .deleting = deleting ;
208
206
this .allowLazyOpen = allowLazyOpen ;
209
- this .blockReason = blockReason ;
207
+ this .blocked = blocked == null ? Blocked . none () : blocked ;
210
208
}
211
209
212
210
public Job (StreamInput in ) throws IOException {
@@ -238,9 +236,9 @@ public Job(StreamInput in) throws IOException {
238
236
deleting = in .readBoolean ();
239
237
allowLazyOpen = in .readBoolean ();
240
238
if (in .getVersion ().onOrAfter (Version .V_8_0_0 )) {
241
- blockReason = in . readOptionalEnum ( BlockReason . class );
239
+ blocked = new Blocked ( in );
242
240
} else {
243
- blockReason = deleting ? BlockReason . DELETE : null ;
241
+ blocked = deleting ? new Blocked ( Blocked . Reason . DELETE , null ) : Blocked . none () ;
244
242
}
245
243
}
246
244
@@ -427,9 +425,8 @@ public boolean allowLazyOpen() {
427
425
return allowLazyOpen ;
428
426
}
429
427
430
- @ Nullable
431
- public BlockReason getBlockReason () {
432
- return blockReason ;
428
+ public Blocked getBlocked () {
429
+ return blocked ;
433
430
}
434
431
435
432
/**
@@ -520,7 +517,7 @@ public void writeTo(StreamOutput out) throws IOException {
520
517
out .writeBoolean (deleting );
521
518
out .writeBoolean (allowLazyOpen );
522
519
if (out .getVersion ().onOrAfter (Version .V_8_0_0 )) {
523
- out . writeOptionalEnum ( blockReason );
520
+ blocked . writeTo ( out );
524
521
}
525
522
}
526
523
@@ -597,8 +594,8 @@ public XContentBuilder doXContentBody(XContentBuilder builder, Params params) th
597
594
}
598
595
builder .field (RESULTS_INDEX_NAME .getPreferredName (), resultsIndexName );
599
596
builder .field (ALLOW_LAZY_OPEN .getPreferredName (), allowLazyOpen );
600
- if (blockReason != null ) {
601
- builder .field (BLOCK_REASON .getPreferredName (), blockReason );
597
+ if (blocked . getReason () != Blocked . Reason . NONE ) {
598
+ builder .field (BLOCKED .getPreferredName (), blocked );
602
599
}
603
600
return builder ;
604
601
}
@@ -636,15 +633,15 @@ public boolean equals(Object other) {
636
633
&& Objects .equals (this .resultsIndexName , that .resultsIndexName )
637
634
&& Objects .equals (this .deleting , that .deleting )
638
635
&& Objects .equals (this .allowLazyOpen , that .allowLazyOpen )
639
- && Objects .equals (this .blockReason , that .blockReason );
636
+ && Objects .equals (this .blocked , that .blocked );
640
637
}
641
638
642
639
@ Override
643
640
public int hashCode () {
644
641
return Objects .hash (jobId , jobType , jobVersion , groups , description , createTime , finishedTime ,
645
642
analysisConfig , analysisLimits , dataDescription , modelPlotConfig , renormalizationWindowDays ,
646
643
backgroundPersistInterval , modelSnapshotRetentionDays , dailyModelSnapshotRetentionAfterDays , resultsRetentionDays ,
647
- customSettings , modelSnapshotId , modelSnapshotMinVersion , resultsIndexName , deleting , allowLazyOpen , blockReason );
644
+ customSettings , modelSnapshotId , modelSnapshotMinVersion , resultsIndexName , deleting , allowLazyOpen , blocked );
648
645
}
649
646
650
647
// Class already extends from AbstractDiffable, so copied from ToXContentToBytes#toString()
@@ -694,7 +691,7 @@ public static class Builder implements Writeable {
694
691
private String resultsIndexName ;
695
692
private boolean deleting ;
696
693
private boolean allowLazyOpen ;
697
- private BlockReason blockReason ;
694
+ private Blocked blocked = Blocked . none () ;
698
695
699
696
public Builder () {
700
697
}
@@ -726,7 +723,7 @@ public Builder(Job job) {
726
723
this .resultsIndexName = job .getResultsIndexNameNoPrefix ();
727
724
this .deleting = job .isDeleting ();
728
725
this .allowLazyOpen = job .allowLazyOpen ();
729
- this .blockReason = job .getBlockReason ();
726
+ this .blocked = job .getBlocked ();
730
727
}
731
728
732
729
public Builder (StreamInput in ) throws IOException {
@@ -757,9 +754,9 @@ public Builder(StreamInput in) throws IOException {
757
754
deleting = in .readBoolean ();
758
755
allowLazyOpen = in .readBoolean ();
759
756
if (in .getVersion ().onOrAfter (Version .V_8_0_0 )) {
760
- blockReason = in . readOptionalEnum ( BlockReason . class );
757
+ blocked = new Blocked ( in );
761
758
} else {
762
- blockReason = null ;
759
+ blocked = Blocked . none () ;
763
760
}
764
761
}
765
762
@@ -888,10 +885,10 @@ public Builder setResultsIndexName(String resultsIndexName) {
888
885
public Builder setDeleting (boolean deleting ) {
889
886
this .deleting = deleting ;
890
887
if (deleting ) {
891
- this .blockReason = BlockReason . DELETE ;
888
+ this .blocked = new Blocked ( Blocked . Reason . DELETE , null ) ;
892
889
} else {
893
- if (blockReason == BlockReason .DELETE ) {
894
- blockReason = null ;
890
+ if (blocked . getReason () == Blocked . Reason .DELETE ) {
891
+ blocked = Blocked . none () ;
895
892
}
896
893
}
897
894
return this ;
@@ -902,19 +899,9 @@ public Builder setAllowLazyOpen(boolean allowLazyOpen) {
902
899
return this ;
903
900
}
904
901
905
- private Builder setBlockReason (String blockReason ) {
906
- if (blockReason == null ) {
907
- this .blockReason = null ;
908
- this .deleting = false ;
909
- return this ;
910
- } else {
911
- return setBlockReason (BlockReason .fromString (blockReason ));
912
- }
913
- }
914
-
915
- public Builder setBlockReason (BlockReason blockReason ) {
916
- this .blockReason = blockReason ;
917
- this .deleting = (this .blockReason == BlockReason .DELETE );
902
+ public Builder setBlocked (Blocked blocked ) {
903
+ this .blocked = ExceptionsHelper .requireNonNull (blocked , BLOCKED );
904
+ this .deleting = (this .blocked .getReason () == Blocked .Reason .DELETE );
918
905
return this ;
919
906
}
920
907
@@ -984,7 +971,7 @@ public void writeTo(StreamOutput out) throws IOException {
984
971
out .writeBoolean (deleting );
985
972
out .writeBoolean (allowLazyOpen );
986
973
if (out .getVersion ().onOrAfter (Version .V_8_0_0 )) {
987
- out . writeOptionalEnum ( blockReason );
974
+ blocked . writeTo ( out );
988
975
}
989
976
}
990
977
@@ -1015,15 +1002,15 @@ public boolean equals(Object o) {
1015
1002
&& Objects .equals (this .resultsIndexName , that .resultsIndexName )
1016
1003
&& Objects .equals (this .deleting , that .deleting )
1017
1004
&& Objects .equals (this .allowLazyOpen , that .allowLazyOpen )
1018
- && Objects .equals (this .blockReason , that .blockReason );
1005
+ && Objects .equals (this .blocked , that .blocked );
1019
1006
}
1020
1007
1021
1008
@ Override
1022
1009
public int hashCode () {
1023
1010
return Objects .hash (id , jobType , jobVersion , groups , description , analysisConfig , analysisLimits , dataDescription ,
1024
1011
createTime , finishedTime , modelPlotConfig , renormalizationWindowDays ,
1025
1012
backgroundPersistInterval , modelSnapshotRetentionDays , dailyModelSnapshotRetentionAfterDays , resultsRetentionDays ,
1026
- customSettings , modelSnapshotId , modelSnapshotMinVersion , resultsIndexName , deleting , allowLazyOpen , blockReason );
1013
+ customSettings , modelSnapshotId , modelSnapshotMinVersion , resultsIndexName , deleting , allowLazyOpen , blocked );
1027
1014
}
1028
1015
1029
1016
/**
@@ -1182,7 +1169,7 @@ public Job build() {
1182
1169
id , jobType , jobVersion , groups , description , createTime , finishedTime ,
1183
1170
analysisConfig , analysisLimits , dataDescription , modelPlotConfig , renormalizationWindowDays ,
1184
1171
backgroundPersistInterval , modelSnapshotRetentionDays , dailyModelSnapshotRetentionAfterDays , resultsRetentionDays ,
1185
- customSettings , modelSnapshotId , modelSnapshotMinVersion , resultsIndexName , deleting , allowLazyOpen , blockReason );
1172
+ customSettings , modelSnapshotId , modelSnapshotMinVersion , resultsIndexName , deleting , allowLazyOpen , blocked );
1186
1173
}
1187
1174
1188
1175
private void checkValidBackgroundPersistInterval () {
0 commit comments