From 782d60b352cd6ea1b1bf9c2ec71ab014c6d411fe Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 13:32:46 -0700 Subject: [PATCH 01/11] correcting the naming of Subnet#getNetworkSecurityGroup as proper method --- .../java/com/microsoft/azure/management/network/Subnet.java | 2 +- .../azure/management/network/implementation/SubnetImpl.java | 2 +- .../main/java/com/microsoft/azure/management/samples/Utils.java | 2 +- azure/src/test/java/com/microsoft/azure/TestNetwork.java | 2 +- 4 files changed, 4 insertions(+), 4 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 af5ab4b636230..ae5476e4b2dc1 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 @@ -30,7 +30,7 @@ public interface Subnet extends *

* Note that this method will result in a call to Azure each time it is invoked. */ - NetworkSecurityGroup networkSecurityGroup(); + NetworkSecurityGroup getNetworkSecurityGroup(); /** * Grouping of subnet definition stages. 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 f76ef954fa015..d8fd78346e9c9 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 @@ -40,7 +40,7 @@ public String name() { } @Override - public NetworkSecurityGroup networkSecurityGroup() { + public NetworkSecurityGroup getNetworkSecurityGroup() { SubResource nsgResource = this.inner().networkSecurityGroup(); if (nsgResource == null) { return null; 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 6e299fefc7bef..a64a8355084db 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 @@ -204,7 +204,7 @@ public static void print(Network resource) throws CloudException, IOException { for (Subnet subnet : resource.subnets().values()) { info.append("\n\tSubnet: ").append(subnet.name()) .append("\n\t\tAddress prefix: ").append(subnet.addressPrefix()); - NetworkSecurityGroup subnetNsg = subnet.networkSecurityGroup(); + NetworkSecurityGroup subnetNsg = subnet.getNetworkSecurityGroup(); if (subnetNsg != null) { info.append("\n\t\tNetwork security group: ").append(subnetNsg.id()); } diff --git a/azure/src/test/java/com/microsoft/azure/TestNetwork.java b/azure/src/test/java/com/microsoft/azure/TestNetwork.java index d04cdbc130e10..8925788c75820 100644 --- a/azure/src/test/java/com/microsoft/azure/TestNetwork.java +++ b/azure/src/test/java/com/microsoft/azure/TestNetwork.java @@ -104,7 +104,7 @@ public void print(Network resource) { NetworkSecurityGroup nsg; try { - nsg = subnet.networkSecurityGroup(); + nsg = subnet.getNetworkSecurityGroup(); } catch (Exception e) { nsg = null; } From dc9ccd6838d510bf191d1816dc5995115cca8a7d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 14:08:02 -0700 Subject: [PATCH 02/11] making SubnetImpl constructor internal for consistency with .NET --- .../azure/management/network/implementation/SubnetImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d8fd78346e9c9..f9526818d316b 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 @@ -24,7 +24,7 @@ class SubnetImpl Subnet.UpdateDefinition, Subnet.Update { - protected SubnetImpl(SubnetInner inner, NetworkImpl parent) { + SubnetImpl(SubnetInner inner, NetworkImpl parent) { super(inner, parent); } From 785a1d1045fc7e05ac112b08d0cf541c6e1707ed Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 14:16:48 -0700 Subject: [PATCH 03/11] NPE/initialization bug fix in NetworkImpl#withDnsServer() --- .../management/network/implementation/NetworkImpl.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 c63f38accba9f..ce3a722b4077a 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 @@ -6,11 +6,13 @@ package com.microsoft.azure.management.network.implementation; import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.network.DhcpOptions; import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.network.Subnet; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl; import rx.Observable; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -80,6 +82,14 @@ NetworkManager manager() { @Override public NetworkImpl withDnsServer(String ipAddress) { + if (this.inner().dhcpOptions() == null) { + this.inner().withDhcpOptions(new DhcpOptions()); + } + + if (this.inner().dhcpOptions().dnsServers() == null) { + this.inner().dhcpOptions().withDnsServers(new ArrayList()); + } + this.inner().dhcpOptions().dnsServers().add(ipAddress); return this; } From cc8349bf57f46ae1eef015c4313a584e5a5d8045 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 14:22:56 -0700 Subject: [PATCH 04/11] NPE/initialization bug fix in NetworkImpl#withAddressSpace() --- .../management/network/implementation/NetworkImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 ce3a722b4077a..6ff2f262b323a 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 @@ -6,6 +6,7 @@ package com.microsoft.azure.management.network.implementation; import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.network.AddressSpace; import com.microsoft.azure.management.network.DhcpOptions; import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.network.Subnet; @@ -118,6 +119,14 @@ public NetworkImpl withoutSubnet(String name) { @Override public NetworkImpl withAddressSpace(String cidr) { + if (this.inner().addressSpace() == null) { + this.inner().withAddressSpace(new AddressSpace()); + } + + if (this.inner().addressSpace().addressPrefixes() == null) { + this.inner().addressSpace().withAddressPrefixes(new ArrayList()); + } + this.inner().addressSpace().addressPrefixes().add(cidr); return this; } From 32e9661f7c35504527358f876c6ce59c635589ae Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 14:28:54 -0700 Subject: [PATCH 05/11] fix for potential NPE in NetworkImpl#addressSpaces() --- .../management/network/implementation/NetworkImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 6ff2f262b323a..30183416f87d8 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 @@ -142,7 +142,13 @@ public SubnetImpl defineSubnet(String name) { @Override public List addressSpaces() { - return Collections.unmodifiableList(this.inner().addressSpace().addressPrefixes()); + if (this.inner().addressSpace() == null) { + return null; + } else if(this.inner().addressSpace().addressPrefixes() == null) { + return null; + } else { + return Collections.unmodifiableList(this.inner().addressSpace().addressPrefixes()); + } } @Override From 6a595ff5aea02f667cec92fc9e8442e687bc7367 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 14:33:25 -0700 Subject: [PATCH 06/11] potential NPE bug fix in NetworkImpl#dnsServerIps and rename to follow conventions --- .../java/com/microsoft/azure/management/network/Network.java | 2 +- .../azure/management/network/implementation/NetworkImpl.java | 4 ++-- .../java/com/microsoft/azure/management/samples/Utils.java | 2 +- azure/src/test/java/com/microsoft/azure/TestNetwork.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) 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 a86c50dfa5331..86744bd6b33b7 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 @@ -39,7 +39,7 @@ public interface Network extends /** * @return list of DNS server IP addresses associated with this virtual network */ - List dnsServerIPs(); + List dnsServerIps(); /** * @return subnets of this virtual network as a map indexed by subnet name 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 30183416f87d8..4c6356c07588a 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 @@ -152,8 +152,8 @@ public List addressSpaces() { } @Override - public List dnsServerIPs() { - return Collections.unmodifiableList(this.inner().dhcpOptions().dnsServers()); + public List dnsServerIps() { + return (this.inner().dhcpOptions() != null) ? this.inner().dhcpOptions().dnsServers() : null; } @Override 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 a64a8355084db..224fb3fdcd1d1 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 @@ -198,7 +198,7 @@ public static void print(Network resource) throws CloudException, IOException { .append("\n\tRegion: ").append(resource.region()) .append("\n\tTags: ").append(resource.tags()) .append("\n\tAddress spaces: ").append(resource.addressSpaces()) - .append("\n\tDNS server IPs: ").append(resource.dnsServerIPs()); + .append("\n\tDNS server IPs: ").append(resource.dnsServerIps()); // Output subnets for (Subnet subnet : resource.subnets().values()) { diff --git a/azure/src/test/java/com/microsoft/azure/TestNetwork.java b/azure/src/test/java/com/microsoft/azure/TestNetwork.java index 8925788c75820..dbdad0aca5e41 100644 --- a/azure/src/test/java/com/microsoft/azure/TestNetwork.java +++ b/azure/src/test/java/com/microsoft/azure/TestNetwork.java @@ -94,7 +94,7 @@ public void print(Network resource) { .append("\n\tRegion: ").append(resource.region()) .append("\n\tTags: ").append(resource.tags()) .append("\n\tAddress spaces: ").append(resource.addressSpaces()) - .append("\n\tDNS server IPs: ").append(resource.dnsServerIPs()); + .append("\n\tDNS server IPs: ").append(resource.dnsServerIps()); // Output subnets for (Subnet subnet : resource.subnets().values()) { From 448ff61ee1ff39ba0296b558ab659364ef1bf585 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 14:56:28 -0700 Subject: [PATCH 07/11] NetworkImpl#addressSpaces() and dnsServerIps() should never return null --- .../network/implementation/NetworkImpl.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 4c6356c07588a..639c23e60dd5c 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 @@ -142,10 +142,11 @@ public SubnetImpl defineSubnet(String name) { @Override public List addressSpaces() { + List addressSpaces = new ArrayList(); if (this.inner().addressSpace() == null) { - return null; + return Collections.unmodifiableList(addressSpaces); } else if(this.inner().addressSpace().addressPrefixes() == null) { - return null; + return Collections.unmodifiableList(addressSpaces); } else { return Collections.unmodifiableList(this.inner().addressSpace().addressPrefixes()); } @@ -153,7 +154,14 @@ public List addressSpaces() { @Override public List dnsServerIps() { - return (this.inner().dhcpOptions() != null) ? this.inner().dhcpOptions().dnsServers() : null; + List ips = new ArrayList(); + if (this.inner().dhcpOptions() == null) { + return Collections.unmodifiableList(ips); + } else if (this.inner().dhcpOptions().dnsServers() == null) { + return Collections.unmodifiableList(ips); + } else { + return this.inner().dhcpOptions().dnsServers(); + } } @Override From 5ce7c2add513704c193e19084384cde5d48c8531 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 16:14:58 -0700 Subject: [PATCH 08/11] potential NPE bug fixes in NetworkInterfaceImpl and NicIpConfigurationImpl --- .../implementation/NetworkInterfaceImpl.java | 13 ++++++++++--- .../implementation/NicIpConfigurationImpl.java | 8 ++------ 2 files changed, 12 insertions(+), 9 deletions(-) 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 62b39e13b49b4..a32bdd96cc67a 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 @@ -285,17 +285,24 @@ public String macAddress() { @Override public String internalDnsNameLabel() { - return this.inner().dnsSettings().internalDnsNameLabel(); + return (this.inner().dnsSettings() != null) ? this.inner().dnsSettings().internalDnsNameLabel() : null; } @Override public String internalDomainNameSuffix() { - return this.inner().dnsSettings().internalDomainNameSuffix(); + return (this.inner().dnsSettings() != null) ? this.inner().dnsSettings().internalDomainNameSuffix() : null; } @Override public List appliedDnsServers() { - return Collections.unmodifiableList(this.inner().dnsSettings().appliedDnsServers()); + List dnsServers = new ArrayList(); + if (this.inner().dnsSettings() == null) { + return Collections.unmodifiableList(dnsServers); + } else if (this.inner().dnsSettings().appliedDnsServers() == null) { + return Collections.unmodifiableList(dnsServers); + } else { + return Collections.unmodifiableList(this.inner().dnsSettings().appliedDnsServers()); + } } @Override 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 b245299020eb0..0eeeea2b4bce0 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,17 +120,13 @@ public String subnetName() { @Override public String networkId() { SubResource subnetRef = this.inner().subnet(); - if (subnetRef != null) { - return ResourceUtils.parentResourcePathFromResourceId(subnetRef.id()); - } else { - return null; - } + return (subnetRef != null) ? ResourceUtils.parentResourcePathFromResourceId(subnetRef.id()) : null; } @Override public Network getNetwork() { String id = this.networkId(); - return this.networkManager.networks().getById(id); + return (id != null) ? this.networkManager.networks().getById(id) : null; } @Override From 778ea23dd7614b8da0891d317a5ae707df885dbc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 16:18:29 -0700 Subject: [PATCH 09/11] more potential NPE fixes in NetworkInterfaceImpl --- .../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 a32bdd96cc67a..e1c5d074156cf 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 @@ -307,7 +307,7 @@ public List appliedDnsServers() { @Override public String internalFqdn() { - return this.inner().dnsSettings().internalFqdn(); + return (this.inner().dnsSettings() != null) ? this.inner().dnsSettings().internalFqdn() : null; } @Override From cd16387a78c881d8f4f0a7c33c1d7f0230b2bba1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 16:27:06 -0700 Subject: [PATCH 10/11] more NPE avoidance in NetworkInterfaceImpl --- .../implementation/NetworkInterfaceImpl.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 e1c5d074156cf..b975737141b16 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 @@ -332,10 +332,7 @@ public Map ipConfigurations() { @Override public String networkSecurityGroupId() { - if (this.inner().networkSecurityGroup() != null) { - return this.inner().networkSecurityGroup().id(); - } - return null; + return (this.inner().networkSecurityGroup() != null) ? this.inner().networkSecurityGroup().id() : null; } @Override @@ -377,10 +374,14 @@ public NicIpConfigurationImpl primaryIpConfiguration() { * @return the list of DNS server IPs from the DNS settings */ private List dnsServerIps() { - if (this.inner().dnsSettings().dnsServers() == null) { - this.inner().dnsSettings().withDnsServers(new ArrayList()); + List dnsServers = new ArrayList(); + if (this.inner().dnsSettings() == null) { + return dnsServers; + } else if (this.inner().dnsSettings().dnsServers() == null) { + return dnsServers; + } else { + return this.inner().dnsSettings().dnsServers(); } - return this.inner().dnsSettings().dnsServers(); } @Override From 6d19f8e0a92918d29e963fd5dd7ee1d58a94177c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2016 16:37:33 -0700 Subject: [PATCH 11/11] checkstyle issue --- .../azure/management/network/implementation/NetworkImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 639c23e60dd5c..cc406a361b983 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 @@ -145,7 +145,7 @@ public List addressSpaces() { List addressSpaces = new ArrayList(); if (this.inner().addressSpace() == null) { return Collections.unmodifiableList(addressSpaces); - } else if(this.inner().addressSpace().addressPrefixes() == null) { + } else if (this.inner().addressSpace().addressPrefixes() == null) { return Collections.unmodifiableList(addressSpaces); } else { return Collections.unmodifiableList(this.inner().addressSpace().addressPrefixes());