usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [12/52] [abbrv] git commit: uuid fixes, adding serialization fixes
Date Wed, 03 Sep 2014 22:11:07 GMT
uuid fixes, adding serialization fixes


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

Branch: refs/heads/two-dot-o-push-notifications
Commit: 64ad13d5a1ec3fe9d158e39ac4a6d80df3aedcfe
Parents: 9c47aee
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Tue Aug 26 12:50:54 2014 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Thu Aug 28 09:30:04 2014 -0600

----------------------------------------------------------------------
 stack/core/pom.xml                              | 20 +++++++-
 .../corepersistence/CpEntityManager.java        | 49 +++++++++++---------
 .../corepersistence/CpRelationManager.java      | 10 ++--
 .../java/org/apache/usergrid/mq/Message.java    | 13 +++---
 .../apache/usergrid/persistence/EntityRef.java  |  3 ++
 .../apache/usergrid/persistence/PathQuery.java  |  8 ++--
 .../usergrid/persistence/SimpleEntityRef.java   | 36 +++++++-------
 .../usergrid/persistence/PathQueryIT.java       |  4 +-
 .../persistence/core/util/ValidationUtils.java  |  2 +-
 .../usergrid/persistence/index/query/Query.java |  4 +-
 10 files changed, 93 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/core/pom.xml
----------------------------------------------------------------------
diff --git a/stack/core/pom.xml b/stack/core/pom.xml
index 0972a89..41c7244 100644
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@ -576,6 +576,24 @@
             <version>${rx.version}</version>
         </dependency>
 
-    </dependencies>
+
+    <dependency>
+      <groupId>com.codahale.metrics</groupId>
+      <artifactId>metrics-core</artifactId>
+      <version>${metrics.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>com.codahale.metrics</groupId>
+      <artifactId>metrics-graphite</artifactId>
+      <version>${metrics.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.clearspring.analytics</groupId>
+      <artifactId>stream</artifactId>
+      <version>2.7.0</version>
+    </dependency>
+
+  </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 28124c2..f40bc3b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -33,6 +33,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.UUID;
 
+import com.clearspring.analytics.hash.MurmurHash;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.Assert;
@@ -323,10 +324,10 @@ public class CpEntityManager implements EntityManager {
 
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope
);
 
-        if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
-            throw new IllegalArgumentException(
-                "Entity Id " + id.getType() + ":"+ id.getUuid() +" uuid not time based");
-        }
+//        if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
+//            throw new IllegalArgumentException(
+//                "Entity Id " + id.getType() + ":"+ id.getUuid() +" uuid not time based");
+//        }
 
        org.apache.usergrid.persistence.model.entity.Entity cpEntity = 
                 ecm.load( id ).toBlockingObservable().last();
@@ -410,10 +411,10 @@ public class CpEntityManager implements EntityManager {
 
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope
);
 
-        if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
-            throw new IllegalArgumentException(
-                "Entity Id " + id.getType() + ":"+ id.getUuid() +" uuid not time based");
-        }
+//        if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
+//            throw new IllegalArgumentException(
+//                "Entity Id " + id.getType() + ":"+ id.getUuid() +" uuid not time based");
+//        }
 
         org.apache.usergrid.persistence.model.entity.Entity cpEntity = 
                 ecm.load( id ).toBlockingObservable().last();
@@ -489,10 +490,10 @@ public class CpEntityManager implements EntityManager {
             } );
         }
 
-        if ( !UUIDUtils.isTimeBased( entityId.getUuid() ) ) {
-            throw new IllegalArgumentException(
-                "Entity Id " + entityId.getType() + ":"+ entityId.getUuid() +" uuid not time
based");
-        }
+//        if ( !UUIDUtils.isTimeBased( entityId.getUuid() ) ) {
+//            throw new IllegalArgumentException(
+//                "Entity Id " + entityId.getType() + ":"+ entityId.getUuid() +" uuid not
time based");
+//        }
 
         org.apache.usergrid.persistence.model.entity.Entity cpEntity =
                 ecm.load( entityId ).toBlockingObservable().last();
@@ -543,10 +544,10 @@ public class CpEntityManager implements EntityManager {
 
         Id entityId = new SimpleId( entityRef.getUuid(), entityRef.getType() );
 
-        if ( !UUIDUtils.isTimeBased( entityId.getUuid() ) ) {
-            throw new IllegalArgumentException(
-                "Entity Id " + entityId.getType() + ":"+ entityId.getUuid() +" uuid not time
based");
-        }
+//        if ( !UUIDUtils.isTimeBased( entityId.getUuid() ) ) {
+//            throw new IllegalArgumentException(
+//                "Entity Id " + entityId.getType() + ":"+ entityId.getUuid() +" uuid not
time based");
+//        }
 
         org.apache.usergrid.persistence.model.entity.Entity entity = 
                 ecm.load( entityId ).toBlockingObservable().last();
@@ -984,10 +985,10 @@ public class CpEntityManager implements EntityManager {
 
         Id entityId = new SimpleId( entityRef.getUuid(), entityRef.getType() );
 
-        if ( !UUIDUtils.isTimeBased( entityId.getUuid() ) ) {
-            throw new IllegalArgumentException(
-                "Entity Id " + entityId.getType() + ":"+entityId.getUuid() +" uuid not time
based");
-        }
+//        if ( !UUIDUtils.isTimeBased( entityId.getUuid() ) ) {
+//            throw new IllegalArgumentException(
+//                "Entity Id " + entityId.getType() + ":"+entityId.getUuid() +" uuid not
time based");
+//        }
 
         org.apache.usergrid.persistence.model.entity.Entity cpEntity =
                 ecm.load( entityId ).toBlockingObservable().last();
@@ -2363,7 +2364,13 @@ public class CpEntityManager implements EntityManager {
             return null;
         }
 
-        long timestamp = UUIDUtils.getTimestampInMicros( timestampUuid );
+        long timestamp = 0;
+
+        if(UUIDUtils.isTimeBased(timestampUuid)) {
+            timestamp = UUIDUtils.getTimestampInMicros(timestampUuid);
+        }else{
+            timestamp = MurmurHash.hash64(timestampUuid);
+        }
 
         UUID itemId = UUIDUtils.newTimeUUID();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 31d32dd..9199d19 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import com.clearspring.analytics.hash.MurmurHash;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.Assert;
@@ -685,12 +686,13 @@ public class CpRelationManager implements RelationManager {
                 headEntity.getType(), headEntity.getUuid(), 
                 itemRef.getType(), itemRef.getUuid() });
 
+        long uuidHash = MurmurHash.hash64( memberEntity.getId().getUuid());
         // create graph edge connection from head entity to member entity
         Edge edge = new SimpleEdge(
-            cpHeadEntity.getId(), 
-            edgeType, 
-            memberEntity.getId(), 
-            memberEntity.getId().getUuid().timestamp() );
+            cpHeadEntity.getId(),
+            edgeType,
+            memberEntity.getId(),
+           uuidHash);
         GraphManager gm = managerCache.getGraphManager(applicationScope);
         gm.writeEdge(edge).toBlockingObservable().last();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/core/src/main/java/org/apache/usergrid/mq/Message.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/mq/Message.java b/stack/core/src/main/java/org/apache/usergrid/mq/Message.java
index 85aea1f..b48fe74 100644
--- a/stack/core/src/main/java/org/apache/usergrid/mq/Message.java
+++ b/stack/core/src/main/java/org/apache/usergrid/mq/Message.java
@@ -30,6 +30,7 @@ import java.util.UUID;
 
 import javax.xml.bind.annotation.XmlRootElement;
 
+import com.clearspring.analytics.hash.MurmurHash;
 import org.apache.usergrid.utils.UUIDUtils;
 
 import com.fasterxml.jackson.annotation.JsonAnyGetter;
@@ -484,13 +485,13 @@ public class Message {
 
 
     public void setUuid( UUID uuid ) {
-        if ( isTimeBased( uuid ) ) {
+        //if ( isTimeBased( uuid ) ) {
             properties.put( MESSAGE_ID, uuid );
-            properties.put( MESSAGE_TIMESTAMP, getTimestampInMillis( uuid ) );
-        }
-        else {
-            throw new IllegalArgumentException( "Not a time-based UUID" );
-        }
+            properties.put( MESSAGE_TIMESTAMP, MurmurHash.hash64(uuid));
+//        }
+//        else {
+//            throw new IllegalArgumentException( "Not a time-based UUID" );
+//        }
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java
index b9d60cb..8133840 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java
@@ -17,8 +17,11 @@
 package org.apache.usergrid.persistence;
 
 
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+
 import java.util.UUID;
 
+@JsonTypeInfo( use= JsonTypeInfo.Id.CLASS,include= JsonTypeInfo.As.WRAPPER_OBJECT,property="@class"
)
 public interface EntityRef {
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java b/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java
index 6721fa6..c1d0360 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java
@@ -26,7 +26,7 @@ public class PathQuery<E> {
 
     private PathQuery source;
     private Query query;
-    private EntityRef head;
+    private SimpleEntityRef head;
 
 
     public PathQuery() {
@@ -38,7 +38,7 @@ public class PathQuery<E> {
      *
      * @param head the top-level entity
      */
-    public PathQuery( EntityRef head ) {
+    public PathQuery( SimpleEntityRef head ) {
         this.head = head;
         this.query = null;
     }
@@ -50,7 +50,7 @@ public class PathQuery<E> {
      * @param head the top-level entity
      * @param query the query - must have a collection or connectType value set
      */
-    public PathQuery( EntityRef head, Query query ) {
+    public PathQuery( SimpleEntityRef head, Query query ) {
         if ( query.getCollection() == null && query.getConnectionType() == null )
{
             throw new IllegalArgumentException( "Query must have a collection or connectionType
value" );
         }
@@ -122,7 +122,7 @@ public class PathQuery<E> {
     }
 
 
-    public EntityRef getHead() {
+    public SimpleEntityRef getHead() {
         return head;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
index 3e0f413..65f093f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
@@ -17,6 +17,9 @@
 package org.apache.usergrid.persistence;
 
 
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
 import java.util.UUID;
 
 
@@ -26,24 +29,25 @@ public class SimpleEntityRef implements EntityRef {
 
     protected final String type;
 
-    protected final UUID id;
+    protected final UUID uuid;
 
 
-    public SimpleEntityRef( UUID id ) {
-        this.id = id;
+    public SimpleEntityRef( UUID uuid ) {
+        this.uuid = uuid;
         type = null;
     }
 
 
-    public SimpleEntityRef( String type, UUID id ) {
+    @JsonCreator
+    public SimpleEntityRef(@JsonProperty("type")  String type,@JsonProperty("uuid")  UUID
uuid ) {
         this.type = type;
-        this.id = id;
+        this.uuid = uuid;
     }
 
 
     public SimpleEntityRef( EntityRef entityRef ) {
         type = entityRef.getType();
-        id = entityRef.getUuid();
+        uuid = entityRef.getUuid();
     }
 
 
@@ -54,7 +58,7 @@ public class SimpleEntityRef implements EntityRef {
 
     @Override
     public UUID getUuid() {
-        return id;
+        return uuid;
     }
 
 
@@ -69,8 +73,8 @@ public class SimpleEntityRef implements EntityRef {
     }
 
 
-    public static EntityRef ref( UUID entityId ) {
-        return new SimpleEntityRef( null, entityId );
+    public static EntityRef ref( UUID uuid ) {
+        return new SimpleEntityRef( null, uuid );
     }
 
 
@@ -83,7 +87,7 @@ public class SimpleEntityRef implements EntityRef {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ( ( id == null ) ? 0 : id.hashCode() );
+        result = prime * result + ( ( uuid == null ) ? 0 : uuid.hashCode() );
         result = prime * result + ( ( type == null ) ? 0 : type.hashCode() );
         return result;
     }
@@ -101,12 +105,12 @@ public class SimpleEntityRef implements EntityRef {
             return false;
         }
         SimpleEntityRef other = ( SimpleEntityRef ) obj;
-        if ( id == null ) {
-            if ( other.id != null ) {
+        if ( uuid == null ) {
+            if ( other.uuid != null ) {
                 return false;
             }
         }
-        else if ( !id.equals( other.id ) ) {
+        else if ( !uuid.equals( other.uuid ) ) {
             return false;
         }
         if ( type == null ) {
@@ -123,13 +127,13 @@ public class SimpleEntityRef implements EntityRef {
 
     @Override
     public String toString() {
-        if ( ( type == null ) && ( id == null ) ) {
+        if ( ( type == null ) && ( uuid == null ) ) {
             return "EntityRef(" + NULL_ID.toString() + ")";
         }
         if ( type == null ) {
-            return "EntityRef(" + id.toString() + ")";
+            return "EntityRef(" + uuid.toString() + ")";
         }
-        return type + "(" + id + ")";
+        return type + "(" + uuid + ")";
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/core/src/test/java/org/apache/usergrid/persistence/PathQueryIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PathQueryIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PathQueryIT.java
index bdaef0a..16fae85 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PathQueryIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PathQueryIT.java
@@ -92,7 +92,7 @@ public class PathQueryIT extends AbstractCoreIT {
         deviceQuery.addFilter( "index >= 2" );
         int expectedDeviceQuerySize = 3;
 
-        PathQuery<EntityRef> usersPQ = new PathQuery<EntityRef>( em.getApplicationRef(),
userQuery );
+        PathQuery<EntityRef> usersPQ = new PathQuery<EntityRef>( new SimpleEntityRef(
em.getApplicationRef()), userQuery );
         PathQuery<Entity> devicesPQ = usersPQ.chain( deviceQuery );
         HashSet set = new HashSet( expectedUserQuerySize * expectedDeviceQuerySize );
         Iterator<Entity> i = devicesPQ.iterator( em );
@@ -174,7 +174,7 @@ public class PathQueryIT extends AbstractCoreIT {
         deviceQuery.addFilter( "index >= 4" );
         int expectedDeviceQuerySize = 3;
 
-        PathQuery groupsPQ = new PathQuery( em.getApplicationRef(), groupQuery );
+        PathQuery groupsPQ = new PathQuery(new SimpleEntityRef( em.getApplicationRef() ),
groupQuery );
         PathQuery usersPQ = groupsPQ.chain( userQuery );
         PathQuery<Entity> devicesPQ = usersPQ.chain( deviceQuery );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/util/ValidationUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/util/ValidationUtils.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/util/ValidationUtils.java
index 62f7ab6..141978a 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/util/ValidationUtils.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/util/ValidationUtils.java
@@ -80,7 +80,7 @@ public class ValidationUtils {
 
         Preconditions.checkNotNull( uuid, "The id uuid is required to be set" );
 
-        Preconditions.checkArgument( uuid.version() == UUID_VERSION, "The uuid must be version
1" );
+        //Preconditions.checkArgument( uuid.version() == UUID_VERSION, "The uuid must be
version 1" );
 
         final String type = entityId.getType();
         Preconditions.checkNotNull( type, "The id type is required " );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/64ad13d5/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
index 9dda724..569c08d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
@@ -28,6 +28,8 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
 import org.antlr.runtime.ANTLRStringStream;
 import org.antlr.runtime.ClassicToken;
 import org.antlr.runtime.CommonTokenStream;
@@ -1081,7 +1083,7 @@ public class Query {
         private final Query.SortDirection direction;
 
 
-        public SortPredicate( String propertyName, Query.SortDirection direction ) {
+        public SortPredicate(@JsonProperty("propertyName")  String propertyName, @JsonProperty("direction")
 Query.SortDirection direction ) {
             if ( propertyName == null ) {
                 throw new NullPointerException( "Property name was null" );
             }


Mime
View raw message