try {
ResourceType rt = getResourceType(rtName);
if (null != rt) {
Subject overlord = getOverlord();
ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
// delete any resources first
ResourceCriteria c = new ResourceCriteria();
c.setStrict(true);
c.addFilterResourceTypeId(rt.getId());
c.addFilterInventoryStatus(InventoryStatus.NEW);
List<Resource> doomedResources = resourceManager.findResourcesByCriteria(overlord, c);
c.addFilterInventoryStatus(InventoryStatus.DELETED);
doomedResources.addAll(resourceManager.findResourcesByCriteria(overlord, c));
c.addFilterInventoryStatus(InventoryStatus.UNINVENTORIED);
doomedResources.addAll(resourceManager.findResourcesByCriteria(overlord, c));
// invoke bulk delete on the resource to remove any dependencies not defined in the hibernate entity model
// perform in-band and out-of-band work in quick succession
for (Resource doomed : doomedResources) {
List<Integer> deletedIds = resourceManager.uninventoryResource(overlord, doomed.getId());
for (Integer deletedResourceId : deletedIds) {
resourceManager.uninventoryResourceAsyncWork(overlord, deletedResourceId);
}
}
// Measurement defs go away via cascade remove