From 46b7ffa23c686331b364e4781d9841c7750a12b2 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Mon, 30 Apr 2012 10:49:31 +0100 Subject: [PATCH] Renaming the service client (user operations) ServiceClient to better match up to Keystone documentation --- .../keystone/v2_0/KeystoneAsyncClient.java | 2 +- .../keystone/v2_0/KeystoneClient.java | 2 +- .../keystone/v2_0/ServiceAsyncClient.java | 71 +++++++++++++++++++ .../keystone/v2_0/ServiceClient.java | 51 +++++++++++++ .../v2_0/config/KeystoneRestClientModule.java | 9 +-- .../keystone/v2_0/AdminClientLiveTest.java | 1 - .../keystone/v2_0/UserClientExpectTest.java | 8 +-- .../keystone/v2_0/UserClientLiveTest.java | 16 +---- 8 files changed, 133 insertions(+), 27 deletions(-) create mode 100644 labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceAsyncClient.java create mode 100644 labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceClient.java diff --git a/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneAsyncClient.java b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneAsyncClient.java index cae2d1d9f2..cb88070c2f 100644 --- a/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneAsyncClient.java +++ b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneAsyncClient.java @@ -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 diff --git a/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneClient.java b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneClient.java index ff7f27f18a..2c63a5b074 100644 --- a/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneClient.java +++ b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneClient.java @@ -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 diff --git a/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceAsyncClient.java b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceAsyncClient.java new file mode 100644 index 0000000000..9cc665fd91 --- /dev/null +++ b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceAsyncClient.java @@ -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. + *

+ * + * @see ServiceClient + * @see + * @author Adam Lowe + */ +@SkipEncoding({ '/', '=' }) +public interface ServiceAsyncClient { + /** + * @see ServiceClient#getApiMetadata() + */ + @GET + @SelectJson("version") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getApiMetadata(); + + /** + * @see ServiceClient#listTenants() + */ + @GET + @SelectJson("tenants") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/tenants") + @RequestFilters(AuthenticateRequest.class) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listTenants(); +} diff --git a/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceClient.java b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceClient.java new file mode 100644 index 0000000000..a09a78e3eb --- /dev/null +++ b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceClient.java @@ -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. + *

+ * + * @author Adam Lowe + * @see ServiceAsyncClient + * @see + */ +@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 listTenants(); +} \ No newline at end of file diff --git a/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java index d1a90b5d9a..70b672c5cf 100644 --- a/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java +++ b/labs/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java @@ -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 { public static final Map, Class> DELEGATE_MAP = ImmutableMap., 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() { diff --git a/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/AdminClientLiveTest.java b/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/AdminClientLiveTest.java index 28d4aee799..82ab9fc504 100644 --- a/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/AdminClientLiveTest.java +++ b/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/AdminClientLiveTest.java @@ -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; diff --git a/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/UserClientExpectTest.java b/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/UserClientExpectTest.java index d312336a19..58697da9e3 100644 --- a/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/UserClientExpectTest.java +++ b/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/UserClientExpectTest.java @@ -46,13 +46,13 @@ import com.google.common.collect.ImmutableSet; public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest { 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 tenants = client.listTenants(); assertNotNull(tenants); assertFalse(tenants.isEmpty()); diff --git a/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/UserClientLiveTest.java b/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/UserClientLiveTest.java index 3faccd1f91..9399e9c190 100644 --- a/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/UserClientLiveTest.java +++ b/labs/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/UserClientLiveTest.java @@ -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 result = keystoneContext.getApi().getUserClientForRegion(regionId).listTenants(); + Set result = keystoneContext.getApi().getServiceClientForRegion(regionId).listTenants(); assertNotNull(result); assertFalse(result.isEmpty());