mirror of https://github.com/apache/cloudstack.git
add more classes
This commit is contained in:
parent
fff6fde823
commit
0debd8a393
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.cloudstack.storage;
|
||||
|
||||
public interface EndPoint {
|
||||
public String getEndPoint();
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.volume.Volume;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeDao;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeVO;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType;
|
||||
|
||||
public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
|
||||
protected PrimaryDataStoreDriver driver;
|
||||
protected List<VolumeDiskType> supportedDiskTypes;
|
||||
@Inject
|
||||
VolumeDao volumeDao;
|
||||
public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, List<VolumeDiskType> types) {
|
||||
this.driver = driver;
|
||||
this.supportedDiskTypes = types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Volume getVolume(long id) {
|
||||
VolumeVO volumeVO = volumeDao.findById(id);
|
||||
Volume vol = new Volume(this, volumeVO);
|
||||
return vol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Volume> getVolumes() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteVolume(long id) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Volume createVolume(long id, VolumeDiskType diskType) {
|
||||
Volume vol = this.getVolume(id);
|
||||
if (vol == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.getSupportedDiskTypes().contains(diskType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
vol.setVolumeDiskType(diskType);
|
||||
this.driver.createVolume(vol);
|
||||
vol.update();
|
||||
return vol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeDiskType> getSupportedDiskTypes() {
|
||||
return this.supportedDiskTypes;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,11 +18,15 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.storage.volume.Volume;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType;
|
||||
|
||||
public interface PrimaryDataStore {
|
||||
Volume getVolume(long id);
|
||||
List<Volume> getVolumes();
|
||||
boolean deleteVolume(long id);
|
||||
Volume createVolume(long id, VolumeDiskType diskType);
|
||||
List<VolumeDiskType> getSupportedDiskTypes();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package org.apache.cloudstack.storage.datastore.driver;
|
||||
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.volume.Volume;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DefaultPrimaryDataStoreDriverImpl implements
|
||||
PrimaryDataStoreDriver {
|
||||
|
||||
@Override
|
||||
public boolean createVolume(Volume vol) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteVolume(Volume vo) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String grantAccess(Volume vol, EndPoint ep) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revokeAccess(Volume vol, EndPoint ep) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.apache.cloudstack.storage.datastore.driver;
|
||||
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.volume.Volume;
|
||||
|
||||
public interface PrimaryDataStoreDriver {
|
||||
boolean createVolume(Volume vol);
|
||||
boolean deleteVolume(Volume vo);
|
||||
String grantAccess(Volume vol, EndPoint ep);
|
||||
boolean revokeAccess(Volume vol, EndPoint ep);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
|
||||
|
||||
public class DefaultPrimaryDatastoreProviderImpl implements
|
||||
PrimaryDataStoreProvider {
|
||||
@Inject
|
||||
public PrimaryDataStoreDriver driver;
|
||||
@Override
|
||||
public PrimaryDataStore getDataStore(String dataStoreId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
|
||||
public interface PrimaryDataStoreProvider {
|
||||
public PrimaryDataStore getDataStore(String dataStoreId);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
public interface PrimaryDataStoreProviderManager {
|
||||
public PrimaryDataStoreProvider getDataStoreProvider(String providerUuid);
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@ package org.apache.cloudstack.storage.volume;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeDao;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeVO;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskTypeHelper;
|
||||
|
|
@ -13,13 +15,15 @@ import com.cloud.utils.fsm.StateObject;
|
|||
|
||||
public class Volume implements StateObject<VolumeState> {
|
||||
protected VolumeVO volumeVO;
|
||||
protected DataStore dataStore;
|
||||
protected PrimaryDataStore dataStore;
|
||||
@Inject
|
||||
VolumeDiskTypeHelper diskTypeHelper;
|
||||
@Inject
|
||||
VolumeTypeHelper volumeTypeHelper;
|
||||
@Inject
|
||||
VolumeDao volumeDao;
|
||||
|
||||
public Volume(DataStore dataStore, VolumeVO volumeVO) {
|
||||
public Volume(PrimaryDataStore dataStore, VolumeVO volumeVO) {
|
||||
this.volumeVO = volumeVO;
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
|
|
@ -29,7 +33,7 @@ public class Volume implements StateObject<VolumeState> {
|
|||
return volumeVO.getState();
|
||||
}
|
||||
|
||||
public DataStore getDataStore() {
|
||||
public PrimaryDataStore getDataStore() {
|
||||
return dataStore;
|
||||
}
|
||||
|
||||
|
|
@ -44,4 +48,13 @@ public class Volume implements StateObject<VolumeState> {
|
|||
public VolumeType getType() {
|
||||
return volumeTypeHelper.getType(volumeVO.getVolumeType());
|
||||
}
|
||||
|
||||
public void setVolumeDiskType(VolumeDiskType type) {
|
||||
volumeVO.setDiskType(type.toString());
|
||||
}
|
||||
|
||||
public void update() {
|
||||
volumeDao.update(volumeVO.getId(), volumeVO);
|
||||
volumeVO = volumeDao.findById(volumeVO.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
package org.apache.cloudstack.storage.volume.disktype;
|
||||
|
||||
public interface VolumeDiskType {
|
||||
boolean equals(String diskType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,23 @@ public class VolumeDiskTypeBase implements VolumeDiskType {
|
|||
protected String type = "Unknown";
|
||||
|
||||
@Override
|
||||
public boolean equals(String diskType) {
|
||||
if (getType().equalsIgnoreCase(diskType)) {
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that instanceof String) {
|
||||
if (getType().equalsIgnoreCase((String)that)) {
|
||||
return true;
|
||||
}
|
||||
} else if (that instanceof VolumeDiskTypeBase) {
|
||||
VolumeDiskTypeBase th = (VolumeDiskTypeBase)that;
|
||||
if (this.getType().equalsIgnoreCase(th.getType())) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
<context:annotation-config />
|
||||
<context:component-scan base-package="org.apache.cloudstack.storage" />
|
||||
<context:component-scan base-package="com.cloud.utils.db" />
|
||||
<context:component-scan base-package="com.cloud.utils.component" />
|
||||
<context:component-scan base-package="com.cloud.storage.dao" />
|
||||
|
||||
<context:component-scan base-package=" com.cloud.upgrade.dao" />
|
||||
|
|
|
|||
|
|
@ -25,9 +25,13 @@ import java.util.LinkedList;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl;
|
||||
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
|
||||
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.VHD;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VMDK;
|
||||
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskTypeHelper;
|
||||
import org.apache.cloudstack.storage.volume.type.VolumeTypeHelper;
|
||||
import org.junit.Before;
|
||||
|
|
@ -36,11 +40,13 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.mockito.Mockito.*;
|
||||
|
||||
|
||||
import com.cloud.utils.component.ComponentInject;
|
||||
import com.cloud.utils.db.DB;
|
||||
|
||||
|
||||
|
|
@ -86,5 +92,16 @@ public class volumeServiceTest {
|
|||
public void test1() {
|
||||
System.out.println(volTypeHelper.getType("Root"));
|
||||
System.out.println(volDiskTypeHelper.getDiskType("vmdk"));
|
||||
assertFalse(new VMDK().equals(new VHD()));
|
||||
VMDK vmdk = new VMDK();
|
||||
assertTrue(vmdk.equals(vmdk));
|
||||
VMDK newvmdk = new VMDK();
|
||||
assertTrue(vmdk.equals(newvmdk));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticBean() {
|
||||
DefaultPrimaryDatastoreProviderImpl provider = ComponentInject.inject(DefaultPrimaryDatastoreProviderImpl.class);
|
||||
assertNotNull(provider.driver);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.cloud.utils.component;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ComponentInject {
|
||||
|
||||
private static AutowireCapableBeanFactory beanFactory;
|
||||
@Inject
|
||||
private void setbeanFactory(AutowireCapableBeanFactory bf) {
|
||||
ComponentInject.beanFactory = bf;
|
||||
}
|
||||
|
||||
public static <T> T inject(Class<T> clazz) {
|
||||
return beanFactory.createBean(clazz);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue