Search in sources :

Example 1 with AliasesNotFoundException

use of org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException in project elasticsearch by elastic.

the class TransportIndicesAliasesAction method masterOperation.

@Override
protected void masterOperation(final IndicesAliasesRequest request, final ClusterState state, final ActionListener<IndicesAliasesResponse> listener) {
    //Expand the indices names
    List<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 (AliasActions action : actions) {
        String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request.indicesOptions(), action.indices());
        Collections.addAll(aliases, action.aliases());
        for (String index : concreteIndices) {
            switch(action.actionType()) {
                case ADD:
                    for (String alias : action.concreteAliases(state.metaData(), index)) {
                        finalActions.add(new AliasAction.Add(index, alias, action.filter(), action.indexRouting(), action.searchRouting()));
                    }
                    break;
                case REMOVE:
                    for (String alias : action.concreteAliases(state.metaData(), index)) {
                        finalActions.add(new AliasAction.Remove(index, alias));
                    }
                    break;
                case REMOVE_INDEX:
                    finalActions.add(new AliasAction.RemoveIndex(index));
                    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 IndicesAliasesResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug("failed to perform aliases", t);
            listener.onFailure(t);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) AliasesNotFoundException(org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) AliasAction(org.elasticsearch.cluster.metadata.AliasAction) AliasesNotFoundException(org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) HashSet(java.util.HashSet)

Example 2 with AliasesNotFoundException

use of org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException in project elasticsearch by elastic.

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.elasticsearch.rest.action.admin.indices.AliasesNotFoundException)

Aggregations

AliasesNotFoundException (org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AliasActions (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)1 ClusterStateUpdateResponse (org.elasticsearch.cluster.ack.ClusterStateUpdateResponse)1 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)1 AliasAction (org.elasticsearch.cluster.metadata.AliasAction)1