mirror of
https://github.com/apache/jclouds.git
synced 2025-02-17 15:35:44 +00:00
fixed multi nodes creation issue
This commit is contained in:
parent
6fea7cc950
commit
7d0bd78770
@ -97,14 +97,24 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||||||
// cloning volume
|
// cloning volume
|
||||||
String poolName = storageVol.storagePoolLookupByVolume().getName();
|
String poolName = storageVol.storagePoolLookupByVolume().getName();
|
||||||
StoragePool storagePool = client.storagePoolLookupByName(poolName);
|
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
|
// define Domain
|
||||||
String xmlFinal = generateClonedDomainXML(domain.getXMLDesc(0), clonedVol);
|
String xmlFinal = generateClonedDomainXML(domain.getXMLDesc(0), clonedVol);
|
||||||
Domain newDomain = client.domainDefineXML(xmlFinal);
|
Domain newDomain = client.domainDefineXML(xmlFinal);
|
||||||
newDomain.create();
|
newDomain.create();
|
||||||
// store the credentials so that later functions can use them
|
// 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;
|
return newDomain;
|
||||||
} catch (LibvirtException e) {
|
} catch (LibvirtException e) {
|
||||||
return propogate(e);
|
return propogate(e);
|
||||||
@ -163,9 +173,9 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||||||
@Override
|
@Override
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
try {
|
try {
|
||||||
client.domainLookupByUUIDString(id).finalize();
|
client.domainLookupByUUIDString(id).destroy();
|
||||||
|
|
||||||
/* TODO
|
/*
|
||||||
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(
|
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(
|
||||||
client.domainLookupByUUIDString(id).getXMLDesc(0)
|
client.domainLookupByUUIDString(id).getXMLDesc(0)
|
||||||
)));
|
)));
|
||||||
@ -175,7 +185,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||||||
storageVol.delete(0);
|
storageVol.delete(0);
|
||||||
|
|
||||||
client.domainLookupByUUIDString(id).undefine();
|
client.domainLookupByUUIDString(id).undefine();
|
||||||
*/
|
*/
|
||||||
} catch (LibvirtException e) {
|
} catch (LibvirtException e) {
|
||||||
propogate(e);
|
propogate(e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -206,7 +216,7 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||||||
|
|
||||||
private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException,
|
private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException,
|
||||||
XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException {
|
XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException {
|
||||||
return storagePool.storageVolCreateXML(generateClonedVolumeXML(from.getXMLDesc(0)), 0);
|
return storagePool.storageVolCreateXMLFrom(generateClonedVolumeXML(from.getXMLDesc(0)), from, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,13 +86,14 @@ public class LibvirtExperimentLiveTest {
|
|||||||
* You can control the default template via overriding a method in standalonecomputeservicexontextmodule
|
* 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) {
|
for (NodeMetadata nodeMetadata : nodeMetadataSet) {
|
||||||
|
|
||||||
context.getComputeService().suspendNode(nodeMetadata.getId());
|
context.getComputeService().suspendNode(nodeMetadata.getId());
|
||||||
Thread.sleep(3000);
|
|
||||||
context.getComputeService().resumeNode(nodeMetadata.getId());
|
context.getComputeService().resumeNode(nodeMetadata.getId());
|
||||||
|
|
||||||
// TODO seems that destroy is intended to be a force shutoff, not a delete VM ...
|
// 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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user