removed deprecated Unwrap fields

This commit is contained in:
Adrian Cole 2011-12-18 17:59:13 -08:00
parent 468ad69c94
commit 4eb6c08155
39 changed files with 153 additions and 514 deletions

View File

@ -23,6 +23,8 @@ package org.jclouds.cloudstack;
*/
public class AsyncJobException extends RuntimeException {
private static final long serialVersionUID = -9174243454135616477L;
public AsyncJobException() {
}

View File

@ -18,16 +18,13 @@
*/
package org.jclouds.cloudstack.domain;
import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
import org.omg.CORBA.UNKNOWN;
import java.util.Date;
import java.util.Map;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import java.util.Date;
import com.google.gson.annotations.SerializedName;
/**
* Represents a host issued by Cloudstack
*

View File

@ -18,9 +18,10 @@
*/
package org.jclouds.cloudstack.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.gson.annotations.SerializedName;
/**

View File

@ -18,10 +18,10 @@
*/
package org.jclouds.cloudstack.domain;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import com.google.gson.annotations.SerializedName;
/**
* @author Richard Downer
*/

View File

@ -18,7 +18,11 @@
*/
package org.jclouds.cloudstack.features;
import com.google.common.util.concurrent.ListenableFuture;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.cloudstack.domain.Account;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.CreateAccountOptions;
@ -29,11 +33,7 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.Set;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to CloudStack Account features available to Global

View File

@ -18,32 +18,27 @@
*/
package org.jclouds.cloudstack.features;
import com.google.common.util.concurrent.ListenableFuture;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.cloudstack.domain.DiskOffering;
import org.jclouds.cloudstack.domain.NetworkOffering;
import org.jclouds.cloudstack.domain.ServiceOffering;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.CreateDiskOfferingOptions;
import org.jclouds.cloudstack.options.CreateServiceOfferingOptions;
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions;
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.OnlyElement;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.Set;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to cloudstack via their REST API.

View File

@ -32,10 +32,11 @@ import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions;
import org.jclouds.functions.JoinOnComma;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.OnlyElement;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -58,7 +59,7 @@ public interface LoadBalancerAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "listLoadBalancerRules")
@Unwrap(depth = 2)
@SelectJson("loadbalancerrule")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<LoadBalancerRule>> listLoadBalancerRules(ListLoadBalancerRulesOptions... options);
@ -68,7 +69,8 @@ public interface LoadBalancerAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "listLoadBalancerRules")
@Unwrap(depth = 3, edgeCollection = Set.class)
@SelectJson("loadbalancerrule")
@OnlyElement
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<LoadBalancerRule> getLoadBalancerRule(@QueryParam("id") long id);
@ -78,7 +80,7 @@ public interface LoadBalancerAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "createLoadBalancerRule")
@Unwrap(depth = 2)
@SelectJson("loadbalancerrule")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<LoadBalancerRule> createLoadBalancerRuleForPublicIP(@QueryParam("publicipid") long publicIPId,
@QueryParam("algorithm") Algorithm algorithm, @QueryParam("name") String name,
@ -89,7 +91,7 @@ public interface LoadBalancerAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "deleteLoadBalancerRule")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Long> deleteLoadBalancerRule(@QueryParam("id") long id);
@ -100,7 +102,7 @@ public interface LoadBalancerAsyncClient {
@GET
@QueryParams(keys = "command", values = "assignToLoadBalancerRule")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> assignVirtualMachinesToLoadBalancerRule(@QueryParam("id") long id,
@QueryParam("virtualmachineids") @ParamParser(JoinOnComma.class) Iterable<Long> virtualMachineIds);
@ -111,7 +113,7 @@ public interface LoadBalancerAsyncClient {
@GET
@QueryParams(keys = "command", values = "assignToLoadBalancerRule")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> assignVirtualMachinesToLoadBalancerRule(@QueryParam("id") long id,
@QueryParam("virtualmachineids") @ParamParser(JoinOnComma.class) long... virtualMachineIds);
@ -122,7 +124,7 @@ public interface LoadBalancerAsyncClient {
@GET
@QueryParams(keys = "command", values = "removeFromLoadBalancerRule")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> removeVirtualMachinesFromLoadBalancerRule(@QueryParam("id") long id,
@QueryParam("virtualmachineids") @ParamParser(JoinOnComma.class) Iterable<Long> virtualMachineIds);
@ -133,7 +135,7 @@ public interface LoadBalancerAsyncClient {
@GET
@QueryParams(keys = "command", values = "removeFromLoadBalancerRule")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> removeVirtualMachinesFromLoadBalancerRule(@QueryParam("id") long id,
@QueryParam("virtualmachineids") @ParamParser(JoinOnComma.class) long... virtualMachineIds);
@ -143,7 +145,7 @@ public interface LoadBalancerAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "listLoadBalancerRuleInstances")
@Unwrap(depth = 2)
@SelectJson("loadbalancerrule")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<VirtualMachine>> listVirtualMachinesAssignedToLoadBalancerRule(@QueryParam("id") long id);

View File

@ -37,7 +37,6 @@ import org.jclouds.rest.annotations.OnlyElement;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
@ -92,7 +91,7 @@ public interface SecurityGroupAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "authorizeSecurityGroupIngress")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> authorizeIngressPortsToCIDRs(@QueryParam("securitygroupid") long securityGroupId,
@QueryParam("protocol") String protocol, @QueryParam("startport") int startPort,
@ -105,7 +104,7 @@ public interface SecurityGroupAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "authorizeSecurityGroupIngress")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> authorizeIngressPortsToSecurityGroups(@QueryParam("securitygroupid") long securityGroupId,
@QueryParam("protocol") String protocol, @QueryParam("startport") int startPort,
@ -118,7 +117,7 @@ public interface SecurityGroupAsyncClient {
*/
@GET
@QueryParams(keys = { "command", "protocol" }, values = { "authorizeSecurityGroupIngress", "ICMP" })
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> authorizeIngressICMPToCIDRs(@QueryParam("securitygroupid") long securityGroupId,
@QueryParam("icmpcode") int ICMPCode, @QueryParam("icmptype") int ICMPType,
@ -130,7 +129,7 @@ public interface SecurityGroupAsyncClient {
*/
@GET
@QueryParams(keys = { "command", "protocol" }, values = { "authorizeSecurityGroupIngress", "ICMP" })
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> authorizeIngressICMPToSecurityGroups(@QueryParam("securitygroupid") long securityGroupId,
@QueryParam("icmpcode") int ICMPCode, @QueryParam("icmptype") int ICMPType,
@ -143,7 +142,7 @@ public interface SecurityGroupAsyncClient {
@GET
@QueryParams(keys = "command", values = "revokeSecurityGroupIngress")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> revokeIngressRule(@QueryParam("id") long id, AccountInDomainOptions... options);

View File

@ -50,7 +50,6 @@ import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;

View File

@ -90,7 +90,7 @@ public interface VirtualMachineAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "rebootVirtualMachine")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> rebootVirtualMachine(@QueryParam("id") long id);
@ -99,7 +99,7 @@ public interface VirtualMachineAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "startVirtualMachine")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> startVirtualMachine(@QueryParam("id") long id);
@ -108,7 +108,7 @@ public interface VirtualMachineAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "stopVirtualMachine")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> stopVirtualMachine(@QueryParam("id") long id);
@ -117,7 +117,7 @@ public interface VirtualMachineAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "resetPasswordForVirtualMachine")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> resetPasswordForVirtualMachine(@QueryParam("id") long id);
@ -126,7 +126,7 @@ public interface VirtualMachineAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "changeServiceForVirtualMachine")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> changeServiceForVirtualMachine(@QueryParam("id") long id);
@ -135,7 +135,7 @@ public interface VirtualMachineAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "updateVirtualMachine")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> updateVirtualMachine(@QueryParam("id") long id);
@ -144,7 +144,7 @@ public interface VirtualMachineAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "destroyVirtualMachine")
@Unwrap(depth = 2)
@SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Long> destroyVirtualMachine(@QueryParam("id") long id);

View File

@ -25,18 +25,17 @@ import java.util.Set;
import javax.inject.Singleton;
import com.google.inject.TypeLiteral;
import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.domain.JsonBall;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.json.internal.GsonWrapper;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
import org.jclouds.json.internal.GsonWrapper;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole

View File

@ -18,10 +18,9 @@
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.cloudstack.domain.NetworkType;
import org.jclouds.cloudstack.domain.TrafficType;
import com.google.common.collect.ImmutableSet;
/**
* Options used to control what hosts information is returned

View File

@ -19,10 +19,6 @@
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.StorageType;
import org.jclouds.cloudstack.domain.SystemVmType;
import java.util.Set;
/**
* Options to control how service offerings are created

View File

@ -19,10 +19,6 @@
package org.jclouds.cloudstack.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.cloudstack.domain.AsyncJob.ResultCode.FAIL;
import static org.jclouds.cloudstack.domain.AsyncJob.ResultCode.SUCCESS;
import static org.jclouds.cloudstack.domain.AsyncJob.Status.FAILED;
import static org.jclouds.cloudstack.domain.AsyncJob.Status.SUCCEEDED;
import javax.annotation.Resource;
import javax.inject.Singleton;

View File

@ -18,17 +18,17 @@
*/
package org.jclouds.cloudstack.predicates;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.cloudstack.domain.VirtualMachine.State;
import org.jclouds.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource;
import javax.inject.Singleton;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.logging.Logger;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
*

View File

@ -67,8 +67,8 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.net.InetAddresses;

View File

@ -18,13 +18,13 @@
*/
package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.Capacity;
import org.jclouds.cloudstack.options.ListCapacityOptions;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.Set;
import static org.testng.Assert.*;
import org.jclouds.cloudstack.domain.Capacity;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code GlobalCapacityClient}

View File

@ -18,7 +18,8 @@
*/
package org.jclouds.cloudstack.features;
import com.google.inject.TypeLiteral;
import java.lang.reflect.Method;
import org.jclouds.cloudstack.options.ListHostsOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
@ -26,8 +27,7 @@ import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code GlobalHostAsyncClient}

View File

@ -18,14 +18,12 @@
*/
package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.logging.Logger;
import org.testng.annotations.Test;
import static org.testng.Assert.assertTrue;
import java.util.Set;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.jclouds.cloudstack.domain.Host;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code GlobalHostClient}

View File

@ -18,7 +18,8 @@
*/
package org.jclouds.cloudstack.features;
import com.google.inject.TypeLiteral;
import java.lang.reflect.Method;
import org.jclouds.cloudstack.options.CreateDiskOfferingOptions;
import org.jclouds.cloudstack.options.CreateServiceOfferingOptions;
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
@ -31,10 +32,7 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.DEFAULT;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code GlobalOfferingAsyncClient}

View File

@ -18,33 +18,19 @@
*/
package org.jclouds.cloudstack.features;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.DiskOffering;
import org.jclouds.cloudstack.domain.JobResult;
import org.jclouds.cloudstack.domain.NetworkOffering;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.jclouds.cloudstack.domain.ServiceOffering;
import org.jclouds.cloudstack.domain.StorageType;
import org.jclouds.cloudstack.domain.UsageRecord;
import org.jclouds.cloudstack.options.GenerateUsageRecordsOptions;
import org.jclouds.cloudstack.options.ListUsageRecordsOptions;
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions;
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
import org.jclouds.logging.Logger;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.Calendar;
import java.util.Date;
import java.util.Set;
import java.util.TimeZone;
import static com.google.common.collect.Iterables.getFirst;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.OPTIONAL;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.REQUIRED;
import static org.jclouds.cloudstack.options.CreateDiskOfferingOptions.Builder.diskSizeInGB;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable;
import static org.testng.Assert.*;
import org.jclouds.cloudstack.domain.JobResult;
import org.jclouds.cloudstack.domain.UsageRecord;
import org.jclouds.cloudstack.options.GenerateUsageRecordsOptions;
import org.jclouds.cloudstack.options.ListUsageRecordsOptions;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code GlobalUsageClient}

View File

@ -18,9 +18,9 @@
*/
package org.jclouds.cloudstack.features;
import com.google.inject.TypeLiteral;
import java.lang.reflect.Method;
import org.jclouds.cloudstack.options.CreateUserOptions;
import org.jclouds.cloudstack.options.UpdateAccountOptions;
import org.jclouds.cloudstack.options.UpdateUserOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
@ -29,7 +29,7 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code GlobalUserAsyncClient}

View File

@ -24,7 +24,7 @@ import java.lang.reflect.Method;
import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm;
import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -52,7 +52,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest<L
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
@ -70,7 +70,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest<L
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
@ -89,7 +89,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest<L
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -106,7 +106,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest<L
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
@ -125,7 +125,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest<L
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);

View File

@ -67,17 +67,23 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
prefix += "rule";
try {
network = find(client.getNetworkClient().listNetworks(), NetworkPredicates.hasLoadBalancerService());
Long defaultTemplate = (imageId != null && !"".equals(imageId)) ? new Long(imageId) : null;
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network,
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
virtualMachineRunning);
if (vm.getPassword() != null)
password = vm.getPassword();
} catch (NoSuchElementException e) {
networksDisabled = true;
}
}
public void testCreateVm() {
if (networksDisabled)
return;
Long defaultTemplate = (imageId != null && !"".equals(imageId)) ? new Long(imageId) : null;
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network,
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
virtualMachineRunning);
if (vm.getPassword() != null)
password = vm.getPassword();
}
@Test(dependsOnMethods = "testCreateVm")
public void testCreateLoadBalancerRule() throws Exception {
if (networksDisabled)
return;
@ -134,8 +140,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
public void testRemoveFromLoadBalancerRule() throws Exception {
if (networksDisabled)
throw new SshException();
assertTrue(jobComplete.apply(client.getLoadBalancerClient().removeVirtualMachinesFromLoadBalancerRule(rule.getId(),
vm.getId())));
assertTrue(jobComplete.apply(client.getLoadBalancerClient().removeVirtualMachinesFromLoadBalancerRule(
rule.getId(), vm.getId())));
assertEquals(client.getLoadBalancerClient().listVirtualMachinesAssignedToLoadBalancerRule(rule.getId()).size(), 0);
assertEquals(rule.getState(), State.ADD);
checkSSH(new IPSocket(ip.getIPAddress(), 22));

View File

@ -18,10 +18,11 @@
*/
package org.jclouds.cloudstack.features;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.DEFAULT;
import java.io.IOException;
import java.lang.reflect.Method;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
@ -36,8 +37,6 @@ import org.testng.annotations.Test;
import com.google.common.base.Functions;
import com.google.inject.TypeLiteral;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.DEFAULT;
/**
* Tests behavior of {@code OfferingAsyncClient}
*

View File

@ -27,7 +27,6 @@ import org.jclouds.functions.IdentityFunction;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -134,7 +133,7 @@ public class SecurityGroupAsyncClientTest extends BaseCloudStackAsyncClientTest<
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -154,7 +153,7 @@ public class SecurityGroupAsyncClientTest extends BaseCloudStackAsyncClientTest<
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -173,7 +172,7 @@ public class SecurityGroupAsyncClientTest extends BaseCloudStackAsyncClientTest<
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -193,7 +192,7 @@ public class SecurityGroupAsyncClientTest extends BaseCloudStackAsyncClientTest<
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -213,7 +212,7 @@ public class SecurityGroupAsyncClientTest extends BaseCloudStackAsyncClientTest<
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);

View File

@ -21,7 +21,6 @@ package org.jclouds.cloudstack.features;
import java.io.IOException;
import java.lang.reflect.Method;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.ExtractMode;
import org.jclouds.cloudstack.domain.Template;
import org.jclouds.cloudstack.domain.TemplateFilter;
@ -42,11 +41,11 @@ import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableSet;
import com.google.inject.TypeLiteral;
/**

View File

@ -27,7 +27,6 @@ import org.jclouds.functions.IdentityFunction;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -130,7 +129,7 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -147,7 +146,7 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -164,7 +163,7 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -181,7 +180,7 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -198,7 +197,7 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -215,7 +214,7 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
@ -232,7 +231,7 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);

View File

@ -18,16 +18,16 @@
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.OPTIONAL;
import static org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions.Builder.availability;
import static org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions.Builder.displayText;
import static org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions.Builder.name;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code UpdateNetworkOfferingOptions}
*

View File

@ -18,23 +18,14 @@
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.StorageType;
import org.jclouds.cloudstack.domain.SystemVmType;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.hostTags;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.isSystem;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.limitCpuUse;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.networkRateInMb;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.storageType;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.systemVmType;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.tags;
import static org.jclouds.cloudstack.options.UpdateServiceOfferingOptions.Builder.displayText;
import static org.jclouds.cloudstack.options.UpdateServiceOfferingOptions.Builder.name;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code UpdateServiceOfferingOptions}
*

View File

@ -18,7 +18,6 @@
*/
package org.jclouds.cloudstack.parse;
import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.cloudstack.domain.JobResult;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.rest.annotations.SelectJson;

View File

@ -18,10 +18,11 @@
*/
package org.jclouds.cloudstack.parse;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.REQUIRED;
import java.util.Set;
import org.jclouds.cloudstack.domain.NetworkOffering;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.rest.annotations.SelectJson;
@ -29,8 +30,6 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.REQUIRED;
/**
* @author Adrian Cole
*/

View File

@ -18,22 +18,17 @@
*/
package org.jclouds.cloudstack.parse;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
import java.util.Calendar;
import java.util.Date;
import java.util.Set;
import java.util.TimeZone;
import org.jclouds.cloudstack.domain.StoragePool;
import org.jclouds.cloudstack.functions.ParseIdToNameFromHttpResponse;
import org.jclouds.http.HttpResponse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import com.google.common.collect.ImmutableSet;
/**
*

View File

@ -18,24 +18,24 @@
*/
package org.jclouds.cloudstack.predicates;
import org.jclouds.cloudstack.AsyncJobException;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.cloudstack.domain.AsyncJobError;
import org.jclouds.cloudstack.features.AsyncJobClient;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.jclouds.cloudstack.domain.AsyncJob.ResultCode;
import static org.jclouds.cloudstack.domain.AsyncJob.Status;
import static org.jclouds.cloudstack.domain.AsyncJobError.ErrorCode;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import org.jclouds.cloudstack.AsyncJobException;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.cloudstack.domain.AsyncJob.ResultCode;
import org.jclouds.cloudstack.domain.AsyncJob.Status;
import org.jclouds.cloudstack.domain.AsyncJobError;
import org.jclouds.cloudstack.domain.AsyncJobError.ErrorCode;
import org.jclouds.cloudstack.features.AsyncJobClient;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
* @author Andrei Savu
*/
@ -55,9 +55,9 @@ public class JobCompleteTest {
@Test
public void testJobComplete() {
AsyncJob job = AsyncJob.builder().id(100L)
AsyncJob<?> job = AsyncJob.builder().id(100L)
.status(Status.SUCCEEDED).resultCode(ResultCode.SUCCESS).build();
expect(asyncJobClient.getAsyncJob(job.getId())).andReturn(job);
expect((Object) asyncJobClient.getAsyncJob(job.getId())).andReturn(job);
replay(client, asyncJobClient);
assertTrue(new JobComplete(client).apply(job.getId()));
@ -66,10 +66,10 @@ public class JobCompleteTest {
@Test
public void testFailedJobComplete() {
AsyncJob job = AsyncJob.builder().id(100L)
AsyncJob<?> job = AsyncJob.builder().id(100L)
.status(Status.FAILED).resultCode(ResultCode.FAIL)
.error(new AsyncJobError(ErrorCode.INTERNAL_ERROR, "Dummy test error")).build();
expect(asyncJobClient.getAsyncJob(job.getId())).andReturn(job);
expect((Object) asyncJobClient.getAsyncJob(job.getId())).andReturn(job);
replay(client, asyncJobClient);
try {

View File

@ -1,70 +0,0 @@
/**
* 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.http.functions;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpResponse;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
*/
@Singleton
public class UnwrapOnlyNestedJsonValue<T> implements Function<HttpResponse, T> {
private final ParseJson<Map<String, Map<String, T>>> json;
private final TypeLiteral<T> type;
@Inject
UnwrapOnlyNestedJsonValue(ParseJson<Map<String, Map<String, T>>> json, TypeLiteral<T> type) {
this.json = json;
this.type = type;
}
@SuppressWarnings("unchecked")
@Override
public T apply(HttpResponse arg0) {
Map<String, Map<String, T>> map = json.apply(arg0);
if (map == null || map.size() == 0)
return null;
Map<String, T> map1 = Iterables.getOnlyElement(map.values());
if (map1 == null || map1.size() == 0) {
if (type.getRawType().isAssignableFrom(Set.class))
return (T) ImmutableSet.of();
else if (type.getRawType().isAssignableFrom(List.class))
return (T) ImmutableList.of();
else if (type.getRawType().isAssignableFrom(Map.class))
return (T) ImmutableMap.of();
return null;
}
return Iterables.getOnlyElement(map1.values());
}
}

View File

@ -1,51 +0,0 @@
/**
* 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.http.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpResponse;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Singleton
public class UnwrapOnlyNestedJsonValueInSet<T> implements Function<HttpResponse, T> {
private final UnwrapOnlyNestedJsonValue<Set<T>> json;
@Inject
UnwrapOnlyNestedJsonValueInSet(UnwrapOnlyNestedJsonValue<Set<T>> json) {
this.json = json;
}
@Override
public T apply(HttpResponse arg0) {
Set<T> set = json.apply(arg0);
if (set == null || set.size() == 0)
return null;
return Iterables.getOnlyElement(set);
}
}

View File

@ -23,7 +23,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.Map;
/**
* Unwraps the only value in a nested json reponse
@ -35,48 +34,6 @@ import java.util.Map;
@Target(METHOD)
@Retention(RUNTIME)
public @interface Unwrap {
/**
* level to unwrap.
*
* ex. if default (1)
*
* { "foo" :"bar" } becomes "bar"
*
* ex. if (2)
*
* { "foo" : {"bar" : ["baz"]} } becomes ["baz"]
*
* <h4>Deprecation</h4>
* <p/>
* Note that using @SelectJson("bar") is more effective than guessing the
* depth
*
* @see SelectJson
*/
@Deprecated
int depth() default 1;
/**
* final collection type
*
* ex. if depth(2), edgeCollection(Map.class)
*
* { "foo" : {"bar" : ["baz"]} } becomes ["baz"]
*
* ex. if depth(3), edgeCollection(Set.class)
*
* { "foo" : {"bar" : ["baz"]} } becomes "baz"
*
* <h4>Note</h4> only Map and Set are valid
* <p/>
* <h4>Deprecation</h4>
* <p/>
* Note that using @SelectJson("bar") @OnlyElement will have the same effect
*
* @see SelectJson
* @see OnlyElement
*/
@Deprecated
Class<?> edgeCollection() default Map.class;
}

View File

@ -47,9 +47,9 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedSet;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import javax.annotation.Resource;
@ -78,6 +78,7 @@ import org.jclouds.http.HttpUtils;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
@ -85,10 +86,6 @@ import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.http.functions.ReturnStringIf2xx;
import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.UnwrapOnlyJsonValueInSet;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.http.utils.ModifyRequest;
import org.jclouds.internal.ClassMethodArgs;
@ -142,18 +139,18 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Inject;
import com.google.inject.Injector;
@ -844,23 +841,11 @@ public class RestAnnotationProcessor<T> {
return returnVal;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({ "unchecked" })
public static Key<? extends Function<HttpResponse, ?>> getJsonParserKeyForMethodAnType(Method method, Type returnVal) {
ParameterizedType parserType;
if (method.isAnnotationPresent(Unwrap.class)) {
int depth = method.getAnnotation(Unwrap.class).depth();
Class edgeCollection = method.getAnnotation(Unwrap.class).edgeCollection();
if (depth == 1 && edgeCollection == Map.class)
parserType = Types.newParameterizedType(UnwrapOnlyJsonValue.class, returnVal);
else if (depth == 2 && edgeCollection == Map.class)
parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValue.class, returnVal);
else if (depth == 2 && edgeCollection == Set.class)
parserType = Types.newParameterizedType(UnwrapOnlyJsonValueInSet.class, returnVal);
else if (depth == 3 && edgeCollection == Set.class)
parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValueInSet.class, returnVal);
else
throw new IllegalStateException(String.format("depth(%d) edgeCollection(%s) not yet supported for @Unwrap",
depth, edgeCollection));
parserType = Types.newParameterizedType(UnwrapOnlyJsonValue.class, returnVal);
} else {
parserType = Types.newParameterizedType(ParseJson.class, returnVal);
}

View File

@ -99,9 +99,6 @@ import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.http.functions.ReturnStringIf2xx;
import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.UnwrapOnlyJsonValueInSet;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
import org.jclouds.http.internal.PayloadEnclosingImpl;
import org.jclouds.http.options.BaseHttpRequestOptions;
import org.jclouds.http.options.GetOptions;
@ -897,29 +894,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<? extends Set<String>> testUnwrap4();
@GET
@Path("/")
@Unwrap(depth = 2)
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<? extends Set<String>> testUnwrapDepth2();
@GET
@Path("/")
@Unwrap(depth = 2)
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> testUnwrapDepth2Long();
@GET
@Path("/")
@SelectJson("jobid")
ListenableFuture<Long> selectLong();
@GET
@Path("/")
@Unwrap(depth = 2, edgeCollection = Set.class)
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<String> testUnwrapDepth2Set();
@GET
@Path("/")
@SelectJson("runit")
@ -927,12 +906,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<String> selectOnlyElement();
@GET
@Path("/")
@Unwrap(depth = 3, edgeCollection = Set.class)
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<String> testUnwrapDepth3();
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("ROWDY")
@ -1136,68 +1109,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
ImmutableSet.of("0.7.0", "0.7.1"));
}
@SuppressWarnings("unchecked")
public void testUnwrapDepth2() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPut.class.getMethod("testUnwrapDepth2");
HttpRequest request = factory(TestPut.class).createRequest(method);
assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValue.class);
// now test that it works!
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
assertEquals(parser.apply(new HttpResponse(200, "ok",
newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}"))), ImmutableSet.of("0.7.0", "0.7.1"));
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))),
ImmutableSet.<String> of());
}
@SuppressWarnings("unchecked")
public void testUnwrapDepth2Set() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPut.class.getMethod("testUnwrapDepth2Set");
HttpRequest request = factory(TestPut.class).createRequest(method);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValueInSet.class);
// now test that it works!
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\"]}"))), "0.7.0");
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[]}"))), null);
}
@SuppressWarnings("unchecked")
public void testSelectOnlyElement() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPut.class.getMethod("selectOnlyElement");
HttpRequest request = factory(TestPut.class).createRequest(method);
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\"]}"))), "0.7.0");
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[]}"))), null);
}
@SuppressWarnings("unchecked")
public void testUnwrapDepth2Long() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPut.class.getMethod("testUnwrapDepth2Long");
HttpRequest request = factory(TestPut.class).createRequest(method);
assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValue.class);
// now test that it works!
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
assertEquals(parser.apply(new HttpResponse(200, "ok",
newStringPayload("{ \"destroyvirtualmachineresponse\" : {\"jobid\":4} }"))), new Long(4));
}
@SuppressWarnings("unchecked")
public void selectLong() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPut.class.getMethod("selectLong");
@ -1213,52 +1124,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
newStringPayload("{ \"destroyvirtualmachineresponse\" : {\"jobid\":4} }"))), new Long(4));
}
@SuppressWarnings("unchecked")
public void testUnwrapDepth3() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPut.class.getMethod("testUnwrapDepth3");
HttpRequest request = factory(TestPut.class).createRequest(method);
assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValueInSet.class);
// now test that it works!
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\"]}}"))),
"0.7.0");
}
@SuppressWarnings("unchecked")
public void testUnwrapDepth3None() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPut.class.getMethod("testUnwrapDepth3");
HttpRequest request = factory(TestPut.class).createRequest(method);
assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValueInSet.class);
// now test that it works!
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{\"runit\":[]}}"))), null);
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))), null);
}
@SuppressWarnings("unchecked")
@Test(expectedExceptions = IllegalArgumentException.class)
public void testUnwrapDepth3TooMany() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPut.class.getMethod("testUnwrapDepth3");
HttpRequest request = factory(TestPut.class).createRequest(method);
assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValueInSet.class);
// now test that it works!
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}")));
}
static class TestRequestFilter1 implements HttpRequestFilter {
public HttpRequest filter(HttpRequest request) throws HttpException {
return request;