From 9c4ff83f25e8a3260a1125cc571ed105c458d5fe Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Tue, 22 Dec 2009 00:05:16 +0000 Subject: [PATCH] Issue 139: introduced default exception for 404 errors git-svn-id: http://jclouds.googlecode.com/svn/trunk@2501 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../storage/blob/AzureBlobClientTest.java | 27 ++-- .../storage/queue/AzureQueueClientTest.java | 11 +- .../blobstore/KeyNotFoundException.java | 4 +- .../rest/ResourceNotFoundException.java | 53 +++++++ .../functions/ThrowResourceNotFoundOn404.java | 47 ++++++ .../rest/internal/AsyncRestClientProxy.java | 2 +- .../internal/RestAnnotationProcessor.java | 5 +- .../java/org/jclouds/rest/RestClientTest.java | 5 +- .../org/jclouds/mezeo/pcs2/PCSClientTest.java | 13 +- .../org/jclouds/mezeo/pcs2/PCSCloudTest.java | 3 +- .../cloudservers/CloudServersClientTest.java | 75 ++++----- .../vcloud/config/VCloudRestClientModule.java | 25 +++ .../org/jclouds/vcloud/domain/TaskStatus.java | 6 +- .../jclouds/vcloud/VCloudComputeClient.java | 102 +++---------- .../vcloud/VCloudComputeClientLiveTest.java | 73 +++------ vcloud/core/src/test/resources/vapp.xml | 144 ++++++++++++++++++ .../HostingDotComVCloudRestClientModule.java | 25 --- .../TerremarkVCloudRestClientModule.java | 28 ---- 18 files changed, 394 insertions(+), 254 deletions(-) create mode 100644 core/src/main/java/org/jclouds/rest/ResourceNotFoundException.java create mode 100644 core/src/main/java/org/jclouds/rest/functions/ThrowResourceNotFoundOn404.java create mode 100644 vcloud/core/src/test/resources/vapp.xml diff --git a/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobClientTest.java b/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobClientTest.java index 08ff6c6c91..7204582b9f 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobClientTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobClientTest.java @@ -58,6 +58,7 @@ import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.config.RestModule; +import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Jsr330; @@ -95,7 +96,7 @@ public class AzureBlobClientTest { .singletonList("2009-07-17")); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListContainersOptions() throws SecurityException, NoSuchMethodException { @@ -116,7 +117,7 @@ public class AzureBlobClientTest { .singletonList("2009-07-17")); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testCreateContainer() throws SecurityException, NoSuchMethodException { @@ -136,7 +137,7 @@ public class AzureBlobClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnTrueIfContainerAlreadyExists.class); } @@ -155,7 +156,7 @@ public class AzureBlobClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnVoidIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnVoidOnNotFoundOr404.class); } @@ -180,7 +181,7 @@ public class AzureBlobClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnTrueIfContainerAlreadyExists.class); } @@ -201,7 +202,7 @@ public class AzureBlobClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnTrueIfContainerAlreadyExists.class); } @@ -220,7 +221,7 @@ public class AzureBlobClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnTrueOn404.class); } @@ -244,7 +245,7 @@ public class AzureBlobClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnTrueIfContainerAlreadyExists.class); } @@ -263,7 +264,7 @@ public class AzureBlobClientTest { .singletonList("2009-07-17")); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListRootBlobs() throws SecurityException, NoSuchMethodException { @@ -281,7 +282,7 @@ public class AzureBlobClientTest { .singletonList("2009-07-17")); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testContainerProperties() throws SecurityException, NoSuchMethodException { @@ -298,7 +299,7 @@ public class AzureBlobClientTest { .singletonList("2009-07-17")); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseContainerPropertiesFromHeaders.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException { @@ -320,7 +321,7 @@ public class AzureBlobClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnVoidIf2xx.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException { @@ -341,7 +342,7 @@ public class AzureBlobClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnVoidIf2xx.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } @BeforeClass diff --git a/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueClientTest.java b/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueClientTest.java index f9ead3f444..60e912ff01 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueClientTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueClientTest.java @@ -47,6 +47,7 @@ import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.config.RestModule; +import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Jsr330; @@ -86,7 +87,7 @@ public class AzureQueueClientTest { .singletonList("2009-07-17")); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListQueuesOptions() throws SecurityException, NoSuchMethodException { @@ -106,7 +107,7 @@ public class AzureQueueClientTest { .singletonList("2009-07-17")); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testCreateQueue() throws SecurityException, NoSuchMethodException { @@ -126,7 +127,7 @@ public class AzureQueueClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testDeleteQueue() throws SecurityException, NoSuchMethodException { @@ -144,7 +145,7 @@ public class AzureQueueClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException { @@ -165,7 +166,7 @@ public class AzureQueueClientTest { assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } @BeforeClass diff --git a/blobstore/src/main/java/org/jclouds/blobstore/KeyNotFoundException.java b/blobstore/src/main/java/org/jclouds/blobstore/KeyNotFoundException.java index 697467ad78..2f8f11074e 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/KeyNotFoundException.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/KeyNotFoundException.java @@ -23,12 +23,14 @@ */ package org.jclouds.blobstore; +import org.jclouds.rest.ResourceNotFoundException; + /** * Thrown when a blob cannot be located in the container. * * @author Adrian Cole */ -public class KeyNotFoundException extends RuntimeException { +public class KeyNotFoundException extends ResourceNotFoundException { private String container; private String key; diff --git a/core/src/main/java/org/jclouds/rest/ResourceNotFoundException.java b/core/src/main/java/org/jclouds/rest/ResourceNotFoundException.java new file mode 100644 index 0000000000..adb24fcf40 --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/ResourceNotFoundException.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.rest; + +/** + * Thrown when a resource cannot be located. + * + * @author Adrian Cole + */ +public class ResourceNotFoundException extends RuntimeException { + + /** The serialVersionUID */ + private static final long serialVersionUID = -2272965726680821281L; + + + public ResourceNotFoundException() { + super(); + } + + public ResourceNotFoundException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public ResourceNotFoundException(String arg0) { + super(arg0); + } + + public ResourceNotFoundException(Throwable arg0) { + super(arg0); + } + +} diff --git a/core/src/main/java/org/jclouds/rest/functions/ThrowResourceNotFoundOn404.java b/core/src/main/java/org/jclouds/rest/functions/ThrowResourceNotFoundOn404.java new file mode 100644 index 0000000000..ef54661cda --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/functions/ThrowResourceNotFoundOn404.java @@ -0,0 +1,47 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.rest.functions; + +import org.jclouds.http.HttpResponseException; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Function; + +/** + * + * @author Adrian Cole + */ +public class ThrowResourceNotFoundOn404 implements Function { + + public Object apply(Exception from) { + if (from instanceof HttpResponseException) { + HttpResponseException responseException = (HttpResponseException) from; + if (responseException.getResponse().getStatusCode() == 404) { + throw new ResourceNotFoundException(from); + } + } + return null; + } + +} diff --git a/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java b/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java index 318b61ea08..893fc9768e 100755 --- a/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java +++ b/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java @@ -92,7 +92,7 @@ public class AsyncRestClientProxy implements InvocationHandler { method = util.getDelegateOrNull(method); logger.trace("Converting %s.%s", declaring.getSimpleName(), method.getName()); Function exceptionParser = util - .createExceptionParserOrNullIfNotFound(method); + .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method); // in case there is an exception creating the request, we should at least pass in args if (exceptionParser instanceof InvocationContext) { ((InvocationContext) exceptionParser).setContext(null); diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 4ef4389f45..5e453eb181 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -94,6 +94,7 @@ import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; @@ -211,12 +212,12 @@ public class RestAnnotationProcessor { } @VisibleForTesting - public Function createExceptionParserOrNullIfNotFound(Method method) { + public Function createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(Method method) { ExceptionParser annotation = method.getAnnotation(ExceptionParser.class); if (annotation != null) { return injector.getInstance(annotation.value()); } - return null; + return injector.getInstance(ThrowResourceNotFoundOn404.class); } @SuppressWarnings("unchecked") diff --git a/core/src/test/java/org/jclouds/rest/RestClientTest.java b/core/src/test/java/org/jclouds/rest/RestClientTest.java index 0a91b9fe61..1e30a33275 100644 --- a/core/src/test/java/org/jclouds/rest/RestClientTest.java +++ b/core/src/test/java/org/jclouds/rest/RestClientTest.java @@ -34,6 +34,7 @@ import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpUtils; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.rest.config.RestModule; +import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; @@ -86,9 +87,9 @@ public abstract class RestClientTest { protected void assertExceptionParserClassEquals(Method method, @Nullable Class parserClass) { if (parserClass == null) - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); else - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), parserClass); } diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSClientTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSClientTest.java index ab28165a7f..727b3945d4 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSClientTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSClientTest.java @@ -58,6 +58,7 @@ import org.jclouds.mezeo.pcs2.options.PutBlockOptions; import org.jclouds.mezeo.pcs2.xml.ContainerHandler; import org.jclouds.mezeo.pcs2.xml.FileHandler; import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; @@ -123,7 +124,7 @@ public class PCSClientTest extends RestClientTest { assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null); assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnVoidOnNotFoundOr404.class); } @@ -139,7 +140,7 @@ public class PCSClientTest extends RestClientTest { ContainerHandler.class); assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testGetFileInfo() throws SecurityException, NoSuchMethodException { @@ -154,7 +155,7 @@ public class PCSClientTest extends RestClientTest { FileHandler.class); assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowKeyNotFoundOn404.class); } @@ -224,7 +225,7 @@ public class PCSClientTest extends RestClientTest { assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null); assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnVoidOnNotFoundOr404.class); } @@ -242,7 +243,7 @@ public class PCSClientTest extends RestClientTest { assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/unknown")); assertEquals("bar", httpMethod.getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnVoidIf2xx.class); } @@ -257,7 +258,7 @@ public class PCSClientTest extends RestClientTest { assertEquals(httpMethod.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1"); assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), AddMetadataItemIntoMap.class); } diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java index 52fe153adb..3caa54c7e9 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java @@ -41,6 +41,7 @@ import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.mezeo.pcs2.xml.CloudXlinkHandler; import org.jclouds.rest.config.RestModule; +import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; @@ -71,7 +72,7 @@ public class PCSCloudTest { CloudXlinkHandler.class); assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } private RestAnnotationProcessor processor; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java index b535675de7..548c85d1a9 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java @@ -77,6 +77,7 @@ import org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions; import org.jclouds.rackspace.cloudservers.options.ListOptions; import org.jclouds.rackspace.cloudservers.options.RebuildServerOptions; import org.jclouds.rest.config.RestModule; +import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; @@ -182,7 +183,7 @@ public class CloudServersClientTest { .singletonList(MediaType.APPLICATION_JSON)); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseServerFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); assertNotNull(processor.getMapPayloadBinderOrNull(method, new Object[] { "", 1, 2, new CreateServerOptions[] { CreateServerOptions.Builder.withSharedIpGroup(1) } })); } @@ -196,7 +197,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getEndpoint().getPath(), "/images/2"); assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -215,7 +216,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseServerListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } Date now = new Date(); @@ -234,7 +235,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseServerListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListServersDetail() throws SecurityException, NoSuchMethodException { @@ -250,7 +251,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseServerListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testGetServer() throws SecurityException, NoSuchMethodException { @@ -265,7 +266,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseServerFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnServerNotFoundOn404.class); } @@ -282,7 +283,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseFlavorListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListFlavorsOptions() throws SecurityException, NoSuchMethodException { @@ -299,7 +300,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseFlavorListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListFlavorsDetail() throws SecurityException, NoSuchMethodException { @@ -315,7 +316,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseFlavorListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListFlavorsDetailOptions() throws SecurityException, NoSuchMethodException { @@ -332,7 +333,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseFlavorListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testGetFlavor() throws SecurityException, NoSuchMethodException { @@ -347,7 +348,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseFlavorFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFlavorNotFoundOn404.class); } @@ -364,7 +365,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseImageListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListImagesDetail() throws SecurityException, NoSuchMethodException { @@ -380,7 +381,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseImageListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListImagesOptions() throws SecurityException, NoSuchMethodException { @@ -397,7 +398,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseImageListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListImagesDetailOptions() throws SecurityException, NoSuchMethodException { @@ -414,7 +415,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseImageListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testGetImage() throws SecurityException, NoSuchMethodException { @@ -429,7 +430,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseImageFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnImageNotFoundOn404.class); } @@ -442,7 +443,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2"); assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -465,7 +466,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3}}", httpMethod.getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -489,7 +490,7 @@ public class CloudServersClientTest { .singletonList(MediaType.APPLICATION_JSON)); assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3,\"configureServer\":true}}", httpMethod .getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -506,7 +507,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1"); assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -530,7 +531,7 @@ public class CloudServersClientTest { .singletonList(MediaType.APPLICATION_JSON)); assertEquals(httpMethod.getPayload().getRawContent(), "{\"backupSchedule\":{\"daily\":\"H_0800_1000\",\"enabled\":true,\"weekly\":\"MONDAY\"}}"); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -545,7 +546,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule"); assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -567,7 +568,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); assertEquals("{\"server\":{\"adminPass\":\"foo\"}}", httpMethod.getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -589,7 +590,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); assertEquals("{\"server\":{\"name\":\"foo\"}}", httpMethod.getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -608,7 +609,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSharedIpGroupListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListSharedIpGroupsOptions() throws SecurityException, NoSuchMethodException { @@ -625,7 +626,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSharedIpGroupListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListSharedIpGroupsDetail() throws SecurityException, NoSuchMethodException { @@ -641,7 +642,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSharedIpGroupListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testListSharedIpGroupsDetailOptions() throws SecurityException, @@ -659,7 +660,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSharedIpGroupListFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); } public void testGetSharedIpGroup() throws SecurityException, NoSuchMethodException { @@ -674,7 +675,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSharedIpGroupFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnSharedIpGroupNotFoundOn404.class); } @@ -717,7 +718,7 @@ public class CloudServersClientTest { .singletonList(MediaType.APPLICATION_JSON)); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSharedIpGroupFromJsonResponse.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); assertNotNull(processor.getMapPayloadBinderOrNull(method, new Object[] { "", new CreateSharedIpGroupOptions[] { withServer(2) } })); } @@ -731,7 +732,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2"); assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -813,7 +814,7 @@ public class CloudServersClientTest { .singletonList(MediaType.APPLICATION_JSON)); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseImageFromJsonResponse.class); - assertNotNull(processor.createExceptionParserOrNullIfNotFound(method)); + assertNotNull(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method)); assertNotNull(processor.getMapPayloadBinderOrNull(method, new Object[] { "", 2 })); } @@ -852,7 +853,7 @@ public class CloudServersClientTest { + "")); assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -876,7 +877,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); assertEquals("{\"reboot\":{\"type\":\"HARD\"}}", httpMethod.getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -897,7 +898,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); assertEquals("{\"resize\":{\"flavorId\":3}}", httpMethod.getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -918,7 +919,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); assertEquals("{\"confirmResize\":null}", httpMethod.getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); @@ -938,7 +939,7 @@ public class CloudServersClientTest { assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); assertEquals("{\"revertResize\":null}", httpMethod.getPayload().getRawContent()); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(), + assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ReturnTrueIf2xx.class); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index 7bce52334b..32821118f1 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -31,6 +31,8 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import java.io.UnsupportedEncodingException; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.URI; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -44,6 +46,9 @@ import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.RequiresHttp; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.predicates.AddressReachable; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; import org.jclouds.util.Utils; @@ -65,7 +70,9 @@ import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; +import org.jclouds.vcloud.predicates.TaskSuccess; +import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; import com.google.inject.AbstractModule; @@ -80,6 +87,24 @@ import com.google.inject.Provides; @ConfiguresRestClient public class VCloudRestClientModule extends AbstractModule { + @Provides + @Singleton + protected Predicate socketTester(SocketOpen open) { + return new RetryablePredicate(open, 130, 10, TimeUnit.SECONDS); + } + + @Provides + @Singleton + protected Predicate addressTester(AddressReachable reachable) { + return new RetryablePredicate(reachable, 60, 5, TimeUnit.SECONDS); + } + + @Provides + @Singleton + protected Predicate successTester(TaskSuccess success) { + return new RetryablePredicate(success, 600, 10, TimeUnit.SECONDS); + } + @Override protected void configure() { } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TaskStatus.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TaskStatus.java index 34f6d6f465..ee81842eee 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TaskStatus.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TaskStatus.java @@ -29,7 +29,11 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Adrian Cole */ public enum TaskStatus { - SUCCESS, FAILED, RUNNING, QUEUED, ERROR, CANCELLED; + SUCCESS, FAILED, RUNNING, QUEUED, ERROR, CANCELLED, + /** + * invalid status, temporarily in. + */ + COMPLETED; public String value() { return name().toLowerCase(); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java index 3beffa50cc..5ff9af71ac 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java @@ -26,17 +26,13 @@ package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkArgument; import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.URI; import java.util.Map; import javax.annotation.Resource; import javax.inject.Inject; +import org.jclouds.compute.domain.Image; import org.jclouds.logging.Logger; -import org.jclouds.ssh.ExecResponse; -import org.jclouds.ssh.SshClient; -import org.jclouds.ssh.SshClient.Factory; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; @@ -54,56 +50,47 @@ public class VCloudComputeClient { @Resource protected Logger logger = Logger.NULL; - private final Predicate socketTester; - private final Predicate taskTester; + private final Predicate taskTester; private final VCloudClient tmClient; @Inject - public VCloudComputeClient(VCloudClient tmClient, Factory sshFactory, - Predicate socketTester, Predicate successTester) { + public VCloudComputeClient(VCloudClient tmClient, + Predicate successTester) { this.tmClient = tmClient; - this.sshFactory = sshFactory; - this.socketTester = socketTester; this.taskTester = successTester; } - private final Factory sshFactory; - - public enum Image { - CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS - } - private Map imageCatalogIdMap = ImmutableMap. builder().put( Image.CENTOS_53, "3").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put( Image.UMBUNTU_JEOS, "11").build(); - private String username; - - private String password; - - public String start(String name, int minCores, int minMegs, Image image) { + public Map start(String name, Image image, int minCores, int minMegs, + long diskSize, Map properties) { checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); String templateId = imageCatalogIdMap.get(image); String vDCId = tmClient.getDefaultVDC().getId(); - logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)", - name, minCores, minMegs, templateId, vDCId); - VApp vAppResponse = tmClient.instantiateVAppTemplateInVDC(name, templateId, vDCId, - InstantiateVAppTemplateOptions.Builder.processorCount(minCores).memory(minMegs)); - tmClient.getVApp(vAppResponse.getId()); + logger + .debug( + ">> instantiating vApp vDC(%s) name(%s) template(%s) minCores(%d) minMegs(%d) diskSize(%d) properties(%s) ", + vDCId, name, templateId, minCores, minMegs, diskSize, properties); + VApp vAppResponse = tmClient.instantiateVAppTemplateInVDC(vDCId, name, + templateId, InstantiateVAppTemplateOptions.Builder.processorCount(minCores) + .memory(minMegs).disk(diskSize).productProperties(properties)); logger.debug("<< instantiated VApp(%s)", vAppResponse.getId()); logger.debug(">> deploying vApp(%s)", vAppResponse.getId()); - VApp vApp = blockUntilVAppStatusOrThrowException(vAppResponse, tmClient - .deployVApp(vAppResponse.getId()), "deploy", VAppStatus.OFF); - logger.debug("<< deployed vApp(%s)", vApp.getId()); - - logger.debug(">> powering vApp(%s)", vApp.getId()); - vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOnVApp(vApp.getId()), - "powerOn", VAppStatus.ON); + .deployVApp(vAppResponse.getId()), "deploy", VAppStatus.ON);// TODO, I'm not sure + // this should be on + // already + // logger.debug("<< deployed vApp(%s)", vApp.getId()); + // + // logger.debug(">> powering vApp(%s)", vApp.getId()); + // vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOnVApp(vApp.getId()), + // "powerOn", VAppStatus.ON); logger.debug("<< on vApp(%s)", vApp.getId()); - return vApp.getId(); + return ImmutableMap. of("id", vApp.getId(), "username", null, "password", null); } /** @@ -116,14 +103,6 @@ public class VCloudComputeClient { return Iterables.getLast(vApp.getNetworkToAddresses().values()); } - public ExecResponse exec(InetAddress address, String command) { - InetSocketAddress sshSocket = new InetSocketAddress(address, 22); - logger.debug(">> exec ssh://%s@%s/%s", username, sshSocket, command); - ExecResponse exec = exec(sshSocket, username, password, command); - logger.debug("<< output(%s) error(%s)", exec.getOutput(), exec.getError()); - return exec; - } - public void reboot(String id) { VApp vApp = tmClient.getVApp(id); logger.debug(">> rebooting vApp(%s)", vApp.getId()); @@ -135,7 +114,8 @@ public class VCloudComputeClient { public void stop(String id) { VApp vApp = tmClient.getVApp(id); if (vApp.getStatus() != VAppStatus.OFF) { - logger.debug(">> powering off vApp(%s)", vApp.getId()); + logger.debug(">> powering off vApp(%s), current status: %s", vApp.getId(), vApp + .getStatus()); blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()), "powerOff", VAppStatus.OFF); logger.debug("<< off vApp(%s)", vApp.getId()); @@ -145,24 +125,9 @@ public class VCloudComputeClient { logger.debug("<< deleted vApp(%s)", vApp.getId()); } - private ExecResponse exec(InetSocketAddress socket, String username, String password, - String command) { - if (!socketTester.apply(socket)) { - throw new SocketNotOpenException(socket); - } - SshClient connection = sshFactory.create(socket, username, password); - try { - connection.connect(); - return connection.exec(command); - } finally { - if (connection != null) - connection.disconnect(); - } - } - private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType, VAppStatus expectedStatus) { - if (!taskTester.apply(deployTask.getLocation())) { + if (!taskTester.apply(deployTask.getId())) { throw new TaskException(taskType, vApp, deployTask); } @@ -192,23 +157,6 @@ public class VCloudComputeClient { } - public static class SocketNotOpenException extends RuntimeException { - - private final InetSocketAddress socket; - /** The serialVersionUID */ - private static final long serialVersionUID = 251801929573211256L; - - public SocketNotOpenException(InetSocketAddress socket) { - super("socket not open: " + socket); - this.socket = socket; - } - - public InetSocketAddress getSocket() { - return socket; - } - - } - public static class VAppException extends RuntimeException { private final VApp vApp; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java index 5b61ce2403..1b45eb9e91 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java @@ -28,41 +28,34 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.URI; import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.jclouds.compute.domain.Image; import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.predicates.AddressReachable; -import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.predicates.SocketOpen; import org.jclouds.ssh.jsch.config.JschSshClientModule; -import org.jclouds.vcloud.VCloudComputeClient.Image; import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; -import org.jclouds.vcloud.predicates.TaskSuccess; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.CaseFormat; import com.google.common.base.Predicate; -import com.google.inject.AbstractModule; import com.google.inject.Injector; import com.google.inject.Key; -import com.google.inject.Provides; import com.google.inject.TypeLiteral; import com.google.inject.internal.ImmutableMap; /** - * Tests behavior of {@code VCloudClient} + * Tests behavior of {@code HostingDotComVCloudClient} * * @author Adrian Cole */ -@Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest") +@Test(groups = "live", sequential = true, testName = "vcloud.HostingDotComVCloudClientLiveTest") public class VCloudComputeClientLiveTest { VCloudComputeClient client; VCloudClient tmClient; @@ -84,9 +77,9 @@ public class VCloudComputeClientLiveTest { private Map expectationMap = ImmutableMap. builder() .put(Image.CENTOS_53, - new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( + new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( Image.RHEL_53, - new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( + new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put( Image.UMBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build(); @@ -100,8 +93,10 @@ public class VCloudComputeClientLiveTest { String serverName = getCompatibleServerName(toTest); int processorCount = 1; int memory = 512; + long disk = 10 * 1025 * 1024; + Map properties = ImmutableMap.of("foo", "bar"); - id = client.start(serverName, processorCount, memory, toTest); + id = client.start(serverName, toTest, processorCount, memory, disk, properties).get("id"); Expectation expectation = expectationMap.get(toTest); VApp vApp = tmClient.getVApp(id); @@ -111,8 +106,9 @@ public class VCloudComputeClientLiveTest { } private String getCompatibleServerName(Image toTest) { - String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0, - toTest.toString().length() <= 15 ? toTest.toString().length() : 14); + String serverName = CaseFormat.UPPER_UNDERSCORE + .to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, + toTest.toString().length() <= 15 ? toTest.toString().length() : 14); return serverName; } @@ -122,16 +118,10 @@ public class VCloudComputeClientLiveTest { assert !addressTester.apply(privateAddress); } - @Test(dependsOnMethods = "testGetAnyPrivateAddress") - public void testSshLoadBalanceIp() { - // assert addressTester.apply(publicIp); - client.exec(privateAddress, "uname -a"); - } - private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, int processorCount, int memory, long hardDisk) { - assertEquals(vApp.getName(), serverName); - assertEquals(vApp.getOperatingSystemDescription(), expectedOs); + // assertEquals(vApp.getName(), serverName); + // assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR) .getVirtualQuantity(), processorCount); assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) @@ -151,39 +141,12 @@ public class VCloudComputeClientLiveTest { @BeforeGroups(groups = { "live" }) public void setupClient() { - String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), - "jclouds.test.endpoint"); + String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint"); String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); - Injector injector = new VCloudContextBuilder(new VCloudPropertiesBuilder( - URI.create(endpoint), account, key).relaxSSLHostname().build()).withModules( - new Log4JLoggingModule(), new JschSshClientModule(), new AbstractModule() { - - @Override - protected void configure() { - } - - @SuppressWarnings("unused") - @Provides - private Predicate socketTester(SocketOpen open) { - return new RetryablePredicate(open, 130, 10, - TimeUnit.SECONDS);// make it longer then - // default internet - } - - @SuppressWarnings("unused") - @Provides - private Predicate addressTester(AddressReachable reachable) { - return new RetryablePredicate(reachable, 60, 5, TimeUnit.SECONDS); - } - - @SuppressWarnings("unused") - @Provides - private Predicate successTester(TaskSuccess success) { - return new RetryablePredicate(success, 300, 10, TimeUnit.SECONDS); - } - - }).buildInjector(); + Injector injector = new VCloudContextBuilder( + new VCloudPropertiesBuilder(URI.create(endpoint), account, key).relaxSSLHostname().build()) + .withModules(new Log4JLoggingModule(), new JschSshClientModule()).buildInjector(); client = injector.getInstance(VCloudComputeClient.class); tmClient = injector.getInstance(VCloudClient.class); addressTester = injector.getInstance(Key.get(new TypeLiteral>() { diff --git a/vcloud/core/src/test/resources/vapp.xml b/vcloud/core/src/test/resources/vapp.xml new file mode 100644 index 0000000000..7154585cd8 --- /dev/null +++ b/vcloud/core/src/test/resources/vapp.xml @@ -0,0 +1,144 @@ + + + + + The kind of installed guest operating system + Other Linux (32-bit) + + + Virtual hardware + + + + + + + + + + + + + + Virtual Hardware Family + 0 + + + + + + SQL + vmx-07 + + + + + hertz * 10^6 + + + + + Number of Virtual CPUs + 1 virtual CPU(s) + 1 + + + + + + + + 3 + 1 + count + + + + + + byte * 2^20 + + + + + Memory Size + 16MB of memory + 2 + + + + + + + + 4 + 16 + byte * 2^20 + + + + 0 + + + + + + + SCSI Controller + SCSI Controller 0 + 3 + + + + + + + lsilogic + 6 + + + + + + 7 + true + Internal + PCNet32 ethernet adapter on "Internal" network + Network Adapter 1 + 8 + PCNet32 + 10 + + + + 0 + + + + + + + Hard Disk 1 + 104857 + 9 + + + + 3 + + + + 17 + 104857 + + + + + \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java index 53059bb5b4..72465f3113 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java @@ -23,18 +23,12 @@ */ package org.jclouds.vcloud.hostingdotcom.config; -import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.URI; -import java.util.concurrent.TimeUnit; import javax.inject.Singleton; import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.http.RequiresHttp; -import org.jclouds.predicates.AddressReachable; -import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; import org.jclouds.vcloud.VCloudAsyncClient; @@ -42,9 +36,7 @@ import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudAsyncClient; import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient; -import org.jclouds.vcloud.predicates.TaskSuccess; -import com.google.common.base.Predicate; import com.google.inject.Provides; /** @@ -55,23 +47,6 @@ import com.google.inject.Provides; @RequiresHttp @ConfiguresRestClient public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule { - @Provides - @Singleton - protected Predicate socketTester(SocketOpen open) { - return new RetryablePredicate(open, 130, 10, TimeUnit.SECONDS); - } - - @Provides - @Singleton - protected Predicate addressTester(AddressReachable reachable) { - return new RetryablePredicate(reachable, 60, 5, TimeUnit.SECONDS); - } - - @Provides - @Singleton - protected Predicate successTester(TaskSuccess success) { - return new RetryablePredicate(success, 600, 10, TimeUnit.SECONDS); - } @Provides @Singleton diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java index d2f1e517b1..c07916c601 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java @@ -24,29 +24,21 @@ package org.jclouds.vcloud.terremark.config; import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.concurrent.TimeUnit; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.http.RequiresHttp; -import org.jclouds.predicates.AddressReachable; -import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.config.VCloudRestClientModule; -import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; -import com.google.common.base.Predicate; import com.google.inject.Provides; /** @@ -57,26 +49,6 @@ import com.google.inject.Provides; @RequiresHttp @ConfiguresRestClient public class TerremarkVCloudRestClientModule extends VCloudRestClientModule { - @Provides - @Singleton - protected Predicate socketTester(SocketOpen open) { - return new RetryablePredicate(open, 130, 10, TimeUnit.SECONDS);// make it - // longer - // then - // default internet - } - - @Provides - @Singleton - protected Predicate addressTester(AddressReachable reachable) { - return new RetryablePredicate(reachable, 60, 5, TimeUnit.SECONDS); - } - - @Provides - @Singleton - protected Predicate successTester(TaskSuccess success) { - return new RetryablePredicate(success, 600, 10, TimeUnit.SECONDS); - } @Provides @Singleton