upgradeRequest.getTimestamp());
resourceManager.addResourceError(error);
return null;
}
ResourceUpgradeResponse ret = new ResourceUpgradeResponse();
ret.setResourceId(resource.getId());
if (upgradeRequest.hasSomethingToUpgrade()) {
String resourceKey = upgradeRequest.getNewResourceKey();
String name = upgradeRequest.getNewName();
String description = upgradeRequest.getNewDescription();
String version = upgradeRequest.getNewVersion();
boolean isUpgradeAll = allowGenericPropertiesUpgrade || upgradeRequest.isForceGenericPropertyUpgrade();
StringBuilder logMessage = new StringBuilder("Resource [").append(resource.toString()).append(
"] upgraded [");
if (needsUpgrade(resource.getResourceKey(), resourceKey)) {
resource.setResourceKey(resourceKey);
logMessage.append("resourceKey, ");
ret.setUpgradedResourceKey(resource.getResourceKey());
}
if (isUpgradeAll && needsUpgrade(resource.getName(), name)) {
resource.setName(name);
logMessage.append("name, ");
ret.setUpgradedResourceName(resource.getName());
}
if (isUpgradeAll && needsUpgrade(resource.getDescription(), description)) {
resource.setDescription(description);
logMessage.append("description, ");
ret.setUpgradedResourceDescription(resource.getDescription());
}
if (needsUpgrade(resource.getVersion(), version)) {
resource.setVersion(version);
logMessage.append("version, ");
ret.setUpgradedResourceVersion(resource.getVersion());
}
// If provided, assume the new plugin config should replace the old plugin config in its entirety.
// Use a deep copy without ids as the updgardeRequest config may contain entity config props.
// Note: we explicitly do not call configurationManager.updatePluginConfiguration() because the
// agent is already updated to the new configuration. Instead we call the dedicated local method
// supporting this use case.
Configuration pluginConfig = upgradeRequest.getNewPluginConfiguration();
if (null != pluginConfig) {
pluginConfig = pluginConfig.deepCopy(false);
PluginConfigurationUpdate update = configurationManager.upgradePluginConfiguration(
subjectManager.getOverlord(), resource.getId(), pluginConfig);
ret.setUpgradedResourcePluginConfiguration(update.getResource().getPluginConfiguration());
}
// finally let's remove the potential previous upgrade error. we've now successfully
// upgraded the resource.
List<ResourceError> upgradeErrors = resourceManager.findResourceErrors(subjectManager.getOverlord(),