Search in sources :

Example 1 with Custom

use of org.elasticsearch.cluster.metadata.MetaData.Custom in project elasticsearch by elastic.

the class TransportClusterStateAction method masterOperation.

@Override
protected void masterOperation(final ClusterStateRequest request, final ClusterState state, final ActionListener<ClusterStateResponse> listener) throws IOException {
    ClusterState currentState = clusterService.state();
    logger.trace("Serving cluster state request using version {}", currentState.version());
    ClusterState.Builder builder = ClusterState.builder(currentState.getClusterName());
    builder.version(currentState.version());
    builder.stateUUID(currentState.stateUUID());
    if (request.nodes()) {
        builder.nodes(currentState.nodes());
    }
    if (request.routingTable()) {
        if (request.indices().length > 0) {
            RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
            String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request);
            for (String filteredIndex : indices) {
                if (currentState.routingTable().getIndicesRouting().containsKey(filteredIndex)) {
                    routingTableBuilder.add(currentState.routingTable().getIndicesRouting().get(filteredIndex));
                }
            }
            builder.routingTable(routingTableBuilder.build());
        } else {
            builder.routingTable(currentState.routingTable());
        }
    }
    if (request.blocks()) {
        builder.blocks(currentState.blocks());
    }
    if (request.metaData()) {
        MetaData.Builder mdBuilder;
        if (request.indices().length == 0) {
            mdBuilder = MetaData.builder(currentState.metaData());
        } else {
            mdBuilder = MetaData.builder();
        }
        if (request.indices().length > 0) {
            String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request);
            for (String filteredIndex : indices) {
                IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex);
                if (indexMetaData != null) {
                    mdBuilder.put(indexMetaData, false);
                }
            }
        }
        // Filter our metadata that shouldn't be returned by API
        for (ObjectObjectCursor<String, Custom> custom : currentState.metaData().customs()) {
            if (!custom.value.context().contains(MetaData.XContentContext.API)) {
                mdBuilder.removeCustom(custom.key);
            }
        }
        builder.metaData(mdBuilder);
    }
    if (request.customs()) {
        builder.customs(currentState.customs());
    }
    listener.onResponse(new ClusterStateResponse(currentState.getClusterName(), builder.build(), serializeFullClusterState(currentState, Version.CURRENT).length()));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PublishClusterStateAction.serializeFullClusterState(org.elasticsearch.discovery.zen.PublishClusterStateAction.serializeFullClusterState) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Custom(org.elasticsearch.cluster.metadata.MetaData.Custom) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

ClusterState (org.elasticsearch.cluster.ClusterState)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 Custom (org.elasticsearch.cluster.metadata.MetaData.Custom)1 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)1 PublishClusterStateAction.serializeFullClusterState (org.elasticsearch.discovery.zen.PublishClusterStateAction.serializeFullClusterState)1