|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.action; |
| 11 | + |
| 12 | +import org.elasticsearch.ElasticsearchException; |
| 13 | +import org.elasticsearch.core.Nullable; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +/** |
| 18 | + * This class allows capturing context about index expression replacements performed on an {@link IndicesRequest.Replaceable} during |
| 19 | + * index resolution, in particular the results of local resolution, and the remote (unresolved) expressions if any. |
| 20 | + * <p> |
| 21 | + * The replacements are separated into local and remote expressions. |
| 22 | + * For local expressions, the class allows recording local index resolution results along with failure info. |
| 23 | + * For remote expressions, only the expressions are recorded. |
| 24 | + * |
| 25 | + * <p>An example structure is:</p> |
| 26 | + * |
| 27 | + * <pre>{@code |
| 28 | + * { |
| 29 | + * "original": "my-index-*", |
| 30 | + * "localExpressions": { |
| 31 | + * "expressions": ["my-index-000001", "my-index-000002"], |
| 32 | + * "localIndexResolutionResult": "SUCCESS" |
| 33 | + * }, |
| 34 | + * "remoteExpressions": ["remote1:my-index-*", "remote2:my-index-*"] |
| 35 | + * } |
| 36 | + * }</pre> |
| 37 | + * |
| 38 | + * @param original the original index expression, as provided by the user |
| 39 | + * @param localExpressions the local expressions that replace the original along with their resolution result |
| 40 | + * and failure info |
| 41 | + * @param remoteExpressions the remote expressions that replace the original |
| 42 | + */ |
| 43 | +public record ResolvedIndexExpression(String original, LocalExpressions localExpressions, List<String> remoteExpressions) { |
| 44 | + /** |
| 45 | + * Indicates if a local index resolution attempt was successful or failed. |
| 46 | + * Failures can be due to missing concrete resources or unauthorized concrete resources. |
| 47 | + * A wildcard expression resolving to nothing is still considered a successful resolution. |
| 48 | + */ |
| 49 | + enum LocalIndexResolutionResult { |
| 50 | + SUCCESS, |
| 51 | + CONCRETE_RESOURCE_MISSING, |
| 52 | + CONCRETE_RESOURCE_UNAUTHORIZED, |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Represents local (non-remote) resolution results, including expanded indices, and the resolution result. |
| 57 | + */ |
| 58 | + public record LocalExpressions( |
| 59 | + List<String> expressions, |
| 60 | + LocalIndexResolutionResult localIndexResolutionResult, |
| 61 | + @Nullable ElasticsearchException exception |
| 62 | + ) { |
| 63 | + public LocalExpressions { |
| 64 | + assert localIndexResolutionResult != LocalIndexResolutionResult.SUCCESS || exception == null |
| 65 | + : "If the local resolution result is SUCCESS, exception must be null"; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments