Issue 952:add status field to image

This commit is contained in:
Adrian Cole 2012-05-30 21:20:01 -07:00
parent 5ce29e0931
commit 96773b8a1b
69 changed files with 663 additions and 308 deletions

View File

@ -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<ServerStatus, Status> serverToNodeStatus = ImmutableMap
.<ServerStatus, Status> 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<ServerStatus, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
.<ServerStatus, NodeMetadata.Status> 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<ServerStatus, Status> provideServerToNodeStatus() {
return serverToNodeStatus;
Map<ServerStatus, NodeMetadata.Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<ImageStatus, Image.Status> toPortableImageStatus = ImmutableMap
.<ImageStatus, Image.Status> 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<ImageStatus, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
@Override

View File

@ -52,7 +52,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* CloudServers implementation of {@link ImageExtension}
*
* @author David Alves
*
* @see <a href="http://docs.rackspace.com/servers/api/v1.0/cs-devguide/content/Images-d1e4062.html">docs</a>
*/
@Singleton
public class CloudServersImageExtension implements ImageExtension {

View File

@ -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<org.jclouds.cloudservers.domain.Image, Image> {
private final Map<ImageStatus, Status> toPortableImageStatus;
private final Function<org.jclouds.cloudservers.domain.Image, OperatingSystem> imageToOs;
@Inject
CloudServersImageToImage(Function<org.jclouds.cloudservers.domain.Image, OperatingSystem> imageToOs) {
CloudServersImageToImage(Map<ImageStatus, Image.Status> toPortableImageStatus, Function<org.jclouds.cloudservers.domain.Image, OperatingSystem> 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<org.jclouds.cloudserve
builder.description(from.getName());
builder.version(from.getUpdated().getTime() + "");
builder.operatingSystem(imageToOs.apply(from));
builder.status(toPortableImageStatus.get(from.getStatus()));
Image image = builder.build();
return image;
}

View File

@ -30,7 +30,7 @@ public class CloudServersComputeServiceContextModuleTest {
public void testAllStatusCovered() {
for (ServerStatus state : ServerStatus.values()) {
assert CloudServersComputeServiceContextModule.serverToNodeStatus.containsKey(state) : state;
assert CloudServersComputeServiceContextModule.toPortableNodeStatus.containsKey(state) : state;
}
}

View File

@ -20,8 +20,7 @@ package org.jclouds.cloudservers.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException;
import org.jclouds.cloudservers.compute.config.CloudServersComputeServiceContextModule;
import org.jclouds.cloudservers.functions.ParseImageFromJsonResponseTest;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image;
@ -38,23 +37,27 @@ import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
@Test(groups = "unit", testName = "CloudServersImageToImageTest")
public class CloudServersImageToImageTest {
@Test
public void testApplyWhereImageNotFound() throws UnknownHostException {
assertEquals(convertImage(), new ImageBuilder().name("CentOS 5.2").operatingSystem(
public void test() {
Image toTest = convertImage();
assertEquals(toTest, new ImageBuilder().name("CentOS 5.2").operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2").is64Bit(
true).build()).description("CentOS 5.2").ids("2").version("1286712000000").build());
true).build()).description("CentOS 5.2").ids("2").status(Image.Status.PENDING).version(
"1286712000000").build());
assertEquals(toTest.getStatus(), Image.Status.PENDING);
}
public static Image convertImage() {
org.jclouds.cloudservers.domain.Image image = ParseImageFromJsonResponseTest.parseImage();
CloudServersImageToImage parser = new CloudServersImageToImage(new CloudServersImageToOperatingSystem(
new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice
.createInjector(new GsonModule()).getInstance(Json.class))));
CloudServersImageToImage parser = new CloudServersImageToImage(
CloudServersComputeServiceContextModule.toPortableImageStatus, new CloudServersImageToOperatingSystem(
new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(
new GsonModule()).getInstance(Json.class))));
return parser.apply(image);
}

View File

@ -60,7 +60,7 @@ public class ServerToNodeMetadataTest {
@Test
public void testApplyWhereImageAndHardwareNotFound() {
Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.serverToNodeStatus;
Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus;
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
Server server = ParseServerFromJsonResponseTest.parseServer();
@ -91,7 +91,7 @@ public class ServerToNodeMetadataTest {
@Test
public void testApplyWhereImageFoundAndHardwareNotFound() {
Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.serverToNodeStatus;
Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus;
org.jclouds.compute.domain.Image jcImage = CloudServersImageToImageTest.convertImage();
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
@ -126,7 +126,7 @@ public class ServerToNodeMetadataTest {
@Test
public void testApplyWhereImageAndHardwareFound() {
Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.serverToNodeStatus;
Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus;
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(CloudServersImageToImageTest.convertImage());
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
Server server = ParseServerFromJsonResponseTest.parseServer();

View File

@ -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<DriveInfo, Image> {
return new ImageBuilder().ids(drive.getUuid())
.userMetadata(ImmutableMap.<String, String> 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();
}
}

View File

@ -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<Template, Image> {
if (!template.isCrossZones())
builder.location(findLocationForTemplate.apply(template));
//TODO: implement status mapping!!!
builder.status(Status.AVAILABLE);
return builder.build();
}

View File

@ -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() {

View File

@ -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<org.jclouds.deltacloud.d
builder.name(from.getName());
builder.description(from.getDescription());
builder.operatingSystem(imageToOperatingSystem.apply(from));
builder.status(Status.AVAILABLE);
return builder.build();
}
}

View File

@ -54,10 +54,12 @@ import org.jclouds.ec2.compute.predicates.SecurityGroupPresent;
import org.jclouds.ec2.domain.InstanceState;
import org.jclouds.ec2.domain.KeyPair;
import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.ec2.domain.Image.ImageState;
import org.jclouds.ec2.reference.EC2Constants;
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.Functions;
import com.google.common.base.Predicate;
@ -79,19 +81,36 @@ import com.google.inject.name.Names;
*/
public class EC2ComputeServiceDependenciesModule extends AbstractModule {
public static final Map<InstanceState, Status> instanceToNodeStatus = ImmutableMap
.<InstanceState, Status> 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<InstanceState, Status> toPortableNodeStatus = ImmutableMap
.<InstanceState, Status> 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<InstanceState, NodeMetadata.Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<ImageState, Image.Status> toPortableImageStatus = ImmutableMap
.<ImageState, Image.Status> builder()
.put(ImageState.AVAILABLE, Image.Status.AVAILABLE)
.put(ImageState.DEREGISTERED, Image.Status.DELETED)
.put(ImageState.UNRECOGNIZED, Image.Status.UNRECOGNIZED).build();
@Singleton
@Provides
Map<InstanceState, Status> provideServerToNodeStatus() {
return instanceToNodeStatus;
protected Map<ImageState, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
@Override
protected void configure() {
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);

View File

@ -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<org.jclouds.ec2.domain.Image, Im
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final Map<ImageState, Status> toPortableImageStatus;
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
private final Supplier<Set<? extends Location>> locations;
private final Supplier<Location> defaultLocation;
private final Map<OsFamily, Map<String, String>> osVersionMap;
private final ReviseParsedImage reviseParsedImage;
@Inject
public EC2ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
public EC2ImageParser(Map<ImageState, Image.Status> toPortableImageStatus,
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
Map<OsFamily, Map<String, String>> osVersionMap, @Memoized Supplier<Set<? extends Location>> locations,
Supplier<Location> 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<org.jclouds.ec2.domain.Image, Im
from.getRegion()).parent(defaultLocation.get()).build());
}
builder.operatingSystem(osBuilder.build());
builder.status(toPortableImageStatus.get(from.getImageState()));
return builder.build();
}

View File

@ -79,6 +79,7 @@ import com.google.common.collect.ImmutableSet;
*
* @author Oleksiy Yarmula
*/
@Test(testName = "EC2TemplateBuilderTest")
public class EC2TemplateBuilderTest {
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build();
@ -166,6 +167,7 @@ public class EC2TemplateBuilderTest {
final Image image = 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();
Map<RegionAndName, Image> 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

View File

@ -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<org.jclouds.compute.domain.Image> 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<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus,
new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
.ofInstance(defaultLocation), new ReviseParsedImage.NoopReviseParsedImage());
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}

View File

@ -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.<String, Credentials> 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> hardware,
final ImmutableSet<Location> locations, final Set<org.jclouds.compute.domain.Image> images,
Map<String, Credentials> credentialStore) {
Map<InstanceState, Status> instanceToNodeStatus = EC2ComputeServiceDependenciesModule.instanceToNodeStatus;
Map<InstanceState, Status> instanceToNodeStatus = EC2ComputeServiceDependenciesModule.toPortableNodeStatus;
CacheLoader<RegionAndName, Image> getRealImage = new CacheLoader<RegionAndName, Image>() {

View File

@ -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<DriveInfo, Image> {
.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())

View File

@ -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<ServerStatus, Status> serverToNodeStatus = ImmutableMap
public static final Map<ServerStatus, Status> toPortableNodeStatus = ImmutableMap
.<ServerStatus, Status> 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<ServerStatus, Status> provideServerToNodeStatus() {
return serverToNodeStatus;
Map<ServerStatus, Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<ImageStatus, Image.Status> toPortableImageStatus = ImmutableMap
.<ImageStatus, Image.Status> 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<ImageStatus, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
}

View File

@ -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<org.jclouds.openstack.nova.domain.Image, Image> {
private final Map<ImageStatus, Status> toPortableImageStatus;
private final Function<org.jclouds.openstack.nova.domain.Image, OperatingSystem> imageToOs;
@Inject
NovaImageToImage(Function<org.jclouds.openstack.nova.domain.Image, OperatingSystem> imageToOs) {
NovaImageToImage(Map<ImageStatus, Image.Status> toPortableImageStatus,
Function<org.jclouds.openstack.nova.domain.Image, OperatingSystem> imageToOs) {
this.toPortableImageStatus = toPortableImageStatus;
this.imageToOs = imageToOs;
}
@ -47,6 +54,7 @@ public class NovaImageToImage implements Function<org.jclouds.openstack.nova.dom
builder.description(from.getName() != null ? from.getName() : "unspecified");
builder.version(from.getUpdated() != null ? from.getUpdated().getTime() + "" : "-1");
builder.operatingSystem(imageToOs.apply(from)); //image name may not represent the OS type
builder.status(toPortableImageStatus.get(from.getStatus()));
builder.uri(from.getURI());
Image image = builder.build();
return image;

View File

@ -30,7 +30,7 @@ public class NovaComputeServiceContextModuleTest {
public void testAllStatusCovered() {
for (ServerStatus state : ServerStatus.values()) {
assert NovaComputeServiceContextModule.serverToNodeStatus.containsKey(state) : state;
assert NovaComputeServiceContextModule.toPortableNodeStatus.containsKey(state) : state;
}
}

View File

@ -30,6 +30,7 @@ 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.openstack.nova.compute.config.NovaComputeServiceContextModule;
import org.jclouds.openstack.nova.functions.ParseImageFromJsonResponseTest;
import org.testng.annotations.Test;
@ -38,29 +39,32 @@ import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
@Test(groups = "unit", testName = "NovaImageToImageTest")
public class NovaImageToImageTest {
@Test
public void testApplyWhereImageNotFound() {
public void test() {
Image image = new ImageBuilder()
.name("CentOS 5.2")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2")
.is64Bit(true).build()).description("CentOS 5.2").ids("2").version("1286712000000")
.status(Image.Status.PENDING)
.uri(URI.create("https://servers.api.rackspacecloud.com/v1.1/1234/images/1")).build();
Image parsedImage = convertImage();
assertEquals(parsedImage, image);
assertEquals(parsedImage.getStatus(), Image.Status.PENDING);
}
public static Image convertImage() {
org.jclouds.openstack.nova.domain.Image image = ParseImageFromJsonResponseTest.parseImage();
NovaImageToImage parser = new NovaImageToImage(new NovaImageToOperatingSystem(
new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class))));
NovaImageToImage parser = new NovaImageToImage(NovaComputeServiceContextModule.toPortableImageStatus,
new NovaImageToOperatingSystem(new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice
.createInjector(new GsonModule()).getInstance(Json.class))));
return parser.apply(image);
}

View File

@ -64,7 +64,7 @@ public class ServerToNodeMetadataTest {
@Test
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException,
ClassNotFoundException, URISyntaxException {
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.serverToNodeStatus;
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus;
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
Server server = ParseServerFromJsonResponseTest.parseServer();
@ -100,7 +100,7 @@ public class ServerToNodeMetadataTest {
@Test
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException,
ClassNotFoundException, URISyntaxException {
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.serverToNodeStatus;
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus;
org.jclouds.compute.domain.Image jcImage = NovaImageToImageTest.convertImage();
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
@ -125,7 +125,7 @@ public class ServerToNodeMetadataTest {
@Test
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException, NoSuchMethodException,
ClassNotFoundException, URISyntaxException {
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.serverToNodeStatus;
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus;
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(NovaImageToImageTest.convertImage());
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
Server server = ParseServerFromJsonResponseTest.parseServer();

View File

@ -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<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus,
new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
.ofInstance(defaultLocation), new NovaReviseParsedImage(new ImageToOperatingSystem(map)));
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}

View File

@ -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<Server.Status, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
.<Server.Status, NodeMetadata.Status> 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<Server.Status, NodeMetadata.Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<org.jclouds.openstack.nova.v1_1.domain.Image.Status, Image.Status> toPortableImageStatus = ImmutableMap
.<org.jclouds.openstack.nova.v1_1.domain.Image.Status, Image.Status> 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<org.jclouds.openstack.nova.v1_1.domain.Image.Status, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
@Override
protected Optional<ImageExtension> provideImageExtension(Injector i) {

View File

@ -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<ImageInZone, Image> {
private final Map<Status, org.jclouds.compute.domain.Image.Status> toPortableImageStatus;
private final Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs;
private final Supplier<Map<String, Location>> locationIndex;
@Inject
public ImageInZoneToImage(Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs,
public ImageInZoneToImage(Map<org.jclouds.openstack.nova.v1_1.domain.Image.Status, Image.Status> toPortableImageStatus,
Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs,
Supplier<Map<String, Location>> 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<ImageInZone, Image> {
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();
}
}

View File

@ -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<ServerInZone, NodeMe
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected Map<Status, org.jclouds.compute.domain.NodeMetadata.Status> toPortableNodeStatus;
protected final Supplier<Map<String, Location>> locationIndex;
protected final Supplier<Set<? extends Image>> images;
protected final Supplier<Set<? extends Hardware>> hardwares;
protected final GroupNamingConvention nodeNamingConvention;
@Inject
public ServerInZoneToNodeMetadata(Supplier<Map<String, Location>> locationIndex,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
GroupNamingConvention.Factory namingConvention) {
public ServerInZoneToNodeMetadata(Map<Server.Status, NodeMetadata.Status> toPortableNodeStatus,
Supplier<Map<String, Location>> locationIndex, @Memoized Supplier<Set<? extends Image>> images,
@Memoized Supplier<Set<? extends Hardware>> 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<ServerInZone, NodeMe
builder.imageId(ZoneAndId.fromZoneAndId(serverInZone.getZone(), from.getImage().getId()).slashEncode());
builder.operatingSystem(findOperatingSystemForServerOrNull(serverInZone));
builder.hardware(findHardwareForServerOrNull(serverInZone));
builder.status(from.getStatus().getNodeStatus());
builder.status(toPortableNodeStatus.get(from.getStatus()));
builder.publicAddresses(filter(
transform(filter(from.getAddresses().values(), Predicates.not(isPrivateAddress)),
AddressToStringTransformationFunction.INSTANCE), isInet4Address));

View File

@ -24,7 +24,6 @@ import java.util.Date;
import java.util.Map;
import java.util.Set;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.openstack.domain.Resource;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient;
@ -62,19 +61,7 @@ public class Server extends Resource {
*/
public static enum Status {
ACTIVE(NodeMetadata.Status.RUNNING), BUILD(NodeMetadata.Status.PENDING), REBUILD(NodeMetadata.Status.PENDING), SUSPENDED(
NodeMetadata.Status.SUSPENDED), RESIZE(NodeMetadata.Status.PENDING), VERIFY_RESIZE(
NodeMetadata.Status.PENDING), REVERT_RESIZE(NodeMetadata.Status.PENDING), PASSWORD(
NodeMetadata.Status.PENDING), REBOOT(NodeMetadata.Status.PENDING), HARD_REBOOT(
NodeMetadata.Status.PENDING), DELETED(NodeMetadata.Status.TERMINATED), UNKNOWN(
NodeMetadata.Status.UNRECOGNIZED), ERROR(NodeMetadata.Status.ERROR), UNRECOGNIZED(
NodeMetadata.Status.UNRECOGNIZED), PAUSED(NodeMetadata.Status.SUSPENDED);
protected final NodeMetadata.Status nodeState;
Status(NodeMetadata.Status nodeState) {
this.nodeState = nodeState;
}
ACTIVE, BUILD, REBUILD, SUSPENDED, PAUSED, RESIZE, VERIFY_RESIZE, REVERT_RESIZE, PASSWORD, REBOOT, HARD_REBOOT, DELETED, UNKNOWN, ERROR, UNRECOGNIZED;
public String value() {
return name();
@ -87,10 +74,6 @@ public class Server extends Resource {
return UNRECOGNIZED;
}
}
public NodeMetadata.Status getNodeStatus() {
return nodeState;
}
}

View File

@ -23,18 +23,18 @@ import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Nullable;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
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.Image;
import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ImageInZone;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
@ -57,10 +57,11 @@ public class ImageInZoneToImageTest {
@Test
public void testConversionWhereLocationFound() {
UUID id = UUID.randomUUID();
Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build();
Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).status(Image.Status.DELETED).build();
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
"My Test OS", true);
ImageInZoneToImage converter = new ImageInZoneToImage(new MockImageToOsConverter(operatingSystem), locationIndex);
ImageInZoneToImage converter = new ImageInZoneToImage(NovaComputeServiceContextModule.toPortableImageStatus,
constant(operatingSystem), locationIndex);
ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "az-1.region-a.geo-1");
@ -71,6 +72,7 @@ public class ImageInZoneToImageTest {
assertEquals(convertedImage.getLocation(), locationIndex.get().get("az-1.region-a.geo-1"));
assertEquals(convertedImage.getName(), novaImageToConvert.getName());
assertEquals(convertedImage.getStatus(), org.jclouds.compute.domain.Image.Status.DELETED);
assertEquals(convertedImage.getOperatingSystem(), operatingSystem);
}
@ -80,29 +82,16 @@ public class ImageInZoneToImageTest {
Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build();
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
"My Test OS", true);
ImageInZoneToImage converter = new ImageInZoneToImage(new MockImageToOsConverter(operatingSystem), locationIndex);
ImageInZoneToImage converter = new ImageInZoneToImage(NovaComputeServiceContextModule.toPortableImageStatus,
constant(operatingSystem), locationIndex);
ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "South");
converter.apply(novaImageInZoneToConvert);
}
private class MockImageToOsConverter implements Function<Image, OperatingSystem> {
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<Image, OperatingSystem> constant(OperatingSystem operatingSystem){
return Function.class.cast(Functions.constant(operatingSystem));
}
}

View File

@ -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
.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
.<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> 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
.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
.<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
.<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));

View File

@ -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.<Set<? extends Image>> ofInstance(images),
Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
.<Set<? extends Image>> ofInstance(images), Suppliers
.<Set<? extends Hardware>> 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.<Set<? extends Image>> ofInstance(images),
Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
.<Set<? extends Image>> ofInstance(images), Suppliers
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);

View File

@ -64,18 +64,50 @@ import com.google.inject.TypeLiteral;
public class VCloudComputeServiceDependenciesModule extends AbstractModule {
@VisibleForTesting
public static final Map<Status, NodeMetadata.Status> VAPPSTATUS_TO_NODESTATE = ImmutableMap.<Status, NodeMetadata.Status> 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<Status, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
.<Status, NodeMetadata.Status> 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<Status, NodeMetadata.Status> provideVAppStatusToNodeStatus() {
return VAPPSTATUS_TO_NODESTATE;
protected Map<Status, NodeMetadata.Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<Status, Image.Status> toPortableImageStatus = ImmutableMap
.<Status, Image.Status> 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<Status, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
@SuppressWarnings("unchecked")

View File

@ -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<VAppTemplate, Image> {
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final Map<Status, Image.Status> toPortableImageStatus;
private final Function<VAppTemplate, Envelope> templateToEnvelope;
private final FindLocationForResource findLocationForResource;
@Inject
protected ImageForVAppTemplate(Function<VAppTemplate, Envelope> templateToEnvelope,
protected ImageForVAppTemplate(Map<Status, Image.Status> toPortableImageStatus, Function<VAppTemplate, Envelope> 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<VAppTemplate, Image> {
}
builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
builder.operatingSystem(CIMOperatingSystem.toComputeOs(ovf));
builder.status(toPortableImageStatus.get(from.getStatus()));
return builder.build();
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -101,7 +101,7 @@ public class VAppToNodeMetadataTest {
@Singleton
@Provides
protected Map<Status, NodeMetadata.Status> provideVAppStatusToNodeStatus() {
return VCloudComputeServiceDependenciesModule.VAPPSTATUS_TO_NODESTATE;
return VCloudComputeServiceDependenciesModule.toPortableNodeStatus;
}
});

View File

@ -59,19 +59,37 @@ import com.google.inject.TypeLiteral;
public class TerremarkVCloudComputeServiceContextModule extends BaseComputeServiceContextModule {
@VisibleForTesting
public static final Map<Status, NodeMetadata.Status> VAPPSTATUS_TO_NODESTATE = ImmutableMap
.<Status, NodeMetadata.Status> 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<Status, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
.<Status, NodeMetadata.Status> 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<Status, NodeMetadata.Status> provideVAppStatusToNodeStatus() {
return VAPPSTATUS_TO_NODESTATE;
protected Map<Status, NodeMetadata.Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<Status, Image.Status> toPortableImageStatus = ImmutableMap
.<Status, Image.Status> 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<Status, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
@Override
protected void configure() {
super.configure();

View File

@ -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<VAppTemplate, Image> {
private final Map<Status, org.jclouds.compute.domain.Image.Status> toPortableImageStatus;
private final FindLocationForResource findLocationForResource;
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
private final Function<String, OperatingSystem> osParser;
@ -42,8 +46,9 @@ public class ImageForVCloudExpressVAppTemplate implements Function<VAppTemplate,
private ReferenceType parent;
@Inject
protected ImageForVCloudExpressVAppTemplate(FindLocationForResource findLocationForResource,
protected ImageForVCloudExpressVAppTemplate(Map<Status, Image.Status> toPortableImageStatus, FindLocationForResource findLocationForResource,
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, Function<String, OperatingSystem> 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<VAppTemplate,
builder.location(findLocationForResource.apply(checkNotNull(parent, "parent")));
builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
builder.operatingSystem(osParser.apply(from.getName()));
builder.status(toPortableImageStatus.get(from.getStatus()));
builder.defaultCredentials(credentialsProvider.apply(from));
return builder.build();
}

View File

@ -32,7 +32,7 @@ public class TerremarkVCloudComputeServiceContextModuleTest {
public void testAllStatusCovered() {
for (Status state : EnumSet.allOf(Status.class)) {
assert TerremarkVCloudComputeServiceContextModule.VAPPSTATUS_TO_NODESTATE.containsKey(state) : state;
assert TerremarkVCloudComputeServiceContextModule.toPortableNodeStatus.containsKey(state) : state;
}
}

View File

@ -31,7 +31,32 @@ import com.google.inject.ImplementedBy;
* @author Adrian Cole
*/
@ImplementedBy(ImageImpl.class)
public interface Image extends ComputeMetadata {
public interface Image extends ComputeMetadataIncludingStatus<Image.Status> {
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
*/

View File

@ -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;
}
/**
* <h4>will be removed in jclouds 1.4.0</h4>
*
* @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;
}
/**
* <h4>will be removed in jclouds 1.4.0</h4>
*
* @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());
}
}

View File

@ -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;
/**
* <h4>will be removed in jclouds 1.4.0</h4>
*/
@Deprecated
public ImageImpl(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, Set<String> 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<String, String> userMetadata, Set<String> tags, OperatingSystem operatingSystem, String description,
Map<String, String> userMetadata, Set<String> 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;
}
}

View File

@ -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();

View File

@ -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()));

View File

@ -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<OSTemplate, Image> {
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();
}
}

View File

@ -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<CIMOperatingSystem, I
builder.name(from.getName());
builder.description(from.getDescription());
builder.operatingSystem(from);
builder.status(Status.AVAILABLE);
return builder.build();
}

View File

@ -20,6 +20,8 @@ package org.jclouds.vcloud.director.v1_5.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;
@ -34,6 +36,7 @@ import org.jclouds.ovf.Envelope;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import com.google.common.base.Function;
@ -49,12 +52,15 @@ public class ImageForVAppTemplate implements Function<VAppTemplate, Image> {
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final Map<Status, Image.Status> toPortableImageStatus;
private final Function<VAppTemplate, Envelope> templateToEnvelope;
private final FindLocationForResource findLocationForResource;
@Inject
protected ImageForVAppTemplate(Function<VAppTemplate, Envelope> templateToEnvelope,
protected ImageForVAppTemplate(Map<Status, Image.Status> toPortableImageStatus, Function<VAppTemplate, Envelope> 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<VAppTemplate, Image> {
}
builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
builder.operatingSystem(CIMOperatingSystem.toComputeOs(ovf));
builder.status(toPortableImageStatus.get(from.getStatus()));
return builder.build();
}

View File

@ -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;

View File

@ -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<MachineState, Status> machineToNodeStatus = ImmutableMap
.<MachineState, Status> 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<MachineState, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
.<MachineState, NodeMetadata.Status> 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<MachineState, NodeMetadata.Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<MachineState, Image.Status> toPortableImageStatus = ImmutableMap
.<MachineState, Image.Status> 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<MachineState, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
}

View File

@ -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();
}
};

View File

@ -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<IMachine, Image> {
private final Map<MachineState, Status> toPortableImageStatus;
private final Supplier<VirtualBoxManager> virtualboxManager;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject
public IMachineToImage(Supplier<VirtualBoxManager> virtualboxManager, Map<OsFamily, Map<String, String>> osVersionMap) {
public IMachineToImage(Map<MachineState, Image.Status> toPortableImageStatus, Supplier<VirtualBoxManager> virtualboxManager, Map<OsFamily, Map<String, String>> 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<IMachine, Image> {
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();
}
}

View File

@ -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<IMachine, NodeMetadata>
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final Map<MachineState, Status> toPortableNodeStatus;
private final MachineUtils machineUtils;
@Inject
public IMachineToNodeMetadata(MachineUtils machineUtils) {
public IMachineToNodeMetadata(Map<MachineState, NodeMetadata.Status> toPortableNodeStatus, MachineUtils machineUtils) {
this.toPortableNodeStatus = toPortableNodeStatus;
this.machineUtils = machineUtils;
}
@ -90,7 +92,7 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
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);

View File

@ -177,7 +177,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
private NodeMetadata buildPartialNodeMetadata(IMachine clone) {
NodeMetadataBuilder nodeMetadataBuilder = new NodeMetadataBuilder();
nodeMetadataBuilder.id(clone.getName());
nodeMetadataBuilder.status(VirtualBoxComputeServiceContextModule.machineToNodeStatus.get(clone.getState()));
nodeMetadataBuilder.status(VirtualBoxComputeServiceContextModule.toPortableNodeStatus.get(clone.getState()));
nodeMetadataBuilder.publicAddresses(ImmutableSet.of(machineUtils.getIpAddressFromHostOnlyNIC(clone.getName())));
LoginCredentials loginCredentials = new LoginCredentials("toor", "password", null, true);

View File

@ -35,6 +35,7 @@ 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.functions.IMachineToImage;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IGuestOSType;
@ -79,7 +80,8 @@ public class VirtualBoxComputeServiceAdapterTest {
replay(manager, vBox, clonedMachine, imageMachine, osType);
Function<IMachine, Image> iMachineToImage = new IMachineToImage(Suppliers.ofInstance(manager), osMap);
Function<IMachine, Image> iMachineToImage = new IMachineToImage(
VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers.ofInstance(manager), osMap);
// VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(Suppliers.ofInstance(manager), iMachineToImage, new ImageFromYamlString(), new Supplier<String>() {
//
// @Override

View File

@ -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<OsFamily, Map<String, String>> 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);

View File

@ -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());

View File

@ -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<Image, YamlImage> images;

View File

@ -163,7 +163,7 @@ public class AWSRunningInstanceToNodeMetadataTest {
protected AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
final ImmutableSet<Location> locations, Set<org.jclouds.compute.domain.Image> images,
Map<String, Credentials> credentialStore) {
Map<InstanceState, Status> instanceToNodeStatus = EC2ComputeServiceDependenciesModule.instanceToNodeStatus;
Map<InstanceState, Status> instanceToNodeStatus = EC2ComputeServiceDependenciesModule.toPortableNodeStatus;
final Map<RegionAndName, ? extends Image> backing = ImagesToRegionAndIdMap.imagesToMap(images);

View File

@ -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<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)),
Suppliers.ofInstance(defaultLocation), new AWSEC2ReviseParsedImage(map));
EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus,
new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
.ofInstance(defaultLocation), new AWSEC2ReviseParsedImage(map));
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}
}

View File

@ -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);

View File

@ -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<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus,
new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
.ofInstance(defaultLocation), new EucalyptusPartnerCloudReviseParsedImage(map));
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}

View File

@ -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<ServerState, Status> serverStateToNodeStatus = ImmutableMap.<ServerState, Status> 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<ServerState, Status> toPortableNodeStatus = ImmutableMap.<ServerState, Status> 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<ServerState, Status> provideServerToNodeStatus() {
return serverStateToNodeStatus;
Map<ServerState, Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
static final Map<ServerImageState, Image.Status> toPortableImageStatus = ImmutableMap
.<ServerImageState, Image.Status> 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<ServerImageState, Image.Status> 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

View File

@ -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<ServerImage, Image> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final Map<ServerImageState, Status> toPortableImageStatus;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject
ServerImageToImage(Map<OsFamily, Map<String, String>> osVersionMap) {
ServerImageToImage(Map<ServerImageState, Image.Status> toPortableImageStatus,
Map<OsFamily, Map<String, String>> osVersionMap) {
this.toPortableImageStatus = toPortableImageStatus;
this.osVersionMap = osVersionMap;
}
@ -93,6 +98,7 @@ public class ServerImageToImage implements Function<ServerImage, Image> {
builder.name(from.getFriendlyName());
builder.description(from.getDescription());
builder.operatingSystem(parseOs(from));
builder.status(toPortableImageStatus.get(from.getState()));
return builder.build();
}

View File

@ -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;
}
}

View File

@ -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<Set<? extends Image>>
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());

View File

@ -46,6 +46,7 @@ public class SlicehostImageToImage implements Function<org.jclouds.slicehost.dom
builder.name(from.getName());
builder.description(from.getName());
builder.operatingSystem(imageToOs.apply(from));
builder.status(Image.Status.AVAILABLE);
Image image = builder.build();
return image;
}

View File

@ -41,31 +41,38 @@ import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
@Test(groups = "unit", testName = "SlicehostImageToImageTest")
public class SlicehostImageToImageTest {
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
@Test
public void test() throws UnknownHostException {
Image toTest = convertImage();
assertEquals(
convertImage(),
toTest,
new ImageBuilder()
.name("CentOS 5.2")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2")
.is64Bit(true).build()).description("CentOS 5.2").ids("2").build());
.is64Bit(true).build()).description("CentOS 5.2").ids("2")
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
assertEquals(toTest.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
}
@Test
public void test32() throws UnknownHostException {
Image toTest = convertImage("/test_get_image32.xml");
assertEquals(
convertImage("/test_get_image32.xml"),
toTest,
new ImageBuilder()
.name("Ubuntu 10.10 (maverick) 32-bit")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UBUNTU).version("10.10")
.description("Ubuntu 10.10 (maverick) 32-bit").build())
.description("Ubuntu 10.10 (maverick) 32-bit").ids("70").build());
.description("Ubuntu 10.10 (maverick) 32-bit").ids("70")
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
assertEquals(toTest.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
}
public static Image convertImage() {

View File

@ -90,6 +90,7 @@ public class ProductItemToImage implements Function<ProductItem, Image> {
.ids(imageId().apply(productItem))
.description(description)
.operatingSystem(os)
.status(Image.Status.AVAILABLE)
.build();
}

View File

@ -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<String> operatingSystems = Arrays.asList(

View File

@ -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();
}
}
}

View File

@ -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<org.jclouds.serverman
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", from);
}
builder.status(Status.AVAILABLE);
return builder.build();
}