use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class WebHDFSCommand method remove.
private String remove(Map<String, String> mounts, String path) {
String mountPoint = determineMountPoint(path);
KnoxSession session = getSessionForMountPoint(mounts, mountPoint);
if (session != null) {
String targetPath = determineTargetPath(path, mountPoint);
try {
Hdfs.rm(session).file(targetPath).now().getString();
} catch (KnoxShellException | IOException e) {
e.printStackTrace();
}
} else {
return "No session established for mountPoint: " + mountPoint + " Use :fs mount {topology-url} {mountpoint-name}";
}
return "Successfully removed: " + path;
}
use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class WebHDFSCommand method exists.
private boolean exists(KnoxSession session, String path) {
boolean rc = false;
try {
Response response = Hdfs.status(session).file(path).now();
rc = response.exists();
} catch (KnoxShellException e) {
// NOP
}
return rc;
}
use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class WebHDFSCommand method cat.
private String cat(Map<String, String> mounts, String path) {
String response = null;
String mountPoint = determineMountPoint(path);
KnoxSession session = getSessionForMountPoint(mounts, mountPoint);
if (session != null) {
String targetPath = determineTargetPath(path, mountPoint);
try {
String contents = Hdfs.get(session).from(targetPath).now().getString();
response = contents;
} catch (KnoxShellException | IOException e) {
e.printStackTrace();
response = "Exception ocurred: " + e.getMessage();
}
} else {
response = "No session established for mountPoint: " + mountPoint + " Use :fs mount {topology-url} {mountpoint-name}";
}
return response;
}
use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class WebHDFSCommand method listStatus.
private Object listStatus(Map<String, String> mounts, String path) {
Object response = null;
try {
String directory;
String mountPoint = determineMountPoint(path);
if (mountPoint != null) {
KnoxSession session = getSessionForMountPoint(mounts, mountPoint);
if (session != null) {
directory = determineTargetPath(path, mountPoint);
String json = Hdfs.ls(session).dir(directory).now().getString();
Map<String, HashMap<String, ArrayList<HashMap<String, String>>>> map = JsonUtils.getFileStatusesAsMap(json);
if (map != null) {
ArrayList<HashMap<String, String>> list = map.get("FileStatuses").get("FileStatus");
KnoxShellTable table = buildTableFromListStatus(directory, list);
response = table;
}
} else {
response = "No session established for mountPoint: " + mountPoint + " Use :fs mount {topology-url} {mountpoint-name}";
}
} else {
response = "No mountpoint found. Use ':fs mount {topologyURL} {mountpoint}'.";
}
} catch (KnoxShellException | IOException e) {
response = "Exception ocurred: " + e.getMessage();
e.printStackTrace();
}
return response;
}
use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class AliasResponse method parseResponseEntity.
private void parseResponseEntity() {
if (!isExpectedResponseStatus()) {
throw new KnoxShellException("Unexpected response: " + response().getStatusLine().getReasonPhrase());
}
HttpEntity entity = response().getEntity();
if (entity == null) {
throw new KnoxShellException("Missing expected response content");
}
String contentType = entity.getContentType().getValue();
if (!CONTENT_TYPE.equals(contentType)) {
throw new KnoxShellException("Unexpected response content type: " + contentType);
}
try {
responseContent = EntityUtils.toString(entity);
parsedResponse = (new ObjectMapper()).readValue(responseContent, new TypeReference<Map<String, Object>>() {
});
} catch (Exception e) {
throw new KnoxShellException("Unable to process response content", e);
}
}
Aggregations