return null;
}
@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);
File absoluteDestDir = getAbsoluteDestinationDir(request.getLiveBundleResourceDeployment());
if (absoluteDestDir != null) {
purgeRequest.setDestinationTarget(absoluteDestDir.toURI());
} else {
String connectionString = getConnectionString(request.getLiveBundleResourceDeployment());
if (connectionString != null) {
purgeRequest.setDestinationTarget(URI.create(connectionString));
}
purgeRequest.setReferencedConfiguration(
createReferencedConfigurationFromResource(request.getLiveBundleResourceDeployment()));
}
// get the bundle facet object that will process the bundle and call it to start the purge
int facetMethodTimeout =
30 * 60 * 1000; // 30 minutes should be enough time for the bundle plugin to purge everything
BundleFacet bundlePluginComponent = getBundleFacet(bundleHandlerResourceId, facetMethodTimeout);
BundlePurgeResult result = bundlePluginComponent.purgeBundle(purgeRequest);
if (result.isSuccess()) {
auditDeployment(resourceDeployment, AUDIT_PURGE_ENDED, bundleDeployment.getName(), deploymentMessage);
} else {
response.setErrorMessage(result.getErrorMessage());
auditDeployment(resourceDeployment, AUDIT_PURGE_ENDED, bundleDeployment.getName(), null,
Status.FAILURE, "Failed: " + deploymentMessage, result.getErrorMessage());
}
} catch (Throwable t) {
LOG.error("Failed to purge bundle: " + request, t);
response.setErrorMessage(t);
}
return response;
}