Commit b810a59b by 朱海

[chg]异常捕获

1 parent 8fdb47f3
...@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -42,21 +43,25 @@ public class ILM implements CommandLineRunner { ...@@ -42,21 +43,25 @@ public class ILM implements CommandLineRunner {
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
Map<String, Phase> phases = new HashMap<>(); try {
Map<String, LifecycleAction> setPriorityAction = new HashMap<>(); Map<String, Phase> phases = new HashMap<>();
setPriorityAction.put(SetPriorityAction.NAME, new SetPriorityAction(100)); Map<String, LifecycleAction> setPriorityAction = new HashMap<>();
phases.put("hot", new Phase("hot", TimeValue.ZERO, setPriorityAction)); setPriorityAction.put(SetPriorityAction.NAME, new SetPriorityAction(100));
phases.put("hot", new Phase("hot", TimeValue.ZERO, setPriorityAction));
Map<String, LifecycleAction> deleteActions =
Collections.singletonMap(DeleteAction.NAME, new DeleteAction()); Map<String, LifecycleAction> deleteActions =
phases.put("delete", new Phase("delete", Collections.singletonMap(DeleteAction.NAME, new DeleteAction());
new TimeValue(deleteAfterDays, TimeUnit.DAYS), deleteActions)); phases.put("delete", new Phase("delete",
new TimeValue(deleteAfterDays, TimeUnit.DAYS), deleteActions));
LifecyclePolicy policy = new LifecyclePolicy(LIFECYCLE_NAME, phases);
PutLifecyclePolicyRequest lifecyclePolicyRequest = new PutLifecyclePolicyRequest(policy); LifecyclePolicy policy = new LifecyclePolicy(LIFECYCLE_NAME, phases);
AcknowledgedResponse acknowledgedResponse = restHighLevelClient.indexLifecycle().putLifecyclePolicy(lifecyclePolicyRequest, RequestOptions.DEFAULT); PutLifecyclePolicyRequest lifecyclePolicyRequest = new PutLifecyclePolicyRequest(policy);
if (acknowledgedResponse.isAcknowledged()) { AcknowledgedResponse acknowledgedResponse = restHighLevelClient.indexLifecycle().putLifecyclePolicy(lifecyclePolicyRequest, RequestOptions.DEFAULT);
log.info(LIFECYCLE_NAME + "生命周期创建完成"); if (acknowledgedResponse.isAcknowledged()) {
log.info(LIFECYCLE_NAME + "生命周期创建完成");
}
} catch (Exception e) {
log.error("生命周期创建异常", e);
} }
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!