From 6f5bfed58243921705b44c63494c4f010ca1c54a Mon Sep 17 00:00:00 2001 From: David Legg Date: Wed, 10 Jul 2024 13:07:21 -0700 Subject: [PATCH 1/4] Add streamline Logger Adds a Logger class to the streamline framework, which uses topics to emit log messages directly as events. Also builds such a Logger when the Registrar is initialized, and reconfigures errors to go to that logger when the error behavior is set to LOG. Before this, errors were collected awkwardly into a discrete string resource. --- .../contrib/streamline/debugging/Logger.java | 60 +++++++++++++++++++ .../streamline/debugging/SimpleLogger.java | 51 ++++++++++++++++ .../streamline/modeling/Registrar.java | 47 ++++++--------- .../jpl/aerie/streamline_demo/Mission.java | 6 +- 4 files changed, 132 insertions(+), 32 deletions(-) create mode 100644 contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logger.java create mode 100644 contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/SimpleLogger.java diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logger.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logger.java new file mode 100644 index 0000000000..9935d687d7 --- /dev/null +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logger.java @@ -0,0 +1,60 @@ +package gov.nasa.jpl.aerie.contrib.streamline.debugging; + +import gov.nasa.jpl.aerie.contrib.streamline.core.Resources; +import gov.nasa.jpl.aerie.merlin.framework.Registrar; + +import java.time.Instant; +import java.util.Arrays; +import java.util.Map; + +import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MICROSECONDS; +import static java.util.stream.Collectors.toMap; + +public class Logger { + private static final int LEVEL_INDICATOR_SIZE = Arrays.stream(LogLevel.values()) + .map(v -> v.toString().length()) + .max(Integer::compareTo) + .orElseThrow(); + private static final String LOG_MESSAGE_FORMAT = "%s [%-" + LEVEL_INDICATOR_SIZE + "s] %s"; + + private final Map subLoggers; + private final Instant planStart; + + public Logger(Registrar registrar, Instant planStart) { + // TODO - refactor the plan start out, by instead building a global sim clock to do the same job. + // To do that "right", the global clock should be a resource with custom dynamics for continuous Instant clocks. + subLoggers = Arrays.stream(LogLevel.values()).collect(toMap( + level -> level, + level -> new SimpleLogger(level.name(), registrar))); + this.planStart = planStart; + } + + public void log(LogLevel level, String messageFormat, Object... args) { + Instant time = planStart.plusNanos(Resources.currentTime().in(MICROSECONDS) * 1_000); + String message = messageFormat.formatted(args); + subLoggers.get(level).log(LOG_MESSAGE_FORMAT.formatted(time, level, message)); + } + + public void debug(String messageFormat, Object... args) { + log(LogLevel.DEBUG, messageFormat, args); + } + + public void info(String messageFormat, Object... args) { + log(LogLevel.INFO, messageFormat, args); + } + + public void warning(String messageFormat, Object... args) { + log(LogLevel.WARNING, messageFormat, args); + } + + public void error(String messageFormat, Object... args) { + log(LogLevel.ERROR, messageFormat, args); + } + + public enum LogLevel { + DEBUG, + INFO, + WARNING, + ERROR + } +} diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/SimpleLogger.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/SimpleLogger.java new file mode 100644 index 0000000000..7ad64cc789 --- /dev/null +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/SimpleLogger.java @@ -0,0 +1,51 @@ +package gov.nasa.jpl.aerie.contrib.streamline.debugging; + +import gov.nasa.jpl.aerie.merlin.framework.CellRef; +import gov.nasa.jpl.aerie.merlin.framework.Registrar; +import gov.nasa.jpl.aerie.merlin.protocol.model.CellType; +import gov.nasa.jpl.aerie.merlin.protocol.model.EffectTrait; +import gov.nasa.jpl.aerie.merlin.protocol.types.Unit; + +import static gov.nasa.jpl.aerie.contrib.serialization.rulesets.BasicValueMappers.string; +import static gov.nasa.jpl.aerie.merlin.protocol.types.Unit.UNIT; + +public class SimpleLogger { + private final CellRef cellRef = CellRef.allocate(UNIT, new CellType<>() { + @Override + public EffectTrait getEffectType() { + return new EffectTrait<>() { + @Override + public String empty() { + return null; + } + + @Override + public String sequentially(String prefix, String suffix) { + return null; + } + + @Override + public String concurrently(String left, String right) { + return null; + } + }; + } + + @Override + public Unit duplicate(Unit unit) { + return unit; + } + + @Override + public void apply(Unit unit, String s) { + } + }); + + public SimpleLogger(String name, Registrar registrar) { + registrar.topic(name, cellRef, string()); + } + + public void log(String message) { + cellRef.emit(message); + } +} diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java index 124eb56d5c..b0591e58aa 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java @@ -2,12 +2,12 @@ import gov.nasa.jpl.aerie.contrib.serialization.mappers.IntegerValueMapper; import gov.nasa.jpl.aerie.contrib.serialization.mappers.NullableValueMapper; -import gov.nasa.jpl.aerie.contrib.serialization.mappers.StringValueMapper; import gov.nasa.jpl.aerie.contrib.streamline.core.MutableResource; import gov.nasa.jpl.aerie.contrib.streamline.core.Dynamics; import gov.nasa.jpl.aerie.contrib.streamline.core.Resource; import gov.nasa.jpl.aerie.contrib.streamline.core.Resources; import gov.nasa.jpl.aerie.contrib.streamline.core.monads.ThinResourceMonad; +import gov.nasa.jpl.aerie.contrib.streamline.debugging.Logger; import gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.Discrete; import gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.monads.DiscreteResourceMonad; import gov.nasa.jpl.aerie.contrib.streamline.modeling.linear.Linear; @@ -16,11 +16,8 @@ import gov.nasa.jpl.aerie.merlin.protocol.types.Unit; import org.apache.commons.lang3.exception.ExceptionUtils; +import java.time.Instant; import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; import static gov.nasa.jpl.aerie.contrib.streamline.core.MutableResource.resource; import static gov.nasa.jpl.aerie.contrib.streamline.core.Reactions.whenever; @@ -30,9 +27,8 @@ import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Profiling.profile; import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Tracing.trace; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.Registrar.ErrorBehavior.*; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.not; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.when; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.monads.DiscreteDynamicsMonad.effect; +import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteEffects.increment; +import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.*; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.monads.DiscreteResourceMonad.map; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.linear.Linear.linear; import static gov.nasa.jpl.aerie.merlin.framework.ModelActions.waitUntil; @@ -49,8 +45,8 @@ public class Registrar { private final gov.nasa.jpl.aerie.merlin.framework.Registrar baseRegistrar; private boolean trace = false; private boolean profile = false; - private final MutableResource>>> errors; private final ErrorBehavior errorBehavior; + private final MutableResource> numberOfErrors = discreteResource(0); public enum ErrorBehavior { /** @@ -64,17 +60,20 @@ public enum ErrorBehavior { Throw } - public Registrar(final gov.nasa.jpl.aerie.merlin.framework.Registrar baseRegistrar, final ErrorBehavior errorBehavior) { + /** + * The "main" logger. Unless you have a compelling reason to direct logging somewhere else, + * this logger should be used by virtually all model components. + * This logger will be initialized automatically when a registrar is constructed. + */ + public static Logger LOGGER; + + public Registrar(final gov.nasa.jpl.aerie.merlin.framework.Registrar baseRegistrar, final Instant planStart, final ErrorBehavior errorBehavior) { Resources.init(); + LOGGER = new Logger(baseRegistrar, planStart); this.baseRegistrar = baseRegistrar; this.errorBehavior = errorBehavior; - errors = resource(Discrete.discrete(Map.of())); - var errorString = map(errors, errors$ -> errors$.entrySet().stream().map(entry -> formatError(entry.getKey(), entry.getValue())).collect(joining("\n\n"))); - // Register the errors and number of errors resources for output - // TODO consider using serializable events, rather than resources, to log errors - discrete("errors", errorString, new StringValueMapper()); - discrete("numberOfErrors", map(errors, Map::size), new IntegerValueMapper()); + discrete("numberOfErrors", numberOfErrors, new IntegerValueMapper()); } private static String formatError(Throwable e, Collection affectedResources) { @@ -148,21 +147,9 @@ private > void logErrors(String name, Resource resou }); } - // TODO: Consider using a MultiMap instead of doing this by hand below private Unit logError(String resourceName, Throwable e) { - errors.emit(effect(s -> { - var s$ = new HashMap<>(s); - s$.compute(e, (e$, affectedResources) -> { - if (affectedResources == null) { - return Set.of(resourceName); - } else { - var affectedResources$ = new HashSet<>(affectedResources); - affectedResources$.add(resourceName); - return affectedResources$; - } - }); - return s$; - })); + LOGGER.error("Error affecting %s: %s", resourceName, e); + increment(numberOfErrors); return Unit.UNIT; } diff --git a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/Mission.java b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/Mission.java index ece739efba..7168516eca 100644 --- a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/Mission.java +++ b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/Mission.java @@ -5,13 +5,15 @@ import gov.nasa.jpl.aerie.contrib.streamline.modeling.Registrar; import gov.nasa.jpl.aerie.merlin.framework.ModelActions; +import java.time.Instant; + public final class Mission { public final DataModel dataModel; public final ErrorTestingModel errorTestingModel; public final ApproximationModel approximationModel; - public Mission(final gov.nasa.jpl.aerie.merlin.framework.Registrar registrar$, final Configuration config) { - var registrar = new Registrar(registrar$, Registrar.ErrorBehavior.Log); + public Mission(final gov.nasa.jpl.aerie.merlin.framework.Registrar registrar$, final Instant planStart, final Configuration config) { + var registrar = new Registrar(registrar$, planStart, Registrar.ErrorBehavior.Log); if (config.traceResources) registrar.setTrace(); if (config.profileResources) Resource.profileAllResources(); dataModel = new DataModel(registrar, config); From b18eb06704d59387009bfe6f28e9d68fef0b8205 Mon Sep 17 00:00:00 2001 From: David Legg Date: Wed, 10 Jul 2024 15:49:32 -0700 Subject: [PATCH 2/4] Move primary logger to Logging Move the primary Logger instance to a separate class, out of Registrar. This makes more sense logically, as Logging only incidentally depends on the Registrar, in the sense that creating the Registrar is a natural place to initialize all of the singletons. It also makes the logger easier to find (I hope). --- .../contrib/streamline/debugging/Logging.java | 29 +++++++++++++++++++ .../streamline/modeling/Registrar.java | 16 +++------- 2 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logging.java diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logging.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logging.java new file mode 100644 index 0000000000..1dfa625118 --- /dev/null +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logging.java @@ -0,0 +1,29 @@ +package gov.nasa.jpl.aerie.contrib.streamline.debugging; + +import gov.nasa.jpl.aerie.merlin.framework.Registrar; + +import java.time.Instant; + +public final class Logging { + private Logging() {} + + /** + * The "main" logger. Unless you have a compelling reason to direct logging somewhere else, + * this logger should be used by virtually all model components. + * This logger will be initialized automatically when a registrar is constructed. + */ + public static Logger LOGGER; + + /** + * Initialize the primary logger. + * This is called when constructing a {@link gov.nasa.jpl.aerie.contrib.streamline.modeling.Registrar}, + * and does not need to be called directly by the model. + */ + public static void init(final Registrar registrar, final Instant planStart) { + if (LOGGER == null) { + LOGGER = new Logger(registrar, planStart); + } else { + LOGGER.warning("Attempting to re-initialize primary logger. This attempt is being ignored."); + } + } +} diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java index b0591e58aa..c8b43df896 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java @@ -7,7 +7,7 @@ import gov.nasa.jpl.aerie.contrib.streamline.core.Resource; import gov.nasa.jpl.aerie.contrib.streamline.core.Resources; import gov.nasa.jpl.aerie.contrib.streamline.core.monads.ThinResourceMonad; -import gov.nasa.jpl.aerie.contrib.streamline.debugging.Logger; +import gov.nasa.jpl.aerie.contrib.streamline.debugging.Logging; import gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.Discrete; import gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.monads.DiscreteResourceMonad; import gov.nasa.jpl.aerie.contrib.streamline.modeling.linear.Linear; @@ -19,17 +19,16 @@ import java.time.Instant; import java.util.Collection; -import static gov.nasa.jpl.aerie.contrib.streamline.core.MutableResource.resource; import static gov.nasa.jpl.aerie.contrib.streamline.core.Reactions.whenever; import static gov.nasa.jpl.aerie.contrib.streamline.core.Resources.currentData; import static gov.nasa.jpl.aerie.contrib.streamline.core.Resources.currentValue; +import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Logging.LOGGER; import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Naming.*; import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Profiling.profile; import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Tracing.trace; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.Registrar.ErrorBehavior.*; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteEffects.increment; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.*; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.monads.DiscreteResourceMonad.map; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.linear.Linear.linear; import static gov.nasa.jpl.aerie.merlin.framework.ModelActions.waitUntil; import static java.util.stream.Collectors.joining; @@ -50,7 +49,7 @@ public class Registrar { public enum ErrorBehavior { /** - * Log errors to the error state, + * Log errors to {@link Logging#LOGGER} * and replace resource value with null. */ Log, @@ -60,16 +59,9 @@ public enum ErrorBehavior { Throw } - /** - * The "main" logger. Unless you have a compelling reason to direct logging somewhere else, - * this logger should be used by virtually all model components. - * This logger will be initialized automatically when a registrar is constructed. - */ - public static Logger LOGGER; - public Registrar(final gov.nasa.jpl.aerie.merlin.framework.Registrar baseRegistrar, final Instant planStart, final ErrorBehavior errorBehavior) { Resources.init(); - LOGGER = new Logger(baseRegistrar, planStart); + Logging.init(baseRegistrar, planStart); this.baseRegistrar = baseRegistrar; this.errorBehavior = errorBehavior; From 63f0f03617372c44c9f7c67bd6525b19fc6e29b6 Mon Sep 17 00:00:00 2001 From: Matthew Dailis Date: Tue, 6 Aug 2024 08:48:06 -0700 Subject: [PATCH 3/4] Use UNIT to implement no-op effects --- .../streamline/debugging/SimpleLogger.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/SimpleLogger.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/SimpleLogger.java index 7ad64cc789..1dc4e68a99 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/SimpleLogger.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/SimpleLogger.java @@ -12,21 +12,21 @@ public class SimpleLogger { private final CellRef cellRef = CellRef.allocate(UNIT, new CellType<>() { @Override - public EffectTrait getEffectType() { + public EffectTrait getEffectType() { return new EffectTrait<>() { @Override - public String empty() { - return null; + public Unit empty() { + return UNIT; } @Override - public String sequentially(String prefix, String suffix) { - return null; + public Unit sequentially(Unit prefix, Unit suffix) { + return UNIT; } @Override - public String concurrently(String left, String right) { - return null; + public Unit concurrently(Unit left, Unit right) { + return UNIT; } }; } @@ -37,9 +37,9 @@ public Unit duplicate(Unit unit) { } @Override - public void apply(Unit unit, String s) { + public void apply(Unit unit, Unit s) { } - }); + }, $ -> UNIT); public SimpleLogger(String name, Registrar registrar) { registrar.topic(name, cellRef, string()); From f4ddb29e1f829cee820e407a04e4aae5cc724911 Mon Sep 17 00:00:00 2001 From: David Legg Date: Thu, 15 Aug 2024 15:04:49 -0700 Subject: [PATCH 4/4] Remove time from logging Per @mattdailis' suggestion, since serialized events are tagged with the time they're emitted already, there's no need to include that information in the log message itself. Further, removing that dependency on the plan start time makes this PR fully backwards-compatible. --- .../contrib/streamline/debugging/Logger.java | 14 +++---------- .../contrib/streamline/debugging/Logging.java | 6 ++---- .../streamline/modeling/Registrar.java | 21 ++----------------- .../jpl/aerie/streamline_demo/Mission.java | 6 ++---- 4 files changed, 9 insertions(+), 38 deletions(-) diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logger.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logger.java index 9935d687d7..4483feb988 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logger.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logger.java @@ -1,13 +1,10 @@ package gov.nasa.jpl.aerie.contrib.streamline.debugging; -import gov.nasa.jpl.aerie.contrib.streamline.core.Resources; import gov.nasa.jpl.aerie.merlin.framework.Registrar; -import java.time.Instant; import java.util.Arrays; import java.util.Map; -import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MICROSECONDS; import static java.util.stream.Collectors.toMap; public class Logger { @@ -15,24 +12,19 @@ public class Logger { .map(v -> v.toString().length()) .max(Integer::compareTo) .orElseThrow(); - private static final String LOG_MESSAGE_FORMAT = "%s [%-" + LEVEL_INDICATOR_SIZE + "s] %s"; + private static final String LOG_MESSAGE_FORMAT = "[%-" + LEVEL_INDICATOR_SIZE + "s] %s"; private final Map subLoggers; - private final Instant planStart; - public Logger(Registrar registrar, Instant planStart) { - // TODO - refactor the plan start out, by instead building a global sim clock to do the same job. - // To do that "right", the global clock should be a resource with custom dynamics for continuous Instant clocks. + public Logger(Registrar registrar) { subLoggers = Arrays.stream(LogLevel.values()).collect(toMap( level -> level, level -> new SimpleLogger(level.name(), registrar))); - this.planStart = planStart; } public void log(LogLevel level, String messageFormat, Object... args) { - Instant time = planStart.plusNanos(Resources.currentTime().in(MICROSECONDS) * 1_000); String message = messageFormat.formatted(args); - subLoggers.get(level).log(LOG_MESSAGE_FORMAT.formatted(time, level, message)); + subLoggers.get(level).log(LOG_MESSAGE_FORMAT.formatted(level, message)); } public void debug(String messageFormat, Object... args) { diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logging.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logging.java index 1dfa625118..f9741e8047 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logging.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/debugging/Logging.java @@ -2,8 +2,6 @@ import gov.nasa.jpl.aerie.merlin.framework.Registrar; -import java.time.Instant; - public final class Logging { private Logging() {} @@ -19,9 +17,9 @@ private Logging() {} * This is called when constructing a {@link gov.nasa.jpl.aerie.contrib.streamline.modeling.Registrar}, * and does not need to be called directly by the model. */ - public static void init(final Registrar registrar, final Instant planStart) { + public static void init(final Registrar registrar) { if (LOGGER == null) { - LOGGER = new Logger(registrar, planStart); + LOGGER = new Logger(registrar); } else { LOGGER.warning("Attempting to re-initialize primary logger. This attempt is being ignored."); } diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java index c8b43df896..a8ab5ecce3 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Registrar.java @@ -14,10 +14,6 @@ import gov.nasa.jpl.aerie.merlin.framework.ValueMapper; import gov.nasa.jpl.aerie.merlin.protocol.types.RealDynamics; import gov.nasa.jpl.aerie.merlin.protocol.types.Unit; -import org.apache.commons.lang3.exception.ExceptionUtils; - -import java.time.Instant; -import java.util.Collection; import static gov.nasa.jpl.aerie.contrib.streamline.core.Reactions.whenever; import static gov.nasa.jpl.aerie.contrib.streamline.core.Resources.currentData; @@ -31,7 +27,6 @@ import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.*; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.linear.Linear.linear; import static gov.nasa.jpl.aerie.merlin.framework.ModelActions.waitUntil; -import static java.util.stream.Collectors.joining; /** * Wrapper for {@link gov.nasa.jpl.aerie.merlin.framework.Registrar} specialized for {@link Resource}. @@ -59,27 +54,15 @@ public enum ErrorBehavior { Throw } - public Registrar(final gov.nasa.jpl.aerie.merlin.framework.Registrar baseRegistrar, final Instant planStart, final ErrorBehavior errorBehavior) { + public Registrar(final gov.nasa.jpl.aerie.merlin.framework.Registrar baseRegistrar, final ErrorBehavior errorBehavior) { Resources.init(); - Logging.init(baseRegistrar, planStart); + Logging.init(baseRegistrar); this.baseRegistrar = baseRegistrar; this.errorBehavior = errorBehavior; discrete("numberOfErrors", numberOfErrors, new IntegerValueMapper()); } - private static String formatError(Throwable e, Collection affectedResources) { - return "Error affecting %s:%n%s".formatted( - String.join(", ", affectedResources), - formatException(e)); - } - - private static String formatException(Throwable e) { - return ExceptionUtils.stream(e) - .map(ExceptionUtils::getMessage) - .collect(joining("\nCaused by: ")); - } - public void setTrace() { trace = true; } diff --git a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/Mission.java b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/Mission.java index 7168516eca..ece739efba 100644 --- a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/Mission.java +++ b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/Mission.java @@ -5,15 +5,13 @@ import gov.nasa.jpl.aerie.contrib.streamline.modeling.Registrar; import gov.nasa.jpl.aerie.merlin.framework.ModelActions; -import java.time.Instant; - public final class Mission { public final DataModel dataModel; public final ErrorTestingModel errorTestingModel; public final ApproximationModel approximationModel; - public Mission(final gov.nasa.jpl.aerie.merlin.framework.Registrar registrar$, final Instant planStart, final Configuration config) { - var registrar = new Registrar(registrar$, planStart, Registrar.ErrorBehavior.Log); + public Mission(final gov.nasa.jpl.aerie.merlin.framework.Registrar registrar$, final Configuration config) { + var registrar = new Registrar(registrar$, Registrar.ErrorBehavior.Log); if (config.traceResources) registrar.setTrace(); if (config.profileResources) Resource.profileAllResources(); dataModel = new DataModel(registrar, config);