Skip to content

Commit a439ec9

Browse files
minchen07chaturvedia
authored andcommitted
CLOUDSTACK-6025:CreateTemplate from snapshot in NFS is failing , after
migarting to S3 datastore.(cherry picked from commit a3caea7) Signed-off-by: Animesh Chaturvedi <animesh@apache.org>
1 parent 0d72e2c commit a439ec9

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

‎engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,16 +463,16 @@ public void syncVolumeSnapshotsToRegionStore(long volumeId, DataStore store) {
463463

464464
// push one individual snapshots currently on cache store to region store if it is not there already
465465
private void syncSnapshotToRegionStore(long snapshotId, DataStore store){
466-
if (s_logger.isDebugEnabled()) {
467-
s_logger.debug("sync snapshot " + snapshotId + " from cache to object store...");
468-
}
469466
// if snapshot is already on region wide object store, check if it is really downloaded there (by checking install_path). Sync snapshot to region
470467
// wide store if it is not there physically.
471468
SnapshotInfo snapOnStore = _snapshotFactory.getSnapshot(snapshotId, store);
472469
if (snapOnStore == null) {
473470
throw new CloudRuntimeException("Cannot find an entry in snapshot_store_ref for snapshot " + snapshotId + " on region store: " + store.getName());
474471
}
475472
if (snapOnStore.getPath() == null || snapOnStore.getPath().length() == 0) {
473+
if (s_logger.isDebugEnabled()) {
474+
s_logger.debug("sync snapshot " + snapshotId + " from cache to object store...");
475+
}
476476
// snapshot is not on region store yet, sync to region store
477477
SnapshotInfo srcSnapshot = _snapshotFactory.getReadySnapshotOnCache(snapshotId);
478478
if (srcSnapshot == null) {

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ protected Answer execute(CopyCommand cmd) {
9595
} else if (srcData.getObjectType() == DataObjectType.TEMPLATE) {
9696
// sync template from NFS cache to S3 in NFS migration to S3 case
9797
storageManager.createOvaForTemplate((TemplateObjectTO)srcData);
98-
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.SNAPSHOT) {
98+
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT) {
99+
// pack ova first
99100
// sync snapshot from NFS cache to S3 in NFS migration to S3 case
100101
String parentPath = storageResource.getRootDir(srcDataStore.getUrl());
101102
SnapshotObjectTO snap = (SnapshotObjectTO)srcData;
@@ -104,27 +105,28 @@ protected Answer execute(CopyCommand cmd) {
104105
String name = path.substring(index + 1);
105106
String snapDir = path.substring(0, index);
106107
storageManager.createOva(parentPath + File.separator + snapDir, name);
107-
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
108-
//create template from snapshot on src at first, then copy it to s3
109-
TemplateObjectTO cacheTemplate = (TemplateObjectTO)destData;
110-
cacheTemplate.setDataStore(srcDataStore);
111-
CopyCmdAnswer answer = (CopyCmdAnswer)processor.createTemplateFromSnapshot(cmd);
112-
if (!answer.getResult()) {
113-
return answer;
108+
if (destData.getObjectType() == DataObjectType.TEMPLATE) {
109+
//create template from snapshot on src at first, then copy it to s3
110+
TemplateObjectTO cacheTemplate = (TemplateObjectTO)destData;
111+
cacheTemplate.setDataStore(srcDataStore);
112+
CopyCmdAnswer answer = (CopyCmdAnswer)processor.createTemplateFromSnapshot(cmd);
113+
if (!answer.getResult()) {
114+
return answer;
115+
}
116+
cacheTemplate.setDataStore(destDataStore);
117+
TemplateObjectTO template = (TemplateObjectTO)answer.getNewData();
118+
template.setDataStore(srcDataStore);
119+
CopyCommand newCmd = new CopyCommand(template, destData, cmd.getWait(), cmd.executeInSequence());
120+
Answer result = storageResource.defaultAction(newCmd);
121+
//clean up template data on staging area
122+
try {
123+
DeleteCommand deleteCommand = new DeleteCommand(template);
124+
storageResource.defaultAction(deleteCommand);
125+
} catch (Exception e) {
126+
s_logger.debug("Failed to clean up staging area:", e);
127+
}
128+
return result;
114129
}
115-
cacheTemplate.setDataStore(destDataStore);
116-
TemplateObjectTO template = (TemplateObjectTO)answer.getNewData();
117-
template.setDataStore(srcDataStore);
118-
CopyCommand newCmd = new CopyCommand(template, destData, cmd.getWait(), cmd.executeInSequence());
119-
Answer result = storageResource.defaultAction(newCmd);
120-
//clean up template data on staging area
121-
try {
122-
DeleteCommand deleteCommand = new DeleteCommand(template);
123-
storageResource.defaultAction(deleteCommand);
124-
} catch (Exception e) {
125-
s_logger.debug("Failed to clean up staging area:", e);
126-
}
127-
return result;
128130
}
129131
needDelegation = true;
130132
}

0 commit comments

Comments
 (0)