diff --git a/src/main/java/com/hazelcast/azure/AzureComputeApi.java b/src/main/java/com/hazelcast/azure/AzureComputeApi.java index d29e5af..22b001b 100644 --- a/src/main/java/com/hazelcast/azure/AzureComputeApi.java +++ b/src/main/java/com/hazelcast/azure/AzureComputeApi.java @@ -106,7 +106,7 @@ private Map parsePrivateIpResponse(String respons JsonObject ipProps = ipConfiguration.asObject().get("properties").asObject(); String privateIp = ipProps.getString("privateIPAddress", null); String publicIpId = toJsonObject(ipProps.get("publicIPAddress")).getString("id", null); - if (!isEmpty(publicIpId)) { + if (!isEmpty(privateIp)) { interfaces.put(publicIpId, new AzureNetworkInterface(privateIp, publicIpId, tagList)); } } diff --git a/src/test/java/com/hazelcast/azure/AzureComputeApiTest.java b/src/test/java/com/hazelcast/azure/AzureComputeApiTest.java index 041653a..b1db0b9 100644 --- a/src/test/java/com/hazelcast/azure/AzureComputeApiTest.java +++ b/src/test/java/com/hazelcast/azure/AzureComputeApiTest.java @@ -45,6 +45,7 @@ public class AzureComputeApiTest { private static final String INSTANCE_1_PUBLIC_IP = "35.207.0.219"; private static final String INSTANCE_2_PRIVATE_IP = "10.240.0.3"; private static final String INSTANCE_2_PUBLIC_IP = "35.237.227.147"; + private static final String INSTANCE_3_PRIVATE_IP = "10.240.0.4"; private AzureComputeApi azureComputeApi; @@ -74,9 +75,11 @@ public void instancesNoScaleSetNoTag() { // then AzureAddress address1 = new AzureAddress(INSTANCE_1_PRIVATE_IP, INSTANCE_1_PUBLIC_IP); AzureAddress address2 = new AzureAddress(INSTANCE_2_PRIVATE_IP, INSTANCE_2_PUBLIC_IP); + AzureAddress address3 = new AzureAddress(INSTANCE_3_PRIVATE_IP, null); Set expected = new LinkedHashSet(2); expected.add(address1); expected.add(address2); + expected.add(address3); assertEquals(expected, result); } @@ -100,9 +103,11 @@ public void instancesWithScaleSet() { // then AzureAddress address1 = new AzureAddress(INSTANCE_1_PRIVATE_IP, INSTANCE_1_PUBLIC_IP); AzureAddress address2 = new AzureAddress(INSTANCE_2_PRIVATE_IP, INSTANCE_2_PUBLIC_IP); + AzureAddress address3 = new AzureAddress(INSTANCE_3_PRIVATE_IP, null); Set expected = new LinkedHashSet(2); expected.add(address1); expected.add(address2); + expected.add(address3); assertEquals(expected, result); } @@ -127,6 +132,7 @@ public void instancesWithTag() { expected.add(address1); assertEquals(expected, result); } + /** * Response recorded from the real Cloud Compute API call. */ @@ -223,9 +229,49 @@ private static String instancesResponseForNetworkInterfaces() { + " }\n" + " },\n" + " \"type\": \"Microsoft.Network/networkInterfaces\"\n" + + " },\n" + + " {\n" + + " \"name\": \"test-nic3\",\n" + + " \"id\": \"/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/test-nic3\",\n" + + " \"location\": \"eastus\",\n" + + " \"properties\": {\n" + + " \"provisioningState\": \"Succeeded\",\n" + + " \"ipConfigurations\": [\n" + + " {\n" + + " \"name\": \"ipconfig1\",\n" + + " \"id\": \"/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/test-nic3/ipConfigurations/ipconfig1\",\n" + + " \"properties\": {\n" + + " \"provisioningState\": \"Succeeded\",\n" + + " \"privateIPAddress\": \"%s\",\n" + + " \"privateIPAllocationMethod\": \"Dynamic\",\n" + + " \"subnet\": {\n" + + " \"id\": \"/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/rg1-vnet2/subnets/default\"\n" + + " },\n" + + " \"primary\": true,\n" + + " \"privateIPAddressVersion\": \"IPv4\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"dnsSettings\": {\n" + + " \"dnsServers\": [],\n" + + " \"appliedDnsServers\": [],\n" + + " \"internalDomainNameSuffix\": \"test3.bx.internal.cloudapp.net\"\n" + + " },\n" + + " \"macAddress\": \"00-0D-3A-1B-C7-23\",\n" + + " \"enableAcceleratedNetworking\": true,\n" + + " \"enableIPForwarding\": false,\n" + + " \"networkSecurityGroup\": {\n" + + " \"id\": \"/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/networkSecurityGroups/nsg\"\n" + + " },\n" + + " \"primary\": true,\n" + + " \"virtualMachine\": {\n" + + " \"id\": \"/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachines/vm2\"\n" + + " }\n" + + " },\n" + + " \"type\": \"Microsoft.Network/networkInterfaces\"\n" + " }\n" + " ]\n" - + "}", INSTANCE_1_PRIVATE_IP, TAG.getKey(), TAG.getValue(), INSTANCE_2_PRIVATE_IP); + + "}", INSTANCE_1_PRIVATE_IP, TAG.getKey(), TAG.getValue(), INSTANCE_2_PRIVATE_IP, INSTANCE_3_PRIVATE_IP); } private String instancesResponseForPublicIPAddresses() {