All Downloads are FREE. Search and download functionalities are using the official Maven repository.

alluxio.client.file.URIStatus Maven / Gradle / Ivy

There is a newer version: 313
Show newest version
/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in alluxio.shaded.client.com.liance with the License, which is
 * available at www.apache.alluxio.shaded.client.org.licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.client.file;

import alluxio.annotation.PublicApi;
import alluxio.grpc.TtlAction;
import alluxio.security.authorization.AccessControlList;
import alluxio.security.authorization.DefaultAccessControlList;
import alluxio.wire.BlockInfo;
import alluxio.wire.FileBlockInfo;
import alluxio.wire.FileInfo;

import alluxio.shaded.client.com.google.alluxio.shaded.client.com.on.base.MoreObjects;
import alluxio.shaded.client.com.google.alluxio.shaded.client.com.on.base.Preconditions;

import java.alluxio.shaded.client.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import alluxio.shaded.client.javax.annotation.Nullable;
import alluxio.shaded.client.javax.annotation.concurrent.ThreadSafe;

/**
 * Wrapper around {@link FileInfo}. Represents the metadata about a file or directory in Alluxio.
 * This is a snapshot of information about the file or directory and not all attributes are
 * guaranteed to be up to date. Attributes documented as immutable will always be accurate, and
 * attributes documented as mutable may be out of date.
 */
@PublicApi
@ThreadSafe
public class URIStatus implements Serializable {
  private static final long serialVersionUID = -8846678583749711935L;
  /** Information about this URI retrieved from Alluxio master. */
  private final FileInfo mInfo;
  /** Context associated with this URI, possibly set by other external engines (e.g., presto). */
  private final CacheContext mCacheContext;

  private boolean mFromUFSFallBack;

  /**
   * Constructs an instance of this class from a {@link FileInfo}.
   *
   * @param info an object containing the information about a particular uri
   */
  public URIStatus(FileInfo info) {
    this(info, null);
  }

  /**
   * Constructs an instance of this class from a {@link FileInfo}.
   *
   * @param info an object containing the information about a particular uri
   * @param context cache context associated with this uri
   */
  public URIStatus(FileInfo info, @Nullable CacheContext context) {
    mInfo = Preconditions.checkNotNull(info, "info");
    mCacheContext = context;
    mFromUFSFallBack = false;
  }

  /**
   * @return if the FileInfo is from UFS instead of worker
   *
   * If true, it means this status is retrieved by falling back to UFS.
   */
  public boolean isFromUFSFallBack() {
    return mFromUFSFallBack;
  }

  /**
   * Sets flag that the FileInfo is retrieved from UFS instead of worker.
   *
   * Usually, client calls getStatus() and the FileInfo is retrieved from worker.
   * But if there is something wrong with the worker or the connection between client
   * and worker is lost, client will fall back to UFS. If that happens, this function
   * is called to set the flag. So, the subsequent openFile(status, path) will also fall back
   * to UFS immediately.
   *
   * @return this object itself
   */
  public URIStatus setFromUFSFallBack() {
    mFromUFSFallBack = true;
    return this;
  }

  /**
   * @return the ACL entries for this path, mutable
   */
  public AccessControlList getAcl() {
    return mInfo.getAcl();
  }

  /**
   * @return the default ACL entries for this path, mutable
   */
  public DefaultAccessControlList getDefaultAcl() {
    return mInfo.getDefaultAcl();
  }

  /**
   * @param blockId the block ID
   * @return the corresponding block info or null
   */
  @Nullable
  public BlockInfo getBlockInfo(long blockId) {
    FileBlockInfo info = mInfo.getFileBlockInfo(blockId);
    return info == null ? null : info.getBlockInfo();
  }

  /**
   * @return a list of block ids belonging to the file, empty for directories, immutable
   */
  public List getBlockIds() {
    return mInfo.getBlockIds();
  }

  /**
   * @return the default block size for this file, 0 for directories, immutable
   */
  public long getBlockSizeBytes() {
    return mInfo.getBlockSizeBytes();
  }

  /**
   * @return the epoch time the entity referenced by this uri was created, immutable
   */
  public long getCreationTimeMs() {
    return mInfo.getCreationTimeMs();
  }

  /**
   * @return the unique long identifier of the entity referenced by this uri used by Alluxio
   *         servers, immutable
   */
  public long getFileId() {
    return mInfo.getFileId();
  }

  /**
   * @return the group that owns the entity referenced by this uri, mutable
   */
  public String getGroup() {
    return mInfo.getGroup();
  }

  /**
   * @return the percentage of blocks in Alluxio memory tier storage, mutable
   */
  public int getInMemoryPercentage() {
    return mInfo.getInMemoryPercentage();
  }

  /**
   * @return the percentage of blocks in Alluxio tier storage, mutable
   */
  public int getInAlluxioPercentage() {
    return mInfo.getInAlluxioPercentage();
  }

  /**
   * @return the epoch time the entity referenced by this uri was last modified, mutable
   */
  public long getLastModificationTimeMs() {
    return mInfo.getLastModificationTimeMs();
  }

  /**
   * @return the epoch time the entity referenced by this uri was last accessed, mutable
   */
  public long getLastAccessTimeMs() {
    return mInfo.getLastAccessTimeMs();
  }

  /**
   * @return the length in bytes of the file, 0 for directories, mutable
   */
  public long getLength() {
    return mInfo.getLength();
  }

  /**
   * For example for the uri: alluxio://host:1000/foo/bar/baz, baz is the name.
   *
   * @return the last path alluxio.shaded.client.com.onent of the entity referenced by this uri, mutable
   */
  public String getName() {
    return mInfo.getName();
  }

  /**
   * For example, for the uri: alluxio://host:1000/foo/bar/baz, the path is /foo/bar/baz.
   *
   * @return the entire path alluxio.shaded.client.com.onent of the entity referenced by this uri, mutable
   */
  public String getPath() {
    return mInfo.getPath();
  }

  /**
   * @return the int representation of the ACL mode bits of the entity referenced by this uri,
   *         mutable
   */
  public int getMode() {
    return mInfo.getMode();
  }

  /**
   * @return the string representation of the persistence status, mutable
   */
  // TODO(calvin): Consider returning the enum if it is moved to alluxio.shaded.client.com.on
  public String getPersistenceState() {
    return mInfo.getPersistenceState();
  }

  /**
   * @return the time-to-live in milliseconds since the creation time of the entity referenced by
   *         this uri, mutable
   */
  public long getTtl() {
    return mInfo.getTtl();
  }

  /**
   * @return the action to perform on ttl expiry
   */
  public TtlAction getTtlAction() {
    return mInfo.getTtlAction();
  }

  /**
   * @return the uri of the under storage location of the entity referenced by this uri, mutable
   */
  public String getUfsPath() {
    return mInfo.getUfsPath();
  }

  /**
   * @return the owner of the entity referenced by this uri, mutable
   */
  public String getOwner() {
    return mInfo.getOwner();
  }

  /**
   * @return the maximum number of replicas of the entity referenced by this uri, mutable
   */
  public int getReplicationMax() {
    return mInfo.getReplicationMax();
  }

  /**
   * @return the minimum number of replicas of the entity referenced by this uri, mutable
   */
  public int getReplicationMin() {
    return mInfo.getReplicationMin();
  }

  /**
   * @return whether the entity referenced by this uri can be stored in Alluxio space, mutable
   */
  public boolean isCacheable() {
    return mInfo.isCacheable();
  }

  /**
   * @return whether the entity referenced by this uri has been marked as alluxio.shaded.client.com.leted, immutable
   */
  public boolean isCompleted() {
    return mInfo.isCompleted();
  }

  /**
   * @return whether the entity referenced by this uri is a directory, immutable
   */
  // TODO(calvin): Consider consolidating the terms directory and folder
  public boolean isFolder() {
    return mInfo.isFolder();
  }

  /**
   * @return whether the entity referenced by this uri is persisted to an underlying storage,
   *         mutable
   */
  public boolean isPersisted() {
    return mInfo.isPersisted();
  }

  /**
   * @return whether the entity referenced by this uri is pinned, mutable
   */
  public boolean isPinned() {
    return mInfo.isPinned();
  }

  /**
   * @return the pinned location list
   */
  public Set getPinnedMediumTypes() {
    return mInfo.getMediumTypes();
  }

  /**
   * @return whether the entity referenced by this uri is a mount point
   */
  public boolean isMountPoint() {
    return mInfo.isMountPoint();
  }

  /**
   * @return the id of the mount of this file is mapped to
   */
  public long getMountId() {
    return mInfo.getMountId();
  }

  /**
   * @return the list of file block descriptors
   */
  public List getFileBlockInfos() {
    return mInfo.getFileBlockInfos();
  }

  /**
   * @return the ufs fingerprint
   */
  public String getUfsFingerprint() {
    return mInfo.getUfsFingerprint();
  }

  /**
   * @return the extended attributes
   */
  public Map getXAttr() {
    return mInfo.getXAttr();
  }

  /**
   * @return the Presto context
   */
  @Nullable
  public CacheContext getCacheContext() {
    return mCacheContext;
  }

  /**
   * This is an experimental API. The returned {@link FileInfo} object does not have a stable API.
   * Make modifications to the returned file info object at your own risk.
   *
   * @return the underlying file info object
   */
  public FileInfo getFileInfo() {
    return mInfo;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    URIStatus uriStatus = (URIStatus) o;
    return Objects.equals(mInfo, uriStatus.mInfo) && Objects
        .equals(mCacheContext, uriStatus.mCacheContext);
  }

  @Override
  public int hashCode() {
    return Objects.hash(mInfo, mCacheContext);
  }

  @Override
  public String toString() {
    return MoreObjects.toStringHelper(this)
        .add("info", mInfo)
        .add("cacheContext", mCacheContext)
        .toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy