Formatting Removed some extraneous comments.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/96a1a72d Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/96a1a72d Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/96a1a72d Branch: refs/pull/70/merge Commit: 96a1a72df1523f2f372b3756f6cd9ebf2cba1ddb Parents: b1deced Author: grey <[email protected]> Authored: Tue Feb 25 09:58:50 2014 -0800 Committer: grey <[email protected]> Committed: Tue Feb 25 09:58:50 2014 -0800 ---------------------------------------------------------------------- .../usergrid/persistence/entities/Export.java | 41 ++-- .../applications/ApplicationResource.java | 47 +++-- .../rest/management/ManagementResourceIT.java | 103 +++++----- .../apache/usergrid/management/ExportInfo.java | 38 ++-- .../usergrid/management/export/ExportJob.java | 43 ++-- .../management/export/ExportService.java | 13 +- .../management/export/ExportServiceImpl.java | 35 ++-- .../management/export/S3ExportImpl.java | 7 +- .../cassandra/ManagementServiceIT.java | 197 ++++++++++--------- .../management/cassandra/MockS3ExportImpl.java | 10 +- 10 files changed, 282 insertions(+), 252 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Export.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Export.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Export.java index 182b2ae..7905550 100644 --- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Export.java +++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Export.java @@ -10,51 +10,64 @@ import org.apache.usergrid.persistence.annotations.EntityProperty; /** - *Contains state information for an Entity Job - * + * Contains state information for an Entity Job */ @XmlRootElement public class Export extends TypedEntity { public static enum State { //CREATED, FAILED, SCHEDULED, STARTED, FINISHED, CANCELED, EXPIRED - PENDING,STARTED,FAILED,COMPLETED + PENDING, STARTED, FAILED, COMPLETED } + @EntityProperty protected State curState; @EntityProperty protected Long queued; - /** Time send started */ + /** + * Time send started + */ @EntityProperty protected Long started; - /** Time processed */ + /** + * Time processed + */ @EntityProperty protected Long finished; - /** Time to expire the exportJob */ + /** + * Time to expire the exportJob + */ @EntityProperty protected Long expire; - /** True if exportJob is canceled */ + /** + * True if exportJob is canceled + */ @EntityProperty protected Boolean canceled; - /** Error message */ + /** + * Error message + */ @EntityProperty protected String errorMessage; + public Export() { } - public boolean isExpired () { - return (expire != null && expire > System.currentTimeMillis()); + + public boolean isExpired() { + return ( expire != null && expire > System.currentTimeMillis() ); } + public Long getStarted() { return started; } @@ -89,15 +102,19 @@ public class Export extends TypedEntity { return canceled; } + //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) { + public void setState( State setter ) { curState = setter; } + + @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) @EntityProperty - public State getState() { return curState; } + 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/96a1a72d/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java index 5f45326..e94f4df 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java @@ -210,66 +210,63 @@ public class ApplicationResource extends AbstractContextResource { return new JSONWithPadding( response, callback ); } + @POST @Path("export") @Consumes(APPLICATION_JSON) @RequireOrganizationAccess - public Response exportPostJson (@Context UriInfo ui, - Map<String, Object> json, - @QueryParam( "callback" ) @DefaultValue( "" ) String callback) + 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>( ); + Map<String, String> uuidRet = new HashMap<String, String>(); try { //parse the json into some useful object (the config params) - ExportInfo objEx = new ExportInfo(json); + ExportInfo objEx = new ExportInfo( json ); objEx.setApplicationId( applicationId ); - jobUUID = exportService.schedule(objEx); + jobUUID = exportService.schedule( objEx ); uuidRet.put( "jobUUID", jobUUID.toString() ); - } - catch (NullPointerException e) { - OAuthResponse errorMsg = OAuthResponse.errorResponse( SC_BAD_REQUEST ) - .setErrorDescription( "Job Not Created" ) - .buildJSONMessage(); + 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) { + 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(); + return Response.status( SC_ACCEPTED ).entity( uuidRet ).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 { + @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) { + 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(); + 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(); + return Response.status( SC_OK ).entity( entity.getState() ).build(); } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java index 0621219..a9b06fd 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java @@ -531,6 +531,8 @@ public class ManagementResourceIT extends AbstractRestIT { assertEquals( Status.OK, status ); } + + @Test public void exportCallSuccessful() throws Exception { Status responseStatus = Status.OK; @@ -540,8 +542,7 @@ public class ManagementResourceIT extends AbstractRestIT { try { node = resource().path( "/management/orgs/test-organization/apps/test-app/export" ) - .queryParam( "access_token", superAdminToken() ) - .accept( MediaType.APPLICATION_JSON ) + .queryParam( "access_token", superAdminToken() ).accept( MediaType.APPLICATION_JSON ) .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class, payload ); } catch ( UniformInterfaceException uie ) { @@ -551,6 +552,7 @@ public class ManagementResourceIT extends AbstractRestIT { assertEquals( Status.OK, responseStatus ); } + @Ignore public void exportCallCreationEntities100() throws Exception { Status responseStatus = Status.OK; @@ -562,27 +564,28 @@ public class ManagementResourceIT extends AbstractRestIT { //TODO: make sure to put a valid admin token here. storage_info.put( "admin_token", adminToken() ); //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"); + 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); + properties.put( "storage_provider", "s3" ); + properties.put( "storage_info", storage_info ); - payload.put( "path", "test-organization/test-app/user"); - payload.put( "properties", properties); + payload.put( "path", "test-organization/test-app/user" ); + payload.put( "properties", properties ); - for (int i = 0; i < 100; i++) { - Map<String, String> userCreation = hashMap( "type", "app_user" ).map( "name", "fred"+i ); + for ( int i = 0; i < 100; i++ ) { + Map<String, String> userCreation = hashMap( "type", "app_user" ).map( "name", "fred" + i ); - node = resource().path( "/test-organization/test-app/app_users" ) - .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class, userCreation ); + node = resource().path( "/test-organization/test-app/app_users" ).queryParam( "access_token", access_token ) + .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) + .post( JsonNode.class, userCreation ); } try { - node = resource().path( "/management/orgs/test-organization/apps/test-app/export" ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class, payload ); + 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 ) { responseStatus = uie.getResponse().getClientResponseStatus(); @@ -591,6 +594,7 @@ public class ManagementResourceIT extends AbstractRestIT { assertEquals( Status.OK, responseStatus ); } + @Test public void exportUUIDRetTest() throws Exception { Status responseStatus = Status.ACCEPTED; @@ -603,10 +607,8 @@ public class ManagementResourceIT extends AbstractRestIT { try { node = resource().path( "/management/orgs/test-organization/apps/test-app/export" ) - .queryParam( "access_token", superAdminToken() ) - .accept( MediaType.APPLICATION_JSON ) + .queryParam( "access_token", superAdminToken() ).accept( MediaType.APPLICATION_JSON ) .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class, payload ); - } catch ( UniformInterfaceException uie ) { responseStatus = uie.getResponse().getClientResponseStatus(); @@ -615,6 +617,8 @@ public class ManagementResourceIT extends AbstractRestIT { assertEquals( Status.ACCEPTED, responseStatus ); 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 @@ -625,27 +629,26 @@ public class ManagementResourceIT extends AbstractRestIT { HashMap<String, Object> payload = payloadBuilder(); node = resource().path( "/management/orgs/test-organization/apps/test-app/export" ) - .queryParam( "access_token", superAdminToken() ) - .accept( MediaType.APPLICATION_JSON ) + .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( "\"","" ); + uuid = uuid.replaceAll( "\"", "" ); try { - node = resource().path( "/management/orgs/test-organization/apps/test-app/export/"+uuid).queryParam( "access_token", - superAdminToken() ).accept( MediaType.APPLICATION_JSON ) + 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 ) - // .get( JsonNode.class ); - }catch(UniformInterfaceException uie) { + } + catch ( UniformInterfaceException uie ) { responseStatus = uie.getResponse().getClientResponseStatus(); } assertEquals( Status.OK, responseStatus ); - assertEquals( "PENDING",node.asText() );//TODO: do tests for other states in service tier - + 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 { @@ -653,18 +656,17 @@ public class ManagementResourceIT extends AbstractRestIT { 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 ).queryParam( "access_token", - superAdminToken() ).accept( MediaType.APPLICATION_JSON ).type( - MediaType.APPLICATION_JSON_TYPE ) - .get( JsonNode.class ); - }catch(UniformInterfaceException uie) { + node = resource().path( "/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( Status.BAD_REQUEST, responseStatus ); } + @Test public void exportGetUnauthorized() throws Exception { JsonNode node = null; @@ -672,34 +674,33 @@ public class ManagementResourceIT extends AbstractRestIT { 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 ) + .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) .get( JsonNode.class ); - }catch(UniformInterfaceException uie) { + } + catch ( UniformInterfaceException uie ) { responseStatus = uie.getResponse().getClientResponseStatus(); } - assertEquals(Status.UNAUTHORIZED, responseStatus); + assertEquals( Status.UNAUTHORIZED, responseStatus ); } + /*Creates fake payload for testing purposes.*/ - public HashMap<String,Object> payloadBuilder() { + 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"); + 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); + properties.put( "storage_provider", "s3" ); + properties.put( "storage_info", storage_info ); - payload.put( "path", "test-organization/test-app"); - payload.put( "properties", properties); + payload.put( "path", "test-organization/test-app" ); + payload.put( "properties", properties ); return payload; } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java b/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java index f4ed4cf..4436f0b 100644 --- a/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java +++ b/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java @@ -22,14 +22,15 @@ public class ExportInfo extends TypedEntity { private String bucket_location; private UUID applicationId; - public ExportInfo ( Map<String, Object> exportData) { - path = (String) exportData.get("path"); - properties = (Map) exportData.get("properties"); - storage_provider = (String) properties.get ("storage_provider"); - storage_info = (Map) properties.get("storage_info"); - s3_accessId = (String) storage_info.get("s3_accessId"); - s3_key = (String) storage_info.get("s3_key"); - bucket_location = (String) storage_info.get("bucket_location"); + + public ExportInfo( Map<String, Object> exportData ) { + path = ( String ) exportData.get( "path" ); + properties = ( Map ) exportData.get( "properties" ); + storage_provider = ( String ) properties.get( "storage_provider" ); + storage_info = ( Map ) properties.get( "storage_info" ); + s3_accessId = ( String ) storage_info.get( "s3_accessId" ); + s3_key = ( String ) storage_info.get( "s3_key" ); + bucket_location = ( String ) storage_info.get( "bucket_location" ); } @@ -38,28 +39,35 @@ public class ExportInfo extends TypedEntity { } - public String getPath () { + public String getPath() { return path; } + //Wouldn't get exposed. public Map<String, Object> getProperties() { return properties; } - public String getStorage_provider () { + + public String getStorage_provider() { return storage_provider; } //TODO: write setter methods - public Map<String, Object> getStorage_info () { return storage_info; } + + public Map<String, Object> getStorage_info() { return storage_info; } + //TODO: is this a security concern? How would we get rid of the key once we're done with this value? - public String getS3_key () { return s3_key; } + public String getS3_key() { return s3_key; } + + + public String getBucket_location() { return bucket_location; } + - public String getBucket_location () { return bucket_location; } + public String getS3_accessId() { return s3_accessId; } - public String getS3_accessId () { return s3_accessId; } - public void setApplicationId (UUID appId) { applicationId = appId;} + public void setApplicationId( UUID appId ) { applicationId = appId;} } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java index 9830040..ed2fef5 100644 --- a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java +++ b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportJob.java @@ -13,9 +13,8 @@ import org.apache.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 + * 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 { @@ -24,35 +23,37 @@ public class ExportJob extends OnlyOnceJob { @Autowired ExportService exportService; + public ExportJob() { - logger.info("ExportJob created " + this); + logger.info( "ExportJob created " + this ); } + @Override - public void doJob(JobExecution jobExecution) throws Exception { + public void doJob( JobExecution jobExecution ) throws Exception { logger.info( "execute ExportJob {}", jobExecution ); 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 ); - } + 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 - protected long getDelay(JobExecution jobExecution) throws Exception { + protected long getDelay( JobExecution jobExecution ) throws Exception { //return arbitrary number return 100; } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/stack/services/src/main/java/org/apache/usergrid/management/export/ExportService.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportService.java b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportService.java index 6e9f4e5..8c127da 100644 --- a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportService.java +++ b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportService.java @@ -9,29 +9,24 @@ import org.apache.usergrid.management.ExportInfo; /** * Performs all functions related to exporting - * */ public interface ExportService { /** * Schedules the export to execute - * @param config */ - UUID schedule(ExportInfo config) throws Exception; + UUID schedule( ExportInfo config ) throws Exception; /** * Perform the export to the external resource - * @param config */ - void doExport(ExportInfo config, JobExecution jobExecution) throws Exception; + void doExport( ExportInfo config, JobExecution jobExecution ) throws Exception; /** * Returns the current state of the service. - * @return */ - String getState(UUID appId,UUID state) throws Exception; - - void setS3Export(S3Export s3Export); + String getState( UUID appId, UUID state ) throws Exception; + void setS3Export( S3Export s3Export ); } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/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 2d8ff5c..155639c 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 @@ -41,9 +41,8 @@ import com.google.common.collect.BiMap; /** - * - *Need to refactor out the mutliple orgs being take , need to factor out the multiple apps - * it will just be the one app and the one org and all of it's collections. + * Need to refactor out the mutliple orgs being take , need to factor out the multiple apps it will just be the one app + * and the one org and all of it's collections. */ public class ExportServiceImpl implements ExportService { @@ -72,10 +71,11 @@ public class ExportServiceImpl implements ExportService { private S3Export s3Export; + @Override public UUID schedule( final ExportInfo config ) throws Exception { - EntityManager em = emf.getEntityManager( config.getApplicationId()); + EntityManager em = emf.getEntityManager( config.getApplicationId() ); Export export = new Export(); export.setState( Export.State.PENDING ); @@ -119,21 +119,21 @@ public class ExportServiceImpl implements ExportService { sch.createJob( EXPORT_JOB_NAME, soonestPossible, jobData ); return export.getUuid(); - } + + /** * Query Entity Manager for specific Export Entity within application - * @param appId,uuid + * * @return String - * @throws Exception */ @Override - public String getState(final UUID appId, final UUID uuid) throws Exception { + public String getState( final UUID appId, final UUID uuid ) throws Exception { EntityManager rootEm = emf.getEntityManager( appId ); Export export = rootEm.get( uuid, Export.class ); - if(export == null){ + if ( export == null ) { return null; } return export.getState().toString(); @@ -141,10 +141,10 @@ public class ExportServiceImpl implements ExportService { @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( config.getApplicationId()); + EntityManager em = emf.getEntityManager( config.getApplicationId() ); Export export = em.get( exportId, Export.class ); String pathToBeParsed = config.getPath(); @@ -162,7 +162,7 @@ public class ExportServiceImpl implements ExportService { em.update( export ); - Map<UUID, String> organizationGet = getOrgs(config); + Map<UUID, String> organizationGet = getOrgs( config ); for ( Map.Entry<UUID, String> organization : organizationGet.entrySet() ) { //needs to pass app name, and possibly collection to export exportApplicationsForOrg( organization, config, jobExecution ); @@ -171,7 +171,8 @@ public class ExportServiceImpl implements ExportService { em.update( export ); } - private Map<UUID, String> getOrgs(ExportInfo exportInfo) throws Exception { + + 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; @@ -223,10 +224,12 @@ public class ExportServiceImpl implements ExportService { return managementService; } + public void setManagementService( final ManagementService managementService ) { this.managementService = managementService; } + //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. @@ -258,7 +261,7 @@ public class ExportServiceImpl implements ExportService { // 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" )) { + if ( collectionName.equals( "exports" ) ) { continue; } @@ -269,7 +272,7 @@ public class ExportServiceImpl implements ExportService { PagingResultsIterator itr = new PagingResultsIterator( entities ); - for( Object e: itr){ + for ( Object e : itr ) { starting_time = checkTimeDelta( starting_time, jobExecution ); Entity entity = ( Entity ) e; @@ -288,7 +291,7 @@ public class ExportServiceImpl implements ExportService { baos.close(); InputStream is = new ByteArrayInputStream( baos.toByteArray() ); - s3Export.copyToS3( is, config , appFileName); + s3Export.copyToS3( is, config, appFileName ); } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/stack/services/src/main/java/org/apache/usergrid/management/export/S3ExportImpl.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/S3ExportImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/export/S3ExportImpl.java index 54d8ab1..2c274e3 100644 --- a/stack/services/src/main/java/org/apache/usergrid/management/export/S3ExportImpl.java +++ b/stack/services/src/main/java/org/apache/usergrid/management/export/S3ExportImpl.java @@ -15,6 +15,7 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.netty.config.NettyPayloadModule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.apache.usergrid.management.ExportInfo; import com.google.common.collect.ImmutableSet; @@ -42,8 +43,8 @@ public class S3ExportImpl implements S3Export { overrides.setProperty( "s3" + ".credential", secretKey ); final Iterable<? extends Module> MODULES = ImmutableSet - .of( new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule - () ); + .of( new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), + new NettyPayloadModule() ); BlobStoreContext context = ContextBuilder.newBuilder( "s3" ).credentials( accessId, secretKey ).modules( MODULES ) @@ -78,7 +79,5 @@ public class S3ExportImpl implements S3Export { catch ( Exception e ) { logger.error( "Error uploading to blob store", e ); } - } - } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java ---------------------------------------------------------------------- diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java index e1b297c..34affe6 100644 --- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java +++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java @@ -744,6 +744,8 @@ public class ManagementServiceIT { assertEquals( userId, authedUser.getUuid() ); } + + //Tests to make sure we can call the job with mock data and it runs. @Ignore public void testFileConnections() throws Exception { @@ -752,9 +754,10 @@ public class ManagementServiceIT { try { - f = new File ("test.json"); + f = new File( "test.json" ); f.delete(); - } catch (Exception e) { + } + catch ( Exception e ) { //consumed because this checks to see if the file exists. If it doesn't then don't do anything and carry on. } @@ -762,7 +765,7 @@ public class ManagementServiceIT { ExportService exportService = setup.getExportService(); HashMap<String, Object> payload = payloadBuilder(); - ExportInfo exportInfo = new ExportInfo(payload); + ExportInfo exportInfo = new ExportInfo( payload ); exportInfo.setApplicationId( applicationId ); EntityManager em = setup.getEmf().getEntityManager( applicationId ); @@ -771,17 +774,16 @@ public class ManagementServiceIT { Entity[] entity; entity = new Entity[10]; //creates entities - for (int i = 0; i< 10;i++) { + for ( int i = 0; i < 10; i++ ) { userProperties = new LinkedHashMap<String, Object>(); userProperties.put( "username", "billybob" + i ); - userProperties.put( "email", "test"+i+"@anuff.com");//String.format( "[email protected]", i ) ); + userProperties.put( "email", "test" + i + "@anuff.com" );//String.format( "[email protected]", i ) ); 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() ) ); + 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 ); @@ -792,22 +794,22 @@ public class ManagementServiceIT { jobData.setProperty( "exportInfo", exportInfo ); jobData.setProperty( "exportId", exportUUID ); - JobExecution jobExecution = mock ( JobExecution.class); - when(jobExecution.getJobData()).thenReturn( jobData ); + JobExecution jobExecution = mock( JobExecution.class ); + when( jobExecution.getJobData() ).thenReturn( jobData ); - exportService.doExport( exportInfo, jobExecution ); + exportService.doExport( exportInfo, jobExecution ); JSONParser parser = new JSONParser(); - org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse(new FileReader(f)); + org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) ); //assertEquals(13, a.size() ); - org.json.simple.JSONObject objEnt = ( org.json.simple.JSONObject) a.get( 0 ); - org.json.simple.JSONObject objConnections = ( org.json.simple.JSONObject) objEnt.get( "connections" ); + org.json.simple.JSONObject objEnt = ( org.json.simple.JSONObject ) a.get( 0 ); + 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"); + org.json.simple.JSONArray objVibrations = ( org.json.simple.JSONArray ) objConnections.get( "Vibrations" ); assertNotNull( objVibrations ); @@ -821,9 +823,10 @@ public class ManagementServiceIT { File f = null; try { - f = new File ("test.json"); + f = new File( "test.json" ); f.delete(); - } catch (Exception e) { + } + catch ( Exception e ) { //consumed because this checks to see if the file exists. If it doesn't then don't do anything and carry on. } @@ -831,7 +834,7 @@ public class ManagementServiceIT { ExportService exportService = setup.getExportService(); HashMap<String, Object> payload = payloadBuilder(); - ExportInfo exportInfo = new ExportInfo(payload); + ExportInfo exportInfo = new ExportInfo( payload ); exportInfo.setApplicationId( applicationId ); UUID exportUUID = exportService.schedule( exportInfo ); @@ -842,25 +845,24 @@ public class ManagementServiceIT { jobData.setProperty( "exportInfo", exportInfo ); jobData.setProperty( "exportId", exportUUID ); - JobExecution jobExecution = mock ( JobExecution.class); - when(jobExecution.getJobData()).thenReturn( jobData ); + JobExecution jobExecution = mock( JobExecution.class ); + when( jobExecution.getJobData() ).thenReturn( jobData ); - exportService.doExport( exportInfo, jobExecution ); + exportService.doExport( exportInfo, jobExecution ); JSONParser parser = new JSONParser(); - org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse(new FileReader(f)); + org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) ); - for (int i = 0; i < a.size();i++ ) - { - org.json.simple.JSONObject entity = ( org.json.simple.JSONObject) a.get( i ); + for ( int i = 0; i < a.size(); i++ ) { + org.json.simple.JSONObject entity = ( org.json.simple.JSONObject ) a.get( i ); org.json.simple.JSONObject entityData = ( JSONObject ) entity.get( "Metadata" ); assertNotNull( entityData ); - } f.delete(); } + @Test public void testFileExportOneOrg() throws Exception { @@ -868,18 +870,21 @@ public class ManagementServiceIT { try { - f = new File ("test.json"); + f = new File( "test.json" ); f.delete(); - } catch (Exception e) { + } + catch ( Exception e ) { //consumed because this checks to see if the file exists. If it doesn't then don't do anything and carry on. } - setup.getMgmtSvc().createOwnerAndOrganization( "noExport","junkUserName","junkRealName","[email protected]","123456789" ); + setup.getMgmtSvc() + .createOwnerAndOrganization( "noExport", "junkUserName", "junkRealName", "[email protected]", + "123456789" ); S3Export s3Export = new MockS3ExportImpl(); ExportService exportService = setup.getExportService(); HashMap<String, Object> payload = payloadBuilder(); - ExportInfo exportInfo = new ExportInfo(payload); + ExportInfo exportInfo = new ExportInfo( payload ); exportInfo.setApplicationId( applicationId ); UUID exportUUID = exportService.schedule( exportInfo ); @@ -890,27 +895,27 @@ public class ManagementServiceIT { jobData.setProperty( "exportInfo", exportInfo ); jobData.setProperty( "exportId", exportUUID ); - JobExecution jobExecution = mock ( JobExecution.class); - when(jobExecution.getJobData()).thenReturn( jobData ); + JobExecution jobExecution = mock( JobExecution.class ); + when( jobExecution.getJobData() ).thenReturn( jobData ); - exportService.doExport( exportInfo, jobExecution ); + exportService.doExport( exportInfo, jobExecution ); JSONParser parser = new JSONParser(); - org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse(new FileReader(f)); + org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) ); //assertEquals( 3 , a.size() ); - for (int i = 0; i < a.size();i++ ) - { - org.json.simple.JSONObject entity = ( org.json.simple.JSONObject) a.get( i ); + for ( int i = 0; i < a.size(); i++ ) { + org.json.simple.JSONObject entity = ( org.json.simple.JSONObject ) a.get( i ); org.json.simple.JSONObject entityData = ( JSONObject ) entity.get( "Metadata" ); - String entityName = ( String) entityData.get( "name" ); + String entityName = ( String ) entityData.get( "name" ); // assertNotEquals( "NotEqual","junkRealName",entityName ); assertFalse( "junkRealName".equals( entityName ) ); - } f.delete(); } + + @Test public void testFileExportOneApp() throws Exception { @@ -919,9 +924,10 @@ public class ManagementServiceIT { String appName = "testAppNotExported"; try { - f = new File ("test.json"); + f = new File( "test.json" ); f.delete(); - } catch (Exception e) { + } + catch ( Exception e ) { //consumed because this checks to see if the file exists. If it doesn't, don't do anything and carry on. } @@ -934,10 +940,10 @@ public class ManagementServiceIT { Entity[] entity; entity = new Entity[10]; //creates entities - for (int i = 0; i< 10;i++) { + for ( int i = 0; i < 10; i++ ) { userProperties = new LinkedHashMap<String, Object>(); userProperties.put( "username", "billybob" + i ); - userProperties.put( "email", "test"+i+"@anuff.com");//String.format( "[email protected]", i ) ); + userProperties.put( "email", "test" + i + "@anuff.com" );//String.format( "[email protected]", i ) ); entity[i] = em.create( "user", userProperties ); } @@ -945,7 +951,7 @@ public class ManagementServiceIT { ExportService exportService = setup.getExportService(); HashMap<String, Object> payload = payloadBuilder(); - ExportInfo exportInfo = new ExportInfo(payload); + ExportInfo exportInfo = new ExportInfo( payload ); exportInfo.setApplicationId( applicationId ); UUID exportUUID = exportService.schedule( exportInfo ); @@ -956,34 +962,34 @@ public class ManagementServiceIT { jobData.setProperty( "exportInfo", exportInfo ); jobData.setProperty( "exportId", exportUUID ); - JobExecution jobExecution = mock ( JobExecution.class); - when(jobExecution.getJobData()).thenReturn( jobData ); + JobExecution jobExecution = mock( JobExecution.class ); + when( jobExecution.getJobData() ).thenReturn( jobData ); - exportService.doExport( exportInfo, jobExecution ); + exportService.doExport( exportInfo, jobExecution ); JSONParser parser = new JSONParser(); - org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse(new FileReader(f)); + org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) ); //assertEquals( 3 , a.size() ); - for (int i = 0; i < a.size();i++ ) - { - org.json.simple.JSONObject data = ( org.json.simple.JSONObject) a.get( i ); + for ( int i = 0; i < a.size(); i++ ) { + org.json.simple.JSONObject data = ( org.json.simple.JSONObject ) a.get( i ); org.json.simple.JSONObject entityData = ( JSONObject ) data.get( "Metadata" ); - String entityName = ( String) entityData.get( "name" ); + String entityName = ( String ) entityData.get( "name" ); assertFalse( "junkRealName".equals( entityName ) ); //assertNotEquals( "NotEquals","junkRealName",entityName ); } f.delete(); } + //only handles the DoJob Code , different tests for DoExport @Test public void testExportDoJob() throws Exception { HashMap<String, Object> payload = payloadBuilder(); - ExportInfo exportInfo = new ExportInfo(payload); + ExportInfo exportInfo = new ExportInfo( payload ); exportInfo.setApplicationId( applicationId ); @@ -991,22 +997,23 @@ public class ManagementServiceIT { jobData.setProperty( "jobName", "exportJob" ); jobData.setProperty( "exportInfo", exportInfo ); //this needs to be populated with properties of export info - JobExecution jobExecution = mock ( JobExecution.class); + JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); ExportJob job = new ExportJob(); - ExportService eS = mock (ExportService.class); + ExportService eS = mock( ExportService.class ); job.setExportService( eS ); try { job.doJob( jobExecution ); - }catch ( Exception e) { - assert( false ); } - assert(true); - + catch ( Exception e ) { + assert ( false ); + } + assert ( true ); } + @Test public void testExportDoExport() throws Exception { @@ -1015,9 +1022,9 @@ public class ManagementServiceIT { HashMap<String, Object> payload = payloadBuilder(); ExportService eS = setup.getExportService(); - JobExecution jobExecution = mock( JobExecution.class); + JobExecution jobExecution = mock( JobExecution.class ); - ExportInfo exportInfo = new ExportInfo(payload); + ExportInfo exportInfo = new ExportInfo( payload ); exportInfo.setApplicationId( applicationId ); UUID entityExportUUID = eS.schedule( exportInfo ); @@ -1026,33 +1033,35 @@ public class ManagementServiceIT { JobData jobData = new JobData(); jobData.setProperty( "jobName", "exportJob" ); jobData.setProperty( "exportInfo", exportInfo ); - jobData.setProperty( "exportId", entityExportUUID); + jobData.setProperty( "exportId", entityExportUUID ); when( jobExecution.getJobData() ).thenReturn( jobData ); //Exportem.get(entityExport); - Export exportEntity = ( Export ) em.get(entityExportUUID); + Export exportEntity = ( Export ) em.get( entityExportUUID ); assertNotNull( exportEntity ); String derp = exportEntity.getState().name(); - assertEquals( "PENDING",exportEntity.getState().name()); + assertEquals( "PENDING", exportEntity.getState().name() ); try { - eS.doExport( exportInfo,jobExecution ); - }catch(Exception e) { + eS.doExport( exportInfo, jobExecution ); + } + catch ( Exception e ) { throw e; //assert(false); } - exportEntity = ( Export ) em.get(entityExportUUID); + exportEntity = ( Export ) em.get( entityExportUUID ); assertNotNull( exportEntity ); - assertEquals( "COMPLETED",exportEntity.getState().name() ); + assertEquals( "COMPLETED", exportEntity.getState().name() ); } + //tests that with empty job data, the export still runs. @Test public void testExportEmptyJobData() throws Exception { JobData jobData = new JobData(); - JobExecution jobExecution = mock ( JobExecution.class); + JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); @@ -1062,18 +1071,20 @@ public class ManagementServiceIT { job.setExportService( setup.getExportService() ); try { job.doJob( jobExecution ); - }catch ( Exception e) { - assert( false ); } - assert(true); + catch ( Exception e ) { + assert ( false ); + } + assert ( true ); } + @Test - public void testNullJobExecution () { + public void testNullJobExecution() { JobData jobData = new JobData(); - JobExecution jobExecution = mock ( JobExecution.class); + JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); @@ -1083,12 +1094,14 @@ public class ManagementServiceIT { job.setExportService( setup.getExportService() ); try { job.doJob( jobExecution ); - }catch ( Exception e) { - assert( false ); } - assert(true); + catch ( Exception e ) { + assert ( false ); + } + assert ( true ); } + @Ignore //For this test please input your s3 credentials into payload builder. public void testIntegration100Entities() throws Exception { @@ -1096,7 +1109,7 @@ public class ManagementServiceIT { ExportService exportService = setup.getExportService(); HashMap<String, Object> payload = payloadBuilder(); - ExportInfo exportInfo = new ExportInfo(payload); + ExportInfo exportInfo = new ExportInfo( payload ); exportInfo.setApplicationId( applicationId ); EntityManager em = setup.getEmf().getEntityManager( applicationId ); @@ -1105,13 +1118,12 @@ public class ManagementServiceIT { Entity[] entity; entity = new Entity[100]; //creates entities - for (int i = 0; i< 100;i++) { + for ( int i = 0; i < 100; i++ ) { userProperties = new LinkedHashMap<String, Object>(); userProperties.put( "username", "billybob" + i ); - userProperties.put( "email", "test"+i+"@anuff.com");//String.format( "[email protected]", i ) ); + userProperties.put( "email", "test" + i + "@anuff.com" );//String.format( "[email protected]", i ) ); entity[i] = em.create( "user", userProperties ); - } UUID exportUUID = exportService.schedule( exportInfo ); @@ -1123,29 +1135,28 @@ public class ManagementServiceIT { jobData.setProperty( "exportInfo", exportInfo ); jobData.setProperty( "exportId", exportUUID ); - JobExecution jobExecution = mock ( JobExecution.class); - when(jobExecution.getJobData()).thenReturn( jobData ); - - exportService.doExport( exportInfo, jobExecution ); + JobExecution jobExecution = mock( JobExecution.class ); + when( jobExecution.getJobData() ).thenReturn( jobData ); + exportService.doExport( exportInfo, jobExecution ); } /*Creates fake payload for testing purposes.*/ - public HashMap<String,Object> payloadBuilder() { + 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: 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"); + 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); + properties.put( "storage_provider", "s3" ); + properties.put( "storage_info", storage_info ); - payload.put( "path", "test-organization/test-app"); - payload.put( "properties", properties); + payload.put( "path", "test-organization/test-app" ); + payload.put( "properties", properties ); return payload; } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/96a1a72d/stack/services/src/test/java/org/apache/usergrid/management/cassandra/MockS3ExportImpl.java ---------------------------------------------------------------------- diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/MockS3ExportImpl.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/MockS3ExportImpl.java index 432fe5e..d8a8b08 100644 --- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/MockS3ExportImpl.java +++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/MockS3ExportImpl.java @@ -10,13 +10,13 @@ import java.io.OutputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.apache.usergrid.management.ExportInfo; import org.apache.usergrid.management.export.S3Export; /** - * Writes to file instead of s3. - * + * Streams / reads the information written from the export service to a file named "test.json" */ public class MockS3ExportImpl implements S3Export { @Override @@ -28,8 +28,7 @@ public class MockS3ExportImpl implements S3Export { //FileInputStream fis = new PrintWriter( inputStream ); try { - outputStream = new FileOutputStream( new File("test.json") ); - + outputStream = new FileOutputStream( new File( "test.json" ) ); } catch ( FileNotFoundException e ) { e.printStackTrace(); @@ -37,10 +36,9 @@ public class MockS3ExportImpl implements S3Export { try { - while ( (read = (inputStream.read( bytes ))) != -1) { + while ( ( read = ( inputStream.read( bytes ) ) ) != -1 ) { outputStream.write( bytes, 0, read ); } - } catch ( IOException e ) { e.printStackTrace();
