Class SecurityIndexManager

java.lang.Object
org.elasticsearch.xpack.security.support.SecurityIndexManager
All Implemented Interfaces:
org.elasticsearch.cluster.ClusterStateListener

public class SecurityIndexManager extends Object implements org.elasticsearch.cluster.ClusterStateListener
Manages the lifecycle, mapping and data upgrades/migrations of the RestrictedIndicesNames#SECURITY_MAIN_ALIAS and RestrictedIndicesNames#SECURITY_MAIN_ALIAS alias-index pair.
  • Field Details

  • Method Details

    • buildSecurityIndexManager

      public static SecurityIndexManager buildSecurityIndexManager(org.elasticsearch.client.internal.Client client, org.elasticsearch.cluster.service.ClusterService clusterService, org.elasticsearch.indices.SystemIndexDescriptor descriptor)
    • freeze

      public SecurityIndexManager freeze()
    • aliasName

      public String aliasName()
    • indexExists

      public boolean indexExists()
    • getCreationTime

      public Instant getCreationTime()
    • isIndexUpToDate

      public boolean isIndexUpToDate()
      Returns whether the index is on the current format if it exists. If the index does not exist we treat the index as up to date as we expect it to be created with the current format.
    • isAvailable

      public boolean isAvailable()
    • isMappingUpToDate

      public boolean isMappingUpToDate()
    • isStateRecovered

      public boolean isStateRecovered()
    • getUnavailableReason

      public org.elasticsearch.ElasticsearchException getUnavailableReason()
    • addStateListener

      public void addStateListener(BiConsumer<SecurityIndexManager.State,SecurityIndexManager.State> listener)
      Add a listener for notifications on state changes to the configured index. The previous and current state are provided.
    • removeStateListener

      public void removeStateListener(BiConsumer<SecurityIndexManager.State,SecurityIndexManager.State> listener)
      Remove a listener from notifications on state changes to the configured index.
    • clusterChanged

      public void clusterChanged(org.elasticsearch.cluster.ClusterChangedEvent event)
      Specified by:
      clusterChanged in interface org.elasticsearch.cluster.ClusterStateListener
    • onStateRecovered

      public void onStateRecovered(Consumer<SecurityIndexManager.State> recoveredStateConsumer)
    • checkIndexMappingVersionMatches

      public static boolean checkIndexMappingVersionMatches(String indexName, org.elasticsearch.cluster.ClusterState clusterState, org.apache.logging.log4j.Logger logger, Predicate<org.elasticsearch.Version> predicate)
    • checkIndexVersionThenExecute

      public void checkIndexVersionThenExecute(Consumer<Exception> consumer, Runnable andThen)
      Validates that the index is up to date and does not need to be migrated. If it is not, the consumer is called with an exception. If the index is up to date, the runnable will be executed. NOTE: this method does not check the availability of the index; this check is left to the caller so that this condition can be handled appropriately.
    • prepareIndexIfNeededThenExecute

      public void prepareIndexIfNeededThenExecute(Consumer<Exception> consumer, Runnable andThen)
      Prepares the index by creating it if it doesn't exist, then executes the runnable.
      Parameters:
      consumer - a handler for any exceptions that are raised either during preparation or execution
      andThen - executed if the index exists or after preparation is performed successfully
    • isMoveFromRedToNonRed

      public static boolean isMoveFromRedToNonRed(SecurityIndexManager.State previousState, SecurityIndexManager.State currentState)
      Return true if the state moves from an unhealthy ("RED") index state to a healthy ("non-RED") state.
    • isIndexDeleted

      public static boolean isIndexDeleted(SecurityIndexManager.State previousState, SecurityIndexManager.State currentState)
      Return true if the state moves from the index existing to the index not existing.