public boolean isManaged() { return getManagementContext() != null && managed; }
private SubscriptionContext newSubscriptionContext() { synchronized (AbstractLocation.this) { return getManagementContext().getSubscriptionContext(AbstractLocation.this); } } }
@Override protected ExecutionContext getContext() { return AbstractLocation.this.getManagementContext().getServerExecutionContext(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private void loadExtension() { Map<String, String> extensions = getConfig(LocationConfigKeys.EXTENSIONS); if (extensions != null) { for (Map.Entry<String, String> extension: extensions.entrySet()) { try { Class<?> extensionClassType = new ClassLoaderUtils(this, getManagementContext()).loadClass(extension.getKey()); if (!hasExtension(extensionClassType)) { Object extensionClass = new ClassLoaderUtils(this, getManagementContext()).loadClass(extension.getValue()).newInstance(); addExtension((Class)extensionClassType, extensionClass); } } catch (Exception e) { LOG.error("Location extension can not be loaded (rethrowing): {} {} {}", new Object[] {extension.getKey(), extension.getValue(), e}); throw Exceptions.propagate(e); } } } }
if (!getManagementContext().getLocationManager().isManaged(child)) { Locations.manage(child, getManagementContext()); } else if (getManagementContext() != null) { if (((LocalLocationManager)getManagementContext().getLocationManager()).getLocationEvenIfPreManaged(child.getId()) == null) { ((ManagementContextInternal)getManagementContext()).prePreManage(child);
@Override protected ExecutionContext getExecutionContext(BrooklynObject bo) { // Support DSL in location config. DSL expects to be resolved in the execution context of an entity. // Since there's no location-entity relation try to infer it from the context of the caller. Entity contextEntity = BrooklynTaskTags.getTargetOrContextEntity(Tasks.current()); if (contextEntity != null) { return ((EntityInternal)contextEntity).getExecutionContext(); } else { // Known places we get called without entity context: // * unmanaging entity and subsequently its location // * EntityResource.listTasks(String, String) returning a Task<SshMachineLocation> and calling toString() on the return value log.trace("No resolving context found, will use global execution context. Could lead to NPE on DSL resolving."); if (bo==null) return null; ManagementContext mgmt = ((AbstractLocation)bo).getManagementContext(); if (mgmt==null) return null; return mgmt.getServerExecutionContext(); } }
protected void onChanged() { // currently changes simply trigger re-persistence; there is no intermediate listener as we do for EntityChangeListener if (isManaged()) { getManagementContext().getRebindManager().getChangeListener().onChanged(this); } }
public void onManagementStopped() { this.managed = false; if (getManagementContext().isRunning()) { BrooklynStorage storage = ((ManagementContextInternal)getManagementContext()).getStorage(); storage.remove(getId()+"-parent"); storage.remove(getId()+"-children"); storage.remove(getId()+"-creationTime"); storage.remove(getId()+"-hostGeoInfo"); storage.remove(getId()+"-displayName"); storage.remove(getId()+"-config"); } }
public boolean removeChild(Location child) { boolean removed; synchronized (children) { removed = children.remove(child); } if (removed) { if (child instanceof Closeable) { Streams.closeQuietly((Closeable)child); } child.setParent(null); if (isManaged() && Locations.isManaged(child)) { // This is called as part of child's LocalLocationManager.unmanage; don't try to // unmanage it yet again as then would get a log.warn! getManagementContext().getLocationManager().unmanage(child); } } onChanged(); return removed; }
private static Map<String, Object> getSshFlags(Location location) { Set<ConfigKey<?>> sshConfig = MutableSet.of(); StringConfigMap mgmtConfig = null; sshConfig.addAll(location.config().findKeysPresent(ConfigPredicates.nameStartsWith(SshTool.BROOKLYN_CONFIG_KEY_PREFIX))); if (location instanceof AbstractLocation) { ManagementContext mgmt = ((AbstractLocation)location).getManagementContext(); if (mgmt!=null) { mgmtConfig = mgmt.getConfig(); sshConfig.addAll(mgmtConfig.findKeysPresent(ConfigPredicates.nameStartsWith(SshTool.BROOKLYN_CONFIG_KEY_PREFIX))); } } Map<String, Object> result = Maps.newLinkedHashMap(); for (ConfigKey<?> key : sshConfig) { Maybe<Object> v = ((LocationInternal)location).config().getRaw(key); if (v.isAbsent() && mgmtConfig!=null) v = Maybe.of( (Object) mgmtConfig.getConfig(key) ); result.put(ConfigUtils.unprefixedKey(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, key).getName(), v.get()); } return result; }