use of org.apache.cloudstack.storage.command.CopyCmdAnswer in project cloudstack by apache.
the class SimulatorStorageProcessor method backupSnapshot.
@Override
public Answer backupSnapshot(CopyCommand cmd) {
DataTO srcData = cmd.getSrcTO();
DataTO destData = cmd.getDestTO();
SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
DataStoreTO imageStore = destData.getDataStore();
if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("unsupported protocol");
}
int index = snapshot.getPath().lastIndexOf("/");
String snapshotName = snapshot.getPath().substring(index + 1);
String snapshotRelPath = "snapshots";
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
newSnapshot.setPath(snapshotRelPath + File.separator + snapshotName);
return new CopyCmdAnswer(newSnapshot);
}
use of org.apache.cloudstack.storage.command.CopyCmdAnswer in project cloudstack by apache.
the class SimulatorStorageProcessor method copyVolumeFromImageCacheToPrimary.
@Override
public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
VolumeObjectTO volume = new VolumeObjectTO();
volume.setPath(UUID.randomUUID().toString());
volume.setSize(100);
volume.setFormat(Storage.ImageFormat.RAW);
return new CopyCmdAnswer(volume);
}
use of org.apache.cloudstack.storage.command.CopyCmdAnswer in project cloudstack by apache.
the class SimulatorStorageProcessor method createTemplateFromVolume.
@Override
public Answer createTemplateFromVolume(CopyCommand cmd) {
DataTO destData = cmd.getDestTO();
VolumeObjectTO srcData = (VolumeObjectTO) cmd.getSrcTO();
TemplateObjectTO template = new TemplateObjectTO();
template.setPath(template.getName());
template.setFormat(Storage.ImageFormat.RAW);
template.setSize(srcData.getSize());
DataStoreTO imageStore = destData.getDataStore();
if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("unsupported protocol");
}
return new CopyCmdAnswer(template);
}
use of org.apache.cloudstack.storage.command.CopyCmdAnswer in project cloudstack by apache.
the class NfsSecondaryStorageResource method copyFromNfsToS3.
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 S3TO s3 = (S3TO) destDataStore;
try {
final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), _nfsVersion);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
}
final String bucket = s3.getBucketName();
File srcFile = findFile(templatePath);
if (srcFile == null) {
return new CopyCmdAnswer("Can't find src file:" + templatePath);
}
ImageFormat format = getTemplateFormat(srcFile.getName());
String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
putFile(s3, srcFile, bucket, key).waitForCompletion();
DataTO retObj = null;
if (destData.getObjectType() == DataObjectType.TEMPLATE) {
TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(key);
newTemplate.setSize(getVirtualSize(srcFile, format));
newTemplate.setPhysicalSize(srcFile.length());
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);
retObj = newSnapshot;
}
return new CopyCmdAnswer(retObj);
} catch (Exception e) {
s_logger.error("failed to upload" + srcData.getPath(), e);
return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
}
}
use of org.apache.cloudstack.storage.command.CopyCmdAnswer in project cloudstack by apache.
the class Ovm3StorageProcessor method createTemplateFromSnapshot.
/**
* Copies from secondary to secondary
*/
@Override
public Answer createTemplateFromSnapshot(CopyCommand cmd) {
LOGGER.debug("execute createTemplateFromSnapshot: " + cmd.getClass());
try {
// src.getPath contains the uuid of the snapshot.
DataTO srcData = cmd.getSrcTO();
SnapshotObjectTO srcSnap = (SnapshotObjectTO) srcData;
String secPoolUuid = pool.setupSecondaryStorage(srcData.getDataStore().getUrl());
String srcFile = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + srcSnap.getPath();
// dest
DataTO destData = cmd.getDestTO();
TemplateObjectTO destTemplate = (TemplateObjectTO) destData;
String secPoolUuidTemplate = pool.setupSecondaryStorage(destData.getDataStore().getUrl());
String destDir = config.getAgentSecStoragePath() + "/" + secPoolUuidTemplate + "/" + destTemplate.getPath();
String destFile = destDir + "/" + destTemplate.getUuid() + ".raw";
CloudstackPlugin csp = new CloudstackPlugin(c);
csp.ovsMkdirs(destDir);
Linux host = new Linux(c);
host.copyFile(srcFile, destFile);
TemplateObjectTO newVol = new TemplateObjectTO();
newVol.setUuid(destTemplate.getUuid());
newVol.setPath(destTemplate.getUuid());
newVol.setFormat(ImageFormat.RAW);
return new CopyCmdAnswer(newVol);
} catch (Ovm3ResourceException e) {
String msg = "Error backupSnapshot: " + e.getMessage();
LOGGER.info(msg);
return new CopyCmdAnswer(msg);
}
}
Aggregations