类org.apache.hadoop.util.HttpExceptionUtils源码实例Demo

下面列出了怎么用org.apache.hadoop.util.HttpExceptionUtils的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Concat existing files together.
 * @param f the path to the target destination.
 * @param psrcs the paths to the sources to use for the concatenation.
 *
 * @throws IOException
 */
@Override
public void concat(Path f, Path[] psrcs) throws IOException {
  List<String> strPaths = new ArrayList<String>(psrcs.length);
  for(Path psrc : psrcs) {
    strPaths.add(psrc.toUri().getPath());
  }
  String srcs = StringUtils.join(",", strPaths);

  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.CONCAT.toString());
  params.put(SOURCES_PARAM, srcs);
  HttpURLConnection conn = getConnection(Operation.CONCAT.getMethod(),
      params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码2 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Return the current user's home directory in this filesystem.
 * The default implementation returns "/user/$USER/".
 */
@Override
public Path getHomeDirectory() {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.GETHOMEDIRECTORY.toString());
  try {
    HttpURLConnection conn =
      getConnection(Operation.GETHOMEDIRECTORY.getMethod(), params,
                    new Path(getUri().toString(), "/"), false);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    return new Path((String) json.get(HOME_DIR_JSON));
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
源代码3 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public ContentSummary getContentSummary(Path f) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.GETCONTENTSUMMARY.toString());
  HttpURLConnection conn =
    getConnection(Operation.GETCONTENTSUMMARY.getMethod(), params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) ((JSONObject)
    HttpFSUtils.jsonParse(conn)).get(CONTENT_SUMMARY_JSON);
  return new ContentSummary.Builder().
      length((Long) json.get(CONTENT_SUMMARY_LENGTH_JSON)).
      fileCount((Long) json.get(CONTENT_SUMMARY_FILE_COUNT_JSON)).
      directoryCount((Long) json.get(CONTENT_SUMMARY_DIRECTORY_COUNT_JSON)).
      quota((Long) json.get(CONTENT_SUMMARY_QUOTA_JSON)).
      spaceConsumed((Long) json.get(CONTENT_SUMMARY_SPACE_CONSUMED_JSON)).
      spaceQuota((Long) json.get(CONTENT_SUMMARY_SPACE_QUOTA_JSON)).build();
}
 
源代码4 项目: big-c   文件: HttpFSFileSystem.java
/**
 * Concat existing files together.
 * @param f the path to the target destination.
 * @param psrcs the paths to the sources to use for the concatenation.
 *
 * @throws IOException
 */
@Override
public void concat(Path f, Path[] psrcs) throws IOException {
  List<String> strPaths = new ArrayList<String>(psrcs.length);
  for(Path psrc : psrcs) {
    strPaths.add(psrc.toUri().getPath());
  }
  String srcs = StringUtils.join(",", strPaths);

  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.CONCAT.toString());
  params.put(SOURCES_PARAM, srcs);
  HttpURLConnection conn = getConnection(Operation.CONCAT.getMethod(),
      params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码5 项目: big-c   文件: HttpFSFileSystem.java
/**
 * Return the current user's home directory in this filesystem.
 * The default implementation returns "/user/$USER/".
 */
@Override
public Path getHomeDirectory() {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.GETHOMEDIRECTORY.toString());
  try {
    HttpURLConnection conn =
      getConnection(Operation.GETHOMEDIRECTORY.getMethod(), params,
                    new Path(getUri().toString(), "/"), false);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    return new Path((String) json.get(HOME_DIR_JSON));
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
源代码6 项目: big-c   文件: HttpFSFileSystem.java
@Override
public ContentSummary getContentSummary(Path f) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.GETCONTENTSUMMARY.toString());
  HttpURLConnection conn =
    getConnection(Operation.GETCONTENTSUMMARY.getMethod(), params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) ((JSONObject)
    HttpFSUtils.jsonParse(conn)).get(CONTENT_SUMMARY_JSON);
  return new ContentSummary.Builder().
      length((Long) json.get(CONTENT_SUMMARY_LENGTH_JSON)).
      fileCount((Long) json.get(CONTENT_SUMMARY_FILE_COUNT_JSON)).
      directoryCount((Long) json.get(CONTENT_SUMMARY_DIRECTORY_COUNT_JSON)).
      quota((Long) json.get(CONTENT_SUMMARY_QUOTA_JSON)).
      spaceConsumed((Long) json.get(CONTENT_SUMMARY_SPACE_CONSUMED_JSON)).
      spaceQuota((Long) json.get(CONTENT_SUMMARY_SPACE_QUOTA_JSON)).build();
}
 
源代码7 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Opens an FSDataInputStream at the indicated Path.
 * <p>
 * IMPORTANT: the returned <code>FSDataInputStream</code> does not support the
 * <code>PositionReadable</code> and <code>Seekable</code> methods.
 *
 * @param f the file name to open
 * @param bufferSize the size of the buffer to be used.
 */
@Override
public FSDataInputStream open(Path f, int bufferSize) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.OPEN.toString());
  HttpURLConnection conn = getConnection(Operation.OPEN.getMethod(), params,
                                         f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  return new FSDataInputStream(
    new HttpFSDataInputStream(conn.getInputStream(), bufferSize));
}
 
源代码8 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public void close() throws IOException {
  try {
    super.close();
  } finally {
    HttpExceptionUtils.validateResponse(conn, closeStatus);
  }
}
 
源代码9 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Renames Path src to Path dst.  Can take place on local fs
 * or remote DFS.
 */
@Override
public boolean rename(Path src, Path dst) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.RENAME.toString());
  params.put(DESTINATION_PARAM, dst.toString());
  HttpURLConnection conn = getConnection(Operation.RENAME.getMethod(),
                                         params, src, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  return (Boolean) json.get(RENAME_JSON);
}
 
源代码10 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Make the given file and all non-existent parents into
 * directories. Has the semantics of Unix 'mkdir -p'.
 * Existence of the directory hierarchy is not an error.
 */
@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.MKDIRS.toString());
  params.put(PERMISSION_PARAM, permissionToString(permission));
  HttpURLConnection conn = getConnection(Operation.MKDIRS.getMethod(),
                                         params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  return (Boolean) json.get(MKDIRS_JSON);
}
 
源代码11 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Set owner of a path (i.e. a file or a directory).
 * The parameters username and groupname cannot both be null.
 *
 * @param p The path
 * @param username If it is null, the original username remains unchanged.
 * @param groupname If it is null, the original groupname remains unchanged.
 */
@Override
public void setOwner(Path p, String username, String groupname)
  throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.SETOWNER.toString());
  params.put(OWNER_PARAM, username);
  params.put(GROUP_PARAM, groupname);
  HttpURLConnection conn = getConnection(Operation.SETOWNER.getMethod(),
                                         params, p, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码12 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Set permission of a path.
 *
 * @param p path.
 * @param permission permission.
 */
@Override
public void setPermission(Path p, FsPermission permission) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.SETPERMISSION.toString());
  params.put(PERMISSION_PARAM, permissionToString(permission));
  HttpURLConnection conn = getConnection(Operation.SETPERMISSION.getMethod(), params, p, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码13 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Set replication for an existing file.
 *
 * @param src file name
 * @param replication new replication
 *
 * @return true if successful;
 *         false if file does not exist or is a directory
 *
 * @throws IOException
 */
@Override
public boolean setReplication(Path src, short replication)
  throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.SETREPLICATION.toString());
  params.put(REPLICATION_PARAM, Short.toString(replication));
  HttpURLConnection conn =
    getConnection(Operation.SETREPLICATION.getMethod(), params, src, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  return (Boolean) json.get(SET_REPLICATION_JSON);
}
 
源代码14 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Modify the ACL entries for a file.
 *
 * @param path Path to modify
 * @param aclSpec describing modifications
 * @throws IOException
 */
@Override
public void modifyAclEntries(Path path, List<AclEntry> aclSpec)
        throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.MODIFYACLENTRIES.toString());
  params.put(ACLSPEC_PARAM, AclEntry.aclSpecToString(aclSpec));
  HttpURLConnection conn = getConnection(
          Operation.MODIFYACLENTRIES.getMethod(), params, path, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码15 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Remove the specified ACL entries from a file
 * @param path Path to modify
 * @param aclSpec describing entries to remove
 * @throws IOException
 */
@Override
public void removeAclEntries(Path path, List<AclEntry> aclSpec)
        throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.REMOVEACLENTRIES.toString());
  params.put(ACLSPEC_PARAM, AclEntry.aclSpecToString(aclSpec));
  HttpURLConnection conn = getConnection(
          Operation.REMOVEACLENTRIES.getMethod(), params, path, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码16 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Removes the default ACL for the given file
 * @param path Path from which to remove the default ACL.
 * @throws IOException
 */
@Override
public void removeDefaultAcl(Path path) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.REMOVEDEFAULTACL.toString());
  HttpURLConnection conn = getConnection(
          Operation.REMOVEDEFAULTACL.getMethod(), params, path, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码17 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Remove all ACLs from a file
 * @param path Path from which to remove all ACLs
 * @throws IOException
 */
@Override
public void removeAcl(Path path) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.REMOVEACL.toString());
  HttpURLConnection conn = getConnection(Operation.REMOVEACL.getMethod(),
          params, path, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码18 项目: hadoop   文件: HttpFSFileSystem.java
/**
 * Set the ACLs for the given file
 * @param path Path to modify
 * @param aclSpec describing modifications, must include
 *                entries for user, group, and others for compatibility
 *                with permission bits.
 * @throws IOException
 */
@Override
public void setAcl(Path path, List<AclEntry> aclSpec) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.SETACL.toString());
  params.put(ACLSPEC_PARAM, AclEntry.aclSpecToString(aclSpec));
  HttpURLConnection conn = getConnection(Operation.SETACL.getMethod(),
                                         params, path, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码19 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public FileChecksum getFileChecksum(Path f) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.GETFILECHECKSUM.toString());
  HttpURLConnection conn =
    getConnection(Operation.GETFILECHECKSUM.getMethod(), params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  final JSONObject json = (JSONObject) ((JSONObject)
    HttpFSUtils.jsonParse(conn)).get(FILE_CHECKSUM_JSON);
  return new FileChecksum() {
    @Override
    public String getAlgorithmName() {
      return (String) json.get(CHECKSUM_ALGORITHM_JSON);
    }

    @Override
    public int getLength() {
      return ((Long) json.get(CHECKSUM_LENGTH_JSON)).intValue();
    }

    @Override
    public byte[] getBytes() {
      return StringUtils.hexStringToByte((String) json.get(CHECKSUM_BYTES_JSON));
    }

    @Override
    public void write(DataOutput out) throws IOException {
      throw new UnsupportedOperationException();
    }

    @Override
    public void readFields(DataInput in) throws IOException {
      throw new UnsupportedOperationException();
    }
  };
}
 
源代码20 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public void setXAttr(Path f, String name, byte[] value,
    EnumSet<XAttrSetFlag> flag) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.SETXATTR.toString());
  params.put(XATTR_NAME_PARAM, name);
  if (value != null) {
    params.put(XATTR_VALUE_PARAM, 
        XAttrCodec.encodeValue(value, XAttrCodec.HEX));
  }
  params.put(XATTR_SET_FLAG_PARAM, EnumSetParam.toString(flag));
  HttpURLConnection conn = getConnection(Operation.SETXATTR.getMethod(),
      params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码21 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public byte[] getXAttr(Path f, String name) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.GETXATTRS.toString());
  params.put(XATTR_NAME_PARAM, name);
  HttpURLConnection conn = getConnection(Operation.GETXATTRS.getMethod(),
      params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  Map<String, byte[]> xAttrs = createXAttrMap(
      (JSONArray) json.get(XATTRS_JSON));
  return xAttrs != null ? xAttrs.get(name) : null;
}
 
源代码22 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public Map<String, byte[]> getXAttrs(Path f) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.GETXATTRS.toString());
  HttpURLConnection conn = getConnection(Operation.GETXATTRS.getMethod(),
      params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  return createXAttrMap((JSONArray) json.get(XATTRS_JSON));
}
 
源代码23 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public Map<String, byte[]> getXAttrs(Path f, List<String> names)
    throws IOException {
  Preconditions.checkArgument(names != null && !names.isEmpty(), 
      "XAttr names cannot be null or empty.");
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.GETXATTRS.toString());
  Map<String, List<String>> multiValuedParams = Maps.newHashMap();
  multiValuedParams.put(XATTR_NAME_PARAM, names);
  HttpURLConnection conn = getConnection(Operation.GETXATTRS.getMethod(),
      params, multiValuedParams, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  return createXAttrMap((JSONArray) json.get(XATTRS_JSON));
}
 
源代码24 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public List<String> listXAttrs(Path f) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.LISTXATTRS.toString());
  HttpURLConnection conn = getConnection(Operation.LISTXATTRS.getMethod(),
      params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  return createXAttrNames((String) json.get(XATTRNAMES_JSON));
}
 
源代码25 项目: hadoop   文件: HttpFSFileSystem.java
@Override
public void removeXAttr(Path f, String name) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.REMOVEXATTR.toString());
  params.put(XATTR_NAME_PARAM, name);
  HttpURLConnection conn = getConnection(Operation.REMOVEXATTR.getMethod(),
      params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
源代码26 项目: big-c   文件: HttpFSFileSystem.java
/**
 * Opens an FSDataInputStream at the indicated Path.
 * <p>
 * IMPORTANT: the returned <code>FSDataInputStream</code> does not support the
 * <code>PositionReadable</code> and <code>Seekable</code> methods.
 *
 * @param f the file name to open
 * @param bufferSize the size of the buffer to be used.
 */
@Override
public FSDataInputStream open(Path f, int bufferSize) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.OPEN.toString());
  HttpURLConnection conn = getConnection(Operation.OPEN.getMethod(), params,
                                         f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  return new FSDataInputStream(
    new HttpFSDataInputStream(conn.getInputStream(), bufferSize));
}
 
源代码27 项目: big-c   文件: HttpFSFileSystem.java
@Override
public void close() throws IOException {
  try {
    super.close();
  } finally {
    HttpExceptionUtils.validateResponse(conn, closeStatus);
  }
}
 
源代码28 项目: big-c   文件: HttpFSFileSystem.java
/**
 * Renames Path src to Path dst.  Can take place on local fs
 * or remote DFS.
 */
@Override
public boolean rename(Path src, Path dst) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.RENAME.toString());
  params.put(DESTINATION_PARAM, dst.toString());
  HttpURLConnection conn = getConnection(Operation.RENAME.getMethod(),
                                         params, src, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  return (Boolean) json.get(RENAME_JSON);
}
 
源代码29 项目: big-c   文件: HttpFSFileSystem.java
/**
 * Make the given file and all non-existent parents into
 * directories. Has the semantics of Unix 'mkdir -p'.
 * Existence of the directory hierarchy is not an error.
 */
@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.MKDIRS.toString());
  params.put(PERMISSION_PARAM, permissionToString(permission));
  HttpURLConnection conn = getConnection(Operation.MKDIRS.getMethod(),
                                         params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
  JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
  return (Boolean) json.get(MKDIRS_JSON);
}
 
源代码30 项目: big-c   文件: HttpFSFileSystem.java
/**
 * Set owner of a path (i.e. a file or a directory).
 * The parameters username and groupname cannot both be null.
 *
 * @param p The path
 * @param username If it is null, the original username remains unchanged.
 * @param groupname If it is null, the original groupname remains unchanged.
 */
@Override
public void setOwner(Path p, String username, String groupname)
  throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.SETOWNER.toString());
  params.put(OWNER_PARAM, username);
  params.put(GROUP_PARAM, groupname);
  HttpURLConnection conn = getConnection(Operation.SETOWNER.getMethod(),
                                         params, p, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
 类所在包
 类方法
 同包方法