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/03/27 04:21:35 UTC

[2/4] git commit: Fixed formatting and removed commented out code and extra method.

Fixed formatting and removed commented out code and extra method.


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

Branch: refs/heads/master
Commit: 548570cda3681c3fa969061ac82c016fb2936499
Parents: 2c4bf9d
Author: grey <gr...@apigee.com>
Authored: Wed Mar 26 19:29:50 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Mar 26 19:29:50 2014 -0700

----------------------------------------------------------------------
 .../management/export/ExportServiceImpl.java    | 215 +++++++++----------
 1 file changed, 98 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/548570cd/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
index c87b1df..78d1e48 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
@@ -19,7 +19,6 @@ package org.apache.usergrid.management.export;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
@@ -81,7 +80,7 @@ public class ExportServiceImpl implements ExportService {
 
 
     @Override
-    public UUID schedule( final Map<String,Object> config ) throws Exception {
+    public UUID schedule( final Map<String, Object> config ) throws Exception {
 
         if ( config == null ) {
             logger.error( "export information cannot be null" );
@@ -95,8 +94,9 @@ public class ExportServiceImpl implements ExportService {
 
         EntityManager em = null;
         try {
-            em = emf.getEntityManager( ( UUID ) config.get("applicationId") );
-        }catch (Exception e) {
+            em = emf.getEntityManager( ( UUID ) config.get( "applicationId" ) );
+        }
+        catch ( Exception e ) {
             logger.error( "application doesn't exist within the current context" );
             return null;
         }
@@ -104,9 +104,10 @@ public class ExportServiceImpl implements ExportService {
         Export export = new Export();
 
         //update state
-        try{
+        try {
             export = em.create( export );
-        }catch(Exception e) {
+        }
+        catch ( Exception e ) {
             logger.error( "Export entity creation failed" );
             return null;
         }
@@ -133,20 +134,20 @@ public class ExportServiceImpl implements ExportService {
 
 
     /**
-     * Query Entity Manager for the string state of the Export Entity.
-     * This corresponds to the GET /export
+     * Query Entity Manager for the string state of the Export Entity. This corresponds to the GET /export
+     *
      * @return String
      */
     @Override
     public String getState( final UUID appId, final UUID uuid ) throws Exception {
 
         //get application entity manager
-        if(appId == null) {
+        if ( appId == null ) {
             logger.error( "Application context cannot be found." );
             return "Application context cannot be found.";
         }
 
-        if(uuid == null) {
+        if ( uuid == null ) {
             logger.error( "UUID passed in cannot be null." );
             return "UUID passed in cannot be null";
         }
@@ -166,41 +167,42 @@ public class ExportServiceImpl implements ExportService {
 
     @Override
     public void doExport( final JobExecution jobExecution ) throws Exception {
-        Map<String,Object> config = ( Map<String, Object> ) jobExecution.getJobData().getProperty( "exportInfo" );
+        Map<String, Object> config = ( Map<String, Object> ) jobExecution.getJobData().getProperty( "exportInfo" );
 
-        if (config  == null) {
+        if ( config == null ) {
             logger.error( "Export Information passed through is null" );
             return;
         }
         //get the entity manager for the application, and the entity that this Export corresponds to.
         UUID exportId = ( UUID ) jobExecution.getJobData().getProperty( EXPORT_ID );
-        if(config.get( "applicationId" ) == null) {
+        if ( config.get( "applicationId" ) == null ) {
             logger.error( "Export Information application uuid is null" );
             return;
         }
-        EntityManager em = emf.getEntityManager( ( UUID ) config.get("applicationId") );
+        EntityManager em = emf.getEntityManager( ( UUID ) config.get( "applicationId" ) );
         Export export = em.get( exportId, Export.class );
 
         //update the entity state to show that the job has officially started.
         export.setState( Export.State.STARTED );
         em.update( export );
 
-        if ( config.get("collectionName") == null) {
+        if ( config.get( "collectionName" ) == null ) {
             //exports all the applications for a given organization.
 
-            if(config.get( "organizationId" ) == null){
+            if ( config.get( "organizationId" ) == null ) {
                 logger.error( "No organization could be found" );
                 export.setState( Export.State.FAILED );
                 em.update( export );
                 return;
             }
-           exportApplicationsForOrg( ( UUID ) config.get( "organizationId" ),( UUID )config.get( "ApplicationId") ,config, jobExecution );
-
+            exportApplicationsForOrg( ( UUID ) config.get( "organizationId" ), ( UUID ) config.get( "ApplicationId" ),
+                    config, jobExecution );
         }
         else {
             try {
                 //exports all the applications for a single organization
-                exportApplicationForOrg( ( UUID ) config.get( "organizationId" ), (UUID) config.get("applicationId") ,config, jobExecution );
+                exportApplicationForOrg( ( UUID ) config.get( "organizationId" ),
+                        ( UUID ) config.get( "applicationId" ), config, jobExecution );
             }
             catch ( Exception e ) {
                 //if for any reason the backing up fails, then update the entity with a failed state.
@@ -214,7 +216,6 @@ public class ExportServiceImpl implements ExportService {
     }
 
 
-
     public SchedulerService getSch() {
         return sch;
     }
@@ -245,14 +246,11 @@ public class ExportServiceImpl implements ExportService {
         this.managementService = managementService;
     }
 
+
     /**
      * Exports all applications for the given organization.
-     * @param organizationUUID
-     * @param config
-     * @param jobExecution
-     * @throws Exception
      */
-    private void exportApplicationsForOrg( UUID organizationUUID, UUID applicationId ,final Map<String,Object> config,
+    private void exportApplicationsForOrg( UUID organizationUUID, UUID applicationId, final Map<String, Object> config,
                                            final JobExecution jobExecution ) throws Exception {
 
         //retrieves export entity
@@ -263,51 +261,47 @@ public class ExportServiceImpl implements ExportService {
         //sets up a output stream for s3 backup.
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
-        // Loop through the applications per organization
-        //BiMap<UUID, String> applications = managementService.getApplicationsForOrganization( organizationUUID );
-        //for ( Map.Entry<UUID, String> application : applications.entrySet() ) {
-
         ApplicationInfo application = managementService.getApplicationInfo( applicationId );
-        String appFileName = prepareOutputFileName( "application", application.getName(), null);
+        String appFileName = prepareOutputFileName( "application", application.getName(), null );
 
-            JsonGenerator jg = getJsonGenerator( baos );
+        JsonGenerator jg = getJsonGenerator( baos );
 
-            EntityManager em = emf.getEntityManager( applicationId );
+        EntityManager em = emf.getEntityManager( applicationId );
 
-            jg.writeStartArray();
+        jg.writeStartArray();
 
-            Map<String, Object> metadata = em.getApplicationCollectionMetadata();
-            long starting_time = System.currentTimeMillis();
+        Map<String, Object> metadata = em.getApplicationCollectionMetadata();
+        long starting_time = System.currentTimeMillis();
 
-            // Loop through the collections. This is the only way to loop
-            // through the entities in the application (former namespace).
-            //could support queries, just need to implement that in the rest endpoint.
-            for ( String collectionName : metadata.keySet() ) {
-                if(collectionName.equals( "exports" )) {
-                    continue;
-                }
-                //if the collection you are looping through doesn't match the name of the one you want. Don't export it.
-
-                if ( (config.get( "collectionName" ) == null)||collectionName.equals( config.get( "collectionName" ) ) ) {
-                    //Query entity manager for the entities in a collection
-                    Query query = new Query();
-                    query.setLimit( MAX_ENTITY_FETCH );
-                    query.setResultsLevel( Results.Level.ALL_PROPERTIES );
-                    Results entities = em.searchCollection( em.getApplicationRef(), collectionName, query );
-
-                    //pages through the query and backs up all results.
-                    PagingResultsIterator itr = new PagingResultsIterator( entities );
-                    for ( Object e : itr ) {
-                        starting_time = checkTimeDelta( starting_time, jobExecution );
-                        Entity entity = ( Entity ) e;
-                        jg.writeStartObject();
-                        jg.writeFieldName( "Metadata" );
-                        jg.writeObject(entity );
-                        saveCollectionMembers( jg, em, ( String ) config.get( "collectionName" ), entity );
-                        jg.writeEndObject();
-                    }
+        // Loop through the collections. This is the only way to loop
+        // through the entities in the application (former namespace).
+        //could support queries, just need to implement that in the rest endpoint.
+        for ( String collectionName : metadata.keySet() ) {
+            if ( collectionName.equals( "exports" ) ) {
+                continue;
+            }
+            //if the collection you are looping through doesn't match the name of the one you want. Don't export it.
+
+            if ( ( config.get( "collectionName" ) == null ) || collectionName
+                    .equals( config.get( "collectionName" ) ) ) {
+                //Query entity manager for the entities in a collection
+                Query query = new Query();
+                query.setLimit( MAX_ENTITY_FETCH );
+                query.setResultsLevel( Results.Level.ALL_PROPERTIES );
+                Results entities = em.searchCollection( em.getApplicationRef(), collectionName, query );
+
+                //pages through the query and backs up all results.
+                PagingResultsIterator itr = new PagingResultsIterator( entities );
+                for ( Object e : itr ) {
+                    starting_time = checkTimeDelta( starting_time, jobExecution );
+                    Entity entity = ( Entity ) e;
+                    jg.writeStartObject();
+                    jg.writeFieldName( "Metadata" );
+                    jg.writeObject( entity );
+                    saveCollectionMembers( jg, em, ( String ) config.get( "collectionName" ), entity );
+                    jg.writeEndObject();
                 }
-           // }
+            }
 
             // Close writer and file for this application.
             jg.writeEndArray();
@@ -327,59 +321,54 @@ public class ExportServiceImpl implements ExportService {
         }
     }
 
+
     //might be confusing, but uses the /s/ inclusion or exclusion nomenclature.
-    private void exportApplicationForOrg( UUID organizationUUID, UUID applicationUUID ,final Map<String,Object> config,
-                                           final JobExecution jobExecution ) throws Exception {
+    private void exportApplicationForOrg( UUID organizationUUID, UUID applicationUUID, final Map<String, Object> config,
+                                          final JobExecution jobExecution ) throws Exception {
 
         //retrieves export entity
         UUID exportId = ( UUID ) jobExecution.getJobData().getProperty( EXPORT_ID );
-        EntityManager exportManager = emf.getEntityManager( (UUID) config.get("applicationId") );
+        EntityManager exportManager = emf.getEntityManager( ( UUID ) config.get( "applicationId" ) );
         Export export = exportManager.get( exportId, Export.class );
 
         //sets up a output stream for s3 backup.
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
-        // Loop through the applications per organization
-        //BiMap<UUID, String> applications = managementService.getApplicationsForOrganization( organizationUUID );
-        //for ( Map.Entry<UUID, String> application : applications.entrySet() ) {
-
-           // logger.info( application.getValue() + " : " + application.getKey() );
-            ApplicationInfo application = managementService.getApplicationInfo( applicationUUID );
-
-            JsonGenerator jg = getJsonGenerator( baos );
-
-            EntityManager em = emf.getEntityManager( applicationUUID );
-
-            jg.writeStartArray();
-
-            Map<String, Object> metadata = em.getApplicationCollectionMetadata();
-            long starting_time = System.currentTimeMillis();
-
-            // Loop through the collections. This is the only way to loop
-            // through the entities in the application (former namespace).
-            //could support queries, just need to implement that in the rest endpoint.
-            for ( String collectionName : metadata.keySet() ) {
-                //if the collection you are looping through doesn't match the name of the one you want. Don't export it.
-                if ( collectionName.equals( (String) config.get("collectionName")) ) {
-                    //Query entity manager for the entities in a collection
-                    Query query = new Query();
-                    query.setLimit( MAX_ENTITY_FETCH );
-                    query.setResultsLevel( Results.Level.ALL_PROPERTIES );
-                    Results entities = em.searchCollection( em.getApplicationRef(), collectionName, query );
-
-                    //pages through the query and backs up all results.
-                    PagingResultsIterator itr = new PagingResultsIterator( entities );
-                    for ( Object e : itr ) {
-                        starting_time = checkTimeDelta( starting_time, jobExecution );
-                        Entity entity = ( Entity ) e;
-                        jg.writeStartObject();
-                        jg.writeFieldName( "Metadata" );
-                        jg.writeObject(entity );
-                        saveCollectionMembers( jg, em, ( String ) config.get( "collectionName" ), entity );
-                        jg.writeEndObject();
-                    }
+        ApplicationInfo application = managementService.getApplicationInfo( applicationUUID );
+
+        JsonGenerator jg = getJsonGenerator( baos );
+
+        EntityManager em = emf.getEntityManager( applicationUUID );
+
+        jg.writeStartArray();
+
+        Map<String, Object> metadata = em.getApplicationCollectionMetadata();
+        long starting_time = System.currentTimeMillis();
+
+        // Loop through the collections. This is the only way to loop
+        // through the entities in the application (former namespace).
+        //could support queries, just need to implement that in the rest endpoint.
+        for ( String collectionName : metadata.keySet() ) {
+            //if the collection you are looping through doesn't match the name of the one you want. Don't export it.
+            if ( collectionName.equals( ( String ) config.get( "collectionName" ) ) ) {
+                //Query entity manager for the entities in a collection
+                Query query = new Query();
+                query.setLimit( MAX_ENTITY_FETCH );
+                query.setResultsLevel( Results.Level.ALL_PROPERTIES );
+                Results entities = em.searchCollection( em.getApplicationRef(), collectionName, query );
+
+                //pages through the query and backs up all results.
+                PagingResultsIterator itr = new PagingResultsIterator( entities );
+                for ( Object e : itr ) {
+                    starting_time = checkTimeDelta( starting_time, jobExecution );
+                    Entity entity = ( Entity ) e;
+                    jg.writeStartObject();
+                    jg.writeFieldName( "Metadata" );
+                    jg.writeObject( entity );
+                    saveCollectionMembers( jg, em, ( String ) config.get( "collectionName" ), entity );
+                    jg.writeEndObject();
                 }
-           // }
+            }
 
             // Close writer and file for this application.
             jg.writeEndArray();
@@ -389,9 +378,9 @@ public class ExportServiceImpl implements ExportService {
 
             //sets up the Inputstream for copying the method to s3.
             InputStream is = new ByteArrayInputStream( baos.toByteArray() );
-            String appFileName = prepareOutputFileName( "application", application.getName(),collectionName);
+            String appFileName = prepareOutputFileName( "application", application.getName(), collectionName );
 
-                try {
+            try {
                 s3Export.copyToS3( is, config, appFileName );
             }
             catch ( Exception e ) {
@@ -404,9 +393,6 @@ public class ExportServiceImpl implements ExportService {
 
     /**
      * Regulates how long to wait until the next heartbeat.
-     * @param startingTime
-     * @param jobExecution
-     * @return
      */
     public long checkTimeDelta( long startingTime, final JobExecution jobExecution ) {
 
@@ -539,11 +525,6 @@ public class ExportServiceImpl implements ExportService {
     }
 
 
-    protected File createOutputFile( String type, String name, String colName ) {
-        return new File( prepareOutputFileName( type, name, colName ) );
-    }
-
-
     /**
      * @param type just a label such us: organization, application.
      *
@@ -553,7 +534,7 @@ public class ExportServiceImpl implements ExportService {
         StringBuilder str = new StringBuilder();
         str.append( name );
         str.append( "." );
-        if( CollectionName != null) {
+        if ( CollectionName != null ) {
             str.append( CollectionName );
             str.append( "." );
         }