public void deleteResource() throws Exception {
Configuration pluginConfiguration = getResourceContext().getPluginConfiguration();
String fullFileName = pluginConfiguration.getSimple("deployment").getStringValue();
ESB5Component jbossASComponent = (ESB5Component) getResourceContext().getParentResourceComponent();
ProfileServiceConnection profileServiceConnection = jbossASComponent.getConnection();
DeploymentManager deployMgr = profileServiceConnection.getDeploymentManager();
String repositoryName = null;
String [] arr = deployMgr.getRepositoryNames(new String[] {fullFileName});
for (int i = 0; i<arr.length; i++) {
repositoryName = arr[i];
}
if (repositoryName != null) {
DeploymentProgress stop = null;
try {
stop = deployMgr.stop(repositoryName);
if (stop != null)
stop.run();
} catch (Throwable t) {
log.error("Could not find deployment to delete. " + t.getMessage());
return;
} finally {
jbossASComponent.disconnectFromProfileService();
}
DeploymentStatus stopStatus = stop.getDeploymentStatus();
if (stopStatus.isFailed()) {
if ((stopStatus.getFailure() != null) && (stopStatus.getFailure().getCause() != null)
&& (stopStatus.getFailure().getCause() instanceof java.lang.NullPointerException)) {
// jon 2.3 case
// If we get a NPE here, it means that the .esb deployment has already been deleted
// Return here because otherwise JON will not update and remove the deployment
log.error("Failed to stop deployment '" + repositoryName + "'.", stopStatus.getFailure());
jbossASComponent.disconnectFromProfileService();
return;
} else if ((stopStatus.getFailure().getCause() != null)
&& (stopStatus.getFailure().getCause() instanceof org.jboss.profileservice.spi.NoSuchDeploymentException)) {
// jon 2.4 case
// If we get a NPE here, it means that the .esb deployment has already been deleted
// Return here because otherwise JON will not update and remove the deployment
log.error("Failed to stop deployment '" + repositoryName + "'.", stopStatus.getFailure());
jbossASComponent.disconnectFromProfileService();
return;
}
log.error("Failed to stop deployment '" + repositoryName + "'.", stopStatus.getFailure());
throw new Exception("Failed to stop deployment '" + repositoryName + "' - cause: "
+ stopStatus.getFailure());
}
DeploymentProgress remove = deployMgr.remove(repositoryName);
if (remove != null) {
remove.run();
DeploymentStatus status = remove.getDeploymentStatus();
if (status.isFailed()) {
log.error("Failed to remove deployment '" + repositoryName + "'.", status.getFailure());
throw new Exception("Failed to remove deployment '" + repositoryName + ". "
+ "If the deployment has already been removed through other means and you want to "
+ "remove it from JON, uninventory it from the Resources section. Cause: "
+ status.getFailure());
}
} else {
throw new RuntimeException("Did not find Deployment " + fullFileName);
}
}
ManagementView mView = profileServiceConnection.getManagementView();
mView.load();
jbossASComponent.disconnectFromProfileService();
}