Skip to content

Commit 2abbed6

Browse files
CSTACKEX-18_2: taking snapshot with memory option set as true
1 parent 5bff41f commit 2abbed6

File tree

8 files changed

+867
-19
lines changed

8 files changed

+867
-19
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
import com.cloud.vm.VirtualMachine;
23+
24+
/**
25+
* Answer for {@link RestoreVMFromMemoryFileCommand}.
26+
*
27+
* <p>Contains the result of restoring a VM from a memory file,
28+
* including the VM's power state after restoration.</p>
29+
*/
30+
public class RestoreVMFromMemoryFileAnswer extends Answer {
31+
32+
private VirtualMachine.PowerState vmPowerState;
33+
34+
public RestoreVMFromMemoryFileAnswer() {
35+
// Default constructor for serialization
36+
}
37+
38+
public RestoreVMFromMemoryFileAnswer(RestoreVMFromMemoryFileCommand cmd, boolean success, String details) {
39+
super(cmd, success, details);
40+
}
41+
42+
public RestoreVMFromMemoryFileAnswer(RestoreVMFromMemoryFileCommand cmd, boolean success, String details,
43+
VirtualMachine.PowerState vmPowerState) {
44+
super(cmd, success, details);
45+
this.vmPowerState = vmPowerState;
46+
}
47+
48+
public VirtualMachine.PowerState getVmPowerState() {
49+
return vmPowerState;
50+
}
51+
52+
public void setVmPowerState(VirtualMachine.PowerState vmPowerState) {
53+
this.vmPowerState = vmPowerState;
54+
}
55+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
/**
23+
* Command to restore a VM from a saved memory file.
24+
*
25+
* <p>This command restores a previously saved VM memory state from a file,
26+
* effectively resuming the VM from the exact point where it was saved.
27+
* This is used during VM snapshot revert operations for storage plugins
28+
* that use file-based memory snapshots (e.g., ONTAP).</p>
29+
*
30+
* <p>The workflow is:</p>
31+
* <ol>
32+
* <li>Ensure the VM is stopped/undefined</li>
33+
* <li>Restore memory from file using virsh restore or Connect.domainRestore()</li>
34+
* <li>VM resumes running from the saved state</li>
35+
* </ol>
36+
*/
37+
public class RestoreVMFromMemoryFileCommand extends Command {
38+
39+
private String vmName;
40+
private String vmUuid;
41+
private String memoryFilePath;
42+
private boolean deleteMemoryFileAfterRestore;
43+
44+
public RestoreVMFromMemoryFileCommand() {
45+
// Default constructor for serialization
46+
}
47+
48+
/**
49+
* Creates a command to restore VM from a memory file.
50+
*
51+
* @param vmName the name of the VM (libvirt domain name)
52+
* @param vmUuid the UUID of the VM
53+
* @param memoryFilePath the absolute path to the saved memory file
54+
* @param deleteMemoryFileAfterRestore if true, delete the memory file after successful restore
55+
*/
56+
public RestoreVMFromMemoryFileCommand(String vmName, String vmUuid, String memoryFilePath,
57+
boolean deleteMemoryFileAfterRestore) {
58+
this.vmName = vmName;
59+
this.vmUuid = vmUuid;
60+
this.memoryFilePath = memoryFilePath;
61+
this.deleteMemoryFileAfterRestore = deleteMemoryFileAfterRestore;
62+
}
63+
64+
public String getVmName() {
65+
return vmName;
66+
}
67+
68+
public void setVmName(String vmName) {
69+
this.vmName = vmName;
70+
}
71+
72+
public String getVmUuid() {
73+
return vmUuid;
74+
}
75+
76+
public void setVmUuid(String vmUuid) {
77+
this.vmUuid = vmUuid;
78+
}
79+
80+
public String getMemoryFilePath() {
81+
return memoryFilePath;
82+
}
83+
84+
public void setMemoryFilePath(String memoryFilePath) {
85+
this.memoryFilePath = memoryFilePath;
86+
}
87+
88+
public boolean isDeleteMemoryFileAfterRestore() {
89+
return deleteMemoryFileAfterRestore;
90+
}
91+
92+
public void setDeleteMemoryFileAfterRestore(boolean deleteMemoryFileAfterRestore) {
93+
this.deleteMemoryFileAfterRestore = deleteMemoryFileAfterRestore;
94+
}
95+
96+
@Override
97+
public boolean executeInSequence() {
98+
return false;
99+
}
100+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
/**
23+
* Answer for {@link SaveVMMemoryToFileCommand}.
24+
*
25+
* <p>Contains the result of saving VM memory to a file, including the actual
26+
* file path where memory was saved and the file size.</p>
27+
*/
28+
public class SaveVMMemoryToFileAnswer extends Answer {
29+
30+
private String memoryFilePath;
31+
private long memoryFileSize;
32+
33+
public SaveVMMemoryToFileAnswer() {
34+
// Default constructor for serialization
35+
}
36+
37+
public SaveVMMemoryToFileAnswer(SaveVMMemoryToFileCommand cmd, boolean success, String details) {
38+
super(cmd, success, details);
39+
}
40+
41+
public SaveVMMemoryToFileAnswer(SaveVMMemoryToFileCommand cmd, boolean success, String details,
42+
String memoryFilePath, long memoryFileSize) {
43+
super(cmd, success, details);
44+
this.memoryFilePath = memoryFilePath;
45+
this.memoryFileSize = memoryFileSize;
46+
}
47+
48+
public String getMemoryFilePath() {
49+
return memoryFilePath;
50+
}
51+
52+
public void setMemoryFilePath(String memoryFilePath) {
53+
this.memoryFilePath = memoryFilePath;
54+
}
55+
56+
public long getMemoryFileSize() {
57+
return memoryFileSize;
58+
}
59+
60+
public void setMemoryFileSize(long memoryFileSize) {
61+
this.memoryFileSize = memoryFileSize;
62+
}
63+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
/**
23+
* Command to save VM memory state to a file on shared storage.
24+
*
25+
* <p>This command pauses the VM, saves its memory state to the specified file path,
26+
* and then resumes the VM. This is used by storage plugins (e.g., ONTAP) that need
27+
* to capture memory state as a file that can be included in a storage-level snapshot,
28+
* rather than using libvirt's internal qcow2 snapshot mechanism.</p>
29+
*
30+
* <p>The workflow is:</p>
31+
* <ol>
32+
* <li>Pause the VM (to ensure consistent memory state)</li>
33+
* <li>Save memory to file using virsh save or Domain.save()</li>
34+
* <li>Resume the VM (so the VM continues running after snapshot)</li>
35+
* </ol>
36+
*
37+
* <p>Note: This is different from libvirt's managed-save which stops the VM.
38+
* We want the VM to continue running after the memory is saved.</p>
39+
*/
40+
public class SaveVMMemoryToFileCommand extends Command {
41+
42+
private String vmName;
43+
private String vmUuid;
44+
private String memoryFilePath;
45+
private boolean resumeAfterSave;
46+
47+
public SaveVMMemoryToFileCommand() {
48+
// Default constructor for serialization
49+
}
50+
51+
/**
52+
* Creates a command to save VM memory to a file.
53+
*
54+
* @param vmName the name of the VM (libvirt domain name)
55+
* @param vmUuid the UUID of the VM
56+
* @param memoryFilePath the absolute path where memory should be saved
57+
* (must be on shared/accessible storage)
58+
* @param resumeAfterSave if true, resume the VM after saving memory;
59+
* if false, leave the VM paused (caller will resume later)
60+
*/
61+
public SaveVMMemoryToFileCommand(String vmName, String vmUuid, String memoryFilePath, boolean resumeAfterSave) {
62+
this.vmName = vmName;
63+
this.vmUuid = vmUuid;
64+
this.memoryFilePath = memoryFilePath;
65+
this.resumeAfterSave = resumeAfterSave;
66+
}
67+
68+
public String getVmName() {
69+
return vmName;
70+
}
71+
72+
public void setVmName(String vmName) {
73+
this.vmName = vmName;
74+
}
75+
76+
public String getVmUuid() {
77+
return vmUuid;
78+
}
79+
80+
public void setVmUuid(String vmUuid) {
81+
this.vmUuid = vmUuid;
82+
}
83+
84+
public String getMemoryFilePath() {
85+
return memoryFilePath;
86+
}
87+
88+
public void setMemoryFilePath(String memoryFilePath) {
89+
this.memoryFilePath = memoryFilePath;
90+
}
91+
92+
public boolean isResumeAfterSave() {
93+
return resumeAfterSave;
94+
}
95+
96+
public void setResumeAfterSave(boolean resumeAfterSave) {
97+
this.resumeAfterSave = resumeAfterSave;
98+
}
99+
100+
@Override
101+
public boolean executeInSequence() {
102+
return false;
103+
}
104+
}

0 commit comments

Comments
 (0)