mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +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 java.util.List; | ||||||
| 
 | 
 | ||||||
|  | import com.cloud.storage.Snapshot; | ||||||
| import com.cloud.storage.SnapshotVO; | import com.cloud.storage.SnapshotVO; | ||||||
| import com.cloud.utils.db.Filter; | import com.cloud.utils.db.Filter; | ||||||
| import com.cloud.utils.db.GenericDao; | import com.cloud.utils.db.GenericDao; | ||||||
| @ -29,5 +30,6 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long> { | |||||||
| 	List<SnapshotVO> listByVolumeId(Filter filter, long volumeId); | 	List<SnapshotVO> listByVolumeId(Filter filter, long volumeId); | ||||||
| 	SnapshotVO findNextSnapshot(long parentSnapId); | 	SnapshotVO findNextSnapshot(long parentSnapId); | ||||||
| 	long getLastSnapshot(long volumeId, long snapId); | 	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 javax.ejb.Local; | ||||||
| 
 | 
 | ||||||
|  | import com.cloud.storage.Snapshot; | ||||||
| import com.cloud.storage.SnapshotVO; | import com.cloud.storage.SnapshotVO; | ||||||
| import com.cloud.utils.db.Filter; | import com.cloud.utils.db.Filter; | ||||||
| import com.cloud.utils.db.GenericDaoBase; | 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 { | public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements SnapshotDao { | ||||||
|      |      | ||||||
|     private final SearchBuilder<SnapshotVO> VolumeIdSearch; |     private final SearchBuilder<SnapshotVO> VolumeIdSearch; | ||||||
|  |     private final SearchBuilder<SnapshotVO> VolumeIdTypeSearch; | ||||||
|     private final SearchBuilder<SnapshotVO> ParentIdSearch; |     private final SearchBuilder<SnapshotVO> ParentIdSearch; | ||||||
|     private final GenericSearchBuilder<SnapshotVO, Long> lastSnapSearch; |     private final GenericSearchBuilder<SnapshotVO, Long> lastSnapSearch; | ||||||
|      |      | ||||||
| @ -43,6 +45,12 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements | |||||||
|         return findOneIncludingRemovedBy(sc); |         return findOneIncludingRemovedBy(sc); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     @Override | ||||||
|  |     public List<SnapshotVO> listByVolumeIdType(long volumeId, String type ) { | ||||||
|  |         return listByVolumeIdType(null, volumeId, type); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public List<SnapshotVO> listByVolumeId(long volumeId) { |     public List<SnapshotVO> listByVolumeId(long volumeId) { | ||||||
|         return listByVolumeId(null, volumeId); |         return listByVolumeId(null, volumeId); | ||||||
| @ -55,11 +63,24 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements | |||||||
|         return listBy(sc, filter); |         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() { |     protected SnapshotDaoImpl() { | ||||||
|         VolumeIdSearch = createSearchBuilder(); |         VolumeIdSearch = createSearchBuilder(); | ||||||
|         VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); |         VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); | ||||||
|         VolumeIdSearch.done(); |         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 = createSearchBuilder(); | ||||||
|         ParentIdSearch.and("prevSnapshotId", ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ); |         ParentIdSearch.and("prevSnapshotId", ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ); | ||||||
|         ParentIdSearch.done(); |         ParentIdSearch.done(); | ||||||
|  | |||||||
| @ -6875,7 +6875,7 @@ public class ManagementServerImpl implements ManagementServer { | |||||||
|     public long deleteSnapshotAsync(long userId, long snapshotId) { |     public long deleteSnapshotAsync(long userId, long snapshotId) { | ||||||
|     	Snapshot snapshot = findSnapshotById(snapshotId); |     	Snapshot snapshot = findSnapshotById(snapshotId); | ||||||
|         long volumeId = snapshot.getVolumeId(); |         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. |         // 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. |         // 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) { |     private void postCreateRecurringSnapshotForPolicy(long userId, long volumeId, long snapshotId, long policyId) { | ||||||
|         //Use count query |         //Use count query | ||||||
|     	Filter searchFilter = new Filter(SnapshotVO.class, GenericDaoBase.CREATED_COLUMN, true, null, null); |         List<SnapshotVO> snaps = listSnapsforVolumeType(volumeId, SnapshotType.RECURRING.name()); | ||||||
|         List<SnapshotVO> snaps = listSnapsforPolicy(policyId, searchFilter); |  | ||||||
|         SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId); |         SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId); | ||||||
|          |          | ||||||
|         while(snaps.size() > policy.getMaxSnaps() && snaps.size() > 1) { |         while(snaps.size() > policy.getMaxSnaps() && snaps.size() > 1) { | ||||||
| @ -640,9 +639,8 @@ public class SnapshotManagerImpl implements SnapshotManager { | |||||||
|         while( lastSnapshot.getRemoved() != null ) { |         while( lastSnapshot.getRemoved() != null ) { | ||||||
|             String BackupSnapshotId = lastSnapshot.getBackupSnapshotId(); |             String BackupSnapshotId = lastSnapshot.getBackupSnapshotId(); | ||||||
|             if( BackupSnapshotId != null ) { |             if( BackupSnapshotId != null ) { | ||||||
|                 if( destroySnapshotBackUp(userId, snapshotId, policyId) ) { |                 if( destroySnapshotBackUp(userId, lastId, policyId) ) { | ||||||
|                     lastSnapshot.setBackupSnapshotId(null); | 
 | ||||||
|                     _snapshotDao.update(lastId, lastSnapshot); |  | ||||||
|                 } else { |                 } else { | ||||||
|                     s_logger.debug("Destroying snapshot backup failed " + lastSnapshot); |                     s_logger.debug("Destroying snapshot backup failed " + lastSnapshot); | ||||||
|                     break; |                     break; | ||||||
| @ -650,6 +648,9 @@ public class SnapshotManagerImpl implements SnapshotManager { | |||||||
|             } |             } | ||||||
|             postDeleteSnapshot(userId, lastId, policyId); |             postDeleteSnapshot(userId, lastId, policyId); | ||||||
|             lastId = lastSnapshot.getPrevSnapshotId(); |             lastId = lastSnapshot.getPrevSnapshotId(); | ||||||
|  |             if( lastId == 0 ) { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|             lastSnapshot = _snapshotDao.findById(lastId); |             lastSnapshot = _snapshotDao.findById(lastId); | ||||||
|         } |         } | ||||||
|         return true; |         return true; | ||||||
| @ -699,8 +700,9 @@ public class SnapshotManagerImpl implements SnapshotManager { | |||||||
|                 _pauseInterval, _shouldBeSnapshotCapable, volume.getInstanceId()); |                 _pauseInterval, _shouldBeSnapshotCapable, volume.getInstanceId()); | ||||||
| 
 | 
 | ||||||
|         if ((answer != null) && answer.getResult()) { |         if ((answer != null) && answer.getResult()) { | ||||||
|  |             snapshot.setBackupSnapshotId(null); | ||||||
|  |             _snapshotDao.update(snapshotId, snapshot); | ||||||
|             // This is not the last snapshot. |             // This is not the last snapshot. | ||||||
|             postDeleteSnapshot(userId, snapshotId, policyId); |  | ||||||
|             success = true; |             success = true; | ||||||
|             details = "Successfully deleted snapshot " + snapshotId + " for volumeId: " + volumeId + " and policyId " |             details = "Successfully deleted snapshot " + snapshotId + " for volumeId: " + volumeId + " and policyId " | ||||||
|                     + policyId; |                     + policyId; | ||||||
| @ -934,6 +936,10 @@ public class SnapshotManagerImpl implements SnapshotManager { | |||||||
|         return _snapshotDao.listByVolumeId(volumeId); |         return _snapshotDao.listByVolumeId(volumeId); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     public List<SnapshotVO> listSnapsforVolumeType(long volumeId, String type) { | ||||||
|  |         return _snapshotDao.listByVolumeIdType(volumeId, type); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
| 	public void deletePoliciesForVolume(Long volumeId) { | 	public void deletePoliciesForVolume(Long volumeId) { | ||||||
|     	List<SnapshotPolicyVO> policyInstances = listPoliciesforVolume(volumeId); |     	List<SnapshotPolicyVO> policyInstances = listPoliciesforVolume(volumeId); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user