mirror of https://github.com/apache/jclouds.git
openstack and rackspace related changes for Issue 826
This commit is contained in:
parent
bdd739ad04
commit
e759c6a450
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudfiles.config;
|
package org.jclouds.cloudfiles.config;
|
||||||
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -34,7 +35,7 @@ import org.jclouds.http.annotation.ServerError;
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||||
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
|
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
|
||||||
import org.jclouds.openstack.keystone.v1_1.domain.Auth;
|
import org.jclouds.openstack.keystone.v1_1.functions.PublicURLFromAuthResponseForService;
|
||||||
import org.jclouds.openstack.keystone.v1_1.handlers.RetryOnRenew;
|
import org.jclouds.openstack.keystone.v1_1.handlers.RetryOnRenew;
|
||||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||||
|
@ -44,7 +45,7 @@ import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,19 +77,19 @@ public class CloudFilesRestClientModule extends RestClientModule<CloudFilesClien
|
||||||
CommonSwiftAsyncClient provideCommonSwiftClient(CloudFilesAsyncClient in) {
|
CommonSwiftAsyncClient provideCommonSwiftClient(CloudFilesAsyncClient in) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@CDNManagement
|
@CDNManagement
|
||||||
protected URI provideCDNUrl(Auth response) {
|
protected Supplier<URI> provideCDNUrl(PublicURLFromAuthResponseForService.Factory factory) {
|
||||||
return Iterables.get(response.getServiceCatalog().get("cloudFilesCDN"), 0).getPublicURL();
|
return factory.create("cloudFilesCDN");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Storage
|
@Storage
|
||||||
protected URI provideStorageUrl(Auth response) {
|
protected Supplier<URI> provideStorageUrl(PublicURLFromAuthResponseForService.Factory factory) {
|
||||||
return Iterables.get(response.getServiceCatalog().get("cloudFiles"), 0).getPublicURL();
|
return factory.create("cloudFiles");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,16 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudloadbalancers.config;
|
package org.jclouds.cloudloadbalancers.config;
|
||||||
|
|
||||||
import static com.google.common.collect.Iterables.get;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
|
|
||||||
import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient;
|
import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient;
|
||||||
import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient;
|
import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient;
|
||||||
|
@ -37,6 +32,7 @@ import org.jclouds.cloudloadbalancers.features.NodeAsyncClient;
|
||||||
import org.jclouds.cloudloadbalancers.features.NodeClient;
|
import org.jclouds.cloudloadbalancers.features.NodeClient;
|
||||||
import org.jclouds.cloudloadbalancers.functions.ConvertLB;
|
import org.jclouds.cloudloadbalancers.functions.ConvertLB;
|
||||||
import org.jclouds.cloudloadbalancers.handlers.ParseCloudLoadBalancersErrorFromHttpResponse;
|
import org.jclouds.cloudloadbalancers.handlers.ParseCloudLoadBalancersErrorFromHttpResponse;
|
||||||
|
import org.jclouds.cloudloadbalancers.location.RegionUrisFromPropertiesAndAccountIDPathSuffix;
|
||||||
import org.jclouds.cloudloadbalancers.reference.RackspaceConstants;
|
import org.jclouds.cloudloadbalancers.reference.RackspaceConstants;
|
||||||
import org.jclouds.http.HttpErrorHandler;
|
import org.jclouds.http.HttpErrorHandler;
|
||||||
import org.jclouds.http.HttpRetryHandler;
|
import org.jclouds.http.HttpRetryHandler;
|
||||||
|
@ -44,25 +40,20 @@ import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.http.annotation.ClientError;
|
import org.jclouds.http.annotation.ClientError;
|
||||||
import org.jclouds.http.annotation.Redirection;
|
import org.jclouds.http.annotation.Redirection;
|
||||||
import org.jclouds.http.annotation.ServerError;
|
import org.jclouds.http.annotation.ServerError;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||||
import org.jclouds.location.Provider;
|
|
||||||
import org.jclouds.location.Region;
|
import org.jclouds.location.Region;
|
||||||
import org.jclouds.location.config.ProvideRegionToURIViaProperties;
|
import org.jclouds.location.suppliers.RegionIdToURISupplier;
|
||||||
import org.jclouds.logging.Logger.LoggerFactory;
|
|
||||||
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
|
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
|
||||||
import org.jclouds.openstack.keystone.v1_1.domain.Auth;
|
import org.jclouds.openstack.keystone.v1_1.functions.PublicURLFromAuthResponseForService;
|
||||||
import org.jclouds.openstack.keystone.v1_1.handlers.RetryOnRenew;
|
import org.jclouds.openstack.keystone.v1_1.handlers.RetryOnRenew;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableBiMap;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
@ -93,37 +84,13 @@ public class CloudLoadBalancersRestClientModule extends
|
||||||
public CloudLoadBalancersRestClientModule() {
|
public CloudLoadBalancersRestClientModule() {
|
||||||
this(new AuthenticationServiceModule());
|
this(new AuthenticationServiceModule());
|
||||||
}
|
}
|
||||||
protected void bindRegionsToProvider() {
|
|
||||||
bindRegionsToProvider(RegionUrisFromPropertiesAndAccountIDPathSuffix.class);
|
@Override
|
||||||
|
protected void installLocations() {
|
||||||
|
super.installLocations();
|
||||||
|
bind(RegionIdToURISupplier.class).to(RegionUrisFromPropertiesAndAccountIDPathSuffix.class).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class RegionUrisFromPropertiesAndAccountIDPathSuffix extends ProvideRegionToURIViaProperties {
|
|
||||||
|
|
||||||
private final String accountID;
|
|
||||||
private final javax.inject.Provider<UriBuilder> builders;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected RegionUrisFromPropertiesAndAccountIDPathSuffix(Injector injector,
|
|
||||||
javax.inject.Provider<UriBuilder> builders, @Named(RackspaceConstants.PROPERTY_ACCOUNT_ID) String accountID) {
|
|
||||||
super(injector);
|
|
||||||
this.builders = builders;
|
|
||||||
this.accountID = accountID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, URI> get() {
|
|
||||||
return Maps.transformValues(super.get(), new Function<URI, URI>(){
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public URI apply(URI input) {
|
|
||||||
return builders.get().uri(input).path(accountID).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void bindRegionsToProvider(Class<? extends javax.inject.Provider<Map<String, URI>>> providerClass) {
|
protected void bindRegionsToProvider(Class<? extends javax.inject.Provider<Map<String, URI>>> providerClass) {
|
||||||
bind(new TypeLiteral<Map<String, URI>>() {
|
bind(new TypeLiteral<Map<String, URI>>() {
|
||||||
}).annotatedWith(Region.class).toProvider(providerClass).in(Scopes.SINGLETON);
|
}).annotatedWith(Region.class).toProvider(providerClass).in(Scopes.SINGLETON);
|
||||||
|
@ -133,7 +100,6 @@ public class CloudLoadBalancersRestClientModule extends
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(module);
|
install(module);
|
||||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||||
bindRegionsToProvider();
|
|
||||||
install(new FactoryModuleBuilder().build(ConvertLB.Factory.class));
|
install(new FactoryModuleBuilder().build(ConvertLB.Factory.class));
|
||||||
super.configure();
|
super.configure();
|
||||||
}
|
}
|
||||||
|
@ -141,30 +107,20 @@ public class CloudLoadBalancersRestClientModule extends
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named(RackspaceConstants.PROPERTY_ACCOUNT_ID)
|
@Named(RackspaceConstants.PROPERTY_ACCOUNT_ID)
|
||||||
protected String accountID(Auth response) {
|
protected Supplier<String> accountID(PublicURLFromAuthResponseForService.Factory factory) {
|
||||||
URI serverURL = Iterables.get(response.getServiceCatalog().get("cloudServers"), 0).getPublicURL();
|
return Suppliers.compose(new Function<URI, String>() {
|
||||||
return serverURL.getPath().substring(serverURL.getPath().lastIndexOf('/') + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Override
|
||||||
@Singleton
|
public String apply(URI arg0) {
|
||||||
@Region
|
return arg0.getPath().substring(arg0.getPath().lastIndexOf('/') + 1);
|
||||||
public Set<String> regions(@Region Map<String, URI> endpoints) {
|
}
|
||||||
return endpoints.keySet();
|
|
||||||
}
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "getAccountIdFromCloudServers()";
|
||||||
|
}
|
||||||
|
}, factory.create("cloudServers"));
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Nullable
|
|
||||||
@Region
|
|
||||||
protected String getDefaultRegion(@Provider URI uri, @Region Map<String, URI> map, LoggerFactory logFactory) {
|
|
||||||
String region = ImmutableBiMap.copyOf(map).inverse().get(uri);
|
|
||||||
if (region == null && map.size() > 0) {
|
|
||||||
logFactory.getLogger(getClass().getName()).warn(
|
|
||||||
"failed to find region for current endpoint %s in %s; choosing first: %s", uri, map, region);
|
|
||||||
region = get(map.keySet(), 0);
|
|
||||||
}
|
|
||||||
return region;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -181,4 +137,5 @@ public class CloudLoadBalancersRestClientModule extends
|
||||||
protected void bindRetryHandlers() {
|
protected void bindRetryHandlers() {
|
||||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
* 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.cloudloadbalancers.functions;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
|
import org.jclouds.cloudloadbalancers.reference.RackspaceConstants;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public final class AppendAccountIdToURI implements Function<Supplier<URI>, Supplier<URI>> {
|
||||||
|
|
||||||
|
private final Supplier<String> accountID;
|
||||||
|
private final javax.inject.Provider<UriBuilder> builders;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public AppendAccountIdToURI(javax.inject.Provider<UriBuilder> builders,
|
||||||
|
@Named(RackspaceConstants.PROPERTY_ACCOUNT_ID) Supplier<String> accountID) {
|
||||||
|
this.accountID = accountID;
|
||||||
|
this.builders = builders;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<URI> apply(final Supplier<URI> input) {
|
||||||
|
return new Supplier<URI>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URI get() {
|
||||||
|
return builders.get().uri(input.get()).path(accountID.get()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "appendAccountId()";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,7 +30,6 @@ public class CloudLoadBalancersLoadBalancerContextModule extends BaseLoadBalance
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new CloudLoadBalancersBindLoadBalancerSuppliersByClass());
|
|
||||||
install(new CloudLoadBalancersBindLoadBalancerStrategiesByClass());
|
install(new CloudLoadBalancersBindLoadBalancerStrategiesByClass());
|
||||||
install(new CloudLoadBalancersLoadBalancerServiceDependenciesModule());
|
install(new CloudLoadBalancersLoadBalancerServiceDependenciesModule());
|
||||||
super.configure();
|
super.configure();
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
@ -43,6 +42,7 @@ import org.jclouds.location.Region;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,12 +58,12 @@ public class CloudLoadBalancersListLoadBalancersStrategy implements ListLoadBala
|
||||||
private final CloudLoadBalancersAsyncClient aclient;
|
private final CloudLoadBalancersAsyncClient aclient;
|
||||||
private final Function<LoadBalancer, LoadBalancerMetadata> converter;
|
private final Function<LoadBalancer, LoadBalancerMetadata> converter;
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
private final Set<String> regions;
|
private final Supplier<Set<String>> regions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected CloudLoadBalancersListLoadBalancersStrategy(CloudLoadBalancersAsyncClient aclient,
|
protected CloudLoadBalancersListLoadBalancersStrategy(CloudLoadBalancersAsyncClient aclient,
|
||||||
Function<LoadBalancer, LoadBalancerMetadata> converter,
|
Function<LoadBalancer, LoadBalancerMetadata> converter,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Nullable @Region Set<String> regions) {
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Region Supplier<Set<String>> regions) {
|
||||||
this.aclient = checkNotNull(aclient, "aclient");
|
this.aclient = checkNotNull(aclient, "aclient");
|
||||||
this.regions = checkNotNull(regions, "regions");
|
this.regions = checkNotNull(regions, "regions");
|
||||||
this.converter = checkNotNull(converter, "converter");
|
this.converter = checkNotNull(converter, "converter");
|
||||||
|
@ -72,7 +72,7 @@ public class CloudLoadBalancersListLoadBalancersStrategy implements ListLoadBala
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
|
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
|
||||||
return transform(concat(transformParallel(regions, new Function<String, Future<Set<LoadBalancer>>>() {
|
return transform(concat(transformParallel(regions.get(), new Function<String, Future<Set<LoadBalancer>>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Set<LoadBalancer>> apply(String from) {
|
public ListenableFuture<Set<LoadBalancer>> apply(String from) {
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
* 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.cloudloadbalancers.location;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.cloudloadbalancers.functions.AppendAccountIdToURI;
|
||||||
|
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||||
|
import org.jclouds.location.Provider;
|
||||||
|
import org.jclouds.location.Region;
|
||||||
|
import org.jclouds.location.suppliers.fromconfig.RegionIdToURIFromConfigurationOrDefaultToProvider;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class RegionUrisFromPropertiesAndAccountIDPathSuffix extends RegionIdToURIFromConfigurationOrDefaultToProvider {
|
||||||
|
|
||||||
|
private AppendAccountIdToURI filter;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected RegionUrisFromPropertiesAndAccountIDPathSuffix(ValueOfConfigurationKeyOrNull config,
|
||||||
|
@Provider Supplier<URI> providerURI, @Region Supplier<Set<String>> regionIds, AppendAccountIdToURI filter) {
|
||||||
|
super(config, providerURI, regionIds);
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Supplier<URI>> get() {
|
||||||
|
return Maps.transformValues(super.get(), filter);
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ import org.jclouds.compute.domain.OperatingSystem;
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.functions.IdentityFunction;
|
import org.jclouds.functions.IdentityFunction;
|
||||||
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
|
import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -85,13 +85,9 @@ public class CloudServersComputeServiceContextModule
|
||||||
// we aren't converting location from a provider-specific type
|
// we aren't converting location from a provider-specific type
|
||||||
bind(new TypeLiteral<Function<Location, Location>>() {
|
bind(new TypeLiteral<Function<Location, Location>>() {
|
||||||
}).to((Class) IdentityFunction.class);
|
}).to((Class) IdentityFunction.class);
|
||||||
|
|
||||||
// there are no locations except the provider
|
|
||||||
bind(new TypeLiteral<Supplier<Location>>() {
|
|
||||||
}).to(OnlyLocationOrFirstZone.class);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap
|
public static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap
|
||||||
.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
||||||
|
@ -125,4 +121,5 @@ public class CloudServersComputeServiceContextModule
|
||||||
return serverToNodeState;
|
return serverToNodeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@ import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LoginCredentials;
|
import org.jclouds.domain.LoginCredentials;
|
||||||
import org.jclouds.location.suppliers.JustProvider;
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defines the connection between the {@link CloudServersClient} implementation and the jclouds
|
* defines the connection between the {@link CloudServersClient} implementation and the jclouds
|
||||||
|
@ -47,13 +48,10 @@ import org.jclouds.location.suppliers.JustProvider;
|
||||||
public class CloudServersComputeServiceAdapter implements ComputeServiceAdapter<Server, Flavor, Image, Location> {
|
public class CloudServersComputeServiceAdapter implements ComputeServiceAdapter<Server, Flavor, Image, Location> {
|
||||||
|
|
||||||
protected final CloudServersClient client;
|
protected final CloudServersClient client;
|
||||||
protected final JustProvider locationSupplier;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected CloudServersComputeServiceAdapter(CloudServersClient client, JustProvider locationSupplier) {
|
protected CloudServersComputeServiceAdapter(CloudServersClient client) {
|
||||||
this.client = checkNotNull(client, "client");
|
this.client = checkNotNull(client, "client");
|
||||||
this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,10 +81,10 @@ public class CloudServersComputeServiceAdapter implements ComputeServiceAdapter<
|
||||||
return client.listServers(ListOptions.Builder.withDetails());
|
return client.listServers(ListOptions.Builder.withDetails());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Location> listLocations() {
|
public Iterable<Location> listLocations() {
|
||||||
return (Iterable<Location>) locationSupplier.get();
|
// Not using the adapter to determine locations
|
||||||
|
return ImmutableSet.<Location>of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,14 +39,13 @@ import org.jclouds.http.annotation.ServerError;
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||||
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
|
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
|
||||||
import org.jclouds.openstack.keystone.v1_1.domain.Auth;
|
import org.jclouds.openstack.keystone.v1_1.functions.PublicURLFromAuthResponseForService;
|
||||||
import org.jclouds.openstack.keystone.v1_1.handlers.RetryOnRenew;
|
import org.jclouds.openstack.keystone.v1_1.handlers.RetryOnRenew;
|
||||||
import org.jclouds.openstack.services.Compute;
|
import org.jclouds.openstack.services.Compute;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,10 +89,10 @@ public class CloudServersRestClientModule extends RestClientModule<CloudServersC
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Compute
|
@Compute
|
||||||
protected URI provideServerUrl(Auth response) {
|
protected Supplier<URI> provideServerUrl(PublicURLFromAuthResponseForService.Factory factory) {
|
||||||
return Iterables.get(response.getServiceCatalog().get("cloudServers"), 0).getPublicURL();
|
return factory.create("cloudServers");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: see if we still need this.
|
//TODO: see if we still need this.
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
|
|
@ -31,7 +31,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -96,7 +95,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
createServerOptionsVarargsClass);
|
createServerOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1);
|
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}",
|
assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}",
|
||||||
"application/json", false);
|
"application/json", false);
|
||||||
|
@ -114,7 +113,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
createServerOptionsVarargsClass);
|
createServerOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1, withSharedIpGroup(2));
|
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1, withSharedIpGroup(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request,
|
assertPayloadEquals(request,
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
|
||||||
|
@ -133,7 +132,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor
|
HttpRequest request = processor
|
||||||
.createRequest(method, "ralphie", 2, 1, withFile("/etc/jclouds", "foo".getBytes()));
|
.createRequest(method, "ralphie", 2, 1, withFile("/etc/jclouds", "foo".getBytes()));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
request,
|
||||||
|
@ -154,7 +153,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1,
|
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1,
|
||||||
withMetadata(ImmutableMap.of("foo", "bar")));
|
withMetadata(ImmutableMap.of("foo", "bar")));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request,
|
assertPayloadEquals(request,
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
|
||||||
|
@ -175,7 +174,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1,
|
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1,
|
||||||
withSharedIpGroup(2).withSharedIp("127.0.0.1"));
|
withSharedIpGroup(2).withSharedIp("127.0.0.1"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
request,
|
||||||
|
@ -193,7 +192,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("deleteImage", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("deleteImage", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE http://serverManagementUrl/images/2 HTTP/1.1");
|
assertRequestLineEquals(request, "DELETE https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -208,7 +207,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("getLimits");
|
Method method = CloudServersAsyncClient.class.getMethod("getLimits");
|
||||||
HttpRequest request = processor.createRequest(method);
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/limits?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/limits?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -223,7 +222,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listServers", listOptionsVarargsClass);
|
Method method = CloudServersAsyncClient.class.getMethod("listServers", listOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method);
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/servers?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -241,7 +240,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
|
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET http://serverManagementUrl/servers?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
"GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -256,7 +255,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listServers", listOptionsVarargsClass);
|
Method method = CloudServersAsyncClient.class.getMethod("listServers", listOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, withDetails());
|
HttpRequest request = processor.createRequest(method, withDetails());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/servers/detail?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/detail?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -271,7 +270,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("getServer", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("getServer", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/servers/2?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -286,7 +285,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listFlavors", listOptionsVarargsClass);
|
Method method = CloudServersAsyncClient.class.getMethod("listFlavors", listOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method);
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/flavors?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/flavors?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -302,7 +301,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
|
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET http://serverManagementUrl/flavors?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
"GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/flavors?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -317,7 +316,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listFlavors", listOptionsVarargsClass);
|
Method method = CloudServersAsyncClient.class.getMethod("listFlavors", listOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, withDetails());
|
HttpRequest request = processor.createRequest(method, withDetails());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/flavors/detail?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/flavors/detail?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -333,7 +332,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, withDetails().changesSince(now).maxResults(1).startAt(2));
|
HttpRequest request = processor.createRequest(method, withDetails().changesSince(now).maxResults(1).startAt(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET http://serverManagementUrl/flavors/detail?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
"GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/flavors/detail?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -348,7 +347,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("getFlavor", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("getFlavor", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/flavors/2?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/flavors/2?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -363,7 +362,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listImages", listOptionsVarargsClass);
|
Method method = CloudServersAsyncClient.class.getMethod("listImages", listOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method);
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/images?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -378,7 +377,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listImages", listOptionsVarargsClass);
|
Method method = CloudServersAsyncClient.class.getMethod("listImages", listOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, withDetails());
|
HttpRequest request = processor.createRequest(method, withDetails());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/images/detail?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/detail?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -394,7 +393,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
|
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET http://serverManagementUrl/images?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
"GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -410,7 +409,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, withDetails().changesSince(now).maxResults(1).startAt(2));
|
HttpRequest request = processor.createRequest(method, withDetails().changesSince(now).maxResults(1).startAt(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET http://serverManagementUrl/images/detail?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
"GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/detail?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -425,7 +424,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("getImage", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("getImage", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/images/2?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/2?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -440,7 +439,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("deleteServer", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("deleteServer", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE http://serverManagementUrl/servers/2 HTTP/1.1");
|
assertRequestLineEquals(request, "DELETE https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -456,7 +455,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
boolean.class);
|
boolean.class);
|
||||||
HttpRequest request = processor.createRequest(method, "127.0.0.1", 2, 3, false);
|
HttpRequest request = processor.createRequest(method, "127.0.0.1", 2, 3, false);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT http://serverManagementUrl/servers/2/ips/public/127.0.0.1 HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/ips/public/127.0.0.1 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"shareIp\":{\"sharedIpGroupId\":3,\"configureServer\":false}}",
|
assertPayloadEquals(request, "{\"shareIp\":{\"sharedIpGroupId\":3,\"configureServer\":false}}",
|
||||||
MediaType.APPLICATION_JSON, false);
|
MediaType.APPLICATION_JSON, false);
|
||||||
|
@ -474,7 +473,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
boolean.class);
|
boolean.class);
|
||||||
HttpRequest request = processor.createRequest(method, "127.0.0.1", 2, 3, true);
|
HttpRequest request = processor.createRequest(method, "127.0.0.1", 2, 3, true);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT http://serverManagementUrl/servers/2/ips/public/127.0.0.1 HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/ips/public/127.0.0.1 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"shareIp\":{\"sharedIpGroupId\":3,\"configureServer\":true}}",
|
assertPayloadEquals(request, "{\"shareIp\":{\"sharedIpGroupId\":3,\"configureServer\":true}}",
|
||||||
MediaType.APPLICATION_JSON, false);
|
MediaType.APPLICATION_JSON, false);
|
||||||
|
@ -492,7 +491,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("unshareIp", String.class, int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("unshareIp", String.class, int.class);
|
||||||
HttpRequest request = processor.createRequest(method, "127.0.0.1", 2, 3, false);
|
HttpRequest request = processor.createRequest(method, "127.0.0.1", 2, 3, false);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE http://serverManagementUrl/servers/2/ips/public/127.0.0.1 HTTP/1.1");
|
assertRequestLineEquals(request, "DELETE https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/ips/public/127.0.0.1 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -509,7 +508,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, 2, new BackupSchedule(WeeklyBackup.MONDAY,
|
HttpRequest request = processor.createRequest(method, 2, new BackupSchedule(WeeklyBackup.MONDAY,
|
||||||
DailyBackup.H_0800_1000, true));
|
DailyBackup.H_0800_1000, true));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers/2/backup_schedule HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/backup_schedule HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request,
|
assertPayloadEquals(request,
|
||||||
"{\"backupSchedule\":{\"daily\":\"H_0800_1000\",\"enabled\":true,\"weekly\":\"MONDAY\"}}",
|
"{\"backupSchedule\":{\"daily\":\"H_0800_1000\",\"enabled\":true,\"weekly\":\"MONDAY\"}}",
|
||||||
|
@ -527,7 +526,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("deleteBackupSchedule", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("deleteBackupSchedule", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE http://serverManagementUrl/servers/2/backup_schedule HTTP/1.1");
|
assertRequestLineEquals(request, "DELETE https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/backup_schedule HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, null, MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, null, MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -543,7 +542,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("changeAdminPass", int.class, String.class);
|
Method method = CloudServersAsyncClient.class.getMethod("changeAdminPass", int.class, String.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2, "foo");
|
HttpRequest request = processor.createRequest(method, 2, "foo");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT http://serverManagementUrl/servers/2 HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"server\":{\"adminPass\":\"foo\"}}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"server\":{\"adminPass\":\"foo\"}}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -559,7 +558,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("renameServer", int.class, String.class);
|
Method method = CloudServersAsyncClient.class.getMethod("renameServer", int.class, String.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2, "foo");
|
HttpRequest request = processor.createRequest(method, 2, "foo");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT http://serverManagementUrl/servers/2 HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"server\":{\"name\":\"foo\"}}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"server\":{\"name\":\"foo\"}}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -575,7 +574,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listSharedIpGroups", listOptionsVarargsClass);
|
Method method = CloudServersAsyncClient.class.getMethod("listSharedIpGroups", listOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method);
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/shared_ip_groups?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/shared_ip_groups?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -591,7 +590,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
|
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET http://serverManagementUrl/shared_ip_groups?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
"GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/shared_ip_groups?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -606,7 +605,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listSharedIpGroups", listOptionsVarargsClass);
|
Method method = CloudServersAsyncClient.class.getMethod("listSharedIpGroups", listOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, withDetails());
|
HttpRequest request = processor.createRequest(method, withDetails());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/shared_ip_groups/detail?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/shared_ip_groups/detail?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -622,7 +621,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
HttpRequest request = processor.createRequest(method, withDetails().changesSince(now).maxResults(1).startAt(2));
|
HttpRequest request = processor.createRequest(method, withDetails().changesSince(now).maxResults(1).startAt(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET http://serverManagementUrl/shared_ip_groups/detail?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
"GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/shared_ip_groups/detail?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -637,7 +636,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("getSharedIpGroup", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("getSharedIpGroup", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/shared_ip_groups/2?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/shared_ip_groups/2?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -656,7 +655,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
createSharedIpGroupOptionsVarargsClass);
|
createSharedIpGroupOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, "ralphie");
|
HttpRequest request = processor.createRequest(method, "ralphie");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/shared_ip_groups?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/shared_ip_groups?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, "{\"sharedIpGroup\":{\"name\":\"ralphie\"}}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"sharedIpGroup\":{\"name\":\"ralphie\"}}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -673,7 +672,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
createSharedIpGroupOptionsVarargsClass);
|
createSharedIpGroupOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, "ralphie", withServer(2));
|
HttpRequest request = processor.createRequest(method, "ralphie", withServer(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/shared_ip_groups?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/shared_ip_groups?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, "{\"sharedIpGroup\":{\"name\":\"ralphie\",\"server\":2}}",
|
assertPayloadEquals(request, "{\"sharedIpGroup\":{\"name\":\"ralphie\",\"server\":2}}",
|
||||||
MediaType.APPLICATION_JSON, false);
|
MediaType.APPLICATION_JSON, false);
|
||||||
|
@ -689,7 +688,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("deleteSharedIpGroup", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("deleteSharedIpGroup", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE http://serverManagementUrl/shared_ip_groups/2 HTTP/1.1");
|
assertRequestLineEquals(request, "DELETE https://lon.servers.api.rackspacecloud.com/v1.0/10001786/shared_ip_groups/2 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -704,7 +703,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("getAddresses", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("getAddresses", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/servers/2/ips?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/ips?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -719,7 +718,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listPublicAddresses", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("listPublicAddresses", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/servers/2/ips/public?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/ips/public?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -734,7 +733,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("listPrivateAddresses", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("listPrivateAddresses", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/servers/2/ips/private?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/ips/private?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -749,7 +748,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("getBackupSchedule", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("getBackupSchedule", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://serverManagementUrl/servers/2/backup_schedule?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/backup_schedule?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
@ -764,7 +763,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("createImageFromServer", String.class, int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("createImageFromServer", String.class, int.class);
|
||||||
HttpRequest request = processor.createRequest(method, "ralphie", 2);
|
HttpRequest request = processor.createRequest(method, "ralphie", 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/images?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||||
assertPayloadEquals(request, "{\"image\":{\"serverId\":2,\"name\":\"ralphie\"}}", MediaType.APPLICATION_JSON,
|
assertPayloadEquals(request, "{\"image\":{\"serverId\":2,\"name\":\"ralphie\"}}", MediaType.APPLICATION_JSON,
|
||||||
false);
|
false);
|
||||||
|
@ -785,7 +784,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
rebuildServerOptionsVarargsClass);
|
rebuildServerOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, 3);
|
HttpRequest request = processor.createRequest(method, 3);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers/3/action?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/3/action?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"rebuild\":{}}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"rebuild\":{}}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -801,7 +800,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
rebuildServerOptionsVarargsClass);
|
rebuildServerOptionsVarargsClass);
|
||||||
HttpRequest request = processor.createRequest(method, 3, withImage(2));
|
HttpRequest request = processor.createRequest(method, 3, withImage(2));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers/3/action?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/3/action?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"rebuild\":{\"imageId\":2}}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"rebuild\":{\"imageId\":2}}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -816,7 +815,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("rebootServer", int.class, RebootType.class);
|
Method method = CloudServersAsyncClient.class.getMethod("rebootServer", int.class, RebootType.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2, RebootType.HARD);
|
HttpRequest request = processor.createRequest(method, 2, RebootType.HARD);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers/2/action?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/action?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"reboot\":{\"type\":\"HARD\"}}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"reboot\":{\"type\":\"HARD\"}}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -831,7 +830,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("resizeServer", int.class, int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("resizeServer", int.class, int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2, 3);
|
HttpRequest request = processor.createRequest(method, 2, 3);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers/2/action?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/action?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"resize\":{\"flavorId\":3}}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"resize\":{\"flavorId\":3}}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -847,7 +846,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("confirmResizeServer", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("confirmResizeServer", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers/2/action?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/action?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"confirmResize\":null}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"confirmResize\":null}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -862,7 +861,7 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
Method method = CloudServersAsyncClient.class.getMethod("revertResizeServer", int.class);
|
Method method = CloudServersAsyncClient.class.getMethod("revertResizeServer", int.class);
|
||||||
HttpRequest request = processor.createRequest(method, 2);
|
HttpRequest request = processor.createRequest(method, 2);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://serverManagementUrl/servers/2/action?format=json HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://lon.servers.api.rackspacecloud.com/v1.0/10001786/servers/2/action?format=json HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "{\"revertResize\":null}", MediaType.APPLICATION_JSON, false);
|
assertPayloadEquals(request, "{\"revertResize\":null}", MediaType.APPLICATION_JSON, false);
|
||||||
|
|
||||||
|
@ -910,11 +909,6 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected URI provideServerUrl(Auth response) {
|
|
||||||
return URI.create("http://serverManagementUrl");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String provider = "cloudservers";
|
protected String provider = "cloudservers";
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.compute.domain.OperatingSystem;
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.functions.IdentityFunction;
|
import org.jclouds.functions.IdentityFunction;
|
||||||
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
|
|
||||||
import org.jclouds.openstack.nova.NovaAsyncClient;
|
import org.jclouds.openstack.nova.NovaAsyncClient;
|
||||||
import org.jclouds.openstack.nova.NovaClient;
|
import org.jclouds.openstack.nova.NovaClient;
|
||||||
import org.jclouds.openstack.nova.compute.functions.FlavorToHardware;
|
import org.jclouds.openstack.nova.compute.functions.FlavorToHardware;
|
||||||
|
@ -46,7 +45,6 @@ import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
@ -85,12 +83,8 @@ public class NovaComputeServiceContextModule
|
||||||
bind(new TypeLiteral<Function<Location, Location>>() {
|
bind(new TypeLiteral<Function<Location, Location>>() {
|
||||||
}).to((Class) IdentityFunction.class);
|
}).to((Class) IdentityFunction.class);
|
||||||
|
|
||||||
// there are no locations except the provider
|
|
||||||
bind(new TypeLiteral<Supplier<Location>>() {
|
|
||||||
}).to(OnlyLocationOrFirstZone.class);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap
|
public static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap
|
||||||
.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
||||||
|
|
|
@ -25,18 +25,19 @@ import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeService;
|
||||||
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.domain.LoginCredentials;
|
||||||
import org.jclouds.openstack.nova.NovaClient;
|
import org.jclouds.openstack.nova.NovaClient;
|
||||||
import org.jclouds.openstack.nova.domain.Flavor;
|
import org.jclouds.openstack.nova.domain.Flavor;
|
||||||
import org.jclouds.openstack.nova.domain.Image;
|
import org.jclouds.openstack.nova.domain.Image;
|
||||||
import org.jclouds.openstack.nova.domain.RebootType;
|
import org.jclouds.openstack.nova.domain.RebootType;
|
||||||
import org.jclouds.openstack.nova.domain.Server;
|
import org.jclouds.openstack.nova.domain.Server;
|
||||||
import org.jclouds.openstack.nova.options.ListOptions;
|
import org.jclouds.openstack.nova.options.ListOptions;
|
||||||
import org.jclouds.compute.ComputeService;
|
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.jclouds.compute.domain.Template;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.domain.LoginCredentials;
|
|
||||||
import org.jclouds.location.suppliers.JustProvider;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defines the connection between the {@link NovaClient} implementation and the jclouds
|
* defines the connection between the {@link NovaClient} implementation and the jclouds
|
||||||
|
@ -47,13 +48,10 @@ import org.jclouds.location.suppliers.JustProvider;
|
||||||
public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server, Flavor, Image, Location> {
|
public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server, Flavor, Image, Location> {
|
||||||
|
|
||||||
protected final NovaClient client;
|
protected final NovaClient client;
|
||||||
protected final JustProvider locationSupplier;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected NovaComputeServiceAdapter(NovaClient client, JustProvider locationSupplier) {
|
protected NovaComputeServiceAdapter(NovaClient client) {
|
||||||
this.client = checkNotNull(client, "client");
|
this.client = checkNotNull(client, "client");
|
||||||
this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,10 +80,10 @@ public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server,
|
||||||
return client.listServers(ListOptions.Builder.withDetails());
|
return client.listServers(ListOptions.Builder.withDetails());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Location> listLocations() {
|
public Iterable<Location> listLocations() {
|
||||||
return (Iterable<Location>) locationSupplier.get();
|
// Not using the adapter to determine locations
|
||||||
|
return ImmutableSet.<Location>of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,10 +22,6 @@ import java.net.URI;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.openstack.nova.NovaAsyncClient;
|
|
||||||
import org.jclouds.openstack.nova.NovaClient;
|
|
||||||
import org.jclouds.openstack.nova.ServerManagement;
|
|
||||||
import org.jclouds.openstack.nova.handlers.ParseNovaErrorFromHttpResponse;
|
|
||||||
import org.jclouds.http.HttpErrorHandler;
|
import org.jclouds.http.HttpErrorHandler;
|
||||||
import org.jclouds.http.HttpRetryHandler;
|
import org.jclouds.http.HttpRetryHandler;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
|
@ -34,13 +30,18 @@ import org.jclouds.http.annotation.Redirection;
|
||||||
import org.jclouds.http.annotation.ServerError;
|
import org.jclouds.http.annotation.ServerError;
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
|
||||||
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
|
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
|
||||||
|
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
|
||||||
import org.jclouds.openstack.handlers.RetryOnRenew;
|
import org.jclouds.openstack.handlers.RetryOnRenew;
|
||||||
|
import org.jclouds.openstack.nova.NovaAsyncClient;
|
||||||
|
import org.jclouds.openstack.nova.NovaClient;
|
||||||
|
import org.jclouds.openstack.nova.ServerManagement;
|
||||||
|
import org.jclouds.openstack.nova.handlers.ParseNovaErrorFromHttpResponse;
|
||||||
import org.jclouds.openstack.reference.AuthHeaders;
|
import org.jclouds.openstack.reference.AuthHeaders;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,12 +81,11 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
|
||||||
protected void bindRetryHandlers() {
|
protected void bindRetryHandlers() {
|
||||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@ServerManagement
|
@ServerManagement
|
||||||
protected URI provideServerUrl(AuthenticationResponse response) {
|
protected Supplier<URI> provideServerUrl(URIFromAuthenticationResponseForService.Factory factory) {
|
||||||
return response.getServices().get(AuthHeaders.SERVER_MANAGEMENT_URL);
|
return factory.create(AuthHeaders.SERVER_MANAGEMENT_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -39,7 +38,6 @@ import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
|
||||||
import org.jclouds.openstack.TestOpenStackAuthenticationModule;
|
import org.jclouds.openstack.TestOpenStackAuthenticationModule;
|
||||||
import org.jclouds.openstack.filters.AddTimestampQuery;
|
import org.jclouds.openstack.filters.AddTimestampQuery;
|
||||||
import org.jclouds.openstack.filters.AuthenticateRequest;
|
import org.jclouds.openstack.filters.AuthenticateRequest;
|
||||||
|
@ -777,11 +775,6 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
||||||
super(new TestOpenStackAuthenticationModule());
|
super(new TestOpenStackAuthenticationModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected URI provideServerUrl(AuthenticationResponse response) {
|
|
||||||
return URI.create("http://endpoint/vapi-version");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String provider = "nova";
|
protected String provider = "nova";
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.location.config.JustProviderLocationModule;
|
|
||||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||||
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
|
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
|
||||||
|
@ -47,7 +46,6 @@ public class SwiftBlobStoreContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
install(new JustProviderLocationModule());
|
|
||||||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
bind(AsyncBlobStore.class).to(SwiftAsyncBlobStore.class).in(Scopes.SINGLETON);
|
bind(AsyncBlobStore.class).to(SwiftAsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||||
bind(BlobStore.class).to(SwiftBlobStore.class).in(Scopes.SINGLETON);
|
bind(BlobStore.class).to(SwiftBlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
|
|
@ -30,8 +30,8 @@ import org.jclouds.http.annotation.Redirection;
|
||||||
import org.jclouds.http.annotation.ServerError;
|
import org.jclouds.http.annotation.ServerError;
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
|
||||||
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
|
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
|
||||||
|
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
|
||||||
import org.jclouds.openstack.handlers.RetryOnRenew;
|
import org.jclouds.openstack.handlers.RetryOnRenew;
|
||||||
import org.jclouds.openstack.reference.AuthHeaders;
|
import org.jclouds.openstack.reference.AuthHeaders;
|
||||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||||
|
@ -41,6 +41,7 @@ import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,11 +83,11 @@ public class BaseSwiftRestClientModule<S extends CommonSwiftClient, A extends Co
|
||||||
protected void bindRetryHandlers() {
|
protected void bindRetryHandlers() {
|
||||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Storage
|
@Storage
|
||||||
protected URI provideStorageUrl(AuthenticationResponse response) {
|
protected Supplier<URI> provideStorageUrl(URIFromAuthenticationResponseForService.Factory factory) {
|
||||||
return response.getServices().get(AuthHeaders.STORAGE_URL);
|
return factory.create(AuthHeaders.STORAGE_URL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.swift.config;
|
package org.jclouds.openstack.swift.config;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
|
||||||
import org.jclouds.openstack.reference.AuthHeaders;
|
|
||||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||||
import org.jclouds.openstack.swift.SwiftAsyncClient;
|
import org.jclouds.openstack.swift.SwiftAsyncClient;
|
||||||
|
@ -57,7 +53,4 @@ public class SwiftRestClientModule extends BaseSwiftRestClientModule<SwiftClient
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected URI provideStorageUrl(AuthenticationResponse response) {
|
|
||||||
return response.getServices().get(AuthHeaders.STORAGE_URL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import javax.ws.rs.core.UriBuilder;
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
|
@ -22,15 +22,11 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.openstack.TestOpenStackAuthenticationModule;
|
import org.jclouds.openstack.TestOpenStackAuthenticationModule;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
|
||||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
|
||||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
|
||||||
import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule;
|
import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
|
@ -65,12 +61,6 @@ public abstract class CommonSwiftClientTest<A extends CommonSwiftAsyncClient> ex
|
||||||
private TestSwiftRestClientModule() {
|
private TestSwiftRestClientModule() {
|
||||||
super(new TestOpenStackAuthenticationModule(), CommonSwiftClient.class, CommonSwiftAsyncClient.class);
|
super(new TestOpenStackAuthenticationModule(), CommonSwiftClient.class, CommonSwiftAsyncClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected URI provideStorageUrl(AuthenticationResponse response) {
|
|
||||||
return URI.create("http://storage");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String provider = "swift";
|
protected String provider = "swift";
|
||||||
|
|
|
@ -18,23 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack;
|
package org.jclouds.openstack;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
import org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders;
|
import org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders;
|
||||||
import org.jclouds.openstack.reference.AuthHeaders;
|
import org.jclouds.openstack.reference.AuthHeaders;
|
||||||
import org.jclouds.rest.annotations.ResponseParser;
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,48 +42,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
public interface OpenStackAuthAsyncClient {
|
public interface OpenStackAuthAsyncClient {
|
||||||
public static final String VERSION = "1.0";
|
public static final String VERSION = "1.0";
|
||||||
|
|
||||||
public static class AuthenticationResponse {
|
|
||||||
private final String authToken;
|
|
||||||
private Map<String, URI> services;
|
|
||||||
|
|
||||||
public AuthenticationResponse(String authToken, Map<String, URI> services) {
|
|
||||||
this.authToken = checkNotNull(authToken, "authToken");
|
|
||||||
this.services = ImmutableMap.copyOf(checkNotNull(services, "services"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, URI> getServices() {
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndpoints(Map<String, URI> services) {
|
|
||||||
this.services = services;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthToken() {
|
|
||||||
return authToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
// performance isn't a concern on a infrequent object like this, so using shortcuts;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(authToken, services);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object that) {
|
|
||||||
if (that == null)
|
|
||||||
return false;
|
|
||||||
return Objects.equal(this.toString(), that.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return Objects.toStringHelper(this).add("authToken", authToken).add("services", services).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes
|
@Consumes
|
||||||
@ResponseParser(ParseAuthenticationResponseFromHeaders.class)
|
@ResponseParser(ParseAuthenticationResponseFromHeaders.class)
|
||||||
|
|
|
@ -16,23 +16,21 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudloadbalancers.loadbalancer.config;
|
package org.jclouds.openstack;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import java.util.Set;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.loadbalancer.config.BindLoadBalancerSuppliersByClass;
|
|
||||||
import org.jclouds.location.suppliers.RegionToProviderOrJustProvider;
|
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Provides access to Rackspace resources via their REST API.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class CloudLoadBalancersBindLoadBalancerSuppliersByClass extends BindLoadBalancerSuppliersByClass {
|
@Timeout(duration = 10, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface OpenStackAuthClient {
|
||||||
|
|
||||||
@Override
|
AuthenticationResponse authenticate(String user, String key);
|
||||||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
|
||||||
return RegionToProviderOrJustProvider.class;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -19,11 +19,10 @@
|
||||||
package org.jclouds.openstack.config;
|
package org.jclouds.openstack.config;
|
||||||
|
|
||||||
import static com.google.common.base.Suppliers.memoizeWithExpiration;
|
import static com.google.common.base.Suppliers.memoizeWithExpiration;
|
||||||
import static com.google.common.base.Throwables.propagate;
|
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
@ -37,8 +36,9 @@ import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.location.Provider;
|
import org.jclouds.location.Provider;
|
||||||
import org.jclouds.openstack.Authentication;
|
import org.jclouds.openstack.Authentication;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient;
|
import org.jclouds.openstack.OpenStackAuthAsyncClient;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
import org.jclouds.openstack.OpenStackAuthClient;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
|
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
@ -48,6 +48,7 @@ import com.google.common.cache.LoadingCache;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the Rackspace authentication service connection, including logging and http transport.
|
* Configures the Rackspace authentication service connection, including logging and http transport.
|
||||||
|
@ -61,6 +62,10 @@ public class OpenStackAuthenticationModule extends AbstractModule {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(new TypeLiteral<Function<Credentials, AuthenticationResponse>>() {
|
bind(new TypeLiteral<Function<Credentials, AuthenticationResponse>>() {
|
||||||
}).to(GetAuthenticationResponse.class);
|
}).to(GetAuthenticationResponse.class);
|
||||||
|
// OpenStackAuthClient is used directly for filters and retry handlers, so let's bind it
|
||||||
|
// explicitly
|
||||||
|
bindClientAndAsyncClient(binder(), OpenStackAuthClient.class, OpenStackAuthAsyncClient.class);
|
||||||
|
install(new FactoryModuleBuilder().build(URIFromAuthenticationResponseForService.Factory.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,21 +87,13 @@ public class OpenStackAuthenticationModule extends AbstractModule {
|
||||||
public static class GetAuthenticationResponse extends
|
public static class GetAuthenticationResponse extends
|
||||||
RetryOnTimeOutExceptionFunction<Credentials, AuthenticationResponse> {
|
RetryOnTimeOutExceptionFunction<Credentials, AuthenticationResponse> {
|
||||||
|
|
||||||
// passing factory here to avoid a circular dependency on
|
|
||||||
// OpenStackAuthAsyncClient resolving OpenStackAuthAsyncClient
|
|
||||||
@Inject
|
@Inject
|
||||||
public GetAuthenticationResponse(final AsyncClientFactory factory) {
|
public GetAuthenticationResponse(final OpenStackAuthClient client) {
|
||||||
super(new Function<Credentials, AuthenticationResponse>() {
|
super(new Function<Credentials, AuthenticationResponse>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthenticationResponse apply(Credentials input) {
|
public AuthenticationResponse apply(Credentials input) {
|
||||||
try {
|
return client.authenticate(input.identity, input.credential);
|
||||||
Future<AuthenticationResponse> response = factory.create(OpenStackAuthAsyncClient.class)
|
|
||||||
.authenticate(input.identity, input.credential);
|
|
||||||
return response.get(30, TimeUnit.SECONDS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw propagate(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,7 +107,7 @@ public class OpenStackAuthenticationModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public LoadingCache<Credentials, AuthenticationResponse> provideAuthenticationResponseCache2(
|
public LoadingCache<Credentials, AuthenticationResponse> provideAuthenticationResponseCache(
|
||||||
Function<Credentials, AuthenticationResponse> getAuthenticationResponse) {
|
Function<Credentials, AuthenticationResponse> getAuthenticationResponse) {
|
||||||
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS).build(
|
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS).build(
|
||||||
CacheLoader.from(getAuthenticationResponse));
|
CacheLoader.from(getAuthenticationResponse));
|
||||||
|
@ -123,11 +120,7 @@ public class OpenStackAuthenticationModule extends AbstractModule {
|
||||||
return new Supplier<AuthenticationResponse>() {
|
return new Supplier<AuthenticationResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public AuthenticationResponse get() {
|
public AuthenticationResponse get() {
|
||||||
try {
|
return cache.getUnchecked(creds);
|
||||||
return cache.get(creds);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
throw propagate(e.getCause());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -143,11 +136,4 @@ public class OpenStackAuthenticationModule extends AbstractModule {
|
||||||
}, 1, TimeUnit.SECONDS);
|
}, 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected AuthenticationResponse provideAuthenticationResponse(Supplier<AuthenticationResponse> supplier)
|
|
||||||
throws InterruptedException, ExecutionException, TimeoutException {
|
|
||||||
return supplier.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/**
|
||||||
|
* 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, Href 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.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
public class AuthenticationResponse {
|
||||||
|
private final String authToken;
|
||||||
|
private Map<String, URI> services;
|
||||||
|
|
||||||
|
public AuthenticationResponse(String authToken, Map<String, URI> services) {
|
||||||
|
this.authToken = checkNotNull(authToken, "authToken");
|
||||||
|
this.services = ImmutableMap.copyOf(checkNotNull(services, "services"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, URI> getServices() {
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndpoints(Map<String, URI> services) {
|
||||||
|
this.services = services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthToken() {
|
||||||
|
return authToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(authToken, services);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object that) {
|
||||||
|
if (that == null)
|
||||||
|
return false;
|
||||||
|
return Objects.equal(this.toString(), that.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Objects.toStringHelper(this).add("authToken", authToken).add("services", services).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -34,7 +34,7 @@ import javax.ws.rs.core.UriBuilder;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
import org.jclouds.rest.InvocationContext;
|
import org.jclouds.rest.InvocationContext;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/**
|
||||||
|
* 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.functions;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class URIFromAuthenticationResponseForService implements Supplier<URI> {
|
||||||
|
public static interface Factory {
|
||||||
|
URIFromAuthenticationResponseForService create(String service);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Supplier<AuthenticationResponse> auth;
|
||||||
|
private final String service;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public URIFromAuthenticationResponseForService(Supplier<AuthenticationResponse> auth, @Assisted String service) {
|
||||||
|
this.auth = auth;
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URI get() {
|
||||||
|
return auth.get().getServices().get(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "getURIForService(" + service + ")";
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpRetryHandler;
|
import org.jclouds.http.HttpRetryHandler;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
import org.jclouds.openstack.reference.AuthHeaders;
|
import org.jclouds.openstack.reference.AuthHeaders;
|
||||||
|
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.openstack.keystone.v1_1.config;
|
package org.jclouds.openstack.keystone.v1_1.config;
|
||||||
|
|
||||||
import static com.google.common.base.Throwables.propagate;
|
import static com.google.common.base.Throwables.propagate;
|
||||||
|
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -33,18 +34,19 @@ import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.location.Provider;
|
import org.jclouds.location.Provider;
|
||||||
import org.jclouds.openstack.Authentication;
|
import org.jclouds.openstack.Authentication;
|
||||||
import org.jclouds.openstack.keystone.v1_1.ServiceAsyncClient;
|
import org.jclouds.openstack.keystone.v1_1.ServiceAsyncClient;
|
||||||
|
import org.jclouds.openstack.keystone.v1_1.ServiceClient;
|
||||||
import org.jclouds.openstack.keystone.v1_1.domain.Auth;
|
import org.jclouds.openstack.keystone.v1_1.domain.Auth;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
import org.jclouds.openstack.keystone.v1_1.functions.PublicURLFromAuthResponseForService;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -57,6 +59,10 @@ public class AuthenticationServiceModule extends AbstractModule {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(new TypeLiteral<Function<Credentials, Auth>>() {
|
bind(new TypeLiteral<Function<Credentials, Auth>>() {
|
||||||
}).to(GetAuth.class);
|
}).to(GetAuth.class);
|
||||||
|
// ServiceClient is used directly for filters and retry handlers, so let's bind it
|
||||||
|
// explicitly
|
||||||
|
bindClientAndAsyncClient(binder(), ServiceClient.class, ServiceAsyncClient.class);
|
||||||
|
install(new FactoryModuleBuilder().build(PublicURLFromAuthResponseForService.Factory.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,28 +80,16 @@ public class AuthenticationServiceModule extends AbstractModule {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected ServiceAsyncClient provideServiceClient(AsyncClientFactory factory) {
|
|
||||||
return factory.create(ServiceAsyncClient.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class GetAuth extends RetryOnTimeOutExceptionFunction<Credentials, Auth> {
|
public static class GetAuth extends RetryOnTimeOutExceptionFunction<Credentials, Auth> {
|
||||||
|
|
||||||
// passing factory here to avoid a circular dependency on
|
|
||||||
// OpenStackAuthAsyncClient resolving OpenStackAuthAsyncClient
|
|
||||||
@Inject
|
@Inject
|
||||||
public GetAuth(final AsyncClientFactory factory) {
|
public GetAuth(final ServiceClient client) {
|
||||||
super(new Function<Credentials, Auth>() {
|
super(new Function<Credentials, Auth>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Auth apply(Credentials input) {
|
public Auth apply(Credentials input) {
|
||||||
try {
|
return client.authenticate(input.identity, input.credential);
|
||||||
return factory.create(ServiceAsyncClient.class).authenticate(input.identity, input.credential).get();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,7 +103,7 @@ public class AuthenticationServiceModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public LoadingCache<Credentials, Auth> provideAuthCache2(Function<Credentials, Auth> getAuth) {
|
public LoadingCache<Credentials, Auth> provideAuthCache(Function<Credentials, Auth> getAuth) {
|
||||||
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS).build(CacheLoader.from(getAuth));
|
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS).build(CacheLoader.from(getAuth));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,11 +122,4 @@ public class AuthenticationServiceModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Auth provideAuth(Supplier<Auth> supplier) {
|
|
||||||
return supplier.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
* 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.v1_1.functions;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.openstack.keystone.v1_1.domain.Auth;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class PublicURLFromAuthResponseForService implements Supplier<URI> {
|
||||||
|
public static interface Factory {
|
||||||
|
PublicURLFromAuthResponseForService create(String service);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Supplier<Auth> auth;
|
||||||
|
private final String service;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public PublicURLFromAuthResponseForService(Supplier<Auth> auth, @Assisted String service) {
|
||||||
|
this.auth = auth;
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URI get() {
|
||||||
|
return Iterables.get(auth.get().getServiceCatalog().get(service), 0).getPublicURL();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "getPublicURLForService(" + service + ")";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
* 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.v1_1.functions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.openstack.keystone.v1_1.domain.Auth;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
public class PublicUrlForService implements Function<Auth, URI> {
|
||||||
|
private final String serviceId;
|
||||||
|
|
||||||
|
public PublicUrlForService(String serviceId) {
|
||||||
|
this.serviceId = checkNotNull(serviceId, "serviceId");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URI apply(Auth arg0) {
|
||||||
|
return Iterables.get(arg0.getServiceCatalog().get(serviceId), 0).getPublicURL();
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.openstack.keystone.v2_0.config;
|
package org.jclouds.openstack.keystone.v2_0.config;
|
||||||
|
|
||||||
import static com.google.common.base.Throwables.propagate;
|
import static com.google.common.base.Throwables.propagate;
|
||||||
|
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -35,11 +36,12 @@ import org.jclouds.http.annotation.ClientError;
|
||||||
import org.jclouds.location.Provider;
|
import org.jclouds.location.Provider;
|
||||||
import org.jclouds.openstack.Authentication;
|
import org.jclouds.openstack.Authentication;
|
||||||
import org.jclouds.openstack.keystone.v2_0.ServiceAsyncClient;
|
import org.jclouds.openstack.keystone.v2_0.ServiceAsyncClient;
|
||||||
|
import org.jclouds.openstack.keystone.v2_0.ServiceClient;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
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.AuthenticateApiAccessKeyCredentials;
|
||||||
import org.jclouds.openstack.keystone.v2_0.functions.AuthenticatePasswordCredentials;
|
import org.jclouds.openstack.keystone.v2_0.functions.AuthenticatePasswordCredentials;
|
||||||
|
import org.jclouds.openstack.keystone.v2_0.functions.PublicURLFromAccessForService;
|
||||||
import org.jclouds.openstack.keystone.v2_0.handlers.RetryOnRenew;
|
import org.jclouds.openstack.keystone.v2_0.handlers.RetryOnRenew;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
@ -49,6 +51,7 @@ import com.google.common.cache.LoadingCache;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -61,6 +64,10 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
||||||
bind(CredentialType.class).toProvider(CredentialTypeFromPropertyOrDefault.class);
|
bind(CredentialType.class).toProvider(CredentialTypeFromPropertyOrDefault.class);
|
||||||
|
// ServiceClient is used directly for filters and retry handlers, so let's bind it
|
||||||
|
// explicitly
|
||||||
|
bindClientAndAsyncClient(binder(), ServiceClient.class, ServiceAsyncClient.class);
|
||||||
|
install(new FactoryModuleBuilder().build(PublicURLFromAccessForService.Factory.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,15 +85,6 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* service is needed to locate endpoints and such
|
|
||||||
*/
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected ServiceAsyncClient provideServiceClient(AsyncClientFactory factory) {
|
|
||||||
return factory.create(ServiceAsyncClient.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
static class CredentialTypeFromPropertyOrDefault implements javax.inject.Provider<CredentialType> {
|
static class CredentialTypeFromPropertyOrDefault implements javax.inject.Provider<CredentialType> {
|
||||||
/**
|
/**
|
||||||
|
@ -150,14 +148,4 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* currently, endpointParams are not configured to take their results from a supplier lazily, so
|
|
||||||
* we need to eagerly fetch.
|
|
||||||
*/
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Access provideAccess(Supplier<Access> supplier) {
|
|
||||||
return supplier.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -19,22 +19,23 @@
|
||||||
package org.jclouds.openstack.keystone.v2_0.functions;
|
package org.jclouds.openstack.keystone.v2_0.functions;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.openstack.keystone.v2_0.ServiceAsyncClient;
|
import org.jclouds.openstack.keystone.v2_0.ServiceClient;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.ApiAccessKeyCredentials;
|
import org.jclouds.openstack.keystone.v2_0.domain.ApiAccessKeyCredentials;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
public class AuthenticateApiAccessKeyCredentials implements Function<Credentials, Access> {
|
public class AuthenticateApiAccessKeyCredentials implements Function<Credentials, Access> {
|
||||||
private final ServiceAsyncClient client;
|
private final ServiceClient client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AuthenticateApiAccessKeyCredentials(ServiceAsyncClient client) {
|
public AuthenticateApiAccessKeyCredentials(ServiceClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,13 +47,9 @@ public class AuthenticateApiAccessKeyCredentials implements Function<Credentials
|
||||||
String usernameOrAccessKey = Iterables.get(tenantIdUsernameOrAccessKey, 1);
|
String usernameOrAccessKey = Iterables.get(tenantIdUsernameOrAccessKey, 1);
|
||||||
String passwordOrSecretKey = input.credential;
|
String passwordOrSecretKey = input.credential;
|
||||||
|
|
||||||
try {
|
ApiAccessKeyCredentials apiAccessKeyCredentials = ApiAccessKeyCredentials.createWithAccessKeyAndSecretKey(
|
||||||
ApiAccessKeyCredentials apiAccessKeyCredentials = ApiAccessKeyCredentials.createWithAccessKeyAndSecretKey(
|
usernameOrAccessKey, passwordOrSecretKey);
|
||||||
usernameOrAccessKey, passwordOrSecretKey);
|
return client.authenticateTenantWithCredentials(tenantId, apiAccessKeyCredentials);
|
||||||
return client.authenticateTenantWithCredentials(tenantId, apiAccessKeyCredentials).get();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,23 +21,20 @@ package org.jclouds.openstack.keystone.v2_0.functions;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.openstack.keystone.v2_0.ServiceAsyncClient;
|
import org.jclouds.openstack.keystone.v2_0.ServiceClient;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials;
|
import org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
public class AuthenticatePasswordCredentials implements Function<Credentials, Access> {
|
public class AuthenticatePasswordCredentials implements Function<Credentials, Access> {
|
||||||
private final AsyncClientFactory factory;
|
private final ServiceClient client;
|
||||||
// passing factory here to avoid a circular dependency on
|
|
||||||
// OpenStackAuthAsyncClient resolving ServiceAsyncClient
|
|
||||||
@Inject
|
@Inject
|
||||||
public AuthenticatePasswordCredentials(AsyncClientFactory factory) {
|
public AuthenticatePasswordCredentials(ServiceClient client) {
|
||||||
this.factory = factory;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,14 +45,9 @@ public class AuthenticatePasswordCredentials implements Function<Credentials, Ac
|
||||||
String usernameOrAccessKey = Iterables.get(tenantIdUsernameOrAccessKey, 1);
|
String usernameOrAccessKey = Iterables.get(tenantIdUsernameOrAccessKey, 1);
|
||||||
String passwordOrSecretKey = input.credential;
|
String passwordOrSecretKey = input.credential;
|
||||||
|
|
||||||
ServiceAsyncClient client = factory.create(ServiceAsyncClient.class);
|
PasswordCredentials passwordCredentials = PasswordCredentials.createWithUsernameAndPassword(usernameOrAccessKey,
|
||||||
try {
|
passwordOrSecretKey);
|
||||||
PasswordCredentials passwordCredentials = PasswordCredentials.createWithUsernameAndPassword(
|
return client.authenticateTenantWithCredentials(tenantId, passwordCredentials);
|
||||||
usernameOrAccessKey, passwordOrSecretKey);
|
|
||||||
return client.authenticateTenantWithCredentials(tenantId, passwordCredentials).get();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
* 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.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
||||||
|
import org.jclouds.openstack.keystone.v2_0.domain.Service;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class PublicURLFromAccessForService implements Supplier<URI> {
|
||||||
|
public static interface Factory {
|
||||||
|
PublicURLFromAccessForService create(String service);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Supplier<Access> auth;
|
||||||
|
private final String service;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public PublicURLFromAccessForService(Supplier<Access> auth, @Assisted String service) {
|
||||||
|
this.auth = auth;
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URI get() {
|
||||||
|
return Iterables.getOnlyElement(Iterables.find(auth.get().getServiceCatalog(), new Predicate<Service>(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Service input) {
|
||||||
|
return input.getId().equals(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
}).getEndpoints()).getPublicURL();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "getPublicURLForService(" + service + ")";
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,12 +22,8 @@ import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient;
|
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
|
||||||
import org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders;
|
import org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.RestContextSpec;
|
import org.jclouds.rest.RestContextSpec;
|
||||||
|
@ -90,9 +86,4 @@ public class OpenStackAuthAsyncClientTest extends RestClientTest<OpenStackAuthAs
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Timeout(duration = 10, timeUnit = TimeUnit.SECONDS)
|
|
||||||
public interface OpenStackAuthClient {
|
|
||||||
|
|
||||||
AuthenticationResponse authenticate(String user, String key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,13 @@ package org.jclouds.openstack;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
|
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
|
||||||
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
|
import org.jclouds.openstack.reference.AuthHeaders;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -35,11 +40,24 @@ public class TestOpenStackAuthenticationModule extends OpenStackAuthenticationMo
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
|
bind(GetAuthenticationResponse.class).to(TestGetAuthenticationResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Singleton
|
||||||
protected AuthenticationResponse provideAuthenticationResponse(Supplier<AuthenticationResponse> supplier) {
|
public static class TestGetAuthenticationResponse extends GetAuthenticationResponse {
|
||||||
return new AuthenticationResponse("authToken", ImmutableMap.<String, URI> of());
|
|
||||||
|
@Inject
|
||||||
|
protected TestGetAuthenticationResponse() {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthenticationResponse apply(Credentials input) {
|
||||||
|
return new AuthenticationResponse("authToken", ImmutableMap.<String, URI> of(
|
||||||
|
AuthHeaders.SERVER_MANAGEMENT_URL, URI.create("http://endpoint/vapi-version"),
|
||||||
|
AuthHeaders.STORAGE_URL, URI.create("http://storage")));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
|
|
@ -29,8 +29,7 @@ import org.jclouds.http.annotation.ClientError;
|
||||||
import org.jclouds.http.annotation.Redirection;
|
import org.jclouds.http.annotation.Redirection;
|
||||||
import org.jclouds.http.annotation.ServerError;
|
import org.jclouds.http.annotation.ServerError;
|
||||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
import org.jclouds.openstack.keystone.v2_0.functions.PublicURLFromAccessForService;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.Service;
|
|
||||||
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
|
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
|
||||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||||
import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient;
|
import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient;
|
||||||
|
@ -41,9 +40,8 @@ import org.jclouds.openstack.services.ServiceType;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,19 +81,11 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
|
||||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(NovaErrorHandler.class);
|
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(NovaErrorHandler.class);
|
||||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(NovaErrorHandler.class);
|
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(NovaErrorHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Compute
|
@Compute
|
||||||
protected URI provideServerUrl(Access response) {
|
protected Supplier<URI> provideServerUrl(PublicURLFromAccessForService.Factory factory) {
|
||||||
return Iterables.getOnlyElement(Iterables.find(response.getServiceCatalog(), new Predicate<Service>(){
|
return factory.create(ServiceType.COMPUTE);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Service input) {
|
|
||||||
return input.getId().equals(ServiceType.COMPUTE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}).getEndpoints()).getPublicURL();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue