usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [3/4] usergrid git commit: Added org fix to ApplicationAuditOrgFix and confirmed fix. also added application re-establishing and reconnecting logic to tool for regular application audit.
Date Fri, 18 Dec 2015 19:35:17 GMT
Added org fix to ApplicationAuditOrgFix and confirmed fix. also added application re-establishing
and reconnecting logic to tool for regular application audit.


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

Branch: refs/heads/unique_index_logging
Commit: 00c2d0571db34dd99f7ed4fd7a7161a6ca19492f
Parents: d2a9fb8
Author: George Reyes <grey@apache.org>
Authored: Fri Dec 18 11:16:21 2015 -0800
Committer: George Reyes <grey@apache.org>
Committed: Fri Dec 18 11:16:21 2015 -0800

----------------------------------------------------------------------
 .../apache/usergrid/tools/ApplicationAudit.java | 65 ++++++++++++++++++--
 .../usergrid/tools/ApplicationAuditOrgFix.java  | 44 ++++++++++---
 2 files changed, 94 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/00c2d057/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAudit.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAudit.java b/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAudit.java
index 3a025cb..037dc8f 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAudit.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAudit.java
@@ -19,6 +19,7 @@ package org.apache.usergrid.tools;
 
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -34,10 +35,13 @@ import org.apache.thrift.TBaseHelper;
 
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.OrganizationInfo;
+import org.apache.usergrid.management.cassandra.ManagementServiceImpl;
+import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.EntityRef;
 import org.apache.usergrid.persistence.SimpleEntityRef;
 import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
+import org.apache.usergrid.security.AuthPrincipalType;
 import org.apache.usergrid.utils.UUIDUtils;
 
 import com.google.common.collect.BiMap;
@@ -257,7 +261,47 @@ public class ApplicationAudit extends ToolBase {
         if(applicationInfo==null){
             if( !applicationUUID.equals( UUID.fromString( "00000000-0000-0000-0000-000000000010"
) )) {
 
-                logger.error( "Application uuid: {} and name: {} has return null.", applicationUUID,
uniqueValue );
+                //logger.error( "Application uuid: {} and name: {} has return null.", applicationUUID,
uniqueValue );
+
+                String orgName = uniqueValue.split( "/" )[0];
+                OrganizationInfo organizationInfo = managementService.getOrganizationByName(
orgName );
+                if(organizationInfo == null) {
+
+                    logger.error( "Application uuid: {} with name: {} returned null and org
name: {} cannot be found.",
+                            new Object[]{applicationUUID, uniqueValue,orgName });
+                }
+                else{
+                    logger.error("Org name: {} and uuid: {} is no longer associated with
App uuid: {} and name: {} because APP NO LONGER EXISTS. RECREATING.",
+                            new Object[]{organizationInfo.getName(),organizationInfo.getUuid(),applicationUUID,uniqueValue});
+
+
+
+
+                    Map<String,Object> applicationProperties = new HashMap<String,
Object>(  );
+                    applicationProperties.put( "name",uniqueValue );
+                    try {
+                        em.create( applicationUUID, ManagementServiceImpl.APPLICATION_INFO,
applicationProperties);
+                    }catch(Exception e){
+                        logger.error("Found the following error: {} when trying to recreate.",e.getMessage());
+                    }
+                    applicationInfo = managementService.getApplicationInfo( applicationUUID
);
+                    if(applicationInfo!=null){
+                        logger.info("Org name: {} and uuid: {}  with App uuid: {} and name:
{} has been Repaired.",
+                                new Object[]{organizationInfo.getName(),organizationInfo.getUuid(),applicationInfo.getId(),applicationInfo.getName()});
+                    }
+                    else{
+                        logger.error("Org name: {} and uuid: {}  with App uuid: {} and name:
{} repair has failed.",
+                                new Object[]{organizationInfo.getName(),organizationInfo.getUuid(),applicationUUID,uniqueValue});
+                    }
+
+//                    ManagementServiceImpl managementServiceImpl = ( ManagementServiceImpl
) managementService;
+//                    managementServiceImpl.writeUserToken( MANAGEMENT_APPLICATION_ID, applicationEntity,
encryptionService
+//                            .plainTextCredentials( generateOAuthSecretKey( AuthPrincipalType.APPLICATION
), null,
+//                                    MANAGEMENT_APPLICATION_ID ) );
+//                    managementService.addApplicationToOrganization( organizationInfo.getUuid(),
applicationUUID);
+                }
+
+
             }
         }
         else{
@@ -265,9 +309,20 @@ public class ApplicationAudit extends ToolBase {
             if(organizationInfo==null) {
                 if(!applicationUUID.equals( UUID.fromString( "00000000-0000-0000-0000-000000000001")))
{
 
-                    logger.error(
-                            "Application uuid: {} with name: {} is lost and has no organizations
associated with it.",
-                            applicationUUID, applicationInfo.getName() );
+                    String orgName = applicationInfo.getName().split( "/" )[0];
+                    organizationInfo = managementService.getOrganizationByName( orgName );
+                    if(organizationInfo == null) {
+
+                        logger.error( "Application uuid: {} with name: {} is lost and org
name: {} cannot be found.",
+                                new Object[]{applicationUUID, applicationInfo.getName(),orgName
});
+                    }
+                    else{
+                        logger.error("Org name: {} and uuid: {} is no longer associated with
App uuid: {} and name: {}. Restablishing connection...",
+                                new Object[]{organizationInfo.getName(),organizationInfo.getUuid(),applicationUUID,applicationInfo.getName()});
+
+                        managementService.addApplicationToOrganization( organizationInfo.getUuid(),
applicationUUID);
+
+                    }
                 }
             }
             else{
@@ -309,7 +364,7 @@ public class ApplicationAudit extends ToolBase {
                     loggingObject[0] = app.getKey();
                     loggingObject[1] = app.getValue();
                     loggingObject[2] = uuid;
-                    logger.info( "Application with uuid: {} and name: {} was returned from
orgUUID: {} ",loggingObject );
+                    logger.info( "Application with uuid: {} and name: {} was returned from
orgUUID: {} but that orgUUID cannot be found.",loggingObject );
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/00c2d057/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAuditOrgFix.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAuditOrgFix.java
b/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAuditOrgFix.java
index d99d28f..0c7ad01 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAuditOrgFix.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/ApplicationAuditOrgFix.java
@@ -43,6 +43,7 @@ import org.apache.usergrid.persistence.Results;
 import org.apache.usergrid.persistence.SimpleEntityRef;
 import org.apache.usergrid.persistence.cassandra.RelationManagerImpl;
 import org.apache.usergrid.persistence.cassandra.Serializers;
+import org.apache.usergrid.persistence.entities.Group;
 import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
 import org.apache.usergrid.utils.UUIDUtils;
 
@@ -118,11 +119,11 @@ public class ApplicationAuditOrgFix extends ToolBase {
 
         options.addOption( hostOption );
 
-        Option appOption =
-                OptionBuilder.withArgName( "app" ).hasArg().isRequired( false ).withDescription(
"Application uuid" )
-                             .create( "app" );
-
-        options.addOption( appOption );
+//        Option appOption =
+//                OptionBuilder.withArgName( "app" ).hasArg().isRequired( false ).withDescription(
"Application uuid" )
+//                             .create( "app" );
+//
+//        options.addOption( appOption );
 
         Option entityUniquePropertyValue =
                 OptionBuilder.withArgName( ENTITY_UNIQUE_PROPERTY_VALUE ).hasArg().isRequired(
false )
@@ -148,11 +149,17 @@ public class ApplicationAuditOrgFix extends ToolBase {
 
 
         // go through each collection and audit the values
-        Keyspace ko = cass.getUsergridApplicationKeyspace();
         Keyspace keyspaceforOrgAppFix = cass.getApplicationKeyspace( MANAGEMENT_APPLICATION_ID
);
+        EntityManager em = emf.getEntityManager( MANAGEMENT_APPLICATION_ID );
         Mutator<ByteBuffer> repairMutator = createMutator( cass.getApplicationKeyspace(
MANAGEMENT_APPLICATION_ID ), be );
         int index = 0;
-        HashSet<UUID> orgUUIDs = getOrgUUIDS();
+        HashSet<UUID> orgUUIDs = new HashSet<UUID>(  );
+        if(line.getOptionValue( ENTITY_UNIQUE_PROPERTY_VALUE )==null) {
+             orgUUIDs = getOrgUUIDS();
+        }
+        else{
+            orgUUIDs.add( UUID.fromString( line.getOptionValue( ENTITY_UNIQUE_PROPERTY_VALUE
) ) );
+        }
 
 
         for ( UUID orgUUID : orgUUIDs ) {
@@ -167,7 +174,6 @@ public class ApplicationAuditOrgFix extends ToolBase {
                     logger.error( "There are no applications associated with this org: {}",
orgUUID );
                 }
                 else {
-                    Boolean orgFixed = false;
                     for ( HColumn<DynamicComposite, ByteBuffer> col : cols ) {
                         DynamicComposite dynamicComposite = col.getName();
                         UUID applicationId = ( UUID ) dynamicComposite.get( 0 );
@@ -177,7 +183,25 @@ public class ApplicationAuditOrgFix extends ToolBase {
                             logger.info("The following application uuid: {} returns null
for org uuid: {}",applicationId,orgUUID);
                         }
                         else{
-                            logger.info("The following application with information: {},
 will be used to repair org uuid: {}.",applicationInfo,orgUUID);
+
+                            String uniqueValue = applicationInfo.getName().split( "/" )[0];
+                            logger.info("The following application with information: {} ,with
the derived name: {} ,will be used to repair org uuid: {}",new Object[]{applicationInfo.getName(),uniqueValue,orgUUID});
+
+                            Group organizationEntity = new Group();
+                            organizationEntity.setPath( uniqueValue );
+                            try {
+                                em.create( orgUUID, Group.ENTITY_TYPE, organizationEntity.getProperties()
);
+                                organizationEntity = em.get( orgUUID, Group.class );
+                                if ( organizationEntity == null ) {
+                                    logger.error( "OrgName: {} with uuid: {} could not be
created", uniqueValue, orgUUID );
+                                }
+                                else{
+                                    logger.info( "OrgName: {}  with uuid: {} was fixed.",
uniqueValue, orgUUID );
+                                }
+                            }catch(Exception e){
+                                logger.error("Could not create: {} because of {}",uniqueValue,e.getMessage());
+                            }
+                            break;
                         }
 
                     }
@@ -209,7 +233,7 @@ public class ApplicationAuditOrgFix extends ToolBase {
                     if(verificationOrganizationInfo==null){
                         logger.error("Repair failed for rowkey: {} and org uuid: {}",key,orgUUID);
                     }
-                    else if(verificationOrganizationInfo.getUuid().equals( organizationInfo.getUuid())&&
verificationOrganizationInfo.equals( organizationInfo.getName() )){
+                    else if(verificationOrganizationInfo.getUuid().equals( organizationInfo.getUuid())&&
verificationOrganizationInfo.getName().equals( organizationInfo.getName() )){
                         logger.info( "Org name: {} with uuid is fixed: {}",organizationInfo.getUuid(),organizationInfo.getUuid()
);
                     }
                 }


Mime
View raw message