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);
}
}
}
}
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));
}
}
}
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);
}
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;
}
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());
}
Aggregations