Search in sources :

Example 1 with AliasesNotFoundException

use of org.opensearch.rest.action.admin.indices.AliasesNotFoundException in project OpenSearch by opensearch-project.

the class ExceptionSerializationTests method testAliasesMissingException.

public void testAliasesMissingException() throws IOException {
    AliasesNotFoundException ex = serialize(new AliasesNotFoundException("one", "two", "three"));
    assertEquals("aliases [one, two, three] missing", ex.getMessage());
    assertEquals("aliases", ex.getResourceType());
    assertArrayEquals(new String[] { "one", "two", "three" }, ex.getResourceId().toArray(new String[0]));
}
Also used : AliasesNotFoundException(org.opensearch.rest.action.admin.indices.AliasesNotFoundException)

Example 2 with AliasesNotFoundException

use of org.opensearch.rest.action.admin.indices.AliasesNotFoundException in project OpenSearch by opensearch-project.

the class TransportIndicesAliasesAction method masterOperation.

@Override
protected void masterOperation(final IndicesAliasesRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) {
    // Expand the indices names
    List<IndicesAliasesRequest.AliasActions> actions = request.aliasActions();
    List<AliasAction> finalActions = new ArrayList<>();
    // Resolve all the AliasActions into AliasAction instances and gather all the aliases
    Set<String> aliases = new HashSet<>();
    for (IndicesAliasesRequest.AliasActions action : actions) {
        final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request.indicesOptions(), false, action.indices());
        for (Index concreteIndex : concreteIndices) {
            IndexAbstraction indexAbstraction = state.metadata().getIndicesLookup().get(concreteIndex.getName());
            assert indexAbstraction != null : "invalid cluster metadata. index [" + concreteIndex.getName() + "] was not found";
            if (indexAbstraction.getParentDataStream() != null) {
                throw new IllegalArgumentException("The provided expressions [" + String.join(",", action.indices()) + "] match a backing index belonging to data stream [" + indexAbstraction.getParentDataStream().getName() + "]. Data streams and their backing indices don't support aliases.");
            }
        }
        final Optional<Exception> maybeException = requestValidators.validateRequest(request, state, concreteIndices);
        if (maybeException.isPresent()) {
            listener.onFailure(maybeException.get());
            return;
        }
        Collections.addAll(aliases, action.getOriginalAliases());
        for (final Index index : concreteIndices) {
            switch(action.actionType()) {
                case ADD:
                    for (String alias : concreteAliases(action, state.metadata(), index.getName())) {
                        finalActions.add(new AliasAction.Add(index.getName(), alias, action.filter(), action.indexRouting(), action.searchRouting(), action.writeIndex(), action.isHidden()));
                    }
                    break;
                case REMOVE:
                    for (String alias : concreteAliases(action, state.metadata(), index.getName())) {
                        finalActions.add(new AliasAction.Remove(index.getName(), alias, action.mustExist()));
                    }
                    break;
                case REMOVE_INDEX:
                    finalActions.add(new AliasAction.RemoveIndex(index.getName()));
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported action [" + action.actionType() + "]");
            }
        }
    }
    if (finalActions.isEmpty() && false == actions.isEmpty()) {
        throw new AliasesNotFoundException(aliases.toArray(new String[aliases.size()]));
    }
    request.aliasActions().clear();
    IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest(unmodifiableList(finalActions)).ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout());
    indexAliasesService.indicesAliases(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {

        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new AcknowledgedResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug("failed to perform aliases", t);
            listener.onFailure(t);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Index(org.opensearch.index.Index) ClusterStateUpdateResponse(org.opensearch.cluster.ack.ClusterStateUpdateResponse) HashSet(java.util.HashSet) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) AliasesNotFoundException(org.opensearch.rest.action.admin.indices.AliasesNotFoundException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) IndexAbstraction(org.opensearch.cluster.metadata.IndexAbstraction) AliasAction(org.opensearch.cluster.metadata.AliasAction) AliasesNotFoundException(org.opensearch.rest.action.admin.indices.AliasesNotFoundException)

Aggregations

AliasesNotFoundException (org.opensearch.rest.action.admin.indices.AliasesNotFoundException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1 ClusterStateUpdateResponse (org.opensearch.cluster.ack.ClusterStateUpdateResponse)1 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)1 AliasAction (org.opensearch.cluster.metadata.AliasAction)1 IndexAbstraction (org.opensearch.cluster.metadata.IndexAbstraction)1 Index (org.opensearch.index.Index)1