@@ -93,8 +93,11 @@ private LifecycleExecutionState(String phase, String action, String step, String
93
93
*/
94
94
public static LifecycleExecutionState fromIndexMetadata (IndexMetadata indexMetadata ) {
95
95
Map <String , String > customData = indexMetadata .getCustomData (ILM_CUSTOM_METADATA_KEY );
96
- customData = customData == null ? new HashMap <>() : customData ;
97
- return fromCustomMetadata (customData );
96
+ if (customData != null && customData .isEmpty () == false ) {
97
+ return fromCustomMetadata (customData );
98
+ } else {
99
+ return LifecycleExecutionState .builder ().build ();
100
+ }
98
101
}
99
102
100
103
/**
@@ -159,77 +162,95 @@ public static Builder builder(LifecycleExecutionState state) {
159
162
}
160
163
161
164
static LifecycleExecutionState fromCustomMetadata (Map <String , String > customData ) {
165
+ assert customData .isEmpty () == false ;
162
166
Builder builder = builder ();
163
- if (customData .containsKey (PHASE )) {
164
- builder .setPhase (customData .get (PHASE ));
167
+ String phase = customData .get (PHASE );
168
+ if (phase != null ) {
169
+ builder .setPhase (phase );
165
170
}
166
- if (customData .containsKey (ACTION )) {
167
- builder .setAction (customData .get (ACTION ));
171
+ String action = customData .get (ACTION );
172
+ if (action != null ) {
173
+ builder .setAction (action );
168
174
}
169
- if (customData .containsKey (STEP )) {
170
- builder .setStep (customData .get (STEP ));
175
+ String step = customData .get (STEP );
176
+ if (step != null ) {
177
+ builder .setStep (step );
171
178
}
172
- if (customData .containsKey (FAILED_STEP )) {
173
- builder .setFailedStep (customData .get (FAILED_STEP ));
179
+ String failedStep = customData .get (FAILED_STEP );
180
+ if (failedStep != null ) {
181
+ builder .setFailedStep (failedStep );
174
182
}
175
- if (customData .containsKey (IS_AUTO_RETRYABLE_ERROR )) {
176
- builder .setIsAutoRetryableError (Boolean .parseBoolean (customData .get (IS_AUTO_RETRYABLE_ERROR )));
183
+ String isAutoRetryableError = customData .get (IS_AUTO_RETRYABLE_ERROR );
184
+ if (isAutoRetryableError != null ) {
185
+ builder .setIsAutoRetryableError (Boolean .parseBoolean (isAutoRetryableError ));
177
186
}
178
- if (customData .containsKey (FAILED_STEP_RETRY_COUNT )) {
179
- builder .setFailedStepRetryCount (Integer .parseInt (customData .get (FAILED_STEP_RETRY_COUNT )));
187
+ String failedStepRetryCount = customData .get (FAILED_STEP_RETRY_COUNT );
188
+ if (failedStepRetryCount != null ) {
189
+ builder .setFailedStepRetryCount (Integer .parseInt (failedStepRetryCount ));
180
190
}
181
- if (customData .containsKey (STEP_INFO )) {
182
- builder .setStepInfo (customData .get (STEP_INFO ));
191
+ String stepInfo = customData .get (STEP_INFO );
192
+ if (stepInfo != null ) {
193
+ builder .setStepInfo (stepInfo );
183
194
}
184
- if (customData .containsKey (PHASE_DEFINITION )) {
185
- builder .setPhaseDefinition (customData .get (PHASE_DEFINITION ));
195
+ String phaseDefinition = customData .get (PHASE_DEFINITION );
196
+ if (phaseDefinition != null ) {
197
+ builder .setPhaseDefinition (phaseDefinition );
186
198
}
187
- if (customData .containsKey (SNAPSHOT_REPOSITORY )) {
188
- builder .setSnapshotRepository (customData .get (SNAPSHOT_REPOSITORY ));
199
+ String snapShotRepository = customData .get (SNAPSHOT_REPOSITORY );
200
+ if (snapShotRepository != null ) {
201
+ builder .setSnapshotRepository (snapShotRepository );
189
202
}
190
- if (customData .containsKey (SNAPSHOT_NAME )) {
191
- builder .setSnapshotName (customData .get (SNAPSHOT_NAME ));
203
+ String snapshotName = customData .get (SNAPSHOT_NAME );
204
+ if (snapshotName != null ) {
205
+ builder .setSnapshotName (snapshotName );
192
206
}
193
- if (customData .containsKey (SHRINK_INDEX_NAME )) {
194
- builder .setShrinkIndexName (customData .get (SHRINK_INDEX_NAME ));
207
+ String shrinkIndexName = customData .get (SHRINK_INDEX_NAME );
208
+ if (shrinkIndexName != null ) {
209
+ builder .setShrinkIndexName (shrinkIndexName );
195
210
}
196
- if (customData .containsKey (INDEX_CREATION_DATE )) {
211
+ String indexCreationDate = customData .get (INDEX_CREATION_DATE );
212
+ if (indexCreationDate != null ) {
197
213
try {
198
- builder .setIndexCreationDate (Long .parseLong (customData . get ( INDEX_CREATION_DATE ) ));
214
+ builder .setIndexCreationDate (Long .parseLong (indexCreationDate ));
199
215
} catch (NumberFormatException e ) {
200
216
throw new ElasticsearchException ("Custom metadata field [{}] does not contain a valid long. Actual value: [{}]" ,
201
217
e , INDEX_CREATION_DATE , customData .get (INDEX_CREATION_DATE ));
202
218
}
203
219
}
204
- if (customData .containsKey (PHASE_TIME )) {
220
+ String phaseTime = customData .get (PHASE_TIME );
221
+ if (phaseTime != null ) {
205
222
try {
206
- builder .setPhaseTime (Long .parseLong (customData . get ( PHASE_TIME ) ));
223
+ builder .setPhaseTime (Long .parseLong (phaseTime ));
207
224
} catch (NumberFormatException e ) {
208
225
throw new ElasticsearchException ("Custom metadata field [{}] does not contain a valid long. Actual value: [{}]" ,
209
226
e , PHASE_TIME , customData .get (PHASE_TIME ));
210
227
}
211
228
}
212
- if (customData .containsKey (ACTION_TIME )) {
229
+ String actionTime = customData .get (ACTION_TIME );
230
+ if (actionTime != null ) {
213
231
try {
214
- builder .setActionTime (Long .parseLong (customData . get ( ACTION_TIME ) ));
232
+ builder .setActionTime (Long .parseLong (actionTime ));
215
233
} catch (NumberFormatException e ) {
216
234
throw new ElasticsearchException ("Custom metadata field [{}] does not contain a valid long. Actual value: [{}]" ,
217
235
e , ACTION_TIME , customData .get (ACTION_TIME ));
218
236
}
219
237
}
220
- if (customData .containsKey (STEP_TIME )) {
238
+ String stepTime = customData .get (STEP_TIME );
239
+ if (stepTime != null ) {
221
240
try {
222
- builder .setStepTime (Long .parseLong (customData . get ( STEP_TIME ) ));
241
+ builder .setStepTime (Long .parseLong (stepTime ));
223
242
} catch (NumberFormatException e ) {
224
243
throw new ElasticsearchException ("Custom metadata field [{}] does not contain a valid long. Actual value: [{}]" ,
225
244
e , STEP_TIME , customData .get (STEP_TIME ));
226
245
}
227
246
}
228
- if (customData .containsKey (SNAPSHOT_INDEX_NAME )) {
229
- builder .setSnapshotIndexName (customData .get (SNAPSHOT_INDEX_NAME ));
247
+ String snapshotIndexName = customData .get (SNAPSHOT_INDEX_NAME );
248
+ if (snapshotIndexName != null ) {
249
+ builder .setSnapshotIndexName (snapshotIndexName );
230
250
}
231
- if (customData .containsKey (ROLLUP_INDEX_NAME )) {
232
- builder .setRollupIndexName (customData .get (ROLLUP_INDEX_NAME ));
251
+ String rollupIndexName = customData .get (ROLLUP_INDEX_NAME );
252
+ if (rollupIndexName != null ) {
253
+ builder .setRollupIndexName (rollupIndexName );
233
254
}
234
255
return builder .build ();
235
256
}
0 commit comments