Skip to content

Commit cb2a842

Browse files
committed
CLOUDSTACK-3513: [Automation] Failed to copy iso and template between
zones.
1 parent 1e3e131 commit cb2a842

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ public AsyncCallFuture<TemplateApiResult> copyTemplate(TemplateInfo srcTemplate,
580580

581581
TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<TemplateApiResult>(null,
582582
(TemplateObject) templateOnStore, future);
583-
AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
584-
caller.setCallback(caller.getTarget().copyTemplateCallBack(null, null)).setContext(context);
583+
AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
584+
caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context);
585585
destStore.getDriver().createAsync(destStore, templateOnStore, caller);
586586
return future;
587587
}
@@ -652,6 +652,28 @@ protected Void copyTemplateCallBack(AsyncCallbackDispatcher<TemplateServiceImpl,
652652
return null;
653653
}
654654

655+
protected Void copyTemplateCrossZoneCallBack(AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, TemplateOpContext<TemplateApiResult> context) {
656+
TemplateInfo destTemplate = context.getTemplate();
657+
CreateCmdResult result = callback.getResult();
658+
AsyncCallFuture<TemplateApiResult> future = context.getFuture();
659+
TemplateApiResult res = new TemplateApiResult(destTemplate);
660+
try {
661+
if (result.isFailed()) {
662+
res.setResult(result.getResult());
663+
destTemplate.processEvent(Event.OperationFailed);
664+
} else {
665+
destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
666+
}
667+
future.complete(res);
668+
} catch (Exception e) {
669+
s_logger.debug("Failed to process copy template cross zones callback", e);
670+
res.setResult(e.toString());
671+
future.complete(res);
672+
}
673+
674+
return null;
675+
}
676+
655677
@Override
656678
public void addSystemVMTemplatesToSecondary(DataStore store) {
657679
long storeId = store.getId();

server/src/com/cloud/template/TemplateManagerImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,6 @@ public boolean copy(long userId, VMTemplateVO template, DataStore srcSecStore, D
634634
createEventType = EventTypes.EVENT_TEMPLATE_CREATE;
635635
}
636636

637-
Transaction txn = Transaction.currentTxn();
638-
txn.start();
639-
640637
TemplateInfo srcTemplate = this._tmplFactory.getTemplate(template.getId(), srcSecStore);
641638
// Copy will just find one eligible image store for the destination zone
642639
// and copy template there, not propagate to all image stores

0 commit comments

Comments
 (0)