usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [2/3] git commit: Adding repair toolkit when application metadata mismatch
Date Tue, 04 Feb 2014 16:20:41 GMT
Adding repair toolkit when application metadata mismatch


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

Branch: refs/pull/47/merge
Commit: 6c14dc28f3cd79452e8d5a56f4703ce7c17eba94
Parents: 5faeb10
Author: Sungju Jin <sungju@softwaregeeks.org>
Authored: Wed Feb 5 00:19:25 2014 +0900
Committer: Sungju Jin <sungju@softwaregeeks.org>
Committed: Wed Feb 5 00:19:25 2014 +0900

----------------------------------------------------------------------
 .../RepairingMismatchedApplicationMetadata.java | 57 ++++++++++++++++++++
 1 file changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6c14dc28/stack/tools/src/main/java/org/usergrid/tools/RepairingMismatchedApplicationMetadata.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/usergrid/tools/RepairingMismatchedApplicationMetadata.java
b/stack/tools/src/main/java/org/usergrid/tools/RepairingMismatchedApplicationMetadata.java
new file mode 100644
index 0000000..24146fc
--- /dev/null
+++ b/stack/tools/src/main/java/org/usergrid/tools/RepairingMismatchedApplicationMetadata.java
@@ -0,0 +1,57 @@
+package org.usergrid.tools;
+
+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.usergrid.persistence.Schema.PROPERTY_NAME;
+import static org.usergrid.persistence.Schema.PROPERTY_UUID;
+import static org.usergrid.persistence.cassandra.CassandraPersistenceUtils.addInsertToMutator;
+import static org.usergrid.persistence.cassandra.CassandraPersistenceUtils.batchExecute;
+import static org.usergrid.persistence.cassandra.CassandraService.APPLICATIONS_CF;
+import static org.usergrid.persistence.cassandra.CassandraService.RETRY_COUNT;
+
+public class RepairingMismatchedApplicationMetadata extends ToolBase {
+
+    public static final ByteBufferSerializer be = new ByteBufferSerializer();
+
+    @Override
+    public Options createOptions() {
+        Options options = super.createOptions();
+        return options;
+    }
+
+    @Override
+    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, (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());
+                }
+            }
+        }
+
+        logger.info("Waiting 60 sec...");
+        Thread.sleep(1000 * 60);
+    }
+}


Mime
View raw message