summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization')
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java76
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java11
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java50
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java11
4 files changed, 143 insertions, 5 deletions
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java
index 345900ab..3c654880 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java
@@ -8,16 +8,47 @@ import org.openslx.libvirt.capabilities.Capabilities;
import org.openslx.libvirt.xml.LibvirtXmlDocumentException;
import org.openslx.libvirt.xml.LibvirtXmlSerializationException;
import org.openslx.libvirt.xml.LibvirtXmlValidationException;
-
+import org.openslx.virtualization.Version;
+
+/**
+ * Representation of a Libvirt hypervisor backend (e.g. QEMU or VMware).
+ * <p>
+ * The representation allows to connect to a running Libvirt service and query the host system's
+ * capabilities or manage virtual machines.
+ *
+ * @implNote This class is the abstract representation to implement various Libvirt hypervisor
+ * backends using inheritance.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
public abstract class LibvirtHypervisor implements Closeable
{
+ /**
+ * Connection to a Libvirt hypervisor backend.
+ */
protected Connect hypervisor = null;
+ /**
+ * Creates a new Libvirt hypervisor backend specified by an URI and connects to the specified
+ * backend.
+ *
+ * @param connectionUri URI of a specific Libvirt hypervisor backend.
+ * @throws LibvirtHypervisorException failed to connect to the specified Libvirt hypervisor
+ * backend.
+ */
public LibvirtHypervisor( String connectionUri ) throws LibvirtHypervisorException
{
this.connect( connectionUri );
}
+ /**
+ * Connects to the Libvirt hypervisor backend specified by an URI.
+ *
+ * @param connectionUri URI of a specific Libvirt hypervisor backend.
+ * @throws LibvirtHypervisorException failed to connect to the specified Libvirt hypervisor
+ * backend.
+ */
protected void connect( String connectionUri ) throws LibvirtHypervisorException
{
try {
@@ -27,6 +58,13 @@ public abstract class LibvirtHypervisor implements Closeable
}
}
+ /**
+ * Returns the queried Libvirt hypervisor's host system capabilities.
+ *
+ * @return queried Libvirt hypervisor's host system capabilities.
+ * @throws LibvirtHypervisorException failed to query and return the Libvirt hypervisor's host
+ * system capabilities.
+ */
public Capabilities getCapabilites() throws LibvirtHypervisorException
{
Capabilities hypervisorCapabilities = null;
@@ -42,20 +80,41 @@ public abstract class LibvirtHypervisor implements Closeable
return hypervisorCapabilities;
}
- public int getVersion() throws LibvirtHypervisorException
+ /**
+ * Returns the version of the Libvirt hypervisor backend.
+ *
+ * @return version of the Libvirt hypervisor backend.
+ * @throws LibvirtHypervisorException failed to get the version of the Libvirt hypervisor
+ * backend.
+ */
+ public Version getVersion() throws LibvirtHypervisorException
{
- int hypervisorVersion = 0;
+ long hypervisorVersionRaw = 0;
+ Version hypervisorVersion = null;
try {
- final long hypervisorVersionLong = this.hypervisor.getVersion();
- hypervisorVersion = Long.valueOf( hypervisorVersionLong ).intValue();
+ hypervisorVersionRaw = this.hypervisor.getVersion();
} catch ( LibvirtException e ) {
throw new LibvirtHypervisorException( e.getLocalizedMessage() );
}
+ if ( hypervisorVersionRaw > 0 ) {
+ final short major = Long.valueOf( hypervisorVersionRaw / Long.valueOf( 1000000 ) ).shortValue();
+ hypervisorVersionRaw %= Long.valueOf( 1000000 );
+ final short minor = Long.valueOf( hypervisorVersionRaw / Long.valueOf( 1000 ) ).shortValue();
+ hypervisorVersion = new Version( major, minor );
+ }
+
return hypervisorVersion;
}
+ /**
+ * Register a virtual machine by the Libvirt hypervisor based on a virtualization configuration.
+ *
+ * @param vmConfiguration virtualization configuration for the virtual machine.
+ * @return instance of the registered and defined virtual machine.
+ * @throws LibvirtHypervisorException failed to register and define virtual machine.
+ */
public LibvirtVirtualMachine registerVm( org.openslx.libvirt.domain.Domain vmConfiguration )
throws LibvirtHypervisorException
{
@@ -71,6 +130,13 @@ public abstract class LibvirtHypervisor implements Closeable
return new LibvirtVirtualMachine( libvirtDomain );
}
+ /**
+ * Deregisters an already registered virtual machine by the Libvirt hypervisor.
+ *
+ * @param vm virtual machine that should be deregistered
+ * @throws LibvirtHypervisorException failed to deregister virtual machine by the Libvirt hypervisor.
+ * @throws LibvirtVirtualMachineException failed to check and stop the virtual machine.
+ */
public void deregisterVm( LibvirtVirtualMachine vm )
throws LibvirtHypervisorException, LibvirtVirtualMachineException
{
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java
index acf640e1..64ae6b20 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java
@@ -1,5 +1,11 @@
package org.openslx.runvirt.virtualization;
+/**
+ * An exception of a Libvirt hypervisor error during acquiring the hypervisor's functionality.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
public class LibvirtHypervisorException extends Exception
{
/**
@@ -7,6 +13,11 @@ public class LibvirtHypervisorException extends Exception
*/
private static final long serialVersionUID = -3631452625806770209L;
+ /**
+ * Creates a Libvirt hypervisor exception including an error message.
+ *
+ * @param errorMsg message to describe a specific Libvirt hypervisor error.
+ */
LibvirtHypervisorException( String errorMsg )
{
super( errorMsg );
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java
index 781bd938..32b99d66 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java
@@ -3,20 +3,45 @@ package org.openslx.runvirt.virtualization;
import org.libvirt.Domain;
import org.libvirt.LibvirtException;
+/**
+ * Representation of a Libvirt virtual machine.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
public class LibvirtVirtualMachine
{
+ /**
+ * Libvirt virtualization configuration of the virtual machine.
+ */
private Domain domain;
+ /**
+ * Creates a new Libvirt virtual machine specified by a virtualization configuration.
+ *
+ * @param vm Libvirt virtualization configuration to specify the Libvirt virtual machine.
+ */
LibvirtVirtualMachine( Domain vm )
{
this.domain = vm;
}
+ /**
+ * Returns the Libvirt virtualization configuration of the Libvirt virtual machine.
+ *
+ * @return Libvirt virtualization configuration of the Libvirt virtual machine.
+ */
public Domain getLibvirtDomain()
{
return this.domain;
}
+ /**
+ * Checks if the Libvirt virtual machine is running.
+ *
+ * @return state of the Libvirt virtual machine whether it is running or not.
+ * @throws LibvirtVirtualMachineException failed to check if Libvirt machine is running or not.
+ */
public boolean isRunning() throws LibvirtVirtualMachineException
{
int state = 0;
@@ -30,6 +55,11 @@ public class LibvirtVirtualMachine
return ( state == 0 ) ? false : true;
}
+ /**
+ * Starts the Libvirt virtual machine.
+ *
+ * @throws LibvirtVirtualMachineException failed to start the Libvirt virtual machine.
+ */
public void start() throws LibvirtVirtualMachineException
{
if ( !this.isRunning() ) {
@@ -41,6 +71,11 @@ public class LibvirtVirtualMachine
}
}
+ /**
+ * Stops the Libvirt virtual machine.
+ *
+ * @throws LibvirtVirtualMachineException failed to stop the Libvirt virtual machine.
+ */
public void stop() throws LibvirtVirtualMachineException
{
if ( this.isRunning() ) {
@@ -52,6 +87,11 @@ public class LibvirtVirtualMachine
}
}
+ /**
+ * Suspends the Libvirt virtual machine.
+ *
+ * @throws LibvirtVirtualMachineException failed to suspend the Libvirt virtual machine.
+ */
public void suspend() throws LibvirtVirtualMachineException
{
try {
@@ -61,6 +101,11 @@ public class LibvirtVirtualMachine
}
}
+ /**
+ * Resumes the Libvirt virtual machine.
+ *
+ * @throws LibvirtVirtualMachineException faild to resume the Libvirt virtual machine.
+ */
public void resume() throws LibvirtVirtualMachineException
{
try {
@@ -70,6 +115,11 @@ public class LibvirtVirtualMachine
}
}
+ /**
+ * Reboot the Libvirt virtual machine.
+ *
+ * @throws LibvirtVirtualMachineException failed to reboot the Libvirt virtual machine.
+ */
public void reboot() throws LibvirtVirtualMachineException
{
try {
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java
index 4e8ee1ba..dd490be3 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java
@@ -1,5 +1,11 @@
package org.openslx.runvirt.virtualization;
+/**
+ * An exception of a Libvirt virtual machine error during controlling the virtual machine.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
public class LibvirtVirtualMachineException extends Exception
{
/**
@@ -7,6 +13,11 @@ public class LibvirtVirtualMachineException extends Exception
*/
private static final long serialVersionUID = -5371327391243047616L;
+ /**
+ * Creates a Libvirt virtual machine exception including an error message.
+ *
+ * @param errorMsg message to describe a specific Libvirt virtual machine error.
+ */
public LibvirtVirtualMachineException( String errorMsg )
{
super( errorMsg );