public String getVolumePath(final Connect conn, final DiskTO volume) 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())) { 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(); } }
protected Answer copyFromNfsToS3(CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); DataStoreTO srcDataStore = srcData.getDataStore(); NfsTO srcStore = (NfsTO)srcDataStore; DataStoreTO destDataStore = destData.getDataStore(); final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), _nfsVersion); s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3."); String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName(); if (destData.getObjectType() == DataObjectType.TEMPLATE) { TemplateObjectTO newTemplate = new TemplateObjectTO(); newTemplate.setPath(key); newTemplate.setFormat(format); retObj = newTemplate; } else if (destData.getObjectType() == DataObjectType.VOLUME) { VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setPath(key); newVol.setSize(srcFile.length()); retObj = newVol; } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) { SnapshotObjectTO newSnapshot = new SnapshotObjectTO(); newSnapshot.setPath(key); s_logger.error("failed to upload" + srcData.getPath(), e); return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
DataTO destData = copyCommand.getDestTO(); boolean isSourceDataHypervisorXenServer = srcData.getHypervisorType() == HypervisorType.XenServer; if (!isSourceDataHypervisorXenServer) { logger.debug("We are returning the default host to execute commands because the target hypervisor of the source data is not XenServer."); return defaultHostToExecuteCommands; DataStoreTO srcStore = srcData.getDataStore(); DataStoreTO destStore = destData.getDataStore(); boolean isSourceAndDestinationNfsObjects = srcStore instanceof NfsTO && destStore instanceof NfsTO; if (!isSourceAndDestinationNfsObjects) { return defaultHostToExecuteCommands; boolean isSourceObjectSnapshotTypeAndDestinationObjectTemplateType = srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE; if (!isSourceObjectSnapshotTypeAndDestinationObjectTemplateType) { logger.debug("We are returning the default host to execute commands because the source and destination objects are not snapshot and template respectively."); HostVO hostCandidateToExecutedCommand = hostDao.findHostInZoneToExecuteCommand(defaultHostToExecuteCommand.getDataCenterId(), srcData.getHypervisorType()); hostDao.loadDetails(hostCandidateToExecutedCommand); String hypervisorVersion = hostCandidateToExecutedCommand.getHypervisorVersion();
protected Answer execute(CopyCommand cmd) { DataTO srcData = cmd.getSrcTO(); DataTO destData = cmd.getDestTO(); DataStoreTO srcDataStore = srcData.getDataStore(); DataStoreTO destDataStore = destData.getDataStore(); if (srcData.getObjectType() == DataObjectType.TEMPLATE && (srcData.getDataStore().getRole() == DataStoreRole.Image || srcData.getDataStore().getRole() == DataStoreRole.ImageCache) && destData.getDataStore().getRole() == DataStoreRole.Primary) { } else if (srcData.getObjectType() == DataObjectType.TEMPLATE && srcDataStore.getRole() == DataStoreRole.Primary && destDataStore.getRole() == DataStoreRole.Primary) { } else if (srcData.getObjectType() == DataObjectType.VOLUME && (srcData.getDataStore().getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Image)) { } else if (srcData.getObjectType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Primary) { if (destData.getObjectType() == DataObjectType.VOLUME) { return processor.copyVolumeFromPrimaryToSecondary(cmd); } else if (destData.getObjectType() == DataObjectType.TEMPLATE) { return processor.createTemplateFromVolume(cmd); } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.SNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) { return processor.backupSnapshot(cmd); } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.VOLUME) { return processor.createVolumeFromSnapshot(cmd); } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) { return processor.createTemplateFromSnapshot(cmd);
/** * Adds {@code 'vmware.create.full.clone'} value for a given primary storage, whose HV is VMware, on datastore's {@code fullCloneFlag} field * @param dataTO Dest data store TO * @return dataTO including fullCloneFlag, if provided */ protected DataTO addFullCloneFlagOnVMwareDest(DataTO dataTO) { if (dataTO != null && dataTO.getHypervisorType().equals(Hypervisor.HypervisorType.VMware)){ DataStoreTO dataStoreTO = dataTO.getDataStore(); if (dataStoreTO != null && dataStoreTO instanceof PrimaryDataStoreTO){ PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO; Boolean value = CapacityManager.VmwareCreateCloneFull.valueIn(primaryDataStoreTO.getId()); primaryDataStoreTO.setFullCloneFlag(value); } } return dataTO; }
private Answer execute(final CopyCommand cmd) { URI agentUri = null; try { final String cmdName = cmd.getClass().getName(); agentUri = new URI("https", null, _agentIp, _port, "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; s_logger.error(errMsg, e); return null; } cleanPassword(cmd.getSrcTO().getDataStore()); cleanPassword(cmd.getDestTO().getDataStore()); // Send the cmd to hyperv agent. final String ansStr = postHttpRequest(s_gson.toJson(cmd), agentUri); if (ansStr == null) { return Answer.createUnsupportedCommandAnswer(cmd); } final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); final String logResult = cleanPassword(s_gson.toJson(result)); s_logger.debug("executeRequest received response " + logResult); if (result.length > 0) { return result[0]; } return null; }
DataStoreTO srcDataStore = srcData.getDataStore(); NfsTO srcStore = (NfsTO)srcDataStore; DataStoreTO destDataStore = destData.getDataStore(); File srcFile = getFile(srcData.getPath(), srcStore.getUrl(), _nfsVersion); long pathId = destData.getId(); String containerName = SwiftUtil.getContainerName(destData.getObjectType().toString(), pathId); String swiftPath = SwiftUtil.putObject(swift, srcFile, containerName, srcFile.getName()); if (destData.getObjectType() == DataObjectType.TEMPLATE) { TemplateObjectTO destTemplateData = (TemplateObjectTO)destData; String uniqueName = destTemplateData.getName(); newTemplate.setFormat(getTemplateFormat(srcFile.getName())); retObj = newTemplate; } else if (destData.getObjectType() == DataObjectType.VOLUME) { VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setPath(containerName); newVol.setSize(getVirtualSize(srcFile, getTemplateFormat(srcFile.getName()))); retObj = newVol; } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) { SnapshotObjectTO newSnapshot = new SnapshotObjectTO(); newSnapshot.setPath(containerName + File.separator + srcFile.getName()); s_logger.error("failed to upload " + srcData.getPath(), e); return new CopyCmdAnswer("failed to upload " + srcData.getPath() + e.toString());
protected Answer deleteVolume(final DeleteCommand cmd) { DataTO obj = cmd.getData(); DataStoreTO dstore = obj.getDataStore(); if (dstore instanceof NfsTO) { NfsTO nfs = (NfsTO)dstore; String relativeVolumePath = obj.getPath(); String parent = getRootDir(nfs.getUrl(), _nfsVersion); } else if (dstore instanceof S3TO) { final S3TO s3 = (S3TO)dstore; final String path = obj.getPath(); final String bucket = s3.getBucketName(); try { Long volumeId = obj.getId(); String path = obj.getPath(); String filename = StringUtils.substringAfterLast(path, "/"); // assuming
protected Answer copyFromS3ToNfs(CopyCommand cmd, DataTO srcData, S3TO s3, DataTO destData, NfsTO destImageStore) { final String storagePath = destImageStore.getUrl(); final String destPath = destData.getPath(); try { String downloadPath = determineStorageTemplatePath(storagePath, destPath, _nfsVersion); final File downloadDirectory = _storage.getFile(downloadPath); if (downloadDirectory.exists()) { s_logger.debug("Directory " + downloadPath + " already exists"); } else { if (!downloadDirectory.mkdirs()) { final String errMsg = "Unable to create directory " + downloadPath + " to copy from S3 to cache."; s_logger.error(errMsg); return new CopyCmdAnswer(errMsg); } } File destFile = new File(downloadDirectory, substringAfterLast(srcData.getPath(), S3Utils.SEPARATOR)); S3Utils.getFile(s3, s3.getBucketName(), srcData.getPath(), destFile).waitForCompletion(); return postProcessing(destFile, downloadPath, destPath, srcData, destData); } catch (Exception e) { final String errMsg = format("Failed to download" + "due to $1%s", e.getMessage()); s_logger.error(errMsg, e); return new CopyCmdAnswer(errMsg); } }
public Answer execute(DeleteCommand cmd) { DataTO data = cmd.getData(); String msg; LOGGER.debug("Deleting object: " + data.getObjectType()); if (data.getObjectType() == DataObjectType.VOLUME) { return deleteVolume(cmd); } else if (data.getObjectType() == DataObjectType.SNAPSHOT) { return deleteSnapshot(cmd); } else if (data.getObjectType() == DataObjectType.TEMPLATE) { msg = "Template deletion is not implemented yet."; LOGGER.info(msg); } else { msg = data.getObjectType() + " deletion is not implemented yet."; LOGGER.info(msg); } return new Answer(cmd, false, msg); }
protected Answer execute(final DeleteCommand cmd) { DataTO obj = cmd.getData(); DataObjectType objType = obj.getObjectType(); if (obj.getPath() == null) { // account for those fake entries for NFS migration to object store return new Answer(cmd, true, "Object with null install path does not exist on image store , no need to delete"); } switch (objType) { case TEMPLATE: return deleteTemplate(cmd); case VOLUME: return deleteVolume(cmd); case SNAPSHOT: return deleteSnapshot(cmd); } return Answer.createUnsupportedCommandAnswer(cmd); }
private void handlePath(final DiskTO[] disks, final Map<String, Map<String, String>> iqnToData) { if (disks != null && iqnToData != 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) { final Long volumeId = disk.getData().getId(); final VolumeVO volume = _volsDao.findById(volumeId); final String iScsiName = volume.get_iScsiName(); boolean update = false; final Map<String, String> data = iqnToData.get(iScsiName); if (data != null) { final String path = data.get(StartAnswer.PATH); if (path != null) { volume.setPath(path); update = true; } final String imageFormat = data.get(StartAnswer.IMAGE_FORMAT); if (imageFormat != null) { volume.setFormat(ImageFormat.valueOf(imageFormat)); update = true; } if (update) { _volsDao.update(volumeId, volume); } } } } } }
protected Answer copyFromNfsToImage(CopyCommand cmd) { DataTO destData = cmd.getDestTO(); DataStoreTO destDataStore = destData.getDataStore(); if (destDataStore instanceof S3TO) { return copyFromNfsToS3(cmd); } else if (destDataStore instanceof SwiftTO) { return copyFromNfsToSwift(cmd); } else { return new CopyCmdAnswer("unsupported "); } }
public final Answer execute(final CopyCommand cmd) { LOGGER.debug("execute: "+ cmd.getClass()); DataTO srcData = cmd.getSrcTO(); DataStoreTO srcStore = srcData.getDataStore(); DataTO destData = cmd.getDestTO(); DataStoreTO destStore = destData.getDataStore(); String msg = "Not implemented yet"; try { && (srcData.getObjectType() == DataObjectType.TEMPLATE) && (destData.getObjectType() == DataObjectType.TEMPLATE)) { return copyTemplateToPrimaryStorage(cmd); } else if ((srcData.getObjectType() == DataObjectType.TEMPLATE) && (destData.getObjectType() == DataObjectType.VOLUME)) { if (srcStore.getUrl().equals(destStore.getUrl())) { return cloneVolumeFromBaseTemplate(cmd); } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.SNAPSHOT)) { return backupSnapshot(cmd); } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.TEMPLATE)) { return createTemplateFromSnapshot(cmd); } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.VOLUME)) { return createVolumeFromSnapshot(cmd); } else { msg = "Unable to do stuff for " + srcStore.getClass() + ":" + srcData.getObjectType() + " to "
protected Answer deleteTemplate(DeleteCommand cmd) { DataTO obj = cmd.getData(); DataStoreTO dstore = obj.getDataStore(); if (dstore instanceof NfsTO) { NfsTO nfs = (NfsTO)dstore; String relativeTemplatePath = obj.getPath(); String parent = getRootDir(nfs.getUrl(), _nfsVersion); } else if (dstore instanceof S3TO) { final S3TO s3 = (S3TO)dstore; final String path = obj.getPath(); final String bucket = s3.getBucketName(); try { String container = "T-" + obj.getId(); String object = "";
protected Answer copyFromSwiftToNfs(CopyCommand cmd, DataTO srcData, SwiftTO swiftTO, DataTO destData, NfsTO destImageStore) { final String storagePath = destImageStore.getUrl(); final String destPath = destData.getPath(); try { String downloadPath = determineStorageTemplatePath(storagePath, destPath, _nfsVersion); final File downloadDirectory = _storage.getFile(downloadPath); if (downloadDirectory.exists()) { s_logger.debug("Directory " + downloadPath + " already exists"); } else { if (!downloadDirectory.mkdirs()) { final String errMsg = "Unable to create directory " + downloadPath + " to copy from Swift to cache."; s_logger.error(errMsg); return new CopyCmdAnswer(errMsg); } } File destFile = SwiftUtil.getObject(swiftTO, downloadDirectory, srcData.getPath()); return postProcessing(destFile, downloadPath, destPath, srcData, destData); } catch (Exception e) { s_logger.debug("Failed to copy swift to nfs", e); return new CopyCmdAnswer(e.toString()); } }
public Answer execute(CreateObjectCommand cmd) { LOGGER.debug("execute: "+ cmd.getClass()); DataTO data = cmd.getData(); if (data.getObjectType() == DataObjectType.VOLUME) { return createVolume(cmd); } else if (data.getObjectType() == DataObjectType.SNAPSHOT) { return createSnapshot(cmd); } else if (data.getObjectType() == DataObjectType.TEMPLATE) { LOGGER.debug("Template object creation not supported."); } return new CreateObjectAnswer(data.getObjectType() + " object creation not supported"); } /**
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); } } } }
protected boolean needCacheStorage(DataObject srcData, DataObject destData) { DataTO srcTO = srcData.getTO(); DataStoreTO srcStoreTO = srcTO.getDataStore(); if (srcStoreTO instanceof NfsTO || srcStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } DataTO destTO = destData.getTO(); DataStoreTO destStoreTO = destTO.getDataStore(); if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } if (s_logger.isDebugEnabled()) { s_logger.debug("needCacheStorage true, dest at " + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + srcTO.getPath() + " src role " + srcStoreTO.getRole().toString()); } return true; }
LOGGER.debug("execute copyTemplateToPrimaryStorage: "+ cmd.getClass()); DataTO srcData = cmd.getSrcTO(); DataStoreTO srcStore = srcData.getDataStore(); DataTO destData = cmd.getDestTO(); NfsTO srcImageStore = (NfsTO) srcStore; try { String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl()); String primaryPoolUuid = destData.getDataStore().getUuid(); String destPath = config.getAgentOvmRepoPath() + "/" + ovmObject.deDash(primaryPoolUuid) + "/" + srcData.getPath(); if (srcData.getPath().endsWith("/")) { srcFile = sourcePath + "/" + srcData.getPath() + "/" + destUuid + ".raw"; LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile); host.copyFile(srcFile, destFile);