Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed publicIp check to privateIp when parsing API response [CN-47] #77

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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