@Override
public BundlePurgeResponse purge(BundlePurgeRequest request) {
final BundlePurgeResponse response = new BundlePurgeResponse();
try {
final BundleResourceDeployment resourceDeployment = request.getLiveBundleResourceDeployment();
final BundleDeployment bundleDeployment = resourceDeployment.getBundleDeployment();
// find the resource that will purge the bundle
BundleType bundleType = bundleDeployment.getBundleVersion().getBundle().getBundleType();
ResourceType resourceType = bundleType.getResourceType();
Set<Resource> resources = inventoryManager.getResourcesWithType(resourceType);
if (resources.isEmpty()) {
throw new Exception("No bundle plugin supports bundle type [" + bundleType + "]");
}
final int bundleHandlerResourceId = resources.iterator().next().getId();
final ResourceContainer resourceContainer = inventoryManager.getResourceContainer(bundleHandlerResourceId);
if (null == resourceContainer.getResourceContext()) {
throw new Exception("No bundle plugin resource available to handle purge for bundle type ["
+ bundleType
+ "]. Ensure the bundle plugin is deployed and its resource is imported into inventory.");
}
// purge the bundle utilizing the bundle facet object
String deploymentMessage = "Deployment [" + bundleDeployment + "] to be purged via ["
+ resourceDeployment.getResource() + "]";
auditDeployment(resourceDeployment, AUDIT_PURGE_STARTED, bundleDeployment.getName(), deploymentMessage);
org.rhq.core.pluginapi.bundle.BundlePurgeRequest purgeRequest = new org.rhq.core.pluginapi.bundle.BundlePurgeRequest();
purgeRequest.setBundleManagerProvider(this);
purgeRequest.setLiveResourceDeployment(resourceDeployment);