use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class VmwareResource method examineStorageSubSystemCommandFullCloneFlagForVmware.
/**
* Examine StorageSubSystem command to get full clone flag, if provided
*
* @param cmd command to execute
* @param params params
* @return copy of params including new values, if suitable
*/
protected EnumMap<VmwareStorageProcessorConfigurableFields, Object> examineStorageSubSystemCommandFullCloneFlagForVmware(CopyCommand cmd, EnumMap<VmwareStorageProcessorConfigurableFields, Object> params) {
EnumMap<VmwareStorageProcessorConfigurableFields, Object> paramsCopy = new EnumMap<VmwareStorageProcessorConfigurableFields, Object>(params);
HypervisorType hypervisor = cmd.getDestTO().getHypervisorType();
if (hypervisor != null && hypervisor.equals(HypervisorType.VMware)) {
DataStoreTO destDataStore = cmd.getDestTO().getDataStore();
if (destDataStore instanceof PrimaryDataStoreTO) {
PrimaryDataStoreTO dest = (PrimaryDataStoreTO) destDataStore;
if (dest.isFullCloneFlag() != null) {
paramsCopy.put(VmwareStorageProcessorConfigurableFields.FULL_CLONE_FLAG, dest.isFullCloneFlag().booleanValue());
}
if (dest.getDiskProvisioningStrictnessFlag() != null) {
paramsCopy.put(VmwareStorageProcessorConfigurableFields.DISK_PROVISIONING_STRICTNESS, dest.getDiskProvisioningStrictnessFlag().booleanValue());
}
}
}
return paramsCopy;
}
use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class DirectDownloadManagerImpl method downloadTemplate.
@Override
public void downloadTemplate(long templateId, long poolId, long hostId) {
VMTemplateVO template = vmTemplateDao.findById(templateId);
StoragePoolVO pool = primaryDataStoreDao.findById(poolId);
HostVO host = hostDao.findById(hostId);
if (pool == null) {
throw new CloudRuntimeException("Storage pool " + poolId + " could not be found");
}
if (template == null) {
throw new CloudRuntimeException("Template " + templateId + " could not be found");
}
if (host == null) {
throw new CloudRuntimeException("Host " + hostId + " could not be found");
}
if (!template.isDirectDownload()) {
throw new CloudRuntimeException("Template " + templateId + " is not marked for direct download");
}
Map<String, String> details = template.getDetails();
String url = template.getUrl();
String checksum = template.getChecksum();
Map<String, String> headers = getHeadersFromDetails(details);
DataStore store = dataStoreManager.getDataStore(poolId, DataStoreRole.Primary);
if (store == null) {
throw new CloudRuntimeException("Data store " + poolId + " could not be found");
}
PrimaryDataStore primaryDataStore = (PrimaryDataStore) store;
PrimaryDataStoreTO to = (PrimaryDataStoreTO) primaryDataStore.getTO();
DownloadProtocol protocol = getProtocolFromUrl(url);
DirectDownloadCommand cmd = getDirectDownloadCommandFromProtocol(protocol, url, templateId, to, checksum, headers);
cmd.setTemplateSize(template.getSize());
cmd.setFormat(template.getFormat());
if (tmplFactory.getTemplate(templateId, store) != null) {
cmd.setDestData((TemplateObjectTO) tmplFactory.getTemplate(templateId, store).getTO());
}
int cmdTimeOut = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
cmd.setWait(cmdTimeOut);
Answer answer = sendDirectDownloadCommand(cmd, template, poolId, host);
VMTemplateStoragePoolVO sPoolRef = vmTemplatePoolDao.findByPoolTemplate(poolId, templateId, null);
if (sPoolRef == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Not found (templateId:" + templateId + " poolId: " + poolId + ") in template_spool_ref, persisting it");
}
DirectDownloadAnswer ans = (DirectDownloadAnswer) answer;
sPoolRef = new VMTemplateStoragePoolVO(poolId, templateId, null);
sPoolRef.setDownloadPercent(100);
sPoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
sPoolRef.setState(ObjectInDataStoreStateMachine.State.Ready);
sPoolRef.setTemplateSize(ans.getTemplateSize());
sPoolRef.setLocalDownloadPath(ans.getInstallPath());
sPoolRef.setInstallPath(ans.getInstallPath());
vmTemplatePoolDao.persist(sPoolRef);
} else {
// For managed storage, update after template downloaded and copied to the disk
DirectDownloadAnswer ans = (DirectDownloadAnswer) answer;
sPoolRef.setDownloadPercent(100);
sPoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
sPoolRef.setState(ObjectInDataStoreStateMachine.State.Ready);
sPoolRef.setTemplateSize(ans.getTemplateSize());
sPoolRef.setLocalDownloadPath(ans.getInstallPath());
sPoolRef.setInstallPath(ans.getInstallPath());
vmTemplatePoolDao.update(sPoolRef.getId(), sPoolRef);
}
}
use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method needCacheStorage.
private boolean needCacheStorage(DataObject srcData, DataObject destData) {
DataTO srcTO = srcData.getTO();
DataStoreTO srcStoreTO = srcTO.getDataStore();
DataTO destTO = destData.getTO();
DataStoreTO destStoreTO = destTO.getDataStore();
// both snapshot and volume are on primary datastore - no need for a cache storage as hypervisor will copy directly
if (srcStoreTO instanceof PrimaryDataStoreTO && destStoreTO instanceof PrimaryDataStoreTO) {
return false;
}
if (srcStoreTO instanceof NfsTO || srcStoreTO.getRole() == DataStoreRole.ImageCache) {
return false;
}
if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) {
return false;
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("needCacheStorage true; dest at " + destTO.getPath() + ", dest role " + destStoreTO.getRole().toString() + "; src at " + srcTO.getPath() + ", src role " + srcStoreTO.getRole().toString());
}
return true;
}
use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class LibvirtComputingResource method getVolumePath.
public String getVolumePath(final Connect conn, final DiskTO volume, boolean diskOnHostCache) throws LibvirtException, URISyntaxException {
final DataTO data = volume.getData();
final DataStoreTO store = data.getDataStore();
if (volume.getType() == Volume.Type.ISO && data.getPath() != null && (store instanceof NfsTO || store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload())) {
if (data.getPath().startsWith(ConfigDrive.CONFIGDRIVEDIR) && diskOnHostCache) {
String configDrivePath = getConfigPath() + "/" + data.getPath();
return configDrivePath;
}
final String isoPath = store.getUrl().split("\\?")[0] + File.separator + data.getPath();
final int index = isoPath.lastIndexOf("/");
final String path = isoPath.substring(0, index);
final String name = isoPath.substring(index + 1);
final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path);
final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
return isoVol.getPath();
} else {
return data.getPath();
}
}
use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class LibvirtCopyVolumeCommandWrapper method handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails.
private Answer handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails(CopyVolumeCommand command, LibvirtComputingResource libvirtComputingResource) {
KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
PrimaryDataStoreTO srcPrimaryDataStore = null;
KVMStoragePool secondaryStoragePool = null;
Map<String, String> srcDetails = command.getSrcDetails();
String srcPath = srcDetails.get(DiskTO.IQN);
if (srcPath == null) {
return new CopyVolumeAnswer(command, false, "No IQN was specified", null, null);
}
try {
LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
String destVolumeName = libvirtUtilitiesHelper.generateUUIDName() + ".qcow2";
String destVolumePath = command.getVolumePath() + File.separator;
String secondaryStorageUrl = command.getSecondaryStorageURL();
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
secondaryStoragePool.createFolder(File.separator + destVolumePath);
storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + File.separator + destVolumePath);
VolumeObjectTO srcVolumeObjectTO = (VolumeObjectTO) command.getSrcData();
srcPrimaryDataStore = (PrimaryDataStoreTO) srcVolumeObjectTO.getDataStore();
storagePoolMgr.connectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath, srcDetails);
KVMPhysicalDisk srcPhysicalDisk = storagePoolMgr.getPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
storagePoolMgr.copyPhysicalDisk(srcPhysicalDisk, destVolumeName, secondaryStoragePool, command.getWait() * 1000);
return new CopyVolumeAnswer(command, true, null, null, destVolumePath + destVolumeName);
} catch (final CloudRuntimeException e) {
return new CopyVolumeAnswer(command, false, e.toString(), null, null);
} finally {
try {
if (srcPrimaryDataStore != null) {
storagePoolMgr.disconnectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
}
} catch (Exception e) {
LOGGER.warn("Unable to disconnect from the source device.", e);
}
if (secondaryStoragePool != null) {
storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
}
}
}
Aggregations