diff --git a/server/src/main/java/com/hedera/block/server/config/BlockNodeConfigExtension.java b/server/src/main/java/com/hedera/block/server/config/BlockNodeConfigExtension.java index 152526fd9..731030d4b 100644 --- a/server/src/main/java/com/hedera/block/server/config/BlockNodeConfigExtension.java +++ b/server/src/main/java/com/hedera/block/server/config/BlockNodeConfigExtension.java @@ -21,6 +21,7 @@ import com.swirlds.common.metrics.config.MetricsConfig; import com.swirlds.common.metrics.platform.prometheus.PrometheusConfig; import com.swirlds.config.api.ConfigurationExtension; +import edu.umd.cs.findbugs.annotations.NonNull; import java.util.Set; /** Registers configuration types for the server. */ @@ -32,6 +33,7 @@ public class BlockNodeConfigExtension implements ConfigurationExtension { * * @return Set of configuration data types for the server */ + @NonNull @Override public Set> getConfigDataTypes() { return Set.of(BasicCommonConfig.class, MetricsConfig.class, PrometheusConfig.class); diff --git a/server/src/main/java/com/hedera/block/server/config/BlockNodeContextFactory.java b/server/src/main/java/com/hedera/block/server/config/BlockNodeContextFactory.java index 2ecd680dc..1e400771c 100644 --- a/server/src/main/java/com/hedera/block/server/config/BlockNodeContextFactory.java +++ b/server/src/main/java/com/hedera/block/server/config/BlockNodeContextFactory.java @@ -24,13 +24,12 @@ import com.swirlds.config.extensions.sources.SystemEnvironmentConfigSource; import com.swirlds.config.extensions.sources.SystemPropertiesConfigSource; import com.swirlds.metrics.api.Metrics; +import edu.umd.cs.findbugs.annotations.NonNull; import java.io.IOException; import java.nio.file.Path; /** Static factory that creates {@link BlockNodeContext} */ public class BlockNodeContextFactory { - private static final System.Logger logger = - System.getLogger(BlockNodeContextFactory.class.getName()); private static final String APPLICATION_PROPERTIES_1 = "app.properties"; @@ -40,28 +39,25 @@ private BlockNodeContextFactory() {} * @return an instance of {@link BlockNodeContext} which holds {@link Configuration}, {@link * Metrics} and {@link MetricsService} for the rest of the application to use. */ - public static BlockNodeContext create() { + public static BlockNodeContext create() throws IOException { final Configuration configuration = getConfiguration(); final Metrics metrics = getMetrics(configuration); final MetricsService metricsService = new MetricsService(metrics); return new BlockNodeContext(metrics, metricsService, configuration); } - private static Configuration getConfiguration() { - try { - return ConfigurationBuilder.create() - .withSource(SystemEnvironmentConfigSource.getInstance()) - .withSource(SystemPropertiesConfigSource.getInstance()) - .withSource(new ClasspathFileConfigSource(Path.of(APPLICATION_PROPERTIES_1))) - .autoDiscoverExtensions() - .build(); - } catch (IOException e) { - logger.log(System.Logger.Level.ERROR, "Error reading configuration", e); - throw new RuntimeException("Error reading configuration", e); - } + private static Configuration getConfiguration() throws IOException { + + return ConfigurationBuilder.create() + .withSource(SystemEnvironmentConfigSource.getInstance()) + .withSource(SystemPropertiesConfigSource.getInstance()) + .withSource(new ClasspathFileConfigSource(Path.of(APPLICATION_PROPERTIES_1))) + .autoDiscoverExtensions() + .build(); } - private static Metrics getMetrics(final Configuration configuration) { + @NonNull + private static Metrics getMetrics(@NonNull final Configuration configuration) { final DefaultMetricsProvider metricsProvider = new DefaultMetricsProvider(configuration); final Metrics metrics = metricsProvider.createGlobalMetrics(); metricsProvider.start(); diff --git a/server/src/main/java/com/hedera/block/server/metrics/MetricsService.java b/server/src/main/java/com/hedera/block/server/metrics/MetricsService.java index a5f6b0c18..9ad3d2838 100644 --- a/server/src/main/java/com/hedera/block/server/metrics/MetricsService.java +++ b/server/src/main/java/com/hedera/block/server/metrics/MetricsService.java @@ -19,6 +19,7 @@ import com.swirlds.metrics.api.Counter; import com.swirlds.metrics.api.LongGauge; import com.swirlds.metrics.api.Metrics; +import edu.umd.cs.findbugs.annotations.NonNull; public class MetricsService { @@ -34,7 +35,7 @@ public class MetricsService { public final Counter exampleCounter; - public MetricsService(final Metrics metrics) { + public MetricsService(@NonNull final Metrics metrics) { this.exampleGauge = metrics.getOrCreate(EXAMPLE_GAUGE); this.exampleCounter = metrics.getOrCreate(EXAMPLE_COUNTER); } diff --git a/server/src/test/java/com/hedera/block/server/config/BlockNodeContextFactoryTest.java b/server/src/test/java/com/hedera/block/server/config/BlockNodeContextFactoryTest.java index baf193aa2..cd02cd8b7 100644 --- a/server/src/test/java/com/hedera/block/server/config/BlockNodeContextFactoryTest.java +++ b/server/src/test/java/com/hedera/block/server/config/BlockNodeContextFactoryTest.java @@ -18,12 +18,13 @@ import static org.junit.jupiter.api.Assertions.*; +import java.io.IOException; import org.junit.jupiter.api.Test; class BlockNodeContextFactoryTest { @Test - void create_returnsBlockNodeContext() { + void create_returnsBlockNodeContext() throws IOException { BlockNodeContext context = BlockNodeContextFactory.create(); assertNotNull(context.metrics());