Skip to content

Commit

Permalink
Release azure-resourcemanager 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-Fluent committed Oct 26, 2020
1 parent 1993f40 commit 9770a6a
Show file tree
Hide file tree
Showing 4 changed files with 1,662 additions and 1,420 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extensions:

To run this sample:

Set the environment variable `AZURE_AUTH_LOCATION` with the full path for an auth file. See [how to create an auth file](https://github.com/Azure/azure-libraries-for-java/blob/master/AUTH.md).
See [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/identity/azure-identity#defaultazurecredential) and prepare the authentication works best for you. For more details on authentication, please refer to [AUTH.md](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md).

git clone https://github.com/Azure-Samples/app-service-java-manage-web-apps.git

Expand All @@ -35,9 +35,11 @@ Set the environment variable `AZURE_AUTH_LOCATION` with the full path for an aut

## More information ##

[http://azure.com/java](http://azure.com/java)
For general documentation as well as quickstarts on how to use Azure Management Libraries for Java, please see [here](https://aka.ms/azsdk/java/mgmt).

If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212)
Start to develop applications with Java on Azure [here](http://azure.com/java).

If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212).

---

Expand Down
34 changes: 15 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<mainClass>com.microsoft.azure.management.appservice.samples.ManageWebAppBasic</mainClass>
<mainClass>com.azure.resourcemanager.appservice.samples.ManageWebAppBasic</mainClass>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<version>3.8.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -40,7 +41,7 @@
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.management.appservice.samples.ManageWebAppBasic.java</mainClass>
<mainClass>com.azure.resourcemanager.appservice.samples.ManageWebAppBasic.java</mainClass>
</manifest>
</archive>
</configuration>
Expand All @@ -51,24 +52,19 @@
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.36.3</version>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.management.appservice.samples;

import com.microsoft.azure.management.Azure;
import com.microsoft.azure.management.appservice.AppServicePlan;
import com.microsoft.azure.management.appservice.PricingTier;
import com.microsoft.azure.management.appservice.JavaVersion;
import com.microsoft.azure.management.appservice.WebApp;
import com.microsoft.azure.management.appservice.WebContainer;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
import com.microsoft.azure.management.samples.Utils;
import com.microsoft.rest.LogLevel;

import java.io.File;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.appservice.samples;

import com.azure.core.credential.TokenCredential;
import com.azure.core.management.AzureEnvironment;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.appservice.models.AppServicePlan;
import com.azure.resourcemanager.appservice.models.JavaVersion;
import com.azure.resourcemanager.appservice.models.PricingTier;
import com.azure.resourcemanager.appservice.models.WebApp;
import com.azure.resourcemanager.appservice.models.WebAppBasic;
import com.azure.resourcemanager.appservice.models.WebContainer;
import com.azure.core.management.Region;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.samples.Utils;
import com.azure.core.http.policy.HttpLogDetailLevel;

/**
* Azure App Service basic sample for managing web apps.
Expand All @@ -32,16 +31,16 @@ public final class ManageWebAppBasic {

/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @param azureResourceManager instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
public static boolean runSample(AzureResourceManager azureResourceManager) {
// New resources
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
final String app3Name = SdkContext.randomResourceName("webapp3-", 20);
final String rg1Name = SdkContext.randomResourceName("rg1NEMV_", 24);
final String rg2Name = SdkContext.randomResourceName("rg2NEMV_", 24);
final String app1Name = Utils.randomResourceName(azureResourceManager, "webapp1-", 20);
final String app2Name = Utils.randomResourceName(azureResourceManager, "webapp2-", 20);
final String app3Name = Utils.randomResourceName(azureResourceManager, "webapp3-", 20);
final String rg1Name = Utils.randomResourceName(azureResourceManager, "rg1NEMV_", 24);
final String rg2Name = Utils.randomResourceName(azureResourceManager, "rg2NEMV_", 24);

try {

Expand All @@ -51,7 +50,7 @@ public static boolean runSample(Azure azure) {

System.out.println("Creating web app " + app1Name + " in resource group " + rg1Name + "...");

WebApp app1 = azure.webApps()
WebApp app1 = azureResourceManager.webApps()
.define(app1Name)
.withRegion(Region.US_WEST)
.withNewResourceGroup(rg1Name)
Expand All @@ -65,8 +64,8 @@ public static boolean runSample(Azure azure) {
// Create a second web app with the same app service plan

System.out.println("Creating another web app " + app2Name + " in resource group " + rg1Name + "...");
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
WebApp app2 = azure.webApps()
AppServicePlan plan = azureResourceManager.appServicePlans().getById(app1.appServicePlanId());
WebApp app2 = azureResourceManager.webApps()
.define(app2Name)
.withExistingWindowsPlan(plan)
.withExistingResourceGroup(rg1Name)
Expand All @@ -80,7 +79,7 @@ public static boolean runSample(Azure azure) {
// in a different resource group

System.out.println("Creating another web app " + app3Name + " in resource group " + rg2Name + "...");
WebApp app3 = azure.webApps()
WebApp app3 = azureResourceManager.webApps()
.define(app3Name)
.withExistingWindowsPlan(plan)
.withNewResourceGroup(rg2Name)
Expand Down Expand Up @@ -118,46 +117,42 @@ public static boolean runSample(Azure azure) {

System.out.println("Printing list of web apps in resource group " + rg1Name + "...");

for (WebApp webApp : azure.webApps().listByResourceGroup(rg1Name)) {
for (WebAppBasic webApp : azureResourceManager.webApps().listByResourceGroup(rg1Name)) {
Utils.print(webApp);
}

System.out.println("Printing list of web apps in resource group " + rg2Name + "...");

for (WebApp webApp : azure.webApps().listByResourceGroup(rg2Name)) {
for (WebAppBasic webApp : azureResourceManager.webApps().listByResourceGroup(rg2Name)) {
Utils.print(webApp);
}

//=============================================================
// Delete a web app

System.out.println("Deleting web app " + app1Name + "...");
azure.webApps().deleteByResourceGroup(rg1Name, app1Name);
azureResourceManager.webApps().deleteByResourceGroup(rg1Name, app1Name);
System.out.println("Deleted web app " + app1Name + "...");

System.out.println("Printing list of web apps in resource group " + rg1Name + " again...");
for (WebApp webApp : azure.webApps().listByResourceGroup(rg1Name)) {
for (WebAppBasic webApp : azureResourceManager.webApps().listByResourceGroup(rg1Name)) {
Utils.print(webApp);
}
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rg1Name);
azure.resourceGroups().beginDeleteByName(rg1Name);
azureResourceManager.resourceGroups().beginDeleteByName(rg1Name);
System.out.println("Deleted Resource Group: " + rg1Name);
System.out.println("Deleting Resource Group: " + rg2Name);
azure.resourceGroups().beginDeleteByName(rg2Name);
azureResourceManager.resourceGroups().beginDeleteByName(rg2Name);
System.out.println("Deleted Resource Group: " + rg2Name);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}

/**
Expand All @@ -170,17 +165,20 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.build();

Azure azure = Azure
.configure()
.withLogLevel(LogLevel.BODY_AND_HEADERS)
.authenticate(credFile)
.withDefaultSubscription();
AzureResourceManager azureResourceManager = AzureResourceManager
.configure()
.withLogLevel(HttpLogDetailLevel.BASIC)
.authenticate(credential, profile)
.withDefaultSubscription();

// Print selected subscription
System.out.println("Selected subscription: " + azure.subscriptionId());
runSample(azure);
System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
runSample(azureResourceManager);

} catch (Exception e) {
System.out.println(e.getMessage());
Expand Down
Loading

0 comments on commit 9770a6a

Please sign in to comment.