Issue 327: fixed terremark tag pattern and disk parsing

This commit is contained in:
Adrian Cole 2010-08-15 12:50:03 -07:00
parent 3363f62b83
commit 5b215533f1
5 changed files with 91 additions and 92 deletions

View File

@ -103,14 +103,13 @@ public class BaseComputeService implements ComputeService {
@Inject
protected BaseComputeService(ComputeServiceContext context, Provider<Set<? extends Image>> images,
Provider<Set<? extends Size>> sizes, Provider<Set<? extends Location>> locations,
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateOptions> templateOptionsProvider,
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated, ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
Provider<Set<? extends Size>> sizes, Provider<Set<? extends Location>> locations,
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateOptions> templateOptionsProvider, @Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated, ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.context = checkNotNull(context, "context");
this.images = checkNotNull(images, "images");
this.sizes = checkNotNull(sizes, "sizes");
@ -141,12 +140,12 @@ public class BaseComputeService implements ComputeService {
*/
@Override
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template)
throws RunNodesException {
throws RunNodesException {
checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens");
checkNotNull(template.getLocation(), "location");
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", count, count > 1 ? "s"
: "", tag, template.getLocation().getId(), template.getImage().getProviderId(), template.getSize()
.getProviderId(), template.getOptions());
: "", tag, template.getLocation().getId(), template.getImage().getProviderId(), template.getSize()
.getProviderId(), template.getOptions());
Set<NodeMetadata> nodes = Sets.newHashSet();
Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
Map<?, Future<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count, template, nodes, badNodes);
@ -162,7 +161,7 @@ public class BaseComputeService implements ComputeService {
*/
@Override
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, TemplateOptions templateOptions)
throws RunNodesException {
throws RunNodesException {
return runNodesWithTag(tag, count, templateBuilder().any().options(templateOptions).build());
}
@ -193,23 +192,23 @@ public class BaseComputeService implements ComputeService {
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> destroying nodes matching(%s)", filter);
Set<NodeMetadata> set = Sets.newLinkedHashSet(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, Future<NodeMetadata>>() {
new Function<NodeMetadata, Future<NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping
@Override
public Future<NodeMetadata> apply(final NodeMetadata from) {
return executor.submit(new Callable<NodeMetadata>() {
// TODO make an async interface instead of re-wrapping
@Override
public Future<NodeMetadata> apply(final NodeMetadata from) {
return executor.submit(new Callable<NodeMetadata>() {
@Override
public NodeMetadata call() throws Exception {
destroyNode(from.getId());
return from;
}
@Override
public NodeMetadata call() throws Exception {
destroyNode(from.getId());
return from;
}
});
}
});
}
}, executor, null, logger, "destroying nodes"));
}, executor, null, logger, "destroying nodes"));
logger.debug("<< destroyed(%d)", set.size());
return set;
}
@ -317,7 +316,7 @@ public class BaseComputeService implements ComputeService {
*/
@Override
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, Payload runScript)
throws RunScriptOnNodesException {
throws RunScriptOnNodesException {
return runScriptOnNodesMatching(filter, runScript, RunScriptOptions.NONE);
}
@ -326,9 +325,9 @@ public class BaseComputeService implements ComputeService {
*/
@Override
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
final Payload runScript, @Nullable final RunScriptOptions options) throws RunScriptOnNodesException {
final Payload runScript, @Nullable final RunScriptOptions options) throws RunScriptOnNodesException {
Iterable<NodeMetadata> nodes = verifyParametersAndListNodes(filter, runScript, (options != null) ? options
: RunScriptOptions.NONE);
: RunScriptOptions.NONE);
final Map<NodeMetadata, ExecResponse> execs = Maps.newHashMap();
@ -374,7 +373,7 @@ public class BaseComputeService implements ComputeService {
}
private Iterable<NodeMetadata> verifyParametersAndListNodes(Predicate<NodeMetadata> filter, Payload runScript,
final RunScriptOptions options) {
final RunScriptOptions options) {
checkNotNull(filter, "Filter must be provided");
checkNotNull(runScript, "The script (represented by bytes array - use \"script\".getBytes() must be provided");
checkNotNull(options, "options");
@ -395,9 +394,9 @@ public class BaseComputeService implements ComputeService {
// don't override
checkNotNull(node.getCredentials(), "If the default credentials need to be used, they can't be null");
checkNotNull(node.getCredentials().identity, "Account name for ssh authentication must be "
+ "specified. Try passing RunScriptOptions with new credentials");
+ "specified. Try passing RunScriptOptions with new credentials");
checkNotNull(node.getCredentials().credential, "Key or password for ssh authentication must be "
+ "specified. Try passing RunScriptOptions with new credentials");
+ "specified. Try passing RunScriptOptions with new credentials");
}
return node;
}

View File

@ -138,7 +138,7 @@ public abstract class BaseComputeServiceLiveTest {
String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8);
assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret;
return ImmutableMap.<String, String> of("private", secret, "public", Files.toString(new File(secretKeyFile
+ ".pub"), Charsets.UTF_8));
+ ".pub"), Charsets.UTF_8));
}
protected void setupCredentials() {
@ -154,7 +154,7 @@ public abstract class BaseComputeServiceLiveTest {
if (context != null)
context.close();
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet.of(
new Log4JLoggingModule(), getSshModule()));
new Log4JLoggingModule(), getSshModule()));
client = context.getComputeService();
}
@ -171,7 +171,7 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
public void testCorrectAuthException() throws Exception {
new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA",
ImmutableSet.<Module> of(new Log4JLoggingModule())).close();
ImmutableSet.<Module> of(new Log4JLoggingModule())).close();
}
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
@ -204,7 +204,7 @@ public abstract class BaseComputeServiceLiveTest {
Image image = get(nodes, 0).getImage();
try {
Map<? extends NodeMetadata, ExecResponse> responses = runScriptWithCreds(tag, image.getOsFamily(),
new Credentials(good.identity, "romeo"));
new Credentials(good.identity, "romeo"));
assert false : "shouldn't pass with a bad password\n" + responses;
} catch (RunScriptOnNodesException e) {
assert getRootCause(e).getMessage().contains("Auth fail") : e;
@ -238,8 +238,8 @@ public abstract class BaseComputeServiceLiveTest {
template = buildTemplate(client.templateBuilder());
template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey(
newStringPayload(keyPair.get("public"))).runScript(
newStringPayload(buildScript(template.getImage().getOsFamily())));
newStringPayload(keyPair.get("public"))).runScript(
newStringPayload(buildScript(template.getImage().getOsFamily())));
try {
nodes = newTreeSet(client.runNodesWithTag(tag, 2, template));
} catch (RunNodesException e) {
@ -255,9 +255,10 @@ public abstract class BaseComputeServiceLiveTest {
assertLocationSameOrChild(node1.getLocation(), template.getLocation());
assertLocationSameOrChild(node2.getLocation(), template.getLocation());
assertEquals(node1.getImage(), template.getImage());
assertEquals(node2.getImage(), template.getImage());
if (node1.getImage() != null)
assertEquals(node1.getImage(), template.getImage());
if (node2.getImage() != null)
assertEquals(node2.getImage(), template.getImage());
}
@ -282,10 +283,10 @@ public abstract class BaseComputeServiceLiveTest {
}
protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String tag, OsFamily osFamily,
Credentials creds) throws RunScriptOnNodesException {
Credentials creds) throws RunScriptOnNodesException {
try {
return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(osFamily)),
overrideCredentialsWith(creds));
overrideCredentialsWith(creds));
} catch (SshException e) {
if (getRootCause(e).getMessage().contains("Auth fail")) {
// System.err.printf("bad credentials: %s:%s for %s%n",
@ -318,32 +319,31 @@ public abstract class BaseComputeServiceLiveTest {
public static String buildScript(OsFamily osFamily) {
switch (osFamily) {
case UBUNTU:
return new StringBuilder()//
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
.append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")//
.append(
"sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")//
.append("apt-get update\n")//
.append("apt-get install -f -y --force-yes openjdk-6-jdk\n")//
.append("wget -qO/usr/bin/runurl run.alestic.com/runurl\n")//
.append("chmod 755 /usr/bin/runurl\n")//
.toString();
case CENTOS:
case RHEL:
return new StringBuilder()
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")
.append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append(
"echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("yum --nogpgcheck -y install java-1.6.0-openjdk\n")
.append(
"echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")
.toString();
default:
throw new IllegalArgumentException(osFamily.toString());
case UBUNTU:
return new StringBuilder()//
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
.append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")//
.append(
"sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")//
.append("apt-get update\n")//
.append("apt-get install -f -y --force-yes openjdk-6-jdk\n")//
.append("wget -qO/usr/bin/runurl run.alestic.com/runurl\n")//
.append("chmod 755 /usr/bin/runurl\n")//
.toString();
case CENTOS:
case RHEL:
return new StringBuilder()
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")
.append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append(
"echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n").append(
"yum --nogpgcheck -y install java-1.6.0-openjdk\n").append(
"echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")
.toString();
default:
throw new IllegalArgumentException(osFamily.toString());
}
}
@ -367,7 +367,7 @@ public abstract class BaseComputeServiceLiveTest {
protected void assertNodeZero(Set<? extends NodeMetadata> metadataSet) {
assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]",
metadataSet, nodes);
metadataSet, nodes);
}
@Test(enabled = true, dependsOnMethods = "testGet")
@ -428,26 +428,26 @@ public abstract class BaseComputeServiceLiveTest {
assert location != location.getParent() : location;
assert location.getScope() != null : location;
switch (location.getScope()) {
case PROVIDER:
assertProvider(location);
break;
case REGION:
assertProvider(location.getParent());
break;
case ZONE:
Location provider = location.getParent().getParent();
// zone can be a direct descendant of provider
if (provider == null)
provider = location.getParent();
assertProvider(provider);
break;
case HOST:
Location provider2 = location.getParent().getParent().getParent();
// zone can be a direct descendant of provider
if (provider2 == null)
provider2 = location.getParent().getParent();
assertProvider(provider2);
break;
case PROVIDER:
assertProvider(location);
break;
case REGION:
assertProvider(location.getParent());
break;
case ZONE:
Location provider = location.getParent().getParent();
// zone can be a direct descendant of provider
if (provider == null)
provider = location.getParent();
assertProvider(provider);
break;
case HOST:
Location provider2 = location.getParent().getParent().getParent();
// zone can be a direct descendant of provider
if (provider2 == null)
provider2 = location.getParent().getParent();
assertProvider(provider2);
break;
}
}
}

View File

@ -60,7 +60,7 @@ public class GetExtra implements Function<VApp, Map<String, String>> {
.getVirtualQuantity()
+ "");
for (ResourceAllocation disk : filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))) {
extra.put(String.format("disk_drive/%s/kb", disk.getId()), disk.getVirtualQuantity() + "");
extra.put(String.format("disk_drive/%s/kb", disk.getAddressOnParent()), disk.getVirtualQuantity() + "");
}
for (Entry<String, String> net : vApp.getNetworkToAddresses().entries()) {

View File

@ -67,7 +67,7 @@ public class VCloudGetNodeMetadata {
protected final GetExtra getExtra;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
public static final Pattern TAG_PATTERN_WITHOUT_TEMPLATE = Pattern.compile("([^-]+)-[0-9]+");
public static final Pattern TAG_PATTERN_WITHOUT_TEMPLATE = Pattern.compile("([^-]+)-[0-9a-f]+");
@Inject
VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient,

View File

@ -69,7 +69,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(node.getType(), ComputeType.NODE);
NodeMetadata allData = client.getNodeMetadata(node.getId());
assert allData.getExtra().get("processor/count") != null : allData.getExtra();
assert allData.getExtra().get("disk_drive/1/kb") != null : allData.getExtra();
assert allData.getExtra().get("disk_drive/0/kb") != null : allData.getExtra();
assert allData.getExtra().get("memory/mb") != null : allData.getExtra();
System.out.println(allData.getExtra());
}