Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Bug 1200579 - Unable to delete/remove agent plug-ins that define a bu…
Browse files Browse the repository at this point in the history
…ndle

type target

When removing a resouceType make sure we also remove associated bundleTypes
(which may include Bundles of that type)

(cherry picked from commit a98a734)
  • Loading branch information
Libor Zoubek authored and Michael Burman committed Apr 2, 2015
1 parent aa78e35 commit f613f22
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2014 Red Hat, Inc.
* Copyright (C) 2005-2015 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -2763,4 +2763,27 @@ private Map<BundleGroup, Boolean> populateBundleGroupMap(List<BundleGroup> bundl
}
return result;
}

@Override
public void deleteMetadata(Subject subject, ResourceType resourceType) throws Exception {

// disconnect from explicitly targeting bundle types
for (BundleType bundleType : resourceType.getExplicitlyTargetingBundleTypes()) {
bundleType.getExplicitlyTargetedResourceTypes().remove(resourceType);
entityManager.merge(bundleType);
}
resourceType.getExplicitlyTargetingBundleTypes().clear();

// if our resourceType has associated bundleType, sadly we have to delete all bundles of that type
if (resourceType.getBundleType() != null) {
BundleType toRemove = resourceType.getBundleType();
BundleCriteria criteria = new BundleCriteria();
criteria.addFilterBundleTypeId(toRemove.getId());
for (Bundle bundle : bundleManager.findBundlesByCriteria(subject, criteria)) {
deleteBundle(subject, bundle.getId());
}
entityManager.remove(toRemove);
}

}
}
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2014 Red Hat, Inc.
* Copyright (C) 2005-2015 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -38,6 +38,7 @@
import org.rhq.core.domain.bundle.composite.BundleGroupAssignmentComposite;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.resource.ResourceType;

/**
* Local interface to the manager responsible for creating and managing bundles.
Expand Down Expand Up @@ -393,4 +394,12 @@ BundleGroupAssignmentComposite getAssignableBundleGroups(Subject subject, Subjec
BundleDeployment scheduleBundleDeploymentInNewTransaction(Subject subject, int bundleDeploymentId,
boolean isCleanDeployment, boolean isRevert, Integer revertedDeploymentReplacedDeployment) throws Exception;

/**
* Deletes all Bundles, Bundle types connected to given resource type
* @param subject
* @param resourceType
* @throws Exception
*/
void deleteMetadata(Subject subject, ResourceType resourceType) throws Exception;

}
Expand Up @@ -58,6 +58,7 @@
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.authz.RequiredPermission;
import org.rhq.enterprise.server.bundle.BundleManagerLocal;
import org.rhq.enterprise.server.inventory.InventoryManagerLocal;
import org.rhq.enterprise.server.resource.ResourceManagerLocal;
import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal;
Expand Down Expand Up @@ -124,6 +125,9 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
@EJB
private PluginConfigurationMetadataManagerLocal pluginConfigMetadataMgr;

@EJB
private BundleManagerLocal bundleMgr;

@TransactionAttribute(TransactionAttributeType.NEVER)
public void updateTypes(Set<ResourceType> resourceTypes) throws Exception {
// Only process the type if it is a non-runs-inside type (i.e. not a child of some other type X at this same
Expand Down Expand Up @@ -256,6 +260,15 @@ public void completeRemoveResourceType(Subject subject, ResourceType existingTyp
entityManager.flush();
existingType = entityManager.find(existingType.getClass(), existingType.getId());

try {
bundleMgr.deleteMetadata(subject, existingType);
} catch (Exception e) {
throw new RuntimeException("Bundle metadata deletion failed. Cannot finish deleting " + existingType, e);
}

entityManager.flush();
existingType = entityManager.find(existingType.getClass(), existingType.getId());

try {
alertMetadataMgr.deleteAlertTemplates(subject, existingType);
} catch (Exception e) {
Expand Down

0 comments on commit f613f22

Please sign in to comment.