我已经找到了如何通过UI上传/管理Azure批处理作业应用程序包:
https://docs.microsoft.com/en-us/azure/batch/batch-application-packages
如何以编程方式上传和管理资源包:
但我似乎无法将2和2放在如何以编程方式管理Application Packages。在设置批处理作业时,是否有可以调用上传/管理应用程序包的API端点?
答案 0 :(得分:6)
由于这不是那么简单,我会写下我的发现。 这些是通过无人参与的应用程序以编程方式上载应用程序包的步骤 - 无需用户输入(例如Azure凭据)。
在Azure门户中:
Web app / API
)在您的代码中:
BatchManagementClient
ApplicationPackageOperationsExtensions.CreateAsync
方法,该方法应返回ApplicationPackage
ApplicationPackage
包含StorageUrl,现在可用于通过存储API上传应用程序包ApplicationPackage
后,您必须通过ApplicationPackageOperationsExtensions.ActivateAsync
将整个代码放在一起看起来像这样:
private const string ResourceUri = "https://management.core.windows.net/";
private const string AuthUri = "https://login.microsoftonline.com/" + "{TenantId}";
private const string ApplicationId = "{ApplicationId}";
private const string ApplicationSecretKey = "{ApplicationSecretKey}";
private const string SubscriptionId = "{SubscriptionId}";
private const string ResourceGroupName = "{ResourceGroupName}";
private const string BatchAccountName = "{BatchAccountName}";
private async Task UploadApplicationPackageAsync() {
// get the access token
var authContext = new AuthenticationContext(AuthUri);
var authResult = await authContext.AcquireTokenAsync(ResourceUri, new ClientCredential(ApplicationId, ApplicationSecretKey)).ConfigureAwait(false);
// create the BatchManagementClient and set the subscription id
var bmc = new BatchManagementClient(new TokenCredentials(authResult.AccessToken)) {
SubscriptionId = SubscriptionId
};
// create the application package
var createResult = await bmc.ApplicationPackage.CreateWithHttpMessagesAsync(ResourceGroupName, BatchAccountName, "MyPackage", "1.0").ConfigureAwait(false);
// upload the package to the blob storage
var cloudBlockBlob = new CloudBlockBlob(new Uri(createResult.Body.StorageUrl));
cloudBlockBlob.Properties.ContentType = "application/x-zip-compressed";
await cloudBlockBlob.UploadFromFileAsync("myZip.zip").ConfigureAwait(false);
// create the application package
var activateResult = await bmc.ApplicationPackage.ActivateWithHttpMessagesAsync(ResourceGroupName, BatchAccountName, "MyPackage", "1.0", "zip").ConfigureAwait(false);
}
答案 1 :(得分:1)
Azure批处理应用程序包管理操作在管理平面上进行。此命名空间的MSDN文档位于:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.batch
Microsoft.Azure.Management.Batch
的nuget包在这里:
https://www.nuget.org/packages/Microsoft.Azure.Management.Batch/
以下示例显示了C#中的管理平面操作,尽管它适用于非应用程序包操作:
https://github.com/Azure/azure-batch-samples/tree/master/CSharp/AccountManagement