if (template.getTemplateType() == TemplateType.PERHOST) {
return null;
}
SwiftTO swift = _swiftMgr.getSwiftTO();
if (swift == null) {
String errMsg = " There is no Swift in this setup ";
s_logger.warn(errMsg);
return errMsg;
}
HostVO secHost = _hostDao.findById(templateHostRef.getHostId());
if (secHost == null) {
String errMsg = "Can not find secondary storage " + templateHostRef.getHostId();
s_logger.warn(errMsg);
return errMsg;
}
uploadTemplateToSwiftFromSecondaryStorageCommand cmd = new uploadTemplateToSwiftFromSecondaryStorageCommand(swift, secHost.getName(), secHost.getDataCenterId(), template.getAccountId(),
templateId, _primaryStorageDownloadWait);
Answer answer = null;
try {
answer = _agentMgr.sendToSSVM(secHost.getDataCenterId(), cmd);
if (answer == null || !answer.getResult()) {
if (template.getTemplateType() != TemplateType.SYSTEM) {
String errMsg = "Failed to upload template " + templateId + " to Swift from secondary storage due to " + ((answer == null) ? "null" : answer.getDetails());
s_logger.warn(errMsg);
throw new CloudRuntimeException(errMsg);
}
return null;
}
String path = templateHostRef.getInstallPath();
int index = path.lastIndexOf('/');
path = path.substring(index + 1);
VMTemplateSwiftVO tmpltSwift = new VMTemplateSwiftVO(swift.getId(), templateHostRef.getTemplateId(), new Date(), path, templateHostRef.getSize(), templateHostRef.getPhysicalSize());
_tmpltSwiftDao.persist(tmpltSwift);
_swiftMgr.propagateTemplateOnAllZones(templateHostRef.getTemplateId());
} catch (Exception e) {
String errMsg = "Failed to upload template " + templateId + " to Swift from secondary storage due to " + e.toString();
s_logger.warn(errMsg);