Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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> storageAccount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required only for new section added in README? Should we plan to cover same scenario for important resource inside Network, Compute, etc. ?

Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should cover them (they are largely already covered, as in VM, network. But just this one I was trying to do in README is not...).

Probably going to put it in guideline if possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. As we put this on README, then it will be significant to our users. I will double check if any missing in Network and Compute first.


/**
* Specifies the storage account to use for the function app.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@ public FunctionAppImpl withNewStorageAccount(String name, StorageAccountSkuType
return this;
}

@Override
public FunctionAppImpl withNewStorageAccount(Creatable<StorageAccount> storageAccount) {
storageAccountCreatable = storageAccount;
this.addDependency(storageAccountCreatable);
return this;
}

@Override
public FunctionAppImpl withExistingStorageAccount(StorageAccount storageAccount) {
this.storageAccountToSet = storageAccount;
Expand Down
86 changes: 82 additions & 4 deletions sdk/management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we don't have a AzureProfile constructor with only one parameter.

Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a pending discussion with Chuang. true or false here is not very human friendly. So a proposal is either take a Configuration object, or just remove it (since there is another constructor that takes tenantId subscriptionId azureEnvironment).

I will adjust this when finalized.

TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand All @@ -90,6 +90,9 @@ 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.
- Integration with Azure role-based access control.
- Asynchronous operations with [Reactor][reactor].
- Configurable client, e.g. configuring HTTP client, retries, logging, etc.

Expand All @@ -108,7 +111,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")
Expand All @@ -132,12 +135,78 @@ 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<StorageAccount> creatableStorageAccount = azure.storageAccounts()
.define(storageAccountName)
.withRegion(Region.US_EAST)
.withExistingResourceGroup(rgName)
.withGeneralPurposeAccountKindV2()
.withSku(StorageAccountSkuType.STANDARD_LRS);

Creatable<AppServicePlan> 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", functionAppPackageUrl)
.create();
```

### Batch Azure resource provisioning

You can batch create and delete managed disk instances.

```java
List<String> diskNames = Arrays.asList("datadisk1", "datadisk2");

List<Creatable<Disk>> 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<Disk> 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();
```

Comment on lines +190 to +203
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a section on RBAC. Probably this is the only lib in java than can do this...

### Asynchronous operations

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)
Expand All @@ -151,7 +220,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
Expand Down