Error: Machine Take Snapshot Not Implemented

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
brandnbil
Posts: 4
Joined: 1. Mar 2016, 16:56

Error: Machine Take Snapshot Not Implemented

Post by brandnbil »

Im running into an exception when attempting to take a snapshot from a java implementation of the virtual box api using the latest java api jar and the latest version of virtualbox running on windows (5.0.14). The exception i get is below:

This is the code im running, its a pretty straightforward example of instantiating an IMachine object by machine name, and attempting to take a snapshot of it.

Code: Select all

public String takeVMSnapshot(VirtualBoxManager vboxMgr, IVirtualBox vBox, String vmName, String snapshotName) {
	String returnValue = "";
        
        try {
        	IMachine machine = vBox.findMachine(vmName);
        	IProgress progress = machine.takeSnapshot(snapshotName, "", true, null);
        	progress.waitForCompletion(-1);
                returnValue = "Successfully created snapshot " + snapshotName + " on VM: " + vmName;
        } catch (VBoxException e) {
               e.printStackTrace();
               returnValue = "Attempted to create snapshot " + snapshotName + " on VM: " + vmName + " but the method takeVMSnapshot failed. Here's the exception: " + e.getMessage();
        }

     return returnValue;
}
And here is the exception thrown when it attempts to call the takeSnapshot method on the IMachine object:

Code: Select all

org.virtualbox_5_0.VBoxException: VirtualBox error: rc=0x80004001 Method Machine::takeSnapshot is not implemented (0x80004001)
	at org.virtualbox_5_0.IMachine.takeSnapshot(IMachine.java:6430)
	at VirtualBoxService.takeVMSnapshot(VirtualBoxService.java:338)
	at VirtualBoxService.main(VirtualBoxService.java:615)
Caused by: org.virtualbox_5_0.jaxws.RuntimeFaultMsg: VirtualBox error: rc=0x80004001 Method Machine::takeSnapshot is not implemented (0x80004001)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:136)
	at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
	at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
	at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
	at com.sun.proxy.$Proxy24.iMachineTakeSnapshot(Unknown Source)
	at org.virtualbox_5_0.IMachine.takeSnapshot(IMachine.java:6420)
	... 2 more
Ive tried this on two separate vbox servers, and both throw the exact same exception.

Again, im running Both VirtualBox 5.0.14 for windows, and am running my java code using the vboxjws.jar included in the latest 5.0.14 SDK. Also, i have attached a screenshot of the VBoxWebSrv.exe output from my running web service instance on my server when the takeSnapshot request comes in.

I attempted to take a snapshot using a VBoxManage direct CLI call for the same VM in question, and the worked as expected.

Can anyone explain what would cause this exception?
Attachments
vboxconsole.PNG
vboxconsole.PNG (26.88 KiB) Viewed 7864 times
Last edited by noteirak on 1. Mar 2016, 17:49, edited 1 time in total.
Reason: Added code tag
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Error: Machine Take Snapshot Not Implemented

Post by noteirak »

You need to acquire a Shared locked session on the VM to be able to take a snapshot.
The error is definitely misleading here...
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
brandnbil
Posts: 4
Joined: 1. Mar 2016, 16:56

Re: Error: Machine Take Snapshot Not Implemented

Post by brandnbil »

My original code actually did have the takesnapshot event wrapped within the context of a shared locked session, and i believe i was still getting this same error. However, im going to go back and try that again now just to be sure. Thanks for the suggestion, will follow up with results.
brandnbil
Posts: 4
Joined: 1. Mar 2016, 16:56

Re: Error: Machine Take Snapshot Not Implemented

Post by brandnbil »

Thanks again for the suggestion, however it did not resolve the exception. Im still seeing the same exception with my updated code:

Code: Select all


	public String takeVMSnapshot(VirtualBoxManager vboxMgr, IVirtualBox vBox, String vmName, String snapshotName) {
		String returnValue = "";
		ISession session = null;
		
        try {
        	IMachine machine = vBox.findMachine(vmName);
        	session = vboxMgr.getSessionObject();
        	machine.lockMachine(session, LockType.Shared);
        	IProgress progress = machine.takeSnapshot(snapshotName, "", true, null);
        	progress.waitForCompletion(-1);
        	session.unlockMachine();
            returnValue = "Successfully created snapshot " + snapshotName + " on VM: " + vmName;
        } catch (VBoxException e) {
            e.printStackTrace();
            session.unlockMachine();
            returnValue = "Attempted to create snapshot " + snapshotName + " on VM: " + vmName + " but the method takeVMSnapshot failed. Here's the exception: " + e.getMessage();
        }
        
        return returnValue;
    }

Again the exception output is:

Code: Select all


org.virtualbox_5_0.VBoxException: VirtualBox error: rc=0x80004001 Method Machine::takeSnapshot is not implemented (0x80004001)
	at org.virtualbox_5_0.IMachine.takeSnapshot(IMachine.java:6430)
	at VirtualBoxService.takeVMSnapshot(VirtualBoxService.java:337)
	at VirtualBoxService.main(VirtualBoxService.java:607)
Caused by: org.virtualbox_5_0.jaxws.RuntimeFaultMsg: VirtualBox error: rc=0x80004001 Method Machine::takeSnapshot is not implemented (0x80004001)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:136)
	at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
	at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
	at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
	at com.sun.proxy.$Proxy24.iMachineTakeSnapshot(Unknown Source)
	at org.virtualbox_5_0.IMachine.takeSnapshot(IMachine.java:6420)
	... 2 more

If this is not the correct way to wrap this method call within a shared lock session, then please let me know. Thanks again for your assistance.
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Error: Machine Take Snapshot Not Implemented

Post by noteirak »

I see the issue - even tho you are locking the machine, you are not using the machine object from the session (so the actual locked object)
So instead of

Code: Select all

IProgress progress = machine.takeSnapshot(snapshotName, "", true, null);
You need to do

Code: Select all

IProgress progress = session.getMachine().takeSnapshot(snapshotName, "", true, null);
Try the following code instead:

Code: Select all


	public String takeVMSnapshot(VirtualBoxManager vboxMgr, IVirtualBox vBox, String vmName, String snapshotName) {
		String returnValue = "";
		ISession session = null;
		
        try {
        	IMachine machine = vBox.findMachine(vmName);
        	session = vboxMgr.getSessionObject();
        	machine.lockMachine(session, LockType.Shared);
        	IProgress progress = session.getMachine().takeSnapshot(snapshotName, "", true, null);
        	progress.waitForCompletion(-1);
        	session.unlockMachine();
            returnValue = "Successfully created snapshot " + snapshotName + " on VM: " + vmName;
        } catch (VBoxException e) {
            e.printStackTrace();
            session.unlockMachine();
            returnValue = "Attempted to create snapshot " + snapshotName + " on VM: " + vmName + " but the method takeVMSnapshot failed. Here's the exception: " + e.getMessage();
        }
        
        return returnValue;
    }

Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
brandnbil
Posts: 4
Joined: 1. Mar 2016, 16:56

Re: Error: Machine Take Snapshot Not Implemented

Post by brandnbil »

Ahhhh, ok that makes sense now. That fixed the issue.

Also minor side note, passing a null value into the id argument of the takeSnapshot method was still throwing a null pointer exception (but the snapshot was still taken correctly anyway). So i just instantiated an explicit uuid value to pass into the id argument, and it ran without any errors.

Anyway thanks again for your help, much appreciated. Here is the final working code.

Code: Select all


public String takeVMSnapshot(VirtualBoxManager vboxMgr, IVirtualBox vBox, String vmName, String snapshotName) {
		String returnValue = "";
		ISession session = null;
		Holder<String> snapshotUuid = new Holder<String>(UUID.randomUUID().toString());
		
        try {
        	IMachine machine = vBox.findMachine(vmName);
            session = vboxMgr.getSessionObject();
            machine.lockMachine(session, LockType.Shared);
            IProgress progress = session.getMachine().takeSnapshot(snapshotName, "", true, snapshotUuid);
            progress.waitForCompletion(-1);
            session.unlockMachine();
            returnValue = "Successfully created snapshot " + snapshotName + " on VM: " + vmName;
        } catch (VBoxException e) {
            e.printStackTrace();
            session.unlockMachine();
            returnValue = "Attempted to create snapshot " + snapshotName + " on VM: " + vmName + " but the method takeVMSnapshot failed. Here's the exception: " + e.getMessage();
        }
        
        return returnValue;
    }

noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Error: Machine Take Snapshot Not Implemented

Post by noteirak »

Glad you got it working!

About the snapshot UUID throwing a null pointer, that is because you gave a null value for the Holder parameter in the method call.
You can simply create a new Holder object without any value inside (using the no-arg constructor) which will then generate a UUID on its own and populate the Holder with it, which you can access afterwards, like this:

Code: Select all

Holder<String> snapshotUuid = new Holder<String>();
...
String uuid = snapshotUuid.value;
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply