From ed7bdc0d6d60d1c7c88807a4f828b6f445d772e9 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Tue, 26 May 2020 12:55:48 +0800 Subject: [PATCH 1/5] support creatable as input --- .../java/com/azure/management/appservice/FunctionApp.java | 8 ++++++++ .../appservice/implementation/FunctionAppImpl.java | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/FunctionApp.java b/sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/FunctionApp.java index 1c5b59cb77f0..3c98f2c7e3d3 100644 --- a/sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/FunctionApp.java +++ b/sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/FunctionApp.java @@ -325,6 +325,14 @@ interface WithStorageAccount { */ WithCreate withNewStorageAccount(String name, StorageAccountSkuType sku); + /** + * Creates a new storage account to use for the function app. + * + * @param storageAccount a creatable definition for a new storage account + * @return the next stage of the definition + */ + WithCreate withNewStorageAccount(Creatable storageAccount); + /** * Specifies the storage account to use for the function app. * diff --git a/sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/implementation/FunctionAppImpl.java b/sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/implementation/FunctionAppImpl.java index e16cc2f898a7..b794874f54b5 100644 --- a/sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/implementation/FunctionAppImpl.java +++ b/sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/implementation/FunctionAppImpl.java @@ -332,6 +332,13 @@ public FunctionAppImpl withNewStorageAccount(String name, StorageAccountSkuType return this; } + @Override + public FunctionAppImpl withNewStorageAccount(Creatable storageAccount) { + storageAccountCreatable = storageAccount; + this.addDependency(storageAccountCreatable); + return this; + } + @Override public FunctionAppImpl withExistingStorageAccount(StorageAccount storageAccount) { this.storageAccountToSet = storageAccount; From 299192ee3fa5d487e19d9dd10b015daedbd108ee Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Tue, 26 May 2020 12:57:02 +0800 Subject: [PATCH 2/5] update readme to add more key concept --- sdk/management/README.md | 69 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/sdk/management/README.md b/sdk/management/README.md index 13a55e5e7408..4aeb9ccea4b7 100644 --- a/sdk/management/README.md +++ b/sdk/management/README.md @@ -70,7 +70,7 @@ In addition, Azure subscription ID can be configured via environment variable `A With above configuration, `azure` client can be authenticated by following code: ```java -AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true); +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); TokenCredential credential = new DefaultAzureCredentialBuilder() .authorityHost(profile.environment().getActiveDirectoryEndpoint()) .build(); @@ -90,6 +90,8 @@ See [Samples][sample] for code snippets and samples. The key concepts of Azure Management Libraries includes: - Fluent interface to manage Azure resources. +- Dependency across Azure resources. +- Batch Azure resource provisioning. - Asynchronous operations with [Reactor][reactor]. - Configurable client, e.g. configuring HTTP client, retries, logging, etc. @@ -108,7 +110,7 @@ The key concepts of Azure Management Libraries includes: ### Fluent interface -You can create a virtual machine instance, together with required virtual network and ip address. +You can create a virtual machine instance, together with required virtual network and ip address created automatically. ```java VirtualMachine linuxVM = azure.virtualMachines().define("myLinuxVM") @@ -132,6 +134,58 @@ linuxVM.update() .apply(); ``` +### Dependency across Azure resources. + +You can create a function app, together with required storage account and app service plan created on specification. + +```java +Creatable creatableStorageAccount = azure.storageAccounts() + .define(storageAccountName) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withGeneralPurposeAccountKindV2() + .withSku(StorageAccountSkuType.STANDARD_LRS); + +Creatable creatableAppServicePlan = azure.appServicePlans() + .define(appServicePlanName) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withPricingTier(PricingTier.STANDARD_S1) + .withOperatingSystem(OperatingSystem.LINUX); + +FunctionApp linuxFunctionApp = azure.functionApps().define(functionAppName) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withNewLinuxAppServicePlan(creatableAppServicePlan) + .withBuiltInImage(FunctionRuntimeStack.JAVA_8) + .withNewStorageAccount(creatableStorageAccount) + .withHttpsOnly(true) + .withAppSetting("WEBSITE_RUN_FROM_PACKAGE", FUNCTION_APP_PACKAGE_URL) + .create(); +``` + +### Batch Azure resource provisioning + +You can batch create and delete managed disk instances. + +```java +List diskNames = Arrays.asList("datadisk1", "datadisk2"); + +List> creatableDisks = diskNames.stream() + .map(diskName -> azure.disks() + .define(diskName) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withData() + .withSizeInGB(1) + .withSku(DiskSkuTypes.STANDARD_LRS)) + .collect(Collectors.toList()); + +Collection disks = azure.disks().create(creatableDisks).values(); + +azure.disks().deleteByIds(disks.stream().map(Disk::id).collect(Collectors.toList())); +``` + ### Asynchronous operations You can create storage account, then blob container, in reactive programming. @@ -151,7 +205,16 @@ azure.storageAccounts().define("mystorageaccount") .withExistingBlobService(rgName, ((StorageAccount) indexable).name()) .withPublicAccess(PublicAccess.BLOB) .createAsync() - ).blockLast(); + ) + ... +``` + +You can operate on virtual machines in parallel. + +```java +azure.virtualMachines().listByResourceGroupAsync(rgName) + .flatMap(VirtualMachine::restartAsync) + ... ``` ### Configurable client From 7022356cae387e21a7b7b67071c8d5b1e7794ac8 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Tue, 26 May 2020 13:06:50 +0800 Subject: [PATCH 3/5] use variable instead of string --- sdk/management/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/management/README.md b/sdk/management/README.md index 4aeb9ccea4b7..9899215ef96b 100644 --- a/sdk/management/README.md +++ b/sdk/management/README.md @@ -191,7 +191,7 @@ azure.disks().deleteByIds(disks.stream().map(Disk::id).collect(Collectors.toList You can create storage account, then blob container, in reactive programming. ```java -azure.storageAccounts().define("mystorageaccount") +azure.storageAccounts().define(storageAccountName) .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .withSku(StorageAccountSkuType.STANDARD_LRS) From 757bface202afa5c3a080eeec02ab77ca2f51a59 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Tue, 26 May 2020 13:14:57 +0800 Subject: [PATCH 4/5] use variable instead --- sdk/management/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/management/README.md b/sdk/management/README.md index 9899215ef96b..1e6c41c157f9 100644 --- a/sdk/management/README.md +++ b/sdk/management/README.md @@ -160,7 +160,7 @@ FunctionApp linuxFunctionApp = azure.functionApps().define(functionAppName) .withBuiltInImage(FunctionRuntimeStack.JAVA_8) .withNewStorageAccount(creatableStorageAccount) .withHttpsOnly(true) - .withAppSetting("WEBSITE_RUN_FROM_PACKAGE", FUNCTION_APP_PACKAGE_URL) + .withAppSetting("WEBSITE_RUN_FROM_PACKAGE", functionAppPackageUrl) .create(); ``` From 3eb4a15b3d31e872f0d84dc17ab0c651552f3566 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Wed, 27 May 2020 13:26:29 +0800 Subject: [PATCH 5/5] concept on RBAC --- sdk/management/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdk/management/README.md b/sdk/management/README.md index 1e6c41c157f9..88d577a1aae0 100644 --- a/sdk/management/README.md +++ b/sdk/management/README.md @@ -92,6 +92,7 @@ The key concepts of Azure Management Libraries includes: - Fluent interface to manage Azure resources. - Dependency across Azure resources. - Batch Azure resource provisioning. +- Integration with Azure role-based access control. - Asynchronous operations with [Reactor][reactor]. - Configurable client, e.g. configuring HTTP client, retries, logging, etc. @@ -186,6 +187,20 @@ Collection disks = azure.disks().create(creatableDisks).values(); azure.disks().deleteByIds(disks.stream().map(Disk::id).collect(Collectors.toList())); ``` +### Integration with Azure role-based access control + +You can assign Contributor for an Azure resource to a service principal. + +```java +String raName = UUID.randomUUID().toString(); +RoleAssignment roleAssignment = azure.accessManagement().roleAssignments() + .define(raName) + .forServicePrincipal(servicePrincipal) + .withBuiltInRole(BuiltInRole.CONTRIBUTOR) + .withScope(resource.id()) + .create(); +``` + ### Asynchronous operations You can create storage account, then blob container, in reactive programming.