create template/primary data store is done

This commit is contained in:
Edison Su 2012-11-20 18:56:51 -08:00
parent 573d13dd7c
commit 550f4fbcdc
46 changed files with 682 additions and 189 deletions

View File

@ -145,6 +145,7 @@
<mainClass>com.cloud.upgrade.DatabaseCreator</mainClass>
<arguments>
<argument>${basedir}/target/db/create-schema.sql</argument>
<argument>${basedir}/target/db/4.1-new-db-schema.sql</argument>
<argument>${basedir}/target/db/create-schema-premium.sql</argument>
<argument>com.cloud.upgrade.DatabaseUpgradeChecker</argument>
</arguments>

View File

@ -82,4 +82,5 @@ public interface VolumeEntity extends CloudStackEntity {
VolumeType getType();
StorageEntity getDataStore();
void setPath(String path);
boolean createVolumeFromTemplate(long dataStoreId, VolumeDiskType diskType, TemplateEntity template);
}

View File

@ -110,7 +110,7 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
if (!ds.contains(volume)) {
throw new CloudRuntimeException("volume: " + volume + "doesn't exist on backup storage");
}
/*
VolumeProfile vp = ds.prepareVolume(volume, destStore);
VolumeStrategy vs = destStore.getVolumeStrategy();
@ -130,12 +130,15 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
txn.commit();
return destVolume;
*/
return null;
}
@DB
protected Volume migrateVolume(VolumeVO volume, DataStore srcStore, DataStore destStore, String reservationId) throws NoTransitionException {
Transaction txn = Transaction.currentTxn();
txn.start();
/*
volume.setReservationId(reservationId);
volume = _volumeMgr.processEvent(volume, Volume.Event.MigrationRequested);
Volume destVolume = _volumeMgr.allocateDuplicateVolume(volume);
@ -156,12 +159,15 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
_volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded);
return destVolume;
*/
return null;
}
@DB
protected Volume recreateVolume(VolumeVO srcVolume, DataStore destStore, String reservationId) throws NoTransitionException {
Transaction txn = Transaction.currentTxn();
txn.start();
/*
srcVolume.setReservationId(reservationId);
srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.CopyRequested);
Volume destVolume = _volumeMgr.allocateDuplicateVolume(srcVolume);
@ -185,10 +191,13 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
_volumeMgr.processEvent(srcVolume, Volume.Event.OperationSucceeded);
return destVolume;
*/
return null;
}
protected Volume createVolumeOnStorage(Volume volume, DataStore destStore, String reservationId) throws NoTransitionException {
VolumeStrategy vs = destStore.getVolumeStrategy();
/*
volume.setReservationId(reservationId);
volume = _volumeMgr.processEvent(volume, Volume.Event.CreateRequested);
@ -208,6 +217,8 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded);
return volume;
*/
return null;
}
@DB

View File

@ -12,7 +12,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.storage.HypervisorHostEndPoint;
import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
import org.apache.cloudstack.storage.image.TemplateInfo;
import org.apache.cloudstack.storage.image.TemplateObject;
@ -38,16 +38,16 @@ import edu.emory.mathcs.backport.java.util.Collections;
public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreImpl.class);
protected PrimaryDataStoreDriver driver;
protected DataStoreVO pdsv;
protected PrimaryDataStoreVO pdsv;
protected PrimaryDataStoreInfo pdsInfo;
@Inject
private VolumeDao volumeDao;
@Inject
//@Inject
private HostDao hostDao;
@Inject
TemplatePrimaryDataStoreManager templatePrimaryStoreMgr;
public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, DataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, PrimaryDataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
this.driver = driver;
this.pdsv = pdsv;
this.pdsInfo = pdsInfo;
@ -56,7 +56,7 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
@Override
public VolumeInfo getVolume(long id) {
VolumeVO volumeVO = volumeDao.findById(id);
VolumeObject vol = new VolumeObject(this, volumeVO);
VolumeObject vol = VolumeObject.getVolumeObject(this, volumeVO);
return vol;
}
@ -155,8 +155,7 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
@Override
public long getId() {
// TODO Auto-generated method stub
return 0;
return pdsv.getId();
}
@Override

View File

@ -25,19 +25,19 @@ import org.apache.cloudstack.storage.datastore.DataStoreStatus;
import com.cloud.utils.db.GenericDao;
public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
public interface PrimaryDataStoreDao extends GenericDao<PrimaryDataStoreVO, Long> {
/**
* @param datacenterId
* -- the id of the datacenter (availability zone)
*/
List<DataStoreVO> listByDataCenterId(long datacenterId);
List<PrimaryDataStoreVO> listByDataCenterId(long datacenterId);
/**
* @param datacenterId
* -- the id of the datacenter (availability zone)
*/
List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId);
List<PrimaryDataStoreVO> listBy(long datacenterId, long podId, Long clusterId);
/**
* Set capacity of storage pool in bytes
@ -59,7 +59,7 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
*/
void updateAvailable(long id, long available);
DataStoreVO persist(DataStoreVO pool, Map<String, String> details);
PrimaryDataStoreVO persist(PrimaryDataStoreVO pool, Map<String, String> details);
/**
* Find pool by name.
@ -68,7 +68,7 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
* name of pool.
* @return the single StoragePoolVO
*/
List<DataStoreVO> findPoolByName(String name);
List<PrimaryDataStoreVO> findPoolByName(String name);
/**
* Find pools by the pod that matches the details.
@ -79,9 +79,9 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
* details to match. All must match for the pool to be returned.
* @return List of StoragePoolVO
*/
List<DataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details);
List<PrimaryDataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details);
List<DataStoreVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared);
List<PrimaryDataStoreVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared);
/**
* Find pool by UUID.
@ -90,13 +90,13 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
* uuid of pool.
* @return the single StoragePoolVO
*/
DataStoreVO findPoolByUUID(String uuid);
PrimaryDataStoreVO findPoolByUUID(String uuid);
List<DataStoreVO> listByStorageHost(String hostFqdnOrIp);
List<PrimaryDataStoreVO> listByStorageHost(String hostFqdnOrIp);
DataStoreVO findPoolByHostPath(long dcId, Long podId, String host, String path, String uuid);
PrimaryDataStoreVO findPoolByHostPath(long dcId, Long podId, String host, String path, String uuid);
List<DataStoreVO> listPoolByHostPath(String host, String path);
List<PrimaryDataStoreVO> listPoolByHostPath(String host, String path);
void updateDetails(long poolId, Map<String, String> details);
@ -104,13 +104,13 @@ public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
List<String> searchForStoragePoolDetails(long poolId, String value);
List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid);
List<PrimaryDataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid);
List<DataStoreVO> listByStatus(DataStoreStatus status);
List<PrimaryDataStoreVO> listByStatus(DataStoreStatus status);
long countPoolsByStatus(DataStoreStatus... statuses);
List<DataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status);
List<PrimaryDataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status);
List<DataStoreVO> listPoolsByCluster(long clusterId);
List<PrimaryDataStoreVO> listPoolsByCluster(long clusterId);
}

View File

@ -47,12 +47,12 @@ import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.exception.CloudRuntimeException;
@Component
public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> implements PrimaryDataStoreDao {
protected final SearchBuilder<DataStoreVO> AllFieldSearch;
protected final SearchBuilder<DataStoreVO> DcPodSearch;
protected final SearchBuilder<DataStoreVO> DcPodAnyClusterSearch;
protected final SearchBuilder<DataStoreVO> DeleteLvmSearch;
protected final GenericSearchBuilder<DataStoreVO, Long> StatusCountSearch;
public class PrimaryDataStoreDaoImpl extends GenericDaoBase<PrimaryDataStoreVO, Long> implements PrimaryDataStoreDao {
protected final SearchBuilder<PrimaryDataStoreVO> AllFieldSearch;
protected final SearchBuilder<PrimaryDataStoreVO> DcPodSearch;
protected final SearchBuilder<PrimaryDataStoreVO> DcPodAnyClusterSearch;
protected final SearchBuilder<PrimaryDataStoreVO> DeleteLvmSearch;
protected final GenericSearchBuilder<PrimaryDataStoreVO, Long> StatusCountSearch;
protected final PrimaryDataStoreDetailsDao _detailsDao = null;
@ -105,73 +105,73 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
}
@Override
public List<DataStoreVO> findPoolByName(String name) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<PrimaryDataStoreVO> findPoolByName(String name) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("name", name);
return listIncludingRemovedBy(sc);
}
@Override
public DataStoreVO findPoolByUUID(String uuid) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public PrimaryDataStoreVO findPoolByUUID(String uuid) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("uuid", uuid);
return findOneIncludingRemovedBy(sc);
}
@Override
public List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<PrimaryDataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("uuid", uuid);
return listBy(sc);
}
@Override
public List<DataStoreVO> listByDataCenterId(long datacenterId) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<PrimaryDataStoreVO> listByDataCenterId(long datacenterId) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("datacenterId", datacenterId);
return listBy(sc);
}
@Override
public void updateAvailable(long id, long available) {
DataStoreVO pool = createForUpdate(id);
PrimaryDataStoreVO pool = createForUpdate(id);
pool.setAvailableBytes(available);
update(id, pool);
}
@Override
public void updateCapacity(long id, long capacity) {
DataStoreVO pool = createForUpdate(id);
PrimaryDataStoreVO pool = createForUpdate(id);
pool.setCapacityBytes(capacity);
update(id, pool);
}
@Override
public List<DataStoreVO> listByStorageHost(String hostFqdnOrIp) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<PrimaryDataStoreVO> listByStorageHost(String hostFqdnOrIp) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("hostAddress", hostFqdnOrIp);
return listIncludingRemovedBy(sc);
}
@Override
public List<DataStoreVO> listByStatus(DataStoreStatus status) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<PrimaryDataStoreVO> listByStatus(DataStoreStatus status) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("status", status);
return listBy(sc);
}
@Override
public List<DataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<PrimaryDataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("status", status);
sc.setParameters("datacenterId", dcId);
return listBy(sc);
}
@Override
public DataStoreVO findPoolByHostPath(long datacenterId, Long podId, String host, String path, String uuid) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public PrimaryDataStoreVO findPoolByHostPath(long datacenterId, Long podId, String host, String path, String uuid) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("hostAddress", host);
sc.setParameters("path", path);
sc.setParameters("datacenterId", datacenterId);
@ -182,16 +182,16 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
}
@Override
public List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId) {
public List<PrimaryDataStoreVO> listBy(long datacenterId, long podId, Long clusterId) {
if (clusterId != null) {
SearchCriteria<DataStoreVO> sc = DcPodSearch.create();
SearchCriteria<PrimaryDataStoreVO> sc = DcPodSearch.create();
sc.setParameters("datacenterId", datacenterId);
sc.setParameters("podId", podId);
sc.setParameters("cluster", clusterId);
return listBy(sc);
} else {
SearchCriteria<DataStoreVO> sc = DcPodAnyClusterSearch.create();
SearchCriteria<PrimaryDataStoreVO> sc = DcPodAnyClusterSearch.create();
sc.setParameters("datacenterId", datacenterId);
sc.setParameters("podId", podId);
return listBy(sc);
@ -199,16 +199,16 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
}
@Override
public List<DataStoreVO> listPoolByHostPath(String host, String path) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<PrimaryDataStoreVO> listPoolByHostPath(String host, String path) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("hostAddress", host);
sc.setParameters("path", path);
return listBy(sc);
}
public DataStoreVO listById(Integer id) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public PrimaryDataStoreVO listById(Integer id) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("id", id);
return findOneIncludingRemovedBy(sc);
@ -216,7 +216,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
@Override
@DB
public DataStoreVO persist(DataStoreVO pool, Map<String, String> details) {
public PrimaryDataStoreVO persist(PrimaryDataStoreVO pool, Map<String, String> details) {
Transaction txn = Transaction.currentTxn();
txn.start();
pool = super.persist(pool);
@ -232,7 +232,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
@DB
@Override
public List<DataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details) {
public List<PrimaryDataStoreVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details) {
StringBuilder sql = new StringBuilder(DetailsSqlPrefix);
if (clusterId != null) {
sql.append("storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL) AND (");
@ -254,7 +254,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
}
pstmt.setInt(i++, details.size());
ResultSet rs = pstmt.executeQuery();
List<DataStoreVO> pools = new ArrayList<DataStoreVO>();
List<PrimaryDataStoreVO> pools = new ArrayList<PrimaryDataStoreVO>();
while (rs.next()) {
pools.add(toEntityBean(rs, false));
}
@ -273,8 +273,8 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
}
@Override
public List<DataStoreVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) {
List<DataStoreVO> storagePools = null;
public List<PrimaryDataStoreVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) {
List<PrimaryDataStoreVO> storagePools = null;
if (tags == null || tags.length == 0) {
storagePools = listBy(dcId, podId, clusterId);
} else {
@ -285,8 +285,8 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
if (shared == null) {
return storagePools;
} else {
List<DataStoreVO> filteredStoragePools = new ArrayList<DataStoreVO>(storagePools);
for (DataStoreVO pool : storagePools) {
List<PrimaryDataStoreVO> filteredStoragePools = new ArrayList<PrimaryDataStoreVO>(storagePools);
for (PrimaryDataStoreVO pool : storagePools) {
/*
* if (shared != pool.isShared()) {
* filteredStoragePools.remove(pool); }
@ -357,8 +357,8 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<DataStoreVO, Long> i
}
@Override
public List<DataStoreVO> listPoolsByCluster(long clusterId) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
public List<PrimaryDataStoreVO> listPoolsByCluster(long clusterId) {
SearchCriteria<PrimaryDataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("clusterId", clusterId);
return listBy(sc);

View File

@ -21,5 +21,5 @@ package org.apache.cloudstack.storage.datastore.db;
import com.cloud.utils.db.GenericDao;
public interface PrimaryDataStoreProviderDao extends GenericDao<PrimaryDataStoreProviderVO, Long> {
public PrimaryDataStoreProviderVO findByName(String name);
}

View File

@ -21,8 +21,18 @@ package org.apache.cloudstack.storage.datastore.db;
import org.springframework.stereotype.Component;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.db.SearchCriteria.Op;
@Component
class PrimaryDataStoreProviderDaoImpl extends GenericDaoBase<PrimaryDataStoreProviderVO, Long> implements PrimaryDataStoreProviderDao {
@Override
public PrimaryDataStoreProviderVO findByName(String name) {
SearchCriteriaService<PrimaryDataStoreProviderVO, PrimaryDataStoreProviderVO> sc = SearchCriteria2.create(PrimaryDataStoreProviderVO.class);
sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
return sc.find();
}
}

View File

@ -25,14 +25,25 @@ import javax.persistence.Table;
import javax.persistence.TableGenerator;
@Entity
@Table(name = "data_store_provider")
@Table(name = "primary_data_store_provider")
public class PrimaryDataStoreProviderVO {
@Id
@TableGenerator(name = "data_store_provider_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "data_store_provider_seq", allocationSize = 1)
@Column(name = "id", updatable = false, nullable = false)
private long id;
@Column(name = "name", nullable = false)
private String name;
public long getId() {
return id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -40,7 +40,7 @@ import com.cloud.utils.db.GenericDao;
@Entity
@Table(name = "storage_pool")
public class DataStoreVO implements Identity {
public class PrimaryDataStoreVO implements Identity {
@Id
@TableGenerator(name = "storage_pool_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "storage_pool_seq", allocationSize = 1)
@Column(name = "id", updatable = false, nullable = false)
@ -81,11 +81,8 @@ public class DataStoreVO implements Identity {
@Enumerated(value = EnumType.STRING)
private DataStoreStatus status;
@Column(name = "storage_provider", updatable = true, nullable = false)
private Long storageProvider;
@Column(name = "storage_type", nullable = false)
private String storageType;
@Column(name = "storage_provider_id", updatable = true, nullable = false)
private Long storageProviderId;
@Column(name = "host_address")
private String hostAddress;
@ -110,7 +107,7 @@ public class DataStoreVO implements Identity {
return status;
}
public DataStoreVO() {
public PrimaryDataStoreVO() {
// TODO Auto-generated constructor stub
}
@ -125,6 +122,10 @@ public class DataStoreVO implements Identity {
public String getPoolType() {
return protocol;
}
public void setPoolType(String protocol) {
this.protocol = protocol;
}
public Date getCreated() {
return created;
@ -147,19 +148,11 @@ public class DataStoreVO implements Identity {
}
public Long getStorageProviderId() {
return storageProvider;
return storageProviderId;
}
public void setStorageProviderId(Long provider) {
storageProvider = provider;
}
public String getStorageType() {
return storageType;
}
public void setStorageType(String type) {
storageType = type;
storageProviderId = provider;
}
public long getCapacityBytes() {
@ -185,6 +178,10 @@ public class DataStoreVO implements Identity {
public String getHostAddress() {
return hostAddress;
}
public void setHostAddress(String host) {
this.hostAddress = host;
}
public String getPath() {
return path;
@ -225,6 +222,10 @@ public class DataStoreVO implements Identity {
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public Long getPodId() {
return podId;
@ -236,10 +237,10 @@ public class DataStoreVO implements Identity {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof DataStoreVO) || obj == null) {
if (!(obj instanceof PrimaryDataStoreVO) || obj == null) {
return false;
}
DataStoreVO that = (DataStoreVO) obj;
PrimaryDataStoreVO that = (PrimaryDataStoreVO) obj;
return this.id == that.id;
}

View File

@ -18,17 +18,76 @@
*/
package org.apache.cloudstack.storage.datastore.lifecycle;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
import org.springframework.stereotype.Component;
@Component
public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle {
private final PrimaryDataStoreProvider provider;
protected PrimaryDataStoreDao dataStoreDao;
public DefaultPrimaryDataStoreLifeCycleImpl(PrimaryDataStoreProvider provider, PrimaryDataStoreDao dataStoreDao) {
this.provider = provider;
this.dataStoreDao = dataStoreDao;
}
protected class DataStoreUrlParser {
private String schema;
private String host;
private String path;
private int port;
public DataStoreUrlParser(String url) {
try {
URI uri = new URI(url);
schema = uri.getScheme();
host = uri.getHost();
path = uri.getPath();
port = (uri.getPort() == -1) ? 0 : uri.getPort();
} catch (URISyntaxException e) {
}
}
public String getSchema() {
return this.schema;
}
public String getHost() {
return this.host;
}
public String getPath() {
return this.path;
}
public int getPort() {
return this.port;
}
}
@Override
public boolean registerDataStore(Map<String, String> dsInfos) {
// TODO Auto-generated method stub
return false;
public PrimaryDataStoreInfo registerDataStore(Map<String, String> dsInfos) {
DataStoreUrlParser parser = new DataStoreUrlParser(dsInfos.get("url"));
PrimaryDataStoreVO dataStore = new PrimaryDataStoreVO();
dataStore.setName(dsInfos.get("name"));
dataStore.setPoolType(parser.getSchema());
dataStore.setPort(parser.port);
dataStore.setDataCenterId(Integer.parseInt(dsInfos.get("dcId")));
dataStore.setHostAddress(parser.getHost());
dataStore.setPath(parser.getPath());
dataStore.setStorageProviderId(this.provider.getId());
dataStore = dataStoreDao.persist(dataStore);
//TODO: add extension point for each data store
return this.provider.getDataStore(dataStore.getId());
}
@Override

View File

@ -20,8 +20,10 @@ package org.apache.cloudstack.storage.datastore.lifecycle;
import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
public interface PrimaryDataStoreLifeCycle {
public boolean registerDataStore(Map<String, String> dsInfos);
public PrimaryDataStoreInfo registerDataStore(Map<String, String> dsInfos);
public boolean attach(long scope);

View File

@ -21,7 +21,7 @@ package org.apache.cloudstack.storage.datastore.manager;
import javax.inject.Inject;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
@ -40,7 +40,7 @@ public class DefaultPrimaryDataStoreManagerImpl implements PrimaryDataStoreManag
@Override
public PrimaryDataStore getPrimaryDataStore(long dataStoreId) {
DataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId);
PrimaryDataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId);
Long providerId = dataStoreVO.getStorageProviderId();
PrimaryDataStoreProvider provider = providerManager.getDataStoreProvider(providerId);
PrimaryDataStore dataStore = provider.getDataStore(dataStoreId);

View File

@ -1,31 +1,43 @@
package org.apache.cloudstack.storage.datastore.provider;
import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl;
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
import org.apache.cloudstack.storage.datastore.lifecycle.DefaultPrimaryDataStoreLifeCycleImpl;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.lifecycle.DefaultPrimaryDataStoreLifeCycle;
import org.springframework.stereotype.Component;
import com.cloud.utils.component.ComponentInject;
@Component
public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProvider {
private final String providerName = "default primary data store provider";
protected PrimaryDataStoreDriver driver;
@Inject
public PrimaryDataStoreDao dataStoreDao;
private PrimaryDataStoreProviderVO provider;
private final PrimaryDataStoreDao dataStoreDao;
protected PrimaryDataStoreLifeCycle dataStoreLifeCycle;
public DefaultPrimaryDatastoreProviderImpl() {
@Inject
public DefaultPrimaryDatastoreProviderImpl(PrimaryDataStoreDao dataStoreDao) {
this.driver = new DefaultPrimaryDataStoreDriverImpl();
this.dataStoreDao = dataStoreDao;
this.dataStoreLifeCycle = new DefaultPrimaryDataStoreLifeCycleImpl(this, dataStoreDao);
}
@Override
public PrimaryDataStore getDataStore(long dataStoreId) {
DataStoreVO dsv = dataStoreDao.findById(dataStoreId);
PrimaryDataStoreVO dsv = dataStoreDao.findById(dataStoreId);
if (dsv == null) {
return null;
}
@ -41,4 +53,31 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
return null;
}
@Override
public PrimaryDataStoreLifeCycle getDataStoreLifeCycle() {
return dataStoreLifeCycle;
}
@Override
public long getId() {
return this.provider.getId();
}
@Override
public boolean register(PrimaryDataStoreProviderVO provider, Map<String, Object> params) {
this.provider = provider;
return true;
}
@Override
public boolean init(PrimaryDataStoreProviderVO provider) {
this.provider = provider;
return true;
}
@Override
public String getName() {
return providerName;
}
}

View File

@ -1,10 +1,18 @@
package org.apache.cloudstack.storage.datastore.provider;
import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
public interface PrimaryDataStoreProvider {
public PrimaryDataStore getDataStore(long dataStoreId);
public PrimaryDataStoreLifeCycle getDataStoreLifeCycle();
public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId);
public long getId();
public String getName();
public boolean register(PrimaryDataStoreProviderVO provider, Map<String, Object> params);
public boolean init(PrimaryDataStoreProviderVO provider);
}

View File

@ -1,5 +1,11 @@
package org.apache.cloudstack.storage.datastore.provider;
public interface PrimaryDataStoreProviderManager {
import java.util.List;
import com.cloud.utils.component.Manager;
public interface PrimaryDataStoreProviderManager extends Manager {
public PrimaryDataStoreProvider getDataStoreProvider(Long providerId);
public PrimaryDataStoreProvider getDataStoreProvider(String name);
public List<PrimaryDataStoreProvider> getDataStoreProviders();
}

View File

@ -18,15 +18,86 @@
*/
package org.apache.cloudstack.storage.datastore.provider;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
import org.springframework.stereotype.Component;
@Component
public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProviderManager {
@Inject
List<PrimaryDataStoreProvider> providers;
@Inject
PrimaryDataStoreProviderDao providerDao;
@Override
public PrimaryDataStoreProvider getDataStoreProvider(Long providerId) {
for (PrimaryDataStoreProvider provider : providers) {
if (provider.getId() == providerId) {
return provider;
}
}
return null;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
List<PrimaryDataStoreProviderVO> providerVos = providerDao.listAll();
for (PrimaryDataStoreProvider provider : providers) {
boolean existingProvider = false;
for (PrimaryDataStoreProviderVO providerVo : providerVos) {
if (providerVo.getName().equalsIgnoreCase(provider.getName())) {
existingProvider = true;
break;
}
}
if (!existingProvider) {
PrimaryDataStoreProviderVO dataStoreProvider = new PrimaryDataStoreProviderVO();
dataStoreProvider.setName(provider.getName());
dataStoreProvider = providerDao.persist(dataStoreProvider);
provider.register(dataStoreProvider, params);
}
PrimaryDataStoreProviderVO providervo = providerDao.findByName(provider.getName());
provider.init(providervo);
}
return true;
}
@Override
public boolean start() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean stop() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public PrimaryDataStoreProvider getDataStoreProvider(String name) {
for (PrimaryDataStoreProvider provider : providers) {
if (provider.getName().equalsIgnoreCase(name)) {
return provider;
}
}
return null;
}
@Override
public List<PrimaryDataStoreProvider> getDataStoreProviders() {
return providers;
}
}

View File

@ -59,7 +59,6 @@ public class TemplateEntityImpl implements TemplateEntity {
return this.templateInfo.getId();
}
@Override
public String getExternalId() {
// TODO Auto-generated method stub
return null;

View File

@ -21,8 +21,18 @@ package org.apache.cloudstack.storage.image.db;
import org.springframework.stereotype.Component;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.db.SearchCriteria.Op;
@Component
public class ImageDaoStoreDaoImpl extends GenericDaoBase<ImageDataStoreVO, Long> implements ImageDataStoreDao {
@Override
public ImageDataStoreVO findByName(String name) {
SearchCriteriaService<ImageDataStoreVO, ImageDataStoreVO> sc = SearchCriteria2.create(ImageDataStoreVO.class);
sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
return sc.find();
}
}

View File

@ -21,5 +21,5 @@ package org.apache.cloudstack.storage.image.db;
import com.cloud.utils.db.GenericDao;
public interface ImageDataStoreDao extends GenericDao<ImageDataStoreVO, Long> {
public ImageDataStoreVO findByName(String name);
}

View File

@ -21,4 +21,5 @@ package org.apache.cloudstack.storage.image.db;
import com.cloud.utils.db.GenericDao;
public interface ImageDataStoreProviderDao extends GenericDao<ImageDataStoreProviderVO, Long> {
public ImageDataStoreProviderVO findByName(String name);
}

View File

@ -21,8 +21,16 @@ package org.apache.cloudstack.storage.image.db;
import org.springframework.stereotype.Component;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.db.SearchCriteria.Op;
@Component
public class ImageDataStoreProviderDaoImpl extends GenericDaoBase<ImageDataStoreProviderVO, Long> implements ImageDataStoreProviderDao {
@Override
public ImageDataStoreProviderVO findByName(String name) {
SearchCriteriaService<ImageDataStoreProviderVO, ImageDataStoreProviderVO> service = SearchCriteria2.create(ImageDataStoreProviderVO.class);
service.addAnd(service.getEntity().getName(), Op.EQ, name);
return service.find();
}
}

View File

@ -35,7 +35,7 @@ public class ImageDataStoreVO {
@Column(name = "name", nullable = false)
private String name;
@Column(name = "image_provider", nullable = false)
@Column(name = "image_provider_id", nullable = false)
private long provider;
public long getId() {

View File

@ -143,7 +143,7 @@ public class ImageDataVO implements Identity {
this.uniqueName = uniqueName;
}
protected ImageDataVO() {
public ImageDataVO() {
this.uuid = UUID.randomUUID().toString();
}
@ -178,6 +178,10 @@ public class ImageDataVO implements Identity {
public boolean requiresHvm() {
return requiresHvm;
}
public void setRequireHvm(boolean hvm) {
this.requiresHvm = hvm;
}
public int getBits() {
return bits;
@ -230,6 +234,10 @@ public class ImageDataVO implements Identity {
public long getAccountId() {
return accountId;
}
public void setAccountId(long accountId) {
this.accountId = accountId;
}
public String getChecksum() {
return checksum;

View File

@ -21,7 +21,7 @@ package org.apache.cloudstack.storage.image.format;
import org.apache.cloudstack.storage.BaseType;
import org.springframework.stereotype.Component;
@Component
@Component("image_format_vhd")
public class VHD extends BaseType implements ImageFormat {
private final String type = "VHD";

View File

@ -20,7 +20,7 @@ package org.apache.cloudstack.storage.image.manager;
import javax.inject.Inject;
import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
import org.apache.cloudstack.storage.image.db.ImageDataDao;
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;

View File

@ -18,10 +18,13 @@
*/
package org.apache.cloudstack.storage.image.provider;
import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDao;
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderVO;
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriverImpl;
@ -29,6 +32,8 @@ import org.apache.cloudstack.storage.image.store.ImageDataStore;
import org.apache.cloudstack.storage.image.store.ImageDataStoreImpl;
import org.springframework.stereotype.Component;
import com.cloud.utils.component.ComponentInject;
@Component
public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
private final String providerName = "DefaultProvider";
@ -36,12 +41,14 @@ public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
ImageDataStoreProviderDao providerDao;
@Inject
ImageDataStoreDao imageStoreDao;
ImageDataStoreProviderVO provider;
@Override
public ImageDataStore getImageDataStore(long imageStoreId) {
ImageDataStoreVO idsv = imageStoreDao.findById(imageStoreId);
ImageDataStoreDriver driver = new ImageDataStoreDriverImpl();
ImageDataStore ids = new ImageDataStoreImpl(idsv, driver, false, null);
ids = ComponentInject.inject(ids);
return ids;
}
@ -52,8 +59,24 @@ public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
@Override
public boolean register(long providerId) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean init() {
provider = providerDao.findByName(providerName);
return true;
}
@Override
public ImageDataStore registerDataStore(String name, Map<String, String> params) {
ImageDataStoreVO dataStore = imageStoreDao.findByName(name);
if (dataStore == null) {
dataStore = new ImageDataStoreVO();
dataStore.setName(name);
dataStore.setProvider(provider.getId());
dataStore = imageStoreDao.persist(dataStore);
}
return getImageDataStore(dataStore.getId());
}
}

View File

@ -19,9 +19,15 @@
package org.apache.cloudstack.storage.image.provider;
import org.apache.cloudstack.storage.image.store.ImageDataStore;
import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle;
public interface ImageDataStoreProvider {
public interface ImageDataStoreProvider extends ImageDataStoreLifeCycle {
ImageDataStore getImageDataStore(long imageStoreId);
boolean register(long providerId);
public String getName();
/**
* @param providerId
* @return
*/
boolean init();
}

View File

@ -18,6 +18,8 @@
*/
package org.apache.cloudstack.storage.image.provider;
import java.util.List;
import org.apache.cloudstack.storage.image.TemplateObject;
import org.apache.cloudstack.storage.image.store.ImageDataStore;
@ -25,8 +27,13 @@ import com.cloud.utils.component.Manager;
public interface ImageDataStoreProviderManager extends Manager {
public ImageDataStoreProvider getProvider(long providerId);
public List<ImageDataStoreProvider> listProvider();
public ImageDataStore getDataStore(Long dataStoreId);
public ImageDataStore getDataStoreFromTemplateId(long templateId);
/**
* @param name
* @return
*/
ImageDataStoreProvider getProvider(String name);
}

View File

@ -24,7 +24,6 @@ import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.image.TemplateObject;
import org.apache.cloudstack.storage.image.db.ImageDataDao;
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDao;
@ -51,7 +50,8 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider
return null;
}
protected ImageDataStoreProvider getProvider(String name) {
@Override
public ImageDataStoreProvider getProvider(String name) {
for (ImageDataStoreProvider provider : providers) {
if (provider.getName().equalsIgnoreCase(name)) {
return provider;
@ -104,6 +104,7 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider
nProvider = providerDao.persist(nProvider);
provider.register(nProvider.getId());
}
provider.init();
}
return true;
@ -126,4 +127,9 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider
// TODO Auto-generated method stub
return null;
}
@Override
public List<ImageDataStoreProvider> listProvider() {
return providers;
}
}

View File

@ -83,8 +83,7 @@ public class ImageDataStoreImpl implements ImageDataStore {
@Override
public long getImageDataStoreId() {
// TODO Auto-generated method stub
return 0;
return imageDataStoreVO.getId();
}
@Override

View File

@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.storage.image.store.lifecycle;
import java.util.Map;
import org.apache.cloudstack.storage.image.store.ImageDataStore;
public interface ImageDataStoreLifeCycle {
public ImageDataStore registerDataStore(String name, Map<String, String> params);
}

View File

@ -72,6 +72,7 @@ public class DefaultVolumeStrategy implements VolumeStrategy {
VolumeProfile vp = _driver.createVolumeFromTemplate(get(volume.getId()), tp, dp);
/*
VolumeVO vlvo = _volumeMgr.getVolume(volume.getId());
vlvo.setFolder(_ds.getPath());
@ -80,8 +81,10 @@ public class DefaultVolumeStrategy implements VolumeStrategy {
vlvo.setPoolType(_ds.getPoolType());
vlvo.setPoolId(_ds.getId());
vlvo.setPodId(_ds.getPodId());
return _volumeMgr.updateVolume(vlvo);
*/
return null;
}
public boolean deleteVolume(Volume vol) {

View File

@ -24,17 +24,21 @@ import java.util.List;
import java.util.Map;
import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity;
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
import org.apache.cloudstack.storage.image.TemplateEntityImpl;
import org.apache.cloudstack.storage.image.TemplateInfo;
public class VolumeEntityImpl implements VolumeEntity {
private VolumeInfo volumeInfo;
public VolumeEntityImpl(VolumeInfo volumeObject) {
private final VolumeService vs;
public VolumeEntityImpl(VolumeInfo volumeObject, VolumeService vs) {
this.volumeInfo = volumeObject;
this.vs = vs;
}
public VolumeInfo getVolumeInfo() {
@ -55,7 +59,6 @@ public class VolumeEntityImpl implements VolumeEntity {
return volumeInfo.getId();
}
@Override
public String getExternalId() {
// TODO Auto-generated method stub
return null;
@ -214,4 +217,11 @@ public class VolumeEntityImpl implements VolumeEntity {
}
@Override
public boolean createVolumeFromTemplate(long dataStoreId, VolumeDiskType diskType, TemplateEntity template) {
TemplateInfo ti = ((TemplateEntityImpl)template).getTemplateInfo();
volumeInfo = vs.createVolumeFromTemplate(volumeInfo, dataStoreId, diskType, ti);
return true;
}
}

View File

@ -19,10 +19,13 @@
package org.apache.cloudstack.storage.volume;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeProfile;
import org.apache.cloudstack.storage.volume.db.VolumeVO;
import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.Volume.Event;
import com.cloud.storage.Volume.State;
import com.cloud.utils.fsm.NoTransitionException;
import com.cloud.utils.fsm.StateMachine2;
public interface VolumeManager {
VolumeVO allocateDuplicateVolume(VolumeVO oldVol);
@ -34,4 +37,9 @@ public interface VolumeManager {
VolumeVO getVolume(long volumeId);
VolumeVO updateVolume(VolumeVO volume);
/**
* @return
*/
StateMachine2<State, Event, VolumeVO> getStateMachine();
}

View File

@ -19,29 +19,67 @@
package org.apache.cloudstack.storage.volume;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeProfile;
import org.apache.cloudstack.storage.volume.db.VolumeDao;
import org.apache.cloudstack.storage.volume.db.VolumeVO;
import org.springframework.stereotype.Component;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.Volume;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.Volume.Event;
import com.cloud.storage.Volume.State;
import com.cloud.utils.component.Inject;
import com.cloud.utils.fsm.NoTransitionException;
import com.cloud.utils.fsm.StateMachine2;
@Component
public class VolumeManagerImpl implements VolumeManager {
private StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
@Inject
protected VolumeDao _volumeDao;
private final static StateMachine2<State, Event, VolumeVO> s_fsm = new StateMachine2<State, Event, VolumeVO>();
public VolumeManagerImpl() {
initStateMachine();
}
public VolumeVO allocateDuplicateVolume(VolumeVO oldVol) {
/*
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(), oldVol.getSize());
newVol.setTemplateId(oldVol.getTemplateId());
newVol.setDeviceId(oldVol.getDeviceId());
newVol.setInstanceId(oldVol.getInstanceId());
newVol.setRecreatable(oldVol.isRecreatable());
newVol.setReservationId(oldVol.getReservationId());
*/
return null;
// return _volumeDao.persist(newVol);
}
private void initStateMachine() {
s_fsm.addTransition(Volume.State.Allocated, Event.CreateRequested, Volume.State.Creating);
s_fsm.addTransition(Volume.State.Allocated, Event.DestroyRequested, Volume.State.Destroy);
s_fsm.addTransition(Volume.State.Creating, Event.OperationRetry, Volume.State.Creating);
s_fsm.addTransition(Volume.State.Creating, Event.OperationFailed, Volume.State.Allocated);
s_fsm.addTransition(Volume.State.Creating, Event.OperationSucceeded, Volume.State.Ready);
s_fsm.addTransition(Volume.State.Creating, Event.DestroyRequested, Volume.State.Destroy);
s_fsm.addTransition(Volume.State.Creating, Event.CreateRequested, Volume.State.Creating);
s_fsm.addTransition(Volume.State.Allocated, Event.UploadRequested, Volume.State.UploadOp);
s_fsm.addTransition(Volume.State.UploadOp, Event.CopyRequested, Volume.State.Creating);// CopyRequested for volume from sec to primary storage
s_fsm.addTransition(Volume.State.Creating, Event.CopySucceeded, Volume.State.Ready);
s_fsm.addTransition(Volume.State.Creating, Event.CopyFailed, Volume.State.UploadOp);// Copying volume from sec to primary failed.
s_fsm.addTransition(Volume.State.UploadOp, Event.DestroyRequested, Volume.State.Destroy);
s_fsm.addTransition(Volume.State.Ready, Event.DestroyRequested, Volume.State.Destroy);
s_fsm.addTransition(Volume.State.Destroy, Event.ExpungingRequested, Volume.State.Expunging);
s_fsm.addTransition(Volume.State.Ready, Event.SnapshotRequested, Volume.State.Snapshotting);
s_fsm.addTransition(Volume.State.Snapshotting, Event.OperationSucceeded, Volume.State.Ready);
s_fsm.addTransition(Volume.State.Snapshotting, Event.OperationFailed, Volume.State.Ready);
s_fsm.addTransition(Volume.State.Ready, Event.MigrationRequested, Volume.State.Migrating);
s_fsm.addTransition(Volume.State.Migrating, Event.OperationSucceeded, Volume.State.Ready);
s_fsm.addTransition(Volume.State.Migrating, Event.OperationFailed, Volume.State.Ready);
s_fsm.addTransition(Volume.State.Destroy, Event.OperationSucceeded, Volume.State.Destroy);
}
@Override
public StateMachine2<State, Event, VolumeVO> getStateMachine() {
return s_fsm;
}
public VolumeVO processEvent(Volume vol, Volume.Event event) throws NoTransitionException {
// _volStateMachine.transitTo(vol, event, null, _volumeDao);

View File

@ -18,6 +18,7 @@ import org.apache.log4j.Logger;
import com.cloud.storage.Volume;
import com.cloud.storage.Volume.State;
import com.cloud.utils.component.ComponentInject;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.fsm.NoTransitionException;
import com.cloud.utils.fsm.StateMachine2;
@ -25,7 +26,7 @@ import com.cloud.utils.fsm.StateMachine2;
public class VolumeObject implements VolumeInfo {
private static final Logger s_logger = Logger.getLogger(VolumeObject.class);
protected VolumeVO volumeVO;
private StateMachine2<Volume.State, VolumeEvent, VolumeVO> _volStateMachine;
private StateMachine2<Volume.State, Volume.Event, VolumeVO> _volStateMachine;
protected PrimaryDataStore dataStore;
@Inject
VolumeDiskTypeHelper diskTypeHelper;
@ -33,11 +34,18 @@ public class VolumeObject implements VolumeInfo {
VolumeTypeHelper volumeTypeHelper;
@Inject
VolumeDao volumeDao;
public VolumeObject(PrimaryDataStore dataStore, VolumeVO volumeVO) {
@Inject
VolumeManager volumeMgr;
private VolumeObject(PrimaryDataStore dataStore, VolumeVO volumeVO) {
this.volumeVO = volumeVO;
this.dataStore = dataStore;
}
public static VolumeObject getVolumeObject(PrimaryDataStore dataStore, VolumeVO volumeVO) {
VolumeObject vo = new VolumeObject(dataStore, volumeVO);
vo = ComponentInject.inject(vo);
return vo;
}
public String getUuid() {
return volumeVO.getUuid();
@ -91,8 +99,9 @@ public class VolumeObject implements VolumeInfo {
volumeVO.setDiskType(type.toString());
}
public boolean stateTransit(VolumeEvent event) {
public boolean stateTransit(Volume.Event event) {
boolean result = false;
_volStateMachine = volumeMgr.getStateMachine();
try {
result = _volStateMachine.transitTo(volumeVO, event, null, volumeDao);
} catch (NoTransitionException e) {

View File

@ -68,14 +68,14 @@ public class VolumeServiceImpl implements VolumeService {
}
VolumeObject vo = (VolumeObject) volume;
vo.stateTransit(VolumeEvent.CreateRequested);
vo.stateTransit(Volume.Event.CreateRequested);
try {
VolumeInfo vi = dataStore.createVolume(vo, diskType);
vo.stateTransit(VolumeEvent.OperationSucceeded);
vo.stateTransit(Volume.Event.OperationSucceeded);
return vi;
} catch (Exception e) {
vo.stateTransit(VolumeEvent.OperationFailed);
vo.stateTransit(Volume.Event.OperationFailed);
throw new CloudRuntimeException(e.toString());
}
}
@ -107,7 +107,7 @@ public class VolumeServiceImpl implements VolumeService {
@Override
public VolumeEntity allocateVolumeInDb(long size, VolumeType type, String volName, Long templateId) {
VolumeVO vo = volDao.allocVolume(size, type, volName, templateId);
return new VolumeEntityImpl(new VolumeObject(null, vo));
return new VolumeEntityImpl(VolumeObject.getVolumeObject(null, vo), this);
}
@Override
@ -118,10 +118,10 @@ public class VolumeServiceImpl implements VolumeService {
}
if (vo.getPoolId() == null) {
return new VolumeEntityImpl(new VolumeObject(null, vo));
return new VolumeEntityImpl(VolumeObject.getVolumeObject(null, vo), this);
} else {
PrimaryDataStore dataStore = dataStoreMgr.getPrimaryDataStore(vo.getPoolId());
return new VolumeEntityImpl(dataStore.getVolume(volumeId));
return new VolumeEntityImpl(dataStore.getVolume(volumeId), this);
}
}
@ -164,16 +164,16 @@ public class VolumeServiceImpl implements VolumeService {
VolumeObject vo = (VolumeObject) volume;
try {
vo.stateTransit(VolumeEvent.CreateRequested);
vo.stateTransit(Volume.Event.CreateRequested);
} catch (Exception e) {
throw new CloudRuntimeException(e.toString());
}
try {
volume = pd.createVoluemFromBaseImage(volume, templateOnPrimaryStore);
vo.stateTransit(VolumeEvent.OperationSucceeded);
vo.stateTransit(Volume.Event.OperationSucceeded);
} catch (Exception e) {
vo.stateTransit(VolumeEvent.OperationFailed);
vo.stateTransit(Volume.Event.OperationFailed);
throw new CloudRuntimeException(e.toString());
}
return volume;

View File

@ -28,7 +28,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.fsm.StateDao;
public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.State, VolumeEvent, VolumeVO> {
public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.State, Volume.Event, VolumeVO> {
List<VolumeVO> findDetachedByAccount(long accountId);

View File

@ -335,7 +335,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
}
@Override
public boolean updateState(Volume.State currentState, VolumeEvent event, Volume.State nextState, VolumeVO vo, Object data) {
public boolean updateState(Volume.State currentState, Volume.Event event, Volume.State nextState, VolumeVO vo, Object data) {
Long oldUpdated = vo.getUpdatedCount();
Date oldUpdatedTime = vo.getUpdated();

View File

@ -141,16 +141,14 @@ public class VolumeVO implements Identity, StateObject<Volume.State> {
@Column(name = "uuid")
String uuid;
@Column(name = "reservation")
String reservationId;
// Real Constructor
public VolumeVO(long size, String type, String name, Long templateId) {
this.volumeType = type.toString();
this.volumeType = type;
this.size = size;
this.name = name;
this.templateId = templateId;
this.uuid = UUID.randomUUID().toString();
this.state = Volume.State.Allocated;
}
// Copy Constructor
@ -398,14 +396,6 @@ public class VolumeVO implements Identity, StateObject<Volume.State> {
}
}
public String getReservationId() {
return this.reservationId;
}
public void setReservationId(String reserv) {
this.reservationId = reserv;
}
@Override
public String getUuid() {
return this.uuid;

View File

@ -23,26 +23,43 @@ import static org.junit.Assert.*;
import java.awt.List;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.QCOW2;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VHD;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VMDK;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTypeHelper;
import org.apache.cloudstack.engine.subsystem.api.storage.type.RootDisk;
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeTypeHelper;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
import org.apache.cloudstack.storage.image.ImageService;
import org.apache.cloudstack.storage.image.db.ImageDataDao;
import org.apache.cloudstack.storage.image.db.ImageDataVO;
import org.apache.cloudstack.storage.image.format.ISO;
import org.apache.cloudstack.storage.image.format.ImageFormat;
import org.apache.cloudstack.storage.image.format.ImageFormatHelper;
import org.apache.cloudstack.storage.image.format.OVA;
import org.apache.cloudstack.storage.image.format.Unknown;
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProvider;
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
import org.apache.cloudstack.storage.image.store.ImageDataStore;
import org.apache.cloudstack.storage.volume.VolumeService;
import org.apache.cloudstack.storage.volume.db.VolumeDao;
import org.apache.cloudstack.storage.volume.db.VolumeVO;
import org.junit.Before;
import org.junit.Test;
@ -54,31 +71,110 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.mockito.Mockito.*;
import com.cloud.storage.Storage.TemplateType;
import com.cloud.utils.component.ComponentInject;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/resource/storageContext.xml")
public class volumeServiceTest {
@Inject
ImageDataStoreProviderManager imageProviderMgr;
@Inject
ImageService imageService;
@Inject
VolumeService volumeService;
@Inject
ImageDataDao imageDataDao;
@Inject
VolumeDao volumeDao;
@Inject
PrimaryDataStoreProviderManager primaryDataStoreProviderMgr;
@Before
public void setUp() {
}
@Test
public void test() {
private ImageDataVO createImageData() {
ImageDataVO image = new ImageDataVO();
image.setTemplateType(TemplateType.USER);
image.setUrl("http://testurl/test.vhd");
image.setUniqueName(UUID.randomUUID().toString());
image.setName(UUID.randomUUID().toString());
image.setPublicTemplate(true);
image.setFeatured(true);
image.setRequireHvm(true);
image.setBits(64);
image.setFormat(new VHD().toString());
image.setAccountId(1);
image.setEnablePassword(true);
image.setEnableSshKey(true);
image.setGuestOSId(1);
image.setBootable(true);
image.setPrepopulate(true);
image.setCrossZones(true);
image.setExtractable(true);
image = imageDataDao.persist(image);
return image;
}
private TemplateEntity createTemplate() {
try {
imageProviderMgr.configure("image Provider", new HashMap<String, Object>());
ImageDataVO image = createImageData();
ImageDataStoreProvider defaultProvider = imageProviderMgr.getProvider("DefaultProvider");
ImageDataStore store = defaultProvider.registerDataStore("defaultHttpStore", new HashMap<String, String>());
imageService.registerTemplate(image.getId(), store.getImageDataStoreId());
TemplateEntity te = imageService.getTemplateEntity(image.getId());
return te;
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
@Test
public void createTemplateTest() {
createTemplate();
}
private PrimaryDataStoreInfo createPrimaryDataStore() {
try {
primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
PrimaryDataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
Map<String, String> params = new HashMap<String, String>();
params.put("url", "nfs://test/test");
params.put("dcId", "1");
params.put("name", "my primary data store");
PrimaryDataStoreInfo primaryDataStoreInfo = lifeCycle.registerDataStore(params);
return primaryDataStoreInfo;
} catch (ConfigurationException e) {
return null;
}
}
@Test
public void createPrimaryDataStoreTest() {
createPrimaryDataStore();
}
private VolumeVO createVolume(long templateId) {
VolumeVO volume = new VolumeVO(1000, new RootDisk().toString(), UUID.randomUUID().toString(), templateId);
volume = volumeDao.persist(volume);
return volume;
}
@Test
public void createVolumeFromTemplate() {
TemplateEntity te = createTemplate();
PrimaryDataStoreInfo dataStoreInfo = createPrimaryDataStore();
VolumeVO volume = createVolume(te.getId());
VolumeEntity ve = volumeService.getVolumeEntity(volume.getId());
ve.createVolumeFromTemplate(dataStoreInfo.getId(), new VHD(), te);
}
//@Test
public void test1() {
System.out.println(VolumeTypeHelper.getType("Root"));
@ -105,7 +201,7 @@ public class volumeServiceTest {
//@Test
public void testStaticBean() {
DefaultPrimaryDatastoreProviderImpl provider = ComponentInject.inject(DefaultPrimaryDatastoreProviderImpl.class);
assertNotNull(provider.dataStoreDao);
//assertNotNull(provider.dataStoreDao);
DefaultPrimaryDataStoreImpl dpdsi = new DefaultPrimaryDataStoreImpl(null, null, null);
ComponentInject.inject(dpdsi);

View File

@ -12,6 +12,7 @@
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="org.apache.cloudstack.storage" />
<context:component-scan base-package="org.apache.cloudstack.engine.subsystem.api.storage" />
<context:component-scan base-package="com.cloud.utils.db" />
<context:component-scan base-package="com.cloud.utils.component" />
@ -28,36 +29,7 @@
</aop:config>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/cloud" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="openJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform"
value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="openJpaVendorAdapter" />
<property name="packagesToScan" value="org.apache.cloudstack.storage" />
</bean>
<bean id="sharedEntityManager"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="someDependencyMock" class="org.apache.cloudstack.storage.test.StorageFactoryBean">
<constructor-arg name="classToBeMocked"

View File

@ -106,8 +106,8 @@ public class DatabaseCreator {
System.exit(1);
}
SystemIntegrityChecker checker = (SystemIntegrityChecker)ComponentLocator.inject(clazz);
checker.check();
//SystemIntegrityChecker checker = (SystemIntegrityChecker)ComponentLocator.inject(clazz);
//checker.check();
}
}
}

View File

@ -0,0 +1,41 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.
alter table vm_template add image_data_store_id bigint unsigned;
alter table storage_pool add storage_provider_id bigint unsigned;
alter table storage_pool modify id bigint unsigned AUTO_INCREMENT UNIQUE NOT NULL;
alter table volumes add disk_type varchar(255);
alter table volumes drop foreign key `fk_volumes__account_id`;
CREATE TABLE `cloud`.`primary_data_store_provider` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`name` varchar(255) NOT NULL COMMENT 'name of primary data store provider',
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`image_data_store_provider` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`name` varchar(255) NOT NULL COMMENT 'name of data store provider',
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`image_data_store` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`name` varchar(255) NOT NULL COMMENT 'name of data store',
`image_provider_id` bigint unsigned NOT NULL COMMENT 'id of image_data_store_provider',
PRIMARY KEY(`id`),
CONSTRAINT `fk_tags__image_data_store_provider_id` FOREIGN KEY(`image_provider_id`) REFERENCES `image_data_store_provider`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -1500,7 +1500,6 @@ CREATE TABLE `cloud`.`storage_pool` (
`created` datetime COMMENT 'date the pool created',
`removed` datetime COMMENT 'date removed if not null',
`update_time` DATETIME,
`storage_provider` varchar(255) NOT NULL,
`status` varchar(32),
PRIMARY KEY (`id`),
CONSTRAINT `fk_storage_pool__pod_id` FOREIGN KEY `fk_storage_pool__pod_id` (`pod_id`) REFERENCES `host_pod_ref` (`id`) ON DELETE CASCADE,
@ -2372,5 +2371,19 @@ CREATE TABLE `cloud`.`nicira_nvp_nic_map` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`image_data_store` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`name` varchar(255) NOT NULL COMMENT 'name of data store',
`image_provider_id` bigint unsigned NOT NULL COMMENT 'id of image_data_store_provider',
PRIMARY KEY(`id`),
CONSTRAINT `fk_tags__image_data_store_provider_id` FOREIGN KEY(`image_provider_id`) REFERENCES `image_data_store_provider`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`image_data_store_provider` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`name` varchar(255) NOT NULL COMMENT 'name of data store provider',
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET foreign_key_checks = 1;