Search in sources :

Example 6 with KnoxShellException

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;
}
Also used : KnoxSession(org.apache.knox.gateway.shell.KnoxSession) IOException(java.io.IOException) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException)

Example 7 with KnoxShellException

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);
    }
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) IOException(java.io.IOException) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException)

Example 8 with KnoxShellException

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());
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpResponse(org.apache.http.HttpResponse) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 9 with KnoxShellException

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());
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpResponse(org.apache.http.HttpResponse) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Aggregations

KnoxShellException (org.apache.knox.gateway.shell.KnoxShellException)9 IOException (java.io.IOException)5 KnoxSession (org.apache.knox.gateway.shell.KnoxSession)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HttpResponse (org.apache.http.HttpResponse)2 StringEntity (org.apache.http.entity.StringEntity)2 Test (org.junit.Test)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)1 HashMap (java.util.HashMap)1 HttpEntity (org.apache.http.HttpEntity)1 Response (org.apache.knox.gateway.shell.hdfs.Status.Response)1 KnoxShellTable (org.apache.knox.gateway.shell.table.KnoxShellTable)1