Adds listAll to PublicIPAddressAPI

Adds listAll to NetworkInterfaceCardApi

Addresses comments on tests

Sets resourcegroup pathparam as nullable for NetworkInterfaceCardApi and PublicIPAddressApi
This commit is contained in:
Dani Estevez 2018-07-09 12:35:53 -04:00 committed by Ignasi Barrera
parent 4958f1f29a
commit 566ac23392
9 changed files with 320 additions and 26 deletions

View File

@ -17,7 +17,6 @@
package org.jclouds.azurecompute.arm;
import java.io.Closeable;
import javax.ws.rs.PathParam;
import org.jclouds.azurecompute.arm.domain.ServicePrincipal;
@ -48,6 +47,7 @@ import org.jclouds.azurecompute.arm.features.VirtualMachineScaleSetApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkGatewayApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkGatewayConnectionApi;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rest.annotations.Delegate;
import com.google.common.base.Supplier;
@ -115,7 +115,7 @@ public interface AzureComputeApi extends Closeable {
* @see <a href="https://msdn.microsoft.com/en-us/library/mt163668.aspx">docs</a>
*/
@Delegate
NetworkInterfaceCardApi getNetworkInterfaceCardApi(@PathParam("resourcegroup") String resourcegroup);
NetworkInterfaceCardApi getNetworkInterfaceCardApi(@Nullable @PathParam("resourcegroup") String resourcegroup);
/**
* The Public IP Address API includes operations for managing public ID Addresses for NICs in your subscription.
@ -123,7 +123,7 @@ public interface AzureComputeApi extends Closeable {
* @see <a href="https://msdn.microsoft.com/en-us/library/azure/mt163638.aspx">docs</a>
*/
@Delegate
PublicIPAddressApi getPublicIPAddressApi(@PathParam("resourcegroup") String resourcegroup);
PublicIPAddressApi getPublicIPAddressApi(@Nullable @PathParam("resourcegroup") String resourcegroup);
/**

View File

@ -19,7 +19,6 @@ package org.jclouds.azurecompute.arm.features;
import java.net.URI;
import java.util.List;
import java.util.Map;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -45,19 +44,26 @@ import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload;
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/networkInterfaces")
@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
@Consumes(MediaType.APPLICATION_JSON)
public interface NetworkInterfaceCardApi {
@Named("networkinterfacecard:list")
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/networkInterfaces")
@SelectJson("value")
@GET
@Fallback(EmptyListOnNotFoundOr404.class)
List<NetworkInterfaceCard> list();
@Named("networkinterfacecard:list_all")
@Path("/providers/Microsoft.Network/networkInterfaces")
@SelectJson("value")
@GET
@Fallback(EmptyListOnNotFoundOr404.class)
List<NetworkInterfaceCard> listAllInSubscription();
@Named("networkinterfacecard:create_or_update")
@Path("/{networkinterfacecardname}")
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/networkInterfaces/{networkinterfacecardname}")
@MapBinder(BindToJsonPayload.class)
@PUT
NetworkInterfaceCard createOrUpdate(@PathParam("networkinterfacecardname") String networkinterfacecardname,
@ -66,13 +72,13 @@ public interface NetworkInterfaceCardApi {
@Nullable @PayloadParam("tags") Map<String, String> tags);
@Named("networkinterfacecard:get")
@Path("/{networkinterfacecardname}")
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/networkInterfaces/{networkinterfacecardname}")
@GET
@Fallback(NullOnNotFoundOr404.class)
NetworkInterfaceCard get(@PathParam("networkinterfacecardname") String networkinterfacecardname);
@Named("networkinterfacecard:delete")
@Path("/{networkinterfacecardname}")
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/networkInterfaces/{networkinterfacecardname}")
@DELETE
@ResponseParser(URIParser.class)
@Fallback(NullOnNotFoundOr404.class)

View File

@ -18,7 +18,6 @@ package org.jclouds.azurecompute.arm.features;
import java.util.List;
import java.util.Map;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -44,19 +43,26 @@ import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload;
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/publicIPAddresses")
@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
@Consumes(MediaType.APPLICATION_JSON)
public interface PublicIPAddressApi {
@Named("publicipaddress:list")
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/publicIPAddresses")
@SelectJson("value")
@GET
@Fallback(EmptyListOnNotFoundOr404.class)
List<PublicIPAddress> list();
@Named("publicipaddress:list_all")
@Path("/providers/Microsoft.Network/publicIPAddresses")
@SelectJson("value")
@GET
@Fallback(EmptyListOnNotFoundOr404.class)
List<PublicIPAddress> listAllInSubscription();
@Named("publicipaddress:create_or_update")
@Path("/{publicipaddressname}")
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/publicIPAddresses/{publicipaddressname}")
@MapBinder(BindToJsonPayload.class)
@PUT
PublicIPAddress createOrUpdate(@PathParam("publicipaddressname") String publicipaddressname,
@ -65,13 +71,13 @@ public interface PublicIPAddressApi {
@PayloadParam("properties") PublicIPAddressProperties properties);
@Named("publicipaddress:get")
@Path("/{publicipaddressname}")
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/publicIPAddresses/{publicipaddressname}")
@GET
@Fallback(NullOnNotFoundOr404.class)
PublicIPAddress get(@PathParam("publicipaddressname") String publicipaddressname);
@Named("publicipaddress:delete")
@Path("/{publicipaddressname}")
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/publicIPAddresses/{publicipaddressname}")
@DELETE
@ResponseParser(FalseOn204.class)
boolean delete(@PathParam("publicipaddressname") String publicipaddressname);

View File

@ -105,7 +105,14 @@ public class NetworkInterfaceCardApiLiveTest extends BaseAzureComputeApiLiveTest
assertTrue(nicList.contains(api().get(nicName)));
}
@Test(dependsOnMethods = {"listNetworkInterfaceCards", "getNetworkInterfaceCard"})
@Test(dependsOnMethods = "createNetworkInterfaceCard")
public void listAllNetworkInterfaceCardsInSubscription() {
List<NetworkInterfaceCard> nicList = api.getNetworkInterfaceCardApi(null).listAllInSubscription();
assertTrue(nicList.contains(api().get(nicName)));
}
@Test(dependsOnMethods = { "listNetworkInterfaceCards", "listAllNetworkInterfaceCardsInSubscription",
"getNetworkInterfaceCard" })
public void deleteNetworkInterfaceCard() {
URI uri = api().delete(nicName);
assertResourceDeleted(uri);

View File

@ -17,6 +17,7 @@
package org.jclouds.azurecompute.arm.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
@ -87,13 +88,49 @@ public class NetworkInterfaceCardApiMockTest extends BaseAzureComputeApiMockTest
assertEquals(nicList.get(1).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Static");
}
public void listAllNetworkInterfaceCardsInSubscription() throws InterruptedException {
server.enqueue(jsonResponse("/listallnetworkinterfaces.json"));
final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(null);
List<NetworkInterfaceCard> nicList = nicApi.listAllInSubscription();
String path = String
.format("/subscriptions/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, apiVersion);
assertSent(server, "GET", path);
assertTrue(nicList.size() == 3);
assertTrue(nicList.get(0).properties().ipConfigurations().size() > 0);
assertEquals(nicList.get(0).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(),
"Dynamic");
assertTrue(nicList.get(1).properties().ipConfigurations().size() > 0);
assertEquals(nicList.get(1).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(),
"Static");
assertTrue(nicList.get(2).properties().ipConfigurations().size() > 0);
assertNotEquals(IdReference.extractResourceGroup(nicList.get(2).id()), resourcegroup);
assertEquals(nicList.get(2).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(),
"Static");
}
public void listAllNetworkInterfaceCardsInSubscriptionEmpty() throws Exception {
server.enqueue(new MockResponse().setResponseCode(404));
final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(null);
assertTrue(nicApi.listAllInSubscription().isEmpty());
String path = String
.format("/subscriptions/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, apiVersion);
assertSent(server, "GET", path);
}
public void listNetworkInterfaceCardsEmpty() throws Exception {
server.enqueue(new MockResponse().setResponseCode(404));
final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup);
assertTrue(nicApi.list().isEmpty());
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, resourcegroup, apiVersion);
String path = String
.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces?%s",
subscriptionid, resourcegroup, apiVersion);
assertSent(server, "GET", path);
}

View File

@ -119,7 +119,18 @@ public class PublicIPAddressApiLiveTest extends BaseAzureComputeApiLiveTest {
assertTrue(ipList.size() > 0);
}
@Test(groups = "live", dependsOnMethods = {"listPublicIPAddresses", "getPublicIPAddress"}, alwaysRun = true)
@Test(groups = "live", dependsOnMethods = "createPublicIPAddress")
public void listAllPublicIPAddressesInSubscription() {
final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(null);
List<PublicIPAddress> ipList = ipApi.listAllInSubscription();
assertTrue(ipList.size() > 0);
}
@Test(groups = "live", dependsOnMethods = { "listPublicIPAddresses", "listAllPublicIPAddressesInSubscription",
"getPublicIPAddress" }, alwaysRun = true)
public void deletePublicIPAddress() {
final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourceGroupName);
boolean status = ipApi.delete(publicIpAddressName);

View File

@ -16,22 +16,23 @@
*/
package org.jclouds.azurecompute.arm.features;
import com.google.common.collect.ImmutableMap;
import com.squareup.okhttp.mockwebserver.MockResponse;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import org.jclouds.azurecompute.arm.domain.DnsSettings;
import org.jclouds.azurecompute.arm.domain.PublicIPAddress;
import org.jclouds.azurecompute.arm.domain.PublicIPAddressProperties;
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
import org.testng.annotations.Test;
import java.util.List;
import java.util.Map;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import com.google.common.collect.ImmutableMap;
import com.squareup.okhttp.mockwebserver.MockResponse;
@Test(groups = "unit", testName = "NetworkInterfaceCardApiMockTest", singleThreaded = true)
@ -103,6 +104,30 @@ public class PublicIPAddressApiMockTest extends BaseAzureComputeApiMockTest {
assertEquals(ipList.size(), 0);
}
public void listAllPublicIPAddressesInSubscription() throws InterruptedException {
server.enqueue(jsonResponse("/PublicIPAddressListAll.json"));
final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(null);
List<PublicIPAddress> ipList = ipApi.listAllInSubscription();
String path = String
.format("/subscriptions/%s/providers/Microsoft.Network/publicIPAddresses?%s", subscriptionid, apiVersion);
assertSent(server, "GET", path);
assertEquals(ipList.size(), 5);
}
public void listAllPublicIPAddressesInSubscriptionEmpty() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404));
final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(null);
List<PublicIPAddress> ipList = ipApi.listAllInSubscription();
String path = String
.format("/subscriptions/%s/providers/Microsoft.Network/publicIPAddresses?%s", subscriptionid, apiVersion);
assertSent(server, "GET", path);
assertEquals(ipList.size(), 0);
}
public void createPublicIPAddress() throws InterruptedException {
server.enqueue(jsonResponse("/PublicIPAddressCreate.json").setStatus("HTTP/1.1 201 Created"));

View File

@ -0,0 +1,102 @@
{
"value": [
{
"name": "my2ndpublicaddress",
"id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/my2ndpublicaddress",
"etag": "W/\"b83fa879-46ee-48a9-8120-26572449788f\"",
"type": "Microsoft.Network/publicIPAddresses",
"location": "northeurope",
"tags": {
"testkey": "testvalue"
},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "ebe3f160-2484-447a-8980-c587b214b16f",
"publicIPAllocationMethod": "Dynamic",
"idleTimeoutInMinutes": 4,
"dnsSettings": {
"domainNameLabel": "foobar123",
"fqdn": "foobar123.northeurope.cloudapp.azure.com"
}
}
},
{
"name": "my3rdpublicaddress",
"id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/my3rdpublicaddress",
"etag": "W/\"17d2cf9a-7aa8-4c53-a5b8-ebc2ccb7bf93\"",
"type": "Microsoft.Network/publicIPAddresses",
"location": "northeurope",
"tags": {
"testkey": "testvalue"
},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "e1107240-79c5-4829-ba16-f7a00c2763df",
"ipAddress": "12.12.123.123",
"publicIPAllocationMethod": "Static",
"idleTimeoutInMinutes": 4
}
},
{
"name": "my4thpublicaddress",
"id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/my4thpublicaddress",
"etag": "W/\"c32275e9-e1fc-465a-a5de-728c1359e123\"",
"type": "Microsoft.Network/publicIPAddresses",
"location": "northeurope",
"tags": {
"testkey": "testvalue"
},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "dbde9a83-8c1a-43f4-8d81-0fa469703e8a",
"ipAddress": "12.12.123.124",
"publicIPAllocationMethod": "Static",
"idleTimeoutInMinutes": 4
}
},
{
"name": "mypublicaddress",
"id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/mypublicaddress",
"etag": "W/\"0b020646-202f-4ac6-b1a7-f9645db7c371\"",
"type": "Microsoft.Network/publicIPAddresses",
"location": "northeurope",
"tags": {},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "eb0da01e-2a30-4e84-b7a4-0ce9dde019f5",
"ipAddress": "12.123.12.125",
"publicIPAllocationMethod": "Static",
"idleTimeoutInMinutes": 4,
"dnsSettings": {
"domainNameLabel": "foobar",
"fqdn": "foobar.northeurope.cloudapp.azure.com"
},
"ipConfiguration": {
"id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkInterfaces/myNic/ipConfigurations/myip1"
}
}
},
{
"name": "mypublicaddressinanotherResourceGroup",
"id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/anotherresourcegroup/providers/Microsoft.Network/publicIPAddresses/mypublicaddress",
"etag": "W/\"0b020646-202f-4ac6-b1a7-f9645db7c371\"",
"type": "Microsoft.Network/publicIPAddresses",
"location": "northeurope",
"tags": {},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "eb0da01e-2a30-4e84-b7a4-0ce9dde019f5",
"ipAddress": "12.123.12.126",
"publicIPAllocationMethod": "Static",
"idleTimeoutInMinutes": 4,
"dnsSettings": {
"domainNameLabel": "foobar",
"fqdn": "foobarotherrg.northeurope.cloudapp.azure.com"
},
"ipConfiguration": {
"id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/anotherresourcegroup/providers/Microsoft.Network/networkInterfaces/myNic/ipConfigurations/myip2"
}
}
}
]
}

View File

@ -0,0 +1,100 @@
{
"value": [
{
"name": "AnotherNIC",
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/AnotherNIC",
"etag": "W/\"e4ed4253-64b6-4184-bfaa-554f470d20c5\"",
"type": "Microsoft.Network/networkInterfaces",
"location": "northeurope",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "7fcf6704-21c5-4983-bd9f-017e0873f22f",
"ipConfigurations": [
{
"name": "ipconfig1",
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/AnotherNIC/ipConfigurations/ipconfig1",
"etag": "W/\"e4ed4253-64b6-4184-bfaa-554f470d20c5\"",
"properties": {
"provisioningState": "Succeeded",
"privateIPAddress": "10.2.1.4",
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/armlivetesting/providers/Microsoft.Network/virtualNetworks/jclouds-virtual-network-live-test/subnets/anothersubnet"
},
"primary": true
}
}
],
"dnsSettings": {
"dnsServers": [],
"appliedDnsServers": []
},
"enableIPForwarding": false
}
},
{
"name": "MyNic",
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/MyNic",
"etag": "W/\"a37d25ff-3f62-4ee2-a111-f355beb5ff69\"",
"type": "Microsoft.Network/networkInterfaces",
"location": "northeurope",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "35908409-a081-4411-86a9-51f9ea99321f",
"ipConfigurations": [
{
"name": "ipconfig1",
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/MyNic/ipConfigurations/ipconfig1",
"etag": "W/\"a37d25ff-3f62-4ee2-a111-f355beb5ff69\"",
"properties": {
"provisioningState": "Succeeded",
"privateIPAddress": "10.2.0.100",
"privateIPAllocationMethod": "Static",
"subnet": {
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/armlivetesting/providers/Microsoft.Network/virtualNetworks/jclouds-virtual-network-live-test/subnets/default"
},
"primary": true
}
}
],
"dnsSettings": {
"dnsServers": [],
"appliedDnsServers": []
},
"enableIPForwarding": false
}
},
{
"name": "MyNicInAnotherRG",
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/otherazurearmtesting/providers/Microsoft.Network/networkInterfaces/MyNic",
"etag": "W/\"a37d25ff-3f62-4ee2-a111-f355beb5ff69\"",
"type": "Microsoft.Network/networkInterfaces",
"location": "northeurope",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "35908409-a081-4411-86a9-51f9ea99321f",
"ipConfigurations": [
{
"name": "ipconfig1",
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/otherazurearmtesting/providers/Microsoft.Network/networkInterfaces/MyNic/ipConfigurations/ipconfig1",
"etag": "W/\"a37d25ff-3f62-4ee2-a111-f355beb5ff69\"",
"properties": {
"provisioningState": "Succeeded",
"privateIPAddress": "10.2.0.101",
"privateIPAllocationMethod": "Static",
"subnet": {
"id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/otherazurearmtesting/providers/Microsoft.Network/virtualNetworks/jclouds-virtual-network-live-test/subnets/default"
},
"primary": true
}
}
],
"dnsSettings": {
"dnsServers": [],
"appliedDnsServers": []
},
"enableIPForwarding": false
}
}
]
}