Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/160#discussion_r24765926
  
    --- Diff: 
stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java 
---
    @@ -0,0 +1,159 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.usergrid.corepersistence;
    +
    +
    +import java.util.Properties;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.springframework.beans.BeansException;
    +import org.springframework.beans.factory.FactoryBean;
    +import org.springframework.context.ApplicationContext;
    +import org.springframework.context.ApplicationContextAware;
    +
    +import org.apache.commons.lang.StringUtils;
    +
    +import org.apache.usergrid.persistence.cassandra.CassandraService;
    +
    +import com.google.inject.Guice;
    +import com.google.inject.Injector;
    +import com.google.inject.Singleton;
    +import com.netflix.config.ConfigurationManager;
    +
    +import me.prettyprint.cassandra.service.CassandraHost;
    +
    +
    +/**
    + * Factory for configuring Guice then returning it
    + */
    +@Singleton
    +public class GuiceFactory implements FactoryBean<Injector>, 
ApplicationContextAware {
    +
    +    private static final Logger logger = LoggerFactory.getLogger( 
GuiceFactory.class );
    +
    +
    +    private final CassandraService cass;
    +
    +    private final Properties systemProperties;
    +
    +
    +    private ApplicationContext applicationContext;
    +
    +    private Injector injector;
    +
    +
    +
    +    public GuiceFactory( final CassandraService cass, final Properties 
systemProperties ) {
    +        this.cass = cass;
    +        this.systemProperties = systemProperties;
    +    }
    +
    +
    +    @Override
    +    public Injector getObject() throws Exception {
    +
    +        if ( this.injector != null ) {
    +            return injector;
    +        }
    +
    +
    +        try {
    +
    +            cass.init();
    +            logger.info( "Loading Core Persistence properties" );
    +
    +            String hostsString = "";
    +            CassandraHost[] hosts = 
cass.getCassandraHostConfigurator().buildCassandraHosts();
    +            if ( hosts.length == 0 ) {
    +                throw new RuntimeException( "Fatal error: no Cassandra 
hosts configured" );
    +            }
    +            String sep = "";
    +            for ( CassandraHost host : hosts ) {
    +                if ( StringUtils.isEmpty( host.getHost() ) ) {
    +                    throw new RuntimeException( "Fatal error: Cassandra 
hostname cannot be empty" );
    +                }
    +                hostsString = hostsString + sep + host.getHost();
    +                sep = ",";
    +            }
    +
    +            logger.info( "hostsString: " + hostsString );
    +
    +            Properties cpProps = new Properties();
    +
    +            // Some Usergrid properties must be mapped to Core Persistence 
properties
    +            cpProps.put( "cassandra.hosts", hostsString );
    +            cpProps.put( "cassandra.port", hosts[0].getPort() );
    +            cpProps.put( "cassandra.cluster_name", 
cass.getProperties().get( "cassandra.cluster" ) );
    +
    +            String cassRemoteString = ( String ) cass.getProperties().get( 
"cassandra.use_remote" );
    +            if ( cassRemoteString != null && cassRemoteString.equals( 
"false" ) ) {
    +                cpProps.put( "cassandra.embedded", "true" );
    +            }
    +            else {
    +                cpProps.put( "cassandra.embedded", "false" );
    +            }
    +
    +            cpProps.put( "collections.keyspace.strategy.class",
    +                cass.getProperties().get( "cassandra.keyspace.strategy" ) 
);
    +
    +            cpProps.put( "collections.keyspace.strategy.options",
    +                cass.getProperties().get( "cassandra.keyspace.replication" 
) );
    +
    +
    +            logger.debug( "Set Cassandra properties for Core Persistence: 
" + cpProps.toString() );
    +
    +            // Make all Usergrid properties into Core Persistence config
    +            cpProps.putAll( cass.getProperties() );
    +            cpProps.putAll( systemProperties );
    +            //logger.debug("All properties fed to Core Persistence: " + 
cpProps.toString() );
    +
    +
    +
    +            ConfigurationManager.loadProperties( cpProps );
    +        }
    +        catch ( Exception e ) {
    +            throw new RuntimeException( "Fatal error loading 
configuration.", e );
    +        }
    +
    +        //this is seriously fugly, and needs removed
    +        injector = Guice.createInjector( new GuiceModule( 
applicationContext ) );
    --- End diff --
    
    Could we separate this out? It seems like a method called getObject 
shouldn't do configuration loading either.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to