Applied fixes suggested in last review

Renamed VirtualMachineTemplateWithZone to
VirtualMachineTemplateInVirtualDatacenter and encoded the id using a
slash instead of the hyphen.
This commit is contained in:
Ignasi Barrera 2012-10-21 22:44:24 +02:00
parent 26f801058d
commit e9502ab81e
7 changed files with 67 additions and 61 deletions

View File

@ -22,14 +22,14 @@ package org.jclouds.abiquo.compute.config;
import org.jclouds.abiquo.compute.functions.DatacenterToLocation;
import org.jclouds.abiquo.compute.functions.VirtualDatacenterToLocation;
import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateToImage;
import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateWithZoneToHardware;
import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateInVirtualDatacenterToHardware;
import org.jclouds.abiquo.compute.functions.VirtualMachineToNodeMetadata;
import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions;
import org.jclouds.abiquo.compute.strategy.AbiquoComputeServiceAdapter;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
@ -52,7 +52,7 @@ import com.google.inject.TypeLiteral;
*/
public class AbiquoComputeServiceContextModule
extends
ComputeServiceAdapterContextModule<VirtualMachine, VirtualMachineTemplateWithZone, VirtualMachineTemplate, VirtualDatacenter>
ComputeServiceAdapterContextModule<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>
{
@Override
@ -60,7 +60,7 @@ public class AbiquoComputeServiceContextModule
{
super.configure();
bind(
new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateWithZone, VirtualMachineTemplate, VirtualDatacenter>>()
new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>>()
{
}).to(AbiquoComputeServiceAdapter.class);
bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>()
@ -69,9 +69,9 @@ public class AbiquoComputeServiceContextModule
bind(new TypeLiteral<Function<VirtualMachineTemplate, Image>>()
{
}).to(VirtualMachineTemplateToImage.class);
bind(new TypeLiteral<Function<VirtualMachineTemplateWithZone, Hardware>>()
bind(new TypeLiteral<Function<VirtualMachineTemplateInVirtualDatacenter, Hardware>>()
{
}).to(VirtualMachineTemplateWithZoneToHardware.class);
}).to(VirtualMachineTemplateInVirtualDatacenterToHardware.class);
bind(new TypeLiteral<Function<Datacenter, Location>>()
{
}).to(DatacenterToLocation.class);
@ -80,7 +80,7 @@ public class AbiquoComputeServiceContextModule
}).to(VirtualDatacenterToLocation.class);
bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON);
bind(TemplateOptions.class).to(AbiquoTemplateOptions.class);
install(new LocationsFromComputeServiceAdapterModule<VirtualMachine, VirtualMachineTemplateWithZone, VirtualMachineTemplate, VirtualDatacenter>()
install(new LocationsFromComputeServiceAdapterModule<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>()
{
});
}

View File

@ -26,7 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image;
@ -47,8 +47,8 @@ import com.google.common.base.Function;
* @author Ignasi Barrera
*/
@Singleton
public class VirtualMachineTemplateWithZoneToHardware implements
Function<VirtualMachineTemplateWithZone, Hardware>
public class VirtualMachineTemplateInVirtualDatacenterToHardware implements
Function<VirtualMachineTemplateInVirtualDatacenter, Hardware>
{
/** The default core speed, 2.0Ghz. */
public static final double DEFAULT_CORE_SPEED = 2.0;
@ -56,7 +56,7 @@ public class VirtualMachineTemplateWithZoneToHardware implements
private final Function<VirtualDatacenter, Location> virtualDatacenterToLocation;
@Inject
public VirtualMachineTemplateWithZoneToHardware(
public VirtualMachineTemplateInVirtualDatacenterToHardware(
final Function<VirtualDatacenter, Location> virtualDatacenterToLocation)
{
this.virtualDatacenterToLocation =
@ -64,14 +64,15 @@ public class VirtualMachineTemplateWithZoneToHardware implements
}
@Override
public Hardware apply(final VirtualMachineTemplateWithZone templateWithZone)
public Hardware apply(
final VirtualMachineTemplateInVirtualDatacenter templateInVirtualDatacenter)
{
VirtualMachineTemplate template = templateWithZone.getTemplate();
VirtualDatacenter zone = templateWithZone.getZone();
VirtualMachineTemplate template = templateInVirtualDatacenter.getTemplate();
VirtualDatacenter virtualDatacenter = templateInVirtualDatacenter.getZone();
HardwareBuilder builder = new HardwareBuilder();
builder.providerId(template.getId().toString());
builder.id(template.getId().toString() + "-" + zone.getId());
builder.id(template.getId().toString() + "/" + virtualDatacenter.getId());
builder.uri(template.getURI());
builder.name(template.getName());
@ -79,8 +80,8 @@ public class VirtualMachineTemplateWithZoneToHardware implements
builder.ram(template.getRamRequired());
// Location information
builder.location(virtualDatacenterToLocation.apply(zone));
builder.hypervisor(zone.getHypervisorType().name());
builder.location(virtualDatacenterToLocation.apply(virtualDatacenter));
builder.hypervisor(virtualDatacenter.getHypervisorType().name());
builder.supportsImage(ImagePredicates.idEquals(template.getId().toString()));
VolumeBuilder volumeBuilder = new VolumeBuilder();

View File

@ -32,7 +32,7 @@ import javax.inject.Singleton;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.abiquo.domain.network.Ip;
import org.jclouds.abiquo.domain.network.PrivateIp;
import org.jclouds.compute.domain.Hardware;
@ -62,7 +62,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
private final VirtualMachineTemplateToImage virtualMachineTemplateToImage;
private final VirtualMachineTemplateWithZoneToHardware virtualMachineTemplateToHardware;
private final VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware;
private final VirtualMachineStateToNodeState virtualMachineStateToNodeState;
@ -71,7 +71,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
@Inject
public VirtualMachineToNodeMetadata(
final VirtualMachineTemplateToImage virtualMachineTemplateToImage,
final VirtualMachineTemplateWithZoneToHardware virtualMachineTemplateToHardware,
final VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware,
final VirtualMachineStateToNodeState virtualMachineStateToNodeState,
final Function<VirtualDatacenter, Location> virtualDatacenterToLocation)
{
@ -110,7 +110,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
// Hardware details
Hardware defaultHardware =
virtualMachineTemplateToHardware
.apply(new VirtualMachineTemplateWithZone(template, vdc));
.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
Hardware hardware =
HardwareBuilder
@ -118,7 +118,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
.ram(vm.getRam())
.processors(
Lists.newArrayList(new Processor(vm.getCpu(),
VirtualMachineTemplateWithZoneToHardware.DEFAULT_CORE_SPEED))) //
VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED))) //
.build();
builder.hardware(hardware);

View File

@ -37,7 +37,7 @@ import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.abiquo.domain.enterprise.Enterprise;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.domain.network.PublicIp;
@ -74,7 +74,7 @@ import com.google.inject.Inject;
@Singleton
public class AbiquoComputeServiceAdapter
implements
ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateWithZone, VirtualMachineTemplate, VirtualDatacenter>
ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>
{
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -168,29 +168,29 @@ public class AbiquoComputeServiceAdapter
}
@Override
public Iterable<VirtualMachineTemplateWithZone> listHardwareProfiles()
public Iterable<VirtualMachineTemplateInVirtualDatacenter> listHardwareProfiles()
{
// In Abiquo, images are scoped to a region (physical datacenter), and hardware profiles are
// scoped to a zone (a virtual datacenter in the region, with a concrete virtualization
// technology)
return concat(transform(listImages(),
new Function<VirtualMachineTemplate, Iterable<VirtualMachineTemplateWithZone>>()
new Function<VirtualMachineTemplate, Iterable<VirtualMachineTemplateInVirtualDatacenter>>()
{
@Override
public Iterable<VirtualMachineTemplateWithZone> apply(
public Iterable<VirtualMachineTemplateInVirtualDatacenter> apply(
final VirtualMachineTemplate template)
{
Iterable<VirtualDatacenter> compatibleZones =
compatibleVirtualDatacenters.execute(template);
return transform(compatibleZones,
new Function<VirtualDatacenter, VirtualMachineTemplateWithZone>()
new Function<VirtualDatacenter, VirtualMachineTemplateInVirtualDatacenter>()
{
@Override
public VirtualMachineTemplateWithZone apply(final VirtualDatacenter vdc)
public VirtualMachineTemplateInVirtualDatacenter apply(final VirtualDatacenter vdc)
{
return new VirtualMachineTemplateWithZone(template, vdc);
return new VirtualMachineTemplateInVirtualDatacenter(template, vdc);
}
});
}

View File

@ -26,13 +26,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* @author Ignasi Barrera
*/
public class VirtualMachineTemplateWithZone
public class VirtualMachineTemplateInVirtualDatacenter
{
private VirtualMachineTemplate template;
private VirtualDatacenter zone;
public VirtualMachineTemplateWithZone(final VirtualMachineTemplate template,
public VirtualMachineTemplateInVirtualDatacenter(final VirtualMachineTemplate template,
final VirtualDatacenter zone)
{
super();

View File

@ -34,7 +34,7 @@ import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Volume;
import org.jclouds.domain.Location;
@ -48,20 +48,20 @@ import com.abiquo.server.core.cloud.VirtualDatacenterDto;
import com.google.common.base.Function;
/**
* Unit tests for the {@link VirtualMachineTemplateWithZoneToHardware} function.
* Unit tests for the {@link VirtualMachineTemplateInVirtualDatacenterToHardware} function.
*
* @author Ignasi Barrera
*/
@Test(groups = "unit", testName = "VirtualMachineTemplateToHardwareTest")
public class VirtualMachineTemplateWithZoneToHardwareTest
@Test(groups = "unit", testName = "VirtualMachineTemplateInVirtualDatacenterToHardwareTest")
public class VirtualMachineTemplateInVirtualDatacenterToHardwareTest
{
@SuppressWarnings("unchecked")
public void testVirtualMachineTemplateToHardware()
{
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation);
VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
dto.setId(5);
@ -78,12 +78,13 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc));
Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation);
assertEquals(hardware.getProviderId(), template.getId().toString());
assertEquals(hardware.getId(), template.getId() + "-" + vdc.getId());
assertEquals(hardware.getId(), template.getId() + "/" + vdc.getId());
assertEquals(hardware.getName(), template.getName());
assertEquals(hardware.getUri(), URI.create("http://foo/bar"));
@ -91,7 +92,7 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
assertEquals(hardware.getProcessors().size(), 1);
assertEquals(hardware.getProcessors().get(0).getCores(), (double) template.getCpuRequired());
assertEquals(hardware.getProcessors().get(0).getSpeed(),
VirtualMachineTemplateWithZoneToHardware.DEFAULT_CORE_SPEED);
VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED);
assertEquals(hardware.getVolumes().size(), 1);
assertEquals(hardware.getVolumes().get(0).getSize(), 50F);
@ -105,8 +106,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation);
VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
dto.setId(5);
@ -122,7 +123,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc));
Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation);
@ -135,14 +137,14 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation);
VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplate template =
wrap(context, VirtualMachineTemplate.class, new VirtualMachineTemplateDto());
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, new VirtualDatacenterDto());
function.apply(new VirtualMachineTemplateWithZone(template, vdc));
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
}
@SuppressWarnings("unchecked")
@ -150,8 +152,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation);
VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
dto.setId(5);
@ -166,7 +168,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc));
Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation);
@ -179,8 +182,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation);
VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
dto.setId(5);
@ -195,7 +198,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc));
Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation);
@ -207,8 +211,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation);
VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
// VirtualMachineTemplate domain object does not have a builder, it is read only
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
@ -224,7 +228,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc));
Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation);

View File

@ -33,7 +33,7 @@ import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.abiquo.domain.network.ExternalIp;
import org.jclouds.abiquo.domain.network.Ip;
import org.jclouds.abiquo.domain.network.PrivateIp;
@ -157,13 +157,13 @@ public class VirtualMachineToNodeMetadataTest
return templateToImage;
}
private VirtualMachineTemplateWithZoneToHardware templateToHardware()
private VirtualMachineTemplateInVirtualDatacenterToHardware templateToHardware()
{
VirtualMachineTemplateWithZoneToHardware virtualMachineTemplateToHardware =
EasyMock.createMock(VirtualMachineTemplateWithZoneToHardware.class);
VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware =
EasyMock.createMock(VirtualMachineTemplateInVirtualDatacenterToHardware.class);
expect(
virtualMachineTemplateToHardware.apply(anyObject(VirtualMachineTemplateWithZone.class)))
virtualMachineTemplateToHardware.apply(anyObject(VirtualMachineTemplateInVirtualDatacenter.class)))
.andReturn(hardware);
replay(virtualMachineTemplateToHardware);