Search in sources :

Example 1 with ForbiddenHttpErrorStatus

use of com.microsoft.azure.hdinsight.sdk.common.errorresponse.ForbiddenHttpErrorStatus in project azure-tools-for-java by Microsoft.

the class ADLSGen2FileSystem method listFiles.

@NotNull
public VirtualFile[] listFiles(AdlsGen2VirtualFile vf) {
    List<AdlsGen2VirtualFile> childrenList = new ArrayList<>();
    if (vf.isDirectory()) {
        // sample fileSystemRootPath: https://accountName.dfs.core.windows.net/fileSystem/
        String fileSystemRootPath = rootPathUri.resolve("/").getUrl().toString();
        // sample directoryParam: sub/path/to
        String directoryParam = vf.getAbfsUri().getDirectoryParam();
        childrenList = this.op.list(fileSystemRootPath, directoryParam).map(remoteFile -> new AdlsGen2VirtualFile((AbfsUri) AbfsUri.parse(fileSystemRootPath).resolveAsRoot(AzureStorageUri.encodeAndNormalizePath(remoteFile.getName())), remoteFile.isDirectory(), this)).doOnNext(file -> file.setParent(vf)).onErrorResumeNext(err -> {
            String errorMessage = "Failed to list folders and files with error " + err.getMessage() + ". ";
            if (err instanceof ForbiddenHttpErrorStatus) {
                errorMessage += ADLSGen2Deploy.getForbiddenErrorHints(vf.toString());
            }
            return Observable.error(new IOException(errorMessage));
        }).toList().toBlocking().lastOrDefault(new ArrayList<>());
    }
    return childrenList.toArray(new VirtualFile[0]);
}
Also used : ForbiddenHttpErrorStatus(com.microsoft.azure.hdinsight.sdk.common.errorresponse.ForbiddenHttpErrorStatus) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ADLSGen2Deploy(com.microsoft.azure.hdinsight.spark.common.ADLSGen2Deploy) IOException(java.io.IOException) VirtualFileListener(com.intellij.openapi.vfs.VirtualFileListener) AbfsUri(com.microsoft.azure.hdinsight.common.AbfsUri) HttpObservable(com.microsoft.azure.hdinsight.sdk.common.HttpObservable) ADLSGen2FSOperation(com.microsoft.azure.hdinsight.sdk.storage.adlsgen2.ADLSGen2FSOperation) Observable(rx.Observable) ArrayList(java.util.ArrayList) List(java.util.List) AzureStorageUri(com.microsoft.azure.hdinsight.common.AzureStorageUri) ArrayList(java.util.ArrayList) ForbiddenHttpErrorStatus(com.microsoft.azure.hdinsight.sdk.common.errorresponse.ForbiddenHttpErrorStatus) IOException(java.io.IOException) AbfsUri(com.microsoft.azure.hdinsight.common.AbfsUri) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileListener (com.intellij.openapi.vfs.VirtualFileListener)1 AbfsUri (com.microsoft.azure.hdinsight.common.AbfsUri)1 AzureStorageUri (com.microsoft.azure.hdinsight.common.AzureStorageUri)1 HttpObservable (com.microsoft.azure.hdinsight.sdk.common.HttpObservable)1 ForbiddenHttpErrorStatus (com.microsoft.azure.hdinsight.sdk.common.errorresponse.ForbiddenHttpErrorStatus)1 ADLSGen2FSOperation (com.microsoft.azure.hdinsight.sdk.storage.adlsgen2.ADLSGen2FSOperation)1 ADLSGen2Deploy (com.microsoft.azure.hdinsight.spark.common.ADLSGen2Deploy)1 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)1 Nullable (com.microsoft.azuretools.azurecommons.helpers.Nullable)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Observable (rx.Observable)1