Class AbstractProjectResolver

java.lang.Object
org.elasticsearch.cluster.project.AbstractProjectResolver
All Implemented Interfaces:
ProjectIdResolver, ProjectResolver

public abstract class AbstractProjectResolver extends Object implements ProjectResolver
A ProjectResolver that uses Task.X_ELASTIC_PROJECT_ID_HTTP_HEADER to find the active project
  • Constructor Details

  • Method Details

    • getFallbackProjectId

      protected abstract ProjectId getFallbackProjectId()
      Subclasses should override this method to handle the case where no project id is specified in the thread context. This may return a default project id or throw an exception
    • allowAccessToAllProjects

      protected abstract boolean allowAccessToAllProjects(ThreadContext threadContext)
      Returns true if the current request is permitted to perform operations on all projects, false otherwise.
    • getProjectId

      public ProjectId getProjectId()
      Description copied from interface: ProjectIdResolver
      Retrieve the project for the current request.
      Specified by:
      getProjectId in interface ProjectIdResolver
      Returns:
      The identifier of the current project.
    • getProjectIds

      public Collection<ProjectId> getProjectIds(ClusterState clusterState)
      Description copied from interface: ProjectResolver
      Returns the identifiers of all projects on which this request should operate. In practice, this will either be:
      • If the request is tied to a single project, then a collection with a single item that is the same as ProjectIdResolver.getProjectId() if the project exists in the cluster state
      • If the request is not tied to a single project and it is allowed to access all projects, then a collection of all the project ids in the cluster
      • Otherwise an exception is thrown
      Specified by:
      getProjectIds in interface ProjectResolver
      Returns:
      A readonly collection of all the project ids on which this request should operate
    • executeOnProject

      public <E extends Exception> void executeOnProject(ProjectId projectId, CheckedRunnable<E> body) throws E
      Description copied from interface: ProjectResolver
      Execute a block in the context of a specific project. This method:
      1. Configures the execution (thread) context so that any calls to resolve a project (e.g. ProjectIdResolver.getProjectId() or ProjectResolver.getProjectMetadata(Metadata)) will return the project specified by projectId.
      2. Executes the CheckedRunnable.run() method on the supplied body
      3. Restores the context to its original state
      Specified by:
      executeOnProject in interface ProjectResolver
      Throws:
      E
    • supportsMultipleProjects

      public boolean supportsMultipleProjects()
      Description copied from interface: ProjectIdResolver
      Returns false if the cluster runs in a setup that always expects only a single default project (see also Metadata.DEFAULT_PROJECT_ID). Otherwise, it should return true to indicate the cluster can accommodate multiple projects regardless how many project it current has.
      Specified by:
      supportsMultipleProjects in interface ProjectIdResolver
    • findProject

      protected static ProjectMetadata findProject(Metadata metadata, String headerValue)
    • getProjectIdFromThreadContext

      protected String getProjectIdFromThreadContext()