use of org.apache.knox.gateway.shell.KnoxSession 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.KnoxSession in project knox by apache.
the class WebHDFSCommand method mount.
private String mount(Map<String, String> mounts, String url, String mountPoint) {
KnoxSession session = establishSession(mountPoint, url);
if (session != null) {
mounts.put(mountPoint, url);
KnoxSession.persistMountPoints(mounts);
return url + " mounted as " + mountPoint;
}
return "Failed to mount " + url + " as " + mountPoint;
}
use of org.apache.knox.gateway.shell.KnoxSession in project knox by apache.
the class WebHDFSCommand method establishSession.
private KnoxSession establishSession(String mountPoint, String url) {
CredentialCollector dlg;
try {
dlg = login();
} catch (CredentialCollectionException e) {
e.printStackTrace();
return null;
}
String username = dlg.name();
String password = new String(dlg.chars());
KnoxSession session = null;
try {
session = KnoxSession.login(url, username, password);
sessions.put(mountPoint, session);
} catch (URISyntaxException e) {
e.printStackTrace();
}
return session;
}
use of org.apache.knox.gateway.shell.KnoxSession 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.KnoxSession in project knox by apache.
the class WebHDFSCommand method put.
private String put(Map<String, String> mounts, String localFile, String path, int permission) {
String mountPoint = determineMountPoint(path);
KnoxSession session = getSessionForMountPoint(mounts, mountPoint);
if (session != null) {
String targetPath = determineTargetPath(path, mountPoint);
try {
boolean overwrite = false;
if (exists(session, targetPath)) {
if (collectClearInput(targetPath + " already exists would you like to overwrite (Y/n)").equalsIgnoreCase("y")) {
overwrite = true;
}
}
Hdfs.put(session).file(localFile).to(targetPath).overwrite(overwrite).permission(permission).now().getString();
} catch (IOException e) {
e.printStackTrace();
return "Exception ocurred: " + e.getMessage();
}
} else {
return "No session established for mountPoint: " + mountPoint + " Use :fs mount {topology-url} {mountpoint-name}";
}
return "Successfully put: " + localFile + " to: " + path;
}
Aggregations