From 384f30101ea099681b97a65486e5852b54d6cadd Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 17 May 2011 14:00:50 -0700 Subject: [PATCH] fixed template download --- .../api/storage/ListTemplateCommand.java | 2 +- .../resource/NfsSecondaryStorageResource.java | 12 ++++---- .../storage/template/DownloadManagerImpl.java | 2 +- .../storage/template/TemplateConstants.java | 2 +- .../storage/template/UploadManagerImpl.java | 29 ------------------- scripts/storage/secondary/listvmtmplt.sh | 2 +- .../storage/download/DownloadListener.java | 2 +- 7 files changed, 11 insertions(+), 40 deletions(-) diff --git a/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java b/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java index ea9200e7033..959e4ae5494 100644 --- a/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java +++ b/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java @@ -29,7 +29,7 @@ public class ListTemplateCommand extends StorageCommand { @Override public boolean executeInSequence() { - return false; + return true; } public String getSecUrl() { diff --git a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java index e50de93351d..3e9232760a4 100755 --- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java +++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java @@ -108,7 +108,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S private String _localgw; private String _eth1mask; private String _eth1ip; - + final private String _parent = "/mnt/SecStorage/"; @Override public void disconnected() { } @@ -361,8 +361,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S return new Answer(cmd, true, null); } - - public String getRootDir(String secUrl) { + synchronized public String getRootDir(String secUrl) { try { URI uri = new URI(secUrl); String nfsHost = uri.getHost(); @@ -371,7 +370,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S String nfsHostIp = nfsHostAddr.getHostAddress(); String nfsPath = nfsHostIp + ":" + uri.getPath(); String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes()).toString(); - String root = "/mnt/SecStorage/" + dir; + String root = _parent + "/" + dir; mount(root, nfsPath); return root; } catch (Exception e) { @@ -465,6 +464,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S throw new ConfigurationException("Unable to find class " + value); } } + _storage.mkdirs(_parent); _configSslScr = Script.findScript(getDefaultScriptsDir(), "config_ssl.sh"); if (_configSslScr != null) { s_logger.info("config_ssl.sh found in " + _configSslScr); @@ -538,8 +538,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S _params.put(StorageLayer.InstanceConfigKey, _storage); _dlMgr = new DownloadManagerImpl(); _dlMgr.configure("DownloadManager", _params); - _upldMgr = new UploadManagerImpl(); - _upldMgr.configure("UploadManager", params); + //_upldMgr = new UploadManagerImpl(); + //_upldMgr.configure("UploadManager", params); } catch (ConfigurationException e) { s_logger.warn("Caught problem while configuring DownloadManager", e); return false; diff --git a/core/src/com/cloud/storage/template/DownloadManagerImpl.java b/core/src/com/cloud/storage/template/DownloadManagerImpl.java index 35021faefec..4de0314454f 100755 --- a/core/src/com/cloud/storage/template/DownloadManagerImpl.java +++ b/core/src/com/cloud/storage/template/DownloadManagerImpl.java @@ -608,7 +608,7 @@ public class DownloadManagerImpl implements DownloadManager { ZfsPathParser zpp = new ZfsPathParser(rootdir); script.execute(zpp); result.addAll(zpp.getPaths()); - s_logger.info("found " + zpp.getPaths().size() + " templates"); + s_logger.info("found " + zpp.getPaths().size() + " templates" + zpp.getPaths()); return result; } diff --git a/core/src/com/cloud/storage/template/TemplateConstants.java b/core/src/com/cloud/storage/template/TemplateConstants.java index 782ed1c5b28..46e8a7b76a6 100644 --- a/core/src/com/cloud/storage/template/TemplateConstants.java +++ b/core/src/com/cloud/storage/template/TemplateConstants.java @@ -22,7 +22,7 @@ package com.cloud.storage.template; * */ public final class TemplateConstants { - public static final String DEFAULT_TMPLT_ROOT_DIR = "template/"; + public static final String DEFAULT_TMPLT_ROOT_DIR = "template"; public static final String DEFAULT_TMPLT_FIRST_LEVEL_DIR = "tmpl/"; public static final String DEFAULT_SYSTEM_VM_TEMPLATE_PATH = "template/tmpl/1/"; diff --git a/core/src/com/cloud/storage/template/UploadManagerImpl.java b/core/src/com/cloud/storage/template/UploadManagerImpl.java index 4dd2269cbe1..d559ae0b3a3 100755 --- a/core/src/com/cloud/storage/template/UploadManagerImpl.java +++ b/core/src/com/cloud/storage/template/UploadManagerImpl.java @@ -470,7 +470,6 @@ public class UploadManagerImpl implements UploadManager { _sslCopy = Boolean.parseBoolean(useSsl); } - configureFolders(name, params); String inSystemVM = (String)params.get("secondary.storage.vm"); if (inSystemVM != null && "true".equalsIgnoreCase(inSystemVM)) { s_logger.info("UploadManager: starting additional services since we are inside system vm"); @@ -526,34 +525,6 @@ public class UploadManagerImpl implements UploadManager { } - protected void configureFolders(String name, Map params) throws ConfigurationException { - parentDir = (String) params.get("template.parent"); - if (parentDir == null) { - throw new ConfigurationException("Unable to find the parent root for the templates"); - } - - String value = (String) params.get("public.templates.root.dir"); - if (value == null) { - value = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR; - } - - if (value.startsWith(File.separator)) { - publicTemplateRepo = value; - } else { - publicTemplateRepo = parentDir + File.separator + value; - } - - if (!publicTemplateRepo.endsWith(File.separator)) { - publicTemplateRepo += File.separator; - } - - publicTemplateRepo += TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR; - - if (!_storage.mkdirs(publicTemplateRepo)) { - throw new ConfigurationException("Unable to create public templates directory"); - } - } - @Override public String getName() { return _name; diff --git a/scripts/storage/secondary/listvmtmplt.sh b/scripts/storage/secondary/listvmtmplt.sh index 517dbe97ab5..5b3e13d07a2 100755 --- a/scripts/storage/secondary/listvmtmplt.sh +++ b/scripts/storage/secondary/listvmtmplt.sh @@ -55,7 +55,7 @@ fi for i in $(find /$rootdir -name template.properties ); do d=$(dirname $i) - filename=$(grep "filename" $i | awk -F"=" '{print $NF}') + filename=$(grep "^filename" $i | awk -F"=" '{print $NF}') # size=$(grep "virtualsize" $i | awk -F"=" '{print $NF}') # if [ -n "$filename" ] && [ -n "$size" ] # then diff --git a/server/src/com/cloud/storage/download/DownloadListener.java b/server/src/com/cloud/storage/download/DownloadListener.java index 4eef22bb663..f8f7769a7c4 100644 --- a/server/src/com/cloud/storage/download/DownloadListener.java +++ b/server/src/com/cloud/storage/download/DownloadListener.java @@ -280,7 +280,7 @@ public class DownloadListener implements Listener { @Override public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException { if (cmd instanceof StartupRoutingCommand) { - downloadMonitor.handleSysTemplateDownload(agent); + //downloadMonitor.handleSysTemplateDownload(agent); } else if ( cmd instanceof StartupStorageCommand) { StartupStorageCommand storage = (StartupStorageCommand)cmd; if( storage.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE ||