Repository: brooklyn-server Updated Branches: refs/heads/master b9a657258 -> 05d6ee096
Move Entities.dumpInfo() methods to Dumper class Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b7afb934 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b7afb934 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b7afb934 Branch: refs/heads/master Commit: b7afb93411e42c8cf821515f9a14440cd741f916 Parents: b9a6572 Author: Aled Sage <[email protected]> Authored: Mon Oct 9 09:51:46 2017 +0100 Committer: Aled Sage <[email protected]> Committed: Thu Oct 19 10:03:37 2017 +0100 ---------------------------------------------------------------------- .../org/apache/brooklyn/core/entity/Dumper.java | 376 ++++++++++++++++++ .../apache/brooklyn/core/entity/Entities.java | 387 +++++++------------ 2 files changed, 507 insertions(+), 256 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b7afb934/core/src/main/java/org/apache/brooklyn/core/entity/Dumper.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Dumper.java b/core/src/main/java/org/apache/brooklyn/core/entity/Dumper.java new file mode 100644 index 0000000..40c8909 --- /dev/null +++ b/core/src/main/java/org/apache/brooklyn/core/entity/Dumper.java @@ -0,0 +1,376 @@ +/* + * 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; + +import static org.apache.brooklyn.core.entity.Entities.isSecret; +import static org.apache.brooklyn.core.entity.Entities.isTrivial; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutionException; + +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.api.entity.Group; +import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.api.policy.Policy; +import org.apache.brooklyn.api.sensor.AttributeSensor; +import org.apache.brooklyn.api.sensor.Enricher; +import org.apache.brooklyn.api.sensor.Feed; +import org.apache.brooklyn.api.sensor.Sensor; +import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.config.ConfigKey.HasConfigKey; +import org.apache.brooklyn.core.location.internal.LocationInternal; +import org.apache.brooklyn.core.objs.BrooklynObjectInternal; +import org.apache.brooklyn.util.core.flags.FlagUtils; +import org.apache.brooklyn.util.core.task.Tasks; +import org.apache.brooklyn.util.guava.Maybe; +import org.apache.brooklyn.util.text.Strings; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +/** + * Convenience methods for dumping info about entities etc. + */ +public class Dumper { + + public static void dumpInfo(Iterable<? extends Entity> entities) { + for (Entity e : entities) { + dumpInfo(e); + } + } + + 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); + } + } + + public static void dumpInfo(Entity e, Writer out) throws IOException { + dumpInfo(e, out, "", " "); + } + + public static void dumpInfo(Entity e, String currentIndentation, String tab) throws IOException { + dumpInfo(e, new PrintWriter(System.out), currentIndentation, tab); + } + + 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(); + } + + 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); + } + } + + public static void dumpInfo(Location loc, Writer out) throws IOException { + dumpInfo(loc, out, "", " "); + } + + public static void dumpInfo(Location loc, String currentIndentation, String tab) throws IOException { + dumpInfo(loc, new PrintWriter(System.out), currentIndentation, tab); + } + + @SuppressWarnings("rawtypes") + 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(); + } + + public static void dumpInfo(Task<?> t) { + Tasks.dumpInfo(t); + } + + 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); + } + } + + public static void dumpInfo(Enricher enr, Writer out) throws IOException { + dumpInfo(enr, out, "", " "); + } + + public static void dumpInfo(Enricher enr, String currentIndentation, String tab) throws IOException { + dumpInfo(enr, new PrintWriter(System.out), currentIndentation, tab); + } + + 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(); + } + + public static void dumpInfo(Feed feed, String currentIndentation, String tab) throws IOException { + dumpInfo(feed, new PrintWriter(System.out), currentIndentation, tab); + } + + 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(); + } + + 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); + } + } + + public static void dumpInfo(Policy pol, Writer out) throws IOException { + dumpInfo(pol, out, "", " "); + } + + public static void dumpInfo(Policy pol, String currentIndentation, String tab) throws IOException { + dumpInfo(pol, new PrintWriter(System.out), currentIndentation, tab); + } + + 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(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + 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; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + 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; + } + + 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; + } +} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b7afb934/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java index 9f1853f..02ea9b3 100644 --- a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java +++ b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java @@ -22,19 +22,15 @@ import static org.apache.brooklyn.util.guava.Functionals.isSatisfied; import java.io.Closeable; import java.io.IOException; -import java.io.PrintWriter; import java.io.Writer; import java.lang.reflect.Proxy; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Stack; -import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -44,7 +40,6 @@ import org.apache.brooklyn.api.effector.Effector; import org.apache.brooklyn.api.entity.Application; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.api.entity.drivers.EntityDriver; import org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolver; import org.apache.brooklyn.api.location.Location; @@ -69,7 +64,6 @@ import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.entity.trait.StartableMethods; import org.apache.brooklyn.core.internal.BrooklynProperties; import org.apache.brooklyn.core.location.Locations; -import org.apache.brooklyn.core.location.internal.LocationInternal; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; import org.apache.brooklyn.core.mgmt.internal.BrooklynShutdownHooks; import org.apache.brooklyn.core.mgmt.internal.EffectorUtils; @@ -77,14 +71,12 @@ import org.apache.brooklyn.core.mgmt.internal.EntityManagerInternal; import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.core.mgmt.internal.NonDeploymentManagementContext; -import org.apache.brooklyn.core.objs.BrooklynObjectInternal; import org.apache.brooklyn.core.objs.proxy.EntityProxyImpl; import org.apache.brooklyn.core.sensor.DependentConfiguration; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.collections.MutableSet; import org.apache.brooklyn.util.core.ResourceUtils; import org.apache.brooklyn.util.core.config.ConfigBag; -import org.apache.brooklyn.util.core.flags.FlagUtils; import org.apache.brooklyn.util.core.task.DynamicTasks; import org.apache.brooklyn.util.core.task.ParallelTask; import org.apache.brooklyn.util.core.task.TaskTags; @@ -95,7 +87,6 @@ import org.apache.brooklyn.util.exceptions.Exceptions; import org.apache.brooklyn.util.guava.Maybe; import org.apache.brooklyn.util.repeat.Repeater; import org.apache.brooklyn.util.stream.Streams; -import org.apache.brooklyn.util.text.Strings; import org.apache.brooklyn.util.time.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -111,7 +102,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.Atomics; @@ -270,305 +260,190 @@ public class Entities { (v instanceof CharSequence&& ((CharSequence)v).length() == 0); } + /** + * @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); } /**
