added new Extension annotation for determining if clients are available or not

This commit is contained in:
Adrian Cole 2012-03-14 11:05:56 -07:00
parent bc95b6fe25
commit e9f29883d9
24 changed files with 364 additions and 94 deletions

View File

@ -0,0 +1,77 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.services;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* An extension of a {@link ServiceType service}. In order for us to understand
* the context of the extension, we must consider the <a href=
* "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html"
* >extensions call</a>.
*
* <br/>
* For our purposes, the minimal context of an extension is the type of the
* service it extends ex. {@link ServiceType#COMPUTE}, and its namespace ex. <a
* href
* ="http://docs.openstack.org/ext/keypairs/api/v1.1">http://docs.openstack.org
* /ext/keypairs/api/v1.1</a>.
*
* @author Adrian Cole
*
* @see ServiceType
* @see <a href=
* "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html"
* />
* @see <a href="http://nova.openstack.org/api_ext" />
* @see <a href="http://nova.openstack.org/api_ext/ext_keypairs.html" />
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Extension {
/**
* the service type this is an extension of.
*
* <h3>note</h3>
*
* This isn't necessarily one of the built-in {@link ServiceType services},
* it could be an extension of a custom service.
*
* @return the service type this is an extension of.
*
*/
String of();
/**
* namespace ex. <a href
* ="http://docs.openstack.org/ext/keypairs/api/v1.1">http
* ://docs.openstack.org /ext/keypairs/api/v1.1</a>.
*
* @return the namespace of the extension
*/
String namespace();
}

View File

@ -33,6 +33,7 @@ import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import com.google.common.base.Optional;
import com.google.inject.Provides;
/**
@ -85,7 +86,7 @@ public interface NovaAsyncClient {
* Provides asynchronous access to Floating IP features.
*/
@Delegate
FloatingIPAsyncClient getFloatingIPClientForRegion(
Optional<FloatingIPAsyncClient> getFloatingIPExtensionForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**

View File

@ -35,6 +35,7 @@ import org.jclouds.openstack.nova.v1_1.features.ServerClient;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import com.google.common.base.Optional;
import com.google.inject.Provides;
/**
@ -87,7 +88,7 @@ public interface NovaClient {
* Provides synchronous access to Floating IP features.
*/
@Delegate
FloatingIPClient getFloatingIPClientForRegion(
Optional<FloatingIPClient> getFloatingIPExtensionForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**

View File

@ -18,7 +18,6 @@
*/
package org.jclouds.openstack.nova.v1_1.extensions;
import java.net.URI;
/**
* Extension namespaces
@ -27,8 +26,8 @@ import java.net.URI;
* @see <a href= "http://nova.openstack.org/api_ext/" />
*/
public interface ExtensionNamespaces {
public static URI KEYPAIRS = URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1");
public static URI VOLUMES = URI.create("http://docs.openstack.org/ext/volumes/api/v1.1");
public static URI SECURITY_GROUPS = URI.create("http://docs.openstack.org/ext/securitygroups/api/v1.1");
public static URI FLOATING_IPS = URI.create("http://docs.openstack.org/ext/floating_ips/api/v1.1");
public static final String KEYPAIRS = "http://docs.openstack.org/ext/keypairs/api/v1.1";
public static final String VOLUMES = "http://docs.openstack.org/ext/volumes/api/v1.1";
public static final String SECURITY_GROUPS = "http://docs.openstack.org/ext/securitygroups/api/v1.1";
public static final String FLOATING_IPS = "http://docs.openstack.org/ext/floating_ips/api/v1.1";
}

View File

@ -32,6 +32,8 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
import org.jclouds.openstack.nova.v1_1.features.ExtensionAsyncClient;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
@ -50,10 +52,13 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see FloatingIPClient
* @author Jeremy Daggett
* @see ExtensionAsyncClient
* @see <a href="http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html" />
* @see <a href=
* "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html"
* />
* @see <a href="http://nova.openstack.org/api_ext" />
* @see <a href="http://wiki.openstack.org/os_api_floating_ip"/>
*/
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.FLOATING_IPS)
@SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface FloatingIPAsyncClient {
@ -107,9 +112,7 @@ public interface FloatingIPAsyncClient {
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"addFloatingIp\":%7B\"address\":\"{address}\"%7D%7D")
ListenableFuture<Void> addFloatingIP(
@PathParam("server") String serverId,
@PayloadParam("address") String address);
ListenableFuture<Void> addFloatingIP(@PathParam("server") String serverId, @PayloadParam("address") String address);
/**
* @see FloatingIPClient#removeFloatingIP
@ -119,8 +122,6 @@ public interface FloatingIPAsyncClient {
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"removeFloatingIp\":%7B\"address\":\"{address}\"%7D%7D")
ListenableFuture<Void> removeFloatingIP(
@PathParam("server") String serverId,
@PayloadParam("address") String address);
ListenableFuture<Void> removeFloatingIP(@PathParam("server") String serverId, @PayloadParam("address") String address);
}

View File

@ -23,6 +23,8 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
/**
* Provides synchronous access to Floating IPs.
@ -31,6 +33,7 @@ import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
* @see FloatingIPAsyncClient
* @author Jeremy Daggett
*/
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.FLOATING_IPS)
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface FloatingIPClient {

View File

@ -33,6 +33,8 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.domain.KeyPair;
import org.jclouds.openstack.nova.v1_1.features.ExtensionAsyncClient;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
@ -55,6 +57,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see <a href="http://nova.openstack.org/api_ext" />
* @see <a href="http://nova.openstack.org/api_ext/ext_keypairs.html" />
*/
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.KEYPAIRS)
@SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface KeyPairAsyncClient {

View File

@ -24,6 +24,8 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.nova.v1_1.domain.KeyPair;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
/**
* Provides synchronous access to Security Groups.
@ -32,6 +34,7 @@ import org.jclouds.openstack.nova.v1_1.domain.KeyPair;
* @see KeyPairAsyncClient
* @author Jeremy Daggett
*/
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.KEYPAIRS)
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface KeyPairClient {

View File

@ -32,6 +32,8 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup;
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
@ -54,6 +56,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see <a href="http://nova.openstack.org/api_ext" />
* @see <a href="http://wiki.openstack.org/os-security-groups" />
*/
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.SECURITY_GROUPS)
@SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface SecurityGroupAsyncClient {

View File

@ -24,6 +24,8 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup;
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
/**
* Provides synchronous access to Security Groups.
@ -32,6 +34,7 @@ import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule;
* @see SecurityGroupAsyncClient
* @author Jeremy Daggett
*/
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.SECURITY_GROUPS)
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface SecurityGroupClient {

View File

@ -26,7 +26,7 @@ import java.util.Properties;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseServerListTest;
import org.testng.annotations.Test;
@ -39,7 +39,7 @@ import com.google.common.collect.ImmutableSet;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "PasswordAuthenticationExpectTest")
public class PasswordAuthenticationExpectTest extends BaseNovaRestClientExpectTest {
public class PasswordAuthenticationExpectTest extends BaseNovaClientExpectTest {
/**
* this reflects the properties that a user would pass to createContext

View File

@ -0,0 +1,160 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.extensions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaAsyncClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseFloatingIPListTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseFloatingIPTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
/**
* Tests annotation parsing of {@code FloatingIPAsyncClient}
*
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "FloatingIPAsyncClientExpectTest")
public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTest {
public void testListFloatingIPsWhenResponseIs2xx() throws Exception {
HttpRequest listFloatingIPs = HttpRequest
.builder()
.method("GET")
.endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
.headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/floatingip_list.json")).build();
NovaAsyncClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listFloatingIPs, listFloatingIPsResponse);
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), ImmutableSet.of("North"));
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs().get()
.toString(), new ParseFloatingIPListTest().expected().toString());
}
public void testListFloatingIPsWhenResponseIs404() throws Exception {
HttpRequest listFloatingIPs = HttpRequest
.builder()
.method("GET")
.endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
.headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(404).build();
NovaAsyncClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listFloatingIPs, listFloatingIPsResponse);
assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs().get()
.isEmpty());
}
public void testGetFloatingIPWhenResponseIs2xx() throws Exception {
HttpRequest getFloatingIP = HttpRequest
.builder()
.method("GET")
.endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips/1"))
.headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/floatingip_details.json")).build();
NovaAsyncClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, getFloatingIP, getFloatingIPResponse);
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1").get()
.toString(), new ParseFloatingIPTest().expected().toString());
}
public void testGetFloatingIPWhenResponseIs404() throws Exception {
HttpRequest getFloatingIP = HttpRequest
.builder()
.method("GET")
.endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips/1"))
.headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
NovaAsyncClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, getFloatingIP, getFloatingIPResponse);
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1").get());
}
public void testAllocateWhenResponseIs2xx() throws Exception {
HttpRequest allocateFloatingIP = HttpRequest
.builder()
.method("POST")
.endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
.headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build())
.payload(payloadFromStringWithContentType("{}", "application/json")).build();
HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/floatingip_details.json")).build();
NovaAsyncClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, allocateFloatingIP, allocateFloatingIPResponse);
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().allocate().get()
.toString(), new ParseFloatingIPTest().expected().toString());
}
public void testAllocateWhenResponseIs404() throws Exception {
HttpRequest allocateFloatingIP = HttpRequest
.builder()
.method("POST")
.endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
.headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build())
.payload(payloadFromStringWithContentType("{}", "application/json")).build();
HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
NovaAsyncClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, allocateFloatingIP, allocateFloatingIPResponse);
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().allocate().get());
}
}

View File

@ -27,7 +27,7 @@ import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseFloatingIPListTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseFloatingIPTest;
import org.testng.annotations.Test;
@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableSet;
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "FloatingIPClientExpectTest")
public class FloatingIPClientExpectTest extends BaseNovaRestClientExpectTest {
public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
public void testListFloatingIPsWhenResponseIs2xx() throws Exception {
HttpRequest listFloatingIPs = HttpRequest
@ -64,7 +64,7 @@ public class FloatingIPClientExpectTest extends BaseNovaRestClientExpectTest {
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(),
ImmutableSet.of("North"));
assertEquals(clientWhenFloatingIPsExist.getFloatingIPClientForRegion("North")
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get()
.listFloatingIPs().toString(), new ParseFloatingIPListTest().expected()
.toString());
}
@ -87,7 +87,7 @@ public class FloatingIPClientExpectTest extends BaseNovaRestClientExpectTest {
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
listFloatingIPs, listFloatingIPsResponse);
assertTrue(clientWhenNoServersExist.getFloatingIPClientForRegion("North")
assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get()
.listFloatingIPs().isEmpty());
}
@ -109,7 +109,7 @@ public class FloatingIPClientExpectTest extends BaseNovaRestClientExpectTest {
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
getFloatingIP, getFloatingIPResponse);
assertEquals(clientWhenFloatingIPsExist.getFloatingIPClientForRegion("North")
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get()
.getFloatingIP("1").toString(),
new ParseFloatingIPTest().expected().toString());
}
@ -131,7 +131,7 @@ public class FloatingIPClientExpectTest extends BaseNovaRestClientExpectTest {
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
getFloatingIP, getFloatingIPResponse);
assertNull(clientWhenNoServersExist.getFloatingIPClientForRegion("North")
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get()
.getFloatingIP("1"));
}
@ -154,7 +154,7 @@ public class FloatingIPClientExpectTest extends BaseNovaRestClientExpectTest {
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
allocateFloatingIP, allocateFloatingIPResponse);
assertEquals(clientWhenFloatingIPsExist.getFloatingIPClientForRegion("North")
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get()
.allocate().toString(),
new ParseFloatingIPTest().expected().toString());
@ -178,7 +178,7 @@ public class FloatingIPClientExpectTest extends BaseNovaRestClientExpectTest {
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
allocateFloatingIP, allocateFloatingIPResponse);
assertNull(clientWhenNoServersExist.getFloatingIPClientForRegion("North")
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get()
.allocate());
}

View File

@ -25,6 +25,7 @@ import static org.testng.Assert.assertTrue;
import java.util.Set;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
import org.jclouds.openstack.nova.v1_1.domain.Address;
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
@ -52,8 +53,10 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest {
@Test
public void testListFloatingIPs() throws Exception {
for (String regionId : context.getApi().getConfiguredRegions()) {
FloatingIPClient client = context.getApi().getFloatingIPClientForRegion(regionId);
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId);
if (!clientOption.isPresent())
continue;
FloatingIPClient client = clientOption.get();
Set<FloatingIP> response = client.listFloatingIPs();
assert null != response;
assertTrue(response.size() >= 0);
@ -73,7 +76,10 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest {
@Test
public void testAllocateAndDeallocateFloatingIPs() throws Exception {
for (String regionId : context.getApi().getConfiguredRegions()) {
FloatingIPClient client = context.getApi().getFloatingIPClientForRegion(regionId);
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId);
if (!clientOption.isPresent())
continue;
FloatingIPClient client = clientOption.get();
FloatingIP floatingIP = client.allocate();
assertNotNull(floatingIP);
@ -101,7 +107,10 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest {
@Test
public void testAddAndRemoveFloatingIp() throws Exception {
for (String regionId : context.getApi().getConfiguredRegions()) {
FloatingIPClient client = context.getApi().getFloatingIPClientForRegion(regionId);
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId);
if (!clientOption.isPresent())
continue;
FloatingIPClient client = clientOption.get();
ServerClient serverClient = context.getApi().getServerClientForRegion(regionId);
Server server = serverClient.createServer("test", imageIdForRegion(regionId), flavorRefForRegion(regionId));
blockUntilServerActive(server.getId(), serverClient);

View File

@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableSet;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseKeyPairListTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseKeyPairTest;
import org.testng.annotations.Test;
@ -40,7 +40,7 @@ import static org.testng.Assert.assertTrue;
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "KeyPairClientExpectTest")
public class KeyPairClientExpectTest extends BaseNovaRestClientExpectTest {
public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
public void testListKeyPairsWhenResponseIs2xx() throws Exception {
HttpRequest listKeyPairs = HttpRequest

View File

@ -18,19 +18,19 @@
*/
package org.jclouds.openstack.nova.v1_1.extensions;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseSecurityGroupListTest;
import org.testng.annotations.Test;
import java.net.URI;
import java.util.logging.Logger;
import static org.testng.Assert.assertEquals;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
/**
* Tests annotation parsing of {@code SecurityGroupAsyncClient}
@ -38,7 +38,7 @@ import static org.testng.Assert.assertEquals;
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "SecurityGroupClientExpectTest")
public class SecurityGroupClientExpectTest extends BaseNovaRestClientExpectTest {
public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
public void testListSecurityGroupsWhenResponseIs2xx() throws Exception {
HttpRequest listSecurityGroups = HttpRequest
.builder()

View File

@ -27,7 +27,7 @@ import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseExtensionListTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseExtensionTest;
import org.testng.annotations.Test;
@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableSet;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ExtensionClientExpectTest")
public class ExtensionClientExpectTest extends BaseNovaRestClientExpectTest {
public class ExtensionClientExpectTest extends BaseNovaClientExpectTest {
public void testListExtensionsWhenResponseIs2xx() throws Exception {
HttpRequest listExtensions = HttpRequest

View File

@ -27,7 +27,7 @@ import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseFlavorListTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseFlavorTest;
import org.testng.annotations.Test;
@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableSet;
* @author Jeremy Daggett
*/
@Test(groups = "unit", testName = "FlavorClientExpectTest")
public class FlavorClientExpectTest extends BaseNovaRestClientExpectTest {
public class FlavorClientExpectTest extends BaseNovaClientExpectTest {
public void testListFlavorsWhenResponseIs2xx() throws Exception {
HttpRequest listFlavors = HttpRequest

View File

@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableSet;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseImageTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseImageListTest;
import org.testng.annotations.Test;
@ -40,7 +40,7 @@ import static org.testng.Assert.assertTrue;
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "ImageAsyncClientTest")
public class ImageClientExpectTest extends BaseNovaRestClientExpectTest {
public class ImageClientExpectTest extends BaseNovaClientExpectTest {
public void testListImagesWhenResponseIs2xx() throws Exception {
HttpRequest listImages = HttpRequest
.builder()

View File

@ -26,7 +26,7 @@ import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseServerListTest;
import org.testng.annotations.Test;
@ -39,7 +39,7 @@ import com.google.common.collect.ImmutableSet;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ServerAsyncClientTest")
public class ServerClientExpectTest extends BaseNovaRestClientExpectTest {
public class ServerClientExpectTest extends BaseNovaClientExpectTest {
public void testListServersWhenResponseIs2xx() throws Exception {
HttpRequest listServers = HttpRequest.builder().method("GET").endpoint(

View File

@ -18,33 +18,32 @@
*/
package org.jclouds.openstack.nova.v1_1.internal;
import static org.testng.Assert.assertEquals;
import static org.jclouds.rest.RestContextFactory.createContext;
import java.util.Properties;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Base class for writing KeyStone Rest Client Expect tests
*
* @author Adrian Cole
*/
public abstract class BaseNovaAsyncClientTest<T> extends RestClientTest<T> {
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), AuthenticateRequest.class);
public class BaseNovaAsyncClientExpectTest extends BaseNovaExpectTest<NovaAsyncClient> {
public NovaAsyncClient createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
RestContextSpec<NovaClient, NovaAsyncClient> contextSpec = new RestContextFactory(setupRestProperties())
.createContextSpec(provider, identity, credential, new Properties());
return createContext(contextSpec,
ImmutableSet.<Module> of(new ExpectModule(fn), new NullLoggingModule(), module), props).getAsyncApi();
}
@Override
public RestContextSpec<NovaClient, NovaAsyncClient> createContextSpec() {
Properties props = new Properties();
return new RestContextFactory().createContextSpec("openstack-nova", "accountId", "accessKey", props);
}
}

View File

@ -0,0 +1,30 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.internal;
import org.jclouds.openstack.nova.v1_1.NovaClient;
/**
* Base class for writing KeyStone Rest Client Expect tests
*
* @author Adrian Cole
*/
public class BaseNovaClientExpectTest extends BaseNovaExpectTest<NovaClient> {
}

View File

@ -25,42 +25,21 @@ import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture;
import org.jclouds.rest.BaseRestClientExpectTest;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Base class for writing KeyStone Expect tests with the ComputeService abstraction
* Base class for writing KeyStone Expect tests with the ComputeService
* abstraction
*
* @author Matt Stephenson
*/
public class BaseNovaComputeServiceExpectTest extends BaseRestClientExpectTest<ComputeService>
{
protected HttpRequest keystoneAuthWithUsernameAndPassword;
protected HttpRequest keystoneAuthWithAccessKeyAndSecretKey;
protected String authToken;
protected HttpResponse responseWithKeystoneAccess;
public BaseNovaComputeServiceExpectTest()
{
provider = "openstack-nova";
keystoneAuthWithUsernameAndPassword = KeystoneFixture.INSTANCE.initialAuthWithUsernameAndPassword(identity,
credential);
keystoneAuthWithAccessKeyAndSecretKey = KeystoneFixture.INSTANCE.initialAuthWithAccessKeyAndSecretKey(identity,
credential);
authToken = KeystoneFixture.INSTANCE.getAuthToken();
responseWithKeystoneAccess = KeystoneFixture.INSTANCE.responseWithAccess();
// now, createContext arg will need tenant prefix
identity = KeystoneFixture.INSTANCE.getTenantName() + ":" + identity;
}
public class BaseNovaComputeServiceExpectTest extends BaseNovaExpectTest<ComputeService> {
@Override
public ComputeService createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props)
{
public ComputeService createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, identity, credential,
ImmutableSet.<Module> of(new ExpectModule(fn), new NullLoggingModule(), module), props).getComputeService();
}

View File

@ -21,21 +21,20 @@ package org.jclouds.openstack.nova.v1_1.internal;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.rest.BaseRestClientExpectTest;
/**
* Base class for writing KeyStone Rest Client Expect tests
* Base class for writing Nova Expect tests
*
* @author Adrian Cole
*/
public class BaseNovaRestClientExpectTest extends BaseRestClientExpectTest<NovaClient> {
public class BaseNovaExpectTest<T> extends BaseRestClientExpectTest<T> {
protected HttpRequest keystoneAuthWithUsernameAndPassword;
protected HttpRequest keystoneAuthWithAccessKeyAndSecretKey;
protected String authToken;
protected HttpResponse responseWithKeystoneAccess;
public BaseNovaRestClientExpectTest() {
public BaseNovaExpectTest() {
provider = "openstack-nova";
keystoneAuthWithUsernameAndPassword = KeystoneFixture.INSTANCE.initialAuthWithUsernameAndPassword(identity,
credential);