Class ProjectMetadata

java.lang.Object
org.elasticsearch.cluster.metadata.ProjectMetadata
All Implemented Interfaces:
Iterable<IndexMetadata>, Diffable<ProjectMetadata>, Writeable, ChunkedToXContent

public class ProjectMetadata extends Object implements Iterable<IndexMetadata>, Diffable<ProjectMetadata>, ChunkedToXContent
  • Field Details

    • PROJECT_UNDER_DELETION_BLOCK

      public static final ClusterBlock PROJECT_UNDER_DELETION_BLOCK
  • Method Details

    • withLifecycleState

      public ProjectMetadata withLifecycleState(Index index, LifecycleExecutionState lifecycleState)
      Given an index and lifecycle state, returns a metadata where the lifecycle state will be associated with the given index. The passed-in index must already be present in the cluster state, this method cannot be used to add an index.
      Parameters:
      index - A non-null index
      lifecycleState - A non-null lifecycle execution state
      Returns:
      a Metadata instance where the index has the provided lifecycle state
    • withIndexSettingsUpdates

      public ProjectMetadata withIndexSettingsUpdates(Map<Index,Settings> updates)
    • withAllocationAndTermUpdatesOnly

      public ProjectMetadata withAllocationAndTermUpdatesOnly(Map<String,IndexMetadata> updates)
      Creates a copy of this instance updated with the given IndexMetadata that must only contain changes to primary terms and in-sync allocation ids relative to the existing entries. This method is only used by IndexMetadataUpdater.applyChanges(Metadata, GlobalRoutingTable).
      Parameters:
      updates - map of index name to IndexMetadata.
      Returns:
      updated metadata instance
    • withAddedIndex

      public ProjectMetadata withAddedIndex(IndexMetadata index)
      Creates a copy of this instance with the given index added.
      Parameters:
      index - index to add
      Returns:
      copy with added index
    • id

      public ProjectId id()
      Returns:
      The identifier of this project
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasIndex

      public boolean hasIndex(String index)
      Checks whether an index exists (as of this ProjectMetadata with the given name. Does not check aliases or data streams.
      Parameters:
      index - An index name that may or may not exist in the cluster.
      Returns:
      true if a concrete index with that name exists, false otherwise.
    • hasIndex

      public boolean hasIndex(Index index)
      Checks whether an index exists. Similar to hasIndex(String), but ensures that the index has the same UUID as the given Index.
      Parameters:
      index - An Index object that may or may not exist in the cluster.
      Returns:
      true if an index exists with the same name and UUID as the given index object, false otherwise.
    • hasIndexMetadata

      public boolean hasIndexMetadata(IndexMetadata indexMetadata)
      Returns true iff existing index has the same IndexMetadata instance
    • hasIndexAbstraction

      public boolean hasIndexAbstraction(String index)
      Checks whether an index abstraction (that is, index, alias, or data stream) exists (as of this Metadata with the given name.
      Parameters:
      index - An index name that may or may not exist in the cluster.
      Returns:
      true if an index abstraction with that name exists, false otherwise.
    • index

      public IndexMetadata index(String index)
    • index

      public IndexMetadata index(Index index)
    • indexGraveyard

      public IndexGraveyard indexGraveyard()
      The collection of index deletions in the cluster.
    • getIndexSafe

      public IndexMetadata getIndexSafe(Index index)
      Returns the IndexMetadata for this index.
      Throws:
      IndexNotFoundException - if no metadata for this index is found
    • getIndicesLookup

      public SortedMap<String,IndexAbstraction> getIndicesLookup()
    • sameIndicesLookup

      public boolean sameIndicesLookup(ProjectMetadata other)
    • hasAlias

      public boolean hasAlias(String aliasName)
      Returns whether an alias exists with provided alias name.
      Parameters:
      aliasName - The provided alias name
      Returns:
      whether an alias exists with provided alias name
    • findAllAliases

      public Map<String,List<AliasMetadata>> findAllAliases(String[] concreteIndices)
      Finds the specific index aliases that point to the requested concrete indices directly or that match with the indices via wildcards.
      Parameters:
      concreteIndices - The concrete indices that the aliases must point to in order to be returned.
      Returns:
      A map of index name to the list of aliases metadata. If a concrete index does not have matching aliases then the result will not include the index's key.
    • findAliases

      public Map<String,List<AliasMetadata>> findAliases(String[] aliases, String[] concreteIndices)
      Finds the specific index aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified concrete indices (directly or matching indices via wildcards).
      Parameters:
      aliases - The aliases to look for. Might contain include or exclude wildcards.
      concreteIndices - The concrete indices that the aliases must point to in order to be returned
      Returns:
      A map of index name to the list of aliases metadata. If a concrete index does not have matching aliases then the result will not include the index's key.
    • aliasedIndices

      public Set<Index> aliasedIndices(String aliasName)
      Returns all the indices that the alias with the provided alias name refers to. These are aliased indices. Not that, this only return indices that have been aliased and not indices that are behind a data stream or data stream alias.
      Parameters:
      aliasName - The provided alias name
      Returns:
      all aliased indices by the alias with the provided alias name
    • aliasedIndices

      public Set<String> aliasedIndices()
      Returns:
      the names of all indices aliases.
    • equalsAliases

      public boolean equalsAliases(ProjectMetadata other)
    • findMappings

      public Map<String,MappingMetadata> findMappings(String[] concreteIndices, Function<String,? extends Predicate<String>> fieldFilter, Runnable onNextIndex)
      Finds all mappings for concrete indices. Only fields that match the provided field filter will be returned (default is a predicate that always returns true, which can be overridden via plugins)
      Parameters:
      onNextIndex - a hook that gets notified for each index that's processed
      See Also:
    • getMappingsByHash

      public Map<String,MappingMetadata> getMappingsByHash()
    • indices

      public Map<String,IndexMetadata> indices()
    • templates

      public Map<String,IndexTemplateMetadata> templates()
    • indexIsADataStream

      public boolean indexIsADataStream(String indexName)
      Checks whether the provided index is a data stream.
    • getTotalNumberOfShards

      public int getTotalNumberOfShards()
      Gets the total number of shards from all indices, including replicas and closed indices.
    • getTotalOpenIndexShards

      public int getTotalOpenIndexShards()
      Gets the total number of open shards from all indices. Includes replicas, but does not include shards that are part of closed indices.
    • getConcreteAllIndices

      public String[] getConcreteAllIndices()
      Returns all the concrete indices.
    • getConcreteVisibleIndices

      public String[] getConcreteVisibleIndices()
      Returns all the concrete indices that are not hidden.
    • getConcreteAllOpenIndices

      public String[] getConcreteAllOpenIndices()
      Returns all of the concrete indices that are open.
    • getConcreteVisibleOpenIndices

      public String[] getConcreteVisibleOpenIndices()
      Returns all of the concrete indices that are open and not hidden.
    • getConcreteAllClosedIndices

      public String[] getConcreteAllClosedIndices()
      Returns all of the concrete indices that are closed.
    • getConcreteVisibleClosedIndices

      public String[] getConcreteVisibleClosedIndices()
      Returns all of the concrete indices that are closed and not hidden.
    • indicesLookupInitialized

      public boolean indicesLookupInitialized()
    • oldestIndexVersion

      public IndexVersion oldestIndexVersion()
    • resolveWriteIndexRouting

      public String resolveWriteIndexRouting(@Nullable String routing, String aliasOrIndex)
      Returns indexing routing for the given aliasOrIndex. Resolves routing from the alias metadata used in the write index.
    • resolveIndexRouting

      public String resolveIndexRouting(@Nullable String routing, String aliasOrIndex)
      Returns indexing routing for the given index.
    • iterator

      public Iterator<IndexMetadata> iterator()
      Specified by:
      iterator in interface Iterable<IndexMetadata>
    • stream

      public Stream<IndexMetadata> stream()
    • size

      public int size()
    • custom

      public <T extends Metadata.ProjectCustom> T custom(String type)
    • custom

      public <T extends Metadata.ProjectCustom> T custom(String type, T defaultValue)
    • customs

    • reservedStateMetadata

      public Map<String,ReservedStateMetadata> reservedStateMetadata()
    • dataStreams

      public Map<String,DataStream> dataStreams()
    • dataStreamAliases

      public Map<String,DataStreamAlias> dataStreamAliases()
    • dataStreamAliasesByDataStream

      public Map<String,List<DataStreamAlias>> dataStreamAliasesByDataStream()
      Return a map of DataStreamAlias objects by DataStream name
    • findDataStreams

      public Map<String,DataStream> findDataStreams(String... concreteIndices)
      Finds the parent data streams, if any, for the specified concrete indices.
    • findDataStreamAliases

      public Map<String,List<DataStreamAlias>> findDataStreamAliases(String[] aliases, String[] dataStreams)
      Finds the specific data stream aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified data streams (directly or matching data streams via wildcards).
      Parameters:
      aliases - The aliases to look for. Might contain include or exclude wildcards.
      dataStreams - The data streams that the aliases must point to in order to be returned
      Returns:
      A map of data stream name to the list of DataStreamAlias objects that match. If a data stream does not have matching aliases then the result will not include the data stream's key.
    • componentTemplates

      public Map<String,ComponentTemplate> componentTemplates()
    • templatesV2

      public Map<String,ComposableIndexTemplate> templatesV2()
    • retrieveIndexModeFromTemplate

      public IndexMode retrieveIndexModeFromTemplate(ComposableIndexTemplate indexTemplate)
    • isIndexManagedByILM

      public boolean isIndexManagedByILM(IndexMetadata indexMetadata)
      Indicates if the provided index is managed by ILM. This takes into account if the index is part of data stream that's potentially managed by data stream lifecycle and the value of the IndexSettings.PREFER_ILM_SETTING
    • getSecret

      public Optional<SecureString> getSecret(String key)
    • builder

      public static ProjectMetadata.Builder builder(ProjectId id)
    • builder

      public static ProjectMetadata.Builder builder(ProjectMetadata projectMetadata)
    • copyAndUpdate

      public ProjectMetadata copyAndUpdate(Consumer<ProjectMetadata.Builder> updater)
    • toXContentChunked

      public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params p)
      Description copied from interface: ChunkedToXContent
      Create an iterator of ToXContent chunks for a REST response. Each chunk is serialized with the same XContentBuilder and ToXContent.Params, which is also the same as the ToXContent.Params passed as the params argument. For best results, all chunks should be O(1) size. The last chunk in the iterator must always yield at least one byte of output. See also ChunkedToXContentHelper for some handy utilities.

      Note that chunked response bodies cannot send deprecation warning headers once transmission has started, so implementations must check for deprecated feature use before returning.

      Specified by:
      toXContentChunked in interface ChunkedToXContent
      Returns:
      iterator over chunks of ToXContent
    • readFrom

      public static ProjectMetadata readFrom(StreamInput in) throws IOException
      Throws:
      IOException
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • diff

      public org.elasticsearch.cluster.metadata.ProjectMetadata.ProjectMetadataDiff diff(ProjectMetadata previousState)
      Description copied from interface: Diffable
      Returns serializable object representing differences between this and previousState
      Specified by:
      diff in interface Diffable<ProjectMetadata>