java - 无法使用 Azure Management Libraries for Java 在订阅中列出 azure appservices(春季启动应用程序)
问题描述
我正在尝试使用适用于 java 的 azure 管理库在我的一个 azure 订阅中的 appservices 中列出我部署的 Spring Boot 应用程序,但无法这样做。
从 azure cli 一切正常。
azure java sdk version 1.18.0 (latest)
jdk version 1.8.0_172
构建.gradle
dependencies {
compile group: 'com.microsoft.azure', name: 'azure', version: '1.18.0'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
片段
try {
Azure azure = Azure
.configure()
.authenticate(applicationTokenCredentials)
.withDefaultSubscription();
listWebApps(azure);
listWebAppsUsingAppServicePlan(azure);
} catch (IOException e) {
e.printStackTrace();
}
private static void listWebAppsUsingAppServicePlan(Azure azure){
PagedList<WebApp> webAppPagedList = azure.appServices().webApps().list();
System.out.printf("There are %d web apps when searched via azure.appServices().webApps()\n", webAppPagedList.size());
for (WebApp app : webAppPagedList) {
System.out.printf("App: %s, Deployment slots: %d", app.name(), app.deploymentSlots().list().size());
}
}
private static void listWebApps(Azure azure){
PagedList<WebApp> webAppPagedList = azure.webApps().list();
System.out.printf("There are %d web apps when searched via azure.webApps()\n", webAppPagedList.size());
for (WebApp app : webAppPagedList) {
System.out.printf("App: %s, Deployment slots: %d", app.name(), app.deploymentSlots().list().size());
}
}
输出
There are 0 web apps when searched via azure.webApps()
There are 0 web apps when searched via azure.appServices().webApps()
我是否遗漏了什么,或者是否有一些先决条件让我知道。
非常感谢。
解决方案
不知何故azure.webApps().list()
,方法是返回一个空列表,但切换到
azure.webapps.listAsync()
解决了我的问题。
新的片段
azure.webApps().listAsync()
.subscribe(webApp -> {
int capacity = webApp.manager().appServicePlans().getById(webApp.appServicePlanId()).capacity();
System.out.println(webApp.name() + ": " + capacity + (capacity == 1 ? " instance" : " instances"));
});
}
推荐阅读
- sql - 按每个 ID 的最小和最大日期分组
- c++ - libgtest.so 文件无法识别,格式无法识别
- c# - 如何从对象列表中调用通用函数
- python - 无法在我的公司网络上安装 Pylint
- r - dplyr/purrr 遍历列和行
- spring-boot - ConnectionPool:池为空 - 增加 maxPoolSize 或 borrowConnectionTimeout
- r - 如何为多项 gbm 创建部分依赖图?
- here-api - HERE Maps API 在 Chromium 80 上随机变为空白
- javascript - Firebase Web 应用程序 - 调用 gotData 函数
- javascript - 在函数内部调用 Promise,然后导出结果?