Updated Branches: refs/heads/master 725b7c5c2 -> 1c9d1676c
JCLOUDS-348 list quotas for cinder + expected and live tests Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/1c9d1676 Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/1c9d1676 Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/1c9d1676 Branch: refs/heads/master Commit: 1c9d1676cd7cc1ad3fe8b37b7f1ebf63d4efd81e Parents: 725b7c5 Author: istolber <[email protected]> Authored: Wed Oct 16 07:14:40 2013 +0200 Committer: Everett Toews <[email protected]> Committed: Mon Oct 21 09:12:53 2013 -0500 ---------------------------------------------------------------------- .../jclouds/openstack/cinder/v1/CinderApi.java | 12 +- .../openstack/cinder/v1/domain/VolumeQuota.java | 167 +++++++++++++++++++ .../openstack/cinder/v1/features/QuotaApi.java | 55 ++++++ .../cinder/v1/features/QuotasApiExpectTest.java | 55 ++++++ .../cinder/v1/features/QuotasApiLiveTest.java | 58 +++++++ .../src/test/resources/quotas.json | 6 + 6 files changed, 351 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1c9d1676/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/CinderApi.java ---------------------------------------------------------------------- diff --git a/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/CinderApi.java b/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/CinderApi.java index 3de7f27..8cfb40b 100644 --- a/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/CinderApi.java +++ b/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/CinderApi.java @@ -21,6 +21,7 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.Zone; import org.jclouds.location.functions.ZoneToEndpoint; +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; @@ -32,8 +33,7 @@ import com.google.inject.Provides; /** * Provides synchronous access to Cinder. - * - * @see CinderAsyncApi + * * @see <a href="http://api.openstack.org/">API Doc</a> * @author Everett Toews */ @@ -72,4 +72,12 @@ public interface CinderApi extends Closeable { @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); + } http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1c9d1676/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/domain/VolumeQuota.java ---------------------------------------------------------------------- diff --git a/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/domain/VolumeQuota.java b/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/domain/VolumeQuota.java new file mode 100644 index 0000000..31436b3 --- /dev/null +++ b/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/domain/VolumeQuota.java @@ -0,0 +1,167 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.cinder.v1.domain; + +import com.google.common.base.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Inbar Stolberg + */ +public class VolumeQuota { + + private final String id; + private final int volumes; + private final int gigabytes; + private final int snapshots; + + protected VolumeQuota(String id, int volumes, int gigabytes, int snapshots) { + this.id = checkNotNull(id, "id"); + this.volumes = volumes; + this.gigabytes = gigabytes; + this.snapshots = snapshots; + } + + /** + * The id of the tenant this set of limits applies to + */ + public String getId() { + return this.id; + } + + /** + * The limit of the number of volumes that can be created for the tenant + */ + public int getVolumes() { + return this.volumes; + } + + /** + * The limit of the total size of all volumes for the tenant + */ + public int getGigabytes() { + return this.gigabytes; + } + + /** + * The limit of the number of snapshots that can be used by the tenant + */ + public int getSnapshots() { + return this.snapshots; + } + + + @Override + public int hashCode() { + return Objects.hashCode(id, volumes, gigabytes, snapshots); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + VolumeQuota that = VolumeQuota.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.volumes, that.volumes) + && Objects.equal(this.gigabytes, that.gigabytes) + && Objects.equal(this.snapshots, that.snapshots); + } + + protected Objects.ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("volumes", volumes).add("gigabytes", gigabytes).add("snapshots", snapshots); + } + + @Override + public String toString() { + return string().toString(); + } + + public static Builder<?> builder() { + return new ConcreteBuilder(); + } + + public Builder<?> toBuilder() { + return new ConcreteBuilder().fromVolumeQuota(this); + } + + public static abstract class Builder<T extends Builder<T>> { + protected abstract T self(); + + protected String id; + protected int volumes; + protected int gigabytes; + protected int snapshots; + + + /** + * @see VolumeQuota#getId() + */ + public T id(String id) { + this.id = id; + return self(); + } + + /** + * @see VolumeQuota#getVolumes() + */ + public T volumes(int volumes) { + this.volumes = volumes; + return self(); + } + + /** + * @see VolumeQuota#getGigabytes() + */ + public T gigabytes(int gigabytes) { + this.gigabytes = gigabytes; + return self(); + } + + /** + * @see VolumeQuota#getSnapshots() + */ + public T snapshots(int snapshots) { + this.snapshots = snapshots; + return self(); + } + + + public VolumeQuota build() { + return new VolumeQuota(id, volumes, gigabytes, snapshots); + } + + public T fromVolumeQuota(VolumeQuota in) { + return this + .id(in.getId()) + .volumes(in.getVolumes()) + .gigabytes(in.getGigabytes()) + .snapshots(in.getSnapshots()); + + } + } + + private static class ConcreteBuilder extends Builder<ConcreteBuilder> { + @Override + protected ConcreteBuilder self() { + return this; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1c9d1676/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/features/QuotaApi.java ---------------------------------------------------------------------- diff --git a/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/features/QuotaApi.java b/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/features/QuotaApi.java new file mode 100644 index 0000000..476d1f1 --- /dev/null +++ b/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/features/QuotaApi.java @@ -0,0 +1,55 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.cinder.v1.features; + +import org.jclouds.Fallbacks; +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. + * + * @author Inbar Stolberg + * @see QuotaApi + * @see <a href="http://api.openstack.org/">API Doc</a> + */ +@SkipEncoding({'/', '='}) +@RequestFilters(AuthenticateRequest.class) +@Path("/os-quota-sets") +public interface QuotaApi { + + + @GET + @SelectJson("quota_set") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/{tenant_id}") + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + VolumeQuota getByTenant(@PathParam("tenant_id") String tenantId); + +} http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1c9d1676/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/QuotasApiExpectTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/QuotasApiExpectTest.java b/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/QuotasApiExpectTest.java new file mode 100644 index 0000000..dd7d435 --- /dev/null +++ b/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/QuotasApiExpectTest.java @@ -0,0 +1,55 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.cinder.v1.features; + +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; + +/** + * @author inbar stolberg + */ +@Test(groups = "unit", testName = "QuotaApiExpectTest") +public class QuotasApiExpectTest extends BaseCinderApiExpectTest { + + public void testGetQuotas() throws Exception { + URI endpoint = URI.create("http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/os-quota-sets/demo"); + QuotaApi api = requestsSendResponses( + keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build() + ).getQuotaApi("RegionOne"); + + assertEquals(api.getByTenant("demo"), getTestQuotas()); + } + + public static VolumeQuota getTestQuotas() { + return VolumeQuota.builder() + .gigabytes(1000) + .volumes(10) + .snapshots(20) + .id("demo").build(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1c9d1676/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/QuotasApiLiveTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/QuotasApiLiveTest.java b/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/QuotasApiLiveTest.java new file mode 100644 index 0000000..c316a5d --- /dev/null +++ b/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/QuotasApiLiveTest.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.cinder.v1.features; + +import com.google.common.collect.Iterables; +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; + +/** + * @author inbar stolberg + */ +@Test(groups = "live", testName = "QuotasApiLiveTest", singleThreaded = true) +public class QuotasApiLiveTest extends BaseCinderApiLiveTest { + + private QuotaApi quotaApi; + + public QuotasApiLiveTest() { + super(); + provider = "openstack-cinder"; + } + + @BeforeClass(groups = {"integration", "live"}) + public void setupContext() { + super.setup(); + String zone = Iterables.getFirst(api.getConfiguredZones(), "nova"); + quotaApi = api.getQuotaApi(zone); + } + + public void testGetStorageQuotas() throws ExecutionException, InterruptedException { + VolumeQuota volumeQuota = quotaApi.getByTenant("demo"); + + assertTrue(volumeQuota.getGigabytes() >= 0); + assertTrue(volumeQuota.getVolumes() >= 0); + assertTrue(volumeQuota.getSnapshots() >= 0); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1c9d1676/apis/openstack-cinder/src/test/resources/quotas.json ---------------------------------------------------------------------- diff --git a/apis/openstack-cinder/src/test/resources/quotas.json b/apis/openstack-cinder/src/test/resources/quotas.json new file mode 100644 index 0000000..a50b8b5 --- /dev/null +++ b/apis/openstack-cinder/src/test/resources/quotas.json @@ -0,0 +1,6 @@ +{"quota_set": { + "gigabytes": 1000, + "volumes": 10, + "snapshots": 20, + "id": "demo" +}}
