This is an automated email from the ASF dual-hosted git repository. jcabrerizo pushed a commit to branch activities-rest-optization in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 87f14388a7840b377bf70453848fc56498065a69 Author: Juan Cabrerizo <j...@cabrerizo.es> AuthorDate: Fri Apr 28 10:50:41 2023 +0100 refactor code --- .../rest/resources/AbstractBrooklynRestResource.java | 4 ++-- .../apache/brooklyn/rest/transform/TaskTransformer.java | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/AbstractBrooklynRestResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/AbstractBrooklynRestResource.java index dfd13370e4..0a435bf681 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/AbstractBrooklynRestResource.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/AbstractBrooklynRestResource.java @@ -266,7 +266,7 @@ public abstract class AbstractBrooklynRestResource { public static Object getValueForDisplay(ManagementContext mgmt, ObjectMapper mapper, Object value, boolean preferJson, boolean isJerseyReturnValue, Boolean suppressNestedSecrets, Boolean suppressOutput) { suppressNestedSecrets = checkAndGetSecretsSuppressed(mgmt, suppressNestedSecrets, false); - return getValueForDisplayAfterSecretsCheck(mgmt, mapper, value, preferJson, isJerseyReturnValue, suppressNestedSecrets,suppressOutput); + return getValueForDisplayAfterSecretsCheck(mgmt, mapper, value, preferJson, isJerseyReturnValue, suppressNestedSecrets, suppressOutput); } static Object getValueForDisplayAfterSecretsCheck(ManagementContext mgmt, ObjectMapper mapper, Object value, boolean preferJson, boolean isJerseyReturnValue, Boolean suppressNestedSecrets, Boolean suppressOutput) { @@ -299,7 +299,7 @@ public abstract class AbstractBrooklynRestResource { String resultS = mapper.writeValueAsString(result); result = BeanWithTypeUtils.newSimpleMapper().readValue(resultS, Object.class); if (suppressOutput){ - result = TaskTransformer.suppressWorkflowOutputs(result); + result = TaskTransformer.suppressOutputs(result); } //the below treats all numbers as doubles //new Gson().fromJson(resultS, Object.class); diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/TaskTransformer.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/TaskTransformer.java index b15d346ae0..390732fb92 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/TaskTransformer.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/TaskTransformer.java @@ -20,14 +20,12 @@ package org.apache.brooklyn.rest.transform; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.mgmt.HasTaskChildren; import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.core.config.Sanitizer; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags.WrappedStream; import org.apache.brooklyn.rest.api.ActivityApi; @@ -236,16 +234,16 @@ public class TaskTransformer { return taskTaskSummaryFunction.apply(task); }).collect(Collectors.toList()); } - public static Object suppressWorkflowOutputs(Object x) { + public static Object suppressOutputs(Object x) { if (x instanceof Map) { Map y = MutableMap.of(); ((Map)x).forEach((k,v) -> { - y.put(k, v!=null && TaskTransformer.IS_OUTPUT.apply(k) ? "(output suppressed)": suppressWorkflowOutputs(v) ); + y.put(k, v!=null && TaskTransformer.IS_OUTPUT.apply(k) ? "(output suppressed)": suppressOutputs(v) ); }); return y; }else if (x instanceof Iterable){ List y = MutableList.of(); - ((Iterable)x).forEach(xi -> y.add(suppressWorkflowOutputs(xi))); + ((Iterable)x).forEach(xi -> y.add(suppressOutputs(xi))); return y; }else { return x; @@ -254,16 +252,12 @@ public class TaskTransformer { public static final Predicate<Object> IS_OUTPUT = new IsOutputPredicate(); + static final ImmutableList<String> OUTPUT_VALUES = ImmutableList.of("output", "stdout", "stderr"); private static class IsOutputPredicate implements Predicate<Object> { @Override public boolean apply(Object name) { if (name == null) return false; - String lowerName = name.toString().toLowerCase(); - for (String outputFieldName : ImmutableList.of("output", "stdout", "stderr")) { - if (lowerName.contains(outputFieldName)) - return true; - } - return false; + return OUTPUT_VALUES.contains(name.toString().toLowerCase()); } }