protected void assertNotYetManaged() { if (!inConstruction && (managementContext != null && managementContext.getLocationManager().isManaged(this))) { LOG.warn("Configuration being made to {} after deployment; may not be supported in future versions", this); } //throw new IllegalStateException("Cannot set configuration "+key+" on active location "+this) }
/** * Registers the given location (and all its children) with the management context. * @throws IllegalStateException if the parent location is not already managed * * @since 0.6.0 (added only for backwards compatibility, where locations are being created directly). * @deprecated in 0.6.0; use {@link LocationManager#createLocation(LocationSpec)} instead. */ public static void manage(Location loc, ManagementContext managementContext) { if (!managementContext.getLocationManager().isManaged(loc)) { log.warn("Deprecated use of unmanaged location ("+loc+"); will be managed automatically now but not supported in future versions"); // FIXME this occurs MOST OF THE TIME e.g. including BrooklynLauncher.location(locationString) // not sure what is the recommend way to convert from locationString to locationSpec, or the API we want to expose; // deprecating some of the LocationRegistry methods seems sensible? log.debug("Stack trace for location of: Deprecated use of unmanaged location; will be managed automatically now but not supported in future versions", new Exception("TRACE for: Deprecated use of unmanaged location")); managementContext.getLocationManager().manage(loc); } }
@Override public <T extends Location> T createLocation(Map<?, ?> config, Class<T> type) { if (isInitialManagementContextReal()) { return initialManagementContext.getLocationManager().createLocation(config, type); } else { throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation: cannot create "+type); } }
@Override public Location manage(Location loc) { if (isInitialManagementContextReal()) { return initialManagementContext.getLocationManager().manage(loc); } else { throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation: cannot manage "+loc); } }
@Override public Collection<Location> getLocations() { if (isInitialManagementContextReal()) { return initialManagementContext.getLocationManager().getLocations(); } else { return Collections.emptyList(); } }
@Override public <T extends Location> T createLocation(LocationSpec<T> spec) { if (isInitialManagementContextReal()) { return initialManagementContext.getLocationManager().createLocation(spec); } else { throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation: cannot create "+spec); } }
@Override public void unmanage(Location loc) { if (isInitialManagementContextReal()) { initialManagementContext.getLocationManager().unmanage(loc); } else { throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation: cannot unmanage "+loc); } }
@Override public Location getLocation(String id) { if (isInitialManagementContextReal()) { return initialManagementContext.getLocationManager().getLocation(id); } else { return null; } }
protected boolean removeChild(Location child) { boolean removed; synchronized (childLocations) { removed = childLocations.remove(child); } if (removed) { if (child instanceof Closeable) { Closeables.closeQuietly((Closeable)child); } child.setParent(null); if (isManaged()) { managementContext.getLocationManager().unmanage(child); } } return removed; }
public void addChild(Location child) { // Previously, setParent delegated to addChildLocation and we sometimes ended up with // duplicate entries here. Instead this now uses a similar scheme to // AbstractLocation.setParent/addChild (with any weaknesses for distribution that such a // scheme might have...). // // We continue to use a list to allow identical-looking locations, but they must be different // instances. synchronized (childLocations) { for (Location contender : childLocations) { if (contender == child) { // don't re-add; no-op return; } } childLocations.add(child); } child.setParent(this); if (isManaged()) { managementContext.getLocationManager().manage(child); } }
return managementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class) .configure(flags));
machine = managementContext.getLocationManager().createLocation(MutableMap.of("user", userHere.trim(), "address", hostHere.trim()), SshMachineLocation.class); } else { machine = managementContext.getLocationManager().createLocation(MutableMap.of("address", hostHere.trim()), SshMachineLocation.class); return managementContext.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class) .configure(flags));
protected Location newLocationFromString(String spec, brooklyn.location.LocationRegistry registry, Map properties, Map locationFlags) { Matcher matcher = PATTERN.matcher(spec); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid location '" + spec + "'; must specify something like single(named:foo)"); } String namedLocation = (String) locationFlags.get("named"); String args = matcher.group(2); Map<String,?> locationArgs = KeyValueParser.parseMap(args); Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null, namedLocation, properties); MutableMap<String, Object> flags = MutableMap.<String, Object>builder() .putAll(filteredProperties) .putAll(locationFlags) .removeAll("named") .putAll(locationArgs).build(); if (locationArgs.get("target") == null) { throw new IllegalArgumentException("target must be specified in single-machine spec"); } String target = locationArgs.get("target").toString(); locationArgs.remove("target"); if (!managementContext.getLocationRegistry().canResolve(target)) { throw new IllegalArgumentException("Invalid target location '" + target + "'; must be resolvable location"); } return managementContext.getLocationManager().createLocation(LocationSpec.create(SingleMachineProvisioningLocation.class) .configure("location", target) .configure("locationFlags", flags)); }
protected FixedListMachineProvisioningLocation<SshMachineLocation> newLocationFromString(String spec, brooklyn.location.LocationRegistry registry, Map properties, Map locationFlags) { Matcher matcher = PATTERN.matcher(spec); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid location '" + spec + "'; must specify something like host:(\"1.1.1.1\")"); } String namedLocation = (String) locationFlags.get("named"); Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null, namedLocation, properties); MutableMap<String, Object> flags = MutableMap.<String, Object>builder().putAll(filteredProperties).putAll(locationFlags).removeAll("named").build(); String args = matcher.group(2); String target = "byon:(hosts=" + args + ")"; if (!managementContext.getLocationRegistry().canResolve(target)) { throw new IllegalArgumentException("Invalid target location '" + target + "'; must be resolvable location"); } return managementContext.getLocationManager().createLocation(LocationSpec.create(SingleMachineProvisioningLocation.class) .configure("location", target) .configure("locationFlags", flags)); }
.build(); if (isManaged()) { sshLocByIp = getManagementContext().getLocationManager().createLocation(locationProps, SshMachineLocation.class); } else { sshLocByIp = new SshMachineLocation(locationProps);
return managementContext.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class) .configure(flags));
/** uses reflection to create an object of the same type, assuming a Map constructor; * subclasses can extend and downcast the result */ @Override public AbstractCloudMachineProvisioningLocation newSubLocation(Map<?,?> newFlags) { // TODO should be able to use ConfigBag.newInstanceExtending; would require moving stuff around to api etc // TODO was previously `return LocationCreationUtils.newSubLocation(newFlags, this)`; need to retest on CloudStack etc return getManagementContext().getLocationManager().createLocation(LocationSpec.create(getClass()) .parent(this) .configure(getRawLocalConfigBag().getAllConfig()) .configure(newFlags)); }
return managementContext.getLocationManager().createLocation(LocationSpec.create(JcloudsLocation.class) .configure(jcloudsProperties));
@Override public JcloudsLocation newSubLocation(Map<?,?> newFlags) { // TODO should be able to use ConfigBag.newInstanceExtending; would require moving stuff around to api etc return getManagementContext().getLocationManager().createLocation(LocationSpec.create(getClass()) .parent(this) .configure(getRawLocalConfigBag().getAllConfig()) .configure(newFlags) .configure(MACHINE_CREATION_SEMAPHORE, getMachineCreationSemaphore())); }
return getManagementContext().getLocationManager().createLocation(LocationSpec.create(JcloudsSshMachineLocation.class) .configure("address", vmHostname) .configure("displayName", vmHostname)