mirror of https://github.com/apache/jclouds.git
Prefer Regions to Zones in OpenStack APIs
This commit is contained in:
parent
9009bb5268
commit
744cd5d7eb
|
@ -18,65 +18,113 @@ package org.jclouds.openstack.cinder.v1;
|
|||
|
||||
import java.io.Closeable;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.functions.ZoneToEndpoint;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.functions.RegionToEndpoint;
|
||||
import org.jclouds.openstack.cinder.v1.domain.Snapshot;
|
||||
import org.jclouds.openstack.cinder.v1.domain.Volume;
|
||||
import org.jclouds.openstack.cinder.v1.domain.VolumeType;
|
||||
import org.jclouds.openstack.cinder.v1.features.QuotaApi;
|
||||
import org.jclouds.openstack.cinder.v1.features.SnapshotApi;
|
||||
import org.jclouds.openstack.cinder.v1.features.VolumeApi;
|
||||
import org.jclouds.openstack.cinder.v1.features.VolumeTypeApi;
|
||||
import org.jclouds.openstack.v2_0.features.ExtensionApi;
|
||||
import org.jclouds.openstack.v2_0.services.Extension;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Cinder.
|
||||
*
|
||||
* @see <a href="http://api.openstack.org/">API Doc</a>
|
||||
* Provides synchronous access to OpenStack Block Storage (Cinder) v1 API.
|
||||
*/
|
||||
public interface CinderApi extends Closeable {
|
||||
|
||||
/**
|
||||
* @return the Zone codes configured
|
||||
* @return the Region codes configured
|
||||
*/
|
||||
@Provides
|
||||
@Zone
|
||||
Set<String> getConfiguredZones();
|
||||
|
||||
@Region
|
||||
Set<String> getConfiguredRegions();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Extension features.
|
||||
* Provides synchronous access to {@link Extension} features.
|
||||
*/
|
||||
@Delegate
|
||||
ExtensionApi getExtensionApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to {@link Volume} features.
|
||||
*/
|
||||
@Delegate
|
||||
VolumeApi getVolumeApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to {@link VolumeType} features.
|
||||
*/
|
||||
@Delegate
|
||||
VolumeTypeApi getVolumeTypeApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to {@link Snapshot} features.
|
||||
*/
|
||||
@Delegate
|
||||
SnapshotApi getSnapshotApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to quota features.
|
||||
*/
|
||||
@Delegate
|
||||
QuotaApi getQuotaApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* @return the Zone codes configured
|
||||
* @deprecated Please use {@link #getConfiguredRegions()} as this method will be removed in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Provides
|
||||
@Region
|
||||
Set<String> getConfiguredZones();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Extension features.
|
||||
* @deprecated Please use {@link #getExtensionApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
ExtensionApi getExtensionApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Volume features.
|
||||
* @deprecated Please use {@link #getVolumeApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
VolumeApi getVolumeApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to VolumeType features.
|
||||
* @deprecated Please use {@link #getVolumeTypeApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
VolumeTypeApi getVolumeTypeApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Snapshot features.
|
||||
* @deprecated Please use {@link #getSnapshotApi(String)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
SnapshotApi getSnapshotApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to quotas features.
|
||||
*/
|
||||
@Delegate
|
||||
QuotaApi getQuotaApi(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.jclouds.openstack.cinder.v1.config.CinderParserModule;
|
|||
import org.jclouds.openstack.keystone.v2_0.config.AuthenticationApiModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
|
||||
import org.jclouds.openstack.v2_0.ServiceType;
|
||||
import org.jclouds.rest.internal.BaseHttpApiMetadata;
|
||||
|
||||
|
@ -35,10 +35,10 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ApiMetadata} for Cinder v1 API
|
||||
* Implementation of {@link org.jclouds.apis.ApiMetadata} for Cinder v1 API
|
||||
*/
|
||||
public class CinderApiMetadata extends BaseHttpApiMetadata<CinderApi> {
|
||||
|
||||
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromApiMetadata(this);
|
||||
|
@ -74,12 +74,12 @@ public class CinderApiMetadata extends BaseHttpApiMetadata<CinderApi> {
|
|||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(AuthenticationApiModule.class)
|
||||
.add(KeystoneAuthenticationModule.class)
|
||||
.add(ZoneModule.class)
|
||||
.add(RegionModule.class)
|
||||
.add(CinderParserModule.class)
|
||||
.add(CinderHttpApiModule.class)
|
||||
.build());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CinderApiMetadata build() {
|
||||
return new CinderApiMetadata(this);
|
||||
|
|
|
@ -16,7 +16,15 @@
|
|||
*/
|
||||
package org.jclouds.openstack.cinder.v1.features;
|
||||
|
||||
import org.jclouds.Fallbacks;
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.cinder.v1.domain.VolumeQuota;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
|
@ -24,29 +32,22 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Quota via their REST API.
|
||||
* Provides access to the Quota API.
|
||||
*
|
||||
* @see QuotaApi
|
||||
* @see <a href="http://api.openstack.org/">API Doc</a>
|
||||
*/
|
||||
@SkipEncoding({'/', '='})
|
||||
@RequestFilters(AuthenticateRequest.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/os-quota-sets")
|
||||
public interface QuotaApi {
|
||||
|
||||
|
||||
@Named("quota:get")
|
||||
@GET
|
||||
@SelectJson("quota_set")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/{tenant_id}")
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Nullable
|
||||
VolumeQuota getByTenant(@PathParam("tenant_id") String tenantId);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404;
|
||||
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.cinder.v1.domain.Snapshot;
|
||||
import org.jclouds.openstack.cinder.v1.options.CreateSnapshotOptions;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
|
@ -42,12 +43,13 @@ import org.jclouds.rest.annotations.SkipEncoding;
|
|||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Volume Snapshots via their REST API.
|
||||
*
|
||||
* @see <a href="http://api.openstack.org/">API Doc</a>
|
||||
* Provides synchronous access to Volume Snapshots API.
|
||||
*
|
||||
*/
|
||||
@SkipEncoding({'/', '='})
|
||||
@RequestFilters(AuthenticateRequest.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/snapshots")
|
||||
public interface SnapshotApi {
|
||||
/**
|
||||
* Returns a summary list of Snapshots.
|
||||
|
@ -56,10 +58,8 @@ public interface SnapshotApi {
|
|||
*/
|
||||
@Named("snapshot:list")
|
||||
@GET
|
||||
@Path("/snapshots")
|
||||
@SelectJson("snapshots")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
FluentIterable<? extends Snapshot> list();
|
||||
|
||||
/**
|
||||
|
@ -69,10 +69,9 @@ public interface SnapshotApi {
|
|||
*/
|
||||
@Named("snapshot:list")
|
||||
@GET
|
||||
@Path("/snapshots/detail")
|
||||
@Path("/detail")
|
||||
@SelectJson("snapshots")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
FluentIterable<? extends Snapshot> listInDetail();
|
||||
|
||||
/**
|
||||
|
@ -83,26 +82,24 @@ public interface SnapshotApi {
|
|||
*/
|
||||
@Named("snapshot:get")
|
||||
@GET
|
||||
@Path("/snapshots/{id}")
|
||||
@Path("/{id}")
|
||||
@SelectJson("snapshot")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Nullable
|
||||
Snapshot get(@PathParam("id") String snapshotId);
|
||||
|
||||
/**
|
||||
* Creates a new Snapshot. The Volume status must be Available.
|
||||
*
|
||||
*
|
||||
* @param volumeId The Volume Id from which to create the Snapshot
|
||||
* @param options See CreateSnapshotOptions
|
||||
* @return The new Snapshot
|
||||
*/
|
||||
@Named("snapshot:create")
|
||||
@POST
|
||||
@Path("/snapshots")
|
||||
@SelectJson("snapshot")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@MapBinder(CreateSnapshotOptions.class)
|
||||
@MapBinder(CreateSnapshotOptions.class)
|
||||
Snapshot create(@PayloadParam("volume_id") String volumeId, CreateSnapshotOptions... options);
|
||||
|
||||
/**
|
||||
|
@ -113,8 +110,7 @@ public interface SnapshotApi {
|
|||
*/
|
||||
@Named("snapshot:delete")
|
||||
@DELETE
|
||||
@Path("/snapshots/{id}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(FalseOnNotFoundOr404.class)
|
||||
@Path("/{id}")
|
||||
@Fallback(FalseOnNotFoundOr404.class)
|
||||
boolean delete(@PathParam("id") String snapshotId);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404;
|
||||
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.cinder.v1.domain.Volume;
|
||||
import org.jclouds.openstack.cinder.v1.options.CreateVolumeOptions;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
|
@ -42,16 +43,16 @@ import org.jclouds.rest.annotations.SkipEncoding;
|
|||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Volumes.
|
||||
*
|
||||
* Provides synchronous access to the Volume API.
|
||||
*
|
||||
* This API strictly handles creating and managing Volumes. To attach a Volume to a Server you need to use the
|
||||
* @see VolumeAttachmentApi
|
||||
*
|
||||
* @see VolumeAsyncApi
|
||||
* @see <a href="http://api.openstack.org/">API Doc</a>
|
||||
*
|
||||
*/
|
||||
@SkipEncoding({'/', '='})
|
||||
@RequestFilters(AuthenticateRequest.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/volumes")
|
||||
public interface VolumeApi {
|
||||
/**
|
||||
* Returns a summary list of Volumes.
|
||||
|
@ -60,9 +61,7 @@ public interface VolumeApi {
|
|||
*/
|
||||
@Named("volume:list")
|
||||
@GET
|
||||
@Path("/volumes")
|
||||
@SelectJson("volumes")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
FluentIterable<? extends Volume> list();
|
||||
|
||||
|
@ -73,10 +72,9 @@ public interface VolumeApi {
|
|||
*/
|
||||
@Named("volume:list")
|
||||
@GET
|
||||
@Path("/volumes/detail")
|
||||
@Path("/detail")
|
||||
@SelectJson("volumes")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
FluentIterable<? extends Volume> listInDetail();
|
||||
|
||||
/**
|
||||
|
@ -87,24 +85,22 @@ public interface VolumeApi {
|
|||
*/
|
||||
@Named("volume:get")
|
||||
@GET
|
||||
@Path("/volumes/{id}")
|
||||
@Path("/{id}")
|
||||
@SelectJson("volume")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Nullable
|
||||
Volume get(@PathParam("id") String volumeId);
|
||||
|
||||
/**
|
||||
* Creates a new Volume
|
||||
*
|
||||
*
|
||||
* @param volumeId Id of the Volume
|
||||
* @param options See CreateVolumeOptions
|
||||
* @return The new Volume
|
||||
*/
|
||||
@Named("volume:create")
|
||||
@POST
|
||||
@Path("/volumes")
|
||||
@SelectJson("volume")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@MapBinder(CreateVolumeOptions.class)
|
||||
Volume create(@PayloadParam("size") int sizeGB, CreateVolumeOptions... options);
|
||||
|
@ -117,8 +113,7 @@ public interface VolumeApi {
|
|||
*/
|
||||
@Named("volume:delete")
|
||||
@DELETE
|
||||
@Path("/volumes/{id}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/{id}")
|
||||
@Fallback(FalseOnNotFoundOr404.class)
|
||||
boolean delete(@PathParam("id") String volumeId);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404;
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.cinder.v1.domain.VolumeType;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
|
@ -35,24 +36,22 @@ import org.jclouds.rest.annotations.SkipEncoding;
|
|||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Volumes via their REST API.
|
||||
*
|
||||
* @see VolumeAsyncApi
|
||||
* @see <a href="http://api.openstack.org/">API Doc</a>
|
||||
* Provides synchronous access to the OpenStack Block Storage (Cinder) v1 Volume Types API.
|
||||
*
|
||||
*/
|
||||
@SkipEncoding({'/', '='})
|
||||
@RequestFilters(AuthenticateRequest.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/types")
|
||||
public interface VolumeTypeApi {
|
||||
/**
|
||||
* Returns a summary list of VolumeTypes.
|
||||
*
|
||||
* @return The list of VolumeTypes
|
||||
*/
|
||||
@Named("volumetype:list")
|
||||
@Named("volumeType:list")
|
||||
@GET
|
||||
@Path("/types")
|
||||
@SelectJson("volume_types")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
FluentIterable<? extends VolumeType> list();
|
||||
|
||||
|
@ -62,11 +61,11 @@ public interface VolumeTypeApi {
|
|||
* @param volumeTypeId Id of the VolumeType
|
||||
* @return Details of a specific VolumeType
|
||||
*/
|
||||
@Named("volumetype:get")
|
||||
@Named("volumeType:get")
|
||||
@GET
|
||||
@Path("/types/{id}")
|
||||
@Path("/{id}")
|
||||
@SelectJson("volume_type")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Nullable
|
||||
VolumeType get(@PathParam("id") String volumeTypeId);
|
||||
}
|
||||
|
|
|
@ -37,21 +37,21 @@ import com.google.common.base.Predicate;
|
|||
* Snapshot snapshot = snapshotApi.create(volumeId);
|
||||
* RetryablePredicate<String> awaitAvailable = RetryablePredicate.create(
|
||||
* SnapshotPredicates.available(snapshotApi), 600, 10, 10, TimeUnit.SECONDS);
|
||||
*
|
||||
*
|
||||
* if (!awaitAvailable.apply(snapshot.getId())) {
|
||||
* throw new TimeoutException("Timeout on snapshot: " + snapshot);
|
||||
* }
|
||||
* throw new TimeoutException("Timeout on snapshot: " + snapshot);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* You can also use the static convenience methods as so.
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* Snapshot snapshot = snapshotApi.create(volumeId);
|
||||
*
|
||||
*
|
||||
* if (!SnapshotPredicates.awaitAvailable(snapshotApi).apply(snapshot.getId())) {
|
||||
* throw new TimeoutException("Timeout on snapshot: " + snapshot);
|
||||
* throw new TimeoutException("Timeout on snapshot: " + snapshot);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
|
@ -59,20 +59,20 @@ import com.google.common.base.Predicate;
|
|||
public class SnapshotPredicates {
|
||||
/**
|
||||
* Wait until a Snapshot is Available.
|
||||
*
|
||||
* @param snapshotApi The SnapshotApi in the zone where your Snapshot resides.
|
||||
*
|
||||
* @param snapshotApi The SnapshotApi in the region where your Snapshot resides.
|
||||
* @return RetryablePredicate That will check the status every 5 seconds for a maxiumum of 20 minutes.
|
||||
*/
|
||||
public static Predicate<Snapshot> awaitAvailable(SnapshotApi snapshotApi) {
|
||||
StatusUpdatedPredicate statusPredicate = new StatusUpdatedPredicate(snapshotApi, Volume.Status.AVAILABLE);
|
||||
return retry(statusPredicate, 1200, 5, 5, SECONDS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wait until a Snapshot no longer exists.
|
||||
*
|
||||
* @param snapshotApi The SnapshotApi in the zone where your Snapshot resides.
|
||||
* @return RetryablePredicate That will check the whether the Snapshot exists
|
||||
*
|
||||
* @param snapshotApi The SnapshotApi in the region where your Snapshot resides.
|
||||
* @return RetryablePredicate That will check the whether the Snapshot exists
|
||||
* every 5 seconds for a maxiumum of 20 minutes.
|
||||
*/
|
||||
public static Predicate<Snapshot> awaitDeleted(SnapshotApi snapshotApi) {
|
||||
|
@ -85,7 +85,7 @@ public class SnapshotPredicates {
|
|||
StatusUpdatedPredicate statusPredicate = new StatusUpdatedPredicate(snapshotApi, status);
|
||||
return retry(statusPredicate, maxWaitInSec, periodInSec, periodInSec, SECONDS);
|
||||
}
|
||||
|
||||
|
||||
private static class StatusUpdatedPredicate implements Predicate<Snapshot> {
|
||||
private SnapshotApi snapshotApi;
|
||||
private Status status;
|
||||
|
@ -108,7 +108,7 @@ public class SnapshotPredicates {
|
|||
else {
|
||||
Snapshot snapshotUpdated = snapshotApi.get(snapshot.getId());
|
||||
checkNotNull(snapshotUpdated, "Snapshot %s not found.", snapshot.getId());
|
||||
|
||||
|
||||
return status.equals(snapshotUpdated.getStatus());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,24 +34,24 @@ import com.google.common.base.Predicate;
|
|||
* <pre>
|
||||
* {@code
|
||||
* Volume volume = volumeApi.create(100);
|
||||
*
|
||||
*
|
||||
* RetryablePredicate<String> awaitAvailable = RetryablePredicate.create(
|
||||
* VolumePredicates.available(volumeApi), 600, 10, 10, TimeUnit.SECONDS);
|
||||
*
|
||||
*
|
||||
* if (!awaitAvailable.apply(volume.getId())) {
|
||||
* throw new TimeoutException("Timeout on volume: " + volume);
|
||||
* }
|
||||
* throw new TimeoutException("Timeout on volume: " + volume);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* You can also use the static convenience methods as so.
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* Volume volume = volumeApi.create(100);
|
||||
*
|
||||
*
|
||||
* if (!VolumePredicates.awaitAvailable(volumeApi).apply(volume.getId())) {
|
||||
* throw new TimeoutException("Timeout on volume: " + volume);
|
||||
* throw new TimeoutException("Timeout on volume: " + volume);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
|
@ -59,19 +59,19 @@ import com.google.common.base.Predicate;
|
|||
public class VolumePredicates {
|
||||
/**
|
||||
* Wait until a Volume is Available.
|
||||
*
|
||||
* @param volumeApi The VolumeApi in the zone where your Volume resides.
|
||||
*
|
||||
* @param volumeApi The VolumeApi in the region where your Volume resides.
|
||||
* @return RetryablePredicate That will check the status every 5 seconds for a maxiumum of 10 minutes.
|
||||
*/
|
||||
public static Predicate<Volume> awaitAvailable(VolumeApi volumeApi) {
|
||||
StatusUpdatedPredicate statusPredicate = new StatusUpdatedPredicate(volumeApi, Volume.Status.AVAILABLE);
|
||||
return retry(statusPredicate, 600, 5, 5, SECONDS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wait until a Volume is In Use.
|
||||
*
|
||||
* @param volumeApi The VolumeApi in the zone where your Volume resides.
|
||||
*
|
||||
* @param volumeApi The VolumeApi in the region where your Volume resides.
|
||||
* @return RetryablePredicate That will check the status every 5 seconds for a maxiumum of 10 minutes.
|
||||
*/
|
||||
public static Predicate<Volume> awaitInUse(VolumeApi volumeApi) {
|
||||
|
@ -81,22 +81,22 @@ public class VolumePredicates {
|
|||
|
||||
/**
|
||||
* Wait until a Volume no longer exists.
|
||||
*
|
||||
* @param volumeApi The VolumeApi in the zone where your Volume resides.
|
||||
* @return RetryablePredicate That will check the whether the Volume exists
|
||||
*
|
||||
* @param volumeApi The VolumeApi in the region where your Volume resides.
|
||||
* @return RetryablePredicate That will check the whether the Volume exists
|
||||
* every 5 seconds for a maxiumum of 10 minutes.
|
||||
*/
|
||||
public static Predicate<Volume> awaitDeleted(VolumeApi volumeApi) {
|
||||
DeletedPredicate deletedPredicate = new DeletedPredicate(volumeApi);
|
||||
return retry(deletedPredicate, 600, 5, 5, SECONDS);
|
||||
}
|
||||
|
||||
|
||||
public static Predicate<Volume> awaitStatus(
|
||||
VolumeApi volumeApi, Volume.Status status, long maxWaitInSec, long periodInSec) {
|
||||
StatusUpdatedPredicate statusPredicate = new StatusUpdatedPredicate(volumeApi, status);
|
||||
return retry(statusPredicate, maxWaitInSec, periodInSec, periodInSec, SECONDS);
|
||||
}
|
||||
|
||||
|
||||
private static class StatusUpdatedPredicate implements Predicate<Volume> {
|
||||
private VolumeApi volumeApi;
|
||||
private Status status;
|
||||
|
@ -112,14 +112,14 @@ public class VolumePredicates {
|
|||
@Override
|
||||
public boolean apply(Volume volume) {
|
||||
checkNotNull(volume, "volume must be defined");
|
||||
|
||||
|
||||
if (status.equals(volume.getStatus())) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
Volume volumeUpdated = volumeApi.get(volume.getId());
|
||||
checkNotNull(volumeUpdated, "Volume %s not found.", volume.getId());
|
||||
|
||||
|
||||
return status.equals(volumeUpdated.getStatus());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
*/
|
||||
package org.jclouds.openstack.cinder.v1.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.cinder.v1.domain.VolumeQuota;
|
||||
import org.jclouds.openstack.cinder.v1.internal.BaseCinderApiExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
@Test(groups = "unit", testName = "QuotaApiExpectTest")
|
||||
public class QuotasApiExpectTest extends BaseCinderApiExpectTest {
|
||||
|
||||
|
|
|
@ -16,15 +16,16 @@
|
|||
*/
|
||||
package org.jclouds.openstack.cinder.v1.features;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.jclouds.openstack.cinder.v1.domain.VolumeQuota;
|
||||
import org.jclouds.openstack.cinder.v1.internal.BaseCinderApiLiveTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@Test(groups = "live", testName = "QuotasApiLiveTest", singleThreaded = true)
|
||||
public class QuotasApiLiveTest extends BaseCinderApiLiveTest {
|
||||
|
@ -39,8 +40,8 @@ public class QuotasApiLiveTest extends BaseCinderApiLiveTest {
|
|||
@BeforeClass(groups = {"integration", "live"})
|
||||
public void setupContext() {
|
||||
super.setup();
|
||||
String zone = Iterables.getFirst(api.getConfiguredZones(), "nova");
|
||||
quotaApi = api.getQuotaApi(zone);
|
||||
String region = Iterables.getFirst(api.getConfiguredRegions(), "nova");
|
||||
quotaApi = api.getQuotaApi(region);
|
||||
}
|
||||
|
||||
public void testGetStorageQuotas() throws ExecutionException, InterruptedException {
|
||||
|
|
|
@ -56,7 +56,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list_simple.json")).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
Set<? extends Snapshot> snapshots = api.list().toSet();
|
||||
assertEquals(snapshots, ImmutableSet.of(testSnapshot()));
|
||||
|
@ -69,7 +69,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
Set<? extends Snapshot> snapshots = api.list().toSet();
|
||||
assertTrue(snapshots.isEmpty());
|
||||
|
@ -82,7 +82,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list_details.json")).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
Set<? extends Snapshot> snapshots = api.listInDetail().toSet();
|
||||
assertEquals(snapshots, ImmutableSet.of(testSnapshot()));
|
||||
|
@ -104,7 +104,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
Set<? extends Snapshot> snapshots = api.listInDetail().toSet();
|
||||
assertTrue(snapshots.isEmpty());
|
||||
|
@ -117,7 +117,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_get.json")).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
Snapshot snapshot = api.get("67d03df1-ce5d-4ba7-adbe-492ceb80170b");
|
||||
assertEquals(snapshot, testSnapshot());
|
||||
|
@ -130,7 +130,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
assertNull(api.get("67d03df1-ce5d-4ba7-adbe-492ceb80170b"));
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
.payload(payloadFromResourceWithContentType("/snapshot_create.json", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_create_response.json")).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
CreateSnapshotOptions options = CreateSnapshotOptions.Builder
|
||||
.name("jclouds-test-snapshot")
|
||||
|
@ -167,7 +167,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
.payload(payloadFromResourceWithContentType("/snapshot_create.json", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
CreateSnapshotOptions options = CreateSnapshotOptions.Builder
|
||||
.name("jclouds-test-snapshot")
|
||||
|
@ -193,7 +193,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
.wrap("{\"badRequest\": {\"message\": \"Invalid volume: must be available\", \"code\": 400}}"
|
||||
.getBytes())))
|
||||
.build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
CreateSnapshotOptions options = CreateSnapshotOptions.Builder
|
||||
.name("jclouds-test-snapshot")
|
||||
|
@ -214,7 +214,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
.payload(payloadFromResourceWithContentType("/snapshot_create.json", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(401).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
CreateSnapshotOptions options = CreateSnapshotOptions.Builder
|
||||
.name("jclouds-test-snapshot")
|
||||
|
@ -231,7 +231,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(200).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
assertTrue(api.delete("67d03df1-ce5d-4ba7-adbe-492ceb80170b"));
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(401).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
api.delete("67d03df1-ce5d-4ba7-adbe-492ceb80170b");
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
assertFalse(api.delete("67d03df1-ce5d-4ba7-adbe-492ceb80170b"));
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ public class SnapshotApiExpectTest extends BaseCinderApiExpectTest {
|
|||
.wrap("{\"badRequest\": {\"message\": \"Invalid volume: Volume Snapshot status must be available or error\", \"code\": 400}}"
|
||||
.getBytes())))
|
||||
.build()
|
||||
).getSnapshotApiForZone("RegionOne");
|
||||
).getSnapshotApi("RegionOne");
|
||||
|
||||
api.delete("67d03df1-ce5d-4ba7-adbe-492ceb80170b");
|
||||
}
|
||||
|
|
|
@ -42,12 +42,12 @@ import com.google.common.collect.Iterables;
|
|||
@Test(groups = "live", testName = "VolumeApiLiveTest", singleThreaded = true)
|
||||
public class VolumeAndSnapshotApiLiveTest extends BaseCinderApiLiveTest {
|
||||
private static final String name = System.getProperty("user.name").replace('.', '-').toLowerCase();
|
||||
|
||||
private String zone;
|
||||
|
||||
private String region;
|
||||
|
||||
private VolumeApi volumeApi;
|
||||
private SnapshotApi snapshotApi;
|
||||
|
||||
|
||||
private Volume testVolume;
|
||||
private Snapshot testSnapshot;
|
||||
|
||||
|
@ -55,9 +55,9 @@ public class VolumeAndSnapshotApiLiveTest extends BaseCinderApiLiveTest {
|
|||
@Override
|
||||
public void setup() {
|
||||
super.setup();
|
||||
zone = Iterables.getLast(api.getConfiguredZones(), "nova");
|
||||
volumeApi = api.getVolumeApiForZone(zone);
|
||||
snapshotApi = api.getSnapshotApiForZone(zone);
|
||||
region = Iterables.getLast(api.getConfiguredRegions(), "nova");
|
||||
volumeApi = api.getVolumeApi(region);
|
||||
snapshotApi = api.getSnapshotApi(region);
|
||||
}
|
||||
|
||||
@AfterClass(groups = { "integration", "live" })
|
||||
|
@ -81,7 +81,7 @@ public class VolumeAndSnapshotApiLiveTest extends BaseCinderApiLiveTest {
|
|||
.name(name)
|
||||
.description("description of test volume");
|
||||
testVolume = volumeApi.create(100, options);
|
||||
|
||||
|
||||
assertTrue(VolumePredicates.awaitAvailable(volumeApi).apply(testVolume));
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list_simple.json")).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
Set<? extends Volume> volumes = api.list().toSet();
|
||||
assertEquals(volumes, ImmutableSet.of(testVolume()));
|
||||
|
@ -66,7 +66,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
Set<? extends Volume> volumes = api.list().toSet();
|
||||
assertTrue(volumes.isEmpty());
|
||||
|
@ -79,7 +79,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list_details.json")).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
Set<? extends Volume> volumes = api.listInDetail().toSet();
|
||||
assertEquals(volumes, ImmutableSet.of(testVolume()));
|
||||
|
@ -92,7 +92,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
Set<? extends Volume> volumes = api.listInDetail().toSet();
|
||||
assertTrue(volumes.isEmpty());
|
||||
|
@ -108,7 +108,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
.payload(payloadFromResourceWithContentType("/volume_create.json", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_create_response.json")).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
CreateVolumeOptions options = CreateVolumeOptions.Builder
|
||||
.name("jclouds-test-volume")
|
||||
|
@ -129,7 +129,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
.payload(payloadFromResourceWithContentType("/volume_create.json", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(404).payload(payloadFromResource("/volume_create_response.json")).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
CreateVolumeOptions options = CreateVolumeOptions.Builder
|
||||
.name("jclouds-test-volume")
|
||||
|
@ -144,7 +144,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_get.json")).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
Volume volume = api.get("60761c60-0f56-4499-b522-ff13e120af10");
|
||||
assertEquals(volume, testVolume());
|
||||
|
@ -163,7 +163,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
assertNull(api.get("60761c60-0f56-4499-b522-ff13e120af10"));
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
assertTrue(api.delete("60761c60-0f56-4499-b522-ff13e120af10"));
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ public class VolumeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getVolumeApiForZone("RegionOne");
|
||||
).getVolumeApi("RegionOne");
|
||||
|
||||
assertFalse(api.delete("60761c60-0f56-4499-b522-ff13e120af10"));
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class VolumeTypeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_list_simple.json")).build()
|
||||
).getVolumeTypeApiForZone("RegionOne");
|
||||
).getVolumeTypeApi("RegionOne");
|
||||
|
||||
Set<? extends VolumeType> types = api.list().toSet();
|
||||
assertEquals(types, ImmutableSet.of(testVolumeType()));
|
||||
|
@ -59,7 +59,7 @@ public class VolumeTypeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_get.json")).build()
|
||||
).getVolumeTypeApiForZone("RegionOne");
|
||||
).getVolumeTypeApi("RegionOne");
|
||||
|
||||
VolumeType type = api.get("1");
|
||||
assertEquals(type, testVolumeType());
|
||||
|
@ -72,7 +72,7 @@ public class VolumeTypeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getVolumeTypeApiForZone("RegionOne");
|
||||
).getVolumeTypeApi("RegionOne");
|
||||
|
||||
assertNull(api.get("X"));
|
||||
}
|
||||
|
|
|
@ -34,14 +34,14 @@ import com.google.common.collect.Iterables;
|
|||
@Test(groups = "live", testName = "VolumeTypeApiLiveTest", singleThreaded = true)
|
||||
public class VolumeTypeApiLiveTest extends BaseCinderApiLiveTest {
|
||||
private VolumeTypeApi volumeTypeApi;
|
||||
private String zone;
|
||||
private String region;
|
||||
|
||||
@BeforeGroups(groups = {"integration", "live"})
|
||||
@Override
|
||||
public void setup() {
|
||||
super.setup();
|
||||
zone = Iterables.getLast(api.getConfiguredZones(), "nova");
|
||||
volumeTypeApi = api.getVolumeTypeApiForZone(zone);
|
||||
region = Iterables.getLast(api.getConfiguredRegions(), "nova");
|
||||
volumeTypeApi = api.getVolumeTypeApi(region);
|
||||
}
|
||||
|
||||
@AfterClass(groups = { "integration", "live" })
|
||||
|
|
|
@ -80,7 +80,7 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
|||
* <li>add the above annotation to any {@link AsyncApi} classes by placing it on the type. ex.
|
||||
* {@code @Endpoint(CloudDNS.class)}</li>
|
||||
* <li>add the following to your {@link org.jclouds.rest.config.RestClientModule}</li>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* bind(new TypeLiteral<Supplier<URI>>() {
|
||||
* }).annotatedWith(CloudDNS.class).to(new TypeLiteral<Supplier<URI>>() {
|
||||
|
@ -148,6 +148,11 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated All OpenStack APIs rely on regions in jclouds 2.0 and this module will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
public static class ZoneModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
|
|
@ -106,7 +106,7 @@ public class KeystoneHttpApiModule extends HttpApiModule<KeystoneApi> {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
public LoadingCache<String, Set<? extends Extension>> provideExtensionsByZone(final javax.inject.Provider<KeystoneApi> keystoneApi) {
|
||||
public LoadingCache<String, Set<? extends Extension>> provideExtensionsByRegion(final javax.inject.Provider<KeystoneApi> keystoneApi) {
|
||||
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS)
|
||||
.build(CacheLoader.from(Suppliers.memoize(new Supplier<Set<? extends Extension>>() {
|
||||
@Override
|
||||
|
|
|
@ -148,7 +148,7 @@ public class KeystoneRestClientModule<S extends KeystoneApi, A extends KeystoneA
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
public LoadingCache<String, Set<? extends Extension>> provideExtensionsByZone(final javax.inject.Provider<KeystoneApi> keystoneApi) {
|
||||
public LoadingCache<String, Set<? extends Extension>> provideExtensionsByRegion(final javax.inject.Provider<KeystoneApi> keystoneApi) {
|
||||
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS)
|
||||
.build(CacheLoader.from(Suppliers.memoize(new Supplier<Set<? extends Extension>>() {
|
||||
@Override
|
||||
|
|
|
@ -54,7 +54,7 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio
|
|||
"Keypair Support").build();
|
||||
|
||||
@org.jclouds.openstack.v2_0.services.Extension(of = ServiceType.COMPUTE, namespace = "http://docs.openstack.org/ext/keypairs/api/v1.1")
|
||||
interface KeyPairAsyncApi {
|
||||
interface KeyPairApi {
|
||||
|
||||
}
|
||||
|
||||
|
@ -64,50 +64,50 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio
|
|||
"Floating IPs support").build();
|
||||
|
||||
@org.jclouds.openstack.v2_0.services.Extension(of = ServiceType.COMPUTE, namespace = "http://docs.openstack.org/ext/floating_ips/api/v1.1")
|
||||
interface FloatingIPAsyncApi {
|
||||
interface FloatingIPApi {
|
||||
|
||||
}
|
||||
|
||||
interface NovaAsyncApi {
|
||||
interface NovaApi {
|
||||
|
||||
@Delegate
|
||||
Optional<FloatingIPAsyncApi> getFloatingIPExtensionForZone(String zone);
|
||||
Optional<FloatingIPApi> getFloatingIPExtensionApi(String region);
|
||||
|
||||
@Delegate
|
||||
Optional<KeyPairAsyncApi> getKeyPairExtensionForZone(String zone);
|
||||
Optional<KeyPairApi> getKeyPairExtensionApi(String region);
|
||||
|
||||
}
|
||||
|
||||
InvocationSuccess getFloatingIPExtension(List<Object> args) throws SecurityException, NoSuchMethodException {
|
||||
return InvocationSuccess.create(
|
||||
Invocation.create(method(NovaAsyncApi.class, "getFloatingIPExtensionForZone", String.class), args), "foo");
|
||||
Invocation.create(method(NovaApi.class, "getFloatingIPExtensionApi", String.class), args), "foo");
|
||||
}
|
||||
|
||||
InvocationSuccess getKeyPairExtension(List<Object> args) throws SecurityException, NoSuchMethodException {
|
||||
return InvocationSuccess.create(
|
||||
Invocation.create(method(NovaAsyncApi.class, "getKeyPairExtensionForZone", String.class), args), "foo");
|
||||
Invocation.create(method(NovaApi.class, "getKeyPairExtensionApi", String.class), args), "foo");
|
||||
}
|
||||
|
||||
public void testPresentWhenExtensionsIncludeNamespaceFromAnnotationAbsentWhenNot() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
assertEquals(whenExtensionsInZoneInclude("zone", keypairs, floatingIps).apply(getFloatingIPExtension(ImmutableList.<Object> of("zone"))), Optional.of("foo"));
|
||||
assertEquals(whenExtensionsInZoneInclude("zone", keypairs, floatingIps).apply(getKeyPairExtension(ImmutableList.<Object> of("zone"))), Optional.of("foo"));
|
||||
assertEquals(whenExtensionsInZoneInclude("zone", keypairs).apply(getFloatingIPExtension(ImmutableList.<Object> of("zone"))), Optional.absent());
|
||||
assertEquals(whenExtensionsInZoneInclude("zone", floatingIps).apply(getKeyPairExtension(ImmutableList.<Object> of("zone"))), Optional.absent());
|
||||
assertEquals(whenExtensionsInRegionInclude("region", keypairs, floatingIps).apply(getFloatingIPExtension(ImmutableList.<Object> of("region"))), Optional.of("foo"));
|
||||
assertEquals(whenExtensionsInRegionInclude("region", keypairs, floatingIps).apply(getKeyPairExtension(ImmutableList.<Object> of("region"))), Optional.of("foo"));
|
||||
assertEquals(whenExtensionsInRegionInclude("region", keypairs).apply(getFloatingIPExtension(ImmutableList.<Object> of("region"))), Optional.absent());
|
||||
assertEquals(whenExtensionsInRegionInclude("region", floatingIps).apply(getKeyPairExtension(ImmutableList.<Object> of("region"))), Optional.absent());
|
||||
}
|
||||
|
||||
public void testZoneWithoutExtensionsReturnsAbsent() throws SecurityException, NoSuchMethodException {
|
||||
assertEquals(whenExtensionsInZoneInclude("zone", floatingIps).apply(
|
||||
getFloatingIPExtension(ImmutableList.<Object> of("differentzone"))), Optional.absent());
|
||||
assertEquals(whenExtensionsInZoneInclude("zone", keypairs).apply(
|
||||
getKeyPairExtension(ImmutableList.<Object> of("differentzone"))), Optional.absent());
|
||||
|
||||
public void testRegionWithoutExtensionsReturnsAbsent() throws SecurityException, NoSuchMethodException {
|
||||
assertEquals(whenExtensionsInRegionInclude("region", floatingIps).apply(
|
||||
getFloatingIPExtension(ImmutableList.<Object> of("differentregion"))), Optional.absent());
|
||||
assertEquals(whenExtensionsInRegionInclude("region", keypairs).apply(
|
||||
getKeyPairExtension(ImmutableList.<Object> of("differentregion"))), Optional.absent());
|
||||
}
|
||||
|
||||
/**
|
||||
* It is possible that the /extensions call returned the correct extension, but that the
|
||||
* namespaces were different, for whatever reason. One way to address this is to have a multimap
|
||||
* of the authoritative namespace to alternate onces, which could be wired up with guice
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void testPresentWhenAliasForExtensionMapsToNamespace() throws SecurityException, NoSuchMethodException {
|
||||
Extension keypairsWithDifferentNamespace = keypairs.toBuilder().namespace(
|
||||
|
@ -116,22 +116,22 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio
|
|||
Multimap<URI, URI> aliases = ImmutableMultimap.of(keypairs.getNamespace(), keypairsWithDifferentNamespace
|
||||
.getNamespace());
|
||||
|
||||
assertEquals(whenExtensionsAndAliasesInZoneInclude("zone", ImmutableSet.of(keypairsWithDifferentNamespace), aliases).apply(
|
||||
getKeyPairExtension(ImmutableList.<Object> of("zone"))), Optional.of("foo"));
|
||||
assertEquals(whenExtensionsAndAliasesInZoneInclude("zone", ImmutableSet.of(keypairsWithDifferentNamespace), aliases).apply(
|
||||
getFloatingIPExtension(ImmutableList.<Object> of("zone"))), Optional.absent());
|
||||
assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(keypairsWithDifferentNamespace), aliases).apply(
|
||||
getKeyPairExtension(ImmutableList.<Object> of("region"))), Optional.of("foo"));
|
||||
assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(keypairsWithDifferentNamespace), aliases).apply(
|
||||
getFloatingIPExtension(ImmutableList.<Object> of("region"))), Optional.absent());
|
||||
|
||||
}
|
||||
|
||||
private PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet whenExtensionsInZoneInclude(
|
||||
String zone, Extension... extensions) {
|
||||
return whenExtensionsAndAliasesInZoneInclude(zone, ImmutableSet.copyOf(extensions), ImmutableMultimap.<URI, URI> of());
|
||||
private PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet whenExtensionsInRegionInclude(
|
||||
String region, Extension... extensions) {
|
||||
return whenExtensionsAndAliasesInRegionInclude(region, ImmutableSet.copyOf(extensions), ImmutableMultimap.<URI, URI> of());
|
||||
}
|
||||
|
||||
private PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet whenExtensionsAndAliasesInZoneInclude(
|
||||
String zone, final Set<Extension> extensions, final Multimap<URI, URI> aliases) {
|
||||
final LoadingCache<String, Set<? extends Extension>> extensionsForZone = CacheBuilder.newBuilder().build(
|
||||
CacheLoader.from(Functions.forMap(ImmutableMap.<String, Set<? extends Extension>>of(zone, extensions, "differentzone",
|
||||
private PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet whenExtensionsAndAliasesInRegionInclude(
|
||||
String region, final Set<Extension> extensions, final Multimap<URI, URI> aliases) {
|
||||
final LoadingCache<String, Set<? extends Extension>> extensionsForRegion = CacheBuilder.newBuilder().build(
|
||||
CacheLoader.from(Functions.forMap(ImmutableMap.<String, Set<? extends Extension>>of(region, extensions, "differentregion",
|
||||
ImmutableSet.<Extension> of()))));
|
||||
|
||||
PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet fn = Guice.createInjector(
|
||||
|
@ -142,7 +142,7 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio
|
|||
|
||||
@Provides
|
||||
LoadingCache<String, Set<? extends Extension>> getExtensions() {
|
||||
return extensionsForZone;
|
||||
return extensionsForRegion;
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -150,7 +150,7 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio
|
|||
return aliases;
|
||||
}
|
||||
}).getInstance(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class);
|
||||
|
||||
|
||||
return fn;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ import java.io.Closeable;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.functions.ZoneToEndpoint;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.functions.RegionToEndpoint;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.AvailabilityZoneApi;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.ConsolesApi;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.FlavorExtraSpecsApi;
|
||||
|
@ -49,156 +49,413 @@ import com.google.common.base.Optional;
|
|||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Provides access to the OpenStack Compute (Nova) API.
|
||||
* Provides access to the OpenStack Compute (Nova) v2 API.
|
||||
* <p/>
|
||||
*
|
||||
*/
|
||||
public interface NovaApi extends Closeable {
|
||||
/**
|
||||
*
|
||||
* @return the Zone codes configured
|
||||
* @return the Region codes configured
|
||||
*/
|
||||
@Provides
|
||||
@Zone
|
||||
Set<String> getConfiguredZones();
|
||||
@Region
|
||||
Set<String> getConfiguredRegions();
|
||||
|
||||
/**
|
||||
* Provides access to Server features.
|
||||
*/
|
||||
@Delegate
|
||||
ServerApi getServerApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
ServerApi getServerApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Flavor features.
|
||||
*/
|
||||
@Delegate
|
||||
FlavorApi getFlavorApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
FlavorApi getFlavorApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Extension features.
|
||||
*/
|
||||
@Delegate
|
||||
ExtensionApi getExtensionApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
ExtensionApi getExtensionApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Image features.
|
||||
*/
|
||||
@Delegate
|
||||
ImageApi getImageApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
ImageApi getImageApi(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to availability zone features
|
||||
* Provides access to Availability Zone features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends AvailabilityZoneApi> getAvailabilityZoneApi(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Floating IP features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends FloatingIPApi> getFloatingIPExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends FloatingIPApi> getFloatingIPApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Security Group features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends SecurityGroupApi> getSecurityGroupExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends SecurityGroupApi> getSecurityGroupApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Key Pair features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends KeyPairApi> getKeyPairExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends KeyPairApi> getKeyPairApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Host Administration features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends HostAdministrationApi> getHostAdministrationExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends HostAdministrationApi> getHostAdministrationApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Simple Tenant Usage features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends SimpleTenantUsageApi> getSimpleTenantUsageExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends SimpleTenantUsageApi> getSimpleTenantUsageApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Virtual Interface features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends VirtualInterfaceApi> getVirtualInterfaceExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends VirtualInterfaceApi> getVirtualInterfaceApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Server Extra Data features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends ServerWithSecurityGroupsApi> getServerWithSecurityGroupsExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends ServerWithSecurityGroupsApi> getServerWithSecurityGroupsApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Server Admin Actions features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends ServerAdminApi> getServerAdminExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends ServerAdminApi> getServerAdminApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Aggregate features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends HostAggregateApi> getHostAggregateExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends HostAggregateApi> getHostAggregateApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Flavor extra specs features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends FlavorExtraSpecsApi> getFlavorExtraSpecsExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends FlavorExtraSpecsApi> getFlavorExtraSpecsApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Quota features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends QuotaApi> getQuotaExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends QuotaApi> getQuotaApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Volume features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends VolumeApi> getVolumeExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends VolumeApi> getVolumeApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Volume Attachment features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends VolumeAttachmentApi> getVolumeAttachmentExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
Optional<? extends VolumeAttachmentApi> getVolumeAttachmentApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Volume Type features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends VolumeTypeApi> getVolumeTypeApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Console features.
|
||||
*
|
||||
* <h3>NOTE</h3>
|
||||
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
|
||||
* to determine if it is present.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends ConsolesApi> getConsolesApi(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* @return the Zone codes configured
|
||||
* @deprecated Please use {@link #getConfiguredRegions()} as this method will be removed in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Provides
|
||||
@Region
|
||||
Set<String> getConfiguredZones();
|
||||
|
||||
/**
|
||||
* Provides access to Server features.
|
||||
* @deprecated Please use {@link #getServerApi(String)} as this method will be removed in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
ServerApi getServerApiForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Flavor features.
|
||||
* @deprecated Please use {@link #getFlavorApi(String)} as this method will be removed in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
FlavorApi getFlavorApiForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Extension features.
|
||||
* @deprecated Please use {@link #getExtensionApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
ExtensionApi getExtensionApiForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Image features.
|
||||
* @deprecated Please use {@link #getImageApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
ImageApi getImageApiForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Floating IP features.
|
||||
* @deprecated Please use {@link #getFloatingIPApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends FloatingIPApi> getFloatingIPExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Security Group features.
|
||||
* @deprecated Please use {@link #getSecurityGroupApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends SecurityGroupApi> getSecurityGroupExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Key Pair features.
|
||||
* @deprecated Please use {@link #getKeyPairApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends KeyPairApi> getKeyPairExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Host Administration features.
|
||||
* @deprecated Please use {@link #getHostAdministrationApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends HostAdministrationApi> getHostAdministrationExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Simple Tenant Usage features.
|
||||
* @deprecated Please use {@link #getSimpleTenantUsageApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends SimpleTenantUsageApi> getSimpleTenantUsageExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Virtual Interface features.
|
||||
* @deprecated Please use {@link #getVirtualInterfaceApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends VirtualInterfaceApi> getVirtualInterfaceExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Server Extra Data features.
|
||||
* @deprecated Please use {@link #getServerWithSecurityGroupsApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends ServerWithSecurityGroupsApi> getServerWithSecurityGroupsExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Server Admin Actions features.
|
||||
* @deprecated Please use {@link #getServerAdminApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends ServerAdminApi> getServerAdminExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Aggregate features.
|
||||
* @deprecated Please use {@link #getHostAggregateApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends HostAggregateApi> getHostAggregateExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Flavor extra specs features.
|
||||
* @deprecated Please use {@link #getFlavorExtraSpecsApi(String)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends FlavorExtraSpecsApi> getFlavorExtraSpecsExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Quota features.
|
||||
* @deprecated Please use {@link #getQuotaApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends QuotaApi> getQuotaExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Volume features.
|
||||
* @deprecated Please use {@link #getVolumeApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends VolumeApi> getVolumeExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Volume Attachment features.
|
||||
* @deprecated Please use {@link #getVolumeAttachmentApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends VolumeAttachmentApi> getVolumeAttachmentExtensionForZone(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Volume Type features.
|
||||
* @deprecated Please use {@link #getVolumeTypeApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends VolumeTypeApi> getVolumeTypeExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Console features.
|
||||
* @deprecated Please use {@link #getConsolesApi(String region)} as this method will be removed
|
||||
* in jclouds 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends ConsolesApi> getConsolesExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String zone);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.compute.ComputeServiceContext;
|
|||
import org.jclouds.openstack.keystone.v2_0.config.AuthenticationApiModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
|
||||
import org.jclouds.openstack.nova.v2_0.config.NovaHttpApiModule;
|
||||
import org.jclouds.openstack.nova.v2_0.config.NovaParserModule;
|
||||
|
@ -92,7 +92,7 @@ public class NovaApiMetadata extends BaseHttpApiMetadata<NovaApi> {
|
|||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(AuthenticationApiModule.class)
|
||||
.add(KeystoneAuthenticationModule.class)
|
||||
.add(ZoneModule.class)
|
||||
.add(RegionModule.class)
|
||||
.add(NovaParserModule.class)
|
||||
.add(NovaHttpApiModule.class)
|
||||
.add(NovaComputeServiceContextModule.class).build());
|
||||
|
|
|
@ -61,8 +61,8 @@ import org.jclouds.openstack.nova.v2_0.NovaApi;
|
|||
import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi;
|
||||
import org.jclouds.openstack.nova.v2_0.predicates.SecurityGroupPredicates;
|
||||
|
@ -81,9 +81,9 @@ import com.google.common.util.concurrent.ListeningExecutorService;
|
|||
@Singleton
|
||||
public class NovaComputeService extends BaseComputeService {
|
||||
protected final NovaApi novaApi;
|
||||
protected final LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupMap;
|
||||
protected final LoadingCache<ZoneAndName, KeyPair> keyPairCache;
|
||||
protected final Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByZoneId;
|
||||
protected final LoadingCache<RegionAndName, SecurityGroupInRegion> securityGroupMap;
|
||||
protected final LoadingCache<RegionAndName, KeyPair> keyPairCache;
|
||||
protected final Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByRegionId;
|
||||
protected final GroupNamingConvention.Factory namingConvention;
|
||||
|
||||
@Inject
|
||||
|
@ -102,9 +102,9 @@ public class NovaComputeService extends BaseComputeService {
|
|||
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
||||
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, NovaApi novaApi,
|
||||
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupMap,
|
||||
LoadingCache<ZoneAndName, KeyPair> keyPairCache,
|
||||
Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByZoneId,
|
||||
LoadingCache<RegionAndName, SecurityGroupInRegion> securityGroupMap,
|
||||
LoadingCache<RegionAndName, KeyPair> keyPairCache,
|
||||
Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByRegionId,
|
||||
GroupNamingConvention.Factory namingConvention, Optional<ImageExtension> imageExtension,
|
||||
Optional<SecurityGroupExtension> securityGroupExtension) {
|
||||
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
|
||||
|
@ -115,53 +115,53 @@ public class NovaComputeService extends BaseComputeService {
|
|||
this.novaApi = checkNotNull(novaApi, "novaApi");
|
||||
this.securityGroupMap = checkNotNull(securityGroupMap, "securityGroupMap");
|
||||
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
|
||||
this.orphanedGroupsByZoneId = checkNotNull(orphanedGroupsByZoneId, "orphanedGroupsByZoneId");
|
||||
this.orphanedGroupsByRegionId = checkNotNull(orphanedGroupsByRegionId, "orphanedGroupsByRegionId");
|
||||
this.namingConvention = checkNotNull(namingConvention, "namingConvention");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) {
|
||||
Multimap<String, String> zoneToZoneAndGroupNames = orphanedGroupsByZoneId.apply(deadNodes);
|
||||
for (Map.Entry<String, Collection<String>> entry : zoneToZoneAndGroupNames.asMap().entrySet()) {
|
||||
cleanOrphanedGroupsInZone(ImmutableSet.copyOf(entry.getValue()), entry.getKey());
|
||||
Multimap<String, String> regionToRegionAndGroupNames = orphanedGroupsByRegionId.apply(deadNodes);
|
||||
for (Map.Entry<String, Collection<String>> entry : regionToRegionAndGroupNames.asMap().entrySet()) {
|
||||
cleanOrphanedGroupsInRegion(ImmutableSet.copyOf(entry.getValue()), entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanOrphanedGroupsInZone(Set<String> groups, String zoneId) {
|
||||
cleanupOrphanedSecurityGroupsInZone(groups, zoneId);
|
||||
cleanupOrphanedKeyPairsInZone(groups, zoneId);
|
||||
protected void cleanOrphanedGroupsInRegion(Set<String> groups, String regionId) {
|
||||
cleanupOrphanedSecurityGroupsInRegion(groups, regionId);
|
||||
cleanupOrphanedKeyPairsInRegion(groups, regionId);
|
||||
}
|
||||
|
||||
private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) {
|
||||
Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId);
|
||||
private void cleanupOrphanedSecurityGroupsInRegion(Set<String> groups, String regionId) {
|
||||
Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupApi(regionId);
|
||||
if (securityGroupApi.isPresent()) {
|
||||
for (String group : groups) {
|
||||
for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().list(),
|
||||
SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) {
|
||||
ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName());
|
||||
logger.debug(">> deleting securityGroup(%s)", zoneAndName);
|
||||
RegionAndName regionAndName = RegionAndName.fromRegionAndName(regionId, securityGroup.getName());
|
||||
logger.debug(">> deleting securityGroup(%s)", regionAndName);
|
||||
securityGroupApi.get().delete(securityGroup.getId());
|
||||
// TODO: test this clear happens
|
||||
securityGroupMap.invalidate(zoneAndName);
|
||||
logger.debug("<< deleted securityGroup(%s)", zoneAndName);
|
||||
securityGroupMap.invalidate(regionAndName);
|
||||
logger.debug("<< deleted securityGroup(%s)", regionAndName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanupOrphanedKeyPairsInZone(Set<String> groups, String zoneId) {
|
||||
Optional<? extends KeyPairApi> keyPairApi = novaApi.getKeyPairExtensionForZone(zoneId);
|
||||
private void cleanupOrphanedKeyPairsInRegion(Set<String> groups, String regionId) {
|
||||
Optional<? extends KeyPairApi> keyPairApi = novaApi.getKeyPairApi(regionId);
|
||||
if (keyPairApi.isPresent()) {
|
||||
for (String group : groups) {
|
||||
for (KeyPair pair : keyPairApi.get().list().filter(nameMatches(namingConvention.create().containsGroup(group)))) {
|
||||
ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, pair.getName());
|
||||
logger.debug(">> deleting keypair(%s)", zoneAndName);
|
||||
RegionAndName regionAndName = RegionAndName.fromRegionAndName(regionId, pair.getName());
|
||||
logger.debug(">> deleting keypair(%s)", regionAndName);
|
||||
keyPairApi.get().delete(pair.getName());
|
||||
// TODO: test this clear happens
|
||||
keyPairCache.invalidate(zoneAndName);
|
||||
logger.debug("<< deleted keypair(%s)", zoneAndName);
|
||||
keyPairCache.invalidate(regionAndName);
|
||||
logger.debug("<< deleted keypair(%s)", regionAndName);
|
||||
}
|
||||
keyPairCache.invalidate(ZoneAndName.fromZoneAndName(zoneId,
|
||||
keyPairCache.invalidate(RegionAndName.fromRegionAndName(regionId,
|
||||
namingConvention.create().sharedNameForGroup(group)));
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,5 @@ public class NovaComputeService extends BaseComputeService {
|
|||
public NovaTemplateOptions templateOptions() {
|
||||
return NovaTemplateOptions.class.cast(super.templateOptions());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,22 +34,23 @@ import org.jclouds.compute.domain.Template;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.RemoveFloatingIpFromNodeAndDeallocate;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.strategy.ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Flavor;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Image;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.RebootType;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.ServerCreated;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.FlavorInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ImageInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.FlavorInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ImageInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
||||
import org.jclouds.openstack.nova.v2_0.predicates.ImagePredicates;
|
||||
|
||||
|
@ -67,23 +68,23 @@ import com.google.common.collect.ImmutableSet.Builder;
|
|||
* model to the computeService generic domain model.
|
||||
*/
|
||||
public class NovaComputeServiceAdapter implements
|
||||
ComputeServiceAdapter<ServerInZone, FlavorInZone, ImageInZone, Location> {
|
||||
ComputeServiceAdapter<ServerInRegion, FlavorInRegion, ImageInRegion, Location> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected final NovaApi novaApi;
|
||||
protected final Supplier<Set<String>> zoneIds;
|
||||
protected final Supplier<Set<String>> regionIds;
|
||||
protected final RemoveFloatingIpFromNodeAndDeallocate removeFloatingIpFromNodeAndDeallocate;
|
||||
protected final LoadingCache<ZoneAndName, KeyPair> keyPairCache;
|
||||
protected final LoadingCache<RegionAndName, KeyPair> keyPairCache;
|
||||
|
||||
@Inject
|
||||
public NovaComputeServiceAdapter(NovaApi novaApi, @Zone Supplier<Set<String>> zoneIds,
|
||||
public NovaComputeServiceAdapter(NovaApi novaApi, @Region Supplier<Set<String>> regionIds,
|
||||
RemoveFloatingIpFromNodeAndDeallocate removeFloatingIpFromNodeAndDeallocate,
|
||||
LoadingCache<ZoneAndName, KeyPair> keyPairCache) {
|
||||
LoadingCache<RegionAndName, KeyPair> keyPairCache) {
|
||||
this.novaApi = checkNotNull(novaApi, "novaApi");
|
||||
this.zoneIds = checkNotNull(zoneIds, "zoneIds");
|
||||
this.regionIds = checkNotNull(regionIds, "regionIds");
|
||||
this.removeFloatingIpFromNodeAndDeallocate = checkNotNull(removeFloatingIpFromNodeAndDeallocate,
|
||||
"removeFloatingIpFromNodeAndDeallocate");
|
||||
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
|
||||
|
@ -95,7 +96,7 @@ public class NovaComputeServiceAdapter implements
|
|||
* done so.
|
||||
*/
|
||||
@Override
|
||||
public NodeAndInitialCredentials<ServerInZone> createNodeWithGroupEncodedIntoName(String group, String name,
|
||||
public NodeAndInitialCredentials<ServerInRegion> createNodeWithGroupEncodedIntoName(String group, String name,
|
||||
Template template) {
|
||||
|
||||
LoginCredentials.Builder credentialsBuilder = LoginCredentials.builder();
|
||||
|
@ -118,40 +119,40 @@ public class NovaComputeServiceAdapter implements
|
|||
Optional<String> privateKey = Optional.absent();
|
||||
if (templateOptions.getKeyPairName() != null) {
|
||||
options.keyPairName(templateOptions.getKeyPairName());
|
||||
KeyPair keyPair = keyPairCache.getIfPresent(ZoneAndName.fromZoneAndName(template.getLocation().getId(), templateOptions.getKeyPairName()));
|
||||
KeyPair keyPair = keyPairCache.getIfPresent(RegionAndName.fromRegionAndName(template.getLocation().getId(), templateOptions.getKeyPairName()));
|
||||
if (keyPair != null && keyPair.getPrivateKey() != null) {
|
||||
privateKey = Optional.of(keyPair.getPrivateKey());
|
||||
credentialsBuilder.privateKey(privateKey.get());
|
||||
}
|
||||
}
|
||||
|
||||
String zoneId = template.getLocation().getId();
|
||||
String regionId = template.getLocation().getId();
|
||||
String imageId = template.getImage().getProviderId();
|
||||
String flavorId = template.getHardware().getProviderId();
|
||||
|
||||
logger.debug(">> creating new server zone(%s) name(%s) image(%s) flavor(%s) options(%s)", zoneId, name, imageId, flavorId, options);
|
||||
ServerCreated lightweightServer = novaApi.getServerApiForZone(zoneId).create(name, imageId, flavorId, options);
|
||||
Server server = novaApi.getServerApiForZone(zoneId).get(lightweightServer.getId());
|
||||
logger.debug(">> creating new server region(%s) name(%s) image(%s) flavor(%s) options(%s)", regionId, name, imageId, flavorId, options);
|
||||
ServerCreated lightweightServer = novaApi.getServerApi(regionId).create(name, imageId, flavorId, options);
|
||||
Server server = novaApi.getServerApi(regionId).get(lightweightServer.getId());
|
||||
|
||||
logger.trace("<< server(%s)", server.getId());
|
||||
|
||||
ServerInZone serverInZone = new ServerInZone(server, zoneId);
|
||||
ServerInRegion serverInRegion = new ServerInRegion(server, regionId);
|
||||
if (!privateKey.isPresent() && lightweightServer.getAdminPass().isPresent())
|
||||
credentialsBuilder.password(lightweightServer.getAdminPass().get());
|
||||
return new NodeAndInitialCredentials<ServerInZone>(serverInZone, serverInZone.slashEncode(), credentialsBuilder
|
||||
return new NodeAndInitialCredentials<ServerInRegion>(serverInRegion, serverInRegion.slashEncode(), credentialsBuilder
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<FlavorInZone> listHardwareProfiles() {
|
||||
Builder<FlavorInZone> builder = ImmutableSet.builder();
|
||||
for (final String zoneId : zoneIds.get()) {
|
||||
builder.addAll(transform(novaApi.getFlavorApiForZone(zoneId).listInDetail().concat(),
|
||||
new Function<Flavor, FlavorInZone>() {
|
||||
public Iterable<FlavorInRegion> listHardwareProfiles() {
|
||||
Builder<FlavorInRegion> builder = ImmutableSet.builder();
|
||||
for (final String regionId : regionIds.get()) {
|
||||
builder.addAll(transform(novaApi.getFlavorApi(regionId).listInDetail().concat(),
|
||||
new Function<Flavor, FlavorInRegion>() {
|
||||
|
||||
@Override
|
||||
public FlavorInZone apply(Flavor arg0) {
|
||||
return new FlavorInZone(arg0, zoneId);
|
||||
public FlavorInRegion apply(Flavor arg0) {
|
||||
return new FlavorInRegion(arg0, regionId);
|
||||
}
|
||||
|
||||
}));
|
||||
|
@ -160,19 +161,19 @@ public class NovaComputeServiceAdapter implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ImageInZone> listImages() {
|
||||
Builder<ImageInZone> builder = ImmutableSet.builder();
|
||||
Set<String> zones = zoneIds.get();
|
||||
checkState(zones.size() > 0, "no zones found in supplier %s", zoneIds);
|
||||
for (final String zoneId : zones) {
|
||||
Set<? extends Image> images = novaApi.getImageApiForZone(zoneId).listInDetail().concat().toSet();
|
||||
public Iterable<ImageInRegion> listImages() {
|
||||
Builder<ImageInRegion> builder = ImmutableSet.builder();
|
||||
Set<String> regions = regionIds.get();
|
||||
checkState(regions.size() > 0, "no regions found in supplier %s", regionIds);
|
||||
for (final String regionId : regions) {
|
||||
Set<? extends Image> images = novaApi.getImageApi(regionId).listInDetail().concat().toSet();
|
||||
if (images.size() == 0) {
|
||||
logger.debug("no images found in zone %s", zoneId);
|
||||
logger.debug("no images found in region %s", regionId);
|
||||
continue;
|
||||
}
|
||||
Iterable<? extends Image> active = filter(images, ImagePredicates.statusEquals(Image.Status.ACTIVE));
|
||||
if (images.size() == 0) {
|
||||
logger.debug("no images with status active in zone %s; non-active: %s", zoneId,
|
||||
logger.debug("no images with status active in region %s; non-active: %s", regionId,
|
||||
transform(active, new Function<Image, String>() {
|
||||
|
||||
@Override
|
||||
|
@ -184,11 +185,11 @@ public class NovaComputeServiceAdapter implements
|
|||
}));
|
||||
continue;
|
||||
}
|
||||
builder.addAll(transform(active, new Function<Image, ImageInZone>() {
|
||||
builder.addAll(transform(active, new Function<Image, ImageInRegion>() {
|
||||
|
||||
@Override
|
||||
public ImageInZone apply(Image arg0) {
|
||||
return new ImageInZone(arg0, zoneId);
|
||||
public ImageInRegion apply(Image arg0) {
|
||||
return new ImageInRegion(arg0, regionId);
|
||||
}
|
||||
|
||||
}));
|
||||
|
@ -197,15 +198,15 @@ public class NovaComputeServiceAdapter implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ServerInZone> listNodes() {
|
||||
Builder<ServerInZone> builder = ImmutableSet.builder();
|
||||
for (final String zoneId : zoneIds.get()) {
|
||||
builder.addAll(novaApi.getServerApiForZone(zoneId).listInDetail().concat()
|
||||
.transform(new Function<Server, ServerInZone>() {
|
||||
public Iterable<ServerInRegion> listNodes() {
|
||||
Builder<ServerInRegion> builder = ImmutableSet.builder();
|
||||
for (final String regionId : regionIds.get()) {
|
||||
builder.addAll(novaApi.getServerApi(regionId).listInDetail().concat()
|
||||
.transform(new Function<Server, ServerInRegion>() {
|
||||
|
||||
@Override
|
||||
public ServerInZone apply(Server arg0) {
|
||||
return new ServerInZone(arg0, zoneId);
|
||||
public ServerInRegion apply(Server arg0) {
|
||||
return new ServerInRegion(arg0, regionId);
|
||||
}
|
||||
|
||||
}));
|
||||
|
@ -214,11 +215,11 @@ public class NovaComputeServiceAdapter implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ServerInZone> listNodesByIds(final Iterable<String> ids) {
|
||||
return filter(listNodes(), new Predicate<ServerInZone>() {
|
||||
public Iterable<ServerInRegion> listNodesByIds(final Iterable<String> ids) {
|
||||
return filter(listNodes(), new Predicate<ServerInRegion>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(ServerInZone server) {
|
||||
public boolean apply(ServerInRegion server) {
|
||||
return contains(ids, server.slashEncode());
|
||||
}
|
||||
});
|
||||
|
@ -231,43 +232,43 @@ public class NovaComputeServiceAdapter implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public ServerInZone getNode(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
Server server = novaApi.getServerApiForZone(zoneAndId.getZone()).get(zoneAndId.getId());
|
||||
return server == null ? null : new ServerInZone(server, zoneAndId.getZone());
|
||||
public ServerInRegion getNode(String id) {
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
Server server = novaApi.getServerApi(regionAndId.getRegion()).get(regionAndId.getId());
|
||||
return server == null ? null : new ServerInRegion(server, regionAndId.getRegion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageInZone getImage(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
Image image = novaApi.getImageApiForZone(zoneAndId.getZone()).get(zoneAndId.getId());
|
||||
return image == null ? null : new ImageInZone(image, zoneAndId.getZone());
|
||||
public ImageInRegion getImage(String id) {
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
Image image = novaApi.getImageApi(regionAndId.getRegion()).get(regionAndId.getId());
|
||||
return image == null ? null : new ImageInRegion(image, regionAndId.getRegion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyNode(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
if (novaApi.getFloatingIPExtensionForZone(zoneAndId.getZone()).isPresent()) {
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
if (novaApi.getFloatingIPApi(regionAndId.getRegion()).isPresent()) {
|
||||
try {
|
||||
removeFloatingIpFromNodeAndDeallocate.apply(zoneAndId);
|
||||
removeFloatingIpFromNodeAndDeallocate.apply(regionAndId);
|
||||
} catch (RuntimeException e) {
|
||||
logger.warn(e, "<< error removing and deallocating ip from node(%s): %s", id, e.getMessage());
|
||||
}
|
||||
}
|
||||
novaApi.getServerApiForZone(zoneAndId.getZone()).delete(zoneAndId.getId());
|
||||
novaApi.getServerApi(regionAndId.getRegion()).delete(regionAndId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebootNode(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
novaApi.getServerApiForZone(zoneAndId.getZone()).reboot(zoneAndId.getId(), RebootType.HARD);
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
novaApi.getServerApi(regionAndId.getRegion()).reboot(regionAndId.getId(), RebootType.HARD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeNode(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
|
||||
novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId());
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
if (novaApi.getServerAdminApi(regionAndId.getRegion()).isPresent()) {
|
||||
novaApi.getServerAdminApi(regionAndId.getRegion()).get().resume(regionAndId.getId());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension");
|
||||
}
|
||||
|
@ -275,9 +276,9 @@ public class NovaComputeServiceAdapter implements
|
|||
|
||||
@Override
|
||||
public void suspendNode(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
|
||||
novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId());
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
if (novaApi.getServerAdminApi(regionAndId.getRegion()).isPresent()) {
|
||||
novaApi.getServerAdminApi(regionAndId.getRegion()).get().suspend(regionAndId.getId());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("suspend requires installation of the Admin Actions extension");
|
||||
}
|
||||
|
|
|
@ -52,14 +52,14 @@ import org.jclouds.openstack.nova.v2_0.compute.NovaComputeServiceAdapter;
|
|||
import org.jclouds.openstack.nova.v2_0.compute.extensions.NovaImageExtension;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.extensions.NovaSecurityGroupExtension;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.CreateSecurityGroupIfNeeded;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.FlavorInZoneToHardware;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.ImageInZoneToImage;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.FlavorInRegionToHardware;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.ImageInRegionToImage;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.ImageToOperatingSystem;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.NovaSecurityGroupInZoneToSecurityGroup;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.NovaSecurityGroupInRegionToSecurityGroup;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.NovaSecurityGroupToSecurityGroup;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.OrphanedGroupsByZoneId;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.OrphanedGroupsByRegionId;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.SecurityGroupRuleToIpPermission;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.ServerInZoneToNodeMetadata;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.functions.ServerInRegionToNodeMetadata;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.loaders.CreateUniqueKeyPair;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.loaders.FindSecurityGroupOrCreate;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.loaders.LoadFloatingIpsForInstance;
|
||||
|
@ -69,13 +69,13 @@ import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
|
|||
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.FlavorInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ImageInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.FlavorInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ImageInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.predicates.FindSecurityGroupWithNameAndReturnTrue;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -100,19 +100,19 @@ import com.google.inject.name.Names;
|
|||
* Module for building a compute service context for Nova
|
||||
*/
|
||||
public class NovaComputeServiceContextModule extends
|
||||
ComputeServiceAdapterContextModule<ServerInZone, FlavorInZone, ImageInZone, Location> {
|
||||
ComputeServiceAdapterContextModule<ServerInRegion, FlavorInRegion, ImageInRegion, Location> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(new TypeLiteral<ComputeServiceAdapter<ServerInZone, FlavorInZone, ImageInZone, Location>>() {
|
||||
bind(new TypeLiteral<ComputeServiceAdapter<ServerInRegion, FlavorInRegion, ImageInRegion, Location>>() {
|
||||
}).to(NovaComputeServiceAdapter.class);
|
||||
|
||||
bind(ComputeService.class).to(NovaComputeService.class);
|
||||
|
||||
bind(new TypeLiteral<Function<ServerInZone, NodeMetadata>>() {
|
||||
}).to(ServerInZoneToNodeMetadata.class);
|
||||
bind(new TypeLiteral<Function<ServerInRegion, NodeMetadata>>() {
|
||||
}).to(ServerInRegionToNodeMetadata.class);
|
||||
|
||||
bind(new TypeLiteral<Function<SecurityGroupRule, IpPermission>>() {
|
||||
}).to(SecurityGroupRuleToIpPermission.class);
|
||||
|
@ -120,19 +120,19 @@ public class NovaComputeServiceContextModule extends
|
|||
bind(new TypeLiteral<Function<org.jclouds.openstack.nova.v2_0.domain.SecurityGroup, SecurityGroup>>() {
|
||||
}).to(NovaSecurityGroupToSecurityGroup.class);
|
||||
|
||||
bind(new TypeLiteral<Function<SecurityGroupInZone, SecurityGroup>>() {
|
||||
}).to(NovaSecurityGroupInZoneToSecurityGroup.class);
|
||||
bind(new TypeLiteral<Function<SecurityGroupInRegion, SecurityGroup>>() {
|
||||
}).to(NovaSecurityGroupInRegionToSecurityGroup.class);
|
||||
|
||||
bind(new TypeLiteral<Function<Set<? extends NodeMetadata>, Multimap<String, String>>>() {
|
||||
}).to(OrphanedGroupsByZoneId.class);
|
||||
}).to(OrphanedGroupsByRegionId.class);
|
||||
|
||||
bind(new TypeLiteral<Function<ImageInZone, Image>>() {
|
||||
}).to(ImageInZoneToImage.class);
|
||||
bind(new TypeLiteral<Function<ImageInRegion, Image>>() {
|
||||
}).to(ImageInRegionToImage.class);
|
||||
bind(new TypeLiteral<Function<org.jclouds.openstack.nova.v2_0.domain.Image, OperatingSystem>>() {
|
||||
}).to(ImageToOperatingSystem.class);
|
||||
|
||||
bind(new TypeLiteral<Function<FlavorInZone, Hardware>>() {
|
||||
}).to(FlavorInZoneToHardware.class);
|
||||
bind(new TypeLiteral<Function<FlavorInRegion, Hardware>>() {
|
||||
}).to(FlavorInRegionToHardware.class);
|
||||
|
||||
// we aren't converting location from a provider-specific type
|
||||
bind(new TypeLiteral<Function<Location, Location>>() {
|
||||
|
@ -140,19 +140,19 @@ public class NovaComputeServiceContextModule extends
|
|||
|
||||
bind(TemplateOptions.class).to(NovaTemplateOptions.class);
|
||||
|
||||
bind(new TypeLiteral<CacheLoader<ZoneAndId, Iterable<? extends FloatingIP>>>() {
|
||||
bind(new TypeLiteral<CacheLoader<RegionAndId, Iterable<? extends FloatingIP>>>() {
|
||||
}).annotatedWith(Names.named("FLOATINGIP")).to(LoadFloatingIpsForInstance.class);
|
||||
|
||||
bind(new TypeLiteral<Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>>() {
|
||||
bind(new TypeLiteral<Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion>>() {
|
||||
}).to(CreateSecurityGroupIfNeeded.class);
|
||||
|
||||
bind(new TypeLiteral<CacheLoader<ZoneAndName, SecurityGroupInZone>>() {
|
||||
bind(new TypeLiteral<CacheLoader<RegionAndName, SecurityGroupInRegion>>() {
|
||||
}).to(FindSecurityGroupOrCreate.class);
|
||||
|
||||
bind(CreateNodesWithGroupEncodedIntoNameThenAddToSet.class).to(
|
||||
ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.class);
|
||||
|
||||
bind(new TypeLiteral<CacheLoader<ZoneAndName, KeyPair>>() {
|
||||
bind(new TypeLiteral<CacheLoader<RegionAndName, KeyPair>>() {
|
||||
}).to(CreateUniqueKeyPair.class);
|
||||
|
||||
bind(new TypeLiteral<ImageExtension>() {
|
||||
|
@ -174,15 +174,15 @@ public class NovaComputeServiceContextModule extends
|
|||
@Provides
|
||||
@Singleton
|
||||
@Named("FLOATINGIP")
|
||||
protected LoadingCache<ZoneAndId, Iterable<? extends FloatingIP>> instanceToFloatingIps(
|
||||
@Named("FLOATINGIP") CacheLoader<ZoneAndId, Iterable<? extends FloatingIP>> in) {
|
||||
protected LoadingCache<RegionAndId, Iterable<? extends FloatingIP>> instanceToFloatingIps(
|
||||
@Named("FLOATINGIP") CacheLoader<RegionAndId, Iterable<? extends FloatingIP>> in) {
|
||||
return CacheBuilder.newBuilder().build(in);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupMap(
|
||||
CacheLoader<ZoneAndName, SecurityGroupInZone> in) {
|
||||
protected LoadingCache<RegionAndName, SecurityGroupInRegion> securityGroupMap(
|
||||
CacheLoader<RegionAndName, SecurityGroupInRegion> in) {
|
||||
return CacheBuilder.newBuilder().build(in);
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ public class NovaComputeServiceContextModule extends
|
|||
@Provides
|
||||
@Singleton
|
||||
@Named("SECURITYGROUP_PRESENT")
|
||||
protected Predicate<AtomicReference<ZoneAndName>> securityGroupEventualConsistencyDelay(
|
||||
protected Predicate<AtomicReference<RegionAndName>> securityGroupEventualConsistencyDelay(
|
||||
FindSecurityGroupWithNameAndReturnTrue in,
|
||||
@Named(TIMEOUT_SECURITYGROUP_PRESENT) long msDelay) {
|
||||
return retry(in, msDelay, 100l, MILLISECONDS);
|
||||
|
@ -203,8 +203,8 @@ public class NovaComputeServiceContextModule extends
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected LoadingCache<ZoneAndName, KeyPair> keyPairMap(
|
||||
CacheLoader<ZoneAndName, KeyPair> in) {
|
||||
protected LoadingCache<RegionAndName, KeyPair> keyPairMap(
|
||||
CacheLoader<RegionAndName, KeyPair> in) {
|
||||
return CacheBuilder.newBuilder().build(in);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -82,10 +82,10 @@ public class NovaImageExtension implements ImageExtension {
|
|||
|
||||
@Override
|
||||
public ImageTemplate buildImageTemplateFromNode(String name, final String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
Server server = novaApi.getServerApiForZone(zoneAndId.getZone()).get(zoneAndId.getId());
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
Server server = novaApi.getServerApi(regionAndId.getRegion()).get(regionAndId.getId());
|
||||
if (server == null)
|
||||
throw new NoSuchElementException("Cannot find server with id: " + zoneAndId);
|
||||
throw new NoSuchElementException("Cannot find server with id: " + regionAndId);
|
||||
CloneImageTemplate template = new ImageTemplateBuilder.CloneImageTemplateBuilder().nodeId(id).name(name).build();
|
||||
return template;
|
||||
}
|
||||
|
@ -95,19 +95,19 @@ public class NovaImageExtension implements ImageExtension {
|
|||
checkState(template instanceof CloneImageTemplate,
|
||||
" openstack-nova only supports creating images through cloning.");
|
||||
CloneImageTemplate cloneTemplate = (CloneImageTemplate) template;
|
||||
ZoneAndId sourceImageZoneAndId = ZoneAndId.fromSlashEncoded(cloneTemplate.getSourceNodeId());
|
||||
RegionAndId sourceImageRegionAndId = RegionAndId.fromSlashEncoded(cloneTemplate.getSourceNodeId());
|
||||
|
||||
String newImageId = novaApi.getServerApiForZone(sourceImageZoneAndId.getZone()).createImageFromServer(
|
||||
cloneTemplate.getName(), sourceImageZoneAndId.getId());
|
||||
String newImageId = novaApi.getServerApi(sourceImageRegionAndId.getRegion()).createImageFromServer(
|
||||
cloneTemplate.getName(), sourceImageRegionAndId.getId());
|
||||
|
||||
final ZoneAndId targetImageZoneAndId = ZoneAndId.fromZoneAndId(sourceImageZoneAndId.getZone(), newImageId);
|
||||
final RegionAndId targetImageRegionAndId = RegionAndId.fromRegionAndId(sourceImageRegionAndId.getRegion(), newImageId);
|
||||
|
||||
logger.info(">> Registered new Image %s, waiting for it to become available.", newImageId);
|
||||
|
||||
|
||||
final AtomicReference<Image> image = Atomics.newReference(new ImageBuilder()
|
||||
.location(find(locations.get(), idEquals(targetImageZoneAndId.getZone())))
|
||||
.id(targetImageZoneAndId.slashEncode())
|
||||
.providerId(targetImageZoneAndId.getId())
|
||||
.location(find(locations.get(), idEquals(targetImageRegionAndId.getRegion())))
|
||||
.id(targetImageRegionAndId.slashEncode())
|
||||
.providerId(targetImageRegionAndId.getId())
|
||||
.description(cloneTemplate.getName())
|
||||
.operatingSystem(OperatingSystem.builder().description(cloneTemplate.getName()).build())
|
||||
.status(Image.Status.PENDING).build());
|
||||
|
@ -125,9 +125,9 @@ public class NovaImageExtension implements ImageExtension {
|
|||
|
||||
@Override
|
||||
public boolean deleteImage(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
try {
|
||||
this.novaApi.getImageApiForZone(zoneAndId.getZone()).delete(zoneAndId.getId());
|
||||
this.novaApi.getImageApi(regionAndId.getRegion()).delete(regionAndId.getId());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -40,17 +40,17 @@ import org.jclouds.compute.domain.SecurityGroup;
|
|||
import org.jclouds.compute.extensions.SecurityGroupExtension;
|
||||
import org.jclouds.compute.functions.GroupNamingConvention;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.net.domain.IpPermission;
|
||||
import org.jclouds.net.domain.IpProtocol;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Ingress;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.ServerWithSecurityGroups;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.ServerWithSecurityGroupsApi;
|
||||
|
||||
|
@ -70,22 +70,22 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
|
||||
protected final NovaApi api;
|
||||
protected final ListeningExecutorService userExecutor;
|
||||
protected final Supplier<Set<String>> zoneIds;
|
||||
protected final Function<SecurityGroupInZone, SecurityGroup> groupConverter;
|
||||
protected final LoadingCache<ZoneAndName, SecurityGroupInZone> groupCreator;
|
||||
protected final Supplier<Set<String>> regionIds;
|
||||
protected final Function<SecurityGroupInRegion, SecurityGroup> groupConverter;
|
||||
protected final LoadingCache<RegionAndName, SecurityGroupInRegion> groupCreator;
|
||||
protected final GroupNamingConvention.Factory namingConvention;
|
||||
|
||||
@Inject
|
||||
public NovaSecurityGroupExtension(NovaApi api,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
|
||||
@Zone Supplier<Set<String>> zoneIds,
|
||||
Function<SecurityGroupInZone, SecurityGroup> groupConverter,
|
||||
LoadingCache<ZoneAndName, SecurityGroupInZone> groupCreator,
|
||||
@Region Supplier<Set<String>> regionIds,
|
||||
Function<SecurityGroupInRegion, SecurityGroup> groupConverter,
|
||||
LoadingCache<RegionAndName, SecurityGroupInRegion> groupCreator,
|
||||
GroupNamingConvention.Factory namingConvention) {
|
||||
|
||||
this.api = checkNotNull(api, "api");
|
||||
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
|
||||
this.zoneIds = checkNotNull(zoneIds, "zoneIds");
|
||||
this.regionIds = checkNotNull(regionIds, "regionIds");
|
||||
this.groupConverter = checkNotNull(groupConverter, "groupConverter");
|
||||
this.groupCreator = checkNotNull(groupCreator, "groupCreator");
|
||||
this.namingConvention = checkNotNull(namingConvention, "namingConvention");
|
||||
|
@ -93,7 +93,7 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
|
||||
@Override
|
||||
public Set<SecurityGroup> listSecurityGroups() {
|
||||
Iterable<? extends SecurityGroupInZone> rawGroups = pollSecurityGroups();
|
||||
Iterable<? extends SecurityGroupInRegion> rawGroups = pollSecurityGroups();
|
||||
Iterable<SecurityGroup> groups = transform(filter(rawGroups, notNull()),
|
||||
groupConverter);
|
||||
return ImmutableSet.copyOf(groups);
|
||||
|
@ -102,15 +102,15 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
|
||||
@Override
|
||||
public Set<SecurityGroup> listSecurityGroupsInLocation(final Location location) {
|
||||
String zone = location.getId();
|
||||
if (zone == null) {
|
||||
String region = location.getId();
|
||||
if (region == null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
return listSecurityGroupsInLocation(zone);
|
||||
return listSecurityGroupsInLocation(region);
|
||||
}
|
||||
|
||||
public Set<SecurityGroup> listSecurityGroupsInLocation(String zone) {
|
||||
Iterable<? extends SecurityGroupInZone> rawGroups = pollSecurityGroupsByZone(zone);
|
||||
public Set<SecurityGroup> listSecurityGroupsInLocation(String region) {
|
||||
Iterable<? extends SecurityGroupInRegion> rawGroups = pollSecurityGroupsByRegion(region);
|
||||
Iterable<SecurityGroup> groups = transform(filter(rawGroups, notNull()),
|
||||
groupConverter);
|
||||
return ImmutableSet.copyOf(groups);
|
||||
|
@ -118,12 +118,12 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
|
||||
@Override
|
||||
public Set<SecurityGroup> listSecurityGroupsForNode(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(checkNotNull(id, "id"));
|
||||
String zone = zoneAndId.getZone();
|
||||
String instanceId = zoneAndId.getId();
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(checkNotNull(id, "id"));
|
||||
String region = regionAndId.getRegion();
|
||||
String instanceId = regionAndId.getId();
|
||||
|
||||
Optional<? extends ServerWithSecurityGroupsApi> serverApi = api.getServerWithSecurityGroupsExtensionForZone(zone);
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupExtensionForZone(zone);
|
||||
Optional<? extends ServerWithSecurityGroupsApi> serverApi = api.getServerWithSecurityGroupsApi(region);
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(region);
|
||||
|
||||
if (!serverApi.isPresent() || !sgApi.isPresent()) {
|
||||
return ImmutableSet.of();
|
||||
|
@ -135,54 +135,54 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
}
|
||||
|
||||
Set<String> groupNames = instance.getSecurityGroupNames();
|
||||
Set<? extends SecurityGroupInZone> rawGroups =
|
||||
sgApi.get().list().filter(nameIn(groupNames)).transform(groupToGroupInZone(zone)).toSet();
|
||||
Set<? extends SecurityGroupInRegion> rawGroups =
|
||||
sgApi.get().list().filter(nameIn(groupNames)).transform(groupToGroupInRegion(region)).toSet();
|
||||
|
||||
return ImmutableSet.copyOf(transform(filter(rawGroups, notNull()), groupConverter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecurityGroup getSecurityGroupById(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(checkNotNull(id, "id"));
|
||||
String zone = zoneAndId.getZone();
|
||||
String groupId = zoneAndId.getId();
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(checkNotNull(id, "id"));
|
||||
String region = regionAndId.getRegion();
|
||||
String groupId = regionAndId.getId();
|
||||
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupExtensionForZone(zone);
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(region);
|
||||
|
||||
if (!sgApi.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SecurityGroupInZone rawGroup = new SecurityGroupInZone(sgApi.get().get(groupId), zone);
|
||||
SecurityGroupInRegion rawGroup = new SecurityGroupInRegion(sgApi.get().get(groupId), region);
|
||||
|
||||
return groupConverter.apply(rawGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecurityGroup createSecurityGroup(String name, Location location) {
|
||||
String zone = location.getId();
|
||||
if (zone == null) {
|
||||
String region = location.getId();
|
||||
if (region == null) {
|
||||
return null;
|
||||
}
|
||||
return createSecurityGroup(name, zone);
|
||||
return createSecurityGroup(name, region);
|
||||
}
|
||||
|
||||
public SecurityGroup createSecurityGroup(String name, String zone) {
|
||||
public SecurityGroup createSecurityGroup(String name, String region) {
|
||||
String markerGroup = namingConvention.create().sharedNameForGroup(name);
|
||||
ZoneSecurityGroupNameAndPorts zoneAndName = new ZoneSecurityGroupNameAndPorts(zone, markerGroup, ImmutableSet.<Integer> of());
|
||||
RegionSecurityGroupNameAndPorts regionAndName = new RegionSecurityGroupNameAndPorts(region, markerGroup, ImmutableSet.<Integer> of());
|
||||
|
||||
SecurityGroupInZone rawGroup = groupCreator.getUnchecked(zoneAndName);
|
||||
SecurityGroupInRegion rawGroup = groupCreator.getUnchecked(regionAndName);
|
||||
return groupConverter.apply(rawGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeSecurityGroup(String id) {
|
||||
checkNotNull(id, "id");
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
String zone = zoneAndId.getZone();
|
||||
String groupId = zoneAndId.getId();
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
|
||||
String region = regionAndId.getRegion();
|
||||
String groupId = regionAndId.getId();
|
||||
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupExtensionForZone(zone);
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(region);
|
||||
|
||||
if (!sgApi.isPresent()) {
|
||||
return false;
|
||||
|
@ -194,16 +194,16 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
|
||||
sgApi.get().delete(groupId);
|
||||
// TODO: test this clear happens
|
||||
groupCreator.invalidate(new ZoneSecurityGroupNameAndPorts(zone, groupId, ImmutableSet.<Integer> of()));
|
||||
groupCreator.invalidate(new RegionSecurityGroupNameAndPorts(region, groupId, ImmutableSet.<Integer> of()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecurityGroup addIpPermission(IpPermission ipPermission, SecurityGroup group) {
|
||||
String zone = group.getLocation().getId();
|
||||
ZoneAndId groupZoneAndId = ZoneAndId.fromSlashEncoded(group.getId());
|
||||
String id = groupZoneAndId.getId();
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupExtensionForZone(zone);
|
||||
String region = group.getLocation().getId();
|
||||
RegionAndId groupRegionAndId = RegionAndId.fromSlashEncoded(group.getId());
|
||||
String id = groupRegionAndId.getId();
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(region);
|
||||
|
||||
if (!sgApi.isPresent()) {
|
||||
return null;
|
||||
|
@ -222,9 +222,9 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
}
|
||||
|
||||
if (ipPermission.getGroupIds().size() > 0) {
|
||||
for (String zoneAndGroupRaw : ipPermission.getGroupIds()) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(zoneAndGroupRaw);
|
||||
String groupId = zoneAndId.getId();
|
||||
for (String regionAndGroupRaw : ipPermission.getGroupIds()) {
|
||||
RegionAndId regionAndId = RegionAndId.fromSlashEncoded(regionAndGroupRaw);
|
||||
String groupId = regionAndId.getId();
|
||||
sgApi.get().createRuleAllowingSecurityGroupId(id,
|
||||
Ingress.builder()
|
||||
.ipProtocol(ipPermission.getIpProtocol())
|
||||
|
@ -235,7 +235,7 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
}
|
||||
}
|
||||
|
||||
return getSecurityGroupById(ZoneAndId.fromZoneAndId(zone, id).slashEncode());
|
||||
return getSecurityGroupById(RegionAndId.fromRegionAndId(region, id).slashEncode());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -256,11 +256,11 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
|
||||
@Override
|
||||
public SecurityGroup removeIpPermission(IpPermission ipPermission, SecurityGroup group) {
|
||||
String zone = group.getLocation().getId();
|
||||
ZoneAndId groupZoneAndId = ZoneAndId.fromSlashEncoded(group.getId());
|
||||
String id = groupZoneAndId.getId();
|
||||
String region = group.getLocation().getId();
|
||||
RegionAndId groupRegionAndId = RegionAndId.fromSlashEncoded(group.getId());
|
||||
String id = groupRegionAndId.getId();
|
||||
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupExtensionForZone(zone);
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(region);
|
||||
|
||||
if (!sgApi.isPresent()) {
|
||||
return null;
|
||||
|
@ -291,7 +291,7 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
}
|
||||
}
|
||||
|
||||
return getSecurityGroupById(ZoneAndId.fromZoneAndId(zone, id).slashEncode());
|
||||
return getSecurityGroupById(RegionAndId.fromRegionAndId(region, id).slashEncode());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -330,41 +330,41 @@ public class NovaSecurityGroupExtension implements SecurityGroupExtension {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected Iterable<? extends SecurityGroupInZone> pollSecurityGroups() {
|
||||
Iterable<? extends Set<? extends SecurityGroupInZone>> groups
|
||||
= transform(zoneIds.get(), allSecurityGroupsInZone());
|
||||
protected Iterable<? extends SecurityGroupInRegion> pollSecurityGroups() {
|
||||
Iterable<? extends Set<? extends SecurityGroupInRegion>> groups
|
||||
= transform(regionIds.get(), allSecurityGroupsInRegion());
|
||||
|
||||
return concat(groups);
|
||||
}
|
||||
|
||||
|
||||
protected Iterable<? extends SecurityGroupInZone> pollSecurityGroupsByZone(String zone) {
|
||||
return allSecurityGroupsInZone().apply(zone);
|
||||
protected Iterable<? extends SecurityGroupInRegion> pollSecurityGroupsByRegion(String region) {
|
||||
return allSecurityGroupsInRegion().apply(region);
|
||||
}
|
||||
|
||||
protected Function<String, Set<? extends SecurityGroupInZone>> allSecurityGroupsInZone() {
|
||||
return new Function<String, Set<? extends SecurityGroupInZone>>() {
|
||||
protected Function<String, Set<? extends SecurityGroupInRegion>> allSecurityGroupsInRegion() {
|
||||
return new Function<String, Set<? extends SecurityGroupInRegion>>() {
|
||||
|
||||
@Override
|
||||
public Set<? extends SecurityGroupInZone> apply(final String from) {
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupExtensionForZone(from);
|
||||
public Set<? extends SecurityGroupInRegion> apply(final String from) {
|
||||
Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(from);
|
||||
|
||||
if (!sgApi.isPresent()) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
|
||||
return sgApi.get().list().transform(groupToGroupInZone(from)).toSet();
|
||||
return sgApi.get().list().transform(groupToGroupInRegion(from)).toSet();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
protected Function<org.jclouds.openstack.nova.v2_0.domain.SecurityGroup, SecurityGroupInZone> groupToGroupInZone(final String zone) {
|
||||
return new Function<org.jclouds.openstack.nova.v2_0.domain.SecurityGroup, SecurityGroupInZone>() {
|
||||
protected Function<org.jclouds.openstack.nova.v2_0.domain.SecurityGroup, SecurityGroupInRegion> groupToGroupInRegion(final String region) {
|
||||
return new Function<org.jclouds.openstack.nova.v2_0.domain.SecurityGroup, SecurityGroupInRegion>() {
|
||||
@Override
|
||||
public SecurityGroupInZone apply(org.jclouds.openstack.nova.v2_0.domain.SecurityGroup group) {
|
||||
return new SecurityGroupInZone(group, zone);
|
||||
public SecurityGroupInRegion apply(org.jclouds.openstack.nova.v2_0.domain.SecurityGroup group) {
|
||||
return new SecurityGroupInRegion(group, region);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.options.NodeAndNovaTemplateOptions;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
|
||||
|
@ -60,11 +60,11 @@ public class AllocateAndAddFloatingIpToNode implements
|
|||
|
||||
private final Predicate<AtomicReference<NodeMetadata>> nodeRunning;
|
||||
private final NovaApi novaApi;
|
||||
private final LoadingCache<ZoneAndId, Iterable<? extends FloatingIP>> floatingIpCache;
|
||||
private final LoadingCache<RegionAndId, Iterable<? extends FloatingIP>> floatingIpCache;
|
||||
|
||||
@Inject
|
||||
public AllocateAndAddFloatingIpToNode(@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||
NovaApi novaApi, @Named("FLOATINGIP") LoadingCache<ZoneAndId, Iterable<? extends FloatingIP>> floatingIpCache) {
|
||||
NovaApi novaApi, @Named("FLOATINGIP") LoadingCache<RegionAndId, Iterable<? extends FloatingIP>> floatingIpCache) {
|
||||
this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning");
|
||||
this.novaApi = checkNotNull(novaApi, "novaApi");
|
||||
this.floatingIpCache = checkNotNull(floatingIpCache, "floatingIpCache");
|
||||
|
@ -75,8 +75,8 @@ public class AllocateAndAddFloatingIpToNode implements
|
|||
checkState(nodeRunning.apply(input.get().getNodeMetadata()), "node never achieved state running %s", input.get().getNodeMetadata());
|
||||
NodeMetadata node = input.get().getNodeMetadata().get();
|
||||
// node's location is a host
|
||||
String zoneId = node.getLocation().getParent().getId();
|
||||
FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(zoneId).get();
|
||||
String regionId = node.getLocation().getParent().getId();
|
||||
FloatingIPApi floatingIpApi = novaApi.getFloatingIPApi(regionId).get();
|
||||
Optional<Set<String>> poolNames = input.get().getNovaTemplateOptions().get().getFloatingIpPoolNames();
|
||||
|
||||
Optional<FloatingIP> ip = allocateFloatingIPForNode(floatingIpApi, poolNames, node.getId());
|
||||
|
@ -87,7 +87,7 @@ public class AllocateAndAddFloatingIpToNode implements
|
|||
|
||||
floatingIpApi.addToServer(ip.get().getIp(), node.getProviderId());
|
||||
input.get().getNodeMetadata().set(NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip.get().getIp())).build());
|
||||
floatingIpCache.invalidate(ZoneAndId.fromSlashEncoded(node.getId()));
|
||||
floatingIpCache.invalidate(RegionAndId.fromSlashEncoded(node.getId()));
|
||||
return input.get().getNodeMetadata();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,15 +32,15 @@ import org.jclouds.net.domain.IpProtocol;
|
|||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Ingress;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
@Singleton
|
||||
public class CreateSecurityGroupIfNeeded implements Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> {
|
||||
public class CreateSecurityGroupIfNeeded implements Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
@ -52,29 +52,29 @@ public class CreateSecurityGroupIfNeeded implements Function<ZoneSecurityGroupNa
|
|||
}
|
||||
|
||||
@Override
|
||||
public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts zoneSecurityGroupNameAndPorts) {
|
||||
checkNotNull(zoneSecurityGroupNameAndPorts, "zoneSecurityGroupNameAndPorts");
|
||||
public SecurityGroupInRegion apply(RegionSecurityGroupNameAndPorts regionSecurityGroupNameAndPorts) {
|
||||
checkNotNull(regionSecurityGroupNameAndPorts, "regionSecurityGroupNameAndPorts");
|
||||
|
||||
String zoneId = zoneSecurityGroupNameAndPorts.getZone();
|
||||
Optional<? extends SecurityGroupApi> api = novaApi.getSecurityGroupExtensionForZone(zoneId);
|
||||
checkArgument(api.isPresent(), "Security groups are required, but the extension is not availablein zone %s!", zoneId);
|
||||
logger.debug(">> creating securityGroup %s", zoneSecurityGroupNameAndPorts);
|
||||
String regionId = regionSecurityGroupNameAndPorts.getRegion();
|
||||
Optional<? extends SecurityGroupApi> api = novaApi.getSecurityGroupApi(regionId);
|
||||
checkArgument(api.isPresent(), "Security groups are required, but the extension is not available in region %s!", regionId);
|
||||
logger.debug(">> creating securityGroup %s", regionSecurityGroupNameAndPorts);
|
||||
try {
|
||||
|
||||
SecurityGroup securityGroup = api.get().createWithDescription(
|
||||
zoneSecurityGroupNameAndPorts.getName(), zoneSecurityGroupNameAndPorts.getName());
|
||||
regionSecurityGroupNameAndPorts.getName(), regionSecurityGroupNameAndPorts.getName());
|
||||
|
||||
logger.debug("<< created securityGroup(%s)", securityGroup);
|
||||
for (int port : zoneSecurityGroupNameAndPorts.getPorts()) {
|
||||
for (int port : regionSecurityGroupNameAndPorts.getPorts()) {
|
||||
authorizeGroupToItselfAndAllIPsToTCPPort(api.get(), securityGroup, port);
|
||||
}
|
||||
return new SecurityGroupInZone(api.get().get(securityGroup.getId()), zoneId);
|
||||
return new SecurityGroupInRegion(api.get().get(securityGroup.getId()), regionId);
|
||||
} catch (IllegalStateException e) {
|
||||
logger.trace("<< trying to find securityGroup(%s): %s", zoneSecurityGroupNameAndPorts, e.getMessage());
|
||||
SecurityGroup group = find(api.get().list(), nameEquals(zoneSecurityGroupNameAndPorts
|
||||
logger.trace("<< trying to find securityGroup(%s): %s", regionSecurityGroupNameAndPorts, e.getMessage());
|
||||
SecurityGroup group = find(api.get().list(), nameEquals(regionSecurityGroupNameAndPorts
|
||||
.getName()));
|
||||
logger.debug("<< reused securityGroup(%s)", group.getId());
|
||||
return new SecurityGroupInZone(group, zoneId);
|
||||
return new SecurityGroupInRegion(group, regionId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,29 +29,29 @@ import org.jclouds.compute.domain.Processor;
|
|||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Flavor;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.FlavorInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.FlavorInRegion;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* A function for transforming the nova specific FlavorInZone object to the generic Hardware object.
|
||||
* A function for transforming the nova specific FlavorInRegion object to the generic Hardware object.
|
||||
*/
|
||||
public class FlavorInZoneToHardware implements Function<FlavorInZone, Hardware> {
|
||||
public class FlavorInRegionToHardware implements Function<FlavorInRegion, Hardware> {
|
||||
|
||||
private final Supplier<Map<String, Location>> locationIndex;
|
||||
|
||||
@Inject
|
||||
public FlavorInZoneToHardware(Supplier<Map<String, Location>> locationIndex) {
|
||||
public FlavorInRegionToHardware(Supplier<Map<String, Location>> locationIndex) {
|
||||
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hardware apply(FlavorInZone flavorInZone) {
|
||||
Location location = locationIndex.get().get(flavorInZone.getZone());
|
||||
checkState(location != null, "location %s not in locationIndex: %s", flavorInZone.getZone(), locationIndex.get());
|
||||
Flavor flavor = flavorInZone.getFlavor();
|
||||
return new HardwareBuilder().id(flavorInZone.slashEncode()).providerId(flavor.getId()).name(flavor.getName())
|
||||
public Hardware apply(FlavorInRegion flavorInRegion) {
|
||||
Location location = locationIndex.get().get(flavorInRegion.getRegion());
|
||||
checkState(location != null, "location %s not in locationIndex: %s", flavorInRegion.getRegion(), locationIndex.get());
|
||||
Flavor flavor = flavorInRegion.getFlavor();
|
||||
return new HardwareBuilder().id(flavorInRegion.slashEncode()).providerId(flavor.getId()).name(flavor.getName())
|
||||
.ram(flavor.getRam()).processor(new Processor(flavor.getVcpus(), 1.0)).volume(
|
||||
new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(location).build();
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.jclouds.compute.domain.ImageBuilder;
|
|||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Image.Status;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ImageInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ImageInRegion;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
@ -37,13 +37,13 @@ import com.google.common.base.Supplier;
|
|||
/**
|
||||
* A function for transforming a nova-specific Image into a generic Image object.
|
||||
*/
|
||||
public class ImageInZoneToImage implements Function<ImageInZone, Image> {
|
||||
public class ImageInRegionToImage implements Function<ImageInRegion, Image> {
|
||||
private final Map<Status, org.jclouds.compute.domain.Image.Status> toPortableImageStatus;
|
||||
private final Function<org.jclouds.openstack.nova.v2_0.domain.Image, OperatingSystem> imageToOs;
|
||||
private final Supplier<Map<String, Location>> locationIndex;
|
||||
|
||||
@Inject
|
||||
public ImageInZoneToImage(Map<org.jclouds.openstack.nova.v2_0.domain.Image.Status, Image.Status> toPortableImageStatus,
|
||||
public ImageInRegionToImage(Map<org.jclouds.openstack.nova.v2_0.domain.Image.Status, Image.Status> toPortableImageStatus,
|
||||
Function<org.jclouds.openstack.nova.v2_0.domain.Image, OperatingSystem> imageToOs,
|
||||
Supplier<Map<String, Location>> locationIndex) {
|
||||
this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus");
|
||||
|
@ -52,15 +52,15 @@ public class ImageInZoneToImage implements Function<ImageInZone, Image> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Image apply(ImageInZone imageInZone) {
|
||||
Location location = locationIndex.get().get(imageInZone.getZone());
|
||||
checkState(location != null, "location %s not in locationIndex: %s", imageInZone.getZone(), locationIndex.get());
|
||||
org.jclouds.openstack.nova.v2_0.domain.Image image = imageInZone.getImage();
|
||||
return new ImageBuilder().id(imageInZone.slashEncode()).providerId(image.getId()).name(image.getName())
|
||||
public Image apply(ImageInRegion imageInRegion) {
|
||||
Location location = locationIndex.get().get(imageInRegion.getRegion());
|
||||
checkState(location != null, "location %s not in locationIndex: %s", imageInRegion.getRegion(), locationIndex.get());
|
||||
org.jclouds.openstack.nova.v2_0.domain.Image image = imageInRegion.getImage();
|
||||
return new ImageBuilder().id(imageInRegion.slashEncode()).providerId(image.getId()).name(image.getName())
|
||||
.userMetadata(image.getMetadata()).operatingSystem(imageToOs.apply(image)).description(image.getName())
|
||||
.location(location).status(toPortableImageStatus.get(image.getStatus())).build();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).toString();
|
|
@ -30,7 +30,7 @@ import org.jclouds.compute.domain.SecurityGroupBuilder;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -42,7 +42,7 @@ import com.google.inject.Inject;
|
|||
* SecurityGroup object.
|
||||
*/
|
||||
@Singleton
|
||||
public class NovaSecurityGroupInZoneToSecurityGroup implements Function<SecurityGroupInZone, SecurityGroup> {
|
||||
public class NovaSecurityGroupInRegionToSecurityGroup implements Function<SecurityGroupInRegion, SecurityGroup> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
@ -51,22 +51,22 @@ public class NovaSecurityGroupInZoneToSecurityGroup implements Function<Security
|
|||
protected final Supplier<Map<String, Location>> locationIndex;
|
||||
|
||||
@Inject
|
||||
public NovaSecurityGroupInZoneToSecurityGroup(Function<org.jclouds.openstack.nova.v2_0.domain.SecurityGroup, SecurityGroup> baseConverter,
|
||||
public NovaSecurityGroupInRegionToSecurityGroup(Function<org.jclouds.openstack.nova.v2_0.domain.SecurityGroup, SecurityGroup> baseConverter,
|
||||
Supplier<Map<String, Location>> locationIndex) {
|
||||
this.baseConverter = checkNotNull(baseConverter, "baseConverter");
|
||||
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecurityGroup apply(SecurityGroupInZone group) {
|
||||
public SecurityGroup apply(SecurityGroupInRegion group) {
|
||||
SecurityGroupBuilder builder = SecurityGroupBuilder.fromSecurityGroup(baseConverter.apply(group.getSecurityGroup()));
|
||||
|
||||
Location zone = locationIndex.get().get(group.getZone());
|
||||
checkState(zone != null, "location %s not in locationIndex: %s", group.getZone(), locationIndex.get());
|
||||
Location region = locationIndex.get().get(group.getRegion());
|
||||
checkState(region != null, "location %s not in locationIndex: %s", group.getRegion(), locationIndex.get());
|
||||
|
||||
builder.location(zone);
|
||||
builder.location(region);
|
||||
|
||||
builder.id(group.getZone() + "/" + group.getSecurityGroup().getId());
|
||||
builder.id(group.getRegion() + "/" + group.getSecurityGroup().getId());
|
||||
|
||||
return builder.build();
|
||||
}
|
|
@ -30,7 +30,7 @@ import org.jclouds.compute.domain.NodeMetadata;
|
|||
import org.jclouds.compute.predicates.NodePredicates;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.predicates.AllNodesInGroupTerminated;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
|
@ -39,35 +39,35 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
|
||||
public class OrphanedGroupsByZoneId implements Function<Set<? extends NodeMetadata>, Multimap<String, String>> {
|
||||
private final Predicate<ZoneAndName> allNodesInGroupTerminated;
|
||||
public class OrphanedGroupsByRegionId implements Function<Set<? extends NodeMetadata>, Multimap<String, String>> {
|
||||
private final Predicate<RegionAndName> allNodesInGroupTerminated;
|
||||
|
||||
@Inject
|
||||
protected OrphanedGroupsByZoneId(ComputeService computeService) {
|
||||
protected OrphanedGroupsByRegionId(ComputeService computeService) {
|
||||
this(new AllNodesInGroupTerminated(checkNotNull(computeService, "computeService")));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
OrphanedGroupsByZoneId(Predicate<ZoneAndName> allNodesInGroupTerminated) {
|
||||
OrphanedGroupsByRegionId(Predicate<RegionAndName> allNodesInGroupTerminated) {
|
||||
this.allNodesInGroupTerminated = checkNotNull(allNodesInGroupTerminated, "allNodesInGroupTerminated");
|
||||
}
|
||||
|
||||
public Multimap<String, String> apply(Set<? extends NodeMetadata> deadNodes) {
|
||||
Iterable<? extends NodeMetadata> nodesWithGroup = filter(deadNodes, NodePredicates.hasGroup());
|
||||
Set<ZoneAndName> zoneAndGroupNames = ImmutableSet.copyOf(filter(transform(nodesWithGroup,
|
||||
new Function<NodeMetadata, ZoneAndName>() {
|
||||
Set<RegionAndName> regionAndGroupNames = ImmutableSet.copyOf(filter(transform(nodesWithGroup,
|
||||
new Function<NodeMetadata, RegionAndName>() {
|
||||
|
||||
@Override
|
||||
public ZoneAndName apply(NodeMetadata input) {
|
||||
String zoneId = input.getLocation().getScope() == LocationScope.HOST ? input.getLocation()
|
||||
public RegionAndName apply(NodeMetadata input) {
|
||||
String regionId = input.getLocation().getScope() == LocationScope.HOST ? input.getLocation()
|
||||
.getParent().getId() : input.getLocation().getId();
|
||||
return ZoneAndName.fromZoneAndName(zoneId, input.getGroup());
|
||||
return RegionAndName.fromRegionAndName(regionId, input.getGroup());
|
||||
}
|
||||
|
||||
}), allNodesInGroupTerminated));
|
||||
Multimap<String, String> zoneToZoneAndGroupNames = Multimaps.transformValues(Multimaps.index(zoneAndGroupNames,
|
||||
ZoneAndName.ZONE_FUNCTION), ZoneAndName.NAME_FUNCTION);
|
||||
return zoneToZoneAndGroupNames;
|
||||
Multimap<String, String> regionToRegionAndGroupNames = Multimaps.transformValues(Multimaps.index(regionAndGroupNames,
|
||||
RegionAndName.REGION_FUNCTION), RegionAndName.NAME_FUNCTION);
|
||||
return regionToRegionAndGroupNames;
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -36,25 +36,25 @@ import com.google.common.cache.LoadingCache;
|
|||
/**
|
||||
* A function for removing and deallocating an ip address from a node
|
||||
*/
|
||||
public class RemoveFloatingIpFromNodeAndDeallocate implements Function<ZoneAndId, ZoneAndId> {
|
||||
public class RemoveFloatingIpFromNodeAndDeallocate implements Function<RegionAndId, RegionAndId> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final NovaApi novaApi;
|
||||
private final LoadingCache<ZoneAndId, Iterable<? extends FloatingIP>> floatingIpCache;
|
||||
private final LoadingCache<RegionAndId, Iterable<? extends FloatingIP>> floatingIpCache;
|
||||
|
||||
@Inject
|
||||
public RemoveFloatingIpFromNodeAndDeallocate(NovaApi novaApi,
|
||||
@Named("FLOATINGIP") LoadingCache<ZoneAndId, Iterable<? extends FloatingIP>> floatingIpCache) {
|
||||
@Named("FLOATINGIP") LoadingCache<RegionAndId, Iterable<? extends FloatingIP>> floatingIpCache) {
|
||||
this.novaApi = checkNotNull(novaApi, "novaApi");
|
||||
this.floatingIpCache = checkNotNull(floatingIpCache, "floatingIpCache");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneAndId apply(ZoneAndId id) {
|
||||
FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(id.getZone()).get();
|
||||
public RegionAndId apply(RegionAndId id) {
|
||||
FloatingIPApi floatingIpApi = novaApi.getFloatingIPApi(id.getRegion()).get();
|
||||
for (FloatingIP ip : floatingIpCache.getUnchecked(id)) {
|
||||
logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id);
|
||||
floatingIpApi.removeFromServer(ip.getIp(), id.getId());
|
||||
|
|
|
@ -32,8 +32,8 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.net.domain.IpPermission;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -50,16 +50,16 @@ public class SecurityGroupRuleToIpPermission implements Function<SecurityGroupRu
|
|||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
protected final Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone;
|
||||
protected final Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion;
|
||||
protected final Supplier<Map<String, Location>> locationIndex;
|
||||
LoadingCache<ZoneAndName, SecurityGroupInZone> groupMap;
|
||||
LoadingCache<RegionAndName, SecurityGroupInRegion> groupMap;
|
||||
|
||||
@Inject
|
||||
public SecurityGroupRuleToIpPermission(@Named("SECURITYGROUP_PRESENT") Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone,
|
||||
public SecurityGroupRuleToIpPermission(@Named("SECURITYGROUP_PRESENT") Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion,
|
||||
Supplier<Map<String, Location>> locationIndex,
|
||||
LoadingCache<ZoneAndName, SecurityGroupInZone> groupMap) {
|
||||
this.returnSecurityGroupExistsInZone = checkNotNull(returnSecurityGroupExistsInZone,
|
||||
"returnSecurityGroupExistsInZone");
|
||||
LoadingCache<RegionAndName, SecurityGroupInRegion> groupMap) {
|
||||
this.returnSecurityGroupExistsInRegion = checkNotNull(returnSecurityGroupExistsInRegion,
|
||||
"returnSecurityGroupExistsInRegion");
|
||||
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
|
||||
this.groupMap = checkNotNull(groupMap, "groupMap");
|
||||
}
|
||||
|
@ -71,26 +71,26 @@ public class SecurityGroupRuleToIpPermission implements Function<SecurityGroupRu
|
|||
builder.fromPort(rule.getFromPort());
|
||||
builder.toPort(rule.getToPort());
|
||||
if (rule.getGroup() != null) {
|
||||
String zone = getFirst(filter(locationIndex.get().keySet(), isSecurityGroupInZone(rule.getGroup().getName())),
|
||||
String region = getFirst(filter(locationIndex.get().keySet(), isSecurityGroupInRegion(rule.getGroup().getName())),
|
||||
null);
|
||||
if (zone != null) {
|
||||
SecurityGroupInZone group = groupMap.getUnchecked(ZoneAndName.fromZoneAndName(zone, rule.getGroup().getName()));
|
||||
builder.groupId(zone + "/" + group.getSecurityGroup().getId());
|
||||
if (region != null) {
|
||||
SecurityGroupInRegion group = groupMap.getUnchecked(RegionAndName.fromRegionAndName(region, rule.getGroup().getName()));
|
||||
builder.groupId(region + "/" + group.getSecurityGroup().getId());
|
||||
}
|
||||
}
|
||||
if (rule.getIpRange() != null)
|
||||
builder.cidrBlock(rule.getIpRange());
|
||||
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected Predicate<String> isSecurityGroupInZone(final String groupName) {
|
||||
protected Predicate<String> isSecurityGroupInRegion(final String groupName) {
|
||||
return new Predicate<String>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(String zone) {
|
||||
AtomicReference<ZoneAndName> securityGroupInZoneRef = Atomics.newReference(ZoneAndName.fromZoneAndName(zone, groupName));
|
||||
return returnSecurityGroupExistsInZone.apply(securityGroupInZoneRef);
|
||||
public boolean apply(String region) {
|
||||
AtomicReference<RegionAndName> securityGroupInRegionRef = Atomics.newReference(RegionAndName.fromRegionAndName(region, groupName));
|
||||
return returnSecurityGroupExistsInRegion.apply(securityGroupInRegionRef);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.openstack.nova.v2_0.domain.Address;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Server.Status;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
import org.jclouds.util.InetAddresses2;
|
||||
|
||||
|
@ -67,11 +67,11 @@ import com.google.common.net.InetAddresses;
|
|||
* A function for transforming a nova-specific Server into a generic
|
||||
* NodeMetadata object.
|
||||
*/
|
||||
public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMetadata> {
|
||||
public class ServerInRegionToNodeMetadata implements Function<ServerInRegion, NodeMetadata> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
|
||||
protected Map<Status, org.jclouds.compute.domain.NodeMetadata.Status> toPortableNodeStatus;
|
||||
protected final Supplier<Map<String, Location>> locationIndex;
|
||||
protected final Supplier<Set<? extends Image>> images;
|
||||
|
@ -79,7 +79,7 @@ public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMe
|
|||
protected final GroupNamingConvention nodeNamingConvention;
|
||||
|
||||
@Inject
|
||||
public ServerInZoneToNodeMetadata(Map<Server.Status, NodeMetadata.Status> toPortableNodeStatus,
|
||||
public ServerInRegionToNodeMetadata(Map<Server.Status, NodeMetadata.Status> toPortableNodeStatus,
|
||||
Supplier<Map<String, Location>> locationIndex, @Memoized Supplier<Set<? extends Image>> images,
|
||||
@Memoized Supplier<Set<? extends Hardware>> hardwares, GroupNamingConvention.Factory namingConvention) {
|
||||
this.toPortableNodeStatus = checkNotNull(toPortableNodeStatus, "toPortableNodeStatus");
|
||||
|
@ -90,27 +90,27 @@ public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMe
|
|||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(ServerInZone serverInZone) {
|
||||
Location zone = locationIndex.get().get(serverInZone.getZone());
|
||||
checkState(zone != null, "location %s not in locationIndex: %s", serverInZone.getZone(), locationIndex.get());
|
||||
Server from = serverInZone.getServer();
|
||||
public NodeMetadata apply(ServerInRegion serverInRegion) {
|
||||
Location region = locationIndex.get().get(serverInRegion.getRegion());
|
||||
checkState(region != null, "location %s not in locationIndex: %s", serverInRegion.getRegion(), locationIndex.get());
|
||||
Server from = serverInRegion.getServer();
|
||||
|
||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
builder.id(serverInZone.slashEncode());
|
||||
builder.id(serverInRegion.slashEncode());
|
||||
builder.providerId(from.getId());
|
||||
builder.name(from.getName());
|
||||
builder.hostname(from.getName());
|
||||
builder.location(from.getHostId() != null ? new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId())
|
||||
.description(from.getHostId()).parent(zone).build() : zone);
|
||||
.description(from.getHostId()).parent(region).build() : region);
|
||||
builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention));
|
||||
addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata());
|
||||
|
||||
if (from.getImage() != null) {
|
||||
builder.imageId(ZoneAndId.fromZoneAndId(serverInZone.getZone(), from.getImage().getId()).slashEncode());
|
||||
builder.imageId(RegionAndId.fromRegionAndId(serverInRegion.getRegion(), from.getImage().getId()).slashEncode());
|
||||
}
|
||||
|
||||
builder.operatingSystem(findOperatingSystemForServerOrNull(serverInZone));
|
||||
builder.hardware(findHardwareForServerOrNull(serverInZone));
|
||||
builder.operatingSystem(findOperatingSystemForServerOrNull(serverInRegion));
|
||||
builder.hardware(findHardwareForServerOrNull(serverInRegion));
|
||||
builder.status(toPortableNodeStatus.get(from.getStatus()));
|
||||
|
||||
Set<Address> addresses = newHashSet(from.getAddresses().values());
|
||||
|
@ -140,16 +140,16 @@ public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMe
|
|||
builder.uri(link.getHref());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
private static final Predicate<Address> isPrivateAddress = new Predicate<Address>() {
|
||||
public boolean apply(Address in) {
|
||||
return InetAddresses2.IsPrivateIPAddress.INSTANCE.apply(in.getAddr());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static final Predicate<String> isInet4Address = new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
|
@ -172,15 +172,15 @@ public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMe
|
|||
}
|
||||
}
|
||||
|
||||
protected Hardware findHardwareForServerOrNull(ServerInZone serverInZone) {
|
||||
return findObjectOfTypeForServerOrNull(hardwares.get(), "hardware", serverInZone.getServer().getFlavor().getId(),
|
||||
serverInZone);
|
||||
protected Hardware findHardwareForServerOrNull(ServerInRegion serverInRegion) {
|
||||
return findObjectOfTypeForServerOrNull(hardwares.get(), "hardware", serverInRegion.getServer().getFlavor().getId(),
|
||||
serverInRegion);
|
||||
}
|
||||
|
||||
protected OperatingSystem findOperatingSystemForServerOrNull(ServerInZone serverInZone) {
|
||||
if (serverInZone.getServer().getImage() != null) {
|
||||
protected OperatingSystem findOperatingSystemForServerOrNull(ServerInRegion serverInRegion) {
|
||||
if (serverInRegion.getServer().getImage() != null) {
|
||||
Image image = findObjectOfTypeForServerOrNull(
|
||||
images.get(), "image", serverInZone.getServer().getImage().getId(), serverInZone);
|
||||
images.get(), "image", serverInRegion.getServer().getImage().getId(), serverInRegion);
|
||||
|
||||
return (image != null) ? image.getOperatingSystem() : null;
|
||||
} else {
|
||||
|
@ -190,16 +190,16 @@ public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMe
|
|||
}
|
||||
|
||||
public <T extends ComputeMetadata> T findObjectOfTypeForServerOrNull(Set<? extends T> supply, String type,
|
||||
final String objectId, final ZoneAndId serverInZone) {
|
||||
final String objectId, final RegionAndId serverInRegion) {
|
||||
try {
|
||||
return find(supply, new Predicate<T>() {
|
||||
@Override
|
||||
public boolean apply(T input) {
|
||||
return input.getId().equals(ZoneAndId.fromZoneAndId(serverInZone.getZone(), objectId).slashEncode());
|
||||
return input.getId().equals(RegionAndId.fromRegionAndId(serverInRegion.getRegion(), objectId).slashEncode());
|
||||
}
|
||||
});
|
||||
} catch (NoSuchElementException e) {
|
||||
logger.trace("could not find %s with id(%s) for server(%s)", type, objectId, serverInZone);
|
||||
logger.trace("could not find %s with id(%s) for server(%s)", type, objectId, serverInRegion);
|
||||
}
|
||||
return null;
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
@ -36,7 +36,7 @@ import com.google.common.cache.CacheLoader;
|
|||
import com.google.inject.Inject;
|
||||
|
||||
@Singleton
|
||||
public class CreateUniqueKeyPair extends CacheLoader<ZoneAndName, KeyPair> {
|
||||
public class CreateUniqueKeyPair extends CacheLoader<RegionAndName, KeyPair> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
@ -50,15 +50,15 @@ public class CreateUniqueKeyPair extends CacheLoader<ZoneAndName, KeyPair> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public KeyPair load(ZoneAndName zoneAndName) {
|
||||
String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone();
|
||||
String prefix = zoneAndName.getName();
|
||||
public KeyPair load(RegionAndName regionAndName) {
|
||||
String regionId = checkNotNull(regionAndName, "regionAndName").getRegion();
|
||||
String prefix = regionAndName.getName();
|
||||
|
||||
Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId);
|
||||
checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!",
|
||||
zoneId);
|
||||
Optional<? extends KeyPairApi> api = novaApi.getKeyPairApi(regionId);
|
||||
checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in region %s!",
|
||||
regionId);
|
||||
|
||||
logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix);
|
||||
logger.debug(">> creating keyPair region(%s) prefix(%s)", regionId, prefix);
|
||||
|
||||
KeyPair keyPair = null;
|
||||
while (keyPair == null) {
|
||||
|
|
|
@ -23,60 +23,60 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.util.concurrent.Atomics;
|
||||
|
||||
public class FindSecurityGroupOrCreate extends CacheLoader<ZoneAndName, SecurityGroupInZone> {
|
||||
public class FindSecurityGroupOrCreate extends CacheLoader<RegionAndName, SecurityGroupInRegion> {
|
||||
|
||||
protected final Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone;
|
||||
protected final Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator;
|
||||
protected final Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion;
|
||||
protected final Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion> groupCreator;
|
||||
|
||||
@Inject
|
||||
public FindSecurityGroupOrCreate(
|
||||
@Named("SECURITYGROUP_PRESENT") Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone,
|
||||
Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator) {
|
||||
this.returnSecurityGroupExistsInZone = checkNotNull(returnSecurityGroupExistsInZone,
|
||||
"returnSecurityGroupExistsInZone");
|
||||
@Named("SECURITYGROUP_PRESENT") Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion,
|
||||
Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion> groupCreator) {
|
||||
this.returnSecurityGroupExistsInRegion = checkNotNull(returnSecurityGroupExistsInRegion,
|
||||
"returnSecurityGroupExistsInRegion");
|
||||
this.groupCreator = checkNotNull(groupCreator, "groupCreator");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecurityGroupInZone load(ZoneAndName in) {
|
||||
AtomicReference<ZoneAndName> securityGroupInZoneRef = Atomics.newReference(checkNotNull(in,
|
||||
"zoneSecurityGroupNameAndPorts"));
|
||||
if (returnSecurityGroupExistsInZone.apply(securityGroupInZoneRef)) {
|
||||
return returnExistingSecurityGroup(securityGroupInZoneRef);
|
||||
public SecurityGroupInRegion load(RegionAndName in) {
|
||||
AtomicReference<RegionAndName> securityGroupInRegionRef = Atomics.newReference(checkNotNull(in,
|
||||
"regionSecurityGroupNameAndPorts"));
|
||||
if (returnSecurityGroupExistsInRegion.apply(securityGroupInRegionRef)) {
|
||||
return returnExistingSecurityGroup(securityGroupInRegionRef);
|
||||
} else {
|
||||
return createNewSecurityGroup(in);
|
||||
}
|
||||
}
|
||||
|
||||
private SecurityGroupInZone returnExistingSecurityGroup(AtomicReference<ZoneAndName> securityGroupInZoneRef) {
|
||||
ZoneAndName securityGroupInZone = securityGroupInZoneRef.get();
|
||||
checkState(securityGroupInZone instanceof SecurityGroupInZone,
|
||||
private SecurityGroupInRegion returnExistingSecurityGroup(AtomicReference<RegionAndName> securityGroupInRegionRef) {
|
||||
RegionAndName securityGroupInRegion = securityGroupInRegionRef.get();
|
||||
checkState(securityGroupInRegion instanceof SecurityGroupInRegion,
|
||||
"programming error: predicate %s should update the atomic reference to the actual security group found",
|
||||
returnSecurityGroupExistsInZone);
|
||||
return SecurityGroupInZone.class.cast(securityGroupInZone);
|
||||
returnSecurityGroupExistsInRegion);
|
||||
return SecurityGroupInRegion.class.cast(securityGroupInRegion);
|
||||
}
|
||||
|
||||
private SecurityGroupInZone createNewSecurityGroup(ZoneAndName in) {
|
||||
private SecurityGroupInRegion createNewSecurityGroup(RegionAndName in) {
|
||||
checkState(
|
||||
checkNotNull(in, "zoneSecurityGroupNameAndPorts") instanceof ZoneSecurityGroupNameAndPorts,
|
||||
"programming error: when issuing get to this cacheloader, you need to pass an instance of ZoneSecurityGroupNameAndPorts, not %s",
|
||||
checkNotNull(in, "regionSecurityGroupNameAndPorts") instanceof RegionSecurityGroupNameAndPorts,
|
||||
"programming error: when issuing get to this cacheloader, you need to pass an instance of RegionSecurityGroupNameAndPorts, not %s",
|
||||
in);
|
||||
ZoneSecurityGroupNameAndPorts zoneSecurityGroupNameAndPorts = ZoneSecurityGroupNameAndPorts.class.cast(in);
|
||||
return groupCreator.apply(zoneSecurityGroupNameAndPorts);
|
||||
RegionSecurityGroupNameAndPorts regionSecurityGroupNameAndPorts = RegionSecurityGroupNameAndPorts.class.cast(in);
|
||||
return groupCreator.apply(regionSecurityGroupNameAndPorts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "returnExistingSecurityGroupInZoneOrCreateAsNeeded()";
|
||||
return "returnExistingSecurityGroupInRegionOrCreateAsNeeded()";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
@ -30,12 +30,12 @@ import com.google.common.cache.CacheLoader;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Each zone may or may not have the floating ip function present. In order to safely proceed, we
|
||||
* must allow the user to determine if a zone has floating ip services before attempting to use
|
||||
* Each region may or may not have the floating ip function present. In order to safely proceed, we
|
||||
* must allow the user to determine if a region has floating ip services before attempting to use
|
||||
* them.
|
||||
*/
|
||||
@Singleton
|
||||
public class LoadFloatingIpsForInstance extends CacheLoader<ZoneAndId, Iterable<? extends FloatingIP>> {
|
||||
public class LoadFloatingIpsForInstance extends CacheLoader<RegionAndId, Iterable<? extends FloatingIP>> {
|
||||
private final NovaApi api;
|
||||
|
||||
@Inject
|
||||
|
@ -44,9 +44,9 @@ public class LoadFloatingIpsForInstance extends CacheLoader<ZoneAndId, Iterable<
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends FloatingIP> load(final ZoneAndId key) throws Exception {
|
||||
String zone = key.getZone();
|
||||
Optional<? extends FloatingIPApi> ipApiOptional = api.getFloatingIPExtensionForZone(zone);
|
||||
public Iterable<? extends FloatingIP> load(final RegionAndId key) throws Exception {
|
||||
String region = key.getRegion();
|
||||
Optional<? extends FloatingIPApi> ipApiOptional = api.getFloatingIPApi(region);
|
||||
if (ipApiOptional.isPresent()) {
|
||||
return ipApiOptional.get().list().filter(
|
||||
new Predicate<FloatingIP>() {
|
||||
|
|
|
@ -196,10 +196,10 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
|
||||
/**
|
||||
* <h3>Note</h3>
|
||||
*
|
||||
* This requires that {@link NovaApi#getExtensionForZone(String)} to return
|
||||
*
|
||||
* This requires that {@link NovaApi#getExtensionForRegion(String)} to return
|
||||
* {@link Optional#isPresent present}
|
||||
*
|
||||
*
|
||||
* @return true if auto assignment of a floating ip to each vm is enabled
|
||||
*/
|
||||
public boolean shouldAutoAssignFloatingIp() {
|
||||
|
@ -229,7 +229,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
/**
|
||||
* <h3>Note</h3>
|
||||
*
|
||||
* This requires that {@link NovaApi#getKeyPairExtensionForZone(String)} to return
|
||||
* This requires that {@link NovaApi#getKeyPairExtensionApi(String)} to return
|
||||
* {@link Optional#isPresent present}
|
||||
*
|
||||
* @return true if auto generation of keypairs is enabled
|
||||
|
@ -241,7 +241,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
/**
|
||||
* if unset, generate a default group prefixed with {@link jclouds#} according
|
||||
* to {@link #getInboundPorts()}
|
||||
*
|
||||
*
|
||||
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
|
||||
* @deprecated Use {@link TemplateOptions#getGroups()} instead.
|
||||
*/
|
||||
|
@ -301,14 +301,14 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see NovaTemplateOptions#shouldGenerateKeyPair()
|
||||
* @see NovaTemplateOptions#shouldGenerateKeyPair()
|
||||
*/
|
||||
public static NovaTemplateOptions generateKeyPair(boolean enable) {
|
||||
return new NovaTemplateOptions().generateKeyPair(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NovaTemplateOptions#getKeyPairName()
|
||||
* @see NovaTemplateOptions#getKeyPairName()
|
||||
*/
|
||||
public static NovaTemplateOptions keyPairName(String keyPairName) {
|
||||
return new NovaTemplateOptions().keyPairName(keyPairName);
|
||||
|
@ -645,8 +645,8 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
}
|
||||
|
||||
/**
|
||||
* OpenStack can be configured to write metadata to a special configuration drive that will be
|
||||
* attached to the instance when it boots. The instance can retrieve any information that would
|
||||
* OpenStack can be configured to write metadata to a special configuration drive that will be
|
||||
* attached to the instance when it boots. The instance can retrieve any information that would
|
||||
* normally be available through the metadata service by mounting this disk and reading files from it.
|
||||
* To enable the config drive, set this parameter to "true".
|
||||
* This has to be enabled for user data cases.
|
||||
|
|
|
@ -28,15 +28,15 @@ import javax.inject.Inject;
|
|||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
|
||||
public class AllNodesInGroupTerminated implements Predicate<ZoneAndName> {
|
||||
public class AllNodesInGroupTerminated implements Predicate<RegionAndName> {
|
||||
private final ComputeService computeService;
|
||||
|
||||
|
||||
|
||||
//TODO: TESTME
|
||||
@Inject
|
||||
public AllNodesInGroupTerminated(ComputeService computeService) {
|
||||
|
@ -44,10 +44,10 @@ public class AllNodesInGroupTerminated implements Predicate<ZoneAndName> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ZoneAndName input) {
|
||||
// new nodes can have the zone as their location, existing nodes, the parent is the
|
||||
public boolean apply(RegionAndName input) {
|
||||
// new nodes can have the region as their location, existing nodes, the parent is the
|
||||
// location
|
||||
return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getZone()),
|
||||
parentLocationId(input.getZone()))), and(inGroup(input.getName()), TERMINATED));
|
||||
return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getRegion()),
|
||||
parentLocationId(input.getRegion()))), and(inGroup(input.getName()), TERMINATED));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,9 @@ import org.jclouds.openstack.nova.v2_0.compute.functions.AllocateAndAddFloatingI
|
|||
import org.jclouds.openstack.nova.v2_0.compute.options.NodeAndNovaTemplateOptions;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
|
@ -64,8 +64,8 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
|
|||
CreateNodesWithGroupEncodedIntoNameThenAddToSet {
|
||||
|
||||
private final AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode;
|
||||
private final LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache;
|
||||
private final LoadingCache<ZoneAndName, KeyPair> keyPairCache;
|
||||
private final LoadingCache<RegionAndName, SecurityGroupInRegion> securityGroupCache;
|
||||
private final LoadingCache<RegionAndName, KeyPair> keyPairCache;
|
||||
private final NovaApi novaApi;
|
||||
|
||||
@Inject
|
||||
|
@ -76,8 +76,8 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
|
|||
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
|
||||
AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode,
|
||||
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache,
|
||||
LoadingCache<ZoneAndName, KeyPair> keyPairCache, NovaApi novaApi) {
|
||||
LoadingCache<RegionAndName, SecurityGroupInRegion> securityGroupCache,
|
||||
LoadingCache<RegionAndName, KeyPair> keyPairCache, NovaApi novaApi) {
|
||||
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
|
||||
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
|
||||
this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache");
|
||||
|
@ -97,21 +97,21 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
|
|||
|
||||
assert template.getOptions().equals(templateOptions) : "options didn't clone properly";
|
||||
|
||||
String zone = mutableTemplate.getLocation().getId();
|
||||
String region = mutableTemplate.getLocation().getId();
|
||||
|
||||
if (templateOptions.shouldAutoAssignFloatingIp()) {
|
||||
checkArgument(novaApi.getFloatingIPExtensionForZone(zone).isPresent(),
|
||||
checkArgument(novaApi.getFloatingIPApi(region).isPresent(),
|
||||
"Floating IPs are required by options, but the extension is not available! options: %s",
|
||||
templateOptions);
|
||||
}
|
||||
|
||||
boolean keyPairExtensionPresent = novaApi.getKeyPairExtensionForZone(zone).isPresent();
|
||||
boolean keyPairExtensionPresent = novaApi.getKeyPairApi(region).isPresent();
|
||||
if (templateOptions.shouldGenerateKeyPair()) {
|
||||
checkArgument(keyPairExtensionPresent,
|
||||
"Key Pairs are required by options, but the extension is not available! options: %s", templateOptions);
|
||||
KeyPair keyPair = keyPairCache.getUnchecked(ZoneAndName.fromZoneAndName(zone, namingConvention.create()
|
||||
KeyPair keyPair = keyPairCache.getUnchecked(RegionAndName.fromRegionAndName(region, namingConvention.create()
|
||||
.sharedNameForGroup(group)));
|
||||
keyPairCache.asMap().put(ZoneAndName.fromZoneAndName(zone, keyPair.getName()), keyPair);
|
||||
keyPairCache.asMap().put(RegionAndName.fromRegionAndName(region, keyPair.getName()), keyPair);
|
||||
templateOptions.keyPairName(keyPair.getName());
|
||||
} else if (templateOptions.getKeyPairName() != null) {
|
||||
checkArgument(keyPairExtensionPresent,
|
||||
|
@ -120,11 +120,11 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
|
|||
String pem = templateOptions.getLoginPrivateKey();
|
||||
KeyPair keyPair = KeyPair.builder().name(templateOptions.getKeyPairName())
|
||||
.fingerprint(fingerprintPrivateKey(pem)).privateKey(pem).build();
|
||||
keyPairCache.asMap().put(ZoneAndName.fromZoneAndName(zone, keyPair.getName()), keyPair);
|
||||
keyPairCache.asMap().put(RegionAndName.fromRegionAndName(region, keyPair.getName()), keyPair);
|
||||
}
|
||||
}
|
||||
|
||||
boolean securityGroupExtensionPresent = novaApi.getSecurityGroupExtensionForZone(zone).isPresent();
|
||||
boolean securityGroupExtensionPresent = novaApi.getSecurityGroupApi(region).isPresent();
|
||||
List<Integer> inboundPorts = Ints.asList(templateOptions.getInboundPorts());
|
||||
if (!templateOptions.getGroups().isEmpty()) {
|
||||
checkArgument(securityGroupExtensionPresent,
|
||||
|
@ -134,7 +134,7 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
|
|||
if (templateOptions.getGroups().isEmpty() && !inboundPorts.isEmpty()) {
|
||||
String securityGroupName = namingConvention.create().sharedNameForGroup(group);
|
||||
try {
|
||||
securityGroupCache.get(new ZoneSecurityGroupNameAndPorts(zone, securityGroupName, inboundPorts));
|
||||
securityGroupCache.get(new RegionSecurityGroupNameAndPorts(region, securityGroupName, inboundPorts));
|
||||
} catch (ExecutionException e) {
|
||||
throw Throwables.propagate(e.getCause());
|
||||
}
|
||||
|
|
|
@ -97,12 +97,12 @@ public class NovaHttpApiModule extends HttpApiModule<NovaApi> {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
public LoadingCache<String, Set<? extends Extension>> provideExtensionsByZone(final Provider<NovaApi> novaApi) {
|
||||
public LoadingCache<String, Set<? extends Extension>> provideExtensionsByRegion(final Provider<NovaApi> novaApi) {
|
||||
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS)
|
||||
.build(new CacheLoader<String, Set<? extends Extension>>() {
|
||||
@Override
|
||||
public Set<? extends Extension> load(String key) throws Exception {
|
||||
return novaApi.get().getExtensionApiForZone(key).list();
|
||||
return novaApi.get().getExtensionApi(key).list();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -36,16 +36,16 @@ import com.google.common.collect.ImmutableSet;
|
|||
|
||||
/**
|
||||
* Aggregates can be manipulated using the Aggregate Extension to Nova (alias "OS-AGGREGATES")
|
||||
*
|
||||
*
|
||||
* @see org.jclouds.openstack.nova.v2_0.extensions.HostAggregateApi
|
||||
*/
|
||||
public class HostAggregate {
|
||||
|
||||
public static Builder<?> builder() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromHostAggregate(this);
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,8 @@ public class HostAggregate {
|
|||
protected Date created;
|
||||
protected Date updated;
|
||||
protected Map<String, String> metadata = ImmutableMap.of();
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* @see HostAggregate#getId()
|
||||
*/
|
||||
public T id(String id) {
|
||||
|
@ -69,7 +69,7 @@ public class HostAggregate {
|
|||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see HostAggregate#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
|
@ -77,7 +77,7 @@ public class HostAggregate {
|
|||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see HostAggregate#getAvailabilityZone()
|
||||
*/
|
||||
public T availabilityZone(String availabilityZone) {
|
||||
|
@ -85,11 +85,11 @@ public class HostAggregate {
|
|||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see HostAggregate#getHosts()
|
||||
*/
|
||||
public T hosts(Set<String> hosts) {
|
||||
this.hosts = ImmutableSet.copyOf(checkNotNull(hosts, "hosts"));
|
||||
this.hosts = ImmutableSet.copyOf(checkNotNull(hosts, "hosts"));
|
||||
return self();
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class HostAggregate {
|
|||
return hosts(ImmutableSet.copyOf(in));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see HostAggregate#getState()
|
||||
*/
|
||||
public T state(String state) {
|
||||
|
@ -105,7 +105,7 @@ public class HostAggregate {
|
|||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see HostAggregate#getCreated()
|
||||
*/
|
||||
public T created(Date created) {
|
||||
|
@ -113,7 +113,7 @@ public class HostAggregate {
|
|||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see HostAggregate#getUpdated()
|
||||
*/
|
||||
public T updated(Date updated) {
|
||||
|
@ -121,18 +121,18 @@ public class HostAggregate {
|
|||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see HostAggregate#getMetadata()
|
||||
*/
|
||||
public T metadata(Map<String, String> metadata) {
|
||||
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
|
||||
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
|
||||
return self();
|
||||
}
|
||||
|
||||
public HostAggregate build() {
|
||||
return new HostAggregate(id, name, availabilityZone, hosts, state, created, updated, metadata);
|
||||
}
|
||||
|
||||
|
||||
public T fromHostAggregate(HostAggregate in) {
|
||||
return this
|
||||
.id(in.getId())
|
||||
|
@ -174,11 +174,11 @@ public class HostAggregate {
|
|||
this.id = checkNotNull(id, "id");
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone");
|
||||
this.hosts = hosts == null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(hosts);
|
||||
this.hosts = hosts == null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(hosts);
|
||||
this.state = checkNotNull(state, "state");
|
||||
this.created = checkNotNull(created, "created");
|
||||
this.updated = Optional.fromNullable(updated);
|
||||
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(metadata);
|
||||
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(metadata);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -190,8 +190,6 @@ public class HostAggregate {
|
|||
}
|
||||
|
||||
/**
|
||||
* note: an "Availability Zone" is different from a Nova "Zone"
|
||||
*
|
||||
* @return the availability zone this aggregate is in
|
||||
*/
|
||||
public String getAvailabilityZone() {
|
||||
|
@ -237,12 +235,12 @@ public class HostAggregate {
|
|||
&& Objects.equal(this.updated, that.updated)
|
||||
&& Objects.equal(this.metadata, that.metadata);
|
||||
}
|
||||
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("id", id).add("name", name).add("availabilityZone", availabilityZone).add("hosts", hosts).add("state", state).add("created", created).add("updated", updated).add("metadata", metadata);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Objects;
|
|
@ -14,17 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Flavor;
|
||||
|
||||
public class FlavorInZone extends ZoneAndId {
|
||||
public class FlavorInRegion extends RegionAndId {
|
||||
protected final Flavor image;
|
||||
|
||||
public FlavorInZone(Flavor image, String zoneId) {
|
||||
super(zoneId, checkNotNull(image, "image").getId());
|
||||
public FlavorInRegion(Flavor image, String regionId) {
|
||||
super(regionId, checkNotNull(image, "image").getId());
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,12 @@ public class FlavorInZone extends ZoneAndId {
|
|||
return image;
|
||||
}
|
||||
|
||||
// superclass hashCode/equals are good enough, and help us use ZoneAndId and FlavorInZone
|
||||
// superclass hashCode/equals are good enough, and help us use RegionAndId and FlavorInRegion
|
||||
// interchangeably as Map keys
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[image=" + image + ", zoneId=" + zoneId + "]";
|
||||
return "[image=" + image + ", regionId=" + regionId + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -14,17 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Image;
|
||||
|
||||
public class ImageInZone extends ZoneAndId {
|
||||
public class ImageInRegion extends RegionAndId {
|
||||
protected final Image image;
|
||||
|
||||
public ImageInZone(Image image, String zoneId) {
|
||||
super(zoneId, checkNotNull(image, "image").getId());
|
||||
public ImageInRegion(Image image, String regionId) {
|
||||
super(regionId, checkNotNull(image, "image").getId());
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,12 @@ public class ImageInZone extends ZoneAndId {
|
|||
return image;
|
||||
}
|
||||
|
||||
// superclass hashCode/equals are good enough, and help us use ZoneAndId and ImageInZone
|
||||
// superclass hashCode/equals are good enough, and help us use RegionAndId and ImageInRegion
|
||||
// interchangeably as Map keys
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[image=" + image + ", zoneId=" + zoneId + "]";
|
||||
return "[image=" + image + ", regionId=" + regionId + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
@ -23,36 +23,36 @@ import com.google.common.base.Objects;
|
|||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
public class ZoneAndId {
|
||||
public static ZoneAndId fromSlashEncoded(String id) {
|
||||
public class RegionAndId {
|
||||
public static RegionAndId fromSlashEncoded(String id) {
|
||||
Iterable<String> parts = Splitter.on('/').split(checkNotNull(id, "id"));
|
||||
checkArgument(Iterables.size(parts) == 2, "id must be in format zoneId/id");
|
||||
return new ZoneAndId(Iterables.get(parts, 0), Iterables.get(parts, 1));
|
||||
checkArgument(Iterables.size(parts) == 2, "id must be in format regionId/id");
|
||||
return new RegionAndId(Iterables.get(parts, 0), Iterables.get(parts, 1));
|
||||
}
|
||||
|
||||
public static ZoneAndId fromZoneAndId(String zoneId, String id) {
|
||||
return new ZoneAndId(zoneId, id);
|
||||
public static RegionAndId fromRegionAndId(String regionId, String id) {
|
||||
return new RegionAndId(regionId, id);
|
||||
}
|
||||
|
||||
private static String slashEncodeZoneAndId(String zoneId, String id) {
|
||||
return checkNotNull(zoneId, "zoneId") + "/" + checkNotNull(id, "id");
|
||||
private static String slashEncodeRegionAndId(String regionId, String id) {
|
||||
return checkNotNull(regionId, "regionId") + "/" + checkNotNull(id, "id");
|
||||
}
|
||||
|
||||
public String slashEncode() {
|
||||
return slashEncodeZoneAndId(zoneId, id);
|
||||
return slashEncodeRegionAndId(regionId, id);
|
||||
}
|
||||
|
||||
protected final String zoneId;
|
||||
protected final String regionId;
|
||||
protected final String id;
|
||||
|
||||
protected ZoneAndId(String zoneId, String id) {
|
||||
this.zoneId = checkNotNull(zoneId, "zoneId");
|
||||
protected RegionAndId(String regionId, String id) {
|
||||
this.regionId = checkNotNull(regionId, "regionId");
|
||||
this.id = checkNotNull(id, "id");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(zoneId, id);
|
||||
return Objects.hashCode(regionId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,12 +63,12 @@ public class ZoneAndId {
|
|||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ZoneAndId other = (ZoneAndId) obj;
|
||||
return Objects.equal(zoneId, other.zoneId) && Objects.equal(id, other.id);
|
||||
RegionAndId other = (RegionAndId) obj;
|
||||
return Objects.equal(regionId, other.regionId) && Objects.equal(id, other.id);
|
||||
}
|
||||
|
||||
public String getZone() {
|
||||
return zoneId;
|
||||
public String getRegion() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -77,7 +77,7 @@ public class ZoneAndId {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[zoneId=" + zoneId + ", id=" + id + "]";
|
||||
return "[regionId=" + regionId + ", id=" + id + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -14,70 +14,70 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Helpful when looking for resources by zone and name
|
||||
* Helpful when looking for resources by region and name
|
||||
*/
|
||||
public class ZoneAndName {
|
||||
|
||||
public static final Function<ZoneAndName, String> NAME_FUNCTION = new Function<ZoneAndName, String>() {
|
||||
public class RegionAndName {
|
||||
|
||||
public static final Function<RegionAndName, String> NAME_FUNCTION = new Function<RegionAndName, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(ZoneAndName input) {
|
||||
public String apply(RegionAndName input) {
|
||||
return input.getName();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
public static final Function<ZoneAndName, String> ZONE_FUNCTION = new Function<ZoneAndName, String>() {
|
||||
|
||||
public static final Function<RegionAndName, String> REGION_FUNCTION = new Function<RegionAndName, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(ZoneAndName input) {
|
||||
return input.getZone();
|
||||
public String apply(RegionAndName input) {
|
||||
return input.getRegion();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
public static ZoneAndName fromSlashEncoded(String name) {
|
||||
|
||||
public static RegionAndName fromSlashEncoded(String name) {
|
||||
Iterable<String> parts = Splitter.on('/').split(checkNotNull(name, "name"));
|
||||
checkArgument(Iterables.size(parts) == 2, "name must be in format zoneId/name");
|
||||
return new ZoneAndName(Iterables.get(parts, 0), Iterables.get(parts, 1));
|
||||
checkArgument(Iterables.size(parts) == 2, "name must be in format regionId/name");
|
||||
return new RegionAndName(Iterables.get(parts, 0), Iterables.get(parts, 1));
|
||||
}
|
||||
|
||||
public static ZoneAndName fromZoneAndName(String zoneId, String name) {
|
||||
return new ZoneAndName(zoneId, name);
|
||||
public static RegionAndName fromRegionAndName(String regionId, String name) {
|
||||
return new RegionAndName(regionId, name);
|
||||
}
|
||||
|
||||
private static String slashEncodeZoneAndName(String zoneId, String name) {
|
||||
return checkNotNull(zoneId, "zoneId") + "/" + checkNotNull(name, "name");
|
||||
private static String slashEncodeRegionAndName(String regionId, String name) {
|
||||
return checkNotNull(regionId, "regionId") + "/" + checkNotNull(name, "name");
|
||||
}
|
||||
|
||||
public String slashEncode() {
|
||||
return slashEncodeZoneAndName(zoneId, name);
|
||||
return slashEncodeRegionAndName(regionId, name);
|
||||
}
|
||||
|
||||
protected final String zoneId;
|
||||
protected final String regionId;
|
||||
protected final String name;
|
||||
|
||||
protected ZoneAndName(String zoneId, String name) {
|
||||
this.zoneId = checkNotNull(zoneId, "zoneId");
|
||||
protected RegionAndName(String regionId, String name) {
|
||||
this.regionId = checkNotNull(regionId, "regionId");
|
||||
this.name = checkNotNull(name, "name");
|
||||
}
|
||||
|
||||
public String getZone() {
|
||||
return zoneId;
|
||||
public String getRegion() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -90,13 +90,13 @@ public class ZoneAndName {
|
|||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
ZoneAndName that = ZoneAndName.class.cast(o);
|
||||
return equal(this.zoneId, that.zoneId) && equal(this.name, that.name);
|
||||
RegionAndName that = RegionAndName.class.cast(o);
|
||||
return equal(this.regionId, that.regionId) && equal(this.name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(zoneId, name);
|
||||
return Objects.hashCode(regionId, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,6 +105,6 @@ public class ZoneAndName {
|
|||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return MoreObjects.toStringHelper("").add("zoneId", zoneId).add("name", name);
|
||||
return MoreObjects.toStringHelper("").add("regionId", regionId).add("name", name);
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
@ -25,11 +25,11 @@ import com.google.common.base.Objects;
|
|||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
public class ZoneSecurityGroupNameAndPorts extends ZoneAndName {
|
||||
public class RegionSecurityGroupNameAndPorts extends RegionAndName {
|
||||
protected final Set<Integer> ports;
|
||||
|
||||
public ZoneSecurityGroupNameAndPorts(String zoneId, String name, Iterable<Integer> ports) {
|
||||
super(zoneId, name);
|
||||
public RegionSecurityGroupNameAndPorts(String regionId, String name, Iterable<Integer> ports) {
|
||||
super(regionId, name);
|
||||
this.ports = ImmutableSet.<Integer> copyOf(checkNotNull(ports, "ports"));
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class ZoneSecurityGroupNameAndPorts extends ZoneAndName {
|
|||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
ZoneSecurityGroupNameAndPorts that = ZoneSecurityGroupNameAndPorts.class.cast(o);
|
||||
RegionSecurityGroupNameAndPorts that = RegionSecurityGroupNameAndPorts.class.cast(o);
|
||||
return super.equals(that) && equal(this.ports, that.ports);
|
||||
}
|
||||
|
|
@ -14,17 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup;
|
||||
|
||||
public class SecurityGroupInZone extends ZoneAndName {
|
||||
public class SecurityGroupInRegion extends RegionAndName {
|
||||
protected final SecurityGroup securityGroup;
|
||||
|
||||
public SecurityGroupInZone(SecurityGroup securityGroup, String zoneId) {
|
||||
super(zoneId, checkNotNull(securityGroup, "securityGroup").getName());
|
||||
public SecurityGroupInRegion(SecurityGroup securityGroup, String regionId) {
|
||||
super(regionId, checkNotNull(securityGroup, "securityGroup").getName());
|
||||
this.securityGroup = securityGroup;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,12 @@ public class SecurityGroupInZone extends ZoneAndName {
|
|||
return securityGroup;
|
||||
}
|
||||
|
||||
// superclass hashCode/equals are good enough, and help us use ZoneAndName and ServerInZone
|
||||
// superclass hashCode/equals are good enough, and help us use RegionAndName and ServerInRegion
|
||||
// interchangeably as Map keys
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[securityGroup=" + securityGroup + ", zoneId=" + zoneId + "]";
|
||||
return "[securityGroup=" + securityGroup + ", regionId=" + regionId + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -14,17 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||
|
||||
public class ServerInZone extends ZoneAndId {
|
||||
public class ServerInRegion extends RegionAndId {
|
||||
protected final Server server;
|
||||
|
||||
public ServerInZone(Server server, String zoneId) {
|
||||
super(zoneId, checkNotNull(server, "server").getId());
|
||||
public ServerInRegion(Server server, String regionId) {
|
||||
super(regionId, checkNotNull(server, "server").getId());
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,12 @@ public class ServerInZone extends ZoneAndId {
|
|||
return server;
|
||||
}
|
||||
|
||||
// superclass hashCode/equals are good enough, and help us use ZoneAndId and ServerInZone
|
||||
// superclass hashCode/equals are good enough, and help us use RegionAndId and ServerInRegion
|
||||
// interchangeably as Map keys
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[server=" + server + ", zoneId=" + zoneId + "]";
|
||||
return "[server=" + server + ", regionId=" + regionId + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v2_0.domain.zonescoped;
|
||||
package org.jclouds.openstack.nova.v2_0.domain.regionscoped;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Objects;
|
|
@ -24,7 +24,7 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.AvailabilityZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.AvailabilityZone;
|
||||
import org.jclouds.openstack.v2_0.ServiceType;
|
||||
import org.jclouds.openstack.v2_0.services.Extension;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
|
|
|
@ -23,22 +23,22 @@ import java.beans.ConstructorProperties;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.collect.internal.Arg0ToPagedIterable;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Flavor;
|
||||
import org.jclouds.openstack.nova.v2_0.features.FlavorApi;
|
||||
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseFlavorDetails.Flavors;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
/**
|
||||
* boiler plate until we determine a better way
|
||||
|
@ -71,8 +71,8 @@ public class ParseFlavorDetails extends ParseJson<Flavors> {
|
|||
|
||||
@Override
|
||||
protected Function<Object, IterableWithMarker<Flavor>> markerToNextForArg0(Optional<Object> arg0) {
|
||||
String zone = arg0.get().toString();
|
||||
final FlavorApi flavorApi = api.getFlavorApiForZone(zone);
|
||||
String region = arg0.get().toString();
|
||||
final FlavorApi flavorApi = api.getFlavorApi(region);
|
||||
return new Function<Object, IterableWithMarker<Flavor>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -71,8 +71,8 @@ public class ParseFlavors extends ParseJson<Flavors> {
|
|||
|
||||
@Override
|
||||
protected Function<Object, IterableWithMarker<Resource>> markerToNextForArg0(Optional<Object> arg0) {
|
||||
String zone = arg0.get().toString();
|
||||
final FlavorApi flavorApi = api.getFlavorApiForZone(zone);
|
||||
String region = arg0.get().toString();
|
||||
final FlavorApi flavorApi = api.getFlavorApi(region);
|
||||
return new Function<Object, IterableWithMarker<Resource>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -71,8 +71,8 @@ public class ParseImageDetails extends ParseJson<Images> {
|
|||
|
||||
@Override
|
||||
protected Function<Object, IterableWithMarker<Image>> markerToNextForArg0(Optional<Object> arg0) {
|
||||
String zone = arg0.get().toString();
|
||||
final ImageApi imageApi = api.getImageApiForZone(zone);
|
||||
String region = arg0.get().toString();
|
||||
final ImageApi imageApi = api.getImageApi(region);
|
||||
return new Function<Object, IterableWithMarker<Image>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -23,22 +23,22 @@ import java.beans.ConstructorProperties;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.collect.internal.Arg0ToPagedIterable;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.features.ImageApi;
|
||||
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImages.Images;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.domain.Resource;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
/**
|
||||
* boiler plate until we determine a better way
|
||||
|
@ -71,8 +71,8 @@ public class ParseImages extends ParseJson<Images> {
|
|||
|
||||
@Override
|
||||
protected Function<Object, IterableWithMarker<Resource>> markerToNextForArg0(Optional<Object> arg0) {
|
||||
String zone = arg0.get().toString();
|
||||
final ImageApi imageApi = api.getImageApiForZone(zone);
|
||||
String region = arg0.get().toString();
|
||||
final ImageApi imageApi = api.getImageApi(region);
|
||||
return new Function<Object, IterableWithMarker<Resource>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -71,8 +71,8 @@ public class ParseServerDetails extends ParseJson<Servers> {
|
|||
|
||||
@Override
|
||||
protected Function<Object, IterableWithMarker<Server>> markerToNextForArg0(Optional<Object> arg0) {
|
||||
String zone = arg0.get().toString();
|
||||
final ServerApi serverApi = api.getServerApiForZone(zone);
|
||||
String region = arg0.get().toString();
|
||||
final ServerApi serverApi = api.getServerApi(region);
|
||||
return new Function<Object, IterableWithMarker<Server>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -23,22 +23,22 @@ import java.beans.ConstructorProperties;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.collect.internal.Arg0ToPagedIterable;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.features.ServerApi;
|
||||
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServers.Servers;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.domain.Resource;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
/**
|
||||
* boiler plate until we determine a better way
|
||||
|
@ -71,8 +71,8 @@ public class ParseServers extends ParseJson<Servers> {
|
|||
|
||||
@Override
|
||||
protected Function<Object, IterableWithMarker<Resource>> markerToNextForArg0(Optional<Object> arg0) {
|
||||
String zone = arg0.get().toString();
|
||||
final ServerApi serverApi = api.getServerApiForZone(zone);
|
||||
String region = arg0.get().toString();
|
||||
final ServerApi serverApi = api.getServerApi(region);
|
||||
return new Function<Object, IterableWithMarker<Resource>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -360,7 +360,7 @@ public class CreateServerOptions implements MapBinder {
|
|||
* <p/>
|
||||
* <h3>Note</h3>
|
||||
* <p/>
|
||||
* This requires that {@link NovaApi#getSecurityGroupExtensionForZone(String)} to return
|
||||
* This requires that {@link NovaApi#getSecurityGroupExtensionApi(String)} to return
|
||||
* {@link Optional#isPresent present}
|
||||
*/
|
||||
public Set<String> getSecurityGroupNames() {
|
||||
|
@ -376,7 +376,7 @@ public class CreateServerOptions implements MapBinder {
|
|||
public Set<String> getNetworks() {
|
||||
return networks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get custom networks specified for the server.
|
||||
*
|
||||
|
@ -429,7 +429,7 @@ public class CreateServerOptions implements MapBinder {
|
|||
|
||||
/**
|
||||
* Determines if a configuration drive will be attached to the server or not.
|
||||
* This can be used for cloud-init or other configuration purposes.
|
||||
* This can be used for cloud-init or other configuration purposes.
|
||||
*/
|
||||
public boolean getConfigDrive() {
|
||||
return configDrive;
|
||||
|
|
|
@ -28,8 +28,8 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
||||
|
@ -42,7 +42,7 @@ import com.google.inject.Inject;
|
|||
* AtomicReference is so that we can return the securityGroup that matched.
|
||||
*/
|
||||
@Singleton
|
||||
public class FindSecurityGroupWithNameAndReturnTrue implements Predicate<AtomicReference<ZoneAndName>> {
|
||||
public class FindSecurityGroupWithNameAndReturnTrue implements Predicate<AtomicReference<RegionAndName>> {
|
||||
|
||||
private final NovaApi novaApi;
|
||||
|
||||
|
@ -54,24 +54,24 @@ public class FindSecurityGroupWithNameAndReturnTrue implements Predicate<AtomicR
|
|||
this.novaApi = checkNotNull(novaApi, "novaApi");
|
||||
}
|
||||
|
||||
public boolean apply(AtomicReference<ZoneAndName> securityGroupInZoneRef) {
|
||||
checkNotNull(securityGroupInZoneRef, "securityGroupRef");
|
||||
final ZoneAndName securityGroupInZone = checkNotNull(securityGroupInZoneRef.get(), "securityGroupInZone");
|
||||
public boolean apply(AtomicReference<RegionAndName> securityGroupInRegionRef) {
|
||||
checkNotNull(securityGroupInRegionRef, "securityGroupRef");
|
||||
final RegionAndName securityGroupInRegion = checkNotNull(securityGroupInRegionRef.get(), "securityGroupInRegion");
|
||||
|
||||
Optional<? extends SecurityGroupApi> api = novaApi.getSecurityGroupExtensionForZone(securityGroupInZone.getZone());
|
||||
Optional<? extends SecurityGroupApi> api = novaApi.getSecurityGroupApi(securityGroupInRegion.getRegion());
|
||||
checkArgument(api.isPresent(), "Security groups are required, but the extension is not available!");
|
||||
|
||||
logger.trace("looking for security group %s", securityGroupInZone.slashEncode());
|
||||
logger.trace("looking for security group %s", securityGroupInRegion.slashEncode());
|
||||
try {
|
||||
SecurityGroup returnVal = Iterables.find(api.get().list(), new Predicate<SecurityGroup>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(SecurityGroup input) {
|
||||
return input.getName().equals(securityGroupInZone.getName());
|
||||
return input.getName().equals(securityGroupInRegion.getName());
|
||||
}
|
||||
|
||||
});
|
||||
securityGroupInZoneRef.set(new SecurityGroupInZone(returnVal, securityGroupInZone.getZone()));
|
||||
securityGroupInRegionRef.set(new SecurityGroupInRegion(returnVal, securityGroupInRegion.getRegion()));
|
||||
return true;
|
||||
} catch (ResourceNotFoundException e) {
|
||||
return false;
|
||||
|
|
|
@ -57,18 +57,18 @@ public class ServerPredicates {
|
|||
|
||||
/**
|
||||
* Waits until a Server is ACTIVE.
|
||||
*
|
||||
* @param serverApi The ServerApi in the zone where your Server resides.
|
||||
*
|
||||
* @param serverApi The ServerApi in the region where your Server resides.
|
||||
* @return Predicate that will check the status every 5 seconds for a maximum of 10 minutes.
|
||||
*/
|
||||
public static Predicate<String> awaitActive(ServerApi serverApi) {
|
||||
return awaitStatus(serverApi, ACTIVE, TEN_MINUTES, FIVE_SECONDS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Waits until a Server is SHUTOFF.
|
||||
*
|
||||
* @param serverApi The ServerApi in the zone where your Server resides.
|
||||
*
|
||||
* @param serverApi The ServerApi in the region where your Server resides.
|
||||
* @return Predicate that will check the status every 5 seconds for a maximum of 10 minutes.
|
||||
*/
|
||||
public static Predicate<String> awaitShutoff(ServerApi serverApi) {
|
||||
|
@ -78,7 +78,7 @@ public class ServerPredicates {
|
|||
/**
|
||||
* Waits until a Server reaches Status.
|
||||
*
|
||||
* @param serverApi The ServerApi in the zone where your Server resides.
|
||||
* @param serverApi The ServerApi in the region where your Server resides.
|
||||
* @return Predicate that will check the status every periodInSec seconds for a maximum of maxWaitInSec minutes.
|
||||
*/
|
||||
public static Predicate<String> awaitStatus(
|
||||
|
@ -87,7 +87,7 @@ public class ServerPredicates {
|
|||
|
||||
return retry(statusPredicate, maxWaitInSec, periodInSec, periodInSec, SECONDS);
|
||||
}
|
||||
|
||||
|
||||
public static class ServerStatusPredicate implements Predicate<String> {
|
||||
private final ServerApi serverApi;
|
||||
private final Status status;
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see KeystoneProperties#CREDENTIAL_TYPE
|
||||
*
|
||||
* @see org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties#CREDENTIAL_TYPE
|
||||
*/
|
||||
@Test(groups = "unit", testName = "AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest")
|
||||
public class AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest extends BaseNovaApiExpectTest {
|
||||
|
@ -64,9 +64,9 @@ public class AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest extends Ba
|
|||
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKeyAndTenantId,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenServersExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(),
|
||||
assertEquals(apiWhenServersExist.getServerApi("az-1.region-a.geo-1").list().concat().toString(),
|
||||
new ParseServerListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see KeystoneProperties#CREDENTIAL_TYPE
|
||||
*/
|
||||
@Test(groups = "unit", testName = "AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest")
|
||||
|
@ -64,9 +64,9 @@ public class AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest
|
|||
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKeyAndTenantName,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenServersExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(),
|
||||
assertEquals(apiWhenServersExist.getServerApi("az-1.region-a.geo-1").list().concat().toString(),
|
||||
new ParseServerListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see KeystoneProperties#CREDENTIAL_TYPE
|
||||
*
|
||||
* @see org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties#CREDENTIAL_TYPE
|
||||
*/
|
||||
@Test(groups = "unit", testName = "AccessKeyAndSecretKeyAuthenticationExpectTest")
|
||||
public class AccessKeyAndSecretKeyAuthenticationExpectTest extends BaseNovaApiExpectTest {
|
||||
|
@ -59,9 +59,9 @@ public class AccessKeyAndSecretKeyAuthenticationExpectTest extends BaseNovaApiEx
|
|||
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKeyAndTenantName,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenServersExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(),
|
||||
assertEquals(apiWhenServersExist.getServerApi("az-1.region-a.geo-1").list().concat().toString(),
|
||||
new ParseServerListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class EndpointIdIsRandomExpectTest extends BaseNovaApiExpectTest {
|
|||
return overrides;
|
||||
}
|
||||
|
||||
public void testVersionMatchOnConfiguredZonesWhenResponseIs2xx() {
|
||||
public void testVersionMatchOnConfiguredRegionsWhenResponseIs2xx() {
|
||||
|
||||
HttpRequest authenticate = HttpRequest
|
||||
.builder()
|
||||
|
@ -63,7 +63,7 @@ public class EndpointIdIsRandomExpectTest extends BaseNovaApiExpectTest {
|
|||
|
||||
NovaApi whenNovaRegionExists = requestSendsResponse(authenticate, authenticationResponse);
|
||||
|
||||
assertEquals(whenNovaRegionExists.getConfiguredZones(), ImmutableSet.of("RegionOne"));
|
||||
assertEquals(whenNovaRegionExists.getConfiguredRegions(), ImmutableSet.of("RegionOne"));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -27,15 +27,15 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see KeystoneProperties#CREDENTIAL_TYPE
|
||||
*
|
||||
* @see org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties#CREDENTIAL_TYPE
|
||||
*/
|
||||
@Test(groups = "unit", testName = "PasswordAuthenticationExpectTest")
|
||||
public class PasswordAuthenticationExpectTest extends BaseNovaApiExpectTest {
|
||||
public PasswordAuthenticationExpectTest() {
|
||||
identity = "identity";
|
||||
}
|
||||
|
||||
|
||||
public void testListServersWhenResponseIs2xx() throws Exception {
|
||||
HttpRequest listServers = HttpRequest
|
||||
.builder()
|
||||
|
@ -50,9 +50,9 @@ public class PasswordAuthenticationExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenServersExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(),
|
||||
assertEquals(apiWhenServersExist.getServerApi("az-1.region-a.geo-1").list().concat().toString(),
|
||||
new ParseServerListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see KeystoneProperties#CREDENTIAL_TYPE
|
||||
*
|
||||
* @see org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties#CREDENTIAL_TYPE
|
||||
*/
|
||||
@Test(groups = "unit", testName = "PasswordAuthenticationWithTenantNameExpectTest")
|
||||
public class PasswordAuthenticationWithTenantNameExpectTest extends BaseNovaApiExpectTest {
|
||||
|
@ -59,9 +59,9 @@ public class PasswordAuthenticationWithTenantNameExpectTest extends BaseNovaApiE
|
|||
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenServersExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(),
|
||||
assertEquals(apiWhenServersExist.getServerApi("az-1.region-a.geo-1").list().concat().toString(),
|
||||
new ParseServerListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions;
|
|||
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Network;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaComputeServiceContextExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -92,7 +92,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
|
||||
NovaComputeServiceAdapter adapter = forNetworks.getInstance(NovaComputeServiceAdapter.class);
|
||||
|
||||
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", template);
|
||||
NodeAndInitialCredentials<ServerInRegion> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", template);
|
||||
assertNotNull(server);
|
||||
// Response irrelevant in this expect test - just verifying the request.
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
|
||||
NovaComputeServiceAdapter adapter = forDiskConfig.getInstance(NovaComputeServiceAdapter.class);
|
||||
|
||||
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", template);
|
||||
NodeAndInitialCredentials<ServerInRegion> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", template);
|
||||
assertNotNull(server);
|
||||
assertEquals(server.getNode().getServer().getDiskConfig().orNull(), Server.DISK_CONFIG_AUTO);
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
|
||||
NovaComputeServiceAdapter adapter = forConfigDrive.getInstance(NovaComputeServiceAdapter.class);
|
||||
|
||||
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", template);
|
||||
NodeAndInitialCredentials<ServerInRegion> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", template);
|
||||
assertNotNull(server);
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
|
||||
NovaComputeServiceAdapter adapter = forNovaNetworks.getInstance(NovaComputeServiceAdapter.class);
|
||||
|
||||
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", template);
|
||||
NodeAndInitialCredentials<ServerInRegion> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", template);
|
||||
assertNotNull(server);
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
|
||||
NovaComputeServiceAdapter adapter = forSecurityGroups.getInstance(NovaComputeServiceAdapter.class);
|
||||
|
||||
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||
NodeAndInitialCredentials<ServerInRegion> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||
template);
|
||||
assertNotNull(server);
|
||||
assertEquals(server.getCredentials(), LoginCredentials.builder().password("ZWuHcmTMQ7eXoHeM").build());
|
||||
|
@ -286,13 +286,13 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
NovaComputeServiceAdapter adapter = forSecurityGroups.getInstance(NovaComputeServiceAdapter.class);
|
||||
|
||||
// we expect to have already an entry in the cache for the key
|
||||
LoadingCache<ZoneAndName, KeyPair> keyPairCache = forSecurityGroups.getInstance(Key
|
||||
.get(new TypeLiteral<LoadingCache<ZoneAndName, KeyPair>>() {
|
||||
LoadingCache<RegionAndName, KeyPair> keyPairCache = forSecurityGroups.getInstance(Key
|
||||
.get(new TypeLiteral<LoadingCache<RegionAndName, KeyPair>>() {
|
||||
}));
|
||||
keyPairCache.put(ZoneAndName.fromZoneAndName("az-1.region-a.geo-1", "foo"), KeyPair.builder().name("foo")
|
||||
keyPairCache.put(RegionAndName.fromRegionAndName("az-1.region-a.geo-1", "foo"), KeyPair.builder().name("foo")
|
||||
.privateKey("privateKey").build());
|
||||
|
||||
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||
NodeAndInitialCredentials<ServerInRegion> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||
template);
|
||||
assertNotNull(server);
|
||||
assertEquals(server.getCredentials(), LoginCredentials.builder().privateKey("privateKey").build());
|
||||
|
@ -333,7 +333,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
|
||||
NovaComputeServiceAdapter adapter = forSecurityGroups.getInstance(NovaComputeServiceAdapter.class);
|
||||
|
||||
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||
NodeAndInitialCredentials<ServerInRegion> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||
template);
|
||||
assertNotNull(server);
|
||||
assertNull(server.getCredentials());
|
||||
|
@ -417,8 +417,8 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = super.setupProperties();
|
||||
// only specify one zone so that we don't have to configure requests for multiple zones
|
||||
overrides.setProperty("jclouds.zones", "az-1.region-a.geo-1");
|
||||
// only specify one region so that we don't have to configure requests for multiple regions
|
||||
overrides.setProperty("jclouds.regions", "az-1.region-a.geo-1");
|
||||
return overrides;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,17 +50,17 @@ import com.google.inject.TypeLiteral;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "NovaComputeServiceExpectTest")
|
||||
public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTest {
|
||||
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = super.setupProperties();
|
||||
// only specify limited zones so that we don't have to configure requests for multiple zones.
|
||||
// only specify limited regions so that we don't have to configure requests for multiple regions.
|
||||
// since we are doing tests with keystone responses from hpcloud and also openstack, we have
|
||||
// to whitelist one zone from each
|
||||
overrides.setProperty("jclouds.zones", "az-1.region-a.geo-1,RegionOne");
|
||||
// to whitelist one region from each
|
||||
overrides.setProperty("jclouds.regions", "az-1.region-a.geo-1,RegionOne");
|
||||
return overrides;
|
||||
}
|
||||
|
||||
|
||||
public void testListLocationsWhenResponseIs2xx() throws Exception {
|
||||
|
||||
Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder()
|
||||
|
@ -189,7 +189,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe
|
|||
|
||||
HttpResponse securityGroupWithPort22 = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/securitygroup_details_port22.json")).build();
|
||||
|
||||
|
||||
HttpRequest create = HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
|
|
|
@ -34,11 +34,11 @@ import com.google.common.util.concurrent.Futures;
|
|||
|
||||
@Test(groups = "unit", testName = "NovaImageExtensionExpectTest")
|
||||
public class NovaImageExtensionExpectTest extends BaseNovaComputeServiceExpectTest {
|
||||
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = super.setupProperties();
|
||||
overrides.setProperty("jclouds.zones", "az-1.region-a.geo-1");
|
||||
overrides.setProperty("jclouds.regions", "az-1.region-a.geo-1");
|
||||
return overrides;
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class NovaImageExtensionExpectTest extends BaseNovaComputeServiceExpectTe
|
|||
payloadFromStringWithContentType(
|
||||
"{\"createImage\":{\"name\":\"test\", \"metadata\": {}}}",
|
||||
"application/json")).build();
|
||||
|
||||
|
||||
HttpResponse createImageResponse = HttpResponse.builder().statusCode(202)
|
||||
.addHeader("Location", "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/52415800-8b69-11e0-9b19-734f5736d2a2")
|
||||
.build();
|
||||
|
@ -67,7 +67,7 @@ public class NovaImageExtensionExpectTest extends BaseNovaComputeServiceExpectTe
|
|||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/52415800-8b69-11e0-9b19-734f5736d2a2")
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("X-Auth-Token", authToken).build();
|
||||
|
||||
|
||||
HttpResponse getImageResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/image_active.json")).build();
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class NovaImageExtensionExpectTest extends BaseNovaComputeServiceExpectTe
|
|||
requestResponseMap.put(getImage, getImageResponse).build();
|
||||
|
||||
ImageExtension apiThatCreatesImage = requestsSendResponses(requestResponseMap.build()).getImageExtension().get();
|
||||
|
||||
|
||||
ImageTemplate newImageTemplate = apiThatCreatesImage.buildImageTemplateFromNode("test", "az-1.region-a.geo-1/71752");
|
||||
|
||||
Image image = Futures.getUnchecked(apiThatCreatesImage.createImage(newImageTemplate));
|
||||
|
|
|
@ -47,7 +47,7 @@ import com.google.common.collect.Sets;
|
|||
@Test(groups = "unit", testName = "NovaSecurityGroupExtensionExpectTest")
|
||||
public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeServiceExpectTest {
|
||||
|
||||
protected String zone = "az-1.region-a.geo-1";
|
||||
protected String region = "az-1.region-a.geo-1";
|
||||
protected HttpRequest list = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/os-security-groups")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
|
||||
|
@ -59,7 +59,7 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = super.setupProperties();
|
||||
overrides.setProperty("jclouds.zones", zone);
|
||||
overrides.setProperty("jclouds.regions", region);
|
||||
return overrides;
|
||||
}
|
||||
|
||||
|
@ -95,9 +95,9 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
SecurityGroupExtension extension = requestsSendResponses(requestResponseMap.build()).getSecurityGroupExtension().get();
|
||||
|
||||
Set<SecurityGroup> groups = extension.listSecurityGroupsInLocation(new LocationBuilder()
|
||||
.scope(LocationScope.ZONE)
|
||||
.id(zone)
|
||||
.description("zone")
|
||||
.scope(LocationScope.REGION)
|
||||
.id(region)
|
||||
.description("region")
|
||||
.build());
|
||||
assertEquals(groups.size(), 1);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
|
||||
SecurityGroupExtension extension = requestsSendResponses(requestResponseMap.build()).getSecurityGroupExtension().get();
|
||||
|
||||
Set<SecurityGroup> groups = extension.listSecurityGroupsForNode(zone + "/8d0a6ca5-8849-4b3d-b86e-f24c92490ebb");
|
||||
Set<SecurityGroup> groups = extension.listSecurityGroupsForNode(region + "/8d0a6ca5-8849-4b3d-b86e-f24c92490ebb");
|
||||
assertEquals(groups.size(), 1);
|
||||
}
|
||||
|
||||
|
@ -150,8 +150,8 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
|
||||
SecurityGroupExtension extension = requestsSendResponses(requestResponseMap.build()).getSecurityGroupExtension().get();
|
||||
|
||||
SecurityGroup group = extension.getSecurityGroupById(zone + "/160");
|
||||
assertEquals(group.getId(), zone + "/160");
|
||||
SecurityGroup group = extension.getSecurityGroupById(region + "/160");
|
||||
assertEquals(group.getId(), region + "/160");
|
||||
}
|
||||
|
||||
public void testCreateSecurityGroup() {
|
||||
|
@ -193,11 +193,11 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
SecurityGroupExtension extension = requestsSendResponses(requestResponseMap.build()).getSecurityGroupExtension().get();
|
||||
|
||||
SecurityGroup group = extension.createSecurityGroup("test", new LocationBuilder()
|
||||
.scope(LocationScope.ZONE)
|
||||
.id(zone)
|
||||
.description("zone")
|
||||
.scope(LocationScope.REGION)
|
||||
.id(region)
|
||||
.description("region")
|
||||
.build());
|
||||
assertEquals(group.getId(), zone + "/160");
|
||||
assertEquals(group.getId(), region + "/160");
|
||||
}
|
||||
|
||||
public void testRemoveSecurityGroup() {
|
||||
|
@ -225,7 +225,7 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
|
||||
SecurityGroupExtension extension = requestsSendResponses(requestResponseMap.build()).getSecurityGroupExtension().get();
|
||||
|
||||
assertTrue(extension.removeSecurityGroup(zone + "/160"), "Expected removal of securitygroup to be successful");
|
||||
assertTrue(extension.removeSecurityGroup(region + "/160"), "Expected removal of securitygroup to be successful");
|
||||
}
|
||||
|
||||
public void testAddIpPermissionCidrFromIpPermission() {
|
||||
|
@ -269,7 +269,7 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
|
||||
IpPermission perm = builder.build();
|
||||
|
||||
SecurityGroup origGroup = extension.getSecurityGroupById(zone + "/160");
|
||||
SecurityGroup origGroup = extension.getSecurityGroupById(region + "/160");
|
||||
|
||||
assertNotNull(origGroup);
|
||||
SecurityGroup newGroup = extension.addIpPermission(perm, origGroup);
|
||||
|
@ -309,7 +309,7 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
ImmutableList.of(responseWithKeystoneAccess, extensionsOfNovaResponse, getSecurityGroupNoRulesResponse,
|
||||
createRuleResponse, getSecurityGroupResponse, listResponse, listResponse)).getSecurityGroupExtension().get();
|
||||
|
||||
SecurityGroup origGroup = extension.getSecurityGroupById(zone + "/160");
|
||||
SecurityGroup origGroup = extension.getSecurityGroupById(region + "/160");
|
||||
|
||||
assertNotNull(origGroup);
|
||||
SecurityGroup newGroup = extension.addIpPermission(IpProtocol.TCP,
|
||||
|
@ -364,7 +364,7 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
|
||||
IpPermission perm = builder.build();
|
||||
|
||||
SecurityGroup origGroup = extension.getSecurityGroupById(zone + "/160");
|
||||
SecurityGroup origGroup = extension.getSecurityGroupById(region + "/160");
|
||||
|
||||
assertNotNull(origGroup);
|
||||
SecurityGroup newGroup = extension.addIpPermission(perm, origGroup);
|
||||
|
@ -404,7 +404,7 @@ public class NovaSecurityGroupExtensionExpectTest extends BaseNovaComputeService
|
|||
ImmutableList.of(responseWithKeystoneAccess, extensionsOfNovaResponse, getSecurityGroupNoRulesResponse,
|
||||
createRuleResponse, getSecurityGroupResponse, listResponse, listResponse)).getSecurityGroupExtension().get();
|
||||
|
||||
SecurityGroup origGroup = extension.getSecurityGroupById(zone + "/160");
|
||||
SecurityGroup origGroup = extension.getSecurityGroupById(region + "/160");
|
||||
|
||||
assertNotNull(origGroup);
|
||||
SecurityGroup newGroup = extension.addIpPermission(IpProtocol.TCP,
|
||||
|
|
|
@ -48,10 +48,10 @@ import com.google.common.util.concurrent.Atomics;
|
|||
public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeServiceExpectTest {
|
||||
final Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
|
||||
"openstack-nova").build();
|
||||
final Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.ZONE).parent(provider).build();
|
||||
final Location region = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.REGION).parent(provider).build();
|
||||
final Location host = new LocationBuilder().scope(LocationScope.HOST).id("hostId").description("hostId")
|
||||
.parent(zone).build();
|
||||
.parent(region).build();
|
||||
final NodeMetadata node = new NodeMetadataBuilder().id("az-1.region-a.geo-1/71592").providerId("71592").location(
|
||||
host).name("Server 71592").status(Status.RUNNING).privateAddresses(ImmutableSet.of("10.4.27.237"))
|
||||
.credentials(LoginCredentials.builder().password("foo").build()).build();
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Flavor;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.FlavorInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.FlavorInRegion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -38,28 +38,28 @@ import com.google.common.collect.ImmutableMap;
|
|||
/**
|
||||
* Tests the function used to transform Flavor objects into Hardware objects
|
||||
*/
|
||||
@Test(testName = "FlavorInZoneToHardwareTest")
|
||||
public class FlavorInZoneToHardwareTest {
|
||||
@Test(testName = "FlavorInRegionToHardwareTest")
|
||||
public class FlavorInRegionToHardwareTest {
|
||||
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
|
||||
"openstack-nova").build();
|
||||
Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.ZONE).parent(provider).build();
|
||||
Location region = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.REGION).parent(provider).build();
|
||||
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location> of("az-1.region-a.geo-1", zone));
|
||||
.<String, Location> of("az-1.region-a.geo-1", region));
|
||||
|
||||
@Test
|
||||
public void testConversionWhereLocationFound() {
|
||||
|
||||
UUID id = UUID.randomUUID();
|
||||
|
||||
FlavorInZone flavorInZoneToConvert = new FlavorInZone(Flavor.builder().id(id.toString())
|
||||
FlavorInRegion flavorInRegionToConvert = new FlavorInRegion(Flavor.builder().id(id.toString())
|
||||
.name("Test Flavor " + id).ram(262144).disk(10000).vcpus(16).build(), "az-1.region-a.geo-1");
|
||||
|
||||
Hardware converted = new FlavorInZoneToHardware(locationIndex).apply(flavorInZoneToConvert);
|
||||
Hardware converted = new FlavorInRegionToHardware(locationIndex).apply(flavorInRegionToConvert);
|
||||
|
||||
Flavor flavorToConvert = flavorInZoneToConvert.getFlavor();
|
||||
Flavor flavorToConvert = flavorInRegionToConvert.getFlavor();
|
||||
assertEquals(converted.getName(), flavorToConvert.getName());
|
||||
assertEquals(converted.getId(), flavorInZoneToConvert.slashEncode());
|
||||
assertEquals(converted.getId(), flavorInRegionToConvert.slashEncode());
|
||||
assertEquals(converted.getProviderId(), flavorToConvert.getId());
|
||||
assertEquals(converted.getLocation(), locationIndex.get().get("az-1.region-a.geo-1"));
|
||||
|
||||
|
@ -80,9 +80,9 @@ public class FlavorInZoneToHardwareTest {
|
|||
|
||||
UUID id = UUID.randomUUID();
|
||||
|
||||
FlavorInZone flavorInZoneToConvert = new FlavorInZone(Flavor.builder().id(id.toString())
|
||||
FlavorInRegion flavorInRegionToConvert = new FlavorInRegion(Flavor.builder().id(id.toString())
|
||||
.name("Test Flavor " + id).ram(262144).disk(10000).vcpus(16).build(), "South");
|
||||
new FlavorInZoneToHardware(locationIndex).apply(flavorInZoneToConvert);
|
||||
new FlavorInRegionToHardware(locationIndex).apply(flavorInRegionToConvert);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.jclouds.domain.LocationBuilder;
|
|||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Image;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ImageInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ImageInRegion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -40,30 +40,30 @@ import com.google.common.collect.ImmutableMap;
|
|||
/**
|
||||
* Tests the function that transforms nova-specific images to generic images.
|
||||
*/
|
||||
@Test(testName = "ImageInZoneToHardwareTest")
|
||||
public class ImageInZoneToImageTest {
|
||||
@Test(testName = "ImageInRegionToHardwareTest")
|
||||
public class ImageInRegionToImageTest {
|
||||
|
||||
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
|
||||
"openstack-nova").build();
|
||||
Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.ZONE).parent(provider).build();
|
||||
Location region = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.REGION).parent(provider).build();
|
||||
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location> of("az-1.region-a.geo-1", zone));
|
||||
|
||||
.<String, Location> of("az-1.region-a.geo-1", region));
|
||||
|
||||
@Test
|
||||
public void testConversionWhereLocationFound() {
|
||||
UUID id = UUID.randomUUID();
|
||||
Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).status(Image.Status.DELETED).build();
|
||||
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
|
||||
"My Test OS", true);
|
||||
ImageInZoneToImage converter = new ImageInZoneToImage(NovaComputeServiceContextModule.toPortableImageStatus,
|
||||
ImageInRegionToImage converter = new ImageInRegionToImage(NovaComputeServiceContextModule.toPortableImageStatus,
|
||||
constant(operatingSystem), locationIndex);
|
||||
|
||||
ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "az-1.region-a.geo-1");
|
||||
ImageInRegion novaImageInRegionToConvert = new ImageInRegion(novaImageToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
org.jclouds.compute.domain.Image convertedImage = converter.apply(novaImageInZoneToConvert);
|
||||
org.jclouds.compute.domain.Image convertedImage = converter.apply(novaImageInRegionToConvert);
|
||||
|
||||
assertEquals(convertedImage.getId(), novaImageInZoneToConvert.slashEncode());
|
||||
assertEquals(convertedImage.getId(), novaImageInRegionToConvert.slashEncode());
|
||||
assertEquals(convertedImage.getProviderId(), novaImageToConvert.getId());
|
||||
assertEquals(convertedImage.getLocation(), locationIndex.get().get("az-1.region-a.geo-1"));
|
||||
|
||||
|
@ -78,12 +78,12 @@ public class ImageInZoneToImageTest {
|
|||
Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build();
|
||||
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
|
||||
"My Test OS", true);
|
||||
ImageInZoneToImage converter = new ImageInZoneToImage(NovaComputeServiceContextModule.toPortableImageStatus,
|
||||
ImageInRegionToImage converter = new ImageInRegionToImage(NovaComputeServiceContextModule.toPortableImageStatus,
|
||||
constant(operatingSystem), locationIndex);
|
||||
|
||||
ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "South");
|
||||
ImageInRegion novaImageInRegionToConvert = new ImageInRegion(novaImageToConvert, "South");
|
||||
|
||||
converter.apply(novaImageInZoneToConvert);
|
||||
converter.apply(novaImageInRegionToConvert);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
|
@ -27,7 +27,7 @@ import org.jclouds.compute.domain.SecurityGroup;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -35,56 +35,56 @@ import com.google.common.base.Suppliers;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@Test(groups = "unit", testName = "NovaSecurityGroupInZoneToSecurityGroupTest")
|
||||
public class NovaSecurityGroupInZoneToSecurityGroupTest {
|
||||
@Test(groups = "unit", testName = "NovaSecurityGroupInRegionToSecurityGroupTest")
|
||||
public class NovaSecurityGroupInRegionToSecurityGroupTest {
|
||||
|
||||
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova")
|
||||
.description("openstack-nova").build();
|
||||
Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
|
||||
.scope(LocationScope.ZONE).parent(provider).build();
|
||||
Location region = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
|
||||
.scope(LocationScope.REGION).parent(provider).build();
|
||||
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location>of("az-1.region-a.geo-1", zone));
|
||||
.<String, Location>of("az-1.region-a.geo-1", region));
|
||||
|
||||
|
||||
@Test
|
||||
public void testApplyWithGroup() {
|
||||
NovaSecurityGroupInZoneToSecurityGroup parser = createGroupParser();
|
||||
NovaSecurityGroupInRegionToSecurityGroup parser = createGroupParser();
|
||||
|
||||
SecurityGroupInZone origGroup = new SecurityGroupInZone(securityGroupWithGroup(), zone.getId());
|
||||
SecurityGroupInRegion origGroup = new SecurityGroupInRegion(securityGroupWithGroup(), region.getId());
|
||||
|
||||
SecurityGroup newGroup = parser.apply(origGroup);
|
||||
|
||||
assertEquals(newGroup.getId(), origGroup.getZone() + "/" + origGroup.getSecurityGroup().getId());
|
||||
assertEquals(newGroup.getId(), origGroup.getRegion() + "/" + origGroup.getSecurityGroup().getId());
|
||||
assertEquals(newGroup.getProviderId(), origGroup.getSecurityGroup().getId());
|
||||
assertEquals(newGroup.getName(), origGroup.getSecurityGroup().getName());
|
||||
assertEquals(newGroup.getOwnerId(), origGroup.getSecurityGroup().getTenantId());
|
||||
assertEquals(newGroup.getIpPermissions(), ImmutableSet.copyOf(transform(origGroup.getSecurityGroup().getRules(),
|
||||
NovaSecurityGroupToSecurityGroupTest.ruleConverter)));
|
||||
assertEquals(newGroup.getLocation().getId(), origGroup.getZone());
|
||||
assertEquals(newGroup.getLocation().getId(), origGroup.getRegion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyWithCidr() {
|
||||
|
||||
NovaSecurityGroupInZoneToSecurityGroup parser = createGroupParser();
|
||||
NovaSecurityGroupInRegionToSecurityGroup parser = createGroupParser();
|
||||
|
||||
SecurityGroupInZone origGroup = new SecurityGroupInZone(securityGroupWithCidr(), zone.getId());
|
||||
SecurityGroupInRegion origGroup = new SecurityGroupInRegion(securityGroupWithCidr(), region.getId());
|
||||
|
||||
SecurityGroup newGroup = parser.apply(origGroup);
|
||||
|
||||
assertEquals(newGroup.getId(), origGroup.getZone() + "/" + origGroup.getSecurityGroup().getId());
|
||||
assertEquals(newGroup.getId(), origGroup.getRegion() + "/" + origGroup.getSecurityGroup().getId());
|
||||
assertEquals(newGroup.getProviderId(), origGroup.getSecurityGroup().getId());
|
||||
assertEquals(newGroup.getName(), origGroup.getSecurityGroup().getName());
|
||||
assertEquals(newGroup.getOwnerId(), origGroup.getSecurityGroup().getTenantId());
|
||||
assertEquals(newGroup.getIpPermissions(), ImmutableSet.copyOf(transform(origGroup.getSecurityGroup().getRules(),
|
||||
NovaSecurityGroupToSecurityGroupTest.ruleConverter)));
|
||||
assertEquals(newGroup.getLocation().getId(), origGroup.getZone());
|
||||
assertEquals(newGroup.getLocation().getId(), origGroup.getRegion());
|
||||
}
|
||||
|
||||
private NovaSecurityGroupInZoneToSecurityGroup createGroupParser() {
|
||||
private NovaSecurityGroupInRegionToSecurityGroup createGroupParser() {
|
||||
NovaSecurityGroupToSecurityGroup baseParser = new NovaSecurityGroupToSecurityGroup(NovaSecurityGroupToSecurityGroupTest.ruleConverter);
|
||||
|
||||
NovaSecurityGroupInZoneToSecurityGroup parser = new NovaSecurityGroupInZoneToSecurityGroup(baseParser, locationIndex);
|
||||
NovaSecurityGroupInRegionToSecurityGroup parser = new NovaSecurityGroupInRegionToSecurityGroup(baseParser, locationIndex);
|
||||
|
||||
return parser;
|
||||
}
|
|
@ -29,8 +29,8 @@ import org.jclouds.domain.LocationScope;
|
|||
import org.jclouds.net.domain.IpProtocol;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.TenantIdAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
|
@ -49,23 +49,23 @@ public class NovaSecurityGroupToSecurityGroupTest {
|
|||
|
||||
private static final Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova")
|
||||
.description("openstack-nova").build();
|
||||
private static final Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
|
||||
.scope(LocationScope.ZONE).parent(provider).build();
|
||||
private static final Location region = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
|
||||
.scope(LocationScope.REGION).parent(provider).build();
|
||||
private static final Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location>of("az-1.region-a.geo-1", zone));
|
||||
.<String, Location>of("az-1.region-a.geo-1", region));
|
||||
|
||||
|
||||
private static final Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysTrue();
|
||||
private static final Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion = Predicates.alwaysTrue();
|
||||
|
||||
private static final Map<ZoneAndName, SecurityGroupInZone> groupMap = ImmutableMap.of(
|
||||
ZoneAndName.fromZoneAndName("az-1.region-a.geo-1", "some-group"), new SecurityGroupInZone(securityGroupWithGroup(), "az-1.region-a.geo-1"),
|
||||
ZoneAndName.fromZoneAndName("az-1.region-a.geo-1", "some-other-group"), new SecurityGroupInZone(securityGroupWithCidr(), "az-1.region-a.geo-1"));
|
||||
private static final Map<RegionAndName, SecurityGroupInRegion> groupMap = ImmutableMap.of(
|
||||
RegionAndName.fromRegionAndName("az-1.region-a.geo-1", "some-group"), new SecurityGroupInRegion(securityGroupWithGroup(), "az-1.region-a.geo-1"),
|
||||
RegionAndName.fromRegionAndName("az-1.region-a.geo-1", "some-other-group"), new SecurityGroupInRegion(securityGroupWithCidr(), "az-1.region-a.geo-1"));
|
||||
|
||||
// weird compilation error means have to declare extra generics for call to build() - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=365818
|
||||
private static final Supplier <LoadingCache<ZoneAndName, SecurityGroupInZone>> groupCache = Suppliers.<LoadingCache<ZoneAndName, SecurityGroupInZone>> ofInstance(
|
||||
CacheBuilder.newBuilder().<ZoneAndName, SecurityGroupInZone>build(CacheLoader.from(Functions.forMap(groupMap))));
|
||||
private static final Supplier <LoadingCache<RegionAndName, SecurityGroupInRegion>> groupCache = Suppliers.<LoadingCache<RegionAndName, SecurityGroupInRegion>> ofInstance(
|
||||
CacheBuilder.newBuilder().<RegionAndName, SecurityGroupInRegion>build(CacheLoader.from(Functions.forMap(groupMap))));
|
||||
|
||||
public static final SecurityGroupRuleToIpPermission ruleConverter = new SecurityGroupRuleToIpPermission(returnSecurityGroupExistsInZone, locationIndex,
|
||||
public static final SecurityGroupRuleToIpPermission ruleConverter = new SecurityGroupRuleToIpPermission(returnSecurityGroupExistsInRegion, locationIndex,
|
||||
groupCache.get());
|
||||
|
||||
public static org.jclouds.openstack.nova.v2_0.domain.SecurityGroup securityGroupWithGroup() {
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.parse.ParseServerTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -42,49 +42,49 @@ import com.google.common.collect.ImmutableMultimap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
@Test(testName = "OrphanedGroupsByZoneIdTest")
|
||||
public class OrphanedGroupsByZoneIdTest {
|
||||
@Test(testName = "OrphanedGroupsByRegionIdTest")
|
||||
public class OrphanedGroupsByRegionIdTest {
|
||||
|
||||
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
|
||||
"openstack-nova").build();
|
||||
Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.ZONE).parent(provider).build();
|
||||
Location region = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.REGION).parent(provider).build();
|
||||
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location> of("az-1.region-a.geo-1", zone));
|
||||
.<String, Location> of("az-1.region-a.geo-1", region));
|
||||
|
||||
GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
|
||||
|
||||
|
||||
@Test
|
||||
public void testWhenComputeServiceSaysAllNodesAreDeadBothGroupsAreReturned() {
|
||||
|
||||
ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
|
||||
ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1");
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
|
||||
ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
|
||||
ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1");
|
||||
|
||||
ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
|
||||
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
|
||||
.<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
|
||||
|
||||
Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));
|
||||
|
||||
assertEquals(new OrphanedGroupsByZoneId(Predicates.<ZoneAndName> alwaysTrue()).apply(set), ImmutableMultimap
|
||||
assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysTrue()).apply(set), ImmutableMultimap
|
||||
.<String, String> builder().putAll("az-1.region-a.geo-1", "sample", "test").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenComputeServiceSaysAllNodesAreDeadNoGroupsAreReturned() {
|
||||
|
||||
ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
|
||||
ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1");
|
||||
ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
|
||||
ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1");
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
|
||||
ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
|
||||
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
|
||||
.<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
|
||||
|
||||
Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));
|
||||
|
||||
assertEquals(new OrphanedGroupsByZoneId(Predicates.<ZoneAndName> alwaysFalse()).apply(set), ImmutableMultimap
|
||||
assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysFalse()).apply(set), ImmutableMultimap
|
||||
.<String, String> of());
|
||||
|
||||
}
|
|
@ -38,7 +38,7 @@ import org.jclouds.domain.LocationBuilder;
|
|||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.parse.ParseServerTest;
|
||||
import org.jclouds.openstack.nova.v2_0.parse.ParseServerWithoutImageTest;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
|
@ -55,15 +55,15 @@ import com.google.inject.Guice;
|
|||
* Tests for the function for transforming a nova specific Server into a generic
|
||||
* NodeMetadata object.
|
||||
*/
|
||||
@Test(testName = "ServerInZoneToNodeMetadataTest")
|
||||
public class ServerInZoneToNodeMetadataTest {
|
||||
@Test(testName = "ServerInRegionToNodeMetadataTest")
|
||||
public class ServerInRegionToNodeMetadataTest {
|
||||
|
||||
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova")
|
||||
.description("openstack-nova").build();
|
||||
Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
|
||||
.scope(LocationScope.ZONE).parent(provider).build();
|
||||
Location region = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
|
||||
.scope(LocationScope.REGION).parent(provider).build();
|
||||
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location> of("az-1.region-a.geo-1", zone));
|
||||
.<String, Location> of("az-1.region-a.geo-1", region));
|
||||
|
||||
GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
|
||||
|
||||
|
@ -71,10 +71,10 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
public void testWhenNoHardwareOrImageMatchServerScopedIdsImageIdIsStillSet() {
|
||||
|
||||
Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/FOOOOOOOO").providerId("FOOOOOOOO")
|
||||
.location(zone).build();
|
||||
.location(region).build();
|
||||
Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/FOOOOOOOO")
|
||||
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
|
||||
.providerId("FOOOOOOOO").description("foobuntu").location(zone).status(Image.Status.AVAILABLE).build();
|
||||
.providerId("FOOOOOOOO").description("foobuntu").location(region).status(Image.Status.AVAILABLE).build();
|
||||
|
||||
checkHardwareAndImageStatus(null, existingHardware, "az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54",
|
||||
null, existingImage);
|
||||
|
@ -84,11 +84,11 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
public void testWhenNoHardwareAndImageMatchServerScopedIdsHardwareOperatingSystemAndImageIdAreSet() {
|
||||
|
||||
Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(region).build();
|
||||
Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
|
||||
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
|
||||
.providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
|
||||
.location(zone).build();
|
||||
.location(region).build();
|
||||
|
||||
checkHardwareAndImageStatus(existingHardware, existingHardware, existingImage.getId(),
|
||||
existingImage.getOperatingSystem(), existingImage);
|
||||
|
@ -97,11 +97,11 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
@Test
|
||||
public void testNullAccessIPs() {
|
||||
Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(region).build();
|
||||
Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
|
||||
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
|
||||
.providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
|
||||
.location(zone).build();
|
||||
.location(region).build();
|
||||
|
||||
Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
|
||||
Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
|
||||
|
@ -111,14 +111,14 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
.accessIPv6(null)
|
||||
.build();
|
||||
|
||||
ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
|
||||
ServerInRegion serverInRegionToConvert = new ServerInRegion(serverToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
|
||||
ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
|
||||
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
|
||||
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInRegionToConvert);
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getPrivateAddresses());
|
||||
assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
|
||||
|
@ -131,11 +131,11 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
@Test
|
||||
public void testDuplicateAccessIPs() {
|
||||
Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(region).build();
|
||||
Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
|
||||
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
|
||||
.providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
|
||||
.location(zone).build();
|
||||
.location(region).build();
|
||||
|
||||
Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
|
||||
Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
|
||||
|
@ -145,14 +145,14 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
.accessIPv6("::babe:67.23.10.132")
|
||||
.build();
|
||||
|
||||
ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
|
||||
ServerInRegion serverInRegionToConvert = new ServerInRegion(serverToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
|
||||
ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
|
||||
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
|
||||
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInRegionToConvert);
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getPrivateAddresses());
|
||||
assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
|
||||
|
@ -165,11 +165,11 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
@Test
|
||||
public void testAlternateAccessIPs() {
|
||||
Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(region).build();
|
||||
Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
|
||||
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
|
||||
.providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
|
||||
.location(zone).build();
|
||||
.location(region).build();
|
||||
|
||||
Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
|
||||
Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
|
||||
|
@ -179,14 +179,14 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
.accessIPv6("::babe:76.32.1.231")
|
||||
.build();
|
||||
|
||||
ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
|
||||
ServerInRegion serverInRegionToConvert = new ServerInRegion(serverToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
|
||||
ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
|
||||
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
|
||||
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInRegionToConvert);
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getPrivateAddresses());
|
||||
assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
|
||||
|
@ -206,22 +206,22 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
@Test
|
||||
public void testServerWithoutImage() {
|
||||
Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(region).build();
|
||||
Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
|
||||
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
|
||||
.providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
|
||||
.location(zone).build();
|
||||
.location(region).build();
|
||||
|
||||
Server serverToConvert = new ParseServerWithoutImageTest().expected();
|
||||
ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
|
||||
ServerInRegion serverInRegionToConvert = new ServerInRegion(serverToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
|
||||
ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
|
||||
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex,
|
||||
Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.of(existingImage)),
|
||||
Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet.of(existingHardware)),
|
||||
namingConvention);
|
||||
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInRegionToConvert);
|
||||
|
||||
assertNull(convertedNodeMetadata.getImageId());
|
||||
}
|
||||
|
@ -235,16 +235,16 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
.of(existingHardware);
|
||||
Server serverToConvert = new ParseServerTest().expected();
|
||||
|
||||
ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
|
||||
ServerInRegion serverInRegionToConvert = new ServerInRegion(serverToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
|
||||
ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
|
||||
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
|
||||
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInRegionToConvert);
|
||||
|
||||
assertEquals(serverInZoneToConvert.slashEncode(), convertedNodeMetadata.getId());
|
||||
assertEquals(serverInRegionToConvert.slashEncode(), convertedNodeMetadata.getId());
|
||||
assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
|
||||
|
||||
assertEquals(convertedNodeMetadata.getLocation().getScope(), LocationScope.HOST);
|
||||
|
@ -279,26 +279,26 @@ public class ServerInZoneToNodeMetadataTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testNewServerWithoutHostIdSetsZoneAsLocation() {
|
||||
public void testNewServerWithoutHostIdSetsRegionAsLocation() {
|
||||
|
||||
Set<Image> images = ImmutableSet.<Image> of();
|
||||
Set<Hardware> hardwares = ImmutableSet.<Hardware> of();
|
||||
|
||||
Server serverToConvert = expectedServer();
|
||||
|
||||
ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
|
||||
ServerInRegion serverInRegionToConvert = new ServerInRegion(serverToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
|
||||
ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
|
||||
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
|
||||
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInRegionToConvert);
|
||||
|
||||
assertEquals(serverInZoneToConvert.slashEncode(), convertedNodeMetadata.getId());
|
||||
assertEquals(serverInRegionToConvert.slashEncode(), convertedNodeMetadata.getId());
|
||||
assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
|
||||
|
||||
assertEquals(convertedNodeMetadata.getLocation(), zone);
|
||||
assertEquals(convertedNodeMetadata.getLocation(), region);
|
||||
|
||||
URI expectedURI = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/37936628937291/servers/71752");
|
||||
assertEquals(convertedNodeMetadata.getUri(), expectedURI);
|
|
@ -26,7 +26,7 @@ import java.net.UnknownHostException;
|
|||
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -48,8 +48,8 @@ public class CreateUniqueKeyPairTest {
|
|||
KeyPair pair = createMock(KeyPair.class);
|
||||
|
||||
Optional optKeyApi = Optional.of(keyApi);
|
||||
|
||||
expect(api.getKeyPairExtensionForZone("zone")).andReturn(optKeyApi).atLeastOnce();
|
||||
|
||||
expect(api.getKeyPairApi("region")).andReturn(optKeyApi).atLeastOnce();
|
||||
|
||||
expect(keyApi.create("group-1")).andReturn(pair);
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class CreateUniqueKeyPairTest {
|
|||
|
||||
}).getInstance(CreateUniqueKeyPair.class);
|
||||
|
||||
assertEquals(parser.load(ZoneAndName.fromZoneAndName("zone", "group")), pair);
|
||||
assertEquals(parser.load(RegionAndName.fromRegionAndName("region", "group")), pair);
|
||||
|
||||
verify(api, keyApi);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class CreateUniqueKeyPairTest {
|
|||
|
||||
KeyPair pair = createMock(KeyPair.class);
|
||||
|
||||
expect(api.getKeyPairExtensionForZone("zone")).andReturn((Optional) Optional.of(keyApi)).atLeastOnce();
|
||||
expect(api.getKeyPairApi("region")).andReturn((Optional) Optional.of(keyApi)).atLeastOnce();
|
||||
|
||||
expect(uniqueIdSupplier.get()).andReturn("1");
|
||||
expect(keyApi.create("group-1")).andThrow(new IllegalStateException());
|
||||
|
@ -100,7 +100,7 @@ public class CreateUniqueKeyPairTest {
|
|||
|
||||
}).getInstance(CreateUniqueKeyPair.class);
|
||||
|
||||
assertEquals(parser.load(ZoneAndName.fromZoneAndName("zone", "group")), pair);
|
||||
assertEquals(parser.load(RegionAndName.fromRegionAndName("region", "group")), pair);
|
||||
|
||||
verify(api, keyApi, uniqueIdSupplier);
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ import static org.testng.Assert.fail;
|
|||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -39,43 +39,43 @@ public class FindSecurityGroupOrCreateTest {
|
|||
|
||||
@Test
|
||||
public void testWhenNotFoundCreatesANewSecurityGroup() throws Exception {
|
||||
Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysFalse();
|
||||
Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion = Predicates.alwaysFalse();
|
||||
|
||||
SecurityGroupInZone securityGroupInZone = createMock(SecurityGroupInZone.class);
|
||||
SecurityGroupInRegion securityGroupInRegion = createMock(SecurityGroupInRegion.class);
|
||||
|
||||
ZoneSecurityGroupNameAndPorts input = new ZoneSecurityGroupNameAndPorts("zone", "groupName", ImmutableSet
|
||||
RegionSecurityGroupNameAndPorts input = new RegionSecurityGroupNameAndPorts("region", "groupName", ImmutableSet
|
||||
.<Integer> of(22, 8080));
|
||||
|
||||
Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = Functions.forMap(ImmutableMap
|
||||
.<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> of(input, securityGroupInZone));
|
||||
Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion> groupCreator = Functions.forMap(ImmutableMap
|
||||
.<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion> of(input, securityGroupInRegion));
|
||||
|
||||
FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
|
||||
returnSecurityGroupExistsInZone, groupCreator);
|
||||
returnSecurityGroupExistsInRegion, groupCreator);
|
||||
|
||||
assertEquals(parser.load(input), securityGroupInZone);
|
||||
assertEquals(parser.load(input), securityGroupInRegion);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWhenFoundReturnsSecurityGroupFromAtomicReferenceValueUpdatedDuringPredicateCheck() throws Exception {
|
||||
final SecurityGroupInZone securityGroupInZone = createMock(SecurityGroupInZone.class);
|
||||
final SecurityGroupInRegion securityGroupInRegion = createMock(SecurityGroupInRegion.class);
|
||||
|
||||
Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = new Predicate<AtomicReference<ZoneAndName>>() {
|
||||
Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion = new Predicate<AtomicReference<RegionAndName>>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(AtomicReference<ZoneAndName> input) {
|
||||
input.set(securityGroupInZone);
|
||||
public boolean apply(AtomicReference<RegionAndName> input) {
|
||||
input.set(securityGroupInRegion);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
|
||||
RegionAndName input = RegionAndName.fromRegionAndName("region", "groupName");
|
||||
|
||||
Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
|
||||
Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion> groupCreator = new Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion>() {
|
||||
|
||||
@Override
|
||||
public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
|
||||
public SecurityGroupInRegion apply(RegionSecurityGroupNameAndPorts input) {
|
||||
fail();
|
||||
return null;
|
||||
}
|
||||
|
@ -83,24 +83,24 @@ public class FindSecurityGroupOrCreateTest {
|
|||
};
|
||||
|
||||
FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
|
||||
returnSecurityGroupExistsInZone, groupCreator);
|
||||
returnSecurityGroupExistsInRegion, groupCreator);
|
||||
|
||||
assertEquals(parser.load(input), securityGroupInZone);
|
||||
assertEquals(parser.load(input), securityGroupInRegion);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testWhenFoundPredicateMustUpdateAtomicReference() throws Exception {
|
||||
|
||||
Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysTrue();
|
||||
Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion = Predicates.alwaysTrue();
|
||||
|
||||
ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
|
||||
RegionAndName input = RegionAndName.fromRegionAndName("region", "groupName");
|
||||
|
||||
Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
|
||||
Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion> groupCreator = new Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion>() {
|
||||
|
||||
@Override
|
||||
public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
|
||||
public SecurityGroupInRegion apply(RegionSecurityGroupNameAndPorts input) {
|
||||
fail();
|
||||
return null;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class FindSecurityGroupOrCreateTest {
|
|||
};
|
||||
|
||||
FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
|
||||
returnSecurityGroupExistsInZone, groupCreator);
|
||||
returnSecurityGroupExistsInRegion, groupCreator);
|
||||
|
||||
parser.load(input);
|
||||
|
||||
|
@ -117,15 +117,15 @@ public class FindSecurityGroupOrCreateTest {
|
|||
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testWhenNotFoundInputMustBeZoneSecurityGroupNameAndPorts() throws Exception {
|
||||
Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysFalse();
|
||||
public void testWhenNotFoundInputMustBeRegionSecurityGroupNameAndPorts() throws Exception {
|
||||
Predicate<AtomicReference<RegionAndName>> returnSecurityGroupExistsInRegion = Predicates.alwaysFalse();
|
||||
|
||||
ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
|
||||
RegionAndName input = RegionAndName.fromRegionAndName("region", "groupName");
|
||||
|
||||
Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
|
||||
Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion> groupCreator = new Function<RegionSecurityGroupNameAndPorts, SecurityGroupInRegion>() {
|
||||
|
||||
@Override
|
||||
public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
|
||||
public SecurityGroupInRegion apply(RegionSecurityGroupNameAndPorts input) {
|
||||
fail();
|
||||
return null;
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ public class FindSecurityGroupOrCreateTest {
|
|||
};
|
||||
|
||||
FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
|
||||
returnSecurityGroupExistsInZone, groupCreator);
|
||||
returnSecurityGroupExistsInRegion, groupCreator);
|
||||
|
||||
parser.load(input);
|
||||
|
||||
|
|
|
@ -23,10 +23,9 @@ import static org.easymock.EasyMock.verify;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.AssertJUnit.assertFalse;
|
||||
|
||||
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
|
||||
import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -43,7 +42,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
FloatingIPApi ipApi = createMock(FloatingIPApi.class);
|
||||
FloatingIP testIp = FloatingIP.builder().id("1").ip("1.1.1.1").fixedIp("10.1.1.1").instanceId("i-blah").build();
|
||||
|
||||
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
|
||||
expect(api.getFloatingIPApi("RegionOne")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
|
||||
expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(testIp)))
|
||||
.atLeastOnce();
|
||||
|
||||
|
@ -52,7 +51,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
|
||||
LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
|
||||
|
||||
assertEquals(ImmutableSet.copyOf(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah"))), ImmutableSet.of(testIp));
|
||||
assertEquals(ImmutableSet.copyOf(parser.load(RegionAndId.fromRegionAndId("RegionOne", "i-blah"))), ImmutableSet.of(testIp));
|
||||
|
||||
verify(api);
|
||||
verify(ipApi);
|
||||
|
@ -63,7 +62,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
NovaApi api = createMock(NovaApi.class);
|
||||
FloatingIPApi ipApi = createMock(FloatingIPApi.class);
|
||||
|
||||
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
|
||||
expect(api.getFloatingIPApi("region")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
|
||||
|
||||
expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of()))
|
||||
.atLeastOnce();
|
||||
|
@ -73,7 +72,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
|
||||
LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
|
||||
|
||||
assertFalse(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah")).iterator().hasNext());
|
||||
assertFalse(parser.load(RegionAndId.fromRegionAndId("region", "i-blah")).iterator().hasNext());
|
||||
|
||||
verify(api);
|
||||
verify(ipApi);
|
||||
|
@ -85,7 +84,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
NovaApi api = createMock(NovaApi.class);
|
||||
FloatingIPApi ipApi = createMock(FloatingIPApi.class);
|
||||
|
||||
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
|
||||
expect(api.getFloatingIPApi("region")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
|
||||
|
||||
expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(FloatingIP.builder().id("1").ip("1.1.1.1").build())))
|
||||
.atLeastOnce();
|
||||
|
@ -95,7 +94,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
|
||||
LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
|
||||
|
||||
assertFalse(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah")).iterator().hasNext());
|
||||
assertFalse(parser.load(RegionAndId.fromRegionAndId("region", "i-blah")).iterator().hasNext());
|
||||
|
||||
verify(api);
|
||||
verify(ipApi);
|
||||
|
|
|
@ -48,7 +48,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.suspend("1"));
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.suspend("1"));
|
||||
}
|
||||
|
@ -73,11 +73,11 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
|
||||
HttpResponse.builder().statusCode(403).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
api.suspend("1");
|
||||
}
|
||||
|
||||
|
||||
public void testResume() {
|
||||
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/1/action");
|
||||
ServerAdminApi api = requestsSendResponses(
|
||||
|
@ -85,7 +85,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.resume("1"));
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.resume("1"));
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
|
||||
HttpResponse.builder().statusCode(403).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
api.resume("1");
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "lock").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.lock("1"));
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "lock").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.lock("1"));
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.unlock("1"));
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.unlock("1"));
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "pause").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.pause("1"));
|
||||
}
|
||||
|
@ -182,11 +182,11 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "pause").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.pause("1"));
|
||||
}
|
||||
|
||||
|
||||
public void testUnpause() {
|
||||
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/1/action");
|
||||
ServerAdminApi api = requestsSendResponses(
|
||||
|
@ -194,7 +194,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.unpause("1"));
|
||||
}
|
||||
|
@ -206,11 +206,11 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.unpause("1"));
|
||||
}
|
||||
|
||||
|
||||
public void testMigrateServer() {
|
||||
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/1/action");
|
||||
ServerAdminApi api = requestsSendResponses(
|
||||
|
@ -218,7 +218,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.migrate("1"));
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.migrate("1"));
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.resetNetwork("1"));
|
||||
}
|
||||
|
@ -255,11 +255,11 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.resetNetwork("1"));
|
||||
}
|
||||
|
||||
|
||||
public void testInjectNetworkInfoIntoServer() {
|
||||
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/1/action");
|
||||
ServerAdminApi api = requestsSendResponses(
|
||||
|
@ -267,7 +267,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.injectNetworkInfo("1"));
|
||||
}
|
||||
|
@ -279,11 +279,11 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.injectNetworkInfo("1"));
|
||||
}
|
||||
|
||||
|
||||
public void testBackupServer() {
|
||||
ServerAdminApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
|
@ -291,7 +291,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
authenticatedGET().endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/1/action").method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(202).addHeader("Location", "http://172.16.89.149:8774/v2/images/1976b3b3-409a-468d-b16c-a9172c341b46").build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
String imageId = api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other")));
|
||||
assertEquals(imageId, "1976b3b3-409a-468d-b16c-a9172c341b46");
|
||||
|
@ -306,7 +306,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
authenticatedGET().endpoint(endpoint).method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other")));
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
|
||||
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(202).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.liveMigrate("1", "bighost", true, false));
|
||||
}
|
||||
|
@ -332,11 +332,11 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
|
||||
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getServerAdminApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.liveMigrate("1", "bighost", true, false));
|
||||
}
|
||||
|
||||
|
||||
protected HttpRequest.Builder<?> standardActionRequestBuilderVoidResponse(URI endpoint, String actionName) {
|
||||
return HttpRequest.builder()
|
||||
.method("POST")
|
||||
|
|
|
@ -42,7 +42,7 @@ import com.google.common.collect.Iterables;
|
|||
|
||||
/**
|
||||
* Tests behavior of HostAdministrationApi
|
||||
*
|
||||
*
|
||||
* TODO test migration methods
|
||||
*/
|
||||
@Test(groups = "live", testName = "AdminActionsApiLiveTest", singleThreaded = true)
|
||||
|
@ -51,7 +51,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
|
|||
private ServerApi serverApi;
|
||||
private ExtensionApi extensionApi;
|
||||
private Optional<? extends ServerAdminApi> apiOption;
|
||||
private String zone;
|
||||
private String region;
|
||||
|
||||
private String testServerId;
|
||||
private String backupImageId;
|
||||
|
@ -60,13 +60,13 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
|
|||
@Override
|
||||
public void setup() {
|
||||
super.setup();
|
||||
zone = Iterables.getLast(api.getConfiguredZones(), "nova");
|
||||
serverApi = api.getServerApiForZone(zone);
|
||||
extensionApi = api.getExtensionApiForZone(zone);
|
||||
imageApi = api.getImageApiForZone(zone);
|
||||
apiOption = api.getServerAdminExtensionForZone(zone);
|
||||
region = Iterables.getLast(api.getConfiguredRegions(), "nova");
|
||||
serverApi = api.getServerApi(region);
|
||||
extensionApi = api.getExtensionApi(region);
|
||||
imageApi = api.getImageApi(region);
|
||||
apiOption = api.getServerAdminApi(region);
|
||||
if (apiOption.isPresent()) {
|
||||
testServerId = createServerInZone(zone).getId();
|
||||
testServerId = createServerInRegion(region).getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
|
|||
protected void tearDown() {
|
||||
if (apiOption.isPresent()) {
|
||||
if (testServerId != null) {
|
||||
assertTrue(api.getServerApiForZone(zone).delete(testServerId));
|
||||
assertTrue(api.getServerApi(region).delete(testServerId));
|
||||
}
|
||||
if (backupImageId != null) {
|
||||
imageApi.delete(backupImageId);
|
||||
|
|
|
@ -19,10 +19,11 @@ package org.jclouds.openstack.nova.v2_0.extensions;
|
|||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.AvailabilityZone;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.AvailabilityZone;
|
||||
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -46,7 +47,7 @@ public class AvailabilityZoneApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi availabilityZonesApi = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
|
||||
|
||||
assertEquals(availabilityZonesApi.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(availabilityZonesApi.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
FluentIterable<? extends AvailabilityZone> zones = availabilityZonesApi.getAvailabilityZoneApi("az-1.region-a.geo-1").get().list();
|
||||
|
||||
|
|
|
@ -18,9 +18,11 @@ package org.jclouds.openstack.nova.v2_0.extensions;
|
|||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.AvailabilityZone;
|
||||
|
||||
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.AvailabilityZone;
|
||||
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
|
|
@ -42,16 +42,16 @@ public class ConsolesApiLiveTest extends BaseNovaApiLiveTest {
|
|||
}
|
||||
|
||||
private void testGetConsole(Console.Type consoleType) {
|
||||
for (String zoneId : api.getConfiguredZones()) {
|
||||
Optional<? extends ConsolesApi> apiOption = api.getConsolesExtensionForZone(zoneId);
|
||||
for (String regionId : api.getConfiguredRegions()) {
|
||||
Optional<? extends ConsolesApi> apiOption = api.getConsolesApi(regionId);
|
||||
if (!apiOption.isPresent()) {
|
||||
System.err.println("Consoles extension not present in server.");
|
||||
continue;
|
||||
}
|
||||
|
||||
ConsolesApi api = apiOption.get();
|
||||
ServerApi serverApi = this.api.getServerApiForZone(zoneId);
|
||||
Server server = createServerInZone(zoneId);
|
||||
ServerApi serverApi = this.api.getServerApi(regionId);
|
||||
Server server = createServerInRegion(regionId);
|
||||
Console console = api.getConsole(server.getId(), consoleType);
|
||||
assertNotNull(console.getType());
|
||||
assertTrue(consoleType.equals(console.getType()));
|
||||
|
|
|
@ -90,9 +90,9 @@ public class ConsolesApiMockTest extends BaseOpenStackMockTest<NovaApi> {
|
|||
try {
|
||||
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
|
||||
|
||||
String zoneId = getFirst(novaApi.getConfiguredZones(), "RegionTwo");
|
||||
String regionId = getFirst(novaApi.getConfiguredRegions(), "RegionTwo");
|
||||
|
||||
ConsolesApi consolesApi = novaApi.getConsolesExtensionForZone(zoneId).get();
|
||||
ConsolesApi consolesApi = novaApi.getConsolesApi(regionId).get();
|
||||
|
||||
assertEquals(server.getRequestCount(), 2);
|
||||
assertAuthentication(server);
|
||||
|
@ -120,9 +120,9 @@ public class ConsolesApiMockTest extends BaseOpenStackMockTest<NovaApi> {
|
|||
try {
|
||||
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
|
||||
|
||||
String zoneId = getFirst(novaApi.getConfiguredZones(), "RegionTwo");
|
||||
String regionId = getFirst(novaApi.getConfiguredRegions(), "RegionTwo");
|
||||
|
||||
ConsolesApi consolesApi = novaApi.getConsolesExtensionForZone(zoneId).get();
|
||||
ConsolesApi consolesApi = novaApi.getConsolesApi(regionId).get();
|
||||
|
||||
assertEquals(server.getRequestCount(), 2);
|
||||
assertAuthentication(server);
|
||||
|
|
|
@ -44,7 +44,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_extra_specs.json")).build()
|
||||
).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getFlavorExtraSpecsApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.getMetadata("9"), ImmutableMap.of("test", "value1"));
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getFlavorExtraSpecsApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.getMetadata("9").isEmpty());
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"extra_specs\":{\"test1\":\"somevalue\"}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).build()
|
||||
).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getFlavorExtraSpecsApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.updateMetadata("9", ImmutableMap.of("test1", "somevalue")));
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"test1\":\"somevalue\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).build()
|
||||
).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getFlavorExtraSpecsApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.updateMetadataEntry("5", "test1", "somevalue"));
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"test1\":\"another value\"}", MediaType.APPLICATION_JSON)).build()
|
||||
).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getFlavorExtraSpecsApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.getMetadataKey("5", "test1"), "another value");
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getFlavorExtraSpecsApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertNull(api.getMetadataKey("5", "test1"));
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(200).build()
|
||||
).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getFlavorExtraSpecsApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.deleteMetadataKey("5", "test1"));
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(404).build()
|
||||
).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
|
||||
).getFlavorExtraSpecsApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.deleteMetadataKey("5", "test1"));
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ import com.google.common.collect.Maps;
|
|||
public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest {
|
||||
private FlavorApi flavorApi;
|
||||
private Optional<? extends FlavorExtraSpecsApi> apiOption;
|
||||
private String zone;
|
||||
private String region;
|
||||
|
||||
private Resource testFlavor;
|
||||
private Map<String, String> testSpecs = ImmutableMap.of("jclouds-test", "some data", "jclouds-test2", "more data!");
|
||||
|
@ -50,9 +50,9 @@ public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest {
|
|||
@Override
|
||||
public void setup() {
|
||||
super.setup();
|
||||
zone = Iterables.getLast(api.getConfiguredZones(), "nova");
|
||||
flavorApi = api.getFlavorApiForZone(zone);
|
||||
apiOption = api.getFlavorExtraSpecsExtensionForZone(zone);
|
||||
region = Iterables.getLast(api.getConfiguredRegions(), "nova");
|
||||
flavorApi = api.getFlavorApi(region);
|
||||
apiOption = api.getFlavorExtraSpecsApi(region);
|
||||
}
|
||||
|
||||
@AfterClass(groups = { "integration", "live" })
|
||||
|
|
|
@ -41,9 +41,9 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse);
|
||||
|
||||
assertEquals(apiWhenExtensionNotInList.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
assertTrue(apiWhenExtensionNotInList.getFloatingIPExtensionForZone("az-1.region-a.geo-1").isPresent());
|
||||
assertTrue(apiWhenExtensionNotInList.getFloatingIPApi("az-1.region-a.geo-1").isPresent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -52,9 +52,9 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, unmatchedExtensionsOfNovaResponse);
|
||||
|
||||
assertEquals(apiWhenExtensionNotInList.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
assertFalse(apiWhenExtensionNotInList.getFloatingIPExtensionForZone("az-1.region-a.geo-1").isPresent());
|
||||
assertFalse(apiWhenExtensionNotInList.getFloatingIPApi("az-1.region-a.geo-1").isPresent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -72,9 +72,9 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
|
||||
|
||||
assertEquals(apiWhenFloatingIPsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenFloatingIPsExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().list()
|
||||
assertEquals(apiWhenFloatingIPsExist.getFloatingIPApi("az-1.region-a.geo-1").get().list()
|
||||
.toString(), new ParseFloatingIPListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
|
||||
|
||||
assertTrue(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().list().isEmpty());
|
||||
assertTrue(apiWhenNoServersExist.getFloatingIPApi("az-1.region-a.geo-1").get().list().isEmpty());
|
||||
}
|
||||
|
||||
public void testGetFloatingIPWhenResponseIs2xx() throws Exception {
|
||||
|
@ -108,7 +108,7 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse);
|
||||
|
||||
assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().get("1")
|
||||
assertEquals(apiWhenFloatingIPsExist.getFloatingIPApi("az-1.region-a.geo-1").get().get("1")
|
||||
.toString(), new ParseFloatingIPTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse);
|
||||
|
||||
assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().get("1"));
|
||||
assertNull(apiWhenNoServersExist.getFloatingIPApi("az-1.region-a.geo-1").get().get("1"));
|
||||
}
|
||||
|
||||
public void testAllocateWhenResponseIs2xx() throws Exception {
|
||||
|
@ -144,7 +144,7 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP,
|
||||
createFloatingIPResponse);
|
||||
|
||||
assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create().toString(),
|
||||
assertEquals(apiWhenFloatingIPsExist.getFloatingIPApi("az-1.region-a.geo-1").get().create().toString(),
|
||||
new ParseFloatingIPTest().expected().toString());
|
||||
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP,
|
||||
createFloatingIPResponse);
|
||||
|
||||
assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create());
|
||||
assertNull(apiWhenNoServersExist.getFloatingIPApi("az-1.region-a.geo-1").get().create());
|
||||
}
|
||||
|
||||
public void testAllocateWithPoolNameWhenResponseIs2xx() throws Exception {
|
||||
|
@ -183,7 +183,7 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP,
|
||||
createFloatingIPResponse);
|
||||
|
||||
assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocateFromPool("myPool").toString(),
|
||||
assertEquals(apiWhenFloatingIPsExist.getFloatingIPApi("az-1.region-a.geo-1").get().allocateFromPool("myPool").toString(),
|
||||
new ParseFloatingIPTest().expected().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
|
|||
|
||||
@Test
|
||||
public void testListFloatingIPs() throws Exception {
|
||||
for (String zoneId : api.getConfiguredZones()) {
|
||||
Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPExtensionForZone(zoneId);
|
||||
for (String regionId : api.getConfiguredRegions()) {
|
||||
Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPApi(regionId);
|
||||
if (!apiOption.isPresent())
|
||||
continue;
|
||||
FloatingIPApi api = apiOption.get();
|
||||
|
@ -65,8 +65,8 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
|
|||
|
||||
@Test
|
||||
public void testAllocateAndDecreateFloatingIPs() throws Exception {
|
||||
for (String zoneId : api.getConfiguredZones()) {
|
||||
Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPExtensionForZone(zoneId);
|
||||
for (String regionId : api.getConfiguredRegions()) {
|
||||
Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPApi(regionId);
|
||||
if (!apiOption.isPresent())
|
||||
continue;
|
||||
FloatingIPApi api = apiOption.get();
|
||||
|
@ -96,13 +96,13 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
|
|||
|
||||
@Test
|
||||
public void testAddAndRemoveFloatingIp() throws Exception {
|
||||
for (String zoneId : api.getConfiguredZones()) {
|
||||
Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPExtensionForZone(zoneId);
|
||||
for (String regionId : api.getConfiguredRegions()) {
|
||||
Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPApi(regionId);
|
||||
if (!apiOption.isPresent())
|
||||
continue;
|
||||
FloatingIPApi api = apiOption.get();
|
||||
ServerApi serverApi = this.api.getServerApiForZone(zoneId);
|
||||
Server server = createServerInZone(zoneId);
|
||||
ServerApi serverApi = this.api.getServerApi(regionId);
|
||||
Server server = createServerInRegion(regionId);
|
||||
FloatingIP floatingIP = api.create();
|
||||
assertNotNull(floatingIP);
|
||||
try {
|
||||
|
|
|
@ -41,8 +41,8 @@ import com.google.common.collect.Iterables;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "HostAdministrationApiExpectTest")
|
||||
public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
||||
|
||||
|
||||
|
||||
|
||||
public void testList() {
|
||||
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/os-hosts");
|
||||
HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
|
@ -51,8 +51,8 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.addHeader("Accept", "application/json")
|
||||
.addHeader("X-Auth-Token", authToken)
|
||||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/hosts_list.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/hosts_list.json")).build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
|
||||
Host expected = Host.builder().name("ubuntu").service("compute").build();
|
||||
|
||||
Set<? extends Host> result = api.list().toSet();
|
||||
|
@ -71,7 +71,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.addHeader("Accept", "application/json")
|
||||
.addHeader("X-Auth-Token", authToken)
|
||||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host.json")).build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<HostResourceUsage> expected = ImmutableSet.of(
|
||||
HostResourceUsage.builder().memoryMb(16083).project("(total)").cpu(4).diskGb(181).host("ubuntu").build(),
|
||||
|
@ -82,7 +82,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
|
||||
assertEquals(api.listResourceUsage("xyz").toSet(), expected);
|
||||
}
|
||||
|
||||
|
||||
public void testEnableHost() {
|
||||
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/os-hosts/ubuntu");
|
||||
HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
|
@ -94,7 +94,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"enabled\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertTrue(api.enable("ubuntu"));
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.payload(payloadFromStringWithContentType("{\"status\":\"enable\"}", MediaType.APPLICATION_JSON))
|
||||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404)
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
api.enable("ubuntu");
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"disabled\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertFalse(api.enable("ubuntu"));
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"disabled\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertTrue(api.disable("ubuntu"));
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"maintenance_mode\":\"on_maintenance\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertTrue(api.startMaintenance("ubuntu"));
|
||||
}
|
||||
|
||||
|
@ -169,10 +169,10 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"maintenance_mode\":\"off_maintenance\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertTrue(api.stopMaintenance("ubuntu"));
|
||||
}
|
||||
|
||||
|
||||
public void testStartupHost() {
|
||||
HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
|
@ -182,7 +182,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.addHeader("X-Auth-Token", authToken).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"startup\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertTrue(api.startup("ubuntu"));
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/os-hosts/ubuntu/startup")
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("X-Auth-Token", authToken).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(404).build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertTrue(api.startup("ubuntu"));
|
||||
}
|
||||
|
||||
|
@ -207,10 +207,10 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.addHeader("X-Auth-Token", authToken).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"shutdown\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertFalse(api.startup("ubuntu"));
|
||||
}
|
||||
|
||||
|
||||
public void testShutdownHost() {
|
||||
HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
|
@ -220,10 +220,10 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.addHeader("X-Auth-Token", authToken).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"shutdown\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertTrue(api.shutdown("ubuntu"));
|
||||
}
|
||||
|
||||
|
||||
public void testRebootHost() {
|
||||
HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
|
@ -233,7 +233,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.addHeader("X-Auth-Token", authToken).build(),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"reboot\"}", MediaType.APPLICATION_JSON))
|
||||
.build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.build()).getHostAdministrationApi("az-1.region-a.geo-1").get();
|
||||
assertTrue(api.reboot("ubuntu"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest {
|
|||
super.setup();
|
||||
|
||||
if (identity.endsWith(":admin")) {
|
||||
String zone = Iterables.getLast(api.getConfiguredZones(), "nova");
|
||||
optApi = api.getHostAdministrationExtensionForZone(zone);
|
||||
String region = Iterables.getLast(api.getConfiguredRegions(), "nova");
|
||||
optApi = api.getHostAdministrationApi(region);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_list.json")).build())
|
||||
.getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
HostAggregate result = Iterables.getOnlyElement(api.list());
|
||||
assertEquals(result, exampleHostAggregate());
|
||||
|
@ -60,7 +60,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_with_host_details.json")).build())
|
||||
.getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.get("1"), exampleHostAggregateWithHost());
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(404).build()).getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertNull(api.get("1"));
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.payload(payloadFromStringWithContentType("{\"aggregate\":{\"name\":\"ubuntu1\",\"availability_zone\":\"nova\"}}", MediaType.APPLICATION_JSON))
|
||||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build())
|
||||
.getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
.getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.createInAvailabilityZone("ubuntu1", "nova"), exampleHostAggregate());
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).build()).getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.delete("1"));
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(404).build()).getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(api.delete("1"));
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"aggregate\":{\"name\":\"newaggregatename\"}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.updateName("1", "newaggregatename"), exampleHostAggregate());
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"aggregate\":{\"availability_zone\":\"zone1\"}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.updateAvailabilityZone("1", "zone1"), exampleHostAggregate());
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"add_host\":{\"host\":\"ubuntu\"}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.addHost("1", "ubuntu"), exampleHostAggregate());
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"remove_host\":{\"host\":\"ubuntu\"}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.removeHost("1", "ubuntu"), exampleHostAggregate());
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"set_metadata\":{\"metadata\":{\"mykey\":\"some value or other\"}}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.setMetadata("1", ImmutableMap.of("mykey", "some value or other")), exampleHostAggregate());
|
||||
}
|
||||
|
|
|
@ -49,9 +49,9 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest {
|
|||
@Override
|
||||
public void setup() {
|
||||
super.setup();
|
||||
String zone = Iterables.getLast(api.getConfiguredZones(), "nova");
|
||||
apiOption = api.getHostAggregateExtensionForZone(zone);
|
||||
hostAdminOption = api.getHostAdministrationExtensionForZone(zone);
|
||||
String region = Iterables.getLast(api.getConfiguredRegions(), "nova");
|
||||
apiOption = api.getHostAggregateApi(region);
|
||||
hostAdminOption = api.getHostAdministrationApi(region);
|
||||
}
|
||||
|
||||
@AfterClass(groups = { "integration", "live" })
|
||||
|
@ -99,7 +99,7 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest {
|
|||
)) {
|
||||
// Apply changes
|
||||
HostAggregate details = api.setMetadata(testAggregate.getId(), theMetaData);
|
||||
|
||||
|
||||
// bug in openstack - metadata values are never removed, so we just checking what we've set
|
||||
for (Map.Entry<String, String> entry : theMetaData.entrySet()) {
|
||||
assertEquals(details.getMetadata().get(entry.getKey()), entry.getValue());
|
||||
|
|
|
@ -50,10 +50,10 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
|
||||
|
||||
assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
assertEquals(apiWhenServersExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
|
||||
|
||||
// NOTE this required a change to the KeyPair domain object toString method
|
||||
assertEquals(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().list().toString(),
|
||||
assertEquals(apiWhenServersExist.getKeyPairApi("az-1.region-a.geo-1").get().list().toString(),
|
||||
new ParseKeyPairListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
|
||||
|
||||
assertTrue(apiWhenNoServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().list().isEmpty());
|
||||
assertTrue(apiWhenNoServersExist.getKeyPairApi("az-1.region-a.geo-1").get().list().isEmpty());
|
||||
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, create, createResponse);
|
||||
|
||||
assertEquals(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().create("testkeypair")
|
||||
assertEquals(apiWhenServersExist.getKeyPairApi("az-1.region-a.geo-1").get().create("testkeypair")
|
||||
.toString(), new ParseKeyPairTest().expected().toString());
|
||||
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest {
|
|||
|
||||
assertEquals(
|
||||
apiWhenServersExist
|
||||
.getKeyPairExtensionForZone("az-1.region-a.geo-1")
|
||||
.getKeyPairApi("az-1.region-a.geo-1")
|
||||
.get()
|
||||
.createWithPublicKey(
|
||||
"testkeypair",
|
||||
|
@ -136,7 +136,7 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, delete, deleteResponse);
|
||||
|
||||
assertTrue(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().delete("testkeypair"));
|
||||
assertTrue(apiWhenServersExist.getKeyPairApi("az-1.region-a.geo-1").get().delete("testkeypair"));
|
||||
}
|
||||
|
||||
public void testGetKeyPairWhenResponseIs2xx() throws Exception {
|
||||
|
@ -153,7 +153,7 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenKeyPairExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse);
|
||||
|
||||
assertEquals(apiWhenKeyPairExists.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().get("testkeypair"),
|
||||
assertEquals(apiWhenKeyPairExists.getKeyPairApi("az-1.region-a.geo-1").get().get("testkeypair"),
|
||||
new ParseKeyPairTest().expected());
|
||||
}
|
||||
|
||||
|
@ -170,6 +170,6 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest {
|
|||
NovaApi apiWhenNoKeyPairExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse);
|
||||
|
||||
assertNull(apiWhenNoKeyPairExists.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().get("testkeypair"));
|
||||
assertNull(apiWhenNoKeyPairExists.getKeyPairApi("az-1.region-a.geo-1").get().get("testkeypair"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,16 +35,16 @@ public class KeyPairApiLiveTest extends BaseNovaApiLiveTest {
|
|||
final String PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCrrBREFxz3002l1HuXz0+UOdJQ/mOYD5DiJwwB/TOybwIKQJPOxJWA9gBoo4k9dthTKBTaEYbzrll7iZcp59E80S6mNiAr3mUgi+x5Y8uyXeJ2Ws+h6peVyFVUu9epkwpcTd1GVfdcVWsTajwDz9+lxCDhl0RZKDFoT0scTxbj/w== nova@nv-aw2az2-api0002";
|
||||
|
||||
public void testListKeyPairs() throws Exception {
|
||||
for (String zoneId : api.getConfiguredZones()) {
|
||||
KeyPairApi keyPairApi = api.getKeyPairExtensionForZone(zoneId).get();
|
||||
for (String regionId : api.getConfiguredRegions()) {
|
||||
KeyPairApi keyPairApi = api.getKeyPairApi(regionId).get();
|
||||
FluentIterable<? extends KeyPair> keyPairsList = keyPairApi.list();
|
||||
assertNotNull(keyPairsList);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateAndGetAndDeleteKeyPair() throws Exception {
|
||||
for (String zoneId : api.getConfiguredZones()) {
|
||||
KeyPairApi keyPairApi = api.getKeyPairExtensionForZone(zoneId).get();
|
||||
for (String regionId : api.getConfiguredRegions()) {
|
||||
KeyPairApi keyPairApi = api.getKeyPairApi(regionId).get();
|
||||
KeyPair createdKeyPair = null;
|
||||
try {
|
||||
createdKeyPair = keyPairApi.create(KEYPAIR_NAME);
|
||||
|
@ -63,8 +63,8 @@ public class KeyPairApiLiveTest extends BaseNovaApiLiveTest {
|
|||
}
|
||||
|
||||
public void testCreateAndDeleteKeyPairWithPublicKey() throws Exception {
|
||||
for (String zoneId : api.getConfiguredZones()) {
|
||||
KeyPairApi keyPairApi = api.getKeyPairExtensionForZone(zoneId).get();
|
||||
for (String regionId : api.getConfiguredRegions()) {
|
||||
KeyPairApi keyPairApi = api.getKeyPairApi(regionId).get();
|
||||
KeyPair createdKeyPair = null;
|
||||
try {
|
||||
createdKeyPair = keyPairApi.createWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY);
|
||||
|
|
|
@ -42,7 +42,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest {
|
|||
QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()).getQuotaApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.getByTenant("demo"), getTestQuotas());
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest {
|
|||
QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(404).build()).getQuotaApi("az-1.region-a.geo-1").get();
|
||||
assertNull(api.getByTenant("demo"));
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest {
|
|||
QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()).getQuotaApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertEquals(api.getDefaultsForTenant("demo"), getTestQuotas());
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest {
|
|||
QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(404).build()).getQuotaApi("az-1.region-a.geo-1").get();
|
||||
assertNull(api.getDefaultsForTenant("demo"));
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.addHeader("Accept", "application/json")
|
||||
.payload(payloadFromResourceWithContentType("/quotas.json", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(200).build()).getQuotaApi("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(api.updateQuotaOfTenant(getTestQuotas(), "demo"));
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest {
|
|||
.addHeader("Accept", "application/json")
|
||||
.payload(payloadFromResourceWithContentType("/quotas.json", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
|
||||
HttpResponse.builder().statusCode(404).build()).getQuotaApi("az-1.region-a.geo-1").get();
|
||||
|
||||
api.updateQuotaOfTenant(getTestQuotas(), "demo");
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ public class QuotaApiLiveTest extends BaseNovaApiLiveTest {
|
|||
public void setup() {
|
||||
super.setup();
|
||||
tenant = identity.split(":")[0];
|
||||
String zone = Iterables.getLast(api.getConfiguredZones(), "nova");
|
||||
apiOption = api.getQuotaExtensionForZone(zone);
|
||||
String region = Iterables.getLast(api.getConfiguredRegions(), "nova");
|
||||
apiOption = api.getQuotaApi(region);
|
||||
}
|
||||
|
||||
public void testGetQuotasForCurrentTenant() {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue