You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by aledsage <gi...@git.apache.org> on 2017/10/17 17:33:49 UTC

[GitHub] brooklyn-server pull request #864: Separate dumper class

GitHub user aledsage opened a pull request:

    https://github.com/apache/brooklyn-server/pull/864

    Separate dumper class

    Move all `Entities.dumpInfo` to `Dumper`, deprecating the methods in `Entities`.
    
    Previously, `Entities` was too much of a dumping ground for lots of methods related to entities, and has become huge! We've previously moved some stuff from it, such as `sanitize` to `Sanitizer`. This PR continues that trend.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/aledsage/brooklyn-server separate-dumper-class

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/864.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #864
    
----
commit dca846e9fb197375d0485dacdcabfa483de4a93d
Author: Aled Sage <al...@gmail.com>
Date:   2017-10-09T08:51:46Z

    Move Entities.dumpInfo() methods to Dumper class

commit 42c38686304462f2049edc858b5a571991e4abd3
Author: Aled Sage <al...@gmail.com>
Date:   2017-10-09T08:55:33Z

    Dumper: change methods to package-private
    
    And fix deprecated code usage

commit f69c695a298729b3b4551139a2f51956d3c1c7c6
Author: Aled Sage <al...@gmail.com>
Date:   2017-10-17T17:33:05Z

    Use `Dumper.dumpInfo` instead of `Entities.dumpInfo`

----


---

[GitHub] brooklyn-server pull request #864: Separate dumper class

Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/864#discussion_r145357727
  
    --- 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);
    --- End diff --
    
    Fair enough


---

[GitHub] brooklyn-server pull request #864: Separate dumper class

Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/864#discussion_r145347765
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/entity/Dumper.java ---
    @@ -0,0 +1,379 @@
    +/*
    + * 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.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.config.Sanitizer;
    +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.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.
    --- End diff --
    
    This class has method to dump info not only for entities, but locations, enrichers, etc. Maybe it would be better to say:
    `Convenience methods for dumping info about BrooklynObject etc.` ?


---

[GitHub] brooklyn-server pull request #864: Separate dumper class

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/864#discussion_r145355268
  
    --- 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);
    --- End diff --
    
    It's now a package-private method of `Dumper`, used to sort the sensors when we're going to dump out the entity's details. It therefore needs to be in (or accessible from) the `Dumper` class. I don't think it should ever have been a public method (i.e. part of our sprawling api).
    
    This is a way to deprecate it from the public api.


---

[GitHub] brooklyn-server pull request #864: Separate dumper class

Posted by tbouron <gi...@git.apache.org>.
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


---

[GitHub] brooklyn-server pull request #864: Separate dumper class

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/864


---

[GitHub] brooklyn-server pull request #864: Separate dumper class

Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/864#discussion_r145348526
  
    --- 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);
    --- End diff --
    
    Same as above


---

[GitHub] brooklyn-server pull request #864: Separate dumper class

Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/864#discussion_r145348481
  
    --- 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);
    --- End diff --
    
    Should this be in the `Dumper` class? It does not seem to have a relation to dumping data


---