List of usage examples for java.lang IllegalStateException fillInStackTrace
public synchronized Throwable fillInStackTrace()
From source file:org.rhq.core.pc.upgrade.ResourceUpgradeDelegate.java
public void sendRequests() throws Throwable { if (enabled && requests.size() > 0) { try {/* w w w. j a va 2s .c om*/ //check the validity of the upgrades now that we have a complete picture //about the changes and the inventory looks like it was already upgraded. for (ResourceUpgradeRequest request : requests) { ResourceContainer container = inventoryManager.getResourceContainer(request.getResourceId()); if (container != null) { Resource resource = container.getResource(); String upgradeErrors = null; if ((upgradeErrors = checkUpgradeValid(resource, request)) != null) { //the resource is in its upgraded state but it's going to get reverted back to the original state //in the code below. Let's use the original resource for the error message so that we don't confuse //the user. ResourceUpgradeRequest orig = findOriginal(request); //orig should never be null, but let's be paranoid if (orig != null) { orig.updateResource(resource); } String errorString = "Upgrading the resource [" + resource + "] using these updates [" + request + "] would render the inventory invalid because of the following reasons: " + upgradeErrors; //now switch the resource back to the upgraded state for the rest of the code below again request.updateResource(resource); log.error(errorString); IllegalStateException ex = new IllegalStateException(errorString); ex.fillInStackTrace(); //set the error and clear out everything else, so that we send the error //to the server and locally roll back to the previous state. request.setErrorProperties(ex); request.clearUpgradeData(); if (request.getUpgradeErrorMessage() != null) { rememberFailure(resource); inventoryManager.deactivateResource(resource); } } } } //now before we talk to server and sync up the upgraded data, //reset the resources to their original values so that any changes //the server makes to the upgrade data are applied to the "vanilla" state //of the resources. i.e we only want to make changes the server approves. for (ResourceUpgradeRequest request : originalResourceData) { ResourceContainer container = inventoryManager.getResourceContainer(request.getResourceId()); if (container != null) { Resource resource = container.getResource(); request.updateResource(resource); } } //merge the resources with the data as received from the server //(this can differ from what the upgrade "wants" because the server is //free to disallow some changes, e.g. resource name change) inventoryManager.mergeResourcesFromUpgrade(requests); //and now restart all the "touched" resources with the true intended //data for (ResourceUpgradeRequest request : requests) { ResourceContainer container = inventoryManager.getResourceContainer(request.getResourceId()); if (container != null) { Resource resource = container.getResource(); try { inventoryManager.activateResource(resource, container, true); } catch (InvalidPluginConfigurationException e) { log.debug("Resource [" + resource + "] failed to start up after upgrade.", e); inventoryManager.handleInvalidPluginConfigurationResourceError(resource, e); } catch (Throwable t) { log.error("Failed to activate the resource [" + resource + "] after upgrade.", t); inventoryManager.handleInvalidPluginConfigurationResourceError(resource, t); } } } } catch (Throwable t) { mergeFailed = true; //deactivate all the resources to be upgraded. We might have a problem //because they have not been upgraded because the merge failed. for (ResourceUpgradeRequest request : requests) { ResourceContainer container = inventoryManager.getResourceContainer(request.getResourceId()); if (container != null) { inventoryManager.deactivateResource(container.getResource()); } } throw t; } } }