use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class WebHDFSCommand method mkdir.
private String mkdir(Map<String, String> mounts, String path, String perms) {
String result = null;
String mountPoint = determineMountPoint(path);
KnoxSession session = getSessionForMountPoint(mounts, mountPoint);
if (session != null) {
String targetPath = determineTargetPath(path, mountPoint);
if (!exists(session, targetPath)) {
try {
if (perms != null) {
Hdfs.mkdir(sessions.get(mountPoint)).dir(targetPath).now().getString();
} else {
Hdfs.mkdir(session).dir(targetPath).perm(perms).now().getString();
}
result = "Successfully created directory: " + targetPath;
} catch (KnoxShellException | IOException e) {
e.printStackTrace();
result = "Exception ocurred: " + e.getMessage();
}
} else {
result = targetPath + " already exists";
}
} else {
result = "No session established for mountPoint: " + mountPoint + " Use :fs mount {topology-url} {mountpoint-name}";
}
return result;
}
use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class KnoxShellTableJSONSerializer method saveTableInFile.
private static String saveTableInFile(KnoxShellTable table, boolean data, String filePath) {
try {
final String jsonResult;
if (data) {
final SimpleFilterProvider filterProvider = new SimpleFilterProvider();
filterProvider.addFilter("knoxShellTableFilter", SimpleBeanPropertyFilter.filterOutAllExcept("headers", "rows", "title", "id"));
jsonResult = JsonUtils.renderAsJsonString(table, filterProvider, JSON_DATE_FORMAT.get());
} else {
jsonResult = JsonUtils.renderAsJsonString(KnoxShellTableCallHistory.getInstance().getCallHistory(table.id), null, JSON_DATE_FORMAT.get());
}
KnoxShellTableFileUtils.persistToFile(filePath, jsonResult);
return "Successfully saved into " + filePath;
} catch (IOException e) {
throw new KnoxShellException("Error while saving KnoxShellTable JSON into " + filePath, e);
}
}
use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class AbstractResponseTest method testInvalidResponseJSON.
@Test
public void testInvalidResponseJSON() {
StringEntity entity = null;
try {
entity = new StringEntity("{ \"topology\": \"testInvalidJSONCluster\", \"aliases\" : [ ");
entity.setContentType("application/json");
} catch (UnsupportedEncodingException e) {
fail(e.getMessage());
}
HttpResponse httpResponse = createTestResponse(createTestStatusLine(getExpectedResponseStatusCode()), entity);
try {
createResponse(httpResponse);
} catch (KnoxShellException e) {
// Expected
assertEquals("Unable to process response content", e.getMessage());
assertTrue(e.getCause().getMessage().contains("Unexpected end-of-input"));
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.apache.knox.gateway.shell.KnoxShellException in project knox by apache.
the class AbstractResponseTest method testInvalidResponseContentType.
@Test
public void testInvalidResponseContentType() {
StringEntity entity = null;
try {
entity = new StringEntity("{ \"topology\": \"testInvalidJSONCluster\", \"aliases\" : [ ");
} catch (UnsupportedEncodingException e) {
fail(e.getMessage());
}
HttpResponse httpResponse = createTestResponse(createTestStatusLine(getExpectedResponseStatusCode()), entity);
try {
createResponse(httpResponse);
} catch (KnoxShellException e) {
// Expected
assertTrue(e.getMessage().startsWith("Unexpected response content type: "));
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations