Search in sources :

Example 96 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class VirtualMachineManagerImpl method handlePath.

// for managed storage on KVM, need to make sure the path field of the volume in question is populated with the IQN
private void handlePath(final DiskTO[] disks, final HypervisorType hypervisorType) {
    if (hypervisorType != HypervisorType.KVM) {
        return;
    }
    if (disks != null) {
        for (final DiskTO disk : disks) {
            final Map<String, String> details = disk.getDetails();
            final boolean isManaged = details != null && Boolean.parseBoolean(details.get(DiskTO.MANAGED));
            if (isManaged && disk.getPath() == null) {
                final Long volumeId = disk.getData().getId();
                final VolumeVO volume = _volsDao.findById(volumeId);
                disk.setPath(volume.get_iScsiName());
                if (disk.getData() instanceof VolumeObjectTO) {
                    final VolumeObjectTO volTo = (VolumeObjectTO) disk.getData();
                    volTo.setPath(volume.get_iScsiName());
                }
                volume.setPath(volume.get_iScsiName());
                _volsDao.update(volumeId, volume);
            }
        }
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 97 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class VMEntityManagerImpl method reserveVirtualMachine.

@Override
public String reserveVirtualMachine(VMEntityVO vmEntityVO, DeploymentPlanner plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude) throws InsufficientCapacityException, ResourceUnavailableException {
    //call planner and get the deployDestination.
    //load vm instance and offerings and call virtualMachineManagerImpl
    //FIXME: profile should work on VirtualMachineEntity
    VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
    VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm);
    vmProfile.setServiceOffering(_serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()));
    DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
    if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
        plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
    }
    boolean planChangedByReadyVolume = false;
    List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    if (!vols.isEmpty()) {
        VolumeVO vol = vols.get(0);
        StoragePool pool = (StoragePool) dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
        if (!pool.isInMaintenance()) {
            long rootVolDcId = pool.getDataCenterId();
            Long rootVolPodId = pool.getPodId();
            Long rootVolClusterId = pool.getClusterId();
            if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
                Long clusterIdSpecified = planToDeploy.getClusterId();
                if (clusterIdSpecified != null && rootVolClusterId != null) {
                    if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
                        // planner
                        throw new ResourceUnavailableException("Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for " + vm, Cluster.class, clusterIdSpecified);
                    }
                }
                plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, null);
            } else {
                plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
                planChangedByReadyVolume = true;
            }
        }
    }
    while (true) {
        DeployDestination dest = null;
        try {
            dest = _dpMgr.planDeployment(vmProfile, plan, exclude, plannerToUse);
        } catch (AffinityConflictException e) {
            throw new CloudRuntimeException("Unable to create deployment, affinity rules associated to the VM conflict");
        }
        if (dest != null) {
            String reservationId = _dpMgr.finalizeReservation(dest, vmProfile, plan, exclude, plannerToUse);
            if (reservationId != null) {
                return reservationId;
            } else {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Cannot finalize the VM reservation for this destination found, retrying");
                }
                exclude.addHost(dest.getHost().getId());
                continue;
            }
        } else if (planChangedByReadyVolume) {
            // call retry it.
            return UUID.randomUUID().toString();
        } else {
            throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId(), areAffinityGroupsAssociated(vmProfile));
        }
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StoragePool(com.cloud.storage.StoragePool) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) VMInstanceVO(com.cloud.vm.VMInstanceVO) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) AffinityConflictException(com.cloud.exception.AffinityConflictException) DataCenter(com.cloud.dc.DataCenter) VolumeVO(com.cloud.storage.VolumeVO) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 98 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class PrimaryDataStoreImpl method create.

/**
     * Please read the comment for the create(DataObject) method if you are planning on passing in "false" for createEntryInTempSpoolRef.
     */
@Override
public DataObject create(DataObject obj, boolean createEntryInTempSpoolRef) {
    // create template on primary storage
    if (obj.getType() == DataObjectType.TEMPLATE && (!isManaged() || (createEntryInTempSpoolRef && canCloneVolume()))) {
        try {
            String templateIdPoolIdString = "templateId:" + obj.getId() + "poolId:" + getId();
            VMTemplateStoragePoolVO templateStoragePoolRef;
            GlobalLock lock = GlobalLock.getInternLock(templateIdPoolIdString);
            if (!lock.lock(5)) {
                s_logger.debug("Couldn't lock the db on the string " + templateIdPoolIdString);
                return null;
            }
            try {
                templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId());
                if (templateStoragePoolRef == null) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Not found (" + templateIdPoolIdString + ") in template_spool_ref, persisting it");
                    }
                    templateStoragePoolRef = new VMTemplateStoragePoolVO(getId(), obj.getId());
                    templateStoragePoolRef = templatePoolDao.persist(templateStoragePoolRef);
                }
            } catch (Throwable t) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Failed to insert (" + templateIdPoolIdString + ") to template_spool_ref", t);
                }
                templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId());
                if (templateStoragePoolRef == null) {
                    throw new CloudRuntimeException("Failed to create template storage pool entry");
                } else {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Another thread already inserts " + templateStoragePoolRef.getId() + " to template_spool_ref", t);
                    }
                }
            } finally {
                lock.unlock();
                lock.releaseRef();
            }
        } catch (Exception e) {
            s_logger.debug("Caught exception ", e);
        }
    } else if (obj.getType() == DataObjectType.SNAPSHOT) {
        return objectInStoreMgr.create(obj, this);
    } else if (obj.getType() == DataObjectType.VOLUME) {
        VolumeVO vol = volumeDao.findById(obj.getId());
        if (vol != null) {
            vol.setPoolId(getId());
            volumeDao.update(vol.getId(), vol);
        }
    }
    return objectInStoreMgr.get(obj, this);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) GlobalLock(com.cloud.utils.db.GlobalLock) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 99 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class VolumeDataFactoryImpl method getVolume.

@Override
public VolumeInfo getVolume(long volumeId, DataStoreRole storeRole) {
    VolumeVO volumeVO = volumeDao.findById(volumeId);
    VolumeObject vol = null;
    if (storeRole == DataStoreRole.Image) {
        VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
        if (volumeStore != null) {
            DataStore store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
            vol = VolumeObject.getVolumeObject(store, volumeVO);
        }
    } else {
        // Primary data store
        if (volumeVO.getPoolId() != null) {
            DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
            vol = VolumeObject.getVolumeObject(store, volumeVO);
        }
    }
    return vol;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

Example 100 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class VolumeTest method testDeleteDisk.

@Test
public void testDeleteDisk() throws InterruptedException, ExecutionException, ConcurrentOperationException {
    DataStore primaryStore = createPrimaryDataStore();
    primaryStoreId = primaryStore.getId();
    primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId);
    VolumeVO volume = createVolume(null, primaryStore.getId());
    VolumeInfo volInfo = this.volFactory.getVolume(volume.getId());
    AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeAsync(volInfo, primaryStore);
    VolumeApiResult result = future.get();
    Assert.assertTrue(result.isSuccess());
    VolumeInfo vol = result.getVolume();
    boolean res = this.volumeService.destroyVolume(volInfo.getId());
    Assert.assertTrue(res);
    volInfo = this.volFactory.getVolume(vol.getId());
    future = this.volumeService.expungeVolumeAsync(volInfo);
    result = future.get();
    Assert.assertTrue(result.isSuccess());
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) Test(org.testng.annotations.Test)

Aggregations

VolumeVO (com.cloud.storage.VolumeVO)156 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)44 ArrayList (java.util.ArrayList)39 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)36 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 HostVO (com.cloud.host.HostVO)24 VMInstanceVO (com.cloud.vm.VMInstanceVO)24 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)22 Account (com.cloud.user.Account)19 HashMap (java.util.HashMap)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)16 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)16 StoragePool (com.cloud.storage.StoragePool)15 HostPodVO (com.cloud.dc.HostPodVO)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 Pair (com.cloud.utils.Pair)13 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)11 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)11 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)11