@Override public boolean apply(Exception input) { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") AWSResponseException exception = Exceptions.getFirstThrowableOfType(input, AWSResponseException.class); if (exception != null) { String code = exception.getError().getCode(); return AWS_ERRORS_TO_RETRY.contains(code); } return false; }
/** http://code.google.com/p/jclouds/issues/detail?id=992 */ public void testUseBucketWithUpperCaseName() throws Exception { String bucketName = CONTAINER_PREFIX + "-TestBucket"; String blobName = "TestBlob.txt"; StorageMetadata container = null; BlobStore store = view.getBlobStore(); // Create and use a valid bucket name with uppercase characters in the bucket name (US regions // only) try { store.createContainerInLocation(null, bucketName); for (StorageMetadata metadata : store.list()) { if (metadata.getName().equals(bucketName)) { container = metadata; break; } } assertNotNull(container); store.putBlob( bucketName, store.blobBuilder(blobName).payload("This is a test!").contentType("text/plain").build()); assertNotNull(store.getBlob(bucketName, blobName)); } finally { if (container != null) { store.deleteContainer(bucketName); } } // Try to create the same bucket successfully created above in one of the non-US regions to // ensure an error is // encountered as expected. Location location = null; for (Location pLocation : store.listAssignableLocations()) { if (!ImmutableSet.of(Region.US_STANDARD, Region.US_EAST_1, Region.US_WEST_1, Region.US_WEST_2) .contains(pLocation.getId())) { location = pLocation; break; } } try { store.createContainerInLocation(location, bucketName); fail("Should had failed because in non-US regions, mixed-case bucket names are invalid."); } catch (AWSResponseException e) { assertEquals("InvalidBucketName", e.getError().getCode()); } }
private void createPlacementGroupInRegion(String region, String name) { checkNotNull(region, "region"); checkNotNull(name, "name"); logger.debug(">> creating placementGroup region(%s) name(%s)", region, name); try { ec2Client.getPlacementGroupServices().createPlacementGroupInRegion(region, name); logger.debug("<< created placementGroup(%s)", name); checkState( placementGroupAvailable.apply(new PlacementGroup(region, name, "cluster", State.PENDING)), String.format( "placementGroup region(%s) name(%s) failed to become available", region, name)); } catch (AWSResponseException e) { if (e.getError().getCode().equals("InvalidPlacementGroup.Duplicate")) { logger.debug("<< reused placementGroup(%s)", name); } else { throw e; } } }
@Test(enabled = false, dependsOnMethods = "testBundleInstance") void testAMIFromBundle() { volume = Iterables.getOnlyElement( client .getElasticBlockStoreServices() .describeVolumesInRegion(volume.getRegion(), volume.getId())); if (volume.getAttachments().size() > 0) { // should be cleanly unmounted, so force is not necessary. client .getElasticBlockStoreServices() .detachVolumeInRegion(instance.getRegion(), volume.getId(), false); System.out.printf( "%d: %s awaiting detachment to complete%n", System.currentTimeMillis(), volume.getId()); assert volumeTester.apply(volume); } else { attachment = null; // protect test closer so that it doesn't try to // detach } snapshot = client .getElasticBlockStoreServices() .createSnapshotInRegion( volume.getRegion(), volume.getId(), withDescription("EBS Ubuntu Hardy")); System.out.printf( "%d: %s awaiting snapshot to complete%n", System.currentTimeMillis(), snapshot.getId()); assert snapshotTester.apply(snapshot); Image image = Iterables.getOnlyElement( client .getAMIServices() .describeImagesInRegion(snapshot.getRegion(), imageIds(IMAGE_ID))); String description = image.getDescription() == null ? "jclouds" : image.getDescription(); System.out.printf( "%d: %s creating ami from snapshot%n", System.currentTimeMillis(), snapshot.getId()); String amiId = client .getAMIServices() .registerUnixImageBackedByEbsInRegion( snapshot.getRegion(), "ebsboot-" + image.getId(), snapshot.getId(), withKernelId(image.getKernelId()) .withRamdisk(image.getRamdiskId()) .withDescription(description) .asArchitecture(Architecture.I386)); try { ebsImage = Iterables.getOnlyElement( client .getAMIServices() .describeImagesInRegion(snapshot.getRegion(), imageIds(amiId))); } catch (AWSResponseException e) { // TODO add a retry handler for this HTTP code 400 and the below error if (e.getError().getClass().equals("InvalidAMIID.NotFound")) ebsImage = Iterables.getOnlyElement( client .getAMIServices() .describeImagesInRegion(snapshot.getRegion(), imageIds(amiId))); else throw e; } verifyImage(); }