Package com.github.ambry.frontend
Class AccountAndContainerInjector
- java.lang.Object
-
- com.github.ambry.frontend.AccountAndContainerInjector
-
public class AccountAndContainerInjector extends java.lang.Object
Helper class to resolve and addAccount
andContainer
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-unknownAccount
andContainer
was not previously injected, inject them into the providedRestRequest
, based on the givenBlobProperties
' service ID and blob privacy setting.void
injectAccountAndContainerForPostRequest(com.github.ambry.rest.RestRequest restRequest, com.github.ambry.frontend.RestRequestMetricsGroup metricsGroup)
Injects targetAccount
andContainer
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 targetAccount
andContainer
id from the blobId string, queries theAccountService
to get the correspondingAccount
andContainer
, and injects the targetAccount
andContainer
into theRestRequest
.
-
-
-
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 targetAccount
andContainer
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 thex-ambry-target-account
andx-ambry-target-container
headers.- Parameters:
restRequest
- The PutRestRequest
.metricsGroup
- TheRestRequestMetricsGroup
to use to set upContainerMetrics
, ornull
ifContainerMetrics
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 targetAccount
andContainer
id from the blobId string, queries theAccountService
to get the correspondingAccount
andContainer
, and injects the targetAccount
andContainer
into theRestRequest
.- Parameters:
blobId
- The blobId to get the targetAccount
andContainer
id.restRequest
- The rest request to insert the targetAccount
andContainer
.metricsGroup
- TheRestRequestMetricsGroup
to use to set upContainerMetrics
, ornull
ifContainerMetrics
instantiation is not needed.- Throws:
com.github.ambry.rest.RestServiceException
- if 1) eitherAccount
orContainer
could not be found; or 2) eitherAccount
orContainer
IDs were explicitly specified asAccount.UNKNOWN_ACCOUNT_ID
orContainer.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-unknownAccount
andContainer
was not previously injected, inject them into the providedRestRequest
, based on the givenBlobProperties
' service ID and blob privacy setting. This is useful for V1 blob IDs that do not directly encode the account/container ID.- Parameters:
restRequest
- TheRestRequest
to injectAccount
andContainer
.blobProperties
- TheBlobProperties
that contains the service id and blob privacy setting.metricsGroup
- TheRestRequestMetricsGroup
to use to set upContainerMetrics
, ornull
ifContainerMetrics
instantiation is not needed.- Throws:
com.github.ambry.rest.RestServiceException
- if no valid account or container could be identified for re-injection.
-
-