public class BasicLocationRegistry extends java.lang.Object implements LocationRegistry
LocationRegistry
for general description.
This implementation unfortunately has to deal with location definitions coming from three places:
BrooklynCatalog
BrooklynTypeRegistry
The first is read on init in the call to updateDefinedLocations()
.
The latter two are not loaded here but are treated as lookups to BrooklynTypeRegistry
.
(Prior to 0.12.0 items in BrooklynCatalog
were scanned on init here, and then
it updated this on additions and removals there. That is no longer done with type registry.)
We should consider deprecating this as a place where locations can be defined (switch to type registry only).
However this is used for items from brooklyn.properties -- we could create a bundle to store those to help with migration, and then deprecate/block changes to those after the bundle is created. However properties are the only way currently to set default data used for various clouds; either we'd need to deprecate that also, or find a way to support that in a bundled world.
This is also used in a few other places, such as clocker and the server pool entity. Things here are never persisted though, so it is those callers' responsibility to recreate. Alternatively (better) would be for them to add items to the catalog instead of here.
Or we keep this lying around for now. Probably not worth the pain above.
Also note the location item in the catalog has an unparsed blob of YAML, which contains
important things like the type and the config of the location. This is only parsed when
BrooklynTypeRegistry#createSpec(RegisteredType)
is called, so we do that for
lookup possibly more often than one might expect. (If a time hole this could be cached.)
We also need to make sure some of the resolvers here can be used to identify types, so
when loading types, the spec creation routines are able to call this to
resolve(String, Boolean, Map)
(that returns a Location
not a spec,
but the Location
instance is discarded).
Finally note /v1/catalog/locations does not list items stored here; only /v1/locations does that.
Modifier and Type | Field and Description |
---|---|
static org.slf4j.Logger |
log |
Constructor and Description |
---|
BasicLocationRegistry(ManagementContext mgmt) |
Modifier and Type | Method and Description |
---|---|
static void |
addNamedLocationLocalhost(ManagementContext mgmt) |
boolean |
canMaybeResolve(java.lang.String spec)
Deprecated.
|
static java.util.List<java.lang.String> |
expandCommaSeparateLocations(java.lang.String locations)
Splits a comma-separated list of locations (names or specs) into an explicit list.
|
LocationDefinition |
getDefinedLocationById(java.lang.String id)
returns a LocationDefinition given its ID (usually a random string), or null if none
|
LocationDefinition |
getDefinedLocationByName(java.lang.String name)
returns a LocationDefinition given its name (e.g.
|
java.util.Map<java.lang.String,LocationDefinition> |
getDefinedLocations()
Deprecated.
|
java.util.Map<java.lang.String,LocationDefinition> |
getDefinedLocations(boolean includeThingsWeAreFacadeFor)
map of ID (possibly randomly generated) to the definition (spec, name, id, and props;
where spec is the spec as defined, for instance possibly another named:xxx location).
|
java.util.List<Location> |
getListOfLocationsManaged(java.lang.Object l)
Takes a string, interpreted as a comma-separated (or JSON style, when you need internal double quotes or commas) list;
or a list of strings, or null (giving the empty list) and returns a list of managed locations.
|
Location |
getLocationManaged(java.lang.String spec)
A combination of
LocationRegistry.getLocationSpec(String) then LocationManager.createLocation(LocationSpec) ,
mainly for use in tests or specialised situations where a managed location is needed directly. |
Location |
getLocationManaged(java.lang.String spec,
java.util.Map locationFlags)
As
LocationRegistry.getLocationManaged(String) applying the config as per LocationRegistry.getLocationSpec(String, Map) . |
Maybe<LocationSpec<? extends Location>> |
getLocationSpec(LocationDefinition ld)
As
LocationRegistry.getLocationSpec(String) where the caller has a LocationDefinition . |
Maybe<LocationSpec<? extends Location>> |
getLocationSpec(LocationDefinition ld,
java.util.Map locationFlags)
As
LocationRegistry.getLocationSpec(String,Map) where the caller has a LocationDefinition . |
Maybe<LocationSpec<? extends Location>> |
getLocationSpec(java.lang.String spec)
Create a
LocationSpec representing the given spec string such as a named location
or using a resolver prefix such as jclouds:aws-ec2. |
Maybe<LocationSpec<? extends Location>> |
getLocationSpec(java.lang.String spec,
java.util.Map locationFlags)
As
LocationRegistry.getLocationSpec(String) but also setting the given flags configured on the resulting spec. |
java.util.Map |
getProperties() |
static boolean |
isResolverPrefixForSpec(LocationResolver resolver,
java.lang.String spec,
boolean argumentRequired)
providers default impl for
LocationResolver.accepts(String, LocationRegistry) |
void |
putProperties(java.util.Map<java.lang.String,?> vals) |
boolean |
registerResolver(LocationResolver r)
Registers the given resolver, invoking
LocationResolver.init(ManagementContext) on the argument
and returning true, unless the argument indicates false for LocationResolver.EnableableLocationResolver#isEnabled() |
void |
removeDefinedLocation(CatalogItem<Location,LocationSpec<?>> item)
Deprecated.
since 0.12.0 this class is a facade so method no longer wanted
|
void |
removeDefinedLocation(java.lang.String id)
removes the defined location from the registry (applications running there are unaffected)
|
java.util.List<Location> |
resolve(java.lang.Iterable<?> spec)
Deprecated.
|
Location |
resolve(LocationDefinition ld)
Deprecated.
|
Maybe<Location> |
resolve(LocationDefinition ld,
java.lang.Boolean manage,
java.util.Map locationFlags)
Deprecated.
|
Location |
resolve(java.lang.String spec)
Deprecated.
|
Maybe<Location> |
resolve(java.lang.String spec,
java.lang.Boolean manage,
java.util.Map locationFlags)
Deprecated.
|
Location |
resolve(java.lang.String spec,
java.util.Map locationFlags)
Deprecated.
|
java.util.List<Location> |
resolveList(java.lang.Object l)
Deprecated.
|
void |
updateDefinedLocation(CatalogItem<Location,LocationSpec<?>> item)
Deprecated.
since 0.12.0 this class is a facade so method no longer wanted
|
void |
updateDefinedLocation(LocationDefinition l)
Deprecated.
|
void |
updateDefinedLocation(RegisteredType item)
Deprecated.
since 0.12.0 this class is a facade so method no longer wanted
|
void |
updateDefinedLocationNonPersisted(LocationDefinition l)
adds or updates the given defined location in this registry; note it is not persisted;
callers should consider adding to the
BrooklynTypeRegistry instead |
void |
updateDefinedLocations() |
public BasicLocationRegistry(ManagementContext mgmt)
public static java.util.List<java.lang.String> expandCommaSeparateLocations(java.lang.String locations)
public boolean registerResolver(LocationResolver r)
LocationResolver.init(ManagementContext)
on the argument
and returning true, unless the argument indicates false for LocationResolver.EnableableLocationResolver#isEnabled()
public java.util.Map<java.lang.String,LocationDefinition> getDefinedLocations(boolean includeThingsWeAreFacadeFor)
LocationRegistry
getDefinedLocations
in interface LocationRegistry
@Deprecated public java.util.Map<java.lang.String,LocationDefinition> getDefinedLocations()
getDefinedLocations
in interface LocationRegistry
public LocationDefinition getDefinedLocationById(java.lang.String id)
LocationRegistry
getDefinedLocationById
in interface LocationRegistry
public LocationDefinition getDefinedLocationByName(java.lang.String name)
LocationRegistry
BrooklynTypeRegistry
for registered items, then in this list, or null if nonegetDefinedLocationByName
in interface LocationRegistry
@Deprecated public void updateDefinedLocation(LocationDefinition l)
LocationRegistry
updateDefinedLocation
in interface LocationRegistry
public void updateDefinedLocationNonPersisted(LocationDefinition l)
LocationRegistry
BrooklynTypeRegistry
insteadupdateDefinedLocationNonPersisted
in interface LocationRegistry
@Deprecated public void updateDefinedLocation(CatalogItem<Location,LocationSpec<?>> item)
CatalogItem.getCatalogItemId()
.@Deprecated public void updateDefinedLocation(RegisteredType item)
RegisteredType.getId()
.@Deprecated public void removeDefinedLocation(CatalogItem<Location,LocationSpec<?>> item)
public void removeDefinedLocation(java.lang.String id)
LocationRegistry
removeDefinedLocation
in interface LocationRegistry
public void updateDefinedLocations()
@Deprecated public boolean canMaybeResolve(java.lang.String spec)
LocationRegistry
LocationRegistry.resolve(String, Boolean, Map)
which has stronger guaranteescanMaybeResolve
in interface LocationRegistry
@Deprecated public final Location resolve(java.lang.String spec)
LocationRegistry
LocationRegistry.resolve(String, Boolean, Map)
; asks for the location to be managed, and supplies no additional flags,
and unwraps the result (throwing if the spec cannot be resolve).resolve
in interface LocationRegistry
@Deprecated public Maybe<Location> resolve(java.lang.String spec, java.lang.Boolean manage, java.util.Map locationFlags)
LocationRegistry
resolve
in interface LocationRegistry
public Location getLocationManaged(java.lang.String spec)
LocationRegistry
LocationRegistry.getLocationSpec(String)
then LocationManager.createLocation(LocationSpec)
,
mainly for use in tests or specialised situations where a managed location is needed directly.
The caller is responsible for ensuring that the resulting Location
is cleaned up, ie removed from management via LocationManager.unmanage(Location)
directly or linking it to
an Entity
or another Location
which will unmanage it.getLocationManaged
in interface LocationRegistry
public final Location getLocationManaged(java.lang.String spec, java.util.Map locationFlags)
LocationRegistry
LocationRegistry.getLocationManaged(String)
applying the config as per LocationRegistry.getLocationSpec(String, Map)
.getLocationManaged
in interface LocationRegistry
public Maybe<LocationSpec<? extends Location>> getLocationSpec(LocationDefinition ld)
LocationRegistry
LocationRegistry.getLocationSpec(String)
where the caller has a LocationDefinition
.getLocationSpec
in interface LocationRegistry
public Maybe<LocationSpec<? extends Location>> getLocationSpec(LocationDefinition ld, java.util.Map locationFlags)
LocationRegistry
LocationRegistry.getLocationSpec(String,Map)
where the caller has a LocationDefinition
.getLocationSpec
in interface LocationRegistry
public Maybe<LocationSpec<? extends Location>> getLocationSpec(java.lang.String spec)
LocationRegistry
LocationSpec
representing the given spec string such as a named location
or using a resolver prefix such as jclouds:aws-ec2.
This can then be inspected, assigned to an EntitySpec
,
or passed to LocationManager.createLocation(LocationSpec)
to create directly.
(For that last case, common in tests, see LocationRegistry.getLocationManaged(String)
.)getLocationSpec
in interface LocationRegistry
public Maybe<LocationSpec<? extends Location>> getLocationSpec(java.lang.String spec, java.util.Map locationFlags)
LocationRegistry
LocationRegistry.getLocationSpec(String)
but also setting the given flags configured on the resulting spec.getLocationSpec
in interface LocationRegistry
@Deprecated public final Location resolve(java.lang.String spec, java.util.Map locationFlags)
LocationRegistry
LocationRegistry.resolve(String, Boolean, Map)
, but unwrappedresolve
in interface LocationRegistry
public static boolean isResolverPrefixForSpec(LocationResolver resolver, java.lang.String spec, boolean argumentRequired)
LocationResolver.accepts(String, LocationRegistry)
@Deprecated public java.util.List<Location> resolve(java.lang.Iterable<?> spec)
LocationRegistry
LocationRegistry.getLocationManaged(String)
but takes collections (of strings or locations)
Expects a collection of elements being individual location spec strings or locations, and returns a list of resolved (newly created and managed) locations.
From 0.7.0 this no longer flattens lists (nested lists are disallowed) or parses comma-separated elements (they are resolved as-is)
resolve
in interface LocationRegistry
@Deprecated public java.util.List<Location> resolveList(java.lang.Object l)
LocationRegistry
LocationRegistry.resolve(Iterable)
; or null/empty (empty list),
and returns a list of resolved (created and managed) locationsresolveList
in interface LocationRegistry
public java.util.List<Location> getListOfLocationsManaged(java.lang.Object l)
LocationRegistry
The caller is responsible for ensuring these get cleaned up, as described at LocationRegistry.getLocationManaged(String)
.
getListOfLocationsManaged
in interface LocationRegistry
@Deprecated public Location resolve(LocationDefinition ld)
LocationRegistry
resolve
in interface LocationRegistry
@Deprecated public Maybe<Location> resolve(LocationDefinition ld, java.lang.Boolean manage, java.util.Map locationFlags)
LocationRegistry
The manage parameter is Boolean
so that null can be used to say rely on anything in the flags.
resolve
in interface LocationRegistry
public java.util.Map getProperties()
getProperties
in interface LocationRegistry
public void putProperties(java.util.Map<java.lang.String,?> vals)
public static void addNamedLocationLocalhost(ManagementContext mgmt)