usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [39/50] [abbrv] git commit: Functionality Added: Added working state info, and added functional Export Endpoint.
Date Tue, 25 Feb 2014 06:21:53 GMT
Functionality Added: Added working state info, and added functional Export Endpoint.

Removed export endpoint from ManagementResource and moved it to ApplicationResource.
Refactored tests to use generic payload builder.
Error checking added to ExportJob.
Made Cassandra backups specific to apps they are called from.


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

Branch: refs/pull/60/merge
Commit: 11f447f66cf821e6010b985de7cb0269200f7fe9
Parents: a58eceb
Author: grey <greyes@apigee.com>
Authored: Thu Feb 20 14:12:29 2014 -0800
Committer: grey <greyes@apigee.com>
Committed: Thu Feb 20 14:12:29 2014 -0800

----------------------------------------------------------------------
 .../usergrid/persistence/entities/Export.java   | 28 ++-----
 .../rest/management/ManagementResource.java     | 66 ----------------
 .../applications/ApplicationResource.java       | 80 +++++++++++++++++++
 .../rest/management/ManagementResourceIT.java   | 83 ++++++++------------
 .../org/usergrid/management/ExportInfo.java     | 12 +++
 .../usergrid/management/export/ExportJob.java   | 28 ++++---
 .../management/export/ExportService.java        |  2 +-
 .../management/export/ExportServiceImpl.java    | 15 ++--
 .../cassandra/ManagementServiceIT.java          | 73 ++++++++++-------
 9 files changed, 203 insertions(+), 184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/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 f467430..60d2bcb 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
@@ -3,6 +3,7 @@ package org.usergrid.persistence.entities;
 
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.codehaus.jackson.map.annotate.JsonSerialize;
 import org.usergrid.persistence.TypedEntity;
 import org.usergrid.persistence.annotations.EntityProperty;
 
@@ -20,7 +21,7 @@ public class Export extends TypedEntity {
     }
 
     @EntityProperty
-    public State curState;
+    protected State curState;
 
     @EntityProperty
     protected Long queued;
@@ -46,25 +47,6 @@ public class Export extends TypedEntity {
     @EntityProperty
     protected String errorMessage;
 
-    @EntityProperty
-    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;
-    }
-
     public Export() {
     }
 
@@ -107,10 +89,14 @@ public class Export extends TypedEntity {
     }
 
     //state should moved to a derived state, but it is not there yet.
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    @EntityProperty
     public void setState(State setter) {
         curState = setter;
     }
-
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    @EntityProperty
+    public State  getState() { return curState; }
 
     public void setCanceled( final Boolean canceled ) {
         this.canceled = canceled;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/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 20043b3..5e04177 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
@@ -17,9 +17,7 @@ package org.usergrid.rest.management;
 
 
 import java.net.URLEncoder;
-import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DefaultValue;
@@ -28,7 +26,6 @@ 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;
@@ -41,7 +38,6 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
-import org.usergrid.management.ExportInfo;
 import org.usergrid.management.UserInfo;
 import org.usergrid.management.exceptions.DisabledAdminUserException;
 import org.usergrid.management.exceptions.UnactivatedAdminUserException;
@@ -56,7 +52,6 @@ import org.usergrid.security.shiro.utils.SubjectUtils;
 
 import org.apache.amber.oauth2.common.error.OAuthError;
 import org.apache.amber.oauth2.common.exception.OAuthProblemException;
-import org.apache.amber.oauth2.common.exception.OAuthSystemException;
 import org.apache.amber.oauth2.common.message.OAuthResponse;
 import org.apache.amber.oauth2.common.message.types.GrantType;
 import org.apache.commons.lang.StringUtils;
@@ -64,10 +59,8 @@ import org.apache.shiro.codec.Base64;
 
 import com.sun.jersey.api.view.Viewable;
 
-import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
 import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
 import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
-import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
 import static javax.servlet.http.HttpServletResponse.SC_OK;
 import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@@ -449,65 +442,6 @@ public class ManagementResource extends AbstractContextResource {
             return handleViewable( "error", e );
         }
     }
-    //TODO: url encoded form of export
-    //TODO: add authorization.
-
-    @POST
-    @Path( "export" )
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response exportPostJson (@Context UriInfo ui,
-                                    Map<String, Object> json,
-                                    @QueryParam( "callback" ) @DefaultValue( "" ) String
callback)
-            throws OAuthSystemException {
-
-
-        OAuthResponse response = null;
-        UUID jobUUID = null;
-        Map<String, String> uuidRet = new HashMap<String, String>(  );
-
-        try {
-
-        //parse the json into some useful object (the config params)
-            ExportInfo objEx = new ExportInfo(json);
-            jobUUID = exportService.schedule(objEx);
-            uuidRet.put( "jobUUID", jobUUID.toString() );
-
-        }
-        catch (NullPointerException e) {
-            OAuthResponse errorMsg = OAuthResponse.errorResponse( SC_BAD_REQUEST )
-                         .setErrorDescription( "Job Not Created" )
-                         .buildJSONMessage();
-
-            return Response.status( errorMsg.getResponseStatus() ).type( jsonMediaType( callback
) )
-                           .entity( wrapWithCallback( errorMsg.getBody(), callback ) ).build();
-        }
-        catch (Exception e) {
-            //TODO:throw descriptive error message and or include on in the response
-            //TODO:fix below, it doesn't work if there is an exception. Make it look like
the OauthResponse.
-            return Response.status( SC_INTERNAL_SERVER_ERROR ).build();
-        }
-
-        return Response.status(SC_ACCEPTED).entity(uuidRet).build();
-
-        //Response.status( response.getResponseStatus() ).type( jsonMediaType( callback )
)
-                 //      .entity( wrapWithCallback( "", callback ) ).build();
-    }
-
-    @GET
-    @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(state).build();
-        //return Response.status(SC_OK).entity(state).build();
-    }
-
 
     String errorMsg = "";
     String responseType;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/stack/rest/src/main/java/org/usergrid/rest/management/organizations/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/usergrid/rest/management/organizations/applications/ApplicationResource.java
b/stack/rest/src/main/java/org/usergrid/rest/management/organizations/applications/ApplicationResource.java
index 48b9f60..9f6a6c8 100644
--- a/stack/rest/src/main/java/org/usergrid/rest/management/organizations/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/usergrid/rest/management/organizations/applications/ApplicationResource.java
@@ -16,6 +16,7 @@
 package org.usergrid.rest.management.organizations.applications;
 
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
@@ -25,30 +26,43 @@ import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 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;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 import org.usergrid.management.ApplicationInfo;
+import org.usergrid.management.ExportInfo;
 import org.usergrid.management.OrganizationInfo;
+import org.usergrid.management.export.ExportService;
+import org.usergrid.persistence.entities.Export;
 import org.usergrid.rest.AbstractContextResource;
 import org.usergrid.rest.ApiResponse;
+import org.usergrid.rest.applications.ServiceResource;
 import org.usergrid.rest.security.annotations.RequireOrganizationAccess;
+import org.usergrid.rest.utils.JSONPUtils;
 import org.usergrid.security.oauth.ClientCredentialsInfo;
 import org.usergrid.security.providers.SignInAsProvider;
 import org.usergrid.security.providers.SignInProviderFactory;
 import org.usergrid.services.ServiceManager;
 
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
+import org.apache.amber.oauth2.common.message.OAuthResponse;
 import org.apache.commons.lang.StringUtils;
 
 import com.google.common.base.Preconditions;
 import com.sun.jersey.api.json.JSONWithPadding;
 
+import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
+import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
+import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+import static javax.servlet.http.HttpServletResponse.SC_OK;
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 
 
@@ -60,6 +74,8 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 })
 public class ApplicationResource extends AbstractContextResource {
 
+    @Autowired
+    protected ExportService exportService;
     OrganizationInfo organization;
     UUID applicationId;
     ApplicationInfo application;
@@ -192,4 +208,68 @@ public class ApplicationResource extends AbstractContextResource {
 
         return new JSONWithPadding( response, callback );
     }
+    //add export here
+    @POST
+    @Path("export")
+    @Consumes(APPLICATION_JSON)
+    @RequireOrganizationAccess
+    public Response exportPostJson (@Context UriInfo ui,
+                                    Map<String, Object> json,
+                                    @QueryParam( "callback" ) @DefaultValue( "" ) String
callback)
+            throws OAuthSystemException {
+
+
+        OAuthResponse response = null;
+        UUID jobUUID = null;
+        Map<String, String> uuidRet = new HashMap<String, String>(  );
+
+        try {
+            //parse the json into some useful object (the config params)
+            ExportInfo objEx = new ExportInfo(json);
+            objEx.setApplicationId( applicationId );
+            jobUUID = exportService.schedule(objEx);
+            uuidRet.put( "jobUUID", jobUUID.toString() );
+
+        }
+        catch (NullPointerException e) {
+            OAuthResponse errorMsg = OAuthResponse.errorResponse( SC_BAD_REQUEST )
+                                                  .setErrorDescription( "Job Not Created"
)
+                                                  .buildJSONMessage();
+
+            return Response.status( errorMsg.getResponseStatus() ).type( JSONPUtils.jsonMediaType(
callback ) )
+                           .entity( ServiceResource.wrapWithCallback( errorMsg.getBody(),
callback ) ).build();
+        }
+        catch (Exception e) {
+            //TODO:throw descriptive error message and or include on in the response
+            //TODO:fix below, it doesn't work if there is an exception. Make it look like
the OauthResponse.
+            return Response.status( SC_INTERNAL_SERVER_ERROR ).build();
+        }
+
+        return Response.status(SC_ACCEPTED).entity(uuidRet).build();
+
+        //Response.status( response.getResponseStatus() ).type( jsonMediaType( callback )
)
+        //      .entity( wrapWithCallback( "", callback ) ).build();
+    }
+
+    @GET
+    @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" ) UUID jobUUIDStr,
+                                  @QueryParam( "callback" ) @DefaultValue( "" ) String callback
) throws Exception {
+
+        Export entity;
+        try {
+            entity = smf.getServiceManager( applicationId ).getEntityManager().get(jobUUIDStr,
Export.class  );
+        }catch(Exception e) {
+            return Response.status( SC_BAD_REQUEST ).build();
+        }
+        //validate this user owns it
+
+        if (entity == null) {
+            return Response.status(SC_BAD_REQUEST).build();
+        }
+
+        return Response.status(SC_OK).entity(entity.getState()).build();
+        //return Response.status(SC_OK).entity(state).build();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/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 04b7bdc..07433f2 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
@@ -536,25 +536,10 @@ public class ManagementResourceIT extends AbstractRestIT {
         Status responseStatus = Status.OK;
         JsonNode node = null;
 
-        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.
-        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();
 
         try {
-            node = resource().path( "/management/export" ).accept( MediaType.APPLICATION_JSON
)
+            node = resource().path( "/management/orgs/test-organization/apps/test-app/export"
).accept( MediaType.APPLICATION_JSON )
                       .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class, payload
);
         }
         catch ( UniformInterfaceException uie ) {
@@ -594,7 +579,7 @@ public class ManagementResourceIT extends AbstractRestIT {
         }
 
         try {
-            node = resource().path( "/management/export" ).accept( MediaType.APPLICATION_JSON
)
+            node = resource().path( "/management/orgs/test-organization/apps/test-app/export"
).accept( MediaType.APPLICATION_JSON )
                              .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class,
payload );
         }
         catch ( UniformInterfaceException uie ) {
@@ -603,10 +588,7 @@ public class ManagementResourceIT extends AbstractRestIT {
 
         assertEquals( Status.OK, responseStatus );
     }
-//tests that you need to accomplish.
-    //make sure you can call the endpoint
-    //make sure you can return the uuid back to the user
-    //make sure you can mock the s3 testing
+
     @Test
     public void exportUUIDRetTest() throws Exception {
         Status responseStatus = Status.ACCEPTED;
@@ -615,26 +597,11 @@ public class ManagementResourceIT extends AbstractRestIT {
         JsonNode node = null;
 
 
-        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/user");
-        payload.put( "properties", properties);
+        HashMap<String, Object> payload = payloadBuilder();
 
         try {
-            node = resource().path( "/management/export" )
+            node = resource().path( "/management/orgs/test-organization/apps/test-app/export"
)
+                             .queryParam( "access_token", superAdminToken() )
                              .accept( MediaType.APPLICATION_JSON )
                              .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class,
payload );
 
@@ -647,6 +614,7 @@ public class ManagementResourceIT extends AbstractRestIT {
         assertNotNull( node.get( "jobUUID" ) );
     }
 /*Make a test with an invalid uuid and a wrong uuid.*/
+    //all tests should be moved to OrganizationResourceIT ( *not* Organizations there is
a difference)
     @Test
     public void exportGetJobStatTest() throws Exception {
         JsonNode node = null;
@@ -654,15 +622,15 @@ public class ManagementResourceIT extends AbstractRestIT {
 
         HashMap<String, Object> payload = payloadBuilder();
 
-        node = resource().path( "/management/export" )
+        node = resource().path( "/management/orgs/test-organization/apps/test-app/export"
)
+                         .queryParam( "access_token", superAdminToken() )
                          .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( "test-organization/test-app/export"+uuid).queryParam(
"access_token",
+            node = resource().path( "/management/orgs/test-organization/apps/test-app/export/"+uuid).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 )
@@ -673,29 +641,44 @@ public class ManagementResourceIT extends AbstractRestIT {
 
 
         assertEquals( Status.OK, responseStatus );
-        assertEquals( "PENDING",node.get( "jobStatus" ) );
+        assertEquals( "PENDING",node.asText() );//TODO: do tests for other states in service
tier
 
     }
-
+    //do an unauthorized test for both post and get
     @Test
     public void exportGetWrongUUID() throws Exception {
         JsonNode node = null;
-        Status responseStatus = Status.BAD_REQUEST;
-
+        Status responseStatus = Status.OK;
+        UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" );
         try {
             node = resource().path(
-                "/management/export/123456789" ).accept( MediaType.APPLICATION_JSON ).type(
+                "/management/orgs/test-organization/apps/test-app/export/"+fake ).queryParam(
"access_token",
+                    superAdminToken() ).accept( MediaType.APPLICATION_JSON ).type(
                 MediaType.APPLICATION_JSON_TYPE )
                         .get( JsonNode.class );
         }catch(UniformInterfaceException uie) {
             responseStatus = uie.getResponse().getClientResponseStatus();
         }
-
         assertEquals(Status.BAD_REQUEST, responseStatus);
-        assertEquals( "No Such Job", node.get( "jobStatus" ) );
 
     }
 
+    @Test
+    public void exportGetUnauthorized() throws Exception {
+        JsonNode node = null;
+        Status responseStatus = Status.OK;
+        UUID fake = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" );
+        try {
+            node = resource().path( "/management/orgs/test-organization/apps/test-app/export/"
+ fake )
+                             .accept( MediaType.APPLICATION_JSON )
+                             .type( MediaType.APPLICATION_JSON_TYPE )
+                             .get( JsonNode.class );
+        }catch(UniformInterfaceException uie) {
+            responseStatus = uie.getResponse().getClientResponseStatus();
+        }
+        assertEquals(Status.UNAUTHORIZED, responseStatus);
+    }
+
     /*Creates fake payload for testing purposes.*/
     public HashMap<String,Object> payloadBuilder() {
         HashMap<String, Object> payload = new HashMap<String, Object>();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/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 2589fa3..d0d2630 100644
--- a/stack/services/src/main/java/org/usergrid/management/ExportInfo.java
+++ b/stack/services/src/main/java/org/usergrid/management/ExportInfo.java
@@ -1,6 +1,8 @@
 package org.usergrid.management;
 
+
 import java.util.Map;
+import java.util.UUID;
 
 import org.usergrid.persistence.TypedEntity;
 
@@ -19,6 +21,7 @@ public class ExportInfo extends TypedEntity {
     private String admin_token;
     private String s3_key;
     private String bucket_location;
+    private UUID applicationId;
 
     public ExportInfo ( Map<String, Object> exportData) {
         path = (String) exportData.get("path");
@@ -31,10 +34,17 @@ public class ExportInfo extends TypedEntity {
         bucket_location = (String) storage_info.get("bucket_location");
     }
 
+
+    public UUID getApplicationId() {
+        return applicationId;
+    }
+
+
     public String getPath () {
         return path;
     };
 
+
     //Wouldn't get exposed.
     public Map<String, Object> getProperties() {
         return properties;
@@ -54,4 +64,6 @@ public class ExportInfo extends TypedEntity {
     public String getBucket_location () { return bucket_location; }
 
     public String getS3_accessId () { return s3_accessId; }
+
+    public void setApplicationId (UUID appId) { applicationId = appId;}
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/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 90849cf..ed8a24e 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
@@ -1,8 +1,6 @@
 package org.usergrid.management.export;
 
 
-import java.util.UUID;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,15 +31,23 @@ public class ExportJob extends OnlyOnceJob {
     public void doJob(JobExecution jobExecution) throws Exception {
         logger.info( "execute ExportJob {}", jobExecution );
 
-        JobData jobData = jobExecution.getJobData();
-        UUID exportId = ( UUID ) jobData.getProperty("exportId");
-        //this is probably the state info that todd mentioned
-        ExportInfo config = (ExportInfo) jobData.getProperty( "exportInfo" );
-
-        jobExecution.heartbeat();
-        exportService.doExport( config,jobExecution );
-
-        logger.info( "executed ExportJob completed normally" );
+        ExportInfo config = null;
+            //add check for null jobData.
+            JobData jobData = jobExecution.getJobData();
+            config = (ExportInfo) jobData.getProperty( "exportInfo" );
+            if(jobData == null) {
+                logger.error( "jobData cannot be null" );
+                return;
+            }
+            else if (config == null) {
+                logger.error( "Export information cannot be null" );
+                return;
+            }
+            else {
+                jobExecution.heartbeat();
+                exportService.doExport( config,jobExecution );
+            }
+        logger.info( "executed ExportJob process completed" );
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/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 a643598..644aef6 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
@@ -30,7 +30,7 @@ public interface ExportService {
      * Returns the current state of the service.
      * @return
      */
-    String getState(UUID state) throws Exception;
+    String getState(UUID appId,UUID state) throws Exception;
 
     void setS3Export(S3Export s3Export);
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/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 445fe10..243c6f4 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
@@ -83,7 +83,7 @@ public class ExportServiceImpl implements ExportService {
     @Override
     public UUID schedule( final ExportInfo config ) throws Exception {
 
-        EntityManager em = emf.getEntityManager( CassandraService.MANAGEMENT_APPLICATION_ID
);
+        EntityManager em = emf.getEntityManager( config.getApplicationId());
 
         Export export = new Export();
         export.setState( Export.State.PENDING );
@@ -115,6 +115,8 @@ public class ExportServiceImpl implements ExportService {
 
         //write to the em
         export = em.create( export );
+        export.setState( Export.State.PENDING );
+        em.update( export );
 
         JobData jobData = new JobData();
         jobData.setProperty( "exportInfo", config );
@@ -127,8 +129,6 @@ public class ExportServiceImpl implements ExportService {
         return export.getUuid();
 
     }
-
-//should be done
     /**
      * get the state of specific export entity
      * @param uuid
@@ -136,9 +136,9 @@ public class ExportServiceImpl implements ExportService {
      * @throws Exception
      */
     @Override
-    public String getState(final UUID uuid) throws Exception {
+    public String getState(final UUID appId, final UUID uuid) throws Exception {
 
-        EntityManager rootEm = emf.getEntityManager( CassandraService.MANAGEMENT_APPLICATION_ID
);
+        EntityManager rootEm = emf.getEntityManager( appId );
 
 
         Export export = rootEm.get( uuid, Export.class );
@@ -157,7 +157,7 @@ public class ExportServiceImpl implements ExportService {
 
         UUID exportId = ( UUID ) jobExecution.getJobData().getProperty( EXPORT_ID );
 
-        EntityManager em = emf.getEntityManager( CassandraService.MANAGEMENT_APPLICATION_ID
);
+        EntityManager em = emf.getEntityManager( config.getApplicationId());
 
         Export export = em.get( exportId, Export.class );
 
@@ -177,7 +177,6 @@ public class ExportServiceImpl implements ExportService {
         }
 
         export.setState( Export.State.COMPLETED );
-
         em.update( export );
 
     }
@@ -261,7 +260,7 @@ public class ExportServiceImpl implements ExportService {
             JsonGenerator jg = getJsonGenerator( baos );
 
             // load the dictionary
-
+            //TODO: change the CassService below to only be the applicationId that gets stored
in the config.
             EntityManager rootEm = emf.getEntityManager( CassandraService.MANAGEMENT_APPLICATION_ID
);
 
             Entity appEntity = rootEm.get( application.getKey() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/11f447f6/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 447803d..105a0fd 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
@@ -36,6 +36,8 @@ import org.usergrid.management.export.S3ExportImpl;
 import org.usergrid.persistence.CredentialsInfo;
 import org.usergrid.persistence.Entity;
 import org.usergrid.persistence.EntityManager;
+import org.usergrid.persistence.EntityManagerFactory;
+import org.usergrid.persistence.entities.Export;
 import org.usergrid.persistence.entities.JobData;
 import org.usergrid.persistence.entities.User;
 import org.usergrid.security.AuthPrincipalType;
@@ -922,46 +924,27 @@ public class ManagementServiceIT {
         f.delete();
     }
 
+    //only handles the DoJob Code , different tests for DoExport
     @Test
     public void testExportDoJob() throws Exception {
 
-        //ExportService exportService = mock( ExportService.class );
-        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);
+        exportInfo.setApplicationId( applicationId );
 
 
-        //ExportJob job = new ExportJob();
-        //ExportInfo exportInfo;
-
         JobData jobData = new JobData();
         jobData.setProperty( "jobName", "exportJob" );
-        jobData.setProperty( "ExportInfo", exportInfo ); //this needs to be populated with
properties of export info
+        jobData.setProperty( "exportInfo", exportInfo ); //this needs to be populated with
properties of export info
 
         JobExecution jobExecution = mock ( JobExecution.class);
 
         when( jobExecution.getJobData() ).thenReturn( jobData );
 
         ExportJob job = new ExportJob();
-        S3Export s3Export = mock( S3Export.class );
-        setup.getExportService().setS3Export( s3Export );
-        job.setExportService( setup.getExportService() );
+        ExportService eS = mock (ExportService.class);
+        job.setExportService( eS );
         try {
          job.doJob( jobExecution );
         }catch ( Exception e) {
@@ -971,6 +954,44 @@ public class ManagementServiceIT {
 
     }
 
+    @Test
+    public void testExportDoExport() throws Exception {
+
+        EntityManagerFactory emf = setup.getEmf();
+        EntityManager em = emf.getEntityManager( applicationId );
+        HashMap<String, Object> payload = payloadBuilder();
+        ExportService eS = setup.getExportService();
+
+        JobExecution jobExecution = mock( JobExecution.class);
+
+        ExportInfo exportInfo = new ExportInfo(payload);
+        exportInfo.setApplicationId( applicationId );
+
+        UUID entityExportUUID = eS.schedule( exportInfo );
+
+
+        JobData jobData = new JobData();
+        jobData.setProperty( "jobName", "exportJob" );
+        jobData.setProperty( "exportInfo", exportInfo );
+        jobData.setProperty( "exportId", entityExportUUID);
+
+        when( jobExecution.getJobData() ).thenReturn( jobData );
+
+        //Exportem.get(entityExport);
+        Export exportEntity = ( Export ) em.get(entityExportUUID);
+        assertNotNull( exportEntity );
+        String derp = exportEntity.getState().name();
+        assertEquals( "PENDING",exportEntity.getState().name());
+        try {
+            eS.doExport( exportInfo,jobExecution );
+        }catch(Exception e) {
+            assert(false);
+        }
+        exportEntity = ( Export ) em.get(entityExportUUID);
+        assertNotNull( exportEntity );
+        assertEquals( "COMPLETED",exportEntity.getState().name() );
+    }
+
     //tests that with empty job data, the export still runs.
     @Test
     public void testExportEmptyJobData() throws Exception {
@@ -1027,7 +1048,6 @@ public class ManagementServiceIT {
         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.
 
 
         properties.put( "storage_provider","s3");
@@ -1073,7 +1093,6 @@ public class ManagementServiceIT {
         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.
 
 
 


Mime
View raw message