public class BasicLocationRegistry extends java.lang.Object implements LocationRegistry
LocationRegistry for general description.
TODO The relationship between the catalog and the location registry is a bit messy. For all existing code, the location registry is the definitive way to resolve locations.
Any location item added to the catalog must therefore be registered here.
Whenever an item is added to the catalog, it will automatically call
updateDefinedLocation(RegisteredType). Similarly, when a location
is deleted from the catalog it will call #removeDefinedLocation(RegisteredType).
However, 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
BrooklynCatalog.createSpec(CatalogItem) is called. We therefore jump through
some hoops to wire together the catalog and the registry.
To add a location to the catalog, and then to resolve a location that is in the catalog, it goes through the following steps:
BrooklynCatalog.addItems(String)
updateDefinedLocation(RegisteredType)
RegisteredType.getSymbolicName().
The definition's spec is brooklyn.catalog:<symbolicName>:<version>,
location: my-new-location.
(this feels similar to the "named locations").
getLocationManaged(String).
LocationDefiniton.getSpec() is retrieved; the right LocationResolver is
found for it.
CatalogLocationResolver, because the spec starts with brooklyn.catalog:.
BrooklynTypeRegistry.
LocationSpec by calling BrooklynTypeRegistry#createSpec(RegisteredType).
resolve(String, Boolean, Map), which
returns an actual location object.
LocationSpec,
returns the spec and discards the location object.
Location from the LocationSpec
Once done, update the UI use /v1/catalog/locations instead of /v1/locations (currently the latter is the only way to list locations known in the LocationRegistry ie those from brookln.properties.)
| 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()
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) |
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)
Converts the given item from the catalog into a LocationDefinition, and adds it
to the registry (overwriting anything already registered with the id
CatalogItem.getCatalogItemId(). |
void |
updateDefinedLocation(LocationDefinition l)
adds or updates the given defined location
|
void |
updateDefinedLocation(RegisteredType item)
Converts the given item from the catalog into a LocationDefinition, and adds it
to the registry (overwriting anything already registered with the id
RegisteredType.getId(). |
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()
LocationRegistrygetDefinedLocations in interface LocationRegistrypublic LocationDefinition getDefinedLocationById(java.lang.String id)
LocationRegistrygetDefinedLocationById in interface LocationRegistrypublic LocationDefinition getDefinedLocationByName(java.lang.String name)
LocationRegistrygetDefinedLocationByName in interface LocationRegistrypublic void updateDefinedLocation(LocationDefinition l)
LocationRegistryupdateDefinedLocation in interface LocationRegistrypublic void updateDefinedLocation(CatalogItem<Location,LocationSpec<?>> item)
CatalogItem.getCatalogItemId().public void updateDefinedLocation(RegisteredType item)
RegisteredType.getId().public void removeDefinedLocation(CatalogItem<Location,LocationSpec<?>> item)
public void removeDefinedLocation(java.lang.String id)
LocationRegistryremoveDefinedLocation in interface LocationRegistrypublic void updateDefinedLocations()
@Deprecated public boolean canMaybeResolve(java.lang.String spec)
LocationRegistryLocationRegistry.resolve(String, Boolean, Map) which has stronger guaranteescanMaybeResolve in interface LocationRegistry@Deprecated public final Location resolve(java.lang.String spec)
LocationRegistryLocationRegistry.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)
LocationRegistryresolve in interface LocationRegistrypublic Location getLocationManaged(java.lang.String spec)
LocationRegistryLocationRegistry.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 LocationRegistrypublic final Location getLocationManaged(java.lang.String spec, java.util.Map locationFlags)
LocationRegistryLocationRegistry.getLocationManaged(String) applying the config as per LocationRegistry.getLocationSpec(String, Map).getLocationManaged in interface LocationRegistrypublic Maybe<LocationSpec<? extends Location>> getLocationSpec(LocationDefinition ld)
LocationRegistryLocationRegistry.getLocationSpec(String) where the caller has a LocationDefinition.getLocationSpec in interface LocationRegistrypublic Maybe<LocationSpec<? extends Location>> getLocationSpec(LocationDefinition ld, java.util.Map locationFlags)
LocationRegistryLocationRegistry.getLocationSpec(String,Map) where the caller has a LocationDefinition.getLocationSpec in interface LocationRegistrypublic Maybe<LocationSpec<? extends Location>> getLocationSpec(java.lang.String spec)
LocationRegistryLocationSpec 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 LocationRegistrypublic Maybe<LocationSpec<? extends Location>> getLocationSpec(java.lang.String spec, java.util.Map locationFlags)
LocationRegistryLocationRegistry.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)
LocationRegistryLocationRegistry.resolve(String, Boolean, Map), but unwrappedresolve in interface LocationRegistrypublic 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)
LocationRegistryLocationRegistry.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)
LocationRegistryLocationRegistry.resolve(Iterable); or null/empty (empty list),
and returns a list of resolved (created and managed) locationsresolveList in interface LocationRegistrypublic 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)
LocationRegistryresolve 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 LocationRegistrypublic java.util.Map getProperties()
getProperties in interface LocationRegistrypublic void putProperties(java.util.Map<java.lang.String,?> vals)
public static void addNamedLocationLocalhost(ManagementContext mgmt)