Class AccountAndContainerInjector


  • public class AccountAndContainerInjector
    extends java.lang.Object
    Helper class to resolve and add Account and Container details to requests.
    • Constructor Summary

      Constructors 
      Constructor Description
      AccountAndContainerInjector​(com.github.ambry.account.AccountService accountService, FrontendMetrics frontendMetrics, com.github.ambry.config.FrontendConfig frontendConfig)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void ensureAccountAndContainerInjected​(com.github.ambry.rest.RestRequest restRequest, com.github.ambry.messageformat.BlobProperties blobProperties, com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
      If a non-unknown Account and Container was not previously injected, inject them into the provided RestRequest, based on the given BlobProperties' service ID and blob privacy setting.
      void injectAccountAndContainerForNamedBlob​(com.github.ambry.rest.RestRequest restRequest, com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
      Injects target Account and Container for named blob requests.
      void injectAccountAndContainerForPostRequest​(com.github.ambry.rest.RestRequest restRequest, com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
      Injects target Account and Container for PUT requests.
      void injectTargetAccountAndContainerFromBlobId​(com.github.ambry.commons.BlobId blobId, com.github.ambry.rest.RestRequest restRequest, com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
      Obtains the target Account and Container id from the blobId string, queries the AccountService to get the corresponding Account and Container, and injects the target Account and Container into the RestRequest.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AccountAndContainerInjector

        public AccountAndContainerInjector​(com.github.ambry.account.AccountService accountService,
                                           FrontendMetrics frontendMetrics,
                                           com.github.ambry.config.FrontendConfig frontendConfig)
    • Method Detail

      • injectAccountAndContainerForPostRequest

        public void injectAccountAndContainerForPostRequest​(com.github.ambry.rest.RestRequest restRequest,
                                                            com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
                                                     throws com.github.ambry.rest.RestServiceException
        Injects target Account and Container for PUT requests. This method also ensures required headers are present for the PUT requests that use serviceId as the account name, and the PUT requests that carry both the x-ambry-target-account and x-ambry-target-container headers.
        Parameters:
        restRequest - The Put RestRequest.
        metricsGroup - The RestRequestMetricsGroup to use to set up ContainerMetrics, or null if ContainerMetrics instantiation is not needed.
        Throws:
        com.github.ambry.rest.RestServiceException
      • injectAccountAndContainerForNamedBlob

        public void injectAccountAndContainerForNamedBlob​(com.github.ambry.rest.RestRequest restRequest,
                                                          com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
                                                   throws com.github.ambry.rest.RestServiceException
        Injects target Account and Container for named blob requests. This will treat the request path as a named blob path that includes the account and container names.
        Parameters:
        restRequest - The Put RestRequest.
        metricsGroup - The RestRequestMetricsGroup to use to set up ContainerMetrics, or null if ContainerMetrics instantiation is not needed.
        Throws:
        com.github.ambry.rest.RestServiceException
      • injectTargetAccountAndContainerFromBlobId

        public void injectTargetAccountAndContainerFromBlobId​(com.github.ambry.commons.BlobId blobId,
                                                              com.github.ambry.rest.RestRequest restRequest,
                                                              com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
                                                       throws com.github.ambry.rest.RestServiceException
        Obtains the target Account and Container id from the blobId string, queries the AccountService to get the corresponding Account and Container, and injects the target Account and Container into the RestRequest.
        Parameters:
        blobId - The blobId to get the target Account and Container id.
        restRequest - The rest request to insert the target Account and Container.
        metricsGroup - The RestRequestMetricsGroup to use to set up ContainerMetrics, or null if ContainerMetrics instantiation is not needed.
        Throws:
        com.github.ambry.rest.RestServiceException - if 1) either Account or Container could not be found; or 2) either Account or Container IDs were explicitly specified as Account.UNKNOWN_ACCOUNT_ID or Container.UNKNOWN_CONTAINER_ID.
      • ensureAccountAndContainerInjected

        public void ensureAccountAndContainerInjected​(com.github.ambry.rest.RestRequest restRequest,
                                                      com.github.ambry.messageformat.BlobProperties blobProperties,
                                                      com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
                                               throws com.github.ambry.rest.RestServiceException
        If a non-unknown Account and Container was not previously injected, inject them into the provided RestRequest, based on the given BlobProperties' service ID and blob privacy setting. This is useful for V1 blob IDs that do not directly encode the account/container ID.
        Parameters:
        restRequest - The RestRequest to inject Account and Container.
        blobProperties - The BlobProperties that contains the service id and blob privacy setting.
        metricsGroup - The RestRequestMetricsGroup to use to set up ContainerMetrics, or null if ContainerMetrics instantiation is not needed.
        Throws:
        com.github.ambry.rest.RestServiceException - if no valid account or container could be identified for re-injection.