move code around

This commit is contained in:
Edison Su 2012-10-26 18:36:40 -07:00
parent bf21081633
commit fff6fde823
12 changed files with 821 additions and 35 deletions

View File

@ -0,0 +1,29 @@
/*
* 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.datastore;
public enum DataStoreStatus {
Creating,
Up,
PrepareForMaintenance,
ErrorInMaintenance,
CancelMaintenance,
Maintenance,
Removed;
}

View File

@ -0,0 +1,28 @@
/*
* 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.datastore;
import org.apache.cloudstack.storage.volume.Volume;
import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType;
public interface PrimaryDataStore {
Volume getVolume(long id);
boolean deleteVolume(long id);
Volume createVolume(long id, VolumeDiskType diskType);
}

View File

@ -0,0 +1,258 @@
/*
* 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.datastore.db;
import java.util.Date;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.apache.cloudstack.storage.datastore.DataStoreStatus;
import com.cloud.api.Identity;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="storage_pool")
public class DataStoreVO 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)
private long id;
@Column(name="name", updatable=false, nullable=false, length=255)
private String name = null;
@Column(name="uuid", length=255)
private String uuid = null;
@Column(name="pool_type", updatable=false, nullable=false, length=32)
private String protocol;
@Column(name=GenericDao.CREATED_COLUMN)
Date created;
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
@Column(name="update_time", updatable=true)
@Temporal(value=TemporalType.TIMESTAMP)
private Date updateTime;
@Column(name="data_center_id", updatable=true, nullable=false)
private long dataCenterId;
@Column(name="pod_id", updatable=true)
private Long podId;
@Column(name="available_bytes", updatable=true, nullable=true)
private long availableBytes;
@Column(name="capacity_bytes", updatable=true, nullable=true)
private long capacityBytes;
@Column(name="status", updatable=true, nullable=false)
@Enumerated(value=EnumType.STRING)
private DataStoreStatus status;
@Column(name="storage_provider", updatable=true, nullable=false)
private String storageProvider;
@Column(name="storage_type", nullable=false)
private String storageType;
@Column(name="host_address")
private String hostAddress;
@Column(name="path")
private String path;
@Column(name="port")
private int port;
@Column(name="user_info")
private String userInfo;
@Column(name="cluster_id")
private Long clusterId;
public long getId() {
return id;
}
public DataStoreStatus getStatus() {
return status;
}
public DataStoreVO() {
// TODO Auto-generated constructor stub
}
public String getName() {
return name;
}
public String getUuid() {
return uuid;
}
public String getPoolType() {
return protocol;
}
public Date getCreated() {
return created;
}
public Date getRemoved() {
return removed;
}
public Date getUpdateTime() {
return updateTime;
}
public long getDataCenterId() {
return dataCenterId;
}
public long getAvailableBytes() {
return availableBytes;
}
public String getStorageProvider() {
return storageProvider;
}
public void setStorageProvider(String provider) {
storageProvider = provider;
}
public String getStorageType() {
return storageType;
}
public void setStorageType(String type) {
storageType = type;
}
public long getCapacityBytes() {
return capacityBytes;
}
public void setAvailableBytes(long available) {
availableBytes = available;
}
public void setCapacityBytes(long capacity) {
capacityBytes = capacity;
}
public Long getClusterId() {
return clusterId;
}
public void setClusterId(Long clusterId) {
this.clusterId = clusterId;
}
public String getHostAddress() {
return hostAddress;
}
public String getPath() {
return path;
}
public String getUserInfo() {
return userInfo;
}
public void setStatus(DataStoreStatus status)
{
this.status = status;
}
public void setId(long id) {
this.id = id;
}
public void setDataCenterId(long dcId) {
this.dataCenterId = dcId;
}
public void setPodId(Long podId) {
this.podId = podId;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public void setPath(String path) {
this.path = path;
}
public void setUserInfo(String userInfo) {
this.userInfo = userInfo;
}
public int getPort() {
return port;
}
public Long getPodId() {
return podId;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof DataStoreVO) || obj == null) {
return false;
}
DataStoreVO that = (DataStoreVO)obj;
return this.id == that.id;
}
@Override
public int hashCode() {
return new Long(id).hashCode();
}
@Override
public String toString() {
return new StringBuilder("Pool[").append(id).append("|").append(protocol).append("]").toString();
}
}

View File

@ -0,0 +1,106 @@
/*
* 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.datastore.db;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.storage.datastore.DataStoreStatus;
import com.cloud.utils.db.GenericDao;
public interface PrimaryDataStoreDao extends GenericDao<DataStoreVO, Long> {
/**
* @param datacenterId -- the id of the datacenter (availability zone)
*/
List<DataStoreVO> listByDataCenterId(long datacenterId);
/**
* @param datacenterId -- the id of the datacenter (availability zone)
*/
List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId);
/**
* Set capacity of storage pool in bytes
* @param id pool id.
* @param capacity capacity in bytes
*/
void updateCapacity(long id, long capacity);
/**
* Set available bytes of storage pool in bytes
* @param id pool id.
* @param available available capacity in bytes
*/
void updateAvailable(long id, long available);
DataStoreVO persist(DataStoreVO pool, Map<String, String> details);
/**
* Find pool by name.
*
* @param name name of pool.
* @return the single StoragePoolVO
*/
List<DataStoreVO> findPoolByName(String name);
/**
* Find pools by the pod that matches the details.
*
* @param podId pod id to find the pools in.
* @param details 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<DataStoreVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared);
/**
* Find pool by UUID.
*
* @param uuid uuid of pool.
* @return the single StoragePoolVO
*/
DataStoreVO findPoolByUUID(String uuid);
List<DataStoreVO> listByStorageHost(String hostFqdnOrIp);
DataStoreVO findPoolByHostPath(long dcId, Long podId, String host, String path, String uuid);
List<DataStoreVO> listPoolByHostPath(String host, String path);
void updateDetails(long poolId, Map<String, String> details);
Map<String, String> getDetails(long poolId);
List<String> searchForStoragePoolDetails(long poolId, String value);
List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid);
List<DataStoreVO> listByStatus(DataStoreStatus status);
long countPoolsByStatus(DataStoreStatus... statuses);
List<DataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status);
List<DataStoreVO> listPoolsByCluster(long clusterId);
}

View File

@ -0,0 +1,375 @@
/*
* 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.datastore.db;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.datastore.DataStoreStatus;
import com.cloud.storage.StoragePoolDetailVO;
import com.cloud.storage.dao.StoragePoolDetailsDao;
import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.exception.CloudRuntimeException;
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;
protected final StoragePoolDetailsDao _detailsDao;
private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and (";
private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?";
private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?";
protected PrimaryDataStoreDaoImpl() {
AllFieldSearch = createSearchBuilder();
AllFieldSearch.and("name", AllFieldSearch.entity().getName(), SearchCriteria.Op.EQ);
AllFieldSearch.and("uuid", AllFieldSearch.entity().getUuid(), SearchCriteria.Op.EQ);
AllFieldSearch.and("datacenterId", AllFieldSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
AllFieldSearch.and("hostAddress", AllFieldSearch.entity().getHostAddress(), SearchCriteria.Op.EQ);
AllFieldSearch.and("status",AllFieldSearch.entity().getStatus(),SearchCriteria.Op.EQ);
AllFieldSearch.and("path", AllFieldSearch.entity().getPath(), SearchCriteria.Op.EQ);
AllFieldSearch.and("podId", AllFieldSearch.entity().getPodId(), Op.EQ);
AllFieldSearch.and("clusterId", AllFieldSearch.entity().getClusterId(), Op.EQ);
AllFieldSearch.done();
DcPodSearch = createSearchBuilder();
DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
DcPodSearch.and().op("nullpod", DcPodSearch.entity().getPodId(), SearchCriteria.Op.NULL);
DcPodSearch.or("podId", DcPodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
DcPodSearch.cp();
DcPodSearch.and().op("nullcluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.NULL);
DcPodSearch.or("cluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
DcPodSearch.cp();
DcPodSearch.done();
DcPodAnyClusterSearch = createSearchBuilder();
DcPodAnyClusterSearch.and("datacenterId", DcPodAnyClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
DcPodAnyClusterSearch.and().op("nullpod", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.NULL);
DcPodAnyClusterSearch.or("podId", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.EQ);
DcPodAnyClusterSearch.cp();
DcPodAnyClusterSearch.done();
DeleteLvmSearch = createSearchBuilder();
DeleteLvmSearch.and("ids", DeleteLvmSearch.entity().getId(), SearchCriteria.Op.IN);
DeleteLvmSearch.and().op("LVM", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ);
DeleteLvmSearch.or("Filesystem", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ);
DeleteLvmSearch.cp();
DeleteLvmSearch.done();
StatusCountSearch = createSearchBuilder(Long.class);
StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN);
StatusCountSearch.select(null, Func.COUNT, null);
StatusCountSearch.done();
_detailsDao = ComponentLocator.inject(StoragePoolDetailsDaoImpl.class);
}
@Override
public List<DataStoreVO> findPoolByName(String name) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("name", name);
return listIncludingRemovedBy(sc);
}
@Override
public DataStoreVO findPoolByUUID(String uuid) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("uuid", uuid);
return findOneIncludingRemovedBy(sc);
}
@Override
public List<DataStoreVO> findIfDuplicatePoolsExistByUUID(String uuid) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("uuid", uuid);
return listBy(sc);
}
@Override
public List<DataStoreVO> listByDataCenterId(long datacenterId) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("datacenterId", datacenterId);
return listBy(sc);
}
@Override
public void updateAvailable(long id, long available) {
DataStoreVO pool = createForUpdate(id);
pool.setAvailableBytes(available);
update(id, pool);
}
@Override
public void updateCapacity(long id, long capacity) {
DataStoreVO pool = createForUpdate(id);
pool.setCapacityBytes(capacity);
update(id, pool);
}
@Override
public List<DataStoreVO> listByStorageHost(String hostFqdnOrIp) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("hostAddress", hostFqdnOrIp);
return listIncludingRemovedBy(sc);
}
@Override
public List<DataStoreVO> listByStatus(DataStoreStatus status){
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("status", status);
return listBy(sc);
}
@Override
public List<DataStoreVO> listByStatusInZone(long dcId, DataStoreStatus status){
SearchCriteria<DataStoreVO> 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();
sc.setParameters("hostAddress", host);
sc.setParameters("path", path);
sc.setParameters("datacenterId", datacenterId);
sc.setParameters("podId", podId);
sc.setParameters("uuid", uuid);
return findOneBy(sc);
}
@Override
public List<DataStoreVO> listBy(long datacenterId, long podId, Long clusterId) {
if (clusterId != null) {
SearchCriteria<DataStoreVO> sc = DcPodSearch.create();
sc.setParameters("datacenterId", datacenterId);
sc.setParameters("podId", podId);
sc.setParameters("cluster", clusterId);
return listBy(sc);
} else {
SearchCriteria<DataStoreVO> sc = DcPodAnyClusterSearch.create();
sc.setParameters("datacenterId", datacenterId);
sc.setParameters("podId", podId);
return listBy(sc);
}
}
@Override
public List<DataStoreVO> listPoolByHostPath(String host, String path) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("hostAddress", host);
sc.setParameters("path", path);
return listBy(sc);
}
public DataStoreVO listById(Integer id)
{
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("id", id);
return findOneIncludingRemovedBy(sc);
}
@Override @DB
public DataStoreVO persist(DataStoreVO pool, Map<String, String> details) {
Transaction txn = Transaction.currentTxn();
txn.start();
pool = super.persist(pool);
if (details != null) {
for (Map.Entry<String, String> detail : details.entrySet()) {
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue());
_detailsDao.persist(vo);
}
}
txn.commit();
return pool;
}
@DB
@Override
public List<DataStoreVO> 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 (");
}
for (Map.Entry<String, String> detail : details.entrySet()) {
sql.append("((storage_pool_details.name='").append(detail.getKey()).append("') AND (storage_pool_details.value='").append(detail.getValue()).append("')) OR ");
}
sql.delete(sql.length() - 4, sql.length());
sql.append(DetailsSqlSuffix);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
int i = 1;
pstmt.setLong(i++, dcId);
pstmt.setLong(i++, podId);
if (clusterId != null) {
pstmt.setLong(i++, clusterId);
}
pstmt.setInt(i++, details.size());
ResultSet rs = pstmt.executeQuery();
List<DataStoreVO> pools = new ArrayList<DataStoreVO>();
while (rs.next()) {
pools.add(toEntityBean(rs, false));
}
return pools;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt, e);
}
}
protected Map<String, String> tagsToDetails(String[] tags) {
Map<String, String> details = new HashMap<String, String>(tags.length);
for (String tag: tags) {
details.put(tag, "true");
}
return details;
}
@Override
public List<DataStoreVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) {
List<DataStoreVO> storagePools = null;
if (tags == null || tags.length == 0) {
storagePools = listBy(dcId, podId, clusterId);
} else {
Map<String, String> details = tagsToDetails(tags);
storagePools = findPoolsByDetails(dcId, podId, clusterId, details);
}
if (shared == null) {
return storagePools;
} else {
List<DataStoreVO> filteredStoragePools = new ArrayList<DataStoreVO>(storagePools);
for (DataStoreVO pool : storagePools) {
/*
if (shared != pool.isShared()) {
filteredStoragePools.remove(pool);
}*/
}
return filteredStoragePools;
}
}
@Override
@DB
public List<String> searchForStoragePoolDetails(long poolId, String value){
StringBuilder sql = new StringBuilder(FindPoolTagDetails);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, poolId);
pstmt.setString(2, value);
ResultSet rs = pstmt.executeQuery();
List<String> tags = new ArrayList<String>();
while (rs.next()) {
tags.add(rs.getString("name"));
}
return tags;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e);
}
}
@Override
public void updateDetails(long poolId, Map<String, String> details) {
if (details != null) {
_detailsDao.update(poolId, details);
}
}
@Override
public Map<String, String> getDetails(long poolId) {
return _detailsDao.getDetails(poolId);
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
_detailsDao.configure("DetailsDao", params);
return true;
}
@Override
public long countPoolsByStatus( DataStoreStatus... statuses) {
SearchCriteria<Long> sc = StatusCountSearch.create();
sc.setParameters("status", (Object[])statuses);
List<Long> rs = customSearchIncludingRemoved(sc, null);
if (rs.size() == 0) {
return 0;
}
return rs.get(0);
}
@Override
public List<DataStoreVO> listPoolsByCluster(long clusterId) {
SearchCriteria<DataStoreVO> sc = AllFieldSearch.create();
sc.setParameters("clusterId", clusterId);
return listBy(sc);
}
}

View File

@ -21,11 +21,13 @@ package org.apache.cloudstack.storage.manager;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.StoragePool;
public interface StoragePoolService {
StoragePool addStoragePool(long zoneId, long podId, long clusterId, long hostId,
public interface PrimaryDataStoreManager {
PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId,
String URI,
String storageType,
String poolName,
@ -36,4 +38,5 @@ public interface StoragePoolService {
void disableStoragePool(long poolId);
Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor);
Map<String, List<String>> getSupportedSecondaryStorages(long zoneId);
PrimaryDataStore getDataStore(String id);
}

View File

@ -41,7 +41,7 @@ import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
public class StoragePoolManagerImpl implements StoragePoolService {
public class PrimaryDataStoreManagerImpl implements PrimaryDataStoreManager {
@Inject(adapter = StorageProvider.class)
protected Adapters<StorageProvider> _storageProviders;
@Inject

View File

@ -25,7 +25,7 @@ public interface VolumeService {
/**
*
*/
Volume allocateVolumeInDb(long size, VolumeType type);
Volume allocateVolumeInDb(long size, VolumeType type,String volName, Long templateId);
/**
* Creates the volume based on the given criteria
@ -34,7 +34,7 @@ public interface VolumeService {
*
* @return the volume object
*/
Volume createVolume(long volumeId);
Volume createVolume(long volumeId, long dataStoreId);
/**
* Delete volume

View File

@ -18,6 +18,9 @@
*/
package org.apache.cloudstack.storage.volume;
import javax.inject.Inject;
import org.apache.cloudstack.storage.volume.db.VolumeDao;
import org.apache.cloudstack.storage.volume.type.VolumeType;
import org.springframework.stereotype.Service;
@ -25,8 +28,10 @@ import com.cloud.utils.db.DB;
@Service
public class VolumeServiceImpl implements VolumeService {
@Inject
VolumeDao volDao;
@Override
public Volume createVolume(long volumeId) {
public Volume createVolume(long volumeId, long dataStoreId) {
// TODO Auto-generated method stub
return null;
}
@ -62,8 +67,8 @@ public class VolumeServiceImpl implements VolumeService {
}
@Override
public Volume allocateVolumeInDb(long size, VolumeType type) {
// TODO Auto-generated method stub
public Volume allocateVolumeInDb(long size, VolumeType type, String volName, Long templateId) {
volDao.allocVolume(size, type, volName, templateId);
return null;
}
}

View File

@ -21,6 +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.disktype.VolumeDiskType;
import org.apache.cloudstack.storage.volume.type.VolumeType;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@ -77,5 +78,5 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<VolumeSt
List<Long> listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId);
VolumeVO allocVolume(long size, VolumeType type);
VolumeVO allocVolume(long size, VolumeType type, String volName, Long templateId);
}

View File

@ -28,6 +28,7 @@ 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.disktype.VolumeDiskType;
import org.apache.cloudstack.storage.volume.type.RootDisk;
import org.apache.cloudstack.storage.volume.type.VolumeType;
import org.apache.log4j.Logger;
@ -418,8 +419,9 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
@Override
@DB
public VolumeVO allocVolume(long size, VolumeType type) {
VolumeVO vol = new VolumeVO();
public VolumeVO allocVolume(long size, VolumeType type, String volName, Long templateId) {
VolumeVO vol = new VolumeVO(size, type.toString(), volName, templateId);
vol = this.persist(vol);
return vol;
}
}

View File

@ -141,38 +141,17 @@ public class VolumeVO implements Identity {
String reservationId;
// Real Constructor
public VolumeVO(VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
public VolumeVO(long size, String type, String name, Long templateId) {
this.volumeType = type.toString();
this.name = name;
this.dataCenterId = dcId;
this.accountId = accountId;
this.domainId = domainId;
this.size = size;
this.diskOfferingId = diskOfferingId;
this.state = VolumeState.Allocated;
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, String vType) {
this.name = name;
this.accountId = accountId;
this.domainId = domainId;
this.instanceId = instanceId;
this.folder = folder;
this.path = path;
this.size = size;
this.podId = podId;
this.dataCenterId = dcId;
this.volumeType = vType.toString();
this.state = VolumeState.Allocated;
this.recreatable = false;
this.templateId = templateId;
this.uuid = UUID.randomUUID().toString();
}
// Copy Constructor
public VolumeVO(VolumeVO that) {
this(that.getName(), that.getDataCenterId(), that.getPodId(), that.getAccountId(), that.getDomainId(), that.getInstanceId(), that.getFolder(), that.getPath(), that.getSize(), that
.getVolumeType());
this(that.getSize(), that.getVolumeType(), that.getName(), that.getTemplateId());
this.recreatable = that.isRecreatable();
this.state = that.getState();
this.size = that.getSize();