diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/DataStoreStatus.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/DataStoreStatus.java new file mode 100644 index 00000000000..65f46b1e156 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/DataStoreStatus.java @@ -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; +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java new file mode 100644 index 00000000000..6fc4ed0c5c7 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java @@ -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); +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/db/DataStoreVO.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/DataStoreVO.java new file mode 100644 index 00000000000..960d7c88648 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/DataStoreVO.java @@ -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(); + } +} \ No newline at end of file diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java new file mode 100644 index 00000000000..8016559a6b9 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java @@ -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 { + + /** + * @param datacenterId -- the id of the datacenter (availability zone) + */ + List listByDataCenterId(long datacenterId); + + /** + * @param datacenterId -- the id of the datacenter (availability zone) + */ + List 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 details); + + /** + * Find pool by name. + * + * @param name name of pool. + * @return the single StoragePoolVO + */ + List 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 findPoolsByDetails(long dcId, long podId, Long clusterId, Map details); + + List 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 listByStorageHost(String hostFqdnOrIp); + + DataStoreVO findPoolByHostPath(long dcId, Long podId, String host, String path, String uuid); + + List listPoolByHostPath(String host, String path); + + void updateDetails(long poolId, Map details); + + Map getDetails(long poolId); + + List searchForStoragePoolDetails(long poolId, String value); + + List findIfDuplicatePoolsExistByUUID(String uuid); + + List listByStatus(DataStoreStatus status); + + long countPoolsByStatus(DataStoreStatus... statuses); + + List listByStatusInZone(long dcId, DataStoreStatus status); + + List listPoolsByCluster(long clusterId); +} \ No newline at end of file diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java new file mode 100644 index 00000000000..28744abf5d9 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -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 implements PrimaryDataStoreDao { + protected final SearchBuilder AllFieldSearch; + protected final SearchBuilder DcPodSearch; + protected final SearchBuilder DcPodAnyClusterSearch; + protected final SearchBuilder DeleteLvmSearch; + protected final GenericSearchBuilder 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 findPoolByName(String name) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("name", name); + return listIncludingRemovedBy(sc); + } + + + @Override + public DataStoreVO findPoolByUUID(String uuid) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("uuid", uuid); + return findOneIncludingRemovedBy(sc); + } + + + + @Override + public List findIfDuplicatePoolsExistByUUID(String uuid) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("uuid", uuid); + return listBy(sc); + } + + + @Override + public List listByDataCenterId(long datacenterId) { + SearchCriteria 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 listByStorageHost(String hostFqdnOrIp) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("hostAddress", hostFqdnOrIp); + return listIncludingRemovedBy(sc); + } + + @Override + public List listByStatus(DataStoreStatus status){ + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("status", status); + return listBy(sc); + } + + @Override + public List listByStatusInZone(long dcId, DataStoreStatus status){ + SearchCriteria 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 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 listBy(long datacenterId, long podId, Long clusterId) { + if (clusterId != null) { + SearchCriteria sc = DcPodSearch.create(); + sc.setParameters("datacenterId", datacenterId); + sc.setParameters("podId", podId); + + sc.setParameters("cluster", clusterId); + return listBy(sc); + } else { + SearchCriteria sc = DcPodAnyClusterSearch.create(); + sc.setParameters("datacenterId", datacenterId); + sc.setParameters("podId", podId); + return listBy(sc); + } + } + + @Override + public List listPoolByHostPath(String host, String path) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("hostAddress", host); + sc.setParameters("path", path); + + return listBy(sc); + } + + public DataStoreVO listById(Integer id) + { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("id", id); + + return findOneIncludingRemovedBy(sc); + } + + @Override @DB + public DataStoreVO persist(DataStoreVO pool, Map details) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + pool = super.persist(pool); + if (details != null) { + for (Map.Entry detail : details.entrySet()) { + StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue()); + _detailsDao.persist(vo); + } + } + txn.commit(); + return pool; + } + + @DB + @Override + public List findPoolsByDetails(long dcId, long podId, Long clusterId, Map 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 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 pools = new ArrayList(); + while (rs.next()) { + pools.add(toEntityBean(rs, false)); + } + return pools; + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to execute " + pstmt, e); + } + } + + protected Map tagsToDetails(String[] tags) { + Map details = new HashMap(tags.length); + for (String tag: tags) { + details.put(tag, "true"); + } + return details; + } + + @Override + public List findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) { + List storagePools = null; + if (tags == null || tags.length == 0) { + storagePools = listBy(dcId, podId, clusterId); + } else { + Map details = tagsToDetails(tags); + storagePools = findPoolsByDetails(dcId, podId, clusterId, details); + } + + if (shared == null) { + return storagePools; + } else { + List filteredStoragePools = new ArrayList(storagePools); + for (DataStoreVO pool : storagePools) { + /* + if (shared != pool.isShared()) { + filteredStoragePools.remove(pool); + }*/ + } + + return filteredStoragePools; + } + } + + @Override + @DB + public List 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 tags = new ArrayList(); + + 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 details) { + if (details != null) { + _detailsDao.update(poolId, details); + } + } + + @Override + public Map getDetails(long poolId) { + return _detailsDao.getDetails(poolId); + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + _detailsDao.configure("DetailsDao", params); + return true; + } + + + + @Override + public long countPoolsByStatus( DataStoreStatus... statuses) { + SearchCriteria sc = StatusCountSearch.create(); + + sc.setParameters("status", (Object[])statuses); + + List rs = customSearchIncludingRemoved(sc, null); + if (rs.size() == 0) { + return 0; + } + + return rs.get(0); + } + + @Override + public List listPoolsByCluster(long clusterId) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("clusterId", clusterId); + + return listBy(sc); + } +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolService.java b/platform/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java similarity index 85% rename from platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolService.java rename to platform/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java index ed2107646cf..6292ab8b553 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolService.java +++ b/platform/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java @@ -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> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor); Map> getSupportedSecondaryStorages(long zoneId); + PrimaryDataStore getDataStore(String id); } diff --git a/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolManagerImpl.java b/platform/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java similarity index 98% rename from platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolManagerImpl.java rename to platform/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java index 5fccf50a3f1..6faf6d7a16b 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolManagerImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java @@ -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 _storageProviders; @Inject diff --git a/platform/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java b/platform/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java index c160bc60d34..79aa6456151 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java +++ b/platform/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java @@ -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 diff --git a/platform/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/platform/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index ca12b4d8ed5..a44f82d83c8 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -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; } } diff --git a/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java b/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java index 1f8da577a0b..0f297278fdf 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java +++ b/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java @@ -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, StateDao 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); } diff --git a/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java b/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java index 7f416969dfc..ca51bac7866 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java @@ -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 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; } } diff --git a/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java b/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java index 651b2b68a6b..7f2cede9c29 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java +++ b/platform/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java @@ -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();