Search in sources :

Example 1 with AbstractEnvironment

use of org.springframework.core.env.AbstractEnvironment in project kylo by Teradata.

the class SparkShellApp method sparkConf.

/**
 * Creates the Spark configuration.
 *
 * @return the Spark configuration
 */
@Bean
public SparkConf sparkConf(final Environment env, @Qualifier("sparkShellPort") final int serverPort) {
    final SparkConf conf = new SparkConf().setAppName("SparkShellServer").set("spark.ui.port", Integer.toString(serverPort + 1));
    final Iterable<Map.Entry<String, Object>> properties = FluentIterable.from(Collections.singleton(env)).filter(AbstractEnvironment.class).transformAndConcat(new Function<AbstractEnvironment, Iterable<?>>() {

        @Nullable
        @Override
        public Iterable<?> apply(@Nullable final AbstractEnvironment input) {
            return (input != null) ? input.getPropertySources() : null;
        }
    }).filter(ResourcePropertySource.class).transform(new Function<ResourcePropertySource, Map<String, Object>>() {

        @Nullable
        @Override
        public Map<String, Object> apply(@Nullable final ResourcePropertySource input) {
            return (input != null) ? input.getSource() : null;
        }
    }).transformAndConcat(new Function<Map<String, Object>, Iterable<Map.Entry<String, Object>>>() {

        @Nullable
        @Override
        public Iterable<Map.Entry<String, Object>> apply(@Nullable final Map<String, Object> input) {
            return (input != null) ? input.entrySet() : null;
        }
    }).filter(new Predicate<Map.Entry<String, Object>>() {

        @Override
        public boolean apply(@Nullable final Map.Entry<String, Object> input) {
            return (input != null && input.getKey().startsWith("spark."));
        }
    });
    for (final Map.Entry<String, Object> entry : properties) {
        conf.set(entry.getKey(), entry.getValue().toString());
    }
    return conf;
}
Also used : FluentIterable(com.google.common.collect.FluentIterable) AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) Function(com.google.common.base.Function) ResourcePropertySource(org.springframework.core.io.support.ResourcePropertySource) SparkConf(org.apache.spark.SparkConf) Map(java.util.Map) Nullable(javax.annotation.Nullable) Bean(org.springframework.context.annotation.Bean)

Example 2 with AbstractEnvironment

use of org.springframework.core.env.AbstractEnvironment in project pinpoint by naver.

the class ExperimentalConfig method readExperimentalProperties.

private Map<String, Object> readExperimentalProperties(Environment environment) {
    MutablePropertySources propertySources = ((AbstractEnvironment) environment).getPropertySources();
    Map<String, Object> collect = propertySources.stream().filter(ps -> ps instanceof EnumerablePropertySource).map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).filter(propName -> propName.startsWith(PREFIX)).collect(Collectors.toMap(Function.identity(), toValue(environment)));
    return collect;
}
Also used : Objects(java.util.Objects) Component(org.springframework.stereotype.Component) Arrays(java.util.Arrays) Environment(org.springframework.core.env.Environment) Map(java.util.Map) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Arrays(java.util.Arrays)

Example 3 with AbstractEnvironment

use of org.springframework.core.env.AbstractEnvironment in project spring-boot by spring-projects.

the class EnvironmentConverterTests method convertedEnvironmentHasSameConversionService.

@Test
void convertedEnvironmentHasSameConversionService() {
    AbstractEnvironment originalEnvironment = new MockEnvironment();
    ConfigurableConversionService conversionService = mock(ConfigurableConversionService.class);
    originalEnvironment.setConversionService(conversionService);
    StandardEnvironment convertedEnvironment = this.environmentConverter.convertEnvironmentIfNecessary(originalEnvironment, StandardEnvironment.class);
    assertThat(convertedEnvironment.getConversionService()).isEqualTo(conversionService);
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) ConfigurableConversionService(org.springframework.core.convert.support.ConfigurableConversionService) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 4 with AbstractEnvironment

use of org.springframework.core.env.AbstractEnvironment in project dubbo by alibaba.

the class DubboRelaxedBinding2AutoConfiguration method dubboScanBasePackagesPropertyResolver.

public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) {
    ConfigurableEnvironment propertyResolver = new AbstractEnvironment() {

        @Override
        protected void customizePropertySources(MutablePropertySources propertySources) {
            Map<String, Object> dubboScanProperties = getSubProperties(environment.getPropertySources(), DUBBO_SCAN_PREFIX);
            propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties));
        }
    };
    ConfigurationPropertySources.attach(propertyResolver);
    return propertyResolver;
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MapPropertySource(org.springframework.core.env.MapPropertySource) AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources)

Example 5 with AbstractEnvironment

use of org.springframework.core.env.AbstractEnvironment in project kylo by Teradata.

the class LivyWranglerConfig method sparkConf.

/**
 * Creates the Spark configuration.
 *
 * @return the Spark configuration
 */
@Bean
@Primary
public SparkConf sparkConf(final Environment env) /*, @Qualifier("sparkShellPort") final int serverPort*/
{
    final SparkConf conf = new SparkConf().setAppName("SparkShellServer");
    // .set("spark.ui.port", Integer.toString(serverPort + 1));
    final Iterable<Map.Entry<String, Object>> properties = FluentIterable.from(Collections.singleton(env)).filter(AbstractEnvironment.class).transformAndConcat(new Function<AbstractEnvironment, Iterable<?>>() {

        @Nullable
        @Override
        public Iterable<?> apply(@Nullable final AbstractEnvironment input) {
            return (input != null) ? input.getPropertySources() : null;
        }
    }).filter(ResourcePropertySource.class).transform(new Function<ResourcePropertySource, Map<String, Object>>() {

        @Nullable
        @Override
        public Map<String, Object> apply(@Nullable final ResourcePropertySource input) {
            return (input != null) ? input.getSource() : null;
        }
    }).transformAndConcat(new Function<Map<String, Object>, Iterable<Map.Entry<String, Object>>>() {

        @Nullable
        @Override
        public Iterable<Map.Entry<String, Object>> apply(@Nullable final Map<String, Object> input) {
            return (input != null) ? input.entrySet() : null;
        }
    }).filter(new Predicate<Map.Entry<String, Object>>() {

        @Override
        public boolean apply(@Nullable final Map.Entry<String, Object> input) {
            return (input != null && input.getKey().startsWith("spark."));
        }
    });
    for (final Map.Entry<String, Object> entry : properties) {
        conf.set(entry.getKey(), entry.getValue().toString());
    }
    return conf;
}
Also used : FluentIterable(com.google.common.collect.FluentIterable) AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) Function(com.google.common.base.Function) ResourcePropertySource(org.springframework.core.io.support.ResourcePropertySource) SparkConf(org.apache.spark.SparkConf) Map(java.util.Map) Nullable(javax.annotation.Nullable) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Aggregations

AbstractEnvironment (org.springframework.core.env.AbstractEnvironment)11 MutablePropertySources (org.springframework.core.env.MutablePropertySources)6 Map (java.util.Map)5 Test (org.junit.jupiter.api.Test)4 Function (com.google.common.base.Function)3 FluentIterable (com.google.common.collect.FluentIterable)3 Nullable (javax.annotation.Nullable)3 SparkConf (org.apache.spark.SparkConf)3 Bean (org.springframework.context.annotation.Bean)3 ResourcePropertySource (org.springframework.core.io.support.ResourcePropertySource)3 Arrays (java.util.Arrays)2 Properties (java.util.Properties)2 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 EnumerablePropertySource (org.springframework.core.env.EnumerablePropertySource)2 Environment (org.springframework.core.env.Environment)2 MapPropertySource (org.springframework.core.env.MapPropertySource)2 StandardEnvironment (org.springframework.core.env.StandardEnvironment)2 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 MockPropertySource (org.springframework.mock.env.MockPropertySource)2 Lists (com.google.common.collect.Lists)1