fixed multi nodes creation issue

This commit is contained in:
andreaturli 2010-11-09 19:28:04 +01:00
parent 6fea7cc950
commit 7d0bd78770
2 changed files with 21 additions and 10 deletions

View File

@ -97,14 +97,24 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
// cloning volume
String poolName = storageVol.storagePoolLookupByVolume().getName();
StoragePool storagePool = client.storagePoolLookupByName(poolName);
StorageVol clonedVol = cloneVolume(storagePool, storageVol);
StorageVol clonedVol = null; //cloneVolume(storagePool, storageVol);
boolean cloned = false;
int retry = 0;
while(!cloned && retry<10) {
try {
clonedVol = cloneVolume(storagePool, storageVol);
cloned = true;
} catch (LibvirtException e) {
retry++;
Thread.sleep(1000);
}
}
// define Domain
String xmlFinal = generateClonedDomainXML(domain.getXMLDesc(0), clonedVol);
Domain newDomain = client.domainDefineXML(xmlFinal);
newDomain.create();
// store the credentials so that later functions can use them
credentialStore.put(domain.getUUIDString() + "", new Credentials("identity", "credential"));
credentialStore.put(domain.getUUIDString() + "", new Credentials("identity", "credential"));
return newDomain;
} catch (LibvirtException e) {
return propogate(e);
@ -163,9 +173,9 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
@Override
public void destroyNode(String id) {
try {
client.domainLookupByUUIDString(id).finalize();
client.domainLookupByUUIDString(id).destroy();
/* TODO
/*
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(
client.domainLookupByUUIDString(id).getXMLDesc(0)
)));
@ -175,7 +185,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
storageVol.delete(0);
client.domainLookupByUUIDString(id).undefine();
*/
*/
} catch (LibvirtException e) {
propogate(e);
} catch (Exception e) {
@ -206,7 +216,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException,
XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException {
return storagePool.storageVolCreateXML(generateClonedVolumeXML(from.getXMLDesc(0)), 0);
return storagePool.storageVolCreateXMLFrom(generateClonedVolumeXML(from.getXMLDesc(0)), from, 0);
}
@Override

View File

@ -86,13 +86,14 @@ public class LibvirtExperimentLiveTest {
* You can control the default template via overriding a method in standalonecomputeservicexontextmodule
*/
Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().runNodesWithTag("tty", 2);
Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().runNodesWithTag("tty", 1);
for (NodeMetadata nodeMetadata : nodeMetadataSet) {
context.getComputeService().suspendNode(nodeMetadata.getId());
Thread.sleep(3000);
context.getComputeService().resumeNode(nodeMetadata.getId());
// TODO seems that destroy is intended to be a force shutoff, not a delete VM ...
//context.getComputeService().destroyNode(nodeMetadata.getId());
context.getComputeService().destroyNode(nodeMetadata.getId());
}
} catch (Exception e) {
e.printStackTrace();