Skip to content

Commit 911f7f1

Browse files
authored
Bump resourcemanagerhybrid versions to 1.0.0-hybrid and improve READMEs (Azure#26063)
* Update readmes to add more info on hybrid packages * Update version to 1.0.0-hybrid * Remove locales from README links * Use codesnippet-maven-plugin for codesnippets * Update single service package section * Prioritize documenting auth to hub instead of azure * Remove DocsTest
1 parent 75a7135 commit 911f7f1

File tree

61 files changed

+1721
-1082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1721
-1082
lines changed

sdk/resourcemanagerhybrid/README.md

Lines changed: 68 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Azure management client library for Java (Hybrid)
22

3-
The Azure Management Libraries for Java (Hybrid) is a higher-level, object-oriented API for *managing* Azure resources,
4-
that is optimized for ease of use, succinctness and consistency.
3+
The Azure Management Libraries for Java (Hybrid) is a higher-level, object-oriented API for *managing* Azure and Azure Stack Hub resources,
4+
that is optimized for ease of use, succinctness and consistency. It uses [API Profiles][api_profile] to allow building hybrid cloud solutions
5+
that target both Azure and Azure Stack Hub.
56

67
## We'd love to hear your feedback
78

@@ -31,22 +32,17 @@ If you are an existing user of the older version of Azure management library for
3132

3233
### Include the package
3334

34-
For your convenience, we have provided a multi-service package that includes some of the most highly used Azure services. We recommend using this package when you are dealing with mutiple services.
35+
For you convenience, we have provided a multi-service package that includes services shared between Azure and Azure Stack Hub through a common API Profile. We recommend using this package when you are dealing with multiple services.
3536

36-
[//]: # ({x-version-update-start;com.azure.resourcemanager:azure-resourcemanager;current})
3737
```xml
3838
<dependency>
3939
<groupId>com.azure.resourcemanager</groupId>
4040
<artifactId>azure-resourcemanager</artifactId>
4141
<version>1.0.0-hybrid</version>
4242
</dependency>
4343
```
44-
[//]: # ({x-version-update-end})
45-
46-
The services available via `azure-resourcemanager` are listed as below:
4744

48-
<details>
49-
<summary> List of services </summary>
45+
The services available are listed as below:
5046

5147
- App Services
5248
- Authorization
@@ -60,21 +56,21 @@ The services available via `azure-resourcemanager` are listed as below:
6056
- Network
6157
- Resources
6258
- Storage
63-
</details>
6459

65-
In the case where you are interested in certain service above or the service not included in the multi-service package, you can choose to use the single-service package for each service. Those packages follow the same naming patterns and design principals. For example, the package for Media Services has the following artifact information.
60+
If you are only interested in using a subset of the services above, you can choose to use single-package services. These
61+
packages follow the same naming patterns and design principals. For example, the Compute package can be used directly
62+
with the following artifact information:
6663

67-
[//]: # ({x-version-update-start;com.azure.resourcemanager:azure-resourcemanager-mediaservices;dependency})
6864
```xml
6965
<dependency>
7066
<groupId>com.azure.resourcemanager</groupId>
71-
<artifactId>azure-resourcemanager-mediaservices</artifactId>
72-
<version>1.0.0</version>
67+
<artifactId>azure-resourcemanager-compute</artifactId>
68+
<version>1.0.0-hybrid</version>
7369
</dependency>
7470
```
75-
[//]: # ({x-version-update-end})
7671

77-
See [Single-Service Packages][single_service_packages] for a complete list of single-services packages with the API versions they are consuming.
72+
Note that some features included in service packages may not be available on Azure Stack Hub. For example, see
73+
[Azure Stack Hub VM Considerations][vm_considerations] for a list of difference between Compute on Azure and Azure Stack Hub.
7874

7975
### Include the recommended packages
8076

@@ -120,9 +116,9 @@ In addition, Azure subscription ID can be configured via environment variable `A
120116

121117
With above configuration, the manager class can be authenticated by following code:
122118

123-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L62-L68 -->
124-
```java
125-
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
119+
```java com.azure.resourcemanager.authenticate
120+
String armEndpoint = "https://management.<region>.<your-domain>";
121+
AzureProfile profile = new AzureProfile(getAzureEnvironmentFromArmEndpoint(armEndpoint));
126122
TokenCredential credential = new DefaultAzureCredentialBuilder()
127123
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
128124
.build();
@@ -131,7 +127,54 @@ AzureResourceManager azure = AzureResourceManager
131127
.withDefaultSubscription();
132128
```
133129

134-
The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.
130+
Change `armEndpoint` to point to the Azure Resource Manager endpoint of your Azure Stack Hub. The azure environment's
131+
properties above can be populated with the following example:
132+
133+
```java com.azure.resourcemanager.getazureenvironment
134+
private static AzureEnvironment getAzureEnvironmentFromArmEndpoint(String armEndpoint) {
135+
// Create HTTP client and request
136+
HttpClient httpClient = HttpClient.createDefault();
137+
138+
HttpRequest request = new HttpRequest(HttpMethod.GET,
139+
String.format("%s/metadata/endpoints?api-version=2019-10-01", armEndpoint))
140+
.setHeader("accept", "application/json");
141+
142+
// Execute the request and read the response
143+
HttpResponse response = httpClient.send(request).block();
144+
if (response.getStatusCode() != 200) {
145+
throw new RuntimeException("Failed : HTTP error code : " + response.getStatusCode());
146+
}
147+
String body = response.getBodyAsString().block();
148+
try {
149+
ArrayNode metadataArray = JacksonAdapter.createDefaultSerializerAdapter()
150+
.deserialize(body, ArrayNode.class, SerializerEncoding.JSON);
151+
152+
if (metadataArray == null || metadataArray.isEmpty()) {
153+
throw new RuntimeException("Failed to find metadata : " + body);
154+
}
155+
156+
JsonNode metadata = metadataArray.iterator().next();
157+
AzureEnvironment azureEnvironment = new AzureEnvironment(new HashMap<String, String>() {
158+
{
159+
put("managementEndpointUrl", metadata.at("/authentication/audiences/0").asText());
160+
put("resourceManagerEndpointUrl", armEndpoint);
161+
put("galleryEndpointUrl", metadata.at("/gallery").asText());
162+
put("activeDirectoryEndpointUrl", metadata.at("/authentication/loginEndpoint").asText());
163+
put("activeDirectoryResourceId", metadata.at("/authentication/audiences/0").asText());
164+
put("activeDirectoryGraphResourceId", metadata.at("/graph").asText());
165+
put("storageEndpointSuffix", "." + metadata.at("/suffixes/storage").asText());
166+
put("keyVaultDnsSuffix", "." + metadata.at("/suffixes/keyVaultDns").asText());
167+
}
168+
});
169+
return azureEnvironment;
170+
} catch (IOException ioe) {
171+
ioe.printStackTrace();
172+
throw new RuntimeException(ioe);
173+
}
174+
}
175+
```
176+
177+
When targeting a hybrid solution to global Azure instead of your Azure Stack Hub, `AzureEnvironment.AZURE` can be used instead.
135178

136179
See [Authentication][authenticate] for more options.
137180

@@ -154,165 +197,7 @@ The key concepts of Azure Management Libraries includes:
154197

155198
## Examples
156199

157-
### Fluent interface
158-
159-
You can create a virtual machine instance, together with required virtual network and ip address created automatically.
160-
161-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L95-L105 -->
162-
```java
163-
VirtualMachine linuxVM = azure.virtualMachines().define("myLinuxVM")
164-
.withRegion(Region.US_EAST)
165-
.withNewResourceGroup(rgName)
166-
.withNewPrimaryNetwork("10.0.0.0/28")
167-
.withPrimaryPrivateIPAddressDynamic()
168-
.withoutPrimaryPublicIPAddress()
169-
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS)
170-
.withRootUsername("<username>")
171-
.withSsh("<ssh-key>")
172-
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
173-
.create();
174-
```
175-
176-
Update.
177-
178-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L107-L109 -->
179-
```java
180-
linuxVM.update()
181-
.withNewDataDisk(10, 0, CachingTypes.READ_WRITE)
182-
.apply();
183-
```
184-
185-
### Dependency across Azure resources
186-
187-
You can create a function app, together with required storage account and app service plan created on specification.
188-
189-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L115-L135 -->
190-
```java
191-
Creatable<StorageAccount> creatableStorageAccount = azure.storageAccounts()
192-
.define("<storage-account-name>")
193-
.withRegion(Region.US_EAST)
194-
.withExistingResourceGroup(rgName)
195-
.withGeneralPurposeAccountKindV2()
196-
.withSku(StorageAccountSkuType.STANDARD_LRS);
197-
Creatable<AppServicePlan> creatableAppServicePlan = azure.appServicePlans()
198-
.define("<app-service-plan-name>")
199-
.withRegion(Region.US_EAST)
200-
.withExistingResourceGroup(rgName)
201-
.withPricingTier(PricingTier.STANDARD_S1)
202-
.withOperatingSystem(OperatingSystem.LINUX);
203-
FunctionApp linuxFunctionApp = azure.functionApps().define("<function-app-name>")
204-
.withRegion(Region.US_EAST)
205-
.withExistingResourceGroup(rgName)
206-
.withNewLinuxAppServicePlan(creatableAppServicePlan)
207-
.withBuiltInImage(FunctionRuntimeStack.JAVA_8)
208-
.withNewStorageAccount(creatableStorageAccount)
209-
.withHttpsOnly(true)
210-
.withAppSetting("WEBSITE_RUN_FROM_PACKAGE", "<function-app-package-url>")
211-
.create();
212-
```
213-
214-
### Batch Azure resource provisioning
215-
216-
You can batch create and delete managed disk instances.
217-
218-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L141-L152 -->
219-
```java
220-
List<String> diskNames = Arrays.asList("datadisk1", "datadisk2");
221-
List<Creatable<Disk>> creatableDisks = diskNames.stream()
222-
.map(diskName -> azure.disks()
223-
.define(diskName)
224-
.withRegion(Region.US_EAST)
225-
.withExistingResourceGroup(rgName)
226-
.withData()
227-
.withSizeInGB(10)
228-
.withSku(DiskSkuTypes.STANDARD_LRS))
229-
.collect(Collectors.toList());
230-
Collection<Disk> disks = azure.disks().create(creatableDisks).values();
231-
azure.disks().deleteByIds(disks.stream().map(Disk::id).collect(Collectors.toList()));
232-
```
233-
234-
### Integration with Azure role-based access control
235-
236-
You can assign Contributor for an Azure resource to a service principal.
237-
238-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L160-L166 -->
239-
```java
240-
String raName = UUID.randomUUID().toString();
241-
RoleAssignment roleAssignment = azure.accessManagement().roleAssignments()
242-
.define(raName)
243-
.forServicePrincipal(servicePrincipal)
244-
.withBuiltInRole(BuiltInRole.CONTRIBUTOR)
245-
.withScope(resource.id())
246-
.create();
247-
```
248-
249-
### Asynchronous operations (Preview)
250-
251-
You can create storage account, then blob container, in reactive programming.
252-
253-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L172-L185 -->
254-
```java
255-
azure.storageAccounts().define("<storage-account-name>")
256-
.withRegion(Region.US_EAST)
257-
.withNewResourceGroup(rgName)
258-
.withSku(StorageAccountSkuType.STANDARD_LRS)
259-
.withGeneralPurposeAccountKindV2()
260-
.withOnlyHttpsTraffic()
261-
.createAsync()
262-
.flatMap(storageAccount -> azure.storageBlobContainers()
263-
.defineContainer("container")
264-
.withExistingStorageAccount(storageAccount)
265-
.withPublicAccess(PublicAccess.NONE)
266-
.createAsync()
267-
)
268-
//...
269-
```
270-
271-
You can operate on virtual machines in parallel.
272-
273-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L192-L194 -->
274-
```java
275-
azure.virtualMachines().listByResourceGroupAsync(rgName)
276-
.flatMap(VirtualMachine::restartAsync)
277-
//...
278-
```
279-
280-
### Configurable client
281-
282-
You can customize various aspects of the client and pipeline.
283-
284-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L206-L210 -->
285-
```java
286-
AzureResourceManager azure = AzureResourceManager
287-
.configure()
288-
.withHttpClient(customizedHttpClient)
289-
.withPolicy(additionalPolicy)
290-
//...
291-
```
292-
293-
### Include single package
294-
295-
Instead of include the complete Azure Management Libraries, you can choose to include a single service package.
296-
297-
For example, here is sample maven dependency for Compute package.
298-
299-
[//]: # ({x-version-update-start;com.azure.resourcemanager:azure-resourcemanager-compute;current})
300-
```xml
301-
<dependency>
302-
<groupId>com.azure.resourcemanager</groupId>
303-
<artifactId>azure-resourcemanager-compute</artifactId>
304-
<version>2.7.0</version>
305-
</dependency>
306-
```
307-
[//]: # ({x-version-update-end})
308-
309-
Sample code to create the authenticated client.
310-
311-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L88-L89 -->
312-
```java
313-
ComputeManager manager = ComputeManager.authenticate(credential, profile);
314-
manager.virtualMachines().list();
315-
```
200+
See [Azure management client library for Java (Azure)][resourcemanager_azure] for examples on Azure.
316201

317202
## Troubleshooting
318203

@@ -335,8 +220,7 @@ locate the root issue. View the [logging][logging] wiki for guidance about enabl
335220

336221
Sample code to enable logging in Azure Management Libraries.
337222

338-
<!-- embedme ./azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java#L76-L80 -->
339-
```java
223+
```java com.azure.resourcemanager.logging
340224
AzureResourceManager azure = AzureResourceManager
341225
.configure()
342226
.withLogLevel(HttpLogDetailLevel.BASIC)
@@ -447,11 +331,13 @@ For details on contributing to this repository, see the [contributing guide](htt
447331
[azure_core_http_okhttp]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/core/azure-core-http-okhttp
448332
[azure_core]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/core/azure-core
449333
[logging]: https://github.com/Azure/azure-sdk-for-java/wiki/Logging-with-Azure-SDK
450-
[single_service_packages]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/SINGLE_SERVICE_PACKAGES.md
451334
[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/AUTH.md
452335
[sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/SAMPLE.md
453336
[design]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/DESIGN.md
454337
[design_preview]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/DESIGN_PREVIEW.md
455338
[throttling]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/THROTTLING.md
456339
[reactor]: https://projectreactor.io/
457340
[rbac]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/RBAC.md
341+
[api_profile]: https://docs.microsoft.com/azure-stack/user/azure-stack-version-profiles
342+
[vm_considerations]: https://docs.microsoft.com/azure-stack/user/azure-stack-vm-considerations
343+
[resourcemanager_azure]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/README.md
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# Release History
22

3-
## 1.0.0-hybridbeta.1 (Unreleased)
3+
## 1.0.0-hybrid (2021-12-16)
4+
5+
- Azure Resource Manager App Service client library for Java (Hybrid) using API Profiles to allow building hybrid cloud solutions
6+
that target both Azure and Azure Stack Hub.

0 commit comments

Comments
 (0)