From d6ac7be31dc4f131e6efea6348445e0f4410459c Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Mon, 30 Apr 2012 10:02:37 +0100 Subject: [PATCH] Adding AdminURL supplier for keystone 2.0 --- .../config/KeystoneAuthenticationModule.java | 14 ++++++ .../keystone/v2_0/functions/AdminURL.java | 44 ++++++++++++++++++ .../functions/EndpointToSupplierAdminURI.java | 28 ++++++++++++ .../functions/RegionToAdminEndpointURI.java | 16 +++++++ ...RIFromAccessForTypeAndVersionSupplier.java | 45 +++++++++++++++++++ .../suppliers/RegionIdToAdminURISupplier.java | 28 ++++++++++++ 6 files changed, 175 insertions(+) create mode 100644 common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/AdminURL.java create mode 100644 common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/EndpointToSupplierAdminURI.java create mode 100644 common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/RegionToAdminEndpointURI.java create mode 100644 common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/suppliers/RegionIdToAdminURIFromAccessForTypeAndVersionSupplier.java create mode 100644 common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/suppliers/RegionIdToAdminURISupplier.java diff --git a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java index 4730cf4efd..01c5257001 100644 --- a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java @@ -46,6 +46,8 @@ import org.jclouds.openstack.keystone.v2_0.domain.Access; import org.jclouds.openstack.keystone.v2_0.functions.AuthenticateApiAccessKeyCredentials; import org.jclouds.openstack.keystone.v2_0.functions.AuthenticatePasswordCredentials; import org.jclouds.openstack.keystone.v2_0.handlers.RetryOnRenew; +import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToAdminURIFromAccessForTypeAndVersionSupplier; +import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToAdminURISupplier; import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToURIFromAccessForTypeAndVersionSupplier; import org.jclouds.openstack.keystone.v2_0.suppliers.ZoneIdToURIFromAccessForTypeAndVersionSupplier; import org.jclouds.rest.annotations.ApiVersion; @@ -85,6 +87,8 @@ public class KeystoneAuthenticationModule extends AbstractModule { protected void configure() { install(new FactoryModuleBuilder().implement(RegionIdToURISupplier.class, RegionIdToURIFromAccessForTypeAndVersionSupplier.class).build(RegionIdToURISupplier.Factory.class)); + install(new FactoryModuleBuilder().implement(RegionIdToAdminURISupplier.class, + RegionIdToAdminURIFromAccessForTypeAndVersionSupplier.class).build(RegionIdToAdminURISupplier.Factory.class)); // dynamically build the region list as opposed to from properties bind(RegionIdsSupplier.class).to(RegionIdsFromRegionIdToURIKeySet.class); } @@ -98,6 +102,16 @@ public class KeystoneAuthenticationModule extends AbstractModule { RegionIdToURISupplier.Factory factory) { return factory.createForApiTypeAndVersion(serviceType, apiVersion); } + + // supply the region to id to AdminURL map from keystone, based on the servicetype and api version in + // config + @Provides + @Singleton + protected RegionIdToAdminURISupplier provideRegionIdToAdminURISupplierForApiVersion( + @Named(KeystoneProperties.SERVICE_TYPE) String serviceType, @ApiVersion String apiVersion, + RegionIdToAdminURISupplier.Factory factory) { + return factory.createForApiTypeAndVersion(serviceType, apiVersion); + } } diff --git a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/AdminURL.java b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/AdminURL.java new file mode 100644 index 0000000000..07a1344925 --- /dev/null +++ b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/AdminURL.java @@ -0,0 +1,44 @@ +/** + * 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.functions; + +import java.net.URI; + +import javax.inject.Singleton; + +import org.jclouds.openstack.keystone.v2_0.domain.Endpoint; + +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; + +/** + * @author Adam Lowe + */ +@Singleton +public class AdminURL implements EndpointToSupplierAdminURI { + // TODO: check accessibility and prioritize private first + @Override + public Supplier apply(Endpoint input) { + return Suppliers.ofInstance(input.getAdminURL()); + } + + public String toString() { + return "supplyAdminURL()"; + } +} \ No newline at end of file diff --git a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/EndpointToSupplierAdminURI.java b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/EndpointToSupplierAdminURI.java new file mode 100644 index 0000000000..2061a2dc11 --- /dev/null +++ b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/EndpointToSupplierAdminURI.java @@ -0,0 +1,28 @@ +/** + * 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.functions; + +import com.google.inject.ImplementedBy; + +/** + * @author Adam Lowe + */ +@ImplementedBy(AdminURL.class) +public interface EndpointToSupplierAdminURI extends EndpointToSupplierURI { +} \ No newline at end of file diff --git a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/RegionToAdminEndpointURI.java b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/RegionToAdminEndpointURI.java new file mode 100644 index 0000000000..a98bf9d87f --- /dev/null +++ b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/RegionToAdminEndpointURI.java @@ -0,0 +1,16 @@ +package org.jclouds.openstack.keystone.v2_0.functions; + +import javax.inject.Inject; + +import org.jclouds.location.functions.RegionToEndpoint; +import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToAdminURISupplier; + +/** + * @author Adam Lowe + */ +public class RegionToAdminEndpointURI extends RegionToEndpoint { + @Inject + public RegionToAdminEndpointURI(RegionIdToAdminURISupplier regionToEndpointSupplier) { + super(regionToEndpointSupplier); + } +} diff --git a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/suppliers/RegionIdToAdminURIFromAccessForTypeAndVersionSupplier.java b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/suppliers/RegionIdToAdminURIFromAccessForTypeAndVersionSupplier.java new file mode 100644 index 0000000000..74d15f5be0 --- /dev/null +++ b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/suppliers/RegionIdToAdminURIFromAccessForTypeAndVersionSupplier.java @@ -0,0 +1,45 @@ +/** + * 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.suppliers; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.openstack.keystone.v2_0.domain.Access; +import org.jclouds.openstack.keystone.v2_0.functions.EndpointToRegion; +import org.jclouds.openstack.keystone.v2_0.functions.EndpointToSupplierAdminURI; + +import com.google.common.base.Supplier; +import com.google.inject.assistedinject.Assisted; + +@Singleton +public class RegionIdToAdminURIFromAccessForTypeAndVersionSupplier extends + LocationIdToURIFromAccessForTypeAndVersionSupplier implements RegionIdToAdminURISupplier { + @Inject + public RegionIdToAdminURIFromAccessForTypeAndVersionSupplier(Supplier access, + EndpointToSupplierAdminURI endpointToSupplierURI, EndpointToRegion endpointToRegion, + @Assisted("apiType") String apiType, @Assisted("apiVersion") String apiVersion) { + super(access, endpointToSupplierURI, endpointToRegion, apiType, apiVersion); + } + + @Override + public String toString() { + return "regionIdToAdminURIFromAccessForTypeAndVersion(" + apiType + ", " + apiVersion + ")"; + } +} \ No newline at end of file diff --git a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/suppliers/RegionIdToAdminURISupplier.java b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/suppliers/RegionIdToAdminURISupplier.java new file mode 100644 index 0000000000..9f2b1c15b7 --- /dev/null +++ b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/suppliers/RegionIdToAdminURISupplier.java @@ -0,0 +1,28 @@ +package org.jclouds.openstack.keystone.v2_0.suppliers; + +import java.net.URI; +import java.util.Map; + +import com.google.common.base.Supplier; +import com.google.inject.ImplementedBy; +import com.google.inject.assistedinject.Assisted; + +/** + * @author Adam Lowe + */ +@ImplementedBy(RegionIdToAdminURIFromAccessForTypeAndVersionSupplier.class) +public interface RegionIdToAdminURISupplier extends Supplier>> { + static interface Factory { + /** + * + * @param apiType + * type of the api, according to the provider. ex. {@code compute} {@code + * object-store} + * @param apiVersion + * version of the api + * @return regions mapped to default uri + */ + RegionIdToAdminURISupplier createForApiTypeAndVersion(@Assisted("apiType") String apiType, + @Assisted("apiVersion") String apiVersion); + } +}