Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/746#discussion_r127262964
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java 
---
    @@ -194,29 +168,71 @@ public boolean registerResolver(LocationResolver r) {
         }
         
         @Override
    -    public Map<String,LocationDefinition> getDefinedLocations() {
    +    public Map<String, LocationDefinition> getDefinedLocations(boolean 
includeThingsWeAreFacadeFor) {
    +        Map<String, LocationDefinition> result = MutableMap.of();
             synchronized (definedLocations) {
    -            return 
ImmutableMap.<String,LocationDefinition>copyOf(definedLocations);
    +            result.putAll(definedLocations);
    +        }
    +        for (RegisteredType rt: 
mgmt.getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION)) {
    +            result.put(rt.getId(), newDefinedLocation(rt));
             }
    +        return result;
    +    }
    +    
    +    @Override @Deprecated
    +    public Map<String,LocationDefinition> getDefinedLocations() {
    +        return getDefinedLocations(true);
         }
         
         @Override
         public LocationDefinition getDefinedLocationById(String id) {
    -        return definedLocations.get(id);
    +        return getDefinedLocation(id, true);
         }
     
         @Override
         public LocationDefinition getDefinedLocationByName(String name) {
    +        return getDefinedLocation(name, false);
    +    }
    +    
    +    private LocationDefinition getDefinedLocation(String nameOrId, boolean 
isId) {
    +        RegisteredType lt = mgmt.getTypeRegistry().get(nameOrId, 
RegisteredTypeLoadingContexts.withSpecSuperType(null, LocationSpec.class));
    +        if (lt!=null) {
    +            return newDefinedLocation(lt);
    +        }
    +        
             synchronized (definedLocations) {
    -            for (LocationDefinition l: definedLocations.values()) {
    -                if (l.getName().equals(name)) return l;
    +            if (isId) {
    +                LocationDefinition ld = definedLocations.get(nameOrId);
    +                if (ld!=null) {
    +                    return ld;
    +                }
    +            } else {
    +                for (LocationDefinition l: definedLocations.values()) {
    +                    if (l.getName().equals(nameOrId)) return l;
    +                }
    +            }
    +        }
    +        
    +        // fall back to ignoring supertypes, in case they weren't set
    +        lt = mgmt.getTypeRegistry().get(nameOrId);
    +        if (lt!=null && lt.getSuperTypes().isEmpty()) {
    +            if (lt.getKind()!=RegisteredTypeKind.UNRESOLVED) {
    +                // don't warn when still trying to resolve
    +                log.warn("Location registry only found "+nameOrId+" when 
ignoring supertypes; check it is correctly resolved.");
                 }
    -            return null;
    +            return newDefinedLocation(lt);
             }
    +        
    +        return null;
         }
     
    -    @Override
    +    @Override @Deprecated
    --- End diff --
    
    need a `since` comment here too


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to