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(CatalogItem)
. Similarly, when a location
is deleted from the catalog it will call removeDefinedLocation(CatalogItem)
.
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(CatalogItem)
CatalogItem.getSymbolicName()
.
The definition's spec is brooklyn.catalog:<symbolicName>:<version>
,
location: my-new-location
.
(this feels similar to the "named locations").
resolve(String)
.
LocationDefiniton.getSpec()
is retrieved; the right LocationResolver
is
found for it.
CatalogLocationResolver
, because the spec starts with brooklyn.catalog:
.
BrooklynCatalog.getCatalogItem(String, String)
.
LocationSpec
by calling BrooklynCatalog.createSpec(CatalogItem)
.
resolve(String, Boolean, Map)
, which
returns an actual location object.
LocationSpec
,
returns the spec and discards the location object.
Location
from the LocationSpec
Modifier and Type | Field and Description |
---|---|
static org.slf4j.Logger |
log |
Constructor and Description |
---|
BasicLocationRegistry(ManagementContext mgmt) |
Modifier and Type | Method and Description |
---|---|
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.Map |
getProperties() |
static boolean |
isResolverPrefixForSpec(LocationResolver resolver,
java.lang.String spec,
boolean argumentRequired)
providers default impl for RegistryLocationResolver.accepts
|
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)
As
LocationRegistry.resolve(String) but takes collections (of strings or locations) |
Location |
resolve(LocationDefinition ld)
As {@link #resolve(LocationDefinition, Boolean, Map), with the location managed, and no additional flags,
unwrapping the result (throwing if not resolvable)
|
Maybe<Location> |
resolve(LocationDefinition ld,
java.lang.Boolean manage,
java.util.Map locationFlags)
Returns a fully populated (config etc) location from the given definition, with optional add'l flags.
|
Location |
resolve(LocationDefinition ld,
java.util.Map<?,?> flags)
Deprecated.
|
Location |
resolve(java.lang.String spec)
See
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) |
Maybe<Location> |
resolve(java.lang.String spec,
boolean manage)
Deprecated.
|
Maybe<Location> |
resolve(java.lang.String spec,
java.lang.Boolean manage,
java.util.Map locationFlags)
Returns a location created from the given spec, which might correspond to a definition, or created on-the-fly.
|
Location |
resolve(java.lang.String spec,
java.util.Map locationFlags)
As
LocationRegistry.resolve(String, Boolean, Map) , but unwrapped |
Location |
resolveForPeeking(LocationDefinition ld)
Deprecated.
|
Location |
resolveIfPossible(java.lang.String spec)
Deprecated.
|
java.util.List<Location> |
resolveList(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, passed to
LocationRegistry.resolve(Iterable) ; or null/empty (empty list),
and returns a list of resolved (created and managed) locations |
Location |
resolveLocationDefinition(LocationDefinition ld,
java.util.Map locationFlags,
java.lang.String optionalName)
Deprecated.
since 0.7.0 not used (and optionalName was ignored anyway)
|
static void |
setupLocationRegistryForTesting(ManagementContext mgmt) |
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 |
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()
LocationRegistry
getDefinedLocations
in interface LocationRegistry
public LocationDefinition getDefinedLocationById(java.lang.String id)
LocationRegistry
getDefinedLocationById
in interface LocationRegistry
public LocationDefinition getDefinedLocationByName(java.lang.String name)
LocationRegistry
getDefinedLocationByName
in interface LocationRegistry
public void updateDefinedLocation(LocationDefinition l)
LocationRegistry
updateDefinedLocation
in interface LocationRegistry
public void updateDefinedLocation(CatalogItem<Location,LocationSpec<?>> item)
CatalogItem.getCatalogItemId()
.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
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 final Location resolveIfPossible(java.lang.String spec)
LocationRegistry
LocationRegistry.resolve(String)
but returning null (never throwing)resolveIfPossible
in interface LocationRegistry
@Deprecated public final Maybe<Location> resolve(java.lang.String spec, boolean manage)
public Maybe<Location> resolve(java.lang.String spec, java.lang.Boolean manage, java.util.Map locationFlags)
LocationRegistry
resolve
in interface LocationRegistry
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)
public java.util.List<Location> resolve(java.lang.Iterable<?> spec)
LocationRegistry
LocationRegistry.resolve(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
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 Location resolve(LocationDefinition ld)
LocationRegistry
resolve
in interface LocationRegistry
@Deprecated public Location resolveForPeeking(LocationDefinition ld)
LocationRegistry
resolveForPeeking
in interface LocationRegistry
@Deprecated public Location resolve(LocationDefinition ld, java.util.Map<?,?> flags)
LocationRegistry
resolve
in interface LocationRegistry
@Deprecated public Location resolveLocationDefinition(LocationDefinition ld, java.util.Map locationFlags, java.lang.String optionalName)
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 static void setupLocationRegistryForTesting(ManagementContext mgmt)