+ (vhosts.size() + 1) + ". The upgrade will continue using the resource key matching.");
} else {
//k, this seems to be a correct value
//the SNMP indices are in the reverse order of the definitions in the config files
//+1, where the main server is always on index 1.
VHostSpec vhost = vhosts.get(vhosts.size() - snmpServiceIndex + 1);
//right, let's do a cross-check before we actually create the resource key so
//that we catch user-generated errors.
Set<String> legacyResourceKeys =
legacyResourceKeyUtil.getLegacyVirtualHostResourceKeys(vhost);
if (legacyResourceKeys.contains(resourceKey)) {
newResourceKey = createResourceKey(vhost.serverName, vhost.hosts);
} else {
log.debug("The cross-check of the SNMP WWW Service Index value and resource key failed for virtual host with old resource key: "
+ resourceKey + ". The upgrade will continue using resource key matching.");
}
}
}
} else {
log.warn("The " + LEGACY_SNMP_SERVICE_INDEX_CONFIG_PROP
+ " property should be a positive integer greater than zero but is " + snmpServiceIndex
+ " instead. The upgrade will continue using the resource key matching.");
}
}
}
if (newResourceKey != null) {
ResourceUpgradeReport report = new ResourceUpgradeReport();
report.setNewResourceKey(newResourceKey);
return report;
}
Map<String, Set<VHostSpec>> possibleMatchesPerRK = new HashMap<String, Set<VHostSpec>>();
for (VHostSpec vhost : vhosts) {
Set<String> legacyResourceKeys = legacyResourceKeyUtil.getLegacyVirtualHostResourceKeys(vhost);
for (String legacyRK : legacyResourceKeys) {
addPossibleRKMatch(legacyRK, vhost, possibleMatchesPerRK);
}
}
for (String legacyRK : legacyResourceKeyUtil.getLegacyMainServerResourceKeys()) {
addPossibleRKMatch(legacyRK, null, possibleMatchesPerRK);
}
Set<VHostSpec> matchingVhosts = possibleMatchesPerRK.get(resourceKey);
if (matchingVhosts == null || matchingVhosts.isEmpty()) {
throw new IllegalArgumentException(
"Failed to identify the vhost resource with the old-style resource key '"
+ resourceKey
+ "' with any of the vhosts in the apache configuration files. This means that the vhost resource is stale and you can safely uninventory it.");
} else if (matchingVhosts.size() > 1) {
String message =
"Failed to uniquely identify the vhost from the old-style resource key. The old resource key is '"
+ resourceKey
+ "' which could be matched with any of the following possible new-style resource keys: "
+ matchingVhosts
+ ". The plugin does not have enough information to successfully upgrade this resource."
+ " Please take note of any alert definitions or operation schedules that you have defined for this resource and manually uninventory it.";
throw new IllegalArgumentException(message);
} else {
VHostSpec vhost = matchingVhosts.iterator().next();
if (vhost == null) {
newResourceKey = ApacheVirtualHostServiceComponent.MAIN_SERVER_RESOURCE_KEY;
} else {
newResourceKey = createResourceKey(vhost.serverName, vhost.hosts);
}