}
if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
//need to take extra processing for vmware, such as packing to ova, before sending to S3
if (srcData.getObjectType() == DataObjectType.VOLUME) {
NfsTO cacheStore = (NfsTO)srcDataStore;
String parentPath = storageResource.getRootDir(cacheStore.getUrl());
VolumeObjectTO vol = (VolumeObjectTO)srcData;
String path = vol.getPath();
int index = path.lastIndexOf(File.separator);
String name = path.substring(index + 1);
storageManager.createOva(parentPath + File.separator + path, name);
vol.setPath(path + File.separator + name + ".ova");
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
//create template from snapshot on src at first, then copy it to s3
TemplateObjectTO cacheTemplate = (TemplateObjectTO)destData;
cacheTemplate.setDataStore(srcDataStore);
CopyCmdAnswer answer = (CopyCmdAnswer)processor.createTemplateFromSnapshot(cmd);
if (!answer.getResult()) {
return answer;
}
cacheTemplate.setDataStore(destDataStore);
TemplateObjectTO template = (TemplateObjectTO)answer.getNewData();
template.setDataStore(srcDataStore);
CopyCommand newCmd = new CopyCommand(template, destData, cmd.getWait(), cmd.executeInSequence());
return storageResource.defaultAction(newCmd);
}
needDelegation = true;
}
if (srcData.getObjectType() == DataObjectType.SNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
//for back up snapshot, we need to do backup to cache, then to object store if object store is used.
if (cmd.getCacheTO() != null) {
cmd.setDestTO(cmd.getCacheTO());
CopyCmdAnswer answer = (CopyCmdAnswer)processor.backupSnapshot(cmd);
if (!answer.getResult()) {
return answer;
}
NfsTO cacheStore = (NfsTO)cmd.getCacheTO().getDataStore();
String parentPath = storageResource.getRootDir(cacheStore.getUrl());
SnapshotObjectTO newSnapshot = (SnapshotObjectTO)answer.getNewData();
String path = newSnapshot.getPath();
int index = path.lastIndexOf(File.separator);
String name = path.substring(index + 1);
String dir = path.substring(0, index);