@Override public String[] provide(String[] original, Object request, boolean supportsReplace) { if(supportsReplace) { if(retainMode && original != null && original.length > 0) { //TODO datemath? List<String> originalAsList = Arrays.asList(original); if(originalAsList.contains("*") || originalAsList.contains("_all")) { return replacements; } original = resolver.concreteIndexNames(clusterService.state(), IndicesOptions.lenientExpandOpen(), original); final String[] retained = WildcardMatcher.getMatchAny(original, replacements).toArray(new String[0]); return retained; } return replacements; } else { return NOOP; } } }, false);
private String[] getResolvedIndexPattern(User user, IndexNameExpressionResolver resolver, ClusterService cs) { String unresolved = getUnresolvedIndexPattern(user); String[] resolved = null; if(WildcardMatcher.containsWildcard(unresolved)) { final String[] aliasesForPermittedPattern = cs.state().getMetaData().getAliasAndIndexLookup() .entrySet().stream() .filter(e->e.getValue().isAlias()) .filter(e->WildcardMatcher.match(unresolved, e.getKey())) .map(e->e.getKey()).toArray(String[]::new); if(aliasesForPermittedPattern != null && aliasesForPermittedPattern.length > 0) { resolved = resolver.concreteIndexNames(cs.state(), IndicesOptions.lenientExpandOpen(), aliasesForPermittedPattern); } } if(resolved == null && !unresolved.isEmpty()) { resolved = resolver.concreteIndexNames(cs.state(), IndicesOptions.lenientExpandOpen(), unresolved); } if(resolved == null || resolved.length == 0) { return new String[]{unresolved}; } else { //append unresolved value for pattern matching String[] retval = Arrays.copyOf(resolved, resolved.length +1); retval[retval.length-1] = unresolved; return retval; } }
_indices = new ArrayList<>(Arrays.asList(resolver.concreteIndexNames(state, IndicesOptions.fromOptions(false, true, true, false), requestedPatterns))); if (log.isDebugEnabled()) { log.debug("Resolved pattern {} to {}", requestedPatterns, _indices);
final String[] allIndices = resolver.concreteIndexNames(cs.state(), IndicesOptions.lenientExpandOpen(), "*"); final Set<String> wanted = new HashSet<>(Arrays.asList(allIndices)); WildcardMatcher.wildcardRetainInSet(wanted, permitted);
@Override protected final void masterOperation(final Request request, final ClusterState state, final ActionListener<Response> listener) { String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); doMasterOperation(request, concreteIndices, state, listener); }
/** * Returns <code>true</code> iff the given expression resolves to the given index name otherwise <code>false</code> */ public final boolean matchesIndex(String indexName, String expression, ClusterState state) { final String[] concreteIndices = concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), expression); for (String index : concreteIndices) { if (Regex.simpleMatch(index, indexName)) { return true; } } return indexName.equals(expression); }
@Override protected ClusterBlockException checkBlock(IndicesShardStoresRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(CloseIndexRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(TypesExistsRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(GetAliasesRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(GetSettingsRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(GetAliasesRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(OpenIndexRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(GetIndexRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(ClusterSearchShardsRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(GetMappingsRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(CreateSnapshotRequest request, ClusterState state) { // We are reading the cluster metadata and indices - so we need to check both blocks ClusterBlockException clusterBlockException = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); if (clusterBlockException != null) { return clusterBlockException; } return state.blocks() .indicesBlockedException(ClusterBlockLevel.READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@Override protected ClusterBlockException checkBlock(PutMappingRequest request, ClusterState state) { String[] indices; if (request.getConcreteIndex() == null) { indices = indexNameExpressionResolver.concreteIndexNames(state, request); } else { indices = new String[] {request.getConcreteIndex().getName()}; } return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indices); }
@Override protected ClusterBlockException checkBlock(RolloverRequest request, ClusterState state) { IndicesOptions indicesOptions = IndicesOptions.fromOptions(true, true, request.indicesOptions().expandWildcardsOpen(), request.indicesOptions().expandWildcardsClosed()); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, indicesOptions, request.indices())); }
@Override protected ClusterBlockException checkBlock(IndicesExistsRequest request, ClusterState state) { //make sure through indices options that the concrete indices call never throws IndexMissingException IndicesOptions indicesOptions = IndicesOptions.fromOptions(true, true, request.indicesOptions().expandWildcardsOpen(), request.indicesOptions().expandWildcardsClosed()); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, indicesOptions, request.indices())); }