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

The following examples show how to use org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo#getPath() . 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: DistributedFileSystem.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Modify a CacheDirective.
 * 
 * @param info Information about the directive to modify. You must set the ID
 *          to indicate which CacheDirective you want to modify.
 * @param flags {@link CacheFlag}s to use for this operation.
 * @throws IOException if the directive could not be modified
 */
public void modifyCacheDirective(
    CacheDirectiveInfo info, EnumSet<CacheFlag> flags) throws IOException {
  if (info.getPath() != null) {
    info = new CacheDirectiveInfo.Builder(info).
        setPath(new Path(getPathName(fixRelativePart(info.getPath()))).
            makeQualified(getUri(), getWorkingDirectory())).build();
  }
  dfs.modifyCacheDirective(info, flags);
}
 
Example 10
Source File: DistributedFileSystem.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * List cache directives.  Incrementally fetches results from the server.
 * 
 * @param filter Filter parameters to use when listing the directives, null to
 *               list all directives visible to us.
 * @return A RemoteIterator which returns CacheDirectiveInfo objects.
 */
public RemoteIterator<CacheDirectiveEntry> listCacheDirectives(
    CacheDirectiveInfo filter) throws IOException {
  if (filter == null) {
    filter = new CacheDirectiveInfo.Builder().build();
  }
  if (filter.getPath() != null) {
    filter = new CacheDirectiveInfo.Builder(filter).
        setPath(new Path(getPathName(fixRelativePart(filter.getPath())))).
        build();
  }
  final RemoteIterator<CacheDirectiveEntry> iter =
      dfs.listCacheDirectives(filter);
  return new RemoteIterator<CacheDirectiveEntry>() {
    @Override
    public boolean hasNext() throws IOException {
      return iter.hasNext();
    }

    @Override
    public CacheDirectiveEntry next() throws IOException {
      // Although the paths we get back from the NameNode should always be
      // absolute, we call makeQualified to add the scheme and authority of
      // this DistributedFilesystem.
      CacheDirectiveEntry desc = iter.next();
      CacheDirectiveInfo info = desc.getInfo();
      Path p = info.getPath().makeQualified(getUri(), getWorkingDirectory());
      return new CacheDirectiveEntry(
          new CacheDirectiveInfo.Builder(info).setPath(p).build(),
          desc.getStats());
    }
  };
}
 
Example 11
Source File: CacheManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static String validatePath(CacheDirectiveInfo directive)
    throws InvalidRequestException {
  if (directive.getPath() == null) {
    throw new InvalidRequestException("No path specified.");
  }
  String path = directive.getPath().toUri().getPath();
  if (!DFSUtil.isValidName(path)) {
    throw new InvalidRequestException("Invalid path '" + path + "'.");
  }
  return path;
}
 
Example 12
Source File: CacheRegistry.java    From nnproxy with Apache License 2.0 5 votes vote down vote up
private static String validatePath(CacheDirectiveInfo directive)
        throws InvalidRequestException {
    if (directive.getPath() == null) {
        throw new InvalidRequestException("No path specified.");
    }
    String path = directive.getPath().toUri().getPath();
    if (!DFSUtil.isValidName(path)) {
        throw new InvalidRequestException("Invalid path '" + path + "'.");
    }
    return path;
}
 
Example 13
Source File: DistributedFileSystem.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Modify a CacheDirective.
 * 
 * @param info Information about the directive to modify. You must set the ID
 *          to indicate which CacheDirective you want to modify.
 * @param flags {@link CacheFlag}s to use for this operation.
 * @throws IOException if the directive could not be modified
 */
public void modifyCacheDirective(
    CacheDirectiveInfo info, EnumSet<CacheFlag> flags) throws IOException {
  if (info.getPath() != null) {
    info = new CacheDirectiveInfo.Builder(info).
        setPath(new Path(getPathName(fixRelativePart(info.getPath()))).
            makeQualified(getUri(), getWorkingDirectory())).build();
  }
  dfs.modifyCacheDirective(info, flags);
}
 
Example 14
Source File: DistributedFileSystem.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * List cache directives.  Incrementally fetches results from the server.
 * 
 * @param filter Filter parameters to use when listing the directives, null to
 *               list all directives visible to us.
 * @return A RemoteIterator which returns CacheDirectiveInfo objects.
 */
public RemoteIterator<CacheDirectiveEntry> listCacheDirectives(
    CacheDirectiveInfo filter) throws IOException {
  if (filter == null) {
    filter = new CacheDirectiveInfo.Builder().build();
  }
  if (filter.getPath() != null) {
    filter = new CacheDirectiveInfo.Builder(filter).
        setPath(new Path(getPathName(fixRelativePart(filter.getPath())))).
        build();
  }
  final RemoteIterator<CacheDirectiveEntry> iter =
      dfs.listCacheDirectives(filter);
  return new RemoteIterator<CacheDirectiveEntry>() {
    @Override
    public boolean hasNext() throws IOException {
      return iter.hasNext();
    }

    @Override
    public CacheDirectiveEntry next() throws IOException {
      // Although the paths we get back from the NameNode should always be
      // absolute, we call makeQualified to add the scheme and authority of
      // this DistributedFilesystem.
      CacheDirectiveEntry desc = iter.next();
      CacheDirectiveInfo info = desc.getInfo();
      Path p = info.getPath().makeQualified(getUri(), getWorkingDirectory());
      return new CacheDirectiveEntry(
          new CacheDirectiveInfo.Builder(info).setPath(p).build(),
          desc.getStats());
    }
  };
}
 
Example 15
Source File: CacheManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static String validatePath(CacheDirectiveInfo directive)
    throws InvalidRequestException {
  if (directive.getPath() == null) {
    throw new InvalidRequestException("No path specified.");
  }
  String path = directive.getPath().toUri().getPath();
  if (!DFSUtil.isValidName(path)) {
    throw new InvalidRequestException("Invalid path '" + path + "'.");
  }
  return path;
}
 
Example 16
Source File: CacheRegistry.java    From nnproxy with Apache License 2.0 4 votes vote down vote up
public BatchedRemoteIterator.BatchedListEntries<CacheDirectiveEntry> listCacheDirectives(long prevId,
                                                                                         CacheDirectiveInfo filter) throws InvalidRequestException {
    final int NUM_PRE_ALLOCATED_ENTRIES = 16;
    String filterPath = null;
    if (filter.getPath() != null) {
        filterPath = validatePath(filter);
    }
    if (filter.getReplication() != null) {
        throw new InvalidRequestException(
                "Filtering by replication is unsupported.");
    }

    // Querying for a single ID
    final Long id = filter.getId();
    if (id != null) {
        if (!directivesById.containsKey(id)) {
            throw new InvalidRequestException("Did not find requested id " + id);
        }
        // Since we use a tailMap on directivesById, setting prev to id-1 gets
        // us the directive with the id (if present)
        prevId = id - 1;
    }

    ArrayList<CacheDirectiveEntry> replies =
            new ArrayList<CacheDirectiveEntry>(NUM_PRE_ALLOCATED_ENTRIES);
    int numReplies = 0;
    SortedMap<Long, CacheDirectiveEntry> tailMap =
            directivesById.tailMap(prevId + 1);
    for (Map.Entry<Long, CacheDirectiveEntry> cur : tailMap.entrySet()) {
        if (numReplies >= maxListCacheDirectivesNumResponses) {
            return new BatchedRemoteIterator.BatchedListEntries<>(replies, true);
        }
        CacheDirectiveInfo info = cur.getValue().getInfo();

        // If the requested ID is present, it should be the first item.
        // Hitting this case means the ID is not present, or we're on the second
        // item and should break out.
        if (id != null &&
                !(info.getId().equals(id))) {
            break;
        }
        if (filter.getPool() != null &&
                !info.getPool().equals(filter.getPool())) {
            continue;
        }
        if (filterPath != null &&
                !info.getPath().toUri().getPath().equals(filterPath)) {
            continue;
        }
        replies.add(cur.getValue());
        numReplies++;
    }
    return new BatchedRemoteIterator.BatchedListEntries<>(replies, false);
}