You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2024/04/09 10:55:35 UTC
(brooklyn-server) 02/04: remove deprecated config key methods
This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 0d6fa32ac7ec96e7009aff76795dbd1ee8e8109b
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Tue Apr 9 09:40:52 2024 +0100
remove deprecated config key methods
---
.../config/internal/AbstractConfigMapImpl.java | 33 +-----
.../internal/ConfigMapViewWithStringKeys.java | 132 ---------------------
.../core/entity/internal/EntityConfigMap.java | 30 +----
.../brooklyn/core/internal/BrooklynProperties.java | 2 +-
.../core/location/internal/LocationConfigMap.java | 5 -
.../objs/AbstractConfigurationSupportInternal.java | 6 +-
.../brooklyn/core/objs/AdjunctConfigMap.java | 18 +--
.../java/org/apache/brooklyn/config/ConfigMap.java | 27 +----
.../apache/brooklyn/config/StringConfigMap.java | 6 +-
9 files changed, 13 insertions(+), 246 deletions(-)
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java b/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
index 9c1f4c4c01..5d69a4bca6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
@@ -70,12 +70,7 @@ public abstract class AbstractConfigMapImpl<TContainer extends BrooklynObject> i
private static final Logger LOG = LoggerFactory.getLogger(AbstractConfigMapImpl.class);
- @Deprecated /** @deprecated since 0.10.0 - see method which uses it */
- protected final transient org.apache.brooklyn.core.entity.internal.ConfigMapViewWithStringKeys mapViewWithStringKeys = new org.apache.brooklyn.core.entity.internal.ConfigMapViewWithStringKeys(this);
-
- // TODO make final when not working with previously serialized instances
- // (we shouldn't be, but just in case!)
- protected TContainer bo;
+ protected final TContainer bo;
/**
* Map of configuration information that is defined at start-up time for the entity. These
@@ -142,27 +137,6 @@ public abstract class AbstractConfigMapImpl<TContainer extends BrooklynObject> i
}
}
- /** an immutable copy of the config visible at this entity, local and inherited (preferring local) */
- @Override @Deprecated
- public Map<ConfigKey<?>,Object> getAllConfig() {
- Map<ConfigKey<?>,Object> result = new LinkedHashMap<ConfigKey<?>,Object>();
- if (getParent()!=null)
- result.putAll( getParentInternal().config().getInternalConfigMap().getAllConfig() );
- putAllOwnConfigIntoSafely(result);
- return Collections.unmodifiableMap(result);
- }
-
- /** Creates an immutable copy of the config visible at this entity, local and inherited (preferring local), including those that did not match config keys */
- @Deprecated
- public ConfigBag getAllConfigBag() {
- ConfigBag result = putAllOwnConfigIntoSafely(ConfigBag.newInstance());
- if (getParent()!=null) {
- result.putIfAbsent(
- ((AbstractConfigMapImpl<?>)getParentInternal().config().getInternalConfigMap()).getAllConfigBag() );
- }
- return result.seal();
- }
-
/** As {@link #getAllConfigLocalRaw()} } but in a {@link ConfigBag} for convenience */
public ConfigBag getLocalConfigBag() {
return putAllOwnConfigIntoSafely(ConfigBag.newInstance()).seal();
@@ -321,11 +295,6 @@ public abstract class AbstractConfigMapImpl<TContainer extends BrooklynObject> i
return false;
}
- @Override
- public Map<String,Object> asMapWithStringKeys() {
- return mapViewWithStringKeys;
- }
-
@Override
public int size() {
return ownConfig.size();
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/internal/ConfigMapViewWithStringKeys.java b/core/src/main/java/org/apache/brooklyn/core/entity/internal/ConfigMapViewWithStringKeys.java
deleted file mode 100644
index 38f83c7347..0000000000
--- a/core/src/main/java/org/apache/brooklyn/core/entity/internal/ConfigMapViewWithStringKeys.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.entity.internal;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.ConfigMap;
-import org.apache.brooklyn.core.config.BasicConfigKey;
-
-import com.google.common.collect.Sets;
-
-/**
- * Internal class that presents a view over a ConfigMap, so it looks like a Map (with the
- * keys being the config key names).
- *
- * @deprecated since 0.10.0 removed support, no longer needed
- */
-@Deprecated
-public class ConfigMapViewWithStringKeys implements Map<String,Object> {
-
- private ConfigMap target;
-
- public ConfigMapViewWithStringKeys(ConfigMap target) {
- this.target = target;
- }
-
- @Override
- public int size() {
- return target.getAllConfig().size();
- }
-
- @Override
- public boolean isEmpty() {
- return target.getAllConfig().isEmpty();
- }
-
- @Override
- public boolean containsKey(Object key) {
- return keySet().contains(key);
- }
-
- @Override
- public boolean containsValue(Object value) {
- return values().contains(value);
- }
-
- @Override
- public Object get(Object key) {
- return target.getConfig(new BasicConfigKey<Object>(Object.class, (String)key));
- }
-
- @Override
- public Object put(String key, Object value) {
- throw new UnsupportedOperationException("This view is read-only");
- }
-
- @Override
- public Object remove(Object key) {
- throw new UnsupportedOperationException("This view is read-only");
- }
-
- @Override
- public void putAll(Map<? extends String, ? extends Object> m) {
- throw new UnsupportedOperationException("This view is read-only");
- }
-
- @Override
- public void clear() {
- throw new UnsupportedOperationException("This view is read-only");
- }
-
- @Override
- public Set<String> keySet() {
- LinkedHashSet<String> result = Sets.newLinkedHashSet();
- Set<Map.Entry<ConfigKey<?>, Object>> set = target.getAllConfig().entrySet();
- for (final Map.Entry<ConfigKey<?>, Object> entry: set) {
- result.add(entry.getKey().getName());
- }
- return result;
- }
-
- @Override
- public Collection<Object> values() {
- return target.getAllConfig().values();
- }
-
- @Override
- public Set<Map.Entry<String, Object>> entrySet() {
- LinkedHashSet<Map.Entry<String, Object>> result = Sets.newLinkedHashSet();
- Set<Map.Entry<ConfigKey<?>, Object>> set = target.getAllConfig().entrySet();
- for (final Map.Entry<ConfigKey<?>, Object> entry: set) {
- result.add(new Map.Entry<String, Object>() {
- @Override
- public String getKey() {
- return entry.getKey().getName();
- }
-
- @Override
- public Object getValue() {
- return entry.getValue();
- }
-
- @Override
- public Object setValue(Object value) {
- return entry.setValue(value);
- }
- });
- }
- return result;
- }
-
-}
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java b/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java
index cd7464a2ee..c7b5532b64 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/internal/EntityConfigMap.java
@@ -18,8 +18,6 @@
*/
package org.apache.brooklyn.core.entity.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import java.util.Map;
import java.util.Set;
@@ -30,15 +28,12 @@ import org.apache.brooklyn.api.objs.BrooklynObject;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigConstraints;
import org.apache.brooklyn.core.config.internal.AbstractConfigMapImpl;
-import org.apache.brooklyn.core.entity.AbstractEntity;
import org.apache.brooklyn.core.entity.EntityInternal;
-import org.apache.brooklyn.core.objs.BrooklynObjectInternal.ConfigurationSupportInternal;
import org.apache.brooklyn.util.guava.Maybe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Maps;
+import static com.google.common.base.Preconditions.checkNotNull;
public class EntityConfigMap extends AbstractConfigMapImpl<Entity> {
@@ -53,9 +48,6 @@ public class EntityConfigMap extends AbstractConfigMapImpl<Entity> {
super(checkNotNull(entity, "entity must be specified"), checkNotNull(storage, "storage map must be specified"));
}
- /** entity against which config resolution / task execution will occur
- * @deprecated since 0.10.0 kept for serialization */ @Deprecated
- private EntityInternal entity;
@Override
public EntityInternal getContainer() {
Entity result = super.getContainer();
@@ -64,15 +56,13 @@ public class EntityConfigMap extends AbstractConfigMapImpl<Entity> {
synchronized (this) {
result = super.getContainer();
if (result!=null) return (EntityInternal) result;
- bo = entity;
- entity = null;
}
return (EntityInternal) super.getBrooklynObject();
}
@Override
public <T> void assertValid(ConfigKey<T> key, T val) {
- ConfigConstraints.assertValid((Entity) getContainer(), key, val);
+ ConfigConstraints.assertValid(getContainer(), key, val);
}
protected EntityInternal getEntity() {
@@ -117,22 +107,6 @@ public class EntityConfigMap extends AbstractConfigMapImpl<Entity> {
return container.getEntityType().getConfigKeys();
}
- @Override @Deprecated
- public EntityConfigMap submap(Predicate<ConfigKey<?>> filter) {
- EntityConfigMap m = new EntityConfigMap(getEntity(), Maps.<ConfigKey<?>, Object>newLinkedHashMap());
- synchronized (ownConfig) {
- for (Map.Entry<ConfigKey<?>,Object> entry: ownConfig.entrySet()) {
- if (filter.apply(entry.getKey())) {
- m.ownConfig.put(entry.getKey(), entry.getValue());
- }
- }
- }
- if (getEntity().getParent()!=null) {
- merge(m, ((EntityConfigMap) ((ConfigurationSupportInternal)getEntity().getParent().config()).getInternalConfigMap()).submap(filter));
- }
- return m;
- }
-
@Deprecated
private void merge(EntityConfigMap local, EntityConfigMap parent) {
for (ConfigKey<?> k: parent.ownConfig.keySet()) {
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java
index 0126e238cf..aa36f3f2f7 100644
--- a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynProperties.java
@@ -332,7 +332,7 @@ public interface BrooklynProperties extends StringConfigMap {
@Override
public Maybe<Object> getConfigRaw(ConfigKey<?> key, boolean includeInherited);
- @Override @Deprecated
+ @Deprecated
public Map<ConfigKey<?>, Object> getAllConfig();
@Override
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationConfigMap.java b/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationConfigMap.java
index cc75230ac7..afea45804a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationConfigMap.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/internal/LocationConfigMap.java
@@ -90,11 +90,6 @@ public class LocationConfigMap extends AbstractConfigMapImpl<Location> {
/* nothing needed */
}
- @Override
- public LocationConfigMap submap(Predicate<ConfigKey<?>> filter) {
- throw new UnsupportedOperationException("Location does not support submap");
- }
-
@Override
protected <T> Object coerceConfigValAndValidate(ConfigKey<T> key, Object v, boolean validate) {
if ((Class.class.isAssignableFrom(key.getType()) || Function.class.isAssignableFrom(key.getType())) && v instanceof String) {
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractConfigurationSupportInternal.java b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractConfigurationSupportInternal.java
index ff56c293fe..0391458f21 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractConfigurationSupportInternal.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractConfigurationSupportInternal.java
@@ -274,7 +274,11 @@ public abstract class AbstractConfigurationSupportInternal implements BrooklynOb
@Override
// see super; we aspire to depreate this due to poor treatment of inheritance
public ConfigBag getBag() {
- return getConfigsInternal().getAllConfigBag();
+ ConfigBag result = ConfigBag.newInstance();
+ AbstractConfigMapImpl<? extends BrooklynObject> ci = getConfigsInternal();
+ ci.findKeysPresent(x -> true).forEach(k ->
+ result.put((ConfigKey)k, ci.getConfigRaw(k, true).or(k.getDefaultValue()) ) );
+ return result;
}
/**
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AdjunctConfigMap.java b/core/src/main/java/org/apache/brooklyn/core/objs/AdjunctConfigMap.java
index 8c92db8225..412d184ceb 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AdjunctConfigMap.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AdjunctConfigMap.java
@@ -18,24 +18,19 @@
*/
package org.apache.brooklyn.core.objs;
-import java.util.Map;
import java.util.Set;
-import org.apache.brooklyn.api.entity.Entity;
+import com.google.common.base.Preconditions;
import org.apache.brooklyn.api.mgmt.ExecutionContext;
import org.apache.brooklyn.api.objs.BrooklynObject;
import org.apache.brooklyn.api.objs.EntityAdjunct;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigConstraints;
import org.apache.brooklyn.core.config.internal.AbstractConfigMapImpl;
-import org.apache.brooklyn.core.entity.EntityInternal;
import org.apache.brooklyn.util.guava.Maybe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-
public class AdjunctConfigMap extends AbstractConfigMapImpl<EntityAdjunct> {
@SuppressWarnings("unused")
@@ -56,8 +51,6 @@ public class AdjunctConfigMap extends AbstractConfigMapImpl<EntityAdjunct> {
synchronized (this) {
result = super.getContainer();
if (result!=null) return result;
- bo = adjunct;
- adjunct = null;
}
return super.getContainer();
}
@@ -78,15 +71,6 @@ public class AdjunctConfigMap extends AbstractConfigMapImpl<EntityAdjunct> {
return ((AbstractEntityAdjunct)bo).getExecutionContext();
}
- @Override
- public AdjunctConfigMap submap(Predicate<ConfigKey<?>> filter) {
- AdjunctConfigMap m = new AdjunctConfigMap((AbstractEntityAdjunct)getContainer());
- for (Map.Entry<ConfigKey<?>,Object> entry: ownConfig.entrySet())
- if (filter.apply(entry.getKey()))
- m.ownConfig.put(entry.getKey(), entry.getValue());
- return m;
- }
-
@Override
protected EntityAdjunct getParentOfContainer(EntityAdjunct container) {
return null;
diff --git a/utils/common/src/main/java/org/apache/brooklyn/config/ConfigMap.java b/utils/common/src/main/java/org/apache/brooklyn/config/ConfigMap.java
index 45f00424c8..2045c690c4 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/config/ConfigMap.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/config/ConfigMap.java
@@ -63,23 +63,7 @@ public interface ConfigMap {
/** returns a read-only map of all local config keys with their raw (unresolved+uncoerced) contents */
public Map<ConfigKey<?>,Object> getAllConfigLocalRaw();
-
- /** returns a map of all config keys to their raw (unresolved+uncoerced) contents
- *
- * @deprecated since 0.10.0 in favour of {@link #getAllConfigLocalRaw()} for local
- * and {@link ConfigMapWithInheritance} methods for inherited;
- * kept on some sub-interfaces (eg Brooklyn properties) */
- @Deprecated // and confirmed no uses (besides sub-interface)
- public Map<ConfigKey<?>,Object> getAllConfig();
- /** returns submap matching the given filter predicate; see ConfigPredicates for common predicates
- * @deprecated since 0.10.0 use {@link #findKeys(Predicate)} then do whatever is desired for the values;
- * kept on {@link StringConfigMap} */
- @Deprecated // and confirmed no uses (besides sub-interface)
- // deprecated because this becomes irritating to implement in a hierarchical world, it requires caching the predicate;
- // also it encourages subsequent calls to deprecated methods such as #getAllConfig
- public ConfigMap submap(Predicate<ConfigKey<?>> filter);
-
/** @deprecated since 0.11.0 use {@link #findKeysDeclared(Predicate)} or {@link #findKeysPresent(Predicate)}
* <p>
* this method is like the above but it does not compare against reference keys in the container / type context.
@@ -87,6 +71,7 @@ public interface ConfigMap {
* one of the above other two methods. if keys in the map are needed and not the reference keys,
* let the brooklyn developers know to keep this functionality! */
@Deprecated
+ // XXX
public Set<ConfigKey<?>> findKeys(Predicate<? super ConfigKey<?>> filter);
/** returns all keys present in the map matching the given filter predicate; see ConfigPredicates for common predicates.
@@ -103,16 +88,6 @@ public interface ConfigMap {
// TODO should include structured config keys if they have a sub element config present
public Set<ConfigKey<?>> findKeysPresent(Predicate<? super ConfigKey<?>> filter);
- /** returns a read-only map view which has string keys (corresponding to the config key names);
- * callers encouraged to use the typed keys (and so not use this method),
- * but in some compatibility areas having a Properties-like view is useful
- *
- * @deprecated since 0.10.0 use the corresponding methods to return {@link ConfigKey}-based maps,
- * then pass to a ConfigBag to get a string-map view; kept for {@link StringConfigMap}
- */
- @Deprecated // and confirmed no uses (besides sub-interface)
- public Map<String,Object> asMapWithStringKeys();
-
public int size();
public boolean isEmpty();
diff --git a/utils/common/src/main/java/org/apache/brooklyn/config/StringConfigMap.java b/utils/common/src/main/java/org/apache/brooklyn/config/StringConfigMap.java
index 6b68caf078..57d9a17ccd 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/config/StringConfigMap.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/config/StringConfigMap.java
@@ -34,14 +34,12 @@ public interface StringConfigMap extends ConfigMap {
* and 'defaultIfNone' (a default value to return if there is no such property);
* defaults to no warning and null default value */
public String getFirst(@SuppressWarnings("rawtypes") Map flags, String... keys);
-
+
/** returns submap matching the given filter predicate; see ConfigPredicates for common predicates */
- @Override
public StringConfigMap submap(Predicate<ConfigKey<?>> filter);
-
+
/** returns a read-only map view which has string keys (corresponding to the config key names);
* callers encouraged to use the typed keys (and so not use this method),
* but in some compatibility areas having a Properties-like view is useful */
- @Override
public Map<String,Object> asMapWithStringKeys();
}