From f4afd8a53f70e44ca233e7e4056066fc2bb35b4c Mon Sep 17 00:00:00 2001 From: andreaturli Date: Sun, 12 Dec 2010 16:34:25 +0100 Subject: [PATCH 01/33] fix on jclouds-vsphere --- .../src/main/java/org/jclouds/vi/Image.java | 4 +- .../jclouds/vi/compute/ViComputeService.java | 3 -- .../ViComputeServiceContextBuilder.java | 5 -- .../compute/ViComputeServiceContextSpec.java | 2 +- .../vi/compute/ViPropertiesBuilder.java | 4 +- .../config/ViComputeServiceContextModule.java | 14 ++--- .../functions/DatacenterToLocation.java | 4 +- .../functions/LibvirtNodeToLocation.java | 42 --------------- .../vi/compute/functions/ViImageToImage.java | 1 + .../functions/VirtualMachineToHardware.java | 47 +++++++---------- .../VirtualMachineToNodeMetadata.java | 38 +++++++------- .../strategy/ViComputeServiceAdapter.java | 51 ++++++++++--------- .../ViComputeServiceContextBuilderTest.java | 3 +- .../vi/compute/ViComputeServiceLiveTest.java | 3 +- .../vi/compute/ViExperimentLiveTest.java | 45 ++++++++-------- 15 files changed, 103 insertions(+), 163 deletions(-) delete mode 100644 sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/LibvirtNodeToLocation.java diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/Image.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/Image.java index 069b5bfd67..463029bbf6 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/Image.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/Image.java @@ -28,10 +28,10 @@ import com.google.common.base.Objects; */ public class Image { - public int id; + public String id; public String name; - public Image(int id, String name) { + public Image(String id, String name) { this.id = id; this.name = name; } diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeService.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeService.java index f5b240a3fa..72a6fc5f8d 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeService.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeService.java @@ -19,7 +19,6 @@ package org.jclouds.vi.compute; -import java.io.StringReader; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -49,12 +48,10 @@ import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.util.ComputeUtils; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; -import org.xml.sax.InputSource; import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.base.Throwables; -import com.jamesmurty.utils.XMLBuilder; import com.vmware.vim25.mo.ServiceInstance; /** diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeServiceContextBuilder.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeServiceContextBuilder.java index 8baff48f3d..26565137e2 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeServiceContextBuilder.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeServiceContextBuilder.java @@ -19,8 +19,6 @@ package org.jclouds.vi.compute; -import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR; - import java.util.List; import java.util.Properties; @@ -38,9 +36,6 @@ public class ViComputeServiceContextBuilder extends StandaloneComputeServiceCont public ViComputeServiceContextBuilder(Properties props) { super(ServiceInstance.class, props); - - if (!properties.containsKey(PROPERTY_LIBVIRT_DOMAIN_DIR)) - properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu"); } @Override diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeServiceContextSpec.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeServiceContextSpec.java index c28e15f75c..ad186a411a 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeServiceContextSpec.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViComputeServiceContextSpec.java @@ -33,7 +33,7 @@ public class ViComputeServiceContextSpec extends RestContextSpec modules) { - super("vsphere", endpoint, "1", identity, credential, ComputeService.class, ComputeService.class, + super("vi", endpoint, "1", identity, credential, ComputeService.class, ComputeService.class, PropertiesBuilder.class, (Class) ViComputeServiceContextBuilder.class, modules); } diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViPropertiesBuilder.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViPropertiesBuilder.java index 98a154751f..4823cdbcbb 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViPropertiesBuilder.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/ViPropertiesBuilder.java @@ -29,7 +29,7 @@ import java.util.Properties; import org.jclouds.PropertiesBuilder; /** - * Builds properties used in Libvirt Clients + * Builds properties used in vi Clients * * @author Andrea Turli */ @@ -37,7 +37,7 @@ public class ViPropertiesBuilder extends PropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu"); +// properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu"); properties.setProperty(PROPERTY_TIMEOUT_NODE_SUSPENDED, 120 * 1000 + ""); // auth fail sometimes happens in EC2, as the rc.local script that injects the diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java index 981bf94052..0d908458f4 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java @@ -19,8 +19,6 @@ package org.jclouds.vi.compute.config; -import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR; - import java.io.File; import java.io.IOException; import java.io.StringReader; @@ -45,7 +43,6 @@ import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.suppliers.DefaultLocationSupplier; import org.jclouds.domain.Location; import org.jclouds.rest.annotations.Provider; -import org.jclouds.vi.Datacenter; import org.jclouds.vi.Image; import org.jclouds.vi.compute.functions.DatacenterToLocation; import org.jclouds.vi.compute.functions.ViImageToImage; @@ -61,11 +58,10 @@ import com.google.common.base.Supplier; import com.google.common.collect.Iterables; import com.google.common.io.Files; import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Provides; import com.google.inject.TypeLiteral; -import com.google.inject.name.Names; import com.jamesmurty.utils.XMLBuilder; +import com.vmware.vim25.mo.Datacenter; import com.vmware.vim25.mo.ServiceInstance; import com.vmware.vim25.mo.VirtualMachine; @@ -97,16 +93,14 @@ public class ViComputeServiceContextModule extends protected ServiceInstance createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential) throws RemoteException, MalformedURLException { - System.out.println(endpoint); - System.out.println(identity); - System.out.println(credential); return new ServiceInstance(endpoint.toURL(), identity, credential, true); } @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); - String hardwareId = searchForHardwareIdInDomainDir(domainDir); + //String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); + String domainDir = ""; + String hardwareId = searchForHardwareIdInDomainDir(domainDir); String image = searchForImageIdInDomainDir(domainDir); return template.hardwareId(hardwareId).imageId(image); } diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/DatacenterToLocation.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/DatacenterToLocation.java index d5ac03464d..e07d865770 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/DatacenterToLocation.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/DatacenterToLocation.java @@ -24,9 +24,9 @@ import javax.inject.Singleton; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.internal.LocationImpl; -import org.jclouds.vi.Datacenter; import com.google.common.base.Function; +import com.vmware.vim25.mo.Datacenter; /** * @author Adrian Cole @@ -36,7 +36,7 @@ public class DatacenterToLocation implements Function { @Override public Location apply(Datacenter from) { - return new LocationImpl(LocationScope.ZONE, from.id + "", from.name, null); + return new LocationImpl(LocationScope.ZONE, from.getName() + "", from.getName(), null); } } diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/LibvirtNodeToLocation.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/LibvirtNodeToLocation.java deleted file mode 100644 index 9482ec7220..0000000000 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/LibvirtNodeToLocation.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.vi.compute.functions; - -import javax.inject.Singleton; - -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationScope; -import org.jclouds.domain.internal.LocationImpl; -import org.jclouds.vi.Datacenter; - -import com.google.common.base.Function; - -/** - * @author Adrian Cole - */ -@Singleton -public class LibvirtNodeToLocation implements Function { - - @Override - public Location apply(Datacenter from) { - return new LocationImpl(LocationScope.ZONE, from.id + "", from.name, null); - } - -} diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/ViImageToImage.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/ViImageToImage.java index 7fdedf6538..8275831d22 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/ViImageToImage.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/ViImageToImage.java @@ -51,6 +51,7 @@ public class ViImageToImage implements Function { OsFamily family = null; try { + // TODO family = OsFamily.fromValue(from.name); builder.operatingSystem(new OperatingSystemBuilder().name(from.name).family(family).description(from.name).build()); } catch (IllegalArgumentException e) { diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/VirtualMachineToHardware.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/VirtualMachineToHardware.java index 281de80a11..8a6938766b 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/VirtualMachineToHardware.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/VirtualMachineToHardware.java @@ -19,31 +19,23 @@ package org.jclouds.vi.compute.functions; -import java.io.IOException; -import java.io.StringReader; import java.util.List; import javax.inject.Singleton; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Volume; import org.jclouds.compute.domain.internal.VolumeImpl; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.Lists; -import com.jamesmurty.utils.XMLBuilder; +import com.vmware.vim25.VirtualDevice; +import com.vmware.vim25.VirtualDeviceBackingInfo; +import com.vmware.vim25.VirtualDisk; +import com.vmware.vim25.VirtualDiskFlatVer2BackingInfo; import com.vmware.vim25.mo.VirtualMachine; /** @@ -67,26 +59,21 @@ public class VirtualMachineToHardware implements Function volumes = Lists.newArrayList(); - - /* - XMLBuilder xmlBuilder = XMLBuilder.parse(new InputSource(new StringReader(from.getXMLDesc(0)))); - Document doc = xmlBuilder.getDocument(); - XPathExpression expr = XPathFactory.newInstance().newXPath().compile("//devices/disk[@device='disk']/source/@file"); - NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); - String diskFileName = nodes.item(0).getNodeValue(); - for (int i = 0; i < nodes.getLength(); i++) { - StorageVol storageVol = from.getConnect().storageVolLookupByPath(diskFileName); - String id = storageVol.getKey(); - float size = new Long(storageVol.getInfo().capacity).floatValue(); - volumes.add(new VolumeImpl(id, Volume.Type.LOCAL, size, null, true, false)); + // look for volumes + VirtualDevice[] devices = from.getConfig().getHardware().getDevice(); + for (VirtualDevice virtualDevice : devices) { + if(virtualDevice.getDeviceInfo().getLabel().contains("Hard disk")) { + if(virtualDevice instanceof VirtualDisk) { + VirtualDisk disk = (VirtualDisk) virtualDevice; + VirtualDeviceBackingInfo backingInfo = disk.getBacking(); + if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) { + VirtualDiskFlatVer2BackingInfo diskFlatVer2BackingInfo = (VirtualDiskFlatVer2BackingInfo) backingInfo; + volumes.add(new VolumeImpl(diskFlatVer2BackingInfo.getUuid(), Volume.Type.LOCAL, new Float(disk.getCapacityInKB() + ""), diskFlatVer2BackingInfo.getFileName(), true, false)); + } + } + } } - */ - - // TODO builder.volumes((List) volumes); - Float size = new Float(21345); - String id = "dglffdbdflmb"; - volumes.add(new VolumeImpl(id, Volume.Type.LOCAL, size, null, true, false)); return builder.build(); } diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/VirtualMachineToNodeMetadata.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/VirtualMachineToNodeMetadata.java index 6fd5d2d3d7..f11883f2a9 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/VirtualMachineToNodeMetadata.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/functions/VirtualMachineToNodeMetadata.java @@ -59,18 +59,18 @@ public class VirtualMachineToNodeMetadata implements Function findHardwareForDomain; - private final FindLocationForDomain findLocationForDomain; - private final FindImageForDomain findImageForDomain; + private final Function findHardwareForVirtualMachine; + private final FindLocationForVirtualMachine findLocationForVirtualMachine; + private final FindImageForVirtualMachine findImageForVirtualMachine; private final Map credentialStore; @Inject - VirtualMachineToNodeMetadata(Map credentialStore, Function findHardwareForDomain, - FindLocationForDomain findLocationForDomain, FindImageForDomain findImageForDomain) { + VirtualMachineToNodeMetadata(Map credentialStore, Function findHardwareForVirtualMachine, + FindLocationForVirtualMachine findLocationForVirtualMachine, FindImageForVirtualMachine findImageForVirtualMachine) { this.credentialStore = checkNotNull(credentialStore, "credentialStore"); - this.findHardwareForDomain = checkNotNull(findHardwareForDomain, "findHardwareForDomain"); - this.findLocationForDomain = checkNotNull(findLocationForDomain, "findLocationForDomain"); - this.findImageForDomain = checkNotNull(findImageForDomain, "findImageForDomain"); + this.findHardwareForVirtualMachine = checkNotNull(findHardwareForVirtualMachine, "findHardwareForVirtualMachine"); + this.findLocationForVirtualMachine = checkNotNull(findLocationForVirtualMachine, "findLocationForVirtualMachine"); + this.findImageForVirtualMachine = checkNotNull(findImageForVirtualMachine, "findImageForVirtualMachine"); } @Override @@ -79,19 +79,23 @@ public class VirtualMachineToNodeMetadata implements Function of(from.publicAddress)); // builder.privateAddresses(ImmutableSet. of(from.privateAddress)); - builder.credentials(credentialStore.get("node#" + from.getMOR().get_value())); + builder.credentials(credentialStore.get("node#" + from.getName())); } catch (Exception e) { // TODO Auto-generated catch block @@ -101,10 +105,10 @@ public class VirtualMachineToNodeMetadata implements Function { + public static class FindImageForVirtualMachine extends FindResourceInSet { @Inject - public FindImageForDomain(@Memoized Supplier> hardware) { + public FindImageForVirtualMachine(@Memoized Supplier> hardware) { super(hardware); } @@ -117,10 +121,10 @@ public class VirtualMachineToNodeMetadata implements Function { + public static class FindLocationForVirtualMachine extends FindResourceInSet { @Inject - public FindLocationForDomain(@Memoized Supplier> hardware) { + public FindLocationForVirtualMachine(@Memoized Supplier> hardware) { super(hardware); } diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/strategy/ViComputeServiceAdapter.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/strategy/ViComputeServiceAdapter.java index a0ac47bec2..47326098f1 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/strategy/ViComputeServiceAdapter.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/strategy/ViComputeServiceAdapter.java @@ -20,7 +20,6 @@ package org.jclouds.vi.compute.strategy; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR; import java.rmi.RemoteException; import java.util.List; @@ -33,14 +32,14 @@ import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.domain.Template; import org.jclouds.domain.Credentials; -import org.jclouds.vi.Datacenter; import org.jclouds.vi.Image; import com.google.common.base.Throwables; import com.google.common.collect.Lists; -import com.google.inject.name.Named; import com.vmware.vim25.InvalidProperty; import com.vmware.vim25.RuntimeFault; +import com.vmware.vim25.mo.Datacenter; +import com.vmware.vim25.mo.Folder; import com.vmware.vim25.mo.InventoryNavigator; import com.vmware.vim25.mo.ManagedEntity; import com.vmware.vim25.mo.ServiceInstance; @@ -116,25 +115,25 @@ public class ViComputeServiceAdapter implements ComputeServiceAdapter listHardwareProfiles() { - return listNodes(); + // TODO + return null; } @Override public Iterable listImages() { - /* - int i = 1; + List images = Lists.newArrayList(); try { - String[] domains = client.listDefinedDomains(); - List images = Lists.newArrayList(); - for (String domainName : domains) { - images.add(new Image(i++, domainName)); + + ManagedEntity[] entities = new InventoryNavigator( + client.getRootFolder()).searchManagedEntities("VirtualMachine"); + for (ManagedEntity entity : entities) { + VirtualMachine vm = (VirtualMachine) entity; + images.add(new Image(vm.getConfig().getGuestId(), vm.getConfig().getGuestFullName())); } return images; } catch (Exception e) { return propogate(e); } - */ - return null; } @Override @@ -143,8 +142,8 @@ public class ViComputeServiceAdapter implements ComputeServiceAdapter vms = Lists.newArrayList(); for (ManagedEntity entity : vmEntities) { - System.out.println(entity.getName()); - vms.add((VirtualMachine) entity); + VirtualMachine vm = (VirtualMachine) entity; + vms.add(vm); } return vms; } catch (InvalidProperty e) { @@ -164,7 +163,7 @@ public class ViComputeServiceAdapter implements ComputeServiceAdapter datacenters = Lists.newArrayList(); for (int i = 0; i< datacenterEntities.length; i++) { - datacenters.add(new Datacenter(i, datacenterEntities[i].getName())); + datacenters.add((Datacenter) datacenterEntities[i]); } return datacenters; } catch (InvalidProperty e) { @@ -178,18 +177,20 @@ public class ViComputeServiceAdapter implements ComputeServiceAdapter goGridContext = new ComputeServiceContextFactory().createContext( + RestContext viContext = new ComputeServiceContextFactory().createContext( provider, identity, credential).getProviderSpecificContext(); } } diff --git a/sandbox/vsphere/src/test/java/org/jclouds/vi/compute/ViExperimentLiveTest.java b/sandbox/vsphere/src/test/java/org/jclouds/vi/compute/ViExperimentLiveTest.java index c9bb37b772..f4a4859cee 100644 --- a/sandbox/vsphere/src/test/java/org/jclouds/vi/compute/ViExperimentLiveTest.java +++ b/sandbox/vsphere/src/test/java/org/jclouds/vi/compute/ViExperimentLiveTest.java @@ -25,9 +25,11 @@ import java.util.Set; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.vi.compute.ViComputeServiceContextSpec; +import org.jclouds.domain.Location; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -57,37 +59,38 @@ public class ViExperimentLiveTest { try { context = new ComputeServiceContextFactory().createContext(new ViComputeServiceContextSpec( endpoint, identity, credential)); - context.getComputeService().listNodes(); - - /* - * /* System.out.println("images " + context.getComputeService().listImages()); - * System.out.println("nodes " + context.getComputeService().listNodes()); - * System.out.println("hardware profiles " + - * context.getComputeService().listHardwareProfiles()); - */ +// Set locations = context.getComputeService().listAssignableLocations(); +// +// Set nodes = context.getComputeService().listNodes(); - -/* Template defaultTemplate = context.getComputeService().templateBuilder() - .hardwareId("d106ae67-5a1b-8f91-b311-83c93bcb0a1f").imageId("1") //.locationId("") - .build();*/ - + // TODO +// Set hardwares = context.getComputeService().listHardwareProfiles(); +// +// Set images = context.getComputeService().listImages(); + + NodeMetadata node = context.getComputeService().getNodeMetadata("provaVM"); + System.out.println(node); /* * We will probably make a default template out of properties at some point You can control * the default template via overriding a method in standalonecomputeservicexontextmodule */ - - Set nodeMetadataSet = context.getComputeService().runNodesWithTag("tty", 1); + + /* Template defaultTemplate = context.getComputeService().templateBuilder() + .hardwareId("d106ae67-5a1b-8f91-b311-83c93bcb0a1f").imageId("1") //.locationId("") + .build(); + Set nodeMetadataSet = context.getComputeService().runNodesWithTag("MyServer", 1); for (NodeMetadata nodeMetadata : nodeMetadataSet) { - /* - * context.getComputeService().suspendNode(nodeMetadata.getId()); - * context.getComputeService().resumeNode(nodeMetadata.getId()); - */ + +// context.getComputeService().suspendNode(nodeMetadata.getId()); +// context.getComputeService().resumeNode(nodeMetadata.getId()); + context.getComputeService().destroyNode(nodeMetadata.getId()); } } catch (Exception e) { e.printStackTrace(); + */ } finally { if (context != null) context.close(); From 3921856973dbd795b04657536ec372cb0a294c63 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 17 Dec 2010 19:14:32 +0100 Subject: [PATCH 02/33] updated to latest ec2 image version numbers --- .../org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java | 2 +- .../org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java index 496d7c0b7c..47cb94c0a8 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java @@ -90,7 +90,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { protected void assertDefaultWorks() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.9-beta"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "2010.11.1-beta"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java index 8d6d44e70a..3c592eed75 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java @@ -75,7 +75,7 @@ public class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { assertEquals(template.getImage().getOperatingSystem().getVersion(), "10.10"); assertEquals(template.getImage().getOperatingSystem().is64Bit(), false); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); - assertEquals(template.getImage().getVersion(), "20101204"); + assertEquals(template.getImage().getVersion(), "20101215"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(getCores(template.getHardware()), 1.0d); From c1f6eab2c4998e217f74182fa53770cbfa7e2952 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 17 Dec 2010 19:15:35 +0100 Subject: [PATCH 03/33] refactored test logic --- .../compute/BaseComputeServiceLiveTest.java | 1 + .../org/jclouds/compute/RunScriptData.java | 89 ++++++++++--------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 72b376e831..8a84eb71f9 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -474,6 +474,7 @@ public abstract class BaseComputeServiceLiveTest { template = client.templateBuilder().options(blockOnComplete(false).blockOnPort(8080, 600).inboundPorts(22, 8080)) .build(); + // note this is a dependency on the template resolution template.getOptions().runScript( RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage() diff --git a/compute/src/test/java/org/jclouds/compute/RunScriptData.java b/compute/src/test/java/org/jclouds/compute/RunScriptData.java index f09d10b758..1907c8de55 100644 --- a/compute/src/test/java/org/jclouds/compute/RunScriptData.java +++ b/compute/src/test/java/org/jclouds/compute/RunScriptData.java @@ -33,6 +33,7 @@ import org.jclouds.compute.predicates.OperatingSystemPredicates; import org.jclouds.scriptbuilder.InitBuilder; import org.jclouds.scriptbuilder.domain.AuthorizeRSAPublicKey; import org.jclouds.scriptbuilder.domain.Statement; +import org.jclouds.scriptbuilder.domain.Statements; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -56,32 +57,34 @@ public class RunScriptData { throw new IllegalArgumentException("don't know how to handle" + os.toString()); } + public static Statement authorizePortInIpTables(int port) { + return Statements.newStatementList(// just in case iptables are being used, try to open 8080 + exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"),// + // TODO gogrid rules only allow ports 22, 3389, 80 and 443. + // the above rule will be ignored, so we have to apply this + // directly + exec("iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport " + port + " -j ACCEPT"),// + exec("iptables-save")); + } + public static Statement createScriptInstallAndStartJBoss(String publicKey, OperatingSystem os) { Map envVariables = ImmutableMap.of("jbossHome", jbossHome); Statement toReturn = new InitBuilder( - "jboss", - jbossHome, - jbossHome, - envVariables, - ImmutableList - . of( - new AuthorizeRSAPublicKey(publicKey),// - installJavaAndCurl(os),// - // just in case iptables are being used, try to open 8080 - exec("iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT"),// - // TODO gogrid rules only allow ports 22, 3389, 80 and 443. - // the above rule will be ignored, so we have to apply this - // directly - exec("iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 8080 -j ACCEPT"),// - exec("iptables-save"),// - extractTargzIntoDirectory( - URI - .create("http://commondatastorage.googleapis.com/jclouds-repo/jboss-as-distribution-6.0.0.20100911-M5.tar.gz"), - "/usr/local"), exec("{md} " + jbossHome), exec("mv /usr/local/jboss-*/* " - + jbossHome),// - exec("chmod -R oug+r+w " + jbossHome)),// - ImmutableList - . of(interpret("java -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=lib/endorsed -classpath bin/run.jar org.jboss.Main -b 0.0.0.0"))); + "jboss", + jbossHome, + jbossHome, + envVariables, + ImmutableList. of( + new AuthorizeRSAPublicKey(publicKey),// + installJavaAndCurl(os),// + authorizePortInIpTables(8080),// + extractTargzIntoDirectory( + URI.create("http://commondatastorage.googleapis.com/jclouds-repo/jboss-as-distribution-6.0.0.20100911-M5.tar.gz"), + "/usr/local"),// + exec("{md} " + jbossHome), exec("mv /usr/local/jboss-*/* " + jbossHome),// + exec("chmod -R oug+r+w " + jbossHome)),// + ImmutableList + . of(interpret("java -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=lib/endorsed -classpath bin/run.jar org.jboss.Main -b 0.0.0.0"))); return toReturn; } @@ -93,28 +96,28 @@ public class RunScriptData { } public static final Statement APT_RUN_SCRIPT = newStatementList(// - exec(installAfterUpdatingIfNotPresent("curl")),// - exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) ||"),// - execHttpResponse(URI.create("http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install")),// - exec(new StringBuilder()// - .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// - // jeos hasn't enough room! - .append("rm -rf /var/cache/apt /usr/lib/vmware-tools\n")// - .append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")// - .toString())); + exec(installAfterUpdatingIfNotPresent("curl")),// + exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) ||"),// + execHttpResponse(URI.create("http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install")),// + exec(new StringBuilder()// + .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// + // jeos hasn't enough room! + .append("rm -rf /var/cache/apt /usr/lib/vmware-tools\n")// + .append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")// + .toString())); public static final Statement YUM_RUN_SCRIPT = newStatementList( - exec("which curl ||yum --nogpgcheck -y install curl"),// - exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) ||"),// - execHttpResponse(URI.create("http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install")),// - exec(new StringBuilder()// - .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n") // - .append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")// - .toString())); + exec("which curl ||yum --nogpgcheck -y install curl"),// + exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) ||"),// + execHttpResponse(URI.create("http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install")),// + exec(new StringBuilder()// + .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n") // + .append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")// + .toString())); public static final Statement ZYPPER_RUN_SCRIPT = exec(new StringBuilder()// - .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// - .append("which curl || zypper install curl\n")// - .append("(which java && java -fullversion 2>&1|egrep -q 1.6 ) || zypper install java-1.6.0-openjdk\n")// - .toString()); + .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// + .append("which curl || zypper install curl\n")// + .append("(which java && java -fullversion 2>&1|egrep -q 1.6 ) || zypper install java-1.6.0-openjdk\n")// + .toString()); } From 01eba379d83d6d513969139b9dbfcd1770c5f8cb Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 17 Dec 2010 19:17:22 +0100 Subject: [PATCH 04/33] Issue 427: started on deltacloud --- .../src/main/java/org/jclouds/util/Utils.java | 11 ++ core/src/main/resources/rest.properties | 3 + sandbox/deltacloud/pom.xml | 133 ++++++++++++++++++ .../deltacloud/DeltacloudAsyncClient.java | 69 +++++++++ .../jclouds/deltacloud/DeltacloudClient.java | 66 +++++++++ .../deltacloud/DeltacloudContextBuilder.java | 45 ++++++ .../DeltacloudPropertiesBuilder.java | 45 ++++++ .../config/DeltacloudRestClientModule.java | 59 ++++++++ .../handlers/DeltacloudErrorHandler.java | 98 +++++++++++++ .../options/CreateInstanceOptions.java | 50 +++++++ .../reference/DeltacloudCollection.java | 30 ++++ .../jclouds/deltacloud/xml/LinksHandler.java | 55 ++++++++ .../deltacloud/DeltacloudAsyncClientTest.java | 132 +++++++++++++++++ .../deltacloud/DeltacloudClientLiveTest.java | 113 +++++++++++++++ .../handlers/DeltacloudErrorHandlerTest.java | 123 ++++++++++++++++ .../deltacloud/handlers/LinksHandlerTest.java | 58 ++++++++ .../options/CreateInstanceOptionsTest.java | 48 +++++++ .../deltacloud/src/test/resources/links.xml | 7 + 18 files changed, 1145 insertions(+) create mode 100644 sandbox/deltacloud/pom.xml create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudContextBuilder.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/handlers/DeltacloudErrorHandler.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/options/CreateInstanceOptions.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/reference/DeltacloudCollection.java create mode 100755 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java create mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java create mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java create mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/DeltacloudErrorHandlerTest.java create mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/LinksHandlerTest.java create mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/options/CreateInstanceOptionsTest.java create mode 100644 sandbox/deltacloud/src/test/resources/links.xml diff --git a/core/src/main/java/org/jclouds/util/Utils.java b/core/src/main/java/org/jclouds/util/Utils.java index c0a745367a..a01198d1c7 100644 --- a/core/src/main/java/org/jclouds/util/Utils.java +++ b/core/src/main/java/org/jclouds/util/Utils.java @@ -66,6 +66,7 @@ import org.jclouds.domain.Credentials; import org.jclouds.logging.Logger; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.RestContextBuilder; +import org.xml.sax.Attributes; import com.google.common.base.Charsets; import com.google.common.base.Function; @@ -88,6 +89,16 @@ import com.google.inject.spi.Message; * @author Adrian Cole */ public class Utils { + public static Map cleanseAttributes(Attributes in) { + Map attrs = Maps.newLinkedHashMap(); + for (int i = 0; i < in.getLength(); i++) { + String name = in.getQName(i); + if (name.indexOf(':') != -1) + name = name.substring(name.indexOf(':') + 1); + attrs.put(name, in.getValue(i)); + } + return attrs; + } /** * If the supplied map contains the key {@code k1}, its value will be assigned to the key diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index 465c817ad4..65bec42734 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -92,6 +92,9 @@ bluelock-vcdirector.propertiesbuilder=org.jclouds.vcloud.bluelock.BlueLockVCloud gogrid.propertiesbuilder=org.jclouds.gogrid.GoGridPropertiesBuilder gogrid.contextbuilder=org.jclouds.gogrid.GoGridContextBuilder +deltacloud.propertiesbuilder=org.jclouds.deltacloud.DeltacloudPropertiesBuilder +deltacloud.contextbuilder=org.jclouds.deltacloud.DeltacloudContextBuilder + elasticstack.propertiesbuilder=org.jclouds.elasticstack.ElasticStackPropertiesBuilder elasticstack.contextbuilder=org.jclouds.elasticstack.ElasticStackContextBuilder diff --git a/sandbox/deltacloud/pom.xml b/sandbox/deltacloud/pom.xml new file mode 100644 index 0000000000..9d81257d0b --- /dev/null +++ b/sandbox/deltacloud/pom.xml @@ -0,0 +1,133 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds + jclouds-deltacloud + jclouds deltacloud core + jclouds components to access deltacloud + + + + + jclouds-googlecode-deploy + http://jclouds.googlecode.com/svn/repo + + + jclouds-rimu-snapshots-nexus + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + + + trmkrun-ccc,test.trmk-924 + http://localhost:3001/api + 1.0 + FIXME + FIXME + + + + ${project.groupId} + jclouds-core + ${project.version} + + + ${project.groupId} + jclouds-core + ${project.version} + test-jar + test + + + log4j + log4j + 1.2.14 + test + + + ${project.groupId} + jclouds-log4j + ${project.version} + test + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + + test.deltacloud.endpoint + ${test.deltacloud.endpoint} + + + test.deltacloud.apiversion + ${test.deltacloud.apiversion} + + + test.deltacloud.identity + ${test.deltacloud.identity} + + + test.deltacloud.credential + ${test.deltacloud.credential} + + + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} + + + + + + + + + + + diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java new file mode 100644 index 0000000000..76e386b796 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud; + +import java.net.URI; +import java.util.Map; + +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; + +import org.jclouds.deltacloud.options.CreateInstanceOptions; +import org.jclouds.deltacloud.reference.DeltacloudCollection; +import org.jclouds.deltacloud.xml.LinksHandler; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.XMLResponseParser; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to deltacloud via their REST API. + *

+ * + * @see DeltacloudClient + * @see + * @author Adrian Cole + */ +@RequestFilters(BasicAuthentication.class) +@Consumes(MediaType.APPLICATION_XML) +public interface DeltacloudAsyncClient { + + /** + * @see DeltacloudClient#getCollections + */ + @GET + @Path("") + @XMLResponseParser(LinksHandler.class) + ListenableFuture> getCollections(); + + /** + * @see DeltacloudClient#createInstance + */ + @POST + @Path("") + ListenableFuture createInstance(URI instanceCollection, @FormParam("image_id") String imageId, + CreateInstanceOptions... options); + +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java new file mode 100644 index 0000000000..0427eea923 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud; + +import java.net.URI; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.deltacloud.options.CreateInstanceOptions; +import org.jclouds.deltacloud.reference.DeltacloudCollection; + +/** + * Provides synchronous access to deltacloud. + *

+ * + * @see DeltacloudAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface DeltacloudClient { + /** + * The result of this entry-point is a set of entry-points into other collections, such as + * images, instances, hardware profiles and realms, among others. + * + * @return named links to available collections, or empty map, if no resources are found + */ + Map getCollections(); + + /** + * Create a new Instance + * + *

Note

+ * + * If options realmId or hardwareProfileName are not specified, the provider must select + * reasonable defaults. The architecture of the selected hardware profile must match the + * architecture of the specified image. + * + * @param instanceCollection + * which endpoint to create the instance in + * @param imageId + * The identifier (not URL) of the image from which to base the instance + * @param options + * includes realm, hardware profile, etc. + * @return newly-created instance including a URL to retrieve the instance in the future. + */ + String createInstance(URI instanceCollection, String imageId, CreateInstanceOptions... options); +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudContextBuilder.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudContextBuilder.java new file mode 100644 index 0000000000..7704c625e1 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudContextBuilder.java @@ -0,0 +1,45 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.deltacloud.config.DeltacloudRestClientModule; +import org.jclouds.rest.RestContextBuilder; + +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +public class DeltacloudContextBuilder extends + RestContextBuilder { + + public DeltacloudContextBuilder(Properties props) { + super(DeltacloudClient.class, DeltacloudAsyncClient.class, props); + } + + protected void addClientModule(List modules) { + modules.add(new DeltacloudRestClientModule()); + } + +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java new file mode 100644 index 0000000000..5e10e40f57 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java @@ -0,0 +1,45 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud; + +import static org.jclouds.Constants.PROPERTY_API_VERSION; + +import java.util.Properties; + +import org.jclouds.PropertiesBuilder; + +/** + * Builds properties used in deltacloud Clients + * + * @author Adrian Cole + */ +public class DeltacloudPropertiesBuilder extends PropertiesBuilder { + @Override + protected Properties defaultProperties() { + Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_API_VERSION, "1.0"); + return properties; + } + + public DeltacloudPropertiesBuilder(Properties properties) { + super(properties); + } + +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java new file mode 100644 index 0000000000..b8c3b8b55d --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.config; + +import org.jclouds.deltacloud.DeltacloudAsyncClient; +import org.jclouds.deltacloud.DeltacloudClient; +import org.jclouds.deltacloud.handlers.DeltacloudErrorHandler; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.RequiresHttp; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.config.RestClientModule; + +/** + * Configures the deltacloud connection. + * + * @author Adrian Cole + */ +@RequiresHttp +@ConfiguresRestClient +public class DeltacloudRestClientModule extends RestClientModule { + + public DeltacloudRestClientModule() { + super(DeltacloudClient.class, DeltacloudAsyncClient.class); + } + + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(DeltacloudErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(DeltacloudErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(DeltacloudErrorHandler.class); + } + + @Override + protected void bindRetryHandlers() { + // TODO + } + +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/handlers/DeltacloudErrorHandler.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/handlers/DeltacloudErrorHandler.java new file mode 100644 index 0000000000..4db7e6d89e --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/handlers/DeltacloudErrorHandler.java @@ -0,0 +1,98 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.handlers; + +import java.io.IOException; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.logging.Logger; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.util.Utils; + +import com.google.common.base.Throwables; +import com.google.common.io.Closeables; + +/** + * + * @author Adrian Cole + * + */ +@Singleton +public class DeltacloudErrorHandler implements HttpErrorHandler { + @Resource + protected Logger logger = Logger.NULL; + + public void handleError(HttpCommand command, HttpResponse response) { + // it is important to always read fully and close streams + String message = parseMessage(response); + Exception exception = message != null ? new HttpResponseException(command, response, message) + : new HttpResponseException(command, response); + try { + message = message != null ? message : String.format("%s -> %s", command.getRequest().getRequestLine(), + response.getStatusLine()); + switch (response.getStatusCode()) { + case 400: + exception = new IllegalArgumentException(message, exception); + break; + case 401: + exception = new AuthorizationException(message, exception); + break; + case 404: + if (!command.getRequest().getMethod().equals("DELETE")) { + exception = new ResourceNotFoundException(message, exception); + } + break; + case 405: + exception = new IllegalArgumentException(message, exception); + break; + case 409: + exception = new IllegalStateException(message, exception); + break; + } + } finally { + if (response.getPayload() != null) + Closeables.closeQuietly(response.getPayload().getInput()); + command.setException(exception); + } + } + + public String parseMessage(HttpResponse response) { + if (response.getPayload() == null) + return null; + try { + return Utils.toStringAndClose(response.getPayload().getInput()); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + response.getPayload().getInput().close(); + } catch (IOException e) { + Throwables.propagate(e); + } + } + } +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/options/CreateInstanceOptions.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/options/CreateInstanceOptions.java new file mode 100644 index 0000000000..25a1a92eb8 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/options/CreateInstanceOptions.java @@ -0,0 +1,50 @@ +package org.jclouds.deltacloud.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Contains options supported in the Deltacloud API for the Create Instance operation.

+ * Usage

The recommended way to instantiate a CreateInstanceOptions object is to statically + * import CreateInstanceOptions.Builder.* and invoke a static creation method followed by an + * instance mutator (if needed): + *

+ * + * import static org.jclouds.deltacloud.options.CreateInstanceOptions.Builder.* + *

+ * DeltacloudClient connection = // get connection + * ListenableFuture instance = client.createInstance(collection, "imageId", named("robot")); + * + * + * @author Adrian Cole + * @see + */ +public class CreateInstanceOptions extends BaseHttpRequestOptions { + public static final CreateInstanceOptions NONE = new CreateInstanceOptions(); + + /** + * A short label to identify the instance. + * + */ + public CreateInstanceOptions named(String name) { + formParameters.put("name", checkNotNull(name, "name")); + return this; + } + + public String getName() { + return this.getFirstFormOrNull("name"); + } + + public static class Builder { + + /** + * @see CreateInstanceOptions#named + */ + public static CreateInstanceOptions named(String name) { + CreateInstanceOptions options = new CreateInstanceOptions(); + return options.named(name); + } + + } +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/reference/DeltacloudCollection.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/reference/DeltacloudCollection.java new file mode 100644 index 0000000000..d0419bbddb --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/reference/DeltacloudCollection.java @@ -0,0 +1,30 @@ +package org.jclouds.deltacloud.reference; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.CaseFormat; + +/** + * + * @author Adrian Cole + */ +public enum DeltacloudCollection { + HARDWARE_PROFILES, INSTANCE_STATES, REALMS, IMAGES, INSTANCES, UNRECOGNIZED; + + public String value() { + return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_UNDERSCORE, name())); + } + + @Override + public String toString() { + return value(); + } + + public static DeltacloudCollection fromValue(String link) { + try { + return valueOf(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(link, "link"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } +} \ No newline at end of file diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java new file mode 100755 index 0000000000..f91eab99be --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.links/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.xml; + +import java.net.URI; +import java.util.Map; + +import org.jclouds.deltacloud.reference.DeltacloudCollection; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.util.Utils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Maps; + +/** + * @author Adrian Cole + */ +public class LinksHandler extends ParseSax.HandlerWithResult> { + + private Map links = Maps.newLinkedHashMap(); + + public Map getResult() { + return links; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = Utils.cleanseAttributes(attrs); + if (qName.equals("link")) { + String rel = attributes.get("rel"); + if (rel != null) { + DeltacloudCollection link = DeltacloudCollection.fromValue(rel); + links.put(link, URI.create(attributes.get("href"))); + } + } + } +} diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java new file mode 100644 index 0000000000..6248900ff3 --- /dev/null +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java @@ -0,0 +1,132 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.deltacloud.options.CreateInstanceOptions; +import org.jclouds.deltacloud.xml.LinksHandler; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ReturnStringIf2xx; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code DeltacloudAsyncClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "deltacloud.DeltacloudAsyncClientTest") +public class DeltacloudAsyncClientTest extends RestClientTest { + public void testGetCollections() throws SecurityException, NoSuchMethodException, IOException { + Method method = DeltacloudAsyncClient.class.getMethod("getCollections"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET http://localhost:3001/api HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n"); + assertPayloadEquals(httpRequest, null, null, false); + + // now make sure request filters apply by replaying + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + + assertRequestLineEquals(httpRequest, "GET http://localhost:3001/api HTTP/1.1"); + // for example, using basic authentication, we should get "only one" + // header + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\nAuthorization: Basic Zm9vOmJhcg==\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseSax.class); + assertSaxResponseParserClassEquals(method, LinksHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + + } + + public void testCreateInstance() throws SecurityException, NoSuchMethodException, IOException { + Method method = DeltacloudAsyncClient.class.getMethod("createInstance", URI.class, String.class, + CreateInstanceOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + URI.create("http://localhost:3001/api/instances"), "imageId-1"); + + assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n"); + assertPayloadEquals(httpRequest, "image_id=imageId-1", "application/x-www-form-urlencoded", false); + + assertResponseParserClassEquals(method, httpRequest, ReturnStringIf2xx.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + + } + + public void testCreateInstanceWithOptions() throws SecurityException, NoSuchMethodException, IOException { + Method method = DeltacloudAsyncClient.class.getMethod("createInstance", URI.class, String.class, + CreateInstanceOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + URI.create("http://localhost:3001/api/instances"), "imageId-1", CreateInstanceOptions.Builder.named("foo")); + + assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n"); + assertPayloadEquals(httpRequest, "image_id=imageId-1&name=foo", "application/x-www-form-urlencoded", false); + + assertResponseParserClassEquals(method, httpRequest, ReturnStringIf2xx.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + + } + + @Override + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + public RestContextSpec createContextSpec() { + Properties props = new Properties(); + props.setProperty("deltacloud.endpoint", "http://localhost:3001/api"); + return new RestContextFactory().createContextSpec("deltacloud", "foo", "bar", props); + } +} diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java new file mode 100644 index 0000000000..038e91e5a1 --- /dev/null +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java @@ -0,0 +1,113 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.Map; +import java.util.Properties; + +import org.jclouds.Constants; +import org.jclouds.deltacloud.reference.DeltacloudCollection; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextFactory; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Tests behavior of {@code DeltacloudClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true) +public class DeltacloudClientLiveTest { + + protected DeltacloudClient client; + protected RestContext context; + + protected String provider = "deltacloud"; + protected String identity; + protected String credential; + protected String endpoint; + protected String apiversion; + + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); + } + + protected Properties setupProperties() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + overrides.setProperty(provider + ".identity", identity); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); + return overrides; + } + + @BeforeGroups(groups = "live") + public void setupClient() { + setupCredentials(); + Properties overrides = setupProperties(); + context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), + overrides); + + client = context.getApi(); + } + + @AfterGroups(groups = "live") + void tearDown() { + if (context != null) + context.close(); + } + + @Test + public void testGetLinksContainsAll() throws Exception { + Map links = client.getCollections(); + assertNotNull(links); + for (DeltacloudCollection link : DeltacloudCollection.values()) + assert (links.get(link) != null) : link; + } + + @Test + public void testCreateInstance() throws Exception { + // TODO + } + + @Test + public void testCreateInstanceWithOptions() throws Exception { + // TODO + } + +} diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/DeltacloudErrorHandlerTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/DeltacloudErrorHandlerTest.java new file mode 100644 index 0000000000..d1f8c2c021 --- /dev/null +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/DeltacloudErrorHandlerTest.java @@ -0,0 +1,123 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.handlers; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.reportMatcher; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +import java.net.URI; + +import org.easymock.IArgumentMatcher; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +import com.google.inject.Guice; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class DeltacloudErrorHandlerTest { + + @Test + public void test400MakesIllegalArgumentException() { + assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 400, "", "Bad Request", + IllegalArgumentException.class); + } + + @Test + public void test401MakesAuthorizationException() { + assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 401, "", "Unauthorized", + AuthorizationException.class); + } + + @Test + public void test404MakesResourceNotFoundException() { + assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 404, "", "Not Found", + ResourceNotFoundException.class); + } + + @Test + public void test405MakesIllegalArgumentException() { + assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 405, "", "Method Not Allowed", + IllegalArgumentException.class); + } + + @Test + public void test409MakesIllegalStateException() { + assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 409, "", "Conflict", IllegalStateException.class); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, + Class expected) { + assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, + String content, Class expected) { + + DeltacloudErrorHandler function = Guice.createInjector().getInstance(DeltacloudErrorHandler.class); + + HttpCommand command = createMock(HttpCommand.class); + HttpRequest request = new HttpRequest(method, uri); + HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Utils + .toInputStream(content))); + response.getPayload().getContentMetadata().setContentType(contentType); + + expect(command.getRequest()).andReturn(request).atLeastOnce(); + command.setException(classEq(expected)); + + replay(command); + + function.handleError(command, response); + + verify(command); + } + + public static Exception classEq(final Class in) { + reportMatcher(new IArgumentMatcher() { + + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("classEq("); + buffer.append(in); + buffer.append(")"); + } + + @Override + public boolean matches(Object arg) { + return arg.getClass() == in; + } + + }); + return null; + } + +} diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/LinksHandlerTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/LinksHandlerTest.java new file mode 100644 index 0000000000..877b6c2056 --- /dev/null +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/LinksHandlerTest.java @@ -0,0 +1,58 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.handlers; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.util.Map; + +import org.jclouds.deltacloud.reference.DeltacloudCollection; +import org.jclouds.deltacloud.xml.LinksHandler; +import org.jclouds.http.functions.BaseHandlerTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +/** + * Tests behavior of {@code LinksHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class LinksHandlerTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/links.xml"); + + Map result = factory.create(injector.getInstance(LinksHandler.class)).parse(is); + assertEquals(result, ImmutableMap.of(// + DeltacloudCollection.HARDWARE_PROFILES, URI.create("http://fancycloudprovider.com/api/hardware_profiles"),// + DeltacloudCollection.INSTANCE_STATES, URI.create("http://fancycloudprovider.com/api/instance_states"),// + DeltacloudCollection.REALMS, URI.create("http://fancycloudprovider.com/api/realms"),// + DeltacloudCollection.IMAGES, URI.create("http://fancycloudprovider.com/api/images"),// + DeltacloudCollection.INSTANCES, URI.create("http://fancycloudprovider.com/api/instances") + + )); + + } + +} diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/options/CreateInstanceOptionsTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/options/CreateInstanceOptionsTest.java new file mode 100644 index 0000000000..296d2de6d6 --- /dev/null +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/options/CreateInstanceOptionsTest.java @@ -0,0 +1,48 @@ +package org.jclouds.deltacloud.options; + +import static org.jclouds.deltacloud.options.CreateInstanceOptions.Builder.named; +import static org.testng.Assert.assertEquals; + +import java.util.Collections; + +import org.jclouds.http.options.HttpRequestOptions; +import org.testng.annotations.Test; + +/** + * Tests possible uses of CreateInstanceOptions and CreateInstanceOptions.Builder.* + * + * @author Adrian Cole + */ +public class CreateInstanceOptionsTest { + + @Test + public void testAssignability() { + assert HttpRequestOptions.class.isAssignableFrom(CreateInstanceOptions.class); + assert !String.class.isAssignableFrom(CreateInstanceOptions.class); + } + + @Test + public void testWithNamed() { + CreateInstanceOptions options = new CreateInstanceOptions(); + options.named("test"); + assertEquals(options.buildFormParameters().get("name"), Collections.singletonList("test")); + } + + @Test + public void testNullWithNamed() { + CreateInstanceOptions options = new CreateInstanceOptions(); + assertEquals(options.buildFormParameters().get("name"), Collections.EMPTY_LIST); + } + + @Test + public void testWithNamedStatic() { + CreateInstanceOptions options = named("test"); + assertEquals(options.buildFormParameters().get("name"), Collections.singletonList("test")); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testWithNamedNPE() { + named(null); + } + +} diff --git a/sandbox/deltacloud/src/test/resources/links.xml b/sandbox/deltacloud/src/test/resources/links.xml new file mode 100644 index 0000000000..251d904b05 --- /dev/null +++ b/sandbox/deltacloud/src/test/resources/links.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file From cfad0e25bb176e4bb2608afa05988099bf1a4466 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 17 Dec 2010 23:04:13 +0100 Subject: [PATCH 05/33] Issue 27: disabled additionalInfo when using eucalyptus --- ...rityGroupsAsNeededAndReturnRunOptions.java | 19 ++++- ...GroupsAsNeededAndReturnRunOptionsTest.java | 80 +++++++++++++++++-- 2 files changed, 90 insertions(+), 9 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java index 64c8eb219a..97be5ce8e0 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java @@ -39,6 +39,7 @@ import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.options.RunInstancesOptions; import org.jclouds.compute.domain.Template; import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.rest.annotations.Provider; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Sets; @@ -49,6 +50,8 @@ import com.google.common.collect.Sets; */ @Singleton public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions { + @VisibleForTesting + final String provider; @VisibleForTesting final Map credentialsMap; @VisibleForTesting @@ -63,11 +66,12 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions final CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded; @Inject - CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions(Map credentialsMap, - @Named("SECURITY") Map securityGroupMap, + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions(@Provider String provider, + Map credentialsMap, @Named("SECURITY") Map securityGroupMap, @Named("PLACEMENT") Map placementGroupMap, CreateUniqueKeyPair createUniqueKeyPair, CreateSecurityGroupIfNeeded createSecurityGroupIfNeeded, CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded) { + this.provider = provider; this.credentialsMap = credentialsMap; this.securityGroupMap = securityGroupMap; this.placementGroupMap = placementGroupMap; @@ -76,9 +80,18 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions this.createPlacementGroupIfNeeded = createPlacementGroupIfNeeded; } + // this method only exists so that we can mock + String getProvider() { + return provider; + } + public RunInstancesOptions execute(String region, String tag, Template template) { - RunInstancesOptions instanceOptions = asType(template.getHardware().getId()).withAdditionalInfo(tag); + RunInstancesOptions instanceOptions = asType(template.getHardware().getId()); + + // Eucalyptus currently doesn't support additional info + if (!"eucalyptus".equals(getProvider())) + instanceOptions.withAdditionalInfo(tag); String keyPairName = createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, template.getOptions()); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index c65f73be49..4affe571f8 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -56,7 +56,7 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit", testName = "ec2.CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest") public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest { - public void testExecuteWithDefaultOptions() throws SecurityException, NoSuchMethodException { + public void testExecuteWithDefaultOptionsEC2() throws SecurityException, NoSuchMethodException { // setup constants String region = Region.AP_SOUTHEAST_1; String tag = "tag"; @@ -69,6 +69,8 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions strategy = createMock( CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class, new Method[] { + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class + .getDeclaredMethod("getProvider"), CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class.getDeclaredMethod( "createNewKeyPairUnlessUserSpecifiedOtherwise", String.class, String.class, TemplateOptions.class), @@ -87,6 +89,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( systemGeneratedKeyPairName); expect(strategy.getSecurityGroupsForTagAndOptions(region, tag, options)).andReturn(generatedGroups); + expect(strategy.getProvider()).andReturn("ec2"); expect(options.getSubnetId()).andReturn(null); expect(options.getUserData()).andReturn(null); @@ -112,6 +115,65 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT verify(strategy); } + public void testEucalyptusDoesNotUseAdditionalInfo() throws SecurityException, NoSuchMethodException { + // setup constants + String region = Region.AP_SOUTHEAST_1; + String tag = "tag"; + Hardware size = EC2HardwareBuilder.m1_small().build(); + String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; + String generatedGroup = "group"; + Set generatedGroups = ImmutableSet.of(generatedGroup); + + // create mocks + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions strategy = createMock( + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class, + new Method[] { + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class + .getDeclaredMethod("getProvider"), + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class.getDeclaredMethod( + "createNewKeyPairUnlessUserSpecifiedOtherwise", String.class, String.class, + TemplateOptions.class), + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class.getDeclaredMethod( + "createNewPlacementGroupUnlessUserSpecifiedOtherwise", String.class, String.class, + TemplateOptions.class), + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class.getDeclaredMethod( + "getSecurityGroupsForTagAndOptions", String.class, String.class, TemplateOptions.class) }); + + EC2TemplateOptions options = createMock(EC2TemplateOptions.class); + Template template = createMock(Template.class); + + // setup expectations + expect(template.getHardware()).andReturn(size).atLeastOnce(); + expect(template.getOptions()).andReturn(options).atLeastOnce(); + expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( + systemGeneratedKeyPairName); + expect(strategy.getSecurityGroupsForTagAndOptions(region, tag, options)).andReturn(generatedGroups); + expect(strategy.getProvider()).andReturn("eucalyptus"); + expect(options.getSubnetId()).andReturn(null); + expect(options.getUserData()).andReturn(null); + + // replay mocks + replay(options); + replay(template); + replay(strategy); + + // run + RunInstancesOptions runOptions = strategy.execute(region, tag, template); + assertEquals(runOptions.buildQueryParameters(), ImmutableMultimap. of()); + assertEquals( + runOptions.buildFormParameters().entries(), + ImmutableMultimap. of("InstanceType", size.getProviderId(), "SecurityGroup.1", + generatedGroup, "KeyName", systemGeneratedKeyPairName).entries()); + assertEquals(runOptions.buildMatrixParameters(), ImmutableMultimap. of()); + assertEquals(runOptions.buildRequestHeaders(), ImmutableMultimap. of()); + assertEquals(runOptions.buildStringPayload(), null); + + // verify mocks + verify(options); + verify(template); + verify(strategy); + } + public void testExecuteForCCAutomatic() throws SecurityException, NoSuchMethodException { // setup constants String region = Region.US_EAST_1; @@ -291,7 +353,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String generatedGroup = "group"; Set generatedGroups = ImmutableSet.of(generatedGroup); - + // create mocks CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions strategy = createMock( CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class, @@ -328,7 +390,8 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT assertEquals( runOptions.buildFormParameters().entries(), ImmutableMultimap. of("InstanceType", size.getProviderId(), "AdditionalInfo", tag, - "SecurityGroup.1", "group", "KeyName", systemGeneratedKeyPairName, "UserData", Base64.encodeBytes("hello".getBytes())).entries()); + "SecurityGroup.1", "group", "KeyName", systemGeneratedKeyPairName, "UserData", + Base64.encodeBytes("hello".getBytes())).entries()); assertEquals(runOptions.buildMatrixParameters(), ImmutableMultimap. of()); assertEquals(runOptions.buildRequestHeaders(), ImmutableMultimap. of()); assertEquals(runOptions.buildStringPayload(), null); @@ -681,8 +744,12 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT verify(strategy.createPlacementGroupIfNeeded); } - @SuppressWarnings("unchecked") private CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions setupStrategy() { + return setupStrategy("ec2"); + } + + @SuppressWarnings("unchecked") + private CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions setupStrategy(String provider) { Map credentialsMap = createMock(Map.class); Map securityGroupMap = createMock(Map.class); Map placementGroupMap = createMock(Map.class); @@ -690,8 +757,9 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT CreateSecurityGroupIfNeeded createSecurityGroupIfNeeded = createMock(CreateSecurityGroupIfNeeded.class); CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded = createMock(CreatePlacementGroupIfNeeded.class); - return new CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions(credentialsMap, securityGroupMap, - placementGroupMap, createUniqueKeyPair, createSecurityGroupIfNeeded, createPlacementGroupIfNeeded); + return new CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions(provider, credentialsMap, + securityGroupMap, placementGroupMap, createUniqueKeyPair, createSecurityGroupIfNeeded, + createPlacementGroupIfNeeded); } private void replayStrategy(CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions strategy) { From b870740e0dfd41a9aecbb9512caf930fd4bdb093 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 17 Dec 2010 23:39:07 +0100 Subject: [PATCH 06/33] Issue 27: skipped multiple-security group for euc --- .../compute/EucalyptusComputeServiceLiveTestDisabled.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java index c85cfe7bb0..991f7e15e6 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java @@ -52,6 +52,12 @@ public class EucalyptusComputeServiceLiveTestDisabled extends EC2ComputeServiceL // euc does not support monitoring } + @Override + @Test(enabled = false) + public void testExtendedOptionsNoKeyPair() throws Exception { + // euc does not support multiple security groups + } + @Override protected void assertDefaultWorks() { Template defaultTemplate = client.templateBuilder().build(); From 5d28eb096d35b9296dd62953897c521e3284426d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 18 Dec 2010 11:06:14 +0100 Subject: [PATCH 07/33] Issue 406: lowered log level of invisible ec2 images --- .../ec2/compute/functions/RegionAndIdToImage.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RegionAndIdToImage.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RegionAndIdToImage.java index 310b30f9ca..03333a0544 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RegionAndIdToImage.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RegionAndIdToImage.java @@ -21,6 +21,8 @@ package org.jclouds.aws.ec2.compute.functions; import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.imageIds; +import java.util.NoSuchElementException; + import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Singleton; @@ -29,6 +31,7 @@ import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.compute.domain.Image; import org.jclouds.logging.Logger; +import org.jclouds.rest.ResourceNotFoundException; import com.google.common.base.Function; import com.google.common.collect.Iterables; @@ -56,9 +59,19 @@ public final class RegionAndIdToImage implements Function org.jclouds.aws.ec2.domain.Image image = Iterables.getOnlyElement(sync.getAMIServices() .describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); return parser.apply(image); + } catch (NoSuchElementException e) { + logger.debug(message(key, e)); + return null; + } catch (ResourceNotFoundException e) { + logger.debug(message(key, e)); + return null; } catch (Exception e) { - logger.warn(e, "could not find image %s/%s: %s", key.getRegion(), key.getName(), e.getMessage()); + logger.warn(e, message(key, e)); return null; } } + + public static String message(RegionAndName key, Exception e) { + return String.format("could not find image %s/%s: %s", key.getRegion(), key.getName(), e.getMessage()); + } } \ No newline at end of file From fa736f3467aa28ff09c02bad1ddfdf5065211851 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 18 Dec 2010 12:17:03 +0100 Subject: [PATCH 08/33] Issue 429: work around localhost issue in openstack swift --- ...AuthenticationResponseFromHeadersTest.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseAuthenticationResponseFromHeadersTest.java diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseAuthenticationResponseFromHeadersTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseAuthenticationResponseFromHeadersTest.java new file mode 100644 index 0000000000..15c3fc5af1 --- /dev/null +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseAuthenticationResponseFromHeadersTest.java @@ -0,0 +1,77 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.rackspace.cloudfiles.functions; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import javax.ws.rs.core.UriBuilder; + +import org.jclouds.Constants; +import org.jclouds.blobstore.reference.BlobStoreConstants; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rackspace.RackspaceAuthAsyncClient.AuthenticationResponse; +import org.jclouds.rackspace.functions.ParseAuthenticationResponseFromHeaders; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.name.Names; +import com.sun.jersey.api.uri.UriBuilderImpl; + +/** + * Tests behavior of {@code ParseContainerListFromJsonResponse} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "cloudfiles.ParseAuthenticationResponseFromHeadersTest") +public class ParseAuthenticationResponseFromHeadersTest { + + Injector i = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf"); + bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1"); + bind(UriBuilder.class).to(UriBuilderImpl.class); + } + + }); + + public void testReplaceLocalhost() { + ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class); + HttpRequest request = new HttpRequest("GET", URI.create("http://realhost:11000/v1.0")); + parser.setContext(request); + + HttpResponse response = new HttpResponse(204, "No Content", null); + response.getHeaders().put("X-Auth-Token", "token"); + response.getHeaders().put("X-Storage-Token", "token"); + response.getHeaders().put("X-Storage-Url", "http://127.0.0.1:8080/v1/token"); + + AuthenticationResponse md = parser.apply(response); + assertEquals( + md, + new ParseAuthenticationResponseFromHeaders.AuthenticationResponseImpl("token", null, null, URI + .create("http://realhost:8080/v1/token"))); + } +} From a4501eb9cac30026ac4af342ceaa834839f10443 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 18 Dec 2010 12:36:32 +0100 Subject: [PATCH 09/33] Issue 429: adjusted regex to accept both mosso and swift syntax --- .../ParseCloudFilesErrorFromHttpResponse.java | 6 +- ...arseAuthenticationResponseFromHeaders.java | 132 +++++++++--------- ...ckspaceAuthenticationRestClientModule.java | 5 +- 3 files changed, 71 insertions(+), 72 deletions(-) diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/handlers/ParseCloudFilesErrorFromHttpResponse.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/handlers/ParseCloudFilesErrorFromHttpResponse.java index 15d1f18d4a..d79b86be03 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/handlers/ParseCloudFilesErrorFromHttpResponse.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/handlers/ParseCloudFilesErrorFromHttpResponse.java @@ -46,9 +46,9 @@ import org.jclouds.util.Utils; public class ParseCloudFilesErrorFromHttpResponse implements HttpErrorHandler { @Resource protected Logger logger = Logger.NULL; - public static final String MOSSO_PREFIX = "^/v1[^/]*/MossoCloudFS_[^/]+/"; - public static final Pattern CONTAINER_PATH = Pattern.compile(MOSSO_PREFIX + "([^/]+)$"); - public static final Pattern CONTAINER_KEY_PATH = Pattern.compile(MOSSO_PREFIX + "([^/]+)/(.*)"); + public static final String PREFIX = "^/v[0-9][^/]*/[a-zA-Z]+_[^/]+/"; + public static final Pattern CONTAINER_PATH = Pattern.compile(PREFIX + "([^/]+)$"); + public static final Pattern CONTAINER_KEY_PATH = Pattern.compile(PREFIX + "([^/]+)/(.*)"); public void handleError(HttpCommand command, HttpResponse response) { Exception exception = new HttpResponseException(command, response); diff --git a/rackspace/src/main/java/org/jclouds/rackspace/functions/ParseAuthenticationResponseFromHeaders.java b/rackspace/src/main/java/org/jclouds/rackspace/functions/ParseAuthenticationResponseFromHeaders.java index baeef7961f..3c26bc6194 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/functions/ParseAuthenticationResponseFromHeaders.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/functions/ParseAuthenticationResponseFromHeaders.java @@ -29,118 +29,116 @@ import static org.jclouds.rackspace.reference.RackspaceHeaders.STORAGE_URL; import java.net.URI; import javax.annotation.Resource; -import javax.inject.Singleton; +import javax.inject.Inject; +import javax.inject.Provider; +import javax.ws.rs.core.UriBuilder; +import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.logging.Logger; import org.jclouds.rackspace.RackspaceAuthAsyncClient.AuthenticationResponse; +import org.jclouds.rest.InvocationContext; import com.google.common.base.Function; +import com.google.common.base.Objects; /** * This parses {@link AuthenticationResponse} from HTTP headers. * * @author Adrian Cole */ -@Singleton -public class ParseAuthenticationResponseFromHeaders implements Function { + +public class ParseAuthenticationResponseFromHeaders implements Function, + InvocationContext { public static final class AuthenticationResponseImpl implements AuthenticationResponse { - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((CDNManagementUrl == null) ? 0 : CDNManagementUrl.hashCode()); - result = prime * result + ((authToken == null) ? 0 : authToken.hashCode()); - result = prime * result + ((serverManagementUrl == null) ? 0 : serverManagementUrl.hashCode()); - result = prime * result + ((storageUrl == null) ? 0 : storageUrl.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AuthenticationResponseImpl other = (AuthenticationResponseImpl) obj; - if (CDNManagementUrl == null) { - if (other.CDNManagementUrl != null) - return false; - } else if (!CDNManagementUrl.equals(other.CDNManagementUrl)) - return false; - if (authToken == null) { - if (other.authToken != null) - return false; - } else if (!authToken.equals(other.authToken)) - return false; - if (serverManagementUrl == null) { - if (other.serverManagementUrl != null) - return false; - } else if (!serverManagementUrl.equals(other.serverManagementUrl)) - return false; - if (storageUrl == null) { - if (other.storageUrl != null) - return false; - } else if (!storageUrl.equals(other.storageUrl)) - return false; - return true; - } - private final String authToken; - private final String CDNManagementUrl; - private final String serverManagementUrl; - private final String storageUrl; + private final URI CDNManagementUrl; + private final URI serverManagementUrl; + private final URI storageUrl; - public AuthenticationResponseImpl(String authToken, String CDNManagementUrl, String serverManagementUrl, - String storageUrl) { + public AuthenticationResponseImpl(String authToken, URI CDNManagementUrl, URI serverManagementUrl, URI storageUrl) { this.authToken = authToken; this.CDNManagementUrl = CDNManagementUrl; this.serverManagementUrl = serverManagementUrl; this.storageUrl = storageUrl; } - @Override - public String toString() { - return "[CDNManagementUrl=" + CDNManagementUrl + ", serverManagementUrl=" + serverManagementUrl - + ", storageUrl=" + storageUrl + "]"; - } - public String getAuthToken() { return authToken; } public URI getCDNManagementUrl() { - return URI.create(CDNManagementUrl); + return CDNManagementUrl; } public URI getServerManagementUrl() { - return URI.create(serverManagementUrl); + return serverManagementUrl; } public URI getStorageUrl() { - return URI.create(storageUrl); + return storageUrl; } + + // performance isn't a concern on a infrequent object like this, so using shortcuts; + + @Override + public int hashCode() { + return Objects.hashCode(CDNManagementUrl, authToken, serverManagementUrl, storageUrl); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + return Objects.equal(this.toString(), that.toString()); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("CDNManagementUrl", CDNManagementUrl) + .add("serverManagementUrl", serverManagementUrl).add("storageUrl", storageUrl).toString(); + } + } @Resource protected Logger logger = Logger.NULL; + private final Provider uriBuilderProvider; + private String hostToReplace; + + @Inject + public ParseAuthenticationResponseFromHeaders(Provider uriBuilderProvider) { + this.uriBuilderProvider = uriBuilderProvider; + } + /** - * parses the http response headers to create a new - * {@link AuthenticationResponse} object. + * parses the http response headers to create a new {@link AuthenticationResponse} object. */ public AuthenticationResponse apply(HttpResponse from) { releasePayload(from); - AuthenticationResponse response = new AuthenticationResponseImpl(checkNotNull(from - .getFirstHeaderOrNull(AUTH_TOKEN), AUTH_TOKEN), checkNotNull(from.getFirstHeaderOrNull(CDN_MANAGEMENT_URL), - CDN_MANAGEMENT_URL), checkNotNull(from.getFirstHeaderOrNull(SERVER_MANAGEMENT_URL), SERVER_MANAGEMENT_URL), - checkNotNull(from.getFirstHeaderOrNull(STORAGE_URL), STORAGE_URL + " not found in headers:" - + from.getStatusLine() + " - " + from.getHeaders())); + AuthenticationResponse response = new AuthenticationResponseImpl(checkNotNull( + from.getFirstHeaderOrNull(AUTH_TOKEN), AUTH_TOKEN), getURI(from, CDN_MANAGEMENT_URL), getURI(from, + SERVER_MANAGEMENT_URL), getURI(from, STORAGE_URL)); logger.debug("will connect to: ", response); return response; } + + protected URI getURI(HttpResponse from, String header) { + String headerValue = from.getFirstHeaderOrNull(header); + if (headerValue == null) + return null; + URI toReturn = URI.create(headerValue); + if (!"127.0.0.1".equals(toReturn.getHost())) + return toReturn; + return uriBuilderProvider.get().uri(toReturn).host(hostToReplace).build(); + } + + @Override + public Object setContext(HttpRequest request) { + hostToReplace = request.getEndpoint().getHost(); + return this; + } } \ No newline at end of file diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/TestRackspaceAuthenticationRestClientModule.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/TestRackspaceAuthenticationRestClientModule.java index 7cf599465a..4f5e49b283 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/TestRackspaceAuthenticationRestClientModule.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/TestRackspaceAuthenticationRestClientModule.java @@ -19,6 +19,7 @@ package org.jclouds.rackspace.cloudservers; +import java.net.URI; import java.util.Date; import org.jclouds.http.RequiresHttp; @@ -39,8 +40,8 @@ public class TestRackspaceAuthenticationRestClientModule extends RackspaceAuthen @Override protected AuthenticationResponse provideAuthenticationResponse(Supplier supplier) { - return new AuthenticationResponseImpl("authToken", "http://CDNManagementUrl", "http://serverManagementUrl", - "http://storageUrl"); + return new AuthenticationResponseImpl("authToken", URI.create("http://CDNManagementUrl"), + URI.create("http://serverManagementUrl"), URI.create("http://storageUrl")); } @Override From 0d286b0c602813fbc15bdb19c29362948b2a5213 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 18 Dec 2010 12:43:00 +0100 Subject: [PATCH 10/33] Issue 429: test case for swift --- ...seCloudFilesErrorFromHttpResponseTest.java | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/handlers/ParseCloudFilesErrorFromHttpResponseTest.java diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/handlers/ParseCloudFilesErrorFromHttpResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/handlers/ParseCloudFilesErrorFromHttpResponseTest.java new file mode 100644 index 0000000000..bebbd38916 --- /dev/null +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/handlers/ParseCloudFilesErrorFromHttpResponseTest.java @@ -0,0 +1,101 @@ +package org.jclouds.rackspace.cloudfiles.handlers; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.reportMatcher; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +import java.net.URI; + +import org.easymock.IArgumentMatcher; +import org.jclouds.blobstore.ContainerNotFoundException; +import org.jclouds.blobstore.KeyNotFoundException; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class ParseCloudFilesErrorFromHttpResponseTest { + + @Test + public void test404SetsKeyNotFoundExceptionMosso() { + assertCodeMakes("HEAD", + URI.create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), 404, + "Not Found", "", KeyNotFoundException.class); + } + + @Test + public void test404SetsKeyNotFoundExceptionSwift() { + assertCodeMakes("HEAD", + URI.create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), + 404, "Not Found", "", KeyNotFoundException.class); + } + + @Test + public void test404SetsContainerNotFoundExceptionMosso() { + assertCodeMakes("HEAD", + URI.create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), 404, + "Not Found", "", ContainerNotFoundException.class); + } + + @Test + public void test404SetsContainerNotFoundExceptionSwift() { + assertCodeMakes("HEAD", + URI.create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), + 404, "Not Found", "", ContainerNotFoundException.class); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, + Class expected) { + assertCodeMakes(method, uri, statusCode, message, "text/plain", content, expected); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, + String content, Class expected) { + + ParseCloudFilesErrorFromHttpResponse function = new ParseCloudFilesErrorFromHttpResponse(); + + HttpCommand command = createMock(HttpCommand.class); + HttpRequest request = new HttpRequest(method, uri); + HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Utils + .toInputStream(content))); + response.getPayload().getContentMetadata().setContentType(contentType); + + expect(command.getRequest()).andReturn(request).atLeastOnce(); + command.setException(classEq(expected)); + + replay(command); + + function.handleError(command, response); + + verify(command); + } + + public static Exception classEq(final Class in) { + reportMatcher(new IArgumentMatcher() { + + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("classEq("); + buffer.append(in); + buffer.append(")"); + } + + @Override + public boolean matches(Object arg) { + return arg.getClass() == in; + } + + }); + return null; + } + +} \ No newline at end of file From 81760ee086f55b6095d6faa6dddd3e6380845c54 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 18 Dec 2010 19:51:49 +0100 Subject: [PATCH 11/33] Issue 412: server create now operates --- .../cloudsigma/CloudSigmaClientLiveTest.java | 8 +- .../CommonElasticStackAsyncClient.java | 71 +++++++- .../CommonElasticStackClient.java | 74 ++++++++ .../binders/BindServerToPlainTextString.java | 61 +++++++ .../config/ElasticStackRestClientModule.java | 6 + .../jclouds/elasticstack/domain/Server.java | 2 +- .../elasticstack/domain/ServerInfo.java | 2 +- .../elasticstack/functions/ServerToMap.java | 83 +++++++++ .../CommonElasticStackClientLiveTest.java | 156 +++++++++++++--- .../ElasticStackAsyncClientTest.java | 166 ++++++++++++++++-- .../ElasticStackClientLiveTest.java | 58 +++--- .../BindServerToPlainTextStringTest.java | 92 ++++++++++ ...DelimitedByBlankLinesToServerInfoTest.java | 5 + .../functions/MapToServerInfoTest.java | 35 ++++ .../functions/ServerToMapTest.java | 66 +++++++ .../elasticstack/predicates/DriveClaimed.java | 44 +++++ .../src/test/resources/create_server.txt | 11 ++ .../src/test/resources/new_server.txt | 24 +++ 18 files changed, 886 insertions(+), 78 deletions(-) create mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java create mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java create mode 100644 sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java create mode 100644 sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java create mode 100644 sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/predicates/DriveClaimed.java create mode 100644 sandbox/elasticstack/src/test/resources/create_server.txt create mode 100644 sandbox/elasticstack/src/test/resources/new_server.txt diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java index 223fa37d14..d2ba081591 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java @@ -67,6 +67,12 @@ public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTest getServerInfo(@PathParam("uuid") String uuid); + /** + * @see ElasticStackClient#createAndStartServer + */ + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/create") + ListenableFuture createAndStartServer( + @BinderParam(BindServerToPlainTextString.class) Server createServer); + + /** + * @see ElasticStackClient#createServer + */ + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/create/stopped") + ListenableFuture createServer( + @BinderParam(BindServerToPlainTextString.class) Server createServer); + + /** + * @see ElasticStackClient#setServer + */ + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/{uuid}/set") + ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, + @BinderParam(BindServerToPlainTextString.class) Server setServer); + + /** + * @see ElasticStackClient#destroyServer + */ + @POST + @Path("/servers/{uuid}/destroy") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture destroyServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#startServer + */ + @POST + @Path("/servers/{uuid}/start") + ListenableFuture startServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#stopServer + */ + @POST + @Path("/servers/{uuid}/stop") + ListenableFuture stopServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#shutdownServer + */ + @POST + @Path("/servers/{uuid}/shutdown") + ListenableFuture shutdownServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#resetServer + */ + @POST + @Path("/servers/{uuid}/reset") + ListenableFuture resetServer(@PathParam("uuid") String uuid); + /** * @see ElasticStackClient#listDrives() */ @@ -118,8 +186,7 @@ public interface CommonElasticStackAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/create") - ListenableFuture createDrive( - @BinderParam(BindDriveToPlainTextString.class) Drive createDrive); + ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); /** * @see ElasticStackClient#setDriveData diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java index a611d5e99d..6cf1a2916e 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java @@ -26,6 +26,7 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.elasticstack.domain.Drive; import org.jclouds.elasticstack.domain.DriveData; import org.jclouds.elasticstack.domain.DriveInfo; +import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerInfo; /** @@ -59,6 +60,79 @@ public interface CommonElasticStackClient { */ ServerInfo getServerInfo(String uuid); + /** + * create a new server + * + * @param server + * @return newly created server + */ + ServerInfo createServer(Server server); + + /** + * create and start a new server + * + * @param server + * @return newly created server + */ + ServerInfo createAndStartServer(Server server); + + /** + * set server configuration + * + * @param uuid + * what server to change + * @param serverData + * what values to change + * @return new data + */ + ServerInfo setServerConfiguration(String uuid, Server server); + + /** + * Destroy a server + * + * @param uuid + * what to destroy + */ + void destroyServer(String uuid); + + /** + * Start a server + * + * @param uuid + * what to start + */ + void startServer(String uuid); + + /** + * Stop a server + *

+ * Kills the server immediately, equivalent to a power failure. Server reverts to a stopped + * status if it is persistent and is automatically destroyed otherwise. + * + * @param uuid + * what to stop + */ + void stopServer(String uuid); + + /** + * Shutdown a server + *

+ * Sends the server an ACPI power-down event. Server reverts to a stopped status if it is + * persistent and is automatically destroyed otherwise. + * + * @param uuid + * what to shutdown + */ + void shutdownServer(String uuid); + + /** + * Reset a server + * + * @param uuid + * what to reset + */ + void resetServer(String uuid); + /** * list of drive uuids in your account * diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java new file mode 100644 index 0000000000..ba5cfe4895 --- /dev/null +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java @@ -0,0 +1,61 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.binders; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; + +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class BindServerToPlainTextString implements Binder { + private final Function> createServerRequestToMap; + private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; + + @Inject + public BindServerToPlainTextString(Function> createServerRequestToMap, + ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { + this.createServerRequestToMap = createServerRequestToMap; + this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; + } + + public void bindToRequest(HttpRequest request, Object payload) { + checkArgument(payload instanceof Server, "this binder is only valid for Server!"); + Server create = Server.class.cast(payload); + Map map = createServerRequestToMap.apply(create); + request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); + request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); + } +} diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java index 05435aecde..6e88d05692 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java @@ -29,10 +29,12 @@ import org.jclouds.elasticstack.domain.Drive; import org.jclouds.elasticstack.domain.DriveData; import org.jclouds.elasticstack.domain.DriveMetrics; import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerMetrics; import org.jclouds.elasticstack.functions.CreateDriveRequestToMap; import org.jclouds.elasticstack.functions.DriveDataToMap; import org.jclouds.elasticstack.functions.MapToDevices; +import org.jclouds.elasticstack.functions.ServerToMap; import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; import org.jclouds.elasticstack.functions.MapToDriveMetrics; import org.jclouds.elasticstack.functions.MapToNICs; @@ -79,6 +81,10 @@ public class ElasticStackRestClientModule extends RestClientModule>() { }).to(DeviceToId.class); + bind(new TypeLiteral>>() { + }).to(ServerToMap.class); + bind(new TypeLiteral>>() { + }).to(ServerToMap.class); } @Override diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java index dc50aa7b91..7ea0a65b53 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java @@ -127,7 +127,7 @@ public class Server extends Item { } public Server build() { - return new Server(uuid, name, cpu, smp, mem, persistent, devices, tags, bootDeviceIds, userMetadata, nics, + return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc, description); } } diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java index 0e5d3e2aa5..45a54314e7 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java @@ -161,7 +161,7 @@ public class ServerInfo extends Server { } public ServerInfo build() { - return new ServerInfo(uuid, name, cpu, smp, mem, persistent, devices, tags, bootDeviceIds, userMetadata, nics, + return new ServerInfo(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc, description, status, started, user, metrics); } } diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java new file mode 100644 index 0000000000..b6e846ce47 --- /dev/null +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java @@ -0,0 +1,83 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.Map.Entry; + +import javax.inject.Singleton; + +import org.jclouds.elasticstack.domain.Device; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; + +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableMap; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ServerToMap implements Function> { + @Override + public Map apply(Server from) { + checkNotNull(from, "server"); + ImmutableMap.Builder builder = ImmutableMap.builder(); + builder.put("name", from.getName()); + builder.put("cpu", from.getCpu() + ""); + if (from.getSmp() != null) + builder.put("smp", from.getSmp() + ""); + else + builder.put("smp", "auto"); + builder.put("mem", from.getMem() + ""); + builder.put("persistent", from.isPersistent() + ""); + if (from.getBootDeviceIds().size() != 0) + builder.put("boot", Joiner.on(' ').join(from.getBootDeviceIds())); + for (Entry entry : from.getDevices().entrySet()) { + builder.put(entry.getKey(), entry.getValue().getDriveUuid()); + builder.put(entry.getKey() + ":media", entry.getValue().getMediaType().toString()); + } + int nicId = 0; + for (NIC nic : from.getNics()) { + builder.put("nic:" + nicId + ":model", nic.getModel().toString()); + if (nic.getDhcp() != null) + builder.put("nic:" + nicId + ":dhcp", nic.getDhcp()); + if (nic.getVlan() != null) + builder.put("nic:" + nicId + ":vlan", nic.getVlan()); + if (nic.getMac() != null) + builder.put("nic:" + nicId + ":mac", nic.getMac()); + nicId++; + } + builder.put("vnc:ip", from.getVnc().getIp() == null ? "auto" : from.getVnc().getIp()); + if (from.getVnc().getPassword() != null) + builder.put("vnc:password", from.getVnc().getPassword()); + if (from.getVnc().isTls()) + builder.put("vnc:tls", "on"); + if (from.getTags().size() != 0) + builder.put("tags", Joiner.on(' ').join(from.getTags())); + for (Entry entry : from.getUserMetadata().entrySet()) + builder.put("user:" + entry.getKey(), entry.getValue()); + return builder.build(); + } +} \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java index cf2afcc2e7..40500e9fa3 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java @@ -25,6 +25,7 @@ import static org.testng.Assert.assertNotNull; import java.util.Properties; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.jclouds.Constants; import org.jclouds.elasticstack.domain.ClaimType; @@ -32,16 +33,28 @@ import org.jclouds.elasticstack.domain.CreateDriveRequest; import org.jclouds.elasticstack.domain.DriveData; import org.jclouds.elasticstack.domain.DriveInfo; import org.jclouds.elasticstack.domain.DriveStatus; +import org.jclouds.elasticstack.domain.IDEDevice; +import org.jclouds.elasticstack.domain.Model; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.domain.ServerStatus; +import org.jclouds.elasticstack.domain.VNC; +import org.jclouds.elasticstack.predicates.DriveClaimed; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; import org.testng.annotations.AfterGroups; +import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.gson.Gson; import com.google.inject.Module; /** @@ -52,6 +65,7 @@ import com.google.inject.Module; @Test(groups = "live", sequential = true) public abstract class CommonElasticStackClientLiveTest { + protected static final String VNC_PASSWORD = "XXXXXXXX"; protected S client; protected RestContext context; @@ -60,6 +74,7 @@ public abstract class CommonElasticStackClientLiveTest driveNotClaimed; protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); @@ -90,6 +105,8 @@ public abstract class CommonElasticStackClientLiveTest(Predicates.not(new DriveClaimed(client)), 30, 1, + TimeUnit.SECONDS); } @AfterGroups(groups = "live") @@ -139,59 +156,150 @@ public abstract class CommonElasticStackClientLiveTest httpRequest = processor.createRequest(method, + BindServerToPlainTextStringTest.SERVER); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/servers/create HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, BindServerToPlainTextStringTest.CREATED_SERVER, "text/plain", false); + + assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testCreateServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = ElasticStackAsyncClient.class.getMethod("createServer", Server.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + BindServerToPlainTextStringTest.SERVER); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/servers/create/stopped HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, BindServerToPlainTextStringTest.CREATED_SERVER, "text/plain", false); + + assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testSetServerConfiguration() throws SecurityException, NoSuchMethodException, IOException { + Method method = ElasticStackAsyncClient.class.getMethod("setServerConfiguration", String.class, Server.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "100", + BindServerToPlainTextStringTest.SERVER); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/servers/100/set HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, BindServerToPlainTextStringTest.CREATED_SERVER, "text/plain", false); + + assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testDestroyServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = ElasticStackAsyncClient.class.getMethod("destroyServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/servers/uuid/destroy HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testStartServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = ElasticStackAsyncClient.class.getMethod("startServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/servers/uuid/start HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testStopServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = ElasticStackAsyncClient.class.getMethod("stopServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/servers/uuid/stop HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testShutdownServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = ElasticStackAsyncClient.class.getMethod("shutdownServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/servers/uuid/shutdown HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testResetServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = ElasticStackAsyncClient.class.getMethod("resetServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/servers/uuid/reset HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + public void testListDrives() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticStackAsyncClient.class.getMethod("listDrives"); GeneratedHttpRequest httpRequest = processor.createRequest(method); @@ -213,6 +347,22 @@ public class ElasticStackAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/uuid/destroy HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + public void testImageDrive() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticStackAsyncClient.class.getMethod("imageDrive", String.class, String.class); GeneratedHttpRequest httpRequest = processor.createRequest(method, "100", "200"); @@ -247,22 +397,6 @@ public class ElasticStackAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "uuid"); - - assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/uuid/destroy HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - public void testReadDrive() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticStackAsyncClient.class.getMethod("readDrive", String.class); GeneratedHttpRequest httpRequest = processor.createRequest(method, "100"); diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java index ae102e8092..4863c9468d 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java @@ -38,50 +38,42 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "elasticstack.ElasticStackClientLiveTest") public class ElasticStackClientLiveTest extends CommonElasticStackClientLiveTest { - private DriveInfo info2; + private DriveInfo drive2; + private DriveInfo drive3; - @Override - public void testGetDrive() throws Exception { - super.testGetDrive(); - } - - @Override - public void testCreate() throws Exception { - super.testCreate(); - } - - @Override - public void testSetDriveData() throws Exception { - super.testSetDriveData(); - } - - @Override - public void testDestroyDrive() throws Exception { - super.testDestroyDrive(); - } - - @Test(dependsOnMethods = "testCreate") public void testWeCanReadAndWriteToDrive() throws IOException { - client.writeDrive(info.getUuid(), Payloads.newStringPayload("foo")); - assertEquals(Utils.toStringAndClose(client.readDrive(info.getUuid(), ReadDriveOptions.Builder.offset(0).size(3)) - .getInput()), "foo"); + drive2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build()); + client.writeDrive(drive2.getUuid(), Payloads.newStringPayload("foo")); + assertEquals(Utils.toStringAndClose(client + .readDrive(drive2.getUuid(), ReadDriveOptions.Builder.offset(0).size(3)).getInput()), "foo"); } @Test(dependsOnMethods = "testWeCanReadAndWriteToDrive") public void testWeCopyADriveContentsViaGzip() throws IOException { - try { - info2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(4 * 1024 * 1024l).build()); - client.imageDrive(info.getUuid(), info2.getUuid()); - - // TODO block until complete - System.err.println("state " + client.getDriveInfo(info2.getUuid())); - assertEquals(Utils.toStringAndClose(client.readDrive(info2.getUuid(), + drive3 = client + .createDrive(new CreateDriveRequest.Builder().name(prefix + "3").size(1 * 1024 * 1024l).build()); + System.err.println("before image; drive 2" + client.getDriveInfo(drive2.getUuid())); + System.err.println("before image; drive 3" + client.getDriveInfo(drive3.getUuid())); + client.imageDrive(drive2.getUuid(), drive3.getUuid()); + assert driveNotClaimed.apply(drive3) : client.getDriveInfo(drive3.getUuid()); + assert driveNotClaimed.apply(drive2) : client.getDriveInfo(drive2.getUuid()); + System.err.println("after image; drive 2" + client.getDriveInfo(drive2.getUuid())); + System.err.println("after image; drive 3" + client.getDriveInfo(drive3.getUuid())); + assertEquals(Utils.toStringAndClose(client.readDrive(drive3.getUuid(), ReadDriveOptions.Builder.offset(0).size(3)).getInput()), "foo"); } finally { - client.destroyDrive(info2.getUuid()); + client.destroyDrive(drive2.getUuid()); + client.destroyDrive(drive3.getUuid()); } + } + @Override + protected void prepareDrive() { + System.err.println("before prepare" + client.getDriveInfo(drive.getUuid())); + client.imageDrive("e6111e4c-67af-4438-b1bc-189747d5a8e5", drive.getUuid()); + assert driveNotClaimed.apply(drive) : client.getDriveInfo(drive.getUuid()); + System.err.println("after prepare" + client.getDriveInfo(drive.getUuid())); } } diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java new file mode 100644 index 0000000000..d6fb33314d --- /dev/null +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java @@ -0,0 +1,92 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.binders; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.elasticstack.domain.IDEDevice; +import org.jclouds.elasticstack.domain.Model; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.VNC; +import org.jclouds.elasticstack.functions.ServerToMap; +import org.jclouds.http.HttpRequest; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class BindServerToPlainTextStringTest { + + public static String CREATED_SERVER; + static { + try { + CREATED_SERVER = Utils.toStringAndClose(BindServerToPlainTextStringTest.class + .getResourceAsStream("/create_server.txt")); + } catch (IOException e) { + CREATED_SERVER = null; + } + } + public static final Server SERVER = new Server.Builder() + .name("TestServer") + .cpu(2000) + .mem(1024) + .devices( + ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid("08c92dd5-70a0-4f51-83d2-835919d254df") + .build())).bootDeviceIds(ImmutableSet.of("ide:0:0")) + .nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000). + + build())).vnc(new VNC(null, "XXXXXXXX", false)).build(); + private static final BindServerToPlainTextString FN = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + bind(new TypeLiteral>>() { + }).to(ServerToMap.class); + bind(new TypeLiteral>>() { + }).to(ServerToMap.class); + } + + }).getInstance(BindServerToPlainTextString.class); + + public void testSimple() throws IOException { + HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create")); + FN.bindToRequest(request, SERVER); + assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); + assertEquals(request.getPayload().getRawContent(), CREATED_SERVER); + } + +} \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java index 37d3fa6292..0687535890 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java @@ -73,4 +73,9 @@ public class KeyValuesDelimitedByBlankLinesToServerInfoTest { assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToServerInfoTest.class .getResourceAsStream("/servers.txt")))), MapToServerInfoTest.ONE); } + + public void testNew() { + assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToServerInfoTest.class + .getResourceAsStream("/new_server.txt")))), MapToServerInfoTest.ONE); + } } \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java index b6ef223688..e3e28a1955 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java @@ -124,4 +124,39 @@ public class MapToServerInfoTest { assertEquals(MAP_TO_DRIVE.apply(input), ONE); } + + public static ServerInfo NEW = new ServerInfo.Builder() + .persistent(true) + .uuid("bd98615a-6f74-4d63-ad1e-b13338b9356a") + .cpu(1000) + .bootDeviceIds(ImmutableSet.of("ide:0:0")) + .smp(1) + .mem(512) + .status(ServerStatus.ACTIVE) + .started(new Date(1292695612)) + .user("2f6244eb-50bc-4403-847e-f03cc3706a1f") + .name("adriancole.test") + .vnc(new VNC("83.222.249.221", "XXXXXXXX", false)) + .nics(ImmutableSet.of(new NIC.Builder() + .model(Model.E1000) + .block( + ImmutableList.of("tcp/43594", "tcp/5902", "udp/5060", "tcp/5900", "tcp/5901", "tcp/21", "tcp/22", + "tcp/23", "tcp/25", "tcp/110", "tcp/143", "tcp/43595")).build())) + .devices( + ImmutableMap.of("ide:0:0", + new IDEDevice.Builder((int) 0, (int) 0).uuid("403c9a86-0aab-4e47-aa95-e9768021c4c1").build() + + )) + .metrics( + new ServerMetrics.Builder().driveMetrics(ImmutableMap.of("ide:0:0", new DriveMetrics.Builder().build())) + .build()).build(); + + public void testNew() throws IOException { + + Map input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( + Utils.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/new_server.txt"))).get(0); + + assertEquals(MAP_TO_DRIVE.apply(input), NEW); + + } } \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java new file mode 100644 index 0000000000..ea963ca3b8 --- /dev/null +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.functions; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.elasticstack.domain.IDEDevice; +import org.jclouds.elasticstack.domain.Model; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.VNC; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class ServerToMapTest { + + private static final ServerToMap SERVER_TO_MAP = new ServerToMap(); + + public void testBasics() { + assertEquals( + SERVER_TO_MAP.apply(new Server.Builder() + .name("TestServer") + .cpu(2000) + .mem(1024) + .devices( + ImmutableMap.of("ide:0:0", + new IDEDevice.Builder(0, 0).uuid("08c92dd5-70a0-4f51-83d2-835919d254df").build())) + .bootDeviceIds(ImmutableSet.of("ide:0:0")).nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000). + + build())).vnc(new VNC(null, "XXXXXXXX", false)).build()), + ImmutableMap + .builder() + .putAll(ImmutableMap.of("name", "TestServer", "cpu", "2000", "smp", "auto", "mem", "1024")) + .putAll( + ImmutableMap.of("persistent", "false", "boot", "ide:0:0", "ide:0:0", + "08c92dd5-70a0-4f51-83d2-835919d254df")) + .putAll( + ImmutableMap.of("ide:0:0:media", "disk", "nic:0:model", "e1000", "vnc:ip", "auto", + "vnc:password", "XXXXXXXX")).build()); + } + +} \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/predicates/DriveClaimed.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/predicates/DriveClaimed.java new file mode 100644 index 0000000000..cc6b607a8c --- /dev/null +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/predicates/DriveClaimed.java @@ -0,0 +1,44 @@ +package org.jclouds.elasticstack.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.elasticstack.CommonElasticStackClient; +import org.jclouds.elasticstack.domain.DriveInfo; +import org.jclouds.logging.Logger; + +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class DriveClaimed implements Predicate { + + private final CommonElasticStackClient client; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public DriveClaimed(CommonElasticStackClient client) { + this.client = client; + } + + public boolean apply(DriveInfo drive) { + logger.trace("looking for claims on drive %s", checkNotNull(drive, "drive")); + drive = refresh(drive); + if (drive == null) + return false; + logger.trace("%s: looking for drive claims: currently: %s", drive.getUuid(), drive.getClaimed()); + return drive.getClaimed().size() > 0; + } + + private DriveInfo refresh(DriveInfo drive) { + return client.getDriveInfo(drive.getUuid()); + } +} diff --git a/sandbox/elasticstack/src/test/resources/create_server.txt b/sandbox/elasticstack/src/test/resources/create_server.txt new file mode 100644 index 0000000000..474d4d7ce1 --- /dev/null +++ b/sandbox/elasticstack/src/test/resources/create_server.txt @@ -0,0 +1,11 @@ +name TestServer +cpu 2000 +smp auto +mem 1024 +persistent false +boot ide:0:0 +ide:0:0 08c92dd5-70a0-4f51-83d2-835919d254df +ide:0:0:media disk +nic:0:model e1000 +vnc:ip auto +vnc:password XXXXXXXX \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/resources/new_server.txt b/sandbox/elasticstack/src/test/resources/new_server.txt new file mode 100644 index 0000000000..1dfbad99eb --- /dev/null +++ b/sandbox/elasticstack/src/test/resources/new_server.txt @@ -0,0 +1,24 @@ +ide:0:0:write:requests 0 +boot ide:0:0 +vnc:password XXXXXXXX +ide:0:0 403c9a86-0aab-4e47-aa95-e9768021c4c1 +ide:0:0:read:requests 0 +ide:0:0:read:bytes 0 +vnc:ip 83.222.249.221 +tx:packets 0 +tx 0 +rx 0 +smp 1 +mem 512 +nic:0:model e1000 +status active +started 1292695612 +rx:packets 0 +user 2f6244eb-50bc-4403-847e-f03cc3706a1f +ide:0:0:media disk +name adriancole.test +persistent true +nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595 +server bd98615a-6f74-4d63-ad1e-b13338b9356a +ide:0:0:write:bytes 0 +cpu 1000 \ No newline at end of file From c57e09c5aee1f7e7e1b94b2be4079dbab41d5491 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 18 Dec 2010 21:36:52 +0100 Subject: [PATCH 12/33] Issue 412: updated syntax for readDrive based on notes from elasticstack --- .../elasticstack/ElasticStackAsyncClient.java | 22 +---- .../elasticstack/ElasticStackClient.java | 14 +-- .../binders/BindReadDriveOptionsToPath.java | 59 ------------ .../options/ReadDriveOptions.java | 91 ------------------- .../CommonElasticStackClientLiveTest.java | 36 ++++---- .../ElasticStackAsyncClientTest.java | 21 +---- .../ElasticStackClientLiveTest.java | 7 +- .../BindReadDriveOptionsToPathTest.java | 51 ----------- .../options/ReadDriveOptionsTest.java | 83 ----------------- 9 files changed, 33 insertions(+), 351 deletions(-) delete mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindReadDriveOptionsToPath.java delete mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/options/ReadDriveOptions.java delete mode 100644 sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindReadDriveOptionsToPathTest.java delete mode 100644 sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/options/ReadDriveOptionsTest.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java index 4314cdfb24..cea0b3c52f 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java @@ -20,20 +20,16 @@ package org.jclouds.elasticstack; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.jclouds.elasticstack.binders.BindReadDriveOptionsToPath; import org.jclouds.elasticstack.domain.ImageConversionType; import org.jclouds.elasticstack.functions.ReturnPayload; -import org.jclouds.elasticstack.options.ReadDriveOptions; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.io.Payload; -import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; @@ -72,25 +68,15 @@ public interface ElasticStackAsyncClient extends CommonElasticStackAsyncClient { @PathParam("conversion") ImageConversionType conversionType); /** - * @see ElasticStackClient#readDrive(String) - */ - @GET - @Consumes(MediaType.APPLICATION_OCTET_STREAM) - @Path("/drives/{uuid}/read") - @ResponseParser(ReturnPayload.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture readDrive(@PathParam("uuid") String uuid); - - /** - * @see ElasticStackClient#readDrive(String,ReadDriveOptions) + * @see ElasticStackClient#readDrive */ @POST @Consumes(MediaType.APPLICATION_OCTET_STREAM) - @Path("/drives/{uuid}/read") + @Path("/drives/{uuid}/read/{offset}/{size}") @ResponseParser(ReturnPayload.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture readDrive(@PathParam("uuid") String uuid, - @BinderParam(BindReadDriveOptionsToPath.class) ReadDriveOptions options); + ListenableFuture readDrive(@PathParam("uuid") String uuid, @PathParam("offset") long offset, + @PathParam("size") long size); /** * @see ElasticStackClient#writeDrive(String, Payload) diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java index 5d4998c366..129ac4a94f 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java @@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.elasticstack.domain.ImageConversionType; -import org.jclouds.elasticstack.options.ReadDriveOptions; import org.jclouds.io.Payload; /** @@ -60,16 +59,13 @@ public interface ElasticStackClient extends CommonElasticStackClient { * * @param uuid * drive to read + * @param offset + * start at the specified offset in bytes + * @param size + * the specified size in bytes; must be <=4096k * @return binary content of the drive. */ - Payload readDrive(String uuid); - - /** - * @see #readDrive(String) - * @param options - * controls offset and size of the request - */ - Payload readDrive(String uuid, ReadDriveOptions options); + Payload readDrive(String uuid, long offset, long size); /** * Write binary data to a drive diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindReadDriveOptionsToPath.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindReadDriveOptionsToPath.java deleted file mode 100644 index 878b4bca3a..0000000000 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindReadDriveOptionsToPath.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.elasticstack.binders; - -import static com.google.common.base.Preconditions.checkArgument; - -import javax.inject.Inject; -import javax.inject.Provider; -import javax.inject.Singleton; -import javax.ws.rs.core.UriBuilder; - -import org.jclouds.elasticstack.options.ReadDriveOptions; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.Binder; - -/** - * - * @author Adrian Cole - */ -@Singleton -public class BindReadDriveOptionsToPath implements Binder { - private final Provider uriBuilderProvider; - - @Inject - public BindReadDriveOptionsToPath(Provider uriBuilderProvider) { - this.uriBuilderProvider = uriBuilderProvider; - } - - public void bindToRequest(HttpRequest request, Object payload) { - checkArgument(payload instanceof ReadDriveOptions, "this binder is only valid for ReadDriveOptions!"); - ReadDriveOptions options = ReadDriveOptions.class.cast(payload); - if (options.getOffset() != null || options.getSize() != null){ - UriBuilder builder = uriBuilderProvider.get().uri(request.getEndpoint()); - if (options.getOffset() != null) - builder.path("/"+options.getOffset()); - if (options.getSize() != null) - builder.path("/"+options.getSize()); - request.setEndpoint(builder.build()); - } - - } -} diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/options/ReadDriveOptions.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/options/ReadDriveOptions.java deleted file mode 100644 index cfbe4af50e..0000000000 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/options/ReadDriveOptions.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.elasticstack.options; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Contains options supported for read drive operations.

- * Usage

The recommended way to instantiate a ReadDriveOptions object is to statically import - * ReadDriveOptions.Builder.* and invoke a static creation method followed by an instance mutator - * (if needed): - *

- * - * import static org.jclouds.elasticstack.options.ReadDriveOptions.Builder.*; - * - * - * // this will get the first 1024 bytes starting at offset 2048 - * Payload payload = client.readDrive("drive-uuid",offset(2048l).size(1024l)); - * - * - * @author Adrian Cole - * - */ -public class ReadDriveOptions { - - private Long offset; - private Long size; - - /** - * start at the specified offset in bytes - */ - public ReadDriveOptions offset(long offset) { - checkArgument(offset >= 0, "start must be >= 0"); - this.offset = offset; - return this; - } - - /** - * download the specified size in bytes - */ - public ReadDriveOptions size(long size) { - checkArgument(size >= 0, "start must be >= 0"); - this.size = size; - return this; - } - - public static class Builder { - - /** - * @see ReadDriveOptions#offset - */ - public static ReadDriveOptions offset(long offset) { - ReadDriveOptions options = new ReadDriveOptions(); - return options.offset(offset); - } - - /** - * @see ReadDriveOptions#size - */ - public static ReadDriveOptions size(long size) { - ReadDriveOptions options = new ReadDriveOptions(); - return options.size(size); - } - - } - - public Long getOffset() { - return offset; - } - - public Long getSize() { - return size; - } -} diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java index 40500e9fa3..48be0d32ca 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java @@ -246,21 +246,24 @@ public abstract class CommonElasticStackClientLiveTest httpRequest = processor.createRequest(method, "100"); - - assertRequestLineEquals(httpRequest, "GET https://api.elasticstack.com/drives/100/read HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/octet-stream\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReturnPayload.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(httpRequest); - } - - public void testReadDriveOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = ElasticStackAsyncClient.class.getMethod("readDrive", String.class, ReadDriveOptions.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, "100", - new ReadDriveOptions().offset(1024).size(2048)); + Method method = ElasticStackAsyncClient.class.getMethod("readDrive", String.class, long.class, long.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "100", 1024, 2048); assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/100/read/1024/2048 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/octet-stream\n"); diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java index 4863c9468d..ecd3b1276a 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java @@ -25,7 +25,6 @@ import java.io.IOException; import org.jclouds.elasticstack.domain.CreateDriveRequest; import org.jclouds.elasticstack.domain.DriveInfo; -import org.jclouds.elasticstack.options.ReadDriveOptions; import org.jclouds.io.Payloads; import org.jclouds.util.Utils; import org.testng.annotations.Test; @@ -44,8 +43,7 @@ public class ElasticStackClientLiveTest extends public void testWeCanReadAndWriteToDrive() throws IOException { drive2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build()); client.writeDrive(drive2.getUuid(), Payloads.newStringPayload("foo")); - assertEquals(Utils.toStringAndClose(client - .readDrive(drive2.getUuid(), ReadDriveOptions.Builder.offset(0).size(3)).getInput()), "foo"); + assertEquals(Utils.toStringAndClose(client.readDrive(drive2.getUuid(), 0, 3).getInput()), "foo"); } @Test(dependsOnMethods = "testWeCanReadAndWriteToDrive") @@ -60,8 +58,7 @@ public class ElasticStackClientLiveTest extends assert driveNotClaimed.apply(drive2) : client.getDriveInfo(drive2.getUuid()); System.err.println("after image; drive 2" + client.getDriveInfo(drive2.getUuid())); System.err.println("after image; drive 3" + client.getDriveInfo(drive3.getUuid())); - assertEquals(Utils.toStringAndClose(client.readDrive(drive3.getUuid(), - ReadDriveOptions.Builder.offset(0).size(3)).getInput()), "foo"); + assertEquals(Utils.toStringAndClose(client.readDrive(drive3.getUuid(), 0, 3).getInput()), "foo"); } finally { client.destroyDrive(drive2.getUuid()); client.destroyDrive(drive3.getUuid()); diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindReadDriveOptionsToPathTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindReadDriveOptionsToPathTest.java deleted file mode 100644 index d7d9701b6c..0000000000 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindReadDriveOptionsToPathTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.elasticstack.binders; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.elasticstack.options.ReadDriveOptions; -import org.jclouds.http.HttpRequest; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientTest.MockModule; -import org.jclouds.rest.config.RestModule; -import org.testng.annotations.Test; - -import com.google.inject.Guice; - -/** - * - * @author Adrian Cole - */ -@Test(groups = { "unit" }) -public class BindReadDriveOptionsToPathTest { - - private static final BindReadDriveOptionsToPath FN = Guice.createInjector(new RestModule(), new MockModule(), - new NullLoggingModule()).getInstance(BindReadDriveOptionsToPath.class); - - public void testSimple() { - HttpRequest request = new HttpRequest("POST", URI.create("https://drives/read")); - FN.bindToRequest(request, new ReadDriveOptions().offset(1024l).size(2048l)); - assertEquals(request.getEndpoint().getPath(), "/read/1024/2048"); - } - -} \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/options/ReadDriveOptionsTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/options/ReadDriveOptionsTest.java deleted file mode 100644 index 3e4e4a3a38..0000000000 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/options/ReadDriveOptionsTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.elasticstack.options; - -import static org.jclouds.elasticstack.options.ReadDriveOptions.Builder.offset; -import static org.jclouds.elasticstack.options.ReadDriveOptions.Builder.size; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import org.testng.annotations.Test; - -/** - * Tests possible uses of ReadDriveOptions and ReadDriveOptions.Builder.* - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ReadDriveOptionsTest { - - @Test - public void testNullOffset() { - ReadDriveOptions options = new ReadDriveOptions(); - assertNull(options.getOffset()); - } - - @Test - public void testOffset() { - ReadDriveOptions options = new ReadDriveOptions().offset(1024); - assertEquals(options.getOffset(), new Long(1024)); - } - - @Test - public void testOffsetStatic() { - ReadDriveOptions options = offset(1024); - assertEquals(options.getOffset(), new Long(1024)); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testOffsetNegative() { - offset(-1); - } - - @Test - public void testNullSize() { - ReadDriveOptions options = new ReadDriveOptions(); - assertNull(options.getSize()); - } - - @Test - public void testSize() { - ReadDriveOptions options = new ReadDriveOptions().size(1024); - assertEquals(options.getSize(), new Long(1024)); - } - - @Test - public void testSizeStatic() { - ReadDriveOptions options = size(1024); - assertEquals(options.getSize(), new Long(1024)); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testSizeNegative() { - size(-1); - } - -} From 70fbb3a5b8adaf75ece08108963d706b50877656 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 19 Dec 2010 12:28:56 +0100 Subject: [PATCH 13/33] Issue 412: elastichosts drive now verifies ssh opens properly --- .../CommonElasticStackClient.java | 2 + .../jclouds/elasticstack/domain/Server.java | 7 ++ .../jclouds/elasticstack/util/Servers.java | 54 +++++++++++++ .../CommonElasticStackClientLiveTest.java | 81 +++++++++++-------- .../ElasticStackClientLiveTest.java | 3 +- ...DelimitedByBlankLinesToServerInfoTest.java | 4 +- 6 files changed, 113 insertions(+), 38 deletions(-) create mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/util/Servers.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java index 6cf1a2916e..5839248f6b 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java @@ -119,6 +119,8 @@ public interface CommonElasticStackClient { *

* Sends the server an ACPI power-down event. Server reverts to a stopped status if it is * persistent and is automatically destroyed otherwise. + *

note

behaviour on shutdown depends on how your server OS is set up to respond to an + * ACPI power button signal. * * @param uuid * what to shutdown diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java index 7ea0a65b53..018909bee1 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java @@ -130,6 +130,13 @@ public class Server extends Item { return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc, description); } + + public static Builder fromServer(Server in) { + return new Builder().uuid(in.getUuid()).name(in.getName()).cpu(in.getCpu()).mem(in.getMem()) + .persistent(in.isPersistent()).description(in.getDescription()).devices(in.getDevices()) + .bootDeviceIds(in.getBootDeviceIds()).tags(in.getTags()).userMetadata(in.getUserMetadata()) + .nics(in.getNics()).vnc(in.getVnc()); + } } protected final int cpu; diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/util/Servers.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/util/Servers.java new file mode 100644 index 0000000000..1d8564f0cc --- /dev/null +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/util/Servers.java @@ -0,0 +1,54 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.util; + +import org.jclouds.elasticstack.domain.IDEDevice; +import org.jclouds.elasticstack.domain.Model; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.VNC; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +public class Servers { + /** + * Helper to create a small persistent server + * + * @param name + * what to name the server + * @param driveUuuid + * id of the boot drive + * @param vncPassword + * password for vnc + * @return a builder for a persistent 1Ghz 512m server with DHCP enabled network. + */ + public static Server.Builder small(String name, String driveUuuid, String vncPassword) { + return new Server.Builder().name(name).cpu(1000).mem(512).persistent(true) + .devices(ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(driveUuuid).build())) + .bootDeviceIds(ImmutableSet.of("ide:0:0")) + .nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp("auto").build())) + .vnc(new VNC(null, vncPassword, false)); + } +} \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java index 48be0d32ca..7a08fd4f3f 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java @@ -26,6 +26,7 @@ import static org.testng.Assert.assertNotNull; import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; import org.jclouds.Constants; import org.jclouds.elasticstack.domain.ClaimType; @@ -39,17 +40,19 @@ import org.jclouds.elasticstack.domain.NIC; import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerInfo; import org.jclouds.elasticstack.domain.ServerStatus; -import org.jclouds.elasticstack.domain.VNC; import org.jclouds.elasticstack.predicates.DriveClaimed; +import org.jclouds.elasticstack.util.Servers; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.net.IPSocket; +import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; import org.testng.annotations.AfterGroups; -import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -68,6 +71,7 @@ public abstract class CommonElasticStackClientLiveTest context; + protected Predicate socketTester; protected String provider = "elasticstack"; protected String identity; @@ -105,14 +109,9 @@ public abstract class CommonElasticStackClientLiveTest(Predicates.not(new DriveClaimed(client)), 30, 1, + driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), 120, 1, TimeUnit.SECONDS); - } - - @AfterGroups(groups = "live") - void tearDown() { - if (context != null) - context.close(); + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 120, 1, TimeUnit.SECONDS); } @Test @@ -211,13 +210,12 @@ public abstract class CommonElasticStackClientLiveTest Date: Sun, 19 Dec 2010 16:33:52 +0100 Subject: [PATCH 14/33] Issue 419: cloudsigma server lifecycle now works --- .../cloudsigma/CloudSigmaAsyncClient.java | 70 ++++- .../jclouds/cloudsigma/CloudSigmaClient.java | 14 + ...indCloneDriveOptionsToPlainTextString.java | 91 ++++++ .../config/CloudSigmaRestClientModule.java | 4 + .../cloudsigma/functions/DriveDataToMap.java | 11 +- ...luesDelimitedByBlankLinesToServerInfo.java | 53 ++++ ...sDelimitedByBlankLinesToServerInfoSet.java | 62 ++++ .../cloudsigma/functions/MapToDriveInfo.java | 2 +- .../cloudsigma/functions/MapToServerInfo.java | 95 +++++++ .../cloudsigma/functions/ServerToMap.java | 83 ++++++ .../cloudsigma/options/CloneDriveOptions.java | 72 +++++ .../cloudsigma/CloudSigmaAsyncClientTest.java | 264 +++++++++++++++++- .../cloudsigma/CloudSigmaClientLiveTest.java | 22 +- ...loneDriveOptionsToPlainTextStringTest.java | 78 ++++++ ...sDelimitedByBlankLinesToDriveInfoTest.java | 2 +- ...DelimitedByBlankLinesToServerInfoTest.java | 85 ++++++ ...limitedByBlankLinesToDriveInfoSetTest.java | 2 +- ...imitedByBlankLinesToServerInfoSetTest.java | 85 ++++++ .../functions/MapToDriveInfoTest.java | 2 +- .../functions/MapToServerInfoTest.java | 167 +++++++++++ .../cloudsigma/functions/ServerToMapTest.java | 66 +++++ .../options/CloneDriveOptionsTest.java | 59 ++++ .../test/resources/{ => cloudsigma}/drive.txt | 2 +- .../CommonElasticStackAsyncClient.java | 12 +- .../CommonElasticStackClient.java | 8 - .../elasticstack/ElasticStackAsyncClient.java | 15 + .../elasticstack/ElasticStackClient.java | 10 + .../config/ElasticStackRestClientModule.java | 2 - .../org/jclouds/elasticstack/domain/NIC.java | 1 + .../jclouds/elasticstack/domain/Server.java | 2 +- .../CommonElasticStackClientLiveTest.java | 39 +-- 31 files changed, 1416 insertions(+), 64 deletions(-) create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java rename sandbox/cloudsigma/src/test/resources/{ => cloudsigma}/drive.txt (97%) diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java index 4a0ba2fe95..e70ea6c2f2 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java @@ -28,19 +28,28 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; +import org.jclouds.cloudsigma.binders.BindCloneDriveOptionsToPlainTextString; import org.jclouds.cloudsigma.domain.DriveInfo; import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; +import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo; import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; +import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.elasticstack.CommonElasticStackAsyncClient; import org.jclouds.elasticstack.ElasticStackClient; import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString; import org.jclouds.elasticstack.binders.BindDriveToPlainTextString; +import org.jclouds.elasticstack.binders.BindServerToPlainTextString; import org.jclouds.elasticstack.domain.Drive; import org.jclouds.elasticstack.domain.DriveData; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.ServerInfo; import org.jclouds.elasticstack.functions.SplitNewlines; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.MapPayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -84,7 +93,17 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture> listStandardImages(); /** - * @see ElasticStackClient#listDriveInfo() + * @see CloudSigmaClient#cloneDrive + */ + @POST + @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) + @Path("/drives/{uuid}/clone") + @MapBinder(BindCloneDriveOptionsToPlainTextString.class) + ListenableFuture cloneDrive(@PathParam("uuid") String sourceUuid, + @MapPayloadParam("name") String newName, CloneDriveOptions... options); + + /** + * {@inheritDoc} */ @Override @GET @@ -93,7 +112,7 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture> listDriveInfo(); /** - * @see ElasticStackClient#getDriveInfo + * {@inheritDoc} */ @Override @GET @@ -103,7 +122,7 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture getDriveInfo(@PathParam("uuid") String uuid); /** - * @see ElasticStackClient#createDrive + * {@inheritDoc} */ @Override @POST @@ -113,12 +132,53 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); /** - * @see ElasticStackClient#setDriveData + * {@inheritDoc} */ + @Override @POST - @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/{uuid}/set") ListenableFuture setDriveData(@PathParam("uuid") String uuid, @BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive); + + /** + * {@inheritDoc} + */ + @Override + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/create") + ListenableFuture createServer( + @BinderParam(BindServerToPlainTextString.class) Server createServer); + + /** + * {@inheritDoc} + */ + @Override + @GET + @Path("/servers/info") + @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class) + ListenableFuture> listServerInfo(); + + /** + * {@inheritDoc} + */ + @Override + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/{uuid}/info") + ListenableFuture getServerInfo(@PathParam("uuid") String uuid); + + /** + * {@inheritDoc} + */ + @Override + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/{uuid}/set") + ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, + @BinderParam(BindServerToPlainTextString.class) Server setServer); } diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java index ecf4394a63..5ac74140ba 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java @@ -23,6 +23,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.concurrent.Timeout; import org.jclouds.elasticstack.CommonElasticStackClient; import org.jclouds.elasticstack.domain.Drive; @@ -60,6 +61,19 @@ public interface CloudSigmaClient extends CommonElasticStackClient { */ Set listStandardImages(); + /** + * Clone an existing drive. By default, the size is the same as the source + * + * @param sourceUuid + * source to clone + * @param newName + * name of the resulting drive + * @param options + * options to control size + * @return new drive + */ + DriveInfo cloneDrive(String sourceUuid, String newName, CloneDriveOptions... options); + /** * {@inheritDoc} */ diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java new file mode 100644 index 0000000000..9cfb13b671 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java @@ -0,0 +1,91 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudsigma.CloudSigmaAsyncClient; +import org.jclouds.cloudsigma.options.CloneDriveOptions; +import org.jclouds.elasticstack.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.MapBinder; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class BindCloneDriveOptionsToPlainTextString implements MapBinder { + private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; + + @Inject + public BindCloneDriveOptionsToPlainTextString( + ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { + this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; + } + + @Override + public void bindToRequest(HttpRequest request, Map postParams) { + checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, + "this binder is only valid for GeneratedHttpRequests!"); + @SuppressWarnings("unchecked") + GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; + checkState(gRequest.getArgs() != null, "args should be initialized at this point"); + + CloneDriveOptions options = findOptionsInArgsOrNull(gRequest); + if (options != null) { + postParams = ImmutableMap. builder().putAll(postParams).putAll(options.getOptions()).build(); + } + + request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(postParams))); + request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); + + } + + static CloneDriveOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) { + for (Object arg : gRequest.getArgs()) { + if (arg instanceof CloneDriveOptions) { + return (CloneDriveOptions) arg; + } else if (arg instanceof CloneDriveOptions[]) { + CloneDriveOptions[] options = (CloneDriveOptions[]) arg; + return (options.length > 0) ? options[0] : null; + } + } + return null; + } + + @Override + public void bindToRequest(HttpRequest request, Object input) { + throw new UnsupportedOperationException(); + } + +} diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java index e935551866..c187dadc17 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java @@ -26,11 +26,13 @@ import org.jclouds.cloudsigma.CloudSigmaAsyncClient; import org.jclouds.cloudsigma.CloudSigmaClient; import org.jclouds.cloudsigma.functions.CreateDriveRequestToMap; import org.jclouds.cloudsigma.functions.DriveDataToMap; +import org.jclouds.cloudsigma.functions.ServerToMap; import org.jclouds.elasticstack.domain.Device; import org.jclouds.elasticstack.domain.Drive; import org.jclouds.elasticstack.domain.DriveData; import org.jclouds.elasticstack.domain.DriveMetrics; import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerMetrics; import org.jclouds.elasticstack.functions.MapToDevices; import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; @@ -86,6 +88,8 @@ public class CloudSigmaRestClientModule extends RestClientModule>() { }).to(DeviceToId.class); + bind(new TypeLiteral>>() { + }).to(ServerToMap.class); } @Override diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java index 715098e6b8..baa1c0301e 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java @@ -29,7 +29,6 @@ import javax.inject.Singleton; import org.jclouds.elasticstack.domain.DriveData; import com.google.common.base.Function; -import com.google.common.collect.Maps; /** * @@ -46,14 +45,6 @@ public class DriveDataToMap implements Function> @Override public Map apply(DriveData from) { - return Maps.transformEntries(renameKey(baseDriveToMap.apply(from), "tags", "use"), - new Maps.EntryTransformer() { - - @Override - public String transformEntry(String arg0, String arg1) { - return "use".equals(arg0) ? arg1.replace(' ', ',') : arg1; - } - - }); + return renameKey(baseDriveToMap.apply(from), "tags", "use"); } } \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java new file mode 100644 index 0000000000..32224ed897 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.http.HttpResponse; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class KeyValuesDelimitedByBlankLinesToServerInfo implements Function { + private final ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet setParser; + + @Inject + public KeyValuesDelimitedByBlankLinesToServerInfo(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet setParser) { + this.setParser = setParser; + } + + @Override + public ServerInfo apply(HttpResponse response) { + Set drives = setParser.apply(response); + if (drives.size() == 0) + return null; + return Iterables.get(drives, 0); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java new file mode 100644 index 0000000000..1726d153a1 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java @@ -0,0 +1,62 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ReturnStringIf2xx; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet implements Function> { + private final ReturnStringIf2xx returnStringIf200; + private final ListOfKeyValuesDelimitedByBlankLinesToListOfMaps mapConverter; + private final MapToServerInfo mapToServer; + + @Inject + ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet(ReturnStringIf2xx returnStringIf200, + ListOfKeyValuesDelimitedByBlankLinesToListOfMaps mapConverter, MapToServerInfo mapToServer) { + this.returnStringIf200 = returnStringIf200; + this.mapConverter = mapConverter; + this.mapToServer = mapToServer; + } + + @Override + public Set apply(HttpResponse response) { + String text = returnStringIf200.apply(response); + if (text == null || text.trim().equals("")) + return ImmutableSet. of(); + return ImmutableSet.copyOf(Iterables.transform(mapConverter.apply(text), mapToServer)); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java index 2910718e2a..45af167398 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java @@ -50,7 +50,7 @@ public class MapToDriveInfo implements Function, DriveInfo> return null; DriveInfo.Builder builder = DriveInfo.Builder.fromDriveInfo(mapToDriveInfo.apply(from)); if (from.containsKey("use")) - builder.tags(Splitter.on(',').split(from.get("use"))); + builder.tags(Splitter.on(' ').split(from.get("use"))); if (from.containsKey("bits")) builder.bits(new Integer(from.get("bits"))); if (from.containsKey("url")) diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java new file mode 100644 index 0000000000..d4ec8c2512 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java @@ -0,0 +1,95 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.elasticstack.domain.Device; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.domain.ServerMetrics; +import org.jclouds.elasticstack.domain.ServerStatus; +import org.jclouds.elasticstack.domain.VNC; + +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.Maps; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class MapToServerInfo implements Function, ServerInfo> { + private final Function, Map> mapToDevices; + private final Function, ServerMetrics> mapToMetrics; + private final Function, List> mapToNICs; + + @Inject + public MapToServerInfo(Function, Map> mapToDevices, + Function, ServerMetrics> mapToMetrics, Function, List> mapToNICs) { + this.mapToDevices = mapToDevices; + this.mapToMetrics = mapToMetrics; + this.mapToNICs = mapToNICs; + } + + @Override + public ServerInfo apply(Map from) { + if (from.size() == 0) + return null; + ServerInfo.Builder builder = new ServerInfo.Builder(); + builder.name(from.get("name")); + builder.description(from.get("description")); + builder.persistent(Boolean.parseBoolean(from.get("persistent"))); + if (from.containsKey("use")) + builder.tags(Splitter.on(' ').split(from.get("use"))); + if (from.containsKey("status")) + builder.status(ServerStatus.fromValue(from.get("status"))); + if (from.containsKey("smp") && !"auto".equals(from.get("smp"))) + builder.smp(new Integer(from.get("smp"))); + builder.cpu(Integer.parseInt(from.get("cpu"))); + builder.mem(Integer.parseInt(from.get("mem"))); + builder.user(from.get("user")); + if (from.containsKey("started")) + builder.started(new Date(new Long(from.get("started")))); + builder.uuid(from.get("server")); + builder.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls") + && Boolean.valueOf(from.get("vnc:tls")))); + if (from.containsKey("boot")) + builder.bootDeviceIds(Splitter.on(' ').split(from.get("boot"))); + + Map metadata = Maps.newLinkedHashMap(); + for (Entry entry : from.entrySet()) { + if (entry.getKey().startsWith("user:")) + metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue()); + } + builder.userMetadata(metadata); + builder.nics(mapToNICs.apply(from)); + builder.devices(mapToDevices.apply(from)); + builder.metrics(mapToMetrics.apply(from)); + return builder.build(); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java new file mode 100644 index 0000000000..8a5bfab146 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java @@ -0,0 +1,83 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.Map.Entry; + +import javax.inject.Singleton; + +import org.jclouds.elasticstack.domain.Device; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; + +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableMap; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ServerToMap implements Function> { + @Override + public Map apply(Server from) { + checkNotNull(from, "server"); + ImmutableMap.Builder builder = ImmutableMap.builder(); + builder.put("name", from.getName()); + builder.put("cpu", from.getCpu() + ""); + if (from.getSmp() != null) + builder.put("smp", from.getSmp() + ""); + else + builder.put("smp", "auto"); + builder.put("mem", from.getMem() + ""); + builder.put("persistent", from.isPersistent() + ""); + if (from.getBootDeviceIds().size() != 0) + builder.put("boot", Joiner.on(' ').join(from.getBootDeviceIds())); + for (Entry entry : from.getDevices().entrySet()) { + builder.put(entry.getKey(), entry.getValue().getDriveUuid()); + builder.put(entry.getKey() + ":media", entry.getValue().getMediaType().toString()); + } + int nicId = 0; + for (NIC nic : from.getNics()) { + builder.put("nic:" + nicId + ":model", nic.getModel().toString()); + if (nic.getDhcp() != null) + builder.put("nic:" + nicId + ":dhcp", nic.getDhcp()); + if (nic.getVlan() != null) + builder.put("nic:" + nicId + ":vlan", nic.getVlan()); + if (nic.getMac() != null) + builder.put("nic:" + nicId + ":mac", nic.getMac()); + nicId++; + } + builder.put("vnc:ip", from.getVnc().getIp() == null ? "auto" : from.getVnc().getIp()); + if (from.getVnc().getPassword() != null) + builder.put("vnc:password", from.getVnc().getPassword()); + if (from.getVnc().isTls()) + builder.put("vnc:tls", "on"); + if (from.getTags().size() != 0) + builder.put("use", Joiner.on(' ').join(from.getTags())); + for (Entry entry : from.getUserMetadata().entrySet()) + builder.put("user:" + entry.getKey(), entry.getValue()); + return builder.build(); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java new file mode 100644 index 0000000000..df9f5c59a2 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java @@ -0,0 +1,72 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.options; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.Map; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +/** + * Contains options supported for clone drive operations.

+ * Usage

The recommended way to instantiate a CloneDriveOptions object is to statically import + * CloneDriveOptions.Builder.* and invoke a static creation method followed by an instance mutator + * (if needed): + *

* - * @see ElasticStackClient + * @see CloudSigmaClient * @see * @author Adrian Cole */ @RequestFilters(BasicAuthentication.class) @Consumes(MediaType.TEXT_PLAIN) -public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { +public interface CloudSigmaAsyncClient { /** - * @see ElasticStackClient#listStandardDrives() + * @see CloudSigmaClient#listStandardDrives */ @GET @Path("/drives/standard/list") @@ -77,7 +76,7 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture> listStandardDrives(); /** - * @see ElasticStackClient#listStandardCds() + * @see CloudSigmaClient#listStandardCds */ @GET @Path("/drives/standard/cd/list") @@ -85,7 +84,7 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture> listStandardCds(); /** - * @see ElasticStackClient#listStandardImages() + * @see CloudSigmaClient#listStandardImages */ @GET @Path("/drives/standard/img/list") @@ -103,18 +102,16 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { @MapPayloadParam("name") String newName, CloneDriveOptions... options); /** - * {@inheritDoc} + * @see CloudSigmaClient#listDriveInfo */ - @Override @GET @Path("/drives/info") @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class) - ListenableFuture> listDriveInfo(); + ListenableFuture> listDriveInfo(); /** - * {@inheritDoc} + * @see CloudSigmaClient#getDriveInfo */ - @Override @GET @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @@ -122,9 +119,8 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture getDriveInfo(@PathParam("uuid") String uuid); /** - * {@inheritDoc} + * @see CloudSigmaClient#createDrive */ - @Override @POST @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @@ -132,9 +128,8 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); /** - * {@inheritDoc} + * @see CloudSigmaClient#setDriveData */ - @Override @POST @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/{uuid}/set") @@ -142,9 +137,8 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { @BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive); /** - * {@inheritDoc} + * @see CloudSigmaClient#createServer */ - @Override @POST @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @@ -153,18 +147,16 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { @BinderParam(BindServerToPlainTextString.class) Server createServer); /** - * {@inheritDoc} + * @see CloudSigmaClient#listServerInfo */ - @Override @GET @Path("/servers/info") @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class) ListenableFuture> listServerInfo(); /** - * {@inheritDoc} + * @see CloudSigmaClient#getServerInfo */ - @Override @GET @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @@ -172,13 +164,72 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient { ListenableFuture getServerInfo(@PathParam("uuid") String uuid); /** - * {@inheritDoc} + * @see CloudSigmaClient#setServerConfiguration */ - @Override @POST @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @Path("/servers/{uuid}/set") ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, @BinderParam(BindServerToPlainTextString.class) Server setServer); + + /** + * @see CloudSigmaClient#listServers + */ + @GET + @Path("/servers/list") + @ResponseParser(SplitNewlines.class) + ListenableFuture> listServers(); + + /** + * @see CloudSigmaClient#destroyServer + */ + @POST + @Path("/servers/{uuid}/destroy") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture destroyServer(@PathParam("uuid") String uuid); + + /** + * @see CloudSigmaClient#startServer + */ + @POST + @Path("/servers/{uuid}/start") + ListenableFuture startServer(@PathParam("uuid") String uuid); + + /** + * @see CloudSigmaClient#stopServer + */ + @POST + @Path("/servers/{uuid}/stop") + ListenableFuture stopServer(@PathParam("uuid") String uuid); + + /** + * @see CloudSigmaClient#shutdownServer + */ + @POST + @Path("/servers/{uuid}/shutdown") + ListenableFuture shutdownServer(@PathParam("uuid") String uuid); + + /** + * @see CloudSigmaClient#resetServer + */ + @POST + @Path("/servers/{uuid}/reset") + ListenableFuture resetServer(@PathParam("uuid") String uuid); + + /** + * @see CloudSigmaClient#listDrives + */ + @GET + @Path("/drives/list") + @ResponseParser(SplitNewlines.class) + ListenableFuture> listDrives(); + + /** + * @see CloudSigmaClient#destroyDrive + */ + @POST + @Path("/drives/{uuid}/destroy") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture destroyDrive(@PathParam("uuid") String uuid); } diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java index 5ac74140ba..edd2a72197 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java @@ -25,20 +25,157 @@ import java.util.concurrent.TimeUnit; import org.jclouds.cloudsigma.domain.DriveInfo; import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.concurrent.Timeout; -import org.jclouds.elasticstack.CommonElasticStackClient; -import org.jclouds.elasticstack.domain.Drive; -import org.jclouds.elasticstack.domain.DriveData; +import org.jclouds.cloudsigma.domain.Drive; +import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.ServerInfo; /** * Provides synchronous access to CloudSigma. *

* * @see CloudSigmaAsyncClient - * @see + * @see * @author Adrian Cole */ @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) -public interface CloudSigmaClient extends CommonElasticStackClient { +public interface CloudSigmaClient { + /** + * list of server uuids in your account + * + * @return or empty set if no servers are found + */ + Set listServers(); + + /** + * Get all servers info + * + * @return or empty set if no servers are found + */ + Set listServerInfo(); + + /** + * @param uuid + * what to get + * @return null, if not found + */ + ServerInfo getServerInfo(String uuid); + + /** + * create a new server + * + * @param server + * @return newly created server + */ + ServerInfo createServer(Server server); + + /** + * set server configuration + * + * @param uuid + * what server to change + * @param serverData + * what values to change + * @return new data + */ + ServerInfo setServerConfiguration(String uuid, Server server); + + /** + * Destroy a server + * + * @param uuid + * what to destroy + */ + void destroyServer(String uuid); + + /** + * Start a server + * + * @param uuid + * what to start + */ + void startServer(String uuid); + + /** + * Stop a server + *

+ * Kills the server immediately, equivalent to a power failure. Server reverts to a stopped + * status if it is persistent and is automatically destroyed otherwise. + * + * @param uuid + * what to stop + */ + void stopServer(String uuid); + + /** + * Shutdown a server + *

+ * Sends the server an ACPI power-down event. Server reverts to a stopped status if it is + * persistent and is automatically destroyed otherwise. + *

note

behaviour on shutdown depends on how your server OS is set up to respond to an + * ACPI power button signal. + * + * @param uuid + * what to shutdown + */ + void shutdownServer(String uuid); + + /** + * Reset a server + * + * @param uuid + * what to reset + */ + void resetServer(String uuid); + + /** + * list of drive uuids in your account + * + * @return or empty set if no drives are found + */ + Set listDrives(); + + /** + * Get all drives info + * + * @return or empty set if no drives are found + */ + Set listDriveInfo(); + + /** + * @param uuid + * what to get + * @return null, if not found + */ + DriveInfo getDriveInfo(String uuid); + + /** + * create a new drive + * + * @param createDrive + * required parameters: name, size + * @return newly created drive + */ + DriveInfo createDrive(Drive createDrive); + + /** + * set extra drive data + * + * @param uuid + * what drive to change + * @param driveData + * what values to change + * @return new data + */ + DriveInfo setDriveData(String uuid, DriveData driveData); + + /** + * Destroy a drive + * + * @param uuid + * what to delete + */ + void destroyDrive(String uuid); /** * list of drive uuids that are in the library @@ -74,28 +211,5 @@ public interface CloudSigmaClient extends CommonElasticStackClient { */ DriveInfo cloneDrive(String sourceUuid, String newName, CloneDriveOptions... options); - /** - * {@inheritDoc} - */ - @Override - Set listDriveInfo(); - - /** - * {@inheritDoc} - */ - @Override - DriveInfo getDriveInfo(String uuid); - - /** - * {@inheritDoc} - */ - @Override - DriveInfo createDrive(Drive createDrive); - - /** - * {@inheritDoc} - */ - @Override - DriveInfo setDriveData(String uuid, DriveData driveData); } diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java index d1daf9bde5..4a38f0f2dd 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java @@ -19,8 +19,10 @@ package org.jclouds.cloudsigma; +import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.cloudsigma.reference.CloudSigmaConstants.PROPERTY_VNC_PASSWORD; import java.util.Properties; @@ -37,6 +39,7 @@ public class CloudSigmaPropertiesBuilder extends PropertiesBuilder { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_ENDPOINT, "https://api.cloudsigma.com"); properties.setProperty(PROPERTY_API_VERSION, "1.0"); + properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d"); return properties; } @@ -44,4 +47,11 @@ public class CloudSigmaPropertiesBuilder extends PropertiesBuilder { super(properties); } + @Override + public Properties build() { + Properties props = super.build(); + checkArgument(props.getProperty(PROPERTY_VNC_PASSWORD).length() <= 8, + "vnc passwords should be less that 8 characters!"); + return props; + } } diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java index 9cfb13b671..7614b0a7f8 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java @@ -31,7 +31,7 @@ import javax.ws.rs.core.MediaType; import org.jclouds.cloudsigma.CloudSigmaAsyncClient; import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.elasticstack.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; +import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; import org.jclouds.http.HttpRequest; import org.jclouds.rest.MapBinder; import org.jclouds.rest.internal.GeneratedHttpRequest; diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java new file mode 100644 index 0000000000..9f86bfcceb --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java @@ -0,0 +1,61 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.binders; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class BindDriveDataToPlainTextString implements Binder { + private final Function> createDriveRequestToMap; + private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; + + @Inject + public BindDriveDataToPlainTextString(Function> createDriveRequestToMap, + ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { + this.createDriveRequestToMap = createDriveRequestToMap; + this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; + } + + public void bindToRequest(HttpRequest request, Object payload) { + checkArgument(payload instanceof DriveData, "this binder is only valid for DriveData!"); + DriveData create = DriveData.class.cast(payload); + Map map = createDriveRequestToMap.apply(create); + request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); + request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); + } +} diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java new file mode 100644 index 0000000000..71d5627b1a --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java @@ -0,0 +1,61 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.binders; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudsigma.domain.Drive; +import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class BindDriveToPlainTextString implements Binder { + private final Function> createDriveRequestToMap; + private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; + + @Inject + public BindDriveToPlainTextString(Function> createDriveRequestToMap, + ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { + this.createDriveRequestToMap = createDriveRequestToMap; + this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; + } + + public void bindToRequest(HttpRequest request, Object payload) { + checkArgument(payload instanceof Drive, "this binder is only valid for Drive!"); + Drive create = Drive.class.cast(payload); + Map map = createDriveRequestToMap.apply(create); + request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); + request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); + } +} diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java new file mode 100644 index 0000000000..371b1858db --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java @@ -0,0 +1,61 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.binders; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class BindServerToPlainTextString implements Binder { + private final Function> createServerRequestToMap; + private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines; + + @Inject + public BindServerToPlainTextString(Function> createServerRequestToMap, + ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) { + this.createServerRequestToMap = createServerRequestToMap; + this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines; + } + + public void bindToRequest(HttpRequest request, Object payload) { + checkArgument(payload instanceof Server, "this binder is only valid for Server!"); + Server create = Server.class.cast(payload); + Map map = createServerRequestToMap.apply(create); + request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); + request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); + } +} diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java index c187dadc17..cdd01de601 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java @@ -24,22 +24,22 @@ import java.util.Map; import org.jclouds.cloudsigma.CloudSigmaAsyncClient; import org.jclouds.cloudsigma.CloudSigmaClient; -import org.jclouds.cloudsigma.functions.CreateDriveRequestToMap; +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.Drive; +import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.domain.DriveMetrics; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.ServerMetrics; +import org.jclouds.cloudsigma.functions.BaseDriveToMap; import org.jclouds.cloudsigma.functions.DriveDataToMap; +import org.jclouds.cloudsigma.functions.MapToDevices; +import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; +import org.jclouds.cloudsigma.functions.MapToDriveMetrics; +import org.jclouds.cloudsigma.functions.MapToNICs; +import org.jclouds.cloudsigma.functions.MapToServerMetrics; import org.jclouds.cloudsigma.functions.ServerToMap; -import org.jclouds.elasticstack.domain.Device; -import org.jclouds.elasticstack.domain.Drive; -import org.jclouds.elasticstack.domain.DriveData; -import org.jclouds.elasticstack.domain.DriveMetrics; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.ServerMetrics; -import org.jclouds.elasticstack.functions.MapToDevices; -import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; -import org.jclouds.elasticstack.functions.MapToDriveMetrics; -import org.jclouds.elasticstack.functions.MapToNICs; -import org.jclouds.elasticstack.functions.MapToServerMetrics; -import org.jclouds.elasticstack.handlers.ElasticStackErrorHandler; +import org.jclouds.cloudsigma.handlers.CloudSigmaErrorHandler; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.RequiresHttp; import org.jclouds.http.annotation.ClientError; @@ -66,16 +66,16 @@ public class CloudSigmaRestClientModule extends RestClientModule>>() { - }).to(CreateDriveRequestToMap.class); + }).to(BaseDriveToMap.class); bind(new TypeLiteral>>() { }).to(DriveDataToMap.class); bind(new TypeLiteral, List>>() { diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java new file mode 100644 index 0000000000..42ae17cb78 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java @@ -0,0 +1,86 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * + * @author Adrian Cole + */ +public class BlockDevice extends Device { + public static class Builder extends Device.Builder { + private final int index; + + public Builder(int index) { + this.index = index; + } + + @Override + public Device build() { + return new BlockDevice(uuid, mediaType, index); + } + + } + + private final int index; + + public BlockDevice(String driveUuid, MediaType mediaType, int index) { + super(driveUuid, mediaType); + checkArgument(index >= 0 && index < 8, "index must be between 0 and 7"); + this.index = index; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + index; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BlockDevice other = (BlockDevice) obj; + if (index != other.index) + return false; + return true; + } + + @Override + public String getId() { + return String.format("block:%d", index); + } + + public int getIndex() { + return index; + } + + @Override + public String toString() { + return "[id=" + getId() + ", driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]"; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java new file mode 100644 index 0000000000..ccaa572ba1 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java @@ -0,0 +1,57 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * either 'exclusive' (the default) or 'shared' to allow multiple servers to access a drive + * simultaneously + * + * @author Adrian Cole + */ +public enum ClaimType { + /** + * + */ + EXCLUSIVE, + /** + * allow multiple servers to access a drive simultaneously + */ + SHARED, UNRECOGNIZED; + + public String value() { + return name().toLowerCase(); + } + + @Override + public String toString() { + return value(); + } + + public static ClaimType fromValue(String claim) { + try { + return valueOf(checkNotNull(claim, "claim").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java new file mode 100644 index 0000000000..4f3987de66 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java @@ -0,0 +1,162 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +public class CreateDriveRequest extends Drive { + public static class Builder extends Drive.Builder { + + private Set avoid = ImmutableSet.of(); + + @Nullable + private String encryptionCipher; + + public Builder avoid(Iterable avoid) { + this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid")); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder claimType(ClaimType claimType) { + return Builder.class.cast(super.claimType(claimType)); + } + + public Builder encryptionCipher(String encryptionCipher) { + this.encryptionCipher = encryptionCipher; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder readers(Iterable readers) { + return Builder.class.cast(super.readers(readers)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder size(long size) { + return Builder.class.cast(super.size(size)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder use(Iterable use) { + return Builder.class.cast(super.use(use)); + } + + public CreateDriveRequest build() { + return new CreateDriveRequest(name, size, claimType, readers, use, encryptionCipher, avoid); + } + } + + private final Set avoid; + @Nullable + private final String encryptionCipher; + + public CreateDriveRequest(String name, long size, @Nullable ClaimType claimType, Iterable readers, + Iterable use, @Nullable String encryptionCipher, Iterable avoid) { + super(null, name, size, claimType, readers, use); + this.encryptionCipher = encryptionCipher; + this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid")); + } + + /** + * + * @return list of existing drives to ensure this new drive is created on physical different + * hardware than those existing drives + */ + public Set getAvoid() { + return avoid; + } + + /** + * + * @return either 'none' or 'aes-xts-plain' (the default) + */ + @Nullable + public String getEncryptionCipher() { + return encryptionCipher; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((avoid == null) ? 0 : avoid.hashCode()); + result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + CreateDriveRequest other = (CreateDriveRequest) obj; + if (avoid == null) { + if (other.avoid != null) + return false; + } else if (!avoid.equals(other.avoid)) + return false; + if (encryptionCipher == null) { + if (other.encryptionCipher != null) + return false; + } else if (!encryptionCipher.equals(other.encryptionCipher)) + return false; + return true; + } + + @Override + public String toString() { + return "[name=" + name + ", size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", use=" + use + + ", avoid=" + avoid + ", encryptionCipher=" + encryptionCipher + "]"; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Device.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Device.java new file mode 100644 index 0000000000..13a45b996b --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Device.java @@ -0,0 +1,108 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Adrian Cole + */ +public abstract class Device { + public static abstract class Builder { + protected String uuid; + protected MediaType mediaType = MediaType.DISK; + + public Builder mediaType(MediaType mediaType) { + this.mediaType = mediaType; + return this; + } + + public Builder uuid(String uuid) { + this.uuid = uuid; + return this; + } + + public abstract Device build(); + } + + protected final String driveUuid; + protected final MediaType mediaType; + + public Device(String driveUuid, MediaType mediaType) { + this.driveUuid = checkNotNull(driveUuid, "driveUuid"); + this.mediaType = checkNotNull(mediaType, "mediaType"); + } + + /** + * id generated based on the device bus, unit, and/or index numbers; + */ + public abstract String getId(); + + /** + * + * @return Drive UUID to connect as specified device. + */ + public String getDriveUuid() { + return driveUuid; + } + + /** + * + * @return set to 'cdrom' to simulate a cdrom, set to 'disk' or leave unset to simulate a hard + * disk. + */ + public MediaType getMediaType() { + return mediaType; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((driveUuid == null) ? 0 : driveUuid.hashCode()); + result = prime * result + ((mediaType == null) ? 0 : mediaType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Device other = (Device) obj; + if (driveUuid == null) { + if (other.driveUuid != null) + return false; + } else if (!driveUuid.equals(other.driveUuid)) + return false; + if (mediaType != other.mediaType) + return false; + return true; + } + + @Override + public String toString() { + return "[driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]"; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Drive.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Drive.java new file mode 100644 index 0000000000..2b19a03fa4 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Drive.java @@ -0,0 +1,203 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +public class Drive extends Item { + public static class Builder extends Item.Builder { + protected long size; + protected ClaimType claimType = ClaimType.EXCLUSIVE; + protected Set readers = ImmutableSet.of(); + + public Builder claimType(ClaimType claimType) { + this.claimType = claimType; + return this; + } + + public Builder readers(Iterable readers) { + this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers")); + return this; + } + + public Builder size(long size) { + this.size = size; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder uuid(String uuid) { + return Builder.class.cast(super.uuid(uuid)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder use(Iterable use) { + return Builder.class.cast(super.use(use)); + } + + public Drive build() { + return new Drive(uuid, name, size, claimType, readers, use); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((claimType == null) ? 0 : claimType.hashCode()); + result = prime * result + ((readers == null) ? 0 : readers.hashCode()); + result = prime * result + (int) (size ^ (size >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + Builder other = (Builder) obj; + if (claimType != other.claimType) + return false; + if (readers == null) { + if (other.readers != null) + return false; + } else if (!readers.equals(other.readers)) + return false; + if (size != other.size) + return false; + return true; + } + } + + protected final long size; + protected final ClaimType claimType; + protected final Set readers; + + public Drive(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType, Iterable readers, + Iterable use) { + super(uuid, name, use); + this.size = size; + this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null"); + this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers")); + } + + /** + * + * @return either 'exclusive' (the default) or 'shared' to allow multiple servers to access a + * drive simultaneously + */ + @Nullable + public ClaimType getClaimType() { + return claimType; + } + + /** + * + * @return list of users allowed to read from a drive or 'ffffffff-ffff-ffff-ffff-ffffffffffff' + * for all users + */ + public Set getReaders() { + return readers; + } + + /** + * + * @return size of drive in bytes + */ + public long getSize() { + return size; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((claimType == null) ? 0 : claimType.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((readers == null) ? 0 : readers.hashCode()); + result = prime * result + (int) (size ^ (size >>> 32)); + result = prime * result + ((use == null) ? 0 : use.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Drive other = (Drive) obj; + if (claimType != other.claimType) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (readers == null) { + if (other.readers != null) + return false; + } else if (!readers.equals(other.readers)) + return false; + if (size != other.size) + return false; + if (use == null) { + if (other.use != null) + return false; + } else if (!use.equals(other.use)) + return false; + return true; + } + + @Override + public String toString() { + return "[uuid=" + uuid + ", name=" + name + ", use=" + use + ", size=" + size + ", claimType=" + claimType + + ", readers=" + readers + "]"; + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java new file mode 100644 index 0000000000..4504f5f4f7 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java @@ -0,0 +1,80 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import javax.annotation.Nullable; + +/** + * + * @author Adrian Cole + */ +public class DriveData extends Drive { + public static class Builder extends Drive.Builder { + + /** + * {@inheritDoc} + */ + @Override + public Builder claimType(ClaimType claimType) { + return Builder.class.cast(super.claimType(claimType)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder readers(Iterable readers) { + return Builder.class.cast(super.readers(readers)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder size(long size) { + return Builder.class.cast(super.size(size)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder use(Iterable use) { + return Builder.class.cast(super.use(use)); + } + + public DriveData build() { + return new DriveData(uuid, name, size, claimType, readers, use); + } + } + + public DriveData(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType, + Iterable readers, Iterable use) { + super(uuid, name, size, claimType, readers, use); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java index ddec88deac..9792cf65e8 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java @@ -22,12 +22,9 @@ package org.jclouds.cloudsigma.domain; import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; -import java.util.Map; import java.util.Set; -import org.jclouds.elasticstack.domain.ClaimType; -import org.jclouds.elasticstack.domain.DriveMetrics; -import org.jclouds.elasticstack.domain.DriveStatus; +import javax.annotation.Nullable; import com.google.common.collect.ImmutableSet; @@ -35,8 +32,17 @@ import com.google.common.collect.ImmutableSet; * * @author Adrian Cole */ -public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo { - public static class Builder extends org.jclouds.elasticstack.domain.DriveInfo.Builder { +public class DriveInfo extends Drive { + public static class Builder extends Drive.Builder { + + protected DriveStatus status; + protected String user; + protected Set claimed = ImmutableSet.of(); + @Nullable + protected String encryptionCipher; + @Nullable + protected String imaging; + protected DriveMetrics metrics; private Boolean autoexpanding; private Integer bits; private String description; @@ -48,6 +54,36 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo { private DriveType type; private URI url; + public Builder status(DriveStatus status) { + this.status = status; + return this; + } + + public Builder user(String user) { + this.user = user; + return this; + } + + public Builder claimed(Iterable claimed) { + this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed")); + return this; + } + + public Builder imaging(String imaging) { + this.imaging = imaging; + return this; + } + + public Builder metrics(DriveMetrics metrics) { + this.metrics = metrics; + return this; + } + + public Builder encryptionCipher(String encryptionCipher) { + this.encryptionCipher = encryptionCipher; + return this; + } + public Builder autoexpanding(Boolean autoexpanding) { this.autoexpanding = autoexpanding; return this; @@ -98,55 +134,6 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo { return this; } - /** - * {@inheritDoc} - */ - @Override - public Builder status(DriveStatus status) { - return Builder.class.cast(super.status(status)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder user(String user) { - return Builder.class.cast(super.user(user)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder claimed(Iterable claimed) { - return Builder.class.cast(super.claimed(claimed)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder imaging(String imaging) { - return Builder.class.cast(super.imaging(imaging)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder metrics(DriveMetrics metrics) { - return Builder.class.cast(super.metrics(metrics)); - - } - - /** - * {@inheritDoc} - */ - @Override - public Builder encryptionCipher(String encryptionCipher) { - return Builder.class.cast(super.encryptionCipher(encryptionCipher)); - } - /** * {@inheritDoc} */ @@ -191,24 +178,17 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo { * {@inheritDoc} */ @Override - public Builder tags(Iterable tags) { - return Builder.class.cast(super.tags(tags)); + public Builder use(Iterable use) { + return Builder.class.cast(super.use(use)); } - /** - * {@inheritDoc} - */ - @Override - public Builder userMetadata(Map userMetadata) { - return Builder.class.cast(super.userMetadata(userMetadata)); - } - - public static Builder fromDriveInfo(org.jclouds.elasticstack.domain.DriveInfo driveInfo) { - return new Builder().uuid(driveInfo.getUuid()).name(driveInfo.getName()).size(driveInfo.getSize()) - .claimType(driveInfo.getClaimType()).readers(driveInfo.getReaders()).tags(driveInfo.getTags()) - .userMetadata(driveInfo.getUserMetadata()).status(driveInfo.getStatus()).user(driveInfo.getUser()) - .claimed(driveInfo.getClaimed()).encryptionCipher(driveInfo.getEncryptionCipher()) - .imaging(driveInfo.getImaging()).metrics(driveInfo.getMetrics()); + public static Builder fromDriveInfo(DriveInfo in) { + return new Builder().uuid(in.getUuid()).name(in.getName()).size(in.getSize()).claimType(in.getClaimType()) + .readers(in.getReaders()).use(in.getUse()).status(in.getStatus()).user(in.getUser()) + .claimed(in.getClaimed()).encryptionCipher(in.getEncryptionCipher()).imaging(in.getImaging()) + .metrics(in.getMetrics()).autoexpanding(in.getAutoexpanding()).bits(in.getBits()) + .description(in.getDescription()).encryptionKey(in.getEncryptionKey()).free(in.getFree()) + .installNotes(in.getInstallNotes()).type(in.getType()).url(in.getUrl()); } /** @@ -216,12 +196,21 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo { */ @Override public DriveInfo build() { - return new DriveInfo(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed, - encryptionCipher, imaging, metrics, autoexpanding, bits, description, driveType, encryptionKey, free, - installNotes, os, type, url); + return new DriveInfo(uuid, name, size, claimType, readers, use, status, user, claimed, encryptionCipher, + imaging, metrics, autoexpanding, bits, description, driveType, encryptionKey, free, installNotes, os, + type, url); } + } + protected final DriveStatus status; + protected final String user; + protected final Set claimed; + @Nullable + protected final String encryptionCipher; + @Nullable + protected final String imaging; + protected final DriveMetrics metrics; private final Boolean autoexpanding; private final Integer bits; private final String description; @@ -234,12 +223,17 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo { private final URI url; public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable readers, - Iterable tags, Map userMetadata, DriveStatus status, String user, Set claimed, - String encryptionCipher, String imaging, DriveMetrics metrics, Boolean autoexpanding, Integer bits, - String description, Iterable driveType, String encryptionKey, Boolean free, String installNotes, - String os, DriveType type, URI url) { - super(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed, encryptionCipher, imaging, - metrics); + Iterable use, DriveStatus status, String user, Set claimed, String encryptionCipher, + String imaging, DriveMetrics metrics, Boolean autoexpanding, Integer bits, String description, + Iterable driveType, String encryptionKey, Boolean free, String installNotes, String os, + DriveType type, URI url) { + super(uuid, name, size, claimType, readers, use); + this.status = status; + this.user = user; + this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed")); + this.encryptionCipher = encryptionCipher; + this.imaging = imaging; + this.metrics = checkNotNull(metrics, "metrics"); this.autoexpanding = autoexpanding; this.bits = bits; this.description = description; @@ -252,80 +246,54 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo { this.url = url; } - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((autoexpanding == null) ? 0 : autoexpanding.hashCode()); - result = prime * result + ((bits == null) ? 0 : bits.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((driveType == null) ? 0 : driveType.hashCode()); - result = prime * result + ((encryptionKey == null) ? 0 : encryptionKey.hashCode()); - result = prime * result + ((free == null) ? 0 : free.hashCode()); - result = prime * result + ((installNotes == null) ? 0 : installNotes.hashCode()); - result = prime * result + ((os == null) ? 0 : os.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - result = prime * result + ((url == null) ? 0 : url.hashCode()); - return result; + /** + * + * @return current status of the drive + */ + public DriveStatus getStatus() { + return status; } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - DriveInfo other = (DriveInfo) obj; - if (autoexpanding == null) { - if (other.autoexpanding != null) - return false; - } else if (!autoexpanding.equals(other.autoexpanding)) - return false; - if (bits == null) { - if (other.bits != null) - return false; - } else if (!bits.equals(other.bits)) - return false; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; - if (driveType == null) { - if (other.driveType != null) - return false; - } else if (!driveType.equals(other.driveType)) - return false; - if (encryptionKey == null) { - if (other.encryptionKey != null) - return false; - } else if (!encryptionKey.equals(other.encryptionKey)) - return false; - if (free == null) { - if (other.free != null) - return false; - } else if (!free.equals(other.free)) - return false; - if (installNotes == null) { - if (other.installNotes != null) - return false; - } else if (!installNotes.equals(other.installNotes)) - return false; - if (os == null) { - if (other.os != null) - return false; - } else if (!os.equals(other.os)) - return false; - if (type != other.type) - return false; - if (url == null) { - if (other.url != null) - return false; - } else if (!url.equals(other.url)) - return false; - return true; + /** + * + * @return owner of the drive + */ + public String getUser() { + return user; + } + + /** + * + * @return if drive is in use by a server, values are the server uuids + */ + public Set getClaimed() { + return claimed; + } + + /** + * + * @return either 'none' or 'aes-xts-plain' (the default) + */ + @Nullable + public String getEncryptionCipher() { + return encryptionCipher; + } + + /** + * + * @return percentage completed of drive imaging if this is underway, or 'queued' if waiting for + * another imaging operation to complete first + */ + public String getImaging() { + return imaging; + } + + /** + * + * @return i/o and request metrics for read and write ops + */ + public DriveMetrics getMetrics() { + return metrics; } // TODO @@ -373,19 +341,124 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo { return type; } - // TODO - - @Override - public String toString() { - return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name=" - + name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", autoexpanding=" + autoexpanding - + ", bits=" + bits + ", description=" + description + ", driveType=" + driveType + ", encryptionKey=" - + encryptionKey + ", free=" + free + ", installNotes=" + installNotes + ", os=" + os + ", type=" + type - + ", url=" + url + "]"; - } - public URI getUrl() { return url; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((autoexpanding == null) ? 0 : autoexpanding.hashCode()); + result = prime * result + ((bits == null) ? 0 : bits.hashCode()); + result = prime * result + ((claimed == null) ? 0 : claimed.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((driveType == null) ? 0 : driveType.hashCode()); + result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode()); + result = prime * result + ((encryptionKey == null) ? 0 : encryptionKey.hashCode()); + result = prime * result + ((free == null) ? 0 : free.hashCode()); + result = prime * result + ((imaging == null) ? 0 : imaging.hashCode()); + result = prime * result + ((installNotes == null) ? 0 : installNotes.hashCode()); + result = prime * result + ((metrics == null) ? 0 : metrics.hashCode()); + result = prime * result + ((os == null) ? 0 : os.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((url == null) ? 0 : url.hashCode()); + result = prime * result + ((user == null) ? 0 : user.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + DriveInfo other = (DriveInfo) obj; + if (autoexpanding == null) { + if (other.autoexpanding != null) + return false; + } else if (!autoexpanding.equals(other.autoexpanding)) + return false; + if (bits == null) { + if (other.bits != null) + return false; + } else if (!bits.equals(other.bits)) + return false; + if (claimed == null) { + if (other.claimed != null) + return false; + } else if (!claimed.equals(other.claimed)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (driveType == null) { + if (other.driveType != null) + return false; + } else if (!driveType.equals(other.driveType)) + return false; + if (encryptionCipher == null) { + if (other.encryptionCipher != null) + return false; + } else if (!encryptionCipher.equals(other.encryptionCipher)) + return false; + if (encryptionKey == null) { + if (other.encryptionKey != null) + return false; + } else if (!encryptionKey.equals(other.encryptionKey)) + return false; + if (free == null) { + if (other.free != null) + return false; + } else if (!free.equals(other.free)) + return false; + if (imaging == null) { + if (other.imaging != null) + return false; + } else if (!imaging.equals(other.imaging)) + return false; + if (installNotes == null) { + if (other.installNotes != null) + return false; + } else if (!installNotes.equals(other.installNotes)) + return false; + if (metrics == null) { + if (other.metrics != null) + return false; + } else if (!metrics.equals(other.metrics)) + return false; + if (os == null) { + if (other.os != null) + return false; + } else if (!os.equals(other.os)) + return false; + if (status != other.status) + return false; + if (type != other.type) + return false; + if (url == null) { + if (other.url != null) + return false; + } else if (!url.equals(other.url)) + return false; + if (user == null) { + if (other.user != null) + return false; + } else if (!user.equals(other.user)) + return false; + return true; + } + + @Override + public String toString() { + return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name=" + + name + ", use=" + use + ", status=" + status + ", user=" + user + ", claimed=" + claimed + + ", encryptionCipher=" + encryptionCipher + ", imaging=" + imaging + ", metrics=" + metrics + "]"; + } + } \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java new file mode 100644 index 0000000000..f3f69eda6f --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java @@ -0,0 +1,139 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + + +/** + * + * @author Adrian Cole + */ +public class DriveMetrics { + public static class Builder { + protected long readBytes; + protected long readRequests; + protected long writeBytes; + protected long writeRequests; + + public Builder readBytes(long readBytes) { + this.readBytes = readBytes; + return this; + } + + public Builder readRequests(long readRequests) { + this.readRequests = readRequests; + return this; + } + + public Builder writeBytes(long writeBytes) { + this.writeBytes = writeBytes; + return this; + } + + public Builder writeRequests(long writeRequests) { + this.writeRequests = writeRequests; + return this; + } + + public DriveMetrics build() { + return new DriveMetrics(readBytes, readRequests, writeBytes, writeRequests); + } + } + + protected final long readBytes; + protected final long readRequests; + protected final long writeBytes; + protected final long writeRequests; + + public DriveMetrics(long readBytes, long readRequests, long writeBytes, long writeRequests) { + this.readBytes = readBytes; + this.readRequests = readRequests; + this.writeBytes = writeBytes; + this.writeRequests = writeRequests; + } + + /** + * + * @return Cumulative i/o byte/request count for each drive + */ + public long getReadBytes() { + return readBytes; + } + + /** + * + * @return Cumulative i/o byte/request count for each drive + */ + public long getReadRequests() { + return readRequests; + } + + /** + * + * @return Cumulative i/o byte/request count for each drive + */ + public long getWriteBytes() { + return writeBytes; + } + + /** + * + * @return Cumulative i/o byte/request count for each drive + */ + public long getWriteRequests() { + return writeRequests; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (readBytes ^ (readBytes >>> 32)); + result = prime * result + (int) (readRequests ^ (readRequests >>> 32)); + result = prime * result + (int) (writeBytes ^ (writeBytes >>> 32)); + result = prime * result + (int) (writeRequests ^ (writeRequests >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DriveMetrics other = (DriveMetrics) obj; + if (readBytes != other.readBytes) + return false; + if (readRequests != other.readRequests) + return false; + if (writeBytes != other.writeBytes) + return false; + if (writeRequests != other.writeRequests) + return false; + return true; + } + + @Override + public String toString() { + return "[readBytes=" + readBytes + ", readRequests=" + readRequests + ", writeBytes=" + writeBytes + + ", writeRequests=" + writeRequests + "]"; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java new file mode 100644 index 0000000000..20b47fe597 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java @@ -0,0 +1,48 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Adrian Cole + */ +public enum DriveStatus { + ACTIVE, INACTIVE, COPYING, IMAGING, UNRECOGNIZED; + + public String value() { + return name().toLowerCase(); + } + + @Override + public String toString() { + return value(); + } + + public static DriveStatus fromValue(String status) { + try { + return valueOf(checkNotNull(status, "status").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java new file mode 100644 index 0000000000..8dc328a3ea --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java @@ -0,0 +1,98 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * + * @author Adrian Cole + */ +public class IDEDevice extends Device { + public static class Builder extends Device.Builder { + private final int bus; + private final int unit; + + public Builder(int bus, int unit) { + this.bus = bus; + this.unit = unit; + } + + @Override + public Device build() { + return new IDEDevice(uuid, mediaType, bus, unit); + } + + } + + private final int bus; + private final int unit; + + public IDEDevice(String driveUuid, MediaType mediaType, int bus, int unit) { + super(driveUuid, mediaType); + checkArgument(bus == 0 || bus == 1, "bus must be 0 or 1"); + checkArgument(unit == 0 || unit == 1, "unit must be 0 or 1"); + this.bus = bus; + this.unit = unit; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + bus; + result = prime * result + unit; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IDEDevice other = (IDEDevice) obj; + if (bus != other.bus) + return false; + if (unit != other.unit) + return false; + return true; + } + + @Override + public String getId() { + return String.format("ide:%d:%d", bus, unit); + } + + public int getBus() { + return bus; + } + + public int getUnit() { + return unit; + } + + @Override + public String toString() { + return "[id=" + getId() + ", driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]"; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Item.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Item.java new file mode 100644 index 0000000000..ead2748e01 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Item.java @@ -0,0 +1,170 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +public class Item { + public static class Builder { + protected String uuid; + protected String name; + protected Set use = ImmutableSet.of(); + + public Builder uuid(String uuid) { + this.uuid = uuid; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder use(Iterable use) { + this.use = ImmutableSet.copyOf(checkNotNull(use, "use")); + return this; + } + + public Item build() { + return new Item(uuid, name, use); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((use == null) ? 0 : use.hashCode()); + result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Builder other = (Builder) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (use == null) { + if (other.use != null) + return false; + } else if (!use.equals(other.use)) + return false; + if (uuid == null) { + if (other.uuid != null) + return false; + } else if (!uuid.equals(other.uuid)) + return false; + return true; + } + } + + @Nullable + protected final String uuid; + protected final String name; + protected final Set use; + + public Item(@Nullable String uuid, String name, Iterable use) { + this.uuid = uuid; + this.name = checkNotNull(name, "name"); + this.use = ImmutableSet.copyOf(checkNotNull(use, "use")); + } + + /** + * + * @return uuid of the item. + */ + @Nullable + public String getUuid() { + return uuid; + } + + /** + * + * @return name of the item + */ + public String getName() { + return name; + } + + /** + * + * @return list of use + */ + public Set getUse() { + return use; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((use == null) ? 0 : use.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Item other = (Item) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (use == null) { + if (other.use != null) + return false; + } else if (!use.equals(other.use)) + return false; + + return true; + } + + @Override + public String toString() { + return "[uuid=" + uuid + ", name=" + name + ", use=" + use + "]"; + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java new file mode 100644 index 0000000000..4fd67bb459 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java @@ -0,0 +1,50 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Media type - set to 'cdrom' to simulate a cdrom, set to 'disk' or leave unset to simulate a hard + * disk. + * + * @author Adrian Cole + */ +public enum MediaType { + DISK, CDROM, UNRECOGNIZED; + + public String value() { + return name().toLowerCase(); + } + + @Override + public String toString() { + return value(); + } + + public static MediaType fromValue(String type) { + try { + return valueOf(checkNotNull(type, "type").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Model.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Model.java new file mode 100644 index 0000000000..cbec34277b --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Model.java @@ -0,0 +1,47 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Adrian Cole + */ +public enum Model { + E1000, RTl8139, VIRTIO, UNRECOGNIZED; + + public String value() { + return name().toLowerCase(); + } + + @Override + public String toString() { + return value(); + } + + public static Model fromValue(String model) { + try { + return valueOf(checkNotNull(model, "model").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/NIC.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/NIC.java new file mode 100644 index 0000000000..f19f3d3259 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/NIC.java @@ -0,0 +1,177 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +public class NIC { + public static class Builder { + private String dhcp; + private Model model; + private String vlan; + private String mac; + // TODO cloudsigma specific + private Set block = ImmutableSet.of(); + + public Builder dhcp(String dhcp) { + this.dhcp = dhcp; + return this; + } + + public Builder model(Model model) { + this.model = model; + return this; + } + + public Builder vlan(String vlan) { + this.vlan = vlan; + return this; + } + + public Builder mac(String mac) { + this.mac = mac; + return this; + } + + public Builder block(Iterable block) { + this.block = ImmutableSet.copyOf(checkNotNull(block, "block")); + return this; + } + + public NIC build() { + return new NIC(dhcp, model, vlan, mac, block); + } + } + + private final String dhcp; + private final Model model; + private final String vlan; + private final String mac; + private final Set block; + + public NIC(@Nullable String dhcp, Model model, @Nullable String vlan, @Nullable String mac, Iterable block) { + this.dhcp = dhcp; + this.model = checkNotNull(model, "model"); + this.vlan = vlan; + this.mac = mac; + this.block = ImmutableSet.copyOf(checkNotNull(block, "block")); + } + + /** + * + * @return The IP address offered by DHCP to network interface 0. If unset, no address is + * offered. Set to 'auto' to allocate a temporary IP at boot. + */ + public String getDhcp() { + return dhcp; + } + + /** + * + * @return Create network interface with given type (use 'e1000' as default value; 'rtl8139' or + * 'virtio' are also available). + */ + public Model getModel() { + return model; + } + + /** + * + * @return The VLAN to which the network interface is attached. + */ + public String getVlan() { + return vlan; + } + + /** + * + * @return The MAC address of the network interface. If unset, a randomly generated address is + * used. If set, should be unique on the VLAN. + */ + public String getMac() { + return mac; + } + + // TODO undocumented + public Set getBlock() { + return block; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((block == null) ? 0 : block.hashCode()); + result = prime * result + ((dhcp == null) ? 0 : dhcp.hashCode()); + result = prime * result + ((mac == null) ? 0 : mac.hashCode()); + result = prime * result + ((model == null) ? 0 : model.hashCode()); + result = prime * result + ((vlan == null) ? 0 : vlan.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NIC other = (NIC) obj; + if (block == null) { + if (other.block != null) + return false; + } else if (!block.equals(other.block)) + return false; + if (dhcp == null) { + if (other.dhcp != null) + return false; + } else if (!dhcp.equals(other.dhcp)) + return false; + if (mac == null) { + if (other.mac != null) + return false; + } else if (!mac.equals(other.mac)) + return false; + if (model != other.model) + return false; + if (vlan == null) { + if (other.vlan != null) + return false; + } else if (!vlan.equals(other.vlan)) + return false; + return true; + } + + @Override + public String toString() { + return "[dhcp=" + dhcp + ", model=" + model + ", vlan=" + vlan + ", mac=" + mac + ", block=" + block + "]"; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java new file mode 100644 index 0000000000..aad202cc56 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java @@ -0,0 +1,94 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * + * @author Adrian Cole + */ +public class SCSIDevice extends Device { + public static class Builder extends Device.Builder { + private final int unit; + + public Builder(int unit) { + this.unit = unit; + } + + @Override + public Device build() { + return new SCSIDevice(uuid, mediaType, unit); + } + + } + + private final int bus = 0; + private final int unit; + + public SCSIDevice(String driveUuid, MediaType mediaType, int unit) { + super(driveUuid, mediaType); + checkArgument(unit >= 0 && unit < 8, "unit must be between 0 and 7"); + this.unit = unit; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + bus; + result = prime * result + unit; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SCSIDevice other = (SCSIDevice) obj; + if (bus != other.bus) + return false; + if (unit != other.unit) + return false; + return true; + } + + public int getBus() { + return bus; + } + + public int getUnit() { + return unit; + } + + @Override + public String getId() { + return String.format("scsi:%d:%d", bus, unit); + } + + @Override + public String toString() { + return "[id=" + getId() + ", driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]"; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Server.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Server.java new file mode 100644 index 0000000000..87e026f00c --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Server.java @@ -0,0 +1,293 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +public class Server extends Item { + + public static class Builder extends Item.Builder { + protected int cpu; + protected Integer smp; + protected int mem; + protected boolean persistent; + protected Map devices = ImmutableMap.of(); + protected Set bootDeviceIds = ImmutableSet.of(); + protected List nics = ImmutableList.of(); + protected VNC vnc; + // TODO cloudsigma specific + protected String description; + + public Builder cpu(int cpu) { + this.cpu = cpu; + return this; + } + + public Builder smp(Integer smp) { + this.smp = smp; + return this; + } + + public Builder mem(int mem) { + this.mem = mem; + return this; + } + + public Builder persistent(boolean persistent) { + this.persistent = persistent; + return this; + } + + public Builder devices(Map devices) { + this.devices = ImmutableMap.copyOf(checkNotNull(devices, "devices")); + return this; + } + + public Builder bootDeviceIds(Iterable bootDeviceIds) { + this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds")); + return this; + } + + public Builder nics(Iterable nics) { + this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics")); + return this; + } + + public Builder vnc(VNC vnc) { + this.vnc = vnc; + return this; + } + + public Builder description(String description) { + this.description = description; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder uuid(String uuid) { + return Builder.class.cast(super.uuid(uuid)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder use(Iterable use) { + return Builder.class.cast(super.use(use)); + } + + public Server build() { + return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, use, nics, vnc, description); + } + + public static Builder fromServer(Server in) { + return new Builder().uuid(in.getUuid()).name(in.getName()).cpu(in.getCpu()).mem(in.getMem()) + .persistent(in.isPersistent()).description(in.getDescription()).devices(in.getDevices()) + .bootDeviceIds(in.getBootDeviceIds()).use(in.getUse()).nics(in.getNics()).vnc(in.getVnc()); + } + } + + protected final int cpu; + protected final Integer smp; + protected final int mem; + protected final boolean persistent; + @Nullable + protected final Map devices; + protected final Set bootDeviceIds; + protected final List nics; + protected final VNC vnc; + @Nullable + private final String description; + + public Server(@Nullable String uuid, String name, int cpu, @Nullable Integer smp, int mem, boolean persistent, + Map devices, Iterable bootDeviceIds, Iterable use, + Iterable nics, VNC vnc, String description) { + super(uuid, name, use); + this.cpu = cpu; + this.smp = smp; + this.mem = mem; + this.persistent = persistent; + this.devices = ImmutableMap.copyOf(checkNotNull(devices, "devices")); + this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds")); + this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics")); + this.vnc = checkNotNull(vnc, "vnc"); + this.description = description; + } + + /** + * + * @return CPU quota in core MHz. + */ + public int getCpu() { + return cpu; + } + + /** + * + * @return number of virtual processors or null if calculated based on cpu. + */ + public Integer getSmp() { + return smp; + } + + /** + * + * @return virtual memory size in MB. + */ + public int getMem() { + return mem; + } + + /** + * + * @return 'true' means that server will revert to a 'stopped' status on server stop or shutdown, + * rather than being destroyed automatically. + */ + public boolean isPersistent() { + return persistent; + } + + /** + * + * @return devices present, mapped by id + */ + public Map getDevices() { + return devices; + } + + /** + * + * @return ids of the devices to boot, e.g. ide:0:0 or ide:1:0 + * @see Device#getId() + */ + public Set getBootDeviceIds() { + return bootDeviceIds; + } + + public List getNics() { + return nics; + } + + public VNC getVnc() { + return vnc; + } + + // TODO undocumented + public String getDescription() { + return description; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((bootDeviceIds == null) ? 0 : bootDeviceIds.hashCode()); + result = prime * result + cpu; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((devices == null) ? 0 : devices.hashCode()); + result = prime * result + mem; + result = prime * result + ((nics == null) ? 0 : nics.hashCode()); + result = prime * result + (persistent ? 1231 : 1237); + result = prime * result + ((smp == null) ? 0 : smp.hashCode()); + result = prime * result + ((vnc == null) ? 0 : vnc.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + Server other = (Server) obj; + if (bootDeviceIds == null) { + if (other.bootDeviceIds != null) + return false; + } else if (!bootDeviceIds.equals(other.bootDeviceIds)) + return false; + if (cpu != other.cpu) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (devices == null) { + if (other.devices != null) + return false; + } else if (!devices.equals(other.devices)) + return false; + if (mem != other.mem) + return false; + if (nics == null) { + if (other.nics != null) + return false; + } else if (!nics.equals(other.nics)) + return false; + if (persistent != other.persistent) + return false; + if (smp == null) { + if (other.smp != null) + return false; + } else if (!smp.equals(other.smp)) + return false; + if (vnc == null) { + if (other.vnc != null) + return false; + } else if (!vnc.equals(other.vnc)) + return false; + return true; + } + + @Override + public String toString() { + return "[uuid=" + uuid + ", name=" + name + ", use=" + use + ", cpu=" + cpu + ", smp=" + smp + ", mem=" + mem + + ", persistent=" + persistent + ", devices=" + devices + ", bootDeviceIds=" + bootDeviceIds + ", nics=" + + nics + ", vnc=" + vnc + ", description=" + description + "]"; + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java new file mode 100644 index 0000000000..1fcc31f422 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java @@ -0,0 +1,258 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import java.util.Date; +import java.util.Map; + +import javax.annotation.Nullable; + +/** + * + * @author Adrian Cole + */ +public class ServerInfo extends Server { + + public static class Builder extends Server.Builder { + protected ServerStatus status; + protected Date started; + protected String user; + protected ServerMetrics metrics; + + public Builder status(ServerStatus status) { + this.status = status; + return this; + } + + public Builder started(Date started) { + this.started = started; + return this; + } + + public Builder user(String user) { + this.user = user; + return this; + } + + public Builder metrics(ServerMetrics metrics) { + this.metrics = metrics; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder cpu(int cpu) { + return Builder.class.cast(super.cpu(cpu)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder smp(Integer smp) { + return Builder.class.cast(super.smp(smp)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder mem(int mem) { + return Builder.class.cast(super.mem(mem)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder persistent(boolean persistent) { + return Builder.class.cast(super.persistent(persistent)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder devices(Map devices) { + return Builder.class.cast(super.devices(devices)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder bootDeviceIds(Iterable bootDeviceIds) { + return Builder.class.cast(super.bootDeviceIds(bootDeviceIds)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder nics(Iterable nics) { + return Builder.class.cast(super.nics(nics)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder vnc(VNC vnc) { + return Builder.class.cast(super.vnc(vnc)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder description(String description) { + return Builder.class.cast(super.description(description)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder uuid(String uuid) { + return Builder.class.cast(super.uuid(uuid)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder use(Iterable use) { + return Builder.class.cast(super.use(use)); + } + + public ServerInfo build() { + return new ServerInfo(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, use, nics, vnc, + description, status, started, user, metrics); + } + } + + protected final ServerStatus status; + @Nullable + protected final Date started; + @Nullable + protected final String user; + protected final ServerMetrics metrics; + + public ServerInfo(String uuid, String name, int cpu, Integer smp, int mem, boolean persistent, + Map devices, Iterable bootDeviceIds, Iterable use, + Iterable nics, VNC vnc, String description, ServerStatus status, Date started, String user, + @Nullable ServerMetrics metrics) { + super(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, use, nics, vnc, description); + this.status = status; + this.started = started; + this.user = user; + this.metrics = metrics; + } + + /** + * + * @return active | stopped | paused | dumped | dead + */ + public ServerStatus getStatus() { + return status; + } + + // TODO undocumented + public Date getStarted() { + return started; + } + + /** + * + * @return metrics, if the server is running, or null + */ + @Nullable + public ServerMetrics getMetrics() { + return metrics; + } + + // TODO undocumented + /** + * + * @return owner of the server. + */ + public String getUser() { + return user; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((metrics == null) ? 0 : metrics.hashCode()); + result = prime * result + ((started == null) ? 0 : started.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((user == null) ? 0 : user.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + ServerInfo other = (ServerInfo) obj; + if (metrics == null) { + if (other.metrics != null) + return false; + } else if (!metrics.equals(other.metrics)) + return false; + if (started == null) { + if (other.started != null) + return false; + } else if (!started.equals(other.started)) + return false; + if (status != other.status) + return false; + if (user == null) { + if (other.user != null) + return false; + } else if (!user.equals(other.user)) + return false; + return true; + } + + @Override + public String toString() { + return "[cpu=" + cpu + ", smp=" + smp + ", mem=" + mem + ", persistent=" + persistent + ", devices=" + devices + + ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + ", uuid=" + uuid + ", name=" + + name + ", use=" + use + ", status=" + status + ", started=" + started + ", user=" + user + ", metrics=" + + metrics + "]"; + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java new file mode 100644 index 0000000000..8826bfe0af --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java @@ -0,0 +1,156 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; + +import com.google.common.collect.ImmutableMap; + +/** + * + * @author Adrian Cole + */ +public class ServerMetrics { + + public static class Builder { + protected long txPackets; + protected long tx; + protected long rxPackets; + protected long rx; + protected Map driveMetrics = ImmutableMap. of(); + + public Builder txPackets(long txPackets) { + this.txPackets = txPackets; + return this; + } + + public Builder tx(long tx) { + this.tx = tx; + return this; + } + + public Builder rxPackets(long rxPackets) { + this.rxPackets = rxPackets; + return this; + } + + public Builder rx(long rx) { + this.rx = rx; + return this; + } + + public Builder driveMetrics(Map driveMetrics) { + this.driveMetrics = ImmutableMap.copyOf(checkNotNull(driveMetrics, "driveMetrics")); + return this; + } + + public ServerMetrics build() { + return new ServerMetrics(tx, txPackets, rx, rxPackets, driveMetrics); + } + } + + protected final long txPackets; + protected final long tx; + protected final long rxPackets; + protected final long rx; + protected final Map driveMetrics; + + public ServerMetrics(long tx, long txPackets, long rx, long rxPackets, Map driveMetrics) { + this.txPackets = txPackets; + this.tx = tx; + this.rxPackets = rxPackets; + this.rx = rx; + this.driveMetrics = ImmutableMap.copyOf(checkNotNull(driveMetrics, "driveMetrics")); + } + + // TODO undocumented + public long getTxPackets() { + return txPackets; + } + + // TODO undocumented + public long getTx() { + return tx; + } + + // TODO undocumented + public long getRxPackets() { + return rxPackets; + } + + // TODO undocumented + public long getRx() { + return rx; + } + + /** + * + * @return metrics keyed on device id ex. {@code ide:0:0} + */ + public Map getDriveMetrics() { + return driveMetrics; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((driveMetrics == null) ? 0 : driveMetrics.hashCode()); + result = prime * result + (int) (rx ^ (rx >>> 32)); + result = prime * result + (int) (rxPackets ^ (rxPackets >>> 32)); + result = prime * result + (int) (tx ^ (tx >>> 32)); + result = prime * result + (int) (txPackets ^ (txPackets >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServerMetrics other = (ServerMetrics) obj; + if (driveMetrics == null) { + if (other.driveMetrics != null) + return false; + } else if (!driveMetrics.equals(other.driveMetrics)) + return false; + if (rx != other.rx) + return false; + if (rxPackets != other.rxPackets) + return false; + if (tx != other.tx) + return false; + if (txPackets != other.txPackets) + return false; + return true; + } + + @Override + public String toString() { + return "[ txPackets=" + txPackets + ", tx=" + tx + ", rxPackets=" + rxPackets + ", rx=" + rx + ", driveMetrics=" + + driveMetrics + "]"; + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java new file mode 100644 index 0000000000..443b889d6c --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java @@ -0,0 +1,47 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Adrian Cole + */ +public enum ServerStatus { + ACTIVE, STOPPED, PAUSED, DUMPED, DEAD, UNRECOGNIZED; + public String value() { + return name().toLowerCase(); + } + + @Override + public String toString() { + return value(); + } + + public static ServerStatus fromValue(String status) { + try { + return valueOf(checkNotNull(status, "status").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/VNC.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/VNC.java new file mode 100644 index 0000000000..8bfc818928 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/VNC.java @@ -0,0 +1,105 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.domain; + +import javax.annotation.Nullable; + +/** + * + * @author Adrian Cole + */ +public class VNC { + @Nullable + private final String ip; + @Nullable + private final String password; + private final boolean tls; + + public VNC(String ip, String password, boolean tls) { + this.ip = ip; + this.password = password; + this.tls = tls; + } + + /** + * + * @return IP address for overlay VNC access on port 5900. Set to 'auto', to reuse nic:0:dhcp if + * available, or otherwise allocate a temporary IP at boot. + */ + public String getIp() { + return ip; + } + + /** + * + * @return Password for VNC access. If unset, VNC is disabled. + */ + public String getPassword() { + return password; + } + + /** + * + * @return Set to 'on' to require VeNCrypt-style TLS auth in addition to the password. If this is + * unset, only unencrypted VNC is available. + */ + public boolean isTls() { + return tls; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((ip == null) ? 0 : ip.hashCode()); + result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + (tls ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VNC other = (VNC) obj; + if (ip == null) { + if (other.ip != null) + return false; + } else if (!ip.equals(other.ip)) + return false; + if (password == null) { + if (other.password != null) + return false; + } else if (!password.equals(other.password)) + return false; + if (tls != other.tls) + return false; + return true; + } + + @Override + public String toString() { + return "[ip=" + ip + ", password=" + password + ", tls=" + tls + "]"; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/CreateDriveRequestToMap.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/BaseDriveToMap.java similarity index 53% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/CreateDriveRequestToMap.java rename to sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/BaseDriveToMap.java index 91564eac6c..87557a5ba1 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/CreateDriveRequestToMap.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/BaseDriveToMap.java @@ -19,40 +19,37 @@ package org.jclouds.cloudsigma.functions; -import static org.jclouds.util.Utils.renameKey; +import static com.google.common.base.Preconditions.checkNotNull; import java.util.Map; -import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.elasticstack.domain.Drive; +import org.jclouds.cloudsigma.domain.ClaimType; +import org.jclouds.cloudsigma.domain.Drive; import com.google.common.base.Function; -import com.google.common.collect.Maps; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableMap; /** * * @author Adrian Cole */ @Singleton -public class CreateDriveRequestToMap implements Function> { - private final org.jclouds.elasticstack.functions.CreateDriveRequestToMap baseDriveToMap; - - @Inject - public CreateDriveRequestToMap(org.jclouds.elasticstack.functions.CreateDriveRequestToMap baseDriveToMap) { - this.baseDriveToMap = baseDriveToMap; - } - +public class BaseDriveToMap implements Function> { @Override public Map apply(Drive from) { - return Maps.transformEntries(renameKey(baseDriveToMap.apply(from), "tags", "use"), - new Maps.EntryTransformer() { - - @Override - public String transformEntry(String arg0, String arg1) { - return "use".equals(arg0) ? arg1.replace(' ', ',') : arg1; - } - - }); } + checkNotNull(from, "drive"); + ImmutableMap.Builder builder = ImmutableMap.builder(); + builder.put("name", from.getName()); + builder.put("size", from.getSize() + ""); + if (from.getClaimType() != ClaimType.EXCLUSIVE) + builder.put("claim:type", from.getClaimType().toString()); + if (from.getReaders().size() != 0) + builder.put("readers", Joiner.on(' ').join(from.getReaders())); + if (from.getUse().size() != 0) + builder.put("use", Joiner.on(' ').join(from.getUse())); + return builder.build(); + } } \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java index baa1c0301e..f3ae1ae6c5 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java @@ -26,7 +26,7 @@ import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.elasticstack.domain.DriveData; +import org.jclouds.cloudsigma.domain.DriveData; import com.google.common.base.Function; @@ -36,15 +36,15 @@ import com.google.common.base.Function; */ @Singleton public class DriveDataToMap implements Function> { - private final org.jclouds.elasticstack.functions.DriveDataToMap baseDriveToMap; + private final BaseDriveToMap baseDriveToMap; @Inject - public DriveDataToMap(org.jclouds.elasticstack.functions.DriveDataToMap baseDriveToMap) { + public DriveDataToMap(BaseDriveToMap baseDriveToMap) { this.baseDriveToMap = baseDriveToMap; } @Override public Map apply(DriveData from) { - return renameKey(baseDriveToMap.apply(from), "tags", "use"); + return renameKey(baseDriveToMap.apply(from), "use", "use"); } } \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java index 32224ed897..8e1beccc0d 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java @@ -24,7 +24,7 @@ import java.util.Set; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.cloudsigma.domain.ServerInfo; import org.jclouds.http.HttpResponse; import com.google.common.base.Function; diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java index 3d7d1a3d53..bf3ac43598 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java @@ -25,7 +25,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ReturnStringIf2xx; diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java new file mode 100644 index 0000000000..abc3956fe6 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.List; +import java.util.Map; + +import javax.inject.Singleton; + +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ListOfKeyValuesDelimitedByBlankLinesToListOfMaps implements Function>> { + + @Override + public List> apply(String from) { + List> maps = Lists.newArrayList(); + for (String listOfKeyValues : Splitter.on("\n\n").split(from)) { + if (!"".equals(listOfKeyValues)) { + Map map = Maps.newLinkedHashMap(); + for (String keyValueLine : Splitter.on('\n').split(listOfKeyValues)) { + if (!"".equals(keyValueLine)) { + int firstIndex = keyValueLine.indexOf(' '); + String key = keyValueLine.substring(0, firstIndex); + String value = keyValueLine.substring(firstIndex + 1).replace("\\n", "\n"); + map.put(key, value); + } + } + if (map.size() != 0) + maps.add(map); + } + } + return maps; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java index 1726d153a1..70c971ba89 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java @@ -24,8 +24,8 @@ import java.util.Set; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ReturnStringIf2xx; diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java new file mode 100644 index 0000000000..0e6befe520 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java @@ -0,0 +1,58 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.Map; + +import javax.inject.Singleton; + +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ListOfMapsToListOfKeyValuesDelimitedByBlankLines implements + Function>, String> { + + @Override + public String apply(Iterable> from) { + return Joiner.on("\n\n").join(Iterables.transform(from, new Function, String>() { + + @Override + public String apply(Map from) { + return Joiner.on('\n').withKeyValueSeparator(" ") + .join(Maps.transformValues(from, new Function() { + + @Override + public String apply(String from) { + return from.replace("\n", "\\n"); + } + + })); + } + + })); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java new file mode 100644 index 0000000000..00f237250f --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java @@ -0,0 +1,102 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.cloudsigma.domain.BlockDevice; +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.IDEDevice; +import org.jclouds.cloudsigma.domain.MediaType; +import org.jclouds.cloudsigma.domain.SCSIDevice; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.common.collect.Maps; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class MapToDevices implements Function, Map> { + @Singleton + public static class DeviceToId implements Function { + @Override + public String apply(Device input) { + return input.getId(); + } + } + + private final Function deviceToId; + + @Inject + public MapToDevices(Function deviceToId) { + this.deviceToId = deviceToId; + } + + public Map apply(Map from) { + Builder devices = ImmutableSet.builder(); + addIDEDevices(from, devices); + addSCSIDevices(from, devices); + addBlockDevices(from, devices); + + return Maps.uniqueIndex(devices.build(), deviceToId); + } + + protected void addBlockDevices(Map from, Builder devices) { + BLOCK: for (int index : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) { + String key = String.format("block:0:%d", index); + if (!from.containsKey(key)) + break BLOCK; + devices.add(populateBuilder(new BlockDevice.Builder(index), key, from).build()); + } + } + + protected void addSCSIDevices(Map from, Builder devices) { + SCSI: for (int unit : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) { + String key = String.format("scsi:0:%d", unit); + if (!from.containsKey(key)) + break SCSI; + devices.add(populateBuilder(new SCSIDevice.Builder(unit), key, from).build()); + } + } + + protected void addIDEDevices(Map from, Builder devices) { + IDE: for (int bus : new int[] { 0, 1 }) + for (int unit : new int[] { 0, 1 }) { + String key = String.format("ide:%d:%d", bus, unit); + if (!from.containsKey(key)) + break IDE; + devices.add(populateBuilder(new IDEDevice.Builder(bus, unit), key, from).build()); + } + } + + protected Device.Builder populateBuilder(Device.Builder deviceBuilder, String key, Map from) { + deviceBuilder.uuid(from.get(key)); + if (from.containsKey(key + ":media")) + deviceBuilder.mediaType(MediaType.fromValue(from.get(key + ":media"))); + return deviceBuilder; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java index 45af167398..fd61960b1b 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java @@ -21,15 +21,19 @@ package org.jclouds.cloudsigma.functions; import java.net.URI; import java.util.Map; +import java.util.Map.Entry; -import javax.inject.Inject; import javax.inject.Singleton; +import org.jclouds.cloudsigma.domain.ClaimType; import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.cloudsigma.domain.DriveMetrics; +import org.jclouds.cloudsigma.domain.DriveStatus; import org.jclouds.cloudsigma.domain.DriveType; import com.google.common.base.Function; import com.google.common.base.Splitter; +import com.google.common.collect.Maps; /** * @@ -37,20 +41,38 @@ import com.google.common.base.Splitter; */ @Singleton public class MapToDriveInfo implements Function, DriveInfo> { - private final org.jclouds.elasticstack.functions.MapToDriveInfo mapToDriveInfo; - - @Inject - public MapToDriveInfo(org.jclouds.elasticstack.functions.MapToDriveInfo mapToDriveInfo) { - this.mapToDriveInfo = mapToDriveInfo; - } @Override public DriveInfo apply(Map from) { if (from.size() == 0) return null; - DriveInfo.Builder builder = DriveInfo.Builder.fromDriveInfo(mapToDriveInfo.apply(from)); + if (from.size() == 0) + return null; + DriveInfo.Builder builder = new DriveInfo.Builder(); + builder.name(from.get("name")); if (from.containsKey("use")) - builder.tags(Splitter.on(' ').split(from.get("use"))); + builder.use(Splitter.on(' ').split(from.get("use"))); + if (from.containsKey("status")) + builder.status(DriveStatus.fromValue(from.get("status"))); + builder.metrics(buildMetrics(from)); + builder.user(from.get("user")); + builder.encryptionCipher(from.get("encryption:cipher")); + builder.uuid(from.get("drive")); + if (from.containsKey("claim:type")) + builder.claimType(ClaimType.fromValue(from.get("claim:type"))); + if (from.containsKey("claimed")) + builder.claimed(Splitter.on(' ').split(from.get("claimed"))); + if (from.containsKey("readers")) + builder.readers(Splitter.on(' ').split(from.get("readers"))); + if (from.containsKey("size")) + builder.size(new Long(from.get("size"))); + Map metadata = Maps.newLinkedHashMap(); + for (Entry entry : from.entrySet()) { + if (entry.getKey().startsWith("user:")) + metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue()); + } + if (from.containsKey("use")) + builder.use(Splitter.on(' ').split(from.get("use"))); if (from.containsKey("bits")) builder.bits(new Integer(from.get("bits"))); if (from.containsKey("url")) @@ -69,4 +91,17 @@ public class MapToDriveInfo implements Function, DriveInfo> builder.type(DriveType.fromValue(from.get("type"))); return builder.build(); } + + protected DriveMetrics buildMetrics(Map from) { + DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder(); + if (from.containsKey("read:bytes")) + metricsBuilder.readBytes(new Long(from.get("read:bytes"))); + if (from.containsKey("read:requests")) + metricsBuilder.readRequests(new Long(from.get("read:requests"))); + if (from.containsKey("write:bytes")) + metricsBuilder.writeBytes(new Long(from.get("write:bytes"))); + if (from.containsKey("write:requests")) + metricsBuilder.writeRequests(new Long(from.get("write:requests"))); + return metricsBuilder.build(); + } } \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java new file mode 100644 index 0000000000..79e515901c --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java @@ -0,0 +1,87 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.cloudsigma.domain.DriveMetrics; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class MapToDriveMetrics implements Function, Map> { + + public Map apply(Map from) { + Builder builder = ImmutableMap. builder(); + addIDEDevices(from, builder); + addSCSIDevices(from, builder); + addBlockDevices(from, builder); + return builder.build(); + } + + protected void addBlockDevices(Map from, Builder devices) { + BLOCK: for (int index : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) { + String key = String.format("block:0:%d", index); + if (!from.containsKey(key)) + break BLOCK; + devices.put(key, buildMetrics(key, from)); + } + } + + protected void addSCSIDevices(Map from, Builder devices) { + SCSI: for (int unit : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) { + String key = String.format("scsi:0:%d", unit); + if (!from.containsKey(key)) + break SCSI; + devices.put(key, buildMetrics(key, from)); + } + } + + protected void addIDEDevices(Map from, Builder devices) { + IDE: for (int bus : new int[] { 0, 1 }) + for (int unit : new int[] { 0, 1 }) { + String key = String.format("ide:%d:%d", bus, unit); + if (!from.containsKey(key)) + break IDE; + devices.put(key, buildMetrics(key, from)); + } + } + + protected DriveMetrics buildMetrics(String key, Map from) { + DriveMetrics.Builder builder = new DriveMetrics.Builder(); + if (from.containsKey(key + ":read:bytes")) + builder.readBytes(new Long(from.get(key + ":read:bytes"))); + if (from.containsKey(key + ":read:requests")) + builder.readRequests(new Long(from.get(key + ":read:requests"))); + if (from.containsKey(key + ":write:bytes")) + builder.writeBytes(new Long(from.get(key + ":write:bytes"))); + if (from.containsKey(key + ":write:requests")) + builder.writeRequests(new Long(from.get(key + ":write:requests"))); + return builder.build(); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java new file mode 100644 index 0000000000..9baa6e8606 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.List; +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.cloudsigma.domain.Model; +import org.jclouds.cloudsigma.domain.NIC; + +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class MapToNICs implements Function, List> { + + @Override + public List apply(Map from) { + ImmutableList.Builder nics = ImmutableList.builder(); + NIC: for (int id : new int[] { 0, 1 }) { + String key = String.format("nic:%d", id); + if (!from.containsKey(key + ":model")) + break NIC; + NIC.Builder nicBuilder = new NIC.Builder(); + nicBuilder.dhcp(from.get(key + ":dhcp")); + nicBuilder.model(Model.fromValue(from.get(key + ":model"))); + nicBuilder.vlan(from.get(key + ":vlan")); + nicBuilder.mac(from.get(key + ":mac")); + if (from.containsKey(key + ":block")) + nicBuilder.block(Splitter.on(' ').split(from.get(key + ":block"))); + nics.add(nicBuilder.build()); + } + return nics.build(); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java index d4ec8c2512..bb9fea7572 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java @@ -27,12 +27,12 @@ import java.util.Map.Entry; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.elasticstack.domain.Device; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.domain.ServerMetrics; -import org.jclouds.elasticstack.domain.ServerStatus; -import org.jclouds.elasticstack.domain.VNC; +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.domain.ServerMetrics; +import org.jclouds.cloudsigma.domain.ServerStatus; +import org.jclouds.cloudsigma.domain.VNC; import com.google.common.base.Function; import com.google.common.base.Splitter; @@ -65,7 +65,7 @@ public class MapToServerInfo implements Function, ServerInfo builder.description(from.get("description")); builder.persistent(Boolean.parseBoolean(from.get("persistent"))); if (from.containsKey("use")) - builder.tags(Splitter.on(' ').split(from.get("use"))); + builder.use(Splitter.on(' ').split(from.get("use"))); if (from.containsKey("status")) builder.status(ServerStatus.fromValue(from.get("status"))); if (from.containsKey("smp") && !"auto".equals(from.get("smp"))) @@ -86,7 +86,6 @@ public class MapToServerInfo implements Function, ServerInfo if (entry.getKey().startsWith("user:")) metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue()); } - builder.userMetadata(metadata); builder.nics(mapToNICs.apply(from)); builder.devices(mapToDevices.apply(from)); builder.metrics(mapToMetrics.apply(from)); diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java new file mode 100644 index 0000000000..f982abf6a3 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.cloudsigma.domain.DriveMetrics; +import org.jclouds.cloudsigma.domain.ServerMetrics; + +import com.google.common.base.Function; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class MapToServerMetrics implements Function, ServerMetrics> { + private final Function, Map> mapToDriveMetrics; + + @Inject + public MapToServerMetrics(Function, Map> mapToDriveMetrics) { + this.mapToDriveMetrics = mapToDriveMetrics; + } + + public ServerMetrics apply(Map from) { + ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder(); + if (from.containsKey("tx:packets")) + metricsBuilder.txPackets(new Long(from.get("tx:packets"))); + if (from.containsKey("tx")) + metricsBuilder.tx(new Long(from.get("tx"))); + if (from.containsKey("rx:packets")) + metricsBuilder.rxPackets(new Long(from.get("rx:packets"))); + if (from.containsKey("rx")) + metricsBuilder.rx(new Long(from.get("rx"))); + metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from)); + + ServerMetrics metrics = metricsBuilder.build(); + return metrics; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java new file mode 100644 index 0000000000..d7e7424467 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java @@ -0,0 +1,38 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payload; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class ReturnPayload implements Function { + + public Payload apply(HttpResponse from) { + return from.getPayload(); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java index 8a5bfab146..7c67b4996f 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java @@ -26,9 +26,9 @@ import java.util.Map.Entry; import javax.inject.Singleton; -import org.jclouds.elasticstack.domain.Device; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.Server; +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.Server; import com.google.common.base.Function; import com.google.common.base.Joiner; @@ -74,10 +74,8 @@ public class ServerToMap implements Function> { builder.put("vnc:password", from.getVnc().getPassword()); if (from.getVnc().isTls()) builder.put("vnc:tls", "on"); - if (from.getTags().size() != 0) - builder.put("use", Joiner.on(' ').join(from.getTags())); - for (Entry entry : from.getUserMetadata().entrySet()) - builder.put("user:" + entry.getKey(), entry.getValue()); + if (from.getUse().size() != 0) + builder.put("use", Joiner.on(' ').join(from.getUse())); return builder.build(); } } \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java new file mode 100644 index 0000000000..b87fd5e4de --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static com.google.common.base.Predicates.equalTo; +import static com.google.common.base.Predicates.not; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Sets.newTreeSet; + +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ReturnStringIf2xx; + +import com.google.common.base.Function; +import com.google.common.base.Splitter; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class SplitNewlines implements Function> { + private final ReturnStringIf2xx returnStringIf200; + + @Inject + SplitNewlines(ReturnStringIf2xx returnStringIf200) { + this.returnStringIf200 = returnStringIf200; + } + + @Override + public Set apply(HttpResponse response) { + return newTreeSet(filter(Splitter.on('\n').split(returnStringIf200.apply(response)), not(equalTo("")))); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java new file mode 100644 index 0000000000..7c4f3dfc83 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java @@ -0,0 +1,107 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.handlers; + +import java.io.IOException; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.logging.Logger; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.util.Utils; + +import com.google.common.base.Throwables; +import com.google.common.io.Closeables; + +/** + * This will parse and set an appropriate exception on the command object. + * + *

+ * Errors are returned with an appropriate HTTP status code, an X-Elastic- Error header specifying + * the error type, and a text description in the HTTP body. + * + * @author Adrian Cole + * + */ +@Singleton +public class CloudSigmaErrorHandler implements HttpErrorHandler { + @Resource + protected Logger logger = Logger.NULL; + + public void handleError(HttpCommand command, HttpResponse response) { + // it is important to always read fully and close streams + String message = parseMessage(response); + Exception exception = message != null ? new HttpResponseException(command, response, message) + : new HttpResponseException(command, response); + try { + message = message != null ? message : String.format("%s -> %s", command.getRequest().getRequestLine(), + response.getStatusLine()); + switch (response.getStatusCode()) { + case 400: + if ((command.getRequest().getEndpoint().getPath().endsWith("/info")) + || (message != null && message.indexOf("could not be found") != -1)) + exception = new ResourceNotFoundException(message, exception); + else + exception = new IllegalArgumentException(message, exception); + break; + case 401: + exception = new AuthorizationException(message, exception); + break; + case 404: + if (!command.getRequest().getMethod().equals("DELETE")) { + exception = new ResourceNotFoundException(message, exception); + } + break; + case 405: + exception = new IllegalArgumentException(message, exception); + break; + case 409: + exception = new IllegalStateException(message, exception); + break; + } + } finally { + if (response.getPayload() != null) + Closeables.closeQuietly(response.getPayload().getInput()); + command.setException(exception); + } + } + + public String parseMessage(HttpResponse response) { + if (response.getPayload() == null) + return null; + try { + return Utils.toStringAndClose(response.getPayload().getInput()); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + response.getPayload().getInput().close(); + } catch (IOException e) { + Throwables.propagate(e); + } + } + } +} diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java new file mode 100644 index 0000000000..9160caa348 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java @@ -0,0 +1,63 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.cloudsigma.CloudSigmaClient; +import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.logging.Logger; + +import com.google.common.base.Predicate; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class DriveClaimed implements Predicate { + + private final CloudSigmaClient client; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public DriveClaimed(CloudSigmaClient client) { + this.client = client; + } + + public boolean apply(DriveInfo drive) { + logger.trace("looking for claims on drive %s", checkNotNull(drive, "drive")); + drive = refresh(drive); + if (drive == null) + return false; + logger.trace("%s: looking for drive claims: currently: %s", drive.getUuid(), drive.getClaimed()); + return drive.getClaimed().size() > 0; + } + + private DriveInfo refresh(DriveInfo drive) { + return client.getDriveInfo(drive.getUuid()); + } +} diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java new file mode 100644 index 0000000000..7f19b80427 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java @@ -0,0 +1,33 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.reference; + +/** + * + * @author Adrian Cole + */ +public class CloudSigmaConstants { + + /** + * default VNC password used on new machines + */ + public static final String PROPERTY_VNC_PASSWORD = "jclouds.cloudsigma.vnc-password"; + +} diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/util/Servers.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/util/Servers.java new file mode 100644 index 0000000000..e452ee798c --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/util/Servers.java @@ -0,0 +1,54 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.util; + +import org.jclouds.cloudsigma.domain.IDEDevice; +import org.jclouds.cloudsigma.domain.Model; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.VNC; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +public class Servers { + /** + * Helper to create a small persistent server + * + * @param name + * what to name the server + * @param driveUuuid + * id of the boot drive + * @param vncPassword + * password for vnc + * @return a builder for a persistent 1Ghz 512m server with DHCP enabled network. + */ + public static Server.Builder small(String name, String driveUuuid, String vncPassword) { + return new Server.Builder().name(name).cpu(1000).mem(512).persistent(true) + .devices(ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(driveUuuid).build())) + .bootDeviceIds(ImmutableSet.of("ide:0:0")) + .nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp("auto").build())) + .vnc(new VNC(null, vncPassword, false)); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java index 9eebec7f9c..934e7064a4 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java @@ -30,12 +30,12 @@ import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerIn import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.elasticstack.binders.BindServerToPlainTextStringTest; -import org.jclouds.elasticstack.domain.CreateDriveRequest; -import org.jclouds.elasticstack.domain.Drive; -import org.jclouds.elasticstack.domain.DriveData; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.functions.SplitNewlines; +import org.jclouds.cloudsigma.binders.BindServerToPlainTextStringTest; +import org.jclouds.cloudsigma.domain.CreateDriveRequest; +import org.jclouds.cloudsigma.domain.Drive; +import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.functions.SplitNewlines; import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ReleasePayloadAndReturn; @@ -140,12 +140,12 @@ public class CloudSigmaAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - new CreateDriveRequest.Builder().name("foo").tags(ImmutableList.of("production", "candy")).size(10000l) + new CreateDriveRequest.Builder().name("foo").use(ImmutableList.of("production", "candy")).size(10000l) .build()); assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/create HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, "name foo\nsize 10000\nuse production,candy", "text/plain", false); + assertPayloadEquals(httpRequest, "name foo\nsize 10000\nuse production candy", "text/plain", false); assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class); assertSaxResponseParserClassEquals(method, null); @@ -193,7 +193,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "100", - new DriveData.Builder().name("foo").size(10000l).tags(ImmutableList.of("production", "candy")).build()); + new DriveData.Builder().name("foo").size(10000l).use(ImmutableList.of("production", "candy")).build()); assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/100/set HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java index e9399563d8..f95716e78c 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java @@ -19,22 +19,52 @@ package org.jclouds.cloudsigma; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import java.io.IOException; +import java.util.Properties; import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; +import org.jclouds.Constants; +import org.jclouds.cloudsigma.domain.ClaimType; +import org.jclouds.cloudsigma.domain.CreateDriveRequest; +import org.jclouds.cloudsigma.domain.DriveData; import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.cloudsigma.domain.DriveStatus; import org.jclouds.cloudsigma.domain.DriveType; +import org.jclouds.cloudsigma.domain.IDEDevice; +import org.jclouds.cloudsigma.domain.Model; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.domain.ServerStatus; import org.jclouds.cloudsigma.options.CloneDriveOptions; +import org.jclouds.cloudsigma.predicates.DriveClaimed; +import org.jclouds.cloudsigma.util.Servers; import org.jclouds.domain.Credentials; -import org.jclouds.elasticstack.CommonElasticStackClientLiveTest; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.net.IPSocket; +import org.jclouds.predicates.InetSocketAddressConnect; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.ssh.ExecResponse; +import org.jclouds.ssh.SshClient; +import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.gson.Gson; +import com.google.inject.Guice; +import com.google.inject.Module; /** * Tests behavior of {@code CloudSigmaClient} @@ -42,12 +72,277 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", testName = "cloudsigma.CloudSigmaClientLiveTest") -public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTest { +public class CloudSigmaClientLiveTest { + protected long driveSize = 8 * 1024 * 1024 * 1024l; + protected int maxDriveImageTime = 300; + protected String vncPassword = "Il0veVNC"; + protected CloudSigmaClient client; + protected RestContext context; + protected Predicate socketTester; - public CloudSigmaClientLiveTest() { - provider = "cloudsigma"; - driveSize = 8 * 1024 * 1024 * 1024l; - maxDriveImageTime = 300; + protected String provider = "cloudsigma"; + protected String identity; + protected String credential; + protected String endpoint; + protected String apiversion; + protected Predicate driveNotClaimed; + + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); + } + + protected Properties setupProperties() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + overrides.setProperty(provider + ".identity", identity); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); + return overrides; + } + + @BeforeGroups(groups = "live") + public void setupClient() { + setupCredentials(); + Properties overrides = setupProperties(); + // context = new ComputeServiceContextFactory().createContext(provider, + // ImmutableSet. of(new Log4JLoggingModule()), + // overrides).getProviderSpecificContext(); + context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), + overrides); + + client = context.getApi(); + driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, + 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, + TimeUnit.SECONDS); + } + + @Test + public void testListServers() throws Exception { + Set servers = client.listServers(); + assertNotNull(servers); + } + + @Test + public void testListServerInfo() throws Exception { + Set servers = client.listServerInfo(); + assertNotNull(servers); + } + + @Test + public void testGetServer() throws Exception { + for (String serverUUID : client.listServers()) { + assert !"".equals(serverUUID); + assertNotNull(client.getServerInfo(serverUUID)); + } + } + + @Test + public void testListDrives() throws Exception { + Set drives = client.listDrives(); + assertNotNull(drives); + } + + @Test + public void testListDriveInfo() throws Exception { + Set drives = client.listDriveInfo(); + assertNotNull(drives); + } + + @Test + public void testGetDrive() throws Exception { + for (String driveUUID : client.listDrives()) { + assert !"".equals(driveUUID); + assertNotNull(client.getDriveInfo(driveUUID)); + } + } + + protected String prefix = System.getProperty("user.name") + ".test"; + protected DriveInfo drive; + + @Test + public void testCreateDrive() throws Exception { + drive = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(driveSize).build()); + checkCreatedDrive(); + + DriveInfo newInfo = client.getDriveInfo(drive.getUuid()); + checkDriveMatchesGet(newInfo); + + } + + protected void checkDriveMatchesGet(DriveInfo newInfo) { + assertEquals(newInfo.getUuid(), drive.getUuid()); + assertEquals(newInfo.getType(), DriveType.DISK); + } + + protected void checkCreatedDrive() { + assertNotNull(drive.getUuid()); + assertNotNull(drive.getUser()); + assertEquals(drive.getName(), prefix); + assertEquals(drive.getSize(), driveSize); + assertEquals(drive.getStatus(), DriveStatus.ACTIVE); + // for some reason, these occasionally return as 4096,1 + // assertEquals(info.getReadBytes(), 0l); + // assertEquals(info.getWriteBytes(), 0l); + // assertEquals(info.getReadRequests(), 0l); + // assertEquals(info.getWriteRequests(), 0l); + assertEquals(drive.getEncryptionCipher(), "aes-xts-plain"); + assertEquals(drive.getType(), null); + } + + @Test(dependsOnMethods = "testCreateDrive") + public void testSetDriveData() throws Exception { + + DriveInfo drive2 = client.setDriveData( + drive.getUuid(), + new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous") + .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")) + .use(ImmutableSet.of("networking", "security", "gateway")).build()); + + assertNotNull(drive2.getUuid(), drive.getUuid()); + assertEquals(drive2.getName(), "rediculous"); + assertEquals(drive2.getClaimType(), ClaimType.SHARED); + assertEquals(drive2.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")); + assertEquals(drive2.getUse(), ImmutableSet.of("networking", "security", "gateway")); + drive = drive2; + } + + protected ServerInfo server; + + @Test(dependsOnMethods = "testSetDriveData") + public void testCreateAndStartServer() throws Exception { + Logger.getAnonymousLogger().info("preparing drive"); + prepareDrive(); + + Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build(); + + Logger.getAnonymousLogger().info("starting server"); + server = client.createServer(serverRequest); + client.startServer(server.getUuid()); + server = client.getServerInfo(server.getUuid()); + checkStartedServer(); + + Server newInfo = client.getServerInfo(server.getUuid()); + checkServerMatchesGet(newInfo); + + } + + protected void checkServerMatchesGet(Server newInfo) { + assertEquals(newInfo.getUuid(), server.getUuid()); + } + + protected void checkStartedServer() { + System.out.println(new Gson().toJson(server)); + assertNotNull(server.getUuid()); + assertNotNull(server.getUser()); + assertEquals(server.getName(), prefix); + assertEquals(server.isPersistent(), true); + assertEquals(server.getDevices(), + ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build())); + assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0")); + assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp()); + assertEquals(server.getNics().get(0).getModel(), Model.E1000); + assertEquals(server.getStatus(), ServerStatus.ACTIVE); + } + + @Test(dependsOnMethods = "testCreateAndStartServer") + public void testConnectivity() throws Exception { + Logger.getAnonymousLogger().info("awaiting vnc"); + assert socketTester.apply(new IPSocket(server.getVnc().getIp(), 5900)) : server; + Logger.getAnonymousLogger().info("awaiting ssh"); + assert socketTester.apply(new IPSocket(server.getNics().get(0).getDhcp(), 22)) : server; + doConnectViaSsh(server, getSshCredentials(server)); + } + + @Test(dependsOnMethods = "testConnectivity") + public void testLifeCycle() throws Exception { + client.stopServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED); + + client.startServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); + + client.resetServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); + + client.shutdownServer(server.getUuid()); + // behavior on shutdown depends on how your server OS is set up to respond to an ACPI power + // button signal + assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo( + server.getUuid()).getStatus() == ServerStatus.STOPPED); + } + + @Test(dependsOnMethods = "testLifeCycle") + public void testSetServerConfiguration() throws Exception { + client.stopServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED); + + ServerInfo server2 = client.setServerConfiguration( + server.getUuid(), + Server.Builder.fromServer(server).name("rediculous") + .use(ImmutableSet.of("networking", "security", "gateway")).build()); + + assertNotNull(server2.getUuid(), server.getUuid()); + assertEquals(server2.getName(), "rediculous"); + checkUse(server2); + server = server2; + } + + protected void checkUse(ServerInfo server2) { + // bug where use aren't updated + assertEquals(server2.getUse(), ImmutableSet. of()); + } + + @Test(dependsOnMethods = "testSetServerConfiguration") + public void testDestroyServer() throws Exception { + client.destroyServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()), null); + } + + @Test(dependsOnMethods = "testDestroyServer") + public void testDestroyDrive() throws Exception { + client.destroyDrive(drive.getUuid()); + assertEquals(client.getDriveInfo(drive.getUuid()), null); + } + + protected void doConnectViaSsh(Server server, Credentials creds) throws IOException { + SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class) + .create(new IPSocket(server.getVnc().getIp(), 22), creds); + try { + ssh.connect(); + ExecResponse hello = ssh.exec("echo hello"); + assertEquals(hello.getOutput().trim(), "hello"); + System.err.println(ssh.exec("df -k").getOutput()); + System.err.println(ssh.exec("mount").getOutput()); + System.err.println(ssh.exec("uname -a").getOutput()); + } finally { + if (ssh != null) + ssh.disconnect(); + } + } + + @AfterGroups(groups = "live") + protected void tearDown() { + try { + client.destroyServer(server.getUuid()); + } catch (Exception e) { + // no need to check null or anything as we swallow all + } + try { + client.destroyDrive(drive.getUuid()); + } catch (Exception e) { + + } + if (context != null) + context.close(); } @Test @@ -68,24 +363,10 @@ public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTest of()); - assertEquals(server2.getUserMetadata(), ImmutableMap. of()); - } } diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java new file mode 100644 index 0000000000..fbd187970a --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java @@ -0,0 +1,87 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.binders; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudsigma.domain.ClaimType; +import org.jclouds.cloudsigma.domain.Drive; +import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.functions.BaseDriveToMap; +import org.jclouds.cloudsigma.functions.DriveDataToMap; +import org.jclouds.http.HttpRequest; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class BindDriveDataToPlainTextStringTest { + + private static final BindDriveDataToPlainTextString FN = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + bind(new TypeLiteral>>() { + }).to(BaseDriveToMap.class); + bind(new TypeLiteral>>() { + }).to(DriveDataToMap.class); + } + + }).getInstance(BindDriveDataToPlainTextString.class); + + public void testSimple() { + HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create")); + FN.bindToRequest(request, new DriveData.Builder().name("foo").size(100l).build()); + assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); + assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100"); + } + + public void testComplete() throws IOException { + DriveData input = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") + // + .size(8589934592l)// + .claimType(ClaimType.SHARED)// + .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))// + .use(ImmutableSet.of("tag1", "tag2"))// + .build(); + + HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create")); + FN.bindToRequest(request, input); + assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); + assertEquals(request.getPayload().getRawContent(), + Utils.toStringAndClose(BindDriveDataToPlainTextStringTest.class.getResourceAsStream("/drive_data.txt"))); + + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java new file mode 100644 index 0000000000..ce81c41a37 --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java @@ -0,0 +1,91 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.binders; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudsigma.domain.ClaimType; +import org.jclouds.cloudsigma.domain.CreateDriveRequest; +import org.jclouds.cloudsigma.domain.Drive; +import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.functions.BaseDriveToMap; +import org.jclouds.cloudsigma.functions.DriveDataToMap; +import org.jclouds.http.HttpRequest; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class BindDriveToPlainTextStringTest { + + private static final BindDriveToPlainTextString FN = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + bind(new TypeLiteral>>() { + }).to(BaseDriveToMap.class); + bind(new TypeLiteral>>() { + }).to(DriveDataToMap.class); + } + + }).getInstance(BindDriveToPlainTextString.class); + + public void testSimple() { + HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create")); + FN.bindToRequest(request, new CreateDriveRequest.Builder().name("foo").size(100l).build()); + assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); + assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100"); + } + + public void testComplete() throws IOException { + CreateDriveRequest input = new CreateDriveRequest.Builder() + .name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") + // + .size(8589934592l)// + .claimType(ClaimType.SHARED)// + .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))// + .use(ImmutableSet.of("tag1", "tag2"))// + .encryptionCipher("aes-xts-plain").avoid(ImmutableSet.of("avoid1")).build(); + + HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create")); + FN.bindToRequest(request, input); + assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); + assertEquals(request.getPayload().getRawContent(), + Utils.toStringAndClose(BindDriveToPlainTextStringTest.class + .getResourceAsStream("/create_drive.txt"))); + + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java new file mode 100644 index 0000000000..548c7a251f --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java @@ -0,0 +1,92 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.binders; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudsigma.domain.IDEDevice; +import org.jclouds.cloudsigma.domain.Model; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.VNC; +import org.jclouds.cloudsigma.functions.ServerToMap; +import org.jclouds.http.HttpRequest; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class BindServerToPlainTextStringTest { + + public static String CREATED_SERVER; + static { + try { + CREATED_SERVER = Utils.toStringAndClose(BindServerToPlainTextStringTest.class + .getResourceAsStream("/create_server.txt")); + } catch (IOException e) { + CREATED_SERVER = null; + } + } + public static final Server SERVER = new Server.Builder() + .name("TestServer") + .cpu(2000) + .mem(1024) + .devices( + ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid("08c92dd5-70a0-4f51-83d2-835919d254df") + .build())).bootDeviceIds(ImmutableSet.of("ide:0:0")) + .nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000). + + build())).vnc(new VNC(null, "XXXXXXXX", false)).build(); + private static final BindServerToPlainTextString FN = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + bind(new TypeLiteral>>() { + }).to(ServerToMap.class); + bind(new TypeLiteral>>() { + }).to(ServerToMap.class); + } + + }).getInstance(BindServerToPlainTextString.class); + + public void testSimple() throws IOException { + HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create")); + FN.bindToRequest(request, SERVER); + assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); + assertEquals(request.getPayload().getRawContent(), CREATED_SERVER); + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java new file mode 100644 index 0000000000..4c6e11e37c --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; + +import org.jclouds.cloudsigma.domain.ClaimType; +import org.jclouds.cloudsigma.domain.Drive; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class BaseDriveToMapTest { + + private static final BaseDriveToMap BASEDRIVE_TO_MAP = new BaseDriveToMap(); + + public void testBasics() { + assertEquals(BASEDRIVE_TO_MAP.apply(new Drive.Builder().name("foo").size(100l).build()), + ImmutableMap.of("name", "foo", "size", "100")); + } + + public void testComplete() throws IOException { + Drive one = new Drive.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") + // + .size(8589934592l)// + .claimType(ClaimType.SHARED)// + .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))// + .use(ImmutableSet.of("tag1", "tag2"))// + .build(); + assertEquals( + BASEDRIVE_TO_MAP.apply(one), + ImmutableMap.builder().put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") + .put("size", "8589934592").put("claim:type", "shared") + .put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff").put("use", "tag1 tag2").build() + + ); + + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java new file mode 100644 index 0000000000..24a4b00f77 --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java @@ -0,0 +1,65 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; + +import org.jclouds.cloudsigma.domain.ClaimType; +import org.jclouds.cloudsigma.domain.DriveData; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class DriveDataToMapTest { + + private static final DriveDataToMap BASEDRIVE_TO_MAP = Guice.createInjector().getInstance(DriveDataToMap.class); + + public void testBasics() { + assertEquals(BASEDRIVE_TO_MAP.apply(new DriveData.Builder().name("foo").size(100l).build()), + ImmutableMap.of("name", "foo", "size", "100")); + } + + public void testComplete() throws IOException { + DriveData one = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") + // + .size(8589934592l)// + .claimType(ClaimType.SHARED)// + .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))// + .use(ImmutableSet.of("tag1", "tag2"))// + .build(); + assertEquals( + BASEDRIVE_TO_MAP.apply(one), + ImmutableMap.builder().put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") + .put("size", "8589934592").put("claim:type", "shared") + .put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff").put("use", "tag1 tag2").build() + + ); + + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java index 2def4841fb..aeff757ebf 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java @@ -45,6 +45,6 @@ public class KeyValuesDelimitedByBlankLinesToDriveInfoTest { public void testOne() { assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class - .getResourceAsStream("/cloudsigma/drive.txt")))), MapToDriveInfoTest.ONE); + .getResourceAsStream("/drive.txt")))), MapToDriveInfoTest.ONE); } } diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java index 6a8575b35d..75de5a003f 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java @@ -24,15 +24,15 @@ import static org.testng.Assert.assertEquals; import java.util.List; import java.util.Map; -import org.jclouds.elasticstack.domain.Device; -import org.jclouds.elasticstack.domain.DriveMetrics; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.ServerMetrics; -import org.jclouds.elasticstack.functions.MapToDevices; -import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; -import org.jclouds.elasticstack.functions.MapToDriveMetrics; -import org.jclouds.elasticstack.functions.MapToNICs; -import org.jclouds.elasticstack.functions.MapToServerMetrics; +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.DriveMetrics; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.ServerMetrics; +import org.jclouds.cloudsigma.functions.MapToDevices; +import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; +import org.jclouds.cloudsigma.functions.MapToDriveMetrics; +import org.jclouds.cloudsigma.functions.MapToNICs; +import org.jclouds.cloudsigma.functions.MapToServerMetrics; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; import org.testng.annotations.Test; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java index ed92403cc2..28e6f2ab3a 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java @@ -47,6 +47,6 @@ public class ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest { public void testOne() { assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class - .getResourceAsStream("/cloudsigma/drive.txt")))), ImmutableSet. of(MapToDriveInfoTest.ONE)); + .getResourceAsStream("/drive.txt")))), ImmutableSet. of(MapToDriveInfoTest.ONE)); } } diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java new file mode 100644 index 0000000000..1a5bb428ff --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest { + + private static final ListOfKeyValuesDelimitedByBlankLinesToListOfMaps FN = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps(); + + public void testNone() { + assertEquals(FN.apply(""), Lists.newArrayList()); + assertEquals(FN.apply("\n\n\n"), Lists.newArrayList()); + } + + public void testOneMap() { + assertEquals(FN.apply("key1 value1\nkey2 value2"), + ImmutableList.of(ImmutableMap.of("key1", "value1", "key2", "value2"))); + assertEquals(FN.apply("key1 value1\nkey2 value2\n\n"), + ImmutableList.of(ImmutableMap.of("key1", "value1", "key2", "value2"))); + } + + public void testValueEncodesNewlines() { + assertEquals(FN.apply("key1 value1\\n\nkey2 value2"), + ImmutableList.of(ImmutableMap.of("key1", "value1\n", "key2", "value2"))); + } + + public void testTwoMaps() { + assertEquals( + FN.apply("key1 value1\nkey2 value2\n\nkey1 v1\nkey2 v2"), + ImmutableList.of(ImmutableMap.of("key1", "value1", "key2", "value2"), + ImmutableMap.of("key1", "v1", "key2", "v2"))); + assertEquals( + FN.apply("key1 value1\nkey2 value2\n\nkey1 v1\nkey2 v2\n\n"), + ImmutableList.of(ImmutableMap.of("key1", "value1", "key2", "value2"), + ImmutableMap.of("key1", "v1", "key2", "v2"))); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java index 2cf011cb15..757c05543e 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java @@ -24,16 +24,16 @@ import static org.testng.Assert.assertEquals; import java.util.List; import java.util.Map; -import org.jclouds.elasticstack.domain.Device; -import org.jclouds.elasticstack.domain.DriveMetrics; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.domain.ServerMetrics; -import org.jclouds.elasticstack.functions.MapToDevices; -import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; -import org.jclouds.elasticstack.functions.MapToDriveMetrics; -import org.jclouds.elasticstack.functions.MapToNICs; -import org.jclouds.elasticstack.functions.MapToServerMetrics; +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.DriveMetrics; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.domain.ServerMetrics; +import org.jclouds.cloudsigma.functions.MapToDevices; +import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; +import org.jclouds.cloudsigma.functions.MapToDriveMetrics; +import org.jclouds.cloudsigma.functions.MapToNICs; +import org.jclouds.cloudsigma.functions.MapToServerMetrics; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; import org.testng.annotations.Test; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java new file mode 100644 index 0000000000..fce825382c --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import java.util.Map; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest { + + private static final ListOfMapsToListOfKeyValuesDelimitedByBlankLines FN = new ListOfMapsToListOfKeyValuesDelimitedByBlankLines(); + + public void testNone() { + assertEquals(FN.apply(ImmutableList.> of()), ""); + } + + public void testOneMap() { + assertEquals( + FN.apply(ImmutableList.> of(ImmutableMap.of("key1", "value1", "key2", "value2"))), + "key1 value1\nkey2 value2"); + } + + public void testValueEncodesNewlines() { + assertEquals( + FN.apply(ImmutableList.> of(ImmutableMap.of("key1", "value1\n", "key2", "value2"))), + "key1 value1\\n\nkey2 value2"); + } + + public void testTwoMaps() { + assertEquals(FN.apply(ImmutableList.> of(ImmutableMap.of("key1", "value1", "key2", "value2"), + ImmutableMap.of("key1", "v1", "key2", "v2"))), "key1 value1\nkey2 value2\n\nkey1 v1\nkey2 v2"); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java index 39ef3bdf2e..f3ca0396d6 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java @@ -25,12 +25,11 @@ import java.io.IOException; import java.net.URI; import java.util.Map; +import org.jclouds.cloudsigma.domain.ClaimType; import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.cloudsigma.domain.DriveMetrics; +import org.jclouds.cloudsigma.domain.DriveStatus; import org.jclouds.cloudsigma.domain.DriveType; -import org.jclouds.elasticstack.domain.ClaimType; -import org.jclouds.elasticstack.domain.DriveMetrics; -import org.jclouds.elasticstack.domain.DriveStatus; -import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; import org.jclouds.util.Utils; import org.testng.annotations.Test; @@ -45,7 +44,7 @@ import com.google.common.collect.ImmutableSet; public class MapToDriveInfoTest { public static DriveInfo ONE = new DriveInfo.Builder() .status(DriveStatus.ACTIVE) - .tags(ImmutableSet.of("networking", "security", "gateway")) + .use(ImmutableSet.of("networking", "security", "gateway")) .name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") .bits(64) .url(URI.create("http://www.ubuntu.com")) @@ -72,10 +71,9 @@ public class MapToDriveInfoTest { .free(true)// .type(DriveType.DISK)// .size(8589934592l)// - .userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz")).build(); + .build(); - private static final MapToDriveInfo MAP_TO_DRIVE = new MapToDriveInfo( - new org.jclouds.elasticstack.functions.MapToDriveInfo()); + private static final MapToDriveInfo MAP_TO_DRIVE = new MapToDriveInfo(); public void testEmptyMapReturnsNull() { assertEquals(MAP_TO_DRIVE.apply(ImmutableMap. of()), null); @@ -90,7 +88,7 @@ public class MapToDriveInfoTest { public void testComplete() throws IOException { Map input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( - Utils.toStringAndClose(MapToDriveInfoTest.class.getResourceAsStream("/cloudsigma/drive.txt"))).get(0); + Utils.toStringAndClose(MapToDriveInfoTest.class.getResourceAsStream("/drive.txt"))).get(0); assertEquals(MAP_TO_DRIVE.apply(input), ONE); diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java index e9fc095742..e8eed37b99 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java @@ -25,21 +25,21 @@ import java.io.IOException; import java.util.Date; import java.util.Map; -import org.jclouds.elasticstack.domain.DriveMetrics; -import org.jclouds.elasticstack.domain.IDEDevice; -import org.jclouds.elasticstack.domain.MediaType; -import org.jclouds.elasticstack.domain.Model; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.domain.ServerMetrics; -import org.jclouds.elasticstack.domain.ServerStatus; -import org.jclouds.elasticstack.domain.VNC; -import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; -import org.jclouds.elasticstack.functions.MapToDevices; -import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; -import org.jclouds.elasticstack.functions.MapToDriveMetrics; -import org.jclouds.elasticstack.functions.MapToNICs; -import org.jclouds.elasticstack.functions.MapToServerMetrics; +import org.jclouds.cloudsigma.domain.DriveMetrics; +import org.jclouds.cloudsigma.domain.IDEDevice; +import org.jclouds.cloudsigma.domain.MediaType; +import org.jclouds.cloudsigma.domain.Model; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.domain.ServerMetrics; +import org.jclouds.cloudsigma.domain.ServerStatus; +import org.jclouds.cloudsigma.domain.VNC; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; +import org.jclouds.cloudsigma.functions.MapToDevices; +import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; +import org.jclouds.cloudsigma.functions.MapToDriveMetrics; +import org.jclouds.cloudsigma.functions.MapToNICs; +import org.jclouds.cloudsigma.functions.MapToServerMetrics; import org.jclouds.util.Utils; import org.testng.annotations.Test; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java index 744f6aafb8..16d63f2222 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java @@ -21,11 +21,11 @@ package org.jclouds.cloudsigma.functions; import static org.testng.Assert.assertEquals; -import org.jclouds.elasticstack.domain.IDEDevice; -import org.jclouds.elasticstack.domain.Model; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.VNC; +import org.jclouds.cloudsigma.domain.IDEDevice; +import org.jclouds.cloudsigma.domain.Model; +import org.jclouds.cloudsigma.domain.NIC; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.VNC; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java new file mode 100644 index 0000000000..13076a59b0 --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.util.Set; + +import org.jclouds.cloudsigma.functions.SplitNewlines; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSortedSet; +import com.google.inject.Guice; + +/** + * Tests behavior of {@code NewlineDelimitedStringHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class SplitNewlinesTest { + + static Function> createParser() { + return Guice.createInjector().getInstance(SplitNewlines.class); + } + + public void test() { + InputStream is = SplitNewlinesTest.class.getResourceAsStream("/uuids.txt"); + Set list = createParser().apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))); + assertEquals(list, ImmutableSortedSet.of("7e8ab721-81c9-4cb9-a651-4cafbfe1501c", + "ea6a8fdb-dab3-4d06-86c2-41a5835e6ed9", "74744450-d338-4087-b3b8-59b505110a57")); + } + +} diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java new file mode 100644 index 0000000000..d613f4532f --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java @@ -0,0 +1,141 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.handlers; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.reportMatcher; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +import java.net.URI; + +import org.easymock.IArgumentMatcher; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +import com.google.inject.Guice; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class CloudSigmaErrorHandlerTest { + + @Test + public void test400MakesIllegalArgumentException() { + assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 400, "", "Bad Request", + IllegalArgumentException.class); + } + + @Test + public void test400MakesResourceNotFoundExceptionOnInfo() { + assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo/info"), 400, "", "", + ResourceNotFoundException.class); + } + + @Test + public void test400MakesResourceNotFoundExceptionOnMessageNotFound() { + assertCodeMakes( + "GET", + URI.create("https://cloudsigma.com/foo"), + 400, + "", + "errors:system Drive 8f9b42b1-26de-49ad-a3fd-d4fa06524339 could not be found. Please re-validate your entry.", + ResourceNotFoundException.class); + } + + @Test + public void test401MakesAuthorizationException() { + assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 401, "", "Unauthorized", + AuthorizationException.class); + } + + @Test + public void test404MakesResourceNotFoundException() { + assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 404, "", "Not Found", + ResourceNotFoundException.class); + } + + @Test + public void test405MakesIllegalArgumentException() { + assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 405, "", "Method Not Allowed", + IllegalArgumentException.class); + } + + @Test + public void test409MakesIllegalStateException() { + assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 409, "", "Conflict", + IllegalStateException.class); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, + Class expected) { + assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, + String content, Class expected) { + + CloudSigmaErrorHandler function = Guice.createInjector().getInstance(CloudSigmaErrorHandler.class); + + HttpCommand command = createMock(HttpCommand.class); + HttpRequest request = new HttpRequest(method, uri); + HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Utils + .toInputStream(content))); + response.getPayload().getContentMetadata().setContentType(contentType); + + expect(command.getRequest()).andReturn(request).atLeastOnce(); + command.setException(classEq(expected)); + + replay(command); + + function.handleError(command, response); + + verify(command); + } + + public static Exception classEq(final Class in) { + reportMatcher(new IArgumentMatcher() { + + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("classEq("); + buffer.append(in); + buffer.append(")"); + } + + @Override + public boolean matches(Object arg) { + return arg.getClass() == in; + } + + }); + return null; + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/resources/create_drive.txt b/sandbox/cloudsigma/src/test/resources/create_drive.txt new file mode 100644 index 0000000000..44ce187567 --- /dev/null +++ b/sandbox/cloudsigma/src/test/resources/create_drive.txt @@ -0,0 +1,5 @@ +name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System +size 8589934592 +claim:type shared +readers ffffffff-ffff-ffff-ffff-ffffffffffff +use tag1 tag2 \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/resources/create_server.txt b/sandbox/cloudsigma/src/test/resources/create_server.txt new file mode 100644 index 0000000000..474d4d7ce1 --- /dev/null +++ b/sandbox/cloudsigma/src/test/resources/create_server.txt @@ -0,0 +1,11 @@ +name TestServer +cpu 2000 +smp auto +mem 1024 +persistent false +boot ide:0:0 +ide:0:0 08c92dd5-70a0-4f51-83d2-835919d254df +ide:0:0:media disk +nic:0:model e1000 +vnc:ip auto +vnc:password XXXXXXXX \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/resources/cloudsigma/drive.txt b/sandbox/cloudsigma/src/test/resources/drive.txt similarity index 100% rename from sandbox/cloudsigma/src/test/resources/cloudsigma/drive.txt rename to sandbox/cloudsigma/src/test/resources/drive.txt diff --git a/sandbox/cloudsigma/src/test/resources/drive_data.txt b/sandbox/cloudsigma/src/test/resources/drive_data.txt new file mode 100644 index 0000000000..44ce187567 --- /dev/null +++ b/sandbox/cloudsigma/src/test/resources/drive_data.txt @@ -0,0 +1,5 @@ +name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System +size 8589934592 +claim:type shared +readers ffffffff-ffff-ffff-ffff-ffffffffffff +use tag1 tag2 \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/resources/log4j.xml b/sandbox/cloudsigma/src/test/resources/log4j.xml new file mode 100644 index 0000000000..7343ec00e2 --- /dev/null +++ b/sandbox/cloudsigma/src/test/resources/log4j.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/resources/new_server.txt b/sandbox/cloudsigma/src/test/resources/new_server.txt new file mode 100644 index 0000000000..1dfbad99eb --- /dev/null +++ b/sandbox/cloudsigma/src/test/resources/new_server.txt @@ -0,0 +1,24 @@ +ide:0:0:write:requests 0 +boot ide:0:0 +vnc:password XXXXXXXX +ide:0:0 403c9a86-0aab-4e47-aa95-e9768021c4c1 +ide:0:0:read:requests 0 +ide:0:0:read:bytes 0 +vnc:ip 83.222.249.221 +tx:packets 0 +tx 0 +rx 0 +smp 1 +mem 512 +nic:0:model e1000 +status active +started 1292695612 +rx:packets 0 +user 2f6244eb-50bc-4403-847e-f03cc3706a1f +ide:0:0:media disk +name adriancole.test +persistent true +nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595 +server bd98615a-6f74-4d63-ad1e-b13338b9356a +ide:0:0:write:bytes 0 +cpu 1000 \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/resources/servers.txt b/sandbox/cloudsigma/src/test/resources/servers.txt new file mode 100644 index 0000000000..a3d1ff1b46 --- /dev/null +++ b/sandbox/cloudsigma/src/test/resources/servers.txt @@ -0,0 +1,40 @@ +ide:0:0:write:requests 3698 +boot ide:0:0 +vnc:password HfHzVmLT +ide:0:0 4af85ed3-0caa-4736-8a26-a33d7de0a122 +ide:0:0:read:requests 11154 +ide:0:0:read:bytes 45686784 +vnc:ip 46.20.114.124 +tx:packets 31 +tx 2550 +rx 455530 +smp 1 +mem 1024 +nic:0:model e1000 +status active +started 1291493868 +rx:packets 7583 +user 2f6244eb-50bc-4403-847e-f03cc3706a1f +name jo +persistent true +nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595 +server f8bee9cd-8e4b-4a05-8593-1314e3bfe49b +nic:0:dhcp 46.20.114.124 +ide:0:0:write:bytes 15147008 +cpu 2000 + +status stopped +name Demo +mem 1024 +boot ide:0:0 +vnc:password HWbjvrg2 +persistent true +server 0f962616-2071-4173-be79-7dd084271edf +smp auto +nic:0:dhcp auto +user 2f6244eb-50bc-4403-847e-f03cc3706a1f +nic:0:model e1000 +vnc:ip auto +ide:0:0 853bb98a-4fff-4c2f-a265-97c363f19ea5 +cpu 2000 +ide:0:0:media cdrom diff --git a/sandbox/cloudsigma/src/test/resources/uuids.txt b/sandbox/cloudsigma/src/test/resources/uuids.txt new file mode 100644 index 0000000000..092a4f8d6d --- /dev/null +++ b/sandbox/cloudsigma/src/test/resources/uuids.txt @@ -0,0 +1,3 @@ +7e8ab721-81c9-4cb9-a651-4cafbfe1501c +ea6a8fdb-dab3-4d06-86c2-41a5835e6ed9 +74744450-d338-4087-b3b8-59b505110a57 diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackAsyncClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackAsyncClient.java deleted file mode 100644 index 43ddd019cc..0000000000 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackAsyncClient.java +++ /dev/null @@ -1,199 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.elasticstack; - -import java.util.Set; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.MediaType; - -import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString; -import org.jclouds.elasticstack.binders.BindDriveToPlainTextString; -import org.jclouds.elasticstack.binders.BindServerToPlainTextString; -import org.jclouds.elasticstack.domain.Drive; -import org.jclouds.elasticstack.domain.DriveData; -import org.jclouds.elasticstack.domain.DriveInfo; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; -import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToServerInfo; -import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; -import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; -import org.jclouds.elasticstack.functions.SplitNewlines; -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.ExceptionParser; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; - -import com.google.common.util.concurrent.ListenableFuture; - -/** - * Provides asynchronous access to elasticstack via their REST API. - *

- * - * @see ElasticStackClient - * @see - * @author Adrian Cole - */ -@RequestFilters(BasicAuthentication.class) -@Consumes(MediaType.TEXT_PLAIN) -public interface CommonElasticStackAsyncClient { - - /** - * @see ElasticStackClient#listServers() - */ - @GET - @Path("/servers/list") - @ResponseParser(SplitNewlines.class) - ListenableFuture> listServers(); - - /** - * @see ElasticStackClient#listServerInfo() - */ - @GET - @Path("/servers/info") - @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class) - ListenableFuture> listServerInfo(); - - /** - * @see ElasticStackClient#getServerInfo - */ - @GET - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) - @Path("/servers/{uuid}/info") - ListenableFuture getServerInfo(@PathParam("uuid") String uuid); - - /** - * @see ElasticStackClient#createServer - */ - @POST - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) - @Path("/servers/create/stopped") - ListenableFuture createServer( - @BinderParam(BindServerToPlainTextString.class) Server createServer); - - /** - * @see ElasticStackClient#setServerConfiguration - */ - @POST - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) - @Path("/servers/{uuid}/set") - ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, - @BinderParam(BindServerToPlainTextString.class) Server setServer); - - /** - * @see ElasticStackClient#destroyServer - */ - @POST - @Path("/servers/{uuid}/destroy") - @ExceptionParser(ReturnVoidOnNotFoundOr404.class) - ListenableFuture destroyServer(@PathParam("uuid") String uuid); - - /** - * @see ElasticStackClient#startServer - */ - @POST - @Path("/servers/{uuid}/start") - ListenableFuture startServer(@PathParam("uuid") String uuid); - - /** - * @see ElasticStackClient#stopServer - */ - @POST - @Path("/servers/{uuid}/stop") - ListenableFuture stopServer(@PathParam("uuid") String uuid); - - /** - * @see ElasticStackClient#shutdownServer - */ - @POST - @Path("/servers/{uuid}/shutdown") - ListenableFuture shutdownServer(@PathParam("uuid") String uuid); - - /** - * @see ElasticStackClient#resetServer - */ - @POST - @Path("/servers/{uuid}/reset") - ListenableFuture resetServer(@PathParam("uuid") String uuid); - - /** - * @see ElasticStackClient#listDrives() - */ - @GET - @Path("/drives/list") - @ResponseParser(SplitNewlines.class) - ListenableFuture> listDrives(); - - /** - * @see ElasticStackClient#listDriveInfo() - */ - @GET - @Path("/drives/info") - @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class) - ListenableFuture> listDriveInfo(); - - /** - * @see ElasticStackClient#getDriveInfo - */ - @GET - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) - @Path("/drives/{uuid}/info") - ListenableFuture getDriveInfo(@PathParam("uuid") String uuid); - - /** - * @see ElasticStackClient#createDrive - */ - @POST - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) - @Path("/drives/create") - ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); - - /** - * @see ElasticStackClient#setDriveData - */ - @POST - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) - @Path("/drives/{uuid}/set") - ListenableFuture setDriveData(@PathParam("uuid") String uuid, - @BinderParam(BindDriveDataToPlainTextString.class) DriveData setDrive); - - /** - * @see ElasticStackClient#destroyDrive - */ - @POST - @Path("/drives/{uuid}/destroy") - @ExceptionParser(ReturnVoidOnNotFoundOr404.class) - ListenableFuture destroyDrive(@PathParam("uuid") String uuid); - -} diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java deleted file mode 100644 index 78632ca642..0000000000 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.elasticstack; - -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import org.jclouds.concurrent.Timeout; -import org.jclouds.elasticstack.domain.Drive; -import org.jclouds.elasticstack.domain.DriveData; -import org.jclouds.elasticstack.domain.DriveInfo; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.ServerInfo; - -/** - * Provides synchronous access to elasticstack. - *

- * - * @see ElasticStackAsyncClient - * @see - * @author Adrian Cole - */ -@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) -public interface CommonElasticStackClient { - /** - * list of server uuids in your account - * - * @return or empty set if no servers are found - */ - Set listServers(); - - /** - * Get all servers info - * - * @return or empty set if no servers are found - */ - Set listServerInfo(); - - /** - * @param uuid - * what to get - * @return null, if not found - */ - ServerInfo getServerInfo(String uuid); - - /** - * create a new server - * - * @param server - * @return newly created server - */ - ServerInfo createServer(Server server); - - /** - * set server configuration - * - * @param uuid - * what server to change - * @param serverData - * what values to change - * @return new data - */ - ServerInfo setServerConfiguration(String uuid, Server server); - - /** - * Destroy a server - * - * @param uuid - * what to destroy - */ - void destroyServer(String uuid); - - /** - * Start a server - * - * @param uuid - * what to start - */ - void startServer(String uuid); - - /** - * Stop a server - *

- * Kills the server immediately, equivalent to a power failure. Server reverts to a stopped - * status if it is persistent and is automatically destroyed otherwise. - * - * @param uuid - * what to stop - */ - void stopServer(String uuid); - - /** - * Shutdown a server - *

- * Sends the server an ACPI power-down event. Server reverts to a stopped status if it is - * persistent and is automatically destroyed otherwise. - *

note

behaviour on shutdown depends on how your server OS is set up to respond to an - * ACPI power button signal. - * - * @param uuid - * what to shutdown - */ - void shutdownServer(String uuid); - - /** - * Reset a server - * - * @param uuid - * what to reset - */ - void resetServer(String uuid); - - /** - * list of drive uuids in your account - * - * @return or empty set if no drives are found - */ - Set listDrives(); - - /** - * Get all drives info - * - * @return or empty set if no drives are found - */ - Set listDriveInfo(); - - /** - * @param uuid - * what to get - * @return null, if not found - */ - DriveInfo getDriveInfo(String uuid); - - /** - * create a new drive - * - * @param createDrive - * required parameters: name, size - * @return newly created drive - */ - DriveInfo createDrive(Drive createDrive); - - /** - * set extra drive data - * - * @param uuid - * what drive to change - * @param driveData - * what values to change - * @return new data - */ - DriveInfo setDriveData(String uuid, DriveData driveData); - - /** - * Destroy a drive - * - * @param uuid - * what to delete - */ - void destroyDrive(String uuid); - -} diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java index 30423756a1..7dd0959117 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java @@ -19,19 +19,31 @@ package org.jclouds.elasticstack; +import java.util.Set; + import javax.ws.rs.Consumes; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString; +import org.jclouds.elasticstack.binders.BindDriveToPlainTextString; import org.jclouds.elasticstack.binders.BindServerToPlainTextString; +import org.jclouds.elasticstack.domain.Drive; +import org.jclouds.elasticstack.domain.DriveData; +import org.jclouds.elasticstack.domain.DriveInfo; import org.jclouds.elasticstack.domain.ImageConversionType; import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToServerInfo; +import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; +import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; import org.jclouds.elasticstack.functions.ReturnPayload; +import org.jclouds.elasticstack.functions.SplitNewlines; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.io.Payload; import org.jclouds.rest.annotations.BinderParam; @@ -53,7 +65,140 @@ import com.google.common.util.concurrent.ListenableFuture; */ @RequestFilters(BasicAuthentication.class) @Consumes(MediaType.TEXT_PLAIN) -public interface ElasticStackAsyncClient extends CommonElasticStackAsyncClient { +public interface ElasticStackAsyncClient { + + /** + * @see ElasticStackClient#listServers() + */ + @GET + @Path("/servers/list") + @ResponseParser(SplitNewlines.class) + ListenableFuture> listServers(); + + /** + * @see ElasticStackClient#listServerInfo() + */ + @GET + @Path("/servers/info") + @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class) + ListenableFuture> listServerInfo(); + + /** + * @see ElasticStackClient#getServerInfo + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/{uuid}/info") + ListenableFuture getServerInfo(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#createServer + */ + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/create/stopped") + ListenableFuture createServer( + @BinderParam(BindServerToPlainTextString.class) Server createServer); + + /** + * @see ElasticStackClient#setServerConfiguration + */ + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/{uuid}/set") + ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, + @BinderParam(BindServerToPlainTextString.class) Server setServer); + + /** + * @see ElasticStackClient#destroyServer + */ + @POST + @Path("/servers/{uuid}/destroy") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture destroyServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#startServer + */ + @POST + @Path("/servers/{uuid}/start") + ListenableFuture startServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#stopServer + */ + @POST + @Path("/servers/{uuid}/stop") + ListenableFuture stopServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#shutdownServer + */ + @POST + @Path("/servers/{uuid}/shutdown") + ListenableFuture shutdownServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#resetServer + */ + @POST + @Path("/servers/{uuid}/reset") + ListenableFuture resetServer(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#listDrives() + */ + @GET + @Path("/drives/list") + @ResponseParser(SplitNewlines.class) + ListenableFuture> listDrives(); + + /** + * @see ElasticStackClient#listDriveInfo() + */ + @GET + @Path("/drives/info") + @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class) + ListenableFuture> listDriveInfo(); + + /** + * @see ElasticStackClient#getDriveInfo + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) + @Path("/drives/{uuid}/info") + ListenableFuture getDriveInfo(@PathParam("uuid") String uuid); + + /** + * @see ElasticStackClient#createDrive + */ + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) + @Path("/drives/create") + ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); + + /** + * @see ElasticStackClient#setDriveData + */ + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) + @Path("/drives/{uuid}/set") + ListenableFuture setDriveData(@PathParam("uuid") String uuid, + @BinderParam(BindDriveDataToPlainTextString.class) DriveData setDrive); + + /** + * @see ElasticStackClient#destroyDrive + */ + @POST + @Path("/drives/{uuid}/destroy") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture destroyDrive(@PathParam("uuid") String uuid); /** * @see ElasticStackClient#createAndStartServer diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java index 7fb5631415..763b04a2bf 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java @@ -19,9 +19,13 @@ package org.jclouds.elasticstack; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.elasticstack.domain.Drive; +import org.jclouds.elasticstack.domain.DriveData; +import org.jclouds.elasticstack.domain.DriveInfo; import org.jclouds.elasticstack.domain.ImageConversionType; import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerInfo; @@ -36,7 +40,143 @@ import org.jclouds.io.Payload; * @author Adrian Cole */ @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) -public interface ElasticStackClient extends CommonElasticStackClient { +public interface ElasticStackClient { + /** + * list of server uuids in your account + * + * @return or empty set if no servers are found + */ + Set listServers(); + + /** + * Get all servers info + * + * @return or empty set if no servers are found + */ + Set listServerInfo(); + + /** + * @param uuid + * what to get + * @return null, if not found + */ + ServerInfo getServerInfo(String uuid); + + /** + * create a new server + * + * @param server + * @return newly created server + */ + ServerInfo createServer(Server server); + + /** + * set server configuration + * + * @param uuid + * what server to change + * @param serverData + * what values to change + * @return new data + */ + ServerInfo setServerConfiguration(String uuid, Server server); + + /** + * Destroy a server + * + * @param uuid + * what to destroy + */ + void destroyServer(String uuid); + + /** + * Start a server + * + * @param uuid + * what to start + */ + void startServer(String uuid); + + /** + * Stop a server + *

+ * Kills the server immediately, equivalent to a power failure. Server reverts to a stopped + * status if it is persistent and is automatically destroyed otherwise. + * + * @param uuid + * what to stop + */ + void stopServer(String uuid); + + /** + * Shutdown a server + *

+ * Sends the server an ACPI power-down event. Server reverts to a stopped status if it is + * persistent and is automatically destroyed otherwise. + *

note

behaviour on shutdown depends on how your server OS is set up to respond to an + * ACPI power button signal. + * + * @param uuid + * what to shutdown + */ + void shutdownServer(String uuid); + + /** + * Reset a server + * + * @param uuid + * what to reset + */ + void resetServer(String uuid); + + /** + * list of drive uuids in your account + * + * @return or empty set if no drives are found + */ + Set listDrives(); + + /** + * Get all drives info + * + * @return or empty set if no drives are found + */ + Set listDriveInfo(); + + /** + * @param uuid + * what to get + * @return null, if not found + */ + DriveInfo getDriveInfo(String uuid); + + /** + * create a new drive + * + * @param createDrive + * required parameters: name, size + * @return newly created drive + */ + DriveInfo createDrive(Drive createDrive); + + /** + * set extra drive data + * + * @param uuid + * what drive to change + * @param driveData + * what values to change + * @return new data + */ + DriveInfo setDriveData(String uuid, DriveData driveData); + + /** + * Destroy a drive + * + * @param uuid + * what to delete + */ + void destroyDrive(String uuid); /** * create and start a new server diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java index f6d232cccc..53a8f9b741 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java @@ -37,7 +37,7 @@ public class ElasticStackPropertiesBuilder extends PropertiesBuilder { protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_API_VERSION, "1.0"); - properties.setProperty(PROPERTY_API_VERSION, "IL9vs34d"); + properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d"); return properties; } diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java index 4d6988dadd..6e27de97a8 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java @@ -37,7 +37,6 @@ import org.jclouds.compute.domain.Volume; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.suppliers.DefaultLocationSupplier; import org.jclouds.domain.Location; -import org.jclouds.elasticstack.CommonElasticStackClient; import org.jclouds.elasticstack.ElasticStackAsyncClient; import org.jclouds.elasticstack.ElasticStackClient; import org.jclouds.elasticstack.compute.ElasticStackComputeServiceAdapter; @@ -129,12 +128,6 @@ public class ElasticStackComputeServiceContextModule }.getType()); } - @Provides - @Singleton - protected CommonElasticStackClient convert(ElasticStackClient in) { - return in; - } - @Provides @Singleton protected Predicate supplyDriveUnclaimed(DriveClaimed driveClaimed, diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java index de0dee3358..bfed641561 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java @@ -46,8 +46,6 @@ public class Server extends Item { protected Set bootDeviceIds = ImmutableSet.of(); protected List nics = ImmutableList.of(); protected VNC vnc; - // TODO cloudsigma specific - protected String description; public Builder cpu(int cpu) { this.cpu = cpu; @@ -89,11 +87,6 @@ public class Server extends Item { return this; } - public Builder description(String description) { - this.description = description; - return this; - } - /** * {@inheritDoc} */ @@ -127,15 +120,13 @@ public class Server extends Item { } public Server build() { - return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, - vnc, description); + return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc); } public static Builder fromServer(Server in) { return new Builder().uuid(in.getUuid()).name(in.getName()).cpu(in.getCpu()).mem(in.getMem()) - .persistent(in.isPersistent()).description(in.getDescription()).devices(in.getDevices()) - .bootDeviceIds(in.getBootDeviceIds()).tags(in.getTags()).userMetadata(in.getUserMetadata()) - .nics(in.getNics()).vnc(in.getVnc()); + .persistent(in.isPersistent()).devices(in.getDevices()).bootDeviceIds(in.getBootDeviceIds()) + .tags(in.getTags()).userMetadata(in.getUserMetadata()).nics(in.getNics()).vnc(in.getVnc()); } } @@ -148,12 +139,10 @@ public class Server extends Item { protected final Set bootDeviceIds; protected final List nics; protected final VNC vnc; - @Nullable - private final String description; public Server(@Nullable String uuid, String name, int cpu, @Nullable Integer smp, int mem, boolean persistent, Map devices, Iterable bootDeviceIds, Iterable tags, - Map userMetadata, Iterable nics, VNC vnc, String description) { + Map userMetadata, Iterable nics, VNC vnc) { super(uuid, name, tags, userMetadata); this.cpu = cpu; this.smp = smp; @@ -163,7 +152,6 @@ public class Server extends Item { this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds")); this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics")); this.vnc = checkNotNull(vnc, "vnc"); - this.description = description; } /** @@ -224,18 +212,12 @@ public class Server extends Item { return vnc; } - // TODO undocumented - public String getDescription() { - return description; - } - @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((bootDeviceIds == null) ? 0 : bootDeviceIds.hashCode()); result = prime * result + cpu; - result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((devices == null) ? 0 : devices.hashCode()); result = prime * result + mem; result = prime * result + ((nics == null) ? 0 : nics.hashCode()); @@ -261,11 +243,6 @@ public class Server extends Item { return false; if (cpu != other.cpu) return false; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; if (devices == null) { if (other.devices != null) return false; @@ -297,8 +274,7 @@ public class Server extends Item { public String toString() { return "[uuid=" + uuid + ", name=" + name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", cpu=" + cpu + ", smp=" + smp + ", mem=" + mem + ", persistent=" + persistent + ", devices=" + devices - + ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + ", description=" + description - + "]"; + + ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + "]"; } } \ No newline at end of file diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java index 45a54314e7..1240b2d9fd 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java @@ -120,14 +120,6 @@ public class ServerInfo extends Server { return Builder.class.cast(super.vnc(vnc)); } - /** - * {@inheritDoc} - */ - @Override - public Builder description(String description) { - return Builder.class.cast(super.description(description)); - } - /** * {@inheritDoc} */ @@ -162,7 +154,7 @@ public class ServerInfo extends Server { public ServerInfo build() { return new ServerInfo(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, - vnc, description, status, started, user, metrics); + vnc, status, started, user, metrics); } } @@ -175,9 +167,9 @@ public class ServerInfo extends Server { public ServerInfo(String uuid, String name, int cpu, Integer smp, int mem, boolean persistent, Map devices, Iterable bootDeviceIds, Iterable tags, - Map userMetadata, Iterable nics, VNC vnc, String description, ServerStatus status, - Date started, String user, @Nullable ServerMetrics metrics) { - super(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc, description); + Map userMetadata, Iterable nics, VNC vnc, ServerStatus status, Date started, String user, + @Nullable ServerMetrics metrics) { + super(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc); this.status = status; this.started = started; this.user = user; diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java index 8293bd1a0c..ae7671a1ff 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java @@ -62,7 +62,6 @@ public class MapToServerInfo implements Function, ServerInfo return null; ServerInfo.Builder builder = new ServerInfo.Builder(); builder.name(from.get("name")); - builder.description(from.get("description")); builder.persistent(Boolean.parseBoolean(from.get("persistent"))); if (from.containsKey("tags")) builder.tags(Splitter.on(' ').split(from.get("tags"))); diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java index cc6b607a8c..73af68828d 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java @@ -1,16 +1,35 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + package org.jclouds.elasticstack.predicates; import static com.google.common.base.Preconditions.checkNotNull; import javax.annotation.Resource; +import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.elasticstack.CommonElasticStackClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.jclouds.elasticstack.domain.DriveInfo; import org.jclouds.logging.Logger; import com.google.common.base.Predicate; -import com.google.inject.Inject; /** * @@ -19,13 +38,13 @@ import com.google.inject.Inject; @Singleton public class DriveClaimed implements Predicate { - private final CommonElasticStackClient client; + private final ElasticStackClient client; @Resource protected Logger logger = Logger.NULL; @Inject - public DriveClaimed(CommonElasticStackClient client) { + public DriveClaimed(ElasticStackClient client) { this.client = client; } diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java deleted file mode 100644 index 0eda00b6e1..0000000000 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java +++ /dev/null @@ -1,348 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.elasticstack; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.io.IOException; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; - -import org.jclouds.Constants; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.domain.Credentials; -import org.jclouds.elasticstack.domain.ClaimType; -import org.jclouds.elasticstack.domain.CreateDriveRequest; -import org.jclouds.elasticstack.domain.DriveData; -import org.jclouds.elasticstack.domain.DriveInfo; -import org.jclouds.elasticstack.domain.DriveStatus; -import org.jclouds.elasticstack.domain.IDEDevice; -import org.jclouds.elasticstack.domain.Model; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.domain.ServerStatus; -import org.jclouds.elasticstack.predicates.DriveClaimed; -import org.jclouds.elasticstack.util.Servers; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.net.IPSocket; -import org.jclouds.predicates.InetSocketAddressConnect; -import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.RestContext; -import org.jclouds.ssh.ExecResponse; -import org.jclouds.ssh.SshClient; -import org.jclouds.ssh.jsch.config.JschSshClientModule; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.gson.Gson; -import com.google.inject.Guice; -import com.google.inject.Module; - -/** - * Tests behavior of {@code CommonElasticStackClient} - * - * @author Adrian Cole - */ -@Test(groups = "live", sequential = true) -public abstract class CommonElasticStackClientLiveTest { - - protected long driveSize = 1 * 1024 * 1024 * 1024l; - protected int maxDriveImageTime = 120; - protected String vncPassword = "Il0veVNC"; - protected S client; - protected RestContext context; - protected Predicate socketTester; - - protected String provider = "elasticstack"; - protected String identity; - protected String credential; - protected String endpoint; - protected String apiversion; - protected Predicate driveNotClaimed; - - protected void setupCredentials() { - identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = System.getProperty("test." + provider + ".credential"); - endpoint = System.getProperty("test." + provider + ".endpoint"); - apiversion = System.getProperty("test." + provider + ".apiversion"); - } - - protected Properties setupProperties() { - Properties overrides = new Properties(); - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); - overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - overrides.setProperty(provider + ".identity", identity); - if (credential != null) - overrides.setProperty(provider + ".credential", credential); - if (endpoint != null) - overrides.setProperty(provider + ".endpoint", endpoint); - if (apiversion != null) - overrides.setProperty(provider + ".apiversion", apiversion); - return overrides; - } - - @BeforeGroups(groups = "live") - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - - client = context.getApi(); - driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, - 1, TimeUnit.SECONDS); - socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, - TimeUnit.SECONDS); - } - - @Test - public void testListServers() throws Exception { - Set servers = client.listServers(); - assertNotNull(servers); - } - - @Test - public void testListServerInfo() throws Exception { - Set servers = client.listServerInfo(); - assertNotNull(servers); - } - - @Test - public void testGetServer() throws Exception { - for (String serverUUID : client.listServers()) { - assert !"".equals(serverUUID); - assertNotNull(client.getServerInfo(serverUUID)); - } - } - - @Test - public void testListDrives() throws Exception { - Set drives = client.listDrives(); - assertNotNull(drives); - } - - @Test - public void testListDriveInfo() throws Exception { - Set drives = client.listDriveInfo(); - assertNotNull(drives); - } - - @Test - public void testGetDrive() throws Exception { - for (String driveUUID : client.listDrives()) { - assert !"".equals(driveUUID); - assertNotNull(client.getDriveInfo(driveUUID)); - } - } - - protected String prefix = System.getProperty("user.name") + ".test"; - protected DriveInfo drive; - - @Test - public void testCreateDrive() throws Exception { - drive = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(driveSize).build()); - checkCreatedDrive(); - - DriveInfo newInfo = client.getDriveInfo(drive.getUuid()); - checkDriveMatchesGet(newInfo); - - } - - protected void checkDriveMatchesGet(DriveInfo newInfo) { - assertEquals(newInfo.getUuid(), drive.getUuid()); - } - - protected void checkCreatedDrive() { - assertNotNull(drive.getUuid()); - assertNotNull(drive.getUser()); - assertEquals(drive.getName(), prefix); - assertEquals(drive.getSize(), driveSize); - assertEquals(drive.getStatus(), DriveStatus.ACTIVE); - // for some reason, these occasionally return as 4096,1 - // assertEquals(info.getReadBytes(), 0l); - // assertEquals(info.getWriteBytes(), 0l); - // assertEquals(info.getReadRequests(), 0l); - // assertEquals(info.getWriteRequests(), 0l); - assertEquals(drive.getEncryptionCipher(), "aes-xts-plain"); - } - - @Test(dependsOnMethods = "testCreateDrive") - public void testSetDriveData() throws Exception { - - DriveInfo drive2 = client.setDriveData( - drive.getUuid(), - new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous") - .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")) - .tags(ImmutableSet.of("networking", "security", "gateway")) - .userMetadata(ImmutableMap.of("foo", "bar")).build()); - - assertNotNull(drive2.getUuid(), drive.getUuid()); - assertEquals(drive2.getName(), "rediculous"); - assertEquals(drive2.getClaimType(), ClaimType.SHARED); - assertEquals(drive2.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")); - assertEquals(drive2.getTags(), ImmutableSet.of("networking", "security", "gateway")); - assertEquals(drive2.getUserMetadata(), ImmutableMap.of("foo", "bar")); - drive = drive2; - } - - protected ServerInfo server; - - protected abstract void prepareDrive(); - - @Test(dependsOnMethods = "testSetDriveData") - public void testCreateAndStartServer() throws Exception { - Logger.getAnonymousLogger().info("preparing drive"); - prepareDrive(); - - Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build(); - - Logger.getAnonymousLogger().info("starting server"); - server = client.createServer(serverRequest); - client.startServer(server.getUuid()); - server = client.getServerInfo(server.getUuid()); - checkStartedServer(); - - Server newInfo = client.getServerInfo(server.getUuid()); - checkServerMatchesGet(newInfo); - - } - - protected void checkServerMatchesGet(Server newInfo) { - assertEquals(newInfo.getUuid(), server.getUuid()); - } - - protected void checkStartedServer() { - System.out.println(new Gson().toJson(server)); - assertNotNull(server.getUuid()); - assertNotNull(server.getUser()); - assertEquals(server.getName(), prefix); - assertEquals(server.isPersistent(), true); - assertEquals(server.getDevices(), - ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build())); - assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0")); - assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp()); - assertEquals(server.getNics().get(0).getModel(), Model.E1000); - assertEquals(server.getStatus(), ServerStatus.ACTIVE); - } - - @Test(dependsOnMethods = "testCreateAndStartServer") - public void testConnectivity() throws Exception { - Logger.getAnonymousLogger().info("awaiting vnc"); - assert socketTester.apply(new IPSocket(server.getVnc().getIp(), 5900)) : server; - Logger.getAnonymousLogger().info("awaiting ssh"); - assert socketTester.apply(new IPSocket(server.getNics().get(0).getDhcp(), 22)) : server; - doConnectViaSsh(server, getSshCredentials(server)); - } - - @Test(dependsOnMethods = "testConnectivity") - public void testLifeCycle() throws Exception { - client.stopServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED); - - client.startServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); - - client.resetServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); - - client.shutdownServer(server.getUuid()); - // behavior on shutdown depends on how your server OS is set up to respond to an ACPI power - // button signal - assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo( - server.getUuid()).getStatus() == ServerStatus.STOPPED); - } - - @Test(dependsOnMethods = "testLifeCycle") - public void testSetServerConfiguration() throws Exception { - client.stopServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED); - - ServerInfo server2 = client.setServerConfiguration( - server.getUuid(), - Server.Builder.fromServer(server).name("rediculous") - .tags(ImmutableSet.of("networking", "security", "gateway")) - .userMetadata(ImmutableMap.of("foo", "bar")).build()); - - assertNotNull(server2.getUuid(), server.getUuid()); - assertEquals(server2.getName(), "rediculous"); - checkTagsAndMetadata(server2); - server = server2; - } - - protected void checkTagsAndMetadata(ServerInfo server2) { - assertEquals(server2.getTags(), ImmutableSet.of("networking", "security", "gateway")); - assertEquals(server2.getUserMetadata(), ImmutableMap.of("foo", "bar")); - } - - @Test(dependsOnMethods = "testSetServerConfiguration") - public void testDestroyServer() throws Exception { - client.destroyServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()), null); - } - - @Test(dependsOnMethods = "testDestroyServer") - public void testDestroyDrive() throws Exception { - client.destroyDrive(drive.getUuid()); - assertEquals(client.getDriveInfo(drive.getUuid()), null); - } - - protected void doConnectViaSsh(Server server, Credentials creds) throws IOException { - SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class) - .create(new IPSocket(server.getVnc().getIp(), 22), creds); - try { - ssh.connect(); - ExecResponse hello = ssh.exec("echo hello"); - assertEquals(hello.getOutput().trim(), "hello"); - System.err.println(ssh.exec("df -k").getOutput()); - System.err.println(ssh.exec("mount").getOutput()); - System.err.println(ssh.exec("uname -a").getOutput()); - } finally { - if (ssh != null) - ssh.disconnect(); - } - } - - protected abstract Credentials getSshCredentials(Server server); - - @AfterGroups(groups = "live") - protected void tearDown() { - try { - client.destroyServer(server.getUuid()); - } catch (Exception e) { - // no need to check null or anything as we swallow all - } - try { - client.destroyDrive(drive.getUuid()); - } catch (Exception e) { - - } - if (context != null) - context.close(); - } -} diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java index fbd98ffb68..9704ed8e69 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java @@ -19,27 +19,332 @@ package org.jclouds.elasticstack; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import java.io.IOException; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; +import org.jclouds.Constants; +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.domain.Credentials; +import org.jclouds.elasticstack.domain.ClaimType; import org.jclouds.elasticstack.domain.CreateDriveRequest; +import org.jclouds.elasticstack.domain.DriveData; import org.jclouds.elasticstack.domain.DriveInfo; +import org.jclouds.elasticstack.domain.DriveStatus; +import org.jclouds.elasticstack.domain.IDEDevice; import org.jclouds.elasticstack.domain.ImageConversionType; +import org.jclouds.elasticstack.domain.Model; import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.domain.ServerStatus; +import org.jclouds.elasticstack.predicates.DriveClaimed; +import org.jclouds.elasticstack.util.Servers; import org.jclouds.io.Payloads; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.net.IPSocket; +import org.jclouds.predicates.InetSocketAddressConnect; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.rest.RestContext; +import org.jclouds.ssh.ExecResponse; +import org.jclouds.ssh.SshClient; +import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.util.Utils; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.gson.Gson; +import com.google.inject.Guice; +import com.google.inject.Module; + /** * Tests behavior of {@code ElasticStackClient} * * @author Adrian Cole */ @Test(groups = "live", testName = "elasticstack.ElasticStackClientLiveTest") -public class ElasticStackClientLiveTest extends - CommonElasticStackClientLiveTest { +public class ElasticStackClientLiveTest { + + protected long driveSize = 1 * 1024 * 1024 * 1024l; + protected int maxDriveImageTime = 120; + protected String vncPassword = "Il0veVNC"; + protected ElasticStackClient client; + protected RestContext context; + protected Predicate socketTester; + + protected String provider = "elasticstack"; + protected String identity; + protected String credential; + protected String endpoint; + protected String apiversion; + protected Predicate driveNotClaimed; + + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); + } + + protected Properties setupProperties() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + overrides.setProperty(provider + ".identity", identity); + if (credential != null) + overrides.setProperty(provider + ".credential", credential); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); + return overrides; + } + + @BeforeGroups(groups = "live") + public void setupClient() { + setupCredentials(); + Properties overrides = setupProperties(); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); + + client = context.getApi(); + driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, + 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, + TimeUnit.SECONDS); + } + + @Test + public void testListServers() throws Exception { + Set servers = client.listServers(); + assertNotNull(servers); + } + + @Test + public void testListServerInfo() throws Exception { + Set servers = client.listServerInfo(); + assertNotNull(servers); + } + + @Test + public void testGetServer() throws Exception { + for (String serverUUID : client.listServers()) { + assert !"".equals(serverUUID); + assertNotNull(client.getServerInfo(serverUUID)); + } + } + + @Test + public void testListDrives() throws Exception { + Set drives = client.listDrives(); + assertNotNull(drives); + } + + @Test + public void testListDriveInfo() throws Exception { + Set drives = client.listDriveInfo(); + assertNotNull(drives); + } + + @Test + public void testGetDrive() throws Exception { + for (String driveUUID : client.listDrives()) { + assert !"".equals(driveUUID); + assertNotNull(client.getDriveInfo(driveUUID)); + } + } + + protected String prefix = System.getProperty("user.name") + ".test"; + protected DriveInfo drive; + + @Test + public void testCreateDrive() throws Exception { + drive = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(driveSize).build()); + checkCreatedDrive(); + + DriveInfo newInfo = client.getDriveInfo(drive.getUuid()); + checkDriveMatchesGet(newInfo); + + } + + protected void checkDriveMatchesGet(DriveInfo newInfo) { + assertEquals(newInfo.getUuid(), drive.getUuid()); + } + + protected void checkCreatedDrive() { + assertNotNull(drive.getUuid()); + assertNotNull(drive.getUser()); + assertEquals(drive.getName(), prefix); + assertEquals(drive.getSize(), driveSize); + assertEquals(drive.getStatus(), DriveStatus.ACTIVE); + // for some reason, these occasionally return as 4096,1 + // assertEquals(info.getReadBytes(), 0l); + // assertEquals(info.getWriteBytes(), 0l); + // assertEquals(info.getReadRequests(), 0l); + // assertEquals(info.getWriteRequests(), 0l); + assertEquals(drive.getEncryptionCipher(), "aes-xts-plain"); + } + + @Test(dependsOnMethods = "testCreateDrive") + public void testSetDriveData() throws Exception { + + DriveInfo drive2 = client.setDriveData( + drive.getUuid(), + new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous") + .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")) + .tags(ImmutableSet.of("networking", "security", "gateway")) + .userMetadata(ImmutableMap.of("foo", "bar")).build()); + + assertNotNull(drive2.getUuid(), drive.getUuid()); + assertEquals(drive2.getName(), "rediculous"); + assertEquals(drive2.getClaimType(), ClaimType.SHARED); + assertEquals(drive2.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")); + assertEquals(drive2.getTags(), ImmutableSet.of("networking", "security", "gateway")); + assertEquals(drive2.getUserMetadata(), ImmutableMap.of("foo", "bar")); + drive = drive2; + } + + protected ServerInfo server; + + @Test(dependsOnMethods = "testSetDriveData") + public void testCreateAndStartServer() throws Exception { + Logger.getAnonymousLogger().info("preparing drive"); + prepareDrive(); + + Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build(); + + Logger.getAnonymousLogger().info("starting server"); + server = client.createServer(serverRequest); + client.startServer(server.getUuid()); + server = client.getServerInfo(server.getUuid()); + checkStartedServer(); + + Server newInfo = client.getServerInfo(server.getUuid()); + checkServerMatchesGet(newInfo); + + } + + protected void checkServerMatchesGet(Server newInfo) { + assertEquals(newInfo.getUuid(), server.getUuid()); + } + + protected void checkStartedServer() { + System.out.println(new Gson().toJson(server)); + assertNotNull(server.getUuid()); + assertNotNull(server.getUser()); + assertEquals(server.getName(), prefix); + assertEquals(server.isPersistent(), true); + assertEquals(server.getDevices(), + ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build())); + assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0")); + assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp()); + assertEquals(server.getNics().get(0).getModel(), Model.E1000); + assertEquals(server.getStatus(), ServerStatus.ACTIVE); + } + + @Test(dependsOnMethods = "testCreateAndStartServer") + public void testConnectivity() throws Exception { + Logger.getAnonymousLogger().info("awaiting vnc"); + assert socketTester.apply(new IPSocket(server.getVnc().getIp(), 5900)) : server; + Logger.getAnonymousLogger().info("awaiting ssh"); + assert socketTester.apply(new IPSocket(server.getNics().get(0).getDhcp(), 22)) : server; + doConnectViaSsh(server, getSshCredentials(server)); + } + + @Test(dependsOnMethods = "testConnectivity") + public void testLifeCycle() throws Exception { + client.stopServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED); + + client.startServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); + + client.resetServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); + + client.shutdownServer(server.getUuid()); + // behavior on shutdown depends on how your server OS is set up to respond to an ACPI power + // button signal + assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo( + server.getUuid()).getStatus() == ServerStatus.STOPPED); + } + + @Test(dependsOnMethods = "testLifeCycle") + public void testSetServerConfiguration() throws Exception { + client.stopServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED); + + ServerInfo server2 = client.setServerConfiguration( + server.getUuid(), + Server.Builder.fromServer(server).name("rediculous") + .tags(ImmutableSet.of("networking", "security", "gateway")) + .userMetadata(ImmutableMap.of("foo", "bar")).build()); + + assertNotNull(server2.getUuid(), server.getUuid()); + assertEquals(server2.getName(), "rediculous"); + checkTagsAndMetadata(server2); + server = server2; + } + + protected void checkTagsAndMetadata(ServerInfo server2) { + assertEquals(server2.getTags(), ImmutableSet.of("networking", "security", "gateway")); + assertEquals(server2.getUserMetadata(), ImmutableMap.of("foo", "bar")); + } + + @Test(dependsOnMethods = "testSetServerConfiguration") + public void testDestroyServer() throws Exception { + client.destroyServer(server.getUuid()); + assertEquals(client.getServerInfo(server.getUuid()), null); + } + + @Test(dependsOnMethods = "testDestroyServer") + public void testDestroyDrive() throws Exception { + client.destroyDrive(drive.getUuid()); + assertEquals(client.getDriveInfo(drive.getUuid()), null); + } + + protected void doConnectViaSsh(Server server, Credentials creds) throws IOException { + SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class) + .create(new IPSocket(server.getVnc().getIp(), 22), creds); + try { + ssh.connect(); + ExecResponse hello = ssh.exec("echo hello"); + assertEquals(hello.getOutput().trim(), "hello"); + System.err.println(ssh.exec("df -k").getOutput()); + System.err.println(ssh.exec("mount").getOutput()); + System.err.println(ssh.exec("uname -a").getOutput()); + } finally { + if (ssh != null) + ssh.disconnect(); + } + } + + @AfterGroups(groups = "live") + protected void tearDown() { + try { + client.destroyServer(server.getUuid()); + } catch (Exception e) { + // no need to check null or anything as we swallow all + } + try { + client.destroyDrive(drive.getUuid()); + } catch (Exception e) { + + } + if (context != null) + context.close(); + } + private DriveInfo drive2; private DriveInfo drive3; @@ -68,12 +373,10 @@ public class ElasticStackClientLiveTest extends } } - @Override protected Credentials getSshCredentials(Server server) { return new Credentials("toor", server.getVnc().getPassword()); } - @Override protected void prepareDrive() { System.err.println("before prepare" + client.getDriveInfo(drive.getUuid())); client.imageDrive("38df0986-4d85-4b76-b502-3878ffc80161", drive.getUuid(), ImageConversionType.GUNZIP); From de04e9ec9dbda62c6cea3a71d3571c153a3904a6 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 01:35:18 +0100 Subject: [PATCH 21/33] Issue 412: elasticstack/hosts is now a top-level provider --- README.txt | 4 +++- allcompute/pom.xml | 5 +++++ compute/src/main/clojure/org/jclouds/compute.clj | 3 ++- {sandbox/elasticstack => elasticstack}/pom.xml | 2 +- .../org/jclouds/elasticstack/ElasticStackAsyncClient.java | 0 .../java/org/jclouds/elasticstack/ElasticStackClient.java | 0 .../org/jclouds/elasticstack/ElasticStackContextBuilder.java | 0 .../jclouds/elasticstack/ElasticStackPropertiesBuilder.java | 0 .../elasticstack/binders/BindDriveDataToPlainTextString.java | 0 .../elasticstack/binders/BindDriveToPlainTextString.java | 0 .../elasticstack/binders/BindServerToPlainTextString.java | 0 .../compute/ElasticStackComputeServiceAdapter.java | 0 .../config/ElasticStackComputeServiceContextModule.java | 0 .../compute/functions/ServerInfoToNodeMetadata.java | 0 .../elasticstack/config/ElasticStackRestClientModule.java | 0 .../java/org/jclouds/elasticstack/domain/BlockDevice.java | 0 .../main/java/org/jclouds/elasticstack/domain/ClaimType.java | 0 .../org/jclouds/elasticstack/domain/CreateDriveRequest.java | 0 .../main/java/org/jclouds/elasticstack/domain/Device.java | 0 .../src/main/java/org/jclouds/elasticstack/domain/Drive.java | 0 .../main/java/org/jclouds/elasticstack/domain/DriveData.java | 0 .../main/java/org/jclouds/elasticstack/domain/DriveInfo.java | 0 .../java/org/jclouds/elasticstack/domain/DriveMetrics.java | 0 .../java/org/jclouds/elasticstack/domain/DriveStatus.java | 0 .../main/java/org/jclouds/elasticstack/domain/IDEDevice.java | 0 .../org/jclouds/elasticstack/domain/ImageConversionType.java | 0 .../src/main/java/org/jclouds/elasticstack/domain/Item.java | 0 .../main/java/org/jclouds/elasticstack/domain/MediaType.java | 0 .../src/main/java/org/jclouds/elasticstack/domain/Model.java | 0 .../src/main/java/org/jclouds/elasticstack/domain/NIC.java | 0 .../java/org/jclouds/elasticstack/domain/SCSIDevice.java | 0 .../main/java/org/jclouds/elasticstack/domain/Server.java | 0 .../java/org/jclouds/elasticstack/domain/ServerInfo.java | 0 .../java/org/jclouds/elasticstack/domain/ServerMetrics.java | 0 .../java/org/jclouds/elasticstack/domain/ServerStatus.java | 0 .../src/main/java/org/jclouds/elasticstack/domain/VNC.java | 0 .../java/org/jclouds/elasticstack/domain/WellKnownImage.java | 0 .../org/jclouds/elasticstack/functions/BaseDriveToMap.java | 0 .../elasticstack/functions/CreateDriveRequestToMap.java | 0 .../org/jclouds/elasticstack/functions/DriveDataToMap.java | 0 .../functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java | 0 .../KeyValuesDelimitedByBlankLinesToServerInfo.java | 0 .../ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java | 0 .../ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java | 0 .../ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java | 0 .../ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java | 0 .../org/jclouds/elasticstack/functions/MapToDevices.java | 0 .../org/jclouds/elasticstack/functions/MapToDriveInfo.java | 0 .../jclouds/elasticstack/functions/MapToDriveMetrics.java | 0 .../java/org/jclouds/elasticstack/functions/MapToNICs.java | 0 .../org/jclouds/elasticstack/functions/MapToServerInfo.java | 0 .../jclouds/elasticstack/functions/MapToServerMetrics.java | 0 .../org/jclouds/elasticstack/functions/ReturnPayload.java | 0 .../java/org/jclouds/elasticstack/functions/ServerToMap.java | 0 .../org/jclouds/elasticstack/functions/SplitNewlines.java | 0 .../elasticstack/handlers/ElasticStackErrorHandler.java | 0 .../org/jclouds/elasticstack/predicates/DriveClaimed.java | 0 .../elasticstack/reference/ElasticStackConstants.java | 0 .../src/main/java/org/jclouds/elasticstack/util/Servers.java | 0 .../src/main/resources/preinstalled_images.json | 0 .../jclouds/elasticstack/ElasticStackAsyncClientTest.java | 0 .../org/jclouds/elasticstack/ElasticStackClientLiveTest.java | 0 .../org/jclouds/elasticstack/ProvidersInPropertiesTest.java | 0 .../binders/BindDriveDataToPlainTextStringTest.java | 0 .../elasticstack/binders/BindDriveToPlainTextStringTest.java | 0 .../binders/BindServerToPlainTextStringTest.java | 0 .../compute/ElasticStackComputeServiceLiveTest.java | 0 .../compute/ElasticStackTemplateBuilderLiveTest.java | 0 .../jclouds/elasticstack/functions/BaseDriveToMapTest.java | 0 .../elasticstack/functions/CreateDriveRequestToMapTest.java | 0 .../jclouds/elasticstack/functions/DriveDataToMapTest.java | 0 .../KeyValuesDelimitedByBlankLinesToDriveInfoTest.java | 0 .../KeyValuesDelimitedByBlankLinesToServerInfoTest.java | 0 ...stOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java | 0 ...ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java | 0 ...tOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java | 0 ...ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java | 0 .../jclouds/elasticstack/functions/MapToDriveInfoTest.java | 0 .../jclouds/elasticstack/functions/MapToServerInfoTest.java | 0 .../org/jclouds/elasticstack/functions/ServerToMapTest.java | 0 .../jclouds/elasticstack/functions/SplitNewlinesTest.java | 0 .../elasticstack/handlers/ElasticStackErrorHandlerTest.java | 0 .../src/test/resources/create_drive.txt | 0 .../src/test/resources/create_server.txt | 0 .../src/test/resources/drive.txt | 0 .../src/test/resources/drive_data.txt | 0 .../src/test/resources/log4j.xml | 0 .../src/test/resources/new_server.txt | 0 .../src/test/resources/servers.txt | 0 .../src/test/resources/uuids.txt | 0 90 files changed, 11 insertions(+), 3 deletions(-) rename {sandbox/elasticstack => elasticstack}/pom.xml (99%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextString.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextString.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/BlockDevice.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/ClaimType.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/CreateDriveRequest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/Device.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/Drive.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/DriveData.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/DriveInfo.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/DriveMetrics.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/DriveStatus.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/IDEDevice.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/ImageConversionType.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/Item.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/MediaType.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/Model.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/NIC.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/SCSIDevice.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/Server.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/ServerMetrics.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/ServerStatus.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/VNC.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/BaseDriveToMap.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMap.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/DriveDataToMap.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/MapToDevices.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/MapToDriveInfo.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/MapToDriveMetrics.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/MapToServerMetrics.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/ReturnPayload.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/functions/SplitNewlines.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/java/org/jclouds/elasticstack/util/Servers.java (100%) rename {sandbox/elasticstack => elasticstack}/src/main/resources/preinstalled_images.json (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/ProvidersInPropertiesTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextStringTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextStringTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/BaseDriveToMapTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMapTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/DriveDataToMapTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/MapToDriveInfoTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/functions/SplitNewlinesTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java (100%) rename {sandbox/elasticstack => elasticstack}/src/test/resources/create_drive.txt (100%) rename {sandbox/elasticstack => elasticstack}/src/test/resources/create_server.txt (100%) rename {sandbox/elasticstack => elasticstack}/src/test/resources/drive.txt (100%) rename {sandbox/elasticstack => elasticstack}/src/test/resources/drive_data.txt (100%) rename {sandbox/elasticstack => elasticstack}/src/test/resources/log4j.xml (100%) rename {sandbox/elasticstack => elasticstack}/src/test/resources/new_server.txt (100%) rename {sandbox/elasticstack => elasticstack}/src/test/resources/servers.txt (100%) rename {sandbox/elasticstack => elasticstack}/src/test/resources/uuids.txt (100%) diff --git a/README.txt b/README.txt index 6fbeb8f7de..efc7e7bf3e 100644 --- a/README.txt +++ b/README.txt @@ -31,7 +31,9 @@ our dev version is 1.0-SNAPSHOT our compute api supports: ec2, gogrid, cloudservers (rackspace), rimuhosting, vcloud, trmk-ecloud, trmk-vcloudexpress, eucalyptus, - bluelock-vclouddirector, slicehost, stub (in-memory) + elasticstack, bluelock-vclouddirector, slicehost, + elastichosts-lon-p (Peer 1), elastichosts-sat-p (Peer 1), + elastichosts-lon-b (BlueSquare), stub (in-memory) * note * the pom dependency org.jclouds/jclouds-allcompute gives you access to to all of these providers diff --git a/allcompute/pom.xml b/allcompute/pom.xml index 000e927a1f..8e00363dd1 100644 --- a/allcompute/pom.xml +++ b/allcompute/pom.xml @@ -69,5 +69,10 @@ jclouds-slicehost ${project.version} + + ${project.groupId} + jclouds-elasticstack + ${project.version} + diff --git a/compute/src/main/clojure/org/jclouds/compute.clj b/compute/src/main/clojure/org/jclouds/compute.clj index 0ee451a81a..dd140be944 100644 --- a/compute/src/main/clojure/org/jclouds/compute.clj +++ b/compute/src/main/clojure/org/jclouds/compute.clj @@ -22,7 +22,8 @@ Current supported services are: [ec2, rimuhosting, cloudservers, trmk-ecloud, trmk-vcloudexpress, vcloud, - bluelock, eucalyptus, slicehost] + bluelock, eucalyptus, slicehost, elastichosts-lon-p, elastichosts-sat-p, + elastichosts, elastichosts-lon-b, stub] Here's an example of getting some compute configuration from rackspace: diff --git a/sandbox/elasticstack/pom.xml b/elasticstack/pom.xml similarity index 99% rename from sandbox/elasticstack/pom.xml rename to elasticstack/pom.xml index 73a9c7f299..9afc7f0880 100644 --- a/sandbox/elasticstack/pom.xml +++ b/elasticstack/pom.xml @@ -28,7 +28,7 @@ org.jclouds jclouds-project 1.0-SNAPSHOT - ../../project/pom.xml + ../project/pom.xml org.jclouds jclouds-elasticstack diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java b/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java b/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java b/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java b/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextString.java b/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextString.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextString.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextString.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextString.java b/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextString.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextString.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextString.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java b/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/binders/BindServerToPlainTextString.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java b/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/BlockDevice.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/BlockDevice.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/BlockDevice.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/BlockDevice.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ClaimType.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ClaimType.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ClaimType.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/ClaimType.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/CreateDriveRequest.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/CreateDriveRequest.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/CreateDriveRequest.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/CreateDriveRequest.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Device.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Device.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Device.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/Device.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Drive.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Drive.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Drive.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/Drive.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveData.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveData.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveData.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveData.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveInfo.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveInfo.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveInfo.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveInfo.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveMetrics.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveMetrics.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveMetrics.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveMetrics.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveStatus.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveStatus.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveStatus.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/DriveStatus.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/IDEDevice.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/IDEDevice.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/IDEDevice.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/IDEDevice.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ImageConversionType.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ImageConversionType.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ImageConversionType.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/ImageConversionType.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Item.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Item.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Item.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/Item.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/MediaType.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/MediaType.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/MediaType.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/MediaType.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Model.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Model.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Model.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/Model.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/NIC.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/NIC.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/NIC.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/NIC.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/SCSIDevice.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/SCSIDevice.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/SCSIDevice.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/SCSIDevice.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerInfo.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerMetrics.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerMetrics.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerMetrics.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerMetrics.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerStatus.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerStatus.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerStatus.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/ServerStatus.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/VNC.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/VNC.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/VNC.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/VNC.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java b/elasticstack/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/BaseDriveToMap.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/BaseDriveToMap.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/BaseDriveToMap.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/BaseDriveToMap.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMap.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMap.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMap.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMap.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/DriveDataToMap.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/DriveDataToMap.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/DriveDataToMap.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/DriveDataToMap.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDevices.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDevices.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDevices.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDevices.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDriveInfo.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDriveInfo.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDriveInfo.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDriveInfo.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDriveMetrics.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDriveMetrics.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDriveMetrics.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToDriveMetrics.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerMetrics.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerMetrics.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerMetrics.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerMetrics.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ReturnPayload.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ReturnPayload.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ReturnPayload.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/ReturnPayload.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/SplitNewlines.java b/elasticstack/src/main/java/org/jclouds/elasticstack/functions/SplitNewlines.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/functions/SplitNewlines.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/functions/SplitNewlines.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java b/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java b/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java b/elasticstack/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/util/Servers.java b/elasticstack/src/main/java/org/jclouds/elasticstack/util/Servers.java similarity index 100% rename from sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/util/Servers.java rename to elasticstack/src/main/java/org/jclouds/elasticstack/util/Servers.java diff --git a/sandbox/elasticstack/src/main/resources/preinstalled_images.json b/elasticstack/src/main/resources/preinstalled_images.json similarity index 100% rename from sandbox/elasticstack/src/main/resources/preinstalled_images.json rename to elasticstack/src/main/resources/preinstalled_images.json diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ProvidersInPropertiesTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/ProvidersInPropertiesTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ProvidersInPropertiesTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/ProvidersInPropertiesTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextStringTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextStringTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextStringTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveDataToPlainTextStringTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextStringTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextStringTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextStringTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextStringTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/BaseDriveToMapTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/BaseDriveToMapTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/BaseDriveToMapTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/BaseDriveToMapTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMapTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMapTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMapTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/CreateDriveRequestToMapTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/DriveDataToMapTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/DriveDataToMapTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/DriveDataToMapTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/DriveDataToMapTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToDriveInfoTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToDriveInfoTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToDriveInfoTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToDriveInfoTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/SplitNewlinesTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/functions/SplitNewlinesTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/functions/SplitNewlinesTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/functions/SplitNewlinesTest.java diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java rename to elasticstack/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java diff --git a/sandbox/elasticstack/src/test/resources/create_drive.txt b/elasticstack/src/test/resources/create_drive.txt similarity index 100% rename from sandbox/elasticstack/src/test/resources/create_drive.txt rename to elasticstack/src/test/resources/create_drive.txt diff --git a/sandbox/elasticstack/src/test/resources/create_server.txt b/elasticstack/src/test/resources/create_server.txt similarity index 100% rename from sandbox/elasticstack/src/test/resources/create_server.txt rename to elasticstack/src/test/resources/create_server.txt diff --git a/sandbox/elasticstack/src/test/resources/drive.txt b/elasticstack/src/test/resources/drive.txt similarity index 100% rename from sandbox/elasticstack/src/test/resources/drive.txt rename to elasticstack/src/test/resources/drive.txt diff --git a/sandbox/elasticstack/src/test/resources/drive_data.txt b/elasticstack/src/test/resources/drive_data.txt similarity index 100% rename from sandbox/elasticstack/src/test/resources/drive_data.txt rename to elasticstack/src/test/resources/drive_data.txt diff --git a/sandbox/elasticstack/src/test/resources/log4j.xml b/elasticstack/src/test/resources/log4j.xml similarity index 100% rename from sandbox/elasticstack/src/test/resources/log4j.xml rename to elasticstack/src/test/resources/log4j.xml diff --git a/sandbox/elasticstack/src/test/resources/new_server.txt b/elasticstack/src/test/resources/new_server.txt similarity index 100% rename from sandbox/elasticstack/src/test/resources/new_server.txt rename to elasticstack/src/test/resources/new_server.txt diff --git a/sandbox/elasticstack/src/test/resources/servers.txt b/elasticstack/src/test/resources/servers.txt similarity index 100% rename from sandbox/elasticstack/src/test/resources/servers.txt rename to elasticstack/src/test/resources/servers.txt diff --git a/sandbox/elasticstack/src/test/resources/uuids.txt b/elasticstack/src/test/resources/uuids.txt similarity index 100% rename from sandbox/elasticstack/src/test/resources/uuids.txt rename to elasticstack/src/test/resources/uuids.txt From 8a51b65cd69bbed4f53a0bd7a263149db2c8fb5b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 10:42:31 +0100 Subject: [PATCH 22/33] fixed syntax in box.net --- .../java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sandbox/boxdotnet/src/test/java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java b/sandbox/boxdotnet/src/test/java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java index 9845e8409d..8703f49368 100644 --- a/sandbox/boxdotnet/src/test/java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java +++ b/sandbox/boxdotnet/src/test/java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java @@ -30,7 +30,7 @@ import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory.ContextSpec; +import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.GeneratedHttpRequest; @@ -123,7 +123,7 @@ public class BoxDotNetAsyncClientTest extends RestClientTest createContextSpec() { + public RestContextSpec createContextSpec() { return contextSpec("boxdotnet", "https://www.box.net/api/1.0/rest", "1.0", "identity", "credential", BoxDotNetClient.class, BoxDotNetAsyncClient.class); } From 29f3e65d87e3f4a9c61d71253b35c58fdc88bdea Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 10:46:46 +0100 Subject: [PATCH 23/33] fixed pom --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 6ff8b53bc2..48c19ae35e 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,7 @@ rimuhosting vcloud gogrid + elasticstack allcompute allblobstore all From 2760345bd3af7d7aefe89f94a8642961c28c5588 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 14:36:04 +0100 Subject: [PATCH 24/33] promoted os version bundle object to be accessible outside tests --- .../compute/EC2TemplateBuilderLiveTest.java | 2 +- .../domain/os}/OsFamilyVersion64Bit.java | 18 +++-- .../compute/BaseTemplateBuilderLiveTest.java | 1 + .../functions/WellKnownImageToImage.java | 70 +++++++++++++++++++ .../ElasticStackTemplateBuilderLiveTest.java | 2 +- .../GoGridTemplateBuilderLiveTest.java | 2 +- .../CloudServersTemplateBuilderLiveTest.java | 2 +- .../RimuHostingTemplateBuilderLiveTest.java | 2 +- .../SlicehostTemplateBuilderLiveTest.java | 2 +- ...erremarkECloudTemplateBuilderLiveTest.java | 2 +- ...kVCloudExpressTemplateBuilderLiveTest.java | 2 +- 11 files changed, 93 insertions(+), 12 deletions(-) rename compute/src/{test/java/org/jclouds/compute => main/java/org/jclouds/compute/domain/os}/OsFamilyVersion64Bit.java (90%) create mode 100644 elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/WellKnownImageToImage.java diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java index 3c592eed75..0bae72c07d 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java @@ -30,9 +30,9 @@ import org.jclouds.aws.ec2.reference.EC2Constants; import org.jclouds.compute.BaseTemplateBuilderLiveTest; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.testng.annotations.Test; diff --git a/compute/src/test/java/org/jclouds/compute/OsFamilyVersion64Bit.java b/compute/src/main/java/org/jclouds/compute/domain/os/OsFamilyVersion64Bit.java similarity index 90% rename from compute/src/test/java/org/jclouds/compute/OsFamilyVersion64Bit.java rename to compute/src/main/java/org/jclouds/compute/domain/os/OsFamilyVersion64Bit.java index a2f13d634c..e015b580e6 100644 --- a/compute/src/test/java/org/jclouds/compute/OsFamilyVersion64Bit.java +++ b/compute/src/main/java/org/jclouds/compute/domain/os/OsFamilyVersion64Bit.java @@ -17,14 +17,24 @@ * ==================================================================== */ -package org.jclouds.compute; +package org.jclouds.compute.domain.os; import org.jclouds.compute.domain.OsFamily; +/** + * + * @author Adrian Cole + * + */ public class OsFamilyVersion64Bit { - public final OsFamily family; - public final String version; - public final boolean is64Bit; + public OsFamily family; + public String version; + public boolean is64Bit; + + // for serialization + OsFamilyVersion64Bit() { + + } public OsFamilyVersion64Bit(OsFamily family, String version, boolean is64Bit) { this.family = family; diff --git a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java index ddf8fcc2e6..a40c075c42 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java @@ -36,6 +36,7 @@ import org.jclouds.Constants; import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.json.Json; import org.jclouds.json.config.GsonModule; diff --git a/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/WellKnownImageToImage.java b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/WellKnownImageToImage.java new file mode 100644 index 0000000000..ea12b435d2 --- /dev/null +++ b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/WellKnownImageToImage.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.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.OperatingSystemBuilder; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.elasticstack.domain.DriveInfo; +import org.jclouds.elasticstack.domain.WellKnownImage; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +@Singleton +public class WellKnownImageToImage implements Function { + private final Supplier locationSupplier; + private final Map preinstalledImages; + + @Inject + public WellKnownImageToImage(Supplier locationSupplier, Map preinstalledImages) { + this.locationSupplier = locationSupplier; + this.preinstalledImages = preinstalledImages; + } + + @Override + public Image apply(DriveInfo drive) { + WellKnownImage input = preinstalledImages.get(drive.getUuid()); + return new ImageBuilder() + .ids(drive.getUuid()) + .userMetadata( + ImmutableMap. builder().putAll(drive.getUserMetadata()) + .put("size", input.getSize() + "").build()) + .defaultCredentials(new Credentials("toor", null)) + .location(locationSupplier.get()) + .name(input.getDescription()) + .description(drive.getName()) + .operatingSystem( + new OperatingSystemBuilder().family(input.getOsFamily()).version(input.getOsVersion()) + .name(input.getDescription()).description(drive.getName()).is64Bit(true).build()).version("") + .build(); + } +} \ No newline at end of file diff --git a/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java b/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java index d1d09b1e8d..1808c71a83 100644 --- a/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java +++ b/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java @@ -20,8 +20,8 @@ package org.jclouds.elasticstack.compute; import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.testng.annotations.Test; import com.google.common.base.Predicate; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java index ab09cf3337..57f881899b 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java @@ -25,9 +25,9 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.testng.annotations.Test; import com.google.common.base.Predicate; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersTemplateBuilderLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersTemplateBuilderLiveTest.java index 0eb104d29a..8152a48dc7 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersTemplateBuilderLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersTemplateBuilderLiveTest.java @@ -20,8 +20,8 @@ package org.jclouds.rackspace.cloudservers.compute; import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.testng.annotations.Test; import com.google.common.base.Predicate; diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java index 4206b962db..72256eea09 100644 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java @@ -20,8 +20,8 @@ package org.jclouds.rimuhosting.miro.compute; import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.testng.annotations.Test; import com.google.common.base.Predicate; diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java index cf88d5ac72..c001b33f05 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java @@ -25,9 +25,9 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.testng.annotations.Test; import com.google.common.base.Predicate; diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudTemplateBuilderLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudTemplateBuilderLiveTest.java index 95845f31a0..3770e566b8 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudTemplateBuilderLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudTemplateBuilderLiveTest.java @@ -25,9 +25,9 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.testng.annotations.Test; import com.google.common.base.Predicate; diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java index 514b15fac3..c30a81d0c4 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java @@ -25,9 +25,9 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; import org.testng.annotations.Test; import com.google.common.base.Predicate; From 5587fc663540829793bc2913a4ad5b2279e51dab Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 14:37:24 +0100 Subject: [PATCH 25/33] Issue 412: parallel image fetches --- .../elasticstack/ElasticStackAsyncClient.java | 18 ++--- .../ElasticStackComputeServiceAdapter.java | 79 +++++++++---------- ...asticStackComputeServiceContextModule.java | 23 ++++-- .../functions/ServerInfoToNodeMetadata.java | 9 ++- 4 files changed, 71 insertions(+), 58 deletions(-) diff --git a/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java b/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java index 7dd0959117..a27bf24c37 100644 --- a/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java +++ b/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java @@ -81,7 +81,7 @@ public interface ElasticStackAsyncClient { @GET @Path("/servers/info") @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class) - ListenableFuture> listServerInfo(); + ListenableFuture> listServerInfo(); /** * @see ElasticStackClient#getServerInfo @@ -90,7 +90,7 @@ public interface ElasticStackAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @Path("/servers/{uuid}/info") - ListenableFuture getServerInfo(@PathParam("uuid") String uuid); + ListenableFuture getServerInfo(@PathParam("uuid") String uuid); /** * @see ElasticStackClient#createServer @@ -99,7 +99,7 @@ public interface ElasticStackAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @Path("/servers/create/stopped") - ListenableFuture createServer( + ListenableFuture createServer( @BinderParam(BindServerToPlainTextString.class) Server createServer); /** @@ -109,7 +109,7 @@ public interface ElasticStackAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @Path("/servers/{uuid}/set") - ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, + ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, @BinderParam(BindServerToPlainTextString.class) Server setServer); /** @@ -162,7 +162,7 @@ public interface ElasticStackAsyncClient { @GET @Path("/drives/info") @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class) - ListenableFuture> listDriveInfo(); + ListenableFuture> listDriveInfo(); /** * @see ElasticStackClient#getDriveInfo @@ -171,7 +171,7 @@ public interface ElasticStackAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/{uuid}/info") - ListenableFuture getDriveInfo(@PathParam("uuid") String uuid); + ListenableFuture getDriveInfo(@PathParam("uuid") String uuid); /** * @see ElasticStackClient#createDrive @@ -180,7 +180,7 @@ public interface ElasticStackAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/create") - ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); + ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); /** * @see ElasticStackClient#setDriveData @@ -189,7 +189,7 @@ public interface ElasticStackAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/{uuid}/set") - ListenableFuture setDriveData(@PathParam("uuid") String uuid, + ListenableFuture setDriveData(@PathParam("uuid") String uuid, @BinderParam(BindDriveDataToPlainTextString.class) DriveData setDrive); /** @@ -207,7 +207,7 @@ public interface ElasticStackAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @Path("/servers/create") - ListenableFuture createAndStartServer( + ListenableFuture createAndStartServer( @BinderParam(BindServerToPlainTextString.class) Server createServer); /** diff --git a/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java index 015e1cf6a9..0439ef8d14 100644 --- a/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java +++ b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java @@ -3,25 +3,25 @@ package org.jclouds.elasticstack.compute; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.notNull; import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; +import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.elasticstack.util.Servers.small; import java.net.URI; -import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.Constants; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Volume; @@ -31,6 +31,7 @@ import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.elasticstack.ElasticStackAsyncClient; import org.jclouds.elasticstack.ElasticStackClient; import org.jclouds.elasticstack.domain.Device; import org.jclouds.elasticstack.domain.Drive; @@ -45,9 +46,7 @@ import org.jclouds.rest.annotations.Provider; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -57,31 +56,37 @@ import com.google.common.collect.ImmutableSet.Builder; * */ @Singleton -public class ElasticStackComputeServiceAdapter implements ComputeServiceAdapter { +public class ElasticStackComputeServiceAdapter implements + ComputeServiceAdapter { private final ElasticStackClient client; + private final ElasticStackAsyncClient aclient; private final Predicate driveNotClaimed; - private final Supplier locationSupplier; - private final List preinstalledImages; + private final Map preinstalledImages; + private final Map cache; private final String providerName; private final URI providerURI; private final String defaultVncPassword; + private final ExecutorService executor; @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @Inject - public ElasticStackComputeServiceAdapter(ElasticStackClient client, Predicate driveNotClaimed, - Supplier locationSupplier, @Provider String providerName, @Provider URI providerURI, - List preinstalledImages, - @Named(ElasticStackConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword) { + public ElasticStackComputeServiceAdapter(ElasticStackClient client, ElasticStackAsyncClient aclient, + Predicate driveNotClaimed, @Provider String providerName, @Provider URI providerURI, + Map preinstalledImages, Map cache, + @Named(ElasticStackConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.client = checkNotNull(client, "client"); + this.aclient = checkNotNull(aclient, "aclient"); this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed"); - this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier"); this.providerName = checkNotNull(providerName, "providerName"); this.providerURI = checkNotNull(providerURI, "providerURI"); this.preinstalledImages = checkNotNull(preinstalledImages, "preinstalledImages"); + this.cache = checkNotNull(cache, "cache"); this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword"); + this.executor = checkNotNull(executor, "executor"); } @Override @@ -125,6 +130,11 @@ public class ElasticStackComputeServiceAdapter implements ComputeServiceAdapter< return (toParse != null && new Float(toParse) <= size); } + @Override + public String toString() { + return "sizeLessThanOrEqual(" + size + ")"; + } + }).ids(id).ram(ram).processors(ImmutableList.of(new Processor(1, cpu))) .volumes(ImmutableList. of(new VolumeImpl(size, true, true))).build()); } @@ -135,37 +145,20 @@ public class ElasticStackComputeServiceAdapter implements ComputeServiceAdapter< * look up the current standard images and do not error out, if they are not found. */ @Override - public Iterable listImages() { - return filter(transform(preinstalledImages, new Function() { + public Iterable listImages() { + Iterable drives = transformParallel(preinstalledImages.keySet(), + new Function>() { - @Override - public Image apply(WellKnownImage input) { - DriveInfo drive = null; - try { - drive = client.getDriveInfo(input.getUuid()); - } catch (Exception e) { - logger.warn(e, "could not find image: %s", input); - } - if (drive == null) { - logger.warn("could not find image: %s", input); - return null; - } - return new ImageBuilder() - .ids(drive.getUuid()) - .userMetadata( - ImmutableMap. builder().putAll(drive.getUserMetadata()) - .put("size", input.getSize() + "").build()) - .defaultCredentials(new Credentials("toor", null)) - .location(locationSupplier.get()) - .name(input.getDescription()) - .description(drive.getName()) - .operatingSystem( - new OperatingSystemBuilder().family(input.getOsFamily()).version(input.getOsVersion()) - .name(input.getDescription()).description(drive.getName()).is64Bit(true).build()) - .version("").build(); - } + @Override + public Future apply(String input) { + return aclient.getDriveInfo(input); + } - }), notNull()); + }, executor, null, logger, "drives"); + Iterable returnVal = filter(drives, notNull()); + for (DriveInfo drive : returnVal) + cache.put(drive.getUuid(), drive); + return returnVal; } @SuppressWarnings("unchecked") diff --git a/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java index 6e27de97a8..604b8ac3fa 100644 --- a/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java +++ b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java @@ -44,6 +44,7 @@ import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata; import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.DeviceToVolume; import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.FindImageForId; import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.GetImageIdFromServer; +import org.jclouds.elasticstack.compute.functions.WellKnownImageToImage; import org.jclouds.elasticstack.domain.Device; import org.jclouds.elasticstack.domain.DriveInfo; import org.jclouds.elasticstack.domain.Server; @@ -59,6 +60,7 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Supplier; import com.google.common.collect.MapMaker; +import com.google.common.collect.Maps; import com.google.inject.Provides; import com.google.inject.TypeLiteral; @@ -68,7 +70,7 @@ import com.google.inject.TypeLiteral; */ public class ElasticStackComputeServiceContextModule extends - ComputeServiceAdapterContextModule { + ComputeServiceAdapterContextModule { public ElasticStackComputeServiceContextModule() { super(ElasticStackClient.class, ElasticStackAsyncClient.class); @@ -78,7 +80,7 @@ public class ElasticStackComputeServiceContextModule @Override protected void configure() { super.configure(); - bind(new TypeLiteral>() { + bind(new TypeLiteral>() { }).to(ElasticStackComputeServiceAdapter.class); bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE); bind(new TypeLiteral>() { @@ -97,12 +99,14 @@ public class ElasticStackComputeServiceContextModule }).to(GetImageIdFromServer.class); bind(new TypeLiteral>() { }).to(FindImageForId.class); + bind(new TypeLiteral>() { + }).to(WellKnownImageToImage.class); } @Provides @Singleton protected Map cache(GetDrive getDrive) { - return new MapMaker().expiration(30, TimeUnit.SECONDS).makeComputingMap(getDrive); + return new MapMaker().makeComputingMap(getDrive); } @Singleton @@ -122,10 +126,19 @@ public class ElasticStackComputeServiceContextModule @Singleton @Provides - protected List provideImages(Json json) throws IOException { - return json.fromJson(Utils.toStringAndClose(getClass().getResourceAsStream("/preinstalled_images.json")), + protected Map provideImages(Json json) throws IOException { + List wellKnowns = json.fromJson( + Utils.toStringAndClose(getClass().getResourceAsStream("/preinstalled_images.json")), new TypeLiteral>() { }.getType()); + return Maps.uniqueIndex(wellKnowns, new Function() { + + @Override + public String apply(WellKnownImage input) { + return input.getUuid(); + } + + }); } @Provides diff --git a/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java index cdd22788ec..eed46bb5f6 100644 --- a/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java +++ b/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java @@ -132,6 +132,13 @@ public class ServerInfoToNodeMetadata implements Function { private final Map cache; @@ -148,7 +155,7 @@ public class ServerInfoToNodeMetadata implements Function Date: Mon, 20 Dec 2010 14:39:25 +0100 Subject: [PATCH 26/33] Issue 419: computeservice support for cloudsigma --- .../cloudsigma/CloudSigmaAsyncClient.java | 30 +-- .../jclouds/cloudsigma/CloudSigmaClient.java | 6 +- .../cloudsigma/CloudSigmaContextBuilder.java | 11 +- ...indCloneDriveOptionsToPlainTextString.java | 2 +- .../CloudSigmaComputeServiceAdapter.java | 231 ++++++++++++++++++ ...CloudSigmaComputeServiceContextModule.java | 140 +++++++++++ ...arseOsFamilyVersion64BitFromImageName.java | 81 ++++++ .../functions/PreinstalledDiskToImage.java | 66 +++++ .../functions/ServerInfoToNodeMetadata.java | 183 ++++++++++++++ ...esDelimitedByBlankLinesToDriveInfoSet.java | 1 - ...sDelimitedByBlankLinesToServerInfoSet.java | 1 - .../cloudsigma/CloudSigmaAsyncClientTest.java | 10 +- .../cloudsigma/CloudSigmaClientLiveTest.java | 17 +- .../CloudSigmaComputeServiceLiveTest.java | 39 +++ .../CloudSigmaTemplateBuilderLiveTest.java | 56 +++++ ...DelimitedByBlankLinesToServerInfoTest.java | 4 - ...imitedByBlankLinesToServerInfoSetTest.java | 4 - .../functions/MapToServerInfoTest.java | 5 - ...OsFamilyVersion64BitFromImageNameTest.java | 75 ++++++ .../functions/SplitNewlinesTest.java | 1 - .../src/test/resources/osmatches.json | 140 +++++++++++ 21 files changed, 1052 insertions(+), 51 deletions(-) create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java create mode 100644 sandbox/cloudsigma/src/test/resources/osmatches.json diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java index 2a96dfd361..e199a1e378 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java @@ -29,20 +29,20 @@ import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; import org.jclouds.cloudsigma.binders.BindCloneDriveOptionsToPlainTextString; -import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; -import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.cloudsigma.binders.BindDriveDataToPlainTextString; import org.jclouds.cloudsigma.binders.BindDriveToPlainTextString; import org.jclouds.cloudsigma.binders.BindServerToPlainTextString; import org.jclouds.cloudsigma.domain.Drive; import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.domain.DriveInfo; import org.jclouds.cloudsigma.domain.Server; import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; +import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; import org.jclouds.cloudsigma.functions.SplitNewlines; +import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; @@ -98,7 +98,7 @@ public interface CloudSigmaAsyncClient { @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/{uuid}/clone") @MapBinder(BindCloneDriveOptionsToPlainTextString.class) - ListenableFuture cloneDrive(@PathParam("uuid") String sourceUuid, + ListenableFuture cloneDrive(@PathParam("uuid") String sourceUuid, @MapPayloadParam("name") String newName, CloneDriveOptions... options); /** @@ -107,7 +107,7 @@ public interface CloudSigmaAsyncClient { @GET @Path("/drives/info") @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class) - ListenableFuture> listDriveInfo(); + ListenableFuture> listDriveInfo(); /** * @see CloudSigmaClient#getDriveInfo @@ -116,7 +116,7 @@ public interface CloudSigmaAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/{uuid}/info") - ListenableFuture getDriveInfo(@PathParam("uuid") String uuid); + ListenableFuture getDriveInfo(@PathParam("uuid") String uuid); /** * @see CloudSigmaClient#createDrive @@ -125,7 +125,7 @@ public interface CloudSigmaAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/create") - ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); + ListenableFuture createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive); /** * @see CloudSigmaClient#setDriveData @@ -133,7 +133,7 @@ public interface CloudSigmaAsyncClient { @POST @ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class) @Path("/drives/{uuid}/set") - ListenableFuture setDriveData(@PathParam("uuid") String uuid, + ListenableFuture setDriveData(@PathParam("uuid") String uuid, @BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive); /** @@ -143,7 +143,7 @@ public interface CloudSigmaAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @Path("/servers/create") - ListenableFuture createServer( + ListenableFuture createServer( @BinderParam(BindServerToPlainTextString.class) Server createServer); /** @@ -152,7 +152,7 @@ public interface CloudSigmaAsyncClient { @GET @Path("/servers/info") @ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class) - ListenableFuture> listServerInfo(); + ListenableFuture> listServerInfo(); /** * @see CloudSigmaClient#getServerInfo @@ -161,7 +161,7 @@ public interface CloudSigmaAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @Path("/servers/{uuid}/info") - ListenableFuture getServerInfo(@PathParam("uuid") String uuid); + ListenableFuture getServerInfo(@PathParam("uuid") String uuid); /** * @see CloudSigmaClient#setServerConfiguration @@ -170,7 +170,7 @@ public interface CloudSigmaAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) @Path("/servers/{uuid}/set") - ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, + ListenableFuture setServerConfiguration(@PathParam("uuid") String uuid, @BinderParam(BindServerToPlainTextString.class) Server setServer); /** diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java index edd2a72197..84a8bb8db7 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java @@ -22,13 +22,13 @@ package org.jclouds.cloudsigma; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.concurrent.Timeout; import org.jclouds.cloudsigma.domain.Drive; import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.domain.DriveInfo; import org.jclouds.cloudsigma.domain.Server; import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.options.CloneDriveOptions; +import org.jclouds.concurrent.Timeout; /** * Provides synchronous access to CloudSigma. diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java index d69dfc3874..71f5fc550e 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java @@ -22,8 +22,9 @@ package org.jclouds.cloudsigma; import java.util.List; import java.util.Properties; +import org.jclouds.cloudsigma.compute.config.CloudSigmaComputeServiceContextModule; import org.jclouds.cloudsigma.config.CloudSigmaRestClientModule; -import org.jclouds.rest.RestContextBuilder; +import org.jclouds.compute.ComputeServiceContextBuilder; import com.google.inject.Module; @@ -31,13 +32,17 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class CloudSigmaContextBuilder extends - RestContextBuilder { +public class CloudSigmaContextBuilder extends ComputeServiceContextBuilder { public CloudSigmaContextBuilder(Properties props) { super(CloudSigmaClient.class, CloudSigmaAsyncClient.class, props); } + @Override + protected void addContextModule(List modules) { + modules.add(new CloudSigmaComputeServiceContextModule()); + } + protected void addClientModule(List modules) { modules.add(new CloudSigmaRestClientModule()); } diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java index 7614b0a7f8..c0e26d0a88 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java @@ -30,8 +30,8 @@ import javax.inject.Singleton; import javax.ws.rs.core.MediaType; import org.jclouds.cloudsigma.CloudSigmaAsyncClient; -import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines; +import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.http.HttpRequest; import org.jclouds.rest.MapBinder; import org.jclouds.rest.internal.GeneratedHttpRequest; diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java new file mode 100644 index 0000000000..a3c9dcfdc6 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java @@ -0,0 +1,231 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.net.URI; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.cloudsigma.CloudSigmaAsyncClient; +import org.jclouds.cloudsigma.CloudSigmaClient; +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.cloudsigma.domain.DriveType; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.options.CloneDriveOptions; +import org.jclouds.cloudsigma.reference.CloudSigmaConstants; +import org.jclouds.cloudsigma.util.Servers; +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.internal.VolumeImpl; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.logging.Logger; +import org.jclouds.rest.annotations.Provider; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * defines the connection between the {@link CloudSigmaClient} implementation and the jclouds + * {@link ComputeService} + * + */ +@Singleton +public class CloudSigmaComputeServiceAdapter implements + ComputeServiceAdapter { + private static final Predicate PREINSTALLED_DISK = Predicates.and(Predicates.notNull(), + new Predicate() { + + @Override + public boolean apply(DriveInfo drive) { + return drive.getType().equals(DriveType.DISK) && drive.getDriveType().contains("preinstalled"); + } + + }); + private final CloudSigmaClient client; + private final CloudSigmaAsyncClient aclient; + private final Predicate driveNotClaimed; + private final String providerName; + private final URI providerURI; + private final String defaultVncPassword; + private final Map cache; + private final ExecutorService executor; + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + @Inject + public CloudSigmaComputeServiceAdapter(CloudSigmaClient client, CloudSigmaAsyncClient aclient, + Predicate driveNotClaimed, @Provider String providerName, @Provider URI providerURI, + @Named(CloudSigmaConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword, Map cache, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.client = checkNotNull(client, "client"); + this.aclient = checkNotNull(aclient, "aclient"); + this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed"); + this.providerName = checkNotNull(providerName, "providerName"); + this.providerURI = checkNotNull(providerURI, "providerURI"); + this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword"); + this.cache = checkNotNull(cache, "cache"); + this.executor = checkNotNull(executor, "executor"); + } + + @Override + public ServerInfo runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, + Map credentialStore) { + long bootSize = (long) (template.getHardware().getVolumes().get(0).getSize() * 1024 * 1024 * 1024l); + logger.debug(">> imaging boot drive source(%s) bytes(%d)", template.getImage().getId(), bootSize); + DriveInfo drive = client.cloneDrive(template.getImage().getId(), template.getImage().getId(), + new CloneDriveOptions().size(bootSize)); + boolean success = driveNotClaimed.apply(drive); + logger.debug("<< image(%s) complete(%s)", drive.getUuid(), success); + if (!success) { + client.destroyDrive(drive.getUuid()); + throw new IllegalStateException("could not image drive in time!"); + } + Server toCreate = Servers.small(name, drive.getUuid(), defaultVncPassword).mem(template.getHardware().getRam()) + .cpu((int) (template.getHardware().getProcessors().get(0).getSpeed())).build(); + + logger.debug(">> creating server"); + ServerInfo from = client.createServer(toCreate); + logger.debug("<< created server(%s)", from.getUuid()); + logger.debug(">> starting server(%s)", from.getUuid()); + client.startServer(from.getUuid()); + // store the credentials so that later functions can use them + credentialStore.put(from.getUuid() + "", new Credentials("cloudsigma", "cloudsigma")); + return from; + } + + @Override + public Iterable listHardwareProfiles() { + Builder hardware = ImmutableSet. builder(); + for (double cpu : new double[] { 1000, 5000, 10000, 20000 }) + for (int ram : new int[] { 512, 1024, 4 * 1024, 16 * 1024, 32 * 1024 }) { + final float size = (float) ram * 10 / 1024; + String id = String.format("cpu=%f,ram=%s,disk=%f", cpu, ram, size); + hardware.add(new HardwareBuilder().supportsImage(new Predicate() { + + @Override + public boolean apply(Image input) { + String toParse = input.getUserMetadata().get("size"); + return (toParse != null && new Float(toParse) <= size); + } + + @Override + public String toString() { + return "sizeLessThanOrEqual(" + size + ")"; + } + + }).ids(id).ram(ram).processors(ImmutableList.of(new Processor(1, cpu))) + .volumes(ImmutableList. of(new VolumeImpl(size, true, true))).build()); + } + return hardware.build(); + } + + /** + * look up the current standard images and do not error out, if they are not found. + */ + @Override + public Iterable listImages() { + Iterable drives = transformParallel(client.listStandardDrives(), + new Function>() { + + @Override + public Future apply(String input) { + return aclient.getDriveInfo(input); + } + + }, executor, null, logger, "drives"); + Iterable returnVal = filter(drives, PREINSTALLED_DISK); + for (DriveInfo drive : returnVal) + cache.put(drive.getUuid(), drive); + return returnVal; + } + + @SuppressWarnings("unchecked") + @Override + public Iterable listNodes() { + return (Iterable) client.listServerInfo(); + } + + @Override + public Iterable listLocations() { + return ImmutableSet. of(new LocationImpl(LocationScope.PROVIDER, providerName, providerURI + .toASCIIString(), null)); + } + + @Override + public ServerInfo getNode(String id) { + return client.getServerInfo(id); + } + + @Override + public void destroyNode(String id) { + ServerInfo server = getNode(id); + if (server != null) { + client.stopServer(id); + client.destroyServer(id); + for (Device dev : server.getDevices().values()) + client.destroyDrive(dev.getDriveUuid()); + } + } + + @Override + public void rebootNode(String id) { + client.resetServer(id); + } + + @Override + public void resumeNode(String id) { + client.startServer(id); + + } + + @Override + public void suspendNode(String id) { + client.stopServer(id); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java new file mode 100644 index 0000000000..055c85fa6b --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java @@ -0,0 +1,140 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.compute.config; + +import static org.jclouds.compute.domain.OsFamily.UBUNTU; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.cloudsigma.CloudSigmaAsyncClient; +import org.jclouds.cloudsigma.CloudSigmaClient; +import org.jclouds.cloudsigma.compute.CloudSigmaComputeServiceAdapter; +import org.jclouds.cloudsigma.compute.functions.ParseOsFamilyVersion64BitFromImageName; +import org.jclouds.cloudsigma.compute.functions.PreinstalledDiskToImage; +import org.jclouds.cloudsigma.compute.functions.ServerInfoToNodeMetadata; +import org.jclouds.cloudsigma.compute.functions.ServerInfoToNodeMetadata.DeviceToVolume; +import org.jclouds.cloudsigma.compute.functions.ServerInfoToNodeMetadata.FindImageForId; +import org.jclouds.cloudsigma.compute.functions.ServerInfoToNodeMetadata.GetImageIdFromServer; +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.predicates.DriveClaimed; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule.IdentityFunction; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.suppliers.DefaultLocationSupplier; +import org.jclouds.domain.Location; +import org.jclouds.predicates.RetryablePredicate; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.base.Supplier; +import com.google.common.collect.MapMaker; +import com.google.inject.Injector; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +public class CloudSigmaComputeServiceContextModule + extends + ComputeServiceAdapterContextModule { + + public CloudSigmaComputeServiceContextModule() { + super(CloudSigmaClient.class, CloudSigmaAsyncClient.class); + } + + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + return template.osFamily(UBUNTU).osVersionMatches("10.04").os64Bit(true).minRam(1024); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>() { + }).to(CloudSigmaComputeServiceAdapter.class); + bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE); + bind(new TypeLiteral>() { + }).to(DefaultLocationSupplier.class); + bind(new TypeLiteral>() { + }).to(ServerInfoToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); + bind(new TypeLiteral>() { + }).to(PreinstalledDiskToImage.class); + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); + bind(new TypeLiteral>() { + }).to(DeviceToVolume.class); + bind(new TypeLiteral>() { + }).to(GetImageIdFromServer.class); + bind(new TypeLiteral>() { + }).to(FindImageForId.class); + bind(new TypeLiteral>() { + }).to(ParseOsFamilyVersion64BitFromImageName.class); + + } + + @Provides + @Singleton + protected Map cache(GetDrive getDrive) { + return new MapMaker().makeComputingMap(getDrive); + } + + @Singleton + public static class GetDrive implements Function { + private final CloudSigmaClient client; + + @Inject + public GetDrive(CloudSigmaClient client) { + this.client = client; + } + + @Override + public DriveInfo apply(String input) { + return client.getDriveInfo(input); + } + } + + @Provides + @Singleton + protected Predicate supplyDriveUnclaimed(DriveClaimed driveClaimed, + ComputeServiceConstants.Timeouts timeouts) { + return new RetryablePredicate(Predicates.not(driveClaimed), timeouts.nodeRunning, 1000, + TimeUnit.MILLISECONDS); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java new file mode 100644 index 0000000000..a86f2a32e3 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java @@ -0,0 +1,81 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.compute.functions; + +import static com.google.common.base.Predicates.and; +import static com.google.common.base.Predicates.containsPattern; +import static com.google.common.base.Predicates.not; +import static com.google.common.base.Predicates.or; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; + +import com.google.common.base.Function; + +/** + * Defaults to version null and 64bit, if the operating system is unrecognized and the pattern + * "32bit" isn't in the string. + * + * @author Adrian Cole + * + */ +@Singleton +public class ParseOsFamilyVersion64BitFromImageName implements Function { + + // ex CentOS 5.5 Linux 64bit Preinstalled System with AppFirst Monitoring + public static final Pattern PATTERN = Pattern.compile("([^ ]+)[^0-9]([0-9.]+) .*"); + + @Override + public OsFamilyVersion64Bit apply(String input) { + boolean is64Bit = and(not(containsPattern("32bit")), + or(containsPattern("64bit"), not(containsPattern("Windows")))).apply(input); + if (input.contains("Windows")) { + String version = null; + Matcher matcher = Pattern.compile(".*(20[01][0-9] R[1-9]).*").matcher(input); + if (matcher.find()) { + version = matcher.group(1); + } else { + matcher = Pattern.compile(".*(20[01][0-9]).*").matcher(input); + if (matcher.find()) + version = matcher.group(1); + } + return new OsFamilyVersion64Bit(OsFamily.WINDOWS, version, is64Bit); + } else { + Matcher matcher = PATTERN.matcher(input); + if (matcher.find()) { + OsFamily fam = OsFamily.fromValue(matcher.group(1).toLowerCase()); + String version = matcher.group(2); + switch (fam) { + case UNRECOGNIZED: + return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, null, is64Bit); + case WINDOWS: + } + return new OsFamilyVersion64Bit(fam, version, is64Bit); + } else { + return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, null, is64Bit); + } + } + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java new file mode 100644 index 0000000000..1815bac10f --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.compute.functions; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystemBuilder; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +@Singleton +public class PreinstalledDiskToImage implements Function { + private final Supplier locationSupplier; + private final Function imageParser; + + @Inject + public PreinstalledDiskToImage(Supplier locationSupplier, + Function imageParser) { + this.locationSupplier = locationSupplier; + this.imageParser = imageParser; + } + + @Override + public Image apply(DriveInfo drive) { + if (drive.getName() == null) + return null; + String description = drive.getDescription() != null ? drive.getDescription() : drive.getName(); + OperatingSystemBuilder builder = new OperatingSystemBuilder(); + OsFamilyVersion64Bit parsed = imageParser.apply(drive.getName()); + builder.name(drive.getName()).description(description).is64Bit(parsed.is64Bit).version(parsed.version) + .family(parsed.family); + return new ImageBuilder().ids(drive.getUuid()) + .userMetadata(ImmutableMap. of("size", drive.getSize() / 1024 / 1024 / 1024 + "")) + .defaultCredentials(new Credentials("cloudsigma", "cloudsigma")).location(locationSupplier.get()) + .name(drive.getName()).description(description).operatingSystem(builder.build()).version("").build(); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java new file mode 100644 index 0000000000..ef07925402 --- /dev/null +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java @@ -0,0 +1,183 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.cloudsigma.domain.Device; +import org.jclouds.cloudsigma.domain.DriveInfo; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.domain.ServerStatus; +import org.jclouds.collect.FindResourceInSet; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.VolumeBuilder; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Singleton +public class ServerInfoToNodeMetadata implements Function { + public static final Map serverStatusToNodeState = ImmutableMap + . builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)// + .put(ServerStatus.STOPPED, NodeState.SUSPENDED)// + .put(ServerStatus.PAUSED, NodeState.SUSPENDED)// + .put(ServerStatus.DUMPED, NodeState.PENDING)// + .put(ServerStatus.DEAD, NodeState.TERMINATED)// + .put(ServerStatus.UNRECOGNIZED, NodeState.UNRECOGNIZED)// + .build(); + + private final Function getImageIdFromServer; + private final Function findImageForId; + private final Map credentialStore; + private final Supplier locationSupplier; + private final Function deviceToVolume; + + @Inject + ServerInfoToNodeMetadata(Map credentialStore, Function getImageIdFromServer, + Function findImageForId, Function deviceToVolume, + Supplier locationSupplier) { + this.credentialStore = checkNotNull(credentialStore, "credentialStore"); + this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier"); + this.deviceToVolume = checkNotNull(deviceToVolume, "deviceToVolume"); + this.findImageForId = checkNotNull(findImageForId, "findImageForId"); + this.getImageIdFromServer = checkNotNull(getImageIdFromServer, "getImageIdFromServer"); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public NodeMetadata apply(ServerInfo from) { + NodeMetadataBuilder builder = new NodeMetadataBuilder(); + builder.ids(from.getUuid()); + builder.name(from.getName()); + builder.location(locationSupplier.get()); + builder.tag(parseTagFromName(from.getName())); + + String imageId = getImageIdFromServer.apply(from); + if (imageId != null) { + Image image = findImageForId.apply(imageId); + if (image != null) { + builder.operatingSystem(image.getOperatingSystem()); + } + } + builder.hardware(new HardwareBuilder().ids(from.getUuid()) + .processors(ImmutableList.of(new Processor(1, from.getCpu()))).ram(from.getMem()) + .volumes((List) ImmutableList.of(Iterables.transform(from.getDevices().values(), deviceToVolume))).build()); + builder.state(serverStatusToNodeState.get(from.getStatus())); + builder.publicAddresses(ImmutableSet. of(from.getVnc().getIp())); + builder.privateAddresses(ImmutableSet. of()); + builder.credentials(credentialStore.get(from.getUuid())); + // note sudo password! + builder.adminPassword(from.getVnc().getPassword()); + return builder.build(); + } + + @Singleton + public static final class DeviceToVolume implements Function { + private final Map cache; + + @Inject + public DeviceToVolume(Map cache) { + this.cache = checkNotNull(cache, "cache"); + } + + @Override + public Volume apply(Device input) { + VolumeBuilder builder = new VolumeBuilder(); + builder.id(input.getId()); + DriveInfo drive = cache.get(input.getDriveUuid()); + if (drive != null) { + builder.size(drive.getSize() / 1024 / 1024f); + } + return new VolumeBuilder().durable(true).type(Volume.Type.NAS).build(); + } + } + + /** + * When we create the boot drive of the server, by convention we set the name to the image it + * came from. + * + * @author Adrian Cole + * + */ + @Singleton + public static class GetImageIdFromServer implements Function { + private final Map cache; + + @Inject + public GetImageIdFromServer(Map cache) { + this.cache = cache; + } + + @Override + public String apply(Server from) { + String imageId = null; + String bootDeviceId = Iterables.get(from.getBootDeviceIds(), 0); + Device bootDevice = from.getDevices().get(bootDeviceId); + if (bootDevice != null) { + try { + imageId = cache.get(bootDevice.getDriveUuid()).getName(); + } catch (NullPointerException e) { + + } + } + return imageId; + } + } + + @Singleton + public static class FindImageForId extends FindResourceInSet { + + @Inject + public FindImageForId(@Memoized Supplier> images) { + super(images); + } + + @Override + public boolean matches(String from, Image input) { + return input.getProviderId().equals(from); + } + } + +} diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java index bf3ac43598..54ef298a44 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java @@ -25,7 +25,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ReturnStringIf2xx; diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java index 70c971ba89..bf9e95fab9 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java @@ -25,7 +25,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.cloudsigma.domain.ServerInfo; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ReturnStringIf2xx; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java index 934e7064a4..d4c89f84f5 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java @@ -25,17 +25,17 @@ import java.io.IOException; import java.lang.reflect.Method; import java.util.Properties; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; -import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.cloudsigma.binders.BindServerToPlainTextStringTest; import org.jclouds.cloudsigma.domain.CreateDriveRequest; import org.jclouds.cloudsigma.domain.Drive; import org.jclouds.cloudsigma.domain.DriveData; import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; +import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; import org.jclouds.cloudsigma.functions.SplitNewlines; +import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ReleasePayloadAndReturn; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java index f95716e78c..997fce89e8 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java @@ -44,13 +44,13 @@ import org.jclouds.cloudsigma.domain.ServerStatus; import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.cloudsigma.predicates.DriveClaimed; import org.jclouds.cloudsigma.util.Servers; +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.domain.Credentials; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.jsch.config.JschSshClientModule; @@ -112,11 +112,8 @@ public class CloudSigmaClientLiveTest { public void setupClient() { setupCredentials(); Properties overrides = setupProperties(); - // context = new ComputeServiceContextFactory().createContext(provider, - // ImmutableSet. of(new Log4JLoggingModule()), - // overrides).getProviderSpecificContext(); - context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); client = context.getApi(); driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, @@ -159,9 +156,13 @@ public class CloudSigmaClientLiveTest { @Test public void testGetDrive() throws Exception { - for (String driveUUID : client.listDrives()) { + for (String driveUUID : client.listStandardDrives()) { assert !"".equals(driveUUID); - assertNotNull(client.getDriveInfo(driveUUID)); + DriveInfo drive = client.getDriveInfo(driveUUID); + assertNotNull(drive); + assert !drive.getType().equals(DriveType.UNRECOGNIZED) : drive; + if (drive.getType() == DriveType.DISK && drive.getDriveType().contains("preinstalled")) + System.out.println(drive.getName()); } } diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java new file mode 100644 index 0000000000..be182ee43d --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java @@ -0,0 +1,39 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.cloudsigma.compute; + +import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "live") +public class CloudSigmaComputeServiceLiveTest extends BaseComputeServiceLiveTest { + public CloudSigmaComputeServiceLiveTest() { + provider = "cloudsigma"; + } + + @Override + protected JschSshClientModule getSshModule() { + return new JschSshClientModule(); + } + +} diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..d8237511c6 --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.compute; + +import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class CloudSigmaTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { + + public CloudSigmaTemplateBuilderLiveTest() { + provider = "cloudsigma"; + } + + @Override + protected Predicate defineUnsupportedOperatingSystems() { + return new Predicate() { + + @Override + public boolean apply(OsFamilyVersion64Bit input) { + return ((input.family == OsFamily.RHEL) || // + (input.family == OsFamily.CENTOS && !(input.version.equals("5.5") && input.is64Bit)) || // + (input.family == OsFamily.UBUNTU && !(input.version.matches("10.[01][04]") && input.is64Bit)) || // + (input.family == OsFamily.WINDOWS && !((input.version.equals("2008 R2") && input.is64Bit) + || (input.version.equals("2008") && !input.is64Bit) || (input.version.equals("2003")))) // + ); + } + + }; + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java index 75de5a003f..62eadbf8ef 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java @@ -28,11 +28,7 @@ import org.jclouds.cloudsigma.domain.Device; import org.jclouds.cloudsigma.domain.DriveMetrics; import org.jclouds.cloudsigma.domain.NIC; import org.jclouds.cloudsigma.domain.ServerMetrics; -import org.jclouds.cloudsigma.functions.MapToDevices; import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; -import org.jclouds.cloudsigma.functions.MapToDriveMetrics; -import org.jclouds.cloudsigma.functions.MapToNICs; -import org.jclouds.cloudsigma.functions.MapToServerMetrics; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; import org.testng.annotations.Test; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java index 757c05543e..90cd45cbbd 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java @@ -29,11 +29,7 @@ import org.jclouds.cloudsigma.domain.DriveMetrics; import org.jclouds.cloudsigma.domain.NIC; import org.jclouds.cloudsigma.domain.ServerInfo; import org.jclouds.cloudsigma.domain.ServerMetrics; -import org.jclouds.cloudsigma.functions.MapToDevices; import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; -import org.jclouds.cloudsigma.functions.MapToDriveMetrics; -import org.jclouds.cloudsigma.functions.MapToNICs; -import org.jclouds.cloudsigma.functions.MapToServerMetrics; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; import org.testng.annotations.Test; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java index e8eed37b99..d7fe5a6ae8 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java @@ -34,12 +34,7 @@ import org.jclouds.cloudsigma.domain.ServerInfo; import org.jclouds.cloudsigma.domain.ServerMetrics; import org.jclouds.cloudsigma.domain.ServerStatus; import org.jclouds.cloudsigma.domain.VNC; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; -import org.jclouds.cloudsigma.functions.MapToDevices; import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; -import org.jclouds.cloudsigma.functions.MapToDriveMetrics; -import org.jclouds.cloudsigma.functions.MapToNICs; -import org.jclouds.cloudsigma.functions.MapToServerMetrics; import org.jclouds.util.Utils; import org.testng.annotations.Test; diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java new file mode 100644 index 0000000000..d31e5129df --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static com.google.common.collect.Iterables.transform; +import static com.google.common.collect.Lists.newArrayList; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Map.Entry; + +import org.jclouds.cloudsigma.compute.functions.ParseOsFamilyVersion64BitFromImageName; +import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; +import org.jclouds.json.Json; +import org.jclouds.json.internal.GsonWrapper; +import org.jclouds.util.Utils; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.gson.Gson; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ParseOsFamilyVersion64BitFromImageNameTest { + Json json = new GsonWrapper(new Gson()); + + @DataProvider(name = "data") + public Object[][] createData() throws IOException { + InputStream is = ParseOsFamilyVersion64BitFromImageNameTest.class.getResourceAsStream("/osmatches.json"); + Map values = json.fromJson(Utils.toStringAndClose(is), + new TypeLiteral>() { + }.getType()); + + return newArrayList( + transform(values.entrySet(), new Function, Object[]>() { + + @Override + public Object[] apply(Entry input) { + return new Object[] { input.getKey(), input.getValue() }; + } + + })).toArray(new Object[][] {}); + } + + ParseOsFamilyVersion64BitFromImageName parser = new ParseOsFamilyVersion64BitFromImageName(); + + @Test(dataProvider = "data") + public void test(String input, OsFamilyVersion64Bit expected) { + assertEquals(parser.apply(input), expected); + } +} diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java index 13076a59b0..f595c0647b 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java @@ -24,7 +24,6 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Set; -import org.jclouds.cloudsigma.functions.SplitNewlines; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; import org.testng.annotations.Test; diff --git a/sandbox/cloudsigma/src/test/resources/osmatches.json b/sandbox/cloudsigma/src/test/resources/osmatches.json new file mode 100644 index 0000000000..963b533fc5 --- /dev/null +++ b/sandbox/cloudsigma/src/test/resources/osmatches.json @@ -0,0 +1,140 @@ +{ + + "Ubuntu 10.04 Server Edition Linux 64bit with Plesk": { + "family": "UBUNTU", + "version": "10.04", + "is64Bit": true + }, + + "CentOS 5.5 Linux 64bit Preinstalled System": { + "family": "CENTOS", + "version": "5.5", + "is64Bit": true + }, + + "Windows Server Standard 2008 R2 64bit English": { + "family": "WINDOWS", + "version": "2008 R2", + "is64Bit": true + }, + + "Ubuntu 10.04 Server Edition Linux 64bit": { + "family": "UBUNTU", + "version": "10.04", + "is64Bit": true + }, + + "Windows Server 2008 Standard 32bit English": { + "family": "WINDOWS", + "version": "2008", + "is64Bit": false + }, + + "Windows Server 2008 Standard 32bit English pub": { + "family": "WINDOWS", + "version": "2008", + "is64Bit": false + }, + + + "Fedora 14 Linux 64bit Preinstalled System": { + "family": "FEDORA", + "version": "14", + "is64Bit": true + }, + + "CentOS 5.5 Linux 64bit Preinstalled System with AppFirst Monitoring pub": { + "family": "CENTOS", + "version": "5.5", + "is64Bit": true + }, + + + "Ubuntu 10.10 Server Edition LAMP Linux 64bit Preinstalled System": { + "family": "UBUNTU", + "version": "10.10", + "is64Bit": true + }, + + "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System": { + "family": "UBUNTU", + "version": "10.10", + "is64Bit": true + }, + + "Windows Server Web 2008 R2 64bit English": { + "family": "WINDOWS", + "version": "2008 R2", + "is64Bit": true + }, + + + "SQL Server Standard 2008 R2 - Windows Server Standard 2008 R2 - 64bit English": { + "family": "WINDOWS", + "version": "2008 R2", + "is64Bit": true + }, + + + "Ubuntu 10.10 Desktop Edition 64bit Preinstalled System": { + "family": "UBUNTU", + "version": "10.10", + "is64Bit": true + }, + + "Ubuntu 10.04 Desktop Edition Linux 64bit Preinstalled System": { + "family": "UBUNTU", + "version": "10.04", + "is64Bit": true + }, + + "Debian 5.0 Preinstalled": { + "family": "DEBIAN", + "version": "5.0", + "is64Bit": true + }, + + "pfSense 2.0 BETA4-20101127-031119 Preinstalled System": { + "family": "UNRECOGNIZED", + "version": null, + "is64Bit": true + }, + + "FreeBSD 8.1 Preinstalled Base System": { + "family": "FREEBSD", + "version": "8.1", + "is64Bit": true + }, + + "CentOS 5.5 Linux 64bit Preinstalled System with AppFirst Monitoring": { + "family": "CENTOS", + "version": "5.5", + "is64Bit": true + }, + + "Fedora 13 Linux 64bit Preinstalled System": { + "family": "FEDORA", + "version": "13", + "is64Bit": true + }, + + "Windows Server 2003 Standard 32bit English": { + "family": "WINDOWS", + "version": "2003", + "is64Bit": false + }, + + "Windows Server 2003 Standard 64bit English": { + "family": "WINDOWS", + "version": "2003", + "is64Bit": true + }, + + "Debian 5.0 Preinstalled without X": { + "family": "DEBIAN", + "version": "5.0", + "is64Bit": true + } + + +} \ No newline at end of file From 413900bac0cf991bb5bcb7be0ce6bd487bfc7357 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 15:16:04 +0100 Subject: [PATCH 27/33] cloudsigma as a top-level provider --- README.txt | 2 +- allcompute/pom.xml | 5 +++++ {sandbox/cloudsigma => cloudsigma}/pom.xml | 2 +- .../java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java | 0 .../main/java/org/jclouds/cloudsigma/CloudSigmaClient.java | 0 .../org/jclouds/cloudsigma/CloudSigmaContextBuilder.java | 0 .../org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java | 0 .../binders/BindCloneDriveOptionsToPlainTextString.java | 0 .../cloudsigma/binders/BindDriveDataToPlainTextString.java | 0 .../cloudsigma/binders/BindDriveToPlainTextString.java | 0 .../cloudsigma/binders/BindServerToPlainTextString.java | 0 .../cloudsigma/compute/CloudSigmaComputeServiceAdapter.java | 0 .../config/CloudSigmaComputeServiceContextModule.java | 0 .../functions/ParseOsFamilyVersion64BitFromImageName.java | 0 .../compute/functions/PreinstalledDiskToImage.java | 0 .../compute/functions/ServerInfoToNodeMetadata.java | 0 .../cloudsigma/config/CloudSigmaRestClientModule.java | 0 .../main/java/org/jclouds/cloudsigma/domain/BlockDevice.java | 0 .../main/java/org/jclouds/cloudsigma/domain/ClaimType.java | 0 .../org/jclouds/cloudsigma/domain/CreateDriveRequest.java | 0 .../src/main/java/org/jclouds/cloudsigma/domain/Device.java | 0 .../src/main/java/org/jclouds/cloudsigma/domain/Drive.java | 0 .../main/java/org/jclouds/cloudsigma/domain/DriveData.java | 0 .../main/java/org/jclouds/cloudsigma/domain/DriveInfo.java | 0 .../java/org/jclouds/cloudsigma/domain/DriveMetrics.java | 0 .../main/java/org/jclouds/cloudsigma/domain/DriveStatus.java | 0 .../main/java/org/jclouds/cloudsigma/domain/DriveType.java | 0 .../main/java/org/jclouds/cloudsigma/domain/IDEDevice.java | 0 .../src/main/java/org/jclouds/cloudsigma/domain/Item.java | 0 .../main/java/org/jclouds/cloudsigma/domain/MediaType.java | 0 .../src/main/java/org/jclouds/cloudsigma/domain/Model.java | 0 .../src/main/java/org/jclouds/cloudsigma/domain/NIC.java | 0 .../main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java | 0 .../src/main/java/org/jclouds/cloudsigma/domain/Server.java | 0 .../main/java/org/jclouds/cloudsigma/domain/ServerInfo.java | 0 .../java/org/jclouds/cloudsigma/domain/ServerMetrics.java | 0 .../java/org/jclouds/cloudsigma/domain/ServerStatus.java | 0 .../src/main/java/org/jclouds/cloudsigma/domain/VNC.java | 0 .../org/jclouds/cloudsigma/functions/BaseDriveToMap.java | 0 .../org/jclouds/cloudsigma/functions/DriveDataToMap.java | 0 .../functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java | 0 .../KeyValuesDelimitedByBlankLinesToServerInfo.java | 0 .../ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java | 0 .../ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java | 0 .../ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java | 0 .../ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java | 0 .../java/org/jclouds/cloudsigma/functions/MapToDevices.java | 0 .../org/jclouds/cloudsigma/functions/MapToDriveInfo.java | 0 .../org/jclouds/cloudsigma/functions/MapToDriveMetrics.java | 0 .../java/org/jclouds/cloudsigma/functions/MapToNICs.java | 0 .../org/jclouds/cloudsigma/functions/MapToServerInfo.java | 0 .../org/jclouds/cloudsigma/functions/MapToServerMetrics.java | 0 .../java/org/jclouds/cloudsigma/functions/ReturnPayload.java | 0 .../java/org/jclouds/cloudsigma/functions/ServerToMap.java | 0 .../java/org/jclouds/cloudsigma/functions/SplitNewlines.java | 0 .../jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java | 0 .../org/jclouds/cloudsigma/options/CloneDriveOptions.java | 0 .../java/org/jclouds/cloudsigma/predicates/DriveClaimed.java | 0 .../jclouds/cloudsigma/reference/CloudSigmaConstants.java | 0 .../src/main/java/org/jclouds/cloudsigma/util/Servers.java | 0 .../org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java | 0 .../org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java | 0 .../org/jclouds/cloudsigma/ProvidersInPropertiesTest.java | 0 .../binders/BindCloneDriveOptionsToPlainTextStringTest.java | 0 .../binders/BindDriveDataToPlainTextStringTest.java | 0 .../cloudsigma/binders/BindDriveToPlainTextStringTest.java | 0 .../cloudsigma/binders/BindServerToPlainTextStringTest.java | 0 .../cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java | 0 .../compute/CloudSigmaTemplateBuilderLiveTest.java | 0 .../org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java | 0 .../org/jclouds/cloudsigma/functions/DriveDataToMapTest.java | 0 .../KeyValuesDelimitedByBlankLinesToDriveInfoTest.java | 0 .../KeyValuesDelimitedByBlankLinesToServerInfoTest.java | 0 ...stOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java | 0 ...ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java | 0 ...tOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java | 0 ...ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java | 0 .../org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java | 0 .../jclouds/cloudsigma/functions/MapToServerInfoTest.java | 0 .../ParseOsFamilyVersion64BitFromImageNameTest.java | 0 .../org/jclouds/cloudsigma/functions/ServerToMapTest.java | 0 .../org/jclouds/cloudsigma/functions/SplitNewlinesTest.java | 0 .../cloudsigma/handlers/CloudSigmaErrorHandlerTest.java | 0 .../jclouds/cloudsigma/options/CloneDriveOptionsTest.java | 0 .../src/test/resources/create_drive.txt | 0 .../src/test/resources/create_server.txt | 0 .../cloudsigma => cloudsigma}/src/test/resources/drive.txt | 0 .../src/test/resources/drive_data.txt | 0 .../cloudsigma => cloudsigma}/src/test/resources/log4j.xml | 0 .../src/test/resources/new_server.txt | 0 .../src/test/resources/osmatches.json | 0 .../cloudsigma => cloudsigma}/src/test/resources/servers.txt | 0 .../cloudsigma => cloudsigma}/src/test/resources/uuids.txt | 0 compute/src/main/clojure/org/jclouds/compute.clj | 2 +- pom.xml | 1 + 95 files changed, 9 insertions(+), 3 deletions(-) rename {sandbox/cloudsigma => cloudsigma}/pom.xml (99%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/Device.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/Drive.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/DriveType.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/Item.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/Model.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/NIC.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/Server.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/domain/VNC.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/BaseDriveToMap.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/main/java/org/jclouds/cloudsigma/util/Servers.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/create_drive.txt (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/create_server.txt (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/drive.txt (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/drive_data.txt (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/log4j.xml (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/new_server.txt (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/osmatches.json (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/servers.txt (100%) rename {sandbox/cloudsigma => cloudsigma}/src/test/resources/uuids.txt (100%) diff --git a/README.txt b/README.txt index efc7e7bf3e..f438745c1a 100644 --- a/README.txt +++ b/README.txt @@ -30,7 +30,7 @@ our current version is 1.0-beta-8 our dev version is 1.0-SNAPSHOT our compute api supports: ec2, gogrid, cloudservers (rackspace), rimuhosting, vcloud, - trmk-ecloud, trmk-vcloudexpress, eucalyptus, + trmk-ecloud, trmk-vcloudexpress, eucalyptus, cloudsigma, elasticstack, bluelock-vclouddirector, slicehost, elastichosts-lon-p (Peer 1), elastichosts-sat-p (Peer 1), elastichosts-lon-b (BlueSquare), stub (in-memory) diff --git a/allcompute/pom.xml b/allcompute/pom.xml index 8e00363dd1..3d4e4dfb54 100644 --- a/allcompute/pom.xml +++ b/allcompute/pom.xml @@ -74,5 +74,10 @@ jclouds-elasticstack ${project.version} + + ${project.groupId} + jclouds-cloudsigma + ${project.version} + diff --git a/sandbox/cloudsigma/pom.xml b/cloudsigma/pom.xml similarity index 99% rename from sandbox/cloudsigma/pom.xml rename to cloudsigma/pom.xml index b0169695f4..d920f70eac 100644 --- a/sandbox/cloudsigma/pom.xml +++ b/cloudsigma/pom.xml @@ -28,7 +28,7 @@ org.jclouds jclouds-project 1.0-SNAPSHOT - ../../project/pom.xml + ../project/pom.xml org.jclouds jclouds-cloudsigma diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaClient.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextString.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ParseOsFamilyVersion64BitFromImageName.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/PreinstalledDiskToImage.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/config/CloudSigmaRestClientModule.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Device.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Device.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Device.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Device.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Drive.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Drive.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Drive.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Drive.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveInfo.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveType.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveType.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveType.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveType.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Item.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Item.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Item.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Item.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Model.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Model.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Model.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Model.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/NIC.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/NIC.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/NIC.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/NIC.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Server.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Server.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Server.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Server.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/VNC.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/VNC.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/VNC.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/VNC.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/BaseDriveToMap.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/BaseDriveToMap.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/BaseDriveToMap.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/BaseDriveToMap.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfo.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfo.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveInfo.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerInfo.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ServerToMap.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/util/Servers.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/util/Servers.java similarity index 100% rename from sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/util/Servers.java rename to cloudsigma/src/main/java/org/jclouds/cloudsigma/util/Servers.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaTemplateBuilderLiveTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java b/cloudsigma/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java similarity index 100% rename from sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java rename to cloudsigma/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java diff --git a/sandbox/cloudsigma/src/test/resources/create_drive.txt b/cloudsigma/src/test/resources/create_drive.txt similarity index 100% rename from sandbox/cloudsigma/src/test/resources/create_drive.txt rename to cloudsigma/src/test/resources/create_drive.txt diff --git a/sandbox/cloudsigma/src/test/resources/create_server.txt b/cloudsigma/src/test/resources/create_server.txt similarity index 100% rename from sandbox/cloudsigma/src/test/resources/create_server.txt rename to cloudsigma/src/test/resources/create_server.txt diff --git a/sandbox/cloudsigma/src/test/resources/drive.txt b/cloudsigma/src/test/resources/drive.txt similarity index 100% rename from sandbox/cloudsigma/src/test/resources/drive.txt rename to cloudsigma/src/test/resources/drive.txt diff --git a/sandbox/cloudsigma/src/test/resources/drive_data.txt b/cloudsigma/src/test/resources/drive_data.txt similarity index 100% rename from sandbox/cloudsigma/src/test/resources/drive_data.txt rename to cloudsigma/src/test/resources/drive_data.txt diff --git a/sandbox/cloudsigma/src/test/resources/log4j.xml b/cloudsigma/src/test/resources/log4j.xml similarity index 100% rename from sandbox/cloudsigma/src/test/resources/log4j.xml rename to cloudsigma/src/test/resources/log4j.xml diff --git a/sandbox/cloudsigma/src/test/resources/new_server.txt b/cloudsigma/src/test/resources/new_server.txt similarity index 100% rename from sandbox/cloudsigma/src/test/resources/new_server.txt rename to cloudsigma/src/test/resources/new_server.txt diff --git a/sandbox/cloudsigma/src/test/resources/osmatches.json b/cloudsigma/src/test/resources/osmatches.json similarity index 100% rename from sandbox/cloudsigma/src/test/resources/osmatches.json rename to cloudsigma/src/test/resources/osmatches.json diff --git a/sandbox/cloudsigma/src/test/resources/servers.txt b/cloudsigma/src/test/resources/servers.txt similarity index 100% rename from sandbox/cloudsigma/src/test/resources/servers.txt rename to cloudsigma/src/test/resources/servers.txt diff --git a/sandbox/cloudsigma/src/test/resources/uuids.txt b/cloudsigma/src/test/resources/uuids.txt similarity index 100% rename from sandbox/cloudsigma/src/test/resources/uuids.txt rename to cloudsigma/src/test/resources/uuids.txt diff --git a/compute/src/main/clojure/org/jclouds/compute.clj b/compute/src/main/clojure/org/jclouds/compute.clj index dd140be944..e78dd3f697 100644 --- a/compute/src/main/clojure/org/jclouds/compute.clj +++ b/compute/src/main/clojure/org/jclouds/compute.clj @@ -23,7 +23,7 @@ Current supported services are: [ec2, rimuhosting, cloudservers, trmk-ecloud, trmk-vcloudexpress, vcloud, bluelock, eucalyptus, slicehost, elastichosts-lon-p, elastichosts-sat-p, - elastichosts, elastichosts-lon-b, stub] + elastichosts, elastichosts-lon-b, cloudsigma, stub] Here's an example of getting some compute configuration from rackspace: diff --git a/pom.xml b/pom.xml index 48c19ae35e..798c852b84 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,7 @@ vcloud gogrid elasticstack + cloudsigma allcompute allblobstore all From 0f5f97d6d3d368061c0cfae926d2b787b8c56675 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 15:40:48 +0100 Subject: [PATCH 28/33] revised default disk size for cloudsigma --- .../cloudsigma/compute/CloudSigmaComputeServiceAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java b/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java index a3c9dcfdc6..c29111a60a 100644 --- a/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java +++ b/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java @@ -144,7 +144,7 @@ public class CloudSigmaComputeServiceAdapter implements Builder hardware = ImmutableSet. builder(); for (double cpu : new double[] { 1000, 5000, 10000, 20000 }) for (int ram : new int[] { 512, 1024, 4 * 1024, 16 * 1024, 32 * 1024 }) { - final float size = (float) ram * 10 / 1024; + final float size = (float) cpu / 100; String id = String.format("cpu=%f,ram=%s,disk=%f", cpu, ram, size); hardware.add(new HardwareBuilder().supportsImage(new Predicate() { From 4426bef0fa491fd31a04dce661d26228d945069b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 21:24:22 +0100 Subject: [PATCH 29/33] fixed maven details --- README.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.txt b/README.txt index f438745c1a..6ef98d2ad9 100644 --- a/README.txt +++ b/README.txt @@ -105,8 +105,8 @@ Compute Example (Clojure): Downloads: * distribution zip: http://jclouds.googlecode.com/files/jclouds-1.0-beta-8.zip - * maven repo: http://jclouds.googlecode.com/svn/repo - * snapshot repo: http://jclouds.rimuhosting.com/maven2/snapshots + * maven repo: https://oss.sonatype.org/content/repositories/releases + * snapshot repo: https://oss.sonatype.org/content/repositories/snapshots Links: * project page: http://code.google.com/p/jclouds/ From 0423f08a8703e6bd4b16edad372abe0be746c360 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 21:52:40 +0100 Subject: [PATCH 30/33] issue 432 --- core/src/main/java/org/jclouds/io/MutableContentMetadata.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/jclouds/io/MutableContentMetadata.java b/core/src/main/java/org/jclouds/io/MutableContentMetadata.java index 84953cface..60ff465e2f 100644 --- a/core/src/main/java/org/jclouds/io/MutableContentMetadata.java +++ b/core/src/main/java/org/jclouds/io/MutableContentMetadata.java @@ -30,7 +30,7 @@ public interface MutableContentMetadata extends ContentMetadata { void setContentMD5(@Nullable byte[] md5); - void setContentType(@Nullable String md5); + void setContentType(@Nullable String contentType); /** * Set Content Disposition of the payload From 892bc85d4e9a3e1e37e3e805939f63524cf94855 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 21:56:53 +0100 Subject: [PATCH 31/33] Issue 433: don't accept empty userdata --- .../aws/ec2/options/RunInstancesOptions.java | 5 +- .../ec2/options/RunInstancesOptionsTest.java | 57 ++++++++----------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java b/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java index b9bd70cb42..1775dc1bb3 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java @@ -121,8 +121,9 @@ public class RunInstancesOptions extends BaseEC2RequestOptions { * Unencoded data */ public RunInstancesOptions withUserData(byte[] unencodedData) { - checkArgument(checkNotNull(unencodedData, "unencodedData").length <= 16 * 1024, - "userData cannot be larger than 16kb"); + int length = checkNotNull(unencodedData, "unencodedData").length; + checkArgument(length > 0, "userData cannot be empty"); + checkArgument(length <= 16 * 1024, "userData cannot be larger than 16kb"); formParameters.put("UserData", Base64.encodeBytes(unencodedData)); return this; } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/options/RunInstancesOptionsTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/options/RunInstancesOptionsTest.java index 945ab9f88b..fa51852597 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/options/RunInstancesOptionsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/options/RunInstancesOptionsTest.java @@ -79,8 +79,7 @@ public class RunInstancesOptionsTest { public void testWithSecurityGroup() { RunInstancesOptions options = new RunInstancesOptions(); options.withSecurityGroup("test"); - assertEquals(options.buildFormParameters().get("SecurityGroup.1"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("SecurityGroup.1"), Collections.singletonList("test")); } @Test @@ -92,8 +91,7 @@ public class RunInstancesOptionsTest { @Test public void testWithSecurityGroupStatic() { RunInstancesOptions options = withSecurityGroup("test"); - assertEquals(options.buildFormParameters().get("SecurityGroup.1"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("SecurityGroup.1"), Collections.singletonList("test")); } @Test(expectedExceptions = NullPointerException.class) @@ -105,8 +103,7 @@ public class RunInstancesOptionsTest { public void testWithAdditionalInfo() { RunInstancesOptions options = new RunInstancesOptions(); options.withAdditionalInfo("test"); - assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections.singletonList("test")); } @Test @@ -118,8 +115,7 @@ public class RunInstancesOptionsTest { @Test public void testWithAdditionalInfoStatic() { RunInstancesOptions options = withAdditionalInfo("test"); - assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections.singletonList("test")); } @Test(expectedExceptions = NullPointerException.class) @@ -151,12 +147,16 @@ public class RunInstancesOptionsTest { withUserData(null); } + @Test(expectedExceptions = IllegalArgumentException.class) + public void testWithUserDataEmpty() { + withUserData("".getBytes()); + } + @Test public void testWithInstanceType() { RunInstancesOptions options = new RunInstancesOptions(); options.asType(InstanceType.C1_XLARGE); - assertEquals(options.buildFormParameters().get("InstanceType"), Collections - .singletonList("c1.xlarge")); + assertEquals(options.buildFormParameters().get("InstanceType"), Collections.singletonList("c1.xlarge")); } @Test @@ -168,8 +168,7 @@ public class RunInstancesOptionsTest { @Test public void testWithInstanceTypeStatic() { RunInstancesOptions options = asType(InstanceType.C1_XLARGE); - assertEquals(options.buildFormParameters().get("InstanceType"), Collections - .singletonList("c1.xlarge")); + assertEquals(options.buildFormParameters().get("InstanceType"), Collections.singletonList("c1.xlarge")); } @Test(expectedExceptions = NullPointerException.class) @@ -205,22 +204,21 @@ public class RunInstancesOptionsTest { public void testWithDeviceName() { RunInstancesOptions options = new RunInstancesOptions(); options.withDeviceName("test"); - assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), + Collections.singletonList("test")); } @Test public void testNullWithDeviceName() { RunInstancesOptions options = new RunInstancesOptions(); - assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), - Collections.EMPTY_LIST); + assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), Collections.EMPTY_LIST); } @Test public void testWithDeviceNameStatic() { RunInstancesOptions options = withDeviceName("test"); - assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), + Collections.singletonList("test")); } @Test(expectedExceptions = NullPointerException.class) @@ -232,8 +230,7 @@ public class RunInstancesOptionsTest { public void testWithMonitoringEnabled() { RunInstancesOptions options = new RunInstancesOptions(); options.enableMonitoring(); - assertEquals(options.buildFormParameters().get("Monitoring.Enabled"), Collections - .singletonList("true")); + assertEquals(options.buildFormParameters().get("Monitoring.Enabled"), Collections.singletonList("true")); } @Test @@ -245,8 +242,7 @@ public class RunInstancesOptionsTest { @Test public void testWithMonitoringEnabledStatic() { RunInstancesOptions options = enableMonitoring(); - assertEquals(options.buildFormParameters().get("Monitoring.Enabled"), Collections - .singletonList("true")); + assertEquals(options.buildFormParameters().get("Monitoring.Enabled"), Collections.singletonList("true")); } @Test @@ -277,8 +273,7 @@ public class RunInstancesOptionsTest { public void testWithRamdisk() { RunInstancesOptions options = new RunInstancesOptions(); options.withRamdisk("test"); - assertEquals(options.buildFormParameters().get("RamdiskId"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("RamdiskId"), Collections.singletonList("test")); } @Test @@ -290,8 +285,7 @@ public class RunInstancesOptionsTest { @Test public void testWithRamdiskStatic() { RunInstancesOptions options = withRamdisk("test"); - assertEquals(options.buildFormParameters().get("RamdiskId"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("RamdiskId"), Collections.singletonList("test")); } @Test(expectedExceptions = NullPointerException.class) @@ -303,22 +297,21 @@ public class RunInstancesOptionsTest { public void testWithVirtualName() { RunInstancesOptions options = new RunInstancesOptions(); options.withVirtualName("test"); - assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), + Collections.singletonList("test")); } @Test public void testNullWithVirtualName() { RunInstancesOptions options = new RunInstancesOptions(); - assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), - Collections.EMPTY_LIST); + assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), Collections.EMPTY_LIST); } @Test public void testWithVirtualNameStatic() { RunInstancesOptions options = withVirtualName("test"); - assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), Collections - .singletonList("test")); + assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), + Collections.singletonList("test")); } @Test(expectedExceptions = NullPointerException.class) From d60df6cd6b5b56a0c680a9ee05fca45e7bcc9309 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 21 Dec 2010 13:33:38 +0100 Subject: [PATCH 32/33] added instructions for delta --- sandbox/deltacloud/README.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sandbox/deltacloud/README.txt diff --git a/sandbox/deltacloud/README.txt b/sandbox/deltacloud/README.txt new file mode 100644 index 0000000000..ee1b021e83 --- /dev/null +++ b/sandbox/deltacloud/README.txt @@ -0,0 +1,9 @@ +To install deltacloud, do the following: + * OS/X and jruby + # brew install jruby + # jruby -S gem --version 1.1.0 install rack + # jruby -S gem install deltacloud-core + +To run a local deltacloud server, do the following: + * jruby + * jruby -S deltacloudd -i mock From 946311f8129e8bf9fb105d129965e823b93abd95 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 21 Dec 2010 14:22:10 +0100 Subject: [PATCH 33/33] Issue 427: deltacloud refactor and image support --- ...rityGroupsAsNeededAndReturnRunOptions.java | 4 - .../aws/ec2/options/RunInstancesOptions.java | 23 +-- ...GroupsAsNeededAndReturnRunOptionsTest.java | 81 ++------- .../ec2/options/RunInstancesOptionsTest.java | 19 -- sandbox/deltacloud/pom.xml | 4 +- .../deltacloud/DeltacloudAsyncClient.java | 36 +++- .../jclouds/deltacloud/DeltacloudClient.java | 22 ++- .../DeltacloudCollection.java | 10 +- .../deltacloud/collections/Images.java | 40 +++++ .../deltacloud/collections/Instances.java | 40 +++++ .../config/DeltacloudRestClientModule.java | 52 +++++- .../deltacloud/domain/Architecture.java | 29 ++++ .../org/jclouds/deltacloud/domain/Image.java | 164 ++++++++++++++++++ .../jclouds/deltacloud/xml/ImageHandler.java | 87 ++++++++++ .../jclouds/deltacloud/xml/ImagesHandler.java | 69 ++++++++ .../jclouds/deltacloud/xml/LinksHandler.java | 2 +- .../deltacloud/DeltacloudAsyncClientTest.java | 87 ++++++++-- .../deltacloud/DeltacloudClientLiveTest.java | 17 +- .../deltacloud/handlers/LinksHandlerTest.java | 2 +- .../deltacloud/xml/ImageHandlerTest.java | 65 +++++++ .../deltacloud/xml/ImagesHandlerTest.java | 60 +++++++ .../src/test/resources/test_get_image.xml | 7 + .../src/test/resources/test_list_images.xml | 20 +++ 23 files changed, 800 insertions(+), 140 deletions(-) rename sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/{reference => collections}/DeltacloudCollection.java (80%) create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/Images.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/Instances.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Architecture.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Image.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/ImageHandler.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/ImagesHandler.java create mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImageHandlerTest.java create mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImagesHandlerTest.java create mode 100644 sandbox/deltacloud/src/test/resources/test_get_image.xml create mode 100644 sandbox/deltacloud/src/test/resources/test_list_images.xml diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java index 97be5ce8e0..cc7839635d 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java @@ -89,10 +89,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions RunInstancesOptions instanceOptions = asType(template.getHardware().getId()); - // Eucalyptus currently doesn't support additional info - if (!"eucalyptus".equals(getProvider())) - instanceOptions.withAdditionalInfo(tag); - String keyPairName = createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, template.getOptions()); String placementGroupName = template.getHardware().getId().startsWith("cc") ? createNewPlacementGroupUnlessUserSpecifiedOtherwise( diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java b/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java index 1775dc1bb3..0701fe43ba 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/options/RunInstancesOptions.java @@ -41,7 +41,8 @@ import org.jclouds.encryption.internal.Base64; * * @author Adrian Cole * @see
*/ public class RunInstancesOptions extends BaseEC2RequestOptions { @@ -105,18 +106,6 @@ public class RunInstancesOptions extends BaseEC2RequestOptions { return getFirstFormOrNull("Placement.GroupName"); } - /** - * Specifies additional information to make available to the instance(s). - */ - public RunInstancesOptions withAdditionalInfo(String info) { - formParameters.put("AdditionalInfo", checkNotNull(info, "info")); - return this; - } - - String getAdditionalInfo() { - return getFirstFormOrNull("AdditionalInfo"); - } - /** * Unencoded data */ @@ -245,14 +234,6 @@ public class RunInstancesOptions extends BaseEC2RequestOptions { return options.inPlacementGroup(placementGroup); } - /** - * @see RunInstancesOptions#withAdditionalInfo(String) - */ - public static RunInstancesOptions withAdditionalInfo(String additionalInfo) { - RunInstancesOptions options = new RunInstancesOptions(); - return options.withAdditionalInfo(additionalInfo); - } - /** * @see RunInstancesOptions#withUserData(byte []) */ diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index 4affe571f8..cbbdff1f49 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -89,66 +89,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( systemGeneratedKeyPairName); expect(strategy.getSecurityGroupsForTagAndOptions(region, tag, options)).andReturn(generatedGroups); - expect(strategy.getProvider()).andReturn("ec2"); - expect(options.getSubnetId()).andReturn(null); - expect(options.getUserData()).andReturn(null); - - // replay mocks - replay(options); - replay(template); - replay(strategy); - - // run - RunInstancesOptions runOptions = strategy.execute(region, tag, template); - assertEquals(runOptions.buildQueryParameters(), ImmutableMultimap. of()); - assertEquals( - runOptions.buildFormParameters().entries(), - ImmutableMultimap. of("InstanceType", size.getProviderId(), "AdditionalInfo", tag, - "SecurityGroup.1", generatedGroup, "KeyName", systemGeneratedKeyPairName).entries()); - assertEquals(runOptions.buildMatrixParameters(), ImmutableMultimap. of()); - assertEquals(runOptions.buildRequestHeaders(), ImmutableMultimap. of()); - assertEquals(runOptions.buildStringPayload(), null); - - // verify mocks - verify(options); - verify(template); - verify(strategy); - } - - public void testEucalyptusDoesNotUseAdditionalInfo() throws SecurityException, NoSuchMethodException { - // setup constants - String region = Region.AP_SOUTHEAST_1; - String tag = "tag"; - Hardware size = EC2HardwareBuilder.m1_small().build(); - String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; - String generatedGroup = "group"; - Set generatedGroups = ImmutableSet.of(generatedGroup); - - // create mocks - CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions strategy = createMock( - CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class, - new Method[] { - CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class - .getDeclaredMethod("getProvider"), - CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class.getDeclaredMethod( - "createNewKeyPairUnlessUserSpecifiedOtherwise", String.class, String.class, - TemplateOptions.class), - CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class.getDeclaredMethod( - "createNewPlacementGroupUnlessUserSpecifiedOtherwise", String.class, String.class, - TemplateOptions.class), - CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class.getDeclaredMethod( - "getSecurityGroupsForTagAndOptions", String.class, String.class, TemplateOptions.class) }); - - EC2TemplateOptions options = createMock(EC2TemplateOptions.class); - Template template = createMock(Template.class); - - // setup expectations - expect(template.getHardware()).andReturn(size).atLeastOnce(); - expect(template.getOptions()).andReturn(options).atLeastOnce(); - expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( - systemGeneratedKeyPairName); - expect(strategy.getSecurityGroupsForTagAndOptions(region, tag, options)).andReturn(generatedGroups); - expect(strategy.getProvider()).andReturn("eucalyptus"); expect(options.getSubnetId()).andReturn(null); expect(options.getUserData()).andReturn(null); @@ -220,9 +160,9 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT assertEquals(runOptions.buildQueryParameters(), ImmutableMultimap. of()); assertEquals( runOptions.buildFormParameters().entries(), - ImmutableMultimap. of("InstanceType", size.getProviderId(), "AdditionalInfo", tag, - "SecurityGroup.1", generatedGroup, "KeyName", systemGeneratedKeyPairName, "Placement.GroupName", - generatedGroup).entries()); + ImmutableMultimap. of("InstanceType", size.getProviderId(), "SecurityGroup.1", + generatedGroup, "KeyName", systemGeneratedKeyPairName, "Placement.GroupName", generatedGroup) + .entries()); assertEquals(runOptions.buildMatrixParameters(), ImmutableMultimap. of()); assertEquals(runOptions.buildRequestHeaders(), ImmutableMultimap. of()); assertEquals(runOptions.buildStringPayload(), null); @@ -279,9 +219,9 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT assertEquals(runOptions.buildQueryParameters(), ImmutableMultimap. of()); assertEquals( runOptions.buildFormParameters().entries(), - ImmutableMultimap. of("InstanceType", size.getProviderId(), "AdditionalInfo", tag, - "SecurityGroup.1", generatedGroup, "KeyName", systemGeneratedKeyPairName, "Placement.GroupName", - generatedGroup).entries()); + ImmutableMultimap. of("InstanceType", size.getProviderId(), "SecurityGroup.1", + generatedGroup, "KeyName", systemGeneratedKeyPairName, "Placement.GroupName", generatedGroup) + .entries()); assertEquals(runOptions.buildMatrixParameters(), ImmutableMultimap. of()); assertEquals(runOptions.buildRequestHeaders(), ImmutableMultimap. of()); assertEquals(runOptions.buildStringPayload(), null); @@ -333,8 +273,8 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT assertEquals(runOptions.buildQueryParameters(), ImmutableMultimap. of()); assertEquals( runOptions.buildFormParameters().entries(), - ImmutableMultimap. of("InstanceType", size.getProviderId(), "AdditionalInfo", tag, - "SubnetId", "1", "KeyName", systemGeneratedKeyPairName).entries()); + ImmutableMultimap. of("InstanceType", size.getProviderId(), "SubnetId", "1", "KeyName", + systemGeneratedKeyPairName).entries()); assertEquals(runOptions.buildMatrixParameters(), ImmutableMultimap. of()); assertEquals(runOptions.buildRequestHeaders(), ImmutableMultimap. of()); assertEquals(runOptions.buildStringPayload(), null); @@ -389,9 +329,8 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT assertEquals(runOptions.buildQueryParameters(), ImmutableMultimap. of()); assertEquals( runOptions.buildFormParameters().entries(), - ImmutableMultimap. of("InstanceType", size.getProviderId(), "AdditionalInfo", tag, - "SecurityGroup.1", "group", "KeyName", systemGeneratedKeyPairName, "UserData", - Base64.encodeBytes("hello".getBytes())).entries()); + ImmutableMultimap. of("InstanceType", size.getProviderId(), "SecurityGroup.1", "group", + "KeyName", systemGeneratedKeyPairName, "UserData", Base64.encodeBytes("hello".getBytes())).entries()); assertEquals(runOptions.buildMatrixParameters(), ImmutableMultimap. of()); assertEquals(runOptions.buildRequestHeaders(), ImmutableMultimap. of()); assertEquals(runOptions.buildStringPayload(), null); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/options/RunInstancesOptionsTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/options/RunInstancesOptionsTest.java index fa51852597..f29be3c5b5 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/options/RunInstancesOptionsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/options/RunInstancesOptionsTest.java @@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.options; import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.asType; import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.enableMonitoring; -import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.withAdditionalInfo; import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.withDeviceName; import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.withKernelId; import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.withKeyName; @@ -99,30 +98,12 @@ public class RunInstancesOptionsTest { withSecurityGroup(null); } - @Test - public void testWithAdditionalInfo() { - RunInstancesOptions options = new RunInstancesOptions(); - options.withAdditionalInfo("test"); - assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections.singletonList("test")); - } - @Test public void testNullWithAdditionalInfo() { RunInstancesOptions options = new RunInstancesOptions(); assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections.EMPTY_LIST); } - @Test - public void testWithAdditionalInfoStatic() { - RunInstancesOptions options = withAdditionalInfo("test"); - assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections.singletonList("test")); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testWithAdditionalInfoNPE() { - withAdditionalInfo(null); - } - @Test public void testWithUserData() { RunInstancesOptions options = new RunInstancesOptions(); diff --git a/sandbox/deltacloud/pom.xml b/sandbox/deltacloud/pom.xml index 9d81257d0b..d66b991628 100644 --- a/sandbox/deltacloud/pom.xml +++ b/sandbox/deltacloud/pom.xml @@ -55,8 +55,8 @@ trmkrun-ccc,test.trmk-924 http://localhost:3001/api 1.0 - FIXME - FIXME + mockuser + mockpassword diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java index 76e386b796..86dac7b9e8 100644 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java @@ -21,6 +21,7 @@ package org.jclouds.deltacloud; import java.net.URI; import java.util.Map; +import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; @@ -29,12 +30,22 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; +import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.collections.Images; +import org.jclouds.deltacloud.collections.Instances; +import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.options.CreateInstanceOptions; -import org.jclouds.deltacloud.reference.DeltacloudCollection; +import org.jclouds.deltacloud.xml.ImageHandler; +import org.jclouds.deltacloud.xml.ImagesHandler; import org.jclouds.deltacloud.xml.LinksHandler; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -58,12 +69,31 @@ public interface DeltacloudAsyncClient { @XMLResponseParser(LinksHandler.class) ListenableFuture> getCollections(); + /** + * @see DeltacloudClient#listImages + */ + @GET + @Endpoint(Images.class) + @Path("") + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + @XMLResponseParser(ImagesHandler.class) + ListenableFuture> listImages(); + + /** + * @see DeltacloudClient#getImage + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("") + @XMLResponseParser(ImageHandler.class) + ListenableFuture getImage(@EndpointParam URI imageHref); + /** * @see DeltacloudClient#createInstance */ @POST + @Endpoint(Instances.class) @Path("") - ListenableFuture createInstance(URI instanceCollection, @FormParam("image_id") String imageId, - CreateInstanceOptions... options); + ListenableFuture createInstance(@FormParam("image_id") String imageId, CreateInstanceOptions... options); } diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java index 0427eea923..a993777a56 100644 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java @@ -21,11 +21,13 @@ package org.jclouds.deltacloud; import java.net.URI; import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.options.CreateInstanceOptions; -import org.jclouds.deltacloud.reference.DeltacloudCollection; /** * Provides synchronous access to deltacloud. @@ -45,6 +47,20 @@ public interface DeltacloudClient { */ Map getCollections(); + /** + * The images collection will return a set of all images available to the current user. + * + * @return images viewable to the user or empty set + */ + Set listImages(); + + /** + * + * @param imageHref + * @return image or null, if not found + */ + Image getImage(URI imageHref); + /** * Create a new Instance * @@ -54,13 +70,11 @@ public interface DeltacloudClient { * reasonable defaults. The architecture of the selected hardware profile must match the * architecture of the specified image. * - * @param instanceCollection - * which endpoint to create the instance in * @param imageId * The identifier (not URL) of the image from which to base the instance * @param options * includes realm, hardware profile, etc. * @return newly-created instance including a URL to retrieve the instance in the future. */ - String createInstance(URI instanceCollection, String imageId, CreateInstanceOptions... options); + String createInstance(String imageId, CreateInstanceOptions... options); } diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/reference/DeltacloudCollection.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/DeltacloudCollection.java similarity index 80% rename from sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/reference/DeltacloudCollection.java rename to sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/DeltacloudCollection.java index d0419bbddb..6767cd083d 100644 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/reference/DeltacloudCollection.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/DeltacloudCollection.java @@ -1,4 +1,4 @@ -package org.jclouds.deltacloud.reference; +package org.jclouds.deltacloud.collections; import static com.google.common.base.Preconditions.checkNotNull; @@ -9,7 +9,13 @@ import com.google.common.base.CaseFormat; * @author Adrian Cole */ public enum DeltacloudCollection { - HARDWARE_PROFILES, INSTANCE_STATES, REALMS, IMAGES, INSTANCES, UNRECOGNIZED; + HARDWARE_PROFILES, INSTANCE_STATES, REALMS, + + @Images + IMAGES, + + @Instances + INSTANCES, UNRECOGNIZED; public String value() { return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_UNDERSCORE, name())); diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/Images.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/Images.java new file mode 100644 index 0000000000..58442ec4c4 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/Images.java @@ -0,0 +1,40 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.collections; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * The images collection will return a set of all images available to the current user. + * + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface Images { + +} \ No newline at end of file diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/Instances.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/Instances.java new file mode 100644 index 0000000000..22268849c7 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/Instances.java @@ -0,0 +1,40 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.collections; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * The instances collection will return a set of all instances available to the current user. + * + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface Instances { + +} \ No newline at end of file diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java index b8c3b8b55d..0417749cfa 100644 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java @@ -19,16 +19,33 @@ package org.jclouds.deltacloud.config; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; + +import java.net.URI; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +import javax.inject.Named; +import javax.inject.Singleton; + import org.jclouds.deltacloud.DeltacloudAsyncClient; import org.jclouds.deltacloud.DeltacloudClient; +import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.collections.Images; +import org.jclouds.deltacloud.collections.Instances; import org.jclouds.deltacloud.handlers.DeltacloudErrorHandler; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.RequiresHttp; import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; +import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; + +import com.google.common.base.Supplier; +import com.google.inject.Provides; /** * Configures the deltacloud connection. @@ -43,7 +60,6 @@ public class DeltacloudRestClientModule extends RestClientModule authException = new AtomicReference(); + + @Provides + @Singleton + protected Supplier> provideCollections( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, + seconds, new Supplier>() { + @Override + public Map get() { + return client.getCollections(); + } + }); + } + + /** + * since the supplier is memoized, and there are no objects created here, this doesn't need to be + * singleton. + */ + @Provides + @Images + protected URI provideImageCollection(Supplier> collectionSupplier) { + return collectionSupplier.get().get(DeltacloudCollection.IMAGES); + } + + /** + * since the supplier is memoized, and there are no objects created here, this doesn't need to be + * singleton. + */ + @Provides + @Instances + protected URI provideInstanceCollection(Supplier> collectionSupplier) { + return collectionSupplier.get().get(DeltacloudCollection.INSTANCES); + } } diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Architecture.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Architecture.java new file mode 100644 index 0000000000..394ad105f2 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Architecture.java @@ -0,0 +1,29 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.domain; + +/** + * + * @author Adrian Cole + */ +public interface Architecture { + public static final String I386 = "i386"; + public static final String X86_64 = "x86_64"; +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Image.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Image.java new file mode 100644 index 0000000000..9d3e876594 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/Image.java @@ -0,0 +1,164 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import javax.annotation.Nullable; + +/** + * An image is a platonic form of a machine. Images are not directly executable, but are a template + * for creating actual instances of machines. + * + * @author Adrian Cole + */ +public class Image { + private final URI href; + private final String id; + private final String ownerId; + @Nullable + private final String name; + @Nullable + private final String description; + private final String architecture; + + public Image(URI href, String id, String ownerId, @Nullable String name, String description, String architecture) { + this.href = checkNotNull(href, "href"); + this.id = checkNotNull(id, "id"); + this.ownerId = checkNotNull(ownerId, "ownerId"); + this.name = name; + this.description = description; + this.architecture = checkNotNull(architecture, "architecture"); + } + + /** + * + * @return URL to manipulate a specific image + */ + public URI getHref() { + return href; + } + + /** + * + * @return A unique identifier for the image + */ + public String getId() { + return id; + } + + /** + * + * @return An opaque identifier which indicates the owner of an image + */ + public String getOwnerId() { + return ownerId; + } + + /** + * + * @return An optional short label describing the image + */ + @Nullable + public String getName() { + return name; + } + + /** + * + * @return An optional description describing the image more fully + */ + @Nullable + public String getDescription() { + return description; + } + + /** + * + * @return A description of the machine architecture of the image which may contain values such + * as: i386, x86_64 + */ + public String getArchitecture() { + return architecture; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((architecture == null) ? 0 : architecture.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((href == null) ? 0 : href.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Image other = (Image) obj; + if (architecture == null) { + if (other.architecture != null) + return false; + } else if (!architecture.equals(other.architecture)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (href == null) { + if (other.href != null) + return false; + } else if (!href.equals(other.href)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (ownerId == null) { + if (other.ownerId != null) + return false; + } else if (!ownerId.equals(other.ownerId)) + return false; + return true; + } + + @Override + public String toString() { + return "[href=" + href + ", id=" + id + ", ownerId=" + ownerId + ", name=" + name + ", description=" + + description + ", architecture=" + architecture + "]"; + } +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/ImageHandler.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/ImageHandler.java new file mode 100644 index 0000000000..6b3a131a36 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/ImageHandler.java @@ -0,0 +1,87 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.xml; + +import java.net.URI; +import java.util.Map; + +import org.jclouds.deltacloud.domain.Image; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.util.Utils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class ImageHandler extends ParseSax.HandlerWithResult { + private StringBuilder currentText = new StringBuilder(); + + private URI href; + private String id; + private String ownerId; + private String name; + private String description; + private String architecture; + + private Image image; + + public Image getResult() { + return image; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = Utils.cleanseAttributes(attrs); + if (qName.equals("image")) { + String href = attributes.get("href"); + if (href != null) { + this.href = URI.create(href); + } + this.id = attributes.get("id"); + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (qName.equalsIgnoreCase("owner_id")) { + this.ownerId = currentText.toString().trim(); + } else if (qName.equalsIgnoreCase("name")) { + this.name = currentText.toString().trim(); + } else if (qName.equalsIgnoreCase("description")) { + this.description = currentText.toString().trim(); + } else if (qName.equalsIgnoreCase("architecture")) { + this.architecture = currentText.toString().trim(); + } else if (qName.equalsIgnoreCase("image")) { + this.image = new Image(href, id, ownerId, name, description, architecture); + this.href = null; + this.id = null; + this.ownerId = null; + this.name = null; + this.description = null; + this.architecture = null; + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/ImagesHandler.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/ImagesHandler.java new file mode 100644 index 0000000000..96a40de254 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/ImagesHandler.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.xml; + +import java.util.Set; + +import javax.inject.Inject; + +import org.jclouds.deltacloud.domain.Image; +import org.jclouds.http.functions.ParseSax; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class ImagesHandler extends ParseSax.HandlerWithResult> { + private StringBuilder currentText = new StringBuilder(); + + private Set images = Sets.newLinkedHashSet(); + private final ImageHandler imageHandler; + + @Inject + public ImagesHandler(ImageHandler locationHandler) { + this.imageHandler = locationHandler; + } + + public Set getResult() { + return images; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + imageHandler.startElement(uri, localName, qName, attributes); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + imageHandler.endElement(uri, localName, qName); + if (qName.equals("image") && currentText.toString().trim().equals("")) { + this.images.add(imageHandler.getResult()); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + imageHandler.characters(ch, start, length); + currentText.append(ch, start, length); + } +} diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java index f91eab99be..e8fdf61c8f 100755 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java @@ -22,7 +22,7 @@ package org.jclouds.deltacloud.xml; import java.net.URI; import java.util.Map; -import org.jclouds.deltacloud.reference.DeltacloudCollection; +import org.jclouds.deltacloud.collections.DeltacloudCollection; import org.jclouds.http.functions.ParseSax; import org.jclouds.util.Utils; import org.xml.sax.Attributes; diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java index 6248900ff3..4455b7497b 100644 --- a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java @@ -24,22 +24,34 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; +import java.util.Map; import java.util.Properties; +import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.config.DeltacloudRestClientModule; import org.jclouds.deltacloud.options.CreateInstanceOptions; +import org.jclouds.deltacloud.xml.ImageHandler; +import org.jclouds.deltacloud.xml.ImagesHandler; import org.jclouds.deltacloud.xml.LinksHandler; import org.jclouds.http.HttpRequest; +import org.jclouds.http.RequiresHttp; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReturnStringIf2xx; +import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; +import com.google.inject.Module; import com.google.inject.TypeLiteral; /** @@ -75,13 +87,42 @@ public class DeltacloudAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - URI.create("http://localhost:3001/api/instances"), "imageId-1"); + public void testListImages() throws IOException, SecurityException, NoSuchMethodException { + Method method = DeltacloudAsyncClient.class.getMethod("listImages"); + HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api HTTP/1.1"); + assertRequestLineEquals(request, "GET http://localhost:3001/api/images HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, ImagesHandler.class); + assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetImage() throws IOException, SecurityException, NoSuchMethodException { + Method method = DeltacloudAsyncClient.class.getMethod("getImage", URI.class); + HttpRequest request = processor.createRequest(method, URI.create("https://delta/image1")); + + assertRequestLineEquals(request, "GET https://delta/image1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, ImageHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateInstance() throws SecurityException, NoSuchMethodException, IOException { + Method method = DeltacloudAsyncClient.class.getMethod("createInstance", String.class, + CreateInstanceOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "imageId-1"); + + assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api/instances HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n"); assertPayloadEquals(httpRequest, "image_id=imageId-1", "application/x-www-form-urlencoded", false); @@ -94,12 +135,12 @@ public class DeltacloudAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - URI.create("http://localhost:3001/api/instances"), "imageId-1", CreateInstanceOptions.Builder.named("foo")); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "imageId-1", + CreateInstanceOptions.Builder.named("foo")); - assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api HTTP/1.1"); + assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api/instances HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n"); assertPayloadEquals(httpRequest, "image_id=imageId-1&name=foo", "application/x-www-form-urlencoded", false); @@ -123,6 +164,32 @@ public class DeltacloudAsyncClientTest extends RestClientTest> provideCollections(long seconds, DeltacloudClient client) { + return Suppliers.ofInstance(null); + } + + @Override + protected URI provideImageCollection(Supplier> collectionSupplier) { + return URI.create("http://localhost:3001/api/images"); + } + + @Override + protected URI provideInstanceCollection(Supplier> collectionSupplier) { + return URI.create("http://localhost:3001/api/instances"); + } + + } + @Override public RestContextSpec createContextSpec() { Properties props = new Properties(); diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java index 038e91e5a1..72e471db83 100644 --- a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java @@ -20,14 +20,18 @@ package org.jclouds.deltacloud; import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.Map; import java.util.Properties; +import java.util.Set; import org.jclouds.Constants; -import org.jclouds.deltacloud.reference.DeltacloudCollection; +import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.domain.Image; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; @@ -100,6 +104,17 @@ public class DeltacloudClientLiveTest { assert (links.get(link) != null) : link; } + public void testListAndGetImages() throws Exception { + Set response = client.listImages(); + assert null != response; + long imageCount = response.size(); + assertTrue(imageCount >= 0); + for (Image image : response) { + Image newDetails = client.getImage(image.getHref()); + assertEquals(image, newDetails); + } + } + @Test public void testCreateInstance() throws Exception { // TODO diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/LinksHandlerTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/LinksHandlerTest.java index 877b6c2056..ebe6705ecc 100644 --- a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/LinksHandlerTest.java +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/LinksHandlerTest.java @@ -25,7 +25,7 @@ import java.io.InputStream; import java.net.URI; import java.util.Map; -import org.jclouds.deltacloud.reference.DeltacloudCollection; +import org.jclouds.deltacloud.collections.DeltacloudCollection; import org.jclouds.deltacloud.xml.LinksHandler; import org.jclouds.http.functions.BaseHandlerTest; import org.testng.annotations.Test; diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImageHandlerTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImageHandlerTest.java new file mode 100644 index 0000000000..4c6cdbfb44 --- /dev/null +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImageHandlerTest.java @@ -0,0 +1,65 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.deltacloud.domain.Image; +import org.jclouds.deltacloud.xml.ImageHandler; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.config.SaxParserModule; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code ImageHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ImageHandlerTest { + + static ParseSax createParser() { + Injector injector = Guice.createInjector(new SaxParserModule()); + ParseSax parser = (ParseSax) injector.getInstance(ParseSax.Factory.class).create( + injector.getInstance(ImageHandler.class)); + return parser; + } + + public static Image parseImage() { + return parseImage("/test_get_image.xml"); + } + + public static Image parseImage(String resource) { + InputStream is = ImageHandlerTest.class.getResourceAsStream(resource); + return createParser().parse(is); + } + + public void test() { + Image expects = new Image(URI.create("http://fancycloudprovider.com/api/images/img1"), "img1", "fedoraproject", + "Fedora 10", "Fedora 10", "x86_64"); + assertEquals(parseImage(), expects); + } +} diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImagesHandlerTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImagesHandlerTest.java new file mode 100644 index 0000000000..e5b080bb77 --- /dev/null +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImagesHandlerTest.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.deltacloud.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.util.Set; + +import org.jclouds.deltacloud.domain.Image; +import org.jclouds.deltacloud.xml.ImagesHandler; +import org.jclouds.http.functions.BaseHandlerTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code ImagesHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ImagesHandlerTest extends BaseHandlerTest { + + @Test + public void test() { + InputStream is = getClass().getResourceAsStream("/test_list_images.xml"); + Set expects = ImmutableSet.of( + + new Image(URI.create("http://fancycloudprovider.com/api/images/img1"), "img1", "fedoraproject", "Fedora 10", + "Fedora 10", "x86_64"), new Image(URI.create("http://fancycloudprovider.com/api/images/img2"), "img2", + "fedoraproject", "Fedora 10", "Fedora 10", "i386"), + new Image(URI.create("http://fancycloudprovider.com/api/images/img3"), "img3", "ted", "JBoss", "JBoss", + "i386")); + System.out.println(factory); + System.out.println(injector); + + // not sure why this isn't always automatically called from surefire. + setUpInjector(); + assertEquals(factory.create(injector.getInstance(ImagesHandler.class)).parse(is), expects); + } +} diff --git a/sandbox/deltacloud/src/test/resources/test_get_image.xml b/sandbox/deltacloud/src/test/resources/test_get_image.xml new file mode 100644 index 0000000000..9fd7f331a0 --- /dev/null +++ b/sandbox/deltacloud/src/test/resources/test_get_image.xml @@ -0,0 +1,7 @@ + + + fedoraproject + Fedora 10 + Fedora 10 + x86_64 + \ No newline at end of file diff --git a/sandbox/deltacloud/src/test/resources/test_list_images.xml b/sandbox/deltacloud/src/test/resources/test_list_images.xml new file mode 100644 index 0000000000..49c888d264 --- /dev/null +++ b/sandbox/deltacloud/src/test/resources/test_list_images.xml @@ -0,0 +1,20 @@ + + + fedoraproject + Fedora 10 + Fedora 10 + x86_64 + + + fedoraproject + Fedora 10 + Fedora 10 + i386 + + + ted + JBoss + JBoss + i386 + + \ No newline at end of file

+ * + * import static org.jclouds.cloudsigma.options.CloneDriveOptions.Builder.*; + * + * + * Payload payload = client.cloneDrive("drive-uuid","newName", size(2*1024*1024l)); + * + * + * @author Adrian Cole + * + */ +public class CloneDriveOptions { + private final Map options = Maps.newLinkedHashMap(); + + /** + * adjust to new size in bytes + */ + public CloneDriveOptions size(long size) { + checkArgument(size >= 0, "size must be >= 0"); + options.put("size", size + ""); + return this; + } + + public static class Builder { + + /** + * @see CloneDriveOptions#size + */ + public static CloneDriveOptions size(long size) { + CloneDriveOptions options = new CloneDriveOptions(); + return options.size(size); + } + + } + + public Map getOptions() { + return ImmutableMap.copyOf(options); + } +} diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java index 51039a819d..9eebec7f9c 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java @@ -26,22 +26,31 @@ import java.lang.reflect.Method; import java.util.Properties; import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; +import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo; import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; +import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; +import org.jclouds.cloudsigma.options.CloneDriveOptions; +import org.jclouds.elasticstack.binders.BindServerToPlainTextStringTest; import org.jclouds.elasticstack.domain.CreateDriveRequest; import org.jclouds.elasticstack.domain.Drive; import org.jclouds.elasticstack.domain.DriveData; +import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.functions.SplitNewlines; import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; import com.google.inject.TypeLiteral; /** @@ -131,7 +140,8 @@ public class CloudSigmaAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - new CreateDriveRequest.Builder().name("foo").tags(ImmutableList.of("production", "candy")).size(10000l).build()); + new CreateDriveRequest.Builder().name("foo").tags(ImmutableList.of("production", "candy")).size(10000l) + .build()); assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/create HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); @@ -145,6 +155,41 @@ public class CloudSigmaAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "sourceid", "newname"); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/sourceid/clone HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, "name newname", "text/plain", false); + + assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testCloneDriveOptions() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("cloneDrive", String.class, String.class, + CloneDriveOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "sourceid", "newname", + new CloneDriveOptions().size(1024l)); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/sourceid/clone HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, "name newname\nsize 1024", "text/plain", false); + + assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + public void testSetDriveData() throws SecurityException, NoSuchMethodException, IOException { Method method = CloudSigmaAsyncClient.class.getMethod("setDriveData", String.class, DriveData.class); GeneratedHttpRequest httpRequest = processor.createRequest(method, "100", @@ -152,16 +197,231 @@ public class CloudSigmaAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/list HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + // now make sure request filters apply by replaying + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + + assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/list HTTP/1.1"); + // for example, using basic authentication, we should get "only one" + // header + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n"); + assertPayloadEquals(httpRequest, null, null, false); + + // TODO: insert expected response class, which probably extends ParseJson + assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + + } + + public void testListServerInfo() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("listServerInfo"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/info HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + } + + public void testGetServerInfo() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("getServerInfo", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/uuid/info HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); + assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); checkFilters(httpRequest); } + public void testCreateServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("createServer", Server.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + BindServerToPlainTextStringTest.SERVER); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/create HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, BindServerToPlainTextStringTest.CREATED_SERVER, "text/plain", false); + + assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testSetServerConfiguration() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("setServerConfiguration", String.class, Server.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "100", + BindServerToPlainTextStringTest.SERVER); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/100/set HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, BindServerToPlainTextStringTest.CREATED_SERVER, "text/plain", false); + + assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testDestroyServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("destroyServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/destroy HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testStartServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("startServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/start HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testStopServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("stopServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/stop HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testShutdownServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("shutdownServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/shutdown HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testResetServer() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("resetServer", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/reset HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testListDrives() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("listDrives"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/list HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + // now make sure request filters apply by replaying + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + + assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/list HTTP/1.1"); + // for example, using basic authentication, we should get "only one" + // header + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n"); + assertPayloadEquals(httpRequest, null, null, false); + + // TODO: insert expected response class, which probably extends ParseJson + assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + + } + + public void testDestroyDrive() throws SecurityException, NoSuchMethodException, IOException { + Method method = CloudSigmaAsyncClient.class.getMethod("destroyDrive", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "uuid"); + + assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/uuid/destroy HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + @Override protected void checkFilters(HttpRequest request) { assertEquals(request.getFilters().size(), 1); diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java index d2ba081591..fd553233ca 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java @@ -26,9 +26,14 @@ import java.util.Set; import org.jclouds.cloudsigma.domain.DriveInfo; import org.jclouds.cloudsigma.domain.DriveType; +import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.elasticstack.CommonElasticStackClientLiveTest; +import org.jclouds.elasticstack.domain.ServerInfo; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + /** * Tests behavior of {@code CloudSigmaClient} * @@ -39,6 +44,8 @@ public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTest drives = client.listStandardImages(); assertNotNull(drives); } + @Override protected void checkDriveMatchesGet(org.jclouds.elasticstack.domain.DriveInfo newInfo) { super.checkDriveMatchesGet(newInfo); @@ -72,7 +80,17 @@ public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTest of()); + assertEquals(server2.getUserMetadata(), ImmutableMap. of()); } } diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java new file mode 100644 index 0000000000..8f9d0a5769 --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java @@ -0,0 +1,78 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.binders; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +import java.io.IOException; + +import org.jclouds.cloudsigma.options.CloneDriveOptions; +import org.jclouds.io.MutableContentMetadata; +import org.jclouds.io.Payload; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Guice; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class BindCloneDriveOptionsToPlainTextStringTest { + + private static final BindCloneDriveOptionsToPlainTextString binder = Guice.createInjector().getInstance( + BindCloneDriveOptionsToPlainTextString.class); + + public void testDefault() throws IOException { + assertInputAndArgsCreatesPayload(ImmutableMap.of("name", "newdrive"), new Object[] {}, "name newdrive"); + } + + public void testWithSize() throws IOException { + assertInputAndArgsCreatesPayload(ImmutableMap.of("name", "newdrive"), + new Object[] { new CloneDriveOptions().size(1024) }, "name newdrive\nsize 1024"); + } + + protected void assertInputAndArgsCreatesPayload(ImmutableMap inputMap, Object[] args, String expected) { + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getArgs()).andReturn(args).atLeastOnce(); + request.setPayload(expected); + Payload payload = createMock(Payload.class); + expect(request.getPayload()).andReturn(payload); + MutableContentMetadata md = createMock(MutableContentMetadata.class); + expect(payload.getContentMetadata()).andReturn(md); + md.setContentType("text/plain"); + + replay(request); + replay(payload); + replay(md); + + binder.bindToRequest(request, inputMap); + + verify(request); + verify(payload); + verify(md); + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java index aeff757ebf..2def4841fb 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java @@ -45,6 +45,6 @@ public class KeyValuesDelimitedByBlankLinesToDriveInfoTest { public void testOne() { assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class - .getResourceAsStream("/drive.txt")))), MapToDriveInfoTest.ONE); + .getResourceAsStream("/cloudsigma/drive.txt")))), MapToDriveInfoTest.ONE); } } diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java new file mode 100644 index 0000000000..6a8575b35d --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java @@ -0,0 +1,85 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import java.util.List; +import java.util.Map; + +import org.jclouds.elasticstack.domain.Device; +import org.jclouds.elasticstack.domain.DriveMetrics; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.ServerMetrics; +import org.jclouds.elasticstack.functions.MapToDevices; +import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; +import org.jclouds.elasticstack.functions.MapToDriveMetrics; +import org.jclouds.elasticstack.functions.MapToNICs; +import org.jclouds.elasticstack.functions.MapToServerMetrics; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class KeyValuesDelimitedByBlankLinesToServerInfoTest { + + private static final KeyValuesDelimitedByBlankLinesToServerInfo FN = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + bind(new TypeLiteral, List>>() { + }).to(MapToNICs.class); + bind(new TypeLiteral, Map>>() { + }).to(MapToDevices.class); + bind(new TypeLiteral, Map>>() { + }).to(MapToDriveMetrics.class); + bind(new TypeLiteral, ServerMetrics>>() { + }).to(MapToServerMetrics.class); + bind(new TypeLiteral>() { + }).to(DeviceToId.class); + } + + }).getInstance(KeyValuesDelimitedByBlankLinesToServerInfo.class); + + public void testNone() { + assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload(""))), null); + assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload("\n\n"))), null); + assertEquals(FN.apply(new HttpResponse(200, "", null)), null); + } + + public void testOne() { + assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToServerInfoTest.class + .getResourceAsStream("/servers.txt")))), MapToServerInfoTest.ONE); + } + + public void testNew() { + assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToServerInfoTest.class + .getResourceAsStream("/new_server.txt")))), MapToServerInfoTest.NEW); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java index 28e6f2ab3a..ed92403cc2 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest.java @@ -47,6 +47,6 @@ public class ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest { public void testOne() { assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class - .getResourceAsStream("/drive.txt")))), ImmutableSet. of(MapToDriveInfoTest.ONE)); + .getResourceAsStream("/cloudsigma/drive.txt")))), ImmutableSet. of(MapToDriveInfoTest.ONE)); } } diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java new file mode 100644 index 0000000000..2cf011cb15 --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java @@ -0,0 +1,85 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import java.util.List; +import java.util.Map; + +import org.jclouds.elasticstack.domain.Device; +import org.jclouds.elasticstack.domain.DriveMetrics; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.domain.ServerMetrics; +import org.jclouds.elasticstack.functions.MapToDevices; +import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; +import org.jclouds.elasticstack.functions.MapToDriveMetrics; +import org.jclouds.elasticstack.functions.MapToNICs; +import org.jclouds.elasticstack.functions.MapToServerMetrics; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest { + + private static final ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet FN = Guice.createInjector( + new AbstractModule() { + + @Override + protected void configure() { + bind(new TypeLiteral, List>>() { + }).to(MapToNICs.class); + bind(new TypeLiteral, Map>>() { + }).to(MapToDevices.class); + bind(new TypeLiteral, Map>>() { + }).to(MapToDriveMetrics.class); + bind(new TypeLiteral, ServerMetrics>>() { + }).to(MapToServerMetrics.class); + bind(new TypeLiteral>() { + }).to(DeviceToId.class); + } + + }).getInstance(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class); + + public void testNone() { + assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload(""))), ImmutableSet. of()); + assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload("\n\n"))), + ImmutableSet. of()); + assertEquals(FN.apply(new HttpResponse(200, "", null)), ImmutableSet. of()); + } + + public void testOne() { + assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToServerInfoTest.class + .getResourceAsStream("/servers.txt")))), ImmutableSet. of(MapToServerInfoTest.ONE, + MapToServerInfoTest.TWO)); + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java index e630bf4572..39ef3bdf2e 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToDriveInfoTest.java @@ -90,7 +90,7 @@ public class MapToDriveInfoTest { public void testComplete() throws IOException { Map input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( - Utils.toStringAndClose(MapToDriveInfoTest.class.getResourceAsStream("/drive.txt"))).get(0); + Utils.toStringAndClose(MapToDriveInfoTest.class.getResourceAsStream("/cloudsigma/drive.txt"))).get(0); assertEquals(MAP_TO_DRIVE.apply(input), ONE); diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java new file mode 100644 index 0000000000..e9fc095742 --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/MapToServerInfoTest.java @@ -0,0 +1,167 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.Date; +import java.util.Map; + +import org.jclouds.elasticstack.domain.DriveMetrics; +import org.jclouds.elasticstack.domain.IDEDevice; +import org.jclouds.elasticstack.domain.MediaType; +import org.jclouds.elasticstack.domain.Model; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.domain.ServerMetrics; +import org.jclouds.elasticstack.domain.ServerStatus; +import org.jclouds.elasticstack.domain.VNC; +import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps; +import org.jclouds.elasticstack.functions.MapToDevices; +import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; +import org.jclouds.elasticstack.functions.MapToDriveMetrics; +import org.jclouds.elasticstack.functions.MapToNICs; +import org.jclouds.elasticstack.functions.MapToServerMetrics; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class MapToServerInfoTest { + public static ServerInfo ONE = new ServerInfo.Builder() + .persistent(true) + .uuid("f8bee9cd-8e4b-4a05-8593-1314e3bfe49b") + .cpu(2000) + .bootDeviceIds(ImmutableSet.of("ide:0:0")) + .smp(1) + .mem(1024) + .status(ServerStatus.ACTIVE) + .started(new Date(1291493868l)) + .user("2f6244eb-50bc-4403-847e-f03cc3706a1f") + .name("jo") + .vnc(new VNC("46.20.114.124", "HfHzVmLT", false)) + .nics(ImmutableSet.of(new NIC.Builder() + .model(Model.E1000) + .dhcp("46.20.114.124") + .block( + ImmutableList.of("tcp/43594", "tcp/5902", "udp/5060", "tcp/5900", "tcp/5901", "tcp/21", "tcp/22", + "tcp/23", "tcp/25", "tcp/110", "tcp/143", "tcp/43595")).build())) + .devices( + ImmutableMap.of("ide:0:0", + new IDEDevice.Builder((int) 0, (int) 0).uuid("4af85ed3-0caa-4736-8a26-a33d7de0a122").build() + + )) + .metrics( + new ServerMetrics.Builder() + .tx(2550) + .txPackets(31) + .rx(455530) + .rxPackets(7583) + .driveMetrics( + ImmutableMap.of("ide:0:0", new DriveMetrics.Builder().readRequests(11154) + .readBytes(45686784).writeRequests(3698).writeBytes(15147008).build())).build()) + .build(); + + public static ServerInfo TWO = new ServerInfo.Builder() + .status(ServerStatus.STOPPED) + .name("Demo") + .mem(1024) + .cpu(2000) + .persistent(true) + .uuid("0f962616-2071-4173-be79-7dd084271edf") + .bootDeviceIds(ImmutableSet.of("ide:0:0")) + .user("2f6244eb-50bc-4403-847e-f03cc3706a1f") + .vnc(new VNC("auto", "HWbjvrg2", false)) + .nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp("auto").build())) + .devices( + ImmutableMap.of( + "ide:0:0", + new IDEDevice.Builder((int) 0, (int) 0).uuid("853bb98a-4fff-4c2f-a265-97c363f19ea5") + .mediaType(MediaType.CDROM).build())) + .metrics( + new ServerMetrics.Builder().driveMetrics(ImmutableMap.of("ide:0:0", new DriveMetrics.Builder().build())) + .build()).build(); + + private static final MapToServerInfo MAP_TO_DRIVE = new MapToServerInfo(new MapToDevices(new DeviceToId()), + new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs()); + + public void testEmptyMapReturnsNull() { + assertEquals(MAP_TO_DRIVE.apply(ImmutableMap. of()), null); + } + + public void testBasics() { + ServerInfo expects = new ServerInfo.Builder().name("foo").uuid("hello").vnc(new VNC("auto", null, false)) + .cpu(1000).mem(2048).metrics(new ServerMetrics.Builder().build()).build(); + assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.of("name", "foo", "server", "hello", "vnc:ip", "auto", "cpu", + "1000", "mem", "2048")), expects); + } + + public void testComplete() throws IOException { + + Map input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( + Utils.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/servers.txt"))).get(0); + + assertEquals(MAP_TO_DRIVE.apply(input), ONE); + + } + + public static ServerInfo NEW = new ServerInfo.Builder() + .persistent(true) + .uuid("bd98615a-6f74-4d63-ad1e-b13338b9356a") + .cpu(1000) + .bootDeviceIds(ImmutableSet.of("ide:0:0")) + .smp(1) + .mem(512) + .status(ServerStatus.ACTIVE) + .started(new Date(1292695612)) + .user("2f6244eb-50bc-4403-847e-f03cc3706a1f") + .name("adriancole.test") + .vnc(new VNC("83.222.249.221", "XXXXXXXX", false)) + .nics(ImmutableSet.of(new NIC.Builder() + .model(Model.E1000) + .block( + ImmutableList.of("tcp/43594", "tcp/5902", "udp/5060", "tcp/5900", "tcp/5901", "tcp/21", "tcp/22", + "tcp/23", "tcp/25", "tcp/110", "tcp/143", "tcp/43595")).build())) + .devices( + ImmutableMap.of("ide:0:0", + new IDEDevice.Builder((int) 0, (int) 0).uuid("403c9a86-0aab-4e47-aa95-e9768021c4c1").build() + + )) + .metrics( + new ServerMetrics.Builder().driveMetrics(ImmutableMap.of("ide:0:0", new DriveMetrics.Builder().build())) + .build()).build(); + + public void testNew() throws IOException { + + Map input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( + Utils.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/new_server.txt"))).get(0); + + assertEquals(MAP_TO_DRIVE.apply(input), NEW); + + } +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java new file mode 100644 index 0000000000..744f6aafb8 --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ServerToMapTest.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.functions; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.elasticstack.domain.IDEDevice; +import org.jclouds.elasticstack.domain.Model; +import org.jclouds.elasticstack.domain.NIC; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.VNC; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }) +public class ServerToMapTest { + + private static final ServerToMap SERVER_TO_MAP = new ServerToMap(); + + public void testBasics() { + assertEquals( + SERVER_TO_MAP.apply(new Server.Builder() + .name("TestServer") + .cpu(2000) + .mem(1024) + .devices( + ImmutableMap.of("ide:0:0", + new IDEDevice.Builder(0, 0).uuid("08c92dd5-70a0-4f51-83d2-835919d254df").build())) + .bootDeviceIds(ImmutableSet.of("ide:0:0")).nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000). + + build())).vnc(new VNC(null, "XXXXXXXX", false)).build()), + ImmutableMap + .builder() + .putAll(ImmutableMap.of("name", "TestServer", "cpu", "2000", "smp", "auto", "mem", "1024")) + .putAll( + ImmutableMap.of("persistent", "false", "boot", "ide:0:0", "ide:0:0", + "08c92dd5-70a0-4f51-83d2-835919d254df")) + .putAll( + ImmutableMap.of("ide:0:0:media", "disk", "nic:0:model", "e1000", "vnc:ip", "auto", + "vnc:password", "XXXXXXXX")).build()); + } + +} \ No newline at end of file diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java new file mode 100644 index 0000000000..960cb766fb --- /dev/null +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/options/CloneDriveOptionsTest.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudsigma.options; + +import static org.jclouds.cloudsigma.options.CloneDriveOptions.Builder.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import org.testng.annotations.Test; + +/** + * Tests possible uses of CloneDriveOptions and CloneDriveOptions.Builder.* + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class CloneDriveOptionsTest { + + @Test + public void testNullSize() { + CloneDriveOptions options = new CloneDriveOptions(); + assertNull(options.getOptions().get("size")); + } + + @Test + public void testSize() { + CloneDriveOptions options = new CloneDriveOptions().size(1024); + assertEquals(options.getOptions().get("size"), "1024"); + } + + @Test + public void testSizeStatic() { + CloneDriveOptions options = size(1024); + assertEquals(options.getOptions().get("size"), "1024"); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeNegative() { + size(-1); + } + +} diff --git a/sandbox/cloudsigma/src/test/resources/drive.txt b/sandbox/cloudsigma/src/test/resources/cloudsigma/drive.txt similarity index 97% rename from sandbox/cloudsigma/src/test/resources/drive.txt rename to sandbox/cloudsigma/src/test/resources/cloudsigma/drive.txt index 04372bb776..63abfc8f14 100644 --- a/sandbox/cloudsigma/src/test/resources/drive.txt +++ b/sandbox/cloudsigma/src/test/resources/cloudsigma/drive.txt @@ -1,5 +1,5 @@ status active -use networking,security,gateway +use networking security gateway name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System bits 64 url http://www.ubuntu.com diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackAsyncClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackAsyncClient.java index 2ef61f6e9e..43ddd019cc 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackAsyncClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackAsyncClient.java @@ -88,16 +88,6 @@ public interface CommonElasticStackAsyncClient { @Path("/servers/{uuid}/info") ListenableFuture getServerInfo(@PathParam("uuid") String uuid); - /** - * @see ElasticStackClient#createAndStartServer - */ - @POST - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) - @Path("/servers/create") - ListenableFuture createAndStartServer( - @BinderParam(BindServerToPlainTextString.class) Server createServer); - /** * @see ElasticStackClient#createServer */ @@ -109,7 +99,7 @@ public interface CommonElasticStackAsyncClient { @BinderParam(BindServerToPlainTextString.class) Server createServer); /** - * @see ElasticStackClient#setServer + * @see ElasticStackClient#setServerConfiguration */ @POST @ExceptionParser(ReturnNullOnNotFoundOr404.class) diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java index 5839248f6b..78632ca642 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java @@ -68,14 +68,6 @@ public interface CommonElasticStackClient { */ ServerInfo createServer(Server server); - /** - * create and start a new server - * - * @param server - * @return newly created server - */ - ServerInfo createAndStartServer(Server server); - /** * set server configuration * diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java index cea0b3c52f..30423756a1 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackAsyncClient.java @@ -26,10 +26,15 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.jclouds.elasticstack.binders.BindServerToPlainTextString; import org.jclouds.elasticstack.domain.ImageConversionType; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToServerInfo; import org.jclouds.elasticstack.functions.ReturnPayload; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.io.Payload; +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; @@ -50,6 +55,16 @@ import com.google.common.util.concurrent.ListenableFuture; @Consumes(MediaType.TEXT_PLAIN) public interface ElasticStackAsyncClient extends CommonElasticStackAsyncClient { + /** + * @see ElasticStackClient#createAndStartServer + */ + @POST + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class) + @Path("/servers/create") + ListenableFuture createAndStartServer( + @BinderParam(BindServerToPlainTextString.class) Server createServer); + /** * @see ElasticStackClient#imageDrive(String,String) */ diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java index 129ac4a94f..7fb5631415 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackClient.java @@ -23,6 +23,8 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.elasticstack.domain.ImageConversionType; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.ServerInfo; import org.jclouds.io.Payload; /** @@ -36,6 +38,14 @@ import org.jclouds.io.Payload; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface ElasticStackClient extends CommonElasticStackClient { + /** + * create and start a new server + * + * @param server + * @return newly created server + */ + ServerInfo createAndStartServer(Server server); + /** * Image a drive from another drive. The actual imaging process is asynchronous, with progress * reported via drive info. diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java index 6e88d05692..2ed5bf7f9e 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/config/ElasticStackRestClientModule.java @@ -83,8 +83,6 @@ public class ElasticStackRestClientModule extends RestClientModule>>() { }).to(ServerToMap.class); - bind(new TypeLiteral>>() { - }).to(ServerToMap.class); } @Override diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/NIC.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/NIC.java index c553edd6de..371977f9db 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/NIC.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/NIC.java @@ -37,6 +37,7 @@ public class NIC { private Model model; private String vlan; private String mac; + // TODO elasticstack specific private Set block = ImmutableSet.of(); public Builder dhcp(String dhcp) { diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java index 018909bee1..ceda1d3e51 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java @@ -46,7 +46,7 @@ public class Server extends Item { protected Set bootDeviceIds = ImmutableSet.of(); protected List nics = ImmutableList.of(); protected VNC vnc; - // TODO undocumented + // TODO cloudsigma specific protected String description; public Builder cpu(int cpu) { diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java index 7a08fd4f3f..3906f67088 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java @@ -36,7 +36,6 @@ import org.jclouds.elasticstack.domain.DriveInfo; import org.jclouds.elasticstack.domain.DriveStatus; import org.jclouds.elasticstack.domain.IDEDevice; import org.jclouds.elasticstack.domain.Model; -import org.jclouds.elasticstack.domain.NIC; import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerInfo; import org.jclouds.elasticstack.domain.ServerStatus; @@ -54,7 +53,6 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; @@ -68,7 +66,9 @@ import com.google.inject.Module; @Test(groups = "live", sequential = true) public abstract class CommonElasticStackClientLiveTest { - protected static final String VNC_PASSWORD = "XXXXXXXX"; + protected long driveSize = 1 * 1024 * 1024 * 1024l; + protected int maxDriveImageTime = 120; + protected String vncPassword = "Il0veVNC"; protected S client; protected RestContext context; protected Predicate socketTester; @@ -109,9 +109,10 @@ public abstract class CommonElasticStackClientLiveTest(Predicates.not(new DriveClaimed(client)), 120, 1, + driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, + 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, TimeUnit.SECONDS); - socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 120, 1, TimeUnit.SECONDS); } @Test @@ -159,7 +160,7 @@ public abstract class CommonElasticStackClientLiveTest Date: Sun, 19 Dec 2010 17:05:11 +0100 Subject: [PATCH 15/33] Issue 412, 419: ssh test --- sandbox/cloudsigma/pom.xml | 6 +++++ .../cloudsigma/CloudSigmaClientLiveTest.java | 7 ++++++ sandbox/elasticstack/pom.xml | 6 +++++ .../CommonElasticStackClientLiveTest.java | 22 +++++++++++++++++++ .../ElasticStackClientLiveTest.java | 8 +++++++ 5 files changed, 49 insertions(+) diff --git a/sandbox/cloudsigma/pom.xml b/sandbox/cloudsigma/pom.xml index 0b6be3bd0d..70c6a0c0ad 100644 --- a/sandbox/cloudsigma/pom.xml +++ b/sandbox/cloudsigma/pom.xml @@ -64,6 +64,12 @@ jclouds-elasticstack ${project.version} + + ${project.groupId} + jclouds-jsch + ${project.version} + test + ${project.groupId} jclouds-core diff --git a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java index fd553233ca..e9399563d8 100644 --- a/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java +++ b/sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java @@ -27,7 +27,9 @@ import java.util.Set; import org.jclouds.cloudsigma.domain.DriveInfo; import org.jclouds.cloudsigma.domain.DriveType; import org.jclouds.cloudsigma.options.CloneDriveOptions; +import org.jclouds.domain.Credentials; import org.jclouds.elasticstack.CommonElasticStackClientLiveTest; +import org.jclouds.elasticstack.domain.Server; import org.jclouds.elasticstack.domain.ServerInfo; import org.testng.annotations.Test; @@ -78,6 +80,11 @@ public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTestjclouds-core ${project.version} + + ${project.groupId} + jclouds-jsch + ${project.version} + test + ${project.groupId} jclouds-core diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java index 3906f67088..911a8e6fb1 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java @@ -23,12 +23,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import java.io.IOException; import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import org.jclouds.Constants; +import org.jclouds.domain.Credentials; import org.jclouds.elasticstack.domain.ClaimType; import org.jclouds.elasticstack.domain.CreateDriveRequest; import org.jclouds.elasticstack.domain.DriveData; @@ -47,6 +49,9 @@ import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; +import org.jclouds.ssh.ExecResponse; +import org.jclouds.ssh.SshClient; +import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -56,6 +61,7 @@ import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; +import com.google.inject.Guice; import com.google.inject.Module; /** @@ -251,6 +257,7 @@ public abstract class CommonElasticStackClientLiveTest Date: Sun, 19 Dec 2010 18:18:01 +0100 Subject: [PATCH 16/33] Issue 385: exposed way to access synch and asynch classes within skeleton compute provider --- .../src/main/clojure/org/jclouds/modules.clj | 4 +- .../compute/ComputeServiceAdapter.java | 2 +- ...> ComputeServiceAdapterContextModule.java} | 38 +++-- ...veComputeServiceAdapterContextModule.java} | 31 ++-- .../StubComputeServiceContextModule.java | 12 +- .../LibvirtComputeServiceContextModule.java | 136 +++++++++--------- .../config/ViComputeServiceContextModule.java | 19 ++- ...verManagerComputeServiceContextModule.java | 10 +- 8 files changed, 138 insertions(+), 114 deletions(-) rename compute/src/main/java/org/jclouds/compute/config/{StandaloneComputeServiceContextModule.java => ComputeServiceAdapterContextModule.java} (87%) rename compute/src/main/java/org/jclouds/compute/config/{JCloudsNativeStandaloneComputeServiceContextModule.java => JCloudsNativeComputeServiceAdapterContextModule.java} (68%) diff --git a/compute/src/main/clojure/org/jclouds/modules.clj b/compute/src/main/clojure/org/jclouds/modules.clj index a8d3ceda81..f49e6a9d5c 100644 --- a/compute/src/main/clojure/org/jclouds/modules.clj +++ b/compute/src/main/clojure/org/jclouds/modules.clj @@ -34,7 +34,9 @@ (defn compute-module [] - (org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule + (org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule + (class ComputeService) + (class ComputeService) (defrecord ClojureComputeServiceAdapter [] org.jclouds.compute.JCloudsNativeComputeServiceAdapter (^NodeMetadata runNodeWithTagAndNameAndStoreCredentials [this ^String tag ^String name ^Template template ^Map credentialStore] diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java index bf13254eaa..55ec6ad6b1 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java @@ -25,7 +25,7 @@ import org.jclouds.compute.domain.Template; import org.jclouds.domain.Credentials; /** - * A means of specifying the interface between the {@link ComputeServices} and a concrete compute + * A means of specifying the interface between the {@link ComputeService ComputeServices} and a concrete compute * cloud implementation, jclouds or otherwise. * * @author Adrian Cole diff --git a/compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/ComputeServiceAdapterContextModule.java similarity index 87% rename from compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java rename to compute/src/main/java/org/jclouds/compute/config/ComputeServiceAdapterContextModule.java index d9788657d5..160b147d84 100644 --- a/compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/ComputeServiceAdapterContextModule.java @@ -27,7 +27,6 @@ import java.util.Set; import javax.inject.Singleton; -import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.Hardware; @@ -49,20 +48,30 @@ import com.google.common.base.Supplier; import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; +import com.google.inject.util.Types; /** * * @author Adrian Cole */ -public class StandaloneComputeServiceContextModule extends BaseComputeServiceContextModule { +public class ComputeServiceAdapterContextModule extends BaseComputeServiceContextModule { + private Class asyncClientType; + private Class syncClientType; + + public ComputeServiceAdapterContextModule(Class syncClientType, Class asyncClientType) { + this.syncClientType = syncClientType; + this.asyncClientType = asyncClientType; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void configure() { super.configure(); bindDefaultLocation(); bind(new TypeLiteral() { - }).to(new TypeLiteral>() { - }).in(Scopes.SINGLETON); + }).to((TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class, syncClientType, + asyncClientType))).in(Scopes.SINGLETON); } public class TransformingSetSupplier implements Supplier> { @@ -84,7 +93,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideHardware(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -98,7 +107,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideImages(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -117,7 +126,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideLocations(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -169,19 +178,4 @@ public class StandaloneComputeServiceContextModule extends BaseCompu protected SuspendNodeStrategy defineStopNodeStrategy(AdaptingComputeServiceStrategies in) { return in; } - - // enum singleton pattern - public static enum IdentityFunction implements Function { - INSTANCE; - - public Object apply(Object o) { - return o; - } - - @Override - public String toString() { - return "identity"; - } - } - } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/config/JCloudsNativeStandaloneComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/JCloudsNativeComputeServiceAdapterContextModule.java similarity index 68% rename from compute/src/main/java/org/jclouds/compute/config/JCloudsNativeStandaloneComputeServiceContextModule.java rename to compute/src/main/java/org/jclouds/compute/config/JCloudsNativeComputeServiceAdapterContextModule.java index 48502b3c89..507f03c248 100644 --- a/compute/src/main/java/org/jclouds/compute/config/JCloudsNativeStandaloneComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/JCloudsNativeComputeServiceAdapterContextModule.java @@ -32,12 +32,13 @@ import com.google.inject.TypeLiteral; * * @author Adrian Cole */ -public class JCloudsNativeStandaloneComputeServiceContextModule extends - StandaloneComputeServiceContextModule { - private final Class> adapter; +public class JCloudsNativeComputeServiceAdapterContextModule extends + ComputeServiceAdapterContextModule { + protected final Class> adapter; - public JCloudsNativeStandaloneComputeServiceContextModule( + public JCloudsNativeComputeServiceAdapterContextModule(Class syncClientType, Class asyncClientType, Class> adapter) { + super(syncClientType, asyncClientType); this.adapter = adapter; } @@ -52,14 +53,28 @@ public class JCloudsNativeStandaloneComputeServiceContextModule extends }).to(adapter); bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE); bind(new TypeLiteral>() { - }).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class); + }).to((Class) IdentityFunction.class); bind(new TypeLiteral>() { - }).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class); + }).to((Class) IdentityFunction.class); bind(new TypeLiteral>() { - }).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class); + }).to((Class) IdentityFunction.class); bind(new TypeLiteral>() { - }).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class); + }).to((Class) IdentityFunction.class); super.configure(); } + // enum singleton pattern + public static enum IdentityFunction implements Function { + INSTANCE; + + public Object apply(Object o) { + return o; + } + + @Override + public String toString() { + return "identity"; + } + } + } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java index fe61f1df32..a9547a6192 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java @@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentMap; import javax.inject.Singleton; -import org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule; +import org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.concurrent.SingleThreaded; @@ -33,21 +33,21 @@ import com.google.inject.Provides; * * @author Adrian Cole */ +@SuppressWarnings("rawtypes") @SingleThreaded -public class StubComputeServiceContextModule extends JCloudsNativeStandaloneComputeServiceContextModule { +public class StubComputeServiceContextModule extends + JCloudsNativeComputeServiceAdapterContextModule { public StubComputeServiceContextModule() { - super(StubComputeServiceAdapter.class); + super(ConcurrentMap.class, ConcurrentMap.class, StubComputeServiceAdapter.class); } - // Ensure that a plain class is able to be bound as getProviderSpecificContext.getApi() - @SuppressWarnings("rawtypes") @Provides @Singleton ConcurrentMap provideApi(ConcurrentMap in) { return in; } - + @Override protected void configure() { install(new StubComputeServiceDependenciesModule()); diff --git a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/domain/LibvirtComputeServiceContextModule.java b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/domain/LibvirtComputeServiceContextModule.java index 223b8ed737..c8932334f8 100644 --- a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/domain/LibvirtComputeServiceContextModule.java +++ b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/domain/LibvirtComputeServiceContextModule.java @@ -36,7 +36,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.WildcardFileFilter; import org.jclouds.Constants; import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.StandaloneComputeServiceContextModule; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.TemplateBuilder; @@ -73,78 +73,78 @@ import com.jamesmurty.utils.XMLBuilder; * @author Adrian Cole */ public class LibvirtComputeServiceContextModule extends -StandaloneComputeServiceContextModule { - @Override - protected void configure() { - super.configure(); - bind(new TypeLiteral>() { - }).to(LibvirtComputeServiceAdapter.class); - bind(new TypeLiteral>() { - }).to(DefaultLocationSupplier.class); - bind(new TypeLiteral>() { - }).to(DomainToNodeMetadata.class); - bind(new TypeLiteral>() { - }).to(LibvirtImageToImage.class); - bind(new TypeLiteral>() { - }).to(DomainToHardware.class); - bind(new TypeLiteral>() { - }).to(DatacenterToLocation.class); - - //bind(ComputeService.class).to(LibvirtComputeService.class); - } + ComputeServiceAdapterContextModule { + + public LibvirtComputeServiceContextModule() { + super(Connect.class, Connect.class); + } - @Provides - @Singleton - protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity, - @Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException { - // ConnectAuth connectAuth = null; - return new Connect(endpoint.toASCIIString()); - } + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>() { + }).to(LibvirtComputeServiceAdapter.class); + bind(new TypeLiteral>() { + }).to(DefaultLocationSupplier.class); + bind(new TypeLiteral>() { + }).to(DomainToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to(LibvirtImageToImage.class); + bind(new TypeLiteral>() { + }).to(DomainToHardware.class); + bind(new TypeLiteral>() { + }).to(DatacenterToLocation.class); - @Override - protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); - String hardwareId = searchForHardwareIdInDomainDir(domainDir); - String image = searchForImageIdInDomainDir(domainDir); - return template.hardwareId(hardwareId).imageId(image) ; - } + // bind(ComputeService.class).to(LibvirtComputeService.class); + } + @Provides + @Singleton + protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity, + @Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException { + // ConnectAuth connectAuth = null; + return new Connect(endpoint.toASCIIString()); + } - private String searchForImageIdInDomainDir(String domainDir) { - // TODO - return "1"; - } - - @SuppressWarnings("unchecked") - private String searchForHardwareIdInDomainDir(String domainDir) { + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); + String hardwareId = searchForHardwareIdInDomainDir(domainDir); + String image = searchForImageIdInDomainDir(domainDir); + return template.hardwareId(hardwareId).imageId(image); + } - Collection xmlDomains = FileUtils.listFiles( new File(domainDir), new WildcardFileFilter("*.xml"), null); - String uuid = ""; - try { - String fromXML = Files.toString(Iterables.get(xmlDomains, 0), Charsets.UTF_8); - XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(fromXML))); - uuid = builder.xpathFind("/domain/uuid").getElement().getTextContent(); - } catch (IOException e) { - e.printStackTrace(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (XPathExpressionException e) { - e.printStackTrace(); - } - return uuid; - } + private String searchForImageIdInDomainDir(String domainDir) { + // TODO + return "1"; + } - /* - * Map regions = newLinkedHashMap(); - for (String region : Splitter.on(',').split(regionString)) { - regions.put( - region, - URI.create(injector.getInstance(Key.get(String.class, - Names.named(Constants.PROPERTY_ENDPOINT + "." + region))))); + @SuppressWarnings("unchecked") + private String searchForHardwareIdInDomainDir(String domainDir) { + + Collection xmlDomains = FileUtils.listFiles(new File(domainDir), new WildcardFileFilter("*.xml"), null); + String uuid = ""; + try { + String fromXML = Files.toString(Iterables.get(xmlDomains, 0), Charsets.UTF_8); + XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(fromXML))); + uuid = builder.xpathFind("/domain/uuid").getElement().getTextContent(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (XPathExpressionException e) { + e.printStackTrace(); } - return regions; - */ - + return uuid; + } + + /* + * Map regions = newLinkedHashMap(); for (String region : + * Splitter.on(',').split(regionString)) { regions.put( region, + * URI.create(injector.getInstance(Key.get(String.class, Names.named(Constants.PROPERTY_ENDPOINT + * + "." + region))))); } return regions; + */ + } \ No newline at end of file diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java index 0d908458f4..3abcba9e90 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java @@ -36,7 +36,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.WildcardFileFilter; import org.jclouds.Constants; import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.StandaloneComputeServiceContextModule; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.TemplateBuilder; @@ -69,8 +69,14 @@ import com.vmware.vim25.mo.VirtualMachine; * * @author Adrian Cole */ -public class ViComputeServiceContextModule extends - StandaloneComputeServiceContextModule { +public class ViComputeServiceContextModule + extends + ComputeServiceAdapterContextModule { + + public ViComputeServiceContextModule() { + super(ServiceInstance.class, ServiceInstance.class); + } + @Override protected void configure() { super.configure(); @@ -98,9 +104,10 @@ public class ViComputeServiceContextModule extends @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - //String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); - String domainDir = ""; - String hardwareId = searchForHardwareIdInDomainDir(domainDir); + // String domainDir = injector.getInstance(Key.get(String.class, + // Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); + String domainDir = ""; + String hardwareId = searchForHardwareIdInDomainDir(domainDir); String image = searchForImageIdInDomainDir(domainDir); return template.hardwareId(hardwareId).imageId(image); } diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/config/ServerManagerComputeServiceContextModule.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/config/ServerManagerComputeServiceContextModule.java index 82f434858f..fac7624399 100644 --- a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/config/ServerManagerComputeServiceContextModule.java +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/config/ServerManagerComputeServiceContextModule.java @@ -20,7 +20,7 @@ package org.jclouds.servermanager.compute.config; import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.StandaloneComputeServiceContextModule; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.suppliers.DefaultLocationSupplier; import org.jclouds.domain.Location; @@ -28,6 +28,7 @@ import org.jclouds.servermanager.Datacenter; import org.jclouds.servermanager.Hardware; import org.jclouds.servermanager.Image; import org.jclouds.servermanager.Server; +import org.jclouds.servermanager.ServerManager; import org.jclouds.servermanager.compute.functions.DatacenterToLocation; import org.jclouds.servermanager.compute.functions.ServerManagerHardwareToHardware; import org.jclouds.servermanager.compute.functions.ServerManagerImageToImage; @@ -43,7 +44,12 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ public class ServerManagerComputeServiceContextModule extends - StandaloneComputeServiceContextModule { + ComputeServiceAdapterContextModule { + + public ServerManagerComputeServiceContextModule() { + super(ServerManager.class, ServerManager.class); + } + @Override protected void configure() { super.configure(); From 5f0a0e628a559aaca80fc1c69deca0087d08c16b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 19 Dec 2010 18:30:33 +0100 Subject: [PATCH 17/33] worked around odd test result on osx --- .../cloudwatch/CloudWatchAsyncClientTest.java | 15 +++++-- .../ec2/services/InstanceAsyncClientTest.java | 41 ++++++++++++------- .../SecurityGroupAsyncClientTest.java | 34 ++++++++++----- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/aws/core/src/test/java/org/jclouds/aws/cloudwatch/CloudWatchAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/cloudwatch/CloudWatchAsyncClientTest.java index 9c3b11b049..545edf3847 100644 --- a/aws/core/src/test/java/org/jclouds/aws/cloudwatch/CloudWatchAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/cloudwatch/CloudWatchAsyncClientTest.java @@ -57,16 +57,23 @@ public class CloudWatchAsyncClientTest extends RestClientTest Date: Sun, 19 Dec 2010 23:51:37 +0100 Subject: [PATCH 18/33] allowed provider to be the default location --- .../compute/suppliers/DefaultLocationSupplier.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compute/src/main/java/org/jclouds/compute/suppliers/DefaultLocationSupplier.java b/compute/src/main/java/org/jclouds/compute/suppliers/DefaultLocationSupplier.java index 50d42c0847..974f230b9e 100644 --- a/compute/src/main/java/org/jclouds/compute/suppliers/DefaultLocationSupplier.java +++ b/compute/src/main/java/org/jclouds/compute/suppliers/DefaultLocationSupplier.java @@ -19,6 +19,9 @@ package org.jclouds.compute.suppliers; +import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.getOnlyElement; + import java.util.Set; import javax.inject.Inject; @@ -30,7 +33,6 @@ import org.jclouds.domain.LocationScope; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.collect.Iterables; /** * @@ -48,7 +50,9 @@ public class DefaultLocationSupplier implements Supplier { @Override public Location get() { - return Iterables.find(locations.get(), new Predicate() { + if (locations.get().size() == 1) + return getOnlyElement(locations.get()); + return find(locations.get(), new Predicate() { @Override public boolean apply(Location input) { From 90ee548e8d12ed3bab166e693e38a0442d837bc7 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 19 Dec 2010 23:52:57 +0100 Subject: [PATCH 19/33] Issue 412: added computeservice support to elasticstack --- core/src/main/resources/rest.properties | 16 ++ ...arseAuthenticationResponseFromHeaders.java | 1 - sandbox/elasticstack/pom.xml | 9 +- .../ElasticStackContextBuilder.java | 9 +- .../ElasticStackPropertiesBuilder.java | 11 + .../ElasticStackComputeServiceAdapter.java | 213 ++++++++++++++++++ ...asticStackComputeServiceContextModule.java | 145 ++++++++++++ .../functions/ServerInfoToNodeMetadata.java | 174 ++++++++++++++ .../jclouds/elasticstack/domain/Server.java | 4 +- .../elasticstack/domain/WellKnownImage.java | 82 +++++++ .../handlers/ElasticStackErrorHandler.java | 3 +- .../elasticstack/predicates/DriveClaimed.java | 0 .../reference/ElasticStackConstants.java | 34 +++ .../main/resources/preinstalled_images.json | 72 ++++++ .../CommonElasticStackClientLiveTest.java | 11 +- .../ElasticStackClientLiveTest.java | 3 +- .../ProvidersInPropertiesTest.java | 19 +- .../ElasticStackComputeServiceLiveTest.java | 39 ++++ .../ElasticStackTemplateBuilderLiveTest.java | 56 +++++ .../ElasticStackErrorHandlerTest.java | 13 +- .../elasticstack/src/test/resources/log4j.xml | 192 ++++++++++------ 21 files changed, 1020 insertions(+), 86 deletions(-) create mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java create mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java create mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java create mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java rename sandbox/elasticstack/src/{test => main}/java/org/jclouds/elasticstack/predicates/DriveClaimed.java (100%) create mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java create mode 100644 sandbox/elasticstack/src/main/resources/preinstalled_images.json create mode 100644 sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java create mode 100644 sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index 65bec42734..df5122d8ed 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -97,6 +97,22 @@ deltacloud.contextbuilder=org.jclouds.deltacloud.DeltacloudContextBuilder elasticstack.propertiesbuilder=org.jclouds.elasticstack.ElasticStackPropertiesBuilder elasticstack.contextbuilder=org.jclouds.elasticstack.ElasticStackContextBuilder +elasticstack.apiversion=1.0 + +elastichosts-lon-p.propertiesbuilder=org.jclouds.elasticstack.ElasticStackPropertiesBuilder +elastichosts-lon-p.contextbuilder=org.jclouds.elasticstack.ElasticStackContextBuilder +elastichosts-lon-p.apiversion=1.0 +elastichosts-lon-p.endpoint=https://api.lon-p.elastichosts.com + +elastichosts-lon-b.propertiesbuilder=org.jclouds.elasticstack.ElasticStackPropertiesBuilder +elastichosts-lon-b.contextbuilder=org.jclouds.elasticstack.ElasticStackContextBuilder +elastichosts-lon-b.apiversion=1.0 +elastichosts-lon-b.endpoint=https://api.lon-b.elastichosts.com + +elastichosts-sat-p.propertiesbuilder=org.jclouds.elasticstack.ElasticStackPropertiesBuilder +elastichosts-sat-p.contextbuilder=org.jclouds.elasticstack.ElasticStackContextBuilder +elastichosts-sat-p.apiversion=1.0 +elastichosts-sat-p.endpoint=https://api.sat-p.elastichosts.com cloudsigma.propertiesbuilder=org.jclouds.cloudsigma.CloudSigmaPropertiesBuilder cloudsigma.contextbuilder=org.jclouds.cloudsigma.CloudSigmaContextBuilder diff --git a/rackspace/src/main/java/org/jclouds/rackspace/functions/ParseAuthenticationResponseFromHeaders.java b/rackspace/src/main/java/org/jclouds/rackspace/functions/ParseAuthenticationResponseFromHeaders.java index 3c26bc6194..40f231364e 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/functions/ParseAuthenticationResponseFromHeaders.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/functions/ParseAuthenticationResponseFromHeaders.java @@ -47,7 +47,6 @@ import com.google.common.base.Objects; * * @author Adrian Cole */ - public class ParseAuthenticationResponseFromHeaders implements Function, InvocationContext { diff --git a/sandbox/elasticstack/pom.xml b/sandbox/elasticstack/pom.xml index 28ed17159b..73a9c7f299 100644 --- a/sandbox/elasticstack/pom.xml +++ b/sandbox/elasticstack/pom.xml @@ -61,7 +61,7 @@ ${project.groupId} - jclouds-core + jclouds-compute ${project.version} @@ -77,6 +77,13 @@ test-jar test + + ${project.groupId} + jclouds-compute + ${project.version} + test-jar + test + log4j log4j diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java index 9a072d3dac..5eec7f6ebc 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java @@ -22,8 +22,9 @@ package org.jclouds.elasticstack; import java.util.List; import java.util.Properties; +import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.elasticstack.compute.config.ElasticStackComputeServiceContextModule; import org.jclouds.elasticstack.config.ElasticStackRestClientModule; -import org.jclouds.rest.RestContextBuilder; import com.google.inject.Module; @@ -32,11 +33,15 @@ import com.google.inject.Module; * @author Adrian Cole */ public class ElasticStackContextBuilder extends - RestContextBuilder { + ComputeServiceContextBuilder { public ElasticStackContextBuilder(Properties props) { super(ElasticStackClient.class, ElasticStackAsyncClient.class, props); } + @Override + protected void addContextModule(List modules) { + modules.add(new ElasticStackComputeServiceContextModule()); + } protected void addClientModule(List modules) { modules.add(new ElasticStackRestClientModule()); diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java index 4f1b2bd9ee..f6d232cccc 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java @@ -19,7 +19,9 @@ package org.jclouds.elasticstack; +import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.elasticstack.reference.ElasticStackConstants.PROPERTY_VNC_PASSWORD; import java.util.Properties; @@ -35,9 +37,18 @@ public class ElasticStackPropertiesBuilder extends PropertiesBuilder { protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_API_VERSION, "1.0"); + properties.setProperty(PROPERTY_API_VERSION, "IL9vs34d"); return properties; } + @Override + public Properties build() { + Properties props = super.build(); + checkArgument(props.getProperty(PROPERTY_VNC_PASSWORD).length() <= 8, + "vnc passwords should be less that 8 characters!"); + return props; + } + public ElasticStackPropertiesBuilder(Properties properties) { super(properties); } diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java new file mode 100644 index 0000000000..015e1cf6a9 --- /dev/null +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java @@ -0,0 +1,213 @@ +package org.jclouds.elasticstack.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.notNull; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; +import static org.jclouds.elasticstack.util.Servers.small; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystemBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.internal.VolumeImpl; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.elasticstack.domain.Device; +import org.jclouds.elasticstack.domain.Drive; +import org.jclouds.elasticstack.domain.DriveInfo; +import org.jclouds.elasticstack.domain.ImageConversionType; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.domain.WellKnownImage; +import org.jclouds.elasticstack.reference.ElasticStackConstants; +import org.jclouds.logging.Logger; +import org.jclouds.rest.annotations.Provider; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * defines the connection between the {@link ElasticStackClient} implementation and the jclouds + * {@link ComputeService} + * + */ +@Singleton +public class ElasticStackComputeServiceAdapter implements ComputeServiceAdapter { + private final ElasticStackClient client; + private final Predicate driveNotClaimed; + private final Supplier locationSupplier; + private final List preinstalledImages; + private final String providerName; + private final URI providerURI; + private final String defaultVncPassword; + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + @Inject + public ElasticStackComputeServiceAdapter(ElasticStackClient client, Predicate driveNotClaimed, + Supplier locationSupplier, @Provider String providerName, @Provider URI providerURI, + List preinstalledImages, + @Named(ElasticStackConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword) { + this.client = checkNotNull(client, "client"); + this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed"); + this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier"); + this.providerName = checkNotNull(providerName, "providerName"); + this.providerURI = checkNotNull(providerURI, "providerURI"); + this.preinstalledImages = checkNotNull(preinstalledImages, "preinstalledImages"); + this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword"); + } + + @Override + public ServerInfo runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, + Map credentialStore) { + long bootSize = (long) (template.getHardware().getVolumes().get(0).getSize() * 1024 * 1024 * 1024l); + logger.debug(">> creating boot drive bytes(%d)", bootSize); + DriveInfo drive = client.createDrive(new Drive.Builder().name(template.getImage().getName()).size(bootSize) + .build()); + logger.debug("<< drive(%s)", drive.getUuid()); + + logger.debug(">> imaging boot drive source(%s)", template.getImage().getId()); + client.imageDrive(template.getImage().getId(), drive.getUuid(), ImageConversionType.GUNZIP); + boolean success = driveNotClaimed.apply(drive); + logger.debug("<< imaged (%s)", success); + if (!success) { + client.destroyDrive(drive.getUuid()); + throw new IllegalStateException("could not image drive in time!"); + } + Server toCreate = small(name, drive.getUuid(), defaultVncPassword).mem(template.getHardware().getRam()) + .cpu((int) (template.getHardware().getProcessors().get(0).getSpeed())).build(); + + ServerInfo from = client.createAndStartServer(toCreate); + // store the credentials so that later functions can use them + credentialStore.put(from.getUuid() + "", new Credentials("toor", from.getVnc().getPassword())); + return from; + } + + @Override + public Iterable listHardwareProfiles() { + Builder hardware = ImmutableSet. builder(); + for (double cpu : new double[] { 1000, 5000, 10000, 20000 }) + for (int ram : new int[] { 512, 1024, 2048, 4096, 8192 }) { + final float size = (float) cpu / 1000; + String id = String.format("cpu=%f,ram=%s,disk=%f", cpu, ram, size); + hardware.add(new HardwareBuilder().supportsImage(new Predicate() { + + @Override + public boolean apply(Image input) { + String toParse = input.getUserMetadata().get("size"); + return (toParse != null && new Float(toParse) <= size); + } + + }).ids(id).ram(ram).processors(ImmutableList.of(new Processor(1, cpu))) + .volumes(ImmutableList. of(new VolumeImpl(size, true, true))).build()); + } + return hardware.build(); + } + + /** + * look up the current standard images and do not error out, if they are not found. + */ + @Override + public Iterable listImages() { + return filter(transform(preinstalledImages, new Function() { + + @Override + public Image apply(WellKnownImage input) { + DriveInfo drive = null; + try { + drive = client.getDriveInfo(input.getUuid()); + } catch (Exception e) { + logger.warn(e, "could not find image: %s", input); + } + if (drive == null) { + logger.warn("could not find image: %s", input); + return null; + } + return new ImageBuilder() + .ids(drive.getUuid()) + .userMetadata( + ImmutableMap. builder().putAll(drive.getUserMetadata()) + .put("size", input.getSize() + "").build()) + .defaultCredentials(new Credentials("toor", null)) + .location(locationSupplier.get()) + .name(input.getDescription()) + .description(drive.getName()) + .operatingSystem( + new OperatingSystemBuilder().family(input.getOsFamily()).version(input.getOsVersion()) + .name(input.getDescription()).description(drive.getName()).is64Bit(true).build()) + .version("").build(); + } + + }), notNull()); + } + + @SuppressWarnings("unchecked") + @Override + public Iterable listNodes() { + return (Iterable) client.listServerInfo(); + } + + @Override + public Iterable listLocations() { + return ImmutableSet. of(new LocationImpl(LocationScope.PROVIDER, providerName, providerURI + .toASCIIString(), null)); + } + + @Override + public ServerInfo getNode(String id) { + return client.getServerInfo(id); + } + + @Override + public void destroyNode(String id) { + ServerInfo server = getNode(id); + if (server != null) { + client.destroyServer(id); + for (Device dev : server.getDevices().values()) + client.destroyDrive(dev.getDriveUuid()); + } + } + + @Override + public void rebootNode(String id) { + client.resetServer(id); + } + + @Override + public void resumeNode(String id) { + client.startServer(id); + + } + + @Override + public void suspendNode(String id) { + client.stopServer(id); + } +} \ No newline at end of file diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java new file mode 100644 index 0000000000..4d6988dadd --- /dev/null +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java @@ -0,0 +1,145 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.compute.config; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule.IdentityFunction; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.suppliers.DefaultLocationSupplier; +import org.jclouds.domain.Location; +import org.jclouds.elasticstack.CommonElasticStackClient; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.elasticstack.compute.ElasticStackComputeServiceAdapter; +import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata; +import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.DeviceToVolume; +import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.FindImageForId; +import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.GetImageIdFromServer; +import org.jclouds.elasticstack.domain.Device; +import org.jclouds.elasticstack.domain.DriveInfo; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.domain.WellKnownImage; +import org.jclouds.elasticstack.predicates.DriveClaimed; +import org.jclouds.json.Json; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.util.Utils; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.base.Supplier; +import com.google.common.collect.MapMaker; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +public class ElasticStackComputeServiceContextModule + extends + ComputeServiceAdapterContextModule { + + public ElasticStackComputeServiceContextModule() { + super(ElasticStackClient.class, ElasticStackAsyncClient.class); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>() { + }).to(ElasticStackComputeServiceAdapter.class); + bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE); + bind(new TypeLiteral>() { + }).to(DefaultLocationSupplier.class); + bind(new TypeLiteral>() { + }).to(ServerInfoToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); + bind(new TypeLiteral>() { + }).to(DeviceToVolume.class); + bind(new TypeLiteral>() { + }).to(GetImageIdFromServer.class); + bind(new TypeLiteral>() { + }).to(FindImageForId.class); + } + + @Provides + @Singleton + protected Map cache(GetDrive getDrive) { + return new MapMaker().expiration(30, TimeUnit.SECONDS).makeComputingMap(getDrive); + } + + @Singleton + public static class GetDrive implements Function { + private final ElasticStackClient client; + + @Inject + public GetDrive(ElasticStackClient client) { + this.client = client; + } + + @Override + public DriveInfo apply(String input) { + return client.getDriveInfo(input); + } + } + + @Singleton + @Provides + protected List provideImages(Json json) throws IOException { + return json.fromJson(Utils.toStringAndClose(getClass().getResourceAsStream("/preinstalled_images.json")), + new TypeLiteral>() { + }.getType()); + } + + @Provides + @Singleton + protected CommonElasticStackClient convert(ElasticStackClient in) { + return in; + } + + @Provides + @Singleton + protected Predicate supplyDriveUnclaimed(DriveClaimed driveClaimed, + ComputeServiceConstants.Timeouts timeouts) { + return new RetryablePredicate(Predicates.not(driveClaimed), timeouts.nodeRunning, 1000, + TimeUnit.MILLISECONDS); + } +} \ No newline at end of file diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java new file mode 100644 index 0000000000..cdd22788ec --- /dev/null +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java @@ -0,0 +1,174 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.FindResourceInSet; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.VolumeBuilder; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.elasticstack.domain.Device; +import org.jclouds.elasticstack.domain.DriveInfo; +import org.jclouds.elasticstack.domain.Server; +import org.jclouds.elasticstack.domain.ServerInfo; +import org.jclouds.elasticstack.domain.ServerStatus; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Singleton +public class ServerInfoToNodeMetadata implements Function { + public static final Map serverStatusToNodeState = ImmutableMap + . builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)// + .put(ServerStatus.STOPPED, NodeState.SUSPENDED)// + .put(ServerStatus.PAUSED, NodeState.SUSPENDED)// + .put(ServerStatus.DUMPED, NodeState.PENDING)// + .put(ServerStatus.DEAD, NodeState.TERMINATED)// + .put(ServerStatus.UNRECOGNIZED, NodeState.UNRECOGNIZED)// + .build(); + + private final Function getImageIdFromServer; + private final Function findImageForId; + private final Map credentialStore; + private final Supplier locationSupplier; + private final Function deviceToVolume; + + @Inject + ServerInfoToNodeMetadata(Map credentialStore, Function getImageIdFromServer, + Function findImageForId, Function deviceToVolume, + Supplier locationSupplier) { + this.credentialStore = checkNotNull(credentialStore, "credentialStore"); + this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier"); + this.deviceToVolume = checkNotNull(deviceToVolume, "deviceToVolume"); + this.findImageForId = checkNotNull(findImageForId, "findImageForId"); + this.getImageIdFromServer = checkNotNull(getImageIdFromServer, "getImageIdFromServer"); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public NodeMetadata apply(ServerInfo from) { + NodeMetadataBuilder builder = new NodeMetadataBuilder(); + builder.ids(from.getUuid()); + builder.name(from.getName()); + builder.location(locationSupplier.get()); + builder.tag(parseTagFromName(from.getName())); + + String imageId = getImageIdFromServer.apply(from); + if (imageId != null) { + Image image = findImageForId.apply(imageId); + if (image != null) { + builder.operatingSystem(image.getOperatingSystem()); + } + } + builder.hardware(new HardwareBuilder().ids(from.getUuid()) + .processors(ImmutableList.of(new Processor(1, from.getCpu()))).ram(from.getMem()) + .volumes((List) ImmutableList.of(Iterables.transform(from.getDevices().values(), deviceToVolume))).build()); + builder.state(serverStatusToNodeState.get(from.getStatus())); + builder.publicAddresses(ImmutableSet. of(from.getVnc().getIp())); + builder.privateAddresses(ImmutableSet. of()); + builder.credentials(credentialStore.get(from.getUuid())); + return builder.build(); + } + + @Singleton + public static final class DeviceToVolume implements Function { + private final Map cache; + + @Inject + public DeviceToVolume(Map cache) { + this.cache = checkNotNull(cache, "cache"); + } + + @Override + public Volume apply(Device input) { + VolumeBuilder builder = new VolumeBuilder(); + builder.id(input.getId()); + DriveInfo drive = cache.get(input.getDriveUuid()); + if (drive != null) { + builder.size(drive.getSize() / 1024 / 1024f); + } + return new VolumeBuilder().durable(true).type(Volume.Type.NAS).build(); + } + } + + @Singleton + public static class GetImageIdFromServer implements Function { + private final Map cache; + + @Inject + public GetImageIdFromServer(Map cache) { + this.cache = cache; + } + + @Override + public String apply(Server from) { + String imageId = null; + String bootDeviceId = Iterables.get(from.getBootDeviceIds(), 0); + Device bootDevice = from.getDevices().get(bootDeviceId); + if (bootDevice != null) { + try { + imageId = cache.get(bootDevice.getDriveUuid()).getUuid(); + } catch (NullPointerException e) { + + } + } + return imageId; + } + } + + @Singleton + public static class FindImageForId extends FindResourceInSet { + + @Inject + public FindImageForId(@Memoized Supplier> images) { + super(images); + } + + @Override + public boolean matches(String from, Image input) { + return input.getProviderId().equals(from); + } + } + +} diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java index ceda1d3e51..de0dee3358 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/Server.java @@ -144,7 +144,7 @@ public class Server extends Item { protected final int mem; protected final boolean persistent; @Nullable - protected final Map devices; + protected final Map devices; protected final Set bootDeviceIds; protected final List nics; protected final VNC vnc; @@ -203,7 +203,7 @@ public class Server extends Item { * * @return devices present, mapped by id */ - public Map getDevices() { + public Map getDevices() { return devices; } diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java new file mode 100644 index 0000000000..b9544d303a --- /dev/null +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/domain/WellKnownImage.java @@ -0,0 +1,82 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.domain; + +import org.jclouds.compute.domain.OsFamily; + +import com.google.common.base.Objects; + +/** + * + * @author Adrian Cole + */ +public class WellKnownImage { + private String uuid; + private String description; + private OsFamily osFamily; + private String osVersion; + private int size; + + // intended only for serialization + WellKnownImage() { + + } + + // performance isn't a concern on a infrequent object like this, so using shortcuts; + + public String getUuid() { + return uuid; + } + + public String getDescription() { + return description; + } + + public OsFamily getOsFamily() { + return osFamily; + } + + public String getOsVersion() { + return osVersion; + } + + public int getSize() { + return size; + } + + @Override + public int hashCode() { + return Objects.hashCode(uuid, description, osFamily, osVersion, size); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + return Objects.equal(this.toString(), that.toString()); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("uuid", uuid).add("description", description).add("osFamily", osFamily) + .add("osVersion", osVersion).add("size", size).toString(); + } + +} \ No newline at end of file diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java index cdc0c55e03..d578b7318f 100644 --- a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java @@ -61,7 +61,8 @@ public class ElasticStackErrorHandler implements HttpErrorHandler { response.getStatusLine()); switch (response.getStatusCode()) { case 400: - if (message != null && message.indexOf("could not be found") != -1) + if ((command.getRequest().getEndpoint().getPath().endsWith("/info")) + || (message != null && message.indexOf("could not be found") != -1)) exception = new ResourceNotFoundException(message, exception); else exception = new IllegalArgumentException(message, exception); diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/predicates/DriveClaimed.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java similarity index 100% rename from sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/predicates/DriveClaimed.java rename to sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/predicates/DriveClaimed.java diff --git a/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java new file mode 100644 index 0000000000..f20736b5af --- /dev/null +++ b/sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/reference/ElasticStackConstants.java @@ -0,0 +1,34 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.reference; + +/** + * Common constants used in ElasticStack provider + * + * @author Adrian Cole + */ +public class ElasticStackConstants { + + /** + * default VNC password used on new machines + */ + public static final String PROPERTY_VNC_PASSWORD = "jclouds.elasticstack.vnc-password"; + +} diff --git a/sandbox/elasticstack/src/main/resources/preinstalled_images.json b/sandbox/elasticstack/src/main/resources/preinstalled_images.json new file mode 100644 index 0000000000..dadd7b7441 --- /dev/null +++ b/sandbox/elasticstack/src/main/resources/preinstalled_images.json @@ -0,0 +1,72 @@ +[ + { + "uuid": "38df0986-4d85-4b76-b502-3878ffc80161", + "description": "CentOS Linux 5.5", + "osFamily": "CENTOS", + "osVersion": "5.5", + "size": "3" + }, + { + "uuid": "980cf63c-f21e-4382-997b-6541d5809629", + "description": "Debian Linux 5.0", + "osFamily": "DEBIAN", + "osVersion": "5.0", + "size": "1" + }, + { + "uuid": "aee5589a-88c3-43ef-bb0a-9cab6e64192d", + "description": "Ubuntu Linux 10.04", + "osFamily": "UBUNTU", + "osVersion": "10.04", + "size": "1" + }, + { + "uuid": "bf1d943e-2a55-46bb-a8c7-6099e44a3dde", + "description": "Ubuntu Linux 8.10: Base system with X", + "osFamily": "UBUNTU", + "osVersion": "8.10", + "size": "3" + }, + { + "uuid": "757586d5-f1e9-4d9c-b215-5a391c9a24bf", + "description": "Ubuntu Linux 9.04: Base system with X", + "osFamily": "UBUNTU", + "osVersion": "9.04", + "size": "3" + }, + { + "uuid": "b9d0eb72-d273-43f1-98e3-0d4b87d372c0", + "description": "Windows Web Server 2008", + "osFamily": "WINDOWS", + "osVersion": "2008", + "size": "13" + }, + { + "uuid": "b405b598-4ae4-4ba8-8a2b-a9487d693f34", + "description": "Windows Web Server 2008 R2", + "osFamily": "WINDOWS", + "osVersion": "2008 R2", + "size": "13" + }, + { + "uuid": "9397d327-3bf6-46a2-abf6-69553dbb6927", + "description": "Windows Web Server 2008 R2 + SQL Server", + "osFamily": "WINDOWS", + "osVersion": "2008 R2", + "size": "13" + }, + { + "uuid": "10a88d1c-6575-46e3-8d2c-7744065ea530", + "description": "Windows Server 2008 Standard R2", + "osFamily": "WINDOWS", + "osVersion": "2008 R2", + "size": "13" + }, + { + "uuid": "662c5b3f-9828-4aa2-a866-7cfa53798cdf", + "description": "Windows Server 2008 Standard R2 + SQL Server", + "osFamily": "WINDOWS", + "osVersion": "2008 R2", + "size": "13" + } +] diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java index 911a8e6fb1..0eda00b6e1 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java @@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import org.jclouds.Constants; +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.domain.Credentials; import org.jclouds.elasticstack.domain.ClaimType; import org.jclouds.elasticstack.domain.CreateDriveRequest; @@ -48,7 +49,6 @@ import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.jsch.config.JschSshClientModule; @@ -84,7 +84,7 @@ public abstract class CommonElasticStackClientLiveTest driveNotClaimed; + protected Predicate driveNotClaimed; protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); @@ -111,8 +111,8 @@ public abstract class CommonElasticStackClientLiveTest of(new Log4JLoggingModule()), - overrides); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); client = context.getApi(); driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, @@ -319,6 +319,9 @@ public abstract class CommonElasticStackClientLiveTest providers = Utils.getSupportedProviders(); assert Iterables.contains(providers, "elasticstack") : providers; + assert Iterables.contains(providers, "elastichosts-lon-p") : providers; + assert Iterables.contains(providers, "elastichosts-lon-b") : providers; + assert Iterables.contains(providers, "elastichosts-sat-p") : providers; + } + + @Test + public void testSupportedComputeServiceProviders() { + Iterable providers = ComputeServiceUtils.getSupportedProviders(); + assert Iterables.contains(providers, "elasticstack") : providers; + assert Iterables.contains(providers, "elastichosts-lon-p") : providers; + assert Iterables.contains(providers, "elastichosts-lon-b") : providers; + assert Iterables.contains(providers, "elastichosts-sat-p") : providers; } -// -// @Test -// public void testSupportedComputeServiceProviders() { -// Iterable providers = ComputeServiceUtils.getSupportedProviders(); -// assert Iterables.contains(providers, "cloudsigma") : providers; -// } } diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java new file mode 100644 index 0000000000..fa9c9c60bf --- /dev/null +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java @@ -0,0 +1,39 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.elasticstack.compute; + +import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "live") +public class ElasticStackComputeServiceLiveTest extends BaseComputeServiceLiveTest { + public ElasticStackComputeServiceLiveTest() { + provider = "elasticstack"; + } + + @Override + protected JschSshClientModule getSshModule() { + return new JschSshClientModule(); + } + +} diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..d1d09b1e8d --- /dev/null +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackTemplateBuilderLiveTest.java @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.elasticstack.compute; + +import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.OsFamilyVersion64Bit; +import org.jclouds.compute.domain.OsFamily; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class ElasticStackTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { + + public ElasticStackTemplateBuilderLiveTest() { + provider = "elasticstack"; + } + + @Override + protected Predicate defineUnsupportedOperatingSystems() { + return new Predicate() { + + @Override + public boolean apply(OsFamilyVersion64Bit input) { + return ((input.family == OsFamily.RHEL) || // + (input.family == OsFamily.CENTOS && !(input.version.equals("5.5") && input.is64Bit)) || // + (input.family == OsFamily.UBUNTU && !(input.version.equals("10.04") && input.is64Bit)) || // + (input.family == OsFamily.WINDOWS && !((input.version.equals("2008") || input.version.equals("2008 R2")) && input.is64Bit)) // + ); + } + + }; + } + +} \ No newline at end of file diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java index 0e23584cc0..e7165d0144 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandlerTest.java @@ -52,9 +52,20 @@ public class ElasticStackErrorHandlerTest { IllegalArgumentException.class); } + @Test + public void test400MakesResourceNotFoundExceptionOnInfo() { + assertCodeMakes("GET", URI.create("https://elasticstack.com/foo/info"), 400, "", "", + ResourceNotFoundException.class); + } + @Test public void test400MakesResourceNotFoundExceptionOnMessageNotFound() { - assertCodeMakes("GET", URI.create("https://elasticstack.com/foo"), 400, "", "errors:system Drive 8f9b42b1-26de-49ad-a3fd-d4fa06524339 could not be found. Please re-validate your entry.", + assertCodeMakes( + "GET", + URI.create("https://elasticstack.com/foo"), + 400, + "", + "errors:system Drive 8f9b42b1-26de-49ad-a3fd-d4fa06524339 could not be found. Please re-validate your entry.", ResourceNotFoundException.class); } diff --git a/sandbox/elasticstack/src/test/resources/log4j.xml b/sandbox/elasticstack/src/test/resources/log4j.xml index 99fc6ca2a0..7343ec00e2 100644 --- a/sandbox/elasticstack/src/test/resources/log4j.xml +++ b/sandbox/elasticstack/src/test/resources/log4j.xml @@ -1,32 +1,31 @@ - + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed + under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions + and limitations under the License. + ==================================================================== + --> - + + debug="false"> @@ -39,72 +38,133 @@ - + - - - - + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - + + - + + + + + + - + + + + + + + - - - - - + + + - + \ No newline at end of file From 23b164ba3d152f3afc981354211a9b334d762d64 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 20 Dec 2010 01:12:42 +0100 Subject: [PATCH 20/33] Issue 419: removed dependency between elasticstack and cloudsigma --- sandbox/cloudsigma/pom.xml | 11 +- .../cloudsigma/CloudSigmaAsyncClient.java | 115 +++-- .../jclouds/cloudsigma/CloudSigmaClient.java | 170 ++++++-- .../CloudSigmaPropertiesBuilder.java | 10 + ...indCloneDriveOptionsToPlainTextString.java | 2 +- .../BindDriveDataToPlainTextString.java | 61 +++ .../binders/BindDriveToPlainTextString.java | 61 +++ .../binders/BindServerToPlainTextString.java | 61 +++ .../config/CloudSigmaRestClientModule.java | 36 +- .../cloudsigma/domain/BlockDevice.java | 86 ++++ .../jclouds/cloudsigma/domain/ClaimType.java | 57 +++ .../cloudsigma/domain/CreateDriveRequest.java | 162 +++++++ .../org/jclouds/cloudsigma/domain/Device.java | 108 +++++ .../org/jclouds/cloudsigma/domain/Drive.java | 203 +++++++++ .../jclouds/cloudsigma/domain/DriveData.java | 80 ++++ .../jclouds/cloudsigma/domain/DriveInfo.java | 399 +++++++++++------- .../cloudsigma/domain/DriveMetrics.java | 139 ++++++ .../cloudsigma/domain/DriveStatus.java | 48 +++ .../jclouds/cloudsigma/domain/IDEDevice.java | 98 +++++ .../org/jclouds/cloudsigma/domain/Item.java | 170 ++++++++ .../jclouds/cloudsigma/domain/MediaType.java | 50 +++ .../org/jclouds/cloudsigma/domain/Model.java | 47 +++ .../org/jclouds/cloudsigma/domain/NIC.java | 177 ++++++++ .../jclouds/cloudsigma/domain/SCSIDevice.java | 94 +++++ .../org/jclouds/cloudsigma/domain/Server.java | 293 +++++++++++++ .../jclouds/cloudsigma/domain/ServerInfo.java | 258 +++++++++++ .../cloudsigma/domain/ServerMetrics.java | 156 +++++++ .../cloudsigma/domain/ServerStatus.java | 47 +++ .../org/jclouds/cloudsigma/domain/VNC.java | 105 +++++ ...eRequestToMap.java => BaseDriveToMap.java} | 39 +- .../cloudsigma/functions/DriveDataToMap.java | 8 +- ...luesDelimitedByBlankLinesToServerInfo.java | 2 +- ...esDelimitedByBlankLinesToDriveInfoSet.java | 2 +- ...luesDelimitedByBlankLinesToListOfMaps.java | 59 +++ ...sDelimitedByBlankLinesToServerInfoSet.java | 4 +- ...oListOfKeyValuesDelimitedByBlankLines.java | 58 +++ .../cloudsigma/functions/MapToDevices.java | 102 +++++ .../cloudsigma/functions/MapToDriveInfo.java | 53 ++- .../functions/MapToDriveMetrics.java | 87 ++++ .../cloudsigma/functions/MapToNICs.java | 59 +++ .../cloudsigma/functions/MapToServerInfo.java | 15 +- .../functions/MapToServerMetrics.java | 60 +++ .../cloudsigma/functions/ReturnPayload.java | 38 ++ .../cloudsigma/functions/ServerToMap.java | 12 +- .../cloudsigma/functions/SplitNewlines.java | 55 +++ .../handlers/CloudSigmaErrorHandler.java | 107 +++++ .../cloudsigma/predicates/DriveClaimed.java | 63 +++ .../reference/CloudSigmaConstants.java | 33 ++ .../org/jclouds/cloudsigma/util/Servers.java | 54 +++ .../cloudsigma/CloudSigmaAsyncClientTest.java | 18 +- .../cloudsigma/CloudSigmaClientLiveTest.java | 331 +++++++++++++-- .../BindDriveDataToPlainTextStringTest.java | 87 ++++ .../BindDriveToPlainTextStringTest.java | 91 ++++ .../BindServerToPlainTextStringTest.java | 92 ++++ .../functions/BaseDriveToMapTest.java | 64 +++ .../functions/DriveDataToMapTest.java | 65 +++ ...sDelimitedByBlankLinesToDriveInfoTest.java | 2 +- ...DelimitedByBlankLinesToServerInfoTest.java | 18 +- ...limitedByBlankLinesToDriveInfoSetTest.java | 2 +- ...DelimitedByBlankLinesToListOfMapsTest.java | 66 +++ ...imitedByBlankLinesToServerInfoSetTest.java | 20 +- ...tOfKeyValuesDelimitedByBlankLinesTest.java | 60 +++ .../functions/MapToDriveInfoTest.java | 16 +- .../functions/MapToServerInfoTest.java | 30 +- .../cloudsigma/functions/ServerToMapTest.java | 10 +- .../functions/SplitNewlinesTest.java | 55 +++ .../handlers/CloudSigmaErrorHandlerTest.java | 141 +++++++ .../src/test/resources/create_drive.txt | 5 + .../src/test/resources/create_server.txt | 11 + .../test/resources/{cloudsigma => }/drive.txt | 0 .../src/test/resources/drive_data.txt | 5 + .../cloudsigma/src/test/resources/log4j.xml | 170 ++++++++ .../src/test/resources/new_server.txt | 24 ++ .../cloudsigma/src/test/resources/servers.txt | 40 ++ .../cloudsigma/src/test/resources/uuids.txt | 3 + .../CommonElasticStackAsyncClient.java | 199 --------- .../CommonElasticStackClient.java | 179 -------- .../elasticstack/ElasticStackAsyncClient.java | 147 ++++++- .../elasticstack/ElasticStackClient.java | 142 ++++++- .../ElasticStackPropertiesBuilder.java | 2 +- ...asticStackComputeServiceContextModule.java | 7 - .../jclouds/elasticstack/domain/Server.java | 34 +- .../elasticstack/domain/ServerInfo.java | 16 +- .../functions/MapToServerInfo.java | 1 - .../elasticstack/predicates/DriveClaimed.java | 27 +- .../CommonElasticStackClientLiveTest.java | 348 --------------- .../ElasticStackClientLiveTest.java | 311 +++++++++++++- 87 files changed, 5883 insertions(+), 1170 deletions(-) create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextString.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextString.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextString.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/BlockDevice.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ClaimType.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/CreateDriveRequest.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Device.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Drive.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveData.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveMetrics.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/DriveStatus.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/IDEDevice.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Item.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/MediaType.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Model.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/NIC.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/SCSIDevice.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/Server.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerInfo.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerMetrics.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/ServerStatus.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/domain/VNC.java rename sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/{CreateDriveRequestToMap.java => BaseDriveToMap.java} (53%) create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDevices.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToDriveMetrics.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToNICs.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/MapToServerMetrics.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/ReturnPayload.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/SplitNewlines.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/predicates/DriveClaimed.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/reference/CloudSigmaConstants.java create mode 100644 sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/util/Servers.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/SplitNewlinesTest.java create mode 100644 sandbox/cloudsigma/src/test/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandlerTest.java create mode 100644 sandbox/cloudsigma/src/test/resources/create_drive.txt create mode 100644 sandbox/cloudsigma/src/test/resources/create_server.txt rename sandbox/cloudsigma/src/test/resources/{cloudsigma => }/drive.txt (100%) create mode 100644 sandbox/cloudsigma/src/test/resources/drive_data.txt create mode 100644 sandbox/cloudsigma/src/test/resources/log4j.xml create mode 100644 sandbox/cloudsigma/src/test/resources/new_server.txt create mode 100644 sandbox/cloudsigma/src/test/resources/servers.txt create mode 100644 sandbox/cloudsigma/src/test/resources/uuids.txt delete mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackAsyncClient.java delete mode 100644 sandbox/elasticstack/src/main/java/org/jclouds/elasticstack/CommonElasticStackClient.java delete mode 100644 sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/CommonElasticStackClientLiveTest.java diff --git a/sandbox/cloudsigma/pom.xml b/sandbox/cloudsigma/pom.xml index 70c6a0c0ad..b0169695f4 100644 --- a/sandbox/cloudsigma/pom.xml +++ b/sandbox/cloudsigma/pom.xml @@ -61,7 +61,7 @@ ${project.groupId} - jclouds-elasticstack + jclouds-compute ${project.version} @@ -79,7 +79,14 @@ ${project.groupId} - jclouds-elasticstack + jclouds-core + ${project.version} + test-jar + test + + + ${project.groupId} + jclouds-compute ${project.version} test-jar test diff --git a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java index e70ea6c2f2..2a96dfd361 100644 --- a/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java +++ b/sandbox/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaAsyncClient.java @@ -35,16 +35,14 @@ import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerIn import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.elasticstack.CommonElasticStackAsyncClient; -import org.jclouds.elasticstack.ElasticStackClient; -import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString; -import org.jclouds.elasticstack.binders.BindDriveToPlainTextString; -import org.jclouds.elasticstack.binders.BindServerToPlainTextString; -import org.jclouds.elasticstack.domain.Drive; -import org.jclouds.elasticstack.domain.DriveData; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.functions.SplitNewlines; +import org.jclouds.cloudsigma.binders.BindDriveDataToPlainTextString; +import org.jclouds.cloudsigma.binders.BindDriveToPlainTextString; +import org.jclouds.cloudsigma.binders.BindServerToPlainTextString; +import org.jclouds.cloudsigma.domain.Drive; +import org.jclouds.cloudsigma.domain.DriveData; +import org.jclouds.cloudsigma.domain.Server; +import org.jclouds.cloudsigma.domain.ServerInfo; +import org.jclouds.cloudsigma.functions.SplitNewlines; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; @@ -53,6 +51,7 @@ import org.jclouds.rest.annotations.MapPayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -60,16 +59,16 @@ import com.google.common.util.concurrent.ListenableFuture; * Provides asynchronous access to CloudSigma via their REST API. *