You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/04/17 19:57:26 UTC

[1/3] incubator-usergrid git commit: WIP overwrite

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-541 85b47ee30 -> 02c530a2b


WIP overwrite


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/cfcbc745
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/cfcbc745
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/cfcbc745

Branch: refs/heads/USERGRID-541
Commit: cfcbc74544b8629a136627bbd402c320c4f048e5
Parents: 85b47ee
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Apr 15 17:55:01 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Apr 15 17:55:01 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/migration/AppInfoMigrationPlugin.java        | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cfcbc745/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
index 9f13454..129f2f9 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
@@ -65,8 +65,8 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
     @Inject
     final private MigrationInfoSerialization migrationInfoSerialization;
 
-//    @Inject
-//    final private EntityManagerFactory emf;
+    @Inject
+    final private EntityManagerFactory emf;
 
     @Inject
     final private EntityCollectionManagerFactory entityCollectionManagerFactory;


[3/3] incubator-usergrid git commit: Updated wiring to allow spring beans to be used in guice

Posted by to...@apache.org.
Updated wiring to allow spring beans to be used in guice


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/02c530a2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/02c530a2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/02c530a2

Branch: refs/heads/USERGRID-541
Commit: 02c530a2b36df71a959d479068bd81d9c62127d4
Parents: bd1b371
Author: Todd Nine <tn...@apigee.com>
Authored: Fri Apr 17 11:57:23 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Fri Apr 17 11:57:23 2015 -0600

----------------------------------------------------------------------
 .../main/resources/usergrid-default.properties  |   3 +-
 .../corepersistence/CpEntityManager.java        |  19 +--
 .../corepersistence/CpEntityManagerFactory.java |  15 ++-
 .../corepersistence/CpRelationManager.java      |  12 +-
 .../usergrid/corepersistence/GuiceFactory.java  |  66 +++++-----
 .../usergrid/persistence/PersistenceModule.java | 124 +++----------------
 .../main/resources/usergrid-core-context.xml    |   8 +-
 .../resources/usergrid-custom-test.properties   |   2 -
 8 files changed, 89 insertions(+), 160 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c530a2/stack/config/src/main/resources/usergrid-default.properties
----------------------------------------------------------------------
diff --git a/stack/config/src/main/resources/usergrid-default.properties b/stack/config/src/main/resources/usergrid-default.properties
index ffc7628..c21a1ff 100644
--- a/stack/config/src/main/resources/usergrid-default.properties
+++ b/stack/config/src/main/resources/usergrid-default.properties
@@ -82,10 +82,9 @@ cassandra.cluster=Test Cluster
 
 cassandra.keyspace.strategy=org.apache.cassandra.locator.SimpleStrategy
 #cassandra.keyspace.strategy=org.apache.cassandra.locator.NetworkTopologyStrategy
-#cassandra.keyspace.strategy.options.replication_factor=1
-#cassandra.keyspace.strategy.options.us-east=1
 
 cassandra.keyspace.replication=replication_factor:1
+#cassandra.keyspace.replication=us-east:3
 
 cassandra.username=
 cassandra.password=

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c530a2/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index a615a43..1506551 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -37,6 +37,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.Assert;
 
+import org.apache.usergrid.corepersistence.index.IndexService;
 import org.apache.usergrid.corepersistence.util.CpEntityMapUtils;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.persistence.AggregateCounter;
@@ -165,17 +166,19 @@ public class CpEntityManager implements EntityManager {
     public static final String APPLICATION_ENTITIES = "application.entities";
     public static final long ONE_COUNT = 1L;
 
-    private UUID applicationId;
+    private final UUID applicationId;
     private Application application;
 
 
-    private ManagerCache managerCache;
+    private final ManagerCache managerCache;
 
-    private ApplicationScope applicationScope;
+    private final ApplicationScope applicationScope;
 
-    private CassandraService cass;
+    private final CassandraService cass;
 
-    private CounterUtils counterUtils;
+    private final CounterUtils counterUtils;
+
+    private final IndexService indexService;
 
     private boolean skipAggregateCounters;
     private MetricsFactory metricsFactory;
@@ -215,16 +218,18 @@ public class CpEntityManager implements EntityManager {
      * @param metricsFactory
      * @param applicationId
      */
-    public CpEntityManager(final CassandraService cass, final CounterUtils counterUtils, final ManagerCache managerCache, final MetricsFactory metricsFactory, final UUID applicationId ) {
+    public CpEntityManager(final CassandraService cass, final CounterUtils counterUtils, final IndexService indexService, final ManagerCache managerCache, final MetricsFactory metricsFactory, final UUID applicationId ) {
 
         Preconditions.checkNotNull( cass, "cass must not be null" );
         Preconditions.checkNotNull( counterUtils, "counterUtils must not be null" );
         Preconditions.checkNotNull( managerCache, "managerCache must not be null" );
         Preconditions.checkNotNull( applicationId, "applicationId must not be null" );
+        Preconditions.checkNotNull( indexService, "indexService must not be null" );
 
 
         this.managerCache = managerCache;
         this.applicationId = applicationId;
+        this.indexService = indexService;
 
         applicationScope = CpNamingUtils.getApplicationScope( applicationId );
 
@@ -734,7 +739,7 @@ public class CpEntityManager implements EntityManager {
         Preconditions.checkNotNull( entityRef, "entityRef cannot be null" );
 
         CpRelationManager relationManager =
-            new CpRelationManager( metricsFactory, managerCache, this, applicationId, entityRef );
+            new CpRelationManager( metricsFactory, managerCache, indexService, this, applicationId, entityRef );
         return relationManager;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c530a2/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index e03ed47..6ad8616 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -39,6 +39,8 @@ import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 
 import org.apache.commons.lang.StringUtils;
+
+import org.apache.usergrid.corepersistence.index.IndexService;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.exception.ConflictException;
 import org.apache.usergrid.persistence.*;
@@ -109,9 +111,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private Injector injector;
     private final EntityIndex entityIndex;
     private final MetricsFactory metricsFactory;
+    private final IndexService indexService;
 
-    public CpEntityManagerFactory(
-            final CassandraService cassandraService, final CounterUtils counterUtils, final Injector injector) {
+    public CpEntityManagerFactory( final CassandraService cassandraService, final CounterUtils counterUtils,
+                                   final Injector injector) {
 
         this.cassandraService = cassandraService;
         this.counterUtils = counterUtils;
@@ -120,7 +123,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
         this.managerCache = injector.getInstance( ManagerCache.class );
         this.metricsFactory = injector.getInstance( MetricsFactory.class );
-        this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(getManagementEntityManager());
+        this.indexService = injector.getInstance( IndexService.class );
+        this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
+            getManagementEntityManager() );
+
     }
 
 
@@ -175,8 +181,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
 
     private EntityManager _getEntityManager( UUID applicationId ) {
-
-        EntityManager em = new CpEntityManager(cassandraService, counterUtils, managerCache, metricsFactory, applicationId );
+        EntityManager em = new CpEntityManager(cassandraService, counterUtils, indexService, managerCache, metricsFactory, applicationId );
         return em;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c530a2/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 3c72b60..a0a44b3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -30,6 +30,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.Assert;
 
+import org.apache.usergrid.corepersistence.index.IndexService;
 import org.apache.usergrid.corepersistence.results.CollectionResultsLoaderFactoryImpl;
 import org.apache.usergrid.corepersistence.results.ConnectionResultsLoaderFactoryImpl;
 import org.apache.usergrid.corepersistence.results.ElasticSearchQueryExecutor;
@@ -117,18 +118,23 @@ public class CpRelationManager implements RelationManager {
 
     private org.apache.usergrid.persistence.model.entity.Entity cpHeadEntity;
 
-    private ApplicationScope applicationScope;
+    private final ApplicationScope applicationScope;
+
+    private final IndexService indexService;
 
     private MetricsFactory metricsFactory;
     private Timer updateCollectionTimer;
 
 
-    public CpRelationManager(final MetricsFactory metricsFactory, final ManagerCache managerCache, final EntityManager em, final UUID applicationId, final EntityRef headEntity ) {
+    public CpRelationManager( final MetricsFactory metricsFactory, final ManagerCache managerCache, final IndexService indexService, final EntityManager em, final UUID applicationId, final EntityRef headEntity) {
+
 
         Assert.notNull( em, "Entity manager cannot be null" );
         Assert.notNull( applicationId, "Application Id cannot be null" );
         Assert.notNull( headEntity, "Head entity cannot be null" );
         Assert.notNull( headEntity.getUuid(), "Head entity uuid cannot be null" );
+        Assert.notNull( indexService, "indexService cannot be null" );
+
         // TODO: this assert should not be failing
         //Assert.notNull( indexBucketLocator, "indexBucketLocator cannot be null" );
         this.em = em;
@@ -155,6 +161,8 @@ public class CpRelationManager implements RelationManager {
         Assert.notNull( cpHeadEntity, String
             .format( "cpHeadEntity cannot be null for entity id %s, app id %s", entityId.getUuid(), applicationId ) );
 
+        this.indexService = indexService;
+
 
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c530a2/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
index 3a08034..6a87005 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
@@ -22,20 +22,22 @@ package org.apache.usergrid.corepersistence;
 
 import java.util.Properties;
 
+import javax.inject.Named;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
 
 import org.apache.commons.lang.StringUtils;
 
 import org.apache.usergrid.persistence.PersistenceModule;
 
+import com.google.common.base.Preconditions;
 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;
@@ -45,25 +47,28 @@ import me.prettyprint.cassandra.service.CassandraHostConfigurator;
 /**
  * Factory for configuring Guice then returning it
  */
-@Singleton
+@Component
 public class GuiceFactory implements FactoryBean<Injector> {
 
     private static final Logger logger = LoggerFactory.getLogger( GuiceFactory.class );
 
-    private final CassandraHostConfigurator chc;
+    @Autowired
+    private CassandraHostConfigurator chc;
 
-    private final Properties systemProperties;
+    @Autowired
+    @Named("properties")
+    private Properties systemProperties;
 
+    @Autowired
     private ApplicationContext applicationContext;
 
     private Injector injector;
 
 
-
-    public GuiceFactory( final ApplicationContext applicationContext, final CassandraHostConfigurator chc, final Properties systemProperties  ) {
-        this.chc = chc;
-        this.systemProperties = systemProperties;
-        this.applicationContext = applicationContext;
+    public GuiceFactory() {
+        //        this.chc = chc;
+        //        this.systemProperties = systemProperties;
+        //        this.applicationContext = applicationContext;
     }
 
 
@@ -83,15 +88,16 @@ public class GuiceFactory implements FactoryBean<Injector> {
             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 = ",";
+                hostsString += host.getHost() + ",";
             }
 
+            hostsString = hostsString.substring( 0, hostsString.length() - 1 );
+
             logger.info( "hostsString: " + hostsString );
 
             Properties cpProps = new Properties();
@@ -99,21 +105,14 @@ public class GuiceFactory implements FactoryBean<Injector> {
             // 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",  systemProperties.getProperty( "cassandra.cluster" ) );
 
-            String cassRemoteString = ( String ) systemProperties.getProperty( "cassandra.use_remote" );
-            if ( cassRemoteString != null && cassRemoteString.equals( "false" ) ) {
-                cpProps.put( "cassandra.embedded", "true" );
-            }
-            else {
-                cpProps.put( "cassandra.embedded", "false" );
-            }
+            cpProps.put( "cassandra.cluster_name", getAndValidateProperty( "cassandra.cluster" ) );
 
-            cpProps.put( "collections.keyspace.strategy.class",
-                systemProperties.getProperty( "cassandra.keyspace.strategy" ) );
+            cpProps
+                .put( "collections.keyspace.strategy.class", getAndValidateProperty( "cassandra.keyspace.strategy" ) );
 
             cpProps.put( "collections.keyspace.strategy.options",
-                systemProperties.getProperty( "cassandra.keyspace.replication" ) );
+                getAndValidateProperty( "cassandra.keyspace.replication" ) );
 
             logger.debug( "Set Cassandra properties for Core Persistence: " + cpProps.toString() );
 
@@ -128,14 +127,23 @@ public class GuiceFactory implements FactoryBean<Injector> {
         }
 
 
-
-        //this is seriously fugly, and needs removed we shouldn't be mixing spring and guice
-        injector = Guice.createInjector( new CoreModule(  ), new PersistenceModule( applicationContext ) );
+        //we have to inject a couple of spring beans into our Guice.  Wire it with PersistenceModule
+        injector = Guice.createInjector( new CoreModule(), new PersistenceModule( applicationContext ) );
 
         return injector;
     }
 
 
+    private String getAndValidateProperty( final String propName ) {
+
+        final String propValue = systemProperties.getProperty( propName );
+
+        Preconditions.checkNotNull( propValue, propName + " cannot be unset. Set this in your properties" );
+
+        return propValue;
+    }
+
+
     @Override
     public Class<?> getObjectType() {
         return Injector.class;
@@ -146,6 +154,4 @@ public class GuiceFactory implements FactoryBean<Injector> {
     public boolean isSingleton() {
         return true;
     }
-
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c530a2/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java b/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java
index 6e58676..70fff90 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java
@@ -20,32 +20,15 @@
 package org.apache.usergrid.persistence;
 
 
-import java.io.IOException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.Collection;
-import java.util.Properties;
-
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.ListableBeanFactory;
 import org.springframework.context.ApplicationContext;
 
-import org.apache.usergrid.locking.cassandra.HectorLockManagerImpl;
 
-import com.google.common.base.Preconditions;
-import com.google.common.io.CharSource;
-import com.google.common.io.Resources;
 import com.google.inject.AbstractModule;
-import com.google.inject.Inject;
-import com.google.inject.Provides;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
-import com.google.inject.name.Names;
+import com.google.inject.Provider;
 import com.google.inject.spring.SpringIntegration;
 
-import me.prettyprint.cassandra.connection.RoundRobinBalancingPolicy;
-import me.prettyprint.cassandra.service.CassandraHostConfigurator;
-import me.prettyprint.cassandra.service.ThriftCluster;
-import me.prettyprint.hector.api.Cluster;
-
 
 /**
  * Replacement for configuration of our spring modules with guice
@@ -66,97 +49,18 @@ public class PersistenceModule extends AbstractModule {
 
     @Override
     protected void configure() {
-        SpringIntegration.bindAll( binder(), applicationContext );
-    }
 
+        //bind the application context to our guice instance
+
+        final BeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
+        bind( BeanFactory.class).toInstance( beanFactory);
+
+        //create our bridge and put the EMF into guice.  Ultimately all spring needs removed and we need to just use guice
+
+        final Provider<EntityManagerFactory> emfProvider = SpringIntegration.fromSpring( EntityManagerFactory.class, "entityManagerFactory" );
+
+        bind( EntityManagerFactory.class ).toProvider(  emfProvider );
+    }
 
 
-//    <bean id="cassandraCluster" class="me.prettyprint.cassandra.service.ThriftCluster">
-//   		<constructor-arg value="${cassandra.cluster}" />
-//   		<constructor-arg ref="cassandraHostConfigurator" />
-//   	</bean>
-//    @Provides
-//    @Singleton
-//    @Inject
-//    public Cluster configureThrift( @Named( "cassandra.cluster" ) final String cassCluster,
-//                                          @Named( "cassandra.connections" ) final int cassandraConnections ){
-//
-//        final int setSize = cassandraConnections == 0 ? 50: cassandraConnections;
-//
-//        CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator( cassCluster );
-//
-//        hostConfigurator.setMaxActive( setSize );
-//        hostConfigurator.setLoadBalancingPolicy( new RoundRobinBalancingPolicy() );
-//
-//
-//        ThriftCluster thriftCluster = new ThriftCluster(cassCluster, hostConfigurator);
-//
-//        return thriftCluster;
-//
-//    }
-//
-//
-//    @Provides
-//    @Singleton
-//    @Inject
-//    public Properties configureProps(final PropertiesProvider propertiesProvider ){
-//
-//        final Properties props = new Properties(  );
-//
-//        for(final String propFile: propertiesProvider.getPropertiesFiles()){
-//
-//            final URL url = Resources.getResource( propFile );
-//
-//            Preconditions.checkNotNull( url, "Could not find properties file '" + propFile + "' on the classpath" );
-//
-//
-//            final CharSource propsInput = Resources.asCharSource( url, Charset.defaultCharset() );
-//            try {
-//                props.load( propsInput.openStream() );
-//            }
-//            catch ( IOException e ) {
-//                throw new RuntimeException( "Unable to load properties file '" + propFile + "'", e );
-//            }
-//        }
-//
-//        //bind these properties
-//        Names.bindProperties( binder(), props );
-//
-//        return props;
-//    }
-//
-//    @Provides
-//    @Singleton
-//    @Inject
-//    public void configureLocks(final Cluster hectorCluster, @Named("cassandra.lock.keyspace") final String lockKeyspace, @Named("cassandra.lock.keyspace") final String writeCl, final String readCl ){
-//
-//
-//        final HectorLockManagerImpl hectorLockManager = new HectorLockManagerImpl();
-//
-//
-////
-////        <bean name="consistencyLevelPolicy" class="me.prettyprint.cassandra.model.ConfigurableConsistencyLevel">
-////               <property name="defaultReadConsistencyLevel" value="${cassandra.readcl}"/>
-////               <property name="defaultWriteConsistencyLevel" value="${cassandra.writecl}"/>
-////           </bean>
-//
-////        <bean name="lockManager" class="org.apache.usergrid.locking.cassandra.HectorLockManagerImpl" >
-////       		<property name="cluster" ref="cassandraCluster"/>
-////       		<property name="keyspaceName" value="${cassandra.lock.keyspace}"/>
-////       		<property name="consistencyLevelPolicy" ref="consistencyLevelPolicy"/>
-////       	</bean>
-//
-//    }
-//
-//
-//    /**
-//     * Interface to allow users to provide and inject properties
-//     */
-//    public interface PropertiesProvider{
-//        /**
-//         * Get the properties files to load
-//         * @return
-//         */
-//        String[] getPropertiesFiles();
-//    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c530a2/stack/core/src/main/resources/usergrid-core-context.xml
----------------------------------------------------------------------
diff --git a/stack/core/src/main/resources/usergrid-core-context.xml b/stack/core/src/main/resources/usergrid-core-context.xml
index 0be6d00..f33586f 100644
--- a/stack/core/src/main/resources/usergrid-core-context.xml
+++ b/stack/core/src/main/resources/usergrid-core-context.xml
@@ -95,10 +95,14 @@
 
     <bean id="injector"
    		class="org.apache.usergrid.corepersistence.GuiceFactory">
-   		<constructor-arg ref="cassandraHostConfigurator" />
-        <constructor-arg ref="properties" />
     </bean>
 
+    <!--  <bean id="injector"
+       		class="org.apache.usergrid.corepersistence.GuiceFactory">
+       		<constructor-arg ref="cassandraHostConfigurator" />
+            <constructor-arg ref="properties" />
+        </bean>-->
+
 	<bean id="cassandraService"
 		class="org.apache.usergrid.persistence.cassandra.CassandraService" init-method="init" destroy-method="destroy">
 		<constructor-arg ref="properties" />

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c530a2/stack/core/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --git a/stack/core/src/test/resources/usergrid-custom-test.properties b/stack/core/src/test/resources/usergrid-custom-test.properties
index 93ef28b..703424f 100644
--- a/stack/core/src/test/resources/usergrid-custom-test.properties
+++ b/stack/core/src/test/resources/usergrid-custom-test.properties
@@ -14,8 +14,6 @@
 
 # these settings allow tests to run and consistently pass on 16GB MacBook Pro
 # with ug.heapmax=5000m and ug.heapmin=3000m (set in Maven settings.xml)
-cassandra.startup=external
-elasticsearch.startup=external
 cassandra.timeout=2000
 cassandra.connections=1000
 


[2/3] incubator-usergrid git commit: WIP overwrite

Posted by to...@apache.org.
WIP overwrite


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/bd1b371a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/bd1b371a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/bd1b371a

Branch: refs/heads/USERGRID-541
Commit: bd1b371a27c1befc5e1aea6410ed3d548548185d
Parents: cfcbc74
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Apr 16 17:57:17 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Apr 16 17:57:17 2015 -0600

----------------------------------------------------------------------
 stack/core/pom.xml                              |   8 +
 .../usergrid/corepersistence/CoreModule.java    |   5 +-
 .../corepersistence/CpEntityManagerFactory.java |   2 +-
 .../usergrid/corepersistence/GuiceFactory.java  |  17 +-
 .../ManagementEntityManagerProvider.java        |  44 -----
 .../persistence/GuiceAdapterBeanFactory.java    | 114 +++++++++++++
 .../usergrid/persistence/PersistenceModule.java | 162 +++++++++++++++++++
 .../corepersistence/TestIndexModule.java        |  14 +-
 8 files changed, 294 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd1b371a/stack/core/pom.xml
----------------------------------------------------------------------
diff --git a/stack/core/pom.xml b/stack/core/pom.xml
index 6f3c381..3504be4 100644
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@ -163,6 +163,14 @@
 
   <dependencies>
 
+
+      <!-- dependent on wiring guice and spring -->
+      <dependency>
+          <groupId>com.google.inject.extensions</groupId>
+          <artifactId>guice-spring</artifactId>
+          <version>4.0-beta5</version>
+      </dependency>
+
     <!-- Apache Dependencies -->
 
     <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd1b371a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index 545de43..7e8af87 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -22,6 +22,7 @@ import org.apache.usergrid.corepersistence.index.IndexServiceImpl;
 import org.apache.usergrid.corepersistence.index.QueryFig;
 import org.apache.usergrid.corepersistence.index.QueueProvider;
 import org.apache.usergrid.corepersistence.migration.*;
+import org.apache.usergrid.persistence.PersistenceModule;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.safehaus.guicyfig.GuicyFigModule;
 import org.springframework.context.ApplicationContext;
@@ -67,10 +68,6 @@ public class CoreModule  extends AbstractModule {
 
 
 
-    public CoreModule( ) {
-
-    }
-
     @Override
     protected void configure() {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd1b371a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 8741a8c..e03ed47 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -176,7 +176,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     private EntityManager _getEntityManager( UUID applicationId ) {
 
-        EntityManager em = new CpEntityManager(cassandraService, counterUtils,managerCache, metricsFactory, applicationId );
+        EntityManager em = new CpEntityManager(cassandraService, counterUtils, managerCache, metricsFactory, applicationId );
         return em;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd1b371a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
index fe09a38..3a08034 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
@@ -31,8 +31,7 @@ import org.springframework.context.ApplicationContextAware;
 
 import org.apache.commons.lang.StringUtils;
 
-import org.apache.usergrid.persistence.cassandra.CassandraService;
-import org.apache.usergrid.persistence.core.guice.CommonModule;
+import org.apache.usergrid.persistence.PersistenceModule;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -47,7 +46,7 @@ import me.prettyprint.cassandra.service.CassandraHostConfigurator;
  * Factory for configuring Guice then returning it
  */
 @Singleton
-public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAware {
+public class GuiceFactory implements FactoryBean<Injector> {
 
     private static final Logger logger = LoggerFactory.getLogger( GuiceFactory.class );
 
@@ -55,16 +54,16 @@ public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAw
 
     private final Properties systemProperties;
 
-
     private ApplicationContext applicationContext;
 
     private Injector injector;
 
 
 
-    public GuiceFactory( final CassandraHostConfigurator chc, final Properties systemProperties  ) {
+    public GuiceFactory( final ApplicationContext applicationContext, final CassandraHostConfigurator chc, final Properties systemProperties  ) {
         this.chc = chc;
         this.systemProperties = systemProperties;
+        this.applicationContext = applicationContext;
     }
 
 
@@ -128,8 +127,10 @@ public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAw
             throw new RuntimeException( "Fatal error loading configuration.", e );
         }
 
+
+
         //this is seriously fugly, and needs removed we shouldn't be mixing spring and guice
-        injector = Guice.createInjector( new CoreModule( ) );
+        injector = Guice.createInjector( new CoreModule(  ), new PersistenceModule( applicationContext ) );
 
         return injector;
     }
@@ -147,8 +148,4 @@ public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAw
     }
 
 
-    @Override
-    public void setApplicationContext( final ApplicationContext applicationContext ) throws BeansException {
-        this.applicationContext = applicationContext;
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd1b371a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagementEntityManagerProvider.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagementEntityManagerProvider.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagementEntityManagerProvider.java
deleted file mode 100644
index 666c927..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagementEntityManagerProvider.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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 org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-
-import com.google.inject.Provider;
-import com.google.inject.Singleton;
-
-
-@Singleton
-public class ManagementEntityManagerProvider implements Provider<EntityManager> {
-
-
-
-    @Override
-    @Singleton
-    public EntityManager get() {
-
-        CpNamingUtils.MANAGEMENT_APPLICATION_ID);
-
-        final EntityManager em = new CpEntityManager(  );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd1b371a/stack/core/src/main/java/org/apache/usergrid/persistence/GuiceAdapterBeanFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/GuiceAdapterBeanFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/GuiceAdapterBeanFactory.java
new file mode 100644
index 0000000..8bda3b0
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/GuiceAdapterBeanFactory.java
@@ -0,0 +1,114 @@
+/*
+ * 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.persistence;
+
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+import com.google.inject.Injector;
+
+
+/**
+ * This allows us to search guice for beans that are not in spring
+ */
+@Component
+public class GuiceAdapterBeanFactory extends DefaultListableBeanFactory {
+
+    /**
+     * Wire our injector into this so we can use it go get beans
+     */
+    @Autowired
+    private Injector injector;
+
+
+    public <T> T getBean( Class<T> requiredType ) throws BeansException {
+        final T bean = super.getBean( requiredType );
+
+        // Comes from spring, return it
+        if ( bean != null ) {
+            return bean;
+        }
+
+        final T guiceBean = injector.getInstance( requiredType );
+
+        if(guiceBean == null){
+            throw new NoGuiceBean( "Could not find bean for class" + requiredType );
+        }
+
+
+        return guiceBean;
+    }
+
+
+    @Override
+    public Object getBean( final String name ) throws BeansException {
+        final Object springBean = super.getBean( name );
+
+        return validateBean( springBean, name );
+    }
+
+
+    @Override
+    public <T> T getBean( final String name, final Class<T> requiredType ) throws BeansException {
+        final T springBean = super.getBean( name, requiredType );
+
+        return validateBean( springBean, name );
+    }
+
+
+    @Override
+    public <T> T getBean( final String name, final Class<T> requiredType, final Object... args ) throws BeansException {
+        final T springBean = super.getBean( name, requiredType, args );
+
+       return validateBean( springBean, name );
+    }
+
+
+    /**
+     * If we can't find the spring bean, we should blow up
+     * @param springBean
+     * @param <T>
+     * @return
+     */
+    private <T> T validateBean( T springBean, final String name ) {
+        if ( springBean == null ) {
+            throw new NoGuiceBean( String.format("Guice beans by name is unsupoported, and could not find a spring bean with the name '%s'", name) );
+        }
+
+        return springBean;
+    }
+
+
+    /**
+     * Exception class to throw when we can't find a bean in spring, and can't find it in guice
+     */
+    public static final class NoGuiceBean extends BeansException{
+
+        public NoGuiceBean( final String msg ) {
+            super( msg );
+        }
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd1b371a/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java b/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java
new file mode 100644
index 0000000..6e58676
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/PersistenceModule.java
@@ -0,0 +1,162 @@
+/*
+ * 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.persistence;
+
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.Properties;
+
+import org.springframework.context.ApplicationContext;
+
+import org.apache.usergrid.locking.cassandra.HectorLockManagerImpl;
+
+import com.google.common.base.Preconditions;
+import com.google.common.io.CharSource;
+import com.google.common.io.Resources;
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+import com.google.inject.name.Names;
+import com.google.inject.spring.SpringIntegration;
+
+import me.prettyprint.cassandra.connection.RoundRobinBalancingPolicy;
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
+import me.prettyprint.cassandra.service.ThriftCluster;
+import me.prettyprint.hector.api.Cluster;
+
+
+/**
+ * Replacement for configuration of our spring modules with guice
+ */
+public class PersistenceModule extends AbstractModule {
+
+
+
+    private final ApplicationContext applicationContext;
+
+    public PersistenceModule( final ApplicationContext applicationContext ) {
+
+        this.applicationContext = applicationContext;
+    }
+
+
+
+
+    @Override
+    protected void configure() {
+        SpringIntegration.bindAll( binder(), applicationContext );
+    }
+
+
+
+//    <bean id="cassandraCluster" class="me.prettyprint.cassandra.service.ThriftCluster">
+//   		<constructor-arg value="${cassandra.cluster}" />
+//   		<constructor-arg ref="cassandraHostConfigurator" />
+//   	</bean>
+//    @Provides
+//    @Singleton
+//    @Inject
+//    public Cluster configureThrift( @Named( "cassandra.cluster" ) final String cassCluster,
+//                                          @Named( "cassandra.connections" ) final int cassandraConnections ){
+//
+//        final int setSize = cassandraConnections == 0 ? 50: cassandraConnections;
+//
+//        CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator( cassCluster );
+//
+//        hostConfigurator.setMaxActive( setSize );
+//        hostConfigurator.setLoadBalancingPolicy( new RoundRobinBalancingPolicy() );
+//
+//
+//        ThriftCluster thriftCluster = new ThriftCluster(cassCluster, hostConfigurator);
+//
+//        return thriftCluster;
+//
+//    }
+//
+//
+//    @Provides
+//    @Singleton
+//    @Inject
+//    public Properties configureProps(final PropertiesProvider propertiesProvider ){
+//
+//        final Properties props = new Properties(  );
+//
+//        for(final String propFile: propertiesProvider.getPropertiesFiles()){
+//
+//            final URL url = Resources.getResource( propFile );
+//
+//            Preconditions.checkNotNull( url, "Could not find properties file '" + propFile + "' on the classpath" );
+//
+//
+//            final CharSource propsInput = Resources.asCharSource( url, Charset.defaultCharset() );
+//            try {
+//                props.load( propsInput.openStream() );
+//            }
+//            catch ( IOException e ) {
+//                throw new RuntimeException( "Unable to load properties file '" + propFile + "'", e );
+//            }
+//        }
+//
+//        //bind these properties
+//        Names.bindProperties( binder(), props );
+//
+//        return props;
+//    }
+//
+//    @Provides
+//    @Singleton
+//    @Inject
+//    public void configureLocks(final Cluster hectorCluster, @Named("cassandra.lock.keyspace") final String lockKeyspace, @Named("cassandra.lock.keyspace") final String writeCl, final String readCl ){
+//
+//
+//        final HectorLockManagerImpl hectorLockManager = new HectorLockManagerImpl();
+//
+//
+////
+////        <bean name="consistencyLevelPolicy" class="me.prettyprint.cassandra.model.ConfigurableConsistencyLevel">
+////               <property name="defaultReadConsistencyLevel" value="${cassandra.readcl}"/>
+////               <property name="defaultWriteConsistencyLevel" value="${cassandra.writecl}"/>
+////           </bean>
+//
+////        <bean name="lockManager" class="org.apache.usergrid.locking.cassandra.HectorLockManagerImpl" >
+////       		<property name="cluster" ref="cassandraCluster"/>
+////       		<property name="keyspaceName" value="${cassandra.lock.keyspace}"/>
+////       		<property name="consistencyLevelPolicy" ref="consistencyLevelPolicy"/>
+////       	</bean>
+//
+//    }
+//
+//
+//    /**
+//     * Interface to allow users to provide and inject properties
+//     */
+//    public interface PropertiesProvider{
+//        /**
+//         * Get the properties files to load
+//         * @return
+//         */
+//        String[] getPropertiesFiles();
+//    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd1b371a/stack/core/src/test/java/org/apache/usergrid/corepersistence/TestIndexModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/TestIndexModule.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/TestIndexModule.java
index 6a98af6..e5254d1 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/TestIndexModule.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/TestIndexModule.java
@@ -19,19 +19,7 @@
 package org.apache.usergrid.corepersistence;
 
 
-import org.safehaus.guicyfig.GuicyFigModule;
-
-import org.apache.usergrid.persistence.core.guice.CommonModule;
 import org.apache.usergrid.persistence.core.guice.TestModule;
-import org.apache.usergrid.persistence.core.migration.data.MigrationDataProvider;
-import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.index.guice.IndexModule;
-import org.apache.usergrid.persistence.index.guice.IndexTestFig;
-
-import com.google.inject.Inject;
-import com.google.inject.TypeLiteral;
-
-import rx.Observable;
 
 
 public class TestIndexModule extends TestModule {
@@ -40,7 +28,7 @@ public class TestIndexModule extends TestModule {
     protected void configure() {
 
         //this will break, we need to untagle this and move to guice in core completely
-        install( new CoreModule());
+        install( new CoreModule( ));
     }