You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/08/22 16:15:50 UTC

[54/95] [abbrv] git commit: added implementation for correctly resuming the job and handle invalid UUID

added implementation for correctly resuming the job and handle invalid UUID


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

Branch: refs/heads/import-feature
Commit: 3c9eef6c4c636fcc99ef88f6083eb861956706ea
Parents: f06f5fa
Author: Pooja Jain <Ap...@Pooja-Jains-MacBook-Pro.local>
Authored: Thu Jul 24 14:28:39 2014 -0700
Committer: Pooja Jain <Ap...@Pooja-Jains-MacBook-Pro.local>
Committed: Thu Jul 24 14:28:39 2014 -0700

----------------------------------------------------------------------
 portal/config.js                                |   2 +-
 .../management/importUG/ImportServiceImpl.java  | 133 +++++++++++--------
 2 files changed, 78 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c9eef6c/portal/config.js
----------------------------------------------------------------------
diff --git a/portal/config.js b/portal/config.js
index 223279c..8adb6e8 100644
--- a/portal/config.js
+++ b/portal/config.js
@@ -4,7 +4,7 @@ Usergrid.showNotifcations = true;
 
 
 // used only if hostname does not match a real server name
-Usergrid.overrideUrl = 'http://poojaandharishdancepartyextravaganza2.usergrid.com/';
+Usergrid.overrideUrl = 'http://import.usergrid.com/';
 
 Usergrid.options = {
   client:{

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c9eef6c/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java
index c984d09..5e435db 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importUG/ImportServiceImpl.java
@@ -22,15 +22,15 @@ import org.apache.usergrid.batch.service.SchedulerService;
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.ManagementService;
 import org.apache.usergrid.management.OrganizationInfo;
+import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.EntityManagerFactory;
 import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.entities.Import;
 import org.apache.usergrid.persistence.entities.JobData;
 import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.JsonParser;
 import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.JsonParser;
 import org.codehaus.jackson.JsonToken;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.slf4j.Logger;
@@ -469,12 +469,22 @@ public class ImportServiceImpl implements ImportService {
                 // this handles partially completed files by updating entities from the point of failure
                 if(!lastUpdatedUUID.equals(""))
                 {
-                    // go till the next entity
+                    // go till the last updated entity
                      while(!jp.getText().equals(lastUpdatedUUID)) {
                          jp.nextToken();
                      }
+                    // skip the last one and start from teh next one
+                    // to avoid connections
+                    while(jp.getCurrentToken() != JsonToken.START_OBJECT) {
+                        jp.nextToken();
+                    }
+                    // to avoid dictionaries
+                    while(jp.getCurrentToken() != JsonToken.START_OBJECT) {
+                        jp.nextToken();
+                    }
                 }
 
+                // get to start of an object i.e next entity.
                 while(jp.getCurrentToken() != JsonToken.START_OBJECT) {
                     jp.nextToken();
                 }
@@ -526,82 +536,93 @@ public class ImportServiceImpl implements ImportService {
      */
     private void importEntityStuff( JsonParser jp, EntityManager em, EntityManager rootEm, Import importUG, int index) throws Exception {
 
+        ArrayList fileNames = (ArrayList) importUG.getDynamicProperties().get("files");
+        Entity entity = null;
         EntityRef ownerEntityRef=null;
         String entityUuid="";
         String entityType="";
 
         // Go inside the value after getting the owner entity id.
-        while ( jp.nextToken() != JsonToken.END_OBJECT ) {
+        while (jp.nextToken() != JsonToken.END_OBJECT) {
+
             String collectionName = jp.getCurrentName();
 
-            // create the connections
-            if ( collectionName.equals( "connections" ) ) {
+            try {
+                // create the connections
+                if (collectionName.equals("connections")) {
 
-                jp.nextToken(); // START_OBJECT
-                while ( jp.nextToken() != JsonToken.END_OBJECT ) {
-                    String connectionType = jp.getCurrentName();
+                    jp.nextToken(); // START_OBJECT
+                    while (jp.nextToken() != JsonToken.END_OBJECT) {
+                        String connectionType = jp.getCurrentName();
 
-                    jp.nextToken(); // START_ARRAY
-                    while ( jp.nextToken() != JsonToken.END_ARRAY ) {
-                        String entryId = jp.getText();
+                        jp.nextToken(); // START_ARRAY
+                        while (jp.nextToken() != JsonToken.END_ARRAY) {
+                            String entryId = jp.getText();
 
-                        EntityRef entryRef = em.getRef( UUID.fromString( entryId ) );
-                        // Store in DB
-                        em.createConnection(ownerEntityRef, connectionType, entryRef);
+                            EntityRef entryRef = em.getRef(UUID.fromString(entryId));
+                            // Store in DB
+                            em.createConnection(ownerEntityRef, connectionType, entryRef);
+                        }
                     }
                 }
-            }
-            // add dictionaries
-            else if ( collectionName.equals( "dictionaries" ) ) {
-
-                jp.nextToken(); // START_OBJECT
-                while ( jp.nextToken() != JsonToken.END_OBJECT ) {
-
-                    String dictionaryName = jp.getCurrentName();
-
-                    jp.nextToken();
+                // add dictionaries
+                else if (collectionName.equals("dictionaries")) {
 
-                    @SuppressWarnings("unchecked") Map<String, Object> dictionary = jp.readValueAs( HashMap.class );
+                    jp.nextToken(); // START_OBJECT
+                    while (jp.nextToken() != JsonToken.END_OBJECT) {
 
-                    em.addMapToDictionary( ownerEntityRef, dictionaryName, dictionary );
-                }
-            }
-            else {
-                // Regular collections
-                jp.nextToken(); // START_OBJECT
+                        String dictionaryName = jp.getCurrentName();
 
-                Map<String,Object> properties = new HashMap<String,Object>();
+                        jp.nextToken();
 
-                JsonToken token = jp.nextToken();
+                        @SuppressWarnings("unchecked") Map<String, Object> dictionary = jp.readValueAs(HashMap.class);
 
-                while ( token != JsonToken.END_OBJECT ) {
-                    if(token == JsonToken.VALUE_STRING || token == JsonToken.VALUE_NUMBER_INT )
-                    {
-                        String key = jp.getCurrentName();
-                        if(key.equals("uuid")) {
-                            entityUuid = jp.getText();
-                        }
-                        else if(key.equals("type")) {
-                            entityType = jp.getText();
-                        }
-                        else
-                        {
-                            String value = jp.getText();
-                            properties.put(key,value);
+                        em.addMapToDictionary(ownerEntityRef, dictionaryName, dictionary);
+                    }
+                } else {
+                    // Regular collections
+                    jp.nextToken(); // START_OBJECT
+
+                    Map<String, Object> properties = new HashMap<String, Object>();
+
+                    JsonToken token = jp.nextToken();
+
+                    while (token != JsonToken.END_OBJECT) {
+                        if (token == JsonToken.VALUE_STRING || token == JsonToken.VALUE_NUMBER_INT) {
+                            String key = jp.getCurrentName();
+                            if (key.equals("uuid")) {
+                                entityUuid = jp.getText();
+
+                            } else if (key.equals("type")) {
+                                entityType = jp.getText();
+                            } else if (key.length() != 0 && jp.getText().length() != 0) {
+                                String value = jp.getText();
+                                properties.put(key, value);
+                            }
                         }
+                        token = jp.nextToken();
                     }
-                    token = jp.nextToken();
-                }
-
-                Entity e = em.create(UUID.fromString(entityUuid),entityType,properties);
-                ownerEntityRef = em.getRef(UUID.fromString(entityUuid));
 
+                    entity = em.create(UUID.fromString(entityUuid), entityType, properties);
+                    ownerEntityRef = em.getRef(UUID.fromString(entityUuid));
+                }
+            }
+            catch (IllegalArgumentException e) {
+                // skip illegal entity UUID and go to next one
+                ((Map<String, Object>) fileNames.get(index)).put("Entity Creation Error", e.getMessage());
+                rootEm.update(importUG);
+            }
+            catch (Exception e) {
+                // skip illegal entity UUID and go to next one
+                ((Map<String, Object>) fileNames.get(index)).put("Miscellaneous Error", e.getMessage());
+                rootEm.update(importUG);
             }
         }
         // update the last updated entity
-        ArrayList fileNames = (ArrayList) importUG.getDynamicProperties().get("files");
-        ((Map<String,Object>)fileNames.get(index)).put("lastUpdatedUUID",entityUuid);
-        rootEm.update(importUG);
+        if(entity != null) {
+            ((Map<String, Object>) fileNames.get(index)).put("lastUpdatedUUID", entityUuid);
+            rootEm.update(importUG);
+        }
     }
 }