Skip to content

Commit dcf3790

Browse files
author
Edison Su
committed
add volume types
1 parent a388a74 commit dcf3790

21 files changed

Lines changed: 271 additions & 43 deletions
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
11
package org.apache.cloudstack.storage.volume;
22

3+
import javax.inject.Inject;
4+
5+
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
36
import org.apache.cloudstack.storage.volume.db.VolumeVO;
7+
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType;
8+
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskTypeHelper;
9+
import org.apache.cloudstack.storage.volume.type.VolumeType;
10+
import org.apache.cloudstack.storage.volume.type.VolumeTypeHelper;
411

512
import com.cloud.utils.fsm.StateObject;
613

7-
public class Volume implements StateObject<VolumeState>{
8-
private VolumeVO volumeVO;
14+
public class Volume implements StateObject<VolumeState> {
15+
protected VolumeVO volumeVO;
16+
protected DataStore dataStore;
17+
@Inject
18+
VolumeDiskTypeHelper diskTypeHelper;
19+
@Inject
20+
VolumeTypeHelper volumeTypeHelper;
21+
22+
public Volume(DataStore dataStore, VolumeVO volumeVO) {
23+
this.volumeVO = volumeVO;
24+
this.dataStore = dataStore;
25+
}
26+
927
@Override
1028
public VolumeState getState() {
11-
// TODO Auto-generated method stub
12-
return null;
29+
return volumeVO.getState();
1330
}
1431

32+
public DataStore getDataStore() {
33+
return dataStore;
34+
}
1535

16-
36+
public long getSize() {
37+
return volumeVO.getSize();
38+
}
39+
40+
public VolumeDiskType getDiskType() {
41+
return diskTypeHelper.getDiskType(volumeVO.getDiskType());
42+
}
43+
44+
public VolumeType getType() {
45+
return volumeTypeHelper.getType(volumeVO.getVolumeType());
46+
}
1747
}

platform/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
*/
1919
package org.apache.cloudstack.storage.volume;
2020

21-
22-
import com.cloud.storage.Volume;
21+
import org.apache.cloudstack.storage.volume.type.VolumeType;
2322

2423
public interface VolumeService {
2524

25+
/**
26+
*
27+
*/
28+
Volume allocateVolumeInDb(long size, VolumeType type);
29+
2630
/**
2731
* Creates the volume based on the given criteria
2832
*

platform/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,13 @@
1818
*/
1919
package org.apache.cloudstack.storage.volume;
2020

21-
import org.apache.cloudstack.storage.volume.db.VolumeDao;
22-
import org.apache.cloudstack.storage.volume.db.VolumeVO;
23-
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.stereotype.Component;
21+
import org.apache.cloudstack.storage.volume.type.VolumeType;
22+
import org.springframework.stereotype.Service;
2523

26-
import com.cloud.storage.SnapshotVO;
27-
import com.cloud.storage.Volume;
28-
import com.cloud.storage.dao.SnapshotDao;
29-
import com.cloud.upgrade.dao.VersionDao;
30-
import com.cloud.upgrade.dao.VersionVO;
3124
import com.cloud.utils.db.DB;
3225

33-
@Component
26+
@Service
3427
public class VolumeServiceImpl implements VolumeService {
35-
@Autowired
36-
VolumeDao _volumeDao;
3728
@Override
3829
public Volume createVolume(long volumeId) {
3930
// TODO Auto-generated method stub
@@ -43,8 +34,6 @@ public Volume createVolume(long volumeId) {
4334
@DB
4435
@Override
4536
public boolean deleteVolume(long volumeId) {
46-
VolumeVO vol = new VolumeVO(VolumeType.ROOT, "root", 1, 1,1 ,1,1);
47-
_volumeDao.persist(vol);
4837
return true;
4938
}
5039

@@ -71,4 +60,10 @@ public boolean rokeAccess(long volumeId, long endpointId) {
7160
// TODO Auto-generated method stub
7261
return false;
7362
}
63+
64+
@Override
65+
public Volume allocateVolumeInDb(long size, VolumeType type) {
66+
// TODO Auto-generated method stub
67+
return null;
68+
}
7469
}

platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.apache.cloudstack.storage.volume.Volume;
2222
import org.apache.cloudstack.storage.volume.VolumeEvent;
2323
import org.apache.cloudstack.storage.volume.VolumeState;
24-
import org.apache.cloudstack.storage.volume.VolumeType;
24+
import org.apache.cloudstack.storage.volume.type.VolumeType;
2525

2626
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2727
import com.cloud.storage.Storage.ImageFormat;
@@ -76,4 +76,6 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<VolumeSt
7676
List<VolumeVO> findReadyRootVolumesByInstance(long instanceId);
7777

7878
List<Long> listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId);
79+
80+
VolumeVO allocVolume(long size, VolumeType type);
7981
}

platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525

2626
import javax.ejb.Local;
2727

28+
import org.apache.cloudstack.storage.volume.Volume;
2829
import org.apache.cloudstack.storage.volume.VolumeEvent;
2930
import org.apache.cloudstack.storage.volume.VolumeState;
30-
import org.apache.cloudstack.storage.volume.VolumeType;
31+
import org.apache.cloudstack.storage.volume.type.RootDisk;
32+
import org.apache.cloudstack.storage.volume.type.VolumeType;
3133
import org.apache.log4j.Logger;
3234
import org.springframework.stereotype.Component;
3335

@@ -104,7 +106,7 @@ public List<VolumeVO> findByPoolId(long poolId) {
104106
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
105107
sc.setParameters("poolId", poolId);
106108
sc.setParameters("notDestroyed", VolumeState.Destroy);
107-
sc.setParameters("vType", VolumeType.ROOT.toString());
109+
sc.setParameters("vType", new RootDisk().toString());
108110
return listBy(sc);
109111
}
110112

@@ -146,7 +148,7 @@ public List<VolumeVO> findReadyRootVolumesByInstance(long instanceId) {
146148
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
147149
sc.setParameters("instanceId", instanceId);
148150
sc.setParameters("state", VolumeState.Ready);
149-
sc.setParameters("vType", VolumeType.ROOT);
151+
sc.setParameters("vType", new RootDisk().toString());
150152
return listBy(sc);
151153
}
152154

@@ -413,4 +415,11 @@ public boolean remove(Long id) {
413415
txn.commit();
414416
return result;
415417
}
418+
419+
@Override
420+
@DB
421+
public VolumeVO allocVolume(long size, VolumeType type) {
422+
VolumeVO vol = new VolumeVO();
423+
return vol;
424+
}
416425
}

platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
import javax.persistence.TemporalType;
3333

3434
import org.apache.cloudstack.storage.volume.VolumeState;
35-
import org.apache.cloudstack.storage.volume.VolumeType;
35+
import org.apache.cloudstack.storage.volume.disktype.Unknown;
36+
import org.apache.cloudstack.storage.volume.type.VolumeType;
3637

3738
import com.cloud.api.Identity;
3839
import com.cloud.storage.Storage.StoragePoolType;
@@ -104,13 +105,15 @@ public class VolumeVO implements Identity {
104105
String firstSnapshotBackupUuid;
105106

106107
@Column(name = "volume_type")
107-
@Enumerated(EnumType.STRING)
108-
VolumeType volumeType = VolumeType.UNKNOWN;
108+
String volumeType = "UNKNOWN";
109109

110110
@Column(name = "pool_type")
111111
@Enumerated(EnumType.STRING)
112112
StoragePoolType poolType;
113-
113+
114+
@Column(name = "disk_type")
115+
String diskType = new Unknown().toString();
116+
114117
@Column(name = GenericDao.REMOVED_COLUMN)
115118
Date removed;
116119

@@ -139,7 +142,7 @@ public class VolumeVO implements Identity {
139142

140143
// Real Constructor
141144
public VolumeVO(VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
142-
this.volumeType = type;
145+
this.volumeType = type.toString();
143146
this.name = name;
144147
this.dataCenterId = dcId;
145148
this.accountId = accountId;
@@ -150,7 +153,7 @@ public VolumeVO(VolumeType type, String name, long dcId, long domainId, long acc
150153
this.uuid = UUID.randomUUID().toString();
151154
}
152155

153-
public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, VolumeType vType) {
156+
public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, String vType) {
154157
this.name = name;
155158
this.accountId = accountId;
156159
this.domainId = domainId;
@@ -160,7 +163,7 @@ public VolumeVO(String name, long dcId, long podId, long accountId, long domainI
160163
this.size = size;
161164
this.podId = podId;
162165
this.dataCenterId = dcId;
163-
this.volumeType = vType;
166+
this.volumeType = vType.toString();
164167
this.state = VolumeState.Allocated;
165168
this.recreatable = false;
166169
this.uuid = UUID.randomUUID().toString();
@@ -267,7 +270,7 @@ public void setDeviceId(Long deviceId) {
267270
this.deviceId = deviceId;
268271
}
269272

270-
public VolumeType getVolumeType() {
273+
public String getVolumeType() {
271274
return volumeType;
272275
}
273276

@@ -311,7 +314,7 @@ public void setDataCenterId(long dataCenterId) {
311314
this.dataCenterId = dataCenterId;
312315
}
313316

314-
public void setVolumeType(VolumeType type) {
317+
public void setVolumeType(String type) {
315318
volumeType = type;
316319
}
317320

@@ -430,5 +433,13 @@ public String getUuid() {
430433
public void setUuid(String uuid) {
431434
this.uuid = uuid;
432435
}
436+
437+
public String getDiskType() {
438+
return diskType;
439+
}
440+
441+
public void setDiskType(String type) {
442+
diskType = type;
443+
}
433444
}
434445

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.apache.cloudstack.storage.volume.disktype;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
@Component
6+
public class QCOW2 extends VolumeDiskTypeBase {
7+
public QCOW2() {
8+
this.type = "QCOW2";
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.apache.cloudstack.storage.volume.disktype;
2+
3+
public class Unknown extends VolumeDiskTypeBase {
4+
public Unknown() {
5+
this.type = "Unknown";
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.apache.cloudstack.storage.volume.disktype;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
@Component
6+
public class VHD extends VolumeDiskTypeBase {
7+
public VHD() {
8+
this.type = "VHD";
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.apache.cloudstack.storage.volume.disktype;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
@Component
6+
public class VMDK extends VolumeDiskTypeBase {
7+
public VMDK() {
8+
this.type = "VMDK";
9+
}
10+
}

0 commit comments

Comments
 (0)