Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use common config #7336

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions common/config/src/main/java/io/helidon/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ default Config get(Key key) {
*/
<T> ConfigValue<List<T>> asList(Class<T> type) throws ConfigException;

/**
* Returns this node as a list mapping each list value using the provided mapper.
*
* @param mapper mapper to convert each list node into a typed value
* @param <T> type of list elements
* @return a typed list with values
* @throws io.helidon.common.config.ConfigException in case the mapper fails to map the values
*/
<T> ConfigValue<List<T>> mapList(Function<Config, T> mapper) throws ConfigException;

/**
* Returns a list of child {@code Config} nodes if the node is {@code Type#OBJECT}.
* Returns a list of element nodes if the node is {@code Type#LIST}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ public <T> ConfigValue<List<T>> asList(Class<T> type) throws ConfigException {
return new EmptyValue<>(this.key);
}

@Override
public <T> ConfigValue<List<T>> mapList(Function<Config, T> mapper) throws ConfigException {
return new EmptyValue<>(this.key);
}

@Override
public <C extends Config> ConfigValue<List<C>> asNodeList() throws ConfigException {
return new EmptyValue<>(this.key);
Expand Down
7 changes: 7 additions & 0 deletions config/config/src/main/java/io/helidon/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.stream.Stream;

import io.helidon.common.GenericType;
import io.helidon.common.config.ConfigException;
import io.helidon.config.spi.ConfigFilter;
import io.helidon.config.spi.ConfigMapper;
import io.helidon.config.spi.ConfigMapperProvider;
Expand Down Expand Up @@ -814,6 +815,12 @@ default ConfigValue<Double> asDouble() {
*/
<T> ConfigValue<List<T>> asList(Function<Config, T> mapper) throws ConfigMappingException;

@Override
default <T> io.helidon.common.config.ConfigValue<List<T>> mapList(Function<io.helidon.common.config.Config, T> mapper)
throws ConfigException {
return asList(mapper::apply);
}

/**
* Returns existing current config node as a {@link Optional} instance
* or {@link Optional#empty()} in case of {@link Type#MISSING} node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public <T> ConfigValue<List<T>> asList(Class<T> type) throws ConfigException {
return config.asList(type);
}

@Override
public <T> ConfigValue<List<T>> mapList(Function<Config, T> mapper) throws ConfigException {
return config.mapList(mapper);
}

@Override
public <C extends Config> ConfigValue<List<C>> asNodeList() throws ConfigException {
return config.asNodeList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.util.function.BiFunction;

import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.dbclient.DbClientServiceBase;
import io.helidon.dbclient.DbStatementType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import java.util.Objects;
import java.util.function.Supplier;

import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.metrics.api.MetricsSettings;
import io.helidon.metrics.api.Registry;
import io.helidon.metrics.api.RegistryFactory;

Expand Down Expand Up @@ -68,7 +69,7 @@ private MicrostreamMetricsSupport(Builder builder) {
this.embeddedStorageManager = builder.embeddedStorageManager();

if (builder.registryFactory() == null) {
registryFactory = RegistryFactory.getInstance(config);
registryFactory = RegistryFactory.getInstance(MetricsSettings.create(config));
} else {
registryFactory = builder.registryFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class CoordinatorService implements HttpService {

CoordinatorService(LraPersistentRegistry lraPersistentRegistry, Supplier<URI> coordinatorUriSupplier, Config config) {
this.lraPersistentRegistry = lraPersistentRegistry;
coordinatorURL = LazyValue.create(coordinatorUriSupplier);
this.coordinatorURL = LazyValue.create(coordinatorUriSupplier);
this.config = config;
init();
}
Expand Down Expand Up @@ -418,7 +418,6 @@ private URI coordinatorUriWithPath(String additionalPath) {
*/
public static CoordinatorService create() {
return builder()
.config(Config.create().get(CoordinatorService.CONFIG_PREFIX))
.build();
}

Expand Down Expand Up @@ -480,7 +479,7 @@ public Builder url(Supplier<URI> uriSupplier) {
@Override
public CoordinatorService build() {
if (config == null) {
config = Config.create().get(CoordinatorService.CONFIG_PREFIX);
config = Config.empty();
}
if (lraPersistentRegistry == null) {
lraPersistentRegistry = new LraDatabasePersistentRegistry(config);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,7 +42,9 @@ public static void main(String[] args) {

Config config = Config.create();

CoordinatorService coordinatorService = CoordinatorService.builder().build();
CoordinatorService coordinatorService = CoordinatorService.builder()
.config(config.get(CoordinatorService.CONFIG_PREFIX))
.build();

WebServer server = WebServer.builder()
.routing(it -> updateRouting(it, config, coordinatorService))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.sql.DataSource;

import io.helidon.common.Builder;
import io.helidon.common.config.Config;
import io.helidon.common.configurable.ScheduledThreadPoolSupplier;
import io.helidon.common.configurable.ThreadPoolSupplier;
import io.helidon.messaging.connectors.jms.JmsConnector;
Expand Down Expand Up @@ -187,7 +188,7 @@ class AqConnectorBuilder implements Builder<AqConnectorBuilder, AqConnectorImpl>
private final Map<String, DataSource> dataSourceMap = new HashMap<>();
private ScheduledExecutorService scheduler;
private ExecutorService executor;
private io.helidon.config.Config config;
private Config config;

/**
* Add custom {@link jakarta.jms.ConnectionFactory ConnectionFactory} referencable by supplied name with
Expand All @@ -208,7 +209,7 @@ public AqConnectorBuilder dataSource(String name, DataSource dataSource) {
* @param config custom config
* @return this builder
*/
public AqConnectorBuilder config(io.helidon.config.Config config) {
public AqConnectorBuilder config(Config config) {
this.config = config;
return this;
}
Expand Down Expand Up @@ -260,7 +261,7 @@ public AqConnectorBuilder scheduler(ScheduledThreadPoolSupplier schedulerPoolSup
@Override
public AqConnectorImpl build() {
if (config == null) {
config = io.helidon.config.Config.empty();
config = Config.empty();
}

if (executor == null) {
Expand Down
4 changes: 2 additions & 2 deletions metrics/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<artifactId>helidon-common-http</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.util.Map;

import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;
import io.helidon.config.metadata.ConfiguredValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.metrics.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import io.helidon.config.Config;
import io.helidon.common.config.Config;

class BaseMetricsSettingsImpl implements BaseMetricsSettings {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.helidon.metrics.api;

import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.metrics.api;

import io.helidon.config.Config;
import io.helidon.common.config.Config;

class ComponentMetricsSettingsImpl implements ComponentMetricsSettings {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.helidon.metrics.api;

import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.metrics.api;

import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.config.metadata.ConfiguredOption;

class KeyPerformanceIndicatorMetricsSettingsImpl implements KeyPerformanceIndicatorMetricsSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.util.Map;

import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;

Expand All @@ -31,12 +31,12 @@
public interface MetricsSettings {

/**
* Returns default metrics settings based on the {@code metrics} section of the default config.
* Returns default metrics settings.
*
* @return new settings reflecting the default config
*/
static MetricsSettings create() {
return create(Config.create().get(Builder.METRICS_CONFIG_KEY));
return create(Config.empty());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.util.List;
import java.util.Map;

import io.helidon.config.Config;
import io.helidon.config.ConfigValue;
import io.helidon.common.config.Config;
import io.helidon.common.config.ConfigValue;

class MetricsSettingsImpl implements MetricsSettings {

Expand Down Expand Up @@ -155,11 +155,11 @@ public Builder config(Config metricsSettingsConfig) {
.ifPresent(this::enabled);

metricsSettingsConfig.get(REGISTRIES_CONFIG_KEY)
.asList(ScopedRegistrySettingsImpl::create)
.mapList(ScopedRegistrySettingsImpl::create)
.ifPresent(this::addAllTypedRegistrySettings);

metricsSettingsConfig.get(GLOBAL_TAGS_CONFIG_KEY)
.as(Builder::globalTagsExpressionToMap)
.map(Builder::globalTagsExpressionToMap)
.ifPresent(this::globalTags);

metricsSettingsConfig.get(APP_TAG_CONFIG_KEY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.Optional;
import java.util.Set;

import io.helidon.common.config.Config;
import io.helidon.common.media.type.MediaType;
import io.helidon.config.Config;

import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.Gauge;
Expand Down Expand Up @@ -101,7 +101,7 @@ static RegistryFactory getInstance() {
*/
@Deprecated
static RegistryFactory getInstance(Config config) {
return RegistryFactoryManager.getInstance(config);
return RegistryFactoryManager.getInstance(MetricsSettings.create(config));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import io.helidon.common.HelidonServiceLoader;
import io.helidon.common.LazyValue;
import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.metrics.api.spi.RegistryFactoryProvider;

/**
Expand Down Expand Up @@ -126,11 +126,6 @@ static RegistryFactory getInstance(ComponentMetricsSettings componentMetricsSett
: NO_OP_INSTANCE);
}

@Deprecated
static RegistryFactory getInstance(Config config) {
return getInstance(MetricsSettings.create(config));
}

private static <T> T accessMetricsSettings(Supplier<T> operation) {
SETTINGS_ACCESS.lock();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.metrics.api;

import io.helidon.config.Config;
import io.helidon.common.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.config.metadata.ConfiguredOption;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.metrics.api;

import java.util.regex.Pattern;

import io.helidon.config.Config;
import io.helidon.common.config.Config;

class RegistryFilterSettingsImpl implements RegistryFilterSettings {

Expand Down
Loading