You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ha...@apache.org on 2024/06/14 07:43:08 UTC
(cloudstack) branch UseObjectNameWhileDownloading created (now 9d64ebede9a)
This is an automated email from the ASF dual-hosted git repository.
harikrishna pushed a change to branch UseObjectNameWhileDownloading
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
at 9d64ebede9a Use object name as the file name when downloading the template or ISO or volumes
This branch includes the following new commits:
new 9d64ebede9a Use object name as the file name when downloading the template or ISO or volumes
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(cloudstack) 01/01: Use object name as the file name when downloading the template or ISO or volumes
Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
harikrishna pushed a commit to branch UseObjectNameWhileDownloading
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit 9d64ebede9ac0dc1cf15298429716cf3f60e172c
Author: Harikrishna Patnala <ha...@gmail.com>
AuthorDate: Fri Jun 14 13:02:38 2024 +0530
Use object name as the file name when downloading the template or ISO or volumes
---
.../engine/subsystem/api/storage/DataObject.java | 2 ++
.../driver/CloudStackImageStoreDriverImpl.java | 39 +++++++++++++++++-----
.../diagnostics/to/DiagnosticsDataObject.java | 5 +++
3 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java
index 091c09d7a4d..fe052f01606 100644
--- a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java
+++ b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java
@@ -50,4 +50,6 @@ public interface DataObject {
void decRefCount();
Long getRefCount();
+
+ String getName();
}
diff --git a/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java b/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
index 71fa2e91bcb..d2961f0b064 100644
--- a/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
+++ b/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
@@ -25,6 +25,7 @@ import javax.inject.Inject;
import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
import com.cloud.host.dao.HostDao;
import com.cloud.storage.Upload;
+import com.cloud.utils.StringUtils;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
@@ -64,20 +65,42 @@ public class CloudStackImageStoreDriverImpl extends NfsImageStoreDriverImpl {
return nfsTO;
}
+ private String createObjectNameForExtractUrl(String installPath, ImageFormat format, DataObject dataObject) {
+ String objectNameInUrl = dataObject.getName();
+ try {
+ objectNameInUrl = cleanObjectName(objectNameInUrl);
+ } catch (Exception e) {
+ objectNameInUrl = UUID.randomUUID().toString();
+ }
+
+ if (format != null) {
+ objectNameInUrl = objectNameInUrl + "." + format.getFileExtension();
+ } else if (installPath.lastIndexOf(".") != -1) {
+ objectNameInUrl = objectNameInUrl + "." + installPath.substring(installPath.lastIndexOf(".") + 1);
+ }
+
+ return objectNameInUrl;
+ }
+
+ private String cleanObjectName(String objectName) {
+ if (StringUtils.isEmpty(objectName)) {
+ throw new IllegalArgumentException("Object name is empty or null");
+ }
+ return objectName.trim()
+ .replaceAll("[^a-zA-Z0-9]+", "-")
+ .replaceAll("-{2,}", "-")
+ .replaceAll("^-|-$", "");
+ }
+
@Override
public String createEntityExtractUrl(DataStore store, String installPath, ImageFormat format, DataObject dataObject) {
// find an endpoint to send command
EndPoint ep = _epSelector.select(store);
// Create Symlink at ssvm
String path = installPath;
- String uuid = UUID.randomUUID().toString();
- if (format != null) {
- uuid = uuid + "." + format.getFileExtension();
- } else if (path.lastIndexOf(".") != -1) {
- uuid = uuid + "." + path.substring(path.lastIndexOf(".") + 1);
- }
+ String objectNameInUrl = createObjectNameForExtractUrl(path, format, dataObject);
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity)store).getMountPoint(),
- path, uuid, dataObject == null ? null: dataObject.getTO());
+ path, objectNameInUrl, dataObject == null ? null: dataObject.getTO());
Answer ans = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
@@ -92,7 +115,7 @@ public class CloudStackImageStoreDriverImpl extends NfsImageStoreDriverImpl {
throw new CloudRuntimeException(errorString);
}
// Construct actual URL locally now that the symlink exists at SSVM
- return generateCopyUrl(ep.getPublicAddr(), uuid);
+ return generateCopyUrl(ep.getPublicAddr(), objectNameInUrl);
}
private String generateCopyUrl(String ipAddress, String uuid) {
diff --git a/server/src/main/java/org/apache/cloudstack/diagnostics/to/DiagnosticsDataObject.java b/server/src/main/java/org/apache/cloudstack/diagnostics/to/DiagnosticsDataObject.java
index ebe1d7fbc73..de66ad4d5e6 100644
--- a/server/src/main/java/org/apache/cloudstack/diagnostics/to/DiagnosticsDataObject.java
+++ b/server/src/main/java/org/apache/cloudstack/diagnostics/to/DiagnosticsDataObject.java
@@ -99,4 +99,9 @@ public class DiagnosticsDataObject implements DataObject {
public Long getRefCount() {
return null;
}
+
+ @Override
+ public String getName() {
+ return dataStore.getName();
+ }
}