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:27 UTC
[2/3] incubator-usergrid git commit: WIP overwrite
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( ));
}