@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 <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); } }
protected SshMachineLocation createMachine(String addr) { if (lm==null) return new SshMachineLocation(makeConfig(addr)); else return lm.createLocation(makeConfig(addr), SshMachineLocation.class); } private Map makeConfig(String address) {
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)); }
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(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())); }
@SuppressWarnings("unchecked") public FixedListMachineProvisioningLocation<SshMachineLocation> build() { if (lm==null) return new FixedListMachineProvisioningLocation<SshMachineLocation>(MutableMap.builder() .putIfNotNull("machines", machines) .putIfNotNull("user", user) .putIfNotNull("privateKeyPassphrase", privateKeyPassphrase) .putIfNotNull("privateKeyFile", privateKeyFile) .putIfNotNull("privateKeyData", privateKeyData) .putIfNotNull("localTempDir", localTempDir) .build()); else return lm.createLocation(MutableMap.builder() .putIfNotNull("machines", machines) .putIfNotNull("user", user) .putIfNotNull("privateKeyPassphrase", privateKeyPassphrase) .putIfNotNull("privateKeyFile", privateKeyFile) .putIfNotNull("privateKeyData", privateKeyData) .putIfNotNull("localTempDir", localTempDir) .build(), FixedListMachineProvisioningLocation.class); } }
return getManagementContext().getLocationManager().createLocation(LocationSpec.create(JcloudsSshMachineLocation.class) .configure("address", vmHostname) .configure("displayName", vmHostname)