use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project crate by crate.
the class TransportRenameTableAction method masterOperation.
@Override
protected void masterOperation(RenameTableRequest request, ClusterState state, ActionListener<AcknowledgedResponse> listener) throws Exception {
AtomicReference<String[]> newIndexNames = new AtomicReference<>(null);
ActionListener<AcknowledgedResponse> waitForShardsListener = ActionListeners.waitForShards(listener, activeShardsObserver, request.timeout(), () -> logger.info("Renamed a relation, but the operation timed out waiting for enough shards to become available"), newIndexNames::get);
clusterService.submitStateUpdateTask("rename-table", new AckedClusterStateUpdateTask<AcknowledgedResponse>(Priority.HIGH, request, waitForShardsListener) {
@Override
public ClusterState execute(ClusterState currentState) throws Exception {
ClusterState updatedState = executor.execute(currentState, request);
IndicesOptions openIndices = IndicesOptions.fromOptions(true, true, true, false, true, true, false);
newIndexNames.set(indexNameExpressionResolver.concreteIndexNames(updatedState, openIndices, request.targetTableIdent().indexNameOrAlias()));
return updatedState;
}
@Override
protected AcknowledgedResponse newResponse(boolean acknowledged) {
return new AcknowledgedResponse(acknowledged);
}
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project crate by crate.
the class IndexNameExpressionResolver method concreteIndices.
Index[] concreteIndices(Context context, String... indexExpressions) {
if (indexExpressions == null || indexExpressions.length == 0) {
indexExpressions = new String[] { Metadata.ALL };
}
Metadata metadata = context.getState().metadata();
IndicesOptions options = context.getOptions();
final boolean failClosed = options.forbidClosedIndices() && options.ignoreUnavailable() == false;
// If only one index is specified then whether we fail a request if an index is missing depends on the allow_no_indices
// option. At some point we should change this, because there shouldn't be a reason why whether a single index
// or multiple indices are specified yield different behaviour.
final boolean failNoIndices = indexExpressions.length == 1 ? !options.allowNoIndices() : !options.ignoreUnavailable();
List<String> expressions = expressionResolver.resolve(context, Arrays.asList(indexExpressions));
if (expressions.isEmpty()) {
if (!options.allowNoIndices()) {
IndexNotFoundException infe = new IndexNotFoundException((String) null);
infe.setResources("index_expression", indexExpressions);
throw infe;
} else {
return Index.EMPTY_ARRAY;
}
}
final Set<Index> concreteIndices = new HashSet<>(expressions.size());
for (String expression : expressions) {
AliasOrIndex aliasOrIndex = metadata.getAliasAndIndexLookup().get(expression);
if (aliasOrIndex == null) {
if (failNoIndices) {
IndexNotFoundException infe = new IndexNotFoundException(expression);
infe.setResources("index_expression", expression);
throw infe;
} else {
continue;
}
} else if (aliasOrIndex.isAlias() && context.getOptions().ignoreAliases()) {
if (failNoIndices) {
throw aliasesNotSupportedException(expression);
} else {
continue;
}
}
if (aliasOrIndex.isAlias() && context.isResolveToWriteIndex()) {
AliasOrIndex.Alias alias = (AliasOrIndex.Alias) aliasOrIndex;
IndexMetadata writeIndex = alias.getWriteIndex();
if (writeIndex == null) {
throw new IllegalArgumentException("no write index is defined for alias [" + alias.getAliasName() + "]." + " The write index may be explicitly disabled using is_write_index=false or the alias points to multiple" + " indices without one being designated as a write index");
}
concreteIndices.add(writeIndex.getIndex());
} else {
if (aliasOrIndex.getIndices().size() > 1 && !options.allowAliasesToMultipleIndices()) {
String[] indexNames = new String[aliasOrIndex.getIndices().size()];
int i = 0;
for (IndexMetadata indexMetadata : aliasOrIndex.getIndices()) {
indexNames[i++] = indexMetadata.getIndex().getName();
}
throw new IllegalArgumentException("Alias [" + expression + "] has more than one indices associated with it [" + Arrays.toString(indexNames) + "], can't execute a single index op");
}
for (IndexMetadata index : aliasOrIndex.getIndices()) {
if (index.getState() == IndexMetadata.State.CLOSE) {
if (failClosed) {
throw new IndexClosedException(index.getIndex());
} else {
if (options.forbidClosedIndices() == false) {
concreteIndices.add(index.getIndex());
}
}
} else if (index.getState() == IndexMetadata.State.OPEN) {
concreteIndices.add(index.getIndex());
} else {
throw new IllegalStateException("index state [" + index.getState() + "] not supported");
}
}
}
}
if (options.allowNoIndices() == false && concreteIndices.isEmpty()) {
IndexNotFoundException infe = new IndexNotFoundException((String) null);
infe.setResources("index_expression", indexExpressions);
throw infe;
}
return concreteIndices.toArray(new Index[concreteIndices.size()]);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method indexCreationDate.
@Override
public Optional<DateTime> indexCreationDate(String index) {
final GetSettingsRequest request = new GetSettingsRequest().indices(index).indicesOptions(IndicesOptions.fromOptions(true, true, true, false));
final GetSettingsResponse result = client.execute((c, requestOptions) -> c.indices().getSettings(request, requestOptions), "Couldn't read settings of index " + index);
final Optional<String> creationDate = Optional.ofNullable(result.getIndexToSettings().get(index)).map(indexSettings -> indexSettings.get("index.creation_date"));
return creationDate.map(Long::valueOf).map(instant -> new DateTime(instant, DateTimeZone.UTC));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method aliases.
@Override
public Map<String, Set<String>> aliases(String indexPattern) {
final GetAliasesRequest request = new GetAliasesRequest().indices(indexPattern).indicesOptions(IndicesOptions.fromOptions(false, false, true, false));
final GetAliasesResponse result = client.execute((c, requestOptions) -> c.indices().getAlias(request, requestOptions), "Couldn't collect aliases for index pattern " + indexPattern);
return result.getAliases().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(AliasMetadata::alias).collect(Collectors.toSet())));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project graylog2-server by Graylog2.
the class IndexToolsAdapterES7 method count.
@Override
public long count(Set<String> indices, Optional<Set<String>> includedStreams) {
final CountRequest request = new CountRequest(indices.toArray(new String[0]), buildStreamIdFilter(includedStreams)).indicesOptions(IndicesOptions.fromOptions(true, false, true, false));
final CountResponse result = client.execute((c, requestOptions) -> c.count(request, requestOptions), "Unable to count documents of index.");
return result.getCount();
}
Aggregations