Search in sources :

Example 26 with StoragePoolHostVO

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;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) TemplateApiResult(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) MalformedURLException(java.net.MalformedURLException) DB(com.cloud.utils.db.DB)

Example 27 with StoragePoolHostVO

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);
}
Also used : StoragePool(com.cloud.storage.StoragePool) ClusterVO(com.cloud.dc.ClusterVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HashMap(java.util.HashMap) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) GlobalLock(com.cloud.utils.db.GlobalLock) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil)

Example 28 with StoragePoolHostVO

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;
}
Also used : StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 29 with StoragePoolHostVO

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();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 30 with StoragePoolHostVO

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();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Aggregations

StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)33 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)12 StoragePool (com.cloud.storage.StoragePool)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)8 Answer (com.cloud.agent.api.Answer)7 HostVO (com.cloud.host.HostVO)7 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)7 DB (com.cloud.utils.db.DB)6 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)5 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)5 ArrayList (java.util.ArrayList)5 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)4 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)4 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)3 ClusterVO (com.cloud.dc.ClusterVO)3 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2