Example usage for com.google.common.collect Maps fromProperties

List of usage examples for com.google.common.collect Maps fromProperties

Introduction

In this page you can find the example usage for com.google.common.collect Maps fromProperties.

Prototype

@GwtIncompatible("java.util.Properties")
public static ImmutableMap<String, String> fromProperties(Properties properties) 

Source Link

Document

Creates an ImmutableMap from a Properties instance.

Usage

From source file:org.apache.metron.profiler.spark.BatchProfiler.java

/**
 * Execute the Batch Profiler.//  w ww  .  ja  v a2s .  c  om
 *
 * @param spark The spark session.
 * @param profilerProps The profiler configuration properties.
 * @param globalProperties The Stellar global properties.
 * @param readerProps The properties passed to the {@link org.apache.spark.sql.DataFrameReader}.
 * @param profiles The profile definitions.
 * @return The number of profile measurements produced.
 */
public long run(SparkSession spark, Properties profilerProps, Properties globalProperties,
        Properties readerProps, ProfilerConfig profiles) {

    LOG.debug("Building {} profile(s)", profiles.getProfiles().size());
    Map<String, String> globals = Maps.fromProperties(globalProperties);

    // fetch the archived telemetry using the input reader
    TelemetryReader reader = TelemetryReaders.create(TELEMETRY_INPUT_READER.get(profilerProps, String.class));
    Dataset<String> telemetry = reader.read(spark, profilerProps, readerProps);
    LOG.debug("Found {} telemetry record(s)", telemetry.cache().count());

    // find all routes for each message
    Dataset<MessageRoute> routes = telemetry.flatMap(messageRouterFunction(profilerProps, profiles, globals),
            Encoders.bean(MessageRoute.class));
    LOG.debug("Generated {} message route(s)", routes.cache().count());

    // build the profiles
    Dataset<ProfileMeasurementAdapter> measurements = routes
            .groupByKey(new GroupByPeriodFunction(profilerProps), Encoders.STRING())
            .mapGroups(new ProfileBuilderFunction(profilerProps, globals),
                    Encoders.bean(ProfileMeasurementAdapter.class));
    LOG.debug("Produced {} profile measurement(s)", measurements.cache().count());

    // write the profile measurements to HBase
    long count = measurements.mapPartitions(new HBaseWriterFunction(profilerProps), Encoders.INT())
            .agg(sum("value")).head().getLong(0);
    LOG.debug("{} profile measurement(s) written to HBase", count);

    return count;
}

From source file:com.sos.scheduler.engine.kernel.util.ClassResource.java

public final ImmutableMap<String, String> properties() {
    try {// ww  w .j a  v  a  2  s.  c  o  m
        Properties properties = new Properties();
        properties.load(getInputStream());
        return Maps.fromProperties(properties);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.tajo.client.v2.LegacyClientDelegate.java

public LegacyClientDelegate(ServiceDiscovery discovery, Properties clientParams) {
    super(new DelegateServiceTracker(discovery), null, new KeyValueSet(
            clientParams == null ? new HashMap<String, String>() : Maps.fromProperties(clientParams)));
    queryClient = new QueryClientImpl(this);
}

From source file:org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration.java

public static ExecutionContextConfiguration fromInputStream(InputStream inputStream) throws IOException {
    Properties properties = new Properties();
    properties.load(inputStream);/* ww w  . j av a 2  s  .co m*/
    Context context = new Context(Maps.fromProperties(properties));
    return new ExecutionContextConfiguration(context);
}

From source file:io.prestosql.plugin.kafka.util.EmbeddedKafka.java

EmbeddedKafka(EmbeddedZookeeper zookeeper, Properties overrideProperties) {
    this.zookeeper = requireNonNull(zookeeper, "zookeeper is null");
    requireNonNull(overrideProperties, "overrideProperties is null");

    this.kafkaDataDir = Files.createTempDir();

    Map<String, String> properties = ImmutableMap.<String, String>builder().put("broker.id", "0")
            .put("host.name", "localhost").put("num.partitions", "2")
            .put("log.flush.interval.messages", "10000").put("log.flush.interval.ms", "1000")
            .put("log.retention.minutes", "60").put("log.segment.bytes", "1048576")
            .put("auto.create.topics.enable", "false").put("zookeeper.connection.timeout.ms", "1000000")
            .put("port", "0").put("log.dirs", kafkaDataDir.getAbsolutePath())
            .put("zookeeper.connect", zookeeper.getConnectString())
            .putAll(Maps.fromProperties(overrideProperties)).build();

    KafkaConfig config = new KafkaConfig(properties);
    this.kafkaServer = new KafkaServer(config, Time.SYSTEM, Option.empty(), List.make(0, null));
}

From source file:com.codetroopers.maven.mergeprops.MergeProperty.java

private static void checkCountMismatch(final Map<String, Properties> propertiesMap, final Merge merge,
        final Map<String, Integer> localeSizeMap) throws MojoFailureException {
    //if we got the same numbers of keys, the set will flatten every values
    if (shouldFailIfNoMatchFromProperty() && merge.getFailOnCountMismatch()
            && new HashSet<Integer>(localeSizeMap.values()).size() != 1) {

        final HashMultiset<String> multiset = HashMultiset.create();
        for (Map.Entry<String, Properties> entry : propertiesMap.entrySet()) {
            multiset.addAll(Maps.fromProperties(entry.getValue()).keySet());
        }//ww  w . j a v a 2  s.  co m
        final int bundlesAmount = propertiesMap.keySet().size();
        final Set<String> lonelyKeys = Sets.newHashSet(Collections2.filter(multiset, new Predicate<String>() {
            @Override
            public boolean apply(final String input) {
                return multiset.count(input) != bundlesAmount;
            }
        }));
        throw new MojoFailureException(lonelyKeys, "Invalid property count for file : " + merge.getTarget(),
                "Lonely keys are : \n" + Joiner.on("\n").join(lonelyKeys));
    }
}

From source file:org.apache.gobblin.service.modules.restli.FlowConfigUtils.java

public static FlowConfig deserializeFlowConfig(String serialized) throws IOException {
    Properties properties = PropertiesUtils.deserialize(serialized);
    FlowConfig flowConfig = new FlowConfig()
            .setId(new FlowId().setFlowName(properties.getProperty(FLOWCONFIG_ID_NAME))
                    .setFlowGroup(properties.getProperty(FLOWCONFIG_ID_GROUP)));

    if (properties.containsKey(FLOWCONFIG_SCHEDULE_CRON)) {
        flowConfig.setSchedule(new Schedule().setCronSchedule(properties.getProperty(FLOWCONFIG_SCHEDULE_CRON))
                .setRunImmediately(/*from   w  ww. j a va  2s  .  c om*/
                        Boolean.valueOf(properties.getProperty(FLOWCONFIG_SCHEDULE_RUN_IMMEDIATELY))));
    }

    if (properties.containsKey(FLOWCONFIG_TEMPLATEURIS)) {
        flowConfig.setTemplateUris(properties.getProperty(FLOWCONFIG_TEMPLATEURIS));
    }

    properties.remove(FLOWCONFIG_ID_NAME);
    properties.remove(FLOWCONFIG_ID_GROUP);
    properties.remove(FLOWCONFIG_SCHEDULE_CRON);
    properties.remove(FLOWCONFIG_SCHEDULE_RUN_IMMEDIATELY);
    properties.remove(FLOWCONFIG_TEMPLATEURIS);

    flowConfig.setProperties(new StringMap(Maps.fromProperties(properties)));

    return flowConfig;
}

From source file:com.netflix.metacat.main.presto.metadata.CatalogManager.java

private static Map<String, String> loadProperties(final File file) throws Exception {
    Preconditions.checkNotNull(file, "file is null");

    final Properties properties = new Properties();
    try (FileInputStream in = new FileInputStream(file)) {
        properties.load(in);/*from   w w w .  j a  va  2 s  . c o m*/
    }
    return Maps.fromProperties(properties);
}

From source file:org.lbogdanov.poker.web.AppInitializer.java

/**
 * {@inheritDoc}//from   ww  w .  j a va 2s.  c om
 */
@Override
protected Injector getInjector() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    try {
        InputStream settings = Resources.newInputStreamSupplier(Resources.getResource("settings.properties"))
                .getInput();
        Properties props = new Properties();
        try {
            props.load(settings);
        } finally {
            settings.close();
        }
        Settings.init(Maps.fromProperties(props));
    } catch (IOException ioe) {
        throw Throwables.propagate(ioe);
    }
    final boolean isDevel = DEVELOPMENT_MODE.asBool().or(false);
    Module shiroModule = new ShiroWebModule(servletContext) {

        @Override
        @SuppressWarnings("unchecked")
        protected void configureShiroWeb() {
            bind(String.class).annotatedWith(Names.named(InjectableOAuthFilter.FAILURE_URL_PARAM))
                    .toInstance("/");
            // TODO simple ini-based realm for development
            bindRealm().toInstance(new IniRealm(IniFactorySupport.loadDefaultClassPathIni()));
            bindRealm().to(InjectableOAuthRealm.class).in(Singleton.class);

            addFilterChain("/" + Constants.OAUTH_CLBK_FILTER_URL, Key.get(InjectableOAuthFilter.class));
            addFilterChain("/" + Constants.OAUTH_FILTER_URL,
                    config(CallbackUrlSetterFilter.class, Constants.OAUTH_CLBK_FILTER_URL),
                    Key.get(InjectableOAuthUserFilter.class));
        }

        @Provides
        @Singleton
        private OAuthProvider getOAuthProvider() {
            Google2Provider provider = new Google2Provider();
            provider.setKey(GOOGLE_OAUTH_KEY.asString().get());
            provider.setSecret(GOOGLE_OAUTH_SECRET.asString().get());
            provider.setCallbackUrl("example.com"); // fake URL, will be replaced by CallbackUrlSetterFilter
            provider.setScope(Google2Scope.EMAIL_AND_PROFILE);
            return provider;
        }

    };
    Module appModule = new ServletModule() {

        @Override
        protected void configureServlets() {
            ServerConfig dbConfig = new ServerConfig();
            String jndiDataSource = DB_DATA_SOURCE.asString().orNull();
            if (Strings.isNullOrEmpty(jndiDataSource)) { // use direct JDBC connection
                DataSourceConfig dsConfig = new DataSourceConfig();
                dsConfig.setDriver(DB_DRIVER.asString().get());
                dsConfig.setUrl(DB_URL.asString().get());
                dsConfig.setUsername(DB_USER.asString().orNull());
                dsConfig.setPassword(DB_PASSWORD.asString().orNull());
                dbConfig.setDataSourceConfig(dsConfig);
            } else {
                dbConfig.setDataSourceJndiName(jndiDataSource);
            }
            dbConfig.setName("PlanningPoker");
            dbConfig.setDefaultServer(true);
            dbConfig.addClass(Session.class);
            dbConfig.addClass(User.class);

            bind(EbeanServer.class).toInstance(EbeanServerFactory.create(dbConfig));
            bind(SessionService.class).to(SessionServiceImpl.class);
            bind(UserService.class).to(UserServiceImpl.class);
            bind(WebApplication.class).to(PokerWebApplication.class);
            bind(MeteorServlet.class).in(Singleton.class);
            bind(ObjectMapper.class).toProvider(new Provider<ObjectMapper>() {

                @Override
                public ObjectMapper get() {
                    SimpleModule module = new SimpleModule().addSerializer(UserSerializer.get());
                    return new ObjectMapper().registerModule(module);
                }

            }).in(Singleton.class);
            String wicketConfig = (isDevel ? RuntimeConfigurationType.DEVELOPMENT
                    : RuntimeConfigurationType.DEPLOYMENT).toString();
            ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
            params.put(ApplicationConfig.FILTER_CLASS, WicketFilter.class.getName())
                    .put(ApplicationConfig.PROPERTY_SESSION_SUPPORT, Boolean.TRUE.toString())
                    .put(ApplicationConfig.BROADCAST_FILTER_CLASSES, TrackMessageSizeFilter.class.getName())
                    .put(ApplicationConfig.BROADCASTER_CACHE, UUIDBroadcasterCache.class.getName())
                    .put(ApplicationConfig.SHOW_SUPPORT_MESSAGE, Boolean.FALSE.toString())
                    .put(WicketFilter.FILTER_MAPPING_PARAM, "/*")
                    .put(WebApplication.CONFIGURATION, wicketConfig)
                    .put(WicketFilter.APP_FACT_PARAM, GuiceWebApplicationFactory.class.getName())
                    .put("injectorContextAttribute", Injector.class.getName()).build();
            serve("/*").with(MeteorServlet.class, params.build());
        }

    };
    Stage stage = isDevel ? Stage.DEVELOPMENT : Stage.PRODUCTION;
    return Guice.createInjector(stage, ShiroWebModule.guiceFilterModule(), shiroModule, appModule);
}

From source file:org.gbif.common.search.inject.BaseSearchModule.java

private Map<String, String> buildProperties(Properties properties) {
    return buildProperties(Maps.fromProperties(properties));
}