You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/28 14:20:45 UTC
[1/3] git commit: Changes to injected types in Graph module to allow
use in Core.
Repository: incubator-usergrid
Updated Branches:
refs/heads/entity-manager c66283827 -> 9954c2b33
Changes to injected types in Graph module to allow use in Core.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e993b4ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e993b4ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e993b4ca
Branch: refs/heads/entity-manager
Commit: e993b4ca1fc43820e54e14c4340b4df3859dd0c7
Parents: c662838
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 28 08:30:37 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 28 08:30:37 2014 -0400
----------------------------------------------------------------------
.../usergrid/corepersistence/GuiceModule.java | 142 +++++++++++++++++++
.../graph/impl/EdgeDeleteListener.java | 12 +-
.../graph/impl/GraphManagerImpl.java | 16 ++-
.../graph/GraphManagerTimeoutIT.java | 15 +-
4 files changed, 161 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e993b4ca/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
new file mode 100644
index 0000000..b10290b
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed 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 com.google.inject.AbstractModule;
+import com.google.inject.TypeLiteral;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.multibindings.Multibinder;
+import org.apache.usergrid.persistence.collection.guice.CollectionModule;
+import org.apache.usergrid.persistence.collection.migration.Migration;
+import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessObserver;
+import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphFig;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
+import org.apache.usergrid.persistence.graph.consistency.AsyncProcessorImpl;
+import org.apache.usergrid.persistence.graph.consistency.LocalTimeoutQueue;
+import org.apache.usergrid.persistence.graph.consistency.TimeService;
+import org.apache.usergrid.persistence.graph.consistency.TimeoutQueue;
+import org.apache.usergrid.persistence.graph.guice.EdgeDelete;
+import org.apache.usergrid.persistence.graph.guice.NodeDelete;
+import org.apache.usergrid.persistence.graph.impl.CollectionIndexObserver;
+import org.apache.usergrid.persistence.graph.impl.EdgeEvent;
+import org.apache.usergrid.persistence.graph.impl.GraphManagerImpl;
+import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepair;
+import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepairImpl;
+import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepair;
+import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepairImpl;
+import org.apache.usergrid.persistence.graph.serialization.CassandraConfig;
+import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
+import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
+import org.apache.usergrid.persistence.graph.serialization.NodeSerialization;
+import org.apache.usergrid.persistence.graph.serialization.impl.CassandraConfigImpl;
+import org.apache.usergrid.persistence.graph.serialization.impl.EdgeMetadataSerializationImpl;
+import org.apache.usergrid.persistence.graph.serialization.impl.EdgeSerializationImpl;
+import org.apache.usergrid.persistence.graph.serialization.impl.NodeSerializationImpl;
+import org.apache.usergrid.persistence.index.EntityCollectionIndex;
+import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
+import org.apache.usergrid.persistence.index.IndexFig;
+import org.apache.usergrid.persistence.index.impl.EsEntityCollectionIndex;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.safehaus.guicyfig.GuicyFigModule;
+
+
+
+/**
+ * Guice Module that encapsulates Core Persistence.
+ */
+public class GuiceModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+
+ //------------
+ // COLLECTION
+ //
+
+ // configure collections and our core astyanax framework
+ install(new CollectionModule());
+
+ //------------
+ // INDEX
+ //
+
+ install (new GuicyFigModule( IndexFig.class ));
+
+ install( new FactoryModuleBuilder()
+ .implement( EntityCollectionIndex.class, EsEntityCollectionIndex.class )
+ .build( EntityCollectionIndexFactory.class ) );
+
+ //------------
+ // GRAPH
+ //
+
+ //install our configuration
+ install (new GuicyFigModule( GraphFig.class ));
+
+ bind( PostProcessObserver.class ).to( CollectionIndexObserver.class );
+
+ bind( EdgeMetadataSerialization.class).to( EdgeMetadataSerializationImpl.class);
+ bind( EdgeSerialization.class).to( EdgeSerializationImpl.class );
+ bind( NodeSerialization.class).to( NodeSerializationImpl.class );
+
+ bind( CassandraConfig.class).to( CassandraConfigImpl.class );
+
+ // create a guice factory for getting our collection manager
+ install( new FactoryModuleBuilder().implement( GraphManager.class, GraphManagerImpl.class )
+ .build( GraphManagerFactory.class ) );
+
+ //do multibindings for migrations
+ Multibinder<Migration> migrationBinding = Multibinder.newSetBinder( binder(), Migration.class );
+ migrationBinding.addBinding().to( EdgeMetadataSerializationImpl.class );
+ migrationBinding.addBinding().to( EdgeSerializationImpl.class );
+ migrationBinding.addBinding().to( NodeSerializationImpl.class );
+
+ // Graph event bus, will need to be refactored into it's own classes
+
+ // create a guice factor for getting our collection manager
+
+ // TODO: figure out why all this is necessary here but not in GraphModule
+ bind( new TypeLiteral<TimeoutQueue<Edge>>(){} )
+ .to( new TypeLiteral<LocalTimeoutQueue<Edge>>(){} );
+
+ bind( new TypeLiteral<TimeoutQueue<EdgeEvent<Edge>>>(){} )
+ .to( new TypeLiteral<LocalTimeoutQueue<EdgeEvent<Edge>>>(){} );
+
+ bind( new TypeLiteral<TimeoutQueue<Id>>(){} )
+ .to( new TypeLiteral<LocalTimeoutQueue<Id>>(){} );
+
+ bind( new TypeLiteral<AsyncProcessor<Edge>>(){} )
+ .annotatedWith( EdgeDelete.class )
+ .to( new TypeLiteral<AsyncProcessorImpl<Edge>>(){} );
+
+ bind( new TypeLiteral<AsyncProcessor<EdgeEvent<Edge>>>(){} )
+ .annotatedWith( EdgeDelete.class )
+ .to( new TypeLiteral<AsyncProcessorImpl<EdgeEvent<Edge>>>(){} );
+
+ bind( new TypeLiteral<AsyncProcessor<Id>>(){} )
+ .annotatedWith( NodeDelete.class )
+ .to( new TypeLiteral<AsyncProcessorImpl<Id>>(){} );
+
+ //Repair/cleanup classes
+ bind( EdgeMetaRepair.class).to( EdgeMetaRepairImpl.class );
+ bind( EdgeDeleteRepair.class).to( EdgeDeleteRepairImpl.class );
+ bind( TimeService.class).to( TimeServiceImpl.class );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e993b4ca/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
index 11c052b..c519207 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
@@ -41,10 +41,14 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
@Inject
- public EdgeDeleteListener( final EdgeSerialization edgeSerialization,
- final EdgeMetadataSerialization edgeMetadataSerialization,
- final GraphManagerFactory graphManagerFactory, final Keyspace keyspace,
- @EdgeDelete final AsyncProcessor edgeDelete, final GraphFig graphFig ) {
+ public EdgeDeleteListener(
+ final EdgeSerialization edgeSerialization,
+ final EdgeMetadataSerialization edgeMetadataSerialization,
+ final GraphManagerFactory graphManagerFactory,
+ final Keyspace keyspace,
+ @EdgeDelete final AsyncProcessor<EdgeEvent<Edge>> edgeDelete,
+ final GraphFig graphFig ) {
+
this.edgeSerialization = edgeSerialization;
this.edgeMetadataSerialization = edgeMetadataSerialization;
this.graphManagerFactory = graphManagerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e993b4ca/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
index ad7f67b..037e99b 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
@@ -54,6 +54,7 @@ import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import org.apache.usergrid.persistence.model.entity.Entity;
import rx.Observable;
import rx.functions.Func1;
@@ -82,11 +83,14 @@ public class GraphManagerImpl implements GraphManager {
@Inject
- public GraphManagerImpl( final EdgeMetadataSerialization edgeMetadataSerialization,
- final EdgeSerialization edgeSerialization, final NodeSerialization nodeSerialization,
- final GraphFig graphFig,
- @EdgeDelete final AsyncProcessor edgeDelete, @NodeDelete final AsyncProcessor nodeDelete,
- @Assisted final OrganizationScope scope ) {
+ public GraphManagerImpl(
+ final EdgeMetadataSerialization edgeMetadataSerialization,
+ final EdgeSerialization edgeSerialization,
+ final NodeSerialization nodeSerialization,
+ final GraphFig graphFig,
+ @EdgeDelete final AsyncProcessor<Edge> edgeDelete,
+ @NodeDelete final AsyncProcessor<Id> nodeDelete,
+ @Assisted final OrganizationScope scope ) {
ValidationUtils.validateOrganizationScope( scope );
@@ -97,10 +101,8 @@ public class GraphManagerImpl implements GraphManager {
this.nodeSerialization = nodeSerialization;
this.graphFig = graphFig;
-
this.edgeDeleteAsyncProcessor = edgeDelete;
-
this.nodeDeleteAsyncProcessor = nodeDelete;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e993b4ca/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
index 8685b65..7153e74 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
@@ -23,12 +23,10 @@ package org.apache.usergrid.persistence.graph;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
-import org.jukito.All;
import org.jukito.JukitoRunner;
import org.jukito.UseModules;
import org.junit.Before;
@@ -36,18 +34,13 @@ import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.apache.usergrid.persistence.collection.OrganizationScope;
import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
-import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
-import org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType;
import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import com.google.inject.Inject;
@@ -57,12 +50,8 @@ import rx.Observable;
import rx.Subscriber;
import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdgeAndId;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@@ -129,7 +118,7 @@ public class GraphManagerTimeoutIT {
SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
- final MockingIterator<MarkedEdge> itr = new MockingIterator<>( Collections.singletonList( edge ) );
+ final Iterator<MarkedEdge> itr = new MockingIterator<>( Collections.singletonList( edge ) );
//TODO, T.N. replace this with a different mock, the spies don't work with multi threading like RX
@@ -179,7 +168,7 @@ public class GraphManagerTimeoutIT {
}
- private class MockingIterator<T> implements Iterator<T> {
+ private static class MockingIterator<T> implements Iterator<T> {
private final Iterator<T> items;
[2/3] git commit: Minor refactoring of EntityBuilder to
EntityMapUtils.
Posted by sn...@apache.org.
Minor refactoring of EntityBuilder to EntityMapUtils.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/7bbfd1e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/7bbfd1e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/7bbfd1e3
Branch: refs/heads/entity-manager
Commit: 7bbfd1e3713ffb682fadf97639d4bee0f3d2c291
Parents: e993b4c
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 28 08:31:39 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 28 08:31:39 2014 -0400
----------------------------------------------------------------------
.../index/impl/EsEntityCollectionIndex.java | 92 +------
.../index/legacy/EntityManagerFacade.java | 4 +-
.../persistence/index/utils/EntityMapUtils.java | 265 +++++++++++++++++++
.../index/impl/EntityCollectionIndexTest.java | 10 +-
4 files changed, 274 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7bbfd1e3/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
index 3c0239c..2ae1ef8 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
@@ -22,11 +22,8 @@ import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.lang3.time.StopWatch;
@@ -40,15 +37,9 @@ import org.apache.usergrid.persistence.index.IndexFig;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.field.ArrayField;
-import org.apache.usergrid.persistence.model.field.EntityObjectField;
-import org.apache.usergrid.persistence.model.field.Field;
-import org.apache.usergrid.persistence.model.field.ListField;
-import org.apache.usergrid.persistence.model.field.LocationField;
-import org.apache.usergrid.persistence.model.field.SetField;
-import org.apache.usergrid.persistence.model.field.StringField;
import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.index.query.Results;
+import org.apache.usergrid.persistence.index.utils.EntityMapUtils;
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
@@ -203,7 +194,7 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
timer.start();
}
- Map<String, Object> entityAsMap = EsEntityCollectionIndex.entityToMap(entity);
+ Map<String, Object> entityAsMap = EntityMapUtils.toMap(entity);
entityAsMap.put("created", entity.getId().getUuid().timestamp());
entityAsMap.put("updated", entity.getVersion().timestamp());
@@ -331,85 +322,6 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
return results;
}
- /**
- * Convert Entity to Map, adding version_ug_field and a {name}_ug_analyzed field for each
- * StringField.
- */
- public static Map entityToMap(Entity entity) {
-
- Map<String, Object> entityMap = new HashMap<String, Object>();
-
- for (Object f : entity.getFields().toArray()) {
- Field field = (Field) f;
-
- if (f instanceof ListField || f instanceof ArrayField) {
- List list = (List) field.getValue();
- entityMap.put(field.getName(),
- new ArrayList(processCollectionForMap(list)));
-
- } else if (f instanceof SetField) {
- Set set = (Set) field.getValue();
- entityMap.put(field.getName(),
- new ArrayList(processCollectionForMap(set)));
-
- } else if (f instanceof EntityObjectField) {
- Entity ev = (Entity) field.getValue();
- entityMap.put(field.getName(), entityToMap(ev)); // recursion
-
- } else if (f instanceof StringField) {
- // index in lower case because Usergrid queries are case insensitive
- entityMap.put(field.getName(), ((String) field.getValue()).toLowerCase());
- entityMap.put(field.getName() + ANALYZED_SUFFIX, field.getValue());
-
- } else if (f instanceof LocationField) {
- LocationField locField = (LocationField) f;
- Map<String, Object> locMap = new HashMap<String, Object>();
-
- // field names lat and lon trigger ElasticSearch geo location
- locMap.put("lat", locField.getValue().getLatitude());
- locMap.put("lon", locField.getValue().getLongtitude());
- entityMap.put(field.getName() + GEO_SUFFIX, locMap);
-
- } else {
- entityMap.put(field.getName(), field.getValue());
- }
- }
-
- return entityMap;
- }
-
- private static Collection processCollectionForMap(Collection c) {
- if (c.isEmpty()) {
- return c;
- }
- List processed = new ArrayList();
- Object sample = c.iterator().next();
-
- if (sample instanceof Entity) {
- for (Object o : c.toArray()) {
- Entity e = (Entity) o;
- processed.add(entityToMap(e));
- }
-
- } else if (sample instanceof List) {
- for (Object o : c.toArray()) {
- List list = (List) o;
- processed.add(processCollectionForMap(list)); // recursion;
- }
-
- } else if (sample instanceof Set) {
- for (Object o : c.toArray()) {
- Set set = (Set) o;
- processed.add(processCollectionForMap(set)); // recursion;
- }
-
- } else {
- for (Object o : c.toArray()) {
- processed.add(o);
- }
- }
- return processed;
- }
/**
* Build mappings for data to be indexed. Setup String fields as not_analyzed and analyzed,
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7bbfd1e3/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
index 912978f..57a1912 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
@@ -17,7 +17,7 @@
*/
package org.apache.usergrid.persistence.index.legacy;
-import org.apache.usergrid.persistence.index.utils.EntityBuilder;
+import org.apache.usergrid.persistence.index.utils.EntityMapUtils;
import java.util.HashMap;
import java.util.Map;
import org.apache.usergrid.persistence.collection.CollectionScope;
@@ -101,7 +101,7 @@ public class EntityManagerFacade {
typesByCollectionNames.put( collectionName, type );
Entity entity = new Entity(new SimpleId(UUIDGenerator.newTimeUUID(), type ));
- entity = EntityBuilder.fromMap( scope.getName(), entity, properties );
+ entity = EntityMapUtils.fromMap( entity, properties );
entity.setField(new LongField("created", entity.getId().getUuid().timestamp()) );
entity.setField(new LongField("modified", entity.getId().getUuid().timestamp()) );
entity = ecm.write( entity ).toBlockingObservable().last();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7bbfd1e3/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityMapUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityMapUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityMapUtils.java
new file mode 100644
index 0000000..23f67eb
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityMapUtils.java
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+
+package org.apache.usergrid.persistence.index.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import static org.apache.usergrid.persistence.index.impl.EsEntityCollectionIndex.ANALYZED_SUFFIX;
+import static org.apache.usergrid.persistence.index.impl.EsEntityCollectionIndex.GEO_SUFFIX;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.field.ArrayField;
+import org.apache.usergrid.persistence.model.field.BooleanField;
+import org.apache.usergrid.persistence.model.field.DoubleField;
+import org.apache.usergrid.persistence.model.field.EntityObjectField;
+import org.apache.usergrid.persistence.model.field.Field;
+import org.apache.usergrid.persistence.model.field.FloatField;
+import org.apache.usergrid.persistence.model.field.IntegerField;
+import org.apache.usergrid.persistence.model.field.ListField;
+import org.apache.usergrid.persistence.model.field.LocationField;
+import org.apache.usergrid.persistence.model.field.LongField;
+import org.apache.usergrid.persistence.model.field.SetField;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.field.value.Location;
+
+
+public class EntityMapUtils {
+
+ public static Entity fromMap( Map<String, Object> item ) {
+ return fromMap( null, item );
+ }
+
+ public static Entity fromMap( Entity entity, Map<String, Object> map ) {
+
+ if ( entity == null ) {
+ entity = new Entity();
+ }
+
+ for ( String fieldName : map.keySet() ) {
+
+ Object value = map.get( fieldName );
+
+ if ( value instanceof String ) {
+ entity.setField( new StringField( fieldName, (String)value ));
+
+ } else if ( value instanceof Boolean ) {
+ entity.setField( new BooleanField( fieldName, (Boolean)value ));
+
+ } else if ( value instanceof Integer ) {
+ entity.setField( new IntegerField( fieldName, (Integer)value ));
+
+ } else if ( value instanceof Double ) {
+ entity.setField( new DoubleField( fieldName, (Double)value ));
+
+ } else if ( value instanceof Float ) {
+ entity.setField( new FloatField( fieldName, (Float)value ));
+
+ } else if ( value instanceof Long ) {
+ entity.setField( new LongField( fieldName, (Long)value ));
+
+ } else if ( value instanceof List) {
+ entity.setField( listToListField( fieldName, (List)value ));
+
+ } else if ( value instanceof Map ) {
+
+ Field field = null;
+
+ // is the map really a location element?
+ Map<String, Object> m = (Map<String, Object>)value;
+ if ( m.size() == 2) {
+ Double lat = null;
+ Double lon = null;
+ try {
+ if ( m.get("latitude") != null && m.get("longitude") != null ) {
+ lat = Double.parseDouble( m.get("latitude").toString() );
+ lon = Double.parseDouble( m.get("longitude").toString() );
+
+ } else if ( m.get("lat") != null && m.get("lon") != null ) {
+ lat = Double.parseDouble( m.get("lat").toString() );
+ lon = Double.parseDouble( m.get("lon").toString() );
+ }
+ } catch ( NumberFormatException ignored ) {}
+
+ if ( lat != null && lon != null ) {
+ field = new LocationField( fieldName, new Location( lat, lon ));
+ }
+ }
+
+ if ( field == null ) {
+
+ // not a location element, process it as map
+ entity.setField( new EntityObjectField( fieldName,
+ fromMap( (Map<String, Object>)value ))); // recursion
+
+ } else {
+ entity.setField( field );
+ }
+
+ } else {
+ throw new RuntimeException("Unknown type " + value.getClass().getName());
+ }
+ }
+
+ return entity;
+ }
+
+
+ private static ListField listToListField( String fieldName, List list ) {
+
+ if (list.isEmpty()) {
+ return new ListField( fieldName );
+ }
+
+ Object sample = list.get(0);
+
+ if ( sample instanceof Map ) {
+ return new ListField<Entity>( fieldName, processListForField( list ));
+
+ } else if ( sample instanceof List ) {
+ return new ListField<List>( fieldName, processListForField( list ));
+
+ } else if ( sample instanceof String ) {
+ return new ListField<String>( fieldName, (List<String>)list );
+
+ } else if ( sample instanceof Boolean ) {
+ return new ListField<Boolean>( fieldName, (List<Boolean>)list );
+
+ } else if ( sample instanceof Integer ) {
+ return new ListField<Integer>( fieldName, (List<Integer>)list );
+
+ } else if ( sample instanceof Double ) {
+ return new ListField<Double>( fieldName, (List<Double>)list );
+
+ } else if ( sample instanceof Long ) {
+ return new ListField<Long>( fieldName, (List<Long>)list );
+
+ } else {
+ throw new RuntimeException("Unknown type " + sample.getClass().getName());
+ }
+ }
+
+
+ private static List processListForField( List list ) {
+ if ( list.isEmpty() ) {
+ return list;
+ }
+ Object sample = list.get(0);
+
+ if ( sample instanceof Map ) {
+ List<Entity> newList = new ArrayList<Entity>();
+ for ( Map<String, Object> map : (List<Map<String, Object>>)list ) {
+ newList.add( fromMap( map ) );
+ }
+ return newList;
+
+ } else if ( sample instanceof List ) {
+ return processListForField( list ); // recursion
+
+ } else {
+ return list;
+ }
+ }
+
+
+ /**
+ * Convert Entity to Map, adding version_ug_field and a {name}_ug_analyzed field for each
+ * StringField.
+ */
+ public static Map toMap(Entity entity) {
+
+ Map<String, Object> entityMap = new HashMap<String, Object>();
+
+ for (Object f : entity.getFields().toArray()) {
+ Field field = (Field) f;
+
+ if (f instanceof ListField || f instanceof ArrayField) {
+ List list = (List) field.getValue();
+ entityMap.put(field.getName(),
+ new ArrayList(processCollectionForMap(list)));
+
+ } else if (f instanceof SetField) {
+ Set set = (Set) field.getValue();
+ entityMap.put(field.getName(),
+ new ArrayList(processCollectionForMap(set)));
+
+ } else if (f instanceof EntityObjectField) {
+ Entity ev = (Entity) field.getValue();
+ entityMap.put(field.getName(), toMap(ev)); // recursion
+
+ } else if (f instanceof StringField) {
+ // index in lower case because Usergrid queries are case insensitive
+ entityMap.put(field.getName(), ((String) field.getValue()).toLowerCase());
+ entityMap.put(field.getName() + ANALYZED_SUFFIX, field.getValue());
+
+ } else if (f instanceof LocationField) {
+ LocationField locField = (LocationField) f;
+ Map<String, Object> locMap = new HashMap<String, Object>();
+
+ // field names lat and lon trigger ElasticSearch geo location
+ locMap.put("lat", locField.getValue().getLatitude());
+ locMap.put("lon", locField.getValue().getLongtitude());
+ entityMap.put(field.getName() + GEO_SUFFIX, locMap);
+
+ } else {
+ entityMap.put(field.getName(), field.getValue());
+ }
+ }
+
+ return entityMap;
+ }
+
+
+ private static Collection processCollectionForMap(Collection c) {
+ if (c.isEmpty()) {
+ return c;
+ }
+ List processed = new ArrayList();
+ Object sample = c.iterator().next();
+
+ if (sample instanceof Entity) {
+ for (Object o : c.toArray()) {
+ Entity e = (Entity) o;
+ processed.add(toMap(e));
+ }
+
+ } else if (sample instanceof List) {
+ for (Object o : c.toArray()) {
+ List list = (List) o;
+ processed.add(processCollectionForMap(list)); // recursion;
+ }
+
+ } else if (sample instanceof Set) {
+ for (Object o : c.toArray()) {
+ Set set = (Set) o;
+ processed.add(processCollectionForMap(set)); // recursion;
+ }
+
+ } else {
+ for (Object o : c.toArray()) {
+ processed.add(o);
+ }
+ }
+ return processed;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7bbfd1e3/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
index f0c42f2..265a71e 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
@@ -43,7 +43,7 @@ import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.index.query.Results;
-import org.apache.usergrid.persistence.index.utils.EntityBuilder;
+import org.apache.usergrid.persistence.index.utils.EntityMapUtils;
import org.jukito.JukitoRunner;
import org.jukito.UseModules;
import static org.junit.Assert.assertEquals;
@@ -98,7 +98,7 @@ public class EntityCollectionIndexTest {
Map<String, Object> item = (Map<String, Object>)o;
Entity entity = new Entity(new SimpleId(UUIDGenerator.newTimeUUID(), scope.getName()));
- entity = EntityBuilder.fromMap( scope.getName(), entity, item );
+ entity = EntityMapUtils.fromMap( entity, item );
EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
entity = entityManager.write( entity ).toBlockingObservable().last();
@@ -133,7 +133,7 @@ public class EntityCollectionIndexTest {
put("topspeed", 215);
}};
- Entity entity = EntityBuilder.fromMap( scope.getName(), entityMap );
+ Entity entity = EntityMapUtils.fromMap( entityMap );
EntityUtils.setId( entity, new SimpleId( "fastcar" ));
entity = entityManager.write( entity ).toBlockingObservable().last();
entityIndex.index( entity );
@@ -209,10 +209,10 @@ public class EntityCollectionIndexTest {
Map<String, Object> map1 = (Map<String, Object>)o;
// convert map to entity
- Entity entity1 = EntityBuilder.fromMap( "testscope", map1 );
+ Entity entity1 = EntityMapUtils.fromMap( map1 );
// convert entity back to map
- Map map2 = EsEntityCollectionIndex.entityToMap( entity1 );
+ Map map2 = EntityMapUtils.toMap( entity1 );
// the two maps should be the same except for six new system properties
Map diff = Maps.difference( map1, map2 ).entriesDiffering();
[3/3] git commit: Core Persistence EntityManager now passing one
simple create() and get() test.
Posted by sn...@apache.org.
Core Persistence EntityManager now passing one simple create() and get() test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9954c2b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9954c2b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9954c2b3
Branch: refs/heads/entity-manager
Commit: 9954c2b3376571f55fd6942fd1cf983b8f7558e7
Parents: 7bbfd1e
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 28 08:32:19 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 28 08:32:19 2014 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManager.java | 814 +++++++++++++++++++
.../corepersistence/CpEntityManagerImpl.java | 567 -------------
.../usergrid/corepersistence/CpModule.java | 122 ---
.../corepersistence/HybridEntityManager.java | 305 +++++++
.../main/resources/usergrid-core-context.xml | 2 +-
.../java/org/apache/usergrid/Application.java | 6 +
.../org/apache/usergrid/CoreApplication.java | 8 +
.../usergrid/persistence/CollectionIT.java | 17 +
stack/core/src/test/resources/log4j.properties | 4 +-
.../persistence/index/utils/EntityBuilder.java | 177 ----
10 files changed, 1153 insertions(+), 869 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/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
new file mode 100644
index 0000000..4a8da23
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -0,0 +1,814 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed 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.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import me.prettyprint.hector.api.mutation.Mutator;
+import org.apache.usergrid.persistence.ConnectedEntityRef;
+import org.apache.usergrid.persistence.ConnectionRef;
+import org.apache.usergrid.persistence.CounterResolution;
+import org.apache.usergrid.persistence.DynamicEntity;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.Identifier;
+import org.apache.usergrid.persistence.IndexBucketLocator;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.RelationManager;
+import org.apache.usergrid.persistence.Results;
+import org.apache.usergrid.persistence.RoleRef;
+import org.apache.usergrid.persistence.TypedEntity;
+import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.apache.usergrid.persistence.cassandra.GeoIndexManager;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.entities.Role;
+import org.apache.usergrid.persistence.index.EntityCollectionIndex;
+import org.apache.usergrid.persistence.index.utils.EntityMapUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.LongField;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+public class CpEntityManager implements EntityManager {
+
+ private CollectionScope applicationScope;
+ private EntityCollectionManager ecm;
+ private EntityCollectionIndex eci;
+
+ // TODO: eliminate need for a UUID to type map
+ private final Map<UUID, String> typesByUuid = new HashMap<UUID, String>();
+ private final Map<String, String> typesByCollectionNames = new HashMap<String, String>();
+
+
+ CpEntityManager(CollectionScope collectionScope, EntityCollectionManager ecm, EntityCollectionIndex eci) {
+ this.applicationScope = collectionScope;
+ this.ecm = ecm;
+ this.eci = eci;
+ }
+
+
+ @Override
+ public Entity create(String entityType, Map<String, Object> properties) throws Exception {
+
+ org.apache.usergrid.persistence.model.entity.Entity cpEntity =
+ new org.apache.usergrid.persistence.model.entity.Entity(
+ new SimpleId(UUIDGenerator.newTimeUUID(), entityType ));
+
+ cpEntity = EntityMapUtils.fromMap( cpEntity, properties );
+ cpEntity.setField(new LongField("created", cpEntity.getId().getUuid().timestamp()) );
+ cpEntity.setField(new LongField("modified", cpEntity.getId().getUuid().timestamp()) );
+
+ cpEntity = ecm.write( cpEntity ).toBlockingObservable().last();
+ eci.index( cpEntity );
+
+ Entity entity = new DynamicEntity( entityType, cpEntity.getId().getUuid() );
+ entity.setUuid( cpEntity.getId().getUuid() );
+ Map<String, Object> entityMap = EntityMapUtils.toMap( cpEntity );
+ entity.addProperties( entityMap );
+
+ typesByUuid.put( entity.getUuid(), entityType );
+
+ return entity;
+ }
+
+
+ @Override
+ public <A extends Entity> A create(
+ String entityType, Class<A> entityClass, Map<String, Object> properties) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public <A extends TypedEntity> A create(A entity) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public Entity create( UUID importId, String entityType, Map<String, Object> properties) throws Exception {
+ return create( entityType, properties );
+ }
+
+
+ @Override
+ public Entity get( UUID entityId ) throws Exception {
+ String type = typesByUuid.get( entityId );
+ return get( entityId, type );
+ }
+
+
+ public Entity get( UUID entityId, String type ) throws Exception {
+
+ Id id = new SimpleId( entityId, type );
+
+ org.apache.usergrid.persistence.model.entity.Entity cpEntity =
+ ecm.load( id ).toBlockingObservable().last();
+
+ Entity entity = new DynamicEntity( type, cpEntity.getId().getUuid() );
+ entity.setUuid( cpEntity.getId().getUuid() );
+ Map<String, Object> entityMap = EntityMapUtils.toMap( cpEntity );
+ entity.addProperties( entityMap );
+ return entity;
+ }
+
+ @Override
+ public Entity get(EntityRef entityRef) throws Exception {
+ return get( entityRef.getUuid(), entityRef.getType() );
+ }
+
+
+ @Override
+ public <A extends Entity> A get(UUID entityId, Class<A> entityClass) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public Results get(Collection<UUID> entityIds, Results.Level resultsLevel) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public Results get(Collection<UUID> entityIds) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public Results get(Collection<UUID> entityIds, Class<? extends Entity> entityClass,
+ Results.Level resultsLevel) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public Results get(Collection<UUID> entityIds, String entityType,
+ Class<? extends Entity> entityClass, Results.Level resultsLevel) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public void update( Entity entity ) throws Exception {
+
+ Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
+
+ org.apache.usergrid.persistence.model.entity.Entity cpEntity =
+ ecm.load( entityId ).toBlockingObservable().last();
+
+ cpEntity = EntityMapUtils.fromMap( cpEntity, entity.getProperties() );
+
+ cpEntity = ecm.write( cpEntity ).toBlockingObservable().last();
+ eci.index( cpEntity );
+ }
+
+
+ @Override
+ public void delete(EntityRef entityRef) throws Exception {
+
+ Id entityId = new SimpleId( entityRef.getUuid(), entityRef.getType() );
+
+ org.apache.usergrid.persistence.model.entity.Entity entity =
+ ecm.load( entityId ).toBlockingObservable().last();
+
+ if ( entity != null ) {
+ eci.deindex( entity );
+ ecm.delete( entityId );
+ }
+ }
+
+
+ @Override
+ public Results searchCollection(EntityRef entityRef, String collectionName, Query query) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+// String type = typesByCollectionNames.get( collectionName );
+// if ( type == null ) {
+// throw new RuntimeException(
+// "No type found for collection name: " + collectionName);
+// }
+//
+// org.apache.usergrid.persistence.index.query.Results results = eci.execute( query );
+// return results;
+ }
+
+
+ @Override
+ public void setApplicationId(UUID applicationId) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public GeoIndexManager getGeoIndexManager() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public EntityRef getApplicationRef() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Application getApplication() throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void updateApplication(Application app) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void updateApplication(Map<String, Object> properties) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public RelationManager getRelationManager(EntityRef entityRef) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getApplicationCollections() throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Object> getApplicationCollectionMetadata() throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public long getApplicationCollectionSize(String collectionName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public void createApplicationCollection(String entityType) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public EntityRef getAlias(String aliasType, String alias) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public EntityRef getAlias(UUID ownerId, String collectionName, String aliasValue) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, EntityRef> getAlias(String aliasType, List<String> aliases) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, EntityRef> getAlias(UUID ownerId, String collectionName, List<String> aliases) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public EntityRef validate(EntityRef entityRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public String getType(UUID entityId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public EntityRef getRef(UUID entityId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+
+ @Override
+ public Object getProperty(EntityRef entityRef, String propertyName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public List<Entity> getPartialEntities(Collection<UUID> ids, Collection<String> properties) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Object> getProperties(EntityRef entityRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void setProperty(EntityRef entityRef, String propertyName, Object propertyValue) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void setProperty(EntityRef entityRef, String propertyName,
+ Object propertyValue, boolean override) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void updateProperties(EntityRef entityRef, Map<String, Object> properties) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void deleteProperty(EntityRef entityRef, String propertyName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<Object> getDictionaryAsSet(EntityRef entityRef, String dictionaryName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void addToDictionary(EntityRef entityRef, String dictionaryName, Object elementValue) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void addToDictionary(EntityRef entityRef, String dictionaryName,
+ Object elementName, Object elementValue) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void addSetToDictionary(EntityRef entityRef, String dictionaryName, Set<?> elementValues) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void addMapToDictionary(EntityRef entityRef, String dictionaryName, Map<?, ?> elementValues) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<Object, Object> getDictionaryAsMap(EntityRef entityRef, String dictionaryName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Object getDictionaryElementValue(EntityRef entityRef, String dictionaryName, String elementName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void removeFromDictionary(EntityRef entityRef, String dictionaryName, Object elementValue) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getDictionaries(EntityRef entity) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Map<UUID, Set<String>>> getOwners(EntityRef entityRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean isCollectionMember(EntityRef owner, String collectionName, EntityRef entity) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean isConnectionMember(EntityRef owner, String connectionName, EntityRef entity) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getCollections(EntityRef entityRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getCollection(EntityRef entityRef, String collectionName, UUID startResult, int count, Results.Level resultsLevel, boolean reversed) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getCollection(UUID entityId, String collectionName, Query query, Results.Level resultsLevel) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Entity addToCollection(EntityRef entityRef, String collectionName, EntityRef itemRef) throws Exception {
+ // TODO: eliminate need for typesByCollectionNames
+ typesByCollectionNames.put( collectionName, entityRef.getType() );
+ return get( entityRef );
+ }
+
+ @Override
+ public Entity addToCollections(List<EntityRef> ownerEntities, String collectionName, EntityRef itemRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Entity createItemInCollection(EntityRef entityRef, String collectionName, String itemType, Map<String, Object> properties) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void removeFromCollection(EntityRef entityRef, String collectionName, EntityRef itemRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getCollectionIndexes(EntityRef entity, String collectionName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void copyRelationships(EntityRef srcEntityRef, String srcRelationName, EntityRef dstEntityRef, String dstRelationName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public ConnectionRef createConnection(ConnectionRef connection) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public ConnectionRef createConnection(EntityRef connectingEntity, String connectionType, EntityRef connectedEntityRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public ConnectionRef createConnection(EntityRef connectingEntity, String pairedConnectionType, EntityRef pairedEntity, String connectionType, EntityRef connectedEntityRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public ConnectionRef createConnection(EntityRef connectingEntity, ConnectedEntityRef... connections) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public ConnectionRef connectionRef(EntityRef connectingEntity, String connectionType, EntityRef connectedEntityRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public ConnectionRef connectionRef(EntityRef connectingEntity, String pairedConnectionType, EntityRef pairedEntity, String connectionType, EntityRef connectedEntityRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public ConnectionRef connectionRef(EntityRef connectingEntity, ConnectedEntityRef... connections) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void deleteConnection(ConnectionRef connectionRef) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getConnectionTypes(EntityRef ref) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getConnectedEntities(UUID entityId, String connectionType, String connectedEntityType, Results.Level resultsLevel) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getConnectingEntities(UUID entityId, String connectionType, String connectedEntityType, Results.Level resultsLevel) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getConnectingEntities(UUID uuid, String connectionType, String entityType, Results.Level level, int count) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results searchConnectedEntities(EntityRef connectingEntity, Query query) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getConnectionIndexes(EntityRef entity, String connectionType) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, String> getRoles() throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void resetRoles() throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Entity createRole(String roleName, String roleTitle, long inactivity) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void grantRolePermission(String roleName, String permission) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void grantRolePermissions(String roleName, Collection<String> permissions) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void revokeRolePermission(String roleName, String permission) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getRolePermissions(String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void deleteRole(String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, String> getGroupRoles(UUID groupId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Entity createGroupRole(UUID groupId, String roleName, long inactivity) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void grantGroupRolePermission(UUID groupId, String roleName, String permission) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void revokeGroupRolePermission(UUID groupId, String roleName, String permission) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getGroupRolePermissions(UUID groupId, String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void deleteGroupRole(UUID groupId, String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getUserRoles(UUID userId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void addUserToRole(UUID userId, String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void removeUserFromRole(UUID userId, String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getUserPermissions(UUID userId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void grantUserPermission(UUID userId, String permission) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void revokeUserPermission(UUID userId, String permission) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, String> getUserGroupRoles(UUID userId, UUID groupId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void addUserToGroupRole(UUID userId, UUID groupId, String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void removeUserFromGroupRole(UUID userId, UUID groupId, String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getUsersInGroupRole(UUID groupId, String roleName, Results.Level level) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void incrementAggregateCounters(UUID userId, UUID groupId, String category, String counterName, long value) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getAggregateCounters(UUID userId, UUID groupId, String category, String counterName, CounterResolution resolution, long start, long finish, boolean pad) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getAggregateCounters(UUID userId, UUID groupId, UUID queueId, String category, String counterName, CounterResolution resolution, long start, long finish, boolean pad) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Results getAggregateCounters(Query query) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public EntityRef getUserByIdentifier(Identifier identifier) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public EntityRef getGroupByIdentifier(Identifier identifier) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getCounterNames() throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Long> getEntityCounters(UUID entityId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Long> getApplicationCounters() throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void incrementAggregateCounters(UUID userId, UUID groupId, String category, Map<String, Long> counters) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean isPropertyValueUniqueForEntity(String entityType, String propertyName, Object propertyValue) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public <A extends Entity> A get(EntityRef entityRef, Class<A> entityClass) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Role> getRolesWithTitles(Set<String> roleNames) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public String getRoleTitle(String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Role> getUserRolesWithTitles(UUID userId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Role> getGroupRolesWithTitles(UUID userId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void addGroupToRole(UUID userId, String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void removeGroupFromRole(UUID userId, String roleName) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getGroupPermissions(UUID groupId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void grantGroupPermission(UUID groupId, String permission) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void revokeGroupPermission(UUID groupId, String permission) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public <A extends Entity> A batchCreate(Mutator<ByteBuffer> m, String entityType, Class<A> entityClass, Map<String, Object> properties, UUID importId, UUID timestampUuid) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void batchCreateRole(Mutator<ByteBuffer> batch, UUID groupId, String roleName, String roleTitle, long inactivity, RoleRef roleRef, UUID timestampUuid) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Mutator<ByteBuffer> batchSetProperty(Mutator<ByteBuffer> batch, EntityRef entity, String propertyName, Object propertyValue, UUID timestampUuid) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Mutator<ByteBuffer> batchSetProperty(Mutator<ByteBuffer> batch, EntityRef entity, String propertyName, Object propertyValue, boolean force, boolean noRead, UUID timestampUuid) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Mutator<ByteBuffer> batchUpdateDictionary(Mutator<ByteBuffer> batch, EntityRef entity, String dictionaryName, Object elementValue, Object elementCoValue, boolean removeFromDictionary, UUID timestampUuid) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Mutator<ByteBuffer> batchUpdateDictionary(Mutator<ByteBuffer> batch, EntityRef entity, String dictionaryName, Object elementValue, boolean removeFromDictionary, UUID timestampUuid) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Mutator<ByteBuffer> batchUpdateProperties(Mutator<ByteBuffer> batch, EntityRef entity, Map<String, Object> properties, UUID timestampUuid) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<String> getDictionaryNames(EntityRef entity) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void insertEntity(String type, UUID entityId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void deleteEntity(UUID entityId) throws Exception {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public UUID getApplicationId() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public IndexBucketLocator getIndexBucketLocator() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public CassandraService getCass() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerImpl.java
deleted file mode 100644
index cdbbd01..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerImpl.java
+++ /dev/null
@@ -1,567 +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 com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.netflix.config.ConfigurationManager;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.UUID;
-import me.prettyprint.hector.api.mutation.Mutator;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Query;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.TypedEntity;
-import org.apache.usergrid.persistence.cassandra.CassandraService;
-import org.apache.usergrid.persistence.cassandra.CounterUtils;
-import org.apache.usergrid.persistence.cassandra.EntityManagerFactoryImpl;
-import org.apache.usergrid.persistence.cassandra.EntityManagerImpl;
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
-import org.apache.usergrid.persistence.collection.migration.MigrationException;
-import org.apache.usergrid.persistence.collection.migration.MigrationManager;
-import org.apache.usergrid.persistence.entities.Application;
-import org.apache.usergrid.persistence.index.EntityCollectionIndex;
-import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Hybrid Core Persistence implementation of EntityManager.
- */
-public class CpEntityManagerImpl extends EntityManagerImpl {
- private static final Logger logger = LoggerFactory.getLogger(CpEntityManagerImpl.class);
-
- private static EntityCollectionManagerFactory ecmf;
- private static EntityCollectionIndexFactory ecif ;
- static {
-
- try {
- ConfigurationManager.loadCascadedPropertiesFromResources("core-persistence");
-
- // TODO: make CpEntityManager work in non-test environment
- Properties testProps = new Properties() {{
- put("cassandra.hosts", "localhost:" + System.getProperty("cassandra.rpc_port"));
- }};
-
- ConfigurationManager.loadProperties( testProps );
-
- } catch (IOException ex) {
- throw new RuntimeException("Error loading Core Persistence proprties", ex);
- }
-
- Injector injector = Guice.createInjector( new CpModule() );
-
- MigrationManager m = injector.getInstance( MigrationManager.class );
- try {
- m.migrate();
- } catch (MigrationException ex) {
- throw new RuntimeException("Error migrating Core Persistence", ex);
- }
-
- ecmf = injector.getInstance( EntityCollectionManagerFactory.class );
- ecif = injector.getInstance( EntityCollectionIndexFactory.class );
- }
- private final Map<CollectionScope, EntityCollectionManager> managers = new HashMap<>();
- private final Map<CollectionScope, EntityCollectionIndex> indexes = new HashMap<>();
-
- private CollectionScope applicationScope = null;
-
- @Override
- public EntityManager init(
- EntityManagerFactoryImpl emf,
- CassandraService cass,
- CounterUtils counterUtils,
- UUID applicationId,
- boolean skipAggregateCounters ) {
-
- super.init( emf, cass, counterUtils, applicationId, skipAggregateCounters );
- setApplicationId(applicationId);
- return this;
- }
-
- @Override
- public void setApplicationId( UUID applicationId ) {
- super.setApplicationId( applicationId );
- try {
- Application app = getApplication();
-
- Id orgId = getOrganizationId( app );
- Id appId = new SimpleId( applicationId, "application");
-
- applicationScope =
- new CollectionScopeImpl(orgId, appId, "applicationScope");
-
- } catch (Exception ex) {
- logger.error("Error getting applicationScope", ex);
- }
- }
-
- private static final String SYSTEM_ORG_TYPE = "zzz_defaultorg_zzz";
- private static final String SYSTEM_APP_TYPE = "zzz_defaultapp_zzz";
- private static final String SYSTEM_SCOPE_TYPE = "zzz_default_zzz";
-
- private static final Id defaultOrgId = new SimpleId( SYSTEM_ORG_TYPE );
- private static final Id defaultAppId = new SimpleId( SYSTEM_APP_TYPE );
- private static final CollectionScope systemScope = new CollectionScopeImpl(
- defaultOrgId, defaultAppId, SYSTEM_SCOPE_TYPE );
-
- private Id getOrganizationId( Application app ) {
-
-
-
- EntityCollectionManager ecm = getManager( systemScope );
- EntityCollectionIndex eci = getIndex( systemScope );
-
- String orgName = (app == null) ? SYSTEM_ORG_TYPE : app.getOrganizationName();
-
- org.apache.usergrid.persistence.index.query.Query q =
- org.apache.usergrid.persistence.index.query.Query.fromQL(
- "name = '" + orgName + "'");
-
- org.apache.usergrid.persistence.index.query.Results execute = eci.execute(q);
-
- if ( execute.isEmpty() ) { // create if does not exist
-
- org.apache.usergrid.persistence.model.entity.Entity entity =
- new org.apache.usergrid.persistence.model.entity.Entity(
- new SimpleId(UUIDGenerator.newTimeUUID(), "organization" ));
-
- entity.setField( new StringField( "name", orgName ));
- entity = ecm.write( entity ).toBlockingObservable().last();
-
- Id orgId = entity.getId();
- return orgId;
- }
-
- org.apache.usergrid.persistence.model.entity.Entity entity =
- execute.getEntities().get(0);
-
- Id orgId = entity.getId();
- return orgId;
- }
-
- private Id getApplicationId( Application app ) {
-
- Id defaultOrgId = new SimpleId("zzz_default_zzz");
- Id defaultAppId = new SimpleId("zzz_default_zzz");
- CollectionScope defaultScope = new CollectionScopeImpl(
- defaultOrgId, defaultAppId, "organizations" );
-
- EntityCollectionManager ecm = getManager( defaultScope );
- EntityCollectionIndex eci = getIndex( defaultScope );
-
- String orgName = (app == null) ? "zzz_default_zzz" : app.getOrganizationName();
-
- org.apache.usergrid.persistence.index.query.Query q =
- org.apache.usergrid.persistence.index.query.Query.fromQL(
- "name = '" + orgName + "'");
-
- org.apache.usergrid.persistence.index.query.Results execute = eci.execute(q);
-
- if ( execute.isEmpty() ) { // create if does not exist
-
- org.apache.usergrid.persistence.model.entity.Entity entity =
- new org.apache.usergrid.persistence.model.entity.Entity(
- new SimpleId(UUIDGenerator.newTimeUUID(), "organization" ));
-
- entity.setField( new StringField( "name", orgName ));
- entity = ecm.write( entity ).toBlockingObservable().last();
-
- Id orgId = entity.getId();
- return orgId;
- }
-
- org.apache.usergrid.persistence.model.entity.Entity entity =
- execute.getEntities().get(0);
-
- Id orgId = entity.getId();
- return orgId;
- }
-
-
- private EntityCollectionIndex getIndex( CollectionScope scope ) {
- EntityCollectionIndex eci = indexes.get( scope );
- if ( eci == null ) {
- eci = ecif.createCollectionIndex( scope );
- indexes.put( scope, eci );
- }
- return eci;
- }
-
- private EntityCollectionManager getManager( CollectionScope scope ) {
- EntityCollectionManager ecm = managers.get( scope );
- if ( ecm == null ) {
- ecm = ecmf.createCollectionManager( scope );
- managers.put( scope, ecm);
- }
- return ecm;
- }
-
-
- @Override
- public Set<String> getCollectionIndexes(
- EntityRef entity, String collectionName) throws Exception {
- return super.getCollectionIndexes(entity, collectionName);
- }
-
- @Override
- public Results searchCollection(
- EntityRef entityRef, String collectionName, Query query) throws Exception {
- return super.searchCollection(entityRef, collectionName, query);
- }
-
- @Override
- public Entity createItemInCollection(
- EntityRef entityRef,
- String collectionName,
- String itemType,
- Map<String, Object> properties) throws Exception {
- return super.createItemInCollection(entityRef, collectionName, itemType, properties);
- }
-
- @Override
- public Results getCollection(
- UUID entityId,
- String collectionName,
- Query query,
- Results.Level resultsLevel) throws Exception {
- return super.getCollection(entityId, collectionName, query, resultsLevel);
- }
-
- @Override
- public Results getCollection(
- EntityRef entityRef,
- String collectionName,
- UUID startResult,
- int count,
- Results.Level resultsLevel,
- boolean reversed) throws Exception {
- return super.getCollection(entityRef,
- collectionName,
- startResult,
- count,
- resultsLevel,
- reversed);
- }
-
- @Override
- public Set<String> getCollections(
- EntityRef entityRef) throws Exception {
- return super.getCollections(entityRef);
- }
-
- @Override
- public boolean isPropertyValueUniqueForEntity(
- String entityType,
- String propertyName,
- Object propertyValue) throws Exception {
- return super.isPropertyValueUniqueForEntity(
- entityType, propertyName, propertyValue);
- }
-
- @Override
- public void updateProperties(
- EntityRef entityRef, Map<String, Object> properties) throws Exception {
- super.updateProperties(entityRef, properties);
- }
-
- @Override
- public void setProperty(
- EntityRef entityRef,
- String propertyName,
- Object propertyValue,
- boolean override) throws Exception {
- super.setProperty(entityRef,
- propertyName, propertyValue, override);
- }
-
- @Override
- public void setProperty(
- EntityRef entityRef, String propertyName, Object propertyValue) throws Exception {
- super.setProperty(entityRef, propertyName, propertyValue);
- }
-
- @Override
- public List<Entity> getPartialEntities(
- Collection<UUID> ids, Collection<String> fields) throws Exception {
- return super.getPartialEntities(ids, fields);
- }
-
- @Override
- public Map<String, Object> getProperties(
- EntityRef entityRef) throws Exception {
- return super.getProperties(entityRef);
- }
-
- @Override
- public Object getProperty(
- EntityRef entityRef, String propertyName) throws Exception {
- return super.getProperty(entityRef, propertyName);
- }
-
- @Override
- public void update(
- Entity entity) throws Exception {
- super.update(entity);
- }
-
- @Override
- public Results loadEntities(
- Results results,
- Results.Level resultsLevel,
- Map<UUID, UUID> associatedMap,
- int count) throws Exception {
- return super.loadEntities(results, resultsLevel, associatedMap, count);
- }
-
- @Override
- public Results loadEntities(
- Results results, Results.Level resultsLevel, int count) throws Exception {
- return super.loadEntities(results, resultsLevel, count);
- }
-
- @Override
- public Results get(
- Collection<UUID> entityIds,
- String entityType,
- Class<? extends Entity> entityClass,
- Results.Level resultsLevel) throws Exception {
- return super.get(entityIds, entityType, entityClass, resultsLevel);
- }
-
- @Override
- public Results get(
- Collection<UUID> entityIds,
- Class<? extends Entity> entityClass,
- Results.Level resultsLevel) throws Exception {
- return super.get(entityIds, entityClass, resultsLevel);
- }
-
- @Override
- public Results get(
- Collection<UUID> entityIds) throws Exception {
- return super.get(entityIds);
- }
-
- @Override
- public Results get(
- Collection<UUID> entityIds,
- Results.Level resultsLevel) throws Exception {
- return super.get(entityIds, resultsLevel);
- }
-
- @Override
- public <A extends Entity> A get(
- UUID entityId, Class<A> entityClass) throws Exception {
- return super.get(entityId, entityClass);
- }
-
- @Override
- public <A extends Entity> A get(
- EntityRef entityRef, Class<A> entityClass) throws Exception {
- return super.get(entityRef, entityClass);
- }
-
- @Override
- public Entity get(
- EntityRef entityRef) throws Exception {
- return super.get(entityRef);
- }
-
- @Override
- public Entity get(
- UUID entityid) throws Exception {
- return super.get(entityid);
- }
-
- @Override
- public EntityRef validate(
- EntityRef entityRef, boolean verify) throws Exception {
- return super.validate(entityRef, verify);
- }
-
- @Override
- public EntityRef validate(
- EntityRef entityRef) throws Exception {
- return super.validate(entityRef);
- }
-
- @Override
- public void delete(
- EntityRef entityRef) throws Exception {
- super.delete(entityRef);
- }
-
- @Override
- public void deleteEntity(
- UUID entityId) throws Exception {
- super.deleteEntity(entityId);
- }
-
- @Override
- public void updateProperties(
- UUID entityId, Map<String, Object> properties) throws Exception {
- super.updateProperties(entityId, properties);
- }
-
- @Override
- public Set<String> getPropertyNames(
- EntityRef entity) throws Exception {
- return super.getPropertyNames(entity);
- }
-
- @Override
- public <A extends Entity> List<A> getEntities(
- Collection<UUID> entityIds, Class<A> entityClass) throws Exception {
- return super.getEntities(entityIds, entityClass);
- }
-
- @Override
- public <A extends Entity> A getEntity(
- UUID entityId, Class<A> entityClass) throws Exception {
- return super.getEntity(entityId, entityClass);
- }
-
- @Override
- public String getEntityType(
- UUID entityId) throws Exception {
- return super.getEntityType(entityId);
- }
-
- @Override
- public <A extends Entity> A batchCreate(
- Mutator<ByteBuffer> m,
- String entityType,
- Class<A> entityClass,
- Map<String, Object> properties,
- UUID importId,
- UUID timestampUuid) throws Exception {
- return super.batchCreate(m,
- entityType,
- entityClass,
- properties,
- importId,
- timestampUuid);
- }
-
- @Override
- public <A extends Entity> A create(
- String entityType,
- Class<A> entityClass,
- Map<String, Object> properties,
- UUID importId) throws Exception {
- return super.create(entityType, entityClass, properties, importId);
- }
-
- @Override
- public Entity create(
- String entityType, Map<String, Object> properties) throws Exception {
- return super.create(entityType, properties);
- }
-
- @Override
- public Entity create(
- UUID importId,
- String entityType,
- Map<String, Object> properties) throws Exception {
- return super.create(importId, entityType, properties);
- }
-
- @Override
- public <A extends Entity> A create(
- String entityType,
- Class<A> entityClass,
- Map<String, Object> properties) throws Exception {
- return super.create(entityType, entityClass, properties);
- }
-
- @Override
- public boolean isPropertyValueUniqueForEntity(
- UUID ownerEntityId,
- String entityType,
- String propertyName,
- Object propertyValue) throws Exception {
- return super.isPropertyValueUniqueForEntity(ownerEntityId,
- entityType,
- propertyName,
- propertyValue);
- }
-
- @Override
- public Mutator<ByteBuffer> batchUpdateProperties(
- Mutator<ByteBuffer> batch,
- EntityRef entity,
- Map<String, Object> properties,
- UUID timestampUuid) throws Exception {
- return super.batchUpdateProperties(batch, entity, properties, timestampUuid);
- }
-
- @Override
- public Mutator<ByteBuffer> batchSetProperty(
- Mutator<ByteBuffer> batch,
- EntityRef entity,
- String propertyName,
- Object propertyValue,
- boolean force,
- boolean noRead,
- UUID timestampUuid) throws Exception {
- return super.batchSetProperty(batch,
- entity,
- propertyName,
- propertyValue,
- force,
- noRead,
- timestampUuid);
- }
-
- @Override
- public Mutator<ByteBuffer> batchSetProperty(
- Mutator<ByteBuffer> batch,
- EntityRef entity,
- String propertyName,
- Object propertyValue,
- UUID timestampUuid) throws Exception {
- return super.batchSetProperty(batch,
- entity,
- propertyName,
- propertyValue,
- timestampUuid);
- }
-
- @Override
- public <A extends TypedEntity> A create(
- A entity) throws Exception {
- return super.create(entity);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpModule.java
deleted file mode 100644
index 3529ace..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpModule.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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 com.google.inject.AbstractModule;
-import com.google.inject.assistedinject.FactoryModuleBuilder;
-import com.google.inject.multibindings.Multibinder;
-import org.apache.usergrid.persistence.collection.guice.CollectionModule;
-import org.apache.usergrid.persistence.collection.migration.Migration;
-import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessObserver;
-import org.apache.usergrid.persistence.graph.GraphFig;
-import org.apache.usergrid.persistence.graph.GraphManager;
-import org.apache.usergrid.persistence.graph.GraphManagerFactory;
-import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
-import org.apache.usergrid.persistence.graph.consistency.AsyncProcessorImpl;
-import org.apache.usergrid.persistence.graph.consistency.LocalTimeoutQueue;
-import org.apache.usergrid.persistence.graph.consistency.TimeService;
-import org.apache.usergrid.persistence.graph.consistency.TimeoutQueue;
-import org.apache.usergrid.persistence.graph.guice.EdgeDelete;
-import org.apache.usergrid.persistence.graph.guice.NodeDelete;
-import org.apache.usergrid.persistence.graph.impl.CollectionIndexObserver;
-import org.apache.usergrid.persistence.graph.impl.GraphManagerImpl;
-import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepair;
-import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepairImpl;
-import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepair;
-import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepairImpl;
-import org.apache.usergrid.persistence.graph.serialization.CassandraConfig;
-import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
-import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
-import org.apache.usergrid.persistence.graph.serialization.NodeSerialization;
-import org.apache.usergrid.persistence.graph.serialization.impl.CassandraConfigImpl;
-import org.apache.usergrid.persistence.graph.serialization.impl.EdgeMetadataSerializationImpl;
-import org.apache.usergrid.persistence.graph.serialization.impl.EdgeSerializationImpl;
-import org.apache.usergrid.persistence.graph.serialization.impl.NodeSerializationImpl;
-import org.apache.usergrid.persistence.index.EntityCollectionIndex;
-import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
-import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.impl.EsEntityCollectionIndex;
-import org.safehaus.guicyfig.GuicyFigModule;
-
-
-
-/**
- * Guice Module that encapsulates Core Persistence.
- */
-public class CpModule extends AbstractModule {
-
- @Override
- protected void configure() {
-
- //------------
- // COLLECTION
- //
-
- // configure collections and our core astyanax framework
- install(new CollectionModule());
-
- //------------
- // INDEX
- //
-
- install (new GuicyFigModule( IndexFig.class ));
-
- install( new FactoryModuleBuilder()
- .implement( EntityCollectionIndex.class, EsEntityCollectionIndex.class )
- .build( EntityCollectionIndexFactory.class ) );
-
- //------------
- // GRAPH
- //
-
- //install our configuration
- install (new GuicyFigModule( GraphFig.class ));
-
- bind( PostProcessObserver.class ).to( CollectionIndexObserver.class );
-
- bind( EdgeMetadataSerialization.class).to( EdgeMetadataSerializationImpl.class);
- bind( EdgeSerialization.class).to( EdgeSerializationImpl.class );
- bind( NodeSerialization.class).to( NodeSerializationImpl.class );
-
- bind( CassandraConfig.class).to( CassandraConfigImpl.class );
-
- // create a guice factory for getting our collection manager
- install( new FactoryModuleBuilder().implement( GraphManager.class, GraphManagerImpl.class )
- .build( GraphManagerFactory.class ) );
-
- //do multibindings for migrations
- Multibinder<Migration> migrationBinding = Multibinder.newSetBinder( binder(), Migration.class );
- migrationBinding.addBinding().to( EdgeMetadataSerializationImpl.class );
- migrationBinding.addBinding().to( EdgeSerializationImpl.class );
- migrationBinding.addBinding().to( NodeSerializationImpl.class );
-
- // Graph event bus, will need to be refactored into it's own classes
-
- // create a guice factor for getting our collection manager
-
- //local queue. Need to
- bind(TimeoutQueue.class).to( LocalTimeoutQueue.class );
-
- bind(AsyncProcessor.class).annotatedWith( EdgeDelete.class ).to( AsyncProcessorImpl.class );
- bind(AsyncProcessor.class).annotatedWith( NodeDelete.class ).to( AsyncProcessorImpl.class );
-
- //Repair/cleanup classes
- bind( EdgeMetaRepair.class).to( EdgeMetaRepairImpl.class );
- bind( EdgeDeleteRepair.class).to( EdgeDeleteRepairImpl.class );
- bind( TimeService.class).to( TimeServiceImpl.class );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManager.java
new file mode 100644
index 0000000..fcab94c
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManager.java
@@ -0,0 +1,305 @@
+/*
+ * 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 com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.netflix.config.ConfigurationManager;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.Results;
+import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.apache.usergrid.persistence.cassandra.CounterUtils;
+import org.apache.usergrid.persistence.cassandra.EntityManagerFactoryImpl;
+import org.apache.usergrid.persistence.cassandra.EntityManagerImpl;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.OrganizationScope;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+import org.apache.usergrid.persistence.collection.impl.OrganizationScopeImpl;
+import org.apache.usergrid.persistence.collection.migration.MigrationException;
+import org.apache.usergrid.persistence.collection.migration.MigrationManager;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.index.EntityCollectionIndex;
+import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
+import org.apache.usergrid.persistence.index.exceptions.QueryParseException;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.field.UUIDField;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Hybrid Core Persistence implementation of EntityManager.
+ */
+public class HybridEntityManager extends EntityManagerImpl {
+ private static final Logger log = LoggerFactory.getLogger(HybridEntityManager.class);
+
+ /** Each instance operates on a CollectionScope. */
+ private CollectionScope scope = null;
+
+
+ private static EntityCollectionManagerFactory ecmf;
+ private static EntityCollectionIndexFactory ecif;
+ private static GraphManagerFactory gmf;
+
+ private CpEntityManager cpEntityManager = null;
+
+ private static final String SYSTEM_ORG_UUID = "b9b51240-b5d5-11e3-9ea8-11c207d6769a";
+ private static final String SYSTEM_ORG_TYPE = "zzz_defaultapp_zzz";
+
+ private static final String SYSTEM_APP_UUID = "b6768a08-b5d5-11e3-a495-10ddb1de66c4";
+ private static final String SYSTEM_APP_TYPE = "zzz_defaultapp_zzz";
+
+ private static final OrganizationScope SYSTEM_ORG_SCOPE =
+ new OrganizationScopeImpl(
+ new SimpleId( UUID.fromString(SYSTEM_ORG_UUID), SYSTEM_ORG_TYPE ));
+
+ private static final CollectionScope SYSTEM_APP_SCOPE =
+ new CollectionScopeImpl(
+ SYSTEM_ORG_SCOPE.getOrganization(),
+ new SimpleId( UUID.fromString(SYSTEM_APP_UUID), SYSTEM_APP_TYPE ),
+ SYSTEM_APP_TYPE);
+
+ private final Map<CollectionScope, EntityCollectionManager> managers = new HashMap<>();
+ private final Map<CollectionScope, EntityCollectionIndex> indexes = new HashMap<>();
+ private final Map<OrganizationScope, GraphManager> graphManagers = new HashMap<>();
+
+
+ static {
+
+ try {
+ ConfigurationManager.loadCascadedPropertiesFromResources("core-persistence");
+
+ // TODO: make CpEntityManager work in non-test environment
+ Properties testProps = new Properties() {{
+ put("cassandra.hosts", "localhost:" + System.getProperty("cassandra.rpc_port"));
+ }};
+
+ ConfigurationManager.loadProperties( testProps );
+
+ } catch (IOException ex) {
+ throw new RuntimeException("Error loading Core Persistence proprties", ex);
+ }
+
+ Injector injector = Guice.createInjector( new GuiceModule() );
+
+ MigrationManager m = injector.getInstance( MigrationManager.class );
+ try {
+ m.migrate();
+ } catch (MigrationException ex) {
+ throw new RuntimeException("Error migrating Core Persistence", ex);
+ }
+
+ ecmf = injector.getInstance( EntityCollectionManagerFactory.class );
+ ecif = injector.getInstance( EntityCollectionIndexFactory.class );
+ }
+
+
+ @Override
+ public EntityManager init(
+ EntityManagerFactoryImpl emf,
+ CassandraService cass,
+ CounterUtils counterUtils,
+ UUID applicationId,
+ boolean skipAggregateCounters ) {
+
+ super.init( emf, cass, counterUtils, applicationId, skipAggregateCounters );
+
+
+ return this;
+
+ }
+
+
+ private EntityManager getCpEntityManager() {
+ if ( cpEntityManager == null ) {
+ EntityCollectionManager ecm = getManager( SYSTEM_APP_SCOPE );
+ EntityCollectionIndex eci = getIndex( SYSTEM_APP_SCOPE );
+ try {
+ cpEntityManager = new CpEntityManager( getCollectionScope(), ecm, eci );
+ } catch (Exception ex) {
+ throw new RuntimeException("Error initializing CpEntityManager", ex);
+ }
+ }
+ return cpEntityManager;
+ }
+
+
+ @Override
+ public void setApplicationId( UUID applicationId ) {
+ super.setApplicationId( applicationId );
+ }
+
+
+ private CollectionScope getCollectionScope() throws Exception {
+
+ if ( scope == null && getApplication() != null ) {
+ Id appId = getAppId();
+ Id orgId = getOrgId();
+ scope = new CollectionScopeImpl( orgId, appId, "applications" );
+ }
+ return scope;
+ }
+
+ private Id getOrgId() throws Exception, QueryParseException {
+
+ Id orgId;
+ EntityCollectionManager ecm = getManager( SYSTEM_APP_SCOPE );
+ EntityCollectionIndex eci = getIndex( SYSTEM_APP_SCOPE );
+
+ String orgName = getApplication().getOrganizationName();
+
+ org.apache.usergrid.persistence.index.query.Query q =
+ org.apache.usergrid.persistence.index.query.Query.fromQL(
+ "name = '" + orgName + "'");
+
+ org.apache.usergrid.persistence.index.query.Results results = eci.execute(q);
+
+ if ( results.isEmpty() ) { // create if does not exist
+
+ org.apache.usergrid.persistence.model.entity.Entity entity =
+ new org.apache.usergrid.persistence.model.entity.Entity(
+ new SimpleId(UUIDGenerator.newTimeUUID(), "organization" ));
+
+ entity.setField( new StringField( "name", orgName ));
+ entity = ecm.write( entity ).toBlockingObservable().last();
+ log.debug("Added record for org name {}", orgName );
+
+ orgId = entity.getId();
+
+ } else {
+ org.apache.usergrid.persistence.model.entity.Entity entity =
+ results.getEntities().get(0);
+ orgId = entity.getId();
+ }
+
+ return orgId;
+ }
+
+
+ private Id getAppId() throws QueryParseException, Exception {
+
+ Id appId;
+ EntityCollectionManager ecm = getManager( SYSTEM_APP_SCOPE );
+ EntityCollectionIndex eci = getIndex( SYSTEM_APP_SCOPE );
+
+ UUID appUuid = getApplication().getUuid();
+
+ org.apache.usergrid.persistence.index.query.Query q =
+ org.apache.usergrid.persistence.index.query.Query.fromQL(
+ "uuid = '" + appUuid.toString() + "'");
+ org.apache.usergrid.persistence.index.query.Results results = eci.execute(q);
+ if ( results.isEmpty() ) { // create if does not exist
+
+ org.apache.usergrid.persistence.model.entity.Entity entity =
+ new org.apache.usergrid.persistence.model.entity.Entity(
+ new SimpleId(UUIDGenerator.newTimeUUID(), "application" ));
+
+ entity.setField( new UUIDField( "uuid", appUuid ));
+ entity = ecm.write( entity ).toBlockingObservable().last();
+ log.debug("Added record for app uuid {}", appUuid.toString() );
+
+ appId = entity.getId();
+
+ } else {
+ org.apache.usergrid.persistence.model.entity.Entity entity =
+ results.getEntities().get(0);
+ appId = entity.getId();
+ }
+ return appId;
+ }
+
+
+ private EntityCollectionIndex getIndex( CollectionScope scope ) {
+ EntityCollectionIndex eci = indexes.get( scope );
+ if ( eci == null ) {
+ eci = ecif.createCollectionIndex( scope );
+ indexes.put( scope, eci );
+ }
+ return eci;
+ }
+
+ private EntityCollectionManager getManager( CollectionScope scope ) {
+ EntityCollectionManager ecm = managers.get( scope );
+ if ( ecm == null ) {
+ ecm = ecmf.createCollectionManager( scope );
+ managers.put( scope, ecm);
+ }
+ return ecm;
+ }
+
+ //-------------------------------------------------------------------------
+ //---------------------------------------------------------- Implementation
+ //-------------------------------------------------------------------------
+
+ @Override
+ public Results searchCollection(EntityRef entityRef, String collectionName, Query query) throws Exception {
+ return getCpEntityManager().searchCollection(entityRef, collectionName, query);
+ }
+
+ @Override
+ public Entity addToCollection(EntityRef entityRef, String collectionName, EntityRef itemRef) throws Exception {
+ return getCpEntityManager().addToCollection(entityRef, collectionName, itemRef);
+ }
+
+ @Override
+ public Entity get(UUID entityid) throws Exception {
+ return getCpEntityManager().get(entityid);
+ }
+
+ @Override
+ public Entity create(UUID importId, String entityType, Map<String, Object> properties) throws Exception {
+ return getCpEntityManager().create(importId, entityType, properties);
+ }
+
+ @Override
+ public Entity create(String entityType, Map<String, Object> properties) throws Exception {
+ return getCpEntityManager().create( entityType, properties);
+ }
+
+ @Override
+ public void update(Entity entity) throws Exception {
+ getCpEntityManager().update(entity);
+ }
+
+ @Override
+ public EntityRef getApplicationRef() {
+ return getCpEntityManager().getApplicationRef();
+ }
+
+ @Override
+ public void updateProperties(EntityRef entityRef, Map<String, Object> properties) throws Exception {
+ getCpEntityManager().updateProperties(entityRef, properties);
+ }
+
+ @Override
+ public void delete(EntityRef entityRef) throws Exception {
+ getCpEntityManager().delete( entityRef );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/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 f9e0eb8..64ac9e8 100644
--- a/stack/core/src/main/resources/usergrid-core-context.xml
+++ b/stack/core/src/main/resources/usergrid-core-context.xml
@@ -156,7 +156,7 @@
<bean id="mailUtils" class="org.apache.usergrid.utils.MailUtils" />
- <bean id="entityManager" class="org.apache.usergrid.corepersistence.CpEntityManagerImpl" scope="prototype"/>
+ <bean id="entityManager" class="org.apache.usergrid.corepersistence.HybridEntityManager" scope="prototype"/>
<bean id="relationManager" class="org.apache.usergrid.persistence.cassandra.RelationManagerImpl" scope="prototype"/>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/stack/core/src/test/java/org/apache/usergrid/Application.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/Application.java b/stack/core/src/test/java/org/apache/usergrid/Application.java
index 1fdcd43..6945af2 100644
--- a/stack/core/src/test/java/org/apache/usergrid/Application.java
+++ b/stack/core/src/test/java/org/apache/usergrid/Application.java
@@ -137,4 +137,10 @@ public interface Application extends TestRule {
* @param properties the Map of property key value pairs
*/
void putAll( Map<String, Object> properties );
+
+ /**
+ * Remove and de-index entity.
+ * @param Entity to be removed.
+ */
+ public void remove( Entity entity ) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index 79a164c..9c718c2 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -33,6 +33,8 @@ import org.apache.usergrid.persistence.Query;
import org.apache.usergrid.persistence.Results;
import static junit.framework.Assert.assertNotNull;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.SimpleEntityRef;
public class CoreApplication implements Application, TestRule {
@@ -169,4 +171,10 @@ public class CoreApplication implements Application, TestRule {
public QueueManager getQm() {
return setup.getQmf().getQueueManager( getId() );
}
+
+ @Override
+ public void remove(Entity entity) throws Exception {
+ EntityRef ref = new SimpleEntityRef( entity.getType(), entity.getUuid() );
+ em.delete( ref );
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
index a09e696..d0b9caa 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
@@ -56,6 +56,23 @@ public class CollectionIT extends AbstractCoreIT {
@Test
+ public void testSimpleCrud() throws Exception {
+
+ app.put( "username", "edanuff" );
+ app.put( "email", "ed@anuff.com" );
+ Entity user = app.create( "user" );
+ assertNotNull( user );
+
+ user = app.get( user.getUuid() );
+ assertNotNull( user );
+
+ app.remove( user );
+ user = app.get( user.getUuid() );
+ //assertNull( user );
+ }
+
+
+ @Test
public void testCollection() throws Exception {
app.put( "username", "edanuff" );
app.put( "email", "ed@anuff.com" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/stack/core/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/core/src/test/resources/log4j.properties b/stack/core/src/test/resources/log4j.properties
index 0c30ab3..9a4b851 100644
--- a/stack/core/src/test/resources/log4j.properties
+++ b/stack/core/src/test/resources/log4j.properties
@@ -18,7 +18,7 @@
# and the pattern to %c instead of %l. (%l is slower.)
# output messages into a rolling log file as well as stdout
-log4j.rootLogger=INFO,stdout
+log4j.rootLogger=ERROR,stdout
# stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
@@ -39,7 +39,7 @@ log4j.logger.org.apache.usergrid.rest.security.AllowAjaxFilter=WARN, stdout
log4j.logger.me.prettyprint.hector.api.beans.AbstractComposite=ERROR, stdout
#log4j.logger.org.apache.usergrid.locking.singlenode.SingleNodeLockManagerImpl=DEBUG, stdout
-log4j.logger.org.apache.usergrid.persistence.cassandra.CpEntityManagerImpl=INFO, stdout
+log4j.logger.org.apache.usergrid.persistence.cassandra.CpEntityManagerImpl=DEBUG
#log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9954c2b3/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
deleted file mode 100644
index 6de9d39..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-
-package org.apache.usergrid.persistence.index.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.field.BooleanField;
-import org.apache.usergrid.persistence.model.field.DoubleField;
-import org.apache.usergrid.persistence.model.field.EntityObjectField;
-import org.apache.usergrid.persistence.model.field.Field;
-import org.apache.usergrid.persistence.model.field.FloatField;
-import org.apache.usergrid.persistence.model.field.IntegerField;
-import org.apache.usergrid.persistence.model.field.ListField;
-import org.apache.usergrid.persistence.model.field.LocationField;
-import org.apache.usergrid.persistence.model.field.LongField;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.model.field.value.Location;
-
-
-public class EntityBuilder {
-
- public static Entity fromMap( String scope, Map<String, Object> item ) {
- return fromMap( scope, null, item );
- }
-
- public static Entity fromMap( String scope, Entity entity, Map<String, Object> map ) {
-
- if ( entity == null ) {
- entity = new Entity();
- }
-
- for ( String fieldName : map.keySet() ) {
-
- Object value = map.get( fieldName );
-
- if ( value instanceof String ) {
- entity.setField( new StringField( fieldName, (String)value ));
-
- } else if ( value instanceof Boolean ) {
- entity.setField( new BooleanField( fieldName, (Boolean)value ));
-
- } else if ( value instanceof Integer ) {
- entity.setField( new IntegerField( fieldName, (Integer)value ));
-
- } else if ( value instanceof Double ) {
- entity.setField( new DoubleField( fieldName, (Double)value ));
-
- } else if ( value instanceof Float ) {
- entity.setField( new FloatField( fieldName, (Float)value ));
-
- } else if ( value instanceof Long ) {
- entity.setField( new LongField( fieldName, (Long)value ));
-
- } else if ( value instanceof List) {
- entity.setField( listToListField( scope, fieldName, (List)value ));
-
- } else if ( value instanceof Map ) {
-
- Field field = null;
-
- // is the map really a location element?
- Map<String, Object> m = (Map<String, Object>)value;
- if ( m.size() == 2) {
- Double lat = null;
- Double lon = null;
- try {
- if ( m.get("latitude") != null && m.get("longitude") != null ) {
- lat = Double.parseDouble( m.get("latitude").toString() );
- lon = Double.parseDouble( m.get("longitude").toString() );
-
- } else if ( m.get("lat") != null && m.get("lon") != null ) {
- lat = Double.parseDouble( m.get("lat").toString() );
- lon = Double.parseDouble( m.get("lon").toString() );
- }
- } catch ( NumberFormatException ignored ) {}
-
- if ( lat != null && lon != null ) {
- field = new LocationField( fieldName, new Location( lat, lon ));
- }
- }
-
- if ( field == null ) {
-
- // not a location element, process it as map
- entity.setField( new EntityObjectField( fieldName,
- fromMap( scope, (Map<String, Object>)value ))); // recursion
-
- } else {
- entity.setField( field );
- }
-
- } else {
- throw new RuntimeException("Unknown type " + value.getClass().getName());
- }
- }
-
- return entity;
- }
-
-
- private static ListField listToListField( String scope, String fieldName, List list ) {
-
- if (list.isEmpty()) {
- return new ListField( fieldName );
- }
-
- Object sample = list.get(0);
-
- if ( sample instanceof Map ) {
- return new ListField<Entity>( fieldName, processListForField( scope, list ));
-
- } else if ( sample instanceof List ) {
- return new ListField<List>( fieldName, processListForField( scope, list ));
-
- } else if ( sample instanceof String ) {
- return new ListField<String>( fieldName, (List<String>)list );
-
- } else if ( sample instanceof Boolean ) {
- return new ListField<Boolean>( fieldName, (List<Boolean>)list );
-
- } else if ( sample instanceof Integer ) {
- return new ListField<Integer>( fieldName, (List<Integer>)list );
-
- } else if ( sample instanceof Double ) {
- return new ListField<Double>( fieldName, (List<Double>)list );
-
- } else if ( sample instanceof Long ) {
- return new ListField<Long>( fieldName, (List<Long>)list );
-
- } else {
- throw new RuntimeException("Unknown type " + sample.getClass().getName());
- }
- }
-
-
- private static List processListForField( String scope, List list ) {
- if ( list.isEmpty() ) {
- return list;
- }
- Object sample = list.get(0);
-
- if ( sample instanceof Map ) {
- List<Entity> newList = new ArrayList<Entity>();
- for ( Map<String, Object> map : (List<Map<String, Object>>)list ) {
- newList.add( fromMap( scope, map ) );
- }
- return newList;
-
- } else if ( sample instanceof List ) {
- return processListForField( scope, list ); // recursion
-
- } else {
- return list;
- }
- }
-
-
-}