usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [3/3] usergrid git commit: Added repair into audit tool
Date Tue, 08 Dec 2015 22:35:10 GMT
Added repair into audit tool


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

Branch: refs/heads/unique_index_logging
Commit: 51cf21c080d22d7341d4b2ac27a1683b70b3d9ab
Parents: 15d8164
Author: George Reyes <grey@apache.org>
Authored: Tue Dec 8 14:35:03 2015 -0800
Committer: George Reyes <grey@apache.org>
Committed: Tue Dec 8 14:35:03 2015 -0800

----------------------------------------------------------------------
 .../usergrid/tools/ManagementUserAudit.java     | 62 +++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/51cf21c0/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
b/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
index c15fe94..4d3a876 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.tools;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -36,8 +37,12 @@ import org.apache.thrift.TBaseHelper;
 
 import org.apache.usergrid.management.UserInfo;
 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.cassandra.CassandraService;
 import org.apache.usergrid.persistence.cassandra.EntityManagerImpl;
+import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.utils.UUIDUtils;
 
 import me.prettyprint.cassandra.service.RangeSlicesIterator;
@@ -255,7 +260,62 @@ public class ManagementUserAudit extends ToolBase {
 
                 }
                 if(cols.size()==1){
-                    logger.error( "Management user with uuid: {} and email: {} is broken",ue.fromByteBuffer(
cols.get( 0 ).getName()), uniqueValue );
+                    logger.error( "Management user with uuid: {} and email: {} is broken.
Starting Repair.",ue.fromByteBuffer( cols.get( 0 ).getName()), uniqueValue );
+                    EntityManager em = emf.getEntityManager( CassandraService.MANAGEMENT_APPLICATION_ID
);
+                    EntityRef entity = em.getUserByIdentifier( Identifier.fromEmail(uniqueValue)
);
+                    if(entity == null){
+                        entity = em.getUserByIdentifier(Identifier.fromName(uniqueValue));
+                    }
+                    if(entity == null){
+                        logger.error("Entity id parameter {} with {} value does not exist",
"email", uniqueValue);
+                        return;
+                        //throw new IllegalArgumentException("Entity not found.");
+                    }
+
+                    Map<String, Object> properties = new HashMap<String, Object>();
+                    properties.put("email", uniqueValue);
+                    properties.put("username", uniqueValue);
+                    properties.put("name", uniqueValue);
+                    properties.put("uuid", entity.getUuid());
+                    properties.put("confirmed", true);
+                    properties.put("activated", true);
+
+
+
+                    // Re-create the user entity with the existing UUID found in the index
+                    em.create(entity.getUuid(), User.ENTITY_TYPE, properties );
+                    logger.debug( "Repair Finished.Verifying Fix." );
+                    userInfo = managementService.getAdminUserByEmail( uniqueValue );
+                    if(userInfo==null){
+                        logger.error("Repair failed for uuid: {} and email {}", ue.fromByteBuffer(
cols.get( 0 ).getName()),uniqueValue );
+                    }
+                    if(!userInfo.getUuid().equals(cols.get( 0 ).getName())){
+                        Object[] loggerObjects = new Object[3];
+                        loggerObjects[0] = uniqueValue;
+                        loggerObjects[1] = ue.fromByteBuffer( cols.get( 0 ).getName());
+                        loggerObjects[2] = userInfo.getUuid();
+                        logger.error("Repair associated a new uuid for email {}. It should
have been uuid: {} but is instead uuid: {}", loggerObjects );
+                    }
+
+                    if(!userInfo.getUsername().equals( uniqueValue )){
+                        Object[] loggerObjects = new Object[3];
+                        loggerObjects[0] = uniqueValue;
+                        loggerObjects[1] = uniqueValue;
+                        loggerObjects[2] = uniqueValue;
+                        logger.error("Repair associated a new username for email {}. It should
have been username: {} but is instead username: {}", loggerObjects );
+                    }
+
+                    if(!userInfo.getEmail().equals( uniqueValue )){
+                        Object[] loggerObjects = new Object[3];
+                        loggerObjects[0] = uniqueValue;
+                        loggerObjects[1] = uniqueValue;
+                        loggerObjects[2] = uniqueValue;
+                        logger.error("Repair associated a new email for email {}. It should
have been email: {} but is instead email: {}", loggerObjects );
+                    }
+
+                    logger.debug("Repair succeeded for uuid: {} and email {}", ue.fromByteBuffer(
cols.get( 0 ).getName()),uniqueValue );
+
+
                 }
                 else{
                     logger.error( "Management user with email: {} is broken and has no uuid's
associated with it",uniqueValue );


Mime
View raw message