Search in sources :

Example 86 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class NotAValidCommand method testModifyStoragePoolCommand.

@Test
public void testModifyStoragePoolCommand() {
    final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final ModifyStoragePoolCommand modifyStorageCommand = new ModifyStoragePoolCommand(false, poolVO);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(modifyStorageCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 87 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class DateraHostListener method hostRemoved.

@Override
public boolean hostRemoved(long hostId, long clusterId) {
    ClusterVO clusterVO = _clusterDao.findById(clusterId);
    HostVO hostVO = _hostDao.findByIdIncludingRemoved(hostId);
    String initiatorName = DateraUtil.INITIATOR_PREFIX + "-" + hostVO.getUuid();
    int s_lockTimeInSeconds = 5;
    GlobalLock lock = GlobalLock.getInternLock(clusterVO.getUuid());
    if (!lock.lock(s_lockTimeInSeconds)) {
        String errMsg = "Couldn't lock the DB on the following string: " + clusterVO.getUuid();
        s_logger.debug(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    try {
        List<StoragePoolVO> storagePools = _storagePoolDao.findPoolsByProvider(DateraUtil.PROVIDER_NAME);
        if (storagePools != null && storagePools.size() > 0) {
            for (StoragePoolVO storagePool : storagePools) {
                ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, DateraUtil.getInitiatorGroupKey(storagePool.getId()));
                String initiatorGroupName = clusterDetail != null ? clusterDetail.getValue() : null;
                if (initiatorGroupName != null && DateraUtil.hostSupport_iScsi(hostVO)) {
                    DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePool.getId(), _storagePoolDetailsDao);
                    DateraObject.Initiator initiator = DateraUtil.getInitiator(conn, hostVO.getStorageUrl());
                    DateraObject.InitiatorGroup initiatorGroup = DateraUtil.getInitiatorGroup(conn, initiatorGroupName);
                    if (initiator != null && DateraUtil.isInitiatorPresentInGroup(initiator, initiatorGroup)) {
                        DateraUtil.removeInitiatorFromGroup(conn, initiator.getPath(), initiatorGroupName);
                    }
                }
            }
        }
    } catch (DateraObject.DateraError | UnsupportedEncodingException e) {
        s_logger.warn("Error while removing host from initiator groups ", e);
    } finally {
        lock.unlock();
        lock.releaseRef();
    }
    return true;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) GlobalLock(com.cloud.utils.db.GlobalLock) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DateraObject(org.apache.cloudstack.storage.datastore.util.DateraObject) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO)

Example 88 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method updateVolumePathDetails.

private void updateVolumePathDetails(VolumeObject vol, ResizeVolumeAnswer answer) {
    VolumeVO volumeVO = volumeDao.findById(vol.getId());
    String datastoreUUID = answer.getContextParam("datastoreUUID");
    if (datastoreUUID != null) {
        StoragePoolVO storagePoolVO = primaryStoreDao.findByUuid(datastoreUUID);
        if (storagePoolVO != null) {
            volumeVO.setPoolId(storagePoolVO.getId());
        } else {
            s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreUUID, vol.getId()));
        }
    }
    String volumePath = answer.getContextParam("volumePath");
    if (volumePath != null) {
        volumeVO.setPath(volumePath);
    }
    String chainInfo = answer.getContextParam("chainInfo");
    if (chainInfo != null) {
        volumeVO.setChainInfo(chainInfo);
    }
    volumeDao.update(volumeVO.getId(), volumeVO);
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 89 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method copyAsync.

@Override
public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
    DataStore store = destData.getDataStore();
    if (store.getRole() == DataStoreRole.Primary) {
        if ((srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.TEMPLATE)) {
            // For CLVM, we need to copy template to primary storage at all, just fake the copy result.
            TemplateObjectTO templateObjectTO = new TemplateObjectTO();
            templateObjectTO.setPath(UUID.randomUUID().toString());
            templateObjectTO.setSize(srcdata.getSize());
            templateObjectTO.setPhysicalSize(srcdata.getSize());
            templateObjectTO.setFormat(Storage.ImageFormat.RAW);
            CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
            CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        } else if (srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.VOLUME) {
            // For CLVM, we need to pass template on secondary storage to hypervisor
            int primaryStorageDownloadWait = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
            StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
            DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
            DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
            CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), primaryStorageDownloadWait, true);
            EndPoint ep = epSelector.select(srcData, destData);
            Answer answer = null;
            if (ep == null) {
                String errMsg = "No remote endpoint to send CopyCommand, check if host or ssvm is down?";
                s_logger.error(errMsg);
                answer = new Answer(cmd, false, errMsg);
            } else {
                answer = ep.sendMessage(cmd);
            }
            CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        } else if (srcdata.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.VOLUME) {
            SnapshotObjectTO srcTO = (SnapshotObjectTO) srcdata.getTO();
            CopyCommand cmd = new CopyCommand(srcTO, destData.getTO(), StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value(), true);
            EndPoint ep = epSelector.select(srcdata, destData);
            CopyCmdAnswer answer = null;
            if (ep == null) {
                String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
                s_logger.error(errMsg);
                answer = new CopyCmdAnswer(errMsg);
            } else {
                answer = (CopyCmdAnswer) ep.sendMessage(cmd);
            }
            CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        }
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 90 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class LinstorPrimaryDataStoreDriverImpl method deleteAsync.

@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
    s_logger.debug("deleteAsync: " + dataObject.getType() + ";" + dataObject.getUuid());
    String errMsg = null;
    final long storagePoolId = dataStore.getId();
    final StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
    switch(dataObject.getType()) {
        case VOLUME:
            {
                final VolumeInfo volumeInfo = (VolumeInfo) dataObject;
                final String rscName = LinstorUtil.RSC_PREFIX + volumeInfo.getPath();
                deleteResourceDefinition(storagePool, rscName);
                long usedBytes = storagePool.getUsedBytes();
                long capacityIops = storagePool.getCapacityIops();
                usedBytes -= volumeInfo.getSize();
                if (volumeInfo.getMaxIops() != null)
                    capacityIops += volumeInfo.getMaxIops();
                storagePool.setUsedBytes(Math.max(0, usedBytes));
                storagePool.setCapacityIops(Math.max(0, capacityIops));
                _storagePoolDao.update(storagePoolId, storagePool);
            }
            break;
        case SNAPSHOT:
            final SnapshotInfo snapshotInfo = (SnapshotInfo) dataObject;
            final String rscName = LinstorUtil.RSC_PREFIX + snapshotInfo.getBaseVolume().getPath();
            deleteSnapshot(dataStore, rscName, getSnapshotName(snapshotInfo.getUuid()));
            long usedBytes = storagePool.getUsedBytes() - snapshotInfo.getSize();
            storagePool.setUsedBytes(Math.max(0, usedBytes));
            _storagePoolDao.update(storagePoolId, storagePool);
            break;
        default:
            errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
            s_logger.error(errMsg);
    }
    if (callback != null) {
        CommandResult result = new CommandResult();
        result.setResult(errMsg);
        callback.complete(result);
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)276 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)106 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)75 ArrayList (java.util.ArrayList)54 VolumeVO (com.cloud.storage.VolumeVO)53 HostVO (com.cloud.host.HostVO)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)45 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)45 HashMap (java.util.HashMap)44 Answer (com.cloud.agent.api.Answer)38 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)35 StoragePool (com.cloud.storage.StoragePool)33 Test (org.junit.Test)33 VMInstanceVO (com.cloud.vm.VMInstanceVO)25 Map (java.util.Map)25 Account (com.cloud.user.Account)24 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)20 ExecutionException (java.util.concurrent.ExecutionException)20 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 ClusterVO (com.cloud.dc.ClusterVO)18