Skip to content

Commit a6ce66e

Browse files
committed
move a lot of code into vmsnapshot strategy
fix compile fix compile add vm_snapshot_details table in db add vmsnapshot test cases
1 parent 5c5326f commit a6ce66e

33 files changed

Lines changed: 1398 additions & 813 deletions

File tree

client/tomcatconf/applicationContext.xml.in

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@
365365
<bean id="vMReservationDaoImpl" class="org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDaoImpl" />
366366
<bean id="vMRootDiskTagDaoImpl" class="org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMRootDiskTagDaoImpl" />
367367
<bean id="vMSnapshotDaoImpl" class="com.cloud.vm.snapshot.dao.VMSnapshotDaoImpl" />
368+
<bean id="vMSnapshotDetailsDaoImpl" class="com.cloud.vm.snapshot.dao.VMSnapshotDetailsDaoImpl" />
368369
<bean id="vMTemplateDetailsDaoImpl" class="com.cloud.storage.dao.VMTemplateDetailsDaoImpl" />
369370
<bean id="vMTemplateHostDaoImpl" class="com.cloud.storage.dao.VMTemplateHostDaoImpl" />
370371
<bean id="vMTemplatePoolDaoImpl" class="com.cloud.storage.dao.VMTemplatePoolDaoImpl" />
@@ -882,8 +883,17 @@
882883
<bean id="ApplicationLoadBalancerService" class="org.apache.cloudstack.network.lb.ApplicationLoadBalancerManagerImpl" />
883884
<bean id="InternalLoadBalancerVMManager" class="org.apache.cloudstack.network.lb.InternalLoadBalancerVMManagerImpl" />
884885

885-
<bean id="vMSnapshotManagerImpl" class="com.cloud.vm.snapshot.VMSnapshotManagerImpl" />
886+
<!--VM snapshot Strategies-->
887+
<bean id='vmSnapshotHelper' class="org.apache.cloudstack.storage.vmsnapshot.VMSnapshotHelperImpl" />
888+
<bean id='defaultVMSnapshotStrategy' class="org.apache.cloudstack.storage.vmsnapshot.DefaultVMSnapshotStrategy"/>
886889

890+
<bean id="vMSnapshotManagerImpl" class="com.cloud.vm.snapshot.VMSnapshotManagerImpl">
891+
<property name="vmSnapshotStrategies">
892+
<list>
893+
<ref local="defaultVMSnapshotStrategy"/>
894+
</list>
895+
</property>
896+
</bean>
887897

888898
<!--=======================================================================================================-->
889899
<!-- -->

core/src/com/cloud/agent/api/CreateVMSnapshotAnswer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717

1818
package com.cloud.agent.api;
1919

20-
import java.util.List;
20+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2121

22-
import com.cloud.agent.api.to.VolumeTO;
22+
import java.util.List;
2323

2424
public class CreateVMSnapshotAnswer extends Answer {
2525

26-
private List<VolumeTO> volumeTOs;
26+
private List<VolumeObjectTO> volumeTOs;
2727
private VMSnapshotTO vmSnapshotTo;
2828

2929

30-
public List<VolumeTO> getVolumeTOs() {
30+
public List<VolumeObjectTO> getVolumeTOs() {
3131
return volumeTOs;
3232
}
3333

34-
public void setVolumeTOs(List<VolumeTO> volumeTOs) {
34+
public void setVolumeTOs(List<VolumeObjectTO> volumeTOs) {
3535
this.volumeTOs = volumeTOs;
3636
}
3737

@@ -53,7 +53,7 @@ public CreateVMSnapshotAnswer(CreateVMSnapshotCommand cmd, boolean success,
5353
}
5454

5555
public CreateVMSnapshotAnswer(CreateVMSnapshotCommand cmd,
56-
VMSnapshotTO vmSnapshotTo, List<VolumeTO> volumeTOs) {
56+
VMSnapshotTO vmSnapshotTo, List<VolumeObjectTO> volumeTOs) {
5757
super(cmd, true, "");
5858
this.vmSnapshotTo = vmSnapshotTo;
5959
this.volumeTOs = volumeTOs;

core/src/com/cloud/agent/api/CreateVMSnapshotCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
import java.util.List;
2020

21+
import com.cloud.agent.api.to.DataTO;
2122
import com.cloud.agent.api.to.VolumeTO;
2223
import com.cloud.vm.VirtualMachine;
24+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2325

2426
public class CreateVMSnapshotCommand extends VMSnapshotBaseCommand {
2527

26-
public CreateVMSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeTO> volumeTOs, String guestOSType, VirtualMachine.State vmState) {
28+
public CreateVMSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeObjectTO> volumeTOs, String guestOSType, VirtualMachine.State vmState) {
2729
super(vmName, snapshot, volumeTOs, guestOSType);
2830
this.vmState = vmState;
2931
}

core/src/com/cloud/agent/api/DeleteVMSnapshotAnswer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
// under the License.
1717
package com.cloud.agent.api;
1818

19-
import java.util.List;
19+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2020

21-
import com.cloud.agent.api.to.VolumeTO;
21+
import java.util.List;
2222

2323
public class DeleteVMSnapshotAnswer extends Answer {
24-
private List<VolumeTO> volumeTOs;
24+
private List<VolumeObjectTO> volumeTOs;
2525

2626
public DeleteVMSnapshotAnswer() {
2727
}
@@ -32,16 +32,16 @@ public DeleteVMSnapshotAnswer(DeleteVMSnapshotCommand cmd, boolean result,
3232
}
3333

3434
public DeleteVMSnapshotAnswer(DeleteVMSnapshotCommand cmd,
35-
List<VolumeTO> volumeTOs) {
35+
List<VolumeObjectTO> volumeTOs) {
3636
super(cmd, true, "");
3737
this.volumeTOs = volumeTOs;
3838
}
3939

40-
public List<VolumeTO> getVolumeTOs() {
40+
public List<VolumeObjectTO> getVolumeTOs() {
4141
return volumeTOs;
4242
}
4343

44-
public void setVolumeTOs(List<VolumeTO> volumeTOs) {
44+
public void setVolumeTOs(List<VolumeObjectTO> volumeTOs) {
4545
this.volumeTOs = volumeTOs;
4646
}
4747

core/src/com/cloud/agent/api/DeleteVMSnapshotCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
import java.util.List;
2020

2121
import com.cloud.agent.api.to.VolumeTO;
22+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2223

2324

2425
public class DeleteVMSnapshotCommand extends VMSnapshotBaseCommand {
25-
public DeleteVMSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeTO> volumeTOs, String guestOSType) {
26+
public DeleteVMSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeObjectTO> volumeTOs, String guestOSType) {
2627
super( vmName, snapshot, volumeTOs, guestOSType);
2728
}
2829
}

core/src/com/cloud/agent/api/RevertToVMSnapshotAnswer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
package com.cloud.agent.api;
1919

20-
import java.util.List;
21-
22-
import com.cloud.agent.api.to.VolumeTO;
2320
import com.cloud.vm.VirtualMachine;
21+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
22+
23+
import java.util.List;
2424

2525
public class RevertToVMSnapshotAnswer extends Answer {
2626

27-
private List<VolumeTO> volumeTOs;
27+
private List<VolumeObjectTO> volumeTOs;
2828
private VirtualMachine.State vmState;
2929

3030
public RevertToVMSnapshotAnswer(RevertToVMSnapshotCommand cmd, boolean result,
@@ -37,7 +37,7 @@ public RevertToVMSnapshotAnswer() {
3737
}
3838

3939
public RevertToVMSnapshotAnswer(RevertToVMSnapshotCommand cmd,
40-
List<VolumeTO> volumeTOs,
40+
List<VolumeObjectTO> volumeTOs,
4141
VirtualMachine.State vmState) {
4242
super(cmd, true, "");
4343
this.volumeTOs = volumeTOs;
@@ -48,11 +48,11 @@ public VirtualMachine.State getVmState() {
4848
return vmState;
4949
}
5050

51-
public List<VolumeTO> getVolumeTOs() {
51+
public List<VolumeObjectTO> getVolumeTOs() {
5252
return volumeTOs;
5353
}
5454

55-
public void setVolumeTOs(List<VolumeTO> volumeTOs) {
55+
public void setVolumeTOs(List<VolumeObjectTO> volumeTOs) {
5656
this.volumeTOs = volumeTOs;
5757
}
5858

core/src/com/cloud/agent/api/RevertToVMSnapshotCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
import java.util.List;
2020

2121
import com.cloud.agent.api.to.VolumeTO;
22+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2223

2324
public class RevertToVMSnapshotCommand extends VMSnapshotBaseCommand {
2425

25-
public RevertToVMSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeTO> volumeTOs, String guestOSType) {
26+
public RevertToVMSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeObjectTO> volumeTOs, String guestOSType) {
2627
super(vmName, snapshot, volumeTOs, guestOSType);
2728
}
2829

core/src/com/cloud/agent/api/VMSnapshotBaseCommand.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,29 @@
1919

2020
import java.util.List;
2121

22+
import com.cloud.agent.api.to.DataTO;
2223
import com.cloud.agent.api.to.VolumeTO;
24+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2325

2426
public class VMSnapshotBaseCommand extends Command{
25-
protected List<VolumeTO> volumeTOs;
27+
protected List<VolumeObjectTO> volumeTOs;
2628
protected VMSnapshotTO target;
2729
protected String vmName;
2830
protected String guestOSType;
2931

3032

31-
public VMSnapshotBaseCommand(String vmName, VMSnapshotTO snapshot, List<VolumeTO> volumeTOs, String guestOSType) {
33+
public VMSnapshotBaseCommand(String vmName, VMSnapshotTO snapshot, List<VolumeObjectTO> volumeTOs, String guestOSType) {
3234
this.vmName = vmName;
3335
this.target = snapshot;
3436
this.volumeTOs = volumeTOs;
3537
this.guestOSType = guestOSType;
3638
}
3739

38-
public List<VolumeTO> getVolumeTOs() {
40+
public List<VolumeObjectTO> getVolumeTOs() {
3941
return volumeTOs;
4042
}
4143

42-
public void setVolumeTOs(List<VolumeTO> volumeTOs) {
44+
public void setVolumeTOs(List<VolumeObjectTO> volumeTOs) {
4345
this.volumeTOs = volumeTOs;
4446
}
4547

core/src/org/apache/cloudstack/storage/to/VolumeObjectTO.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class VolumeObjectTO implements DataTO {
3838
private String chainInfo;
3939
private Storage.ImageFormat format;
4040
private long id;
41+
42+
private Long deviceId;
4143
private Long bytesReadRate;
4244
private Long bytesWriteRate;
4345
private Long iopsReadRate;
@@ -70,6 +72,7 @@ public VolumeObjectTO(VolumeInfo volume) {
7072
this.iopsReadRate = volume.getIopsReadRate();
7173
this.iopsWriteRate = volume.getIopsWriteRate();
7274
this.hypervisorType = volume.getHypervisorType();
75+
setDeviceId(volume.getDeviceId());
7376
}
7477

7578
public String getUuid() {
@@ -220,4 +223,13 @@ public Long getIopsWriteRate() {
220223
return iopsWriteRate;
221224
}
222225

226+
public Long getDeviceId() {
227+
return deviceId;
228+
}
229+
230+
public void setDeviceId(Long deviceId) {
231+
this.deviceId = deviceId;
232+
}
233+
234+
223235
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
package org.apache.cloudstack.engine.subsystem.api.storage;
20+
21+
import com.cloud.vm.snapshot.VMSnapshot;
22+
23+
public interface VMSnapshotStrategy {
24+
VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot);
25+
boolean deleteVMSnapshot(VMSnapshot vmSnapshot);
26+
boolean revertVMSnapshot(VMSnapshot vmSnapshot);
27+
boolean canHandle(VMSnapshot vmSnapshot);
28+
}

0 commit comments

Comments
 (0)