private static BasicLocationDefinition localhost(String id) { return new BasicLocationDefinition(id, "localhost", "localhost", null); }
protected BasicLocationDefinition newDefinedLocation(RegisteredType item) { String id = item.getId(); String spec = CatalogLocationResolver.createLegacyWrappedReference(id); return new BasicLocationDefinition(id, item.getSymbolicName(), spec, ImmutableMap.<String, Object>of()); }
/** * Converts the given item from the catalog into a LocationDefinition, and adds it * to the registry (overwriting anything already registered with the id * {@link CatalogItem#getCatalogItemId()}. * @deprecated since 0.12.0 this class is a facade so method no longer wanted */ @Deprecated // not used public void updateDefinedLocation(CatalogItem<Location, LocationSpec<?>> item) { String id = item.getCatalogItemId(); String symbolicName = item.getSymbolicName(); String spec = CatalogLocationResolver.createLegacyWrappedReference(id); Map<String, Object> config = ImmutableMap.<String, Object>of(); BasicLocationDefinition locDefinition = new BasicLocationDefinition(symbolicName, symbolicName, spec, config); updateDefinedLocation(locDefinition); }
public void updateDefinedLocations() { synchronized (definedLocations) { // first read all properties starting brooklyn.location.named.xxx // (would be nice to move to a better way, e.g. yaml, then deprecate this approach, but first // we need ability/format for persisting named locations, and better support for adding+saving via REST/GUI) int count = 0; String NAMED_LOCATION_PREFIX = "brooklyn.location.named."; StringConfigMap namedLocationProps = mgmt.getConfig().submap(ConfigPredicates.nameStartsWith(NAMED_LOCATION_PREFIX)); for (String k: namedLocationProps.asMapWithStringKeys().keySet()) { String name = k.substring(NAMED_LOCATION_PREFIX.length()); // If has a dot, then is a sub-property of a named location (e.g. brooklyn.location.named.prod1.user=bob) if (!name.contains(".")) { // this is a new named location String spec = (String) namedLocationProps.asMapWithStringKeys().get(k); // make up an ID String id = Identifiers.makeRandomId(8); BrooklynProperties config = ConfigUtils.filterForPrefixAndStrip(namedLocationProps.asMapWithStringKeys(), k+"."); definedLocations.put(id, new BasicLocationDefinition(id, name, spec, config.asMapWithStringKeys())); count++; } } if (log.isDebugEnabled()) log.debug("Found "+count+" defined locations from properties (*.named.* syntax): "+definedLocations.values()); } }
@SuppressWarnings("deprecation") public static LocationSummary newInstance(ManagementContext mgmt, String id, org.apache.brooklyn.rest.domain.LocationSpec locationSpec, LocationDetailLevel level, UriBuilder ub) { LocationDefinition ld = new BasicLocationDefinition(id, locationSpec.getName(), locationSpec.getSpec(), locationSpec.getConfig()); return newInstance(mgmt, ld, level, ub); }
@Override public LocationDefinition register() { String locationName = checkNotNull(getConfig(LOCATION_NAME), "config %s", LOCATION_NAME.getName()); LocationDefinition check = getManagementContext().getLocationRegistry().getDefinedLocationByName(locationName); if (check != null) { throw new IllegalStateException("Location " + locationName + " is already defined: " + check); } String locationSpec = String.format(DockerResolver.DOCKER_INFRASTRUCTURE_SPEC, getId()) + String.format(":(name=\"%s\")", locationName); LocationDefinition definition = new BasicLocationDefinition(locationName, locationSpec, ImmutableMap.<String, Object>of()); getManagementContext().getLocationRegistry().updateDefinedLocation(definition); locationRegistrationId = definition.getId(); requestPersist(); return definition; }
@Override public LocationDefinition register() { String locationName = checkNotNull(config().get(LOCATION_NAME), "config %s", LOCATION_NAME.getName()); LocationDefinition check = getManagementContext().getLocationRegistry().getDefinedLocationByName(locationName); if (check != null) { throw new IllegalStateException("Location " + locationName + " is already defined: " + check); } String locationSpec = String.format(ServerPoolLocationResolver.POOL_SPEC, getId()) + String.format(":(name=\"%s\")", locationName); LocationDefinition definition = new BasicLocationDefinition(locationName, locationSpec, ImmutableMap.<String, Object>of()); getManagementContext().getLocationRegistry().updateDefinedLocation(definition); locationRegistrationId = definition.getId(); requestPersist(); return definition; }
@Override public LocationDefinition register() { String locationName = checkNotNull(getConfig(LOCATION_NAME), "config %s", LOCATION_NAME.getName()); LocationDefinition check = getManagementContext().getLocationRegistry().getDefinedLocationByName(locationName); if (check != null) { throw new IllegalStateException("Location " + locationName + " is already defined: " + check); } String locationSpec = String.format(MesosResolver.MESOS_CLUSTER_SPEC, getId()) + String.format(":(name=\"%s\")", locationName); LocationDefinition definition = new BasicLocationDefinition(locationName, locationSpec, ImmutableMap.<String, Object>of()); getManagementContext().getLocationRegistry().updateDefinedLocation(definition); locationRegistrationId = definition.getId(); requestPersist(); return definition; }
@Override public LocationDefinition register() { String locationName = checkNotNull(getConfig(LOCATION_NAME), "config %s", LOCATION_NAME.getName()); LocationDefinition check = getManagementContext().getLocationRegistry().getDefinedLocationByName(locationName); if (check != null) { throw new IllegalStateException("Location " + locationName + " is already defined: " + check); } String locationSpec = String.format(MarathonResolver.MARATHON_FRAMEWORK_SPEC, getId()) + String.format(":(name=\"%s\")", locationName); LocationDefinition definition = new BasicLocationDefinition(locationName, locationSpec, ImmutableMap.<String, Object>of()); getManagementContext().getLocationRegistry().updateDefinedLocation(definition); locationRegistrationId = definition.getId(); requestPersist(); return definition; }
@Override public LocationDefinition register() { String locationName = checkNotNull(config().get(LOCATION_NAME), "config %s", LOCATION_NAME.getName()); LocationDefinition check = getManagementContext().getLocationRegistry().getDefinedLocationByName(locationName); if (check != null) { throw new IllegalStateException("Location " + locationName + " is already defined: " + check); } String hostLocId = getId(); String infraLocId = (getParent() != null) ? getParent().getId() : ""; String locationSpec = String.format(DockerResolver.DOCKER_HOST_MACHINE_SPEC, infraLocId, hostLocId) + String.format(":(name=\"%s\")", locationName); LocationDefinition definition = new BasicLocationDefinition(locationName, locationSpec, ImmutableMap.<String, Object>of()); getManagementContext().getLocationRegistry().updateDefinedLocation(definition); locationRegistrationId = definition.getId(); requestPersist(); return definition; }
@Override public LocationDefinition register() { String locationName = checkNotNull(getConfig(LOCATION_NAME), "config %s", LOCATION_NAME.getName()); LocationDefinition check = getManagementContext().getLocationRegistry().getDefinedLocationByName(locationName); if (check != null) { throw new IllegalStateException("Location " + locationName + " is already defined: " + check); } String locationSpec = String.format(StubResolver.DOCKER_INFRASTRUCTURE_SPEC, getId()) + String.format(":(name=\"%s\")", locationName); LocationDefinition definition = new BasicLocationDefinition(locationName, locationSpec, ImmutableMap.<String, Object>of()); getManagementContext().getLocationRegistry().updateDefinedLocation(definition); locationRegistrationId = definition.getId(); requestPersist(); return definition; }
@Override public LocationDefinition register() { String locationName = checkNotNull(getConfig(LOCATION_NAME), "config %s", LOCATION_NAME.getName()); LocationDefinition check = getManagementContext().getLocationRegistry().getDefinedLocationByName(locationName); if (check != null) { throw new IllegalStateException("Location " + locationName + " is already defined: " + check); } String hostLocId = getId(); String infraLocId = (getParent() != null) ? getParent().getId() : ""; String locationSpec = String.format(StubResolver.DOCKER_HOST_MACHINE_SPEC, infraLocId, hostLocId) + String.format(":(name=\"%s\")", locationName); LocationDefinition definition = new BasicLocationDefinition(locationName, locationSpec, ImmutableMap.<String, Object>of()); getManagementContext().getLocationRegistry().updateDefinedLocation(definition); locationRegistrationId = definition.getId(); requestPersist(); return definition; }
@Test public void testManagedLocationsNamedCreateAndCleanup() { Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(0)); Asserts.assertThat(mgmt.getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(0)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); mgmt.getLocationRegistry().updateDefinedLocationNonPersisted( new BasicLocationDefinition("lh1", "localhost", null) ); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); // currently such defined locations do NOT appear in catalog -- see CatalogYamlLocationTest Asserts.assertThat(mgmt.getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(0)); Location loc = mgmt.getLocationRegistry().getLocationManaged("lh1"); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(1)); mgmt.getLocationManager().unmanage(loc); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); }