Github user iyovcheva commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/264#discussion_r71283685
--- Diff:
core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/transformer/impl/DeleteOrphanedLocationsTransformer.java
---
@@ -94,6 +126,86 @@ public boolean containsAny(Collection<?> container,
Iterable<?> contenders) {
}
return result;
}
+
+ public Map<String, String> findLocationsToKeep(BrooklynMementoRawData
input) {
+ Map<String, String> locationsToKeep = MutableMap.of();
+ Set<String> allReferencedLocations =
findAllReferencedLocations(input);
+
+ for (Map.Entry location: input.getLocations().entrySet()) {
+ if (allReferencedLocations.contains(location.getKey())) {
+ locationsToKeep.put((String) location.getKey(), (String)
location.getValue());
+ }
+ }
+ return locationsToKeep;
+ }
+
+ public Set<String> findAllReferencedLocations(BrooklynMementoRawData
input) {
+ Set<String> allReferencedLocations = MutableSet.of();
+
+
allReferencedLocations.addAll(searchLocationsToKeepInEntities(input.getEntities()));
+
allReferencedLocations.addAll(searchLocationsToKeepInPolicies(input.getPolicies()));
+
allReferencedLocations.addAll(searchLocationsToKeepInEnrichers(input.getEnrichers()));
+
allReferencedLocations.addAll(searchLocationsToKeepInLocations(input.getLocations(),
allReferencedLocations));
+
+ return allReferencedLocations;
+ }
+
+ private Set<String> searchLocationsToKeepInEntities(Map<String,
String> entities) {
+ Set<String> result = MutableSet.of();
+
+ for(Map.Entry entity: entities.entrySet()) {
+
+ String locationProxyPrefix = "<locationProxy>";
+ String locationProxySuffix = "</locationProxy>";
+ String locationPrefix = "<locations>\n" +
+ " <string>";
+ String locationSuffix = "</string>\n" +
+ " </locations>";
+ String locationPrefixWinEOF = "<locations>\r\n" +
+ " <string>";
+ String locationSuffixWinEOF = "</string>\r\n" +
+ " </locations>";
+
+ String entityString = (String) entity.getValue();
+ result.addAll(Strings.getAllOccurrencesBetween(entityString,
locationProxyPrefix, locationProxySuffix));
+ result.addAll(Strings.getAllOccurrencesBetween(entityString,
locationPrefix, locationSuffix));
+ result.addAll(Strings.getAllOccurrencesBetween(entityString,
locationPrefixWinEOF, locationSuffixWinEOF));
+ }
+
+ return result;
+ }
+
+ private Set<String> searchLocationsToKeepInLocations(Map<String,
String> locations, Set<String> alreadyReferencedLocations) {
--- End diff --
Added them as well, but the comment won't show as outdated.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---