}
ResourceUpgradeContext<ResourceComponent<T>> upgradeContext = inventoryManager.createResourceUpgradeContext(
resource, parentResourceContext, parentResourceComponent, discoveryComponent);
ResourceUpgradeRequest request = new ResourceUpgradeRequest(resource.getId());
request.setTimestamp(System.currentTimeMillis());
ResourceUpgradeReport upgradeReport = null;
try {
upgradeReport = inventoryManager.invokeDiscoveryComponentResourceUpgradeFacet(resource.getResourceType(),
discoveryComponent, upgradeContext, parentResourceContainer);
} catch (Throwable t) {
log.error("ResourceUpgradeFacet threw an exception while upgrading resource [" + resource + "]", t);
request.setErrorProperties(t);
} finally {
if (isResConfigCompacted) {
resource.setResourceConfiguration(null);
}
}
if (upgradeReport != null && upgradeReport.hasSomethingToUpgrade()) {
request.fillInFromReport(upgradeReport);
}
if (request.hasSomethingToUpgrade()) {
requests.add(request);
}
if (request.getUpgradeErrorMessage() != null) {
rememberFailure(resource);
return false;
}
//alright, everything went fine with the upgrade. Let's update the data of the resource
//right now so that it starts up as if it was already upgraded. This is to ensure that
//its children will use a parent component that behaves like the upgraded one.
//We are going to roll back the upgraded data if the upgrade fails to sync with the server
//later on.
//remember the original values
ResourceUpgradeRequest original = new ResourceUpgradeRequest(resource.getId());
original.fillInFromResource(resource);
originalResourceData.add(original);
//update the resource
request.updateResource(resource);