mirror of https://github.com/apache/cloudstack.git
add volume types
This commit is contained in:
parent
a388a748d0
commit
dcf3790e81
|
|
@ -1,17 +1,47 @@
|
|||
package org.apache.cloudstack.storage.volume;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeVO;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskTypeHelper;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeType;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeTypeHelper;
|
||||
|
||||
import com.cloud.utils.fsm.StateObject;
|
||||
|
||||
public class Volume implements StateObject<VolumeState>{
|
||||
private VolumeVO volumeVO;
|
||||
public class Volume implements StateObject<VolumeState> {
|
||||
protected VolumeVO volumeVO;
|
||||
protected DataStore dataStore;
|
||||
@Inject
|
||||
VolumeDiskTypeHelper diskTypeHelper;
|
||||
@Inject
|
||||
VolumeTypeHelper volumeTypeHelper;
|
||||
|
||||
public Volume(DataStore dataStore, VolumeVO volumeVO) {
|
||||
this.volumeVO = volumeVO;
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeState getState() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return volumeVO.getState();
|
||||
}
|
||||
|
||||
public DataStore getDataStore() {
|
||||
return dataStore;
|
||||
}
|
||||
|
||||
|
||||
public long getSize() {
|
||||
return volumeVO.getSize();
|
||||
}
|
||||
|
||||
public VolumeDiskType getDiskType() {
|
||||
return diskTypeHelper.getDiskType(volumeVO.getDiskType());
|
||||
}
|
||||
|
||||
public VolumeType getType() {
|
||||
return volumeTypeHelper.getType(volumeVO.getVolumeType());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.volume;
|
||||
|
||||
|
||||
import com.cloud.storage.Volume;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeType;
|
||||
|
||||
public interface VolumeService {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Volume allocateVolumeInDb(long size, VolumeType type);
|
||||
|
||||
/**
|
||||
* Creates the volume based on the given criteria
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,22 +18,13 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.volume;
|
||||
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeDao;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.upgrade.dao.VersionDao;
|
||||
import com.cloud.upgrade.dao.VersionVO;
|
||||
import com.cloud.utils.db.DB;
|
||||
|
||||
@Component
|
||||
@Service
|
||||
public class VolumeServiceImpl implements VolumeService {
|
||||
@Autowired
|
||||
VolumeDao _volumeDao;
|
||||
@Override
|
||||
public Volume createVolume(long volumeId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
@ -43,8 +34,6 @@ public class VolumeServiceImpl implements VolumeService {
|
|||
@DB
|
||||
@Override
|
||||
public boolean deleteVolume(long volumeId) {
|
||||
VolumeVO vol = new VolumeVO(VolumeType.ROOT, "root", 1, 1,1 ,1,1);
|
||||
_volumeDao.persist(vol);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -71,4 +60,10 @@ public class VolumeServiceImpl implements VolumeService {
|
|||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Volume allocateVolumeInDb(long size, VolumeType type) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||
import org.apache.cloudstack.storage.volume.Volume;
|
||||
import org.apache.cloudstack.storage.volume.VolumeEvent;
|
||||
import org.apache.cloudstack.storage.volume.VolumeState;
|
||||
import org.apache.cloudstack.storage.volume.VolumeType;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeType;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
|
|
@ -76,4 +76,6 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<VolumeSt
|
|||
List<VolumeVO> findReadyRootVolumesByInstance(long instanceId);
|
||||
|
||||
List<Long> listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId);
|
||||
|
||||
VolumeVO allocVolume(long size, VolumeType type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@ import java.util.List;
|
|||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.cloudstack.storage.volume.Volume;
|
||||
import org.apache.cloudstack.storage.volume.VolumeEvent;
|
||||
import org.apache.cloudstack.storage.volume.VolumeState;
|
||||
import org.apache.cloudstack.storage.volume.VolumeType;
|
||||
import org.apache.cloudstack.storage.volume.type.RootDisk;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeType;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -104,7 +106,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("poolId", poolId);
|
||||
sc.setParameters("notDestroyed", VolumeState.Destroy);
|
||||
sc.setParameters("vType", VolumeType.ROOT.toString());
|
||||
sc.setParameters("vType", new RootDisk().toString());
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +148,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("instanceId", instanceId);
|
||||
sc.setParameters("state", VolumeState.Ready);
|
||||
sc.setParameters("vType", VolumeType.ROOT);
|
||||
sc.setParameters("vType", new RootDisk().toString());
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
|
@ -413,4 +415,11 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
txn.commit();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public VolumeVO allocVolume(long size, VolumeType type) {
|
||||
VolumeVO vol = new VolumeVO();
|
||||
return vol;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ import javax.persistence.Temporal;
|
|||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.cloudstack.storage.volume.VolumeState;
|
||||
import org.apache.cloudstack.storage.volume.VolumeType;
|
||||
import org.apache.cloudstack.storage.volume.disktype.Unknown;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeType;
|
||||
|
||||
import com.cloud.api.Identity;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
|
@ -104,13 +105,15 @@ public class VolumeVO implements Identity {
|
|||
String firstSnapshotBackupUuid;
|
||||
|
||||
@Column(name = "volume_type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
VolumeType volumeType = VolumeType.UNKNOWN;
|
||||
String volumeType = "UNKNOWN";
|
||||
|
||||
@Column(name = "pool_type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
StoragePoolType poolType;
|
||||
|
||||
|
||||
@Column(name = "disk_type")
|
||||
String diskType = new Unknown().toString();
|
||||
|
||||
@Column(name = GenericDao.REMOVED_COLUMN)
|
||||
Date removed;
|
||||
|
||||
|
|
@ -139,7 +142,7 @@ public class VolumeVO implements Identity {
|
|||
|
||||
// Real Constructor
|
||||
public VolumeVO(VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
|
||||
this.volumeType = type;
|
||||
this.volumeType = type.toString();
|
||||
this.name = name;
|
||||
this.dataCenterId = dcId;
|
||||
this.accountId = accountId;
|
||||
|
|
@ -150,7 +153,7 @@ public class VolumeVO implements Identity {
|
|||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, VolumeType vType) {
|
||||
public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, String vType) {
|
||||
this.name = name;
|
||||
this.accountId = accountId;
|
||||
this.domainId = domainId;
|
||||
|
|
@ -160,7 +163,7 @@ public class VolumeVO implements Identity {
|
|||
this.size = size;
|
||||
this.podId = podId;
|
||||
this.dataCenterId = dcId;
|
||||
this.volumeType = vType;
|
||||
this.volumeType = vType.toString();
|
||||
this.state = VolumeState.Allocated;
|
||||
this.recreatable = false;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
|
|
@ -267,7 +270,7 @@ public class VolumeVO implements Identity {
|
|||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public VolumeType getVolumeType() {
|
||||
public String getVolumeType() {
|
||||
return volumeType;
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +314,7 @@ public class VolumeVO implements Identity {
|
|||
this.dataCenterId = dataCenterId;
|
||||
}
|
||||
|
||||
public void setVolumeType(VolumeType type) {
|
||||
public void setVolumeType(String type) {
|
||||
volumeType = type;
|
||||
}
|
||||
|
||||
|
|
@ -430,5 +433,13 @@ public class VolumeVO implements Identity {
|
|||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getDiskType() {
|
||||
return diskType;
|
||||
}
|
||||
|
||||
public void setDiskType(String type) {
|
||||
diskType = type;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package org.apache.cloudstack.storage.volume.disktype;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class QCOW2 extends VolumeDiskTypeBase {
|
||||
public QCOW2() {
|
||||
this.type = "QCOW2";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package org.apache.cloudstack.storage.volume.disktype;
|
||||
|
||||
public class Unknown extends VolumeDiskTypeBase {
|
||||
public Unknown() {
|
||||
this.type = "Unknown";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.apache.cloudstack.storage.volume.disktype;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VHD extends VolumeDiskTypeBase {
|
||||
public VHD() {
|
||||
this.type = "VHD";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.apache.cloudstack.storage.volume.disktype;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VMDK extends VolumeDiskTypeBase {
|
||||
public VMDK() {
|
||||
this.type = "VMDK";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.cloudstack.storage.volume.disktype;
|
||||
|
||||
public interface VolumeDiskType {
|
||||
boolean equals(String diskType);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.apache.cloudstack.storage.volume.disktype;
|
||||
|
||||
public class VolumeDiskTypeBase implements VolumeDiskType {
|
||||
protected String type = "Unknown";
|
||||
|
||||
@Override
|
||||
public boolean equals(String diskType) {
|
||||
if (getType().equalsIgnoreCase(diskType)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getType();
|
||||
}
|
||||
|
||||
protected String getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.apache.cloudstack.storage.volume.disktype;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VolumeDiskTypeHelper {
|
||||
@Inject
|
||||
protected List<VolumeDiskType> diskTypes;
|
||||
protected VolumeDiskType defaultType = new Unknown();
|
||||
|
||||
public VolumeDiskType getDiskType(String type) {
|
||||
for (VolumeDiskType diskType : diskTypes) {
|
||||
if (diskType.equals(type)) {
|
||||
return diskType;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultType;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.apache.cloudstack.storage.volume.type;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DataDisk extends VolumeTypeBase {
|
||||
public DataDisk() {
|
||||
this.type = "DataDisk";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.apache.cloudstack.storage.volume.type;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Iso extends VolumeTypeBase {
|
||||
public Iso() {
|
||||
this.type = "iso";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.apache.cloudstack.storage.volume.type;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RootDisk extends VolumeTypeBase {
|
||||
public RootDisk() {
|
||||
this.type = "Root";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.apache.cloudstack.storage.volume.type;
|
||||
|
||||
public class Unknown extends VolumeTypeBase {
|
||||
public Unknown() {
|
||||
this.type = "Unknown";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,12 +16,8 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.volume;
|
||||
package org.apache.cloudstack.storage.volume.type;
|
||||
|
||||
public enum VolumeType {
|
||||
UNKNOWN,
|
||||
ROOT,
|
||||
SWAP,
|
||||
DATADISK,
|
||||
ISO
|
||||
public interface VolumeType {
|
||||
boolean equals(String type);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.apache.cloudstack.storage.volume.type;
|
||||
|
||||
public class VolumeTypeBase implements VolumeType {
|
||||
protected String type = "Unknown";
|
||||
|
||||
@Override
|
||||
public boolean equals(String type) {
|
||||
if (this.type.equalsIgnoreCase(type)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.apache.cloudstack.storage.volume.type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VolumeTypeHelper {
|
||||
@Inject
|
||||
private List<VolumeType> types;
|
||||
private VolumeType defaultType = new Unknown();
|
||||
|
||||
public VolumeType getType(String type) {
|
||||
for (VolumeType ty : types) {
|
||||
if (ty.equals(type)) {
|
||||
return ty;
|
||||
}
|
||||
}
|
||||
return defaultType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,6 +28,8 @@ import javax.inject.Inject;
|
|||
import org.apache.cloudstack.storage.volume.VolumeMotionService;
|
||||
import org.apache.cloudstack.storage.volume.VolumeService;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeDao;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskTypeHelper;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeTypeHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -51,13 +53,15 @@ public class volumeServiceTest {
|
|||
protected VolumeDao volumeDao;
|
||||
@Autowired
|
||||
protected VolumeMotionService vmotion;
|
||||
|
||||
@Autowired
|
||||
protected VolumeTypeHelper volTypeHelper;
|
||||
@Inject
|
||||
protected VolumeDiskTypeHelper volDiskTypeHelper;
|
||||
@Before
|
||||
public void setUp() {
|
||||
Mockito.when(vmotion.copyVolume(null, null)).thenReturn(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DB
|
||||
public void test() {
|
||||
assertTrue(volService.deleteVolume(1) != false);
|
||||
|
|
@ -77,4 +81,10 @@ public class volumeServiceTest {
|
|||
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
System.out.println(volTypeHelper.getType("Root"));
|
||||
System.out.println(volDiskTypeHelper.getDiskType("vmdk"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue