|
@@ -23,6 +23,7 @@ import org.elasticsearch.common.xcontent.DeprecationHandler;
|
|
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|
|
+import org.elasticsearch.core.Nullable;
|
|
|
import org.elasticsearch.tasks.Task;
|
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
|
import org.elasticsearch.transport.TransportService;
|
|
@@ -52,8 +53,8 @@ public class TransportExplainLifecycleAction
|
|
|
public TransportExplainLifecycleAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool,
|
|
|
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
|
|
|
NamedXContentRegistry xContentRegistry, IndexLifecycleService indexLifecycleService) {
|
|
|
- super(ExplainLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters,
|
|
|
- ExplainLifecycleRequest::new, indexNameExpressionResolver, ExplainLifecycleResponse::new);
|
|
|
+ super(ExplainLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, ExplainLifecycleRequest::new,
|
|
|
+ indexNameExpressionResolver, ExplainLifecycleResponse::new);
|
|
|
this.xContentRegistry = xContentRegistry;
|
|
|
this.indexLifecycleService = indexLifecycleService;
|
|
|
}
|
|
@@ -64,57 +65,13 @@ public class TransportExplainLifecycleAction
|
|
|
Map<String, IndexLifecycleExplainResponse> indexResponses = new HashMap<>();
|
|
|
for (String index : concreteIndices) {
|
|
|
IndexMetadata idxMetadata = state.metadata().index(index);
|
|
|
- Settings idxSettings = idxMetadata.getSettings();
|
|
|
- LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMetadata);
|
|
|
- String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxSettings);
|
|
|
- String currentPhase = lifecycleState.getPhase();
|
|
|
- String stepInfo = lifecycleState.getStepInfo();
|
|
|
- BytesArray stepInfoBytes = null;
|
|
|
- if (stepInfo != null) {
|
|
|
- stepInfoBytes = new BytesArray(stepInfo);
|
|
|
- }
|
|
|
- // parse existing phase steps from the phase definition in the index settings
|
|
|
- String phaseDef = lifecycleState.getPhaseDefinition();
|
|
|
- PhaseExecutionInfo phaseExecutionInfo = null;
|
|
|
- if (Strings.isNullOrEmpty(phaseDef) == false) {
|
|
|
- try (XContentParser parser = JsonXContent.jsonXContent.createParser(xContentRegistry,
|
|
|
- DeprecationHandler.THROW_UNSUPPORTED_OPERATION, phaseDef)) {
|
|
|
- phaseExecutionInfo = PhaseExecutionInfo.parse(parser, currentPhase);
|
|
|
- } catch (IOException e) {
|
|
|
- listener.onFailure(new ElasticsearchParseException(
|
|
|
- "failed to parse phase definition for index [" + index + "]", e));
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
final IndexLifecycleExplainResponse indexResponse;
|
|
|
- if (Strings.hasLength(policyName)) {
|
|
|
- // If this is requesting only errors, only include indices in the error step or which are using a nonexistent policy
|
|
|
- if (request.onlyErrors() == false
|
|
|
- || (ErrorStep.NAME.equals(lifecycleState.getStep()) || indexLifecycleService.policyExists(policyName) == false)) {
|
|
|
- Long originationDate = idxSettings.getAsLong(LIFECYCLE_ORIGINATION_DATE, -1L);
|
|
|
- indexResponse = IndexLifecycleExplainResponse.newManagedIndexResponse(index, policyName,
|
|
|
- originationDate != -1L ? originationDate : lifecycleState.getLifecycleDate(),
|
|
|
- lifecycleState.getPhase(),
|
|
|
- lifecycleState.getAction(),
|
|
|
- lifecycleState.getStep(),
|
|
|
- lifecycleState.getFailedStep(),
|
|
|
- lifecycleState.isAutoRetryableError(),
|
|
|
- lifecycleState.getFailedStepRetryCount(),
|
|
|
- lifecycleState.getPhaseTime(),
|
|
|
- lifecycleState.getActionTime(),
|
|
|
- lifecycleState.getStepTime(),
|
|
|
- lifecycleState.getSnapshotRepository(),
|
|
|
- lifecycleState.getSnapshotName(),
|
|
|
- lifecycleState.getShrinkIndexName(),
|
|
|
- stepInfoBytes,
|
|
|
- phaseExecutionInfo);
|
|
|
- } else {
|
|
|
- indexResponse = null;
|
|
|
- }
|
|
|
- } else if (request.onlyManaged() == false && request.onlyErrors() == false) {
|
|
|
- indexResponse = IndexLifecycleExplainResponse.newUnmanagedIndexResponse(index);
|
|
|
- } else {
|
|
|
- indexResponse = null;
|
|
|
+ try {
|
|
|
+ indexResponse = getIndexLifecycleExplainResponse(idxMetadata, request.onlyErrors(), request.onlyManaged(),
|
|
|
+ indexLifecycleService, xContentRegistry);
|
|
|
+ } catch (IOException e) {
|
|
|
+ listener.onFailure(new ElasticsearchParseException("failed to parse phase definition for index [" + index + "]", e));
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
if (indexResponse != null) {
|
|
@@ -124,4 +81,61 @@ public class TransportExplainLifecycleAction
|
|
|
listener.onResponse(new ExplainLifecycleResponse(indexResponses));
|
|
|
}
|
|
|
|
|
|
+ @Nullable
|
|
|
+ static IndexLifecycleExplainResponse getIndexLifecycleExplainResponse(IndexMetadata indexMetadata, boolean onlyErrors,
|
|
|
+ boolean onlyManaged, IndexLifecycleService indexLifecycleService,
|
|
|
+ NamedXContentRegistry xContentRegistry) throws IOException {
|
|
|
+ Settings idxSettings = indexMetadata.getSettings();
|
|
|
+ LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
|
|
|
+ String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxSettings);
|
|
|
+ String currentPhase = lifecycleState.getPhase();
|
|
|
+ String stepInfo = lifecycleState.getStepInfo();
|
|
|
+ BytesArray stepInfoBytes = null;
|
|
|
+ if (stepInfo != null) {
|
|
|
+ stepInfoBytes = new BytesArray(stepInfo);
|
|
|
+ }
|
|
|
+ String indexName = indexMetadata.getIndex().getName();
|
|
|
+
|
|
|
+ // parse existing phase steps from the phase definition in the index settings
|
|
|
+ String phaseDef = lifecycleState.getPhaseDefinition();
|
|
|
+ PhaseExecutionInfo phaseExecutionInfo = null;
|
|
|
+ if (Strings.isNullOrEmpty(phaseDef) == false) {
|
|
|
+ try (XContentParser parser = JsonXContent.jsonXContent.createParser(xContentRegistry,
|
|
|
+ DeprecationHandler.THROW_UNSUPPORTED_OPERATION, phaseDef)) {
|
|
|
+ phaseExecutionInfo = PhaseExecutionInfo.parse(parser, currentPhase);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ final IndexLifecycleExplainResponse indexResponse;
|
|
|
+ if (Strings.hasLength(policyName)) {
|
|
|
+ // If this is requesting only errors, only include indices in the error step or which are using a nonexistent policy
|
|
|
+ if (onlyErrors == false
|
|
|
+ || (ErrorStep.NAME.equals(lifecycleState.getStep()) || indexLifecycleService.policyExists(policyName) == false)) {
|
|
|
+ Long originationDate = idxSettings.getAsLong(LIFECYCLE_ORIGINATION_DATE, -1L);
|
|
|
+ indexResponse = IndexLifecycleExplainResponse.newManagedIndexResponse(indexName, policyName,
|
|
|
+ originationDate != -1L ? originationDate : lifecycleState.getLifecycleDate(),
|
|
|
+ lifecycleState.getPhase(),
|
|
|
+ lifecycleState.getAction(),
|
|
|
+ lifecycleState.getStep(),
|
|
|
+ lifecycleState.getFailedStep(),
|
|
|
+ lifecycleState.isAutoRetryableError(),
|
|
|
+ lifecycleState.getFailedStepRetryCount(),
|
|
|
+ lifecycleState.getPhaseTime(),
|
|
|
+ lifecycleState.getActionTime(),
|
|
|
+ lifecycleState.getStepTime(),
|
|
|
+ lifecycleState.getSnapshotRepository(),
|
|
|
+ lifecycleState.getSnapshotName(),
|
|
|
+ lifecycleState.getShrinkIndexName(),
|
|
|
+ stepInfoBytes,
|
|
|
+ phaseExecutionInfo);
|
|
|
+ } else {
|
|
|
+ indexResponse = null;
|
|
|
+ }
|
|
|
+ } else if (onlyManaged == false && onlyErrors == false) {
|
|
|
+ indexResponse = IndexLifecycleExplainResponse.newUnmanagedIndexResponse(indexName);
|
|
|
+ } else {
|
|
|
+ indexResponse = null;
|
|
|
+ }
|
|
|
+ return indexResponse;
|
|
|
+ }
|
|
|
}
|