Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/864#discussion_r145348576
--- Diff: core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
---
@@ -302,305 +292,190 @@ public static boolean isTrivial(Object v) {
return Sanitizer.sanitize(input);
}
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Iterable<? extends Entity> entities) {
- for (Entity e : entities) {
- dumpInfo(e);
- }
+ Dumper.dumpInfo(entities);
}
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Entity e) {
- try {
- dumpInfo(e, new PrintWriter(System.out), "", " ");
- } catch (IOException exc) {
- // system.out throwing an exception is odd, so don't have
IOException on signature
- throw new RuntimeException(exc);
- }
+ Dumper.dumpInfo(e);
}
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Entity e, Writer out) throws IOException {
- dumpInfo(e, out, "", " ");
+ Dumper.dumpInfo(e, out);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Entity e, String currentIndentation,
String tab) throws IOException {
- dumpInfo(e, new PrintWriter(System.out), currentIndentation, tab);
+ Dumper.dumpInfo(e, currentIndentation, tab);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Entity e, Writer out, String
currentIndentation, String tab) throws IOException {
- out.append(currentIndentation+e.toString()+" "+e.getId()+"\n");
-
- out.append(currentIndentation+tab+tab+"displayName =
"+e.getDisplayName()+"\n");
- if (Strings.isNonBlank(e.getCatalogItemId())) {
- out.append(currentIndentation+tab+tab+"catalogItemId =
"+e.getCatalogItemId()+"\n");
- }
- final List<String> searchPath = e.getCatalogItemIdSearchPath();
- if (!searchPath.isEmpty()) {
- out.append(currentIndentation + tab + tab + "searchPath = [");
- for (int i = 0 ; i < searchPath.size() ; i++) {
- out.append(i > 0 ? ",\n" : "\n");
- out.append(currentIndentation + tab + tab +
searchPath.get(i));
- }
- out.append("\n" + currentIndentation + tab + tab + "]");
- }
-
- out.append(currentIndentation+tab+tab+"locations =
"+e.getLocations()+"\n");
-
- Set<ConfigKey<?>> keys = Sets.newLinkedHashSet(
-
((EntityInternal)e).config().getLocalBag().getAllConfigAsConfigKeyMap().keySet()
- //((EntityInternal)e).getConfigMap().getLocalConfig().keySet()
- );
- for (ConfigKey<?> it : sortConfigKeys(keys)) {
- // use the official config key declared on the type if
available
- // (since the map sometimes contains <object> keys
- ConfigKey<?> realKey =
e.getEntityType().getConfigKey(it.getName());
- if (realKey!=null) it = realKey;
-
- Maybe<Object> mv =
((EntityInternal)e).config().getLocalRaw(it);
- if (!isTrivial(mv)) {
- Object v = mv.get();
- out.append(currentIndentation+tab+tab+it.getName());
- out.append(" = ");
- if (isSecret(it.getName())) out.append("xxxxxxxx");
- else if ((v instanceof Task) && ((Task<?>)v).isDone()) {
- if (((Task<?>)v).isError()) {
- out.append("ERROR in "+v);
- } else {
- try {
- out.append(((Task<?>)v).get() + " (from
"+v+")");
- } catch (ExecutionException ee) {
- throw new IllegalStateException("task "+v+"
done and !isError, but threw exception on get", ee);
- } catch (InterruptedException ie) {
- Thread.currentThread().interrupt();
- return;
- }
- }
- } else out.append(""+v);
- out.append("\n");
- }
- }
-
- for (Sensor<?> it : sortSensors(e.getEntityType().getSensors())) {
- if (it instanceof AttributeSensor) {
- Object v = e.getAttribute((AttributeSensor<?>)it);
- if (!isTrivial(v)) {
- out.append(currentIndentation+tab+tab+it.getName());
- out.append(": ");
- if (isSecret(it.getName())) out.append("xxxxxxxx");
- else out.append(""+v);
- out.append("\n");
- }
- }
- }
-
- if (e instanceof Group) {
- StringBuilder members = new StringBuilder();
- for (Entity it : ((Group)e).getMembers()) {
- if (members.length()>0) members.append(", ");
- members.append(it.getId());
- }
- out.append(currentIndentation+tab+tab+"Members:
"+members.toString()+"\n");
- }
-
- if (!e.policies().isEmpty()) {
- out.append(currentIndentation+tab+tab+"Policies:\n");
- for (Policy policy : e.policies()) {
- dumpInfo(policy, out, currentIndentation+tab+tab+tab, tab);
- }
- }
-
- if (!e.enrichers().isEmpty()) {
- out.append(currentIndentation+tab+tab+"Enrichers:\n");
- for (Enricher enricher : e.enrichers()) {
- dumpInfo(enricher, out, currentIndentation+tab+tab+tab,
tab);
- }
- }
-
- if (!((EntityInternal)e).feeds().getFeeds().isEmpty()) {
- out.append(currentIndentation+tab+tab+"Feeds:\n");
- for (Feed feed : ((EntityInternal)e).feeds().getFeeds()) {
- dumpInfo(feed, out, currentIndentation+tab+tab+tab, tab);
- }
- }
-
- for (Entity it : e.getChildren()) {
- dumpInfo(it, out, currentIndentation+tab, tab);
- }
-
- out.flush();
+ Dumper.dumpInfo(e, out, currentIndentation, tab);
}
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Location loc) {
- try {
- dumpInfo(loc, new PrintWriter(System.out), "", " ");
- } catch (IOException exc) {
- // system.out throwing an exception is odd, so don't have
IOException on signature
- throw new RuntimeException(exc);
- }
+ Dumper.dumpInfo(loc);
}
+
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Location loc, Writer out) throws
IOException {
- dumpInfo(loc, out, "", " ");
+ Dumper.dumpInfo(loc, out);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Location loc, String currentIndentation,
String tab) throws IOException {
- dumpInfo(loc, new PrintWriter(System.out), currentIndentation,
tab);
+ Dumper.dumpInfo(loc, currentIndentation, tab);
}
- @SuppressWarnings("rawtypes")
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Location loc, Writer out, String
currentIndentation, String tab) throws IOException {
- out.append(currentIndentation+loc.toString()+"\n");
-
- for (Object entryO :
((LocationInternal)loc).config().getBag().getAllConfig().entrySet()) {
- Map.Entry entry = (Map.Entry)entryO;
- Object keyO = entry.getKey();
- String key =
- keyO instanceof HasConfigKey ?
((HasConfigKey)keyO).getConfigKey().getName() :
- keyO instanceof ConfigKey ?
((ConfigKey)keyO).getName() :
- keyO == null ? null :
- keyO.toString();
- Object val = entry.getValue();
- if (!isTrivial(val)) {
- out.append(currentIndentation+tab+tab+key);
- out.append(" = ");
- if (isSecret(key)) out.append("xxxxxxxx");
- else out.append(""+val);
- out.append("\n");
- }
- }
-
- for (Map.Entry<String,?> entry :
sortMap(FlagUtils.getFieldsWithFlags(loc)).entrySet()) {
- String key = entry.getKey();
- Object val = entry.getValue();
- if (!isTrivial(val)) {
- out.append(currentIndentation+tab+tab+key);
- out.append(" = ");
- if (isSecret(key)) out.append("xxxxxxxx");
- else out.append(""+val);
- out.append("\n");
- }
- }
-
- for (Location it : loc.getChildren()) {
- dumpInfo(it, out, currentIndentation+tab, tab);
- }
-
- out.flush();
+ Dumper.dumpInfo(loc, out, currentIndentation, tab);
}
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Task<?> t) {
- Tasks.dumpInfo(t);
+ Dumper.dumpInfo(t);
}
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Enricher enr) {
- try {
- dumpInfo(enr, new PrintWriter(System.out), "", " ");
- } catch (IOException exc) {
- // system.out throwing an exception is odd, so don't have
IOException on signature
- throw new RuntimeException(exc);
- }
+ Dumper.dumpInfo(enr);
}
+
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Enricher enr, Writer out) throws
IOException {
- dumpInfo(enr, out, "", " ");
+ Dumper.dumpInfo(enr, out);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Enricher enr, String currentIndentation,
String tab) throws IOException {
- dumpInfo(enr, new PrintWriter(System.out), currentIndentation,
tab);
+ Dumper.dumpInfo(enr, currentIndentation, tab);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Enricher enr, Writer out, String
currentIndentation, String tab) throws IOException {
- out.append(currentIndentation+enr.toString()+"\n");
-
- for (ConfigKey<?> key :
sortConfigKeys(enr.getEnricherType().getConfigKeys())) {
- Maybe<Object> val =
((BrooklynObjectInternal)enr).config().getRaw(key);
- if (!isTrivial(val)) {
- out.append(currentIndentation+tab+tab+key);
- out.append(" = ");
- if (isSecret(key.getName())) out.append("xxxxxxxx");
- else out.append(""+val.get());
- out.append("\n");
- }
- }
-
- out.flush();
+ Dumper.dumpInfo(enr, out, currentIndentation, tab);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Feed feed, String currentIndentation,
String tab) throws IOException {
- dumpInfo(feed, new PrintWriter(System.out), currentIndentation,
tab);
+ Dumper.dumpInfo(feed, currentIndentation, tab);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Feed feed, Writer out, String
currentIndentation, String tab) throws IOException {
- out.append(currentIndentation+feed.toString()+"\n");
-
- // TODO create a FeedType cf EnricherType ?
- for (ConfigKey<?> key :
sortConfigKeys(((BrooklynObjectInternal)feed).config().getBag().getAllConfigAsConfigKeyMap().keySet()))
{
- Maybe<Object> val =
((BrooklynObjectInternal)feed).config().getRaw(key);
- if (!isTrivial(val)) {
- out.append(currentIndentation+tab+tab+key);
- out.append(" = ");
- if (isSecret(key.getName())) out.append("xxxxxxxx");
- else out.append(""+val.get());
- out.append("\n");
- }
- }
-
- out.flush();
+ Dumper.dumpInfo(feed, out, currentIndentation, tab);
}
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Policy pol) {
- try {
- dumpInfo(pol, new PrintWriter(System.out), "", " ");
- } catch (IOException exc) {
- // system.out throwing an exception is odd, so don't have
IOException on signature
- throw new RuntimeException(exc);
- }
+ Dumper.dumpInfo(pol);
}
+
+ /**
+ * @deprecated since 1.0.0; instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Policy pol, Writer out) throws IOException
{
- dumpInfo(pol, out, "", " ");
+ Dumper.dumpInfo(pol, out);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Policy pol, String currentIndentation,
String tab) throws IOException {
- dumpInfo(pol, new PrintWriter(System.out), currentIndentation,
tab);
+ Dumper.dumpInfo(pol, currentIndentation, tab);
}
+
+ /**
+ * @deprecated since 1.0.0; such fine-grained customization will be
removed from API, instead use {@link Dumper} methods
+ */
+ @Deprecated
public static void dumpInfo(Policy pol, Writer out, String
currentIndentation, String tab) throws IOException {
- out.append(currentIndentation+pol.toString()+"\n");
-
- for (ConfigKey<?> key :
sortConfigKeys(pol.getPolicyType().getConfigKeys())) {
- Maybe<Object> val =
((BrooklynObjectInternal)pol).config().getRaw(key);
- if (!isTrivial(val)) {
- out.append(currentIndentation+tab+tab+key);
- out.append(" = ");
- if (isSecret(key.getName())) out.append("xxxxxxxx");
- else out.append(""+val.get());
- out.append("\n");
- }
- }
-
- out.flush();
+ Dumper.dumpInfo(pol, out, currentIndentation, tab);
}
- @SuppressWarnings({ "rawtypes", "unchecked" })
+ /**
+ * Sorts the sensors into alphabetical order by name.
+ * @deprecated since 1.0.0; viewed as unnecessary in the API, will be
removed
+ */
+ @Deprecated
public static List<Sensor<?>> sortSensors(Set<Sensor<?>> sensors) {
- List result = new ArrayList(sensors);
- Collections.sort(result, new Comparator<Sensor>() {
- @Override
- public int compare(Sensor arg0, Sensor arg1) {
- return arg0.getName().compareTo(arg1.getName());
- }
-
- });
- return result;
+ return Dumper.sortSensors(sensors);
}
- @SuppressWarnings({ "rawtypes", "unchecked" })
+ /**
+ * Sorts the sensors into alphabetical order by name.
+ * @deprecated since 1.0.0; viewed as unnecessary in the API, will be
removed
+ */
+ @Deprecated
public static List<ConfigKey<?>> sortConfigKeys(Set<ConfigKey<?>>
configs) {
- List result = new ArrayList(configs);
- Collections.sort(result, new Comparator<ConfigKey>() {
- @Override
- public int compare(ConfigKey arg0, ConfigKey arg1) {
- return arg0.getName().compareTo(arg1.getName());
- }
-
- });
- return result;
+ return Dumper.sortConfigKeys(configs);
}
+ /**
+ * Sorts the sensors into alphabetical order by name.
+ * @deprecated since 1.0.0; viewed as unnecessary in the API, will be
removed
+ */
+ @Deprecated
public static <T> Map<String, T> sortMap(Map<String, T> map) {
- Map<String,T> result = Maps.newLinkedHashMap();
- List<String> order = Lists.newArrayList(map.keySet());
- Collections.sort(order, String.CASE_INSENSITIVE_ORDER);
-
- for (String key : order) {
- result.put(key, map.get(key));
- }
- return result;
+ return Dumper.sortMap(map);
--- End diff --
Same as above
---