Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion hadoop-ozone/dist/src/main/license/bin/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ Apache License 2.0
com.google.inject.extensions:guice-servlet
com.google.inject:guice
com.google.j2objc:j2objc-annotations
com.googlecode.json-simple:json-simple
com.jolbox:bonecp
com.lmax:disruptor
com.nimbusds:nimbus-jose-jwt
Expand Down
1 change: 0 additions & 1 deletion hadoop-ozone/dist/src/main/license/jar-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ share/ozone/lib/jooq-codegen.jar
share/ozone/lib/jooq-meta.jar
share/ozone/lib/jooq.jar
share/ozone/lib/jsch.jar
share/ozone/lib/json-simple.jar
share/ozone/lib/jsp-api.jar
share/ozone/lib/jspecify.jar
share/ozone/lib/jsr311-api.jar
Expand Down
16 changes: 7 additions & 9 deletions hadoop-ozone/httpfsgateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,15 @@
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -60,8 +61,6 @@
import org.apache.ozone.fs.http.HttpFSConstants;
import org.apache.ozone.fs.http.HttpFSConstants.FILETYPE;
import org.apache.ozone.lib.service.FileSystemAccess;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

/**
* FileSystem operation executors used by {@link HttpFSServer}.
Expand Down Expand Up @@ -107,7 +106,7 @@ private static Map<String, Object> toJson(FileStatus[] fileStatuses,
boolean isFile) {
Map<String, Object> json = new LinkedHashMap<>();
Map<String, Object> inner = new LinkedHashMap<>();
JSONArray statuses = new JSONArray();
List<Map<String, Object>> statuses = new ArrayList<>();
for (FileStatus f : fileStatuses) {
statuses.add(toJsonInner(f, isFile));
}
Expand Down Expand Up @@ -209,7 +208,7 @@ private static Map<String, Object> toJson(FileSystem.DirectoryEntries
private static Map<String, Object> aclStatusToJSON(AclStatus aclStatus) {
Map<String, Object> json = new LinkedHashMap<String, Object>();
Map<String, Object> inner = new LinkedHashMap<String, Object>();
JSONArray entriesArray = new JSONArray();
List<String> entriesArray = new ArrayList<>();
inner.put(HttpFSConstants.OWNER_JSON, aclStatus.getOwner());
inner.put(HttpFSConstants.GROUP_JSON, aclStatus.getGroup());
inner.put(HttpFSConstants.PERMISSION_JSON,
Expand Down Expand Up @@ -254,14 +253,13 @@ private static Map fileChecksumToJSON(FileChecksum checksum) {
* @return The JSON representation of the xAttrs.
* @throws IOException
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private static Map xAttrsToJSON(Map<String, byte[]> xAttrs,
private static Map<String, Object> xAttrsToJSON(Map<String, byte[]> xAttrs,
XAttrCodec encoding) throws IOException {
Map jsonMap = new LinkedHashMap();
JSONArray jsonArray = new JSONArray();
Map<String, Object> jsonMap = new LinkedHashMap<>();
List<Map<String, Object>> jsonArray = new ArrayList<>();
if (xAttrs != null) {
for (Entry<String, byte[]> e : xAttrs.entrySet()) {
Map json = new LinkedHashMap();
Map<String, Object> json = new LinkedHashMap<>();
json.put(HttpFSConstants.XATTR_NAME_JSON, e.getKey());
if (e.getValue() != null) {
json.put(HttpFSConstants.XATTR_VALUE_JSON,
Expand All @@ -286,7 +284,7 @@ private static Map xAttrsToJSON(Map<String, byte[]> xAttrs,
private static Map xAttrNamesToJSON(List<String> names) throws IOException {
Map jsonMap = new LinkedHashMap();
jsonMap.put(HttpFSConstants.XATTRNAMES_JSON,
JSONArray.toJSONString(names));
JsonUtil.toJsonString(names));
return jsonMap;
}

Expand Down Expand Up @@ -364,27 +362,26 @@ private static Map<String, Object> quotaUsageToMap(QuotaUsage quotaUsage) {
}

/**
* Converts an object into a Json Map with with one key-value entry.
* Converts an object into a Json Map with one key-value entry.
* <p/>
* It assumes the given value is either a JSON primitive type or a
* <code>JsonAware</code> instance.
* The value may be a JSON primitive, a Map or List, or any object that
* Jackson can serialize.
*
* @param name name for the key of the entry.
* @param value for the value of the entry.
*
* @return the JSON representation of the key-value pair.
*/
@SuppressWarnings("unchecked")
private static JSONObject toJSON(String name, Object value) {
JSONObject json = new JSONObject();
private static Map<String, Object> toJSON(String name, Object value) {
Comment thread
smengcl marked this conversation as resolved.
Comment thread
smengcl marked this conversation as resolved.
Map<String, Object> json = new LinkedHashMap<>();
json.put(name, value);
return json;
}

@SuppressWarnings({ "unchecked" })
private static JSONObject storagePolicyToJSON(BlockStoragePolicySpi policy) {
private static Map<String, Object> storagePolicyToJSON(
BlockStoragePolicySpi policy) {
BlockStoragePolicy p = (BlockStoragePolicy) policy;
JSONObject policyJson = new JSONObject();
Map<String, Object> policyJson = new LinkedHashMap<>();
policyJson.put("id", p.getId());
policyJson.put("name", p.getName());
policyJson.put("storageTypes", toJsonArray(p.getStorageTypes()));
Expand All @@ -395,24 +392,22 @@ private static JSONObject storagePolicyToJSON(BlockStoragePolicySpi policy) {
return policyJson;
}

@SuppressWarnings("unchecked")
private static JSONArray toJsonArray(StorageType[] storageTypes) {
JSONArray jsonArray = new JSONArray();
private static List<String> toJsonArray(StorageType[] storageTypes) {
List<String> jsonArray = new ArrayList<>();
for (StorageType type : storageTypes) {
jsonArray.add(type.toString());
}
return jsonArray;
}

@SuppressWarnings("unchecked")
private static JSONObject storagePoliciesToJSON(
private static Map<String, Object> storagePoliciesToJSON(
Collection<? extends BlockStoragePolicySpi> storagePolicies) {
JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray();
JSONObject policies = new JSONObject();
Map<String, Object> json = new LinkedHashMap<>();
List<Map<String, Object>> jsonArray = new ArrayList<>();
Map<String, Object> policies = new LinkedHashMap<>();
if (storagePolicies != null) {
for (BlockStoragePolicySpi policy : storagePolicies) {
JSONObject policyMap = storagePolicyToJSON(policy);
Map<String, Object> policyMap = storagePolicyToJSON(policy);
jsonArray.add(policyMap);
}
}
Expand Down Expand Up @@ -507,8 +502,8 @@ public Void execute(FileSystem fs) throws IOException {
* Executor that performs a truncate FileSystemAccess files system operation.
*/
@InterfaceAudience.Private
public static class FSTruncate implements
FileSystemAccess.FileSystemExecutor<JSONObject> {
public static class FSTruncate implements
FileSystemAccess.FileSystemExecutor<Map> {
private Path path;
private long newLength;

Expand Down Expand Up @@ -537,7 +532,7 @@ public FSTruncate(String path, long newLength) {
* @throws IOException thrown if an IO error occurred.
*/
@Override
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
boolean result = fs.truncate(path, newLength);
HttpFSServerWebApp.get().getMetrics().incrOpsTruncate();
return toJSON(
Expand Down Expand Up @@ -730,7 +725,7 @@ public static long copyBytes(InputStream in, OutputStream out, long count)
*/
@InterfaceAudience.Private
public static class FSDelete
implements FileSystemAccess.FileSystemExecutor<JSONObject> {
implements FileSystemAccess.FileSystemExecutor<Map> {
private Path path;
private boolean recursive;

Expand All @@ -756,7 +751,7 @@ public FSDelete(String path, boolean recursive) {
* @throws IOException thrown if an IO error occurred.
*/
@Override
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
boolean deleted = fs.delete(path, recursive);
HttpFSServerWebApp.get().getMetrics().incrOpsDelete();
return toJSON(
Expand Down Expand Up @@ -842,7 +837,7 @@ public Map execute(FileSystem fs) throws IOException {
*/
@InterfaceAudience.Private
public static class FSHomeDir
implements FileSystemAccess.FileSystemExecutor<JSONObject> {
implements FileSystemAccess.FileSystemExecutor<Map> {

Comment thread
smengcl marked this conversation as resolved.
/**
* Executes the filesystem operation.
Expand All @@ -854,10 +849,9 @@ public static class FSHomeDir
* @throws IOException thrown if an IO error occurred.
*/
@Override
@SuppressWarnings("unchecked")
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
Path homeDir = fs.getHomeDirectory();
JSONObject json = new JSONObject();
Map<String, Object> json = new LinkedHashMap<>();
json.put(HttpFSConstants.HOME_DIR_JSON, homeDir.toUri().getPath());
return json;
}
Expand Down Expand Up @@ -955,7 +949,7 @@ public Map execute(FileSystem fs) throws IOException {
*/
@InterfaceAudience.Private
public static class FSMkdirs
implements FileSystemAccess.FileSystemExecutor<JSONObject> {
implements FileSystemAccess.FileSystemExecutor<Map> {

private Path path;
private short permission;
Expand Down Expand Up @@ -986,7 +980,7 @@ public FSMkdirs(String path, short permission,
* @throws IOException thrown if an IO error occurred.
*/
@Override
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
FsPermission fsPermission = new FsPermission(permission);
if (unmaskedPermission != -1) {
fsPermission = FsCreateModes.create(fsPermission,
Expand Down Expand Up @@ -1039,7 +1033,7 @@ public InputStream execute(FileSystem fs) throws IOException {
*/
@InterfaceAudience.Private
public static class FSRename
implements FileSystemAccess.FileSystemExecutor<JSONObject> {
implements FileSystemAccess.FileSystemExecutor<Map> {
private Path path;
private Path toPath;

Expand All @@ -1065,7 +1059,7 @@ public FSRename(String path, String toPath) {
* @throws IOException thrown if an IO error occurred.
*/
@Override
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
boolean renamed = fs.rename(path, toPath);
HttpFSServerWebApp.get().getMetrics().incrOpsRename();
return toJSON(HttpFSConstants.RENAME_JSON, renamed);
Expand Down Expand Up @@ -1343,18 +1337,17 @@ public Void execute(FileSystem fs) throws IOException {
*/
@InterfaceAudience.Private
public static class FSTrashRoot
implements FileSystemAccess.FileSystemExecutor<JSONObject> {
implements FileSystemAccess.FileSystemExecutor<Map> {
private Path path;

public FSTrashRoot(String path) {
this.path = new Path(path);
}

@Override
@SuppressWarnings("unchecked")
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
Path trashRoot = fs.getTrashRoot(this.path);
JSONObject json = new JSONObject();
Map<String, Object> json = new LinkedHashMap<>();
json.put(HttpFSConstants.TRASH_DIR_JSON, trashRoot.toUri().getPath());
return json;
}
Expand Down Expand Up @@ -1401,7 +1394,7 @@ public Map execute(FileSystem fs) throws IOException {
*/
@InterfaceAudience.Private
public static class FSSetReplication
implements FileSystemAccess.FileSystemExecutor<JSONObject> {
implements FileSystemAccess.FileSystemExecutor<Map> {
private Path path;
private short replication;

Expand All @@ -1427,10 +1420,9 @@ public FSSetReplication(String path, short replication) {
* @throws IOException thrown if an IO error occurred.
*/
@Override
@SuppressWarnings("unchecked")
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
boolean ret = fs.setReplication(path, replication);
JSONObject json = new JSONObject();
Map<String, Object> json = new LinkedHashMap<>();
json.put(HttpFSConstants.SET_REPLICATION_JSON, ret);
return json;
}
Expand Down Expand Up @@ -1610,13 +1602,12 @@ public Map execute(FileSystem fs) throws IOException {
* Executor that performs a getAllStoragePolicies FileSystemAccess files
* system operation.
*/
@SuppressWarnings({ "unchecked" })
@InterfaceAudience.Private
public static class FSGetAllStoragePolicies implements
FileSystemAccess.FileSystemExecutor<JSONObject> {
FileSystemAccess.FileSystemExecutor<Map> {

@Override
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
Collection<? extends BlockStoragePolicySpi> storagePolicies = fs
.getAllStoragePolicies();
return storagePoliciesToJSON(storagePolicies);
Expand All @@ -1627,10 +1618,9 @@ public JSONObject execute(FileSystem fs) throws IOException {
* Executor that performs a getStoragePolicy FileSystemAccess files system
* operation.
*/
@SuppressWarnings({ "unchecked" })
@InterfaceAudience.Private
public static class FSGetStoragePolicy implements
FileSystemAccess.FileSystemExecutor<JSONObject> {
FileSystemAccess.FileSystemExecutor<Map> {

private Path path;

Expand All @@ -1639,9 +1629,9 @@ public FSGetStoragePolicy(String path) {
}

@Override
public JSONObject execute(FileSystem fs) throws IOException {
public Map execute(FileSystem fs) throws IOException {
BlockStoragePolicySpi storagePolicy = fs.getStoragePolicy(path);
JSONObject json = new JSONObject();
Map<String, Object> json = new LinkedHashMap<>();
json.put(HttpFSConstants.STORAGE_POLICY_JSON,
storagePolicyToJSON(storagePolicy));
return json;
Expand Down Expand Up @@ -1793,9 +1783,9 @@ public FSCreateSnapshot(String path, String snapshotName) {
@Override
public String execute(FileSystem fs) throws IOException {
Path snapshotPath = fs.createSnapshot(path, snapshotName);
JSONObject json = toJSON(HttpFSConstants.HOME_DIR_JSON,
Map<String, Object> json = toJSON(HttpFSConstants.HOME_DIR_JSON,
snapshotPath.toString());
return json.toJSONString().replaceAll("\\\\", "");
return JsonUtil.toJsonString(json);
}
}

Expand Down
Loading