mirror of https://github.com/apache/jclouds.git
metadata for nova
This commit is contained in:
parent
c078cb2170
commit
605d6580de
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* 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.nova.v2_0.binders;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.json.Json;
|
||||||
|
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class BindMetadataToJsonPayload extends BindToJsonPayload {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public BindMetadataToJsonPayload(Json jsonBinder) {
|
||||||
|
super(jsonBinder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||||
|
return bindToRequest(request,
|
||||||
|
(Object) ImmutableMap.of("metadata", ImmutableMap.of(postParams.get("key"), postParams.get("value"))));
|
||||||
|
}
|
||||||
|
}
|
|
@ -68,7 +68,7 @@ public class Quota {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Quota#getMetadataItems()
|
* @see Quota#getMetadatas()
|
||||||
*/
|
*/
|
||||||
public T metadataItems(int metadataItems) {
|
public T metadataItems(int metadataItems) {
|
||||||
this.metadataItems = metadataItems;
|
this.metadataItems = metadataItems;
|
||||||
|
@ -170,7 +170,7 @@ public class Quota {
|
||||||
public T fromQuotas(Quota in) {
|
public T fromQuotas(Quota in) {
|
||||||
return this
|
return this
|
||||||
.id(in.getId())
|
.id(in.getId())
|
||||||
.metadataItems(in.getMetadataItems())
|
.metadataItems(in.getMetadatas())
|
||||||
.injectedFileContentBytes(in.getInjectedFileContentBytes())
|
.injectedFileContentBytes(in.getInjectedFileContentBytes())
|
||||||
.volumes(in.getVolumes())
|
.volumes(in.getVolumes())
|
||||||
.gigabytes(in.getGigabytes())
|
.gigabytes(in.getGigabytes())
|
||||||
|
@ -242,7 +242,7 @@ public class Quota {
|
||||||
/**
|
/**
|
||||||
* The limit of the number of metadata items for the tenant
|
* The limit of the number of metadata items for the tenant
|
||||||
*/
|
*/
|
||||||
public int getMetadataItems() {
|
public int getMetadatas() {
|
||||||
return this.metadataItems;
|
return this.metadataItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.collect.PagedIterable;
|
import org.jclouds.collect.PagedIterable;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
|
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
|
||||||
import org.jclouds.openstack.nova.v2_0.domain.Image;
|
import org.jclouds.openstack.nova.v2_0.domain.Image;
|
||||||
import org.jclouds.openstack.v2_0.domain.Resource;
|
import org.jclouds.openstack.v2_0.domain.Resource;
|
||||||
|
@ -84,7 +85,7 @@ public interface ImageApi {
|
||||||
* id of the image
|
* id of the image
|
||||||
* @return the metadata as a Map<String, String>
|
* @return the metadata as a Map<String, String>
|
||||||
*/
|
*/
|
||||||
Map<String, String> listMetadata(String id);
|
Map<String, String> getMetadata(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the metadata for an image.
|
* Sets the metadata for an image.
|
||||||
|
@ -115,9 +116,10 @@ public interface ImageApi {
|
||||||
* id of the image
|
* id of the image
|
||||||
* @param metadata
|
* @param metadata
|
||||||
* a Map containing the metadata
|
* a Map containing the metadata
|
||||||
* @return the metadata as a Map<String, String>
|
* @return the value or null if not present
|
||||||
*/
|
*/
|
||||||
Map<String, String> getMetadataItem(String id, String key);
|
@Nullable
|
||||||
|
String getMetadata(String id, String key);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,9 +131,9 @@ public interface ImageApi {
|
||||||
* the name of the metadata item
|
* the name of the metadata item
|
||||||
* @param value
|
* @param value
|
||||||
* the value of the metadata item
|
* the value of the metadata item
|
||||||
* @return the metadata as a Map<String, String>
|
* @return the value you updated
|
||||||
*/
|
*/
|
||||||
Map<String, String> setMetadataItem(String id, String key, String value);
|
String updateMetadata(String id, String key, String value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a metadata item from an image.
|
* Delete a metadata item from an image.
|
||||||
|
@ -141,6 +143,6 @@ public interface ImageApi {
|
||||||
* @param key
|
* @param key
|
||||||
* the name of the metadata item
|
* the name of the metadata item
|
||||||
*/
|
*/
|
||||||
void deleteMetadataItem(String id, String key);
|
void deleteMetadata(String id, String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,14 +34,15 @@ import org.jclouds.collect.PagedIterable;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
|
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
|
||||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||||
import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404;
|
import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404;
|
||||||
|
import org.jclouds.openstack.nova.v2_0.binders.BindMetadataToJsonPayload;
|
||||||
import org.jclouds.openstack.nova.v2_0.domain.Image;
|
import org.jclouds.openstack.nova.v2_0.domain.Image;
|
||||||
|
import org.jclouds.openstack.nova.v2_0.functions.internal.OnlyMetadataValueOrNull;
|
||||||
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImageDetails;
|
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImageDetails;
|
||||||
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImages;
|
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImages;
|
||||||
import org.jclouds.openstack.v2_0.domain.Resource;
|
import org.jclouds.openstack.v2_0.domain.Resource;
|
||||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||||
import org.jclouds.rest.annotations.ExceptionParser;
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
import org.jclouds.rest.annotations.MapBinder;
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
import org.jclouds.rest.annotations.Payload;
|
|
||||||
import org.jclouds.rest.annotations.PayloadParam;
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.ResponseParser;
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
|
@ -129,14 +130,14 @@ public interface ImageAsyncApi {
|
||||||
ListenableFuture<Void> delete(@PathParam("id") String id);
|
ListenableFuture<Void> delete(@PathParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ImageApi#listMetadata
|
* @see ImageApi#getMetadata
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@SelectJson("metadata")
|
@SelectJson("metadata")
|
||||||
@Path("/images/{id}/metadata")
|
@Path("/images/{id}/metadata")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
||||||
ListenableFuture<Map<String, String>> listMetadata(@PathParam("id") String id);
|
ListenableFuture<Map<String, String>> getMetadata(@PathParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ImageApi#setMetadata
|
* @see ImageApi#setMetadata
|
||||||
|
@ -163,34 +164,34 @@ public interface ImageAsyncApi {
|
||||||
ListenableFuture<? extends Map<String, String>> updateMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map<String, String> metadata);
|
ListenableFuture<? extends Map<String, String>> updateMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map<String, String> metadata);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ImageApi#getMetadataItem
|
* @see ImageApi#getMetadata
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@SelectJson("metadata")
|
|
||||||
@Path("/images/{id}/metadata/{key}")
|
@Path("/images/{id}/metadata/{key}")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ResponseParser(OnlyMetadataValueOrNull.class)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<? extends Map<String, String>> getMetadataItem(@PathParam("id") String id, @PathParam("key") String key);
|
ListenableFuture<String> getMetadata(@PathParam("id") String id, @PathParam("key") String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ImageApi#setMetadataItem
|
* @see ImageApi#updateMetadata
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@SelectJson("metadata")
|
|
||||||
@Path("/images/{id}/metadata/{key}")
|
@Path("/images/{id}/metadata/{key}")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
@ResponseParser(OnlyMetadataValueOrNull.class)
|
||||||
@Payload("%7B\"metadata\":%7B\"{key}\":\"{value}\"%7D%7D")
|
@MapBinder(BindMetadataToJsonPayload.class)
|
||||||
ListenableFuture<? extends Map<String, String>> setMetadataItem(@PathParam("id") String id, @PathParam("key") String key, @PathParam("value") String value);
|
ListenableFuture<String> updateMetadata(@PathParam("id") String id,
|
||||||
|
@PathParam("key") @PayloadParam("key") String key, @PathParam("value") @PayloadParam("value") String value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ImageApi#deleteMetadataItem
|
* @see ImageApi#deleteMetadata
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Consumes
|
@Consumes
|
||||||
@Path("/images/{id}/metadata/{key}")
|
@Path("/images/{id}/metadata/{key}")
|
||||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||||
ListenableFuture<Void> deleteMetadataItem(@PathParam("id") String id, @PathParam("key") String key);
|
ListenableFuture<Void> deleteMetadata(@PathParam("id") String id, @PathParam("key") String key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.collect.PagedIterable;
|
import org.jclouds.collect.PagedIterable;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
|
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
|
||||||
import org.jclouds.openstack.nova.v2_0.domain.RebootType;
|
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.Server;
|
||||||
|
@ -201,7 +202,7 @@ public interface ServerApi {
|
||||||
*
|
*
|
||||||
* @return the metadata as a Map<String, String>
|
* @return the metadata as a Map<String, String>
|
||||||
*/
|
*/
|
||||||
Map<String, String> listMetadata(String id);
|
Map<String, String> getMetadata(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the metadata for a server.
|
* Set the metadata for a server.
|
||||||
|
@ -232,9 +233,10 @@ public interface ServerApi {
|
||||||
* id of the image
|
* id of the image
|
||||||
* @param metadata
|
* @param metadata
|
||||||
* a Map containing the metadata
|
* a Map containing the metadata
|
||||||
* @return the metadata as a Map<String, String>
|
* @return the value or null if not present
|
||||||
*/
|
*/
|
||||||
Map<String, String> getMetadataItem(String id, String key);
|
@Nullable
|
||||||
|
String getMetadata(String id, String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a metadata item for a server.
|
* Set a metadata item for a server.
|
||||||
|
@ -245,9 +247,9 @@ public interface ServerApi {
|
||||||
* the name of the metadata item
|
* the name of the metadata item
|
||||||
* @param value
|
* @param value
|
||||||
* the value of the metadata item
|
* the value of the metadata item
|
||||||
* @return the metadata as a Map<String, String>
|
* @return the value you updated
|
||||||
*/
|
*/
|
||||||
Map<String, String> setMetadataItem(String id, String key, String value);
|
String updateMetadata(String id, String key, String value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a metadata item from a server.
|
* Delete a metadata item from a server.
|
||||||
|
@ -257,6 +259,6 @@ public interface ServerApi {
|
||||||
* @param key
|
* @param key
|
||||||
* the name of the metadata item
|
* the name of the metadata item
|
||||||
*/
|
*/
|
||||||
void deleteMetadataItem(String id, String key);
|
void deleteMetadata(String id, String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,12 @@ import org.jclouds.collect.PagedIterable;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
|
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
|
||||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||||
import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404;
|
import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404;
|
||||||
|
import org.jclouds.openstack.nova.v2_0.binders.BindMetadataToJsonPayload;
|
||||||
import org.jclouds.openstack.nova.v2_0.domain.RebootType;
|
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.Server;
|
||||||
import org.jclouds.openstack.nova.v2_0.domain.ServerCreated;
|
import org.jclouds.openstack.nova.v2_0.domain.ServerCreated;
|
||||||
import org.jclouds.openstack.nova.v2_0.functions.ParseImageIdFromLocationHeader;
|
import org.jclouds.openstack.nova.v2_0.functions.ParseImageIdFromLocationHeader;
|
||||||
|
import org.jclouds.openstack.nova.v2_0.functions.internal.OnlyMetadataValueOrNull;
|
||||||
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServerDetails;
|
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServerDetails;
|
||||||
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServers;
|
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServers;
|
||||||
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
||||||
|
@ -69,8 +71,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
* <p/>
|
* <p/>
|
||||||
*
|
*
|
||||||
* @see ServerApi
|
* @see ServerApi
|
||||||
* @see <a href=
|
* @see <a href= "http://docs.openstack.org/api/openstack-compute/1.1/content/Servers-d1e2073.html"
|
||||||
* "http://docs.openstack.org/api/openstack-compute/1.1/content/Servers-d1e2073.html"
|
|
||||||
* />
|
* />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -120,7 +121,6 @@ public interface ServerAsyncApi {
|
||||||
@ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||||
ListenableFuture<? extends PaginatedCollection<? extends Server>> listInDetail(PaginationOptions options);
|
ListenableFuture<? extends PaginatedCollection<? extends Server>> listInDetail(PaginationOptions options);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerApi#get
|
* @see ServerApi#get
|
||||||
*/
|
*/
|
||||||
|
@ -159,7 +159,7 @@ public interface ServerAsyncApi {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Payload("{\"os-stop\":null}")
|
@Payload("{\"os-stop\":null}")
|
||||||
ListenableFuture<Void> stop(@PathParam("id") String id);
|
ListenableFuture<Void> stop(@PathParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerApi#reboot
|
* @see ServerApi#reboot
|
||||||
*/
|
*/
|
||||||
|
@ -209,7 +209,7 @@ public interface ServerAsyncApi {
|
||||||
@Path("/servers")
|
@Path("/servers")
|
||||||
@MapBinder(CreateServerOptions.class)
|
@MapBinder(CreateServerOptions.class)
|
||||||
ListenableFuture<ServerCreated> create(@PayloadParam("name") String name, @PayloadParam("imageRef") String imageRef,
|
ListenableFuture<ServerCreated> create(@PayloadParam("name") String name, @PayloadParam("imageRef") String imageRef,
|
||||||
@PayloadParam("flavorRef") String flavorRef, CreateServerOptions... options);
|
@PayloadParam("flavorRef") String flavorRef, CreateServerOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerApi#rebuild
|
* @see ServerApi#rebuild
|
||||||
|
@ -253,15 +253,15 @@ public interface ServerAsyncApi {
|
||||||
ListenableFuture<String> createImageFromServer(@PayloadParam("name") String name, @PathParam("id") String id);
|
ListenableFuture<String> createImageFromServer(@PayloadParam("name") String name, @PathParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerApi#listMetadata
|
* @see ServerApi#getMetadata
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@SelectJson("metadata")
|
@SelectJson("metadata")
|
||||||
@Path("/servers/{id}/metadata")
|
@Path("/servers/{id}/metadata")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
||||||
ListenableFuture<? extends Map<String, String>> listMetadata(@PathParam("id") String id);
|
ListenableFuture<? extends Map<String, String>> getMetadata(@PathParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerApi#setMetadata
|
* @see ServerApi#setMetadata
|
||||||
*/
|
*/
|
||||||
|
@ -272,7 +272,8 @@ public interface ServerAsyncApi {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
||||||
@MapBinder(BindToJsonPayload.class)
|
@MapBinder(BindToJsonPayload.class)
|
||||||
ListenableFuture<? extends Map<String, String>> setMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map<String, String> metadata);
|
ListenableFuture<? extends Map<String, String>> setMetadata(@PathParam("id") String id,
|
||||||
|
@PayloadParam("metadata") Map<String, String> metadata);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerApi#updateMetadata
|
* @see ServerApi#updateMetadata
|
||||||
|
@ -284,37 +285,38 @@ public interface ServerAsyncApi {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
||||||
@MapBinder(BindToJsonPayload.class)
|
@MapBinder(BindToJsonPayload.class)
|
||||||
ListenableFuture<? extends Map<String, String>> updateMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map<String, String> metadata);
|
ListenableFuture<? extends Map<String, String>> updateMetadata(@PathParam("id") String id,
|
||||||
|
@PayloadParam("metadata") Map<String, String> metadata);
|
||||||
/**
|
|
||||||
* @see ServerApi#getMetadataItem
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@SelectJson("metadata")
|
|
||||||
@Path("/servers/{id}/metadata/{key}")
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
|
||||||
ListenableFuture<? extends Map<String, String>> getMetadataItem(@PathParam("id") String id, @PathParam("key") String key);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerApi#setMetadataItem
|
* @see ServerApi#getMetadata
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("/servers/{id}/metadata/{key}")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ResponseParser(OnlyMetadataValueOrNull.class)
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<String> getMetadata(@PathParam("id") String id, @PathParam("key") String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ServerApi#updateMetadata
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@SelectJson("metadata")
|
|
||||||
@Path("/servers/{id}/metadata/{key}")
|
@Path("/servers/{id}/metadata/{key}")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
@ResponseParser(OnlyMetadataValueOrNull.class)
|
||||||
@Payload("%7B\"metadata\":%7B\"{key}\":\"{value}\"%7D%7D")
|
@MapBinder(BindMetadataToJsonPayload.class)
|
||||||
ListenableFuture<? extends Map<String, String>> setMetadataItem(@PathParam("id") String id, @PathParam("key") String key, @PathParam("value") String value);
|
ListenableFuture<String> updateMetadata(@PathParam("id") String id,
|
||||||
|
@PathParam("key") @PayloadParam("key") String key, @PathParam("value") @PayloadParam("value") String value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerApi#deleteMetadataItem
|
* @see ServerApi#deleteMetadata
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Consumes
|
@Consumes
|
||||||
@Path("/servers/{id}/metadata/{key}")
|
@Path("/servers/{id}/metadata/{key}")
|
||||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||||
ListenableFuture<Void> deleteMetadataItem(@PathParam("id") String id, @PathParam("key") String key);
|
ListenableFuture<Void> deleteMetadata(@PathParam("id") String id, @PathParam("key") String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.openstack.nova.v2_0.functions.internal;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
import org.jclouds.json.internal.GsonWrapper;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class OnlyMetadataValueOrNull implements Function<HttpResponse, String> {
|
||||||
|
private final ParseJson<Wrapper> parser;
|
||||||
|
|
||||||
|
private static class Wrapper implements Supplier<String> {
|
||||||
|
private Map<String, String> metadata;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get() {
|
||||||
|
return metadata == null ? null : Iterables.get(metadata.values(), 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public OnlyMetadataValueOrNull(GsonWrapper gsonView) {
|
||||||
|
this.parser = new ParseJson<Wrapper>(checkNotNull(gsonView, "gsonView"), new TypeLiteral<Wrapper>() {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apply(HttpResponse response) {
|
||||||
|
checkNotNull(response, "response");
|
||||||
|
return parser.apply(response).get();
|
||||||
|
}
|
||||||
|
}
|
|
@ -71,7 +71,7 @@ public class QuotaApiLiveTest extends BaseNovaApiLiveTest {
|
||||||
Quota modified = before.toBuilder()
|
Quota modified = before.toBuilder()
|
||||||
.cores(before.getCores() - 1)
|
.cores(before.getCores() - 1)
|
||||||
.instances(before.getInstances() - 1)
|
.instances(before.getInstances() - 1)
|
||||||
.metadataItems(before.getMetadataItems() - 1)
|
.metadataItems(before.getMetadatas() - 1)
|
||||||
.ram(before.getRam() - 1)
|
.ram(before.getRam() - 1)
|
||||||
.volumes(before.getVolumes() - 1)
|
.volumes(before.getVolumes() - 1)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -119,26 +119,26 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
|
|
||||||
public void testListMetadataWhenResponseIs2xx() throws Exception {
|
public void testListMetadataWhenResponseIs2xx() throws Exception {
|
||||||
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
||||||
HttpRequest listMetadata = HttpRequest
|
HttpRequest getMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata")
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata")
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json")
|
||||||
.addHeader("X-Auth-Token", authToken).build();
|
.addHeader("X-Auth-Token", authToken).build();
|
||||||
|
|
||||||
HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(200)
|
HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(200)
|
||||||
.payload(payloadFromResource("/metadata_list.json")).build();
|
.payload(payloadFromResource("/metadata_list.json")).build();
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, listMetadata, listMetadataResponse);
|
responseWithKeystoneAccess, getMetadata, getMetadataResponse);
|
||||||
|
|
||||||
assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").listMetadata(imageId).toString(),
|
assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadata(imageId).toString(),
|
||||||
new ParseMetadataListTest().expected().toString());
|
new ParseMetadataListTest().expected().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListMetadataWhenResponseIs404() throws Exception {
|
public void testListMetadataWhenResponseIs404() throws Exception {
|
||||||
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
||||||
HttpRequest listMetadata = HttpRequest
|
HttpRequest getMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata")
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata")
|
||||||
|
@ -146,13 +146,13 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(404).build();
|
HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, listMetadata, listMetadataResponse);
|
responseWithKeystoneAccess, getMetadata, getMetadataResponse);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").listMetadata(imageId);
|
apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadata(imageId);
|
||||||
fail("Expected an exception.");
|
fail("Expected an exception.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
;
|
;
|
||||||
|
@ -224,7 +224,7 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
HttpRequest setMetadata = HttpRequest
|
HttpRequest setMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + imageId + "/metadata")
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata")
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json")
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json"))
|
.payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json"))
|
||||||
|
@ -274,7 +274,7 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
||||||
String key = "Image%20Version";
|
String key = "Image%20Version";
|
||||||
|
|
||||||
HttpRequest getMetadataItem = HttpRequest
|
HttpRequest getMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key)
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key)
|
||||||
|
@ -282,15 +282,14 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse getMetadataItemResponse = HttpResponse.builder().statusCode(200)
|
HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(200)
|
||||||
.payload(payloadFromString("{\"metadata\":{\"Image Version\":\"2.5\"}}")).build();
|
.payload(payloadFromString("{\"metadata\":{\"Image Version\":\"2.5\"}}")).build();
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, getMetadataItem, getMetadataItemResponse);
|
responseWithKeystoneAccess, getMetadata, getMetadataResponse);
|
||||||
|
|
||||||
System.out.println(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, "Image Version").toString());
|
assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadata(imageId, "Image Version").toString(),
|
||||||
assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, "Image Version").toString(),
|
"2.5");
|
||||||
"{Image Version=2.5}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetMetadataItemWhenResponseIs404() throws Exception {
|
public void testGetMetadataItemWhenResponseIs404() throws Exception {
|
||||||
|
@ -311,58 +310,37 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, getMetadata, getMetadataResponse);
|
responseWithKeystoneAccess, getMetadata, getMetadataResponse);
|
||||||
|
|
||||||
assertNull(apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, key));
|
assertNull(apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").getMetadata(imageId, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetMetadataItemWhenResponseIs2xx() throws Exception {
|
public void testSetMetadataItemWhenResponseIs2xx() throws Exception {
|
||||||
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
||||||
String key = "Image%20Version";
|
String key = "Image Version";
|
||||||
|
|
||||||
HttpRequest setMetadataItem = HttpRequest
|
HttpRequest updateMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("PUT")
|
.method("PUT")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key)
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + "Image%20Version")
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json")
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json"))
|
.payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(200)
|
HttpResponse updateMetadataResponse = HttpResponse.builder().statusCode(200)
|
||||||
.payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json")).build();
|
.payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json")).build();
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse);
|
responseWithKeystoneAccess, updateMetadata, updateMetadataResponse);
|
||||||
|
|
||||||
assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").setMetadataItem(imageId, key, "2.5").toString(),
|
assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").updateMetadata(imageId, key, "2.5").toString(),
|
||||||
"Image Version=2.5");
|
"2.5");
|
||||||
}
|
|
||||||
|
|
||||||
public void testSetMetadataItemWhenResponseIs404() throws Exception {
|
|
||||||
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
|
||||||
String key = "Image%20Version";
|
|
||||||
|
|
||||||
HttpRequest setMetadataItem = HttpRequest
|
|
||||||
.builder()
|
|
||||||
.method("PUT")
|
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key)
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("X-Auth-Token", authToken)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
|
||||||
responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse);
|
|
||||||
|
|
||||||
assertNull(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").setMetadataItem(imageId, key, "2.5"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteMetadataItemWhenResponseIs2xx() throws Exception {
|
public void testDeleteMetadataItemWhenResponseIs2xx() throws Exception {
|
||||||
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
||||||
String key = "Image%20Version";
|
String key = "Image%20Version";
|
||||||
|
|
||||||
HttpRequest deleteMetadataItem = HttpRequest
|
HttpRequest deleteMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("DELETE")
|
.method("DELETE")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key)
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key)
|
||||||
|
@ -370,19 +348,19 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(204).build();
|
HttpResponse deleteMetadataResponse = HttpResponse.builder().statusCode(204).build();
|
||||||
|
|
||||||
NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse);
|
responseWithKeystoneAccess, deleteMetadata, deleteMetadataResponse);
|
||||||
|
|
||||||
apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadataItem(imageId, key);
|
apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadata(imageId, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteMetadataItemWhenResponseIs404() throws Exception {
|
public void testDeleteMetadataItemWhenResponseIs404() throws Exception {
|
||||||
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2";
|
||||||
String key = "Image%20Version";
|
String key = "Image%20Version";
|
||||||
|
|
||||||
HttpRequest deleteMetadataItem = HttpRequest
|
HttpRequest deleteMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("DELETE")
|
.method("DELETE")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key)
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key)
|
||||||
|
@ -390,12 +368,12 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(404).build();
|
HttpResponse deleteMetadataResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse);
|
responseWithKeystoneAccess, deleteMetadata, deleteMetadataResponse);
|
||||||
|
|
||||||
apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadataItem(imageId, key);
|
apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadata(imageId, key);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||||
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
|
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
|
||||||
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
||||||
import org.jclouds.openstack.nova.v2_0.parse.ParseCreatedServerTest;
|
import org.jclouds.openstack.nova.v2_0.parse.ParseCreatedServerTest;
|
||||||
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataItemTest;
|
|
||||||
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataListTest;
|
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataListTest;
|
||||||
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest;
|
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest;
|
||||||
import org.jclouds.openstack.nova.v2_0.parse.ParseServerListTest;
|
import org.jclouds.openstack.nova.v2_0.parse.ParseServerListTest;
|
||||||
|
@ -278,27 +277,27 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
public void testListMetadataWhenResponseIs2xx() throws Exception {
|
public void testListMetadataWhenResponseIs2xx() throws Exception {
|
||||||
String serverId = "123";
|
String serverId = "123";
|
||||||
|
|
||||||
HttpRequest listMetadata = HttpRequest
|
HttpRequest getMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata")
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata")
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json")
|
||||||
.addHeader("X-Auth-Token", authToken).build();
|
.addHeader("X-Auth-Token", authToken).build();
|
||||||
|
|
||||||
HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(200)
|
HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(200)
|
||||||
.payload(payloadFromResource("/metadata_list.json")).build();
|
.payload(payloadFromResource("/metadata_list.json")).build();
|
||||||
|
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, listMetadata, listMetadataResponse);
|
responseWithKeystoneAccess, getMetadata, getMetadataResponse);
|
||||||
|
|
||||||
assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").listMetadata(serverId).toString(),
|
assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadata(serverId).toString(),
|
||||||
new ParseMetadataListTest().expected().toString());
|
new ParseMetadataListTest().expected().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListMetadataWhenResponseIs404() throws Exception {
|
public void testListMetadataWhenResponseIs404() throws Exception {
|
||||||
String serverId = "123";
|
String serverId = "123";
|
||||||
HttpRequest listMetadata = HttpRequest
|
HttpRequest getMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata")
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata")
|
||||||
|
@ -306,13 +305,13 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(404).build();
|
HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, listMetadata, listMetadataResponse);
|
responseWithKeystoneAccess, getMetadata, getMetadataResponse);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").listMetadata(serverId);
|
apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadata(serverId);
|
||||||
fail("Expected an exception.");
|
fail("Expected an exception.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
;
|
;
|
||||||
|
@ -432,24 +431,24 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
|
|
||||||
public void testGetMetadataItemWhenResponseIs2xx() throws Exception {
|
public void testGetMetadataItemWhenResponseIs2xx() throws Exception {
|
||||||
String serverId = "123";
|
String serverId = "123";
|
||||||
String key = "Server%20Label";
|
String key = "Server Label";
|
||||||
|
|
||||||
HttpRequest getMetadataItem = HttpRequest
|
HttpRequest getMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key)
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + "Server%20Label")
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json")
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse getMetadataItemResponse = HttpResponse.builder().statusCode(200)
|
HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(200)
|
||||||
.payload(payloadFromResource("/metadata_item.json")).build();
|
.payload(payloadFromResource("/metadata_item.json")).build();
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, getMetadataItem, getMetadataItemResponse);
|
responseWithKeystoneAccess, getMetadata, getMetadataResponse);
|
||||||
|
|
||||||
assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadataItem(serverId, "Server Label").toString(),
|
assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadata(serverId, key).toString(),
|
||||||
new ParseMetadataItemTest().expected().toString());
|
"Web Head 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetMetadataItemWhenResponseIs404() throws Exception {
|
public void testGetMetadataItemWhenResponseIs404() throws Exception {
|
||||||
|
@ -541,7 +540,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
String serverId = "123";
|
String serverId = "123";
|
||||||
String key = "Server%20Label";
|
String key = "Server%20Label";
|
||||||
|
|
||||||
HttpRequest setMetadataItem = HttpRequest
|
HttpRequest updateMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("DELETE")
|
.method("DELETE")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key)
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key)
|
||||||
|
@ -549,12 +548,12 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(204).build();
|
HttpResponse updateMetadataResponse = HttpResponse.builder().statusCode(204).build();
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse);
|
responseWithKeystoneAccess, updateMetadata, updateMetadataResponse);
|
||||||
|
|
||||||
apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadataItem(serverId, key);
|
apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadata(serverId, key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,7 +561,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
String serverId = "123";
|
String serverId = "123";
|
||||||
String key = "Server%20Label";
|
String key = "Server%20Label";
|
||||||
|
|
||||||
HttpRequest deleteMetadataItem = HttpRequest
|
HttpRequest deleteMetadata = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("DELETE")
|
.method("DELETE")
|
||||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key)
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key)
|
||||||
|
@ -570,12 +569,12 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
.addHeader("X-Auth-Token", authToken)
|
.addHeader("X-Auth-Token", authToken)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(404).build();
|
HttpResponse deleteMetadataResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse);
|
responseWithKeystoneAccess, deleteMetadata, deleteMetadataResponse);
|
||||||
|
|
||||||
apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadataItem(serverId, key);
|
apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadata(serverId, key);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue