usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [15/35] usergrid git commit: Fixes to allow ImportAdmin to run in distributed env, also remove org-merge from ImportAdmins.
Date Mon, 25 Jan 2016 21:18:07 GMT
Fixes to allow ImportAdmin to run in distributed env, also remove org-merge from ImportAdmins.


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

Branch: refs/heads/USERGRID-1047
Commit: b22ac656cda8429ac4ae47ffbdfe78c9c4fb599b
Parents: e38ee3e
Author: Dave Johnson <snoopdave@apache.org>
Authored: Fri Jan 15 15:12:09 2016 -0500
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Fri Jan 15 15:12:09 2016 -0500

----------------------------------------------------------------------
 .../org/apache/usergrid/tools/ImportAdmins.java | 81 ++------------------
 .../org/apache/usergrid/tools/ToolBase.java     |  6 +-
 2 files changed, 11 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/b22ac656/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java b/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java
index 7a925b0..c1a60b8 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java
@@ -30,7 +30,6 @@ import org.apache.usergrid.persistence.EntityRef;
 import org.apache.usergrid.persistence.SimpleEntityRef;
 import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsException;
-import org.apache.usergrid.persistence.index.query.Identifier;
 import org.codehaus.jackson.JsonFactory;
 import org.codehaus.jackson.JsonParser;
 import org.codehaus.jackson.JsonToken;
@@ -118,9 +117,8 @@ public class ImportAdmins extends ToolBase {
     @SuppressWarnings("static-access")
     public Options createOptions() {
 
-        Option hostOption = OptionBuilder.withArgName("host")
-                .hasArg()
-                .withDescription("Cassandra host").create("host");
+        // inherit parent options
+        Options options = super.createOptions();
 
         Option inputDir = OptionBuilder
                 .hasArg()
@@ -138,10 +136,8 @@ public class ImportAdmins extends ToolBase {
                 .withDescription("Print on the console an echo of the content written to
the file")
                 .create(VERBOSE);
 
-        Options options = new Options();
-        options.addOption(hostOption);
-        options.addOption(writeThreads);
-        options.addOption(auditThreads);
+        options.addOption( writeThreads );
+        options.addOption( auditThreads );
         options.addOption( inputDir );
         options.addOption( verbose );
 
@@ -503,73 +499,8 @@ public class ImportAdmins extends ToolBase {
                 logger.warn("User {} has no dictionaries", entityRef.getUuid() );
             }
 
-        } else { // this is a duplicate user, so merge orgs
-
-            logger.info("Processing duplicate username={} email={}", dup.email, dup.username
);
-
-            Identifier identifier = dup.email != null ?
-                Identifier.fromEmail( dup.email ) : Identifier.from( dup.username );
-            User originalUser = em.get( em.getUserByIdentifier(identifier), User.class );
-
-            // get map of original user's orgs
-
-            UserInfo originalUserInfo = managementService.getAdminUserByEmail( originalUser.getEmail()
);
-            Map<String, Object> originalUserOrgData =
-                    managementService.getAdminUserOrganizationData( originalUser.getUuid()
);
-            Map<String, Map<String, Object>> originalUserOrgs =
-                    (Map<String, Map<String, Object>>) originalUserOrgData.get(
"organizations" );
-
-            // loop through duplicate user's orgs and give orgs to original user
-
-            List<Object> organizationsList = (List<Object>) metadata.get("organizations");
-            for (Object orgObject : organizationsList) {
-
-                Map<String, Object> orgMap = (Map<String, Object>) orgObject;
-                UUID orgUuid = UUID.fromString( (String) orgMap.get( "uuid" ) );
-                String orgName = (String) orgMap.get( "name" );
-
-                if (originalUserOrgs.get( orgName ) == null) { // original user does not
have this org
-
-                    OrganizationInfo orgInfo = managementService.getOrganizationByUuid( orgUuid
);
-
-                    if (orgInfo == null) { // org does not exist yet, create it and add original
user to it
-                        try {
-                            managementService.createOrganization( orgUuid, orgName, originalUserInfo,
false );
-                            orgInfo = managementService.getOrganizationByUuid( orgUuid );
-
-                            logger.debug( "Created new org {} for user {}:{}:{} from duplicate
user {}:{}",
-                                new Object[]{
-                                        orgInfo.getName(),
-                                        originalUser.getUsername(),
-                                        originalUser.getEmail(),
-                                        originalUser.getUuid(),
-                                        dup.username, dup.email
-                                });
-
-                        } catch (DuplicateUniquePropertyExistsException dpee) {
-                            logger.debug( "Org {} already exists", orgName );
-                        }
-                    } else { // org exists so add original user to it
-                        try {
-                            managementService.addAdminUserToOrganization( originalUserInfo,
orgInfo, false );
-                            logger.debug( "Added to org user {}:{}:{} from duplicate user
{}:{}",
-                                    new Object[]{
-                                            orgInfo.getName(),
-                                            originalUser.getUsername(),
-                                            originalUser.getEmail(),
-                                            originalUser.getUuid(),
-                                            dup.username, dup.email
-                                    });
-
-                        } catch (Exception e) {
-                            logger.error( "Error Adding user {} to org {}",
-                                    new Object[]{originalUserInfo.getEmail(), orgName} );
-                        }
-                    }
-
-                } // else original user already has this org
-
-            }
+        } else { // let the DuplicateAdminRepair tool handle merging of admins
+            logger.info("Not processing duplicate username={} email={}", dup.email, dup.username
);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b22ac656/stack/tools/src/main/java/org/apache/usergrid/tools/ToolBase.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/ToolBase.java b/stack/tools/src/main/java/org/apache/usergrid/tools/ToolBase.java
index 7fb7015..9725dda 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/ToolBase.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/ToolBase.java
@@ -101,7 +101,7 @@ public abstract class ToolBase {
             System.setProperty( "cassandra.url", line.getOptionValue( "host" ) );
             System.setProperty( "elasticsearch.hosts", line.getOptionValue( "eshost" ) );
             System.setProperty( "elasticsearch.cluster_name", line.getOptionValue( "escluster"
) );
-            System.setProperty( "usergrid.cluster_name", "usergrid" );
+            System.setProperty( "usergrid.cluster_name", line.getOptionValue( "ugcluster"
)  );
         }
 
         try {
@@ -141,6 +141,9 @@ public abstract class ToolBase {
         Option esClusterOption = OptionBuilder.withArgName( "escluster" ).hasArg()
             .withDescription( "ElasticSearch cluster name" ).create( "escluster" );
 
+        Option ugClusterOption = OptionBuilder.withArgName( "ugcluster" ).hasArg()
+            .withDescription( "Usergrid cluster name" ).create( "ugcluster" );
+
         Option remoteOption = OptionBuilder
             .withDescription( "Use remote Cassandra instance" ).create( "remote" );
 
@@ -152,6 +155,7 @@ public abstract class ToolBase {
         options.addOption( hostOption );
         options.addOption( esHostOption );
         options.addOption( esClusterOption );
+        options.addOption( ugClusterOption );
         options.addOption( remoteOption );
         options.addOption( verbose );
 


Mime
View raw message