Issue 457: rename tag -> group

This commit is contained in:
Adrian Cole 2011-01-31 18:02:54 -08:00
parent a1dbbd203c
commit 4a52218565
112 changed files with 634 additions and 1396 deletions

View File

@ -95,7 +95,7 @@ Compute Example (Java):
template = client.templateBuilder().osFamily(UBUNTU).smallest().build(); template = client.templateBuilder().osFamily(UBUNTU).smallest().build();
// these nodes will be accessible via ssh when the call returns // these nodes will be accessible via ssh when the call returns
nodes = client.runNodesWithTag("mycluster", 2, template); nodes = client.createNodesInGroup("mycluster", 2, template);
Compute Example (Clojure): Compute Example (Clojure):
(use 'org.jclouds.compute) (use 'org.jclouds.compute)
@ -107,7 +107,7 @@ Compute Example (Clojure):
; use the default node template and launch a couple nodes ; use the default node template and launch a couple nodes
; these will have your ~/.ssh/id_rsa.pub authorized when complete ; these will have your ~/.ssh/id_rsa.pub authorized when complete
(with-compute-service [compute] (with-compute-service [compute]
(run-nodes "mycluster" 2)) (create-nodes "mycluster" 2))
Downloads: Downloads:
* distribution zip: http://jclouds.googlecode.com/files/jclouds-1.0-beta-8.zip * distribution zip: http://jclouds.googlecode.com/files/jclouds-1.0-beta-8.zip

View File

@ -189,19 +189,19 @@ public class ComputeTask extends Task {
private void list(ComputeService computeService) { private void list(ComputeService computeService) {
log("list"); log("list");
for (ComputeMetadata node : computeService.listNodes()) { for (ComputeMetadata node : computeService.listNodes()) {
log(String.format(" location=%s, id=%s, tag=%s", node.getLocation(), node.getProviderId(), node.getName())); log(String.format(" location=%s, id=%s, group=%s", node.getLocation(), node.getProviderId(), node.getName()));
} }
} }
private void create(ComputeService computeService) throws RunNodesException, IOException { private void create(ComputeService computeService) throws RunNodesException, IOException {
String tag = nodeElement.getTag(); String group = nodeElement.getGroup();
log(String.format("create tag: %s, count: %d, hardware: %s, os: %s", tag, nodeElement.getCount(), nodeElement log(String.format("create group: %s, count: %d, hardware: %s, os: %s", group, nodeElement.getCount(), nodeElement
.getHardware(), nodeElement.getOs())); .getHardware(), nodeElement.getOs()));
Template template = createTemplateFromElement(nodeElement, computeService); Template template = createTemplateFromElement(nodeElement, computeService);
for (NodeMetadata createdNode : computeService.runNodesWithTag(tag, nodeElement.getCount(), template)) { for (NodeMetadata createdNode : computeService.createNodesInGroup(group, nodeElement.getCount(), template)) {
logDetails(computeService, createdNode); logDetails(computeService, createdNode);
addNodeDetailsAsProjectProperties(createdNode); addNodeDetailsAsProjectProperties(createdNode);
} }
@ -223,8 +223,8 @@ public class ComputeTask extends Task {
log(String.format("reboot id: %s", nodeElement.getId())); log(String.format("reboot id: %s", nodeElement.getId()));
computeService.rebootNode(nodeElement.getId()); computeService.rebootNode(nodeElement.getId());
} else { } else {
log(String.format("reboot tag: %s", nodeElement.getTag())); log(String.format("reboot group: %s", nodeElement.getGroup()));
computeService.rebootNodesMatching(NodePredicates.withTag(nodeElement.getTag())); computeService.rebootNodesMatching(NodePredicates.inGroup(nodeElement.getGroup()));
} }
} }
@ -233,8 +233,8 @@ public class ComputeTask extends Task {
log(String.format("destroy id: %s", nodeElement.getId())); log(String.format("destroy id: %s", nodeElement.getId()));
computeService.destroyNode(nodeElement.getId()); computeService.destroyNode(nodeElement.getId());
} else { } else {
log(String.format("destroy tag: %s", nodeElement.getTag())); log(String.format("destroy group: %s", nodeElement.getGroup()));
computeService.destroyNodesMatching(NodePredicates.withTag(nodeElement.getTag())); computeService.destroyNodesMatching(NodePredicates.inGroup(nodeElement.getGroup()));
} }
} }
@ -243,9 +243,9 @@ public class ComputeTask extends Task {
log(String.format("get id: %s", nodeElement.getId())); log(String.format("get id: %s", nodeElement.getId()));
logDetails(computeService, computeService.getNodeMetadata(nodeElement.getId())); logDetails(computeService, computeService.getNodeMetadata(nodeElement.getId()));
} else { } else {
log(String.format("get tag: %s", nodeElement.getTag())); log(String.format("get group: %s", nodeElement.getGroup()));
for (ComputeMetadata node : Iterables.filter(computeService.listNodesDetailsMatching(NodePredicates.all()), for (ComputeMetadata node : Iterables.filter(computeService.listNodesDetailsMatching(NodePredicates.all()),
NodePredicates.withTag(nodeElement.getTag()))) { NodePredicates.inGroup(nodeElement.getGroup()))) {
logDetails(computeService, node); logDetails(computeService, node);
} }
} }
@ -254,8 +254,8 @@ public class ComputeTask extends Task {
private void logDetails(ComputeService computeService, ComputeMetadata node) { private void logDetails(ComputeService computeService, ComputeMetadata node) {
NodeMetadata metadata = node instanceof NodeMetadata ? NodeMetadata.class.cast(node) : computeService NodeMetadata metadata = node instanceof NodeMetadata ? NodeMetadata.class.cast(node) : computeService
.getNodeMetadata(node.getId()); .getNodeMetadata(node.getId());
log(String.format(" node id=%s, name=%s, tag=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, hardware=%s", log(String.format(" node id=%s, name=%s, group=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, hardware=%s",
metadata.getProviderId(), metadata.getName(), metadata.getTag(), metadata.getLocation(), metadata metadata.getProviderId(), metadata.getName(), metadata.getGroup(), metadata.getLocation(), metadata
.getState(), ComputeTaskUtils.ipOrEmptyString(metadata.getPublicAddresses()), .getState(), ComputeTaskUtils.ipOrEmptyString(metadata.getPublicAddresses()),
ipOrEmptyString(metadata.getPrivateAddresses()), metadata.getHardware())); ipOrEmptyString(metadata.getPrivateAddresses()), metadata.getHardware()));
} }

View File

@ -27,7 +27,7 @@ import java.io.File;
*/ */
public class NodeElement { public class NodeElement {
private String id; private String id;
private String tag; private String group;
private String hardware; private String hardware;
private String os; private String os;
private String image; private String image;
@ -147,12 +147,12 @@ public class NodeElement {
return count; return count;
} }
public void setTag(String tag) { public void setGroup(String group) {
this.tag = tag; this.group = group;
} }
public String getTag() { public String getGroup() {
return tag; return group;
} }
public void setPrivatekeyfile(File privatekeyfile) { public void setPrivatekeyfile(File privatekeyfile) {

View File

@ -71,7 +71,7 @@ public class NodeToNodeMetadata implements Function<Node, NodeMetadata> {
builder.ids(from.getId()); builder.ids(from.getId());
builder.name(from.getName()); builder.name(from.getName());
builder.location(location.get()); builder.location(location.get());
builder.tag(from.getGroup()); builder.group(from.getGroup());
// TODO add tags! // TODO add tags!
builder.operatingSystem(new OperatingSystemBuilder().arch(from.getOsArch()).family( builder.operatingSystem(new OperatingSystemBuilder().arch(from.getOsArch()).family(
OsFamily.fromValue(from.getOsFamily())).description(from.getOsDescription()) OsFamily.fromValue(from.getOsFamily())).description(from.getOsDescription())

View File

@ -60,7 +60,7 @@ public class BYONComputeServiceAdapter implements JCloudsNativeComputeServiceAda
} }
@Override @Override
public NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, public NodeMetadata createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore) { Map<String, Credentials> credentialStore) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -53,7 +53,7 @@ public class NodeToNodeMetadataTest {
public static NodeMetadata expectedNodeMetadataFromResource(String resource) { public static NodeMetadata expectedNodeMetadataFromResource(String resource) {
Location location = expectedLocationFromResource(resource); Location location = expectedLocationFromResource(resource);
return new NodeMetadataBuilder().ids("cluster-1").tag("hadoop").name("cluster-1").location(location).state( return new NodeMetadataBuilder().ids("cluster-1").group("hadoop").name("cluster-1").location(location).state(
NodeState.RUNNING).operatingSystem( NodeState.RUNNING).operatingSystem(
new OperatingSystemBuilder().description("redhat").family(OsFamily.RHEL).arch("x86").version("5.3") new OperatingSystemBuilder().description("redhat").family(OsFamily.RHEL).arch("x86").version("5.3")
.build()).publicAddresses(ImmutableSet.of("cluster-1.mydomain.com")).credentials( .build()).publicAddresses(ImmutableSet.of("cluster-1.mydomain.com")).credentials(

View File

@ -20,14 +20,14 @@
package org.jclouds.cloudservers.compute.config; package org.jclouds.cloudservers.compute.config;
import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.cloudservers.compute.strategy.CloudServersAddNodeWithTagStrategy; import org.jclouds.cloudservers.compute.strategy.CloudServersCreateNodeWithGroupEncodedIntoName;
import org.jclouds.cloudservers.compute.strategy.CloudServersDestroyNodeStrategy; import org.jclouds.cloudservers.compute.strategy.CloudServersDestroyNodeStrategy;
import org.jclouds.cloudservers.compute.strategy.CloudServersGetNodeMetadataStrategy; import org.jclouds.cloudservers.compute.strategy.CloudServersGetNodeMetadataStrategy;
import org.jclouds.cloudservers.compute.strategy.CloudServersListNodesStrategy; import org.jclouds.cloudservers.compute.strategy.CloudServersListNodesStrategy;
@ -41,8 +41,8 @@ import org.jclouds.cloudservers.compute.strategy.CloudServersLifeCycleStrategy;
public class CloudServersBindComputeStrategiesByClass extends BindComputeStrategiesByClass { public class CloudServersBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
@Override @Override
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() { protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
return CloudServersAddNodeWithTagStrategy.class; return CloudServersCreateNodeWithGroupEncodedIntoName.class;
} }
@Override @Override

View File

@ -20,7 +20,7 @@
package org.jclouds.cloudservers.compute.functions; package org.jclouds.cloudservers.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -112,7 +112,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
builder.location(new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()).description( builder.location(new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()).description(
from.getHostId()).parent(location.get()).build()); from.getHostId()).parent(location.get()).build());
builder.userMetadata(from.getMetadata()); builder.userMetadata(from.getMetadata());
builder.tag(parseTagFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
builder.imageId(from.getImageId() + ""); builder.imageId(from.getImageId() + "");
builder.operatingSystem(parseOperatingSystem(from)); builder.operatingSystem(parseOperatingSystem(from));
builder.hardware(parseHardware(from)); builder.hardware(parseHardware(from));

View File

@ -28,7 +28,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.cloudservers.CloudServersClient; import org.jclouds.cloudservers.CloudServersClient;
import org.jclouds.cloudservers.domain.Server; import org.jclouds.cloudservers.domain.Server;
@ -39,13 +39,13 @@ import com.google.common.base.Function;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrategy { public class CloudServersCreateNodeWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName {
protected final CloudServersClient client; protected final CloudServersClient client;
protected final Map<String, Credentials> credentialStore; protected final Map<String, Credentials> credentialStore;
protected final Function<Server, NodeMetadata> serverToNodeMetadata; protected final Function<Server, NodeMetadata> serverToNodeMetadata;
@Inject @Inject
protected CloudServersAddNodeWithTagStrategy(CloudServersClient client, Map<String, Credentials> credentialStore, protected CloudServersCreateNodeWithGroupEncodedIntoName(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");
@ -53,7 +53,7 @@ public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrateg
} }
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
Server from = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer Server from = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer
.parseInt(template.getHardware().getProviderId())); .parseInt(template.getHardware().getProviderId()));
credentialStore.put("node#" + from.getId(), new Credentials("root", from.getAdminPass())); credentialStore.put("node#" + from.getId(), new Credentials("root", from.getAdminPass()));

View File

@ -74,11 +74,11 @@ public class ServerToNodeMetadataTest {
NodeMetadata metadata = parser.apply(server); NodeMetadata metadata = parser.apply(server);
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"))
"NOTAG#sample-server").imageId("2").id("1234").providerId("1234").name("sample-server").credentials( .imageId("2").id("1234").providerId("1234").name("sample-server").credentials(creds).location(
creds).location( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0").description( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
"e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()).userMetadata( .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
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
@ -95,11 +95,11 @@ public class ServerToNodeMetadataTest {
NodeMetadata metadata = parser.apply(server); NodeMetadata metadata = parser.apply(server);
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"))
"NOTAG#sample-server").imageId("2").id("1234").providerId("1234").name("sample-server").location( .imageId("2").id("1234").providerId("1234").name("sample-server").location(
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0").description( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
"e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()).userMetadata( .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
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());
} }
@ -118,13 +118,13 @@ public class ServerToNodeMetadataTest {
NodeMetadata metadata = parser.apply(server); NodeMetadata metadata = parser.apply(server);
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"))
"NOTAG#sample-server").imageId("2").operatingSystem( .imageId("2").operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2").is64Bit( new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
true).build()).id("1234").providerId("1234").name("sample-server").location( .is64Bit(true).build()).id("1234").providerId("1234").name("sample-server").location(
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0").description( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
"e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()).userMetadata( .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
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());
} }
@ -142,16 +142,16 @@ public class ServerToNodeMetadataTest {
NodeMetadata metadata = parser.apply(server); NodeMetadata metadata = parser.apply(server);
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"))
"NOTAG#sample-server").imageId("2").hardware( .imageId("2").hardware(
new HardwareBuilder().ids("1").name("256 MB Server").processors( new HardwareBuilder().ids("1").name("256 MB Server").processors(
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").version("5.2").is64Bit( new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
true).build()).id("1234").providerId("1234").name("sample-server").location( .is64Bit(true).build()).id("1234").providerId("1234").name("sample-server").location(
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0").description( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
"e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()).userMetadata( .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
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

@ -46,7 +46,7 @@ import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -75,7 +75,7 @@ public class EC2ComputeService extends BaseComputeService {
protected EC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore, protected EC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy, ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider, Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
@ -96,26 +96,26 @@ public class EC2ComputeService extends BaseComputeService {
} }
@VisibleForTesting @VisibleForTesting
void deleteSecurityGroup(String region, String tag) { void deleteSecurityGroup(String region, String group) {
Preconditions2.checkNotEmpty(tag, "tag"); Preconditions2.checkNotEmpty(group, "group");
String group = String.format("jclouds#%s#%s", tag, region); String groupName = String.format("jclouds#%s#%s", group, region);
if (ec2Client.getSecurityGroupServices().describeSecurityGroupsInRegion(region, group).size() > 0) { if (ec2Client.getSecurityGroupServices().describeSecurityGroupsInRegion(region, groupName).size() > 0) {
logger.debug(">> deleting securityGroup(%s)", group); logger.debug(">> deleting securityGroup(%s)", groupName);
try { try {
ec2Client.getSecurityGroupServices().deleteSecurityGroupInRegion(region, group); ec2Client.getSecurityGroupServices().deleteSecurityGroupInRegion(region, groupName);
// TODO: test this clear happens // TODO: test this clear happens
securityGroupMap.remove(new RegionNameAndIngressRules(region, group, null, false)); securityGroupMap.remove(new RegionNameAndIngressRules(region, groupName, null, false));
logger.debug("<< deleted securityGroup(%s)", group); logger.debug("<< deleted securityGroup(%s)", groupName);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
logger.debug("<< inUse securityGroup(%s)", group); logger.debug("<< inUse securityGroup(%s)", groupName);
} }
} }
} }
@VisibleForTesting @VisibleForTesting
void deleteKeyPair(String region, String tag) { void deleteKeyPair(String region, String group) {
for (KeyPair keyPair : ec2Client.getKeyPairServices().describeKeyPairsInRegion(region)) { for (KeyPair keyPair : ec2Client.getKeyPairServices().describeKeyPairsInRegion(region)) {
if (keyPair.getKeyName().matches(String.format("jclouds#%s#%s#%s", tag, region, "[0-9a-f]+"))) { if (keyPair.getKeyName().matches(String.format("jclouds#%s#%s#%s", group, region, "[0-9a-f]+"))) {
logger.debug(">> deleting keyPair(%s)", keyPair.getKeyName()); logger.debug(">> deleting keyPair(%s)", keyPair.getKeyName());
ec2Client.getKeyPairServices().deleteKeyPairInRegion(region, keyPair.getKeyName()); ec2Client.getKeyPairServices().deleteKeyPairInRegion(region, keyPair.getKeyName());
// TODO: test this clear happens // TODO: test this clear happens
@ -134,8 +134,8 @@ public class EC2ComputeService extends BaseComputeService {
Set<? extends NodeMetadata> deadOnes = super.destroyNodesMatching(filter); Set<? extends NodeMetadata> deadOnes = super.destroyNodesMatching(filter);
Map<String, String> regionTags = Maps.newHashMap(); Map<String, String> regionTags = Maps.newHashMap();
for (NodeMetadata nodeMetadata : deadOnes) { for (NodeMetadata nodeMetadata : deadOnes) {
if (nodeMetadata.getTag() != null) if (nodeMetadata.getGroup() != null)
regionTags.put(AWSUtils.parseHandle(nodeMetadata.getId())[0], nodeMetadata.getTag()); regionTags.put(AWSUtils.parseHandle(nodeMetadata.getId())[0], nodeMetadata.getGroup());
} }
for (Entry<String, String> regionTag : regionTags.entrySet()) { for (Entry<String, String> regionTag : regionTags.entrySet()) {
cleanUpIncidentalResources(regionTag); cleanUpIncidentalResources(regionTag);

View File

@ -23,16 +23,16 @@ import org.jclouds.ec2.compute.strategy.EC2DestroyNodeStrategy;
import org.jclouds.ec2.compute.strategy.EC2GetNodeMetadataStrategy; import org.jclouds.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
import org.jclouds.ec2.compute.strategy.EC2ListNodesStrategy; import org.jclouds.ec2.compute.strategy.EC2ListNodesStrategy;
import org.jclouds.ec2.compute.strategy.EC2RebootNodeStrategy; import org.jclouds.ec2.compute.strategy.EC2RebootNodeStrategy;
import org.jclouds.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy; import org.jclouds.ec2.compute.strategy.EC2CreateNodesInGroupThenAddToSet;
import org.jclouds.ec2.compute.strategy.EC2ResumeNodeStrategy; import org.jclouds.ec2.compute.strategy.EC2ResumeNodeStrategy;
import org.jclouds.ec2.compute.strategy.EC2SuspendNodeStrategy; import org.jclouds.ec2.compute.strategy.EC2SuspendNodeStrategy;
import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
@ -41,23 +41,23 @@ import org.jclouds.compute.strategy.SuspendNodeStrategy;
*/ */
public class EC2BindComputeStrategiesByClass extends BindComputeStrategiesByClass { public class EC2BindComputeStrategiesByClass extends BindComputeStrategiesByClass {
@Override @Override
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() { protected Class<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
return EC2RunNodesAndAddToSetStrategy.class; return EC2CreateNodesInGroupThenAddToSet.class;
} }
/** /**
* not needed, as {@link EC2RunNodesAndAddToSetStrategy} is used and is already set-based. * not needed, as {@link EC2CreateNodesInGroupThenAddToSet} is used and is already set-based.
*/ */
@Override @Override
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() { protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
return null; return null;
} }
/** /**
* not needed, as {@link EC2RunNodesAndAddToSetStrategy} is used and is already set-based. * not needed, as {@link EC2CreateNodesInGroupThenAddToSet} is used and is already set-based.
*/ */
@Override @Override
protected void bindAddNodeWithTagStrategy(Class<? extends AddNodeWithTagStrategy> clazz) { protected void bindAddNodeWithTagStrategy(Class<? extends CreateNodeWithGroupEncodedIntoName> clazz) {
} }
@Override @Override

View File

@ -89,8 +89,8 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
String providerId = checkNotNull(instance, "instance").getId(); String providerId = checkNotNull(instance, "instance").getId();
builder.providerId(providerId); builder.providerId(providerId);
builder.id(instance.getRegion() + "/" + providerId); builder.id(instance.getRegion() + "/" + providerId);
String tag = getTagForInstance(instance); String group = getGroupForInstance(instance);
builder.tag(tag); builder.group(group);
builder.credentials(credentialStore.get("node#" + 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(NullSafeCollections.nullSafeSet(instance.getIpAddress())); builder.publicAddresses(NullSafeCollections.nullSafeSet(instance.getIpAddress()));
@ -157,10 +157,10 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
} }
@VisibleForTesting @VisibleForTesting
String getTagForInstance(final RunningInstance instance) { String getGroupForInstance(final RunningInstance instance) {
String tag = String.format("NOTAG#%s", instance.getId());// default String group = null;
try { try {
tag = Iterables.getOnlyElement(Iterables.filter(instance.getGroupIds(), new Predicate<String>() { group = Iterables.getOnlyElement(Iterables.filter(instance.getGroupIds(), new Predicate<String>() {
@Override @Override
public boolean apply(String input) { public boolean apply(String input) {
@ -169,13 +169,13 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
})).substring(8).replaceAll("#" + instance.getRegion() + "$", ""); })).substring(8).replaceAll("#" + instance.getRegion() + "$", "");
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.debug("no tag parsed from %s's groups: %s", instance.getId(), instance.getGroupIds()); logger.debug("no group parsed from %s's security groups: %s", instance.getId(), instance.getGroupIds());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger logger
.debug("too many groups match %s; %s's groups: %s", "jclouds#", instance.getId(), instance .debug("too many groups match %s; %s's security groups: %s", "jclouds#", instance.getId(), instance
.getGroupIds()); .getGroupIds());
} }
return tag; return group;
} }
@VisibleForTesting @VisibleForTesting

View File

@ -38,7 +38,7 @@ import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.util.ComputeUtils; import org.jclouds.compute.util.ComputeUtils;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
@ -60,7 +60,7 @@ import com.google.common.collect.Multimap;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrategy { public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThenAddToSet {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -79,7 +79,7 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
final Map<String, Credentials> credentialStore; final Map<String, Credentials> credentialStore;
@Inject @Inject
EC2RunNodesAndAddToSetStrategy( EC2CreateNodesInGroupThenAddToSet(
EC2Client client, EC2Client client,
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
@Named("PRESENT") Predicate<RunningInstance> instancePresent, @Named("PRESENT") Predicate<RunningInstance> instancePresent,
@ -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 group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Iterable<? extends RunningInstance> started = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(tag, count, Iterable<? extends RunningInstance> started = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(group, count,
template); template);
Iterable<String> ids = transform(started, instanceToId); Iterable<String> ids = transform(started, instanceToId);
@ -130,13 +130,13 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
// TODO write test for this // TODO write test for this
@VisibleForTesting @VisibleForTesting
Iterable<? extends RunningInstance> createKeyPairAndSecurityGroupsAsNeededThenRunInstances(String tag, int count, Iterable<? extends RunningInstance> createKeyPairAndSecurityGroupsAsNeededThenRunInstances(String group, int count,
Template template) { Template template) {
String region = AWSUtils.getRegionFromLocationOrNull(template.getLocation()); String region = AWSUtils.getRegionFromLocationOrNull(template.getLocation());
String zone = getZoneFromLocationOrNull(template.getLocation()); String zone = getZoneFromLocationOrNull(template.getLocation());
RunInstancesOptions instanceOptions = createKeyPairAndSecurityGroupsAsNeededAndReturncustomize.execute(region, RunInstancesOptions instanceOptions = createKeyPairAndSecurityGroupsAsNeededAndReturncustomize.execute(region,
tag, template); group, template);
int countStarted = 0; int countStarted = 0;
int tries = 0; int tries = 0;

View File

@ -107,26 +107,26 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getInstanceServices(); .getInstanceServices();
String tag = this.tag + "o"; String group = this.group + "o";
TemplateOptions options = client.templateOptions(); TemplateOptions options = client.templateOptions();
options.as(EC2TemplateOptions.class).securityGroups(tag); options.as(EC2TemplateOptions.class).securityGroups(group);
options.as(EC2TemplateOptions.class).keyPair(tag); options.as(EC2TemplateOptions.class).keyPair(group);
String startedId = null; String startedId = null;
try { try {
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag); cleanupExtendedStuff(securityGroupClient, keyPairClient, group);
// create a security group that allows ssh in so that our scripts later // create a security group that allows ssh in so that our scripts later
// will work // will work
securityGroupClient.createSecurityGroupInRegion(null, tag, tag); securityGroupClient.createSecurityGroupInRegion(null, group, group);
securityGroupClient.authorizeSecurityGroupIngressInRegion(null, tag, IpProtocol.TCP, 22, 22, "0.0.0.0/0"); securityGroupClient.authorizeSecurityGroupIngressInRegion(null, group, IpProtocol.TCP, 22, 22, "0.0.0.0/0");
// create a keypair to pass in as well // create a keypair to pass in as well
KeyPair result = keyPairClient.createKeyPairInRegion(null, tag); KeyPair result = keyPairClient.createKeyPairInRegion(null, group);
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options); Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
NodeMetadata first = Iterables.get(nodes, 0); NodeMetadata first = Iterables.get(nodes, 0);
assert first.getCredentials() != null : first; assert first.getCredentials() != null : first;
assert first.getCredentials().identity != null : first; assert first.getCredentials().identity != null : first;
@ -135,29 +135,29 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
RunningInstance instance = getInstance(instanceClient, startedId); RunningInstance instance = getInstance(instanceClient, startedId);
assertEquals(instance.getKeyName(), tag); assertEquals(instance.getKeyName(), group);
// make sure we made our dummy group and also let in the user's group // make sure we made our dummy group and also let in the user's group
assertEquals(Sets.newTreeSet(instance.getGroupIds()), ImmutableSortedSet.<String> of("jclouds#" + tag + "#" assertEquals(Sets.newTreeSet(instance.getGroupIds()), ImmutableSortedSet.<String> of("jclouds#" + group + "#"
+ instance.getRegion(), tag)); + instance.getRegion(), group));
// make sure our dummy group has no rules // make sure our dummy group has no rules
SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null, SecurityGroup secgroup = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
"jclouds#" + tag + "#" + instance.getRegion())); "jclouds#" + group + "#" + instance.getRegion()));
assert group.getIpPermissions().size() == 0 : group; assert secgroup.getIpPermissions().size() == 0 : secgroup;
// try to run a script with the original keyPair // try to run a script with the original keyPair
runScriptWithCreds(tag, first.getOperatingSystem(), new Credentials(first.getCredentials().identity, result runScriptWithCreds(group, first.getOperatingSystem(), new Credentials(first.getCredentials().identity, result
.getKeyMaterial())); .getKeyMaterial()));
} finally { } finally {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(NodePredicates.inGroup(group));
if (startedId != null) { if (startedId != null) {
// ensure we didn't delete these resources! // ensure we didn't delete these resources!
assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag).size(), 1); assertEquals(keyPairClient.describeKeyPairsInRegion(null, group).size(), 1);
assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, tag).size(), 1); assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, group).size(), 1);
} }
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag); cleanupExtendedStuff(securityGroupClient, keyPairClient, group);
} }
} }
@ -173,7 +173,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
ElasticBlockStoreClient ebsClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) ElasticBlockStoreClient ebsClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getElasticBlockStoreServices(); .getElasticBlockStoreServices();
String tag = this.tag + "e"; String group = this.group + "e";
int volumeSize = 8; int volumeSize = 8;
Location zone = Iterables.find(context.getComputeService().listAssignableLocations(), new Predicate<Location>() { Location zone = Iterables.find(context.getComputeService().listAssignableLocations(), new Predicate<Location>() {
@ -200,7 +200,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
.mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true); .mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);
try { try {
NodeMetadata node = Iterables.getOnlyElement(client.runNodesWithTag(tag, 1, template)); NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));
// TODO figure out how to validate the ephemeral drive. perhaps with df -k? // TODO figure out how to validate the ephemeral drive. perhaps with df -k?
@ -228,7 +228,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(snapshot.getId(), volume.getSnapshotId()); assertEquals(snapshot.getId(), volume.getSnapshotId());
} finally { } finally {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(NodePredicates.inGroup(group));
ebsClient.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId()); ebsClient.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
} }
} }
@ -239,19 +239,19 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
return instance; return instance;
} }
protected void cleanupExtendedStuff(SecurityGroupClient securityGroupClient, KeyPairClient keyPairClient, String tag) protected void cleanupExtendedStuff(SecurityGroupClient securityGroupClient, KeyPairClient keyPairClient, String group)
throws InterruptedException { throws InterruptedException {
try { try {
for (SecurityGroup group : securityGroupClient.describeSecurityGroupsInRegion(null)) for (SecurityGroup secgroup : securityGroupClient.describeSecurityGroupsInRegion(null))
if (group.getName().startsWith("jclouds#" + tag) || group.getName().equals(tag)) { if (secgroup.getName().startsWith("jclouds#" + group) || secgroup.getName().equals(group)) {
securityGroupClient.deleteSecurityGroupInRegion(null, group.getName()); securityGroupClient.deleteSecurityGroupInRegion(null, secgroup.getName());
} }
} catch (Exception e) { } catch (Exception e) {
} }
try { try {
for (KeyPair pair : keyPairClient.describeKeyPairsInRegion(null)) for (KeyPair pair : keyPairClient.describeKeyPairsInRegion(null))
if (pair.getKeyName().startsWith("jclouds#" + tag) || pair.getKeyName().equals(tag)) { if (pair.getKeyName().startsWith("jclouds#" + group) || pair.getKeyName().equals(group)) {
keyPairClient.deleteKeyPairInRegion(null, pair.getKeyName()); keyPairClient.deleteKeyPairInRegion(null, pair.getKeyName());
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -46,7 +46,7 @@ import com.google.inject.Module;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live") @Test(groups = "live")
public class TestCanRecreateTagLiveTest { public class TestCanRecreateGroupLiveTest {
private ComputeServiceContext context; private ComputeServiceContext context;
protected String provider = "ec2"; protected String provider = "ec2";
@ -85,21 +85,21 @@ public class TestCanRecreateTagLiveTest {
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides);
} }
public void testCanRecreateTag() throws Exception { public void testCanRecreateGroup() throws Exception {
String tag = PREFIX + "recreate"; String tag = PREFIX + "recreate";
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
try { try {
Template template = context.getComputeService().templateBuilder().locationId("us-west-1").build(); Template template = context.getComputeService().templateBuilder().locationId("us-west-1").build();
context.getComputeService().runNodesWithTag(tag, 1, template); context.getComputeService().createNodesInGroup(tag, 1, template);
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
context.getComputeService().runNodesWithTag(tag, 1, template); context.getComputeService().createNodesInGroup(tag, 1, template);
} catch (RunNodesException e) { } catch (RunNodesException e) {
System.err.println(e.getNodeErrors().keySet()); System.err.println(e.getNodeErrors().keySet());
Throwables.propagate(e); Throwables.propagate(e);
} finally { } finally {
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
} }
} }

View File

@ -1,833 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ec2.compute.functions;
import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class CredentialsForInstanceTest {
DateService dateService = new SimpleDateFormatDateService();
// @SuppressWarnings({ "unchecked" })
// @Test
// public void testApplyWithEBSWhenBootIsInstanceStoreAndAvailabilityZoneNotFound() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m1_small().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
// Image image = createMock(Image.class);
//
// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.of("default")).atLeastOnce();
// expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(location));
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// expect(instance.getIpAddress()).andReturn("174.129.1.50");
// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
//
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
//
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
//
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
// (Set) ImmutableSet.<Image> of(image));
//
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
//
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
// new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
//
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
//
// expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
// expect(instance.getEbsBlockDevices()).andReturn(
// ImmutableMap.<String, EbsBlockDevice> of(
// "/dev/sdg",
// new EbsBlockDevice("vol-1f20d376", Attachment.Status.ATTACHED, dateService
// .iso8601DateParse("2009-12-11T16:32:46.000Z"), false),
// "/dev/sdj",
// new EbsBlockDevice("vol-c0eb78aa", Attachment.Status.ATTACHED, dateService
// .iso8601DateParse("2010-06-17T10:43:28.000Z"), false)));
// expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
// expect(instance.getRootDeviceName()).andReturn(null).atLeastOnce();
//
// replay(imageMap);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
// replay(jcImage);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
//
// assertEquals(metadata.getTag(), "NOTAG#i-3d640055");
// assertEquals(metadata.getLocation(), null);
// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
// assertEquals(metadata.getHardware().getId(), "m1.small");
// assertEquals(metadata.getHardware().getName(), "m1.small");
// assertEquals(metadata.getHardware().getProviderId(), "m1.small");
// assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
// assertEquals(metadata.getHardware().getRam(), 1740);
// assertEquals(metadata.getHardware().getVolumes(),
// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
// new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false),//
// new VolumeImpl("vol-1f20d376", Volume.Type.SAN, null, "/dev/sdg", false, true),//
// new VolumeImpl("vol-c0eb78aa", Volume.Type.SAN, null, "/dev/sdj", false, true)));
//
// assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
//
// }
//
// @SuppressWarnings({ "unchecked" })
// @Test
// public void testApplyForNovaWhereNullAvailabilityZoneIpAddressNoGroups() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m1_small().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
// Image image = createMock(Image.class);
//
// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
// expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(region));
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// expect(instance.getIpAddress()).andReturn(null);
// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
//
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
//
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
//
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
// (Set) ImmutableSet.<Image> of(image));
//
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
//
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
//
// expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce();
//
// expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
// expect(instance.getEbsBlockDevices()).andReturn(Maps.<String, EbsBlockDevice> newHashMap());
// expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
//
// replay(imageMap);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
// replay(jcImage);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
//
// assertEquals(metadata.getTag(), "NOTAG#i-3d640055");
// assertEquals(metadata.getLocation(), region);
// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
// assertEquals(metadata.getHardware().getId(), "m1.small");
// assertEquals(metadata.getHardware().getName(), "m1.small");
// assertEquals(metadata.getHardware().getProviderId(), "m1.small");
// assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
// assertEquals(metadata.getHardware().getRam(), 1740);
// assertEquals(metadata.getHardware().getVolumes(),
// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
// new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
//
// assertEquals(metadata.getCredentials(), new Credentials("user", null));
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
//
// }
//
// @SuppressWarnings({ "unchecked" })
// @Test
// public void testApplyWhereUnknownInstanceType() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m1_small().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
// Image image = createMock(Image.class);
//
// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
// expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(region));
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// expect(instance.getIpAddress()).andReturn(null);
// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
//
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
//
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
//
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
// (Set) ImmutableSet.<Image> of(image));
//
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
//
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
//
// expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce();
//
// expect(instance.getInstanceType()).andReturn("hhttpp").atLeastOnce();
//
// replay(imageMap);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
// replay(jcImage);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
//
// assertEquals(metadata.getTag(), "NOTAG#i-3d640055");
// assertEquals(metadata.getLocation(), region);
// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
// assertEquals(metadata.getHardware(), null);
//
// assertEquals(metadata.getCredentials(), new Credentials("user", null));
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
//
// }
//
// @SuppressWarnings({ "unchecked" })
// @Test
// public void testApplyForNovaWhereImageNotFound() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m1_small().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
//
// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
// expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(region));
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// expect(instance.getIpAddress()).andReturn(null);
// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
//
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
//
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
//
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
// (Set) ImmutableSet.<Image> of());
//
// expect(credentialProvider.execute(null)).andReturn(new Credentials("root", null));
//
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
//
// expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce();
//
// expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
// expect(instance.getEbsBlockDevices()).andReturn(Maps.<String, EbsBlockDevice> newHashMap());
// expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
//
// replay(imageMap);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
// replay(jcImage);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
//
// assertEquals(metadata.getTag(), "NOTAG#i-3d640055");
// assertEquals(metadata.getLocation(), region);
// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
// assertEquals(metadata.getHardware().getId(), "m1.small");
// assertEquals(metadata.getHardware().getName(), "m1.small");
// assertEquals(metadata.getHardware().getProviderId(), "m1.small");
// assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
// assertEquals(metadata.getHardware().getRam(), 1740);
// assertEquals(metadata.getHardware().getVolumes(),
// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
// new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
//
// assertEquals(metadata.getCredentials(), new Credentials("root", null));
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
//
// }
//
// @SuppressWarnings("unchecked")
// @Test
// public void testImageNotFoundAndLazyReturnsNull() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
//
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
//
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(location));
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m2_4xlarge().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
//
// expect(instance.getId()).andReturn("id").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
//
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
//
// expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andReturn(null);
//
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
//
// replay(imageMap);
// replay(jcImage);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
// assertEquals(metadata.getTag(), "NOTAG#id");
// assertEquals(metadata.getCredentials(), null);
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
// }
//
// @SuppressWarnings("unchecked")
// @Test
// public void testImageNotFoundStillSetsImageId() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
//
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(location));
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m2_4xlarge().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
//
// expect(instance.getId()).andReturn("id").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
//
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
//
// expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andThrow(new NullPointerException())
// .atLeastOnce();
//
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
//
// replay(imageMap);
// replay(jcImage);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
// assertEquals(metadata.getTag(), "NOTAG#id");
// assertEquals(metadata.getCredentials(), null);
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
// }
//
// @SuppressWarnings("unchecked")
// @Test
// public void testImageNotFoundAndLazySucceeds() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
//
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(location));
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m2_4xlarge().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
//
// expect(instance.getId()).andReturn("id").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
//
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
//
// org.jclouds.compute.domain.Image lateImage = createMock(org.jclouds.compute.domain.Image.class);
//
// expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andReturn(lateImage).atLeastOnce();
// expect(lateImage.getId()).andReturn("us-east-1/imageId").atLeastOnce();
// expect(lateImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
//
// replay(lateImage);
// replay(imageMap);
// replay(jcImage);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
// assertEquals(metadata.getImageId(), lateImage.getId());
// assertEquals(metadata.getTag(), "NOTAG#id");
// assertEquals(metadata.getCredentials(), null);
//
// verify(lateImage);
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
// }
//
// @SuppressWarnings("unchecked")
// @Test
// public void testApplyWithNoSecurityGroupCreatesTagOfIdPrefixedByTagAndNullCredentials() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
//
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(location));
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m2_4xlarge().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
//
// expect(instance.getId()).andReturn("id").atLeastOnce();
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
//
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
//
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
//
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
//
// replay(imageMap);
// replay(jcImage);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
// assertEquals(metadata.getTag(), "NOTAG#id");
// assertEquals(metadata.getCredentials(), null);
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
// }
//
// @SuppressWarnings("unchecked")
// @Test
// public void testApplyWithNoKeyPairCreatesTagOfParsedSecurityGroupAndNullCredentials() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
//
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(location));
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m2_4xlarge().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
//
// expect(instance.getId()).andReturn("id").atLeastOnce();
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce();
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
//
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
//
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
//
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
//
// replay(imageMap);
// replay(jcImage);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
// assertEquals(metadata.getTag(), "tag");
// assertEquals(metadata.getCredentials(), null);
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
// }
//
// @SuppressWarnings({ "unchecked" })
// @Test
// public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m2_4xlarge().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
// Image image = createMock(Image.class);
//
// expect(instance.getId()).andReturn("id").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce();
// expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(location));
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
//
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
//
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
//
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn(
// (Set) ImmutableSet.<Image> of(image));
//
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
//
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
// new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
//
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
//
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
//
// replay(imageMap);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
// replay(jcImage);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
// NodeMetadata metadata = parser.apply(instance);
//
// assertEquals(metadata.getTag(), "tag");
// assertEquals(metadata.getLocation(), location);
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
//
// assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
//
// }
//
// @SuppressWarnings({ "unchecked" })
// @Test
// public void testApplyWithTwoSecurityGroups() throws UnknownHostException {
// EC2Client client = createMock(EC2Client.class);
// AMIClient amiClient = createMock(AMIClient.class);
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
// .<Hardware> of(m2_4xlarge().build()));
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
// RunningInstance instance = createMock(RunningInstance.class);
// Image image = createMock(Image.class);
//
// expect(instance.getId()).andReturn("id").atLeastOnce();
// expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds1", "jclouds2")).atLeastOnce();
// expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce();
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
//
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
// .<Location> of(location));
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
//
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
//
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
//
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
//
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
//
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn(
// (Set) ImmutableSet.<Image> of(image));
//
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
//
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
// new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
//
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
//
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
//
// replay(imageMap);
// replay(client);
// replay(amiClient);
// replay(credentialsMap);
// replay(credentialProvider);
// replay(instance);
// replay(jcImage);
//
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
// credentialProvider, imageMap, locations, hardwares);
//
// NodeMetadata metadata = parser.apply(instance);
//
// assertEquals(metadata.getTag(), "NOTAG#id");
// assertEquals(metadata.getLocation(), location);
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
//
// assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
//
// verify(imageMap);
// verify(jcImage);
// verify(client);
// verify(amiClient);
// verify(credentialsMap);
// verify(credentialProvider);
// verify(instance);
//
// }
}

View File

@ -83,8 +83,8 @@ public class RunningInstanceToNodeMetadataTest {
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).publicAddresses( assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).publicAddresses(
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses( ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(
ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f").credentials(creds).imageId( ImmutableSet.of("174.129.81.68")).credentials(creds).imageId("us-east-1/ami-82e4b5c7").id(
"us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").build()); "us-east-1/i-0799056f").providerId("i-0799056f").build());
} }
@Test @Test
@ -96,8 +96,8 @@ public class RunningInstanceToNodeMetadataTest {
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).publicAddresses( assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).publicAddresses(
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses( ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(
ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").id( ImmutableSet.of("174.129.81.68")).imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f")
"us-east-1/i-0799056f").providerId("i-0799056f").build()); .providerId("i-0799056f").build());
} }
@Test @Test
@ -108,9 +108,8 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses( assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag( ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId(
"NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f") "us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build());
.providerId("i-0799056f").location(provider).build());
} }
@Test @Test
@ -121,8 +120,8 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses( assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag( ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId(
"NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").operatingSystem( "us-east-1/ami-82e4b5c7").operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description( new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description(
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f") "137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f")
.providerId("i-0799056f").location(provider).build()); .providerId("i-0799056f").location(provider).build());
@ -137,8 +136,8 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses( assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag( ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId(
"NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").hardware(m1_small().build()).operatingSystem( "us-east-1/ami-82e4b5c7").hardware(m1_small().build()).operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description( new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description(
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f") "137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f")
.providerId("i-0799056f").location(provider).build()); .providerId("i-0799056f").location(provider).build());
@ -166,9 +165,9 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses( assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag( ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId(
"NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f") "us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").hardware(
.providerId("i-0799056f").hardware(m1_small().build()).location(provider).build()); m1_small().build()).location(provider).build());
} }
protected RunningInstance firstInstanceFromResource(String resource) { protected RunningInstance firstInstanceFromResource(String resource) {

View File

@ -99,7 +99,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
String imageId = "ami1"; String imageId = "ami1";
String instanceCreatedId = "instance1"; String instanceCreatedId = "instance1";
// setup mocks // setup mocks
EC2RunNodesAndAddToSetStrategy strategy = setupStrategy(); EC2CreateNodesInGroupThenAddToSet strategy = setupStrategy();
InputParams input = new InputParams(location); InputParams input = new InputParams(location);
InstanceClient instanceClient = createMock(InstanceClient.class); InstanceClient instanceClient = createMock(InstanceClient.class);
RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class); RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class);
@ -200,7 +200,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
} }
} }
private void verifyStrategy(EC2RunNodesAndAddToSetStrategy strategy) { private void verifyStrategy(EC2CreateNodesInGroupThenAddToSet strategy) {
verify(strategy.createKeyPairAndSecurityGroupsAsNeededAndReturncustomize); verify(strategy.createKeyPairAndSecurityGroupsAsNeededAndReturncustomize);
verify(strategy.client); verify(strategy.client);
verify(strategy.instancePresent); verify(strategy.instancePresent);
@ -211,7 +211,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private EC2RunNodesAndAddToSetStrategy setupStrategy() { private EC2CreateNodesInGroupThenAddToSet setupStrategy() {
EC2Client client = createMock(EC2Client.class); EC2Client client = createMock(EC2Client.class);
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize = createMock(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class); CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize = createMock(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class);
Predicate<RunningInstance> instanceStateRunning = createMock(Predicate.class); Predicate<RunningInstance> instanceStateRunning = createMock(Predicate.class);
@ -219,11 +219,11 @@ public class EC2RunNodesAndAddToSetStrategyTest {
Function<RunningInstance, Credentials> instanceToCredentials = createMock(Function.class); Function<RunningInstance, Credentials> instanceToCredentials = createMock(Function.class);
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, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, return new EC2CreateNodesInGroupThenAddToSet(client, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
instanceStateRunning, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils); instanceStateRunning, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils);
} }
private void replayStrategy(EC2RunNodesAndAddToSetStrategy strategy) { private void replayStrategy(EC2CreateNodesInGroupThenAddToSet strategy) {
replay(strategy.createKeyPairAndSecurityGroupsAsNeededAndReturncustomize); replay(strategy.createKeyPairAndSecurityGroupsAsNeededAndReturncustomize);
replay(strategy.client); replay(strategy.client);
replay(strategy.instancePresent); replay(strategy.instancePresent);

View File

@ -86,7 +86,7 @@ public class ElasticStackComputeServiceAdapter implements
} }
@Override @Override
public ServerInfo runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, public ServerInfo createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore) { Map<String, Credentials> credentialStore) {
long bootSize = (long) (template.getHardware().getVolumes().get(0).getSize() * 1024 * 1024 * 1024l); long bootSize = (long) (template.getHardware().getVolumes().get(0).getSize() * 1024 * 1024 * 1024l);
logger.debug(">> creating boot drive bytes(%d)", bootSize); logger.debug(">> creating boot drive bytes(%d)", bootSize);

View File

@ -20,7 +20,7 @@
package org.jclouds.elasticstack.compute.functions; package org.jclouds.elasticstack.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -92,7 +92,7 @@ public class ServerInfoToNodeMetadata implements Function<ServerInfo, NodeMetada
builder.ids(from.getUuid()); builder.ids(from.getUuid());
builder.name(from.getName()); builder.name(from.getName());
builder.location(locationSupplier.get()); builder.location(locationSupplier.get());
builder.tag(parseTagFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
String imageId = getImageIdFromServer.apply(from); String imageId = getImageIdFromServer.apply(from);
if (imageId != null) { if (imageId != null) {

View File

@ -65,7 +65,7 @@ public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveT
Set<? extends LoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(null); Set<? extends LoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(null);
assertNotNull(elbs); assertNotNull(elbs);
for (LoadBalancer elb : elbs) { for (LoadBalancer elb : elbs) {
if (elb.getName().equals(tag)) if (elb.getName().equals(group))
assertEquals(elb.getInstanceIds(), instanceIds); assertEquals(elb.getInstanceIds(), instanceIds);
} }
} }

View File

@ -38,7 +38,7 @@ public class EucalyptusComputeServiceLiveTest extends EC2ComputeServiceLiveTest
public EucalyptusComputeServiceLiveTest() { public EucalyptusComputeServiceLiveTest() {
provider = "eucalyptus"; provider = "eucalyptus";
// security groups must be <30 characters // security groups must be <30 characters
tag = "eu"; group = "eu";
} }
@Override @Override

View File

@ -66,7 +66,7 @@ public class BindCaptureVAppParamsToXmlPayload implements MapBinder {
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); checkState(gRequest.getArgs() != null, "args should be initialized at this point");

View File

@ -94,7 +94,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); checkState(gRequest.getArgs() != null, "args should be initialized at this point");

View File

@ -19,14 +19,14 @@
package org.jclouds.vcloud.compute.config; package org.jclouds.vcloud.compute.config;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy; import org.jclouds.vcloud.compute.strategy.InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn;
import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy; import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy;
@ -36,8 +36,8 @@ import org.jclouds.vcloud.compute.strategy.VCloudLifeCycleStrategy;
*/ */
public class VCloudBindComputeStrategiesByClass extends CommonVCloudBindComputeStrategiesByClass { public class VCloudBindComputeStrategiesByClass extends CommonVCloudBindComputeStrategiesByClass {
@Override @Override
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() { protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
return VCloudAddNodeWithTagStrategy.class; return InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.class;
} }
@Override @Override

View File

@ -20,7 +20,7 @@
package org.jclouds.vcloud.compute.functions; package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom; import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom;
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getPrivateIpsFromVApp; import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getPrivateIpsFromVApp;
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getPublicIpsFromVApp; import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getPublicIpsFromVApp;
@ -71,12 +71,7 @@ public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
builder.uri(from.getHref()); builder.uri(from.getHref());
builder.name(from.getName()); builder.name(from.getName());
builder.location(findLocationForResourceInVDC.apply(from.getVDC())); builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
String tag = parseTagFromName(from.getName()); builder.group(parseGroupFromName(from.getName()));
builder.tag(tag);
if (logger.isTraceEnabled()) {
if (tag.startsWith("NOTAG#"))
logger.warn("failed to parse tag from name %s", from);
}
builder.operatingSystem(toComputeOs(from, null)); builder.operatingSystem(toComputeOs(from, null));
builder.hardware(hardwareForVApp.apply(from)); builder.hardware(hardwareForVApp.apply(from));
builder.state(vAppStatusToNodeState.get(from.getStatus())); builder.state(vAppStatusToNodeState.get(from.getStatus()));

View File

@ -32,7 +32,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
@ -50,7 +50,7 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy { public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn implements CreateNodeWithGroupEncodedIntoName {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -60,7 +60,7 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
protected final Predicate<URI> successTester; protected final Predicate<URI> successTester;
@Inject @Inject
protected VCloudAddNodeWithTagStrategy(Predicate<URI> successTester, VCloudClient client, protected InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn(Predicate<URI> successTester, VCloudClient client,
GetNodeMetadataStrategy getNode) { GetNodeMetadataStrategy getNode) {
this.client = client; this.client = client;
this.successTester = successTester; this.successTester = successTester;
@ -68,7 +68,7 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
} }
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata createNodeWithGroupEncodedIntoName(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory(
template.getHardware().getRam()).disk( template.getHardware().getRam()).disk(
(long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l)); (long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l));

View File

@ -51,7 +51,7 @@ public class CaptureVAppLiveTest {
protected ComputeService client; protected ComputeService client;
protected String tag = System.getProperty("user.name") + "cap"; protected String group = System.getProperty("user.name") + "cap";
protected String provider = "vcloud"; protected String provider = "vcloud";
protected String identity; protected String identity;
@ -94,7 +94,7 @@ public class CaptureVAppLiveTest {
VAppTemplate vappTemplate = null; VAppTemplate vappTemplate = null;
try { try {
node = getOnlyElement(client.runNodesWithTag(tag, 1)); node = getOnlyElement(client.createNodesInGroup(group, 1));
VCloudClient vcloudApi = VCloudClient.class.cast(client.getContext().getProviderSpecificContext().getApi()); VCloudClient vcloudApi = VCloudClient.class.cast(client.getContext().getProviderSpecificContext().getApi());
@ -117,7 +117,7 @@ public class CaptureVAppLiveTest {
// vdc is equiv to the node's location // vdc is equiv to the node's location
// vapp uri is the same as the node's id // vapp uri is the same as the node's id
vappTemplate = vcloudApi.captureVAppInVDC(URI.create(node.getLocation().getId()), URI.create(node.getId()), vappTemplate = vcloudApi.captureVAppInVDC(URI.create(node.getLocation().getId()), URI.create(node.getId()),
tag); group);
task = vappTemplate.getTasks().get(0); task = vappTemplate.getTasks().get(0);

View File

@ -50,7 +50,7 @@ import com.google.inject.Module;
/** /**
* This tests that we can use guest customization as an alternative to bootstrapping with ssh. There * This tests that we can use guest customization as an alternative to bootstrapping with ssh. There
* are a few advantages to this, including the fact that it can work inside google appengine where * are a few advangroupes to this, including the fact that it can work inside google appengine where
* network sockets (ssh:22) are prohibited. * network sockets (ssh:22) are prohibited.
* *
* @author Adrian Cole * @author Adrian Cole
@ -110,7 +110,7 @@ public class VCloudGuestCustomizationLiveTest {
@Test @Test
public void testExtendedOptionsWithCustomizationScript() throws Exception { public void testExtendedOptionsWithCustomizationScript() throws Exception {
String tag = "customize"; String group = "customize";
String script = "cat > /root/foo.txt<<EOF\nI love candy\nEOF\n"; String script = "cat > /root/foo.txt<<EOF\nI love candy\nEOF\n";
TemplateOptions options = client.templateOptions(); TemplateOptions options = client.templateOptions();
@ -119,7 +119,7 @@ public class VCloudGuestCustomizationLiveTest {
NodeMetadata node = null; NodeMetadata node = null;
try { try {
node = getOnlyElement(client.runNodesWithTag(tag, 1, options)); node = getOnlyElement(client.createNodesInGroup(group, 1, options));
IPSocket socket = new IPSocket(get(node.getPublicAddresses(), 0), 22); IPSocket socket = new IPSocket(get(node.getPublicAddresses(), 0), 22);

View File

@ -87,7 +87,7 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); checkState(gRequest.getArgs() != null, "args should be initialized at this point");

View File

@ -19,14 +19,14 @@
package org.jclouds.vcloud.compute.config; package org.jclouds.vcloud.compute.config;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressAddNodeWithTagStrategy; import org.jclouds.vcloud.compute.strategy.StartVAppWithGroupEncodedIntoName;
import org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy; import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy; import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy;
@ -38,8 +38,8 @@ import org.jclouds.vcloud.compute.strategy.VCloudExpressLifeCycleStrategy;
public class VCloudExpressBindComputeStrategiesByClass extends CommonVCloudBindComputeStrategiesByClass { public class VCloudExpressBindComputeStrategiesByClass extends CommonVCloudBindComputeStrategiesByClass {
@Override @Override
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() { protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
return VCloudExpressAddNodeWithTagStrategy.class; return StartVAppWithGroupEncodedIntoName.class;
} }
@Override @Override

View File

@ -20,7 +20,7 @@
package org.jclouds.vcloud.compute.functions; package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -75,7 +75,7 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
builder.uri(from.getHref()); builder.uri(from.getHref());
builder.name(from.getName()); builder.name(from.getName());
builder.location(findLocationForResourceInVDC.apply(from.getVDC())); builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
builder.tag(parseTagFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
builder.operatingSystem(from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType builder.operatingSystem(from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType
.fromValue(from.getOsType()), null, null, from.getOperatingSystemDescription()) : null); .fromValue(from.getOsType()), null, null, from.getOperatingSystemDescription()) : null);
builder.hardware(hardwareForVCloudExpressVApp.apply(from)); builder.hardware(hardwareForVCloudExpressVApp.apply(from));

View File

@ -29,7 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient; import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
@ -41,13 +41,13 @@ import com.google.common.base.Function;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrategy { public class StartVAppWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName {
protected final VCloudExpressClient client; protected final VCloudExpressClient client;
protected final VCloudExpressComputeClient computeClient; protected final VCloudExpressComputeClient computeClient;
protected final Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata; protected final Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata;
@Inject @Inject
protected VCloudExpressAddNodeWithTagStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient, protected StartVAppWithGroupEncodedIntoName(VCloudExpressClient client, VCloudExpressComputeClient computeClient,
Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata) { Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata) {
this.client = client; this.client = client;
this.computeClient = computeClient; this.computeClient = computeClient;
@ -55,7 +55,7 @@ public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrate
} }
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata createNodeWithGroupEncodedIntoName(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory(
template.getHardware().getRam()).disk( template.getHardware().getRam()).disk(
(long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l)); (long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l));

View File

@ -45,7 +45,7 @@ import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -69,7 +69,7 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
protected TerremarkVCloudComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore, protected TerremarkVCloudComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy, ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider, Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,

View File

@ -19,23 +19,23 @@
package org.jclouds.vcloud.terremark.compute.config; package org.jclouds.vcloud.terremark.compute.config;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.vcloud.compute.config.VCloudExpressBindComputeStrategiesByClass; import org.jclouds.vcloud.compute.config.VCloudExpressBindComputeStrategiesByClass;
import org.jclouds.vcloud.terremark.compute.strategy.TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.vcloud.terremark.compute.strategy.TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.vcloud.terremark.compute.strategy.TerremarkVCloudAddNodeWithTagStrategy; import org.jclouds.vcloud.terremark.compute.strategy.StartVAppWithGroupEncodedIntoName;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class TerremarkBindComputeStrategiesByClass extends VCloudExpressBindComputeStrategiesByClass { public class TerremarkBindComputeStrategiesByClass extends VCloudExpressBindComputeStrategiesByClass {
@Override @Override
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() { protected Class<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
return TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.class; return TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.class;
} }
@Override @Override
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() { protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
return TerremarkVCloudAddNodeWithTagStrategy.class; return StartVAppWithGroupEncodedIntoName.class;
} }
} }

View File

@ -61,12 +61,12 @@ public class NodeMetadataToOrgAndName implements Function<NodeMetadata, OrgAndNa
@Override @Override
public OrgAndName apply(NodeMetadata from) { public OrgAndName apply(NodeMetadata from) {
if (from.getTag() != null) { if (from.getGroup() != null) {
Org org = client.findOrgNamed(vdcToOrg.get().get(from.getLocation().getId())); Org org = client.findOrgNamed(vdcToOrg.get().get(from.getLocation().getId()));
if (org == null) { if (org == null) {
logger.warn("did not find an association for vdc %s in %s", from.getLocation().getId(), vdcToOrg); logger.warn("did not find an association for vdc %s in %s", from.getLocation().getId(), vdcToOrg);
} else { } else {
return new OrgAndName(org.getHref(), from.getTag()); return new OrgAndName(org.getHref(), from.getGroup());
} }
} }
return null; return null;

View File

@ -69,7 +69,7 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT
NodeMetadata node = super.apply(from); NodeMetadata node = super.apply(from);
if (node == null) if (node == null)
return null; return null;
if (node.getTag() != null) { if (node.getGroup() != null) {
node = installCredentialsFromCache(node); node = installCredentialsFromCache(node);
} }
return node; return node;
@ -94,7 +94,7 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT
OrgAndName getOrgAndNameFromNode(NodeMetadata node) { OrgAndName getOrgAndNameFromNode(NodeMetadata node) {
URI orgId = URI.create(node.getLocation().getParent().getId()); URI orgId = URI.create(node.getLocation().getParent().getId());
OrgAndName orgAndName = new OrgAndName(orgId, node.getTag()); OrgAndName orgAndName = new OrgAndName(orgId, node.getGroup());
return orgAndName; return orgAndName;
} }

View File

@ -26,7 +26,7 @@ import static com.google.common.collect.Iterables.size;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED; import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
import static org.jclouds.compute.predicates.NodePredicates.parentLocationId; import static org.jclouds.compute.predicates.NodePredicates.parentLocationId;
import static org.jclouds.compute.predicates.NodePredicates.withTag; import static org.jclouds.compute.predicates.NodePredicates.inGroup;
import java.util.Map; import java.util.Map;
@ -68,13 +68,13 @@ public class CleanupOrphanKeys {
credentialStore.remove("node#" + node.getId()); credentialStore.remove("node#" + node.getId());
credentialStore.remove("node#" + node.getId() + "#adminPassword"); credentialStore.remove("node#" + node.getId() + "#adminPassword");
} }
Iterable<OrgAndName> orgTags = filter(transform(deadOnes, nodeToOrgAndName), notNull()); Iterable<OrgAndName> orgGroups = filter(transform(deadOnes, nodeToOrgAndName), notNull());
for (OrgAndName orgTag : orgTags) { for (OrgAndName orgGroup : orgGroups) {
Iterable<? extends NodeMetadata> nodesInOrg = listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag Iterable<? extends NodeMetadata> nodesInOrg = listNodes.listDetailsOnNodesMatching(parentLocationId(orgGroup
.getOrg().toASCIIString())); .getOrg().toASCIIString()));
Iterable<? extends NodeMetadata> nodesWithTag = filter(nodesInOrg, withTag(orgTag.getName())); Iterable<? extends NodeMetadata> nodesInGroup = filter(nodesInOrg, inGroup(orgGroup.getName()));
if (size(nodesWithTag) == 0 || all(nodesWithTag, TERMINATED)) if (size(nodesInGroup) == 0 || all(nodesInGroup, TERMINATED))
deleteKeyPair.execute(orgTag); deleteKeyPair.execute(orgGroup);
} }
} }

View File

@ -30,7 +30,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient; import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient;
@ -43,14 +43,14 @@ import com.google.common.base.Function;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class TerremarkVCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy { public class StartVAppWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName {
protected final TerremarkVCloudComputeClient computeClient; protected final TerremarkVCloudComputeClient computeClient;
protected final TemplateToInstantiateOptions getOptions; protected final TemplateToInstantiateOptions getOptions;
protected final Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata; protected final Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata;
private final Map<String, Credentials> credentialStore; private final Map<String, Credentials> credentialStore;
@Inject @Inject
protected TerremarkVCloudAddNodeWithTagStrategy(TerremarkVCloudComputeClient computeClient, protected StartVAppWithGroupEncodedIntoName(TerremarkVCloudComputeClient computeClient,
Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata, TemplateToInstantiateOptions getOptions, Function<VCloudExpressVApp, NodeMetadata> vAppToNodeMetadata, TemplateToInstantiateOptions getOptions,
Map<String, Credentials> credentialStore) { Map<String, Credentials> credentialStore) {
this.computeClient = computeClient; this.computeClient = computeClient;
@ -60,7 +60,7 @@ public class TerremarkVCloudAddNodeWithTagStrategy implements AddNodeWithTagStra
} }
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
TerremarkInstantiateVAppTemplateOptions options = getOptions.apply(template); TerremarkInstantiateVAppTemplateOptions options = getOptions.apply(template);
VCloudExpressVApp vApp = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template VCloudExpressVApp vApp = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template
.getImage().getId()), name, options, template.getOptions().getInboundPorts()); .getImage().getId()), name, options, template.getOptions().getInboundPorts());

View File

@ -33,10 +33,10 @@ import org.jclouds.Constants;
import org.jclouds.compute.config.CustomizationResponse; import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap; import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions; import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions;
@ -48,13 +48,13 @@ import com.google.common.collect.Multimap;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy extends EncodeTagIntoNameRunNodesAndAddToSetStrategy { public class TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy extends CreateNodesWithGroupEncodedIntoNameThenAddToSet {
private final CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise; private final CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise;
@Inject @Inject
protected TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy( protected TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy(
AddNodeWithTagStrategy addNodeWithTagStrategy, CreateNodeWithGroupEncodedIntoName addNodeWithTagStrategy,
ListNodesStrategy listNodesStrategy, ListNodesStrategy listNodesStrategy,
@Named("NAMING_CONVENTION") String nodeNamingConvention, @Named("NAMING_CONVENTION") String nodeNamingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,

View File

@ -88,13 +88,13 @@ public class CleanupOrphanKeysTest {
CleanupOrphanKeys strategy = setupStrategy(); CleanupOrphanKeys strategy = setupStrategy();
NodeMetadata nodeMetadata = createMock(NodeMetadata.class); NodeMetadata nodeMetadata = createMock(NodeMetadata.class);
Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata); Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata);
OrgAndName orgTag = new OrgAndName(URI.create("location"), "tag"); OrgAndName orgTag = new OrgAndName(URI.create("location"), "group");
// setup expectations // setup expectations
expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce(); expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce();
expect((Object) strategy.listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag.getOrg().toASCIIString()))) expect((Object) strategy.listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag.getOrg().toASCIIString())))
.andReturn(ImmutableSet.of(nodeMetadata)); .andReturn(ImmutableSet.of(nodeMetadata));
expect(nodeMetadata.getTag()).andReturn(orgTag.getName()).atLeastOnce(); expect(nodeMetadata.getGroup()).andReturn(orgTag.getName()).atLeastOnce();
expect(nodeMetadata.getState()).andReturn(NodeState.RUNNING).atLeastOnce(); expect(nodeMetadata.getState()).andReturn(NodeState.RUNNING).atLeastOnce();
expectCleanupCredentialStore(strategy, nodeMetadata); expectCleanupCredentialStore(strategy, nodeMetadata);
@ -115,13 +115,13 @@ public class CleanupOrphanKeysTest {
CleanupOrphanKeys strategy = setupStrategy(); CleanupOrphanKeys strategy = setupStrategy();
NodeMetadata nodeMetadata = createMock(NodeMetadata.class); NodeMetadata nodeMetadata = createMock(NodeMetadata.class);
Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata); Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata);
OrgAndName orgTag = new OrgAndName(URI.create("location"), "tag"); OrgAndName orgTag = new OrgAndName(URI.create("location"), "group");
// setup expectations // setup expectations
expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce(); expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce();
expect((Object) strategy.listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag.getOrg().toASCIIString()))) expect((Object) strategy.listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag.getOrg().toASCIIString())))
.andReturn(ImmutableSet.of(nodeMetadata)); .andReturn(ImmutableSet.of(nodeMetadata));
expect(nodeMetadata.getTag()).andReturn(orgTag.getName()).atLeastOnce(); expect(nodeMetadata.getGroup()).andReturn(orgTag.getName()).atLeastOnce();
expect(nodeMetadata.getState()).andReturn(NodeState.TERMINATED).atLeastOnce(); expect(nodeMetadata.getState()).andReturn(NodeState.TERMINATED).atLeastOnce();
strategy.deleteKeyPair.execute(orgTag); strategy.deleteKeyPair.execute(orgTag);
expectCleanupCredentialStore(strategy, nodeMetadata); expectCleanupCredentialStore(strategy, nodeMetadata);
@ -149,7 +149,7 @@ public class CleanupOrphanKeysTest {
CleanupOrphanKeys strategy = setupStrategy(); CleanupOrphanKeys strategy = setupStrategy();
NodeMetadata nodeMetadata = createMock(NodeMetadata.class); NodeMetadata nodeMetadata = createMock(NodeMetadata.class);
Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata); Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata);
OrgAndName orgTag = new OrgAndName(URI.create("location"), "tag"); OrgAndName orgTag = new OrgAndName(URI.create("location"), "group");
// setup expectations // setup expectations
expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce(); expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce();

View File

@ -66,7 +66,7 @@ public class BindCloneVAppParamsToXmlPayload implements MapBinder {
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); checkState(gRequest.getArgs() != null, "args should be initialized at this point");

View File

@ -20,8 +20,8 @@
package org.jclouds.vcloud.compute.config; package org.jclouds.vcloud.compute.config;
import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -29,8 +29,8 @@ import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStr
public abstract class CommonVCloudBindComputeStrategiesByClass extends BindComputeStrategiesByClass { public abstract class CommonVCloudBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
@Override @Override
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() { protected Class<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
return EncodeTagIntoNameRunNodesAndAddToSetStrategy.class; return CreateNodesWithGroupEncodedIntoNameThenAddToSet.class;
} }
} }

View File

@ -27,7 +27,6 @@ import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.config.BindComputeSuppliersByClass; import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.location.config.LocationModule;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;

View File

@ -47,7 +47,7 @@ Here's an example of getting some compute configuration from rackspace:
(pprint (nodes)) (pprint (nodes))
(pprint (hardware-profiles))) (pprint (hardware-profiles)))
Here's an example of creating and running a small linux node with the tag Here's an example of creating and running a small linux node in the group
webserver: webserver:
;; create a compute service using ssh and log4j extensions ;; create a compute service using ssh and log4j extensions
@ -55,7 +55,7 @@ webserver:
(compute-service (compute-service
provider provider-identity provider-credential :ssh :log4j)) provider provider-identity provider-credential :ssh :log4j))
(run-node \"webserver\" compute) (create-node \"webserver\" compute)
See http://code.google.com/p/jclouds for details." See http://code.google.com/p/jclouds for details."
(:use org.jclouds.core (:use org.jclouds.core
@ -144,11 +144,11 @@ See http://code.google.com/p/jclouds for details."
([#^ComputeService compute] ([#^ComputeService compute]
(seq (.listNodesDetailsMatching compute (NodePredicates/all))))) (seq (.listNodesDetailsMatching compute (NodePredicates/all)))))
(defn nodes-with-tag (defn nodes-in-group
"list details of all the nodes with the given tag." "list details of all the nodes in the given group."
([tag] (nodes-with-tag tag *compute*)) ([group] (nodes-in-group group *compute*))
([#^String tag #^ComputeService compute] ([#^String group #^ComputeService compute]
(filter #(= (.getTag %) tag) (nodes-with-details compute)))) (filter #(= (.getTag %) group) (nodes-with-details compute))))
(defn images (defn images
"Retrieve the available images for the compute context." "Retrieve the available images for the compute context."
@ -171,66 +171,66 @@ See http://code.google.com/p/jclouds for details."
(slurp (str (. System getProperty "user.home") "/.ssh/id_rsa.pub")))) (slurp (str (. System getProperty "user.home") "/.ssh/id_rsa.pub"))))
build))) build)))
(defn run-nodes (defn create-nodes
"Create the specified number of nodes using the default or specified "Create the specified number of nodes using the default or specified
template. template.
;; Simplest way to add 2 small linux nodes to the group webserver is to run ;; Simplest way to add 2 small linux nodes to the group webserver is to run
(run-nodes \"webserver\" 2 compute) (create-nodes \"webserver\" 2 compute)
;; which is the same as wrapping the run-nodes command with an implicit ;; which is the same as wrapping the create-nodes command with an implicit
;; compute service. ;; compute service.
;; Note that this will actually add another 2 nodes to the set called ;; Note that this will actually add another 2 nodes to the set called
;; \"webserver\" ;; \"webserver\"
(with-compute-service [compute] (with-compute-service [compute]
(run-nodes \"webserver\" 2 )) (create-nodes \"webserver\" 2 ))
;; which is the same as specifying the default template ;; which is the same as specifying the default template
(with-compute-service [compute] (with-compute-service [compute]
(run-nodes \"webserver\" 2 (default-template))) (create-nodes \"webserver\" 2 (default-template)))
;; which, on gogrid, is the same as constructing the smallest centos template ;; which, on gogrid, is the same as constructing the smallest centos template
;; that has no layered software ;; that has no layered software
(with-compute-service [compute] (with-compute-service [compute]
(run-nodes \"webserver\" 2 (create-nodes \"webserver\" 2
(build-template (build-template
service service
{:os-family :centos :smallest true {:os-family :centos :smallest true
:image-name-matches \".*w/ None.*\"})))" :image-name-matches \".*w/ None.*\"})))"
([tag count] ([group count]
(run-nodes tag count (default-template *compute*) *compute*)) (create-nodes group count (default-template *compute*) *compute*))
([tag count compute-or-template] ([group count compute-or-template]
(if (compute-service? compute-or-template) (if (compute-service? compute-or-template)
(run-nodes (create-nodes
tag count (default-template compute-or-template) compute-or-template) group count (default-template compute-or-template) compute-or-template)
(run-nodes tag count compute-or-template *compute*))) (create-nodes group count compute-or-template *compute*)))
([tag count template #^ComputeService compute] ([group count template #^ComputeService compute]
(seq (seq
(.runNodesWithTag compute tag count template)))) (.createNodesInGroup compute group count template))))
(defn run-node (defn create-node
"Create a node using the default or specified template. "Create a node using the default or specified template.
;; simplest way to add a small linux node to the group webserver is to run ;; simplest way to add a small linux node to the group webserver is to run
(run-node \"webserver\" compute) (create-node \"webserver\" compute)
;; which is the same as wrapping the run-node command with an implicit compute ;; which is the same as wrapping the create-node command with an implicit compute
;; service. ;; service.
;; Note that this will actually add another node to the set called ;; Note that this will actually add another node to the set called
;; \"webserver\" ;; \"webserver\"
(with-compute-service [compute] (with-compute-service [compute]
(run-node \"webserver\" ))" (create-node \"webserver\" ))"
([tag] ([group]
(first (run-nodes tag 1 (default-template *compute*) *compute*))) (first (create-nodes group 1 (default-template *compute*) *compute*)))
([tag compute-or-template] ([group compute-or-template]
(if (compute-service? compute-or-template) (if (compute-service? compute-or-template)
(first (first
(run-nodes (create-nodes
tag 1 (default-template compute-or-template) compute-or-template)) group 1 (default-template compute-or-template) compute-or-template))
(first (run-nodes tag 1 compute-or-template *compute*)))) (first (create-nodes group 1 compute-or-template *compute*))))
([tag template compute] ([group template compute]
(first (run-nodes tag 1 template compute)))) (first (create-nodes group 1 template compute))))
(defn #^NodeMetadata node-details (defn #^NodeMetadata node-details
"Retrieve the node metadata, given its id." "Retrieve the node metadata, given its id."
@ -238,11 +238,11 @@ See http://code.google.com/p/jclouds for details."
([id #^ComputeService compute] ([id #^ComputeService compute]
(.getNodeMetadata compute id))) (.getNodeMetadata compute id)))
(defn suspend-nodes-with-tag (defn suspend-nodes-in-group
"Reboot all the nodes with the given tag." "Reboot all the nodes in the given group."
([tag] (suspend-nodes-with-tag tag *compute*)) ([group] (suspend-nodes-in-group group *compute*))
([#^String tag #^ComputeService compute] ([#^String group #^ComputeService compute]
(.suspendNodesMatching compute (NodePredicates/withTag tag)))) (.suspendNodesMatching compute (NodePredicates/inGroup group))))
(defn suspend-node (defn suspend-node
"Suspend a node, given its id." "Suspend a node, given its id."
@ -250,11 +250,11 @@ See http://code.google.com/p/jclouds for details."
([id #^ComputeService compute] ([id #^ComputeService compute]
(.suspendNode compute id))) (.suspendNode compute id)))
(defn resume-nodes-with-tag (defn resume-nodes-in-group
"Suspend all the nodes with the given tag." "Suspend all the nodes in the given group."
([tag] (resume-nodes-with-tag tag *compute*)) ([group] (resume-nodes-in-group group *compute*))
([#^String tag #^ComputeService compute] ([#^String group #^ComputeService compute]
(.resumeNodesMatching compute (NodePredicates/withTag tag)))) (.resumeNodesMatching compute (NodePredicates/inGroup group))))
(defn resume-node (defn resume-node
"Resume a node, given its id." "Resume a node, given its id."
@ -262,11 +262,11 @@ See http://code.google.com/p/jclouds for details."
([id #^ComputeService compute] ([id #^ComputeService compute]
(.resumeNode compute id))) (.resumeNode compute id)))
(defn reboot-nodes-with-tag (defn reboot-nodes-in-group
"Reboot all the nodes with the given tag." "Reboot all the nodes in the given group."
([tag] (reboot-nodes-with-tag tag *compute*)) ([group] (reboot-nodes-in-group group *compute*))
([#^String tag #^ComputeService compute] ([#^String group #^ComputeService compute]
(.rebootNodesMatching compute (NodePredicates/withTag tag)))) (.rebootNodesMatching compute (NodePredicates/inGroup group))))
(defn reboot-node (defn reboot-node
"Reboot a node, given its id." "Reboot a node, given its id."
@ -274,11 +274,11 @@ See http://code.google.com/p/jclouds for details."
([id #^ComputeService compute] ([id #^ComputeService compute]
(.rebootNode compute id))) (.rebootNode compute id)))
(defn destroy-nodes-with-tag (defn destroy-nodes-in-group
"Destroy all the nodes with the given tag." "Destroy all the nodes in the given group."
([tag] (destroy-nodes-with-tag tag *compute*)) ([group] (destroy-nodes-in-group group *compute*))
([#^String tag #^ComputeService compute] ([#^String group #^ComputeService compute]
(.destroyNodesMatching compute (NodePredicates/withTag tag)))) (.destroyNodesMatching compute (NodePredicates/inGroup group))))
(defn destroy-node (defn destroy-node
"Destroy a node, given its id." "Destroy a node, given its id."
@ -330,10 +330,10 @@ See http://code.google.com/p/jclouds for details."
[#^NodeMetadata node] [#^NodeMetadata node]
(.getPrivateAddresses node)) (.getPrivateAddresses node))
(defn tag (defn group
"Returns a the node's tag" "Returns a the node's group"
[#^NodeMetadata node] [#^NodeMetadata node]
(.getTag node)) (.getGroup node))
(defn hostname (defn hostname
"Returns the compute node's name" "Returns the compute node's name"
@ -353,7 +353,7 @@ See http://code.google.com/p/jclouds for details."
(define-accessors Template image hardware location options) (define-accessors Template image hardware location options)
(define-accessors Image version os-family os-description architecture) (define-accessors Image version os-family os-description architecture)
(define-accessors Hardware processors ram volumes) (define-accessors Hardware processors ram volumes)
(define-accessors NodeMetadata "node" credentials hardware state tag) (define-accessors NodeMetadata "node" credentials hardware state group)
(defn builder-options [builder] (defn builder-options [builder]
(or (or

View File

@ -40,7 +40,7 @@
(class ComputeService) (class ComputeService)
(defrecord ClojureComputeServiceAdapter [] (defrecord ClojureComputeServiceAdapter []
org.jclouds.compute.JCloudsNativeComputeServiceAdapter org.jclouds.compute.JCloudsNativeComputeServiceAdapter
(^NodeMetadata runNodeWithTagAndNameAndStoreCredentials [this ^String tag ^String name ^Template template ^Map credentialStore] (^NodeMetadata createNodeWithGroupEncodedIntoNameThenStoreCredentials [this ^String group ^String name ^Template template ^Map credentialStore]
()) ())
(^Iterable listNodes [this ] (^Iterable listNodes [this ]
()) ())

View File

@ -20,6 +20,7 @@
package org.jclouds.compute; package org.jclouds.compute;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
@ -98,8 +99,8 @@ public interface ComputeService {
/** /**
* *
* The compute api treats nodes as a group based on a tag you specify. Using this tag, you can * The compute api treats nodes as a group based on the name you specify. Using this group, you
* choose to operate one or many nodes as a logical unit without regard to the implementation * can choose to operate one or many nodes as a logical unit without regard to the implementation
* details of the cloud. * details of the cloud.
* <p/> * <p/>
* *
@ -119,7 +120,7 @@ public interface ComputeService {
* If resources such as security groups are needed, they will be reused or created for you. * If resources such as security groups are needed, they will be reused or created for you.
* Inbound port 22 will always be opened up. * Inbound port 22 will always be opened up.
* *
* @param tag * @param group
* - common identifier to group nodes by, cannot contain hyphens * - common identifier to group nodes by, cannot contain hyphens
* @param count * @param count
* - how many to fire up. * - how many to fire up.
@ -131,19 +132,38 @@ public interface ComputeService {
* when there's a problem applying options to nodes. Note that successful and failed * when there's a problem applying options to nodes. Note that successful and failed
* nodes are a part of this exception, so be sure to inspect this carefully. * nodes are a part of this exception, so be sure to inspect this carefully.
*/ */
Set<? extends NodeMetadata> createNodesInGroup(String group, int count, Template template) throws RunNodesException;
/**
* Like {@link ComputeService#createNodesInGroup(String,int,Template)}, except that the template
* is default, equivalent to {@code templateBuilder().any().options(templateOptions)}.
*/
Set<? extends NodeMetadata> createNodesInGroup(String group, int count, TemplateOptions templateOptions)
throws RunNodesException;
/**
* Like {@link ComputeService#createNodesInGroup(String,int,TemplateOptions)}, except that the
* options are default, as specified in {@link ComputeService#templateOptions}.
*/
Set<? extends NodeMetadata> createNodesInGroup(String group, int count) throws RunNodesException;
/**
* @see #createNodesInGroup(String , int , Template )
*/
@Deprecated
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template) throws RunNodesException; Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template) throws RunNodesException;
/** /**
* Like {@link ComputeService#runNodesWithTag(String,int,Template)}, except that the template is * @see #createNodesInGroup(String , int , TemplateOptions )
* default, equivalent to {@code templateBuilder().any().options(templateOptions)}.
*/ */
@Deprecated
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, TemplateOptions templateOptions) Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, TemplateOptions templateOptions)
throws RunNodesException; throws RunNodesException;
/** /**
* Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)}, except that the * @see #createNodesInGroup(String , int )
* options are default, as specified in {@link ComputeService#templateOptions}.
*/ */
@Deprecated
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException; Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException;
/** /**
@ -272,6 +292,13 @@ public interface ComputeService {
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
Statement runScript) throws RunScriptOnNodesException; Statement runScript) throws RunScriptOnNodesException;
/**
*
* @see ComputeService#runScriptOnNodesMatching(Predicate, Statement, RunScriptOptions)
*/
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, String runScript,
RunScriptOptions options) throws RunScriptOnNodesException;
/** /**
* Run the script on all nodes with the specific predicate. * Run the script on all nodes with the specific predicate.
* *

View File

@ -60,7 +60,7 @@ public interface ComputeServiceAdapter<N, H, I, L> {
* @see ComputeService#runNodesWithTag(String, int, Template) * @see ComputeService#runNodesWithTag(String, int, Template)
* @see ComputeServiceContext#getCredentialStore * @see ComputeServiceContext#getCredentialStore
*/ */
N runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, N createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore); Map<String, Credentials> credentialStore);
/** /**

View File

@ -40,7 +40,7 @@ public interface JCloudsNativeComputeServiceAdapter extends
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, NodeMetadata createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore); Map<String, Credentials> credentialStore);
/** /**

View File

@ -19,15 +19,15 @@
package org.jclouds.compute.config; package org.jclouds.compute.config;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Scopes; import com.google.inject.Scopes;
@ -49,15 +49,15 @@ public abstract class BindComputeStrategiesByClass extends AbstractModule {
bindDestroyNodeStrategy(defineDestroyNodeStrategy()); bindDestroyNodeStrategy(defineDestroyNodeStrategy());
} }
protected void bindRunNodesAndAddToSetStrategy(Class<? extends RunNodesAndAddToSetStrategy> clazz) { protected void bindRunNodesAndAddToSetStrategy(Class<? extends CreateNodesInGroupThenAddToSet> clazz) {
bind(RunNodesAndAddToSetStrategy.class).to(clazz).in(Scopes.SINGLETON); bind(CreateNodesInGroupThenAddToSet.class).to(clazz).in(Scopes.SINGLETON);
} }
/** /**
* needed, if {@link RunNodesAndAddToSetStrategy} requires it * needed, if {@link CreateNodesInGroupThenAddToSet} requires it
*/ */
protected void bindAddNodeWithTagStrategy(Class<? extends AddNodeWithTagStrategy> clazz) { protected void bindAddNodeWithTagStrategy(Class<? extends CreateNodeWithGroupEncodedIntoName> clazz) {
bind(AddNodeWithTagStrategy.class).to(clazz).in(Scopes.SINGLETON); bind(CreateNodeWithGroupEncodedIntoName.class).to(clazz).in(Scopes.SINGLETON);
} }
protected void bindDestroyNodeStrategy(Class<? extends DestroyNodeStrategy> clazz) { protected void bindDestroyNodeStrategy(Class<? extends DestroyNodeStrategy> clazz) {
@ -84,14 +84,14 @@ public abstract class BindComputeStrategiesByClass extends AbstractModule {
bind(ListNodesStrategy.class).to(clazz).in(Scopes.SINGLETON); bind(ListNodesStrategy.class).to(clazz).in(Scopes.SINGLETON);
} }
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() { protected Class<? extends CreateNodesInGroupThenAddToSet> defineRunNodesAndAddToSetStrategy() {
return EncodeTagIntoNameRunNodesAndAddToSetStrategy.class; return CreateNodesWithGroupEncodedIntoNameThenAddToSet.class;
} }
/** /**
* needed, if {@link RunNodesAndAddToSetStrategy} requires it * needed, if {@link CreateNodesInGroupThenAddToSet} requires it
*/ */
protected abstract Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy(); protected abstract Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy();
protected abstract Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy(); protected abstract Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy();

View File

@ -29,7 +29,7 @@ import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
@ -114,7 +114,7 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
@Provides @Provides
@Singleton @Singleton
protected AddNodeWithTagStrategy defineAddNodeWithTagStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) { protected CreateNodeWithGroupEncodedIntoName defineAddNodeWithTagStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
return in; return in;
} }

View File

@ -37,11 +37,17 @@ public interface NodeMetadata extends ComputeMetadata {
/** /**
* Tag used for all resources that belong to the same logical group. run, destroy commands are * Tag used for all resources that belong to the same logical group. run, destroy commands are
* scoped to tag. * scoped to group.
* *
* @return tag for this node, or null, if not a part of a group * @return group for this node, or null, if not a part of a group
* *
*/ */
String getGroup();
/**
* @see #getGroup
*/
@Deprecated
String getTag(); String getTag();
/** /**

View File

@ -46,7 +46,7 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder {
@Nullable @Nullable
private Credentials credentials; private Credentials credentials;
@Nullable @Nullable
private String tag; private String group;
private int loginPort = 22; private int loginPort = 22;
@Nullable @Nullable
private String imageId; private String imageId;
@ -89,8 +89,8 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder {
return this; return this;
} }
public NodeMetadataBuilder tag(@Nullable String tag) { public NodeMetadataBuilder group(@Nullable String group) {
this.tag = tag; this.group = group;
return this; return this;
} }
@ -146,13 +146,13 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder {
@Override @Override
public NodeMetadata build() { public NodeMetadata build() {
return new NodeMetadataImpl(providerId, name, id, location, uri, userMetadata, tag, hardware, imageId, os, state, return new NodeMetadataImpl(providerId, name, id, location, uri, userMetadata, group, hardware, imageId, os, state,
loginPort, publicAddresses, privateAddresses, adminPassword, credentials); loginPort, publicAddresses, privateAddresses, adminPassword, credentials);
} }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) {
return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location(
node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tag(node.getTag()).hardware( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).group(node.getGroup()).hardware(
node.getHardware()).imageId(node.getImageId()).operatingSystem(node.getOperatingSystem()).state( node.getHardware()).imageId(node.getImageId()).operatingSystem(node.getOperatingSystem()).state(
node.getState()).loginPort(node.getLoginPort()).publicAddresses(node.getPublicAddresses()) node.getState()).loginPort(node.getLoginPort()).publicAddresses(node.getPublicAddresses())
.privateAddresses(node.getPrivateAddresses()).adminPassword(node.getAdminPassword()).credentials( .privateAddresses(node.getPrivateAddresses()).adminPassword(node.getAdminPassword()).credentials(

View File

@ -55,7 +55,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
@Nullable @Nullable
private final Credentials credentials; private final Credentials credentials;
@Nullable @Nullable
private final String tag; private final String group;
@Nullable @Nullable
private final String imageId; private final String imageId;
@Nullable @Nullable
@ -64,12 +64,12 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
private final OperatingSystem os; private final OperatingSystem os;
public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri, public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, @Nullable String tag, @Nullable Hardware hardware, Map<String, String> userMetadata, @Nullable String group, @Nullable Hardware hardware,
@Nullable String imageId, @Nullable OperatingSystem os, NodeState state, int loginPort, @Nullable String imageId, @Nullable OperatingSystem os, NodeState state, int loginPort,
Iterable<String> publicAddresses, Iterable<String> privateAddresses, @Nullable String adminPassword, Iterable<String> publicAddresses, Iterable<String> privateAddresses, @Nullable String adminPassword,
@Nullable Credentials credentials) { @Nullable Credentials credentials) {
super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata); super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata);
this.tag = tag; this.group = group;
this.hardware = hardware; this.hardware = hardware;
this.imageId = imageId; this.imageId = imageId;
this.os = os; this.os = os;
@ -86,7 +86,15 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
*/ */
@Override @Override
public String getTag() { public String getTag() {
return tag; return getGroup();
}
/**
* {@inheritDoc}
*/
@Override
public String getGroup() {
return group;
} }
/** /**
@ -163,7 +171,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
@Override @Override
public String toString() { public String toString() {
return "[id=" + getId() + ", providerId=" + getProviderId() + ", tag=" + getTag() + ", name=" + getName() return "[id=" + getId() + ", providerId=" + getProviderId() + ", group=" + getTag() + ", name=" + getName()
+ ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os=" + ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os="
+ getOperatingSystem() + ", state=" + getState() + ", loginPort=" + getLoginPort() + getOperatingSystem() + ", state=" + getState() + ", loginPort=" + getLoginPort()
+ ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses + ", hardware=" + ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses + ", hardware="
@ -178,7 +186,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
result = prime * result + loginPort; result = prime * result + loginPort;
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode()); result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode()); result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
result = prime * result + ((tag == null) ? 0 : tag.hashCode()); result = prime * result + ((group == null) ? 0 : group.hashCode());
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode()); result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
result = prime * result + ((hardware == null) ? 0 : hardware.hashCode()); result = prime * result + ((hardware == null) ? 0 : hardware.hashCode());
result = prime * result + ((os == null) ? 0 : os.hashCode()); result = prime * result + ((os == null) ? 0 : os.hashCode());
@ -208,10 +216,10 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
return false; return false;
} else if (!publicAddresses.equals(other.publicAddresses)) } else if (!publicAddresses.equals(other.publicAddresses))
return false; return false;
if (tag == null) { if (group == null) {
if (other.tag != null) if (other.group != null)
return false; return false;
} else if (!tag.equals(other.tag)) } else if (!group.equals(other.group))
return false; return false;
if (imageId == null) { if (imageId == null) {
if (other.imageId != null) if (other.imageId != null)

View File

@ -76,7 +76,7 @@ import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.RunScriptOnNodeAndAddToGoodMapOrPutExceptionIntoBadMap; import org.jclouds.compute.strategy.RunScriptOnNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
@ -116,7 +116,7 @@ public class BaseComputeService implements ComputeService {
private final Supplier<Set<? extends Location>> locations; private final Supplier<Set<? extends Location>> locations;
private final ListNodesStrategy listNodesStrategy; private final ListNodesStrategy listNodesStrategy;
private final GetNodeMetadataStrategy getNodeMetadataStrategy; private final GetNodeMetadataStrategy getNodeMetadataStrategy;
private final RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy; private final CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy;
private final RebootNodeStrategy rebootNodeStrategy; private final RebootNodeStrategy rebootNodeStrategy;
private final DestroyNodeStrategy destroyNodeStrategy; private final DestroyNodeStrategy destroyNodeStrategy;
private final ResumeNodeStrategy resumeNodeStrategy; private final ResumeNodeStrategy resumeNodeStrategy;
@ -135,7 +135,7 @@ public class BaseComputeService implements ComputeService {
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Image>> images,
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles, @Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy, ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider, Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
@ -178,45 +178,63 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template) public Set<? extends NodeMetadata> runNodesWithTag(String group, int count, Template template)
throws RunNodesException { throws RunNodesException {
checkNotNull(tag, "tag cannot be null"); return createNodesInGroup(group, count, template);
}
/**
* {@inheritDoc}
*/
@Override
public Set<? extends NodeMetadata> runNodesWithTag(String group, int count, TemplateOptions templateOptions)
throws RunNodesException {
return createNodesInGroup(group, count, templateBuilder().any().options(templateOptions).build());
}
/**
* {@inheritDoc}
*/
@Override
public Set<? extends NodeMetadata> runNodesWithTag(String group, int count) throws RunNodesException {
return createNodesInGroup(group, count, templateOptions());
}
@Override
public Set<? extends NodeMetadata> createNodesInGroup(String group, int count, Template template)
throws RunNodesException {
checkNotNull(group, "group cannot be null");
checkNotNull(template.getLocation(), "location"); checkNotNull(template.getLocation(), "location");
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) hardwareProfile(%s) options(%s)", count, logger.debug(">> running %d node%s group(%s) location(%s) image(%s) hardwareProfile(%s) options(%s)", count,
count > 1 ? "s" : "", tag, template.getLocation().getId(), template.getImage().getId(), template count > 1 ? "s" : "", group, template.getLocation().getId(), template.getImage().getId(), template
.getHardware().getId(), template.getOptions()); .getHardware().getId(), template.getOptions());
Set<NodeMetadata> goodNodes = newLinkedHashSet(); Set<NodeMetadata> goodNodes = newLinkedHashSet();
Map<NodeMetadata, Exception> badNodes = newLinkedHashMap(); Map<NodeMetadata, Exception> badNodes = newLinkedHashMap();
Multimap<NodeMetadata, CustomizationResponse> customizationResponses = LinkedHashMultimap.create(); Multimap<NodeMetadata, CustomizationResponse> customizationResponses = LinkedHashMultimap.create();
Map<?, Future<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count, template, goodNodes, badNodes, Map<?, Future<Void>> responses = runNodesAndAddToSetStrategy.execute(group, count, template, goodNodes, badNodes,
customizationResponses); customizationResponses);
Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger, "runNodesWithTag(" Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger, "runNodesWithTag("
+ tag + ")"); + group + ")");
for (NodeMetadata node : concat(goodNodes, badNodes.keySet())) for (NodeMetadata node : concat(goodNodes, 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, goodNodes, executionExceptions, badNodes); throw new RunNodesException(group, count, template, goodNodes, executionExceptions, badNodes);
} }
return goodNodes; return goodNodes;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, TemplateOptions templateOptions) public Set<? extends NodeMetadata> createNodesInGroup(String group, int count, TemplateOptions templateOptions)
throws RunNodesException { throws RunNodesException {
return runNodesWithTag(tag, count, templateBuilder().any().options(templateOptions).build()); return createNodesInGroup(group, count, templateBuilder().any().options(templateOptions).build());
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException { public Set<? extends NodeMetadata> createNodesInGroup(String group, int count) throws RunNodesException {
return runNodesWithTag(tag, count, templateOptions()); return createNodesInGroup(group, count, templateOptions());
} }
/** /**
@ -492,6 +510,13 @@ public class BaseComputeService implements ComputeService {
return runScriptOnNodesMatching(filter, runScript, RunScriptOptions.NONE); return runScriptOnNodesMatching(filter, runScript, RunScriptOptions.NONE);
} }
@Override
public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
String runScript, RunScriptOptions options) throws RunScriptOnNodesException {
return runScriptOnNodesMatching(filter, Statements.exec(checkNotNull(runScript, "runScript")),
RunScriptOptions.NONE);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -562,4 +587,5 @@ public class BaseComputeService implements ComputeService {
return executor.submit(initScriptRunnerFactory.create(node, script, options, badNodes)); return executor.submit(initScriptRunnerFactory.create(node, script, options, badNodes));
} }
} }
} }

View File

@ -42,11 +42,10 @@ public class ComputeServiceContextImpl<S, A> implements ComputeServiceContext {
private final Utils utils; private final Utils utils;
private final Map<String, Credentials> credentialStore; private final Map<String, Credentials> credentialStore;
@SuppressWarnings({ "unchecked" }) @SuppressWarnings( { "unchecked" })
@Inject @Inject
public ComputeServiceContextImpl(ComputeService computeService, Map<String, Credentials> credentialStore, public ComputeServiceContextImpl(ComputeService computeService, Map<String, Credentials> credentialStore,
Utils utils, Utils utils, @SuppressWarnings("rawtypes") RestContext providerSpecificContext) {
@SuppressWarnings("rawtypes") RestContext providerSpecificContext) {
this.credentialStore = credentialStore; this.credentialStore = credentialStore;
this.utils = utils; this.utils = utils;
this.providerSpecificContext = providerSpecificContext; this.providerSpecificContext = providerSpecificContext;
@ -57,7 +56,7 @@ public class ComputeServiceContextImpl<S, A> implements ComputeServiceContext {
return computeService; return computeService;
} }
@SuppressWarnings({ "unchecked", "hiding" }) @SuppressWarnings( { "unchecked", "hiding" })
@Override @Override
public <S, A> RestContext<S, A> getProviderSpecificContext() { public <S, A> RestContext<S, A> getProviderSpecificContext() {
return (RestContext<S, A>) providerSpecificContext; return (RestContext<S, A>) providerSpecificContext;

View File

@ -42,8 +42,7 @@ import com.google.common.collect.Sets;
*/ */
public class NodePredicates { public class NodePredicates {
private static class ParentLocationId implements private static class ParentLocationId implements Predicate<ComputeMetadata> {
Predicate<ComputeMetadata> {
private final String id; private final String id;
private ParentLocationId(String id) { private ParentLocationId(String id) {
@ -156,8 +155,7 @@ public class NodePredicates {
} }
/** /**
* Return nodes with the specific ids Note: returns all nodes, regardless of * Return nodes with the specific ids Note: returns all nodes, regardless of the state.
* the state.
* *
* @param ids * @param ids
* ids of the resources * ids of the resources
@ -187,51 +185,67 @@ public class NodePredicates {
} }
/** /**
* Return nodes with specified tag. Note: returns all nodes, regardless of * Return nodes in the specified group. Note: returns all nodes, regardless of the state.
* the state.
* *
* @param tag * @param group
* tag to match the items * group to match the items
* @return predicate * @return predicate
*/ */
public static Predicate<NodeMetadata> withTag(final String tag) { public static Predicate<NodeMetadata> inGroup(final String group) {
Preconditions2.checkNotEmpty(tag, "Tag must be defined"); Preconditions2.checkNotEmpty(group, "group must be defined");
return new Predicate<NodeMetadata>() { return new Predicate<NodeMetadata>() {
@Override @Override
public boolean apply(NodeMetadata nodeMetadata) { public boolean apply(NodeMetadata nodeMetadata) {
return tag.equals(nodeMetadata.getTag()); return group.equals(nodeMetadata.getGroup());
} }
@Override @Override
public String toString() { public String toString() {
return "withTag(" + tag + ")"; return "inGroup(" + group + ")";
} }
}; };
} }
/** /**
* Return nodes with specified tag that are in the NODE_RUNNING state.
* *
* @param tag * @see #inGroup(String)
* tag to match the items */
@Deprecated
public static Predicate<NodeMetadata> withTag(final String tag) {
return inGroup(tag);
}
/**
* Return nodes with specified group that are in the NODE_RUNNING state.
*
* @param group
* group to match the items
* @return predicate * @return predicate
*/ */
public static Predicate<NodeMetadata> runningWithTag(final String tag) { public static Predicate<NodeMetadata> runningInGroup(final String group) {
Preconditions2.checkNotEmpty(tag, "Tag must be defined"); Preconditions2.checkNotEmpty(group, "Tag must be defined");
return new Predicate<NodeMetadata>() { return new Predicate<NodeMetadata>() {
@Override @Override
public boolean apply(NodeMetadata nodeMetadata) { public boolean apply(NodeMetadata nodeMetadata) {
return tag.equals(nodeMetadata.getTag()) return group.equals(nodeMetadata.getGroup()) && nodeMetadata.getState() == NodeState.RUNNING;
&& nodeMetadata.getState() == NodeState.RUNNING;
} }
@Override @Override
public String toString() { public String toString() {
return "runningWithTag(" + tag + ")"; return "runningInGroup(" + group + ")";
} }
}; };
} }
/**
*
* @see #inGroup(String)
*/
@Deprecated
public static Predicate<NodeMetadata> runningWithTag(final String tag) {
return runningInGroup(tag);
}
/** /**
* Match nodes with State == RUNNING * Match nodes with State == RUNNING
*/ */

View File

@ -27,21 +27,21 @@ import org.jclouds.compute.domain.Template;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public interface AddNodeWithTagStrategy { public interface CreateNodeWithGroupEncodedIntoName {
/** /**
* create a node given the name and template parameters such as imageid, hardwareid, and * create a node given the name and template parameters such as imageid, hardwareid, and
* locationid. * locationid.
* *
* @param tag * @param group
* tag supplied by the user * group name supplied by the user
* @param name * @param name
* supplied by {@link RunNodesAndAddToSetStrategy } and must have the tag encoded into * supplied by {@link CreateNodesInGroupThenAddToSet } and must have the tag encoded into
* it. * it.
* @param template * @param template
* supplied by the user * supplied by the user
* @return NodeMetadata from the new object, most likely in some pending state. * @return NodeMetadata from the new object, most likely in some pending state.
*/ */
NodeMetadata addNodeWithTag(String tag, String name, Template template); NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template);
} }

View File

@ -26,19 +26,18 @@ import java.util.concurrent.Future;
import org.jclouds.compute.config.CustomizationResponse; import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
/** /**
* creates futures that correlate to
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ImplementedBy(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class) @ImplementedBy(CreateNodesWithGroupEncodedIntoNameThenAddToSet.class)
public interface RunNodesAndAddToSetStrategy { public interface CreateNodesInGroupThenAddToSet {
Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes, Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses); Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses);
} }

View File

@ -36,7 +36,7 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
@ -55,7 +55,7 @@ import com.google.common.collect.Iterables;
* *
*/ */
@Singleton @Singleton
public class AdaptingComputeServiceStrategies<N, H, I, L> implements AddNodeWithTagStrategy, DestroyNodeStrategy, public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeWithGroupEncodedIntoName, DestroyNodeStrategy,
GetNodeMetadataStrategy, ListNodesStrategy, RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy { GetNodeMetadataStrategy, ListNodesStrategy, RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -129,12 +129,12 @@ public class AdaptingComputeServiceStrategies<N, H, I, L> implements AddNodeWith
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
checkState(tag != null, "tag (that which groups identical nodes together) must be specified"); checkState(group != null, "group (that which groups identical nodes together) must be specified");
checkState(name != null && name.indexOf(tag) != -1, "name should have %s encoded into it", tag); checkState(name != null && name.indexOf(group) != -1, "name should have %s encoded into it", group);
checkState(template != null, "template must be specified"); checkState(template != null, "template must be specified");
N from = client.runNodeWithTagAndNameAndStoreCredentials(tag, name, template, credentialStore); N from = client.createNodeWithGroupEncodedIntoNameThenStoreCredentials(group, name, template, credentialStore);
NodeMetadata node = nodeMetadataAdapter.apply(from); NodeMetadata node = nodeMetadataAdapter.apply(from);
return node; return node;
} }

View File

@ -44,10 +44,10 @@ import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap; import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -59,7 +59,7 @@ import com.google.common.collect.Multimap;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class EncodeTagIntoNameRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrategy { public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNodesInGroupThenAddToSet {
private class AddNode implements Callable<NodeMetadata> { private class AddNode implements Callable<NodeMetadata> {
private final String name; private final String name;
@ -78,7 +78,7 @@ public class EncodeTagIntoNameRunNodesAndAddToSetStrategy implements RunNodesAnd
logger.debug(">> adding node location(%s) name(%s) image(%s) hardware(%s)", logger.debug(">> adding node location(%s) name(%s) image(%s) hardware(%s)",
template.getLocation().getId(), name, template.getImage().getProviderId(), template.getHardware() template.getLocation().getId(), name, template.getImage().getProviderId(), template.getHardware()
.getProviderId()); .getProviderId());
node = addNodeWithTagStrategy.addNodeWithTag(tag, name, template); node = addNodeWithTagStrategy.createNodeWithGroupEncodedIntoName(tag, name, template);
logger.debug("<< %s node(%s)", node.getState(), node.getId()); logger.debug("<< %s node(%s)", node.getState(), node.getId());
return node; return node;
} }
@ -92,15 +92,15 @@ public class EncodeTagIntoNameRunNodesAndAddToSetStrategy implements RunNodesAnd
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final AddNodeWithTagStrategy addNodeWithTagStrategy; protected final CreateNodeWithGroupEncodedIntoName addNodeWithTagStrategy;
protected final ListNodesStrategy listNodesStrategy; protected final ListNodesStrategy listNodesStrategy;
protected final String nodeNamingConvention; protected final String nodeNamingConvention;
protected final ExecutorService executor; protected final ExecutorService executor;
protected final CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory; protected final CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory;
@Inject @Inject
protected EncodeTagIntoNameRunNodesAndAddToSetStrategy( protected CreateNodesWithGroupEncodedIntoNameThenAddToSet(
AddNodeWithTagStrategy addNodeWithTagStrategy, CreateNodeWithGroupEncodedIntoName addNodeWithTagStrategy,
ListNodesStrategy listNodesStrategy, ListNodesStrategy listNodesStrategy,
@Named("NAMING_CONVENTION") String nodeNamingConvention, @Named("NAMING_CONVENTION") String nodeNamingConvention,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,

View File

@ -80,13 +80,13 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
} }
@Override @Override
public NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, public NodeMetadata createNodeWithGroupEncodedIntoNameThenStoreCredentials(String group, 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);
builder.name(name); builder.name(name);
builder.tag(tag); builder.group(group);
builder.location(location.get()); builder.location(location.get());
builder.imageId(template.getImage().getId()); builder.imageId(template.getImage().getId());
builder.operatingSystem(template.getImage().getOperatingSystem()); builder.operatingSystem(template.getImage().getOperatingSystem());

View File

@ -103,12 +103,11 @@ public class ComputeServiceUtils {
/** /**
* *
* * @return null if group cannot be parsed
* @return NOTAG#+from if tag cannot be parsed
*/ */
public static String parseTagFromName(String from) { public static String parseGroupFromName(String from) {
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from); Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from);
return matcher.find() ? matcher.group(1) : "NOTAG#" + from; return matcher.find() ? matcher.group(1) : null;
} }
public static double getCores(Hardware input) { public static double getCores(Hardware input) {

View File

@ -99,7 +99,7 @@ import com.google.inject.Module;
@Test(groups = { "integration", "live" }, sequential = true) @Test(groups = { "integration", "live" }, sequential = true)
public abstract class BaseComputeServiceLiveTest { public abstract class BaseComputeServiceLiveTest {
protected String tag; protected String group;
protected RetryablePredicate<IPSocket> socketTester; protected RetryablePredicate<IPSocket> socketTester;
protected SortedSet<NodeMetadata> nodes; protected SortedSet<NodeMetadata> nodes;
@ -132,10 +132,10 @@ public abstract class BaseComputeServiceLiveTest {
@BeforeGroups(groups = { "integration", "live" }) @BeforeGroups(groups = { "integration", "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException {
setServiceDefaults(); setServiceDefaults();
if (tag == null) if (group == null)
tag = checkNotNull(provider, "provider"); group = checkNotNull(provider, "provider");
if (tag.indexOf('-') == -1) if (group.indexOf('-') == -1)
tag = tag + "-"; group = group + "-";
setupCredentials(); setupCredentials();
setupKeyPairForTest(); setupKeyPairForTest();
initializeContextAndClient(); initializeContextAndClient();
@ -215,7 +215,7 @@ public abstract class BaseComputeServiceLiveTest {
// starting this one alphabetically before create2nodes.. // starting this one alphabetically before create2nodes..
@Test(enabled = true, dependsOnMethods = { "testCompareSizes" }) @Test(enabled = true, dependsOnMethods = { "testCompareSizes" })
public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception { public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception {
String tag = this.tag + "r"; String tag = this.group + "r";
try { try {
client.destroyNodesMatching(withTag(tag)); client.destroyNodesMatching(withTag(tag));
} catch (Exception e) { } catch (Exception e) {
@ -267,19 +267,19 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCompareSizes") @Test(enabled = true, dependsOnMethods = "testCompareSizes")
public void testCreateTwoNodesWithRunScript() throws Exception { public void testCreateTwoNodesWithRunScript() throws Exception {
try { try {
client.destroyNodesMatching(withTag(tag)); client.destroyNodesMatching(withTag(group));
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
} }
refreshTemplate(); refreshTemplate();
try { try {
nodes = newTreeSet(client.runNodesWithTag(tag, 2, template)); nodes = newTreeSet(client.runNodesWithTag(group, 2, template));
} catch (RunNodesException e) { } catch (RunNodesException e) {
nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
throw e; throw e;
} }
assertEquals(nodes.size(), 2); assertEquals(nodes.size(), 2);
checkNodes(nodes, tag); checkNodes(nodes, group);
NodeMetadata node1 = nodes.first(); NodeMetadata node1 = nodes.first();
NodeMetadata node2 = nodes.last(); NodeMetadata node2 = nodes.last();
// credentials aren't always the same // credentials aren't always the same
@ -324,8 +324,8 @@ public abstract class BaseComputeServiceLiveTest {
public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception {
initializeContextAndClient(); initializeContextAndClient();
refreshTemplate(); refreshTemplate();
TreeSet<NodeMetadata> nodes = newTreeSet(client.runNodesWithTag(tag, 1, template)); TreeSet<NodeMetadata> nodes = newTreeSet(client.runNodesWithTag(group, 1, template));
checkNodes(nodes, tag); checkNodes(nodes, group);
NodeMetadata node = nodes.first(); NodeMetadata node = nodes.first();
this.nodes.add(node); this.nodes.add(node);
assertEquals(nodes.size(), 1); assertEquals(nodes.size(), 1);
@ -375,7 +375,7 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
public void testGet() throws Exception { public void testGet() throws Exception {
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(client Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(client
.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))), .listNodesDetailsMatching(all()), and(withTag(group), not(TERMINATED))),
new Function<NodeMetadata, String>() { new Function<NodeMetadata, String>() {
@Override @Override
@ -407,14 +407,14 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testGet") @Test(enabled = true, dependsOnMethods = "testGet")
public void testReboot() throws Exception { public void testReboot() throws Exception {
client.rebootNodesMatching(withTag(tag));// TODO test client.rebootNodesMatching(withTag(group));// TODO test
// validation // validation
testGet(); testGet();
} }
@Test(enabled = true, dependsOnMethods = "testReboot") @Test(enabled = true, dependsOnMethods = "testReboot")
public void testSuspendResume() throws Exception { public void testSuspendResume() throws Exception {
client.suspendNodesMatching(withTag(tag)); client.suspendNodesMatching(withTag(group));
Set<? extends NodeMetadata> stoppedNodes = refreshNodes(); Set<? extends NodeMetadata> stoppedNodes = refreshNodes();
@ -430,7 +430,7 @@ public abstract class BaseComputeServiceLiveTest {
}) : stoppedNodes; }) : stoppedNodes;
client.resumeNodesMatching(withTag(tag)); client.resumeNodesMatching(withTag(group));
testGet(); testGet();
} }
@ -467,22 +467,22 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails" }) @Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails" })
public void testDestroyNodes() { public void testDestroyNodes() {
int toDestroy = refreshNodes().size(); int toDestroy = refreshNodes().size();
Set<? extends NodeMetadata> destroyed = client.destroyNodesMatching(withTag(tag)); Set<? extends NodeMetadata> destroyed = client.destroyNodesMatching(withTag(group));
assertEquals(toDestroy, destroyed.size()); assertEquals(toDestroy, destroyed.size());
for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), withTag(tag))) { for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), withTag(group))) {
assert node.getState() == NodeState.TERMINATED : node; assert node.getState() == NodeState.TERMINATED : node;
assertEquals(context.getCredentialStore().get("node#" + node.getId()), null); assertEquals(context.getCredentialStore().get("node#" + node.getId()), null);
} }
} }
private Set<? extends NodeMetadata> refreshNodes() { private Set<? extends NodeMetadata> refreshNodes() {
return filter(client.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))); return filter(client.listNodesDetailsMatching(all()), and(withTag(group), not(TERMINATED)));
} }
@Test(enabled = true) @Test(enabled = true)
public void testCreateAndRunAService() throws Exception { public void testCreateAndRunAService() throws Exception {
String tag = this.tag + "s"; String tag = this.group + "s";
try { try {
client.destroyNodesMatching(withTag(tag)); client.destroyNodesMatching(withTag(tag));
} catch (Exception e) { } catch (Exception e) {
@ -554,7 +554,7 @@ public abstract class BaseComputeServiceLiveTest {
} }
public void testOptionToNotBlock() throws Exception { public void testOptionToNotBlock() throws Exception {
String tag = this.tag + "block"; String tag = this.group + "block";
try { try {
client.destroyNodesMatching(withTag(tag)); client.destroyNodesMatching(withTag(tag));
} catch (Exception e) { } catch (Exception e) {

View File

@ -19,7 +19,7 @@
package org.jclouds.compute.util; package org.jclouds.compute.util;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
@ -41,7 +41,7 @@ public class ComputeServiceUtilsTest {
@Test @Test
public void testParseTagFromName() { public void testParseTagFromName() {
assertEquals(parseTagFromName("gogrid--849"), "gogrid-"); assertEquals(parseGroupFromName("gogrid--849"), "gogrid-");
} }
@Test @Test

View File

@ -60,7 +60,7 @@ import com.google.inject.Module;
public abstract class BaseLoadBalancerServiceLiveTest { public abstract class BaseLoadBalancerServiceLiveTest {
protected SshClient.Factory sshFactory; protected SshClient.Factory sshFactory;
protected String tag; protected String group;
protected RetryablePredicate<IPSocket> socketTester; protected RetryablePredicate<IPSocket> socketTester;
protected Set<? extends NodeMetadata> nodes; protected Set<? extends NodeMetadata> nodes;
@ -126,8 +126,8 @@ public abstract class BaseLoadBalancerServiceLiveTest {
@BeforeGroups(groups = { "integration", "live" }) @BeforeGroups(groups = { "integration", "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException {
setServiceDefaults(); setServiceDefaults();
if (tag == null) if (group == null)
tag = checkNotNull(provider, "provider"); group = checkNotNull(provider, "provider");
setupCredentials(); setupCredentials();
initializeContext(); initializeContext();
initializeComputeContext(); initializeComputeContext();
@ -166,7 +166,7 @@ public abstract class BaseLoadBalancerServiceLiveTest {
@BeforeGroups(groups = { "integration", "live" }, dependsOnMethods = "setupClient") @BeforeGroups(groups = { "integration", "live" }, dependsOnMethods = "setupClient")
public void createNodes() throws RunNodesException { public void createNodes() throws RunNodesException {
try { try {
nodes = computeContext.getComputeService().runNodesWithTag(tag, 2); nodes = computeContext.getComputeService().createNodesInGroup(group, 2);
} catch (RunNodesException e) { } catch (RunNodesException e) {
nodes = e.getSuccessfulNodes(); nodes = e.getSuccessfulNodes();
throw e; throw e;
@ -177,7 +177,7 @@ public abstract class BaseLoadBalancerServiceLiveTest {
public void testLoadBalanceNodesMatching() throws Exception { public void testLoadBalanceNodesMatching() throws Exception {
// create load balancers // create load balancers
loadbalancer = context.getLoadBalancerService().createLoadBalancerInLocation(null, tag, "HTTP", 80, 80, nodes); loadbalancer = context.getLoadBalancerService().createLoadBalancerInLocation(null, group, "HTTP", 80, 80, nodes);
assertNotNull(loadbalancer); assertNotNull(loadbalancer);
validateNodesInLoadBalancer(); validateNodesInLoadBalancer();
@ -197,7 +197,7 @@ public abstract class BaseLoadBalancerServiceLiveTest {
context.getLoadBalancerService().destroyLoadBalancer(loadbalancer.getId()); context.getLoadBalancerService().destroyLoadBalancer(loadbalancer.getId());
} }
if (nodes != null) { if (nodes != null) {
computeContext.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); computeContext.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
} }
computeContext.close(); computeContext.close();
context.close(); context.close();

View File

@ -49,7 +49,7 @@ import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -77,7 +77,7 @@ public class AWSEC2ComputeService extends EC2ComputeService {
protected AWSEC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore, protected AWSEC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy, ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider, Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,

View File

@ -52,7 +52,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
public AWSEC2ComputeServiceLiveTest() { public AWSEC2ComputeServiceLiveTest() {
provider = "aws-ec2"; provider = "aws-ec2";
tag = "ec2"; group = "ec2";
} }
@Override @Override
@ -67,29 +67,29 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getInstanceServices(); .getInstanceServices();
String tag = this.tag + "o"; String group = this.group + "o";
TemplateOptions options = client.templateOptions(); TemplateOptions options = client.templateOptions();
// Date before = new Date(); // Date before = new Date();
options.as(AWSEC2TemplateOptions.class).securityGroups(tag); options.as(AWSEC2TemplateOptions.class).securityGroups(group);
options.as(AWSEC2TemplateOptions.class).keyPair(tag); options.as(AWSEC2TemplateOptions.class).keyPair(group);
options.as(AWSEC2TemplateOptions.class).enableMonitoring(); options.as(AWSEC2TemplateOptions.class).enableMonitoring();
String startedId = null; String startedId = null;
try { try {
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag); cleanupExtendedStuff(securityGroupClient, keyPairClient, group);
// create a security group that allows ssh in so that our scripts later // create a security group that allows ssh in so that our scripts later
// will work // will work
securityGroupClient.createSecurityGroupInRegion(null, tag, tag); securityGroupClient.createSecurityGroupInRegion(null, group, group);
securityGroupClient.authorizeSecurityGroupIngressInRegion(null, tag, IpProtocol.TCP, 22, 22, "0.0.0.0/0"); securityGroupClient.authorizeSecurityGroupIngressInRegion(null, group, IpProtocol.TCP, 22, 22, "0.0.0.0/0");
// create a keypair to pass in as well // create a keypair to pass in as well
KeyPair result = keyPairClient.createKeyPairInRegion(null, tag); KeyPair result = keyPairClient.createKeyPairInRegion(null, group);
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options); Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
NodeMetadata first = Iterables.get(nodes, 0); NodeMetadata first = Iterables.get(nodes, 0);
assert first.getCredentials() != null : first; assert first.getCredentials() != null : first;
assert first.getCredentials().identity != null : first; assert first.getCredentials().identity != null : first;
@ -98,7 +98,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
AWSRunningInstance instance = AWSRunningInstance.class.cast(getInstance(instanceClient, startedId)); AWSRunningInstance instance = AWSRunningInstance.class.cast(getInstance(instanceClient, startedId));
assertEquals(instance.getKeyName(), tag); assertEquals(instance.getKeyName(), group);
assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED); assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED);
// TODO when the cloudwatchclient is finished // TODO when the cloudwatchclient is finished
@ -117,26 +117,26 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
// } // }
// make sure we made our dummy group and also let in the user's group // make sure we made our dummy group and also let in the user's group
assertEquals(Sets.newTreeSet(instance.getGroupIds()), ImmutableSortedSet.<String> of("jclouds#" + tag + "#" assertEquals(Sets.newTreeSet(instance.getGroupIds()), ImmutableSortedSet.<String> of("jclouds#" + group + "#"
+ instance.getRegion(), tag)); + instance.getRegion(), group));
// make sure our dummy group has no rules // make sure our dummy group has no rules
SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null, SecurityGroup secgroup = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
"jclouds#" + tag + "#" + instance.getRegion())); "jclouds#" +group + "#" + instance.getRegion()));
assert group.getIpPermissions().size() == 0 : group; assert secgroup.getIpPermissions().size() == 0 : secgroup;
// try to run a script with the original keyPair // try to run a script with the original keyPair
runScriptWithCreds(tag, first.getOperatingSystem(), new Credentials(first.getCredentials().identity, result runScriptWithCreds(group, first.getOperatingSystem(), new Credentials(first.getCredentials().identity, result
.getKeyMaterial())); .getKeyMaterial()));
} finally { } finally {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(NodePredicates.inGroup(group));
if (startedId != null) { if (startedId != null) {
// ensure we didn't delete these resources! // ensure we didn't delete these resources!
assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag).size(), 1); assertEquals(keyPairClient.describeKeyPairsInRegion(null, group).size(), 1);
assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, tag).size(), 1); assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, group).size(), 1);
} }
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag); cleanupExtendedStuff(securityGroupClient, keyPairClient, group);
} }
} }
@ -157,26 +157,26 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getInstanceServices(); .getInstanceServices();
String tag = this.tag + "g"; String group = this.group + "g";
TemplateOptions options = client.templateOptions(); TemplateOptions options = client.templateOptions();
// options.as(AWSEC2TemplateOptions.class).securityGroups(tag); // options.as(AWSEC2TemplateOptions.class).securityGroups(group);
options.as(AWSEC2TemplateOptions.class).keyPair(tag); options.as(AWSEC2TemplateOptions.class).keyPair(group);
options.as(AWSEC2TemplateOptions.class).subnetId(subnetId); options.as(AWSEC2TemplateOptions.class).subnetId(subnetId);
String startedId = null; String startedId = null;
String nodeId = null; String nodeId = null;
try { try {
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag); cleanupExtendedStuff(securityGroupClient, keyPairClient, group);
// create the security group // create the security group
// securityGroupClient.createSecurityGroupInRegion(null, tag, tag); // securityGroupClient.createSecurityGroupInRegion(null, group, group);
// create a keypair to pass in as well // create a keypair to pass in as well
keyPairClient.createKeyPairInRegion(null, tag); keyPairClient.createKeyPairInRegion(null, group);
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options); Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
NodeMetadata first = Iterables.get(nodes, 0); NodeMetadata first = Iterables.get(nodes, 0);
assert first.getCredentials() != null : first; assert first.getCredentials() != null : first;
@ -194,9 +194,9 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
client.destroyNode(nodeId); client.destroyNode(nodeId);
if (startedId != null) { if (startedId != null) {
// ensure we didn't delete these resources! // ensure we didn't delete these resources!
assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag).size(), 1); assertEquals(keyPairClient.describeKeyPairsInRegion(null, group).size(), 1);
} }
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag); cleanupExtendedStuff(securityGroupClient, keyPairClient, group);
} }
} }

View File

@ -199,13 +199,13 @@ public class PlacementGroupClientLiveTest {
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public"))
.runScript(buildScript(template.getImage().getOperatingSystem())); .runScript(buildScript(template.getImage().getOperatingSystem()));
String tag = PREFIX + "cccluster"; String group = PREFIX + "cccluster";
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
// TODO make this not lookup an explicit region // TODO make this not lookup an explicit region
client.getPlacementGroupServices().deletePlacementGroupInRegion(null, "jclouds#" + tag + "#us-east-1"); client.getPlacementGroupServices().deletePlacementGroupInRegion(null, "jclouds#" + group + "#us-east-1");
try { try {
Set<? extends NodeMetadata> nodes = context.getComputeService().runNodesWithTag(tag, 1, template); Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(group, 1, template);
NodeMetadata node = getOnlyElement(nodes); NodeMetadata node = getOnlyElement(nodes);
getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null, getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null,
@ -215,7 +215,7 @@ public class PlacementGroupClientLiveTest {
System.err.println(e.getNodeErrors().keySet()); System.err.println(e.getNodeErrors().keySet());
Throwables.propagate(e); Throwables.propagate(e);
} finally { } finally {
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
} }
} }

View File

@ -32,7 +32,7 @@ public class AWSELBLoadBalancerServiceLiveTest extends ELBLoadBalancerServiceLiv
public AWSELBLoadBalancerServiceLiveTest() { public AWSELBLoadBalancerServiceLiveTest() {
provider = "aws-elb"; provider = "aws-elb";
computeProvider = "aws-ec2"; computeProvider = "aws-ec2";
tag = "elb"; group = "elb";
} }
} }

View File

@ -43,7 +43,7 @@ public class BlueLockVCloudDirectorComputeServiceLiveTest extends VCloudComputeS
@Override @Override
public void setServiceDefaults() { public void setServiceDefaults() {
tag = "director"; group = "director";
} }
@Test @Test

View File

@ -31,7 +31,7 @@ public class CloudServersUKComputeServiceLiveTest extends CloudServersComputeSer
public CloudServersUKComputeServiceLiveTest() { public CloudServersUKComputeServiceLiveTest() {
provider = "cloudservers-uk"; provider = "cloudservers-uk";
tag = "cs"; group = "cs";
} }
} }

View File

@ -31,7 +31,7 @@ public class CloudServersUSComputeServiceLiveTest extends CloudServersComputeSer
public CloudServersUSComputeServiceLiveTest() { public CloudServersUSComputeServiceLiveTest() {
provider = "cloudservers-us"; provider = "cloudservers-us";
tag = "cs"; group = "cs";
} }
} }

View File

@ -109,7 +109,7 @@ public class CloudSigmaComputeServiceAdapter implements
} }
@Override @Override
public ServerInfo runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, public ServerInfo createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore) { Map<String, Credentials> credentialStore) {
long bootSize = (long) (template.getHardware().getVolumes().get(0).getSize() * 1024 * 1024 * 1024l); long bootSize = (long) (template.getHardware().getVolumes().get(0).getSize() * 1024 * 1024 * 1024l);
logger.debug(">> imaging boot drive source(%s) bytes(%d)", template.getImage().getId(), bootSize); logger.debug(">> imaging boot drive source(%s) bytes(%d)", template.getImage().getId(), bootSize);

View File

@ -20,7 +20,7 @@
package org.jclouds.cloudsigma.compute.functions; package org.jclouds.cloudsigma.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -92,7 +92,7 @@ public class ServerInfoToNodeMetadata implements Function<ServerInfo, NodeMetada
builder.ids(from.getUuid()); builder.ids(from.getUuid());
builder.name(from.getName()); builder.name(from.getName());
builder.location(locationSupplier.get()); builder.location(locationSupplier.get());
builder.tag(parseTagFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
String imageId = getImageIdFromServer.apply(from); String imageId = getImageIdFromServer.apply(from);
if (imageId != null) { if (imageId != null) {

View File

@ -31,7 +31,7 @@ public class ElasticHostsBlueSquareLondonComputeServiceLiveTest extends ElasticS
public ElasticHostsBlueSquareLondonComputeServiceLiveTest() { public ElasticHostsBlueSquareLondonComputeServiceLiveTest() {
provider = "elastichosts-lon-b"; provider = "elastichosts-lon-b";
tag = "elastichosts"; group = "elastichosts";
} }
} }

View File

@ -31,7 +31,7 @@ public class ElasticHostsPeer1LondonComputeServiceLiveTest extends ElasticStackC
public ElasticHostsPeer1LondonComputeServiceLiveTest() { public ElasticHostsPeer1LondonComputeServiceLiveTest() {
provider = "elastichosts-lon-p"; provider = "elastichosts-lon-p";
tag = "elastichosts"; group = "elastichosts";
} }
} }

View File

@ -31,7 +31,7 @@ public class ElasticHostsPeer1SanAntonioComputeServiceLiveTest extends ElasticSt
public ElasticHostsPeer1SanAntonioComputeServiceLiveTest() { public ElasticHostsPeer1SanAntonioComputeServiceLiveTest() {
provider = "elastichosts-sat-p"; provider = "elastichosts-sat-p";
tag = "elastichosts"; group = "elastichosts";
} }
} }

View File

@ -34,7 +34,7 @@ public class EucalyptusPartnerCloudEucalyptusComputeServiceLiveTest extends Euca
public EucalyptusPartnerCloudEucalyptusComputeServiceLiveTest() { public EucalyptusPartnerCloudEucalyptusComputeServiceLiveTest() {
provider = "eucalyptus-partnercloud-ec2"; provider = "eucalyptus-partnercloud-ec2";
// security groups must be <30 characters // security groups must be <30 characters
tag = "eu"; group = "eu";
} }
@Override @Override
@ -45,4 +45,9 @@ public class EucalyptusPartnerCloudEucalyptusComputeServiceLiveTest extends Euca
.getProperty("test.eucalyptus-partnercloud-ec2.virtualization-type")); .getProperty("test.eucalyptus-partnercloud-ec2.virtualization-type"));
return overrides; return overrides;
} }
// test hangs
@Override
public void testExtendedOptionsAndLogin() throws Exception {
}
} }

View File

@ -20,14 +20,14 @@
package org.jclouds.gogrid.compute.config; package org.jclouds.gogrid.compute.config;
import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.gogrid.compute.strategy.GoGridAddNodeWithTagStrategy; import org.jclouds.gogrid.compute.strategy.FindPublicIpThenCreateNodeInGroup;
import org.jclouds.gogrid.compute.strategy.GoGridDestroyNodeStrategy; import org.jclouds.gogrid.compute.strategy.GoGridDestroyNodeStrategy;
import org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy; import org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy;
import org.jclouds.gogrid.compute.strategy.GoGridLifeCycleStrategy; import org.jclouds.gogrid.compute.strategy.GoGridLifeCycleStrategy;
@ -40,8 +40,8 @@ import org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy;
*/ */
public class GoGridBindComputeStrategiesByClass extends BindComputeStrategiesByClass { public class GoGridBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
@Override @Override
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() { protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
return GoGridAddNodeWithTagStrategy.class; return FindPublicIpThenCreateNodeInGroup.class;
} }
@Override @Override

View File

@ -20,7 +20,7 @@
package org.jclouds.gogrid.compute.functions; package org.jclouds.gogrid.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -109,7 +109,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
builder.ids(from.getId() + ""); builder.ids(from.getId() + "");
builder.name(from.getName()); builder.name(from.getName());
builder.location(locations.get().get(from.getDatacenter().getId() + "")); builder.location(locations.get().get(from.getDatacenter().getId() + ""));
builder.tag(parseTagFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
builder.hardware(parseHardware(from)); builder.hardware(parseHardware(from));
builder.imageId(from.getImage().getId() + ""); builder.imageId(from.getImage().getId() + "");

View File

@ -31,7 +31,7 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.domain.Ip; import org.jclouds.gogrid.domain.Ip;
import org.jclouds.gogrid.domain.IpType; import org.jclouds.gogrid.domain.IpType;
@ -49,7 +49,7 @@ import com.google.common.collect.Iterables;
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Singleton @Singleton
public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy { public class FindPublicIpThenCreateNodeInGroup implements CreateNodeWithGroupEncodedIntoName {
private final GoGridClient client; private final GoGridClient client;
private final Function<Hardware, String> sizeToRam; private final Function<Hardware, String> sizeToRam;
private final Function<Server, NodeMetadata> serverToNodeMetadata; private final Function<Server, NodeMetadata> serverToNodeMetadata;
@ -57,7 +57,7 @@ public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
private RetryablePredicate<Server> serverLatestJobCompletedShort; private RetryablePredicate<Server> serverLatestJobCompletedShort;
@Inject @Inject
protected GoGridAddNodeWithTagStrategy(GoGridClient client, protected FindPublicIpThenCreateNodeInGroup(GoGridClient client,
Function<Server, NodeMetadata> serverToNodeMetadata, Function<Hardware, String> sizeToRam, Function<Server, NodeMetadata> serverToNodeMetadata, Function<Hardware, String> sizeToRam,
Timeouts timeouts) { Timeouts timeouts) {
this.client = client; this.client = client;
@ -71,7 +71,7 @@ public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
} }
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
Server addedServer = null; Server addedServer = null;
boolean notStarted = true; boolean notStarted = true;
int numOfRetries = 20; int numOfRetries = 20;

View File

@ -73,7 +73,7 @@ public class ServerToNodeMetadataTest {
Server server = createMock(Server.class); Server server = createMock(Server.class);
expect(server.getId()).andReturn(1000l).atLeastOnce(); expect(server.getId()).andReturn(1000l).atLeastOnce();
expect(server.getName()).andReturn("tag-ff").atLeastOnce(); expect(server.getName()).andReturn("group-ff").atLeastOnce();
expect(server.getState()).andReturn(ServerState.ON).atLeastOnce(); expect(server.getState()).andReturn(ServerState.ON).atLeastOnce();
expect(serverStateToNodeState.get(ServerState.ON)).andReturn(NodeState.RUNNING); expect(serverStateToNodeState.get(ServerState.ON)).andReturn(NodeState.RUNNING);
@ -83,7 +83,7 @@ public class ServerToNodeMetadataTest {
Map<String, Credentials> credentialsMap = createMock(Map.class); Map<String, Credentials> credentialsMap = createMock(Map.class);
expect(client.getServerCredentialsList()).andReturn(credentialsMap); expect(client.getServerCredentialsList()).andReturn(credentialsMap);
expect(credentialsMap.get("tag-ff")).andReturn(new Credentials("user", "pass")); expect(credentialsMap.get("group-ff")).andReturn(new Credentials("user", "pass"));
expect(server.getIp()).andReturn(new Ip("127.0.0.1")); expect(server.getIp()).andReturn(new Ip("127.0.0.1"));
@ -112,7 +112,7 @@ public class ServerToNodeMetadataTest {
NodeMetadata metadata = parser.apply(server); NodeMetadata metadata = parser.apply(server);
assertEquals(metadata.getLocation(), location); assertEquals(metadata.getLocation(), location);
assertEquals(metadata.getImageId(), "2000"); assertEquals(metadata.getImageId(), "2000");
assertEquals(metadata.getTag(), "tag"); assertEquals(metadata.getGroup(), "group");
assertEquals(metadata.getCredentials(), new Credentials("user", "pass")); assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
verify(caller); verify(caller);

View File

@ -31,7 +31,7 @@ public class OpenHostingEast1ComputeServiceLiveTest extends ElasticStackComputeS
public OpenHostingEast1ComputeServiceLiveTest() { public OpenHostingEast1ComputeServiceLiveTest() {
provider = "openhosting-east1"; provider = "openhosting-east1";
tag = "openhosting"; group = "openhosting";
} }
} }

View File

@ -31,7 +31,7 @@ public class ServerloveManchesterComputeServiceLiveTest extends ElasticStackComp
public ServerloveManchesterComputeServiceLiveTest() { public ServerloveManchesterComputeServiceLiveTest() {
provider = "serverlove-z1-man"; provider = "serverlove-z1-man";
tag = "serverlove"; group = "serverlove";
} }
} }

View File

@ -20,14 +20,14 @@
package org.jclouds.slicehost.compute.config; package org.jclouds.slicehost.compute.config;
import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.slicehost.compute.strategy.SlicehostAddNodeWithTagStrategy; import org.jclouds.slicehost.compute.strategy.SlicehostCreateNodeWithGroupEncodedIntoName;
import org.jclouds.slicehost.compute.strategy.SlicehostDestroyNodeStrategy; import org.jclouds.slicehost.compute.strategy.SlicehostDestroyNodeStrategy;
import org.jclouds.slicehost.compute.strategy.SlicehostGetNodeMetadataStrategy; import org.jclouds.slicehost.compute.strategy.SlicehostGetNodeMetadataStrategy;
import org.jclouds.slicehost.compute.strategy.SlicehostListNodesStrategy; import org.jclouds.slicehost.compute.strategy.SlicehostListNodesStrategy;
@ -41,8 +41,8 @@ import org.jclouds.slicehost.compute.strategy.SlicehostLifeCycleStrategy;
public class SlicehostBindComputeStrategiesByClass extends BindComputeStrategiesByClass { public class SlicehostBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
@Override @Override
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() { protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
return SlicehostAddNodeWithTagStrategy.class; return SlicehostCreateNodeWithGroupEncodedIntoName.class;
} }
@Override @Override

View File

@ -20,7 +20,7 @@
package org.jclouds.slicehost.compute.functions; package org.jclouds.slicehost.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -104,7 +104,7 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
builder.ids(from.getId() + ""); builder.ids(from.getId() + "");
builder.name(from.getName()); builder.name(from.getName());
builder.location(location.get()); builder.location(location.get());
builder.tag(parseTagFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
builder.imageId(from.getImageId() + ""); builder.imageId(from.getImageId() + "");
builder.operatingSystem(parseOperatingSystem(from)); builder.operatingSystem(parseOperatingSystem(from));
builder.hardware(parseHardware(from)); builder.hardware(parseHardware(from));

View File

@ -28,7 +28,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.slicehost.SlicehostClient; import org.jclouds.slicehost.SlicehostClient;
import org.jclouds.slicehost.domain.Slice; import org.jclouds.slicehost.domain.Slice;
@ -40,13 +40,13 @@ import com.google.common.base.Function;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class SlicehostAddNodeWithTagStrategy implements AddNodeWithTagStrategy { public class SlicehostCreateNodeWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName {
protected final SlicehostClient client; protected final SlicehostClient client;
protected final Map<String, Credentials> credentialStore; protected final Map<String, Credentials> credentialStore;
protected final Function<Slice, NodeMetadata> sliceToNodeMetadata; protected final Function<Slice, NodeMetadata> sliceToNodeMetadata;
@Inject @Inject
protected SlicehostAddNodeWithTagStrategy(SlicehostClient client, Map<String, Credentials> credentialStore, protected SlicehostCreateNodeWithGroupEncodedIntoName(SlicehostClient client, Map<String, Credentials> credentialStore,
Function<Slice, NodeMetadata> sliceToNodeMetadata) { Function<Slice, NodeMetadata> sliceToNodeMetadata) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.credentialStore = checkNotNull(credentialStore, "credentialStore");
@ -54,7 +54,7 @@ public class SlicehostAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
} }
@Override @Override
public NodeMetadata addNodeWithTag(String tag, String name, Template template) { public NodeMetadata createNodeWithGroupEncodedIntoName(String group, 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("node#" + from.getId(), new Credentials("root", from.getRootPassword())); credentialStore.put("node#" + from.getId(), new Credentials("root", from.getRootPassword()));

View File

@ -72,7 +72,7 @@ public class SliceToNodeMetadataTest {
NodeMetadata metadata = parser.apply(slice); NodeMetadata metadata = parser.apply(slice);
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")).group("jclouds")
.imageId("2").id("1").providerId("1").name("jclouds-foo").location(provider).credentials(creds) .imageId("2").id("1").providerId("1").name("jclouds-foo").location(provider).credentials(creds)
.userMetadata(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());
} }
@ -91,7 +91,7 @@ public class SliceToNodeMetadataTest {
NodeMetadata metadata = parser.apply(slice); NodeMetadata metadata = parser.apply(slice);
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")).group("jclouds")
.imageId("2").id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata( .imageId("2").id("1").providerId("1").name("jclouds-foo").location(provider).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());
} }
@ -110,7 +110,7 @@ public class SliceToNodeMetadataTest {
NodeMetadata metadata = parser.apply(slice); NodeMetadata metadata = parser.apply(slice);
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")).group("jclouds")
.imageId("2").operatingSystem( .imageId("2").operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2") new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
.is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").location(provider) .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").location(provider)
@ -130,7 +130,7 @@ public class SliceToNodeMetadataTest {
NodeMetadata metadata = parser.apply(slice); NodeMetadata metadata = parser.apply(slice);
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")).group("jclouds")
.imageId("2").hardware( .imageId("2").hardware(
new HardwareBuilder().ids("1").name("256 slice").processors( new HardwareBuilder().ids("1").name("256 slice").processors(
ImmutableList.of(new Processor(0.25, 1.0))).ram(256).volumes( ImmutableList.of(new Processor(0.25, 1.0))).ram(256).volumes(

View File

@ -52,7 +52,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv
@Override @Override
public void setServiceDefaults() { public void setServiceDefaults() {
tag = "te"; group = "te";
} }
@Test @Test

View File

@ -52,7 +52,7 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer
@Override @Override
public void setServiceDefaults() { public void setServiceDefaults() {
tag = "vcx"; group = "vcx";
} }
@Test @Test

View File

@ -45,7 +45,7 @@ import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -73,7 +73,7 @@ public class LibvirtComputeService extends BaseComputeService {
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Image>> images,
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles, @Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy, ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider, Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,

View File

@ -20,7 +20,7 @@
package org.jclouds.libvirt.compute.functions; package org.jclouds.libvirt.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -88,7 +88,7 @@ public class DomainToNodeMetadata implements Function<Domain, NodeMetadata> {
builder.providerId(from.getID() + ""); builder.providerId(from.getID() + "");
builder.name(from.getName()); builder.name(from.getName());
builder.location(findLocationForDomain.apply(from)); builder.location(findLocationForDomain.apply(from));
builder.tag(parseTagFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
builder.operatingSystem(new OperatingSystemBuilder().description(from.getOSType()).build()); builder.operatingSystem(new OperatingSystemBuilder().description(from.getOSType()).build());
builder.hardware(findHardwareForDomain.apply(from)); builder.hardware(findHardwareForDomain.apply(from));

View File

@ -81,7 +81,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
} }
@Override @Override
public Domain runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, public Domain createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore) { Map<String, Credentials> credentialStore) {
try { try {
String domainName = tag; String domainName = tag;

View File

@ -77,7 +77,7 @@ public class LibvirtExperimentLiveTest {
* the default template via overriding a method in standalonecomputeservicexontextmodule * the default template via overriding a method in standalonecomputeservicexontextmodule
*/ */
Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().runNodesWithTag("tty", 1); Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().createNodesInGroup("tty", 1);
for (NodeMetadata nodeMetadata : nodeMetadataSet) { for (NodeMetadata nodeMetadata : nodeMetadataSet) {
/* /*
* context.getComputeService().suspendNode(nodeMetadata.getId()); * context.getComputeService().suspendNode(nodeMetadata.getId());

View File

@ -69,7 +69,7 @@ public class SDNAuthAsyncClientTest extends RestClientTest<SDNAuthAsyncClient> {
@Override @Override
public RestContextSpec<SDNAuthClient, SDNAuthAsyncClient> createContextSpec() { public RestContextSpec<SDNAuthClient, SDNAuthAsyncClient> createContextSpec() {
return contextSpec("test", "http://localhost:8080", "1", "identity", "credential", SDNAuthClient.class, return contextSpec("test", "http://localhost:8080", "1", "", "identity", "credential", SDNAuthClient.class,
SDNAuthAsyncClient.class); SDNAuthAsyncClient.class);
} }

View File

@ -74,7 +74,7 @@ public class SDNAuthenticationLiveTest {
identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
RestContextSpec<SDNAuthClient, SDNAuthAsyncClient> contextSpec = contextSpec("test", endpoint, "1", identity, RestContextSpec<SDNAuthClient, SDNAuthAsyncClient> contextSpec = contextSpec("test", endpoint, "1", "", identity,
credential, SDNAuthClient.class, SDNAuthAsyncClient.class); credential, SDNAuthClient.class, SDNAuthAsyncClient.class);
context = createContextBuilder( context = createContextBuilder(

View File

@ -44,7 +44,7 @@ import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -69,7 +69,7 @@ public class ViComputeService extends BaseComputeService {
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Image>> images,
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles, @Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy, ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider, Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,

View File

@ -20,7 +20,7 @@
package org.jclouds.vi.compute.functions; package org.jclouds.vi.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -83,7 +83,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
builder.providerId(from.getConfig().getLocationId() + ""); builder.providerId(from.getConfig().getLocationId() + "");
builder.name(from.getName()); builder.name(from.getName());
builder.location(findLocationForVirtualMachine.apply(from)); builder.location(findLocationForVirtualMachine.apply(from));
builder.tag(parseTagFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
builder.operatingSystem(new OperatingSystemBuilder() builder.operatingSystem(new OperatingSystemBuilder()
.name(from.getConfig().getGuestFullName()) .name(from.getConfig().getGuestFullName())

Some files were not shown because too many files have changed in this diff Show More