fixed credentials so that node creds are prefixed consistently with node#; normalized os version parsing

This commit is contained in:
Adrian Cole 2010-10-27 23:45:30 -07:00
parent cfa9f7f7da
commit 39361c9cbd
58 changed files with 399 additions and 353 deletions

View File

@ -91,7 +91,7 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
builder.id(instance.getRegion() + "/" + providerId); builder.id(instance.getRegion() + "/" + providerId);
String tag = getTagForInstance(instance); String tag = getTagForInstance(instance);
builder.tag(tag); builder.tag(tag);
builder.credentials(credentialStore.get(instance.getRegion() + "/" + providerId)); builder.credentials(credentialStore.get("node#" + instance.getRegion() + "/" + providerId));
builder.state(instanceToNodeState.get(instance.getInstanceState())); builder.state(instanceToNodeState.get(instance.getInstanceState()));
builder.publicAddresses(nullSafeSet(instance.getIpAddress())); builder.publicAddresses(nullSafeSet(instance.getIpAddress()));
builder.privateAddresses(nullSafeSet(instance.getPrivateIpAddress())); builder.privateAddresses(nullSafeSet(instance.getPrivateIpAddress()));

View File

@ -79,12 +79,12 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
@Inject @Inject
EC2RunNodesAndAddToSetStrategy( EC2RunNodesAndAddToSetStrategy(
EC2Client client, EC2Client client,
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions, CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions,
@Named("PRESENT") Predicate<RunningInstance> instancePresent, @Named("PRESENT") Predicate<RunningInstance> instancePresent,
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
Function<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore, Function<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
ComputeUtils utils) { ComputeUtils utils) {
this.client = client; this.client = client;
this.instancePresent = instancePresent; this.instancePresent = instancePresent;
this.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions; this.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions;
@ -96,10 +96,10 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
@Override @Override
public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes, public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes) { Map<NodeMetadata, Exception> badNodes) {
Reservation<? extends RunningInstance> reservation = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(tag, Reservation<? extends RunningInstance> reservation = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(tag,
count, template); count, template);
Iterable<String> ids = transform(reservation, instanceToId); Iterable<String> ids = transform(reservation, instanceToId);
@ -111,8 +111,8 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
populateCredentials(reservation); populateCredentials(reservation);
} }
return utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(template.getOptions(), return utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(template.getOptions(), transform(
transform(reservation, runningInstanceToNodeMetadata), goodNodes, badNodes); reservation, runningInstanceToNodeMetadata), goodNodes, badNodes);
} }
protected void populateCredentials(Reservation<? extends RunningInstance> reservation) { protected void populateCredentials(Reservation<? extends RunningInstance> reservation) {
@ -120,27 +120,27 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
Credentials credentials = instanceToCredentials.apply(instance1); Credentials credentials = instanceToCredentials.apply(instance1);
if (credentials != null) if (credentials != null)
for (RunningInstance instance : reservation) for (RunningInstance instance : reservation)
credentialStore.put(instance.getRegion() + "/" + instance.getId(), credentials); credentialStore.put("node#" + instance.getRegion() + "/" + instance.getId(), credentials);
} }
@VisibleForTesting @VisibleForTesting
Reservation<? extends RunningInstance> createKeyPairAndSecurityGroupsAsNeededThenRunInstances(String tag, int count, Reservation<? extends RunningInstance> createKeyPairAndSecurityGroupsAsNeededThenRunInstances(String tag, int count,
Template template) { Template template) {
String region = getRegionFromLocationOrNull(template.getLocation()); String region = getRegionFromLocationOrNull(template.getLocation());
String zone = getZoneFromLocationOrNull(template.getLocation()); String zone = getZoneFromLocationOrNull(template.getLocation());
RunInstancesOptions instanceOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, RunInstancesOptions instanceOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region,
tag, template); tag, template);
if (EC2TemplateOptions.class.cast(template.getOptions()).isMonitoringEnabled()) if (EC2TemplateOptions.class.cast(template.getOptions()).isMonitoringEnabled())
instanceOptions.enableMonitoring(); instanceOptions.enableMonitoring();
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count, region, zone, template 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, return client.getInstanceServices().runInstancesInRegion(region, zone, template.getImage().getProviderId(), 1,
count, instanceOptions); count, instanceOptions);
} }
} }

View File

@ -33,6 +33,7 @@ import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.domain.Statement;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; 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 // using jclouds ability to detect operating systems before we launch them, we can avoid
// the bad practice of assuming everything is ubuntu. // 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 // 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. // configured for amz. Note we are getting temporary access to a private blob.

View File

@ -68,7 +68,7 @@ public class CredentialsStoredInBlobStoreTest {
public void testWeCanUseBlobStoreToStoreCredentialsAcrossContexts() throws RunNodesException, IOException { public void testWeCanUseBlobStoreToStoreCredentialsAcrossContexts() throws RunNodesException, IOException {
ComputeServiceContext computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar", ComputeServiceContext computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar",
ImmutableSet.of(new CredentialStoreModule(credentialsMap))); ImmutableSet.of(new CredentialStoreModule(credentialsMap)));
Set<? extends NodeMetadata> nodes = computeContext.getComputeService().runNodesWithTag("foo", 10); Set<? extends NodeMetadata> nodes = computeContext.getComputeService().runNodesWithTag("foo", 10);
@ -76,19 +76,19 @@ public class CredentialsStoredInBlobStoreTest {
computeContext.close(); computeContext.close();
// recreate the compute context with the same map and ensure it still works! // recreate the compute context with the same map and ensure it still works!
computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar", computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar", Collections
Collections.singleton(new CredentialStoreModule(credentialsMap))); .singleton(new CredentialStoreModule(credentialsMap)));
verifyCredentialsFromNodesAreInContext(nodes, computeContext); verifyCredentialsFromNodesAreInContext(nodes, computeContext);
} }
protected void verifyCredentialsFromNodesAreInContext(Set<? extends NodeMetadata> nodes, protected void verifyCredentialsFromNodesAreInContext(Set<? extends NodeMetadata> nodes,
ComputeServiceContext computeContext) throws IOException { ComputeServiceContext computeContext) throws IOException {
// verify each node's credential is in the map. // verify each node's credential is in the map.
assertEquals(computeContext.credentialStore().size(), 10); assertEquals(computeContext.credentialStore().size(), 10);
for (NodeMetadata node : nodes) { 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 // verify the credentials are in the backing store and of a known json format
@ -96,7 +96,7 @@ public class CredentialsStoredInBlobStoreTest {
for (Entry<String, InputStream> entry : credentialsMap.entrySet()) { for (Entry<String, InputStream> entry : credentialsMap.entrySet()) {
Credentials credentials = computeContext.credentialStore().get(entry.getKey()); Credentials credentials = computeContext.credentialStore().get(entry.getKey());
assertEquals(Utils.toStringAndClose(entry.getValue()), String.format( assertEquals(Utils.toStringAndClose(entry.getValue()), String.format(
"{\"identity\":\"%s\",\"credential\":\"%s\"}", credentials.identity, credentials.credential)); "{\"identity\":\"%s\",\"credential\":\"%s\"}", credentials.identity, credentials.credential));
} }
} }
} }

View File

@ -90,6 +90,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
protected void assertDefaultWorks() { protected void assertDefaultWorks() {
Template defaultTemplate = client.templateBuilder().build(); Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.9-beta");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }

View File

@ -82,14 +82,14 @@ public class EC2TemplateBuilderLiveTest {
.<Module> of(new Log4JLoggingModule()), setupProperties()); .<Module> of(new Log4JLoggingModule()), setupProperties());
Template template = newContext.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL) 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()); System.out.println(template.getHardware());
assert (template.getImage().getProviderId().startsWith("ami-")) : template; 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().is64Bit(), false);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); 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.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 1.0d); assertEquals(getCores(template.getHardware()), 1.0d);
@ -135,7 +135,7 @@ public class EC2TemplateBuilderLiveTest {
Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); Template defaultTemplate = newContext.getComputeService().templateBuilder().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; 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().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");

View File

@ -75,7 +75,7 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of( .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of(
"us-east-1/i-9slweygo", creds)); "node#us-east-1/i-9slweygo", creds));
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml"); RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");

View File

@ -92,7 +92,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
return null; return null;
} }
@SuppressWarnings({ "unchecked" }) @SuppressWarnings( { "unchecked" })
private void assertRegionAndZoneForLocation(Location location, String region, String zone) { private void assertRegionAndZoneForLocation(Location location, String region, String zone) {
String imageId = "ami1"; String imageId = "ami1";
String instanceCreatedId = "instance1"; String instanceCreatedId = "instance1";
@ -102,27 +102,26 @@ public class EC2RunNodesAndAddToSetStrategyTest {
InstanceClient instanceClient = createMock(InstanceClient.class); InstanceClient instanceClient = createMock(InstanceClient.class);
RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class); RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Reservation<? extends RunningInstance> reservation = new Reservation<RunningInstance>(region, Reservation<? extends RunningInstance> reservation = new Reservation<RunningInstance>(region, ImmutableSet
ImmutableSet.<String> of(), ImmutableSet.<RunningInstance> of(instance), "ownerId", "requesterId", .<String> of(), ImmutableSet.<RunningInstance> of(instance), "ownerId", "requesterId", "reservationId");
"reservationId");
NodeMetadata nodeMetadata = createMock(NodeMetadata.class); NodeMetadata nodeMetadata = createMock(NodeMetadata.class);
// setup expectations // setup expectations
expect(strategy.client.getInstanceServices()).andReturn(instanceClient).atLeastOnce(); expect(strategy.client.getInstanceServices()).andReturn(instanceClient).atLeastOnce();
expect( expect(
strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, input.tag, strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, input.tag,
input.template)).andReturn(ec2Options); input.template)).andReturn(ec2Options);
expect(input.template.getLocation()).andReturn(input.location).atLeastOnce(); expect(input.template.getLocation()).andReturn(input.location).atLeastOnce();
expect(input.template.getImage()).andReturn(input.image).atLeastOnce(); expect(input.template.getImage()).andReturn(input.image).atLeastOnce();
expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce(); expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce();
expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn( expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn(
(Reservation) reservation); (Reservation) reservation);
expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce(); expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
// simulate a lazy credentials fetch // 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(strategy.instanceToCredentials.apply(instance)).andReturn(creds);
expect(instance.getRegion()).andReturn(region); 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(strategy.instancePresent.apply(instance)).andReturn(true);
expect(input.template.getOptions()).andReturn(input.options).atLeastOnce(); expect(input.template.getOptions()).andReturn(input.options).atLeastOnce();
@ -130,8 +129,8 @@ public class EC2RunNodesAndAddToSetStrategyTest {
expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata); expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata);
expect( expect(
strategy.utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(eq(input.options), strategy.utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(eq(input.options),
containsNodeMetadata(nodeMetadata), eq(input.nodes), eq(input.badNodes))).andReturn(null); containsNodeMetadata(nodeMetadata), eq(input.nodes), eq(input.badNodes))).andReturn(null);
// replay mocks // replay mocks
replay(instanceClient); 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, 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, 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") @SuppressWarnings("unchecked")
@ -214,7 +213,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
Map<String, Credentials> credentialStore = createMock(Map.class); Map<String, Credentials> credentialStore = createMock(Map.class);
ComputeUtils utils = createMock(ComputeUtils.class); ComputeUtils utils = createMock(ComputeUtils.class);
return new EC2RunNodesAndAddToSetStrategy(client, createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions, return new EC2RunNodesAndAddToSetStrategy(client, createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions,
instanceStateRunning, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils); instanceStateRunning, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils);
} }
private void replayStrategy(EC2RunNodesAndAddToSetStrategy strategy) { private void replayStrategy(EC2RunNodesAndAddToSetStrategy strategy) {

View File

@ -26,7 +26,6 @@ import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.Sets.newTreeSet;
import static org.jclouds.compute.ComputeTestUtils.buildScript; import static org.jclouds.compute.ComputeTestUtils.buildScript;
import static org.jclouds.compute.ComputeTestUtils.setupKeyPair; 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.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
@ -89,10 +88,10 @@ public class PlacementGroupClientLiveTest {
protected void setupCredentials() { protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential"); + ".credential");
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint");
apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider
+ ".apiversion"); + ".apiversion");
} }
protected Properties setupProperties() { protected Properties setupProperties() {
@ -110,14 +109,14 @@ public class PlacementGroupClientLiveTest {
public void setupClient() throws FileNotFoundException, IOException { public void setupClient() throws FileNotFoundException, IOException {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider, context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides); .<Module> of(new Log4JLoggingModule()), overrides);
keyPair = setupKeyPair(); keyPair = setupKeyPair();
client = EC2Client.class.cast(context.getProviderSpecificContext().getApi()); client = EC2Client.class.cast(context.getProviderSpecificContext().getApi());
availableTester = new RetryablePredicate<PlacementGroup>(new PlacementGroupAvailable(client), 60, 1, availableTester = new RetryablePredicate<PlacementGroup>(new PlacementGroupAvailable(client), 60, 1,
TimeUnit.SECONDS); TimeUnit.SECONDS);
deletedTester = new RetryablePredicate<PlacementGroup>(new PlacementGroupDeleted(client), 60, 1, TimeUnit.SECONDS); deletedTester = new RetryablePredicate<PlacementGroup>(new PlacementGroupDeleted(client), 60, 1, TimeUnit.SECONDS);
} }
@ -126,12 +125,12 @@ public class PlacementGroupClientLiveTest {
void testDescribe() { void testDescribe() {
for (String region : newArrayList(Region.US_EAST_1)) { for (String region : newArrayList(Region.US_EAST_1)) {
SortedSet<PlacementGroup> allResults = newTreeSet(client.getPlacementGroupServices() SortedSet<PlacementGroup> allResults = newTreeSet(client.getPlacementGroupServices()
.describePlacementGroupsInRegion(region)); .describePlacementGroupsInRegion(region));
assertNotNull(allResults); assertNotNull(allResults);
if (allResults.size() >= 1) { if (allResults.size() >= 1) {
PlacementGroup group = allResults.last(); PlacementGroup group = allResults.last();
SortedSet<PlacementGroup> result = newTreeSet(client.getPlacementGroupServices() SortedSet<PlacementGroup> result = newTreeSet(client.getPlacementGroupServices()
.describePlacementGroupsInRegion(region, group.getName())); .describePlacementGroupsInRegion(region, group.getName()));
assertNotNull(result); assertNotNull(result);
PlacementGroup compare = result.last(); PlacementGroup compare = result.last();
assertEquals(compare, group); assertEquals(compare, group);
@ -160,7 +159,7 @@ public class PlacementGroupClientLiveTest {
private void verifyPlacementGroup(String groupName) { private void verifyPlacementGroup(String groupName) {
assert availableTester.apply(new PlacementGroup(Region.US_EAST_1, groupName, "cluster", State.PENDING)) : group; assert availableTester.apply(new PlacementGroup(Region.US_EAST_1, groupName, "cluster", State.PENDING)) : group;
Set<PlacementGroup> oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(null, Set<PlacementGroup> oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(null,
groupName); groupName);
assertNotNull(oneResult); assertNotNull(oneResult);
assertEquals(oneResult.size(), 1); assertEquals(oneResult.size(), 1);
group = oneResult.iterator().next(); group = oneResult.iterator().next();
@ -195,7 +194,7 @@ public class PlacementGroupClientLiveTest {
assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17"); assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17");
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) 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"; String tag = PREFIX + "cccluster";
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
@ -205,7 +204,7 @@ public class PlacementGroupClientLiveTest {
NodeMetadata node = getOnlyElement(nodes); NodeMetadata node = getOnlyElement(nodes);
getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null, getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null,
node.getProviderId()))); node.getProviderId())));
} catch (RunNodesException e) { } catch (RunNodesException e) {
System.err.println(e.getNodeErrors().keySet()); System.err.println(e.getNodeErrors().keySet());

View File

@ -36,14 +36,15 @@ public interface ComputeServiceAdapter<N, H, I, L> {
/** /**
* {@link ComputeService#runNodesWithTag(String, int, Template)} generates the parameters passed * {@link ComputeService#runNodesWithTag(String, int, Template)} generates the parameters passed
* into this method such that each node in the set has a unique name. * into this method such that each node in the set has a unique name.
* <p/> *
* Your responsibility is to create a node with the underlying library and return after storing * <h4>note</h4> It is intentional to return the library native node object, as generic type
* its credentials in the supplied map.
* <p/>
* Note that 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 * {@code N}. If you are not using library-native objects (such as libvirt {@code Domain}) use
* {@link JCloudsNativeComputeServiceAdapter} instead. * {@link JCloudsNativeComputeServiceAdapter} instead.
* *
* <h4>note</h4> 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 * @param tag
* used to aggregate nodes with identical configuration * used to aggregate nodes with identical configuration
* @param name * @param name
@ -52,14 +53,15 @@ public interface ComputeServiceAdapter<N, H, I, L> {
* includes {@code imageId}, {@code locationId}, and {@code hardwareId} used to start * includes {@code imageId}, {@code locationId}, and {@code hardwareId} used to start
* the instance. * the instance.
* @param credentialStore * @param credentialStore
* once the node is started, its login user and password will be encoded based on the * once the node is started, its login user and password must be stored keyed on
* node {@code id} * {@code node#id}.
* @return library-native representation of a node. * @return library-native representation of a node.
* *
* @see ComputeService#runNodesWithTag(String, int, Template) * @see ComputeService#runNodesWithTag(String, int, Template)
* @see ComputeServiceContext#getCredentialStore
*/ */
N runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, N runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore); Map<String, Credentials> credentialStore);
/** /**
* Hardware profiles describe available cpu, memory, and disk configurations that can be used to * Hardware profiles describe available cpu, memory, and disk configurations that can be used to

View File

@ -50,13 +50,26 @@ public interface ComputeServiceContext {
/** /**
* retrieves a list of credentials for resources created within this context, keyed on {@code id} * 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 * of the resource with a namespace prefix (ex. {@code node#}. We are testing this approach for
* could access this externally. * resources such as compute nodes, where you could access this externally.
* * <p/>
* <h4>accessing credentials for a node</h4>
* <p/>
* the key is in the form {@code node#id}.
* <ul>
* <li>if the node id is {@code 8}, then the key will be {@code node#8}</li>
* <li>if the node id is {@code us-east-1/i-asdfdas}, then the key will be {@code
* node#us-east-1/i-asdfdas}</li>
* <li>if the node id is {@code http://cloud/instances/1}, then the key will be {@code
* node#http://cloud/instances/1}</li>
* </ul>
*/ */
@Beta @Beta
Map<String, Credentials> getCredentialStore(); Map<String, Credentials> getCredentialStore();
/**
* @see ComputeServiceContext#getCredentialStore
*/
@Beta @Beta
Map<String, Credentials> credentialStore(); Map<String, Credentials> credentialStore();

View File

@ -177,7 +177,7 @@ public class BaseComputeService implements ComputeService {
Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger, "starting nodes"); Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger, "starting nodes");
for (NodeMetadata node : concat(nodes, badNodes.keySet())) for (NodeMetadata node : concat(nodes, badNodes.keySet()))
if (node.getCredentials() != null) 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) { if (executionExceptions.size() > 0 || badNodes.size() > 0) {
throw new RunNodesException(tag, count, template, nodes, executionExceptions, badNodes); throw new RunNodesException(tag, count, template, nodes, executionExceptions, badNodes);
} }
@ -227,7 +227,7 @@ public class BaseComputeService implements ComputeService {
}, timeouts.nodeRunning, 1000, TimeUnit.MILLISECONDS); }, timeouts.nodeRunning, 1000, TimeUnit.MILLISECONDS);
boolean successful = tester.apply(id) && (node.get() == null || nodeTerminated.apply(node.get())); boolean successful = tester.apply(id) && (node.get() == null || nodeTerminated.apply(node.get()));
if (successful) if (successful)
credentialStore.remove("node/" + id); credentialStore.remove("node#" + id);
logger.debug("<< destroyed node(%s) success(%s)", id, successful); logger.debug("<< destroyed node(%s) success(%s)", id, successful);
} }

View File

@ -63,9 +63,9 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
@Inject @Inject
public StubComputeServiceAdapter(ConcurrentMap<String, NodeMetadata> nodes, Supplier<Location> location, public StubComputeServiceAdapter(ConcurrentMap<String, NodeMetadata> nodes, Supplier<Location> location,
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, @Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix, @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix,
@org.jclouds.rest.annotations.Provider String providerName) { @org.jclouds.rest.annotations.Provider String providerName) {
this.nodes = nodes; this.nodes = nodes;
this.location = location; this.location = location;
this.idProvider = idProvider; this.idProvider = idProvider;
@ -77,7 +77,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
@Override @Override
public NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, public NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore) { Map<String, Credentials> credentialStore) {
NodeMetadataBuilder builder = new NodeMetadataBuilder(); NodeMetadataBuilder builder = new NodeMetadataBuilder();
String id = idProvider.get() + ""; String id = idProvider.get() + "";
builder.ids(id); builder.ids(id);
@ -91,8 +91,8 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
builder.privateAddresses(ImmutableSet.<String> of(privateIpPrefix + id)); builder.privateAddresses(ImmutableSet.<String> of(privateIpPrefix + id));
builder.credentials(new Credentials("root", passwordPrefix + id)); builder.credentials(new Credentials("root", passwordPrefix + id));
NodeMetadata node = builder.build(); NodeMetadata node = builder.build();
credentialStore.put("node#" + node.getId(), node.getCredentials());
nodes.put(node.getId(), node); nodes.put(node.getId(), node);
credentialStore.put(node.getId(), node.getCredentials());
StubComputeServiceDependenciesModule.setState(node, NodeState.RUNNING, 100); StubComputeServiceDependenciesModule.setState(node, NodeState.RUNNING, 100);
return node; return node;
} }
@ -100,8 +100,8 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
@Override @Override
public Iterable<Hardware> listHardwareProfiles() { public Iterable<Hardware> listHardwareProfiles() {
return ImmutableSet.<Hardware> of(StubComputeServiceDependenciesModule.stub("small", 1, 1740, 160), return ImmutableSet.<Hardware> of(StubComputeServiceDependenciesModule.stub("small", 1, 1740, 160),
StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850), StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850), StubComputeServiceDependenciesModule
StubComputeServiceDependenciesModule.stub("large", 8, 15360, 1690)); .stub("large", 8, 15360, 1690));
} }
@Override @Override
@ -109,34 +109,20 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
Location zone = location.get().getParent(); Location zone = location.get().getParent();
String parentId = zone.getId(); String parentId = zone.getId();
Credentials defaultCredentials = new Credentials("root", null); Credentials defaultCredentials = new Credentials("root", null);
return ImmutableSet return ImmutableSet.<Image> of(new ImageBuilder().providerId("1").name(OsFamily.UBUNTU.name())
.<Image> of( .id(parentId + "/1").location(zone).operatingSystem(
new ImageBuilder() new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false))
.providerId("1") .description("stub ubuntu 32").defaultCredentials(defaultCredentials).build(), //
.name(OsFamily.UBUNTU.name()) new ImageBuilder().providerId("2").name(OsFamily.UBUNTU.name()).id(parentId + "/2").location(zone)
.id(parentId + "/1")
.location(zone)
.operatingSystem( .operatingSystem(
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false)) new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true))
.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))
.description("stub ubuntu 64").defaultCredentials(defaultCredentials).build(), // .description("stub ubuntu 64").defaultCredentials(defaultCredentials).build(), //
new ImageBuilder() new ImageBuilder().providerId("3").name(OsFamily.CENTOS.name()).id(parentId + "/3").location(zone)
.providerId("3")
.name(OsFamily.CENTOS.name())
.id(parentId + "/3")
.location(zone)
.operatingSystem( .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() // .description("stub centos 64").defaultCredentials(defaultCredentials).build() //
); );
} }
@Override @Override
@ -148,9 +134,9 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
public Iterable<Location> listLocations() { public Iterable<Location> listLocations() {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region", Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region",
provider); provider);
return ImmutableSet.<Location> of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName return ImmutableSet.<Location> of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName
+ "zone", region)); + "zone", region));
} }
@Override @Override

View File

@ -19,15 +19,8 @@
package org.jclouds.compute.stub.config; package org.jclouds.compute.stub.config;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule; 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.concurrent.SingleThreaded;
import org.jclouds.domain.Location;
import com.google.inject.TypeLiteral;
/** /**
* *
@ -43,8 +36,6 @@ public class StubComputeServiceContextModule extends JCloudsNativeStandaloneComp
@Override @Override
protected void configure() { protected void configure() {
install(new StubComputeServiceDependenciesModule()); install(new StubComputeServiceDependenciesModule());
bind(new TypeLiteral<ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>>() {
}).to(StubComputeServiceAdapter.class);
super.configure(); super.configure();
} }
} }

View File

@ -74,6 +74,7 @@ import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshException;
@ -236,37 +237,11 @@ public abstract class BaseComputeServiceLiveTest {
assertEquals(toMatch.getImage(), template.getImage()); 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) { protected void checkHttpGet(NodeMetadata node) {
ComputeTestUtils.checkHttpGet(context.utils().http(), node, 8080); ComputeTestUtils.checkHttpGet(context.utils().http(), node, 8080);
} }
@Test(enabled = true, dependsOnMethods = "testCreateAndRunAService") @Test(enabled = true, dependsOnMethods = "testCompareSizes")
public void testCreateTwoNodesWithRunScript() throws Exception { public void testCreateTwoNodesWithRunScript() throws Exception {
try { try {
client.destroyNodesMatching(withTag(tag)); client.destroyNodesMatching(withTag(tag));
@ -299,7 +274,7 @@ public abstract class BaseComputeServiceLiveTest {
template = buildTemplate(client.templateBuilder()); template = buildTemplate(client.templateBuilder());
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) 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) { protected void checkImageIdMatchesTemplate(NodeMetadata node) {
@ -339,14 +314,14 @@ public abstract class BaseComputeServiceLiveTest {
public void testCredentialsCache() throws Exception { public void testCredentialsCache() throws Exception {
initializeContextAndClient(); initializeContextAndClient();
for (NodeMetadata node : nodes) 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<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String tag, OperatingSystem os, protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String tag, OperatingSystem os,
Credentials creds) throws RunScriptOnNodesException { Credentials creds) throws RunScriptOnNodesException {
try { try {
return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(os)), return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(os).render(
overrideCredentialsWith(creds).nameTask("runScriptWithCreds")); OsFamily.UNIX)), overrideCredentialsWith(creds).nameTask("runScriptWithCreds"));
} catch (SshException e) { } catch (SshException e) {
throw e; throw e;
} }
@ -358,7 +333,7 @@ public abstract class BaseComputeServiceLiveTest {
assertNotNull(node.getTag()); assertNotNull(node.getTag());
assertEquals(node.getTag(), tag); assertEquals(node.getTag(), tag);
assertEquals(node.getState(), NodeState.RUNNING); assertEquals(node.getState(), NodeState.RUNNING);
Credentials fromStore = context.getCredentialStore().get(node.getId()); Credentials fromStore = context.getCredentialStore().get("node#" + node.getId());
assertEquals(fromStore, node.getCredentials()); assertEquals(fromStore, node.getCredentials());
assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node; assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node;
assertNotNull(node.getCredentials()); assertNotNull(node.getCredentials());
@ -413,6 +388,32 @@ public abstract class BaseComputeServiceLiveTest {
testGet(); 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" */) @Test(enabled = true/* , dependsOnMethods = "testCompareSizes" */)
public void testTemplateOptions() throws Exception { public void testTemplateOptions() throws Exception {
TemplateOptions options = new TemplateOptions().withMetadata(); TemplateOptions options = new TemplateOptions().withMetadata();
@ -584,7 +585,7 @@ public abstract class BaseComputeServiceLiveTest {
client.destroyNodesMatching(withTag(tag)); client.destroyNodesMatching(withTag(tag));
for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), withTag(tag))) { for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), withTag(tag))) {
assert node.getState() == NodeState.TERMINATED : node; assert node.getState() == NodeState.TERMINATED : node;
assertEquals(context.getCredentialStore().get(node.getId()), null); assertEquals(context.getCredentialStore().get("node#" + node.getId()), null);
} }
} }
context.close(); context.close();

View File

@ -19,7 +19,11 @@
package org.jclouds.compute; 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.jclouds.util.Utils.checkNotEmpty;
import static org.testng.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -27,18 +31,16 @@ import java.lang.reflect.UndeclaredThrowableException;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeoutException; 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.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.predicates.OperatingSystemPredicates; import org.jclouds.compute.predicates.OperatingSystemPredicates;
import org.jclouds.rest.HttpClient; import org.jclouds.rest.HttpClient;
import org.jclouds.scriptbuilder.domain.Statement;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files; import com.google.common.io.Files;
import static com.google.common.collect.Iterables.get;
/** /**
* utilities helpful in testing compute providers * utilities helpful in testing compute providers
@ -46,7 +48,7 @@ import static com.google.common.collect.Iterables.get;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class ComputeTestUtils { public class ComputeTestUtils {
public static String buildScript(OperatingSystem os) { public static Statement buildScript(OperatingSystem os) {
if (OperatingSystemPredicates.supportsApt().apply(os)) if (OperatingSystemPredicates.supportsApt().apply(os))
return RunScriptData.APT_RUN_SCRIPT; return RunScriptData.APT_RUN_SCRIPT;
else if (OperatingSystemPredicates.supportsYum().apply(os)) else if (OperatingSystemPredicates.supportsYum().apply(os))

View File

@ -19,7 +19,7 @@
package org.jclouds.compute; 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.exec;
import static org.jclouds.scriptbuilder.domain.Statements.interpret; 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.InitBuilder;
import org.jclouds.scriptbuilder.domain.AuthorizeRSAPublicKey; import org.jclouds.scriptbuilder.domain.AuthorizeRSAPublicKey;
import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.domain.Statement;
import static org.jclouds.scriptbuilder.domain.Statements.*;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -43,7 +44,7 @@ public class RunScriptData {
private static String jbossHome = "/usr/local/jboss"; 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)) if (os == null || OperatingSystemPredicates.supportsApt().apply(os))
return APT_RUN_SCRIPT; return APT_RUN_SCRIPT;
else if (OperatingSystemPredicates.supportsYum().apply(os)) else if (OperatingSystemPredicates.supportsYum().apply(os))
@ -63,7 +64,7 @@ public class RunScriptData {
envVariables, envVariables,
ImmutableList.<Statement> of( ImmutableList.<Statement> of(
new AuthorizeRSAPublicKey(publicKey), new AuthorizeRSAPublicKey(publicKey),
exec(installJavaAndCurl(os)), installJavaAndCurl(os),
exec("rm -rf /var/cache/apt /usr/lib/vmware-tools"),// jeos hasn't enough room! exec("rm -rf /var/cache/apt /usr/lib/vmware-tools"),// jeos hasn't enough room!
extractTargzIntoDirectory( extractTargzIntoDirectory(
URI.create("http://commondatastorage.googleapis.com/jclouds-repo/jboss-as-distribution-6.0.0.20100911-M5.tar.gz"), 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; 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("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
.append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")// .append("which curl || apt-get install -f -y -qq --force-yes curl\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("rm -rf /var/cache/apt /usr/lib/vmware-tools\n")// jeos hasn't enough room! .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 nameserver 208.67.222.222 >> /etc/resolv.conf\n") //
.append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n") // .append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n") //
.append("echo \"name=jdkrepository\" >> /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")// "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("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n")//
.append("which curl ||yum --nogpgcheck -y install curl\n")// .append("which curl ||yum --nogpgcheck -y install curl\n")//
.append( .append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")//
"(which java && java -fullversion 2>&1|egrep -q 1.6 ) || yum --nogpgcheck -y install java-1.6.0-openjdk&&")// .toString()));
.append("echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")//
.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("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
.append("which curl || zypper install curl\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")// .append("(which java && java -fullversion 2>&1|egrep -q 1.6 ) || zypper install java-1.6.0-openjdk\n")//
.toString(); .toString());
} }

View File

@ -76,13 +76,12 @@ END_OF_SCRIPT
# add desired commands from the user # add desired commands from the user
cat >> $INSTANCE_HOME/bootstrap.sh <<'END_OF_SCRIPT' cat >> $INSTANCE_HOME/bootstrap.sh <<'END_OF_SCRIPT'
cd $INSTANCE_HOME 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 echo nameserver 208.67.222.222 >> /etc/resolv.conf
cp /etc/apt/sources.list /etc/apt/sources.list.old which curl || apt-get install -f -y -qq --force-yes curl
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
rm -rf /var/cache/apt /usr/lib/vmware-tools rm -rf /var/cache/apt /usr/lib/vmware-tools
echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc
mkdir -p ~/.ssh mkdir -p ~/.ssh
cat >> ~/.ssh/authorized_keys <<'END_OF_FILE' cat >> ~/.ssh/authorized_keys <<'END_OF_FILE'
ssh-rsa ssh-rsa

View File

@ -63,13 +63,12 @@ init)
ssh-rsa ssh-rsa
END_OF_FILE END_OF_FILE
chmod 600 ~/.ssh/authorized_keys 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 echo nameserver 208.67.222.222 >> /etc/resolv.conf
cp /etc/apt/sources.list /etc/apt/sources.list.old which curl || apt-get install -f -y -qq --force-yes curl
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
rm -rf /var/cache/apt /usr/lib/vmware-tools 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 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 -) 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 mkdir -p /usr/local/jboss

View File

@ -76,12 +76,12 @@ END_OF_SCRIPT
# add desired commands from the user # add desired commands from the user
cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT' cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT'
cd $INSTANCE_HOME 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 echo nameserver 208.67.222.222 >> /etc/resolv.conf
cp /etc/apt/sources.list /etc/apt/sources.list.old which curl || apt-get install -f -y -qq --force-yes curl
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
rm -rf /var/cache/apt /usr/lib/vmware-tools rm -rf /var/cache/apt /usr/lib/vmware-tools
echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc
END_OF_SCRIPT END_OF_SCRIPT

View File

@ -20,6 +20,7 @@
package org.jclouds.gogrid.compute.suppliers; package org.jclouds.gogrid.compute.suppliers;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -35,7 +36,6 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.domain.ServerImage; import org.jclouds.gogrid.domain.ServerImage;
import org.jclouds.gogrid.util.GoGridUtils;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -47,7 +47,8 @@ import com.google.common.collect.Sets;
*/ */
@Singleton @Singleton
public class GoGridImageSupplier implements Supplier<Set<? extends Image>> { public class GoGridImageSupplier implements Supplier<Set<? extends Image>> {
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 @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -84,18 +85,29 @@ public class GoGridImageSupplier implements Supplier<Set<? extends Image>> {
OsFamily osFamily = null; OsFamily osFamily = null;
String osName = from.getOs().getName(); String osName = from.getOs().getName();
String osArch = from.getArchitecture().getDescription(); String osArch = from.getArchitecture().getDescription();
String osVersion = null;// TODO String osVersion = parseVersion(osName);
String osDescription = from.getOs().getDescription(); String osDescription = from.getOs().getDescription();
boolean is64Bit = (from.getOs().getName().indexOf("64") != -1 || from.getDescription().indexOf("64") != -1); boolean is64Bit = (from.getOs().getName().indexOf("64") != -1 || from.getDescription().indexOf("64") != -1);
String matchedOs = GoGridUtils.parseStringByPatternAndGetNthMatchGroup(osName, GOGRID_OS_NAME_PATTERN, 1); Matcher matcher = GOGRID_OS_PATTERN.matcher(from.getName());
try { if (matcher.find()) {
osFamily = OsFamily.fromValue(matchedOs.toLowerCase()); try {
} catch (IllegalArgumentException e) { osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase());
logger.debug("<< didn't match os(%s)", matchedOs); } catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", from.getName());
}
} }
// TODO determine DC images are in // TODO determine DC images are in
OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
return os; return os;
} }
static String parseVersion(String name) {
Matcher matcher = GOGRID_VERSION_PATTERN.matcher(name);
if (matcher.find()) {
return matcher.group(1);
}
return null;
}
} }

View File

@ -45,6 +45,7 @@ public class GoGridComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public void testTemplateBuilder() { public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build(); Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.3");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(defaultTemplate.getLocation().getId(), "1"); assertEquals(defaultTemplate.getLocation().getId(), "1");
assertEquals(getCores(defaultTemplate.getHardware()), 0.5d); assertEquals(getCores(defaultTemplate.getHardware()), 0.5d);

View File

@ -17,30 +17,21 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.gogrid.util; package org.jclouds.gogrid.compute.suppliers;
import java.util.regex.Matcher; import static org.testng.Assert.assertEquals;
import java.util.regex.Pattern;
import org.testng.annotations.Test;
/** /**
* @author Oleksiy Yarmula *
* @author Adrian Cole
*/ */
public class GoGridUtils { public class GoGridImageSupplierTest {
/** @Test
* Matches nth group or returns null. public void testParseVersion() {
* assertEquals(GoGridImageSupplier.parseVersion("CentOS 5.3 (64-bit)"), "5.3");
* @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;
}
} }

View File

@ -40,7 +40,7 @@ import com.google.common.base.Function;
@Singleton @Singleton
public class CloudServersImageToOperatingSystem implements public class CloudServersImageToOperatingSystem implements
Function<org.jclouds.rackspace.cloudservers.domain.Image, OperatingSystem> { Function<org.jclouds.rackspace.cloudservers.domain.Image, OperatingSystem> {
public static final Pattern RACKSPACE_PATTERN = Pattern.compile("(([^ ]*) .*)"); public static final Pattern RACKSPACE_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -58,12 +58,14 @@ public class CloudServersImageToOperatingSystem implements
osFamily = OsFamily.RHEL; osFamily = OsFamily.RHEL;
} else if (from.getName().indexOf("Oracle EL") != -1) { } else if (from.getName().indexOf("Oracle EL") != -1) {
osFamily = OsFamily.OEL; osFamily = OsFamily.OEL;
} else if (matcher.find()) { }
if (matcher.find()) {
try { try {
osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase()); osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", matcher.group(2)); logger.debug("<< didn't match os(%s)", matcher.group(2));
} }
osVersion = matcher.group(3);
} }
OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
return os; return os;

View File

@ -115,7 +115,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
builder.state(serverToNodeState.get(from.getStatus())); builder.state(serverToNodeState.get(from.getStatus()));
builder.publicAddresses(from.getAddresses().getPublicAddresses()); builder.publicAddresses(from.getAddresses().getPublicAddresses());
builder.privateAddresses(from.getAddresses().getPrivateAddresses()); builder.privateAddresses(from.getAddresses().getPrivateAddresses());
builder.credentials(credentialStore.get(from.getId() + "")); builder.credentials(credentialStore.get("node#" + from.getId()));
return builder.build(); return builder.build();
} }

View File

@ -46,7 +46,7 @@ public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrateg
@Inject @Inject
protected CloudServersAddNodeWithTagStrategy(CloudServersClient client, Map<String, Credentials> credentialStore, protected CloudServersAddNodeWithTagStrategy(CloudServersClient client, Map<String, Credentials> credentialStore,
Function<Server, NodeMetadata> serverToNodeMetadata) { Function<Server, NodeMetadata> serverToNodeMetadata) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.serverToNodeMetadata = checkNotNull(serverToNodeMetadata, "serverToNodeMetadata"); this.serverToNodeMetadata = checkNotNull(serverToNodeMetadata, "serverToNodeMetadata");
@ -54,9 +54,9 @@ public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrateg
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata addNodeWithTag(String tag, String name, Template template) {
Server from = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), Server from = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer
Integer.parseInt(template.getHardware().getProviderId())); .parseInt(template.getHardware().getProviderId()));
credentialStore.put(from.getId() + "", new Credentials("root", from.getAdminPass())); credentialStore.put("node#" + from.getId(), new Credentials("root", from.getAdminPass()));
return serverToNodeMetadata.apply(from); return serverToNodeMetadata.apply(from);
} }

View File

@ -36,6 +36,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; 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); IPSocket socket = new IPSocket(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0), 22);
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, "root", pass); SshClient client = sshFactory.create(socket, new Credentials("root", pass));
try { try {
client.connect(); client.connect();
Payload etcPasswd = client.get("/etc/jclouds.txt"); 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 { private ExecResponse exec(Server details, String pass, String command) throws IOException {
IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0), 22); IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0), 22);
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, "root", pass); SshClient client = sshFactory.create(socket, new Credentials("root", pass));
try { try {
client.connect(); client.connect();
return client.exec(command); return client.exec(command);

View File

@ -52,6 +52,7 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe
public void testTemplateBuilder() { public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build(); Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); assertEquals(defaultTemplate.getLocation().getId(), "DFW1");
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);

View File

@ -44,7 +44,7 @@ public class CloudServersImageToImageTest {
new ImageBuilder() new ImageBuilder()
.name("CentOS 5.2") .name("CentOS 5.2")
.operatingSystem( .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)) .build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null))
.ids("2").version("1286712000000").build()); .ids("2").version("1286712000000").build());
} }

View File

@ -68,7 +68,7 @@ public class ServerToNodeMetadataTest {
Server server = ParseServerFromJsonResponseTest.parseServer(); Server server = ParseServerFromJsonResponseTest.parseServer();
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
.<String, Credentials> of("1234", creds), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers .<String, Credentials> of("node#1234", creds), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares)); .ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
NodeMetadata metadata = parser.apply(server); NodeMetadata metadata = parser.apply(server);
@ -123,12 +123,12 @@ public class ServerToNodeMetadataTest {
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( 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( ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")).tag(
"NOTAG-sample-server").imageId("2").operatingSystem( "NOTAG-sample-server").imageId("2").operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true).build()) new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2").is64Bit(
.id("1234").providerId("1234").name("sample-server").location( true).build()).id("1234").providerId("1234").name("sample-server").location(
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas", "e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
"description", null))).userMetadata( "description", null))).userMetadata(
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); 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 Processor(1.0, 1.0))).ram(256).volumes(
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true) ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true)
.bootDevice(true).build())).build()).operatingSystem( .bootDevice(true).build())).build()).operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true).build()) new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2").is64Bit(
.id("1234").providerId("1234").name("sample-server").location( true).build()).id("1234").providerId("1234").name("sample-server").location(
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas", "e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
"description", null))).userMetadata( "description", null))).userMetadata(
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
} }
} }

View File

@ -161,12 +161,12 @@
<category name="jclouds.ssh"> <category name="jclouds.ssh">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCSSH" /> <appender-ref ref="ASYNCSSH" />
</category><!-- </category>
<category name="jclouds.wire"> <category name="jclouds.wire">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" /> <appender-ref ref="ASYNCWIRE" />
</category> </category>
--><category name="jclouds.blobstore"> <category name="jclouds.blobstore">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCBLOBSTORE" /> <appender-ref ref="ASYNCBLOBSTORE" />
</category> </category>

View File

@ -45,7 +45,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo
@Override @Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { 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");
} }
} }

View File

@ -105,7 +105,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
builder.hardware(null);// TODO builder.hardware(null);// TODO
builder.state(runningStateToNodeState.get(from.getState())); builder.state(runningStateToNodeState.get(from.getState()));
builder.publicAddresses(getPublicAddresses.apply(from)); builder.publicAddresses(getPublicAddresses.apply(from));
builder.credentials(credentialStore.get(from.getId() + "")); builder.credentials(credentialStore.get("node#" + from.getId()));
return builder.build(); return builder.build();
} }

View File

@ -48,7 +48,7 @@ public class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy
@Inject @Inject
protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client, Map<String, Credentials> credentialStore, protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client, Map<String, Credentials> credentialStore,
Function<Server, NodeMetadata> serverToNodeMetadata) { Function<Server, NodeMetadata> serverToNodeMetadata) {
this.client = client; this.client = client;
this.credentialStore = credentialStore; this.credentialStore = credentialStore;
this.serverToNodeMetadata = serverToNodeMetadata; this.serverToNodeMetadata = serverToNodeMetadata;
@ -56,12 +56,11 @@ public class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata addNodeWithTag(String tag, String name, Template template) {
NewServerResponse serverResponse = client.createServer(name, NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(),
checkNotNull(template.getImage().getProviderId(), "imageId"), "imageId"), checkNotNull(template.getHardware().getProviderId(), "hardwareId"));
checkNotNull(template.getHardware().getProviderId(), "hardwareId"));
Server from = client.getServer(serverResponse.getServer().getId()); Server from = client.getServer(serverResponse.getServer().getId());
credentialStore.put(from.getId() + "", new Credentials("root", serverResponse.getNewInstanceRequest() credentialStore.put("node#" + from.getId(), new Credentials("root", serverResponse.getNewInstanceRequest()
.getCreateOptions().getPassword())); .getCreateOptions().getPassword()));
return serverToNodeMetadata.apply(from); return serverToNodeMetadata.apply(from);
} }

View File

@ -46,7 +46,7 @@ import com.google.common.collect.Sets;
*/ */
@Singleton @Singleton
public class RimuHostingImageSupplier implements Supplier<Set<? extends Image>> { public class RimuHostingImageSupplier implements Supplier<Set<? extends Image>> {
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; private final RimuHostingClient sync;
@Inject @Inject
@ -77,23 +77,21 @@ public class RimuHostingImageSupplier implements Supplier<Set<? extends Image>>
protected OperatingSystem parseOs(final org.jclouds.rimuhosting.miro.domain.Image from) { protected OperatingSystem parseOs(final org.jclouds.rimuhosting.miro.domain.Image from) {
OsFamily osFamily = null; OsFamily osFamily = null;
String osName = null; String osName = from.getId();
String osArch = null; String osArch = null;
String osVersion = null; String osVersion = null;
String osDescription = from.getId(); String osDescription = from.getDescription();
boolean is64Bit = from.getId().indexOf("64") != -1; boolean is64Bit = from.getId().indexOf("64") != -1;
osDescription = from.getId(); Matcher matcher = RIMU_PATTERN.matcher(osDescription);
Matcher matcher = RIMU_PATTERN.matcher(from.getId());
if (matcher.find()) { if (matcher.find()) {
try { try {
osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase()); osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase());
osVersion = matcher.group(2).toLowerCase();
} catch (IllegalArgumentException e) { } 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 new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
return os;
} }
} }

View File

@ -56,15 +56,13 @@ public class RimuHostingClientLiveTest {
protected String provider = "rimuhosting"; protected String provider = "rimuhosting";
protected String identity; protected String identity;
protected String credential;
protected String endpoint; protected String endpoint;
protected String apiversion; protected String apiversion;
protected void setupCredentials() { protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider apiversion = System.getProperty("test." + provider + ".apiversion");
+ ".apiversion");
} }
protected Properties setupProperties() { protected Properties setupProperties() {
@ -72,8 +70,10 @@ public class RimuHostingClientLiveTest {
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity); overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".endpoint", endpoint); if (endpoint != null)
overrides.setProperty(provider + ".apiversion", apiversion); overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides; return overrides;
} }

View File

@ -48,6 +48,7 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes
public void testTemplateBuilder() { public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build(); Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS"); assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS");
assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO1B"); assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO1B");

View File

@ -53,16 +53,16 @@ import com.google.common.collect.ImmutableMap;
public class DomainToNodeMetadata implements Function<Domain, NodeMetadata> { public class DomainToNodeMetadata implements Function<Domain, NodeMetadata> {
public static final Map<DomainInfo.DomainState, NodeState> domainStateToNodeState = ImmutableMap public static final Map<DomainInfo.DomainState, NodeState> domainStateToNodeState = ImmutableMap
.<DomainInfo.DomainState, NodeState> builder() .<DomainInfo.DomainState, NodeState> builder().put(DomainInfo.DomainState.VIR_DOMAIN_RUNNING,
.put(DomainInfo.DomainState.VIR_DOMAIN_RUNNING, NodeState.RUNNING)// NodeState.RUNNING)//
.put(DomainInfo.DomainState.VIR_DOMAIN_BLOCKED, NodeState.PENDING)// .put(DomainInfo.DomainState.VIR_DOMAIN_BLOCKED, NodeState.PENDING)//
.put(DomainInfo.DomainState.VIR_DOMAIN_PAUSED, NodeState.SUSPENDED)// .put(DomainInfo.DomainState.VIR_DOMAIN_PAUSED, NodeState.SUSPENDED)//
.put(DomainInfo.DomainState.VIR_DOMAIN_SHUTDOWN, NodeState.SUSPENDED)// .put(DomainInfo.DomainState.VIR_DOMAIN_SHUTDOWN, NodeState.SUSPENDED)//
.put(DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF, NodeState.SUSPENDED)// .put(DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF, NodeState.SUSPENDED)//
.put(DomainInfo.DomainState.VIR_DOMAIN_CRASHED, NodeState.ERROR)// .put(DomainInfo.DomainState.VIR_DOMAIN_CRASHED, NodeState.ERROR)//
.put(DomainInfo.DomainState.VIR_DOMAIN_NOSTATE, NodeState.UNRECOGNIZED)// .put(DomainInfo.DomainState.VIR_DOMAIN_NOSTATE, NodeState.UNRECOGNIZED)//
.build(); .build();
private final Function<Domain, Hardware> findHardwareForDomain; private final Function<Domain, Hardware> findHardwareForDomain;
private final FindLocationForDomain findLocationForDomain; private final FindLocationForDomain findLocationForDomain;
@ -71,7 +71,7 @@ public class DomainToNodeMetadata implements Function<Domain, NodeMetadata> {
@Inject @Inject
DomainToNodeMetadata(Map<String, Credentials> credentialStore, Function<Domain, Hardware> findHardwareForDomain, DomainToNodeMetadata(Map<String, Credentials> credentialStore, Function<Domain, Hardware> findHardwareForDomain,
FindLocationForDomain findLocationForDomain, FindImageForDomain findImageForDomain) { FindLocationForDomain findLocationForDomain, FindImageForDomain findImageForDomain) {
this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.findHardwareForDomain = checkNotNull(findHardwareForDomain, "findHardwareForDomain"); this.findHardwareForDomain = checkNotNull(findHardwareForDomain, "findHardwareForDomain");
this.findLocationForDomain = checkNotNull(findLocationForDomain, "findLocationForDomain"); this.findLocationForDomain = checkNotNull(findLocationForDomain, "findLocationForDomain");
@ -96,7 +96,7 @@ public class DomainToNodeMetadata implements Function<Domain, NodeMetadata> {
builder.state(domainStateToNodeState.get(from.getInfo().state)); builder.state(domainStateToNodeState.get(from.getInfo().state));
// builder.publicAddresses(ImmutableSet.<String> of(from.publicAddress)); // builder.publicAddresses(ImmutableSet.<String> of(from.publicAddress));
// builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress)); // builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress));
builder.credentials(credentialStore.get(from.getUUIDString())); builder.credentials(credentialStore.get("node#" + from.getUUIDString()));
} catch (LibvirtException e) { } catch (LibvirtException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block

View File

@ -38,19 +38,19 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
} }
@Override @Override
public Domain createNodeAndStoreCredentials(String tag, String name, Template template, public Domain runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore) { Map<String, Credentials> credentialStore) {
// create the backend object using parameters from the template. // create the backend object using parameters from the template.
// Domain from = client.createDomainInDC(template.getLocation().getId(), name, // Domain from = client.createDomainInDC(template.getLocation().getId(), name,
// Integer.parseInt(template.getImage().getProviderId()), // Integer.parseInt(template.getImage().getProviderId()),
// Integer.parseInt(template.getHardware().getProviderId())); // Integer.parseInt(template.getHardware().getProviderId()));
// store the credentials so that later functions can use them // 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; return null;
} }
@Override @Override
public Iterable<Domain> listHardware() { public Iterable<Domain> listHardwareProfiles() {
return listNodes(); return listNodes();
} }

View File

@ -19,11 +19,14 @@
package org.jclouds.slicehost.compute.config; package org.jclouds.slicehost.compute.config;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import java.util.Set; import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
@ -31,6 +34,7 @@ import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.rest.annotations.Provider; import org.jclouds.rest.annotations.Provider;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -47,6 +51,11 @@ public class SlicehostComputeServiceContextModule extends BaseComputeServiceCont
return new LocationImpl(LocationScope.ZONE, "DFW1", "Dallas, TX", provider); return new LocationImpl(LocationScope.ZONE, "DFW1", "Dallas, TX", provider);
} }
@Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
return template.osFamily(UBUNTU).os64Bit(true);
}
@Provides @Provides
@Singleton @Singleton
Set<? extends Location> provideLocations(Location location) { Set<? extends Location> provideLocations(Location location) {

View File

@ -125,7 +125,7 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
} }
})); }));
builder.credentials(credentialStore.get(from.getId() + "")); builder.credentials(credentialStore.get("node#" + from.getId()));
return builder.build(); return builder.build();
} }

View File

@ -40,7 +40,7 @@ import com.google.common.base.Function;
@Singleton @Singleton
public class SlicehostImageToOperatingSystem implements public class SlicehostImageToOperatingSystem implements
Function<org.jclouds.slicehost.domain.Image, OperatingSystem> { Function<org.jclouds.slicehost.domain.Image, OperatingSystem> {
public static final Pattern SLICEHOST_PATTERN = Pattern.compile("(([^ ]*) .*)"); public static final Pattern SLICEHOST_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -52,18 +52,20 @@ public class SlicehostImageToOperatingSystem implements
String osArch = null; String osArch = null;
String osVersion = null; String osVersion = null;
String osDescription = from.getName(); String osDescription = from.getName();
boolean is64Bit = true; boolean is64Bit = !from.getName().endsWith("32-bit");
Matcher matcher = SLICEHOST_PATTERN.matcher(from.getName());
if (from.getName().indexOf("Red Hat EL") != -1) { if (from.getName().indexOf("Red Hat EL") != -1) {
osFamily = OsFamily.RHEL; osFamily = OsFamily.RHEL;
} else if (from.getName().indexOf("Oracle EL") != -1) { } else if (from.getName().indexOf("Oracle EL") != -1) {
osFamily = OsFamily.OEL; osFamily = OsFamily.OEL;
} else if (matcher.find()) { }
Matcher matcher = SLICEHOST_PATTERN.matcher(from.getName());
if (matcher.find()) {
try { try {
osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase()); osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", matcher.group(2)); logger.debug("<< didn't match os(%s)", matcher.group(2));
} }
osVersion = matcher.group(3);
} }
OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
return os; return os;

View File

@ -57,7 +57,7 @@ public class SlicehostAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata addNodeWithTag(String tag, String name, Template template) {
Slice from = client.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Slice from = client.createSlice(name, Integer.parseInt(template.getImage().getProviderId()),
Integer.parseInt(template.getHardware().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); return sliceToNodeMetadata.apply(from);
} }
} }

View File

@ -48,6 +48,7 @@ public class SlicehostComputeServiceLiveTest extends BaseComputeServiceLiveTest
public void testTemplateBuilder() { public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build(); Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); assertEquals(defaultTemplate.getLocation().getId(), "DFW1");
assertEquals(getCores(defaultTemplate.getHardware()), 0.25d); assertEquals(getCores(defaultTemplate.getHardware()), 0.25d);

View File

@ -66,7 +66,7 @@ public class SliceToNodeMetadataTest {
Slice slice = SliceHandlerTest.parseSlice(); Slice slice = SliceHandlerTest.parseSlice();
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState, ImmutableMap SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState, ImmutableMap
.<String, Credentials> of("1", creds), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers .<String, Credentials> of("node#1", creds), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares)); .ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
NodeMetadata metadata = parser.apply(slice); NodeMetadata metadata = parser.apply(slice);
@ -112,9 +112,9 @@ public class SliceToNodeMetadataTest {
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds") ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds")
.imageId("2").operatingSystem( .imageId("2").operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true) new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
.build()).id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata( .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").location(provider)
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
} }
@Test @Test
@ -136,8 +136,8 @@ public class SliceToNodeMetadataTest {
ImmutableList.of(new Processor(0.25, 1.0))).ram(256).volumes( ImmutableList.of(new Processor(0.25, 1.0))).ram(256).volumes(
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f).durable(true) ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f).durable(true)
.bootDevice(true).build())).build()).operatingSystem( .bootDevice(true).build())).build()).operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true) new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
.build()).id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata( .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").location(provider)
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
} }
} }

View File

@ -42,19 +42,29 @@ public class SlicehostImageToImageTest {
Location provider = new LocationImpl(LocationScope.ZONE, "dallas", "description", null); Location provider = new LocationImpl(LocationScope.ZONE, "dallas", "description", null);
@Test @Test
public void testApplyWhereImageNotFound() throws UnknownHostException { public void test() throws UnknownHostException {
assertEquals( assertEquals(convertImage(), new ImageBuilder().name("CentOS 5.2").operatingSystem(
convertImage(), new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2").is64Bit(
new ImageBuilder() true).build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null)).ids(
.name("CentOS 5.2") "2").build());
.operatingSystem( }
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true)
.build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null)) @Test
.ids("2").build()); 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() { 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()); SlicehostImageToImage parser = new SlicehostImageToImage(new SlicehostImageToOperatingSystem());

View File

@ -42,12 +42,16 @@ public class ImageHandlerTest {
static ParseSax<Image> createParser() { static ParseSax<Image> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule()); Injector injector = Guice.createInjector(new SaxParserModule());
ParseSax<Image> parser = (ParseSax<Image>) injector.getInstance(ParseSax.Factory.class).create( ParseSax<Image> parser = (ParseSax<Image>) injector.getInstance(ParseSax.Factory.class).create(
injector.getInstance(ImageHandler.class)); injector.getInstance(ImageHandler.class));
return parser; return parser;
} }
public static Image parseImage() { 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); return createParser().parse(is);
} }
@ -56,4 +60,9 @@ public class ImageHandlerTest {
assertEquals(parseImage(), expects); assertEquals(parseImage(), expects);
} }
public void test32() {
Image expects = new Image(70, "Ubuntu 10.10 (maverick) 32-bit");
assertEquals(parseImage("/test_get_image32.xml"), expects);
}
} }

View File

@ -41,13 +41,15 @@ public class ImagesHandlerTest extends BaseHandlerTest {
ParseSax<Set<? extends Image>> createParser() { ParseSax<Set<? extends Image>> createParser() {
ParseSax<Set<? extends Image>> parser = (ParseSax<Set<? extends Image>>) factory.create(injector ParseSax<Set<? extends Image>> parser = (ParseSax<Set<? extends Image>>) factory.create(injector
.getInstance(ImagesHandler.class)); .getInstance(ImagesHandler.class));
return parser; return parser;
} }
public void test() { public void test() {
InputStream is = getClass().getResourceAsStream("/test_list_images.xml"); InputStream is = getClass().getResourceAsStream("/test_list_images.xml");
Set<? extends Image> expects = ImmutableSet.of(new Image(2, "CentOS 5.2"), new Image(3, "Gentoo 2008.0"), Set<? extends Image> expects = ImmutableSet.of(
new Image(2, "CentOS 5.2"), new Image(3, "Gentoo 2008.0"),
new Image(4, "Debian 5.0 (lenny)"), 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(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)") new Image(13, "Fedora 11 (Leonidas)")
); );

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<images type="array">
<image>
<name>Ubuntu 10.10 (maverick) 32-bit</name>
<id type="integer">70</id>
</image>
</images>

View File

@ -1,47 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<images type="array"> <images type="array">
<image> <image>
<name>CentOS 5.2</name> <name>CentOS 5.2</name>
<id type="integer">2</id> <id type="integer">2</id>
</image> </image>
<image> <image>
<name>Gentoo 2008.0</name> <name>Gentoo 2008.0</name>
<id type="integer">3</id> <id type="integer">3</id>
</image> </image>
<image> <image>
<name>Debian 5.0 (lenny)</name> <name>Debian 5.0 (lenny)</name>
<id type="integer">4</id> <id type="integer">4</id>
</image> </image>
<image> <image>
<name>Fedora 10 (Cambridge)</name> <name>Fedora 10 (Cambridge)</name>
<id type="integer">5</id> <id type="integer">5</id>
</image> </image>
<image> <image>
<name>CentOS 5.3</name> <name>CentOS 5.3</name>
<id type="integer">7</id> <id type="integer">7</id>
</image> </image>
<image> <image>
<name>Ubuntu 9.04 (jaunty)</name> <name>Ubuntu 9.04 (jaunty)</name>
<id type="integer">8</id> <id type="integer">8</id>
</image> </image>
<image> <image>
<name>Arch 2009.02</name> <name>Arch 2009.02</name>
<id type="integer">9</id> <id type="integer">9</id>
</image> </image>
<image> <image>
<name>Ubuntu 8.04.2 LTS (hardy)</name> <name>Ubuntu 8.04.2 LTS (hardy)</name>
<id type="integer">10</id> <id type="integer">10</id>
</image> </image>
<image> <image>
<name>Ubuntu 8.10 (intrepid)</name> <name>Ubuntu 8.10 (intrepid)</name>
<id type="integer">11</id> <id type="integer">11</id>
</image> </image>
<image> <image>
<name>Red Hat EL 5.3</name> <name>Ubuntu 10.10 (maverick) 32-bit</name>
<id type="integer">12</id> <id type="integer">70</id>
</image> </image>
<image> <image>
<name>Fedora 11 (Leonidas)</name> <name>Red Hat EL 5.3</name>
<id type="integer">13</id> <id type="integer">12</id>
</image> </image>
<image>
<name>Fedora 11 (Leonidas)</name>
<id type="integer">13</id>
</image>
</images> </images>

View File

@ -53,7 +53,7 @@ public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
@Inject @Inject
protected VAppToNodeMetadata(Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore, protected VAppToNodeMetadata(Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
FindLocationForResource findLocationForResourceInVDC, Function<VApp, Hardware> hardwareForVApp) { FindLocationForResource findLocationForResourceInVDC, Function<VApp, Hardware> hardwareForVApp) {
this.hardwareForVApp = checkNotNull(hardwareForVApp, "hardwareForVApp"); this.hardwareForVApp = checkNotNull(hardwareForVApp, "hardwareForVApp");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC"); this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.credentialStore = checkNotNull(credentialStore, "credentialStore");
@ -73,9 +73,9 @@ public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
builder.publicAddresses(getPublicIpsFromVApp(from)); builder.publicAddresses(getPublicIpsFromVApp(from));
builder.privateAddresses(getPrivateIpsFromVApp(from)); builder.privateAddresses(getPrivateIpsFromVApp(from));
builder.credentials(getCredentialsFrom(from)); builder.credentials(getCredentialsFrom(from));
if (!credentialStore.containsKey(from.getHref().toASCIIString())) if (!credentialStore.containsKey("node#" + from.getHref().toASCIIString()))
credentialStore.put(from.getHref().toASCIIString(), getCredentialsFrom(from)); credentialStore.put("node#" + from.getHref().toASCIIString(), getCredentialsFrom(from));
builder.credentials(credentialStore.get(from.getHref().toASCIIString())); builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString()));
return builder.build(); return builder.build();
} }
} }

View File

@ -82,7 +82,7 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
builder.state(vAppStatusToNodeState.get(from.getStatus())); builder.state(vAppStatusToNodeState.get(from.getStatus()));
builder.publicAddresses(computeClient.getPublicAddresses(from.getHref())); builder.publicAddresses(computeClient.getPublicAddresses(from.getHref()));
builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref())); builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref()));
builder.credentials(credentialStore.get(from.getHref().toASCIIString())); builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString()));
return builder.build(); return builder.build();
} }
} }

View File

@ -100,7 +100,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
VCloudExpressVApp vAppResponse = super.start(VDC, templateId, name, options, portsToOpen); VCloudExpressVApp vAppResponse = super.start(VDC, templateId, name, options, portsToOpen);
if (password != null) { if (password != null) {
credentialStore.put(vAppResponse.getHref().toASCIIString(), new Credentials(defaultCredentials.identity, credentialStore.put("node#" + vAppResponse.getHref().toASCIIString(), new Credentials(defaultCredentials.identity,
password)); password));
} }
if (portsToOpen.length > 0) if (portsToOpen.length > 0)

View File

@ -80,11 +80,11 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT
if (credentialsMap.containsKey(orgAndName)) { if (credentialsMap.containsKey(orgAndName)) {
Credentials creds = credentialsMap.get(orgAndName); Credentials creds = credentialsMap.get(orgAndName);
node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(creds).build(); 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 // this is going to need refactoring.. we really need a credential list in the store per
// node. // node.
String adminPasswordKey = node.getId() + "/adminPassword"; String adminPasswordKey = "node#" + node.getId() + "#adminPassword";
if (credentialStore.containsKey(adminPasswordKey)) { if (credentialStore.containsKey(adminPasswordKey)) {
node = NodeMetadataBuilder.fromNodeMetadata(node).adminPassword( node = NodeMetadataBuilder.fromNodeMetadata(node).adminPassword(
credentialStore.get(adminPasswordKey).credential).build(); credentialStore.get(adminPasswordKey).credential).build();

View File

@ -65,8 +65,8 @@ public class CleanupOrphanKeys {
// TODO refactor so that admin passwords are cached properly, probably as a list value in the // TODO refactor so that admin passwords are cached properly, probably as a list value in the
// credentialStore // credentialStore
for (NodeMetadata node : deadOnes){ for (NodeMetadata node : deadOnes){
credentialStore.remove(node.getId()); credentialStore.remove("node#" + node.getId());
credentialStore.remove(node.getId() + "/adminPassword"); credentialStore.remove("node#" + node.getId() + "#adminPassword");
} }
Iterable<OrgAndName> orgTags = filter(transform(deadOnes, nodeToOrgAndName), notNull()); Iterable<OrgAndName> orgTags = filter(transform(deadOnes, nodeToOrgAndName), notNull());
for (OrgAndName orgTag : orgTags) { for (OrgAndName orgTag : orgTags) {

View File

@ -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 // 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 // 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. // 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())); .getAdminPassword()));
} }
return builder.build(); return builder.build();

View File

@ -111,7 +111,7 @@ public class TerremarkVCloudComputeClientTest {
new TerremarkInstantiateVAppTemplateOptions()); new TerremarkInstantiateVAppTemplateOptions());
assertEquals(response.getHref().toASCIIString(), "vapp"); 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(vdc);
verify(template); verify(template);

View File

@ -139,9 +139,9 @@ public class CleanupOrphanKeysTest {
} }
private void expectCleanupCredentialStore(CleanupOrphanKeys strategy, NodeMetadata nodeMetadata) { private void expectCleanupCredentialStore(CleanupOrphanKeys strategy, NodeMetadata nodeMetadata) {
expect(nodeMetadata.getId()).andReturn("1").times(2); expect("node#" + nodeMetadata.getId()).andReturn("1").times(2);
expect(strategy.credentialStore.remove("1")).andReturn(null); expect(strategy.credentialStore.remove("node#1")).andReturn(null);
expect(strategy.credentialStore.remove("1/adminPassword")).andReturn(null); expect(strategy.credentialStore.remove("node#1#adminPassword")).andReturn(null);
} }
public void testWhenNoneLeftWithTag() { public void testWhenNoneLeftWithTag() {