You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/01/10 23:47:20 UTC

[7/25] removed componentlocator and inject

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f40e7b75/core/src/com/cloud/storage/resource/CifsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/CifsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/CifsSecondaryStorageResource.java
index c606fca..0df2a84 100755
--- a/core/src/com/cloud/storage/resource/CifsSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/CifsSecondaryStorageResource.java
@@ -40,8 +40,8 @@ import com.cloud.agent.api.PingStorageCommand;
 import com.cloud.agent.api.ReadyAnswer;
 import com.cloud.agent.api.ReadyCommand;
 import com.cloud.agent.api.SecStorageFirewallCfgCommand;
-import com.cloud.agent.api.SecStorageSetupCommand;
 import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
+import com.cloud.agent.api.SecStorageSetupCommand;
 import com.cloud.agent.api.SecStorageVMSetupCommand;
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupStorageCommand;
@@ -54,7 +54,6 @@ import com.cloud.agent.api.storage.UploadCommand;
 import com.cloud.agent.api.storage.ssCommand;
 import com.cloud.host.Host;
 import com.cloud.host.Host.Type;
-import com.cloud.resource.ServerResource;
 import com.cloud.resource.ServerResourceBase;
 import com.cloud.storage.Storage;
 import com.cloud.storage.Storage.StoragePoolType;
@@ -65,7 +64,7 @@ import com.cloud.storage.template.TemplateInfo;
 import com.cloud.storage.template.UploadManager;
 import com.cloud.storage.template.UploadManagerImpl;
 import com.cloud.utils.NumbersUtil;
-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.net.NfsUtils;
@@ -81,10 +80,10 @@ import com.cloud.utils.script.Script;
 public class CifsSecondaryStorageResource extends ServerResourceBase implements SecondaryStorageResource {
     private static final Logger s_logger = Logger.getLogger(CifsSecondaryStorageResource.class);
     int _timeout;
-    
+
     String _instance;
     String _parent;
-    
+
     String _dc;
     String _pod;
     String _guid;
@@ -94,27 +93,27 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
     StorageLayer _storage;
     boolean _inSystemVM = false;
     boolean _sslCopy = false;
-    
+
     Random _rand = new Random(System.currentTimeMillis());
-    
+
     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 _configSslScr;
+    private String _configAuthScr;
+    private String _configIpFirewallScr;
+    private String _publicIp;
+    private String _hostname;
+    private String _localgw;
+    private String _eth1mask;
+    private String _eth1ip;
+
     @Override
     public void disconnected() {
         if (_parent != null && !_inSystemVM) {
             Script script = new Script(!_inSystemVM, "umount", _timeout, s_logger);
             script.add(_parent);
             script.execute();
-            
+
             File file = new File(_parent);
             file.delete();
         }
@@ -133,104 +132,104 @@ public class CifsSecondaryStorageResource 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 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 new Answer(cmd, true, "success");
         } else {
             return Answer.createUnsupportedCommandAnswer(cmd);
         }
     }
-    
+
     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()) {
-			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()) {
+            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 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);
-		if (result !=null)
-			success = false;
-
-		return new Answer(cmd, success, result);
-	}
-
-	protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
+
+        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);
+        if (result !=null)
+            success = false;
+
+        return new Answer(cmd, success, result);
+    }
+
+    protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
         final long usedSize = getUsedSize();
         final long totalSize = getTotalSize();
         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) ;
         }
     }
-    
+
     @Override
     public String getRootDir(ssCommand cmd){
         return null;
     }
-    
+
     protected Answer execute(final DeleteTemplateCommand cmd) {
         String relativeTemplatePath = cmd.getTemplatePath();
         String parent = _parent;
@@ -278,15 +277,15 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
         }
         return new Answer(cmd, true, null);
     }
-    
+
     protected long getUsedSize() {
-    	return _storage.getUsedSpace(_parent);
+        return _storage.getUsedSpace(_parent);
     }
-    
+
     protected long getTotalSize() {
-      	return _storage.getTotalSpace(_parent);
+        return _storage.getTotalSpace(_parent);
     }
-    
+
     protected long convertFilesystemSize(final String size) {
         if (size == null || size.isEmpty()) {
             return -1;
@@ -305,25 +304,25 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
 
         return (long)(Double.parseDouble(size.substring(0, size.length() - 1)) * multiplier);
     }
-    
+
 
     @Override
     public Type getType() {
         return Host.Type.SecondaryStorage;
     }
-    
+
     @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");
         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) {
@@ -331,23 +330,23 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
         }         
         _publicIp = (String) params.get("eth2ip");
         _hostname = (String) params.get("name");
-        
+
         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);
@@ -362,30 +361,30 @@ public class CifsSecondaryStorageResource 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);
         }
-        
+
         _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");
 
         _mountParent = (String)params.get("mount.parent");
         if (_mountParent == null) {
             _mountParent = File.separator + "mnt";
         }
-        
+
         if (_instance != null) {
             _mountParent = _mountParent + File.separator + _instance;
         }
@@ -394,63 +393,63 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
         if (_nfsPath == null) {
             throw new ConfigurationException("Unable to find mount.path");
         }
-        
 
-        
+
+
         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
-            	_eth1mask = (String)params.get("eth1mask");
-            	String internalDns1 = (String)params.get("dns1");
-            	String internalDns2 = (String)params.get("dns2");
-
-            	if (internalDns1 == null) {
-            		s_logger.warn("No DNS entry found during configuration of NfsSecondaryStorage");
-            	} else {
-            		addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns1);
-            	}
-            	
-            	String mgmtHost = (String)params.get("host");
-            	String nfsHost = NfsUtils.getHostPart(_nfsPath);
-            	if (nfsHost == null) {
-            		s_logger.error("Invalid or corrupt nfs url " + _nfsPath);
-            		throw new CloudRuntimeException("Unable to determine host part of nfs path");
-            	}
-            	try {
-            		InetAddress nfsHostAddr = InetAddress.getByName(nfsHost);
-            		nfsHost = nfsHostAddr.getHostAddress();
-            	} catch (UnknownHostException uhe) {
-            		s_logger.error("Unable to resolve nfs host " + nfsHost);
-            		throw new CloudRuntimeException("Unable to resolve nfs host to an ip address " + nfsHost);
-            	}
-            	addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, nfsHost);
-            	addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost);
-            	if (internalDns2 != null) {
-                	addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns2);
-            	}
+                _eth1mask = (String)params.get("eth1mask");
+                String internalDns1 = (String)params.get("dns1");
+                String internalDns2 = (String)params.get("dns2");
+
+                if (internalDns1 == null) {
+                    s_logger.warn("No DNS entry found during configuration of NfsSecondaryStorage");
+                } else {
+                    addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns1);
+                }
+
+                String mgmtHost = (String)params.get("host");
+                String nfsHost = NfsUtils.getHostPart(_nfsPath);
+                if (nfsHost == null) {
+                    s_logger.error("Invalid or corrupt nfs url " + _nfsPath);
+                    throw new CloudRuntimeException("Unable to determine host part of nfs path");
+                }
+                try {
+                    InetAddress nfsHostAddr = InetAddress.getByName(nfsHost);
+                    nfsHost = nfsHostAddr.getHostAddress();
+                } catch (UnknownHostException uhe) {
+                    s_logger.error("Unable to resolve nfs host " + nfsHost);
+                    throw new CloudRuntimeException("Unable to resolve nfs host to an ip address " + nfsHost);
+                }
+                addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, nfsHost);
+                addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost);
+                if (internalDns2 != null) {
+                    addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns2);
+                }
 
             }
             String useSsl = (String)params.get("sslcopy");
             if (useSsl != null) {
-            	_sslCopy = Boolean.parseBoolean(useSsl);
-            	if (_sslCopy) {
-            		configureSSL();
-            	}
+                _sslCopy = Boolean.parseBoolean(useSsl);
+                if (_sslCopy) {
+                    configureSSL();
+                }
             }
-        	startAdditionalServices();
-        	_params.put("install.numthreads", "50");
-        	_params.put("secondary.storage.vm", "true");
+            startAdditionalServices();
+            _params.put("install.numthreads", "50");
+            _params.put("secondary.storage.vm", "true");
         }
         _parent = mount(_nfsPath, _mountParent);
         if (_parent == null) {
             throw new ConfigurationException("Unable to create mount point");
         }
-        
-        
+
+
         s_logger.info("Mount point established at " + _parent);
-        
+
         try {
             _params.put("template.parent", _parent);
             _params.put(StorageLayer.InstanceConfigKey, _storage);
@@ -464,98 +463,98 @@ public class CifsSecondaryStorageResource 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);
-    	}
+        }
+        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(_publicIp);
+        command.add(_hostname);
+        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){
+        Script command = new Script(_configIpFirewallScr);		
+        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;
     }
 
-	private void configureSSL() {
-		Script command = new Script(_configSslScr);
-		command.add(_publicIp);
-		command.add(_hostname);
-		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){
-		Script command = new Script(_configIpFirewallScr);		
-		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 path, String parent) {
+    protected String mount(String path, String parent) {
         String mountPoint = null;
         for (int i = 0; i < 10; i++) {
             String mntPt = parent + File.separator + Integer.toHexString(_rand.nextInt(Integer.MAX_VALUE));
@@ -568,29 +567,29 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
             }
             s_logger.debug("Unable to create mount: " + mntPt);
         }
-        
+
         if (mountPoint == null) {
             s_logger.warn("Unable to create a mount point");
             return null;
         }
-       
+
         Script script = null;
         String result = null;
         script = new Script(!_inSystemVM, "umount", _timeout, s_logger);
         script.add(path);
         result = script.execute();
-        
+
         if( _parent != null ) {
             script = new Script("rmdir", _timeout, s_logger);
             script.add(_parent);
             result = script.execute();
         }
- 
+
         Script command = new Script(!_inSystemVM, "mount", _timeout, s_logger);
         command.add("-t", "cifs");
         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");
         }
         String tok[] = path.split(":");
         //command.add(path);
@@ -601,25 +600,25 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
             s_logger.warn("Unable to mount " + path + " due to " + result);
             File file = new File(mountPoint);
             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(mountPoint)) {
-        	return null;
+            return null;
         }
-        
+
         // Create the volumes dir
         if (!checkForVolumesDir(mountPoint)) {
-        	return null;
+            return null;
         }
-        
+
         return mountPoint;
     }
-    
+
     @Override
     public boolean start() {
         return true;
@@ -633,14 +632,14 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
     @Override
     public StartupCommand[] initialize() {
         /*disconnected();
-        
+
         _parent = mount(_nfsPath, _mountParent);
-        
+
         if( _parent == null ) {
             s_logger.warn("Unable to mount the nfs server");
             return null;
         }
-        
+
         try {
             _params.put("template.parent", _parent);
             _params.put(StorageLayer.InstanceConfigKey, _storage);
@@ -650,12 +649,12 @@ public class CifsSecondaryStorageResource extends ServerResourceBase implements
             s_logger.warn("Caught problem while configuring folers", e);
             return null;
         }*/
-        
+
         final StartupStorageCommand cmd = new StartupStorageCommand(_parent, StoragePoolType.NetworkFilesystem, getTotalSize(), new HashMap<String, TemplateInfo>());
-        
+
         cmd.setResourceType(Storage.StorageResourceType.SECONDARY_STORAGE);
         cmd.setIqn(null);
-        
+
         fillNetworkInformation(cmd);
         cmd.setDataCenter(_dc);
         cmd.setPod(_pod);
@@ -687,38 +686,38 @@ public class CifsSecondaryStorageResource 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/f40e7b75/core/src/com/cloud/storage/resource/LocalSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/LocalSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/LocalSecondaryStorageResource.java
index d9c69f8..b86fe6c 100644
--- a/core/src/com/cloud/storage/resource/LocalSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/LocalSecondaryStorageResource.java
@@ -19,7 +19,6 @@ package com.cloud.storage.resource;
 import java.util.HashMap;
 import java.util.Map;
 
-
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
@@ -36,11 +35,11 @@ import com.cloud.agent.api.ReadyCommand;
 import com.cloud.agent.api.SecStorageSetupCommand;
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupStorageCommand;
+import com.cloud.agent.api.storage.DownloadCommand;
+import com.cloud.agent.api.storage.DownloadProgressCommand;
 import com.cloud.agent.api.storage.ListTemplateAnswer;
 import com.cloud.agent.api.storage.ListTemplateCommand;
 import com.cloud.agent.api.storage.ssCommand;
-import com.cloud.agent.api.storage.DownloadCommand;
-import com.cloud.agent.api.storage.DownloadProgressCommand;
 import com.cloud.host.Host;
 import com.cloud.host.Host.Type;
 import com.cloud.resource.ServerResourceBase;
@@ -50,39 +49,38 @@ import com.cloud.storage.StorageLayer;
 import com.cloud.storage.template.DownloadManager;
 import com.cloud.storage.template.DownloadManagerImpl;
 import com.cloud.storage.template.TemplateInfo;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.component.ComponentContext;
 
 public class LocalSecondaryStorageResource extends ServerResourceBase implements SecondaryStorageResource {
     private static final Logger s_logger = Logger.getLogger(LocalSecondaryStorageResource.class);
     int _timeout;
-    
+
     String _instance;
     String _parent;
-    
+
     String _dc;
     String _pod;
     String _guid;
-    
+
     StorageLayer _storage;
-    
+
     DownloadManager _dlMgr;
-    
+
     @Override
     public void disconnected() {
     }
 
-    
+
     @Override
     public String getRootDir(ssCommand cmd){
         return getRootDir();
-        
+
     }
-    
+
     public String getRootDir() {
         return _parent;
     }
-    
+
     @Override
     public Answer executeRequest(Command cmd) {
         if (cmd instanceof DownloadProgressCommand) {
@@ -103,7 +101,7 @@ public class LocalSecondaryStorageResource extends ServerResourceBase implements
             return Answer.createUnsupportedCommandAnswer(cmd);
         }
     }
-    
+
     private Answer execute(ComputeChecksumCommand cmd) {
         return new Answer(cmd, false, null);   
     }
@@ -119,13 +117,13 @@ public class LocalSecondaryStorageResource extends ServerResourceBase implements
     public Type getType() {
         return Host.Type.LocalSecondaryStorage;
     }
-    
+
     @Override
     public PingCommand getCurrentStatus(final long id) {
         return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
     }
-    
-   
+
+
     @Override
     @SuppressWarnings("unchecked")
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@@ -135,30 +133,30 @@ public class LocalSecondaryStorageResource extends ServerResourceBase implements
         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");
 
         _parent = (String)params.get("mount.path");
         if (_parent == null) {
             throw new ConfigurationException("No directory specified.");
         }
-        
+
         _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
         if (_storage == null) {
             String value = (String)params.get(StorageLayer.ClassConfigKey);
             if (value == null) {
                 value = "com.cloud.storage.JavaStorageLayer";
             }
-            
+
             try {
                 Class<StorageLayer> clazz = (Class<StorageLayer>)Class.forName(value);
-                _storage = ComponentLocator.inject(clazz);
+                _storage = ComponentContext.inject(clazz);
             } catch (ClassNotFoundException e) {
                 throw new ConfigurationException("Unable to find class " + value);
             }
@@ -168,15 +166,15 @@ public class LocalSecondaryStorageResource extends ServerResourceBase implements
             s_logger.warn("Unable to create the directory " + _parent);
             throw new ConfigurationException("Unable to create the directory " + _parent);
         }
-     
+
         s_logger.info("Mount point established at " + _parent);
 
         params.put("template.parent", _parent);
         params.put(StorageLayer.InstanceConfigKey, _storage);
-        
+
         _dlMgr = new DownloadManagerImpl();
         _dlMgr.configure("DownloadManager", params);
-        
+
         return true;
     }
 
@@ -192,7 +190,7 @@ public class LocalSecondaryStorageResource extends ServerResourceBase implements
 
     @Override
     public StartupCommand[] initialize() {
-        
+
         final StartupStorageCommand cmd = new StartupStorageCommand(_parent, StoragePoolType.Filesystem, 1024l*1024l*1024l*1024l, _dlMgr.gatherTemplateInfo(_parent));
         cmd.setResourceType(Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE);
         cmd.setIqn("local://");
@@ -202,10 +200,10 @@ public class LocalSecondaryStorageResource extends ServerResourceBase implements
         cmd.setGuid(_guid);
         cmd.setName(_guid);
         cmd.setVersion(LocalSecondaryStorageResource.class.getPackage().getImplementationVersion());
-              
+
         return new StartupCommand [] {cmd};
     }
-    
+
     @Override
     protected String getDefaultScriptsDir() {
         return "scripts/storage/secondary";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f40e7b75/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";