usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [1/3] usergrid git commit: Add endpoint to change an organization's name unique index entry.
Date Sun, 20 Dec 2015 22:18:19 GMT
Repository: usergrid
Updated Branches:
  refs/heads/1.x 69eeb9187 -> a2df8f9d0


Add endpoint to change an organization's name unique index entry.


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

Branch: refs/heads/1.x
Commit: c66ea5deb39920eb75c48da1cc031367eec4fd59
Parents: 69eeb91
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Fri Dec 18 08:43:36 2015 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Fri Dec 18 08:43:36 2015 -0800

----------------------------------------------------------------------
 .../usergrid/persistence/EntityManager.java     |  3 ++
 .../cassandra/EntityManagerImpl.java            | 32 ++++++++++++++++++++
 .../organizations/OrganizationResource.java     | 32 ++++++++++++++++++++
 .../usergrid/management/ManagementService.java  |  2 ++
 .../cassandra/ManagementServiceImpl.java        | 11 +++++++
 5 files changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/c66ea5de/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 5dad23b..25c1ca6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -614,4 +614,7 @@ public interface EntityManager {
     public void grantGroupPermission( UUID groupId, String permission ) throws Exception;
 
     public void revokeGroupPermission( UUID groupId, String permission ) throws Exception;
+
+    public void repairUniqueValue (String collectionName, String entityType, String propertyName,
Object propertyValue,
+                                   UUID oldUUID, UUID newUUID, long timestamp) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c66ea5de/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index 2be0252..c6ba7eb 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -158,6 +158,7 @@ import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtil
 import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.toStorableBinaryValue;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.ALL_COUNT;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.MANAGEMENT_APPLICATION_ID;
+import static org.apache.usergrid.persistence.cassandra.CassandraService.RETRY_COUNT;
 import static org.apache.usergrid.persistence.cassandra.Serializers.be;
 import static org.apache.usergrid.persistence.cassandra.Serializers.le;
 import static org.apache.usergrid.persistence.cassandra.Serializers.se;
@@ -396,6 +397,37 @@ public class EntityManagerImpl implements EntityManager {
         return batch;
     }
 
+    public void repairUniqueValue (String collectionName, String entityType, String propertyName,
Object propertyValue,
+                                   UUID oldUUID, UUID newUUID, long timestamp) throws Exception
{
+
+
+        Keyspace ko = cass.getApplicationKeyspace( applicationId );
+        Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be );
+
+
+            Lock lock = getUniqueUpdateLock(cass.getLockManager(), applicationId, propertyValue,
entityType,
+                    propertyName);
+
+            try {
+                lock.lock();
+
+                //delete the entry for the old UUID
+                uniquePropertyDelete( m, collectionName, entityType, propertyName, propertyValue,
+                       oldUUID, timestamp - 1 );
+
+
+                uniquePropertyWrite( m, collectionName, propertyName, propertyValue, newUUID,
+                        timestamp );
+
+                batchExecute(m, RETRY_COUNT);
+
+            } finally {
+
+                lock.unlock();
+            }
+
+    }
+
 
     /**
      * Batch update properties.

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c66ea5de/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java
index 24a9f43..9d223f9 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationResource.java
@@ -35,6 +35,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.usergrid.utils.UUIDUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -276,6 +277,37 @@ public class OrganizationResource extends AbstractContextResource {
         return new JSONWithPadding( response, callback );
     }
 
+    @RequireOrganizationAccess
+    @Consumes(MediaType.APPLICATION_JSON)
+    @PUT
+    @Path("index")
+    public JSONWithPadding executePutOverride( @Context UriInfo ui, Map<String, Object>
json,
+                                       @QueryParam("callback") @DefaultValue("callback")
String callback )
+            throws Exception {
+
+        logger.debug( "update organization unique index" );
+
+        String oldUuidString = json.get( "oldUUID" ).toString();
+        String newUuidString = json.get( "oldUUID" ).toString();
+        if( oldUuidString.isEmpty() || newUuidString.isEmpty() ){
+            throw new IllegalArgumentException("Property oldUUID and newUUID are both required.");
+        }
+
+        UUID oldUUID = UUID.fromString( oldUuidString );
+        UUID newUUID = UUID.fromString( newUuidString );
+
+        if( !newUUID.equals(organization.getUuid()) ){
+            throw new IllegalArgumentException("Property newUUID must match the org name
or UUID in the uri path.");
+        }
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "update organization unique index" );
+        management.updateOrganizationUniqueIndex( organization, oldUUID );
+
+
+        return new JSONWithPadding( response, callback );
+    }
+
     @POST
     @Path("export")
     @Consumes(APPLICATION_JSON)

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c66ea5de/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 4b0cbfd..0e0657c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -95,6 +95,8 @@ public interface ManagementService {
 
     public void updateOrganization( OrganizationInfo organizationInfo ) throws Exception;
 
+    public void updateOrganizationUniqueIndex( OrganizationInfo organizationInfo, UUID oldUUID
) throws Exception;
+
     /** Deactivate the user and return it's current state */
     public User deactivateUser( UUID applicationId, UUID userId ) throws Exception;
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c66ea5de/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 3cdc806..b5eaf25 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -178,6 +178,8 @@ import static org.apache.usergrid.utils.ConversionUtils.uuid;
 import static org.apache.usergrid.utils.ListUtils.anyNull;
 import static org.apache.usergrid.utils.MapUtils.hashMap;
 import static org.apache.usergrid.utils.PasswordUtils.mongoPassword;
+import static org.apache.usergrid.utils.UUIDUtils.getTimestampInMicros;
+import static org.apache.usergrid.utils.UUIDUtils.newTimeUUID;
 
 
 public class ManagementServiceImpl implements ManagementService {
@@ -608,6 +610,15 @@ public class ManagementServiceImpl implements ManagementService {
         }
     }
 
+    /** this will fetch the org internally and re-put its data  */
+    public void updateOrganizationUniqueIndex( OrganizationInfo organizationInfo, UUID oldUUID
) throws Exception {
+
+        EntityManager em = emf.getEntityManager( MANAGEMENT_APPLICATION_ID );
+        long timestamp = getTimestampInMicros( newTimeUUID() );
+        em.repairUniqueValue("groups", "group", "path", organizationInfo.getName(), oldUUID,
+                organizationInfo.getUuid(), timestamp );
+    }
+
 
     @Override
     public OrganizationInfo importOrganization( UUID organizationId, OrganizationInfo organizationInfo,


Mime
View raw message