use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.
the class SolidFireSharedPrimaryDataStoreLifeCycle method deleteDataStore.
// invoked to delete primary storage that is based on the SolidFire plug-in
@Override
public boolean deleteDataStore(DataStore dataStore) {
List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(dataStore.getId());
HypervisorType hypervisorType = null;
if (hostPoolRecords.size() > 0) {
hypervisorType = getHypervisorType(hostPoolRecords.get(0).getHostId());
}
if (!isSupportedHypervisorType(hypervisorType)) {
throw new CloudRuntimeException(hypervisorType + " is not a supported hypervisor type.");
}
StoragePool storagePool = (StoragePool) dataStore;
StoragePoolVO storagePoolVO = _primaryDataStoreDao.findById(storagePool.getId());
List<VMTemplateStoragePoolVO> unusedTemplatesInPool = _tmpltMgr.getUnusedTemplatesInPool(storagePoolVO);
for (VMTemplateStoragePoolVO templatePoolVO : unusedTemplatesInPool) {
_tmpltMgr.evictTemplateFromStoragePool(templatePoolVO);
}
Long clusterId = null;
for (StoragePoolHostVO host : hostPoolRecords) {
DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(storagePool);
if (HypervisorType.VMware.equals(hypervisorType)) {
deleteCmd.setRemoveDatastore(true);
Map<String, String> details = new HashMap<String, String>();
StoragePoolDetailVO storagePoolDetail = _storagePoolDetailsDao.findDetail(storagePool.getId(), SolidFireUtil.DATASTORE_NAME);
details.put(DeleteStoragePoolCommand.DATASTORE_NAME, storagePoolDetail.getValue());
storagePoolDetail = _storagePoolDetailsDao.findDetail(storagePool.getId(), SolidFireUtil.IQN);
details.put(DeleteStoragePoolCommand.IQN, storagePoolDetail.getValue());
storagePoolDetail = _storagePoolDetailsDao.findDetail(storagePool.getId(), SolidFireUtil.STORAGE_VIP);
details.put(DeleteStoragePoolCommand.STORAGE_HOST, storagePoolDetail.getValue());
storagePoolDetail = _storagePoolDetailsDao.findDetail(storagePool.getId(), SolidFireUtil.STORAGE_PORT);
details.put(DeleteStoragePoolCommand.STORAGE_PORT, storagePoolDetail.getValue());
deleteCmd.setDetails(details);
}
final Answer answer = _agentMgr.easySend(host.getHostId(), deleteCmd);
if (answer != null && answer.getResult()) {
s_logger.info("Successfully deleted storage pool using Host ID " + host.getHostId());
HostVO hostVO = _hostDao.findById(host.getHostId());
if (hostVO != null) {
clusterId = hostVO.getClusterId();
}
break;
} else {
s_logger.error("Failed to delete storage pool using Host ID " + host.getHostId() + ": " + answer.getResult());
}
}
if (clusterId != null) {
ClusterVO cluster = _clusterDao.findById(clusterId);
GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
if (!lock.lock(SolidFireUtil.s_lockTimeInSeconds)) {
String errMsg = "Couldn't lock the DB on the following string: " + cluster.getUuid();
s_logger.debug(errMsg);
throw new CloudRuntimeException(errMsg);
}
try {
removeVolumeFromVag(storagePool.getId(), clusterId);
} finally {
lock.unlock();
lock.releaseRef();
}
}
deleteSolidFireVolume(storagePool.getId());
return _primaryDataStoreHelper.deletePrimaryDataStore(dataStore);
}
use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.
the class SolidFireHostListener method hostConnect.
@Override
public boolean hostConnect(long hostId, long storagePoolId) {
HostVO host = _hostDao.findById(hostId);
StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId);
if (storagePoolHost == null) {
storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, "");
storagePoolHostDao.persist(storagePoolHost);
}
if (host.getHypervisorType().equals(HypervisorType.XenServer)) {
handleXenServer(host.getClusterId(), host.getId(), storagePoolId);
} else if (host.getHypervisorType().equals(HypervisorType.KVM)) {
handleKVM(hostId, storagePoolId);
}
return true;
}
use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.
the class StoragePoolHostDaoImpl method listByHostStatus.
@Override
public List<StoragePoolHostVO> listByHostStatus(long poolId, Status hostStatus) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
String sql = HOST_FOR_POOL_SEARCH;
List<StoragePoolHostVO> result = new ArrayList<StoragePoolHostVO>();
try (PreparedStatement pstmt = txn.prepareStatement(sql)) {
pstmt.setLong(1, poolId);
pstmt.setString(2, hostStatus.toString());
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
// result.add(toEntityBean(rs, false)); TODO: this is buggy in
// GenericDaoBase for hand constructed queries
// ID column
long id = rs.getLong(1);
result.add(findById(id));
}
} catch (SQLException e) {
s_logger.warn("listByHostStatus:Exception: ", e);
}
} catch (Exception e) {
s_logger.warn("listByHostStatus:Exception: ", e);
}
return result;
}
use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.
the class StoragePoolHostDaoImpl method deletePrimaryRecordsForHost.
/**
* This method deletes the primary records from the host
*
* @param hostId
* -- id of the host
*/
@Override
public void deletePrimaryRecordsForHost(long hostId) {
SearchCriteria<StoragePoolHostVO> sc = HostSearch.create();
sc.setParameters("host_id", hostId);
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
remove(sc);
txn.commit();
}
use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.
the class StoragePoolHostDaoImpl method deleteStoragePoolHostDetails.
@Override
public void deleteStoragePoolHostDetails(long hostId, long poolId) {
SearchCriteria<StoragePoolHostVO> sc = PoolHostSearch.create();
sc.setParameters("host_id", hostId);
sc.setParameters("pool_id", poolId);
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
remove(sc);
txn.commit();
}
Aggregations