From 39361c9cbd0d078b5ea34ec65337b8edcd930266 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 27 Oct 2010 23:45:30 -0700 Subject: [PATCH] fixed credentials so that node creds are prefixed consistently with node#; normalized os version parsing --- .../RunningInstanceToNodeMetadata.java | 2 +- .../EC2RunNodesAndAddToSetStrategy.java | 30 +++--- ...teAndBlobStoreTogetherHappilyLiveTest.java | 3 +- .../aws/CredentialsStoredInBlobStoreTest.java | 12 +-- .../compute/EC2ComputeServiceLiveTest.java | 1 + .../compute/EC2TemplateBuilderLiveTest.java | 8 +- .../RunningInstanceToNodeMetadataTest.java | 2 +- .../EC2RunNodesAndAddToSetStrategyTest.java | 27 +++--- .../PlacementGroupClientLiveTest.java | 21 ++--- .../compute/ComputeServiceAdapter.java | 18 ++-- .../compute/ComputeServiceContext.java | 19 +++- .../compute/internal/BaseComputeService.java | 4 +- .../config/StubComputeServiceAdapter.java | 50 ++++------ .../StubComputeServiceContextModule.java | 9 -- .../compute/BaseComputeServiceLiveTest.java | 67 +++++++------- .../org/jclouds/compute/ComputeTestUtils.java | 10 +- .../org/jclouds/compute/RunScriptData.java | 37 ++++---- .../test/resources/initscript_with_java.sh | 9 +- .../test/resources/initscript_with_jboss.sh | 9 +- compute/src/test/resources/runscript.sh | 8 +- .../suppliers/GoGridImageSupplier.java | 28 ++++-- .../compute/GoGridComputeServiceLiveTest.java | 1 + .../suppliers/GoGridImageSupplierTest.java} | 31 +++---- .../CloudServersImageToOperatingSystem.java | 6 +- .../functions/ServerToNodeMetadata.java | 2 +- .../CloudServersAddNodeWithTagStrategy.java | 8 +- .../CloudServersClientLiveTest.java | 5 +- .../CloudServersComputeServiceLiveTest.java | 1 + .../CloudServersImageToImageTest.java | 2 +- .../functions/ServerToNodeMetadataTest.java | 26 +++--- rackspace/src/test/resources/log4j.xml | 4 +- ...imuHostingComputeServiceContextModule.java | 2 +- .../functions/ServerToNodeMetadata.java | 2 +- .../RimuHostingAddNodeWithTagStrategy.java | 11 +-- .../suppliers/RimuHostingImageSupplier.java | 16 ++-- .../miro/RimuHostingClientLiveTest.java | 12 +-- .../RimuHostingComputeServiceLiveTest.java | 1 + .../functions/DomainToNodeMetadata.java | 22 ++--- .../LibvirtComputeServiceAdapter.java | 6 +- .../SlicehostComputeServiceContextModule.java | 9 ++ .../functions/SliceToNodeMetadata.java | 2 +- .../SlicehostImageToOperatingSystem.java | 10 +- .../SlicehostAddNodeWithTagStrategy.java | 2 +- .../SlicehostComputeServiceLiveTest.java | 1 + .../functions/SliceToNodeMetadataTest.java | 14 +-- .../functions/SlicehostImageToImageTest.java | 30 ++++-- .../slicehost/xml/ImageHandlerTest.java | 13 ++- .../slicehost/xml/ImagesHandlerTest.java | 10 +- .../src/test/resources/test_get_image32.xml | 7 ++ .../src/test/resources/test_list_images.xml | 92 ++++++++++--------- .../compute/functions/VAppToNodeMetadata.java | 8 +- .../VCloudExpressVAppToNodeMetadata.java | 2 +- .../compute/TerremarkVCloudComputeClient.java | 2 +- ...remarkVCloudExpressVAppToNodeMetadata.java | 4 +- .../compute/strategy/CleanupOrphanKeys.java | 4 +- ...TerremarkVCloudAddNodeWithTagStrategy.java | 2 +- .../TerremarkVCloudComputeClientTest.java | 2 +- .../strategy/CleanupOrphanKeysTest.java | 6 +- 58 files changed, 399 insertions(+), 353 deletions(-) rename gogrid/src/{main/java/org/jclouds/gogrid/util/GoGridUtils.java => test/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplierTest.java} (50%) create mode 100644 slicehost/src/test/resources/test_get_image32.xml diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java index 9d7bbda728..e73e225ddf 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -91,7 +91,7 @@ public class RunningInstanceToNodeMetadata implements Function instancePresent, - Function runningInstanceToNodeMetadata, - Function instanceToCredentials, Map credentialStore, - ComputeUtils utils) { + EC2Client client, + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions, + @Named("PRESENT") Predicate instancePresent, + Function runningInstanceToNodeMetadata, + Function instanceToCredentials, Map credentialStore, + ComputeUtils utils) { this.client = client; this.instancePresent = instancePresent; this.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions; @@ -96,10 +96,10 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate @Override public Map> execute(String tag, int count, Template template, Set goodNodes, - Map badNodes) { + Map badNodes) { Reservation reservation = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(tag, - count, template); + count, template); Iterable ids = transform(reservation, instanceToId); @@ -111,8 +111,8 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate populateCredentials(reservation); } - return utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(template.getOptions(), - transform(reservation, runningInstanceToNodeMetadata), goodNodes, badNodes); + return utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(template.getOptions(), transform( + reservation, runningInstanceToNodeMetadata), goodNodes, badNodes); } protected void populateCredentials(Reservation reservation) { @@ -120,27 +120,27 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate Credentials credentials = instanceToCredentials.apply(instance1); if (credentials != null) for (RunningInstance instance : reservation) - credentialStore.put(instance.getRegion() + "/" + instance.getId(), credentials); + credentialStore.put("node#" + instance.getRegion() + "/" + instance.getId(), credentials); } @VisibleForTesting Reservation createKeyPairAndSecurityGroupsAsNeededThenRunInstances(String tag, int count, - Template template) { + Template template) { String region = getRegionFromLocationOrNull(template.getLocation()); String zone = getZoneFromLocationOrNull(template.getLocation()); RunInstancesOptions instanceOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, - tag, template); + tag, template); if (EC2TemplateOptions.class.cast(template.getOptions()).isMonitoringEnabled()) instanceOptions.enableMonitoring(); if (logger.isDebugEnabled()) logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count, region, zone, template - .getImage().getProviderId(), instanceOptions.buildFormParameters()); + .getImage().getProviderId(), instanceOptions.buildFormParameters()); return client.getInstanceServices().runInstancesInRegion(region, zone, template.getImage().getProviderId(), 1, - count, instanceOptions); + count, instanceOptions); } } \ No newline at end of file diff --git a/aws/core/src/test/java/org/jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java index c250f99847..5f68fbf41c 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ComputeAndBlobStoreTogetherHappilyLiveTest.java @@ -33,6 +33,7 @@ import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.http.HttpRequest; +import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.Statement; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -82,7 +83,7 @@ public class ComputeAndBlobStoreTogetherHappilyLiveTest extends BlobStoreAndComp // using jclouds ability to detect operating systems before we launch them, we can avoid // the bad practice of assuming everything is ubuntu. - uploadBlob(tag, "openjdk/install", buildScript(defaultOperatingSystem)); + uploadBlob(tag, "openjdk/install", buildScript(defaultOperatingSystem).render(OsFamily.UNIX)); // instead of hard-coding to amazon s3, we can use any blobstore, conceding this test is // configured for amz. Note we are getting temporary access to a private blob. diff --git a/aws/core/src/test/java/org/jclouds/aws/CredentialsStoredInBlobStoreTest.java b/aws/core/src/test/java/org/jclouds/aws/CredentialsStoredInBlobStoreTest.java index 7b09e8fab3..1590caf64a 100644 --- a/aws/core/src/test/java/org/jclouds/aws/CredentialsStoredInBlobStoreTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/CredentialsStoredInBlobStoreTest.java @@ -68,7 +68,7 @@ public class CredentialsStoredInBlobStoreTest { public void testWeCanUseBlobStoreToStoreCredentialsAcrossContexts() throws RunNodesException, IOException { ComputeServiceContext computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar", - ImmutableSet.of(new CredentialStoreModule(credentialsMap))); + ImmutableSet.of(new CredentialStoreModule(credentialsMap))); Set nodes = computeContext.getComputeService().runNodesWithTag("foo", 10); @@ -76,19 +76,19 @@ public class CredentialsStoredInBlobStoreTest { computeContext.close(); // recreate the compute context with the same map and ensure it still works! - computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar", - Collections.singleton(new CredentialStoreModule(credentialsMap))); + computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar", Collections + .singleton(new CredentialStoreModule(credentialsMap))); verifyCredentialsFromNodesAreInContext(nodes, computeContext); } protected void verifyCredentialsFromNodesAreInContext(Set nodes, - ComputeServiceContext computeContext) throws IOException { + ComputeServiceContext computeContext) throws IOException { // verify each node's credential is in the map. assertEquals(computeContext.credentialStore().size(), 10); for (NodeMetadata node : nodes) { - assertEquals(computeContext.credentialStore().get(node.getId()), node.getCredentials()); + assertEquals(computeContext.credentialStore().get("node#" + node.getId()), node.getCredentials()); } // verify the credentials are in the backing store and of a known json format @@ -96,7 +96,7 @@ public class CredentialsStoredInBlobStoreTest { for (Entry entry : credentialsMap.entrySet()) { Credentials credentials = computeContext.credentialStore().get(entry.getKey()); assertEquals(Utils.toStringAndClose(entry.getValue()), String.format( - "{\"identity\":\"%s\",\"credential\":\"%s\"}", credentials.identity, credentials.credential)); + "{\"identity\":\"%s\",\"credential\":\"%s\"}", credentials.identity, credentials.credential)); } } } 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 45bdbf6843..6acab19de3 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,6 +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().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 c5f6ff2e15..da449863fa 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 @@ -82,14 +82,14 @@ public class EC2TemplateBuilderLiveTest { . of(new Log4JLoggingModule()), setupProperties()); Template template = newContext.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL) - .osVersionMatches("10.04").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU).build(); + .osVersionMatches("10.10").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU).build(); System.out.println(template.getHardware()); assert (template.getImage().getProviderId().startsWith("ami-")) : template; - assertEquals(template.getImage().getOperatingSystem().getVersion(), "10.04"); + assertEquals(template.getImage().getOperatingSystem().getVersion(), "10.10"); assertEquals(template.getImage().getOperatingSystem().is64Bit(), false); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); - assertEquals(template.getImage().getVersion(), "20100921"); + assertEquals(template.getImage().getVersion(), "20101027"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(getCores(template.getHardware()), 1.0d); @@ -135,7 +135,7 @@ public class EC2TemplateBuilderLiveTest { Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.8-beta"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.9-beta"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index b1ecab6ad0..8b0b360879 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -75,7 +75,7 @@ public class RunningInstanceToNodeMetadataTest { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet. of(), ImmutableSet . of(), ImmutableSet. of(), ImmutableMap. of( - "us-east-1/i-9slweygo", creds)); + "node#us-east-1/i-9slweygo", creds)); RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml"); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java index 8dde1b4cf5..413c1eea73 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java @@ -92,7 +92,7 @@ public class EC2RunNodesAndAddToSetStrategyTest { return null; } - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings( { "unchecked" }) private void assertRegionAndZoneForLocation(Location location, String region, String zone) { String imageId = "ami1"; String instanceCreatedId = "instance1"; @@ -102,27 +102,26 @@ public class EC2RunNodesAndAddToSetStrategyTest { InstanceClient instanceClient = createMock(InstanceClient.class); RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class); RunningInstance instance = createMock(RunningInstance.class); - Reservation reservation = new Reservation(region, - ImmutableSet. of(), ImmutableSet. of(instance), "ownerId", "requesterId", - "reservationId"); + Reservation reservation = new Reservation(region, ImmutableSet + . of(), ImmutableSet. of(instance), "ownerId", "requesterId", "reservationId"); NodeMetadata nodeMetadata = createMock(NodeMetadata.class); // setup expectations expect(strategy.client.getInstanceServices()).andReturn(instanceClient).atLeastOnce(); expect( - strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, input.tag, - input.template)).andReturn(ec2Options); + strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, input.tag, + input.template)).andReturn(ec2Options); expect(input.template.getLocation()).andReturn(input.location).atLeastOnce(); expect(input.template.getImage()).andReturn(input.image).atLeastOnce(); expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce(); expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn( - (Reservation) reservation); + (Reservation) reservation); expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce(); // simulate a lazy credentials fetch - Credentials creds = new Credentials("foo","bar"); + Credentials creds = new Credentials("foo", "bar"); expect(strategy.instanceToCredentials.apply(instance)).andReturn(creds); expect(instance.getRegion()).andReturn(region); - expect(strategy.credentialStore.put(region + "/" + instanceCreatedId, creds)).andReturn(null); + expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null); expect(strategy.instancePresent.apply(instance)).andReturn(true); expect(input.template.getOptions()).andReturn(input.options).atLeastOnce(); @@ -130,8 +129,8 @@ public class EC2RunNodesAndAddToSetStrategyTest { expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata); expect( - strategy.utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(eq(input.options), - containsNodeMetadata(nodeMetadata), eq(input.nodes), eq(input.badNodes))).andReturn(null); + strategy.utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(eq(input.options), + containsNodeMetadata(nodeMetadata), eq(input.nodes), eq(input.badNodes))).andReturn(null); // replay mocks replay(instanceClient); @@ -154,9 +153,9 @@ public class EC2RunNodesAndAddToSetStrategyTest { } private static final Location REGION_AP_SOUTHEAST_1 = new LocationImpl(LocationScope.REGION, Region.AP_SOUTHEAST_1, - Region.AP_SOUTHEAST_1, new LocationImpl(LocationScope.PROVIDER, "ec2", "ec2", null)); + Region.AP_SOUTHEAST_1, new LocationImpl(LocationScope.PROVIDER, "ec2", "ec2", null)); private static final Location ZONE_AP_SOUTHEAST_1A = new LocationImpl(LocationScope.ZONE, - AvailabilityZone.AP_SOUTHEAST_1A, AvailabilityZone.AP_SOUTHEAST_1A, REGION_AP_SOUTHEAST_1); + AvailabilityZone.AP_SOUTHEAST_1A, AvailabilityZone.AP_SOUTHEAST_1A, REGION_AP_SOUTHEAST_1); // ///////////////////////////////////////////////////////////////////// @SuppressWarnings("unchecked") @@ -214,7 +213,7 @@ public class EC2RunNodesAndAddToSetStrategyTest { Map credentialStore = createMock(Map.class); ComputeUtils utils = createMock(ComputeUtils.class); return new EC2RunNodesAndAddToSetStrategy(client, createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions, - instanceStateRunning, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils); + instanceStateRunning, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils); } private void replayStrategy(EC2RunNodesAndAddToSetStrategy strategy) { diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java index 36b3813a2b..9062ce171c 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java @@ -26,7 +26,6 @@ import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Sets.newTreeSet; import static org.jclouds.compute.ComputeTestUtils.buildScript; import static org.jclouds.compute.ComputeTestUtils.setupKeyPair; -import static org.jclouds.scriptbuilder.domain.Statements.exec; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -89,10 +88,10 @@ public class PlacementGroupClientLiveTest { protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); + + ".credential"); endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + + ".apiversion"); } protected Properties setupProperties() { @@ -110,14 +109,14 @@ public class PlacementGroupClientLiveTest { public void setupClient() throws FileNotFoundException, IOException { setupCredentials(); Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides); + context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet + . of(new Log4JLoggingModule()), overrides); keyPair = setupKeyPair(); client = EC2Client.class.cast(context.getProviderSpecificContext().getApi()); availableTester = new RetryablePredicate(new PlacementGroupAvailable(client), 60, 1, - TimeUnit.SECONDS); + TimeUnit.SECONDS); deletedTester = new RetryablePredicate(new PlacementGroupDeleted(client), 60, 1, TimeUnit.SECONDS); } @@ -126,12 +125,12 @@ public class PlacementGroupClientLiveTest { void testDescribe() { for (String region : newArrayList(Region.US_EAST_1)) { SortedSet allResults = newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region)); + .describePlacementGroupsInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { PlacementGroup group = allResults.last(); SortedSet result = newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region, group.getName())); + .describePlacementGroupsInRegion(region, group.getName())); assertNotNull(result); PlacementGroup compare = result.last(); assertEquals(compare, group); @@ -160,7 +159,7 @@ public class PlacementGroupClientLiveTest { private void verifyPlacementGroup(String groupName) { assert availableTester.apply(new PlacementGroup(Region.US_EAST_1, groupName, "cluster", State.PENDING)) : group; Set oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(null, - groupName); + groupName); assertNotNull(oneResult); assertEquals(oneResult.size(), 1); group = oneResult.iterator().next(); @@ -195,7 +194,7 @@ public class PlacementGroupClientLiveTest { assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17"); template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) - .runScript(exec(buildScript(template.getImage().getOperatingSystem()))); + .runScript(buildScript(template.getImage().getOperatingSystem())); String tag = PREFIX + "cccluster"; context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); @@ -205,7 +204,7 @@ public class PlacementGroupClientLiveTest { NodeMetadata node = getOnlyElement(nodes); getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null, - node.getProviderId()))); + node.getProviderId()))); } catch (RunNodesException e) { System.err.println(e.getNodeErrors().keySet()); diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java index 82d80c1f62..075f9ca51a 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java @@ -36,14 +36,15 @@ public interface ComputeServiceAdapter { /** * {@link ComputeService#runNodesWithTag(String, int, Template)} generates the parameters passed * into this method such that each node in the set has a unique name. - *

- * Your responsibility is to create a node with the underlying library and return after storing - * its credentials in the supplied map. - *

- * Note that it is intentional to return the library native node object, as generic type + * + *

note

It is intentional to return the library native node object, as generic type * {@code N}. If you are not using library-native objects (such as libvirt {@code Domain}) use * {@link JCloudsNativeComputeServiceAdapter} instead. * + *

note

Your responsibility is to create a node with the underlying library and return + * after storing its credentials in the supplied map corresponding to + * {@link ComputeServiceContext#getCredentialStore credentialStore} + * * @param tag * used to aggregate nodes with identical configuration * @param name @@ -52,14 +53,15 @@ public interface ComputeServiceAdapter { * includes {@code imageId}, {@code locationId}, and {@code hardwareId} used to start * the instance. * @param credentialStore - * once the node is started, its login user and password will be encoded based on the - * node {@code id} + * once the node is started, its login user and password must be stored keyed on + * {@code node#id}. * @return library-native representation of a node. * * @see ComputeService#runNodesWithTag(String, int, Template) + * @see ComputeServiceContext#getCredentialStore */ N runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, - Map credentialStore); + Map credentialStore); /** * Hardware profiles describe available cpu, memory, and disk configurations that can be used to diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceContext.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceContext.java index 393ee006e6..78f544eaf3 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceContext.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceContext.java @@ -50,13 +50,26 @@ public interface ComputeServiceContext { /** * retrieves a list of credentials for resources created within this context, keyed on {@code id} - * of the resource. We are testing this approach for resources such as compute nodes, where you - * could access this externally. - * + * of the resource with a namespace prefix (ex. {@code node#}. We are testing this approach for + * resources such as compute nodes, where you could access this externally. + *

+ *

accessing credentials for a node

+ *

+ * the key is in the form {@code node#id}. + *

    + *
  • if the node id is {@code 8}, then the key will be {@code node#8}
  • + *
  • if the node id is {@code us-east-1/i-asdfdas}, then the key will be {@code + * node#us-east-1/i-asdfdas}
  • + *
  • if the node id is {@code http://cloud/instances/1}, then the key will be {@code + * node#http://cloud/instances/1}
  • + *
*/ @Beta Map getCredentialStore(); + /** + * @see ComputeServiceContext#getCredentialStore + */ @Beta Map credentialStore(); diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index 7becc0355c..8dad50f92e 100755 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -177,7 +177,7 @@ public class BaseComputeService implements ComputeService { Map executionExceptions = awaitCompletion(responses, executor, null, logger, "starting nodes"); for (NodeMetadata node : concat(nodes, badNodes.keySet())) if (node.getCredentials() != null) - credentialStore.put("node/" + node.getId(), node.getCredentials()); + credentialStore.put("node#" + node.getId(), node.getCredentials()); if (executionExceptions.size() > 0 || badNodes.size() > 0) { throw new RunNodesException(tag, count, template, nodes, executionExceptions, badNodes); } @@ -227,7 +227,7 @@ public class BaseComputeService implements ComputeService { }, timeouts.nodeRunning, 1000, TimeUnit.MILLISECONDS); boolean successful = tester.apply(id) && (node.get() == null || nodeTerminated.apply(node.get())); if (successful) - credentialStore.remove("node/" + id); + credentialStore.remove("node#" + id); logger.debug("<< destroyed node(%s) success(%s)", id, successful); } diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java index 27d53921d4..d9c8c54aab 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java @@ -63,9 +63,9 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda @Inject public StubComputeServiceAdapter(ConcurrentMap nodes, Supplier location, - @Named("NODE_ID") Provider idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, - @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix, - @org.jclouds.rest.annotations.Provider String providerName) { + @Named("NODE_ID") Provider idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, + @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix, + @org.jclouds.rest.annotations.Provider String providerName) { this.nodes = nodes; this.location = location; this.idProvider = idProvider; @@ -77,7 +77,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda @Override public NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, - Map credentialStore) { + Map credentialStore) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); String id = idProvider.get() + ""; builder.ids(id); @@ -91,8 +91,8 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda builder.privateAddresses(ImmutableSet. of(privateIpPrefix + id)); builder.credentials(new Credentials("root", passwordPrefix + id)); NodeMetadata node = builder.build(); + credentialStore.put("node#" + node.getId(), node.getCredentials()); nodes.put(node.getId(), node); - credentialStore.put(node.getId(), node.getCredentials()); StubComputeServiceDependenciesModule.setState(node, NodeState.RUNNING, 100); return node; } @@ -100,8 +100,8 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda @Override public Iterable listHardwareProfiles() { return ImmutableSet. of(StubComputeServiceDependenciesModule.stub("small", 1, 1740, 160), - StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850), - StubComputeServiceDependenciesModule.stub("large", 8, 15360, 1690)); + StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850), StubComputeServiceDependenciesModule + .stub("large", 8, 15360, 1690)); } @Override @@ -109,34 +109,20 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda Location zone = location.get().getParent(); String parentId = zone.getId(); Credentials defaultCredentials = new Credentials("root", null); - return ImmutableSet - . of( - new ImageBuilder() - .providerId("1") - .name(OsFamily.UBUNTU.name()) - .id(parentId + "/1") - .location(zone) + return ImmutableSet. of(new ImageBuilder().providerId("1").name(OsFamily.UBUNTU.name()) + .id(parentId + "/1").location(zone).operatingSystem( + new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false)) + .description("stub ubuntu 32").defaultCredentials(defaultCredentials).build(), // + new ImageBuilder().providerId("2").name(OsFamily.UBUNTU.name()).id(parentId + "/2").location(zone) .operatingSystem( - new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false)) - .description("stub ubuntu 32").defaultCredentials(defaultCredentials).build(), // - new ImageBuilder() - .providerId("2") - .name(OsFamily.UBUNTU.name()) - .id(parentId + "/2") - .location(zone) - .operatingSystem( - new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true)) + new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true)) .description("stub ubuntu 64").defaultCredentials(defaultCredentials).build(), // - new ImageBuilder() - .providerId("3") - .name(OsFamily.CENTOS.name()) - .id(parentId + "/3") - .location(zone) + new ImageBuilder().providerId("3").name(OsFamily.CENTOS.name()).id(parentId + "/3").location(zone) .operatingSystem( - new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true)) + new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true)) .description("stub centos 64").defaultCredentials(defaultCredentials).build() // - ); + ); } @Override @@ -148,9 +134,9 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda public Iterable listLocations() { Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region", - provider); + provider); return ImmutableSet. of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName - + "zone", region)); + + "zone", region)); } @Override 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 d6ef62cdd8..a298e6c6a1 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 @@ -19,15 +19,8 @@ package org.jclouds.compute.stub.config; -import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.concurrent.SingleThreaded; -import org.jclouds.domain.Location; - -import com.google.inject.TypeLiteral; /** * @@ -43,8 +36,6 @@ public class StubComputeServiceContextModule extends JCloudsNativeStandaloneComp @Override protected void configure() { install(new StubComputeServiceDependenciesModule()); - bind(new TypeLiteral>() { - }).to(StubComputeServiceAdapter.class); super.configure(); } } diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 92a7316fa2..ea73041a88 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -74,6 +74,7 @@ import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.AuthorizationException; +import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; @@ -236,37 +237,11 @@ public abstract class BaseComputeServiceLiveTest { assertEquals(toMatch.getImage(), template.getImage()); } - @Test(enabled = true, dependsOnMethods = "testCompareSizes") - public void testCreateAndRunAService() throws Exception { - - String tag = this.tag + "service"; - try { - client.destroyNodesMatching(withTag(tag)); - } catch (Exception e) { - - } - - 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() - .getOperatingSystem())); - try { - NodeMetadata node = getOnlyElement(client.runNodesWithTag(tag, 1, template)); - - checkHttpGet(node); - } finally { - client.destroyNodesMatching(withTag(tag)); - } - - } - protected void checkHttpGet(NodeMetadata node) { ComputeTestUtils.checkHttpGet(context.utils().http(), node, 8080); } - @Test(enabled = true, dependsOnMethods = "testCreateAndRunAService") + @Test(enabled = true, dependsOnMethods = "testCompareSizes") public void testCreateTwoNodesWithRunScript() throws Exception { try { client.destroyNodesMatching(withTag(tag)); @@ -299,7 +274,7 @@ public abstract class BaseComputeServiceLiveTest { template = buildTemplate(client.templateBuilder()); template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) - .runScript(newStringPayload(buildScript(template.getImage().getOperatingSystem()))); + .runScript(buildScript(template.getImage().getOperatingSystem())); } protected void checkImageIdMatchesTemplate(NodeMetadata node) { @@ -339,14 +314,14 @@ public abstract class BaseComputeServiceLiveTest { public void testCredentialsCache() throws Exception { initializeContextAndClient(); for (NodeMetadata node : nodes) - assert (context.getCredentialStore().get(node.getId()) != null) : "credentials for " + node.getId(); + assert (context.getCredentialStore().get("node#" + node.getId()) != null) : "credentials for " + node.getId(); } protected Map runScriptWithCreds(final String tag, OperatingSystem os, Credentials creds) throws RunScriptOnNodesException { try { - return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(os)), - overrideCredentialsWith(creds).nameTask("runScriptWithCreds")); + return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(os).render( + OsFamily.UNIX)), overrideCredentialsWith(creds).nameTask("runScriptWithCreds")); } catch (SshException e) { throw e; } @@ -358,7 +333,7 @@ public abstract class BaseComputeServiceLiveTest { assertNotNull(node.getTag()); assertEquals(node.getTag(), tag); assertEquals(node.getState(), NodeState.RUNNING); - Credentials fromStore = context.getCredentialStore().get(node.getId()); + Credentials fromStore = context.getCredentialStore().get("node#" + node.getId()); assertEquals(fromStore, node.getCredentials()); assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node; assertNotNull(node.getCredentials()); @@ -413,6 +388,32 @@ public abstract class BaseComputeServiceLiveTest { testGet(); } + @Test(enabled = true, dependsOnMethods = "testReboot") + public void testCreateAndRunAService() throws Exception { + + String tag = this.tag + "service"; + try { + client.destroyNodesMatching(withTag(tag)); + } catch (Exception e) { + + } + + 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() + .getOperatingSystem())); + try { + NodeMetadata node = getOnlyElement(client.runNodesWithTag(tag, 1, template)); + + checkHttpGet(node); + } finally { + client.destroyNodesMatching(withTag(tag)); + } + + } + @Test(enabled = true/* , dependsOnMethods = "testCompareSizes" */) public void testTemplateOptions() throws Exception { TemplateOptions options = new TemplateOptions().withMetadata(); @@ -584,7 +585,7 @@ public abstract class BaseComputeServiceLiveTest { client.destroyNodesMatching(withTag(tag)); for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), withTag(tag))) { assert node.getState() == NodeState.TERMINATED : node; - assertEquals(context.getCredentialStore().get(node.getId()), null); + assertEquals(context.getCredentialStore().get("node#" + node.getId()), null); } } context.close(); diff --git a/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java b/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java index 4a341403a8..5677de6da3 100644 --- a/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java +++ b/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java @@ -19,7 +19,11 @@ package org.jclouds.compute; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.get; import static org.jclouds.util.Utils.checkNotEmpty; +import static org.testng.Assert.assertEquals; + import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -27,18 +31,16 @@ import java.lang.reflect.UndeclaredThrowableException; import java.net.URI; import java.util.Map; import java.util.concurrent.TimeoutException; -import static org.testng.Assert.assertEquals; -import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.predicates.OperatingSystemPredicates; import org.jclouds.rest.HttpClient; +import org.jclouds.scriptbuilder.domain.Statement; import com.google.common.base.Charsets; import com.google.common.collect.ImmutableMap; import com.google.common.io.Files; -import static com.google.common.collect.Iterables.get; /** * utilities helpful in testing compute providers @@ -46,7 +48,7 @@ import static com.google.common.collect.Iterables.get; * @author Adrian Cole */ public class ComputeTestUtils { - public static String buildScript(OperatingSystem os) { + public static Statement buildScript(OperatingSystem os) { if (OperatingSystemPredicates.supportsApt().apply(os)) return RunScriptData.APT_RUN_SCRIPT; else if (OperatingSystemPredicates.supportsYum().apply(os)) diff --git a/compute/src/test/java/org/jclouds/compute/RunScriptData.java b/compute/src/test/java/org/jclouds/compute/RunScriptData.java index 15f9041e7c..9871974813 100644 --- a/compute/src/test/java/org/jclouds/compute/RunScriptData.java +++ b/compute/src/test/java/org/jclouds/compute/RunScriptData.java @@ -19,7 +19,7 @@ package org.jclouds.compute; -import static org.jclouds.compute.util.ComputeServiceUtils.extractTargzIntoDirectory; +import static org.jclouds.compute.util.ComputeServiceUtils.*; import static org.jclouds.scriptbuilder.domain.Statements.exec; import static org.jclouds.scriptbuilder.domain.Statements.interpret; @@ -31,6 +31,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 static org.jclouds.scriptbuilder.domain.Statements.*; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -43,7 +44,7 @@ public class RunScriptData { private static String jbossHome = "/usr/local/jboss"; - public static String installJavaAndCurl(OperatingSystem os) { + public static Statement installJavaAndCurl(OperatingSystem os) { if (os == null || OperatingSystemPredicates.supportsApt().apply(os)) return APT_RUN_SCRIPT; else if (OperatingSystemPredicates.supportsYum().apply(os)) @@ -63,7 +64,7 @@ public class RunScriptData { envVariables, ImmutableList. of( new AuthorizeRSAPublicKey(publicKey), - exec(installJavaAndCurl(os)), + installJavaAndCurl(os), exec("rm -rf /var/cache/apt /usr/lib/vmware-tools"),// jeos hasn't enough room! extractTargzIntoDirectory( URI.create("http://commondatastorage.googleapis.com/jclouds-repo/jboss-as-distribution-6.0.0.20100911-M5.tar.gz"), @@ -74,18 +75,20 @@ public class RunScriptData { return toReturn; } - public static final String APT_RUN_SCRIPT = new StringBuilder()// + public static final Statement APT_RUN_SCRIPT = newStatementList(// + 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("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")// - .append( - "sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")// - .append("which curl || apt-get update -y -qq && apt-get install -f -y -qq --force-yes curl\n")// - .append( - "(which java && java -fullversion 2>&1|egrep -q 1.6 ) || apt-get install -f -y -qq --force-yes openjdk-6-jre\n")// + .append("which curl || apt-get install -f -y -qq --force-yes curl\n")// .append("rm -rf /var/cache/apt /usr/lib/vmware-tools\n")// jeos hasn't enough room! - .toString(); + .append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")// + .toString())); - public static final String YUM_RUN_SCRIPT = new StringBuilder() + public static final Statement YUM_RUN_SCRIPT = newStatementList(// + 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 \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n") // .append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n") // @@ -93,14 +96,12 @@ public class RunScriptData { "echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n")// .append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n")// .append("which curl ||yum --nogpgcheck -y install curl\n")// - .append( - "(which java && java -fullversion 2>&1|egrep -q 1.6 ) || yum --nogpgcheck -y install java-1.6.0-openjdk&&")// - .append("echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")// - .toString(); + .append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")// + .toString())); - public static final String ZYPPER_RUN_SCRIPT = new StringBuilder()// + 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(); + .toString()); } diff --git a/compute/src/test/resources/initscript_with_java.sh b/compute/src/test/resources/initscript_with_java.sh index fb354f897f..0951cb1ac9 100644 --- a/compute/src/test/resources/initscript_with_java.sh +++ b/compute/src/test/resources/initscript_with_java.sh @@ -76,13 +76,12 @@ END_OF_SCRIPT # add desired commands from the user cat >> $INSTANCE_HOME/bootstrap.sh <<'END_OF_SCRIPT' cd $INSTANCE_HOME +(which java && java -fullversion 2>&1|egrep -q 1.6 ) || +curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) echo nameserver 208.67.222.222 >> /etc/resolv.conf -cp /etc/apt/sources.list /etc/apt/sources.list.old -sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list -which curl || apt-get update -y -qq && apt-get install -f -y -qq --force-yes curl -(which java && java -fullversion 2>&1|egrep -q 1.6 ) || apt-get install -f -y -qq --force-yes openjdk-6-jre +which curl || apt-get install -f -y -qq --force-yes curl rm -rf /var/cache/apt /usr/lib/vmware-tools - +echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc mkdir -p ~/.ssh cat >> ~/.ssh/authorized_keys <<'END_OF_FILE' ssh-rsa diff --git a/compute/src/test/resources/initscript_with_jboss.sh b/compute/src/test/resources/initscript_with_jboss.sh index 1640f77670..ae3110bde9 100644 --- a/compute/src/test/resources/initscript_with_jboss.sh +++ b/compute/src/test/resources/initscript_with_jboss.sh @@ -63,13 +63,12 @@ init) ssh-rsa END_OF_FILE chmod 600 ~/.ssh/authorized_keys + (which java && java -fullversion 2>&1|egrep -q 1.6 ) || + curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) echo nameserver 208.67.222.222 >> /etc/resolv.conf - cp /etc/apt/sources.list /etc/apt/sources.list.old - sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list - which curl || apt-get update -y -qq && apt-get install -f -y -qq --force-yes curl - (which java && java -fullversion 2>&1|egrep -q 1.6 ) || apt-get install -f -y -qq --force-yes openjdk-6-jre + which curl || apt-get install -f -y -qq --force-yes curl rm -rf /var/cache/apt /usr/lib/vmware-tools - + echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc rm -rf /var/cache/apt /usr/lib/vmware-tools curl -X GET -s --retry 20 http://commondatastorage.googleapis.com/jclouds-repo/jboss-as-distribution-6.0.0.20100911-M5.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -) mkdir -p /usr/local/jboss diff --git a/compute/src/test/resources/runscript.sh b/compute/src/test/resources/runscript.sh index 760f231c90..ac28804663 100644 --- a/compute/src/test/resources/runscript.sh +++ b/compute/src/test/resources/runscript.sh @@ -76,12 +76,12 @@ END_OF_SCRIPT # add desired commands from the user cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT' cd $INSTANCE_HOME +(which java && java -fullversion 2>&1|egrep -q 1.6 ) || +curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) echo nameserver 208.67.222.222 >> /etc/resolv.conf -cp /etc/apt/sources.list /etc/apt/sources.list.old -sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list -which curl || apt-get update -y -qq && apt-get install -f -y -qq --force-yes curl -(which java && java -fullversion 2>&1|egrep -q 1.6 ) || apt-get install -f -y -qq --force-yes openjdk-6-jre +which curl || apt-get install -f -y -qq --force-yes curl rm -rf /var/cache/apt /usr/lib/vmware-tools +echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc END_OF_SCRIPT diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplier.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplier.java index ee17337bb5..7d8f2fc9f9 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplier.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplier.java @@ -20,6 +20,7 @@ package org.jclouds.gogrid.compute.suppliers; import java.util.Set; +import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Resource; @@ -35,7 +36,6 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.domain.ServerImage; -import org.jclouds.gogrid.util.GoGridUtils; import org.jclouds.logging.Logger; import com.google.common.base.Supplier; @@ -47,7 +47,8 @@ import com.google.common.collect.Sets; */ @Singleton public class GoGridImageSupplier implements Supplier> { - public static final Pattern GOGRID_OS_NAME_PATTERN = Pattern.compile("([a-zA-Z]*)(.*)"); + public static final Pattern GOGRID_OS_PATTERN = Pattern.compile("([a-zA-Z]*).*"); + public static final Pattern GOGRID_VERSION_PATTERN = Pattern.compile(".* ([0-9.]+) .*"); @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) @@ -84,18 +85,29 @@ public class GoGridImageSupplier implements Supplier> { OsFamily osFamily = null; String osName = from.getOs().getName(); String osArch = from.getArchitecture().getDescription(); - String osVersion = null;// TODO + String osVersion = parseVersion(osName); String osDescription = from.getOs().getDescription(); boolean is64Bit = (from.getOs().getName().indexOf("64") != -1 || from.getDescription().indexOf("64") != -1); - String matchedOs = GoGridUtils.parseStringByPatternAndGetNthMatchGroup(osName, GOGRID_OS_NAME_PATTERN, 1); - try { - osFamily = OsFamily.fromValue(matchedOs.toLowerCase()); - } catch (IllegalArgumentException e) { - logger.debug("<< didn't match os(%s)", matchedOs); + Matcher matcher = GOGRID_OS_PATTERN.matcher(from.getName()); + if (matcher.find()) { + try { + osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase()); + } catch (IllegalArgumentException e) { + logger.debug("<< didn't match os(%s)", from.getName()); + } } + // TODO determine DC images are in OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); return os; } + + static String parseVersion(String name) { + Matcher matcher = GOGRID_VERSION_PATTERN.matcher(name); + if (matcher.find()) { + return matcher.group(1); + } + return null; + } } \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java index a12dd02787..195e1f4abe 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java @@ -45,6 +45,7 @@ public class GoGridComputeServiceLiveTest extends BaseComputeServiceLiveTest { public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.3"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assertEquals(defaultTemplate.getLocation().getId(), "1"); assertEquals(getCores(defaultTemplate.getHardware()), 0.5d); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/util/GoGridUtils.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplierTest.java similarity index 50% rename from gogrid/src/main/java/org/jclouds/gogrid/util/GoGridUtils.java rename to gogrid/src/test/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplierTest.java index a43498cb72..a9014d918c 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/util/GoGridUtils.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplierTest.java @@ -17,30 +17,21 @@ * ==================================================================== */ -package org.jclouds.gogrid.util; +package org.jclouds.gogrid.compute.suppliers; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; /** - * @author Oleksiy Yarmula + * + * @author Adrian Cole */ -public class GoGridUtils { +public class GoGridImageSupplierTest { - /** - * Matches nth group or returns null. - * - * @param stringToParse string that the pattern will be applied to - * @param pattern regular expression {@link java.util.regex.Pattern pattern} - * @param nthGroup number of the group to extract / return - * @return matched group or null - */ - public static String parseStringByPatternAndGetNthMatchGroup(String stringToParse, Pattern pattern, int nthGroup) { - Matcher osVersionMatcher = pattern.matcher(stringToParse); - if (osVersionMatcher.find()) { - return osVersionMatcher.group(nthGroup); - } - return null; - } + @Test + public void testParseVersion() { + assertEquals(GoGridImageSupplier.parseVersion("CentOS 5.3 (64-bit)"), "5.3"); + } } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToOperatingSystem.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToOperatingSystem.java index f03c2d6c70..be3f50fb84 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToOperatingSystem.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToOperatingSystem.java @@ -40,7 +40,7 @@ import com.google.common.base.Function; @Singleton public class CloudServersImageToOperatingSystem implements Function { - public static final Pattern RACKSPACE_PATTERN = Pattern.compile("(([^ ]*) .*)"); + public static final Pattern RACKSPACE_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)"); @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) @@ -58,12 +58,14 @@ public class CloudServersImageToOperatingSystem implements osFamily = OsFamily.RHEL; } else if (from.getName().indexOf("Oracle EL") != -1) { osFamily = OsFamily.OEL; - } else if (matcher.find()) { + } + if (matcher.find()) { try { osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase()); } catch (IllegalArgumentException e) { logger.debug("<< didn't match os(%s)", matcher.group(2)); } + osVersion = matcher.group(3); } OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); return os; diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java index 9135be4549..b157f8fa31 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java @@ -115,7 +115,7 @@ public class ServerToNodeMetadata implements Function { builder.state(serverToNodeState.get(from.getStatus())); builder.publicAddresses(from.getAddresses().getPublicAddresses()); builder.privateAddresses(from.getAddresses().getPrivateAddresses()); - builder.credentials(credentialStore.get(from.getId() + "")); + builder.credentials(credentialStore.get("node#" + from.getId())); return builder.build(); } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersAddNodeWithTagStrategy.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersAddNodeWithTagStrategy.java index a22c5fa862..c8ee543bb4 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersAddNodeWithTagStrategy.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersAddNodeWithTagStrategy.java @@ -46,7 +46,7 @@ public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrateg @Inject protected CloudServersAddNodeWithTagStrategy(CloudServersClient client, Map credentialStore, - Function serverToNodeMetadata) { + Function serverToNodeMetadata) { this.client = checkNotNull(client, "client"); this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.serverToNodeMetadata = checkNotNull(serverToNodeMetadata, "serverToNodeMetadata"); @@ -54,9 +54,9 @@ public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrateg @Override public NodeMetadata addNodeWithTag(String tag, String name, Template template) { - Server from = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), - Integer.parseInt(template.getHardware().getProviderId())); - credentialStore.put(from.getId() + "", new Credentials("root", from.getAdminPass())); + Server from = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer + .parseInt(template.getHardware().getProviderId())); + credentialStore.put("node#" + from.getId(), new Credentials("root", from.getAdminPass())); return serverToNodeMetadata.apply(from); } diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java index 0c12caaec7..b45b7c1deb 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java @@ -36,6 +36,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.Constants; +import org.jclouds.domain.Credentials; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payload; import org.jclouds.logging.log4j.config.Log4JLoggingModule; @@ -407,7 +408,7 @@ public class CloudServersClientLiveTest { IPSocket socket = new IPSocket(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0), 22); socketTester.apply(socket); - SshClient client = sshFactory.create(socket, "root", pass); + SshClient client = sshFactory.create(socket, new Credentials("root", pass)); try { client.connect(); Payload etcPasswd = client.get("/etc/jclouds.txt"); @@ -422,7 +423,7 @@ public class CloudServersClientLiveTest { private ExecResponse exec(Server details, String pass, String command) throws IOException { IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0), 22); socketTester.apply(socket); - SshClient client = sshFactory.create(socket, "root", pass); + SshClient client = sshFactory.create(socket, new Credentials("root", pass)); try { client.connect(); return client.exec(command); diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java index 1df4db5c1c..635880da38 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -52,6 +52,7 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToImageTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToImageTest.java index fbfc1ec638..3b2ab4c81d 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToImageTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToImageTest.java @@ -44,7 +44,7 @@ public class CloudServersImageToImageTest { new ImageBuilder() .name("CentOS 5.2") .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true) + new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2").is64Bit(true) .build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null)) .ids("2").version("1286712000000").build()); } diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java index 51b0288450..9c38daec90 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java @@ -68,7 +68,7 @@ public class ServerToNodeMetadataTest { Server server = ParseServerFromJsonResponseTest.parseServer(); ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap - . of("1234", creds), Suppliers.> ofInstance(images), Suppliers + . of("node#1234", creds), Suppliers.> ofInstance(images), Suppliers .ofInstance(provider), Suppliers.> ofInstance(hardwares)); NodeMetadata metadata = parser.apply(server); @@ -123,12 +123,12 @@ public class ServerToNodeMetadataTest { assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")).tag( "NOTAG-sample-server").imageId("2").operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true).build()) - .id("1234").providerId("1234").name("sample-server").location( - new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0", - "e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas", - "description", null))).userMetadata( - ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2").is64Bit( + true).build()).id("1234").providerId("1234").name("sample-server").location( + new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0", + "e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas", + "description", null))).userMetadata( + ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } @@ -152,11 +152,11 @@ public class ServerToNodeMetadataTest { ImmutableList.of(new Processor(1.0, 1.0))).ram(256).volumes( ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true) .bootDevice(true).build())).build()).operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true).build()) - .id("1234").providerId("1234").name("sample-server").location( - new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0", - "e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas", - "description", null))).userMetadata( - ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2").is64Bit( + true).build()).id("1234").providerId("1234").name("sample-server").location( + new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0", + "e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas", + "description", null))).userMetadata( + ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } } \ No newline at end of file diff --git a/rackspace/src/test/resources/log4j.xml b/rackspace/src/test/resources/log4j.xml index ba32e0f097..5b548a0f48 100755 --- a/rackspace/src/test/resources/log4j.xml +++ b/rackspace/src/test/resources/log4j.xml @@ -161,12 +161,12 @@ - + diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index 7013050370..5421e5511f 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -45,7 +45,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return template.hardwareId("MIRO1B").osFamily(UBUNTU).os64Bit(false).imageNameMatches(".*10\\.?04.*"); + return template.hardwareId("MIRO1B").osFamily(UBUNTU).os64Bit(false).osVersionMatches("9.10"); } } diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/functions/ServerToNodeMetadata.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/functions/ServerToNodeMetadata.java index 810b7bf65e..88fee153d2 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/functions/ServerToNodeMetadata.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/functions/ServerToNodeMetadata.java @@ -105,7 +105,7 @@ public class ServerToNodeMetadata implements Function { builder.hardware(null);// TODO builder.state(runningStateToNodeState.get(from.getState())); builder.publicAddresses(getPublicAddresses.apply(from)); - builder.credentials(credentialStore.get(from.getId() + "")); + builder.credentials(credentialStore.get("node#" + from.getId())); return builder.build(); } diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingAddNodeWithTagStrategy.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingAddNodeWithTagStrategy.java index 0b2f39efca..22928ad679 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingAddNodeWithTagStrategy.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingAddNodeWithTagStrategy.java @@ -48,7 +48,7 @@ public class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy @Inject protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client, Map credentialStore, - Function serverToNodeMetadata) { + Function serverToNodeMetadata) { this.client = client; this.credentialStore = credentialStore; this.serverToNodeMetadata = serverToNodeMetadata; @@ -56,12 +56,11 @@ public class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy @Override public NodeMetadata addNodeWithTag(String tag, String name, Template template) { - NewServerResponse serverResponse = client.createServer(name, - checkNotNull(template.getImage().getProviderId(), "imageId"), - checkNotNull(template.getHardware().getProviderId(), "hardwareId")); + NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(), + "imageId"), checkNotNull(template.getHardware().getProviderId(), "hardwareId")); Server from = client.getServer(serverResponse.getServer().getId()); - credentialStore.put(from.getId() + "", new Credentials("root", serverResponse.getNewInstanceRequest() - .getCreateOptions().getPassword())); + credentialStore.put("node#" + from.getId(), new Credentials("root", serverResponse.getNewInstanceRequest() + .getCreateOptions().getPassword())); return serverToNodeMetadata.apply(from); } diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingImageSupplier.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingImageSupplier.java index 05b9d9104b..26b18a63cb 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingImageSupplier.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingImageSupplier.java @@ -46,7 +46,7 @@ import com.google.common.collect.Sets; */ @Singleton public class RimuHostingImageSupplier implements Supplier> { - public static final Pattern RIMU_PATTERN = Pattern.compile("([^0-9]*)(.*)"); + public static final Pattern RIMU_PATTERN = Pattern.compile("([a-zA-Z]+) ?([0-9.]+) .*"); private final RimuHostingClient sync; @Inject @@ -77,23 +77,21 @@ public class RimuHostingImageSupplier implements Supplier> protected OperatingSystem parseOs(final org.jclouds.rimuhosting.miro.domain.Image from) { OsFamily osFamily = null; - String osName = null; + String osName = from.getId(); String osArch = null; String osVersion = null; - String osDescription = from.getId(); + String osDescription = from.getDescription(); boolean is64Bit = from.getId().indexOf("64") != -1; - osDescription = from.getId(); - - Matcher matcher = RIMU_PATTERN.matcher(from.getId()); + Matcher matcher = RIMU_PATTERN.matcher(osDescription); if (matcher.find()) { try { osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase()); + osVersion = matcher.group(2).toLowerCase(); } catch (IllegalArgumentException e) { - logger.debug("<< didn't match os(%s)", matcher.group(2)); + logger.debug("<< didn't match os(%s)", osDescription); } } - OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); - return os; + return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); } } \ No newline at end of file diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java index 6afc1b29c4..7c7a0ea22d 100644 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java @@ -56,15 +56,13 @@ public class RimuHostingClientLiveTest { protected String provider = "rimuhosting"; 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"); - endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); - apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); } protected Properties setupProperties() { @@ -72,8 +70,10 @@ public class RimuHostingClientLiveTest { overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".apiversion", apiversion); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); return overrides; } diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java index 18bc52af10..2116ea9e87 100755 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java @@ -48,6 +48,7 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS"); assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO1B"); diff --git a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/functions/DomainToNodeMetadata.java b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/functions/DomainToNodeMetadata.java index 98907bdfb7..d4b0ced0a4 100644 --- a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/functions/DomainToNodeMetadata.java +++ b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/functions/DomainToNodeMetadata.java @@ -53,16 +53,16 @@ import com.google.common.collect.ImmutableMap; public class DomainToNodeMetadata implements Function { public static final Map domainStateToNodeState = ImmutableMap - . builder() - .put(DomainInfo.DomainState.VIR_DOMAIN_RUNNING, NodeState.RUNNING)// - .put(DomainInfo.DomainState.VIR_DOMAIN_BLOCKED, NodeState.PENDING)// - .put(DomainInfo.DomainState.VIR_DOMAIN_PAUSED, NodeState.SUSPENDED)// - .put(DomainInfo.DomainState.VIR_DOMAIN_SHUTDOWN, NodeState.SUSPENDED)// - .put(DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF, NodeState.SUSPENDED)// - .put(DomainInfo.DomainState.VIR_DOMAIN_CRASHED, NodeState.ERROR)// + . builder().put(DomainInfo.DomainState.VIR_DOMAIN_RUNNING, + NodeState.RUNNING)// + .put(DomainInfo.DomainState.VIR_DOMAIN_BLOCKED, NodeState.PENDING)// + .put(DomainInfo.DomainState.VIR_DOMAIN_PAUSED, NodeState.SUSPENDED)// + .put(DomainInfo.DomainState.VIR_DOMAIN_SHUTDOWN, NodeState.SUSPENDED)// + .put(DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF, NodeState.SUSPENDED)// + .put(DomainInfo.DomainState.VIR_DOMAIN_CRASHED, NodeState.ERROR)// - .put(DomainInfo.DomainState.VIR_DOMAIN_NOSTATE, NodeState.UNRECOGNIZED)// - .build(); + .put(DomainInfo.DomainState.VIR_DOMAIN_NOSTATE, NodeState.UNRECOGNIZED)// + .build(); private final Function findHardwareForDomain; private final FindLocationForDomain findLocationForDomain; @@ -71,7 +71,7 @@ public class DomainToNodeMetadata implements Function { @Inject DomainToNodeMetadata(Map credentialStore, Function findHardwareForDomain, - FindLocationForDomain findLocationForDomain, FindImageForDomain findImageForDomain) { + FindLocationForDomain findLocationForDomain, FindImageForDomain findImageForDomain) { this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.findHardwareForDomain = checkNotNull(findHardwareForDomain, "findHardwareForDomain"); this.findLocationForDomain = checkNotNull(findLocationForDomain, "findLocationForDomain"); @@ -96,7 +96,7 @@ public class DomainToNodeMetadata implements Function { builder.state(domainStateToNodeState.get(from.getInfo().state)); // builder.publicAddresses(ImmutableSet. of(from.publicAddress)); // builder.privateAddresses(ImmutableSet. of(from.privateAddress)); - builder.credentials(credentialStore.get(from.getUUIDString())); + builder.credentials(credentialStore.get("node#" + from.getUUIDString())); } catch (LibvirtException e) { // TODO Auto-generated catch block diff --git a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java index 3c140283a3..22a39ccd78 100644 --- a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java +++ b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java @@ -38,19 +38,19 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter credentialStore) { // create the backend object using parameters from the template. // Domain from = client.createDomainInDC(template.getLocation().getId(), name, // Integer.parseInt(template.getImage().getProviderId()), // Integer.parseInt(template.getHardware().getProviderId())); // store the credentials so that later functions can use them - // credentialStore.put(from.id + "", new Credentials(from.loginUser, from.password)); + // credentialStore.put("node#" + from.id + "", new Credentials(from.loginUser, from.password)); return null; } @Override - public Iterable listHardware() { + public Iterable listHardwareProfiles() { return listNodes(); } diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java index ca21e49616..15ff8b0d15 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java @@ -19,11 +19,14 @@ package org.jclouds.slicehost.compute.config; +import static org.jclouds.compute.domain.OsFamily.UBUNTU; + import java.util.Set; import javax.inject.Singleton; import org.jclouds.compute.config.BaseComputeServiceContextModule; +import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; @@ -31,6 +34,7 @@ import org.jclouds.domain.internal.LocationImpl; import org.jclouds.rest.annotations.Provider; import com.google.common.collect.ImmutableSet; +import com.google.inject.Injector; import com.google.inject.Provides; /** @@ -47,6 +51,11 @@ public class SlicehostComputeServiceContextModule extends BaseComputeServiceCont return new LocationImpl(LocationScope.ZONE, "DFW1", "Dallas, TX", provider); } + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + return template.osFamily(UBUNTU).os64Bit(true); + } + @Provides @Singleton Set provideLocations(Location location) { diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadata.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadata.java index cc678cc0b6..ed602dc4e6 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadata.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadata.java @@ -125,7 +125,7 @@ public class SliceToNodeMetadata implements Function { } })); - builder.credentials(credentialStore.get(from.getId() + "")); + builder.credentials(credentialStore.get("node#" + from.getId())); return builder.build(); } diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToOperatingSystem.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToOperatingSystem.java index 54c76bbe34..a9486f752e 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToOperatingSystem.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToOperatingSystem.java @@ -40,7 +40,7 @@ import com.google.common.base.Function; @Singleton public class SlicehostImageToOperatingSystem implements Function { - public static final Pattern SLICEHOST_PATTERN = Pattern.compile("(([^ ]*) .*)"); + public static final Pattern SLICEHOST_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)"); @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) @@ -52,18 +52,20 @@ public class SlicehostImageToOperatingSystem implements String osArch = null; String osVersion = null; String osDescription = from.getName(); - boolean is64Bit = true; - Matcher matcher = SLICEHOST_PATTERN.matcher(from.getName()); + boolean is64Bit = !from.getName().endsWith("32-bit"); if (from.getName().indexOf("Red Hat EL") != -1) { osFamily = OsFamily.RHEL; } else if (from.getName().indexOf("Oracle EL") != -1) { osFamily = OsFamily.OEL; - } else if (matcher.find()) { + } + Matcher matcher = SLICEHOST_PATTERN.matcher(from.getName()); + if (matcher.find()) { try { osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase()); } catch (IllegalArgumentException e) { logger.debug("<< didn't match os(%s)", matcher.group(2)); } + osVersion = matcher.group(3); } OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); return os; diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostAddNodeWithTagStrategy.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostAddNodeWithTagStrategy.java index 8da557a654..4c3e94f0c6 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostAddNodeWithTagStrategy.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostAddNodeWithTagStrategy.java @@ -57,7 +57,7 @@ public class SlicehostAddNodeWithTagStrategy implements AddNodeWithTagStrategy { public NodeMetadata addNodeWithTag(String tag, String name, Template template) { Slice from = client.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template.getHardware().getProviderId())); - credentialStore.put(from.getId() + "", new Credentials("root", from.getRootPassword())); + credentialStore.put("node#" + from.getId(), new Credentials("root", from.getRootPassword())); return sliceToNodeMetadata.apply(from); } } \ No newline at end of file diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java index 3d2db8d768..05ebe60d0b 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java @@ -48,6 +48,7 @@ public class SlicehostComputeServiceLiveTest extends BaseComputeServiceLiveTest public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); assertEquals(getCores(defaultTemplate.getHardware()), 0.25d); diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadataTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadataTest.java index d03c26a7c2..53d7b29e12 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadataTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadataTest.java @@ -66,7 +66,7 @@ public class SliceToNodeMetadataTest { Slice slice = SliceHandlerTest.parseSlice(); SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState, ImmutableMap - . of("1", creds), Suppliers.> ofInstance(images), Suppliers + . of("node#1", creds), Suppliers.> ofInstance(images), Suppliers .ofInstance(provider), Suppliers.> ofInstance(hardwares)); NodeMetadata metadata = parser.apply(slice); @@ -112,9 +112,9 @@ public class SliceToNodeMetadataTest { assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds") .imageId("2").operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true) - .build()).id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata( - ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2") + .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").location(provider) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } @Test @@ -136,8 +136,8 @@ public class SliceToNodeMetadataTest { ImmutableList.of(new Processor(0.25, 1.0))).ram(256).volumes( ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f).durable(true) .bootDevice(true).build())).build()).operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true) - .build()).id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata( - ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2") + .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").location(provider) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } } \ No newline at end of file diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java index f8c937949b..a02238bcef 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java @@ -42,19 +42,29 @@ public class SlicehostImageToImageTest { Location provider = new LocationImpl(LocationScope.ZONE, "dallas", "description", null); @Test - public void testApplyWhereImageNotFound() throws UnknownHostException { - assertEquals( - convertImage(), - new ImageBuilder() - .name("CentOS 5.2") - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true) - .build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null)) - .ids("2").build()); + public void test() throws UnknownHostException { + assertEquals(convertImage(), new ImageBuilder().name("CentOS 5.2").operatingSystem( + new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2").is64Bit( + true).build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null)).ids( + "2").build()); + } + + @Test + public void test32() throws UnknownHostException { + assertEquals(convertImage("/test_get_image32.xml"), new ImageBuilder().name("Ubuntu 10.10 (maverick) 32-bit") + .operatingSystem( + new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("10.10").description( + "Ubuntu 10.10 (maverick) 32-bit").build()).description( + "Ubuntu 10.10 (maverick) 32-bit").defaultCredentials(new Credentials("root", null)).ids("70") + .build()); } public static Image convertImage() { - org.jclouds.slicehost.domain.Image image = ImageHandlerTest.parseImage(); + return convertImage("/test_get_image.xml"); + } + + public static Image convertImage(String resource) { + org.jclouds.slicehost.domain.Image image = ImageHandlerTest.parseImage(resource); SlicehostImageToImage parser = new SlicehostImageToImage(new SlicehostImageToOperatingSystem()); diff --git a/slicehost/src/test/java/org/jclouds/slicehost/xml/ImageHandlerTest.java b/slicehost/src/test/java/org/jclouds/slicehost/xml/ImageHandlerTest.java index b7f2cd906b..62602c33a6 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/xml/ImageHandlerTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/xml/ImageHandlerTest.java @@ -42,12 +42,16 @@ 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)); + injector.getInstance(ImageHandler.class)); return parser; } public static Image parseImage() { - InputStream is = ImageHandlerTest.class.getResourceAsStream("/test_get_image.xml"); + return parseImage("/test_get_image.xml"); + } + + public static Image parseImage(String resource) { + InputStream is = ImageHandlerTest.class.getResourceAsStream(resource); return createParser().parse(is); } @@ -56,4 +60,9 @@ public class ImageHandlerTest { assertEquals(parseImage(), expects); } + public void test32() { + Image expects = new Image(70, "Ubuntu 10.10 (maverick) 32-bit"); + assertEquals(parseImage("/test_get_image32.xml"), expects); + } + } diff --git a/slicehost/src/test/java/org/jclouds/slicehost/xml/ImagesHandlerTest.java b/slicehost/src/test/java/org/jclouds/slicehost/xml/ImagesHandlerTest.java index cbf83686c7..abfa7c532e 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/xml/ImagesHandlerTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/xml/ImagesHandlerTest.java @@ -41,13 +41,15 @@ public class ImagesHandlerTest extends BaseHandlerTest { ParseSax> createParser() { ParseSax> parser = (ParseSax>) factory.create(injector - .getInstance(ImagesHandler.class)); + .getInstance(ImagesHandler.class)); return parser; } public void test() { InputStream is = getClass().getResourceAsStream("/test_list_images.xml"); - Set expects = ImmutableSet.of(new Image(2, "CentOS 5.2"), new Image(3, "Gentoo 2008.0"), + Set expects = ImmutableSet.of( + + new Image(2, "CentOS 5.2"), new Image(3, "Gentoo 2008.0"), new Image(4, "Debian 5.0 (lenny)"), @@ -63,8 +65,10 @@ public class ImagesHandlerTest extends BaseHandlerTest { new Image(11, "Ubuntu 8.10 (intrepid)"), - new Image(12, "Red Hat EL 5.3"), + new Image(70, "Ubuntu 10.10 (maverick) 32-bit"), + new Image(12, "Red Hat EL 5.3"), + new Image(13, "Fedora 11 (Leonidas)") ); diff --git a/slicehost/src/test/resources/test_get_image32.xml b/slicehost/src/test/resources/test_get_image32.xml new file mode 100644 index 0000000000..bf94c5d172 --- /dev/null +++ b/slicehost/src/test/resources/test_get_image32.xml @@ -0,0 +1,7 @@ + + + + Ubuntu 10.10 (maverick) 32-bit + 70 + + diff --git a/slicehost/src/test/resources/test_list_images.xml b/slicehost/src/test/resources/test_list_images.xml index f87b4e7301..45ec21ece6 100644 --- a/slicehost/src/test/resources/test_list_images.xml +++ b/slicehost/src/test/resources/test_list_images.xml @@ -1,47 +1,51 @@ - - CentOS 5.2 - 2 - - - Gentoo 2008.0 - 3 - - - Debian 5.0 (lenny) - 4 - - - Fedora 10 (Cambridge) - 5 - - - CentOS 5.3 - 7 - - - Ubuntu 9.04 (jaunty) - 8 - - - Arch 2009.02 - 9 - - - Ubuntu 8.04.2 LTS (hardy) - 10 - - - Ubuntu 8.10 (intrepid) - 11 - - - Red Hat EL 5.3 - 12 - - - Fedora 11 (Leonidas) - 13 - + + CentOS 5.2 + 2 + + + Gentoo 2008.0 + 3 + + + Debian 5.0 (lenny) + 4 + + + Fedora 10 (Cambridge) + 5 + + + CentOS 5.3 + 7 + + + Ubuntu 9.04 (jaunty) + 8 + + + Arch 2009.02 + 9 + + + Ubuntu 8.04.2 LTS (hardy) + 10 + + + Ubuntu 8.10 (intrepid) + 11 + + + Ubuntu 10.10 (maverick) 32-bit + 70 + + + Red Hat EL 5.3 + 12 + + + Fedora 11 (Leonidas) + 13 + diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java index 8f2c846a06..d577024927 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java @@ -53,7 +53,7 @@ public class VAppToNodeMetadata implements Function { @Inject protected VAppToNodeMetadata(Map vAppStatusToNodeState, Map credentialStore, - FindLocationForResource findLocationForResourceInVDC, Function hardwareForVApp) { + FindLocationForResource findLocationForResourceInVDC, Function hardwareForVApp) { this.hardwareForVApp = checkNotNull(hardwareForVApp, "hardwareForVApp"); this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC"); this.credentialStore = checkNotNull(credentialStore, "credentialStore"); @@ -73,9 +73,9 @@ public class VAppToNodeMetadata implements Function { builder.publicAddresses(getPublicIpsFromVApp(from)); builder.privateAddresses(getPrivateIpsFromVApp(from)); builder.credentials(getCredentialsFrom(from)); - if (!credentialStore.containsKey(from.getHref().toASCIIString())) - credentialStore.put(from.getHref().toASCIIString(), getCredentialsFrom(from)); - builder.credentials(credentialStore.get(from.getHref().toASCIIString())); + if (!credentialStore.containsKey("node#" + from.getHref().toASCIIString())) + credentialStore.put("node#" + from.getHref().toASCIIString(), getCredentialsFrom(from)); + builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString())); return builder.build(); } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudExpressVAppToNodeMetadata.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudExpressVAppToNodeMetadata.java index 49d0b4a250..06eeb101d6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudExpressVAppToNodeMetadata.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudExpressVAppToNodeMetadata.java @@ -82,7 +82,7 @@ public class VCloudExpressVAppToNodeMetadata implements Function 0) diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TerremarkVCloudExpressVAppToNodeMetadata.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TerremarkVCloudExpressVAppToNodeMetadata.java index d4f7a6d268..7b17baf7a8 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TerremarkVCloudExpressVAppToNodeMetadata.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TerremarkVCloudExpressVAppToNodeMetadata.java @@ -80,11 +80,11 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT if (credentialsMap.containsKey(orgAndName)) { Credentials creds = credentialsMap.get(orgAndName); node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(creds).build(); - credentialStore.put(node.getId(), creds); + credentialStore.put("node#" + node.getId(), creds); } // this is going to need refactoring.. we really need a credential list in the store per // node. - String adminPasswordKey = node.getId() + "/adminPassword"; + String adminPasswordKey = "node#" + node.getId() + "#adminPassword"; if (credentialStore.containsKey(adminPasswordKey)) { node = NodeMetadataBuilder.fromNodeMetadata(node).adminPassword( credentialStore.get(adminPasswordKey).credential).build(); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/CleanupOrphanKeys.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/CleanupOrphanKeys.java index 8e21f5f95a..c137f6196e 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/CleanupOrphanKeys.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/CleanupOrphanKeys.java @@ -65,8 +65,8 @@ public class CleanupOrphanKeys { // TODO refactor so that admin passwords are cached properly, probably as a list value in the // credentialStore for (NodeMetadata node : deadOnes){ - credentialStore.remove(node.getId()); - credentialStore.remove(node.getId() + "/adminPassword"); + credentialStore.remove("node#" + node.getId()); + credentialStore.remove("node#" + node.getId() + "#adminPassword"); } Iterable orgTags = filter(transform(deadOnes, nodeToOrgAndName), notNull()); for (OrgAndName orgTag : orgTags) { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkVCloudAddNodeWithTagStrategy.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkVCloudAddNodeWithTagStrategy.java index 3d103a28f9..0a1789e570 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkVCloudAddNodeWithTagStrategy.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkVCloudAddNodeWithTagStrategy.java @@ -72,7 +72,7 @@ public class TerremarkVCloudAddNodeWithTagStrategy implements AddNodeWithTagStra // this is going to need refactoring.. we really need a credential list in the store per // node. we need to store the credential here explicitly, as there's no connection from a node // in vcloud to the image it was created with. - credentialStore.put(node.getId() + "/adminPassword", new Credentials("root", template.getImage() + credentialStore.put("node#" + node.getId() + "#adminPassword", new Credentials("root", template.getImage() .getAdminPassword())); } return builder.build(); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java index c447161874..0e5d1bd44d 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java @@ -111,7 +111,7 @@ public class TerremarkVCloudComputeClientTest { new TerremarkInstantiateVAppTemplateOptions()); assertEquals(response.getHref().toASCIIString(), "vapp"); - assertEquals(credentialStore.get("vapp"), new Credentials("Administrator", "password")); + assertEquals(credentialStore.get("node#vapp"), new Credentials("Administrator", "password")); verify(vdc); verify(template); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/CleanupOrphanKeysTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/CleanupOrphanKeysTest.java index e972b61747..3f41655e68 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/CleanupOrphanKeysTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/CleanupOrphanKeysTest.java @@ -139,9 +139,9 @@ public class CleanupOrphanKeysTest { } private void expectCleanupCredentialStore(CleanupOrphanKeys strategy, NodeMetadata nodeMetadata) { - expect(nodeMetadata.getId()).andReturn("1").times(2); - expect(strategy.credentialStore.remove("1")).andReturn(null); - expect(strategy.credentialStore.remove("1/adminPassword")).andReturn(null); + expect("node#" + nodeMetadata.getId()).andReturn("1").times(2); + expect(strategy.credentialStore.remove("node#1")).andReturn(null); + expect(strategy.credentialStore.remove("node#1#adminPassword")).andReturn(null); } public void testWhenNoneLeftWithTag() {