@@ -82,12 +82,12 @@ public class SnapshotLifecyclePolicy extends AbstractDiffable<SnapshotLifecycleP
82
82
PARSER .declareString (ConstructingObjectParser .constructorArg (), SCHEDULE );
83
83
PARSER .declareString (ConstructingObjectParser .constructorArg (), REPOSITORY );
84
84
PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), (p , c ) -> p .map (), CONFIG );
85
- PARSER .declareObject (ConstructingObjectParser .constructorArg (), SnapshotRetentionConfiguration ::parse , RETENTION );
85
+ PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), SnapshotRetentionConfiguration ::parse , RETENTION );
86
86
}
87
87
88
88
public SnapshotLifecyclePolicy (final String id , final String name , final String schedule ,
89
- final String repository , @ Nullable Map <String , Object > configuration ,
90
- final SnapshotRetentionConfiguration retentionPolicy ) {
89
+ final String repository , @ Nullable final Map <String , Object > configuration ,
90
+ @ Nullable final SnapshotRetentionConfiguration retentionPolicy ) {
91
91
this .id = Objects .requireNonNull (id , "policy id is required" );
92
92
this .name = Objects .requireNonNull (name , "policy snapshot name is required" );
93
93
this .schedule = Objects .requireNonNull (schedule , "policy schedule is required" );
@@ -102,7 +102,7 @@ public SnapshotLifecyclePolicy(StreamInput in) throws IOException {
102
102
this .schedule = in .readString ();
103
103
this .repository = in .readString ();
104
104
this .configuration = in .readMap ();
105
- this .retentionPolicy = new SnapshotRetentionConfiguration ( in );
105
+ this .retentionPolicy = in . readOptionalWriteable ( SnapshotRetentionConfiguration :: new );
106
106
}
107
107
108
108
public String getId () {
@@ -126,6 +126,7 @@ public Map<String, Object> getConfig() {
126
126
return this .configuration ;
127
127
}
128
128
129
+ @ Nullable
129
130
public SnapshotRetentionConfiguration getRetentionPolicy () {
130
131
return this .retentionPolicy ;
131
132
}
@@ -271,7 +272,7 @@ public void writeTo(StreamOutput out) throws IOException {
271
272
out .writeString (this .schedule );
272
273
out .writeString (this .repository );
273
274
out .writeMap (this .configuration );
274
- this .retentionPolicy . writeTo ( out );
275
+ out . writeOptionalWriteable ( this .retentionPolicy );
275
276
}
276
277
277
278
@ Override
@@ -283,7 +284,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
283
284
if (this .configuration != null ) {
284
285
builder .field (CONFIG .getPreferredName (), this .configuration );
285
286
}
286
- builder .field (RETENTION .getPreferredName (), this .retentionPolicy );
287
+ if (this .retentionPolicy != null ) {
288
+ builder .field (RETENTION .getPreferredName (), this .retentionPolicy );
289
+ }
287
290
builder .endObject ();
288
291
return builder ;
289
292
}
0 commit comments