org.apache.hadoop.util.HttpExceptionUtils Java Examples
The following examples show how to use
org.apache.hadoop.util.HttpExceptionUtils.
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: HttpFSFileSystem.java From hadoop with Apache License 2.0 | 6 votes |
/** * 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); }
Example #2
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 6 votes |
/** * 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); }
Example #3
Source File: HttpFSFileSystem.java From hadoop with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #4
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #5
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 6 votes |
@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(); }
Example #6
Source File: HttpFSFileSystem.java From hadoop with Apache License 2.0 | 6 votes |
@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(); }
Example #7
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #8
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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)); }
Example #9
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@Override public void close() throws IOException { try { super.close(); } finally { HttpExceptionUtils.validateResponse(conn, closeStatus); } }
Example #10
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #11
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #12
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #13
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #14
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #15
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #16
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #17
Source File: HttpFSFileSystem.java From hadoop with Apache License 2.0 | 5 votes |
@Override public void close() throws IOException { try { super.close(); } finally { HttpExceptionUtils.validateResponse(conn, closeStatus); } }
Example #18
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #19
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
/** * 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); }
Example #20
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@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(); } }; }
Example #21
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@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); }
Example #22
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@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; }
Example #23
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@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)); }
Example #24
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@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)); }
Example #25
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@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)); }
Example #26
Source File: HttpFSFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@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); }
Example #27
Source File: HttpFSFileSystem.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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); }
Example #28
Source File: HttpFSFileSystem.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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)); }
Example #29
Source File: HttpFSFileSystem.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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); }
Example #30
Source File: HttpFSFileSystem.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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); }