Skip to content

Commit 5de58f4

Browse files
mgmt update readme, add more concept (#11423)
* support creatable as input * update readme to add more key concept * use variable instead of string * use variable instead * concept on RBAC
1 parent 471a3a7 commit 5de58f4

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/FunctionApp.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ interface WithStorageAccount {
325325
*/
326326
WithCreate withNewStorageAccount(String name, StorageAccountSkuType sku);
327327

328+
/**
329+
* Creates a new storage account to use for the function app.
330+
*
331+
* @param storageAccount a creatable definition for a new storage account
332+
* @return the next stage of the definition
333+
*/
334+
WithCreate withNewStorageAccount(Creatable<StorageAccount> storageAccount);
335+
328336
/**
329337
* Specifies the storage account to use for the function app.
330338
*

sdk/appservice/mgmt/src/main/java/com/azure/management/appservice/implementation/FunctionAppImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,13 @@ public FunctionAppImpl withNewStorageAccount(String name, StorageAccountSkuType
332332
return this;
333333
}
334334

335+
@Override
336+
public FunctionAppImpl withNewStorageAccount(Creatable<StorageAccount> storageAccount) {
337+
storageAccountCreatable = storageAccount;
338+
this.addDependency(storageAccountCreatable);
339+
return this;
340+
}
341+
335342
@Override
336343
public FunctionAppImpl withExistingStorageAccount(StorageAccount storageAccount) {
337344
this.storageAccountToSet = storageAccount;

sdk/management/README.md

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ In addition, Azure subscription ID can be configured via environment variable `A
7070
With above configuration, `azure` client can be authenticated by following code:
7171

7272
```java
73-
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
73+
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
7474
TokenCredential credential = new DefaultAzureCredentialBuilder()
7575
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
7676
.build();
@@ -90,6 +90,9 @@ See [Samples][sample] for code snippets and samples.
9090
The key concepts of Azure Management Libraries includes:
9191

9292
- Fluent interface to manage Azure resources.
93+
- Dependency across Azure resources.
94+
- Batch Azure resource provisioning.
95+
- Integration with Azure role-based access control.
9396
- Asynchronous operations with [Reactor][reactor].
9497
- Configurable client, e.g. configuring HTTP client, retries, logging, etc.
9598

@@ -108,7 +111,7 @@ The key concepts of Azure Management Libraries includes:
108111

109112
### Fluent interface
110113

111-
You can create a virtual machine instance, together with required virtual network and ip address.
114+
You can create a virtual machine instance, together with required virtual network and ip address created automatically.
112115

113116
```java
114117
VirtualMachine linuxVM = azure.virtualMachines().define("myLinuxVM")
@@ -132,12 +135,78 @@ linuxVM.update()
132135
.apply();
133136
```
134137

138+
### Dependency across Azure resources.
139+
140+
You can create a function app, together with required storage account and app service plan created on specification.
141+
142+
```java
143+
Creatable<StorageAccount> creatableStorageAccount = azure.storageAccounts()
144+
.define(storageAccountName)
145+
.withRegion(Region.US_EAST)
146+
.withExistingResourceGroup(rgName)
147+
.withGeneralPurposeAccountKindV2()
148+
.withSku(StorageAccountSkuType.STANDARD_LRS);
149+
150+
Creatable<AppServicePlan> creatableAppServicePlan = azure.appServicePlans()
151+
.define(appServicePlanName)
152+
.withRegion(Region.US_EAST)
153+
.withExistingResourceGroup(rgName)
154+
.withPricingTier(PricingTier.STANDARD_S1)
155+
.withOperatingSystem(OperatingSystem.LINUX);
156+
157+
FunctionApp linuxFunctionApp = azure.functionApps().define(functionAppName)
158+
.withRegion(Region.US_EAST)
159+
.withExistingResourceGroup(rgName)
160+
.withNewLinuxAppServicePlan(creatableAppServicePlan)
161+
.withBuiltInImage(FunctionRuntimeStack.JAVA_8)
162+
.withNewStorageAccount(creatableStorageAccount)
163+
.withHttpsOnly(true)
164+
.withAppSetting("WEBSITE_RUN_FROM_PACKAGE", functionAppPackageUrl)
165+
.create();
166+
```
167+
168+
### Batch Azure resource provisioning
169+
170+
You can batch create and delete managed disk instances.
171+
172+
```java
173+
List<String> diskNames = Arrays.asList("datadisk1", "datadisk2");
174+
175+
List<Creatable<Disk>> creatableDisks = diskNames.stream()
176+
.map(diskName -> azure.disks()
177+
.define(diskName)
178+
.withRegion(Region.US_EAST)
179+
.withExistingResourceGroup(rgName)
180+
.withData()
181+
.withSizeInGB(1)
182+
.withSku(DiskSkuTypes.STANDARD_LRS))
183+
.collect(Collectors.toList());
184+
185+
Collection<Disk> disks = azure.disks().create(creatableDisks).values();
186+
187+
azure.disks().deleteByIds(disks.stream().map(Disk::id).collect(Collectors.toList()));
188+
```
189+
190+
### Integration with Azure role-based access control
191+
192+
You can assign Contributor for an Azure resource to a service principal.
193+
194+
```java
195+
String raName = UUID.randomUUID().toString();
196+
RoleAssignment roleAssignment = azure.accessManagement().roleAssignments()
197+
.define(raName)
198+
.forServicePrincipal(servicePrincipal)
199+
.withBuiltInRole(BuiltInRole.CONTRIBUTOR)
200+
.withScope(resource.id())
201+
.create();
202+
```
203+
135204
### Asynchronous operations
136205

137206
You can create storage account, then blob container, in reactive programming.
138207

139208
```java
140-
azure.storageAccounts().define("mystorageaccount")
209+
azure.storageAccounts().define(storageAccountName)
141210
.withRegion(Region.US_EAST)
142211
.withNewResourceGroup(rgName)
143212
.withSku(StorageAccountSkuType.STANDARD_LRS)
@@ -151,7 +220,16 @@ azure.storageAccounts().define("mystorageaccount")
151220
.withExistingBlobService(rgName, ((StorageAccount) indexable).name())
152221
.withPublicAccess(PublicAccess.BLOB)
153222
.createAsync()
154-
).blockLast();
223+
)
224+
...
225+
```
226+
227+
You can operate on virtual machines in parallel.
228+
229+
```java
230+
azure.virtualMachines().listByResourceGroupAsync(rgName)
231+
.flatMap(VirtualMachine::restartAsync)
232+
...
155233
```
156234

157235
### Configurable client

0 commit comments

Comments
 (0)