CLOUDSTACK-8413: Fixed resource tags on disk are lost when migrate to another storage

During cold volume migration we are duplicating volume entry in volumes table.
When migration is complete, we update the uuid of new entry and expunge the older entry.
This results in removal of resource tags on volume as its resource id still pointing to older volume.
As part of fix while updating uuid for volume, we are updating resource_id for tags also.

This closes #194
This commit is contained in:
Anshul Gangwar 2015-02-19 16:22:20 +05:30 committed by Rajesh Battala
parent 4b2ce34bc9
commit 2133c302f4
5 changed files with 18 additions and 0 deletions

View File

@ -92,6 +92,8 @@ public interface ResourceTag extends ControlledEntity, Identity, InternalIdentit
*/
long getResourceId();
void setResourceId(long resourceId);
/**
* @return
*/

View File

@ -626,6 +626,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
destVol.setInstanceId(instanceId);
update(srcVolId, srcVol);
update(destVolId, destVol);
_tagsDao.updateResourceId(srcVolId, destVolId, ResourceObjectType.Volume);
} catch (Exception e) {
throw new CloudRuntimeException("Unable to persist the sequence number for this host");
}

View File

@ -143,6 +143,10 @@ public class ResourceTagVO implements ResourceTag {
return resourceId;
}
@Override public void setResourceId(long resourceId) {
this.resourceId = resourceId;
}
@Override
public ResourceObjectType getResourceType() {
return resourceType;

View File

@ -34,4 +34,5 @@ public interface ResourceTagDao extends GenericDao<ResourceTagVO, Long> {
List<? extends ResourceTag> listBy(long resourceId, ResourceObjectType resourceType);
void updateResourceId(long srcId, long destId, ResourceObjectType resourceType);
}

View File

@ -59,4 +59,14 @@ public class ResourceTagsDaoImpl extends GenericDaoBase<ResourceTagVO, Long> imp
sc.setParameters("resourceType", resourceType);
return listBy(sc);
}
@Override public void updateResourceId(long srcId, long destId, ResourceObjectType resourceType) {
SearchCriteria<ResourceTagVO> sc = AllFieldsSearch.create();
sc.setParameters("resourceId", srcId);
sc.setParameters("resourceType", resourceType);
for( ResourceTagVO tag : listBy(sc)) {
tag.setResourceId(destId);
update(tag.getId(), tag);
}
}
}