Search in sources :

Example 1 with HDFSPath

use of org.talend.designer.hdfsbrowse.model.HDFSPath in project tbd-studio-se by Talend.

the class FileSelectorTreeViewerProvider method getElements.

public Object[] getElements(Object inputElement) {
    if (inputElement instanceof HDFSConnectionBean) {
        try {
            HDFSPath root = new HDFSFolder(this, (HDFSConnectionBean) inputElement);
            root.setValue(ROOT_PATH);
            root.setPath(ROOT_PATH);
            return new Object[] { root };
        } catch (Exception e) {
            log.error(e);
        }
    }
    return EMPTY_CONTENT;
}
Also used : HDFSConnectionBean(org.talend.designer.hdfsbrowse.model.HDFSConnectionBean) HDFSPath(org.talend.designer.hdfsbrowse.model.HDFSPath) HDFSFolder(org.talend.designer.hdfsbrowse.model.HDFSFolder)

Example 2 with HDFSPath

use of org.talend.designer.hdfsbrowse.model.HDFSPath in project tbd-studio-se by Talend.

the class HadoopOperationManager method loadHDFSFolderChildren.

public void loadHDFSFolderChildren(HDFSConnectionBean connection, Object fileSystem, ClassLoader classLoader, HDFSPath parent, String path) throws HadoopServerException {
    if (connection == null || fileSystem == null || classLoader == null || parent == null || path == null) {
        return;
    }
    ClassLoader oldClassLoaderLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        Object pathObj = ReflectionUtils.newInstance("org.apache.hadoop.fs.Path", classLoader, new Object[] { path });
        Object[] statusList = (Object[]) ReflectionUtils.invokeMethod(fileSystem, "listStatus", new Object[] { pathObj });
        if (statusList == null) {
            return;
        }
        for (Object status : statusList) {
            HDFSPath content = null;
            Object statusPath = ReflectionUtils.invokeMethod(status, "getPath", new Object[0]);
            if (statusPath == null) {
                continue;
            }
            String pathName = (String) ReflectionUtils.invokeMethod(statusPath, "getName", new Object[0]);
            if (StringUtils.isBlank(pathName)) {
                continue;
            }
            String absolutePath = ((URI) ReflectionUtils.invokeMethod(statusPath, "toUri", new Object[0])).toString();
            if (StringUtils.isBlank(absolutePath)) {
                continue;
            }
            String relativePath = URI.create(absolutePath).getPath();
            if ((Boolean) ReflectionUtils.invokeMethod(status, "isDir", new Object[0])) {
                content = new HDFSFolder(parent);
            } else {
                content = new HDFSFile(parent);
                content.setTable(createTable(trimFileExtention(pathName)));
            }
            content.setPath(relativePath);
            content.setValue(pathName);
            parent.addChild(content);
        }
    } catch (Exception e) {
        throw new HadoopServerException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoaderLoader);
    }
}
Also used : HDFSFile(org.talend.designer.hdfsbrowse.model.HDFSFile) HDFSPath(org.talend.designer.hdfsbrowse.model.HDFSPath) HDFSFolder(org.talend.designer.hdfsbrowse.model.HDFSFolder) HadoopServerException(org.talend.designer.hdfsbrowse.exceptions.HadoopServerException) URI(java.net.URI) HadoopServerException(org.talend.designer.hdfsbrowse.exceptions.HadoopServerException)

Aggregations

HDFSFolder (org.talend.designer.hdfsbrowse.model.HDFSFolder)2 HDFSPath (org.talend.designer.hdfsbrowse.model.HDFSPath)2 URI (java.net.URI)1 HadoopServerException (org.talend.designer.hdfsbrowse.exceptions.HadoopServerException)1 HDFSConnectionBean (org.talend.designer.hdfsbrowse.model.HDFSConnectionBean)1 HDFSFile (org.talend.designer.hdfsbrowse.model.HDFSFile)1