use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.
the class TemplateManagerImpl method prepareTemplateForCreate.
@Override
@DB
public VMTemplateStoragePoolVO prepareTemplateForCreate(VMTemplateVO templ, StoragePool pool) {
VMTemplateVO template = _tmpltDao.findById(templ.getId(), true);
long poolId = pool.getId();
long templateId = template.getId();
VMTemplateStoragePoolVO templateStoragePoolRef = null;
TemplateDataStoreVO templateStoreRef = null;
templateStoragePoolRef = _tmpltPoolDao.findByPoolTemplate(poolId, templateId, null);
if (templateStoragePoolRef != null) {
templateStoragePoolRef.setMarkedForGC(false);
_tmpltPoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + templateId + " has already been downloaded to pool " + poolId);
}
return templateStoragePoolRef;
}
}
templateStoreRef = _tmplStoreDao.findByTemplateZoneDownloadStatus(templateId, pool.getDataCenterId(), VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
if (templateStoreRef == null) {
s_logger.error("Unable to find a secondary storage host who has completely downloaded the template.");
return null;
}
List<StoragePoolHostVO> vos = _poolHostDao.listByHostStatus(poolId, com.cloud.host.Status.Up);
if (vos == null || vos.isEmpty()) {
throw new CloudRuntimeException("Cannot download " + templateId + " to poolId " + poolId + " since there is no host in the Up state connected to this pool");
}
if (templateStoragePoolRef == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Downloading template " + templateId + " to pool " + poolId);
}
DataStore srcSecStore = _dataStoreMgr.getDataStore(templateStoreRef.getDataStoreId(), DataStoreRole.Image);
TemplateInfo srcTemplate = _tmplFactory.getTemplate(templateId, srcSecStore);
AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.prepareTemplateOnPrimary(srcTemplate, pool);
try {
TemplateApiResult result = future.get();
if (result.isFailed()) {
s_logger.debug("prepare template failed:" + result.getResult());
return null;
}
return _tmpltPoolDao.findByPoolTemplate(poolId, templateId, null);
} catch (Exception ex) {
s_logger.debug("failed to copy template from image store:" + srcSecStore.getName() + " to primary storage");
}
}
return null;
}
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;
Long hostId = null;
for (StoragePoolHostVO host : hostPoolRecords) {
DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(storagePool);
if (HypervisorType.VMware.equals(hypervisorType)) {
deleteCmd.setRemoveDatastore(true);
Map<String, String> details = new HashMap<>();
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()) {
LOGGER.info("Successfully deleted storage pool using Host ID " + host.getHostId());
HostVO hostVO = hostDao.findById(host.getHostId());
if (hostVO != null) {
clusterId = hostVO.getClusterId();
hostId = hostVO.getId();
}
break;
} else {
if (answer != null) {
LOGGER.error("Failed to delete storage pool using Host ID " + host.getHostId() + ": " + answer.getResult());
} else {
LOGGER.error("Failed to delete storage pool using Host ID " + host.getHostId());
}
}
}
if (clusterId != null) {
ClusterVO cluster = clusterDao.findById(clusterId);
GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
if (!lock.lock(SolidFireUtil.LOCK_TIME_IN_SECONDS)) {
String errMsg = "Couldn't lock the DB on the following string: " + cluster.getUuid();
LOGGER.debug(errMsg);
throw new CloudRuntimeException(errMsg);
}
try {
long sfVolumeId = getVolumeId(storagePool.getId());
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePool.getId(), storagePoolDetailsDao);
List<SolidFireUtil.SolidFireVag> sfVags = SolidFireUtil.getAllVags(sfConnection);
for (SolidFireUtil.SolidFireVag sfVag : sfVags) {
if (SolidFireUtil.sfVagContains(sfVag, sfVolumeId, clusterId, hostDao)) {
SolidFireUtil.removeVolumeIdsFromSolidFireVag(sfConnection, sfVag.getId(), new Long[] { sfVolumeId });
}
}
} finally {
lock.unlock();
lock.releaseRef();
}
}
if (hostId != null) {
handleTargetsForVMware(hostId, storagePool.getId());
}
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 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();
}
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();
}
Aggregations