diff --git a/azure-batch/pom.xml b/azure-batch/pom.xml index 6eee8f3d1991..fac5f9a52e9b 100644 --- a/azure-batch/pom.xml +++ b/azure-batch/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure-mgmt-compute/pom.xml b/azure-mgmt-compute/pom.xml index 6b215b29b2ab..adb92feaae0d 100644 --- a/azure-mgmt-compute/pom.xml +++ b/azure-mgmt-compute/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java index 8720685da641..8bf1aee963a9 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java @@ -3,66 +3,113 @@ import com.microsoft.azure.management.compute.implementation.api.AvailabilitySetInner; import com.microsoft.azure.management.compute.implementation.api.InstanceViewStatus; 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.Updatable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; import java.util.List; +/** + * An immutable client-side representation of an Azure availability set. + */ public interface AvailabilitySet extends GroupableResource, Refreshable, - Wrapper { + Wrapper, + Updatable { /** - * Get the update domain count of availability set, an update domain represents the group of virtual + * Returns the update domain count of an availability set. + *

+ * An update domain represents the group of virtual * machines and underlying physical hardware that can be rebooted at the same time. * - * @return the platformUpdateDomainCount value + * @return the update domain count */ - Integer updateDomainCount(); + int updateDomainCount(); /** - * Get the fault domain count of availability set., a fault domain represents the group of virtual + * Returns the fault domain count of availability set. + *

+ * A fault domain represents the group of virtual * machines that shares common power source and network switch. * - * @return the platformUpdateDomainCount value + * @return the fault domain count */ - Integer FaultDomainCount(); + int faultDomainCount(); /** - * Get the list of ids of virtual machines in the availability set. + * Lists the resource IDs of the virtual machines in the availability set. * - * @return the virtualMachineIds value + * @return list of resource ID strings */ List virtualMachineIds(); /** - * Get the list of virtual machines in the availability set. + * Lists the virtual machines in the availability set. * - * @return the virtualMachineIds value + * @return list of virtual machines */ List virtualMachines() throws Exception; /** - * Get the statuses value. + * Lists the statuses of the existing virtual machines in the availability set. * - * @return the statuses value + * @return list of virtual machine statuses */ List statuses(); + /************************************************************** * Fluent interfaces to provision an AvailabilitySet **************************************************************/ + /** + * The first stage of an availability set definition + */ interface DefinitionBlank extends GroupableResource.DefinitionWithRegion { } + /** + * The stage of the availability set definition allowing to specify the resource group + */ interface DefinitionWithGroup extends GroupableResource.DefinitionWithGroup { } - interface DefinitionCreatable extends Creatable { - DefinitionCreatable withUpdateDomainCount(Integer updateDomainCount); - DefinitionCreatable withFaultDomainCount(Integer faultDomainCount); + /** + * The stage of an availability set definition which contains all the minimum required inputs for + * the resource to be created (via {@link DefinitionCreatable#create()}), but also allows + * for any other optional settings to be specified. + */ + interface DefinitionCreatable extends + Creatable, + Resource.DefinitionWithTags { + /** + * Specifies the update domain count for the availability set. + * @param updateDomainCount update domain count + * @return the next stage of the resource definition + */ + DefinitionCreatable withUpdateDomainCount(int updateDomainCount); + + /** + * Specifies the fault domain count for the availability set. + * @param faultDomainCount fault domain count + * @return the next stage of the resource definition + */ + DefinitionCreatable withFaultDomainCount(int faultDomainCount); + } + + /** + * The template for an availability set update operation, containing all the settings that + * can be modified. + *

+ * Call {@link Update#apply()} to apply the changes to the resource in Azure. + */ + interface Update extends + Appliable, + Resource.UpdateWithTags { } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySets.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySets.java index 59197b8baee4..50548277d186 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySets.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySets.java @@ -7,6 +7,9 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; +/** + * Entry point to availability set management API. + */ public interface AvailabilitySets extends SupportsListing, SupportsListingByGroup, @@ -14,6 +17,9 @@ public interface AvailabilitySets extends SupportsCreating, SupportsDeleting, SupportsDeletingByGroup { + /** + * Entry point to availability set management API within a specific resource group. + */ interface InGroup extends SupportsListing, SupportsCreating, diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachine.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachine.java index 19eb7f6b73c3..bde5269581a4 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachine.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachine.java @@ -2,7 +2,21 @@ import com.microsoft.azure.SubResource; import com.microsoft.azure.management.compute.implementation.KnownVirtualMachineImage; -import com.microsoft.azure.management.compute.implementation.api.*; +import com.microsoft.azure.management.compute.implementation.api.VirtualMachineInner; +import com.microsoft.azure.management.compute.implementation.api.Plan; +import com.microsoft.azure.management.compute.implementation.api.HardwareProfile; +import com.microsoft.azure.management.compute.implementation.api.StorageProfile; +import com.microsoft.azure.management.compute.implementation.api.OSProfile; +import com.microsoft.azure.management.compute.implementation.api.NetworkProfile; +import com.microsoft.azure.management.compute.implementation.api.DiagnosticsProfile; +import com.microsoft.azure.management.compute.implementation.api.VirtualMachineInstanceView; +import com.microsoft.azure.management.compute.implementation.api.VirtualMachineExtensionInner; +import com.microsoft.azure.management.compute.implementation.api.OperatingSystemTypes; +import com.microsoft.azure.management.compute.implementation.api.ImageReference; +import com.microsoft.azure.management.compute.implementation.api.WinRMListener; +import com.microsoft.azure.management.compute.implementation.api.CachingTypes; +import com.microsoft.azure.management.compute.implementation.api.DiskEncryptionSettings; +import com.microsoft.azure.management.compute.implementation.api.VirtualMachineSizeTypes; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; @@ -11,6 +25,9 @@ import java.util.List; +/** + * The type representing Azure virtual machine. + */ public interface VirtualMachine extends GroupableResource, Refreshable, @@ -92,95 +109,130 @@ public interface VirtualMachine extends */ List resources(); + /** + * The initial stage representing virtual machine definition. + */ interface DefinitionBlank extends GroupableResource.DefinitionWithRegion { } + /** + * The virtual machine definition stage with resource group. + */ interface DefinitionWithGroup extends GroupableResource.DefinitionWithGroup { } + /** + * The virtual machine definition stage with Operation System. + */ interface DefinitionWithOS { /** * Specifies the market-place image used for the virtual machine's OS. - * @return The next stage of the virtual machine definition. + * + * @return The next stage of the virtual machine definition */ DefinitionWithMarketplaceImage withMarketplaceImage(); /** * Specifies the user (generalized) image used for the virtual machine's OS. + * * @param imageUrl The url the the VHD - * @return The next stage of the virtual machine definition. + * @return The next stage of the virtual machine definition */ DefinitionWithOSType withStoredImage(String imageUrl); /** * Specifies the specialized operating system disk to be attached to the virtual machine. - * @param osDiskUrl The url to the OS disk in the Azure Storage account. - * @return The next stage of the Windows virtual machine definition. + * + * @param osDiskUrl The url to the OS disk in the Azure Storage account + * @return The next stage of the Windows virtual machine definition */ DefinitionCreatable withOSDisk(String osDiskUrl, OperatingSystemTypes osType); } + /** + * The virtual machine definition stage with marketplace (platform) image. + */ interface DefinitionWithMarketplaceImage { /** * Specifies the version of image. - * @param imageReference describes publisher, offer, sku and version of the market-place image. - * @return The next stage of the virtual machine definition. + * + * @param imageReference describes publisher, offer, sku and version of the market-place image + * @return The next stage of the virtual machine definition */ DefinitionWithOSType version(ImageReference imageReference); /** * Specifies that the latest version of the 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 definition. + * @return The next stage of the virtual machine definition */ DefinitionWithOSType latest(String publisher, String offer, String sku); /** * Specifies the known image to be used. - * @param knownImage Enum value indicating known market-place image. - * @return The next stage of the virtual machine definition. + * + * @param knownImage Enum value indicating known market-place image + * @return The next stage of the virtual machine definition */ DefinitionWithOSType popular(KnownVirtualMachineImage knownImage); } + /** + * The virtual machine definition stage with Operating system type. + */ interface DefinitionWithOSType { /** * Specifies the OS type of the virtual machine as Linux. - * @return The next stage of the Linux virtual machine definition. + * + * @return The next stage of the Linux virtual machine definition */ DefinitionWithRootUserName withLinuxOS(); /** * Specifies the OS type as Windows. - * @return The next stage of the Windows virtual machine definition. + * + * @return The next stage of the Windows virtual machine definition */ DefinitionWithAdminUserName withWindowsOS(); } + /** + * The Linux virtual machine definition stage with root user name. + */ interface DefinitionWithRootUserName { /** * Specifies the root user name for the Linux virtual machine. - * @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 definition. + * + * @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 definition */ DefinitionLinuxCreatable withRootUserName(String rootUserName); } + /** + * The Windows virtual machine definition stage with root user name. + */ interface DefinitionWithAdminUserName { /** * Specifies the administrator user name for the Windows virtual machine. + * * @param adminUserName The Windows administrator user name. This must follow the required naming convention for Windows user name. * @return The stage representing creatable Linux VM definition */ DefinitionWindowsCreatable withAdminUserName(String adminUserName); } + /** + * The Linux virtual machine in creatable stage. + */ interface DefinitionLinuxCreatable extends DefinitionCreatable { /** - * Specifies the SSH public key, each call to this method adds the given public key to the list - * of VM's public keys. + * 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 definition @@ -188,45 +240,65 @@ interface DefinitionLinuxCreatable extends DefinitionCreatable { DefinitionLinuxCreatable withSsh(String publicKey); } + /** + * The Windows virtual machine in cretable stage. + */ interface DefinitionWindowsCreatable extends DefinitionCreatable { /** * Specifies that VM Agent should not be provisioned. + * * @return The stage representing creatable Windows VM definition */ DefinitionWindowsCreatable disableVMAgent(); /** * Specifies that automatic updates should be disabled. + * * @return The stage representing creatable Windows VM definition */ DefinitionWindowsCreatable disableAutoUpdate(); /** * Specifies the time-zone. + * * @return The stage representing creatable Windows VM definition */ DefinitionWindowsCreatable withTimeZone(String timeZone); /** - * Specifies the WINRM listener, each call to this method adds the given listener to the list - * of VM's WinRM listeners. + * Specifies the WINRM listener. + *

+ * each call to this method adds the given listener to the list of VM's WinRM listeners. + * * @return The stage representing creatable Windows VM definition */ DefinitionWindowsCreatable withWinRM(WinRMListener listener); } + /** + * The virtual machine definition stage with password. + * + * @param The virtual machine definition in creatable stage. + */ interface DefinitionPassword { /** * Specifies the password for the virtual machine. + * * @param password The password. This must follow the criteria for Azure VM password. * @return The stage representing creatable VM definition */ T withPassword(String password); } + /** + * The virtual machine definition stage with OS disk configurations. + * + * @param The virtual machine definition in creatable stage. + */ interface DefinitionOSDiskSettings { /** * Specifies the caching type for the Operating System disk. + * * @param cachingType The caching type. * @return The stage representing creatable VM definition */ @@ -234,6 +306,7 @@ interface DefinitionOSDiskSettings { /** * Specifies the name of the OS Disk Vhd file and it's parent container. + * * @param containerName The name of the container in the selected storage account. * @param vhdName The name for the OS Disk vhd. * @return The stage representing creatable VM definition @@ -242,6 +315,7 @@ interface DefinitionOSDiskSettings { /** * Specifies the encryption settings for the OS Disk. + * * @param settings The encryption settings. * @return The stage representing creatable VM definition */ @@ -249,6 +323,7 @@ interface DefinitionOSDiskSettings { /** * Specifies the size of the OSDisk in GB. + * * @param size The VHD size. * @return The stage representing creatable VM definition */ @@ -256,29 +331,164 @@ interface DefinitionOSDiskSettings { /** * Specifies the name for the OS Disk. + * * @param name The OS Disk name. * @return The stage representing creatable VM definition */ T withOSDiskName(String name); } + /** + * The virtual machine definition stage with size. + * + * @param The virtual machine definition in creatable stage. + */ interface DefinitionWithVMSize { /** + * Specifies the virtual machine size. + * * @param sizeName The name of the size for the virtual machine as text * @return The stage representing creatable VM definition */ T withSize(String sizeName); /** + * Specifies the virtual machine size. + * * @param size A size from the list of available sizes for the virtual machine * @return The stage representing creatable VM definition */ T withSize(VirtualMachineSizeTypes size); } + /** + * The virtual machine definition stage with data disk configurations. + * + * @param The virtual machine definition in creatable stage. + */ + interface ConfigureDataDisk { + /** + * Specifies the logical unit number for the data disk. + * + * @param lun The logical unit number + * @return The stage representing optional additional configurations for the attachable data disk + */ + ConfigureDataDisk withLun(Integer lun); + + /** + * Specifies the caching type for the data disk. + * + * @param cachingType The disk caching type. Possible values include: 'None', 'ReadOnly', 'ReadWrite' + * @return The stage representing optional additional configurations for the attachable data disk + */ + ConfigureDataDisk withCaching(CachingTypes cachingType); + + /** + * Adds the data disk to the list of virtual machine's data disks. + * + * @return The stage representing creatable VM definition + */ + T attach(); + } + + /** + * The virtual machine definition stage with data disk target location. + * + * @param The virtual machine definition in creatable stage. + */ + interface ConfigureNewDataDiskWithStoreAt extends ConfigureDataDisk { + /** + * Specifies where the VHD associated with the new blank data disk needs to be stored. + * + * @param storageAccountName The storage account name + * @param containerName The name of the container to hold the new VHD file + * @param vhdName The name for the new VHD file + * @return The stage representing optional additional configurations for the attachable data disk + */ + ConfigureDataDisk storeAt(String storageAccountName, String containerName, String vhdName); + } + + /** + * The virtual machine definition stage with new data disk configuration. + * + * @param The virtual machine definition in creatable stage. + */ + interface ConfigureNewDataDisk { + /** + * Specifies the initial disk size in GB for new blank data disk. + * + * @param size The disk size in GB + * @return The stage representing optional additional configurations for the attachable data disk + */ + ConfigureNewDataDiskWithStoreAt withSizeInGB(Integer size); + } + + /** + * The virtual machine definition stage with existing data disk configuration. + * + * @param The virtual machine definition in creatable stage. + */ + interface ConfigureExistingDataDisk { + /** + * Specifies an existing VHD that needs to be attached to the virtual machine as data disk. + * + * @param storageAccountName The storage account name + * @param containerName The name of the container holding the VHD file + * @param vhdName The name for the VHD file + * @return The stage representing optional additional configurations for the attachable data disk + */ + ConfigureDataDisk from(String storageAccountName, String containerName, String vhdName); + } + + /** + * The virtual machine definition stage with data disk configuration. + * + * @param The virtual machine definition in creatable stage. + */ + interface DefinitionWithDataDisk { + /** + * Specifies that a new blank data disk needs to be attached to virtual machine. + * + * @param sizeInGB The disk size in GB + * @return The stage representing creatable VM definition + */ + T withNewDataDisk(Integer sizeInGB); + + /** + * Specifies an existing VHD that needs to be attached to the virtual machine as data disk. + * + * @param storageAccountName The storage account name + * @param containerName The name of the container holding the VHD file + * @param vhdName The name for the VHD file + * @return The stage representing creatable VM definition + */ + T withExistingDataDisk(String storageAccountName, String containerName, String vhdName); + + /** + * Specifies a new blank data disk to be attached to the virtual machine along with it's configuration. + * + * @param name The name for the data disk + * @return The stage representing configuration for the data disk + */ + ConfigureNewDataDisk defineNewDataDisk(String name); + + /** + * Specifies an existing VHD that needs to be attached to the virtual machine as data disk along with it's configuration. + * + * @param name The name for the data disk + * @return The stage representing configuration for the data disk + */ + ConfigureExistingDataDisk defineExistingDataDisk(String name); + } + + /** + * The virtual machine definition stage with storage account. + * + * @param The virtual machine definition in creatable stage. + */ interface DefinitionStorageAccount { /** - * Specifies the name of the storage account to create, the OS disk for VM created from a market-place + * Specifies the name of the storage account to create, the OS disk for VM created from a market-place. * image will be stored in this account. * * @param name The name of the storage account @@ -305,11 +515,15 @@ interface DefinitionStorageAccount { T withExistingStorageAccount(String name); } + /** + * The virtual machine definition in cretable stage. + */ interface DefinitionCreatable extends DefinitionPassword, DefinitionOSDiskSettings, DefinitionWithVMSize, DefinitionStorageAccount, + DefinitionWithDataDisk, Creatable { } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineImage.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineImage.java index dbc19fdf0879..d2e0363ee9f1 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineImage.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineImage.java @@ -1,42 +1,170 @@ package com.microsoft.azure.management.compute; import com.microsoft.azure.CloudException; -import com.microsoft.azure.management.compute.implementation.api.*; +import com.microsoft.azure.management.compute.implementation.api.ImageReference; +import com.microsoft.azure.management.compute.implementation.api.VirtualMachineImageInner; +import com.microsoft.azure.management.compute.implementation.api.PurchasePlan; +import com.microsoft.azure.management.compute.implementation.api.OSDiskImage; +import com.microsoft.azure.management.compute.implementation.api.DataDiskImage; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; import java.io.IOException; import java.util.List; +/** + * The type representing Azure virtual machine image. + */ public interface VirtualMachineImage extends Wrapper { + /** + * The region in which virtual machine image is available. + * + * @return The region + */ Region location(); + + /** + * The publisher name of the virtual machine image. + * + * @return The publisher name + */ String publisher(); + + /** + * The name of the virtual machine image offer. + * + * @return The offer name + */ String offer(); + + /** + * The commercial name of the virtual machine image (SKU). + * + * @return The SKU name + */ String sku(); + + /** + * The version of the virtual machine image. + * + * @return The version + */ String version(); + + /** + * The image reference representing publisher, offer, sku and version of the virtual machine image. + * + * @return The image reference + */ ImageReference imageReference(); + + /** + * The purchase plan for the virtual machine image. + * + * @return The purchase plan. + */ PurchasePlan plan(); + + /** + * Describes the OS Disk image in the virtual machine image. + * + * @return The OS Disk image + */ OSDiskImage osDiskImage(); + + /** + * Describes the Data disk images in the virtual machine. + * + * @return The data disks. + */ List dataDiskImages(); + /** + * Represents a virtual image image publisher. + */ interface Publisher { - Region location(); + /** + * Gets the region where virtual machine images from this publisher is available. + * + * @return The region name + */ + Region region(); + + /** + * Gets the name of the virtual machine image publisher. + * + * @return The publisher name + */ String publisher(); + + /** + * Lists the virtual machine image offers from this publisher in the specific region. + * + * @return list of virtual machine image offers + * @throws CloudException + * @throws IOException + */ List listOffers() throws CloudException, IOException; } + /** + * Represents a virtual machine image offer. + */ interface Offer { - Region location(); + /** + * Gets the region where this virtual machine image offer is available. + * + * @return The region name + */ + Region region(); + + /** + * Gets the publisher name of this virtual machine image offer. + * + * @return The publisher name + */ String publisher(); + + /** + * Gets the name of the virtual machine image offer. + * + * @return The offer name + */ String offer(); List listSkus() throws CloudException, IOException; } + /** + * Represents a virtual machine image SKU. + */ interface Sku { - Region location(); + /** + * Gets the region where this virtual machine image offer SKU is available. + * + * @return The region name + */ + Region region(); + + /** + * Gets the publisher name of this virtual machine image offer SKU. + * + * @return The publisher name + */ String publisher(); + + /** + * Gets the virtual machine offer name that this SKU belongs to. + * + * @return The offer name + */ String offer(); + + /** + * Gets the commercial name of the virtual machine image (SKU). + * + * @return The SKU name + */ String sku(); List listImages() throws CloudException, IOException; } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineImages.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineImages.java index ef5bad04641e..59cffaa8a1a1 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineImages.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineImages.java @@ -7,7 +7,18 @@ import java.io.IOException; import java.util.List; +/** + * The type representing Azure virtual machine image collection. + */ public interface VirtualMachineImages extends SupportsListingByLocation { - List listPublishers(final Region location) throws CloudException, IOException; + /** + * Lists the virtual machine publishers in a region. + * + * @param region The region + * @return The list of VM image publishers + * @throws CloudException Thrown for an invalid response from the service. + * @throws IOException Thrown for IO exception. + */ + List listPublishers(final Region region) throws CloudException, IOException; } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineSize.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineSize.java index 6a6a1392113f..b8a7aacbb797 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineSize.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineSize.java @@ -1,5 +1,8 @@ package com.microsoft.azure.management.compute; +/** + * A type representing virtual machine size available for a subscription in a region. + */ public interface VirtualMachineSize { /** * Gets the VM size name. @@ -27,7 +30,7 @@ public interface VirtualMachineSize { Integer memoryInMB(); /** - * Gets or the Maximum number of data disks allowed by a VM size. + * Gets the Maximum number of data disks allowed by a VM size. */ Integer maxDataDiskCount(); } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachines.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachines.java index a6862840c70d..1f37b5aab7a4 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachines.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachines.java @@ -11,6 +11,9 @@ import java.io.IOException; +/** + * The type representing Azure virtual machine collection. + */ public interface VirtualMachines extends SupportsListing, SupportsListingByGroup, @@ -20,18 +23,24 @@ public interface VirtualMachines extends SupportsDeletingByGroup { /** * Lists all available virtual machine sizes in a region. + * * @param region The region upon which virtual-machine-sizes is queried. * @return the List<VirtualMachineSize> if successful. - * @throws CloudException - * @throws IOException + * @throws CloudException Thrown for an invalid response from the service. + * @throws IOException Thrown for IO exception. */ PagedList listSizes(String region) throws CloudException, IOException; + + /** + * A type representing Azure virtual machine under a resource gorup. + */ interface InGroup extends SupportsListing, SupportsCreating, SupportsDeleting { /** * Lists all available virtual machine sizes in a region. + * * @param region The region upon which virtual-machine-sizes is queried. * @return the List<VirtualMachineSize> if successful. * @throws CloudException diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java index d6ecf1b48a92..d8081dc2a48f 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java @@ -1,3 +1,8 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ package com.microsoft.azure.management.compute.implementation; import com.microsoft.azure.SubResource; @@ -14,16 +19,18 @@ import com.microsoft.rest.ServiceResponse; import java.util.ArrayList; +import java.util.Collections; import java.util.List; class AvailabilitySetImpl - extends GroupableResourceImpl - implements + extends + GroupableResourceImpl + implements AvailabilitySet, AvailabilitySet.DefinitionBlank, AvailabilitySet.DefinitionWithGroup, - AvailabilitySet.DefinitionCreatable { - private String name; + AvailabilitySet.DefinitionCreatable, + AvailabilitySet.Update { private List idOfVMsInSet; private List vmsInSet; @@ -37,19 +44,18 @@ class AvailabilitySetImpl final AvailabilitySetsInner client, final ResourceGroups resourceGroups, final VirtualMachines virtualMachines) { - super(innerModel.id(), innerModel, resourceGroups); - this.name = name; + super(name, innerModel, resourceGroups); this.client = client; this.virtualMachines = virtualMachines; } @Override - public Integer updateDomainCount() { + public int updateDomainCount() { return this.inner().platformUpdateDomainCount(); } @Override - public Integer FaultDomainCount() { + public int faultDomainCount() { return this.inner().platformFaultDomainCount(); } @@ -62,7 +68,7 @@ public List virtualMachineIds() { } } - return idOfVMsInSet; + return Collections.unmodifiableList(idOfVMsInSet); } @Override @@ -75,18 +81,12 @@ public VirtualMachine load(String resourceGroupName, String resourceName) throws } }); } - return vmsInSet; + return Collections.unmodifiableList(vmsInSet); } @Override public List statuses() { - return this.inner().statuses(); - } - - @Override - public String name() { - // TODO: This method should be removed once once Runtime::Resource::setName is available. - return this.name; + return Collections.unmodifiableList(this.inner().statuses()); } @Override @@ -99,13 +99,13 @@ public AvailabilitySet refresh() throws Exception { } @Override - public AvailabilitySetImpl withUpdateDomainCount(Integer updateDomainCount) { + public AvailabilitySetImpl withUpdateDomainCount(int updateDomainCount) { this.inner().setPlatformUpdateDomainCount(updateDomainCount); return this; } @Override - public AvailabilitySetImpl withFaultDomainCount(Integer faultDomainCount) { + public AvailabilitySetImpl withFaultDomainCount(int faultDomainCount) { this.inner().setPlatformFaultDomainCount(faultDomainCount); return this; } @@ -115,11 +115,21 @@ public AvailabilitySetImpl create() throws Exception { for (Creatable provisionable : prerequisites().values()) { provisionable.create(); } - ServiceResponse response = this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner()); + ServiceResponse response = this.client.createOrUpdate(this.resourceGroupName(), this.key, this.inner()); AvailabilitySetInner availabilitySetInner = response.getBody(); this.setInner(availabilitySetInner); this.idOfVMsInSet = null; this.vmsInSet = null; return this; } + + @Override + public AvailabilitySetImpl update() throws Exception { + return this; + } + + @Override + public AvailabilitySetImpl apply() throws Exception { + return create(); + } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java index 3913e887edf7..54330bdc38e3 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java @@ -33,8 +33,8 @@ public AvailabilitySetsImpl(final AvailabilitySetsInner client, this.virtualMachines = virtualMachines; this.converter = new PagedListConverter() { @Override - public AvailabilitySet typeConvert(AvailabilitySetInner availabilitySetInner) { - return createFluentModel(availabilitySetInner); + public AvailabilitySet typeConvert(AvailabilitySetInner inner) { + return createFluentModel(inner); } }; } @@ -71,13 +71,13 @@ public Page nextPage(String nextPageLink) throws RestExcep } @Override - public AvailabilitySet get(String groupName, String name) throws CloudException, IOException { + public AvailabilitySetImpl get(String groupName, String name) throws CloudException, IOException { ServiceResponse response = this.client.get(groupName, name); return createFluentModel(response.getBody()); } @Override - public AvailabilitySet.DefinitionBlank define(String name) { + public AvailabilitySetImpl define(String name) { return createFluentModel(name); } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImageOfferImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImageOfferImpl.java index c9fd49b090a4..cf27184542b0 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImageOfferImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImageOfferImpl.java @@ -23,8 +23,8 @@ class VirtualMachineImageOfferImpl } @Override - public Region location() { - return publisher.location(); + public Region region() { + return publisher.region(); } @Override @@ -41,7 +41,7 @@ public String offer() { public List listSkus() throws CloudException, IOException { List skus = new ArrayList<>(); for (VirtualMachineImageResourceInner inner : - client.listSkus(location().toString(), publisher(), offer()).getBody()) { + client.listSkus(region().toString(), publisher(), offer()).getBody()) { skus.add(new VirtualMachineImageSkuImpl(this, inner.name(), client)); } return skus; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagePublisherImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagePublisherImpl.java index 305673e5f61b..e517dc3d4613 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagePublisherImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagePublisherImpl.java @@ -23,7 +23,7 @@ class VirtualMachineImagePublisherImpl } @Override - public Region location() { + public Region region() { return location; } @@ -36,7 +36,7 @@ public String publisher() { public List listOffers() throws CloudException, IOException { List offers = new ArrayList<>(); for (VirtualMachineImageResourceInner inner : - client.listOffers(location().toString(), publisher()).getBody()) { + client.listOffers(region().toString(), publisher()).getBody()) { offers.add(new VirtualMachineImageOfferImpl(this, inner.name(), client)); } return offers; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImageSkuImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImageSkuImpl.java index 7f544cee5d58..0475d2769077 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImageSkuImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImageSkuImpl.java @@ -23,8 +23,8 @@ class VirtualMachineImageSkuImpl } @Override - public Region location() { - return offer.location(); + public Region region() { + return offer.region(); } @Override @@ -46,18 +46,18 @@ public List listImages() throws CloudException, IOException List images = new ArrayList<>(); for (VirtualMachineImageResourceInner inner : client.list( - location().toString(), + region().toString(), publisher(), offer(), sku).getBody()) { String version = inner.name(); images.add(new VirtualMachineImageImpl( - location(), + region(), publisher(), offer(), sku, version, - client.get(location().toString(), publisher(), offer(), sku, version).getBody(), + client.get(region().toString(), publisher(), offer(), sku, version).getBody(), client)); } return images; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java index 0539682495ac..9276259368e8 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImagesImpl.java @@ -20,11 +20,11 @@ class VirtualMachineImagesImpl } @Override - public List listPublishers(final Region location) throws CloudException, IOException { + public List listPublishers(final Region region) throws CloudException, IOException { List publishers = new ArrayList<>(); for (VirtualMachineImageResourceInner inner : - client.listPublishers(location.toString()).getBody()) { - publishers.add(new VirtualMachineImagePublisherImpl(location, inner.name(), client)); + client.listPublishers(region.toString()).getBody()) { + publishers.add(new VirtualMachineImagePublisherImpl(region, inner.name(), client)); } return publishers; } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImpl.java index c0f6c967f19e..9df87884dad5 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImpl.java @@ -10,7 +10,11 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; +/** + * The type representing Azure virtual machine. + */ class VirtualMachineImpl extends GroupableResourceImpl implements @@ -18,13 +22,17 @@ class VirtualMachineImpl VirtualMachine.DefinitionBlank, VirtualMachine.DefinitionWithGroup, VirtualMachine.DefinitionWithOS, - VirtualMachine.DefinitionWithMarketplaceImage, + VirtualMachine.DefinitionWithMarketplaceImage, VirtualMachine.DefinitionWithOSType, VirtualMachine.DefinitionWithRootUserName, VirtualMachine.DefinitionWithAdminUserName, VirtualMachine.DefinitionLinuxCreatable, VirtualMachine.DefinitionWindowsCreatable, - VirtualMachine.DefinitionCreatable { + VirtualMachine.DefinitionCreatable, + VirtualMachine.ConfigureDataDisk, + VirtualMachine.ConfigureNewDataDiskWithStoreAt, + VirtualMachine.ConfigureNewDataDisk, + VirtualMachine.ConfigureExistingDataDisk { private final VirtualMachinesInner client; private final VirtualMachineInner innerModel; private final ResourceManager resourceManager; @@ -42,6 +50,7 @@ class VirtualMachineImpl this.innerModel.setStorageProfile(new StorageProfile()); this.innerModel.storageProfile().setOsDisk(new OSDisk()); + this.innerModel.storageProfile().setDataDisks(new ArrayList()); this.innerModel.setOsProfile(new OSProfile()); this.innerModel.setHardwareProfile(new HardwareProfile()); } @@ -264,7 +273,7 @@ public DefinitionCreatable withOSDiskCaching(CachingTypes cachingType) { @Override public DefinitionCreatable withOSDiskVhdLocation(String containerName, String vhdName) { VirtualHardDisk osVhd = new VirtualHardDisk(); - osVhd.setUri(null); // TODO generate and sets VHD URI. + osVhd.setUri(blobUrl(this.storageAccountName, containerName, vhdName)); this.innerModel.storageProfile().osDisk().setVhd(osVhd); return this; } @@ -287,6 +296,88 @@ public DefinitionCreatable withOSDiskName(String name) { return this; } + // Virtual machine data disk fluent methods + // + + @Override + public ConfigureDataDisk withLun(Integer lun) { + DataDisk dataDisk = currentDataDisk(); + dataDisk.setLun(lun); + return this; + } + + @Override + public ConfigureDataDisk withCaching(CachingTypes cachingType) { + DataDisk dataDisk = currentDataDisk(); + dataDisk.setCaching(cachingType); + return this; + } + + @Override + public DefinitionCreatable attach() { + return this; + } + + @Override + public ConfigureDataDisk storeAt(String storageAccountName, String containerName, String vhdName) { + DataDisk dataDisk = currentDataDisk(); + dataDisk.setVhd(new VirtualHardDisk()); + dataDisk.vhd().setUri(blobUrl(storageAccountName, containerName, vhdName)); // URL points to where the new data disk needs to be stored. + return this; + } + + @Override + public ConfigureNewDataDiskWithStoreAt withSizeInGB(Integer sizeInGB) { + DataDisk dataDisk = currentDataDisk(); + dataDisk.setDiskSizeGB(sizeInGB); + return this; + } + + @Override + public ConfigureDataDisk from(String storageAccountName, String containerName, String vhdName) { + DataDisk dataDisk = currentDataDisk(); + dataDisk.setVhd(new VirtualHardDisk()); + dataDisk.vhd().setUri(blobUrl(storageAccountName, containerName, vhdName)); // URL points to an existing data disk to be attached. + return this; + } + + @Override + public ConfigureNewDataDisk defineNewDataDisk(String name) { + DataDisk dataDisk = prepareNewDataDisk(); + dataDisk.setName(name); + dataDisk.setCreateOption(DiskCreateOptionTypes.EMPTY); + return this; + } + + @Override + public ConfigureExistingDataDisk defineExistingDataDisk(String name) { + DataDisk dataDisk = prepareNewDataDisk(); + dataDisk.setName(name); + dataDisk.setCreateOption(DiskCreateOptionTypes.ATTACH); + return this; + } + + @Override + public DefinitionCreatable withNewDataDisk(Integer sizeInGB) { + DataDisk dataDisk = prepareNewDataDisk(); + dataDisk.setDiskSizeGB(sizeInGB); + dataDisk.setCreateOption(DiskCreateOptionTypes.EMPTY); + return this; + } + + @Override + public DefinitionCreatable withExistingDataDisk(String storageAccountName, String containerName, String vhdName) { + DataDisk dataDisk = prepareNewDataDisk(); + VirtualHardDisk diskVhd = new VirtualHardDisk(); + diskVhd.setUri(blobUrl(storageAccountName, containerName, vhdName)); + dataDisk.setVhd(diskVhd); + dataDisk.setCreateOption(DiskCreateOptionTypes.ATTACH); + return this; + } + + // Virtual machine storage account fluent methods + // + @Override public DefinitionCreatable withNewStorageAccount(String name) { return withNewStorageAccount(storageManager.storageAccounts().define(name) @@ -307,29 +398,27 @@ public DefinitionCreatable withExistingStorageAccount(String name) { return this; } - @Override public VirtualMachine create() throws Exception { setDefaults(); return null; } - // Helper methods + // helper methods to set various virtual machine's default properties // - private boolean isStoredImage(OSDisk osDisk) { - return osDisk.image() != null; - } - private boolean isOSDiskAttached(OSDisk osDisk) { - return osDisk.createOption() == DiskCreateOptionTypes.ATTACH; + private void setDefaults() { + setOSDiskAndOSProfileDefaults(); + setHardwareProfileDefaults(); + setDataDisksDefaults(); } - private void setDefaults() { + private void setOSDiskAndOSProfileDefaults() { OSDisk osDisk = this.innerModel.storageProfile().osDisk(); if (!isOSDiskAttached(osDisk)) { if (osDisk.vhd() == null) { // Sets the OS disk VHD for "UserImage" and "VM(Platform)Image" - withOSDiskVhdLocation("vhds", null /*TODO generate random vhd name */); + withOSDiskVhdLocation("vhds", this.name() + "-os-disk-" + UUID.randomUUID().toString() + ".vhd"); } OSProfile osProfile = this.innerModel.osProfile(); if (osDisk.osType() == OperatingSystemTypes.LINUX) { @@ -345,12 +434,82 @@ private void setDefaults() { } if (osDisk.name() == null) { - withOSDiskName(null /*TODO generate random OSDisk name */); + withOSDiskName(this.name() + "-os-disk"); } + } + private void setHardwareProfileDefaults() { HardwareProfile hardwareProfile = this.innerModel.hardwareProfile(); if (hardwareProfile.vmSize() == null) { hardwareProfile.setVmSize(VirtualMachineSizeTypes.BASIC_A0); } } + + private void setDataDisksDefaults() { + List dataDisks = this.innerModel.storageProfile().dataDisks(); + if (dataDisks.size() == 0) { + this.innerModel.storageProfile().setDataDisks(null); + return; + } + + List usedLuns = new ArrayList<>(); + for (DataDisk dataDisk : dataDisks) { + if (dataDisk.lun() != -1) { + usedLuns.add(dataDisk.lun()); + } + } + + for (DataDisk dataDisk : dataDisks) { + if (dataDisk.lun() == -1) { + Integer i = 0; + while (usedLuns.contains(i)) { + i++; + } + dataDisk.setLun(i); + usedLuns.add(i); + } + + if (dataDisk.vhd() == null) { + VirtualHardDisk diskVhd = new VirtualHardDisk(); + diskVhd.setUri(blobUrl(this.storageAccountName, "vhds", + this.name() + "-data-disk-" + dataDisk.lun() + "-" + UUID.randomUUID().toString() + ".vhd")); + dataDisk.setVhd(diskVhd); + } + + if (dataDisk.name() == null) { + dataDisk.setName(this.name() + "-data-disk-" + dataDisk.lun()); + } + + if (dataDisk.caching() == null) { + dataDisk.setCaching(CachingTypes.READ_WRITE); + } + } + } + + // Helper methods + // + + private boolean isStoredImage(OSDisk osDisk) { + return osDisk.image() != null; + } + + private boolean isOSDiskAttached(OSDisk osDisk) { + return osDisk.createOption() == DiskCreateOptionTypes.ATTACH; + } + + private DataDisk prepareNewDataDisk() { + DataDisk dataDisk = new DataDisk(); + dataDisk.setLun(-1); + this.innerModel.storageProfile().dataDisks().add(dataDisk); + return dataDisk; + } + + private DataDisk currentDataDisk() { + List dataDisks = this.innerModel.storageProfile().dataDisks(); + return dataDisks.get(dataDisks.size() - 1); + } + + private String blobUrl(String storageAccountName, String containerName, String blobName) { + return storageAccountName + ".blob.core.windows.net" + "/" + containerName + "/" + blobName; + } } diff --git a/azure-mgmt-datalake-analytics/pom.xml b/azure-mgmt-datalake-analytics/pom.xml index 5e7208d023e7..7f4442405549 100644 --- a/azure-mgmt-datalake-analytics/pom.xml +++ b/azure-mgmt-datalake-analytics/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure-mgmt-datalake-store-uploader/pom.xml b/azure-mgmt-datalake-store-uploader/pom.xml index 46577f743427..20c325851f63 100644 --- a/azure-mgmt-datalake-store-uploader/pom.xml +++ b/azure-mgmt-datalake-store-uploader/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure-mgmt-datalake-store/pom.xml b/azure-mgmt-datalake-store/pom.xml index 8abd1ccf502e..68d72c736b02 100644 --- a/azure-mgmt-datalake-store/pom.xml +++ b/azure-mgmt-datalake-store/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure-mgmt-network/pom.xml b/azure-mgmt-network/pom.xml index 605d68e5c6a0..c18033a48316 100644 --- a/azure-mgmt-network/pom.xml +++ b/azure-mgmt-network/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java index 34ff20520f03..46529bbd6ecb 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java @@ -7,12 +7,16 @@ import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner; 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.Updatable; import com.microsoft.azure.management.resources.fluentcore.model.Appliable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +/** + * Public IP address + */ public interface PublicIpAddress extends GroupableResource, Refreshable, @@ -22,140 +26,234 @@ public interface PublicIpAddress extends /*********************************************************** * Getters ***********************************************************/ + + /** + * @return the assigned IP address + */ String ipAddress(); + + /** + * @return the assigned leaf domain label + */ String leafDomainLabel(); + + /** + * @return the assigned FQDN (fully qualified domain name) + */ String fqdn(); + + /** + * @return the assigned reverse FQDN, if any + */ String reverseFqdn(); + /** + * @return the IP address allocation method (Static/Dynamic) + */ + String ipAllocationMethod(); + + /** + * @return the idle connection timeout setting (in minutes) + */ + int idleTimeoutInMinutes(); + /************************************************************** * Fluent interfaces for provisioning **************************************************************/ + + /** + * Container interface for all the definitions + */ interface Definitions extends - DefinitionBlank, - DefinitionWithGroup, - DefinitionWithIpAddress, - DefinitionWithLeafDomainLabel, - DefinitionCreatable {} - - - interface DefinitionBlank extends GroupableResource.DefinitionWithRegion { + DefinitionBlank, + DefinitionWithGroup, + DefinitionWithIpAddress, + DefinitionWithLeafDomainLabel, + DefinitionCreatable {} + + /** + * The first stage of a public IP address definition + */ + interface DefinitionBlank + extends GroupableResource.DefinitionWithRegion { + } + + /** + * The stage of the public IP address definition allowing to specify the resource group + */ + interface DefinitionWithGroup + extends GroupableResource.DefinitionWithGroup { + } + + /** + * A public IP address definition allowing to set the IP allocation method (static or dynamic) + */ + interface DefinitionWithIpAddress { + /** + * Enables static IP address allocation. + *

+ * Use {@link PublicIpAddress#ipAddress()} after the public IP address is created to obtain the + * actual IP address allocated for this resource by Azure + * + * @return the next stage of the public IP address definition + */ + DefinitionCreatable withStaticIp(); + + /** + * Enables dynamic IP address allocation. + * + * @return the next stage of the public IP address definition + */ + DefinitionCreatable withDynamicIp(); } - interface DefinitionWithGroup extends GroupableResource.DefinitionWithGroup { + + /** + * A public IP address update allowing to change the IP allocation method (static or dynamic) + */ + interface UpdateWithIpAddress { + /** + * Enables static IP address allocation. + *

+ * Use {@link PublicIpAddress#ipAddress()} after the public IP address is updated to + * obtain the actual IP address allocated for this resource by Azure + * + * @return the next stage of the public IP address definition + */ + Update withStaticIp(); + + /** + * Enables dynamic IP address allocation. + * + * @return the next stage of the public IP address definition + */ + Update withDynamicIp(); } - public interface DefinitionWithIpAddress { - /** - * Enables static IP address allocation. The actual IP address allocated for this resource by Azure can be obtained - * after the provisioning process is complete from ipAddress(). - * @return The next stage of the public IP address definition - */ - DefinitionCreatable withStaticIp(); - - /** - * Enables dynamic IP address allocation. - * @return The next stage of the public IP address definition - */ - DefinitionCreatable withDynamicIp(); - } - - - public interface UpdatableWithIpAddress { - /** - * Enables static IP address allocation. The actual IP address allocated for this resource by Azure can be obtained - * after the provisioning process is complete from ipAddress(). - * @return The next stage of the public IP address definition - */ - T withStaticIp(); - - /** - * Enables dynamic IP address allocation. - * @return The next stage of the public IP address definition - */ - T withDynamicIp(); - } + + /** + * A public IP address definition allowing to specify the leaf domain label, if any + */ + interface DefinitionWithLeafDomainLabel { + /** + * Specifies the leaf domain label to associate with this public IP address. + *

+ * The fully qualified domain name (FQDN) + * will be constructed automatically by appending the rest of the domain to this label. + * @param dnsName the leaf domain label to use. This must follow the required naming convention for leaf domain names. + * @return the next stage of the public IP address definition + */ + DefinitionCreatable withLeafDomainLabel(String dnsName); - - /** - * A public IP address definition allowing to specify the leaf domain label, if any - */ - public interface DefinitionWithLeafDomainLabel { - /** - * Specifies the leaf domain label to associate with this public IP address. The fully qualified domain name (FQDN) - * will be constructed automatically by appending the rest of the domain to this label. - * @param dnsName The leaf domain label to use. This must follow the required naming convention for leaf domain names. - * @return The next stage of the public IP address definition - */ - DefinitionCreatable withLeafDomainLabel(String dnsName); - - /** - * Ensures that no leaf domain label will be used. This means that this public IP address will not be associated with a domain name. - * @return The next stage of the public IP address definition - */ - DefinitionCreatable withoutLeafDomainLabel(); - } - - - public interface UpdatableWithLeafDomainLabel { - /** - * Specifies the leaf domain label to associate with this public IP address. The fully qualified domain name (FQDN) - * will be constructed automatically by appending the rest of the domain to this label. - * @param dnsName The leaf domain label to use. This must follow the required naming convention for leaf domain names. - * @return The next stage of the public IP address definition - */ - T withLeafDomainLabel(String dnsName); - - /** - * Ensures that no leaf domain label will be used. This means that this public IP address will not be associated with a domain name. - * @return The next stage of the resource definition - */ - T withoutLeafDomainLabel(); - } - - - public interface DefinitionWithReverseFQDN { - /** - * Specifies the reverse FQDN to assign to this public IP address - * @param reverseFQDN The reverse FQDN to assign - * @return The next stage of the resource definition - */ - T withReverseFqdn(String reverseFQDN); - - /** - * Ensures that no reverse FQDN will be used. - * @return The next stage of the resource definition - */ - T withoutReverseFqdn(); - } - - public interface UpdatableWithReverseFQDN { - /** - * Specifies the reverse FQDN to assign to this public IP address - * @param reverseFQDN The reverse FQDN to assign - * @return The next stage of the resource definition - */ - T withReverseFqdn(String reverseFQDN); - - /** - * Ensures that no reverse FQDN will be used. - * @return The next stage of the resource definition - */ - T withoutReverseFqdn(); - } + /** + * Ensures that no leaf domain label will be used. + *

+ * This means that this public IP address will not be associated with a domain name. + * @return the next stage of the public IP address definition + */ + DefinitionCreatable withoutLeafDomainLabel(); + } - + + /** + * A public IP address update allowing to change the leaf domain label, if any + */ + interface UpdateWithLeafDomainLabel { + /** + * Specifies the leaf domain label to associate with this public IP address. + *

+ * The fully qualified domain name (FQDN) + * will be constructed automatically by appending the rest of the domain to this label. + * @param dnsName the leaf domain label to use. This must follow the required naming convention for leaf domain names. + * @return the next stage of the public IP address definition + */ + Update withLeafDomainLabel(String dnsName); + + /** + * Ensures that no leaf domain label will be used. + *

+ * This means that this public IP address will not be associated with a domain name. + * @return the next stage of the resource definition + */ + Update withoutLeafDomainLabel(); + } + + + /** + * A public IP address definition allowing the reverse FQDN to be specified + */ + interface DefinitionWithReverseFQDN { + /** + * Specifies the reverse FQDN to assign to this public IP address. + *

+ * + * @param reverseFQDN the reverse FQDN to assign + * @return the next stage of the resource definition + */ + T withReverseFqdn(String reverseFQDN); + + /** + * Ensures that no reverse FQDN will be used. + * @return the next stage of the resource definition + */ + T withoutReverseFqdn(); + } + + /** + * A public IP address update allowing the reverse FQDN to be specified + */ + interface UpdateWithReverseFQDN { + /** + * Specifies the reverse FQDN to assign to this public IP address + * @param reverseFQDN the reverse FQDN to assign + * @return the next stage of the resource update + */ + Update withReverseFqdn(String reverseFQDN); + + /** + * Ensures that no reverse FQDN will be used. + * @return The next stage of the resource update + */ + Update withoutReverseFqdn(); + } + + /** + * The stage of the public IP definition which contains all the minimum required inputs for + * the resource to be created (via {@link DefinitionCreatable#create()}), but also allows + * for any other optional settings to be specified. + */ interface DefinitionCreatable extends - Creatable, - DefinitionWithLeafDomainLabel, - DefinitionWithIpAddress, - DefinitionWithReverseFQDN { + Creatable, + DefinitionWithLeafDomainLabel, + DefinitionWithIpAddress, + DefinitionWithReverseFQDN, + Resource.DefinitionWithTags { + + /** + * Specifies the timeout (in minutes) for an idle connection + * @param minutes the length of the time out in minutes + * @return the next stage of the resource definition + */ + DefinitionCreatable withIdleTimeoutInMinutes(int minutes); } - + + /** + * The template for a public IP address update operation, containing all the settings that + * can be modified. + *

+ * Call {@link Update#apply()} to apply the changes to the resource in Azure. + */ interface Update extends - Appliable, - UpdatableWithIpAddress, - UpdatableWithLeafDomainLabel, - UpdatableWithReverseFQDN { + Appliable, + UpdateWithIpAddress, + UpdateWithLeafDomainLabel, + UpdateWithReverseFQDN, + Resource.UpdateWithTags { + /** + * Specifies the timeout (in minutes) for an idle connection + * @param minutes the length of the time out in minutes + * @return the next stage of the resource update + */ + Update withIdleTimeoutInMinutes(int minutes); } } - diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java index 89286f9bae5c..43914a4b3f21 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java @@ -13,18 +13,25 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsGetting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to public IP address management + */ public interface PublicIpAddresses extends - SupportsCreating, - SupportsListing, - SupportsListingByGroup, - SupportsGetting, - SupportsGettingByGroup, - SupportsDeleting, - SupportsDeletingByGroup { + SupportsCreating, + SupportsListing, + SupportsListingByGroup, + SupportsGetting, + SupportsGettingByGroup, + SupportsDeleting, + SupportsDeletingByGroup { - interface InGroup extends + /** + * Entry point to public IP address management within a specific resource group + */ + public interface InGroup extends SupportsListing, - SupportsCreating, + SupportsCreating, SupportsDeleting { } } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java index a355bef58a04..643c1377f76b 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java @@ -6,7 +6,7 @@ package com.microsoft.azure.management.network.implementation; import com.microsoft.azure.management.network.PublicIpAddress; -import com.microsoft.azure.management.network.implementation.api.PublicIPAddressDnsSettings; +import com.microsoft.azure.management.network.implementation.api.IPAllocationMethod; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressesInner; import com.microsoft.azure.management.resources.ResourceGroups; @@ -20,15 +20,13 @@ class PublicIpAddressImpl PublicIpAddress.Definitions, PublicIpAddress.Update { - private String name; private final PublicIPAddressesInner client; PublicIpAddressImpl(String name, PublicIPAddressInner innerModel, final PublicIPAddressesInner client, final ResourceGroups resourceGroups) { - super(innerModel.id(), innerModel, resourceGroups); - this.name = name; + super(name, innerModel, resourceGroups); this.client = client; } @@ -36,13 +34,22 @@ class PublicIpAddressImpl * Verbs **************************************************/ + @Override + public PublicIpAddressImpl apply() throws Exception { + return this.create(); + } + + @Override + public PublicIpAddressImpl update() throws Exception { + return this; + } + @Override public PublicIpAddress refresh() throws Exception { ServiceResponse response = this.client.get(this.resourceGroupName(), this.name()); PublicIPAddressInner inner = response.getBody(); this.setInner(inner); - clearWrapperProperties(); return this; } @@ -51,36 +58,37 @@ public PublicIpAddressImpl create() throws Exception { super.create(); ServiceResponse response = - this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner()); + this.client.createOrUpdate(this.resourceGroupName(), this.key(), this.inner()); this.setInner(response.getBody()); - clearWrapperProperties(); return this; } - private void clearWrapperProperties() { - - } - /***************************************** * Setters (fluent) *****************************************/ - + + @Override + public PublicIpAddressImpl withIdleTimeoutInMinutes(int minutes) { + this.inner().setIdleTimeoutInMinutes(minutes); + return this; + } + @Override public PublicIpAddressImpl withStaticIp() { - this.inner().setPublicIPAllocationMethod("Static"); // TODO: Replace with IpAllocationMethod.STATIC + this.inner().setPublicIPAllocationMethod(IPAllocationMethod.STATIC); return this; } @Override public PublicIpAddressImpl withDynamicIp() { - this.inner().setPublicIPAllocationMethod("Dynamic"); // TODO: Replace with IpAllocationMethod.DYNAMIC + this.inner().setPublicIPAllocationMethod(IPAllocationMethod.DYNAMIC); return this; } @Override public PublicIpAddressImpl withLeafDomainLabel(String dnsName) { - ensureDnsSettings().setDomainNameLabel(dnsName.toLowerCase()); + this.inner().dnsSettings().setDomainNameLabel(dnsName.toLowerCase()); return this; } @@ -91,7 +99,7 @@ public PublicIpAddressImpl withoutLeafDomainLabel() { @Override public PublicIpAddressImpl withReverseFqdn(String reverseFqdn) { - ensureDnsSettings().setReverseFqdn(reverseFqdn.toLowerCase()); + this.inner().dnsSettings().setReverseFqdn(reverseFqdn.toLowerCase()); return this; } @@ -100,20 +108,20 @@ public PublicIpAddressImpl withoutReverseFqdn() { return this.withReverseFqdn(null); } - - private PublicIPAddressDnsSettings ensureDnsSettings() { - PublicIPAddressDnsSettings dnsSettings; - if(null == (dnsSettings = this.inner().dnsSettings())) { - dnsSettings = new PublicIPAddressDnsSettings(); - this.inner().setDnsSettings(dnsSettings); - } - return dnsSettings; - } - - + /********************************************** * Getters **********************************************/ + @Override + public int idleTimeoutInMinutes() { + return this.inner().idleTimeoutInMinutes(); + } + + @Override + public String ipAllocationMethod() { // TODO: This should really return an enum + return this.inner().publicIPAllocationMethod(); + } + @Override public String fqdn() { return this.inner().dnsSettings().fqdn(); @@ -124,11 +132,6 @@ public String reverseFqdn() { return this.inner().dnsSettings().reverseFqdn(); } - @Override - public String name() { - return this.name; - } - @Override public String ipAddress() { return this.inner().ipAddress(); @@ -142,14 +145,4 @@ public String leafDomainLabel() { return this.inner().dnsSettings().domainNameLabel(); } } - - @Override - public PublicIpAddressImpl apply() throws Exception { - return this.create(); - } - - @Override - public PublicIpAddressImpl update() throws Exception { - return this; - } } \ No newline at end of file diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java index db57a1380f18..26815962f873 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java @@ -10,6 +10,7 @@ import com.microsoft.azure.PagedList; import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.network.PublicIpAddresses; +import com.microsoft.azure.management.network.implementation.api.PublicIPAddressDnsSettings; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressesInner; import com.microsoft.azure.management.resources.ResourceGroups; @@ -33,8 +34,8 @@ class PublicIpAddressesImpl this.resourceGroups = resourceGroups; this.converter = new PagedListConverter() { @Override - public PublicIpAddress typeConvert(PublicIPAddressInner publicIpAddressInner) { - return createFluentModel(publicIpAddressInner); + public PublicIpAddress typeConvert(PublicIPAddressInner inner) { + return createFluentModel(inner); } }; } @@ -52,7 +53,7 @@ public PagedList list(String groupName) throws CloudException, } @Override - public PublicIpAddress get(String id) throws CloudException, IOException { + public PublicIpAddressImpl get(String id) throws CloudException, IOException { PublicIPAddressInner inner = client.get( ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)).getBody(); @@ -60,7 +61,7 @@ public PublicIpAddress get(String id) throws CloudException, IOException { } @Override - public PublicIpAddress get(String groupName, String name) throws CloudException, IOException { + public PublicIpAddressImpl get(String groupName, String name) throws CloudException, IOException { ServiceResponse serviceResponse = this.client.get(groupName, name); return createFluentModel(serviceResponse.getBody()); } @@ -76,7 +77,7 @@ public void delete(String groupName, String name) throws Exception { } @Override - public PublicIpAddress.DefinitionBlank define(String name) { + public PublicIpAddressImpl define(String name) { return createFluentModel(name); } @@ -96,9 +97,15 @@ public Page nextPage(String nextPageLink) throws RestExcep private PublicIpAddressImpl createFluentModel(String name) { PublicIPAddressInner inner = new PublicIPAddressInner(); + + if(null == inner.dnsSettings()) { + inner.setDnsSettings(new PublicIPAddressDnsSettings()); + } + return new PublicIpAddressImpl(name, inner, this.client, this.resourceGroups); } + private PublicIpAddressImpl createFluentModel(PublicIPAddressInner inner) { return new PublicIpAddressImpl(inner.name(), inner, this.client, this.resourceGroups); } diff --git a/azure-mgmt-resources/pom.xml b/azure-mgmt-resources/pom.xml index 92d7d509f7b1..c224c53acc8e 100644 --- a/azure-mgmt-resources/pom.xml +++ b/azure-mgmt-resources/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java index 8cde0398eeca..10ba6f35cdec 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java @@ -1,13 +1,11 @@ package com.microsoft.azure.management.resources; -import com.microsoft.azure.management.resources.fluentcore.arm.models.Taggable; import com.microsoft.azure.management.resources.fluentcore.model.*; 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.implementation.api.GenericResourceInner; import com.microsoft.azure.management.resources.implementation.api.Plan; -import java.util.Map; - public interface GenericResource extends GroupableResource, Refreshable, @@ -43,16 +41,10 @@ interface DefinitionWithPlan { DefinitionCreatable withPlan(String name, String publisher, String product, String promotionCode); } - interface DefinitionCreatable extends Creatable { // Properties, tags are optional + interface DefinitionCreatable extends + Creatable, + Resource.DefinitionWithTags { + DefinitionCreatable withProperties(Object properties); - DefinitionCreatable withTags(Map tags); - DefinitionCreatable withTag(String key, String value); - } - - // TODO: Updatable properties needs to be revised. - interface Update extends UpdateBlank, Appliable { - } - - interface UpdateBlank extends Taggable { } } \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroup.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroup.java index ff7dde3048f1..6d79c8b1e1cb 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroup.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroup.java @@ -1,7 +1,7 @@ package com.microsoft.azure.management.resources; import com.microsoft.azure.management.resources.fluentcore.arm.Region; -import com.microsoft.azure.management.resources.fluentcore.arm.models.Taggable; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; import com.microsoft.azure.management.resources.fluentcore.model.*; import com.microsoft.azure.management.resources.implementation.api.ResourceGroupInner; @@ -35,11 +35,11 @@ interface DefinitionCreatable extends Creatable { DefinitionCreatable withTag(String key, String value); } - interface Update extends UpdateBlank, Appliable { + interface Update extends + Appliable, + Resource.UpdateWithTags { } - interface UpdateBlank extends Taggable { - } /************************************************************** * Adapter to other resources diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroups.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroups.java index 5caee92c14d0..a39d6ec331e7 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroups.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroups.java @@ -10,6 +10,6 @@ public interface ResourceGroups extends SupportsGetting, SupportsCreating, SupportsDeleting, - SupportsUpdating { + SupportsUpdating { boolean checkExistence(String name) throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java index 0aedd4c77b83..db1d234251ea 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java @@ -8,7 +8,7 @@ public enum Region { US_CENTRAL("centralus", "Central US"), US_EAST("eastus", "East US"), US_EAST2("eastus2", "East US 2"), - US_NORTH_CENTRAL("nothcentralus", "North Central US"), + US_NORTH_CENTRAL("northcentralus", "North Central US"), US_SOUTH_CENTRAL("southcentralus", "South Central US"), EUROPE_NORTH("northeurope", "North Europe"), EUROPE_WEST("westeurope", "West Europe"), diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsDeletingByGroup.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsDeletingByGroup.java index 1b84b9e11367..b5c3d57dc3a6 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsDeletingByGroup.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsDeletingByGroup.java @@ -19,11 +19,16 @@ */ package com.microsoft.azure.management.resources.fluentcore.arm.collection; +/** + * Provides access to deleting a resource from Azure, identifying it by its name and its resource group + *

+ * (Note: this interface is not intended to be implemented by user code) + */ public interface SupportsDeletingByGroup { /** - * Deletes a resource from a specific group - * @param groupName The group the resource is part of - * @param name The name of the resource within that group + * Deletes a resource from Azure, identifying it by its name and its resource group + * @param groupName the group the resource is part of + * @param name The name of the resource * @throws Exception */ void delete(String groupName, String name) throws Exception; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByGroup.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByGroup.java index 6b92f205244b..1369776eae4e 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByGroup.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByGroup.java @@ -24,7 +24,19 @@ import java.io.IOException; -// Requires class to support reading entities with a supplied group name +/** + * Provides access to getting a specific Azure resource based on its name and resource group + *

+ * (Note: this interface is not intended to be implemented by user code) + */ public interface SupportsGettingByGroup { + /** + * Gets the information about a resource from Azure based on the resource name and the name of its resource group + * @param groupName the name of the resource group the resource is in + * @param name the name of the resource. (Note, this is not the ID) + * @return an immutable representation of the resource + * @throws CloudException + * @throws IOException + */ T get(String groupName, String name) throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsListingByGroup.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsListingByGroup.java index 6acda3c4d0ee..640c9128ac62 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsListingByGroup.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsListingByGroup.java @@ -24,13 +24,16 @@ import com.microsoft.azure.PagedList; import java.io.IOException; -import java.util.List; +/** + * Provides access to listing Azure resources of a specific type in a specific resource group + *

+ * (Note: this interface is not intended to be implemented by user code) +*/ public interface SupportsListingByGroup { - /** - * List of the entities in a specific group - * @param groupName - * @return + /** Lists resources of the specified type in the specified resource group + * @param groupName the name of the resource group to list the resources from + * @return list of resources * @throws Exception */ PagedList list(String groupName) throws CloudException, IOException; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java index 4529b294175f..f9fa15afd834 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java @@ -17,22 +17,69 @@ public interface Resource extends Indexable { */ interface DefinitionWithRegion { /** - * @param regionName The name of the location for the resource - * @return The next stage of the resource definition + * @param regionName The name of the region for the resource + * @return the next stage of the resource definition */ T withRegion(String regionName); /** * @param region The location for the resource - * @return The next stage of the resource definition + * @return the next stage of the resource definition */ T withRegion(Region region); } + /** + * A resource definition allowing tags to be modified for the resource + */ + interface DefinitionWithTags { + /** + * Specifies tags for the resource as a {@link Map}. + * @param tags a {@link Map} of tags + * @return the next stage of the resource definition + */ + T withTags(Map tags); + + /** + * Adds a tag to the resource. + * @param key the key for the tag + * @param value the value for the tag + * @return the next stage of the resource definition + */ + T withTag(String key, String value); + + /** + * Removes a tag from the resource + * @param key the key of the tag to remove + * @return the next stage of the resource definition + */ + T withoutTag(String key); + } /** - * A resource definition allowing tags to be specified + * An update allowing tags to be modified for the resource */ - interface DefinitionWithTags extends Taggable { + interface UpdateWithTags { + /** + * Specifies tags for the resource as a {@link Map}. + * @param tags a {@link Map} of tags + * @return the next stage of the resource update + */ + T withTags(Map tags); + + /** + * Adds a tag to the resource. + * @param key the key for the tag + * @param value the value for the tag + * @return the next stage of the resource definition + */ + T withTag(String key, String value); + + /** + * Removes a tag from the resource + * @param key the key of the tag to remove + * @return the next stage of the resource definition + */ + T withoutTag(String key); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Taggable.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Taggable.java deleted file mode 100644 index ca8ea942d6ae..000000000000 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Taggable.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.microsoft.azure.management.resources.fluentcore.arm.models; - -import java.util.Map; - -public interface Taggable { - T withTags(Map tags); - T withTag(String key, String value); - T withoutTag(String key); -} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupableResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupableResourceImpl.java index a5817954eea9..ea5a4f34575b 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupableResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupableResourceImpl.java @@ -63,7 +63,7 @@ public final FluentModelImplT withNewGroup(String groupName) { } public final FluentModelImplT withNewGroup() { - return this.withNewGroup(this.name() + "group"); + return this.withNewGroup(this.key() + "group"); } @SuppressWarnings("unchecked") diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java index 69fced1709bb..9e8c02f10010 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java @@ -7,6 +7,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; public abstract class ResourceImpl< FluentModelT, @@ -20,6 +21,11 @@ public abstract class ResourceImpl< protected ResourceImpl(String key, InnerModelT innerObject) { super(key, innerObject); + + // Initialize tags + if(innerObject.getTags() == null) { + innerObject.setTags(new TreeMap()); + } } /******************************************* @@ -33,7 +39,11 @@ public String region() { @Override public Map tags() { - return Collections.unmodifiableMap(this.inner().getTags()); + Map tags = this.inner().getTags(); + if(tags == null) { + tags = new TreeMap(); + } + return Collections.unmodifiableMap(tags); } @Override diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsCreating.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsCreating.java index fa697806c85d..9b0071e3e2ff 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsCreating.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsCreating.java @@ -19,8 +19,30 @@ */ package com.microsoft.azure.management.resources.fluentcore.collection; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; -// Requires class to support creating entities +/** + * Providing access to creating Azure top level resources + *

+ * (Note: this interface is not intended to be implemented by user code) + * @param T the initial blank definition interface + */ public interface SupportsCreating { + /** + * Begins a definition for a new resource. + *

+ * This is the beginning of the builder pattern used to create top level resources + * in Azure. The final method completing the definition and starting the actual resource creation + * process in Azure is {@link Creatable#create()}. + *

+ * Note that the {@link Creatable#create()} method is + * only available at the stage of the resource definition that has the minimum set of input + * parameters specified. If you do not see {@link Creatable#create()} among the available methods, it + * means you have not yet specified all the required input settings. Input settings generally begin + * with the word "with", for example: .withNewResourceGroup() and return the next stage + * of the resource definition, as an interface in the "fluent interface" style. + * @param name the name of the new resource + * @return the first stage of the new resource definition + */ T define(String name); } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsDeleting.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsDeleting.java index ac71e974ba58..27cc07a16a2b 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsDeleting.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsDeleting.java @@ -19,7 +19,16 @@ */ package com.microsoft.azure.management.resources.fluentcore.collection; -// Requires class to support deleting entities +/** + * Provides access to deleting a resource from Azure, identifying it by its resource ID + *

+ * (Note: this interface is not intended to be implemented by user code) + */ public interface SupportsDeleting { + /** + * Deletes a resource from Azure, identifying it by its resource ID + * @param id the resource ID of the resource to delete + * @throws Exception + */ void delete(String id) throws Exception; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsGetting.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsGetting.java index cd3093618da9..5ef65f6f5d32 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsGetting.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsGetting.java @@ -23,7 +23,19 @@ import java.io.IOException; -// Requires class to support reading entities +/** + * Provides access to getting a specific Azure resource based on its ID + *

+ * (Note: this interface is not intended to be implemented by user code) + */ public interface SupportsGetting { - T get(String name) throws CloudException, IOException; + /** + * Gets the information about a resource from Azure based on the resource ID + *

+ * @param id the full ID of the resource + * @return an immutable representation of the resource + * @throws CloudException + * @throws IOException + */ + T get(String id) throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java index 275cfa5abef1..285f30fa84fa 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListing.java @@ -23,9 +23,18 @@ import com.microsoft.azure.PagedList; import java.io.IOException; -import java.util.List; -// Requires class to support listing entities +/** + * Provides access to listing Azure resources of a specific type in a subscription + *

+ * (Note: this interface is not intended to be implemented by user code) + */ public interface SupportsListing { + /** + * Lists all the resources of the specified type in the currently selected subscription + * @return list of resources + * @throws CloudException + * @throws IOException + */ PagedList list() throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListingByLocation.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListingByLocation.java index c2dbe5263335..abeaec686030 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListingByLocation.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsListingByLocation.java @@ -25,7 +25,18 @@ import java.io.IOException; import java.util.List; -// Requires class to support listing entities +/** + * Provides access to listing Azure resources of a specific type based on their region (location) + *

+ * (Note: this interface is not intended to be implemented by user code) + */ public interface SupportsListingByLocation { - List list(Region location) throws CloudException, IOException; + /** + * Lists all the resources of the specified type in the specified region + * @param region the Azure region to list the resources from + * @return list of resources + * @throws CloudException + * @throws IOException + */ + List list(Region region) throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsUpdating.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsUpdating.java index 503d808e69bd..f496b24ad2cd 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsUpdating.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsUpdating.java @@ -20,7 +20,28 @@ package com.microsoft.azure.management.resources.fluentcore.collection; -// Requires class to support updating entities +/** + * Provides access to updating a specific Azure resource, based on its resource ID + *

+ * (Note: this interface is not intended to be implemented by user code) + */ public interface SupportsUpdating { - T update(String name); + + /** + * Begins an update definition for an existing resource. + *

+ * This is the beginning of the builder pattern used to modify top level resources + * in Azure. The final method completing the update definition and starting the actual resource update + * process in Azure is {@link Appliable#apply()}. + *

+ * Note that the {@link Appliable#apply()} method is available at any stage of the update definition + * because all the updatable settings are generally optional. + *

Settings typically begin + * with the word "with", for example: .withRegion() and return the update definition itself, to enable chaining + * in the fluent interface style. + * @param id the resource id of the resource to update. Remember to call {@see Appliable#apply()} for the changes + * to go into effect on Azure. + * @return the update definition itself + */ + T update(String id); } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionImpl.java index 02d793e13d0c..91e8063e12bc 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionImpl.java @@ -4,7 +4,6 @@ import com.microsoft.azure.PagedList; import com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableWrapperImpl; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; -import com.microsoft.azure.management.resources.implementation.api.SubscriptionClientImpl; import com.microsoft.azure.management.resources.implementation.api.SubscriptionsInner; import com.microsoft.azure.management.resources.Location; import com.microsoft.azure.management.resources.Subscription; diff --git a/azure-mgmt-storage/pom.xml b/azure-mgmt-storage/pom.xml index 7c4562ab409f..10f7d0f4e229 100644 --- a/azure-mgmt-storage/pom.xml +++ b/azure-mgmt-storage/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure-mgmt-website/pom.xml b/azure-mgmt-website/pom.xml index 49b09faac139..2f164369f09c 100644 --- a/azure-mgmt-website/pom.xml +++ b/azure-mgmt-website/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure/pom.xml b/azure/pom.xml index 9576bddf917a..419917f0fcb2 100644 --- a/azure/pom.xml +++ b/azure/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml diff --git a/azure/src/main/java/com/microsoft/azure/implementation/Azure.java b/azure/src/main/java/com/microsoft/azure/implementation/Azure.java index 97b1647d4b8a..852d33834072 100644 --- a/azure/src/main/java/com/microsoft/azure/implementation/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/implementation/Azure.java @@ -7,6 +7,8 @@ package com.microsoft.azure.implementation; import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.compute.AvailabilitySets; import com.microsoft.azure.management.compute.VirtualMachines; @@ -15,6 +17,7 @@ import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.Deployments; import com.microsoft.azure.management.resources.GenericResources; +import com.microsoft.azure.management.resources.Subscription; import com.microsoft.azure.management.resources.Subscriptions; import com.microsoft.azure.management.resources.Tenants; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; @@ -37,7 +40,8 @@ public final class Azure { private final StorageManager storageManager; private final ComputeManager computeManager; private final NetworkManager networkManager; - + private final String subscriptionId; + public static Authenticated authenticate(ServiceClientCredentials credentials) { return new AuthenticatedImpl( AzureEnvironment.AZURE.newRestClientBuilder() @@ -46,27 +50,34 @@ public static Authenticated authenticate(ServiceClientCredentials credentials) { } /** - * Authenticates API access using a properties file containing the required credentials - * @param credentialsFile The file containing the credentials in the standard Java properties file format, - * with the following keys: - * subscription= - * tenant= - * client= - * key= - * managementURI= - * baseURL= - * authURL= - * @return Authenticated Azure client + * Authenticates API access using a properties file containing the required credentials. + * @param credentialsFile the file containing the credentials in the standard Java properties file format, + * with the following keys:

+ * + * subscription= #subscription ID
+ * tenant= #tenant ID
+ * client= #client id
+ * key= #client key
+ * managementURI= #management URI
+ * baseURL= #base URL
+ * authURL= #authentication URL
+ *
+ * @return authenticated Azure client * @throws IOException + * @throws CloudException */ public static Authenticated authenticate(File credentialsFile) throws IOException { ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credentialsFile); return new AuthenticatedImpl(AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) - .build()) - .withDefaultSubscription(credentials.defaultSubscriptionId()); + .build()).withDefaultSubscription(credentials.defaultSubscriptionId()); } + /** + * Authenticates API access using a {@link RestClient} instance. + * @param restClient the {@link RestClient} configured with Azure authentication credentials + * @return authenticated Azure client + */ public static Authenticated authenticate(RestClient restClient) { return new AuthenticatedImpl(restClient); } @@ -84,19 +95,12 @@ public interface Configurable extends AzureConfigurable { Authenticated authenticate(ServiceClientCredentials credentials); /** - * Authenticates API access using a properties file containing the required credentials - * @param credentialsFile The file containing the credentials in the standard Java properties file format, - * with the following keys: - * subscription= - * tenant= - * client= - * key= - * managementURI= - * baseURL= - * authURL= - * @return Authenticated Azure client - * @throws IOException - */ + * Authenticates API access using a properties file containing the required credentials. + * @param credentialsFile the file containing the credentials in the standard Java properties file format following + * the same schema as {@link Azure#authenticate(File)}.

+ * @return Authenticated Azure client + * @throws IOException + */ Authenticated authenticate(File credentialsFile) throws IOException; } @@ -114,11 +118,42 @@ public Authenticated authenticate(File credentialsFile) throws IOException { } + /** + * Provides authenticated access to a subset of Azure APIs that do not require a specific subscription. + *

+ * To access the subscription-specific APIs, use {@link Authenticated#withSubscription(String)}, + * or {@link Authenticated#withDefaultSubscription()} if a default subscription has already been previously specified + * (for example, in a previously specified authentication file). + * @see Azure#authenticate(File) + */ public interface Authenticated { + /** + * Entry point to subscription management + * @return Subscriptions interface providing access to subscription management + */ Subscriptions subscriptions(); Tenants tenants(); + + /** + * Selects a specific subscription for the APIs to work with. + *

+ * Most Azure APIs require a specific subscription to be selected. + * @param subscriptionId the ID of the subscription + * @return an authenticated Azure client configured to work with the specified subscription + */ Azure withSubscription(String subscriptionId); - Azure withDefaultSubscription(); + + /** + * Selects the default subscription as the subscription for the APIs to work with. + *

+ * The default subscription can be specified inside the authentication file using {@link Azure#authenticate(File)}. + * If no default subscription has been previously provided, the first subscription as + * returned by {@link Authenticated#subscriptions()} will be selected. + * @return an authenticated Azure client configured to work with the default subscription + * @throws IOException + * @throws CloudException + */ + Azure withDefaultSubscription() throws CloudException, IOException; } private static final class AuthenticatedImpl implements Authenticated { @@ -131,8 +166,8 @@ private AuthenticatedImpl(RestClient restClient) { this.restClient = restClient; } - private AuthenticatedImpl withDefaultSubscription(String subscriptionId) { - this.defaultSubscription = subscriptionId; + private AuthenticatedImpl withDefaultSubscription(String subscriptionId) throws IOException { + this.defaultSubscription = subscriptionId; return this; } @@ -152,8 +187,17 @@ public Azure withSubscription(String subscriptionId) { } @Override - public Azure withDefaultSubscription() { - return withSubscription(this.defaultSubscription); + public Azure withDefaultSubscription() throws CloudException, IOException { + if(this.defaultSubscription != null) { + return withSubscription(this.defaultSubscription); + } else { + PagedList subs = this.subscriptions().list(); + if(!subs.isEmpty()) { + return withSubscription(subs.get(0).subscriptionId()); + } else { + return withSubscription(null); + } + } } } @@ -161,15 +205,15 @@ public interface ResourceGroups extends SupportsListing, SupportsGetting, SupportsCreating, SupportsDeleting, - SupportsUpdating { + SupportsUpdating { } public interface ResourceGroup extends com.microsoft.azure.management.resources.ResourceGroup { Deployments.InGroup deployments(); StorageAccounts.InGroup storageAccounts(); - // VirtualMachinesInGroup virtualMachines(); + // VirtualMachinesInGroup virtualMachines(); //TODO AvailabilitySets.InGroup availabilitySets(); - // VirtualNetworksInGroup virtualNetworks(); + // VirtualNetworksInGroup virtualNetworks(); //TODO } private Azure(RestClient restClient, String subscriptionId) { @@ -180,8 +224,20 @@ private Azure(RestClient restClient, String subscriptionId) { this.storageManager = StorageManager.authenticate(restClient, subscriptionId); this.computeManager = ComputeManager.authenticate(restClient, subscriptionId); this.networkManager = NetworkManager.authenticate(restClient, subscriptionId); + this.subscriptionId = subscriptionId; } + /** + * @return the currently selected subscription ID this client is configured to work with + */ + public String subscriptionId() { + return this.subscriptionId; + } + + /** + * Entry point to managing resource groups + * @return the {@link ResourceGroups} interface exposing the resource group management functionality + */ public ResourceGroups resourceGroups() { return resourceGroups; } @@ -190,6 +246,10 @@ public GenericResources genericResources() { return resourceManager.genericResources(); } + /** + * Entry point to managing storage accounts. + * @return the {@link StorageAccounts} interface exposing the storage account management functionality + */ public StorageAccounts storageAccounts() { return storageManager.storageAccounts(); } @@ -198,14 +258,26 @@ public Usages storageUsages() { return storageManager.usages(); } + /** + * Entry point to managing availability sets. + * @return the {@link AvailabilitySets} interface exposing the availability set management functionality + */ public AvailabilitySets availabilitySets() { return computeManager.availabilitySets(); } + /** + * Entry point to managing virtual machines. + * @return the {@link VirtualMachines} interface exposing the virtual machine management functionality + */ public VirtualMachines virtualMachines() { return computeManager.virtualMachines(); } + /** + * Entry point to managing public IP addresses. + * @return the {@link PublicIpAddresses} interface exposing the public IP address management functionality + */ public PublicIpAddresses publicIpAddresses() { return this.networkManager.publicIpAddresses(); } diff --git a/azure/src/main/java/com/microsoft/azure/implementation/AzureResourceGroupsImpl.java b/azure/src/main/java/com/microsoft/azure/implementation/AzureResourceGroupsImpl.java index 54aa961ab0f6..039e464baaa6 100644 --- a/azure/src/main/java/com/microsoft/azure/implementation/AzureResourceGroupsImpl.java +++ b/azure/src/main/java/com/microsoft/azure/implementation/AzureResourceGroupsImpl.java @@ -53,7 +53,7 @@ public void delete(String name) throws Exception { } @Override - public Azure.ResourceGroup.UpdateBlank update(String name) { + public Azure.ResourceGroup.Update update(String name) { return resourceGroupsCore.update(name); } diff --git a/azure/src/test/java/com/microsoft/azure/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java index 09aa93a901f9..3a42e6339e18 100644 --- a/azure/src/test/java/com/microsoft/azure/AzureTests.java +++ b/azure/src/test/java/com/microsoft/azure/AzureTests.java @@ -1,8 +1,12 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ package com.microsoft.azure; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.implementation.Azure; -import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.resources.Subscriptions; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.storage.StorageAccount; @@ -28,84 +32,52 @@ public class AzureTests { private Azure azure, azure2; public static void main(String[] args) throws IOException, CloudException { - final File credFile = new File("azureauth.properties"); - Azure azure = Azure.authenticate(credFile) - .withDefaultSubscription(); - System.out.println(String.valueOf(azure.resourceGroups().list().size())); - - Azure.configure().withLogLevel(Level.BASIC).authenticate(credFile); - System.out.println(String.valueOf(azure.resourceGroups().list().size())); + final File credFile = new File("my.azureauth"); + Azure azure = Azure.authenticate(credFile).withDefaultSubscription(); + System.out.println(String.valueOf(azure.resourceGroups().list().size())); + + Azure.configure().withLogLevel(Level.BASIC).authenticate(credFile); + System.out.println("Selected subscription: " + azure.subscriptionId()); + System.out.println(String.valueOf(azure.resourceGroups().list().size())); + + final File authFileNoSubscription = new File("nosub.azureauth"); + azure = Azure.authenticate(authFileNoSubscription).withDefaultSubscription(); + System.out.println("Selected subscription: " + azure.subscriptionId()); + System.out.println(String.valueOf(azure.resourceGroups().list().size())); } - + @Before public void setup() throws Exception { // Authenticate based on credentials instance - Azure.Authenticated azureAuthed = Azure.configure() + Azure.Authenticated azureAuthed = Azure.configure() .withLogLevel(HttpLoggingInterceptor.Level.BASIC) .withUserAgent("AzureTests") .authenticate(credentials); subscriptions = azureAuthed.subscriptions(); azure = azureAuthed.withSubscription(subscriptionId); - + // Authenticate based on file - this.azure2 = Azure.authenticate(new File("my.auth")) - .withDefaultSubscription(); + this.azure2 = Azure.authenticate(new File("my.azureauth")) + .withDefaultSubscription(); } /** - * Tests the Public IP Address implementation + * Tests the public IP address implementation * @throws Exception */ @Test public void testPublicIpAddresses() throws Exception { - // Verify creation of a new public IP address - String suffix = String.valueOf(System.currentTimeMillis()); - String newPipName = "pip" + suffix; - PublicIpAddress pip = azure2.publicIpAddresses().define(newPipName) - .withRegion(Region.US_WEST) - .withNewGroup() - .withDynamicIp() - .withLeafDomainLabel(newPipName) - .create(); - - // Verify list - int publicIpAddressCount = azure2.publicIpAddresses().list().size(); - System.out.println(publicIpAddressCount); - Assert.assertTrue(0 < publicIpAddressCount); - - // Verify get - String resourceGroupName = pip.resourceGroupName(); - pip = azure2.publicIpAddresses().get(resourceGroupName, newPipName); - Assert.assertTrue(pip.name().equalsIgnoreCase(newPipName)); - printPublicIpAddress(pip); - - // Verify update - pip = pip.update() - .withStaticIp() - .withLeafDomainLabel(newPipName + "xx") - .withReverseFqdn(pip.leafDomainLabel() + "." + pip.region() + ".cloudapp.azure.com") - .apply(); - printPublicIpAddress(pip); - pip = azure2.publicIpAddresses().get(pip.id()); - printPublicIpAddress(pip); - - // Verify delete - azure2.publicIpAddresses().delete(pip.id()); - azure2.resourceGroups().delete(resourceGroupName); - azure2.resourceGroups().delete(pip.resourceGroupName()); + new TestPublicIpAddress().runTest(azure2, azure2.publicIpAddresses()); } - - private void printPublicIpAddress(PublicIpAddress pip) { - System.out.println(new StringBuilder().append("Public IP Address: ").append(pip.id()) - .append("\n\tIP Address: ").append(pip.ipAddress()) - .append("\n\tLeaf domain label: ").append(pip.leafDomainLabel()) - .append("\n\tResource group: ").append(pip.resourceGroupName()) - .append("\n\tFQDN: ").append(pip.fqdn()) - .append("\n\tReverse FQDN: ").append(pip.reverseFqdn()) - .toString()); + + /** + * Tests the availability set implementation + * @throws Exception + */ + @Test public void testAvailabilitySets() throws Exception { + new TestAvailabilitySet().runTest(azure2, azure2.availabilitySets()); } - @Test public void listSubscriptions() throws Exception { Assert.assertTrue(0 < subscriptions.list().size()); diff --git a/azure/src/test/java/com/microsoft/azure/TestAvailabilitySet.java b/azure/src/test/java/com/microsoft/azure/TestAvailabilitySet.java new file mode 100644 index 000000000000..54427f990097 --- /dev/null +++ b/azure/src/test/java/com/microsoft/azure/TestAvailabilitySet.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ +package com.microsoft.azure; + +import org.junit.Assert; + +import com.microsoft.azure.implementation.Azure; +import com.microsoft.azure.management.compute.AvailabilitySet; +import com.microsoft.azure.management.compute.AvailabilitySets; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; + +public class TestAvailabilitySet extends TestTemplate { + + @Override + public AvailabilitySet createResource(Azure azure) throws Exception { + final String newName = "as" + this.testId; + return azure.availabilitySets().define(newName) + .withRegion(Region.US_WEST) + .withNewGroup() + .withFaultDomainCount(2) + .withUpdateDomainCount(4) + .withTag("tag1", "value1") + .create(); + } + + @Override + public AvailabilitySet updateResource(AvailabilitySet resource) throws Exception { + resource = resource.update() + .withTag("tag2", "value2") + .withTag("tag3", "value3") + .withoutTag("tag1") + .apply(); + Assert.assertTrue(resource.tags().containsKey("tag2")); + Assert.assertTrue(!resource.tags().containsKey("tag1")); + return resource; + } + + @Override + public void print(AvailabilitySet resource) { + System.out.println(new StringBuilder().append("Availability Set: ").append(resource.id()) + .append("Name: ").append(resource.name()) + .append("\n\tResource group: ").append(resource.resourceGroupName()) + .append("\n\tRegion: ").append(resource.region()) + .append("\n\tTags: ").append(resource.tags()) + .append("\n\tFault domain count: ").append(resource.faultDomainCount()) + .append("\n\tUpdate domain count: ").append(resource.updateDomainCount()) + .toString()); + } +} diff --git a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java new file mode 100644 index 000000000000..cea491d18b3d --- /dev/null +++ b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ +package com.microsoft.azure; + +import org.junit.Assert; + +import com.microsoft.azure.implementation.Azure; +import com.microsoft.azure.management.network.PublicIpAddress; +import com.microsoft.azure.management.network.PublicIpAddresses; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; + +public class TestPublicIpAddress extends TestTemplate { + + @Override + public PublicIpAddress createResource(Azure azure) throws Exception { + final String newPipName = "pip" + this.testId; + return azure.publicIpAddresses().define(newPipName) + .withRegion(Region.US_WEST) + .withNewGroup() + .withDynamicIp() + .withLeafDomainLabel(newPipName) + .withIdleTimeoutInMinutes(10) + .create(); + } + + @Override + public PublicIpAddress updateResource(PublicIpAddress resource) throws Exception { + final String updatedDnsName = resource.leafDomainLabel() + "xx"; + final int updatedIdleTimeout = 15; + resource = resource.update() + .withStaticIp() + .withLeafDomainLabel(updatedDnsName) + .withReverseFqdn(resource.leafDomainLabel() + "." + resource.region() + ".cloudapp.azure.com") + .withIdleTimeoutInMinutes(updatedIdleTimeout) + .withTag("tag1", "value1") + .withTag("tag2", "value2") + .apply(); + Assert.assertTrue(resource.leafDomainLabel().equalsIgnoreCase(updatedDnsName)); + Assert.assertTrue(resource.idleTimeoutInMinutes()==updatedIdleTimeout); + return resource; + } + + @Override + public void print(PublicIpAddress resource) { + System.out.println(new StringBuilder().append("Public IP Address: ").append(resource.id()) + .append("Name: ").append(resource.name()) + .append("\n\tResource group: ").append(resource.resourceGroupName()) + .append("\n\tRegion: ").append(resource.region()) + .append("\n\tTags: ").append(resource.tags()) + .append("\n\tIP Address: ").append(resource.ipAddress()) + .append("\n\tLeaf domain label: ").append(resource.leafDomainLabel()) + .append("\n\tFQDN: ").append(resource.fqdn()) + .append("\n\tReverse FQDN: ").append(resource.reverseFqdn()) + .append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes()) + .append("\n\tIP allocation method: ").append(resource.ipAllocationMethod()) + .toString()); + } +} diff --git a/azure/src/test/java/com/microsoft/azure/TestTemplate.java b/azure/src/test/java/com/microsoft/azure/TestTemplate.java new file mode 100644 index 000000000000..75f822ad0932 --- /dev/null +++ b/azure/src/test/java/com/microsoft/azure/TestTemplate.java @@ -0,0 +1,113 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ +package com.microsoft.azure; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; + +import com.microsoft.azure.implementation.Azure; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +public abstract class TestTemplate< + T extends GroupableResource, + C extends SupportsListing & SupportsGettingByGroup & SupportsDeleting> { + + protected String testId = String.valueOf(System.currentTimeMillis()); + private T resource; + private Azure azure; + private C collection; + + /** + * Resource creation logic + * @param azure authenticated Azure instance + * @return created resource + * @throws Exception + */ + public abstract T createResource(Azure azure) throws Exception; + + /** + * Resource update logic + * @param resource the resource to update + * @throws Exception + */ + public abstract T updateResource(T resource) throws Exception; + + /** + * Tests the listing logic + * @throws CloudException + * @throws IOException + */ + public void verifyListing() throws CloudException, IOException { + int count = this.collection.list().size(); + System.out.println("Collection size: " + count); + Assert.assertTrue(0 < count); + } + + /** + * Tests the getting logic + * @throws CloudException + * @throws IOException + */ + public T verifyGetting() throws CloudException, IOException { + return this.collection.get(this.resource.resourceGroupName(), this.resource.name()); + } + + /** + * Tests the deletion logic + * @throws Exception + */ + public void verifyDeleting() throws Exception { + final String groupName = this.resource.resourceGroupName(); + this.collection.delete(this.resource.id()); + this.azure.resourceGroups().delete(groupName); + } + + /** + * Prints information about the resource + * @param resource + */ + public abstract void print(T resource); + + /** + * Runs the test + * @param azure authenticated Azure instance + * @param collection collection of resources to test + * @throws Exception + */ + @Test + public void runTest(Azure azure, C collection) throws Exception { + this.azure = azure; + this.collection = collection; + + // Verify creation + this.resource = createResource(azure); + System.out.println("\n------------\nAfter creation:\n"); + print(this.resource); + + // Verify listing + verifyListing(); + + // Verify getting + this.resource = verifyGetting(); + Assert.assertTrue(this.resource != null); + System.out.println("\n------------\nRetrieved resource:\n"); + print(this.resource); + + // Verify update + this.resource = updateResource(this.resource); + Assert.assertTrue(this.resource != null); + System.out.println("\n------------\nUpdated resource:\n"); + print(this.resource); + + // Verify deletion + verifyDeleting(); + } +} diff --git a/pom.xml b/pom.xml index 16d610da7886..14afc37d75ef 100644 --- a/pom.xml +++ b/pom.xml @@ -30,8 +30,6 @@ UTF-8 - ${project.basedir}/tools/checkstyle.xml - ${project.basedir}/tools/suppressions.xml playback @@ -100,6 +98,29 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.microsoft.azure + autorest-build-tools + 1.0.0-SNAPSHOT + + + com.puppycrawl.tools + checkstyle + 6.18 + + + + checkstyle.xml + samedir=runtimes/build-tools/src/main/resources + suppressions.xml + + + org.apache.maven.plugins maven-compiler-plugin @@ -135,25 +156,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - validate - validate - - true - true - - - check - - - - - org.apache.maven.plugins maven-resources-plugin diff --git a/runtimes/.travis.yml b/runtimes/.travis.yml index 7c6423f5079c..05c26fa53735 100644 --- a/runtimes/.travis.yml +++ b/runtimes/.travis.yml @@ -9,5 +9,6 @@ android: - extra-android-m2repository sudo: false script: - - mvn clean package + - mvn clean install + - mvn checkstyle:check - cd ./azure-android-client-authentication && ./gradlew check diff --git a/runtimes/azure-client-authentication/build.gradle b/runtimes/azure-client-authentication/build.gradle index b56a80eeb306..7c4d070dc10a 100644 --- a/runtimes/azure-client-authentication/build.gradle +++ b/runtimes/azure-client-authentication/build.gradle @@ -13,9 +13,10 @@ apply plugin: 'checkstyle' version = '1.0.0-SNAPSHOT' checkstyle { - configFile = new File("$rootDir/Tools/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/Tools/checkstyle"] - reportsDir = new File("$rootDir/Tools/checkstyle/reports") + toolVersion = "6.18" + configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports") } dependencies { diff --git a/runtimes/azure-client-authentication/pom.xml b/runtimes/azure-client-authentication/pom.xml index e3adb48c5f3f..47582ca1eaa8 100644 --- a/runtimes/azure-client-authentication/pom.xml +++ b/runtimes/azure-client-authentication/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../../tools/checkstyle.xml - ${project.basedir}/../../tools/suppressions.xml diff --git a/runtimes/azure-client-runtime/build.gradle b/runtimes/azure-client-runtime/build.gradle index e8a50ca11242..5c29359536ab 100644 --- a/runtimes/azure-client-runtime/build.gradle +++ b/runtimes/azure-client-runtime/build.gradle @@ -13,10 +13,10 @@ apply plugin: 'checkstyle' version = '1.0.0-SNAPSHOT' checkstyle { - toolVersion = "6.9" - configFile = new File("$rootDir/Tools/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/Tools/checkstyle"] - reportsDir = new File("$rootDir/Tools/checkstyle/reports") + toolVersion = "6.18" + configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports") } dependencies { diff --git a/runtimes/azure-client-runtime/pom.xml b/runtimes/azure-client-runtime/pom.xml index 2a1d2234e959..98d91b43e802 100644 --- a/runtimes/azure-client-runtime/pom.xml +++ b/runtimes/azure-client-runtime/pom.xml @@ -35,8 +35,6 @@ UTF-8 - ${project.basedir}/../../tools/checkstyle.xml - ${project.basedir}/../../tools/suppressions.xml diff --git a/runtimes/build-tools/pom.xml b/runtimes/build-tools/pom.xml new file mode 100644 index 000000000000..d540f8f5e698 --- /dev/null +++ b/runtimes/build-tools/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + com.microsoft.azure + autorest-clientruntime-for-java + 1.0.0-SNAPSHOT + ../pom.xml + + + autorest-build-tools + jar + + Build tools for AutoRest client runtime for Java + This package contains the build tools for AutoRest generated Java clients. + https://github.com/Azure/autorest-clientruntime-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + scm:git:https://github.com/Azure/autorest-clientruntime-for-java + scm:git:git@github.com:Azure/autorest-clientruntime-for-java.git + HEAD + + + + UTF-8 + + + + + + microsoft + Microsoft + + + diff --git a/runtimes/build-tools/src/main/resources/checkstyle.xml b/runtimes/build-tools/src/main/resources/checkstyle.xml new file mode 100644 index 000000000000..d156ff63e65f --- /dev/null +++ b/runtimes/build-tools/src/main/resources/checkstyle.xml @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/runtimes/build-tools/src/main/resources/suppressions.xml b/runtimes/build-tools/src/main/resources/suppressions.xml new file mode 100644 index 000000000000..690bb7a9fc35 --- /dev/null +++ b/runtimes/build-tools/src/main/resources/suppressions.xml @@ -0,0 +1,36 @@ + + + + + + + + + \ No newline at end of file diff --git a/runtimes/client-runtime/build.gradle b/runtimes/client-runtime/build.gradle index 2558fc5055f9..a163e9a9f89f 100644 --- a/runtimes/client-runtime/build.gradle +++ b/runtimes/client-runtime/build.gradle @@ -15,10 +15,10 @@ group = 'com.microsoft.rest' version = '1.0.0-SNAPSHOT' checkstyle { - toolVersion = "6.9" - configFile = new File("$rootDir/Tools/checkstyle/checkstyle.xml") - configProperties = [samedir: "$rootDir/Tools/checkstyle"] - reportsDir = new File("$rootDir/Tools/checkstyle/reports") + toolVersion = "6.18" + configFile = new File("$rootDir/ClientRuntimes/Java/build-tools/src/main/resources/checkstyle.xml") + configProperties = [samedir: "$rootDir/ClientRuntimes/Java/build-tools/src/main/resources"] + reportsDir = new File("$rootDir/ClientRuntimes/Java/build-tools/reports") } dependencies { diff --git a/runtimes/client-runtime/pom.xml b/runtimes/client-runtime/pom.xml index 35af73ebb9a1..a7c0b7441b02 100644 --- a/runtimes/client-runtime/pom.xml +++ b/runtimes/client-runtime/pom.xml @@ -36,8 +36,6 @@ UTF-8 - ${project.basedir}/../../tools/checkstyle.xml - ${project.basedir}/../../tools/suppressions.xml diff --git a/runtimes/pom.xml b/runtimes/pom.xml index 11ef8bb1ce53..51a8ab8ffdcc 100644 --- a/runtimes/pom.xml +++ b/runtimes/pom.xml @@ -31,8 +31,6 @@ UTF-8 - ${project.basedir}/../tools/checkstyle.xml - ${project.basedir}/../tools/suppressions.xml @@ -144,6 +142,29 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.microsoft.azure + autorest-build-tools + 1.0.0-SNAPSHOT + + + com.puppycrawl.tools + checkstyle + 6.18 + + + + checkstyle.xml + samedir=build-tools/src/main/resources + suppressions.xml + + + org.apache.maven.plugins maven-compiler-plugin @@ -201,8 +222,9 @@ - ./client-runtime - ./azure-client-runtime - ./azure-client-authentication + build-tools + client-runtime + azure-client-runtime + azure-client-authentication