From c179885be2e6896db04522957351478bafb1a09f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 09:59:44 -0700 Subject: [PATCH 01/16] NSG - minor code rearrangement and test fix --- .../network/NetworkSecurityRule.java | 337 +++++++++--------- .../java/com/microsoft/azure/TestNSG.java | 2 +- 2 files changed, 169 insertions(+), 170 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java index 50d279131485..4127bb50ab1d 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java @@ -177,109 +177,98 @@ interface Definition extends } /** - * The entirety of a network security rule definition as part of a network security group update. - * @param the return type of the final {@link DefinitionAttachable#attach()} - */ - interface UpdateDefinition extends - UpdateDefinables.Blank, - UpdateDefinables.WithDirectionAccess, - UpdateDefinables.WithSourceAddress, - UpdateDefinables.WithSourcePort, - UpdateDefinables.WithDestinationAddress, - UpdateDefinables.WithDestinationPort, - UpdateDefinables.WithProtocol, - UpdateDefinables.WithAttach { - } - - /** - * The entirety of a security rule update as part of a network security group update. + * Grouping of security rule definition stages applicable as part of a network security group creation. */ - interface Update extends - Updatables.WithDirectionAccess, - Updatables.WithSourceAddress, - Updatables.WithSourcePort, - Updatables.WithDestinationAddress, - Updatables.WithDestinationPort, - Updatables.WithProtocol, - Settable { - + interface Definables { /** - * Specifies the priority to assign to this rule. - *

- * Security rules are applied in the order of their assigned priority. - * @param priority the priority number in the range 100 to 4096 - * @return the next stage of the update + * The first stage of a security rule definition. + * @param the return type of the final {@link DefinitionAttachable#attach()} */ - Update withPriority(int priority); - } + interface Blank extends WithDirectionAccess { + } - /** - * Grouping of security rule update stages. - */ - interface Updatables { /** - * The stage of the network rule description allowing the direction and the access type to be specified. + * The stage of the security rule definition allowing the protocol that the rule applies to to be specified. + * @param the return type of the final {@link DefinitionAttachable#attach()} */ - interface WithDirectionAccess { + interface WithProtocol { /** - * Allows inbound traffic. + * Specifies the protocol that this rule applies to. + * @param protocol one of the supported protocols * @return the next stage of the security rule definition */ - Update allowInbound(); + WithAttach withProtocol(Protocol protocol); /** - * Allows outbound traffic. + * Makes this rule apply to any supported protocol. * @return the next stage of the security rule definition */ - Update allowOutbound(); + WithAttach withAnyProtocol(); + } + /** + * The stage of the network rule definition allowing the destination port(s) to be specified. + * @param the return type of the final {@link DefinitionAttachable#attach()} + */ + interface WithDestinationPort { /** - * Blocks inbound traffic. + * Specifies the destination port to which this rule applies. + * @param port the destination port number * @return the next stage of the security rule definition */ - Update denyInbound(); + WithProtocol toPort(int port); /** - * Blocks outbound traffic. + * Makes this rule apply to any destination port. * @return the next stage of the security rule definition */ - Update denyOutbound(); + WithProtocol toAnyPort(); + + /** + * Specifies the destination port range to which this rule applies. + * @param from the starting port number + * @param to the ending port number + * @return the next stage of the security rule definition + */ + WithProtocol toPortRange(int from, int to); } /** - * The stage of the network rule description allowing the source address to be specified. + * The stage of the network rule definition allowing the destination address to be specified. + * @param the return type of the final {@link DefinitionAttachable#attach()} */ - interface WithSourceAddress { + interface WithDestinationAddress { /** - * Specifies the traffic source address prefix to which this rule applies. - * @param cidr an IP address prefix expressed in the CIDR notation + * Specifies the traffic destination address range to which this rule applies. + * @param cidr an IP address range expressed in the CIDR notation * @return the next stage of the security rule definition */ - Update fromAddress(String cidr); + WithDestinationPort toAddress(String cidr); /** - * Specifies that the rule applies to any traffic source address. + * Makes the rule apply to any traffic destination address. * @return the next stage of the security rule definition */ - Update fromAnyAddress(); + WithDestinationPort toAnyAddress(); } /** - * The stage of the network rule description allowing the source port(s) to be specified. + * The stage of the network rule definition allowing the source port(s) to be specified. + * @param the return type of the final {@link DefinitionAttachable#attach()} */ - interface WithSourcePort { + interface WithSourcePort { /** * Specifies the source port to which this rule applies. * @param port the source port number * @return the next stage of the security rule definition */ - Update fromPort(int port); + WithDestinationAddress fromPort(int port); /** * Makes this rule apply to any source port. * @return the next stage of the security rule definition */ - Update fromAnyPort(); + WithDestinationAddress fromAnyPort(); /** * Specifies the source port range to which this rule applies. @@ -287,72 +276,90 @@ interface WithSourcePort { * @param to the ending port number * @return the next stage of the security rule definition */ - Update fromPortRange(int from, int to); + WithDestinationAddress fromPortRange(int from, int to); } /** - * The stage of the network rule description allowing the destination address to be specified. + * The stage of the network rule definition allowing the source address to be specified. + * @param the return type of the final {@link DefinitionAttachable#attach()} */ - interface WithDestinationAddress { + interface WithSourceAddress { /** - * Specifies the traffic destination address range to which this rule applies. - * @param cidr an IP address range expressed in the CIDR notation + * Specifies the traffic source address prefix to which this rule applies. + * @param cidr an IP address prefix expressed in the CIDR notation * @return the next stage of the security rule definition */ - Update toAddress(String cidr); + WithSourcePort fromAddress(String cidr); /** - * Makes the rule apply to any traffic destination address. + * Specifies that the rule applies to any traffic source address. * @return the next stage of the security rule definition */ - Update toAnyAddress(); + WithSourcePort fromAnyAddress(); } /** - * The stage of the network rule description allowing the destination port(s) to be specified. + * The stage of the network rule definition allowing the direction and the access type to be specified. + * @param the return type of the final {@link DefinitionAttachable#attach()} */ - interface WithDestinationPort { + interface WithDirectionAccess { /** - * Specifies the destination port to which this rule applies. - * @param port the destination port number + * Allows inbound traffic. * @return the next stage of the security rule definition */ - Update toPort(int port); + WithSourceAddress allowInbound(); /** - * Makes this rule apply to any destination port. + * Allows outbound traffic. * @return the next stage of the security rule definition */ - Update toAnyPort(); + WithSourceAddress allowOutbound(); /** - * Specifies the destination port range to which this rule applies. - * @param from the starting port number - * @param to the ending port number + * Blocks inbound traffic. * @return the next stage of the security rule definition */ - Update toPortRange(int from, int to); - } + WithSourceAddress denyInbound(); - /** - * The stage of the security rule description allowing the protocol that the rule applies to to be specified. - */ - interface WithProtocol { /** - * Specifies the protocol that this rule applies to. - * @param protocol one of the supported protocols + * Blocks outbound traffic. * @return the next stage of the security rule definition */ - Update withProtocol(Protocol protocol); + WithSourceAddress denyOutbound(); + } + + /** The final stage of the security rule definition. + *

+ * At this stage, any remaining optional settings can be specified, or the security rule definition + * can be attached to the parent network security group definition using {@link WithAttach#attach()}. + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAttach extends Attachable.InDefinition { /** - * Makes this rule apply to any supported protocol. - * @return the next stage of the security rule definition + * Specifies the priority to assign to this rule. + *

+ * Security rules are applied in the order of their assigned priority. + * @param priority the priority number in the range 100 to 4096 + * @return the next stage of the update */ - Update withAnyProtocol(); + WithAttach withPriority(int priority); } } + /** The entirety of a network security rule definition as part of a network security group update. + * @param the return type of the final {@link DefinitionAttachable#attach()} + */ + interface UpdateDefinition extends + UpdateDefinables.Blank, + UpdateDefinables.WithDirectionAccess, + UpdateDefinables.WithSourceAddress, + UpdateDefinables.WithSourcePort, + UpdateDefinables.WithDestinationAddress, + UpdateDefinables.WithDestinationPort, + UpdateDefinables.WithProtocol, + UpdateDefinables.WithAttach { + } /** * Grouping of security rule definition stages applicable as part of a network security group update. @@ -366,7 +373,7 @@ interface Blank extends WithDirectionAccess { } /** - * The stage of the network rule definition allowing the direction and the access type to be specified. + * The stage of the network rule description allowing the direction and the access type to be specified. * @param the return type of the final {@link DefinitionAttachable#attach()} */ interface WithDirectionAccess { @@ -526,98 +533,94 @@ interface WithAttach extends Attachable.InUpdate { } /** - * Grouping of security rule definition stages applicable as part of a network security group creation. + * The entirety of a security rule update as part of a network security group update. */ - interface Definables { + interface Update extends + Updatables.WithDirectionAccess, + Updatables.WithSourceAddress, + Updatables.WithSourcePort, + Updatables.WithDestinationAddress, + Updatables.WithDestinationPort, + Updatables.WithProtocol, + Settable { + /** - * The first stage of a security rule definition. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * Specifies the priority to assign to this rule. + *

+ * Security rules are applied in the order of their assigned priority. + * @param priority the priority number in the range 100 to 4096 + * @return the next stage of the update */ - interface Blank extends WithDirectionAccess { - } + Update withPriority(int priority); + } + /** + * Grouping of security rule update stages. + */ + interface Updatables { /** - * The stage of the security rule definition allowing the protocol that the rule applies to to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * The stage of the network rule description allowing the direction and the access type to be specified. */ - interface WithProtocol { - /** - * Specifies the protocol that this rule applies to. - * @param protocol one of the supported protocols - * @return the next stage of the security rule definition - */ - WithAttach withProtocol(Protocol protocol); - + interface WithDirectionAccess { /** - * Makes this rule apply to any supported protocol. + * Allows inbound traffic. * @return the next stage of the security rule definition */ - WithAttach withAnyProtocol(); - } + Update allowInbound(); - /** - * The stage of the network rule definition allowing the destination port(s) to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} - */ - interface WithDestinationPort { /** - * Specifies the destination port to which this rule applies. - * @param port the destination port number + * Allows outbound traffic. * @return the next stage of the security rule definition */ - WithProtocol toPort(int port); + Update allowOutbound(); /** - * Makes this rule apply to any destination port. + * Blocks inbound traffic. * @return the next stage of the security rule definition */ - WithProtocol toAnyPort(); + Update denyInbound(); /** - * Specifies the destination port range to which this rule applies. - * @param from the starting port number - * @param to the ending port number + * Blocks outbound traffic. * @return the next stage of the security rule definition */ - WithProtocol toPortRange(int from, int to); + Update denyOutbound(); } /** - * The stage of the network rule definition allowing the destination address to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * The stage of the network rule description allowing the source address to be specified. */ - interface WithDestinationAddress { + interface WithSourceAddress { /** - * Specifies the traffic destination address range to which this rule applies. - * @param cidr an IP address range expressed in the CIDR notation + * Specifies the traffic source address prefix to which this rule applies. + * @param cidr an IP address prefix expressed in the CIDR notation * @return the next stage of the security rule definition */ - WithDestinationPort toAddress(String cidr); + Update fromAddress(String cidr); /** - * Makes the rule apply to any traffic destination address. + * Specifies that the rule applies to any traffic source address. * @return the next stage of the security rule definition */ - WithDestinationPort toAnyAddress(); + Update fromAnyAddress(); } /** - * The stage of the network rule definition allowing the source port(s) to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * The stage of the network rule description allowing the source port(s) to be specified. */ - interface WithSourcePort { + interface WithSourcePort { /** * Specifies the source port to which this rule applies. * @param port the source port number * @return the next stage of the security rule definition */ - WithDestinationAddress fromPort(int port); + Update fromPort(int port); /** * Makes this rule apply to any source port. * @return the next stage of the security rule definition */ - WithDestinationAddress fromAnyPort(); + Update fromAnyPort(); /** * Specifies the source port range to which this rule applies. @@ -625,74 +628,70 @@ interface WithSourcePort { * @param to the ending port number * @return the next stage of the security rule definition */ - WithDestinationAddress fromPortRange(int from, int to); + Update fromPortRange(int from, int to); } /** - * The stage of the network rule definition allowing the source address to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * The stage of the network rule description allowing the destination address to be specified. */ - interface WithSourceAddress { + interface WithDestinationAddress { /** - * Specifies the traffic source address prefix to which this rule applies. - * @param cidr an IP address prefix expressed in the CIDR notation + * Specifies the traffic destination address range to which this rule applies. + * @param cidr an IP address range expressed in the CIDR notation * @return the next stage of the security rule definition */ - WithSourcePort fromAddress(String cidr); + Update toAddress(String cidr); /** - * Specifies that the rule applies to any traffic source address. + * Makes the rule apply to any traffic destination address. * @return the next stage of the security rule definition */ - WithSourcePort fromAnyAddress(); + Update toAnyAddress(); } /** - * The stage of the network rule definition allowing the direction and the access type to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * The stage of the network rule description allowing the destination port(s) to be specified. */ - interface WithDirectionAccess { + interface WithDestinationPort { /** - * Allows inbound traffic. + * Specifies the destination port to which this rule applies. + * @param port the destination port number * @return the next stage of the security rule definition */ - WithSourceAddress allowInbound(); + Update toPort(int port); /** - * Allows outbound traffic. + * Makes this rule apply to any destination port. * @return the next stage of the security rule definition */ - WithSourceAddress allowOutbound(); + Update toAnyPort(); /** - * Blocks inbound traffic. + * Specifies the destination port range to which this rule applies. + * @param from the starting port number + * @param to the ending port number * @return the next stage of the security rule definition */ - WithSourceAddress denyInbound(); + Update toPortRange(int from, int to); + } + /** + * The stage of the security rule description allowing the protocol that the rule applies to to be specified. + */ + interface WithProtocol { /** - * Blocks outbound traffic. + * Specifies the protocol that this rule applies to. + * @param protocol one of the supported protocols * @return the next stage of the security rule definition */ - WithSourceAddress denyOutbound(); - } - - /** The final stage of the security rule definition. - *

- * At this stage, any remaining optional settings can be specified, or the security rule definition - * can be attached to the parent network security group definition using {@link WithAttach#attach()}. - * @param the return type of {@link WithAttach#attach()} - */ - interface WithAttach extends Attachable.InDefinition { + Update withProtocol(Protocol protocol); /** - * Specifies the priority to assign to this rule. - *

- * Security rules are applied in the order of their assigned priority. - * @param priority the priority number in the range 100 to 4096 - * @return the next stage of the update + * Makes this rule apply to any supported protocol. + * @return the next stage of the security rule definition */ - WithAttach withPriority(int priority); + Update withAnyProtocol(); } } + } diff --git a/azure/src/test/java/com/microsoft/azure/TestNSG.java b/azure/src/test/java/com/microsoft/azure/TestNSG.java index c4c67094a3e1..4e2df1632752 100644 --- a/azure/src/test/java/com/microsoft/azure/TestNSG.java +++ b/azure/src/test/java/com/microsoft/azure/TestNSG.java @@ -47,7 +47,7 @@ public NetworkSecurityGroup createResource(NetworkSecurityGroups nsgs) throws Ex .create(); // Verify - Assert.assertTrue(nsg.region() == region.toString()); + Assert.assertTrue(nsg.region().equalsIgnoreCase(region.toString())); Assert.assertTrue(nsg.securityRules().size() == 2); return nsg; From cf68fb448b6e6bef83956298da36df0cff1b9ace Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 11:58:20 -0700 Subject: [PATCH 02/16] NSG.description() support --- .../network/NetworkSecurityRule.java | 29 +++++++++++++++++-- .../NetworkSecurityRuleImpl.java | 10 +++++++ .../java/com/microsoft/azure/TestNSG.java | 5 +++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java index 4127bb50ab1d..cb7c433a51ed 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java @@ -128,6 +128,11 @@ public static Protocol fromString(String s) { */ Protocol protocol(); + /** + * @return the user-defined description of the security rule + */ + String description(); + /** * @return the type of access the rule enforces */ @@ -341,9 +346,16 @@ interface WithAttach extends Attachable.InDefinition { *

* Security rules are applied in the order of their assigned priority. * @param priority the priority number in the range 100 to 4096 - * @return the next stage of the update + * @return the next stage */ WithAttach withPriority(int priority); + + /** + * Specifies a description for this security rule. + * @param description the text description to associate with this security rule + * @return the next stage + */ + WithAttach withDescription(String description); } } @@ -529,6 +541,13 @@ interface WithAttach extends Attachable.InUpdate { * @return the next stage of the update */ WithAttach withPriority(int priority); + + /** + * Specifies a description for this security rule. + * @param descrtiption a text description to associate with the security rule + * @return the next stage + */ + WithAttach withDescription(String descrtiption); } } @@ -545,13 +564,19 @@ interface Update extends Settable { /** - * Specifies the priority to assign to this rule. + * Specifies the priority to assign to this security rule. *

* Security rules are applied in the order of their assigned priority. * @param priority the priority number in the range 100 to 4096 * @return the next stage of the update */ Update withPriority(int priority); + + /** Specifies a description for this security rule. + * @param description a text description to associate with this security rule + * @return the next stage + */ + Update withDescription(String description); } /** diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityRuleImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityRuleImpl.java index e68501da7a49..3d901ef316a7 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityRuleImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityRuleImpl.java @@ -183,6 +183,11 @@ public NetworkSecurityRuleImpl withPriority(int priority) { return this; } + @Override + public NetworkSecurityRuleImpl withDescription(String description) { + this.inner().withDescription(description); + return this; + } // Helpers @@ -209,4 +214,9 @@ public NetworkSecurityGroupImpl attach() { public NetworkSecurityGroupImpl set() throws Exception { return this.parent(); } + + @Override + public String description() { + return this.inner().description(); + } } diff --git a/azure/src/test/java/com/microsoft/azure/TestNSG.java b/azure/src/test/java/com/microsoft/azure/TestNSG.java index 4e2df1632752..9aa1aec13d3c 100644 --- a/azure/src/test/java/com/microsoft/azure/TestNSG.java +++ b/azure/src/test/java/com/microsoft/azure/TestNSG.java @@ -43,6 +43,7 @@ public NetworkSecurityGroup createResource(NetworkSecurityGroups nsgs) throws Ex .toPortRange(22, 25) .withAnyProtocol() .withPriority(200) + .withDescription("foo!!") .attach() .create(); @@ -73,6 +74,7 @@ public NetworkSecurityGroup updateResource(NetworkSecurityGroup resource) throws .fromAddress("100.0.0.0/29") .fromPort(88) .withPriority(300) + .withDescription("bar!!!") .set() .apply(); Assert.assertTrue(resource.tags().containsKey("tag1")); @@ -98,7 +100,8 @@ public void print(NetworkSecurityGroup resource) { .append("\n\t\tTo address: ").append(rule.destinationAddressPrefix()) .append("\n\t\tTo port: ").append(rule.destinationPortRange()) .append("\n\t\tProtocol: ").append(rule.protocol()) - .append("\n\t\tPriority: ").append(rule.priority()); + .append("\n\t\tPriority: ").append(rule.priority()) + .append("\n\t\tDescription: ").append(rule.description()); } info.append("\n\tNICs: ").append(resource.networkInterfaceIds()); From cee3d6de299d5731c3c032dfd2e75049dce566c9 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 14:27:57 -0700 Subject: [PATCH 03/16] reorganizing NSG interfaces for consistency with the pattern established in NetworkSecurityRule --- .../management/network/NetworkInterface.java | 4 +- .../network/NetworkSecurityGroup.java | 93 +++++++++++-------- .../network/NetworkSecurityGroups.java | 2 +- .../network/NetworkSecurityRule.java | 50 +++++----- .../NetworkSecurityGroupImpl.java | 2 +- .../NetworkSecurityRuleImpl.java | 2 +- 6 files changed, 82 insertions(+), 71 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java index b94338790b85..04b8aff9ce07 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java @@ -292,7 +292,7 @@ interface DefinitionWithNetworkSecurityGroup { * @param creatable a creatable definition for a new network security group * @return the next stage of the network interface definition */ - DefinitionCreatable withNewNetworkSecurityGroup(NetworkSecurityGroup.DefinitionCreatable creatable); + DefinitionCreatable withNewNetworkSecurityGroup(NetworkSecurityGroup.DefinitionStages.WithCreate creatable); /** * Associates an existing network security group with the network interface. @@ -479,7 +479,7 @@ interface Update extends * @param creatable a creatable definition for a new network security group * @return the next stage of the network interface update */ - Update withNewNetworkSecurityGroup(NetworkSecurityGroup.DefinitionCreatable creatable); + Update withNewNetworkSecurityGroup(NetworkSecurityGroup.DefinitionStages.WithCreate creatable); /** * Associates an existing network security group with the network interface. diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java index 8a952d269c10..64efb47280d1 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java @@ -51,59 +51,70 @@ public interface NetworkSecurityGroup extends /** * The entirety of the network security group definition. */ - interface Definitions extends - DefinitionBlank, - DefinitionWithGroup, - DefinitionCreatable { + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithGroup, + DefinitionStages.WithRule, + DefinitionStages.WithCreate { } /** - * The first stage of the definition. + * Grouping of network security group definition stages. */ - interface DefinitionBlank - extends GroupableResource.DefinitionWithRegion { - } + interface DefinitionStages { + /** + * The first stage of the definition. + */ + interface Blank + extends GroupableResource.DefinitionWithRegion { + } - /** - * The stage of the definition allowing to specify the resource group. - */ - interface DefinitionWithGroup - extends GroupableResource.DefinitionWithGroup { - } + /** + * The stage allowing to specify the resource group. + */ + interface WithGroup + extends GroupableResource.DefinitionWithGroup { + } - /** - * The stage of the definition allowing to define a new security rule. - *

- * When the security rule definition is complete enough, use {@link Attachable#attach()} to attach it to - * this network security group. - */ - interface DefinitionWithRule { /** - * Starts the definition of a new security rule. - * @param name the name for the new security rule - * @return the first stage of the security rule definition + * The stage allowing to define a new security rule. + *

+ * When the security rule description is complete enough, use {@link Attachable#attach()} to attach it to + * this network security group. */ - NetworkSecurityRule.Definables.Blank defineRule(String name); - } + interface WithRule { + /** + * Starts the definition of a new security rule. + * @param name the name for the new security rule + * @return the first stage of the security rule definition + */ + NetworkSecurityRule.DefinitionStages.Blank defineRule(String name); + } - /** - * The stage of the resource definition allowing to add or remove security rules. - */ - interface UpdateWithRule { - Update withoutRule(String name); - NetworkSecurityRule.UpdateDefinables.Blank defineRule(String name); - NetworkSecurityRule.Update updateRule(String name); + /** + * The stage of the 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 WithCreate extends + Creatable, + Resource.DefinitionWithTags, + DefinitionStages.WithRule { + } } /** - * The stage of the 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. + * Grouping of network security group update stages. */ - interface DefinitionCreatable extends - Creatable, - Resource.DefinitionWithTags, - DefinitionWithRule { + interface UpdateStages { + /** + * The stage of the resource definition allowing to add or remove security rules. + */ + interface WithRule { + Update withoutRule(String name); + NetworkSecurityRule.UpdateDefinitionStages.Blank defineRule(String name); + NetworkSecurityRule.Update updateRule(String name); + } } /** @@ -115,6 +126,6 @@ interface DefinitionCreatable extends interface Update extends Appliable, Resource.UpdateWithTags, - UpdateWithRule { + UpdateStages.WithRule { } } 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 3ec2133498e4..2e5be3680c3d 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 @@ -18,7 +18,7 @@ * Entry point to network security group management. */ public interface NetworkSecurityGroups extends - SupportsCreating, + SupportsCreating, SupportsListing, SupportsListingByGroup, SupportsGettingByGroup, diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java index cb7c433a51ed..f7223b8061dd 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java @@ -171,20 +171,20 @@ public static Protocol fromString(String s) { * @param the return type of the final {@link DefinitionAttachable#attach()} */ interface Definition extends - Definables.Blank, - Definables.WithAttach, - Definables.WithDirectionAccess, - Definables.WithSourceAddress, - Definables.WithSourcePort, - Definables.WithDestinationAddress, - Definables.WithDestinationPort, - Definables.WithProtocol { + DefinitionStages.Blank, + DefinitionStages.WithAttach, + DefinitionStages.WithDirectionAccess, + DefinitionStages.WithSourceAddress, + DefinitionStages.WithSourcePort, + DefinitionStages.WithDestinationAddress, + DefinitionStages.WithDestinationPort, + DefinitionStages.WithProtocol { } /** * Grouping of security rule definition stages applicable as part of a network security group creation. */ - interface Definables { + interface DefinitionStages { /** * The first stage of a security rule definition. * @param the return type of the final {@link DefinitionAttachable#attach()} @@ -363,20 +363,20 @@ interface WithAttach extends Attachable.InDefinition { * @param the return type of the final {@link DefinitionAttachable#attach()} */ interface UpdateDefinition extends - UpdateDefinables.Blank, - UpdateDefinables.WithDirectionAccess, - UpdateDefinables.WithSourceAddress, - UpdateDefinables.WithSourcePort, - UpdateDefinables.WithDestinationAddress, - UpdateDefinables.WithDestinationPort, - UpdateDefinables.WithProtocol, - UpdateDefinables.WithAttach { + UpdateDefinitionStages.Blank, + UpdateDefinitionStages.WithDirectionAccess, + UpdateDefinitionStages.WithSourceAddress, + UpdateDefinitionStages.WithSourcePort, + UpdateDefinitionStages.WithDestinationAddress, + UpdateDefinitionStages.WithDestinationPort, + UpdateDefinitionStages.WithProtocol, + UpdateDefinitionStages.WithAttach { } /** * Grouping of security rule definition stages applicable as part of a network security group update. */ - interface UpdateDefinables { + interface UpdateDefinitionStages { /** * The first stage of a security rule description as part of an update of a networking security group. * @param the return type of the final {@link UpdateDefinitionAttachable#attach()} @@ -555,12 +555,12 @@ interface WithAttach extends Attachable.InUpdate { * The entirety of a security rule update as part of a network security group update. */ interface Update extends - Updatables.WithDirectionAccess, - Updatables.WithSourceAddress, - Updatables.WithSourcePort, - Updatables.WithDestinationAddress, - Updatables.WithDestinationPort, - Updatables.WithProtocol, + UpdateStages.WithDirectionAccess, + UpdateStages.WithSourceAddress, + UpdateStages.WithSourcePort, + UpdateStages.WithDestinationAddress, + UpdateStages.WithDestinationPort, + UpdateStages.WithProtocol, Settable { /** @@ -582,7 +582,7 @@ interface Update extends /** * Grouping of security rule update stages. */ - interface Updatables { + interface UpdateStages { /** * The stage of the network rule description allowing the direction and the access type to be specified. */ diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupImpl.java index 8992773d8c17..a665fc8612c5 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupImpl.java @@ -29,7 +29,7 @@ class NetworkSecurityGroupImpl extends GroupableResourceImpl implements NetworkSecurityGroup, - NetworkSecurityGroup.Definitions, + NetworkSecurityGroup.Definition, NetworkSecurityGroup.Update { private final NetworkSecurityGroupsInner client; diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityRuleImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityRuleImpl.java index 3d901ef316a7..647abe46a5b9 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityRuleImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityRuleImpl.java @@ -17,7 +17,7 @@ class NetworkSecurityRuleImpl extends ChildResourceImpl implements NetworkSecurityRule, - NetworkSecurityRule.Definition, + NetworkSecurityRule.Definition, NetworkSecurityRule.UpdateDefinition, NetworkSecurityRule.Update { From c1ceca58f80dfafbaeb9788d5013f2a06f02b5db Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 14:29:23 -0700 Subject: [PATCH 04/16] missed one --- .../management/network/implementation/NetworkInterfaceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java index ef4c9a12a3f6..3587136a6cf2 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java @@ -169,7 +169,7 @@ public NetworkInterfaceImpl withPrimaryPrivateIpAddressStatic(String staticPriva } @Override - public NetworkInterfaceImpl withNewNetworkSecurityGroup(NetworkSecurityGroup.DefinitionCreatable creatable) { + public NetworkInterfaceImpl withNewNetworkSecurityGroup(NetworkSecurityGroup.DefinitionStages.WithCreate creatable) { this.creatableNetworkSecurityGroupKey = creatable.key(); this.addCreatableDependency(creatable); return this; From f17bc4d88fd5f2de56afe315f4bab274ea378605 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 14:57:04 -0700 Subject: [PATCH 05/16] restructuring Network interfaces for consistency and better organization --- .../management/compute/VirtualMachine.java | 2 +- .../implementation/VirtualMachineImpl.java | 2 +- .../azure/management/network/Network.java | 217 +++++++++--------- .../management/network/NetworkInterface.java | 2 +- .../network/NetworkSecurityGroup.java | 1 - .../azure/management/network/Networks.java | 2 +- .../network/NicIpConfiguration.java | 2 +- .../network/implementation/NetworkImpl.java | 2 +- .../implementation/NetworkInterfaceImpl.java | 2 +- .../NicIpConfigurationImpl.java | 6 +- .../network/implementation/SubnetImpl.java | 2 +- .../samples/ManageAvailabilitySet.java | 2 +- 12 files changed, 123 insertions(+), 119 deletions(-) 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 4ff315123595..88bedfa73c59 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 @@ -302,7 +302,7 @@ interface DefinitionWithNetwork extends DefinitionWithPrimaryNetworkInterface { * @param creatable a creatable definition for a new virtual network * @return the next stage of the virtual machine definition */ - DefinitionWithPrivateIp withNewPrimaryNetwork(Network.DefinitionCreatable creatable); + DefinitionWithPrivateIp withNewPrimaryNetwork(Network.DefinitionStages.WithCreate creatable); /** * Creates a new virtual network to associate with the virtual machine's primary network interface. 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 174018acbdec..98f0cd2e0b5e 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 @@ -234,7 +234,7 @@ public VirtualMachineInstanceView refreshInstanceView() throws CloudException, I // Fluent methods for defining virtual network association for the new primary network interface @Override - public VirtualMachineImpl withNewPrimaryNetwork(Network.DefinitionCreatable creatable) { + public VirtualMachineImpl withNewPrimaryNetwork(Network.DefinitionStages.WithCreate creatable) { this.nicDefinitionWithPrivateIp = this.preparePrimaryNetworkInterface(this.namer.randomName("nic", 20)) .withNewPrimaryNetwork(creatable); return this; diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java index ab381272f180..54a2e5a9c5f3 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java @@ -44,139 +44,144 @@ public interface Network extends */ List subnets(); - /************************************************************** - * Fluent interfaces for provisioning - **************************************************************/ - /** * The entirety of the virtual network definition. */ - interface Definitions extends - DefinitionBlank, - DefinitionWithGroup, - DefinitionWithSubnet, - DefinitionCreatable, - DefinitionCreatableWithSubnet { - } - - /** - * The first stage of a virtual network definition. - */ - interface DefinitionBlank - extends GroupableResource.DefinitionWithRegion { - } - - /** - * The stage of the virtual network definition allowing to specify the resource group. - */ - interface DefinitionWithGroup - extends GroupableResource.DefinitionWithGroup { + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithGroup, + DefinitionStages.WithSubnet, + DefinitionStages.WithCreate, + DefinitionStages.WithCreateAndSubnet { } /** - * The stage of the virtual network definition allowing to add subnets. + * Grouping of virtual network definition stages. */ - interface DefinitionWithSubnet { + interface DefinitionStages { /** - * Explicitly adds a subnet to the virtual network. - *

- * If no subnets are explicitly specified, a default subnet called "subnet1" covering the - * entire first address space will be created. - *

- * Note this method's effect is additive, i.e. each time it is used, a new subnet is added to the network. - * @param name the name to assign to the subnet - * @param cidr the address space of the subnet, within the address space of the network, using the CIDR notation - * @return the next stage of the virtual network definition + * The first stage of a virtual network definition. */ - DefinitionCreatableWithSubnet withSubnet(String name, String cidr); + interface Blank + extends GroupableResource.DefinitionWithRegion { + } /** - * Explicitly defines subnets in the virtual network based on the provided map. - * @param nameCidrPairs a {@link Map} of CIDR addresses for the subnets, indexed by the name of each subnet to be defined - * @return the next stage of the virtual network definition + * The stage of the virtual network definition allowing to specify the resource group. */ - DefinitionCreatableWithSubnet withSubnets(Map nameCidrPairs); - - Subnet.DefinitionBlank defineSubnet(String name); - } - + interface WithGroup + extends GroupableResource.DefinitionWithGroup { + } - /** - * The stage of the virtual network update allowing to add or remove subnets. - */ - interface UpdateWithSubnet { /** - * Explicitly adds a subnet to the virtual network. - *

- * Note this method's effect is additive, i.e. each time it is used, a new subnet is added to the network. - * @param name the name to assign to the subnet - * @param cidr the address space of the subnet, within the address space of the network, using the CIDR notation - * @return the next stage of the virtual network update + * The stage of the virtual network definition allowing to add subnets. */ - Update withSubnet(String name, String cidr); + interface WithSubnet { + /** + * Explicitly adds a subnet to the virtual network. + *

+ * If no subnets are explicitly specified, a default subnet called "subnet1" covering the + * entire first address space will be created. + *

+ * Note this method's effect is additive, i.e. each time it is used, a new subnet is added to the network. + * @param name the name to assign to the subnet + * @param cidr the address space of the subnet, within the address space of the network, using the CIDR notation + * @return the next stage of the virtual network definition + */ + DefinitionStages.WithCreateAndSubnet withSubnet(String name, String cidr); + + /** + * Explicitly defines subnets in the virtual network based on the provided map. + * @param nameCidrPairs a {@link Map} of CIDR addresses for the subnets, indexed by the name of each subnet to be defined + * @return the next stage of the virtual network definition + */ + DefinitionStages.WithCreateAndSubnet withSubnets(Map nameCidrPairs); + + Subnet.DefinitionBlank defineSubnet(String name); + } /** - * Explicitly defines all the subnets in the virtual network based on the provided map. + * The stage of the virtual network 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, except for adding subnets. *

- * This replaces any previously existing subnets. - * @param nameCidrPairs a {@link Map} of CIDR addresses for the subnets, indexed by the name of each subnet to be added - * @return the next stage of the virtual network update + * Subnets can be added only right after the address space is explicitly specified + * (see {@link DefinitionWithAddressSpace#withAddressSpace(String)). */ - Update withSubnets(Map nameCidrPairs); + interface WithCreate extends + Creatable, + Resource.DefinitionWithTags { + + /** + * Specifies the IP address of an existing DNS server to associate with the virtual network. + *

+ * Note this method's effect is additive, i.e. each time it is used, a new dns server is added + * to the network. + * @param ipAddress the IP address of the DNS server + * @return the next stage of the virtual network definition + */ + WithCreate withDnsServer(String ipAddress); + + /** + * Explicitly adds an address space to the virtual network. + *

+ * If no address spaces are explicitly specified, a default address space with the CIDR "10.0.0.0/16" will be + * assigned to the virtual network. + *

+ * Note that this method's effect is additive, i.e. each time it is used, a new address space is added to the network. + * This method does not check for conflicts or overlaps with other address spaces. If there is a conflict, + * a cloud exception may be thrown at the time the network is created. + * @param cidr the CIDR representation of the address space + * @return the next stage of the virtual network definition + */ + WithCreateAndSubnet withAddressSpace(String cidr); + } /** - * Removes a subnet from the virtual network. - * @param name name of the subnet to remove - * @return the next stage of the virtual network update + * 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, including adding subnets. */ - Update withoutSubnet(String name); + interface WithCreateAndSubnet extends + DefinitionStages.WithCreate, + DefinitionStages.WithSubnet { + } } /** - * The stage of the virtual network 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, except for adding subnets. - *

- * Subnets can be added only right after the address space is explicitly specified - * (see {@link DefinitionWithAddressSpace#withAddressSpace(String)). + * Grouping of virtual network update stages. */ - interface DefinitionCreatable extends - Creatable, - Resource.DefinitionWithTags { - - /** - * Specifies the IP address of an existing DNS server to associate with the virtual network. - *

- * Note this method's effect is additive, i.e. each time it is used, a new dns server is added - * to the network. - * @param ipAddress the IP address of the DNS server - * @return the next stage of the virtual network definition - */ - DefinitionCreatable withDnsServer(String ipAddress); - + interface UpdateStages { /** - * Explicitly adds an address space to the virtual network. - *

- * If no address spaces are explicitly specified, a default address space with the CIDR "10.0.0.0/16" will be - * assigned to the virtual network. - *

- * Note that this method's effect is additive, i.e. each time it is used, a new address space is added to the network. - * This method does not check for conflicts or overlaps with other address spaces. If there is a conflict, - * a cloud exception may be thrown at the time the network is created. - * @param cidr the CIDR representation of the address space - * @return the next stage of the virtual network definition + * The stage of the virtual network update allowing to add or remove subnets. */ - DefinitionCreatableWithSubnet withAddressSpace(String cidr); - } - - /** - * 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, including adding subnets. - */ - interface DefinitionCreatableWithSubnet extends - DefinitionCreatable, - DefinitionWithSubnet { + interface WithSubnet { + /** + * Explicitly adds a subnet to the virtual network. + *

+ * Note this method's effect is additive, i.e. each time it is used, a new subnet is added to the network. + * @param name the name to assign to the subnet + * @param cidr the address space of the subnet, within the address space of the network, using the CIDR notation + * @return the next stage of the virtual network update + */ + Update withSubnet(String name, String cidr); + + /** + * Explicitly defines all the subnets in the virtual network based on the provided map. + *

+ * This replaces any previously existing subnets. + * @param nameCidrPairs a {@link Map} of CIDR addresses for the subnets, indexed by the name of each subnet to be added + * @return the next stage of the virtual network update + */ + Update withSubnets(Map nameCidrPairs); + + /** + * Removes a subnet from the virtual network. + * @param name name of the subnet to remove + * @return the next stage of the virtual network update + */ + Update withoutSubnet(String name); + } } /** @@ -188,7 +193,7 @@ interface DefinitionCreatableWithSubnet extends interface Update extends Appliable, Resource.UpdateWithTags, - UpdateWithSubnet { + UpdateStages.WithSubnet { /** * Specifies the IP address of the DNS server to associate with the virtual network. diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java index 04b8aff9ce07..6f83585c6ec2 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java @@ -164,7 +164,7 @@ interface DefinitionWithNetwork { * @param creatable a creatable definition for a new virtual network * @return the next stage of the network interface definition */ - DefinitionWithPrivateIp withNewPrimaryNetwork(Network.DefinitionCreatable creatable); + DefinitionWithPrivateIp withNewPrimaryNetwork(Network.DefinitionStages.WithCreate creatable); /** * Creates a new virtual network to associate with the network interface's primary Ip configuration. diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java index 64efb47280d1..b1a67d6b5d14 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java @@ -5,7 +5,6 @@ */ package com.microsoft.azure.management.network; - import java.util.List; import com.microsoft.azure.management.network.implementation.api.NetworkSecurityGroupInner; 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 cc817806b046..0d98140c9931 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 @@ -18,7 +18,7 @@ * Entry point to virtual network management API in Azure. */ public interface Networks extends - SupportsCreating, + SupportsCreating, SupportsListing, SupportsListingByGroup, SupportsGettingByGroup, diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NicIpConfiguration.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NicIpConfiguration.java index b40f57217b9b..2c83745f976e 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NicIpConfiguration.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NicIpConfiguration.java @@ -100,7 +100,7 @@ interface DefinitionWithNetwork { * @param creatable a creatable definition for a new virtual network * @return the next stage of the Ip configuration definition */ - DefinitionWithPrivateIp withNewNetwork(Network.DefinitionCreatable creatable); + DefinitionWithPrivateIp withNewNetwork(Network.DefinitionStages.WithCreate creatable); /** * Creates a new virtual network to associate with the Ip configuration. diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java index 38e7997994e8..820ec9d07348 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java @@ -30,7 +30,7 @@ class NetworkImpl extends GroupableResourceImpl implements Network, - Network.Definitions, + Network.Definition, Network.Update { private final VirtualNetworksInner client; diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java index 3587136a6cf2..f2f8e0f7fc84 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java @@ -103,7 +103,7 @@ public ServiceCall applyAsync(ServiceCallback callback) { **************************************************/ @Override - public NetworkInterfaceImpl withNewPrimaryNetwork(Network.DefinitionCreatable creatable) { + public NetworkInterfaceImpl withNewPrimaryNetwork(Network.DefinitionStages.WithCreate creatable) { this.primaryIpConfiguration().withNewNetwork(creatable); return this; } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NicIpConfigurationImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NicIpConfigurationImpl.java index 8cf334490730..1df15ff649e6 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NicIpConfigurationImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NicIpConfigurationImpl.java @@ -120,7 +120,7 @@ public NetworkInterface set() { } @Override - public NicIpConfigurationImpl withNewNetwork(Network.DefinitionCreatable creatable) { + public NicIpConfigurationImpl withNewNetwork(Network.DefinitionStages.WithCreate creatable) { this.creatableVirtualNetworkKey = creatable.key(); this.parent().addToCreatableDependencies(creatable); return this; @@ -128,11 +128,11 @@ public NicIpConfigurationImpl withNewNetwork(Network.DefinitionCreatable creatab @Override public NicIpConfigurationImpl withNewNetwork(String name, String addressSpaceCidr) { - Network.DefinitionWithGroup definitionWithGroup = this.networkManager.networks() + Network.DefinitionStages.WithGroup definitionWithGroup = this.networkManager.networks() .define(name) .withRegion(this.parent().region()); - Network.DefinitionCreatable definitionAfterGroup; + Network.DefinitionStages.WithCreate definitionAfterGroup; if (this.parent().newGroup() != null) { definitionAfterGroup = definitionWithGroup.withNewGroup(this.parent().newGroup()); } else { diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java index a4c1258a72a8..844035f5310e 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java @@ -17,7 +17,7 @@ class SubnetImpl extends ChildResourceImpl implements Subnet, - Subnet.Definition { + Subnet.Definition { protected SubnetImpl(String name, SubnetInner inner, NetworkImpl parent) { super(name, inner, parent); 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 eff82f0f7ca0..b9316d993fc4 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 @@ -87,7 +87,7 @@ public static void main(String[] args) { //============================================================= // Define a virtual network for the VMs in this availability set - Network.DefinitionCreatable network = azure.networks() + Network.DefinitionStages.WithCreate network = azure.networks() .define(vnetName) .withRegion(Region.US_EAST) .withExistingGroup(rgName) From 91a18720b125b317dadeaec1fc3d07e853b82142 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 15:30:48 -0700 Subject: [PATCH 06/16] Fix for https://github.com/Azure/azure-sdk-for-java/issues/774- PIP.allocationMethod now returns an enum --- .../management/network/PublicIpAddress.java | 35 ++++++++++++++++++- .../implementation/PublicIpAddressImpl.java | 4 +-- .../microsoft/azure/TestPublicIpAddress.java | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-) 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 4757257da1a7..d48ccb2e9d55 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 @@ -23,6 +23,39 @@ public interface PublicIpAddress extends Wrapper, Updatable { + /** + * IP allocation methods. + */ + enum IpAllocationMethod { + STATIC(com.microsoft.azure.management.network.implementation.api.IPAllocationMethod.STATIC), + DYNAMIC(com.microsoft.azure.management.network.implementation.api.IPAllocationMethod.DYNAMIC); + + private final String name; + IpAllocationMethod(String name) { + this.name = name; + } + + public String toString() { + return this.name; + } + + /** + * Converts a string value returned by Azure into a constant. + * @param value the value to convert + * @return the matching enum constant, or null if no match + */ + public static IpAllocationMethod fromString(String value) { + for (IpAllocationMethod i : IpAllocationMethod.values()) { + if (i.name.equalsIgnoreCase(value)) { + return i; + } + } + + return null; + } + } + + /*********************************************************** * Getters ***********************************************************/ @@ -50,7 +83,7 @@ public interface PublicIpAddress extends /** * @return the IP address allocation method (Static/Dynamic) */ - String ipAllocationMethod(); + IpAllocationMethod ipAllocationMethod(); /** * @return the idle connection timeout setting (in minutes) 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 d5035786b4f6..c7216f46364c 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 @@ -109,8 +109,8 @@ public int idleTimeoutInMinutes() { } @Override - public String ipAllocationMethod() { - return this.inner().publicIPAllocationMethod(); + public IpAllocationMethod ipAllocationMethod() { + return IpAllocationMethod.fromString(this.inner().publicIPAllocationMethod()); } @Override diff --git a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java index c86845cbf660..39d25a7dc742 100644 --- a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java +++ b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java @@ -58,7 +58,7 @@ public void print(PublicIpAddress resource) { .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()) + .append("\n\tIP allocation method: ").append(resource.ipAllocationMethod().toString()) .toString()); } } From 28a9723f0072899fb17b105dced46df2aa98f7ee Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 16:17:58 -0700 Subject: [PATCH 07/16] minor impl cleanup --- .../azure/management/compute/implementation/SkuImpl.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/SkuImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/SkuImpl.java index 9aba88c7a1a9..068179985e9e 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/SkuImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/SkuImpl.java @@ -12,7 +12,6 @@ */ class SkuImpl implements Sku { - private final VirtualMachineImagesInner client; private final Offer offer; private final String skuName; private final VirtualMachineImagesInSku imagesInSku; @@ -20,7 +19,6 @@ class SkuImpl SkuImpl(Offer offer, String skuName, VirtualMachineImagesInner client) { this.offer = offer; this.skuName = skuName; - this.client = client; this.imagesInSku = new VirtualMachineImagesInSkuImpl(this, client); } From a60bf7342cbd2a68719a17fc46039241995d267c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 16:18:09 -0700 Subject: [PATCH 08/16] minor impls cleanup --- .../azure/management/compute/implementation/OfferImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/OfferImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/OfferImpl.java index 51a73fc35461..ff7a81c02411 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/OfferImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/OfferImpl.java @@ -12,7 +12,7 @@ class OfferImpl implements Offer { private final Publisher publisher; private final String offerName; - private final Skus skus; + private final SkusImpl skus; OfferImpl(Publisher publisher, String offer, VirtualMachineImagesInner client) { this.publisher = publisher; From 3edc973784fa8df393ce7e50d089692b0c6eb875 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 16:20:53 -0700 Subject: [PATCH 09/16] turning Network@subnets() into a full fledged collection to be able to add other functionality to it --- .../azure/management/network/Network.java | 8 ++-- .../azure/management/network/Subnets.java | 14 +++++++ .../network/implementation/NetworkImpl.java | 4 +- .../network/implementation/SubnetsImpl.java | 39 +++++++++++++++++++ .../compute/samples/ManageVirtualMachine.java | 2 +- .../azure/management/samples/Utils.java | 9 +++-- .../java/com/microsoft/azure/TestNetwork.java | 10 +++-- 7 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnets.java create mode 100644 azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetsImpl.java diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java index 54a2e5a9c5f3..fe86093a26e6 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java @@ -40,9 +40,9 @@ public interface Network extends List dnsServerIPs(); /** - * @return list of subnets of this virtual network + * @return subnets of this virtual network */ - List subnets(); + Subnets subnets(); /** * The entirety of the virtual network definition. @@ -102,7 +102,7 @@ interface WithSubnet { /** * The stage of the virtual network definition which contains all the minimum required inputs for - * the resource to be created (via {@link DefinitionCreatable#create()}), but also allows + * the resource to be created (via {@link WithCreate#create()}), but also allows * for any other optional settings to be specified, except for adding subnets. *

* Subnets can be added only right after the address space is explicitly specified @@ -139,7 +139,7 @@ interface WithCreate extends /** * 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 + * the resource to be created (via {@link WithCreate#create()}), but also allows * for any other optional settings to be specified, including adding subnets. */ interface WithCreateAndSubnet extends diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnets.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnets.java new file mode 100644 index 000000000000..1a63aabe6de8 --- /dev/null +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnets.java @@ -0,0 +1,14 @@ +/** + * 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.network; + +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Interface implementing subnet access. + */ +public interface Subnets extends SupportsListing { +} diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java index 820ec9d07348..94e3d33098de 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java @@ -149,8 +149,8 @@ public List dnsServerIPs() { } @Override - public List subnets() { - return Collections.unmodifiableList(this.subnets); + public SubnetsImpl subnets() { + return new SubnetsImpl(this); } @Override diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetsImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetsImpl.java new file mode 100644 index 000000000000..74dbf25f58a7 --- /dev/null +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetsImpl.java @@ -0,0 +1,39 @@ +/** + * 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.network.implementation; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.network.Subnet; +import com.microsoft.azure.management.network.Subnets; +import com.microsoft.azure.management.network.implementation.api.SubnetInner; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +import java.io.IOException; + +/** + * The implementation for {@link Subnets}. + */ +class SubnetsImpl + extends ReadableWrappersImpl + implements Subnets { + + private final NetworkImpl parentNetwork; + + SubnetsImpl(NetworkImpl parentNetwork) { + this.parentNetwork = parentNetwork; + } + + @Override + public PagedList list() throws CloudException, IOException { + return wrapList(parentNetwork.inner().subnets()); + } + + @Override + protected SubnetImpl wrapModel(SubnetInner inner) { + return new SubnetImpl(inner.name(), inner, this.parentNetwork); + } +} 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 8b8ef4577866..25994cc0e535 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 @@ -212,7 +212,7 @@ public static void main(String[] args) { .withRegion(Region.US_EAST) .withExistingGroup(rgName) .withExistingPrimaryNetwork(network) - .withSubnet(network.subnets().get(0).name()) + .withSubnet(network.subnets().list().get(0).name()) .withPrimaryPrivateIpAddressDynamic() .withoutPrimaryPublicIpAddress() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java b/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java index ec50e4a2556b..0f0865d482b5 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java @@ -7,6 +7,7 @@ package com.microsoft.azure.management.samples; +import com.microsoft.azure.CloudException; import com.microsoft.azure.management.compute.AvailabilitySet; import com.microsoft.azure.management.compute.VirtualMachine; import com.microsoft.azure.management.compute.implementation.api.DataDisk; @@ -19,7 +20,7 @@ import com.microsoft.azure.management.storage.StorageAccount; import com.microsoft.azure.management.storage.implementation.api.StorageAccountKey; - +import java.io.IOException; import java.util.Calendar; import java.util.List; import java.util.UUID; @@ -148,8 +149,10 @@ public static void print(AvailabilitySet resource) { /** * Print network info. * @param resource a network + * @throws IOException IO errors + * @throws CloudException Cloud errors */ - public static void print(Network resource) { + public static void print(Network resource) throws CloudException, IOException { StringBuilder info = new StringBuilder(); info.append("Network: ").append(resource.id()) .append("Name: ").append(resource.name()) @@ -160,7 +163,7 @@ public static void print(Network resource) { .append("\n\tDNS server IPs: ").append(resource.dnsServerIPs()); // Output subnets - for (Subnet subnet : resource.subnets()) { + for (Subnet subnet : resource.subnets().list()) { info.append("\n\tSubnet: ").append(subnet.name()) .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); } diff --git a/azure/src/test/java/com/microsoft/azure/TestNetwork.java b/azure/src/test/java/com/microsoft/azure/TestNetwork.java index 542ef981b1a4..4e6b562acb2c 100644 --- a/azure/src/test/java/com/microsoft/azure/TestNetwork.java +++ b/azure/src/test/java/com/microsoft/azure/TestNetwork.java @@ -57,9 +57,13 @@ public void print(Network resource) { .append("\n\tDNS server IPs: ").append(resource.dnsServerIPs()); // Output subnets - for (Subnet subnet : resource.subnets()) { - info.append("\n\tSubnet: ").append(subnet.name()) - .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); + try { + for (Subnet subnet : resource.subnets().list()) { + info.append("\n\tSubnet: ").append(subnet.name()) + .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); + } + } catch (Exception e) { + e.printStackTrace(); } System.out.println(info.toString()); From 5109c3c075a8462d30619d3cbf56970dc7ff61a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 16:22:59 -0700 Subject: [PATCH 10/16] minor javadoc correction --- .../java/com/microsoft/azure/management/network/Network.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java index fe86093a26e6..b360b256cd83 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java @@ -106,7 +106,7 @@ interface WithSubnet { * for any other optional settings to be specified, except for adding subnets. *

* Subnets can be added only right after the address space is explicitly specified - * (see {@link DefinitionWithAddressSpace#withAddressSpace(String)). + * (see {@link WithCreate#withAddressSpace(String)}). */ interface WithCreate extends Creatable, From 5c17ef3f5a65b4cfd5c2f7318d02cd520aac7d33 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 16:30:44 -0700 Subject: [PATCH 11/16] NIC test fix --- .../azure/TestVirtualMachineNics.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/azure/src/test/java/com/microsoft/azure/TestVirtualMachineNics.java b/azure/src/test/java/com/microsoft/azure/TestVirtualMachineNics.java index 4729fb3077c2..13d2d9869174 100644 --- a/azure/src/test/java/com/microsoft/azure/TestVirtualMachineNics.java +++ b/azure/src/test/java/com/microsoft/azure/TestVirtualMachineNics.java @@ -1,3 +1,9 @@ +/** + * 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.management.compute.KnownWindowsVirtualMachineImage; @@ -37,7 +43,7 @@ public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exc // Prepare the virtual network definition [shared by primary and secondary network interfaces] final String vnetName = "vnet" + this.testId; - Network.DefinitionCreatable networkCreatable = this.networks + Network.DefinitionStages.WithCreate networkCreatable = this.networks .define(vnetName) .withRegion(Region.US_EAST) .withNewGroup(resourceGroupCreatable) @@ -54,6 +60,15 @@ public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exc // .withNewPrimaryPublicIpAddress(secondaryPublicIpCreatable); // [Secondary NIC cannot have PublicIp - Only primary network interface can reference a public IP address] + // Prepare the secondary network interface definition + final String secondaryNicName2 = "nic2" + this.testId; + NetworkInterface.DefinitionCreatable secondaryNetworkInterfaceCreatable2 = this.networkInterfaces + .define(secondaryNicName2) + .withRegion(Region.US_EAST) + .withNewGroup(resourceGroupCreatable) + .withNewPrimaryNetwork(networkCreatable) + .withPrimaryPrivateIpAddressStatic("10.0.0.6"); + // Create Virtual Machine final String vmName = "vm" + this.testId; final String primaryPipName = "pip" + vmName; @@ -68,6 +83,7 @@ public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exc .withPassword("12NewPA$$w0rd!") .withSize(VirtualMachineSizeTypes.STANDARD_A9) .withNewSecondaryNetworkInterface(secondaryNetworkInterfaceCreatable) + .withNewSecondaryNetworkInterface(secondaryNetworkInterfaceCreatable2) .create(); Assert.assertTrue(virtualMachine.networkInterfaceIds().size() == 2); From 35fe785d0e6a3ac104ba5dc9d1d44d109ac4e330 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 17:34:54 -0700 Subject: [PATCH 12/16] Network#subnets() as Map indexed by name --- .../azure/management/network/Network.java | 7 +++- .../azure/management/network/Subnets.java | 14 ------- .../network/implementation/NetworkImpl.java | 25 ++++++------ .../network/implementation/SubnetImpl.java | 3 +- .../network/implementation/SubnetsImpl.java | 39 ------------------- .../compute/samples/ManageVirtualMachine.java | 2 +- .../azure/management/samples/Utils.java | 2 +- .../java/com/microsoft/azure/TestNetwork.java | 10 ++--- 8 files changed, 24 insertions(+), 78 deletions(-) delete mode 100644 azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnets.java delete mode 100644 azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetsImpl.java diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java index b360b256cd83..924ee8f5475c 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Network.java @@ -40,9 +40,12 @@ public interface Network extends List dnsServerIPs(); /** - * @return subnets of this virtual network + * @return subnets of this virtual network as a map indexed by subnet name + * + *

Note that when a virtual network is created with no subnets explicitly defined, a default subnet is + * automatically created with the name "subnet1". */ - Subnets subnets(); + Map subnets(); /** * The entirety of the virtual network definition. diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnets.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnets.java deleted file mode 100644 index 1a63aabe6de8..000000000000 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnets.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * 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.network; - -import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; - -/** - * Interface implementing subnet access. - */ -public interface Subnets extends SupportsListing { -} diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java index 94e3d33098de..45c33c89d612 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; /** * Implementation for {@link Network} and its create and update interfaces. @@ -34,7 +35,7 @@ class NetworkImpl Network.Update { private final VirtualNetworksInner client; - private List subnets; + private TreeMap subnets; NetworkImpl(String name, VirtualNetworkInner innerModel, @@ -46,10 +47,10 @@ class NetworkImpl } private void initializeSubnetsFromInner() { - this.subnets = new ArrayList<>(); + this.subnets = new TreeMap<>(); for (SubnetInner subnetInner : this.inner().subnets()) { SubnetImpl subnet = new SubnetImpl(subnetInner.name(), subnetInner, this); - this.subnets.add(subnet); + this.subnets.put(subnetInner.name(), subnet); } } @@ -82,6 +83,12 @@ public NetworkImpl withDnsServer(String ipAddress) { return this; } + NetworkImpl withSubnet(SubnetImpl subnet) { + this.inner().subnets().add(subnet.inner()); + this.subnets.put(subnet.name(), subnet); + return this; + } + @Override public NetworkImpl withSubnet(String name, String cidr) { return this.defineSubnet(name) @@ -103,13 +110,7 @@ public NetworkImpl withSubnets(Map nameCidrPairs) { @Override public NetworkImpl withoutSubnet(String name) { // Remove from cache - List s = this.subnets; - for (int i = 0; i < s.size(); i++) { - if (s.get(i).name().equalsIgnoreCase(name)) { - s.remove(i); - break; - } - } + this.subnets.remove(name); // Remove from inner List innerSubnets = this.inner().subnets(); @@ -149,8 +150,8 @@ public List dnsServerIPs() { } @Override - public SubnetsImpl subnets() { - return new SubnetsImpl(this); + public Map subnets() { + return Collections.unmodifiableMap(this.subnets); } @Override diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java index 844035f5310e..dbaab0f5d720 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java @@ -46,7 +46,6 @@ public SubnetImpl withAddressPrefix(String cidr) { @Override public NetworkImpl attach() { - this.parent().inner().subnets().add(this.inner()); - return this.parent(); + return this.parent().withSubnet(this); } } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetsImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetsImpl.java deleted file mode 100644 index 74dbf25f58a7..000000000000 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetsImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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.network.implementation; - -import com.microsoft.azure.CloudException; -import com.microsoft.azure.PagedList; -import com.microsoft.azure.management.network.Subnet; -import com.microsoft.azure.management.network.Subnets; -import com.microsoft.azure.management.network.implementation.api.SubnetInner; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; - -import java.io.IOException; - -/** - * The implementation for {@link Subnets}. - */ -class SubnetsImpl - extends ReadableWrappersImpl - implements Subnets { - - private final NetworkImpl parentNetwork; - - SubnetsImpl(NetworkImpl parentNetwork) { - this.parentNetwork = parentNetwork; - } - - @Override - public PagedList list() throws CloudException, IOException { - return wrapList(parentNetwork.inner().subnets()); - } - - @Override - protected SubnetImpl wrapModel(SubnetInner inner) { - return new SubnetImpl(inner.name(), inner, this.parentNetwork); - } -} 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 25994cc0e535..1b1de0ad73ec 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 @@ -212,7 +212,7 @@ public static void main(String[] args) { .withRegion(Region.US_EAST) .withExistingGroup(rgName) .withExistingPrimaryNetwork(network) - .withSubnet(network.subnets().list().get(0).name()) + .withSubnet("subnet1") // Referencing the default subnet name when no name specified at creation .withPrimaryPrivateIpAddressDynamic() .withoutPrimaryPublicIpAddress() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java b/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java index 0f0865d482b5..c978c4bbaa7b 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/samples/Utils.java @@ -163,7 +163,7 @@ public static void print(Network resource) throws CloudException, IOException { .append("\n\tDNS server IPs: ").append(resource.dnsServerIPs()); // Output subnets - for (Subnet subnet : resource.subnets().list()) { + for (Subnet subnet : resource.subnets().values()) { info.append("\n\tSubnet: ").append(subnet.name()) .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); } diff --git a/azure/src/test/java/com/microsoft/azure/TestNetwork.java b/azure/src/test/java/com/microsoft/azure/TestNetwork.java index 4e6b562acb2c..430d613f3ecc 100644 --- a/azure/src/test/java/com/microsoft/azure/TestNetwork.java +++ b/azure/src/test/java/com/microsoft/azure/TestNetwork.java @@ -57,14 +57,10 @@ public void print(Network resource) { .append("\n\tDNS server IPs: ").append(resource.dnsServerIPs()); // Output subnets - try { - for (Subnet subnet : resource.subnets().list()) { - info.append("\n\tSubnet: ").append(subnet.name()) - .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); + for (Subnet subnet : resource.subnets().values()) { + info.append("\n\tSubnet: ").append(subnet.name()) + .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); } - } catch (Exception e) { - e.printStackTrace(); - } System.out.println(info.toString()); } From 4c1d36bda5ab149caf91cb94e6e6ae0b02e9a83d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 17:35:21 -0700 Subject: [PATCH 13/16] javadoc fixes --- .../network/NetworkSecurityGroup.java | 2 +- .../network/NetworkSecurityRule.java | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java index b1a67d6b5d14..ab51d8be8cb3 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroup.java @@ -92,7 +92,7 @@ interface WithRule { /** * The stage of the definition which contains all the minimum required inputs for - * the resource to be created (via {@link DefinitionCreatable#create()}), but also allows + * the resource to be created (via {@link WithCreate#create()}), but also allows * for any other optional settings to be specified. */ interface WithCreate extends diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java index 2204d090dee0..58fa4186a567 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityRule.java @@ -187,14 +187,14 @@ interface Definition extends interface DefinitionStages { /** * The first stage of a security rule definition. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface Blank extends WithDirectionAccess { } /** * The stage of the security rule definition allowing the protocol that the rule applies to to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithProtocol { /** @@ -213,7 +213,7 @@ interface WithProtocol { /** * The stage of the network rule definition allowing the destination port(s) to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithDestinationPort { /** @@ -240,7 +240,7 @@ interface WithDestinationPort { /** * The stage of the network rule definition allowing the destination address to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithDestinationAddress { /** @@ -259,7 +259,7 @@ interface WithDestinationAddress { /** * The stage of the network rule definition allowing the source port(s) to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithSourcePort { /** @@ -286,7 +286,7 @@ interface WithSourcePort { /** * The stage of the network rule definition allowing the source address to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithSourceAddress { /** @@ -305,7 +305,7 @@ interface WithSourceAddress { /** * The stage of the network rule definition allowing the direction and the access type to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithDirectionAccess { /** @@ -360,7 +360,7 @@ interface WithAttach extends Attachable.InDefinition { } /** The entirety of a network security rule definition as part of a network security group update. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link UpdateDefinitionStages.WithAttach#attach()} */ interface UpdateDefinition extends UpdateDefinitionStages.Blank, @@ -386,7 +386,7 @@ interface Blank extends WithDirectionAccess { /** * The stage of the network rule description allowing the direction and the access type to be specified. - * @param the return type of the final {@link DefinitionAttachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithDirectionAccess { /** @@ -416,7 +416,7 @@ interface WithDirectionAccess { /** * The stage of the network rule definition allowing the source address to be specified. - * @param the return type of the final {@link Attachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithSourceAddress { /** @@ -435,7 +435,7 @@ interface WithSourceAddress { /** * The stage of the network rule definition allowing the source port(s) to be specified. - * @param the return type of the final {@link Attachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithSourcePort { /** @@ -462,7 +462,7 @@ interface WithSourcePort { /** * The stage of the network rule definition allowing the destination address to be specified. - * @param the return type of the final {@link Attachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithDestinationAddress { /** @@ -481,7 +481,7 @@ interface WithDestinationAddress { /** * The stage of the network rule definition allowing the destination port(s) to be specified. - * @param the return type of the final {@link Attachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithDestinationPort { /** @@ -508,7 +508,7 @@ interface WithDestinationPort { /** * The stage of the security rule definition allowing the protocol that the rule applies to to be specified. - * @param the return type of the final {@link Attachable#attach()} + * @param the return type of the final {@link WithAttach#attach()} */ interface WithProtocol { /** From d8a5a8064b2c5815527b4460a5ab2bf5db4e1667 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 19:07:05 -0700 Subject: [PATCH 14/16] refactoring *Managers (except ResourceManager) to track the inner client in the base class for consistency and reuse in scenarios where references to related resources are needed --- .../implementation/ComputeManager.java | 19 +++++++++---------- .../implementation/NetworkManager.java | 18 +++++++++--------- .../arm/implementation/Manager.java | 9 ++++++--- .../implementation/StorageManager.java | 17 ++++++++--------- 4 files changed, 32 insertions(+), 31 deletions(-) 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 4eaca4be6795..e1be7d2aaa3a 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,12 +16,10 @@ /** * 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; - // The sdk clients - private ComputeManagementClientImpl computeManagementClient; // The collections private AvailabilitySets availabilitySets; private VirtualMachines virtualMachines; @@ -85,9 +83,10 @@ public ComputeManager authenticate(ServiceClientCredentials credentials, String } private ComputeManager(RestClient restClient, String subscriptionId) { - super(restClient, subscriptionId); - computeManagementClient = new ComputeManagementClientImpl(restClient); - computeManagementClient.withSubscriptionId(subscriptionId); + super( + restClient, + subscriptionId, + new ComputeManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); storageManager = StorageManager.authenticate(restClient, subscriptionId); networkManager = NetworkManager.authenticate(restClient, subscriptionId); } @@ -98,7 +97,7 @@ private ComputeManager(RestClient restClient, String subscriptionId) { public AvailabilitySets availabilitySets() { if (availabilitySets == null) { availabilitySets = new AvailabilitySetsImpl( - computeManagementClient.availabilitySets(), + super.innerManagementClient.availabilitySets(), this.resourceManager()); } return availabilitySets; @@ -109,8 +108,8 @@ public AvailabilitySets availabilitySets() { */ public VirtualMachines virtualMachines() { if (virtualMachines == null) { - virtualMachines = new VirtualMachinesImpl(computeManagementClient.virtualMachines(), - computeManagementClient.virtualMachineSizes(), + virtualMachines = new VirtualMachinesImpl(super.innerManagementClient.virtualMachines(), + super.innerManagementClient.virtualMachineSizes(), this, this.resourceManager(), storageManager, @@ -124,7 +123,7 @@ public VirtualMachines virtualMachines() { */ public VirtualMachineImages virtualMachineImages() { if (virtualMachineImages == null) { - virtualMachineImages = new VirtualMachineImagesImpl(computeManagementClient.virtualMachineImages()); + virtualMachineImages = new VirtualMachineImagesImpl(super.innerManagementClient.virtualMachineImages()); } return virtualMachineImages; } 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 31e228c87fd5..8507d4b36ffa 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,8 +20,7 @@ /** * Entry point to Azure network management. */ -public final class NetworkManager extends Manager { - private final NetworkManagementClientImpl networkManagementClient; +public final class NetworkManager extends Manager { // Collections private PublicIpAddresses publicIpAddresses; @@ -90,9 +89,10 @@ public NetworkManager authenticate(ServiceClientCredentials credentials, String } private NetworkManager(RestClient restClient, String subscriptionId) { - super(restClient, subscriptionId); - networkManagementClient = new NetworkManagementClientImpl(restClient); - networkManagementClient.withSubscriptionId(subscriptionId); + super( + restClient, + subscriptionId, + new NetworkManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); } /** @@ -101,7 +101,7 @@ private NetworkManager(RestClient restClient, String subscriptionId) { public Networks networks() { if (this.networks == null) { this.networks = new NetworksImpl( - this.networkManagementClient.virtualNetworks(), + super.innerManagementClient, super.resourceManager()); } return this.networks; @@ -113,7 +113,7 @@ public Networks networks() { public NetworkSecurityGroups networkSecurityGroups() { if (this.networkSecurityGroups == null) { this.networkSecurityGroups = new NetworkSecurityGroupsImpl( - this.networkManagementClient.networkSecurityGroups(), + super.innerManagementClient.networkSecurityGroups(), super.resourceManager()); } return this.networkSecurityGroups; @@ -125,7 +125,7 @@ public NetworkSecurityGroups networkSecurityGroups() { public PublicIpAddresses publicIpAddresses() { if (this.publicIpAddresses == null) { this.publicIpAddresses = new PublicIpAddressesImpl( - this.networkManagementClient.publicIPAddresses(), + super.innerManagementClient.publicIPAddresses(), super.resourceManager()); } return this.publicIpAddresses; @@ -137,7 +137,7 @@ public PublicIpAddresses publicIpAddresses() { public NetworkInterfaces networkInterfaces() { if (networkInterfaces == null) { this.networkInterfaces = new NetworkInterfacesImpl( - this.networkManagementClient.networkInterfaces(), + super.innerManagementClient.networkInterfaces(), this, super.resourceManager() ); 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 3c7cb9f486b1..52a238102de3 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 @@ -12,15 +12,18 @@ /** * Base class for Azure resource managers. * @param specific manager type + * @param inner management client implementation type */ -public abstract class Manager { +public abstract class Manager { private final ResourceManager resourceManager; + protected final InnerT innerManagementClient; - protected Manager(RestClient restClient, String subscriptionId) { + protected Manager(RestClient restClient, String subscriptionId, InnerT innerManagementClient) { this.resourceManager = ResourceManager.authenticate(restClient).withSubscription(subscriptionId); + this.innerManagementClient = innerManagementClient; } - + protected ResourceManager resourceManager() { return 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 05f84c147892..0393815e0b9a 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,9 +19,7 @@ /** * Entry point to Azure storage resource management. */ -public final class StorageManager extends Manager { - private final StorageManagementClientImpl storageManagementClient; - +public final class StorageManager extends Manager { // Collections private StorageAccounts storageAccounts; private Usages storageUsages; @@ -83,10 +81,11 @@ public StorageManager authenticate(ServiceClientCredentials credentials, String } private StorageManager(RestClient restClient, String subscriptionId) { - super(restClient, subscriptionId); - storageManagementClient = new StorageManagementClientImpl(restClient); - storageManagementClient.withSubscriptionId(subscriptionId); - } + super( + restClient, + subscriptionId, + new StorageManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); + } /** * @return the storage account management API entry point @@ -94,7 +93,7 @@ private StorageManager(RestClient restClient, String subscriptionId) { public StorageAccounts storageAccounts() { if (storageAccounts == null) { storageAccounts = new StorageAccountsImpl( - storageManagementClient.storageAccounts(), + super.innerManagementClient.storageAccounts(), super.resourceManager()); } return storageAccounts; @@ -105,7 +104,7 @@ public StorageAccounts storageAccounts() { */ public Usages usages() { if (storageUsages == null) { - storageUsages = new UsagesImpl(storageManagementClient); + storageUsages = new UsagesImpl(super.innerManagementClient); } return storageUsages; } From 0646416e10f21393641ef68ee30a8d03960e6540 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 19:56:45 -0700 Subject: [PATCH 15/16] pushing service manager into base classes GroupableResourcesImpl and GroupableResourceImpl --- .../implementation/AvailabilitySetImpl.java | 13 +++++++-- .../implementation/AvailabilitySetsImpl.java | 18 ++++++++---- .../implementation/ComputeManager.java | 3 +- .../implementation/VirtualMachineImpl.java | 12 ++++---- .../implementation/VirtualMachinesImpl.java | 15 ++++++---- .../network/implementation/NetworkImpl.java | 25 +++++++++------- .../implementation/NetworkInterfaceImpl.java | 16 +++++----- .../implementation/NetworkInterfacesImpl.java | 20 +++++++------ .../implementation/NetworkManager.java | 14 +++++---- .../NetworkSecurityGroupImpl.java | 28 +++++++++++------- .../NetworkSecurityGroupsImpl.java | 28 ++++++++++++++---- .../network/implementation/NetworksImpl.java | 29 +++++++++++++++---- .../implementation/PublicIpAddressImpl.java | 11 +++++-- .../implementation/PublicIpAddressesImpl.java | 28 ++++++++++++++---- .../GroupableResourcesImpl.java | 10 +++++-- .../arm/implementation/Manager.java | 2 +- .../implementation/GroupableResourceImpl.java | 14 +++++++-- .../implementation/GenericResourceImpl.java | 8 +++-- .../implementation/GenericResourcesImpl.java | 14 +++++---- .../implementation/StorageAccountImpl.java | 11 +++++-- .../implementation/StorageAccountsImpl.java | 20 +++++++++---- .../implementation/StorageManager.java | 3 +- 22 files changed, 237 insertions(+), 105 deletions(-) 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 460165bfcea3..42aff941744f 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 @@ -25,19 +25,26 @@ */ class AvailabilitySetImpl extends - GroupableResourceImpl + GroupableResourceImpl< + AvailabilitySet, + AvailabilitySetInner, + AvailabilitySetImpl, + ComputeManager> implements AvailabilitySet, AvailabilitySet.Definitions, AvailabilitySet.Update { + private List idOfVMsInSet; + // The client to make AvailabilitySet Management API calls private final AvailabilitySetsInner client; AvailabilitySetImpl(String name, AvailabilitySetInner innerModel, final AvailabilitySetsInner client, - final ResourceManager resourceManager) { - super(name, innerModel, resourceManager); + final ResourceManager resourceManager, + final ComputeManager computeManager) { + super(name, innerModel, resourceManager, computeManager); this.client = client; } 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 47ed3152bab1..0074fba50504 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 @@ -25,13 +25,19 @@ * The implementation for {@link AvailabilitySets}. */ class AvailabilitySetsImpl - extends GroupableResourcesImpl + extends GroupableResourcesImpl< + AvailabilitySet, + AvailabilitySetImpl, + AvailabilitySetInner, + AvailabilitySetsInner, + ComputeManager> implements AvailabilitySets { AvailabilitySetsImpl( final AvailabilitySetsInner client, - final ResourceManager resourceManager) { - super(resourceManager, client); + final ResourceManager resourceManager, + final ComputeManager computeManager) { + super(resourceManager, client, computeManager); } @Override @@ -79,7 +85,8 @@ protected AvailabilitySetImpl wrapModel(String name) { return new AvailabilitySetImpl(name, new AvailabilitySetInner(), this.innerCollection, - this.resourceManager); + this.resourceManager, + super.myManager); } @Override @@ -87,6 +94,7 @@ protected AvailabilitySetImpl wrapModel(AvailabilitySetInner availabilitySetInne return new AvailabilitySetImpl(availabilitySetInner.name(), availabilitySetInner, this.innerCollection, - this.resourceManager); + this.resourceManager, + this.myManager); } } 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 e1be7d2aaa3a..c5dc573fbd91 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 @@ -98,7 +98,8 @@ public AvailabilitySets availabilitySets() { if (availabilitySets == null) { availabilitySets = new AvailabilitySetsImpl( super.innerManagementClient.availabilitySets(), - this.resourceManager()); + this.resourceManager(), + this); } return availabilitySets; } 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 98f0cd2e0b5e..9606c80ab396 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 @@ -68,14 +68,17 @@ * The implementation for {@link VirtualMachine} and its create and update interfaces. */ class VirtualMachineImpl - extends GroupableResourceImpl + extends GroupableResourceImpl< + VirtualMachine, + VirtualMachineInner, + VirtualMachineImpl, + ComputeManager> implements VirtualMachine, VirtualMachine.Definitions, VirtualMachine.Update { // Clients private final VirtualMachinesInner client; - private final ComputeManager computeManager; private final StorageManager storageManager; private final NetworkManager networkManager; // the name of the virtual machine @@ -122,9 +125,8 @@ class VirtualMachineImpl final ResourceManager resourceManager, final StorageManager storageManager, final NetworkManager networkManager) { - super(name, innerModel, resourceManager); + super(name, innerModel, resourceManager, computeManager); this.client = client; - this.computeManager = computeManager; this.storageManager = storageManager; this.networkManager = networkManager; this.vmName = name; @@ -618,7 +620,7 @@ public VirtualMachineImpl withNewAvailabilitySet(AvailabilitySet.DefinitionCreat @Override public VirtualMachineImpl withNewAvailabilitySet(String name) { - return withNewAvailabilitySet(this.computeManager.availabilitySets().define(name) + return withNewAvailabilitySet(super.myManager.availabilitySets().define(name) .withRegion(region()) .withExistingGroup(this.resourceGroupName()) ); 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 c0c45b72eb00..916f4e075336 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 @@ -37,9 +37,13 @@ * The implementation for {@link VirtualMachines}. */ class VirtualMachinesImpl - extends GroupableResourcesImpl + extends GroupableResourcesImpl< + VirtualMachine, + VirtualMachineImpl, + VirtualMachineInner, + VirtualMachinesInner, + ComputeManager> implements VirtualMachines { - private final ComputeManager computeManager; private final StorageManager storageManager; private final NetworkManager networkManager; private final VirtualMachineSizesImpl vmSizes; @@ -50,8 +54,7 @@ class VirtualMachinesImpl ResourceManager resourceManager, StorageManager storageManager, NetworkManager networkManager) { - super(resourceManager, client); - this.computeManager = computeManager; + super(resourceManager, client, computeManager); this.storageManager = storageManager; this.networkManager = networkManager; this.vmSizes = new VirtualMachineSizesImpl(virtualMachineSizesClient); @@ -155,7 +158,7 @@ protected VirtualMachineImpl wrapModel(String name) { return new VirtualMachineImpl(name, inner, this.innerCollection, - this.computeManager, + super.myManager, this.resourceManager, this.storageManager, this.networkManager); @@ -166,7 +169,7 @@ protected VirtualMachineImpl wrapModel(VirtualMachineInner virtualMachineInner) return new VirtualMachineImpl(virtualMachineInner.name(), virtualMachineInner, this.innerCollection, - this.computeManager, + super.myManager, this.resourceManager, this.storageManager, this.networkManager); diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java index 45c33c89d612..faa38daceac7 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java @@ -28,21 +28,26 @@ * Implementation for {@link Network} and its create and update interfaces. */ class NetworkImpl - extends GroupableResourceImpl + extends GroupableResourceImpl< + Network, + VirtualNetworkInner, + NetworkImpl, + NetworkManager> implements Network, Network.Definition, Network.Update { - private final VirtualNetworksInner client; + private final VirtualNetworksInner innerCollection; private TreeMap subnets; NetworkImpl(String name, - VirtualNetworkInner innerModel, - final VirtualNetworksInner client, - final ResourceManager resourceManager) { - super(name, innerModel, resourceManager); - this.client = client; + final VirtualNetworkInner innerModel, + final VirtualNetworksInner innerCollection, + final ResourceManager resourceManager, + final NetworkManager networkManager) { + super(name, innerModel, resourceManager, networkManager); + this.innerCollection = innerCollection; initializeSubnetsFromInner(); } @@ -59,7 +64,7 @@ private void initializeSubnetsFromInner() { @Override public NetworkImpl refresh() throws Exception { ServiceResponse response = - this.client.get(this.resourceGroupName(), this.name()); + this.innerCollection.get(this.resourceGroupName(), this.name()); this.setInner(response.getBody()); initializeSubnetsFromInner(); return this; @@ -169,7 +174,7 @@ protected void createResource() throws Exception { } ServiceResponse response = - this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner()); + this.innerCollection.createOrUpdate(this.resourceGroupName(), this.name(), this.inner()); this.setInner(response.getBody()); initializeSubnetsFromInner(); } @@ -188,7 +193,7 @@ protected ServiceCall createResourceAsync(final ServiceCallback callback) } } - return this.client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner(), + return this.innerCollection.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner(), Utils.fromVoidCallback(this, new ServiceCallback() { @Override public void failure(Throwable t) { diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java index f2f8e0f7fc84..c2edf41f3d60 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java @@ -37,14 +37,17 @@ * Implementation for {@link NetworkInterface} and its create and update interfaces. */ class NetworkInterfaceImpl - extends GroupableResourceImpl + extends GroupableResourceImpl< + NetworkInterface, + NetworkInterfaceInner, + NetworkInterfaceImpl, + NetworkManager> implements NetworkInterface, NetworkInterface.Definitions, NetworkInterface.Update { // Clients private final NetworkInterfacesInner client; - private final NetworkManager networkManager; // the name of the network interface private final String nicName; // used to generate unique name for any dependency resources @@ -67,9 +70,8 @@ class NetworkInterfaceImpl final NetworkInterfacesInner client, final NetworkManager networkManager, final ResourceManager resourceManager) { - super(name, innerModel, resourceManager); + super(name, innerModel, resourceManager, networkManager); this.client = client; - this.networkManager = networkManager; this.nicName = name; this.namer = new ResourceNamer(this.nicName); initializeNicIpConfigurations(); @@ -326,7 +328,7 @@ public String networkSecurityGroupId() { public NetworkSecurityGroup networkSecurityGroup() throws CloudException, IOException { if (this.networkSecurityGroup == null && this.networkSecurityGroupId() != null) { String id = this.networkSecurityGroupId(); - this.networkSecurityGroup = this.networkManager + this.networkSecurityGroup = super.myManager .networkSecurityGroups() .getByGroup(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)); @@ -427,7 +429,7 @@ private void initializeNicIpConfigurations() { NicIpConfigurationImpl nicIpConfiguration = new NicIpConfigurationImpl(ipConfig.name(), ipConfig, this, - this.networkManager, + super.myManager, false); this.nicIpConfigurations.add(nicIpConfiguration); } @@ -443,7 +445,7 @@ private NicIpConfigurationImpl prepareNewNicIpConfiguration(String name) { NicIpConfigurationImpl nicIpConfiguration = NicIpConfigurationImpl.prepareNicIpConfiguration( name, this, - this.networkManager + super.myManager ); this.nicIpConfigurations.add(nicIpConfiguration); return nicIpConfiguration; 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 1e8ac8fad748..a64920969a57 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 @@ -19,17 +19,19 @@ * Implementation for {@link NetworkInterfaces}. */ class NetworkInterfacesImpl - extends GroupableResourcesImpl + extends GroupableResourcesImpl< + NetworkInterface, + NetworkInterfaceImpl, + NetworkInterfaceInner, + NetworkInterfacesInner, + NetworkManager> implements NetworkInterfaces { - private final NetworkManager networkManager; - NetworkInterfacesImpl( final NetworkInterfacesInner client, - final NetworkManager networkManager, - final ResourceManager resourceManager) { - super(resourceManager, client); - this.networkManager = networkManager; + final ResourceManager resourceManager, + final NetworkManager networkManager) { + super(resourceManager, client, networkManager); } @Override @@ -70,7 +72,7 @@ protected NetworkInterfaceImpl wrapModel(String name) { return new NetworkInterfaceImpl(name, inner, this.innerCollection, - this.networkManager, + super.myManager, this.resourceManager); } @@ -79,7 +81,7 @@ protected NetworkInterfaceImpl wrapModel(NetworkInterfaceInner inner) { return new NetworkInterfaceImpl(inner.name(), inner, this.innerCollection, - this.networkManager, + super.myManager, 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 8507d4b36ffa..ff31b60907b7 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 @@ -102,7 +102,8 @@ public Networks networks() { if (this.networks == null) { this.networks = new NetworksImpl( super.innerManagementClient, - super.resourceManager()); + super.resourceManager(), + this); } return this.networks; } @@ -114,7 +115,8 @@ public NetworkSecurityGroups networkSecurityGroups() { if (this.networkSecurityGroups == null) { this.networkSecurityGroups = new NetworkSecurityGroupsImpl( super.innerManagementClient.networkSecurityGroups(), - super.resourceManager()); + super.resourceManager(), + this); } return this.networkSecurityGroups; } @@ -126,7 +128,8 @@ public PublicIpAddresses publicIpAddresses() { if (this.publicIpAddresses == null) { this.publicIpAddresses = new PublicIpAddressesImpl( super.innerManagementClient.publicIPAddresses(), - super.resourceManager()); + super.resourceManager(), + this); } return this.publicIpAddresses; } @@ -138,9 +141,8 @@ public NetworkInterfaces networkInterfaces() { if (networkInterfaces == null) { this.networkInterfaces = new NetworkInterfacesImpl( super.innerManagementClient.networkInterfaces(), - this, - super.resourceManager() - ); + super.resourceManager(), + this); } return this.networkInterfaces; } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupImpl.java index a665fc8612c5..6539122c5d74 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkSecurityGroupImpl.java @@ -26,22 +26,28 @@ * Implementation for {@link NetworkSecurityGroup} and its create and update interfaces. */ class NetworkSecurityGroupImpl - extends GroupableResourceImpl + extends GroupableResourceImpl< + NetworkSecurityGroup, + NetworkSecurityGroupInner, + NetworkSecurityGroupImpl, + NetworkManager> implements NetworkSecurityGroup, NetworkSecurityGroup.Definition, NetworkSecurityGroup.Update { - private final NetworkSecurityGroupsInner client; + private final NetworkSecurityGroupsInner innerCollection; private List rules; private List defaultRules; - NetworkSecurityGroupImpl(String name, - NetworkSecurityGroupInner innerModel, - final NetworkSecurityGroupsInner client, - final ResourceManager resourceManager) { - super(name, innerModel, resourceManager); - this.client = client; + NetworkSecurityGroupImpl( + final String name, + final NetworkSecurityGroupInner innerModel, + final NetworkSecurityGroupsInner innerCollection, + final ResourceManager resourceManager, + final NetworkManager networkManager) { + super(name, innerModel, resourceManager, networkManager); + this.innerCollection = innerCollection; initializeRulesFromInner(); } @@ -84,7 +90,7 @@ public NetworkSecurityRuleImpl defineRule(String name) { @Override public NetworkSecurityGroupImpl refresh() throws Exception { ServiceResponse response = - this.client.get(this.resourceGroupName(), this.name()); + this.innerCollection.get(this.resourceGroupName(), this.name()); this.setInner(response.getBody()); initializeRulesFromInner(); return this; @@ -103,14 +109,14 @@ public ServiceCall applyAsync(ServiceCallback callback) { @Override protected void createResource() throws Exception { ServiceResponse response = - this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner()); + this.innerCollection.createOrUpdate(this.resourceGroupName(), this.name(), this.inner()); this.setInner(response.getBody()); initializeRulesFromInner(); } @Override protected ServiceCall createResourceAsync(final ServiceCallback callback) { - return this.client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner(), + return this.innerCollection.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner(), Utils.fromVoidCallback(this, new ServiceCallback() { @Override public void failure(Throwable t) { 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 bc25f2027766..9241bcfe132a 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 @@ -23,11 +23,19 @@ * Implementation for {@link NetworkSecurityGroups}. */ class NetworkSecurityGroupsImpl - extends GroupableResourcesImpl + extends GroupableResourcesImpl< + NetworkSecurityGroup, + NetworkSecurityGroupImpl, + NetworkSecurityGroupInner, + NetworkSecurityGroupsInner, + NetworkManager> implements NetworkSecurityGroups { - NetworkSecurityGroupsImpl(final NetworkSecurityGroupsInner client, final ResourceManager resourceManager) { - super(resourceManager, client); + NetworkSecurityGroupsImpl( + final NetworkSecurityGroupsInner innerCollection, + final ResourceManager resourceManager, + final NetworkManager networkManager) { + super(resourceManager, innerCollection, networkManager); } @Override @@ -75,11 +83,21 @@ protected NetworkSecurityGroupImpl wrapModel(String name) { inner.withDefaultSecurityRules(new ArrayList()); } - return new NetworkSecurityGroupImpl(name, inner, this.innerCollection, this.resourceManager); + return new NetworkSecurityGroupImpl( + name, + inner, + this.innerCollection, + this.resourceManager, + super.myManager); } @Override protected NetworkSecurityGroupImpl wrapModel(NetworkSecurityGroupInner inner) { - return new NetworkSecurityGroupImpl(inner.name(), inner, this.innerCollection, this.resourceManager); + return new NetworkSecurityGroupImpl( + inner.name(), + inner, + this.innerCollection, + this.resourceManager, + this.myManager); } } 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 32f4da5e86a3..87454e573450 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 @@ -11,6 +11,7 @@ import com.microsoft.azure.management.network.Networks; import com.microsoft.azure.management.network.implementation.api.AddressSpace; import com.microsoft.azure.management.network.implementation.api.DhcpOptions; +import com.microsoft.azure.management.network.implementation.api.NetworkManagementClientImpl; import com.microsoft.azure.management.network.implementation.api.SubnetInner; import com.microsoft.azure.management.network.implementation.api.VirtualNetworkInner; import com.microsoft.azure.management.network.implementation.api.VirtualNetworksInner; @@ -25,11 +26,19 @@ * Implementation for {@link Networks}. */ class NetworksImpl - extends GroupableResourcesImpl + extends GroupableResourcesImpl< + Network, + NetworkImpl, + VirtualNetworkInner, + VirtualNetworksInner, + NetworkManager> implements Networks { - NetworksImpl(final VirtualNetworksInner client, final ResourceManager resourceManager) { - super(resourceManager, client); + NetworksImpl( + final NetworkManagementClientImpl networkClient, + final ResourceManager resourceManager, + final NetworkManager networkManager) { + super(resourceManager, networkClient.virtualNetworks(), networkManager); } @Override @@ -95,11 +104,21 @@ protected NetworkImpl wrapModel(String name) { dhcp.withDnsServers(new ArrayList()); } - return new NetworkImpl(name, inner, this.innerCollection, this.resourceManager); + return new NetworkImpl( + name, + inner, + this.innerCollection, + this.resourceManager, + super.myManager); } @Override protected NetworkImpl wrapModel(VirtualNetworkInner inner) { - return new NetworkImpl(inner.name(), inner, this.innerCollection, this.resourceManager); + return new NetworkImpl( + inner.name(), + inner, + this.innerCollection, + this.resourceManager, + this.myManager); } } 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 c7216f46364c..4f51fb94ea88 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 @@ -21,7 +21,11 @@ * Implementation for {@link PublicIpAddress} and its create and update interfaces. */ class PublicIpAddressImpl - extends GroupableResourceImpl + extends GroupableResourceImpl< + PublicIpAddress, + PublicIPAddressInner, + PublicIpAddressImpl, + NetworkManager> implements PublicIpAddress, PublicIpAddress.Definitions, @@ -32,8 +36,9 @@ class PublicIpAddressImpl PublicIpAddressImpl(String name, PublicIPAddressInner innerModel, final PublicIPAddressesInner client, - final ResourceManager resourceManager) { - super(name, innerModel, resourceManager); + final ResourceManager resourceManager, + final NetworkManager networkManager) { + super(name, innerModel, resourceManager, networkManager); this.client = client; } 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 622098a750cb..e4f9a5b43c0d 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 @@ -22,11 +22,19 @@ * Implementation for {@link PublicIpAddresses}. */ class PublicIpAddressesImpl - extends GroupableResourcesImpl + extends GroupableResourcesImpl< + PublicIpAddress, + PublicIpAddressImpl, + PublicIPAddressInner, + PublicIPAddressesInner, + NetworkManager> implements PublicIpAddresses { - PublicIpAddressesImpl(final PublicIPAddressesInner client, final ResourceManager resourceManager) { - super(resourceManager, client); + PublicIpAddressesImpl( + final PublicIPAddressesInner client, + final ResourceManager resourceManager, + final NetworkManager networkManager) { + super(resourceManager, client, networkManager); } @Override @@ -69,11 +77,21 @@ protected PublicIpAddressImpl wrapModel(String name) { inner.withDnsSettings(new PublicIPAddressDnsSettings()); } - return new PublicIpAddressImpl(name, inner, this.innerCollection, this.resourceManager); + return new PublicIpAddressImpl( + name, + inner, + this.innerCollection, + this.resourceManager, + this.myManager); } @Override protected PublicIpAddressImpl wrapModel(PublicIPAddressInner inner) { - return new PublicIpAddressImpl(inner.id(), inner, this.innerCollection, this.resourceManager); + return new PublicIpAddressImpl( + inner.id(), + inner, + this.innerCollection, + this.resourceManager, + this.myManager); } } 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 index 2a66f977d067..ef3bbc6e0d07 100644 --- 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 @@ -22,12 +22,14 @@ * @param the individual resource implementation * @param the wrapper inner type * @param the inner type of the collection object + * @param the manager type for this resource provider type */ public abstract class GroupableResourcesImpl< T extends GroupableResource, ImplT extends T, InnerT extends Resource, - InnerCollectionT> + InnerCollectionT, + ManagerT> extends CreatableWrappersImpl implements SupportsGettingById, @@ -35,12 +37,14 @@ public abstract class GroupableResourcesImpl< protected final ResourceManager resourceManager; protected final InnerCollectionT innerCollection; - + protected final ManagerT myManager; protected GroupableResourcesImpl( ResourceManager resourceManager, - InnerCollectionT innerCollection) { + InnerCollectionT innerCollection, + ManagerT manager) { this.resourceManager = resourceManager; this.innerCollection = innerCollection; + this.myManager = manager; } @Override 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 52a238102de3..1c5377e6e055 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 @@ -23,7 +23,7 @@ protected Manager(RestClient restClient, String subscriptionId, InnerT innerMana this.resourceManager = ResourceManager.authenticate(restClient).withSubscription(subscriptionId); this.innerManagementClient = innerManagementClient; } - + protected ResourceManager resourceManager() { return this.resourceManager; } 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 6b7ad4cb45ba..3bc52b11b0e5 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 @@ -18,23 +18,31 @@ * @param The fluent model type * @param Azure inner resource class type * @param the implementation type of the fluent model type + * @param the service manager type */ public abstract class GroupableResourceImpl< FluentModelT, InnerModelT extends com.microsoft.azure.Resource, - FluentModelImplT extends GroupableResourceImpl> + FluentModelImplT extends GroupableResourceImpl, + ManagerT> extends ResourceImpl implements GroupableResource { - private final ResourceManager resourceManager; + protected final ResourceManager resourceManager; + protected final ManagerT myManager; protected ResourceGroup.DefinitionCreatable newGroup; private String groupName; - protected GroupableResourceImpl(String key, InnerModelT innerObject, ResourceManager resourceManager) { + protected GroupableResourceImpl( + String key, + InnerModelT innerObject, + ResourceManager resourceManager, + ManagerT manager) { super(key, innerObject); this.resourceManager = resourceManager; + this.myManager = manager; } /******************************************* diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java index f1666d49224b..feaa83e3cdce 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java @@ -20,7 +20,11 @@ * The implementation for {@link GenericResource} and its nested interfaces. */ final class GenericResourceImpl - extends GroupableResourceImpl + extends GroupableResourceImpl< + GenericResource, + GenericResourceInner, + GenericResourceImpl, + ResourceManager> implements GenericResource, GenericResource.DefinitionBlank, @@ -44,7 +48,7 @@ final class GenericResourceImpl ResourcesInner client, final ResourceManagementClientImpl serviceClient, final ResourceManager resourceManager) { - super(key, innerModel, resourceManager); + super(key, innerModel, resourceManager, resourceManager); this.client = client; } 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 49c5ad5bf4a1..3e84c39f0373 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 @@ -12,7 +12,6 @@ import com.microsoft.azure.management.resources.ResourceGroup; 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.implementation.api.ResourceGroupsInner; import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; import com.microsoft.azure.management.resources.implementation.api.ResourcesInner; import com.microsoft.azure.management.resources.GenericResource; @@ -26,21 +25,24 @@ * Implementation of the {@link GenericResources}. */ final class GenericResourcesImpl - extends GroupableResourcesImpl + extends GroupableResourcesImpl< + GenericResource, + GenericResourceImpl, + GenericResourceInner, + ResourcesInner, + ResourceManager> implements GenericResources { private final ResourceManagementClientImpl serviceClient; - private final ResourceGroupsInner resourceGroupsInner; GenericResourcesImpl(ResourceManagementClientImpl serviceClient, ResourceManager resourceManager) { - super(resourceManager, serviceClient.resources()); + super(resourceManager, serviceClient.resources(), resourceManager); this.serviceClient = serviceClient; - this.resourceGroupsInner = serviceClient.resourceGroups(); } @Override public PagedList listByGroup(String groupName) throws CloudException, IOException { - return wrapList(resourceGroupsInner.listResources(groupName).getBody()); + return wrapList(this.serviceClient.resourceGroups().listResources(groupName).getBody()); } @Override diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java index 7f7673788ea2..d5fd3510feab 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java @@ -36,7 +36,11 @@ * Implementation for StorageAccount and its parent interfaces. */ class StorageAccountImpl - extends GroupableResourceImpl + extends GroupableResourceImpl< + StorageAccount, + StorageAccountInner, + StorageAccountImpl, + StorageManager> implements StorageAccount, StorageAccount.Definitions, @@ -54,8 +58,9 @@ class StorageAccountImpl StorageAccountImpl(String name, StorageAccountInner innerModel, final StorageAccountsInner client, - final ResourceManager resourceManager) { - super(name, innerModel, resourceManager); + final ResourceManager resourceManager, + final StorageManager storageManager) { + super(name, innerModel, resourceManager, storageManager); this.name = name; this.createParameters = new StorageAccountCreateParametersInner(); this.client = client; 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 31a8e242c5e4..6c007a6e088f 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 @@ -23,11 +23,19 @@ * The implementation of StorageAccounts and its parent interfaces. */ class StorageAccountsImpl - extends GroupableResourcesImpl + extends GroupableResourcesImpl< + StorageAccount, + StorageAccountImpl, + StorageAccountInner, + StorageAccountsInner, + StorageManager> implements StorageAccounts { - StorageAccountsImpl(final StorageAccountsInner client, final ResourceManager resourceManager) { - super(resourceManager, client); + StorageAccountsImpl( + final StorageAccountsInner client, + final ResourceManager resourceManager, + final StorageManager storageManager) { + super(resourceManager, client, storageManager); } @Override @@ -73,7 +81,8 @@ protected StorageAccountImpl wrapModel(String name) { name, new StorageAccountInner(), this.innerCollection, - this.resourceManager); + this.resourceManager, + super.myManager); } @Override @@ -82,6 +91,7 @@ protected StorageAccountImpl wrapModel(StorageAccountInner storageAccountInner) storageAccountInner.name(), storageAccountInner, this.innerCollection, - this.resourceManager); + this.resourceManager, + super.myManager); } } 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 0393815e0b9a..e487003844d0 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 @@ -94,7 +94,8 @@ public StorageAccounts storageAccounts() { if (storageAccounts == null) { storageAccounts = new StorageAccountsImpl( super.innerManagementClient.storageAccounts(), - super.resourceManager()); + super.resourceManager(), + this); } return storageAccounts; } From f069136dfbfe1128775446935e9ac1eb00e16645 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2016 20:27:08 -0700 Subject: [PATCH 16/16] finally, support for Subnet#networkSecurityGroup() --- .../azure/management/network/Subnet.java | 9 ++++++++- .../network/implementation/NetworkImpl.java | 18 ++++++++++++------ .../network/implementation/SubnetImpl.java | 15 +++++++++++++++ .../implementation/ChildResourceImpl.java | 6 ++++-- .../samples/ManageNetworkInterface.java | 2 +- .../java/com/microsoft/azure/TestNetwork.java | 17 ++++++++++++++++- 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnet.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnet.java index dd7a5a5d4f8c..0818b67e1da8 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnet.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Subnet.java @@ -21,7 +21,14 @@ public interface Subnet extends * @return the address space prefix, in CIDR notation, assigned to this subnet */ String addressPrefix(); - //TODO: String networkSecurityGroup(); + + /** + * @return the network security group associated with this subnet + *

+ * Note that this method will result in a call to Azure each time it is invoked. + * @throws Exception if there are problems retrieving the associated network security group + */ + NetworkSecurityGroup networkSecurityGroup() throws Exception; /** * The entirety of a Subnet definition. diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java index faa38daceac7..6c42408cb1cc 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkImpl.java @@ -80,6 +80,18 @@ public ServiceCall applyAsync(ServiceCallback callback) { return createAsync(callback); } + // Helpers + + NetworkImpl withSubnet(SubnetImpl subnet) { + this.inner().subnets().add(subnet.inner()); + this.subnets.put(subnet.name(), subnet); + return this; + } + + NetworkManager myManager() { + return super.myManager; + } + // Setters (fluent) @Override @@ -88,12 +100,6 @@ public NetworkImpl withDnsServer(String ipAddress) { return this; } - NetworkImpl withSubnet(SubnetImpl subnet) { - this.inner().subnets().add(subnet.inner()); - this.subnets.put(subnet.name(), subnet); - return this; - } - @Override public NetworkImpl withSubnet(String name, String cidr) { return this.defineSubnet(name) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java index dbaab0f5d720..eaa940cd10c8 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/SubnetImpl.java @@ -5,8 +5,13 @@ */ package com.microsoft.azure.management.network.implementation; +import java.io.IOException; + +import com.microsoft.azure.CloudException; import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.network.NetworkSecurityGroup; import com.microsoft.azure.management.network.Subnet; +import com.microsoft.azure.management.network.implementation.api.NetworkSecurityGroupInner; import com.microsoft.azure.management.network.implementation.api.SubnetInner; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl; @@ -34,6 +39,16 @@ public String name() { return this.inner().name(); } + @Override + public NetworkSecurityGroup networkSecurityGroup() throws CloudException, IllegalArgumentException, IOException { + NetworkSecurityGroupInner nsgInner = this.inner().networkSecurityGroup(); + if (nsgInner == null) { + return null; + } else { + return this.parent().myManager().networkSecurityGroups().getById(nsgInner.id()); + } + } + // Fluent setters @Override diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ChildResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ChildResourceImpl.java index d7677111b871..2091518558e1 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ChildResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ChildResourceImpl.java @@ -12,7 +12,7 @@ * Child resource abstract implementation. * (Internal use only) * @param Azure inner child class type - * @param Parent implementation + * @param parent implementation */ public abstract class ChildResourceImpl extends IndexableWrapperImpl @@ -20,7 +20,9 @@ public abstract class ChildResourceImpl private final ParentImplT parent; - protected ChildResourceImpl(String name, InnerT innerObject, ParentImplT parent) { + protected ChildResourceImpl(String name, + InnerT innerObject, + ParentImplT parent) { super(name, innerObject); this.parent = parent; } diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkInterface.java b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkInterface.java index bc3aba02edbf..3d7714a8c364 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkInterface.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageNetworkInterface.java @@ -71,7 +71,7 @@ public static void main(String[] args) { // Create a virtual machine with multiple network interfaces // Define a virtual network for the VMs in this availability set - Network.DefinitionCreatable network = azure.networks() + Network.DefinitionStages.WithCreate network = azure.networks() .define(vnetName) .withRegion(Region.US_EAST) .withNewGroup(rgName) diff --git a/azure/src/test/java/com/microsoft/azure/TestNetwork.java b/azure/src/test/java/com/microsoft/azure/TestNetwork.java index 430d613f3ecc..8bb85292940f 100644 --- a/azure/src/test/java/com/microsoft/azure/TestNetwork.java +++ b/azure/src/test/java/com/microsoft/azure/TestNetwork.java @@ -8,6 +8,7 @@ import org.junit.Assert; import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.network.NetworkSecurityGroup; import com.microsoft.azure.management.network.Networks; import com.microsoft.azure.management.network.Subnet; import com.microsoft.azure.management.resources.fluentcore.arm.Region; @@ -59,8 +60,22 @@ public void print(Network resource) { // Output subnets for (Subnet subnet : resource.subnets().values()) { info.append("\n\tSubnet: ").append(subnet.name()) - .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); + .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()) + .append("\n\tAssociated NSG: "); + + NetworkSecurityGroup nsg; + try { + nsg = subnet.networkSecurityGroup(); + } catch (Exception e) { + nsg = null; + } + + if (null == nsg) { + info.append("(None)"); + } else { + info.append(nsg.id()); } + } System.out.println(info.toString()); }