Skip to content
Permalink
Browse files
Use Guice multibindings to configure the aliases
  • Loading branch information
nacx committed Mar 23, 2015
1 parent 3b60945 commit 8b252a4f3487a5533ace98da14f76c8e799810ad
Showing 3 changed files with 23 additions and 23 deletions.
@@ -71,6 +71,11 @@
<artifactId>jclouds-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!-- for the extension namespaces -->
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
@@ -16,6 +16,8 @@
*/
package org.jclouds.openstack.neutron.v2.config;

import static org.jclouds.openstack.keystone.v2_0.config.KeystoneHttpApiModule.aliasBinder;

import java.net.URI;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -41,9 +43,8 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.Provides;
import com.google.inject.multibindings.MapBinder;

/**
* Configures the Neutron connection.
@@ -57,19 +58,17 @@ protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
bind(ImplicitOptionalConverter.class).to(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class);
super.configure();
bindAliases();
}

@Provides
@Singleton
public Multimap<URI, URI> aliases() {
return ImmutableMultimap.<URI, URI>builder()
.put(URI.create(ExtensionNamespaces.L3_ROUTER),
URI.create("http://docs.openstack.org/ext/neutron/router/api/v1.0"))
.put(URI.create(ExtensionNamespaces.SECURITY_GROUPS),
URI.create("http://docs.openstack.org/ext/securitygroups/api/v2.0"))
.put(URI.create(ExtensionNamespaces.LBAAS),
URI.create("http://docs.openstack.org/networking/ext/lbaas/api/v1.0"))
.build();
private void bindAliases() {
MapBinder<URI, URI> aliases = aliasBinder(binder());
aliases.addBinding(URI.create(ExtensionNamespaces.L3_ROUTER)).toInstance(
URI.create("http://docs.openstack.org/ext/neutron/router/api/v1.0"));
aliases.addBinding(URI.create(ExtensionNamespaces.SECURITY_GROUPS)).toInstance(
URI.create("http://docs.openstack.org/ext/securitygroups/api/v2.0"));
aliases.addBinding(URI.create(ExtensionNamespaces.LBAAS)).toInstance(
URI.create("http://docs.openstack.org/networking/ext/lbaas/api/v1.0"));
}

@Provides
@@ -16,11 +16,14 @@
*/
package org.jclouds.openstack.neutron.v2_0.config;

import java.net.URI;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneHttpApiModule.aliasBinder;

import java.util.Set;
import java.util.concurrent.TimeUnit;

import javax.inject.Provider;
import javax.inject.Singleton;

import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
@@ -34,11 +37,10 @@
import org.jclouds.rest.ConfiguresHttpApi;
import org.jclouds.rest.config.HttpApiModule;
import org.jclouds.rest.functions.ImplicitOptionalConverter;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.Provides;

/**
@@ -52,15 +54,9 @@ protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
bind(ImplicitOptionalConverter.class).to(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class);
super.configure();
aliasBinder(binder());
}

@Provides
@Singleton
public Multimap<URI, URI> aliases() {
return ImmutableMultimap.<URI, URI>builder()
.build();
}

@Provides
@Singleton
public LoadingCache<String, Set<? extends Extension>> provideExtensionsByZone(final Provider<NeutronApi> quantumApi) {

0 comments on commit 8b252a4

Please sign in to comment.