From aaa9e00ddeb6149bb5305dbe2006ce1a246acd00 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Sep 2016 11:03:56 -0700 Subject: [PATCH 01/11] allowing to specify only NAT pools or NAT rule in the define flow, not mixing --- .../management/network/LoadBalancer.java | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancer.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancer.java index 6fd254a211914..fa10dfa88c70a 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancer.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancer.java @@ -81,7 +81,10 @@ interface Definition extends DefinitionStages.WithProbe, DefinitionStages.WithProbeOrLoadBalancingRule, DefinitionStages.WithLoadBalancingRule, - DefinitionStages.WithLoadBalancingRuleOrCreate { + DefinitionStages.WithLoadBalancingRuleOrCreate, + DefinitionStages.WithCreateAndInboundNatPool, + DefinitionStages.WithCreateAndInboundNatRule, + DefinitionStages.WithCreateAndNatChoice { } /** @@ -338,7 +341,7 @@ interface WithLoadBalancingRule { /** * The stage of a load balancer definition allowing to create a load balancing rule or create the load balancer. */ - interface WithLoadBalancingRuleOrCreate extends WithLoadBalancingRule, WithCreate { + interface WithLoadBalancingRuleOrCreate extends WithLoadBalancingRule, WithCreateAndNatChoice { } /** @@ -348,9 +351,32 @@ interface WithLoadBalancingRuleOrCreate extends WithLoadBalancingRule, WithCreat */ interface WithCreate extends Creatable, - Resource.DefinitionWithTags, - DefinitionStages.WithInboundNatRule, - DefinitionStages.WithInboundNatPool { + Resource.DefinitionWithTags { + } + + /** + * The stage of a load balancer definition allowing to create the load balancer or start configuring optional inbound NAT rules or pools. + */ + interface WithCreateAndNatChoice extends + WithCreate, + WithInboundNatRule, + WithInboundNatPool { + } + + /** + * The stage of a load balancer definition allowing to create the load balancer or add an inbound NAT pool. + */ + interface WithCreateAndInboundNatPool extends + WithCreate, + WithInboundNatPool { + } + + /** + * The stage of a load balancer definition allowing to create the load balancer or add an inbound NAT rule. + */ + interface WithCreateAndInboundNatRule extends + WithCreate, + WithInboundNatRule { } /** @@ -364,7 +390,7 @@ interface WithInboundNatRule { * @param name the name of the inbound NAT rule * @return the first stage of the new inbound NAT rule definition */ - InboundNatRule.DefinitionStages.Blank defineInboundNatRule(String name); + InboundNatRule.DefinitionStages.Blank defineInboundNatRule(String name); } /** @@ -378,7 +404,7 @@ interface WithInboundNatPool { * @param name the name of the inbound NAT pool * @return the first stage of the new inbound NAT pool definition */ - InboundNatPool.DefinitionStages.Blank defineInboundNatPool(String name); + InboundNatPool.DefinitionStages.Blank defineInboundNatPool(String name); } } From 54f9a24f076b5b831ca721d9901657a9bc461fc6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Sep 2016 11:09:25 -0700 Subject: [PATCH 02/11] impl correction --- .../management/network/implementation/InboundNatPoolImpl.java | 2 +- .../management/network/implementation/InboundNatRuleImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/InboundNatPoolImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/InboundNatPoolImpl.java index 585e0b03ceb3b..7a4a66dca6c7d 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/InboundNatPoolImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/InboundNatPoolImpl.java @@ -20,7 +20,7 @@ class InboundNatPoolImpl extends ChildResourceImpl implements InboundNatPool, - InboundNatPool.Definition, + InboundNatPool.Definition, InboundNatPool.UpdateDefinition, InboundNatPool.Update { diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/InboundNatRuleImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/InboundNatRuleImpl.java index 6050bc9f1138f..862d3915e4d2e 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/InboundNatRuleImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/InboundNatRuleImpl.java @@ -20,7 +20,7 @@ class InboundNatRuleImpl extends ChildResourceImpl implements InboundNatRule, - InboundNatRule.Definition, + InboundNatRule.Definition, InboundNatRule.UpdateDefinition, InboundNatRule.Update { From 053b4e8f9a87a86fb2631beb3062ce8110263153 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Sep 2016 11:50:43 -0700 Subject: [PATCH 03/11] adding .virtualMachineId() to NIC --- .../azure/management/network/NetworkInterface.java | 5 +++++ .../network/implementation/NetworkInterfaceImpl.java | 9 +++++++++ .../java/com/microsoft/azure/TestNetworkInterface.java | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) 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 88f30cfec376c..d046ed18b41eb 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 @@ -138,6 +138,11 @@ public interface NetworkInterface extends */ NetworkSecurityGroup networkSecurityGroup() throws CloudException, IOException; + /** + * @return the resource ID of the associated virtual machine, or null if none. + */ + String virtualMachineId(); + // Setters (fluent) /** 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 fe4cdb84f90f2..899421bd322f0 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 @@ -240,6 +240,15 @@ public NetworkInterfaceImpl withInternalDnsNameLabel(String dnsNameLabel) { // Getters + @Override + public String virtualMachineId() { + if(this.inner().virtualMachine() != null) { + return this.inner().virtualMachine().id(); + } else { + return null; + } + } + @Override public boolean isIpForwardingEnabled() { return Utils.toPrimitiveBoolean(this.inner().enableIPForwarding()); diff --git a/azure/src/test/java/com/microsoft/azure/TestNetworkInterface.java b/azure/src/test/java/com/microsoft/azure/TestNetworkInterface.java index a5e022f643246..f289d149cb716 100644 --- a/azure/src/test/java/com/microsoft/azure/TestNetworkInterface.java +++ b/azure/src/test/java/com/microsoft/azure/TestNetworkInterface.java @@ -53,6 +53,7 @@ public void print(NetworkInterface resource) { .append("\n\tInternal DNS name label: ").append(resource.internalDnsNameLabel()) .append("\n\tInternal FQDN: ").append(resource.internalFqdn()) .append("\n\tInternal domain name suffix: ").append(resource.internalDomainNameSuffix()) + .append("\n\tVirtual machine ID: ").append(resource.virtualMachineId()) .append("\n\tApplied DNS servers: ").append(resource.appliedDnsServers().toString()) .append("\n\tDNS server IPs: "); @@ -61,7 +62,7 @@ public void print(NetworkInterface resource) { info.append("\n\t\t").append(dnsServerIp); } - info.append("\n\t IP forwarding enabled: ").append(resource.isIpForwardingEnabled()) + info.append("\n\tIP forwarding enabled: ").append(resource.isIpForwardingEnabled()) .append("\n\tMAC Address:").append(resource.macAddress()) .append("\n\tPrivate IP:").append(resource.primaryPrivateIp()) .append("\n\tPrivate allocation method:").append(resource.primaryPrivateIpAllocationMethod()) From 737f14a7e62dd26a202dd3985d9f75a1edd0179f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Sep 2016 11:54:47 -0700 Subject: [PATCH 04/11] renaming NIC#networkSecurityGroup() to getNetworkSecurityGroup() because it is a call to Azure, not a direct property of the NIC --- .../microsoft/azure/management/network/NetworkInterface.java | 2 +- .../management/network/implementation/NetworkInterfaceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 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 d046ed18b41eb..a5a50497e8d1c 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 @@ -136,7 +136,7 @@ public interface NetworkInterface extends * @throws CloudException exceptions thrown from the cloud. * @throws IOException exceptions thrown from serialization/deserialization. */ - NetworkSecurityGroup networkSecurityGroup() throws CloudException, IOException; + NetworkSecurityGroup getNetworkSecurityGroup() throws CloudException, IOException; /** * @return the resource ID of the associated virtual machine, or null if none. 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 899421bd322f0..3b99552963f2b 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 @@ -329,7 +329,7 @@ public String networkSecurityGroupId() { } @Override - public NetworkSecurityGroup networkSecurityGroup() throws CloudException, IOException { + public NetworkSecurityGroup getNetworkSecurityGroup() throws CloudException, IOException { if (this.networkSecurityGroup == null && this.networkSecurityGroupId() != null) { String id = this.networkSecurityGroupId(); this.networkSecurityGroup = super.myManager From dd62054e48d6d1ecd456d035a7388905b31be2e4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Sep 2016 13:08:19 -0700 Subject: [PATCH 05/11] exposing ability to list associated VM IDs from an LB backend --- .../azure/management/network/Backend.java | 6 ++++ .../network/implementation/BackendImpl.java | 29 +++++++++++++++++++ .../com/microsoft/azure/TestLoadBalancer.java | 13 +++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Backend.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Backend.java index e78c82fb2c74a..f97d203631fc6 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Backend.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Backend.java @@ -6,6 +6,7 @@ package com.microsoft.azure.management.network; import java.util.Map; +import java.util.Set; import com.microsoft.azure.management.network.implementation.BackendAddressPoolInner; import com.microsoft.azure.management.network.model.HasLoadBalancingRules; @@ -28,6 +29,11 @@ public interface Backend extends */ Map backendNicIpConfigurationNames(); + /** + * @return a list of the resource IDs of the virtual machines associated with this backend + */ + Set getVirtualMachineIds(); + /** * Grouping of backend definition stages. */ diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/BackendImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/BackendImpl.java index bc4c5148e763f..701c781d0ddbe 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/BackendImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/BackendImpl.java @@ -5,14 +5,19 @@ */ package com.microsoft.azure.management.network.implementation; +import java.io.IOException; import java.util.Collections; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.TreeMap; +import com.microsoft.azure.CloudException; import com.microsoft.azure.SubResource; import com.microsoft.azure.management.network.Backend; import com.microsoft.azure.management.network.LoadBalancer; import com.microsoft.azure.management.network.LoadBalancingRule; +import com.microsoft.azure.management.network.NetworkInterface; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl; @@ -70,6 +75,30 @@ public String name() { return this.inner().name(); } + @Override + public Set getVirtualMachineIds() { + Set vmIds = new HashSet<>(); + Map nicConfigs = this.backendNicIpConfigurationNames(); + if (nicConfigs != null) { + for (String nicId : nicConfigs.keySet()) { + try { + NetworkInterface nic = this.parent().manager().networkInterfaces().getById(nicId); + if (nic == null || nic.virtualMachineId() == null) { + continue; + } else { + vmIds.add(nic.virtualMachineId()); + } + } catch (CloudException | IllegalArgumentException | IOException e) { + continue; + } + } + } + + return vmIds; + } + + // Verbs + @Override public LoadBalancerImpl attach() { this.parent().withBackend(this); diff --git a/azure/src/test/java/com/microsoft/azure/TestLoadBalancer.java b/azure/src/test/java/com/microsoft/azure/TestLoadBalancer.java index 6c8f9c9c1aec6..f0b001105bd56 100644 --- a/azure/src/test/java/com/microsoft/azure/TestLoadBalancer.java +++ b/azure/src/test/java/com/microsoft/azure/TestLoadBalancer.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; +import java.util.Set; import org.junit.Assert; @@ -48,7 +49,7 @@ public class TestLoadBalancer { static final String[] PIP_NAMES = {"pipa" + TEST_ID, "pipb" + TEST_ID}; static final String[] VM_IDS = { "/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/marcinslbtest/providers/Microsoft.Compute/virtualMachines/marcinslbtest1", - "/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/marcinslbtest/providers/Microsoft.Compute/virtualMachines/marcinslbtest2" + "/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/marcinslbtest/providers/Microsoft.Compute/virtualMachines/marcinslbtest3" }; /** @@ -460,7 +461,7 @@ public LoadBalancer createResource(LoadBalancers resources) throws Exception { // Frontend (default) .withExistingSubnet(network, "subnet1") // Backend (default) - //TODO .withExistingVirtualMachines(existingVMs) + .withExistingVirtualMachines(existingVMs) .defineBackend("foo") .attach() // Probe (default) @@ -780,6 +781,14 @@ static void printLB(LoadBalancer resource) { .append(" - IP Config: ").append(entry.getValue()); } + // Show assigned virtual machines + Set vmIds = backend.getVirtualMachineIds(); + info.append("\n\t\t\tReferenced virtual machine ids: ") + .append(vmIds.size()); + for (String vmId : vmIds) { + info.append("\n\t\t\t\tVM ID: ").append(vmId); + } + // Show assigned load balancing rules info.append("\n\t\t\tReferenced load balancing rules: ") .append(backend.loadBalancingRules().keySet().toArray(new String[0])); From d5525c549bd90721099c1179653ea1e8a275b1d2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Sep 2016 13:36:02 -0700 Subject: [PATCH 06/11] checkstyle... --- .../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 3b99552963f2b..30024fcbcc6ef 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 @@ -242,7 +242,7 @@ public NetworkInterfaceImpl withInternalDnsNameLabel(String dnsNameLabel) { @Override public String virtualMachineId() { - if(this.inner().virtualMachine() != null) { + if (this.inner().virtualMachine() != null) { return this.inner().virtualMachine().id(); } else { return null; From 4f7829ce34b3cb2701bc4ceb132c7229d69ea12a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Sep 2016 15:23:41 -0700 Subject: [PATCH 07/11] enabling public IPs to be updated during LB update --- .../management/network/LoadBalancer.java | 45 +++++++++++++++++-- .../com/microsoft/azure/TestLoadBalancer.java | 22 ++++----- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancer.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancer.java index fa10dfa88c70a..248b4a05e0ec7 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancer.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancer.java @@ -239,8 +239,7 @@ interface WithVirtualMachine { } /** - * The stage of a load balancer definition allowing to add a public ip address as one of the load - * balancer's public frontends. + * The stage of a load balancer definition allowing to add a public IP address as the default public frontend. * @param the next stage of the definition */ interface WithPublicIpAddress { @@ -552,7 +551,7 @@ interface WithLoadBalancingRule { /** * The stage of a load balancer update allowing to define, remove or edit Internet-facing frontends. */ - interface WithInternetFrontend { + interface WithInternetFrontend extends WithPublicIpAddress { /** * Begins the update of a load balancer frontend. *

@@ -577,6 +576,46 @@ interface WithInternetFrontend { PublicFrontend.Update updateInternetFrontend(String name); } + /** + * The stage of a load balancer update allowing to add a public IP address as the default public frontend. + */ + interface WithPublicIpAddress { + /** + * Assigns the provided public IP address to the default public frontend to the load balancer. + *

+ * This will create a new default frontend for the load balancer under the name "default", if one does not already exist. + * @param publicIpAddress an existing public IP address + * @return the next stage of the update + */ + Update withExistingPublicIpAddress(PublicIpAddress publicIpAddress); + + /** + * Creates a new public IP address as the default public frontend of the load balancer, + * using an automatically generated name and leaf DNS label + * derived from the load balancer's name, in the same resource group and region. + *

+ * This will create a new default frontend for the load balancer under the name "default", if one does not already exist. + * @return the next stage of the update + */ + Update withNewPublicIpAddress(); + + /** + * Adds a new public IP address as the default public frontend of the load balancer, + * using the specified DNS leaf label, an automatically generated frontend name derived from the DNS label, + * in the same resource group and region as the load balancer. + * @param dnsLeafLabel a DNS leaf label + * @return the next stage of the update + */ + Update withNewPublicIpAddress(String dnsLeafLabel); + + /** + * Adds a new public IP address to the default front end of the load balancer. + * @param creatablePublicIpAddress the creatable stage of a public IP address definition + * @return the next stage of the update + */ + Update withNewPublicIpAddress(Creatable creatablePublicIpAddress); + } + /** * The stage of a load balancer update allowing to define one or more private frontends. */ diff --git a/azure/src/test/java/com/microsoft/azure/TestLoadBalancer.java b/azure/src/test/java/com/microsoft/azure/TestLoadBalancer.java index f0b001105bd56..0ebb8e1cc75e3 100644 --- a/azure/src/test/java/com/microsoft/azure/TestLoadBalancer.java +++ b/azure/src/test/java/com/microsoft/azure/TestLoadBalancer.java @@ -169,7 +169,6 @@ public LoadBalancer createResource(LoadBalancers resources) throws Exception { @Override public LoadBalancer updateResource(LoadBalancer resource) throws Exception { resource = resource.update() - //TODO .withExistingPublicIpAddress(pip) .withoutFrontend("default") .withoutBackend("default") .withoutLoadBalancingRule("rule1") @@ -216,13 +215,11 @@ public LoadBalancer createResource(LoadBalancers resources) throws Exception { .withExistingResourceGroup(TestLoadBalancer.GROUP_NAME) // Frontends - .withExistingPublicIpAddress(existingPips.get(0)) .definePublicFrontend("frontend1") - .withExistingPublicIpAddress(existingPips.get(1)) + .withExistingPublicIpAddress(existingPips.get(0)) .attach() // Backends - .withExistingVirtualMachines(existingVMs) .defineBackend("backend1") .attach() @@ -260,13 +257,11 @@ public LoadBalancer createResource(LoadBalancers resources) throws Exception { // Verify frontends Assert.assertTrue(lb.frontends().containsKey("frontend1")); - Assert.assertTrue(lb.frontends().containsKey("default")); - Assert.assertTrue(lb.frontends().size() == 2); + Assert.assertTrue(lb.frontends().size() == 1); // Verify backends - Assert.assertTrue(lb.backends().containsKey("default")); Assert.assertTrue(lb.backends().containsKey("backend1")); - Assert.assertTrue(lb.backends().size() == 2); + Assert.assertTrue(lb.backends().size() == 1); // Verify probes Assert.assertTrue(lb.httpProbes().containsKey("httpProbe1")); @@ -296,8 +291,11 @@ public LoadBalancer createResource(LoadBalancers resources) throws Exception { @Override public LoadBalancer updateResource(LoadBalancer resource) throws Exception { + List existingPips = ensurePIPs(pips); resource = resource.update() - //TODO .withExistingPublicIpAddress(pip) + .updateInternetFrontend("frontend1") + .withExistingPublicIpAddress(existingPips.get(1)) + .parent() .withoutFrontend("default") .withoutBackend("default") .withoutLoadBalancingRule("rule1") @@ -370,9 +368,7 @@ public LoadBalancer updateResource(LoadBalancer resource) throws Exception { List existingPips = ensurePIPs(pips); PublicIpAddress pip = existingPips.get(1); resource = resource.update() - .updateInternetFrontend("default") - .withExistingPublicIpAddress(pip) - .parent() + .withExistingPublicIpAddress(pip) .updateTcpProbe("default") .withPort(22) .parent() @@ -791,7 +787,7 @@ static void printLB(LoadBalancer resource) { // Show assigned load balancing rules info.append("\n\t\t\tReferenced load balancing rules: ") - .append(backend.loadBalancingRules().keySet().toArray(new String[0])); + .append(new ArrayList(backend.loadBalancingRules().keySet())); } System.out.println(info.toString()); From 9b801ef6bc585c252ed5072f00f17911b9a6b6e0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Sep 2016 15:54:58 -0700 Subject: [PATCH 08/11] support for PublicIpAddress#version() --- .../azure/management/network/PublicIpAddress.java | 9 ++++++--- .../network/implementation/PublicIpAddressImpl.java | 6 ++++++ .../java/com/microsoft/azure/TestPublicIpAddress.java | 1 + 3 files changed, 13 insertions(+), 3 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 cbb5b12a46412..89c11612bd3d4 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,9 +23,12 @@ public interface PublicIpAddress extends Wrapper, Updatable { - /*********************************************************** - * Getters - ***********************************************************/ + // Getters + + /** + * @return the IP version of the public IP address + */ + IPVersion version(); /** * @return the assigned IP address 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 12925b6316636..8e9afd77e6c52 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java @@ -6,6 +6,7 @@ package com.microsoft.azure.management.network.implementation; import com.microsoft.azure.management.network.IPAllocationMethod; +import com.microsoft.azure.management.network.IPVersion; import com.microsoft.azure.management.network.PublicIPAddressDnsSettings; import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; @@ -104,6 +105,11 @@ public IPAllocationMethod ipAllocationMethod() { return this.inner().publicIPAllocationMethod(); } + @Override + public IPVersion version() { + return this.inner().publicIPAddressVersion(); + } + @Override public String fqdn() { return this.inner().dnsSettings().fqdn(); diff --git a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java index d4e3f0818b6f9..d6d454cd763de 100644 --- a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java +++ b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java @@ -59,6 +59,7 @@ public void print(PublicIpAddress resource) { .append("\n\tReverse FQDN: ").append(resource.reverseFqdn()) .append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes()) .append("\n\tIP allocation method: ").append(resource.ipAllocationMethod().toString()) + .append("\n\tIP version: ").append(resource.version().toString()) .toString()); } } From bbe0f0645a4b2b2eddb0a46d892ae292fd65db21 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 14 Sep 2016 09:10:52 -0700 Subject: [PATCH 09/11] PIP test tweak --- .../test/java/com/microsoft/azure/TestPublicIpAddress.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java index d6d454cd763de..cfa7ec675cd05 100644 --- a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java +++ b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java @@ -47,7 +47,11 @@ public PublicIpAddress updateResource(PublicIpAddress resource) throws Exception } @Override - public void print(PublicIpAddress resource) { + public void print(PublicIpAddress pip) { + TestPublicIpAddress.printPIP(pip); + } + + public static void printPIP(PublicIpAddress resource) { System.out.println(new StringBuilder().append("Public IP Address: ").append(resource.id()) .append("Name: ").append(resource.name()) .append("\n\tResource group: ").append(resource.resourceGroupName()) From 8ec142efb3ed2f1a55f73c210bf2bc167ae4e26e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Sep 2016 13:37:28 -0700 Subject: [PATCH 10/11] fix for https://github.com/Azure/azure-sdk-for-java/issues/1079 --- .../network/implementation/PublicIpAddressImpl.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 db0b9ca49916d..ae81be780f711 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 @@ -114,12 +114,20 @@ public IPVersion version() { @Override public String fqdn() { - return this.inner().dnsSettings().fqdn(); + if (this.inner().dnsSettings() != null) { + return this.inner().dnsSettings().fqdn(); + } else { + return null; + } } @Override public String reverseFqdn() { - return this.inner().dnsSettings().reverseFqdn(); + if (this.inner().dnsSettings() != null) { + return this.inner().dnsSettings().reverseFqdn(); + } else { + return null; + } } @Override From 05bedf4c0154ac32e8a101d358c1529ea8f022b5 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Sep 2016 16:45:41 -0700 Subject: [PATCH 11/11] ability to directly get the load balancer frontend associated with a public ip address, if any --- .../management/network/PublicIpAddress.java | 10 +++++++ .../implementation/PublicIpAddressImpl.java | 29 ++++++++++++++++++- .../microsoft/azure/TestPublicIpAddress.java | 17 ++++++++--- 3 files changed, 51 insertions(+), 5 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 c8132dcc157ee..b955f6057996f 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 @@ -62,6 +62,16 @@ public interface PublicIpAddress extends */ int idleTimeoutInMinutes(); + /** + * @return the load balancer frontend that this public IP address is assigned to + */ + Frontend getAssignedLoadBalancerFrontend(); + + /** + * @return true if this public IP address is assigned to a load balancer frontend + */ + boolean hasAssignedLoadBalancerFrontend(); + /************************************************************** * Fluent interfaces for builder pattern **************************************************************/ 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 1cb797ffd96a7..67346a8e21708 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 @@ -8,8 +8,11 @@ import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.network.IPAllocationMethod; import com.microsoft.azure.management.network.IPVersion; +import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.PublicFrontend; import com.microsoft.azure.management.network.PublicIPAddressDnsSettings; import com.microsoft.azure.management.network.PublicIpAddress; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; import rx.Observable; @@ -160,4 +163,28 @@ public Observable createResourceAsync() { return this.client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) .map(innerToFluentMap(this)); } -} \ No newline at end of file + + @Override + public PublicFrontend getAssignedLoadBalancerFrontend() { + if (this.hasAssignedLoadBalancerFrontend()) { + final String refId = this.inner().ipConfiguration().id(); + final String loadBalancerId = ResourceUtils.parentResourcePathFromResourceId(refId); + final LoadBalancer lb = this.myManager.loadBalancers().getById(loadBalancerId); + final String frontendName = ResourceUtils.nameFromResourceId(refId); + return (PublicFrontend) lb.frontends().get(frontendName); + } else { + return null; + } + } + + @Override + public boolean hasAssignedLoadBalancerFrontend() { + if (this.inner().ipConfiguration() == null) { + return false; + } else { + final String refId = this.inner().ipConfiguration().id(); + final String resourceType = ResourceUtils.resourceTypeFromResourceId(refId); + return resourceType.equalsIgnoreCase("frontendIPConfigurations"); + } + } +} diff --git a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java index cfa7ec675cd05..10343ee2c03b9 100644 --- a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java +++ b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java @@ -52,8 +52,8 @@ public void print(PublicIpAddress pip) { } public static void printPIP(PublicIpAddress resource) { - System.out.println(new StringBuilder().append("Public IP Address: ").append(resource.id()) - .append("Name: ").append(resource.name()) + StringBuilder info = new StringBuilder().append("Public IP Address: ").append(resource.id()) + .append("\n\tName: ").append(resource.name()) .append("\n\tResource group: ").append(resource.resourceGroupName()) .append("\n\tRegion: ").append(resource.region()) .append("\n\tTags: ").append(resource.tags()) @@ -63,7 +63,16 @@ public static void printPIP(PublicIpAddress resource) { .append("\n\tReverse FQDN: ").append(resource.reverseFqdn()) .append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes()) .append("\n\tIP allocation method: ").append(resource.ipAllocationMethod().toString()) - .append("\n\tIP version: ").append(resource.version().toString()) - .toString()); + .append("\n\tIP version: ").append(resource.version().toString()); + + // Show the associated load balancer frontend if any + info.append("\n\tAssociated load balancer frontend name: "); + if (resource.hasAssignedLoadBalancerFrontend()) { + info.append(resource.getAssignedLoadBalancerFrontend().name()); + } else { + info.append("(None)"); + } + + System.out.println(info.toString()); } }