diff --git a/sdk/management/samples/src/main/java/com/azure/management/appservice/samples/ManageLinuxWebAppWithTrafficManager.java b/sdk/management/samples/src/main/java/com/azure/management/appservice/samples/ManageLinuxWebAppWithTrafficManager.java index af9bd314d93f..febb456be14d 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/appservice/samples/ManageLinuxWebAppWithTrafficManager.java +++ b/sdk/management/samples/src/main/java/com/azure/management/appservice/samples/ManageLinuxWebAppWithTrafficManager.java @@ -1,45 +1,45 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. - -package com.azure.management.appservice.samples; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.management.AzureEnvironment; -import com.azure.identity.DefaultAzureCredentialBuilder; -import com.azure.management.Azure; -import com.azure.management.resources.fluentcore.profile.AzureProfile; - +// +//package com.azure.management.appservice.samples; +// +//import com.azure.core.credential.TokenCredential; +//import com.azure.core.http.policy.HttpLogDetailLevel; +//import com.azure.core.management.AzureEnvironment; +//import com.azure.identity.DefaultAzureCredentialBuilder; +//import com.azure.management.Azure; +//import com.azure.management.resources.fluentcore.profile.AzureProfile; +// //import com.azure.management.trafficmanager.TrafficManagerProfile; //import com.azure.management.trafficmanager.TrafficRoutingMethod; - - -/** - * Azure App Service sample for managing web apps. - * - Create a domain - * - Create a self-signed certificate for the domain - * - Create 3 app service plans in 3 different regions - * - Create 5 web apps under the 3 plans, bound to the domain and the certificate - * - Create a traffic manager in front of the web apps - * - Scale up the app service plans to twice the capacity - */ -public final class ManageLinuxWebAppWithTrafficManager { +// +// +///** +// * Azure App Service sample for managing web apps. +// * - Create a domain +// * - Create a self-signed certificate for the domain +// * - Create 3 app service plans in 3 different regions +// * - Create 5 web apps under the 3 plans, bound to the domain and the certificate +// * - Create a traffic manager in front of the web apps +// * - Scale up the app service plans to twice the capacity +// */ +//public final class ManageLinuxWebAppWithTrafficManager { // private static String rgName; - // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")] - private static final String CERT_PASSWORD = "StrongPass!12"; - - private static Azure azure; +// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")] +// private static final String CERT_PASSWORD = "StrongPass!12"; +// +// private static Azure azure; // private static AppServiceDomain domain; // private static String pfxPath; - /** - * Main function which runs the actual sample. - * @param azure instance of the azure client - * @return true if sample runs successfully - */ - public static boolean runSample(Azure azure) { - System.out.println("removed later"); - return true; +// /** +// * Main function which runs the actual sample. +// * @param azure instance of the azure client +// * @return true if sample runs successfully +// */ +// public static boolean runSample(Azure azure) { +// System.out.println("removed later"); +// return true; // RG_NAME = azure.sdkContext().randomResourceName("rgNEMV_", 24); // // if (ManageLinuxWebAppWithTrafficManager.azure == null) { @@ -230,38 +230,7 @@ public static boolean runSample(Azure azure) { // } // // return false; - } - /** - * Main entry point. - * @param args the parameters - */ - public static void main(String[] args) { - try { - - //============================================================= - // Authenticate - - final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true); - final TokenCredential credential = new DefaultAzureCredentialBuilder() - .authorityHost(profile.environment().getActiveDirectoryEndpoint()) - .build(); - - Azure azure = Azure - .configure() - .withLogLevel(HttpLogDetailLevel.BASIC) - .authenticate(credential, profile) - .withDefaultSubscription(); - - // Print selected subscription - System.out.println("Selected subscription: " + azure.subscriptionId()); - - runSample(azure); - } catch (Exception e) { - System.out.println(e.getMessage()); - e.printStackTrace(); - } - } - +// // private static AppServicePlan createAppServicePlan(String name, Region region) { // return azure.appServicePlans().define(name) // .withRegion(region) @@ -288,4 +257,4 @@ public static void main(String[] args) { // .attach() // .create(); // } -} +//} diff --git a/sdk/management/samples/src/main/java/com/azure/management/appservice/samples/ManageWebAppWithTrafficManager.java b/sdk/management/samples/src/main/java/com/azure/management/appservice/samples/ManageWebAppWithTrafficManager.java index 560c03d0e6a2..58d97c58bcdb 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/appservice/samples/ManageWebAppWithTrafficManager.java +++ b/sdk/management/samples/src/main/java/com/azure/management/appservice/samples/ManageWebAppWithTrafficManager.java @@ -1,45 +1,45 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. - -package com.azure.management.appservice.samples; - -import com.azure.core.credential.TokenCredential; -import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.management.AzureEnvironment; -import com.azure.identity.DefaultAzureCredentialBuilder; -import com.azure.management.Azure; -import com.azure.management.resources.fluentcore.profile.AzureProfile; - +// +//package com.azure.management.appservice.samples; +// +//import com.azure.core.credential.TokenCredential; +//import com.azure.core.http.policy.HttpLogDetailLevel; +//import com.azure.core.management.AzureEnvironment; +//import com.azure.identity.DefaultAzureCredentialBuilder; +//import com.azure.management.Azure; +//import com.azure.management.resources.fluentcore.profile.AzureProfile; +// //import com.azure.management.trafficmanager.TrafficManagerProfile; //import com.azure.management.trafficmanager.TrafficRoutingMethod; - - -/** - * Azure App Service sample for managing web apps. - * - Create a domain - * - Create a self-signed certificate for the domain - * - Create 3 app service plans in 3 different regions - * - Create 5 web apps under the 3 plans, bound to the domain and the certificate - * - Create a traffic manager in front of the web apps - * - Scale up the app service plans to twice the capacity - */ -public final class ManageWebAppWithTrafficManager { +// +// +///** +// * Azure App Service sample for managing web apps. +// * - Create a domain +// * - Create a self-signed certificate for the domain +// * - Create 3 app service plans in 3 different regions +// * - Create 5 web apps under the 3 plans, bound to the domain and the certificate +// * - Create a traffic manager in front of the web apps +// * - Scale up the app service plans to twice the capacity +// */ +//public final class ManageWebAppWithTrafficManager { // private static String rgName; - // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")] - private static final String CERT_PASSWORD = "StrongPass!12"; - - private static Azure azure; +// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")] +// private static final String CERT_PASSWORD = "StrongPass!12"; +// +// private static Azure azure; // private static AppServiceDomain domain; // private static String pfxPath; - - /** - * Main function which runs the actual sample. - * @param azure instance of the azure client - * @return true if sample runs successfully - */ - public static boolean runSample(Azure azure) { - System.out.println("removed later"); - return true; +// +// /** +// * Main function which runs the actual sample. +// * @param azure instance of the azure client +// * @return true if sample runs successfully +// */ +// public static boolean runSample(Azure azure) { +// System.out.println("removed later"); +// return true; // RG_NAME = azure.sdkContext().randomResourceName("rgNEMV_", 24); // // if (ManageWebAppWithTrafficManager.azure == null) { @@ -230,38 +230,7 @@ public static boolean runSample(Azure azure) { // } // // return false; - } - /** - * Main entry point. - * @param args the parameters - */ - public static void main(String[] args) { - try { - - //============================================================= - // Authenticate - - final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true); - final TokenCredential credential = new DefaultAzureCredentialBuilder() - .authorityHost(profile.environment().getActiveDirectoryEndpoint()) - .build(); - - Azure azure = Azure - .configure() - .withLogLevel(HttpLogDetailLevel.BASIC) - .authenticate(credential, profile) - .withDefaultSubscription(); - - // Print selected subscription - System.out.println("Selected subscription: " + azure.subscriptionId()); - - runSample(azure); - } catch (Exception e) { - System.out.println(e.getMessage()); - e.printStackTrace(); - } - } - +// // private static AppServicePlan createAppServicePlan(String name, Region region) { // return azure.appServicePlans().define(name) // .withRegion(region) @@ -287,4 +256,4 @@ public static void main(String[] args) { // .attach() // .create(); // } -} +//} diff --git a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/CreateVirtualMachinesInParallel.java b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/CreateVirtualMachinesInParallel.java index 285d521e6389..93a7ed7c05fa 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/CreateVirtualMachinesInParallel.java +++ b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/CreateVirtualMachinesInParallel.java @@ -75,7 +75,7 @@ public static boolean runSample(Azure azure) { System.out.println("Created a new resource group - " + resourceGroup.id()); - List publicIpCreatableKeys = new ArrayList<>(); +// List publicIpCreatableKeys = new ArrayList<>(); // Prepare a batch of Creatable definitions // List> creatableVirtualMachines = new ArrayList<>(); @@ -114,7 +114,7 @@ public static boolean runSample(Azure azure) { .withExistingResourceGroup(resourceGroup) .withLeafDomainLabel(azure.sdkContext().randomResourceName("pip", 10)); - publicIpCreatableKeys.add(publicIPAddressCreatable.key()); +// publicIpCreatableKeys.add(publicIPAddressCreatable.key()); //============================================================= // Create 1 virtual machine creatable @@ -153,12 +153,12 @@ public static boolean runSample(Azure azure) { System.out.println("Virtual Machines created: (took " + (stopwatch.getTime() / 1000) + " seconds to create) == " + virtualMachines.size() + " == virtual machines"); - List publicIpResourceIds = new ArrayList<>(); - for (String publicIpCreatableKey : publicIpCreatableKeys) { - PublicIPAddress pip = (PublicIPAddress) virtualMachines.createdRelatedResource(publicIpCreatableKey); - publicIpResourceIds.add(pip.id()); - } - +// List publicIpResourceIds = new ArrayList<>(); +// for (String publicIpCreatableKey : publicIpCreatableKeys) { +// PublicIPAddress pip = (PublicIPAddress) virtualMachines.createdRelatedResource(publicIpCreatableKey); +// publicIpResourceIds.add(pip.id()); +// } +// // //============================================================= // // Create 1 Traffic Manager Profile // // diff --git a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ListComputeSkus.java b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ListComputeSkus.java index b647decf5873..19cad7574c07 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ListComputeSkus.java +++ b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ListComputeSkus.java @@ -55,7 +55,6 @@ public static boolean runSample(Azure azure) { } else if (sku.resourceType().equals(ComputeResourceType.SNAPSHOTS)) { size = sku.diskSkuType().toString(); } - Map> regionZones = sku.zones(); System.out.println(String.format(format, sku.name(), sku.resourceType(), size, regionZoneToString(sku.zones()))); } diff --git a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageManagedDisks.java b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageManagedDisks.java index ec93a9083cbc..e05c63710a42 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageManagedDisks.java +++ b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageManagedDisks.java @@ -72,7 +72,7 @@ public static boolean runSample(Azure azure) { .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) .create(); - System.out.println("Created VM [with an implicit Managed OS disk and explicit Managed data disk]"); + System.out.println("Created VM [with an implicit Managed OS disk and explicit Managed data disk]: " + linuxVM1.id()); // Creation is simplified with implicit creation of managed disks without specifying all the disk details. You will notice that you do not require storage accounts // ::== Update the VM @@ -186,7 +186,7 @@ public static boolean runSample(Azure azure) { .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) .create(); - System.out.println("Created VM [from custom image]"); + System.out.println("Created VM [from custom image]: " + linuxVM3.id()); // Create a VM from a VHD (Create Virtual Machine Using Specialized VHD) @@ -207,7 +207,7 @@ public static boolean runSample(Azure azure) { .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) .create(); - System.out.println("Created VM [by attaching un-managed disk]"); + System.out.println("Created VM [by attaching un-managed disk]: " + linuxVM4.id()); // Create a Snapshot (Create Virtual Machine using specialized disks from snapshot) @@ -292,7 +292,7 @@ public static boolean runSample(Azure azure) { .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) .create(); - System.out.println("Created VM [with specialized OS managed disk]"); + System.out.println("Created VM [with specialized OS managed disk]: " + linuxVM6.id()); // ::== Migrate a VM to managed disks with a single reboot diff --git a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageScaleSetUserAssignedMSIFromServicePrincipal.java b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageScaleSetUserAssignedMSIFromServicePrincipal.java index 7489367bb568..e353668140a0 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageScaleSetUserAssignedMSIFromServicePrincipal.java +++ b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageScaleSetUserAssignedMSIFromServicePrincipal.java @@ -142,13 +142,21 @@ public static boolean runSample(Azure.Authenticated authenticated) { System.out.println(e.getMessage()); e.printStackTrace(); } finally { - azure.resourceGroups().beginDeleteByName(rgName); - try { - authenticated.servicePrincipals().deleteById(servicePrincipal.id()); - } catch (Exception e) { } + if (azure != null) { + azure.resourceGroups().beginDeleteByName(rgName); + try { + authenticated.servicePrincipals().deleteById(servicePrincipal.id()); + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + } try { authenticated.activeDirectoryApplications().deleteById(authenticated.activeDirectoryApplications().getByName(servicePrincipal.applicationId()).id()); - } catch (Exception e) { } + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } } return false; } diff --git a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageVirtualMachineScaleSetAsync.java b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageVirtualMachineScaleSetAsync.java index d26c529d62ac..7a86912559be 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageVirtualMachineScaleSetAsync.java +++ b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageVirtualMachineScaleSetAsync.java @@ -255,6 +255,10 @@ public static boolean runSample(final Azure azure) { }) .last().block(); + if (virtualMachineScaleSet == null) { + return false; + } + final String pipFqdn = publicIPAddress.fqdn(); //============================================================= // List virtual machine scale set instance network interfaces and SSH connection string diff --git a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageZonalVirtualMachineScaleSet.java b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageZonalVirtualMachineScaleSet.java index 8bb327693ad3..4c50d4adb875 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageZonalVirtualMachineScaleSet.java +++ b/sdk/management/samples/src/main/java/com/azure/management/compute/samples/ManageZonalVirtualMachineScaleSet.java @@ -183,7 +183,7 @@ public static boolean runSample(Azure azure) { .withAvailabilityZone(AvailabilityZoneId.ZONE_1) .create(); - System.out.println("Created zone aware virtual machine scale set"); + System.out.println("Created zone aware virtual machine scale set: " + virtualMachineScaleSet1.id()); //============================================================= // Create a zone aware virtual machine scale set @@ -208,7 +208,7 @@ public static boolean runSample(Azure azure) { .withAvailabilityZone(AvailabilityZoneId.ZONE_1) .create(); - System.out.println("Created zone aware virtual machine scale set"); + System.out.println("Created zone aware virtual machine scale set: " + virtualMachineScaleSet2.id()); return true; } catch (Exception f) { diff --git a/sdk/management/samples/src/main/java/com/azure/management/dns/samples/ManageDns.java b/sdk/management/samples/src/main/java/com/azure/management/dns/samples/ManageDns.java index 9ac76004d94c..4aef2b95815a 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/dns/samples/ManageDns.java +++ b/sdk/management/samples/src/main/java/com/azure/management/dns/samples/ManageDns.java @@ -49,7 +49,6 @@ public class ManageDns { public static boolean runSample(Azure azure) { final String customDomainName = "THE CUSTOM DOMAIN THAT YOU OWN (e.g. contoso.com)"; final String rgName = azure.sdkContext().randomResourceName("rgNEMV_", 24); - final String appServicePlanName = azure.sdkContext().randomResourceName("jplan1_", 15); final String webAppName = azure.sdkContext().randomResourceName("webapp1-", 20); try { diff --git a/sdk/management/samples/src/main/java/com/azure/management/samples/Utils.java b/sdk/management/samples/src/main/java/com/azure/management/samples/Utils.java index 8f9fff292bb2..05af896f68c5 100644 --- a/sdk/management/samples/src/main/java/com/azure/management/samples/Utils.java +++ b/sdk/management/samples/src/main/java/com/azure/management/samples/Utils.java @@ -172,6 +172,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -3086,9 +3087,10 @@ private interface WebAppTestClient { public static synchronized int getSize(Iterable iterable) { int res = 0; - - for (T t : iterable) { - res++; + Iterator iterator = iterable.iterator(); + while (iterator.hasNext()) { + iterator.next(); + ++res; } return res; } diff --git a/sdk/management/samples/src/test/java/com/azure/management/samples/AppServiceSampleTests.java b/sdk/management/samples/src/test/java/com/azure/management/samples/AppServiceSampleTests.java index 1a304d7ee239..d4f123b2c59a 100644 --- a/sdk/management/samples/src/test/java/com/azure/management/samples/AppServiceSampleTests.java +++ b/sdk/management/samples/src/test/java/com/azure/management/samples/AppServiceSampleTests.java @@ -8,13 +8,13 @@ import com.azure.management.appservice.samples.ManageLinuxWebAppBasic; import com.azure.management.appservice.samples.ManageLinuxWebAppSqlConnection; import com.azure.management.appservice.samples.ManageLinuxWebAppWithDomainSsl; -import com.azure.management.appservice.samples.ManageLinuxWebAppWithTrafficManager; +//import com.azure.management.appservice.samples.ManageLinuxWebAppWithTrafficManager; import com.azure.management.appservice.samples.ManageWebAppBasic; import com.azure.management.appservice.samples.ManageWebAppSlots; import com.azure.management.appservice.samples.ManageWebAppSourceControlAsync; import com.azure.management.appservice.samples.ManageWebAppSqlConnection; import com.azure.management.appservice.samples.ManageWebAppWithDomainSsl; -import com.azure.management.appservice.samples.ManageWebAppWithTrafficManager; +//import com.azure.management.appservice.samples.ManageWebAppWithTrafficManager; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -48,10 +48,10 @@ public void testManageWebAppWithDomainSsl() { Assertions.assertTrue(ManageWebAppWithDomainSsl.runSample(azure)); } - @Test - public void testManageWebAppWithTrafficManager() { - Assertions.assertTrue(ManageWebAppWithTrafficManager.runSample(azure)); - } +// @Test +// public void testManageWebAppWithTrafficManager() { +// Assertions.assertTrue(ManageWebAppWithTrafficManager.runSample(azure)); +// } @Test public void testManageLinuxWebAppBasic() { @@ -69,10 +69,10 @@ public void testManageLinuxWebAppWithDomainSsl() { Assertions.assertTrue(ManageLinuxWebAppWithDomainSsl.runSample(azure)); } - @Test - public void testManageLinuxWebAppWithTrafficManager() { - Assertions.assertTrue(ManageLinuxWebAppWithTrafficManager.runSample(azure)); - } +// @Test +// public void testManageLinuxWebAppWithTrafficManager() { +// Assertions.assertTrue(ManageLinuxWebAppWithTrafficManager.runSample(azure)); +// } @Test public void testManageFunctionAppBasic() {