From 3de5d9db5fa0b3196a00784ffc2c04b998f64de2 Mon Sep 17 00:00:00 2001 From: Rajani Karuturi Date: Mon, 16 Mar 2015 12:41:58 +0530 Subject: [PATCH] volume upload: Restart of MS leads to loss of browser uploaded templates on restart of management server, template sync runs. It checks for templates in ssvm using the uniquename. If it doesnt find any, cleans the directory. In case of uploaded templates, these are getting saved using name instead on uniquename and hence template sync cant find them and does cleanup. Using uniquename in template.properties now. --- .../command/TemplateOrVolumePostUploadCommand.java | 10 ++++++++++ .../com/cloud/template/HypervisorTemplateAdapter.java | 3 ++- .../storage/resource/NfsSecondaryStorageResource.java | 7 ++++--- .../cloudstack/storage/template/UploadEntity.java | 9 +++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java b/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java index cc9df7146a3..0a5f1d68951 100644 --- a/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java +++ b/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java @@ -47,6 +47,8 @@ public class TemplateOrVolumePostUploadCommand { String maxUploadSize; + String description; + public TemplateOrVolumePostUploadCommand(long entityId, String entityUUID, String absolutePath, String checksum, String type, String name, String imageFormat, String dataTo, String dataToRole) { this.entityId = entityId; @@ -166,4 +168,12 @@ public class TemplateOrVolumePostUploadCommand { public void setMaxUploadSize(String maxUploadSize) { this.maxUploadSize = maxUploadSize; } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } } diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java index 0cb48fc07c5..1ad2135a695 100755 --- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java @@ -258,12 +258,13 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase { } TemplateOrVolumePostUploadCommand payload = new TemplateOrVolumePostUploadCommand(template.getId(), template.getUuid(), tmpl.getInstallPath(), tmpl.getChecksum(), tmpl - .getType().toString(), template.getName(), template.getFormat().toString(), templateOnStore.getDataStore().getUri(), templateOnStore.getDataStore().getRole() + .getType().toString(), template.getUniqueName(), template.getFormat().toString(), templateOnStore.getDataStore().getUri(), templateOnStore.getDataStore().getRole() .toString()); //using the existing max template size configuration payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key())); payload.setRemoteEndPoint(ep.getPublicAddr()); payload.setRequiresHvm(template.requiresHvm()); + payload.setDescription(template.getDisplayText()); payloads.add(payload); } _resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template); diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index 236498c4535..d10242c9e04 100755 --- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -2634,6 +2634,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S uploadEntity.setHvm(cmd.getRequiresHvm()); uploadEntity.setChksum(cmd.getChecksum()); uploadEntity.setMaxSizeInGB(maxSizeInGB); + uploadEntity.setDescription(cmd.getDescription()); // create a install dir if (!_storage.exists(installPathPrefix)) { _storage.mkdir(installPathPrefix); @@ -2677,9 +2678,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S Script scr = new Script(getScriptLocation(resourceType), timeout, s_logger); scr.add("-s", Integer.toString(imgSizeGigs)); scr.add("-S", Long.toString(UploadEntity.s_maxTemplateSize)); - //if (uploadEntity.getDescription() != null && dnld.getDescription().length() > 1) { - // scr.add("-d", dnld.getDescription()); - //} + if (uploadEntity.getDescription() != null && uploadEntity.getDescription().length() > 1) { + scr.add("-d", uploadEntity.getDescription()); + } if (uploadEntity.isHvm()) { scr.add("-h"); } diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java index 15a6ef28c66..e9444c23d7b 100644 --- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java +++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java @@ -32,6 +32,7 @@ public class UploadEntity { private String chksum; private long physicalSize; private int maxSizeInGB; + private String description; public static enum ResourceType { VOLUME, TEMPLATE @@ -180,4 +181,12 @@ public class UploadEntity { public void setMaxSizeInGB(int maxSizeInGB) { this.maxSizeInGB = maxSizeInGB; } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } }