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 40fef38bb143..d4dc0a8dcf32 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 @@ -2,6 +2,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; @@ -13,6 +14,7 @@ public interface AvailabilitySets extends SupportsListingByGroup, SupportsGettingByGroup, + SupportsGettingById, SupportsListing, SupportsCreating, SupportsDeleting, 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 464266896fdc..397fac407f2b 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 @@ -5,6 +5,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; @@ -19,6 +20,7 @@ public interface VirtualMachines extends SupportsListing, SupportsListingByGroup, SupportsGettingByGroup, + SupportsGettingById, SupportsCreating, SupportsDeleting, SupportsDeletingByGroup { 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 2ae75bd89a3d..30b224a4b12c 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 @@ -13,8 +13,8 @@ import com.microsoft.azure.management.compute.implementation.api.AvailabilitySetInner; import com.microsoft.azure.management.compute.implementation.api.AvailabilitySetsInner; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupPagedList; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.management.resources.implementation.api.PageImpl; import com.microsoft.rest.RestException; @@ -26,21 +26,13 @@ /** * The implementation for {@link AvailabilitySets}. */ -class AvailabilitySetsImpl implements AvailabilitySets { - private final AvailabilitySetsInner client; - private final ResourceManager resourceManager; - private final PagedListConverter converter; +class AvailabilitySetsImpl + extends GroupableResourcesImpl + implements AvailabilitySets { AvailabilitySetsImpl( final AvailabilitySetsInner client, final ResourceManager resourceManager) { - this.client = client; - this.resourceManager = resourceManager; - this.converter = new PagedListConverter() { - @Override - public AvailabilitySet typeConvert(AvailabilitySetInner inner) { - return createFluentModel(inner); - } - }; + super(resourceManager, client); } @Override @@ -49,7 +41,7 @@ public PagedList list() throws CloudException, IOException { @Override public List listNextGroup(String resourceGroupName) throws RestException, IOException { PageImpl page = new PageImpl<>(); - page.setItems(client.list(resourceGroupName).getBody()); + page.setItems(innerCollection.list(resourceGroupName).getBody()); page.setNextPageLink(null); return converter.convert(new PagedList(page) { @Override @@ -64,7 +56,7 @@ public Page nextPage(String nextPageLink) throws RestExcep @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { PageImpl page = new PageImpl<>(); - page.setItems(client.list(groupName).getBody()); + page.setItems(this.innerCollection.list(groupName).getBody()); page.setNextPageLink(null); return this.converter.convert(new PagedList(page) { @Override @@ -76,7 +68,7 @@ public Page nextPage(String nextPageLink) throws RestExcep @Override public AvailabilitySetImpl getByGroup(String groupName, String name) throws CloudException, IOException { - ServiceResponse response = this.client.get(groupName, name); + ServiceResponse response = this.innerCollection.get(groupName, name); return createFluentModel(response.getBody()); } @@ -92,25 +84,26 @@ public void delete(String id) throws Exception { @Override public void delete(String groupName, String name) throws Exception { - this.client.delete(groupName, name); + this.innerCollection.delete(groupName, name); } /************************************************************** * Fluent model helpers. **************************************************************/ - private AvailabilitySetImpl createFluentModel(String name) { - AvailabilitySetInner availabilitySetInner = new AvailabilitySetInner(); + @Override + protected AvailabilitySetImpl createFluentModel(String name) { return new AvailabilitySetImpl(name, - availabilitySetInner, - this.client, + new AvailabilitySetInner(), + this.innerCollection, this.resourceManager); } - private AvailabilitySetImpl createFluentModel(AvailabilitySetInner availabilitySetInner) { + @Override + protected AvailabilitySetImpl createFluentModel(AvailabilitySetInner availabilitySetInner) { return new AvailabilitySetImpl(availabilitySetInner.name(), availabilitySetInner, - this.client, + this.innerCollection, this.resourceManager); } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java index 7736688b8e55..4eaca4be6795 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java @@ -16,7 +16,7 @@ /** * Entry point to Azure compute resource management. */ -public final class ComputeManager extends Manager { +public final class ComputeManager extends Manager { // The service managers private StorageManager storageManager; private NetworkManager networkManager; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachinesImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachinesImpl.java index 1f24465ad681..5a99abc7f6bd 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachinesImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachinesImpl.java @@ -23,6 +23,7 @@ import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.management.resources.implementation.api.PageImpl; @@ -38,14 +39,12 @@ * The implementation for {@link VirtualMachines}. */ class VirtualMachinesImpl + extends GroupableResourcesImpl implements VirtualMachines { - private final VirtualMachinesInner client; private final VirtualMachineSizesInner virtualMachineSizesClient; private final ComputeManager computeManager; - private final ResourceManager resourceManager; private final StorageManager storageManager; private final NetworkManager networkManager; - private final PagedListConverter converter; VirtualMachinesImpl(VirtualMachinesInner client, VirtualMachineSizesInner virtualMachineSizesClient, @@ -53,18 +52,11 @@ class VirtualMachinesImpl ResourceManager resourceManager, StorageManager storageManager, NetworkManager networkManager) { - this.client = client; + super(resourceManager, client); this.virtualMachineSizesClient = virtualMachineSizesClient; this.computeManager = computeManager; - this.resourceManager = resourceManager; this.storageManager = storageManager; this.networkManager = networkManager; - this.converter = new PagedListConverter() { - @Override - public VirtualMachine typeConvert(VirtualMachineInner inner) { - return createFluentModel(inner); - } - }; } // Actions @@ -72,19 +64,19 @@ public VirtualMachine typeConvert(VirtualMachineInner inner) { @Override public PagedList list() throws CloudException, IOException { - ServiceResponse> response = client.listAll(); - return converter.convert(response.getBody()); + ServiceResponse> response = this.innerCollection.listAll(); + return this.converter.convert(response.getBody()); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - ServiceResponse> response = client.list(groupName); - return converter.convert(toPagedList(response.getBody())); + ServiceResponse> response = this.innerCollection.list(groupName); + return this.converter.convert(toPagedList(response.getBody())); } @Override public VirtualMachine getByGroup(String groupName, String name) throws CloudException, IOException { - ServiceResponse response = this.client.get(groupName, name); + ServiceResponse response = this.innerCollection.get(groupName, name); return createFluentModel(response.getBody()); } @@ -95,7 +87,7 @@ public void delete(String id) throws Exception { @Override public void delete(String groupName, String name) throws Exception { - this.client.delete(groupName, name); + this.innerCollection.delete(groupName, name); } @Override @@ -131,32 +123,32 @@ public PagedList availableSizesByRegion(Region region) throw @Override public void deallocate(String groupName, String name) throws CloudException, IOException, InterruptedException { - this.client.deallocate(groupName, name); + this.innerCollection.deallocate(groupName, name); } @Override public void generalize(String groupName, String name) throws CloudException, IOException { - this.client.generalize(groupName, name); + this.innerCollection.generalize(groupName, name); } @Override public void powerOff(String groupName, String name) throws CloudException, IOException, InterruptedException { - this.client.powerOff(groupName, name); + this.innerCollection.powerOff(groupName, name); } @Override public void restart(String groupName, String name) throws CloudException, IOException, InterruptedException { - this.client.restart(groupName, name); + this.innerCollection.restart(groupName, name); } @Override public void start(String groupName, String name) throws CloudException, IOException, InterruptedException { - this.client.start(groupName, name); + this.innerCollection.start(groupName, name); } @Override public void redeploy(String groupName, String name) throws CloudException, IOException, InterruptedException { - this.client.redeploy(groupName, name); + this.innerCollection.redeploy(groupName, name); } @Override @@ -166,7 +158,7 @@ public String capture(String groupName, String name, VirtualMachineCaptureParametersInner parameters = new VirtualMachineCaptureParametersInner(); parameters.withDestinationContainerName(containerName); parameters.withOverwriteVhds(overwriteVhd); - ServiceResponse captureResult = this.client.capture(groupName, name, parameters); + ServiceResponse captureResult = this.innerCollection.capture(groupName, name, parameters); ObjectMapper mapper = new ObjectMapper(); //Object to JSON string return mapper.writeValueAsString(captureResult.getBody().output()); @@ -175,7 +167,8 @@ public String capture(String groupName, String name, // Helper methods // - private VirtualMachineImpl createFluentModel(String name) { + @Override + protected VirtualMachineImpl createFluentModel(String name) { VirtualMachineInner inner = new VirtualMachineInner(); inner.withStorageProfile(new StorageProfile() .withOsDisk(new OSDisk()) @@ -186,17 +179,18 @@ private VirtualMachineImpl createFluentModel(String name) { .withNetworkInterfaces(new ArrayList())); return new VirtualMachineImpl(name, inner, - this.client, + this.innerCollection, this.computeManager, this.resourceManager, this.storageManager, this.networkManager); } - private VirtualMachineImpl createFluentModel(VirtualMachineInner virtualMachineInner) { + @Override + protected VirtualMachineImpl createFluentModel(VirtualMachineInner virtualMachineInner) { return new VirtualMachineImpl(virtualMachineInner.name(), virtualMachineInner, - this.client, + this.innerCollection, this.computeManager, this.resourceManager, this.storageManager, diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterfaces.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterfaces.java index 27d4d2cbdf72..b9c613784b08 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterfaces.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterfaces.java @@ -2,6 +2,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; @@ -15,6 +16,7 @@ public interface NetworkInterfaces extends SupportsListing, SupportsListingByGroup, SupportsGettingByGroup, + SupportsGettingById, SupportsDeleting, SupportsDeletingByGroup { } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroups.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroups.java index 252296768e4c..3ec2133498e4 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroups.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroups.java @@ -7,6 +7,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; @@ -21,6 +22,7 @@ public interface NetworkSecurityGroups extends SupportsListing, SupportsListingByGroup, SupportsGettingByGroup, + SupportsGettingById, SupportsDeleting, SupportsDeletingByGroup { } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Networks.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Networks.java index 9e612103d38f..cc817806b046 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Networks.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Networks.java @@ -7,6 +7,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; @@ -21,6 +22,7 @@ public interface Networks extends SupportsListing, SupportsListingByGroup, SupportsGettingByGroup, + SupportsGettingById, SupportsDeleting, SupportsDeletingByGroup { } 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 6c13a57f8c75..8711d9f8bf90 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 @@ -7,6 +7,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; @@ -22,5 +23,6 @@ public interface PublicIpAddresses extends SupportsDeleting, SupportsListingByGroup, SupportsGettingByGroup, + SupportsGettingById, SupportsDeletingByGroup { } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfacesImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfacesImpl.java index a1411e6d57d8..8db262b94f0a 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfacesImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfacesImpl.java @@ -9,7 +9,7 @@ import com.microsoft.azure.management.network.implementation.api.NetworkInterfaceIPConfiguration; import com.microsoft.azure.management.network.implementation.api.NetworkInterfaceDnsSettings; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.rest.ServiceResponse; @@ -19,43 +19,34 @@ /** * The type representing Azure network interfaces. */ -class NetworkInterfacesImpl implements NetworkInterfaces { - private final NetworkInterfacesInner client; - private final ResourceManager resourceManager; +class NetworkInterfacesImpl + extends GroupableResourcesImpl + implements NetworkInterfaces { private final NetworkManager networkManager; - private final PagedListConverter converter; - NetworkInterfacesImpl( final NetworkInterfacesInner client, final NetworkManager networkManager, final ResourceManager resourceManager) { - this.client = client; + super(resourceManager, client); this.networkManager = networkManager; - this.resourceManager = resourceManager; - this.converter = new PagedListConverter() { - @Override - public NetworkInterface typeConvert(NetworkInterfaceInner inner) { - return createFluentModel(inner); - } - }; } @Override public PagedList list() throws CloudException, IOException { - ServiceResponse> response = client.listAll(); - return converter.convert(response.getBody()); + ServiceResponse> response = innerCollection.listAll(); + return this.converter.convert(response.getBody()); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - ServiceResponse> response = client.list(groupName); - return converter.convert(response.getBody()); + ServiceResponse> response = innerCollection.list(groupName); + return this.converter.convert(response.getBody()); } @Override public NetworkInterface getByGroup(String groupName, String name) throws CloudException, IOException { - ServiceResponse serviceResponse = this.client.get(groupName, name); + ServiceResponse serviceResponse = this.innerCollection.get(groupName, name); return createFluentModel(serviceResponse.getBody()); } @@ -66,7 +57,7 @@ public void delete(String id) throws Exception { @Override public void delete(String groupName, String name) throws Exception { - this.client.delete(groupName, name); + this.innerCollection.delete(groupName, name); } @Override @@ -74,21 +65,23 @@ public NetworkInterface.DefinitionBlank define(String name) { return createFluentModel(name); } - private NetworkInterfaceImpl createFluentModel(String name) { + @Override + protected NetworkInterfaceImpl createFluentModel(String name) { NetworkInterfaceInner inner = new NetworkInterfaceInner(); inner.withIpConfigurations(new ArrayList()); inner.withDnsSettings(new NetworkInterfaceDnsSettings()); return new NetworkInterfaceImpl(name, inner, - this.client, + this.innerCollection, this.networkManager, this.resourceManager); } - private NetworkInterfaceImpl createFluentModel(NetworkInterfaceInner inner) { + @Override + protected NetworkInterfaceImpl createFluentModel(NetworkInterfaceInner inner) { return new NetworkInterfaceImpl(inner.name(), inner, - this.client, + this.innerCollection, this.networkManager, this.resourceManager); } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java index 5fd53c1df909..31e228c87fd5 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java @@ -20,7 +20,7 @@ /** * Entry point to Azure network management. */ -public final class NetworkManager extends Manager { +public final class NetworkManager extends Manager { private final NetworkManagementClientImpl networkManagementClient; // Collections diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupsImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupsImpl.java index e078848198a7..f8085a14501f 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupsImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupsImpl.java @@ -13,7 +13,7 @@ import com.microsoft.azure.management.network.implementation.api.NetworkSecurityGroupsInner; import com.microsoft.azure.management.network.implementation.api.SecurityRuleInner; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.rest.ServiceResponse; @@ -24,37 +24,29 @@ * Implementation of the NetworkSecurityGroups interface. * (Internal use only) */ -class NetworkSecurityGroupsImpl implements NetworkSecurityGroups { - private final NetworkSecurityGroupsInner client; - private final ResourceManager resourceManager; - private final PagedListConverter converter; +class NetworkSecurityGroupsImpl + extends GroupableResourcesImpl + implements NetworkSecurityGroups { NetworkSecurityGroupsImpl(final NetworkSecurityGroupsInner client, final ResourceManager resourceManager) { - this.client = client; - this.resourceManager = resourceManager; - this.converter = new PagedListConverter() { - @Override - public NetworkSecurityGroup typeConvert(NetworkSecurityGroupInner inner) { - return createFluentModel(inner); - } - }; + super(resourceManager, client); } @Override public PagedList list() throws CloudException, IOException { - ServiceResponse> response = client.listAll(); - return converter.convert(response.getBody()); + ServiceResponse> response = this.innerCollection.listAll(); + return this.converter.convert(response.getBody()); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - ServiceResponse> response = client.list(groupName); - return converter.convert(response.getBody()); + ServiceResponse> response = this.innerCollection.list(groupName); + return this.converter.convert(response.getBody()); } @Override public NetworkSecurityGroupImpl getByGroup(String groupName, String name) throws CloudException, IOException { - ServiceResponse serviceResponse = this.client.get(groupName, name); + ServiceResponse serviceResponse = this.innerCollection.get(groupName, name); return createFluentModel(serviceResponse.getBody()); } @@ -65,7 +57,7 @@ public void delete(String id) throws Exception { @Override public void delete(String groupName, String name) throws Exception { - this.client.delete(groupName, name); + this.innerCollection.delete(groupName, name); } @Override @@ -74,7 +66,9 @@ public NetworkSecurityGroupImpl define(String name) { } // Fluent model create helpers - private NetworkSecurityGroupImpl createFluentModel(String name) { + + @Override + protected NetworkSecurityGroupImpl createFluentModel(String name) { NetworkSecurityGroupInner inner = new NetworkSecurityGroupInner(); // Initialize rules @@ -86,10 +80,11 @@ private NetworkSecurityGroupImpl createFluentModel(String name) { inner.withDefaultSecurityRules(new ArrayList()); } - return new NetworkSecurityGroupImpl(name, inner, this.client, this.resourceManager); + return new NetworkSecurityGroupImpl(name, inner, this.innerCollection, this.resourceManager); } - private NetworkSecurityGroupImpl createFluentModel(NetworkSecurityGroupInner inner) { - return new NetworkSecurityGroupImpl(inner.name(), inner, this.client, this.resourceManager); + @Override + protected NetworkSecurityGroupImpl createFluentModel(NetworkSecurityGroupInner inner) { + return new NetworkSecurityGroupImpl(inner.name(), inner, this.innerCollection, this.resourceManager); } } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworksImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworksImpl.java index e63b0310d9ba..5ae0c7dac950 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworksImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworksImpl.java @@ -15,7 +15,7 @@ import com.microsoft.azure.management.network.implementation.api.VirtualNetworkInner; import com.microsoft.azure.management.network.implementation.api.VirtualNetworksInner; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.rest.ServiceResponse; @@ -26,37 +26,29 @@ * Implementation of the Networks interface. * (Internal use only) */ -class NetworksImpl implements Networks { - private final VirtualNetworksInner client; - private final ResourceManager resourceManager; - private final PagedListConverter converter; +class NetworksImpl + extends GroupableResourcesImpl + implements Networks { NetworksImpl(final VirtualNetworksInner client, final ResourceManager resourceManager) { - this.client = client; - this.resourceManager = resourceManager; - this.converter = new PagedListConverter() { - @Override - public Network typeConvert(VirtualNetworkInner inner) { - return createFluentModel(inner); - } - }; + super(resourceManager, client); } @Override public PagedList list() throws CloudException, IOException { - ServiceResponse> response = client.listAll(); - return converter.convert(response.getBody()); + ServiceResponse> response = this.innerCollection.listAll(); + return this.converter.convert(response.getBody()); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - ServiceResponse> response = client.list(groupName); - return converter.convert(response.getBody()); + ServiceResponse> response = this.innerCollection.list(groupName); + return this.converter.convert(response.getBody()); } @Override public NetworkImpl getByGroup(String groupName, String name) throws CloudException, IOException { - ServiceResponse serviceResponse = this.client.get(groupName, name); + ServiceResponse serviceResponse = this.innerCollection.get(groupName, name); return createFluentModel(serviceResponse.getBody()); } @@ -67,7 +59,7 @@ public void delete(String id) throws Exception { @Override public void delete(String groupName, String name) throws Exception { - this.client.delete(groupName, name); + this.innerCollection.delete(groupName, name); } @Override @@ -77,7 +69,8 @@ public NetworkImpl define(String name) { // Fluent model create helpers - private NetworkImpl createFluentModel(String name) { + @Override + protected NetworkImpl createFluentModel(String name) { VirtualNetworkInner inner = new VirtualNetworkInner(); // Initialize address space @@ -107,10 +100,11 @@ private NetworkImpl createFluentModel(String name) { dhcp.withDnsServers(new ArrayList()); } - return new NetworkImpl(name, inner, this.client, this.resourceManager); + return new NetworkImpl(name, inner, this.innerCollection, this.resourceManager); } - private NetworkImpl createFluentModel(VirtualNetworkInner inner) { - return new NetworkImpl(inner.name(), inner, this.client, this.resourceManager); + @Override + protected NetworkImpl createFluentModel(VirtualNetworkInner inner) { + return new NetworkImpl(inner.name(), inner, this.innerCollection, this.resourceManager); } } 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 6f4d6e627033..f89218673521 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 @@ -13,7 +13,7 @@ import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressesInner; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.rest.ServiceResponse; @@ -24,37 +24,28 @@ * (Internal use only) */ class PublicIpAddressesImpl + extends GroupableResourcesImpl implements PublicIpAddresses { - private final PublicIPAddressesInner client; - private final ResourceManager resourceManager; - private final PagedListConverter converter; PublicIpAddressesImpl(final PublicIPAddressesInner client, final ResourceManager resourceManager) { - this.client = client; - this.resourceManager = resourceManager; - this.converter = new PagedListConverter() { - @Override - public PublicIpAddress typeConvert(PublicIPAddressInner inner) { - return createFluentModel(inner); - } - }; + super(resourceManager, client); } @Override public PagedList list() throws CloudException, IOException { - ServiceResponse> response = client.listAll(); - return converter.convert(response.getBody()); + ServiceResponse> response = this.innerCollection.listAll(); + return this.converter.convert(response.getBody()); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - ServiceResponse> response = client.list(groupName); - return converter.convert(response.getBody()); + ServiceResponse> response = this.innerCollection.list(groupName); + return this.converter.convert(response.getBody()); } @Override public PublicIpAddressImpl getByGroup(String groupName, String name) throws CloudException, IOException { - ServiceResponse serviceResponse = this.client.get(groupName, name); + ServiceResponse serviceResponse = this.innerCollection.get(groupName, name); return createFluentModel(serviceResponse.getBody()); } @@ -65,7 +56,7 @@ public void delete(String id) throws Exception { @Override public void delete(String groupName, String name) throws Exception { - this.client.delete(groupName, name); + this.innerCollection.delete(groupName, name); } @Override @@ -75,17 +66,19 @@ public PublicIpAddressImpl define(String name) { // Fluent model create helpers - private PublicIpAddressImpl createFluentModel(String name) { + @Override + protected PublicIpAddressImpl createFluentModel(String name) { PublicIPAddressInner inner = new PublicIPAddressInner(); if (null == inner.dnsSettings()) { inner.withDnsSettings(new PublicIPAddressDnsSettings()); } - return new PublicIpAddressImpl(name, inner, this.client, this.resourceManager); + return new PublicIpAddressImpl(name, inner, this.innerCollection, this.resourceManager); } - private PublicIpAddressImpl createFluentModel(PublicIPAddressInner inner) { - return new PublicIpAddressImpl(inner.id(), inner, this.client, this.resourceManager); + @Override + protected PublicIpAddressImpl createFluentModel(PublicIPAddressInner inner) { + return new PublicIpAddressImpl(inner.id(), inner, this.innerCollection, this.resourceManager); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/DeploymentOperations.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/DeploymentOperations.java index 99c565b03754..065d71b6496c 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/DeploymentOperations.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/DeploymentOperations.java @@ -6,7 +6,7 @@ package com.microsoft.azure.management.resources; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; /** @@ -14,5 +14,5 @@ */ public interface DeploymentOperations extends SupportsListing, - SupportsGettingByName { + SupportsGettingById { } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployments.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployments.java index b4e6bf66f8c4..b91974475f70 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployments.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployments.java @@ -9,6 +9,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; @@ -26,6 +27,7 @@ public interface Deployments extends SupportsListingByGroup, SupportsGettingByName, SupportsGettingByGroup, + SupportsGettingById, SupportsDeleting, SupportsDeletingByGroup { /** diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java index 05bc76d2cb6f..2504b7c9312d 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java @@ -7,9 +7,10 @@ package com.microsoft.azure.management.resources; import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; -import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; import java.io.IOException; import java.util.List; @@ -18,8 +19,9 @@ * Entry point to generic resources management API. */ public interface GenericResources extends - SupportsListing, SupportsListingByGroup, + SupportsGettingByGroup, + SupportsGettingById, SupportsCreating { /** * Checks if a resource exists in a resource group. diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingById.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingById.java new file mode 100644 index 000000000000..f89d1e4530b4 --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingById.java @@ -0,0 +1,30 @@ +/** + * 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.resources.fluentcore.arm.collection; + +import com.microsoft.azure.CloudException; + +import java.io.IOException; + +/** + * Provides access to getting a specific Azure resource based on its resource ID. + * + * @param the type of the resource collection + */ +public interface SupportsGettingById { + /** + * Gets the information about a resource from Azure based on the resource id. + * + * @param id the id of the resource. + * @return an immutable representation of the resource + * @throws CloudException exceptions thrown from the cloud + * @throws IOException exceptions thrown from serialization/deserialization + * @throws IllegalArgumentException exceptions thrown when something is wrong with the input parameters + */ + T getById(String id) throws CloudException, IllegalArgumentException, IOException; +} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByName.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByName.java index f227cf266e36..2744189d2182 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByName.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByName.java @@ -12,7 +12,7 @@ import java.io.IOException; /** - * Provides access to getting a specific Azure resource based on its name with the current resource group. + * Provides access to getting a specific Azure resource based on its name within the current resource group. * * @param the type of the resource collection */ @@ -25,5 +25,5 @@ public interface SupportsGettingByName { * @throws CloudException exceptions thrown from the cloud * @throws IOException exceptions thrown from serialization/deserialization */ - T get(String name) throws CloudException, IOException; + T getByName(String name) throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/GroupableResourcesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/GroupableResourcesImpl.java new file mode 100644 index 000000000000..3ca549a7e6e8 --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/GroupableResourcesImpl.java @@ -0,0 +1,66 @@ +/** + * 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.resources.fluentcore.arm.collection.implementation; + +import java.io.IOException; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.Resource; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; +import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.implementation.ResourceManager; + +/** + * Base class for resource collection classes. + * (Internal use only) + * @param the individual resource type returned + * @param the individual resource implementation + * @param the wrapper inner type + * @param the inner type of the collection object + */ +public abstract class GroupableResourcesImpl< + T extends GroupableResource, + ImplT extends T, + InnerT extends Resource, + InnerCollectionT> + implements + SupportsGettingById, + SupportsGettingByGroup { + + protected final ResourceManager resourceManager; + protected final InnerCollectionT innerCollection; + protected final PagedListConverter converter; + + protected GroupableResourcesImpl( + ResourceManager resourceManager, + InnerCollectionT innerCollection) { + this.resourceManager = resourceManager; + this.innerCollection = innerCollection; + this.converter = new PagedListConverter() { + @Override + public T typeConvert(InnerT inner) { + return createFluentModel(inner); + } + }; + } + + @Override + public abstract T getByGroup(String groupName, String name) throws CloudException, IOException; + + @Override + public final T getById(String id) throws CloudException, IOException { + return this.getByGroup( + ResourceUtils.groupFromResourceId(id), + ResourceUtils.nameFromResourceId(id)); + } + + protected abstract ImplT createFluentModel(String name); + + protected abstract ImplT createFluentModel(InnerT inner); +} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/package-info.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/package-info.java new file mode 100644 index 000000000000..ab723c700e77 --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/package-info.java @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. + +/** + * This package contains shared implementation classes for resource collections. + */ +package com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/Manager.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/Manager.java index 21f2f2c7122f..3c7cb9f486b1 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/Manager.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/Manager.java @@ -11,8 +11,9 @@ /** * Base class for Azure resource managers. + * @param specific manager type */ -public abstract class Manager { +public abstract class Manager { private final ResourceManager resourceManager; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java index 6295de79b2a2..4d48f6cbd745 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java @@ -71,7 +71,6 @@ final class DeploymentImpl extends this.objectMapper = new ObjectMapper(); } - @Override public String resourceGroupName() { return this.resourceGroupName; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java index 63d9ad37736a..62e6c24286d0 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java @@ -44,7 +44,7 @@ public PagedList list() throws CloudException, IOException } @Override - public DeploymentOperation get(String operationId) throws IOException, CloudException { + public DeploymentOperation getById(String operationId) throws CloudException, IllegalArgumentException, IOException { return createFluentModel(client.get(deployment.resourceGroupName(), deployment.name(), operationId).getBody()); } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java index 9dc445de858f..cdc810a59923 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java @@ -63,7 +63,7 @@ public PagedList listByGroup(String groupName) throws CloudException } @Override - public Deployment get(String name) throws IOException, CloudException { + public Deployment getByName(String name) throws IOException, CloudException { for (ResourceGroup group : this.resourceManager.resourceGroups().list()) { try { DeploymentExtendedInner inner = client.get(group.name(), name).getBody(); @@ -103,13 +103,20 @@ public boolean checkExistence(String resourceGroupName, String deploymentName) t return client.checkExistence(resourceGroupName, deploymentName).getBody(); } - private DeploymentImpl createFluentModel(String name) { + protected DeploymentImpl createFluentModel(String name) { DeploymentExtendedInner deploymentExtendedInner = new DeploymentExtendedInner(); deploymentExtendedInner.withName(name); return new DeploymentImpl(deploymentExtendedInner, client, deploymentOperationsClient, this.resourceManager); } - private DeploymentImpl createFluentModel(DeploymentExtendedInner deploymentExtendedInner) { + protected DeploymentImpl createFluentModel(DeploymentExtendedInner deploymentExtendedInner) { return new DeploymentImpl(deploymentExtendedInner, client, deploymentOperationsClient, this.resourceManager); } + + @Override + public Deployment getById(String id) throws CloudException, IllegalArgumentException, IOException { + return this.getByGroup( + ResourceUtils.groupFromResourceId(id), + ResourceUtils.nameFromResourceId(id)); + } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java index 2732b2763971..e9c54bfd3904 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java @@ -46,7 +46,7 @@ public Feature register(String featureName) throws IOException, CloudException { } @Override - public Feature get(String name) throws CloudException, IOException { + public Feature getByName(String name) throws CloudException, IOException { return new FeatureImpl(client.get(resourceProviderNamespace, name).getBody()); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java index 534771ceaca6..7f38a4c2e463 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java @@ -11,7 +11,7 @@ import com.microsoft.azure.management.resources.GenericResources; import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.resources.implementation.api.ResourceGroupsInner; import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; import com.microsoft.azure.management.resources.implementation.api.ResourcesInner; @@ -23,31 +23,25 @@ import java.util.List; /** - * An instance of this class provides access to generic resources in Azure. + * Implementation of the GenericResouces interface. + * (Internal use only) */ final class GenericResourcesImpl + extends GroupableResourcesImpl implements GenericResources { private final ResourceManagementClientImpl serviceClient; - private final ResourcesInner client; private final ResourceGroupsInner resourceGroupsInner; - private final ResourceManager resourceManager; GenericResourcesImpl(ResourceManagementClientImpl serviceClient, ResourceManager resourceManager) { + super(resourceManager, serviceClient.resources()); this.serviceClient = serviceClient; - this.client = serviceClient.resources(); this.resourceGroupsInner = serviceClient.resourceGroups(); - this.resourceManager = resourceManager; - } - - @Override - public PagedList list() throws CloudException, IOException { - return listIntern(null); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - return listIntern(groupName); + return this.converter.convert(resourceGroupsInner.listResources(groupName).getBody()); } @Override @@ -55,14 +49,14 @@ public GenericResource.DefinitionBlank define(String name) { return new GenericResourceImpl( name, new GenericResourceInner(), - client, + this.innerCollection, serviceClient, this.resourceManager); } @Override public boolean checkExistence(String resourceGroupName, String resourceProviderNamespace, String parentResourcePath, String resourceType, String resourceName, String apiVersion) throws IOException, CloudException { - return client.checkExistence( + return this.innerCollection.checkExistence( resourceGroupName, resourceProviderNamespace, parentResourcePath, @@ -73,11 +67,11 @@ public boolean checkExistence(String resourceGroupName, String resourceProviderN @Override public GenericResource get(String resourceGroupName, String resourceProviderNamespace, String parentResourcePath, String resourceType, String resourceName, String apiVersion) throws CloudException, IOException { - GenericResourceInner inner = client.get(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion).getBody(); + GenericResourceInner inner = this.innerCollection.get(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion).getBody(); GenericResourceImpl resource = new GenericResourceImpl( resourceName, inner, - client, + this.innerCollection, serviceClient, this.resourceManager); @@ -93,30 +87,50 @@ public void moveResources(String sourceResourceGroupName, ResourceGroup targetRe ResourcesMoveInfoInner moveInfo = new ResourcesMoveInfoInner(); moveInfo.withTargetResourceGroup(targetResourceGroup.id()); moveInfo.withResources(resources); - client.moveResources(sourceResourceGroupName, moveInfo); + this.innerCollection.moveResources(sourceResourceGroupName, moveInfo); } @Override public void delete(String resourceGroupName, String resourceProviderNamespace, String parentResourcePath, String resourceType, String resourceName, String apiVersion) throws CloudException, IOException { - client.delete(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion); + this.innerCollection.delete(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion); } - private PagedList listIntern(String groupName) throws IOException, CloudException { - PagedListConverter converter = new PagedListConverter() { - @Override - public GenericResource typeConvert(GenericResourceInner genericResourceInner) { - return new GenericResourceImpl( - genericResourceInner.id(), - genericResourceInner, - client, - serviceClient, - resourceManager) - .withExistingGroup(ResourceUtils.groupFromResourceId(genericResourceInner.id())) - .withProviderNamespace(ResourceUtils.resourceProviderFromResourceId(genericResourceInner.id())) - .withResourceType(ResourceUtils.resourceTypeFromResourceId(genericResourceInner.id())) - .withParentResource(ResourceUtils.parentResourcePathFromResourceId(genericResourceInner.id())); + @Override + public GenericResource getByGroup(String groupName, String name) throws CloudException, IOException { + PagedList genericResources = this.listByGroup(groupName); + for (GenericResource resource : genericResources) { + if (resource.name().equalsIgnoreCase(name)) { + return resource; } - }; - return converter.convert(resourceGroupsInner.listResources(groupName).getBody()); + } + throw new CloudException("Generic resource not found."); + } + + @Override + protected GenericResourceImpl createFluentModel(String id) { + return new GenericResourceImpl( + id, + new GenericResourceInner(), + this.innerCollection, + this.serviceClient, + this.resourceManager) + .withExistingGroup(ResourceUtils.groupFromResourceId(id)) + .withProviderNamespace(ResourceUtils.resourceProviderFromResourceId(id)) + .withResourceType(ResourceUtils.resourceTypeFromResourceId(id)) + .withParentResource(ResourceUtils.parentResourcePathFromResourceId(id)); + } + + @Override + protected GenericResourceImpl createFluentModel(GenericResourceInner inner) { + return new GenericResourceImpl( + inner.id(), + inner, + this.innerCollection, + this.serviceClient, + this.resourceManager) + .withExistingGroup(ResourceUtils.groupFromResourceId(inner.id())) + .withProviderNamespace(ResourceUtils.resourceProviderFromResourceId(inner.id())) + .withResourceType(ResourceUtils.resourceTypeFromResourceId(inner.id())) + .withParentResource(ResourceUtils.parentResourcePathFromResourceId(inner.id())); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ProvidersImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ProvidersImpl.java index 9fa9f66fab81..b110a17cfffe 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ProvidersImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ProvidersImpl.java @@ -49,7 +49,7 @@ public Provider register(String resourceProviderNamespace) throws CloudException } @Override - public Provider get(String resourceProviderNamespace) throws CloudException, IOException { + public Provider getByName(String resourceProviderNamespace) throws CloudException, IOException { return new ProviderImpl(client.get(resourceProviderNamespace).getBody()); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java index 2f1d4d9f70ee..09c1e8642e9e 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java @@ -47,7 +47,7 @@ public ResourceGroup typeConvert(ResourceGroupInner resourceGroupInner) { } @Override - public ResourceGroupImpl get(String name) throws CloudException, IOException { + public ResourceGroupImpl getByName(String name) throws CloudException, IOException { ResourceGroupInner resourceGroupInner = client.get(name).getBody(); return createFluentModel(resourceGroupInner); } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java index 6741a3708c32..43b8cd0e18a7 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java @@ -40,7 +40,7 @@ public Subscription typeConvert(SubscriptionInner subscriptionInner) { @Override // Gets a specific resource group - public SubscriptionImpl get(String name) throws CloudException, IOException { + public SubscriptionImpl getByName(String name) throws CloudException, IOException { SubscriptionInner subscription = client.get(name).getBody(); return new SubscriptionImpl(subscription, client); } diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/DeploymentsTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/DeploymentsTests.java index 6afc3309d391..b9786302d1d9 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/DeploymentsTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/DeploymentsTests.java @@ -72,7 +72,7 @@ public void canDeployVirtualNetwork() throws Exception { // Deployment operations List operations = deployment.deploymentOperations().list(); Assert.assertEquals(2, operations.size()); - DeploymentOperation op = deployment.deploymentOperations().get(operations.get(0).operationId()); + DeploymentOperation op = deployment.deploymentOperations().getById(operations.get(0).operationId()); Assert.assertNotNull(op); resourceClient.genericResources().delete(rgName, "Microsoft.Network", "", "virtualnetworks", "VNet1", "2015-06-15"); } diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GenericResourcesTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GenericResourcesTests.java index 4d752dd38756..b744f0ca405c 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GenericResourcesTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GenericResourcesTests.java @@ -30,7 +30,7 @@ public static void setup() throws Exception { resourceGroups.define(newRgName) .withRegion(Region.US_SOUTH_CENTRAL) .create(); - resourceGroup = resourceGroups.get(rgName); + resourceGroup = resourceGroups.getByName(rgName); } @AfterClass @@ -65,7 +65,7 @@ public void canCreateUpdateMoveResource() throws Exception { // Get Assert.assertNotNull(genericResources.get(rgName, resource.resourceProviderNamespace(), resource.parentResourceId(), resource.resourceType(), resource.name(), resource.apiVersion())); // Move - genericResources.moveResources(rgName, resourceGroups.get(newRgName), Arrays.asList(resource.id())); + genericResources.moveResources(rgName, resourceGroups.getByName(newRgName), Arrays.asList(resource.id())); Assert.assertFalse(genericResources.checkExistence(rgName, resource.resourceProviderNamespace(), resource.parentResourceId(), resource.resourceType(), resource.name(), resource.apiVersion())); resource = genericResources.get(newRgName, resource.resourceProviderNamespace(), resource.parentResourceId(), resource.resourceType(), resource.name(), resource.apiVersion()); Assert.assertNotNull(resource); diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceGroupsTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceGroupsTests.java index 82c23bfe8b15..2ecdf25901de 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceGroupsTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceGroupsTests.java @@ -37,7 +37,7 @@ public void canCreateResourceGroup() throws Exception { Assert.assertEquals("tagvalue", groupResult.tags().get("tagname")); Assert.assertEquals(location, groupResult.region()); // Get - ResourceGroup getGroup = resourceGroups.get(rgName); + ResourceGroup getGroup = resourceGroups.getByName(rgName); Assert.assertNotNull(getGroup); Assert.assertEquals(rgName, getGroup.name()); // Update diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java index 9236968c523f..723e5c069da9 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java @@ -9,6 +9,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; @@ -26,6 +27,7 @@ public interface StorageAccounts extends SupportsDeleting, SupportsListingByGroup, SupportsGettingByGroup, + SupportsGettingById, SupportsDeletingByGroup { /** * Checks that account name is valid and is not in use. diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java index a67059547f46..599445d830a7 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java @@ -10,7 +10,7 @@ import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.management.resources.implementation.api.PageImpl; import com.microsoft.azure.management.storage.StorageAccount; @@ -29,43 +29,34 @@ * The implementation of StorageAccounts and its parent interfaces. */ class StorageAccountsImpl + extends GroupableResourcesImpl implements StorageAccounts { - private final StorageAccountsInner client; - private final ResourceManager resourceManager; - private final PagedListConverter converter; StorageAccountsImpl(final StorageAccountsInner client, final ResourceManager resourceManager) { - this.client = client; - this.resourceManager = resourceManager; - this.converter = new PagedListConverter() { - @Override - public StorageAccount typeConvert(StorageAccountInner storageAccountInner) { - return createFluentModel(storageAccountInner); - } - }; + super(resourceManager, client); } @Override public CheckNameAvailabilityResult checkNameAvailability(String name) throws CloudException, IOException { - CheckNameAvailabilityResultInner inner = client.checkNameAvailability(name).getBody(); + CheckNameAvailabilityResultInner inner = this.innerCollection.checkNameAvailability(name).getBody(); return new CheckNameAvailabilityResult(inner); } @Override public PagedList list() throws CloudException, IOException { - ServiceResponse> response = client.list(); - return converter.convert(toPagedList(response.getBody())); + ServiceResponse> response = this.innerCollection.list(); + return this.converter.convert(toPagedList(response.getBody())); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - ServiceResponse> response = client.listByResourceGroup(groupName); - return converter.convert(toPagedList(response.getBody())); + ServiceResponse> response = this.innerCollection.listByResourceGroup(groupName); + return this.converter.convert(toPagedList(response.getBody())); } @Override public StorageAccount getByGroup(String groupName, String name) throws CloudException, IOException { - ServiceResponse serviceResponse = this.client.getProperties(groupName, name); + ServiceResponse serviceResponse = this.innerCollection.getProperties(groupName, name); return createFluentModel(serviceResponse.getBody()); } @@ -76,7 +67,7 @@ public void delete(String id) throws Exception { @Override public void delete(String groupName, String name) throws Exception { - this.client.delete(groupName, name); + this.innerCollection.delete(groupName, name); } @Override @@ -98,12 +89,13 @@ public Page nextPage(String nextPageLink) throws RestExcept }; } - private StorageAccountImpl createFluentModel(String name) { - StorageAccountInner storageAccountInner = new StorageAccountInner(); - return new StorageAccountImpl(name, storageAccountInner, this.client, this.resourceManager); + @Override + protected StorageAccountImpl createFluentModel(String name) { + return new StorageAccountImpl(name, new StorageAccountInner(), this.innerCollection, this.resourceManager); } - private StorageAccountImpl createFluentModel(StorageAccountInner storageAccountInner) { - return new StorageAccountImpl(storageAccountInner.name(), storageAccountInner, this.client, this.resourceManager); + @Override + protected StorageAccountImpl createFluentModel(StorageAccountInner storageAccountInner) { + return new StorageAccountImpl(storageAccountInner.name(), storageAccountInner, this.innerCollection, this.resourceManager); } } diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java index de87150b744a..05f84c147892 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java @@ -19,7 +19,7 @@ /** * Entry point to Azure storage resource management. */ -public final class StorageManager extends Manager { +public final class StorageManager extends Manager { private final StorageManagementClientImpl storageManagementClient; // Collections diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageAvailabilitySet.java b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageAvailabilitySet.java index 655ef9a8eaf6..eff82f0f7ca0 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageAvailabilitySet.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageAvailabilitySet.java @@ -190,7 +190,7 @@ public static void main(String[] args) { System.out.println(f.getMessage()); f.printStackTrace(); } finally { - if (azure.resourceGroups().get(rgName) != null) { + if (azure.resourceGroups().getByName(rgName) != null) { System.out.println("Deleting Resource Group: " + rgName); azure.resourceGroups().delete(rgName); System.out.println("Deleted Resource Group: " + rgName); diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachine.java b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachine.java index 38bf65e4a423..b16eb732de4e 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachine.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachine.java @@ -225,7 +225,7 @@ public static void main(String[] args) { System.out.println(f.getMessage()); f.printStackTrace(); } finally { - if (azure.resourceGroups().get(rgName) != null) { + if (azure.resourceGroups().getByName(rgName) != null) { System.out.println("Deleting Resource Group: " + rgName); azure.resourceGroups().delete(rgName); System.out.println("Deleted Resource Group: " + rgName); diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/storage/samples/ManageStorageAccount.java b/azure-samples/src/main/java/com/microsoft/azure/management/storage/samples/ManageStorageAccount.java index e4722e031bee..3a0cd764dbce 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/storage/samples/ManageStorageAccount.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/storage/samples/ManageStorageAccount.java @@ -127,7 +127,7 @@ public static void main(String[] args) { System.out.println(f.getMessage()); f.printStackTrace(); } finally { - if (azure.resourceGroups().get(rgName) != null) { + if (azure.resourceGroups().getByName(rgName) != null) { System.out.println("Deleting Resource Group: " + rgName); azure.resourceGroups().delete(rgName); System.out.println("Deleted Resource Group: " + rgName); diff --git a/azure/src/test/java/com/microsoft/azure/TestTemplate.java b/azure/src/test/java/com/microsoft/azure/TestTemplate.java index aae728b4c195..217efcac966e 100644 --- a/azure/src/test/java/com/microsoft/azure/TestTemplate.java +++ b/azure/src/test/java/com/microsoft/azure/TestTemplate.java @@ -7,6 +7,7 @@ import com.microsoft.azure.management.resources.ResourceGroups; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; @@ -21,7 +22,7 @@ */ public abstract class TestTemplate< T extends GroupableResource, - C extends SupportsListing & SupportsGettingByGroup & SupportsDeleting> { + C extends SupportsListing & SupportsGettingByGroup & SupportsDeleting & SupportsGettingById> { protected String testId = String.valueOf(System.currentTimeMillis() % 100000L); private T resource; @@ -61,7 +62,10 @@ public int verifyListing() throws CloudException, IOException { * @throws IOException if anything goes wrong */ public T verifyGetting() throws CloudException, IOException { - return this.collection.getByGroup(this.resource.resourceGroupName(), this.resource.name()); + T resourceByGroup = this.collection.getByGroup(this.resource.resourceGroupName(), this.resource.name()); + T resourceById = this.collection.getById(resourceByGroup.id()); + Assert.assertTrue(resourceById.id().equalsIgnoreCase(resourceByGroup.id())); + return resourceById; } /**