栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Azure Java SDK:ServiceException:ForbiddenError:

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Azure Java SDK:ServiceException:ForbiddenError:

此问题是由于使用了不正确的Azure Java SDK库引起的。当我在下面的文件pom.xml中使用Maven依赖项时,我重现了相同的异常。

<dependency>   <groupId>com.microsoft.azure</groupId>   <artifactId>azure-mgmt-compute</artifactId>   <version>0.8.3</version></dependency>

提供VM重新启动功能的库需要两个参数:

resource group name
vm name
。但是库的API
azure-mgmt-compute
用于Azure资源管理。

若要重新启动VM,

azure-svc-mgmt-compute
如果使用了JKS证书,则需要使用库的API 进行Azure Service
Management。类
VirtualMachineOperations
提供同名函数
restart
需要三个参数:
servicename
deployment name
vm name
。您可以从Azure门户上的Cloud
Service仪表板中找到这些名称。在您的问题代码中,
vm name
应当为“ sqlvm”。

正确的maven pom.xml用于依赖关系,如下所示:

<dependency>   <groupId>com.microsoft.azure</groupId>   <artifactId>azure-svc-mgmt</artifactId>   <version>0.8.3</version></dependency><dependency>   <groupId>com.microsoft.azure</groupId>   <artifactId>azure-svc-mgmt-compute</artifactId>   <version>0.8.3</version></dependency>

和下面的代码

virtualMachinesOperations.restart("<service name: sqlvm>", "<deployment name: sqlvm>", "<vm name: sqlvm>");

通过在路径JAVA_HOME / bin中使用Java Keytool进行genkeypair的以下步骤:

keytool -genkeypair -alias keyfile -keyalg RSA -keystore <KeyStore.jks> -keysize 2048 -storepass "<password>"keytool -v -export -file <KeyStore.cer> -keystore KeyStore.jks -alias keyfile

我的代码:

String uri = "https://management.core.windows.net/";String subscriptionId = "<subscription_id>";String keyStoreLocation = "KeyStore.jks";String keyStorePassword = "<password>";Configuration config = ManagementConfiguration.configure(       new URI(uri),        subscriptionId,       keyStoreLocation, // the file path to the JKS       keyStorePassword, // the password for the JKS       KeyStoreType.jks // flags that I'm using a JKS keystore    ); ComputeManagementClient computeManagementClient = ComputeManagementService.create(config);VirtualMachineOperations virtualMachinesOperations = computeManagementClient.getVirtualMachinesOperations();virtualMachinesOperations.restart("petercore", "petercore", "petercore");


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/455472.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号