From 96773b8a1b9b03b36daf966294db9e58464ffc38 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 30 May 2012 21:20:01 -0700 Subject: [PATCH] Issue 952:add status field to image --- ...oudServersComputeServiceContextModule.java | 74 +++++++++++------- .../CloudServersImageExtension.java | 2 +- .../functions/CloudServersImageToImage.java | 11 ++- ...erversComputeServiceContextModuleTest.java | 2 +- .../CloudServersImageToImageTest.java | 23 +++--- .../functions/ServerToNodeMetadataTest.java | 6 +- .../functions/PreinstalledDiskToImage.java | 3 +- .../compute/functions/TemplateToImage.java | 3 + .../functions/TemplateToImageTest.java | 12 +-- .../functions/DeltacloudImageToImage.java | 2 + .../EC2ComputeServiceDependenciesModule.java | 35 +++++++-- .../ec2/compute/functions/EC2ImageParser.java | 11 ++- .../ec2/compute/EC2TemplateBuilderTest.java | 4 + .../compute/functions/EC2ImageParserTest.java | 26 ++++--- .../RunningInstanceToNodeMetadataTest.java | 6 +- .../functions/WellKnownImageToImage.java | 2 + .../NovaComputeServiceContextModule.java | 24 +++++- .../compute/functions/NovaImageToImage.java | 10 ++- .../NovaComputeServiceContextModuleTest.java | 2 +- .../functions/NovaImageToImageTest.java | 16 ++-- .../functions/ServerToNodeMetadataTest.java | 6 +- .../strategy/NovaReviseParsedImageTest.java | 8 +- .../NovaComputeServiceContextModule.java | 42 ++++++++++ .../compute/functions/ImageInZoneToImage.java | 8 +- .../functions/ServerInZoneToNodeMetadata.java | 13 ++-- .../openstack/nova/v1_1/domain/Server.java | 19 +---- .../functions/ImageInZoneToImageTest.java | 33 +++----- .../functions/OrphanedGroupsByZoneIdTest.java | 11 ++- .../ServerInZoneToNodeMetadataTest.java | 23 +++--- ...CloudComputeServiceDependenciesModule.java | 50 +++++++++--- .../functions/ImageForVAppTemplate.java | 9 ++- .../org/jclouds/vcloud/domain/Status.java | 22 +++++- .../ListImagesInVCloudExpectTest.java | 3 + .../functions/VAppToNodeMetadataTest.java | 2 +- ...markVCloudComputeServiceContextModule.java | 34 ++++++-- .../ImageForVCloudExpressVAppTemplate.java | 8 +- ...VCloudComputeServiceContextModuleTest.java | 2 +- .../org/jclouds/compute/domain/Image.java | 27 ++++++- .../jclouds/compute/domain/ImageBuilder.java | 44 +++-------- .../compute/domain/internal/ImageImpl.java | 34 ++++---- .../config/StubComputeServiceAdapter.java | 2 +- .../internal/TemplateBuilderImplTest.java | 5 +- .../compute/functions/OSTemplateToImage.java | 3 +- .../functions/CIMOperatingSystemToImage.java | 2 + .../functions/ImageForVAppTemplate.java | 9 ++- .../VCloudDirectorRestClientModule.java | 1 - ...VirtualBoxComputeServiceContextModule.java | 78 ++++++++++++++----- .../jclouds/virtualbox/domain/YamlImage.java | 2 +- .../virtualbox/functions/IMachineToImage.java | 8 +- .../functions/IMachineToNodeMetadata.java | 8 +- .../virtualbox/functions/NodeCreator.java | 2 +- .../VirtualBoxComputeServiceAdapterTest.java | 4 +- .../functions/IMachineToImageTest.java | 18 ++++- .../functions/IMachineToNodeMetadataTest.java | 7 +- .../admin/ImageFromYamlStringTest.java | 5 +- .../AWSRunningInstanceToNodeMetadataTest.java | 2 +- .../strategy/AWSEC2ImageParserTest.java | 40 ++++++---- .../strategy/AWSEC2ReviseParsedImageTest.java | 6 +- ...ptusPartnerCloudReviseParsedImageTest.java | 20 +++-- .../GoGridComputeServiceContextModule.java | 37 ++++++--- .../compute/functions/ServerImageToImage.java | 10 ++- ...GoGridComputeServiceContextModuleTest.java | 2 +- .../suppliers/RimuHostingImageSupplier.java | 2 + .../functions/SlicehostImageToImage.java | 1 + .../functions/SlicehostImageToImageTest.java | 17 ++-- .../compute/functions/ProductItemToImage.java | 1 + .../functions/ProductItemToImageTest.java | 2 +- .../VirtualGuestToNodeMetadataTest.java | 3 +- .../functions/ServerManagerImageToImage.java | 2 + 69 files changed, 663 insertions(+), 308 deletions(-) diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index 8ab0b09680..2ac13e1994 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -30,6 +30,7 @@ import org.jclouds.cloudservers.compute.functions.ServerToNodeMetadata; import org.jclouds.cloudservers.compute.predicates.GetImageWhenStatusActivePredicateWithResult; import org.jclouds.cloudservers.compute.strategy.CloudServersComputeServiceAdapter; import org.jclouds.cloudservers.domain.Flavor; +import org.jclouds.cloudservers.domain.ImageStatus; import org.jclouds.cloudservers.domain.Server; import org.jclouds.cloudservers.domain.ServerStatus; import org.jclouds.compute.ComputeServiceAdapter; @@ -38,7 +39,6 @@ import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.NodeMetadata.Status; import org.jclouds.compute.extensions.ImageExtension; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.domain.Location; @@ -93,36 +93,54 @@ public class CloudServersComputeServiceContextModule extends } @VisibleForTesting - public static final Map serverToNodeStatus = ImmutableMap - . builder().put(ServerStatus.ACTIVE, Status.RUNNING)// - .put(ServerStatus.SUSPENDED, Status.SUSPENDED)// - .put(ServerStatus.DELETED, Status.TERMINATED)// - .put(ServerStatus.QUEUE_RESIZE, Status.PENDING)// - .put(ServerStatus.PREP_RESIZE, Status.PENDING)// - .put(ServerStatus.RESIZE, Status.PENDING)// - .put(ServerStatus.VERIFY_RESIZE, Status.PENDING)// - .put(ServerStatus.QUEUE_MOVE, Status.PENDING)// - .put(ServerStatus.PREP_MOVE, Status.PENDING)// - .put(ServerStatus.MOVE, Status.PENDING)// - .put(ServerStatus.VERIFY_MOVE, Status.PENDING)// - .put(ServerStatus.RESCUE, Status.PENDING)// - .put(ServerStatus.ERROR, Status.ERROR)// - .put(ServerStatus.BUILD, Status.PENDING)// - .put(ServerStatus.RESTORING, Status.PENDING)// - .put(ServerStatus.PASSWORD, Status.PENDING)// - .put(ServerStatus.REBUILD, Status.PENDING)// - .put(ServerStatus.DELETE_IP, Status.PENDING)// - .put(ServerStatus.SHARE_IP_NO_CONFIG, Status.PENDING)// - .put(ServerStatus.SHARE_IP, Status.PENDING)// - .put(ServerStatus.REBOOT, Status.PENDING)// - .put(ServerStatus.HARD_REBOOT, Status.PENDING)// - .put(ServerStatus.UNKNOWN, Status.UNRECOGNIZED)// - .put(ServerStatus.UNRECOGNIZED, Status.UNRECOGNIZED).build(); + public static final Map toPortableNodeStatus = ImmutableMap + . builder() + .put(ServerStatus.ACTIVE, NodeMetadata.Status.RUNNING) + .put(ServerStatus.SUSPENDED, NodeMetadata.Status.SUSPENDED) + .put(ServerStatus.DELETED, NodeMetadata.Status.TERMINATED) + .put(ServerStatus.QUEUE_RESIZE, NodeMetadata.Status.PENDING) + .put(ServerStatus.PREP_RESIZE, NodeMetadata.Status.PENDING) + .put(ServerStatus.RESIZE, NodeMetadata.Status.PENDING) + .put(ServerStatus.VERIFY_RESIZE, NodeMetadata.Status.PENDING) + .put(ServerStatus.QUEUE_MOVE, NodeMetadata.Status.PENDING) + .put(ServerStatus.PREP_MOVE, NodeMetadata.Status.PENDING) + .put(ServerStatus.MOVE, NodeMetadata.Status.PENDING) + .put(ServerStatus.VERIFY_MOVE, NodeMetadata.Status.PENDING) + .put(ServerStatus.RESCUE, NodeMetadata.Status.PENDING) + .put(ServerStatus.ERROR, NodeMetadata.Status.ERROR) + .put(ServerStatus.BUILD, NodeMetadata.Status.PENDING) + .put(ServerStatus.RESTORING, NodeMetadata.Status.PENDING) + .put(ServerStatus.PASSWORD, NodeMetadata.Status.PENDING) + .put(ServerStatus.REBUILD, NodeMetadata.Status.PENDING) + .put(ServerStatus.DELETE_IP, NodeMetadata.Status.PENDING) + .put(ServerStatus.SHARE_IP_NO_CONFIG, NodeMetadata.Status.PENDING) + .put(ServerStatus.SHARE_IP, NodeMetadata.Status.PENDING) + .put(ServerStatus.REBOOT, NodeMetadata.Status.PENDING) + .put(ServerStatus.HARD_REBOOT, NodeMetadata.Status.PENDING) + .put(ServerStatus.UNKNOWN, NodeMetadata.Status.UNRECOGNIZED) + .put(ServerStatus.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).build(); @Singleton @Provides - Map provideServerToNodeStatus() { - return serverToNodeStatus; + Map toPortableNodeStatus() { + return toPortableNodeStatus; + } + + @VisibleForTesting + public static final Map toPortableImageStatus = ImmutableMap + . builder() + .put(ImageStatus.ACTIVE, Image.Status.AVAILABLE) + .put(ImageStatus.SAVING, Image.Status.PENDING) + .put(ImageStatus.PREPARING, Image.Status.PENDING) + .put(ImageStatus.QUEUED, Image.Status.PENDING) + .put(ImageStatus.FAILED, Image.Status.ERROR) + .put(ImageStatus.UNKNOWN, Image.Status.UNRECOGNIZED) + .put(ImageStatus.UNRECOGNIZED, Image.Status.UNRECOGNIZED).build(); + + @Singleton + @Provides + Map toPortableImageStatus() { + return toPortableImageStatus; } @Override diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/extensions/CloudServersImageExtension.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/extensions/CloudServersImageExtension.java index 946e6e1017..24f4e4e873 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/extensions/CloudServersImageExtension.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/extensions/CloudServersImageExtension.java @@ -52,7 +52,7 @@ import com.google.common.util.concurrent.ListenableFuture; * CloudServers implementation of {@link ImageExtension} * * @author David Alves - * + * @see docs */ @Singleton public class CloudServersImageExtension implements ImageExtension { diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/functions/CloudServersImageToImage.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/functions/CloudServersImageToImage.java index bedecffe6b..68727aca42 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/functions/CloudServersImageToImage.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/functions/CloudServersImageToImage.java @@ -18,12 +18,16 @@ */ package org.jclouds.cloudservers.compute.functions; +import java.util.Map; + import javax.inject.Inject; import javax.inject.Singleton; +import org.jclouds.cloudservers.domain.ImageStatus; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.Image.Status; import com.google.common.base.Function; @@ -33,13 +37,15 @@ import com.google.common.base.Function; */ @Singleton public class CloudServersImageToImage implements Function { + private final Map toPortableImageStatus; private final Function imageToOs; @Inject - CloudServersImageToImage(Function imageToOs) { + CloudServersImageToImage(Map toPortableImageStatus, Function imageToOs) { + this.toPortableImageStatus=toPortableImageStatus; this.imageToOs = imageToOs; } - + public Image apply(org.jclouds.cloudservers.domain.Image from) { ImageBuilder builder = new ImageBuilder(); builder.ids(from.getId() + ""); @@ -47,6 +53,7 @@ public class CloudServersImageToImage implements Function serverStateToNodeStatus = CloudServersComputeServiceContextModule.serverToNodeStatus; + Map serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus; Set images = ImmutableSet.of(); Set hardwares = ImmutableSet.of(); Server server = ParseServerFromJsonResponseTest.parseServer(); @@ -91,7 +91,7 @@ public class ServerToNodeMetadataTest { @Test public void testApplyWhereImageFoundAndHardwareNotFound() { - Map serverStateToNodeStatus = CloudServersComputeServiceContextModule.serverToNodeStatus; + Map serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus; org.jclouds.compute.domain.Image jcImage = CloudServersImageToImageTest.convertImage(); Set images = ImmutableSet.of(jcImage); Set hardwares = ImmutableSet.of(); @@ -126,7 +126,7 @@ public class ServerToNodeMetadataTest { @Test public void testApplyWhereImageAndHardwareFound() { - Map serverStateToNodeStatus = CloudServersComputeServiceContextModule.serverToNodeStatus; + Map serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus; Set images = ImmutableSet.of(CloudServersImageToImageTest.convertImage()); Set hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor()); Server server = ParseServerFromJsonResponseTest.parseServer(); diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java index 356fc1bec9..56b827c167 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java @@ -26,6 +26,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamilyVersion64Bit; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.domain.OperatingSystem.Builder; import org.jclouds.domain.Location; @@ -61,6 +62,6 @@ public class PreinstalledDiskToImage implements Function { return new ImageBuilder().ids(drive.getUuid()) .userMetadata(ImmutableMap. of("size", drive.getSize() / 1024 / 1024 / 1024 + "")) .location(locationSupplier.get()).name(drive.getName()).description(description) - .operatingSystem(builder.build()).version("").build(); + .operatingSystem(builder.build()).status(Status.AVAILABLE).version("").build(); } } \ No newline at end of file diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/TemplateToImage.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/TemplateToImage.java index 5384178636..f3c1ba4614 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/TemplateToImage.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/TemplateToImage.java @@ -31,6 +31,7 @@ import org.jclouds.collect.Memoized; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.domain.Location; import com.google.common.base.Function; @@ -62,6 +63,8 @@ public class TemplateToImage implements Function { if (!template.isCrossZones()) builder.location(findLocationForTemplate.apply(template)); + //TODO: implement status mapping!!! + builder.status(Status.AVAILABLE); return builder.build(); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/TemplateToImageTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/TemplateToImageTest.java index 83bcefd268..413f608004 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/TemplateToImageTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/TemplateToImageTest.java @@ -27,6 +27,7 @@ import org.jclouds.cloudstack.domain.Template; import org.jclouds.cloudstack.parse.ListTemplatesResponseTest; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.domain.Location; import org.testng.annotations.Test; @@ -51,20 +52,21 @@ public class TemplateToImageTest { // location free image static Image one = new ImageBuilder().id("2").providerId("2").name("CentOS 5.3(64-bit) no GUI (XenServer)") .operatingSystem(TemplateToOperatingSystemTest.one).description("CentOS 5.3(64-bit) no GUI (XenServer)") - .build(); + .status(Status.AVAILABLE).build(); // location free image static Image two = new ImageBuilder().id("4").providerId("4").name("CentOS 5.5(64-bit) no GUI (KVM)") - .operatingSystem(TemplateToOperatingSystemTest.two).description("CentOS 5.5(64-bit) no GUI (KVM)").build(); + .operatingSystem(TemplateToOperatingSystemTest.two).description("CentOS 5.5(64-bit) no GUI (KVM)") + .status(Status.AVAILABLE).build(); static Image three = new ImageBuilder().id("203").providerId("203").name("Windows 7 KVM") .operatingSystem(TemplateToOperatingSystemTest.three).description("Windows 7 KVM") - .location(ZoneToLocationTest.two).build(); + .location(ZoneToLocationTest.two).status(Status.AVAILABLE).build(); // location free image static Image four = new ImageBuilder().id("7").providerId("7").name("CentOS 5.3(64-bit) no GUI (vSphere)") .operatingSystem(TemplateToOperatingSystemTest.four).description("CentOS 5.3(64-bit) no GUI (vSphere)") - .build(); + .status(Status.AVAILABLE).build(); static Image five = new ImageBuilder().id("241").providerId("241").name("kvmdev4") .operatingSystem(TemplateToOperatingSystemTest.five).description("v5.6.28_Dev4") - .location(ZoneToLocationTest.two).build(); + .location(ZoneToLocationTest.two).status(Status.AVAILABLE).build(); @Test public void test() { diff --git a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/compute/functions/DeltacloudImageToImage.java b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/compute/functions/DeltacloudImageToImage.java index a887502041..b8ad9edd0a 100644 --- a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/compute/functions/DeltacloudImageToImage.java +++ b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/compute/functions/DeltacloudImageToImage.java @@ -23,6 +23,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.Image.Status; import com.google.common.base.Function; @@ -47,6 +48,7 @@ public class DeltacloudImageToImage implements Function instanceToNodeStatus = ImmutableMap - . builder().put(InstanceState.PENDING, Status.PENDING).put( - InstanceState.RUNNING, Status.RUNNING).put(InstanceState.SHUTTING_DOWN, Status.PENDING).put( - InstanceState.TERMINATED, Status.TERMINATED).put(InstanceState.STOPPING, Status.PENDING) - .put(InstanceState.STOPPED, Status.SUSPENDED).put(InstanceState.UNRECOGNIZED, Status.UNRECOGNIZED) + public static final Map toPortableNodeStatus = ImmutableMap + . builder() + .put(InstanceState.PENDING, Status.PENDING) + .put(InstanceState.RUNNING, Status.RUNNING) + .put(InstanceState.SHUTTING_DOWN, Status.PENDING) + .put(InstanceState.TERMINATED, Status.TERMINATED) + .put(InstanceState.STOPPING, Status.PENDING) + .put(InstanceState.STOPPED, Status.SUSPENDED) + .put(InstanceState.UNRECOGNIZED, Status.UNRECOGNIZED) .build(); + + @Singleton + @Provides + protected Map toPortableNodeStatus() { + return toPortableNodeStatus; + } + + @VisibleForTesting + public static final Map toPortableImageStatus = ImmutableMap + . builder() + .put(ImageState.AVAILABLE, Image.Status.AVAILABLE) + .put(ImageState.DEREGISTERED, Image.Status.DELETED) + .put(ImageState.UNRECOGNIZED, Image.Status.UNRECOGNIZED).build(); @Singleton @Provides - Map provideServerToNodeStatus() { - return instanceToNodeStatus; + protected Map toPortableImageStatus() { + return toPortableImageStatus; } - + @Override protected void configure() { bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java index 7f14e25ad5..b500d94dbe 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java @@ -35,6 +35,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.util.ComputeServiceUtils; @@ -43,6 +44,7 @@ import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; import org.jclouds.ec2.compute.strategy.ReviseParsedImage; import org.jclouds.ec2.domain.Image.Architecture; +import org.jclouds.ec2.domain.Image.ImageState; import org.jclouds.ec2.domain.Image.ImageType; import org.jclouds.logging.Logger; @@ -60,17 +62,21 @@ public class EC2ImageParser implements Function toPortableImageStatus; private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider; private final Supplier> locations; private final Supplier defaultLocation; private final Map> osVersionMap; private final ReviseParsedImage reviseParsedImage; + @Inject - public EC2ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, + public EC2ImageParser(Map toPortableImageStatus, + PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, Map> osVersionMap, @Memoized Supplier> locations, Supplier defaultLocation, ReviseParsedImage reviseParsedImage) { + this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus"); this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); this.locations = checkNotNull(locations, "locations"); this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); @@ -120,6 +126,7 @@ public class EC2ImageParser implements Function imageMap = ImmutableMap.of( new RegionAndName(image.getLocation().getId(), image.getProviderId()), image); @@ -190,10 +192,12 @@ public class EC2TemplateBuilderTest { new ImageBuilder().providerId("cc-image").name("image").id("us-east-1/cc-image").location(location) .operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", "hvm", "ubuntu", true)) .description("description").version("1.0").defaultCredentials(new LoginCredentials("root", false)) + .status(Image.Status.AVAILABLE) .build(), new ImageBuilder().providerId("normal-image").name("image").id("us-east-1/normal-image").location(location) .operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", "paravirtual", "ubuntu", true)) .description("description").version("1.0").defaultCredentials(new LoginCredentials("root", false)) + .status(Image.Status.AVAILABLE) .build())); // weird compilation error means have to cast this - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=365818 diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java index 147210fdcc..1485987c28 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java @@ -32,6 +32,7 @@ import org.jclouds.domain.Location; import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; import org.jclouds.domain.LoginCredentials; +import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule; import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.ec2.compute.strategy.ReviseParsedImage; import org.jclouds.ec2.domain.Image; @@ -51,26 +52,32 @@ import com.google.inject.Guice; /** * @author Adrian Cole */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "EC2ImageParserTest") public class EC2ImageParserTest { public void testParseAmznImage() { Set result = convertImages("/amzn_images.xml"); + for (org.jclouds.compute.domain.Image image : result) + assertEquals(image.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description( "137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).description("Amazon") - .defaultCredentials(new LoginCredentials("ec2-user", false)).id("us-east-1/ami-82e4b5c7").name("amzn-ami-0.9.7-beta.i386-ebs") - .providerId("ami-82e4b5c7").location(defaultLocation).userMetadata( - ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build()); + .defaultCredentials(new LoginCredentials("ec2-user", false)).id("us-east-1/ami-82e4b5c7").name( + "amzn-ami-0.9.7-beta.i386-ebs").providerId("ami-82e4b5c7").location(defaultLocation) + .userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).status( + org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); assertEquals(Iterables.get(result, 3), new ImageBuilder().operatingSystem( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description( "amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true).build()) - .description("Amazon Linux AMI x86_64 S3").defaultCredentials(new LoginCredentials("ec2-user", false)).id( - "us-east-1/ami-f2e4b5b7").providerId("ami-f2e4b5b7").name("amzn-ami-0.9.7-beta.x86_64-S3").location(defaultLocation) - .userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build()); + .description("Amazon Linux AMI x86_64 S3").defaultCredentials(new LoginCredentials("ec2-user", false)) + .id("us-east-1/ami-f2e4b5b7").providerId("ami-f2e4b5b7").name("amzn-ami-0.9.7-beta.x86_64-S3").location( + defaultLocation) + .userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).status( + org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); + ; } static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description( @@ -83,8 +90,9 @@ public class EC2ImageParserTest { .getInstance(Json.class)); Set result = DescribeImagesResponseHandlerTest.parseImages(resource); - EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, - Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers + EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus, + new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers + .> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers .ofInstance(defaultLocation), new ReviseParsedImage.NoopReviseParsedImage()); return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index ad62257ee3..be44775af5 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -68,7 +68,7 @@ public class RunningInstanceToNodeMetadataTest { public void testAllStatesCovered() { for (InstanceState status : InstanceState.values()) { - assert EC2ComputeServiceDependenciesModule.instanceToNodeStatus.containsKey(status) : status; + assert EC2ComputeServiceDependenciesModule.toPortableNodeStatus.containsKey(status) : status; } } @@ -210,7 +210,7 @@ public class RunningInstanceToNodeMetadataTest { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet .of(provider), ImmutableMap. of(), - EC2ComputeServiceDependenciesModule.instanceToNodeStatus, instanceToImage); + EC2ComputeServiceDependenciesModule.toPortableNodeStatus, instanceToImage); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); @@ -245,7 +245,7 @@ public class RunningInstanceToNodeMetadataTest { protected RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, final ImmutableSet locations, final Set images, Map credentialStore) { - Map instanceToNodeStatus = EC2ComputeServiceDependenciesModule.instanceToNodeStatus; + Map instanceToNodeStatus = EC2ComputeServiceDependenciesModule.toPortableNodeStatus; CacheLoader getRealImage = new CacheLoader() { diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/WellKnownImageToImage.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/WellKnownImageToImage.java index 771c3e3593..27c5052eb3 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/WellKnownImageToImage.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/WellKnownImageToImage.java @@ -26,6 +26,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LoginCredentials; @@ -67,6 +68,7 @@ public class WellKnownImageToImage implements Function { .location(locationSupplier.get()) .name(input.getDescription()) .description(drive.getName()) + .status(Status.AVAILABLE) .operatingSystem( new OperatingSystem.Builder().family(input.getOsFamily()).version(input.getOsVersion()) .name(input.getDescription()).description(drive.getName()).is64Bit(input.is64bit()).build()) diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/compute/config/NovaComputeServiceContextModule.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/compute/config/NovaComputeServiceContextModule.java index 8d2d1c720d..907fa13e77 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/compute/config/NovaComputeServiceContextModule.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/compute/config/NovaComputeServiceContextModule.java @@ -38,6 +38,7 @@ import org.jclouds.openstack.nova.compute.functions.NovaImageToOperatingSystem; import org.jclouds.openstack.nova.compute.functions.ServerToNodeMetadata; import org.jclouds.openstack.nova.compute.strategy.NovaComputeServiceAdapter; import org.jclouds.openstack.nova.domain.Flavor; +import org.jclouds.openstack.nova.domain.ImageStatus; import org.jclouds.openstack.nova.domain.Server; import org.jclouds.openstack.nova.domain.ServerStatus; @@ -80,7 +81,7 @@ public class NovaComputeServiceContextModule extends } @VisibleForTesting - public static final Map serverToNodeStatus = ImmutableMap + public static final Map toPortableNodeStatus = ImmutableMap . builder().put(ServerStatus.ACTIVE, Status.RUNNING)// .put(ServerStatus.SUSPENDED, Status.SUSPENDED)// .put(ServerStatus.DELETED, Status.TERMINATED)// @@ -100,8 +101,25 @@ public class NovaComputeServiceContextModule extends @Singleton @Provides - Map provideServerToNodeStatus() { - return serverToNodeStatus; + Map toPortableNodeStatus() { + return toPortableNodeStatus; } + + @VisibleForTesting + public static final Map toPortableImageStatus = ImmutableMap + . builder() + .put(ImageStatus.ACTIVE, Image.Status.AVAILABLE) + .put(ImageStatus.SAVING, Image.Status.PENDING) + .put(ImageStatus.PREPARING, Image.Status.PENDING) + .put(ImageStatus.QUEUED, Image.Status.PENDING) + .put(ImageStatus.FAILED, Image.Status.ERROR) + .put(ImageStatus.UNKNOWN, Image.Status.UNRECOGNIZED) + .put(ImageStatus.UNRECOGNIZED, Image.Status.UNRECOGNIZED).build(); + @Singleton + @Provides + Map toPortableImageStatus() { + return toPortableImageStatus; + } + } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/compute/functions/NovaImageToImage.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/compute/functions/NovaImageToImage.java index ef811ad851..154fbecb18 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/compute/functions/NovaImageToImage.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/compute/functions/NovaImageToImage.java @@ -18,12 +18,16 @@ */ package org.jclouds.openstack.nova.compute.functions; +import java.util.Map; + import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.Image.Status; +import org.jclouds.openstack.nova.domain.ImageStatus; import com.google.common.base.Function; @@ -33,10 +37,13 @@ import com.google.common.base.Function; */ @Singleton public class NovaImageToImage implements Function { + private final Map toPortableImageStatus; private final Function imageToOs; @Inject - NovaImageToImage(Function imageToOs) { + NovaImageToImage(Map toPortableImageStatus, + Function imageToOs) { + this.toPortableImageStatus = toPortableImageStatus; this.imageToOs = imageToOs; } @@ -47,6 +54,7 @@ public class NovaImageToImage implements Function serverStateToNodeStatus = NovaComputeServiceContextModule.serverToNodeStatus; + Map serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus; Set images = ImmutableSet.of(); Set hardwares = ImmutableSet.of(); Server server = ParseServerFromJsonResponseTest.parseServer(); @@ -100,7 +100,7 @@ public class ServerToNodeMetadataTest { @Test public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException, URISyntaxException { - Map serverStateToNodeStatus = NovaComputeServiceContextModule.serverToNodeStatus; + Map serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus; org.jclouds.compute.domain.Image jcImage = NovaImageToImageTest.convertImage(); Set images = ImmutableSet.of(jcImage); Set hardwares = ImmutableSet.of(); @@ -125,7 +125,7 @@ public class ServerToNodeMetadataTest { @Test public void testApplyWhereImageAndHardwareFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException, URISyntaxException { - Map serverStateToNodeStatus = NovaComputeServiceContextModule.serverToNodeStatus; + Map serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus; Set images = ImmutableSet.of(NovaImageToImageTest.convertImage()); Set hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor()); Server server = ParseServerFromJsonResponseTest.parseServer(); diff --git a/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/strategy/NovaReviseParsedImageTest.java b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/strategy/NovaReviseParsedImageTest.java index d5b79955f9..e26338179c 100644 --- a/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/strategy/NovaReviseParsedImageTest.java +++ b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/strategy/NovaReviseParsedImageTest.java @@ -32,6 +32,7 @@ import org.jclouds.domain.Location; import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; import org.jclouds.domain.LoginCredentials; +import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule; import org.jclouds.ec2.compute.functions.EC2ImageParser; import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.ec2.domain.Image; @@ -74,9 +75,11 @@ public class NovaReviseParsedImageTest { .id("us-east-1/ami-000004d6") .providerId("ami-000004d6") .location(defaultLocation) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE) .userMetadata( ImmutableMap.of("owner", "", "rootDeviceType", "instance-store", "virtualizationType", "paravirtual", "hypervisor", "xen")).build().toString()); + assertEquals(Iterables.get(result, 4).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); } static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description( @@ -89,8 +92,9 @@ public class NovaReviseParsedImageTest { .getInstance(Json.class)); Set result = DescribeImagesResponseHandlerTest.parseImages(resource); - EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, - Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers + EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus, + new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers + .> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers .ofInstance(defaultLocation), new NovaReviseParsedImage(new ImageToOperatingSystem(map))); return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/config/NovaComputeServiceContextModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/config/NovaComputeServiceContextModule.java index 17f081a5fd..3576c11fb2 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/config/NovaComputeServiceContextModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/config/NovaComputeServiceContextModule.java @@ -61,6 +61,7 @@ import org.jclouds.openstack.nova.v1_1.compute.options.NovaTemplateOptions; import org.jclouds.openstack.nova.v1_1.compute.predicates.GetImageWhenImageInZoneHasActiveStatusPredicateWithResult; import org.jclouds.openstack.nova.v1_1.compute.strategy.ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet; import org.jclouds.openstack.nova.v1_1.domain.KeyPair; +import org.jclouds.openstack.nova.v1_1.domain.Server; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.FlavorInZone; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ImageInZone; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.SecurityGroupInZone; @@ -72,6 +73,7 @@ import org.jclouds.openstack.nova.v1_1.predicates.FindSecurityGroupWithNameAndRe import org.jclouds.predicates.PredicateWithResult; import org.jclouds.predicates.RetryablePredicate; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; @@ -217,6 +219,46 @@ public class NovaComputeServiceContextModule extends }, locations); } + + @VisibleForTesting + public static final Map toPortableNodeStatus = ImmutableMap + . builder().put(Server.Status.ACTIVE, NodeMetadata.Status.RUNNING)// + .put(Server.Status.SUSPENDED, NodeMetadata.Status.SUSPENDED)// + .put(Server.Status.DELETED, NodeMetadata.Status.TERMINATED)// + .put(Server.Status.PAUSED, NodeMetadata.Status.SUSPENDED)// + .put(Server.Status.RESIZE, NodeMetadata.Status.PENDING)// + .put(Server.Status.VERIFY_RESIZE, NodeMetadata.Status.PENDING)// + .put(Server.Status.REVERT_RESIZE, NodeMetadata.Status.PENDING)// + .put(Server.Status.BUILD, NodeMetadata.Status.PENDING)// + .put(Server.Status.PASSWORD, NodeMetadata.Status.PENDING)// + .put(Server.Status.REBUILD, NodeMetadata.Status.PENDING)// + .put(Server.Status.ERROR, NodeMetadata.Status.ERROR)// + .put(Server.Status.REBOOT, NodeMetadata.Status.PENDING)// + .put(Server.Status.HARD_REBOOT, NodeMetadata.Status.PENDING)// + .put(Server.Status.UNKNOWN, NodeMetadata.Status.UNRECOGNIZED)// + .put(Server.Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).build(); + + @Singleton + @Provides + protected Map toPortableNodeStatus() { + return toPortableNodeStatus; + } + + @VisibleForTesting + public static final Map toPortableImageStatus = ImmutableMap + . builder() + .put(org.jclouds.openstack.nova.v1_1.domain.Image.Status.ACTIVE, Image.Status.AVAILABLE) + .put(org.jclouds.openstack.nova.v1_1.domain.Image.Status.SAVING, Image.Status.PENDING) + .put(org.jclouds.openstack.nova.v1_1.domain.Image.Status.DELETED, Image.Status.DELETED) + .put(org.jclouds.openstack.nova.v1_1.domain.Image.Status.ERROR, Image.Status.ERROR) + .put(org.jclouds.openstack.nova.v1_1.domain.Image.Status.UNKNOWN, Image.Status.UNRECOGNIZED) + .put(org.jclouds.openstack.nova.v1_1.domain.Image.Status.UNRECOGNIZED, Image.Status.UNRECOGNIZED).build(); + + @Singleton + @Provides + protected Map toPortableImageStatus() { + return toPortableImageStatus; + } @Override protected Optional provideImageExtension(Injector i) { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ImageInZoneToImage.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ImageInZoneToImage.java index 68f6d03c62..5428b43223 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ImageInZoneToImage.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ImageInZoneToImage.java @@ -29,6 +29,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.domain.Location; +import org.jclouds.openstack.nova.v1_1.domain.Image.Status; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ImageInZone; import com.google.common.base.Function; @@ -40,12 +41,15 @@ import com.google.common.base.Supplier; * @author Matt Stephenson */ public class ImageInZoneToImage implements Function { + private final Map toPortableImageStatus; private final Function imageToOs; private final Supplier> locationIndex; @Inject - public ImageInZoneToImage(Function imageToOs, + public ImageInZoneToImage(Map toPortableImageStatus, + Function imageToOs, Supplier> locationIndex) { + this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus"); this.imageToOs = checkNotNull(imageToOs, "imageToOs"); this.locationIndex = checkNotNull(locationIndex, "locationIndex"); } @@ -57,6 +61,6 @@ public class ImageInZoneToImage implements Function { org.jclouds.openstack.nova.v1_1.domain.Image image = imageInZone.getImage(); return new ImageBuilder().id(imageInZone.slashEncode()).providerId(image.getId()).name(image.getName()) .userMetadata(image.getMetadata()).operatingSystem(imageToOs.apply(image)).description(image.getName()) - .location(location).build(); + .location(location).status(toPortableImageStatus.get(image.getStatus())).build(); } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerInZoneToNodeMetadata.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerInZoneToNodeMetadata.java index 0c8433be2b..bc0cf80e53 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerInZoneToNodeMetadata.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerInZoneToNodeMetadata.java @@ -49,6 +49,7 @@ import org.jclouds.domain.LocationScope; import org.jclouds.logging.Logger; import org.jclouds.openstack.nova.v1_1.domain.Address; import org.jclouds.openstack.nova.v1_1.domain.Server; +import org.jclouds.openstack.nova.v1_1.domain.Server.Status; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ServerInZone; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ZoneAndId; import org.jclouds.util.InetAddresses2; @@ -69,16 +70,18 @@ public class ServerInZoneToNodeMetadata implements Function toPortableNodeStatus; protected final Supplier> locationIndex; protected final Supplier> images; protected final Supplier> hardwares; protected final GroupNamingConvention nodeNamingConvention; @Inject - public ServerInZoneToNodeMetadata(Supplier> locationIndex, - @Memoized Supplier> images, @Memoized Supplier> hardwares, - GroupNamingConvention.Factory namingConvention) { + public ServerInZoneToNodeMetadata(Map toPortableNodeStatus, + Supplier> locationIndex, @Memoized Supplier> images, + @Memoized Supplier> hardwares, GroupNamingConvention.Factory namingConvention) { + this.toPortableNodeStatus = checkNotNull(toPortableNodeStatus, "toPortableNodeStatus"); this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix(); this.locationIndex = checkNotNull(locationIndex, "locationIndex"); this.images = checkNotNull(images, "images"); @@ -103,7 +106,7 @@ public class ServerInZoneToNodeMetadata implements Function { - - private final OperatingSystem operatingSystem; - - public MockImageToOsConverter(OperatingSystem operatingSystem) { - this.operatingSystem = operatingSystem; - } - - @Override - public OperatingSystem apply(@Nullable Image image) { - return operatingSystem; - } - - @Override - public boolean equals(@Nullable Object o) { - return false; - } + @SuppressWarnings("unchecked") + private static Function constant(OperatingSystem operatingSystem){ + return Function.class.cast(Functions.constant(operatingSystem)); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/OrphanedGroupsByZoneIdTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/OrphanedGroupsByZoneIdTest.java index baf47f8329..215f1ba836 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/OrphanedGroupsByZoneIdTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/OrphanedGroupsByZoneIdTest.java @@ -30,6 +30,7 @@ import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.domain.Location; import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; +import org.jclouds.openstack.nova.v1_1.compute.config.NovaComputeServiceContextModule; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ServerInZone; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ZoneAndName; import org.jclouds.openstack.nova.v1_1.parse.ParseServerTest; @@ -66,7 +67,8 @@ public class OrphanedGroupsByZoneIdTest { ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1"); - ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(locationIndex, Suppliers + ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata( + NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .> ofInstance(ImmutableSet. of()), Suppliers .> ofInstance(ImmutableSet. of()), namingConvention); @@ -82,9 +84,10 @@ public class OrphanedGroupsByZoneIdTest { ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1"); - ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(locationIndex, Suppliers - .> ofInstance(ImmutableSet. of()), Suppliers - .> ofInstance(ImmutableSet. of()), namingConvention); + ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata( + NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers + .> ofInstance(ImmutableSet. of()), Suppliers + .> ofInstance(ImmutableSet. of()), namingConvention); Set set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerInZoneToNodeMetadataTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerInZoneToNodeMetadataTest.java index c19306fbc6..6b9f64b290 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerInZoneToNodeMetadataTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerInZoneToNodeMetadataTest.java @@ -39,6 +39,7 @@ import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; import org.jclouds.openstack.domain.Link; import org.jclouds.openstack.domain.Resource; +import org.jclouds.openstack.nova.v1_1.compute.config.NovaComputeServiceContextModule; import org.jclouds.openstack.nova.v1_1.domain.Server; import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ServerInZone; import org.jclouds.openstack.nova.v1_1.parse.ParseServerTest; @@ -75,7 +76,7 @@ public class ServerInZoneToNodeMetadataTest { .location(zone).build(); Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/FOOOOOOOO") .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build()) - .providerId("FOOOOOOOO").description("foobuntu").location(zone).build(); + .providerId("FOOOOOOOO").description("foobuntu").location(zone).status(Image.Status.AVAILABLE).build(); checkHardwareAndImageStatus(null, existingHardware, "az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54", null, existingImage); @@ -88,7 +89,8 @@ public class ServerInZoneToNodeMetadataTest { .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build(); Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54") .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build()) - .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").location(zone).build(); + .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE) + .location(zone).build(); checkHardwareAndImageStatus(existingHardware, existingHardware, existingImage.getId(), existingImage.getOperatingSystem(), existingImage); @@ -105,9 +107,10 @@ public class ServerInZoneToNodeMetadataTest { ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1"); - ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(locationIndex, - Suppliers.> ofInstance(images), - Suppliers.> ofInstance(hardwares), namingConvention); + ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata( + NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers + .> ofInstance(images), Suppliers + .> ofInstance(hardwares), namingConvention); NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert); @@ -127,7 +130,8 @@ public class ServerInZoneToNodeMetadataTest { assertEquals(convertedNodeMetadata.getHardware(), expectedHardware); - assertEquals(serverToConvert.getStatus().getNodeStatus(), convertedNodeMetadata.getStatus()); + assertEquals(NovaComputeServiceContextModule.toPortableNodeStatus.get(serverToConvert.getStatus()), + convertedNodeMetadata.getStatus()); assertNotNull(convertedNodeMetadata.getPrivateAddresses()); assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16")); @@ -151,9 +155,10 @@ public class ServerInZoneToNodeMetadataTest { ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1"); - ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(locationIndex, - Suppliers.> ofInstance(images), - Suppliers.> ofInstance(hardwares), namingConvention); + ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata( + NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers + .> ofInstance(images), Suppliers + .> ofInstance(hardwares), namingConvention); NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java index 1207c540ac..0a0d7129c2 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java @@ -64,18 +64,50 @@ import com.google.inject.TypeLiteral; public class VCloudComputeServiceDependenciesModule extends AbstractModule { @VisibleForTesting - public static final Map VAPPSTATUS_TO_NODESTATE = ImmutableMap. builder().put( - Status.OFF, NodeMetadata.Status.SUSPENDED).put(Status.ON, NodeMetadata.Status.RUNNING).put(Status.RESOLVED, NodeMetadata.Status.PENDING) - .put(Status.ERROR, NodeMetadata.Status.ERROR).put(Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).put(Status.DEPLOYED, - NodeMetadata.Status.PENDING).put(Status.INCONSISTENT, NodeMetadata.Status.PENDING).put(Status.UNKNOWN, - NodeMetadata.Status.UNRECOGNIZED).put(Status.MIXED, NodeMetadata.Status.PENDING).put(Status.WAITING_FOR_INPUT, - NodeMetadata.Status.PENDING).put(Status.SUSPENDED, NodeMetadata.Status.SUSPENDED).put(Status.UNRESOLVED, - NodeMetadata.Status.PENDING).build(); + public static final Map toPortableNodeStatus = ImmutableMap + . builder() + .put(Status.OFF, NodeMetadata.Status.SUSPENDED) + .put(Status.ON, NodeMetadata.Status.RUNNING) + .put(Status.RESOLVED, NodeMetadata.Status.PENDING) + .put(Status.MIXED, NodeMetadata.Status.PENDING) + .put(Status.UNKNOWN, NodeMetadata.Status.UNRECOGNIZED) + .put(Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED) + .put(Status.DEPLOYED, NodeMetadata.Status.PENDING) + .put(Status.SUSPENDED, NodeMetadata.Status.SUSPENDED) + .put(Status.WAITING_FOR_INPUT, NodeMetadata.Status.PENDING) + .put(Status.INCONSISTENT, NodeMetadata.Status.PENDING) + .put(Status.ERROR, NodeMetadata.Status.ERROR) + .put(Status.UNRESOLVED, NodeMetadata.Status.PENDING).build(); @Singleton @Provides - protected Map provideVAppStatusToNodeStatus() { - return VAPPSTATUS_TO_NODESTATE; + protected Map toPortableNodeStatus() { + return toPortableNodeStatus; + } + + @VisibleForTesting + public static final Map toPortableImageStatus = ImmutableMap + . builder() + .put(Status.RESOLVED, Image.Status.AVAILABLE) + .put(Status.OFF, Image.Status.AVAILABLE) + .put(Status.MIXED, Image.Status.PENDING) + .put(Status.UNKNOWN, Image.Status.UNRECOGNIZED) + .put(Status.UNRECOGNIZED, Image.Status.UNRECOGNIZED) + .put(Status.DEPLOYED, Image.Status.PENDING) + .put(Status.PENDING_DESCRIPTOR, Image.Status.PENDING) + .put(Status.COPYING, Image.Status.PENDING) + .put(Status.PENDING_CONTENTS, Image.Status.PENDING) + .put(Status.QUARANTINED, Image.Status.PENDING) + .put(Status.QUARANTINE_EXPIRED, Image.Status.ERROR) + .put(Status.REJECTED, Image.Status.ERROR) + .put(Status.TRANSFER_TIMEOUT, Image.Status.ERROR) + .put(Status.ERROR, Image.Status.ERROR) + .put(Status.UNRESOLVED, Image.Status.PENDING).build(); + + @Singleton + @Provides + protected Map toPortableImageStatus() { + return toPortableImageStatus; } @SuppressWarnings("unchecked") diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java index 3bab9811d2..2e0405cbae 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java @@ -20,6 +20,8 @@ package org.jclouds.vcloud.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Map; + import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; @@ -31,6 +33,7 @@ import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.ovf.Envelope; +import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.VAppTemplate; import com.google.common.base.Function; @@ -45,12 +48,15 @@ public class ImageForVAppTemplate implements Function { @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; + private final Map toPortableImageStatus; private final Function templateToEnvelope; private final FindLocationForResource findLocationForResource; + @Inject - protected ImageForVAppTemplate(Function templateToEnvelope, + protected ImageForVAppTemplate(Map toPortableImageStatus, Function templateToEnvelope, FindLocationForResource findLocationForResource) { + this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus"); this.templateToEnvelope = checkNotNull(templateToEnvelope, "templateToEnvelope"); this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); } @@ -71,6 +77,7 @@ public class ImageForVAppTemplate implements Function { } builder.description(from.getDescription() != null ? from.getDescription() : from.getName()); builder.operatingSystem(CIMOperatingSystem.toComputeOs(ovf)); + builder.status(toPortableImageStatus.get(from.getStatus())); return builder.build(); } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/Status.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/Status.java index 9413b3daa3..1baa6af0c2 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/Status.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/Status.java @@ -137,7 +137,19 @@ public enum Status { * * @since vcloud api 1.0 */ - QUARANTINE_EXPIRED; + QUARANTINE_EXPIRED, + /** + * The {@link VAppTemplate} rejected + * + * @since vcloud api 1.0 + */ + REJECTED, + /** + * The {@link VAppTemplate} transfer timeout + * + * @since vcloud api 1.0 + */ + TRANSFER_TIMEOUT; public String value() { switch (this) { @@ -173,6 +185,10 @@ public enum Status { return "14"; case QUARANTINE_EXPIRED: return "15"; + case REJECTED: + return "16"; + case TRANSFER_TIMEOUT: + return "17"; default: return "7"; } @@ -220,6 +236,10 @@ public enum Status { return QUARANTINED; case 15: return QUARANTINE_EXPIRED; + case 16: + return REJECTED; + case 17: + return TRANSFER_TIMEOUT; default: return UNRECOGNIZED; } diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/ListImagesInVCloudExpectTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/ListImagesInVCloudExpectTest.java index 91664671a0..0f82ca9afd 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/ListImagesInVCloudExpectTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/ListImagesInVCloudExpectTest.java @@ -81,8 +81,11 @@ public class ListImagesInVCloudExpectTest extends BaseVCloudComputeServiceExpect // TODO: this looks like a bug, as it says network interfaces .description("This is a special place-holder used for disconnected network interfaces.") .defaultCredentials(LoginCredentials.builder().identity("root").build()) + .status(Image.Status.AVAILABLE) .location(vdcLocation).build(); assertEquals(onlyImage, expectedImage); + assertEquals(onlyImage.getStatus(), Image.Status.AVAILABLE); + } } diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java index 6b335b26c2..b228b542b6 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java @@ -101,7 +101,7 @@ public class VAppToNodeMetadataTest { @Singleton @Provides protected Map provideVAppStatusToNodeStatus() { - return VCloudComputeServiceDependenciesModule.VAPPSTATUS_TO_NODESTATE; + return VCloudComputeServiceDependenciesModule.toPortableNodeStatus; } }); diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/config/TerremarkVCloudComputeServiceContextModule.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/config/TerremarkVCloudComputeServiceContextModule.java index b448da1041..fcafc8e2a0 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -59,19 +59,37 @@ import com.google.inject.TypeLiteral; public class TerremarkVCloudComputeServiceContextModule extends BaseComputeServiceContextModule { @VisibleForTesting - public static final Map VAPPSTATUS_TO_NODESTATE = ImmutableMap - . builder().put(Status.OFF, NodeMetadata.Status.SUSPENDED).put(Status.ON, - NodeMetadata.Status.RUNNING).put(Status.RESOLVED, NodeMetadata.Status.PENDING).put( - Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).put(Status.DEPLOYED, - NodeMetadata.Status.PENDING).put(Status.SUSPENDED, NodeMetadata.Status.SUSPENDED).put( - Status.UNRESOLVED, NodeMetadata.Status.PENDING).build(); + public static final Map toPortableNodeStatus = ImmutableMap + . builder() + .put(Status.OFF, NodeMetadata.Status.SUSPENDED) + .put(Status.ON, NodeMetadata.Status.RUNNING) + .put(Status.RESOLVED, NodeMetadata.Status.PENDING) + .put(Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED) + .put(Status.DEPLOYED, NodeMetadata.Status.PENDING) + .put(Status.SUSPENDED, NodeMetadata.Status.SUSPENDED) + .put(Status.UNRESOLVED, NodeMetadata.Status.PENDING).build(); @Singleton @Provides - protected Map provideVAppStatusToNodeStatus() { - return VAPPSTATUS_TO_NODESTATE; + protected Map toPortableNodeStatus() { + return toPortableNodeStatus; } + + @VisibleForTesting + public static final Map toPortableImageStatus = ImmutableMap + . builder() + .put(Status.RESOLVED, Image.Status.AVAILABLE) + .put(Status.OFF, Image.Status.AVAILABLE) + .put(Status.UNRECOGNIZED, Image.Status.UNRECOGNIZED) + .put(Status.DEPLOYED, Image.Status.PENDING) + .put(Status.UNRESOLVED, Image.Status.PENDING).build(); + @Singleton + @Provides + protected Map toPortableImageStatus() { + return toPortableImageStatus; + } + @Override protected void configure() { super.configure(); diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/functions/ImageForVCloudExpressVAppTemplate.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/functions/ImageForVCloudExpressVAppTemplate.java index 167e1828d7..a06b76b1f1 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/functions/ImageForVCloudExpressVAppTemplate.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/functions/ImageForVCloudExpressVAppTemplate.java @@ -20,6 +20,8 @@ package org.jclouds.trmk.vcloud_0_8.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Map; + import javax.inject.Inject; import org.jclouds.compute.domain.Image; @@ -27,6 +29,7 @@ import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; +import org.jclouds.trmk.vcloud_0_8.domain.Status; import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate; import com.google.common.base.Function; @@ -35,6 +38,7 @@ import com.google.common.base.Function; * @author Adrian Cole */ public class ImageForVCloudExpressVAppTemplate implements Function { + private final Map toPortableImageStatus; private final FindLocationForResource findLocationForResource; private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider; private final Function osParser; @@ -42,8 +46,9 @@ public class ImageForVCloudExpressVAppTemplate implements Function toPortableImageStatus, FindLocationForResource findLocationForResource, PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, Function osParser) { + this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus"); this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); this.credentialsProvider = checkNotNull(credentialsProvider, "credentialsProvider"); this.osParser = osParser; @@ -63,6 +68,7 @@ public class ImageForVCloudExpressVAppTemplate implements Function { + + public static enum Status { + /** + * The image is in transition + */ + PENDING, + /** + * The image is visible, and in the process of being deleted. + */ + DELETED, + /** + * The image is available. + */ + AVAILABLE, + /** + * There is an error on the image + */ + ERROR, + /** + * The state of the image is unrecognized. + */ + UNRECOGNIZED; + + } + /** * The operating system installed on this image */ diff --git a/compute/src/main/java/org/jclouds/compute/domain/ImageBuilder.java b/compute/src/main/java/org/jclouds/compute/domain/ImageBuilder.java index b079e92864..46e283559d 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/ImageBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/domain/ImageBuilder.java @@ -23,11 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; import java.util.Map; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.domain.internal.ImageImpl; -import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LoginCredentials; -import org.jclouds.domain.LoginCredentials.Builder; import org.jclouds.javax.annotation.Nullable; /** @@ -35,6 +34,7 @@ import org.jclouds.javax.annotation.Nullable; */ public class ImageBuilder extends ComputeMetadataBuilder { private OperatingSystem operatingSystem; + private Status status; private String version; private String description; private LoginCredentials defaultLoginCredentials; @@ -47,7 +47,12 @@ public class ImageBuilder extends ComputeMetadataBuilder { this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); return this; } - + + public ImageBuilder status(Status status) { + this.status = checkNotNull(status, "status"); + return this; + } + public ImageBuilder version(@Nullable String version) { this.version = version; return this; @@ -58,32 +63,6 @@ public class ImageBuilder extends ComputeMetadataBuilder { return this; } - /** - *

will be removed in jclouds 1.4.0

- * - * @see LoginCredentials#shouldAuthenticateSudo - */ - @Deprecated - public ImageBuilder adminPassword(@Nullable String adminPassword) { - if (adminPassword != null) { - Builder builder = defaultLoginCredentials != null ? defaultLoginCredentials.toBuilder() : LoginCredentials - .builder(); - builder.authenticateSudo(true); - builder.password(adminPassword); - this.defaultLoginCredentials = builder.build(); - } - return this; - } - /** - *

will be removed in jclouds 1.4.0

- * - * @see #defaultCredentials(LoginCredentials) - */ - @Deprecated - public ImageBuilder defaultCredentials(@Nullable Credentials defaultLoginCredentials) { - return defaultCredentials(LoginCredentials.fromCredentials(defaultLoginCredentials)); - } - public ImageBuilder defaultCredentials(@Nullable LoginCredentials defaultLoginCredentials) { this.defaultLoginCredentials = defaultLoginCredentials; return this; @@ -130,15 +109,16 @@ public class ImageBuilder extends ComputeMetadataBuilder { @Override public Image build() { - return new ImageImpl(providerId, name, id, location, uri, userMetadata, tags, operatingSystem, description, - version, defaultLoginCredentials); + return new ImageImpl(providerId, name, id, location, uri, userMetadata, tags, operatingSystem, status, + description, version, defaultLoginCredentials); } public static ImageBuilder fromImage(Image image) { return new ImageBuilder().providerId(image.getProviderId()).name(image.getName()).id(image.getId()) .location(image.getLocation()).uri(image.getUri()).userMetadata(image.getUserMetadata()) .tags(image.getTags()).version(image.getVersion()).description(image.getDescription()) - .operatingSystem(image.getOperatingSystem()).defaultCredentials(image.getDefaultCredentials()); + .operatingSystem(image.getOperatingSystem()).status(image.getStatus()) + .defaultCredentials(image.getDefaultCredentials()); } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java index ca1a8d9276..edf8ceb946 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java @@ -27,10 +27,8 @@ import java.util.Set; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LoginCredentials; -import org.jclouds.domain.LoginCredentials.Builder; import org.jclouds.javax.annotation.Nullable; /** @@ -42,34 +40,18 @@ public class ImageImpl extends ComputeMetadataImpl implements Image { private static final long serialVersionUID = 7856744554191025307L; private final OperatingSystem operatingSystem; + private final Status status; private final String version; private final String description; private final LoginCredentials defaultCredentials; - /** - *

will be removed in jclouds 1.4.0

- */ - @Deprecated - public ImageImpl(String providerId, String name, String id, Location location, URI uri, - Map userMetadata, Set tags, OperatingSystem operatingSystem, String description, - @Nullable String version, @Nullable String adminPassword, @Nullable Credentials defaultCredentials) { - super(ComputeType.IMAGE, providerId, name, id, location, uri, userMetadata, tags); - this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); - this.version = version; - this.description = checkNotNull(description, "description"); - Builder builder = LoginCredentials.builder(defaultCredentials); - if (adminPassword != null) { - builder.authenticateSudo(true); - builder.password(adminPassword); - } - this.defaultCredentials = builder.build(); - } public ImageImpl(String providerId, String name, String id, Location location, URI uri, - Map userMetadata, Set tags, OperatingSystem operatingSystem, String description, + Map userMetadata, Set tags, OperatingSystem operatingSystem, Image.Status status, String description, @Nullable String version, @Nullable LoginCredentials defaultCredentials) { super(ComputeType.IMAGE, providerId, name, id, location, uri, userMetadata, tags); this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); + this.status = checkNotNull(status, "status"); this.version = version; this.description = checkNotNull(description, "description"); this.defaultCredentials = defaultCredentials; @@ -83,6 +65,14 @@ public class ImageImpl extends ComputeMetadataImpl implements Image { return operatingSystem; } + /** + * {@inheritDoc} + */ + @Override + public Status getStatus() { + return status; + } + /** * {@inheritDoc} */ @@ -168,4 +158,6 @@ public class ImageImpl extends ComputeMetadataImpl implements Image { return 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 2a7c002dec..991bd18e2d 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 @@ -149,7 +149,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda String desc = String.format("stub %s %s", osVersions.getKey(), is64Bit); images.add(new ImageBuilder().ids(id++ + "").name(osVersions.getKey().name()).location(location.get()) .operatingSystem(new OperatingSystem(osVersions.getKey(), desc, version, null, desc, is64Bit)) - .description(desc).build()); + .description(desc).status(Image.Status.AVAILABLE).build()); } } return images.build(); diff --git a/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java b/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java index 992e49f9e5..9a80ef4c3c 100644 --- a/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java +++ b/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java @@ -39,6 +39,7 @@ import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.domain.Location; @@ -55,7 +56,7 @@ import com.google.common.collect.ImmutableSet; * * @author Adrian Cole */ -@Test(groups = "unit", singleThreaded = true) +@Test(groups = "unit", singleThreaded = true, testName = "TemplateBuilderImplTest") public class TemplateBuilderImplTest { Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build(); @@ -797,6 +798,7 @@ public class TemplateBuilderImplTest { .name("Ubuntu 11.04 x64") .description("Ubuntu 11.04 x64") .location(region) + .status(Status.AVAILABLE) .operatingSystem( OperatingSystem.builder().name("Ubuntu 11.04 x64").description("Ubuntu 11.04 x64") .is64Bit(true).version("11.04").family(OsFamily.UBUNTU).build()).build(), @@ -805,6 +807,7 @@ public class TemplateBuilderImplTest { .name("Ubuntu 11.04 64-bit") .description("Ubuntu 11.04 64-bit") .location(region) + .status(Status.AVAILABLE) .operatingSystem( OperatingSystem.builder().name("Ubuntu 11.04 64-bit").description("Ubuntu 11.04 64-bit") .is64Bit(true).version("11.04").family(OsFamily.UBUNTU).build()).build())); diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java b/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java index 3815ddef8f..f7c45277c2 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java @@ -27,6 +27,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamilyVersion64Bit; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.domain.OperatingSystem.Builder; import org.jclouds.glesys.domain.OSTemplate; @@ -52,6 +53,6 @@ public class OSTemplateToImage implements Function { builder.name(template.getName()).description(template.getName()).is64Bit(parsed.is64Bit).version(parsed.version) .family(parsed.family); return new ImageBuilder().ids(template.getName()).name(template.getName()).description(template.getName()) - .operatingSystem(builder.build()).build(); + .operatingSystem(builder.build()).status(Status.AVAILABLE).build(); } } diff --git a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/CIMOperatingSystemToImage.java b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/CIMOperatingSystemToImage.java index 6b2bdcbeba..050b9c8807 100644 --- a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/CIMOperatingSystemToImage.java +++ b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/CIMOperatingSystemToImage.java @@ -23,6 +23,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.CIMOperatingSystem; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.Image.Status; import com.google.common.base.Function; @@ -39,6 +40,7 @@ public class CIMOperatingSystemToImage implements Function { @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; + private final Map toPortableImageStatus; private final Function templateToEnvelope; private final FindLocationForResource findLocationForResource; + @Inject - protected ImageForVAppTemplate(Function templateToEnvelope, + protected ImageForVAppTemplate(Map toPortableImageStatus, Function templateToEnvelope, FindLocationForResource findLocationForResource) { + this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus"); this.templateToEnvelope = checkNotNull(templateToEnvelope, "templateToEnvelope"); this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); } @@ -76,6 +82,7 @@ public class ImageForVAppTemplate implements Function { } builder.description(from.getDescription() != null ? from.getDescription() : from.getName()); builder.operatingSystem(CIMOperatingSystem.toComputeOs(ovf)); + builder.status(toPortableImageStatus.get(from.getStatus())); return builder.build(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 2f560e50a1..d8af02ac6e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -43,7 +43,6 @@ import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient; import org.jclouds.vcloud.director.v1_5.annotations.Login; -import org.jclouds.vcloud.director.v1_5.compute.util.VCloudDirectorComputeUtils; import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index fb55c3be7f..3bf037aecb 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -33,7 +33,6 @@ import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadata.Status; import org.jclouds.compute.extensions.ImageExtension; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.domain.Location; @@ -174,23 +173,64 @@ public class VirtualBoxComputeServiceContextModule extends } @VisibleForTesting - public static final Map machineToNodeStatus = ImmutableMap - . builder().put(MachineState.Running, Status.RUNNING) - .put(MachineState.PoweredOff, Status.SUSPENDED) - .put(MachineState.DeletingSnapshot, Status.PENDING) - .put(MachineState.DeletingSnapshotOnline, Status.PENDING) - .put(MachineState.DeletingSnapshotPaused, Status.PENDING) - .put(MachineState.FaultTolerantSyncing, Status.PENDING) - .put(MachineState.LiveSnapshotting, Status.PENDING) - .put(MachineState.SettingUp, Status.PENDING) - .put(MachineState.Starting, Status.PENDING) - .put(MachineState.Stopping, Status.PENDING) - .put(MachineState.Restoring, Status.PENDING) + public static final Map toPortableNodeStatus = ImmutableMap + . builder().put(MachineState.Running, NodeMetadata.Status.RUNNING) + .put(MachineState.PoweredOff, NodeMetadata.Status.SUSPENDED) + .put(MachineState.DeletingSnapshot, NodeMetadata.Status.PENDING) + .put(MachineState.DeletingSnapshotOnline, NodeMetadata.Status.PENDING) + .put(MachineState.DeletingSnapshotPaused, NodeMetadata.Status.PENDING) + .put(MachineState.FaultTolerantSyncing, NodeMetadata.Status.PENDING) + .put(MachineState.LiveSnapshotting, NodeMetadata.Status.PENDING) + .put(MachineState.SettingUp, NodeMetadata.Status.PENDING) + .put(MachineState.Starting, NodeMetadata.Status.PENDING) + .put(MachineState.Stopping, NodeMetadata.Status.PENDING) + .put(MachineState.Restoring, NodeMetadata.Status.PENDING) // TODO What to map these states to? - .put(MachineState.FirstOnline, Status.PENDING).put(MachineState.FirstTransient, Status.PENDING) - .put(MachineState.LastOnline, Status.PENDING).put(MachineState.LastTransient, Status.PENDING) - .put(MachineState.Teleported, Status.PENDING).put(MachineState.TeleportingIn, Status.PENDING) - .put(MachineState.TeleportingPausedVM, Status.PENDING).put(MachineState.Aborted, Status.ERROR) - .put(MachineState.Stuck, Status.ERROR).put(MachineState.Null, Status.UNRECOGNIZED).build(); - + .put(MachineState.FirstOnline, NodeMetadata.Status.PENDING) + .put(MachineState.FirstTransient, NodeMetadata.Status.PENDING) + .put(MachineState.LastOnline, NodeMetadata.Status.PENDING) + .put(MachineState.LastTransient, NodeMetadata.Status.PENDING) + .put(MachineState.Teleported, NodeMetadata.Status.PENDING) + .put(MachineState.TeleportingIn, NodeMetadata.Status.PENDING) + .put(MachineState.TeleportingPausedVM, NodeMetadata.Status.PENDING) + .put(MachineState.Aborted, NodeMetadata.Status.ERROR) + .put(MachineState.Stuck, NodeMetadata.Status.ERROR) + .put(MachineState.Null, NodeMetadata.Status.TERMINATED).build(); + + @Singleton + @Provides + protected Map toPortableNodeStatus() { + return toPortableNodeStatus; + } + + @VisibleForTesting + public static final Map toPortableImageStatus = ImmutableMap + . builder().put(MachineState.Running, Image.Status.PENDING) + .put(MachineState.PoweredOff, Image.Status.AVAILABLE) + .put(MachineState.DeletingSnapshot, Image.Status.PENDING) + .put(MachineState.DeletingSnapshotOnline, Image.Status.PENDING) + .put(MachineState.DeletingSnapshotPaused, Image.Status.PENDING) + .put(MachineState.FaultTolerantSyncing, Image.Status.PENDING) + .put(MachineState.LiveSnapshotting, Image.Status.PENDING) + .put(MachineState.SettingUp, Image.Status.PENDING) + .put(MachineState.Starting, Image.Status.PENDING) + .put(MachineState.Stopping, Image.Status.PENDING) + .put(MachineState.Restoring, Image.Status.PENDING) + // TODO What to map these states to? + .put(MachineState.FirstOnline, Image.Status.PENDING) + .put(MachineState.FirstTransient, Image.Status.PENDING) + .put(MachineState.LastOnline, Image.Status.PENDING) + .put(MachineState.LastTransient, Image.Status.PENDING) + .put(MachineState.Teleported, Image.Status.PENDING) + .put(MachineState.TeleportingIn, Image.Status.PENDING) + .put(MachineState.TeleportingPausedVM, Image.Status.PENDING) + .put(MachineState.Aborted, Image.Status.ERROR) + .put(MachineState.Stuck, Image.Status.ERROR) + .put(MachineState.Null, Image.Status.DELETED).build(); + + @Singleton + @Provides + protected Map toPortableImageStatus() { + return toPortableImageStatus; + } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java index 37dbb7fc89..bff48a2632 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java @@ -142,7 +142,7 @@ public class YamlImage { .version(arg0.os_version).is64Bit(arg0.os_64bit).arch(arg0.os_arch).build(); return new ImageBuilder().id(arg0.id).name(arg0.name).description(arg0.description) - .operatingSystem(operatingSystem).build(); + .operatingSystem(operatingSystem).status(Image.Status.AVAILABLE).build(); } }; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToImage.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToImage.java index dab6dac6ec..0b6ab199f0 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToImage.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToImage.java @@ -32,10 +32,12 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.javax.annotation.Nullable; import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.virtualbox_4_1.IGuestOSType; import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.MachineState; import org.virtualbox_4_1.VirtualBoxManager; import com.google.common.base.Function; @@ -44,11 +46,13 @@ import com.google.common.base.Supplier; @Singleton public class IMachineToImage implements Function { + private final Map toPortableImageStatus; private final Supplier virtualboxManager; private final Map> osVersionMap; @Inject - public IMachineToImage(Supplier virtualboxManager, Map> osVersionMap) { + public IMachineToImage(Map toPortableImageStatus, Supplier virtualboxManager, Map> osVersionMap) { + this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus"); this.virtualboxManager = checkNotNull(virtualboxManager, "virtualboxManager"); this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap"); } @@ -67,7 +71,7 @@ public class IMachineToImage implements Function { return new ImageBuilder() .id(from.getName().substring(VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX.length(), from.getName().length())).name(from.getName()).description(from.getDescription()) - .operatingSystem(os).build(); + .operatingSystem(os).status(toPortableImageStatus.get(from.getState())).build(); } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java index 2258236dbe..d4c07c1651 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java @@ -19,11 +19,11 @@ package org.jclouds.virtualbox.functions; -import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeStatus; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_NAME_SEPARATOR; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; import java.util.List; +import java.util.Map; import javax.annotation.Resource; import javax.inject.Named; @@ -58,10 +58,12 @@ public class IMachineToNodeMetadata implements Function @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; + private final Map toPortableNodeStatus; private final MachineUtils machineUtils; @Inject - public IMachineToNodeMetadata(MachineUtils machineUtils) { + public IMachineToNodeMetadata(Map toPortableNodeStatus, MachineUtils machineUtils) { + this.toPortableNodeStatus = toPortableNodeStatus; this.machineUtils = machineUtils; } @@ -90,7 +92,7 @@ public class IMachineToNodeMetadata implements Function nodeMetadataBuilder.hostname(vm.getName()); MachineState vmState = vm.getState(); - NodeMetadata.Status nodeState = machineToNodeStatus.get(vmState); + NodeMetadata.Status nodeState = toPortableNodeStatus.get(vmState); if (nodeState == null) nodeState = Status.UNRECOGNIZED; nodeMetadataBuilder.status(nodeState); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java index df5c301552..935ed4805c 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java @@ -177,7 +177,7 @@ public class NodeCreator implements Function iMachineToImage = new IMachineToImage(Suppliers.ofInstance(manager), osMap); + Function iMachineToImage = new IMachineToImage( + VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers.ofInstance(manager), osMap); // VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(Suppliers.ofInstance(manager), iMachineToImage, new ImageFromYamlString(), new Supplier() { // // @Override diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToImageTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToImageTest.java index 8db2dfbeb8..348f800195 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToImageTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToImageTest.java @@ -34,17 +34,19 @@ import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.json.Json; import org.jclouds.json.config.GsonModule; +import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.testng.annotations.Test; import org.virtualbox_4_1.IGuestOSType; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IVirtualBox; +import org.virtualbox_4_1.MachineState; import org.virtualbox_4_1.VirtualBoxManager; import com.google.common.base.Suppliers; import com.google.inject.Guice; -@Test(groups = "unit") +@Test(groups = "unit", testName = "IMachineToImageTest") public class IMachineToImageTest { Map> map = new BaseComputeServiceContextModule() { @@ -67,10 +69,12 @@ public class IMachineToImageTest { expect(vm.getDescription()).andReturn("my-ubuntu-machine").anyTimes(); expect(guestOsType.getDescription()).andReturn(linuxDescription).anyTimes(); expect(guestOsType.getIs64Bit()).andReturn(true); + expect(vm.getState()).andReturn(MachineState.PoweredOff); replay(vbm, vBox, vm, guestOsType); - IMachineToImage fn = new IMachineToImage(Suppliers.ofInstance(vbm), map); + IMachineToImage fn = new IMachineToImage(VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers + .ofInstance(vbm), map); Image image = fn.apply(vm); @@ -80,6 +84,7 @@ public class IMachineToImageTest { assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(image.getOperatingSystem().getVersion(), "10.04"); assertEquals(image.getId(), "my-vm-id"); + assertEquals(image.getStatus(), Image.Status.AVAILABLE); } @@ -100,10 +105,12 @@ public class IMachineToImageTest { expect(vm.getDescription()).andReturn(vmDescription).anyTimes(); expect(guestOsType.getDescription()).andReturn(guestOsDescription).anyTimes(); expect(guestOsType.getIs64Bit()).andReturn(true); + expect(vm.getState()).andReturn(MachineState.Running); replay(vbm, vBox, vm, guestOsType); - IMachineToImage fn = new IMachineToImage(Suppliers.ofInstance(vbm), map); + IMachineToImage fn = new IMachineToImage(VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers + .ofInstance(vbm), map); Image image = fn.apply(vm); @@ -113,6 +120,7 @@ public class IMachineToImageTest { assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(image.getOperatingSystem().getVersion(), "11.04"); assertEquals(image.getId(), "my-vm-id"); + assertEquals(image.getStatus(), Image.Status.PENDING); } @@ -133,10 +141,12 @@ public class IMachineToImageTest { expect(guestOsType.getDescription()).andReturn(unknownOsDescription).anyTimes(); expect(guestOsType.getIs64Bit()).andReturn(true); expect(vBox.getGuestOSType(eq("os-type"))).andReturn(guestOsType); + expect(vm.getState()).andReturn(MachineState.PoweredOff); replay(vbm, vBox, vm, guestOsType); - IMachineToImage fn = new IMachineToImage(Suppliers.ofInstance(vbm), map); + IMachineToImage fn = new IMachineToImage(VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers + .ofInstance(vbm), map); Image image = fn.apply(vm); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java index 9443c40965..adc755cbdf 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java @@ -29,6 +29,7 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import org.jclouds.virtualbox.util.MachineUtils; import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; @@ -67,7 +68,8 @@ public class IMachineToNodeMetadataTest { replay(vm, nat, natEng, hostOnly, machineUtils); - NodeMetadata node = new IMachineToNodeMetadata(machineUtils).apply(vm); + NodeMetadata node = new IMachineToNodeMetadata(VirtualBoxComputeServiceContextModule.toPortableNodeStatus, + machineUtils).apply(vm); assertEquals(MASTER_NAME, node.getName()); assertEquals(1, node.getPrivateAddresses().size()); @@ -105,7 +107,8 @@ public class IMachineToNodeMetadataTest { replay(vm, nat, natEng, hostOnly, machineUtils); - NodeMetadata node = new IMachineToNodeMetadata(machineUtils).apply(vm); + NodeMetadata node = new IMachineToNodeMetadata(VirtualBoxComputeServiceContextModule.toPortableNodeStatus, + machineUtils).apply(vm); assertEquals(name, node.getName()); assertEquals(group, node.getGroup()); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStringTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStringTest.java index 8a51a69b74..843071ad80 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStringTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStringTest.java @@ -37,7 +37,7 @@ import com.google.common.collect.Iterables; /** * @author Andrea Turli */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "ImageFromYamlStringTest") public class ImageFromYamlStringTest { public static final Image TEST1 = new ImageBuilder() @@ -46,7 +46,8 @@ public class ImageFromYamlStringTest { .description("ubuntu 11.04 server (i386)") .operatingSystem( OperatingSystem.builder().description("ubuntu").family(OsFamily.UBUNTU).version("11.04") - .arch("x86").build()).build(); + .arch("x86").build()) + .status(Image.Status.AVAILABLE).build(); Map images; diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadataTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadataTest.java index c820dc1094..d48317b563 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadataTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadataTest.java @@ -163,7 +163,7 @@ public class AWSRunningInstanceToNodeMetadataTest { protected AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, final ImmutableSet locations, Set images, Map credentialStore) { - Map instanceToNodeStatus = EC2ComputeServiceDependenciesModule.instanceToNodeStatus; + Map instanceToNodeStatus = EC2ComputeServiceDependenciesModule.toPortableNodeStatus; final Map backing = ImagesToRegionAndIdMap.imagesToMap(images); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java index 4893990d11..141e20966b 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java @@ -32,6 +32,7 @@ import org.jclouds.domain.Location; import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; import org.jclouds.domain.LoginCredentials; +import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule; import org.jclouds.ec2.compute.functions.EC2ImageParser; import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.ec2.domain.Image; @@ -52,7 +53,7 @@ import com.google.inject.Guice; /** * @author Adrian Cole */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "AWSEC2ImageParserTest") public class AWSEC2ImageParserTest { public void testParseAlesticCanonicalImage() { @@ -73,7 +74,9 @@ public class AWSEC2ImageParserTest { "rootDeviceType", "instance-store", "virtualizationType", "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE) .build()); + assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); assertEquals( Iterables.get(result, 4), @@ -84,7 +87,9 @@ public class AWSEC2ImageParserTest { .build()).description("alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml") .defaultCredentials(new LoginCredentials("ubuntu", false)).id("us-east-1/ami-c0fa1ea9") .providerId("ami-c0fa1ea9").location(defaultLocation).version("20080905") - .userMetadata(ImmutableMap.of("owner", "063491364108", "rootDeviceType", "instance-store")).build()); + .userMetadata(ImmutableMap.of("owner", "063491364108", "rootDeviceType", "instance-store")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); + assertEquals(Iterables.get(result, 4).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); assertEquals( Iterables.get(result, 6), @@ -102,7 +107,8 @@ public class AWSEC2ImageParserTest { "rootDeviceType", "ebs", "virtualizationType", "paravirtual", "hypervisor", "xen")) - .build()); + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); + assertEquals(Iterables.get(result, 6).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); } @@ -120,7 +126,8 @@ public class AWSEC2ImageParserTest { .description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml") .defaultCredentials(new LoginCredentials("root", false)).id("us-east-1/ami-870de2ee") .providerId("ami-870de2ee").location(defaultLocation).version("5622") - .userMetadata(ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store")).build()); + .userMetadata(ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); } @@ -143,7 +150,8 @@ public class AWSEC2ImageParserTest { "rootDeviceType", "ebs", "virtualizationType", "hvm", "hypervisor", "xen")) - .build()); + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); + assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); } @@ -160,15 +168,17 @@ public class AWSEC2ImageParserTest { .build()).description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml") .defaultCredentials(new LoginCredentials("root", false)).id("us-east-1/ami-ccb35ea5") .providerId("ami-ccb35ea5").location(defaultLocation).version("4.4.10") - .userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build()); + .userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); + assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); assertEquals( new Gson().toJson(Iterables.get(result, 1)), - "{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"name\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}"); + "{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"status\":\"AVAILABLE\",\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"name\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}"); assertEquals( new Gson().toJson(Iterables.get(result, 2)), - "{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"name\":\"RightImage Windows_2003_i386_v5.4.3\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"hvm\",\"hypervisor\":\"xen\"}}"); + "{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"status\":\"AVAILABLE\",\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"name\":\"RightImage Windows_2003_i386_v5.4.3\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"hvm\",\"hypervisor\":\"xen\"}}"); } public void testParseAmznImage() { @@ -190,7 +200,8 @@ public class AWSEC2ImageParserTest { "rootDeviceType", "ebs", "virtualizationType", "paravirtual", "hypervisor", "xen")) - .build()); + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); + assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); assertEquals( Iterables.get(result, 3), @@ -208,7 +219,9 @@ public class AWSEC2ImageParserTest { "rootDeviceType", "ebs", "virtualizationType", "paravirtual", "hypervisor", "xen")) - .build()); + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); + assertEquals(Iterables.get(result, 3).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + } static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1") @@ -221,9 +234,10 @@ public class AWSEC2ImageParserTest { .getInstance(Json.class)); Set result = DescribeImagesResponseHandlerTest.parseImages(resource); - EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, - Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), - Suppliers.ofInstance(defaultLocation), new AWSEC2ReviseParsedImage(map)); + EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus, + new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers + .> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers + .ofInstance(defaultLocation), new AWSEC2ReviseParsedImage(map)); return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImageTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImageTest.java index c85cf1f944..e66252726c 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImageTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImageTest.java @@ -57,7 +57,8 @@ public class AWSEC2ReviseParsedImageTest { Image from = newImage("amazon", "Windows_Server-2008-R2_SP1-English-64Bit-Base-2012.03.13"); OperatingSystem.Builder osBuilder = OperatingSystem.builder().description("test"); - ImageBuilder builder = new ImageBuilder().id("1").operatingSystem(osBuilder.build()).description("test"); + ImageBuilder builder = new ImageBuilder().id("1").operatingSystem(osBuilder.build()).status( + org.jclouds.compute.domain.Image.Status.AVAILABLE).description("test"); OsFamily family = OsFamily.WINDOWS; rpi.reviseParsedImage(from, builder, family, osBuilder); @@ -74,7 +75,8 @@ public class AWSEC2ReviseParsedImageTest { Image from = newImage("amazon", "Windows-2008R2-SP1-English-Base-2012.01.12"); OperatingSystem.Builder osBuilder = OperatingSystem.builder().description("test"); - ImageBuilder builder = new ImageBuilder().id("1").operatingSystem(osBuilder.build()).description("test"); + ImageBuilder builder = new ImageBuilder().id("1").operatingSystem(osBuilder.build()).status( + org.jclouds.compute.domain.Image.Status.AVAILABLE).description("test"); OsFamily family = OsFamily.WINDOWS; rpi.reviseParsedImage(from, builder, family, osBuilder); diff --git a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java index be7dc10a7b..bd5cc3a898 100644 --- a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java +++ b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java @@ -32,6 +32,7 @@ import org.jclouds.domain.Location; import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; import org.jclouds.domain.LoginCredentials; +import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule; import org.jclouds.ec2.compute.functions.EC2ImageParser; import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.ec2.domain.Image; @@ -52,7 +53,7 @@ import com.google.inject.Guice; /** * @author Adrian Cole */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "EucalyptusPartnerCloudReviseParsedImageTest") public class EucalyptusPartnerCloudReviseParsedImageTest { public void testParseEucalyptusImage() { @@ -74,7 +75,9 @@ public class EucalyptusPartnerCloudReviseParsedImageTest { .location(defaultLocation) .userMetadata( ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType", - "paravirtual", "hypervisor", "xen")).build().toString()); + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build().toString()); + assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); assertEquals( Iterables.get(result, 1).toString(), @@ -90,7 +93,9 @@ public class EucalyptusPartnerCloudReviseParsedImageTest { .location(defaultLocation) .userMetadata( ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType", - "paravirtual", "hypervisor", "xen")).build().toString()); + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build().toString()); + assertEquals(Iterables.get(result, 1).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); assertEquals( Iterables.get(result, 2).toString(), @@ -106,7 +111,9 @@ public class EucalyptusPartnerCloudReviseParsedImageTest { .location(defaultLocation) .userMetadata( ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType", - "paravirtual", "hypervisor", "xen")).build().toString()); + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build().toString()); + assertEquals(Iterables.get(result, 2).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); } @@ -120,8 +127,9 @@ public class EucalyptusPartnerCloudReviseParsedImageTest { .getInstance(Json.class)); Set result = DescribeImagesResponseHandlerTest.parseImages(resource); - EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, - Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers + EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus, + new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers + .> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers .ofInstance(defaultLocation), new EucalyptusPartnerCloudReviseParsedImage(map)); return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java index e3e258a5a5..7c3a5125b8 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java @@ -42,6 +42,7 @@ import org.jclouds.gogrid.compute.strategy.GoGridComputeServiceAdapter; import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.ServerImage; +import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerState; import com.google.common.annotations.VisibleForTesting; @@ -85,23 +86,37 @@ public class GoGridComputeServiceContextModule extends } @VisibleForTesting - static final Map serverStateToNodeStatus = ImmutableMap. builder() - .put(ServerState.ON, Status.RUNNING)// - .put(ServerState.STARTING, Status.PENDING)// - .put(ServerState.OFF, Status.SUSPENDED)// - .put(ServerState.STOPPING, Status.PENDING)// - .put(ServerState.RESTARTING, Status.PENDING)// - .put(ServerState.SAVING, Status.PENDING)// - .put(ServerState.UNRECOGNIZED, Status.UNRECOGNIZED)// - .put(ServerState.RESTORING, Status.PENDING)// + static final Map toPortableNodeStatus = ImmutableMap. builder() + .put(ServerState.ON, Status.RUNNING) + .put(ServerState.STARTING, Status.PENDING) + .put(ServerState.OFF, Status.SUSPENDED) + .put(ServerState.STOPPING, Status.PENDING) + .put(ServerState.RESTARTING, Status.PENDING) + .put(ServerState.SAVING, Status.PENDING) + .put(ServerState.UNRECOGNIZED, Status.UNRECOGNIZED) + .put(ServerState.RESTORING, Status.PENDING) .put(ServerState.UPDATING, Status.PENDING).build(); @Singleton @Provides - Map provideServerToNodeStatus() { - return serverStateToNodeStatus; + Map toPortableNodeStatus() { + return toPortableNodeStatus; } + + @VisibleForTesting + static final Map toPortableImageStatus = ImmutableMap + . builder() + .put(ServerImageState.AVAILABLE, Image.Status.AVAILABLE) + .put(ServerImageState.SAVING, Image.Status.PENDING) + .put(ServerImageState.TRASH, Image.Status.DELETED) + .put(ServerImageState.UNRECOGNIZED, Image.Status.UNRECOGNIZED).build(); + @Singleton + @Provides + Map toPortableImageStatus() { + return toPortableImageStatus; + } + /** * Finds matches to required configurations. GoGrid's documentation only specifies how much RAM * one can get with different instance types. The # of cores and disk sizes are purely empyrical diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerImageToImage.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerImageToImage.java index 52aedc3328..604815e3ad 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerImageToImage.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerImageToImage.java @@ -31,9 +31,11 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.gogrid.domain.ServerImage; +import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.logging.Logger; import com.google.common.base.Function; @@ -50,11 +52,14 @@ public class ServerImageToImage implements Function { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; - + + private final Map toPortableImageStatus; private final Map> osVersionMap; @Inject - ServerImageToImage(Map> osVersionMap) { + ServerImageToImage(Map toPortableImageStatus, + Map> osVersionMap) { + this.toPortableImageStatus = toPortableImageStatus; this.osVersionMap = osVersionMap; } @@ -93,6 +98,7 @@ public class ServerImageToImage implements Function { builder.name(from.getFriendlyName()); builder.description(from.getDescription()); builder.operatingSystem(parseOs(from)); + builder.status(toPortableImageStatus.get(from.getState())); return builder.build(); } diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModuleTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModuleTest.java index 0ef1b33939..81d84f9376 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModuleTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModuleTest.java @@ -31,7 +31,7 @@ public class GoGridComputeServiceContextModuleTest { public void testAllStatusCovered() { for (ServerState state : ServerState.values()) { - assert GoGridComputeServiceContextModule.serverStateToNodeStatus.containsKey(state) : state; + assert GoGridComputeServiceContextModule.toPortableNodeStatus.containsKey(state) : state; } } diff --git a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingImageSupplier.java b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingImageSupplier.java index 050b5f88be..0af668e5b3 100644 --- a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingImageSupplier.java +++ b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingImageSupplier.java @@ -31,6 +31,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.rimuhosting.miro.RimuHostingClient; @@ -66,6 +67,7 @@ public class RimuHostingImageSupplier implements Supplier> builder.name(from.getDescription()); builder.description(from.getDescription()); builder.operatingSystem(parseOs(from)); + builder.status(Status.AVAILABLE); images.add(builder.build()); } logger.debug("<< images(%d)", images.size()); diff --git a/providers/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImage.java b/providers/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImage.java index 3c20cbf76f..2f7ad3e4a2 100644 --- a/providers/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImage.java +++ b/providers/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImage.java @@ -46,6 +46,7 @@ public class SlicehostImageToImage implements Function { .ids(imageId().apply(productItem)) .description(description) .operatingSystem(os) + .status(Image.Status.AVAILABLE) .build(); } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemToImageTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemToImageTest.java index 39f8c9babc..33da52801c 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemToImageTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemToImageTest.java @@ -46,7 +46,7 @@ import com.google.common.collect.ImmutableSet; * * @author Jason King */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "ProductItemToImageTest") public class ProductItemToImageTest { // Operating Systems available MAR 2012 private static final List operatingSystems = Arrays.asList( diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadataTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadataTest.java index 2b668ba698..fa8be24ad2 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadataTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadataTest.java @@ -212,7 +212,8 @@ public class VirtualGuestToNodeMetadataTest { @Override public Image getImage(VirtualGuest guest) { return new ImageBuilder().ids("123").description("mocked image") - .operatingSystem(OperatingSystem.builder().description("foo os").build()).build(); + .operatingSystem(OperatingSystem.builder().description("foo os").build()) + .status(Image.Status.AVAILABLE).build(); } } } diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerImageToImage.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerImageToImage.java index 28fe56b947..1084ce2d6d 100644 --- a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerImageToImage.java +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerImageToImage.java @@ -26,6 +26,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; @@ -55,6 +56,7 @@ public class ServerManagerImageToImage implements Function