Updated Branches:
  refs/heads/4.2 42f49d031 -> 9a9ef3112

CLOUDSTACK-4318:[Object_Store_Refactor] Failed to delete snapshot copied
to Staging storage during snapshot creation.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9a9ef311
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9a9ef311
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9a9ef311

Branch: refs/heads/4.2
Commit: 9a9ef3112cbcdc6fd6cf05d1704f5c3c723c9e56
Parents: f197a7b
Author: Min Chen <[email protected]>
Authored: Wed Aug 14 18:00:35 2013 -0700
Committer: Min Chen <[email protected]>
Committed: Wed Aug 14 18:01:09 2013 -0700

----------------------------------------------------------------------
 .../storage/image/store/TemplateObject.java     |   4 +-
 .../consoleproxy/ConsoleProxyManagerImpl.java   |  33 ++--
 .../secondary/SecondaryStorageManagerImpl.java  | 169 ++++++++++---------
 .../resource/NfsSecondaryStorageResource.java   |  21 ++-
 4 files changed, 125 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9a9ef311/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
 
b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
index b04ca6c..9c9c751 100644
--- 
a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
+++ 
b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
@@ -198,7 +198,9 @@ public class TemplateObject implements TemplateInfo {
                     templateStoreRef.setDownloadPercent(100);
                     templateStoreRef.setDownloadState(Status.DOWNLOADED);
                     templateStoreRef.setSize(newTemplate.getSize());
-                    
templateStoreRef.setPhysicalSize(newTemplate.getPhysicalSize());
+                    if (newTemplate.getPhysicalSize() != null) {
+                        
templateStoreRef.setPhysicalSize(newTemplate.getPhysicalSize());
+                    }
                     templateStoreDao.update(templateStoreRef.getId(), 
templateStoreRef);
                     if (this.getDataStore().getRole() == DataStoreRole.Image) {
                         VMTemplateVO templateVO = 
this.imageDao.findById(this.getId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9a9ef311/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java 
b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 3d58731..e1c2e91 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -156,7 +156,7 @@ import com.google.gson.GsonBuilder;
 //
 @Local(value = { ConsoleProxyManager.class, ConsoleProxyService.class })
 public class ConsoleProxyManagerImpl extends ManagerBase implements 
ConsoleProxyManager,
-        VirtualMachineGuru<ConsoleProxyVO>, SystemVmLoadScanHandler<Long>, 
ResourceStateAdapter {
+VirtualMachineGuru<ConsoleProxyVO>, SystemVmLoadScanHandler<Long>, 
ResourceStateAdapter {
     private static final Logger s_logger = 
Logger.getLogger(ConsoleProxyManagerImpl.class);
 
     private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 
seconds
@@ -558,7 +558,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
 
             // For VMs that are in Stopping, Starting, Migrating state, let 
client to wait by returning null
             // as sooner or later, Starting/Migrating state will be transited 
to Running and Stopping will be transited
-// to
+            // to
             // Stopped to allow
             // Starting of it
             s_logger.warn("Console proxy is not in correct state to be 
started: " + proxy.getState());
@@ -650,7 +650,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
         HypervisorType availableHypervisor = 
_resourceMgr.getAvailableHypervisor(dataCenterId);
         template = _templateDao.findSystemVMReadyTemplate(dataCenterId, 
availableHypervisor);
         if (template == null) {
-             throw new CloudRuntimeException("Not able to find the System 
templates or not downloaded in zone " + dataCenterId);
+            throw new CloudRuntimeException("Not able to find the System 
templates or not downloaded in zone " + dataCenterId);
         }
 
         Map<String, Object> context = createProxyInstance(dataCenterId, 
template);
@@ -696,18 +696,18 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
             }
             defaultNetwork = networks.get(0);
         } else {
-        TrafficType defaultTrafficType = TrafficType.Public;
-        if (dc.getNetworkType() == NetworkType.Basic || 
dc.isSecurityGroupEnabled()) {
-            defaultTrafficType = TrafficType.Guest;
-        }
-        List<NetworkVO> defaultNetworks = 
_networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
+            TrafficType defaultTrafficType = TrafficType.Public;
+            if (dc.getNetworkType() == NetworkType.Basic || 
dc.isSecurityGroupEnabled()) {
+                defaultTrafficType = TrafficType.Guest;
+            }
+            List<NetworkVO> defaultNetworks = 
_networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
 
             // api should never allow this situation to happen
-        if (defaultNetworks.size() != 1) {
+            if (defaultNetworks.size() != 1) {
                 throw new CloudRuntimeException("Found " + 
defaultNetworks.size() + " networks of type "
-                      + defaultTrafficType + " when expect to find 1");
+                        + defaultTrafficType + " when expect to find 1");
             }
-             defaultNetwork = defaultNetworks.get(0);
+            defaultNetwork = defaultNetworks.get(0);
         }
 
         List<? extends NetworkOffering> offerings = 
_networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork,
 NetworkOffering.SystemManagementNetwork);
@@ -939,6 +939,12 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
         ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
         if (zoneHostInfo != null && isZoneHostReady(zoneHostInfo)) {
             VMTemplateVO template = 
_templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
+            if (template == null) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("System vm template is not ready at data 
center " + dataCenterId + ", wait until it is ready to launch console proxy 
vm");
+                }
+                return false;
+            }
             TemplateDataStoreVO templateHostRef = 
this._vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), 
dataCenterId,
                     Status.DOWNLOADED);
 
@@ -1269,8 +1275,9 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
         String cpvmSrvcOffIdStr = 
configs.get(Config.ConsoleProxyServiceOffering.key());
         if (cpvmSrvcOffIdStr != null) {
             DiskOffering diskOffering = 
_diskOfferingDao.findByUuid(cpvmSrvcOffIdStr);
-            if (diskOffering == null)
+            if (diskOffering == null) {
                 diskOffering = 
_diskOfferingDao.findById(Long.parseLong(cpvmSrvcOffIdStr));
+            }
             if (diskOffering != null) {
                 _serviceOffering = _offeringDao.findById(diskOffering.getId());
             } else {
@@ -1523,7 +1530,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
     @Override
     public void onScanStart() {
         // to reduce possible number of DB queries for capacity scan, we run 
following aggregated queries in preparation
-// stage
+        // stage
         _zoneHostInfoMap = getZoneHostInfo();
 
         _zoneProxyCountMap = new HashMap<Long, ConsoleProxyLoadInfo>();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9a9ef311/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java 
b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
index 52789a1..ba677a0 100755
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
+++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
@@ -117,7 +117,6 @@ import com.cloud.utils.Pair;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.GlobalLock;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria2;
 import com.cloud.utils.db.SearchCriteriaService;
 import com.cloud.utils.events.SubscriptionMgr;
@@ -256,7 +255,7 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
     private final GlobalLock _allocLock = 
GlobalLock.getInternLock(getAllocLockName());
 
     public SecondaryStorageManagerImpl() {
-       _ssvmMgr = this;
+        _ssvmMgr = this;
     }
 
     @Override
@@ -301,16 +300,18 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
             }
 
             List<DataStore> ssStores = 
this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
-             for( DataStore ssStore : ssStores ) {
-                 if (!(ssStore.getTO() instanceof NfsTO ))
-                     continue; // only do this for Nfs
+            for( DataStore ssStore : ssStores ) {
+                if (!(ssStore.getTO() instanceof NfsTO ))
+                {
+                    continue; // only do this for Nfs
+                }
                 String secUrl = ssStore.getUri();
                 SecStorageSetupCommand setupCmd = null;
                 if (!_useSSlCopy) {
-                       setupCmd = new SecStorageSetupCommand(ssStore.getTO(), 
secUrl, null);
+                    setupCmd = new SecStorageSetupCommand(ssStore.getTO(), 
secUrl, null);
                 } else {
-                       Certificates certs = 
_keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
-                       setupCmd = new SecStorageSetupCommand(ssStore.getTO(), 
secUrl, certs);
+                    Certificates certs = 
_keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
+                    setupCmd = new SecStorageSetupCommand(ssStore.getTO(), 
secUrl, certs);
                 }
 
                 Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
@@ -353,7 +354,7 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
                 }
             }
         }
-        */
+         */
         return true;
     }
 
@@ -428,9 +429,9 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
         sc.addAnd(sc.getEntity().getStatus(), Op.IN, com.cloud.host.Status.Up, 
com.cloud.host.Status.Connecting);
         List<HostVO> ssvms = sc.list();
         for (HostVO ssvm : ssvms) {
-               if (ssvm.getId() == ssAHostId) {
-                       continue;
-               }
+            if (ssvm.getId() == ssAHostId) {
+                continue;
+            }
             Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc);
             if (answer != null && answer.getResult()) {
                 if (s_logger.isDebugEnabled()) {
@@ -446,10 +447,10 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
 
         SecStorageFirewallCfgCommand allSSVMIpList = new 
SecStorageFirewallCfgCommand(false);
         for (HostVO ssvm : ssvms) {
-               if (ssvm.getId() == ssAHostId) {
-                       continue;
-               }
-               allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), 
copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
+            if (ssvm.getId() == ssAHostId) {
+                continue;
+            }
+            allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, 
true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
         }
 
         Answer answer = _agentMgr.easySend(ssAHostId, allSSVMIpList);
@@ -542,16 +543,16 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
             }
             defaultNetwork = networks.get(0);
         } else {
-        TrafficType defaultTrafficType = TrafficType.Public;
+            TrafficType defaultTrafficType = TrafficType.Public;
 
-        if (dc.getNetworkType() == NetworkType.Basic || 
dc.isSecurityGroupEnabled()) {
-               defaultTrafficType = TrafficType.Guest;
-        }
-        List<NetworkVO> defaultNetworks = 
_networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
+            if (dc.getNetworkType() == NetworkType.Basic || 
dc.isSecurityGroupEnabled()) {
+                defaultTrafficType = TrafficType.Guest;
+            }
+            List<NetworkVO> defaultNetworks = 
_networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
             // api should never allow this situation to happen
-        if (defaultNetworks.size() != 1) {
+            if (defaultNetworks.size() != 1) {
                 throw new CloudRuntimeException("Found " + 
defaultNetworks.size() + " networks of type "
-                                + defaultTrafficType + " when expect to find 
1");
+                        + defaultTrafficType + " when expect to find 1");
             }
             defaultNetwork = defaultNetworks.get(0);
         }
@@ -562,7 +563,7 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
         defaultNic.setDefaultNic(true);
         defaultNic.setDeviceId(2);
         try {
-               networks.add(new Pair<NetworkVO, 
NicProfile>(_networkMgr.setupNetwork(systemAcct, 
_networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, 
null, null, false).get(0), defaultNic));
+            networks.add(new Pair<NetworkVO, 
NicProfile>(_networkMgr.setupNetwork(systemAcct, 
_networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, 
null, null, false).get(0), defaultNic));
             for (NetworkOffering offering : offerings) {
                 networks.add(new Pair<NetworkVO, 
NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, 
false).get(0), null));
             }
@@ -596,8 +597,9 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
     private SecondaryStorageVmAllocator getCurrentAllocator() {
 
         // for now, only one adapter is supported
-       if(_ssVmAllocators.size() > 0)
-               return _ssVmAllocators.get(0);
+        if(_ssVmAllocators.size() > 0) {
+            return _ssVmAllocators.get(0);
+        }
 
         return null;
     }
@@ -666,8 +668,9 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
             if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
                 try {
                     secStorageVm = startNew(dataCenterId, role);
-                    for (UploadVO upload :_uploadDao.listAll())
+                    for (UploadVO upload :_uploadDao.listAll()) {
                         _uploadDao.expunge(upload.getId());
+                    }
                 } finally {
                     _allocLock.unlock();
                 }
@@ -725,7 +728,9 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
         if (zoneHostInfo != null && (zoneHostInfo.getFlags() & 
RunningHostInfoAgregator.ZoneHostInfo.ROUTING_HOST_MASK) != 0) {
             VMTemplateVO template = 
_templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
             if (template == null) {
-                s_logger.debug("No hypervisor host added  in zone " + 
dataCenterId + ", wait until it is ready to launch secondary storage vm");
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("System vm template is not ready at data 
center " + dataCenterId + ", wait until it is ready to launch secondary storage 
vm");
+                }
                 return false;
             }
 
@@ -844,8 +849,8 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
                 throw new ConfigurationException(msg);
             }
         } else {
-               int ramSize = 
NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), 
DEFAULT_SS_VM_RAMSIZE);
-               int cpuFreq = 
NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ);
+            int ramSize = 
NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), 
DEFAULT_SS_VM_RAMSIZE);
+            int cpuFreq = 
NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ);
             _useLocalStorage = 
Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
             _serviceOffering = new ServiceOfferingVO("System Offering For 
Secondary Storage VM", 1, ramSize, cpuFreq, null, null, false, null, 
_useLocalStorage, true, null, true, VirtualMachine.Type.SecondaryStorageVm, 
true);
             
_serviceOffering.setUniqueName(ServiceOffering.ssvmDefaultOffUniqueName);
@@ -866,27 +871,27 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
 
         _httpProxy = configs.get(Config.SecStorageProxy.key());
         if (_httpProxy != null) {
-               boolean valid = true;
-               String errMsg = null;
-               try {
-                               URI uri = new URI(_httpProxy);
-                               if (!"http".equalsIgnoreCase(uri.getScheme())) {
-                                       errMsg = "Only support http proxy";
-                                       valid = false;
-                               } else if (uri.getHost() == null) {
-                                       errMsg = "host can not be null";
-                                       valid = false;
-                               } else if (uri.getPort() == -1) {
-                                       _httpProxy = _httpProxy + ":3128";
-                               }
-                       } catch (URISyntaxException e) {
-                               errMsg = e.toString();
-                       } finally {
-                               if (!valid) {
-                                       s_logger.debug("ssvm http proxy " + 
_httpProxy + " is invalid: " + errMsg);
-                                       throw new ConfigurationException("ssvm 
http proxy " + _httpProxy +  "is invalid: " + errMsg);
-                               }
-                       }
+            boolean valid = true;
+            String errMsg = null;
+            try {
+                URI uri = new URI(_httpProxy);
+                if (!"http".equalsIgnoreCase(uri.getScheme())) {
+                    errMsg = "Only support http proxy";
+                    valid = false;
+                } else if (uri.getHost() == null) {
+                    errMsg = "host can not be null";
+                    valid = false;
+                } else if (uri.getPort() == -1) {
+                    _httpProxy = _httpProxy + ":3128";
+                }
+            } catch (URISyntaxException e) {
+                errMsg = e.toString();
+            } finally {
+                if (!valid) {
+                    s_logger.debug("ssvm http proxy " + _httpProxy + " is 
invalid: " + errMsg);
+                    throw new ConfigurationException("ssvm http proxy " + 
_httpProxy +  "is invalid: " + errMsg);
+                }
+            }
         }
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Secondary storage vm Manager is configured.");
@@ -1037,7 +1042,7 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
     @Override
     public boolean 
finalizeVirtualMachineProfile(VirtualMachineProfile<SecondaryStorageVmVO> 
profile, DeployDestination dest, ReservationContext context) {
 
-       SecondaryStorageVmVO vm = profile.getVirtualMachine();
+        SecondaryStorageVmVO vm = profile.getVirtualMachine();
         Map<String, String> details = _vmDetailsDao.findDetails(vm.getId());
         vm.setDetails(details);
 
@@ -1073,7 +1078,7 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
         }
 
         if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) 
{
-               buf.append(" 
vmpassword=").append(_configDao.getValue("system.vm.password"));
+            buf.append(" 
vmpassword=").append(_configDao.getValue("system.vm.password"));
         }
 
         for (NicProfile nic : profile.getNics()) {
@@ -1099,9 +1104,9 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
             } else if (nic.getTrafficType() == TrafficType.Public) {
                 buf.append(" 
public.network.device=").append("eth").append(deviceId);
             } else if (nic.getTrafficType() == TrafficType.Storage) {
-               buf.append(" storageip=").append(nic.getIp4Address());
-               buf.append(" storagenetmask=").append(nic.getNetmask());
-               buf.append(" storagegateway=").append(nic.getGateway());
+                buf.append(" storageip=").append(nic.getIp4Address());
+                buf.append(" storagenetmask=").append(nic.getNetmask());
+                buf.append(" storagegateway=").append(nic.getGateway());
             }
         }
 
@@ -1303,24 +1308,24 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
     public void onScanEnd() {
     }
 
-       @Override
+    @Override
     public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] 
cmd) {
-               /* Called when Secondary Storage VM connected */
-               StartupCommand firstCmd = cmd[0];
-           if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
-               return null;
-           }
-
-               host.setType( com.cloud.host.Host.Type.SecondaryStorageVM);
-               return host;
+        /* Called when Secondary Storage VM connected */
+        StartupCommand firstCmd = cmd[0];
+        if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
+            return null;
+        }
+
+        host.setType( com.cloud.host.Host.Type.SecondaryStorageVM);
+        return host;
     }
 
-       @Override
+    @Override
     public HostVO createHostVOForDirectConnectAgent(HostVO host, 
StartupCommand[] startup, ServerResource resource, Map<String, String> details,
             List<String> hostTags) {
-               // Used to be Called when add secondary storage on UI through 
DummySecondaryStorageResource to update that host entry for Secondary Storage.
-           // Now since we move secondary storage from host table, this code 
is not needed to be invoked anymore.
-           /*
+        // Used to be Called when add secondary storage on UI through 
DummySecondaryStorageResource to update that host entry for Secondary Storage.
+        // Now since we move secondary storage from host table, this code is 
not needed to be invoked anymore.
+        /*
                StartupCommand firstCmd = startup[0];
                if (!(firstCmd instanceof StartupStorageCommand)) {
                        return null;
@@ -1360,30 +1365,30 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
                                host.setStorageUrl(ssCmd.getNfsShare());
                        }
                }
-        */
-               return null; // no need to handle this event anymore since 
secondary storage is not in host table anymore.
+         */
+        return null; // no need to handle this event anymore since secondary 
storage is not in host table anymore.
     }
 
-       @Override
+    @Override
     public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean 
isForceDeleteStorage) throws UnableDeleteHostException {
-           // Since secondary storage is moved out of host table, this class 
should not handle delete secondary storage anymore.
+        // Since secondary storage is moved out of host table, this class 
should not handle delete secondary storage anymore.
         return null;
     }
 
 
 
-       @Override
+    @Override
     public List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
-               SearchCriteriaService<HostVO, HostVO> sc = 
SearchCriteria2.create(HostVO.class);
+        SearchCriteriaService<HostVO, HostVO> sc = 
SearchCriteria2.create(HostVO.class);
         if (dcId != null) {
             sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId);
         }
-               sc.addAnd(sc.getEntity().getStatus(), Op.IN, 
com.cloud.host.Status.Up, com.cloud.host.Status.Connecting);
-               sc.addAnd(sc.getEntity().getType(), Op.EQ, 
Host.Type.SecondaryStorageVM);
-           return sc.list();
+        sc.addAnd(sc.getEntity().getStatus(), Op.IN, com.cloud.host.Status.Up, 
com.cloud.host.Status.Connecting);
+        sc.addAnd(sc.getEntity().getType(), Op.EQ, 
Host.Type.SecondaryStorageVM);
+        return sc.list();
     }
 
-       @Override
+    @Override
     public HostVO pickSsvmHost(HostVO ssHost) {
         if( ssHost.getType() == Host.Type.LocalSecondaryStorage ) {
             return  ssHost;
@@ -1416,8 +1421,8 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
         throw new UnsupportedOperationException("Unplug nic is not supported 
for vm of type " + vm.getType());
     }
 
-       @Override
-       public void prepareStop(VirtualMachineProfile<SecondaryStorageVmVO> 
profile) {
+    @Override
+    public void prepareStop(VirtualMachineProfile<SecondaryStorageVmVO> 
profile) {
 
-       }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9a9ef311/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git 
a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
 
b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index f2b40f2..30d0ff7 100755
--- 
a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ 
b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -1239,20 +1239,29 @@ public class NfsSecondaryStorageResource extends 
ServerResourceBase implements S
         DataStoreTO dstore = obj.getDataStore();
         if (dstore instanceof NfsTO) {
             NfsTO nfs = (NfsTO) dstore;
+            String parent = getRootDir(nfs.getUrl());
+            if (!parent.endsWith(File.separator)) {
+                parent += File.separator;
+            }
             String snapshotPath = obj.getPath();
             if (snapshotPath.startsWith(File.separator)) {
                 snapshotPath = snapshotPath.substring(1);
             }
+            // check if the passed snapshot path is a directory or not. For 
ImageCache, path is stored as a directory instead of
+            // snapshot file name. If so, since backupSnapshot process has 
already deleted snapshot in cache, so we just do nothing
+            // and return true.
+            String fullSnapPath = parent + snapshotPath;
+            File snapDir = new File(fullSnapPath);
+            if (snapDir.exists() && snapDir.isDirectory()) {
+                s_logger.debug("snapshot path " + snapshotPath + " is a 
directory, already deleted during backup snapshot, so no need to delete");
+                return new Answer(cmd, true, null);
+            }
+            // passed snapshot path is a snapshot file path, then get snapshot 
directory first
             int index = snapshotPath.lastIndexOf("/");
             String snapshotName = snapshotPath.substring(index + 1);
             snapshotPath = snapshotPath.substring(0, index);
-
-            String parent = getRootDir(nfs.getUrl());
-            if (!parent.endsWith(File.separator)) {
-                parent += File.separator;
-            }
             String absoluteSnapshotPath = parent + snapshotPath;
-            // check if directory exists
+            // check if snapshot directory exists
             File snapshotDir = new File(absoluteSnapshotPath);
             String details = null;
             if (!snapshotDir.exists()) {

Reply via email to