Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Commit

Permalink
Prefer Regions to Zones in OpenStack APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Daggett authored and jdaggett committed Aug 13, 2014
1 parent 9009bb5 commit 744cd5d
Show file tree
Hide file tree
Showing 206 changed files with 2,873 additions and 2,391 deletions.
Expand Up @@ -18,65 +18,113 @@

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 Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();

/**
* 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
@Zone
@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);

}
Expand Up @@ -27,18 +27,18 @@
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;

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);
Expand Down Expand Up @@ -74,12 +74,12 @@ protected Builder() {
.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);
Expand Down
Expand Up @@ -16,37 +16,38 @@
*/
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;
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);

}
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -42,12 +43,13 @@
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.
Expand All @@ -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();

/**
Expand All @@ -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();

/**
Expand All @@ -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);

/**
Expand All @@ -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);
}

0 comments on commit 744cd5d

Please sign in to comment.