Class OMClientRequest

java.lang.Object
org.apache.hadoop.ozone.om.request.OMClientRequest
All Implemented Interfaces:
RequestAuditor
Direct Known Subclasses:
OMBucketAclRequest, OMBucketCreateRequest, OMBucketDeleteRequest, OMBucketSetOwnerRequest, OMBucketSetPropertyRequest, OMCancelDelegationTokenRequest, OMCancelPrepareRequest, OMEchoRPCWriteRequest, OMFinalizeUpgradeRequest, OMGetDelegationTokenRequest, OMKeyAclRequest, OMKeyRequest, OMPrefixAclRequest, OMPrepareRequest, OMQuotaRepairRequest, OMRenewDelegationTokenRequest, OMSetRangerServiceVersionRequest, OMSetSecretRequest, OMSnapshotCreateRequest, OMSnapshotDeleteRequest, OMSnapshotMoveDeletedKeysRequest, OMSnapshotMoveTableKeysRequest, OMSnapshotPurgeRequest, OMSnapshotRenameRequest, OMSnapshotSetPropertyRequest, OMTenantAssignAdminRequest, OMTenantAssignUserAccessIdRequest, OMTenantRevokeAdminRequest, OMTenantRevokeUserAccessIdRequest, OMVolumeRequest, S3GetSecretRequest, S3RevokeSecretRequest

public abstract class OMClientRequest extends Object implements RequestAuditor
OMClientRequest provides methods which every write OM request should implement.
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
  • Constructor Details

    • OMClientRequest

      public OMClientRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest omRequest)
  • Method Details

    • getAuditBuilder

      public OMAuditLogger.Builder getAuditBuilder()
    • preExecute

      public org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest preExecute(OzoneManager ozoneManager) throws IOException
      Perform pre-execute steps on a OMRequest. Called from the RPC context, and generates a OMRequest object which has all the information that will be either persisted in RocksDB or returned to the caller once this operation is executed.
      Returns:
      OMRequest that will be serialized and handed off to Ratis for consensus.
      Throws:
      IOException
    • handleRequestFailure

      public void handleRequestFailure(OzoneManager ozoneManager)
      Performs any request specific failure handling during request submission. An example of this would be an undo of any steps taken during pre-execute.
    • validateAndUpdateCache

      public abstract OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, ExecutionContext context)
      Validate the OMRequest and update the cache. This step should verify that the request can be executed, perform any authorization steps and update the in-memory cache. This step does not persist the changes to the database. To coders and reviewers, CAUTION: Do NOT bring external dependencies into this method, doing so could potentially cause divergence in OM DB states in HA. If you have to, be extremely careful. e.g. Do NOT invoke ACL check inside validateAndUpdateCache, which can use Ranger plugin that relies on external DB.
      Returns:
      the response that will be returned to the client.
    • validateAndUpdateCache

      public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex)
      For testing only.
    • getOmRequest

      public org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest getOmRequest()
    • getUserInfo

      public org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.UserInfo getUserInfo() throws IOException
      Get User information which needs to be set in the OMRequest object.
      Returns:
      User Info.
      Throws:
      IOException
    • getUserIfNotExists

      public org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.UserInfo getUserIfNotExists(OzoneManager ozoneManager) throws IOException
      For non-rpc internal calls Server.getRemoteUser() and Server.getRemoteIp() will be null. Passing getCurrentUser() and Ip of the Om node that started it.
      Returns:
      User Info.
      Throws:
      IOException
    • checkAcls

      public void checkAcls(OzoneManager ozoneManager, org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType resType, org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType storeType, org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType aclType, String vol, String bucket, String key) throws IOException
      Check Acls of ozone object.
      Parameters:
      ozoneManager -
      resType -
      storeType -
      aclType -
      vol -
      bucket -
      key -
      Throws:
      IOException
    • checkACLsWithFSO

      protected void checkACLsWithFSO(OzoneManager ozoneManager, String volumeName, String bucketName, String keyName, org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType aclType) throws IOException
      Check Acls for the ozone key.
      Parameters:
      ozoneManager -
      volumeName -
      bucketName -
      keyName -
      Throws:
      IOException
    • checkAcls

      public void checkAcls(OzoneManager ozoneManager, org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType resType, org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType storeType, org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType aclType, String vol, String bucket, String key, String volOwner) throws IOException
      Check Acls of ozone object with volOwner given.
      Parameters:
      ozoneManager -
      resType -
      storeType -
      aclType -
      vol -
      bucket -
      key -
      volOwner -
      Throws:
      IOException
    • checkAcls

      public void checkAcls(OzoneManager ozoneManager, org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType resType, org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType storeType, org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType aclType, String vol, String bucket, String key, String volOwner, String bucketOwner) throws IOException
      Check Acls of ozone object with volOwner given.
      Parameters:
      ozoneManager -
      resType -
      storeType -
      aclType -
      vol -
      bucket -
      key -
      volOwner -
      bucketOwner -
      Throws:
      IOException
    • createUGI

      public org.apache.hadoop.security.UserGroupInformation createUGI() throws org.apache.hadoop.security.authentication.client.AuthenticationException
      Return UGI object created from OMRequest userInfo. If userInfo is not set, returns null.
      Returns:
      UserGroupInformation.
      Throws:
      org.apache.hadoop.security.authentication.client.AuthenticationException
    • createUGIForApi

      public org.apache.hadoop.security.UserGroupInformation createUGIForApi() throws org.apache.hadoop.ozone.om.exceptions.OMException
      Crete a UGI from request and wrap the AuthenticationException to OMException in case of empty credentials.
      Returns:
      UserGroupInformation
      Throws:
      org.apache.hadoop.ozone.om.exceptions.OMException - exception about an empty user credential (unauthorized request)
    • setUGI

      public void setUGI(org.apache.hadoop.security.UserGroupInformation ugi)
    • getRemoteAddress

      public InetAddress getRemoteAddress() throws IOException
      Return InetAddress created from OMRequest userInfo. If userInfo is not set, returns null.
      Returns:
      InetAddress
      Throws:
      IOException
    • getHostName

      public String getHostName()
      Return String created from OMRequest userInfo. If userInfo is not set, returns null.
      Returns:
      String
    • createErrorOMResponse

      protected org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse createErrorOMResponse(@Nonnull org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse.Builder omResponse, @Nonnull Exception ex)
      Set parameters needed for return error response to client.
      Parameters:
      omResponse -
      ex - - IOException
      Returns:
      error response need to be returned to client - OMResponse.
    • markForAudit

      protected void markForAudit(org.apache.hadoop.ozone.audit.AuditLogger auditLogger, OMAuditLogger.Builder builder)
      Mark ready for log audit.
      Parameters:
      auditLogger -
      builder -
    • buildAuditMessage

      public OMAuditLogger.Builder buildAuditMessage(org.apache.hadoop.ozone.audit.AuditAction op, Map<String,String> auditMap, Throwable throwable, org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.UserInfo userInfo)
      Description copied from interface: RequestAuditor
      Build AuditMessage.
      Specified by:
      buildAuditMessage in interface RequestAuditor
      Parameters:
      op -
      auditMap -
      throwable -
      userInfo -
    • buildVolumeAuditMap

      public Map<String,String> buildVolumeAuditMap(String volume)
      Description copied from interface: RequestAuditor
      Build auditMap with specified volume.
      Specified by:
      buildVolumeAuditMap in interface RequestAuditor
      Parameters:
      volume -
      Returns:
      auditMap.
    • validateAndNormalizeKey

      public static String validateAndNormalizeKey(boolean enableFileSystemPaths, String keyName) throws org.apache.hadoop.ozone.om.exceptions.OMException
      Throws:
      org.apache.hadoop.ozone.om.exceptions.OMException
    • normalizeKeyPath

      public static String normalizeKeyPath(boolean enableFileSystemPaths, String keyPath, org.apache.hadoop.ozone.om.helpers.BucketLayout bucketLayout) throws org.apache.hadoop.ozone.om.exceptions.OMException
      Normalizes the key path based on the bucket layout. This should be used for existing keys. For new key creation, please see validateAndNormalizeKey(boolean, String, BucketLayout)
      Returns:
      normalized key path
      Throws:
      org.apache.hadoop.ozone.om.exceptions.OMException
    • validateAndNormalizeKey

      public static String validateAndNormalizeKey(boolean enableFileSystemPaths, String keyPath, org.apache.hadoop.ozone.om.helpers.BucketLayout bucketLayout) throws org.apache.hadoop.ozone.om.exceptions.OMException
      Throws:
      org.apache.hadoop.ozone.om.exceptions.OMException
    • validateAndNormalizeKey

      public static String validateAndNormalizeKey(String keyName) throws org.apache.hadoop.ozone.om.exceptions.OMException
      Throws:
      org.apache.hadoop.ozone.om.exceptions.OMException
    • isValidKeyPath

      public static String isValidKeyPath(String path) throws org.apache.hadoop.ozone.om.exceptions.OMException
      Whether the pathname is valid. Check key names which contain a ":", ".", "..", "//", "". If it has any of these characters throws OMException, else return the path.
      Throws:
      org.apache.hadoop.ozone.om.exceptions.OMException
    • getOmLockDetails

      public org.apache.hadoop.ozone.om.lock.OMLockDetails getOmLockDetails()
    • mergeOmLockDetails

      public void mergeOmLockDetails(org.apache.hadoop.ozone.om.lock.OMLockDetails details)