Java Code Examples for org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo#getExpiration()

The following examples show how to use org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo#getExpiration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FSImageSerialization.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static void writeCacheDirectiveInfo(DataOutputStream out,
    CacheDirectiveInfo directive) throws IOException {
  writeLong(directive.getId(), out);
  int flags =
      ((directive.getPath() != null) ? 0x1 : 0) |
      ((directive.getReplication() != null) ? 0x2 : 0) |
      ((directive.getPool() != null) ? 0x4 : 0) |
      ((directive.getExpiration() != null) ? 0x8 : 0);
  out.writeInt(flags);
  if (directive.getPath() != null) {
    writeString(directive.getPath().toUri().getPath(), out);
  }
  if (directive.getReplication() != null) {
    writeShort(directive.getReplication(), out);
  }
  if (directive.getPool() != null) {
    writeString(directive.getPool(), out);
  }
  if (directive.getExpiration() != null) {
    writeLong(directive.getExpiration().getMillis(), out);
  }
}
 
Example 2
Source File: FSImageSerialization.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static void writeCacheDirectiveInfo(ContentHandler contentHandler,
    CacheDirectiveInfo directive) throws SAXException {
  XMLUtils.addSaxString(contentHandler, "ID",
      Long.toString(directive.getId()));
  if (directive.getPath() != null) {
    XMLUtils.addSaxString(contentHandler, "PATH",
        directive.getPath().toUri().getPath());
  }
  if (directive.getReplication() != null) {
    XMLUtils.addSaxString(contentHandler, "REPLICATION",
        Short.toString(directive.getReplication()));
  }
  if (directive.getPool() != null) {
    XMLUtils.addSaxString(contentHandler, "POOL", directive.getPool());
  }
  if (directive.getExpiration() != null) {
    XMLUtils.addSaxString(contentHandler, "EXPIRATION",
        "" + directive.getExpiration().getMillis());
  }
}
 
Example 3
Source File: CacheManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Factory method that makes a new CacheDirectiveInfo by applying fields in a
 * CacheDirectiveInfo to an existing CacheDirective.
 * 
 * @param info with some or all fields set.
 * @param defaults directive providing default values for unset fields in
 *          info.
 * 
 * @return new CacheDirectiveInfo of the info applied to the defaults.
 */
private static CacheDirectiveInfo createFromInfoAndDefaults(
    CacheDirectiveInfo info, CacheDirective defaults) {
  // Initialize the builder with the default values
  CacheDirectiveInfo.Builder builder =
      new CacheDirectiveInfo.Builder(defaults.toInfo());
  // Replace default with new value if present
  if (info.getPath() != null) {
    builder.setPath(info.getPath());
  }
  if (info.getReplication() != null) {
    builder.setReplication(info.getReplication());
  }
  if (info.getPool() != null) {
    builder.setPool(info.getPool());
  }
  if (info.getExpiration() != null) {
    builder.setExpiration(info.getExpiration());
  }
  return builder.build();
}
 
Example 4
Source File: PBHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static CacheDirectiveInfoProto convert
    (CacheDirectiveInfo info) {
  CacheDirectiveInfoProto.Builder builder = 
      CacheDirectiveInfoProto.newBuilder();
  if (info.getId() != null) {
    builder.setId(info.getId());
  }
  if (info.getPath() != null) {
    builder.setPath(info.getPath().toUri().getPath());
  }
  if (info.getReplication() != null) {
    builder.setReplication(info.getReplication());
  }
  if (info.getPool() != null) {
    builder.setPool(info.getPool());
  }
  if (info.getExpiration() != null) {
    builder.setExpiration(convert(info.getExpiration()));
  }
  return builder.build();
}
 
Example 5
Source File: FSImageSerialization.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static void writeCacheDirectiveInfo(DataOutputStream out,
    CacheDirectiveInfo directive) throws IOException {
  writeLong(directive.getId(), out);
  int flags =
      ((directive.getPath() != null) ? 0x1 : 0) |
      ((directive.getReplication() != null) ? 0x2 : 0) |
      ((directive.getPool() != null) ? 0x4 : 0) |
      ((directive.getExpiration() != null) ? 0x8 : 0);
  out.writeInt(flags);
  if (directive.getPath() != null) {
    writeString(directive.getPath().toUri().getPath(), out);
  }
  if (directive.getReplication() != null) {
    writeShort(directive.getReplication(), out);
  }
  if (directive.getPool() != null) {
    writeString(directive.getPool(), out);
  }
  if (directive.getExpiration() != null) {
    writeLong(directive.getExpiration().getMillis(), out);
  }
}
 
Example 6
Source File: FSImageSerialization.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static void writeCacheDirectiveInfo(ContentHandler contentHandler,
    CacheDirectiveInfo directive) throws SAXException {
  XMLUtils.addSaxString(contentHandler, "ID",
      Long.toString(directive.getId()));
  if (directive.getPath() != null) {
    XMLUtils.addSaxString(contentHandler, "PATH",
        directive.getPath().toUri().getPath());
  }
  if (directive.getReplication() != null) {
    XMLUtils.addSaxString(contentHandler, "REPLICATION",
        Short.toString(directive.getReplication()));
  }
  if (directive.getPool() != null) {
    XMLUtils.addSaxString(contentHandler, "POOL", directive.getPool());
  }
  if (directive.getExpiration() != null) {
    XMLUtils.addSaxString(contentHandler, "EXPIRATION",
        "" + directive.getExpiration().getMillis());
  }
}
 
Example 7
Source File: CacheManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Factory method that makes a new CacheDirectiveInfo by applying fields in a
 * CacheDirectiveInfo to an existing CacheDirective.
 * 
 * @param info with some or all fields set.
 * @param defaults directive providing default values for unset fields in
 *          info.
 * 
 * @return new CacheDirectiveInfo of the info applied to the defaults.
 */
private static CacheDirectiveInfo createFromInfoAndDefaults(
    CacheDirectiveInfo info, CacheDirective defaults) {
  // Initialize the builder with the default values
  CacheDirectiveInfo.Builder builder =
      new CacheDirectiveInfo.Builder(defaults.toInfo());
  // Replace default with new value if present
  if (info.getPath() != null) {
    builder.setPath(info.getPath());
  }
  if (info.getReplication() != null) {
    builder.setReplication(info.getReplication());
  }
  if (info.getPool() != null) {
    builder.setPool(info.getPool());
  }
  if (info.getExpiration() != null) {
    builder.setExpiration(info.getExpiration());
  }
  return builder.build();
}
 
Example 8
Source File: PBHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static CacheDirectiveInfoProto convert
    (CacheDirectiveInfo info) {
  CacheDirectiveInfoProto.Builder builder = 
      CacheDirectiveInfoProto.newBuilder();
  if (info.getId() != null) {
    builder.setId(info.getId());
  }
  if (info.getPath() != null) {
    builder.setPath(info.getPath().toUri().getPath());
  }
  if (info.getReplication() != null) {
    builder.setReplication(info.getReplication());
  }
  if (info.getPool() != null) {
    builder.setPool(info.getPool());
  }
  if (info.getExpiration() != null) {
    builder.setExpiration(convert(info.getExpiration()));
  }
  return builder.build();
}
 
Example 9
Source File: CacheManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the absolute expiry time of the directive from the
 * {@link CacheDirectiveInfo.Expiration}. This converts a relative Expiration
 * into an absolute time based on the local clock.
 * 
 * @param info to validate.
 * @param maxRelativeExpiryTime of the info's pool.
 * @return the expiration time, or the pool's max absolute expiration if the
 *         info's expiration was not set.
 * @throws InvalidRequestException if the info's Expiration is invalid.
 */
private static long validateExpiryTime(CacheDirectiveInfo info,
    long maxRelativeExpiryTime) throws InvalidRequestException {
  LOG.trace("Validating directive {} pool maxRelativeExpiryTime {}", info,
      maxRelativeExpiryTime);
  final long now = new Date().getTime();
  final long maxAbsoluteExpiryTime = now + maxRelativeExpiryTime;
  if (info == null || info.getExpiration() == null) {
    return maxAbsoluteExpiryTime;
  }
  Expiration expiry = info.getExpiration();
  if (expiry.getMillis() < 0l) {
    throw new InvalidRequestException("Cannot set a negative expiration: "
        + expiry.getMillis());
  }
  long relExpiryTime, absExpiryTime;
  if (expiry.isRelative()) {
    relExpiryTime = expiry.getMillis();
    absExpiryTime = now + relExpiryTime;
  } else {
    absExpiryTime = expiry.getMillis();
    relExpiryTime = absExpiryTime - now;
  }
  // Need to cap the expiry so we don't overflow a long when doing math
  if (relExpiryTime > Expiration.MAX_RELATIVE_EXPIRY_MS) {
    throw new InvalidRequestException("Expiration "
        + expiry.toString() + " is too far in the future!");
  }
  // Fail if the requested expiry is greater than the max
  if (relExpiryTime > maxRelativeExpiryTime) {
    throw new InvalidRequestException("Expiration " + expiry.toString()
        + " exceeds the max relative expiration time of "
        + maxRelativeExpiryTime + " ms.");
  }
  return absExpiryTime;
}
 
Example 10
Source File: CacheManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the absolute expiry time of the directive from the
 * {@link CacheDirectiveInfo.Expiration}. This converts a relative Expiration
 * into an absolute time based on the local clock.
 * 
 * @param info to validate.
 * @param maxRelativeExpiryTime of the info's pool.
 * @return the expiration time, or the pool's max absolute expiration if the
 *         info's expiration was not set.
 * @throws InvalidRequestException if the info's Expiration is invalid.
 */
private static long validateExpiryTime(CacheDirectiveInfo info,
    long maxRelativeExpiryTime) throws InvalidRequestException {
  LOG.trace("Validating directive {} pool maxRelativeExpiryTime {}", info,
      maxRelativeExpiryTime);
  final long now = new Date().getTime();
  final long maxAbsoluteExpiryTime = now + maxRelativeExpiryTime;
  if (info == null || info.getExpiration() == null) {
    return maxAbsoluteExpiryTime;
  }
  Expiration expiry = info.getExpiration();
  if (expiry.getMillis() < 0l) {
    throw new InvalidRequestException("Cannot set a negative expiration: "
        + expiry.getMillis());
  }
  long relExpiryTime, absExpiryTime;
  if (expiry.isRelative()) {
    relExpiryTime = expiry.getMillis();
    absExpiryTime = now + relExpiryTime;
  } else {
    absExpiryTime = expiry.getMillis();
    relExpiryTime = absExpiryTime - now;
  }
  // Need to cap the expiry so we don't overflow a long when doing math
  if (relExpiryTime > Expiration.MAX_RELATIVE_EXPIRY_MS) {
    throw new InvalidRequestException("Expiration "
        + expiry.toString() + " is too far in the future!");
  }
  // Fail if the requested expiry is greater than the max
  if (relExpiryTime > maxRelativeExpiryTime) {
    throw new InvalidRequestException("Expiration " + expiry.toString()
        + " exceeds the max relative expiration time of "
        + maxRelativeExpiryTime + " ms.");
  }
  return absExpiryTime;
}