You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/01/15 03:04:54 UTC

[33/44] Revert "Merge remote-tracking branch 'origin/javelin' into javelin"

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
index a4bea9d..7c10548 100755
--- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
@@ -71,7 +71,6 @@ import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
 import com.cloud.agent.api.SecStorageSetupAnswer;
 import com.cloud.agent.api.SecStorageSetupCommand;
 import com.cloud.agent.api.SecStorageSetupCommand.Certificates;
-import com.cloud.agent.api.StartupSecondaryStorageCommand;
 import com.cloud.agent.api.SecStorageVMSetupCommand;
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupSecondaryStorageCommand;
@@ -109,7 +108,7 @@ import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.S3Utils;
 import com.cloud.utils.S3Utils.FileNamingStrategy;
 import com.cloud.utils.S3Utils.ObjectNamingStrategy;
-import com.cloud.utils.component.ComponentLocator;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.utils.script.OutputInterpreter;
@@ -117,7 +116,7 @@ import com.cloud.utils.script.Script;
 import com.cloud.vm.SecondaryStorageVm;
 
 public class NfsSecondaryStorageResource extends ServerResourceBase implements
-        SecondaryStorageResource {
+SecondaryStorageResource {
 
     private static final Logger s_logger = Logger
             .getLogger(NfsSecondaryStorageResource.class);
@@ -126,7 +125,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
     private static final String SNAPSHOT_ROOT_DIR = "snapshots";
 
     int _timeout;
-    
+
     String _instance;  
     String _dc;
     String _pod;
@@ -136,23 +135,23 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
     StorageLayer _storage;
     boolean _inSystemVM = false;
     boolean _sslCopy = false;
-    
+
     DownloadManager _dlMgr;
     UploadManager _upldMgr;
-	private String _configSslScr;
-	private String _configAuthScr;
-	private String _configIpFirewallScr;
-	private String _publicIp;
-	private String _hostname;
-	private String _localgw;
-	private String _eth1mask;
-	private String _eth1ip;
-	private String _storageIp;
-	private String _storageNetmask;
-	private String _storageGateway;
-	private List<String> nfsIps = new ArrayList<String>();
-	final private String _parent = "/mnt/SecStorage";
-	final private String _tmpltDir = "/var/cloudstack/template";
+    private String _configSslScr;
+    private String _configAuthScr;
+    private String _configIpFirewallScr;
+    private String _publicIp;
+    private String _hostname;
+    private String _localgw;
+    private String _eth1mask;
+    private String _eth1ip;
+    private String _storageIp;
+    private String _storageNetmask;
+    private String _storageGateway;
+    private final List<String> nfsIps = new ArrayList<String>();
+    final private String _parent = "/mnt/SecStorage";
+    final private String _tmpltDir = "/var/cloudstack/template";
     final private String _tmpltpp = "template.properties";
     @Override
     public void disconnected() {
@@ -171,19 +170,19 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         } else if(cmd instanceof DeleteEntityDownloadURLCommand){
             return _upldMgr.handleDeleteEntityDownloadURLCommand((DeleteEntityDownloadURLCommand)cmd);
         } else if (cmd instanceof GetStorageStatsCommand) {
-        	return execute((GetStorageStatsCommand)cmd);
+            return execute((GetStorageStatsCommand)cmd);
         } else if (cmd instanceof CheckHealthCommand) {
             return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
         } else if (cmd instanceof DeleteTemplateCommand) {
-        	return execute((DeleteTemplateCommand) cmd);
+            return execute((DeleteTemplateCommand) cmd);
         } else if (cmd instanceof DeleteVolumeCommand) {
-        	return execute((DeleteVolumeCommand) cmd);
+            return execute((DeleteVolumeCommand) cmd);
         }else if (cmd instanceof ReadyCommand) {
             return new ReadyAnswer((ReadyCommand)cmd);
         } else if (cmd instanceof SecStorageFirewallCfgCommand){
-        	return execute((SecStorageFirewallCfgCommand)cmd);
+            return execute((SecStorageFirewallCfgCommand)cmd);
         } else if (cmd instanceof SecStorageVMSetupCommand){
-        	return execute((SecStorageVMSetupCommand)cmd);
+            return execute((SecStorageVMSetupCommand)cmd);
         } else if (cmd instanceof SecStorageSetupCommand){
             return execute((SecStorageSetupCommand)cmd);
         } else if (cmd instanceof ComputeChecksumCommand){
@@ -218,7 +217,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             return Answer.createUnsupportedCommandAnswer(cmd);
         }
     }
-    
+
     @SuppressWarnings("unchecked")
     private String determineS3TemplateDirectory(final Long accountId,
             final Long templateId) {
@@ -254,7 +253,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
                         "Unable to create directory "
                                 + "download directory %1$s for download of template id "
                                 + "%2$s from S3.", downloadDirectory.getName(),
-                        templateId);
+                                templateId);
                 s_logger.error(errMsg);
                 return new Answer(cmd, false, errMsg);
             }
@@ -262,11 +261,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             getDirectory(s3, s3.getBucketName(),
                     determineS3TemplateDirectory(accountId, templateId),
                     downloadDirectory, new FileNamingStrategy() {
-                        @Override
-                        public String determineFileName(final String key) {
-                            return substringAfterLast(key, S3Utils.SEPARATOR);
-                        }
-                    });
+                @Override
+                public String determineFileName(final String key) {
+                    return substringAfterLast(key, S3Utils.SEPARATOR);
+                }
+            });
 
             return new Answer(cmd, true, format("Successfully downloaded "
                     + "template id %1$s from S3 to directory %2$s", templateId,
@@ -395,23 +394,23 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             final String bucket = s3.getBucketName();
             putDirectory(s3, bucket, _storage.getFile(templatePath),
                     new FilenameFilter() {
-                        @Override
-                        public boolean accept(final File directory,
-                                final String fileName) {
-                            return !fileName.startsWith(".");
-                        }
-                    }, new ObjectNamingStrategy() {
-                        @Override
-                        public String determineKey(final File file) {
-                            s_logger.debug(String
-                                    .format("Determining key using account id %1$s and template id %2$s",
-                                            accountId, templateId));
-                            return join(
-                                    asList(determineS3TemplateDirectory(
-                                            accountId, templateId), file
-                                            .getName()), S3Utils.SEPARATOR);
-                        }
-                    });
+                @Override
+                public boolean accept(final File directory,
+                        final String fileName) {
+                    return !fileName.startsWith(".");
+                }
+            }, new ObjectNamingStrategy() {
+                @Override
+                public String determineKey(final File file) {
+                    s_logger.debug(String
+                            .format("Determining key using account id %1$s and template id %2$s",
+                                    accountId, templateId));
+                    return join(
+                            asList(determineS3TemplateDirectory(
+                                    accountId, templateId), file
+                                    .getName()), S3Utils.SEPARATOR);
+                }
+            });
 
             return new Answer(
                     cmd,
@@ -623,7 +622,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         command.add("-c");
         command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A "
                 + swift.getUrl() + " -U " + swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey()
- + " delete " + container + " " + object);
+                + " delete " + container + " " + object);
         OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
         String result = command.execute(parser);
         if (result != null) {
@@ -678,60 +677,60 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             executeWithNoWaitLock(determineSnapshotLockId(accountId, volumeId),
                     new Callable<Void>() {
 
-                        @Override
-                        public Void call() throws Exception {
+                @Override
+                public Void call() throws Exception {
 
-                            final String directoryName = determineSnapshotLocalDirectory(
-                                    secondaryStorageUrl, accountId, volumeId);
+                    final String directoryName = determineSnapshotLocalDirectory(
+                            secondaryStorageUrl, accountId, volumeId);
 
-                            String result = createLocalDir(directoryName);
-                            if (result != null) {
-                                throw new InternalErrorException(
-                                        format("Failed to create directory %1$s during S3 snapshot download.",
-                                                directoryName));
-                            }
+                    String result = createLocalDir(directoryName);
+                    if (result != null) {
+                        throw new InternalErrorException(
+                                format("Failed to create directory %1$s during S3 snapshot download.",
+                                        directoryName));
+                    }
 
-                            final String snapshotFileName = determineSnapshotBackupFilename(cmd
-                                    .getSnapshotUuid());
-                            final String key = determineSnapshotS3Key(
-                                    accountId, volumeId, snapshotFileName);
-                            final File targetFile = S3Utils.getFile(s3,
-                                    s3.getBucketName(), key,
-                                    _storage.getFile(directoryName),
-                                    new FileNamingStrategy() {
-
-                                        @Override
-                                        public String determineFileName(
-                                                String key) {
-                                            return snapshotFileName;
-                                        }
-
-                                    });
-
-                            if (cmd.getParent() != null) {
-
-                                final String parentPath = join(
-                                        File.pathSeparator, directoryName,
-                                        determineSnapshotBackupFilename(cmd
-                                                .getParent()));
-                                result = setVhdParent(
-                                        targetFile.getAbsolutePath(),
-                                        parentPath);
-                                if (result != null) {
-                                    throw new InternalErrorException(
-                                            format("Failed to set the parent for backup %1$s to %2$s due to %3$s.",
-                                                    targetFile
-                                                            .getAbsolutePath(),
-                                                    parentPath, result));
-                                }
+                    final String snapshotFileName = determineSnapshotBackupFilename(cmd
+                            .getSnapshotUuid());
+                    final String key = determineSnapshotS3Key(
+                            accountId, volumeId, snapshotFileName);
+                    final File targetFile = S3Utils.getFile(s3,
+                            s3.getBucketName(), key,
+                            _storage.getFile(directoryName),
+                            new FileNamingStrategy() {
 
-                            }
+                        @Override
+                        public String determineFileName(
+                                String key) {
+                            return snapshotFileName;
+                        }
 
-                            return null;
+                    });
 
+                    if (cmd.getParent() != null) {
+
+                        final String parentPath = join(
+                                File.pathSeparator, directoryName,
+                                determineSnapshotBackupFilename(cmd
+                                        .getParent()));
+                        result = setVhdParent(
+                                targetFile.getAbsolutePath(),
+                                parentPath);
+                        if (result != null) {
+                            throw new InternalErrorException(
+                                    format("Failed to set the parent for backup %1$s to %2$s due to %3$s.",
+                                            targetFile
+                                            .getAbsolutePath(),
+                                            parentPath, result));
                         }
 
-                    });
+                    }
+
+                    return null;
+
+                }
+
+            });
 
             return new Answer(
                     cmd,
@@ -820,7 +819,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
     }
 
     private Answer execute(ComputeChecksumCommand cmd) {
-        
+
         String relativeTemplatePath = cmd.getTemplatePath();
         String parent = getRootDir(cmd);
 
@@ -841,8 +840,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         if(s_logger.isDebugEnabled()){
             s_logger.debug("parent path " +parent+ " relative template path " +relativeTemplatePath );   
         }
-        
-        
+
+
         try {
             digest = MessageDigest.getInstance("MD5");           
             is = new FileInputStream(f);     
@@ -855,7 +854,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             if(s_logger.isDebugEnabled()){
                 s_logger.debug("Successfully calculated checksum for file " +absoluteTemplatePath+ " - " +checksum );   
             }
-        
+
         }catch(IOException e) {
             String logMsg = "Unable to process file for MD5 - " + absoluteTemplatePath;
             s_logger.error(logMsg);
@@ -865,11 +864,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         }
         finally {
             try {
-            	if(is != null)
-            		is.close();
+                if(is != null)
+                    is.close();
             } catch (IOException e) {
                 if(s_logger.isDebugEnabled()){
-                  s_logger.debug("Could not close the file " +absoluteTemplatePath);   
+                    s_logger.debug("Could not close the file " +absoluteTemplatePath);   
                 }
                 return new Answer(cmd, false, checksum);   
             }                        
@@ -879,38 +878,38 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
     }
 
     private void configCerts(Certificates certs) {
-    	if (certs == null) {
-    		configureSSL();
-    	} else {
-    		String prvKey = certs.getPrivKey();
-    		String pubCert = certs.getPrivCert();
-    		String certChain = certs.getCertChain();
-    		
-    		try {
-				File prvKeyFile = File.createTempFile("prvkey", null);
-				String prvkeyPath = prvKeyFile.getAbsolutePath();
-				BufferedWriter out = new BufferedWriter(new FileWriter(prvKeyFile));
-				out.write(prvKey);
-				out.close();
-				
-				File pubCertFile = File.createTempFile("pubcert", null);
-				String pubCertFilePath = pubCertFile.getAbsolutePath();
-				
-				out = new BufferedWriter(new FileWriter(pubCertFile));
-				out.write(pubCert);
-				out.close();
-				
-				configureSSL(prvkeyPath, pubCertFilePath, null);
-				
-				prvKeyFile.delete();
-				pubCertFile.delete();
-				
-			} catch (IOException e) {
-				s_logger.debug("Failed to config ssl: " + e.toString());
-			}
-    	}
-    }
-    
+        if (certs == null) {
+            configureSSL();
+        } else {
+            String prvKey = certs.getPrivKey();
+            String pubCert = certs.getPrivCert();
+            String certChain = certs.getCertChain();
+
+            try {
+                File prvKeyFile = File.createTempFile("prvkey", null);
+                String prvkeyPath = prvKeyFile.getAbsolutePath();
+                BufferedWriter out = new BufferedWriter(new FileWriter(prvKeyFile));
+                out.write(prvKey);
+                out.close();
+
+                File pubCertFile = File.createTempFile("pubcert", null);
+                String pubCertFilePath = pubCertFile.getAbsolutePath();
+
+                out = new BufferedWriter(new FileWriter(pubCertFile));
+                out.write(pubCert);
+                out.close();
+
+                configureSSL(prvkeyPath, pubCertFilePath, null);
+
+                prvKeyFile.delete();
+                pubCertFile.delete();
+
+            } catch (IOException e) {
+                s_logger.debug("Failed to config ssl: " + e.toString());
+            }
+        }
+    }
+
     private Answer execute(SecStorageSetupCommand cmd) {
         if (!_inSystemVM){
             return new Answer(cmd, true, null);
@@ -930,7 +929,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             mount(root, nfsPath);
 
             configCerts(cmd.getCerts());
-            
+
             nfsIps.add(nfsHostIp);
             return new SecStorageSetupAnswer(dir);
         } catch (Exception e) {
@@ -940,7 +939,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
 
         }
     }
-    
+
     private String deleteSnapshotBackupFromLocalFileSystem(
             final String secondaryStorageUrl, final Long accountId,
             final Long volumeId, final String name, final Boolean deleteAllFlag) {
@@ -1072,7 +1071,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             return new Answer(cmd, false, errMsg);
         }
     }
-    
+
     Map<String, TemplateInfo> swiftListTemplate(SwiftTO swift) {
         String[] containers = swiftList(swift, "", "");
         if (containers == null) {
@@ -1103,9 +1102,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             }
         }
         return tmpltInfos;
-        
+
     }
-    
+
     private Answer execute(ListTemplateCommand cmd) {
         if (!_inSystemVM){
             return new Answer(cmd, true, null);
@@ -1119,50 +1118,50 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             return new ListTemplateAnswer(cmd.getSecUrl(), templateInfos);
         }
     }
-    
+
     private Answer execute(ListVolumeCommand cmd) {
         if (!_inSystemVM){
             return new Answer(cmd, true, null);
         }
-        
+
         String root = getRootDir(cmd.getSecUrl());
         Map<Long, TemplateInfo> templateInfos = _dlMgr.gatherVolumeInfo(root);
         return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
-        
+
     }
-    
+
     private Answer execute(SecStorageVMSetupCommand cmd) {
-    	if (!_inSystemVM){
-			return new Answer(cmd, true, null);
-		}
-		boolean success = true;
-		StringBuilder result = new StringBuilder();
-		for (String cidr: cmd.getAllowedInternalSites()) {
-			if (nfsIps.contains(cidr)) {
-				/*
-				 * if the internal download ip is the same with secondary storage ip, adding internal sites will flush
-				 * ip route to nfs through storage ip. 
-				 */
-				continue;
-			}
-			String tmpresult = allowOutgoingOnPrivate(cidr);
-			if (tmpresult != null) {
-				result.append(", ").append(tmpresult);
-				success = false;
-			}
-		}
-		if (success) {
-			if (cmd.getCopyPassword() != null && cmd.getCopyUserName() != null) {
-				String tmpresult = configureAuth(cmd.getCopyUserName(), cmd.getCopyPassword());
-				if (tmpresult != null) {
-					result.append("Failed to configure auth for copy ").append(tmpresult);
-					success = false;
-				}
-			}
-		}
-		return new Answer(cmd, success, result.toString());
-
-	}
+        if (!_inSystemVM){
+            return new Answer(cmd, true, null);
+        }
+        boolean success = true;
+        StringBuilder result = new StringBuilder();
+        for (String cidr: cmd.getAllowedInternalSites()) {
+            if (nfsIps.contains(cidr)) {
+                /*
+                 * if the internal download ip is the same with secondary storage ip, adding internal sites will flush
+                 * ip route to nfs through storage ip. 
+                 */
+                continue;
+            }
+            String tmpresult = allowOutgoingOnPrivate(cidr);
+            if (tmpresult != null) {
+                result.append(", ").append(tmpresult);
+                success = false;
+            }
+        }
+        if (success) {
+            if (cmd.getCopyPassword() != null && cmd.getCopyUserName() != null) {
+                String tmpresult = configureAuth(cmd.getCopyUserName(), cmd.getCopyPassword());
+                if (tmpresult != null) {
+                    result.append("Failed to configure auth for copy ").append(tmpresult);
+                    success = false;
+                }
+            }
+        }
+        return new Answer(cmd, success, result.toString());
+
+    }
 
     private String setVhdParent(String lFullPath, String pFullPath) {
         Script command = new Script("/bin/bash", s_logger);
@@ -1217,55 +1216,55 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
     }
 
     public String allowOutgoingOnPrivate(String destCidr) {
-    	
-    	Script command = new Script("/bin/bash", s_logger);
-    	String intf = "eth1";
-    	command.add("-c");
-    	command.add("iptables -I OUTPUT -o " + intf + " -d " + destCidr + " -p tcp -m state --state NEW -m tcp  -j ACCEPT");
-
-    	String result = command.execute();
-    	if (result != null) {
-    		s_logger.warn("Error in allowing outgoing to " + destCidr + ", err=" + result );
-    		return "Error in allowing outgoing to " + destCidr + ", err=" + result;
-    	}
-    	
-    	addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, destCidr);
-    	
-    	return null;
-	}
-    
-	private Answer execute(SecStorageFirewallCfgCommand cmd) {
-		if (!_inSystemVM){
-			return new Answer(cmd, true, null);
-		}
-
-		List<String> ipList = new ArrayList<String>();
-		
-		for (PortConfig pCfg:cmd.getPortConfigs()){
-			if (pCfg.isAdd()) {
-				ipList.add(pCfg.getSourceIp());		
-			}
-		}
-		boolean success = true;
-		String result;
-		result = configureIpFirewall(ipList, cmd.getIsAppendAIp());
-		if (result !=null)
-			success = false;
-
-		return new Answer(cmd, success, result);
-	}
-
-	protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
-	    String rootDir = getRootDir(cmd.getSecUrl());
+
+        Script command = new Script("/bin/bash", s_logger);
+        String intf = "eth1";
+        command.add("-c");
+        command.add("iptables -I OUTPUT -o " + intf + " -d " + destCidr + " -p tcp -m state --state NEW -m tcp  -j ACCEPT");
+
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in allowing outgoing to " + destCidr + ", err=" + result );
+            return "Error in allowing outgoing to " + destCidr + ", err=" + result;
+        }
+
+        addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, destCidr);
+
+        return null;
+    }
+
+    private Answer execute(SecStorageFirewallCfgCommand cmd) {
+        if (!_inSystemVM){
+            return new Answer(cmd, true, null);
+        }
+
+        List<String> ipList = new ArrayList<String>();
+
+        for (PortConfig pCfg:cmd.getPortConfigs()){
+            if (pCfg.isAdd()) {
+                ipList.add(pCfg.getSourceIp());		
+            }
+        }
+        boolean success = true;
+        String result;
+        result = configureIpFirewall(ipList, cmd.getIsAppendAIp());
+        if (result !=null)
+            success = false;
+
+        return new Answer(cmd, success, result);
+    }
+
+    protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
+        String rootDir = getRootDir(cmd.getSecUrl());
         final long usedSize = getUsedSize(rootDir);
         final long totalSize = getTotalSize(rootDir);
         if (usedSize == -1 || totalSize == -1) {
-        	return new GetStorageStatsAnswer(cmd, "Unable to get storage stats");
+            return new GetStorageStatsAnswer(cmd, "Unable to get storage stats");
         } else {
-        	return new GetStorageStatsAnswer(cmd, totalSize, usedSize) ;
+            return new GetStorageStatsAnswer(cmd, totalSize, usedSize) ;
         }
     }
-    
+
     protected Answer execute(final DeleteTemplateCommand cmd) {
         String relativeTemplatePath = cmd.getTemplatePath();
         String parent = getRootDir(cmd);
@@ -1313,7 +1312,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         }
         return new Answer(cmd, true, null);
     }
-    
+
     protected Answer execute(final DeleteVolumeCommand cmd) {
         String relativeVolumePath = cmd.getVolumePath();
         String parent = getRootDir(cmd);
@@ -1361,7 +1360,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         }
         return new Answer(cmd, true, null);
     }
-    
+
     Answer execute(CleanupSnapshotBackupCommand cmd) {
         String parent = getRootDir(cmd.getSecondaryStoragePoolURL());
         if (!parent.endsWith(File.separator)) {
@@ -1409,22 +1408,22 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             throw new CloudRuntimeException(msg);
         }
     }
-    
-    
+
+
     @Override
     public String getRootDir(ssCommand cmd){
         return getRootDir(cmd.getSecUrl());
-        
+
     }
-    
+
     protected long getUsedSize(String rootDir) {
         return _storage.getUsedSpace(rootDir);
     }
-    
+
     protected long getTotalSize(String rootDir) {
-      	return _storage.getTotalSpace(rootDir);
+        return _storage.getTotalSpace(rootDir);
     }
-    
+
     protected long convertFilesystemSize(final String size) {
         if (size == null || size.isEmpty()) {
             return -1;
@@ -1443,29 +1442,29 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
 
         return (long)(Double.parseDouble(size.substring(0, size.length() - 1)) * multiplier);
     }
-    
+
 
     @Override
     public Type getType() {
-    	if(SecondaryStorageVm.Role.templateProcessor.toString().equals(_role))
-    		return Host.Type.SecondaryStorage;
-    	
-    	return Host.Type.SecondaryStorageCmdExecutor;
+        if(SecondaryStorageVm.Role.templateProcessor.toString().equals(_role))
+            return Host.Type.SecondaryStorage;
+
+        return Host.Type.SecondaryStorageCmdExecutor;
     }
-    
+
     @Override
     public PingCommand getCurrentStatus(final long id) {
         return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
     }
-    
+
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-    	_eth1ip = (String)params.get("eth1ip");
+        _eth1ip = (String)params.get("eth1ip");
         _eth1mask = (String)params.get("eth1mask");
         if (_eth1ip != null) { //can only happen inside service vm
-        	params.put("private.network.device", "eth1");
+            params.put("private.network.device", "eth1");
         } else {
-        	s_logger.warn("Wait, what's going on? eth1ip is null!!");
+            s_logger.warn("Wait, what's going on? eth1ip is null!!");
         }
         String eth2ip = (String) params.get("eth2ip");
         if (eth2ip != null) {
@@ -1473,29 +1472,29 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         }         
         _publicIp = (String) params.get("eth2ip");
         _hostname = (String) params.get("name");
-        
+
         _storageIp = (String) params.get("storageip");
         if (_storageIp == null) {
-        	s_logger.warn("Wait, there is no storageip in /proc/cmdline, something wrong!");
+            s_logger.warn("Wait, there is no storageip in /proc/cmdline, something wrong!");
         }
         _storageNetmask = (String) params.get("storagenetmask");
         _storageGateway = (String) params.get("storagegateway");
         super.configure(name, params);
-        
+
         _params = params;
         String value = (String)params.get("scripts.timeout");
         _timeout = NumbersUtil.parseInt(value, 1440) * 1000;
-        
+
         _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
         if (_storage == null) {
             value = (String)params.get(StorageLayer.ClassConfigKey);
             if (value == null) {
                 value = "com.cloud.storage.JavaStorageLayer";
             }
-            
+
             try {
                 Class<?> clazz = Class.forName(value);
-                _storage = (StorageLayer)ComponentLocator.inject(clazz);
+                _storage = (StorageLayer)ComponentContext.inject(clazz);
                 _storage.configure("StorageLayer", params);
             } catch (ClassNotFoundException e) {
                 throw new ConfigurationException("Unable to find class " + value);
@@ -1511,34 +1510,34 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         if (_configSslScr != null) {
             s_logger.info("config_auth.sh found in " + _configAuthScr);
         }
-        
+
         _configIpFirewallScr = Script.findScript(getDefaultScriptsDir(), "ipfirewall.sh");
         if (_configIpFirewallScr != null) {
             s_logger.info("_configIpFirewallScr found in " + _configIpFirewallScr);
         }
-        
+
         _role = (String)params.get("role");
         if(_role == null)
-        	_role = SecondaryStorageVm.Role.templateProcessor.toString();
+            _role = SecondaryStorageVm.Role.templateProcessor.toString();
         s_logger.info("Secondary storage runs in role " + _role);
-        
+
         _guid = (String)params.get("guid");
         if (_guid == null) {
             throw new ConfigurationException("Unable to find the guid");
         }
-        
+
         _dc = (String)params.get("zone");
         if (_dc == null) {
             throw new ConfigurationException("Unable to find the zone");
         }
         _pod = (String)params.get("pod");
-        
+
         _instance = (String)params.get("instance");
-    
-        
+
+
         String inSystemVM = (String)params.get("secondary.storage.vm");
         if (inSystemVM == null || "true".equalsIgnoreCase(inSystemVM)) {
-        	_inSystemVM = true;
+            _inSystemVM = true;
             _localgw = (String)params.get("localgw");
             if (_localgw != null) { // can only happen inside service vm
                 String mgmtHost = (String) params.get("host");
@@ -1557,12 +1556,12 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
                 }
 
             }
-            
-        	startAdditionalServices();
-        	_params.put("install.numthreads", "50");
-        	_params.put("secondary.storage.vm", "true");
+
+            startAdditionalServices();
+            _params.put("install.numthreads", "50");
+            _params.put("secondary.storage.vm", "true");
         }
-        
+
         try {
             _params.put(StorageLayer.InstanceConfigKey, _storage);
             _dlMgr = new DownloadManagerImpl();
@@ -1575,114 +1574,114 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         }
         return true;
     }
-    
+
     private void startAdditionalServices() {
-    	Script command = new Script("/bin/bash", s_logger);
-		command.add("-c");
-    	command.add("if [ -f /etc/init.d/ssh ]; then service ssh restart; else service sshd restart; fi ");
-    	String result = command.execute();
-    	if (result != null) {
-    		s_logger.warn("Error in starting sshd service err=" + result );
-    	}
-		command = new Script("/bin/bash", s_logger);
-		command.add("-c");
-    	command.add("iptables -I INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 3922 -j ACCEPT");
-    	result = command.execute();
-    	if (result != null) {
-    		s_logger.warn("Error in opening up ssh port err=" + result );
-    	}
-	}
-    
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("if [ -f /etc/init.d/ssh ]; then service ssh restart; else service sshd restart; fi ");
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in starting sshd service err=" + result );
+        }
+        command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("iptables -I INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 3922 -j ACCEPT");
+        result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in opening up ssh port err=" + result );
+        }
+    }
+
     private void addRouteToInternalIpOrCidr(String localgw, String eth1ip, String eth1mask, String destIpOrCidr) {
-    	s_logger.debug("addRouteToInternalIp: localgw=" + localgw + ", eth1ip=" + eth1ip + ", eth1mask=" + eth1mask + ",destIp=" + destIpOrCidr);
-    	if (destIpOrCidr == null) {
-    		s_logger.debug("addRouteToInternalIp: destIp is null");
-			return;
-		}
-    	if (!NetUtils.isValidIp(destIpOrCidr) && !NetUtils.isValidCIDR(destIpOrCidr)){
-    		s_logger.warn(" destIp is not a valid ip address or cidr destIp=" + destIpOrCidr);
-    		return;
-    	}
-    	boolean inSameSubnet = false;
-    	if (NetUtils.isValidIp(destIpOrCidr)) {
-    		if (eth1ip != null && eth1mask != null) {
-    			inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr, eth1mask);
-    		} else {
-    			s_logger.warn("addRouteToInternalIp: unable to determine same subnet: _eth1ip=" + eth1ip + ", dest ip=" + destIpOrCidr + ", _eth1mask=" + eth1mask);
-    		}
-    	} else {
+        s_logger.debug("addRouteToInternalIp: localgw=" + localgw + ", eth1ip=" + eth1ip + ", eth1mask=" + eth1mask + ",destIp=" + destIpOrCidr);
+        if (destIpOrCidr == null) {
+            s_logger.debug("addRouteToInternalIp: destIp is null");
+            return;
+        }
+        if (!NetUtils.isValidIp(destIpOrCidr) && !NetUtils.isValidCIDR(destIpOrCidr)){
+            s_logger.warn(" destIp is not a valid ip address or cidr destIp=" + destIpOrCidr);
+            return;
+        }
+        boolean inSameSubnet = false;
+        if (NetUtils.isValidIp(destIpOrCidr)) {
+            if (eth1ip != null && eth1mask != null) {
+                inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr, eth1mask);
+            } else {
+                s_logger.warn("addRouteToInternalIp: unable to determine same subnet: _eth1ip=" + eth1ip + ", dest ip=" + destIpOrCidr + ", _eth1mask=" + eth1mask);
+            }
+        } else {
             inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr, NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask));
-    	}
-    	if (inSameSubnet) {
-			s_logger.debug("addRouteToInternalIp: dest ip " + destIpOrCidr + " is in the same subnet as eth1 ip " + eth1ip);
-    		return;
-    	}
-    	Script command = new Script("/bin/bash", s_logger);
-		command.add("-c");
-    	command.add("ip route delete " + destIpOrCidr);
-    	command.execute();
-		command = new Script("/bin/bash", s_logger);
-		command.add("-c");
-    	command.add("ip route add " + destIpOrCidr + " via " + localgw);
-    	String result = command.execute();
-    	if (result != null) {
-    		s_logger.warn("Error in configuring route to internal ip err=" + result );
-    	} else {
-			s_logger.debug("addRouteToInternalIp: added route to internal ip=" + destIpOrCidr + " via " + localgw);
-    	}
-    }
-
-	private void configureSSL() {
-		Script command = new Script(_configSslScr);
-		command.add("-i", _publicIp);
-		command.add("-h", _hostname);
-		String result = command.execute();
-		if (result != null) {
-			s_logger.warn("Unable to configure httpd to use ssl");
-		}
-	}
-	
-	private void configureSSL(String prvkeyPath, String prvCertPath, String certChainPath) {
-		Script command = new Script(_configSslScr);
-		command.add("-i", _publicIp);
-		command.add("-h", _hostname);
-		command.add("-k", prvkeyPath);
-		command.add("-p", prvCertPath);
-		if (certChainPath != null) {
-			command.add("-t", certChainPath);
-		}
-		String result = command.execute();
-		if (result != null) {
-			s_logger.warn("Unable to configure httpd to use ssl");
-		}
-	}
-	
-	private String configureAuth(String user, String passwd) {
-		Script command = new Script(_configAuthScr);
-		command.add(user);
-		command.add(passwd);
-		String result = command.execute();
-		if (result != null) {
-			s_logger.warn("Unable to configure httpd to use auth");
-		}
-		return result;
-	}
-	
-	private String configureIpFirewall(List<String> ipList, boolean isAppend){
-		Script command = new Script(_configIpFirewallScr);
-		command.add(String.valueOf(isAppend));
-		for (String ip : ipList){
-			command.add(ip);
-		}		
-		
-		String result = command.execute();
-		if (result != null) {
-			s_logger.warn("Unable to configure firewall for command : " +command);
-		}
-		return result;
-	}
-	
-	protected String mount(String root, String nfsPath) {
+        }
+        if (inSameSubnet) {
+            s_logger.debug("addRouteToInternalIp: dest ip " + destIpOrCidr + " is in the same subnet as eth1 ip " + eth1ip);
+            return;
+        }
+        Script command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("ip route delete " + destIpOrCidr);
+        command.execute();
+        command = new Script("/bin/bash", s_logger);
+        command.add("-c");
+        command.add("ip route add " + destIpOrCidr + " via " + localgw);
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Error in configuring route to internal ip err=" + result );
+        } else {
+            s_logger.debug("addRouteToInternalIp: added route to internal ip=" + destIpOrCidr + " via " + localgw);
+        }
+    }
+
+    private void configureSSL() {
+        Script command = new Script(_configSslScr);
+        command.add("-i", _publicIp);
+        command.add("-h", _hostname);
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Unable to configure httpd to use ssl");
+        }
+    }
+
+    private void configureSSL(String prvkeyPath, String prvCertPath, String certChainPath) {
+        Script command = new Script(_configSslScr);
+        command.add("-i", _publicIp);
+        command.add("-h", _hostname);
+        command.add("-k", prvkeyPath);
+        command.add("-p", prvCertPath);
+        if (certChainPath != null) {
+            command.add("-t", certChainPath);
+        }
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Unable to configure httpd to use ssl");
+        }
+    }
+
+    private String configureAuth(String user, String passwd) {
+        Script command = new Script(_configAuthScr);
+        command.add(user);
+        command.add(passwd);
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Unable to configure httpd to use auth");
+        }
+        return result;
+    }
+
+    private String configureIpFirewall(List<String> ipList, boolean isAppend){
+        Script command = new Script(_configIpFirewallScr);
+        command.add(String.valueOf(isAppend));
+        for (String ip : ipList){
+            command.add(ip);
+        }		
+
+        String result = command.execute();
+        if (result != null) {
+            s_logger.warn("Unable to configure firewall for command : " +command);
+        }
+        return result;
+    }
+
+    protected String mount(String root, String nfsPath) {
         File file = new File(root);
         if (!file.exists()) {
             if (_storage.mkdir(root)) {
@@ -1691,8 +1690,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
                 s_logger.debug("Unable to create mount point: " + root);
                 return null;       
             }
-	    }
-       
+        }
+
         Script script = null;
         String result = null;
         script = new Script(!_inSystemVM, "mount", _timeout, s_logger);
@@ -1705,12 +1704,12 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
                 return root;
             }
         }
-            
+
         Script command = new Script(!_inSystemVM, "mount", _timeout, s_logger);
         command.add("-t", "nfs");
         if (_inSystemVM) {
-        	//Fedora Core 12 errors out with any -o option executed from java
-        	command.add("-o", "soft,timeo=133,retrans=2147483647,tcp,acdirmax=0,acdirmin=0");
+            //Fedora Core 12 errors out with any -o option executed from java
+            command.add("-o", "soft,timeo=133,retrans=2147483647,tcp,acdirmax=0,acdirmin=0");
         }
         command.add(nfsPath);
         command.add(root);
@@ -1719,23 +1718,23 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
             s_logger.warn("Unable to mount " + nfsPath + " due to " + result);
             file = new File(root);
             if (file.exists())
-            	file.delete();
+                file.delete();
             return null;
         }
-        
+
         // XXX: Adding the check for creation of snapshots dir here. Might have to move it somewhere more logical later.
         if (!checkForSnapshotsDir(root)) {
-        	return null;
+            return null;
         }
-        
+
         // Create the volumes dir
         if (!checkForVolumesDir(root)) {
-        	return null;
+            return null;
         }
-        
+
         return root;
     }
-    
+
     @Override
     public boolean start() {
         return true;
@@ -1748,12 +1747,12 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
 
     @Override
     public StartupCommand[] initialize() {
-        
+
         final StartupSecondaryStorageCommand cmd = new StartupSecondaryStorageCommand();
         fillNetworkInformation(cmd);
         if(_publicIp != null)
             cmd.setPublicIpAddress(_publicIp);
-        
+
         Script command = new Script("/bin/bash", s_logger);
         command.add("-c");
         command.add("ln -sf " + _parent + " /var/www/html/copy");
@@ -1769,38 +1768,38 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
         String snapshotsDirLocation = mountPoint + File.separator + "snapshots";
         return createDir("snapshots", snapshotsDirLocation, mountPoint);
     }
-    
+
     protected boolean checkForVolumesDir(String mountPoint) {
-    	String volumesDirLocation = mountPoint + "/" + "volumes";
-    	return createDir("volumes", volumesDirLocation, mountPoint);
+        String volumesDirLocation = mountPoint + "/" + "volumes";
+        return createDir("volumes", volumesDirLocation, mountPoint);
     }
-    
+
     protected boolean createDir(String dirName, String dirLocation, String mountPoint) {
-    	boolean dirExists = false;
-    	
-    	File dir = new File(dirLocation);
-    	if (dir.exists()) {
-    		if (dir.isDirectory()) {
-    			s_logger.debug(dirName + " already exists on secondary storage, and is mounted at " + mountPoint);
-    			dirExists = true;
-    		} else {
-    			if (dir.delete() && _storage.mkdir(dirLocation)) {
-    				dirExists = true;
-    			}
-    		}
-    	} else if (_storage.mkdir(dirLocation)) {
-    		dirExists = true;
-    	}
-
-    	if (dirExists) {
-    		s_logger.info(dirName  + " directory created/exists on Secondary Storage.");
-    	} else {
-    		s_logger.info(dirName + " directory does not exist on Secondary Storage.");
-    	}
-    	
-    	return dirExists;
-    }
-    
+        boolean dirExists = false;
+
+        File dir = new File(dirLocation);
+        if (dir.exists()) {
+            if (dir.isDirectory()) {
+                s_logger.debug(dirName + " already exists on secondary storage, and is mounted at " + mountPoint);
+                dirExists = true;
+            } else {
+                if (dir.delete() && _storage.mkdir(dirLocation)) {
+                    dirExists = true;
+                }
+            }
+        } else if (_storage.mkdir(dirLocation)) {
+            dirExists = true;
+        }
+
+        if (dirExists) {
+            s_logger.info(dirName  + " directory created/exists on Secondary Storage.");
+        } else {
+            s_logger.info(dirName + " directory does not exist on Secondary Storage.");
+        }
+
+        return dirExists;
+    }
+
     @Override
     protected String getDefaultScriptsDir() {
         return "./scripts/storage/secondary";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/core/src/com/cloud/storage/template/DownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/template/DownloadManagerImpl.java b/core/src/com/cloud/storage/template/DownloadManagerImpl.java
index f8b075d..d5ed71e 100755
--- a/core/src/com/cloud/storage/template/DownloadManagerImpl.java
+++ b/core/src/com/cloud/storage/template/DownloadManagerImpl.java
@@ -29,8 +29,8 @@ import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -43,7 +43,6 @@ import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 
-import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.storage.DownloadAnswer;
 import com.cloud.agent.api.storage.DownloadCommand;
 import com.cloud.agent.api.storage.DownloadCommand.Proxy;
@@ -60,10 +59,6 @@ import com.cloud.storage.template.Processor.FormatInfo;
 import com.cloud.storage.template.TemplateDownloader.DownloadCompleteCallback;
 import com.cloud.storage.template.TemplateDownloader.Status;
 import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.component.Adapter;
-import com.cloud.utils.component.Adapters;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.OutputInterpreter;
 import com.cloud.utils.script.Script;
@@ -72,7 +67,7 @@ import com.cloud.utils.script.Script;
 public class DownloadManagerImpl implements DownloadManager {
     private String _name;
     StorageLayer _storage;
-    Adapters<Processor> _processors;
+    Map<String, Processor> _processors;
 
     public class Completion implements DownloadCompleteCallback {
         private final String jobId;
@@ -94,14 +89,14 @@ public class DownloadManagerImpl implements DownloadManager {
         private final boolean hvm;
         private final ImageFormat format;
         private String tmpltPath;
-        private String description;
+        private final String description;
         private String checksum;
-        private Long accountId;
-        private String installPathPrefix;
+        private final Long accountId;
+        private final String installPathPrefix;
         private long templatesize;
         private long templatePhysicalSize;
-        private long id;
-		private ResourceType resourceType;
+        private final long id;
+        private final ResourceType resourceType;
 
         public DownloadJob(TemplateDownloader td, String jobId, long id, String tmpltName, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum, String installPathPrefix, ResourceType resourceType) {
             super();
@@ -160,10 +155,10 @@ public class DownloadManagerImpl implements DownloadManager {
         }
 
         public ResourceType getResourceType() {
-			return resourceType;
-		}
+            return resourceType;
+        }
 
-		public void setTmpltPath(String tmpltPath) {
+        public void setTmpltPath(String tmpltPath) {
             this.tmpltPath = tmpltPath;
         }
 
@@ -205,9 +200,9 @@ public class DownloadManagerImpl implements DownloadManager {
         public long getTemplatePhysicalSize() {
             return templatePhysicalSize;
         }
-        
+
         public void setCheckSum(String checksum) {
-        	this.checksum = checksum;
+            this.checksum = checksum;
         }
     }
 
@@ -216,7 +211,7 @@ public class DownloadManagerImpl implements DownloadManager {
     private String _volumeDir;
     private String createTmpltScr;
     private String createVolScr;
-    private Adapters<Processor> processors;
+    private List<Processor> processors;
 
     private ExecutorService threadPool;
 
@@ -278,9 +273,9 @@ public class DownloadManagerImpl implements DownloadManager {
             break;
         }
     }
-    
+
     private String computeCheckSum(File f) {
-    	byte[] buffer = new byte[8192];
+        byte[] buffer = new byte[8192];
         int read = 0;
         MessageDigest digest;
         String checksum = null;        
@@ -296,16 +291,16 @@ public class DownloadManagerImpl implements DownloadManager {
             checksum = String.format("%032x",bigInt);
             return checksum;
         }catch(IOException e) {
-        	return null;
+            return null;
         }catch (NoSuchAlgorithmException e) {         
-        	return null;
+            return null;
         }
         finally {
             try {
-            	if(is != null)
-            		is.close();
+                if(is != null)
+                    is.close();
             } catch (IOException e) {
-            	return null;
+                return null;
             }                        
         }
     }
@@ -320,17 +315,17 @@ public class DownloadManagerImpl implements DownloadManager {
         TemplateDownloader td = dnld.getTemplateDownloader();
         String resourcePath = null;               
         ResourceType resourceType = dnld.getResourceType();
-       
+
         // once template path is set, remove the parent dir so that the template is installed with a relative path
         String finalResourcePath = "";
         if (resourceType == ResourceType.TEMPLATE){
-        	finalResourcePath += _templateDir + File.separator + dnld.getAccountId() + File.separator + dnld.getId() + File.separator;
-        	resourcePath = dnld.getInstallPathPrefix() + dnld.getAccountId() + File.separator + dnld.getId() + File.separator;// dnld.getTmpltName();
+            finalResourcePath += _templateDir + File.separator + dnld.getAccountId() + File.separator + dnld.getId() + File.separator;
+            resourcePath = dnld.getInstallPathPrefix() + dnld.getAccountId() + File.separator + dnld.getId() + File.separator;// dnld.getTmpltName();
         }else {
-        	finalResourcePath += _volumeDir + File.separator + dnld.getId() + File.separator;
-        	resourcePath = dnld.getInstallPathPrefix() + dnld.getId() + File.separator;// dnld.getTmpltName();
+            finalResourcePath += _volumeDir + File.separator + dnld.getId() + File.separator;
+            resourcePath = dnld.getInstallPathPrefix() + dnld.getId() + File.separator;// dnld.getTmpltName();
         }
-        
+
         _storage.mkdirs(resourcePath);
         dnld.setTmpltPath(finalResourcePath);
 
@@ -389,9 +384,9 @@ public class DownloadManagerImpl implements DownloadManager {
         // Set permissions for template/volume.properties
         String propertiesFile = resourcePath;
         if (resourceType == ResourceType.TEMPLATE){
-        	propertiesFile += "/template.properties";
+            propertiesFile += "/template.properties";
         }else{
-        	propertiesFile += "/volume.properties";
+            propertiesFile += "/volume.properties";
         }
         File templateProperties = new File(propertiesFile);
         _storage.setWorldReadableAndWriteable(templateProperties);
@@ -405,9 +400,9 @@ public class DownloadManagerImpl implements DownloadManager {
             return "Unable to download due to " + e.getMessage();
         }
 
-        Enumeration<Processor> en = _processors.enumeration();
-        while (en.hasMoreElements()) {
-            Processor processor = en.nextElement();
+        Iterator<Processor> en = _processors.values().iterator();
+        while (en.hasNext()) {
+            Processor processor = en.next();
 
             FormatInfo info = null;
             try {
@@ -423,7 +418,7 @@ public class DownloadManagerImpl implements DownloadManager {
                 break;
             }
         }
-        
+
         if (!loc.save()) {
             s_logger.warn("Cleaning up because we're unable to save the formats");
             loc.purge();
@@ -450,9 +445,9 @@ public class DownloadManagerImpl implements DownloadManager {
         String jobId = uuid.toString();
         String tmpDir = "";
         if(resourceType == ResourceType.TEMPLATE){
-        	tmpDir = installPathPrefix + File.separator + accountId + File.separator + id;
+            tmpDir = installPathPrefix + File.separator + accountId + File.separator + id;
         }else {
-        	tmpDir = installPathPrefix + File.separator + id;
+            tmpDir = installPathPrefix + File.separator + id;
         }
 
         try {
@@ -463,7 +458,7 @@ public class DownloadManagerImpl implements DownloadManager {
             }
             //	TO DO - define constant for volume properties.
             File file = ResourceType.TEMPLATE == resourceType ? _storage.getFile(tmpDir + File.separator + TemplateLocation.Filename) : 
-            	_storage.getFile(tmpDir + File.separator + "volume.properties");
+                _storage.getFile(tmpDir + File.separator + "volume.properties");
             if ( file.exists() ) {
                 file.delete();
             }
@@ -524,9 +519,9 @@ public class DownloadManagerImpl implements DownloadManager {
         }
         return 0;
     }
-    
+
     public String getDownloadCheckSum(String jobId) {
-    	DownloadJob dj = jobs.get(jobId);
+        DownloadJob dj = jobs.get(jobId);
         if (dj != null) {
             return dj.getChecksum();
         }
@@ -589,7 +584,7 @@ public class DownloadManagerImpl implements DownloadManager {
 
     @Override
     public DownloadAnswer handleDownloadCommand(SecondaryStorageResource resource, DownloadCommand cmd) {
-    	ResourceType resourceType = cmd.getResourceType();
+        ResourceType resourceType = cmd.getResourceType();
         if (cmd instanceof DownloadProgressCommand) {
             return handleDownloadProgressCmd( resource, (DownloadProgressCommand) cmd);
         }
@@ -604,9 +599,9 @@ public class DownloadManagerImpl implements DownloadManager {
 
         String installPathPrefix = null;
         if (ResourceType.TEMPLATE == resourceType){
-        	installPathPrefix = resource.getRootDir(cmd) + File.separator + _templateDir;
+            installPathPrefix = resource.getRootDir(cmd) + File.separator + _templateDir;
         }else {
-        	installPathPrefix = resource.getRootDir(cmd) + File.separator + _volumeDir;
+            installPathPrefix = resource.getRootDir(cmd) + File.separator + _volumeDir;
         }
 
         String user = null;
@@ -693,10 +688,10 @@ public class DownloadManagerImpl implements DownloadManager {
 
     }
 
-    
+
     private List<String> listVolumes(String rootdir) {
         List<String> result = new ArrayList<String>();
-        
+
         Script script = new Script(listVolScr, s_logger);
         script.add("-r", rootdir);
         ZfsPathParser zpp = new ZfsPathParser(rootdir);
@@ -705,12 +700,12 @@ public class DownloadManagerImpl implements DownloadManager {
         s_logger.info("found " + zpp.getPaths().size() + " volumes" + zpp.getPaths());
         return result;
     }
-    
-    
-    
+
+
+
     private List<String> listTemplates(String rootdir) {
         List<String> result = new ArrayList<String>();
-        
+
         Script script = new Script(listTmpltScr, s_logger);
         script.add("-r", rootdir);
         ZfsPathParser zpp = new ZfsPathParser(rootdir);
@@ -724,11 +719,11 @@ public class DownloadManagerImpl implements DownloadManager {
     public Map<String, TemplateInfo> gatherTemplateInfo(String rootDir) {
         Map<String, TemplateInfo> result = new HashMap<String, TemplateInfo>();
         String templateDir = rootDir + File.separator + _templateDir;
-        
+
         if (! _storage.exists(templateDir)) {
             _storage.mkdirs(templateDir);
         }
-        
+
         List<String> publicTmplts = listTemplates(templateDir);
         for (String tmplt : publicTmplts) {
             String path = tmplt.substring(0, tmplt.lastIndexOf(File.separator));
@@ -746,18 +741,18 @@ public class DownloadManagerImpl implements DownloadManager {
             }
 
             TemplateInfo tInfo = loc.getTemplateInfo();
-            
+
             if ((tInfo.size == tInfo.physicalSize) && (tInfo.installPath.endsWith(ImageFormat.OVA.getFileExtension()))) {
-            	try {
-            	    Processor processor = _processors.get("VMDK Processor");
-            	    VmdkProcessor vmdkProcessor = (VmdkProcessor)processor;
-            	    long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.installPath.substring(tInfo.installPath.lastIndexOf(File.separator) + 1));
-                	tInfo.size = vSize;
-                	loc.updateVirtualSize(vSize);
-                	loc.save();
-            	} catch (Exception e) {
-            		s_logger.error("Unable to get the virtual size of the template: " + tInfo.installPath + " due to " + e.getMessage());
-            	}
+                try {
+                    Processor processor = _processors.get("VMDK Processor");
+                    VmdkProcessor vmdkProcessor = (VmdkProcessor)processor;
+                    long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.installPath.substring(tInfo.installPath.lastIndexOf(File.separator) + 1));
+                    tInfo.size = vSize;
+                    loc.updateVirtualSize(vSize);
+                    loc.save();
+                } catch (Exception e) {
+                    s_logger.error("Unable to get the virtual size of the template: " + tInfo.installPath + " due to " + e.getMessage());
+                }
             }
 
             result.put(tInfo.templateName, tInfo);
@@ -777,52 +772,52 @@ public class DownloadManagerImpl implements DownloadManager {
         return result;
     }
 
-	@Override
-	public Map<Long, TemplateInfo> gatherVolumeInfo(String rootDir) {	
-	        Map<Long, TemplateInfo> result = new HashMap<Long, TemplateInfo>();
-	        String volumeDir = rootDir + File.separator + _volumeDir;
-	        
-	        if (! _storage.exists(volumeDir)) {
-	            _storage.mkdirs(volumeDir);
-	        }
-	        
-	        List<String> vols = listVolumes(volumeDir);
-	        for (String vol : vols) {
-	            String path = vol.substring(0, vol.lastIndexOf(File.separator));
-	            TemplateLocation loc = new TemplateLocation(_storage, path);
-	            try {
-	                if (!loc.load()) {
-	                    s_logger.warn("Post download installation was not completed for " + path);
-	                    //loc.purge();
-	                    _storage.cleanup(path, volumeDir);
-	                    continue;
-	                }
-	            } catch (IOException e) {
-	                s_logger.warn("Unable to load volume location " + path, e);
-	                continue;
-	            }
-
-	            TemplateInfo vInfo = loc.getTemplateInfo();
-	            
-	            if ((vInfo.size == vInfo.physicalSize) && (vInfo.installPath.endsWith(ImageFormat.OVA.getFileExtension()))) {
-	            	try {
-	            	    Processor processor = _processors.get("VMDK Processor");
-	            	    VmdkProcessor vmdkProcessor = (VmdkProcessor)processor;
-	            	    long vSize = vmdkProcessor.getTemplateVirtualSize(path, vInfo.installPath.substring(vInfo.installPath.lastIndexOf(File.separator) + 1));
-	                	vInfo.size = vSize;
-	                	loc.updateVirtualSize(vSize);
-	                	loc.save();
-	            	} catch (Exception e) {
-	            		s_logger.error("Unable to get the virtual size of the volume: " + vInfo.installPath + " due to " + e.getMessage());
-	            	}
-	            }
-
-	            result.put(vInfo.getId(), vInfo);
-	            s_logger.debug("Added volume name: " + vInfo.templateName + ", path: " + vol);
-	        }
-	        return result;
-	    }
-	
+    @Override
+    public Map<Long, TemplateInfo> gatherVolumeInfo(String rootDir) {	
+        Map<Long, TemplateInfo> result = new HashMap<Long, TemplateInfo>();
+        String volumeDir = rootDir + File.separator + _volumeDir;
+
+        if (! _storage.exists(volumeDir)) {
+            _storage.mkdirs(volumeDir);
+        }
+
+        List<String> vols = listVolumes(volumeDir);
+        for (String vol : vols) {
+            String path = vol.substring(0, vol.lastIndexOf(File.separator));
+            TemplateLocation loc = new TemplateLocation(_storage, path);
+            try {
+                if (!loc.load()) {
+                    s_logger.warn("Post download installation was not completed for " + path);
+                    //loc.purge();
+                    _storage.cleanup(path, volumeDir);
+                    continue;
+                }
+            } catch (IOException e) {
+                s_logger.warn("Unable to load volume location " + path, e);
+                continue;
+            }
+
+            TemplateInfo vInfo = loc.getTemplateInfo();
+
+            if ((vInfo.size == vInfo.physicalSize) && (vInfo.installPath.endsWith(ImageFormat.OVA.getFileExtension()))) {
+                try {
+                    Processor processor = _processors.get("VMDK Processor");
+                    VmdkProcessor vmdkProcessor = (VmdkProcessor)processor;
+                    long vSize = vmdkProcessor.getTemplateVirtualSize(path, vInfo.installPath.substring(vInfo.installPath.lastIndexOf(File.separator) + 1));
+                    vInfo.size = vSize;
+                    loc.updateVirtualSize(vSize);
+                    loc.save();
+                } catch (Exception e) {
+                    s_logger.error("Unable to get the virtual size of the volume: " + vInfo.installPath + " due to " + e.getMessage());
+                }
+            }
+
+            result.put(vInfo.getId(), vInfo);
+            s_logger.debug("Added volume name: " + vInfo.templateName + ", path: " + vol);
+        }
+        return result;
+    }
+
     private int deleteDownloadDirectories(File downloadPath, int deleted) {
         try {
             if (downloadPath.exists()) {
@@ -881,7 +876,7 @@ public class DownloadManagerImpl implements DownloadManager {
 
         String value = null;
 
-        _storage = (StorageLayer) params.get(StorageLayer.InstanceConfigKey);
+        _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
         if (_storage == null) {
             value = (String) params.get(StorageLayer.ClassConfigKey);
             if (value == null) {
@@ -891,10 +886,14 @@ public class DownloadManagerImpl implements DownloadManager {
             Class<StorageLayer> clazz;
             try {
                 clazz = (Class<StorageLayer>) Class.forName(value);
+                _storage = clazz.newInstance();
             } catch (ClassNotFoundException e) {
                 throw new ConfigurationException("Unable to instantiate " + value);
+            } catch (InstantiationException e) {
+                throw new ConfigurationException("Unable to instantiate " + value);
+            } catch (IllegalAccessException e) {
+                throw new ConfigurationException("Unable to instantiate " + value);
             }
-            _storage = ComponentLocator.inject(clazz);
         }
         String useSsl = (String)params.get("sslcopy");
         if (useSsl != null) {
@@ -943,29 +942,27 @@ public class DownloadManagerImpl implements DownloadManager {
         }
         s_logger.info("createvolume.sh found in " + createVolScr);
 
-        List<ComponentInfo<Adapter>> processors = new ArrayList<ComponentInfo<Adapter>>();
+        _processors = new HashMap<String, Processor>();
 
         Processor processor = new VhdProcessor();
         processor.configure("VHD Processor", params);
-        processors.add(new ComponentInfo<Adapter>("VHD Processor", VhdProcessor.class, processor));
+        _processors.put("VHD Processor", processor);
 
         processor = new IsoProcessor();
         processor.configure("ISO Processor", params);
-        processors.add(new ComponentInfo<Adapter>("ISO Processor", IsoProcessor.class, processor));
+        _processors.put("ISO Processor", processor);
 
         processor = new QCOW2Processor();
         processor.configure("QCOW2 Processor", params);
-        processors.add(new ComponentInfo<Adapter>("QCOW2 Processor", QCOW2Processor.class, processor));
+        _processors.put("QCOW2 Processor", processor);
 
         processor = new VmdkProcessor();
         processor.configure("VMDK Processor", params);
-        processors.add(new ComponentInfo<Adapter>("VMDK Processor", VmdkProcessor.class, processor));
+        _processors.put("VMDK Processor", processor);
 
         processor = new RawImageProcessor();
         processor.configure("Raw Image Processor", params);
-        processors.add(new ComponentInfo<Adapter>("Raw Image Processor", RawImageProcessor.class, processor));
-        
-        _processors = new Adapters<Processor>("processors", processors);
+        _processors.put("Raw Image Processor", processor);
 
         _templateDir = (String) params.get("public.templates.root.dir");
         if (_templateDir == null) {
@@ -1047,5 +1044,5 @@ public class DownloadManagerImpl implements DownloadManager {
             return;
         }
     }
-	
+
 }