Renaming the service client (user operations) ServiceClient to better match up to Keystone documentation

This commit is contained in:
Adam Lowe 2012-04-30 10:49:31 +01:00
parent 71ad3abf2a
commit 46b7ffa23c
8 changed files with 133 additions and 27 deletions

View File

@ -51,7 +51,7 @@ public interface KeystoneAsyncClient {
/** Provides asynchronous access to Identity user-accessible features */
@Delegate
UserAsyncClient getUserClientForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
ServiceAsyncClient getServiceClientForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
/** Provides asynchronous access to the KeyStone Admin API */
@Delegate

View File

@ -49,7 +49,7 @@ public interface KeystoneClient {
/** Provides synchronous access to Identity user-accessible features */
@Delegate
UserClient getUserClientForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
ServiceClient getServiceClientForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
/** Provides synchronous access to the KeyStone Admin API */
@Delegate

View File

@ -0,0 +1,71 @@
/**
* 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.keystone.v2_0;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.keystone.v2_0.domain.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to Service via their REST API.
* <p/>
*
* @see ServiceClient
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Client_Operations.html"
* />
* @author Adam Lowe
*/
@SkipEncoding({ '/', '=' })
public interface ServiceAsyncClient {
/**
* @see ServiceClient#getApiMetadata()
*/
@GET
@SelectJson("version")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ApiMetadata> getApiMetadata();
/**
* @see ServiceClient#listTenants()
*/
@GET
@SelectJson("tenants")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/tenants")
@RequestFilters(AuthenticateRequest.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Tenant>> listTenants();
}

View File

@ -0,0 +1,51 @@
/**
* 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.keystone.v2_0;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.keystone.v2_0.domain.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
/**
* Provides synchronous access to the KeyStone Service API.
* <p/>
*
* @author Adam Lowe
* @see ServiceAsyncClient
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Client_Operations.html"
* />
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface ServiceClient {
/**
* Discover API version information, links to documentation (PDF, HTML, WADL), and supported media types
*
* @return the requested information
*/
ApiMetadata getApiMetadata();
/**
* The operation returns a list of tenants which the current token provides access to.
*/
Set<Tenant> listTenants();
}

View File

@ -24,20 +24,17 @@ import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone;
import org.jclouds.openstack.keystone.v2_0.AdminAsyncClient;
import org.jclouds.openstack.keystone.v2_0.AdminClient;
import org.jclouds.openstack.keystone.v2_0.KeystoneAsyncClient;
import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
import org.jclouds.openstack.keystone.v2_0.UserAsyncClient;
import org.jclouds.openstack.keystone.v2_0.UserClient;
import org.jclouds.openstack.keystone.v2_0.ServiceAsyncClient;
import org.jclouds.openstack.keystone.v2_0.ServiceClient;
import org.jclouds.openstack.keystone.v2_0.handlers.KeystoneErrorHandler;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
/**
* Configures the Keystone connection.
@ -48,7 +45,7 @@ import com.google.inject.Scopes;
public class KeystoneRestClientModule extends RestClientModule<KeystoneClient, KeystoneAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(UserClient.class, UserAsyncClient.class).put(AdminClient.class, AdminAsyncClient.class)
.put(ServiceClient.class, ServiceAsyncClient.class).put(AdminClient.class, AdminAsyncClient.class)
.build();
public KeystoneRestClientModule() {

View File

@ -29,7 +29,6 @@ import java.util.Set;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.keystone.v2_0.domain.Access;
import org.jclouds.openstack.keystone.v2_0.domain.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.domain.Endpoint;
import org.jclouds.openstack.keystone.v2_0.domain.Role;

View File

@ -46,13 +46,13 @@ import com.google.common.collect.ImmutableSet;
public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<KeystoneClient> {
public void testGetApiMetaData() {
UserClient client = requestsSendResponses(
ServiceClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
HttpRequest.builder().method("GET").endpoint(URI.create(endpoint + "/v2.0/")).
headers(ImmutableMultimap.of("Accept", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).
payload(payloadFromResourceWithContentType("/api_metadata.json", APPLICATION_JSON)).build())
.getUserClientForRegion("region-a.geo-1");
.getServiceClientForRegion("region-a.geo-1");
ApiMetadata metadata = client.getApiMetadata();
assertNotNull(metadata);
assertEquals(metadata.getId(), "v2.0");
@ -74,13 +74,13 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
}
public void testListTenants() {
UserClient client = requestsSendResponses(
ServiceClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
HttpRequest.builder().method("GET").endpoint(URI.create(endpoint + "/v2.0/tenants")).
headers(ImmutableMultimap.of("Accept", APPLICATION_JSON, "X-Auth-Token", authToken)).build(),
HttpResponse.builder().statusCode(200).
payload(payloadFromResourceWithContentType("/tenant_list.json", APPLICATION_JSON)).build())
.getUserClientForRegion("region-a.geo-1");
.getServiceClientForRegion("region-a.geo-1");
Set<Tenant> tenants = client.listTenants();
assertNotNull(tenants);
assertFalse(tenants.isEmpty());

View File

@ -18,29 +18,17 @@
*/
package org.jclouds.openstack.keystone.v2_0;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import java.net.URI;
import java.util.Set;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.domain.Link;
import org.jclouds.openstack.keystone.v2_0.domain.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.domain.MediaType;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
import org.jclouds.openstack.keystone.v2_0.internal.BaseKeystoneClientLiveTest;
import org.jclouds.openstack.keystone.v2_0.internal.BaseKeystoneRestClientExpectTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
* Tests UserClient
*
@ -51,7 +39,7 @@ public class UserClientLiveTest extends BaseKeystoneClientLiveTest {
public void testGetApiMetaData() {
for (String regionId : keystoneContext.getApi().getConfiguredRegions()) {
ApiMetadata result = keystoneContext.getApi().getUserClientForRegion(regionId).getApiMetadata();
ApiMetadata result = keystoneContext.getApi().getServiceClientForRegion(regionId).getApiMetadata();
assertNotNull(result);
assertNotNull(result.getId());
assertNotNull(result.getStatus());
@ -61,7 +49,7 @@ public class UserClientLiveTest extends BaseKeystoneClientLiveTest {
public void testListTenants() {
for (String regionId : keystoneContext.getApi().getConfiguredRegions()) {
Set<Tenant> result = keystoneContext.getApi().getUserClientForRegion(regionId).listTenants();
Set<Tenant> result = keystoneContext.getApi().getServiceClientForRegion(regionId).listTenants();
assertNotNull(result);
assertFalse(result.isEmpty());