Updates repair process to page through large organization counts.
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/RepairingMismatchedApplicationMetadata.java b/stack/tools/src/main/java/org/apache/usergrid/tools/RepairingMismatchedApplicationMetadata.java
index dee1702..7b18ccc 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/RepairingMismatchedApplicationMetadata.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/RepairingMismatchedApplicationMetadata.java
@@ -16,16 +16,27 @@
  */
 package org.apache.usergrid.tools;
 
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+
+import org.apache.usergrid.management.OrganizationInfo;
+
 import com.google.common.collect.BiMap;
+
 import me.prettyprint.cassandra.serializers.ByteBufferSerializer;
 import me.prettyprint.hector.api.Keyspace;
 import me.prettyprint.hector.api.mutation.Mutator;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Options;
-
-import java.nio.ByteBuffer;
-import java.util.Map;
-import java.util.UUID;
 
 import static me.prettyprint.hector.api.factory.HFactory.createMutator;
 import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
@@ -35,39 +46,74 @@
 import static org.apache.usergrid.persistence.cassandra.CassandraService.APPLICATIONS_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.RETRY_COUNT;
 
+
 public class RepairingMismatchedApplicationMetadata extends ToolBase {
 
     public static final ByteBufferSerializer be = new ByteBufferSerializer();
 
+    private static final Logger logger = LoggerFactory.getLogger( RepairingMismatchedApplicationMetadata.class );
+
+
     @Override
     public Options createOptions() {
         Options options = super.createOptions();
         return options;
     }
 
+
     @Override
-    public void runTool(CommandLine line) throws Exception {
+    public void runTool( CommandLine line ) throws Exception {
         startSpring();
 
-        BiMap<UUID, String> orgs = managementService.getOrganizations();
-        for(Map.Entry org : orgs.entrySet()) {
-            BiMap<UUID, String> apps = managementService.getApplicationsForOrganization((UUID)org.getKey());
-            for(Map.Entry app : apps.entrySet()) {
-                UUID applicationId = emf.lookupApplication((String)app.getValue());
-                if( applicationId == null ) {
-                    String appName = (String)app.getValue();
-                    Keyspace ko = cass.getSystemKeyspace();
-                    Mutator<ByteBuffer> m = createMutator(ko, be);
-                    long timestamp = cass.createTimestamp();
-                    addInsertToMutator(m, APPLICATIONS_CF, appName, PROPERTY_UUID, app.getKey(), timestamp);
-                    addInsertToMutator(m, APPLICATIONS_CF, appName, PROPERTY_NAME, appName, timestamp);
-                    batchExecute(m, RETRY_COUNT);
-                    logger.info("UUID {}, NAME {}", app.getKey(), app.getValue());
+        //sucks, but it's not picking up the configuration
+        LogManager.getLogger( RepairingMismatchedApplicationMetadata.class ).setLevel( Level.INFO );
+
+        UUID orgId = null;
+        List<OrganizationInfo> orgs;
+
+        final int size = 1000;
+
+
+        do {
+            orgs = managementService.getOrganizations( orgId, size );
+
+
+            for ( OrganizationInfo org : orgs ) {
+
+                orgId = org.getUuid();
+
+                logger.info( "Auditing org {}", org.getName() );
+
+                try {
+                    BiMap<UUID, String> apps = managementService.getApplicationsForOrganization( org.getUuid() );
+
+
+                    for ( Map.Entry<UUID, String> app : apps.entrySet() ) {
+
+                        logger.info( "Auditing org {} app {}", org.getName(), app.getValue() );
+
+                        UUID applicationId = emf.lookupApplication( app.getValue() );
+                        if ( applicationId == null ) {
+                            String appName = app.getValue();
+                            Keyspace ko = cass.getSystemKeyspace();
+                            Mutator<ByteBuffer> m = createMutator( ko, be );
+                            long timestamp = cass.createTimestamp();
+                            addInsertToMutator( m, APPLICATIONS_CF, appName, PROPERTY_UUID, app.getKey(), timestamp );
+                            addInsertToMutator( m, APPLICATIONS_CF, appName, PROPERTY_NAME, appName, timestamp );
+                            batchExecute( m, RETRY_COUNT );
+                            logger.info( "Repairing alias with app uuid {}, and name {}", app.getKey(),
+                                    app.getValue() );
+                        }
+                    }
+                }
+                catch ( Exception e ) {
+                    logger.error( "Unable to process applications for organization {}", org, e );
                 }
             }
         }
+        while ( orgs != null && orgs.size() == size );
 
-        logger.info("Waiting 60 sec...");
-        Thread.sleep(1000 * 60);
+        logger.info( "Completed repairing aliases" );
+        Thread.sleep( 1000 * 60 );
     }
 }
diff --git a/stack/tools/src/main/resources/log4j.properties b/stack/tools/src/main/resources/log4j.properties
new file mode 100644
index 0000000..e9c23e5
--- /dev/null
+++ b/stack/tools/src/main/resources/log4j.properties
@@ -0,0 +1,45 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# for production, you should probably set the root to INFO
+# and the pattern to %c instead of %l.  (%l is slower.)
+
+# output messages into a rolling log file as well as stdout
+log4j.rootLogger=INFO,stdout
+
+# stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+#log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) [%c] - %m%n
+
+log4j.category.org.apache.usergrid.tools=TRACE, stdout
+
+log4j.logger.org.apache.usergrid.persistence.cassandra.DB=WARN, stdout
+log4j.logger.org.apache.usergrid.persistence.cassandra.BATCH=WARN, stdout
+log4j.logger.org.apache.usergrid.persistence.cassandra.EntityManagerFactoryImpl=WARN, stdout
+log4j.logger.org.apache.usergrid.persistence.cassandra.DaoUtils=WARN, stdout
+log4j.logger.org.apache.usergrid.persistence.cassandra.EntityManagerImpl=WARN, stdout
+log4j.logger.org.apache.usergrid.persistence.cassandra.ConnectionRefImpl=WARN, stdout
+log4j.logger.me.prettyprint.cassandra.hector.TimingLogger=WARN, stdout
+log4j.logger.org.apache.usergrid.rest.security.AllowAjaxFilter=WARN, stdout
+log4j.logger.me.prettyprint.hector.api.beans.AbstractComposite=ERROR, stdout
+#log4j.logger.org.apache.usergrid.locking.singlenode.SingleNodeLockManagerImpl=DEBUG, stdout
+
+log4j.logger.org.apache.usergrid.persistence.hector.CountingMutator=INFO, stdout
+
+#log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout
+
diff --git a/stack/tools/src/main/resources/log4j.xml b/stack/tools/src/main/resources/log4j.xml
deleted file mode 100644
index dc45e13..0000000
--- a/stack/tools/src/main/resources/log4j.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-        http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
-    <appender class="org.apache.log4j.ConsoleAppender" name="stdout">
-        <layout class="org.apache.log4j.PatternLayout">
-            <param value="%d %p (%t) [%c] - %m%n" name="ConversionPattern"/>
-        </layout>
-    </appender>
-    <logger name="org.apache.usergrid.tools">
-        <level value="info" />
-        <appender-ref ref="stdout"/>
-    </logger>
-</log4j:configuration>
\ No newline at end of file