if (!isS3Enabled()) {
return;
}
final S3TO s3 = getS3TO();
if (s3 == null) {
LOGGER.warn("S3 Template Sync Failed: Attempt to sync templates with S3, but no S3 instance defined.");
return;
}
final HostVO secondaryHost = this.hostDao.findById(templateHostRef
.getHostId());
if (secondaryHost == null) {
throw new CloudRuntimeException(format(
"Unable to find secondary storage host id %1$s.",
templateHostRef.getHostId()));
}
final Long dataCenterId = secondaryHost.getDataCenterId();
final Long accountId = template.getAccountId();
try {
executeWithNoWaitLock(determineLockId(accountId, templateId),
new Callable<Void>() {
@Override
public Void call() throws Exception {
final UploadTemplateToS3FromSecondaryStorageCommand cmd = new UploadTemplateToS3FromSecondaryStorageCommand(
s3, secondaryHost.getStorageUrl(),
dataCenterId, accountId, templateId);
final Answer answer = agentManager.sendToSSVM(
dataCenterId, cmd);
if (answer == null || !answer.getResult()) {
final String reason = answer != null ? answer
.getDetails()
: "S3 template sync failed due to an unspecified error.";
throw new CloudRuntimeException(
format("Failed to upload template id %1$s to S3 from secondary storage due to %2$s.",
templateId, reason));
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format(
"Creating VMTemplateS3VO instance using template id %1s.",
templateId));
}
final VMTemplateS3VO vmTemplateS3VO = new VMTemplateS3VO(
s3.getId(), templateId, now(),
templateHostRef.getSize(), templateHostRef
.getPhysicalSize());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Persisting %1$s",