private void injectAccountAndContainerUsingServiceId(RestRequest restRequest, String serviceId, boolean isPrivate,
      RestRequestMetricsGroup metricsGroup) throws RestServiceException {
    // First, try to see if a migrated account exists for the service ID.
    Account targetAccount = accountService.getAccountByName(serviceId);
    if (targetAccount == null) {
      frontendMetrics.unrecognizedServiceIdCount.inc();
      logger.debug(
          "Account cannot be found for put request with serviceId={}. Setting targetAccount to UNKNOWN_ACCOUNT",
          serviceId);
      // If a migrated account does not exist fall back to the UNKNOWN_ACCOUNT.
      targetAccount = accountService.getAccountById(Account.UNKNOWN_ACCOUNT_ID);
    }
    // Either the UNKNOWN_ACCOUNT, or the migrated account should contain default public/private containers
    Container targetContainer;
    short containerId = isPrivate ? Container.DEFAULT_PRIVATE_CONTAINER_ID : Container.DEFAULT_PUBLIC_CONTAINER_ID;
    try {
      targetContainer = accountService.getContainerById(targetAccount.getId(), containerId);
    } catch (AccountServiceException e) {
      throw new RestServiceException(
          "Failed to get container with Id= " + containerId + " from account " + targetAccount.getName()
              + "for put request; ServiceId=" + serviceId + ", isPrivate=" + isPrivate,
          RestServiceErrorCode.getRestServiceErrorCode(e.getErrorCode()));
    }
    if (targetContainer == null) {
      throw new RestServiceException(
          "Invalid account or container to inject; serviceId=" + serviceId + ", isPrivate=" + isPrivate,
          RestServiceErrorCode.InternalServerError);
    }
    setTargetAccountAndContainerInRestRequest(restRequest, targetAccount, targetContainer, metricsGroup);
  }
Inject {@link Account} and {@link Container} into a {@link RestRequest} based on a blob's service ID and
privacy setting.
@param restRequest The {@link RestRequest} to inject {@link Account} and {@link Container} object.
@param serviceId The service ID associated with the blob.
@param isPrivate The blob's privacy setting.
@param metricsGroup The {@link RestRequestMetricsGroup} to use to set up {@link ContainerMetrics}, or {@code null}
                    if {@link ContainerMetrics} instantiation is not needed.
@throws RestServiceException if either of {@link Account} or {@link Container} object could not be found.
ambry-frontend/src/main/java/com/github/ambry/frontend/AccountAndContainerInjector.java