usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [34/50] [abbrv] git commit: Added comment to Export.java detailing the process to work through the Job. Added methods to access the entity. Fixed ManagementResource so that it takes a @GET call. Currently doesn’t do anything. Fixed ManagementTests so tha
Date Tue, 25 Feb 2014 06:21:48 GMT
Added comment to Export.java detailing the process to work through the Job. Added methods to
access the entity.
Fixed ManagementResource so that it takes a @GET call. Currently doesn’t do anything.
Fixed ManagementTests so that it properly appends the UUID to the end of it. Currently unsure
what endpoint to query so it doesn’t work.
Removed comment, and made ExportInfo a typed entity. This might be removed later on as it
is not being stored anywhere.
Removed getJobUUID method. Now UUID of job is returned from the scheduler method.
Added updates to ExportService. Now properly creates entities and updates the states as appropriate.
Also changed entity loops to be clearer.
Fixed and cleaned up File validity tests in ManagementService Tests.


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

Branch: refs/pull/60/merge
Commit: 59966c2c6dc7e90f96d73a269c502866ca49fc3d
Parents: 871a9a5
Author: grey <greyes@apigee.com>
Authored: Wed Feb 19 15:11:36 2014 -0800
Committer: grey <greyes@apigee.com>
Committed: Wed Feb 19 15:11:36 2014 -0800

----------------------------------------------------------------------
 .../usergrid/persistence/entities/Export.java   | 139 ++++++++-------
 .../rest/management/ManagementResource.java     |  18 +-
 .../rest/management/ManagementResourceIT.java   |  15 +-
 .../org/usergrid/management/ExportInfo.java     |  23 +--
 .../usergrid/management/export/ExportJob.java   |   6 +-
 .../management/export/ExportService.java        |   8 +-
 .../management/export/ExportServiceImpl.java    | 169 ++++++++++++-------
 .../cassandra/ManagementServiceIT.java          |  94 ++++++-----
 8 files changed, 266 insertions(+), 206 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59966c2c/stack/core/src/main/java/org/usergrid/persistence/entities/Export.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/entities/Export.java b/stack/core/src/main/java/org/usergrid/persistence/entities/Export.java
index 818dbf8..fdb41ac 100644
--- a/stack/core/src/main/java/org/usergrid/persistence/entities/Export.java
+++ b/stack/core/src/main/java/org/usergrid/persistence/entities/Export.java
@@ -1,14 +1,8 @@
 package org.usergrid.persistence.entities;
 
 
-import java.util.Map;
-
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-import org.usergrid.persistence.PathQuery;
 import org.usergrid.persistence.TypedEntity;
 import org.usergrid.persistence.annotations.EntityProperty;
 
@@ -17,21 +11,34 @@ import org.usergrid.persistence.annotations.EntityProperty;
  *
  *
  */
+
+/**
+ *
+ *the sch system doesn't make any assumes about the job or how it works.
+ * and so if I need additional information to be persistant.
+ *
+ * The way to save data between queue and storing it.
+ *
+ * in my case, create a export entity. before I schedule the job and it'll have the pending
state in it and
+ * all the information I need to run. Then I'll pass the ID of the export info I saved in
a collection and i'll put that in the jbo
+ * data.
+ *
+ * persist the state in mechanisum that they can all access.
+ *
+ * I could make it a class and I can make it an entity. That way I can get it in and out.
+ * doesn't get exposed to the user.
+ */
 @XmlRootElement
 public class Export extends TypedEntity {
 
-    public static final String ENTITY_TYPE = "export";
-
-    //Additional states could include CREATED,SCHEDULED,EXPIRED
     public static enum State {
-        PENDING, STARTED, FAILED, COMPLETED,
+        //CREATED, FAILED, SCHEDULED, STARTED, FINISHED, CANCELED, EXPIRED
+        PENDING,STARTED,FAILED,COMPLETED
     }
 
-    /** Map Notifier ID -> Properties data provided */
     @EntityProperty
-    protected Map<String, Object> properties;
+    public State curState;
 
-    /** Time processed */
     @EntityProperty
     protected Long queued;
 
@@ -43,7 +50,12 @@ public class Export extends TypedEntity {
     @EntityProperty
     protected Long finished;
 
-    /** True if notification is canceled */
+
+    /** Time to expire the exportJob */
+    @EntityProperty
+    protected Long expire;
+
+    /** True if exportJob is canceled */
     @EntityProperty
     protected Boolean canceled;
 
@@ -52,85 +64,92 @@ public class Export extends TypedEntity {
     protected String errorMessage;
 
     @EntityProperty
-    protected PathQuery<String> pathQuery;
+    public State getState() {
+        if (getErrorMessage() != null) {
+            return State.FAILED;
+//        } else if (getCanceled() == Boolean.TRUE) {
+//            return State.CANCELED;
+        } else if (getFinished() != null) {
+            return State.COMPLETED;
+        } else if (getStarted() != null) {
+            return State.STARTED;
+        }
+//        } else if (isExpired()) {
+//            return State.EXPIRED;
+//        } else if (getQueued() != null) {
+//            return State.SCHEDULED;
+//        }
+        return State.PENDING;
+    }
 
-    /** Contains the Query included with the Path **/
+    public Export() {
+    }
 
-    public Export () {
+    public boolean isExpired () {
+        return (expire != null && expire > System.currentTimeMillis());
     }
 
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Map<String, Object> getProperties() {
-        return properties;
+    public Long getStarted() {
+        return started;
     }
 
-    public void setProperties(Map<String,Object> properties) {
-        this.properties = properties;
+
+    public void setStarted( final Long started ) {
+        this.started = started;
     }
 
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Long getCompleted() {
+
+    public Long getFinished() {
         return finished;
     }
 
-    public void setCompleted(Long finished) {
+
+    public void setFinished( final Long finished ) {
         this.finished = finished;
     }
 
-    @JsonSerialize(include = Inclusion.NON_NULL)
+
+    public Long getExpire() {
+        return expire;
+    }
+
+
+    public void setExpire( final Long expire ) {
+        this.expire = expire;
+    }
+
+
     public Boolean getCanceled() {
         return canceled;
     }
 
-    public void setCanceled(Boolean canceled) {
-        this.canceled = canceled;
+    //state should moved to a derived state, but it is not there yet.
+    public void setState(State setter) {
+        curState = setter;
     }
 
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Long getStarted() {
-        return started;
-    }
 
-    public void setStarted(Long started) {
-        this.started = started;
+    public void setCanceled( final Boolean canceled ) {
+        this.canceled = canceled;
     }
 
-    @JsonSerialize(include = Inclusion.NON_NULL)
+
     public String getErrorMessage() {
         return errorMessage;
     }
 
-    public void setErrorMessage(String errorMessage) {
+
+    public void setErrorMessage( final String errorMessage ) {
         this.errorMessage = errorMessage;
     }
 
-    public void setState(State ignored) {
-        //state is derived from getState, not set.
-    }
 
-    @EntityProperty
-    public State getState() {
-        if (getErrorMessage() != null) {
-            return State.FAILED;
-        } else if (getCompleted() != null) {
-            return State.COMPLETED;
-        } else if (getStarted() != null) {
-            return State.STARTED;
-        }
-        return State.PENDING;
+    public Long getQueued() {
+        return queued;
     }
-    /* there might need to be queued stuff here.  */
-    /*
-    * Path Query Ignored for first pass*/
 
-    //ask scott why these are ignored
-    @JsonIgnore
-    public PathQuery<String> getPathQuery() {
-        return pathQuery;
-    }
 
-    public void setPathQuery(PathQuery<String> pathQuery) {
-        this.pathQuery = pathQuery;
+    public void setQueued( final Long queued ) {
+        this.queued = queued;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59966c2c/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
b/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
index 99b1dc4..20043b3 100644
--- a/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
+++ b/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
@@ -28,6 +28,7 @@ import javax.ws.rs.GET;
 import javax.ws.rs.HeaderParam;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
@@ -468,8 +469,7 @@ public class ManagementResource extends AbstractContextResource {
 
         //parse the json into some useful object (the config params)
             ExportInfo objEx = new ExportInfo(json);
-            exportService.schedule(objEx);
-            jobUUID = exportService.getJobUUID();
+            jobUUID = exportService.schedule(objEx);
             uuidRet.put( "jobUUID", jobUUID.toString() );
 
         }
@@ -494,16 +494,18 @@ public class ManagementResource extends AbstractContextResource {
     }
 
     @GET
-    @Path( "export" )
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response exportGetJson (@Context UriInfo ui,
-                                   Map<String, Object> json,
-                                   @QueryParam( "callback" ) @DefaultValue( "" ) String callback)
{
+    @Path( "export/{jobUUID: [A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}}"
)
+    public Response exportGetJson(@Context UriInfo ui,@PathParam( "jobUUID" ) String jobUUIDStr,
+                                  @QueryParam( "callback" ) @DefaultValue( "" ) String callback
) throws Exception {
 
+//get the info by looking up the job data from the uuid and then call the get state on it
+        //that way you'll find the correct state.
+        //String state = exportService.getState(jobUUIDStr);
 
 
 
-        return Response.status(SC_OK).entity(jobStatus).build();
+        return Response.status(SC_OK).entity(state).build();
+        //return Response.status(SC_OK).entity(state).build();
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59966c2c/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
b/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
index 71b346f..27b9b56 100644
--- a/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
@@ -657,15 +657,22 @@ public class ManagementResourceIT extends AbstractRestIT {
         node = resource().path( "/management/export" )
                          .accept( MediaType.APPLICATION_JSON )
                          .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class, payload
);
+        String uuid = String.valueOf( node.get( "jobUUID" ) );
+        uuid = uuid.replaceAll( "\"","" );
+
 
         try {
-            node = resource().path( "/management/export/"+node.get("jobUUID") ).accept( MediaType.APPLICATION_JSON
).type( MediaType.APPLICATION_JSON_TYPE )
-                .get( JsonNode.class );
+            node = resource().path( "test-organization/default-app/").queryParam( "access_token",
+                    superAdminToken() ).accept( MediaType.APPLICATION_JSON )
+                    .type( MediaType.APPLICATION_JSON_TYPE ).get( JsonNode.class );
+          //  node = resource().path( "/management/exportStats/"+uuid ).accept( MediaType.APPLICATION_JSON
).type( MediaType.APPLICATION_JSON_TYPE )
+            //    .get( JsonNode.class );
         }catch(UniformInterfaceException uie) {
             responseStatus = uie.getResponse().getClientResponseStatus();
         }
 
-        assertEquals( Status.OK,responseStatus );
+
+        assertEquals( Status.OK, responseStatus );
         assertEquals( "PENDING",node.get( "jobStatus" ) );
 
     }
@@ -706,7 +713,7 @@ public class ManagementResourceIT extends AbstractRestIT {
         properties.put( "storage_provider","s3");
         properties.put( "storage_info",storage_info);
 
-        payload.put( "path", "test-organization/test-app/user");
+        payload.put( "path", "test-organization/test-app");
         payload.put( "properties", properties);
         return payload;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59966c2c/stack/services/src/main/java/org/usergrid/management/ExportInfo.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/usergrid/management/ExportInfo.java b/stack/services/src/main/java/org/usergrid/management/ExportInfo.java
index 36df16c..2589fa3 100644
--- a/stack/services/src/main/java/org/usergrid/management/ExportInfo.java
+++ b/stack/services/src/main/java/org/usergrid/management/ExportInfo.java
@@ -2,11 +2,14 @@ package org.usergrid.management;
 
 import java.util.Map;
 
+import org.usergrid.persistence.TypedEntity;
+
+
 /**
  * Created by ApigeeCorporation on 1/31/14.
  */
 //TODO: Documentation on this class.
-public class ExportInfo { //extends Entity something {
+public class ExportInfo extends TypedEntity {
 
     private String path;
     private Map<String, Object> properties;
@@ -17,24 +20,6 @@ public class ExportInfo { //extends Entity something {
     private String s3_key;
     private String bucket_location;
 
-
-    /**
-     *
-     *the sch system doesn't make any assumes about the job or how it works.
-     * and so if I need additional information to be persistant.
-     *
-     * The way to save data between queue and storing it.
-     *
-     * in my case, create a export entity. before I schedule the job and it'll have the pending
state in it and
-     * all the information I need to run. Then I'll pass the ID of the export info I saved
in a collection and i'll put that in the jbo
-     * data.
-     *
-     * persist the state in mechanisum that they can all access.
-     *
-     * I could make it a class and I can make it an entity. That way I can get it in and
out.
-     * doesn't get exposed to the user.
-     */
-
     public ExportInfo ( Map<String, Object> exportData) {
         path = (String) exportData.get("path");
         properties = (Map) exportData.get("properties");

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59966c2c/stack/services/src/main/java/org/usergrid/management/export/ExportJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/usergrid/management/export/ExportJob.java b/stack/services/src/main/java/org/usergrid/management/export/ExportJob.java
index ec5f27b..90849cf 100644
--- a/stack/services/src/main/java/org/usergrid/management/export/ExportJob.java
+++ b/stack/services/src/main/java/org/usergrid/management/export/ExportJob.java
@@ -15,7 +15,8 @@ import org.usergrid.persistence.entities.JobData;
 
 /**
  *
- *
+ *you could make an enum here, that contains the state info
+ * look at scotts code and emulate that to see wha tyou can return in the json object
  */
 @Component("exportJob")
 public class ExportJob extends OnlyOnceJob {
@@ -38,8 +39,7 @@ public class ExportJob extends OnlyOnceJob {
         ExportInfo config = (ExportInfo) jobData.getProperty( "exportInfo" );
 
         jobExecution.heartbeat();
-//pass in jobExecution so that you can call the heartbeat in the do export method.
-        exportService.doExport( config, jobExecution );
+        exportService.doExport( config,jobExecution );
 
         logger.info( "executed ExportJob completed normally" );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59966c2c/stack/services/src/main/java/org/usergrid/management/export/ExportService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/usergrid/management/export/ExportService.java
b/stack/services/src/main/java/org/usergrid/management/export/ExportService.java
index aa1dd1b..a643598 100644
--- a/stack/services/src/main/java/org/usergrid/management/export/ExportService.java
+++ b/stack/services/src/main/java/org/usergrid/management/export/ExportService.java
@@ -17,7 +17,7 @@ public interface ExportService {
      * Schedules the export to execute
      * @param config
      */
-    void schedule(ExportInfo config);
+    UUID schedule(ExportInfo config) throws Exception;
 
 
     /**
@@ -27,10 +27,10 @@ public interface ExportService {
     void doExport(ExportInfo config, JobExecution jobExecution) throws Exception;
 
     /**
-     * Returns the UUID to the user
-     * @param
+     * Returns the current state of the service.
+     * @return
      */
-    UUID getJobUUID();
+    String getState(UUID state) throws Exception;
 
     void setS3Export(S3Export s3Export);
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59966c2c/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
b/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
index c99b4f6..949d7c8 100644
--- a/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
+++ b/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
@@ -28,23 +28,26 @@ import org.usergrid.persistence.ConnectionRef;
 import org.usergrid.persistence.Entity;
 import org.usergrid.persistence.EntityManager;
 import org.usergrid.persistence.EntityManagerFactory;
+import org.usergrid.persistence.PagingResultsIterator;
 import org.usergrid.persistence.Query;
 import org.usergrid.persistence.Results;
 import org.usergrid.persistence.cassandra.CassandraService;
+import org.usergrid.persistence.entities.Export;
 import org.usergrid.persistence.entities.JobData;
-import org.usergrid.persistence.entities.JobStat;
 
 import com.google.common.collect.BiMap;
 
 
 /**
- *
+ *The class is a singleton and thust must not have ANY instance variables declared in its
scope.
  *
  */
 public class ExportServiceImpl implements ExportService {
 
 
     private static final Logger logger = LoggerFactory.getLogger( ExportServiceImpl.class
);
+    public static final String EXPORT_ID = "exportId";
+    public static final String EXPORT_JOB_NAME = "exportJob";
     //dependency injection
     private SchedulerService sch;
 
@@ -71,8 +74,6 @@ public class ExportServiceImpl implements ExportService {
 
     private String filename = PATH_REPLACEMENT;
 
-    private UUID jobUUID;
-
     private S3Export s3Export;
 
     //TODO: Todd, do I refactor most of the methods out to just leave schedule and doExport
much like
@@ -80,12 +81,20 @@ public class ExportServiceImpl implements ExportService {
 
 
     @Override
-    public void schedule( final ExportInfo config ) {
+    public UUID schedule( final ExportInfo config ) throws Exception {
+
+        EntityManager em = emf.getEntityManager( CassandraService.MANAGEMENT_APPLICATION_ID
);
+
+        Export export = new Export();
+        export.setState( Export.State.PENDING );
 
         //validate that org exists,then app, then collection.
+
         String pathToBeParsed = config.getPath();
         //split the path so that you can verify that the organization and the app exist.
         String[] pathItems = pathToBeParsed.split( "/" );
+
+
         try {
             managementService.getOrganizationByName( pathItems[0] );
         }
@@ -104,52 +113,83 @@ public class ExportServiceImpl implements ExportService {
         //TODO: parse path and make sure all the things you need actually exist. then throw
         // good error messages when not found.
 
-        //validate user has access key to org (rather valid user has admin access token)
-        //this is token validation
-        JobData jobData = new JobData();
+        //write to the em
+        export = em.create( export );
 
+        JobData jobData = new JobData();
         jobData.setProperty( "exportInfo", config );
+        jobData.setProperty( EXPORT_ID, export.getUuid() );
+
         long soonestPossible = System.currentTimeMillis() + 250; //sch grace period
-        JobData retJobData = sch.createJob( "exportJob", soonestPossible, jobData );
-        jobUUID = retJobData.getUuid();
 
-        try {
-            JobStat merp = sch.getStatsForJob( "exportJob", retJobData.getUuid() );
-            System.out.println( "hi" );
-        }
-        catch ( Exception e ) {
-            logger.error( "could not get stats for job" );
-        }
+        sch.createJob( EXPORT_JOB_NAME, soonestPossible, jobData );
+
+        return export.getUuid();
+
     }
-//things I need to learn how to do, how to add states to my job and then set them in my export
info such that I can
-    //access them using a uuid.
-    public JobStat getJobStatus( final String uuid) throws Exception {
-        UUID jobId = UUID.fromString( uuid );
-        JobStat jobStat = sch.getStatsForJob( "exportJob", jobId );
-      //  return jobStat.get
-        return jobStat;
+
+//should be done
+    /**
+     * get the state of specific export entity
+     * @param uuid
+     * @return String
+     * @throws Exception
+     */
+    @Override
+    public String getState(final UUID uuid) throws Exception {
+
+        EntityManager rootEm = emf.getEntityManager( CassandraService.MANAGEMENT_APPLICATION_ID
);
+
+
+        Export export = rootEm.get( uuid, Export.class );
+
+        if(export == null){
+            return null;
+        }
+
+        return export.getState().toString();
+
     }
 
 
     @Override
-    public void doExport( final ExportInfo config, final JobExecution jobExecution ) throws
Exception {
+    public void doExport( final ExportInfo config,final JobExecution jobExecution ) throws
Exception {
+
+        UUID exportId = ( UUID ) jobExecution.getJobData().getProperty( EXPORT_ID );
+
+        EntityManager em = emf.getEntityManager( CassandraService.MANAGEMENT_APPLICATION_ID
);
+
+        Export export = em.get( exportId, Export.class );
+
+
+        //update state and re-write the entity
+        export.setState( Export.State.STARTED );
+
+        em.update( export );
 
-        Map<UUID, String> organizations = getOrgs();
+        //needs to pass the org name to getOrgs from path
+        Map<UUID, String> organizations = getOrgs(config);
         for ( Map.Entry<UUID, String> organization : organizations.entrySet() ) {
 
+            //needs to pass app name, and possibly collection to export
             exportApplicationsForOrg( organization, config, jobExecution );
+
         }
-    }
 
+        export.setState( Export.State.COMPLETED );
+
+        em.update( export );
 
-    private Map<UUID, String> getOrgs() throws Exception {
+    }
+
+    //now we also need somebody to take the export info and look through the path for the
specific org.
+    //That way we get a specific org instead of getting all the orgs.
+    private Map<UUID, String> getOrgs(ExportInfo exportInfo) throws Exception {
         // Loop through the organizations
         // TODO:this will come from the orgs in schedule when you do the validations. delete
orgId
         UUID orgId = null;
 
         Map<UUID, String> organizationNames = null;
-        // managementService.setup();
-
 
         if ( orgId == null ) {
             organizationNames = managementService.getOrganizations();
@@ -159,10 +199,7 @@ public class ExportServiceImpl implements ExportService {
             OrganizationInfo info = managementService.getOrganizationByUuid( orgId );
 
             if ( info == null ) {
-
-                //logger.error( "Organization info is null!" );
-                //TODO: remove all instances of system.exit in code case that was adapated.
-                System.exit( 1 );
+                logger.error( "Organization info is null!" );
             }
 
             organizationNames = new HashMap<UUID, String>();
@@ -199,17 +236,10 @@ public class ExportServiceImpl implements ExportService {
         return managementService;
     }
 
-
     public void setManagementService( final ManagementService managementService ) {
         this.managementService = managementService;
     }
 
-
-    public UUID getJobUUID() {
-        return jobUUID;
-    }
-
-
     //write test checking to see what happens if the input stream is closed or wrong.
     //TODO: make multipart streaming functional
     //currently only stores the collection in memory then flushes it.
@@ -288,33 +318,48 @@ public class ExportServiceImpl implements ExportService {
                 Query query = new Query();
                 query.setLimit( MAX_ENTITY_FETCH );
                 query.setResultsLevel( Results.Level.ALL_PROPERTIES );
-
+                //paging iterator. Clean this code up using it.
                 Results entities = em.searchCollection( em.getApplicationRef(), collectionName,
query );
 
+                PagingResultsIterator itr = new PagingResultsIterator( entities );
+//untested
+                for( Object e: itr){
+                    starting_time = checkTimeDelta( starting_time, jobExecution );
+                    Entity entity = ( Entity ) e;
+                    //for ( Entity entity : entities ) {
+                    jg.writeStartObject();
+                    jg.writeFieldName( "Metadata" );
+                    jg.writeObject( entity );
+                    saveCollectionMembers( jg, em, application.getValue(), entity );
+                    jg.writeEndObject();
+                    //}
 
-                starting_time = checkTimeDelta( starting_time, jobExecution );
-
-                while ( entities.size() > 0 ) {
-                    jobExecution.heartbeat();
-                    for ( Entity entity : entities ) {
-                        jg.writeStartObject();
-                        jg.writeFieldName( "Metadata" );
-                        jg.writeObject( entity );
-                        saveCollectionMembers( jg, em, application.getValue(), entity );
-                        jg.writeEndObject();
-                    }
-
-                    //we're done
-                    if ( entities.getCursor() == null ) {
-                        break;
-                    }
 
+                }
 
-                    query.setCursor( entities.getCursor() );
-
-                    entities = em.searchCollection( em.getApplicationRef(), collectionName,
query );
 
-                }
+// working
+//                while ( entities.size() > 0 ) {
+//                    jobExecution.heartbeat();
+//                    for ( Entity entity : entities ) {
+//                        jg.writeStartObject();
+//                        jg.writeFieldName( "Metadata" );
+//                        jg.writeObject( entity );
+//                        saveCollectionMembers( jg, em, application.getValue(), entity );
+//                        jg.writeEndObject();
+//                    }
+//
+//                    //we're done
+//                    if ( entities.getCursor() == null ) {
+//                        break;
+//                    }
+//
+//
+//                    query.setCursor( entities.getCursor() );
+//
+//                    entities = em.searchCollection( em.getApplicationRef(), collectionName,
query );
+//
+//                }
 
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59966c2c/stack/services/src/test/java/org/usergrid/management/cassandra/ManagementServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/usergrid/management/cassandra/ManagementServiceIT.java
b/stack/services/src/test/java/org/usergrid/management/cassandra/ManagementServiceIT.java
index db085b1..447803d 100644
--- a/stack/services/src/test/java/org/usergrid/management/cassandra/ManagementServiceIT.java
+++ b/stack/services/src/test/java/org/usergrid/management/cassandra/ManagementServiceIT.java
@@ -789,40 +789,21 @@ public class ManagementServiceIT {
             f = new File ("test.json");
             f.delete();
         }   catch (Exception e) {
-            //consumed because this checks to see if the file exisits. If it doesn't then
don't do anything and carry on.
+            //consumed because this checks to see if the file exists. If it doesn't then
don't do anything and carry on.
         }
 
         S3Export s3Export = new MockS3ExportImpl();
         ExportService exportService = setup.getExportService();
-        HashMap<String, Object> payload = new HashMap<String, Object>();
-        Map<String, Object> properties = new HashMap<String, Object>();
-        Map<String, Object> storage_info = new HashMap<String, Object>();
-        storage_info.put( "admin_token","insert_token_data_here" );
-        //TODO: always put dummy values here and ignore this test.
-        //TODO: add a ret for when s3 values are invalid.
-        storage_info.put( "s3_key","insert key here" );
-        storage_info.put( "s3_accessId","insert access id here");
-        storage_info.put( "bucket_location","insert bucket name here");
-        properties.put( "storage_provider","s3");
-        properties.put( "storage_info",storage_info);
-
-        payload.put( "path", "test-organization/test-app/user");
-        payload.put( "properties", properties);
+        HashMap<String, Object> payload = payloadBuilder();
 
         ExportInfo exportInfo = new ExportInfo(payload);
 
-        JobData jobData = new JobData();
-        jobData.setProperty( "jobName", "exportJob" );
-        jobData.setProperty( "ExportInfo", exportInfo );
-
-        JobExecution jobExecution = mock ( JobExecution.class);
-
-
-        UUID uuid = UUIDUtils.newTimeUUID();
         EntityManager em = setup.getEmf().getEntityManager( applicationId );
+        //intialize user object to be posted
         Map<String, Object> userProperties = null;
         Entity[] entity;
         entity = new Entity[10];
+        //creates entities
         for (int i = 0; i< 10;i++) {
             userProperties = new LinkedHashMap<String, Object>();
             userProperties.put( "username", "billybob" + i );
@@ -831,16 +812,25 @@ public class ManagementServiceIT {
             entity[i] = em.create( "user", userProperties );
 
         }
+        //creates connections
         em.createConnection( em.getRef( entity[0].getUuid() ),"Vibrations",em.getRef( entity[1].getUuid()
) );
         em.createConnection( em.getRef( entity[1].getUuid() ),"Vibrations",em.getRef( entity[0].getUuid()
) );
 
-
+        UUID exportUUID = exportService.schedule( exportInfo );
         exportService.setS3Export( s3Export );
-        exportService.doExport( exportInfo, jobExecution  );
 
-        JSONParser parser = new JSONParser();
+        //create and initialize jobData returned in JobExecution. 
+        JobData jobData = new JobData();
+        jobData.setProperty( "jobName", "exportJob" );
+        jobData.setProperty( "exportInfo", exportInfo );
+        jobData.setProperty( "exportId", exportUUID );
 
+        JobExecution jobExecution = mock ( JobExecution.class);
+        when(jobExecution.getJobData()).thenReturn( jobData );
+
+        exportService.doExport( exportInfo, jobExecution  );
 
+        JSONParser parser = new JSONParser();
 
         org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse(new FileReader(f));
 
@@ -861,6 +851,8 @@ public class ManagementServiceIT {
         org.json.simple.JSONObject objEnt = ( org.json.simple.JSONObject) a.get( 1 );
         org.json.simple.JSONObject objConnections = ( org.json.simple.JSONObject) objEnt.get(
"connections" );
 
+        assertNotNull( objConnections );
+
         org.json.simple.JSONArray objVibrations = ( org.json.simple.JSONArray ) objConnections.get("Vibrations");
 
         assertNotNull( objVibrations );
@@ -879,38 +871,26 @@ public class ManagementServiceIT {
              f = new File ("test.json");
              f.delete();
         }   catch (Exception e) {
-            //consumed because this checks to see if the file exisits. If it doesn't then
don't do anything and carry on.
+            //consumed because this checks to see if the file exists. If it doesn't then
don't do anything and carry on.
         }
 
-
-
         S3Export s3Export = new MockS3ExportImpl();
         ExportService exportService = setup.getExportService();
-        HashMap<String, Object> payload = new HashMap<String, Object>();
-        Map<String, Object> properties = new HashMap<String, Object>();
-        Map<String, Object> storage_info = new HashMap<String, Object>();
-        storage_info.put( "admin_token","insert_token_data_here" );
-        //TODO: always put dummy values here and ignore this test.
-        //TODO: add a ret for when s3 values are invalid.
-        storage_info.put( "s3_key","insert key here" );
-        storage_info.put( "s3_accessId","insert access id here");
-        storage_info.put( "bucket_location","insert bucket name here");
-        properties.put( "storage_provider","s3");
-        properties.put( "storage_info",storage_info);
-
-        payload.put( "path", "test-organization/test-app/user");
-        payload.put( "properties", properties);
+        HashMap<String, Object> payload = payloadBuilder();
 
         ExportInfo exportInfo = new ExportInfo(payload);
 
+        UUID exportUUID = exportService.schedule( exportInfo );
+        exportService.setS3Export( s3Export );
+
         JobData jobData = new JobData();
         jobData.setProperty( "jobName", "exportJob" );
-        jobData.setProperty( "ExportInfo", exportInfo );
+        jobData.setProperty( "exportInfo", exportInfo );
+        jobData.setProperty( "exportId", exportUUID );
 
         JobExecution jobExecution = mock ( JobExecution.class);
+        when(jobExecution.getJobData()).thenReturn( jobData );
 
-
-        exportService.setS3Export( s3Export );
         exportService.doExport( exportInfo, jobExecution  );
 
         JSONParser parser = new JSONParser();
@@ -1138,4 +1118,26 @@ public class ManagementServiceIT {
         assert(true);
     }
 
+    /*Creates fake payload for testing purposes.*/
+    public HashMap<String,Object> payloadBuilder() {
+        HashMap<String, Object> payload = new HashMap<String, Object>();
+        Map<String, Object> properties = new HashMap<String, Object>();
+        Map<String, Object> storage_info = new HashMap<String, Object>();
+        //TODO: make sure to put a valid admin token here.
+        //storage_info.put( "admin_token","insert_token_data_here" );
+        //TODO: always put dummy values here and ignore this test.
+        //TODO: add a ret for when s3 values are invalid.
+        storage_info.put( "s3_key","insert key here" );
+        storage_info.put( "s3_accessId","insert access id here");
+        storage_info.put( "bucket_location","insert bucket name here");
+
+
+        properties.put( "storage_provider","s3");
+        properties.put( "storage_info",storage_info);
+
+        payload.put( "path", "test-organization/test-app");
+        payload.put( "properties", properties);
+        return payload;
+    }
+
 }


Mime
View raw message