Search in sources :

Example 1 with StoragePoolHostVO

use of com.cloud.storage.StoragePoolHostVO in project cosmic by MissionCriticalCloud.

the class StoragePoolHostDaoImpl method deletePrimaryRecordsForHost.

/**
 * This method deletes the primary records from the host
 *
 * @param hostId -- id of the host
 */
@Override
public void deletePrimaryRecordsForHost(final long hostId) {
    final SearchCriteria<StoragePoolHostVO> sc = HostSearch.create();
    sc.setParameters("host_id", hostId);
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    remove(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 2 with StoragePoolHostVO

use of com.cloud.storage.StoragePoolHostVO in project cosmic by MissionCriticalCloud.

the class DefaultHostListener method hostConnect.

@Override
public boolean hostConnect(final long hostId, final long poolId) throws StorageConflictException {
    final StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    final ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
    final Answer answer = agentMgr.easySend(hostId, cmd);
    if (answer == null) {
        throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
    }
    if (!answer.getResult()) {
        final String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
        alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
        throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
    }
    assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
    final ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
    if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
        final String datastoreName = mspAnswer.getLocalDatastoreName();
        final List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
        for (final StoragePoolVO localStoragePool : localStoragePools) {
            if (datastoreName.equals(localStoragePool.getPath())) {
                s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
                throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
            }
        }
    }
    StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId);
    if (poolHost == null) {
        poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
        storagePoolHostDao.persist(poolHost);
    } else {
        poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
    }
    final StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
    poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes());
    poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
    primaryStoreDao.update(pool.getId(), poolVO);
    s_logger.info("Connection established between storage pool " + pool + " and host " + hostId);
    return true;
}
Also used : ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) StorageConflictException(com.cloud.exception.StorageConflictException) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 3 with StoragePoolHostVO

use of com.cloud.storage.StoragePoolHostVO in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreLifeCycleImpl method deleteDataStore.

@DB
@Override
public boolean deleteDataStore(final DataStore store) {
    final List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(store.getId());
    final StoragePool pool = (StoragePool) store;
    boolean deleteFlag = false;
    // find the hypervisor where the storage is attached to.
    HypervisorType hType = null;
    if (hostPoolRecords.size() > 0) {
        hType = getHypervisorType(hostPoolRecords.get(0).getHostId());
    }
    // Remove the SR associated with the Xenserver
    for (final StoragePoolHostVO host : hostPoolRecords) {
        final DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(pool);
        final Answer answer = agentMgr.easySend(host.getHostId(), deleteCmd);
        if (answer != null && answer.getResult()) {
            deleteFlag = true;
            // if host is KVM hypervisor then send deleteStoragepoolcmd to all the kvm hosts.
            if (HypervisorType.KVM != hType) {
                break;
            }
        } else {
            if (answer != null) {
                s_logger.debug("Failed to delete storage pool: " + answer.getResult());
            }
        }
    }
    if (!hostPoolRecords.isEmpty() && !deleteFlag) {
        throw new CloudRuntimeException("Failed to delete storage pool on host");
    }
    return dataStoreHelper.deletePrimaryDataStore(store);
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) DB(com.cloud.utils.db.DB)

Example 4 with StoragePoolHostVO

use of com.cloud.storage.StoragePoolHostVO in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method doDeleteHost.

@DB
protected boolean doDeleteHost(final long hostId, final boolean isForced, final boolean isForceDeleteStorage) {
    _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    // Verify that host exists
    final HostVO host = _hostDao.findById(hostId);
    if (host == null) {
        throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId());
    if (!isForced && host.getResourceState() != ResourceState.Maintenance) {
        throw new CloudRuntimeException("Host " + host.getUuid() + " cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
    }
    // Get storage pool host mappings here because they can be removed as a
    // part of handleDisconnect later
    // TODO: find out the bad boy, what's a buggy logic!
    final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
    final ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer) dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST, false, host, isForced, isForceDeleteStorage);
    if (answer == null) {
        throw new CloudRuntimeException("No resource adapter respond to DELETE_HOST event for " + host.getName() + " id = " + hostId + ", hypervisorType is " + host.getHypervisorType() + ", host type is " + host.getType());
    }
    if (answer.getIsException()) {
        return false;
    }
    if (!answer.getIsContinue()) {
        return true;
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            _dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
            _agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.Remove);
            // delete host details
            _hostDetailsDao.deleteDetails(hostId);
            // if host is GPU enabled, delete GPU entries
            _hostGpuGroupsDao.deleteGpuEntries(hostId);
            // delete host tags
            _hostTagsDao.deleteTags(hostId);
            host.setGuid(null);
            final Long clusterId = host.getClusterId();
            host.setClusterId(null);
            _hostDao.update(host.getId(), host);
            _hostDao.remove(hostId);
            if (clusterId != null) {
                final List<HostVO> hosts = listAllHostsInCluster(clusterId);
                if (hosts.size() == 0) {
                    final ClusterVO cluster = _clusterDao.findById(clusterId);
                    cluster.setGuid(null);
                    _clusterDao.update(clusterId, cluster);
                }
            }
            try {
                resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId);
            } catch (final NoTransitionException e) {
                s_logger.debug("Cannot transmit host " + host.getId() + " to Enabled state", e);
            }
            // Delete the associated entries in host ref table
            _storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
            // Make sure any VMs that were marked as being on this host are cleaned up
            final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
            for (final VMInstanceVO vm : vms) {
                // this is how VirtualMachineManagerImpl does it when it syncs VM states
                vm.setState(State.Stopped);
                vm.setHostId(null);
                _vmDao.persist(vm);
            }
            // where
            for (final StoragePoolHostVO pool : pools) {
                final Long poolId = pool.getPoolId();
                final StoragePoolVO storagePool = _storagePoolDao.findById(poolId);
                if (storagePool.isLocal() && isForceDeleteStorage) {
                    storagePool.setUuid(null);
                    storagePool.setClusterId(null);
                    _storagePoolDao.update(poolId, storagePool);
                    _storagePoolDao.remove(poolId);
                    s_logger.debug("Local storage id=" + poolId + " is removed as a part of host removal id=" + hostId);
                }
            }
            // delete the op_host_capacity entry
            final Object[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY };
            final SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao.createSearchCriteria();
            hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
            hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
            _capacityDao.remove(hostCapacitySC);
            // remove from dedicated resources
            final DedicatedResourceVO dr = _dedicatedDao.findByHostId(hostId);
            if (dr != null) {
                _dedicatedDao.remove(dr.getId());
            }
        }
    });
    return true;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) SearchCriteria(com.cloud.utils.db.SearchCriteria) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) DB(com.cloud.utils.db.DB)

Example 5 with StoragePoolHostVO

use of com.cloud.storage.StoragePoolHostVO in project cosmic by MissionCriticalCloud.

the class TemplateManagerImpl method prepareTemplateForCreate.

@Override
@DB
public VMTemplateStoragePoolVO prepareTemplateForCreate(final VMTemplateVO templ, final StoragePool pool) {
    final VMTemplateVO template = _tmpltDao.findById(templ.getId(), true);
    final long poolId = pool.getId();
    final long templateId = template.getId();
    final VMTemplateStoragePoolVO templateStoragePoolRef;
    final TemplateDataStoreVO templateStoreRef;
    templateStoragePoolRef = _tmpltPoolDao.findByPoolTemplate(poolId, templateId);
    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;
    }
    final 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);
        }
        final DataStore srcSecStore = _dataStoreMgr.getDataStore(templateStoreRef.getDataStoreId(), DataStoreRole.Image);
        final TemplateInfo srcTemplate = _tmplFactory.getTemplate(templateId, srcSecStore);
        final AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.prepareTemplateOnPrimary(srcTemplate, pool);
        try {
            final TemplateApiResult result = future.get();
            if (result.isFailed()) {
                s_logger.debug("prepare template failed:" + result.getResult());
                return null;
            }
            return _tmpltPoolDao.findByPoolTemplate(poolId, templateId);
        } catch (final 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(com.cloud.engine.subsystem.api.storage.TemplateInfo) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) TemplateApiResult(com.cloud.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) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) MalformedURLException(java.net.MalformedURLException) DB(com.cloud.utils.db.DB)

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