From 43ef09727cdbcf7ba0a7ad5832efccb7713e1236 Mon Sep 17 00:00:00 2001 From: Alexander Verhaar Date: Sat, 17 Dec 2022 00:16:04 +0100 Subject: [PATCH 1/4] New features - Added Migrate3 methods - Finally added `getJobStats` with all the necessary changes --- src/main/java/org/libvirt/Domain.java | 376 ++++++++++++------ src/main/java/org/libvirt/jna/Libvirt.java | 9 +- .../jna/structures/virTypedParameter.java | 9 + .../structures/virTypedParameterValue.java | 2 + .../parameters/DomainMigrateParameters.java | 270 +++++++++++++ .../typed/TypedBooleanParameter.java | 10 +- .../typed/TypedDoubleParameter.java | 6 +- .../parameters/typed/TypedIntParameter.java | 6 +- .../parameters/typed/TypedLongParameter.java | 6 +- .../parameters/typed/TypedParameter.java | 57 ++- .../typed/TypedStringParameter.java | 36 ++ .../parameters/typed/TypedUintParameter.java | 6 +- .../parameters/typed/TypedUlongParameter.java | 6 +- .../java/org/libvirt/TestJavaBindings.java | 95 +++-- 14 files changed, 711 insertions(+), 183 deletions(-) create mode 100644 src/main/java/org/libvirt/parameters/DomainMigrateParameters.java create mode 100644 src/main/java/org/libvirt/parameters/typed/TypedStringParameter.java diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index ef56add..60b8a2d 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -6,11 +6,15 @@ import java.nio.ByteBuffer; import java.util.Arrays; +import java.util.Optional; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import com.sun.jna.Native; import com.sun.jna.NativeLong; +import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; import org.libvirt.event.BlockJobListener; import org.libvirt.event.IOErrorListener; import org.libvirt.event.LifecycleListener; @@ -21,7 +25,6 @@ import org.libvirt.flags.DomainDeviceModifyFlags; import org.libvirt.flags.DomainMetadataFlags; import org.libvirt.flags.DomainMigrateFlags; -import org.libvirt.flags.DomainSnapshotListFlags; import org.libvirt.jna.Libvirt; import org.libvirt.jna.pointers.DomainPointer; import org.libvirt.jna.pointers.DomainSnapshotPointer; @@ -37,12 +40,12 @@ import org.libvirt.jna.structures.virVcpuInfo; import org.libvirt.jna.types.CString; import org.libvirt.jna.types.SizeT; -import org.libvirt.parameters.DomainBlockCopyParameters; import org.libvirt.parameters.typed.TypedParameter; /** * A virtual machine defined within libvirt. */ +@SuppressWarnings("unused") public class Domain { /** @@ -57,8 +60,7 @@ public class Domain { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((virConnect == null) ? 0 : virConnect.hashCode()); + result = prime * result + virConnect.hashCode(); try { result = prime * result + ((VDP == null) ? 0 : Arrays.hashCode(this.getUUID())); } catch (LibvirtException e) { @@ -143,7 +145,7 @@ static Domain constructIncRef(Connect virConnect, DomainPointer VDP) throws Libv * aborted. * * @return ignore (always 0) - * @throws LibvirtException + * @throws LibvirtException on error */ public int abortJob() throws LibvirtException { return processError(libvirt.virDomainAbortJob(VDP)); @@ -153,7 +155,7 @@ public int abortJob() throws LibvirtException { * Creates a virtual device attachment to backend. * * @param xmlDesc XML description of one device - * @throws LibvirtException + * @throws LibvirtException on error */ public void attachDevice(String xmlDesc) throws LibvirtException { processError(libvirt.virDomainAttachDevice(VDP, xmlDesc)); @@ -164,7 +166,7 @@ public void attachDevice(String xmlDesc) throws LibvirtException { * * @param xmlDesc XML description of one device * @param flags the an OR'ed set of virDomainDeviceModifyFlags - * @throws LibvirtException + * @throws LibvirtException on error */ public void attachDeviceFlags(String xmlDesc, int flags) throws LibvirtException { processError(libvirt.virDomainAttachDeviceFlags(VDP, xmlDesc, flags)); @@ -177,7 +179,7 @@ public void attachDeviceFlags(String xmlDesc, int flags) throws LibvirtException * @param destxml the new disk description * @param params {@link virTypedParameter} * @param flags {@link org.libvirt.flags.DomainBlockCopyFlags} - * @throws LibvirtException + * @throws LibvirtException on error */ public void blockCopy(String disk, String destxml, TypedParameter[] params, int flags) throws LibvirtException { virTypedParameter[] input = new virTypedParameter[params.length]; @@ -193,7 +195,7 @@ public void blockCopy(String disk, String destxml, TypedParameter[] params, int * * @param path the path to the block device * @return the info - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainBlockInfo blockInfo(String path) throws LibvirtException { virDomainBlockInfo info = new virDomainBlockInfo(); @@ -206,7 +208,7 @@ public DomainBlockInfo blockInfo(String path) throws LibvirtException { * * @param path the path to the block device * @return the info - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainBlockJobInfo blockJobInfo(String path, int flags) throws LibvirtException { virDomainBlockJobInfo info = new virDomainBlockJobInfo(); @@ -219,7 +221,7 @@ public DomainBlockJobInfo blockJobInfo(String path, int flags) throws LibvirtExc * * @param disk the path to the block device * @param flags {@link org.libvirt.flags.DomainBlockJobAbortFlags} - * @throws LibvirtException + * @throws LibvirtException on error */ public void blockJobAbort(String disk, int flags) throws LibvirtException { processError(libvirt.virDomainBlockJobAbort(VDP, disk, flags)); @@ -288,7 +290,7 @@ public void blockPeek(String disk, long offset, ByteBuffer buffer) throws Libvir * * @param path path to the block device * @return the statistics in a DomainBlockStats object - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainBlockStats blockStats(String path) throws LibvirtException { virDomainBlockStats stats = new virDomainBlockStats(); @@ -302,7 +304,7 @@ public DomainBlockStats blockStats(String path) throws LibvirtException { * @param disk path to the block image, or shorthand (like vda) * @param size the new size of the block devices * @param flags bitwise OR'ed values of {@link DomainBlockResizeFlags} - * @throws LibvirtException + * @throws LibvirtException on error */ public void blockResize(String disk, long size, int flags) throws LibvirtException { processError(libvirt.virDomainBlockResize(VDP, disk, size, flags)); @@ -314,7 +316,7 @@ public void blockResize(String disk, long size, int flags) throws LibvirtExcepti * * @param to path for the core file * @param flags extra flags, currently unused - * @throws LibvirtException + * @throws LibvirtException on error */ public void coreDump(String to, int flags) throws LibvirtException { processError(libvirt.virDomainCoreDump(VDP, to, flags)); @@ -333,7 +335,7 @@ public int cpuMapLength(int maxCpus) { * the defined to the running domains pools. * * @return ignore (always 0) - * @throws LibvirtException + * @throws LibvirtException on error */ public int create() throws LibvirtException { return processError(libvirt.virDomainCreate(VDP)); @@ -345,7 +347,7 @@ public int create() throws LibvirtException { * the defined to the running domains pools. * * @return ignore (always 0) - * @throws LibvirtException + * @throws LibvirtException on error */ public int create(int flags) throws LibvirtException { return processError(libvirt.virDomainCreateWithFlags(VDP, flags)); @@ -357,7 +359,7 @@ public int create(int flags) throws LibvirtException { * The data structure is freed and should not be used thereafter if the call * does not return an error. This function may requires priviledged access * - * @throws LibvirtException + * @throws LibvirtException on error */ public void destroy() throws LibvirtException { processError(libvirt.virDomainDestroy(VDP)); @@ -367,7 +369,7 @@ public void destroy() throws LibvirtException { * Destroys a virtual device attachment to backend. * * @param xmlDesc XML description of one device - * @throws LibvirtException + * @throws LibvirtException on error */ public void detachDevice(String xmlDesc) throws LibvirtException { processError(libvirt.virDomainDetachDevice(VDP, xmlDesc)); @@ -378,7 +380,7 @@ public void detachDevice(String xmlDesc) throws LibvirtException { * * @param xmlDesc XML description of one device * @param flags the an OR'ed set of virDomainDeviceModifyFlags - * @throws LibvirtException + * @throws LibvirtException on error */ public void detachDeviceFlags(String xmlDesc, int flags) throws LibvirtException { processError(libvirt.virDomainDetachDeviceFlags(VDP, xmlDesc, flags)); @@ -394,7 +396,7 @@ protected void finalize() throws LibvirtException { * structure is freed and should not be used thereafter. * * @return number of references left (>= 0) - * @throws LibvirtException + * @throws LibvirtException on error */ public int free() throws LibvirtException { int success = 0; @@ -411,12 +413,12 @@ public int free() throws LibvirtException { * be automatically started when the host machine boots. * * @return the result - * @throws LibvirtException + * @throws LibvirtException on error */ public boolean getAutostart() throws LibvirtException { IntByReference autoStart = new IntByReference(); processError(libvirt.virDomainGetAutostart(VDP, autoStart)); - return autoStart.getValue() != 0 ? true : false; + return autoStart.getValue() != 0; } /** @@ -432,7 +434,7 @@ public Connect getConnect() { * Gets the hypervisor ID number for the domain * * @return the hypervisor ID - * @throws LibvirtException + * @throws LibvirtException on error */ public int getID() throws LibvirtException { return processError(libvirt.virDomainGetID(VDP)); @@ -444,7 +446,7 @@ public int getID() throws LibvirtException { * extracted. * * @return a DomainInfo object describing this domain - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainInfo getInfo() throws LibvirtException { virDomainInfo vInfo = new virDomainInfo(); @@ -457,7 +459,7 @@ public DomainInfo getInfo() throws LibvirtException { * return an error if the domain is not active. * * @return a DomainJobInfo object describing this domain - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainJobInfo getJobInfo() throws LibvirtException { virDomainJobInfo vInfo = new virDomainJobInfo(); @@ -465,11 +467,42 @@ public DomainJobInfo getJobInfo() throws LibvirtException { return new DomainJobInfo(vInfo); } + public DomainJobInfo getJobStats(int flags) throws LibvirtException { + IntByReference nparams = new IntByReference(); + IntByReference type = new IntByReference(); + PointerByReference virTypedParameterPtr = new PointerByReference(); + + processError(libvirt.virDomainGetJobStats(VDP, type, virTypedParameterPtr, nparams, flags)); + + int n = nparams.getValue(); + TypedParameter[] typedParameters = generateTypedParameters(virTypedParameterPtr, n); + + DomainJobInfo domainJobInfo = new DomainJobInfo(new virDomainJobInfo()); + + if (n > 0) { + domainJobInfo.type = type.getValue(); + try { + domainJobInfo.timeElapsed = this.typedParamsGetValue(typedParameters, "time_elapsed", Long::parseLong); + domainJobInfo.timeRemaining = this.typedParamsGetValue(typedParameters, "time_remaining", Long::parseLong); + domainJobInfo.dataTotal = this.typedParamsGetValue(typedParameters, "data_total", Long::parseLong); + domainJobInfo.dataProcessed = this.typedParamsGetValue(typedParameters, "data_processed", Long::parseLong); + domainJobInfo.dataRemaining = this.typedParamsGetValue(typedParameters, "data_remaining", Long::parseLong); + domainJobInfo.memTotal = this.typedParamsGetValue(typedParameters, "mem_total", Long::parseLong); + domainJobInfo.memProcessed = this.typedParamsGetValue(typedParameters, "mem_processed", Long::parseLong); + domainJobInfo.memRemaining = this.typedParamsGetValue(typedParameters, "mem_remaining", Long::parseLong); + domainJobInfo.fileTotal = this.typedParamsGetValue(typedParameters, "file_total", Long::parseLong); + domainJobInfo.fileProcessed = this.typedParamsGetValue(typedParameters, "file_processed", Long::parseLong); + domainJobInfo.fileRemaining = this.typedParamsGetValue(typedParameters, "file_remaining", Long::parseLong); + } catch (LibvirtException ignored) { } + } + return domainJobInfo; + } + /** * Retrieve the maximum amount of physical memory allocated to a domain. * * @return the memory in kilobytes - * @throws LibvirtException + * @throws LibvirtException on error */ public long getMaxMemory() throws LibvirtException { // the memory size in kibibytes (blocks of 1024 bytes), or 0 in case of error. @@ -484,33 +517,20 @@ public long getMaxMemory() throws LibvirtException { * maximum number of virtual CPUs the guest was booted with. * * @return the number of VCPUs - * @throws LibvirtException + * @throws LibvirtException on error */ public int getMaxVcpus() throws LibvirtException { return processError(libvirt.virDomainGetMaxVcpus(VDP)); } /** - * @type: type of metadata, from virDomainMetadataType - * @uri: XML namespace identifier - * @flags: bitwise-OR of virDomainModificationImpact - * - * Retrieves the appropriate domain element given by @type. - * If VIR_DOMAIN_METADATA_ELEMENT is requested parameter @uri - * must be set to the name of the namespace the requested elements - * belong to, otherwise must be NULL. - * - * If an element of the domain XML is not present, the resulting - * error will be VIR_ERR_NO_DOMAIN_METADATA. This method forms - * a shortcut for seeing information from virDomainSetMetadata() - * without having to go through virDomainGetXMLDesc(). + * Retrieves the appropriate domain element given by type. * - * @flags controls whether the live domain or persistent - * configuration will be queried. - * - * @return the metadata string on success (caller must free), - * or NULL in case of failure. - * @throws LibvirtException + * @param type type of metadata, see {@link DomainMetadataFlags} + * @param uri XML namespace identifier if type == MetadataType.ELEMENT, null otherwise + * @param flags bitwise-OR of {@link DomainDeviceModifyFlags} + * @return the metadata string + * @throws LibvirtException on error */ public String getMetadata(DomainMetadataFlags type, String uri, int flags) throws LibvirtException { return processError(libvirt.virDomainGetMetadata(VDP, type.getValue(), uri, flags)); @@ -522,6 +542,7 @@ public String getMetadata(DomainMetadataFlags type, String uri, int flags) throw * @return the name, null if there is no name * @throws LibvirtException never */ + @SuppressWarnings("RedundantThrows") public String getName() throws LibvirtException { return libvirt.virDomainGetName(VDP); } @@ -530,7 +551,7 @@ public String getName() throws LibvirtException { * Gets the type of domain operation system. * * @return the type - * @throws LibvirtException + * @throws LibvirtException on error */ public String getOSType() throws LibvirtException { return processError(libvirt.virDomainGetOSType(VDP)).toString(); @@ -540,7 +561,7 @@ public String getOSType() throws LibvirtException { * Gets the scheduler parameters. * * @return an array of TypedParameter objects - * @throws LibvirtException + * @throws LibvirtException on error */ public TypedParameter[] getSchedulerParameters() throws LibvirtException { IntByReference nParams = new IntByReference(); @@ -574,7 +595,7 @@ public TypedParameter[] getSchedulerParameters() throws LibvirtException { * Gets the scheduler type. * * @return the type of the scheduler - * @throws LibvirtException + * @throws LibvirtException on error */ public String getSchedulerType() throws LibvirtException { return processError(libvirt.virDomainGetSchedulerType(VDP, null)).toString(); @@ -585,7 +606,7 @@ public String getSchedulerType() throws LibvirtException { * * @return the SecurityLabel or {@code null} if the domain is not * running under a security model - * @throws LibvirtException + * @throws LibvirtException on error */ public SecurityLabel getSecurityLabel() throws LibvirtException { virSecurityLabel seclabel = new virSecurityLabel(); @@ -603,7 +624,7 @@ public SecurityLabel getSecurityLabel() throws LibvirtException { * Get the UUID for this domain. * * @return the UUID as an unpacked int array - * @throws LibvirtException + * @throws LibvirtException on error * @see rfc4122 */ public int[] getUUID() throws LibvirtException { @@ -616,7 +637,7 @@ public int[] getUUID() throws LibvirtException { * Gets the UUID for this domain as string. * * @return the UUID in canonical String format - * @throws LibvirtException + * @throws LibvirtException on error * @see rfc4122 */ public String getUUIDString() throws LibvirtException { @@ -630,7 +651,7 @@ public String getUUIDString() throws LibvirtException { * the array contain information. * * @return a bitmap of real CPUs for all vcpus of this domain - * @throws LibvirtException + * @throws LibvirtException on error */ public int[] getVcpusCpuMaps() throws LibvirtException { int[] returnValue = new int[0]; @@ -654,7 +675,7 @@ public int[] getVcpusCpuMaps() throws LibvirtException { * Extracts information about virtual CPUs of this domain * * @return an array of VcpuInfo object describing the VCPUs - * @throws LibvirtException + * @throws LibvirtException on error */ public VcpuInfo[] getVcpusInfo() throws LibvirtException { int cpuCount = getMaxVcpus(); @@ -673,7 +694,7 @@ public VcpuInfo[] getVcpusInfo() throws LibvirtException { * * @param flags not used * @return the XML description String - * @throws LibvirtException + * @throws LibvirtException on error */ public String getXMLDesc(int flags) throws LibvirtException { return processError(libvirt.virDomainGetXMLDesc(VDP, flags)).toString(); @@ -683,7 +704,7 @@ public String getXMLDesc(int flags) throws LibvirtException { * Determine if the domain has a snapshot * * @return 1 if running, 0 if inactive - * @throws LibvirtException + * @throws LibvirtException on error */ public int hasCurrentSnapshot() throws LibvirtException { return processError(libvirt.virDomainHasCurrentSnapshot(VDP, 0)); @@ -694,7 +715,7 @@ public int hasCurrentSnapshot() throws LibvirtException { * * @return 0 if no image is present, 1 if an image is present, and -1 in * case of error - * @throws LibvirtException + * @throws LibvirtException on error */ public int hasManagedSaveImage() throws LibvirtException { return processError(libvirt.virDomainHasManagedSaveImage(VDP, 0)); @@ -710,7 +731,7 @@ public int hasManagedSaveImage() throws LibvirtException { * * @param path path to the interface * @return the statistics in a DomainInterfaceStats object - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainInterfaceStats interfaceStats(String path) throws LibvirtException { virDomainInterfaceStats stats = new virDomainInterfaceStats(); @@ -722,7 +743,7 @@ public DomainInterfaceStats interfaceStats(String path) throws LibvirtException * Determine if the domain is currently running * * @return 1 if running, 0 if inactive - * @throws LibvirtException + * @throws LibvirtException on error */ public int isActive() throws LibvirtException { return processError(libvirt.virDomainIsActive(VDP)); @@ -733,7 +754,7 @@ public int isActive() throws LibvirtException { * will still exist after shutting down * * @return 1 if persistent, 0 if transient - * @throws LibvirtException + * @throws LibvirtException on error */ public int isPersistent() throws LibvirtException { return processError(libvirt.virDomainIsPersistent(VDP)); @@ -750,7 +771,7 @@ public boolean isUpdated() throws LibvirtException { * suspend a domain and save its memory contents to a file on disk. * * @return always 0 - * @throws LibvirtException + * @throws LibvirtException on error */ public int managedSave() throws LibvirtException { return processError(libvirt.virDomainManagedSave(VDP, 0)); @@ -760,7 +781,7 @@ public int managedSave() throws LibvirtException { * Remove any managed save images from the domain * * @return always 0 - * @throws LibvirtException + * @throws LibvirtException on error */ public int managedSaveRemove() throws LibvirtException { return processError(libvirt.virDomainManagedSaveRemove(VDP, 0)); @@ -810,11 +831,11 @@ public void memoryPeek(long start, ByteBuffer buffer, MemoryAddressMode mode) th * * @param number the number of stats to retrieve * @return the collection of stats - * @throws LibvirtException + * @throws LibvirtException on error */ public MemoryStatistic[] memoryStats(int number) throws LibvirtException { virDomainMemoryStats[] stats = new virDomainMemoryStats[number]; - MemoryStatistic[] returnStats = null; + MemoryStatistic[] returnStats; int result = processError(libvirt.virDomainMemoryStats(VDP, stats, number, 0)); returnStats = new MemoryStatistic[result]; for (int x = 0; x < result; x++) { @@ -928,20 +949,56 @@ public Domain migrate(Connect dconn, long flags, String dxml, String dname, Stri * @return the new domain object if the migration was successful. Note that * the new domain object exists in the scope of the destination * connection (dconn). - * @throws LibvirtException + * @throws LibvirtException on error */ public Domain migrate(Connect dconn, long flags, String dname, String uri, long bandwidth) throws LibvirtException { DomainPointer newPtr = processError(libvirt.virDomainMigrate(VDP, dconn.VCP, new NativeLong(flags), dname, uri, new NativeLong(bandwidth))); return new Domain(dconn, newPtr); } + /** + * Migrate the domain object from its current host to the destination host + * given by dconn (a connection to the destination host). + * See VIR_MIGRATE_PARAM_* and virDomainMigrateFlags for detailed + * description of accepted migration parameters and flags. + * See virDomainMigrateFlags documentation for description of individual + * flags. VIR_MIGRATE_TUNNELLED and VIR_MIGRATE_PEER2PEER are not supported + * by this API, use virDomainMigrateToURI3 instead. + *
+ * There are many limitations on migration imposed by the underlying + * technology - for example it may not be possible to migrate between + * different processors even with the same architecture, or between different + * types of hypervisor. virDomainFree should be used to free the resources + * after the returned domain object is no longer needed. + *

+ * For more informations, please @see virDomainMigrate3 + * @param dconn + * destination host (a Connect object) + * @param params + * (optional) migration parameters + * + * @param flags + * bitwise-OR of virDomainMigrateFlags + * @return + * the new domain object if the migration was successful. Note that + * the new domain object exists in the scope of the destination + * connection (dconn). + * @throws LibvirtException on error + */ + public Domain migrate(Connect dconn, TypedParameter[] params, long flags) throws LibvirtException { + assert params != null : "migrate Typed parameters cannot be null"; + virTypedParameter[] virTypedParameters = generateNativeVirTypedParameters(params); + DomainPointer newPtr = processError(libvirt.virDomainMigrate3(VDP, dconn.VCP, virTypedParameters, params.length, new NativeLong(flags))); + return new Domain(dconn, newPtr); + } + /** * Sets maximum tolerable time for which the domain is allowed to be paused * at the end of live migration. * * @param downtime the time to be down * @return always 0 - * @throws LibvirtException + * @throws LibvirtException on error */ public int migrateSetMaxDowntime(long downtime) throws LibvirtException { return processError(libvirt.virDomainMigrateSetMaxDowntime(VDP, downtime, 0)); @@ -965,7 +1022,7 @@ public int migrateSetMaxDowntime(long downtime) throws LibvirtException { * @param dname The name at the destnation * @param bandwidth Specify the migration bandwidth * @return 0 if successful - * @throws LibvirtException + * @throws LibvirtException on error */ public int migrateToURI(String dconnuri, String miguri, String dxml, long flags, String dname, long bandwidth) throws LibvirtException { return processError(libvirt.virDomainMigrateToURI2(VDP, dconnuri, miguri, @@ -982,12 +1039,28 @@ dxml, new NativeLong(flags), * @param dname The name at the destnation * @param bandwidth Specify the migration bandwidth * @return 0 if successful, -1 if not - * @throws LibvirtException + * @throws LibvirtException on error */ public int migrateToURI(String uri, long flags, String dname, long bandwidth) throws LibvirtException { return processError(libvirt.virDomainMigrateToURI(VDP, uri, new NativeLong(flags), dname, new NativeLong(bandwidth))); } + /** + * Migrate the domain object from its current host to the destination host + * given by duri. + * + * @param uri The destination URI + * @param params See VIR_MIGRATE_PARAM_* and virDomainMigrateFlags for detailed description of accepted migration parameters and flags. + * @param flags Controls the migrate + * @return 0 if successful, -1 if not + * @throws LibvirtException on error + */ + public int migrateToURI(String uri, TypedParameter[] params, long flags) throws LibvirtException { + assert params != null : "migrate Typed parameters cannot be null"; + virTypedParameter[] virTypedParameters = generateNativeVirTypedParameters(params); + return processError(libvirt.virDomainMigrateToURI3(VDP, uri, virTypedParameters, params.length, new NativeLong(flags))); + } + /** * Enter the given power management suspension target level. */ @@ -1024,7 +1097,7 @@ public void PMwakeup() throws LibvirtException { * corresponding CPU is usable. Bytes are stored in little-endian * order: CPU0-7, 8-15... In each byte, lowest CPU number is * least significant bit. - * @throws LibvirtException + * @throws LibvirtException on error */ public void pinVcpu(int vcpu, int[] cpumap) throws LibvirtException { byte[] packedMap = new byte[cpumap.length]; @@ -1040,7 +1113,7 @@ public void pinVcpu(int vcpu, int[] cpumap) throws LibvirtException { * ignore the request. * * @param flags extra flags for the reboot operation, not used yet - * @throws LibvirtException + * @throws LibvirtException on error */ public void reboot(int flags) throws LibvirtException { processError(libvirt.virDomainReboot(VDP, flags)); @@ -1051,7 +1124,7 @@ public void reboot(int flags) throws LibvirtException { * where it was frozen by calling virSuspendDomain(). This function may * requires privileged access * - * @throws LibvirtException + * @throws LibvirtException on error */ public void resume() throws LibvirtException { processError(libvirt.virDomainResume(VDP)); @@ -1142,7 +1215,7 @@ public void reset() throws LibvirtException { * * @param snapshot the snapshot to revert to * @return 0 if the creation is successful - * @throws LibvirtException + * @throws LibvirtException on error */ public int revertToSnapshot(DomainSnapshot snapshot) throws LibvirtException { return processError(libvirt.virDomainRevertToSnapshot(snapshot.VDSP, 0)); @@ -1154,7 +1227,7 @@ public int revertToSnapshot(DomainSnapshot snapshot) throws LibvirtException { * @param snapshot the snapshot to revert to * @param flags bitwise-OR of {@link org.libvirt.flags.DomainSnapshotRevertFlags} * @return 0 if the creation is successful - * @throws LibvirtException + * @throws LibvirtException on error */ public int revertToSnapshot(DomainSnapshot snapshot, int flags) throws LibvirtException { return processError(libvirt.virDomainRevertToSnapshot(snapshot.VDSP, flags)); @@ -1167,7 +1240,7 @@ public int revertToSnapshot(DomainSnapshot snapshot, int flags) throws LibvirtEx * restore a domain after saving. * * @param to path for the output file - * @throws LibvirtException + * @throws LibvirtException on error */ public void save(String to) throws LibvirtException { processError(libvirt.virDomainSave(VDP, to)); @@ -1184,8 +1257,8 @@ public String screenshot(Stream stream, int screen) throws LibvirtException { * Configures the network to be automatically started when the host machine * boots. * - * @param autostart - * @throws LibvirtException + * @param autostart whether the domain should be automatically started true or false + * @throws LibvirtException on error */ public void setAutostart(boolean autostart) throws LibvirtException { int autoValue = autostart ? 1 : 0; @@ -1197,7 +1270,7 @@ public void setAutostart(boolean autostart) throws LibvirtException { * domain. This function requires priviledged access to the hypervisor. * * @param memory the amount memory in kilobytes - * @throws LibvirtException + * @throws LibvirtException on error */ public void setMaxMemory(long memory) throws LibvirtException { processError(libvirt.virDomainSetMaxMemory(VDP, new NativeLong(memory))); @@ -1209,41 +1282,34 @@ public void setMaxMemory(long memory) throws LibvirtException { * hypervisor. * * @param memory in kilobytes - * @throws LibvirtException + * @throws LibvirtException on error */ public void setMemory(long memory) throws LibvirtException { processError(libvirt.virDomainSetMemory(VDP, new NativeLong(memory))); } /** - * @type: type of metadata, from {@link DomainMetadataFlags} - * @metadata: new metadata text - * @key: XML namespace key, or NULL - * @uri: XML namespace URI, or NULL - * @flags: bitwise-OR of {@link DomainDeviceModifyFlags} - * - * Sets the appropriate domain element given by @type to the - * value of @metadata. A @type of VIR_DOMAIN_METADATA_DESCRIPTION - * is free-form text; VIR_DOMAIN_METADATA_TITLE is free-form, but no - * newlines are permitted, and should be short (although the length is - * not enforced). For these two options @key and @uri are irrelevant and - * must be set to NULL. - * - * For type VIR_DOMAIN_METADATA_ELEMENT @metadata must be well-formed - * XML belonging to namespace defined by @uri with local name @key. + * Sets the appropriate domain element given by type to the value of metadata. * - * Passing NULL for @metadata says to remove that element from the - * domain XML (passing the empty string leaves the element present). + * A type of MetadataType.DESCRIPTION is free-form text; MetadataType.TITLE is + * free-form, but no newlines are permitted, and should be short (although the length + * is not enforced). For these two options key and uri are irrelevant and must be set + * to null. * - * The resulting metadata will be present in virDomainGetXMLDesc(), - * as well as quick access through virDomainGetMetadata(). + * For type MetadataType.ELEMENT metadata must be well-formed XML belonging to + * namespace defined by uri with local name key. * - * @flags controls whether the live domain, persistent configuration, - * or both will be modified. + * Passing null for metadata says to remove that element from the domain XML (passing + * the empty string leaves the element present). * - * @return 0 on success, -1 in case of failure. - * @throws LibvirtException + * @param type see {@link DomainMetadataFlags} + * @param metadata the new metadata content + * @param key XML namespace prefix for type MetadataType.ELEMENT, null otherwise + * @param uri XML namespace URI for typeMetadataType.ELEMENT, null otherwise + * @param flags see {@link DomainDeviceModifyFlags} + * @throws LibvirtException on error */ + public int setMetadata(DomainMetadataFlags type, String metadata, String key, String uri, int flags) throws LibvirtException { return processError(libvirt.virDomainSetMetadata(VDP, type.getValue(), metadata, key, uri, flags)); } @@ -1252,7 +1318,7 @@ public int setMetadata(DomainMetadataFlags type, String metadata, String key, St * Changes the scheduler parameters * * @param params an array of TypedParameter objects to be changed - * @throws LibvirtException + * @throws LibvirtException on error */ public void setSchedulerParameters(TypedParameter[] params) throws LibvirtException { virTypedParameter[] input = new virTypedParameter[params.length]; @@ -1269,7 +1335,7 @@ public void setSchedulerParameters(TypedParameter[] params) throws LibvirtExcept * function requires priviledged access to the hypervisor. * * @param nvcpus the new number of virtual CPUs for this domain - * @throws LibvirtException + * @throws LibvirtException on error */ public void setVcpus(int nvcpus) throws LibvirtException { processError(libvirt.virDomainSetVcpus(VDP, nvcpus)); @@ -1293,7 +1359,7 @@ public void sendKey(KeycodeSet codeset, int holdtime, int... keys) throws Libvir * request. TODO: should we add an option for reboot, knowing it may not be * doable in the general case ? * - * @throws LibvirtException + * @throws LibvirtException on error */ public void shutdown() throws LibvirtException { processError(libvirt.virDomainShutdown(VDP)); @@ -1306,7 +1372,7 @@ public void shutdown() throws LibvirtException { * @param xmlDesc string containing an XML description of the domain * @param flags flags for creating the snapshot, see the virDomainSnapshotCreateFlags for the flag options * @return the snapshot - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainSnapshot snapshotCreateXML(String xmlDesc, int flags) throws LibvirtException { DomainSnapshotPointer ptr = processError(libvirt.virDomainSnapshotCreateXML(VDP, xmlDesc, flags)); @@ -1322,7 +1388,7 @@ public DomainSnapshot snapshotCreateXML(String xmlDesc, int flags) throws Libvir * * @param xmlDesc string containing an XML description of the domain * @return the snapshot, or null on Error - * @throws LibvirtException + * @throws LibvirtException on error * @see #snapshotCreateXML(String, int) */ public DomainSnapshot snapshotCreateXML(String xmlDesc) throws LibvirtException { @@ -1333,7 +1399,7 @@ public DomainSnapshot snapshotCreateXML(String xmlDesc) throws LibvirtException * Get the current snapshot for a domain, if any. * * @return the snapshot - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainSnapshot snapshotCurrent() throws LibvirtException { DomainSnapshotPointer ptr = processError(libvirt.virDomainSnapshotCurrent(VDP, 0)); @@ -1344,7 +1410,7 @@ public DomainSnapshot snapshotCurrent() throws LibvirtException { * Collect the list of domain snapshots for the given domain. With the option to pass flags * * @return The list of names, or null if an error - * @throws LibvirtException + * @throws LibvirtException on error */ public String[] snapshotListNames(int flags) throws LibvirtException { int num = snapshotNum(); @@ -1365,7 +1431,7 @@ public String[] snapshotListNames(int flags) throws LibvirtException { * as calling {@code snapshotListNames(0);}. * * @return The list of names, or null if an error - * @throws LibvirtException + * @throws LibvirtException on error * @see #snapshotListNames(int) */ public String[] snapshotListNames() throws LibvirtException { @@ -1377,7 +1443,7 @@ public String[] snapshotListNames() throws LibvirtException { * * @param name the name * @return The located snapshot - * @throws LibvirtException + * @throws LibvirtException on error */ public DomainSnapshot snapshotLookupByName(String name) throws LibvirtException { DomainSnapshotPointer ptr = processError(libvirt.virDomainSnapshotLookupByName(VDP, name, 0)); @@ -1397,7 +1463,7 @@ public int snapshotNum() throws LibvirtException { * hypervisor level will stay allocated. Use Domain.resume() to reactivate * the domain. This function requires priviledged access. * - * @throws LibvirtException + * @throws LibvirtException on error */ public void suspend() throws LibvirtException { processError(libvirt.virDomainSuspend(VDP)); @@ -1406,7 +1472,7 @@ public void suspend() throws LibvirtException { /** * undefines this domain but does not stop it if it is running * - * @throws LibvirtException + * @throws LibvirtException on error */ public void undefine() throws LibvirtException { processError(libvirt.virDomainUndefine(VDP)); @@ -1416,7 +1482,7 @@ public void undefine() throws LibvirtException { * Undefines this domain but does not stop if it it is running. With option for passing flags * * @param flags flags for undefining the domain. See virDomainUndefineFlagsValues for more information - * @throws LibvirtException + * @throws LibvirtException on error */ public void undefine(int flags) throws LibvirtException { processError(libvirt.virDomainUndefineFlags(VDP, flags)); @@ -1428,7 +1494,7 @@ public void undefine(int flags) throws LibvirtException { * @param xml the xml to update with * @param flags controls the update * @return always 0 - * @throws LibvirtException + * @throws LibvirtException on error */ public int updateDeviceFlags(String xml, int flags) throws LibvirtException { return processError(libvirt.virDomainUpdateDeviceFlags(VDP, xml, flags)); @@ -1437,4 +1503,86 @@ public int updateDeviceFlags(String xml, int flags) throws LibvirtException { public int startPostCopy(int flags) throws LibvirtException { return processError(libvirt.virDomainMigrateStartPostCopy(VDP, flags)); } + + /** + * This methods creates an array of virTypedParameter objects based on the + * given array of TypedParameter objects. The way it has been designed ensures + * that the output will be in contiguous memory, regardless of the memory + * allocated for each of the provided "TypedParameter[]", avoiding + * "non contiguous memory due to bad backing address at Structure array". + * + * @param params + * Array of TypedParameter objects which can be: + * TypedBooleanParameter, TypedBooleanParameter, TypedDoubleParameter, + * TypedIntParameter, TypedLongParameter, TypedStringParameter, + * TypedUintParameter, or TypedUlongParameter + * @return + * An array of "virTypedParameter" objects in contiguous memory. + */ + private virTypedParameter[] generateNativeVirTypedParameters(TypedParameter[] params) { + virTypedParameter param = new virTypedParameter(); + virTypedParameter[] virTypedParameters = (virTypedParameter[]) param.toArray(params.length); + for (int x = 0; x < params.length; x++) { + virTypedParameter temporaryTypedParameter = TypedParameter.toNative(params[x]); + virTypedParameters[x].field = temporaryTypedParameter.field; + virTypedParameters[x].type = temporaryTypedParameter.type; + virTypedParameters[x].value = temporaryTypedParameter.value; + } + return virTypedParameters; + } + + /** + * This method creates an array of TypedParameter objects based on the + * given pointer to virTypedParameter objects. + * + * @since 1.0.7 + * @param ptr + * Reference pointer to virTypedParameter objects which can be: + * TypedBooleanParameter, TypedBooleanParameter, TypedDoubleParameter, + * TypedIntParameter, TypedLongParameter, TypedStringParameter, + * TypedUintParameter, or TypedUlongParameter + * @param nparams + * Number of parameters + * @return + * An array of "TypedParameter" objects in contiguous memory. + */ + private TypedParameter[] generateTypedParameters(PointerByReference ptr, int nparams) { + TypedParameter[] typedParameter = new TypedParameter[nparams]; + Pointer ptrValue = ptr.getValue(); + virTypedParameter virTypedParameter = new virTypedParameter(ptrValue); + virTypedParameter.read(); + final virTypedParameter[] vTypedParameter = (virTypedParameter[]) virTypedParameter.toArray(nparams); + for (int x = 0; x < nparams; x++) { + if (vTypedParameter[x].type == 8) break; + typedParameter[x] = TypedParameter.create(vTypedParameter[x]); + } + return typedParameter; + } + + /** + * This method will get the value from a typed parameter + * + * @since 1.0.7 + * @param typedParameters + * Array of TypedParameter objects which can be: + * TypedLongParameter or TypedUlongParameter + * @param field + * Field name to get value from + * @param valueMapper + * Function mapper which can be: + * Long::parseLong, Integer::parseInt, + * Double::parseDouble, Boolean::parseBoolean, + * String::toString + * @return + * A long value from field if found + * @throws LibvirtException on error + * if field is not found + */ + private T typedParamsGetValue(TypedParameter[] typedParameters, String field, Function valueMapper) throws LibvirtException { + Optional typedParameterOptional = Arrays.stream(typedParameters) + .filter(name -> name.getField().equals(field)) + .findFirst(); + return typedParameterOptional.map(typedParameter -> valueMapper.apply(typedParameter.getValueAsString())) + .orElseThrow(LibvirtException::new); + } } diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index f748130..d5b5bac 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -9,6 +9,7 @@ import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; +import com.sun.jna.ptr.PointerByReference; import org.libvirt.jna.callbacks.VirConnectCloseFunc; import org.libvirt.jna.callbacks.VirDomainEventCallback; import org.libvirt.jna.callbacks.VirErrorCallback; @@ -53,7 +54,7 @@ */ public interface Libvirt extends Library { - Libvirt INSTANCE = Native.loadLibrary(Platform.isWindows() ? "virt-0" : "virt", Libvirt.class); + Libvirt INSTANCE = Native.load(Platform.isWindows() ? "virt-0" : "virt", Libvirt.class); // Constants we need int VIR_UUID_BUFLEN = 16; @@ -132,6 +133,8 @@ public interface Libvirt extends Library { DomainPointer virDomainMigrate2(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr, String dxml, NativeLong flags, String dname, String uri, NativeLong bandwidth); + DomainPointer virDomainMigrate3(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr, virTypedParameter[] params, int nparams, NativeLong flags); + DomainSnapshotPointer virDomainSnapshotCreateXML(DomainPointer virDomainPtr, String xmlDesc, int flags); DomainSnapshotPointer virDomainSnapshotCurrent(DomainPointer virDomainPtr, int flags); @@ -248,6 +251,8 @@ public interface Libvirt extends Library { int virDomainGetJobInfo(DomainPointer virDomainPtr, virDomainJobInfo vInfo); + int virDomainGetJobStats(DomainPointer virDomainPtr, IntByReference type, PointerByReference params, IntByReference nparams, int flags); + int virDomainGetMaxVcpus(DomainPointer virDomainPtr); int virDomainGetSchedulerParameters(DomainPointer virDomainPtr, virTypedParameter[] params, IntByReference nparams); @@ -286,6 +291,8 @@ public interface Libvirt extends Library { int virDomainMigrateToURI2(DomainPointer virDomainPtr, String dconnuri, String miguri, String dxml, NativeLong flags, String dname, NativeLong bandwidth); + int virDomainMigrateToURI3(DomainPointer virDomainPtr, String dconnuri, virTypedParameter[] params, int nparams, NativeLong flags); + int virDomainPinVcpu(DomainPointer virDomainPtr, int vcpu, byte[] cpumap, int maplen); int virDomainPMSuspendForDuration(DomainPointer virDomainPtr, int target, long duration, int flags); diff --git a/src/main/java/org/libvirt/jna/structures/virTypedParameter.java b/src/main/java/org/libvirt/jna/structures/virTypedParameter.java index 94bece2..fab99e6 100644 --- a/src/main/java/org/libvirt/jna/structures/virTypedParameter.java +++ b/src/main/java/org/libvirt/jna/structures/virTypedParameter.java @@ -3,6 +3,7 @@ import java.util.Arrays; import java.util.List; +import com.sun.jna.Pointer; import com.sun.jna.Structure; import org.libvirt.jna.Libvirt; @@ -16,6 +17,14 @@ public class virTypedParameter extends Structure { private static final List fields = Arrays.asList("field", "type", "value"); + public virTypedParameter() { + super(); + } + + public virTypedParameter(Pointer p) { + super(p); + } + @Override protected List getFieldOrder() { return fields; diff --git a/src/main/java/org/libvirt/jna/structures/virTypedParameterValue.java b/src/main/java/org/libvirt/jna/structures/virTypedParameterValue.java index d7da0da..5681942 100644 --- a/src/main/java/org/libvirt/jna/structures/virTypedParameterValue.java +++ b/src/main/java/org/libvirt/jna/structures/virTypedParameterValue.java @@ -1,5 +1,6 @@ package org.libvirt.jna.structures; +import com.sun.jna.Pointer; import com.sun.jna.Union; /** @@ -11,4 +12,5 @@ public class virTypedParameterValue extends Union { public double d; /* data for double case */ public byte b; /* data for char case */ public String s; /* data for string case */ + public Pointer p; } diff --git a/src/main/java/org/libvirt/parameters/DomainMigrateParameters.java b/src/main/java/org/libvirt/parameters/DomainMigrateParameters.java new file mode 100644 index 0000000..5852b70 --- /dev/null +++ b/src/main/java/org/libvirt/parameters/DomainMigrateParameters.java @@ -0,0 +1,270 @@ +package org.libvirt.parameters; + +public class DomainMigrateParameters { + /** + * VIR_MIGRATE_PARAM_URI: + * + * virDomainMigrate* params field: URI to use for initiating domain migration + * as VIR_TYPED_PARAM_STRING. It takes a hypervisor specific format. The + * uri_transports element of the hypervisor capabilities XML includes details + * of the supported URI schemes. When omitted libvirt will auto-generate + * suitable default URI. It is typically only necessary to specify this URI if + * the destination host has multiple interfaces and a specific interface is + * required to transmit migration data. + * + * This field may not be used when VIR_MIGRATE_TUNNELLED flag is set. + * + * Since: 1.1.0 + */ + public static final String VIR_MIGRATE_PARAM_URI = "migrate_uri"; + + /** + * VIR_MIGRATE_PARAM_DEST_NAME: + * + * virDomainMigrate* params field: the name to be used for the domain on the + * destination host as VIR_TYPED_PARAM_STRING. Omitting this parameter keeps + * the domain name the same. This field is only allowed to be used with + * hypervisors that support domain renaming during migration. + * + * Since: 1.1.0 + */ + public static final String VIR_MIGRATE_PARAM_DEST_NAME = "destination_name"; + + /** + * VIR_MIGRATE_PARAM_DEST_XML: + * + * virDomainMigrate* params field: the new configuration to be used for the + * domain on the destination host as VIR_TYPED_PARAM_STRING. The configuration + * must include an identical set of virtual devices, to ensure a stable guest + * ABI across migration. Only parameters related to host side configuration + * can be changed in the XML. Hypervisors which support this field will forbid + * migration if the provided XML would cause a change in the guest ABI. This + * field cannot be used to rename the domain during migration (use + * VIR_MIGRATE_PARAM_DEST_NAME field for that purpose). Domain name in the + * destination XML must match the original domain name. + * + * Omitting this parameter keeps the original domain configuration. Using this + * field with hypervisors that do not support changing domain configuration + * during migration will result in a failure. + * + * Since: 1.1.0 + */ + public static final String VIR_MIGRATE_PARAM_DEST_XML = "destination_xml"; + + /** + * VIR_MIGRATE_PARAM_PERSIST_XML: + * + * virDomainMigrate* params field: the new persistent configuration to be used + * for the domain on the destination host as VIR_TYPED_PARAM_STRING. + * This field cannot be used to rename the domain during migration (use + * VIR_MIGRATE_PARAM_DEST_NAME field for that purpose). Domain name in the + * destination XML must match the original domain name. + * + * Omitting this parameter keeps the original domain persistent configuration. + * Using this field with hypervisors that do not support changing domain + * configuration during migration will result in a failure. + * + * Since: 1.3.4 + */ + public static final String VIR_MIGRATE_PARAM_PERSIST_XML = "persistent_xml"; + + /** + * VIR_MIGRATE_PARAM_BANDWIDTH: + * + * virDomainMigrate* params field: the maximum bandwidth (in MiB/s) that will + * be used for migration as VIR_TYPED_PARAM_ULLONG. If set to 0 or omitted, + * libvirt will choose a suitable default. Some hypervisors do not support this + * feature and will return an error if this field is used and is not 0. + * + * Since: 1.1.0 + */ + public static final String VIR_MIGRATE_PARAM_BANDWIDTH = "bandwidth"; + + /** + * VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY: + * + * virDomainMigrate* params field: the maximum bandwidth (in MiB/s) that will + * be used for post-copy phase of a migration as VIR_TYPED_PARAM_ULLONG. If set + * to 0 or omitted, post-copy migration speed will not be limited. + * + * Since: 5.1.0 + */ + public static final String VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY = "bandwidth.postcopy"; + + /** + * VIR_MIGRATE_PARAM_GRAPHICS_URI: + * + * virDomainMigrate* params field: URI to use for migrating client's connection + * to domain's graphical console as VIR_TYPED_PARAM_STRING. If specified, the + * client will be asked to automatically reconnect using these parameters + * instead of the automatically computed ones. This can be useful if, e.g., the + * client does not have a direct access to the network virtualization hosts are + * connected to and needs to connect through a proxy. The URI is formed as + * follows: + * + * protocol://hostname[:port]/[?parameters] + * + * where protocol is either "spice" or "vnc" and parameters is a list of + * protocol specific parameters separated by '&'. Currently recognized + * parameters are "tlsPort" and "tlsSubject". For example, + * + * spice://target.host.com:1234/?tlsPort=4567 + * + * Since: 1.1.0 + */ + public static final String VIR_MIGRATE_PARAM_GRAPHICS_URI = "graphics_uri"; + + /** + * VIR_MIGRATE_PARAM_LISTEN_ADDRESS: + * + * virDomainMigrate* params field: The listen address that hypervisor on the + * destination side should bind to for incoming migration. Both IPv4 and IPv6 + * addresses are accepted as well as hostnames (the resolving is done on + * destination). Some hypervisors do not support this feature and will return + * an error if this field is used. + * + * Since: 1.1.4 + */ + public static final String VIR_MIGRATE_PARAM_LISTEN_ADDRESS = "listen_address"; + + /** + * VIR_MIGRATE_PARAM_MIGRATE_DISKS: + * + * virDomainMigrate* params multiple field: The multiple values that list + * the block devices to be migrated. At the moment this is only supported + * by the QEMU driver but not for the tunnelled migration. + * + * Since: 1.2.17 + */ + public static final String VIR_MIGRATE_PARAM_MIGRATE_DISKS = "migrate_disks"; + + /** + * VIR_MIGRATE_PARAM_DISKS_PORT: + * + * virDomainMigrate* params field: port that destination server should use + * for incoming disks migration. Type is VIR_TYPED_PARAM_INT. If set to 0 or + * omitted, libvirt will choose a suitable default. At the moment this is only + * supported by the QEMU driver. + * + * Since: 1.3.3 + */ + public static final String VIR_MIGRATE_PARAM_DISKS_PORT = "disks_port"; + + /** + * VIR_MIGRATE_PARAM_DISKS_URI: + * + * virDomainMigrate* params field: URI used for incoming disks migration. Type + * is VIR_TYPED_PARAM_STRING. Only schemes "tcp" and "unix" are accepted. TCP + * URI can currently only provide a server and port to listen on (and connect + * to), UNIX URI may only provide a path component for a UNIX socket. This is + * currently only supported by the QEMU driver. UNIX URI is only usable if the + * management application makes sure that socket created with this name on the + * destination will be reachable from the source under the same exact path. + * + * Since: 6.8.0 + */ + public static final String VIR_MIGRATE_PARAM_DISKS_URI = "disks_uri"; + + /** + * VIR_MIGRATE_PARAM_COMPRESSION: + * + * virDomainMigrate* params multiple field: name of the method used to + * compress migration traffic. Supported compression methods: xbzrle, mt. + * The parameter may be specified multiple times if more than one method + * should be used. + * + * Since: 1.3.4 + */ + public static final String VIR_MIGRATE_PARAM_COMPRESSION = "compression"; + + /** + * VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL: + * + * virDomainMigrate* params field: the level of compression for multithread + * compression as VIR_TYPED_PARAM_INT. Accepted values are in range 0-9. + * 0 is no compression, 1 is maximum speed and 9 is maximum compression. + * + * Since: 1.3.4 + */ + public static final String VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL = "compression.mt.level"; + + /** + * VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS: + * + * virDomainMigrate* params field: the number of compression threads for + * multithread compression as VIR_TYPED_PARAM_INT. + * + * Since: 1.3.4 + */ + public static final String VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS = "compression.mt.threads"; + + /** + * VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS: + * + * virDomainMigrate* params field: the number of decompression threads for + * multithread compression as VIR_TYPED_PARAM_INT. + * + * Since: 1.3.4 + */ + public static final String VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS = "compression.mt.dthreads"; + + /** + * VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE: + * + * virDomainMigrate* params field: the size of page cache for xbzrle + * compression as VIR_TYPED_PARAM_ULLONG. + * + * Since: 1.3.4 + */ + public static final String VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE = "compression.xbzrle.cache"; + + /** + * VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL: + * + * virDomainMigrate* params field: the initial percentage guest CPUs are + * throttled to when auto-convergence decides migration is not converging. + * As VIR_TYPED_PARAM_INT. + * + * Since: 2.0.0 + */ + public static final String VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL = "auto_converge.initial"; + + /** + * VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT: + * + * virDomainMigrate* params field: the increment added to + * VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL whenever the hypervisor decides + * the current rate is not enough to ensure convergence of the migration. + * As VIR_TYPED_PARAM_INT. + * + * Since: 2.0.0 + */ + public static final String VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT = "auto_converge.increment"; + + /** + * VIR_MIGRATE_PARAM_PARALLEL_CONNECTIONS: + * + * virDomainMigrate* params field: number of connections used during parallel + * migration. As VIR_TYPED_PARAM_INT. + * + * Since: 5.2.0 + */ + public static final String VIR_MIGRATE_PARAM_PARALLEL_CONNECTIONS = "parallel.connections"; + + /** + * VIR_MIGRATE_PARAM_TLS_DESTINATION: + * + * virDomainMigrate* params field: override the destination host name used for + * TLS verification. As VIR_TYPED_PARAM_STRING. + * + * Normally the TLS certificate from the destination host must match the host's + * name for TLS verification to succeed. When the certificate does not match + * the destination hostname and the expected certificate's hostname is known, + * this parameter can be used to pass this expected hostname when starting + * the migration. + * + * Since: 6.0.0 + */ + public static final String VIR_MIGRATE_PARAM_TLS_DESTINATION = "tls.destination"; + +} diff --git a/src/main/java/org/libvirt/parameters/typed/TypedBooleanParameter.java b/src/main/java/org/libvirt/parameters/typed/TypedBooleanParameter.java index baaa6cd..21152cf 100644 --- a/src/main/java/org/libvirt/parameters/typed/TypedBooleanParameter.java +++ b/src/main/java/org/libvirt/parameters/typed/TypedBooleanParameter.java @@ -4,11 +4,19 @@ * Class for representing a boolean typed parameter */ public final class TypedBooleanParameter extends TypedParameter { - private boolean value; + public boolean value; public TypedBooleanParameter() { } + public TypedBooleanParameter(boolean value) { + this.value = value; + } + + public TypedBooleanParameter(byte value) { + this.value = ((value) != 0); + } + public TypedBooleanParameter(boolean value, String field) { this.setField(field); this.setValue(value); diff --git a/src/main/java/org/libvirt/parameters/typed/TypedDoubleParameter.java b/src/main/java/org/libvirt/parameters/typed/TypedDoubleParameter.java index 34061df..2d46333 100644 --- a/src/main/java/org/libvirt/parameters/typed/TypedDoubleParameter.java +++ b/src/main/java/org/libvirt/parameters/typed/TypedDoubleParameter.java @@ -4,11 +4,15 @@ * Class for representing a double typed parameter */ public final class TypedDoubleParameter extends TypedParameter { - private double value; + public double value; public TypedDoubleParameter() { } + public TypedDoubleParameter(double value) { + this.value = value; + } + public TypedDoubleParameter(double value, String field) { this.setField(field); this.setValue(value); diff --git a/src/main/java/org/libvirt/parameters/typed/TypedIntParameter.java b/src/main/java/org/libvirt/parameters/typed/TypedIntParameter.java index cf8c8e5..7368f90 100644 --- a/src/main/java/org/libvirt/parameters/typed/TypedIntParameter.java +++ b/src/main/java/org/libvirt/parameters/typed/TypedIntParameter.java @@ -4,11 +4,15 @@ * Class for representing a int typed parameter */ public final class TypedIntParameter extends TypedParameter { - private int value; + public int value; public TypedIntParameter() { } + public TypedIntParameter(final int value) { + this.value = value; + } + public TypedIntParameter(int value, String field) { this.setField(field); this.setValue(value); diff --git a/src/main/java/org/libvirt/parameters/typed/TypedLongParameter.java b/src/main/java/org/libvirt/parameters/typed/TypedLongParameter.java index 280e565..5799753 100644 --- a/src/main/java/org/libvirt/parameters/typed/TypedLongParameter.java +++ b/src/main/java/org/libvirt/parameters/typed/TypedLongParameter.java @@ -4,11 +4,15 @@ * Class for representing a long typed parameter */ public final class TypedLongParameter extends TypedParameter { - private long value; + public long value; public TypedLongParameter() { } + public TypedLongParameter(long value) { + this.value = value; + } + public TypedLongParameter(long value, String field) { this.setField(field); this.setValue(value); diff --git a/src/main/java/org/libvirt/parameters/typed/TypedParameter.java b/src/main/java/org/libvirt/parameters/typed/TypedParameter.java index 5ca1557..6cb2cd6 100644 --- a/src/main/java/org/libvirt/parameters/typed/TypedParameter.java +++ b/src/main/java/org/libvirt/parameters/typed/TypedParameter.java @@ -11,29 +11,44 @@ * The abstract parent of the actual TypedParameter classes */ public abstract class TypedParameter { + protected static final int TYPED_PARAM_INT = 1; + protected static final int TYPED_PARAM_UINT = 2; + protected static final int TYPED_PARAM_LONG = 3; + protected static final int TYPED_PARAM_ULONG = 4; + protected static final int TYPED_PARAM_DOUBLE = 5; + protected static final int TYPED_PARAM_BOOLEAN = 6; + protected static final int TYPED_PARAM_STRING = 7; public static TypedParameter create(virTypedParameter vParam) { TypedParameter returnValue = null; if (vParam != null) { switch (vParam.type) { - case (1): - returnValue = new TypedIntParameter(vParam.value.i, Native.toString(vParam.field)); + case TYPED_PARAM_INT: + returnValue = new TypedIntParameter(vParam.value.i); break; - case (2): - returnValue = new TypedUintParameter(vParam.value.i, Native.toString(vParam.field)); + case TYPED_PARAM_UINT: + returnValue = new TypedUintParameter(vParam.value.i); break; - case (3): - returnValue = new TypedLongParameter(vParam.value.l, Native.toString(vParam.field)); + case TYPED_PARAM_LONG: + returnValue = new TypedLongParameter(vParam.value.l); break; - case (4): - returnValue = new TypedUlongParameter(vParam.value.l, Native.toString(vParam.field)); + case TYPED_PARAM_ULONG: + returnValue = new TypedUlongParameter(vParam.value.l); break; - case (5): - returnValue = new TypedDoubleParameter(vParam.value.d, Native.toString(vParam.field)); + case TYPED_PARAM_DOUBLE: + returnValue = new TypedDoubleParameter(vParam.value.d); break; - case (6): - returnValue = new TypedBooleanParameter(vParam.value.b, Native.toString(vParam.field)); + case TYPED_PARAM_BOOLEAN: + returnValue = new TypedBooleanParameter(vParam.value.b); break; + case TYPED_PARAM_STRING: + returnValue = new TypedStringParameter(vParam.value.p); + break; + default: + // Unknown type: nothing to do + } + if (returnValue != null) { + returnValue.field = Native.toString(vParam.field); } } return returnValue; @@ -45,30 +60,34 @@ public static virTypedParameter toNative(TypedParameter param) { returnValue.field = copyOf(param.field.getBytes(), Libvirt.VIR_TYPED_PARAM_FIELD_LENGTH); returnValue.type = param.getType(); switch (param.getType()) { - case (1): + case TYPED_PARAM_INT: returnValue.value.i = ((TypedIntParameter) param).getValue(); returnValue.value.setType(int.class); break; - case (2): + case TYPED_PARAM_UINT: returnValue.value.i = ((TypedUintParameter) param).getValue(); returnValue.value.setType(int.class); break; - case (3): + case TYPED_PARAM_LONG: returnValue.value.l = ((TypedLongParameter) param).getValue(); returnValue.value.setType(long.class); break; - case (4): + case TYPED_PARAM_ULONG: returnValue.value.l = ((TypedUlongParameter) param).getValue(); returnValue.value.setType(long.class); break; - case (5): + case TYPED_PARAM_DOUBLE: returnValue.value.d = ((TypedDoubleParameter) param).getValue(); returnValue.value.setType(double.class); break; - case (6): + case TYPED_PARAM_BOOLEAN: returnValue.value.b = (byte) (((TypedBooleanParameter) param).getValue() ? 1 : 0); returnValue.value.setType(byte.class); break; + case TYPED_PARAM_STRING: + returnValue.value.s = param.getValueAsString(); + returnValue.value.setType(String.class); + break; } return returnValue; } @@ -86,7 +105,7 @@ public static byte[] copyOf(byte[] original, int length) { /** * Parameter name */ - private String field; + public String field; public String getField() { return field; diff --git a/src/main/java/org/libvirt/parameters/typed/TypedStringParameter.java b/src/main/java/org/libvirt/parameters/typed/TypedStringParameter.java new file mode 100644 index 0000000..9d87653 --- /dev/null +++ b/src/main/java/org/libvirt/parameters/typed/TypedStringParameter.java @@ -0,0 +1,36 @@ +package org.libvirt.parameters.typed; + +import com.sun.jna.Pointer; + +public class TypedStringParameter extends TypedParameter { + public String value; + + public TypedStringParameter() { + + } + + public TypedStringParameter(String value) { + this.value = value; + } + + public TypedStringParameter(Pointer value) { + this.value = value.getString(0); + } + + public TypedStringParameter(final String value, final String field) { + this.field = field; + this.value = value; + } + + public int getType() { + return TYPED_PARAM_STRING; + } + + public String getTypeAsString() { + return "VIR_TYPED_PARAM_STRING"; + } + + public String getValueAsString() { + return String.valueOf(value); + } +} diff --git a/src/main/java/org/libvirt/parameters/typed/TypedUintParameter.java b/src/main/java/org/libvirt/parameters/typed/TypedUintParameter.java index c474a58..80dda7c 100644 --- a/src/main/java/org/libvirt/parameters/typed/TypedUintParameter.java +++ b/src/main/java/org/libvirt/parameters/typed/TypedUintParameter.java @@ -4,11 +4,15 @@ * Class for representing an unsigned int typed parameter */ public final class TypedUintParameter extends TypedParameter { - private int value; + public int value; public TypedUintParameter() { } + public TypedUintParameter(final int value) { + this.value = value; + } + public TypedUintParameter(int value, String field) { this.setField(field); this.setValue(value); diff --git a/src/main/java/org/libvirt/parameters/typed/TypedUlongParameter.java b/src/main/java/org/libvirt/parameters/typed/TypedUlongParameter.java index e454228..5532166 100644 --- a/src/main/java/org/libvirt/parameters/typed/TypedUlongParameter.java +++ b/src/main/java/org/libvirt/parameters/typed/TypedUlongParameter.java @@ -4,11 +4,15 @@ * Class for representing an unsigned long int typed parameter */ public final class TypedUlongParameter extends TypedParameter { - private long value; + public long value; public TypedUlongParameter() { } + public TypedUlongParameter(long value) { + this.value = value; + } + public TypedUlongParameter(long value, String field) { this.setField(field); this.setValue(value); diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 7e8b402..8904efe 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -8,17 +8,15 @@ import java.util.UUID; import junit.framework.TestCase; -import org.libvirt.event.DomainEvent; import org.libvirt.event.DomainEventType; import org.libvirt.event.LifecycleListener; import org.libvirt.flags.DomainDeviceModifyFlags; import org.libvirt.flags.DomainMetadataFlags; -import org.libvirt.parameters.DomainBlockCopyParameters; import org.libvirt.parameters.typed.TypedParameter; import org.libvirt.parameters.typed.TypedUintParameter; public final class TestJavaBindings extends TestCase { - final int UUIDArray[] = {Integer.decode("0x00"), Integer.decode("0x4b"), Integer.decode("0x96"), Integer.decode("0xe1"), + final int[] UUIDArray = {Integer.decode("0x00"), Integer.decode("0x4b"), Integer.decode("0x96"), Integer.decode("0xe1"), Integer.decode("0x2d"), Integer.decode("0x78"), Integer.decode("0xc3"), Integer.decode("0x0f"), Integer.decode("0x5a"), Integer.decode("0xa5"), Integer.decode("0xf0"), Integer.decode("0x3c"), Integer.decode("0x87"), Integer.decode("0xd2"), Integer.decode("0x1e"), Integer.decode("0x67")}; @@ -35,7 +33,12 @@ public final class TestJavaBindings extends TestCase { } protected void setUp() throws LibvirtException { - conn = new Connect("test:///default", false); + String test_libvirt_uri = System.getenv("TEST_LIBVIRT_URI"); + if (test_libvirt_uri == null) { + conn = new Connect("test:///default", false); + } else { + conn = new Connect(test_libvirt_uri, false); + } } protected void tearDown() throws LibvirtException { @@ -50,7 +53,7 @@ public void testConnectionErrorCallback() throws LibvirtException { try { conn.domainDefineXML("fail, miserably"); fail("LibvirtException expected"); - } catch (LibvirtException e) { + } catch (LibvirtException ignored) { } // ignore assertTrue("Error callback was not called", cb.error); @@ -65,8 +68,8 @@ public void testConnection() throws Exception { assertTrue("conn.getLibVersion() > 6000", conn.getLibVersion() > 6000); assertEquals("conn.getVersion()", 2, conn.getVersion()); assertTrue("conn.isAlive", conn.isAlive()); - assertTrue("conn.isEncrypted", conn.isEncrypted() == 0); - assertTrue("conn.isSecure", conn.isSecure() == 1); + assertEquals("conn.isEncrypted", 0, conn.isEncrypted()); + assertEquals("conn.isSecure", 1, conn.isSecure()); } /* @@ -114,9 +117,9 @@ public void testNetworkCreate() throws Exception { assertEquals("Number of listed networks", 2, conn.listNetworks().length); assertEquals("Number of defined networks", 1, conn.numOfDefinedNetworks()); assertEquals("Number of listed defined networks", 1, conn.listDefinedNetworks().length); - assertTrue("Network1 should not be persistent", network1.isPersistent() == 0); - assertTrue("Network1 should not be active", network1.isActive() == 1); - assertTrue("Network2 should be active", network2.isActive() == 0); + assertEquals("Network1 should not be persistent", 0, network1.isPersistent()); + assertEquals("Network1 should not be active", 1, network1.isActive()); + assertEquals("Network2 should be active", 0, network2.isActive()); this.validateNetworkData(network2); this.validateNetworkData(conn.networkLookupByName("deftest")); this.validateNetworkData(conn.networkLookupByUUIDString("004b96e1-2d78-c30f-5aa5-f03c87d21e67")); @@ -138,10 +141,6 @@ public void validateNetworkData(Network network) throws Exception { assertNotNull("network.getConnect()", network.getConnect()); assertNotNull("network.getUUID()", network.getUUID()); assertNotNull("network.getXMLDesc()", network.getXMLDesc(0)); - // TODO Figure out why this crashes in Eclipse. - // assertNotNull(Connect.connectionForNetwork(network)); - // assertTrue(Connect.connectionForNetwork(network) != - // network.getConnect()); } public void testDomainCreate() throws Exception { @@ -154,15 +153,14 @@ public void testDomainCreate() throws Exception { + " 004b96e1-2d78-c30f-5aa5-f03c87d21e67" + " 8388608" + " 2" + " hvm" + " restart" + " destroy" + " restart" + "", 0); - UUID dom2UUID = UUID.fromString("004b96e1-2d78-c30f-5aa5-f03c87d21e67"); assertEquals("Number of domains", 2, conn.numOfDomains()); assertEquals("Number of listed domains", 2, conn.listDomains().length); assertEquals("Number of defined domains", 1, conn.numOfDefinedDomains()); assertEquals("Number of listed defined domains", 1, conn.listDefinedDomains().length); - assertTrue("Domain1 should be persistent", dom1.isPersistent() == 1); - assertTrue("Domain1 should not be active", dom1.isActive() == 0); - assertTrue("Domain2 should be active", dom2.isActive() == 1); + assertEquals("Domain1 should be persistent", 1, dom1.isPersistent()); + assertEquals("Domain1 should not be active", 0, dom1.isActive()); + assertEquals("Domain2 should be active", 1, dom2.isActive()); this.validateDomainData(dom2); this.validateDomainData(conn.domainLookupByName("createst")); this.validateDomainData(conn.domainLookupByUUID(UUIDArray)); @@ -183,7 +181,7 @@ private void validateDomainData(Domain dom) throws Exception { assertNotNull("dom.getConnect()", dom.getConnect()); assertNotNull("dom.getUUID()", dom.getUUID()); assertNotNull("dom.getXMLDesc()", dom.getXMLDesc(0)); - assertNotNull("dom.getID()", dom.getID()); + assertTrue("dom.getID()", dom.getID() > 0); // Execute the code Iterate over the parameters the easy way for (TypedParameter c : dom.getSchedulerParameters()) { @@ -210,7 +208,7 @@ public void testInterfaces() throws Exception { assertEquals("virtInterfaceGetName", "eth1", virtInt.getName()); assertEquals("virtInterfaceGetMACString", "aa:bb:cc:dd:ee:ff", virtInt.getMACString()); assertNotNull("virtInterfaceGetXMLDesc", virtInt.getXMLDescription(0)); - assertTrue("virInterfaceIsActive", virtInt.isActive() == 1); + assertEquals("virInterfaceIsActive", 1, virtInt.isActive()); System.out.println(virtInt.getXMLDescription(0)); String newXML = "" + "" @@ -228,7 +226,7 @@ public void testInterfaces() throws Exception { public void testAccessAfterClose() throws Exception { conn.close(); - assertTrue("conn.isConnected should be false", !conn.isConnected()); + assertFalse("conn.isConnected should be false", conn.isConnected()); LibvirtException virException = null; try { conn.getHostName(); @@ -253,34 +251,28 @@ public void testStoragePool() throws Exception { assertNotNull("The default pool should not be null", defaultPool); assertEquals("The names should match", defaultPool.getName(), "default-pool"); assertEquals("The uids should match", pool1.getUUIDString(), "004c96e1-2d78-c30f-5aa5-f03c87d21e67"); - assertTrue("pool1 should be persistent", pool1.isPersistent() == 1); - assertTrue("pool1 should not be active", pool1.isActive() == 0); - assertTrue("Domain2 should be active", defaultPool.isActive() == 1); + assertEquals("pool1 should be persistent", 1, pool1.isPersistent()); + assertEquals("pool1 should not be active", 0, pool1.isActive()); + assertEquals("Domain2 should be active", 1, defaultPool.isActive()); } public void testDomainEvents() throws Exception { - final List events = new ArrayList(); - final Thread t = new Thread() { - @Override - public void run() { - try { - Library.runEventLoop(); - } catch (LibvirtException e) { - fail("LibvirtException was thrown: " + e); - } catch (InterruptedException e) { - } + final List events = new ArrayList<>(); + final Thread t = new Thread(() -> { + try { + Library.runEventLoop(); + } catch (LibvirtException e) { + fail("LibvirtException was thrown: " + e); + } catch (InterruptedException ignored) { } - }; + }); t.setDaemon(true); t.start(); - LifecycleListener listener = new LifecycleListener() { - @Override - public int onLifecycleChange(Domain d, DomainEvent e) { - events.add(e.getType()); + LifecycleListener listener = (d, e) -> { + events.add(e.getType()); - return 0; - } + return 0; }; try { conn.addLifecycleListener(listener); @@ -326,9 +318,17 @@ public void testDomainScreenshot() throws Exception { Stream str = this.conn.streamNew(0); Domain dom = this.conn.domainLookupByName("test"); - assertFalse("Domain \"test\" not found", dom == null); + assertNotNull("Domain \"test\" not found", dom); - String mimetype = dom.screenshot(str, 0); + try { + dom.screenshot(str, 0); + } catch (LibvirtException ex) { + if (ex.getMessage().contains("test-screenshot.png': No such file or directory")) { + System.err.format("testDomainScreenshot skipped (missing png file)"); + return; + } + throw ex; + } ByteBuffer bb = ByteBuffer.allocateDirect(8192); @@ -371,4 +371,13 @@ public void testDomainMetadata() throws Exception { String metadata = dom.getMetadata(DomainMetadataFlags.VIR_DOMAIN_METADATA_ELEMENT, "https://github.com/MissionCriticalCloud", DomainDeviceModifyFlags.VIR_DOMAIN_DEVICE_MODIFY_LIVE); assertEquals("Retrieved meta data incorrect: " + metadata, metadata, metadata1); } + + public void testDomainJobStats() throws Exception { +// Domain dom = this.conn.domainLookupByName("test"); +// Domain dom = this.conn.domainLookupByName("i-3-5-VM"); + Domain dom = new Domain(new Connect("blabla"), null); + +// assertNotNull("Domain \"test\" not found", dom); + DomainJobInfo result = dom.getJobStats(0); + } } From 9e84c8299e67e413408fa1234d3768ac4fe7a10e Mon Sep 17 00:00:00 2001 From: Alexander Verhaar Date: Sat, 17 Dec 2022 00:20:48 +0100 Subject: [PATCH 2/4] Remove some garbage from test --- src/test/java/org/libvirt/TestJavaBindings.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 8904efe..1b7e734 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -371,13 +371,4 @@ public void testDomainMetadata() throws Exception { String metadata = dom.getMetadata(DomainMetadataFlags.VIR_DOMAIN_METADATA_ELEMENT, "https://github.com/MissionCriticalCloud", DomainDeviceModifyFlags.VIR_DOMAIN_DEVICE_MODIFY_LIVE); assertEquals("Retrieved meta data incorrect: " + metadata, metadata, metadata1); } - - public void testDomainJobStats() throws Exception { -// Domain dom = this.conn.domainLookupByName("test"); -// Domain dom = this.conn.domainLookupByName("i-3-5-VM"); - Domain dom = new Domain(new Connect("blabla"), null); - -// assertNotNull("Domain \"test\" not found", dom); - DomainJobInfo result = dom.getJobStats(0); - } } From 78fd9ad3e8f1195d01ac17c8de7039aa881c71ed Mon Sep 17 00:00:00 2001 From: Alexander Verhaar Date: Sat, 17 Dec 2022 18:35:13 +0100 Subject: [PATCH 3/4] Bump junit version --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a0d243e..40bd38a 100644 --- a/pom.xml +++ b/pom.xml @@ -9,12 +9,12 @@ libvirt java bindings Java API for the libvirt C library - http://www.libvirt.org + https://www.libvirt.org MIT license - http://www.opensource.org/licenses/mit-license.php + https://www.opensource.org/licenses/mit-license.php @@ -51,7 +51,7 @@ junit junit - 4.12 + 4.13.2 From bb79c77e72d5ddfd514f8e93cb8f3b431c478344 Mon Sep 17 00:00:00 2001 From: Alexander Verhaar Date: Sat, 17 Dec 2022 22:34:53 +0100 Subject: [PATCH 4/4] Change load back to loadLibrary --- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index d5b5bac..afbcadb 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -54,7 +54,7 @@ */ public interface Libvirt extends Library { - Libvirt INSTANCE = Native.load(Platform.isWindows() ? "virt-0" : "virt", Libvirt.class); + Libvirt INSTANCE = Native.loadLibrary(Platform.isWindows() ? "virt-0" : "virt", Libvirt.class); // Constants we need int VIR_UUID_BUFLEN = 16;