mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	bug 6365: find policy from volumeId instead of snapshotID
status 6365: resolved fixed
This commit is contained in:
		
							parent
							
								
									7374f85a18
								
							
						
					
					
						commit
						5b75f8e03b
					
				@ -20,6 +20,7 @@ package com.cloud.storage.dao;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import com.cloud.storage.Snapshot;
 | 
			
		||||
import com.cloud.storage.SnapshotVO;
 | 
			
		||||
import com.cloud.utils.db.Filter;
 | 
			
		||||
import com.cloud.utils.db.GenericDao;
 | 
			
		||||
@ -29,5 +30,6 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long> {
 | 
			
		||||
	List<SnapshotVO> listByVolumeId(Filter filter, long volumeId);
 | 
			
		||||
	SnapshotVO findNextSnapshot(long parentSnapId);
 | 
			
		||||
	long getLastSnapshot(long volumeId, long snapId);
 | 
			
		||||
    List<SnapshotVO> listByVolumeIdType(long volumeId, String type);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,7 @@ import java.util.List;
 | 
			
		||||
 | 
			
		||||
import javax.ejb.Local;
 | 
			
		||||
 | 
			
		||||
import com.cloud.storage.Snapshot;
 | 
			
		||||
import com.cloud.storage.SnapshotVO;
 | 
			
		||||
import com.cloud.utils.db.Filter;
 | 
			
		||||
import com.cloud.utils.db.GenericDaoBase;
 | 
			
		||||
@ -33,6 +34,7 @@ import com.cloud.utils.db.SearchCriteria;
 | 
			
		||||
public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements SnapshotDao {
 | 
			
		||||
    
 | 
			
		||||
    private final SearchBuilder<SnapshotVO> VolumeIdSearch;
 | 
			
		||||
    private final SearchBuilder<SnapshotVO> VolumeIdTypeSearch;
 | 
			
		||||
    private final SearchBuilder<SnapshotVO> ParentIdSearch;
 | 
			
		||||
    private final GenericSearchBuilder<SnapshotVO, Long> lastSnapSearch;
 | 
			
		||||
    
 | 
			
		||||
@ -43,6 +45,12 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
 | 
			
		||||
        return findOneIncludingRemovedBy(sc);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<SnapshotVO> listByVolumeIdType(long volumeId, String type ) {
 | 
			
		||||
        return listByVolumeIdType(null, volumeId, type);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<SnapshotVO> listByVolumeId(long volumeId) {
 | 
			
		||||
        return listByVolumeId(null, volumeId);
 | 
			
		||||
@ -55,11 +63,24 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
 | 
			
		||||
        return listBy(sc, filter);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    public List<SnapshotVO> listByVolumeIdType(Filter filter, long volumeId, String type ) {
 | 
			
		||||
        SearchCriteria<SnapshotVO> sc = VolumeIdTypeSearch.create();
 | 
			
		||||
        sc.setParameters("volumeId", volumeId);
 | 
			
		||||
        sc.setParameters("type", type);
 | 
			
		||||
        return listBy(sc, filter);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected SnapshotDaoImpl() {
 | 
			
		||||
        VolumeIdSearch = createSearchBuilder();
 | 
			
		||||
        VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
 | 
			
		||||
        VolumeIdSearch.done();
 | 
			
		||||
        
 | 
			
		||||
        VolumeIdTypeSearch = createSearchBuilder();
 | 
			
		||||
        VolumeIdTypeSearch.and("volumeId", VolumeIdTypeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
 | 
			
		||||
        VolumeIdTypeSearch.and("type", VolumeIdTypeSearch.entity().getTypeDescription(), SearchCriteria.Op.EQ);
 | 
			
		||||
        VolumeIdTypeSearch.done();
 | 
			
		||||
        
 | 
			
		||||
        ParentIdSearch = createSearchBuilder();
 | 
			
		||||
        ParentIdSearch.and("prevSnapshotId", ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ);
 | 
			
		||||
        ParentIdSearch.done();
 | 
			
		||||
 | 
			
		||||
@ -6875,7 +6875,7 @@ public class ManagementServerImpl implements ManagementServer {
 | 
			
		||||
    public long deleteSnapshotAsync(long userId, long snapshotId) {
 | 
			
		||||
    	Snapshot snapshot = findSnapshotById(snapshotId);
 | 
			
		||||
        long volumeId = snapshot.getVolumeId();
 | 
			
		||||
        List<SnapshotPolicyVO> policies = _snapMgr.listPoliciesforSnapshot(snapshotId);
 | 
			
		||||
        List<SnapshotPolicyVO> policies = _snapMgr.listPoliciesforVolume(volumeId);
 | 
			
		||||
        
 | 
			
		||||
        // Return the job id of the last destroySnapshotAsync job which actually destroys the snapshot.
 | 
			
		||||
        // The rest of the async jobs just update the db and don't really do any meaningful thing.
 | 
			
		||||
 | 
			
		||||
@ -606,8 +606,7 @@ public class SnapshotManagerImpl implements SnapshotManager {
 | 
			
		||||
    
 | 
			
		||||
    private void postCreateRecurringSnapshotForPolicy(long userId, long volumeId, long snapshotId, long policyId) {
 | 
			
		||||
        //Use count query
 | 
			
		||||
    	Filter searchFilter = new Filter(SnapshotVO.class, GenericDaoBase.CREATED_COLUMN, true, null, null);
 | 
			
		||||
        List<SnapshotVO> snaps = listSnapsforPolicy(policyId, searchFilter);
 | 
			
		||||
        List<SnapshotVO> snaps = listSnapsforVolumeType(volumeId, SnapshotType.RECURRING.name());
 | 
			
		||||
        SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId);
 | 
			
		||||
        
 | 
			
		||||
        while(snaps.size() > policy.getMaxSnaps() && snaps.size() > 1) {
 | 
			
		||||
@ -640,9 +639,8 @@ public class SnapshotManagerImpl implements SnapshotManager {
 | 
			
		||||
        while( lastSnapshot.getRemoved() != null ) {
 | 
			
		||||
            String BackupSnapshotId = lastSnapshot.getBackupSnapshotId();
 | 
			
		||||
            if( BackupSnapshotId != null ) {
 | 
			
		||||
                if( destroySnapshotBackUp(userId, snapshotId, policyId) ) {
 | 
			
		||||
                    lastSnapshot.setBackupSnapshotId(null);
 | 
			
		||||
                    _snapshotDao.update(lastId, lastSnapshot);
 | 
			
		||||
                if( destroySnapshotBackUp(userId, lastId, policyId) ) {
 | 
			
		||||
 | 
			
		||||
                } else {
 | 
			
		||||
                    s_logger.debug("Destroying snapshot backup failed " + lastSnapshot);
 | 
			
		||||
                    break;
 | 
			
		||||
@ -650,6 +648,9 @@ public class SnapshotManagerImpl implements SnapshotManager {
 | 
			
		||||
            }
 | 
			
		||||
            postDeleteSnapshot(userId, lastId, policyId);
 | 
			
		||||
            lastId = lastSnapshot.getPrevSnapshotId();
 | 
			
		||||
            if( lastId == 0 ) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            lastSnapshot = _snapshotDao.findById(lastId);
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
@ -699,8 +700,9 @@ public class SnapshotManagerImpl implements SnapshotManager {
 | 
			
		||||
                _pauseInterval, _shouldBeSnapshotCapable, volume.getInstanceId());
 | 
			
		||||
 | 
			
		||||
        if ((answer != null) && answer.getResult()) {
 | 
			
		||||
            snapshot.setBackupSnapshotId(null);
 | 
			
		||||
            _snapshotDao.update(snapshotId, snapshot);
 | 
			
		||||
            // This is not the last snapshot.
 | 
			
		||||
            postDeleteSnapshot(userId, snapshotId, policyId);
 | 
			
		||||
            success = true;
 | 
			
		||||
            details = "Successfully deleted snapshot " + snapshotId + " for volumeId: " + volumeId + " and policyId "
 | 
			
		||||
                    + policyId;
 | 
			
		||||
@ -934,6 +936,10 @@ public class SnapshotManagerImpl implements SnapshotManager {
 | 
			
		||||
        return _snapshotDao.listByVolumeId(volumeId);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public List<SnapshotVO> listSnapsforVolumeType(long volumeId, String type) {
 | 
			
		||||
        return _snapshotDao.listByVolumeIdType(volumeId, type);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
	public void deletePoliciesForVolume(Long volumeId) {
 | 
			
		||||
    	List<SnapshotPolicyVO> policyInstances = listPoliciesforVolume(volumeId);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user