Skip to content

Commit 80aa0d3

Browse files
committed
CLOUDSTACK-4625:Snapshots and templates should be deleted from staging
storage after create template from snapshot on S3.
1 parent f05d6a5 commit 80aa0d3

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ protected Answer createTemplateFromSnapshot(DataObject srcData, DataObject destD
439439
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _createprivatetemplatefromsnapshotwait, _mgmtServer.getExecuteInSequence());
440440
EndPoint ep = selector.select(srcData, destData);
441441
Answer answer = ep.sendMessage(cmd);
442+
443+
// clean up snapshot copied to staging
444+
if (srcData != null) {
445+
cacheMgr.deleteCacheObject(srcData);
446+
}
442447
return answer;
443448
}
444449

‎plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ protected Answer execute(CopyCommand cmd) {
102102
TemplateObjectTO template = (TemplateObjectTO)answer.getNewData();
103103
template.setDataStore(srcDataStore);
104104
CopyCommand newCmd = new CopyCommand(template, destData, cmd.getWait(), cmd.executeInSequence());
105-
return storageResource.defaultAction(newCmd);
105+
Answer result = storageResource.defaultAction(newCmd);
106+
//clean up template data on staging area
107+
try {
108+
DeleteCommand deleteCommand = new DeleteCommand(template);
109+
storageResource.defaultAction(deleteCommand);
110+
} catch (Exception e) {
111+
s_logger.debug("Failed to clean up staging area:", e);
112+
}
113+
return result;
106114
}
107115
needDelegation = true;
108116
}

‎services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,14 @@ protected Answer createTemplateFromSnapshot(CopyCommand cmd) {
526526
SwiftUtil.putObject(swift, properties, containterName, _tmpltpp);
527527
}
528528

529+
//clean up template data on staging area
530+
try {
531+
DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
532+
execute(deleteCommand);
533+
} catch (Exception e) {
534+
s_logger.debug("Failed to clean up staging area:", e);
535+
}
536+
529537
TemplateObjectTO template = new TemplateObjectTO();
530538
template.setPath(swiftPath);
531539
template.setSize(templateFile.length());
@@ -543,7 +551,15 @@ protected Answer createTemplateFromSnapshot(CopyCommand cmd) {
543551
TemplateObjectTO newTemplate = (TemplateObjectTO)answer.getNewData();
544552
newTemplate.setDataStore(srcDataStore);
545553
CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence());
546-
return copyFromNfsToS3(newCpyCmd);
554+
Answer result = copyFromNfsToS3(newCpyCmd);
555+
//clean up template data on staging area
556+
try {
557+
DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
558+
execute(deleteCommand);
559+
} catch (Exception e) {
560+
s_logger.debug("Failed to clean up staging area:", e);
561+
}
562+
return result;
547563
}
548564
}
549565
s_logger.debug("Failed to create templat from snapshot");

0 commit comments

Comments
 (0)