gpt4 book ai didi

java - 尝试在 Azure 上创建目录时出现 AccessControlException

转载 作者:行者123 更新时间:2023-11-30 02:04:36 24 4
gpt4 key购买 nike

我正在尝试使用 azure 数据湖依赖项在 azureDataLake 中创建目录

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-data-lake-store-sdk</artifactId>
<version>2.1.5</version>
</dependency>

使用以下方法:

private ADLStoreClient client; 
public boolean createDirectory(String path) {
try {

// create directory
client.createDirectory(path);

} catch (ADLException ex) {
printExceptionDetails(ex);
return false;
} catch (Exception ex) {
log.error(" Exception in createDirectory : {}", ex);
return false;
}
return true;
}

我得到了这个异常:

Error creating directory /gx-zweappdhd004/home/azhdipaasssh2/ADH/Compta/1458/1533632735200/RAPPORTS/
Operation MKDIRS failed with HTTP403 : AccessControlException

我检查了权限,我都有,所以与权限无关。

更新:

更具体地说,方法内部发生的问题 isSuccessfulResponse() ,正是在这一行 HttpTransport.java#L137因为 httpResponseCode 等于 403,谁能解释一下。

更新2:

我发现这一行返回 403 状态:HttpTransport.java#L288 ,我还尝试评估 conn.getErrorStream().read() 并得到此 stream is close,仅供引用,这是有时会出现的错误,但并非总是如此。

最佳答案

我没有重现您的问题,您可以引用我的工作代码:

import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
import com.microsoft.aad.adal4j.ClientCredential;
import com.microsoft.azure.datalake.store.ADLStoreClient;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class CreateDirectory {

static ADLStoreClient client;

public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
setup();
}

public static void setup() throws IOException, ExecutionException, InterruptedException {
String APP_ID = "<your app id>";
String APP_SECRET = "<your app secret>";
String dirName = "/jay";
String StoreAcct = "jaygong";

String authority = "https://login.microsoftonline.com/<your tenant id>";
String resourcUrl = "https://management.core.windows.net/";
ExecutorService service = Executors.newFixedThreadPool(1);

AuthenticationContext context = new AuthenticationContext(authority, true, service);

// Acquire Token
Future<AuthenticationResult> result = context.acquireToken(
resourcUrl,
new ClientCredential(APP_ID, APP_SECRET),
null
);
String token = result.get().getAccessToken();
System.out.println(token);

String account = StoreAcct + ".azuredatalakestore.net";
client = ADLStoreClient.createClient(account, token);

client.createDirectory(dirName);
System.out.println("finish.....");

}
}

enter image description here

不要忘记向您的客户端授予访问 ADL 权限。

enter image description here

enter image description here

希望对您有帮助。

关于java - 尝试在 Azure 上创建目录时出现 AccessControlException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51723244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com