Skip to content

Commit

Permalink
Mgmt: Azure -> AzureResourceManager (#15409)
Browse files Browse the repository at this point in the history
* Azure -> AzureResourceManager

* fix checkstyle

* update link

* update link
  • Loading branch information
ChenTanyi authored Sep 21, 2020
1 parent ec0875b commit 87f8e3f
Show file tree
Hide file tree
Showing 164 changed files with 2,427 additions and 2,425 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.core.management.AzureEnvironment;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.Azure;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.appplatform.models.SpringApp;
import com.azure.resourcemanager.appplatform.models.SpringService;
import com.azure.resourcemanager.appservice.models.AppServiceCertificateOrder;
Expand Down Expand Up @@ -66,22 +66,22 @@ public class ManageSpringCloud {

/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @param azureResourceManager instance of the azure client
* @param clientId the aad client id in azure instance
* @return true if sample runs successfully
* @throws IllegalStateException unexcepted state
*/
public static boolean runSample(Azure azure, String clientId) throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
final String rgName = azure.sdkContext().randomResourceName("rg", 24);
final String serviceName = azure.sdkContext().randomResourceName("service", 24);
public static boolean runSample(AzureResourceManager azureResourceManager, String clientId) throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
final String rgName = azureResourceManager.sdkContext().randomResourceName("rg", 24);
final String serviceName = azureResourceManager.sdkContext().randomResourceName("service", 24);
final Region region = Region.US_EAST;
final String domainName = azure.sdkContext().randomResourceName("jsdkdemo-", 20) + ".com";
final String certOrderName = azure.sdkContext().randomResourceName("cert", 15);
final String vaultName = azure.sdkContext().randomResourceName("vault", 15);
final String certName = azure.sdkContext().randomResourceName("cert", 15);
final String domainName = azureResourceManager.sdkContext().randomResourceName("jsdkdemo-", 20) + ".com";
final String certOrderName = azureResourceManager.sdkContext().randomResourceName("cert", 15);
final String vaultName = azureResourceManager.sdkContext().randomResourceName("vault", 15);
final String certName = azureResourceManager.sdkContext().randomResourceName("cert", 15);

try {
azure.resourceGroups().define(rgName)
azureResourceManager.resourceGroups().define(rgName)
.withRegion(region)
.create();

Expand All @@ -90,7 +90,7 @@ public static boolean runSample(Azure azure, String clientId) throws IOException

System.out.printf("Creating spring cloud service %s in resource group %s ...%n", serviceName, rgName);

SpringService service = azure.springServices().define(serviceName)
SpringService service = azureResourceManager.springServices().define(serviceName)
.withRegion(region)
.withExistingResourceGroup(rgName)
.create();
Expand Down Expand Up @@ -159,7 +159,7 @@ public static boolean runSample(Azure azure, String clientId) throws IOException

System.out.println("Purchasing a domain " + domainName + "...");

AppServiceDomain domain = azure.appServiceDomains().define(domainName)
AppServiceDomain domain = azureResourceManager.appServiceDomains().define(domainName)
.withExistingResourceGroup(rgName)
.defineRegistrantContact()
.withFirstName("Jon")
Expand All @@ -179,7 +179,7 @@ public static boolean runSample(Azure azure, String clientId) throws IOException
System.out.println("Purchased domain " + domain.name());
Utils.print(domain);

DnsZone dnsZone = azure.dnsZones().getById(domain.dnsZoneId());
DnsZone dnsZone = azureResourceManager.dnsZones().getById(domain.dnsZoneId());
gateway.refresh();

System.out.printf("Updating dns with CNAME ssl.%s to %s%n", domainName, gateway.fqdn());
Expand All @@ -188,7 +188,7 @@ public static boolean runSample(Azure azure, String clientId) throws IOException
.apply();

System.out.printf("Purchasing a certificate for *.%s and save to %s in key vault named %s ...%n", domainName, certOrderName, vaultName);
AppServiceCertificateOrder certificateOrder = azure.appServiceCertificateOrders().define(certOrderName)
AppServiceCertificateOrder certificateOrder = azureResourceManager.appServiceCertificateOrders().define(certOrderName)
.withExistingResourceGroup(rgName)
.withHostName(String.format("*.%s", domainName))
.withWildcardSku()
Expand All @@ -200,7 +200,7 @@ public static boolean runSample(Azure azure, String clientId) throws IOException
Utils.print(certificateOrder);

System.out.printf("Updating key vault %s with access from %s, %s%n", vaultName, clientId, SPRING_CLOUD_SERVICE_PRINCIPAL);
Vault vault = azure.vaults().getByResourceGroup(rgName, vaultName);
Vault vault = azureResourceManager.vaults().getByResourceGroup(rgName, vaultName);
vault.update()
.defineAccessPolicy()
.forServicePrincipal(clientId)
Expand Down Expand Up @@ -261,7 +261,7 @@ public static boolean runSample(Azure azure, String clientId) throws IOException
} finally {
try {
System.out.println("Delete Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
Expand All @@ -284,16 +284,16 @@ public static void main(String[] args) {
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.build();

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

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

runSample(azure, Configuration.getGlobalConfiguration().get(Configuration.PROPERTY_AZURE_CLIENT_ID));
runSample(azureResourceManager, Configuration.getGlobalConfiguration().get(Configuration.PROPERTY_AZURE_CLIENT_ID));
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.management.AzureEnvironment;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.Azure;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.appservice.models.AppServicePlan;
import com.azure.resourcemanager.appservice.models.FunctionApp;
import com.azure.resourcemanager.appservice.models.FunctionAppBasic;
Expand All @@ -28,16 +28,16 @@ public final class ManageFunctionAppBasic {

/**
* 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 = azure.sdkContext().randomResourceName("webapp1-", 20);
final String app2Name = azure.sdkContext().randomResourceName("webapp2-", 20);
final String app3Name = azure.sdkContext().randomResourceName("webapp3-", 20);
final String rg1Name = azure.sdkContext().randomResourceName("rg1NEMV_", 24);
final String rg2Name = azure.sdkContext().randomResourceName("rg2NEMV_", 24);
final String app1Name = azureResourceManager.sdkContext().randomResourceName("webapp1-", 20);
final String app2Name = azureResourceManager.sdkContext().randomResourceName("webapp2-", 20);
final String app3Name = azureResourceManager.sdkContext().randomResourceName("webapp3-", 20);
final String rg1Name = azureResourceManager.sdkContext().randomResourceName("rg1NEMV_", 24);
final String rg2Name = azureResourceManager.sdkContext().randomResourceName("rg2NEMV_", 24);

try {

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

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

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

System.out.println("Creating another function app " + app2Name + " in resource group " + rg1Name + "...");
AppServicePlan plan = azure.appServicePlans().getById(app1.appServicePlanId());
FunctionApp app2 = azure.functionApps()
AppServicePlan plan = azureResourceManager.appServicePlans().getById(app1.appServicePlanId());
FunctionApp app2 = azureResourceManager.functionApps()
.define(app2Name)
.withRegion(Region.US_WEST)
.withExistingResourceGroup(rg1Name)
Expand All @@ -76,7 +76,7 @@ public static boolean runSample(Azure azure) {
// in a different resource group

System.out.println("Creating another function app " + app3Name + " in resource group " + rg2Name + "...");
FunctionApp app3 = azure.functionApps()
FunctionApp app3 = azureResourceManager.functionApps()
.define(app3Name)
.withExistingAppServicePlan(plan)
.withNewResourceGroup(rg2Name)
Expand Down Expand Up @@ -105,35 +105,35 @@ public static boolean runSample(Azure azure) {

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

for (FunctionAppBasic functionApp : azure.functionApps().listByResourceGroup(rg1Name)) {
for (FunctionAppBasic functionApp : azureResourceManager.functionApps().listByResourceGroup(rg1Name)) {
Utils.print(functionApp);
}

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

for (FunctionAppBasic functionApp : azure.functionApps().listByResourceGroup(rg2Name)) {
for (FunctionAppBasic functionApp : azureResourceManager.functionApps().listByResourceGroup(rg2Name)) {
Utils.print(functionApp);
}

//=============================================================
// Delete a function app

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

System.out.println("Printing list of function apps in resource group " + rg1Name + " again...");
for (FunctionAppBasic functionApp : azure.functionApps().listByResourceGroup(rg1Name)) {
for (FunctionAppBasic functionApp : azureResourceManager.functionApps().listByResourceGroup(rg1Name)) {
Utils.print(functionApp);
}
return true;
} 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");
Expand All @@ -158,15 +158,15 @@ public static void main(String[] args) {
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.build();

Azure azure = Azure
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.management.AzureEnvironment;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.Azure;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.appservice.models.FunctionApp;
import com.azure.resourcemanager.appservice.models.LogLevel;
import com.azure.resourcemanager.resources.fluentcore.arm.Region;
Expand All @@ -34,15 +34,15 @@ public final class ManageFunctionAppLogs {

/**
* 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) throws IOException {
public static boolean runSample(AzureResourceManager azureResourceManager) throws IOException {
// New resources
final String suffix = ".azurewebsites.net";
final String appName = azure.sdkContext().randomResourceName("webapp1-", 20);
final String appName = azureResourceManager.sdkContext().randomResourceName("webapp1-", 20);
final String appUrl = appName + suffix;
final String rgName = azure.sdkContext().randomResourceName("rg1NEMV_", 24);
final String rgName = azureResourceManager.sdkContext().randomResourceName("rg1NEMV_", 24);

try {

Expand All @@ -52,7 +52,7 @@ public static boolean runSample(Azure azure) throws IOException {

System.out.println("Creating function app " + appName + " in resource group " + rgName + "...");

FunctionApp app = azure.functionApps().define(appName)
FunctionApp app = azureResourceManager.functionApps().define(appName)
.withRegion(Region.US_WEST)
.withNewResourceGroup(rgName)
.defineDiagnosticLogsConfiguration()
Expand Down Expand Up @@ -143,7 +143,7 @@ protected void hookOnError(Throwable throwable) {
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
azureResourceManager.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
Expand All @@ -167,16 +167,16 @@ public static void main(String[] args) {
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.build();

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

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

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

0 comments on commit 87f8e3f

Please sign in to comment.