From 7c1f20ba84c80ca25bef68f7d4ecc687e6a61245 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 6 Nov 2010 10:51:49 +0100 Subject: [PATCH 01/21] back-filled unit test --- .../jclouds/http/functions/ParseSaxTest.java | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 core/src/test/java/org/jclouds/http/functions/ParseSaxTest.java diff --git a/core/src/test/java/org/jclouds/http/functions/ParseSaxTest.java b/core/src/test/java/org/jclouds/http/functions/ParseSaxTest.java new file mode 100644 index 0000000000..c1df2737f9 --- /dev/null +++ b/core/src/test/java/org/jclouds/http/functions/ParseSaxTest.java @@ -0,0 +1,141 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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 static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; +import org.xml.sax.Locator; +import org.xml.sax.SAXParseException; + +public class ParseSaxTest extends BaseHandlerTest { + public static class TestHandler extends ParseSax.HandlerWithResult { + @Override + public String getResult() { + return ""; + } + } + + ParseSax createParser() { + return factory.create(injector.getInstance(TestHandler.class)); + } + + @Test + public void testAddDetailsAndPropagateOkWhenRequestWithNoDataAndRuntimeExceptionThrowsOriginalException() + throws ExecutionException, InterruptedException, TimeoutException, IOException { + + ParseSax parser = createParser(); + Exception input = new RuntimeException("foo"); + + try { + parser.addDetailsAndPropagate(null, input); + } catch (RuntimeException e) { + assertEquals(e, input); + } + } + + @Test + public void testAddDetailsAndPropagateOkWhenRequestWithNoDataAndExceptionPropagates() throws ExecutionException, + InterruptedException, TimeoutException, IOException { + + ParseSax parser = createParser(); + Exception input = new Exception("foo"); + + try { + parser.addDetailsAndPropagate(null, input); + } catch (RuntimeException e) { + assertEquals(e.getMessage(), "java.lang.Exception: foo"); + assertEquals(e.getCause(), input); + } + } + + @Test + public void testAddDetailsAndPropagateOkWhenRequestIsNotNullAndResponseIsNull() throws ExecutionException, + InterruptedException, TimeoutException, IOException { + + ParseSax parser = createParser(); + HttpRequest request = new HttpRequest("GET", URI.create("http://foohost")); + Exception input = new Exception("foo"); + + try { + parser.setContext(request); + parser.addDetailsAndPropagate(null, input); + } catch (RuntimeException e) { + assertEquals(e.getMessage(), "request: GET http://foohost HTTP/1.1; cause: java.lang.Exception: foo"); + assertEquals(e.getCause(), input); + } + } + + @Test + public void testAddDetailsAndPropagateOkWithValidRequestResponse() throws ExecutionException, InterruptedException, + TimeoutException, IOException { + + ParseSax parser = createParser(); + HttpRequest request = new HttpRequest("GET", URI.create("http://foohost")); + HttpResponse response = new HttpResponse(304, "Not Modified", null); + Exception input = new Exception("foo"); + + try { + parser.setContext(request); + parser.addDetailsAndPropagate(response, input); + } catch (RuntimeException e) { + assertEquals(e.getMessage(), "request: GET http://foohost HTTP/1.1; response: HTTP/1.1 304 Not Modified; cause: java.lang.Exception: foo"); + assertEquals(e.getCause(), input); + } + } + + @Test + public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException() throws ExecutionException, + InterruptedException, TimeoutException, IOException { + + ParseSax parser = createParser(); + HttpRequest request = new HttpRequest("GET", URI.create("http://foohost")); + HttpResponse response = new HttpResponse(304, "Not Modified", null); + Locator locator = createMock(Locator.class); + expect(locator.getColumnNumber()).andReturn(1); + expect(locator.getLineNumber()).andReturn(1); + expect(locator.getPublicId()).andReturn("publicId"); + expect(locator.getSystemId()).andReturn("systemId"); + replay(locator); + Exception input = new SAXParseException("foo", locator); + verify(locator); + + try { + parser.setContext(request); + parser.addDetailsAndPropagate(response, input); + } catch (RuntimeException e) { + assertEquals(e.getMessage(), + "request: GET http://foohost HTTP/1.1; response: HTTP/1.1 304 Not Modified; error at 1:1 in document systemId; cause: org.xml.sax.SAXParseException: foo"); + assertEquals(e.getCause(), input); + } + } + +} \ No newline at end of file From 87127bbc6482bc97fdf7f36971ee4f8ae88c5140 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:34:09 +0100 Subject: [PATCH 02/21] fixed so that eucalyptus does not attempt placement group commands --- .../aws/ec2/compute/EC2ComputeService.java | 70 +++++++++++-------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java index 79584776ce..681b81acc3 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java @@ -24,8 +24,8 @@ import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle; import static org.jclouds.util.Utils.checkNotEmpty; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.ExecutorService; import javax.inject.Inject; @@ -55,12 +55,13 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.util.ComputeUtils; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; +import org.jclouds.http.HttpResponseException; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; @@ -80,23 +81,23 @@ public class EC2ComputeService extends BaseComputeService { @Inject protected EC2ComputeService(ComputeServiceContext context, Map credentialStore, - @Memoized Supplier> images, @Memoized Supplier> sizes, - @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, - GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, - RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, - ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy, - Provider templateBuilderProvider, Provider templateOptionsProvider, - @Named("NODE_RUNNING") Predicate nodeRunning, - @Named("NODE_TERMINATED") Predicate nodeTerminated, - @Named("NODE_SUSPENDED") Predicate nodeSuspended, ComputeUtils utils, Timeouts timeouts, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client, - Map credentialsMap, @Named("SECURITY") Map securityGroupMap, - @Named("PLACEMENT") Map placementGroupMap, - @Named("DELETED") Predicate placementGroupDeleted) { + @Memoized Supplier> images, @Memoized Supplier> sizes, + @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, + GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, + RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, + ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy, + Provider templateBuilderProvider, Provider templateOptionsProvider, + @Named("NODE_RUNNING") Predicate nodeRunning, + @Named("NODE_TERMINATED") Predicate nodeTerminated, + @Named("NODE_SUSPENDED") Predicate nodeSuspended, ComputeUtils utils, Timeouts timeouts, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client, + Map credentialsMap, @Named("SECURITY") Map securityGroupMap, + @Named("PLACEMENT") Map placementGroupMap, + @Named("DELETED") Predicate placementGroupDeleted) { super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, - runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy, - stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, - nodeSuspended, utils, timeouts, executor); + runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy, stopNodeStrategy, + templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, nodeSuspended, utils, + timeouts, executor); this.ec2Client = ec2Client; this.credentialsMap = credentialsMap; this.securityGroupMap = securityGroupMap; @@ -108,21 +109,28 @@ public class EC2ComputeService extends BaseComputeService { void deletePlacementGroup(String region, String tag) { checkNotEmpty(tag, "tag"); String group = String.format("jclouds#%s#%s", tag, region); - if (ec2Client.getPlacementGroupServices().describePlacementGroupsInRegion(region, group).size() > 0) { - logger.debug(">> deleting placementGroup(%s)", group); - try { - ec2Client.getPlacementGroupServices().deletePlacementGroupInRegion(region, group); - checkState(placementGroupDeleted.apply(new PlacementGroup(region, group, "cluster", State.PENDING)), String - .format("placementGroup region(%s) name(%s) failed to delete", region, group)); - placementGroupMap.remove(new RegionAndName(region, tag)); - logger.debug("<< deleted placementGroup(%s)", group); - } catch (AWSResponseException e) { - if (e.getError().getCode().equals("InvalidPlacementGroup.InUse")) { - logger.debug("<< inUse placementGroup(%s)", group); - } else { - throw e; + try { + if (ec2Client.getPlacementGroupServices().describePlacementGroupsInRegion(region, group).size() > 0) { + logger.debug(">> deleting placementGroup(%s)", group); + try { + ec2Client.getPlacementGroupServices().deletePlacementGroupInRegion(region, group); + checkState(placementGroupDeleted.apply(new PlacementGroup(region, group, "cluster", State.PENDING)), + String.format("placementGroup region(%s) name(%s) failed to delete", region, group)); + placementGroupMap.remove(new RegionAndName(region, tag)); + logger.debug("<< deleted placementGroup(%s)", group); + } catch (AWSResponseException e) { + if (e.getError().getCode().equals("InvalidPlacementGroup.InUse")) { + logger.debug("<< inUse placementGroup(%s)", group); + } else { + throw e; + } } } + } catch (HttpResponseException e) { + // Eucalyptus does not support placement groups yet. + if (!(e.getResponse().getStatusCode() == 400 && context.getProviderSpecificContext().getProvider() + .equals("eucalyptus"))) + throw e; } } From c253c1b77d8c314ca6417a00ca513bc09096ea05 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:44:46 +0100 Subject: [PATCH 03/21] fixed accidental chunked encoding on 0 length puts --- .../http/internal/JavaUrlHttpCommandExecutorService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index 47bad3d042..58d016fe1b 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -227,7 +227,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, "0"); // for some reason POST/PUT undoes the content length header above. if (connection.getRequestMethod().equals("POST") || connection.getRequestMethod().equals("PUT")) - connection.setChunkedStreamingMode(0); + connection.setFixedLengthStreamingMode(0); } return connection; From 8036bf08f04c56dab04abe469acda95e2698cf60 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:45:40 +0100 Subject: [PATCH 04/21] improved error response code to include url encoded params which makes ec2 a lot easier to debug --- .../jclouds/http/HttpResponseException.java | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/jclouds/http/HttpResponseException.java b/core/src/main/java/org/jclouds/http/HttpResponseException.java index f7e035657a..d938a8e2a9 100644 --- a/core/src/main/java/org/jclouds/http/HttpResponseException.java +++ b/core/src/main/java/org/jclouds/http/HttpResponseException.java @@ -19,8 +19,13 @@ package org.jclouds.http; +import java.io.IOException; + import javax.annotation.Nullable; +import org.jclouds.io.payloads.StringPayload; +import org.jclouds.util.Utils; + /** * Represents an error obtained from an HttpResponse. * @@ -34,15 +39,14 @@ public class HttpResponseException extends RuntimeException { protected final HttpResponse response; private String content; - public HttpResponseException(String message, HttpCommand command, - @Nullable HttpResponse response, Throwable cause) { + public HttpResponseException(String message, HttpCommand command, @Nullable HttpResponse response, Throwable cause) { super(message, cause); this.command = command; this.response = response; } - public HttpResponseException(String message, HttpCommand command, - @Nullable HttpResponse response, String content, Throwable cause) { + public HttpResponseException(String message, HttpCommand command, @Nullable HttpResponse response, String content, + Throwable cause) { super(message, cause); this.command = command; this.response = response; @@ -50,15 +54,13 @@ public class HttpResponseException extends RuntimeException { } public HttpResponseException(HttpCommand command, HttpResponse response, Throwable cause) { - this(String.format("command: %1$s failed with response: %2$s", command.getRequest() - .getRequestLine(), response.getStatusLine()), command, response, cause); + this(String.format("command: %1$s failed with response: %2$s", command.getRequest().getRequestLine(), + response.getStatusLine()), command, response, cause); } - public HttpResponseException(HttpCommand command, HttpResponse response, String content, - Throwable cause) { - this(String.format("command: %1$s failed with response: %2$s; content: [%3$s]", command - .getRequest().getRequestLine(), response.getStatusLine()), command, response, - content, cause); + public HttpResponseException(HttpCommand command, HttpResponse response, String content, Throwable cause) { + this(String.format("command: %1$s failed with response: %2$s; content: [%3$s]", command.getRequest() + .getRequestLine(), response.getStatusLine()), command, response, content, cause); } public HttpResponseException(String message, HttpCommand command, @Nullable HttpResponse response) { @@ -67,8 +69,7 @@ public class HttpResponseException extends RuntimeException { this.response = response; } - public HttpResponseException(String message, HttpCommand command, - @Nullable HttpResponse response, String content) { + public HttpResponseException(String message, HttpCommand command, @Nullable HttpResponse response, String content) { super(message); this.command = command; this.response = response; @@ -76,14 +77,29 @@ public class HttpResponseException extends RuntimeException { } public HttpResponseException(HttpCommand command, HttpResponse response) { - this(String.format("command: %1$s failed with response: %2$s", command.getRequest() - .getRequestLine(), response.getStatusLine()), command, response); + this(String.format("request: %s %sfailed with response: %s", command.getRequest().getRequestLine(), + requestPayloadIfStringOrFormIfNotReturnEmptyString(command.getRequest()), response.getStatusLine()), + command, response); + } + + static String requestPayloadIfStringOrFormIfNotReturnEmptyString(HttpRequest request) { + if (request.getPayload() != null + && ("application/x-www-form-urlencoded".equals(request.getPayload().getContentMetadata().getContentType()) || request + .getPayload() instanceof StringPayload) + && request.getPayload().getContentMetadata().getContentLength() != null + && request.getPayload().getContentMetadata().getContentLength() < 1024) { + try { + return String.format(" [%s] ", request.getPayload() instanceof StringPayload ? request.getPayload() + .getRawContent() : Utils.toStringAndClose(request.getPayload().getInput())); + } catch (IOException e) { + } + } + return ""; } public HttpResponseException(HttpCommand command, HttpResponse response, String content) { - this(String.format("command: %1$s failed with response: %2$s; content: [%3$s]", command - .getRequest().getRequestLine(), response.getStatusLine(), content), command, - response, content); + this(String.format("command: %s failed with response: %s; content: [%s]", command.getRequest().getRequestLine(), + response.getStatusLine(), content), command, response, content); } public HttpCommand getCommand() { From 4850127902a8c0ed132068585c054e6d055a21f1 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:48:25 +0100 Subject: [PATCH 05/21] terremak ecloud api doesn't support deleting public ip addresses --- .../vcloud/terremark/compute/TerremarkVCloudComputeClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index a812be12d8..d2d6658990 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -217,7 +217,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl try { client.deletePublicIp(address.getId()); logger.debug("<< deleted PublicIpAddress(%s)", address.getId()); - } catch (UnsupportedOperationException e) { + } catch (Exception e) { logger.trace("cannot delete PublicIpAddress(%s) as it is unsupported", address.getId()); } continue IPADDRESS; From 02d1ec664e9798f805272cf4e7c5bb40db433a6d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:49:17 +0100 Subject: [PATCH 06/21] non-ec2 clones allow m1 small to run 64bit images --- .../jclouds/aws/ec2/compute/suppliers/EC2HardwareSupplier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2HardwareSupplier.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2HardwareSupplier.java index 36dc9d2552..4a06e5c855 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2HardwareSupplier.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2HardwareSupplier.java @@ -90,7 +90,7 @@ public class EC2HardwareSupplier implements Supplier> { sizes.add(cc1_4xlarge().location(location).supportsImageIds(ccAmi).build()); } sizes.addAll(ImmutableSet. of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large() - .build(), "nova".equals(providerName) ? m1_small().supportsImage(any()).build() : m1_small().build(), + .build(), !"ec2".equals(providerName) ? m1_small().supportsImage(any()).build() : m1_small().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), m2_4xlarge().build())); return sizes; } From 8849e2793a9aa4a460622526e4dd4e32b037ee84 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:50:07 +0100 Subject: [PATCH 07/21] refactored aws error handler to provide the http content even when it isn't parsable (ex. returned in html --- .../handlers/ParseAWSErrorFromXmlContent.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java b/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java index 1ecc0d1fcc..b7af9095f3 100755 --- a/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java +++ b/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java @@ -66,14 +66,13 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler { public void handleError(HttpCommand command, HttpResponse response) { HttpRequest request = command.getRequest(); - Exception exception = new HttpResponseException(command, response); + Exception exception = null; try { AWSError error = null; String message = null; if (response.getPayload() != null) { String contentType = response.getPayload().getContentMetadata().getContentType(); - if (contentType != null - && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) { + if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) { error = utils.parseAWSErrorFromContent(request, response); if (error != null) { message = error.getMessage(); @@ -86,36 +85,37 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler { } } } - message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response - .getStatusLine()); + message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), + response.getStatusLine()); + if (exception == null) + exception = new HttpResponseException(command, response, message); switch (response.getStatusCode()) { - case 400: - if (error != null && error.getCode() != null - && (error.getCode().endsWith(".NotFound") || error.getCode().endsWith(".Unknown"))) - exception = new ResourceNotFoundException(message, exception); - else if ((error != null && error.getCode() != null && (error.getCode().equals("IncorrectState") || error - .getCode().endsWith(".Duplicate"))) - || (message != null && message.indexOf("already exists") != -1)) - exception = new IllegalStateException(message, exception); - else if (error != null && error.getCode() != null && error.getCode().equals("AuthFailure")) - exception = new AuthorizationException(command.getRequest(), message); - else if (message != null && message.indexOf("Failed to bind the following fields") != -1)// Nova - exception = new IllegalArgumentException(message, exception); - break; - case 401: - case 403: + case 400: + if (error != null && error.getCode() != null + && (error.getCode().endsWith(".NotFound") || error.getCode().endsWith(".Unknown"))) + exception = new ResourceNotFoundException(message, exception); + else if ((error != null && error.getCode() != null && (error.getCode().equals("IncorrectState") || error + .getCode().endsWith(".Duplicate"))) || (message != null && message.indexOf("already exists") != -1)) + exception = new IllegalStateException(message, exception); + else if (error != null && error.getCode() != null && error.getCode().equals("AuthFailure")) exception = new AuthorizationException(command.getRequest(), message); - break; - case 404: - if (!command.getRequest().getMethod().equals("DELETE")) { - String container = request.getEndpoint().getHost(); - String key = request.getEndpoint().getPath(); - if (key == null || key.equals("/")) - exception = new ContainerNotFoundException(container, message); - else - exception = new KeyNotFoundException(container, key, message); - } - break; + else if (message != null && message.indexOf("Failed to bind the following fields") != -1)// Nova + exception = new IllegalArgumentException(message, exception); + break; + case 401: + case 403: + exception = new AuthorizationException(command.getRequest(), message); + break; + case 404: + if (!command.getRequest().getMethod().equals("DELETE")) { + String container = request.getEndpoint().getHost(); + String key = request.getEndpoint().getPath(); + if (key == null || key.equals("/")) + exception = new ContainerNotFoundException(container, message); + else + exception = new KeyNotFoundException(container, key, message); + } + break; } } finally { releasePayload(response); From d94ca199410d6e466a74e6684a333736c297f320 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:57:17 +0100 Subject: [PATCH 08/21] Issue 397: updated default image to 64bit ubuntu 10.04, noting ecloud, eucalyptus, and gogrid only have working centos images, trmk-vcloudexpress doesn't have 10.4, vcloud doesn't have the ability to natively lookup versions, and amazon linux is preferred on ec2. --- .../EC2ComputeServiceContextModule.java | 11 +++++----- .../BaseComputeServiceContextModule.java | 2 +- .../config/StubComputeServiceAdapter.java | 7 +++++-- ...oudServersComputeServiceContextModule.java | 9 -------- .../CloudServersComputeServiceLiveTest.java | 21 +++++++++++++++++-- ...imuHostingComputeServiceContextModule.java | 5 +---- .../RimuHostingComputeServiceLiveTest.java | 2 +- .../SlicehostComputeServiceContextModule.java | 9 -------- .../SlicehostComputeServiceLiveTest.java | 2 +- .../VCloudComputeServiceContextModule.java | 11 +++++++++- ...markECloudComputeServiceContextModule.java | 6 +++++- ...markVCloudComputeServiceContextModule.java | 12 ++++++++++- .../terremark/TerremarkClientLiveTest.java | 8 +++---- ...TerremarkECloudComputeServiceLiveTest.java | 4 ++-- ...kVCloudExpressTemplateBuilderLiveTest.java | 2 +- 15 files changed, 66 insertions(+), 45 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index 7d8fde80ad..b5e76743b1 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -22,7 +22,6 @@ package org.jclouds.aws.ec2.compute.config; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX; import static org.jclouds.compute.domain.OsFamily.CENTOS; -import static org.jclouds.compute.domain.OsFamily.UBUNTU; import java.util.Map; @@ -65,12 +64,12 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { String provider = injector.getInstance(Key.get(String.class, Provider.class)); - if ("eucalyptus".equals(provider)) - return template.osFamily(CENTOS); - else if ("nova".equals(provider)) - return template.osFamily(UBUNTU); - else + if ("ec2".equals(provider)) return template.osFamily(AMZN_LINUX).os64Bit(true); + else if ("nova".equals(provider)) + return super.provideTemplate(injector, template); + else + return template.osFamily(CENTOS); } @Provides diff --git a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java index 5eb304e647..340014c60e 100644 --- a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java @@ -76,7 +76,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Provides @Named("DEFAULT") protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return template.osFamily(UBUNTU); + return template.osFamily(UBUNTU).osVersionMatches("10.04.*").os64Bit(true); } /** diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java index 2d8066c3f7..1176cf9025 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java @@ -120,8 +120,11 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda new ImageBuilder().providerId("3").name(OsFamily.CENTOS.name()).id(parentId + "/3").location(zone) .operatingSystem( new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true)) - .description("stub centos 64").defaultCredentials(defaultCredentials).build() // - + .description("stub centos 64").defaultCredentials(defaultCredentials).build(), // + new ImageBuilder().providerId("4").name(OsFamily.UBUNTU.name()).id(parentId + "/4").location(zone) + .operatingSystem( + new OperatingSystem(OsFamily.UBUNTU, "ubuntu 10.04 64", "10.04", "X86_64", "ubuntu 10.04 64", true)) + .description("stub ubuntu 10.04 64").defaultCredentials(defaultCredentials).build() // ); } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index 96e02eb531..91be884115 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -19,14 +19,9 @@ package org.jclouds.rackspace.cloudservers.compute.config; -import static org.jclouds.compute.domain.OsFamily.UBUNTU; - import org.jclouds.compute.config.BaseComputeServiceContextModule; -import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; -import com.google.inject.Injector; - /** * Configures the {@link CloudServersComputeServiceContext}; requires {@link BaseComputeService} * bound. @@ -43,8 +38,4 @@ public class CloudServersComputeServiceContextModule extends BaseComputeServiceC super.configure(); } - @Override - protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return template.osFamily(UBUNTU).imageNameMatches(".*10\\.?04.*"); - } } diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java index 6c669adf78..ad757b5826 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -52,7 +52,7 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); @@ -66,7 +66,7 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + .createContext(provider, identity, credential).getProviderSpecificContext(); } @Override @@ -82,4 +82,21 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe super.testSuspendResume(); } + @Test(enabled = true, dependsOnMethods = "testSuspendResume") + @Override + public void testGetNodesWithDetails() throws Exception { + super.testGetNodesWithDetails(); + } + + @Test(enabled = true, dependsOnMethods = "testSuspendResume") + @Override + public void testListNodes() throws Exception { + super.testListNodes(); + } + + @Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails" }) + @Override + public void testDestroyNodes() { + super.testDestroyNodes(); + } } \ No newline at end of file diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index 5421e5511f..f123e0aa27 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -19,9 +19,6 @@ package org.jclouds.rimuhosting.miro.compute.config; -import static org.jclouds.compute.domain.OsFamily.UBUNTU; - - import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.TemplateBuilder; @@ -45,7 +42,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return template.hardwareId("MIRO1B").osFamily(UBUNTU).os64Bit(false).osVersionMatches("9.10"); + return super.provideTemplate(injector, template).hardwareId("MIRO1B"); } } diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java index 2116ea9e87..5ad905a914 100755 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java @@ -48,7 +48,7 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS"); assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO1B"); diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java index 15ff8b0d15..ca21e49616 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java @@ -19,14 +19,11 @@ package org.jclouds.slicehost.compute.config; -import static org.jclouds.compute.domain.OsFamily.UBUNTU; - import java.util.Set; import javax.inject.Singleton; import org.jclouds.compute.config.BaseComputeServiceContextModule; -import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; @@ -34,7 +31,6 @@ import org.jclouds.domain.internal.LocationImpl; import org.jclouds.rest.annotations.Provider; import com.google.common.collect.ImmutableSet; -import com.google.inject.Injector; import com.google.inject.Provides; /** @@ -51,11 +47,6 @@ public class SlicehostComputeServiceContextModule extends BaseComputeServiceCont return new LocationImpl(LocationScope.ZONE, "DFW1", "Dallas, TX", provider); } - @Override - protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return template.osFamily(UBUNTU).os64Bit(true); - } - @Provides @Singleton Set provideLocations(Location location) { diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java index 05ebe60d0b..83e5b14e28 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java @@ -48,7 +48,7 @@ public class SlicehostComputeServiceLiveTest extends BaseComputeServiceLiveTest public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); assertEquals(getCores(defaultTemplate.getHardware()), 0.25d); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index 16a2ba0a81..8d9ba099b6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -20,6 +20,8 @@ package org.jclouds.vcloud.compute.config; +import static org.jclouds.compute.domain.OsFamily.UBUNTU; + import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeSuppliersByClass; @@ -44,6 +46,7 @@ import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.VApp; import com.google.common.base.Function; +import com.google.inject.Injector; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; @@ -79,7 +82,13 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic }); bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(GetLoginCredentialsFromGuestConfiguration.class); } - + + //CIM ostype does not include version info + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + return template.osFamily(UBUNTU).os64Bit(true); + } + @Override public BindComputeStrategiesByClass defineComputeStrategyModule() { return new VCloudBindComputeStrategiesByClass(); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkECloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkECloudComputeServiceContextModule.java index 017c798f46..1afcc45c64 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkECloudComputeServiceContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkECloudComputeServiceContextModule.java @@ -29,7 +29,11 @@ import com.google.inject.Injector; * @author Adrian Cole */ public class TerremarkECloudComputeServiceContextModule extends TerremarkVCloudComputeServiceContextModule { + + // as of 6-nov-2010 only centos has ssh key injection in the images. + // ssh key injection in ubuntu is targeted for dec-2010 or sooner + @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return template.osFamily(CENTOS); + return template.osFamily(CENTOS).os64Bit(true); } } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java index 0d84ab905c..3f8397589b 100755 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -19,6 +19,8 @@ package org.jclouds.vcloud.terremark.compute.config; +import static org.jclouds.compute.domain.OsFamily.UBUNTU; + import java.security.SecureRandom; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -30,6 +32,7 @@ import org.jclouds.compute.ComputeService; import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeSuppliersByClass; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.vcloud.compute.VCloudExpressComputeClient; @@ -46,6 +49,7 @@ import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptio import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.inject.Injector; import com.google.inject.Provides; import com.google.inject.TypeLiteral; @@ -69,6 +73,12 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressCom } + // prefer jeos as the copy time is much shorter + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + return template.osFamily(UBUNTU).osDescriptionMatches(".*JeOS.*").os64Bit(true); + } + @Override protected void configure() { super.configure(); @@ -79,7 +89,7 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressCom bind(ComputeService.class).to(TerremarkVCloudComputeService.class); bind(VCloudExpressComputeClient.class).to(TerremarkVCloudComputeClient.class); bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to( - ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.class); + ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.class); bind(SecureRandom.class).toInstance(new SecureRandom()); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java index 87b66edba2..738ba14e27 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java @@ -90,8 +90,8 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes super.testCatalog(); } - protected String expectedOs = "Ubuntu Linux (32-bit)"; - protected String itemName = "Ubuntu JeOS 9.10 (32-bit)"; + protected String expectedOs = "Ubuntu Linux (64-bit)"; + protected String itemName = "Ubuntu JeOS 9.10 (64-bit)"; protected TerremarkVCloudClient tmClient; protected Factory sshFactory; @@ -154,8 +154,8 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes long hardDisk = 4194304; // long hardDisk = 4194304 / 4 * 10; - // String catalogOs = "CentOS 5.3 (32-bit)"; - // String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)"; + // String catalogOs = "CentOS 5.3 (64-bit)"; + // String expectedOs = "Red Hat Enterprise Linux 5 (64-bit)"; // lookup the datacenter you are deploying into vdc = tmClient.findVDCInOrgNamed(null, null); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java index 3be000c4c8..c4281629c2 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java @@ -59,8 +59,8 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.5"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assert defaultTemplate.getLocation().getDescription() != null;// different per org assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java index e138e298d2..58f5bf3d31 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java @@ -99,7 +99,7 @@ public class TerremarkVCloudExpressTemplateBuilderLiveTest { . of(new Log4JLoggingModule()), setupProperties()); Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), null); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); From fff4ca4896c11b799ea9bba23ae3c469a953281b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:58:07 +0100 Subject: [PATCH 09/21] updated test in step with vmware tools --- .../VCloudGuestCustomizationLiveTest.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudGuestCustomizationLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudGuestCustomizationLiveTest.java index 443f6d7f08..2e76103f72 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudGuestCustomizationLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudGuestCustomizationLiveTest.java @@ -73,11 +73,9 @@ public class VCloudGuestCustomizationLiveTest { protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); - endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); - apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); } protected Properties setupProperties() { @@ -85,9 +83,12 @@ public class VCloudGuestCustomizationLiveTest { overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".apiversion", apiversion); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); return overrides; } @@ -97,7 +98,7 @@ public class VCloudGuestCustomizationLiveTest { Properties overrides = setupProperties(); client = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getComputeService(); + ImmutableSet. of(new Log4JLoggingModule()), overrides).getComputeService(); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 60, 1, TimeUnit.SECONDS); sshFactory = Guice.createInjector(getSshModule()).getInstance(Factory.class); } @@ -128,7 +129,7 @@ public class VCloudGuestCustomizationLiveTest { try { ssh.connect(); - assertEquals(ssh.exec(PARSE_VMTOOLSD).getOutput(), script); + assertEquals(ssh.exec(PARSE_VMTOOLSD).getOutput(), script.replaceAll("\n", "\r\n")); assertEquals(ssh.exec("cat /root/foo.txt").getOutput().trim(), "I love candy"); } finally { From f4b0ce9b7dd5f2796978be1ffd07a0eb27b1f522 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 01:58:45 +0100 Subject: [PATCH 10/21] test download of maven 3 beta 3 is no longer on the website --- .../jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/core/src/test/java/org/jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java index 5f68fbf41c..3a1ae08dff 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java @@ -93,7 +93,7 @@ public class ComputeAndBlobStoreTogetherHappilyLiveTest extends BlobStoreAndComp Statement installOpenJDK = execHttpResponse(signedRequestOfInstallScript); // if we want to, we can mix and match batched and ad-hoc commands, such as extracting maven - String mavenVersion = "3.0-beta-3"; + String mavenVersion = "3.0"; Statement extractMavenIntoUsrLocal = extractTargzIntoDirectory( URI.create("http://mirrors.ibiblio.org/pub/mirrors/apache//maven/binaries/apache-maven-" + mavenVersion + "-bin.tar.gz"), "/usr/local"); From 044ffc85638a318ac694bd8b5d9491b68503ef96 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 02:01:15 +0100 Subject: [PATCH 11/21] fixed broked live tests --- .../compute/EC2TemplateBuilderLiveTest.java | 2 +- .../EucalyptusComputeServiceLiveTest.java | 6 +++ .../aws/ec2/services/AMIClientLiveTest.java | 21 ++++---- ...ailabilityZoneAndRegionClientLiveTest.java | 39 +++++++------- .../ElasticBlockStoreClientLiveTest.java | 51 +++++++++---------- .../PlacementGroupClientLiveTest.java | 39 ++++++++------ aws/core/src/test/resources/log4j.xml | 2 - rackspace/src/test/resources/log4j.xml | 2 + .../SlicehostComputeServiceLiveTest.java | 25 ++++++++- .../compute/VCloudComputeServiceLiveTest.java | 11 ++++ 10 files changed, 123 insertions(+), 75 deletions(-) diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java index da449863fa..a7e0022cc5 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java @@ -89,7 +89,7 @@ public class EC2TemplateBuilderLiveTest { assertEquals(template.getImage().getOperatingSystem().getVersion(), "10.10"); assertEquals(template.getImage().getOperatingSystem().is64Bit(), false); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); - assertEquals(template.getImage().getVersion(), "20101027"); + assertEquals(template.getImage().getVersion(), "20101106"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(getCores(template.getHardware()), 1.0d); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java index 48bea286b2..da51847a03 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java @@ -45,6 +45,12 @@ public class EucalyptusComputeServiceLiveTest extends EC2ComputeServiceLiveTest tag = "euc"; } + @Override + @Test(enabled = false) + public void testExtendedOptionsAndLogin() throws Exception { + // euc does not support monitoring + } + @Override protected void assertDefaultWorks() { Template defaultTemplate = client.templateBuilder().build(); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java index 0012e32267..673ef2b69b 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java @@ -36,12 +36,13 @@ import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.domain.Image; -import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.Image.ImageType; +import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -74,13 +75,12 @@ public class AMIClientLiveTest { protected String endpoint; protected String apiversion; + @BeforeClass protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); - endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); - apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); } protected Properties setupProperties() { @@ -88,9 +88,12 @@ public class AMIClientLiveTest { overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".apiversion", apiversion); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); return overrides; } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java index a6e86813b4..3ef0c93d3c 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java @@ -27,10 +27,10 @@ import static org.testng.Assert.assertNotNull; import java.net.URI; import java.util.Iterator; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.SortedMap; -import java.util.Map.Entry; import org.jclouds.Constants; import org.jclouds.aws.domain.Region; @@ -41,13 +41,13 @@ import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.google.inject.Module; /** @@ -66,13 +66,12 @@ public class AvailabilityZoneAndRegionClientLiveTest { protected String endpoint; protected String apiversion; + @BeforeClass protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); - endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); - apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); } protected Properties setupProperties() { @@ -80,9 +79,12 @@ public class AvailabilityZoneAndRegionClientLiveTest { overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".apiversion", apiversion); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); return overrides; } @@ -90,26 +92,25 @@ public class AvailabilityZoneAndRegionClientLiveTest { public void setupClient() { setupCredentials(); Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides).getProviderSpecificContext(); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); client = context.getApi().getAvailabilityZoneAndRegionServices(); } public void testDescribeAvailabilityZones() { - for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, - Region.US_WEST_1, Region.AP_SOUTHEAST_1)) { - Set allResults = Sets.newLinkedHashSet(client - .describeAvailabilityZonesInRegion(region)); + for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, + Region.AP_SOUTHEAST_1)) { + Set allResults = client.describeAvailabilityZonesInRegion(region); assertNotNull(allResults); assert allResults.size() >= 2 : allResults.size(); Iterator iterator = allResults.iterator(); String id1 = iterator.next().getZone(); String id2 = iterator.next().getZone(); - Set twoResults = Sets.newLinkedHashSet(client - .describeAvailabilityZonesInRegion(region, availabilityZones(id1, id2))); + Set twoResults = client.describeAvailabilityZonesInRegion(region, + availabilityZones(id1, id2)); assertNotNull(twoResults); assertEquals(twoResults.size(), 2); - iterator = twoResults.iterator(); + iterator = allResults.iterator(); assertEquals(iterator.next().getZone(), id1); assertEquals(iterator.next().getZone(), id2); } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClientLiveTest.java index 2736288474..daabd9d99d 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClientLiveTest.java @@ -30,7 +30,6 @@ import java.util.SortedSet; import java.util.concurrent.TimeUnit; import org.jclouds.Constants; -import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; @@ -44,6 +43,7 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -71,13 +71,12 @@ public class ElasticBlockStoreClientLiveTest { protected String endpoint; protected String apiversion; + @BeforeClass protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); - endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); - apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); } protected Properties setupProperties() { @@ -85,9 +84,12 @@ public class ElasticBlockStoreClientLiveTest { overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".apiversion", apiversion); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); return overrides; } @@ -95,15 +97,15 @@ public class ElasticBlockStoreClientLiveTest { public void setupClient() { setupCredentials(); Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides).getProviderSpecificContext(); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); client = context.getApi().getElasticBlockStoreServices(); } @Test void testDescribeVolumes() { for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { + Region.AP_SOUTHEAST_1)) { SortedSet allResults = Sets.newTreeSet(client.describeVolumesInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { @@ -136,11 +138,11 @@ public class ElasticBlockStoreClientLiveTest { void testCreateSnapshotInRegion() { Snapshot snapshot = client.createSnapshotInRegion(null, volumeId); Predicate snapshotted = new RetryablePredicate(new SnapshotCompleted(client), 600, 10, - TimeUnit.SECONDS); + TimeUnit.SECONDS); assert snapshotted.apply(snapshot); Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(), - snapshotIds(snapshot.getId()))); + snapshotIds(snapshot.getId()))); assertEquals(result.getProgress(), 100); this.snapshot = result; @@ -152,7 +154,7 @@ public class ElasticBlockStoreClientLiveTest { assertNotNull(volume); Predicate availabile = new RetryablePredicate(new VolumeAvailable(client), 600, 10, - TimeUnit.SECONDS); + TimeUnit.SECONDS); assert availabile.apply(volume); Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); @@ -166,12 +168,12 @@ public class ElasticBlockStoreClientLiveTest { @Test(dependsOnMethods = "testCreateSnapshotInRegion") void testCreateVolumeFromSnapshotInAvailabilityZoneWithSize() { - Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone.US_EAST_1B, 2, snapshot - .getId()); + Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone.US_EAST_1B, 2, + snapshot.getId()); assertNotNull(volume); Predicate availabile = new RetryablePredicate(new VolumeAvailable(client), 600, 10, - TimeUnit.SECONDS); + TimeUnit.SECONDS); assert availabile.apply(volume); Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); @@ -197,13 +199,13 @@ public class ElasticBlockStoreClientLiveTest { @Test void testDescribeSnapshots() { for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { + Region.AP_SOUTHEAST_1)) { SortedSet allResults = Sets.newTreeSet(client.describeSnapshotsInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { Snapshot snapshot = allResults.last(); - Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(region, snapshotIds(snapshot - .getId()))); + Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(region, + snapshotIds(snapshot.getId()))); assertNotNull(result); assertEquals(result, snapshot); } @@ -246,12 +248,7 @@ public class ElasticBlockStoreClientLiveTest { @Test(dependsOnMethods = "testGetCreateVolumePermissionForSnapshot") void testDeleteSnapshotInRegion() { client.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId()); - try { - client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId())); - assert false : "shoud have exception"; - } catch (AWSResponseException e) { - assertEquals(e.getError().getCode(), "InvalidSnapshot.NotFound"); - } + assert client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId())).size() == 0; } @AfterTest diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java index 9062ce171c..d13b7aa6f5 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java @@ -56,7 +56,9 @@ import org.jclouds.compute.domain.Template; import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -85,13 +87,12 @@ public class PlacementGroupClientLiveTest { protected String endpoint; protected String apiversion; + @BeforeClass protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); - endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); - apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); } protected Properties setupProperties() { @@ -99,9 +100,12 @@ public class PlacementGroupClientLiveTest { overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".apiversion", apiversion); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); return overrides; } @@ -109,14 +113,14 @@ public class PlacementGroupClientLiveTest { public void setupClient() throws FileNotFoundException, IOException { setupCredentials(); Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides); keyPair = setupKeyPair(); client = EC2Client.class.cast(context.getProviderSpecificContext().getApi()); availableTester = new RetryablePredicate(new PlacementGroupAvailable(client), 60, 1, - TimeUnit.SECONDS); + TimeUnit.SECONDS); deletedTester = new RetryablePredicate(new PlacementGroupDeleted(client), 60, 1, TimeUnit.SECONDS); } @@ -125,12 +129,12 @@ public class PlacementGroupClientLiveTest { void testDescribe() { for (String region : newArrayList(Region.US_EAST_1)) { SortedSet allResults = newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region)); + .describePlacementGroupsInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { PlacementGroup group = allResults.last(); SortedSet result = newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region, group.getName())); + .describePlacementGroupsInRegion(region, group.getName())); assertNotNull(result); PlacementGroup compare = result.last(); assertEquals(compare, group); @@ -159,7 +163,7 @@ public class PlacementGroupClientLiveTest { private void verifyPlacementGroup(String groupName) { assert availableTester.apply(new PlacementGroup(Region.US_EAST_1, groupName, "cluster", State.PENDING)) : group; Set oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(null, - groupName); + groupName); assertNotNull(oneResult); assertEquals(oneResult.size(), 1); group = oneResult.iterator().next(); @@ -169,6 +173,7 @@ public class PlacementGroupClientLiveTest { } public void testStartCCInstance() throws Exception { + Set sizes = context.getComputeService().listHardwareProfiles(); assert any(sizes, new Predicate() { @@ -194,17 +199,19 @@ public class PlacementGroupClientLiveTest { assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17"); template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) - .runScript(buildScript(template.getImage().getOperatingSystem())); + .runScript(buildScript(template.getImage().getOperatingSystem())); String tag = PREFIX + "cccluster"; context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); + // TODO make this not lookup an explicit region + client.getPlacementGroupServices().deletePlacementGroupInRegion(null, "jclouds#" + tag + "#us-east-1"); try { Set nodes = context.getComputeService().runNodesWithTag(tag, 1, template); NodeMetadata node = getOnlyElement(nodes); getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null, - node.getProviderId()))); + node.getProviderId()))); } catch (RunNodesException e) { System.err.println(e.getNodeErrors().keySet()); diff --git a/aws/core/src/test/resources/log4j.xml b/aws/core/src/test/resources/log4j.xml index 1d36e512fd..5b548a0f48 100644 --- a/aws/core/src/test/resources/log4j.xml +++ b/aws/core/src/test/resources/log4j.xml @@ -162,12 +162,10 @@ - diff --git a/rackspace/src/test/resources/log4j.xml b/rackspace/src/test/resources/log4j.xml index 5b548a0f48..62a9a5a76d 100755 --- a/rackspace/src/test/resources/log4j.xml +++ b/rackspace/src/test/resources/log4j.xml @@ -162,10 +162,12 @@ + diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java index 83e5b14e28..bc635d579d 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java @@ -62,6 +62,29 @@ public class SlicehostComputeServiceLiveTest extends BaseComputeServiceLiveTest public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext tmContext = new ComputeServiceContextFactory().createContext( - provider, identity, credential).getProviderSpecificContext(); + provider, identity, credential).getProviderSpecificContext(); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testSuspendResume() throws Exception { + super.testSuspendResume(); + } + + @Test(enabled = true, dependsOnMethods = "testSuspendResume") + @Override + public void testGetNodesWithDetails() throws Exception { + super.testGetNodesWithDetails(); + } + + @Test(enabled = true, dependsOnMethods = "testSuspendResume") + @Override + public void testListNodes() throws Exception { + super.testListNodes(); + } + + @Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails" }) + @Override + public void testDestroyNodes() { + super.testDestroyNodes(); } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java index 0908cf7c86..6ed6f83234 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java @@ -71,4 +71,15 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { } } + @Test(enabled = true, dependsOnMethods = "testSuspendResume") + @Override + public void testGetNodesWithDetails() throws Exception { + super.testGetNodesWithDetails(); + } + + @Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails" }) + @Override + public void testDestroyNodes() { + super.testDestroyNodes(); + } } \ No newline at end of file From a0203eb1516b552128edfcdab10559e0541e31f6 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 17:38:35 +0100 Subject: [PATCH 12/21] Issue 399: update naming convention --- .../org/jclouds/filesystem/reference/FilesystemConstants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filesystem/src/main/java/org/jclouds/filesystem/reference/FilesystemConstants.java b/filesystem/src/main/java/org/jclouds/filesystem/reference/FilesystemConstants.java index c8afc9ae05..cab89f5bf2 100644 --- a/filesystem/src/main/java/org/jclouds/filesystem/reference/FilesystemConstants.java +++ b/filesystem/src/main/java/org/jclouds/filesystem/reference/FilesystemConstants.java @@ -27,6 +27,6 @@ package org.jclouds.filesystem.reference; public class FilesystemConstants { /** Specify the base directory where provider starts its file operations - must exists */ - public static final String PROPERTY_BASEDIR = "FileSystemAsyncBlobStore-basedir"; - + public static final String PROPERTY_BASEDIR = "jclouds.filesystem.basedir"; + } From 67855c7e7cce09f3a8abc33a860ff21ca06dc22c Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 18:23:08 +0100 Subject: [PATCH 13/21] disabled euc tests until we have a reliable endpoint --- ...alyptusComputeServiceLiveTestDisabled.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java new file mode 100644 index 0000000000..8ab7473043 --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java @@ -0,0 +1,63 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.aws.ec2.compute; + +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Template; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Disabled until we have an environment with enough room to run a few nodes simultaneously. + * + * @author Adrian Cole + */ +@Test(groups = "live", enabled = false, sequential = true, testName = "ec2.EucalyptusComputeServiceLiveTest") +public class EucalyptusComputeServiceLiveTestDisabled extends EC2ComputeServiceLiveTest { + + public EucalyptusComputeServiceLiveTestDisabled() { + provider = "eucalyptus"; + } + + @BeforeClass + @Override + public void setServiceDefaults() { + // security groups must be <30 characters + tag = "euc"; + } + + @Override + @Test(enabled = false) + public void testExtendedOptionsAndLogin() throws Exception { + // euc does not support monitoring + } + + @Override + protected void assertDefaultWorks() { + Template defaultTemplate = client.templateBuilder().build(); + assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); + assertEquals(getCores(defaultTemplate.getHardware()), 2.0d); + } + +} From 15e30cfbaa58f29185c17d5305c20b0da366266d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 20:20:12 +0100 Subject: [PATCH 14/21] Issue 398: correct s3 location api --- .../java/org/jclouds/aws/domain/Region.java | 6 ++-- .../jclouds/aws/s3/S3PropertiesBuilder.java | 23 ++++++------- .../functions/BucketToResourceMetadata.java | 8 +++-- .../aws/s3/xml/LocationConstraintHandler.java | 4 +-- .../ParseAWSErrorFromXmlContentTest.java | 6 ++++ .../aws/s3/services/BucketsLiveTest.java | 32 +++++++++---------- 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/domain/Region.java b/aws/core/src/main/java/org/jclouds/aws/domain/Region.java index 182b99ecf3..e5a0c0408c 100644 --- a/aws/core/src/main/java/org/jclouds/aws/domain/Region.java +++ b/aws/core/src/main/java/org/jclouds/aws/domain/Region.java @@ -42,6 +42,8 @@ public class Region { * consistency for PUTS of new objects in your Amazon S3 bucket and eventual * consistency for overwrite PUTS and DELETES. */ + public static final String EU = "EU"; + public static final String EU_WEST_1 = "eu-west-1"; /** @@ -85,8 +87,8 @@ public class Region { */ public static final String AP_SOUTHEAST_1 = "ap-southeast-1"; - public static Set ALL_S3 = ImmutableSet.of("EU", US_STANDARD, - US_EAST_1, US_WEST_1, AP_SOUTHEAST_1); + public static Set ALL_S3 = ImmutableSet.of(EU, US_STANDARD, + US_WEST_1, AP_SOUTHEAST_1); public static Set ALL_SQS = ImmutableSet.of(EU_WEST_1, US_STANDARD, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1); } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/S3PropertiesBuilder.java b/aws/core/src/main/java/org/jclouds/aws/s3/S3PropertiesBuilder.java index b0ef49ccce..c66cafbd57 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/S3PropertiesBuilder.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/S3PropertiesBuilder.java @@ -60,20 +60,15 @@ public class S3PropertiesBuilder extends PropertiesBuilder { } protected Properties addEndpoints(Properties properties) { - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_STANDARD, - Region.US_EAST_1, Region.US_WEST_1, "EU", Region.AP_SOUTHEAST_1)); - properties.setProperty(PROPERTY_DEFAULT_REGIONS, Joiner.on(',').join(Region.US_STANDARD, - Region.US_EAST_1)); + properties.setProperty(PROPERTY_REGIONS, + Joiner.on(',').join(Region.US_STANDARD, Region.US_WEST_1, "EU", Region.AP_SOUTHEAST_1)); + properties.setProperty(PROPERTY_DEFAULT_REGIONS, Region.US_STANDARD); properties.setProperty(PROPERTY_ENDPOINT, "https://s3.amazonaws.com"); - properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_STANDARD, - "https://s3.amazonaws.com"); - properties - .setProperty(PROPERTY_ENDPOINT + "." + Region.US_EAST_1, "https://s3.amazonaws.com"); - properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_WEST_1, - "https://s3-us-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_STANDARD, "https://s3.amazonaws.com"); + properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_WEST_1, "https://s3-us-west-1.amazonaws.com"); properties.setProperty(PROPERTY_ENDPOINT + "." + "EU", "https://s3-eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_ENDPOINT + "." + Region.AP_SOUTHEAST_1, - "https://s3-ap-southeast-1.amazonaws.com"); + properties + .setProperty(PROPERTY_ENDPOINT + "." + Region.AP_SOUTHEAST_1, "https://s3-ap-southeast-1.amazonaws.com"); return properties; } @@ -92,8 +87,8 @@ public class S3PropertiesBuilder extends PropertiesBuilder { protected void setMetaPrefix() { if (properties.getProperty(PROPERTY_USER_METADATA_PREFIX) == null) { - properties.setProperty(PROPERTY_USER_METADATA_PREFIX, String.format("x-%s-meta-", - properties.getProperty(PROPERTY_HEADER_TAG))); + properties.setProperty(PROPERTY_USER_METADATA_PREFIX, + String.format("x-%s-meta-", properties.getProperty(PROPERTY_HEADER_TAG))); } } diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceMetadata.java b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceMetadata.java index 1a91201aff..a1a891be0b 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceMetadata.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceMetadata.java @@ -71,19 +71,21 @@ public class BucketToResourceMetadata implements Function locations = this.locations.get(); final String region = client.getBucketLocation(from.getName()); + assert region != null : String.format("could not get region for %s", from.getName()); if (region != null) { try { - return Iterables.find(locations.get(), new Predicate() { + return Iterables.find(locations, new Predicate() { @Override public boolean apply(Location input) { - return input.getId().equals(region.toString()); + return input.getId().equalsIgnoreCase(region.toString()); } }); } catch (NoSuchElementException e) { - logger.error("could not get location for region %s in %s", region, locations.get()); + logger.error("could not get location for region %s in %s", region, locations); } } else { logger.error("could not get region for %s", from.getName()); diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/xml/LocationConstraintHandler.java b/aws/core/src/main/java/org/jclouds/aws/s3/xml/LocationConstraintHandler.java index bfb2b0d5ba..d0b89f9eb3 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/xml/LocationConstraintHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/xml/LocationConstraintHandler.java @@ -50,8 +50,8 @@ public class LocationConstraintHandler extends ParseSax.HandlerWithResultIncorrectState", IllegalStateException.class); } + + @Test + public void test409SetsIllegalStateException() { + assertCodeMakes("PUT", URI.create("https://adriancole-blobstore011.s3.amazonaws.com/"), 409, "", + "OperationAbortedA conflicting conditional operation is currently in progress against this resource. Please try again.F716E81C3D814E59SDprHxWzG/YXzanVnV7VTz/wP+6fRt1dS+q00kH1rz248YOOSddkFiTXF04XtqNO", IllegalStateException.class); + } @Test public void test400WithInvalidGroupDuplicateIllegalStateException() { diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/services/BucketsLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/services/BucketsLiveTest.java index 559e9eaf7c..da9db89386 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/services/BucketsLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/services/BucketsLiveTest.java @@ -39,17 +39,17 @@ import java.util.concurrent.TimeoutException; import org.jclouds.aws.domain.Region; import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.domain.AccessControlList; +import org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee; +import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee; +import org.jclouds.aws.s3.domain.AccessControlList.Grant; +import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI; +import org.jclouds.aws.s3.domain.AccessControlList.Permission; import org.jclouds.aws.s3.domain.BucketLogging; import org.jclouds.aws.s3.domain.BucketMetadata; import org.jclouds.aws.s3.domain.CannedAccessPolicy; import org.jclouds.aws.s3.domain.ListBucketResponse; import org.jclouds.aws.s3.domain.Payer; import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee; -import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee; -import org.jclouds.aws.s3.domain.AccessControlList.Grant; -import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI; -import org.jclouds.aws.s3.domain.AccessControlList.Permission; import org.jclouds.aws.s3.internal.StubS3AsyncClient; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.util.Utils; @@ -90,7 +90,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { } public void testPrivateAclIsDefaultForBucket() throws InterruptedException, ExecutionException, TimeoutException, - IOException { + IOException { String bucketName = getContainerName(); try { AccessControlList acl = getApi().getBucketACL(bucketName); @@ -105,7 +105,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { } public void testUpdateBucketACL() throws InterruptedException, ExecutionException, TimeoutException, IOException, - Exception { + Exception { String bucketName = getContainerName(); try { // Confirm the bucket is private @@ -221,9 +221,9 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { assertNull(getApi().getBucketLogging(bucketName)); setupAclForBucketLoggingTarget(targetBucket); - final BucketLogging logging = new BucketLogging(targetBucket, "access_log-", ImmutableSet - . of(new Grant(new EmailAddressGrantee(StubS3AsyncClient.TEST_ACL_EMAIL), - Permission.FULL_CONTROL))); + final BucketLogging logging = new BucketLogging(targetBucket, "access_log-", + ImmutableSet. of(new Grant(new EmailAddressGrantee(StubS3AsyncClient.TEST_ACL_EMAIL), + Permission.FULL_CONTROL))); getApi().enableBucketLogging(bucketName, logging); @@ -231,6 +231,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { public void run() { try { BucketLogging newLogging = getApi().getBucketLogging(bucketName); + assert newLogging !=null; AccessControlList acl = new AccessControlList(); for (Grant grant : newLogging.getTargetGrants()) { // TODO: add permission // checking features to @@ -277,7 +278,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { public void testEu() throws Exception { final String bucketName = getScratchContainerName(); try { - getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "eu", withBucketAcl(CannedAccessPolicy.PUBLIC_READ)); + getApi().putBucketInRegion(Region.EU, bucketName + "eu", withBucketAcl(CannedAccessPolicy.PUBLIC_READ)); assertConsistencyAware(new Runnable() { public void run() { try { @@ -288,7 +289,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { } } }); - assertEquals(Region.EU_WEST_1, getApi().getBucketLocation(bucketName + "eu")); + assertEquals(Region.EU, getApi().getBucketLocation(bucketName + "eu")); // TODO: I believe that the following should work based on the above acl assertion passing. // However, it fails on 403 // URL url = new URL(String.format("http://%s.s3.amazonaws.com", bucketName)); @@ -298,7 +299,6 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { } } - void bucketExists() throws Exception { String bucketName = getContainerName(); try { @@ -334,7 +334,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { } public void testListBucketDelimiter() throws InterruptedException, ExecutionException, TimeoutException, - UnsupportedEncodingException { + UnsupportedEncodingException { String bucketName = getContainerName(); try { String prefix = "apps"; @@ -352,7 +352,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { } public void testListBucketPrefix() throws InterruptedException, ExecutionException, TimeoutException, - UnsupportedEncodingException { + UnsupportedEncodingException { String bucketName = getContainerName(); try { String prefix = "apps"; @@ -370,7 +370,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { } public void testListBucketMaxResults() throws InterruptedException, ExecutionException, TimeoutException, - UnsupportedEncodingException { + UnsupportedEncodingException { String bucketName = getContainerName(); try { addAlphabetUnderRoot(bucketName); From 5f5b01ad35bbb95835e01388fa25296faee86b49 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 20:20:35 +0100 Subject: [PATCH 15/21] fixed test cases --- .../handlers/ParseAWSErrorFromXmlContent.java | 2 + .../EucalyptusComputeServiceLiveTest.java | 62 ------------------- .../jclouds/aws/sqs/SQSClientLiveTest.java | 24 +++---- ...kVCloudDirectorComputeServiceLiveTest.java | 4 +- .../jclouds/vcloud/VCloudClientLiveTest.java | 12 ++-- ...eTerremarkVCloudErrorFromHttpResponse.java | 3 +- ...TerremarkECloudComputeServiceLiveTest.java | 8 +-- ...remarkVCloudErrorFromHttpResponseTest.java | 7 +++ 8 files changed, 35 insertions(+), 87 deletions(-) delete mode 100644 aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java diff --git a/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java b/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java index b7af9095f3..c31338a882 100755 --- a/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java +++ b/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java @@ -116,6 +116,8 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler { exception = new KeyNotFoundException(container, key, message); } break; + case 409: + exception = new IllegalStateException(message, exception); } } finally { releasePayload(response); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java deleted file mode 100644 index da51847a03..0000000000 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.aws.ec2.compute; - -import static org.jclouds.compute.util.ComputeServiceUtils.getCores; -import static org.testng.Assert.assertEquals; - -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Template; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * - * @author Adrian Cole - */ -@Test(groups = "live", sequential = true, testName = "ec2.EucalyptusComputeServiceLiveTest") -public class EucalyptusComputeServiceLiveTest extends EC2ComputeServiceLiveTest { - - public EucalyptusComputeServiceLiveTest() { - provider = "eucalyptus"; - } - - @BeforeClass - @Override - public void setServiceDefaults() { - // security groups must be <30 characters - tag = "euc"; - } - - @Override - @Test(enabled = false) - public void testExtendedOptionsAndLogin() throws Exception { - // euc does not support monitoring - } - - @Override - protected void assertDefaultWorks() { - Template defaultTemplate = client.templateBuilder().build(); - assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); - assertEquals(getCores(defaultTemplate.getHardware()), 2.0d); - } - -} diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSClientLiveTest.java index 77692c30ba..53b57d3186 100644 --- a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSClientLiveTest.java @@ -68,10 +68,9 @@ public class SQSClientLiveTest { protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); - endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); - apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); } protected Properties setupProperties() { @@ -79,9 +78,12 @@ public class SQSClientLiveTest { overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".apiversion", apiversion); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); return overrides; } @@ -90,14 +92,14 @@ public class SQSClientLiveTest { setupCredentials(); Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides); + overrides); this.client = context.getApi(); } @Test void testListQueuesInRegion() throws InterruptedException { for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { + Region.AP_SOUTHEAST_1)) { SortedSet allResults = Sets.newTreeSet(client.listQueuesInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { @@ -114,7 +116,7 @@ public class SQSClientLiveTest { String queueName = PREFIX + "1"; for (final String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { + Region.AP_SOUTHEAST_1)) { try { SortedSet result = Sets.newTreeSet(client.listQueuesInRegion(region, queuePrefix(queueName))); if (result.size() >= 1) { @@ -182,7 +184,7 @@ public class SQSClientLiveTest { assertion.run(); if (i > 0) System.err.printf("%d attempts and %dms asserting %s%n", i + 1, System.currentTimeMillis() - start, - assertion.getClass().getSimpleName()); + assertion.getClass().getSimpleName()); return; } catch (AssertionError e) { error = e; diff --git a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java index 5a216d0ead..6eebfa0a8e 100644 --- a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java +++ b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java @@ -49,10 +49,10 @@ public class BlueLockVCloudDirectorComputeServiceLiveTest extends VCloudComputeS @Test public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); - assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); + assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assert OperatingSystemPredicates.supportsApt().apply(defaultTemplate.getImage().getOperatingSystem()); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getDescription(), "Ubuntu Linux (32-bit)"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getDescription(), "Ubuntu Linux (64-bit)"); assert defaultTemplate.getLocation().getId() != null : defaultTemplate.getLocation(); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); System.out.println(defaultTemplate.getHardware()); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index 927ab5be2c..df802533d5 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -78,13 +78,13 @@ public class VCloudClientLiveTest extends CommonVCloudClientLiveTest tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + .createContext(provider, identity, credential).getProviderSpecificContext(); } @Override @@ -84,7 +84,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv @Override protected void checkOsMatchesTemplate(NodeMetadata node) { if (node.getOperatingSystem() != null) - assertEquals(node.getOperatingSystem().getFamily(), OsFamily.UNRECOGNIZED); + assertEquals(node.getOperatingSystem().getFamily(), null); } @Override @@ -94,7 +94,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv // image.getLocationId() can be null, if it is a location-free image assertEquals(image.getType(), ComputeType.IMAGE); if (image.getOperatingSystem().getFamily() != OsFamily.WINDOWS - && image.getOperatingSystem().getFamily() != OsFamily.SOLARIS) { + && image.getOperatingSystem().getFamily() != OsFamily.SOLARIS) { assert image.getDefaultCredentials() != null && image.getDefaultCredentials().identity != null : image; assert image.getDefaultCredentials().credential != null : image; } @@ -110,7 +110,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv NodeMetadata allData = client.getNodeMetadata(node.getId()); System.out.println(allData.getHardware()); RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + .createContext(provider, identity, credential).getProviderSpecificContext(); VCloudExpressVApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName()); assertEquals(vApp.getName(), allData.getName()); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java index 19062050d9..1c1365a1cc 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java @@ -85,6 +85,13 @@ public class ParseTerremarkVCloudErrorFromHttpResponseTest extends BaseHttpError IllegalStateException.class); } + @Test + public void testKeyAlreadyExistsSetsIllegalStateException() { + assertCodeMakes("POST", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/extensions/org/48/keys"), 400, + "Security key with name livetest exists.", "Security key with name livetest exists.", + IllegalStateException.class); + } + @Override protected Class getHandlerClass() { return ParseTerremarkVCloudErrorFromHttpResponse.class; From 1347165118f810f1227052812921c46e29cbd505 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Nov 2010 22:42:34 +0100 Subject: [PATCH 16/21] ec2 suspend nodes may take up to 2 minutes --- .../jclouds/aws/ec2/EC2PropertiesBuilder.java | 7 +- .../org/jclouds/compute/ComputeService.java | 21 +++- .../compute/BaseComputeServiceLiveTest.java | 102 +++++++++--------- 3 files changed, 78 insertions(+), 52 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2PropertiesBuilder.java b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2PropertiesBuilder.java index b8ad68742f..67dcdf98e5 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2PropertiesBuilder.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2PropertiesBuilder.java @@ -26,6 +26,7 @@ import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_CC_AMIs; import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_ELB_ENDPOINT; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; +import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_SUSPENDED; import java.util.Properties; @@ -49,11 +50,15 @@ public class EC2PropertiesBuilder extends PropertiesBuilder { properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317"); // amis that work with the cluster instances properties.setProperty(PROPERTY_EC2_CC_AMIs, "us-east-1/ami-7ea24a17"); + // sometimes, like in ec2, stop takes a very long time, perhaps + // due to volume management. one example spent 2 minutes moving + // from stopping->stopped state on an ec2 micro + properties.setProperty(PROPERTY_TIMEOUT_NODE_SUSPENDED, 120 * 1000 + ""); // auth fail sometimes happens in EC2, as the rc.local script that injects the // authorized key executes after ssh has started properties.setProperty("jclouds.ssh.max_retries", "7"); properties.setProperty("jclouds.ssh.retryable_messages", - "Auth fail,invalid data,End of IO Stream Read,Connection reset,socket is not established"); + "Auth fail,invalid data,End of IO Stream Read,Connection reset,socket is not established"); return properties; } diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java index 5df136488f..11da882153 100755 --- a/compute/src/main/java/org/jclouds/compute/ComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java @@ -137,7 +137,7 @@ public interface ComputeService { * default, equivalent to {@code templateBuilder().any().options(templateOptions)}. */ Set runNodesWithTag(String tag, int count, TemplateOptions templateOptions) - throws RunNodesException; + throws RunNodesException; /** * Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)}, except that the @@ -148,6 +148,10 @@ public interface ComputeService { /** * resume the node from {@link org.jclouds.compute.domain.NodeState#SUSPENDED suspended} state, * given its id. + * + *

note

+ * + * affected nodes may not resume with the same IP address(es) */ void resumeNode(String id); @@ -155,6 +159,10 @@ public interface ComputeService { * nodes matching the filter are treated as a logical set. Using the resume command, you can save * time by resumeing the nodes in parallel. * + *

note

+ * + * affected nodes may not resume with the same IP address(es) + * * @throws UnsupportedOperationException * if the underlying provider doesn't support suspend/resume */ @@ -164,6 +172,10 @@ public interface ComputeService { * suspend the node, given its id. This will result in * {@link org.jclouds.compute.domain.NodeState#SUSPENDED suspended} state. * + *

note

+ * + * affected nodes may not resume with the same IP address(es) + * * @throws UnsupportedOperationException * if the underlying provider doesn't support suspend/resume */ @@ -173,6 +185,9 @@ public interface ComputeService { * nodes matching the filter are treated as a logical set. Using the suspend command, you can * save time by suspending the nodes in parallel. * + *

note

+ * + * affected nodes may not resume with the same IP address(es) */ void suspendNodesMatching(Predicate filter); @@ -224,7 +239,7 @@ public interface ComputeService { * @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String) */ Map runScriptOnNodesMatching(Predicate filter, Payload runScript) - throws RunScriptOnNodesException; + throws RunScriptOnNodesException; /** * Run the script on all nodes with the specific tag. @@ -243,6 +258,6 @@ public interface ComputeService { * @see org.jclouds.io.Payloads */ Map runScriptOnNodesMatching(Predicate filter, - Payload runScript, RunScriptOptions options) throws RunScriptOnNodesException; + Payload runScript, RunScriptOptions options) throws RunScriptOnNodesException; } diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 9b056ed3e2..f967f6a063 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -161,8 +161,8 @@ public abstract class BaseComputeServiceLiveTest { if (context != null) context.close(); Properties props = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet.of(new Log4JLoggingModule(), - getSshModule()), props); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props); client = context.getComputeService(); } @@ -173,8 +173,8 @@ public abstract class BaseComputeServiceLiveTest { public void testCorrectAuthException() throws Exception { ComputeServiceContext context = null; try { - context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet - . of(new Log4JLoggingModule())); + context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", + ImmutableSet. of(new Log4JLoggingModule())); context.getComputeService().listNodes(); } catch (AuthorizationException e) { throw e; @@ -217,7 +217,7 @@ public abstract class BaseComputeServiceLiveTest { OperatingSystem os = get(nodes, 0).getOperatingSystem(); try { Map responses = runScriptWithCreds(tag, os, new Credentials( - good.identity, "romeo")); + good.identity, "romeo")); assert false : "shouldn't pass with a bad password\n" + responses; } catch (RunScriptOnNodesException e) { assert getRootCause(e).getMessage().contains("Auth fail") : e; @@ -276,7 +276,7 @@ public abstract class BaseComputeServiceLiveTest { template = buildTemplate(client.templateBuilder()); template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) - .runScript(buildScript(template.getImage().getOperatingSystem())); + .runScript(buildScript(template.getImage().getOperatingSystem())); } protected void checkImageIdMatchesTemplate(NodeMetadata node) { @@ -287,8 +287,8 @@ public abstract class BaseComputeServiceLiveTest { protected void checkOsMatchesTemplate(NodeMetadata node) { if (node.getOperatingSystem() != null) assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String - .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node - .getOperatingSystem()); + .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), + node.getOperatingSystem()); } void assertLocationSameOrChild(Location test, Location expected) { @@ -320,10 +320,11 @@ public abstract class BaseComputeServiceLiveTest { } protected Map runScriptWithCreds(final String tag, OperatingSystem os, - Credentials creds) throws RunScriptOnNodesException { + Credentials creds) throws RunScriptOnNodesException { try { - return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(os).render( - OsFamily.UNIX)), overrideCredentialsWith(creds).nameTask("runScriptWithCreds")); + return client.runScriptOnNodesMatching(runningWithTag(tag), + newStringPayload(buildScript(os).render(OsFamily.UNIX)), + overrideCredentialsWith(creds).nameTask("runScriptWithCreds")); } catch (SshException e) { throw e; } @@ -353,16 +354,16 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") public void testGet() throws Exception { - Map metadataMap = newLinkedHashMap(uniqueIndex(filter(client - .listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))), - new Function() { + Map metadataMap = newLinkedHashMap(uniqueIndex( + filter(client.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))), + new Function() { - @Override - public String apply(NodeMetadata from) { - return from.getId(); - } + @Override + public String apply(NodeMetadata from) { + return from.getId(); + } - })); + })); for (NodeMetadata node : nodes) { metadataMap.remove(node.getId()); NodeMetadata metadata = client.getNodeMetadata(node.getId()); @@ -372,15 +373,16 @@ public abstract class BaseComputeServiceLiveTest { checkImageIdMatchesTemplate(metadata); checkOsMatchesTemplate(metadata); assertEquals(metadata.getState(), NodeState.RUNNING); - assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses()); - assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses()); + // due to DHCP the addresses can actually change in-between runs. + assertEquals(metadata.getPrivateAddresses().size(), node.getPrivateAddresses().size()); + assertEquals(metadata.getPublicAddresses().size(), node.getPublicAddresses().size()); } assertNodeZero(metadataMap.values()); } protected void assertNodeZero(Collection metadataSet) { assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]", - metadataSet, nodes); + metadataSet, nodes); } @Test(enabled = true, dependsOnMethods = "testGet") @@ -393,16 +395,20 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, dependsOnMethods = "testReboot") public void testSuspendResume() throws Exception { client.suspendNodesMatching(withTag(tag)); + Set stoppedNodes = refreshNodes(); assert Iterables.all(stoppedNodes, new Predicate() { @Override public boolean apply(NodeMetadata input) { - return input.getState() == NodeState.SUSPENDED; + boolean returnVal = input.getState() == NodeState.SUSPENDED; + if (!returnVal) + System.err.printf("warning: node %s in state %s%n", input.getId(), input.getState()); + return returnVal; } - }) : nodes; + }) : stoppedNodes; client.resumeNodesMatching(withTag(tag)); testGet(); @@ -462,11 +468,11 @@ public abstract class BaseComputeServiceLiveTest { } template = client.templateBuilder().options(blockOnComplete(false).blockOnPort(8080, 600).inboundPorts(22, 8080)) - .build(); + .build(); // note this is a dependency on the template resolution template.getOptions().runScript( - RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage() - .getOperatingSystem())); + RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage() + .getOperatingSystem())); try { NodeMetadata node = getOnlyElement(client.runNodesWithTag(tag, 1, template)); @@ -500,26 +506,26 @@ public abstract class BaseComputeServiceLiveTest { assert location != location.getParent() : location; assert location.getScope() != null : location; switch (location.getScope()) { - case PROVIDER: - assertProvider(location); - break; - case REGION: - assertProvider(location.getParent()); - break; - case ZONE: - Location provider = location.getParent().getParent(); - // zone can be a direct descendant of provider - if (provider == null) - provider = location.getParent(); - assertProvider(provider); - break; - case HOST: - Location provider2 = location.getParent().getParent().getParent(); - // zone can be a direct descendant of provider - if (provider2 == null) - provider2 = location.getParent().getParent(); - assertProvider(provider2); - break; + case PROVIDER: + assertProvider(location); + break; + case REGION: + assertProvider(location.getParent()); + break; + case ZONE: + Location provider = location.getParent().getParent(); + // zone can be a direct descendant of provider + if (provider == null) + provider = location.getParent(); + assertProvider(provider); + break; + case HOST: + Location provider2 = location.getParent().getParent().getParent(); + // zone can be a direct descendant of provider + if (provider2 == null) + provider2 = location.getParent().getParent(); + assertProvider(provider2); + break; } } } @@ -607,7 +613,7 @@ public abstract class BaseComputeServiceLiveTest { assertEquals(hello.getOutput().trim(), "hello"); ExecResponse exec = ssh.exec("java -version"); assert exec.getError().indexOf("1.6") != -1 || exec.getOutput().indexOf("1.6") != -1 : exec + "\n" - + ssh.exec("cat /tmp/bootstrap/stdout.log /tmp/bootstrap/stderr.log"); + + ssh.exec("cat /tmp/bootstrap/stdout.log /tmp/bootstrap/stderr.log"); } finally { if (ssh != null) ssh.disconnect(); From 2f5c52d86d0fa96da51505778b53a78bcb49d0dc Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 8 Nov 2010 06:43:17 +0100 Subject: [PATCH 17/21] Issue 379: patched gson to override default enum parsing --- .../gson/JcloudsDefaultTypeAdapters.java | 928 ++++++++++++++++++ .../com/google/gson/JcloudsGsonBuilder.java | 591 +++++++++++ .../org/jclouds/json/config/GsonModule.java | 20 +- .../test/java/org/jclouds/json/JsonTest.java | 78 ++ 4 files changed, 1607 insertions(+), 10 deletions(-) create mode 100644 core/src/main/java/com/google/gson/JcloudsDefaultTypeAdapters.java create mode 100644 core/src/main/java/com/google/gson/JcloudsGsonBuilder.java create mode 100644 core/src/test/java/org/jclouds/json/JsonTest.java diff --git a/core/src/main/java/com/google/gson/JcloudsDefaultTypeAdapters.java b/core/src/main/java/com/google/gson/JcloudsDefaultTypeAdapters.java new file mode 100644 index 0000000000..39fdc04c80 --- /dev/null +++ b/core/src/main/java/com/google/gson/JcloudsDefaultTypeAdapters.java @@ -0,0 +1,928 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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. + * ==================================================================== + */ + +/* + * Copyright (C) 2008 Google Inc. + * + * Licensed 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 com.google.gson; + +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.SortedSet; +import java.util.StringTokenizer; +import java.util.TreeSet; +import java.util.UUID; + +import com.google.common.base.Function; +import com.google.common.collect.MapMaker; + +/** + * List of all the default type adapters ({@link JsonSerializer}s, {@link JsonDeserializer}s, and + * {@link InstanceCreator}s. + * + *

Note!

+ * changed to edit the default behaviour of enum parsing by Adrian Cole + * + * @author Inderjeet Singh + * @author Joel Leitch + */ +final class JcloudsDefaultTypeAdapters { + + private static final DefaultDateTypeAdapter DATE_TYPE_ADAPTER = new DefaultDateTypeAdapter(); + private static final DefaultJavaSqlDateTypeAdapter JAVA_SQL_DATE_TYPE_ADAPTER = new DefaultJavaSqlDateTypeAdapter(); + private static final DefaultTimeTypeAdapter TIME_TYPE_ADAPTER = new DefaultTimeTypeAdapter(); + private static final DefaultTimestampDeserializer TIMESTAMP_DESERIALIZER = new DefaultTimestampDeserializer(); + + @SuppressWarnings({ "rawtypes" }) + private static final EnumTypeAdapter ENUM_TYPE_ADAPTER = new EnumTypeAdapter(); + private static final UrlTypeAdapter URL_TYPE_ADAPTER = new UrlTypeAdapter(); + private static final UriTypeAdapter URI_TYPE_ADAPTER = new UriTypeAdapter(); + private static final UuidTypeAdapter UUUID_TYPE_ADAPTER = new UuidTypeAdapter(); + private static final LocaleTypeAdapter LOCALE_TYPE_ADAPTER = new LocaleTypeAdapter(); + private static final CollectionTypeAdapter COLLECTION_TYPE_ADAPTER = new CollectionTypeAdapter(); + private static final MapTypeAdapter MAP_TYPE_ADAPTER = new MapTypeAdapter(); + private static final BigDecimalTypeAdapter BIG_DECIMAL_TYPE_ADAPTER = new BigDecimalTypeAdapter(); + private static final BigIntegerTypeAdapter BIG_INTEGER_TYPE_ADAPTER = new BigIntegerTypeAdapter(); + + private static final BooleanTypeAdapter BOOLEAN_TYPE_ADAPTER = new BooleanTypeAdapter(); + private static final ByteTypeAdapter BYTE_TYPE_ADAPTER = new ByteTypeAdapter(); + private static final CharacterTypeAdapter CHARACTER_TYPE_ADAPTER = new CharacterTypeAdapter(); + private static final DoubleDeserializer DOUBLE_TYPE_ADAPTER = new DoubleDeserializer(); + private static final FloatDeserializer FLOAT_TYPE_ADAPTER = new FloatDeserializer(); + private static final IntegerTypeAdapter INTEGER_TYPE_ADAPTER = new IntegerTypeAdapter(); + private static final LongDeserializer LONG_DESERIALIZER = new LongDeserializer(); + private static final NumberTypeAdapter NUMBER_TYPE_ADAPTER = new NumberTypeAdapter(); + private static final ShortTypeAdapter SHORT_TYPE_ADAPTER = new ShortTypeAdapter(); + private static final StringTypeAdapter STRING_TYPE_ADAPTER = new StringTypeAdapter(); + + private static final PropertiesCreator PROPERTIES_CREATOR = new PropertiesCreator(); + private static final TreeSetCreator TREE_SET_CREATOR = new TreeSetCreator(); + private static final HashSetCreator HASH_SET_CREATOR = new HashSetCreator(); + private static final GregorianCalendarTypeAdapter GREGORIAN_CALENDAR_TYPE_ADAPTER = new GregorianCalendarTypeAdapter(); + + // The constants DEFAULT_SERIALIZERS, DEFAULT_DESERIALIZERS, and DEFAULT_INSTANCE_CREATORS + // must be defined after the constants for the type adapters. Otherwise, the type adapter + // constants will appear as nulls. + private static final ParameterizedTypeHandlerMap> DEFAULT_SERIALIZERS = createDefaultSerializers(); + private static final ParameterizedTypeHandlerMap> DEFAULT_DESERIALIZERS = createDefaultDeserializers(); + private static final ParameterizedTypeHandlerMap> DEFAULT_INSTANCE_CREATORS = createDefaultInstanceCreators(); + + private static ParameterizedTypeHandlerMap> createDefaultSerializers() { + ParameterizedTypeHandlerMap> map = new ParameterizedTypeHandlerMap>(); + + map.registerForTypeHierarchy(Enum.class, ENUM_TYPE_ADAPTER); + map.register(URL.class, URL_TYPE_ADAPTER); + map.register(URI.class, URI_TYPE_ADAPTER); + map.register(UUID.class, UUUID_TYPE_ADAPTER); + map.register(Locale.class, LOCALE_TYPE_ADAPTER); + map.registerForTypeHierarchy(Collection.class, COLLECTION_TYPE_ADAPTER); + map.registerForTypeHierarchy(Map.class, MAP_TYPE_ADAPTER); + map.register(Date.class, DATE_TYPE_ADAPTER); + map.register(java.sql.Date.class, JAVA_SQL_DATE_TYPE_ADAPTER); + map.register(Timestamp.class, DATE_TYPE_ADAPTER); + map.register(Time.class, TIME_TYPE_ADAPTER); + map.register(Calendar.class, GREGORIAN_CALENDAR_TYPE_ADAPTER); + map.register(GregorianCalendar.class, GREGORIAN_CALENDAR_TYPE_ADAPTER); + map.register(BigDecimal.class, BIG_DECIMAL_TYPE_ADAPTER); + map.register(BigInteger.class, BIG_INTEGER_TYPE_ADAPTER); + + // Add primitive serializers + map.register(Boolean.class, BOOLEAN_TYPE_ADAPTER); + map.register(boolean.class, BOOLEAN_TYPE_ADAPTER); + map.register(Byte.class, BYTE_TYPE_ADAPTER); + map.register(byte.class, BYTE_TYPE_ADAPTER); + map.register(Character.class, CHARACTER_TYPE_ADAPTER); + map.register(char.class, CHARACTER_TYPE_ADAPTER); + map.register(Integer.class, INTEGER_TYPE_ADAPTER); + map.register(int.class, INTEGER_TYPE_ADAPTER); + map.register(Number.class, NUMBER_TYPE_ADAPTER); + map.register(Short.class, SHORT_TYPE_ADAPTER); + map.register(short.class, SHORT_TYPE_ADAPTER); + map.register(String.class, STRING_TYPE_ADAPTER); + + map.makeUnmodifiable(); + return map; + } + + private static ParameterizedTypeHandlerMap> createDefaultDeserializers() { + ParameterizedTypeHandlerMap> map = new ParameterizedTypeHandlerMap>(); + map.registerForTypeHierarchy(Enum.class, wrapDeserializer(ENUM_TYPE_ADAPTER)); + map.register(URL.class, wrapDeserializer(URL_TYPE_ADAPTER)); + map.register(URI.class, wrapDeserializer(URI_TYPE_ADAPTER)); + map.register(UUID.class, wrapDeserializer(UUUID_TYPE_ADAPTER)); + map.register(Locale.class, wrapDeserializer(LOCALE_TYPE_ADAPTER)); + map.registerForTypeHierarchy(Collection.class, wrapDeserializer(COLLECTION_TYPE_ADAPTER)); + map.registerForTypeHierarchy(Map.class, wrapDeserializer(MAP_TYPE_ADAPTER)); + map.register(Date.class, wrapDeserializer(DATE_TYPE_ADAPTER)); + map.register(java.sql.Date.class, wrapDeserializer(JAVA_SQL_DATE_TYPE_ADAPTER)); + map.register(Timestamp.class, wrapDeserializer(TIMESTAMP_DESERIALIZER)); + map.register(Time.class, wrapDeserializer(TIME_TYPE_ADAPTER)); + map.register(Calendar.class, GREGORIAN_CALENDAR_TYPE_ADAPTER); + map.register(GregorianCalendar.class, GREGORIAN_CALENDAR_TYPE_ADAPTER); + map.register(BigDecimal.class, wrapDeserializer(BIG_DECIMAL_TYPE_ADAPTER)); + map.register(BigInteger.class, wrapDeserializer(BIG_INTEGER_TYPE_ADAPTER)); + + // Add primitive deserializers + map.register(Boolean.class, wrapDeserializer(BOOLEAN_TYPE_ADAPTER)); + map.register(boolean.class, wrapDeserializer(BOOLEAN_TYPE_ADAPTER)); + map.register(Byte.class, wrapDeserializer(BYTE_TYPE_ADAPTER)); + map.register(byte.class, wrapDeserializer(BYTE_TYPE_ADAPTER)); + map.register(Character.class, wrapDeserializer(CHARACTER_TYPE_ADAPTER)); + map.register(char.class, wrapDeserializer(CHARACTER_TYPE_ADAPTER)); + map.register(Double.class, wrapDeserializer(DOUBLE_TYPE_ADAPTER)); + map.register(double.class, wrapDeserializer(DOUBLE_TYPE_ADAPTER)); + map.register(Float.class, wrapDeserializer(FLOAT_TYPE_ADAPTER)); + map.register(float.class, wrapDeserializer(FLOAT_TYPE_ADAPTER)); + map.register(Integer.class, wrapDeserializer(INTEGER_TYPE_ADAPTER)); + map.register(int.class, wrapDeserializer(INTEGER_TYPE_ADAPTER)); + map.register(Long.class, wrapDeserializer(LONG_DESERIALIZER)); + map.register(long.class, wrapDeserializer(LONG_DESERIALIZER)); + map.register(Number.class, wrapDeserializer(NUMBER_TYPE_ADAPTER)); + map.register(Short.class, wrapDeserializer(SHORT_TYPE_ADAPTER)); + map.register(short.class, wrapDeserializer(SHORT_TYPE_ADAPTER)); + map.register(String.class, wrapDeserializer(STRING_TYPE_ADAPTER)); + + map.makeUnmodifiable(); + return map; + } + + private static ParameterizedTypeHandlerMap> createDefaultInstanceCreators() { + ParameterizedTypeHandlerMap> map = new ParameterizedTypeHandlerMap>(); + map.registerForTypeHierarchy(Map.class, MAP_TYPE_ADAPTER); + + // Add Collection type instance creators + map.registerForTypeHierarchy(Collection.class, COLLECTION_TYPE_ADAPTER); + + map.registerForTypeHierarchy(Set.class, HASH_SET_CREATOR); + map.registerForTypeHierarchy(SortedSet.class, TREE_SET_CREATOR); + map.register(Properties.class, PROPERTIES_CREATOR); + map.makeUnmodifiable(); + return map; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private static JsonDeserializer wrapDeserializer(JsonDeserializer deserializer) { + return new JsonDeserializerExceptionWrapper(deserializer); + } + + static ParameterizedTypeHandlerMap> getDefaultSerializers() { + return getDefaultSerializers(false, LongSerializationPolicy.DEFAULT); + } + + static ParameterizedTypeHandlerMap> getDefaultSerializers( + boolean serializeSpecialFloatingPointValues, LongSerializationPolicy longSerializationPolicy) { + ParameterizedTypeHandlerMap> serializers = new ParameterizedTypeHandlerMap>(); + + // Double primitive + JcloudsDefaultTypeAdapters.DoubleSerializer doubleSerializer = new JcloudsDefaultTypeAdapters.DoubleSerializer( + serializeSpecialFloatingPointValues); + serializers.registerIfAbsent(Double.class, doubleSerializer); + serializers.registerIfAbsent(double.class, doubleSerializer); + + // Float primitive + JcloudsDefaultTypeAdapters.FloatSerializer floatSerializer = new JcloudsDefaultTypeAdapters.FloatSerializer( + serializeSpecialFloatingPointValues); + serializers.registerIfAbsent(Float.class, floatSerializer); + serializers.registerIfAbsent(float.class, floatSerializer); + + // Long primitive + JcloudsDefaultTypeAdapters.LongSerializer longSerializer = new JcloudsDefaultTypeAdapters.LongSerializer( + longSerializationPolicy); + serializers.registerIfAbsent(Long.class, longSerializer); + serializers.registerIfAbsent(long.class, longSerializer); + + serializers.registerIfAbsent(DEFAULT_SERIALIZERS); + return serializers; + } + + static ParameterizedTypeHandlerMap> getDefaultDeserializers() { + return DEFAULT_DESERIALIZERS; + } + + static ParameterizedTypeHandlerMap> getDefaultInstanceCreators() { + return DEFAULT_INSTANCE_CREATORS; + } + + static class DefaultDateTypeAdapter implements JsonSerializer, JsonDeserializer { + private final DateFormat format; + + DefaultDateTypeAdapter() { + this.format = DateFormat.getDateTimeInstance(); + } + + DefaultDateTypeAdapter(final String datePattern) { + this.format = new SimpleDateFormat(datePattern); + } + + DefaultDateTypeAdapter(final int style) { + this.format = DateFormat.getDateInstance(style); + } + + public DefaultDateTypeAdapter(final int dateStyle, final int timeStyle) { + this.format = DateFormat.getDateTimeInstance(dateStyle, timeStyle); + } + + // These methods need to be synchronized since JDK DateFormat classes are not thread-safe + // See issue 162 + public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { + synchronized (format) { + String dateFormatAsString = format.format(src); + return new JsonPrimitive(dateFormatAsString); + } + } + + public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + if (!(json instanceof JsonPrimitive)) { + throw new JsonParseException("The date should be a string value"); + } + try { + synchronized (format) { + return format.parse(json.getAsString()); + } + } catch (ParseException e) { + throw new JsonParseException(e); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(DefaultDateTypeAdapter.class.getSimpleName()); + sb.append('(').append(format.getClass().getSimpleName()).append(')'); + return sb.toString(); + } + } + + static class DefaultJavaSqlDateTypeAdapter implements JsonSerializer, JsonDeserializer { + private final DateFormat format; + + DefaultJavaSqlDateTypeAdapter() { + this.format = new SimpleDateFormat("MMM d, yyyy"); + } + + public JsonElement serialize(java.sql.Date src, Type typeOfSrc, JsonSerializationContext context) { + synchronized (format) { + String dateFormatAsString = format.format(src); + return new JsonPrimitive(dateFormatAsString); + } + } + + public java.sql.Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + if (!(json instanceof JsonPrimitive)) { + throw new JsonParseException("The date should be a string value"); + } + try { + synchronized (format) { + Date date = format.parse(json.getAsString()); + return new java.sql.Date(date.getTime()); + } + } catch (ParseException e) { + throw new JsonParseException(e); + } + } + } + + static class DefaultTimestampDeserializer implements JsonDeserializer { + public Timestamp deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + Date date = context.deserialize(json, Date.class); + return new Timestamp(date.getTime()); + } + } + + static class DefaultTimeTypeAdapter implements JsonSerializer