Skip to content

Commit

Permalink
Merge pull request #77 from alparslanavci/issue#76
Browse files Browse the repository at this point in the history
Changed publicIp check to privateIp when parsing API response
  • Loading branch information
alparslanavci authored Apr 9, 2021
2 parents 56b61a1 + 68cb460 commit f20cf3e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/hazelcast/azure/AzureComputeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private Map<String, AzureNetworkInterface> 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));
}
}
Expand Down
48 changes: 47 additions & 1 deletion src/test/java/com/hazelcast/azure/AzureComputeApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<AzureAddress> expected = new LinkedHashSet<AzureAddress>(2);
expected.add(address1);
expected.add(address2);
expected.add(address3);
assertEquals(expected, result);
}

Expand All @@ -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<AzureAddress> expected = new LinkedHashSet<AzureAddress>(2);
expected.add(address1);
expected.add(address2);
expected.add(address3);
assertEquals(expected, result);
}

Expand All @@ -127,6 +132,7 @@ public void instancesWithTag() {
expected.add(address1);
assertEquals(expected, result);
}

/**
* Response recorded from the real Cloud Compute API call.
*/
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit f20cf3e

Please sign in to comment.